Button library supports click sound

This commit is contained in:
Olof Larsson 2016-03-15 22:50:41 +01:00
parent 301c5a766b
commit 1f94c0c1cd
4 changed files with 28 additions and 8 deletions

View File

@ -9,9 +9,12 @@ import org.bukkit.command.CommandSender;
import com.massivecraft.massivecore.collections.MassiveList; import com.massivecraft.massivecore.collections.MassiveList;
import com.massivecraft.massivecore.command.MassiveCommand; 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.Requirement;
import com.massivecraft.massivecore.command.requirement.RequirementAbstract; import com.massivecraft.massivecore.command.requirement.RequirementAbstract;
import com.massivecraft.massivecore.mson.Mson; import com.massivecraft.massivecore.mson.Mson;
import com.massivecraft.massivecore.mson.MsonEvent;
import static com.massivecraft.massivecore.mson.Mson.mson; import static com.massivecraft.massivecore.mson.Mson.mson;
public class Button public class Button
@ -86,6 +89,10 @@ public class Button
public Button setArgs(Collection<String> args) { this.args = new MassiveList<>(args); return this; } public Button setArgs(Collection<String> args) { this.args = new MassiveList<>(args); return this; }
public Button setArgs(String... args) { this.setArgs(Arrays.asList(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 // FIELDS > LINK
// -------------------------------------------- // // -------------------------------------------- //
@ -133,7 +140,20 @@ public class Button
{ {
if (this.getCommand() != null) 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) else if (this.getLink() != null)
{ {

View File

@ -99,10 +99,10 @@ public class MassiveCoreMConf extends Entity<MassiveCoreMConf>
public boolean usingVariableBuffer = true; 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 // MSTORE CONFIGURATON

View File

@ -78,6 +78,7 @@ public final class SoundEffect implements Serializable
public void run(Location location) public void run(Location location)
{ {
if (location == null) return;
location.getWorld().playSound(location, this.getSound(), this.getVolume(), this.getPitch()); 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) public void run(HumanEntity human)
{ {
if (MUtil.isntPlayer(human)) return;
this.run(human, human.getEyeLocation()); this.run(human, human.getEyeLocation());
} }

View File

@ -27,7 +27,7 @@ public class CmdMassiveCoreClick extends MassiveCommand
this.addAliases("click"); this.addAliases("click");
// Parameters // 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 // Requirements
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.CLICK.node)); this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.CLICK.node));
@ -40,11 +40,9 @@ public class CmdMassiveCoreClick extends MassiveCommand
@Override @Override
public void perform() throws MassiveException public void perform() throws MassiveException
{ {
MassiveCoreMConf.get().clickSound.run(me);
String command = this.readArg(); String command = this.readArg();
if ( ! senderIsConsole) if (command == null) return;
{
MassiveCoreMConf.get().commandClickSound.run(me);
}
Mixin.dispatchCommand(sender, command); Mixin.dispatchCommand(sender, command);
} }