mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-26 10:44:42 +02:00
Move all files! Hahah
This commit is contained in:
796
src/main/java/com/intellectualcrafters/plot/BukkitMain.java
Normal file
796
src/main/java/com/intellectualcrafters/plot/BukkitMain.java
Normal file
@ -0,0 +1,796 @@
|
||||
package com.intellectualcrafters.plot;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.commands.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.plugin.java.JavaPluginLoader;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.plotme.ClassicPlotMeConnector;
|
||||
import com.intellectualcrafters.plot.database.plotme.LikePlotMeConverter;
|
||||
import com.intellectualcrafters.plot.database.plotme.PlotMeConnector_017;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.generator.BukkitHybridUtils;
|
||||
import com.intellectualcrafters.plot.generator.HybridGen;
|
||||
import com.intellectualcrafters.plot.generator.HybridUtils;
|
||||
import com.intellectualcrafters.plot.listeners.APlotListener;
|
||||
import com.intellectualcrafters.plot.listeners.ChunkListener;
|
||||
import com.intellectualcrafters.plot.listeners.ForceFieldListener;
|
||||
import com.intellectualcrafters.plot.listeners.InventoryListener;
|
||||
import com.intellectualcrafters.plot.listeners.PlayerEvents;
|
||||
import com.intellectualcrafters.plot.listeners.PlayerEvents_1_8;
|
||||
import com.intellectualcrafters.plot.listeners.PlayerEvents_1_8_3;
|
||||
import com.intellectualcrafters.plot.listeners.PlotListener;
|
||||
import com.intellectualcrafters.plot.listeners.PlotPlusListener;
|
||||
import com.intellectualcrafters.plot.listeners.TNTListener;
|
||||
import com.intellectualcrafters.plot.listeners.WorldEvents;
|
||||
import com.intellectualcrafters.plot.listeners.worldedit.WEListener;
|
||||
import com.intellectualcrafters.plot.listeners.worldedit.WESubscriber;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotManager;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.titles.AbstractTitle;
|
||||
import com.intellectualcrafters.plot.titles.DefaultTitle;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.BlockUpdateUtil;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.ConsoleColors;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.intellectualcrafters.plot.util.EventUtil;
|
||||
import com.intellectualcrafters.plot.util.InventoryUtil;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.PlayerManager;
|
||||
import com.intellectualcrafters.plot.util.SetupUtils;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitChunkManager;
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitEconHandler;
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitEventUtil;
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitInventoryUtil;
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitPlayerManager;
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitSetBlockManager;
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitSetupUtils;
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitTaskManager;
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
|
||||
import com.intellectualcrafters.plot.util.bukkit.Metrics;
|
||||
import com.intellectualcrafters.plot.util.bukkit.SendChunk;
|
||||
import com.intellectualcrafters.plot.util.bukkit.SetBlockFast;
|
||||
import com.intellectualcrafters.plot.util.bukkit.SetBlockFast_1_8;
|
||||
import com.intellectualcrafters.plot.util.bukkit.SetBlockSlow;
|
||||
import com.intellectualcrafters.plot.util.bukkit.SetGenCB;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
import com.intellectualcrafters.plot.uuid.DefaultUUIDWrapper;
|
||||
import com.intellectualcrafters.plot.uuid.LowerOfflineUUIDWrapper;
|
||||
import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper;
|
||||
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
|
||||
public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
||||
|
||||
public static BukkitMain THIS = null;
|
||||
|
||||
private int[] version;
|
||||
|
||||
@Override
|
||||
public boolean checkVersion(final int major, final int minor, final int minor2) {
|
||||
if (version == null) {
|
||||
try {
|
||||
version = new int[3];
|
||||
final String[] split = Bukkit.getBukkitVersion().split("-")[0].split("\\.");
|
||||
version[0] = Integer.parseInt(split[0]);
|
||||
version[1] = Integer.parseInt(split[1]);
|
||||
if (version.length == 3) {
|
||||
version[2] = Integer.parseInt(split[2]);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return (version[0] > major) || ((version[0] == major) && (version[1] > minor)) || ((version[0] == major) && (version[1] == minor) && (version[2] >= minor2));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
THIS = this;
|
||||
PS.instance = new PS(this);
|
||||
if (Settings.METRICS) {
|
||||
try {
|
||||
final Metrics metrics = new Metrics(this);
|
||||
metrics.start();
|
||||
log(C.PREFIX.s() + "&6Metrics enabled.");
|
||||
} catch (final Exception e) {
|
||||
log(C.PREFIX.s() + "&cFailed to load up metrics.");
|
||||
}
|
||||
} else {
|
||||
log("&dUsing metrics will allow us to improve the plugin, please consider it :)");
|
||||
}
|
||||
// File file = new File(this.getDirectory() + File.separator + "disabled.yml");
|
||||
// if (file.exists()) {
|
||||
// file.delete();
|
||||
// try {
|
||||
// String[] split = new String(Files.readAllBytes(file.toPath())).split(",");
|
||||
// for (String plugin : split) {
|
||||
// loadPlugin(plugin);
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
List<World> worlds = Bukkit.getWorlds();
|
||||
if (worlds.size() > 0) {
|
||||
UUIDHandler.cacheAll(worlds.get(0).getName());
|
||||
for (World world : worlds) {
|
||||
try {
|
||||
SetGenCB.setGenerator(world);
|
||||
} catch (Exception e) {
|
||||
log("Failed to reload world: " + world.getName());
|
||||
Bukkit.getServer().unloadWorld(world, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
PS.get().disable();
|
||||
try {
|
||||
unloadRecursively(this);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
};
|
||||
THIS = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(String message) {
|
||||
if (message == null) {
|
||||
return;
|
||||
}
|
||||
message = message.replaceAll("\u00B2", "2");
|
||||
if (THIS != null && Bukkit.getServer().getConsoleSender() != null) {
|
||||
try {
|
||||
message = ChatColor.translateAlternateColorCodes('&', message);
|
||||
if (!Settings.CONSOLE_COLOR) {
|
||||
message = ChatColor.stripColor(message);
|
||||
}
|
||||
Bukkit.getServer().getConsoleSender().sendMessage(message);
|
||||
return;
|
||||
}
|
||||
catch (Throwable e) {};
|
||||
}
|
||||
System.out.println(ConsoleColors.fromString(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
onDisable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return this.getDescription().getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleKick(UUID uuid, C c) {
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
if (player != null && player.isOnline()) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), c);
|
||||
player.teleport(player.getWorld().getSpawnLocation());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerCommands() {
|
||||
new MainCommand();
|
||||
MainCommand.subCommands.add(new Download());
|
||||
MainCommand.subCommands.add(new Disable());
|
||||
MainCommand.subCommands.add(new Update());
|
||||
MainCommand.subCommands.add(new Template());
|
||||
MainCommand.subCommands.add(new Setup());
|
||||
MainCommand.subCommands.add(new DebugUUID());
|
||||
MainCommand.subCommands.add(new DebugFill());
|
||||
MainCommand.subCommands.add(new DebugSaveTest());
|
||||
MainCommand.subCommands.add(new DebugLoadTest());
|
||||
MainCommand.subCommands.add(new CreateRoadSchematic());
|
||||
MainCommand.subCommands.add(new DebugAllowUnsafe());
|
||||
MainCommand.subCommands.add(new RegenAllRoads());
|
||||
MainCommand.subCommands.add(new DebugClear());
|
||||
MainCommand.subCommands.add(new Claim());
|
||||
MainCommand.subCommands.add(new Auto());
|
||||
MainCommand.subCommands.add(new Home());
|
||||
MainCommand.subCommands.add(new Visit());
|
||||
MainCommand.subCommands.add(new TP());
|
||||
MainCommand.subCommands.add(new Set());
|
||||
MainCommand.subCommands.add(new Toggle());
|
||||
MainCommand.subCommands.add(new Clear());
|
||||
MainCommand.subCommands.add(new Delete());
|
||||
MainCommand.subCommands.add(new SetOwner());
|
||||
if (Settings.ENABLE_CLUSTERS) {
|
||||
MainCommand.subCommands.add(new Cluster());
|
||||
}
|
||||
MainCommand.subCommands.add(new Trust());
|
||||
MainCommand.subCommands.add(new Add());
|
||||
MainCommand.subCommands.add(new Deny());
|
||||
MainCommand.subCommands.add(new Untrust());
|
||||
MainCommand.subCommands.add(new Remove());
|
||||
MainCommand.subCommands.add(new Undeny());
|
||||
MainCommand.subCommands.add(new Info());
|
||||
MainCommand.subCommands.add(new list());
|
||||
MainCommand.subCommands.add(new Help());
|
||||
MainCommand.subCommands.add(new Debug());
|
||||
MainCommand.subCommands.add(new SchematicCmd());
|
||||
MainCommand.subCommands.add(new plugin());
|
||||
MainCommand.subCommands.add(new Inventory());
|
||||
MainCommand.subCommands.add(new Purge());
|
||||
MainCommand.subCommands.add(new Reload());
|
||||
MainCommand.subCommands.add(new Merge());
|
||||
MainCommand.subCommands.add(new Unlink());
|
||||
MainCommand.subCommands.add(new Kick());
|
||||
MainCommand.subCommands.add(new Rate());
|
||||
MainCommand.subCommands.add(new DebugClaimTest());
|
||||
MainCommand.subCommands.add(new Inbox());
|
||||
MainCommand.subCommands.add(new Comment());
|
||||
MainCommand.subCommands.add(new Database());
|
||||
MainCommand.subCommands.add(new Unclaim());
|
||||
MainCommand.subCommands.add(new Swap());
|
||||
MainCommand.subCommands.add(new MusicSubcommand());
|
||||
MainCommand.subCommands.add(new DebugRoadRegen());
|
||||
MainCommand.subCommands.add(new Trim());
|
||||
MainCommand.subCommands.add(new DebugExec());
|
||||
MainCommand.subCommands.add(new FlagCmd());
|
||||
MainCommand.subCommands.add(new Target());
|
||||
MainCommand.subCommands.add(new DebugFixFlags());
|
||||
MainCommand.subCommands.add(new Move());
|
||||
MainCommand.subCommands.add(new Condense());
|
||||
MainCommand.subCommands.add(new Confirm());
|
||||
MainCommand.subCommands.add(new Copy());
|
||||
MainCommand.subCommands.add(new Chat());
|
||||
final BukkitCommand bcmd = new BukkitCommand();
|
||||
final PluginCommand plotCommand = getCommand("plots");
|
||||
plotCommand.setExecutor(bcmd);
|
||||
plotCommand.setAliases(Arrays.asList("p", "ps", "plotme", "plot"));
|
||||
plotCommand.setTabCompleter(bcmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getDirectory() {
|
||||
return getDataFolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskManager getTaskManager() {
|
||||
return new BukkitTaskManager();
|
||||
}
|
||||
|
||||
private ArrayDeque<Entity> fastTickEntities;
|
||||
private ArrayDeque<Entity> slowTickEntities;
|
||||
|
||||
@Override
|
||||
public void runEntityTask() {
|
||||
// fastTickEntities = new ArrayDeque<>();
|
||||
// slowTickEntities = new ArrayDeque<>();
|
||||
log(C.PREFIX.s() + "KillAllEntities started.");
|
||||
TaskManager.runTaskRepeat(new Runnable() {
|
||||
long ticked = 0l;
|
||||
long error = 0l;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (this.ticked > 36_000L) {
|
||||
this.ticked = 0l;
|
||||
if (this.error > 0) {
|
||||
log(C.PREFIX.s() + "KillAllEntities has been running for 6 hours. Errors: " + this.error);
|
||||
}
|
||||
this.error = 0l;
|
||||
}
|
||||
World world;
|
||||
for (final PlotWorld pw : PS.get().getPlotWorldObjects()) {
|
||||
PlotManager manager = PS.get().getPlotManager(pw.worldname);
|
||||
world = Bukkit.getWorld(pw.worldname);
|
||||
try {
|
||||
for (Entity entity : world.getEntities()) {
|
||||
switch (entity.getType()) {
|
||||
case EGG:
|
||||
case ENDER_CRYSTAL:
|
||||
case COMPLEX_PART:
|
||||
case ARMOR_STAND:
|
||||
case FISHING_HOOK:
|
||||
case ENDER_SIGNAL:
|
||||
case EXPERIENCE_ORB:
|
||||
case LEASH_HITCH:
|
||||
case FIREWORK:
|
||||
case WEATHER:
|
||||
case LIGHTNING:
|
||||
case WITHER_SKULL:
|
||||
case UNKNOWN:
|
||||
case ITEM_FRAME:
|
||||
case PAINTING:
|
||||
case PLAYER: {
|
||||
// non moving / unremovable
|
||||
continue;
|
||||
}
|
||||
case THROWN_EXP_BOTTLE:
|
||||
case SPLASH_POTION:
|
||||
case SNOWBALL:
|
||||
case ENDER_PEARL:
|
||||
case ARROW: {
|
||||
// managed elsewhere | projectile
|
||||
continue;
|
||||
}
|
||||
case MINECART:
|
||||
case MINECART_CHEST:
|
||||
case MINECART_COMMAND:
|
||||
case MINECART_FURNACE:
|
||||
case MINECART_HOPPER:
|
||||
case MINECART_MOB_SPAWNER:
|
||||
case MINECART_TNT:
|
||||
case BOAT: {
|
||||
// vehicle
|
||||
continue;
|
||||
}
|
||||
case SMALL_FIREBALL:
|
||||
case FIREBALL:
|
||||
case DROPPED_ITEM: {
|
||||
// dropped item
|
||||
continue;
|
||||
}
|
||||
case PRIMED_TNT:
|
||||
case FALLING_BLOCK: {
|
||||
// managed elsewhere
|
||||
continue;
|
||||
}
|
||||
case BAT:
|
||||
case BLAZE:
|
||||
case CAVE_SPIDER:
|
||||
case CHICKEN:
|
||||
case COW:
|
||||
case CREEPER:
|
||||
case ENDERMAN:
|
||||
case ENDERMITE:
|
||||
case ENDER_DRAGON:
|
||||
case GHAST:
|
||||
case GIANT:
|
||||
case GUARDIAN:
|
||||
case HORSE:
|
||||
case IRON_GOLEM:
|
||||
case MAGMA_CUBE:
|
||||
case MUSHROOM_COW:
|
||||
case OCELOT:
|
||||
case PIG:
|
||||
case PIG_ZOMBIE:
|
||||
case RABBIT:
|
||||
case SHEEP:
|
||||
case SILVERFISH:
|
||||
case SKELETON:
|
||||
case SLIME:
|
||||
case SNOWMAN:
|
||||
case SPIDER:
|
||||
case SQUID:
|
||||
case VILLAGER:
|
||||
case WITCH:
|
||||
case WITHER:
|
||||
case WOLF:
|
||||
case ZOMBIE:
|
||||
default: {
|
||||
Location loc = entity.getLocation();
|
||||
if (manager.getPlotIdAbs(pw, loc.getBlockX(), 0, loc.getBlockZ()) == null) {
|
||||
entity.remove();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (final Throwable e) {
|
||||
++this.error;
|
||||
} finally {
|
||||
++this.ticked;
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 20);
|
||||
}
|
||||
|
||||
public boolean unloadPlugin(Plugin plugin) {
|
||||
try {
|
||||
plugin.getClass().getClassLoader().getResources("*");
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
PluginManager pm = Bukkit.getServer().getPluginManager();
|
||||
Map<String, Plugin> ln;
|
||||
List<Plugin> pl;
|
||||
try {
|
||||
Field lnF = pm.getClass().getDeclaredField("lookupNames");
|
||||
lnF.setAccessible(true);
|
||||
ln = (Map) lnF.get(pm);
|
||||
|
||||
Field plF = pm.getClass().getDeclaredField("plugins");
|
||||
plF.setAccessible(true);
|
||||
pl = (List) plF.get(pm);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
pm.disablePlugin(plugin);
|
||||
synchronized (pm) {
|
||||
ln.remove(plugin.getName());
|
||||
pl.remove(plugin);
|
||||
}
|
||||
JavaPluginLoader jpl = (JavaPluginLoader) plugin.getPluginLoader();
|
||||
Field loadersF = null;
|
||||
try {
|
||||
loadersF = jpl.getClass().getDeclaredField("loaders");
|
||||
loadersF.setAccessible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
Map<String, ?> loaderMap = (Map) loadersF.get(jpl);
|
||||
loaderMap.remove(plugin.getDescription().getName());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
closeClassLoader(plugin);
|
||||
System.gc();
|
||||
System.gc();
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean closeClassLoader(Plugin plugin) {
|
||||
try {
|
||||
((URLClassLoader) plugin.getClass().getClassLoader()).close();
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean unloadRecursively(Plugin plugin) {
|
||||
try {
|
||||
Stack<String> pluginFiles = unloadRecursively(plugin.getName(), plugin, new Stack());
|
||||
File file = new File(this.getDirectory() + File.separator + "disabled.yml");
|
||||
file.createNewFile();
|
||||
String prefix = "";
|
||||
String all = "";
|
||||
while (pluginFiles.size() > 0) {
|
||||
String pop = pluginFiles.pop();
|
||||
all += prefix + pop.substring(0, pop.length() - 4);
|
||||
prefix = ",";
|
||||
}
|
||||
if (all.length() != 0) {
|
||||
PrintWriter out = new PrintWriter(this.getDirectory() + File.separator + "disabled.yml");
|
||||
out.write(all);
|
||||
out.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadPlugin(String name) {
|
||||
try {
|
||||
PluginManager manager = Bukkit.getServer().getPluginManager();
|
||||
Plugin plugin = manager.getPlugin(name);
|
||||
if (plugin != null) {
|
||||
manager.enablePlugin(plugin);
|
||||
return;
|
||||
}
|
||||
plugin = manager.loadPlugin(new File("plugins" + File.separator + name + (name.endsWith(".jar") ? "" : ".jar")));
|
||||
plugin.onLoad();
|
||||
manager.enablePlugin(plugin);
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getFile() {
|
||||
return getFile(this);
|
||||
}
|
||||
|
||||
public File getFile(JavaPlugin p) {
|
||||
try {
|
||||
Field f = JavaPlugin.class.getDeclaredField("file");
|
||||
f.setAccessible(true);
|
||||
return (File) f.get(p);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Stack<String> unloadRecursively(String doNotLoad, Plugin plugin, Stack<String> pluginFiles) {
|
||||
if (!plugin.getName().equals(doNotLoad)) {
|
||||
File file = getFile((JavaPlugin) plugin);
|
||||
pluginFiles.push(file.getName());
|
||||
}
|
||||
PluginManager pm = Bukkit.getPluginManager();
|
||||
for (Plugin p : pm.getPlugins()) {
|
||||
List<String> depend = p.getDescription().getDepend();
|
||||
if (depend != null) {
|
||||
for (String s : depend) {
|
||||
if (s.equals(plugin.getName())) {
|
||||
unloadRecursively(doNotLoad, p, pluginFiles);
|
||||
}
|
||||
}
|
||||
}
|
||||
List<String> softDepend = p.getDescription().getSoftDepend();
|
||||
if (softDepend != null) {
|
||||
for (String s : softDepend) {
|
||||
if (s.equals(plugin.getName())) {
|
||||
unloadRecursively(doNotLoad, p, pluginFiles);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (unloadPlugin(plugin)) {
|
||||
List<String> depend = plugin.getDescription().getDepend();
|
||||
if (depend != null) {
|
||||
for (String s : depend) {
|
||||
Plugin p = pm.getPlugin(s);
|
||||
if (p != null) {
|
||||
unloadRecursively(doNotLoad, p, pluginFiles);
|
||||
}
|
||||
}
|
||||
}
|
||||
List<String> softDepend = plugin.getDescription().getSoftDepend();
|
||||
if (softDepend != null) {
|
||||
for (String s : softDepend) {
|
||||
Plugin p = pm.getPlugin(s);
|
||||
if (p != null) {
|
||||
unloadRecursively(doNotLoad, p, pluginFiles);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return pluginFiles;
|
||||
}
|
||||
|
||||
@Override
|
||||
final public ChunkGenerator getDefaultWorldGenerator(final String world, final String id) {
|
||||
WorldEvents.lastWorld = world;
|
||||
if (!PS.get().setupPlotWorld(world, id)) {
|
||||
return null;
|
||||
}
|
||||
HybridGen result = new HybridGen(world);
|
||||
TaskManager.runTaskLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (WorldEvents.lastWorld != null && WorldEvents.lastWorld.equals(world)) {
|
||||
WorldEvents.lastWorld = null;
|
||||
}
|
||||
}
|
||||
}, 20);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerPlayerEvents() {
|
||||
getServer().getPluginManager().registerEvents(new PlayerEvents(), this);
|
||||
if (checkVersion(1, 8, 0)) {
|
||||
getServer().getPluginManager().registerEvents(new PlayerEvents_1_8(), this);
|
||||
}
|
||||
if (checkVersion(1, 8, 3)) {
|
||||
getServer().getPluginManager().registerEvents(new PlayerEvents_1_8_3(), this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerInventoryEvents() {
|
||||
getServer().getPluginManager().registerEvents(new InventoryListener(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerPlotPlusEvents() {
|
||||
PlotPlusListener.startRunnable(this);
|
||||
getServer().getPluginManager().registerEvents(new PlotPlusListener(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerForceFieldEvents() {
|
||||
getServer().getPluginManager().registerEvents(new ForceFieldListener(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerWorldEditEvents() {
|
||||
if (getServer().getPluginManager().getPlugin("WorldEdit") != null) {
|
||||
PS.get().worldEdit = (WorldEditPlugin) getServer().getPluginManager().getPlugin("WorldEdit");
|
||||
final String version = PS.get().worldEdit.getDescription().getVersion();
|
||||
if ((version != null) && version.startsWith("5.")) {
|
||||
log("&cThis version of WorldEdit does not support PlotSquared.");
|
||||
log("&cPlease use WorldEdit 6+ for masking support");
|
||||
log("&c - http://builds.enginehub.org/job/worldedit");
|
||||
} else {
|
||||
getServer().getPluginManager().registerEvents(new WEListener(), this);
|
||||
WorldEdit.getInstance().getEventBus().register(new WESubscriber());
|
||||
MainCommand.subCommands.add(new WE_Anywhere());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EconHandler getEconomyHandler() {
|
||||
try {
|
||||
BukkitEconHandler econ = new BukkitEconHandler();
|
||||
if (econ.init()) {
|
||||
return econ;
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockManager initBlockManager() {
|
||||
if (checkVersion(1, 8, 0)) {
|
||||
try {
|
||||
BukkitSetBlockManager.setBlockManager = new SetBlockFast_1_8();
|
||||
} catch (final Throwable e) {
|
||||
e.printStackTrace();
|
||||
BukkitSetBlockManager.setBlockManager = new SetBlockSlow();
|
||||
}
|
||||
try {
|
||||
new SendChunk();
|
||||
MainUtil.canSendChunk = true;
|
||||
} catch (final Throwable e) {
|
||||
MainUtil.canSendChunk = false;
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
BukkitSetBlockManager.setBlockManager = new SetBlockFast();
|
||||
} catch (final Throwable e) {
|
||||
MainUtil.canSetFast = false;
|
||||
BukkitSetBlockManager.setBlockManager = new SetBlockSlow();
|
||||
}
|
||||
}
|
||||
BlockUpdateUtil.setBlockManager = BukkitSetBlockManager.setBlockManager;
|
||||
return BlockManager.manager = new BukkitUtil();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean initPlotMeConverter() {
|
||||
TaskManager.runTaskLaterAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (new LikePlotMeConverter("PlotMe").run(new ClassicPlotMeConnector())) return;
|
||||
if (new LikePlotMeConverter("PlotMe").run(new PlotMeConnector_017())) return;
|
||||
if (new LikePlotMeConverter("AthionPlots").run(new ClassicPlotMeConnector())) return;
|
||||
}
|
||||
}, 20);
|
||||
return Bukkit.getPluginManager().getPlugin("PlotMe") != null || Bukkit.getPluginManager().getPlugin("AthionPlots") != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkGenerator getGenerator(final String world, final String name) {
|
||||
final Plugin gen_plugin = Bukkit.getPluginManager().getPlugin(name);
|
||||
if ((gen_plugin != null) && gen_plugin.isEnabled()) {
|
||||
return gen_plugin.getDefaultWorldGenerator(world, "");
|
||||
} else {
|
||||
return new HybridGen(world);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public HybridUtils initHybridUtils() {
|
||||
return new BukkitHybridUtils();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SetupUtils initSetupUtils() {
|
||||
return new BukkitSetupUtils();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUIDWrapper initUUIDHandler() {
|
||||
final boolean checkVersion = checkVersion(1, 7, 6);
|
||||
if (Settings.OFFLINE_MODE) {
|
||||
if (Settings.UUID_LOWERCASE) {
|
||||
UUIDHandler.uuidWrapper = new LowerOfflineUUIDWrapper();
|
||||
} else {
|
||||
UUIDHandler.uuidWrapper = new OfflineUUIDWrapper();
|
||||
}
|
||||
Settings.OFFLINE_MODE = true;
|
||||
} else if (checkVersion) {
|
||||
UUIDHandler.uuidWrapper = new DefaultUUIDWrapper();
|
||||
Settings.OFFLINE_MODE = false;
|
||||
} else {
|
||||
if (Settings.UUID_LOWERCASE) {
|
||||
UUIDHandler.uuidWrapper = new LowerOfflineUUIDWrapper();
|
||||
} else {
|
||||
UUIDHandler.uuidWrapper = new OfflineUUIDWrapper();
|
||||
}
|
||||
Settings.OFFLINE_MODE = true;
|
||||
}
|
||||
if (!checkVersion) {
|
||||
log(C.PREFIX.s() + " &c[WARN] Titles are disabled - please update your version of Bukkit to support this feature.");
|
||||
Settings.TITLES = false;
|
||||
FlagManager.removeFlag(FlagManager.getFlag("titles"));
|
||||
} else {
|
||||
AbstractTitle.TITLE_CLASS = new DefaultTitle();
|
||||
if (UUIDHandler.uuidWrapper instanceof DefaultUUIDWrapper) {
|
||||
Settings.TWIN_MODE_UUID = true;
|
||||
} else if (UUIDHandler.uuidWrapper instanceof OfflineUUIDWrapper && !Bukkit.getOnlineMode()) {
|
||||
Settings.TWIN_MODE_UUID = true;
|
||||
}
|
||||
}
|
||||
if (Settings.OFFLINE_MODE) {
|
||||
log(C.PREFIX.s() + " &6PlotSquared is using Offline Mode UUIDs either because of user preference, or because you are using an old version of Bukkit");
|
||||
} else {
|
||||
log(C.PREFIX.s() + " &6PlotSquared is using online UUIDs");
|
||||
}
|
||||
return UUIDHandler.uuidWrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkManager initChunkManager() {
|
||||
return new BukkitChunkManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventUtil initEventUtil() {
|
||||
return new BukkitEventUtil();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerTNTListener() {
|
||||
getServer().getPluginManager().registerEvents(new TNTListener(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregister(PlotPlayer player) {
|
||||
BukkitUtil.removePlayer(player.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public APlotListener initPlotListener() {
|
||||
return new PlotListener();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerChunkProcessor() {
|
||||
getServer().getPluginManager().registerEvents(new ChunkListener(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerWorldEvents() {
|
||||
getServer().getPluginManager().registerEvents(new WorldEvents(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerManager initPlayerManager() {
|
||||
return new BukkitPlayerManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryUtil initInventoryUtil() {
|
||||
return new BukkitInventoryUtil();
|
||||
}
|
||||
}
|
86
src/main/java/com/intellectualcrafters/plot/IPlotMain.java
Normal file
86
src/main/java/com/intellectualcrafters/plot/IPlotMain.java
Normal file
@ -0,0 +1,86 @@
|
||||
package com.intellectualcrafters.plot;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.generator.HybridUtils;
|
||||
import com.intellectualcrafters.plot.listeners.APlotListener;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.intellectualcrafters.plot.util.EventUtil;
|
||||
import com.intellectualcrafters.plot.util.InventoryUtil;
|
||||
import com.intellectualcrafters.plot.util.PlayerManager;
|
||||
import com.intellectualcrafters.plot.util.SetupUtils;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
||||
|
||||
public interface IPlotMain {
|
||||
public void log(String message);
|
||||
|
||||
public File getDirectory();
|
||||
|
||||
public File getFile();
|
||||
|
||||
public void disable();
|
||||
|
||||
public String getVersion();
|
||||
|
||||
public void handleKick(UUID uuid, C c);
|
||||
|
||||
public TaskManager getTaskManager();
|
||||
|
||||
public void runEntityTask();
|
||||
|
||||
public void registerCommands();
|
||||
|
||||
public void registerPlayerEvents();
|
||||
|
||||
public void registerInventoryEvents();
|
||||
|
||||
public void registerPlotPlusEvents();
|
||||
|
||||
public void registerForceFieldEvents();
|
||||
|
||||
public void registerWorldEditEvents();
|
||||
|
||||
public void registerTNTListener();
|
||||
|
||||
public EconHandler getEconomyHandler();
|
||||
|
||||
public BlockManager initBlockManager();
|
||||
|
||||
public EventUtil initEventUtil();
|
||||
|
||||
public ChunkManager initChunkManager();
|
||||
|
||||
public SetupUtils initSetupUtils();
|
||||
|
||||
public HybridUtils initHybridUtils();
|
||||
|
||||
public UUIDWrapper initUUIDHandler();
|
||||
|
||||
public InventoryUtil initInventoryUtil();
|
||||
|
||||
public boolean initPlotMeConverter();
|
||||
|
||||
public void unregister(PlotPlayer player);
|
||||
|
||||
public ChunkGenerator getGenerator(String world, String name);
|
||||
|
||||
public APlotListener initPlotListener();
|
||||
|
||||
public void registerChunkProcessor();
|
||||
|
||||
public void registerWorldEvents();
|
||||
|
||||
public PlayerManager initPlayerManager();
|
||||
|
||||
public boolean checkVersion(int major, int minor, int minor2);
|
||||
|
||||
public void loadPlugin(String plugin);
|
||||
}
|
1554
src/main/java/com/intellectualcrafters/plot/PS.java
Normal file
1554
src/main/java/com/intellectualcrafters/plot/PS.java
Normal file
File diff suppressed because it is too large
Load Diff
672
src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java
Normal file
672
src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java
Normal file
@ -0,0 +1,672 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package com.intellectualcrafters.plot.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.intellectualcrafters.configuration.file.YamlConfiguration;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.commands.MainCommand;
|
||||
import com.intellectualcrafters.plot.commands.SubCommand;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.flag.AbstractFlag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotManager;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.ClusterManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.SchematicHandler;
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitSetBlockManager;
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
||||
|
||||
/**
|
||||
* PlotSquared API
|
||||
*
|
||||
* @author Citymonstret
|
||||
* @author Empire92
|
||||
* @version API 2.0
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
|
||||
@SuppressWarnings("unused") public class PlotAPI {
|
||||
|
||||
/**
|
||||
* Permission that allows for admin access, this permission node will allow the player to use any part of the
|
||||
* plugin, without limitations.
|
||||
*/
|
||||
public static final String ADMIN_PERMISSION = "plots.admin";
|
||||
|
||||
/**
|
||||
* Constructor. Insert any Plugin. (Optimally the plugin that is accessing the method)
|
||||
*
|
||||
* @param plugin Plugin used to access this method
|
||||
*
|
||||
* @throws com.intellectualcrafters.plot.util.PlotSquaredException if the program fails to fetch the PlotSquared
|
||||
* instance
|
||||
* @see com.intellectualcrafters.plot.PS
|
||||
*/
|
||||
@Deprecated
|
||||
public PlotAPI(final JavaPlugin plugin) {
|
||||
}
|
||||
|
||||
public PlotAPI() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all plots
|
||||
*
|
||||
* @return all plots
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.PS#getPlots()
|
||||
*/
|
||||
public Set<Plot> getAllPlots() {
|
||||
return PS.get().getPlots();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all plots for a player
|
||||
*
|
||||
* @param player Player, whose plots to search for
|
||||
*
|
||||
* @return all plots that a player owns
|
||||
*/
|
||||
public Set<Plot> getPlayerPlots(final Player player) {
|
||||
return PS.get().getPlots(BukkitUtil.getPlayer(player));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a plot world
|
||||
*
|
||||
* @param world World Name
|
||||
* @param plotWorld Plot World Object
|
||||
* @param manager World Manager
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.PS#addPlotWorld(String, com.intellectualcrafters.plot.object.PlotWorld,
|
||||
* com.intellectualcrafters.plot.object.PlotManager)
|
||||
*/
|
||||
public void addPlotWorld(final String world, final PlotWorld plotWorld, final PlotManager manager) {
|
||||
PS.get().addPlotWorld(world, plotWorld, manager);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return main configuration
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.PS#config
|
||||
*/
|
||||
public YamlConfiguration getConfig() {
|
||||
return PS.get().config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return storage configuration
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.PS#storage
|
||||
*/
|
||||
public YamlConfiguration getStorage() {
|
||||
return PS.get().storage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the main class for this plugin <br> - Contains a lot of fields and methods - not very well organized <br>
|
||||
* Only use this if you really need it
|
||||
*
|
||||
* @return PlotSquared PlotSquared Main Class
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.PS
|
||||
*/
|
||||
public PS getMain() {
|
||||
return PS.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* ChunkManager class contains several useful methods<br>
|
||||
* - Chunk deletion<br>
|
||||
* - Moving or copying regions<br>
|
||||
* - plot swapping<br>
|
||||
* - Entity tracking<br>
|
||||
* - region regeneration<br>
|
||||
*
|
||||
* @return ChunkManager
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.util.ChunkManager
|
||||
*/
|
||||
public ChunkManager getChunkManager() {
|
||||
return ChunkManager.manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* BlockManager class contains useful methods relating to blocks.
|
||||
*
|
||||
* @return BlockManager
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.util.BlockManager
|
||||
*/
|
||||
public BlockManager getBlockManager() {
|
||||
return BlockManager.manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* BukkitSetBlockManager class contains useful methods relating to bukkit blocks.
|
||||
*
|
||||
* @return BukkitSetBlockManager
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.util.bukkit.BukkitSetBlockManager
|
||||
*/
|
||||
public BukkitSetBlockManager getBukkitBlockManager() {
|
||||
return BukkitSetBlockManager.setBlockManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* UUIDWrapper class has basic methods for getting UUIDS (it's recommended to use the UUIDHandler class instead)
|
||||
*
|
||||
* @return UUIDWrapper
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.uuid.UUIDWrapper
|
||||
*/
|
||||
public UUIDWrapper getUUIDWrapper() {
|
||||
return UUIDHandler.uuidWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not use this. Instead use FlagManager.[method] in your code.
|
||||
* - Flag related stuff
|
||||
*
|
||||
* @return FlagManager
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.flag.FlagManager
|
||||
*/
|
||||
@Deprecated
|
||||
public FlagManager getFlagManager() {
|
||||
return new FlagManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not use this. Instead use ClusterManager.[method] in your code.
|
||||
* - Plot cluster related stuff
|
||||
*
|
||||
* @return ClusterManager
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.util.ClusterManager
|
||||
*/
|
||||
@Deprecated
|
||||
public ClusterManager getClusterManager() {
|
||||
return new ClusterManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not use this. Instead use MainUtil.[method] in your code.
|
||||
* - Basic plot management stuff
|
||||
*
|
||||
* @return MainUtil
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.util.MainUtil
|
||||
*/
|
||||
@Deprecated
|
||||
public MainUtil getMainUtil() {
|
||||
return new MainUtil();
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not use this. Instead use Permissions.[method] in your code.
|
||||
* - Basic permission management stuff
|
||||
*
|
||||
* @return MainUtil
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.util.Permissions
|
||||
*/
|
||||
@Deprecated
|
||||
public Permissions[] getPermissions() {
|
||||
return Permissions.values();
|
||||
}
|
||||
|
||||
/**
|
||||
* SchematicHandler class contains methods related to pasting, reading and writing schematics
|
||||
*
|
||||
* @return SchematicHandler
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.util.SchematicHandler
|
||||
*/
|
||||
public SchematicHandler getSchematicHandler() {
|
||||
return SchematicHandler.manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use C.[caption] instead
|
||||
*
|
||||
* @return C
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.config.C
|
||||
*/
|
||||
@Deprecated
|
||||
public C[] getCaptions() {
|
||||
return C.values();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plot manager for a world. - Most of these methods can be accessed through the MainUtil
|
||||
*
|
||||
* @param world Which manager to get
|
||||
*
|
||||
* @return PlotManager
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.object.PlotManager
|
||||
* @see PS#getPlotManager(String)
|
||||
*/
|
||||
public PlotManager getPlotManager(final World world) {
|
||||
return PS.get().getPlotManager(world.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plot manager for a world. - Contains useful low level methods for plot merging, clearing, and
|
||||
* tessellation
|
||||
*
|
||||
* @param world
|
||||
*
|
||||
* @return PlotManager
|
||||
*
|
||||
* @see PS#getPlotManager(String)
|
||||
* @see com.intellectualcrafters.plot.object.PlotManager
|
||||
*/
|
||||
public PlotManager getPlotManager(final String world) {
|
||||
return PS.get().getPlotManager(world);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the settings for a world (settings bundled in PlotWorld class) - You will need to downcast for the specific
|
||||
* settings a Generator has. e.g. DefaultPlotWorld class implements PlotWorld
|
||||
*
|
||||
* @param world (to get settings of)
|
||||
*
|
||||
* @return PlotWorld class for that world ! will return null if not a plot world world
|
||||
*
|
||||
* @see PS#getPlotWorld(String)
|
||||
* @see com.intellectualcrafters.plot.object.PlotWorld
|
||||
*/
|
||||
public PlotWorld getWorldSettings(final World world) {
|
||||
return PS.get().getPlotWorld(world.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the settings for a world (settings bundled in PlotWorld class)
|
||||
*
|
||||
* @param world (to get settings of)
|
||||
*
|
||||
* @return PlotWorld class for that world ! will return null if not a plot world world
|
||||
*
|
||||
* @see PS#getPlotWorld(String)
|
||||
* @see com.intellectualcrafters.plot.object.PlotWorld
|
||||
*/
|
||||
public PlotWorld getWorldSettings(final String world) {
|
||||
return PS.get().getPlotWorld(world);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to a player.
|
||||
*
|
||||
* @param player Player that will receive the message
|
||||
* @param c (Caption)
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.util.MainUtil#sendMessage(PlotPlayer, C, String...)
|
||||
* com.intellectualcrafters.plot.config.C, String...)
|
||||
*/
|
||||
public void sendMessage(final Player player, final C c) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to a player. - Supports color codes
|
||||
*
|
||||
* @param player Player that will receive the message
|
||||
* @param string The message
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.util.MainUtil#sendMessage(PlotPlayer, String)
|
||||
*/
|
||||
public void sendMessage(final Player player, final String string) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to the console. - Supports color codes
|
||||
*
|
||||
* @param msg Message that should be sent to the console
|
||||
*
|
||||
* @see MainUtil#sendConsoleMessage(String)
|
||||
*/
|
||||
public void sendConsoleMessage(final String msg) {
|
||||
MainUtil.sendConsoleMessage(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to the console
|
||||
*
|
||||
* @param c (Caption)
|
||||
*
|
||||
* @see #sendConsoleMessage(String)
|
||||
* @see com.intellectualcrafters.plot.config.C
|
||||
*/
|
||||
public void sendConsoleMessage(final C c) {
|
||||
sendConsoleMessage(c.s());
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a flag for use in plots
|
||||
*
|
||||
* @param flag Flag that should be registered
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.flag.FlagManager#addFlag(com.intellectualcrafters.plot.flag.AbstractFlag)
|
||||
* @see com.intellectualcrafters.plot.flag.AbstractFlag
|
||||
*/
|
||||
public void addFlag(final AbstractFlag flag) {
|
||||
FlagManager.addFlag(flag);
|
||||
}
|
||||
|
||||
/**
|
||||
* get all the currently registered flags
|
||||
*
|
||||
* @return array of Flag[]
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.flag.FlagManager#getFlags()
|
||||
* @see com.intellectualcrafters.plot.flag.AbstractFlag
|
||||
*/
|
||||
public AbstractFlag[] getFlags() {
|
||||
return FlagManager.getFlags().toArray(new AbstractFlag[FlagManager.getFlags().size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a plot based on the ID
|
||||
*
|
||||
* @param world World in which the plot is located
|
||||
* @param x Plot Location X Co-ord
|
||||
* @param z Plot Location Z Co-ord
|
||||
*
|
||||
* @return plot, null if ID is wrong
|
||||
*
|
||||
* @see MainUtil#getPlot(String, com.intellectualcrafters.plot.object.PlotId)
|
||||
* @see com.intellectualcrafters.plot.object.Plot
|
||||
*/
|
||||
public Plot getPlot(final World world, final int x, final int z) {
|
||||
return MainUtil.getPlot(world.getName(), new PlotId(x, z));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a plot based on the location
|
||||
*
|
||||
* @param l The location that you want to to retrieve the plot from
|
||||
*
|
||||
* @return plot if found, otherwise it creates a temporary plot-
|
||||
*
|
||||
* @see MainUtil#getPlot(com.intellectualcrafters.plot.object.Location)
|
||||
* @see com.intellectualcrafters.plot.object.Plot
|
||||
*/
|
||||
public Plot getPlot(final Location l) {
|
||||
return MainUtil.getPlot(BukkitUtil.getLocation(l));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a plot based on the player location
|
||||
*
|
||||
* @param player Get the current plot for the player location
|
||||
*
|
||||
* @return plot if found, otherwise it creates a temporary plot
|
||||
*
|
||||
* @see #getPlot(org.bukkit.Location)
|
||||
* @see com.intellectualcrafters.plot.object.Plot
|
||||
*/
|
||||
public Plot getPlot(final Player player) {
|
||||
return this.getPlot(player.getLocation());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether or not a player has a plot
|
||||
*
|
||||
* @param player Player that you want to check for
|
||||
*
|
||||
* @return true if player has a plot, false if not.
|
||||
*
|
||||
* @see #getPlots(World, Player, boolean)
|
||||
*/
|
||||
public boolean hasPlot(final World world, final Player player) {
|
||||
return (getPlots(world, player, true) != null) && (getPlots(world, player, true).length > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all plots for the player
|
||||
*
|
||||
* @param plr to search for
|
||||
* @param just_owner should we just search for owner? Or with rights?
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.object.Plot
|
||||
*/
|
||||
public Plot[] getPlots(final World world, final Player plr, final boolean just_owner) {
|
||||
final ArrayList<Plot> pPlots = new ArrayList<>();
|
||||
for (final Plot plot : PS.get().getPlots(world.getName()).values()) {
|
||||
if (just_owner) {
|
||||
if ((plot.owner != null) && (plot.owner.equals(UUIDHandler.getUUID(BukkitUtil.getPlayer(plr))))) {
|
||||
pPlots.add(plot);
|
||||
}
|
||||
} else {
|
||||
if (plot.isAdded(UUIDHandler.getUUID(BukkitUtil.getPlayer(plr)))) {
|
||||
pPlots.add(plot);
|
||||
}
|
||||
}
|
||||
}
|
||||
return pPlots.toArray(new Plot[pPlots.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all plots for the world
|
||||
*
|
||||
* @param world to get plots of
|
||||
*
|
||||
* @return Plot[] - array of plot objects in world
|
||||
*
|
||||
* @see PS#getPlots(String)
|
||||
* @see com.intellectualcrafters.plot.object.Plot
|
||||
*/
|
||||
public Plot[] getPlots(final World world) {
|
||||
Collection<Plot> plots = PS.get().getPlots(world.getName()).values();
|
||||
return plots.toArray(new Plot[plots.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all plot worlds
|
||||
*
|
||||
* @return World[] - array of plot worlds
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.PS#getPlotWorlds()
|
||||
*/
|
||||
public String[] getPlotWorlds() {
|
||||
Set<String> worlds = PS.get().getPlotWorlds();
|
||||
return worlds.toArray(new String[worlds.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if plot world
|
||||
*
|
||||
* @param world (to check if plot world)
|
||||
*
|
||||
* @return boolean (if plot world or not)
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.PS#isPlotWorld(String)
|
||||
*/
|
||||
public boolean isPlotWorld(final World world) {
|
||||
return PS.get().isPlotWorld(world.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get plot locations
|
||||
*
|
||||
* @param p Plot that you want to get the locations for
|
||||
*
|
||||
* @return [0] = bottomLc, [1] = topLoc, [2] = home
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.util.MainUtil#getPlotBottomLoc(String,
|
||||
* com.intellectualcrafters.plot.object.PlotId)
|
||||
* @see com.intellectualcrafters.plot.util.MainUtil#getPlotTopLoc(String,
|
||||
* com.intellectualcrafters.plot.object.PlotId)
|
||||
* @see com.intellectualcrafters.plot.util.MainUtil#getPlotHome(String,
|
||||
* com.intellectualcrafters.plot.object.Plot)
|
||||
* @see com.intellectualcrafters.plot.object.Plot
|
||||
*/
|
||||
public Location[] getLocations(final Plot p) {
|
||||
return new Location[]{BukkitUtil.getLocation(MainUtil.getPlotBottomLoc(p.world, p.id)), BukkitUtil.getLocation(MainUtil.getPlotTopLoc(p.world, p.id)), BukkitUtil.getLocation(MainUtil.getPlotHome(p.world, p.id))};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get home location
|
||||
*
|
||||
* @param p Plot that you want to get the location for
|
||||
*
|
||||
* @return plot bottom location
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.util.MainUtil#getPlotHome(String,
|
||||
* com.intellectualcrafters.plot.object.Plot)
|
||||
* @see com.intellectualcrafters.plot.object.Plot
|
||||
*/
|
||||
public Location getHomeLocation(final Plot p) {
|
||||
return BukkitUtil.getLocation(MainUtil.getPlotHome(p.world, p.id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Bottom Location (min, min, min)
|
||||
*
|
||||
* @param p Plot that you want to get the location for
|
||||
*
|
||||
* @return plot bottom location
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.util.MainUtil#getPlotBottomLoc(String,
|
||||
* com.intellectualcrafters.plot.object.PlotId)
|
||||
* @see com.intellectualcrafters.plot.object.Plot
|
||||
*/
|
||||
public Location getBottomLocation(final Plot p) {
|
||||
return BukkitUtil.getLocation(MainUtil.getPlotBottomLoc(p.world, p.id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Top Location (max, max, max)
|
||||
*
|
||||
* @param p Plot that you want to get the location for
|
||||
*
|
||||
* @return plot top location
|
||||
*
|
||||
* @see MainUtil#getPlotTopLoc(String, com.intellectualcrafters.plot.object.PlotId)
|
||||
* @see com.intellectualcrafters.plot.object.Plot
|
||||
*/
|
||||
public Location getTopLocation(final Plot p) {
|
||||
return BukkitUtil.getLocation(MainUtil.getPlotTopLoc(p.world, p.id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether or not a player is in a plot
|
||||
*
|
||||
* @param player who we're checking for
|
||||
*
|
||||
* @return true if the player is in a plot, false if not-
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.util.MainUtil#getPlot(com.intellectualcrafters.plot.object.Location)
|
||||
*/
|
||||
public boolean isInPlot(final Player player) {
|
||||
return MainUtil.getPlot(BukkitUtil.getLocation(player)) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a subcommand
|
||||
*
|
||||
* @param c SubCommand, that we want to register
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.commands.MainCommand#subCommands
|
||||
* @see com.intellectualcrafters.plot.commands.SubCommand
|
||||
*/
|
||||
public void registerCommand(final SubCommand c) {
|
||||
MainCommand.subCommands.add(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the PlotSquared class
|
||||
*
|
||||
* @return PlotSquared Class
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.PS
|
||||
*/
|
||||
public PS getPlotSquared() {
|
||||
return PS.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the player plot count
|
||||
*
|
||||
* @param world Specify the world we want to select the plots from
|
||||
* @param player Player, for whom we're getting the plot count
|
||||
*
|
||||
* @return the number of plots the player has
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.util.MainUtil#getPlayerPlotCount(String, PlotPlayer)
|
||||
*/
|
||||
public int getPlayerPlotCount(final World world, final Player player) {
|
||||
return MainUtil.getPlayerPlotCount(world.getName(), BukkitUtil.getPlayer(player));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a collection containing the players plots
|
||||
*
|
||||
* @param world Specify the world we want to select the plots from
|
||||
* @param player Player, for whom we're getting the plots
|
||||
*
|
||||
* @return a set containing the players plots
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.PS#getPlots(String, PlotPlayer)
|
||||
* org.bukkit.entity.Player)
|
||||
* @see com.intellectualcrafters.plot.object.Plot
|
||||
*/
|
||||
public Set<Plot> getPlayerPlots(final World world, final Player player) {
|
||||
return PS.get().getPlots(world.getName(), BukkitUtil.getPlayer(player));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the numbers of plots, which the player is able to build in
|
||||
*
|
||||
* @param player Player, for whom we're getting the plots (trusted, member and owner)
|
||||
*
|
||||
* @return the number of allowed plots
|
||||
*
|
||||
*/
|
||||
public int getAllowedPlots(final Player player) {
|
||||
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||
return MainUtil.getAllowedPlots(pp);
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.EventUtil;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
public class Add extends SubCommand {
|
||||
public Add() {
|
||||
super(Command.ADD, "Allow a user to build while you are online", "add <player>", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (args.length != 1) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot add <player>");
|
||||
return true;
|
||||
}
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||
}
|
||||
if ((plot == null) || !plot.hasOwner()) {
|
||||
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
|
||||
return false;
|
||||
}
|
||||
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.add")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||
return true;
|
||||
}
|
||||
UUID uuid;
|
||||
if (args[0].equalsIgnoreCase("*")) {
|
||||
uuid = DBFunc.everyone;
|
||||
} else {
|
||||
uuid = UUIDHandler.getUUID(args[0]);
|
||||
}
|
||||
if (uuid == null) {
|
||||
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
|
||||
return false;
|
||||
}
|
||||
if (plot.isOwner(uuid)) {
|
||||
MainUtil.sendMessage(plr, C.ALREADY_OWNER);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (plot.members.contains(uuid)) {
|
||||
MainUtil.sendMessage(plr, C.ALREADY_ADDED);
|
||||
return false;
|
||||
}
|
||||
if (plot.removeTrusted(uuid)) {
|
||||
plot.addMember(uuid);
|
||||
}
|
||||
else {
|
||||
if (plot.members.size() + plot.trusted.size() >= PS.get().getPlotWorld(plot.world).MAX_PLOT_MEMBERS) {
|
||||
MainUtil.sendMessage(plr, C.PLOT_MAX_MEMBERS);
|
||||
return false;
|
||||
}
|
||||
if (plot.denied.contains(uuid)) {
|
||||
plot.removeDenied(uuid);
|
||||
}
|
||||
plot.addMember(uuid);
|
||||
}
|
||||
EventUtil.manager.callMember(plr, plot, uuid, true);
|
||||
MainUtil.sendMessage(plr, C.MEMBER_ADDED);
|
||||
return true;
|
||||
}
|
||||
}
|
238
src/main/java/com/intellectualcrafters/plot/commands/Auto.java
Normal file
238
src/main/java/com/intellectualcrafters/plot/commands/Auto.java
Normal file
@ -0,0 +1,238 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotCluster;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.ClusterManager;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
|
||||
public class Auto extends SubCommand {
|
||||
public Auto() {
|
||||
super("auto", "plots.auto", "Claim the nearest plot", "auto", "a", CommandCategory.CLAIMING, true);
|
||||
}
|
||||
|
||||
public static PlotId getNextPlot(final PlotId id, final int step) {
|
||||
final int absX = Math.abs(id.x);
|
||||
final int absY = Math.abs(id.y);
|
||||
if (absX > absY) {
|
||||
if (id.x > 0) {
|
||||
return new PlotId(id.x, id.y + 1);
|
||||
} else {
|
||||
return new PlotId(id.x, id.y - 1);
|
||||
}
|
||||
} else if (absY > absX) {
|
||||
if (id.y > 0) {
|
||||
return new PlotId(id.x - 1, id.y);
|
||||
} else {
|
||||
return new PlotId(id.x + 1, id.y);
|
||||
}
|
||||
} else {
|
||||
if (id.x.equals(id.y) && (id.x > 0)) {
|
||||
return new PlotId(id.x, id.y + step);
|
||||
}
|
||||
if (id.x == absX) {
|
||||
return new PlotId(id.x, id.y + 1);
|
||||
}
|
||||
if (id.y == absY) {
|
||||
return new PlotId(id.x, id.y - 1);
|
||||
}
|
||||
return new PlotId(id.x + 1, id.y);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO auto claim a mega plot with schematic
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
String world;
|
||||
int size_x = 1;
|
||||
int size_z = 1;
|
||||
String schematic = "";
|
||||
if (PS.get().getPlotWorlds().size() == 1) {
|
||||
world = PS.get().getPlotWorlds().iterator().next();
|
||||
} else {
|
||||
world = plr.getLocation().getWorld();
|
||||
if (!PS.get().isPlotWorld(world)) {
|
||||
MainUtil.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (args.length > 0) {
|
||||
if (Permissions.hasPermission(plr, "plots.auto.mega")) {
|
||||
try {
|
||||
final String[] split = args[0].split(",");
|
||||
size_x = Integer.parseInt(split[0]);
|
||||
size_z = Integer.parseInt(split[1]);
|
||||
if ((size_x < 1) || (size_z < 1)) {
|
||||
MainUtil.sendMessage(plr, "&cError: size<=0");
|
||||
}
|
||||
if ((size_x > 4) || (size_z > 4)) {
|
||||
MainUtil.sendMessage(plr, "&cError: size>4");
|
||||
}
|
||||
if (args.length > 1) {
|
||||
schematic = args[1];
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
size_x = 1;
|
||||
size_z = 1;
|
||||
schematic = args[0];
|
||||
// PlayerFunctions.sendMessage(plr,
|
||||
// "&cError: Invalid size (X,Y)");
|
||||
// return false;
|
||||
}
|
||||
} else {
|
||||
schematic = args[0];
|
||||
// PlayerFunctions.sendMessage(plr, C.NO_PERMISSION);
|
||||
// return false;
|
||||
}
|
||||
}
|
||||
if ((size_x * size_z) > Settings.MAX_AUTO_SIZE) {
|
||||
MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, Settings.MAX_AUTO_SIZE + "");
|
||||
return false;
|
||||
}
|
||||
final int currentPlots = Settings.GLOBAL_LIMIT ? MainUtil.getPlayerPlotCount(plr) : MainUtil.getPlayerPlotCount(world, plr);
|
||||
final int diff = currentPlots - MainUtil.getAllowedPlots(plr);
|
||||
if ((diff + (size_x * size_z)) > 0) {
|
||||
if (diff < 0) {
|
||||
MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, (-diff) + "");
|
||||
} else {
|
||||
MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
final PlotWorld pWorld = PS.get().getPlotWorld(world);
|
||||
if ((EconHandler.manager != null) && pWorld.USE_ECONOMY) {
|
||||
double cost = pWorld.PLOT_PRICE;
|
||||
cost = (size_x * size_z) * cost;
|
||||
if (cost > 0d) {
|
||||
if (EconHandler.manager.getMoney(plr) < cost) {
|
||||
sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + cost);
|
||||
return true;
|
||||
}
|
||||
EconHandler.manager.withdrawMoney(plr, cost);
|
||||
sendMessage(plr, C.REMOVED_BALANCE, cost + "");
|
||||
}
|
||||
}
|
||||
if (!schematic.equals("")) {
|
||||
// if (pWorld.SCHEMATIC_CLAIM_SPECIFY) {
|
||||
if (!pWorld.SCHEMATICS.contains(schematic.toLowerCase())) {
|
||||
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: " + schematic);
|
||||
return true;
|
||||
}
|
||||
if (!Permissions.hasPermission(plr, "plots.claim." + schematic) && !plr.hasPermission("plots.admin.command.schematic")) {
|
||||
MainUtil.sendMessage(plr, C.NO_SCHEMATIC_PERMISSION, schematic);
|
||||
return true;
|
||||
}
|
||||
// }
|
||||
}
|
||||
final String worldname = world;
|
||||
final PlotWorld plotworld = PS.get().getPlotWorld(worldname);
|
||||
if (plotworld.TYPE == 2) {
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(new Location(worldname, loc.getX(), loc.getY(), loc.getZ()));
|
||||
if (plot == null) {
|
||||
return sendMessage(plr, C.NOT_IN_PLOT);
|
||||
}
|
||||
final PlotCluster cluster = ClusterManager.getCluster(loc);
|
||||
// Must be standing in a cluster
|
||||
if (cluster == null) {
|
||||
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
||||
return false;
|
||||
}
|
||||
final PlotId bot = cluster.getP1();
|
||||
final PlotId top = cluster.getP2();
|
||||
final PlotId origin = new PlotId((bot.x + top.x) / 2, (bot.y + top.y) / 2);
|
||||
PlotId id = new PlotId(0, 0);
|
||||
final int width = Math.max((top.x - bot.x) + 1, (top.y - bot.y) + 1);
|
||||
final int max = width * width;
|
||||
//
|
||||
for (int i = 0; i <= max; i++) {
|
||||
final PlotId currentId = new PlotId(origin.x + id.x, origin.y + id.y);
|
||||
final Plot current = MainUtil.getPlot(worldname, currentId);
|
||||
if (MainUtil.canClaim(plr, current) && (current.settings.isMerged() == false) && cluster.equals(ClusterManager.getCluster(current))) {
|
||||
Claim.claimPlot(plr, current, true, true);
|
||||
return true;
|
||||
}
|
||||
id = getNextPlot(id, 1);
|
||||
}
|
||||
// no free plots
|
||||
MainUtil.sendMessage(plr, C.NO_FREE_PLOTS);
|
||||
return false;
|
||||
}
|
||||
boolean br = false;
|
||||
if ((size_x == 1) && (size_z == 1)) {
|
||||
while (!br) {
|
||||
final Plot plot = MainUtil.getPlot(worldname, getLastPlot(worldname));
|
||||
if (MainUtil.canClaim(plr, plot)) {
|
||||
Claim.claimPlot(plr, plot, true, true);
|
||||
br = true;
|
||||
}
|
||||
MainUtil.lastPlot.put(worldname, getNextPlot(getLastPlot(worldname), 1));
|
||||
}
|
||||
} else {
|
||||
boolean lastPlot = true;
|
||||
while (!br) {
|
||||
final PlotId start = getNextPlot(getLastPlot(worldname), 1);
|
||||
// Checking if the current set of plots is a viable option.
|
||||
MainUtil.lastPlot.put(worldname, start);
|
||||
if (lastPlot) {
|
||||
}
|
||||
if ((PS.get().getPlots(worldname).get(start) != null) && (PS.get().getPlots(worldname).get(start).owner != null)) {
|
||||
continue;
|
||||
} else {
|
||||
lastPlot = false;
|
||||
}
|
||||
final PlotId end = new PlotId((start.x + size_x) - 1, (start.y + size_z) - 1);
|
||||
if (MainUtil.canClaim(plr, worldname, start, end)) {
|
||||
for (int i = start.x; i <= end.x; i++) {
|
||||
for (int j = start.y; j <= end.y; j++) {
|
||||
final Plot plot = MainUtil.getPlot(worldname, new PlotId(i, j));
|
||||
final boolean teleport = ((i == end.x) && (j == end.y));
|
||||
Claim.claimPlot(plr, plot, teleport, true);
|
||||
}
|
||||
}
|
||||
if (!MainUtil.mergePlots(worldname, MainUtil.getPlotSelectionIds(start, end), true)) {
|
||||
return false;
|
||||
}
|
||||
br = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
MainUtil.lastPlot.put(worldname, new PlotId(0, 0));
|
||||
return true;
|
||||
}
|
||||
|
||||
public PlotId getLastPlot(final String world) {
|
||||
if ((MainUtil.lastPlot == null) || !MainUtil.lastPlot.containsKey(world)) {
|
||||
MainUtil.lastPlot.put(world, new PlotId(0, 0));
|
||||
}
|
||||
return MainUtil.lastPlot.get(world);
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.StringComparison;
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
|
||||
|
||||
/**
|
||||
* Created 2015-02-20 for PlotSquared
|
||||
*
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class BukkitCommand implements CommandExecutor, TabCompleter {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final CommandSender commandSender, final Command command, final String commandLabel, final String[] args) {
|
||||
if (commandSender instanceof Player) {
|
||||
return MainCommand.onCommand(BukkitUtil.getPlayer((Player) commandSender), commandLabel, args);
|
||||
}
|
||||
return MainCommand.onCommand(null, commandLabel, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(final CommandSender commandSender, final Command command, final String s, final String[] strings) {
|
||||
if (!(commandSender instanceof Player)) {
|
||||
return null;
|
||||
}
|
||||
final PlotPlayer player = BukkitUtil.getPlayer((Player) commandSender);
|
||||
if (strings.length < 1) {
|
||||
if ((strings.length == 0) || "plots".startsWith(s)) {
|
||||
return Arrays.asList("plots");
|
||||
}
|
||||
}
|
||||
if (strings.length > 1) {
|
||||
return null;
|
||||
}
|
||||
if (!command.getLabel().equalsIgnoreCase("plots")) {
|
||||
return null;
|
||||
}
|
||||
final List<String> tabOptions = new ArrayList<>();
|
||||
final String[] commands = new String[MainCommand.subCommands.size()];
|
||||
for (int x = 0; x < MainCommand.subCommands.size(); x++) {
|
||||
commands[x] = MainCommand.subCommands.get(x).cmd;
|
||||
}
|
||||
String best = new StringComparison(strings[0], commands).getBestMatch();
|
||||
tabOptions.add(best);
|
||||
final String arg = strings[0].toLowerCase();
|
||||
for (final SubCommand cmd : MainCommand.subCommands) {
|
||||
if (!cmd.cmd.equalsIgnoreCase(best)) {
|
||||
if (cmd.permission.hasPermission(player)) {
|
||||
if (cmd.cmd.startsWith(arg)) {
|
||||
tabOptions.add(cmd.cmd);
|
||||
} else if (cmd.alias.size() > 0 && cmd.alias.get(0).startsWith(arg)) {
|
||||
tabOptions.add(cmd.alias.get(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (tabOptions.size() > 0) {
|
||||
return tabOptions;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
119
src/main/java/com/intellectualcrafters/plot/commands/Buy.java
Normal file
119
src/main/java/com/intellectualcrafters/plot/commands/Buy.java
Normal file
@ -0,0 +1,119 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotHandler;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class Buy extends SubCommand {
|
||||
public Buy() {
|
||||
super(Command.BUY, "Buy the plot you are standing on", "b", CommandCategory.CLAIMING, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (EconHandler.manager == null) {
|
||||
return sendMessage(plr, C.ECON_DISABLED);
|
||||
}
|
||||
final Location loc = plr.getLocation();
|
||||
final String world = loc.getWorld();
|
||||
if (!PS.get().isPlotWorld(world)) {
|
||||
return sendMessage(plr, C.NOT_IN_PLOT_WORLD);
|
||||
}
|
||||
Plot plot;
|
||||
if (args.length > 0) {
|
||||
try {
|
||||
final String[] split = args[0].split(";");
|
||||
final PlotId id = new PlotId(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
|
||||
plot = MainUtil.getPlot(world, id);
|
||||
} catch (final Exception e) {
|
||||
return sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
||||
}
|
||||
} else {
|
||||
plot = MainUtil.getPlot(loc);
|
||||
}
|
||||
if (plot == null) {
|
||||
return sendMessage(plr, C.NOT_IN_PLOT);
|
||||
}
|
||||
final int currentPlots = Settings.GLOBAL_LIMIT ? MainUtil.getPlayerPlotCount(plr) : MainUtil.getPlayerPlotCount(world, plr);
|
||||
if (currentPlots >= MainUtil.getAllowedPlots(plr)) {
|
||||
return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
|
||||
}
|
||||
if (!plot.hasOwner()) {
|
||||
return sendMessage(plr, C.PLOT_UNOWNED);
|
||||
}
|
||||
if (PlotHandler.isOwner(plot, plr.getUUID())) {
|
||||
return sendMessage(plr, C.CANNOT_BUY_OWN);
|
||||
}
|
||||
final Flag flag = FlagManager.getPlotFlag(plot, "price");
|
||||
if (flag == null) {
|
||||
return sendMessage(plr, C.NOT_FOR_SALE);
|
||||
}
|
||||
double initPrice = (double) flag.getValue();
|
||||
double price = initPrice;
|
||||
final PlotId id = plot.id;
|
||||
final PlotId id2 = MainUtil.getTopPlot(plot).id;
|
||||
final int size = MainUtil.getPlotSelectionIds(id, id2).size();
|
||||
final PlotWorld plotworld = PS.get().getPlotWorld(world);
|
||||
if (plotworld.USE_ECONOMY) {
|
||||
price += plotworld.PLOT_PRICE * size;
|
||||
initPrice += plotworld.SELL_PRICE * size;
|
||||
}
|
||||
if ((EconHandler.manager != null) && (price > 0d)) {
|
||||
if (EconHandler.manager.getMoney(plr) < price) {
|
||||
return sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + price);
|
||||
}
|
||||
EconHandler.manager.withdrawMoney(plr, price);
|
||||
sendMessage(plr, C.REMOVED_BALANCE, price + "");
|
||||
EconHandler.manager.depositMoney(UUIDHandler.uuidWrapper.getOfflinePlayer(plot.owner), initPrice);
|
||||
final PlotPlayer owner = UUIDHandler.getPlayer(plot.owner);
|
||||
if (owner != null) {
|
||||
sendMessage(plr, C.PLOT_SOLD, plot.id + "", plr.getName(), initPrice + "");
|
||||
}
|
||||
FlagManager.removePlotFlag(plot, "price");
|
||||
}
|
||||
Plot top = MainUtil.getTopPlot(plot);
|
||||
|
||||
for (PlotId myId : MainUtil.getPlotSelectionIds(plot.id, top.id)) {
|
||||
Plot myPlot = MainUtil.getPlot(plot.world, myId);
|
||||
myPlot.owner = plr.getUUID();
|
||||
DBFunc.setOwner(plot, myPlot.owner);
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.CLAIMED);
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
|
||||
public class Chat extends SubCommand {
|
||||
public Chat() {
|
||||
super(Command.CHAT, "Toggle plot chat on or off", "chat", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(PlotPlayer plr, String... args) {
|
||||
final String world = plr.getLocation().getWorld();
|
||||
if (!PS.get().isPlotWorld(world)) {
|
||||
return !sendMessage(plr, C.NOT_IN_PLOT_WORLD);
|
||||
}
|
||||
boolean enable = !(plr.getMeta("chat") != null && (Boolean) plr.getMeta("chat"));
|
||||
if (args.length > 0) {
|
||||
if (args[0].equalsIgnoreCase("on")) {
|
||||
enable = true;
|
||||
} else if (args[0].equalsIgnoreCase("off")) {
|
||||
enable = false;
|
||||
}
|
||||
}
|
||||
final PlotWorld plotworld = PS.get().getPlotWorld(world);
|
||||
if (!enable && plotworld.PLOT_CHAT) {
|
||||
return !sendMessage(plr, C.PLOT_CHAT_FORCED);
|
||||
}
|
||||
plr.setMeta("chat", enable);
|
||||
return sendMessage(plr, enable ? C.PLOT_CHAT_ON : C.PLOT_CHAT_OFF);
|
||||
}
|
||||
}
|
123
src/main/java/com/intellectualcrafters/plot/commands/Claim.java
Normal file
123
src/main/java/com/intellectualcrafters/plot/commands/Claim.java
Normal file
@ -0,0 +1,123 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.intellectualcrafters.plot.util.EventUtil;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.SchematicHandler;
|
||||
import com.intellectualcrafters.plot.util.SchematicHandler.Schematic;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class Claim extends SubCommand {
|
||||
public Claim() {
|
||||
super(Command.CLAIM, "Claim the current plot you're standing on.", "claim", CommandCategory.CLAIMING, true);
|
||||
}
|
||||
|
||||
public static boolean claimPlot(final PlotPlayer player, final Plot plot, final boolean teleport, final boolean auto) {
|
||||
return claimPlot(player, plot, teleport, "", auto);
|
||||
}
|
||||
|
||||
public static boolean claimPlot(final PlotPlayer player, final Plot plot, final boolean teleport, final String schematic, final boolean auto) {
|
||||
if (plot.hasOwner() || plot.settings.isMerged()) {
|
||||
return false;
|
||||
}
|
||||
final boolean result = EventUtil.manager.callClaim(player, plot, false);
|
||||
if (result) {
|
||||
MainUtil.createPlot(player.getUUID(), plot);
|
||||
MainUtil.setSign(player.getName(), plot);
|
||||
MainUtil.sendMessage(player, C.CLAIMED);
|
||||
final Location loc = player.getLocation();
|
||||
if (teleport) {
|
||||
MainUtil.teleportPlayer(player, loc, plot);
|
||||
}
|
||||
final String world = plot.world;
|
||||
final PlotWorld plotworld = PS.get().getPlotWorld(world);
|
||||
final Plot plot2 = PS.get().getPlots(world).get(plot.id);
|
||||
if (plotworld.SCHEMATIC_ON_CLAIM) {
|
||||
Schematic sch;
|
||||
if (schematic.equals("")) {
|
||||
sch = SchematicHandler.manager.getSchematic(plotworld.SCHEMATIC_FILE);
|
||||
} else {
|
||||
sch = SchematicHandler.manager.getSchematic(schematic);
|
||||
if (sch == null) {
|
||||
sch = SchematicHandler.manager.getSchematic(plotworld.SCHEMATIC_FILE);
|
||||
}
|
||||
}
|
||||
SchematicHandler.manager.paste(sch, plot2, 0, 0);
|
||||
}
|
||||
PS.get().getPlotManager(world).claimPlot(plotworld, plot);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
String schematic = "";
|
||||
if (args.length >= 1) {
|
||||
schematic = args[0];
|
||||
}
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
return sendMessage(plr, C.NOT_IN_PLOT);
|
||||
}
|
||||
final int currentPlots = Settings.GLOBAL_LIMIT ? MainUtil.getPlayerPlotCount(plr) : MainUtil.getPlayerPlotCount(loc.getWorld(), plr);
|
||||
if (currentPlots >= MainUtil.getAllowedPlots(plr)) {
|
||||
return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
|
||||
}
|
||||
if (!MainUtil.canClaim(plr, plot)) {
|
||||
return sendMessage(plr, C.PLOT_IS_CLAIMED);
|
||||
}
|
||||
final PlotWorld world = PS.get().getPlotWorld(plot.world);
|
||||
if ((EconHandler.manager != null) && world.USE_ECONOMY) {
|
||||
final double cost = world.PLOT_PRICE;
|
||||
if (cost > 0d) {
|
||||
if (EconHandler.manager.getMoney(plr) < cost) {
|
||||
return sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + cost);
|
||||
}
|
||||
EconHandler.manager.withdrawMoney(plr, cost);
|
||||
sendMessage(plr, C.REMOVED_BALANCE, cost + "");
|
||||
}
|
||||
}
|
||||
if (!schematic.equals("")) {
|
||||
if (world.SCHEMATIC_CLAIM_SPECIFY) {
|
||||
if (!world.SCHEMATICS.contains(schematic.toLowerCase())) {
|
||||
return sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: " + schematic);
|
||||
}
|
||||
if (!Permissions.hasPermission(plr, "plots.claim." + schematic) && !plr.hasPermission("plots.admin.command.schematic")) {
|
||||
return sendMessage(plr, C.NO_SCHEMATIC_PERMISSION, schematic);
|
||||
}
|
||||
}
|
||||
}
|
||||
return claimPlot(plr, plot, false, schematic, false) || sendMessage(plr, C.PLOT_NOT_CLAIMED);
|
||||
}
|
||||
}
|
144
src/main/java/com/intellectualcrafters/plot/commands/Clear.java
Normal file
144
src/main/java/com/intellectualcrafters/plot/commands/Clear.java
Normal file
@ -0,0 +1,144 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.CmdConfirm;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
public class Clear extends SubCommand {
|
||||
public Clear() {
|
||||
super(Command.CLEAR, "Clear a plot", "clear", CommandCategory.ACTIONS, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (plr == null) {
|
||||
// Is console
|
||||
if (args.length < 2) {
|
||||
PS.log("You need to specify two arguments: ID (0;0) & World (world)");
|
||||
} else {
|
||||
final PlotId id = PlotId.fromString(args[0]);
|
||||
final String world = args[1];
|
||||
if (id == null) {
|
||||
PS.log("Invalid Plot ID: " + args[0]);
|
||||
} else {
|
||||
if (!PS.get().isPlotWorld(world)) {
|
||||
PS.log("Invalid plot world: " + world);
|
||||
} else {
|
||||
final Plot plot = MainUtil.getPlot(world, id);
|
||||
if (plot == null) {
|
||||
PS.log("Could not find plot " + args[0] + " in world " + world);
|
||||
} else {
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.clear(plot, plot.owner == null, null);
|
||||
PS.log("Plot " + plot.getId().toString() + " cleared.");
|
||||
}
|
||||
};
|
||||
if (Settings.CONFIRM_CLEAR && !(Permissions.hasPermission(plr, "plots.confirm.bypass"))) {
|
||||
CmdConfirm.addPending(plr, "/plot clear " + id, runnable);
|
||||
}
|
||||
else {
|
||||
TaskManager.runTask(runnable);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot;
|
||||
if (args.length == 2) {
|
||||
PlotId id = PlotId.fromString(args[0]);
|
||||
if (id == null) {
|
||||
if (args[1].equalsIgnoreCase("mine")) {
|
||||
Set<Plot> plots = PS.get().getPlots(plr);
|
||||
if (plots.size() == 0) {
|
||||
MainUtil.sendMessage(plr, C.NO_PLOTS);
|
||||
return false;
|
||||
}
|
||||
plot = plots.iterator().next();
|
||||
}
|
||||
else {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot clear [X;Z|mine]");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
plot = MainUtil.getPlot(loc.getWorld(), id);
|
||||
}
|
||||
}
|
||||
else {
|
||||
plot = MainUtil.getPlot(loc);
|
||||
}
|
||||
if (plot == null) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot clear [X;Z|mine]");
|
||||
return sendMessage(plr, C.NOT_IN_PLOT);
|
||||
}
|
||||
if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) {
|
||||
return sendMessage(plr, C.UNLINK_REQUIRED);
|
||||
}
|
||||
if (((plot == null) || !plot.hasOwner() || !plot.isOwner(UUIDHandler.getUUID(plr))) && !Permissions.hasPermission(plr, "plots.admin.command.clear")) {
|
||||
return sendMessage(plr, C.NO_PLOT_PERMS);
|
||||
}
|
||||
assert plot != null;
|
||||
if (MainUtil.runners.containsKey(plot)) {
|
||||
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
||||
return false;
|
||||
}
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final long start = System.currentTimeMillis();
|
||||
final boolean result = MainUtil.clearAsPlayer(plot, plot.owner == null, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.sendMessage(plr, C.CLEARING_DONE, "" + (System.currentTimeMillis() - start));
|
||||
}
|
||||
});
|
||||
if (!result) {
|
||||
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
||||
}
|
||||
}
|
||||
};
|
||||
if (Settings.CONFIRM_CLEAR && !(Permissions.hasPermission(plr, "plots.confirm.bypass"))) {
|
||||
CmdConfirm.addPending(plr, "/plot clear " + plot.id, runnable);
|
||||
}
|
||||
else {
|
||||
TaskManager.runTask(runnable);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,567 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.generator.AugmentedPopulator;
|
||||
import com.intellectualcrafters.plot.generator.HybridGen;
|
||||
import com.intellectualcrafters.plot.object.BlockLoc;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotCluster;
|
||||
import com.intellectualcrafters.plot.object.PlotClusterId;
|
||||
import com.intellectualcrafters.plot.object.PlotGenerator;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.ClusterManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
public class Cluster extends SubCommand {
|
||||
public Cluster() {
|
||||
super(Command.CLUSTER, "Manage a plot cluster", "cluster", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
// list, create, delete, resize, invite, kick, leave, helpers, tp, sethome
|
||||
if (args.length == 0) {
|
||||
// return arguments
|
||||
MainUtil.sendMessage(plr, C.CLUSTER_AVAILABLE_ARGS);
|
||||
return false;
|
||||
}
|
||||
final String sub = args[0].toLowerCase();
|
||||
switch (sub) {
|
||||
case "l":
|
||||
case "list": {
|
||||
if (!Permissions.hasPermission(plr, "plots.cluster.list")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.list");
|
||||
return false;
|
||||
}
|
||||
if (args.length != 1) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster list");
|
||||
return false;
|
||||
}
|
||||
final HashSet<PlotCluster> clusters = ClusterManager.getClusters(plr.getLocation().getWorld());
|
||||
MainUtil.sendMessage(plr, C.CLUSTER_LIST_HEADING, clusters.size() + "");
|
||||
for (final PlotCluster cluster : clusters) {
|
||||
// Ignore unmanaged clusters
|
||||
final String name = "'" + cluster.getName() + "' : " + cluster.toString();
|
||||
if (UUIDHandler.getUUID(plr).equals(cluster.owner)) {
|
||||
MainUtil.sendMessage(plr, C.CLUSTER_LIST_ELEMENT, "&a" + name);
|
||||
} else if (cluster.helpers.contains(UUIDHandler.getUUID(plr))) {
|
||||
MainUtil.sendMessage(plr, C.CLUSTER_LIST_ELEMENT, "&3" + name);
|
||||
} else if (cluster.invited.contains(UUIDHandler.getUUID(plr))) {
|
||||
MainUtil.sendMessage(plr, C.CLUSTER_LIST_ELEMENT, "&9" + name);
|
||||
} else {
|
||||
MainUtil.sendMessage(plr, C.CLUSTER_LIST_ELEMENT, cluster.toString());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case "c":
|
||||
case "create": {
|
||||
if (!Permissions.hasPermission(plr, "plots.cluster.create")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.create");
|
||||
return false;
|
||||
}
|
||||
if (args.length != 4) {
|
||||
final PlotId id = ClusterManager.estimatePlotId(plr.getLocation());
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster create <name> <id-bot> <id-top>");
|
||||
MainUtil.sendMessage(plr, C.CLUSTER_CURRENT_PLOTID, "" + id);
|
||||
return false;
|
||||
}
|
||||
// check pos1 / pos2
|
||||
final PlotId pos1 = MainUtil.parseId(args[2]);
|
||||
final PlotId pos2 = MainUtil.parseId(args[3]);
|
||||
if ((pos1 == null) || (pos2 == null)) {
|
||||
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
||||
return false;
|
||||
}
|
||||
// check if name is taken
|
||||
final String name = args[1];
|
||||
for (final PlotCluster cluster : ClusterManager.getClusters(plr.getLocation().getWorld())) {
|
||||
if (name.equals(cluster.getName())) {
|
||||
MainUtil.sendMessage(plr, C.ALIAS_IS_TAKEN);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//check if overlap
|
||||
final PlotClusterId id = new PlotClusterId(pos1, pos2);
|
||||
final HashSet<PlotCluster> intersects = ClusterManager.getIntersects(plr.getLocation().getWorld(), id);
|
||||
if ((intersects.size() > 0) || (pos2.x < pos1.x) || (pos2.y < pos1.y)) {
|
||||
MainUtil.sendMessage(plr, C.CLUSTER_INTERSECTION, intersects.size() + "");
|
||||
return false;
|
||||
}
|
||||
// create cluster
|
||||
final String world = plr.getLocation().getWorld();
|
||||
final PlotCluster cluster = new PlotCluster(world, pos1, pos2, UUIDHandler.getUUID(plr));
|
||||
cluster.settings.setAlias(name);
|
||||
DBFunc.createCluster(world, cluster);
|
||||
if (!ClusterManager.clusters.containsKey(world)) {
|
||||
ClusterManager.clusters.put(world, new HashSet<PlotCluster>());
|
||||
}
|
||||
ClusterManager.clusters.get(world).add(cluster);
|
||||
// Add any existing plots to the current cluster
|
||||
for (final Plot plot : PS.get().getPlots(plr.getLocation().getWorld()).values()) {
|
||||
final PlotCluster current = ClusterManager.getCluster(plot);
|
||||
if (cluster.equals(current) && !cluster.isAdded(plot.owner)) {
|
||||
cluster.invited.add(plot.owner);
|
||||
DBFunc.setInvited(world, cluster, plot.owner);
|
||||
}
|
||||
}
|
||||
PlotWorld plotworld = PS.get().getPlotWorld(world);
|
||||
if (plotworld == null) {
|
||||
PS.get().config.createSection("worlds." + world);
|
||||
PS.get().loadWorld(world, null);
|
||||
}
|
||||
else {
|
||||
final String gen_string = PS.get().config.getString("worlds." + world + "." + "generator.plugin");
|
||||
PlotGenerator generator;
|
||||
if (gen_string == null) {
|
||||
generator = new HybridGen(world);
|
||||
} else {
|
||||
generator = (PlotGenerator) PS.get().IMP.getGenerator(world, gen_string);
|
||||
}
|
||||
new AugmentedPopulator(world, generator, cluster, plotworld.TERRAIN == 2, plotworld.TERRAIN != 2);
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.CLUSTER_ADDED);
|
||||
return true;
|
||||
}
|
||||
case "disband":
|
||||
case "del":
|
||||
case "delete": {
|
||||
if (!Permissions.hasPermission(plr, "plots.cluster.delete")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.delete");
|
||||
return false;
|
||||
}
|
||||
if ((args.length != 1) && (args.length != 2)) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster delete [name]");
|
||||
return false;
|
||||
}
|
||||
PlotCluster cluster;
|
||||
if (args.length == 2) {
|
||||
cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
|
||||
if (cluster == null) {
|
||||
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
cluster = ClusterManager.getCluster(plr.getLocation());
|
||||
if (cluster == null) {
|
||||
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!cluster.owner.equals(UUIDHandler.getUUID(plr))) {
|
||||
if (!Permissions.hasPermission(plr, "plots.cluster.delete.other")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.delete.other");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
final PlotWorld plotworld = PS.get().getPlotWorld(plr.getLocation().getWorld());
|
||||
if (plotworld.TYPE == 2) {
|
||||
final ArrayList<Plot> toRemove = new ArrayList<>();
|
||||
for (final Plot plot : PS.get().getPlots(plr.getLocation().getWorld()).values()) {
|
||||
final PlotCluster other = ClusterManager.getCluster(plot);
|
||||
if (cluster.equals(other)) {
|
||||
toRemove.add(plot);
|
||||
}
|
||||
}
|
||||
for (final Plot plot : toRemove) {
|
||||
plot.unclaim();
|
||||
}
|
||||
}
|
||||
DBFunc.delete(cluster);
|
||||
if (plotworld.TYPE == 2) {
|
||||
AugmentedPopulator.removePopulator(plr.getLocation().getWorld(), cluster);
|
||||
}
|
||||
ClusterManager.last = null;
|
||||
ClusterManager.clusters.get(cluster.world).remove(cluster);
|
||||
ClusterManager.regenCluster(cluster);
|
||||
MainUtil.sendMessage(plr, C.CLUSTER_DELETED);
|
||||
return true;
|
||||
}
|
||||
case "res":
|
||||
case "resize": {
|
||||
if (!Permissions.hasPermission(plr, "plots.cluster.resize")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.resize");
|
||||
return false;
|
||||
}
|
||||
if (args.length != 3) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster resize <pos1> <pos2>");
|
||||
return false;
|
||||
}
|
||||
// check pos1 / pos2
|
||||
final PlotId pos1 = MainUtil.parseId(args[1]);
|
||||
final PlotId pos2 = MainUtil.parseId(args[2]);
|
||||
if ((pos1 == null) || (pos2 == null)) {
|
||||
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
||||
return false;
|
||||
}
|
||||
// check if in cluster
|
||||
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation());
|
||||
if (cluster == null) {
|
||||
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
||||
return false;
|
||||
}
|
||||
if (!cluster.hasHelperRights(UUIDHandler.getUUID(plr))) {
|
||||
if (!Permissions.hasPermission(plr, "plots.cluster.resize.other")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.resize.other");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//check if overlap
|
||||
final PlotClusterId id = new PlotClusterId(pos1, pos2);
|
||||
final HashSet<PlotCluster> intersects = ClusterManager.getIntersects(plr.getLocation().getWorld(), id);
|
||||
if (intersects.size() > 1) {
|
||||
MainUtil.sendMessage(plr, C.CLUSTER_INTERSECTION, (intersects.size() - 1) + "");
|
||||
return false;
|
||||
}
|
||||
// resize cluster
|
||||
DBFunc.resizeCluster(cluster, id);
|
||||
MainUtil.sendMessage(plr, C.CLUSTER_RESIZED);
|
||||
return true;
|
||||
}
|
||||
case "reg":
|
||||
case "regenerate":
|
||||
case "regen": {
|
||||
if (!Permissions.hasPermission(plr, "plots.cluster.delete")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.regen");
|
||||
return false;
|
||||
}
|
||||
if ((args.length != 1) && (args.length != 2)) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster regen [name]");
|
||||
return false;
|
||||
}
|
||||
PlotCluster cluster;
|
||||
if (args.length == 2) {
|
||||
cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
|
||||
if (cluster == null) {
|
||||
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
cluster = ClusterManager.getCluster(plr.getLocation());
|
||||
if (cluster == null) {
|
||||
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!cluster.owner.equals(UUIDHandler.getUUID(plr))) {
|
||||
if (!Permissions.hasPermission(plr, "plots.cluster.regen.other")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.regen.other");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
ClusterManager.regenCluster(cluster);
|
||||
MainUtil.sendMessage(plr, C.CLUSTER_REGENERATED);
|
||||
return true;
|
||||
}
|
||||
case "add":
|
||||
case "inv":
|
||||
case "invite": {
|
||||
if (!Permissions.hasPermission(plr, "plots.cluster.invite")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.invite");
|
||||
return false;
|
||||
}
|
||||
if (args.length != 2) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster invite <player>");
|
||||
return false;
|
||||
}
|
||||
// check if in cluster
|
||||
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation());
|
||||
if (cluster == null) {
|
||||
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
||||
return false;
|
||||
}
|
||||
if (!cluster.hasHelperRights(UUIDHandler.getUUID(plr))) {
|
||||
if (!Permissions.hasPermission(plr, "plots.cluster.invite.other")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.invite.other");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// check uuid
|
||||
final UUID uuid = UUIDHandler.getUUID(args[1]);
|
||||
if (uuid == null) {
|
||||
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[2]);
|
||||
return false;
|
||||
}
|
||||
if (!cluster.isAdded(uuid)) {
|
||||
// add the user if not added
|
||||
cluster.invited.add(uuid);
|
||||
final String world = plr.getLocation().getWorld();
|
||||
DBFunc.setInvited(world, cluster, uuid);
|
||||
final PlotPlayer player = UUIDHandler.getPlayer(uuid);
|
||||
if (player != null) {
|
||||
MainUtil.sendMessage(player, C.CLUSTER_INVITED, cluster.getName());
|
||||
}
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.CLUSTER_ADDED_USER);
|
||||
return true;
|
||||
}
|
||||
case "k":
|
||||
case "remove":
|
||||
case "kick": {
|
||||
if (!Permissions.hasPermission(plr, "plots.cluster.kick")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.kick");
|
||||
return false;
|
||||
}
|
||||
if (args.length != 2) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster kick <player>");
|
||||
return false;
|
||||
}
|
||||
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation());
|
||||
if (cluster == null) {
|
||||
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
||||
return false;
|
||||
}
|
||||
if (!cluster.hasHelperRights(UUIDHandler.getUUID(plr))) {
|
||||
if (!Permissions.hasPermission(plr, "plots.cluster.kick.other")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.kick.other");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// check uuid
|
||||
final UUID uuid = UUIDHandler.getUUID(args[1]);
|
||||
if (uuid == null) {
|
||||
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[1]);
|
||||
return false;
|
||||
}
|
||||
// Can't kick if the player is yourself, the owner, or not added to the cluster
|
||||
if (uuid.equals(UUIDHandler.getUUID(plr)) || uuid.equals(cluster.owner) || !cluster.isAdded(uuid)) {
|
||||
MainUtil.sendMessage(plr, C.CANNOT_KICK_PLAYER, cluster.getName());
|
||||
return false;
|
||||
}
|
||||
if (cluster.helpers.contains(uuid)) {
|
||||
cluster.helpers.remove(uuid);
|
||||
DBFunc.removeHelper(cluster, uuid);
|
||||
}
|
||||
cluster.invited.remove(uuid);
|
||||
DBFunc.removeInvited(cluster, uuid);
|
||||
final PlotPlayer player = UUIDHandler.getPlayer(uuid);
|
||||
if (player != null) {
|
||||
MainUtil.sendMessage(player, C.CLUSTER_REMOVED, cluster.getName());
|
||||
}
|
||||
for (final Plot plot : new ArrayList<>(PS.get().getPlots(plr.getLocation().getWorld(), uuid))) {
|
||||
final PlotCluster current = ClusterManager.getCluster(plot);
|
||||
if ((current != null) && current.equals(cluster)) {
|
||||
final String world = plr.getLocation().getWorld();
|
||||
plot.unclaim();
|
||||
}
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.CLUSTER_KICKED_USER);
|
||||
return true;
|
||||
}
|
||||
case "quit":
|
||||
case "leave": {
|
||||
if (!Permissions.hasPermission(plr, "plots.cluster.leave")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.leave");
|
||||
return false;
|
||||
}
|
||||
if ((args.length != 1) && (args.length != 2)) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster leave [name]");
|
||||
return false;
|
||||
}
|
||||
PlotCluster cluster;
|
||||
if (args.length == 2) {
|
||||
cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
|
||||
if (cluster == null) {
|
||||
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
cluster = ClusterManager.getCluster(plr.getLocation());
|
||||
if (cluster == null) {
|
||||
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
final UUID uuid = UUIDHandler.getUUID(plr);
|
||||
if (!cluster.isAdded(uuid)) {
|
||||
MainUtil.sendMessage(plr, C.CLUSTER_NOT_ADDED);
|
||||
return false;
|
||||
}
|
||||
if (uuid.equals(cluster.owner)) {
|
||||
MainUtil.sendMessage(plr, C.CLUSTER_CANNOT_LEAVE);
|
||||
return false;
|
||||
}
|
||||
if (cluster.helpers.contains(uuid)) {
|
||||
cluster.helpers.remove(uuid);
|
||||
DBFunc.removeHelper(cluster, uuid);
|
||||
}
|
||||
cluster.invited.remove(uuid);
|
||||
DBFunc.removeInvited(cluster, uuid);
|
||||
MainUtil.sendMessage(plr, C.CLUSTER_REMOVED, cluster.getName());
|
||||
for (final Plot plot : new ArrayList<>(PS.get().getPlots(plr.getLocation().getWorld(), uuid))) {
|
||||
final PlotCluster current = ClusterManager.getCluster(plot);
|
||||
if ((current != null) && current.equals(cluster)) {
|
||||
final String world = plr.getLocation().getWorld();
|
||||
plot.unclaim();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case "admin":
|
||||
case "helper":
|
||||
case "helpers": {
|
||||
if (!Permissions.hasPermission(plr, "plots.cluster.helpers")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.helpers");
|
||||
return false;
|
||||
}
|
||||
if (args.length != 3) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster helpers <add|remove> <player>");
|
||||
return false;
|
||||
}
|
||||
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation());
|
||||
if (cluster == null) {
|
||||
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
||||
return false;
|
||||
}
|
||||
final UUID uuid = UUIDHandler.getUUID(args[2]);
|
||||
if (uuid == null) {
|
||||
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[2]);
|
||||
return false;
|
||||
}
|
||||
if (args[1].toLowerCase().equals("add")) {
|
||||
cluster.helpers.add(uuid);
|
||||
DBFunc.setHelper(cluster, uuid);
|
||||
return MainUtil.sendMessage(plr, C.CLUSTER_ADDED_HELPER);
|
||||
}
|
||||
if (args[1].toLowerCase().equals("remove")) {
|
||||
cluster.helpers.remove(uuid);
|
||||
DBFunc.removeHelper(cluster, uuid);
|
||||
return MainUtil.sendMessage(plr, C.CLUSTER_REMOVED_HELPER);
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster helpers <add|remove> <player>");
|
||||
return false;
|
||||
}
|
||||
case "spawn":
|
||||
case "home":
|
||||
case "tp": {
|
||||
if (!Permissions.hasPermission(plr, "plots.cluster.tp")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.tp");
|
||||
return false;
|
||||
}
|
||||
if (args.length != 2) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster tp <name>");
|
||||
return false;
|
||||
}
|
||||
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
|
||||
if (cluster == null) {
|
||||
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
|
||||
return false;
|
||||
}
|
||||
final UUID uuid = UUIDHandler.getUUID(plr);
|
||||
if (!cluster.isAdded(uuid)) {
|
||||
if (!Permissions.hasPermission(plr, "plots.cluster.tp.other")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.tp.other");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
plr.teleport(ClusterManager.getHome(cluster));
|
||||
return MainUtil.sendMessage(plr, C.CLUSTER_TELEPORTING);
|
||||
}
|
||||
case "i":
|
||||
case "info":
|
||||
case "show":
|
||||
case "information": {
|
||||
if (!Permissions.hasPermission(plr, "plots.cluster.info")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.info");
|
||||
return false;
|
||||
}
|
||||
if ((args.length != 1) && (args.length != 2)) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster info [name]");
|
||||
return false;
|
||||
}
|
||||
PlotCluster cluster;
|
||||
if (args.length == 2) {
|
||||
cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
|
||||
if (cluster == null) {
|
||||
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
cluster = ClusterManager.getCluster(plr.getLocation());
|
||||
if (cluster == null) {
|
||||
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
final String id = cluster.toString();
|
||||
String owner = UUIDHandler.getName(cluster.owner);
|
||||
if (owner == null) {
|
||||
owner = "unknown";
|
||||
}
|
||||
final String name = cluster.getName();
|
||||
final String size = ((cluster.getP2().x - cluster.getP1().x) + 1) + "x" + ((cluster.getP2().y - cluster.getP1().y) + 1);
|
||||
final String rights = cluster.isAdded(UUIDHandler.getUUID(plr)) + "";
|
||||
String message = C.CLUSTER_INFO.s();
|
||||
message = message.replaceAll("%id%", id);
|
||||
message = message.replaceAll("%owner%", owner);
|
||||
message = message.replaceAll("%name%", name);
|
||||
message = message.replaceAll("%size%", size);
|
||||
message = message.replaceAll("%rights%", rights);
|
||||
MainUtil.sendMessage(plr, message);
|
||||
return true;
|
||||
}
|
||||
case "sh":
|
||||
case "setspawn":
|
||||
case "sethome": {
|
||||
if (!Permissions.hasPermission(plr, "plots.cluster.sethome")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.sethome");
|
||||
return false;
|
||||
}
|
||||
if ((args.length != 1) && (args.length != 2)) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster sethome");
|
||||
return false;
|
||||
}
|
||||
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation());
|
||||
if (cluster == null) {
|
||||
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
||||
return false;
|
||||
}
|
||||
if (!cluster.hasHelperRights(UUIDHandler.getUUID(plr))) {
|
||||
if (!Permissions.hasPermission(plr, "plots.cluster.sethome.other")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.sethome.other");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
final Location base = ClusterManager.getClusterBottom(cluster);
|
||||
final Location relative = plr.getLocation().subtract(base.getX(), 0, base.getZ());
|
||||
final BlockLoc blockloc = new BlockLoc(relative.getX(), relative.getY(), relative.getZ());
|
||||
cluster.settings.setPosition(blockloc);
|
||||
DBFunc.setPosition(cluster, relative.getX() + "," + relative.getY() + "," + relative.getZ());
|
||||
return MainUtil.sendMessage(plr, C.POSITION_SET);
|
||||
}
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.CLUSTER_AVAILABLE_ARGS);
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,159 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
/**
|
||||
* Created by Citymonstret on 2014-08-03.
|
||||
*
|
||||
* @author Citymonstret
|
||||
* @author Empire92
|
||||
*/
|
||||
public enum Command {
|
||||
// TODO new commands
|
||||
// (economy)
|
||||
// - /plot buy
|
||||
// - /plot sell <value>
|
||||
// (Rating system) (ratings can be stored as the average, and number of
|
||||
// ratings)
|
||||
// - /plot rate <number out of 10>
|
||||
|
||||
ADD("add","a"),
|
||||
TRUST("trust", "t"),
|
||||
DENY("deny", "d"),
|
||||
REMOVE("remove", "r"),
|
||||
UNTRUST("untrust", "ut"),
|
||||
UNDENY("undeny", "ud"),
|
||||
TOGGLE("toggle", "attribute"),
|
||||
DOWNLOAD("download", "dl"),
|
||||
MOVE("move"),
|
||||
FLAG("flag", "f"),
|
||||
TARGET("target"),
|
||||
CLUSTER("cluster", "clusters"),
|
||||
BUY("buy", "b"),
|
||||
CREATEROADSCHEMATIC("createroadschematic", "crs"),
|
||||
DEBUGROADREGEN("debugroadregen"),
|
||||
DEBUGFIXFLAGS("debugfixflags"),
|
||||
REGENALLROADS("regenallroads"),
|
||||
ALLOWUNSAFE("debugallowunsafe"),
|
||||
DEBUGLOADTEST("debugloadtest"),
|
||||
DEBUGSAVETEST("debugsavetest"),
|
||||
UNCLAIM("unclaim"),
|
||||
DEBUGCLEAR("debugclear", "fastclear"),
|
||||
SWAP("swap"),
|
||||
INBOX("inbox"),
|
||||
DEBUGCLAIMTEST("debugclaimtest"),
|
||||
COMMENT("comment", "msg"),
|
||||
PASTE("paste"),
|
||||
CLIPBOARD("clipboard", "cboard"),
|
||||
COPY("copy"),
|
||||
KICK("kick", "k"),
|
||||
CLAIM("claim", "c"),
|
||||
MERGE("merge", "m"),
|
||||
UNLINK("unlink", "u"),
|
||||
CLEAR("clear", "", new CommandPermission("plots.clear")),
|
||||
DELETE("delete", "", new CommandPermission("plots.delete")),
|
||||
DEBUG("debug", "", new CommandPermission("plots.admin")),
|
||||
INTERFACE("interface", "int", new CommandPermission("plots.interface")),
|
||||
HOME("home", "h"),
|
||||
INFO("info", "i"),
|
||||
LIST("list", "l"),
|
||||
SET("set", "s"),
|
||||
PURGE("purge"),
|
||||
DATABASE("database", "convert"),
|
||||
CONFIRM("confirm"),
|
||||
TP("tp", "tp"),
|
||||
CHAT("chat", "on|off", new CommandPermission("plots.chat"));
|
||||
/**
|
||||
* Command
|
||||
*/
|
||||
private final String command;
|
||||
/**
|
||||
* Alias
|
||||
*/
|
||||
private final String alias;
|
||||
/**
|
||||
* Permission Node
|
||||
*/
|
||||
private final CommandPermission permission;
|
||||
|
||||
/**
|
||||
* @param command Command "name" (/plot [cmd])
|
||||
*/
|
||||
Command(final String command) {
|
||||
this.command = command;
|
||||
this.alias = command;
|
||||
this.permission = new CommandPermission("plots." + command);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param command Command "name" (/plot [cmd])
|
||||
* @param permission Command Permission Node
|
||||
*/
|
||||
Command(final String command, final CommandPermission permission) {
|
||||
this.command = command;
|
||||
this.permission = permission;
|
||||
this.alias = command;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param command Command "name" (/plot [cmd])
|
||||
* @param alias Command Alias
|
||||
*/
|
||||
Command(final String command, final String alias) {
|
||||
this.command = command;
|
||||
this.alias = alias;
|
||||
this.permission = new CommandPermission("plots." + command);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param command Command "name" (/plot [cmd])
|
||||
* @param alias Command Alias
|
||||
* @param permission Required Permission Node
|
||||
*/
|
||||
Command(final String command, final String alias, final CommandPermission permission) {
|
||||
this.command = command;
|
||||
this.alias = alias;
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return command
|
||||
*/
|
||||
public String getCommand() {
|
||||
return this.command;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return alias
|
||||
*/
|
||||
public String getAlias() {
|
||||
return this.alias;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return permission object
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.commands.CommandPermission
|
||||
*/
|
||||
public CommandPermission getPermission() {
|
||||
return this.permission;
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
|
||||
/**
|
||||
* Created by Citymonstret on 2014-08-03.
|
||||
*
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class CommandPermission {
|
||||
/**
|
||||
* Permission Node
|
||||
*/
|
||||
public final String permission;
|
||||
|
||||
/**
|
||||
* @param permission Command Permission
|
||||
*/
|
||||
public CommandPermission(final String permission) {
|
||||
this.permission = permission.toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player Does the player have the permission?
|
||||
*
|
||||
* @return true of player has the required permission node
|
||||
*/
|
||||
public boolean hasPermission(final PlotPlayer player) {
|
||||
return Permissions.hasPermission(player, this.permission);
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.comment.CommentInbox;
|
||||
import com.intellectualcrafters.plot.object.comment.CommentManager;
|
||||
import com.intellectualcrafters.plot.object.comment.PlotComment;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
|
||||
public class Comment extends SubCommand {
|
||||
public Comment() {
|
||||
super(Command.COMMENT, "Comment on a plot", "comment", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer player, final String... args) {
|
||||
if (args.length < 2) {
|
||||
sendMessage(player, C.COMMENT_SYNTAX, StringUtils.join(CommentManager.inboxes.keySet(),"|"));
|
||||
return false;
|
||||
}
|
||||
CommentInbox inbox = CommentManager.inboxes.get(args[0].toLowerCase());
|
||||
if (inbox == null) {
|
||||
sendMessage(player, C.COMMENT_SYNTAX, StringUtils.join(CommentManager.inboxes.keySet(),"|"));
|
||||
return false;
|
||||
}
|
||||
Plot plot;
|
||||
Location loc = player.getLocation();
|
||||
PlotId id = PlotId.fromString(args[1]);
|
||||
int index;
|
||||
if (id != null) {
|
||||
if (args.length < 4) {
|
||||
sendMessage(player, C.COMMENT_SYNTAX, StringUtils.join(CommentManager.inboxes.keySet(),"|"));
|
||||
return false;
|
||||
}
|
||||
index = 2;
|
||||
plot = MainUtil.getPlot(loc.getWorld(), id);
|
||||
}
|
||||
else {
|
||||
index = 1;
|
||||
plot = MainUtil.getPlot(loc);
|
||||
}
|
||||
if (!inbox.canWrite(plot, player)) {
|
||||
sendMessage(player, C.NO_PERM_INBOX, "");
|
||||
return false;
|
||||
}
|
||||
String message = StringUtils.join(Arrays.copyOfRange(args,index, args.length), " ");
|
||||
PlotComment comment = new PlotComment(loc.getWorld(), id, message, player.getName(), inbox.toString(), System.currentTimeMillis());
|
||||
boolean result = inbox.addComment(plot, comment);
|
||||
if (!result) {
|
||||
sendMessage(player, C.NO_PLOT_INBOX, "");
|
||||
sendMessage(player, C.COMMENT_SYNTAX, StringUtils.join(CommentManager.inboxes.keySet(),"|"));
|
||||
return false;
|
||||
}
|
||||
sendMessage(player, C.COMMENT_ADDED);
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,206 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
|
||||
public class Condense extends SubCommand {
|
||||
public static boolean TASK = false;
|
||||
|
||||
public Condense() {
|
||||
super("condense", "plots.admin", "Condense a plotworld", "condense", "", CommandCategory.DEBUG, false);
|
||||
}
|
||||
|
||||
public static void sendMessage(final String message) {
|
||||
PS.log("&3PlotSquared -> Plot condense&8: &7" + message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (plr != null) {
|
||||
MainUtil.sendMessage(plr, (C.NOT_CONSOLE));
|
||||
return false;
|
||||
}
|
||||
if ((args.length != 2) && (args.length != 3)) {
|
||||
MainUtil.sendMessage(plr, "/plot condense <world> <start|stop|info> [radius]");
|
||||
return false;
|
||||
}
|
||||
final String worldname = args[0];
|
||||
if (!BlockManager.manager.isWorld(worldname) || !PS.get().isPlotWorld(worldname)) {
|
||||
MainUtil.sendMessage(plr, "INVALID WORLD");
|
||||
return false;
|
||||
}
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "start": {
|
||||
if (args.length == 2) {
|
||||
MainUtil.sendMessage(plr, "/plot condense " + worldname + " start <radius>");
|
||||
return false;
|
||||
}
|
||||
if (TASK) {
|
||||
MainUtil.sendMessage(plr, "TASK ALREADY STARTED");
|
||||
return false;
|
||||
}
|
||||
if (args.length == 2) {
|
||||
MainUtil.sendMessage(plr, "/plot condense " + worldname + " start <radius>");
|
||||
return false;
|
||||
}
|
||||
if (!StringUtils.isNumeric(args[2])) {
|
||||
MainUtil.sendMessage(plr, "INVALID RADIUS");
|
||||
return false;
|
||||
}
|
||||
final int radius = Integer.parseInt(args[2]);
|
||||
final Collection<Plot> plots = PS.get().getPlots(worldname).values();
|
||||
final int size = plots.size();
|
||||
final int minimum_radius = (int) Math.ceil((Math.sqrt(size) / 2) + 1);
|
||||
if (radius < minimum_radius) {
|
||||
MainUtil.sendMessage(plr, "RADIUS TOO SMALL");
|
||||
return false;
|
||||
}
|
||||
final List<PlotId> to_move = new ArrayList<>(getPlots(plots, radius));
|
||||
final List<PlotId> free = new ArrayList<>();
|
||||
PlotId start = new PlotId(0, 0);
|
||||
while ((start.x <= minimum_radius) && (start.y <= minimum_radius)) {
|
||||
final Plot plot = MainUtil.getPlot(worldname, start);
|
||||
if (!plot.hasOwner()) {
|
||||
free.add(plot.id);
|
||||
}
|
||||
start = Auto.getNextPlot(start, 1);
|
||||
}
|
||||
if (free.size() == 0 || to_move.size() == 0) {
|
||||
MainUtil.sendMessage(plr, "NO FREE PLOTS FOUND");
|
||||
return false;
|
||||
}
|
||||
MainUtil.move(MainUtil.getPlot(worldname, to_move.get(0)), MainUtil.getPlot(worldname, free.get(0)), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!TASK) {
|
||||
sendMessage("CONDENSE TASK CANCELLED");
|
||||
return;
|
||||
}
|
||||
to_move.remove(0);
|
||||
free.remove(0);
|
||||
int index = 0;
|
||||
for (final PlotId id : to_move) {
|
||||
final Plot plot = MainUtil.getPlot(worldname, id);
|
||||
if (plot.hasOwner()) {
|
||||
break;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
for (int i = 0; i < index; i++) {
|
||||
to_move.remove(0);
|
||||
}
|
||||
index = 0;
|
||||
for (final PlotId id : free) {
|
||||
final Plot plot = MainUtil.getPlot(worldname, id);
|
||||
if (!plot.hasOwner()) {
|
||||
break;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
for (int i = 0; i < index; i++) {
|
||||
free.remove(0);
|
||||
}
|
||||
if (to_move.size() == 0) {
|
||||
sendMessage("TASK COMPLETE. PLEASE VERIFY THAT NO NEW PLOTS HAVE BEEN CLAIMED DURING TASK.");
|
||||
TASK = false;
|
||||
return;
|
||||
}
|
||||
if (free.size() == 0) {
|
||||
sendMessage("TASK FAILED. NO FREE PLOTS FOUND!");
|
||||
TASK = false;
|
||||
return;
|
||||
}
|
||||
sendMessage("MOVING " + to_move.get(0) + " to " + free.get(0));
|
||||
MainUtil.move(MainUtil.getPlot(worldname, to_move.get(0)), MainUtil.getPlot(worldname, free.get(0)), this);
|
||||
}
|
||||
});
|
||||
TASK = true;
|
||||
MainUtil.sendMessage(plr, "TASK STARTED...");
|
||||
return true;
|
||||
}
|
||||
case "stop": {
|
||||
if (!TASK) {
|
||||
MainUtil.sendMessage(plr, "TASK ALREADY STOPPED");
|
||||
return false;
|
||||
}
|
||||
TASK = false;
|
||||
MainUtil.sendMessage(plr, "TASK STOPPED");
|
||||
return true;
|
||||
}
|
||||
case "info": {
|
||||
if (args.length == 2) {
|
||||
MainUtil.sendMessage(plr, "/plot condense " + worldname + " info <radius>");
|
||||
return false;
|
||||
}
|
||||
if (!StringUtils.isNumeric(args[2])) {
|
||||
MainUtil.sendMessage(plr, "INVALID RADIUS");
|
||||
return false;
|
||||
}
|
||||
final int radius = Integer.parseInt(args[2]);
|
||||
final Collection<Plot> plots = PS.get().getPlots(worldname).values();
|
||||
final int size = plots.size();
|
||||
final int minimum_radius = (int) Math.ceil((Math.sqrt(size) / 2) + 1);
|
||||
if (radius < minimum_radius) {
|
||||
MainUtil.sendMessage(plr, "RADIUS TOO SMALL");
|
||||
return false;
|
||||
}
|
||||
final int max_move = getPlots(plots, minimum_radius).size();
|
||||
final int user_move = getPlots(plots, radius).size();
|
||||
MainUtil.sendMessage(plr, "=== DEFAULT EVAL ===");
|
||||
MainUtil.sendMessage(plr, "MINIMUM RADIUS: " + minimum_radius);
|
||||
MainUtil.sendMessage(plr, "MAXIMUM MOVES: " + max_move);
|
||||
MainUtil.sendMessage(plr, "=== INPUT EVAL ===");
|
||||
MainUtil.sendMessage(plr, "INPUT RADIUS: " + radius);
|
||||
MainUtil.sendMessage(plr, "ESTIMATED MOVES: " + user_move);
|
||||
MainUtil.sendMessage(plr, "ESTIMATED TIME: " + "No idea, times will drastically change based on the system performance and load");
|
||||
MainUtil.sendMessage(plr, "&e - Radius is measured in plot width");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
MainUtil.sendMessage(plr, "/plot condense " + worldname + " <start|stop|info> [radius]");
|
||||
return false;
|
||||
}
|
||||
|
||||
public Set<PlotId> getPlots(final Collection<Plot> plots, final int radius) {
|
||||
final HashSet<PlotId> outside = new HashSet<>();
|
||||
for (final Plot plot : plots) {
|
||||
if ((plot.id.x > radius) || (plot.id.x < -radius) || (plot.id.y > radius) || (plot.id.y < -radius)) {
|
||||
outside.add(plot.id);
|
||||
}
|
||||
}
|
||||
return outside;
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.CmdInstance;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.CmdConfirm;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class Confirm extends SubCommand {
|
||||
public Confirm() {
|
||||
super("confirm", "plots.use", "Confirm an action", "confirm", "confirm", CommandCategory.ACTIONS, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
CmdInstance command = CmdConfirm.getPending(plr);
|
||||
if (command == null) {
|
||||
MainUtil.sendMessage(plr, C.FAILED_CONFIRM);
|
||||
return false;
|
||||
}
|
||||
CmdConfirm.removePending(plr);
|
||||
if (System.currentTimeMillis() - command.timestamp > 20000) {
|
||||
MainUtil.sendMessage(plr, C.FAILED_CONFIRM);
|
||||
return false;
|
||||
}
|
||||
TaskManager.runTask(command.command);
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
|
||||
/**
|
||||
* Created 2014-08-01 for PlotSquared
|
||||
*
|
||||
* @author Empire92
|
||||
*/
|
||||
public class Copy extends SubCommand {
|
||||
public Copy() {
|
||||
super("copy", "plots.copy", "Copy a plot", "copypaste", "", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (args.length < 1) {
|
||||
MainUtil.sendMessage(plr, C.NEED_PLOT_ID);
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot copy <X;Z>");
|
||||
return false;
|
||||
}
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot1 = MainUtil.getPlot(loc);
|
||||
if (plot1 == null) {
|
||||
return !MainUtil.sendMessage(plr, C.NOT_IN_PLOT);
|
||||
}
|
||||
if (!plot1.isAdded(plr.getUUID()) && !plr.hasPermission(Permissions.ADMIN.s)) {
|
||||
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||
return false;
|
||||
}
|
||||
final String world = loc.getWorld();
|
||||
final PlotId plot2 = MainUtil.parseId(args[0]);
|
||||
if ((plot2 == null)) {
|
||||
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot copy <X;Z>");
|
||||
return false;
|
||||
}
|
||||
if (plot1.id.equals(plot2)) {
|
||||
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot copy <X;Z>");
|
||||
return false;
|
||||
}
|
||||
if (MainUtil.copy(world, plot1.id, plot2, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.sendMessage(plr, C.COPY_SUCCESS);
|
||||
}
|
||||
})) {
|
||||
return true;
|
||||
} else {
|
||||
MainUtil.sendMessage(plr, C.REQUIRES_UNOWNED);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.generator.HybridPlotWorld;
|
||||
import com.intellectualcrafters.plot.generator.HybridUtils;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
|
||||
public class CreateRoadSchematic extends SubCommand {
|
||||
public CreateRoadSchematic() {
|
||||
super(Command.CREATEROADSCHEMATIC, "Add a road schematic to your world using the road around your current plot", "crs", CommandCategory.DEBUG, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer player, final String... args) {
|
||||
final Location loc = player.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
return sendMessage(player, C.NOT_IN_PLOT);
|
||||
}
|
||||
if (!(PS.get().getPlotWorld(loc.getWorld()) instanceof HybridPlotWorld)) {
|
||||
return sendMessage(player, C.NOT_IN_PLOT_WORLD);
|
||||
}
|
||||
HybridUtils.manager.setupRoadSchematic(plot);
|
||||
MainUtil.sendMessage(player, "&6Saved new road schematic");
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,137 @@
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.MySQL;
|
||||
import com.intellectualcrafters.plot.database.SQLManager;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.StringComparison;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
/**
|
||||
* Created 2014-11-15 for PlotSquared
|
||||
*
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class Database extends SubCommand {
|
||||
public Database() {
|
||||
super(Command.DATABASE, "Convert/Backup Storage", "database [type] [...details]", CommandCategory.DEBUG, false);
|
||||
}
|
||||
|
||||
private static boolean sendMessageU(final UUID uuid, final String msg) {
|
||||
if (uuid == null) {
|
||||
PS.log(msg);
|
||||
} else {
|
||||
final PlotPlayer p = UUIDHandler.getPlayer(uuid);
|
||||
if ((p != null) && p.isOnline()) {
|
||||
return MainUtil.sendMessage(p, msg);
|
||||
} else {
|
||||
return sendMessageU(null, msg);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void insertPlots(final SQLManager manager, final UUID requester, final Connection c) {
|
||||
final java.util.Set<Plot> plots = PS.get().getPlots();
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
final ArrayList<Plot> ps = new ArrayList<>();
|
||||
for (final Plot p : plots) {
|
||||
ps.add(p);
|
||||
}
|
||||
sendMessageU(requester, "&6Starting...");
|
||||
manager.createPlotsAndData(ps, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
sendMessageU(requester, "&6Database conversion finished!");
|
||||
}
|
||||
});
|
||||
} catch (final Exception e) {
|
||||
sendMessageU(requester, "Failed to insert plot objects, see stacktrace for info");
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
c.close();
|
||||
} catch (final SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (args.length < 1) {
|
||||
return sendMessage(plr, "/plot database [sqlite/mysql]");
|
||||
}
|
||||
final String type = new StringComparison(args[0], new String[] { "mysql", "sqlite" }).getBestMatch().toLowerCase();
|
||||
switch (type) {
|
||||
case "mysql":
|
||||
if (args.length < 6) {
|
||||
return sendMessage(plr, "/plot database mysql [host] [port] [username] [password] [database] {prefix}");
|
||||
}
|
||||
final String host = args[1];
|
||||
final String port = args[2];
|
||||
final String username = args[3];
|
||||
final String password = args[4];
|
||||
final String database = args[5];
|
||||
String prefix = "";
|
||||
if (args.length > 6) {
|
||||
prefix = args[6];
|
||||
}
|
||||
Connection n;
|
||||
try {
|
||||
n = new MySQL(host, port, database, username, password).openConnection();
|
||||
// Connection
|
||||
if (n.isClosed()) {
|
||||
return sendMessage(plr, "Failed to open connection");
|
||||
}
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return sendMessage(plr, "Failed to open connection, read stacktrace for info");
|
||||
}
|
||||
final SQLManager manager = new SQLManager(n, prefix);
|
||||
try {
|
||||
manager.createTables("mysql");
|
||||
} catch (final SQLException e) {
|
||||
e.printStackTrace();
|
||||
return sendMessage(plr, "Could not create the required tables and/or load the database") && sendMessage(plr, "Please see the stacktrace for more information");
|
||||
}
|
||||
UUID requester = null;
|
||||
if (plr != null) {
|
||||
requester = UUIDHandler.getUUID(plr);
|
||||
}
|
||||
insertPlots(manager, requester, n);
|
||||
break;
|
||||
case "sqlite":
|
||||
if (args.length < 2) {
|
||||
return sendMessage(plr, "/plot database sqlite [file name]");
|
||||
}
|
||||
sendMessage(plr, "This is not supported yet");
|
||||
break;
|
||||
default:
|
||||
return sendMessage(plr, "Unknown database type");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean sendMessage(final PlotPlayer player, final String msg) {
|
||||
if (player == null) {
|
||||
PS.log(msg);
|
||||
} else {
|
||||
MainUtil.sendMessage(player, msg);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.Lag;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
|
||||
public class Debug extends SubCommand {
|
||||
public Debug() {
|
||||
super(Command.DEBUG, "Show debug information", "debug [msg]", CommandCategory.DEBUG, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if ((args.length > 0) && args[0].equalsIgnoreCase("msg")) {
|
||||
final StringBuilder msg = new StringBuilder();
|
||||
for (final C c : C.values()) {
|
||||
msg.append(c.s()).append("\n");
|
||||
}
|
||||
MainUtil.sendMessage(plr, msg.toString());
|
||||
return true;
|
||||
}
|
||||
StringBuilder information;
|
||||
String header, line, section;
|
||||
{
|
||||
information = new StringBuilder();
|
||||
header = C.DEBUG_HEADER.s();
|
||||
line = C.DEBUG_LINE.s();
|
||||
section = C.DEBUG_SECTION.s();
|
||||
}
|
||||
{
|
||||
final StringBuilder worlds = new StringBuilder("");
|
||||
for (final String world : PS.get().getPlotWorlds()) {
|
||||
worlds.append(world).append(" ");
|
||||
}
|
||||
information.append(header);
|
||||
information.append(getSection(section, "Lag / TPS"));
|
||||
information.append(getLine(line, "Ticks Per Second", Lag.getTPS()));
|
||||
information.append(getLine(line, "Lag Percentage", (int) Lag.getPercentage() + "%"));
|
||||
information.append(getLine(line, "TPS Percentage", (int) Lag.getFullPercentage() + "%"));
|
||||
information.append(getSection(section, "PlotWorld"));
|
||||
information.append(getLine(line, "Plot Worlds", worlds));
|
||||
information.append(getLine(line, "Owned Plots", PS.get().getPlots().size()));
|
||||
information.append(getSection(section, "Messages"));
|
||||
information.append(getLine(line, "Total Messages", C.values().length));
|
||||
information.append(getLine(line, "View all captions", "/plot debug msg"));
|
||||
}
|
||||
{
|
||||
MainUtil.sendMessage(plr, information.toString());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private String getSection(final String line, final String val) {
|
||||
return line.replaceAll("%val%", val) + "\n";
|
||||
}
|
||||
|
||||
private String getLine(final String line, final String var, final Object val) {
|
||||
return line.replaceAll("%var%", var).replaceAll("%val%", "" + val) + "\n";
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class DebugAllowUnsafe extends SubCommand {
|
||||
|
||||
public static final List<UUID> unsafeAllowed = new ArrayList<>();
|
||||
|
||||
public DebugAllowUnsafe() {
|
||||
super(Command.ALLOWUNSAFE, "Allow unsafe actions until toggled off", "allowunsafe", CommandCategory.DEBUG, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (plr == null) {
|
||||
MainUtil.sendMessage(plr, C.IS_CONSOLE);
|
||||
return false;
|
||||
}
|
||||
if (unsafeAllowed.contains(plr.getUUID())) {
|
||||
unsafeAllowed.remove(plr.getUUID());
|
||||
sendMessage(plr, C.DEBUGALLOWUNSAFE_OFF);
|
||||
} else {
|
||||
unsafeAllowed.add(plr.getUUID());
|
||||
sendMessage(plr, C.DEBUGALLOWUNSAFE_ON);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,155 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotManager;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.object.StringWrapper;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.EventUtil;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class DebugClaimTest extends SubCommand {
|
||||
public DebugClaimTest() {
|
||||
super(Command.DEBUGCLAIMTEST, "If you accidentally delete your database, this command will attempt to restore all plots based on the data from the plot signs. Execution time may vary", "debugclaimtest", CommandCategory.DEBUG, false);
|
||||
}
|
||||
|
||||
public static boolean claimPlot(final PlotPlayer player, final Plot plot, final boolean teleport) {
|
||||
return claimPlot(player, plot, teleport, "");
|
||||
}
|
||||
|
||||
public static boolean claimPlot(final PlotPlayer player, final Plot plot, final boolean teleport, final String schematic) {
|
||||
final boolean result = EventUtil.manager.callClaim(player, plot, false);
|
||||
if (result) {
|
||||
MainUtil.createPlot(player.getUUID(), plot);
|
||||
MainUtil.setSign(player.getName(), plot);
|
||||
MainUtil.sendMessage(player, C.CLAIMED);
|
||||
if (teleport) {
|
||||
MainUtil.teleportPlayer(player, player.getLocation(), plot);
|
||||
}
|
||||
}
|
||||
return !result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (plr == null) {
|
||||
if (args.length < 3) {
|
||||
return !MainUtil.sendMessage(null, "If you accidentally delete your database, this command will attempt to restore all plots based on the data from the plot signs. \n\n&cMissing world arg /plot debugclaimtest {world} {PlotId min} {PlotId max}");
|
||||
}
|
||||
final String world = args[0];
|
||||
if (!BlockManager.manager.isWorld(world) || !PS.get().isPlotWorld(world)) {
|
||||
return !MainUtil.sendMessage(null, "&cInvalid plot world!");
|
||||
}
|
||||
PlotId min, max;
|
||||
try {
|
||||
final String[] split1 = args[1].split(";");
|
||||
final String[] split2 = args[2].split(";");
|
||||
min = new PlotId(Integer.parseInt(split1[0]), Integer.parseInt(split1[1]));
|
||||
max = new PlotId(Integer.parseInt(split2[0]), Integer.parseInt(split2[1]));
|
||||
} catch (final Exception e) {
|
||||
return !MainUtil.sendMessage(null, "&cInvalid min/max values. &7The values are to Plot IDs in the format &cX;Y &7where X,Y are the plot coords\nThe conversion will only check the plots in the selected area.");
|
||||
}
|
||||
MainUtil.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Beginning sign to plot conversion. This may take a while...");
|
||||
MainUtil.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: Found an excess of 250,000 chunks. Limiting search radius... (~3.8 min)");
|
||||
final PlotManager manager = PS.get().getPlotManager(world);
|
||||
final PlotWorld plotworld = PS.get().getPlotWorld(world);
|
||||
final ArrayList<Plot> plots = new ArrayList<>();
|
||||
for (final PlotId id : MainUtil.getPlotSelectionIds(min, max)) {
|
||||
final Plot plot = MainUtil.getPlot(world, id);
|
||||
final boolean contains = PS.get().getPlots(world).containsKey(plot.id);
|
||||
if (contains) {
|
||||
MainUtil.sendMessage(null, " - &cDB Already contains: " + plot.id);
|
||||
continue;
|
||||
}
|
||||
final Location loc = manager.getSignLoc(plotworld, plot);
|
||||
final ChunkLoc chunk = new ChunkLoc(loc.getX() >> 4, loc.getZ() >> 4);
|
||||
final boolean result = ChunkManager.manager.loadChunk(world, chunk);
|
||||
if (!result) {
|
||||
continue;
|
||||
}
|
||||
final String[] lines = BlockManager.manager.getSign(loc);
|
||||
if (lines != null) {
|
||||
String line = lines[2];
|
||||
if ((line != null) && (line.length() > 2)) {
|
||||
line = line.substring(2);
|
||||
final BiMap<StringWrapper, UUID> map = UUIDHandler.getUuidMap();
|
||||
UUID uuid = (map.get(new StringWrapper(line)));
|
||||
if (uuid == null) {
|
||||
for (final StringWrapper string : map.keySet()) {
|
||||
if (string.value.toLowerCase().startsWith(line.toLowerCase())) {
|
||||
uuid = map.get(string);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (uuid == null) {
|
||||
uuid = UUIDHandler.getUUID(line);
|
||||
}
|
||||
if (uuid != null) {
|
||||
MainUtil.sendMessage(null, " - &aFound plot: " + plot.id + " : " + line);
|
||||
plot.owner = uuid;
|
||||
plot.hasChanged = true;
|
||||
plots.add(plot);
|
||||
} else {
|
||||
MainUtil.sendMessage(null, " - &cInvalid playername: " + plot.id + " : " + line);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (plots.size() > 0) {
|
||||
MainUtil.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Updating '" + plots.size() + "' plots!");
|
||||
DBFunc.createPlotsAndData(plots, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.sendMessage(null, "&6Database update finished!");
|
||||
}
|
||||
});
|
||||
for (final Plot plot : plots) {
|
||||
PS.get().updatePlot(plot);
|
||||
}
|
||||
MainUtil.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Complete!");
|
||||
} else {
|
||||
MainUtil.sendMessage(null, "No plots were found for the given search.");
|
||||
}
|
||||
} else {
|
||||
MainUtil.sendMessage(plr, "&6This command can only be executed by console as it has been deemed unsafe if abused.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.generator.SquarePlotWorld;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
public class DebugClear extends SubCommand {
|
||||
public DebugClear() {
|
||||
super(Command.DEBUGCLEAR, "Clear a plot using a fast experimental algorithm", "debugclear", CommandCategory.DEBUG, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (plr == null) {
|
||||
// Is console
|
||||
if (args.length < 2) {
|
||||
PS.log("You need to specify two arguments: ID (0;0) & World (world)");
|
||||
} else {
|
||||
final PlotId id = PlotId.fromString(args[0]);
|
||||
final String world = args[1];
|
||||
if (id == null) {
|
||||
PS.log("Invalid Plot ID: " + args[0]);
|
||||
} else {
|
||||
if (!PS.get().isPlotWorld(world) || !(PS.get().getPlotWorld(world) instanceof SquarePlotWorld)) {
|
||||
PS.log("Invalid plot world: " + world);
|
||||
} else {
|
||||
final Plot plot = MainUtil.getPlot(world, id);
|
||||
if (plot == null) {
|
||||
PS.log("Could not find plot " + args[0] + " in world " + world);
|
||||
} else {
|
||||
final Location pos1 = MainUtil.getPlotBottomLoc(world, plot.id).add(1, 0, 1);
|
||||
final Location pos2 = MainUtil.getPlotTopLoc(world, plot.id);
|
||||
if (MainUtil.runners.containsKey(plot)) {
|
||||
MainUtil.sendMessage(null, C.WAIT_FOR_TIMER);
|
||||
return false;
|
||||
}
|
||||
MainUtil.runners.put(plot, 1);
|
||||
ChunkManager.manager.regenerateRegion(pos1, pos2, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.runners.remove(plot);
|
||||
PS.log("Plot " + plot.getId().toString() + " cleared.");
|
||||
PS.log("&aDone!");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if ((plot == null) || !(PS.get().getPlotWorld(loc.getWorld()) instanceof SquarePlotWorld)) {
|
||||
return sendMessage(plr, C.NOT_IN_PLOT);
|
||||
}
|
||||
if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) {
|
||||
return sendMessage(plr, C.UNLINK_REQUIRED);
|
||||
}
|
||||
if (((plot == null) || !plot.hasOwner() || !plot.isOwner(UUIDHandler.getUUID(plr))) && !Permissions.hasPermission(plr, "plots.admin.command.debugclear")) {
|
||||
return sendMessage(plr, C.NO_PLOT_PERMS);
|
||||
}
|
||||
assert plot != null;
|
||||
final Location pos1 = MainUtil.getPlotBottomLoc(loc.getWorld(), plot.id).add(1, 0, 1);
|
||||
final Location pos2 = MainUtil.getPlotTopLoc(loc.getWorld(), plot.id);
|
||||
if (MainUtil.runners.containsKey(plot)) {
|
||||
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
||||
return false;
|
||||
}
|
||||
MainUtil.runners.put(plot, 1);
|
||||
ChunkManager.manager.regenerateRegion(pos1, pos2, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.runners.remove(plot);
|
||||
MainUtil.sendMessage(plr, "&aDone!");
|
||||
}
|
||||
});
|
||||
// sign
|
||||
// wall
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,250 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.PrintWriter;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.generator.BukkitHybridUtils;
|
||||
import com.intellectualcrafters.plot.generator.HybridUtils;
|
||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotAnalysis;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.ExpireManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
public class DebugExec extends SubCommand {
|
||||
public DebugExec() {
|
||||
super("debugexec", "plots.admin", "Multi-purpose debug command", "debugexec", "exec", CommandCategory.DEBUG, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer player, final String... args) {
|
||||
final List<String> allowed_params = Arrays.asList("analyze", "reset-modified", "stop-expire", "start-expire", "show-expired", "update-expired", "seen", "trim-check");
|
||||
if (args.length > 0) {
|
||||
final String arg = args[0].toLowerCase();
|
||||
switch (arg) {
|
||||
case "analyze": {
|
||||
final Plot plot = MainUtil.getPlot(player.getLocation());
|
||||
HybridUtils.manager.analyzePlot(plot, new RunnableVal<PlotAnalysis>() {
|
||||
@Override
|
||||
public void run() {
|
||||
List<Double> result = new ArrayList<>();
|
||||
result.add(Math.round(value.air * 100) / 100d);
|
||||
result.add(Math.round(value.changes * 100) / 100d);
|
||||
result.add(Math.round(value.complexity * 100) / 100d);
|
||||
result.add(Math.round(value.data * 100) / 100d);
|
||||
result.add(Math.round(value.faces * 100) / 100d);
|
||||
result.add(Math.round(value.air * 100) / 100d);
|
||||
result.add(Math.round(value.variety * 100) / 100d);
|
||||
Flag flag = new Flag(FlagManager.getFlag("analysis"), result);
|
||||
FlagManager.addPlotFlag(plot, flag);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
case "stop-expire": {
|
||||
if (ExpireManager.task != -1) {
|
||||
Bukkit.getScheduler().cancelTask(ExpireManager.task);
|
||||
} else {
|
||||
return MainUtil.sendMessage(player, "Task already halted");
|
||||
}
|
||||
ExpireManager.task = -1;
|
||||
return MainUtil.sendMessage(player, "Cancelled task.");
|
||||
}
|
||||
case "remove-flag": {
|
||||
if (args.length != 2) {
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot debugexec remove-flag <flag>");
|
||||
return false;
|
||||
}
|
||||
String flag = args[1];
|
||||
for (Plot plot : PS.get().getPlots()) {
|
||||
if (FlagManager.getPlotFlag(plot, flag) != null) {
|
||||
FlagManager.removePlotFlag(plot, flag);
|
||||
}
|
||||
}
|
||||
return MainUtil.sendMessage(player, "Cleared flag: " + flag);
|
||||
}
|
||||
case "start-rgar": {
|
||||
if (args.length != 2) {
|
||||
PS.log("&cInvalid syntax: /plot debugexec start-rgar <world>");
|
||||
return false;
|
||||
}
|
||||
boolean result;
|
||||
if (!PS.get().isPlotWorld(args[1])) {
|
||||
MainUtil.sendMessage(player, C.NOT_VALID_PLOT_WORLD, args[1]);
|
||||
return false;
|
||||
}
|
||||
if (BukkitHybridUtils.regions != null) {
|
||||
result = ((BukkitHybridUtils)(HybridUtils.manager)).scheduleRoadUpdate(args[1], BukkitHybridUtils.regions, 0);
|
||||
}
|
||||
else {
|
||||
result = HybridUtils.manager.scheduleRoadUpdate(args[1], 0);
|
||||
}
|
||||
if (!result) {
|
||||
PS.log("&cCannot schedule mass schematic update! (Is one already in progress?)");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case "stop-rgar": {
|
||||
if (((BukkitHybridUtils)(HybridUtils.manager)).task == 0) {
|
||||
PS.log("&cTASK NOT RUNNING!");
|
||||
return false;
|
||||
}
|
||||
((BukkitHybridUtils)(HybridUtils.manager)).task = 0;
|
||||
Bukkit.getScheduler().cancelTask(((BukkitHybridUtils)(HybridUtils.manager)).task);
|
||||
PS.log("&cCancelling task...");
|
||||
while (BukkitHybridUtils.chunks.size() > 0) {
|
||||
ChunkLoc chunk = BukkitHybridUtils.chunks.get(0);
|
||||
BukkitHybridUtils.chunks.remove(0);
|
||||
HybridUtils.manager.regenerateRoad(BukkitHybridUtils.world, chunk, 0);
|
||||
ChunkManager.manager.unloadChunk(BukkitHybridUtils.world, chunk);
|
||||
}
|
||||
PS.log("&cCancelled!");
|
||||
return true;
|
||||
}
|
||||
case "start-expire": {
|
||||
if (ExpireManager.task == -1) {
|
||||
ExpireManager.runTask();
|
||||
} else {
|
||||
return MainUtil.sendMessage(player, "Plot expiry task already started");
|
||||
}
|
||||
return MainUtil.sendMessage(player, "Started plot expiry task");
|
||||
}
|
||||
case "update-expired": {
|
||||
if (args.length > 1) {
|
||||
final String world = args[1];
|
||||
if (!BlockManager.manager.isWorld(world)) {
|
||||
return MainUtil.sendMessage(player, "Invalid world: " + args[1]);
|
||||
}
|
||||
MainUtil.sendMessage(player, "Updating expired plot list");
|
||||
ExpireManager.updateExpired(args[1]);
|
||||
return true;
|
||||
}
|
||||
return MainUtil.sendMessage(player, "Use /plot debugexec update-expired <world>");
|
||||
}
|
||||
case "show-expired": {
|
||||
if (args.length > 1) {
|
||||
final String world = args[1];
|
||||
if (!BlockManager.manager.isWorld(world)) {
|
||||
return MainUtil.sendMessage(player, "Invalid world: " + args[1]);
|
||||
}
|
||||
if (!ExpireManager.expiredPlots.containsKey(args[1])) {
|
||||
return MainUtil.sendMessage(player, "No task for world: " + args[1]);
|
||||
}
|
||||
MainUtil.sendMessage(player, "Expired plots (" + ExpireManager.expiredPlots.get(args[1]).size() + "):");
|
||||
for (final Plot plot : ExpireManager.expiredPlots.get(args[1])) {
|
||||
MainUtil.sendMessage(player, " - " + plot.world + ";" + plot.id.x + ";" + plot.id.y + ";" + UUIDHandler.getName(plot.owner) + " : " + ExpireManager.dates.get(plot.owner));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return MainUtil.sendMessage(player, "Use /plot debugexec show-expired <world>");
|
||||
}
|
||||
case "seen": {
|
||||
if (args.length != 2) {
|
||||
return MainUtil.sendMessage(player, "Use /plot debugexec seen <player>");
|
||||
}
|
||||
final UUID uuid = UUIDHandler.getUUID(args[1]);
|
||||
if (uuid == null) {
|
||||
return MainUtil.sendMessage(player, "player not found: " + args[1]);
|
||||
}
|
||||
final OfflinePlotPlayer op = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid);
|
||||
if ((op == null) || (op.getLastPlayed() == 0)) {
|
||||
return MainUtil.sendMessage(player, "player hasn't connected before: " + args[1]);
|
||||
}
|
||||
final Timestamp stamp = new Timestamp(op.getLastPlayed());
|
||||
final Date date = new Date(stamp.getTime());
|
||||
MainUtil.sendMessage(player, "PLAYER: " + args[1]);
|
||||
MainUtil.sendMessage(player, "UUID: " + uuid);
|
||||
MainUtil.sendMessage(player, "Object: " + date.toGMTString());
|
||||
MainUtil.sendMessage(player, "GMT: " + date.toGMTString());
|
||||
MainUtil.sendMessage(player, "Local: " + date.toLocaleString());
|
||||
return true;
|
||||
}
|
||||
case "trim-check": {
|
||||
if (args.length != 2) {
|
||||
MainUtil.sendMessage(player, "Use /plot debugexec trim-check <world>");
|
||||
MainUtil.sendMessage(player, "&7 - Generates a list of regions to trim");
|
||||
return MainUtil.sendMessage(player, "&7 - Run after plot expiry has run");
|
||||
}
|
||||
final String world = args[1];
|
||||
if (!BlockManager.manager.isWorld(world) || !PS.get().isPlotWorld(args[1])) {
|
||||
return MainUtil.sendMessage(player, "Invalid world: " + args[1]);
|
||||
}
|
||||
final ArrayList<ChunkLoc> empty = new ArrayList<>();
|
||||
final boolean result = Trim.getTrimRegions(empty, world, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Trim.sendMessage("Processing is complete! Here's how many chunks would be deleted:");
|
||||
Trim.sendMessage(" - MCA #: " + empty.size());
|
||||
Trim.sendMessage(" - CHUNKS: " + (empty.size() * 1024) + " (max)");
|
||||
Trim.sendMessage("Exporting log for manual approval...");
|
||||
final File file = new File(PS.get().IMP.getDirectory() + File.separator + "trim.txt");
|
||||
PrintWriter writer;
|
||||
try {
|
||||
writer = new PrintWriter(file);
|
||||
for (final ChunkLoc loc : empty) {
|
||||
writer.println(world + "/region/r." + loc.x + "." + loc.z + ".mca");
|
||||
}
|
||||
writer.close();
|
||||
Trim.sendMessage("File saved to 'plugins/PlotSquared/trim.txt'");
|
||||
} catch (final FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
Trim.sendMessage("File failed to save! :(");
|
||||
}
|
||||
Trim.sendMessage("How to get the chunk coords from a region file:");
|
||||
Trim.sendMessage(" - Locate the x,z values for the region file (the two numbers which are separated by a dot)");
|
||||
Trim.sendMessage(" - Multiply each number by 32; this gives you the starting position");
|
||||
Trim.sendMessage(" - Add 31 to each number to get the end position");
|
||||
}
|
||||
});
|
||||
if (!result) {
|
||||
MainUtil.sendMessage(player, "Trim task already started!");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
MainUtil.sendMessage(player, "Possible sub commands: /plot debugexec <" + StringUtils.join(allowed_params, "|") + ">");
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,162 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.SetBlockQueue;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
|
||||
public class DebugFill extends SubCommand {
|
||||
public DebugFill() {
|
||||
super("fill", "plots.fill", "Fill or surround a plot in bedrock", "fill", "debugfill", CommandCategory.DEBUG, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer player, final String... args) {
|
||||
if (args.length != 1 || (!args[0].equalsIgnoreCase("outline") && !args[0].equalsIgnoreCase("all"))) {
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot fill <outline|all>");
|
||||
return true;
|
||||
}
|
||||
final Location loc = player.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
return !sendMessage(player, C.NOT_IN_PLOT);
|
||||
}
|
||||
if ((plot == null) || !plot.hasOwner()) {
|
||||
MainUtil.sendMessage(player, C.PLOT_UNOWNED);
|
||||
return false;
|
||||
}
|
||||
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, "plots.admin.command.fill")) {
|
||||
MainUtil.sendMessage(player, C.NO_PLOT_PERMS);
|
||||
return true;
|
||||
}
|
||||
if (MainUtil.runners.containsKey(plot)) {
|
||||
MainUtil.sendMessage(player, C.WAIT_FOR_TIMER);
|
||||
return false;
|
||||
}
|
||||
final Location bottom = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1);
|
||||
final Location top = MainUtil.getPlotTopLoc(plot.world, plot.id);
|
||||
MainUtil.sendMessage(player, "&cPreparing task");
|
||||
MainUtil.runners.put(plot, 1);
|
||||
SetBlockQueue.addNotify(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.sendMessage(player, "&7 - Starting");
|
||||
if (args[0].equalsIgnoreCase("all")) {
|
||||
int height = 255;
|
||||
PlotBlock block = new PlotBlock((short) 7, (byte) 0);
|
||||
PlotBlock air = new PlotBlock((short) 0, (byte) 0);
|
||||
if (args.length > 2) {
|
||||
try {
|
||||
block = new PlotBlock(Short.parseShort(args[1]), (byte) 0);
|
||||
if (args.length == 3) {
|
||||
height = Integer.parseInt(args[2]);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot fill all <id> <height>");
|
||||
MainUtil.runners.remove(plot);
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (int y = 0; y <= height; y++) {
|
||||
for (int x = bottom.getX(); x <= top.getX(); x++) {
|
||||
for (int z = bottom.getZ(); z <= top.getZ(); z++) {
|
||||
SetBlockQueue.setBlock(plot.world, x, y, z, block);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int y = height + 1; y <= 255; y++) {
|
||||
for (int x = bottom.getX(); x <= top.getX(); x++) {
|
||||
for (int z = bottom.getZ(); z <= top.getZ(); z++) {
|
||||
SetBlockQueue.setBlock(plot.world, x, y, z, air);
|
||||
}
|
||||
}
|
||||
}
|
||||
SetBlockQueue.addNotify(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.runners.remove(plot);
|
||||
MainUtil.sendMessage(player, "&aFill task complete!");
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (args[0].equals("outline")) {
|
||||
int x, z;
|
||||
z = bottom.getZ();
|
||||
for (x = bottom.getX(); x <= (top.getX() - 1); x++) {
|
||||
for (int y = 1; y <= 255; y++) {
|
||||
SetBlockQueue.setBlock(plot.world, x, y, z, 7);
|
||||
}
|
||||
}
|
||||
x = top.getX();
|
||||
for (z = bottom.getZ(); z <= (top.getZ() - 1); z++) {
|
||||
for (int y = 1; y <= 255; y++) {
|
||||
SetBlockQueue.setBlock(plot.world, x, y, z, 7);
|
||||
}
|
||||
}
|
||||
z = top.getZ();
|
||||
for (x = top.getX(); x >= (bottom.getX() + 1); x--) {
|
||||
for (int y = 1; y <= 255; y++) {
|
||||
SetBlockQueue.setBlock(plot.world, x, y, z, 7);
|
||||
}
|
||||
}
|
||||
x = bottom.getX();
|
||||
for (z = top.getZ(); z >= (bottom.getZ() + 1); z--) {
|
||||
for (int y = 1; y <= 255; y++) {
|
||||
SetBlockQueue.setBlock(plot.world, x, y, z, 7);
|
||||
}
|
||||
}
|
||||
SetBlockQueue.addNotify(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.sendMessage(player, "&aWalls complete! The ceiling will take a while :(");
|
||||
bottom.setY(255);
|
||||
top.add(1,0,1);
|
||||
SetBlockQueue.setSlow(true);
|
||||
MainUtil.setSimpleCuboidAsync(plot.world, bottom, top, new PlotBlock((short) 7, (byte) 0));
|
||||
SetBlockQueue.addNotify(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.runners.remove(plot);
|
||||
MainUtil.sendMessage(player, "&aFill task complete!");
|
||||
SetBlockQueue.setSlow(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
|
||||
public class DebugFixFlags extends SubCommand {
|
||||
public DebugFixFlags() {
|
||||
super(Command.DEBUGFIXFLAGS, "Attempt to fix all flags for a world", "debugclear", CommandCategory.DEBUG, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (plr != null) {
|
||||
MainUtil.sendMessage(plr, C.NOT_CONSOLE);
|
||||
return false;
|
||||
}
|
||||
if (args.length != 1) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot debugfixflags <world>");
|
||||
return false;
|
||||
}
|
||||
final String world = args[0];
|
||||
if (!BlockManager.manager.isWorld(world) || !PS.get().isPlotWorld(world)) {
|
||||
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_WORLD, args[0]);
|
||||
return false;
|
||||
}
|
||||
MainUtil.sendMessage(plr, "&8--- &6Starting task &8 ---");
|
||||
for (final Plot plot : PS.get().getPlots(world).values()) {
|
||||
final HashMap<String, Flag> flags = plot.settings.flags;
|
||||
Iterator<Entry<String, Flag>> i = flags.entrySet().iterator();
|
||||
boolean changed = false;
|
||||
while (i.hasNext()) {
|
||||
if (FlagManager.getFlag(i.next().getKey()) == null) {
|
||||
changed = true;
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
if (changed) {
|
||||
DBFunc.setFlags(plot, plot.settings.flags.values());
|
||||
}
|
||||
}
|
||||
MainUtil.sendMessage(plr, "&aDone!");
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class DebugLoadTest extends SubCommand {
|
||||
public DebugLoadTest() {
|
||||
super(Command.DEBUGLOADTEST, "This debug command will force the reload of all plots in the DB", "debugloadtest", CommandCategory.DEBUG, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (plr == null) {
|
||||
try {
|
||||
final Field fPlots = PS.class.getDeclaredField("plots");
|
||||
fPlots.setAccessible(true);
|
||||
fPlots.set(null, DBFunc.getPlots());
|
||||
} catch (final Exception e) {
|
||||
PS.log("&3===FAILED&3===");
|
||||
e.printStackTrace();
|
||||
PS.log("&3===END OF STACKTRACE===");
|
||||
}
|
||||
} else {
|
||||
MainUtil.sendMessage(plr, "&6This command can only be executed by console as it has been deemed unsafe if abused..");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.generator.HybridPlotWorld;
|
||||
import com.intellectualcrafters.plot.generator.HybridUtils;
|
||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
|
||||
public class DebugRoadRegen extends SubCommand {
|
||||
public DebugRoadRegen() {
|
||||
super(Command.DEBUGROADREGEN, "Regenerate all road schematic in your current chunk", "debugroadregen", CommandCategory.DEBUG, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer player, final String... args) {
|
||||
final Location loc = player.getLocation();
|
||||
final String world = loc.getWorld();
|
||||
if (!(PS.get().getPlotWorld(world) instanceof HybridPlotWorld)) {
|
||||
return sendMessage(player, C.NOT_IN_PLOT_WORLD);
|
||||
}
|
||||
final ChunkLoc chunk = new ChunkLoc(loc.getX() >> 4, loc.getZ() >> 4);
|
||||
final boolean result = HybridUtils.manager.regenerateRoad(world, chunk, 0);
|
||||
MainUtil.sendMessage(player, "&6Regenerating chunk: " + chunk.x + "," + chunk.z + "\n&6 - Result: " + (result == true ? "&aSuccess" : "&cFailed"));
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class DebugSaveTest extends SubCommand {
|
||||
public DebugSaveTest() {
|
||||
super(Command.DEBUGSAVETEST, "This debug command will force the recreation of all plots in the DB", "debugsavetest", CommandCategory.DEBUG, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (plr == null) {
|
||||
final ArrayList<Plot> plots = new ArrayList<Plot>();
|
||||
plots.addAll(PS.get().getPlots());
|
||||
MainUtil.sendMessage(null, "&6Starting `DEBUGSAVETEST`");
|
||||
DBFunc.createPlotsAndData(plots, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.sendMessage(null, "&6Database sync finished!");
|
||||
}
|
||||
});
|
||||
} else {
|
||||
MainUtil.sendMessage(plr, "This debug command can only be executed by console as it has been deemed unsafe if abused");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,114 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.ConfigurationNode;
|
||||
import com.intellectualcrafters.plot.generator.HybridGen;
|
||||
import com.intellectualcrafters.plot.object.PlotGenerator;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.SetupObject;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.SetupUtils;
|
||||
|
||||
public class DebugSetup extends SubCommand {
|
||||
public DebugSetup() {
|
||||
super("setup", "plots.admin.command.setup", "Plotworld setup command", "setup", "create", CommandCategory.ACTIONS, false);
|
||||
}
|
||||
|
||||
public void displayGenerators(PlotPlayer plr) {
|
||||
StringBuffer message = new StringBuffer();
|
||||
message.append("&6What generator do you want?");
|
||||
for (Entry<String, ChunkGenerator> entry : SetupUtils.generators.entrySet()) {
|
||||
if (entry.getKey().equals("PlotSquared")) {
|
||||
message.append("\n&8 - &2" + entry.getKey() + " (Default Generator)");
|
||||
}
|
||||
else if (entry.getValue() instanceof HybridGen) {
|
||||
message.append("\n&8 - &7" + entry.getKey() + " (Hybrid Generator)");
|
||||
}
|
||||
else if (entry.getValue() instanceof PlotGenerator) {
|
||||
message.append("\n&8 - &7" + entry.getKey() + " (Plot Generator)");
|
||||
}
|
||||
else {
|
||||
message.append("\n&8 - &7" + entry.getKey() + " (Unknown structure)");
|
||||
}
|
||||
}
|
||||
MainUtil.sendMessage(plr, message.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
// going through setup
|
||||
String name;
|
||||
if (plr == null) {
|
||||
name = "*";
|
||||
}
|
||||
else {
|
||||
name = plr.getName();
|
||||
}
|
||||
if (!SetupUtils.setupMap.containsKey(name)) {
|
||||
final SetupObject object = new SetupObject();
|
||||
SetupUtils.setupMap.put(name, object);
|
||||
SetupUtils.manager.updateGenerators();
|
||||
sendMessage(plr, C.SETUP_INIT);
|
||||
displayGenerators(plr);
|
||||
return false;
|
||||
}
|
||||
if (args.length == 1) {
|
||||
if (args[0].equalsIgnoreCase("cancel")) {
|
||||
SetupUtils.setupMap.remove(name);
|
||||
MainUtil.sendMessage(plr, "&aCancelled setup");
|
||||
return false;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("back")) {
|
||||
final SetupObject object = SetupUtils.setupMap.get(name);
|
||||
if (object.setup_index > 0) {
|
||||
object.setup_index--;
|
||||
final ConfigurationNode node = object.step[object.setup_index];
|
||||
sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", node.getDescription(), node.getType().getType(), node.getDefaultValue() + "");
|
||||
return false;
|
||||
} else if (object.current > 0) {
|
||||
object.current--;
|
||||
}
|
||||
}
|
||||
}
|
||||
final SetupObject object = SetupUtils.setupMap.get(name);
|
||||
final int index = object.current;
|
||||
switch (index) {
|
||||
case 0: { // choose plot manager // skip if 1 option
|
||||
}
|
||||
case 1: { // choose type (default, augmented, cluster)
|
||||
}
|
||||
case 2: { // Choose generator (vanilla, non plot generator) // skip if one option
|
||||
}
|
||||
case 3: { // world setup // skip if one option
|
||||
}
|
||||
case 4: { // world name
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,297 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.AbstractDB;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.StringWrapper;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.PlayerManager;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
import com.intellectualcrafters.plot.uuid.DefaultUUIDWrapper;
|
||||
import com.intellectualcrafters.plot.uuid.LowerOfflineUUIDWrapper;
|
||||
import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper;
|
||||
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
||||
|
||||
public class DebugUUID extends SubCommand {
|
||||
public DebugUUID() {
|
||||
super("uuidconvert", "plots.admin", "Debug uuid conversion", "debuguuid", "debuguuid", CommandCategory.DEBUG, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer player, final String... args) {
|
||||
if (player != null) {
|
||||
MainUtil.sendMessage(player, C.NOT_CONSOLE);
|
||||
return false;
|
||||
}
|
||||
if (args.length == 0) {
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot uuidconvert <lower|offline|online>");
|
||||
return false;
|
||||
}
|
||||
|
||||
UUIDWrapper currentUUIDWrapper = UUIDHandler.uuidWrapper;
|
||||
UUIDWrapper newWrapper = null;
|
||||
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "lower": {
|
||||
newWrapper = new LowerOfflineUUIDWrapper();
|
||||
break;
|
||||
}
|
||||
case "offline": {
|
||||
newWrapper = new OfflineUUIDWrapper();
|
||||
break;
|
||||
}
|
||||
case "online": {
|
||||
newWrapper = new DefaultUUIDWrapper();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
try {
|
||||
Class<?> clazz = Class.forName(args[0]);
|
||||
newWrapper = (UUIDWrapper) clazz.newInstance();
|
||||
}
|
||||
catch (Exception e) {
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot uuidconvert <lower|offline|online>");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (args.length != 2 || !args[1].equals("-o")) {
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot uuidconvert " + args[0] + " - o");
|
||||
MainUtil.sendMessage(player, "&cBe aware of the following!");
|
||||
MainUtil.sendMessage(player, "&8 - &cIf the process is interrupted, all plots could be deleted");
|
||||
MainUtil.sendMessage(player, "&8 - &cIf an error occurs, all plots could be deleted");
|
||||
MainUtil.sendMessage(player, "&8 - &cPlot settings WILL be lost upon conversion");
|
||||
MainUtil.sendMessage(player, "&cBACK UP YOUR DATABASE BEFORE USING THIS!!!");
|
||||
MainUtil.sendMessage(player, "&7Retype the command with the override parameter when ready");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (currentUUIDWrapper.getClass().getCanonicalName().equals(newWrapper.getClass().getCanonicalName())) {
|
||||
MainUtil.sendMessage(player, "&cUUID mode already in use!");
|
||||
return false;
|
||||
}
|
||||
MainUtil.sendConsoleMessage("&6Beginning UUID mode conversion");
|
||||
MainUtil.sendConsoleMessage("&7 - Disconnecting players");
|
||||
for (PlotPlayer user : UUIDHandler.players.values()) {
|
||||
PlayerManager.manager.kickPlayer(user, "PlotSquared UUID conversion has been initiated. You may reconnect when finished.");
|
||||
}
|
||||
|
||||
MainUtil.sendConsoleMessage("&7 - Initializing map");
|
||||
|
||||
HashMap<UUID, UUID> uCMap = new HashMap<UUID, UUID>();
|
||||
HashMap<UUID, UUID> uCReverse = new HashMap<UUID, UUID>();
|
||||
|
||||
MainUtil.sendConsoleMessage("&7 - Collecting playerdata");
|
||||
|
||||
final HashSet<String> worlds = new HashSet<>();
|
||||
worlds.add(Bukkit.getWorlds().get(0).getName());
|
||||
worlds.add("world");
|
||||
final HashSet<UUID> uuids = new HashSet<>();
|
||||
final HashSet<String> names = new HashSet<>();
|
||||
for (final String worldname : worlds) {
|
||||
final File playerdataFolder = new File(worldname + File.separator + "playerdata");
|
||||
String[] dat = playerdataFolder.list(new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(final File f, final String s) {
|
||||
return s.endsWith(".dat");
|
||||
}
|
||||
});
|
||||
if (dat != null) {
|
||||
for (final String current : dat) {
|
||||
final String s = current.replaceAll(".dat$", "");
|
||||
try {
|
||||
final UUID uuid = UUID.fromString(s);
|
||||
uuids.add(uuid);
|
||||
} catch (final Exception e) {
|
||||
PS.log(C.PREFIX.s() + "Invalid playerdata: " + current);
|
||||
}
|
||||
}
|
||||
}
|
||||
final File playersFolder = new File(worldname + File.separator + "players");
|
||||
dat = playersFolder.list(new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(final File f, final String s) {
|
||||
return s.endsWith(".dat");
|
||||
}
|
||||
});
|
||||
if (dat != null) {
|
||||
for (final String current : dat) {
|
||||
names.add(current.replaceAll(".dat$", ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MainUtil.sendConsoleMessage("&7 - Populating map");
|
||||
UUID uuid2;
|
||||
final UUIDWrapper wrapper = new DefaultUUIDWrapper();
|
||||
for (UUID uuid : uuids) {
|
||||
try {
|
||||
final OfflinePlotPlayer op = wrapper.getOfflinePlayer(uuid);
|
||||
uuid = currentUUIDWrapper.getUUID(op);
|
||||
uuid2 = newWrapper.getUUID(op);
|
||||
if (!uuid.equals(uuid2)) {
|
||||
uCMap.put(uuid, uuid2);
|
||||
uCReverse.put(uuid2, uuid);
|
||||
}
|
||||
} catch (final Throwable e) {
|
||||
PS.log(C.PREFIX.s() + "&6Invalid playerdata: " + uuid.toString() + ".dat");
|
||||
}
|
||||
}
|
||||
for (final String name : names) {
|
||||
final UUID uuid = currentUUIDWrapper.getUUID(name);
|
||||
uuid2 = newWrapper.getUUID(name);
|
||||
if (!uuid.equals(uuid2)) {
|
||||
uCMap.put(uuid, uuid2);
|
||||
uCReverse.put(uuid2, uuid);
|
||||
}
|
||||
}
|
||||
if (uCMap.size() == 0) {
|
||||
MainUtil.sendConsoleMessage("&c - Error! Attempting to repopulate");
|
||||
for (OfflinePlotPlayer op : currentUUIDWrapper.getOfflinePlayers()) {
|
||||
if (op.getLastPlayed() != 0) {
|
||||
String name = op.getName();
|
||||
StringWrapper wrap = new StringWrapper(name);
|
||||
UUID uuid = currentUUIDWrapper.getUUID(op);
|
||||
uuid2 = newWrapper.getUUID(op);
|
||||
if (!uuid.equals(uuid2)) {
|
||||
uCMap.put(uuid, uuid2);
|
||||
uCReverse.put(uuid2, uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (uCMap.size() == 0) {
|
||||
MainUtil.sendConsoleMessage("&cError. Failed to collect UUIDs!");
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
MainUtil.sendConsoleMessage("&a - Successfully repopulated");
|
||||
}
|
||||
}
|
||||
|
||||
MainUtil.sendConsoleMessage("&7 - Replacing cache");
|
||||
for (Entry<UUID, UUID> entry : uCMap.entrySet()) {
|
||||
String name = UUIDHandler.getName(entry.getKey());
|
||||
UUIDHandler.add(new StringWrapper(name), entry.getValue());
|
||||
}
|
||||
|
||||
MainUtil.sendConsoleMessage("&7 - Replacing wrapper");
|
||||
UUIDHandler.uuidWrapper = newWrapper;
|
||||
|
||||
MainUtil.sendConsoleMessage("&7 - Updating plot objects");
|
||||
|
||||
for (Plot plot : PS.get().getPlotsRaw()) {
|
||||
UUID value = uCMap.get(plot.owner);
|
||||
if (value != null) {
|
||||
plot.owner = value;
|
||||
}
|
||||
plot.trusted = new ArrayList<>();
|
||||
plot.members = new ArrayList<>();
|
||||
plot.denied = new ArrayList<>();
|
||||
}
|
||||
|
||||
MainUtil.sendConsoleMessage("&7 - Deleting database");
|
||||
final AbstractDB database = DBFunc.dbManager;
|
||||
boolean result = database.deleteTables();
|
||||
|
||||
MainUtil.sendConsoleMessage("&7 - Creating tables");
|
||||
|
||||
try {
|
||||
database.createTables(Settings.DB.USE_MYSQL ? "mysql" : "sqlite");
|
||||
if (!result) {
|
||||
MainUtil.sendConsoleMessage("&cConversion failed! Attempting recovery");
|
||||
for (Plot plot : PS.get().getPlots()) {
|
||||
UUID value = uCReverse.get(plot.owner);
|
||||
if (value != null) {
|
||||
plot.owner = value;
|
||||
}
|
||||
}
|
||||
database.createPlotsAndData(new ArrayList<>(PS.get().getPlots()), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.sendMessage(null, "&6Recovery was successful!");
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (newWrapper instanceof OfflineUUIDWrapper) {
|
||||
PS.get().config.set("UUID.force-lowercase", false);
|
||||
PS.get().config.set("UUID.offline", true);
|
||||
}
|
||||
else if (newWrapper instanceof LowerOfflineUUIDWrapper) {
|
||||
PS.get().config.set("UUID.force-lowercase", true);
|
||||
PS.get().config.set("UUID.offline", true);
|
||||
}
|
||||
else if (newWrapper instanceof DefaultUUIDWrapper) {
|
||||
PS.get().config.set("UUID.force-lowercase", false);
|
||||
PS.get().config.set("UUID.offline", false);
|
||||
}
|
||||
try {
|
||||
PS.get().config.save(PS.get().configFile);
|
||||
}
|
||||
catch (Exception e) {
|
||||
MainUtil.sendConsoleMessage("Could not save configuration. It will need to be manuall set!");
|
||||
}
|
||||
|
||||
MainUtil.sendConsoleMessage("&7 - Populating tables");
|
||||
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ArrayList<Plot> plots = new ArrayList<>(PS.get().getPlots());
|
||||
database.createPlotsAndData(plots, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.sendConsoleMessage("&aConversion complete!");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
MainUtil.sendConsoleMessage("&aIt is now safe for players to join");
|
||||
MainUtil.sendConsoleMessage("&cConversion is still in progress, you will be notified when it is complete");
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.CmdConfirm;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
public class Delete extends SubCommand {
|
||||
public Delete() {
|
||||
super(Command.DELETE, "Delete a plot", "delete", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||
}
|
||||
if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) {
|
||||
return !sendMessage(plr, C.UNLINK_REQUIRED);
|
||||
}
|
||||
if ((((plot == null) || !plot.hasOwner() || !plot.isOwner(UUIDHandler.uuidWrapper.getUUID(plr)))) && !Permissions.hasPermission(plr, "plots.admin.command.delete")) {
|
||||
return !sendMessage(plr, C.NO_PLOT_PERMS);
|
||||
}
|
||||
assert plot != null;
|
||||
final PlotWorld pWorld = PS.get().getPlotWorld(plot.world);
|
||||
if (MainUtil.runners.containsKey(plot)) {
|
||||
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
||||
return false;
|
||||
}
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if ((EconHandler.manager != null) && pWorld.USE_ECONOMY && (plot != null) && plot.hasOwner() && plot.isOwner(UUIDHandler.getUUID(plr))) {
|
||||
final double c = pWorld.SELL_PRICE;
|
||||
if (c > 0d) {
|
||||
EconHandler.manager.depositMoney(plr, c);
|
||||
sendMessage(plr, C.ADDED_BALANCE, c + "");
|
||||
}
|
||||
}
|
||||
PS.get().removePlot(loc.getWorld(), plot.id, true);
|
||||
final long start = System.currentTimeMillis();
|
||||
final boolean result = MainUtil.clearAsPlayer(plot, true, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.sendMessage(plr, C.CLEARING_DONE, "" + (System.currentTimeMillis() - start));
|
||||
}
|
||||
});
|
||||
if (!result) {
|
||||
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
||||
}
|
||||
DBFunc.delete(plot);
|
||||
}
|
||||
};
|
||||
if (Settings.CONFIRM_DELETE && !(Permissions.hasPermission(plr, "plots.confirm.bypass"))) {
|
||||
CmdConfirm.addPending(plr, "/plot delete " + plot.id, runnable);
|
||||
}
|
||||
else {
|
||||
TaskManager.runTask(runnable);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.EventUtil;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
public class Deny extends SubCommand {
|
||||
public Deny() {
|
||||
super(Command.DENY, "Deny a user from a plot", "deny <player>", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (args.length != 1) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot deny <player>");
|
||||
return true;
|
||||
}
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||
}
|
||||
if ((plot == null) || !plot.hasOwner()) {
|
||||
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
|
||||
return false;
|
||||
}
|
||||
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.deny")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||
return true;
|
||||
}
|
||||
UUID uuid;
|
||||
if (args[0].equalsIgnoreCase("*")) {
|
||||
uuid = DBFunc.everyone;
|
||||
} else {
|
||||
uuid = UUIDHandler.getUUID(args[0]);
|
||||
}
|
||||
if (uuid == null) {
|
||||
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
|
||||
return false;
|
||||
}
|
||||
if (plot.isOwner(uuid)) {
|
||||
MainUtil.sendMessage(plr, C.ALREADY_OWNER);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (plot.denied.contains(uuid)) {
|
||||
MainUtil.sendMessage(plr, C.ALREADY_ADDED);
|
||||
return false;
|
||||
}
|
||||
plot.removeMember(uuid);
|
||||
plot.removeTrusted(uuid);
|
||||
plot.addDenied(uuid);
|
||||
EventUtil.manager.callDenied(plr, plot, uuid, true);
|
||||
MainUtil.sendMessage(plr, C.DENIED_ADDED);
|
||||
if (!uuid.equals(DBFunc.everyone)) {
|
||||
PS.get().IMP.handleKick(uuid, C.YOU_GOT_DENIED);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
|
||||
public class Disable extends SubCommand {
|
||||
public static String downloads, version;
|
||||
|
||||
public Disable() {
|
||||
super("disable", "plots.admin", "Disable PlotSquared", "disable", "unload", CommandCategory.DEBUG, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
PS.log("&cDisabling PlotSquared and all dependencies!");
|
||||
PS.get().IMP.disable();
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import com.intellectualcrafters.jnbt.CompoundTag;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.SchematicHandler;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
|
||||
public class Download extends SubCommand {
|
||||
public Download() {
|
||||
super(Command.DOWNLOAD, "Download your plot", "dl", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, String... args) {
|
||||
if (!Settings.METRICS) {
|
||||
MainUtil.sendMessage(plr, "&cPlease enable metrics in order to use this command.\n&7 - Or host it yourself if you don't like the free service");
|
||||
return false;
|
||||
}
|
||||
final String world = plr.getLocation().getWorld();
|
||||
if (!PS.get().isPlotWorld(world)) {
|
||||
return !sendMessage(plr, C.NOT_IN_PLOT_WORLD);
|
||||
}
|
||||
final Plot plot = MainUtil.getPlot(plr.getLocation());
|
||||
if (plot == null) {
|
||||
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||
}
|
||||
if (MainUtil.runners.containsKey(plot)) {
|
||||
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
||||
return false;
|
||||
}
|
||||
MainUtil.runners.put(plot, 1);
|
||||
MainUtil.sendMessage(plr, C.GENERATING_LINK);
|
||||
final CompoundTag tag = SchematicHandler.manager.getCompoundTag(plot.world, plot.id);
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
URL url = SchematicHandler.manager.upload(tag);
|
||||
if (url == null) {
|
||||
MainUtil.sendMessage(plr, C.GENERATING_LINK_FAILED);
|
||||
return;
|
||||
}
|
||||
MainUtil.sendMessage(plr, url.toString());
|
||||
MainUtil.runners.remove(plot);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,244 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.flag.AbstractFlag;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.flag.FlagValue;
|
||||
import com.intellectualcrafters.plot.listeners.APlotListener;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
|
||||
public class FlagCmd extends SubCommand {
|
||||
public FlagCmd() {
|
||||
super(Command.FLAG, "Manage plot flags", "f", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer player, final String... args) {
|
||||
/*
|
||||
* plot flag set fly true
|
||||
* plot flag remove fly
|
||||
* plot flag remove use 1,3
|
||||
* plot flag add use 2,4
|
||||
* plot flag list
|
||||
*/
|
||||
if (args.length == 0) {
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag <set|remove|add|list|info>");
|
||||
return false;
|
||||
}
|
||||
final Location loc = player.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
MainUtil.sendMessage(player, C.NOT_IN_PLOT);
|
||||
return false;
|
||||
}
|
||||
if (!plot.hasOwner()) {
|
||||
sendMessage(player, C.PLOT_NOT_CLAIMED);
|
||||
return false;
|
||||
}
|
||||
if (!plot.isAdded(player.getUUID()) && !Permissions.hasPermission(player, "plots.set.flag.other")) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag.other");
|
||||
return false;
|
||||
}
|
||||
if (args.length > 1 && FlagManager.isReserved(args[1])) {
|
||||
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
|
||||
return false;
|
||||
}
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "info": {
|
||||
if (!Permissions.hasPermission(player, "plots.set.flag")) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flag.info");
|
||||
return false;
|
||||
}
|
||||
if (args.length != 2) {
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag info <flag>");
|
||||
return false;
|
||||
}
|
||||
final AbstractFlag af = FlagManager.getFlag(args[1]);
|
||||
if (af == null) {
|
||||
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag info <flag>");
|
||||
return false;
|
||||
}
|
||||
// flag key
|
||||
MainUtil.sendMessage(player, C.FLAG_KEY, af.getKey());
|
||||
// flag type
|
||||
MainUtil.sendMessage(player, C.FLAG_TYPE, af.value.getClass().getSimpleName());
|
||||
// Flag type description
|
||||
MainUtil.sendMessage(player, C.FLAG_DESC, af.getValueDesc());
|
||||
return true;
|
||||
}
|
||||
case "set": {
|
||||
if (!Permissions.hasPermission(player, "plots.set.flag")) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag");
|
||||
return false;
|
||||
}
|
||||
if (args.length < 3) {
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag set <flag> <value>");
|
||||
return false;
|
||||
}
|
||||
final AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase());
|
||||
if (af == null) {
|
||||
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
|
||||
return false;
|
||||
}
|
||||
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase())) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase());
|
||||
return false;
|
||||
}
|
||||
final String value = StringUtils.join(Arrays.copyOfRange(args, 2, args.length), " ");
|
||||
final Object parsed = af.parseValueRaw(value);
|
||||
if (parsed == null) {
|
||||
MainUtil.sendMessage(player, "&c" + af.getValueDesc());
|
||||
return false;
|
||||
}
|
||||
final Flag flag = new Flag(FlagManager.getFlag(args[1].toLowerCase(), true), parsed);
|
||||
final boolean result = FlagManager.addPlotFlag(plot, flag);
|
||||
if (!result) {
|
||||
MainUtil.sendMessage(player, C.FLAG_NOT_ADDED);
|
||||
return false;
|
||||
}
|
||||
MainUtil.sendMessage(player, C.FLAG_ADDED);
|
||||
APlotListener.manager.plotEntry(player, plot);
|
||||
return true;
|
||||
}
|
||||
case "remove": {
|
||||
if (!Permissions.hasPermission(player, "plots.flag.remove")) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flag.remove");
|
||||
return false;
|
||||
}
|
||||
if ((args.length != 2) && (args.length != 3)) {
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag remove <flag> [values]");
|
||||
return false;
|
||||
}
|
||||
final AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase());
|
||||
if (af == null) {
|
||||
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
|
||||
return false;
|
||||
}
|
||||
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase())) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase());
|
||||
return false;
|
||||
}
|
||||
final Flag flag = FlagManager.getPlotFlagAbs(plot, args[1].toLowerCase());
|
||||
if (flag == null) {
|
||||
MainUtil.sendMessage(player, C.FLAG_NOT_IN_PLOT);
|
||||
return false;
|
||||
}
|
||||
if ((args.length == 3) && flag.getAbstractFlag().isList()) {
|
||||
final String value = StringUtils.join(Arrays.copyOfRange(args, 2, args.length), " ");
|
||||
((FlagValue.ListValue) flag.getAbstractFlag().value).remove(flag.getValue(), value);
|
||||
DBFunc.setFlags(plot, plot.settings.flags.values());
|
||||
} else {
|
||||
final boolean result = FlagManager.removePlotFlag(plot, flag.getKey());
|
||||
if (!result) {
|
||||
MainUtil.sendMessage(player, C.FLAG_NOT_REMOVED);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
MainUtil.sendMessage(player, C.FLAG_REMOVED);
|
||||
APlotListener.manager.plotEntry(player, plot);
|
||||
return true;
|
||||
}
|
||||
case "add": {
|
||||
if (!Permissions.hasPermission(player, "plots.flag.add")) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flag.add");
|
||||
return false;
|
||||
}
|
||||
if (args.length < 3) {
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag add <flag> <values>");
|
||||
return false;
|
||||
}
|
||||
final AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase());
|
||||
if (af == null) {
|
||||
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
|
||||
return false;
|
||||
}
|
||||
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase())) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase());
|
||||
return false;
|
||||
}
|
||||
final String value = StringUtils.join(Arrays.copyOfRange(args, 2, args.length), " ");
|
||||
final Object parsed = af.parseValueRaw(value);
|
||||
if (parsed == null) {
|
||||
MainUtil.sendMessage(player, "&c" + af.getValueDesc());
|
||||
return false;
|
||||
}
|
||||
Flag flag = FlagManager.getPlotFlag(plot, args[1].toLowerCase());
|
||||
if ((flag == null) || !flag.getAbstractFlag().isList()) {
|
||||
flag = new Flag(FlagManager.getFlag(args[1].toLowerCase(), true), parsed);
|
||||
} else {
|
||||
((FlagValue.ListValue) flag.getAbstractFlag().value).add(flag.getValue(), value);
|
||||
}
|
||||
final boolean result = FlagManager.addPlotFlag(plot, flag);
|
||||
if (!result) {
|
||||
MainUtil.sendMessage(player, C.FLAG_NOT_ADDED);
|
||||
return false;
|
||||
}
|
||||
DBFunc.setFlags(plot, plot.settings.flags.values());
|
||||
MainUtil.sendMessage(player, C.FLAG_ADDED);
|
||||
APlotListener.manager.plotEntry(player, plot);
|
||||
return true;
|
||||
}
|
||||
case "list": {
|
||||
if (!Permissions.hasPermission(player, "plots.flag.list")) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flag.list");
|
||||
return false;
|
||||
}
|
||||
if (args.length != 1) {
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag list");
|
||||
return false;
|
||||
}
|
||||
final HashMap<String, ArrayList<String>> flags = new HashMap<>();
|
||||
for (final AbstractFlag af : FlagManager.getFlags()) {
|
||||
final String type = af.value.getClass().getSimpleName().replaceAll("Value", "");
|
||||
if (!flags.containsKey(type)) {
|
||||
flags.put(type, new ArrayList<String>());
|
||||
}
|
||||
flags.get(type).add(af.getKey());
|
||||
}
|
||||
String message = "";
|
||||
String prefix = "";
|
||||
for (final String flag : flags.keySet()) {
|
||||
message += prefix + "&6" + flag + ": &7" + StringUtils.join(flags.get(flag), ", ");
|
||||
prefix = "\n";
|
||||
}
|
||||
MainUtil.sendMessage(player, message);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag <set|remove|add|list|info>");
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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 = Help.java >> Generated by: Citymonstret at 2014-08-11 17:32
|
||||
*/
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
|
||||
public class Help extends SubCommand {
|
||||
public Help() {
|
||||
super("help", "", "Get this help menu", "help", "he", SubCommand.CommandCategory.INFO, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class Home extends SubCommand {
|
||||
public Home() {
|
||||
super(Command.HOME, "Go to your plot", "home {id|alias}", CommandCategory.TELEPORT, true);
|
||||
}
|
||||
|
||||
private Plot isAlias(final String a) {
|
||||
for (final Plot p : PS.get().getPlots()) {
|
||||
if ((p.settings.getAlias().length() > 0) && p.settings.getAlias().equalsIgnoreCase(a)) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, String... args) {
|
||||
final ArrayList<Plot> plots = PS.get().sortPlotsByWorld(PS.get().getPlots(plr));
|
||||
if (plots.size() == 1) {
|
||||
MainUtil.teleportPlayer(plr, plr.getLocation(), plots.get(0));
|
||||
return true;
|
||||
} else if (plots.size() > 1) {
|
||||
if (args.length < 1) {
|
||||
args = new String[] { "1" };
|
||||
}
|
||||
int id = 0;
|
||||
try {
|
||||
id = Integer.parseInt(args[0]);
|
||||
} catch (final Exception e) {
|
||||
Plot temp;
|
||||
if ((temp = isAlias(args[0])) != null) {
|
||||
if (temp.hasOwner()) {
|
||||
if (temp.isOwner(plr.getUUID())) {
|
||||
MainUtil.teleportPlayer(plr, plr.getLocation(), temp);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.NOT_YOUR_PLOT);
|
||||
return false;
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.NOT_VALID_NUMBER, "(1, " + plots.size() + ")");
|
||||
return true;
|
||||
}
|
||||
if ((id > (plots.size())) || (id < 1)) {
|
||||
MainUtil.sendMessage(plr, C.NOT_VALID_NUMBER, "(1, " + plots.size() + ")");
|
||||
return false;
|
||||
}
|
||||
MainUtil.teleportPlayer(plr, plr.getLocation(), plots.get(id - 1));
|
||||
return true;
|
||||
} else {
|
||||
MainUtil.sendMessage(plr, C.FOUND_NO_PLOTS);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public void teleportPlayer(final PlotPlayer player, final Plot plot) {
|
||||
MainUtil.teleportPlayer(player, player.getLocation(), plot);
|
||||
}
|
||||
}
|
214
src/main/java/com/intellectualcrafters/plot/commands/Inbox.java
Normal file
214
src/main/java/com/intellectualcrafters/plot/commands/Inbox.java
Normal file
@ -0,0 +1,214 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
||||
import com.intellectualcrafters.plot.object.comment.CommentInbox;
|
||||
import com.intellectualcrafters.plot.object.comment.CommentManager;
|
||||
import com.intellectualcrafters.plot.object.comment.PlotComment;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
|
||||
public class Inbox extends SubCommand {
|
||||
public Inbox() {
|
||||
super(Command.INBOX, "Review the comments for a plot", "inbox [inbox] [delete <index>|clear|page]", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
public void displayComments(PlotPlayer player, List<PlotComment> oldComments, int page) {
|
||||
if (oldComments == null || oldComments.size() == 0) {
|
||||
MainUtil.sendMessage(player, C.INBOX_EMPTY);
|
||||
return;
|
||||
}
|
||||
PlotComment[] comments = oldComments.toArray(new PlotComment[oldComments.size()]);
|
||||
if (page < 0) {
|
||||
page = 0;
|
||||
}
|
||||
// Get the total pages
|
||||
// int totalPages = ((int) Math.ceil(12 *
|
||||
final int totalPages = (int) Math.ceil(comments.length / 12);
|
||||
if (page > totalPages) {
|
||||
page = totalPages;
|
||||
}
|
||||
// Only display 12 per page
|
||||
int max = (page * 12) + 12;
|
||||
if (max > comments.length) {
|
||||
max = comments.length;
|
||||
}
|
||||
final StringBuilder string = new StringBuilder();
|
||||
string.append(C.PLOT_LIST_HEADER_PAGED.s().replaceAll("plot","comment").replaceAll("%cur", page + 1 + "").replaceAll("%max", totalPages + 1 + "").replaceAll("%word%", "all")).append("\n");
|
||||
PlotComment c;
|
||||
// This might work xD
|
||||
for (int x = (page * 12); x < max; x++) {
|
||||
c = comments[x];
|
||||
String color;
|
||||
if (player.getName().equals(c.senderName)) {
|
||||
color = "&a";
|
||||
}
|
||||
else {
|
||||
color = "&7";
|
||||
}
|
||||
string.append("&8[&7#" + x + "&8][&7" + c.world + ";" + c.id + "&8][&6" + c.senderName + "&8]" + color + c.comment + "\n");
|
||||
}
|
||||
MainUtil.sendMessage(player, string.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer player, final String... args) {
|
||||
final Plot plot = MainUtil.getPlot(player.getLocation());
|
||||
if (args.length == 0) {
|
||||
sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox [inbox] [delete <index>|clear|page]");
|
||||
for (final CommentInbox inbox : CommentManager.inboxes.values()) {
|
||||
if (inbox.canRead(plot, player)) {
|
||||
if (!inbox.getComments(plot, new RunnableVal() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (value != null) {
|
||||
int total = 0;
|
||||
int unread = 0;
|
||||
for (PlotComment comment : (ArrayList<PlotComment>) value) {
|
||||
total++;
|
||||
if (comment.timestamp > CommentManager.getTimestamp(player, inbox.toString())) {
|
||||
unread++;
|
||||
}
|
||||
}
|
||||
if (total != 0) {
|
||||
String color;
|
||||
if (unread > 0) {
|
||||
color = "&c";
|
||||
}
|
||||
else {
|
||||
color = "";
|
||||
}
|
||||
sendMessage(player, C.INBOX_ITEM, color + inbox.toString() + " (" + total + "/" + unread + ")");
|
||||
return;
|
||||
}
|
||||
}
|
||||
sendMessage(player, C.INBOX_ITEM, inbox.toString());
|
||||
}
|
||||
})) {
|
||||
sendMessage(player, C.INBOX_ITEM, inbox.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
final CommentInbox inbox = CommentManager.inboxes.get(args[0].toLowerCase());
|
||||
if (inbox == null) {
|
||||
sendMessage(player, C.INVALID_INBOX, StringUtils.join(CommentManager.inboxes.keySet(),", "));
|
||||
return false;
|
||||
}
|
||||
player.setMeta("inbox:" + inbox.toString(), System.currentTimeMillis());
|
||||
final int page;
|
||||
if (args.length > 1) {
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "delete": {
|
||||
if (!inbox.canModify(plot, player)) {
|
||||
sendMessage(player, C.NO_PERM_INBOX_MODIFY);
|
||||
}
|
||||
if (args.length != 3) {
|
||||
sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox " + inbox.toString() + " delete <index>");
|
||||
}
|
||||
final int index;
|
||||
try {
|
||||
index = Integer.parseInt(args[2]);
|
||||
if (index < 1) {
|
||||
sendMessage(player, C.NOT_VALID_INBOX_INDEX, index + "");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox " + inbox.toString() + " delete <index>");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!inbox.getComments(plot, new RunnableVal() {
|
||||
@Override
|
||||
public void run() {
|
||||
List<PlotComment> comments = (List<PlotComment>) value;
|
||||
if (index > comments.size()) {
|
||||
sendMessage(player, C.NOT_VALID_INBOX_INDEX, index + "");
|
||||
}
|
||||
PlotComment comment = comments.get(index - 1);
|
||||
inbox.removeComment(plot, comment);
|
||||
plot.settings.removeComment(comment);
|
||||
MainUtil.sendMessage(player, C.COMMENT_REMOVED, comment.comment);
|
||||
}
|
||||
})) {
|
||||
sendMessage(player, C.NOT_IN_PLOT);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case "clear": {
|
||||
if (!inbox.canModify(plot, player)) {
|
||||
sendMessage(player, C.NO_PERM_INBOX_MODIFY);
|
||||
}
|
||||
inbox.clearInbox(plot);
|
||||
ArrayList<PlotComment> comments = plot.settings.getComments(inbox.toString());
|
||||
if (comments != null) {
|
||||
plot.settings.removeComments(comments);
|
||||
}
|
||||
MainUtil.sendMessage(player, C.COMMENT_REMOVED, "*");
|
||||
return true;
|
||||
}
|
||||
default: {
|
||||
try {
|
||||
page = Integer.parseInt(args[1]) ;
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox [inbox] [delete <index>|clear|page]");
|
||||
return false;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
page = 1;
|
||||
}
|
||||
if (!inbox.canRead(plot, player)) {
|
||||
sendMessage(player, C.NO_PERM_INBOX);
|
||||
return false;
|
||||
}
|
||||
if (!inbox.getComments(plot, new RunnableVal() {
|
||||
@Override
|
||||
public void run() {
|
||||
List<PlotComment> comments = (List<PlotComment>) value;
|
||||
displayComments(player, comments, page);
|
||||
}
|
||||
})) {
|
||||
if (plot == null) {
|
||||
sendMessage(player, C.NOT_IN_PLOT);
|
||||
}
|
||||
else {
|
||||
sendMessage(player, C.PLOT_UNOWNED);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
253
src/main/java/com/intellectualcrafters/plot/commands/Info.java
Normal file
253
src/main/java/com/intellectualcrafters/plot/commands/Info.java
Normal file
@ -0,0 +1,253 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.object.*;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.StringMan;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
*/
|
||||
@SuppressWarnings({ "javadoc" })
|
||||
public class Info extends SubCommand {
|
||||
public Info() {
|
||||
super(Command.INFO, "Display plot info", "info", CommandCategory.INFO, false);
|
||||
}
|
||||
|
||||
public static String getPlayerList(final Collection<UUID> uuids) {
|
||||
ArrayList<UUID> l = new ArrayList<>(uuids);
|
||||
if ((l == null) || (l.size() < 1)) {
|
||||
return C.NONE.s();
|
||||
}
|
||||
final String c = C.PLOT_USER_LIST.s();
|
||||
final StringBuilder list = new StringBuilder();
|
||||
for (int x = 0; x < l.size(); x++) {
|
||||
if ((x + 1) == l.size()) {
|
||||
list.append(c.replace("%user%", getPlayerName(l.get(x))).replace(",", ""));
|
||||
} else {
|
||||
list.append(c.replace("%user%", getPlayerName(l.get(x))));
|
||||
}
|
||||
}
|
||||
return list.toString();
|
||||
}
|
||||
|
||||
public static String getPlayerName(final UUID uuid) {
|
||||
if (uuid == null) {
|
||||
return "unknown";
|
||||
}
|
||||
if (uuid.equals(DBFunc.everyone) || uuid.toString().equalsIgnoreCase(DBFunc.everyone.toString())) {
|
||||
return "everyone";
|
||||
}
|
||||
final String name = UUIDHandler.getName(uuid);
|
||||
if (name == null) {
|
||||
return "unknown";
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer player, String... args) {
|
||||
String arg = null;
|
||||
Plot plot;
|
||||
if (args.length > 0) arg = args[0] + "";
|
||||
if (arg != null) {
|
||||
switch (arg) {
|
||||
case "trusted":
|
||||
case "alias":
|
||||
case "inv":
|
||||
case "biome":
|
||||
case "denied":
|
||||
case "flags":
|
||||
case "id":
|
||||
case "size":
|
||||
case "members":
|
||||
case "owner":
|
||||
case "rating":
|
||||
plot = MainUtil.getPlotFromString(player, null, player == null);
|
||||
break;
|
||||
default:
|
||||
plot = MainUtil.getPlotFromString(player, arg, player == null);
|
||||
if (args.length == 2) {
|
||||
arg = args[1];
|
||||
}
|
||||
else {
|
||||
arg = null;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
plot = MainUtil.getPlotFromString(player, null, player == null);
|
||||
}
|
||||
if (plot == null && arg != null) {
|
||||
plot = MainUtil.getPlotFromString(player, null, player == null);
|
||||
}
|
||||
if (plot == null) {
|
||||
if (player == null) {
|
||||
return false;
|
||||
}
|
||||
MainUtil.sendMessage(player, C.NOT_IN_PLOT);
|
||||
return false;
|
||||
}
|
||||
if (arg != null) {
|
||||
if (args.length == 1) {
|
||||
args = new String[0];
|
||||
}
|
||||
else {
|
||||
args = new String[] { args[1] };
|
||||
}
|
||||
}
|
||||
if ((args.length == 1) && args[0].equalsIgnoreCase("inv")) {
|
||||
new InfoInventory(plot, player).build().display();
|
||||
return true;
|
||||
}
|
||||
final boolean hasOwner = plot.hasOwner();
|
||||
boolean containsEveryone;
|
||||
boolean trustedEveryone;
|
||||
// Wildcard player {added}
|
||||
{
|
||||
containsEveryone = (plot.trusted != null) && plot.trusted.contains(DBFunc.everyone);
|
||||
trustedEveryone = (plot.members != null) && plot.members.contains(DBFunc.everyone);
|
||||
}
|
||||
// Unclaimed?
|
||||
if (!hasOwner && !containsEveryone && !trustedEveryone) {
|
||||
MainUtil.sendMessage(player, C.PLOT_INFO_UNCLAIMED, (plot.id.x + ";" + plot.id.y));
|
||||
return true;
|
||||
}
|
||||
String info = C.PLOT_INFO.s();
|
||||
if (arg != null) {
|
||||
info = getCaption(arg);
|
||||
if (info == null) {
|
||||
MainUtil.sendMessage(player, "&6Categories&7: &amembers&7, &aalias&7, &abiome&7, &adenied&7, &aflags&7, &aid&7, &asize&7, &atrusted&7, &aowner&7, &arating");
|
||||
return false;
|
||||
}
|
||||
formatAndSend(info, plot.world, plot, player, true);
|
||||
}
|
||||
else {
|
||||
formatAndSend(info, plot.world, plot, player, false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private String getCaption(final String string) {
|
||||
switch (string) {
|
||||
case "trusted":
|
||||
return C.PLOT_INFO_TRUSTED.s();
|
||||
case "alias":
|
||||
return C.PLOT_INFO_ALIAS.s();
|
||||
case "biome":
|
||||
return C.PLOT_INFO_BIOME.s();
|
||||
case "denied":
|
||||
return C.PLOT_INFO_DENIED.s();
|
||||
case "flags":
|
||||
return C.PLOT_INFO_FLAGS.s();
|
||||
case "id":
|
||||
return C.PLOT_INFO_ID.s();
|
||||
case "size":
|
||||
return C.PLOT_INFO_SIZE.s();
|
||||
case "members":
|
||||
return C.PLOT_INFO_MEMBERS.s();
|
||||
case "owner":
|
||||
return C.PLOT_INFO_OWNER.s();
|
||||
case "rating":
|
||||
return C.PLOT_INFO_RATING.s();
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void formatAndSend(String info, final String world, final Plot plot, final PlotPlayer player, final boolean full) {
|
||||
final PlotId id = plot.id;
|
||||
final PlotId id2 = MainUtil.getTopPlot(plot).id;
|
||||
final int num = MainUtil.getPlotSelectionIds(id, id2).size();
|
||||
final String alias = plot.settings.getAlias().length() > 0 ? plot.settings.getAlias() : C.NONE.s();
|
||||
Location top = MainUtil.getPlotTopLoc(world, plot.id);
|
||||
Location bot = MainUtil.getPlotBottomLoc(world, plot.id).add(1,0,1);
|
||||
final String biome = BlockManager.manager.getBiome(bot.add((top.getX() - bot.getX()) / 2, 0, (top.getX() - bot.getX()) / 2));
|
||||
final String trusted = getPlayerList(plot.trusted);
|
||||
final String members = getPlayerList(plot.members);
|
||||
final String denied = getPlayerList(plot.denied);
|
||||
|
||||
final String flags = StringMan.replaceFromMap("$2" + (StringUtils.join(FlagManager.getPlotFlags(plot).values(), "").length() > 0 ? StringUtils.join(FlagManager.getPlotFlags(plot).values(), "$1, $2") : C.NONE.s()), C.replacements);
|
||||
final boolean build = (player == null) || plot.isAdded(player.getUUID());
|
||||
|
||||
String owner = plot.owner == null ? "unowned" : getPlayerList(plot.getOwners());
|
||||
|
||||
info = info.replaceAll("%alias%", alias);
|
||||
info = info.replaceAll("%id%", id.toString());
|
||||
info = info.replaceAll("%id2%", id2.toString());
|
||||
info = info.replaceAll("%num%", num + "");
|
||||
info = info.replaceAll("%biome%", biome);
|
||||
info = info.replaceAll("%owner%", owner);
|
||||
info = info.replaceAll("%members%", members);
|
||||
info = info.replaceAll("%trusted%", trusted);
|
||||
info = info.replaceAll("%helpers%", members);
|
||||
info = info.replaceAll("%denied%", denied);
|
||||
info = info.replaceAll("%flags%", Matcher.quoteReplacement(flags));
|
||||
info = info.replaceAll("%build%", build + "");
|
||||
info = info.replaceAll("%desc%", "No description set.");
|
||||
if (info.contains("%rating%")) {
|
||||
final String newInfo = info;
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int max = 10;
|
||||
if (Settings.RATING_CATEGORIES != null && Settings.RATING_CATEGORIES.size() > 0) {
|
||||
max = 8;
|
||||
}
|
||||
String info;
|
||||
if (full && Settings.RATING_CATEGORIES != null && Settings.RATING_CATEGORIES.size() > 1) {
|
||||
String rating = "";
|
||||
String prefix = "";
|
||||
double[] ratings = MainUtil.getAverageRatings(plot);
|
||||
for (int i = 0; i < ratings.length; i++) {
|
||||
rating += prefix + Settings.RATING_CATEGORIES.get(i) + "=" + String.format("%.1f", ratings[i]);
|
||||
prefix = ",";
|
||||
}
|
||||
info = newInfo.replaceAll("%rating%", rating);
|
||||
}
|
||||
else {
|
||||
info = newInfo.replaceAll("%rating%", String.format("%.1f", MainUtil.getAverageRating(plot)) + "/" + max);
|
||||
}
|
||||
MainUtil.sendMessage(player, C.PLOT_INFO_HEADER);
|
||||
MainUtil.sendMessage(player, info, false);
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
MainUtil.sendMessage(player, C.PLOT_INFO_HEADER);
|
||||
MainUtil.sendMessage(player, info, false);
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.BukkitPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
|
||||
public class Inventory extends SubCommand {
|
||||
public Inventory() {
|
||||
super("inventory", "plots.inventory", "Open a command inventory", "inventory", "inv", CommandCategory.INFO, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
final ArrayList<SubCommand> cmds = new ArrayList<>();
|
||||
for (final SubCommand cmd : MainCommand.subCommands) {
|
||||
if (cmd.permission.hasPermission(plr)) {
|
||||
cmds.add(cmd);
|
||||
}
|
||||
}
|
||||
final int size = 9 * (int) Math.ceil(cmds.size() / 9.0);
|
||||
final org.bukkit.inventory.Inventory inventory = Bukkit.createInventory(null, size, "PlotSquared Commands");
|
||||
for (final SubCommand cmd : cmds) {
|
||||
inventory.addItem(getItem(cmd));
|
||||
}
|
||||
((BukkitPlayer) plr).player.openInventory(inventory);
|
||||
return true;
|
||||
}
|
||||
|
||||
private ItemStack getItem(final SubCommand cmd) {
|
||||
final ItemStack stack = new ItemStack(Material.COMMAND);
|
||||
final ItemMeta meta = stack.getItemMeta();
|
||||
{
|
||||
meta.setDisplayName(ChatColor.GREEN + cmd.cmd + ChatColor.DARK_GRAY + " [" + ChatColor.GREEN + cmd.alias + ChatColor.DARK_GRAY + "]");
|
||||
meta.setLore(new ArrayList<String>() {
|
||||
{
|
||||
add(C.INVENTORY_CATEGORY.s().replace("{category}", cmd.category.toString()));
|
||||
add(C.INVENTORY_DESC.s().replace("{desc}", cmd.description));
|
||||
add(C.INVENTORY_USAGE.s().replace("{usage}", "/plot " + cmd.usage));
|
||||
}
|
||||
});
|
||||
}
|
||||
stack.setItemMeta(meta);
|
||||
return stack;
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
@SuppressWarnings({ "unused", "deprecation", "javadoc" })
|
||||
public class Kick extends SubCommand {
|
||||
public Kick() {
|
||||
super(Command.KICK, "Kick a player from your plot", "kick", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||
}
|
||||
if (plot == null || ((!plot.hasOwner() || !plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.kick"))) {
|
||||
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||
return false;
|
||||
}
|
||||
if (args.length != 1) {
|
||||
MainUtil.sendMessage(plr, "&c/plot kick <player>");
|
||||
return false;
|
||||
}
|
||||
final PlotPlayer player = UUIDHandler.getPlayer(args[0]);
|
||||
if (player == null) {
|
||||
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
|
||||
return false;
|
||||
}
|
||||
Location otherLoc = player.getLocation();
|
||||
if (!plr.getLocation().getWorld().equals(otherLoc.getWorld()) || !plot.equals(MainUtil.getPlot(otherLoc))) {
|
||||
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
|
||||
return false;
|
||||
}
|
||||
player.teleport(BlockManager.manager.getSpawn(loc.getWorld()));
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,193 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.StringComparison;
|
||||
|
||||
/**
|
||||
* PlotSquared command class
|
||||
*
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class MainCommand {
|
||||
/**
|
||||
* Main Permission Node
|
||||
*/
|
||||
private final static SubCommand[] _subCommands = new SubCommand[] { };
|
||||
public final static ArrayList<SubCommand> subCommands = new ArrayList<SubCommand>() {
|
||||
{
|
||||
addAll(Arrays.asList(_subCommands));
|
||||
}
|
||||
};
|
||||
|
||||
public static boolean no_permission(final PlotPlayer player, final String permission) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, permission);
|
||||
return false;
|
||||
}
|
||||
|
||||
public static List<SubCommand> getCommands(final SubCommand.CommandCategory category, final PlotPlayer player) {
|
||||
final List<SubCommand> cmds = new ArrayList<>();
|
||||
for (final SubCommand c : subCommands) {
|
||||
if (!c.isPlayer || (player != null)) {
|
||||
if ((c.category.equals(category)) && c.permission.hasPermission(player)) {
|
||||
cmds.add(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
return cmds;
|
||||
}
|
||||
|
||||
public static List<String> helpMenu(final PlotPlayer player, final SubCommand.CommandCategory category, int page) {
|
||||
List<SubCommand> commands;
|
||||
if (category != null) {
|
||||
commands = getCommands(category, player);
|
||||
} else {
|
||||
commands = subCommands;
|
||||
}
|
||||
// final int totalPages = ((int) Math.ceil(12 * (commands.size()) /
|
||||
// 100));
|
||||
final int perPage = 5;
|
||||
final int totalPages = (commands.size() / perPage) + (commands.size() % perPage == 0 ? 0 : 1);
|
||||
if (page > totalPages) {
|
||||
page = totalPages;
|
||||
}
|
||||
int max = (page * perPage) + perPage;
|
||||
if (max > commands.size()) {
|
||||
max = commands.size();
|
||||
}
|
||||
final List<String> help = new ArrayList<>();
|
||||
help.add(C.HELP_HEADER.s());
|
||||
// HELP_CATEGORY("&cCategory: &6%category%&c, Page: %current%&c/&6%max%&c, Displaying: &6%dis%&c/&6%total%"),
|
||||
help.add(C.HELP_CATEGORY.s().replace("%category%", category == null ? "All" : category.toString()).replace("%current%", "" + (page + 1)).replace("%max%", "" + (totalPages)).replace("%dis%", "" + (commands.size() % perPage)).replace("%total%", "" + commands.size()));
|
||||
SubCommand cmd;
|
||||
final int start = page * perPage;
|
||||
for (int x = start; x < max; x++) {
|
||||
cmd = commands.get(x);
|
||||
String s = t(C.HELP_ITEM.s());
|
||||
if (cmd.alias.size() > 0) {
|
||||
s = s.replace("%alias%", cmd.alias.get(0));
|
||||
}
|
||||
else {
|
||||
s = s.replace("%alias%", "");
|
||||
}
|
||||
s = s.replace("%usage%", cmd.usage.contains("plot") ? cmd.usage : "/plot " + cmd.usage).replace("%cmd%", cmd.cmd).replace("%desc%", cmd.description).replace("[]", "");
|
||||
help.add(s);
|
||||
}
|
||||
if (help.size() < 2) {
|
||||
help.add(t(C.NO_COMMANDS.s()));
|
||||
}
|
||||
return help;
|
||||
}
|
||||
|
||||
private static String t(final String s) {
|
||||
return MainUtil.colorise('&', s);
|
||||
}
|
||||
|
||||
public static boolean onCommand(final PlotPlayer player, final String cmd, final String... args) {
|
||||
if ((args.length < 1) || ((args.length >= 1) && (args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("he")))) {
|
||||
if (args.length < 2) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
builder.append(C.HELP_INFO.s());
|
||||
for (final SubCommand.CommandCategory category : SubCommand.CommandCategory.values()) {
|
||||
builder.append("\n").append(C.HELP_INFO_ITEM.s().replaceAll("%category%", category.toString().toLowerCase()).replaceAll("%category_desc%", category.toString()));
|
||||
}
|
||||
builder.append("\n").append(C.HELP_INFO_ITEM.s().replaceAll("%category%", "all").replaceAll("%category_desc%", "Display all commands"));
|
||||
return MainUtil.sendMessage(player, builder.toString());
|
||||
}
|
||||
final String cat = args[1];
|
||||
SubCommand.CommandCategory cato = null;
|
||||
for (final SubCommand.CommandCategory category : SubCommand.CommandCategory.values()) {
|
||||
if (cat.equalsIgnoreCase(category.toString())) {
|
||||
cato = category;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((cato == null) && !cat.equalsIgnoreCase("all")) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
builder.append(C.HELP_INFO.s());
|
||||
for (final SubCommand.CommandCategory category : SubCommand.CommandCategory.values()) {
|
||||
builder.append("\n").append(C.HELP_INFO_ITEM.s().replaceAll("%category%", category.toString().toLowerCase()).replaceAll("%category_desc%", category.toString()));
|
||||
}
|
||||
return MainUtil.sendMessage(player, builder.toString(), false);
|
||||
}
|
||||
final StringBuilder help = new StringBuilder();
|
||||
int page = 0;
|
||||
boolean digit = true;
|
||||
String arg2;
|
||||
if (args.length > 2) {
|
||||
arg2 = args[2];
|
||||
} else {
|
||||
arg2 = "1";
|
||||
}
|
||||
for (final char c : arg2.toCharArray()) {
|
||||
if (!Character.isDigit(c)) {
|
||||
digit = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (digit) {
|
||||
page = Integer.parseInt(arg2);
|
||||
if (--page < 0) {
|
||||
page = 0;
|
||||
}
|
||||
}
|
||||
for (final String string : helpMenu(player, cato, page)) {
|
||||
help.append(string).append("\n");
|
||||
}
|
||||
MainUtil.sendMessage(player, help.toString());
|
||||
// return PlayerFunctions.sendMessage(player, help.toString());
|
||||
} else {
|
||||
for (final SubCommand command : subCommands) {
|
||||
if (command.cmd.equalsIgnoreCase(args[0]) || command.alias.contains(args[0].toLowerCase())) {
|
||||
final String[] arguments = new String[args.length - 1];
|
||||
System.arraycopy(args, 1, arguments, 0, args.length - 1);
|
||||
if (command.permission.hasPermission(player)) {
|
||||
if ((player != null) || !command.isPlayer) {
|
||||
return command.execute(player, arguments);
|
||||
} else {
|
||||
return !MainUtil.sendMessage(null, C.IS_CONSOLE);
|
||||
}
|
||||
} else {
|
||||
return no_permission(player, command.permission.permission.toLowerCase());
|
||||
}
|
||||
}
|
||||
}
|
||||
MainUtil.sendMessage(player, C.NOT_VALID_SUBCOMMAND);
|
||||
final String[] commands = new String[subCommands.size()];
|
||||
for (int x = 0; x < subCommands.size(); x++) {
|
||||
commands[x] = subCommands.get(x).cmd;
|
||||
}
|
||||
/* Let's try to get a proper usage string */
|
||||
final String command = new StringComparison(args[0], commands).getBestMatch();
|
||||
return MainUtil.sendMessage(player, C.DID_YOU_MEAN, "/plot " + command);
|
||||
// PlayerFunctions.sendMessage(player, C.DID_YOU_MEAN, new
|
||||
// StringComparsion(args[0], commands).getBestMatch());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
231
src/main/java/com/intellectualcrafters/plot/commands/Merge.java
Normal file
231
src/main/java/com/intellectualcrafters/plot/commands/Merge.java
Normal file
@ -0,0 +1,231 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.CmdConfirm;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.intellectualcrafters.plot.util.EventUtil;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class Merge extends SubCommand {
|
||||
public final static String[] values = new String[] { "north", "east", "south", "west" };
|
||||
public final static String[] aliases = new String[] { "n", "e", "s", "w" };
|
||||
|
||||
public Merge() {
|
||||
super(Command.MERGE, "Merge the plot you are standing on with another plot.", "merge", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
public static String direction(float yaw) {
|
||||
yaw = yaw / 90;
|
||||
final int i = Math.round(yaw);
|
||||
switch (i) {
|
||||
case -4:
|
||||
case 0:
|
||||
case 4:
|
||||
return "SOUTH";
|
||||
case -1:
|
||||
case 3:
|
||||
return "EAST";
|
||||
case -2:
|
||||
case 2:
|
||||
return "NORTH";
|
||||
case -3:
|
||||
case 1:
|
||||
return "WEST";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
final Location loc = plr.getLocationFull();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||
}
|
||||
if ((plot == null) || !plot.hasOwner()) {
|
||||
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
|
||||
return false;
|
||||
}
|
||||
final boolean admin = Permissions.hasPermission(plr, "plots.admin.command.merge");
|
||||
if (!plot.isOwner(plr.getUUID()) && !admin) {
|
||||
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||
return false;
|
||||
}
|
||||
if (args.length < 1) {
|
||||
MainUtil.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + StringUtils.join(values, C.BLOCK_LIST_SEPARATER.s()));
|
||||
MainUtil.sendMessage(plr, C.DIRECTION.s().replaceAll("%dir%", direction(loc.getYaw())));
|
||||
return false;
|
||||
}
|
||||
int direction = -1;
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
if (args[0].equalsIgnoreCase(values[i]) || args[0].equalsIgnoreCase(aliases[i])) {
|
||||
direction = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (direction == -1) {
|
||||
MainUtil.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + StringUtils.join(values, C.BLOCK_LIST_SEPARATER.s()));
|
||||
MainUtil.sendMessage(plr, C.DIRECTION.s().replaceAll("%dir%", direction(loc.getYaw())));
|
||||
return false;
|
||||
}
|
||||
PlotId bot = MainUtil.getBottomPlot(plot).id;
|
||||
PlotId top = MainUtil.getTopPlot(plot).id;
|
||||
ArrayList<PlotId> selPlots;
|
||||
final String world = loc.getWorld();
|
||||
switch (direction) {
|
||||
case 0: // north = -y
|
||||
selPlots = MainUtil.getMaxPlotSelectionIds(world, new PlotId(bot.x, bot.y - 1), new PlotId(top.x, top.y));
|
||||
break;
|
||||
case 1: // east = +x
|
||||
selPlots = MainUtil.getMaxPlotSelectionIds(world, new PlotId(bot.x, bot.y), new PlotId(top.x + 1, top.y));
|
||||
break;
|
||||
case 2: // south = +y
|
||||
selPlots = MainUtil.getMaxPlotSelectionIds(world, new PlotId(bot.x, bot.y), new PlotId(top.x, top.y + 1));
|
||||
break;
|
||||
case 3: // west = -x
|
||||
selPlots = MainUtil.getMaxPlotSelectionIds(world, new PlotId(bot.x - 1, bot.y), new PlotId(top.x, top.y));
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
final PlotId botId = selPlots.get(0);
|
||||
final PlotId topId = selPlots.get(selPlots.size() - 1);
|
||||
final PlotId bot1 = MainUtil.getBottomPlot(MainUtil.getPlot(world, botId)).id;
|
||||
final PlotId bot2 = MainUtil.getBottomPlot(MainUtil.getPlot(world, topId)).id;
|
||||
final PlotId top1 = MainUtil.getTopPlot(MainUtil.getPlot(world, topId)).id;
|
||||
final PlotId top2 = MainUtil.getTopPlot(MainUtil.getPlot(world, botId)).id;
|
||||
bot = new PlotId(Math.min(bot1.x, bot2.x), Math.min(bot1.y, bot2.y));
|
||||
top = new PlotId(Math.max(top1.x, top2.x), Math.max(top1.y, top2.y));
|
||||
final ArrayList<PlotId> plots = MainUtil.getMaxPlotSelectionIds(world, bot, top);
|
||||
boolean multiMerge = false;
|
||||
final HashSet<UUID> multiUUID = new HashSet<UUID>();
|
||||
HashSet<PlotId> multiPlots = new HashSet<>();
|
||||
final UUID u1 = plot.owner;
|
||||
for (final PlotId myid : plots) {
|
||||
final Plot myplot = PS.get().getPlots(world).get(myid);
|
||||
if (myplot == null || myplot.owner == null) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERM_MERGE.s().replaceAll("%plot%", myid.toString()));
|
||||
return false;
|
||||
}
|
||||
UUID u2 = myplot.owner;
|
||||
if (u2.equals(u1)) {
|
||||
continue;
|
||||
}
|
||||
PlotPlayer p2 = UUIDHandler.getPlayer(u2);
|
||||
if (p2 == null) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERM_MERGE.s().replaceAll("%plot%", myid.toString()));
|
||||
return false;
|
||||
}
|
||||
multiMerge = true;
|
||||
multiPlots.add(myid);
|
||||
multiUUID.add(u2);
|
||||
}
|
||||
if (multiMerge) {
|
||||
if (!Permissions.hasPermission(plr, Permissions.MERGE_OTHER)) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, Permissions.MERGE_OTHER.s);
|
||||
return false;
|
||||
}
|
||||
for (final UUID uuid : multiUUID) {
|
||||
PlotPlayer accepter = UUIDHandler.getPlayer(uuid);
|
||||
CmdConfirm.addPending(accepter, C.MERGE_REQUEST_CONFIRM.s().replaceAll("%s", plr.getName()), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PlotPlayer accepter = UUIDHandler.getPlayer(uuid);
|
||||
multiUUID.remove(uuid);
|
||||
if (multiUUID.size() == 0) {
|
||||
PlotPlayer pp = UUIDHandler.getPlayer(u1);
|
||||
if (pp == null) {
|
||||
sendMessage(accepter, C.MERGE_NOT_VALID);
|
||||
return;
|
||||
}
|
||||
final PlotWorld plotWorld = PS.get().getPlotWorld(world);
|
||||
if ((EconHandler.manager != null) && plotWorld.USE_ECONOMY) {
|
||||
double cost = plotWorld.MERGE_PRICE;
|
||||
cost = plots.size() * cost;
|
||||
if (cost > 0d) {
|
||||
if (EconHandler.manager.getMoney(plr) < cost) {
|
||||
sendMessage(plr, C.CANNOT_AFFORD_MERGE, cost + "");
|
||||
return;
|
||||
}
|
||||
EconHandler.manager.withdrawMoney(plr, cost);
|
||||
sendMessage(plr, C.REMOVED_BALANCE, cost + "");
|
||||
}
|
||||
}
|
||||
final boolean result = EventUtil.manager.callMerge(world, plot, plots);
|
||||
if (!result) {
|
||||
MainUtil.sendMessage(plr, "&cMerge has been cancelled");
|
||||
return;
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.SUCCESS_MERGE);
|
||||
MainUtil.mergePlots(world, plots, true);
|
||||
MainUtil.setSign(UUIDHandler.getName(plot.owner), plot);
|
||||
}
|
||||
MainUtil.sendMessage(accepter, C.MERGE_ACCEPTED);
|
||||
}
|
||||
});
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.MERGE_REQUESTED);
|
||||
return true;
|
||||
}
|
||||
final PlotWorld plotWorld = PS.get().getPlotWorld(world);
|
||||
if ((EconHandler.manager != null) && plotWorld.USE_ECONOMY) {
|
||||
double cost = plotWorld.MERGE_PRICE;
|
||||
cost = plots.size() * cost;
|
||||
if (cost > 0d) {
|
||||
if (EconHandler.manager.getMoney(plr) < cost) {
|
||||
sendMessage(plr, C.CANNOT_AFFORD_MERGE, cost + "");
|
||||
return false;
|
||||
}
|
||||
EconHandler.manager.withdrawMoney(plr, cost);
|
||||
sendMessage(plr, C.REMOVED_BALANCE, cost + "");
|
||||
}
|
||||
}
|
||||
final boolean result = EventUtil.manager.callMerge(world, plot, plots);
|
||||
if (!result) {
|
||||
MainUtil.sendMessage(plr, "&cMerge has been cancelled");
|
||||
return false;
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.SUCCESS_MERGE);
|
||||
MainUtil.mergePlots(world, plots, true);
|
||||
MainUtil.setSign(UUIDHandler.getName(plot.owner), plot);
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
|
||||
/**
|
||||
* Created 2014-08-01 for PlotSquared
|
||||
*
|
||||
* @author Empire92
|
||||
*/
|
||||
public class Move extends SubCommand {
|
||||
public Move() {
|
||||
super(Command.MOVE, "Move a plot", "debugmove", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (args.length < 1) {
|
||||
MainUtil.sendMessage(plr, C.NEED_PLOT_ID);
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot move <X;Z>");
|
||||
return false;
|
||||
}
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot1 = MainUtil.getPlot(loc);
|
||||
if (plot1 == null) {
|
||||
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||
}
|
||||
if (!plot1.isAdded(plr.getUUID()) && !plr.hasPermission(Permissions.ADMIN.s)) {
|
||||
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||
return false;
|
||||
}
|
||||
final String world = loc.getWorld();
|
||||
final PlotId plot2id = MainUtil.parseId(args[0]);
|
||||
if ((plot2id == null)) {
|
||||
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot move <X;Z>");
|
||||
return false;
|
||||
}
|
||||
String world2;
|
||||
if (args.length == 2) {
|
||||
PlotWorld other = PS.get().getPlotWorld(args[1]);
|
||||
PlotWorld current = PS.get().getPlotWorld(loc.getWorld());
|
||||
if (other == null || current == null || !other.equals(current)) {
|
||||
MainUtil.sendMessage(plr, C.PLOTWORLD_INCOMPATIBLE);
|
||||
return false;
|
||||
}
|
||||
world2 = other.worldname;
|
||||
}
|
||||
else {
|
||||
world2 = world;
|
||||
}
|
||||
Plot plot2 = MainUtil.getPlot(world2, plot2id);
|
||||
|
||||
if (plot1.equals(plot2)) {
|
||||
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot move <X;Z>");
|
||||
return false;
|
||||
}
|
||||
if (MainUtil.move(plot1, plot2, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.sendMessage(plr, C.MOVE_SUCCESS);
|
||||
}
|
||||
})) {
|
||||
return true;
|
||||
} else {
|
||||
MainUtil.sendMessage(plr, C.REQUIRES_UNOWNED);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.listeners.PlotListener;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||
import com.intellectualcrafters.plot.object.PlotInventory;
|
||||
import com.intellectualcrafters.plot.object.PlotItemStack;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
|
||||
public class MusicSubcommand extends SubCommand {
|
||||
public MusicSubcommand() {
|
||||
super("music", "plots.music", "Play music in plot", "music", "mus", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer player, final String... args) {
|
||||
final Location loc = player.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
return !sendMessage(player, C.NOT_IN_PLOT);
|
||||
}
|
||||
if (!plot.isAdded(player.getUUID())) {
|
||||
sendMessage(player, C.NO_PLOT_PERMS);
|
||||
return true;
|
||||
}
|
||||
PlotInventory inv = new PlotInventory(player, 2, "Plot Jukebox") {
|
||||
public boolean onClick(int index) {
|
||||
PlotItemStack item = getItem(index);
|
||||
int id = item.id == 7 ? 0 : item.id;
|
||||
if (id == 0) {
|
||||
FlagManager.removePlotFlag(plot, "music");
|
||||
}
|
||||
else {
|
||||
FlagManager.addPlotFlag(plot, new Flag(FlagManager.getFlag("music"), id));
|
||||
}
|
||||
TaskManager.runTaskLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PlotListener.manager.plotEntry(player, plot);
|
||||
}
|
||||
}, 1);
|
||||
close();
|
||||
return false;
|
||||
}
|
||||
};
|
||||
int index = 0;
|
||||
for (int i = 2256; i < 2268; i++) {
|
||||
String name = "&r&6" + BlockManager.manager.getClosestMatchingName(new PlotBlock((short) i, (byte) 0));
|
||||
String[] lore = {"&r&aClick to play!"};
|
||||
PlotItemStack item = new PlotItemStack(i, (byte) 0, 1, name, lore);
|
||||
inv.setItem(index, item);
|
||||
index++;
|
||||
}
|
||||
if (player.getMeta("music") != null) {
|
||||
String name = "&r&6Cancel music";
|
||||
String[] lore = {"&r&cClick to cancel!"};
|
||||
inv.setItem(index, new PlotItemStack(7, (short) 0, 1, name, lore));
|
||||
}
|
||||
inv.openInventory();
|
||||
return true;
|
||||
}
|
||||
}
|
170
src/main/java/com/intellectualcrafters/plot/commands/Purge.java
Normal file
170
src/main/java/com/intellectualcrafters/plot/commands/Purge.java
Normal file
@ -0,0 +1,170 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
@SuppressWarnings({ "javadoc" })
|
||||
public class Purge extends SubCommand {
|
||||
public Purge() {
|
||||
super("purge", "plots.admin", "Purge all plots for a world", "purge", "", CommandCategory.DEBUG, false);
|
||||
}
|
||||
|
||||
public PlotId getId(final String id) {
|
||||
try {
|
||||
final String[] split = id.split(";");
|
||||
return new PlotId(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
|
||||
} catch (final Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (plr != null) {
|
||||
MainUtil.sendMessage(plr, (C.NOT_CONSOLE));
|
||||
return false;
|
||||
}
|
||||
if (args.length == 1) {
|
||||
final String arg = args[0].toLowerCase();
|
||||
final PlotId id = getId(arg);
|
||||
if (id != null) {
|
||||
MainUtil.sendMessage(plr, "/plot purge x;z &l<world>");
|
||||
return false;
|
||||
}
|
||||
final UUID uuid = UUIDHandler.getUUID(args[0]);
|
||||
if (uuid != null) {
|
||||
MainUtil.sendMessage(plr, "/plot purge " + args[0] + " &l<world>");
|
||||
return false;
|
||||
}
|
||||
if (arg.equals("player")) {
|
||||
MainUtil.sendMessage(plr, "/plot purge &l<player> <world>");
|
||||
return false;
|
||||
}
|
||||
if (arg.equals("unowned")) {
|
||||
MainUtil.sendMessage(plr, "/plot purge unowned &l<world>");
|
||||
return false;
|
||||
}
|
||||
if (arg.equals("unknown")) {
|
||||
MainUtil.sendMessage(plr, "/plot purge unknown &l<world>");
|
||||
return false;
|
||||
}
|
||||
if (arg.equals("all")) {
|
||||
MainUtil.sendMessage(plr, "/plot purge all &l<world>");
|
||||
return false;
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.PURGE_SYNTAX);
|
||||
return false;
|
||||
}
|
||||
if (args.length != 2) {
|
||||
MainUtil.sendMessage(plr, C.PURGE_SYNTAX);
|
||||
return false;
|
||||
}
|
||||
final String worldname = args[1];
|
||||
if (!PS.get().getAllPlotsRaw().containsKey(worldname)) {
|
||||
MainUtil.sendMessage(plr, "INVALID WORLD");
|
||||
return false;
|
||||
}
|
||||
final String arg = args[0].toLowerCase();
|
||||
final PlotId id = getId(arg);
|
||||
if (id != null) {
|
||||
final HashSet<Integer> ids = new HashSet<Integer>();
|
||||
final int DBid = DBFunc.getId(worldname, id);
|
||||
if (DBid != Integer.MAX_VALUE) {
|
||||
ids.add(DBid);
|
||||
}
|
||||
DBFunc.purgeIds(worldname, ids);
|
||||
return finishPurge(DBid == Integer.MAX_VALUE ? 1 : 0);
|
||||
}
|
||||
if (arg.equals("all")) {
|
||||
final Set<PlotId> ids = PS.get().getPlots(worldname).keySet();
|
||||
int length = ids.size();
|
||||
if (length == 0) {
|
||||
return MainUtil.sendMessage(null, "&cNo plots found");
|
||||
}
|
||||
DBFunc.purge(worldname, ids);
|
||||
return finishPurge(length);
|
||||
}
|
||||
if (arg.equals("unknown")) {
|
||||
final Collection<Plot> plots = PS.get().getPlots(worldname).values();
|
||||
final Set<PlotId> ids = new HashSet<>();
|
||||
for (final Plot plot : plots) {
|
||||
if (plot.owner != null) {
|
||||
final String name = UUIDHandler.getName(plot.owner);
|
||||
if (name == null) {
|
||||
ids.add(plot.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
int length = ids.size();
|
||||
if (length == 0) {
|
||||
return MainUtil.sendMessage(null, "&cNo plots found");
|
||||
}
|
||||
DBFunc.purge(worldname, ids);
|
||||
return finishPurge(length);
|
||||
}
|
||||
if (arg.equals("unowned")) {
|
||||
final Collection<Plot> plots = PS.get().getPlots(worldname).values();
|
||||
final Set<PlotId> ids = new HashSet<>();
|
||||
for (final Plot plot : plots) {
|
||||
if (plot.owner == null) {
|
||||
ids.add(plot.id);
|
||||
}
|
||||
}
|
||||
int length = ids.size();
|
||||
if (length == 0) {
|
||||
return MainUtil.sendMessage(null, "&cNo plots found");
|
||||
}
|
||||
DBFunc.purge(worldname, ids);
|
||||
return finishPurge(length);
|
||||
}
|
||||
final UUID uuid = UUIDHandler.getUUID(args[0]);
|
||||
if (uuid != null) {
|
||||
final Set<Plot> plots = PS.get().getPlots(worldname, uuid);
|
||||
final Set<PlotId> ids = new HashSet<>();
|
||||
for (final Plot plot : plots) {
|
||||
ids.add(plot.id);
|
||||
}
|
||||
int length = ids.size();
|
||||
DBFunc.purge(worldname, ids);
|
||||
return finishPurge(length);
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.PURGE_SYNTAX);
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean finishPurge(final int amount) {
|
||||
MainUtil.sendMessage(null, C.PURGE_SUCCESS, amount + "");
|
||||
return false;
|
||||
}
|
||||
}
|
212
src/main/java/com/intellectualcrafters/plot/commands/Rate.java
Normal file
212
src/main/java/com/intellectualcrafters/plot/commands/Rate.java
Normal file
@ -0,0 +1,212 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.events.PlotRateEvent;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.mutable.MutableInt;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotInventory;
|
||||
import com.intellectualcrafters.plot.object.PlotItemStack;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.Rating;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class Rate extends SubCommand {
|
||||
/*
|
||||
* String cmd, String permission, String description, String usage, String
|
||||
* alias, CommandCategory category
|
||||
*/
|
||||
public Rate() {
|
||||
super("rate", "plots.rate", "Rate the plot", "rate [#|next]", "rt", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer player, final String... args) {
|
||||
if (args.length == 1) {
|
||||
if (args[0].equalsIgnoreCase("next")) {
|
||||
ArrayList<Plot> plots = new ArrayList<>(PS.get().getPlots());
|
||||
Collections.sort(plots, new Comparator<Plot>() {
|
||||
@Override
|
||||
public int compare(Plot p1, Plot p2) {
|
||||
double v1 = 0;
|
||||
double v2 = 0;
|
||||
if (p1.settings.ratings != null) {
|
||||
for (Entry<UUID, Rating> entry : p1.getRatings().entrySet()) {
|
||||
v1 -= 11 - entry.getValue().getAverageRating();
|
||||
}
|
||||
}
|
||||
if (p2.settings.ratings != null) {
|
||||
for (Entry<UUID, Rating> entry : p2.getRatings().entrySet()) {
|
||||
v2 -= 11 - entry.getValue().getAverageRating();
|
||||
}
|
||||
}
|
||||
return v2 > v1 ? 1 : -1;
|
||||
}
|
||||
});
|
||||
UUID uuid = player.getUUID();
|
||||
for (Plot p : plots) {
|
||||
if (p.settings.ratings == null || !p.settings.ratings.containsKey(uuid)) {
|
||||
MainUtil.teleportPlayer(player, player.getLocation(), p);
|
||||
MainUtil.sendMessage(player, C.RATE_THIS);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
MainUtil.sendMessage(player, C.FOUND_NO_PLOTS);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
final Location loc = player.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
return !sendMessage(player, C.NOT_IN_PLOT);
|
||||
}
|
||||
if (!plot.hasOwner()) {
|
||||
sendMessage(player, C.RATING_NOT_OWNED);
|
||||
return true;
|
||||
}
|
||||
if (plot.isOwner(player.getUUID())) {
|
||||
sendMessage(player, C.RATING_NOT_YOUR_OWN);
|
||||
return true;
|
||||
}
|
||||
if (Settings.RATING_CATEGORIES != null && Settings.RATING_CATEGORIES.size() != 0) {
|
||||
final Runnable run = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (plot.settings.ratings.containsKey(player.getUUID())) {
|
||||
sendMessage(player, C.RATING_ALREADY_EXISTS, plot.getId().toString());
|
||||
return;
|
||||
}
|
||||
final MutableInt index = new MutableInt(0);
|
||||
final MutableInt rating = new MutableInt(0);
|
||||
String title = Settings.RATING_CATEGORIES.get(0);
|
||||
PlotInventory inventory = new PlotInventory(player, 1, title) {
|
||||
public boolean onClick(int i) {
|
||||
rating.add((i + 1) * Math.pow(10, index.intValue()));
|
||||
index.increment();
|
||||
if (index.intValue() >= Settings.RATING_CATEGORIES.size()) {
|
||||
close();
|
||||
// handle ratings
|
||||
int rV = rating.intValue();
|
||||
// CALL THE EVENT
|
||||
PlotRateEvent rateEvent = new PlotRateEvent(player, rV, plot);
|
||||
Bukkit.getPluginManager().callEvent(rateEvent);
|
||||
// DONE CALLING THE EVENT
|
||||
// get new rating
|
||||
rV = rateEvent.getRating();
|
||||
// set rating
|
||||
plot.settings.ratings.put(player.getUUID(), rV);
|
||||
DBFunc.setRating(plot, player.getUUID(), rV);
|
||||
sendMessage(player, C.RATING_APPLIED, plot.getId().toString());
|
||||
sendMessage(player, C.RATING_APPLIED, plot.getId().toString());
|
||||
return false;
|
||||
}
|
||||
setTitle(Settings.RATING_CATEGORIES.get(index.intValue()));
|
||||
return false;
|
||||
}
|
||||
};
|
||||
inventory.setItem(0, new PlotItemStack(35, (short) 12, 0, "0/8", null));
|
||||
inventory.setItem(1, new PlotItemStack(35, (short) 14, 1, "1/8", null));
|
||||
inventory.setItem(2, new PlotItemStack(35, (short) 1, 2, "2/8", null));
|
||||
inventory.setItem(3, new PlotItemStack(35, (short) 4, 3, "3/8", null));
|
||||
inventory.setItem(4, new PlotItemStack(35, (short) 5, 4, "4/8", null));
|
||||
inventory.setItem(5, new PlotItemStack(35, (short) 9, 5, "5/8", null));
|
||||
inventory.setItem(6, new PlotItemStack(35, (short) 11, 6, "6/8", null));
|
||||
inventory.setItem(7, new PlotItemStack(35, (short) 10, 7, "7/8", null));
|
||||
inventory.setItem(8, new PlotItemStack(35, (short) 2, 8, "8/8", null));
|
||||
inventory.openInventory();
|
||||
}
|
||||
};
|
||||
if (plot.settings.ratings == null) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
plot.settings.ratings = DBFunc.getRatings(plot);
|
||||
run.run();
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
run.run();
|
||||
return true;
|
||||
}
|
||||
if (args.length < 1) {
|
||||
sendMessage(player, C.RATING_NOT_VALID);
|
||||
return true;
|
||||
}
|
||||
final String arg = args[0];
|
||||
|
||||
if (arg.equalsIgnoreCase("next")) {
|
||||
|
||||
}
|
||||
final int rating;
|
||||
if (StringUtils.isNumeric(arg) && arg.length() < 3 && arg.length() > 0) {
|
||||
rating = Integer.parseInt(arg);
|
||||
if (rating > 10) {
|
||||
sendMessage(player, C.RATING_NOT_VALID);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
sendMessage(player, C.RATING_NOT_VALID);
|
||||
return false;
|
||||
}
|
||||
final UUID uuid = player.getUUID();
|
||||
final Runnable run = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (plot.settings.ratings.containsKey(uuid)) {
|
||||
sendMessage(player, C.RATING_ALREADY_EXISTS, plot.getId().toString());
|
||||
return;
|
||||
}
|
||||
plot.settings.ratings.put(uuid, rating);
|
||||
DBFunc.setRating(plot, uuid, rating);
|
||||
sendMessage(player, C.RATING_APPLIED, plot.getId().toString());
|
||||
}
|
||||
};
|
||||
if (plot.settings.ratings == null) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
plot.settings.ratings = DBFunc.getRatings(plot);
|
||||
run.run();
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
run.run();
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.generator.HybridPlotManager;
|
||||
import com.intellectualcrafters.plot.generator.HybridUtils;
|
||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||
import com.intellectualcrafters.plot.object.PlotManager;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
|
||||
public class RegenAllRoads extends SubCommand {
|
||||
public RegenAllRoads() {
|
||||
super(Command.REGENALLROADS, "Regenerate all roads in the map using the set road schematic", "rgar", CommandCategory.DEBUG, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer player, final String... args) {
|
||||
if (player != null) {
|
||||
sendMessage(player, C.NOT_CONSOLE);
|
||||
return false;
|
||||
}
|
||||
if (args.length < 1) {
|
||||
sendMessage(player, C.NEED_PLOT_WORLD);
|
||||
return false;
|
||||
}
|
||||
int height = 0;
|
||||
if (args.length == 2) {
|
||||
try {
|
||||
height = Integer.parseInt(args[1]);
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
sendMessage(player, C.NOT_VALID_NUMBER, "(0, 256)");
|
||||
sendMessage(player, C.COMMAND_SYNTAX, "/plot regenallroads <world> [height]");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
final String name = args[0];
|
||||
final PlotManager manager = PS.get().getPlotManager(name);
|
||||
if ((manager == null) || !(manager instanceof HybridPlotManager)) {
|
||||
sendMessage(player, C.NOT_VALID_PLOT_WORLD);
|
||||
return false;
|
||||
}
|
||||
final List<ChunkLoc> chunks = ChunkManager.manager.getChunkChunks(name);
|
||||
PS.log("&cIf no schematic is set, the following will not do anything");
|
||||
PS.log("&7 - To set a schematic, stand in a plot and use &c/plot createroadschematic");
|
||||
PS.log("&6Potential chunks to update: &7" + (chunks.size() * 1024));
|
||||
PS.log("&6Estimated time: &7" + (chunks.size()) + " seconds");
|
||||
final boolean result = HybridUtils.manager.scheduleRoadUpdate(name, height);
|
||||
if (!result) {
|
||||
PS.log("&cCannot schedule mass schematic update! (Is one already in progress?)");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
|
||||
public class Reload extends SubCommand {
|
||||
public Reload() {
|
||||
super("reload", "plots.admin.command.reload", "Reload configurations", "reload", CommandCategory.INFO, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
try {
|
||||
// The following won't affect world generation, as that has to be
|
||||
// loaded during startup unfortunately.
|
||||
PS.get().config.load(PS.get().configFile);
|
||||
PS.get().setupConfig();
|
||||
C.load(PS.get().translationFile);
|
||||
for (final String pw : PS.get().getPlotWorlds()) {
|
||||
final PlotWorld plotworld = PS.get().getPlotWorld(pw);
|
||||
plotworld.loadDefaultConfiguration(PS.get().config.getConfigurationSection("worlds." + pw));
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.RELOADED_CONFIGS);
|
||||
} catch (final Exception e) {
|
||||
MainUtil.sendMessage(plr, C.RELOAD_FAILED);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
123
src/main/java/com/intellectualcrafters/plot/commands/Remove.java
Normal file
123
src/main/java/com/intellectualcrafters/plot/commands/Remove.java
Normal file
@ -0,0 +1,123 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
public class Remove extends SubCommand {
|
||||
public Remove() {
|
||||
super(Command.REMOVE, "Remove a player from a plot", "remove <player>", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (args.length != 1) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot remove <player>");
|
||||
return true;
|
||||
}
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||
}
|
||||
if ((plot == null) || !plot.hasOwner()) {
|
||||
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
|
||||
return false;
|
||||
}
|
||||
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.remove")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||
return true;
|
||||
}
|
||||
int count = 0;
|
||||
if (args[0].equals("unknown")) {
|
||||
ArrayList<UUID> toRemove = new ArrayList<>();
|
||||
HashSet<UUID> all = new HashSet<>();
|
||||
all.addAll(plot.members);
|
||||
all.addAll(plot.trusted);
|
||||
all.addAll(plot.denied);
|
||||
for (UUID uuid : all) {
|
||||
if (UUIDHandler.getName(uuid) == null) {
|
||||
toRemove.add(uuid);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
for (UUID uuid : toRemove) {
|
||||
plot.removeDenied(uuid);
|
||||
plot.removeTrusted(uuid);
|
||||
plot.removeMember(uuid);
|
||||
}
|
||||
}
|
||||
else if (args[0].equals("*")){
|
||||
ArrayList<UUID> toRemove = new ArrayList<>();
|
||||
HashSet<UUID> all = new HashSet<>();
|
||||
all.addAll(plot.members);
|
||||
all.addAll(plot.trusted);
|
||||
all.addAll(plot.denied);
|
||||
for (UUID uuid : all) {
|
||||
toRemove.add(uuid);
|
||||
count++;
|
||||
}
|
||||
for (UUID uuid : toRemove) {
|
||||
plot.removeDenied(uuid);
|
||||
plot.removeTrusted(uuid);
|
||||
plot.removeMember(uuid);
|
||||
}
|
||||
}
|
||||
else {
|
||||
UUID uuid = UUIDHandler.getUUID(args[0]);
|
||||
if (uuid != null) {
|
||||
if (plot.trusted.contains(uuid)) {
|
||||
if (plot.removeTrusted(uuid)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
else if (plot.members.contains(uuid)) {
|
||||
if (plot.removeMember(uuid)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
else if (plot.denied.contains(uuid)) {
|
||||
if (plot.removeDenied(uuid)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count == 0) {
|
||||
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
MainUtil.sendMessage(plr, C.REMOVED_PLAYERS, count + "");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,297 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.SchematicHandler;
|
||||
import com.intellectualcrafters.plot.util.SchematicHandler.DataCollection;
|
||||
import com.intellectualcrafters.plot.util.SchematicHandler.Dimension;
|
||||
import com.intellectualcrafters.plot.util.SchematicHandler.Schematic;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
|
||||
|
||||
public class SchematicCmd extends SubCommand {
|
||||
private int counter = 0;
|
||||
private boolean running = false;
|
||||
private int task;
|
||||
|
||||
public SchematicCmd() {
|
||||
super("schematic", "plots.schematic", "Schematic Command", "schematic {arg}", "sch", CommandCategory.ACTIONS, false);
|
||||
// TODO command to fetch schematic from worldedit directory
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (args.length < 1) {
|
||||
sendMessage(plr, C.SCHEMATIC_MISSING_ARG);
|
||||
return true;
|
||||
}
|
||||
final String arg = args[0].toLowerCase();
|
||||
final String file;
|
||||
final Schematic schematic;
|
||||
switch (arg) {
|
||||
case "paste": {
|
||||
if (plr == null) {
|
||||
PS.log(C.IS_CONSOLE.s());
|
||||
return false;
|
||||
}
|
||||
if (!Permissions.hasPermission(plr, "plots.schematic.paste")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.schematic.paste");
|
||||
return false;
|
||||
}
|
||||
if (args.length < 2) {
|
||||
sendMessage(plr, C.SCHEMATIC_MISSING_ARG);
|
||||
break;
|
||||
}
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
sendMessage(plr, C.NOT_IN_PLOT);
|
||||
return false;
|
||||
}
|
||||
if (this.running) {
|
||||
MainUtil.sendMessage(plr, "&cTask is already running.");
|
||||
return false;
|
||||
}
|
||||
final String file2 = args[1];
|
||||
this.running = true;
|
||||
this.counter = 0;
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
final Schematic schematic = SchematicHandler.manager.getSchematic(file2);
|
||||
if (schematic == null) {
|
||||
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent or not in gzip format");
|
||||
SchematicCmd.this.running = false;
|
||||
return;
|
||||
}
|
||||
final int x;
|
||||
final int z;
|
||||
final Plot plot2 = MainUtil.getPlot(loc);
|
||||
final Dimension dem = schematic.getSchematicDimension();
|
||||
final Location bot = MainUtil.getPlotBottomLoc(loc.getWorld(), plot2.id).add(1, 0, 1);
|
||||
final int length2 = MainUtil.getPlotWidth(loc.getWorld(), plot2.id);
|
||||
if ((dem.getX() > length2) || (dem.getZ() > length2)) {
|
||||
sendMessage(plr, C.SCHEMATIC_INVALID, String.format("Wrong size (x: %s, z: %d) vs %d ", dem.getX(), dem.getZ(), length2));
|
||||
SchematicCmd.this.running = false;
|
||||
return;
|
||||
}
|
||||
if ((dem.getX() != length2) || (dem.getZ() != length2)) {
|
||||
final Location loc = plr.getLocation();
|
||||
x = Math.min(length2 - dem.getX(), loc.getX() - bot.getX());
|
||||
z = Math.min(length2 - dem.getZ(), loc.getZ() - bot.getZ());
|
||||
} else {
|
||||
x = 0;
|
||||
z = 0;
|
||||
}
|
||||
final DataCollection[] b = schematic.getBlockCollection();
|
||||
final int sy = BlockManager.manager.getHeighestBlock(bot);
|
||||
final int WIDTH = schematic.getSchematicDimension().getX();
|
||||
final int LENGTH = schematic.getSchematicDimension().getZ();
|
||||
final Location l1;
|
||||
if (!(schematic.getSchematicDimension().getY() == BukkitUtil.getMaxHeight(loc.getWorld()))) {
|
||||
l1 = bot.add(0, sy - 1, 0);
|
||||
}
|
||||
else {
|
||||
l1 = bot;
|
||||
}
|
||||
|
||||
final int blen = b.length - 1;
|
||||
SchematicCmd.this.task = TaskManager.runTaskRepeat(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
boolean result = false;
|
||||
while (!result) {
|
||||
final int start = SchematicCmd.this.counter * 5000;
|
||||
if (start > blen) {
|
||||
SchematicHandler.manager.pasteStates(schematic, plot, 0, 0);
|
||||
sendMessage(plr, C.SCHEMATIC_PASTE_SUCCESS);
|
||||
SchematicCmd.this.running = false;
|
||||
PS.get().TASK.cancelTask(SchematicCmd.this.task);
|
||||
return;
|
||||
}
|
||||
final int end = Math.min(start + 5000, blen);
|
||||
result = SchematicHandler.manager.pastePart(loc.getWorld(), b, l1, x, z, start, end, WIDTH, LENGTH);
|
||||
SchematicCmd.this.counter++;
|
||||
}
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
SchematicCmd.this.running = false;
|
||||
MainUtil.sendMessage(plr, "&cAn error occured, see console for more information");
|
||||
}
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
case "test": {
|
||||
if (plr == null) {
|
||||
PS.log(C.IS_CONSOLE.s());
|
||||
return false;
|
||||
}
|
||||
if (!Permissions.hasPermission(plr, "plots.schematic.test")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.schematic.test");
|
||||
return false;
|
||||
}
|
||||
if (args.length < 2) {
|
||||
sendMessage(plr, C.SCHEMATIC_MISSING_ARG);
|
||||
return false;
|
||||
}
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
sendMessage(plr, C.NOT_IN_PLOT);
|
||||
return false;
|
||||
}
|
||||
file = args[1];
|
||||
schematic = SchematicHandler.manager.getSchematic(file);
|
||||
if (schematic == null) {
|
||||
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent");
|
||||
return false;
|
||||
}
|
||||
final int l1 = schematic.getSchematicDimension().getX();
|
||||
final int l2 = schematic.getSchematicDimension().getZ();
|
||||
final int length = MainUtil.getPlotWidth(loc.getWorld(), plot.id);
|
||||
if ((l1 < length) || (l2 < length)) {
|
||||
sendMessage(plr, C.SCHEMATIC_INVALID, String.format("Wrong size (x: %s, z: %d) vs %d ", l1, l2, length));
|
||||
break;
|
||||
}
|
||||
sendMessage(plr, C.SCHEMATIC_VALID);
|
||||
break;
|
||||
}
|
||||
case "saveall":
|
||||
case "exportall": {
|
||||
if (plr != null) {
|
||||
MainUtil.sendMessage(plr, C.NOT_CONSOLE);
|
||||
return false;
|
||||
}
|
||||
if (args.length != 2) {
|
||||
MainUtil.sendMessage(null, "&cNeed world arg. Use &7/plots sch exportall <world>");
|
||||
return false;
|
||||
}
|
||||
final HashMap<PlotId, Plot> plotmap = PS.get().getPlots(args[1]);
|
||||
if ((plotmap == null) || (plotmap.size() == 0)) {
|
||||
MainUtil.sendMessage(plr, "&cInvalid world. Use &7/plots sch exportall <world>");
|
||||
return false;
|
||||
}
|
||||
Collection<Plot> plots = plotmap.values();
|
||||
boolean result = SchematicHandler.manager.exportAll(plots, null, null, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.sendMessage(plr, "&aFinished mass export");
|
||||
}
|
||||
});
|
||||
if (!result) {
|
||||
MainUtil.sendMessage(plr, "&cTask is already running.");
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
PS.log("&3PlotSquared&8->&3Schemaitc&8: &7Mass export has started. This may take a while.");
|
||||
PS.log("&3PlotSquared&8->&3Schemaitc&8: &7Found &c" + plotmap.size() + "&7 plots...");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "export":
|
||||
case "save": {
|
||||
if (!Permissions.hasPermission(plr, "plots.schematic.save")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.schematic.save");
|
||||
return false;
|
||||
}
|
||||
if (this.running) {
|
||||
MainUtil.sendMessage(plr, "&cTask is already running.");
|
||||
return false;
|
||||
}
|
||||
final String world;
|
||||
final Plot p2;
|
||||
if (plr != null) {
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||
}
|
||||
if (!plot.isAdded(plr.getUUID())) {
|
||||
sendMessage(plr, C.NO_PLOT_PERMS);
|
||||
return false;
|
||||
}
|
||||
p2 = plot;
|
||||
world = loc.getWorld();
|
||||
} else {
|
||||
if (args.length == 3) {
|
||||
try {
|
||||
world = args[1];
|
||||
final String[] split = args[2].split(";");
|
||||
final PlotId i = new PlotId(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
|
||||
if ((PS.get().getPlots(world) == null) || (PS.get().getPlots(world).get(i) == null)) {
|
||||
MainUtil.sendMessage(null, "&cInvalid world or id. Use &7/plots sch save <world> <id>");
|
||||
return false;
|
||||
}
|
||||
p2 = PS.get().getPlots(world).get(i);
|
||||
} catch (final Exception e) {
|
||||
MainUtil.sendMessage(null, "&cInvalid world or id. Use &7/plots sch save <world> <id>");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
MainUtil.sendMessage(null, "&cInvalid world or id. Use &7/plots sch save <world> <id>");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Collection<Plot> plots = new ArrayList<Plot>();
|
||||
plots.add(p2);
|
||||
boolean result = SchematicHandler.manager.exportAll(plots, null, null, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.sendMessage(plr, "&aFinished export");
|
||||
SchematicCmd.this.running = false;
|
||||
}
|
||||
});
|
||||
if (!result) {
|
||||
MainUtil.sendMessage(plr, "&cTask is already running.");
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
MainUtil.sendMessage(plr, "&7Starting export...");
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
sendMessage(plr, C.SCHEMATIC_MISSING_ARG);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
335
src/main/java/com/intellectualcrafters/plot/commands/Set.java
Normal file
335
src/main/java/com/intellectualcrafters/plot/commands/Set.java
Normal file
@ -0,0 +1,335 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Configuration;
|
||||
import com.intellectualcrafters.plot.flag.AbstractFlag;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.listeners.APlotListener;
|
||||
import com.intellectualcrafters.plot.object.*;
|
||||
import com.intellectualcrafters.plot.util.*;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class Set extends SubCommand {
|
||||
public final static String[] values = new String[] { "biome", "alias", "home", "flag" };
|
||||
public final static String[] aliases = new String[] { "b", "w", "wf", "f", "a", "h", "fl" };
|
||||
|
||||
public Set() {
|
||||
super(Command.SET, "Set a plot value", "set {arg} {value...}", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||
}
|
||||
if (!plot.hasOwner()) {
|
||||
sendMessage(plr, C.PLOT_NOT_CLAIMED);
|
||||
return false;
|
||||
}
|
||||
if (!plot.isAdded(plr.getUUID())) {
|
||||
if (!Permissions.hasPermission(plr, "plots.set.other")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.set.other");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (args.length < 1) {
|
||||
PlotManager manager = PS.get().getPlotManager(loc.getWorld());
|
||||
ArrayList<String> newValues = new ArrayList<String>();
|
||||
newValues.addAll(Arrays.asList(values));
|
||||
newValues.addAll(Arrays.asList(manager.getPlotComponents(PS.get().getPlotWorld(loc.getWorld()), plot.id)));
|
||||
MainUtil.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + getArgumentList(newValues));
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < aliases.length; i++) {
|
||||
if (aliases[i].equalsIgnoreCase(args[0])) {
|
||||
args[0] = values[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("flag")) {
|
||||
if (args.length < 2) {
|
||||
final String message = StringMan.replaceFromMap("$2" + (StringUtils.join(FlagManager.getFlags(plr), "$1, $2")), C.replacements);
|
||||
// final String message = StringUtils.join(FlagManager.getFlags(plr), "&c, &6");
|
||||
MainUtil.sendMessage(plr, C.NEED_KEY.s().replaceAll("%values%", message));
|
||||
return false;
|
||||
}
|
||||
AbstractFlag af;
|
||||
try {
|
||||
af = FlagManager.getFlag(args[1].toLowerCase());
|
||||
} catch (final Exception e) {
|
||||
af = new AbstractFlag(args[1].toLowerCase());
|
||||
}
|
||||
if (!FlagManager.getFlags().contains(af) || FlagManager.isReserved(af.getKey())) {
|
||||
MainUtil.sendMessage(plr, C.NOT_VALID_FLAG);
|
||||
return false;
|
||||
}
|
||||
if (!Permissions.hasPermission(plr, "plots.set.flag." + args[1].toLowerCase())) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase());
|
||||
return false;
|
||||
}
|
||||
if (args.length == 2) {
|
||||
if (FlagManager.getPlotFlagAbs(plot, args[1].toLowerCase()) == null) {
|
||||
MainUtil.sendMessage(plr, C.FLAG_NOT_IN_PLOT);
|
||||
return false;
|
||||
}
|
||||
final boolean result = FlagManager.removePlotFlag(plot, args[1].toLowerCase());
|
||||
if (!result) {
|
||||
MainUtil.sendMessage(plr, C.FLAG_NOT_REMOVED);
|
||||
return false;
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.FLAG_REMOVED);
|
||||
APlotListener.manager.plotEntry(plr, plot);
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
final String value = StringUtils.join(Arrays.copyOfRange(args, 2, args.length), " ");
|
||||
final Object parsed_value = af.parseValueRaw(value);
|
||||
if (parsed_value == null) {
|
||||
MainUtil.sendMessage(plr, af.getValueDesc());
|
||||
return false;
|
||||
}
|
||||
final Flag flag = new Flag(FlagManager.getFlag(args[1].toLowerCase(), true), parsed_value);
|
||||
final boolean result = FlagManager.addPlotFlag(plot, flag);
|
||||
if (!result) {
|
||||
MainUtil.sendMessage(plr, C.FLAG_NOT_ADDED);
|
||||
return false;
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.FLAG_ADDED);
|
||||
APlotListener.manager.plotEntry(plr, plot);
|
||||
return true;
|
||||
} catch (final Exception e) {
|
||||
MainUtil.sendMessage(plr, "&c" + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("home")) {
|
||||
if (!Permissions.hasPermission(plr, "plots.set.home")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.set.home");
|
||||
return false;
|
||||
}
|
||||
if (args.length > 1) {
|
||||
if (args[1].equalsIgnoreCase("none")) {
|
||||
plot.setHome(null);
|
||||
return true;
|
||||
}
|
||||
return MainUtil.sendMessage(plr, C.HOME_ARGUMENT);
|
||||
}
|
||||
//set to current location
|
||||
final String world = plr.getLocation().getWorld();
|
||||
final Location base = MainUtil.getPlotBottomLoc(world, plot.id);
|
||||
base.setY(0);
|
||||
final Location relative = plr.getLocation().subtract(base.getX(), base.getY(), base.getZ());
|
||||
final BlockLoc blockloc = new BlockLoc(relative.getX(), relative.getY(), relative.getZ(), relative.getYaw(), relative.getPitch());
|
||||
plot.setHome(blockloc);
|
||||
return MainUtil.sendMessage(plr, C.POSITION_SET);
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("alias")) {
|
||||
if (!Permissions.hasPermission(plr, "plots.set.alias")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.set.alias");
|
||||
return false;
|
||||
}
|
||||
if (args.length < 2) {
|
||||
MainUtil.sendMessage(plr, C.MISSING_ALIAS);
|
||||
return false;
|
||||
}
|
||||
final String alias = args[1];
|
||||
if (alias.length() >= 50) {
|
||||
MainUtil.sendMessage(plr, C.ALIAS_TOO_LONG);
|
||||
return false;
|
||||
}
|
||||
for (final Plot p : PS.get().getPlots(plr.getLocation().getWorld()).values()) {
|
||||
if (p.settings.getAlias().equalsIgnoreCase(alias)) {
|
||||
MainUtil.sendMessage(plr, C.ALIAS_IS_TAKEN);
|
||||
return false;
|
||||
}
|
||||
if (UUIDHandler.nameExists(new StringWrapper(alias))) {
|
||||
MainUtil.sendMessage(plr, C.ALIAS_IS_TAKEN);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
plot.setAlias(alias);
|
||||
MainUtil.sendMessage(plr, C.ALIAS_SET_TO.s().replaceAll("%alias%", alias));
|
||||
return true;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("biome")) {
|
||||
if (!Permissions.hasPermission(plr, "plots.set.biome")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.set.biome");
|
||||
return false;
|
||||
}
|
||||
if (args.length < 2) {
|
||||
MainUtil.sendMessage(plr, C.NEED_BIOME);
|
||||
return true;
|
||||
}
|
||||
if (args[1].length() < 2) {
|
||||
sendMessage(plr, C.NAME_LITTLE, "Biome", args[1].length() + "", "2");
|
||||
return true;
|
||||
}
|
||||
final int biome = BlockManager.manager.getBiomeFromString(args[1]);
|
||||
/*
|
||||
* for (Biome b : Biome.values()) {
|
||||
* if (b.toString().equalsIgnoreCase(args[1])) {
|
||||
* biome = b;
|
||||
* break;
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
if (biome == -1) {
|
||||
MainUtil.sendMessage(plr, getBiomeList(BlockManager.manager.getBiomeList()));
|
||||
return true;
|
||||
}
|
||||
plot.setBiome(args[1].toUpperCase());
|
||||
MainUtil.sendMessage(plr, C.BIOME_SET_TO.s() + args[1].toLowerCase());
|
||||
return true;
|
||||
}
|
||||
// Get components
|
||||
final String world = plr.getLocation().getWorld();
|
||||
final PlotWorld plotworld = PS.get().getPlotWorld(world);
|
||||
final PlotManager manager = PS.get().getPlotManager(world);
|
||||
final String[] components = manager.getPlotComponents(plotworld, plot.id);
|
||||
|
||||
boolean allowUnsafe = DebugAllowUnsafe.unsafeAllowed.contains(plr.getUUID());
|
||||
|
||||
for (final String component : components) {
|
||||
if (component.equalsIgnoreCase(args[0])) {
|
||||
if (!Permissions.hasPermission(plr, "plots.set." + component)) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.set." + component);
|
||||
}
|
||||
PlotBlock[] blocks;
|
||||
try {
|
||||
if (args.length < 2) {
|
||||
MainUtil.sendMessage(plr, C.NEED_BLOCK);
|
||||
return true;
|
||||
}
|
||||
String[] split = args[1].split(",");
|
||||
blocks = Configuration.BLOCKLIST.parseString(args[1]);
|
||||
for (int i = 0; i < blocks.length; i++) {
|
||||
PlotBlock block = blocks[i];
|
||||
if (block == null) {
|
||||
MainUtil.sendMessage(plr, C.NOT_VALID_BLOCK, split[i]);
|
||||
String name;
|
||||
if (split[i].contains("%")) {
|
||||
name = split[i].split("%")[1];
|
||||
}
|
||||
else {
|
||||
name = split[i];
|
||||
}
|
||||
StringComparison<PlotBlock>.ComparisonResult match = BlockManager.manager.getClosestBlock(name);
|
||||
if (match != null) {
|
||||
name = BlockManager.manager.getClosestMatchingName(match.best);
|
||||
if (name != null) {
|
||||
MainUtil.sendMessage(plr, C.DID_YOU_MEAN, name.toLowerCase());
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else if (!allowUnsafe && !BlockManager.manager.isBlockSolid(block)) {
|
||||
MainUtil.sendMessage(plr, C.NOT_ALLOWED_BLOCK, block.toString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!allowUnsafe) {
|
||||
for (PlotBlock block : blocks) {
|
||||
if (!BlockManager.manager.isBlockSolid(block)) {
|
||||
MainUtil.sendMessage(plr, C.NOT_ALLOWED_BLOCK, block.toString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (final Exception e2) {
|
||||
MainUtil.sendMessage(plr, C.NOT_VALID_BLOCK, args[1]);
|
||||
return false;
|
||||
}
|
||||
if (MainUtil.runners.containsKey(plot)) {
|
||||
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
||||
return false;
|
||||
}
|
||||
MainUtil.runners.put(plot, 1);
|
||||
manager.setComponent(plotworld, plot.id, component, blocks);
|
||||
MainUtil.sendMessage(plr, C.GENERATING_COMPONENT);
|
||||
SetBlockQueue.addNotify(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.runners.remove(plot);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
{
|
||||
AbstractFlag af;
|
||||
try {
|
||||
af = new AbstractFlag(args[0].toLowerCase());
|
||||
} catch (final Exception e) {
|
||||
af = new AbstractFlag("");
|
||||
}
|
||||
if (FlagManager.getFlags().contains(af)) {
|
||||
final StringBuilder a = new StringBuilder();
|
||||
if (args.length > 1) {
|
||||
for (int x = 1; x < args.length; x++) {
|
||||
a.append(" ").append(args[x]);
|
||||
}
|
||||
}
|
||||
MainCommand.onCommand(plr, world, ("plot set flag " + args[0] + a.toString()).split(" "));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
ArrayList<String> newValues = new ArrayList<String>();
|
||||
newValues.addAll(Arrays.asList(values));
|
||||
newValues.addAll(Arrays.asList(manager.getPlotComponents(PS.get().getPlotWorld(loc.getWorld()), plot.id)));
|
||||
MainUtil.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + getArgumentList(newValues));
|
||||
return false;
|
||||
}
|
||||
|
||||
private String getString(final String s) {
|
||||
return MainUtil.colorise('&', C.BLOCK_LIST_ITEM.s().replaceAll("%mat%", s));
|
||||
}
|
||||
|
||||
private String getArgumentList(final List<String> newValues) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
for (final String s : newValues) {
|
||||
builder.append(getString(s));
|
||||
}
|
||||
return builder.toString().substring(1, builder.toString().length() - 1);
|
||||
}
|
||||
|
||||
private String getBiomeList(final String[] biomes) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
builder.append(MainUtil.colorise('&', C.NEED_BIOME.s()));
|
||||
for (final String b : biomes) {
|
||||
builder.append(getString(b));
|
||||
}
|
||||
return builder.toString().substring(1, builder.toString().length() - 1);
|
||||
}
|
||||
}
|
@ -0,0 +1,113 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
public class SetOwner extends SubCommand {
|
||||
public SetOwner() {
|
||||
super("setowner", "plots.set.owner", "Set the plot owner", "setowner <player>", "so", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
/*
|
||||
* private UUID getUUID(String string) { OfflinePlayer player =
|
||||
* Bukkit.getOfflinePlayer(string); return ((player != null) &&
|
||||
* player.hasPlayedBefore()) ? UUIDHandler.getUUID(player) : null; }
|
||||
*/
|
||||
private UUID getUUID(final String string) {
|
||||
return UUIDHandler.getUUID(string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if ((plot == null) || (plot.owner == null)) {
|
||||
MainUtil.sendMessage(plr, C.NOT_IN_PLOT);
|
||||
return false;
|
||||
}
|
||||
if (args.length < 1) {
|
||||
MainUtil.sendMessage(plr, C.NEED_USER);
|
||||
return false;
|
||||
}
|
||||
|
||||
final PlotId bot = MainUtil.getBottomPlot(plot).id;
|
||||
final PlotId top = MainUtil.getTopPlot(plot).id;
|
||||
final ArrayList<PlotId> plots = MainUtil.getPlotSelectionIds(bot, top);
|
||||
|
||||
PlotPlayer other = UUIDHandler.getPlayer(args[0]);
|
||||
if (other == null) {
|
||||
if (!Permissions.hasPermission(plr, "plots.admin.command.setowner")) {
|
||||
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!Permissions.hasPermission(plr, "plots.admin.command.setowner")) {
|
||||
int size = plots.size();
|
||||
final int currentPlots = (Settings.GLOBAL_LIMIT ? MainUtil.getPlayerPlotCount(other) : MainUtil.getPlayerPlotCount(loc.getWorld(), other)) + size;
|
||||
if (currentPlots > MainUtil.getAllowedPlots(other)) {
|
||||
sendMessage(plr, C.CANT_TRANSFER_MORE_PLOTS);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!plot.isOwner(plr.getUUID())) {
|
||||
if (!Permissions.hasPermission(plr, "plots.admin.command.setowner")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.admin.command.setowner");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
final String world = loc.getWorld();
|
||||
for (final PlotId id : plots) {
|
||||
final Plot current = PS.get().getPlots(world).get(id);
|
||||
final UUID uuid = getUUID(args[0]);
|
||||
if (uuid == null) {
|
||||
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
|
||||
return false;
|
||||
}
|
||||
current.owner = uuid;
|
||||
PS.get().updatePlot(current);
|
||||
DBFunc.setOwner(current, current.owner);
|
||||
}
|
||||
MainUtil.setSign(args[0], plot);
|
||||
MainUtil.sendMessage(plr, C.SET_OWNER);
|
||||
if (other != null) {
|
||||
MainUtil.sendMessage(other, C.NOW_OWNER, plot.world + ";" + plot.id);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
255
src/main/java/com/intellectualcrafters/plot/commands/Setup.java
Normal file
255
src/main/java/com/intellectualcrafters/plot/commands/Setup.java
Normal file
@ -0,0 +1,255 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.ConfigurationNode;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.generator.HybridGen;
|
||||
import com.intellectualcrafters.plot.object.PlotGenerator;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.SetupObject;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.SetupUtils;
|
||||
|
||||
public class Setup extends SubCommand {
|
||||
public Setup() {
|
||||
super("setup", "plots.admin.command.setup", "Plotworld setup command", "setup", "create", CommandCategory.ACTIONS, false);
|
||||
}
|
||||
|
||||
public void displayGenerators(PlotPlayer plr) {
|
||||
StringBuffer message = new StringBuffer();
|
||||
message.append("&6What generator do you want?");
|
||||
for (Entry<String, ChunkGenerator> entry : SetupUtils.generators.entrySet()) {
|
||||
if (entry.getKey().equals("PlotSquared")) {
|
||||
message.append("\n&8 - &2" + entry.getKey() + " (Default Generator)");
|
||||
}
|
||||
else if (entry.getValue() instanceof HybridGen) {
|
||||
message.append("\n&8 - &7" + entry.getKey() + " (Hybrid Generator)");
|
||||
}
|
||||
else if (entry.getValue() instanceof PlotGenerator) {
|
||||
message.append("\n&8 - &7" + entry.getKey() + " (Plot Generator)");
|
||||
}
|
||||
else {
|
||||
message.append("\n&8 - &7" + entry.getKey() + " (Unknown structure)");
|
||||
}
|
||||
}
|
||||
MainUtil.sendMessage(plr, message.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
// going through setup
|
||||
String name;
|
||||
if (plr == null) {
|
||||
name = "*";
|
||||
}
|
||||
else {
|
||||
name = plr.getName();
|
||||
}
|
||||
if (!SetupUtils.setupMap.containsKey(name)) {
|
||||
final SetupObject object = new SetupObject();
|
||||
SetupUtils.setupMap.put(name, object);
|
||||
SetupUtils.manager.updateGenerators();
|
||||
sendMessage(plr, C.SETUP_INIT);
|
||||
displayGenerators(plr);
|
||||
return false;
|
||||
}
|
||||
if (args.length == 1) {
|
||||
if (args[0].equalsIgnoreCase("cancel")) {
|
||||
SetupUtils.setupMap.remove(name);
|
||||
MainUtil.sendMessage(plr, "&aCancelled setup");
|
||||
return false;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("back")) {
|
||||
final SetupObject object = SetupUtils.setupMap.get(name);
|
||||
if (object.setup_index > 0) {
|
||||
object.setup_index--;
|
||||
final ConfigurationNode node = object.step[object.setup_index];
|
||||
sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", node.getDescription(), node.getType().getType(), node.getDefaultValue() + "");
|
||||
return false;
|
||||
} else if (object.current > 0) {
|
||||
object.current--;
|
||||
}
|
||||
}
|
||||
}
|
||||
final SetupObject object = SetupUtils.setupMap.get(name);
|
||||
final int index = object.current;
|
||||
switch (index) {
|
||||
case 0: { // choose generator
|
||||
if ((args.length != 1) || !SetupUtils.generators.containsKey(args[0])) {
|
||||
final String prefix = "\n&8 - &7";
|
||||
MainUtil.sendMessage(plr, "&cYou must choose a generator!" + prefix + StringUtils.join(SetupUtils.generators.keySet(), prefix).replaceAll("PlotSquared", "&2PlotSquared"));
|
||||
sendMessage(plr, C.SETUP_INIT);
|
||||
return false;
|
||||
}
|
||||
object.setupGenerator = args[0];
|
||||
object.current++;
|
||||
final String partial = Settings.ENABLE_CLUSTERS ? "\n&8 - &7PARTIAL&8 - &7Vanilla with clusters of plots" : "";
|
||||
MainUtil.sendMessage(plr, "&6What world type do you want?" + "\n&8 - &2DEFAULT&8 - &7Standard plot generation" + "\n&8 - &7AUGMENTED&8 - &7Plot generation with terrain" + partial);
|
||||
break;
|
||||
}
|
||||
case 1: { // choose world type
|
||||
List<String> allTypes = Arrays.asList(new String[] { "default", "augmented", "partial"});
|
||||
List<String> allDesc = Arrays.asList(new String[] { "Standard plot generation", "Plot generation with vanilla terrain", "Vanilla with clusters of plots"});
|
||||
ArrayList<String> types = new ArrayList<>();
|
||||
if (SetupUtils.generators.get(object.setupGenerator) instanceof PlotGenerator) {
|
||||
types.add("default");
|
||||
}
|
||||
types.add("augmented");
|
||||
if (Settings.ENABLE_CLUSTERS) {
|
||||
types.add("partial");
|
||||
}
|
||||
if ((args.length != 1) || !types.contains(args[0].toLowerCase())) {
|
||||
MainUtil.sendMessage(plr, "&cYou must choose a world type!");
|
||||
for (String type : types) {
|
||||
int i = allTypes.indexOf(type);
|
||||
if (type.equals("default")) {
|
||||
MainUtil.sendMessage(plr, "&8 - &2" + type + " &8-&7 " + allDesc.get(i));
|
||||
}
|
||||
else {
|
||||
MainUtil.sendMessage(plr, "&8 - &7" + type + " &8-&7 " + allDesc.get(i));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
object.type = allTypes.indexOf(args[0].toLowerCase());
|
||||
ChunkGenerator gen = SetupUtils.generators.get(object.setupGenerator);
|
||||
if (object.type == 0) {
|
||||
object.current++;
|
||||
if (object.step == null) {
|
||||
object.plotManager = object.setupGenerator;
|
||||
object.step = ((PlotGenerator) SetupUtils.generators.get(object.plotManager)).getNewPlotWorld(null).getSettingNodes();
|
||||
((PlotGenerator) SetupUtils.generators.get(object.plotManager)).processSetup(object);
|
||||
}
|
||||
if (object.step.length == 0) {
|
||||
object.current = 4;
|
||||
MainUtil.sendMessage(plr, "&6What do you want your world to be called?");
|
||||
object.setup_index = 0;
|
||||
return true;
|
||||
}
|
||||
final ConfigurationNode step = object.step[object.setup_index];
|
||||
sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + "");
|
||||
} else {
|
||||
if (gen instanceof PlotGenerator) {
|
||||
object.plotManager = object.setupGenerator;
|
||||
object.setupGenerator = null;
|
||||
object.step = ((PlotGenerator) SetupUtils.generators.get(object.plotManager)).getNewPlotWorld(null).getSettingNodes();
|
||||
((PlotGenerator) SetupUtils.generators.get(object.plotManager)).processSetup(object);
|
||||
}
|
||||
else {
|
||||
object.plotManager = "PlotSquared";
|
||||
MainUtil.sendMessage(plr, "&c[WARNING] The specified generator does not identify as PlotGenerator");
|
||||
MainUtil.sendMessage(plr, "&7 - You may need to manually configure the other plugin");
|
||||
object.step = ((PlotGenerator) SetupUtils.generators.get(object.plotManager)).getNewPlotWorld(null).getSettingNodes();
|
||||
}
|
||||
MainUtil.sendMessage(plr, "&6What terrain would you like in plots?" + "\n&8 - &2NONE&8 - &7No terrain at all" + "\n&8 - &7ORE&8 - &7Just some ore veins and trees" + "\n&8 - &7ROAD&8 - &7Terrain seperated by roads" + "\n&8 - &7ALL&8 - &7Entirely vanilla generation");
|
||||
}
|
||||
object.current++;
|
||||
break;
|
||||
}
|
||||
case 2: { // Choose terrain
|
||||
final List<String> terrain = Arrays.asList(new String[] { "none", "ore", "road", "all" });
|
||||
if ((args.length != 1) || !terrain.contains(args[0].toLowerCase())) {
|
||||
MainUtil.sendMessage(plr, "&cYou must choose the terrain!" + "\n&8 - &2NONE&8 - &7No terrain at all" + "\n&8 - &7ORE&8 - &7Just some ore veins and trees" + "\n&8 - &7ROAD&8 - &7Terrain seperated by roads" + "\n&8 - &7ALL&8 - &7Entirely vanilla generation");
|
||||
return false;
|
||||
}
|
||||
object.terrain = terrain.indexOf(args[0].toLowerCase());
|
||||
object.current++;
|
||||
if (object.step == null) {
|
||||
object.step = ((PlotGenerator) SetupUtils.generators.get(object.plotManager)).getNewPlotWorld(null).getSettingNodes();
|
||||
}
|
||||
final ConfigurationNode step = object.step[object.setup_index];
|
||||
sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + "");
|
||||
break;
|
||||
}
|
||||
case 3: { // world setup
|
||||
if (object.setup_index == object.step.length) {
|
||||
MainUtil.sendMessage(plr, "&6What do you want your world to be called?");
|
||||
object.setup_index = 0;
|
||||
object.current++;
|
||||
return true;
|
||||
}
|
||||
ConfigurationNode step = object.step[object.setup_index];
|
||||
if (args.length < 1) {
|
||||
sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + "");
|
||||
return false;
|
||||
}
|
||||
final boolean valid = step.isValid(args[0]);
|
||||
if (valid) {
|
||||
sendMessage(plr, C.SETUP_VALID_ARG, step.getConstant(), args[0]);
|
||||
step.setValue(args[0]);
|
||||
object.setup_index++;
|
||||
if (object.setup_index == object.step.length) {
|
||||
execute(plr, args);
|
||||
return false;
|
||||
}
|
||||
step = object.step[object.setup_index];
|
||||
sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + "");
|
||||
return false;
|
||||
} else {
|
||||
sendMessage(plr, C.SETUP_INVALID_ARG, args[0], step.getConstant());
|
||||
sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + "");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
case 4: {
|
||||
if (args.length != 1) {
|
||||
MainUtil.sendMessage(plr, "&cYou need to choose a world name!");
|
||||
return false;
|
||||
}
|
||||
if (BlockManager.manager.isWorld(args[0])) {
|
||||
MainUtil.sendMessage(plr, "&cThat world name is already taken!");
|
||||
}
|
||||
object.world = args[0];
|
||||
SetupUtils.setupMap.remove(name);
|
||||
final String world;
|
||||
if (object.setupManager == null) {
|
||||
world = SetupUtils.manager.setupWorld(object);
|
||||
}
|
||||
else {
|
||||
world = object.setupManager.setupWorld(object);
|
||||
}
|
||||
try {
|
||||
if (plr != null) {
|
||||
plr.teleport(BlockManager.manager.getSpawn(world));
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
plr.sendMessage("&cAn error occured. See console for more information");
|
||||
e.printStackTrace();
|
||||
}
|
||||
sendMessage(plr, C.SETUP_FINISHED, object.world);
|
||||
SetupUtils.setupMap.remove(name);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,210 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
|
||||
/**
|
||||
* SubCommand class
|
||||
*
|
||||
* @author Citymonstret
|
||||
*/
|
||||
@SuppressWarnings({ "deprecation", "unused" })
|
||||
public abstract class SubCommand {
|
||||
/**
|
||||
* Command
|
||||
*/
|
||||
public final String cmd;
|
||||
/**
|
||||
* Permission node
|
||||
*/
|
||||
public final CommandPermission permission;
|
||||
/**
|
||||
* Simple description
|
||||
*/
|
||||
public final String description;
|
||||
/**
|
||||
* Aliases
|
||||
*/
|
||||
public final ArrayList<String> alias;
|
||||
/**
|
||||
* Command usage
|
||||
*/
|
||||
public final String usage;
|
||||
/**
|
||||
* The category
|
||||
*/
|
||||
public final CommandCategory category;
|
||||
/**
|
||||
* Is this a player-online command?
|
||||
*/
|
||||
public final boolean isPlayer;
|
||||
|
||||
/**
|
||||
* @param cmd Command /plot {cmd} <-- That!
|
||||
* @param permission Permission Node
|
||||
* @param description Simple description
|
||||
* @param usage Usage description: /plot command {args...}
|
||||
* @param alias Command alias
|
||||
* @param category CommandCategory. Pick whichever is closest to what you want.
|
||||
*/
|
||||
public SubCommand(final String cmd, final String permission, final String description, final String usage, final String alias, final CommandCategory category, final boolean isPlayer) {
|
||||
this.cmd = cmd;
|
||||
this.permission = new CommandPermission(permission);
|
||||
this.description = description;
|
||||
this.alias = new ArrayList<String>();
|
||||
this.alias.add(alias);
|
||||
this.usage = usage;
|
||||
this.category = category;
|
||||
this.isPlayer = isPlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cmd Command /plot {cmd} <-- That!
|
||||
* @param permission Permission Node
|
||||
* @param description Simple description
|
||||
* @param usage Usage description: /plot command {args...}
|
||||
* @param aliases Command aliases
|
||||
* @param category CommandCategory. Pick whichever is closest to what you want.
|
||||
*/
|
||||
public SubCommand(final String cmd, final String permission, final String description, final String usage, final CommandCategory category, final boolean isPlayer, final String... aliases) {
|
||||
this.cmd = cmd;
|
||||
this.permission = new CommandPermission(permission);
|
||||
this.description = description;
|
||||
this.alias = new ArrayList<String>();
|
||||
this.alias.addAll(Arrays.asList(aliases));
|
||||
this.usage = usage;
|
||||
this.category = category;
|
||||
this.isPlayer = isPlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param command Command /plot {cmd} <-- That!
|
||||
* @param description Simple description
|
||||
* @param usage Usage description: /plot command {args...}
|
||||
* @param category CommandCategory. Pick whichever closests to what you want.
|
||||
*/
|
||||
public SubCommand(final Command command, final String description, final String usage, final CommandCategory category, final boolean isPlayer) {
|
||||
this.cmd = command.getCommand();
|
||||
this.permission = command.getPermission();
|
||||
this.alias = new ArrayList<String>();
|
||||
this.alias.add(command.getAlias());
|
||||
this.description = description;
|
||||
this.usage = usage;
|
||||
this.category = category;
|
||||
this.isPlayer = isPlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute.
|
||||
*
|
||||
* @param plr executor
|
||||
* @param args arguments
|
||||
*
|
||||
* @return true on success, false on failure
|
||||
*/
|
||||
public abstract boolean execute(final PlotPlayer plr, final String... args);
|
||||
|
||||
/**
|
||||
* Execute the command as console
|
||||
*
|
||||
* @param args Arguments
|
||||
*/
|
||||
public void executeConsole(final String... args) {
|
||||
this.execute(null, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message
|
||||
*
|
||||
* @param plr Player who will receive the mssage
|
||||
* @param c Caption
|
||||
* @param args Arguments (%s's)
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.util.MainUtil#sendMessage(PlotPlayer, C, String...)
|
||||
*/
|
||||
public boolean sendMessage(final PlotPlayer plr, final C c, final String... args) {
|
||||
MainUtil.sendMessage(plr, c, args);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* CommandCategory
|
||||
*
|
||||
* @author Citymonstret
|
||||
* @author Empire92
|
||||
*/
|
||||
public enum CommandCategory {
|
||||
/**
|
||||
* Claiming Commands
|
||||
*
|
||||
* Such as: /plot claim
|
||||
*/
|
||||
CLAIMING("Claiming"),
|
||||
/**
|
||||
* Teleportation Commands
|
||||
*
|
||||
* Such as: /plot visit
|
||||
*/
|
||||
TELEPORT("Teleportation"),
|
||||
/**
|
||||
* Action Commands
|
||||
*
|
||||
* Such as: /plot clear
|
||||
*/
|
||||
ACTIONS("Actions"),
|
||||
/**
|
||||
* Information Commands
|
||||
*
|
||||
* Such as: /plot info
|
||||
*/
|
||||
INFO("Information"),
|
||||
/**
|
||||
* Debug Commands
|
||||
*
|
||||
* Such as: /plot debug
|
||||
*/
|
||||
DEBUG("Debug");
|
||||
/**
|
||||
* The category name (Readable)
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param name readable name
|
||||
*/
|
||||
CommandCategory(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
}
|
135
src/main/java/com/intellectualcrafters/plot/commands/Swap.java
Normal file
135
src/main/java/com/intellectualcrafters/plot/commands/Swap.java
Normal file
@ -0,0 +1,135 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotCluster;
|
||||
import com.intellectualcrafters.plot.object.PlotClusterId;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.ClusterManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
|
||||
/**
|
||||
* Created 2014-08-01 for PlotSquared
|
||||
*
|
||||
* @author Empire92
|
||||
*/
|
||||
public class Swap extends SubCommand {
|
||||
public Swap() {
|
||||
super(Command.SWAP, "Swap two plots", "switch", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
MainUtil.sendMessage(plr, "&cThis command has not been optimized for large selections yet. Please bug me if this becomes an issue.");
|
||||
if (args.length < 1) {
|
||||
MainUtil.sendMessage(plr, C.NEED_PLOT_ID);
|
||||
MainUtil.sendMessage(plr, C.SWAP_SYNTAX);
|
||||
return false;
|
||||
}
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||
}
|
||||
if (((plot == null) || !plot.hasOwner() || !plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.swap")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||
return false;
|
||||
}
|
||||
|
||||
Plot bot1 = MainUtil.getBottomPlot(plot);
|
||||
Plot top1 = MainUtil.getTopPlot(plot);
|
||||
|
||||
PlotId id2 = PlotId.fromString(args[0]);
|
||||
if (id2 == null) {
|
||||
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
||||
MainUtil.sendMessage(plr, C.SWAP_SYNTAX);
|
||||
return false;
|
||||
}
|
||||
final String world = loc.getWorld();
|
||||
Plot plot2 = MainUtil.getPlot(world, id2);
|
||||
PlotId id3 = new PlotId(id2.x + top1.id.x - bot1.id.x, id2.y + top1.id.y - bot1.id.y);
|
||||
Plot plot3 = MainUtil.getPlot(world, id3);
|
||||
|
||||
// Getting secon selection
|
||||
Plot bot2 = MainUtil.getBottomPlot(plot2);
|
||||
Plot top2 = MainUtil.getTopPlot(plot3);
|
||||
|
||||
// cancel swap if intersection
|
||||
PlotCluster cluster1 = new PlotCluster(world, bot1.id, top1.id, null);
|
||||
PlotClusterId cluster2id = new PlotClusterId(bot2.id, top2.id);
|
||||
if (ClusterManager.intersects(cluster1, cluster2id)) {
|
||||
MainUtil.sendMessage(plr, C.SWAP_OVERLAP);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check dimensions
|
||||
if (top1.id.x - bot1.id.x != top2.id.x - bot2.id.x || top1.id.y - bot1.id.y != top2.id.y - bot2.id.y ) {
|
||||
MainUtil.sendMessage(plr, C.SWAP_DIMENSIONS, "1");
|
||||
MainUtil.sendMessage(plr, C.SWAP_SYNTAX);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Getting selections as ids
|
||||
final ArrayList<PlotId> selection1 = MainUtil.getPlotSelectionIds(bot1.id, top1.id);
|
||||
final ArrayList<PlotId> selection2 = MainUtil.getPlotSelectionIds(bot2.id, top2.id);
|
||||
|
||||
// Getting selections as location coordinates
|
||||
Location pos1 = MainUtil.getPlotBottomLocAbs(world, bot1.id);
|
||||
Location pos2 = MainUtil.getPlotTopLocAbs(world, top1.id).subtract(1, 0, 1);
|
||||
Location pos3 = MainUtil.getPlotBottomLocAbs(world, bot2.id);
|
||||
Location pos4 = MainUtil.getPlotTopLocAbs(world, top2.id).subtract(1, 0, 1);
|
||||
|
||||
if (MainUtil.getPlot(pos2) != null) {
|
||||
pos1.add(1, 0, 1);
|
||||
pos2.add(1, 0, 1);
|
||||
pos3.add(1, 0, 1);
|
||||
pos4.add(1, 0, 1);
|
||||
}
|
||||
|
||||
// Swapping the blocks, states and entites
|
||||
ChunkManager.manager.swap(world, pos1, pos2, pos3, pos4);
|
||||
|
||||
// Swapping the plot data
|
||||
for (int i = 0; i < selection1.size(); i++) {
|
||||
final boolean last = i == selection1.size() - 1;
|
||||
PlotId swaper = selection1.get(i);
|
||||
PlotId swapee = selection2.get(i);
|
||||
MainUtil.swapData(world, swaper, swapee, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (last) {
|
||||
MainUtil.sendMessage(plr, C.SWAP_SUCCESS);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.STARTED_SWAP);
|
||||
return true;
|
||||
}
|
||||
}
|
103
src/main/java/com/intellectualcrafters/plot/commands/TP.java
Normal file
103
src/main/java/com/intellectualcrafters/plot/commands/TP.java
Normal file
@ -0,0 +1,103 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class TP extends SubCommand {
|
||||
public TP() {
|
||||
super(Command.TP, "Teleport to a plot", "tp {alias|id}", CommandCategory.TELEPORT, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (args.length < 1) {
|
||||
MainUtil.sendMessage(plr, C.NEED_PLOT_ID);
|
||||
return false;
|
||||
}
|
||||
final String id = args[0];
|
||||
PlotId plotid;
|
||||
final Location loc = plr.getLocation();
|
||||
final String pworld = loc.getWorld();
|
||||
String world = pworld;
|
||||
if (args.length == 2) {
|
||||
if (BlockManager.manager.isWorld(args[1])) {
|
||||
world = args[1];
|
||||
}
|
||||
}
|
||||
if (!PS.get().isPlotWorld(world)) {
|
||||
MainUtil.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
|
||||
return false;
|
||||
}
|
||||
Plot temp;
|
||||
if ((temp = isAlias(world, id)) != null) {
|
||||
MainUtil.teleportPlayer(plr, plr.getLocation(), temp);
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
plotid = new PlotId(Integer.parseInt(id.split(";")[0]), Integer.parseInt(id.split(";")[1]));
|
||||
MainUtil.teleportPlayer(plr, plr.getLocation(), MainUtil.getPlot(world, plotid));
|
||||
return true;
|
||||
} catch (final Exception e) {
|
||||
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private Plot isAlias(final String world, String a) {
|
||||
int index = 0;
|
||||
if (a.contains(";")) {
|
||||
final String[] split = a.split(";");
|
||||
if ((split[1].length() > 0) && StringUtils.isNumeric(split[1])) {
|
||||
index = Integer.parseInt(split[1]);
|
||||
}
|
||||
a = split[0];
|
||||
}
|
||||
final PlotPlayer player = UUIDHandler.getPlayer(a);
|
||||
if (player != null) {
|
||||
final java.util.Set<Plot> plotMainPlots = PS.get().getPlots(world, player);
|
||||
final Plot[] plots = plotMainPlots.toArray(new Plot[plotMainPlots.size()]);
|
||||
if (plots.length > index) {
|
||||
return plots[index];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
for (final Plot p : PS.get().getPlots(world).values()) {
|
||||
if ((p.settings.getAlias().length() > 0) && p.settings.getAlias().equalsIgnoreCase(a)) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
|
||||
public class Target extends SubCommand {
|
||||
public Target() {
|
||||
super(Command.TARGET, "Target a plot with your compass", "target <X;Z>", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
final Location ploc = plr.getLocation();
|
||||
if (!PS.get().isPlotWorld(ploc.getWorld())) {
|
||||
MainUtil.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
|
||||
return false;
|
||||
}
|
||||
if (args.length == 1) {
|
||||
final PlotId id = MainUtil.parseId(args[0]);
|
||||
if (id == null) {
|
||||
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
||||
return false;
|
||||
}
|
||||
final Location loc = MainUtil.getPlotHome(ploc.getWorld(), id);
|
||||
plr.setCompassTarget(loc);
|
||||
MainUtil.sendMessage(plr, C.COMPASS_TARGET);
|
||||
return true;
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot target <X;Z>");
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,212 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import com.intellectualcrafters.configuration.ConfigurationSection;
|
||||
import com.intellectualcrafters.configuration.file.YamlConfiguration;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.ConfigurationNode;
|
||||
import com.intellectualcrafters.plot.object.FileBytes;
|
||||
import com.intellectualcrafters.plot.object.PlotManager;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.object.SetupObject;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.SetupUtils;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
|
||||
public class Template extends SubCommand {
|
||||
public Template() {
|
||||
super("template", "plots.admin", "Create or use a world template", "template", "", CommandCategory.DEBUG, false);
|
||||
}
|
||||
|
||||
public static boolean extractAllFiles(String world, String template) {
|
||||
byte[] buffer = new byte[2048];
|
||||
try {
|
||||
File folder = new File(PS.get().IMP.getDirectory() + File.separator + "templates");
|
||||
if (!folder.exists()) {
|
||||
return false;
|
||||
}
|
||||
File input = new File(folder + File.separator + template + ".template");
|
||||
File output = PS.get().IMP.getDirectory();
|
||||
if (!output.exists()) {
|
||||
output.mkdirs();
|
||||
}
|
||||
ZipInputStream zis = new ZipInputStream(new FileInputStream(input));
|
||||
ZipEntry ze = zis.getNextEntry();
|
||||
while (ze != null) {
|
||||
String name = ze.getName();
|
||||
File newFile = new File((output + File.separator + name).replaceAll("__TEMP_DIR__", world));
|
||||
new File(newFile.getParent()).mkdirs();
|
||||
FileOutputStream fos = new FileOutputStream(newFile);
|
||||
int len;
|
||||
while ((len = zis.read(buffer)) > 0) {
|
||||
fos.write(buffer, 0, len);
|
||||
}
|
||||
fos.close();
|
||||
ze = zis.getNextEntry();
|
||||
}
|
||||
zis.closeEntry();
|
||||
zis.close();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] getBytes(PlotWorld plotworld) {
|
||||
ConfigurationSection section = PS.get().config.getConfigurationSection("worlds." + plotworld.worldname);
|
||||
YamlConfiguration config = new YamlConfiguration();
|
||||
String generator = SetupUtils.manager.getGenerator(plotworld);
|
||||
if (generator != null) {
|
||||
config.set("generator.plugin", generator);
|
||||
}
|
||||
for (String key : section.getKeys(true)) {
|
||||
config.set(key, section.get(key));
|
||||
}
|
||||
return config.saveToString().getBytes();
|
||||
}
|
||||
|
||||
public static void zipAll(final String world, Set<FileBytes> files) throws IOException {
|
||||
File output = new File(PS.get().IMP.getDirectory() + File.separator + "templates");
|
||||
output.mkdirs();
|
||||
FileOutputStream fos = new FileOutputStream(output + File.separator + world + ".template");
|
||||
ZipOutputStream zos = new ZipOutputStream(fos);
|
||||
|
||||
for (FileBytes file : files) {
|
||||
ZipEntry ze = new ZipEntry(file.path);
|
||||
zos.putNextEntry(ze);
|
||||
zos.write(file.data);
|
||||
}
|
||||
zos.closeEntry();
|
||||
zos.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (args.length != 2 && args.length != 3) {
|
||||
if (args.length == 1) {
|
||||
if (args[0].equalsIgnoreCase("export")) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot template export <world>");
|
||||
return false;
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("import")) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot template import <world> <template>");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot template <import|export> <world> [template]");
|
||||
return false;
|
||||
}
|
||||
final String world = args[1];
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "import": {
|
||||
if (args.length != 3) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot template import <world> <template>");
|
||||
return false;
|
||||
}
|
||||
if (PS.get().isPlotWorld(world)) {
|
||||
MainUtil.sendMessage(plr, C.SETUP_WORLD_TAKEN, world);
|
||||
return false;
|
||||
}
|
||||
boolean result = extractAllFiles(world, args[2]);
|
||||
if (!result) {
|
||||
MainUtil.sendMessage(plr, "&cInvalid template file: " + args[2] +".template");
|
||||
return false;
|
||||
}
|
||||
File worldFile = new File(PS.get().IMP.getDirectory() + File.separator + "templates" + File.separator + "tmp-data.yml");
|
||||
YamlConfiguration worldConfig = YamlConfiguration.loadConfiguration(worldFile);
|
||||
PS.get().config.set("worlds." + world, worldConfig.get(""));
|
||||
try {
|
||||
PS.get().config.save(PS.get().configFile);
|
||||
PS.get().config.load(PS.get().configFile);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String manager = worldConfig.getString("generator.plugin");
|
||||
if (manager == null) {
|
||||
manager = "PlotSquared";
|
||||
}
|
||||
String generator = worldConfig.getString("generator.init");
|
||||
if (generator == null) {
|
||||
generator = manager;
|
||||
}
|
||||
|
||||
int type = worldConfig.getInt("generator.type");
|
||||
int terrain = worldConfig.getInt("generator.terrain");
|
||||
|
||||
SetupObject setup = new SetupObject();
|
||||
setup.plotManager = manager;
|
||||
setup.setupGenerator = generator;
|
||||
setup.type = type;
|
||||
setup.terrain = terrain;
|
||||
setup.step = new ConfigurationNode[0];
|
||||
setup.world = world;
|
||||
SetupUtils.manager.setupWorld(setup);
|
||||
MainUtil.sendMessage(plr, "Done!");
|
||||
if (plr != null) {
|
||||
plr.teleport(BlockManager.manager.getSpawn(world));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case "export": {
|
||||
if (args.length != 2) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot template export <world>");
|
||||
return false;
|
||||
}
|
||||
final PlotWorld plotworld = PS.get().getPlotWorld(world);
|
||||
if (!BlockManager.manager.isWorld(world) || (plotworld == null)) {
|
||||
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_WORLD);
|
||||
return false;
|
||||
}
|
||||
final PlotManager manager = PS.get().getPlotManager(world);
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
manager.exportTemplate(plotworld);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
MainUtil.sendMessage(plr, "Failed: " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
MainUtil.sendMessage(plr, "Done!");
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
|
||||
public class Toggle extends SubCommand {
|
||||
public Toggle() {
|
||||
super(Command.TOGGLE, "Toggle per user settings", "toggle <setting>", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
public void noArgs(PlotPlayer player) {
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot toggle <setting>");
|
||||
MainUtil.sendMessage(player, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + "titles");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer player, final String... args) {
|
||||
if (args.length == 0) {
|
||||
noArgs(player);
|
||||
return false;
|
||||
}
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "titles": {
|
||||
if (toggle(player, "disabletitles")) {
|
||||
MainUtil.sendMessage(player, C.TOGGLE_ENABLED, args[0]);
|
||||
}
|
||||
else {
|
||||
MainUtil.sendMessage(player, C.TOGGLE_DISABLED, args[0]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
default: {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean toggle(PlotPlayer player, String key) {
|
||||
if (player.getAttribute(key)) {
|
||||
player.removeAttribute(key);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
player.setAttribute(key);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
212
src/main/java/com/intellectualcrafters/plot/commands/Trim.java
Normal file
212
src/main/java/com/intellectualcrafters/plot/commands/Trim.java
Normal file
@ -0,0 +1,212 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
|
||||
public class Trim extends SubCommand {
|
||||
public static boolean TASK = false;
|
||||
public static ArrayList<Plot> expired = null;
|
||||
private static int TASK_ID = 0;
|
||||
|
||||
public Trim() {
|
||||
super("trim", "plots.admin", "Delete unmodified portions of your plotworld", "trim", "", CommandCategory.DEBUG, false);
|
||||
}
|
||||
|
||||
public static boolean getBulkRegions(final ArrayList<ChunkLoc> empty, final String world, final Runnable whenDone) {
|
||||
if (Trim.TASK) {
|
||||
return false;
|
||||
}
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final String directory = world + File.separator + "region";
|
||||
final File folder = new File(directory);
|
||||
final File[] regionFiles = folder.listFiles();
|
||||
for (final File file : regionFiles) {
|
||||
final String name = file.getName();
|
||||
if (name.endsWith("mca")) {
|
||||
if (file.getTotalSpace() <= 8192) {
|
||||
try {
|
||||
final String[] split = name.split("\\.");
|
||||
final int x = Integer.parseInt(split[1]);
|
||||
final int z = Integer.parseInt(split[2]);
|
||||
final ChunkLoc loc = new ChunkLoc(x, z);
|
||||
empty.add(loc);
|
||||
} catch (final Exception e) {
|
||||
PS.log("INVALID MCA: " + name);
|
||||
}
|
||||
} else {
|
||||
final Path path = Paths.get(file.getPath());
|
||||
try {
|
||||
final BasicFileAttributes attr = Files.readAttributes(path, BasicFileAttributes.class);
|
||||
final long creation = attr.creationTime().toMillis();
|
||||
final long modification = file.lastModified();
|
||||
final long diff = Math.abs(creation - modification);
|
||||
if (diff < 10000) {
|
||||
try {
|
||||
final String[] split = name.split("\\.");
|
||||
final int x = Integer.parseInt(split[1]);
|
||||
final int z = Integer.parseInt(split[2]);
|
||||
final ChunkLoc loc = new ChunkLoc(x, z);
|
||||
empty.add(loc);
|
||||
} catch (final Exception e) {
|
||||
PS.log("INVALID MCA: " + name);
|
||||
}
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Trim.TASK = false;
|
||||
TaskManager.runTaskAsync(whenDone);
|
||||
}
|
||||
});
|
||||
Trim.TASK = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean getTrimRegions(final ArrayList<ChunkLoc> empty, final String world, final Runnable whenDone) {
|
||||
if (Trim.TASK) {
|
||||
return false;
|
||||
}
|
||||
System.currentTimeMillis();
|
||||
sendMessage("Collecting region data...");
|
||||
final ArrayList<Plot> plots = new ArrayList<>();
|
||||
plots.addAll(PS.get().getPlots(world).values());
|
||||
final HashSet<ChunkLoc> chunks = new HashSet<>(ChunkManager.manager.getChunkChunks(world));
|
||||
sendMessage(" - MCA #: " + chunks.size());
|
||||
sendMessage(" - CHUNKS: " + (chunks.size() * 1024) + " (max)");
|
||||
sendMessage(" - TIME ESTIMATE: " + (chunks.size() / 1200) + " minutes");
|
||||
Trim.TASK_ID = TaskManager.runTaskRepeat(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final long start = System.currentTimeMillis();
|
||||
while ((System.currentTimeMillis() - start) < 50) {
|
||||
if (plots.size() == 0) {
|
||||
empty.addAll(chunks);
|
||||
Trim.TASK = false;
|
||||
TaskManager.runTaskAsync(whenDone);
|
||||
PS.get().TASK.cancelTask(Trim.TASK_ID);
|
||||
return;
|
||||
}
|
||||
final Plot plot = plots.get(0);
|
||||
plots.remove(0);
|
||||
final Location pos1 = MainUtil.getPlotBottomLoc(world, plot.id);
|
||||
final Location pos2 = MainUtil.getPlotTopLoc(world, plot.id);
|
||||
for (int x = pos1.getX(); x <= pos2.getX(); x += 512 ) {
|
||||
for (int z = pos1.getZ(); z <= pos2.getZ(); z += 512 ) {
|
||||
ChunkLoc chunk = ChunkManager.getChunkChunk(new Location(world, x, 0, z));
|
||||
chunks.remove(chunk);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 20);
|
||||
Trim.TASK = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void deleteChunks(final String world, final ArrayList<ChunkLoc> chunks) {
|
||||
ChunkManager.manager.deleteRegionFiles(world, chunks);
|
||||
}
|
||||
|
||||
public static void sendMessage(final String message) {
|
||||
PS.log("&3PlotSquared -> World trim&8: &7" + message);
|
||||
}
|
||||
|
||||
public PlotId getId(final String id) {
|
||||
try {
|
||||
final String[] split = id.split(";");
|
||||
return new PlotId(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
|
||||
} catch (final Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (plr != null) {
|
||||
MainUtil.sendMessage(plr, (C.NOT_CONSOLE));
|
||||
return false;
|
||||
}
|
||||
if (args.length == 1) {
|
||||
final String arg = args[0].toLowerCase();
|
||||
final PlotId id = getId(arg);
|
||||
if (id != null) {
|
||||
MainUtil.sendMessage(plr, "/plot trim x;z &l<world>");
|
||||
return false;
|
||||
}
|
||||
if (arg.equals("all")) {
|
||||
MainUtil.sendMessage(plr, "/plot trim all &l<world>");
|
||||
return false;
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.TRIM_SYNTAX);
|
||||
return false;
|
||||
}
|
||||
if (args.length != 2) {
|
||||
MainUtil.sendMessage(plr, C.TRIM_SYNTAX);
|
||||
return false;
|
||||
}
|
||||
final String arg = args[0].toLowerCase();
|
||||
if (!arg.equals("all")) {
|
||||
MainUtil.sendMessage(plr, C.TRIM_SYNTAX);
|
||||
return false;
|
||||
}
|
||||
final String world = args[1];
|
||||
if (!BlockManager.manager.isWorld(world) || (PS.get().getPlotWorld(world) == null)) {
|
||||
MainUtil.sendMessage(plr, C.NOT_VALID_WORLD);
|
||||
return false;
|
||||
}
|
||||
if (Trim.TASK) {
|
||||
sendMessage(C.TRIM_IN_PROGRESS.s());
|
||||
return false;
|
||||
}
|
||||
sendMessage(C.TRIM_START.s());
|
||||
final ArrayList<ChunkLoc> empty = new ArrayList<>();
|
||||
getTrimRegions(empty, world, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
deleteChunks(world, empty);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.EventUtil;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
public class Trust extends SubCommand {
|
||||
public Trust() {
|
||||
super(Command.TRUST, "Allow a player to build in a plot", "trust <player>", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (args.length != 1) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot trust <player>");
|
||||
return true;
|
||||
}
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||
}
|
||||
if ((plot == null) || !plot.hasOwner()) {
|
||||
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
|
||||
return false;
|
||||
}
|
||||
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.trust")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||
return true;
|
||||
}
|
||||
UUID uuid;
|
||||
if (args[0].equalsIgnoreCase("*")) {
|
||||
uuid = DBFunc.everyone;
|
||||
} else {
|
||||
uuid = UUIDHandler.getUUID(args[0]);
|
||||
}
|
||||
if (uuid == null) {
|
||||
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
|
||||
return false;
|
||||
}
|
||||
if (plot.isOwner(uuid)) {
|
||||
MainUtil.sendMessage(plr, C.ALREADY_OWNER);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (plot.trusted.contains(uuid)) {
|
||||
MainUtil.sendMessage(plr, C.ALREADY_ADDED);
|
||||
return false;
|
||||
}
|
||||
if (plot.removeMember(uuid)) {
|
||||
plot.addTrusted(uuid);
|
||||
}
|
||||
else {
|
||||
if (plot.members.size() + plot.trusted.size() >= PS.get().getPlotWorld(plot.world).MAX_PLOT_MEMBERS) {
|
||||
MainUtil.sendMessage(plr, C.PLOT_MAX_MEMBERS);
|
||||
return false;
|
||||
}
|
||||
if (plot.denied.contains(uuid)) {
|
||||
plot.removeDenied(uuid);
|
||||
}
|
||||
plot.addTrusted(uuid);
|
||||
}
|
||||
EventUtil.manager.callTrusted(plr, plot, uuid, true);
|
||||
MainUtil.sendMessage(plr, C.TRUSTED_ADDED);
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
|
||||
public class Unclaim extends SubCommand {
|
||||
public Unclaim() {
|
||||
super(Command.UNCLAIM, "Unclaim a plot", "unclaim", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||
}
|
||||
if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) {
|
||||
return !sendMessage(plr, C.UNLINK_REQUIRED);
|
||||
}
|
||||
if ((((plot == null) || !plot.hasOwner() || !plot.isOwner(plr.getUUID()))) && !Permissions.hasPermission(plr, "plots.admin.command.unclaim")) {
|
||||
return !sendMessage(plr, C.NO_PLOT_PERMS);
|
||||
}
|
||||
assert plot != null;
|
||||
final PlotWorld pWorld = PS.get().getPlotWorld(plot.world);
|
||||
if ((EconHandler.manager != null) && pWorld.USE_ECONOMY) {
|
||||
final double c = pWorld.SELL_PRICE;
|
||||
if (c > 0d) {
|
||||
EconHandler.manager.depositMoney(plr, c);
|
||||
sendMessage(plr, C.ADDED_BALANCE, c + "");
|
||||
}
|
||||
}
|
||||
final boolean result = PS.get().removePlot(loc.getWorld(), plot.id, true);
|
||||
if (result) {
|
||||
plot.unclaim();
|
||||
} else {
|
||||
MainUtil.sendMessage(plr, "Plot removal has been denied.");
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.UNCLAIM_SUCCESS);
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
public class Undeny extends SubCommand {
|
||||
public Undeny() {
|
||||
super(Command.UNDENY, "Remove a denied user from a plot", "undeny <player>", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (args.length != 1) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot undeny <player>");
|
||||
return true;
|
||||
}
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||
}
|
||||
if ((plot == null) || !plot.hasOwner()) {
|
||||
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
|
||||
return false;
|
||||
}
|
||||
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.undeny")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||
return true;
|
||||
}
|
||||
int count = 0;
|
||||
if (args[0].equals("unknown")) {
|
||||
ArrayList<UUID> toRemove = new ArrayList<>();
|
||||
for (UUID uuid : plot.denied) {
|
||||
if (UUIDHandler.getName(uuid) == null) {
|
||||
toRemove.add(uuid);
|
||||
}
|
||||
}
|
||||
for (UUID uuid : toRemove) {
|
||||
plot.removeDenied(uuid);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
else if (args[0].equals("*")){
|
||||
for (UUID uuid : new ArrayList<>(plot.denied)) {
|
||||
plot.removeDenied(uuid);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
UUID uuid = UUIDHandler.getUUID(args[0]);
|
||||
if (uuid != null) {
|
||||
if (plot.removeDenied(uuid)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count == 0) {
|
||||
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
MainUtil.sendMessage(plr, C.REMOVED_PLAYERS, count + "");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.CmdConfirm;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
|
||||
/**
|
||||
* Created 2014-08-01 for PlotSquared
|
||||
*
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class Unlink extends SubCommand {
|
||||
public Unlink() {
|
||||
super(Command.UNLINK, "Unlink a mega-plot", "unlink", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||
}
|
||||
if (((plot == null) || !plot.hasOwner() || !plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.unlink")) {
|
||||
return sendMessage(plr, C.NO_PLOT_PERMS);
|
||||
}
|
||||
if (MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) {
|
||||
return sendMessage(plr, C.UNLINK_IMPOSSIBLE);
|
||||
}
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!MainUtil.unlinkPlot(plot)) {
|
||||
MainUtil.sendMessage(plr, "&cUnlink has been cancelled");
|
||||
return;
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.UNLINK_SUCCESS);
|
||||
}
|
||||
};
|
||||
if (Settings.CONFIRM_UNLINK && !(Permissions.hasPermission(plr, "plots.confirm.bypass"))) {
|
||||
CmdConfirm.addPending(plr, "/plot unlink " + plot.id, runnable);
|
||||
}
|
||||
else {
|
||||
TaskManager.runTask(runnable);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
public class Untrust extends SubCommand {
|
||||
public Untrust() {
|
||||
super(Command.UNTRUST, "Remove a trusted user from a plot", "untrust <player>", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (args.length != 1) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot untrust <player>");
|
||||
return true;
|
||||
}
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||
}
|
||||
if ((plot == null) || !plot.hasOwner()) {
|
||||
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
|
||||
return false;
|
||||
}
|
||||
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.untrust")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||
return true;
|
||||
}
|
||||
int count = 0;
|
||||
if (args[0].equals("unknown")) {
|
||||
ArrayList<UUID> toRemove = new ArrayList<>();
|
||||
for (UUID uuid : plot.trusted) {
|
||||
if (UUIDHandler.getName(uuid) == null) {
|
||||
toRemove.add(uuid);
|
||||
}
|
||||
}
|
||||
for (UUID uuid : toRemove) {
|
||||
plot.removeTrusted(uuid);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
else if (args[0].equals("*")){
|
||||
for (UUID uuid : new ArrayList<>(plot.trusted)) {
|
||||
plot.removeTrusted(uuid);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
UUID uuid = UUIDHandler.getUUID(args[0]);
|
||||
if (uuid != null) {
|
||||
if (plot.removeTrusted(uuid)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count == 0) {
|
||||
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
MainUtil.sendMessage(plr, C.REMOVED_PLAYERS, count + "");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
|
||||
public class Update extends SubCommand {
|
||||
public static String downloads, version;
|
||||
|
||||
public Update() {
|
||||
super("update", "plots.admin", "Update PlotSquared", "update", "updateplugin", CommandCategory.DEBUG, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (plr != null) {
|
||||
MainUtil.sendMessage(plr, C.NOT_CONSOLE);
|
||||
return false;
|
||||
}
|
||||
URL url;
|
||||
if (args.length == 0) {
|
||||
url = PS.get().update;
|
||||
}
|
||||
else if (args.length == 1) {
|
||||
try {
|
||||
url = new URL(args[0]);
|
||||
} catch (MalformedURLException e) {
|
||||
MainUtil.sendMessage(plr, "&cInvalid url: " + args[0]);
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot update [url]");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot update");
|
||||
return false;
|
||||
}
|
||||
if (url == null) {
|
||||
MainUtil.sendMessage(plr, "&cNo update found!");
|
||||
MainUtil.sendMessage(plr, "&cTo manually specify an update URL: /plot update <url>");
|
||||
return false;
|
||||
}
|
||||
PS.get().update(url);
|
||||
return true;
|
||||
}
|
||||
}
|
153
src/main/java/com/intellectualcrafters/plot/commands/Visit.java
Normal file
153
src/main/java/com/intellectualcrafters/plot/commands/Visit.java
Normal file
@ -0,0 +1,153 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
public class Visit extends SubCommand {
|
||||
public Visit() {
|
||||
super("visit", "plots.visit", "Visit someones plot", "visit {player} [#]", "v", CommandCategory.TELEPORT, true);
|
||||
}
|
||||
|
||||
public List<Plot> getPlots(final UUID uuid) {
|
||||
final List<Plot> plots = new ArrayList<>();
|
||||
for (final Plot p : PS.get().getPlots()) {
|
||||
if (p.hasOwner() && p.isOwner(uuid)) {
|
||||
plots.add(p);
|
||||
}
|
||||
}
|
||||
return plots;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (args.length < 1) {
|
||||
return sendMessage(plr, C.COMMAND_SYNTAX, "/plot visit <player|alias|world|id> [#]");
|
||||
}
|
||||
ArrayList<Plot> plots = new ArrayList<>();
|
||||
UUID user = UUIDHandler.getUUID(args[0]);
|
||||
if (user != null ) {
|
||||
// do plots by username
|
||||
plots.addAll(PS.get().getPlots(user));
|
||||
} else if (PS.get().isPlotWorld(args[0])) {
|
||||
// do plots by world
|
||||
plots.addAll(PS.get().getPlots(args[0]).values());
|
||||
}
|
||||
else {
|
||||
Plot plot = MainUtil.getPlotFromString(plr, args[0], true);
|
||||
if (plot == null) {
|
||||
return false;
|
||||
}
|
||||
plots.add(plot);
|
||||
}
|
||||
if (plots.size() == 0) {
|
||||
sendMessage(plr, C.FOUND_NO_PLOTS);
|
||||
return false;
|
||||
}
|
||||
int index = 0;
|
||||
if (args.length == 2) {
|
||||
try {
|
||||
index = Integer.parseInt(args[1]) - 1;
|
||||
if (index < 0 || index >= plots.size()) {
|
||||
sendMessage(plr, C.NOT_VALID_NUMBER, "(1, " + plots.size() + ")");
|
||||
sendMessage(plr, C.COMMAND_SYNTAX, "/plot visit " + args[0] + " [#]");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
sendMessage(plr, C.NOT_VALID_NUMBER, "(1, " + plots.size() + ")");
|
||||
sendMessage(plr, C.COMMAND_SYNTAX, "/plot visit " + args[0] + " [#]");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Plot plot = plots.get(index);
|
||||
if (!plot.hasOwner()) {
|
||||
if (!Permissions.hasPermission(plr, "plots.visit.unowned")) {
|
||||
sendMessage(plr, C.NO_PERMISSION, "plots.visit.unowned");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (plot.isOwner(plr.getUUID())) {
|
||||
if (!Permissions.hasPermission(plr, "plots.visit.owned") && !Permissions.hasPermission(plr, "plots.home")) {
|
||||
sendMessage(plr, C.NO_PERMISSION, "plots.visit.owned, plots.home");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (plot.isAdded(plr.getUUID())) {
|
||||
if (!Permissions.hasPermission(plr, "plots.visit.shared")) {
|
||||
sendMessage(plr, C.NO_PERMISSION, "plots.visit.shared");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!Permissions.hasPermission(plr, "plots.visit.other")) {
|
||||
sendMessage(plr, C.NO_PERMISSION, "plots.visit.other");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
MainUtil.teleportPlayer(plr, plr.getLocation(), plots.get(index));
|
||||
return true;
|
||||
|
||||
//
|
||||
// // from alias
|
||||
//
|
||||
//
|
||||
// id = PlotId.fromString(args[0]);
|
||||
//
|
||||
//
|
||||
//
|
||||
// final String username = args[0];
|
||||
// final UUID uuid = UUIDHandler.getUUID(username);
|
||||
// List<Plot> plots = null;
|
||||
// if (uuid != null) {
|
||||
// plots = PlotSquared.sortPlotsByWorld(getPlots(uuid));
|
||||
// }
|
||||
// if ((uuid == null) || plots.isEmpty()) {
|
||||
// return sendMessage(plr, C.FOUND_NO_PLOTS);
|
||||
// }
|
||||
// if (args.length < 2) {
|
||||
// MainUtil.teleportPlayer(plr, plr.getLocation(), plots.get(0));
|
||||
// return true;
|
||||
// }
|
||||
// int i;
|
||||
// try {
|
||||
// i = Integer.parseInt(args[1]);
|
||||
// } catch (final Exception e) {
|
||||
// return sendMessage(plr, C.NOT_VALID_NUMBER);
|
||||
// }
|
||||
// if ((i < 1) || (i > plots.size())) {
|
||||
// return sendMessage(plr, C.NOT_VALID_NUMBER);
|
||||
// }
|
||||
// MainUtil.teleportPlayer(plr, plr.getLocation(), plots.get(i - 1));
|
||||
// return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.listeners.worldedit.WEManager;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
|
||||
public class WE_Anywhere extends SubCommand {
|
||||
public WE_Anywhere() {
|
||||
super("weanywhere", "plots.worldedit.bypass", "Force bypass of WorldEdit", "weanywhere", "wea", CommandCategory.DEBUG, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (PS.get().worldEdit == null) {
|
||||
MainUtil.sendMessage(plr, "&cWorldEdit is not enabled on this server");
|
||||
return false;
|
||||
}
|
||||
if (Permissions.hasPermission(plr, "plots.worldedit.bypass")) {
|
||||
if (WEManager.bypass.contains(plr.getName())) {
|
||||
WEManager.bypass.remove(plr.getName());
|
||||
MainUtil.sendMessage(plr, C.WORLDEDIT_RESTRICTED);
|
||||
}
|
||||
else {
|
||||
WEManager.bypass.add(plr.getName());
|
||||
MainUtil.sendMessage(plr, C.WORLDEDIT_UNMASKED);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
531
src/main/java/com/intellectualcrafters/plot/commands/list.java
Normal file
531
src/main/java/com/intellectualcrafters/plot/commands/list.java
Normal file
@ -0,0 +1,531 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.object.BukkitPlayer;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.Rating;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.StringComparison;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
import com.intellectualcrafters.plot.util.bukkit.chat.FancyMessage;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class list extends SubCommand {
|
||||
public list() {
|
||||
super(Command.LIST, "List all plots", "list {mine|shared|all|world|forsale}", CommandCategory.INFO, false);
|
||||
}
|
||||
|
||||
private static String getName(final UUID id) {
|
||||
if (id == null) {
|
||||
return "none";
|
||||
}
|
||||
final String name = UUIDHandler.getName(id);
|
||||
if (name == null) {
|
||||
return "unknown";
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
private String[] getArgumentList(PlotPlayer player) {
|
||||
List<String> args = new ArrayList<>();
|
||||
if (player == null) {
|
||||
args.addAll(Arrays.asList("world", "all", "unowned", "unknown", "top", "<player", "<world>"));
|
||||
if (EconHandler.manager != null) {
|
||||
args.add("forsale");
|
||||
}
|
||||
} else {
|
||||
if (EconHandler.manager != null && player.hasPermission("plots.list.forsale")) {
|
||||
args.add("forsale");
|
||||
}
|
||||
if (player.hasPermission("plots.list.mine")) {
|
||||
args.add("mine");
|
||||
}
|
||||
if (player.hasPermission("plots.list.shared")) {
|
||||
args.add("shared");
|
||||
}
|
||||
if (player.hasPermission("plots.list.world")) {
|
||||
args.add("world");
|
||||
}
|
||||
if (player.hasPermission("plots.list.top")) {
|
||||
args.add("top");
|
||||
}
|
||||
if (player.hasPermission("plots.list..all")) {
|
||||
args.add("all");
|
||||
}
|
||||
if (player.hasPermission("plots.list.unowned")) {
|
||||
args.add("unowned");
|
||||
}
|
||||
if (player.hasPermission("plots.list.unknown")) {
|
||||
args.add("unknown");
|
||||
}
|
||||
if (player.hasPermission("plots.list.player")) {
|
||||
args.add("<player>");
|
||||
}
|
||||
if (player.hasPermission("plots.list.world")) {
|
||||
args.add("<world>");
|
||||
}
|
||||
}
|
||||
return args.toArray(new String[args.size()]);
|
||||
}
|
||||
|
||||
public void noArgs(PlotPlayer plr) {
|
||||
// For #395
|
||||
// if (plr != null) {
|
||||
// if (EconHandler.manager != null) {
|
||||
// builder.append(getArgumentList(new String[] { "mine", "shared", "world", "all", "unowned", "unknown", "top", "<player>", "<world>", "forsale",}));
|
||||
// }
|
||||
// else {
|
||||
// builder.append(getArgumentList(new String[] { "mine", "shared", "world", "all", "unowned", "unknown", "top", "<player>", "<world>"}));
|
||||
// }
|
||||
// } else {
|
||||
// builder.append(getArgumentList(new String[] { "world", "all", "unowned", "unknown", "top", "<player>", "<world>"}));
|
||||
// }
|
||||
MainUtil.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + getArgumentList(getArgumentList(plr)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (args.length < 1) {
|
||||
noArgs(plr);
|
||||
return false;
|
||||
}
|
||||
int page = 0;
|
||||
if (args.length > 1) {
|
||||
try {
|
||||
page = Integer.parseInt(args[1]);
|
||||
--page;
|
||||
if (page < 0) {
|
||||
page = 0;
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
page = 0;
|
||||
}
|
||||
}
|
||||
|
||||
List<Plot> plots = null;
|
||||
|
||||
String world;
|
||||
if (plr != null) {
|
||||
world = plr.getLocation().getWorld();
|
||||
}
|
||||
else {
|
||||
Set<String> worlds = PS.get().getPlotWorlds();
|
||||
if (worlds.size() == 0) {
|
||||
world = "world";
|
||||
}
|
||||
else {
|
||||
world = worlds.iterator().next();
|
||||
}
|
||||
}
|
||||
String arg = args[0].toLowerCase();
|
||||
boolean sort = true;
|
||||
switch (arg) {
|
||||
case "mine": {
|
||||
if (plr == null) {
|
||||
break;
|
||||
}
|
||||
if (!Permissions.hasPermission(plr, "plots.list.mine")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.mine");
|
||||
return false;
|
||||
}
|
||||
plots = new ArrayList<>(PS.get().getPlots(plr));
|
||||
break;
|
||||
}
|
||||
case "shared": {
|
||||
if (plr == null) {
|
||||
break;
|
||||
}
|
||||
if (!Permissions.hasPermission(plr, "plots.list.shared")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.shared");
|
||||
return false;
|
||||
}
|
||||
plots = new ArrayList<Plot>();
|
||||
for (Plot plot : PS.get().getPlots()) {
|
||||
if (plot.trusted.contains(plr.getUUID()) || plot.members.contains(plr.getUUID())) {
|
||||
plots.add(plot);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "world": {
|
||||
if (!Permissions.hasPermission(plr, "plots.list.world")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.world");
|
||||
return false;
|
||||
}
|
||||
if (!Permissions.hasPermission(plr, "plots.list.world." + world)) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.world." + world);
|
||||
return false;
|
||||
}
|
||||
plots = new ArrayList<>(PS.get().getPlots(world).values());
|
||||
break;
|
||||
}
|
||||
case "all": {
|
||||
if (!Permissions.hasPermission(plr, "plots.list.all")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.all");
|
||||
return false;
|
||||
}
|
||||
plots = new ArrayList<>(PS.get().getPlots());
|
||||
break;
|
||||
}
|
||||
case "top": {
|
||||
if (!Permissions.hasPermission(plr, "plots.list.top")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.top");
|
||||
return false;
|
||||
}
|
||||
plots = new ArrayList<>(PS.get().getPlots());
|
||||
Collections.sort(plots, new Comparator<Plot>() {
|
||||
@Override
|
||||
public int compare(Plot p1, Plot p2) {
|
||||
double v1 = 0;
|
||||
double v2 = 0;
|
||||
if (p1.settings.ratings != null && p1.settings.ratings.size() > 0) {
|
||||
for (Entry<UUID, Rating> entry : p1.getRatings().entrySet()) {
|
||||
double av = entry.getValue().getAverageRating();
|
||||
v1 += av * av;
|
||||
}
|
||||
v1 /= p1.settings.ratings.size();
|
||||
v2 += p2.settings.ratings.size();
|
||||
}
|
||||
if (p2.settings.ratings != null && p2.settings.ratings.size() > 0) {
|
||||
for (Entry<UUID, Rating> entry : p2.getRatings().entrySet()) {
|
||||
double av = entry.getValue().getAverageRating();
|
||||
v2 += av * av;
|
||||
}
|
||||
v2 /= p2.settings.ratings.size();
|
||||
v2 += p2.settings.ratings.size();
|
||||
}
|
||||
if (v2 == v1 && v2 != 0) {
|
||||
return p2.settings.ratings.size() - p1.settings.ratings.size();
|
||||
}
|
||||
return (int) Math.signum(v2 - v1);
|
||||
}
|
||||
});
|
||||
sort = false;
|
||||
break;
|
||||
}
|
||||
case "forsale": {
|
||||
if (!Permissions.hasPermission(plr, "plots.list.forsale")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.forsale");
|
||||
return false;
|
||||
}
|
||||
if (EconHandler.manager == null) {
|
||||
break;
|
||||
}
|
||||
plots = new ArrayList<>();
|
||||
for (Plot plot : PS.get().getPlots()) {
|
||||
final Flag price = FlagManager.getPlotFlag(plot, "price");
|
||||
if (price != null) {
|
||||
plots.add(plot);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "unowned": {
|
||||
if (!Permissions.hasPermission(plr, "plots.list.unowned")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.unowned");
|
||||
return false;
|
||||
}
|
||||
plots = new ArrayList<>();
|
||||
for (Plot plot : PS.get().getPlots()) {
|
||||
if (plot.owner == null) {
|
||||
plots.add(plot);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "unknown": {
|
||||
if (!Permissions.hasPermission(plr, "plots.list.unknown")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.unknown");
|
||||
return false;
|
||||
}
|
||||
plots = new ArrayList<>();
|
||||
for (Plot plot : PS.get().getPlots()) {
|
||||
if (plot.owner == null) {
|
||||
continue;
|
||||
}
|
||||
if (UUIDHandler.getName(plot.owner) == null) {
|
||||
plots.add(plot);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
if (PS.get().isPlotWorld(args[0])) {
|
||||
if (!Permissions.hasPermission(plr, "plots.list.world")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.world");
|
||||
return false;
|
||||
}
|
||||
if (!Permissions.hasPermission(plr, "plots.list.world." + args[0])) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.world." + args[0]);
|
||||
return false;
|
||||
}
|
||||
plots = new ArrayList<>(PS.get().getPlots(args[0]).values());
|
||||
break;
|
||||
}
|
||||
UUID uuid = UUIDHandler.getUUID(args[0]);
|
||||
if (uuid != null) {
|
||||
if (!Permissions.hasPermission(plr, "plots.list.player")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.player");
|
||||
return false;
|
||||
}
|
||||
plots = new ArrayList<>(PS.get().getPlots(uuid));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (plots == null) {
|
||||
sendMessage(plr, C.DID_YOU_MEAN, new StringComparison(args[0], new String[] { "mine", "shared", "world", "all" }).getBestMatch());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (plots.size() == 0) {
|
||||
MainUtil.sendMessage(plr, C.FOUND_NO_PLOTS);
|
||||
return false;
|
||||
}
|
||||
displayPlots(plr, plots, 12, page, world, args, sort);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void displayPlots(PlotPlayer player, List<Plot> plots, int pageSize, int page, String world, String[] args, boolean sort) {
|
||||
if (sort) {
|
||||
if (world != null) {
|
||||
plots = PS.get().sortPlots(plots, world);
|
||||
}
|
||||
else {
|
||||
plots = PS.get().sortPlots(plots);
|
||||
}
|
||||
}
|
||||
if (page < 0) {
|
||||
page = 0;
|
||||
}
|
||||
final int totalPages = (int) Math.ceil(plots.size() / pageSize);
|
||||
if (page > totalPages) {
|
||||
page = totalPages;
|
||||
}
|
||||
// Only display pageSize!
|
||||
int max = (page * pageSize) + pageSize;
|
||||
if (max > plots.size()) {
|
||||
max = plots.size();
|
||||
}
|
||||
|
||||
List<Plot> subList = plots.subList(page * pageSize, max);
|
||||
|
||||
// Header
|
||||
String header = C.PLOT_LIST_HEADER_PAGED.s()
|
||||
.replaceAll("%cur", page + 1 + "")
|
||||
.replaceAll("%max", totalPages + 1 + "")
|
||||
.replaceAll("%amount%", plots.size() + "")
|
||||
.replaceAll("%word%", "all");
|
||||
MainUtil.sendMessage(player, header);
|
||||
|
||||
int i = page * pageSize;
|
||||
for (Plot plot : subList) {
|
||||
if (plot.settings.isMerged()) {
|
||||
if (!MainUtil.getBottomPlot(plot).equals(plot)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
i++;
|
||||
if (player != null && Settings.FANCY_CHAT) {
|
||||
ChatColor color;
|
||||
if (plot.owner == null) {
|
||||
color = ChatColor.GOLD;
|
||||
}
|
||||
else if (plot.isOwner(player.getUUID())) {
|
||||
color = ChatColor.BLUE;
|
||||
}
|
||||
else if (plot.isAdded(player.getUUID())) {
|
||||
color = ChatColor.DARK_GREEN;
|
||||
}
|
||||
else if (plot.isDenied(player.getUUID())) {
|
||||
color = ChatColor.RED;
|
||||
}
|
||||
else {
|
||||
color = ChatColor.GOLD;
|
||||
}
|
||||
FancyMessage trusted =
|
||||
new FancyMessage(
|
||||
ChatColor.stripColor(
|
||||
ChatColor.translateAlternateColorCodes('&',
|
||||
C.PLOT_INFO_TRUSTED.s().replaceAll("%trusted%", Info.getPlayerList(plot.trusted)))))
|
||||
.color(ChatColor.GOLD);
|
||||
|
||||
FancyMessage members =
|
||||
new FancyMessage(
|
||||
ChatColor.stripColor(
|
||||
ChatColor.translateAlternateColorCodes('&',
|
||||
C.PLOT_INFO_MEMBERS.s().replaceAll("%members%", Info.getPlayerList(plot.members)))))
|
||||
.color(ChatColor.GOLD);
|
||||
String strFlags = StringUtils.join(plot.settings.flags.values(), ",");
|
||||
if (strFlags.length() == 0) {
|
||||
strFlags = C.NONE.s();
|
||||
}
|
||||
FancyMessage flags =
|
||||
new FancyMessage(
|
||||
ChatColor.stripColor(
|
||||
ChatColor.translateAlternateColorCodes('&',
|
||||
C.PLOT_INFO_FLAGS.s().replaceAll("%flags%", strFlags))))
|
||||
.color(ChatColor.GOLD);
|
||||
|
||||
FancyMessage message = new FancyMessage("")
|
||||
.then("[")
|
||||
.color(ChatColor.DARK_GRAY)
|
||||
.then(i + "")
|
||||
.command("/plot visit " + plot.world + ";" + plot.id)
|
||||
.tooltip("/plot visit " + plot.world + ";" + plot.id)
|
||||
.color(ChatColor.GOLD)
|
||||
.then("]")
|
||||
|
||||
// teleport tooltip
|
||||
|
||||
.color(ChatColor.DARK_GRAY)
|
||||
.then(" " + plot.toString())
|
||||
|
||||
.formattedTooltip(trusted, members, flags)
|
||||
.command("/plot info " + plot.world + ";" + plot.id)
|
||||
|
||||
.color(color)
|
||||
.then(" - ")
|
||||
.color(ChatColor.GRAY);
|
||||
String prefix = "";
|
||||
for (UUID uuid : plot.getOwners()) {
|
||||
String name = UUIDHandler.getName(uuid);
|
||||
if (name == null) {
|
||||
message = message
|
||||
.then(prefix)
|
||||
.color(ChatColor.DARK_GRAY)
|
||||
.then("unknown")
|
||||
.color(ChatColor.GRAY)
|
||||
.tooltip(uuid.toString())
|
||||
.suggest(uuid.toString());
|
||||
}
|
||||
else {
|
||||
PlotPlayer pp = UUIDHandler.getPlayer(uuid);
|
||||
if (pp != null) {
|
||||
message = message
|
||||
.then(prefix)
|
||||
.color(ChatColor.DARK_GRAY)
|
||||
.then(name).color(ChatColor.GOLD)
|
||||
.formattedTooltip(new FancyMessage("Online").color(ChatColor.DARK_GREEN));
|
||||
}
|
||||
else {
|
||||
message = message
|
||||
.then(prefix)
|
||||
.color(ChatColor.DARK_GRAY)
|
||||
.then(name).color(ChatColor.GOLD)
|
||||
.formattedTooltip(new FancyMessage("Offline").color(ChatColor.RED));
|
||||
}
|
||||
}
|
||||
prefix = ", ";
|
||||
}
|
||||
message.send(((BukkitPlayer) player).player);
|
||||
}
|
||||
else {
|
||||
String message = C.PLOT_LIST_ITEM.s()
|
||||
.replaceAll("%in", i + 1 + "")
|
||||
.replaceAll("%id", plot.id.toString())
|
||||
.replaceAll("%world", plot.world)
|
||||
.replaceAll("%owner", getName(plot.owner))
|
||||
|
||||
// Unused
|
||||
|
||||
.replaceAll("%trusted%", "")
|
||||
.replaceAll("%members%", "")
|
||||
.replaceAll("%tp%", "");
|
||||
MainUtil.sendMessage(player, message);
|
||||
}
|
||||
}
|
||||
if (player != null && Settings.FANCY_CHAT) {
|
||||
if (page < totalPages && page > 0) {
|
||||
// back | next
|
||||
new FancyMessage("")
|
||||
.then("<-")
|
||||
.color(ChatColor.GOLD)
|
||||
.command("/plot list " + args[0] + " " + (page))
|
||||
.then(" | ")
|
||||
.color(ChatColor.DARK_GRAY)
|
||||
.then("->")
|
||||
.color(ChatColor.GOLD)
|
||||
.command("/plot list " + args[0] + " " + (page + 2))
|
||||
.send(((BukkitPlayer) player).player);
|
||||
return;
|
||||
}
|
||||
if (page == 0 && totalPages != 0) {
|
||||
// next
|
||||
new FancyMessage("")
|
||||
.then("<-")
|
||||
.color(ChatColor.DARK_GRAY)
|
||||
.then(" | ")
|
||||
.color(ChatColor.DARK_GRAY)
|
||||
.then("->")
|
||||
.color(ChatColor.GOLD)
|
||||
.command("/plot list " + args[0] + " " + (page + 2))
|
||||
.send(((BukkitPlayer) player).player);
|
||||
return;
|
||||
}
|
||||
if (page == totalPages && totalPages != 0) {
|
||||
// back
|
||||
new FancyMessage("")
|
||||
.then("<-")
|
||||
.color(ChatColor.GOLD)
|
||||
.command("/plot list " + args[0] + " " + (page))
|
||||
.then(" | ")
|
||||
.color(ChatColor.DARK_GRAY)
|
||||
.then("->")
|
||||
.color(ChatColor.DARK_GRAY)
|
||||
.send(((BukkitPlayer) player).player);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
String footer = C.PLOT_LIST_FOOTER.s().replaceAll("%word%", "There is").replaceAll("%num%", plots.size() + "").replaceAll("%plot%", plots.size() == 1 ? "plot" : "plots");
|
||||
MainUtil.sendMessage(player, footer);
|
||||
}
|
||||
}
|
||||
|
||||
private String getArgumentList(final String[] strings) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
String prefix = "";
|
||||
for (final String s : strings) {
|
||||
builder.append(prefix + MainUtil.colorise('&', s));
|
||||
prefix = " | ";
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.StringMan;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class plugin extends SubCommand {
|
||||
|
||||
public plugin() {
|
||||
super("plugin", "plots.use", "Show plugin information", "plugin", "version", CommandCategory.INFO, false);
|
||||
}
|
||||
|
||||
private static String convertToNumericString(final String str, final boolean dividers) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
for (final char c : str.toCharArray()) {
|
||||
if (Character.isDigit(c)) {
|
||||
builder.append(c);
|
||||
} else if (dividers && ((c == ',') || (c == '.') || (c == '-') || (c == '_'))) {
|
||||
builder.append(c);
|
||||
}
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private static String getInfo(final String link) throws Exception {
|
||||
final URLConnection connection = new URL(link).openConnection();
|
||||
connection.addRequestProperty("User-Agent", "Mozilla/4.0");
|
||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
String document = "", line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
document += (line + "\n");
|
||||
}
|
||||
reader.close();
|
||||
return document;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final ArrayList<String> strings = new ArrayList<String>() {
|
||||
// $2>> $1%id$2:$1%world $2- $1%owner
|
||||
{
|
||||
add(String.format("$2>> $1&lPlotSquared $2(Version$2: $1%s$2)", PS.get().IMP.getVersion()));
|
||||
add(String.format("$2>> $1&lAuthors$2: $1Citymonstret $2& $1Empire92"));
|
||||
add(String.format("$2>> $1&lWiki$2: $1https://github.com/IntellectualCrafters/PlotSquared/wiki"));
|
||||
add(String.format("$2>> $1&lWebsite$2: $1http://plotsquared.co"));
|
||||
add(String.format("$2>> $1&lNewest Version$2: $1" + (PS.get().update == null ? PS.get().IMP.getVersion() : PS.get().update)));
|
||||
}
|
||||
};
|
||||
for (final String s : strings) {
|
||||
MainUtil.sendMessage(plr, StringMan.replaceFromMap(s, C.replacements), false);
|
||||
}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
654
src/main/java/com/intellectualcrafters/plot/config/C.java
Normal file
654
src/main/java/com/intellectualcrafters/plot/config/C.java
Normal file
@ -0,0 +1,654 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.config;
|
||||
|
||||
import com.intellectualcrafters.configuration.ConfigurationSection;
|
||||
import com.intellectualcrafters.configuration.file.YamlConfiguration;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.util.StringMan;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Captions class.
|
||||
*
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public enum C {
|
||||
|
||||
/*
|
||||
* Confirm
|
||||
*/
|
||||
FAILED_CONFIRM("$2You have no pending actions to confirm!", "Confirm"),
|
||||
REQUIRES_CONFIRM("$2Are you sure you wish to execute: $1%s$2?&-$2This cannot be undone! If you are sure: $1/plot confirm", "Confirm"),
|
||||
/*
|
||||
* Move
|
||||
*/
|
||||
MOVE_SUCCESS("$4Successfully moved plot.", "Move"),
|
||||
COPY_SUCCESS("$4Successfully copied plot.", "Move"),
|
||||
REQUIRES_UNOWNED("$2The location specified is already occupied.", "Move"),
|
||||
/*
|
||||
* Web
|
||||
*/
|
||||
GENERATING_LINK("$1Processing plot...", "Web"),
|
||||
GENERATING_LINK_FAILED("$2Failed to generate download link!", "Web"),
|
||||
/*
|
||||
* Compass
|
||||
*/
|
||||
COMPASS_TARGET("$4Successfully targeted plot with compass", "Compass"),
|
||||
/*
|
||||
* Cluster
|
||||
*/
|
||||
CLUSTER_AVAILABLE_ARGS("$1The following sub commands are available: $4list$2, $4create$2, $4delete$2, $4resize$2, $4invite$2, $4kick$2, $4leave$2, $4members$2, $4info$2, $4tp$2, $4sethome", "Cluster"),
|
||||
CLUSTER_LIST_HEADING("$2There are $1%s$2 clusters in this world", "Cluster"),
|
||||
CLUSTER_LIST_ELEMENT("$2 - $1%s&-", "Cluster"),
|
||||
CLUSTER_INTERSECTION("$2The proposed area overlaps with $1%s$2 existing cluster/s", "Cluster"),
|
||||
CLUSTER_ADDED("$4Successfully created the cluster.", "Cluster"),
|
||||
CLUSTER_DELETED("$4Successfully deleted the cluster.", "Cluster"),
|
||||
CLUSTER_RESIZED("$4Successfully resized the cluster.", "Cluster"),
|
||||
CLUSTER_ADDED_USER("$4Successfully added user to the cluster.", "Cluster"),
|
||||
CANNOT_KICK_PLAYER("$2You cannot kick that player", "Cluster"),
|
||||
CLUSTER_INVITED("$1You have been invited to the following cluster: $2%s", "Cluster"),
|
||||
CLUSTER_REMOVED("$1You have been removed from cluster: $2%s", "Cluster"),
|
||||
CLUSTER_KICKED_USER("$4Successfully kicked the user", "Cluster"),
|
||||
INVALID_CLUSTER("$1Invalid cluster name: $2%s", "Cluster"),
|
||||
CLUSTER_NOT_ADDED("$2That player was not added to the plot cluster", "Cluster"),
|
||||
CLUSTER_CANNOT_LEAVE("$1You must delete or transfer ownership before leaving", "Cluster"),
|
||||
CLUSTER_ADDED_HELPER("$4Successfully added a helper to the cluster", "Cluster"),
|
||||
CLUSTER_REMOVED_HELPER("$4Successfully removed a helper from the cluster", "Cluster"),
|
||||
CLUSTER_REGENERATED("$4Successfully started cluster regeneration", "Cluster"),
|
||||
CLUSTER_TELEPORTING("$4Teleporting...", "Cluster"),
|
||||
CLUSTER_INFO("$1Current cluster: $2%id%&-$1Name: $2%name%&-$1Owner: $2%owner%&-$1Size: $2%size%&-$1Rights: $2%rights%", "Cluster"),
|
||||
CLUSTER_CURRENT_PLOTID("$1Current plot: $2%s", "Cluster"),
|
||||
/*
|
||||
* Border
|
||||
*/
|
||||
BORDER("$2You are outside the current map border", "Border"),
|
||||
/*
|
||||
* Unclaim
|
||||
*/
|
||||
UNCLAIM_SUCCESS("$4You successfully unclaimed the plot.", "Unclaim"),
|
||||
/*
|
||||
* WorldEdit masks
|
||||
*/
|
||||
REQUIRE_SELECTION_IN_MASK("$2%s of your selection is not within your plot mask. You can only make edits within your plot.", "WorldEdit Masks"),
|
||||
WORLDEDIT_VOLUME("$2You cannot select a volume of %current%. The maximum volume you can modify is %max%.", "WorldEdit Masks"),
|
||||
WORLDEDIT_ITERATIONS("$2You cannot iterate %current% times. The maximum number of iterations allowed is %max%.", "WorldEdit Masks"),
|
||||
WORLDEDIT_UNSAFE("$2Access to that command has been blocked", "WorldEdit Masks"),
|
||||
WORLDEDIT_BYPASS("$2&oTo bypass your restrictions use $4/plot wea", "WorldEdit Masks"),
|
||||
WORLDEDIT_UNMASKED("$1Your WorldEdit is now unrestricted.", "WorldEdit Masks"),
|
||||
WORLDEDIT_RESTRICTED("$1Your WorldEdit is now restricted.", "WorldEdit Masks"),
|
||||
/*
|
||||
* Records
|
||||
*/
|
||||
RECORD_PLAY("$2%player $2started playing record $1%name", "Records"),
|
||||
NOTIFY_ENTER("$2%player $2entered your plot ($1%plot$2)", "Records"),
|
||||
NOTIFY_LEAVE("$2%player $2left your plot ($1%plot$2)", "Records"),
|
||||
/*
|
||||
* Swap
|
||||
*/
|
||||
SWAP_OVERLAP("$2The proposed areas are not allowed to overlap", "Swap"),
|
||||
SWAP_DIMENSIONS("$2The proposed areas must have comparable dimensions", "Swap"),
|
||||
SWAP_SYNTAX("$2/plots swap <plot id>", "Swap"),
|
||||
SWAP_SUCCESS("$4Successfully swapped plots", "Swap"),
|
||||
STARTED_SWAP("$2Started plot swap task. You will be notified when it finishes", "Swap"),
|
||||
/*
|
||||
* Comment
|
||||
*/
|
||||
INBOX_NOTIFICATION("%s unread messages. Use /plot inbox", "Comment"),
|
||||
NOT_VALID_INBOX_INDEX("$2No comment at index %s", "Comment"),
|
||||
INBOX_ITEM("$2 - $4%s", "Comment"),
|
||||
COMMENT_SYNTAX("$2Use /plots comment [X;Z] <%s> <comment>", "Comment"),
|
||||
INVALID_INBOX("$2That is not a valid inbox.&-$1Accepted values: %s", "Comment"),
|
||||
NO_PERM_INBOX("$2You do not have permission for that inbox", "Comment"),
|
||||
NO_PERM_INBOX_MODIFY("$2You do not have permission to modify that inbox", "Comment"),
|
||||
NO_PLOT_INBOX("$2You must stand in or supply a plot argument", "Comment"),
|
||||
COMMENT_REMOVED("$4Successfully deleted comment/s:n$2 - '$3%s$2'", "Comment"),
|
||||
COMMENT_ADDED("$4A comment has been left", "Comment"),
|
||||
COMMENT_HEADER("$2====== Comments ======", "Comment"),
|
||||
INBOX_EMPTY("$2No comments","Comment"),
|
||||
/*
|
||||
* Console
|
||||
*/
|
||||
NOT_CONSOLE("$2For safety reasons, this command can only be executed by console.", "Console"),
|
||||
IS_CONSOLE("$2This command can only be executed by a player.", "Console"),
|
||||
|
||||
/*
|
||||
Inventory
|
||||
*/
|
||||
INVENTORY_USAGE("&cUsage: &6{usage}", "Inventory"),
|
||||
INVENTORY_DESC("&cDescription: &6{desc}", "Inventory"),
|
||||
INVENTORY_CATEGORY("&cCategory: &6{category}", "Inventory"),
|
||||
|
||||
/*
|
||||
* Clipboard
|
||||
*/
|
||||
CLIPBOARD_SET("$2The current plot is now copied to your clipboard, use $1/plot paste$2 to paste it", "Clipboard"),
|
||||
PASTED("$4The plot selection was successfully pasted. It has been cleared from your clipboard.", "Clipboard"),
|
||||
PASTE_FAILED("$2Failed to paste the selection. Reason: $2%s", "Clipboard"),
|
||||
NO_CLIPBOARD("$2You don't have a selection in your clipboard", "Clipboard"),
|
||||
CLIPBOARD_INFO("$2Current Selection - Plot ID: $1%id$2, Width: $1%width$2, Total Blocks: $1%total$2", "Clipboard"),
|
||||
/*
|
||||
*
|
||||
*/
|
||||
TOGGLE_ENABLED("$2Enabled setting: %s", "Toggle"),
|
||||
TOGGLE_DISABLED("$2Disabled setting: %s", "Toggle"),
|
||||
/*
|
||||
* Ratings
|
||||
*/
|
||||
RATE_THIS("$2Rate this plot!", "Ratings"),
|
||||
RATING_NOT_VALID("$2You need to specify a number between 1 and 10", "Ratings"),
|
||||
RATING_ALREADY_EXISTS("$2You have already rated plot $2%s", "Ratings"),
|
||||
RATING_APPLIED("$4You successfully rated plot $2%s", "Ratings"),
|
||||
RATING_NOT_YOUR_OWN("$2You cannot rate your own plot", "Ratings"),
|
||||
RATING_NOT_OWNED("$2You cannot rate a plot that is not claimed by anyone", "Ratings"),
|
||||
/*
|
||||
* Economy Stuff
|
||||
*/
|
||||
ECON_DISABLED("$2Economy is not enabled", "Economy"),
|
||||
CANNOT_AFFORD_PLOT("$2You cannot afford to buy this plot. It costs $1%s", "Economy"),
|
||||
NOT_FOR_SALE("$2This plot is not for sale", "Economy"),
|
||||
CANNOT_BUY_OWN("$2You cannot buy your own plot", "Economy"),
|
||||
PLOT_SOLD("$4Your plot; $1%s$4, has been sold to $1%s$4 for $1$%s", "Economy"),
|
||||
CANNOT_AFFORD_MERGE("$2You cannot afford to merge the plots. It costs $1%s", "Economy"),
|
||||
ADDED_BALANCE("$1%s $2has been added to your balance", "Economy"),
|
||||
REMOVED_BALANCE("$1%s $2has been taken from your balance", "Economy"),
|
||||
/*
|
||||
* Setup Stuff
|
||||
*/
|
||||
SETUP_INIT("$1Usage: $2/plot setup <value>", "Setup"),
|
||||
SETUP_STEP("$3[$1Step %s$3] $1%s $2- $1Expecting: $2%s $1Default: $2%s", "Setup"),
|
||||
SETUP_INVALID_ARG("$2%s is not a valid argument for step %s. To cancel setup use: $1/plot setup cancel", "Setup"),
|
||||
SETUP_VALID_ARG("$2Value $1%s $2set to %s", "Setup"),
|
||||
SETUP_FINISHED("$3If you are using MULTIVERSE or MULTIWORLD the world should have just been created. Otherwise you will need to add the world manually through the bukkit.yml", "Setup"),
|
||||
SETUP_WORLD_TAKEN("$2%s is already a registered plotworld", "Setup"),
|
||||
SETUP_MISSING_WORLD("$2You need to specify a world name ($1/plot setup &l<world>$1 <generator>$2)&-$1Additional commands:&-$2 - $1/plot setup <value>&-$2 - $1/plot setup back&-$2 - $1/plot setup cancel", "Setup"),
|
||||
SETUP_MISSING_GENERATOR("$2You need to specify a generator ($1/plot setup <world> &l<generator>&r$2)&-$1Additional commands:&-$2 - $1/plot setup <value>&-$2 - $1/plot setup back&-$2 - $1/plot setup cancel", "Setup"),
|
||||
SETUP_INVALID_GENERATOR("$2Invalid generator. Possible options: %s", "Setup"),
|
||||
/*
|
||||
* Schematic Stuff
|
||||
*/
|
||||
SCHEMATIC_MISSING_ARG("$2You need to specify an argument. Possible values: $1test <name>$2 , $1save$2 , $1paste $2, $1exportall", "Schematics"),
|
||||
SCHEMATIC_INVALID("$2That is not a valid schematic. Reason: $2%s", "Schematics"),
|
||||
SCHEMATIC_VALID("$2That is a valid schematic", "Schematics"),
|
||||
SCHEMATIC_PASTE_FAILED("$2Failed to paste the schematic", "Schematics"),
|
||||
SCHEMATIC_PASTE_SUCCESS("$4The schematic pasted successfully", "Schematics"),
|
||||
/*
|
||||
* Title Stuff
|
||||
*/
|
||||
TITLE_ENTERED_PLOT("Plot: %world%;%x%;%z%", "Titles"),
|
||||
TITLE_ENTERED_PLOT_COLOR("GOLD", "Titles"),
|
||||
TITLE_ENTERED_PLOT_SUB("Owned by %s", "Titles"),
|
||||
TITLE_ENTERED_PLOT_SUB_COLOR("RED", "Titles"),
|
||||
PREFIX_GREETING("$1%id%$2> ", "Titles"),
|
||||
PREFIX_FAREWELL("$1%id%$2> ", "Titles"),
|
||||
/*
|
||||
* Core Stuff
|
||||
*/
|
||||
PREFIX("$3[$1P2$3] $2", "Core"),
|
||||
ENABLED("$1PlotSquared is now enabled", "Core"),
|
||||
EXAMPLE_MESSAGE("$2This is an example message &k!!!", "Core"),
|
||||
/*
|
||||
* Reload
|
||||
*/
|
||||
RELOADED_CONFIGS("$1Translations and world settings have been reloaded", "Reload"),
|
||||
RELOAD_FAILED("$2Failed to reload file configurations", "Reload"),
|
||||
/*
|
||||
* BarAPI
|
||||
*/
|
||||
BOSSBAR_CLEARING("$2Clearing plot: $1%id%", "Bar API"),
|
||||
/*
|
||||
* Alias
|
||||
*/
|
||||
ALIAS_SET_TO("$2Plot alias set to $1%alias%", "Alias"),
|
||||
MISSING_ALIAS("$2You need to specify an alias", "Alias"),
|
||||
ALIAS_TOO_LONG("$2The alias must be < 50 characters in length", "Alias"),
|
||||
ALIAS_IS_TAKEN("$2That alias is already taken", "Alias"),
|
||||
/*
|
||||
* Position
|
||||
*/
|
||||
MISSING_POSITION("$2You need to specify a position. Possible values: $1none", "Position"),
|
||||
POSITION_SET("$1Home position set to your current location", "Position"),
|
||||
HOME_ARGUMENT("$2Use /plot set home [none]", "Position"),
|
||||
INVALID_POSITION("$2That is not a valid position value", "Position"),
|
||||
/*
|
||||
* Time
|
||||
*/
|
||||
TIME_FORMAT("$1%hours%, %min%, %sec%", "Time"),
|
||||
/*
|
||||
* Permission
|
||||
*/
|
||||
NO_SCHEMATIC_PERMISSION("$2You don't have the permission required to use schematic $1%s", "Permission"),
|
||||
NO_PERMISSION("$2You are lacking the permission node: $1%s", "Permission"),
|
||||
NO_PLOT_PERMS("$2You must be the plot owner to perform this action", "Permission"),
|
||||
CANT_CLAIM_MORE_PLOTS("$2You can't claim more plots.", "Permission"),
|
||||
CANT_TRANSFER_MORE_PLOTS("$2You can't send more plots to that user", "Permission"),
|
||||
CANT_CLAIM_MORE_PLOTS_NUM("$2You can't claim more than $1%s $2plots at once", "Permission"),
|
||||
YOU_BE_DENIED("$2You are not allowed to enter this plot", "Permission"),
|
||||
NO_PERM_MERGE("$2You are not the owner of the plot: $1%plot%", "Permission"),
|
||||
UNLINK_REQUIRED("$2An unlink is required to do this.", "Permission"),
|
||||
UNLINK_IMPOSSIBLE("$2You can only unlink a mega-plot", "Permission"),
|
||||
UNLINK_SUCCESS("$2Successfully unlinked plots.", "Permission"),
|
||||
NO_MERGE_TO_MEGA("$2Mega plots cannot be merged into. Please merge from the desired mega plot.", "Permission"),
|
||||
MERGE_NOT_VALID("$2This merge request is no longer valid.", "Permission"),
|
||||
MERGE_ACCEPTED("$2The merge request has been accepted", "Permission"),
|
||||
SUCCESS_MERGE("$2Plots have been merged!", "Permission"),
|
||||
MERGE_REQUESTED("$2Successfully sent a merge request", "Permission"),
|
||||
MERGE_REQUEST_CONFIRM("merge request from %s", "Permission"),
|
||||
/*
|
||||
* Commands
|
||||
*/
|
||||
NOT_VALID_SUBCOMMAND("$2That is not a valid subcommand", "Commands"),
|
||||
DID_YOU_MEAN("$2Did you mean: $1%s", "Commands"),
|
||||
NAME_LITTLE("$2%s name is too short, $1%s$2<$1%s", "Commands"),
|
||||
NO_COMMANDS("$2I'm sorry, but you're not permitted to use any subcommands.", "Commands"),
|
||||
SUBCOMMAND_SET_OPTIONS_HEADER("$2Possible Values: ", "Commands"),
|
||||
COMMAND_SYNTAX("$1Usage: $2%s", "Commands"),
|
||||
/*
|
||||
* Player not found
|
||||
*/
|
||||
INVALID_PLAYER("$2Player not found: $1%s.", "Errors"),
|
||||
/*
|
||||
*
|
||||
*/
|
||||
COMMAND_WENT_WRONG("$2Something went wrong when executing that command...", "Errors"),
|
||||
/*
|
||||
* purge
|
||||
*/
|
||||
PURGE_SYNTAX("Use /plot purge <x;z|player|unowned|unknown|all> <world>", "Purge"),
|
||||
PURGE_SUCCESS("$4Successfully purged %s plots", "Purge"),
|
||||
/*
|
||||
* trim
|
||||
*/
|
||||
TRIM_SYNTAX("Use /plot trim <all|x;y> <world>", "Trim"),
|
||||
TRIM_START("Starting a world trim task...", "Trim"),
|
||||
TRIM_IN_PROGRESS("A world trim task is already in progress!", "Trim"),
|
||||
NOT_VALID_HYBRID_PLOT_WORLD("The hybrid plot manager is required to perform this action", "Trim"),
|
||||
/*
|
||||
* No <plot>
|
||||
*/
|
||||
NO_FREE_PLOTS("$2There are no free plots available", "Errors"),
|
||||
NOT_IN_PLOT("$2You're not in a plot", "Errors"),
|
||||
NOT_IN_CLUSTER("$2You must be within a plot cluster to perform that action", "Errors"),
|
||||
NOT_IN_PLOT_WORLD("$2You're not in a plot world", "Errors"),
|
||||
PLOTWORLD_INCOMPATIBLE("$2The two worlds must be compatible", "Errors"),
|
||||
NOT_VALID_WORLD("$2That is not a valid world (case sensitive)", "Errors"),
|
||||
NOT_VALID_PLOT_WORLD("$2That is not a valid plot world (case sensitive)", "Errors"),
|
||||
NO_PLOTS("$2You don't have any plots", "Errors"),
|
||||
/*
|
||||
* Block List
|
||||
*/
|
||||
BLOCK_LIST_ITEM(" $1%mat%$2,", "Block List"),
|
||||
BLOCK_LIST_SEPARATER("$1,$2 ", "Block List"),
|
||||
/*
|
||||
* Biome
|
||||
*/
|
||||
NEED_BIOME("$2You need to specify a valid biome.", "Biome"),
|
||||
BIOME_SET_TO("$2Plot biome set to $2", "Biome"),
|
||||
/*
|
||||
* Teleport / Entry
|
||||
*/
|
||||
TELEPORTED_TO_PLOT("$1You have been teleported", "Teleport"),
|
||||
TELEPORTED_TO_ROAD("$2You got teleported to the road", "Teleport"),
|
||||
TELEPORT_IN_SECONDS("$1Teleporting in %s seconds. Do not move...", "Teleport"),
|
||||
TELEPORT_FAILED("$2Teleportation cancelled due to movement or damage", "Teleport"),
|
||||
/*
|
||||
* Set Block
|
||||
*/
|
||||
SET_BLOCK_ACTION_FINISHED("$1The last setblock action is now finished.", "Set Block"),
|
||||
|
||||
/*
|
||||
AllowUnsafe
|
||||
*/
|
||||
DEBUGALLOWUNSAFE_ON("$2Unsafe actions allowed", "unsafe"),
|
||||
DEBUGALLOWUNSAFE_OFF("$2Unsafe actions disabled", "unsafe"),
|
||||
/*
|
||||
* Debug
|
||||
*/
|
||||
DEBUG_HEADER("$1Debug Information&-", "Debug"),
|
||||
DEBUG_SECTION("$2>> $1&l%val%", "Debug"),
|
||||
DEBUG_LINE("$2>> $1%var%$2:$1 %val%&-", "Debug"),
|
||||
/*
|
||||
* Invalid
|
||||
*/
|
||||
NOT_VALID_DATA("$2That's not a valid data id.", "Invalid"),
|
||||
NOT_VALID_BLOCK("$2That's not a valid block: %s", "Invalid"),
|
||||
NOT_ALLOWED_BLOCK("$2That block is not allowed: %s", "Invalid"),
|
||||
NOT_VALID_NUMBER("$2That's not a valid number within the range: %s", "Invalid"),
|
||||
NOT_VALID_PLOT_ID("$2That's not a valid plot id.", "Invalid"),
|
||||
PLOT_ID_FORM("$2The plot id must be in the form: $1X;Y $2e.g. $1-5;7", "Invalid"),
|
||||
NOT_YOUR_PLOT("$2That is not your plot.", "Invalid"),
|
||||
NO_SUCH_PLOT("$2There is no such plot", "Invalid"),
|
||||
PLAYER_HAS_NOT_BEEN_ON("$2That player hasn't been in the plotworld", "Invalid"),
|
||||
FOUND_NO_PLOTS("$2Found no plots with your search query", "Invalid"),
|
||||
/*
|
||||
* Camera
|
||||
*/
|
||||
CAMERA_STARTED("$2You have entered camera mode for plot $1%s", "Camera"),
|
||||
CAMERA_STOPPED("$2You are no longer in camera mode", "Camera"),
|
||||
/*
|
||||
* Need
|
||||
*/
|
||||
NEED_PLOT_NUMBER("$2You've got to specify a plot number or alias", "Need"),
|
||||
NEED_BLOCK("$2You've got to specify a block", "Need"),
|
||||
NEED_PLOT_ID("$2You've got to specify a plot id.", "Need"),
|
||||
NEED_PLOT_WORLD("$2You've got to specify a plot world.", "Need"),
|
||||
NEED_USER("$2You need to specify a username", "Need"),
|
||||
/*
|
||||
* Info
|
||||
*/
|
||||
NONE("None", "Info"),
|
||||
PLOT_UNOWNED("$2The current plot must have an owner to perform this action", "Info"),
|
||||
PLOT_INFO_UNCLAIMED("$2Plot $1%s$2 is not yet claimed", "Info"),
|
||||
PLOT_INFO_HEADER("$3====== $1INFO $3======", false, "Info"),
|
||||
PLOT_INFO("$1ID: $2%id%$1&-" + "$1Alias: $2%alias%$1&-" + "$1Owner: $2%owner%$1&-" + "$1Biome: $2%biome%$1&-" + "$1Can Build: $2%build%$1&-" + "$1Rating: $2%rating%&-" + "$1Trusted: $2%trusted%$1&-" + "$1Members: $2%members%$1&-" + "$1Denied: $2%denied%$1&-" + "$1Flags: $2%flags%", "Info"),
|
||||
PLOT_INFO_TRUSTED("$1Trusted:$2 %trusted%", "Info"),
|
||||
PLOT_INFO_MEMBERS("$1Members:$2 %members%", "Info"),
|
||||
PLOT_INFO_DENIED("$1Denied:$2 %denied%", "Info"),
|
||||
PLOT_INFO_FLAGS("$1Flags:$2 %flags%", "Info"),
|
||||
PLOT_INFO_BIOME("$1Biome:$2 %biome%", "Info"),
|
||||
PLOT_INFO_RATING("$1Rating:$2 %rating%", "Info"),
|
||||
PLOT_INFO_OWNER("$1Owner:$2 %owner%", "Info"),
|
||||
PLOT_INFO_ID("$1ID:$2 %id%", "Info"),
|
||||
PLOT_INFO_ALIAS("$1Alias:$2 %alias%", "Info"),
|
||||
PLOT_INFO_SIZE("$1Size:$2 %size%", "Info"),
|
||||
PLOT_USER_LIST(" $1%user%$2,", "Info"),
|
||||
INFO_SYNTAX_CONSOLE("$2/plot info X;Y", "Info"),
|
||||
/*
|
||||
* Generating
|
||||
*/
|
||||
GENERATING_COMPONENT("$1Started generating component from your settings", "Working"),
|
||||
/*
|
||||
* Clearing
|
||||
*/
|
||||
CLEARING_PLOT("$2Clearing plot async.", "Working"),
|
||||
CLEARING_DONE("$4Clear completed! Took %sms.", "Working"),
|
||||
/*
|
||||
* Claiming
|
||||
*/
|
||||
PLOT_NOT_CLAIMED("$2Plot not claimed", "Working"),
|
||||
PLOT_IS_CLAIMED("$2This plot is already claimed", "Working"),
|
||||
CLAIMED("$4You successfully claimed the plot", "Working"),
|
||||
/*
|
||||
* List
|
||||
*/
|
||||
PLOT_LIST_HEADER_PAGED("$2(Page $1%cur$2/$1%max$2) $1List of %amount% plots", "List"),
|
||||
PLOT_LIST_HEADER("$1List of %word% plots", "List"),
|
||||
PLOT_LIST_ITEM("$2>> $1%id$2:$1%world $2- $1%owner", "List"),
|
||||
PLOT_LIST_ITEM_ORDERED("$2[$1%in$2] >> $1%id$2:$1%world $2- $1%owner", "List"),
|
||||
PLOT_LIST_FOOTER("$2>> $1%word% a total of $2%num% $1claimed %plot%.", "List"),
|
||||
/*
|
||||
* Left
|
||||
*/
|
||||
LEFT_PLOT("$2You left a plot", "Left"),
|
||||
/*
|
||||
* PlotMe
|
||||
*/
|
||||
NOT_USING_PLOTME("$2This server uses the far superior $1PlotSquared $2plot management system. Please use the $1/ps $2or $1/p2 $2or $1/plots $2instead", "Errors"),
|
||||
/*
|
||||
* Wait
|
||||
*/
|
||||
WAIT_FOR_TIMER("$2A setblock timer is bound to either the current plot or you. Please wait for it to finish", "Errors"),
|
||||
/*
|
||||
* Chat
|
||||
*/
|
||||
PLOT_CHAT_FORMAT("$2[$1Plot Chat$2][$1%plot_id%$2] $1%sender%$2: $1%msg%", "Chat"),
|
||||
PLOT_CHAT_FORCED("$2This world forces everyone to use plot chat.", "Chat"),
|
||||
PLOT_CHAT_ON("$4Plot chat enabled.", "Chat"),
|
||||
PLOT_CHAT_OFF("$4Plot chat disabled.", "Chat"),
|
||||
/*
|
||||
* Denied
|
||||
*/
|
||||
DENIED_REMOVED("$4You successfully undenied the player from this plot", "Deny"),
|
||||
DENIED_ADDED("$4You successfully denied the player from this plot", "Deny"),
|
||||
DENIED_NEED_ARGUMENT("$2Arguments are missing. $1/plot denied add <name> $2or $1/plot denied remove <name>", "Deny"),
|
||||
WAS_NOT_DENIED("$2That player was not denied on this plot", "Deny"),
|
||||
YOU_GOT_DENIED("$4You are denied from the plot you were previously on, and got teleported to spawn", "Deny"),
|
||||
/*
|
||||
* Rain
|
||||
*/
|
||||
NEED_ON_OFF("$2You need to specify a value. Possible values: $1on$2, $1off", "Rain"),
|
||||
SETTING_UPDATED("$4You successfully updated the setting", "Rain"),
|
||||
/*
|
||||
* Flag
|
||||
*/
|
||||
FLAG_KEY("$2Key: %s", "Flag"),
|
||||
FLAG_TYPE("$2Type: %s", "Flag"),
|
||||
FLAG_DESC("$2Desc: %s", "Flag"),
|
||||
NEED_KEY("$2Possible values: $1%values%", "Flag"),
|
||||
NOT_VALID_FLAG("$2That is not a valid flag", "Flag"),
|
||||
NOT_VALID_VALUE("$2Flag values must be alphanumerical", "Flag"),
|
||||
FLAG_NOT_IN_PLOT("$2The plot does not have that flag", "Flag"),
|
||||
FLAG_NOT_REMOVED("$2The flag could not be removed", "Flag"),
|
||||
FLAG_NOT_ADDED("$2The flag could not be added", "Flag"),
|
||||
FLAG_REMOVED("$4Successfully removed flag", "Flag"),
|
||||
FLAG_ADDED("$4Successfully added flag", "Flag"),
|
||||
/*
|
||||
* Trusted
|
||||
*/
|
||||
TRUSTED_ADDED("$4You successfully trusted a user to the plot", "Trusted"),
|
||||
TRUSTED_REMOVED("$4You successfully removed a trusted user from the plot", "Trusted"),
|
||||
WAS_NOT_ADDED("$2That player was not trusted on this plot", "Trusted"),
|
||||
PLOT_REMOVED_USER("$1Plot %s of which you were added to has been deleted due to owner inactivity", "Trusted"),
|
||||
/*
|
||||
* Member
|
||||
*/
|
||||
REMOVED_PLAYERS("$2Removed %s players from this plot.", "Member"),
|
||||
ALREADY_OWNER("$2That user is already the plot owner.", "Member"),
|
||||
ALREADY_ADDED("$2That user is already added to that category.", "Member"),
|
||||
MEMBER_ADDED("$4That user can now build while the plot owner is online", "Member"),
|
||||
MEMBER_REMOVED("$1You successfully removed a user from the plot", "Member"),
|
||||
MEMBER_WAS_NOT_ADDED("$2That player was not added as a user on this plot", "Member"),
|
||||
PLOT_MAX_MEMBERS("$2You are not allowed to add any more players to this plot", "Member"),
|
||||
/*
|
||||
* Set Owner
|
||||
*/
|
||||
SET_OWNER("$4You successfully set the plot owner", "Owner"),
|
||||
NOW_OWNER("$4You are now owner of plot %s", "Owner"),
|
||||
/*
|
||||
* Signs
|
||||
*/
|
||||
OWNER_SIGN_LINE_1("$1ID: $1%id%", "Signs"),
|
||||
OWNER_SIGN_LINE_2("$1Owner:", "Signs"),
|
||||
OWNER_SIGN_LINE_3("$2%plr%", "Signs"),
|
||||
OWNER_SIGN_LINE_4("$3Claimed", "Signs"),
|
||||
/*
|
||||
* Help
|
||||
*/
|
||||
HELP_HEADER("$3====== $1Plot\u00B2 Help $3======", "Help"),
|
||||
HELP_CATEGORY("$1Category: $2%category%$2,$1 Page: $2%current%$3/$2%max%$2,$1 Displaying: $2%dis%$3/$2%total%", "Help"),
|
||||
HELP_INFO("$3====== $1Choose a Category $3======", false, "Help"),
|
||||
HELP_INFO_ITEM("$1/plots help %category% $3- $2%category_desc%", "Help"),
|
||||
HELP_ITEM("$1%usage% [%alias%]&- $3- $2%desc%&-", "Help"),
|
||||
/*
|
||||
* Direction
|
||||
*/
|
||||
DIRECTION("$1Current direction: %dir%", "Help"),
|
||||
/*
|
||||
* Custom
|
||||
*/
|
||||
CUSTOM_STRING("-", "-");
|
||||
public static final HashMap<String, String> replacements = new HashMap<>();
|
||||
/**
|
||||
* Translated
|
||||
*/
|
||||
private String s;
|
||||
/**
|
||||
* Default
|
||||
*/
|
||||
private String d;
|
||||
/**
|
||||
* What locale category should this translation fall under
|
||||
*/
|
||||
private String cat;
|
||||
/**
|
||||
* Should the string be prefixed?
|
||||
*/
|
||||
private boolean prefix;
|
||||
|
||||
/**
|
||||
* Constructor for custom strings.
|
||||
*/
|
||||
C() {
|
||||
/*
|
||||
* use setCustomString();
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param d default
|
||||
* @param prefix use prefix
|
||||
*/
|
||||
C(final String d, final boolean prefix, String cat) {
|
||||
this.d = d;
|
||||
if (this.s == null) {
|
||||
this.s = d;
|
||||
}
|
||||
this.prefix = prefix;
|
||||
this.cat = cat.toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param d default
|
||||
*/
|
||||
C(final String d, String cat) {
|
||||
this(d, true, cat.toLowerCase());
|
||||
}
|
||||
|
||||
public static String format(C c, Object... args) {
|
||||
String m = c.s;
|
||||
for (int i = args.length - 1 ; i >= 0; i--) {
|
||||
if (args[i] == null) {
|
||||
continue;
|
||||
}
|
||||
m = m.replaceAll("%s" + i, args[i].toString());
|
||||
}
|
||||
if (args.length > 0) {
|
||||
m = m.replaceAll("%s", args[0].toString());
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
public static void load(File file) {
|
||||
try {
|
||||
if (!file.exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
file.createNewFile();
|
||||
}
|
||||
YamlConfiguration yml = YamlConfiguration.loadConfiguration(file);
|
||||
Set<String> keys = yml.getKeys(true);
|
||||
EnumSet<C> all = EnumSet.allOf(C.class);
|
||||
HashSet<String> allNames = new HashSet<>();
|
||||
HashSet<String> allCats = new HashSet<>();
|
||||
HashSet<String> toRemove = new HashSet<>();
|
||||
for (C c: all) {
|
||||
allNames.add(c.name());
|
||||
allCats.add(c.cat.toLowerCase());
|
||||
}
|
||||
HashSet<C> captions = new HashSet<>();
|
||||
boolean changed = false;
|
||||
for (String key : keys) {
|
||||
if (!yml.isString(key)) {
|
||||
if (!allCats.contains(key)) {
|
||||
toRemove.add(key);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
String[] split = key.split("\\.");
|
||||
String node = split[split.length - 1].toUpperCase();
|
||||
C caption = allNames.contains(node) ? valueOf(node) : null;
|
||||
if (caption != null) {
|
||||
String value = yml.getString(key);
|
||||
if (!split[0].equalsIgnoreCase(caption.cat)) {
|
||||
changed = true;
|
||||
yml.set(key, null);
|
||||
yml.set(caption.cat + "." + caption.name().toLowerCase(), value);
|
||||
}
|
||||
captions.add(caption);
|
||||
caption.s = value;
|
||||
}
|
||||
else {
|
||||
toRemove.add(key);
|
||||
}
|
||||
}
|
||||
for (String remove : toRemove) {
|
||||
changed = true;
|
||||
yml.set(remove, null);
|
||||
}
|
||||
ConfigurationSection config = PS.get().style.getConfigurationSection("color");
|
||||
Set<String> styles = config.getKeys(false);
|
||||
// HashMap<String, String> replacements = new HashMap<>();
|
||||
replacements.clear();
|
||||
for (String style : styles) {
|
||||
replacements.put("$" + style, "\u00a7" + config.getString(style));
|
||||
}
|
||||
for (char letter : "1234567890abcdefklmnor".toCharArray()) {
|
||||
replacements.put("&" + letter, "\u00a7" + letter);
|
||||
}
|
||||
replacements.put("\\\\n", "\n");
|
||||
replacements.put("\\n", "\n");
|
||||
replacements.put("&-", "\n");
|
||||
for (C caption : all) {
|
||||
if (!captions.contains(caption)) {
|
||||
changed = true;
|
||||
yml.set(caption.cat + "." + caption.name().toLowerCase(), caption.d);
|
||||
}
|
||||
caption.s = StringMan.replaceFromMap(caption.s, replacements);
|
||||
}
|
||||
if (changed) {
|
||||
yml.save(file);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public String s() {
|
||||
return this.s;
|
||||
}
|
||||
|
||||
public boolean usePrefix() {
|
||||
return this.prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return translated and color decoded
|
||||
*
|
||||
* @see org.bukkit.ChatColor#translateAlternateColorCodes(char, String)
|
||||
*/
|
||||
public String translated() {
|
||||
return ChatColor.translateAlternateColorCodes('&', this.s());
|
||||
}
|
||||
|
||||
public String getCat() {
|
||||
return cat;
|
||||
}
|
||||
}
|
@ -0,0 +1,251 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.StringComparison;
|
||||
|
||||
/**
|
||||
* Main Configuration Utility
|
||||
*
|
||||
* @author Empire92
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class Configuration {
|
||||
|
||||
public static final SettingValue<String> STRING = new SettingValue<String>("STRING") {
|
||||
@Override
|
||||
public boolean validateValue(final String string) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String parseString(final String string) {
|
||||
return string;
|
||||
}
|
||||
};
|
||||
public static final SettingValue<String[]> STRINGLIST = new SettingValue<String[]>("STRINGLIST") {
|
||||
@Override
|
||||
public boolean validateValue(final String string) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] parseString(final String string) {
|
||||
return string.split(",");
|
||||
}
|
||||
};
|
||||
public static final SettingValue<Integer> INTEGER = new SettingValue<Integer>("INTEGER") {
|
||||
@Override
|
||||
public boolean validateValue(final String string) {
|
||||
try {
|
||||
Integer.parseInt(string);
|
||||
return true;
|
||||
} catch (final Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer parseString(final String string) {
|
||||
return Integer.parseInt(string);
|
||||
}
|
||||
};
|
||||
public static final SettingValue<Boolean> BOOLEAN = new SettingValue<Boolean>("BOOLEAN") {
|
||||
@Override
|
||||
public boolean validateValue(final String string) {
|
||||
try {
|
||||
Boolean.parseBoolean(string);
|
||||
return true;
|
||||
} catch (final Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean parseString(final String string) {
|
||||
return Boolean.parseBoolean(string);
|
||||
}
|
||||
};
|
||||
public static final SettingValue<Double> DOUBLE = new SettingValue<Double>("DOUBLE") {
|
||||
@Override
|
||||
public boolean validateValue(final String string) {
|
||||
try {
|
||||
Double.parseDouble(string);
|
||||
return true;
|
||||
} catch (final Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double parseString(final String string) {
|
||||
return Double.parseDouble(string);
|
||||
}
|
||||
};
|
||||
public static final SettingValue<String> BIOME = new SettingValue<String>("BIOME") {
|
||||
@Override
|
||||
public boolean validateValue(final String string) {
|
||||
try {
|
||||
final int biome = BlockManager.manager.getBiomeFromString(string.toUpperCase());
|
||||
if (biome == -1) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} catch (final Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String parseString(final String string) {
|
||||
if (validateValue(string)) {
|
||||
return string.toUpperCase();
|
||||
}
|
||||
return "FOREST";
|
||||
}
|
||||
};
|
||||
public static final SettingValue<PlotBlock> BLOCK = new SettingValue<PlotBlock>("BLOCK") {
|
||||
@Override
|
||||
public boolean validateValue(final String string) {
|
||||
try {
|
||||
if (string.contains(":")) {
|
||||
final String[] split = string.split(":");
|
||||
Short.parseShort(split[0]);
|
||||
Short.parseShort(split[1]);
|
||||
} else {
|
||||
Short.parseShort(string);
|
||||
}
|
||||
return true;
|
||||
} catch (final Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotBlock parseString(final String string) {
|
||||
if (string.contains(":")) {
|
||||
final String[] split = string.split(":");
|
||||
return new PlotBlock(Short.parseShort(split[0]), Byte.parseByte(split[1]));
|
||||
} else {
|
||||
return new PlotBlock(Short.parseShort(string), (byte) 0);
|
||||
}
|
||||
}
|
||||
};
|
||||
public static final SettingValue<PlotBlock[]> BLOCKLIST = new SettingValue<PlotBlock[]>("BLOCKLIST") {
|
||||
@Override
|
||||
public boolean validateValue(final String string) {
|
||||
try {
|
||||
for (String block : string.split(",")) {
|
||||
if (block.contains("%")) {
|
||||
final String[] split = block.split("%");
|
||||
Integer.parseInt(split[0]);
|
||||
block = split[1];
|
||||
}
|
||||
StringComparison<PlotBlock>.ComparisonResult value = BlockManager.manager.getClosestBlock(block);
|
||||
if (value == null || value.match > 1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch (final Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotBlock[] parseString(final String string) {
|
||||
final String[] blocks = string.split(",");
|
||||
final ArrayList<PlotBlock> parsedvalues = new ArrayList<>();
|
||||
final PlotBlock[] values = new PlotBlock[blocks.length];
|
||||
final int[] counts = new int[blocks.length];
|
||||
int min = 100;
|
||||
for (int i = 0; i < blocks.length; i++) {
|
||||
try {
|
||||
if (blocks[i].contains("%")) {
|
||||
final String[] split = blocks[i].split("%");
|
||||
blocks[i] = split[1];
|
||||
final int value = Integer.parseInt(split[0]);
|
||||
counts[i] = value;
|
||||
if (value < min) {
|
||||
min = value;
|
||||
}
|
||||
} else {
|
||||
counts[i] = 1;
|
||||
if (1 < min) {
|
||||
min = 1;
|
||||
}
|
||||
}
|
||||
StringComparison<PlotBlock>.ComparisonResult result = BlockManager.manager.getClosestBlock(blocks[i]);
|
||||
if (result != null && result.match < 2) {
|
||||
values[i] = result.best;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {}
|
||||
}
|
||||
final int gcd = gcd(counts);
|
||||
for (int i = 0; i < counts.length; i++) {
|
||||
final int num = counts[i];
|
||||
for (int j = 0; j < (num / gcd); j++) {
|
||||
parsedvalues.add(values[i]);
|
||||
}
|
||||
}
|
||||
return parsedvalues.toArray(new PlotBlock[parsedvalues.size()]);
|
||||
}
|
||||
};
|
||||
|
||||
public static int gcd(final int a, final int b) {
|
||||
if (b == 0) {
|
||||
return a;
|
||||
}
|
||||
return gcd(b, a % b);
|
||||
}
|
||||
|
||||
private static int gcd(final int[] a) {
|
||||
int result = a[0];
|
||||
for (int i = 1; i < a.length; i++) {
|
||||
result = gcd(result, a[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create your own SettingValue object to make the management of plotworld configuration easier
|
||||
*/
|
||||
public static abstract class SettingValue<T> {
|
||||
private final String type;
|
||||
|
||||
public SettingValue(final String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public abstract T parseString(final String string);
|
||||
|
||||
public abstract boolean validateValue(final String string);
|
||||
}
|
||||
}
|
@ -0,0 +1,102 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.intellectualcrafters.plot.config.Configuration.SettingValue;
|
||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||
|
||||
/**
|
||||
* Configuration Node
|
||||
*
|
||||
* @author Empire92
|
||||
*/
|
||||
public class ConfigurationNode {
|
||||
private final String constant;
|
||||
private final Object default_value;
|
||||
private final String description;
|
||||
private final SettingValue type;
|
||||
private Object value;
|
||||
|
||||
public ConfigurationNode(final String constant, final Object default_value, final String description, final SettingValue type, final boolean required) {
|
||||
this.constant = constant;
|
||||
this.default_value = default_value;
|
||||
this.description = description;
|
||||
this.value = default_value;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public SettingValue getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public boolean isValid(final String string) {
|
||||
try {
|
||||
final Object result = this.type.parseString(string);
|
||||
return result != null;
|
||||
} catch (final Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean setValue(final String string) {
|
||||
if (!this.type.validateValue(string)) {
|
||||
return false;
|
||||
}
|
||||
this.value = this.type.parseString(string);
|
||||
return true;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
if (this.value instanceof String[]) {
|
||||
return Arrays.asList((String[]) this.value);
|
||||
} else if (this.value instanceof Object[]) {
|
||||
final List<String> values = new ArrayList<String>();
|
||||
for (final Object value : (Object[]) this.value) {
|
||||
values.add(value.toString());
|
||||
}
|
||||
return values;
|
||||
} else if (this.value instanceof PlotBlock) {
|
||||
return this.value.toString();
|
||||
}
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public String getConstant() {
|
||||
return this.constant;
|
||||
}
|
||||
|
||||
public Object getDefaultValue() {
|
||||
if (this.default_value instanceof Object[]) {
|
||||
return StringUtils.join((Object[]) this.default_value, ",");
|
||||
}
|
||||
return this.default_value;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
}
|
243
src/main/java/com/intellectualcrafters/plot/config/Settings.java
Normal file
243
src/main/java/com/intellectualcrafters/plot/config/Settings.java
Normal file
@ -0,0 +1,243 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Updater and DB settings
|
||||
*
|
||||
* @author Citymonstret
|
||||
* @author Empire92
|
||||
*/
|
||||
public class Settings {
|
||||
public static boolean ENABLE_CLUSTERS = false;
|
||||
public static boolean FAST_CLEAR = false;
|
||||
/**
|
||||
* Default UUID_FECTHING: false
|
||||
*/
|
||||
public static boolean PERMISSION_CACHING = false;
|
||||
public static boolean CACHE_RATINGS = true;
|
||||
public static boolean UUID_FROM_DISK = false;
|
||||
|
||||
/**
|
||||
* Web
|
||||
*/
|
||||
public static String WEB_URL = "http://empcraft.com/plots/";
|
||||
public static String WEB_IP = "your.ip.here";
|
||||
|
||||
/**
|
||||
* Ratings
|
||||
*/
|
||||
public static List<String> RATING_CATEGORIES = null;
|
||||
/**
|
||||
* PlotMe settings
|
||||
*/
|
||||
public static boolean CONVERT_PLOTME = true;
|
||||
public static boolean CACHE_PLOTME = false;
|
||||
public static boolean USE_PLOTME_ALIAS = false;
|
||||
/**
|
||||
* Comment system
|
||||
*/
|
||||
public static boolean COMMENT_NOTIFICATIONS = false;
|
||||
/**
|
||||
* Chunk processor
|
||||
*/
|
||||
public static boolean CHUNK_PROCESSOR = false;
|
||||
public static int CHUNK_PROCESSOR_MAX_BLOCKSTATES = 4096;
|
||||
public static int CHUNK_PROCESSOR_MAX_ENTITIES = 512;
|
||||
/**
|
||||
* TNT listener
|
||||
*/
|
||||
public static boolean TNT_LISTENER = false;
|
||||
/**
|
||||
* Redstone disabler
|
||||
*/
|
||||
public static boolean REDSTONE_DISABLER = false;
|
||||
/**
|
||||
* Check for falling blocks when pistons extend?
|
||||
*/
|
||||
public static boolean PISTON_FALLING_BLOCK_CHECK = true;
|
||||
/**
|
||||
* Max auto claiming size
|
||||
*/
|
||||
public static int MAX_AUTO_SIZE = 4;
|
||||
/**
|
||||
* Default worldedit-require-selection-in-mask: false
|
||||
*/
|
||||
public static boolean REQUIRE_SELECTION = true;
|
||||
public static boolean WE_ALLOW_HELPER = false;
|
||||
public static long WE_MAX_VOLUME = 500000;
|
||||
public static long WE_MAX_ITERATIONS = 1000;
|
||||
public static List<String> WE_BLACKLIST = new ArrayList<>();
|
||||
/**
|
||||
* Default kill road mobs: true
|
||||
*/
|
||||
public final static boolean KILL_ROAD_MOBS_DEFAULT = false;
|
||||
/**
|
||||
* Default mob pathfinding: true
|
||||
*/
|
||||
public final static boolean MOB_PATHFINDING_DEFAULT = true;
|
||||
/**
|
||||
* Teleport to path on login
|
||||
*/
|
||||
public static boolean TELEPORT_ON_LOGIN = false;
|
||||
/**
|
||||
* Display titles
|
||||
*/
|
||||
public static boolean TITLES = true;
|
||||
/**
|
||||
* Schematic Save Path
|
||||
*/
|
||||
public static String SCHEMATIC_SAVE_PATH = "/var/www/schematics";
|
||||
/**
|
||||
* Max allowed plots
|
||||
*/
|
||||
public static int MAX_PLOTS = 127;
|
||||
/**
|
||||
* WorldGuard region on claimed plots
|
||||
*/
|
||||
public static boolean WORLDGUARD = false;
|
||||
/**
|
||||
* metrics
|
||||
*/
|
||||
public static boolean METRICS = true;
|
||||
/**
|
||||
* plot specific resource pack
|
||||
*/
|
||||
public static String PLOT_SPECIFIC_RESOURCE_PACK = "";
|
||||
/**
|
||||
* Kill road mobs?
|
||||
*/
|
||||
public static boolean KILL_ROAD_MOBS;
|
||||
/**
|
||||
* mob pathfinding?
|
||||
*/
|
||||
public static boolean MOB_PATHFINDING;
|
||||
/**
|
||||
* Delete plots on ban?
|
||||
*/
|
||||
public static boolean DELETE_PLOTS_ON_BAN = false;
|
||||
/**
|
||||
* Verbose?
|
||||
*/
|
||||
public static boolean DEBUG = true;
|
||||
/**
|
||||
* Have colored console messages?
|
||||
*/
|
||||
public static boolean CONSOLE_COLOR = true;
|
||||
/**
|
||||
* Fancy chat e.g. for /plot list
|
||||
*/
|
||||
public static boolean FANCY_CHAT = true;
|
||||
/**
|
||||
* The delay (in seconds) before teleportation commences
|
||||
*/
|
||||
public static int TELEPORT_DELAY;
|
||||
/**
|
||||
* Auto clear enabled
|
||||
*/
|
||||
public static boolean AUTO_CLEAR = false;
|
||||
/**
|
||||
* Days until a plot gets cleared
|
||||
*/
|
||||
public static int AUTO_CLEAR_DAYS = 360;
|
||||
public static boolean AUTO_CLEAR_CHECK_DISK = false;
|
||||
public static int MIN_BLOCKS_CHANGED = -1;
|
||||
public static int MIN_BLOCKS_CHANGED_IGNORED = -1;
|
||||
public static int CLEAR_INTERVAL = 120;
|
||||
/**
|
||||
* API Location
|
||||
*/
|
||||
public static String API_URL = "http://www.intellectualsites.com/minecraft.php";
|
||||
/**
|
||||
* Use the custom API
|
||||
*/
|
||||
public static boolean CUSTOM_API = true;
|
||||
/**
|
||||
* Use offline mode storage
|
||||
*/
|
||||
public static boolean TWIN_MODE_UUID = false;
|
||||
public static boolean OFFLINE_MODE = false;
|
||||
public static boolean UUID_LOWERCASE = false;
|
||||
/**
|
||||
* Command confirmation
|
||||
*/
|
||||
public static boolean CONFIRM_CLEAR = true;
|
||||
public static boolean CONFIRM_DELETE = true;
|
||||
public static boolean CONFIRM_UNLINK = true;
|
||||
/**
|
||||
* Use global plot limit?
|
||||
*/
|
||||
public static boolean GLOBAL_LIMIT = false;
|
||||
|
||||
/**
|
||||
* Database settings
|
||||
*
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public static class DB {
|
||||
/**
|
||||
* MongoDB enabled?
|
||||
*/
|
||||
public static boolean USE_MONGO = false; /*
|
||||
* TODO: Implement Mongo
|
||||
* @Brandon
|
||||
*/
|
||||
/**
|
||||
* SQLite enabled?
|
||||
*/
|
||||
public static boolean USE_SQLITE = false;
|
||||
/**
|
||||
* MySQL Enabled?
|
||||
*/
|
||||
public static boolean USE_MYSQL = true; /* NOTE: Fixed connector */
|
||||
/**
|
||||
* SQLite Database name
|
||||
*/
|
||||
public static String SQLITE_DB = "storage";
|
||||
/**
|
||||
* MySQL Host name
|
||||
*/
|
||||
public static String HOST_NAME = "localhost";
|
||||
/**
|
||||
* MySQL Port
|
||||
*/
|
||||
public static String PORT = "3306";
|
||||
/**
|
||||
* MySQL DB
|
||||
*/
|
||||
public static String DATABASE = "plot_db";
|
||||
/**
|
||||
* MySQL User
|
||||
*/
|
||||
public static String USER = "root";
|
||||
/**
|
||||
* MySQL Password
|
||||
*/
|
||||
public static String PASSWORD = "password";
|
||||
/**
|
||||
* MySQL Prefix
|
||||
*/
|
||||
public static String PREFIX = "";
|
||||
}
|
||||
}
|
@ -0,0 +1,347 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.database;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotCluster;
|
||||
import com.intellectualcrafters.plot.object.PlotClusterId;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
||||
import com.intellectualcrafters.plot.object.comment.PlotComment;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
* @author Empire92
|
||||
*/
|
||||
public interface AbstractDB {
|
||||
// TODO MongoDB @Brandon
|
||||
/**
|
||||
* The UUID that will count as everyone
|
||||
*/
|
||||
public UUID everyone = UUID.fromString("1-1-3-3-7");
|
||||
|
||||
/**
|
||||
* Set Plot owner
|
||||
*
|
||||
* @param plot Plot in which the owner should be set
|
||||
* @param uuid The uuid of the new owner
|
||||
*/
|
||||
public void setOwner(final Plot plot, final UUID uuid);
|
||||
|
||||
/**
|
||||
* Create all settings, and create default helpers, trusted + denied lists
|
||||
*
|
||||
* @param plots Plots for which the default table entries should be created
|
||||
*/
|
||||
public void createPlotsAndData(final ArrayList<Plot> plots, Runnable whenDone);
|
||||
|
||||
/**
|
||||
* Create a plot
|
||||
*
|
||||
* @param plot That should be created
|
||||
*/
|
||||
public void createPlot(final Plot plot);
|
||||
|
||||
/**
|
||||
* Create tables
|
||||
*
|
||||
* @param database Database in which the tables will be created
|
||||
*
|
||||
* @throws SQLException If the database manager is unable to create the tables
|
||||
*/
|
||||
public void createTables(final String database) throws Exception;
|
||||
|
||||
/**
|
||||
* Delete a plot
|
||||
*
|
||||
* @param plot Plot that should be deleted
|
||||
*/
|
||||
public void delete(final Plot plot);
|
||||
|
||||
public void delete(final PlotCluster cluster);
|
||||
|
||||
/**
|
||||
* Create plot settings
|
||||
*
|
||||
* @param id Plot Entry ID
|
||||
* @param plot Plot Object
|
||||
*/
|
||||
public void createPlotSettings(final int id, final Plot plot);
|
||||
|
||||
/**
|
||||
* Get the table entry ID
|
||||
*
|
||||
* @param world Which the plot is located in
|
||||
* @param id2 Plot ID
|
||||
*
|
||||
* @return Integer = Plot Entry Id
|
||||
*/
|
||||
public int getId(final String world, final PlotId id2);
|
||||
|
||||
/**
|
||||
* Get the id of a given plot cluster
|
||||
*
|
||||
* @param world Which the plot is located in
|
||||
* @param id cluster id
|
||||
*
|
||||
* @return Integer = Cluster Entry Id
|
||||
*/
|
||||
public int getClusterId(final String world, final PlotClusterId id);
|
||||
|
||||
/**
|
||||
* @return A linked hashmap containing all plots
|
||||
*/
|
||||
public LinkedHashMap<String, HashMap<PlotId, Plot>> getPlots();
|
||||
|
||||
/**
|
||||
* @return A hashmap containing all plot clusters
|
||||
*/
|
||||
public HashMap<String, HashSet<PlotCluster>> getClusters();
|
||||
|
||||
/**
|
||||
* Set the merged status for a plot
|
||||
*
|
||||
* @param world World in which the plot is located
|
||||
* @param plot Plot Object
|
||||
* @param merged boolean[]
|
||||
*/
|
||||
public void setMerged(final Plot plot, final boolean[] merged);
|
||||
|
||||
/**
|
||||
* Swap the settings, helpers etc. of two plots
|
||||
* @param p1 Plot1
|
||||
* @param p2 Plot2
|
||||
*/
|
||||
public void swapPlots(final Plot p1, final Plot p2);
|
||||
|
||||
/**
|
||||
* Set plot flags
|
||||
*
|
||||
* @param world World in which the plot is located
|
||||
* @param plot Plot Object
|
||||
* @param flags flags to set (flag[])
|
||||
*/
|
||||
public void setFlags(final Plot plot, final Collection<Flag> flags);
|
||||
|
||||
/**
|
||||
* Set cluster flags
|
||||
*
|
||||
* @param cluster PlotCluster Object
|
||||
* @param flags flags to set (flag[])
|
||||
*/
|
||||
public void setFlags(final PlotCluster cluster, final Collection<Flag> flags);
|
||||
|
||||
/**
|
||||
* Rename a cluster
|
||||
*/
|
||||
public void setClusterName(final PlotCluster cluster, final String name);
|
||||
|
||||
/**
|
||||
* Set the plot alias
|
||||
*
|
||||
* @param plot Plot for which the alias should be set
|
||||
* @param alias Plot Alias
|
||||
*/
|
||||
public void setAlias(final Plot plot, final String alias);
|
||||
|
||||
/**
|
||||
* Purgle a plot
|
||||
*
|
||||
* @param world World in which the plot is located
|
||||
* @param uniqueIds list of plot id (db) to be purged
|
||||
*/
|
||||
public void purgeIds(final String world, final Set<Integer> uniqueIds);
|
||||
|
||||
/**
|
||||
* Purge a whole world
|
||||
*
|
||||
* @param world World in which the plots should be purged
|
||||
*/
|
||||
public void purge(final String world, final Set<PlotId> plotIds);
|
||||
|
||||
/**
|
||||
* Set Plot Home Position
|
||||
*
|
||||
* @param plot Plot Object
|
||||
* @param position Plot Home Position
|
||||
*/
|
||||
public void setPosition(final Plot plot, final String position);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param cluster
|
||||
* @param position
|
||||
*/
|
||||
public void setPosition(final PlotCluster cluster, final String position);
|
||||
|
||||
/**
|
||||
* @param id Plot Entry ID
|
||||
*
|
||||
* @return Plot Settings
|
||||
*/
|
||||
public HashMap<String, Object> getSettings(final int id);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id
|
||||
* @return HashMap<String, Object>
|
||||
*/
|
||||
public HashMap<String, Object> getClusterSettings(final int id);
|
||||
|
||||
/**
|
||||
* @param plot Plot Object
|
||||
* @param uuid Player that should be removed
|
||||
*/
|
||||
public void removeTrusted(final Plot plot, final UUID uuid);
|
||||
|
||||
/**
|
||||
* @param cluster PlotCluster Object
|
||||
* @param uuid Player that should be removed
|
||||
*/
|
||||
public void removeHelper(final PlotCluster cluster, final UUID uuid);
|
||||
|
||||
/**
|
||||
* @param plot Plot Object
|
||||
* @param uuid Player that should be removed
|
||||
*/
|
||||
public void removeMember(final Plot plot, final UUID uuid);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param cluster
|
||||
* @param uuid
|
||||
*/
|
||||
public void removeInvited(final PlotCluster cluster, final UUID uuid);
|
||||
|
||||
/**
|
||||
* @param plot Plot Object
|
||||
* @param uuid Player that should be removed
|
||||
*/
|
||||
public void setTrusted(final Plot plot, final UUID uuid);
|
||||
|
||||
/**
|
||||
* @param cluster PlotCluster Object
|
||||
* @param uuid Player that should be removed
|
||||
*/
|
||||
public void setHelper(final PlotCluster cluster, final UUID uuid);
|
||||
|
||||
/**
|
||||
* @param plot Plot Object
|
||||
* @param uuid Player that should be added
|
||||
*/
|
||||
public void setMember(final Plot plot, final UUID uuid);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param world
|
||||
* @param cluster
|
||||
* @param uuid
|
||||
*/
|
||||
public void setInvited(final PlotCluster cluster, final UUID uuid);
|
||||
|
||||
/**
|
||||
* @param plot Plot Object
|
||||
* @param uuid Player uuid
|
||||
*/
|
||||
public void removeDenied(final Plot plot, final UUID uuid);
|
||||
|
||||
/**
|
||||
* @param plot Plot Object
|
||||
* @param uuid Player uuid that should be added
|
||||
*/
|
||||
public void setDenied(final Plot plot, final UUID uuid);
|
||||
|
||||
/**
|
||||
* Get Plots ratings
|
||||
*
|
||||
* @param plot Plot Object
|
||||
*
|
||||
* @return Plot Ratings (pre-calculated)
|
||||
*/
|
||||
public HashMap<UUID, Integer> getRatings(final Plot plot);
|
||||
|
||||
/**
|
||||
* Set a rating for a plot
|
||||
* @param plot
|
||||
* @param rater
|
||||
* @param value
|
||||
*/
|
||||
public void setRating(final Plot plot, UUID rater, int value);
|
||||
|
||||
/**
|
||||
* Remove a plot comment
|
||||
*
|
||||
* @param world World in which the plot is located
|
||||
* @param plot Plot Object
|
||||
* @param comment Comment to remove
|
||||
*/
|
||||
public void removeComment(final Plot plot, final PlotComment comment);
|
||||
|
||||
/**
|
||||
* Clear an inbox
|
||||
* @param plot
|
||||
* @param inbox
|
||||
*/
|
||||
public void clearInbox(Plot plot, String inbox);
|
||||
|
||||
/**
|
||||
* Set a plot comment
|
||||
*
|
||||
* @param world World in which the plot is located
|
||||
* @param plot Plot Object
|
||||
* @param comment Comment to add
|
||||
*/
|
||||
public void setComment(final Plot plot, final PlotComment comment);
|
||||
|
||||
/**
|
||||
* Get Plot Comments
|
||||
*
|
||||
* @param world World in which the plot is located
|
||||
* @param plot Plot Object
|
||||
* @param tier Comment Tier
|
||||
*
|
||||
* @return Plot Comments within the specified tier
|
||||
*/
|
||||
public void getComments(final Plot plot, final String inbox, RunnableVal whenDone);
|
||||
|
||||
public void createPlotAndSettings(Plot plot);
|
||||
|
||||
public void createCluster(PlotCluster cluster);
|
||||
|
||||
public void resizeCluster(PlotCluster current, PlotClusterId resize);
|
||||
|
||||
public void movePlot(Plot originalPlot, Plot newPlot);
|
||||
|
||||
/**
|
||||
* Don't fuck with this one, unless you enjoy it rough
|
||||
*/
|
||||
public boolean deleteTables();
|
||||
}
|
431
src/main/java/com/intellectualcrafters/plot/database/DBFunc.java
Normal file
431
src/main/java/com/intellectualcrafters/plot/database/DBFunc.java
Normal file
@ -0,0 +1,431 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.database;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.ResultSetMetaData;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotCluster;
|
||||
import com.intellectualcrafters.plot.object.PlotClusterId;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
||||
import com.intellectualcrafters.plot.object.comment.PlotComment;
|
||||
|
||||
/**
|
||||
* DB Functions
|
||||
*
|
||||
* @author Empire92
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class DBFunc {
|
||||
/**
|
||||
* The "global" uuid
|
||||
*/
|
||||
public static final UUID everyone = UUID.fromString("1-1-3-3-7");
|
||||
/**
|
||||
* Abstract Database Manager
|
||||
*/
|
||||
public static AbstractDB dbManager;
|
||||
|
||||
public static void movePlot(final Plot originalPlot, final Plot newPlot) {
|
||||
if (originalPlot.temp || newPlot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.movePlot(originalPlot, newPlot);
|
||||
}
|
||||
/**
|
||||
* Check if a resultset contains a column
|
||||
* @param rs
|
||||
* @param columnName
|
||||
* @return
|
||||
* @throws SQLException
|
||||
*/
|
||||
public static boolean hasColumn(ResultSet r, String name) {
|
||||
try {
|
||||
ResultSetMetaData meta = r.getMetaData();
|
||||
int count = meta.getColumnCount();
|
||||
for (int x = 1; x <= count; x++) {
|
||||
if (name.equals(meta.getColumnName(x))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
catch (SQLException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Set the owner of a plot
|
||||
*
|
||||
* @param plot Plot Object
|
||||
* @param uuid New Owner
|
||||
*/
|
||||
public static void setOwner(final Plot plot, final UUID uuid) {
|
||||
if (plot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.setOwner(plot, uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create all settings + (trusted, denied, members)
|
||||
*
|
||||
* @param plots List containing all plot objects
|
||||
*/
|
||||
public static void createPlotsAndData(final ArrayList<Plot> plots, Runnable whenDone) {
|
||||
dbManager.createPlotsAndData(plots, whenDone);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a plot
|
||||
*
|
||||
* @param plot Plot to create
|
||||
*/
|
||||
public static void createPlot(final Plot plot) {
|
||||
if (plot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.createPlot(plot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a plot
|
||||
*
|
||||
* @param plot Plot to create
|
||||
*/
|
||||
public static void createPlotAndSettings(final Plot plot) {
|
||||
if (plot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.createPlotAndSettings(plot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create tables
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void createTables(final String database) throws Exception {
|
||||
dbManager.createTables(database);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a plot
|
||||
*
|
||||
* @param plot Plot to delete
|
||||
*/
|
||||
public static void delete(final Plot plot) {
|
||||
if (plot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.delete(plot);
|
||||
}
|
||||
|
||||
public static void delete(final PlotCluster toDelete) {
|
||||
dbManager.delete(toDelete);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create plot settings
|
||||
*
|
||||
* @param id Plot ID
|
||||
* @param plot Plot Object
|
||||
*/
|
||||
public static void createPlotSettings(final int id, final Plot plot) {
|
||||
if (plot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.createPlotSettings(id, plot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a plot id
|
||||
*
|
||||
* @param world World
|
||||
* @param id2 Plot ID
|
||||
*
|
||||
* @return ID
|
||||
*/
|
||||
/*
|
||||
* public static int getId(String plotId id2) { Statement stmt =
|
||||
* null; try { stmt = connection.createStatement(); ResultSet r =
|
||||
* stmt.executeQuery("SELECT `id` FROM `plot` WHERE `plot_id_x` = '" + id2.x
|
||||
* + "' AND `plot_id_z` = '" + id2.y + "' AND `world` = '" + world +
|
||||
* "' ORDER BY `timestamp` ASC"); int id = Integer.MAX_VALUE;
|
||||
* while(r.next()) { id = r.getInt("id"); } stmt.close(); return id; }
|
||||
* catch(SQLException e) { e.printStackTrace(); } return Integer.MAX_VALUE;
|
||||
* }
|
||||
*/
|
||||
public static int getId(final String world, final PlotId id2) {
|
||||
return dbManager.getId(world, id2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Plots
|
||||
*/
|
||||
public static LinkedHashMap<String, HashMap<PlotId, Plot>> getPlots() {
|
||||
return dbManager.getPlots();
|
||||
}
|
||||
|
||||
public static void setMerged(final Plot plot, final boolean[] merged) {
|
||||
if (plot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.setMerged(plot, merged);
|
||||
}
|
||||
|
||||
public static void setFlags(final Plot plot, final Collection<Flag> flags) {
|
||||
if (plot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.setFlags(plot, flags);
|
||||
}
|
||||
|
||||
public static void setFlags(final PlotCluster cluster, final Collection<Flag> flags) {
|
||||
dbManager.setFlags(cluster, flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param plot
|
||||
* @param alias
|
||||
*/
|
||||
public static void setAlias(final Plot plot, final String alias) {
|
||||
if (plot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.setAlias(plot, alias);
|
||||
}
|
||||
|
||||
public static void purgeIds(final String world, final Set<Integer> uniqueIds) {
|
||||
dbManager.purgeIds(world, uniqueIds);
|
||||
}
|
||||
|
||||
public static void purge(final String world, final Set<PlotId> plotIds) {
|
||||
dbManager.purge(world, plotIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param plot
|
||||
* @param position
|
||||
*/
|
||||
public static void setPosition(final Plot plot, final String position) {
|
||||
if (plot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.setPosition(plot, position);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id
|
||||
* @return HashMap<String, Object>
|
||||
*/
|
||||
public static HashMap<String, Object> getSettings(final int id) {
|
||||
return dbManager.getSettings(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param plot
|
||||
* @param comment
|
||||
*/
|
||||
public static void removeComment(final Plot plot, final PlotComment comment) {
|
||||
if (plot != null && plot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.removeComment(plot, comment);
|
||||
}
|
||||
|
||||
public static void clearInbox(final Plot plot, final String inbox) {
|
||||
if (plot != null && plot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.clearInbox(plot, inbox);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param plot
|
||||
* @param comment
|
||||
*/
|
||||
public static void setComment(final Plot plot, final PlotComment comment) {
|
||||
if (plot != null && plot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.setComment(plot, comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param plot
|
||||
*/
|
||||
public static void getComments(final Plot plot, final String inbox, RunnableVal whenDone) {
|
||||
if (plot != null && plot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.getComments(plot, inbox, whenDone);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param plot
|
||||
* @param uuid
|
||||
*/
|
||||
public static void removeTrusted(final Plot plot, final UUID uuid) {
|
||||
if (plot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.removeTrusted(plot, uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cluster
|
||||
* @param uuid
|
||||
*/
|
||||
public static void removeHelper(final PlotCluster cluster, final UUID uuid) {
|
||||
dbManager.removeHelper(cluster, uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param world
|
||||
* @param cluster
|
||||
*/
|
||||
public static void createCluster(final String world, final PlotCluster cluster) {
|
||||
dbManager.createCluster(cluster);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param current
|
||||
* @param resize
|
||||
*/
|
||||
public static void resizeCluster(final PlotCluster current, final PlotClusterId resize) {
|
||||
dbManager.resizeCluster(current, resize);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param plot
|
||||
* @param uuid
|
||||
*/
|
||||
public static void removeMember(final Plot plot, final UUID uuid) {
|
||||
if (plot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.removeMember(plot, uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param cluster
|
||||
* @param uuid
|
||||
*/
|
||||
public static void removeInvited(final PlotCluster cluster, final UUID uuid) {
|
||||
dbManager.removeInvited(cluster, uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param world
|
||||
* @param plot
|
||||
* @param uuid
|
||||
*/
|
||||
public static void setTrusted(final Plot plot, final UUID uuid) {
|
||||
if (plot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.setTrusted(plot, uuid);
|
||||
}
|
||||
|
||||
public static void setHelper(final PlotCluster cluster, final UUID uuid) {
|
||||
dbManager.setHelper(cluster, uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param world
|
||||
* @param plot
|
||||
* @param uuid
|
||||
*/
|
||||
public static void setMember(final Plot plot, final UUID uuid) {
|
||||
if (plot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.setMember(plot, uuid);
|
||||
}
|
||||
|
||||
public static void setInvited(final String world, final PlotCluster cluster, final UUID uuid) {
|
||||
dbManager.setInvited(cluster, uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param world
|
||||
* @param plot
|
||||
* @param uuid
|
||||
*/
|
||||
public static void removeDenied(final Plot plot, final UUID uuid) {
|
||||
if (plot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.removeDenied(plot, uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param world
|
||||
* @param plot
|
||||
* @param uuid
|
||||
*/
|
||||
public static void setDenied(final Plot plot, final UUID uuid) {
|
||||
if (plot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.setDenied(plot, uuid);
|
||||
}
|
||||
|
||||
public static HashMap<UUID, Integer> getRatings(final Plot plot) {
|
||||
if (plot.temp) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
return dbManager.getRatings(plot);
|
||||
}
|
||||
|
||||
public static void setRating(Plot plot, UUID rater, int value) {
|
||||
if (plot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.setRating(plot, rater, value);
|
||||
}
|
||||
|
||||
public static HashMap<String, HashSet<PlotCluster>> getClusters() {
|
||||
return dbManager.getClusters();
|
||||
}
|
||||
|
||||
public static void setPosition(final PlotCluster cluster, final String position) {
|
||||
dbManager.setPosition(cluster, position);
|
||||
}
|
||||
|
||||
public static HashMap<String, Object> getClusterSettings(final int id) {
|
||||
return dbManager.getClusterSettings(id);
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.database;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Abstract Database class, serves as a base for any connection method (MySQL, SQLite, etc.)
|
||||
*
|
||||
* @author -_Husky_-
|
||||
* @author tips48
|
||||
*/
|
||||
public abstract class Database {
|
||||
|
||||
public abstract Connection forceConnection() throws SQLException, ClassNotFoundException ;
|
||||
|
||||
/**
|
||||
* Opens a connection with the database
|
||||
*
|
||||
* @return Opened connection
|
||||
*
|
||||
* @throws SQLException if the connection can not be opened
|
||||
* @throws ClassNotFoundException if the driver cannot be found
|
||||
*/
|
||||
public abstract Connection openConnection() throws SQLException, ClassNotFoundException;
|
||||
|
||||
/**
|
||||
* Checks if a connection is open with the database
|
||||
*
|
||||
* @return true if the connection is open
|
||||
*
|
||||
* @throws SQLException if the connection cannot be checked
|
||||
*/
|
||||
public abstract boolean checkConnection() throws SQLException;
|
||||
|
||||
/**
|
||||
* Gets the connection with the database
|
||||
*
|
||||
* @return Connection with the database, null if none
|
||||
*/
|
||||
public abstract Connection getConnection();
|
||||
|
||||
/**
|
||||
* Closes the connection with the database
|
||||
*
|
||||
* @return true if successful
|
||||
*
|
||||
* @throws SQLException if the connection cannot be closed
|
||||
*/
|
||||
public abstract boolean closeConnection() throws SQLException;
|
||||
|
||||
/**
|
||||
* Executes a SQL Query<br> If the connection is closed, it will be opened
|
||||
*
|
||||
* @param query Query to be run
|
||||
*
|
||||
* @return the results of the query
|
||||
*
|
||||
* @throws SQLException If the query cannot be executed
|
||||
* @throws ClassNotFoundException If the driver cannot be found; see {@link #openConnection()}
|
||||
*/
|
||||
public abstract ResultSet querySQL(final String query) throws SQLException, ClassNotFoundException;
|
||||
|
||||
/**
|
||||
* Executes an Update SQL Query<br> See {@link java.sql.Statement#executeUpdate(String)}<br> If the connection is
|
||||
* closed, it will be opened
|
||||
*
|
||||
* @param query Query to be run
|
||||
*
|
||||
* @return Result Code, see {@link java.sql.Statement#executeUpdate(String)}
|
||||
*
|
||||
* @throws SQLException If the query cannot be executed
|
||||
* @throws ClassNotFoundException If the driver cannot be found; see {@link #openConnection()}
|
||||
*/
|
||||
public abstract int updateSQL(final String query) throws SQLException, ClassNotFoundException;
|
||||
}
|
113
src/main/java/com/intellectualcrafters/plot/database/MySQL.java
Normal file
113
src/main/java/com/intellectualcrafters/plot/database/MySQL.java
Normal file
@ -0,0 +1,113 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.database;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
/**
|
||||
* Connects to and uses a MySQL database
|
||||
*
|
||||
* @author -_Husky_-
|
||||
* @author tips48
|
||||
*/
|
||||
public class MySQL extends Database {
|
||||
private final String user;
|
||||
private final String database;
|
||||
private final String password;
|
||||
private final String port;
|
||||
private final String hostname;
|
||||
private Connection connection;
|
||||
|
||||
/**
|
||||
* Creates a new MySQL instance
|
||||
*
|
||||
* @param hostname Name of the host
|
||||
* @param port Port number
|
||||
* @param database Database name
|
||||
* @param username Username
|
||||
* @param password Password
|
||||
*/
|
||||
public MySQL(final String hostname, final String port, final String database, final String username, final String password) {
|
||||
this.hostname = hostname;
|
||||
this.port = port;
|
||||
this.database = database;
|
||||
this.user = username;
|
||||
this.password = password;
|
||||
this.connection = null;
|
||||
}
|
||||
|
||||
public Connection forceConnection() throws SQLException, ClassNotFoundException {
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
this.connection = DriverManager.getConnection("jdbc:mysql://" + this.hostname + ":" + this.port + "/" + this.database, this.user, this.password);
|
||||
return this.connection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection openConnection() throws SQLException, ClassNotFoundException {
|
||||
if (checkConnection()) {
|
||||
return this.connection;
|
||||
}
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
this.connection = DriverManager.getConnection("jdbc:mysql://" + this.hostname + ":" + this.port + "/" + this.database, this.user, this.password);
|
||||
return this.connection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkConnection() throws SQLException {
|
||||
return (this.connection != null) && !this.connection.isClosed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getConnection() {
|
||||
return this.connection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean closeConnection() throws SQLException {
|
||||
if (this.connection == null) {
|
||||
return false;
|
||||
}
|
||||
this.connection.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultSet querySQL(final String query) throws SQLException, ClassNotFoundException {
|
||||
if (checkConnection()) {
|
||||
openConnection();
|
||||
}
|
||||
final Statement statement = this.connection.createStatement();
|
||||
return statement.executeQuery(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateSQL(final String query) throws SQLException, ClassNotFoundException {
|
||||
if (checkConnection()) {
|
||||
openConnection();
|
||||
}
|
||||
final Statement statement = this.connection.createStatement();
|
||||
return statement.executeUpdate(query);
|
||||
}
|
||||
}
|
2258
src/main/java/com/intellectualcrafters/plot/database/SQLManager.java
Normal file
2258
src/main/java/com/intellectualcrafters/plot/database/SQLManager.java
Normal file
File diff suppressed because it is too large
Load Diff
116
src/main/java/com/intellectualcrafters/plot/database/SQLite.java
Normal file
116
src/main/java/com/intellectualcrafters/plot/database/SQLite.java
Normal file
@ -0,0 +1,116 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.database;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
|
||||
/**
|
||||
* Connects to and uses a SQLite database
|
||||
*
|
||||
* @author Citymonstret
|
||||
* @author tips48
|
||||
*/
|
||||
public class SQLite extends Database {
|
||||
private final String dbLocation;
|
||||
private Connection connection;
|
||||
|
||||
/**
|
||||
* Creates a new SQLite instance
|
||||
*
|
||||
* @param dbLocation Location of the Database (Must end in .db)
|
||||
*/
|
||||
public SQLite(final String dbLocation) {
|
||||
this.dbLocation = dbLocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection openConnection() throws SQLException, ClassNotFoundException {
|
||||
if (checkConnection()) {
|
||||
return this.connection;
|
||||
}
|
||||
if (!PS.get().IMP.getDirectory().exists()) {
|
||||
PS.get().IMP.getDirectory().mkdirs();
|
||||
}
|
||||
final File file = new File(this.dbLocation);
|
||||
if (!(file.exists())) {
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (final IOException e) {
|
||||
PS.log("&cUnable to create database!");
|
||||
}
|
||||
}
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
this.connection = DriverManager.getConnection("jdbc:sqlite:" + this.dbLocation);
|
||||
return this.connection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkConnection() throws SQLException {
|
||||
return (this.connection != null) && !this.connection.isClosed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getConnection() {
|
||||
return this.connection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean closeConnection() throws SQLException {
|
||||
if (this.connection == null) {
|
||||
return false;
|
||||
}
|
||||
this.connection.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultSet querySQL(final String query) throws SQLException, ClassNotFoundException {
|
||||
if (checkConnection()) {
|
||||
openConnection();
|
||||
}
|
||||
final Statement statement = this.connection.createStatement();
|
||||
return statement.executeQuery(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateSQL(final String query) throws SQLException, ClassNotFoundException {
|
||||
if (checkConnection()) {
|
||||
openConnection();
|
||||
}
|
||||
final Statement statement = this.connection.createStatement();
|
||||
return statement.executeUpdate(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection forceConnection() throws SQLException, ClassNotFoundException {
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
this.connection = DriverManager.getConnection("jdbc:sqlite:" + this.dbLocation);
|
||||
return this.connection;
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.intellectualcrafters.plot.database;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
public abstract class StmtMod<T> {
|
||||
public abstract String getCreateMySQL(int size);
|
||||
|
||||
public String getCreateMySQL(int size, String query, int params) {
|
||||
final StringBuilder statement = new StringBuilder(query);
|
||||
for (int i = 0; i < size - 1; i++) {
|
||||
statement.append("(" + StringUtils.repeat(",(?)", params).substring(1) + "),");
|
||||
}
|
||||
statement.append("(" + StringUtils.repeat(",(?)", params).substring(1) + ")");
|
||||
return statement.toString();
|
||||
}
|
||||
|
||||
public String getCreateSQLite(int size, String query, int params) {
|
||||
StringBuilder statement = new StringBuilder(query);
|
||||
String modParams = StringUtils.repeat(",?", params).substring(1);
|
||||
for (int i = 0; i < (size - 1); i++) {
|
||||
statement.append("UNION SELECT " + modParams + " ");
|
||||
}
|
||||
return statement.toString();
|
||||
}
|
||||
|
||||
public abstract String getCreateSQLite(int size);
|
||||
public abstract String getCreateSQL();
|
||||
|
||||
public abstract void setMySQL(PreparedStatement stmt, int i, T obj) throws SQLException;
|
||||
public abstract void setSQLite(PreparedStatement stmt, int i, T obj) throws SQLException;
|
||||
public abstract void setSQL(PreparedStatement stmt, T obj) throws SQLException;
|
||||
}
|
@ -0,0 +1,117 @@
|
||||
package com.intellectualcrafters.plot.database.plotme;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
|
||||
import com.intellectualcrafters.configuration.file.FileConfiguration;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
|
||||
public abstract class APlotMeConnector {
|
||||
public abstract Connection getPlotMeConnection(String plugin, FileConfiguration plotConfig, String dataFolder);
|
||||
|
||||
public abstract HashMap<String, HashMap<PlotId, Plot>> getPlotMePlots(Connection connection) throws SQLException;
|
||||
|
||||
public abstract boolean accepts(String version);
|
||||
|
||||
public String getWorld(final String world) {
|
||||
for (final World newworld : Bukkit.getWorlds()) {
|
||||
if (newworld.getName().equalsIgnoreCase(world)) {
|
||||
return newworld.getName();
|
||||
}
|
||||
}
|
||||
return world;
|
||||
}
|
||||
|
||||
public boolean isValidConnection(Connection connection) {
|
||||
return connection != null;
|
||||
}
|
||||
|
||||
public void copyConfig(FileConfiguration plotConfig, String world, String actualWorldName) {
|
||||
final Integer pathwidth = plotConfig.getInt("worlds." + world + ".PathWidth"); //
|
||||
PS.get().config.set("worlds." + actualWorldName + ".road.width", pathwidth);
|
||||
final Integer plotsize = plotConfig.getInt("worlds." + world + ".PlotSize"); //
|
||||
PS.get().config.set("worlds." + actualWorldName + ".plot.size", plotsize);
|
||||
final String wallblock = plotConfig.getString("worlds." + world + ".WallBlockId"); //
|
||||
PS.get().config.set("worlds." + actualWorldName + ".wall.block", wallblock);
|
||||
final String floor = plotConfig.getString("worlds." + world + ".PlotFloorBlockId"); //
|
||||
PS.get().config.set("worlds." + actualWorldName + ".plot.floor", Arrays.asList(floor));
|
||||
final String filling = plotConfig.getString("worlds." + world + ".PlotFillingBlockId"); //
|
||||
PS.get().config.set("worlds." + actualWorldName + ".plot.filling", Arrays.asList(filling));
|
||||
final String road = plotConfig.getString("worlds." + world + ".RoadMainBlockId");
|
||||
PS.get().config.set("worlds." + actualWorldName + ".road.block", road);
|
||||
Integer height = plotConfig.getInt("worlds." + world + ".RoadHeight"); //
|
||||
if (height == null) {
|
||||
height = 64;
|
||||
}
|
||||
PS.get().config.set("worlds." + actualWorldName + ".road.height", height);
|
||||
}
|
||||
|
||||
public Location getPlotTopLocAbs(int path, int plot, final PlotId plotid) {
|
||||
final int px = plotid.x;
|
||||
final int pz = plotid.y;
|
||||
final int x = (px * (path + plot)) - ((int) Math.floor(path / 2)) - 1;
|
||||
final int z = (pz * (path + plot)) - ((int) Math.floor(path / 2)) - 1;
|
||||
return new Location(null, x, 256, z);
|
||||
}
|
||||
|
||||
public Location getPlotBottomLocAbs(int path, int plot, final PlotId plotid) {
|
||||
final int px = plotid.x;
|
||||
final int pz = plotid.y;
|
||||
final int x = (px * (path + plot)) - plot - ((int) Math.floor(path / 2)) - 1;
|
||||
final int z = (pz * (path + plot)) - plot - ((int) Math.floor(path / 2)) - 1;
|
||||
return new Location(null, x, 1, z);
|
||||
}
|
||||
|
||||
public void setMerged(HashMap<String, HashMap<PlotId, boolean[]>> merges, String world, PlotId id, int direction) {
|
||||
HashMap<PlotId, boolean[]> plots = merges.get(world);
|
||||
PlotId id2;
|
||||
switch (direction) {
|
||||
case 0: {
|
||||
id2 = new PlotId(id.x, id.y);
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
id2 = new PlotId(id.x, id.y);
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
id2 = new PlotId(id.x, id.y);
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
id2 = new PlotId(id.x, id.y);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
return;
|
||||
}
|
||||
}
|
||||
boolean[] merge1;
|
||||
boolean[] merge2;
|
||||
if (plots.containsKey(id)) {
|
||||
merge1 = plots.get(id);
|
||||
}
|
||||
else {
|
||||
merge1 = new boolean[]{false, false, false, false};
|
||||
}
|
||||
if (plots.containsKey(id2)) {
|
||||
merge2 = plots.get(id2);
|
||||
}
|
||||
else {
|
||||
merge2 = new boolean[]{false, false, false, false};
|
||||
}
|
||||
merge1[direction] = true;
|
||||
merge2[(direction + 2) % 4] = true;
|
||||
plots.put(id, merge1);
|
||||
plots.put(id2, merge1);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,206 @@
|
||||
package com.intellectualcrafters.plot.database.plotme;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
|
||||
import com.intellectualcrafters.configuration.file.FileConfiguration;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.database.SQLite;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.StringWrapper;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
public class ClassicPlotMeConnector extends APlotMeConnector {
|
||||
|
||||
private String plugin;
|
||||
|
||||
@Override
|
||||
public Connection getPlotMeConnection(String plugin, FileConfiguration plotConfig, String dataFolder) {
|
||||
this.plugin = plugin.toLowerCase();
|
||||
try {
|
||||
if (plotConfig.getBoolean("usemySQL")) {
|
||||
final String user = plotConfig.getString("mySQLuname");
|
||||
final String password = plotConfig.getString("mySQLpass");
|
||||
final String con = plotConfig.getString("mySQLconn");
|
||||
return DriverManager.getConnection(con, user, password);
|
||||
// return new MySQL(plotsquared, hostname, port, database, username, password)
|
||||
} else {
|
||||
return new SQLite(dataFolder + File.separator + "plots.db").openConnection();
|
||||
}
|
||||
}
|
||||
catch (SQLException | ClassNotFoundException e) {}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<String, HashMap<PlotId, Plot>> getPlotMePlots(Connection connection) throws SQLException {
|
||||
ResultSet r;
|
||||
PreparedStatement stmt;
|
||||
final HashMap<String, Integer> plotWidth = new HashMap<>();
|
||||
final HashMap<String, Integer> roadWidth = new HashMap<>();
|
||||
final HashMap<String, HashMap<PlotId, Plot>> plots = new HashMap<>();
|
||||
final HashMap<String, HashMap<PlotId, boolean[]>> merges = new HashMap<>();
|
||||
stmt = connection.prepareStatement("SELECT * FROM `" + plugin + "Plots`");
|
||||
r = stmt.executeQuery();
|
||||
boolean checkUUID = DBFunc.hasColumn(r, "ownerid");
|
||||
boolean merge = !plugin.equals("plotme") && Settings.CONVERT_PLOTME;
|
||||
while (r.next()) {
|
||||
final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ"));
|
||||
final String name = r.getString("owner");
|
||||
final String world = LikePlotMeConverter.getWorld(r.getString("world"));
|
||||
if (!plots.containsKey(world)) {
|
||||
plots.put(world, new HashMap<PlotId, Plot>());
|
||||
if (merge) {
|
||||
int plot = PS.get().config.getInt("worlds." + world + ".plot.size");
|
||||
int path = PS.get().config.getInt("worlds." + world + ".road.width");
|
||||
plotWidth.put(world, plot);
|
||||
roadWidth.put(world, path);
|
||||
merges.put(world, new HashMap<PlotId,boolean[]>());
|
||||
}
|
||||
}
|
||||
if (merge) {
|
||||
int tx = r.getInt("topX");
|
||||
int tz = r.getInt("topZ");
|
||||
int bx = r.getInt("bottomX") - 1;
|
||||
int bz = r.getInt("bottomZ") - 1;
|
||||
int path = roadWidth.get(world);
|
||||
int plot = plotWidth.get(world);
|
||||
Location top = getPlotTopLocAbs(path, plot, id);
|
||||
Location bot = getPlotBottomLocAbs(path, plot, id);
|
||||
if (tx > top.getX()) {
|
||||
setMerged(merges, world, id, 1);
|
||||
}
|
||||
if (tz > top.getZ()) {
|
||||
setMerged(merges, world, id, 2);
|
||||
}
|
||||
if (bx < bot.getX()) {
|
||||
setMerged(merges, world, id, 3);
|
||||
}
|
||||
if (bz > bot.getZ()) {
|
||||
setMerged(merges, world, id, 0);
|
||||
}
|
||||
}
|
||||
UUID owner = UUIDHandler.getUUID(name);
|
||||
if (owner == null) {
|
||||
if (name.equals("*")) {
|
||||
owner = DBFunc.everyone;
|
||||
}
|
||||
else {
|
||||
if (checkUUID){
|
||||
try {
|
||||
byte[] bytes = r.getBytes("ownerid");
|
||||
if (bytes != null) {
|
||||
owner = UUID.nameUUIDFromBytes(bytes);
|
||||
if (owner != null) {
|
||||
UUIDHandler.add(new StringWrapper(name), owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (owner == null) {
|
||||
MainUtil.sendConsoleMessage("&cCould not identify owner for plot: " + id + " -> '" + name + "'");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
UUIDHandler.add(new StringWrapper(name), owner);
|
||||
}
|
||||
final Plot plot = new Plot(world, id, owner);
|
||||
plots.get(world).put(id, plot);
|
||||
}
|
||||
|
||||
for (Entry<String, HashMap<PlotId, boolean[]>> entry : merges.entrySet()) {
|
||||
String world = entry.getKey();
|
||||
for (Entry<PlotId, boolean[]> entry2 : entry.getValue().entrySet()) {
|
||||
HashMap<PlotId, Plot> newplots = plots.get(world);
|
||||
Plot plot = newplots.get(entry2.getKey());
|
||||
if (plot != null) {
|
||||
plot.settings.setMerged(entry2.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
r.close();
|
||||
stmt.close();
|
||||
|
||||
try {
|
||||
|
||||
MainUtil.sendConsoleMessage(" - " + plugin + "Denied");
|
||||
stmt = connection.prepareStatement("SELECT * FROM `" + plugin + "Denied`");
|
||||
r = stmt.executeQuery();
|
||||
|
||||
while (r.next()) {
|
||||
final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ"));
|
||||
final String name = r.getString("player");
|
||||
final String world = LikePlotMeConverter.getWorld(r.getString("world"));
|
||||
UUID denied = UUIDHandler.getUUID(name);
|
||||
if (denied == null) {
|
||||
if (name.equals("*")) {
|
||||
denied = DBFunc.everyone;
|
||||
} else {
|
||||
MainUtil.sendConsoleMessage("&6Could not identify denied for plot: " + id);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (plots.get(world).containsKey(id)) {
|
||||
plots.get(world).get(id).denied.add(denied);
|
||||
}
|
||||
}
|
||||
|
||||
stmt = connection.prepareStatement("SELECT * FROM `" + plugin + "Allowed`");
|
||||
r = stmt.executeQuery();
|
||||
|
||||
while (r.next()) {
|
||||
final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ"));
|
||||
final String name = r.getString("player");
|
||||
final String world = LikePlotMeConverter.getWorld(r.getString("world"));
|
||||
UUID helper = UUIDHandler.getUUID(name);
|
||||
if (helper == null) {
|
||||
if (name.equals("*")) {
|
||||
helper = DBFunc.everyone;
|
||||
} else {
|
||||
MainUtil.sendConsoleMessage("&6Could not identify helper for plot: " + id);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (plots.get(world).containsKey(id)) {
|
||||
plots.get(world).get(id).trusted.add(helper);
|
||||
}
|
||||
}
|
||||
|
||||
r.close();
|
||||
stmt.close();
|
||||
|
||||
}
|
||||
catch (Exception e) {}
|
||||
return plots;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accepts(String version) {
|
||||
if (version == null) {
|
||||
return true;
|
||||
}
|
||||
return PS.get().canUpdate(version, "0.17.0");
|
||||
}
|
||||
}
|
@ -0,0 +1,323 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.database.plotme;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.sql.Connection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldCreator;
|
||||
|
||||
import com.intellectualcrafters.configuration.file.FileConfiguration;
|
||||
import com.intellectualcrafters.configuration.file.YamlConfiguration;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.generator.HybridGen;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
|
||||
/**
|
||||
* Created 2014-08-17 for PlotSquared
|
||||
*
|
||||
* @author Citymonstret
|
||||
* @author Empire92
|
||||
*/
|
||||
public class LikePlotMeConverter {
|
||||
private String plugin;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param plugin Plugin Used to run the converter
|
||||
*/
|
||||
public LikePlotMeConverter(String plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public static String getWorld(final String world) {
|
||||
for (final World newworld : Bukkit.getWorlds()) {
|
||||
if (newworld.getName().equalsIgnoreCase(world)) {
|
||||
return newworld.getName();
|
||||
}
|
||||
}
|
||||
return world;
|
||||
}
|
||||
|
||||
private void sendMessage(final String message) {
|
||||
PS.log("&3PlotMe&8->&3PlotSquared&8: &7" + message);
|
||||
}
|
||||
|
||||
public String getPlotMePath() {
|
||||
return new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator + plugin + File.separator;
|
||||
}
|
||||
|
||||
public String getAthionPlotsPath() {
|
||||
return new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator + plugin + File.separator;
|
||||
}
|
||||
|
||||
public FileConfiguration getPlotMeConfig(String dataFolder) {
|
||||
final File plotMeFile = new File(dataFolder + "config.yml");
|
||||
if (!plotMeFile.exists()) {
|
||||
return null;
|
||||
}
|
||||
return YamlConfiguration.loadConfiguration(plotMeFile);
|
||||
}
|
||||
|
||||
public Set<String> getPlotMeWorlds(FileConfiguration plotConfig) {
|
||||
return plotConfig.getConfigurationSection("worlds").getKeys(false);
|
||||
}
|
||||
|
||||
public void updateWorldYml(String plugin, String location) {
|
||||
try {
|
||||
Path path = Paths.get(location);
|
||||
File file = new File(location);
|
||||
if (!file.exists()) {
|
||||
return;
|
||||
}
|
||||
Charset charset = StandardCharsets.UTF_8;
|
||||
String content = new String(Files.readAllBytes(path), charset);
|
||||
content = content.replaceAll("PlotMe-DefaultGenerator", "PlotSquared");
|
||||
content = content.replaceAll(plugin, "PlotSquared");
|
||||
Files.write(path, content.getBytes(charset));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean run(final APlotMeConnector connector) {
|
||||
try {
|
||||
String dataFolder = getPlotMePath();
|
||||
FileConfiguration plotConfig = getPlotMeConfig(dataFolder);
|
||||
if (plotConfig == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String version = plotConfig.getString("Version");
|
||||
if (version == null) version = plotConfig.getString("version");
|
||||
if (!connector.accepts(version)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
PS.log("&3Using connector: " + connector.getClass().getCanonicalName());
|
||||
|
||||
Connection connection = connector.getPlotMeConnection(plugin, plotConfig, dataFolder);
|
||||
|
||||
if (!connector.isValidConnection(connection)) {
|
||||
sendMessage("Cannot connect to PlotMe DB. Conversion process will not continue");
|
||||
return false;
|
||||
}
|
||||
|
||||
sendMessage(plugin + " conversion has started. To disable this, please set 'plotme-convert.enabled' in the 'settings.yml'");
|
||||
sendMessage("Connecting to " + plugin + " DB");
|
||||
|
||||
int plotCount = 0;
|
||||
final ArrayList<Plot> createdPlots = new ArrayList<>();
|
||||
|
||||
sendMessage("Collecting plot data");
|
||||
|
||||
String dbPrefix = plugin.toLowerCase();
|
||||
sendMessage(" - " + dbPrefix + "Plots");
|
||||
final Set<String> worlds = getPlotMeWorlds(plotConfig);
|
||||
|
||||
if (Settings.CONVERT_PLOTME) {
|
||||
sendMessage("Updating bukkit.yml");
|
||||
updateWorldYml(plugin, "bukkit.yml");
|
||||
updateWorldYml(plugin, "plugins/Multiverse-Core/worlds.yml");
|
||||
for (final String world : plotConfig.getConfigurationSection("worlds").getKeys(false)) {
|
||||
sendMessage("Copying config for: " + world);
|
||||
try {
|
||||
String actualWorldName = getWorld(world);
|
||||
connector.copyConfig(plotConfig, world, actualWorldName);
|
||||
PS.get().config.save(PS.get().configFile);
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
sendMessage("&c-- &lFailed to save configuration for world '" + world + "'\nThis will need to be done using the setup command, or manually");
|
||||
}
|
||||
}
|
||||
}
|
||||
HashMap<String, HashMap<PlotId, Plot>> plots = connector.getPlotMePlots(connection);
|
||||
for (Entry<String, HashMap<PlotId, Plot>> entry : plots.entrySet()) {
|
||||
plotCount += entry.getValue().size();
|
||||
}
|
||||
if (!Settings.CONVERT_PLOTME) {
|
||||
return false;
|
||||
}
|
||||
|
||||
sendMessage(" - " + dbPrefix + "Allowed");
|
||||
|
||||
sendMessage("Collected " + plotCount + " plots from PlotMe");
|
||||
final File PLOTME_DG_FILE = new File(dataFolder + File.separator + "PlotMe-DefaultGenerator" + File.separator + "config.yml");
|
||||
if (PLOTME_DG_FILE.exists()) {
|
||||
final YamlConfiguration PLOTME_DG_YML = YamlConfiguration.loadConfiguration(PLOTME_DG_FILE);
|
||||
try {
|
||||
for (final String world : plots.keySet()) {
|
||||
String actualWorldName = getWorld(world);
|
||||
final String plotMeWorldName = world.toLowerCase();
|
||||
Integer pathwidth = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".PathWidth"); //
|
||||
if (pathwidth == null) {
|
||||
pathwidth = 7;
|
||||
}
|
||||
PS.get().config.set("worlds." + world + ".road.width", pathwidth);
|
||||
Integer plotsize = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".PlotSize"); //
|
||||
if (plotsize == null) {
|
||||
plotsize = 32;
|
||||
}
|
||||
PS.get().config.set("worlds." + world + ".plot.size", plotsize);
|
||||
String wallblock = PLOTME_DG_YML.getString("worlds." + plotMeWorldName + ".WallBlock"); //
|
||||
if (wallblock == null) {
|
||||
wallblock = "44";
|
||||
}
|
||||
PS.get().config.set("worlds." + world + ".wall.block", wallblock);
|
||||
String floor = PLOTME_DG_YML.getString("worlds." + plotMeWorldName + ".PlotFloorBlock"); //
|
||||
if (floor == null) {
|
||||
floor = "2";
|
||||
}
|
||||
PS.get().config.set("worlds." + world + ".plot.floor", Arrays.asList(floor));
|
||||
String filling = PLOTME_DG_YML.getString("worlds." + plotMeWorldName + ".FillBlock"); //
|
||||
if (filling == null) {
|
||||
filling = "3";
|
||||
}
|
||||
PS.get().config.set("worlds." + world + ".plot.filling", Arrays.asList(filling));
|
||||
String road = PLOTME_DG_YML.getString("worlds." + plotMeWorldName + ".RoadMainBlock");
|
||||
if (road == null) {
|
||||
road = "5";
|
||||
}
|
||||
PS.get().config.set("worlds." + world + ".road.block", road);
|
||||
Integer height = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".RoadHeight"); //
|
||||
if ((height == null) || (height == 0)) {
|
||||
height = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".GroundHeight"); //
|
||||
if ((height == null) || (height == 0)) {
|
||||
height = 64;
|
||||
}
|
||||
}
|
||||
PS.get().config.set("worlds." + actualWorldName + ".road.height", height);
|
||||
PS.get().config.set("worlds." + actualWorldName + ".plot.height", height);
|
||||
PS.get().config.set("worlds." + actualWorldName + ".wall.height", height);
|
||||
PS.get().config.save(PS.get().configFile);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
}
|
||||
}
|
||||
for (final String world : plots.keySet()) {
|
||||
int duplicate = 0;
|
||||
for (final Plot plot : plots.get(world).values()) {
|
||||
if (!PS.get().getPlots(world).containsKey(plot.id)) {
|
||||
createdPlots.add(plot);
|
||||
} else {
|
||||
duplicate++;
|
||||
}
|
||||
}
|
||||
if (duplicate > 0) {
|
||||
PS.log("&c[WARNING] Found " + duplicate + " duplicate plots already in DB for world: '" + world + "'. Have you run the converter already?");
|
||||
}
|
||||
}
|
||||
sendMessage("Creating plot DB");
|
||||
Thread.sleep(1000);
|
||||
DBFunc.createPlotsAndData(createdPlots, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
sendMessage("&aDatabase conversion is now complete!");
|
||||
PS.log("&c - Stop the server");
|
||||
PS.log("&c - Disable 'plotme-convert.enabled' and 'plotme-convert.cache-uuids' in the settings.yml");
|
||||
PS.log("&c - Correct any generator settings that haven't copied to 'settings.yml' properly");
|
||||
PS.log("&c - Start the server");
|
||||
PS.get().setAllPlotsRaw(DBFunc.getPlots());
|
||||
}
|
||||
});
|
||||
sendMessage("Saving configuration...");
|
||||
try {
|
||||
PS.get().config.save(PS.get().configFile);
|
||||
} catch (final IOException e) {
|
||||
sendMessage(" - &cFailed to save configuration.");
|
||||
}
|
||||
TaskManager.runTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
boolean MV = false;
|
||||
boolean MW = false;
|
||||
if ((Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null) && Bukkit.getPluginManager().getPlugin("Multiverse-Core").isEnabled()) {
|
||||
MV = true;
|
||||
} else if ((Bukkit.getPluginManager().getPlugin("MultiWorld") != null) && Bukkit.getPluginManager().getPlugin("MultiWorld").isEnabled()) {
|
||||
MW = true;
|
||||
}
|
||||
for (final String worldname : worlds) {
|
||||
final World world = Bukkit.getWorld(getWorld(worldname));
|
||||
if (world == null) {
|
||||
sendMessage("&cInvalid world in PlotMe configuration: " + worldname);
|
||||
}
|
||||
final String actualWorldName = world.getName();
|
||||
sendMessage("Reloading generator for world: '" + actualWorldName + "'...");
|
||||
PS.get().removePlotWorld(actualWorldName);
|
||||
if (MV) {
|
||||
// unload world with MV
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv unload " + actualWorldName);
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (final InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
// load world with MV
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv import " + actualWorldName + " normal -g PlotSquared");
|
||||
} else if (MW) {
|
||||
// unload world with MW
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw unload " + actualWorldName);
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (final InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
// load world with MW
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + actualWorldName + " plugin:PlotSquared");
|
||||
} else {
|
||||
// Load using Bukkit API
|
||||
// - User must set generator manually
|
||||
Bukkit.getServer().unloadWorld(world, true);
|
||||
final World myworld = WorldCreator.name(actualWorldName).generator(new HybridGen(actualWorldName)).createWorld();
|
||||
myworld.save();
|
||||
}
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
sendMessage("&cPlease wait until database conversion is complete. You will be notified with instructions when this happens!");
|
||||
}
|
||||
});
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
PS.log("&/end/");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,199 @@
|
||||
package com.intellectualcrafters.plot.database.plotme;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.intellectualcrafters.configuration.file.FileConfiguration;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.database.SQLite;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.StringWrapper;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
public class PlotMeConnector_017 extends APlotMeConnector {
|
||||
private String plugin;
|
||||
|
||||
@Override
|
||||
public Connection getPlotMeConnection(String plugin, FileConfiguration plotConfig, String dataFolder) {
|
||||
this.plugin = plugin.toLowerCase();
|
||||
try {
|
||||
if (plotConfig.getBoolean("usemySQL")) {
|
||||
String user = plotConfig.getString("mySQLuname");
|
||||
String password = plotConfig.getString("mySQLpass");
|
||||
String con = plotConfig.getString("mySQLconn");
|
||||
return DriverManager.getConnection(con, user, password);
|
||||
} else {
|
||||
File file = new File(dataFolder + File.separator + "plotmecore.db");
|
||||
if (file.exists()) {
|
||||
return new SQLite(dataFolder + File.separator + "plotmecore.db").openConnection();
|
||||
}
|
||||
return new SQLite(dataFolder + File.separator + "plots.db").openConnection();
|
||||
}
|
||||
}
|
||||
catch (SQLException | ClassNotFoundException e) {}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<String, HashMap<PlotId, Plot>> getPlotMePlots(Connection connection) throws SQLException {
|
||||
ResultSet r;
|
||||
PreparedStatement stmt;
|
||||
HashMap<String, Integer> plotWidth = new HashMap<>();
|
||||
HashMap<String, Integer> roadWidth = new HashMap<>();
|
||||
final HashMap<Integer, Plot> plots = new HashMap<>();
|
||||
HashMap<String, HashMap<PlotId, boolean[]>> merges = new HashMap<>();
|
||||
stmt = connection.prepareStatement("SELECT * FROM `" + plugin + "core_plots`");
|
||||
r = stmt.executeQuery();
|
||||
boolean checkUUID = DBFunc.hasColumn(r, "ownerID");
|
||||
boolean merge = !plugin.equals("plotme") && Settings.CONVERT_PLOTME;
|
||||
while (r.next()) {
|
||||
int key = r.getInt("plot_id");
|
||||
PlotId id = new PlotId(r.getInt("plotX"), r.getInt("plotZ"));
|
||||
String name = r.getString("owner");
|
||||
String world = LikePlotMeConverter.getWorld(r.getString("world"));
|
||||
if (!plots.containsKey(world)) {
|
||||
if (merge) {
|
||||
int plot = PS.get().config.getInt("worlds." + world + ".plot.size");
|
||||
int path = PS.get().config.getInt("worlds." + world + ".road.width");
|
||||
plotWidth.put(world, plot);
|
||||
roadWidth.put(world, path);
|
||||
merges.put(world, new HashMap<PlotId,boolean[]>());
|
||||
}
|
||||
}
|
||||
if (merge) {
|
||||
int tx = r.getInt("topX");
|
||||
int tz = r.getInt("topZ");
|
||||
int bx = r.getInt("bottomX") - 1;
|
||||
int bz = r.getInt("bottomZ") - 1;
|
||||
int path = roadWidth.get(world);
|
||||
int plot = plotWidth.get(world);
|
||||
Location top = getPlotTopLocAbs(path, plot, id);
|
||||
Location bot = getPlotBottomLocAbs(path, plot, id);
|
||||
if (tx > top.getX()) {
|
||||
setMerged(merges, world, id, 1);
|
||||
}
|
||||
if (tz > top.getZ()) {
|
||||
setMerged(merges, world, id, 2);
|
||||
}
|
||||
if (bx < bot.getX()) {
|
||||
setMerged(merges, world, id, 3);
|
||||
}
|
||||
if (bz > bot.getZ()) {
|
||||
setMerged(merges, world, id, 0);
|
||||
}
|
||||
}
|
||||
UUID owner = UUIDHandler.getUUID(name);
|
||||
if (owner == null) {
|
||||
if (name.equals("*")) {
|
||||
owner = DBFunc.everyone;
|
||||
}
|
||||
else {
|
||||
if (checkUUID){
|
||||
try {
|
||||
byte[] bytes = r.getBytes("ownerid");
|
||||
if (bytes != null) {
|
||||
owner = UUID.nameUUIDFromBytes(bytes);
|
||||
if (owner != null) {
|
||||
UUIDHandler.add(new StringWrapper(name), owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (owner == null) {
|
||||
MainUtil.sendConsoleMessage("&cCould not identify owner for plot: " + id + " -> '" + name + "'");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
UUIDHandler.add(new StringWrapper(name), owner);
|
||||
}
|
||||
Plot plot = new Plot(world, id, owner);
|
||||
plots.put(key, plot);
|
||||
}
|
||||
for (Entry<Integer, Plot> entry : plots.entrySet()) {
|
||||
Plot plot = entry.getValue();
|
||||
HashMap<PlotId, boolean[]> mergeMap = merges.get(plot.world);
|
||||
if (mergeMap != null) {
|
||||
if (mergeMap.containsKey(plot.id)) {
|
||||
plot.settings.setMerged(mergeMap.get(plot.id));
|
||||
}
|
||||
}
|
||||
}
|
||||
r.close();
|
||||
stmt.close();
|
||||
try {
|
||||
MainUtil.sendConsoleMessage(" - " + plugin + "core_denied");
|
||||
stmt = connection.prepareStatement("SELECT * FROM `" + plugin + "core_denied`");
|
||||
r = stmt.executeQuery();
|
||||
|
||||
while (r.next()) {
|
||||
int key = r.getInt("plot_id");
|
||||
Plot plot = plots.get(key);
|
||||
if (plot == null) {
|
||||
MainUtil.sendConsoleMessage("&6Denied (" + key + ") references deleted plot; ignoring entry.");
|
||||
continue;
|
||||
}
|
||||
UUID denied = UUID.fromString(r.getString("player"));
|
||||
plot.denied.add(denied);
|
||||
}
|
||||
|
||||
MainUtil.sendConsoleMessage(" - " + plugin + "core_allowed");
|
||||
stmt = connection.prepareStatement("SELECT * FROM `" + plugin + "core_allowed`");
|
||||
r = stmt.executeQuery();
|
||||
|
||||
while (r.next()) {
|
||||
int key = r.getInt("plot_id");
|
||||
Plot plot = plots.get(key);
|
||||
if (plot == null) {
|
||||
MainUtil.sendConsoleMessage("&6Allowed (" + key + ") references deleted plot; ignoring entry.");
|
||||
continue;
|
||||
}
|
||||
UUID allowed = UUID.fromString(r.getString("player"));
|
||||
plot.trusted.add(allowed);
|
||||
}
|
||||
r.close();
|
||||
stmt.close();
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
HashMap<String, HashMap<PlotId, Plot>> processed = new HashMap<>();
|
||||
|
||||
for (Entry<Integer, Plot> entry : plots.entrySet()) {
|
||||
Plot plot = entry.getValue();
|
||||
HashMap<PlotId, Plot> map = processed.get(plot.world);
|
||||
if (map == null) {
|
||||
map = new HashMap<>();
|
||||
processed.put(plot.world, map);
|
||||
}
|
||||
map.put(plot.id, plot);
|
||||
}
|
||||
return processed ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accepts(String version) {
|
||||
if (version == null) {
|
||||
return false;
|
||||
}
|
||||
return !PS.get().canUpdate(version, "0.17");
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.events;
|
||||
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.object.PlotCluster;
|
||||
|
||||
/**
|
||||
* Called when a flag is removed from a plot
|
||||
*
|
||||
* @author Citymonstret
|
||||
* @author Empire92
|
||||
*/
|
||||
public class ClusterFlagRemoveEvent extends Event implements Cancellable {
|
||||
private static HandlerList handlers = new HandlerList();
|
||||
private final PlotCluster cluster;
|
||||
private final Flag flag;
|
||||
private boolean cancelled;
|
||||
|
||||
/**
|
||||
* PlotFlagRemoveEvent: Called when a flag is removed from a plot
|
||||
*
|
||||
* @param flag Flag that was removed
|
||||
* @param plot Plot from which the flag was removed
|
||||
*/
|
||||
public ClusterFlagRemoveEvent(final Flag flag, final PlotCluster cluster) {
|
||||
this.cluster = cluster;
|
||||
this.flag = flag;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cluster involved
|
||||
*
|
||||
* @return PlotCluster
|
||||
*/
|
||||
public PlotCluster getCluster() {
|
||||
return this.cluster;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the flag involved
|
||||
*
|
||||
* @return Flag
|
||||
*/
|
||||
public Flag getFlag() {
|
||||
return this.flag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return this.cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(final boolean b) {
|
||||
this.cancelled = b;
|
||||
}
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
* @author Empire92
|
||||
*/
|
||||
public class PlayerClaimPlotEvent extends PlayerEvent implements Cancellable {
|
||||
private static HandlerList handlers = new HandlerList();
|
||||
private final Plot plot;
|
||||
private final boolean auto;
|
||||
private boolean cancelled;
|
||||
|
||||
/**
|
||||
* PlayerClaimPlotEvent: Called when a plot is claimed
|
||||
*
|
||||
* @param player Player that claimed the plot
|
||||
* @param plot Plot that was claimed
|
||||
*/
|
||||
public PlayerClaimPlotEvent(final Player player, final Plot plot, final boolean auto) {
|
||||
super(player);
|
||||
this.plot = plot;
|
||||
this.auto = auto;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plot involved
|
||||
*
|
||||
* @return Plot
|
||||
*/
|
||||
public Plot getPlot() {
|
||||
return this.plot;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if it was an automated claim, else false
|
||||
*/
|
||||
public boolean wasAuto() {
|
||||
return this.auto;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return this.cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(final boolean b) {
|
||||
this.cancelled = b;
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
* @author Empire92
|
||||
*/
|
||||
public class PlayerEnterPlotEvent extends PlayerEvent {
|
||||
private static HandlerList handlers = new HandlerList();
|
||||
private final Plot plot;
|
||||
|
||||
/**
|
||||
* PlayerEnterPlotEvent: Called when a player leaves a plot
|
||||
*
|
||||
* @param player Player that entered the plot
|
||||
* @param plot Plot that was entered
|
||||
*/
|
||||
public PlayerEnterPlotEvent(final Player player, final Plot plot) {
|
||||
super(player);
|
||||
this.plot = plot;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plot involved
|
||||
*
|
||||
* @return Plot
|
||||
*/
|
||||
public Plot getPlot() {
|
||||
return this.plot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
* @author Empire92
|
||||
*/
|
||||
public class PlayerLeavePlotEvent extends PlayerEvent {
|
||||
|
||||
private static HandlerList handlers = new HandlerList();
|
||||
private final Plot plot;
|
||||
|
||||
/**
|
||||
* PlayerLeavePlotEvent: Called when a player leaves a plot
|
||||
*
|
||||
* @param player Player that left the plot
|
||||
* @param plot Plot that was left
|
||||
*/
|
||||
public PlayerLeavePlotEvent(final Player player, final Plot plot) {
|
||||
super(player);
|
||||
this.plot = plot;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plot involved
|
||||
*
|
||||
* @return Plot
|
||||
*/
|
||||
public Plot getPlot() {
|
||||
return this.plot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.events;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
* @author Empire92
|
||||
*/
|
||||
public class PlayerPlotDeniedEvent extends PlotEvent {
|
||||
|
||||
private static HandlerList handlers = new HandlerList();
|
||||
private final Player initiator;
|
||||
private final boolean added;
|
||||
private final UUID player;
|
||||
|
||||
/**
|
||||
* PlayerPlotDeniedEvent: Called when the denied UUID list is modified for a plot
|
||||
*
|
||||
* @param initiator Player that initiated the event
|
||||
* @param plot Plot in which the event occurred
|
||||
* @param player Player that was denied/un-denied
|
||||
* @param added true of add to deny list, false if removed
|
||||
*/
|
||||
public PlayerPlotDeniedEvent(final Player initiator, final Plot plot, final UUID player, final boolean added) {
|
||||
super(plot);
|
||||
this.initiator = initiator;
|
||||
this.added = added;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* If a user was added
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean wasAdded() {
|
||||
return this.added;
|
||||
}
|
||||
|
||||
/**
|
||||
* The player added/removed
|
||||
*
|
||||
* @return UUID
|
||||
*/
|
||||
public UUID getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
/**
|
||||
* The player initiating the action
|
||||
*
|
||||
* @return Player
|
||||
*/
|
||||
public Player getInitiator() {
|
||||
return this.initiator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.events;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
|
||||
/**
|
||||
* @author Empire92
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class PlayerPlotHelperEvent extends PlotEvent {
|
||||
|
||||
private static HandlerList handlers = new HandlerList();
|
||||
private final Player initiator;
|
||||
private final boolean added;
|
||||
private final UUID player;
|
||||
|
||||
/**
|
||||
* PlayerPlotHelperEvent: Called when a plot helper is added/removed
|
||||
*
|
||||
* @param initiator Player that initiated the event
|
||||
* @param plot Plot in which the event occurred
|
||||
* @param player Player that was added/removed from the helper list
|
||||
* @param added true of the player was added, false if the player was removed
|
||||
*/
|
||||
public PlayerPlotHelperEvent(final Player initiator, final Plot plot, final UUID player, final boolean added) {
|
||||
super(plot);
|
||||
this.initiator = initiator;
|
||||
this.added = added;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* If a player was added
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean wasAdded() {
|
||||
return this.added;
|
||||
}
|
||||
|
||||
/**
|
||||
* The UUID added/removed
|
||||
*
|
||||
* @return UUID
|
||||
*/
|
||||
public UUID getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
/**
|
||||
* The player initiating the action
|
||||
*
|
||||
* @return Player
|
||||
*/
|
||||
public Player getInitiator() {
|
||||
return this.initiator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.events;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
* @author Empire92
|
||||
*/
|
||||
public class PlayerPlotTrustedEvent extends PlotEvent {
|
||||
|
||||
private static HandlerList handlers = new HandlerList();
|
||||
private final Player initiator;
|
||||
private final boolean added;
|
||||
private final UUID player;
|
||||
|
||||
/**
|
||||
* PlayerPlotTrustedEvent: Called when a plot trusted user is added/removed
|
||||
*
|
||||
* @param initiator Player that initiated the event
|
||||
* @param plot Plot in which the event occurred
|
||||
* @param player Player that was added/removed from the trusted list
|
||||
* @param added true of the player was added, false if the player was removed
|
||||
*/
|
||||
public PlayerPlotTrustedEvent(final Player initiator, final Plot plot, final UUID player, final boolean added) {
|
||||
super(plot);
|
||||
this.initiator = initiator;
|
||||
this.added = added;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* If a player was added
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean wasAdded() {
|
||||
return this.added;
|
||||
}
|
||||
|
||||
/**
|
||||
* The UUID added/removed
|
||||
*
|
||||
* @return UUID
|
||||
*/
|
||||
public UUID getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
/**
|
||||
* The player initiating the action
|
||||
*
|
||||
* @return Player
|
||||
*/
|
||||
public Player getInitiator() {
|
||||
return this.initiator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
|
||||
/**
|
||||
* Called when a player teleports to a plot
|
||||
*
|
||||
* @author Citymonstret
|
||||
* @author Empire92
|
||||
*/
|
||||
public class PlayerTeleportToPlotEvent extends PlayerEvent implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private final Location from;
|
||||
private final Plot plot;
|
||||
private boolean cancelled;
|
||||
|
||||
/**
|
||||
* PlayerTeleportToPlotEvent: Called when a player teleports to a plot
|
||||
*
|
||||
* @param player That was teleported
|
||||
* @param from Start location
|
||||
* @param plot Plot to which the player was teleported
|
||||
*/
|
||||
public PlayerTeleportToPlotEvent(final Player player, final Location from, final Plot plot) {
|
||||
super(player);
|
||||
this.from = from;
|
||||
this.plot = plot;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the from location
|
||||
*
|
||||
* @return Location
|
||||
*/
|
||||
public Location getFrom() {
|
||||
return this.from;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plot involved
|
||||
*
|
||||
* @return Plot
|
||||
*/
|
||||
public Plot getPlot() {
|
||||
return this.plot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return this.cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(final boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.events;
|
||||
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
|
||||
/**
|
||||
* Called when a plot is cleared
|
||||
*
|
||||
* @author Citymonstret
|
||||
* @author Empire92
|
||||
*/
|
||||
public class PlotClearEvent extends Event implements Cancellable {
|
||||
private static HandlerList handlers = new HandlerList();
|
||||
private final PlotId id;
|
||||
private final String world;
|
||||
private boolean cancelled;
|
||||
|
||||
/**
|
||||
* PlotDeleteEvent: Called when a plot is cleared
|
||||
*
|
||||
* @param world The world in which the plot was cleared
|
||||
* @param id The plot that was cleared
|
||||
*/
|
||||
public PlotClearEvent(final String world, final PlotId id) {
|
||||
this.id = id;
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the PlotId
|
||||
*
|
||||
* @return PlotId
|
||||
*/
|
||||
public PlotId getPlotId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the world name
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String getWorld() {
|
||||
return this.world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return this.cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(final boolean b) {
|
||||
this.cancelled = b;
|
||||
}
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.events;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
|
||||
/**
|
||||
* Called when a plot is deleted
|
||||
*
|
||||
* @author Citymonstret
|
||||
* @author Empire92
|
||||
*/
|
||||
public class PlotDeleteEvent extends Event {
|
||||
private static HandlerList handlers = new HandlerList();
|
||||
private final PlotId id;
|
||||
private final String world;
|
||||
|
||||
/**
|
||||
* PlotDeleteEvent: Called when a plot is deleted
|
||||
*
|
||||
* @param world The world in which the plot was deleted
|
||||
* @param id The ID of the plot that was deleted
|
||||
*/
|
||||
public PlotDeleteEvent(final String world, final PlotId id) {
|
||||
this.id = id;
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the PlotId
|
||||
*
|
||||
* @return PlotId
|
||||
*/
|
||||
public PlotId getPlotId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the world name
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String getWorld() {
|
||||
return this.world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.intellectualcrafters.plot.events;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.sk89q.worldedit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public abstract class PlotEvent extends Event {
|
||||
|
||||
private final Plot plot;
|
||||
|
||||
public PlotEvent(final Plot plot) {
|
||||
this.plot = plot;
|
||||
}
|
||||
|
||||
public final Plot getPlot() {
|
||||
return this.plot;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.events;
|
||||
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
|
||||
/**
|
||||
* Called when a Flag is added to a plot
|
||||
*
|
||||
* @author Citymonstret
|
||||
* @author Empire92
|
||||
*/
|
||||
public class PlotFlagAddEvent extends PlotEvent implements Cancellable {
|
||||
|
||||
private static HandlerList handlers = new HandlerList();
|
||||
private final Flag flag;
|
||||
private boolean cancelled;
|
||||
|
||||
/**
|
||||
* PlotFlagAddEvent: Called when a Flag is added to a plot
|
||||
*
|
||||
* @param flag Flag that was added
|
||||
* @param plot Plot to which the flag was added
|
||||
*/
|
||||
public PlotFlagAddEvent(final Flag flag, final Plot plot) {
|
||||
super(plot);
|
||||
this.flag = flag;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the flag involved
|
||||
*
|
||||
* @return Flag
|
||||
*/
|
||||
public Flag getFlag() {
|
||||
return this.flag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isCancelled() {
|
||||
return this.cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user