1
mirror of https://github.com/Shiewk/SModeration.git synced 2026-04-28 05:54:16 +02:00

Add Enderchest see command and permissions

This commit is contained in:
Shy
2024-06-18 18:26:50 +02:00
parent e54f88fa5e
commit 7eeb6daa46
4 changed files with 115 additions and 1 deletions
@@ -2,6 +2,7 @@ package de.shiewk.smoderation;
import de.shiewk.smoderation.command.*; import de.shiewk.smoderation.command.*;
import de.shiewk.smoderation.event.CustomInventoryEvents; import de.shiewk.smoderation.event.CustomInventoryEvents;
import de.shiewk.smoderation.event.EnderchestSeeEvents;
import de.shiewk.smoderation.event.InvSeeEvents; import de.shiewk.smoderation.event.InvSeeEvents;
import de.shiewk.smoderation.listener.PunishmentListener; import de.shiewk.smoderation.listener.PunishmentListener;
import de.shiewk.smoderation.storage.PunishmentContainer; import de.shiewk.smoderation.storage.PunishmentContainer;
@@ -42,6 +43,7 @@ public final class SModeration extends JavaPlugin {
getPluginManager().registerEvents(new PunishmentListener(), this); getPluginManager().registerEvents(new PunishmentListener(), this);
getPluginManager().registerEvents(new CustomInventoryEvents(), this); getPluginManager().registerEvents(new CustomInventoryEvents(), this);
getPluginManager().registerEvents(new InvSeeEvents(), this); getPluginManager().registerEvents(new InvSeeEvents(), this);
getPluginManager().registerEvents(new EnderchestSeeEvents(), this);
final PluginCommand mute = getCommand("mute"); final PluginCommand mute = getCommand("mute");
assert mute != null; assert mute != null;
@@ -83,6 +85,11 @@ public final class SModeration extends JavaPlugin {
invsee.setExecutor(new InvseeCommand()); invsee.setExecutor(new InvseeCommand());
invsee.setTabCompleter(new InvseeCommand()); invsee.setTabCompleter(new InvseeCommand());
final PluginCommand ecsee = getCommand("enderchestsee");
assert ecsee != null;
ecsee.setExecutor(new EnderchestSeeCommand());
ecsee.setTabCompleter(new EnderchestSeeCommand());
container.load(SAVE_FILE); container.load(SAVE_FILE);
} }
@@ -0,0 +1,64 @@
package de.shiewk.smoderation.command;
import de.shiewk.smoderation.util.PlayerUtil;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
import static de.shiewk.smoderation.SModeration.*;
public class EnderchestSeeCommand implements CommandExecutor, TabCompleter {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (args.length < 1) {
return false;
}
if (sender instanceof HumanEntity human){
final Player player = PlayerUtil.findOnlinePlayer(args[0]);
if (player != null) {
if (human.getUniqueId().equals(player.getUniqueId())){
human.sendMessage(Component.text("You can't open your own ender chest.").color(FAIL_COLOR));
} else {
human.sendMessage(CHAT_PREFIX.append(
Component.text("Opening ender chest of ").color(PRIMARY_COLOR)
.append(Component.text(player.getName()).color(SECONDARY_COLOR))
.append(Component.text("."))
));
human.openInventory(player.getEnderChest());
}
} else {
human.sendMessage(Component.text("This player is not online.").color(FAIL_COLOR));
}
} else {
sender.sendMessage(Component.text("Only an entity that can open inventories can execute this command!").color(FAIL_COLOR));
}
return true;
}
@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (args.length > 1){
return List.of();
}
List<String> available = new ArrayList<>();
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
available.add(onlinePlayer.getName());
}
List<String> completions = new ArrayList<>();
StringUtil.copyPartialMatches(args.length > 0 ? args[0] : "", available, completions);
return completions;
}
}
@@ -0,0 +1,26 @@
package de.shiewk.smoderation.event;
import org.bukkit.entity.HumanEntity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.PlayerInventory;
public class EnderchestSeeEvents implements Listener {
@EventHandler
public void onInventoryClick(InventoryClickEvent event){
final Inventory clicked = event.getView().getTopInventory();
if (!(clicked instanceof PlayerInventory)){
final InventoryHolder holder = clicked.getHolder();
if (holder instanceof HumanEntity humanHolder){
if (!event.getWhoClicked().hasPermission("smod.enderchestsee.modify")){
event.setCancelled(true);
}
}
}
}
}
+18 -1
View File
@@ -62,6 +62,15 @@ commands:
- invs - invs
permission: smod.invsee permission: smod.invsee
description: Views the inventory of another player. description: Views the inventory of another player.
enderchestsee:
usage: "§cUsage: /enderchestsee <player>"
aliases:
- secsee
- senderchestsee
- ecsee
- ecs
permission: smod.enderchestsee
description: Views the ender chest of another player.
permissions: permissions:
smod.mute: smod.mute:
default: op default: op
@@ -99,4 +108,12 @@ permissions:
- smod.invsee - smod.invsee
smod.invsee.preventmodify: smod.invsee.preventmodify:
default: op default: op
description: When giving this permission to a player, prevents their inventory from being modified. description: When giving this permission to a player, prevents their inventory from being modified.
smod.enderchestsee:
default: op
description: Allows the player to view other players ender chests.
smod.enderchestsee.modify:
default: op
description: Allows the player to view and modify other players ender chests.
children:
- smod.enderchestsee