From 1a03c2fc720ddc989704b9e6a69dea3f86cfbea7 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Tue, 9 Oct 2018 16:50:22 -0500 Subject: [PATCH] Added death mute command --- src/main/java/xyz/etztech/qol/QoL.java | 16 ++++-- .../qol/commands/DeathMuteCommand.java | 56 +++++++++++++++++++ .../etztech/qol/listeners/DeathListener.java | 15 +++-- src/main/resources/plugin.yml | 6 ++ 4 files changed, 83 insertions(+), 10 deletions(-) create mode 100644 src/main/java/xyz/etztech/qol/commands/DeathMuteCommand.java diff --git a/src/main/java/xyz/etztech/qol/QoL.java b/src/main/java/xyz/etztech/qol/QoL.java index 16deff9..18f78c7 100644 --- a/src/main/java/xyz/etztech/qol/QoL.java +++ b/src/main/java/xyz/etztech/qol/QoL.java @@ -13,6 +13,7 @@ import xyz.etztech.qol.other.TPSRunnable; import java.util.ArrayList; import java.util.List; +import java.util.UUID; import java.util.logging.Logger; @MavenLibrary(group = "net.ess3", artifact = "Essentials", version = "2.13.1", repository = "http://repo.ess3.net/content/groups/essentials") @@ -28,6 +29,7 @@ public class QoL extends MavenPlugin { private Logger log = Logger.getLogger( "Minecraft" ); private static List mutes = new ArrayList<>(); + private static List deathMutes = new ArrayList<>(); private static boolean whitelist = false; private static boolean timeout = false; private static List audits = new ArrayList<>(); @@ -93,6 +95,8 @@ public class QoL extends MavenPlugin { this.getCommand("colors").setExecutor(colorsCommand); WorldInfoCommand worldInfoCommand = new WorldInfoCommand(this); this.getCommand("worldinfo").setExecutor(worldInfoCommand); + DeathMuteCommand deathMuteCommand = new DeathMuteCommand(this); + this.getCommand("deathmute").setExecutor(deathMuteCommand); if (getConfig().getStringList("list").size() > 0) { ListCommand listCommand = new ListCommand(this); @@ -218,12 +222,16 @@ public class QoL extends MavenPlugin { } } - - - public static boolean hasSM(Player player) { - return mutes.contains(player.getUniqueId().toString()); + public static void addDeathMute(Player player) { + deathMutes.add(player.getUniqueId()); } + + + public static boolean hasSM(Player player) { return mutes.contains(player.getUniqueId().toString()); } + + public static boolean hasDeathMute(Player player) { return deathMutes.contains(player.getUniqueId()); } + public static void removeSM(Player player) { mutes.remove(player.getUniqueId().toString()); } diff --git a/src/main/java/xyz/etztech/qol/commands/DeathMuteCommand.java b/src/main/java/xyz/etztech/qol/commands/DeathMuteCommand.java new file mode 100644 index 0000000..381f628 --- /dev/null +++ b/src/main/java/xyz/etztech/qol/commands/DeathMuteCommand.java @@ -0,0 +1,56 @@ +package xyz.etztech.qol.commands; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import xyz.etztech.qol.EtzTechUtil; +import xyz.etztech.qol.Lang; +import xyz.etztech.qol.QoL; + +public class DeathMuteCommand implements CommandExecutor { + + QoL plugin; + + public DeathMuteCommand(QoL paramQoL) + { + this.plugin = paramQoL; + } + + @Override + public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) { + if (!commandSender.hasPermission("qol.deathmute")) { + EtzTechUtil.sms(commandSender, Lang.NO_PERMISSION.getDef()); + return true; + } + + if (args.length < 1) { + EtzTechUtil.sms(commandSender, ChatColor.RED + "/dm "); + return true; + } + + Player argPlayer = null; + for (Player onlinePlayer : Bukkit.getOnlinePlayers()) { + if (onlinePlayer.getName().equalsIgnoreCase(args[0])) { + argPlayer = onlinePlayer; + } + } + + if (argPlayer == null) { + EtzTechUtil.sms(commandSender, ChatColor.RED + "No player found."); + return true; + } + final Player player = argPlayer; + + + EtzTechUtil.sms(commandSender, ChatColor.GREEN + "Death Muting " + ChatColor.YELLOW + + player.getName()); + + QoL.addDeathMute(player); + return true; + } + + +} diff --git a/src/main/java/xyz/etztech/qol/listeners/DeathListener.java b/src/main/java/xyz/etztech/qol/listeners/DeathListener.java index c958dae..116db78 100644 --- a/src/main/java/xyz/etztech/qol/listeners/DeathListener.java +++ b/src/main/java/xyz/etztech/qol/listeners/DeathListener.java @@ -26,16 +26,19 @@ public class DeathListener implements Listener { @EventHandler public void onDeath(PlayerDeathEvent event) { String message = event.getDeathMessage(); + event.setDeathMessage(""); - Location location = event.getEntity().getLocation(); - String coords = StringUtils.join(Arrays.asList(location.getBlockX(), location.getBlockY(), location.getBlockZ()), ", "); + if (!plugin.hasDeathMute(event.getEntity().getPlayer())) { + Location location = event.getEntity().getLocation(); + String coords = StringUtils.join(Arrays.asList(location.getBlockX(), location.getBlockY(), location.getBlockZ()), ", "); - TextComponent newMessage = new TextComponent(message); - newMessage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Location: " + coords).create())); + TextComponent newMessage = new TextComponent(message); + newMessage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Location: " + coords).create())); - for (Player player : Bukkit.getOnlinePlayers()) { - player.spigot().sendMessage(newMessage); + for (Player player : Bukkit.getOnlinePlayers()) { + player.spigot().sendMessage(newMessage); + } } } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 05091c3..c8672a2 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -33,6 +33,9 @@ commands: shadowmute: description: Shadow Mute command aliases: [sm] + deathmute: + description: Death mute command + aliases: [dm] whitelist: description: Whitelist command timeout: @@ -65,6 +68,9 @@ permissions: qol.shadowmute: description: Ability to use the Shadow Mute command default: op + qol.deathmute: + description: Ability to use the Death Mute command + default: op qol.auditable: description: Audits command usage default: op