mirror of
https://github.com/Shiewk/SModeration.git
synced 2026-04-28 05:54:16 +02:00
Add Invsee command and permissions
This commit is contained in:
@@ -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.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;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
@@ -26,6 +27,7 @@ public final class SModeration extends JavaPlugin {
|
|||||||
public static final TextColor PRIMARY_COLOR = TextColor.color(212, 0, 255);
|
public static final TextColor PRIMARY_COLOR = TextColor.color(212, 0, 255);
|
||||||
public static final TextColor SECONDARY_COLOR = TextColor.color(52, 143, 255);
|
public static final TextColor SECONDARY_COLOR = TextColor.color(52, 143, 255);
|
||||||
public static final TextColor INACTIVE_COLOR = NamedTextColor.GRAY;
|
public static final TextColor INACTIVE_COLOR = NamedTextColor.GRAY;
|
||||||
|
public static final TextColor FAIL_COLOR = NamedTextColor.RED;
|
||||||
public static final TextComponent CHAT_PREFIX = Component.text("SM \u00BB ").color(PRIMARY_COLOR);
|
public static final TextComponent CHAT_PREFIX = Component.text("SM \u00BB ").color(PRIMARY_COLOR);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -39,6 +41,7 @@ public final class SModeration extends JavaPlugin {
|
|||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
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);
|
||||||
|
|
||||||
final PluginCommand mute = getCommand("mute");
|
final PluginCommand mute = getCommand("mute");
|
||||||
assert mute != null;
|
assert mute != null;
|
||||||
@@ -75,6 +78,11 @@ public final class SModeration extends JavaPlugin {
|
|||||||
unban.setExecutor(new UnbanCommand());
|
unban.setExecutor(new UnbanCommand());
|
||||||
unban.setTabCompleter(new UnbanCommand());
|
unban.setTabCompleter(new UnbanCommand());
|
||||||
|
|
||||||
|
final PluginCommand invsee = getCommand("invsee");
|
||||||
|
assert invsee != null;
|
||||||
|
invsee.setExecutor(new InvseeCommand());
|
||||||
|
invsee.setTabCompleter(new InvseeCommand());
|
||||||
|
|
||||||
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 InvseeCommand 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 inventory.").color(FAIL_COLOR));
|
||||||
|
} else {
|
||||||
|
human.sendMessage(CHAT_PREFIX.append(
|
||||||
|
Component.text("Opening inventory of ").color(PRIMARY_COLOR)
|
||||||
|
.append(Component.text(player.getName()).color(SECONDARY_COLOR))
|
||||||
|
.append(Component.text("."))
|
||||||
|
));
|
||||||
|
human.openInventory(player.getInventory());
|
||||||
|
}
|
||||||
|
} 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,29 @@
|
|||||||
|
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.PlayerInventory;
|
||||||
|
|
||||||
|
public class InvSeeEvents implements Listener {
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onInventoryClick(InventoryClickEvent event){
|
||||||
|
final Inventory clicked = event.getView().getTopInventory();
|
||||||
|
if (clicked instanceof PlayerInventory inventory){
|
||||||
|
final HumanEntity holder = inventory.getHolder();
|
||||||
|
if (!event.getWhoClicked().hasPermission("smod.invsee.modify")){
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (holder != null) {
|
||||||
|
if (holder.hasPermission("smod.invsee.preventmodify")){
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import de.shiewk.smoderation.punishments.Punishment;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -45,4 +46,13 @@ public abstract class PlayerUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static @Nullable Player findOnlinePlayer(String name){
|
||||||
|
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||||
|
if (onlinePlayer.getName().equalsIgnoreCase(name)){
|
||||||
|
return onlinePlayer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,6 +54,14 @@ commands:
|
|||||||
- spardon
|
- spardon
|
||||||
permission: smod.unban
|
permission: smod.unban
|
||||||
description: Unbans a banned player.
|
description: Unbans a banned player.
|
||||||
|
invsee:
|
||||||
|
usage: "§cUsage: /invsee <player>"
|
||||||
|
aliases:
|
||||||
|
- sinvsee
|
||||||
|
- smodinvsee
|
||||||
|
- invs
|
||||||
|
permission: smod.invsee
|
||||||
|
description: Views the inventory of another player.
|
||||||
permissions:
|
permissions:
|
||||||
smod.mute:
|
smod.mute:
|
||||||
default: op
|
default: op
|
||||||
@@ -80,4 +88,15 @@ permissions:
|
|||||||
description: Allows the player to unban other players.
|
description: Allows the player to unban other players.
|
||||||
smod.logs:
|
smod.logs:
|
||||||
default: op
|
default: op
|
||||||
description: Allows the player to view mod logs.
|
description: Allows the player to view mod logs.
|
||||||
|
smod.invsee:
|
||||||
|
default: op
|
||||||
|
description: Allows the player to view other players inventories.
|
||||||
|
smod.invsee.modify:
|
||||||
|
default: op
|
||||||
|
description: Allows the player to view and modify other players inventories.
|
||||||
|
children:
|
||||||
|
- smod.invsee
|
||||||
|
smod.invsee.preventmodify:
|
||||||
|
default: op
|
||||||
|
description: When giving this permission to a player, prevents their inventory from being modified.
|
||||||
Reference in New Issue
Block a user