Added freeze command.

This commit is contained in:
Brianna O'Keefe 2019-02-27 16:45:39 -05:00
parent 8fc1b1fe59
commit 7e38aa2107
11 changed files with 175 additions and 16 deletions

View File

@ -1,8 +1,7 @@
package com.songoda.ultimatemoderation;
import com.songoda.ultimatemoderation.command.CommandManager;
import com.songoda.ultimatemoderation.listeners.ChatListener;
import com.songoda.ultimatemoderation.listeners.LoginListener;
import com.songoda.ultimatemoderation.listeners.*;
import com.songoda.ultimatemoderation.utils.Methods;
import com.songoda.ultimatemoderation.utils.SettingsManager;
import org.bukkit.Bukkit;
@ -64,6 +63,9 @@ public class UltimateModeration extends JavaPlugin {
this.commandManager = new CommandManager(this);
// Register Listeners
Bukkit.getPluginManager().registerEvents(new MoveListener(this), this);
Bukkit.getPluginManager().registerEvents(new DropListener(this), this);
Bukkit.getPluginManager().registerEvents(new InventoryListener(this), this);
Bukkit.getPluginManager().registerEvents(new ChatListener(this), this);
Bukkit.getPluginManager().registerEvents(new LoginListener(this), this);

View File

@ -32,6 +32,7 @@ public class CommandManager implements CommandExecutor {
instance.getCommand("Vanish").setExecutor(this);
instance.getCommand("ViewEnderChest").setExecutor(this);
instance.getCommand("InvSee").setExecutor(this);
instance.getCommand("Freeze").setExecutor(this);
AbstractCommand commandUltimateModeration = addCommand(new CommandUltimateModeration());
addCommand(new CommandClearChat());
@ -40,6 +41,7 @@ public class CommandManager implements CommandExecutor {
addCommand(new CommandVanish());
addCommand(new CommandViewEnderChest());
addCommand(new CommandInvSee());
addCommand(new CommandFreeze());
addCommand(new CommandSettings(commandUltimateModeration));
addCommand(new CommandReload(commandUltimateModeration));

View File

@ -0,0 +1,70 @@
package com.songoda.ultimatemoderation.command.commands;
import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.command.AbstractCommand;
import com.songoda.ultimatemoderation.utils.Methods;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class CommandFreeze extends AbstractCommand {
private static List<UUID> frozen = new ArrayList<>();
public CommandFreeze() {
super(true, true,"Freeze");
}
@Override
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) {
if (args.length != 1)
return ReturnType.SYNTAX_ERROR;
Player player = Bukkit.getPlayer(args[0]);
if (player == null) {
sender.sendMessage(instance.getReferences().getPrefix() + "That player does not exist or is not online.");
return ReturnType.FAILURE;
}
if (frozen.contains(player.getUniqueId())) {
frozen.remove(player.getUniqueId());
sender.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.freeze.remove", player.getDisplayName()));
player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.freeze.alertremove"));
} else {
frozen.add(player.getUniqueId());
sender.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.freeze.add", player.getDisplayName()));
player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.freeze.alertadd"));
}
return ReturnType.SUCCESS;
}
public static boolean isFrozen(Player player) {
return frozen.contains(player.getUniqueId());
}
@Override
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) {
return null;
}
@Override
public String getPermissionNode() {
return "um.freeze";
}
@Override
public String getSyntax() {
return "/Freeze <player>";
}
@Override
public String getDescription() {
return "Allows you to freeze a player.";
}
}

View File

@ -11,7 +11,7 @@ import java.util.List;
public class CommandInvSee extends AbstractCommand {
public CommandInvSee() {
super(true, true,"Inv1See");
super(true, true,"InvSee");
}
@Override
@ -35,10 +35,6 @@ public class CommandInvSee extends AbstractCommand {
return null;
}
private boolean isForced(String[] args) {
return args.length != 0 && args[0].equals("force");
}
@Override
public String getPermissionNode() {
return "um.invsee";
@ -51,6 +47,6 @@ public class CommandInvSee extends AbstractCommand {
@Override
public String getDescription() {
return "Allows you to see inside of a players inventory.\n";
return "Allows you to see inside of a players inventory.";
}
}

View File

@ -47,6 +47,6 @@ public class CommandRandomPlayer extends AbstractCommand {
@Override
public String getDescription() {
return "Allows you to randomly teleport to a player on the server.";
return "Allows you to randomly teleport to a player on the server.";
}
}

View File

@ -38,10 +38,6 @@ public class CommandViewEnderChest extends AbstractCommand {
return null;
}
private boolean isForced(String[] args) {
return args.length != 0 && args[0].equals("force");
}
@Override
public String getPermissionNode() {
return "um.viewenderchest";
@ -54,6 +50,6 @@ public class CommandViewEnderChest extends AbstractCommand {
@Override
public String getDescription() {
return "Allows you to see inside of a players enderchest.\n";
return "Allows you to see inside of a players enderchest.";
}
}

View File

@ -0,0 +1,27 @@
package com.songoda.ultimatemoderation.listeners;
import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.command.commands.CommandFreeze;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerMoveEvent;
public class DropListener implements Listener {
private UltimateModeration instance;
public DropListener(UltimateModeration ultimateModeration) {
this.instance = ultimateModeration;
}
@EventHandler
public void onMove(PlayerDropItemEvent event) {
Player player = event.getPlayer();
if (CommandFreeze.isFrozen(player)) {
event.setCancelled(true);
player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.freeze.nope"));
}
}
}

View File

@ -0,0 +1,28 @@
package com.songoda.ultimatemoderation.listeners;
import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.command.commands.CommandFreeze;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
public class InventoryListener implements Listener {
private UltimateModeration instance;
public InventoryListener(UltimateModeration ultimateModeration) {
this.instance = ultimateModeration;
}
@EventHandler
public void onMove(InventoryClickEvent event) {
if (!(event.getWhoClicked() instanceof Player)) return;
Player player = (Player)event.getWhoClicked();
if (CommandFreeze.isFrozen(player)) {
event.setCancelled(true);
player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.freeze.nope"));
}
}
}

View File

@ -0,0 +1,28 @@
package com.songoda.ultimatemoderation.listeners;
import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.command.commands.CommandFreeze;
import com.songoda.ultimatemoderation.command.commands.CommandVanish;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerMoveEvent;
public class MoveListener implements Listener {
private UltimateModeration instance;
public MoveListener(UltimateModeration ultimateModeration) {
this.instance = ultimateModeration;
}
@EventHandler
public void onMove(PlayerMoveEvent event) {
Player player = event.getPlayer();
if (CommandFreeze.isFrozen(player)) {
event.setCancelled(true);
player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.freeze.nope"));
}
}
}

View File

@ -12,3 +12,9 @@ command.togglechat.muted = "&cChat is currently disabled, try again later."
command.vanish.toggledOn = "&7You are now visible."
command.vanish.toggledOff = "&7You are now vanished."
command.freeze.add = "&7You have frozen &6%player%&7 successfully.";
command.freeze.remove = "&7You have unfrozen &6%player%&7 successfully.";
command.freeze.alertadd = "&7You have been frozen.";
command.freeze.alertremove = "&7You have been unfrozen.";
command.freeze.nope = "&cYou cannot do that because you are currently frozen...";

View File

@ -40,3 +40,7 @@ commands:
description: InvSee
default: false
usage: /invsee
Freeze:
description: Freeze
default: false
usage: /freeze