From 1f94c0c1cdfde34bc2f7ab42c0ecbbae98e6a070 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Tue, 15 Mar 2016 22:50:41 +0100 Subject: [PATCH] Button library supports click sound --- src/com/massivecraft/massivecore/Button.java | 22 ++++++++++++++++++- .../massivecore/MassiveCoreMConf.java | 4 ++-- .../massivecraft/massivecore/SoundEffect.java | 2 ++ .../massivecore/CmdMassiveCoreClick.java | 8 +++---- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/com/massivecraft/massivecore/Button.java b/src/com/massivecraft/massivecore/Button.java index 46ec3d34..8a5ee813 100644 --- a/src/com/massivecraft/massivecore/Button.java +++ b/src/com/massivecraft/massivecore/Button.java @@ -9,9 +9,12 @@ import org.bukkit.command.CommandSender; import com.massivecraft.massivecore.collections.MassiveList; import com.massivecraft.massivecore.command.MassiveCommand; +import com.massivecraft.massivecore.command.massivecore.CmdMassiveCore; import com.massivecraft.massivecore.command.requirement.Requirement; import com.massivecraft.massivecore.command.requirement.RequirementAbstract; import com.massivecraft.massivecore.mson.Mson; +import com.massivecraft.massivecore.mson.MsonEvent; + import static com.massivecraft.massivecore.mson.Mson.mson; public class Button @@ -86,6 +89,10 @@ public class Button public Button setArgs(Collection args) { this.args = new MassiveList<>(args); return this; } public Button setArgs(String... args) { this.setArgs(Arrays.asList(args)); return this; } + public boolean clicking = true; + public boolean isClicking() { return this.clicking; } + public Button setClicking(boolean clicking) { this.clicking = clicking; return this; } + // -------------------------------------------- // // FIELDS > LINK // -------------------------------------------- // @@ -133,7 +140,20 @@ public class Button { if (this.getCommand() != null) { - ret = ret.command(this.getCommand(), this.getArgs()); + // Create the command line + String commandLine = this.getCommand().getCommandLine(this.getArgs()); + + // Render the corresponding tooltip + String tooltip = MsonEvent.command(commandLine).createTooltip(); + + // Possibly make command line clicking + if (this.isClicking()) commandLine = CmdMassiveCore.get().cmdMassiveCoreClick.getCommandLine(commandLine); + + // Apply command + ret = ret.command(commandLine); + + // Possibly set tooltip to hide the clicking clutter + if (this.isClicking()) ret = ret.tooltip(tooltip); } else if (this.getLink() != null) { diff --git a/src/com/massivecraft/massivecore/MassiveCoreMConf.java b/src/com/massivecraft/massivecore/MassiveCoreMConf.java index 49889118..43bef543 100644 --- a/src/com/massivecraft/massivecore/MassiveCoreMConf.java +++ b/src/com/massivecraft/massivecore/MassiveCoreMConf.java @@ -99,10 +99,10 @@ public class MassiveCoreMConf extends Entity public boolean usingVariableBuffer = true; // -------------------------------------------- // - // CLICK COMMAND + // CLICK // -------------------------------------------- // - public SoundEffect commandClickSound = SoundEffect.valueOf("UI_BUTTON_CLICK", 1.0f, 1.0f); + public SoundEffect clickSound = SoundEffect.valueOf("UI_BUTTON_CLICK", 0.75f, 1.0f); // -------------------------------------------- // // MSTORE CONFIGURATON diff --git a/src/com/massivecraft/massivecore/SoundEffect.java b/src/com/massivecraft/massivecore/SoundEffect.java index 83589978..7ec0a418 100644 --- a/src/com/massivecraft/massivecore/SoundEffect.java +++ b/src/com/massivecraft/massivecore/SoundEffect.java @@ -78,6 +78,7 @@ public final class SoundEffect implements Serializable public void run(Location location) { + if (location == null) return; location.getWorld().playSound(location, this.getSound(), this.getVolume(), this.getPitch()); } @@ -90,6 +91,7 @@ public final class SoundEffect implements Serializable public void run(HumanEntity human) { + if (MUtil.isntPlayer(human)) return; this.run(human, human.getEyeLocation()); } diff --git a/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreClick.java b/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreClick.java index 56fdb271..4cf55745 100644 --- a/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreClick.java +++ b/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreClick.java @@ -27,7 +27,7 @@ public class CmdMassiveCoreClick extends MassiveCommand this.addAliases("click"); // Parameters - this.addParameter(TypeStringCommand.get(), "command", true).setDesc("the command to perform"); + this.addParameter(null, TypeStringCommand.get(), "command", "none", true).setDesc("the command to perform"); // Requirements this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.CLICK.node)); @@ -40,11 +40,9 @@ public class CmdMassiveCoreClick extends MassiveCommand @Override public void perform() throws MassiveException { + MassiveCoreMConf.get().clickSound.run(me); String command = this.readArg(); - if ( ! senderIsConsole) - { - MassiveCoreMConf.get().commandClickSound.run(me); - } + if (command == null) return; Mixin.dispatchCommand(sender, command); }