- Add /lockup

This commit is contained in:
Taah 2022-02-28 12:39:04 -08:00
parent 02df46c553
commit 565cef61db
9 changed files with 164 additions and 35 deletions

View File

@ -0,0 +1,61 @@
package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.cache.PlayerCache;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.player.PlexPlayer;
import dev.plex.player.PunishedPlayer;
import dev.plex.punishment.Punishment;
import dev.plex.punishment.PunishmentType;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils;
import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;
@CommandParameters(name = "lockup", description = "Lockup a player on the server", usage = "/<command> <player>")
@CommandPermissions(level = Rank.ADMIN, permission = "plex.lockup")
public class LockupCMD extends PlexCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
if (args.length != 1)
{
return usage();
}
Player player = getNonNullPlayer(args[0]);
PunishedPlayer punishedPlayer = PlayerCache.getPunishedPlayer(player.getUniqueId());
if (isAdmin(getPlexPlayer(player)))
{
if (!isConsole(sender))
{
assert playerSender != null;
PlexPlayer plexPlayer1 = getPlexPlayer(playerSender);
if (!plexPlayer1.getRankFromString().isAtLeast(getPlexPlayer(player).getRankFromString()))
{
return messageComponent("higherRankThanYou");
}
}
}
punishedPlayer.setLockedUp(!punishedPlayer.isLockedUp());
PlexUtils.broadcast(messageComponent(punishedPlayer.isLockedUp() ? "lockedUpPlayer" : "unlockedUpPlayer", sender.getName(), player.getName()));
return null;
}
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return args.length == 1 && checkTab(sender, Rank.ADMIN, "plex.mute") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
}
}

View File

@ -5,8 +5,6 @@ import lombok.Getter;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
//TODO: Event doesn't look like it is called
/**
* Event that is called when a player is frozen or unfrozen
*/

View File

@ -0,0 +1,43 @@
package dev.plex.event;
import dev.plex.player.PunishedPlayer;
import lombok.Getter;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
/**
* Event that is called when a player is frozen or unfrozen
*/
@Getter
public class PunishedPlayerLockupEvent extends PunishedPlayerEvent implements Cancellable
{
private static final HandlerList handlers = new HandlerList();
/**
* New lock up state of the player
*/
private final boolean lockedUp;
/**
* Creates a new event instance
*
* @param punishedPlayer The player who was punished
* @param lockedUp The new muted status
*/
public PunishedPlayerLockupEvent(PunishedPlayer punishedPlayer, boolean lockedUp)
{
super(punishedPlayer);
this.lockedUp = lockedUp;
}
public static HandlerList getHandlerList()
{
return handlers;
}
@Override
public HandlerList getHandlers()
{
return handlers;
}
}

View File

@ -5,8 +5,6 @@ import lombok.Getter;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
//TODO: Event doesn't look like it is called
/**
* Event that is called when a player is frozen or unfrozen
*/

View File

@ -37,6 +37,7 @@ public class CommandHandler extends PlexBase
commands.add(new FreezeCMD());
commands.add(new ListCMD());
commands.add(new LocalSpawnCMD());
commands.add(new LockupCMD());
commands.add(new MasterbuilderworldCMD());
commands.add(new MuteCMD());
commands.add(new NameHistoryCMD());

View File

@ -14,10 +14,13 @@ import java.util.UUID;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
@ -60,6 +63,10 @@ public class PlayerListener extends PlexListener
PunishedPlayer punishedPlayer = PlayerCache.getPunishedPlayer(player.getUniqueId());
PlayerCache.getPlexPlayerMap().put(player.getUniqueId(), plexPlayer); //put them into the cache
punishedPlayer.convertPunishments();
if (punishedPlayer.isLockedUp())
{
player.openInventory(player.getInventory());
}
assert plexPlayer != null;
@ -95,4 +102,24 @@ public class PlayerListener extends PlexListener
PlayerCache.getPlexPlayerMap().remove(event.getPlayer().getUniqueId()); //remove them from cache
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerInventoryClose(InventoryCloseEvent event)
{
PunishedPlayer player = PlayerCache.getPunishedPlayer(event.getPlayer().getUniqueId());
if (player.isLockedUp())
{
Bukkit.getScheduler().runTaskLater(plugin, () -> event.getPlayer().openInventory(event.getInventory()), 1L);
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onInventoryClick(InventoryClickEvent event)
{
PunishedPlayer player = PlayerCache.getPunishedPlayer(event.getWhoClicked().getUniqueId());
if (player.isLockedUp())
{
event.setCancelled(true);
}
}
}

View File

@ -5,6 +5,7 @@ import com.google.common.collect.Maps;
import dev.plex.Plex;
import dev.plex.PlexBase;
import dev.plex.event.PunishedPlayerFreezeEvent;
import dev.plex.event.PunishedPlayerLockupEvent;
import dev.plex.event.PunishedPlayerMuteEvent;
import dev.plex.punishment.Punishment;
import dev.plex.util.PlexLog;
@ -23,6 +24,7 @@ import lombok.Setter;
import lombok.SneakyThrows;
import org.apache.commons.io.FileUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.json.JSONArray;
import org.json.JSONObject;
import org.json.JSONTokener;
@ -36,12 +38,14 @@ public class PunishedPlayer extends PlexBase
private boolean muted;
private boolean frozen;
private boolean lockedUp;
public PunishedPlayer(UUID playerUUID)
{
this.uuid = playerUUID.toString();
this.muted = false;
this.frozen = false;
this.lockedUp = false;
}
public void setFrozen(boolean frozen)
@ -64,6 +68,21 @@ public class PunishedPlayer extends PlexBase
}
}
public void setLockedUp(boolean lockedUp)
{
PunishedPlayerLockupEvent e = new PunishedPlayerLockupEvent(this, this.lockedUp);
Bukkit.getServer().getPluginManager().callEvent(e);
if (!e.isCancelled())
{
this.lockedUp = lockedUp;
Player self = Bukkit.getPlayer(UUID.fromString(this.uuid));
if (self != null)
{
self.openInventory(self.getInventory());
}
}
}
public File getPunishmentsFile()
{
File folder = new File(Plex.get().getDataFolder() + File.separator + "punishments");

View File

@ -129,33 +129,6 @@ public class PlexUtils extends PlexBase
return ChatColor.translateAlternateColorCodes('&', string);
}
/*@Deprecated(forRemoval = true)
// if you think the name of this method is dumb feel free to change it i just thought it'd be cool
public static String messageComponent(String s, Object... objects)
{
if (s.equals("baseColor") || s.equals("errorColor") || s.equals("broadcastColor"))
{
return getChatColorFromConfig(plugin.messages, ChatColor.WHITE, s).toString();
}
String f = plugin.messages.getString(s);
if (f == null)
{
return ChatColor.RED + "No message";
}
for (Object object : objects)
{
f = f.replaceFirst("<v>", String.valueOf(object));
}
ChatColor base = getChatColorFromConfig(plugin.messages, ChatColor.GRAY, "baseColor");
ChatColor broadcast = getChatColorFromConfig(plugin.messages, ChatColor.AQUA, "broadcastColor");
ChatColor error = getChatColorFromConfig(plugin.messages, ChatColor.RED, "errorColor");
f = f.replaceAll("<r>", base.toString());
f = f.replaceAll("<b>", broadcast.toString());
f = f.replaceAll("<e>", error.toString());
f = color(f);
return base + f;
}*/
public static Component messageComponent(String entry, Object... objects)
{
return MiniMessage.miniMessage().parse(LegacyComponentSerializer.legacySection().serialize(LegacyComponentSerializer.legacyAmpersand().deserialize(messageString(entry, objects))));

View File

@ -39,12 +39,19 @@ frozePlayer: "<aqua><v> - Froze <v>"
# 1. The person who is unfreezing
# 2. The person who has been unfrozen
unfrozePlayer: "<aqua><v> - Unfroze <v>"
# 1. The person who is freezing
# 2. The person who has been frozen
# 1. The person who is muting
# 2. The person who has been muted
mutedPlayer: "<aqua><v> - Muted <v>"
# 1. The person who is unfreezing
# 2. The person who has been unfrozen
# 1. The person who is unmuting
# 2. The person who has been unmuted
unmutedPlayer: "<aqua><v> - Unmuted <v>"
# 1. The person who is locking up
# 2. The person who has been locked up
lockedUpPlayer: "<aqua><v> - Locking up <v>"
# 1. The person who is unlocking
# 2. The person who has been unlocked
unlockedUpPlayer: "<aqua><v> - Unlocking <v>"
noPermission: "<red>You cannot use this command!"
# 1. The rank required to use the command
noPermissionRank: "<red>You must be at least <v> to use this command!"
@ -106,6 +113,8 @@ playerNotMuted: "<red>That player is not muted!"
playerBanned: "<red>That player is already banned!"
playerFrozen: "<red>That player is already frozen!"
playerMuted: "<red>That player is already muted!"
playerLockedUp: "<red>That player is already locked up!"
muted: "<red>You are currently muted - STFU!"
teleportedToWorldSpawn: "<aqua>Teleporting to the local spawn"
toggleCommandSpy: "CommandSpy has been"