From f033f73a7336de6a5e5d7e2da7c6024235d49f88 Mon Sep 17 00:00:00 2001 From: ImproperIssues Date: Sat, 22 Apr 2023 21:25:59 -0700 Subject: [PATCH] shulker --- .../ogredupealias/OgreDupeAlias.java | 2 + .../commands/commands/MessageCommand.java | 47 +++++++++++++++++++ .../events/CommandEventListener.java | 4 +- .../events/InteractionListener.java | 8 ++-- .../ogredupealias/utils/ShulkerUtils.java | 3 ++ src/main/resources/plugin.yml | 13 ++++- 6 files changed, 71 insertions(+), 6 deletions(-) create mode 100644 src/main/java/io/github/itzispyder/ogredupealias/commands/commands/MessageCommand.java diff --git a/src/main/java/io/github/itzispyder/ogredupealias/OgreDupeAlias.java b/src/main/java/io/github/itzispyder/ogredupealias/OgreDupeAlias.java index 108e887..196cc6b 100644 --- a/src/main/java/io/github/itzispyder/ogredupealias/OgreDupeAlias.java +++ b/src/main/java/io/github/itzispyder/ogredupealias/OgreDupeAlias.java @@ -57,6 +57,8 @@ public final class OgreDupeAlias extends JavaPlugin { getCommand("recipespy").setTabCompleter(new RecipeSpyCommand()); getCommand("irepair").setExecutor(new IRepairCommand()); getCommand("irepair").setTabCompleter(new IRepairCommand()); + getCommand("message").setExecutor(new MessageCommand()); + getCommand("message").setTabCompleter(new MessageCommand()); } public void initConfig() { diff --git a/src/main/java/io/github/itzispyder/ogredupealias/commands/commands/MessageCommand.java b/src/main/java/io/github/itzispyder/ogredupealias/commands/commands/MessageCommand.java new file mode 100644 index 0000000..5321c93 --- /dev/null +++ b/src/main/java/io/github/itzispyder/ogredupealias/commands/commands/MessageCommand.java @@ -0,0 +1,47 @@ +package io.github.itzispyder.ogredupealias.commands.commands; + +import io.github.itzispyder.ogredupealias.commands.CmdExHandler; +import io.github.itzispyder.ogredupealias.commands.TabComplBuilder; +import io.github.itzispyder.ogredupealias.utils.ArrayUtils; +import io.github.itzispyder.ogredupealias.utils.Text; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; +import org.bukkit.entity.Player; + +import java.util.Arrays; +import java.util.List; +import java.util.Objects; + +public class MessageCommand implements TabExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + try { + final Player messenger = (Player) sender; + final Player recipient = Bukkit.getPlayer(args[0]); + + args[0] = null; + final String msg = String.join(" ", Arrays.stream(args).filter(Objects::nonNull).toList()); + + messenger.sendMessage(Text.builder("&7[&bPM&7] &3me &7to &3" + recipient.getName() + " &8>> &b&o" + msg).color().prefix().build()); + recipient.sendMessage(Text.builder("&7[&bPM&7] &3" + messenger.getName() + " &7to &3me &8>> &b&o" + msg).color().prefix().build()); + } + catch (Exception ex) { + CmdExHandler handler = new CmdExHandler(ex,command); + sender.sendMessage(handler.getHelp()); + } + return true; + } + + @Override + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + return new TabComplBuilder(sender,command,label,args) + .add(1, ArrayUtils.toNewList(Bukkit.getOnlinePlayers(), Player::getName)) + .add(2, new String[]{ + "[]" + },args.length >= 2 && args[1].isBlank()) + .build(); + } +} diff --git a/src/main/java/io/github/itzispyder/ogredupealias/events/CommandEventListener.java b/src/main/java/io/github/itzispyder/ogredupealias/events/CommandEventListener.java index aeb99a7..c6aad83 100644 --- a/src/main/java/io/github/itzispyder/ogredupealias/events/CommandEventListener.java +++ b/src/main/java/io/github/itzispyder/ogredupealias/events/CommandEventListener.java @@ -25,7 +25,9 @@ public class CommandEventListener implements Listener { "/whisper", "/w", "/message", - "/msg" + "/msg", + "/dm", + "/pm" ); @EventHandler diff --git a/src/main/java/io/github/itzispyder/ogredupealias/events/InteractionListener.java b/src/main/java/io/github/itzispyder/ogredupealias/events/InteractionListener.java index f4cdf1c..8b86c23 100644 --- a/src/main/java/io/github/itzispyder/ogredupealias/events/InteractionListener.java +++ b/src/main/java/io/github/itzispyder/ogredupealias/events/InteractionListener.java @@ -22,15 +22,15 @@ public class InteractionListener implements Listener { final Block b = e.getClickedBlock(); final ItemStack item = e.getItem(); + if (a == Action.RIGHT_CLICK_AIR || a == Action.RIGHT_CLICK_BLOCK) { + ShulkerUtils.onShulkerInteraction(e); + } + if (PlacedStructures.isCustomTable(b)) { e.setCancelled(true); p.openInventory(InventoryPresets.createCustomTable()); return; } - - if (a == Action.RIGHT_CLICK_AIR || a == Action.RIGHT_CLICK_BLOCK) { - ShulkerUtils.onShulkerInteraction(e); - } } catch (Exception ignore) {} } diff --git a/src/main/java/io/github/itzispyder/ogredupealias/utils/ShulkerUtils.java b/src/main/java/io/github/itzispyder/ogredupealias/utils/ShulkerUtils.java index 0b528c7..5b2e5e9 100644 --- a/src/main/java/io/github/itzispyder/ogredupealias/utils/ShulkerUtils.java +++ b/src/main/java/io/github/itzispyder/ogredupealias/utils/ShulkerUtils.java @@ -32,6 +32,7 @@ public abstract class ShulkerUtils { final ItemStack item = e.getItem(); final Action a = e.getAction(); + if (!e.isCancelled() && a == Action.RIGHT_CLICK_BLOCK) return; if (item == null || item.getType().isAir()) return; if (a != Action.RIGHT_CLICK_BLOCK && a != Action.RIGHT_CLICK_AIR) return; if (!item.getType().name().contains("SHULKER_BOX")) return; @@ -48,6 +49,7 @@ public abstract class ShulkerUtils { final Player p = (Player) e.getWhoClicked(); final ItemStack item = lastOpenedBox.get(p.getUniqueId()); + if (item == null || !item.getType().name().contains("SHULKER_BOX")) return; final BlockStateMeta meta = (BlockStateMeta) item.getItemMeta(); final ShulkerBox box = (ShulkerBox) meta.getBlockState(); @@ -62,6 +64,7 @@ public abstract class ShulkerUtils { final Player p = (Player) e.getPlayer(); final ItemStack item = lastOpenedBox.get(p.getUniqueId()); + if (item == null || !item.getType().name().contains("SHULKER_BOX")) return; final BlockStateMeta meta = (BlockStateMeta) item.getItemMeta(); final ShulkerBox box = (ShulkerBox) meta.getBlockState(); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 08319f4..4b00e5c 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -93,4 +93,15 @@ commands: permission: oda.commands.irepair aliases: - ipearlrepair - - irestock \ No newline at end of file + - irestock + message: + description: Private message a player + usage: /message [] + aliases: + - msg + - pm + - dm + - tell + - whisper + - w + - message \ No newline at end of file