Can now click address in output of analyzer in chat to copy it to clipboard.

Also a bit of refactoring in command code.
This commit is contained in:
Florian Nücke 2015-06-28 14:27:45 +02:00
parent 8bc107cc9a
commit 9592ef6317
10 changed files with 151 additions and 91 deletions

View File

@ -155,6 +155,7 @@ oc:gui.Analyzer.AddressCopied=Address copied to clipboard.
oc:gui.Analyzer.ChargerSpeed=§6Charge speed§f: %s
oc:gui.Analyzer.ComponentName=§6Component name§f: %s
oc:gui.Analyzer.Components=§6Number of connected components§f: %s
oc:gui.Analyzer.CopyToClipboard=Click to copy to clipboard.
oc:gui.Analyzer.LastError=§6Last error§f: %s
oc:gui.Analyzer.RobotName=§6Name§f: %s
oc:gui.Analyzer.RobotOwner=§6Owner§f: %s

View File

@ -1,6 +1,9 @@
package li.cil.oc
import cpw.mods.fml.common.event.FMLFingerprintViolationEvent
import li.cil.oc.client.CommandHandler.SetClipboardCommand
import net.minecraft.event.ClickEvent
import net.minecraft.event.HoverEvent
import net.minecraft.util.ChatComponentText
import net.minecraft.util.ChatComponentTranslation
import net.minecraft.util.StatCollector
@ -23,7 +26,12 @@ object Localization {
def localizeImmediately(key: String) = StatCollector.translateToLocal(resolveKey(key)).split(nl).map(_.trim).mkString("\n")
object Analyzer {
def Address(value: String) = localizeLater("gui.Analyzer.Address", value)
def Address(value: String) = {
val result = localizeLater("gui.Analyzer.Address", value)
result.getChatStyle.setChatClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, s"/${SetClipboardCommand.name} $value"))
result.getChatStyle.setChatHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, localizeLater("gui.Analyzer.CopyToClipboard")))
result
}
def AddressCopied = localizeLater("gui.Analyzer.AddressCopied")

View File

@ -8,7 +8,7 @@ import cpw.mods.fml.common.event._
import cpw.mods.fml.common.network.FMLEventChannel
import li.cil.oc.common.IMC
import li.cil.oc.common.Proxy
import li.cil.oc.server.CommandHandler
import li.cil.oc.server.command.CommandHandler
import org.apache.logging.log4j.LogManager
@Mod(modid = OpenComputers.ID, name = OpenComputers.Name,

View File

@ -0,0 +1,31 @@
package li.cil.oc.client
import li.cil.oc.common.command.SimpleCommand
import net.minecraft.client.gui.GuiScreen
import net.minecraft.command.ICommandSender
import net.minecraftforge.client.ClientCommandHandler
object CommandHandler {
def register(): Unit = {
ClientCommandHandler.instance.registerCommand(SetClipboardCommand)
}
object SetClipboardCommand extends SimpleCommand("oc_setclipboard") {
override def getCommandUsage(source: ICommandSender): String = name + " <value>"
override def processCommand(source: ICommandSender, command: Array[String]): Unit = {
if (source.getEntityWorld.isRemote && command != null && command.length > 0) {
GuiScreen.setClipboardString(command(0))
}
}
// OP levels for reference:
// 1 - Ops can bypass spawn protection.
// 2 - Ops can use /clear, /difficulty, /effect, /gamemode, /gamerule, /give, /summon, /setblock and /tp, and can edit command blocks.
// 3 - Ops can use /ban, /deop, /kick, and /op.
// 4 - Ops can use /stop.
override def getRequiredPermissionLevel = 0
}
}

View File

@ -36,6 +36,8 @@ private[oc] class Proxy extends CommonProxy {
api.API.manual = client.Manual
CommandHandler.register()
MinecraftForge.EVENT_BUS.register(gui.Icons)
}

View File

@ -0,0 +1,21 @@
package li.cil.oc.common.command
import net.minecraft.command.CommandBase
import net.minecraft.command.ICommandSender
import scala.collection.convert.WrapAsJava._
import scala.collection.mutable
abstract class SimpleCommand(val name: String) extends CommandBase {
protected var aliases = mutable.ListBuffer.empty[String]
override def getCommandName = name
override def getCommandAliases = aliases
override def canCommandSenderUseCommand(source: ICommandSender) = true
override def isUsernameIndex(command: Array[String], i: Int) = false
override def addTabCompletionOptions(source: ICommandSender, command: Array[String]) = List.empty[AnyRef]
}

View File

@ -1,89 +0,0 @@
package li.cil.oc.server
import cpw.mods.fml.common.event.FMLServerStartingEvent
import li.cil.oc.Settings
import net.minecraft.command.CommandBase
import net.minecraft.command.ICommandSender
import net.minecraft.command.WrongUsageException
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.nbt.NBTTagCompound
import scala.collection.convert.wrapAsJava._
import scala.collection.mutable
object CommandHandler {
def register(e: FMLServerStartingEvent) {
e.registerServerCommand(WirelessRenderingCommand)
e.registerServerCommand(NonDisassemblyAgreementCommand)
}
// OP levels for reference:
// 1 - Ops can bypass spawn protection.
// 2 - Ops can use /clear, /difficulty, /effect, /gamemode, /gamerule, /give, /summon, /setblock and /tp, and can edit command blocks.
// 3 - Ops can use /ban, /deop, /kick, and /op.
// 4 - Ops can use /stop.
object WirelessRenderingCommand extends SimpleCommand("oc_renderWirelessNetwork") {
aliases += "oc_wlan"
override def getCommandUsage(source: ICommandSender) = name + " <boolean>"
override def processCommand(source: ICommandSender, command: Array[String]) {
Settings.rTreeDebugRenderer =
if (command != null && command.length > 0)
CommandBase.parseBoolean(source, command(0))
else
!Settings.rTreeDebugRenderer
}
override def getRequiredPermissionLevel = 2
}
object NonDisassemblyAgreementCommand extends SimpleCommand("oc_preventDisassembling") {
aliases += "oc_nodis"
aliases += "oc_prevdis"
override def getCommandUsage(source: ICommandSender) = name + " <boolean>"
override def processCommand(source: ICommandSender, command: Array[String]) {
source match {
case player: EntityPlayer =>
val stack = player.getHeldItem
if (stack != null) {
if (!stack.hasTagCompound) {
stack.setTagCompound(new NBTTagCompound())
}
val nbt = stack.getTagCompound
val preventDisassembly =
if (command != null && command.length > 0)
CommandBase.parseBoolean(source, command(0))
else
!nbt.getBoolean(Settings.namespace + "undisassemblable")
if (preventDisassembly)
nbt.setBoolean(Settings.namespace + "undisassemblable", true)
else
nbt.removeTag(Settings.namespace + "undisassemblable")
if (nbt.hasNoTags) stack.setTagCompound(null)
}
case _ => throw new WrongUsageException("Can only be used by players.")
}
}
override def getRequiredPermissionLevel = 2
}
abstract class SimpleCommand(val name: String) extends CommandBase {
protected var aliases = mutable.ListBuffer.empty[String]
override def getCommandName = name
override def getCommandAliases = aliases
override def canCommandSenderUseCommand(source: ICommandSender) = true
override def isUsernameIndex(command: Array[String], i: Int) = false
override def addTabCompletionOptions(source: ICommandSender, command: Array[String]) = List.empty[AnyRef]
}
}

View File

@ -0,0 +1,10 @@
package li.cil.oc.server.command
import cpw.mods.fml.common.event.FMLServerStartingEvent
object CommandHandler {
def register(e: FMLServerStartingEvent) {
e.registerServerCommand(WirelessRenderingCommand)
e.registerServerCommand(NonDisassemblyAgreementCommand)
}
}

View File

@ -0,0 +1,48 @@
package li.cil.oc.server.command
import li.cil.oc.Settings
import li.cil.oc.common.command.SimpleCommand
import net.minecraft.command.CommandBase
import net.minecraft.command.ICommandSender
import net.minecraft.command.WrongUsageException
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.nbt.NBTTagCompound
object NonDisassemblyAgreementCommand extends SimpleCommand("oc_preventDisassembling") {
aliases += "oc_nodis"
aliases += "oc_prevdis"
override def getCommandUsage(source: ICommandSender) = name + " <boolean>"
override def processCommand(source: ICommandSender, command: Array[String]) {
source match {
case player: EntityPlayer =>
val stack = player.getHeldItem
if (stack != null) {
if (!stack.hasTagCompound) {
stack.setTagCompound(new NBTTagCompound())
}
val nbt = stack.getTagCompound
val preventDisassembly =
if (command != null && command.length > 0)
CommandBase.parseBoolean(source, command(0))
else
!nbt.getBoolean(Settings.namespace + "undisassemblable")
if (preventDisassembly)
nbt.setBoolean(Settings.namespace + "undisassemblable", true)
else
nbt.removeTag(Settings.namespace + "undisassemblable")
if (nbt.hasNoTags) stack.setTagCompound(null)
}
case _ => throw new WrongUsageException("Can only be used by players.")
}
}
// OP levels for reference:
// 1 - Ops can bypass spawn protection.
// 2 - Ops can use /clear, /difficulty, /effect, /gamemode, /gamerule, /give, /summon, /setblock and /tp, and can edit command blocks.
// 3 - Ops can use /ban, /deop, /kick, and /op.
// 4 - Ops can use /stop.
override def getRequiredPermissionLevel = 2
}

View File

@ -0,0 +1,28 @@
package li.cil.oc.server.command
import li.cil.oc.Settings
import li.cil.oc.common.command.SimpleCommand
import net.minecraft.command.CommandBase
import net.minecraft.command.ICommandSender
object WirelessRenderingCommand extends SimpleCommand("oc_renderWirelessNetwork") {
aliases += "oc_wlan"
override def getCommandUsage(source: ICommandSender) = name + " <boolean>"
override def processCommand(source: ICommandSender, command: Array[String]) {
Settings.rTreeDebugRenderer =
if (command != null && command.length > 0)
CommandBase.parseBoolean(source, command(0))
else
!Settings.rTreeDebugRenderer
}
// OP levels for reference:
// 1 - Ops can bypass spawn protection.
// 2 - Ops can use /clear, /difficulty, /effect, /gamemode, /gamerule, /give, /summon, /setblock and /tp, and can edit command blocks.
// 3 - Ops can use /ban, /deop, /kick, and /op.
// 4 - Ops can use /stop.
override def getRequiredPermissionLevel = 2
}