Button library supports click sound
This commit is contained in:
parent
301c5a766b
commit
1f94c0c1cd
@ -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<String> 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)
|
||||
{
|
||||
|
@ -99,10 +99,10 @@ public class MassiveCoreMConf extends Entity<MassiveCoreMConf>
|
||||
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
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user