PlotSquared/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Helpers.java

117 lines
4.7 KiB
Java
Raw Normal View History

2014-09-22 13:02:14 +02:00
/*
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute
* and/or monetize any of our intellectual property. IntellectualCrafters is not
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB.
2014-11-05 04:42:08 +01:00
*
* >> File = Helpers.java >> Generated by: Citymonstret at 2014-08-09 01:41
2014-09-22 13:02:14 +02:00
*/
package com.intellectualcrafters.plot.commands;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
2014-09-22 13:02:14 +02:00
import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot;
2014-10-08 16:26:46 +02:00
import com.intellectualcrafters.plot.UUIDHandler;
2014-09-22 13:02:14 +02:00
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.events.PlayerPlotHelperEvent;
@SuppressWarnings("deprecation")
public class Helpers extends SubCommand {
2014-09-22 13:02:14 +02:00
2014-11-05 04:42:08 +01:00
public Helpers() {
super(Command.HELPERS, "Manage plot helpers", "helpers {add|remove} {player}", CommandCategory.ACTIONS, true);
}
2014-09-22 13:02:14 +02:00
2014-11-05 04:42:08 +01:00
@Override
public boolean execute(final Player plr, final String... args) {
if (args.length < 2) {
PlayerFunctions.sendMessage(plr, C.HELPER_NEED_ARGUMENT);
return true;
}
if (!PlayerFunctions.isInPlot(plr)) {
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT);
return true;
}
final Plot plot = PlayerFunctions.getCurrentPlot(plr);
if ((plot.owner == null) || !plot.hasRights(plr)) {
PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS);
return true;
}
if (args[0].equalsIgnoreCase("add")) {
UUID uuid;
if (args[1].equalsIgnoreCase("*")) {
uuid = DBFunc.everyone;
}
else {
uuid = UUIDHandler.getUUID(args[1]);
}
if (!plot.helpers.contains(uuid)) {
2014-10-21 11:58:52 +02:00
if (plot.owner == uuid) {
PlayerFunctions.sendMessage(plr, C.ALREADY_OWNER);
return false;
}
if (plot.trusted.contains(uuid)) {
plot.trusted.remove(uuid);
DBFunc.removeTrusted(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(uuid));
}
if (plot.denied.contains(uuid)) {
plot.denied.remove(uuid);
DBFunc.removeDenied(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(uuid));
}
plot.addHelper(uuid);
DBFunc.setHelper(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1]));
2014-11-05 04:42:08 +01:00
final PlayerPlotHelperEvent event = new PlayerPlotHelperEvent(plr, plot, uuid, true);
2014-10-21 11:58:52 +02:00
Bukkit.getPluginManager().callEvent(event);
}
else {
PlayerFunctions.sendMessage(plr, C.ALREADY_ADDED);
return false;
}
PlayerFunctions.sendMessage(plr, C.HELPER_ADDED);
return true;
2014-11-05 04:42:08 +01:00
}
else if (args[0].equalsIgnoreCase("remove")) {
if (args[1].equalsIgnoreCase("*")) {
final UUID uuid = DBFunc.everyone;
if (!plot.helpers.contains(uuid)) {
PlayerFunctions.sendMessage(plr, C.WAS_NOT_ADDED);
return true;
}
plot.removeHelper(uuid);
DBFunc.removeHelper(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1]));
PlayerFunctions.sendMessage(plr, C.HELPER_REMOVED);
return true;
}
/*
* if (!hasBeenOnServer(args[1])) {
* PlayerFunctions.sendMessage(plr, C.PLAYER_HAS_NOT_BEEN_ON);
* return true; } UUID uuid = null; if
* (Bukkit.getPlayer(args[1]) != null) { uuid =
* Bukkit.getPlayer(args[1]).getUniqueId(); } else { uuid =
* Bukkit.getOfflinePlayer(args[1]).getUniqueId(); } if (uuid ==
* null) { PlayerFunctions.sendMessage(plr,
* C.PLAYER_HAS_NOT_BEEN_ON); return true; } if
* (!plot.helpers.contains(uuid)) {
* PlayerFunctions.sendMessage(plr, C.WAS_NOT_ADDED); return
* true; }
*/
final UUID uuid = UUIDHandler.getUUID(args[1]);
plot.removeHelper(uuid);
DBFunc.removeHelper(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1]));
final PlayerPlotHelperEvent event = new PlayerPlotHelperEvent(plr, plot, uuid, false);
Bukkit.getPluginManager().callEvent(event);
PlayerFunctions.sendMessage(plr, C.HELPER_REMOVED);
}
else {
PlayerFunctions.sendMessage(plr, C.HELPER_NEED_ARGUMENT);
return true;
}
return true;
}
2014-09-22 13:02:14 +02:00
}