mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-23 01:27:37 +00:00
Add blockedit command
This commit is contained in:
parent
262368ed18
commit
273dd8a5ef
@ -274,6 +274,24 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean silentCheckRank(Player player, Rank rank, String permission)
|
||||||
|
{
|
||||||
|
if (player instanceof ConsoleCommandSender)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
PlexPlayer plexPlayer = getPlexPlayer(player);
|
||||||
|
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||||
|
{
|
||||||
|
return plexPlayer.getRankFromString().isAtLeast(rank);
|
||||||
|
}
|
||||||
|
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||||
|
{
|
||||||
|
return player.hasPermission(permission);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether a sender has enough permissions or is high enough a rank
|
* Checks whether a sender has enough permissions or is high enough a rank
|
||||||
*
|
*
|
||||||
|
98
src/main/java/dev/plex/command/impl/BlockEditCMD.java
Normal file
98
src/main/java/dev/plex/command/impl/BlockEditCMD.java
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
package dev.plex.command.impl;
|
||||||
|
|
||||||
|
import dev.plex.command.PlexCommand;
|
||||||
|
import dev.plex.command.annotation.CommandParameters;
|
||||||
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
|
import dev.plex.listener.impl.BlockListener;
|
||||||
|
import dev.plex.rank.enums.Rank;
|
||||||
|
import dev.plex.util.PlexUtils;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
@CommandPermissions(level = Rank.ADMIN, permission = "plex.blockedit")
|
||||||
|
@CommandParameters(name = "blockedit", usage = "/<command> [list | purge | all | <player>]", aliases = "bedit", description = "Prevent players from modifying blocks")
|
||||||
|
public class BlockEditCMD extends PlexCommand
|
||||||
|
{
|
||||||
|
private final BlockListener bl = new BlockListener();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args)
|
||||||
|
{
|
||||||
|
if (args.length == 0)
|
||||||
|
{
|
||||||
|
return usage();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args[0].equalsIgnoreCase("list"))
|
||||||
|
{
|
||||||
|
send(sender, "The following have block modification abilities restricted:");
|
||||||
|
int count = 0;
|
||||||
|
for (String player : bl.blockedPlayers.stream().toList())
|
||||||
|
{
|
||||||
|
send(sender, "- " + player);
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
if (count == 0)
|
||||||
|
{
|
||||||
|
send(sender, "- none");
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else if (args[0].equalsIgnoreCase("purge"))
|
||||||
|
{
|
||||||
|
PlexUtils.broadcast(componentFromString(sender.getName() + " - Unblocking block modification abilities for all players").color(NamedTextColor.AQUA));
|
||||||
|
int count = 0;
|
||||||
|
for (String player : bl.blockedPlayers.stream().toList())
|
||||||
|
{
|
||||||
|
if (bl.blockedPlayers.contains(player))
|
||||||
|
{
|
||||||
|
bl.blockedPlayers.remove(player);
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return messageComponent("unblockedEditsSize", count);
|
||||||
|
}
|
||||||
|
else if (args[0].equalsIgnoreCase("all"))
|
||||||
|
{
|
||||||
|
PlexUtils.broadcast(componentFromString(sender.getName() + " - Blocking block modification abilities for all non-admins").color(NamedTextColor.RED));
|
||||||
|
int count = 0;
|
||||||
|
for (final Player player : Bukkit.getOnlinePlayers())
|
||||||
|
{
|
||||||
|
if (!silentCheckRank(player, Rank.ADMIN, "plex.blockedit"))
|
||||||
|
{
|
||||||
|
bl.blockedPlayers.add(player.getName());
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return messageComponent("blockedEditsSize", count);
|
||||||
|
}
|
||||||
|
|
||||||
|
final Player player = getNonNullPlayer(args[0]);
|
||||||
|
if (!bl.blockedPlayers.contains(player.getName()))
|
||||||
|
{
|
||||||
|
if (silentCheckRank(player, Rank.ADMIN, "plex.blockedit"))
|
||||||
|
{
|
||||||
|
send(sender, messageComponent("higherRankThanYou"));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
PlexUtils.broadcast(messageComponent("blockingEditFor", sender.getName(), player.getName()));
|
||||||
|
bl.blockedPlayers.add(player.getName());
|
||||||
|
send(player, messageComponent("yourEditsHaveBeenBlocked"));
|
||||||
|
send(sender, messageComponent("editsBlocked", player.getName()));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PlexUtils.broadcast(messageComponent("unblockingEditFor", sender.getName(), player.getName()));
|
||||||
|
bl.blockedPlayers.remove(player.getName());
|
||||||
|
send(player, messageComponent("yourEditsHaveBeenUnblocked"));
|
||||||
|
send(sender, messageComponent("editsUnblocked", player.getName()));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
40
src/main/java/dev/plex/listener/impl/BlockListener.java
Normal file
40
src/main/java/dev/plex/listener/impl/BlockListener.java
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
package dev.plex.listener.impl;
|
||||||
|
|
||||||
|
import dev.plex.listener.PlexListener;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
|
|
||||||
|
public class BlockListener extends PlexListener
|
||||||
|
{
|
||||||
|
public List<String> blockedPlayers = new ArrayList<>();
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
|
public void onBlockPlace(BlockPlaceEvent event)
|
||||||
|
{
|
||||||
|
if (blockedPlayers.size() == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (blockedPlayers.contains(event.getPlayer().getName()))
|
||||||
|
{
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
|
public void onBlockBreak(BlockBreakEvent event)
|
||||||
|
{
|
||||||
|
if (blockedPlayers.size() == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (blockedPlayers.contains(event.getPlayer().getName()))
|
||||||
|
{
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -85,7 +85,7 @@ adminRemoved: "<red><v> - Removing <v> from the admin list"
|
|||||||
adminSetRank: "<aqua><v> - Setting <v>'s rank to <v>"
|
adminSetRank: "<aqua><v> - Setting <v>'s rank to <v>"
|
||||||
# The world name
|
# The world name
|
||||||
teleportedToWorld: "<aqua>You have been teleported to the <v>."
|
teleportedToWorld: "<aqua>You have been teleported to the <v>."
|
||||||
higherRankThanYou: "<red>This player is an admin and a higher rank than you."
|
higherRankThanYou: "<red>This player is an admin or a higher rank than you."
|
||||||
playerNotAdmin: "<red>That player is not an admin."
|
playerNotAdmin: "<red>That player is not an admin."
|
||||||
playerIsAdmin: "<red>That player is already an admin."
|
playerIsAdmin: "<red>That player is already an admin."
|
||||||
rankNotFound: "<red>The rank you entered was not found."
|
rankNotFound: "<red>The rank you entered was not found."
|
||||||
@ -110,6 +110,8 @@ playerFrozen: "<red>That player is already frozen!"
|
|||||||
playerMuted: "<red>That player is already muted!"
|
playerMuted: "<red>That player is already muted!"
|
||||||
playerLockedUp: "<red>That player is already locked up!"
|
playerLockedUp: "<red>That player is already locked up!"
|
||||||
muted: "<red>You are currently muted - STFU!"
|
muted: "<red>You are currently muted - STFU!"
|
||||||
|
# 1. The command sender
|
||||||
|
# 2. The player
|
||||||
kickedPlayer: "<red><v> - Kicking <v>"
|
kickedPlayer: "<red><v> - Kicking <v>"
|
||||||
teleportedToWorldSpawn: "<aqua>Teleporting to the local spawn"
|
teleportedToWorldSpawn: "<aqua>Teleporting to the local spawn"
|
||||||
toggleCommandSpy: "<gray>CommandSpy has been"
|
toggleCommandSpy: "<gray>CommandSpy has been"
|
||||||
@ -118,5 +120,23 @@ disabled: "<gray>disabled."
|
|||||||
adminChatFormat: '<dark_gray>[<blue>AdminChat<dark_gray>] <dark_red><v> <gray>» <gold><v>'
|
adminChatFormat: '<dark_gray>[<blue>AdminChat<dark_gray>] <dark_red><v> <gray>» <gold><v>'
|
||||||
maximumPrefixLength: "<red>The maximum length for a tag may only be <v>."
|
maximumPrefixLength: "<red>The maximum length for a tag may only be <v>."
|
||||||
prefixCleared: "<aqua>Your prefix has been cleared."
|
prefixCleared: "<aqua>Your prefix has been cleared."
|
||||||
|
# 1. The player name
|
||||||
otherPrefixCleared: "<aqua>You have cleared <v>'s prefix."
|
otherPrefixCleared: "<aqua>You have cleared <v>'s prefix."
|
||||||
|
# 1. The new prefix
|
||||||
prefixSetTo: "<aqua>Your prefix has been set to <v>"
|
prefixSetTo: "<aqua>Your prefix has been set to <v>"
|
||||||
|
# 1. The amount of players whose edits are blocked
|
||||||
|
blockedEditsSize: "Blocked block modification abilities for <v> players."
|
||||||
|
# 1. The amount of players whose edits are unblocked
|
||||||
|
unblockedEditsSize: "Unblocked all block modification abilities for <v> players."
|
||||||
|
# 1. The command sender
|
||||||
|
# 2. The player name
|
||||||
|
blockingEditFor: "<red><v> - Blocking block modification abilities for <v>"
|
||||||
|
# 1. The command sender
|
||||||
|
# 2. The player name
|
||||||
|
unblockingEditFor: "<aqua><v> - Unblocking block modification abilities for <v>"
|
||||||
|
yourEditsHaveBeenBlocked: "<gray>Your block modification abilities have been blocked."
|
||||||
|
yourEditsHaveBeenUnblocked: "<gray>Your block modification abilities have been restored."
|
||||||
|
# 1. The player name
|
||||||
|
editsBlocked: "<gray>Blocked block modification abilities for <v>"
|
||||||
|
# 1. The player name
|
||||||
|
editsUnblocked: "<gray>Unblocked block modification abilities for <v>"
|
Loading…
Reference in New Issue
Block a user