mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 21:26:45 +01:00
more changes
This commit is contained in:
parent
f154754e1b
commit
d227bcc739
@ -1,8 +1,212 @@
|
||||
package com.intellectualcrafters.plot;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
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.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class BukkitMain extends JavaPlugin implements Listener {
|
||||
import com.intellectualcrafters.plot.commands.Buy;
|
||||
import com.intellectualcrafters.plot.commands.MainCommand;
|
||||
import com.intellectualcrafters.plot.commands.WE_Anywhere;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
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.PlotListener;
|
||||
import com.intellectualcrafters.plot.listeners.PlotPlusListener;
|
||||
import com.intellectualcrafters.plot.listeners.WorldEditListener;
|
||||
import com.intellectualcrafters.plot.util.Metrics;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitTaskManager;
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
|
||||
public class BukkitMain extends JavaPlugin implements Listener,IPlotMain {
|
||||
|
||||
public static BukkitMain THIS = null;
|
||||
public static PlotSquared MAIN = null;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
MAIN = new PlotSquared(this);
|
||||
THIS = 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 :)");
|
||||
}
|
||||
|
||||
// TODO world load event
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
MAIN.disable();
|
||||
MAIN = null;
|
||||
THIS = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(String message) {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
onDisable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return this.getDescription().getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerCommands() {
|
||||
final MainCommand command = new MainCommand();
|
||||
final PluginCommand plotCommand = getCommand("plots");
|
||||
plotCommand.setExecutor(command);
|
||||
plotCommand.setAliases(Arrays.asList("p", "ps", "plotme", "plot"));
|
||||
plotCommand.setTabCompleter(command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getDirectory() {
|
||||
return getDataFolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskManager getTaskManager() {
|
||||
return new BukkitTaskManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runEntityTask() {
|
||||
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 String w : PlotSquared.getPlotWorlds()) {
|
||||
world = Bukkit.getWorld(w);
|
||||
try {
|
||||
if (world.getLoadedChunks().length < 1) {
|
||||
continue;
|
||||
}
|
||||
for (final Chunk chunk : world.getLoadedChunks()) {
|
||||
final Entity[] entities = chunk.getEntities();
|
||||
Entity entity;
|
||||
for (int i = entities.length - 1; i >= 0; i--) {
|
||||
if (!((entity = entities[i]) instanceof Player) && !PlotListener.isInPlot(entity.getLocation())) {
|
||||
entity.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (final Throwable e) {
|
||||
++this.error;
|
||||
} finally {
|
||||
++this.ticked;
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 20);
|
||||
}
|
||||
|
||||
public static boolean checkVersion(int major, int minor, int minor2) {
|
||||
try {
|
||||
String[] version = Bukkit.getBukkitVersion().split("-")[0].split("\\.");
|
||||
int a = Integer.parseInt(version[0]);
|
||||
int b = Integer.parseInt(version[1]);
|
||||
int c = 0;
|
||||
if (version.length == 3) {
|
||||
c = Integer.parseInt(version[2]);
|
||||
}
|
||||
if (a > major || (a == major && b > minor) || (a == major && b == minor && c >= minor2)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerPlayerEvents() {
|
||||
getServer().getPluginManager().registerEvents(new PlayerEvents(), this);
|
||||
if (checkVersion(1, 8, 0)) {
|
||||
getServer().getPluginManager().registerEvents(new PlayerEvents_1_8(), 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) {
|
||||
WorldEditPlugin worldEdit = (WorldEditPlugin) getServer().getPluginManager().getPlugin("WorldEdit");
|
||||
|
||||
final String version = 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 WorldEditListener(), this);
|
||||
MainCommand.subCommands.add(new WE_Anywhere());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Economy getEconomy() {
|
||||
if ((getServer().getPluginManager().getPlugin("Vault") != null) && getServer().getPluginManager().getPlugin("Vault").isEnabled()) {
|
||||
final RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
|
||||
if (economyProvider != null) {
|
||||
MainCommand.subCommands.add(new Buy());
|
||||
return economyProvider.getProvider();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,35 @@
|
||||
package com.intellectualcrafters.plot;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
|
||||
public interface IPlotMain {
|
||||
public void log(String message);
|
||||
|
||||
public File getDirectory();
|
||||
|
||||
public void disable();
|
||||
|
||||
public String getVersion();
|
||||
|
||||
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 Economy getEconomy();
|
||||
}
|
@ -45,6 +45,7 @@ import com.intellectualcrafters.plot.titles.AbstractTitle;
|
||||
import com.intellectualcrafters.plot.titles.DefaultTitle;
|
||||
import com.intellectualcrafters.plot.util.*;
|
||||
import com.intellectualcrafters.plot.util.Logger.LogLevel;
|
||||
import com.intellectualcrafters.plot.util.bukkit.TaskManager;
|
||||
import com.intellectualcrafters.plot.uuid.DefaultUUIDWrapper;
|
||||
import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper;
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
@ -63,6 +64,11 @@ import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* PlotMain class.
|
||||
*
|
||||
@ -70,6 +76,23 @@ import java.util.Map.Entry;
|
||||
* @author Empire92
|
||||
*/
|
||||
public class PlotMain {
|
||||
|
||||
/**
|
||||
* style
|
||||
*/
|
||||
public static File styleFile;
|
||||
public static YamlConfiguration styleConfig;
|
||||
/**
|
||||
* The main configuration file
|
||||
*/
|
||||
public static YamlConfiguration config;
|
||||
/**
|
||||
* Contains storage options
|
||||
*/
|
||||
public static YamlConfiguration storage;
|
||||
|
||||
public static IPlotMain MAIN_IMP = new BukkitMain();
|
||||
|
||||
/**
|
||||
* Permission that allows for "everything"
|
||||
*/
|
||||
@ -86,27 +109,15 @@ public class PlotMain {
|
||||
* All world managers
|
||||
*/
|
||||
private final static HashMap<String, PlotManager> managers = new HashMap<>();
|
||||
/**
|
||||
* style
|
||||
*/
|
||||
public static File styleFile;
|
||||
public static YamlConfiguration styleConfig;
|
||||
/**
|
||||
* settings.properties
|
||||
*/
|
||||
public static File configFile;
|
||||
/**
|
||||
* The main configuration file
|
||||
*/
|
||||
public static YamlConfiguration config;
|
||||
|
||||
/**
|
||||
* storage.properties
|
||||
*/
|
||||
public static File storageFile;
|
||||
/**
|
||||
* Contains storage options
|
||||
*/
|
||||
public static YamlConfiguration storage;
|
||||
/**
|
||||
* MySQL Connection
|
||||
*/
|
||||
@ -152,92 +163,6 @@ public class PlotMain {
|
||||
public static MySQL getMySQL() {
|
||||
return mySQL;
|
||||
}
|
||||
/**
|
||||
* Check a range of permissions e.g. 'plots.plot.<0-100>'<br> Returns highest integer in range.
|
||||
*
|
||||
* @param player to check
|
||||
* @param stub to check
|
||||
* @param range tp check
|
||||
*
|
||||
* @return permitted range
|
||||
*/
|
||||
public static int hasPermissionRange(final Player player, final String stub, final int range) {
|
||||
if ((player == null) || player.isOp() || player.hasPermission(ADMIN_PERMISSION)) {
|
||||
return Byte.MAX_VALUE;
|
||||
}
|
||||
if (player.hasPermission(stub + ".*")) {
|
||||
return Byte.MAX_VALUE;
|
||||
}
|
||||
for (int i = range; i > 0; i--) {
|
||||
if (player.hasPermission(stub + "." + i)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check a player for a permission<br> - Op has all permissions <br> - checks for '*' nodes
|
||||
*
|
||||
* @param player to check
|
||||
* @param perms to check
|
||||
*
|
||||
* @return true of player has permissions
|
||||
*/
|
||||
public static boolean hasPermissions(final Player player, final String[] perms) {
|
||||
// Assumes null player is console.
|
||||
if ((player == null) || player.isOp() || player.hasPermission(ADMIN_PERMISSION)) {
|
||||
return true;
|
||||
}
|
||||
for (final String perm : perms) {
|
||||
boolean permitted = false;
|
||||
if (player.hasPermission(perm)) {
|
||||
permitted = true;
|
||||
} else {
|
||||
final String[] nodes = perm.split("\\.");
|
||||
final StringBuilder n = new StringBuilder();
|
||||
for (int i = 0; i < (nodes.length - 1); i++) {
|
||||
n.append(nodes[i]).append(".");
|
||||
if (player.hasPermission(n + "*")) {
|
||||
permitted = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!permitted) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check a player for a permission<br> - Op has all permissions <br> - checks for '*' nodes
|
||||
*
|
||||
* @param player to check
|
||||
* @param perm to check
|
||||
*
|
||||
* @return true if player has the permission
|
||||
*/
|
||||
public static boolean hasPermission(final Player player, final String perm) {
|
||||
if ((player == null) || player.isOp() || player.hasPermission(ADMIN_PERMISSION)) {
|
||||
return true;
|
||||
}
|
||||
if (player.hasPermission(perm)) {
|
||||
return true;
|
||||
}
|
||||
final String[] nodes = perm.split("\\.");
|
||||
final StringBuilder n = new StringBuilder();
|
||||
for (int i = 0; i < (nodes.length - 1); i++) {
|
||||
n.append(nodes[i] + ("."));
|
||||
if (player.hasPermission(n + "*")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all plots
|
||||
@ -265,36 +190,13 @@ public class PlotMain {
|
||||
return new LinkedHashSet<>(_plots);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player player
|
||||
*
|
||||
* @return Set Containing the players plots
|
||||
* - ignores non plot worlds
|
||||
*/
|
||||
public static Set<Plot> getPlots(final Player player) {
|
||||
final UUID uuid = UUIDHandler.getUUID(player);
|
||||
final ArrayList<Plot> myplots = new ArrayList<>();
|
||||
for (final String world : plots.keySet()) {
|
||||
if (isPlotWorld(world)) {
|
||||
for (final Plot plot : plots.get(world).values()) {
|
||||
if (plot.hasOwner()) {
|
||||
if (plot.getOwner().equals(uuid)) {
|
||||
myplots.add(plot);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return new HashSet<>(myplots);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param world plot world
|
||||
* @param player plot owner
|
||||
*
|
||||
* @return players plots
|
||||
*/
|
||||
public static Set<Plot> getPlots(final World world, final Player player) {
|
||||
public static Set<Plot> getPlots(final String world, final String player) {
|
||||
final UUID uuid = UUIDHandler.getUUID(player);
|
||||
return getPlots(world, uuid);
|
||||
}
|
||||
@ -305,7 +207,7 @@ public class PlotMain {
|
||||
*
|
||||
* @return players plots
|
||||
*/
|
||||
public static Set<Plot> getPlots(final World world, final UUID uuid) {
|
||||
public static Set<Plot> getPlots(final String world, final UUID uuid) {
|
||||
final ArrayList<Plot> myplots = new ArrayList<>();
|
||||
for (final Plot plot : getPlots(world).values()) {
|
||||
if (plot.hasOwner()) {
|
||||
@ -317,28 +219,14 @@ public class PlotMain {
|
||||
return new HashSet<>(myplots);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get plots for the specified world
|
||||
*
|
||||
* @param world A world, in which you want to search for plots
|
||||
*
|
||||
* @return HashMap containing Plot IDs and Plot Objects
|
||||
*/
|
||||
public static HashMap<PlotId, Plot> getPlots(final String world) {
|
||||
if (plots.containsKey(world)) {
|
||||
return plots.get(world);
|
||||
}
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param world plot world
|
||||
*
|
||||
* @return plots in world
|
||||
*/
|
||||
public static HashMap<PlotId, Plot> getPlots(final World world) {
|
||||
if (plots.containsKey(world.getName())) {
|
||||
return plots.get(world.getName());
|
||||
public static HashMap<PlotId, Plot> getPlots(final String world) {
|
||||
if (plots.containsKey(world)) {
|
||||
return plots.get(world);
|
||||
}
|
||||
return new HashMap<>();
|
||||
}
|
||||
@ -359,15 +247,6 @@ public class PlotMain {
|
||||
return strings.toArray(new String[strings.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param world plotworld(?)
|
||||
*
|
||||
* @return true if the world is a plotworld
|
||||
*/
|
||||
public static boolean isPlotWorld(final World world) {
|
||||
return (worlds.containsKey(world.getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param world plotworld(?)
|
||||
*
|
||||
@ -378,19 +257,7 @@ public class PlotMain {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param world World to get manager for
|
||||
*
|
||||
* @return manager for world
|
||||
*/
|
||||
public static PlotManager getPlotManager(final World world) {
|
||||
if (managers.containsKey(world.getName())) {
|
||||
return managers.get(world.getName());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param world world
|
||||
* @param String world
|
||||
*
|
||||
* @return PlotManager
|
||||
*/
|
||||
@ -401,17 +268,6 @@ public class PlotMain {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param world to search
|
||||
*
|
||||
* @return PlotWorld object
|
||||
*/
|
||||
public static PlotWorld getWorldSettings(final World world) {
|
||||
if (worlds.containsKey(world.getName())) {
|
||||
return worlds.get(world.getName());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param world to search
|
||||
@ -426,12 +282,12 @@ public class PlotMain {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param world world to search
|
||||
* @param String world to search
|
||||
*
|
||||
* @return set containing the plots for a world
|
||||
*/
|
||||
public static Plot[] getWorldPlots(final World world) {
|
||||
final Collection<Plot> values = plots.get(world.getName()).values();
|
||||
public static Plot[] getWorldPlots(final String world) {
|
||||
final Collection<Plot> values = plots.get(world).values();
|
||||
return (values.toArray(new Plot[values.size()]));
|
||||
}
|
||||
|
||||
@ -446,15 +302,11 @@ public class PlotMain {
|
||||
*/
|
||||
public static boolean removePlot(final String world, final PlotId id, final boolean callEvent) {
|
||||
if (callEvent) {
|
||||
final PlotDeleteEvent event = new PlotDeleteEvent(world, id);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
event.setCancelled(true);
|
||||
if (!MAIN_IMP.callRemovePlot(world, id)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
plots.get(world).remove(id);
|
||||
|
||||
if (PlotHelper.lastPlot.containsKey(world)) {
|
||||
PlotId last = PlotHelper.lastPlot.get(world);
|
||||
int last_max = Math.max(last.x, last.y);
|
||||
@ -464,7 +316,6 @@ public class PlotMain {
|
||||
PlotHelper.lastPlot.put(world, id);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -500,22 +351,6 @@ public class PlotMain {
|
||||
return connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to the console.
|
||||
*
|
||||
* @param string message
|
||||
*/
|
||||
public static void sendConsoleSenderMessage(final String string) {
|
||||
if (PlotMain.main == null || getMain().getServer().getConsoleSender() == null) {
|
||||
System.out.println(ChatColor.stripColor(ConsoleColors.fromString(string)));
|
||||
} else {
|
||||
String message = ChatColor.translateAlternateColorCodes('&', string);
|
||||
if (!Settings.CONSOLE_COLOR) {
|
||||
message = ChatColor.stripColor(message);
|
||||
}
|
||||
getMain().getServer().getConsoleSender().sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleport a player to a plot
|
||||
@ -526,26 +361,30 @@ public class PlotMain {
|
||||
*
|
||||
* @return true if successful
|
||||
*/
|
||||
public static boolean teleportPlayer(final Player player, final Location from, final Plot plot) {
|
||||
Plot bot = PlayerFunctions.getBottomPlot(player.getWorld(), plot);
|
||||
public boolean teleportPlayer(final Player player, final Location from, final Plot plot) {
|
||||
Plot bot = PlayerFunctions.getBottomPlot(player.getWorld().getName(), plot);
|
||||
final PlayerTeleportToPlotEvent event = new PlayerTeleportToPlotEvent(player, from, bot);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
final Location location = PlotHelper.getPlotHome(Bukkit.getWorld(bot.world), bot);
|
||||
if ((location.getBlockX() >= 29999999) || (location.getBlockX() <= -29999999) || (location.getBlockZ() >= 299999999) || (location.getBlockZ() <= -29999999)) {
|
||||
|
||||
int x = location.getX();
|
||||
int z = location.getZ();
|
||||
|
||||
|
||||
if ((x >= 29999999) || (x <= -29999999) || (z >= 299999999) || (z <= -29999999)) {
|
||||
event.setCancelled(true);
|
||||
return false;
|
||||
}
|
||||
if (Settings.TELEPORT_DELAY == 0 || hasPermission(player, "plots.teleport.delay.bypass")) {
|
||||
Location bukkitLoc = new org.bukkit.Location(player.getWorld(), x, y, z)
|
||||
PlayerFunctions.sendMessage(player, C.TELEPORTED_TO_PLOT);
|
||||
player.teleport(location);
|
||||
return true;
|
||||
}
|
||||
PlayerFunctions.sendMessage(player, C.TELEPORT_IN_SECONDS, Settings.TELEPORT_DELAY + "");
|
||||
Location loc = player.getLocation();
|
||||
final World world = player.getWorld();
|
||||
final int x = loc.getBlockX();
|
||||
final int z = loc.getBlockZ();
|
||||
final String world = player.getWorld();
|
||||
final String name = player.getName();
|
||||
TaskManager.TELEPORT_QUEUE.add(name);
|
||||
TaskManager.runTaskLater(new Runnable() {
|
||||
@ -576,25 +415,7 @@ public class PlotMain {
|
||||
}
|
||||
return !event.isCancelled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to the console
|
||||
*
|
||||
* @param c message
|
||||
*/
|
||||
public static void sendConsoleSenderMessage(final C c) {
|
||||
sendConsoleSenderMessage(c.s());
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcast publicly
|
||||
*
|
||||
* @param c message
|
||||
*/
|
||||
public static void Broadcast(final C c) {
|
||||
Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', C.PREFIX.s() + c.s()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the main class.
|
||||
*
|
||||
@ -762,7 +583,7 @@ public class PlotMain {
|
||||
}
|
||||
this.error = 0l;
|
||||
}
|
||||
World world;
|
||||
String world;
|
||||
for (final String w : getPlotWorlds()) {
|
||||
getWorldSettings(w);
|
||||
world = Bukkit.getServer().getWorld(w);
|
||||
@ -803,7 +624,6 @@ public class PlotMain {
|
||||
options.put("plotme-convert.enabled", Settings.CONVERT_PLOTME);
|
||||
options.put("claim.max-auto-area", Settings.MAX_AUTO_SIZE);
|
||||
options.put("UUID.offline", Settings.OFFLINE_MODE);
|
||||
// options.put("worldguard.enabled", Settings.WORLDGUARD);
|
||||
options.put("kill_road_mobs", Settings.KILL_ROAD_MOBS_DEFAULT);
|
||||
options.put("mob_pathfinding", Settings.MOB_PATHFINDING_DEFAULT);
|
||||
options.put("console.color", Settings.CONSOLE_COLOR);
|
||||
@ -815,14 +635,9 @@ public class PlotMain {
|
||||
options.put("clear.on.ban", false);
|
||||
options.put("max_plots", Settings.MAX_PLOTS);
|
||||
options.put("schematics.save_path", Settings.SCHEMATIC_SAVE_PATH);
|
||||
// options.put("uuid.api.location", Settings.API_URL);
|
||||
// options.put("uuid.api.custom", Settings.CUSTOM_API);
|
||||
// options.put("uuid.fecthing", Settings.UUID_FECTHING);
|
||||
options.put("uuid.read-from-disk", Settings.UUID_FROM_DISK);
|
||||
options.put("titles", Settings.TITLES);
|
||||
options.put("teleport.on_login", Settings.TELEPORT_ON_LOGIN);
|
||||
// options.put("perm-based-mob-cap.enabled", Settings.MOB_CAP_ENABLED);
|
||||
// options.put("perm-based-mob-cap.max", Settings.MOB_CAP);
|
||||
options.put("worldedit.require-selection-in-mask", Settings.REQUIRE_SELECTION);
|
||||
|
||||
for (final Entry<String, Object> node : options.entrySet()) {
|
||||
@ -841,7 +656,6 @@ public class PlotMain {
|
||||
Settings.USE_PLOTME_ALIAS = config.getBoolean("plotme-alias");
|
||||
Settings.CONVERT_PLOTME = config.getBoolean("plotme-convert.enabled");
|
||||
Settings.KILL_ROAD_MOBS = config.getBoolean("kill_road_mobs");
|
||||
// Settings.WORLDGUARD = config.getBoolean("worldguard.enabled");
|
||||
Settings.MOB_PATHFINDING = config.getBoolean("mob_pathf"
|
||||
+ "inding");
|
||||
Settings.METRICS = config.getBoolean("metrics");
|
||||
@ -850,15 +664,11 @@ public class PlotMain {
|
||||
Settings.MAX_AUTO_SIZE = config.getInt("claim.max-auto-area");
|
||||
Settings.AUTO_CLEAR = config.getBoolean("clear.auto.enabled");
|
||||
Settings.TITLES = config.getBoolean("titles");
|
||||
// Settings.MOB_CAP_ENABLED = config.getBoolean("perm-based-mob-cap.enabled");
|
||||
// Settings.MOB_CAP = config.getInt("perm-based-mob-cap.max");
|
||||
Settings.MAX_PLOTS = config.getInt("max_plots");
|
||||
if (Settings.MAX_PLOTS > 32767) {
|
||||
sendConsoleSenderMessage("&c`max_plots` Is set too high! This is a per player setting and does not need to be very large.");
|
||||
Settings.MAX_PLOTS = 32767;
|
||||
}
|
||||
|
||||
|
||||
Settings.SCHEMATIC_SAVE_PATH = config.getString("schematics.save_path");
|
||||
|
||||
Settings.OFFLINE_MODE = config.getBoolean("UUID.offline");
|
||||
@ -870,7 +680,7 @@ public class PlotMain {
|
||||
/**
|
||||
* Create a plotworld config section
|
||||
*
|
||||
* @param plotworld World to create the section for
|
||||
* @param plotString world to create the section for
|
||||
*/
|
||||
public static void createConfiguration(final PlotWorld plotworld) {
|
||||
final Map<String, Object> options = new HashMap<>();
|
||||
@ -1010,12 +820,12 @@ public class PlotMain {
|
||||
*
|
||||
* @param world to load
|
||||
*/
|
||||
public static void loadWorld(final World world) {
|
||||
public static void loadWorld(final String world) {
|
||||
if (world == null) {
|
||||
return;
|
||||
}
|
||||
final ChunkGenerator generator = world.getGenerator();
|
||||
loadWorld(world.getName(), generator);
|
||||
loadWorld(world, generator);
|
||||
}
|
||||
|
||||
public static void setupStyle() {
|
||||
@ -1170,7 +980,7 @@ public class PlotMain {
|
||||
/**
|
||||
* Remove a plot world
|
||||
*
|
||||
* @param world World to remove
|
||||
* @param String world to remove
|
||||
*/
|
||||
public static void removePlotWorld(final String world) {
|
||||
plots.remove(world);
|
||||
@ -1348,34 +1158,117 @@ public class PlotMain {
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the logger mechanics
|
||||
* Check a range of permissions e.g. 'plots.plot.<0-100>'<br> Returns highest integer in range.
|
||||
*
|
||||
* @param player to check
|
||||
* @param stub to check
|
||||
* @param range tp check
|
||||
*
|
||||
* @return permitted range
|
||||
*/
|
||||
private void setupLogger() {
|
||||
final File log = new File(getMain().getDataFolder() + File.separator + "logs" + File.separator + "plots.log");
|
||||
if (!log.exists()) {
|
||||
try {
|
||||
if (!new File(getMain().getDataFolder() + File.separator + "logs").mkdirs()) {
|
||||
sendConsoleSenderMessage(C.PREFIX.s() + "&cFailed to create logs folder. Do it manually.");
|
||||
}
|
||||
if (log.createNewFile()) {
|
||||
final FileWriter writer = new FileWriter(log);
|
||||
writer.write("Created at: " + new Date().toString() + "\n\n\n");
|
||||
writer.close();
|
||||
}
|
||||
} catch (final IOException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
public int hasPermissionRange(final Player player, final String stub, final int range) {
|
||||
if ((player == null) || player.isOp() || player.hasPermission(PlotMain.ADMIN_PERMISSION)) {
|
||||
return Byte.MAX_VALUE;
|
||||
}
|
||||
if (player.hasPermission(stub + ".*")) {
|
||||
return Byte.MAX_VALUE;
|
||||
}
|
||||
for (int i = range; i > 0; i--) {
|
||||
if (player.hasPermission(stub + "." + i)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
Logger.setup(log);
|
||||
Logger.add(LogLevel.GENERAL, "Logger enabled");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check a player for a permission<br> - Op has all permissions <br> - checks for '*' nodes
|
||||
*
|
||||
* @param player to check
|
||||
* @param perms to check
|
||||
*
|
||||
* @return true of player has permissions
|
||||
*/
|
||||
public boolean hasPermissions(final Player player, final String[] perms) {
|
||||
if ((player == null) || player.isOp() || player.hasPermission(PlotMain.ADMIN_PERMISSION)) {
|
||||
return true;
|
||||
}
|
||||
for (final String perm : perms) {
|
||||
boolean permitted = false;
|
||||
if (player.hasPermission(perm)) {
|
||||
permitted = true;
|
||||
} else {
|
||||
final String[] nodes = perm.split("\\.");
|
||||
final StringBuilder n = new StringBuilder();
|
||||
for (int i = 0; i < (nodes.length - 1); i++) {
|
||||
n.append(nodes[i]).append(".");
|
||||
if (player.hasPermission(n + "*")) {
|
||||
permitted = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!permitted) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check a player for a permission<br> - Op has all permissions <br> - checks for '*' nodes
|
||||
*
|
||||
* @param player to check
|
||||
* @param perm to check
|
||||
*
|
||||
* @return true if player has the permission
|
||||
*/
|
||||
public boolean hasPermission(final Player player, final String perm) {
|
||||
if ((player == null) || player.isOp() || player.hasPermission(PlotMain.ADMIN_PERMISSION)) {
|
||||
return true;
|
||||
}
|
||||
if (player.hasPermission(perm)) {
|
||||
return true;
|
||||
}
|
||||
final String[] nodes = perm.split("\\.");
|
||||
final StringBuilder n = new StringBuilder();
|
||||
for (int i = 0; i < (nodes.length - 1); i++) {
|
||||
n.append(nodes[i] + ("."));
|
||||
if (player.hasPermission(n + "*")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean callRemovePlot(String world, PlotId id) {
|
||||
final PlotDeleteEvent event = new PlotDeleteEvent(world, id);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
event.setCancelled(true);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendConsoleSenderMessage(String string) {
|
||||
if (BukkitMain.plugin == null || Bukkit.getServer().getConsoleSender() == null) {
|
||||
System.out.println(ChatColor.stripColor(ConsoleColors.fromString(string)));
|
||||
} else {
|
||||
String message = ChatColor.translateAlternateColorCodes('&', string);
|
||||
if (!Settings.CONSOLE_COLOR) {
|
||||
message = ChatColor.stripColor(message);
|
||||
}
|
||||
Bukkit.getServer().getConsoleSender().sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* On Load.
|
||||
*/
|
||||
@Override
|
||||
final public void onEnable() {
|
||||
public PlotMain() {
|
||||
PlotMain.main = this;
|
||||
// Setup the logger mechanics
|
||||
setupLogger();
|
||||
@ -1638,12 +1531,10 @@ public class PlotMain {
|
||||
Broadcast(C.ENABLED);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* On unload
|
||||
*/
|
||||
@Override
|
||||
final public void onDisable() {
|
||||
public void disable() {
|
||||
Logger.add(LogLevel.GENERAL, "Logger disabled");
|
||||
try {
|
||||
Logger.write();
|
||||
|
@ -0,0 +1,514 @@
|
||||
package com.intellectualcrafters.plot;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import com.intellectualcrafters.plot.commands.Cluster;
|
||||
import com.intellectualcrafters.plot.commands.MainCommand;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.database.MySQL;
|
||||
import com.intellectualcrafters.plot.database.SQLManager;
|
||||
import com.intellectualcrafters.plot.database.SQLite;
|
||||
import com.intellectualcrafters.plot.flag.AbstractFlag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.flag.FlagValue;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotManager;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.ClusterManager;
|
||||
import com.intellectualcrafters.plot.util.ExpireManager;
|
||||
import com.intellectualcrafters.plot.util.Logger;
|
||||
import com.intellectualcrafters.plot.util.Logger.LogLevel;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
|
||||
public class PlotSquared {
|
||||
|
||||
public static File styleFile;
|
||||
public static YamlConfiguration style;
|
||||
|
||||
public static File configFile;
|
||||
public static YamlConfiguration config;
|
||||
|
||||
public static File storageFile;
|
||||
public static YamlConfiguration storage;
|
||||
|
||||
public static PlotSquared THIS = null; // This class
|
||||
public static IPlotMain IMP = null; // Specific implementation of PlotSquared
|
||||
public static String VERSION = null;
|
||||
public static TaskManager TASK = null;
|
||||
public static Economy economy = null;
|
||||
|
||||
private final static HashMap<String, PlotWorld> plotworlds = new HashMap<>();
|
||||
private final static HashMap<String, PlotManager> plotmanagers = new HashMap<>();
|
||||
private static LinkedHashMap<String, HashMap<PlotId, Plot>> plots;
|
||||
|
||||
private static MySQL mySQL;
|
||||
public static Connection connection;
|
||||
|
||||
public static MySQL getMySQL() {
|
||||
return mySQL;
|
||||
}
|
||||
|
||||
public static Connection getConnection() {
|
||||
return connection;
|
||||
}
|
||||
|
||||
public PlotSquared(IPlotMain imp_class) {
|
||||
THIS = this;
|
||||
IMP = imp_class;
|
||||
VERSION = IMP.getVersion();
|
||||
|
||||
C.setupTranslations();
|
||||
C.saveTranslations();
|
||||
|
||||
if (getJavaVersion() < 1.7) {
|
||||
log(C.PREFIX.s() + "&cYour java version is outdated. Please update to at least 1.7.");
|
||||
// Didn't know of any other link :D
|
||||
log(C.PREFIX.s() + "&cURL: &6https://java.com/en/download/index.jsp");
|
||||
IMP.disable();
|
||||
return;
|
||||
}
|
||||
if (getJavaVersion() < 1.8) {
|
||||
log(C.PREFIX.s() + "&cIt's really recommended to run Java 1.8, as it increases performance");
|
||||
}
|
||||
|
||||
TASK = IMP.getTaskManager();
|
||||
if (Settings.KILL_ROAD_MOBS) {
|
||||
IMP.runEntityTask();
|
||||
}
|
||||
if (C.ENABLED.s().length() > 0) {
|
||||
log(C.ENABLED.s());
|
||||
}
|
||||
|
||||
setupConfigs();
|
||||
setupDefaultFlags();
|
||||
setupDatabase();
|
||||
|
||||
// Events
|
||||
IMP.registerCommands();
|
||||
IMP.registerPlayerEvents();
|
||||
IMP.registerInventoryEvents();
|
||||
IMP.registerPlotPlusEvents();
|
||||
IMP.registerForceFieldEvents();
|
||||
IMP.registerWorldEditEvents();
|
||||
|
||||
if (Settings.AUTO_CLEAR) {
|
||||
ExpireManager.runTask();
|
||||
}
|
||||
|
||||
economy = IMP.getEconomy();
|
||||
}
|
||||
|
||||
public void disable() {
|
||||
try {
|
||||
connection.close();
|
||||
mySQL.closeConnection();
|
||||
} catch (NullPointerException | SQLException e) {
|
||||
if (connection != null) {
|
||||
log("&cCould not close mysql connection!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void log(String message) {
|
||||
IMP.log(message);
|
||||
}
|
||||
|
||||
public void setupDatabase() {
|
||||
final String[] tables;
|
||||
if (Settings.ENABLE_CLUSTERS) {
|
||||
MainCommand.subCommands.add(new Cluster());
|
||||
tables = new String[]{"plot_trusted", "plot_ratings", "plot_comments", "cluster"};
|
||||
}
|
||||
else {
|
||||
tables = new String[]{"plot_trusted", "plot_ratings", "plot_comments"};
|
||||
}
|
||||
if (Settings.DB.USE_MYSQL) {
|
||||
try {
|
||||
mySQL = new MySQL(THIS, Settings.DB.HOST_NAME, Settings.DB.PORT, Settings.DB.DATABASE, Settings.DB.USER, Settings.DB.PASSWORD);
|
||||
connection = mySQL.openConnection();
|
||||
{
|
||||
if (DBFunc.dbManager == null) {
|
||||
DBFunc.dbManager = new SQLManager(connection, Settings.DB.PREFIX);
|
||||
}
|
||||
final DatabaseMetaData meta = connection.getMetaData();
|
||||
ResultSet res = meta.getTables(null, null, Settings.DB.PREFIX + "plot", null);
|
||||
if (!res.next()) {
|
||||
DBFunc.createTables("mysql", true);
|
||||
} else {
|
||||
for (final String table : tables) {
|
||||
res = meta.getTables(null, null, Settings.DB.PREFIX + table, null);
|
||||
if (!res.next()) {
|
||||
DBFunc.createTables("mysql", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
log("&c[Plots] MySQL is not setup correctly. The plugin will disable itself.");
|
||||
if ((config == null) || config.getBoolean("debug")) {
|
||||
log("&d==== Here is an ugly stacktrace if you are interested in those things ====");
|
||||
e.printStackTrace();
|
||||
log("&d==== End of stacktrace ====");
|
||||
log("&6Please go to the PlotSquared 'storage.yml' and configure MySQL correctly.");
|
||||
}
|
||||
IMP.disable();
|
||||
return;
|
||||
}
|
||||
plots = DBFunc.getPlots();
|
||||
if (Settings.ENABLE_CLUSTERS) {
|
||||
ClusterManager.clusters = DBFunc.getClusters();
|
||||
}
|
||||
}
|
||||
else if (Settings.DB.USE_MONGO) {
|
||||
// DBFunc.dbManager = new MongoManager();
|
||||
log(C.PREFIX.s() + "MongoDB is not yet implemented");
|
||||
}
|
||||
else if (Settings.DB.USE_SQLITE) {
|
||||
try {
|
||||
connection = new SQLite(THIS, IMP.getDirectory() + File.separator + Settings.DB.SQLITE_DB + ".db").openConnection();
|
||||
{
|
||||
DBFunc.dbManager = new SQLManager(connection, Settings.DB.PREFIX);
|
||||
final DatabaseMetaData meta = connection.getMetaData();
|
||||
ResultSet res = meta.getTables(null, null, Settings.DB.PREFIX + "plot", null);
|
||||
if (!res.next()) {
|
||||
DBFunc.createTables("sqlite", true);
|
||||
} else {
|
||||
for (final String table : tables) {
|
||||
res = meta.getTables(null, null, Settings.DB.PREFIX + table, null);
|
||||
if (!res.next()) {
|
||||
DBFunc.createTables("sqlite", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
log(C.PREFIX.s() + "&cFailed to open SQLite connection. The plugin will disable itself.");
|
||||
log("&9==== Here is an ugly stacktrace, if you are interested in those things ===");
|
||||
e.printStackTrace();
|
||||
IMP.disable();
|
||||
return;
|
||||
}
|
||||
plots = DBFunc.getPlots();
|
||||
if (Settings.ENABLE_CLUSTERS) {
|
||||
ClusterManager.clusters = DBFunc.getClusters();
|
||||
}
|
||||
} else {
|
||||
log(C.PREFIX + "&cNo storage type is set!");
|
||||
IMP.disable();
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void setupDefaultFlags() {
|
||||
final List<String> booleanFlags = Arrays.asList("notify-enter", "notify-leave", "item-drop", "invincible", "instabreak", "drop-protection", "forcefield", "titles", "pve", "pvp", "no-worldedit");
|
||||
final List<String> intervalFlags = Arrays.asList("feed", "heal");
|
||||
final List<String> stringFlags = Arrays.asList("greeting", "farewell");
|
||||
for (final String flag : stringFlags) {
|
||||
FlagManager.addFlag(new AbstractFlag(flag));
|
||||
}
|
||||
for (final String flag : intervalFlags) {
|
||||
FlagManager.addFlag(new AbstractFlag(flag, new FlagValue.IntervalValue()));
|
||||
}
|
||||
for (final String flag : booleanFlags) {
|
||||
FlagManager.addFlag(new AbstractFlag(flag, new FlagValue.BooleanValue()));
|
||||
}
|
||||
FlagManager.addFlag(new AbstractFlag("fly", new FlagValue.BooleanValue()));
|
||||
|
||||
FlagManager.addFlag(new AbstractFlag("explosion", new FlagValue.BooleanValue()));
|
||||
|
||||
FlagManager.addFlag(new AbstractFlag("hostile-interact", new FlagValue.BooleanValue()));
|
||||
FlagManager.addFlag(new AbstractFlag("hostile-attack", new FlagValue.BooleanValue()));
|
||||
|
||||
FlagManager.addFlag(new AbstractFlag("animal-interact", new FlagValue.BooleanValue()));
|
||||
FlagManager.addFlag(new AbstractFlag("animal-attack", new FlagValue.BooleanValue()));
|
||||
|
||||
FlagManager.addFlag(new AbstractFlag("tamed-interact", new FlagValue.BooleanValue()));
|
||||
FlagManager.addFlag(new AbstractFlag("tamed-attack", new FlagValue.BooleanValue()));
|
||||
|
||||
FlagManager.addFlag(new AbstractFlag("misc-interact", new FlagValue.BooleanValue()));
|
||||
|
||||
FlagManager.addFlag(new AbstractFlag("hanging-place", new FlagValue.BooleanValue()));
|
||||
FlagManager.addFlag(new AbstractFlag("hanging-break", new FlagValue.BooleanValue()));
|
||||
|
||||
FlagManager.addFlag(new AbstractFlag("vehicle-use", new FlagValue.BooleanValue()));
|
||||
FlagManager.addFlag(new AbstractFlag("vehicle-place", new FlagValue.BooleanValue()));
|
||||
FlagManager.addFlag(new AbstractFlag("vehicle-break", new FlagValue.BooleanValue()));
|
||||
|
||||
FlagManager.addFlag(new AbstractFlag("place", new FlagValue.PlotBlockListValue()));
|
||||
FlagManager.addFlag(new AbstractFlag("break", new FlagValue.PlotBlockListValue()));
|
||||
FlagManager.addFlag(new AbstractFlag("use", new FlagValue.PlotBlockListValue()));
|
||||
|
||||
FlagManager.addFlag(new AbstractFlag("gamemode") {
|
||||
@Override
|
||||
public String parseValueRaw(final String value) {
|
||||
switch (value) {
|
||||
case "creative":
|
||||
case "c":
|
||||
case "1":
|
||||
return "creative";
|
||||
case "survival":
|
||||
case "s":
|
||||
case "0":
|
||||
return "survival";
|
||||
case "adventure":
|
||||
case "a":
|
||||
case "2":
|
||||
return "adventure";
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValueDesc() {
|
||||
return "Flag value must be a gamemode: 'creative' , 'survival' or 'adventure'";
|
||||
}
|
||||
});
|
||||
|
||||
FlagManager.addFlag(new AbstractFlag("price", new FlagValue.UnsignedDoubleValue()));
|
||||
|
||||
FlagManager.addFlag(new AbstractFlag("time", new FlagValue.LongValue()));
|
||||
|
||||
FlagManager.addFlag(new AbstractFlag("weather") {
|
||||
@Override
|
||||
public String parseValueRaw(final String value) {
|
||||
switch (value) {
|
||||
case "rain":
|
||||
case "storm":
|
||||
case "on":
|
||||
return "rain";
|
||||
case "clear":
|
||||
case "off":
|
||||
case "sun":
|
||||
return "clear";
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValueDesc() {
|
||||
return "Flag value must be weather type: 'clear' or 'rain'";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void setupConfig() {
|
||||
config.set("version", VERSION);
|
||||
final Map<String, Object> options = new HashMap<>();
|
||||
options.put("teleport.delay", 0);
|
||||
options.put("auto_update", false);
|
||||
options.put("clusters.enabled", Settings.ENABLE_CLUSTERS);
|
||||
options.put("plotme-alias", Settings.USE_PLOTME_ALIAS);
|
||||
options.put("plotme-convert.enabled", Settings.CONVERT_PLOTME);
|
||||
options.put("claim.max-auto-area", Settings.MAX_AUTO_SIZE);
|
||||
options.put("UUID.offline", Settings.OFFLINE_MODE);
|
||||
options.put("kill_road_mobs", Settings.KILL_ROAD_MOBS_DEFAULT);
|
||||
options.put("mob_pathfinding", Settings.MOB_PATHFINDING_DEFAULT);
|
||||
options.put("console.color", Settings.CONSOLE_COLOR);
|
||||
options.put("metrics", true);
|
||||
options.put("debug", true);
|
||||
options.put("clear.auto.enabled", false);
|
||||
options.put("clear.auto.days", 365);
|
||||
options.put("clear.check-disk", Settings.AUTO_CLEAR_CHECK_DISK);
|
||||
options.put("clear.on.ban", false);
|
||||
options.put("max_plots", Settings.MAX_PLOTS);
|
||||
options.put("schematics.save_path", Settings.SCHEMATIC_SAVE_PATH);
|
||||
options.put("uuid.read-from-disk", Settings.UUID_FROM_DISK);
|
||||
options.put("titles", Settings.TITLES);
|
||||
options.put("teleport.on_login", Settings.TELEPORT_ON_LOGIN);
|
||||
options.put("worldedit.require-selection-in-mask", Settings.REQUIRE_SELECTION);
|
||||
|
||||
for (final Entry<String, Object> node : options.entrySet()) {
|
||||
if (!config.contains(node.getKey())) {
|
||||
config.set(node.getKey(), node.getValue());
|
||||
}
|
||||
}
|
||||
Settings.ENABLE_CLUSTERS = config.getBoolean("clusters.enabled");
|
||||
Settings.DEBUG = config.getBoolean("debug");
|
||||
if (Settings.DEBUG) {
|
||||
log(C.PREFIX.s() + "&6Debug Mode Enabled (Default). Edit the config to turn this off.");
|
||||
}
|
||||
Settings.TELEPORT_DELAY = config.getInt("teleport.delay");
|
||||
Settings.CONSOLE_COLOR = config.getBoolean("console.color");
|
||||
Settings.TELEPORT_ON_LOGIN = config.getBoolean("teleport.on_login");
|
||||
Settings.USE_PLOTME_ALIAS = config.getBoolean("plotme-alias");
|
||||
Settings.CONVERT_PLOTME = config.getBoolean("plotme-convert.enabled");
|
||||
Settings.KILL_ROAD_MOBS = config.getBoolean("kill_road_mobs");
|
||||
Settings.MOB_PATHFINDING = config.getBoolean("mob_pathf"
|
||||
+ "inding");
|
||||
Settings.METRICS = config.getBoolean("metrics");
|
||||
Settings.AUTO_CLEAR_DAYS = config.getInt("clear.auto.days");
|
||||
Settings.AUTO_CLEAR_CHECK_DISK = config.getBoolean("clear.check-disk");
|
||||
Settings.MAX_AUTO_SIZE = config.getInt("claim.max-auto-area");
|
||||
Settings.AUTO_CLEAR = config.getBoolean("clear.auto.enabled");
|
||||
Settings.TITLES = config.getBoolean("titles");
|
||||
Settings.MAX_PLOTS = config.getInt("max_plots");
|
||||
if (Settings.MAX_PLOTS > 32767) {
|
||||
log("&c`max_plots` Is set too high! This is a per player setting and does not need to be very large.");
|
||||
Settings.MAX_PLOTS = 32767;
|
||||
}
|
||||
Settings.SCHEMATIC_SAVE_PATH = config.getString("schematics.save_path");
|
||||
|
||||
Settings.OFFLINE_MODE = config.getBoolean("UUID.offline");
|
||||
Settings.UUID_FROM_DISK = config.getBoolean("uuid.read-from-disk");
|
||||
|
||||
Settings.REQUIRE_SELECTION = config.getBoolean("worldedit.require-selection-in-mask");
|
||||
}
|
||||
|
||||
public static void setupConfigs() {
|
||||
final File folder = new File(IMP.getDirectory() + File.separator + "config");
|
||||
if (!folder.exists() && !folder.mkdirs()) {
|
||||
log(C.PREFIX.s() + "&cFailed to create the /plugins/config folder. Please create it manually.");
|
||||
}
|
||||
try {
|
||||
styleFile = new File(IMP.getDirectory() + File.separator + "translations" + File.separator + "style.yml");
|
||||
if (!styleFile.exists()) {
|
||||
if (!styleFile.createNewFile()) {
|
||||
log("Could not create the style file, please create \"translations/style.yml\" manually");
|
||||
}
|
||||
}
|
||||
style = YamlConfiguration.loadConfiguration(styleFile);
|
||||
setupStyle();
|
||||
} catch (final Exception err) {
|
||||
Logger.add(LogLevel.DANGER, "Failed to save style.yml");
|
||||
System.out.println("failed to save style.yml");
|
||||
}
|
||||
try {
|
||||
configFile = new File(IMP.getDirectory() + File.separator + "config" + File.separator + "settings.yml");
|
||||
if (!configFile.exists()) {
|
||||
if (!configFile.createNewFile()) {
|
||||
log("Could not create the settings file, please create \"settings.yml\" manually.");
|
||||
}
|
||||
}
|
||||
config = YamlConfiguration.loadConfiguration(configFile);
|
||||
setupConfig();
|
||||
} catch (final Exception err_trans) {
|
||||
Logger.add(LogLevel.DANGER, "Failed to save settings.yml");
|
||||
System.out.println("Failed to save settings.yml");
|
||||
}
|
||||
try {
|
||||
storageFile = new File(IMP.getDirectory() + File.separator + "config" + File.separator + "storage.yml");
|
||||
if (!storageFile.exists()) {
|
||||
if (!storageFile.createNewFile()) {
|
||||
log("Could not the storage settings file, please create \"storage.yml\" manually.");
|
||||
}
|
||||
}
|
||||
storage = YamlConfiguration.loadConfiguration(storageFile);
|
||||
setupStorage();
|
||||
} catch (final Exception err_trans) {
|
||||
Logger.add(LogLevel.DANGER, "Failed to save storage.yml");
|
||||
System.out.println("Failed to save storage.yml");
|
||||
}
|
||||
try {
|
||||
style.save(styleFile);
|
||||
config.save(configFile);
|
||||
storage.save(storageFile);
|
||||
} catch (final IOException e) {
|
||||
Logger.add(LogLevel.DANGER, "Configuration file saving failed");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void setupStorage() {
|
||||
storage.set("version", VERSION);
|
||||
final Map<String, Object> options = new HashMap<>();
|
||||
options.put("mysql.use", false);
|
||||
options.put("sqlite.use", true);
|
||||
options.put("sqlite.db", "storage");
|
||||
options.put("mysql.host", "localhost");
|
||||
options.put("mysql.port", "3306");
|
||||
options.put("mysql.user", "root");
|
||||
options.put("mysql.password", "password");
|
||||
options.put("mysql.database", "plot_db");
|
||||
options.put("prefix", "");
|
||||
for (final Entry<String, Object> node : options.entrySet()) {
|
||||
if (!storage.contains(node.getKey())) {
|
||||
storage.set(node.getKey(), node.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void showDebug() {
|
||||
Settings.DB.USE_MYSQL = storage.getBoolean("mysql.use");
|
||||
Settings.DB.USER = storage.getString("mysql.user");
|
||||
Settings.DB.PASSWORD = storage.getString("mysql.password");
|
||||
Settings.DB.HOST_NAME = storage.getString("mysql.host");
|
||||
Settings.DB.PORT = storage.getString("mysql.port");
|
||||
Settings.DB.DATABASE = storage.getString("mysql.database");
|
||||
Settings.DB.USE_SQLITE = storage.getBoolean("sqlite.use");
|
||||
Settings.DB.SQLITE_DB = storage.getString("sqlite.db");
|
||||
Settings.DB.PREFIX = storage.getString("prefix");
|
||||
Settings.METRICS = config.getBoolean("metrics");
|
||||
Settings.AUTO_CLEAR = config.getBoolean("clear.auto.enabled");
|
||||
Settings.AUTO_CLEAR_DAYS = config.getInt("clear.auto.days");
|
||||
Settings.DELETE_PLOTS_ON_BAN = config.getBoolean("clear.on.ban");
|
||||
Settings.API_URL = config.getString("uuid.api.location");
|
||||
Settings.CUSTOM_API = config.getBoolean("uuid.api.custom");
|
||||
Settings.UUID_FECTHING = config.getBoolean("uuid.fetching");
|
||||
|
||||
C.COLOR_1 = ChatColor.getByChar(style.getString("color.1"));
|
||||
C.COLOR_2 = ChatColor.getByChar(style.getString("color.2"));
|
||||
C.COLOR_3 = ChatColor.getByChar(style.getString("color.3"));
|
||||
C.COLOR_4 = ChatColor.getByChar(style.getString("color.4"));
|
||||
if (Settings.DEBUG) {
|
||||
final Map<String, String> settings = new HashMap<>();
|
||||
settings.put("Kill Road Mobs", "" + Settings.KILL_ROAD_MOBS);
|
||||
settings.put("Use Metrics", "" + Settings.METRICS);
|
||||
settings.put("Delete Plots On Ban", "" + Settings.DELETE_PLOTS_ON_BAN);
|
||||
settings.put("Mob Pathfinding", "" + Settings.MOB_PATHFINDING);
|
||||
settings.put("DB Mysql Enabled", "" + Settings.DB.USE_MYSQL);
|
||||
settings.put("DB SQLite Enabled", "" + Settings.DB.USE_SQLITE);
|
||||
settings.put("Auto Clear Enabled", "" + Settings.AUTO_CLEAR);
|
||||
settings.put("Auto Clear Days", "" + Settings.AUTO_CLEAR_DAYS);
|
||||
settings.put("Schematics Save Path", "" + Settings.SCHEMATIC_SAVE_PATH);
|
||||
settings.put("API Location", "" + Settings.API_URL);
|
||||
for (final Entry<String, String> setting : settings.entrySet()) {
|
||||
log(C.PREFIX.s() + String.format("&cKey: &6%s&c, Value: &6%s", setting.getKey(), setting.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void setupStyle() {
|
||||
style.set("version", VERSION);
|
||||
final Map<String, Object> o = new HashMap<>();
|
||||
o.put("color.1", C.COLOR_1.getChar());
|
||||
o.put("color.2", C.COLOR_2.getChar());
|
||||
o.put("color.3", C.COLOR_3.getChar());
|
||||
o.put("color.4", C.COLOR_4.getChar());
|
||||
for (final Entry<String, Object> node : o.entrySet()) {
|
||||
if (!style.contains(node.getKey())) {
|
||||
style.set(node.getKey(), node.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static double getJavaVersion() {
|
||||
return Double.parseDouble(System.getProperty("java.specification.version"));
|
||||
}
|
||||
|
||||
public static Set<String> getPlotWorlds() {
|
||||
return plotworlds.keySet();
|
||||
}
|
||||
}
|
@ -146,7 +146,7 @@ public class DebugExec extends SubCommand {
|
||||
Trim.sendMessage(" - MCA #: " + empty.size());
|
||||
Trim.sendMessage(" - CHUNKS: " + (empty.size() * 1024) + " (max)");
|
||||
Trim.sendMessage("Exporting log for manual approval...");
|
||||
final File file = new File(PlotMain.getMain().getDataFolder() + File.separator + "trim.txt");
|
||||
final File file = new File(PlotMain.getMain().getDirectory() + File.separator + "trim.txt");
|
||||
PrintWriter writer;
|
||||
try {
|
||||
writer = new PrintWriter(file);
|
||||
|
@ -35,7 +35,7 @@ import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitTaskManager;
|
||||
|
||||
/**
|
||||
* Created 2014-08-01 for PlotSquared
|
||||
|
@ -46,7 +46,7 @@ public class Reload extends SubCommand {
|
||||
final PlotWorld plotworld = PlotMain.getWorldSettings(pw);
|
||||
plotworld.loadDefaultConfiguration(PlotMain.config.getConfigurationSection("worlds." + pw));
|
||||
}
|
||||
PlotMain.BroadcastWithPerms(C.RELOADED_CONFIGS);
|
||||
MainUtil.sendMessage(plr, C.RELOADED_CONFIGS);
|
||||
} catch (final Exception e) {
|
||||
PlayerFunctions.sendMessage(plr, C.RELOAD_FAILED);
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.ExpireManager;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitTaskManager;
|
||||
|
||||
public class Trim extends SubCommand {
|
||||
|
||||
@ -122,7 +122,7 @@ public class Trim extends SubCommand {
|
||||
if (Trim.TASK) {
|
||||
return false;
|
||||
}
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
BukkitTaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String directory = world.getName() + File.separator + "region";
|
||||
@ -169,7 +169,7 @@ public class Trim extends SubCommand {
|
||||
}
|
||||
}
|
||||
Trim.TASK = false;
|
||||
TaskManager.runTaskAsync(whenDone);
|
||||
BukkitTaskManager.runTaskAsync(whenDone);
|
||||
}
|
||||
});
|
||||
Trim.TASK = true;
|
||||
@ -197,7 +197,7 @@ public class Trim extends SubCommand {
|
||||
empty.addAll(chunks);
|
||||
System.out.print("DONE!");
|
||||
Trim.TASK = false;
|
||||
TaskManager.runTaskAsync(whenDone);
|
||||
BukkitTaskManager.runTaskAsync(whenDone);
|
||||
Bukkit.getScheduler().cancelTask(Trim.TASK_ID);
|
||||
return;
|
||||
}
|
||||
|
@ -27,6 +27,8 @@ import java.sql.SQLException;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotSquared;
|
||||
|
||||
/**
|
||||
* Abstract Database class, serves as a base for any connection method (MySQL, SQLite, etc.)
|
||||
*
|
||||
@ -38,15 +40,15 @@ public abstract class Database {
|
||||
/**
|
||||
* Plugin instance, use for plugin.getDataFolder()
|
||||
*/
|
||||
protected final Plugin plugin;
|
||||
protected final PlotSquared plotsquared;
|
||||
|
||||
/**
|
||||
* Creates a new Database
|
||||
*
|
||||
* @param plugin Plugin instance
|
||||
* @param plotsquared Plugin instance
|
||||
*/
|
||||
protected Database(final Plugin plugin) {
|
||||
this.plugin = plugin;
|
||||
protected Database(final PlotSquared plotsquared) {
|
||||
this.plotsquared = plotsquared;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -29,6 +29,8 @@ import java.sql.Statement;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotSquared;
|
||||
|
||||
/**
|
||||
* Connects to and uses a MySQL database
|
||||
*
|
||||
@ -54,8 +56,8 @@ public class MySQL extends Database {
|
||||
* @param username Username
|
||||
* @param password Password
|
||||
*/
|
||||
public MySQL(final Plugin plugin, final String hostname, final String port, final String database, final String username, final String password) {
|
||||
super(plugin);
|
||||
public MySQL(final PlotSquared plotsquared, final String hostname, final String port, final String database, final String username, final String password) {
|
||||
super(plotsquared);
|
||||
this.hostname = hostname;
|
||||
this.port = port;
|
||||
this.database = database;
|
||||
@ -64,6 +66,7 @@ public class MySQL extends Database {
|
||||
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);
|
||||
|
@ -49,7 +49,7 @@ import com.intellectualcrafters.plot.object.PlotClusterId;
|
||||
import com.intellectualcrafters.plot.object.PlotComment;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.util.ClusterManager;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitTaskManager;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
@ -114,7 +114,7 @@ public class SQLManager implements AbstractDB {
|
||||
*/
|
||||
@Override
|
||||
public void setOwner(final Plot plot, final UUID uuid) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
BukkitTaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
@ -310,7 +310,7 @@ public class SQLManager implements AbstractDB {
|
||||
*/
|
||||
@Override
|
||||
public void createPlot(final Plot plot) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
BukkitTaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PreparedStatement stmt = null;
|
||||
@ -332,7 +332,7 @@ public class SQLManager implements AbstractDB {
|
||||
|
||||
@Override
|
||||
public void createPlotAndSettings(final Plot plot) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
BukkitTaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PreparedStatement stmt = null;
|
||||
@ -412,7 +412,7 @@ public class SQLManager implements AbstractDB {
|
||||
@Override
|
||||
public void delete(final String world, final Plot plot) {
|
||||
PlotMain.removePlot(world, plot.id, false);
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
BukkitTaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PreparedStatement stmt = null;
|
||||
@ -453,7 +453,7 @@ public class SQLManager implements AbstractDB {
|
||||
*/
|
||||
@Override
|
||||
public void createPlotSettings(final int id, final Plot plot) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
BukkitTaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PreparedStatement stmt = null;
|
||||
@ -735,7 +735,7 @@ public class SQLManager implements AbstractDB {
|
||||
@Override
|
||||
public void setMerged(final String world, final Plot plot, final boolean[] merged) {
|
||||
plot.settings.setMerged(merged);
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
BukkitTaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
@ -758,7 +758,7 @@ public class SQLManager implements AbstractDB {
|
||||
|
||||
@Override
|
||||
public void swapPlots(final Plot p1, final Plot p2) {
|
||||
TaskManager.runTaskAsync(
|
||||
BukkitTaskManager.runTaskAsync(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -795,7 +795,7 @@ public class SQLManager implements AbstractDB {
|
||||
|
||||
@Override
|
||||
public void movePlot(final String world, final PlotId originalPlot, final PlotId newPlot) {
|
||||
TaskManager.runTaskAsync(
|
||||
BukkitTaskManager.runTaskAsync(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -826,7 +826,7 @@ public class SQLManager implements AbstractDB {
|
||||
flag_string.append(flag.getKey() + ":" + flag.getValueString().replaceAll(":", "\u00AF").replaceAll(",", "\u00B4"));
|
||||
i++;
|
||||
}
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
BukkitTaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
@ -851,7 +851,7 @@ public class SQLManager implements AbstractDB {
|
||||
}
|
||||
}
|
||||
final String flag_string = StringUtils.join(newflags, ",");
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
BukkitTaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
@ -875,7 +875,7 @@ public class SQLManager implements AbstractDB {
|
||||
@Override
|
||||
public void setAlias(final String world, final Plot plot, final String alias) {
|
||||
plot.settings.setAlias(alias);
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
BukkitTaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PreparedStatement stmt = null;
|
||||
@ -969,7 +969,7 @@ public class SQLManager implements AbstractDB {
|
||||
*/
|
||||
@Override
|
||||
public void setPosition(final String world, final Plot plot, final String position) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
BukkitTaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PreparedStatement stmt = null;
|
||||
@ -1042,7 +1042,7 @@ public class SQLManager implements AbstractDB {
|
||||
|
||||
@Override
|
||||
public void removeComment(final String world, final Plot plot, final PlotComment comment) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
BukkitTaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
@ -1104,7 +1104,7 @@ public class SQLManager implements AbstractDB {
|
||||
|
||||
@Override
|
||||
public void setComment(final String world, final Plot plot, final PlotComment comment) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
BukkitTaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
@ -1130,7 +1130,7 @@ public class SQLManager implements AbstractDB {
|
||||
*/
|
||||
@Override
|
||||
public void removeHelper(final String world, final Plot plot, final UUID uuid) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
BukkitTaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
@ -1153,7 +1153,7 @@ public class SQLManager implements AbstractDB {
|
||||
*/
|
||||
@Override
|
||||
public void removeTrusted(final String world, final Plot plot, final UUID uuid) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
BukkitTaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
@ -1176,7 +1176,7 @@ public class SQLManager implements AbstractDB {
|
||||
*/
|
||||
@Override
|
||||
public void setHelper(final String world, final Plot plot, final UUID uuid) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
BukkitTaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
@ -1194,7 +1194,7 @@ public class SQLManager implements AbstractDB {
|
||||
}
|
||||
|
||||
public void setHelper(final int id, final UUID uuid) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
BukkitTaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
@ -1217,7 +1217,7 @@ public class SQLManager implements AbstractDB {
|
||||
*/
|
||||
@Override
|
||||
public void setTrusted(final String world, final Plot plot, final UUID uuid) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
BukkitTaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
@ -1240,7 +1240,7 @@ public class SQLManager implements AbstractDB {
|
||||
*/
|
||||
@Override
|
||||
public void removeDenied(final String world, final Plot plot, final UUID uuid) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
BukkitTaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
@ -1263,7 +1263,7 @@ public class SQLManager implements AbstractDB {
|
||||
*/
|
||||
@Override
|
||||
public void setDenied(final String world, final Plot plot, final UUID uuid) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
BukkitTaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
@ -1303,7 +1303,7 @@ public class SQLManager implements AbstractDB {
|
||||
@Override
|
||||
public void delete(final PlotCluster cluster) {
|
||||
ClusterManager.removeCluster(cluster);
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
BukkitTaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PreparedStatement stmt = null;
|
||||
@ -1560,7 +1560,7 @@ public class SQLManager implements AbstractDB {
|
||||
flag_string.append(flag.getKey() + ":" + flag.getValueString().replaceAll(":", "\u00AF").replaceAll(",", "\u00B4"));
|
||||
i++;
|
||||
}
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
BukkitTaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
@ -1581,7 +1581,7 @@ public class SQLManager implements AbstractDB {
|
||||
@Override
|
||||
public void setClusterName(final PlotCluster cluster, final String name) {
|
||||
cluster.settings.setAlias(name);
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
BukkitTaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PreparedStatement stmt = null;
|
||||
@ -1602,7 +1602,7 @@ public class SQLManager implements AbstractDB {
|
||||
|
||||
@Override
|
||||
public void removeHelper(final PlotCluster cluster, final UUID uuid) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
BukkitTaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
@ -1621,7 +1621,7 @@ public class SQLManager implements AbstractDB {
|
||||
|
||||
@Override
|
||||
public void setHelper(final PlotCluster cluster, final UUID uuid) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
BukkitTaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
@ -1640,7 +1640,7 @@ public class SQLManager implements AbstractDB {
|
||||
|
||||
@Override
|
||||
public void createCluster(final PlotCluster cluster) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
BukkitTaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PreparedStatement stmt = null;
|
||||
@ -1675,7 +1675,7 @@ public class SQLManager implements AbstractDB {
|
||||
final PlotId pos2 = new PlotId(current.getP2().x, current.getP2().y);
|
||||
current.setP1(resize.pos1);
|
||||
current.setP2(resize.pos2);
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
BukkitTaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PreparedStatement stmt = null;
|
||||
@ -1698,7 +1698,7 @@ public class SQLManager implements AbstractDB {
|
||||
|
||||
@Override
|
||||
public void setPosition(final PlotCluster cluster, final String position) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
BukkitTaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PreparedStatement stmt = null;
|
||||
@ -1766,7 +1766,7 @@ public class SQLManager implements AbstractDB {
|
||||
|
||||
@Override
|
||||
public void removeInvited(final PlotCluster cluster, final UUID uuid) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
BukkitTaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
@ -1786,7 +1786,7 @@ public class SQLManager implements AbstractDB {
|
||||
|
||||
@Override
|
||||
public void setInvited(String world, final PlotCluster cluster, final UUID uuid) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
BukkitTaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
|
@ -32,6 +32,8 @@ import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotSquared;
|
||||
|
||||
/**
|
||||
* Connects to and uses a SQLite database
|
||||
*
|
||||
@ -49,8 +51,8 @@ public class SQLite extends Database {
|
||||
* @param plugin Plugin instance
|
||||
* @param dbLocation Location of the Database (Must end in .db)
|
||||
*/
|
||||
public SQLite(final Plugin plugin, final String dbLocation) {
|
||||
super(plugin);
|
||||
public SQLite(final PlotSquared plotsquared, final String dbLocation) {
|
||||
super(plotsquared);
|
||||
this.dbLocation = dbLocation;
|
||||
}
|
||||
|
||||
@ -59,7 +61,7 @@ public class SQLite extends Database {
|
||||
if (checkConnection()) {
|
||||
return this.connection;
|
||||
}
|
||||
if (!this.plugin.getDataFolder().exists()) {
|
||||
if (!this.plotsquared.IMP.getDirectory().exists()) {
|
||||
this.plugin.getDataFolder().mkdirs();
|
||||
}
|
||||
final File file = new File(this.dbLocation);
|
||||
|
@ -20,7 +20,7 @@ import com.intellectualcrafters.plot.object.RegionWrapper;
|
||||
import com.intellectualcrafters.plot.util.SetBlockManager;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitTaskManager;
|
||||
|
||||
public class AugmentedPopulator extends BlockPopulator {
|
||||
|
||||
@ -127,7 +127,7 @@ public class AugmentedPopulator extends BlockPopulator {
|
||||
if (this.o) {
|
||||
chunk.load(true);
|
||||
populateBlocks(world, rand, X, Z, x, z, check);
|
||||
TaskManager.runTaskLater(new Runnable() {
|
||||
BukkitTaskManager.runTaskLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
populateBiome(world, x, z);
|
||||
@ -137,13 +137,13 @@ public class AugmentedPopulator extends BlockPopulator {
|
||||
}, 20);
|
||||
}
|
||||
else {
|
||||
TaskManager.runTaskLater(new Runnable() {
|
||||
BukkitTaskManager.runTaskLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
populateBiome(world, x, z);
|
||||
}
|
||||
}, 20 + rand.nextInt(10));
|
||||
TaskManager.runTaskLater(new Runnable() {
|
||||
BukkitTaskManager.runTaskLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
chunk.load(true);
|
||||
|
@ -46,8 +46,8 @@ import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
||||
import com.intellectualcrafters.plot.util.SchematicHandler;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitTaskManager;
|
||||
|
||||
@SuppressWarnings("deprecation") public class HybridPlotManager extends ClassicPlotManager {
|
||||
|
||||
@ -147,7 +147,7 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
CompoundTag sideroad = SchematicHandler.getCompoundTag(world, pos1, pos2);
|
||||
CompoundTag intersection = SchematicHandler.getCompoundTag(world, pos3, pos4);
|
||||
|
||||
String dir = PlotMain.getMain().getDataFolder() + File.separator + "schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator + plot.world + File.separator;
|
||||
String dir = PlotMain.getMain().getDirectory() + File.separator + "schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator + plot.world + File.separator;
|
||||
|
||||
SchematicHandler.save(sideroad, dir + "sideroad.schematic");
|
||||
SchematicHandler.save(intersection, dir + "intersection.schematic");
|
||||
@ -734,7 +734,7 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
@Override
|
||||
public void run() {
|
||||
PlotHelper.setCuboid(world, new Location(world, max.getBlockX(), dpw.PLOT_HEIGHT, max.getBlockZ()), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT + 1, plotMaxZ + 1), plotfloor);
|
||||
TaskManager.runTask(whenDone);
|
||||
BukkitTaskManager.runTask(whenDone);
|
||||
}
|
||||
}, 1L);
|
||||
}
|
||||
|
@ -99,8 +99,8 @@ import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.object.StringWrapper;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitTaskManager;
|
||||
|
||||
/**
|
||||
* Player Events involving plots
|
||||
@ -161,10 +161,10 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
|
||||
final Location t = event.getTo();
|
||||
final Location q = new Location(t.getWorld(), t.getBlockX(), 0, t.getZ());
|
||||
if ((f.getBlockX() != q.getBlockX()) || (f.getBlockZ() != q.getBlockZ())) {
|
||||
if (Settings.TELEPORT_DELAY != 0 && TaskManager.TELEPORT_QUEUE.size() > 0) {
|
||||
if (Settings.TELEPORT_DELAY != 0 && BukkitTaskManager.TELEPORT_QUEUE.size() > 0) {
|
||||
String name = player.getName();
|
||||
if (TaskManager.TELEPORT_QUEUE.contains(name)) {
|
||||
TaskManager.TELEPORT_QUEUE.remove(name);
|
||||
if (BukkitTaskManager.TELEPORT_QUEUE.contains(name)) {
|
||||
BukkitTaskManager.TELEPORT_QUEUE.remove(name);
|
||||
}
|
||||
}
|
||||
if (!isPlotWorld(player.getWorld())) {
|
||||
@ -925,11 +925,11 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
|
||||
final Entity d = e.getDamager();
|
||||
final Entity a = e.getEntity();
|
||||
|
||||
if (Settings.TELEPORT_DELAY != 0 && TaskManager.TELEPORT_QUEUE.size() > 0 && a instanceof Player) {
|
||||
if (Settings.TELEPORT_DELAY != 0 && BukkitTaskManager.TELEPORT_QUEUE.size() > 0 && a instanceof Player) {
|
||||
Player player = (Player) a;
|
||||
String name = player.getName();
|
||||
if (TaskManager.TELEPORT_QUEUE.contains(name)) {
|
||||
TaskManager.TELEPORT_QUEUE.remove(name);
|
||||
if (BukkitTaskManager.TELEPORT_QUEUE.contains(name)) {
|
||||
BukkitTaskManager.TELEPORT_QUEUE.remove(name);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package com.intellectualcrafters.plot.util;
|
||||
import org.bukkit.World;
|
||||
|
||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
|
||||
|
||||
public abstract class BlockManager {
|
||||
|
||||
@ -33,7 +34,7 @@ public abstract class BlockManager {
|
||||
|
||||
public abstract void functionSetBlock(String worldname, int[] x, int[] y, int[] z, int[] id, byte[] data);
|
||||
|
||||
public abstract void setSign(String worldname, int x, int y, int z);
|
||||
public abstract void setSign(String worldname, int x, int y, int z, String[] lines);
|
||||
|
||||
|
||||
public static void setBlocks(String worldname, int[] x, int y[], int z[], PlotBlock[][] blocks) {
|
||||
|
@ -46,6 +46,7 @@ import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.RegionWrapper;
|
||||
import com.intellectualcrafters.plot.object.entity.EntityWrapper;
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitTaskManager;
|
||||
|
||||
public class ChunkManager {
|
||||
|
||||
@ -94,7 +95,7 @@ public class ChunkManager {
|
||||
}
|
||||
|
||||
public static void deleteRegionFile(final String world, final ChunkLoc loc) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
BukkitTaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String directory = world + File.separator + "region" + File.separator + "r." + loc.x + "." + loc.z + ".mca";
|
||||
@ -198,7 +199,7 @@ public class ChunkManager {
|
||||
if (toGenerate.size() == 0) {
|
||||
Bukkit.getScheduler().cancelTask(tasks.get(currentIndex));
|
||||
tasks.remove(currentIndex);
|
||||
TaskManager.runTask(new Runnable() {
|
||||
BukkitTaskManager.runTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
index.increment();
|
||||
@ -241,7 +242,7 @@ public class ChunkManager {
|
||||
for (Chunk chunk : chunks) {
|
||||
chunk.unload(true, true);
|
||||
}
|
||||
TaskManager.runTaskLater(whenDone, 1);
|
||||
BukkitTaskManager.runTaskLater(whenDone, 1);
|
||||
Bukkit.getScheduler().cancelTask(tasks.get(currentIndex));
|
||||
tasks.remove(currentIndex);
|
||||
return;
|
||||
@ -298,7 +299,7 @@ public class ChunkManager {
|
||||
@Override
|
||||
public void run() {
|
||||
if (chunks.size() == 0) {
|
||||
TaskManager.runTaskLater(whenDone, 1);
|
||||
BukkitTaskManager.runTaskLater(whenDone, 1);
|
||||
Bukkit.getScheduler().cancelTask(tasks.get(currentIndex));
|
||||
tasks.remove(currentIndex);
|
||||
return;
|
||||
|
@ -24,6 +24,7 @@ import com.intellectualcrafters.plot.object.PlotClusterId;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotManager;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitTaskManager;
|
||||
|
||||
public class ClusterManager {
|
||||
public static HashMap<String, HashSet<PlotCluster>> clusters;
|
||||
@ -264,7 +265,7 @@ public class ClusterManager {
|
||||
final AugmentedPopulator populator = getPopulator(cluster);
|
||||
final ArrayList<Chunk> chunks = new ArrayList<>();
|
||||
|
||||
TaskManager.runTaskLater(new Runnable() {
|
||||
BukkitTaskManager.runTaskLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ClusterManager.regenerating.remove(cluster.world + ":" + cluster.getName());
|
||||
@ -284,7 +285,7 @@ public class ClusterManager {
|
||||
}
|
||||
for (final Chunk chunk : chunks) {
|
||||
i+=interval;
|
||||
TaskManager.runTaskLater(new Runnable() {
|
||||
BukkitTaskManager.runTaskLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (populator == null || plotworld.TYPE == 0) {
|
||||
|
@ -22,6 +22,7 @@ import com.intellectualcrafters.plot.events.PlotDeleteEvent;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotManager;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitTaskManager;
|
||||
|
||||
public class ExpireManager {
|
||||
|
||||
@ -45,7 +46,7 @@ public class ExpireManager {
|
||||
long now = System.currentTimeMillis();
|
||||
if (now > getTimeStamp(world)) {
|
||||
timestamp.put(world, now + 86400000l);
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
BukkitTaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
HashMap<Plot, Long> plots = getOldPlots(world);
|
||||
|
@ -74,7 +74,6 @@ public class Lag implements Runnable {
|
||||
*
|
||||
* @return number of ticks since $tI
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public static long getElapsed(final int tI) {
|
||||
final long t = T[tI % T.length];
|
||||
return System.currentTimeMillis() - t;
|
||||
|
@ -0,0 +1,17 @@
|
||||
package com.intellectualcrafters.plot.util;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
|
||||
public class MainUtil {
|
||||
// TODO messages / permission stuff
|
||||
|
||||
/**
|
||||
* Send a message to the console
|
||||
*
|
||||
* @param c message
|
||||
*/
|
||||
public static void sendConsoleSenderMessage(final C c) {
|
||||
PlotMain.MAIN_IMP.sendConsoleSenderMessage(c.s());
|
||||
}
|
||||
}
|
@ -28,6 +28,7 @@ import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotManager;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@ -236,7 +237,7 @@ import java.util.UUID;
|
||||
* @return
|
||||
*/
|
||||
public static int getAllowedPlots(final Player p) {
|
||||
return PlotMain.hasPermissionRange(p, "plots.plot", Settings.MAX_PLOTS);
|
||||
return PlotMain.MAIN_IMP.(p, "plots.plot", Settings.MAX_PLOTS);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -248,7 +249,7 @@ import java.util.UUID;
|
||||
public static Set<Plot> getPlots() {
|
||||
return PlotMain.getPlots();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \\previous\\
|
||||
*
|
||||
@ -285,7 +286,7 @@ import java.util.UUID;
|
||||
public static boolean sendMessage(final Player plr, final String msg, final boolean prefix) {
|
||||
if ((msg.length() > 0) && !msg.equals("")) {
|
||||
if (plr == null) {
|
||||
PlotMain.sendConsoleSenderMessage(C.PREFIX.s() + msg);
|
||||
PlotMain.MAIN_IMP.sendConsoleSenderMessage(C.PREFIX.s() + msg);
|
||||
} else {
|
||||
sendMessageWrapped(plr, ChatColor.translateAlternateColorCodes('&', C.PREFIX.s() + msg));
|
||||
}
|
||||
@ -320,4 +321,5 @@ import java.util.UUID;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -31,7 +31,6 @@ import net.milkbowl.vault.economy.Economy;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
@ -48,13 +47,13 @@ import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.listeners.PlotListener;
|
||||
import com.intellectualcrafters.plot.object.BlockLoc;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotManager;
|
||||
import com.intellectualcrafters.plot.object.PlotSettings;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.bukkit.TaskManager;
|
||||
|
||||
/**
|
||||
* plot functions
|
||||
|
@ -170,14 +170,14 @@ public class SchematicHandler {
|
||||
*/
|
||||
public static Schematic getSchematic(final String name) {
|
||||
{
|
||||
final File parent = new File(PlotMain.getMain().getDataFolder() + File.separator + "schematics");
|
||||
final File parent = new File(PlotMain.getMain().getDirectory() + File.separator + "schematics");
|
||||
if (!parent.exists()) {
|
||||
if (!parent.mkdir()) {
|
||||
throw new RuntimeException("Could not create schematic parent directory");
|
||||
}
|
||||
}
|
||||
}
|
||||
final File file = new File(PlotMain.getMain().getDataFolder() + File.separator + "schematics" + File.separator + name + ".schematic");
|
||||
final File file = new File(PlotMain.getMain().getDirectory() + File.separator + "schematics" + File.separator + name + ".schematic");
|
||||
if (!file.exists()) {
|
||||
PlotMain.sendConsoleSenderMessage(file.toString() + " doesn't exist");
|
||||
return null;
|
||||
|
@ -2,24 +2,37 @@ package com.intellectualcrafters.plot.util;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.PlotSquared;
|
||||
|
||||
public class TaskManager {
|
||||
public abstract class TaskManager {
|
||||
|
||||
public static HashSet<String> TELEPORT_QUEUE = new HashSet<>();
|
||||
public HashSet<String> TELEPORT_QUEUE = new HashSet<>();
|
||||
|
||||
public abstract void taskRepeat(final Runnable r, int interval);
|
||||
|
||||
public abstract void taskAsync(final Runnable r);
|
||||
|
||||
public abstract void task(final Runnable r);
|
||||
|
||||
public abstract void taskLater(final Runnable r, int delay);
|
||||
|
||||
public static void runTaskRepeat(final Runnable r, int interval) {
|
||||
if (r != null)
|
||||
PlotSquared.TASK.taskRepeat(r, interval);
|
||||
}
|
||||
|
||||
public static void runTaskAsync(final Runnable r) {
|
||||
PlotMain.getMain().getServer().getScheduler().runTaskAsynchronously(PlotMain.getMain(), r);
|
||||
if (r != null)
|
||||
PlotSquared.TASK.taskAsync(r);
|
||||
}
|
||||
|
||||
public static void runTask(final Runnable r) {
|
||||
PlotMain.getMain().getServer().getScheduler().runTask(PlotMain.getMain(), r);
|
||||
if (r != null)
|
||||
PlotSquared.TASK.task(r);
|
||||
}
|
||||
|
||||
public static void runTaskLater(final Runnable r, int delay) {
|
||||
if (r == null) {
|
||||
return;
|
||||
}
|
||||
PlotMain.getMain().getServer().getScheduler().runTaskLater(PlotMain.getMain(), r, delay);
|
||||
if (r != null)
|
||||
PlotSquared.TASK.taskLater(r, delay);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,29 @@
|
||||
package com.intellectualcrafters.plot.util.bukkit;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
import com.intellectualcrafters.plot.BukkitMain;
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
|
||||
public class BukkitTaskManager extends TaskManager {
|
||||
|
||||
public void taskRepeat(final Runnable r, int interval) {
|
||||
BukkitMain.THIS.getServer().getScheduler().scheduleSyncRepeatingTask(BukkitMain.THIS, r, interval, interval);
|
||||
}
|
||||
|
||||
public void taskAsync(final Runnable r) {
|
||||
BukkitMain.THIS.getServer().getScheduler().runTaskAsynchronously(BukkitMain.THIS, r);
|
||||
}
|
||||
|
||||
public void task(final Runnable r) {
|
||||
BukkitMain.THIS.getServer().getScheduler().runTask(BukkitMain.THIS, r);
|
||||
}
|
||||
|
||||
public void taskLater(final Runnable r, int delay) {
|
||||
if (r == null) {
|
||||
return;
|
||||
}
|
||||
BukkitMain.THIS.getServer().getScheduler().runTaskLater(BukkitMain.THIS, r, delay);
|
||||
}
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
package com.intellectualcrafters.plot.util.bukkit;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Sign;
|
||||
|
||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.SetBlockManager;
|
||||
import com.intellectualcrafters.plot.util.SetBlockSlow;
|
||||
|
||||
public class BukkitUtil extends BlockManager {
|
||||
|
||||
private static HashMap<String, World> worlds = new HashMap<>();
|
||||
private static String lastString = null;
|
||||
private static World lastWorld = null;
|
||||
|
||||
public static World getWorld(String string) {
|
||||
if (lastString == string) {
|
||||
return lastWorld;
|
||||
}
|
||||
World world = worlds.get(string);
|
||||
if (world == null) {
|
||||
world = Bukkit.getWorld(string);
|
||||
worlds.put(string, world);
|
||||
}
|
||||
return world;
|
||||
}
|
||||
|
||||
public static Chunk getChunkAt(String worldname, int x, int z) {
|
||||
World world = getWorld(worldname);
|
||||
return world.getChunkAt(x, z);
|
||||
}
|
||||
|
||||
public static void update(String world, int x, int z) {
|
||||
ArrayList<Chunk> chunks = new ArrayList<>();
|
||||
final int distance = Bukkit.getViewDistance();
|
||||
for (int cx = -distance; cx < distance; cx++) {
|
||||
for (int cz = -distance; cz < distance; cz++) {
|
||||
final Chunk chunk = getChunkAt(world, (x >> 4) + cx, (z >> 4) + cz);
|
||||
chunks.add(chunk);
|
||||
}
|
||||
}
|
||||
SetBlockManager.setBlockManager.update(chunks);
|
||||
}
|
||||
|
||||
public static void setBlock(World world, int x, int y, int z, int id, byte data) {
|
||||
try {
|
||||
SetBlockManager.setBlockManager.set(world, x, y, z, id, data);
|
||||
}
|
||||
catch (Throwable e) {
|
||||
SetBlockManager.setBlockManager = new SetBlockSlow();
|
||||
SetBlockManager.setBlockManager.set(world, x, y, z, id, data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void functionSetBlock(String worldname, int[] x, int[] y, int[] z, int[] id, byte[] data) {
|
||||
World world = getWorld(worldname);
|
||||
for (int i = 0; i < x.length; i++) {
|
||||
BukkitUtil.setBlock(world, x[i], y[i], z[i], id[i], data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSign(String worldname, int x, int y, int z, String[] lines) {
|
||||
World world = getWorld(worldname);
|
||||
Block block = world.getBlockAt(x, y, z);
|
||||
block.setType(Material.AIR);
|
||||
block.setTypeIdAndData(Material.WALL_SIGN.getId(), (byte) 2, false);
|
||||
BlockState blockstate = block.getState();
|
||||
if ((blockstate instanceof Sign)) {
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
((Sign) blockstate).setLine(i, lines[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user