diff --git a/src/main/java/me/totalfreedom/plex/command/impl/FreezeCMD.java b/src/main/java/me/totalfreedom/plex/command/impl/FreezeCMD.java new file mode 100644 index 0000000..d07c4b1 --- /dev/null +++ b/src/main/java/me/totalfreedom/plex/command/impl/FreezeCMD.java @@ -0,0 +1,44 @@ +package me.totalfreedom.plex.command.impl; + +import me.totalfreedom.plex.cache.PlayerCache; +import me.totalfreedom.plex.command.PlexCommand; +import me.totalfreedom.plex.command.annotation.CommandParameters; +import me.totalfreedom.plex.command.annotation.CommandPermissions; +import me.totalfreedom.plex.command.exception.CommandArgumentException; +import me.totalfreedom.plex.command.source.CommandSource; +import me.totalfreedom.plex.player.PunishedPlayer; +import me.totalfreedom.plex.rank.enums.Rank; +import me.totalfreedom.plex.util.PlexUtils; +import org.bukkit.entity.Player; + +import java.util.List; + +import static me.totalfreedom.plex.util.PlexUtils.tl; + +@CommandParameters(description = "Freeze/unfreeze a player on the server", usage = "/ ") +@CommandPermissions(level = Rank.ADMIN) +public class FreezeCMD extends PlexCommand +{ + public FreezeCMD() + { + super("freeze"); + } + + @Override + public void execute(CommandSource sender, String[] args) + { + if (args.length != 1) + throw new CommandArgumentException(); + Player player = getNonNullPlayer(args[0]); + PunishedPlayer punishedPlayer = PlayerCache.getPunishedPlayer(player.getUniqueId()); + punishedPlayer.setFrozen(!punishedPlayer.isFrozen()); + PlexUtils.broadcast(punishedPlayer.isFrozen() ? tl("frozePlayer", sender.getName(), player.getName()) : + tl("unfrozePlayer", sender.getName(), player.getName())); + } + + @Override + public List onTabComplete(CommandSource sender, String[] args) + { + return args.length == 1 ? PlexUtils.getPlayerNameList() : null; + } +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/plex/command/impl/OpCMD.java b/src/main/java/me/totalfreedom/plex/command/impl/OpCMD.java index fb6c751..1b0dcf5 100644 --- a/src/main/java/me/totalfreedom/plex/command/impl/OpCMD.java +++ b/src/main/java/me/totalfreedom/plex/command/impl/OpCMD.java @@ -28,6 +28,7 @@ public class OpCMD extends PlexCommand if (args.length != 1) throw new CommandArgumentException(); Player player = getNonNullPlayer(args[0]); + player.setOp(true); PlexUtils.broadcast(tl("oppedPlayer", sender.getName(), player.getName())); } diff --git a/src/main/java/me/totalfreedom/plex/event/PunishedPlayerEvent.java b/src/main/java/me/totalfreedom/plex/event/PunishedPlayerEvent.java new file mode 100644 index 0000000..6ae8e6d --- /dev/null +++ b/src/main/java/me/totalfreedom/plex/event/PunishedPlayerEvent.java @@ -0,0 +1,24 @@ +package me.totalfreedom.plex.event; + +import lombok.Getter; +import lombok.Setter; +import me.totalfreedom.plex.player.PunishedPlayer; +import org.bukkit.Bukkit; +import org.bukkit.event.Cancellable; +import org.bukkit.event.player.PlayerEvent; + +import java.util.UUID; + +@Getter +public abstract class PunishedPlayerEvent extends PlayerEvent implements Cancellable +{ + protected PunishedPlayer punishedPlayer; + @Setter + protected boolean cancelled; + + protected PunishedPlayerEvent(PunishedPlayer punishedPlayer) + { + super(Bukkit.getPlayer(UUID.fromString(punishedPlayer.getUuid()))); + this.punishedPlayer = punishedPlayer; + } +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/plex/event/PunishedPlayerFreezeEvent.java b/src/main/java/me/totalfreedom/plex/event/PunishedPlayerFreezeEvent.java new file mode 100644 index 0000000..80fea66 --- /dev/null +++ b/src/main/java/me/totalfreedom/plex/event/PunishedPlayerFreezeEvent.java @@ -0,0 +1,33 @@ +package me.totalfreedom.plex.event; + +import lombok.Getter; +import me.totalfreedom.plex.player.PunishedPlayer; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; +@Getter +public class PunishedPlayerFreezeEvent extends PunishedPlayerEvent implements Cancellable +{ + private static final HandlerList handlers = new HandlerList(); + + /** + * Status of the Punished Player being frozen before the event's occurrence. + */ + private final boolean frozen; + + public PunishedPlayerFreezeEvent(PunishedPlayer punishedPlayer, boolean frozen) + { + super(punishedPlayer); + this.frozen = frozen; + } + + @Override + public HandlerList getHandlers() + { + return handlers; + } + + public static HandlerList getHandlerList() + { + return handlers; + } +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/plex/handlers/CommandHandler.java b/src/main/java/me/totalfreedom/plex/handlers/CommandHandler.java index 3fd6442..c0f7a56 100644 --- a/src/main/java/me/totalfreedom/plex/handlers/CommandHandler.java +++ b/src/main/java/me/totalfreedom/plex/handlers/CommandHandler.java @@ -20,6 +20,7 @@ public class CommandHandler commands.add(new WorldCMD()); commands.add(new OpAllCMD()); commands.add(new OpCMD()); + commands.add(new FreezeCMD()); PlexLog.log(String.format("Registered %s commands!", commands.size())); } diff --git a/src/main/java/me/totalfreedom/plex/handlers/ListenerHandler.java b/src/main/java/me/totalfreedom/plex/handlers/ListenerHandler.java index 8d3fe5a..005dd84 100644 --- a/src/main/java/me/totalfreedom/plex/handlers/ListenerHandler.java +++ b/src/main/java/me/totalfreedom/plex/handlers/ListenerHandler.java @@ -2,10 +2,7 @@ package me.totalfreedom.plex.handlers; import com.google.common.collect.Lists; import me.totalfreedom.plex.listener.PlexListener; -import me.totalfreedom.plex.listener.impl.ChatListener; -import me.totalfreedom.plex.listener.impl.FreezeListener; -import me.totalfreedom.plex.listener.impl.PlayerListener; -import me.totalfreedom.plex.listener.impl.WorldListener; +import me.totalfreedom.plex.listener.impl.*; import me.totalfreedom.plex.util.PlexLog; import java.util.List; diff --git a/src/main/java/me/totalfreedom/plex/player/PunishedPlayer.java b/src/main/java/me/totalfreedom/plex/player/PunishedPlayer.java index b23511e..9da83cb 100644 --- a/src/main/java/me/totalfreedom/plex/player/PunishedPlayer.java +++ b/src/main/java/me/totalfreedom/plex/player/PunishedPlayer.java @@ -4,9 +4,10 @@ import java.util.UUID; import lombok.AccessLevel; import lombok.Getter; import lombok.Setter; +import me.totalfreedom.plex.event.PunishedPlayerFreezeEvent; +import org.bukkit.Bukkit; @Getter -@Setter public class PunishedPlayer { //everything in here will be stored in redis @@ -23,4 +24,11 @@ public class PunishedPlayer this.frozen = false; } + public void setFrozen(boolean frozen) + { + PunishedPlayerFreezeEvent e = new PunishedPlayerFreezeEvent(this, this.frozen); + Bukkit.getServer().getPluginManager().callEvent(e); + if (!e.isCancelled()) + this.frozen = frozen; + } } diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index d4ff6bf..f67ef76 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -29,10 +29,16 @@ noAdminWorldBlockBreak: You are not allowed to break blocks in the admin worl # 1: the world you have been teleported to playerWorldTeleport: You have been teleported to . # 1: the command sender who opped everyone -oppedAllPlayers: has opped all players on the server +oppedAllPlayers: - Opped all players on the server # 1: the person who is opping # 2: the person who has been opped -oppedPlayer: has opped +oppedPlayer: - Opped +# 1: the person who is freezing +# 2: the person who has been frozen +frozePlayer: - Froze +# 1: the person who is unfreezing +# 2: the person who has been unfrozen +unfrozePlayer: - Unfroze noPermission: You cannot use this command! # 1: the login message (uncolored) of the rank required to use the command noPermissionRank: You must be at least rank to use this command!