2014-09-22 13:02:14 +02:00
|
|
|
/*
|
2014-10-12 09:37:36 +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.
|
|
|
|
*
|
|
|
|
* >> 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;
|
|
|
|
|
2014-10-11 09:33:10 +02:00
|
|
|
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")
|
2014-09-24 14:21:43 +02:00
|
|
|
public class Helpers extends SubCommand {
|
2014-09-22 13:02:14 +02:00
|
|
|
|
2014-10-11 09:33:10 +02:00
|
|
|
public Helpers() {
|
2014-10-18 20:06:29 +02:00
|
|
|
super(Command.HELPERS, "Manage plot helpers", "helpers {add|remove} {player}", CommandCategory.ACTIONS, true);
|
2014-10-11 09:33:10 +02:00
|
|
|
}
|
2014-09-22 13:02:14 +02:00
|
|
|
|
2014-10-11 09:33:10 +02:00
|
|
|
@Override
|
|
|
|
public boolean execute(Player plr, 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;
|
|
|
|
}
|
|
|
|
Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
|
|
|
if ((plot.owner == null) || !plot.hasRights(plr)) {
|
|
|
|
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (args[0].equalsIgnoreCase("add")) {
|
|
|
|
if (args[1].equalsIgnoreCase("*")) {
|
|
|
|
UUID uuid = DBFunc.everyone;
|
2014-10-18 20:37:30 +02:00
|
|
|
if (!plot.helpers.contains(uuid)) {
|
2014-10-21 09:11:07 +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));
|
|
|
|
}
|
2014-10-18 20:37:30 +02:00
|
|
|
plot.addHelper(uuid);
|
|
|
|
DBFunc.setHelper(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1]));
|
|
|
|
PlayerPlotHelperEvent event = new PlayerPlotHelperEvent(plr, plot, uuid, true);
|
|
|
|
Bukkit.getPluginManager().callEvent(event);
|
|
|
|
}
|
2014-10-21 09:11:07 +02:00
|
|
|
else {
|
|
|
|
PlayerFunctions.sendMessage(plr, C.ALREADY_ADDED);
|
|
|
|
return false;
|
|
|
|
}
|
2014-10-11 09:33:10 +02:00
|
|
|
PlayerFunctions.sendMessage(plr, C.HELPER_ADDED);
|
|
|
|
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; }
|
|
|
|
*/
|
|
|
|
UUID uuid = UUIDHandler.getUUID(args[1]);
|
2014-10-18 20:37:30 +02:00
|
|
|
if (!plot.helpers.contains(uuid)) {
|
|
|
|
plot.addHelper(uuid);
|
|
|
|
DBFunc.setHelper(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1]));
|
|
|
|
PlayerPlotHelperEvent event = new PlayerPlotHelperEvent(plr, plot, uuid, true);
|
|
|
|
Bukkit.getPluginManager().callEvent(event);
|
|
|
|
}
|
2014-10-11 09:33:10 +02:00
|
|
|
PlayerFunctions.sendMessage(plr, C.HELPER_ADDED);
|
2014-10-12 09:37:36 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
if (args[0].equalsIgnoreCase("remove")) {
|
|
|
|
if (args[1].equalsIgnoreCase("*")) {
|
|
|
|
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);
|
2014-10-11 09:33:10 +02:00
|
|
|
return true;
|
|
|
|
}
|
2014-10-12 09:37:36 +02:00
|
|
|
/*
|
|
|
|
* 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; }
|
|
|
|
*/
|
|
|
|
UUID uuid = UUIDHandler.getUUID(args[1]);
|
2014-10-11 09:33:10 +02:00
|
|
|
plot.removeHelper(uuid);
|
2014-10-12 09:37:36 +02:00
|
|
|
DBFunc.removeHelper(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1]));
|
|
|
|
PlayerPlotHelperEvent event = new PlayerPlotHelperEvent(plr, plot, uuid, false);
|
|
|
|
Bukkit.getPluginManager().callEvent(event);
|
2014-10-11 09:33:10 +02:00
|
|
|
PlayerFunctions.sendMessage(plr, C.HELPER_REMOVED);
|
2014-10-12 09:37:36 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
PlayerFunctions.sendMessage(plr, C.HELPER_NEED_ARGUMENT);
|
2014-10-11 09:33:10 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2014-09-22 13:02:14 +02:00
|
|
|
}
|