This commit is contained in:
ImproperIssues
2023-04-22 21:25:59 -07:00
parent 05e9a6d03e
commit f033f73a73
6 changed files with 71 additions and 6 deletions

View File

@@ -57,6 +57,8 @@ public final class OgreDupeAlias extends JavaPlugin {
getCommand("recipespy").setTabCompleter(new RecipeSpyCommand()); getCommand("recipespy").setTabCompleter(new RecipeSpyCommand());
getCommand("irepair").setExecutor(new IRepairCommand()); getCommand("irepair").setExecutor(new IRepairCommand());
getCommand("irepair").setTabCompleter(new IRepairCommand()); getCommand("irepair").setTabCompleter(new IRepairCommand());
getCommand("message").setExecutor(new MessageCommand());
getCommand("message").setTabCompleter(new MessageCommand());
} }
public void initConfig() { public void initConfig() {

View File

@@ -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<String> 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[]{
"[<message>]"
},args.length >= 2 && args[1].isBlank())
.build();
}
}

View File

@@ -25,7 +25,9 @@ public class CommandEventListener implements Listener {
"/whisper", "/whisper",
"/w", "/w",
"/message", "/message",
"/msg" "/msg",
"/dm",
"/pm"
); );
@EventHandler @EventHandler

View File

@@ -22,15 +22,15 @@ public class InteractionListener implements Listener {
final Block b = e.getClickedBlock(); final Block b = e.getClickedBlock();
final ItemStack item = e.getItem(); final ItemStack item = e.getItem();
if (a == Action.RIGHT_CLICK_AIR || a == Action.RIGHT_CLICK_BLOCK) {
ShulkerUtils.onShulkerInteraction(e);
}
if (PlacedStructures.isCustomTable(b)) { if (PlacedStructures.isCustomTable(b)) {
e.setCancelled(true); e.setCancelled(true);
p.openInventory(InventoryPresets.createCustomTable()); p.openInventory(InventoryPresets.createCustomTable());
return; return;
} }
if (a == Action.RIGHT_CLICK_AIR || a == Action.RIGHT_CLICK_BLOCK) {
ShulkerUtils.onShulkerInteraction(e);
}
} }
catch (Exception ignore) {} catch (Exception ignore) {}
} }

View File

@@ -32,6 +32,7 @@ public abstract class ShulkerUtils {
final ItemStack item = e.getItem(); final ItemStack item = e.getItem();
final Action a = e.getAction(); final Action a = e.getAction();
if (!e.isCancelled() && a == Action.RIGHT_CLICK_BLOCK) return;
if (item == null || item.getType().isAir()) return; if (item == null || item.getType().isAir()) return;
if (a != Action.RIGHT_CLICK_BLOCK && a != Action.RIGHT_CLICK_AIR) return; if (a != Action.RIGHT_CLICK_BLOCK && a != Action.RIGHT_CLICK_AIR) return;
if (!item.getType().name().contains("SHULKER_BOX")) return; if (!item.getType().name().contains("SHULKER_BOX")) return;
@@ -48,6 +49,7 @@ public abstract class ShulkerUtils {
final Player p = (Player) e.getWhoClicked(); final Player p = (Player) e.getWhoClicked();
final ItemStack item = lastOpenedBox.get(p.getUniqueId()); final ItemStack item = lastOpenedBox.get(p.getUniqueId());
if (item == null || !item.getType().name().contains("SHULKER_BOX")) return;
final BlockStateMeta meta = (BlockStateMeta) item.getItemMeta(); final BlockStateMeta meta = (BlockStateMeta) item.getItemMeta();
final ShulkerBox box = (ShulkerBox) meta.getBlockState(); final ShulkerBox box = (ShulkerBox) meta.getBlockState();
@@ -62,6 +64,7 @@ public abstract class ShulkerUtils {
final Player p = (Player) e.getPlayer(); final Player p = (Player) e.getPlayer();
final ItemStack item = lastOpenedBox.get(p.getUniqueId()); final ItemStack item = lastOpenedBox.get(p.getUniqueId());
if (item == null || !item.getType().name().contains("SHULKER_BOX")) return;
final BlockStateMeta meta = (BlockStateMeta) item.getItemMeta(); final BlockStateMeta meta = (BlockStateMeta) item.getItemMeta();
final ShulkerBox box = (ShulkerBox) meta.getBlockState(); final ShulkerBox box = (ShulkerBox) meta.getBlockState();

View File

@@ -94,3 +94,14 @@ commands:
aliases: aliases:
- ipearlrepair - ipearlrepair
- irestock - irestock
message:
description: Private message a player
usage: /message <player> [<message>]
aliases:
- msg
- pm
- dm
- tell
- whisper
- w
- message