Merge pull request #164 from IntellectualCrafters/2.8

2.8
This commit is contained in:
boy0001 2015-02-26 15:19:47 +11:00
commit ad20b79752
222 changed files with 3515 additions and 2639 deletions

View File

@ -8,7 +8,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<artifactId>PlotSquared</artifactId>
<version>2.7.4</version>
<version>2.8</version>
<name>PlotSquared</name>
<packaging>jar</packaging>
<build>
@ -61,10 +61,6 @@
<id>sk80q</id>
<url>http://maven.sk89q.com/artifactory/repo/</url>
</repository>
<repository>
<id>vault-repo</id>
<url>http://nexus.theyeticave.net/content/repositories/pub_releases</url>
</repository>
</repositories>
<dependencies>
<dependency>

View File

@ -12,10 +12,7 @@ import org.bukkit.World;
import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider;
@ -28,7 +25,7 @@ import com.intellectualcrafters.plot.commands.WE_Anywhere;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.PlotMeConverter;
import com.intellectualcrafters.plot.events.PlotDeleteEvent;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.generator.BukkitHybridUtils;
import com.intellectualcrafters.plot.generator.HybridGen;
import com.intellectualcrafters.plot.generator.HybridUtils;
@ -38,12 +35,19 @@ import com.intellectualcrafters.plot.listeners.PlayerEvents;
import com.intellectualcrafters.plot.listeners.PlayerEvents_1_8;
import com.intellectualcrafters.plot.listeners.PlotPlusListener;
import com.intellectualcrafters.plot.listeners.WorldEditListener;
import com.intellectualcrafters.plot.object.PlotId;
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.EventUtil;
import com.intellectualcrafters.plot.util.MainUtil;
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.BukkitEventUtil;
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;
@ -51,20 +55,17 @@ 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.SetBlockManager;
import com.intellectualcrafters.plot.util.bukkit.SetBlockSlow;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
import com.intellectualcrafters.plot.uuid.DefaultUUIDWrapper;
import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper;
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
public static BukkitMain THIS = null;
public static PlotSquared MAIN = null;
@EventHandler
public static void worldLoad(final WorldLoadEvent event) {
UUIDHandler.cacheAll(event.getWorld().getName());
}
public static boolean checkVersion(final int major, final int minor, final int minor2) {
try {
final String[] version = Bukkit.getBukkitVersion().split("-")[0].split("\\.");
@ -83,27 +84,10 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
}
}
@EventHandler
public void PlayerCommand(final PlayerCommandPreprocessEvent event) {
final String message = event.getMessage();
if (message.toLowerCase().startsWith("/plotme")) {
final Plugin plotme = Bukkit.getPluginManager().getPlugin("PlotMe");
if (plotme == null) {
final Player player = event.getPlayer();
if (Settings.USE_PLOTME_ALIAS) {
player.performCommand(message.replace("/plotme", "plots"));
} else {
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.NOT_USING_PLOTME);
}
event.setCancelled(true);
}
}
}
@Override
public void onEnable() {
MAIN = new PlotSquared(this);
THIS = this;
MAIN = new PlotSquared(this);
if (Settings.METRICS) {
try {
final Metrics metrics = new Metrics(this);
@ -127,6 +111,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
@Override
public void log(String message) {
message = message.replaceAll("\u00B2", "2");
if ((THIS == null) || (Bukkit.getServer().getConsoleSender() == null)) {
System.out.println(ChatColor.stripColor(ConsoleColors.fromString(message)));
} else {
@ -150,7 +135,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
@Override
public void registerCommands() {
final MainCommand command = new MainCommand();
new MainCommand();
final BukkitCommand bcmd = new BukkitCommand();
final PluginCommand plotCommand = getCommand("plots");
plotCommand.setExecutor(bcmd);
@ -174,6 +159,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
TaskManager.runTaskRepeat(new Runnable() {
long ticked = 0l;
long error = 0l;
@Override
public void run() {
if (this.ticked > 36_000L) {
@ -214,7 +200,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
if (!PlotSquared.setupPlotWorld(world, id)) {
return null;
}
return new HybridGen(world);
return new HybridGen();
}
@Override
@ -273,18 +259,19 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
public BlockManager initBlockManager() {
if (checkVersion(1, 8, 0)) {
try {
SetBlockManager.setBlockManager = new SetBlockFast_1_8();
BukkitSetBlockManager.setBlockManager = new SetBlockFast_1_8();
} catch (final Throwable e) {
e.printStackTrace();
SetBlockManager.setBlockManager = new SetBlockSlow();
BukkitSetBlockManager.setBlockManager = new SetBlockSlow();
}
} else {
try {
SetBlockManager.setBlockManager = new SetBlockFast();
BukkitSetBlockManager.setBlockManager = new SetBlockFast();
} catch (final Throwable e) {
SetBlockManager.setBlockManager = new SetBlockSlow();
BukkitSetBlockManager.setBlockManager = new SetBlockSlow();
}
}
BlockUpdateUtil.setBlockManager = BukkitSetBlockManager.setBlockManager;
try {
new SendChunk();
MainUtil.canSendChunk = true;
@ -313,21 +300,10 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
if ((gen_plugin != null) && gen_plugin.isEnabled()) {
gen_plugin.getDefaultWorldGenerator(world, "");
} else {
new HybridGen(world);
new HybridGen();
}
}
@Override
public boolean callRemovePlot(final String world, final 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 HybridUtils initHybridUtils() {
return new BukkitHybridUtils();
@ -337,4 +313,42 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
public SetupUtils initSetupUtils() {
return new BukkitSetupUtils();
}
@Override
public UUIDWrapper initUUIDHandler() {
final boolean checkVersion = checkVersion(1, 7, 6);
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 (Settings.OFFLINE_MODE) {
UUIDHandler.uuidWrapper = new OfflineUUIDWrapper();
Settings.OFFLINE_MODE = true;
} else if (checkVersion) {
UUIDHandler.uuidWrapper = new DefaultUUIDWrapper();
Settings.OFFLINE_MODE = false;
} else {
UUIDHandler.uuidWrapper = new OfflineUUIDWrapper();
Settings.OFFLINE_MODE = 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();
}
}

View File

@ -5,10 +5,12 @@ import java.io.File;
import net.milkbowl.vault.economy.Economy;
import com.intellectualcrafters.plot.generator.HybridUtils;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.EventUtil;
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);
@ -39,13 +41,17 @@ public interface IPlotMain {
public BlockManager initBlockManager();
public EventUtil initEventUtil();
public ChunkManager initChunkManager();
public SetupUtils initSetupUtils();
public HybridUtils initHybridUtils();
public UUIDWrapper initUUIDHandler();
public boolean initPlotMeConverter();
public void getGenerator(String world, String name);
public boolean callRemovePlot(String world, PlotId id);
}

View File

@ -50,12 +50,14 @@ 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.EventUtil;
import com.intellectualcrafters.plot.util.ExpireManager;
import com.intellectualcrafters.plot.util.Logger;
import com.intellectualcrafters.plot.util.SetupUtils;
import com.intellectualcrafters.plot.util.Logger.LogLevel;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.SetupUtils;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
@ -203,11 +205,7 @@ public class PlotSquared {
}
public static boolean removePlot(final String world, final PlotId id, final boolean callEvent) {
if (callEvent) {
if (!IMP.callRemovePlot(world, id)) {
return false;
}
}
EventUtil.manager.callDelete(world, id);
plots.get(world).remove(id);
if (MainUtil.lastPlot.containsKey(world)) {
final PlotId last = MainUtil.lastPlot.get(world);
@ -221,11 +219,14 @@ public class PlotSquared {
}
public static void loadWorld(final String world, final PlotGenerator generator) {
if (getPlotWorld(world) != null) {
PlotWorld plotWorld = getPlotWorld(world);
if (plotWorld != null) {
if (generator != null) {
generator.init(plotWorld);
}
return;
}
final Set<String> worlds = (config.contains("worlds") ? config.getConfigurationSection("worlds").getKeys(false) : new HashSet<String>());
final PlotWorld plotWorld;
final PlotGenerator plotGenerator;
final PlotManager plotManager;
final String path = "worlds." + world;
@ -251,6 +252,7 @@ public class PlotSquared {
}
// Now add it
addPlotWorld(world, plotWorld, plotManager);
generator.init(plotWorld);
MainUtil.setupBorder(world);
} else {
if (!worlds.contains(world)) {
@ -261,7 +263,7 @@ public class PlotSquared {
try {
final String gen_string = config.getString("worlds." + world + "." + "generator.plugin");
if (gen_string == null) {
new HybridGen(world);
new HybridGen();
} else {
IMP.getGenerator(world, gen_string);
}
@ -303,6 +305,7 @@ public class PlotSquared {
} else if (plotWorld.TYPE == 1) {
new AugmentedPopulator(world, gen_class, null, plotWorld.TERRAIN == 2, plotWorld.TERRAIN != 2);
}
gen_class.init(plotWorld);
}
}
}
@ -437,12 +440,18 @@ public class PlotSquared {
IMP.registerPlotPlusEvents();
IMP.registerForceFieldEvents();
IMP.registerWorldEditEvents();
// create UUIDWrapper
UUIDHandler.uuidWrapper = IMP.initUUIDHandler();
// create event util class
EventUtil.manager = IMP.initEventUtil();
// create Hybrid utility class
HybridUtils.manager = IMP.initHybridUtils();
// create setup util class
SetupUtils.manager = IMP.initSetupUtils();
// Set block
BlockManager.manager = IMP.initBlockManager();
// Set chunk
ChunkManager.manager = IMP.initChunkManager();
// PlotMe
TaskManager.runTaskLater(new Runnable() {
@Override
@ -716,7 +725,7 @@ public class PlotSquared {
setupStyle();
} catch (final Exception err) {
Logger.add(LogLevel.DANGER, "Failed to save style.yml");
System.out.println("failed to save style.yml");
log("failed to save style.yml");
}
try {
configFile = new File(IMP.getDirectory() + File.separator + "config" + File.separator + "settings.yml");
@ -729,7 +738,7 @@ public class PlotSquared {
setupConfig();
} catch (final Exception err_trans) {
Logger.add(LogLevel.DANGER, "Failed to save settings.yml");
System.out.println("Failed to save settings.yml");
log("Failed to save settings.yml");
}
try {
storageFile = new File(IMP.getDirectory() + File.separator + "config" + File.separator + "storage.yml");
@ -742,7 +751,7 @@ public class PlotSquared {
setupStorage();
} catch (final Exception err_trans) {
Logger.add(LogLevel.DANGER, "Failed to save storage.yml");
System.out.println("Failed to save storage.yml");
log("Failed to save storage.yml");
}
try {
style.save(styleFile);
@ -771,9 +780,6 @@ public class PlotSquared {
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");
@ -790,10 +796,13 @@ public class PlotSquared {
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 = "\u00A7" + (style.getString("color.1"));
C.COLOR_2 = "\u00A7" + (style.getString("color.2"));
C.COLOR_3 = "\u00A7" + (style.getString("color.3"));
C.COLOR_4 = "\u00A7" + (style.getString("color.4"));
}
public static void showDebug() {
C.COLOR_1 = "&" + (style.getString("color.1"));
C.COLOR_2 = "&" + (style.getString("color.2"));
C.COLOR_3 = "&" + (style.getString("color.3"));
C.COLOR_4 = "&" + (style.getString("color.4"));
if (Settings.DEBUG) {
final Map<String, String> settings = new HashMap<>();
settings.put("Kill Road Mobs", "" + Settings.KILL_ROAD_MOBS);

View File

@ -119,7 +119,7 @@ public class Auto extends SubCommand {
MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, Settings.MAX_AUTO_SIZE + "");
return false;
}
int currentPlots = MainUtil.getPlayerPlotCount(world, plr);
final int currentPlots = MainUtil.getPlayerPlotCount(world, plr);
final int diff = currentPlots - MainUtil.getAllowedPlots(plr, currentPlots);
if ((diff + (size_x * size_z)) > 0) {
if (diff < 0) {

View File

@ -21,12 +21,11 @@ import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
public class BukkitCommand implements CommandExecutor, TabCompleter {
@Override
public boolean onCommand(CommandSender commandSender, Command command, String commandLabel, String[] args) {
Player player = null;
public boolean onCommand(final CommandSender commandSender, final Command command, final String commandLabel, final String[] args) {
if (commandSender instanceof Player) {
player = (Player) commandSender;
return MainCommand.onCommand(BukkitUtil.getPlayer((Player) commandSender), commandLabel, args);
}
return MainCommand.onCommand(BukkitUtil.getPlayer(player), commandLabel, args);
return MainCommand.onCommand(null, commandLabel, args);
}
@Override

View File

@ -47,7 +47,7 @@ public class Buy extends SubCommand {
if (PlotSquared.economy == null) {
return sendMessage(plr, C.ECON_DISABLED);
}
Location loc = plr.getLocation();
final Location loc = plr.getLocation();
final String world = loc.getWorld();
if (!PlotSquared.isPlotWorld(world)) {
return sendMessage(plr, C.NOT_IN_PLOT_WORLD);
@ -67,7 +67,7 @@ public class Buy extends SubCommand {
if (plot == null) {
return sendMessage(plr, C.NOT_IN_PLOT);
}
int currentPlots = MainUtil.getPlayerPlotCount(world, plr);
final int currentPlots = MainUtil.getPlayerPlotCount(world, plr);
if (currentPlots >= MainUtil.getAllowedPlots(plr, currentPlots)) {
return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
}
@ -91,14 +91,14 @@ public class Buy extends SubCommand {
price += plotworld.PLOT_PRICE * size;
initPrice += plotworld.SELL_PRICE * size;
}
if (PlotSquared.economy != null && price > 0d) {
if ((PlotSquared.economy != null) && (price > 0d)) {
if (EconHandler.getBalance(plr) < price) {
return sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + price);
}
EconHandler.withdrawPlayer(plr, price);
sendMessage(plr, C.REMOVED_BALANCE, price + "");
EconHandler.depositPlayer(UUIDHandler.uuidWrapper.getOfflinePlayer(plot.owner), initPrice);
PlotPlayer owner = UUIDHandler.getPlayer(plot.owner);
final PlotPlayer owner = UUIDHandler.getPlayer(plot.owner);
if (owner != null) {
sendMessage(plr, C.PLOT_SOLD, plot.id + "", plr.getName(), initPrice + "");
}

View File

@ -20,8 +20,6 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands;
import net.milkbowl.vault.economy.Economy;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.Location;
@ -29,9 +27,11 @@ 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
@ -49,17 +49,12 @@ public class Claim extends SubCommand {
if (plot.hasOwner() || plot.settings.isMerged()) {
return false;
}
// FIXME claim plot event
// final PlayerClaimPlotEvent event = new PlayerClaimPlotEvent(player, plot, auto);
// Bukkit.getPluginManager().callEvent(event);
// boolean result = event.isCancelled();
boolean result = true;
if (!result) {
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);
Location loc = player.getLocation();
final Location loc = player.getLocation();
if (teleport) {
MainUtil.teleportPlayer(player, loc, plot);
}
@ -67,21 +62,21 @@ public class Claim extends SubCommand {
final PlotWorld plotworld = PlotSquared.getPlotWorld(world);
final Plot plot2 = PlotSquared.getPlots(world).get(plot.id);
if (plotworld.SCHEMATIC_ON_CLAIM) {
SchematicHandler.Schematic sch;
Schematic sch;
if (schematic.equals("")) {
sch = SchematicHandler.getSchematic(plotworld.SCHEMATIC_FILE);
sch = SchematicHandler.manager.getSchematic(plotworld.SCHEMATIC_FILE);
} else {
sch = SchematicHandler.getSchematic(schematic);
sch = SchematicHandler.manager.getSchematic(schematic);
if (sch == null) {
sch = SchematicHandler.getSchematic(plotworld.SCHEMATIC_FILE);
sch = SchematicHandler.manager.getSchematic(plotworld.SCHEMATIC_FILE);
}
}
SchematicHandler.paste(player.getLocation(), sch, plot2, 0, 0);
SchematicHandler.manager.paste(sch, plot2, 0, 0);
}
PlotSquared.getPlotManager(world).claimPlot(plotworld, plot);
MainUtil.update(loc);
}
return !result;
return result;
}
@Override
@ -90,12 +85,12 @@ public class Claim extends SubCommand {
if (args.length >= 1) {
schematic = args[0];
}
Location loc = plr.getLocation();
Plot plot = MainUtil.getPlot(loc);
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return sendMessage(plr, C.NOT_IN_PLOT);
}
int currentPlots = MainUtil.getPlayerPlotCount(loc.getWorld(), plr);
final int currentPlots = MainUtil.getPlayerPlotCount(loc.getWorld(), plr);
if (currentPlots >= MainUtil.getAllowedPlots(plr, currentPlots)) {
return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
}
@ -103,10 +98,9 @@ public class Claim extends SubCommand {
return sendMessage(plr, C.PLOT_IS_CLAIMED);
}
final PlotWorld world = PlotSquared.getPlotWorld(plot.world);
if (PlotSquared.economy != null && world.USE_ECONOMY) {
if ((PlotSquared.economy != null) && world.USE_ECONOMY) {
final double cost = world.PLOT_PRICE;
if (cost > 0d) {
final Economy economy = PlotSquared.economy;
if (EconHandler.getBalance(plr) < cost) {
return sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + cost);
}
@ -124,6 +118,6 @@ public class Claim extends SubCommand {
}
}
}
return !claimPlot(plr, plot, false, schematic, false) || sendMessage(plr, C.PLOT_NOT_CLAIMED);
return claimPlot(plr, plot, false, schematic, false) || sendMessage(plr, C.PLOT_NOT_CLAIMED);
}
}

View File

@ -62,12 +62,12 @@ public class Clear extends SubCommand {
}
return true;
}
Location loc = plr.getLocation();
Plot plot = MainUtil.getPlot(loc);
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))) {
if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) {
return sendMessage(plr, C.UNLINK_REQUIRED);
}
if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(UUIDHandler.getUUID(plr))) && !Permissions.hasPermission(plr, "plots.admin.command.clear")) {
@ -75,7 +75,7 @@ public class Clear extends SubCommand {
}
assert plot != null;
final long start = System.currentTimeMillis();
boolean result = MainUtil.clearAsPlayer(plot, false, new Runnable() {
final boolean result = MainUtil.clearAsPlayer(plot, false, new Runnable() {
@Override
public void run() {
MainUtil.sendMessage(plr, C.CLEARING_DONE, "" + (System.currentTimeMillis() - start));

View File

@ -307,7 +307,7 @@ public class Cluster extends SubCommand {
cluster.invited.add(uuid);
final String world = plr.getLocation().getWorld();
DBFunc.setInvited(world, cluster, uuid);
PlotPlayer player = UUIDHandler.getPlayer(uuid);
final PlotPlayer player = UUIDHandler.getPlayer(uuid);
if (player != null) {
MainUtil.sendMessage(player, C.CLUSTER_INVITED, cluster.getName());
}
@ -354,7 +354,7 @@ public class Cluster extends SubCommand {
}
cluster.invited.remove(uuid);
DBFunc.removeInvited(cluster, uuid);
PlotPlayer player = UUIDHandler.getPlayer(uuid);
final PlotPlayer player = UUIDHandler.getPlayer(uuid);
if (player != null) {
MainUtil.sendMessage(player, C.CLUSTER_REMOVED, cluster.getName());
}

View File

@ -41,8 +41,8 @@ public class Comment extends SubCommand {
@Override
public boolean execute(final PlotPlayer plr, final String... args) {
Location loc = plr.getLocation();
Plot plot = MainUtil.getPlot(loc);
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return sendMessage(plr, C.NOT_IN_PLOT);
}

View File

@ -36,8 +36,8 @@ public class CreateRoadSchematic extends SubCommand {
@Override
public boolean execute(final PlotPlayer player, final String... args) {
Location loc = player.getLocation();
Plot plot = MainUtil.getPlot(loc);
final Location loc = player.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return sendMessage(player, C.NOT_IN_PLOT);
}

View File

@ -55,9 +55,6 @@ public class Debug extends SubCommand {
for (final String world : PlotSquared.getPlotWorlds()) {
worlds.append(world).append(" ");
}
// FIXME not sure if we actually need any of this debug info as we should just do a timings report which is more detailed anyway
information.append(header);
information.append(getSection(section, "Lag / TPS"));
information.append(getLine(line, "Ticks Per Second", Lag.getTPS()));

View File

@ -35,8 +35,9 @@ 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.AChunkManager;
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;
@ -53,11 +54,8 @@ public class DebugClaimTest extends SubCommand {
}
public static boolean claimPlot(final PlotPlayer player, final Plot plot, final boolean teleport, final String schematic) {
// FIXME call claim event
// boolean result = event result
boolean result = true;
if (!result) {
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);
@ -65,7 +63,7 @@ public class DebugClaimTest extends SubCommand {
MainUtil.teleportPlayer(player, player.getLocation(), plot);
}
}
return result;
return !result;
}
@Override
@ -74,7 +72,7 @@ public class DebugClaimTest extends SubCommand {
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}");
}
String world = args[0];
final String world = args[0];
if (!BlockManager.manager.isWorld(world) || !PlotSquared.isPlotWorld(world)) {
return !MainUtil.sendMessage(null, "&cInvalid plot world!");
}
@ -100,12 +98,12 @@ public class DebugClaimTest extends SubCommand {
continue;
}
final Location loc = manager.getSignLoc(plotworld, plot);
ChunkLoc chunk = new ChunkLoc(loc.getX() >> 4, loc.getZ() >> 4);
boolean result = AChunkManager.manager.loadChunk(world, chunk);
final ChunkLoc chunk = new ChunkLoc(loc.getX() >> 4, loc.getZ() >> 4);
final boolean result = ChunkManager.manager.loadChunk(world, chunk);
if (!result) {
continue;
}
String[] lines = BlockManager.manager.getSign(loc);
final String[] lines = BlockManager.manager.getSign(loc);
if (lines != null) {
String line = lines[2];
if ((line != null) && (line.length() > 2)) {

View File

@ -27,9 +27,9 @@ 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.ChunkManager;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
public class DebugClear extends SubCommand {
@ -77,9 +77,9 @@ public class DebugClear extends SubCommand {
}
return true;
}
Location loc = plr.getLocation();
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null || !(PlotSquared.getPlotWorld(loc.getWorld()) instanceof SquarePlotWorld)) {
if ((plot == null) || !(PlotSquared.getPlotWorld(loc.getWorld()) instanceof SquarePlotWorld)) {
return sendMessage(plr, C.NOT_IN_PLOT);
}
if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) {
@ -92,7 +92,7 @@ public class DebugClear extends SubCommand {
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(null, C.WAIT_FOR_TIMER);
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
return false;
}
MainUtil.runners.put(plot, 1);

View File

@ -111,8 +111,8 @@ public class DebugExec extends SubCommand {
if (uuid == null) {
return MainUtil.sendMessage(null, "player not found: " + args[1]);
}
BukkitOfflinePlayer op = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid);
if ((op == null) || op.getLastPlayed() == 0) {
final BukkitOfflinePlayer op = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid);
if ((op == null) || (op.getLastPlayed() == 0)) {
return MainUtil.sendMessage(null, "player hasn't connected before: " + args[1]);
}
final Timestamp stamp = new Timestamp(op.getLastPlayed());

View File

@ -36,13 +36,13 @@ public class DebugRoadRegen extends SubCommand {
@Override
public boolean execute(final PlotPlayer player, final String... args) {
Location loc = player.getLocation();
String world = loc.getWorld();
final Location loc = player.getLocation();
final String world = loc.getWorld();
if (!(PlotSquared.getPlotWorld(world) instanceof HybridPlotWorld)) {
return sendMessage(player, C.NOT_IN_PLOT_WORLD);
}
ChunkLoc chunk = new ChunkLoc(loc.getX() >> 4, loc.getZ() >> 4);
boolean result = HybridUtils.manager.regenerateRoad(world, chunk);
final ChunkLoc chunk = new ChunkLoc(loc.getX() >> 4, loc.getZ() >> 4);
final boolean result = HybridUtils.manager.regenerateRoad(world, chunk);
if (result) {
MainUtil.update(loc);
}

View File

@ -39,7 +39,7 @@ public class Delete extends SubCommand {
@Override
public boolean execute(final PlotPlayer plr, final String... args) {
Location loc = plr.getLocation();
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
@ -52,7 +52,7 @@ public class Delete extends SubCommand {
}
assert plot != null;
final PlotWorld pWorld = PlotSquared.getPlotWorld(plot.world);
if (PlotSquared.economy != null && pWorld.USE_ECONOMY && (plot != null) && plot.hasOwner() && plot.getOwner().equals(UUIDHandler.getUUID(plr))) {
if ((PlotSquared.economy != null) && pWorld.USE_ECONOMY && (plot != null) && plot.hasOwner() && plot.getOwner().equals(UUIDHandler.getUUID(plr))) {
final double c = pWorld.SELL_PRICE;
if (c > 0d) {
EconHandler.depositPlayer(plr, c);
@ -66,7 +66,7 @@ public class Delete extends SubCommand {
final boolean result = PlotSquared.removePlot(loc.getWorld(), plot.id, true);
final long start = System.currentTimeMillis();
if (result) {
boolean result2 = MainUtil.clearAsPlayer(plot, false, new Runnable() {
final boolean result2 = MainUtil.clearAsPlayer(plot, true, new Runnable() {
@Override
public void run() {
MainUtil.sendMessage(plr, C.CLEARING_DONE, "" + (System.currentTimeMillis() - start));

View File

@ -28,6 +28,7 @@ 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.EventUtil;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
@ -43,7 +44,7 @@ public class Denied extends SubCommand {
MainUtil.sendMessage(plr, C.DENIED_NEED_ARGUMENT);
return true;
}
Location loc = plr.getLocation();
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
@ -82,7 +83,7 @@ public class Denied extends SubCommand {
}
plot.addDenied(uuid);
DBFunc.setDenied(loc.getWorld(), plot, uuid);
//FIXME PlayerPlotDeniedEvent
EventUtil.manager.callDenied(plr, plot, uuid, true);
} else {
MainUtil.sendMessage(plr, C.ALREADY_ADDED);
return false;
@ -112,7 +113,7 @@ public class Denied extends SubCommand {
final UUID uuid = UUIDHandler.getUUID(args[1]);
plot.removeDenied(uuid);
DBFunc.removeDenied(loc.getWorld(), plot, uuid);
// FIXME PlayerPlotDeniedEvent
EventUtil.manager.callDenied(plr, plot, uuid, false);
MainUtil.sendMessage(plr, C.DENIED_REMOVED);
} else {
MainUtil.sendMessage(plr, C.DENIED_NEED_ARGUMENT);

View File

@ -57,7 +57,7 @@ public class FlagCmd extends SubCommand {
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag <set|remove|add|list|info>");
return false;
}
Location loc = player.getLocation();
final Location loc = player.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
MainUtil.sendMessage(player, C.NOT_IN_PLOT);

View File

@ -27,6 +27,7 @@ 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;
@ -42,7 +43,7 @@ public class Helpers extends SubCommand {
MainUtil.sendMessage(plr, C.HELPER_NEED_ARGUMENT);
return true;
}
Location loc = plr.getLocation();
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
@ -81,7 +82,7 @@ public class Helpers extends SubCommand {
}
plot.addHelper(uuid);
DBFunc.setHelper(loc.getWorld(), plot, uuid);
// FIXME PlayerPlotHelperEvent
EventUtil.manager.callHelper(plr, plot, uuid, true);
} else {
MainUtil.sendMessage(plr, C.ALREADY_ADDED);
return false;
@ -103,7 +104,7 @@ public class Helpers extends SubCommand {
final UUID uuid = UUIDHandler.getUUID(args[1]);
plot.removeHelper(uuid);
DBFunc.removeHelper(loc.getWorld(), plot, uuid);
// FIXME PlayerPlotHelperEvent
EventUtil.manager.callHelper(plr, plot, uuid, false);
MainUtil.sendMessage(plr, C.HELPER_REMOVED);
} else {
MainUtil.sendMessage(plr, C.HELPER_NEED_ARGUMENT);

View File

@ -49,9 +49,9 @@ public class Inbox extends SubCommand {
report = true;
}
}
Location loc = plr.getLocation();
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null && !report) {
if ((plot == null) && !report) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
if ((plot != null) && !plot.hasOwner()) {

View File

@ -53,7 +53,7 @@ public class Info extends SubCommand {
Plot plot;
String world;
if (player != null) {
Location loc = player.getLocation();
final Location loc = player.getLocation();
world = loc.getWorld();
if (!PlotSquared.isPlotWorld(world)) {
MainUtil.sendMessage(player, C.NOT_IN_PLOT_WORLD);

View File

@ -37,7 +37,7 @@ public class Kick extends SubCommand {
@Override
public boolean execute(final PlotPlayer plr, final String... args) {
Location loc = plr.getLocation();
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
@ -50,7 +50,7 @@ public class Kick extends SubCommand {
MainUtil.sendMessage(plr, "&c/plot kick <player>");
return false;
}
PlotPlayer player = UUIDHandler.getPlayer(args[0]);
final PlotPlayer player = UUIDHandler.getPlayer(args[0]);
if (player == null) {
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
return false;

View File

@ -40,7 +40,7 @@ public class MainCommand {
/**
* Main Permission Node
*/
private final static SubCommand[] _subCommands = new SubCommand[] { new Setup(), new DebugSaveTest(), new DebugLoadTest(), new CreateRoadSchematic(), new RegenAllRoads(), new DebugClear(), new Claim(), new Auto(), new Home(), new Visit(), new TP(), new Set(), new Clear(), new Delete(), new SetOwner(), new Denied(), new Helpers(), new Trusted(), new Info(), new list(), new Help(), new Debug(), new Schematic(), new plugin(), new Inventory(), new Purge(), new Reload(), new Merge(), new Unlink(), new Kick(), new Rate(), new DebugClaimTest(), new Inbox(), new Comment(), new Database(), new Unclaim(), new Swap(), new MusicSubcommand(), new DebugRoadRegen(), new Trim(), new DebugExec(), new FlagCmd(), new Target(), new DebugFixFlags(), new Move(), new Condense() };
private final static SubCommand[] _subCommands = new SubCommand[] { new Template(), new Setup(), new DebugSaveTest(), new DebugLoadTest(), new CreateRoadSchematic(), new RegenAllRoads(), new DebugClear(), new Claim(), new Auto(), new Home(), new Visit(), new TP(), new Set(), new Clear(), new Delete(), new SetOwner(), new Denied(), new Helpers(), new Trusted(), new Info(), new list(), new Help(), new Debug(), new SchematicCmd(), new plugin(), new Inventory(), new Purge(), new Reload(), new Merge(), new Unlink(), new Kick(), new Rate(), new DebugClaimTest(), new Inbox(), new Comment(), new Database(), new Unclaim(), new Swap(), new MusicSubcommand(), new DebugRoadRegen(), new Trim(), new DebugExec(), new FlagCmd(), new Target(), new DebugFixFlags(), new Move(), new Condense() };
public final static ArrayList<SubCommand> subCommands = new ArrayList<SubCommand>() {
{
addAll(Arrays.asList(_subCommands));
@ -158,7 +158,7 @@ public class MainCommand {
for (final String string : helpMenu(player, cato, page)) {
help.append(string).append("\n");
}
player.sendMessage(MainUtil.colorise('&', help.toString()));
MainUtil.sendMessage(player, help.toString());
// return PlayerFunctions.sendMessage(player, help.toString());
} else {
for (final SubCommand command : subCommands) {

View File

@ -22,8 +22,6 @@ package com.intellectualcrafters.plot.commands;
import java.util.ArrayList;
import net.milkbowl.vault.economy.Economy;
import org.apache.commons.lang.StringUtils;
import com.intellectualcrafters.plot.PlotSquared;
@ -34,6 +32,7 @@ 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.EventUtil;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
@ -73,7 +72,7 @@ public class Merge extends SubCommand {
@Override
public boolean execute(final PlotPlayer plr, final String... args) {
Location loc = plr.getLocation();
final Location loc = plr.getLocationFull();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
@ -107,7 +106,7 @@ public class Merge extends SubCommand {
PlotId bot = MainUtil.getBottomPlot(plot).id;
PlotId top = MainUtil.getTopPlot(plot).id;
ArrayList<PlotId> plots;
String world = plr.getLocation().getWorld();
final String world = plr.getLocation().getWorld();
switch (direction) {
case 0: // north = -y
plots = MainUtil.getMaxPlotSelectionIds(world, new PlotId(bot.x, bot.y - 1), new PlotId(top.x, top.y));
@ -141,11 +140,10 @@ public class Merge extends SubCommand {
}
}
final PlotWorld plotWorld = PlotSquared.getPlotWorld(world);
if (PlotSquared.economy != null && plotWorld.USE_ECONOMY) {
if ((PlotSquared.economy != null) && plotWorld.USE_ECONOMY) {
double cost = plotWorld.MERGE_PRICE;
cost = plots.size() * cost;
if (cost > 0d) {
final Economy economy = PlotSquared.economy;
if (EconHandler.getBalance(plr) < cost) {
sendMessage(plr, C.CANNOT_AFFORD_MERGE, cost + "");
return false;
@ -154,10 +152,8 @@ public class Merge extends SubCommand {
sendMessage(plr, C.REMOVED_BALANCE, cost + "");
}
}
//FIXME PlotMergeEvent
// boolean result = event.isCancelled();
boolean result = false;
if (result) {
final boolean result = EventUtil.manager.callMerge(world, plot, plots);
if (!result) {
MainUtil.sendMessage(plr, "&cMerge has been cancelled");
return false;
}

View File

@ -42,7 +42,7 @@ public class MusicSubcommand extends SubCommand {
@Override
public boolean execute(final PlotPlayer player, final String... args) {
Location loc = player.getLocation();
final Location loc = player.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return !sendMessage(player, C.NOT_IN_PLOT);

View File

@ -43,7 +43,7 @@ public class Rate extends SubCommand {
sendMessage(plr, C.RATING_NOT_VALID);
return true;
}
Location loc = plr.getLocation();
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);

View File

@ -29,7 +29,7 @@ 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.AChunkManager;
import com.intellectualcrafters.plot.util.ChunkManager;
public class RegenAllRoads extends SubCommand {
public RegenAllRoads() {
@ -52,7 +52,7 @@ public class RegenAllRoads extends SubCommand {
sendMessage(player, C.NOT_VALID_PLOT_WORLD);
return false;
}
final List<ChunkLoc> chunks = AChunkManager.manager.getChunkChunks(name);
final List<ChunkLoc> chunks = ChunkManager.manager.getChunkChunks(name);
PlotSquared.log("&cIf no schematic is set, the following will not do anything");
PlotSquared.log("&7 - To set a schematic, stand in a plot and use &c/plot createroadschematic");
PlotSquared.log("&6Potential chunks to update: &7" + (chunks.size() * 1024));

View File

@ -32,21 +32,23 @@ 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.SchematicHandler;
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;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
public class Schematic extends SubCommand {
public class SchematicCmd extends SubCommand {
private int counter = 0;
private boolean running = false;
private Plot[] plots;
private int task;
public Schematic() {
public SchematicCmd() {
super("schematic", "plots.schematic", "Schematic Command", "schematic {arg}", "sch", CommandCategory.ACTIONS, false);
// TODO command to fetch schematic from worldedit directory
}
@ -59,7 +61,7 @@ public class Schematic extends SubCommand {
}
final String arg = args[0].toLowerCase();
final String file;
final SchematicHandler.Schematic schematic;
final Schematic schematic;
switch (arg) {
case "paste": {
if (plr == null) {
@ -75,7 +77,7 @@ public class Schematic extends SubCommand {
break;
}
final Location loc = plr.getLocation();
Plot plot = MainUtil.getPlot(loc);
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
sendMessage(plr, C.NOT_IN_PLOT);
break;
@ -90,10 +92,10 @@ public class Schematic extends SubCommand {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
final SchematicHandler.Schematic schematic = SchematicHandler.getSchematic(file2);
final Schematic schematic = SchematicHandler.manager.getSchematic(file2);
if (schematic == null) {
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent or not in gzip format");
Schematic.this.running = false;
SchematicCmd.this.running = false;
return;
}
final int x;
@ -104,7 +106,7 @@ public class Schematic extends SubCommand {
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));
Schematic.this.running = false;
SchematicCmd.this.running = false;
return;
}
if ((dem.getX() != length2) || (dem.getZ() != length2)) {
@ -117,26 +119,34 @@ public class Schematic extends SubCommand {
}
final DataCollection[] b = schematic.getBlockCollection();
final int sy = BlockManager.manager.getHeighestBlock(bot);
final Location l1 = bot.add(0, sy - 1, 0);
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;
Schematic.this.task = TaskManager.runTaskRepeat(new Runnable() {
SchematicCmd.this.task = TaskManager.runTaskRepeat(new Runnable() {
@Override
public void run() {
boolean result = false;
while (!result) {
final int start = Schematic.this.counter * 5000;
final int start = SchematicCmd.this.counter * 5000;
if (start > blen) {
SchematicHandler.manager.pasteStates(schematic, plot, 0, 0);
sendMessage(plr, C.SCHEMATIC_PASTE_SUCCESS);
MainUtil.update(plr.getLocation());
Schematic.this.running = false;
PlotSquared.TASK.cancelTask(Schematic.this.task);
SchematicCmd.this.running = false;
PlotSquared.TASK.cancelTask(SchematicCmd.this.task);
return;
}
final int end = Math.min(start + 5000, blen);
result = SchematicHandler.pastePart(loc.getWorld(), b, l1, x, z, start, end, WIDTH, LENGTH);
Schematic.this.counter++;
result = SchematicHandler.manager.pastePart(loc.getWorld(), b, l1, x, z, start, end, WIDTH, LENGTH);
SchematicCmd.this.counter++;
}
}
}, 1);
@ -158,12 +168,12 @@ public class Schematic extends SubCommand {
break;
}
file = args[1];
schematic = SchematicHandler.getSchematic(file);
schematic = SchematicHandler.manager.getSchematic(file);
if (schematic == null) {
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent");
break;
}
Location loc = plr.getLocation();
final Location loc = plr.getLocation();
final int l1 = schematic.getSchematicDimension().getX();
final int l2 = schematic.getSchematicDimension().getZ();
final Plot plot = MainUtil.getPlot(loc);
@ -204,14 +214,14 @@ public class Schematic extends SubCommand {
this.task = TaskManager.runTaskRepeat(new Runnable() {
@Override
public void run() {
if (Schematic.this.counter >= Schematic.this.plots.length) {
if (SchematicCmd.this.counter >= SchematicCmd.this.plots.length) {
PlotSquared.log("&3PlotSquared&8->&3Schemaitc&8: &aFinished!");
Schematic.this.running = false;
PlotSquared.TASK.cancelTask(Schematic.this.task);
SchematicCmd.this.running = false;
PlotSquared.TASK.cancelTask(SchematicCmd.this.task);
return;
}
final Plot plot = Schematic.this.plots[Schematic.this.counter];
final CompoundTag sch = SchematicHandler.getCompoundTag(worldname, plot.id);
final Plot plot = SchematicCmd.this.plots[SchematicCmd.this.counter];
final CompoundTag sch = SchematicHandler.manager.getCompoundTag(worldname, plot.id);
final String o = UUIDHandler.getName(plot.owner);
final String owner = o == null ? "unknown" : o;
if (sch == null) {
@ -221,23 +231,22 @@ public class Schematic extends SubCommand {
@Override
public void run() {
MainUtil.sendMessage(null, "&6ID: " + plot.id);
final boolean result = SchematicHandler.save(sch, Settings.SCHEMATIC_SAVE_PATH + "/" + plot.id.x + ";" + plot.id.y + "," + worldname + "," + owner + ".schematic");
final boolean result = SchematicHandler.manager.save(sch, Settings.SCHEMATIC_SAVE_PATH + "/" + plot.id.x + ";" + plot.id.y + "," + worldname + "," + owner + ".schematic");
if (!result) {
MainUtil.sendMessage(null, "&7 - Failed to save &c" + plot.id);
} else {
MainUtil.sendMessage(null, "&7 - &aExport success: " + plot.id);
MainUtil.sendMessage(null, "&7 - &a success: " + plot.id);
}
}
});
}
Schematic.this.counter++;
SchematicCmd.this.counter++;
}
}, 20);
break;
}
case "export":
case "save":
{
case "save": {
if (!Permissions.hasPermission(plr, "plots.schematic.save")) {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.schematic.save");
return false;
@ -249,7 +258,7 @@ public class Schematic extends SubCommand {
final String world;
final Plot p2;
if (plr != null) {
Location loc = plr.getLocation();
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
@ -286,14 +295,14 @@ public class Schematic extends SubCommand {
this.task = TaskManager.runTaskRepeat(new Runnable() {
@Override
public void run() {
if (Schematic.this.counter >= Schematic.this.plots.length) {
if (SchematicCmd.this.counter >= SchematicCmd.this.plots.length) {
PlotSquared.log("&3PlotSquared&8->&3Schemaitc&8: &aFinished!");
Schematic.this.running = false;
PlotSquared.TASK.cancelTask(Schematic.this.task);
SchematicCmd.this.running = false;
PlotSquared.TASK.cancelTask(SchematicCmd.this.task);
return;
}
final Plot plot = Schematic.this.plots[Schematic.this.counter];
final CompoundTag sch = SchematicHandler.getCompoundTag(world, plot.id);
final Plot plot = SchematicCmd.this.plots[SchematicCmd.this.counter];
final CompoundTag sch = SchematicHandler.manager.getCompoundTag(world, plot.id);
final String o = UUIDHandler.getName(plot.owner);
final String owner = o == null ? "unknown" : o;
if (sch == null) {
@ -303,7 +312,7 @@ public class Schematic extends SubCommand {
@Override
public void run() {
MainUtil.sendMessage(plr, "&6ID: " + plot.id);
final boolean result = SchematicHandler.save(sch, Settings.SCHEMATIC_SAVE_PATH + "/" + plot.id.x + ";" + plot.id.y + "," + world + "," + owner.trim() + ".schematic");
final boolean result = SchematicHandler.manager.save(sch, Settings.SCHEMATIC_SAVE_PATH + "/" + plot.id.x + ";" + plot.id.y + "," + world + "," + owner.trim() + ".schematic");
if (!result) {
MainUtil.sendMessage(plr, "&7 - Failed to save &c" + plot.id);
} else {
@ -312,7 +321,7 @@ public class Schematic extends SubCommand {
}
});
}
Schematic.this.counter++;
SchematicCmd.this.counter++;
}
}, 60);
break;

View File

@ -21,6 +21,7 @@
package com.intellectualcrafters.plot.commands;
import java.util.Arrays;
import java.util.List;
import org.apache.commons.lang.StringUtils;
@ -49,7 +50,7 @@ import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
* @author Citymonstret
*/
public class Set extends SubCommand {
public final static String[] values = new String[] { "biome", "wall", "wall_filling", "floor", "alias", "home", "flag" };
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() {
@ -59,7 +60,7 @@ public class Set extends SubCommand {
@SuppressWarnings("deprecation")
@Override
public boolean execute(final PlotPlayer plr, final String... args) {
Location loc = plr.getLocation();
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
@ -73,7 +74,10 @@ public class Set extends SubCommand {
return false;
}
if (args.length < 1) {
MainUtil.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + getArgumentList(values));
PlotManager manager = PlotSquared.getPlotManager(loc.getWorld());
List<String> newValues = Arrays.asList(values);;
newValues.addAll(Arrays.asList(manager.getPlotComponents(PlotSquared.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++) {
@ -90,7 +94,7 @@ public class Set extends SubCommand {
}
if (args[0].equalsIgnoreCase("flag")) {
if (args.length < 2) {
String message = StringUtils.join(FlagManager.getFlags(plr), "&c, &6");
final String message = StringUtils.join(FlagManager.getFlags(plr), "&c, &6");
MainUtil.sendMessage(plr, C.NEED_KEY.s().replaceAll("%values%", message));
return false;
}
@ -219,22 +223,23 @@ public class Set extends SubCommand {
final String[] components = manager.getPlotComponents(plotworld, plot.id);
for (final String component : components) {
if (component.equalsIgnoreCase(args[0])) {
PlotBlock[] blocks;
try {
blocks = (PlotBlock[]) Configuration.BLOCKLIST.parseString(args[1]);
} catch (final Exception e) {
try {
if (args.length < 2) {
MainUtil.sendMessage(plr, C.NEED_BLOCK);
return true;
}
PlotBlock[] blocks;
try {
blocks = (PlotBlock[]) Configuration.BLOCKLIST.parseObject(args[2]);
} catch (final Exception e) {
try {
blocks = new PlotBlock[] { new PlotBlock((short) BlockManager.manager.getBlockIdFromString(args[2]), (byte) 0) };
blocks = new PlotBlock[] { new PlotBlock((short) BlockManager.manager.getBlockIdFromString(args[1]), (byte) 0) };
} catch (final Exception e2) {
MainUtil.sendMessage(plr, C.NOT_VALID_BLOCK);
return false;
}
}
manager.setComponent(plotworld, plot.id, component, blocks);
MainUtil.update(loc);
MainUtil.sendMessage(plr, C.GENERATING_COMPONENT);
return true;
}
@ -257,7 +262,9 @@ public class Set extends SubCommand {
return true;
}
}
MainUtil.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + getArgumentList(values));
List<String> newValues = Arrays.asList(values);;
newValues.addAll(Arrays.asList(manager.getPlotComponents(plotworld, plot.id)));
MainUtil.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + getArgumentList(newValues));
return false;
}
@ -265,9 +272,9 @@ public class Set extends SubCommand {
return MainUtil.colorise('&', C.BLOCK_LIST_ITEM.s().replaceAll("%mat%", s));
}
private String getArgumentList(final String[] strings) {
private String getArgumentList(final List<String> newValues) {
final StringBuilder builder = new StringBuilder();
for (final String s : strings) {
for (final String s : newValues) {
builder.append(getString(s));
}
return builder.toString().substring(1, builder.toString().length() - 1);

View File

@ -50,7 +50,7 @@ public class SetOwner extends SubCommand {
@Override
public boolean execute(final PlotPlayer plr, final String... args) {
Location loc = plr.getLocation();
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if ((plot == null) || (plot.owner == null)) {
MainUtil.sendMessage(plr, C.NOT_IN_PLOT);
@ -66,7 +66,7 @@ public class SetOwner extends SubCommand {
}
final String world = loc.getWorld();
final PlotId bot = MainUtil.getBottomPlot(plot).id;
final PlotId top = MainUtil.getTopPlot( plot).id;
final PlotId top = MainUtil.getTopPlot(plot).id;
final ArrayList<PlotId> plots = MainUtil.getPlotSelectionIds(bot, top);
for (final PlotId id : plots) {
final Plot current = PlotSquared.getPlots(world).get(id);

View File

@ -22,6 +22,7 @@ package com.intellectualcrafters.plot.commands;
import java.util.Arrays;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import com.intellectualcrafters.plot.config.C;
@ -179,5 +180,4 @@ public class Setup extends SubCommand {
return false;
}
}

View File

@ -27,7 +27,7 @@ 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.AChunkManager;
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;
@ -49,7 +49,7 @@ public class Swap extends SubCommand {
MainUtil.sendMessage(plr, C.SWAP_SYNTAX);
return false;
}
Location loc = plr.getLocation();
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
@ -83,7 +83,7 @@ public class Swap extends SubCommand {
MainUtil.sendMessage(plr, C.SWAP_SYNTAX);
return false;
}
AChunkManager.manager.swap(world, plot.id, plotid);
ChunkManager.manager.swap(world, plot.id, plotid);
// FIXME Requires testing!!
DBFunc.dbManager.swapPlots(plot, MainUtil.getPlot(world, plotid));
MainUtil.sendMessage(plr, C.SWAP_SUCCESS);

View File

@ -48,8 +48,8 @@ public class TP extends SubCommand {
}
final String id = args[0];
PlotId plotid;
Location loc = plr.getLocation();
String pworld = loc.getWorld();
final Location loc = plr.getLocation();
final String pworld = loc.getWorld();
String world = pworld;
if (args.length == 2) {
if (BlockManager.manager.isWorld(args[1])) {

View File

@ -34,7 +34,7 @@ public class Target extends SubCommand {
@Override
public boolean execute(final PlotPlayer plr, final String... args) {
Location ploc = plr.getLocation();
final Location ploc = plr.getLocation();
if (!PlotSquared.isPlotWorld(ploc.getWorld())) {
MainUtil.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
return false;

View File

@ -20,64 +20,169 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.GZIPOutputStream;
import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import com.intellectualcrafters.plot.PlotSquared;
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, true);
super("template", "plots.admin", "Create or use a world template", "template", "", CommandCategory.DEBUG, false);
}
@Override
public boolean execute(final PlotPlayer plr, final String... args) {
if (args.length != 2) {
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot template <import|export> <world>");
if (args.length != 2 && args.length != 3) {
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 (PlotSquared.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(PlotSquared.IMP.getDirectory() + File.separator + "templates" + File.separator + "tmp-data.yml");
YamlConfiguration worldConfig = YamlConfiguration.loadConfiguration(worldFile);
PlotSquared.config.set("worlds." + world, worldConfig.get(""));
try {
PlotSquared.config.save(PlotSquared.configFile);
} catch (IOException e) {
e.printStackTrace();
}
String generator = worldConfig.getString("generator.plugin");
if (generator == null) {
generator = "PlotSquared";
}
int type = worldConfig.getInt("generator.type");
int terrain = worldConfig.getInt("generator.terrain");
SetupObject setup = new SetupObject();
setup.generator = 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;
}
String world = args[1];
final PlotWorld plotworld = PlotSquared.getPlotWorld(world);
if (!BlockManager.manager.isWorld(world) || (plotworld == null)) {
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_WORLD);
return false;
}
switch (args[0].toLowerCase()) {
case "import": {
// TODO import template
MainUtil.sendMessage(plr, "TODO");
final PlotManager manager = PlotSquared.getPlotManager(world);
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
manager.exportTemplate(plotworld);
MainUtil.sendMessage(plr, "Done!");
}
});
return true;
}
case "export": {
MainUtil.sendMessage(plr, "TODO");
}
}
// TODO allow world settings (including schematics to be packed into a single file)
// TODO allow world created based on these packaged files
return true;
}
public void gzipIt(final String output, final String input) {
final byte[] buffer = new byte[1024];
public static boolean extractAllFiles(String world, String template) {
byte[] buffer = new byte[2048];
try {
final GZIPOutputStream gzos = new GZIPOutputStream(new FileOutputStream(output));
final FileInputStream in = new FileInputStream(input);
int len;
while ((len = in.read(buffer)) > 0) {
gzos.write(buffer, 0, len);
File folder = new File(PlotSquared.IMP.getDirectory() + File.separator + "templates");
if (!folder.exists()) {
return false;
}
in.close();
gzos.finish();
gzos.close();
File input = new File(folder + File.separator + template +".template");
File output = PlotSquared.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) {
YamlConfiguration config = new YamlConfiguration();
ConfigurationSection section = config.getConfigurationSection("");
plotworld.saveConfiguration(section);
return config.saveToString().getBytes();
}
public static boolean zipAll(final String world, Set<FileBytes> files) {
try {
File output = new File(PlotSquared.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();
return true;
} catch (final IOException ex) {
ex.printStackTrace();
return false;
}
}
}

View File

@ -35,11 +35,10 @@ 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.AChunkManager;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.bukkit.ChunkManager;
public class Trim extends SubCommand {
public static boolean TASK = false;
@ -128,7 +127,7 @@ public class Trim extends SubCommand {
final ChunkLoc loc = new ChunkLoc(x, z);
empty.add(loc);
} catch (final Exception e) {
System.out.print("INVALID MCA: " + name);
PlotSquared.log("INVALID MCA: " + name);
}
} else {
final Path path = Paths.get(file.getPath());
@ -145,7 +144,7 @@ public class Trim extends SubCommand {
final ChunkLoc loc = new ChunkLoc(x, z);
empty.add(loc);
} catch (final Exception e) {
System.out.print("INVALID MCA: " + name);
PlotSquared.log("INVALID MCA: " + name);
}
}
} catch (final Exception e) {
@ -165,11 +164,11 @@ public class Trim extends SubCommand {
if (Trim.TASK) {
return false;
}
final long startOld = System.currentTimeMillis();
System.currentTimeMillis();
sendMessage("Collecting region data...");
final ArrayList<Plot> plots = new ArrayList<>();
plots.addAll(PlotSquared.getPlots(world).values());
final HashSet<ChunkLoc> chunks = new HashSet<>(AChunkManager.manager.getChunkChunks(world));
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");
@ -180,7 +179,6 @@ public class Trim extends SubCommand {
while ((System.currentTimeMillis() - start) < 50) {
if (plots.size() == 0) {
empty.addAll(chunks);
System.out.print("DONE!");
Trim.TASK = false;
TaskManager.runTaskAsync(whenDone);
PlotSquared.TASK.cancelTask(Trim.TASK_ID);
@ -207,7 +205,7 @@ public class Trim extends SubCommand {
public static void deleteChunks(final String world, final ArrayList<ChunkLoc> chunks) {
for (final ChunkLoc loc : chunks) {
AChunkManager.manager.deleteRegionFile(world, loc);
ChunkManager.manager.deleteRegionFile(world, loc);
}
}

View File

@ -27,6 +27,7 @@ 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;
@ -43,7 +44,7 @@ public class Trusted extends SubCommand {
MainUtil.sendMessage(plr, C.TRUSTED_NEED_ARGUMENT);
return true;
}
Location loc = plr.getLocation();
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
@ -82,7 +83,7 @@ public class Trusted extends SubCommand {
}
plot.addTrusted(uuid);
DBFunc.setTrusted(loc.getWorld(), plot, uuid);
// FIXME PlayerPlotTrustedEvent
EventUtil.manager.callTrusted(plr, plot, uuid, true);
} else {
MainUtil.sendMessage(plr, C.ALREADY_ADDED);
return false;
@ -104,7 +105,7 @@ public class Trusted extends SubCommand {
final UUID uuid = UUIDHandler.getUUID(args[1]);
plot.removeTrusted(uuid);
DBFunc.removeTrusted(loc.getWorld(), plot, uuid);
// FIXME PlayerPlotTrustedEvent
EventUtil.manager.callTrusted(plr, plot, uuid, false);
MainUtil.sendMessage(plr, C.TRUSTED_REMOVED);
} else {
MainUtil.sendMessage(plr, C.TRUSTED_NEED_ARGUMENT);

View File

@ -20,8 +20,6 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands;
import net.milkbowl.vault.economy.Economy;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.database.DBFunc;
@ -41,7 +39,7 @@ public class Unclaim extends SubCommand {
@Override
public boolean execute(final PlotPlayer plr, final String... args) {
Location loc = plr.getLocation();
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
@ -54,10 +52,9 @@ public class Unclaim extends SubCommand {
}
assert plot != null;
final PlotWorld pWorld = PlotSquared.getPlotWorld(plot.world);
if (PlotSquared.economy != null && pWorld.USE_ECONOMY) {
if ((PlotSquared.economy != null) && pWorld.USE_ECONOMY) {
final double c = pWorld.SELL_PRICE;
if (c > 0d) {
final Economy economy = PlotSquared.economy;
EconHandler.depositPlayer(plr, c);
sendMessage(plr, C.ADDED_BALANCE, c + "");
}

View File

@ -31,6 +31,7 @@ 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.EventUtil;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
@ -47,7 +48,7 @@ public class Unlink extends SubCommand {
@Override
public boolean execute(final PlotPlayer plr, final String... args) {
Location loc = plr.getLocation();
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
@ -68,11 +69,14 @@ public class Unlink extends SubCommand {
}
public static boolean unlinkPlot(final Plot plot) {
String world = plot.world;
final String world = plot.world;
final PlotId pos1 = MainUtil.getBottomPlot(plot).id;
final PlotId pos2 = MainUtil.getTopPlot(plot).id;
final ArrayList<PlotId> ids = MainUtil.getPlotSelectionIds(pos1, pos2);
// FIXME PlotUnlinkEvent (cancellable)
final boolean result = EventUtil.manager.callUnlink(world, ids);
if (!result) {
return false;
}
final PlotManager manager = PlotSquared.getPlotManager(world);
final PlotWorld plotworld = PlotSquared.getPlotWorld(world);
manager.startPlotUnlink(plotworld, ids);

View File

@ -444,7 +444,7 @@ public enum C {
* @see com.intellectualsites.translation.TranslationLanguage
*/
protected final static TranslationLanguage lang = new TranslationLanguage("PlotSquared", "this", "use");
public static String COLOR_1 = "\u00A76", COLOR_2 = "\u00A77", COLOR_3 = "\u00A78", COLOR_4 = "\u00A73";
public static String COLOR_1 = "&6", COLOR_2 = "&7", COLOR_3 = "&8", COLOR_4 = "&3";
/**
* The TranslationManager
*

View File

@ -106,7 +106,7 @@ public class Configuration {
@Override
public boolean validateValue(final String string) {
try {
int biome = BlockManager.manager.getBiomeFromString(string.toUpperCase());
final int biome = BlockManager.manager.getBiomeFromString(string.toUpperCase());
if (biome == -1) {
return false;
}

View File

@ -293,7 +293,7 @@ public class PlotMeConverter {
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + actualWorldName + " plugin:PlotSquared");
} else {
Bukkit.getServer().unloadWorld(world, true);
final World myworld = WorldCreator.name(actualWorldName).generator(new HybridGen(actualWorldName)).createWorld();
final World myworld = WorldCreator.name(actualWorldName).generator(new HybridGen()).createWorld();
myworld.save();
}
}

View File

@ -31,7 +31,6 @@ import com.intellectualcrafters.plot.object.Plot;
* @author Citymonstret
* @author Empire92
*/
@SuppressWarnings("unused")
public class PlayerClaimPlotEvent extends PlayerEvent implements Cancellable {
private static HandlerList handlers = new HandlerList();
private final Plot plot;

View File

@ -20,7 +20,6 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.events;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
@ -32,11 +31,10 @@ import com.intellectualcrafters.plot.object.PlotId;
* @author Citymonstret
* @author Empire92
*/
public class PlotDeleteEvent extends Event implements Cancellable {
public class PlotDeleteEvent extends Event {
private static HandlerList handlers = new HandlerList();
private final PlotId id;
private final String world;
private boolean cancelled;
/**
* PlotDeleteEvent: Called when a plot is deleted
@ -75,14 +73,4 @@ public class PlotDeleteEvent extends Event implements Cancellable {
public HandlerList getHandlers() {
return handlers;
}
@Override
public boolean isCancelled() {
return this.cancelled;
}
@Override
public void setCancelled(final boolean b) {
this.cancelled = b;
}
}

View File

@ -34,6 +34,7 @@ import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotSettings;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.EventUtil;
/**
* Flag Manager Utility
@ -137,7 +138,10 @@ public class FlagManager {
* @param flag
*/
public static boolean addPlotFlag(final Plot plot, final Flag flag) {
// FIXME PlotFlagAddEvent
final boolean result = EventUtil.manager.callFlagAdd(flag, plot);
if (!result) {
return false;
}
final Flag hasFlag = getPlotFlag(plot, flag.getKey());
if (hasFlag != null) {
plot.settings.flags.remove(hasFlag);
@ -189,7 +193,10 @@ public class FlagManager {
if (hasFlag != null) {
final Flag flagObj = FlagManager.getPlotFlagAbs(plot, flag);
if (flagObj != null) {
// FIXME PlotFlagRemoveEvent
final boolean result = EventUtil.manager.callFlagRemove(flagObj, plot);
if (!result) {
return false;
}
plot.settings.flags.remove(hasFlag);
DBFunc.setFlags(plot.world, plot, plot.settings.flags);
return true;

View File

@ -19,10 +19,10 @@ import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.util.AChunkManager;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.bukkit.ChunkManager;
import com.intellectualcrafters.plot.util.bukkit.SetBlockManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitChunkManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitSetBlockManager;
public class AugmentedPopulator extends BlockPopulator {
public final PlotWorld plotworld;
@ -38,8 +38,8 @@ public class AugmentedPopulator extends BlockPopulator {
private final int tx;
private final int tz;
public static void removePopulator(String worldname, PlotCluster cluster) {
World world = Bukkit.getWorld(worldname);
public static void removePopulator(final String worldname, final PlotCluster cluster) {
final World world = Bukkit.getWorld(worldname);
for (final Iterator<BlockPopulator> iterator = world.getPopulators().iterator(); iterator.hasNext();) {
final BlockPopulator populator = iterator.next();
if (populator instanceof AugmentedPopulator) {
@ -130,7 +130,7 @@ public class AugmentedPopulator extends BlockPopulator {
public void run() {
populateBiome(world, x, z);
chunk.unload(true, true);
SetBlockManager.setBlockManager.update(Arrays.asList(new Chunk[] { chunk }));
BukkitSetBlockManager.setBlockManager.update(Arrays.asList(new Chunk[] { chunk }));
}
}, 20);
} else {
@ -146,14 +146,14 @@ public class AugmentedPopulator extends BlockPopulator {
chunk.load(true);
populateBlocks(world, rand, X, Z, x, z, check);
chunk.unload(true, true);
SetBlockManager.setBlockManager.update(Arrays.asList(new Chunk[] { chunk }));
BukkitSetBlockManager.setBlockManager.update(Arrays.asList(new Chunk[] { chunk }));
}
}, 40 + rand.nextInt(40));
}
}
private void populateBiome(final World world, final int x, final int z) {
Biome biome = Biome.valueOf(this.plotworld.PLOT_BIOME);
final Biome biome = Biome.valueOf(this.plotworld.PLOT_BIOME);
if (this.b) {
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 16; j++) {
@ -175,15 +175,15 @@ public class AugmentedPopulator extends BlockPopulator {
final int xx = x + blockInfo.x;
final int zz = z + blockInfo.z;
if (this.p) {
if (AChunkManager.CURRENT_PLOT_CLEAR != null) {
if (ChunkManager.isIn(AChunkManager.CURRENT_PLOT_CLEAR, xx, zz)) {
if (ChunkManager.CURRENT_PLOT_CLEAR != null) {
if (BukkitChunkManager.isIn(ChunkManager.CURRENT_PLOT_CLEAR, xx, zz)) {
continue;
}
} else if (this.manager.getPlotIdAbs(this.plotworld, xx, 0, zz) != null) {
continue;
}
}
SetBlockManager.setBlockManager.set(world, xx, blockInfo.y, zz, blockInfo.id, (byte) 0);
BukkitSetBlockManager.setBlockManager.set(world, xx, blockInfo.y, zz, blockInfo.id, (byte) 0);
}
}
for (final BlockPopulator populator : this.generator.getDefaultPopulators(world)) {

View File

@ -14,15 +14,15 @@ import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.util.AChunkManager;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitSetBlockManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
import com.intellectualcrafters.plot.util.bukkit.SetBlockManager;
public class BukkitHybridUtils extends HybridUtils {
@Override
public int checkModified(int threshhold, String worldname, int x1, int x2, int y1, int y2, int z1, int z2, PlotBlock[] blocks) {
World world = BukkitUtil.getWorld(worldname);
public int checkModified(final int threshhold, final String worldname, final int x1, final int x2, final int y1, final int y2, final int z1, final int z2, final PlotBlock[] blocks) {
final World world = BukkitUtil.getWorld(worldname);
int count = 0;
for (int y = y1; y <= y2; y++) {
for (int x = x1; x <= x2; x++) {
@ -49,9 +49,9 @@ public class BukkitHybridUtils extends HybridUtils {
}
@Override
public int get_ey(String worldname, int sx, int ex, int sz, int ez, int sy) {
World world = BukkitUtil.getWorld(worldname);
int maxY = world.getMaxHeight();
public int get_ey(final String worldname, final int sx, final int ex, final int sz, final int ez, final int sy) {
final World world = BukkitUtil.getWorld(worldname);
final int maxY = world.getMaxHeight();
int ey = sy;
for (int x = sx; x <= ex; x++) {
for (int z = sz; z <= ez; z++) {
@ -69,8 +69,8 @@ public class BukkitHybridUtils extends HybridUtils {
}
@Override
public void regenerateChunkChunk(String worldname, ChunkLoc loc) {
World world = BukkitUtil.getWorld(worldname);
public void regenerateChunkChunk(final String worldname, final ChunkLoc loc) {
final World world = BukkitUtil.getWorld(worldname);
final int sx = loc.x << 5;
final int sz = loc.z << 5;
for (int x = sx; x < (sx + 32); x++) {
@ -84,10 +84,10 @@ public class BukkitHybridUtils extends HybridUtils {
for (int z = sz; z < (sz + 32); z++) {
final Chunk chunk = world.getChunkAt(x, z);
chunks2.add(chunk);
regenerateRoad(worldname, new ChunkLoc(x,z));
regenerateRoad(worldname, new ChunkLoc(x, z));
}
}
SetBlockManager.setBlockManager.update(chunks2);
BukkitSetBlockManager.setBlockManager.update(chunks2);
}
private static boolean UPDATE = false;
@ -98,8 +98,8 @@ public class BukkitHybridUtils extends HybridUtils {
if (BukkitHybridUtils.UPDATE) {
return false;
}
final List<ChunkLoc> chunks = AChunkManager.manager.getChunkChunks(world);
final Plugin plugin = (Plugin) BukkitMain.THIS;
final List<ChunkLoc> chunks = ChunkManager.manager.getChunkChunks(world);
final Plugin plugin = BukkitMain.THIS;
this.task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
@Override
public void run() {

View File

@ -7,6 +7,7 @@ import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.PseudoRandom;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.MainUtil;
@ -36,7 +37,7 @@ public abstract class ClassicPlotManager extends SquarePlotManager {
public boolean setFloor(final PlotWorld plotworld, final PlotId plotid, final PlotBlock[] blocks) {
final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld;
final Location pos1 = MainUtil.getPlotBottomLoc(plotworld.worldname, plotid).add(1, 0, 1);
final Location pos2 = MainUtil.getPlotTopLoc(plotworld.worldname, plotid);
final Location pos2 = MainUtil.getPlotTopLoc(plotworld.worldname, plotid).add(1, 0, 1);
pos1.setY(dpw.PLOT_HEIGHT);
pos2.setY(dpw.PLOT_HEIGHT + 1);
MainUtil.setCuboid(plotworld.worldname, pos1, pos2, blocks);
@ -49,56 +50,56 @@ public abstract class ClassicPlotManager extends SquarePlotManager {
return false;
}
final Location bottom = MainUtil.getPlotBottomLoc(plotworld.worldname, plotid);
final Location top = MainUtil.getPlotTopLoc(plotworld.worldname, plotid);
final Location top = MainUtil.getPlotTopLoc(plotworld.worldname, plotid).add(1, 0, 1);
int x, z;
z = bottom.getZ();
int length = top.getX() - bottom.getX();
int size = (length) * 4 * (dpw.WALL_HEIGHT);
final int length = top.getX() - bottom.getX();
final int size = (length) * 4 * (dpw.WALL_HEIGHT);
final int[] xl = new int[size];
final int[] yl = new int[size];
final int[] zl = new int[size];
final PlotBlock[] bl = new PlotBlock[size];
int i = 0;
for (x = bottom.getX(); x < (top.getX() + 1); x++) {
for (x = bottom.getX(); x <= (top.getX() - 1); x++) {
for (int y = 1; y <= dpw.WALL_HEIGHT; y++) {
xl[i] = x;
zl[i] = z;
yl[i] = y;
bl[i] = blocks[BlockManager.random(blocks.length)];
bl[i] = blocks[PseudoRandom.random(blocks.length)];
i++;
}
}
x = top.getX() + 1;
for (z = bottom.getZ(); z < (top.getZ() + 1); z++) {
x = top.getX();
for (z = bottom.getZ(); z <= (top.getZ() - 1); z++) {
for (int y = 1; y <= dpw.WALL_HEIGHT; y++) {
xl[i] = x;
zl[i] = z;
yl[i] = y;
bl[i] = blocks[BlockManager.random(blocks.length)];
bl[i] = blocks[PseudoRandom.random(blocks.length)];
i++;
}
}
z = top.getZ() + 1;
for (x = top.getX() + 1; x > (bottom.getX() - 1); x--) {
z = top.getZ();
for (x = top.getX(); x >= (bottom.getX() + 1); x--) {
for (int y = 1; y <= dpw.WALL_HEIGHT; y++) {
xl[i] = x;
zl[i] = z;
yl[i] = y;
bl[i] = blocks[BlockManager.random(blocks.length)];
bl[i] = blocks[PseudoRandom.random(blocks.length)];
i++;
}
}
x = bottom.getX();
for (z = top.getZ() + 1; z > (bottom.getZ() - 1); z--) {
for (z = top.getZ(); z >= (bottom.getZ() + 1); z--) {
for (int y = 1; y <= dpw.WALL_HEIGHT; y++) {
xl[i] = x;
zl[i] = z;
yl[i] = y;
bl[i] = blocks[BlockManager.random(blocks.length)];
bl[i] = blocks[PseudoRandom.random(blocks.length)];
i++;
}
}
BlockManager.setBlocks(plotworld.worldname, xl, yl, zl, blocks);
BlockManager.setBlocks(plotworld.worldname, xl, yl, zl, bl);
return true;
}
@ -108,9 +109,9 @@ public abstract class ClassicPlotManager extends SquarePlotManager {
return false;
}
final Location bottom = MainUtil.getPlotBottomLoc(plotworld.worldname, plotid);
final Location top = MainUtil.getPlotTopLoc(plotworld.worldname, plotid);
int length = top.getX() - bottom.getX();
int size = (length) * 4;
final Location top = MainUtil.getPlotTopLoc(plotworld.worldname, plotid).add(1, 0, 1);
final int length = top.getX() - bottom.getX();
final int size = (length) * 4;
final int[] xl = new int[size];
final int[] yl = new int[size];
final int[] zl = new int[size];
@ -118,39 +119,39 @@ public abstract class ClassicPlotManager extends SquarePlotManager {
int x, z;
z = bottom.getZ();
int i = 0;
int y = dpw.WALL_HEIGHT + 1;
for (x = bottom.getX(); x < (top.getX() + 1); x++) {
final int y = dpw.WALL_HEIGHT + 1;
for (x = bottom.getX(); x <= (top.getX() - 1); x++) {
xl[i] = x;
zl[i] = z;
yl[i] = y;
bl[i] = blocks[BlockManager.random(blocks.length)];
bl[i] = blocks[PseudoRandom.random(blocks.length)];
i++;
}
x = top.getX() + 1;
for (z = bottom.getZ(); z < (top.getZ() + 1); z++) {
x = top.getX();
for (z = bottom.getZ(); z <= (top.getZ() - 1); z++) {
xl[i] = x;
zl[i] = z;
yl[i] = y;
bl[i] = blocks[BlockManager.random(blocks.length)];
bl[i] = blocks[PseudoRandom.random(blocks.length)];
i++;
}
z = top.getZ() + 1;
for (x = top.getX() + 1; x > (bottom.getX() - 1); x--) {
z = top.getZ();
for (x = top.getX(); x >= (bottom.getX() + 1); x--) {
xl[i] = x;
zl[i] = z;
yl[i] = y;
bl[i] = blocks[BlockManager.random(blocks.length)];
bl[i] = blocks[PseudoRandom.random(blocks.length)];
i++;
}
x = bottom.getX();
for (z = top.getZ() + 1; z > (bottom.getZ() - 1); z--) {
for (z = top.getZ(); z >= (bottom.getZ() + 1); z--) {
xl[i] = x;
zl[i] = z;
yl[i] = y;
bl[i] = blocks[BlockManager.random(blocks.length)];
bl[i] = blocks[PseudoRandom.random(blocks.length)];
i++;
}
BlockManager.setBlocks(plotworld.worldname, xl, yl, zl, blocks);
BlockManager.setBlocks(plotworld.worldname, xl, yl, zl, bl);
return true;
}
@ -258,7 +259,6 @@ public abstract class ClassicPlotManager extends SquarePlotManager {
*/
@Override
public boolean finishPlotMerge(final PlotWorld plotworld, final ArrayList<PlotId> plotIds) {
final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld;
final PlotId pos1 = plotIds.get(0);
final PlotBlock block = ((ClassicPlotWorld) plotworld).WALL_BLOCK;
if (block.id != 0) {
@ -318,7 +318,7 @@ public abstract class ClassicPlotManager extends SquarePlotManager {
* Remove sign for a plot
*/
@Override
public com.intellectualcrafters.plot.object.Location getSignLoc(final PlotWorld plotworld, final Plot plot) {
public Location getSignLoc(final PlotWorld plotworld, final Plot plot) {
final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld;
final Location bot = MainUtil.getPlotBottomLoc(plotworld.worldname, plot.id);
return new com.intellectualcrafters.plot.object.Location(plotworld.worldname, bot.getX(), dpw.ROAD_HEIGHT + 1, bot.getZ() - 1);

View File

@ -31,13 +31,12 @@ import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.generator.BlockPopulator;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.PlotLoc;
import com.intellectualcrafters.plot.object.PlotGenerator;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.util.AChunkManager;
import com.intellectualcrafters.plot.util.ChunkManager;
/**
* The default generator is very messy, as we have decided to try externalize all calculations from within the loop. -
@ -59,22 +58,22 @@ public class HybridGen extends PlotGenerator {
/**
* Some generator specific variables (implementation dependent)
*/
final int plotsize;
final int pathsize;
final short wall;
final short wallfilling;
final short roadblock;
final int size;
final Biome biome;
final int roadheight;
final int wallheight;
final int plotheight;
final short[] plotfloors;
final short[] filling;
final short pathWidthLower;
final short pathWidthUpper;
int plotsize;
int pathsize;
short wall;
short wallfilling;
short roadblock;
int size;
Biome biome;
int roadheight;
int wallheight;
int plotheight;
short[] plotfloors;
short[] filling;
short pathWidthLower;
short pathWidthUpper;
boolean doState = false;
int maxY;
int maxY = 0;
/**
* result object is returned for each generated chunk, do stuff to it
*/
@ -87,10 +86,9 @@ public class HybridGen extends PlotGenerator {
/**
* Initialize variables, and create plotworld object used in calculations
*/
public HybridGen(final String world) {
super(world);
public void init(PlotWorld plotworld) {
if (this.plotworld == null) {
this.plotworld = (HybridPlotWorld) PlotSquared.getPlotWorld(world);
this.plotworld = (HybridPlotWorld) plotworld;
}
this.plotsize = this.plotworld.PLOT_WIDTH;
this.pathsize = this.plotworld.ROAD_WIDTH;
@ -120,10 +118,12 @@ public class HybridGen extends PlotGenerator {
this.pathWidthUpper = (short) (this.pathWidthLower + this.plotsize + 1);
this.biome = Biome.valueOf(this.plotworld.PLOT_BIOME);
try {
this.maxY = Bukkit.getWorld(world).getMaxHeight();
} catch (final NullPointerException e) {
this.maxY = Bukkit.getWorld(plotworld.worldname).getMaxHeight();
} catch (final NullPointerException e) {}
if (this.maxY == 0) {
this.maxY = 256;
}
}
/**
@ -197,8 +197,7 @@ public class HybridGen extends PlotGenerator {
/**
* Return the block populator
*/
@Override
public List<BlockPopulator> getDefaultPopulators(final World world) {
public List<BlockPopulator> getPopulators(final World world) {
// disabling spawning for this world
if (!this.plotworld.MOB_SPAWNING) {
world.setSpawnFlags(false, false);
@ -207,6 +206,9 @@ public class HybridGen extends PlotGenerator {
world.setMonsterSpawnLimit(0);
world.setWaterAnimalSpawnLimit(0);
}
else {
world.setSpawnFlags(true, true);
}
// You can have as many populators as you would like, e.g. tree
// populator, ore populator
return Arrays.asList((BlockPopulator) new HybridPop(this.plotworld));
@ -241,7 +243,7 @@ public class HybridGen extends PlotGenerator {
}
}
}
final RegionWrapper plot = AChunkManager.CURRENT_PLOT_CLEAR;
final RegionWrapper plot = ChunkManager.CURRENT_PLOT_CLEAR;
if (plot != null) {
final int X = cx << 4;
final int Z = cz << 4;
@ -264,8 +266,8 @@ public class HybridGen extends PlotGenerator {
}
setBlock(this.result, x, this.plotheight, z, this.plotfloors);
} else {
final ChunkLoc loc = new ChunkLoc(X + x, Z + z);
final HashMap<Short, Short> blocks = AChunkManager.GENERATE_BLOCKS.get(loc);
final PlotLoc loc = new PlotLoc((short) (X + x), (short) (Z + z));
final HashMap<Short, Short> blocks = ChunkManager.GENERATE_BLOCKS.get(loc);
if (blocks != null) {
for (final short y : blocks.keySet()) {
setBlock(this.result, x, y, z, blocks.get(y).shortValue());
@ -302,7 +304,7 @@ public class HybridGen extends PlotGenerator {
}
setBlock(this.result, x, this.plotheight, z, this.plotfloors);
if (this.plotworld.PLOT_SCHEMATIC) {
final ChunkLoc loc = new ChunkLoc(absX, absZ);
final PlotLoc loc = new PlotLoc((short) absX, (short) absZ);
final HashMap<Short, Short> blocks = this.plotworld.G_SCH.get(loc);
if (blocks != null) {
for (final short y : blocks.keySet()) {
@ -327,7 +329,7 @@ public class HybridGen extends PlotGenerator {
}
}
if (this.plotworld.ROAD_SCHEMATIC_ENABLED) {
final ChunkLoc loc = new ChunkLoc(absX, absZ);
final PlotLoc loc = new PlotLoc((short) absX, (short) absZ);
final HashMap<Short, Short> blocks = this.plotworld.G_SCH.get(loc);
if (blocks != null) {
for (final short y : blocks.keySet()) {

View File

@ -20,6 +20,14 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.generator;
import java.io.File;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.HashSet;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.commands.Template;
import com.intellectualcrafters.plot.object.FileBytes;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotBlock;
@ -31,6 +39,32 @@ import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
@SuppressWarnings("deprecation")
public class HybridPlotManager extends ClassicPlotManager {
@Override
public void exportTemplate(PlotWorld plotworld) {
HashSet<FileBytes> files = new HashSet<>(Arrays.asList(new FileBytes("templates/" + "tmp-data.yml", Template.getBytes(plotworld))));
String psRoot = PlotSquared.IMP.getDirectory() + File.separator;
String dir = "schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator + plotworld.worldname + File.separator;
String newDir = "schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator + "__TEMP_DIR__" + File.separator;
try {
File sideroad = new File(psRoot + dir + "sideroad.schematic");
if (sideroad.exists()) {
files.add(new FileBytes(newDir + "sideroad.schematic", Files.readAllBytes(sideroad.toPath())));
}
File intersection = new File(psRoot + dir + "intersection.schematic");
if (sideroad.exists()) {
files.add(new FileBytes(newDir + "intersection.schematic", Files.readAllBytes(intersection.toPath())));
}
File plot = new File(psRoot + dir + "plot.schematic");
if (sideroad.exists()) {
files.add(new FileBytes(newDir + "plot.schematic", Files.readAllBytes(plot.toPath())));
}
}
catch (Exception e) {
e.printStackTrace();
}
Template.zipAll(plotworld.worldname, files);
}
/**
* Clearing the plot needs to only consider removing the blocks - This implementation has used the SetCuboid
* function, as it is fast, and uses NMS code - It also makes use of the fact that deleting chunks is a lot faster
@ -83,6 +117,7 @@ public class HybridPlotManager extends ClassicPlotManager {
@Override
public void run() {
MainUtil.setCuboid(world, new Location(world, pos1.getX(), dpw.PLOT_HEIGHT, pos1.getZ()), new Location(world, pos2.getX() + 1, dpw.PLOT_HEIGHT + 1, pos2.getZ() + 1), plotfloor);
TaskManager.runTask(whenDone);
}
}, 5);
}

View File

@ -21,6 +21,7 @@
package com.intellectualcrafters.plot.generator;
import java.util.HashMap;
import java.util.HashSet;
import org.apache.commons.lang.StringUtils;
import org.bukkit.configuration.ConfigurationSection;
@ -28,8 +29,9 @@ import org.bukkit.configuration.ConfigurationSection;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Configuration;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.PlotLoc;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.schematic.PlotItem;
import com.intellectualcrafters.plot.util.SchematicHandler;
import com.intellectualcrafters.plot.util.SchematicHandler.DataCollection;
import com.intellectualcrafters.plot.util.SchematicHandler.Dimension;
@ -50,8 +52,9 @@ public class HybridPlotWorld extends ClassicPlotWorld {
super(worldname);
}
public HashMap<ChunkLoc, HashMap<Short, Short>> G_SCH;
public HashMap<ChunkLoc, HashMap<Short, Byte>> G_SCH_DATA;
public HashMap<PlotLoc, HashMap<Short, Short>> G_SCH;
public HashMap<PlotLoc, HashMap<Short, Byte>> G_SCH_DATA;
public HashMap<PlotLoc, HashSet<PlotItem>> G_SCH_STATE;
/**
* This method is called when a world loads. Make sure you set all your constants here. You are provided with the
@ -87,7 +90,6 @@ public class HybridPlotWorld extends ClassicPlotWorld {
PlotSquared.log("&c - road schematics are disabled for this world.");
this.ROAD_SCHEMATIC_ENABLED = false;
}
System.out.print("LOADED!");
}
public void setupSchematics() {
@ -96,9 +98,9 @@ public class HybridPlotWorld extends ClassicPlotWorld {
final String schem1Str = "GEN_ROAD_SCHEMATIC/" + this.worldname + "/sideroad";
final String schem2Str = "GEN_ROAD_SCHEMATIC/" + this.worldname + "/intersection";
final String schem3Str = "GEN_ROAD_SCHEMATIC/" + this.worldname + "/plot";
final Schematic schem1 = SchematicHandler.getSchematic(schem1Str);
final Schematic schem2 = SchematicHandler.getSchematic(schem2Str);
final Schematic schem3 = SchematicHandler.getSchematic(schem3Str);
final Schematic schem1 = SchematicHandler.manager.getSchematic(schem1Str);
final Schematic schem2 = SchematicHandler.manager.getSchematic(schem2Str);
final Schematic schem3 = SchematicHandler.manager.getSchematic(schem3Str);
final int shift = (int) Math.floor(this.ROAD_WIDTH / 2);
int oddshift = 0;
if ((this.ROAD_WIDTH % 2) != 0) {
@ -131,6 +133,23 @@ public class HybridPlotWorld extends ClassicPlotWorld {
}
}
}
HashSet<PlotItem> items = schem3.getItems();
if (items != null) {
G_SCH_STATE = new HashMap<>();
for (PlotItem item : items) {
item.x += shift + oddshift + center_shift_x;
item.z += shift + oddshift + center_shift_z;
item.y += this.PLOT_HEIGHT;
int x = item.x;
int y = item.y;
int z = item.z;
PlotLoc loc = new PlotLoc((short) x, (short) z);
if (!G_SCH_STATE.containsKey(loc)) {
G_SCH_STATE.put(loc, new HashSet<PlotItem>());
}
G_SCH_STATE.get(loc).add(item);
}
}
}
if ((schem1 == null) || (schem2 == null) || (this.ROAD_WIDTH == 0)) {
PlotSquared.log(C.PREFIX.s() + "&3 - schematic: &7false");
@ -301,7 +320,7 @@ public class HybridPlotWorld extends ClassicPlotWorld {
if (x < 0) {
x += this.SIZE;
}
final ChunkLoc loc = new ChunkLoc(x, z);
final PlotLoc loc = new PlotLoc(x, z);
if (!this.G_SCH.containsKey(loc)) {
this.G_SCH.put(loc, new HashMap<Short, Short>());
}

View File

@ -1,6 +1,7 @@
package com.intellectualcrafters.plot.generator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Random;
import org.bukkit.Chunk;
@ -9,10 +10,12 @@ import org.bukkit.block.Biome;
import org.bukkit.generator.BlockPopulator;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.PlotLoc;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.util.AChunkManager;
import com.intellectualcrafters.plot.object.schematic.PlotItem;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.ChunkManager;
/**
* @author Citymonstret
@ -116,8 +119,8 @@ public class HybridPop extends BlockPopulator {
}
this.X = cx << 4;
this.Z = cz << 4;
final HybridPlotManager manager = (HybridPlotManager) PlotSquared.getPlotManager(w.getName());
final RegionWrapper plot = AChunkManager.CURRENT_PLOT_CLEAR;
PlotSquared.getPlotManager(w.getName());
final RegionWrapper plot = ChunkManager.CURRENT_PLOT_CLEAR;
if (plot != null) {
short sx = (short) ((this.X) % this.size);
short sz = (short) ((this.Z) % this.size);
@ -138,9 +141,24 @@ public class HybridPop extends BlockPopulator {
if (this.doFloor) {
setBlock(w, x, (short) this.plotheight, z, this.plotfloors);
}
if (this.plotworld.PLOT_SCHEMATIC) {
final PlotLoc loc = new PlotLoc((short) (this.X + x), (short) (this.Z + z));
final HashMap<Short, Byte> blocks = this.plotworld.G_SCH_DATA.get(loc);
if (blocks != null) {
for (final short y : blocks.keySet()) {
setBlock(w, x, (short) (this.plotheight + y), z, blocks.get(y));
}
}
HashSet<PlotItem> states = this.plotworld.G_SCH_STATE.get(loc);
if (states != null) {
for (PlotItem items : states) {
BlockManager.manager.addItems(this.plotworld.worldname, items);
}
}
}
} else {
final ChunkLoc loc = new ChunkLoc(this.X + x, this.Z + z);
final HashMap<Short, Byte> data = AChunkManager.GENERATE_DATA.get(loc);
final PlotLoc loc = new PlotLoc((short) (this.X + x), (short) (this.Z + z));
final HashMap<Short, Byte> data = ChunkManager.GENERATE_DATA.get(loc);
if (data != null) {
for (final short y : data.keySet()) {
setBlock(w, x, y, z, data.get(y).byteValue());
@ -178,6 +196,23 @@ public class HybridPop extends BlockPopulator {
if (this.doFloor) {
setBlock(w, x, (short) this.plotheight, z, this.plotfloors);
}
if (this.plotworld.PLOT_SCHEMATIC) {
final PlotLoc loc = new PlotLoc(absX, absZ);
final HashMap<Short, Byte> blocks = this.plotworld.G_SCH_DATA.get(loc);
if (blocks != null) {
for (final short y : blocks.keySet()) {
setBlock(w, x, (short) (this.plotheight + y), z, blocks.get(y));
}
}
HashSet<PlotItem> states = this.plotworld.G_SCH_STATE.get(loc);
if (states != null) {
for (PlotItem items : states) {
items.x = this.X + x;
items.z = this.Z + z;
BlockManager.manager.addItems(this.plotworld.worldname, items);
}
}
}
} else {
// wall
if (((absX >= this.pathWidthLower) && (absX <= this.pathWidthUpper) && (absZ >= this.pathWidthLower) && (absZ <= this.pathWidthUpper))) {
@ -199,7 +234,7 @@ public class HybridPop extends BlockPopulator {
}
}
if (this.plotworld.ROAD_SCHEMATIC_ENABLED) {
final ChunkLoc loc = new ChunkLoc(absX, absZ);
final PlotLoc loc = new PlotLoc(absX, absZ);
final HashMap<Short, Byte> blocks = this.plotworld.G_SCH_DATA.get(loc);
if (blocks != null) {
for (final short y : blocks.keySet()) {

View File

@ -11,8 +11,8 @@ 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.util.AChunkManager;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.SchematicHandler;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
@ -72,11 +72,11 @@ public abstract class HybridUtils {
final int ty = get_ey(world, bx, tx, bz, tz, by);
final Location pos3 = new Location(world, bx, by, bz);
final Location pos4 = new Location(world, tx, ty, tz);
final CompoundTag sideroad = SchematicHandler.getCompoundTag(world, pos1, pos2);
final CompoundTag intersection = SchematicHandler.getCompoundTag(world, pos3, pos4);
final CompoundTag sideroad = SchematicHandler.manager.getCompoundTag(world, pos1, pos2);
final CompoundTag intersection = SchematicHandler.manager.getCompoundTag(world, pos3, pos4);
final String dir = PlotSquared.IMP.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");
SchematicHandler.manager.save(sideroad, dir + "sideroad.schematic");
SchematicHandler.manager.save(intersection, dir + "intersection.schematic");
plotworld.ROAD_SCHEMATIC_ENABLED = true;
plotworld.setupSchematics();
return true;
@ -88,7 +88,7 @@ public abstract class HybridUtils {
public abstract boolean scheduleRoadUpdate(final String world);
public boolean regenerateRoad(String world, final ChunkLoc chunk) {
public boolean regenerateRoad(final String world, final ChunkLoc chunk) {
final int x = chunk.x << 4;
final int z = chunk.z << 4;
final int ex = x + 15;
@ -97,12 +97,12 @@ public abstract class HybridUtils {
if (!plotworld.ROAD_SCHEMATIC_ENABLED) {
return false;
}
PlotManager manager = PlotSquared.getPlotManager(world);
final PlotManager manager = PlotSquared.getPlotManager(world);
final PlotId id1 = manager.getPlotId(plotworld, x, 0, z);
final PlotId id2 = manager.getPlotId(plotworld, ex, 0, ez);
boolean toCheck = false;
if ((id1 == null) || (id2 == null) || (id1 != id2)) {
final boolean result = AChunkManager.manager.loadChunk(world, chunk);
final boolean result = ChunkManager.manager.loadChunk(world, chunk);
if (result) {
if (id1 != null) {
final Plot p1 = MainUtil.getPlot(world, id1);

View File

@ -5,8 +5,8 @@ import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.AChunkManager;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.MainUtil;
/**
@ -17,7 +17,7 @@ public abstract class SquarePlotManager extends GridPlotManager {
public boolean clearPlot(final PlotWorld plotworld, final Plot plot, final boolean isDelete, final Runnable whenDone) {
final Location pos1 = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1);
final Location pos2 = MainUtil.getPlotTopLoc(plot.world, plot.id);
AChunkManager.manager.regenerateRegion(pos1, pos2, whenDone);
ChunkManager.manager.regenerateRegion(pos1, pos2, whenDone);
return true;
}
@ -32,7 +32,7 @@ public abstract class SquarePlotManager extends GridPlotManager {
}
@Override
public PlotId getPlotIdAbs(final PlotWorld plotworld, int x, int y, int z) {
public PlotId getPlotIdAbs(final PlotWorld plotworld, int x, final int y, int z) {
final SquarePlotWorld dpw = ((SquarePlotWorld) plotworld);
// get plot size
final int size = dpw.PLOT_WIDTH + dpw.ROAD_WIDTH;
@ -70,7 +70,7 @@ public abstract class SquarePlotManager extends GridPlotManager {
}
@Override
public PlotId getPlotId(final PlotWorld plotworld, int x, int y, int z) {
public PlotId getPlotId(final PlotWorld plotworld, int x, final int y, int z) {
final SquarePlotWorld dpw = ((SquarePlotWorld) plotworld);
if (plotworld == null) {
return null;
@ -99,7 +99,7 @@ public abstract class SquarePlotManager extends GridPlotManager {
final boolean eastWest = (rx <= pathWidthLower) || (rx > end);
if (northSouth && eastWest) {
// This means you are in the intersection
Location loc = new Location(plotworld.worldname, x + dpw.ROAD_WIDTH, y, z + dpw.ROAD_WIDTH);
final Location loc = new Location(plotworld.worldname, x + dpw.ROAD_WIDTH, y, z + dpw.ROAD_WIDTH);
final PlotId id = MainUtil.getPlotAbs(loc);
final Plot plot = PlotSquared.getPlots(plotworld.worldname).get(id);
if (plot == null) {
@ -112,7 +112,7 @@ public abstract class SquarePlotManager extends GridPlotManager {
}
if (northSouth) {
// You are on a road running West to East (yeah, I named the var poorly)
Location loc = new Location(plotworld.worldname, x, y, z + dpw.ROAD_WIDTH);
final Location loc = new Location(plotworld.worldname, x, y, z + dpw.ROAD_WIDTH);
final PlotId id = MainUtil.getPlotAbs(loc);
final Plot plot = PlotSquared.getPlots(plotworld.worldname).get(id);
if (plot == null) {
@ -125,7 +125,7 @@ public abstract class SquarePlotManager extends GridPlotManager {
}
if (eastWest) {
// This is the road separating an Eastern and Western plot
Location loc = new Location(plotworld.worldname, x + dpw.ROAD_WIDTH, y, z);
final Location loc = new Location(plotworld.worldname, x + dpw.ROAD_WIDTH, y, z);
final PlotId id = MainUtil.getPlotAbs(loc);
final Plot plot = PlotSquared.getPlots(plotworld.worldname).get(id);
if (plot == null) {
@ -166,10 +166,10 @@ public abstract class SquarePlotManager extends GridPlotManager {
final int topX = MainUtil.getPlotTopLoc(plot.world, plot.id).getX() + 1;
final int bottomZ = MainUtil.getPlotBottomLoc(plot.world, plot.id).getZ() - 1;
final int topZ = MainUtil.getPlotTopLoc(plot.world, plot.id).getZ() + 1;
int size = (topX - bottomX + 1) * (topZ - bottomZ + 1);
int[] xb = new int[size];
int[] zb = new int[size];
int[] biomes = new int[size];
final int size = ((topX - bottomX) + 1) * ((topZ - bottomZ) + 1);
final int[] xb = new int[size];
final int[] zb = new int[size];
final int[] biomes = new int[size];
int index = 0;
for (int x = bottomX; x <= topX; x++) {
for (int z = bottomZ; z <= topZ; z++) {

View File

@ -51,7 +51,7 @@ public class ForceFieldListener implements Listener {
if (!(entity instanceof Player) || ((oPlayer = (Player) entity) == null) || !BukkitPlayerFunctions.isInPlot(oPlayer) || !BukkitPlayerFunctions.getCurrentPlot(oPlayer).equals(plot)) {
continue;
}
UUID uuid = UUIDHandler.getUUID(BukkitUtil.getPlayer(oPlayer));
final UUID uuid = UUIDHandler.getUUID(BukkitUtil.getPlayer(oPlayer));
if (!plot.isAdded(uuid)) {
players.add(oPlayer);
}
@ -65,7 +65,7 @@ public class ForceFieldListener implements Listener {
if (!(entity instanceof Player) || ((oPlayer = (Player) entity) == null) || !BukkitPlayerFunctions.isInPlot(oPlayer) || !BukkitPlayerFunctions.getCurrentPlot(oPlayer).equals(plot)) {
continue;
}
UUID uuid = UUIDHandler.getUUID(BukkitUtil.getPlayer(oPlayer));
final UUID uuid = UUIDHandler.getUUID(BukkitUtil.getPlayer(oPlayer));
if (plot.isAdded(uuid)) {
return oPlayer;
}
@ -99,15 +99,15 @@ public class ForceFieldListener implements Listener {
@EventHandler
public void onPlotEntry(final PlayerMoveEvent event) {
final Player player = event.getPlayer();
PlotPlayer pp = BukkitUtil.getPlayer(player);
Location loc = pp.getLocation();
Plot plot = MainUtil.getPlot(loc);
final PlotPlayer pp = BukkitUtil.getPlayer(player);
final Location loc = pp.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return;
}
if ((FlagManager.getPlotFlag(plot, "forcefield") != null) && FlagManager.getPlotFlag(plot, "forcefield").getValue().equals("true")) {
if (!PlotListener.booleanFlag(plot, "forcefield", false)) {
UUID uuid = pp.getUUID();
final UUID uuid = pp.getUUID();
if (plot.isAdded(uuid)) {
final Set<Player> players = getNearbyPlayers(player, plot);
for (final Player oPlayer : players) {

View File

@ -31,7 +31,6 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Chunk;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
@ -70,6 +69,8 @@ import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerEggThrowEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
@ -80,20 +81,18 @@ import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.vehicle.VehicleDestroyEvent;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.StructureGrowEvent;
import org.bukkit.event.world.WorldInitEvent;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.Plugin;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.commands.Setup;
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.BukkitPlayer;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotGenerator;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer;
@ -113,14 +112,21 @@ import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
* @author Empire92
*/
public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public static void onWorldInit(final WorldInitEvent event) {
final World world = event.getWorld();
final ChunkGenerator gen = world.getGenerator();
if (gen instanceof PlotGenerator) {
PlotSquared.loadWorld(world.getName(), (PlotGenerator) gen);
@EventHandler
public void PlayerCommand(final PlayerCommandPreprocessEvent event) {
final String message = event.getMessage();
if (message.toLowerCase().startsWith("/plotme")) {
final Plugin plotme = Bukkit.getPluginManager().getPlugin("PlotMe");
if (plotme == null) {
final Player player = event.getPlayer();
if (Settings.USE_PLOTME_ALIAS) {
player.performCommand(message.replace("/plotme", "plots"));
} else {
PlotSquared.loadWorld(world.getName(), null);
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.NOT_USING_PLOTME);
}
event.setCancelled(true);
}
}
}
@ -144,7 +150,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
if (!player.hasPlayedBefore()) {
player.saveData();
}
PlotPlayer pp = BukkitUtil.getPlayer(player);
final PlotPlayer pp = BukkitUtil.getPlayer(player);
final String username = pp.getName();
final StringWrapper name = new StringWrapper(username);
final UUID uuid = pp.getUUID();
@ -189,7 +195,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
passed = false;
}
if (passed) {
PlotPlayer pp = BukkitUtil.getPlayer(player);
final PlotPlayer pp = BukkitUtil.getPlayer(player);
MainUtil.sendMessage(pp, C.BORDER);
return;
}
@ -197,7 +203,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
Plot plot = getCurrentPlot(t);
if (plot != null) {
if (plot.denied.size() > 0) {
PlotPlayer pp = BukkitUtil.getPlayer(player);
final PlotPlayer pp = BukkitUtil.getPlayer(player);
if (plot.isDenied(pp.getUUID())) {
if (!Permissions.hasPermission(pp, "plots.admin.entry.denied")) {
MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.entry.denied");
@ -263,7 +269,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
return;
}
if (!plot.hasOwner()) {
PlotPlayer pp = BukkitUtil.getPlayer(player);
final PlotPlayer pp = BukkitUtil.getPlayer(player);
if (Permissions.hasPermission(pp, "plots.admin.destroy.unowned")) {
return;
}
@ -271,7 +277,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
event.setCancelled(true);
return;
}
PlotPlayer pp = BukkitUtil.getPlayer(player);
final PlotPlayer pp = BukkitUtil.getPlayer(player);
if (!plot.isAdded(pp.getUUID())) {
final Flag destroy = FlagManager.getPlotFlag(plot, "break");
final Block block = event.getBlock();
@ -287,7 +293,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
}
return;
}
PlotPlayer pp = BukkitUtil.getPlayer(player);
final PlotPlayer pp = BukkitUtil.getPlayer(player);
if (Permissions.hasPermission(pp, "plots.admin.destroy.road")) {
return;
}
@ -323,7 +329,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
} else {
final Iterator<Block> iter = event.blockList().iterator();
while (iter.hasNext()) {
final Block b = iter.next();
iter.next();
if (isPlotArea(loc)) {
iter.remove();
}
@ -331,6 +337,13 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
}
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public static void onWorldChanged(final PlayerChangedWorldEvent event) {
final PlotPlayer player = BukkitUtil.getPlayer(event.getPlayer());
((BukkitPlayer) player).hasPerm = new HashSet<>();
((BukkitPlayer) player).noPerm = new HashSet<>();
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public static void onPeskyMobsChangeTheWorldLikeWTFEvent(final EntityChangeBlockEvent event) {
final String world = event.getBlock().getWorld().getName();
@ -348,7 +361,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
final Player p = (Player) e;
final Location loc = BukkitUtil.getLocation(b.getLocation());
if (!isInPlot(loc)) {
PlotPlayer pp = BukkitUtil.getPlayer(p);
final PlotPlayer pp = BukkitUtil.getPlayer(p);
if (!Permissions.hasPermission(pp, "plots.admin.build.road")) {
MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.build.road");
event.setCancelled(true);
@ -357,14 +370,14 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
} else {
final Plot plot = getCurrentPlot(loc);
if ((plot == null) || !plot.hasOwner()) {
PlotPlayer pp = BukkitUtil.getPlayer(p);
final PlotPlayer pp = BukkitUtil.getPlayer(p);
if (!Permissions.hasPermission(pp, "plots.admin.build.unowned")) {
MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.build.unowned");
event.setCancelled(true);
return;
}
} else {
PlotPlayer pp = BukkitUtil.getPlayer(p);
final PlotPlayer pp = BukkitUtil.getPlayer(p);
if (!plot.isAdded(pp.getUUID())) {
if (!Permissions.hasPermission(pp, "plots.admin.build.other")) {
if (isPlotArea(loc)) {
@ -474,7 +487,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
public static void onBlockPistonExtend(final BlockPistonExtendEvent e) {
if (isInPlot(BukkitUtil.getLocation(e.getBlock().getLocation()))) {
for (final Block block : e.getBlocks()) {
Plot plot = getCurrentPlot(BukkitUtil.getLocation(block.getLocation()));
final Plot plot = getCurrentPlot(BukkitUtil.getLocation(block.getLocation()));
if (plot != null) {
if (isPlotArea(BukkitUtil.getLocation(e.getBlock().getLocation()))) {
e.setCancelled(true);
@ -503,11 +516,10 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
return;
}
final List<BlockState> blocks = e.getBlocks();
boolean remove = false;
for (int i = blocks.size() - 1; i >= 0; i--) {
final Location loc = BukkitUtil.getLocation(blocks.get(i).getLocation());
Plot plot = getCurrentPlot(loc);
if (plot == null || !plot.hasOwner()) {
final Plot plot = getCurrentPlot(loc);
if ((plot == null) || !plot.hasOwner()) {
e.getBlocks().remove(i);
}
}
@ -531,7 +543,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
if (isInPlot(loc)) {
final Plot plot = getCurrentPlot(loc);
if (!plot.hasOwner()) {
PlotPlayer pp = BukkitUtil.getPlayer(player);
final PlotPlayer pp = BukkitUtil.getPlayer(player);
if (Permissions.hasPermission(pp, "plots.admin.interact.unowned")) {
return;
}
@ -543,7 +555,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
if ((use != null) && ((HashSet<PlotBlock>) use.getValue()).contains(new PlotBlock((short) block.getTypeId(), block.getData()))) {
return;
}
PlotPlayer pp = BukkitUtil.getPlayer(player);
final PlotPlayer pp = BukkitUtil.getPlayer(player);
if (!plot.isAdded(pp.getUUID())) {
if (Permissions.hasPermission(pp, "plots.admin.interact.other")) {
return;
@ -554,7 +566,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
}
return;
}
PlotPlayer pp = BukkitUtil.getPlayer(player);
final PlotPlayer pp = BukkitUtil.getPlayer(player);
if (Permissions.hasPermission(pp, "plots.admin.interact.road")) {
return;
}
@ -570,7 +582,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
if (event.getEntity() instanceof Player) {
return;
}
Location loc = BukkitUtil.getLocation(event.getLocation());
final Location loc = BukkitUtil.getLocation(event.getLocation());
final String world = loc.getWorld();
if (!isPlotWorld(world)) {
return;
@ -594,28 +606,24 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public static void onBlockIgnite(final BlockIgniteEvent e) {
Player player = e.getPlayer();
final Player player = e.getPlayer();
final Block b = e.getBlock();
final Location loc;
if (b != null) {
loc = BukkitUtil.getLocation(b.getLocation());
}
else {
Entity ent = e.getIgnitingEntity();
} else {
final Entity ent = e.getIgnitingEntity();
if (ent != null) {
loc = BukkitUtil.getLocation(ent);
}
else {
} else {
if (player != null) {
loc = BukkitUtil.getLocation(player);
}
else {
} else {
return;
}
}
}
final String world;
if (e.getBlock() != null) {
world = e.getBlock().getWorld().getName();
@ -641,7 +649,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
}
final Player p = e.getPlayer();
if (!isInPlot(loc)) {
PlotPlayer pp = BukkitUtil.getPlayer(p);
final PlotPlayer pp = BukkitUtil.getPlayer(p);
if (!Permissions.hasPermission(pp, "plots.admin.build.road")) {
MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.build.road");
e.setCancelled(true);
@ -650,15 +658,16 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
} else {
final Plot plot = getCurrentPlot(loc);
if ((plot == null) || !plot.hasOwner()) {
PlotPlayer pp = BukkitUtil.getPlayer(p);
final PlotPlayer pp = BukkitUtil.getPlayer(p);
if (!Permissions.hasPermission(pp, "plots.admin.build.unowned")) {
MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.build.unowned");
e.setCancelled(true);
return;
}
} else {
PlotPlayer pp = BukkitUtil.getPlayer(p);
if (!plot.isAdded(pp.getUUID())) if (!Permissions.hasPermission(pp, "plots.admin.build.other")) {
final PlotPlayer pp = BukkitUtil.getPlayer(p);
if (!plot.isAdded(pp.getUUID())) {
if (!Permissions.hasPermission(pp, "plots.admin.build.other")) {
if (isPlotArea(loc)) {
MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.build.other");
e.setCancelled(true);
@ -668,17 +677,18 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
}
}
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public static void onTeleport(final PlayerTeleportEvent event) {
final Location f = BukkitUtil.getLocation(event.getFrom());
final Location t = BukkitUtil.getLocation(event.getTo());
final Location q = new Location(t.getWorld(), t.getX(), 64, t.getZ());
Player player = event.getPlayer();
final Player player = event.getPlayer();
if (isPlotWorld(q)) {
if (isInPlot(q)) {
final Plot plot = getCurrentPlot(q);
PlotPlayer pp = BukkitUtil.getPlayer(player);
final PlotPlayer pp = BukkitUtil.getPlayer(player);
if (plot.isDenied(pp.getUUID())) {
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.YOU_BE_DENIED);
event.setCancelled(true);
@ -707,7 +717,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
final Block b = e.getBlockClicked().getLocation().add(bf.getModX(), bf.getModY(), bf.getModZ()).getBlock();
final Location loc = BukkitUtil.getLocation(b.getLocation());
if (isPlotWorld(loc)) {
PlotPlayer pp = BukkitUtil.getPlayer(e.getPlayer());
final PlotPlayer pp = BukkitUtil.getPlayer(e.getPlayer());
if (!isInPlot(loc)) {
if (Permissions.hasPermission(pp, "plots.admin.build.road")) {
return;
@ -752,7 +762,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
@EventHandler
public static void onLeave(final PlayerQuitEvent event) {
String name = event.getPlayer().getName();
final String name = event.getPlayer().getName();
if (SetupUtils.setupMap.containsKey(name)) {
SetupUtils.setupMap.remove(name);
}
@ -775,7 +785,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
final Location loc = BukkitUtil.getLocation(b.getLocation());
if (isPlotWorld(loc)) {
final Player p = e.getPlayer();
PlotPlayer pp = BukkitUtil.getPlayer(p);
final PlotPlayer pp = BukkitUtil.getPlayer(p);
if (!isInPlot(loc)) {
if (Permissions.hasPermission(pp, "plots.admin.build.road")) {
return;
@ -817,7 +827,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
final Location loc = BukkitUtil.getLocation(b.getLocation());
if (isPlotWorld(loc)) {
final Player p = e.getPlayer();
PlotPlayer pp = BukkitUtil.getPlayer(p);
final PlotPlayer pp = BukkitUtil.getPlayer(p);
if (!isInPlot(loc)) {
if (!Permissions.hasPermission(pp, "plots.admin.build.road")) {
MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.build.road");
@ -854,7 +864,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
if (r instanceof Player) {
final Player p = (Player) r;
final Location l = BukkitUtil.getLocation(e.getEntity());
PlotPlayer pp = BukkitUtil.getPlayer(p);
final PlotPlayer pp = BukkitUtil.getPlayer(p);
if (isPlotWorld(l)) {
if (!isInPlot(l)) {
if (!Permissions.hasPermission(pp, "plots.admin.destroy.road")) {
@ -892,7 +902,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
final Location l = BukkitUtil.getLocation(e.getRightClicked().getLocation());
if (isPlotWorld(l)) {
final Player p = e.getPlayer();
PlotPlayer pp = BukkitUtil.getPlayer(p);
final PlotPlayer pp = BukkitUtil.getPlayer(p);
if (!isInPlot(l)) {
if (!Permissions.hasPermission(pp, "plots.admin.interact.road")) {
MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.interact.road");
@ -940,8 +950,8 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
final Entity d = e.getAttacker();
if (d instanceof Player) {
final Player p = (Player) d;
final PlotWorld pW = PlotSquared.getPlotWorld(l.getWorld());
PlotPlayer pp = BukkitUtil.getPlayer(p);
PlotSquared.getPlotWorld(l.getWorld());
final PlotPlayer pp = BukkitUtil.getPlayer(p);
if (!isInPlot(l)) {
if (!Permissions.hasPermission(pp, "plots.admin.vehicle.break.road")) {
MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.vehicle.break.road");
@ -998,7 +1008,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
return;
}
if (!isInPlot(l)) {
PlotPlayer pp = BukkitUtil.getPlayer(p);
final PlotPlayer pp = BukkitUtil.getPlayer(p);
if (!Permissions.hasPermission(pp, "plots.admin.pve.road")) {
MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.pve.road");
e.setCancelled(true);
@ -1007,7 +1017,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
} else {
final Plot plot = getCurrentPlot(l);
if ((plot == null) || !plot.hasOwner()) {
PlotPlayer pp = BukkitUtil.getPlayer(p);
final PlotPlayer pp = BukkitUtil.getPlayer(p);
if (!Permissions.hasPermission(pp, "plots.admin.pve.unowned")) {
MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.pve.unowned");
e.setCancelled(true);
@ -1020,7 +1030,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
return;
}
assert plot != null;
PlotPlayer pp = BukkitUtil.getPlayer(p);
final PlotPlayer pp = BukkitUtil.getPlayer(p);
if (!plot.isAdded(pp.getUUID())) {
if ((a instanceof Monster) && FlagManager.isPlotFlagTrue(plot, "hostile-attack")) {
return;
@ -1052,7 +1062,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
final Location l = BukkitUtil.getLocation(e.getEgg().getLocation());
if (isPlotWorld(l)) {
final Player p = e.getPlayer();
PlotPlayer pp = BukkitUtil.getPlayer(p);
final PlotPlayer pp = BukkitUtil.getPlayer(p);
if (!isInPlot(l)) {
if (!Permissions.hasPermission(pp, "plots.admin.projectile.road")) {
MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.projectile.road");
@ -1087,7 +1097,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
if (!isPlotWorld(world)) {
return;
}
PlotPlayer pp = BukkitUtil.getPlayer(player);
final PlotPlayer pp = BukkitUtil.getPlayer(player);
if (Permissions.hasPermission(pp, "plots.admin")) {
return;
}

View File

@ -2,7 +2,6 @@ package com.intellectualcrafters.plot.listeners;
import java.util.UUID;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@ -18,11 +17,11 @@ import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
public class PlayerEvents_1_8 extends PlotListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public static void onInteract(final PlayerInteractAtEntityEvent e) {
public void onInteract(final PlayerInteractAtEntityEvent e) {
final Location l = BukkitUtil.getLocation(e.getRightClicked().getLocation());
if (isPlotWorld(l)) {
final Player p = e.getPlayer();
PlotPlayer pp = BukkitUtil.getPlayer(e.getPlayer());
e.getPlayer();
final PlotPlayer pp = BukkitUtil.getPlayer(e.getPlayer());
if (!isInPlot(l)) {
if (!Permissions.hasPermission(pp, "plots.admin.interact.road")) {
MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.interact.road");
@ -36,7 +35,7 @@ public class PlayerEvents_1_8 extends PlotListener implements Listener {
e.setCancelled(true);
}
} else {
UUID uuid = pp.getUUID();
final UUID uuid = pp.getUUID();
if (!plot.isAdded(uuid)) {
if (!Permissions.hasPermission(pp, "plots.admin.interact.other")) {
if (isPlotArea(l)) {

View File

@ -107,19 +107,19 @@ public class PlotPlusListener extends PlotListener implements Listener {
}
event.setCancelled(true);
final Plot plot = MainUtil.getPlot(BukkitUtil.getLocation(player));
PlotPlayer pp = BukkitUtil.getPlayer(player);
final PlotPlayer pp = BukkitUtil.getPlayer(player);
if (plot == null) {
MainUtil.sendMessage(pp, C.NOT_IN_PLOT);
return;
}
UUID uuid = pp.getUUID();
final UUID uuid = pp.getUUID();
if (!plot.isAdded(uuid)) {
MainUtil.sendMessage(pp, C.NO_PLOT_PERMS);
return;
}
final Set<Player> plotPlayers = new HashSet<>();
for (final Player p : player.getWorld().getPlayers()) {
Plot newPlot = MainUtil.getPlot(BukkitUtil.getLocation(player));
final Plot newPlot = MainUtil.getPlot(BukkitUtil.getLocation(player));
if (plot.equals(newPlot)) {
plotPlayers.add(p);
}
@ -173,12 +173,12 @@ public class PlotPlusListener extends PlotListener implements Listener {
@EventHandler
public void onItemPickup(final PlayerPickupItemEvent event) {
final Player player = event.getPlayer();
PlotPlayer pp = BukkitUtil.getPlayer(player);
final PlotPlayer pp = BukkitUtil.getPlayer(player);
final Plot plot = MainUtil.getPlot(pp.getLocation());
if (plot == null) {
return;
}
UUID uuid = pp.getUUID();
final UUID uuid = pp.getUUID();
if (plot.isAdded(uuid) && booleanFlag(plot, "drop-protection", false)) {
event.setCancelled(true);
}
@ -187,12 +187,12 @@ public class PlotPlusListener extends PlotListener implements Listener {
@EventHandler
public void onItemDrop(final PlayerDropItemEvent event) {
final Player player = event.getPlayer();
PlotPlayer pp = BukkitUtil.getPlayer(player);
final PlotPlayer pp = BukkitUtil.getPlayer(player);
final Plot plot = MainUtil.getPlot(pp.getLocation());
if (plot == null) {
return;
}
UUID uuid = pp.getUUID();
final UUID uuid = pp.getUUID();
if (plot.isAdded(uuid) && booleanFlag(plot, "item-drop", false)) {
event.setCancelled(true);
}
@ -211,7 +211,7 @@ public class PlotPlusListener extends PlotListener implements Listener {
return;
}
final Player trespasser = event.getPlayer();
PlotPlayer pt = BukkitUtil.getPlayer(trespasser);
final PlotPlayer pt = BukkitUtil.getPlayer(trespasser);
if (pp.getUUID().equals(pt.getUUID())) {
return;
}
@ -227,8 +227,8 @@ public class PlotPlusListener extends PlotListener implements Listener {
@EventHandler
public void onPlayerQuit(final PlayerQuitEvent event) {
Player player = event.getPlayer();
String name = player.getName();
final Player player = event.getPlayer();
final String name = player.getName();
if (feedRunnable.containsKey(name)) {
feedRunnable.remove(name);
}
@ -239,14 +239,14 @@ public class PlotPlusListener extends PlotListener implements Listener {
@EventHandler
public void onPlotLeave(final PlayerLeavePlotEvent event) {
Player leaver = event.getPlayer();
final Player leaver = event.getPlayer();
leaver.playEffect(leaver.getLocation(), Effect.RECORD_PLAY, 0);
final Plot plot = event.getPlot();
if (FlagManager.getPlotFlag(plot, "farewell") != null) {
event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', C.PREFIX_FAREWELL.s().replaceAll("%id%", plot.id + "") + FlagManager.getPlotFlag(plot, "farewell").getValueString()));
}
PlotPlayer pl = BukkitUtil.getPlayer(leaver);
String name = pl.getName();
final PlotPlayer pl = BukkitUtil.getPlayer(leaver);
pl.getName();
if (feedRunnable.containsKey(leaver)) {
feedRunnable.remove(leaver);
}

View File

@ -106,8 +106,8 @@ public class WorldEditListener implements Listener {
if ((p.getItemInHand() == null) || (p.getItemInHand().getType() == Material.AIR)) {
return;
}
PlotPlayer pp = BukkitUtil.getPlayer(p);
com.intellectualcrafters.plot.object.Location loc = pp.getLocation();
final PlotPlayer pp = BukkitUtil.getPlayer(p);
final com.intellectualcrafters.plot.object.Location loc = pp.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot != null) {
if (plot.hasOwner() && (plot.helpers != null) && (plot.helpers.contains(DBFunc.everyone) || plot.helpers.contains(pp.getUUID()))) {
@ -119,7 +119,7 @@ public class WorldEditListener implements Listener {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerCommand(final PlayerCommandPreprocessEvent e) {
final Player p = e.getPlayer();
PlotPlayer pp = BukkitUtil.getPlayer(p);
final PlotPlayer pp = BukkitUtil.getPlayer(p);
if (!PlotSquared.isPlotWorld(p.getWorld().getName()) || Permissions.hasPermission(pp, "plots.worldedit.bypass")) {
return;
}
@ -170,7 +170,7 @@ public class WorldEditListener implements Listener {
public void onPlayerJoin(final PlayerJoinEvent e) {
final Player p = e.getPlayer();
final Location l = p.getLocation();
PlotPlayer pp = BukkitUtil.getPlayer(p);
final PlotPlayer pp = BukkitUtil.getPlayer(p);
if (Permissions.hasPermission(pp, "plots.worldedit.bypass")) {
if (isPlotWorld(l)) {
PWE.removeMask(pp);
@ -178,7 +178,7 @@ public class WorldEditListener implements Listener {
return;
}
if (isPlotWorld(l)) {
com.intellectualcrafters.plot.object.Location loc = BukkitUtil.getLocation(l);
final com.intellectualcrafters.plot.object.Location loc = BukkitUtil.getLocation(l);
PWE.setMask(pp, loc, false);
} else {
PWE.removeMask(pp);
@ -192,15 +192,18 @@ public class WorldEditListener implements Listener {
return;
}
final Location f = e.getFrom();
if ((f.getX() == t.getX()) && (f.getZ() == t.getZ())) {
return;
}
final Player p = e.getPlayer();
PlotPlayer pp = BukkitUtil.getPlayer(p);
final PlotPlayer pp = BukkitUtil.getPlayer(p);
if (Permissions.hasPermission(pp, "plots.worldedit.bypass")) {
if (!PWE.hasMask(pp)) {
return;
}
}
com.intellectualcrafters.plot.object.Location locf = BukkitUtil.getLocation(f);
com.intellectualcrafters.plot.object.Location loct = BukkitUtil.getLocation(t);
final com.intellectualcrafters.plot.object.Location locf = BukkitUtil.getLocation(f);
final com.intellectualcrafters.plot.object.Location loct = BukkitUtil.getLocation(t);
if ((locf.getX() != loct.getX()) || (locf.getZ() != loct.getZ())) {
final PlotId idF = MainUtil.getPlotId(locf);
final PlotId idT = MainUtil.getPlotId(loct);
@ -212,8 +215,8 @@ public class WorldEditListener implements Listener {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPortal(final PlayerPortalEvent e) {
Player p = e.getPlayer();
PlotPlayer pp = BukkitUtil.getPlayer(p);
final Player p = e.getPlayer();
final PlotPlayer pp = BukkitUtil.getPlayer(p);
if (Permissions.hasPermission(pp, "plots.worldedit.bypass")) {
return;
}
@ -224,7 +227,7 @@ public class WorldEditListener implements Listener {
return;
}
if (isPlotWorld(t)) {
com.intellectualcrafters.plot.object.Location loct = BukkitUtil.getLocation(t);
final com.intellectualcrafters.plot.object.Location loct = BukkitUtil.getLocation(t);
PWE.setMask(pp, loct, false);
return;
}
@ -236,14 +239,14 @@ public class WorldEditListener implements Listener {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onTeleport(final PlayerTeleportEvent e) {
final Player p = e.getPlayer();
PlotPlayer pp = BukkitUtil.getPlayer(p);
final PlotPlayer pp = BukkitUtil.getPlayer(p);
if (Permissions.hasPermission(pp, "plots.worldedit.bypass")) {
if (!PWE.hasMask(pp)) {
return;
}
}
final Location t = e.getTo();
com.intellectualcrafters.plot.object.Location loct = BukkitUtil.getLocation(t);
final com.intellectualcrafters.plot.object.Location loct = BukkitUtil.getLocation(t);
final Location f = e.getFrom();
if (!PlotSquared.isPlotWorld(loct.getWorld())) {
if (isPlotWorld(f)) {

View File

@ -0,0 +1,32 @@
package com.intellectualcrafters.plot.listeners;
import org.bukkit.World;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.world.WorldInitEvent;
import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.generator.ChunkGenerator;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.object.PlotGenerator;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
public class WorldEvents {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public static void onWorldInit(final WorldInitEvent event) {
final World world = event.getWorld();
final ChunkGenerator gen = world.getGenerator();
if (gen instanceof PlotGenerator) {
PlotSquared.loadWorld(world.getName(), (PlotGenerator) gen);
} else {
if (PlotSquared.isPlotWorld(world.getName())) {
PlotSquared.loadWorld(world.getName(), null);
}
}
}
@EventHandler
public void worldLoad(final WorldLoadEvent event) {
UUIDHandler.cacheAll(event.getWorld().getName());
}
}

View File

@ -12,27 +12,27 @@ public class BukkitOfflinePlayer implements OfflinePlotPlayer {
* Please do not use this method. Instead use BukkitUtil.getPlayer(Player), as it caches player objects.
* @param player
*/
public BukkitOfflinePlayer(OfflinePlayer player) {
public BukkitOfflinePlayer(final OfflinePlayer player) {
this.player = player;
}
@Override
public UUID getUUID() {
return player.getUniqueId();
return this.player.getUniqueId();
}
@Override
public long getLastPlayed() {
return player.getLastPlayed();
return this.player.getLastPlayed();
}
@Override
public boolean isOnline() {
return player.isOnline();
return this.player.isOnline();
}
@Override
public String getName() {
return player.getName();
return this.player.getName();
}
}

View File

@ -13,15 +13,15 @@ public class BukkitPlayer implements PlotPlayer {
public final Player player;
UUID uuid;
String name;
private HashSet<String> hasPerm;
private HashSet<String> noPerm;
public HashSet<String> hasPerm = new HashSet<>();
public HashSet<String> noPerm = new HashSet<>();
private int op = 0;
/**
* Please do not use this method. Instead use BukkitUtil.getPlayer(Player), as it caches player objects.
* @param player
*/
public BukkitPlayer(Player player) {
public BukkitPlayer(final Player player) {
this.player = player;
}
@ -39,29 +39,29 @@ public class BukkitPlayer implements PlotPlayer {
}
@Override
public boolean hasPermission(String perm) {
if (noPerm.contains(perm)) {
public boolean hasPermission(final String perm) {
if (this.noPerm.contains(perm)) {
return false;
}
if (hasPerm.contains(perm)) {
if (this.hasPerm.contains(perm)) {
return true;
}
boolean result = player.hasPermission(perm);
final boolean result = this.player.hasPermission(perm);
if (!result) {
noPerm.add(perm);
this.noPerm.add(perm);
return false;
}
hasPerm.add(perm);
this.hasPerm.add(perm);
return true;
}
@Override
public void sendMessage(String message) {
public void sendMessage(final String message) {
this.player.sendMessage(message);
}
@Override
public void teleport(Location loc) {
public void teleport(final Location loc) {
this.player.teleport(new org.bukkit.Location(BukkitUtil.getWorld(loc.getWorld()), loc.getX(), loc.getY(), loc.getZ()));
}
@ -74,7 +74,7 @@ public class BukkitPlayer implements PlotPlayer {
}
return true;
}
boolean result = this.player.isOp();
final boolean result = this.player.isOp();
if (!result) {
this.op = 1;
return false;
@ -86,7 +86,7 @@ public class BukkitPlayer implements PlotPlayer {
@Override
public String getName() {
if (this.name == null) {
this.name = player.getName();
this.name = this.player.getName();
}
return this.name;
}
@ -97,9 +97,14 @@ public class BukkitPlayer implements PlotPlayer {
}
@Override
public void setCompassTarget(Location loc) {
player.setCompassTarget(new org.bukkit.Location(BukkitUtil.getWorld(loc.getWorld()), loc.getX(), loc.getY(), loc.getZ()));
public void setCompassTarget(final Location loc) {
this.player.setCompassTarget(new org.bukkit.Location(BukkitUtil.getWorld(loc.getWorld()), loc.getX(), loc.getY(), loc.getZ()));
}
@Override
public Location getLocationFull() {
return BukkitUtil.getLocationFull(this.player);
}
}

View File

@ -0,0 +1,11 @@
package com.intellectualcrafters.plot.object;
public class FileBytes {
public String path;
public byte[] data;
public FileBytes(String path, byte[] data) {
this.path = path;
this.data = data;
}
}

View File

@ -51,7 +51,7 @@ public class InfoInventory implements InventoryHolder {
}
public InfoInventory build() {
UUID uuid = UUIDHandler.getUUID(BukkitUtil.getPlayer(player));
final UUID uuid = UUIDHandler.getUUID(BukkitUtil.getPlayer(this.player));
final ItemStack generalInfo = getItem(Material.EMERALD, "&cPlot Info", "&cID: &6" + this.plot.getId().toString(), "&cOwner: &6" + getName(this.plot.getOwner()), "&cAlias: &6" + this.plot.settings.getAlias(), "&cBiome: &6" + this.plot.settings.getBiome().toString().replaceAll("_", "").toLowerCase(), "&cCan Build: &6" + this.plot.isAdded(uuid), "&cIs Denied: &6" + this.plot.isDenied(uuid));
final ItemStack helpers = getItem(Material.EMERALD, "&cHelpers", "&cAmount: &6" + this.plot.helpers.size(), "&8Click to view a list of the plot helpers");
final ItemStack trusted = getItem(Material.EMERALD, "&cTrusted", "&cAmount: &6" + this.plot.trusted.size(), "&8Click to view a list of trusted players");

View File

@ -20,16 +20,28 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.object;
import java.util.List;
import org.bukkit.World;
import org.bukkit.generator.BlockPopulator;
import org.bukkit.generator.ChunkGenerator;
import com.intellectualcrafters.plot.PlotSquared;
public abstract class PlotGenerator extends ChunkGenerator {
public PlotGenerator(final String world) {
PlotSquared.loadWorld(world, this);
@Override
public List<BlockPopulator> getDefaultPopulators(World world) {
PlotSquared.loadWorld(world.getName(), this);
return getPopulators(world);
}
public abstract List<BlockPopulator> getPopulators(World world);
public abstract void init(PlotWorld plotworld);
public abstract PlotWorld getNewPlotWorld(final String world);
public abstract PlotManager getPlotManager();
}

View File

@ -21,6 +21,10 @@
package com.intellectualcrafters.plot.object;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import com.intellectualcrafters.plot.commands.Template;
public abstract class PlotManager {
/*
@ -81,4 +85,10 @@ public abstract class PlotManager {
public abstract boolean finishPlotMerge(final PlotWorld plotworld, final ArrayList<PlotId> plotIds);
public abstract boolean finishPlotUnlink(final PlotWorld plotworld, final ArrayList<PlotId> plotIds);
public void exportTemplate(PlotWorld plotworld) {
HashSet<FileBytes> files = new HashSet<>(Arrays.asList(new FileBytes("templates/" + "tmp-data.yml", Template.getBytes(plotworld))));
Template.zipAll(plotworld.worldname, files);
}
}

View File

@ -10,6 +10,8 @@ import java.util.UUID;
public interface PlotPlayer {
public Location getLocation();
public Location getLocationFull();
public UUID getUUID();
public boolean hasPermission(final String perm);

View File

@ -38,6 +38,7 @@ import com.intellectualcrafters.plot.flag.FlagManager;
*/
public abstract class PlotWorld {
public final static boolean AUTO_MERGE_DEFAULT = false;
public final static boolean ALLOW_SIGNS_DEFAULT = true;
public final static boolean MOB_SPAWNING_DEFAULT = false;
public final static String PLOT_BIOME_DEFAULT = "FOREST";
public final static boolean PLOT_CHAT_DEFAULT = false;
@ -61,12 +62,11 @@ public abstract class PlotWorld {
// make non static and static_default_valu + add config option
public static int[] BLOCKS;
static {
BLOCKS = new int[] {
1,2,3,4,5,7,14,15,16,17,19,21,22,23,24,25,35,41,42,43,45,47,48,49,52,56,57,58,61,62,73,74,80,82,84,86,87,88,91,97,98,99,100,103,110,112,120,121,123,124,125,129,133,153,155,159,162,165,166,168,170,172,173,174,179,181
};
BLOCKS = new int[] { 1, 2, 3, 4, 5, 7, 14, 15, 16, 17, 19, 21, 22, 23, 24, 25, 35, 41, 42, 43, 45, 47, 48, 49, 52, 56, 57, 58, 61, 62, 73, 74, 80, 82, 84, 86, 87, 88, 91, 97, 98, 99, 100, 103, 110, 112, 120, 121, 123, 124, 125, 129, 133, 153, 155, 159, 162, 165, 166, 168, 170, 172, 173, 174, 179, 181 };
}
public final String worldname;
public boolean AUTO_MERGE;
public boolean ALLOW_SIGNS;
public boolean MOB_SPAWNING;
public String PLOT_BIOME;
public boolean PLOT_CHAT;
@ -104,12 +104,13 @@ public abstract class PlotWorld {
}
this.MOB_SPAWNING = config.getBoolean("natural_mob_spawning");
this.AUTO_MERGE = config.getBoolean("plot.auto_merge");
this.ALLOW_SIGNS = config.getBoolean("plot.create_signs");
this.PLOT_BIOME = (String) Configuration.BIOME.parseString(config.getString("plot.biome"));
this.SCHEMATIC_ON_CLAIM = config.getBoolean("schematic.on_claim");
this.SCHEMATIC_FILE = config.getString("schematic.file");
this.SCHEMATIC_CLAIM_SPECIFY = config.getBoolean("schematic.specify_on_claim");
this.SCHEMATICS = config.getStringList("schematic.schematics");
this.USE_ECONOMY = config.getBoolean("economy.use") && PlotSquared.economy != null;
this.USE_ECONOMY = config.getBoolean("economy.use") && (PlotSquared.economy != null);
this.PLOT_PRICE = config.getDouble("economy.prices.claim");
this.MERGE_PRICE = config.getDouble("economy.prices.merge");
this.SELL_PRICE = config.getDouble("economy.prices.sell");
@ -145,6 +146,7 @@ public abstract class PlotWorld {
final HashMap<String, Object> options = new HashMap<>();
options.put("natural_mob_spawning", PlotWorld.MOB_SPAWNING_DEFAULT);
options.put("plot.auto_merge", PlotWorld.AUTO_MERGE_DEFAULT);
options.put("plot.create_signs", PlotWorld.ALLOW_SIGNS_DEFAULT);
options.put("plot.biome", PlotWorld.PLOT_BIOME_DEFAULT.toString());
options.put("schematic.on_claim", PlotWorld.SCHEMATIC_ON_CLAIM_DEFAULT);
options.put("schematic.file", PlotWorld.SCHEMATIC_FILE_DEFAULT);

View File

@ -0,0 +1,26 @@
package com.intellectualcrafters.plot.object;
public class PseudoRandom {
private static long state = 1;
public static long nextLong() {
final long a = state;
state = xorShift64(a);
return a;
}
public static long xorShift64(long a) {
a ^= (a << 21);
a ^= (a >>> 35);
a ^= (a << 4);
return a;
}
public static int random(final int n) {
if (n == 1) {
return 0;
}
final long r = ((nextLong() >>> 32) * n) >> 32;
return (int) r;
}
}

View File

@ -0,0 +1,19 @@
package com.intellectualcrafters.plot.object.schematic;
public class PlotItem {
public int x;
public int y;
public int z;
public short[] id;
public byte[] data;
public byte[] amount;
public PlotItem(short x, short y, short z, short[] id, byte[] data, byte[] amount) {
this.x = x;
this.y = y;
this.z = z;
this.id = id;
this.data = data;
this.amount = amount;
}
}

View File

@ -0,0 +1,115 @@
package com.intellectualcrafters.plot.object.schematic;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Material;
import org.bukkit.block.BlockState;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import com.intellectualcrafters.jnbt.ByteTag;
import com.intellectualcrafters.jnbt.CompoundTag;
import com.intellectualcrafters.jnbt.ListTag;
import com.intellectualcrafters.jnbt.ShortTag;
import com.intellectualcrafters.jnbt.Tag;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.SchematicHandler.Schematic;
public class StateWrapper {
public BlockState state = null;
public CompoundTag tag = null;
public StateWrapper(BlockState state) {
this.state = state;
}
public StateWrapper(CompoundTag tag) {
this.tag = tag;
}
public boolean restoreTag(short x, short y, short z, Schematic schematic) {
if (this.tag == null) {
return false;
}
List<Tag> itemsTag = this.tag.getListTag("Items").getValue();
int length = itemsTag.size();
short[] ids = new short[length];
byte[] datas = new byte[length];
byte[] amounts = new byte[length];
for (int i = 0; i < length; i++) {
Tag itemTag = itemsTag.get(i);
CompoundTag itemComp = (CompoundTag) itemTag;
short id = itemComp.getShort("id");
String idStr = itemComp.getString("id");
if (!StringUtils.isNumeric(idStr) && idStr != null) {
idStr = idStr.split(":")[1];
id = (short) Material.valueOf(idStr.toUpperCase()).getId();
}
ids[i] = id;
datas[i] = (byte) itemComp.getShort("Damage");
amounts[i] = itemComp.getByte("Count");
}
if (length != 0) {
schematic.addItem(new PlotItem(x, y, z, ids, datas, amounts));
}
return true;
}
public CompoundTag getTag() {
if (this.tag != null) {
return this.tag;
}
if (state instanceof InventoryHolder) {
InventoryHolder inv = (InventoryHolder) state;
ItemStack[] contents = inv.getInventory().getContents();
Map<String, Tag> values = new HashMap<String, Tag>();
values.put("Items", new ListTag("Items", CompoundTag.class, serializeInventory(contents)));
return new CompoundTag(values);
}
return null;
}
public String getId() {
return "Chest";
}
public List<CompoundTag> serializeInventory(ItemStack[] items) {
List<CompoundTag> tags = new ArrayList<CompoundTag>();
for (int i = 0; i < items.length; ++i) {
if (items[i] != null) {
Map<String, Tag> tagData = serializeItem(items[i]);
tagData.put("Slot", new ByteTag("Slot", (byte) i));
tags.add(new CompoundTag(tagData));
}
}
return tags;
}
public Map<String, Tag> serializeItem(ItemStack item) {
Map<String, Tag> data = new HashMap<String, Tag>();
data.put("id", new ShortTag("id", (short) item.getTypeId()));
data.put("Damage", new ShortTag("Damage", item.getDurability()));
data.put("Count", new ByteTag("Count", (byte) item.getAmount()));
if (!item.getEnchantments().isEmpty()) {
List<CompoundTag> enchantmentList = new ArrayList<CompoundTag>();
for(Entry<Enchantment, Integer> entry : item.getEnchantments().entrySet()) {
Map<String, Tag> enchantment = new HashMap<String, Tag>();
enchantment.put("id", new ShortTag("id", (short) entry.getKey().getId()));
enchantment.put("lvl", new ShortTag("lvl", entry.getValue().shortValue()));
enchantmentList.add(new CompoundTag(enchantment));
}
Map<String, Tag> auxData = new HashMap<String, Tag>();
auxData.put("ench", new ListTag("ench", CompoundTag.class, enchantmentList));
data.put("tag", new CompoundTag("tag", auxData));
}
return data;
}
}

View File

@ -1,13 +0,0 @@
package com.intellectualcrafters.plot.util;
import java.util.List;
import com.intellectualcrafters.plot.object.ChunkLoc;
public abstract class AbstractSetBlock {
public static AbstractSetBlock setBlockManager = null;
public abstract boolean set(final org.bukkit.World world, final int x, final int y, final int z, final int blockId, final byte data);
public abstract void update(String world, List<ChunkLoc> chunks);
}

View File

@ -1,36 +1,19 @@
package com.intellectualcrafters.plot.util;
import org.bukkit.inventory.ItemStack;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
import com.intellectualcrafters.plot.object.PseudoRandom;
import com.intellectualcrafters.plot.object.schematic.PlotItem;
public abstract class BlockManager {
public static BlockManager manager;
private static long state = 1;
public static long nextLong() {
final long a = state;
state = xorShift64(a);
return a;
}
public static long xorShift64(long a) {
a ^= (a << 21);
a ^= (a >>> 35);
a ^= (a << 4);
return a;
}
public static int random(final int n) {
if (n == 1) {
return 0;
}
final long r = ((nextLong() >>> 32) * n) >> 32;
return (int) r;
}
public abstract String[] getBiomeList();
public abstract boolean addItems(String world, PlotItem items);
public abstract int getBiomeFromString(String biome);
public abstract int getBlockIdFromString(String block);
@ -62,7 +45,7 @@ public abstract class BlockManager {
final byte[] data = new byte[blocks.length];
for (int i = 0; i < blocks.length; i++) {
final PlotBlock[] current = blocks[i];
final int n = random(current.length);
final int n = PseudoRandom.random(current.length);
id[i] = current[n].id;
data[i] = current[n].data;
}

View File

@ -0,0 +1,11 @@
package com.intellectualcrafters.plot.util;
import java.util.List;
import com.intellectualcrafters.plot.object.ChunkLoc;
public abstract class BlockUpdateUtil {
public static BlockUpdateUtil setBlockManager = null;
public abstract void update(String worldname, List<ChunkLoc> chunkLocs);
}

View File

@ -0,0 +1,149 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// 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.util;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import com.intellectualcrafters.jnbt.ByteArrayTag;
import com.intellectualcrafters.jnbt.CompoundTag;
import com.intellectualcrafters.jnbt.IntTag;
import com.intellectualcrafters.jnbt.ListTag;
import com.intellectualcrafters.jnbt.ShortTag;
import com.intellectualcrafters.jnbt.StringTag;
import com.intellectualcrafters.jnbt.Tag;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.schematic.StateWrapper;
/**
* Schematic Handler
*
* @author Citymonstret
* @author Empire92
*/
public class BukkitSchematicHandler extends SchematicHandler {
@Override
public CompoundTag getCompoundTag(final String world, final Location pos1, final Location pos2) {
// loading chunks
int i = 0;
int j = 0;
try {
for (i = (pos1.getX() / 16) * 16; i < (16 + ((pos2.getX() / 16) * 16)); i += 16) {
for (j = (pos1.getZ() / 16) * 16; j < (16 + ((pos2.getZ() / 16) * 16)); j += 16) {
boolean result = ChunkManager.manager.loadChunk(world, new ChunkLoc(i, j));
if (!result) {
return null;
}
}
}
} catch (final Exception e) {
PlotSquared.log("&7 - Cannot save: corrupt chunk at " + (i / 16) + ", " + (j / 16));
return null;
}
final int width = (pos2.getX() - pos1.getX()) + 1;
final int height = (pos2.getY() - pos1.getY()) + 1;
final int length = (pos2.getZ() - pos1.getZ()) + 1;
final HashMap<String, Tag> schematic = new HashMap<>();
schematic.put("Width", new ShortTag("Width", (short) width));
schematic.put("Length", new ShortTag("Length", (short) length));
schematic.put("Height", new ShortTag("Height", (short) height));
schematic.put("Materials", new StringTag("Materials", "Alpha"));
schematic.put("WEOriginX", new IntTag("WEOriginX", 0));
schematic.put("WEOriginY", new IntTag("WEOriginY", 0));
schematic.put("WEOriginZ", new IntTag("WEOriginZ", 0));
schematic.put("WEOffsetX", new IntTag("WEOffsetX", 0));
schematic.put("WEOffsetY", new IntTag("WEOffsetY", 0));
schematic.put("WEOffsetZ", new IntTag("WEOffsetZ", 0));
final byte[] blocks = new byte[width * height * length];
byte[] addBlocks = null;
final byte[] blockData = new byte[width * height * length];
final int sx = pos1.getX();
pos2.getX();
final int sz = pos1.getZ();
pos2.getZ();
final int sy = pos1.getY();
pos2.getY();
List<Tag> tileEntities = new ArrayList<Tag>();
World worldObj = Bukkit.getWorld(world);
for (int x = 0; x < width; x++) {
for (int z = 0; z < length; z++) {
for (int y = 0; y < height; y++) {
final int index = (y * width * length) + (z * width) + x;
Block block = worldObj.getBlockAt(sx + x, sy + y, sz + z);
BlockState state = block.getState();
if (state != null) {
StateWrapper wrapper = new StateWrapper(state);
CompoundTag rawTag = wrapper.getTag();
if (rawTag != null) {
Map<String, Tag> values = new HashMap<String, Tag>();
for (Entry<String, Tag> entry : rawTag.getValue().entrySet()) {
values.put(entry.getKey(), entry.getValue());
}
values.put("id", new StringTag("id", wrapper.getId()));
values.put("x", new IntTag("x", x));
values.put("y", new IntTag("y", y));
values.put("z", new IntTag("z", z));
CompoundTag tileEntityTag = new CompoundTag(values);
tileEntities.add(tileEntityTag);
}
}
int id = block.getTypeId();
byte data = block.getData();
if (id > 255) {
if (addBlocks == null) {
addBlocks = new byte[(blocks.length >> 1) + 1];
}
addBlocks[index >> 1] = (byte) (((index & 1) == 0) ? (addBlocks[index >> 1] & 0xF0) | ((id >> 8) & 0xF) : (addBlocks[index >> 1] & 0xF) | (((id >> 8) & 0xF) << 4));
}
blocks[index] = (byte) id;
blockData[index] = data;
}
}
}
schematic.put("Blocks", new ByteArrayTag("Blocks", blocks));
schematic.put("Data", new ByteArrayTag("Data", blockData));
schematic.put("Entities", new ListTag("Entities", CompoundTag.class, new ArrayList<Tag>()));
schematic.put("TileEntities", new ListTag("TileEntities", CompoundTag.class, tileEntities));
if (addBlocks != null) {
schematic.put("AddBlocks", new ByteArrayTag("AddBlocks", addBlocks));
}
return new CompoundTag("Schematic", schematic);
}
}

View File

@ -9,8 +9,8 @@ import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.RegionWrapper;
public abstract class AChunkManager {
public static AChunkManager manager = null;
public abstract class ChunkManager {
public static ChunkManager manager = null;
public static RegionWrapper CURRENT_PLOT_CLEAR = null;
public static HashMap<ChunkLoc, HashMap<Short, Short>> GENERATE_BLOCKS = new HashMap<>();
public static HashMap<ChunkLoc, HashMap<Short, Byte>> GENERATE_DATA = new HashMap<>();

View File

@ -23,8 +23,8 @@ 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.bukkit.BukkitSetBlockManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
import com.intellectualcrafters.plot.util.bukkit.SetBlockManager;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
public class ClusterManager {
@ -277,7 +277,7 @@ public class ClusterManager {
@Override
public void run() {
if ((populator == null) || (plotworld.TYPE == 0)) {
SetBlockManager.setBlockManager.update(Arrays.asList(new Chunk[] { chunk }));
BukkitSetBlockManager.setBlockManager.update(Arrays.asList(new Chunk[] { chunk }));
world.regenerateChunk(chunk.getX(), chunk.getZ());
chunk.unload(true, true);
} else {

View File

@ -6,19 +6,19 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
public class EconHandler {
// TODO economy shit
public static double getBalance(PlotPlayer player) {
public static double getBalance(final PlotPlayer player) {
return PlotSquared.economy.getBalance(player.getName());
}
public static void withdrawPlayer(PlotPlayer player, double amount) {
public static void withdrawPlayer(final PlotPlayer player, final double amount) {
PlotSquared.economy.withdrawPlayer(player.getName(), amount);
}
public static void depositPlayer(PlotPlayer player, double amount) {
public static void depositPlayer(final PlotPlayer player, final double amount) {
PlotSquared.economy.depositPlayer(player.getName(), amount);
}
public static void depositPlayer(OfflinePlotPlayer player, double amount) {
public static void depositPlayer(final OfflinePlotPlayer player, final double amount) {
PlotSquared.economy.depositPlayer(player.getName(), amount);
}
}

View File

@ -0,0 +1,41 @@
package com.intellectualcrafters.plot.util;
import java.util.ArrayList;
import java.util.UUID;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
public abstract class EventUtil {
public static EventUtil manager = null;
public abstract boolean callClaim(final PlotPlayer player, final Plot plot, final boolean auto);
public abstract boolean callTeleport(final PlotPlayer player, Location from, final Plot plot);
public abstract boolean callClear(final String world, final PlotId id);
public abstract void callDelete(final String world, final PlotId id);
public abstract boolean callFlagAdd(final Flag flag, final Plot plot);
public abstract boolean callFlagRemove(final Flag flag, final Plot plot);
public abstract boolean callMerge(final String world, final Plot plot, final ArrayList<PlotId> plots);
public abstract boolean callUnlink(final String world, final ArrayList<PlotId> plots);
public abstract void callEntry(final PlotPlayer player, final Plot plot);
public abstract void callLeave(final PlotPlayer player, final Plot plot);
public abstract void callDenied(final PlotPlayer initiator, final Plot plot, final UUID player, final boolean added);
public abstract void callHelper(final PlotPlayer initiator, final Plot plot, final UUID player, final boolean added);
public abstract void callTrusted(final PlotPlayer initiator, final Plot plot, final UUID player, final boolean added);
}

View File

@ -97,10 +97,6 @@ public class ExpireManager {
}
final PlotDeleteEvent event = new PlotDeleteEvent(world, plot.id);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
event.setCancelled(true);
return;
}
for (final UUID helper : plot.helpers) {
final PlotPlayer player = UUIDHandler.getPlayer(helper);
if (player != null) {
@ -108,6 +104,11 @@ public class ExpireManager {
}
}
final PlotManager manager = PlotSquared.getPlotManager(world);
if (manager == null) {
PlotSquared.log("&cThis is a friendly reminder to create or delete " + world +" as it is currently setup incorrectly");
expiredPlots.get(world).remove(plot);
return;
}
if (plot.settings.isMerged()) {
Unlink.unlinkPlot(plot);
}
@ -171,7 +172,7 @@ public class ExpireManager {
continue;
}
final BukkitOfflinePlayer op = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid);
if ((op == null) || op.getLastPlayed() == 0) {
if ((op == null) || (op.getLastPlayed() == 0)) {
continue;
}
long last = op.getLastPlayed();

View File

@ -38,6 +38,7 @@ import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotSettings;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.PseudoRandom;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
import com.intellectualcrafters.plot.util.bukkit.SendChunk;
@ -99,7 +100,8 @@ public class MainUtil {
// TODO
// boolean result = PlotSquared.IMP.callPlayerTeleportToPlotEvent(player, from, plot);
final boolean result = true;
final boolean result = false;
// TOOD ^ remove that
if (!result) {
@ -163,7 +165,7 @@ public class MainUtil {
chunks.add(chunk);
}
}
AbstractSetBlock.setBlockManager.update(world, chunks);
BlockUpdateUtil.setBlockManager.update(world, chunks);
}
public static void createWorld(final String world, final String generator) {
@ -230,7 +232,10 @@ public class MainUtil {
final PlotManager manager = PlotSquared.getPlotManager(world);
final PlotWorld plotworld = PlotSquared.getPlotWorld(world);
// FIXME call event
boolean result = EventUtil.manager.callMerge(world, getPlot(world, pos1), plotIds);
if (!result) {
return false;
}
manager.startPlotMerge(plotworld, plotIds);
for (int x = pos1.x; x <= pos2.x; x++) {
@ -323,11 +328,13 @@ public class MainUtil {
}
final PlotManager manager = PlotSquared.getPlotManager(p.world);
final PlotWorld plotworld = PlotSquared.getPlotWorld(p.world);
if (plotworld.ALLOW_SIGNS) {
final Location loc = manager.getSignLoc(plotworld, p);
final String id = p.id.x + ";" + p.id.y;
final String[] lines = new String[] { C.OWNER_SIGN_LINE_1.translated().replaceAll("%id%", id), C.OWNER_SIGN_LINE_2.translated().replaceAll("%id%", id).replaceAll("%plr%", name), C.OWNER_SIGN_LINE_3.translated().replaceAll("%id%", id).replaceAll("%plr%", name), C.OWNER_SIGN_LINE_4.translated().replaceAll("%id%", id).replaceAll("%plr%", name) };
BlockManager.setSign(p.world, loc.getX(), loc.getY(), loc.getZ(), lines);
}
}
public static String getStringSized(final int max, final String string) {
if (string.length() > max) {
@ -483,7 +490,7 @@ public class MainUtil {
if (runners.containsKey(plot)) {
return false;
}
AChunkManager.manager.clearAllEntities(plot);
ChunkManager.manager.clearAllEntities(plot);
clear(plot.world, plot, isDelete, whenDone);
removeSign(plot);
return true;
@ -503,7 +510,7 @@ public class MainUtil {
runners.put(plot, 1);
if (plotworld.TERRAIN != 0) {
final Location pos2 = MainUtil.getPlotTopLoc(world, plot.id);
AChunkManager.manager.regenerateRegion(pos1, pos2, new Runnable() {
ChunkManager.manager.regenerateRegion(pos1, pos2, new Runnable() {
@Override
public void run() {
runners.remove(plot);
@ -539,7 +546,7 @@ public class MainUtil {
for (int y = pos1.getY(); y < pos2.getY(); y++) {
for (int x = pos1.getX(); x < pos2.getX(); x++) {
for (int z = pos1.getZ(); z < pos2.getZ(); z++) {
final int i = BlockManager.random(blocks.length);
final int i = PseudoRandom.random(blocks.length);
xl[index] = x;
yl[index] = y;
zl[index] = z;
@ -811,11 +818,11 @@ public class MainUtil {
plot.id.y += offset_y;
PlotSquared.getPlots(world).put(plot.id, plot);
}
AChunkManager.manager.copyRegion(bot1, top, bot2, new Runnable() {
ChunkManager.manager.copyRegion(bot1, top, bot2, new Runnable() {
@Override
public void run() {
final Location bot = bot1.clone().add(1, 0, 1);
AChunkManager.manager.regenerateRegion(bot, top, null);
ChunkManager.manager.regenerateRegion(bot, top, null);
TaskManager.runTaskLater(whenDone, 1);
}
});
@ -845,12 +852,14 @@ public class MainUtil {
return new String(b);
}
public static boolean sendMessage(final PlotPlayer plr, final String msg, final boolean prefix) {
public static boolean sendMessage(final PlotPlayer plr, String msg, final boolean prefix) {
msg = colorise('&', msg);
final String prefixStr = colorise('&', C.PREFIX.s());
if ((msg.length() > 0) && !msg.equals("")) {
if (plr == null) {
PlotSquared.log(C.PREFIX.s() + msg);
PlotSquared.log(prefixStr + msg);
} else {
sendMessageWrapped(plr, colorise('&', C.PREFIX.s() + msg));
sendMessageWrapped(plr, prefixStr + msg);
}
}
return true;
@ -929,18 +938,18 @@ public class MainUtil {
* @param plr
* @param msg Was used to wrap the chat client length (Packets out--)
*/
public static void sendMessageWrapped(final PlotPlayer plr, String msg) {
if (msg.length() > 65) {
final String[] ss = wordWrap(msg, 65);
final StringBuilder b = new StringBuilder();
for (final String p : ss) {
b.append(p).append(p.equals(ss[ss.length - 1]) ? "" : "\n ");
}
msg = b.toString();
}
if (msg.endsWith("\n")) {
msg = msg.substring(0, msg.length() - 2);
}
public static void sendMessageWrapped(final PlotPlayer plr, final String msg) {
// if (msg.length() > 65) {
// final String[] ss = wordWrap(msg, 65);
// final StringBuilder b = new StringBuilder();
// for (final String p : ss) {
// b.append(p).append(p.equals(ss[ss.length - 1]) ? "" : "\n ");
// }
// msg = b.toString();
// }
// if (msg.endsWith("\n")) {
// msg = msg.substring(0, msg.length() - 2);
// }
plr.sendMessage(msg);
}
@ -963,7 +972,7 @@ public class MainUtil {
}
}
if (plr == null) {
PlotSquared.log(msg);
PlotSquared.log(colorise('&', msg));
} else {
sendMessage(plr, msg, c.usePrefix());
}
@ -1064,7 +1073,7 @@ public class MainUtil {
* @param p
* @return
*/
public static int getAllowedPlots(final PlotPlayer p, int current) {
public static int getAllowedPlots(final PlotPlayer p, final int current) {
return Permissions.hasPermissionRange(p, "plots.plot", Settings.MAX_PLOTS, current);
}

View File

@ -1,23 +1,3 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// 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.util;
import java.io.File;
@ -26,13 +6,13 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import org.bukkit.Chunk;
import org.bukkit.block.BlockState;
import com.intellectualcrafters.jnbt.ByteArrayTag;
import com.intellectualcrafters.jnbt.CompoundTag;
@ -41,22 +21,19 @@ import com.intellectualcrafters.jnbt.ListTag;
import com.intellectualcrafters.jnbt.NBTInputStream;
import com.intellectualcrafters.jnbt.NBTOutputStream;
import com.intellectualcrafters.jnbt.ShortTag;
import com.intellectualcrafters.jnbt.StringTag;
import com.intellectualcrafters.jnbt.Tag;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.commands.Set;
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.schematic.PlotItem;
import com.intellectualcrafters.plot.object.schematic.StateWrapper;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
/**
* Schematic Handler
*
* @author Citymonstret
* @author Empire92
*/
public class SchematicHandler {
public abstract class SchematicHandler {
public static SchematicHandler manager = new BukkitSchematicHandler();
/**
* Paste a schematic
*
@ -66,7 +43,7 @@ public class SchematicHandler {
*
* @return true if succeeded
*/
public static boolean paste(final Location location, final Schematic schematic, final Plot plot, final int x_offset, final int z_offset) {
public boolean paste(final Schematic schematic, final Plot plot, final int x_offset, final int z_offset) {
if (schematic == null) {
PlotSquared.log("Schematic == null :|");
return false;
@ -78,12 +55,16 @@ public class SchematicHandler {
final int HEIGHT = demensions.getY();
final DataCollection[] blocks = schematic.getBlockCollection();
Location l1 = MainUtil.getPlotBottomLoc(plot.world, plot.getId());
final int sy = BukkitUtil.getHeighestBlock(location.getWorld(), l1.getX() + 1, l1.getZ() + 1);
final int sy = BukkitUtil.getHeighestBlock(plot.world, l1.getX() + 1, l1.getZ() + 1);
if (!(HEIGHT == BukkitUtil.getMaxHeight(plot.world))) {
l1 = l1.add(1, sy - 1, 1);
if (HEIGHT == BukkitUtil.getMaxHeight(location.getWorld())) {
} else {
l1.getY();
}
else {
l1 = l1.add(1, 0, 1);
}
int X = l1.getX();
int Y = l1.getY();
int Z = l1.getZ();
final int[] xl = new int[blocks.length];
final int[] yl = new int[blocks.length];
final int[] zl = new int[blocks.length];
@ -94,22 +75,53 @@ public class SchematicHandler {
for (int y = 0; y < HEIGHT; y++) {
final int index = (y * WIDTH * LENGTH) + (z * WIDTH) + x;
final DataCollection block = blocks[index];
xl[index] = x;
yl[index] = y;
zl[index] = z;
xl[index] = x + X;
yl[index] = y + Y;
zl[index] = z + Z;
ids[index] = block.block;
data[index] = block.data;
}
}
}
BlockManager.setBlocks(plot.world, xl, yl, zl, ids, data);
pasteStates(schematic, plot, x_offset, z_offset);
} catch (final Exception e) {
return false;
}
return true;
}
public static Schematic getSchematic(final CompoundTag tag, final File file) {
public boolean pasteStates(final Schematic schematic, final Plot plot, final int x_offset, final int z_offset) {
if (schematic == null) {
PlotSquared.log("Schematic == null :|");
return false;
}
HashSet<PlotItem> items = schematic.getItems();
if (items == null) {
return false;
}
Location l1 = MainUtil.getPlotBottomLoc(plot.world, plot.getId());
final int sy = BukkitUtil.getHeighestBlock(plot.world, l1.getX() + 1, l1.getZ() + 1);
final Dimension demensions = schematic.getSchematicDimension();
final int HEIGHT = demensions.getY();
if (!(HEIGHT == BukkitUtil.getMaxHeight(plot.world))) {
l1 = l1.add(1, sy - 1, 1);
} else {
l1 = l1.add(1, 0, 1);
}
int X = l1.getX() + x_offset;
int Y = l1.getY();
int Z = l1.getZ() + z_offset;
for (PlotItem item : items) {
item.x += X;
item.y += Y;
item.z += Z;
BlockManager.manager.addItems(plot.world, item);
}
return true;
}
public Schematic getSchematic(final CompoundTag tag, final File file) {
final Map<String, Tag> tagMap = tag.getValue();
byte[] addId = new byte[0];
if (tagMap.containsKey("AddBlocks")) {
@ -138,7 +150,22 @@ public class SchematicHandler {
for (int x = 0; x < b.length; x++) {
collection[x] = new DataCollection(blocks[x], d[x]);
}
return new Schematic(collection, dimension, file);
Schematic schem = new Schematic(collection, dimension, file);
try {
List<Tag> blockStates = ListTag.class.cast(tagMap.get("TileEntities")).getValue();
for (Tag stateTag : blockStates) {
CompoundTag ct = ((CompoundTag) stateTag);
Map<String, Tag> state = ct.getValue();
short x = IntTag.class.cast(state.get("x")).getValue().shortValue();
short y = IntTag.class.cast(state.get("y")).getValue().shortValue();
short z = IntTag.class.cast(state.get("z")).getValue().shortValue();
new StateWrapper(ct).restoreTag(x, y, z, schem);
}
}
catch (Exception e) {
e.printStackTrace();
}
return schem;
}
/**
@ -148,7 +175,7 @@ public class SchematicHandler {
*
* @return schematic if found, else null
*/
public static Schematic getSchematic(final String name) {
public Schematic getSchematic(final String name) {
{
final File parent = new File(PlotSquared.IMP.getDirectory() + File.separator + "schematics");
if (!parent.exists()) {
@ -182,7 +209,7 @@ public class SchematicHandler {
*
* @return true if succeeded
*/
public static boolean save(final CompoundTag tag, final String path) {
public boolean save(final CompoundTag tag, final String path) {
if (tag == null) {
PlotSquared.log("&cCannot save empty tag");
return false;
@ -210,7 +237,7 @@ public class SchematicHandler {
*
* @return tag
*/
public static CompoundTag getCompoundTag(final String world, final PlotId id) {
public CompoundTag getCompoundTag(final String world, final PlotId id) {
if (!PlotSquared.getPlots(world).containsKey(id)) {
return null;
}
@ -219,86 +246,21 @@ public class SchematicHandler {
return getCompoundTag(world, pos1, pos2);
}
@SuppressWarnings("deprecation")
public static CompoundTag getCompoundTag(final String world, final Location pos1, final Location pos2) {
// loading chunks
int i = 0;
int j = 0;
try {
for (i = (pos1.getX() / 16) * 16; i < (16 + ((pos2.getX() / 16) * 16)); i += 16) {
for (j = (pos1.getZ() / 16) * 16; j < (16 + ((pos2.getZ() / 16) * 16)); j += 16) {
final Chunk chunk = BukkitUtil.getChunkAt(world, i, j);
final boolean result = chunk.load(false);
if (!result) {
// Plot is not even generated
return null;
}
}
}
} catch (final Exception e) {
PlotSquared.log("&7 - Cannot save: corrupt chunk at " + (i / 16) + ", " + (j / 16));
return null;
}
final int width = (pos2.getX() - pos1.getX()) + 1;
final int height = (pos2.getY() - pos1.getY()) + 1;
final int length = (pos2.getZ() - pos1.getZ()) + 1;
final HashMap<String, Tag> schematic = new HashMap<>();
schematic.put("Width", new ShortTag("Width", (short) width));
schematic.put("Length", new ShortTag("Length", (short) length));
schematic.put("Height", new ShortTag("Height", (short) height));
schematic.put("Materials", new StringTag("Materials", "Alpha"));
schematic.put("WEOriginX", new IntTag("WEOriginX", 0));
schematic.put("WEOriginY", new IntTag("WEOriginY", 0));
schematic.put("WEOriginZ", new IntTag("WEOriginZ", 0));
schematic.put("WEOffsetX", new IntTag("WEOffsetX", 0));
schematic.put("WEOffsetY", new IntTag("WEOffsetY", 0));
schematic.put("WEOffsetZ", new IntTag("WEOffsetZ", 0));
final byte[] blocks = new byte[width * height * length];
byte[] addBlocks = null;
final byte[] blockData = new byte[width * height * length];
final int sx = pos1.getX();
pos2.getX();
final int sz = pos1.getZ();
pos2.getZ();
final int sy = pos1.getY();
pos2.getY();
for (int x = 0; x < width; x++) {
for (int z = 0; z < length; z++) {
for (int y = 0; y < height; y++) {
final int index = (y * width * length) + (z * width) + x;
final PlotBlock block = BukkitUtil.getBlock(new Location(world, sx + x, sy + y, sz + z));
if (block.id > 255) {
if (addBlocks == null) {
addBlocks = new byte[(blocks.length >> 1) + 1];
}
addBlocks[index >> 1] = (byte) (((index & 1) == 0) ? (addBlocks[index >> 1] & 0xF0) | ((block.id >> 8) & 0xF) : (addBlocks[index >> 1] & 0xF) | (((block.id >> 8) & 0xF) << 4));
}
blocks[index] = (byte) block.id;
blockData[index] = block.data;
// We need worldedit to save tileentity data or entities
// - it uses NMS and CB internal code, which changes every
// update
}
}
}
schematic.put("Blocks", new ByteArrayTag("Blocks", blocks));
schematic.put("Data", new ByteArrayTag("Data", blockData));
schematic.put("Entities", new ListTag("Entities", CompoundTag.class, new ArrayList<Tag>()));
schematic.put("TileEntities", new ListTag("TileEntities", CompoundTag.class, new ArrayList<Tag>()));
if (addBlocks != null) {
schematic.put("AddBlocks", new ByteArrayTag("AddBlocks", addBlocks));
}
return new CompoundTag("Schematic", schematic);
}
public abstract CompoundTag getCompoundTag(final String world, final Location pos1, final Location pos2);
public static boolean pastePart(final String world, final DataCollection[] blocks, final Location l1, final int x_offset, final int z_offset, final int i1, final int i2, final int WIDTH, final int LENGTH) {
public boolean pastePart(final String world, final DataCollection[] blocks, final Location l1, final int x_offset, final int z_offset, final int i1, final int i2, final int WIDTH, final int LENGTH) {
int length = 0;
for (int i = i1; i <= i2; i++) {
if (blocks[i].block == 0) {
length++;
}
}
length = i2 - length;
length = i2 - i1 - length + 1;
int X = l1.getX();
int Y = l1.getY();
int Z = l1.getZ();
final int[] xl = new int[length];
final int[] yl = new int[length];
final int[] zl = new int[length];
@ -308,19 +270,19 @@ public class SchematicHandler {
for (int i = i1; i <= i2; i++) {
final short id = blocks[i].block;
if (id == 0) {
continue;
continue; //
}
count++;
final int area = WIDTH * LENGTH;
final int r = i % (area);
final int x = r % WIDTH;
final int y = i / area;
final int z = r / WIDTH;
xl[count] = x;
yl[count] = y;
zl[count] = z;
xl[count] = x + X;
yl[count] = y + Y;
zl[count] = z + Z;
ids[count] = id;
data[count] = blocks[i].data;
count++;
if (y > 256) {
break;
}
@ -334,10 +296,22 @@ public class SchematicHandler {
*
* @author Citymonstret
*/
public static class Schematic {
public class Schematic {
private final DataCollection[] blockCollection;
private final Dimension schematicDimension;
private final File file;
private HashSet<PlotItem> items;
public void addItem(PlotItem item) {
if (this.items == null) {
this.items = new HashSet<>();
}
items.add(item);
}
public HashSet<PlotItem> getItems() {
return this.items;
}
public Schematic(final DataCollection[] blockCollection, final Dimension schematicDimension, final File file) {
this.blockCollection = blockCollection;
@ -363,7 +337,7 @@ public class SchematicHandler {
*
* @author Citymonstret
*/
public static class Dimension {
public class Dimension {
private final int x;
private final int y;
private final int z;
@ -392,7 +366,7 @@ public class SchematicHandler {
*
* @author Citymonstret
*/
public static class DataCollection {
public class DataCollection {
private final short block;
private final byte data;

View File

@ -5,7 +5,6 @@ import java.util.Map;
import com.intellectualcrafters.plot.object.PlotGenerator;
import com.intellectualcrafters.plot.object.SetupObject;
import com.intellectualcrafters.plot.util.bukkit.BukkitSetupUtils;
public abstract class SetupUtils {

View File

@ -9,13 +9,13 @@ public abstract class TaskManager {
public abstract int taskRepeat(final Runnable r, int interval);
public abstract int taskAsync(final Runnable r);
public abstract void taskAsync(final Runnable r);
public abstract int task(final Runnable r);
public abstract void task(final Runnable r);
public abstract int taskLater(final Runnable r, int delay);
public abstract void taskLater(final Runnable r, int delay);
public abstract int taskLaterAsync(final Runnable r, int delay);
public abstract void taskLaterAsync(final Runnable r, int delay);
public abstract void cancelTask(int task);
@ -26,31 +26,27 @@ public abstract class TaskManager {
return -1;
}
public static int runTaskAsync(final Runnable r) {
public static void runTaskAsync(final Runnable r) {
if (r != null) {
return PlotSquared.TASK.taskAsync(r);
PlotSquared.TASK.taskAsync(r);
}
return -1;
}
public static int runTask(final Runnable r) {
public static void runTask(final Runnable r) {
if (r != null) {
return PlotSquared.TASK.task(r);
PlotSquared.TASK.task(r);
}
return -1;
}
public static int runTaskLater(final Runnable r, final int delay) {
public static void runTaskLater(final Runnable r, final int delay) {
if (r != null) {
return PlotSquared.TASK.taskLater(r, delay);
PlotSquared.TASK.taskLater(r, delay);
}
return -1;
}
public static int runTaskLaterAsync(final Runnable r, final int delay) {
public static void runTaskLaterAsync(final Runnable r, final int delay) {
if (r != null) {
return PlotSquared.TASK.taskLaterAsync(r, delay);
PlotSquared.TASK.taskLaterAsync(r, delay);
}
return -1;
}
}

View File

@ -51,11 +51,11 @@ import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.object.entity.EntityWrapper;
import com.intellectualcrafters.plot.util.AChunkManager;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.TaskManager;
public class ChunkManager extends AChunkManager {
public class BukkitChunkManager extends ChunkManager {
public static MutableInt index = new MutableInt(0);
public static HashMap<Integer, Integer> tasks = new HashMap<>();
@ -151,10 +151,10 @@ public class ChunkManager extends AChunkManager {
final int relZ = newPos.getZ() - pos1.getZ();
final RegionWrapper region = new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ());
final World world = Bukkit.getWorld(pos1.getWorld());
final Chunk c1 = world.getChunkAt(pos1.getX(), pos1.getZ());
final Chunk c2 = world.getChunkAt(pos2.getX(), pos2.getZ());
final Chunk c3 = world.getChunkAt((pos1.getX() + relX), (pos1.getZ() + relZ));
final Chunk c4 = world.getChunkAt((pos2.getX() + relX), (pos2.getZ() + relZ));
final Chunk c1 = world.getChunkAt(pos1.getX() >> 4, pos1.getZ() >> 4);
final Chunk c2 = world.getChunkAt(pos2.getX() >> 4, pos2.getZ() >> 4);
final Chunk c3 = world.getChunkAt((pos1.getX() + relX) >> 4, (pos1.getZ() + relZ) >> 4);
final Chunk c4 = world.getChunkAt((pos2.getX() + relX) >> 4, (pos2.getZ() + relZ) >> 4);
final int sx = pos1.getX();
final int sz = pos1.getZ();
final int ex = pos2.getX();
@ -170,9 +170,9 @@ public class ChunkManager extends AChunkManager {
final ArrayList<Chunk> chunks = new ArrayList<>();
final ArrayList<Chunk> toGenerate = new ArrayList<>();
// Load chunks
for (int x = c1x; x <= c2x; x++) {
for (int z = c1z; z <= c2z; z++) {
final Chunk chunk = world.getChunkAt(x << 4, z << 4);
for (int x = c2x; x <= c3x; x++) {
for (int z = c2z; z <= c3z; z++) {
final Chunk chunk = world.getChunkAt(x, z);
toGenerate.add(chunk);
}
}
@ -192,15 +192,15 @@ public class ChunkManager extends AChunkManager {
index.increment();
// Copy entities
initMaps();
for (int x = c3x; x <= c4x; x++) {
for (int z = c3z; z <= c4z; z++) {
for (int x = c1x; x <= c2x; x++) {
for (int z = c1z; z <= c2z; z++) {
final Chunk chunk = world.getChunkAt(x, z);
chunks.add(chunk);
chunk.load(false);
saveEntitiesIn(chunk, region);
}
}
restoreEntities(world, relX, relZ);
}
}
// Copy blocks
final MutableInt mx = new MutableInt(sx);
final Integer currentIndex = index.toInteger();
@ -210,24 +210,24 @@ public class ChunkManager extends AChunkManager {
public void run() {
final long start = System.currentTimeMillis();
while ((System.currentTimeMillis() - start) < 25) {
final int x = mx.intValue();
final int xv = mx.intValue();
for (int z = sz; z <= ez; z++) {
saveBlocks(world, maxY, x, z);
saveBlocks(world, maxY, xv, z);
for (int y = 1; y <= maxY; y++) {
final Block block = world.getBlockAt(x, y, z);
final Block block = world.getBlockAt(xv, y, z);
final int id = block.getTypeId();
final byte data = block.getData();
SetBlockManager.setBlockManager.set(world, x + relX, y, z + relZ, id, data);
BukkitSetBlockManager.setBlockManager.set(world, xv + relX, y, z + relZ, id, data);
}
}
mx.increment();
if (x == ex) { // done!
if (xv == ex) { // done!
restoreBlocks(world, relX, relZ);
SetBlockManager.setBlockManager.update(chunks);
BukkitSetBlockManager.setBlockManager.update(chunks);
for (final Chunk chunk : chunks) {
chunk.unload(true, true);
}
TaskManager.runTaskLater(whenDone, 1);
TaskManager.runTask(whenDone);
Bukkit.getScheduler().cancelTask(tasks.get(currentIndex));
tasks.remove(currentIndex);
return;
@ -256,8 +256,8 @@ public class ChunkManager extends AChunkManager {
index.increment();
final Plugin plugin = BukkitMain.THIS;
final World world = Bukkit.getWorld(pos1.getWorld());
final Chunk c1 = world.getChunkAt(pos1.getX(), pos1.getZ());
final Chunk c2 = world.getChunkAt(pos2.getX(), pos2.getZ());
final Chunk c1 = world.getChunkAt(pos1.getX() >> 4, pos1.getZ() >> 4);
final Chunk c2 = world.getChunkAt(pos2.getX() >> 4, pos2.getZ() >> 4);
final int sx = pos1.getX();
final int sz = pos1.getZ();
final int ex = pos2.getX();
@ -266,6 +266,7 @@ public class ChunkManager extends AChunkManager {
final int c1z = c1.getZ();
final int c2x = c2.getX();
final int c2z = c2.getZ();
final ArrayList<Chunk> chunks = new ArrayList<Chunk>();
for (int x = c1x; x <= c2x; x++) {
for (int z = c1z; z <= c2z; z++) {
@ -334,7 +335,7 @@ public class ChunkManager extends AChunkManager {
restoreEntities(world, 0, 0);
}
chunk.unload(true, true);
SetBlockManager.setBlockManager.update(Arrays.asList(new Chunk[] { chunk }));
BukkitSetBlockManager.setBlockManager.update(Arrays.asList(new Chunk[] { chunk }));
}
CURRENT_PLOT_CLEAR = null;
}
@ -387,6 +388,10 @@ public class ChunkManager extends AChunkManager {
}
public static void saveEntitiesIn(final Chunk chunk, final RegionWrapper region) {
saveEntitiesIn(chunk, region, 0, 0, false);
}
public static void saveEntitiesIn(final Chunk chunk, final RegionWrapper region, int offset_x, int offset_z, boolean delete) {
for (final Entity entity : chunk.getEntities()) {
final Location loc = BukkitUtil.getLocation(entity);
final int x = loc.getX();
@ -398,7 +403,14 @@ public class ChunkManager extends AChunkManager {
continue;
}
final EntityWrapper wrap = new EntityWrapper(entity, (short) 2);
wrap.x += offset_x;
wrap.z += offset_z;
entities.add(wrap);
if (delete) {
if (!(entity instanceof Player)) {
entity.remove();
}
}
}
}
@ -407,7 +419,7 @@ public class ChunkManager extends AChunkManager {
try {
entity.spawn(world, x_offset, z_offset);
} catch (final Exception e) {
System.out.print("Failed to restore entity " + entity.x + "," + entity.y + "," + entity.z + " : " + entity.id + " : " + EntityType.fromId(entity.id));
PlotSquared.log("Failed to restore entity " + entity.x + "," + entity.y + "," + entity.z + " : " + entity.id + " : " + EntityType.fromId(entity.id));
e.printStackTrace();
}
}
@ -598,6 +610,10 @@ public class ChunkManager extends AChunkManager {
}
public static void saveBlocks(final World world, final int maxY, final int x, final int z) {
saveBlocks(world, maxY, x, z, 0, 0);
}
public static void saveBlocks(final World world, final int maxY, int x, int z, int offset_x, int offset_z) {
final HashMap<Short, Short> ids = new HashMap<>();
final HashMap<Short, Byte> datas = new HashMap<>();
for (short y = 1; y < maxY; y++) {
@ -612,13 +628,13 @@ public class ChunkManager extends AChunkManager {
BlockLoc bl;
switch (id) {
case 54:
bl = new BlockLoc(x, y, z);
bl = new BlockLoc(x + offset_x, y, z + offset_z);
final InventoryHolder chest = (InventoryHolder) block.getState();
final ItemStack[] inventory = chest.getInventory().getContents().clone();
chestContents.put(bl, inventory);
break;
case 52:
bl = new BlockLoc(x, y, z);
bl = new BlockLoc(x + offset_x, y, z + offset_z);
final CreatureSpawner spawner = (CreatureSpawner) block.getState();
final String type = spawner.getCreatureTypeId();
if ((type != null) && (type.length() != 0)) {
@ -626,7 +642,7 @@ public class ChunkManager extends AChunkManager {
}
break;
case 137:
bl = new BlockLoc(x, y, z);
bl = new BlockLoc(x + offset_x, y, z + offset_z);
final CommandBlock cmd = (CommandBlock) block.getState();
final String string = cmd.getCommand();
if ((string != null) && (string.length() > 0)) {
@ -636,14 +652,14 @@ public class ChunkManager extends AChunkManager {
case 63:
case 68:
case 323:
bl = new BlockLoc(x, y, z);
bl = new BlockLoc(x + offset_x, y, z + offset_z);
final Sign sign = (Sign) block.getState();
sign.getLines();
signContents.put(bl, sign.getLines().clone());
break;
case 61:
case 62:
bl = new BlockLoc(x, y, z);
bl = new BlockLoc(x + offset_x, y, z + offset_z);
final Furnace furnace = (Furnace) block.getState();
final short burn = furnace.getBurnTime();
final short cook = furnace.getCookTime();
@ -654,19 +670,19 @@ public class ChunkManager extends AChunkManager {
}
break;
case 23:
bl = new BlockLoc(x, y, z);
bl = new BlockLoc(x + offset_x, y, z + offset_z);
final Dispenser dispenser = (Dispenser) block.getState();
final ItemStack[] invDis = dispenser.getInventory().getContents().clone();
dispenserContents.put(bl, invDis);
break;
case 158:
bl = new BlockLoc(x, y, z);
bl = new BlockLoc(x + offset_x, y, z + offset_z);
final Dropper dropper = (Dropper) block.getState();
final ItemStack[] invDro = dropper.getInventory().getContents().clone();
dropperContents.put(bl, invDro);
break;
case 117:
bl = new BlockLoc(x, y, z);
bl = new BlockLoc(x + offset_x, y, z + offset_z);
final BrewingStand brewingStand = (BrewingStand) block.getState();
final short time = (short) brewingStand.getBrewingTime();
if (time > 0) {
@ -676,19 +692,19 @@ public class ChunkManager extends AChunkManager {
brewingStandContents.put(bl, invBre);
break;
case 25:
bl = new BlockLoc(x, y, z);
bl = new BlockLoc(x + offset_x, y, z + offset_z);
final NoteBlock noteBlock = (NoteBlock) block.getState();
final Note note = noteBlock.getNote();
noteBlockContents.put(bl, note);
break;
case 138:
bl = new BlockLoc(x, y, z);
bl = new BlockLoc(x + offset_x, y, z + offset_z);
final Beacon beacon = (Beacon) block.getState();
final ItemStack[] invBea = beacon.getInventory().getContents().clone();
beaconContents.put(bl, invBea);
break;
case 84:
bl = new BlockLoc(x, y, z);
bl = new BlockLoc(x + offset_x, y, z + offset_z);
final Jukebox jukebox = (Jukebox) block.getState();
final Material playing = jukebox.getPlaying();
if (playing != null) {
@ -696,13 +712,13 @@ public class ChunkManager extends AChunkManager {
}
break;
case 154:
bl = new BlockLoc(x, y, z);
bl = new BlockLoc(x + offset_x, y, z + offset_z);
final Hopper hopper = (Hopper) block.getState();
final ItemStack[] invHop = hopper.getInventory().getContents().clone();
hopperContents.put(bl, invHop);
break;
case 397:
bl = new BlockLoc(x, y, z);
bl = new BlockLoc(x + offset_x, y, z + offset_z);
final Skull skull = (Skull) block.getState();
final String o = skull.getOwner();
final byte skulltype = getOrdinal(SkullType.values(), skull.getSkullType());
@ -712,7 +728,7 @@ public class ChunkManager extends AChunkManager {
break;
case 176:
case 177:
bl = new BlockLoc(x, y, z);
bl = new BlockLoc(x + offset_x, y, z + offset_z);
final Banner banner = (Banner) block.getState();
final byte base = getOrdinal(DyeColor.values(), banner.getBaseColor());
final ArrayList<Byte[]> types = new ArrayList<>();
@ -757,12 +773,89 @@ public class ChunkManager extends AChunkManager {
}
@Override
public boolean loadChunk(String world, ChunkLoc loc) {
return BukkitUtil.getWorld(world).getChunkAt(loc.x << 4, loc.z << 4).load(false);
public boolean loadChunk(final String world, final ChunkLoc loc) {
return BukkitUtil.getWorld(world).getChunkAt(loc.x, loc.z).load(false);
}
public static void swapChunk(World world, Chunk pos1, Chunk pos2, RegionWrapper r1, RegionWrapper r2) {
initMaps();
int relX = (r2.minX - r1.minX);
int relZ = (r2.minZ - r1.minZ);
saveEntitiesIn(pos1, r1, relX, relZ, true);
saveEntitiesIn(pos2, r2, -relX, -relZ, true);
int sx = pos1.getX() << 4;
int sz = pos1.getZ() << 4;
int maxY = world.getMaxHeight();
for (int x = Math.max(r1.minX, sx); x <= Math.min(r1.maxX, sx + 15); x++) {
for (int z = Math.max(r1.minZ, sz); z <= Math.min(r1.maxZ, sz + 15); z++) {
saveBlocks(world, maxY, sx, sz, relX, relZ);
for (int y = 0; y < maxY; y++) {
Block block1 = world.getBlockAt(x, y, z);
int id1 = block1.getTypeId();
byte data1 = block1.getData();
int xx = x + relX;
int zz = z + relZ;
Block block2 = world.getBlockAt(xx, y, zz);
int id2 = block2.getTypeId();
byte data2 = block2.getData();
if (id1 == 0) {
if (id2 != 0) {
BukkitSetBlockManager.setBlockManager.set(world, x, y, z, id2, data2);
BukkitSetBlockManager.setBlockManager.set(world, xx, y, zz, 0, (byte) 0);
}
}
else if (id2 == 0) {
if (id1 != 0) {
BukkitSetBlockManager.setBlockManager.set(world, xx, y, zz, id1, data1);
BukkitSetBlockManager.setBlockManager.set(world, x, y, z, 0, (byte) 0);
}
}
else if (id1 == id2) {
if (data1 != data2) {
block1.setData(data2);
block2.setData(data1);
}
}
else {
BukkitSetBlockManager.setBlockManager.set(world, x, y, z, id2, data2);
BukkitSetBlockManager.setBlockManager.set(world, xx, y, zz, id1, data1);
}
}
}
}
restoreBlocks(world, 0, 0);
restoreEntities(world, 0, 0);
}
@Override
public void swap(String world, PlotId id, PlotId plotid) {
public void swap(final String worldname, final PlotId pos1, final PlotId pos2) {
Location bot1 = MainUtil.getPlotBottomLoc(worldname, pos1).add(1, 0, 1);
Location top1 = MainUtil.getPlotTopLoc(worldname, pos1);
Location bot2 = MainUtil.getPlotBottomLoc(worldname, pos2).add(1, 0, 1);
Location top2 = MainUtil.getPlotTopLoc(worldname, pos2);
final RegionWrapper region1 = new RegionWrapper(bot1.getX(), top1.getX(), bot1.getZ(), top1.getZ());
final RegionWrapper region2 = new RegionWrapper(bot2.getX(), top2.getX(), bot2.getZ(), top2.getZ());
final World world = Bukkit.getWorld(bot1.getWorld());
final int relX = bot2.getX() - bot1.getX();
final int relZ = bot2.getZ() - bot1.getZ();
for (int x = bot1.getX() >> 4; x <= top1.getX() >> 4; x++) {
for (int z = bot1.getZ() >> 4; z <= top1.getZ() >> 4; z++) {
Chunk chunk1 = world.getChunkAt(x, z);
Chunk chunk2 = world.getChunkAt(x + (relX >> 4), z + (relZ >> 4));
swapChunk(world, chunk1, chunk2, region1, region2);
}
}
clearAllEntities(MainUtil.getPlot(worldname, pos1));
clearAllEntities(MainUtil.getPlot(worldname, pos2));
// FIXME swap plots
}
}

View File

@ -0,0 +1,111 @@
package com.intellectualcrafters.plot.util.bukkit;
import java.util.ArrayList;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import com.intellectualcrafters.plot.events.PlayerClaimPlotEvent;
import com.intellectualcrafters.plot.events.PlayerEnterPlotEvent;
import com.intellectualcrafters.plot.events.PlayerLeavePlotEvent;
import com.intellectualcrafters.plot.events.PlayerPlotDeniedEvent;
import com.intellectualcrafters.plot.events.PlayerPlotHelperEvent;
import com.intellectualcrafters.plot.events.PlayerPlotTrustedEvent;
import com.intellectualcrafters.plot.events.PlayerTeleportToPlotEvent;
import com.intellectualcrafters.plot.events.PlotClearEvent;
import com.intellectualcrafters.plot.events.PlotDeleteEvent;
import com.intellectualcrafters.plot.events.PlotFlagAddEvent;
import com.intellectualcrafters.plot.events.PlotFlagRemoveEvent;
import com.intellectualcrafters.plot.events.PlotMergeEvent;
import com.intellectualcrafters.plot.events.PlotUnlinkEvent;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.object.BukkitPlayer;
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.EventUtil;
public class BukkitEventUtil extends EventUtil {
public Player getPlayer(PlotPlayer player) {
return ((BukkitPlayer) player).player;
}
public boolean callEvent(Event event) {
Bukkit.getServer().getPluginManager().callEvent(event);
if (event instanceof Cancellable) {
return !((Cancellable) event).isCancelled();
}
return true;
}
@Override
public boolean callClaim(PlotPlayer player, Plot plot, boolean auto) {
return callEvent(new PlayerClaimPlotEvent(getPlayer(player), plot, auto));
}
@Override
public boolean callTeleport(PlotPlayer player, Location from, Plot plot) {
return callEvent(new PlayerTeleportToPlotEvent(getPlayer(player), from, plot));
}
@Override
public boolean callClear(String world, PlotId id) {
return callEvent(new PlotClearEvent(world, id));
}
@Override
public void callDelete(String world, PlotId id) {
callEvent(new PlotDeleteEvent(world, id));
}
@Override
public boolean callFlagAdd(Flag flag, Plot plot) {
return callEvent(new PlotFlagAddEvent(flag, plot));
}
@Override
public boolean callFlagRemove(Flag flag, Plot plot) {
return callEvent(new PlotFlagRemoveEvent(flag, plot));
}
@Override
public boolean callMerge(String world, Plot plot, ArrayList<PlotId> plots) {
return callEvent(new PlotMergeEvent(BukkitUtil.getWorld(world), plot, plots));
}
@Override
public boolean callUnlink(String world, ArrayList<PlotId> plots) {
return callEvent(new PlotUnlinkEvent(BukkitUtil.getWorld(world), plots));
}
@Override
public void callEntry(PlotPlayer player, Plot plot) {
callEvent(new PlayerEnterPlotEvent(getPlayer(player), plot));
}
@Override
public void callLeave(PlotPlayer player, Plot plot) {
callEvent(new PlayerLeavePlotEvent(getPlayer(player), plot));
}
@Override
public void callDenied(PlotPlayer initiator, Plot plot, UUID player, boolean added) {
callEvent(new PlayerPlotDeniedEvent(getPlayer(initiator), plot, player, added));
}
@Override
public void callHelper(PlotPlayer initiator, Plot plot, UUID player, boolean added) {
callEvent(new PlayerPlotHelperEvent(getPlayer(initiator), plot, player, added));
}
@Override
public void callTrusted(PlotPlayer initiator, Plot plot, UUID player, boolean added) {
callEvent(new PlayerPlotTrustedEvent(getPlayer(initiator), plot, player, added));
}
}

View File

@ -56,7 +56,7 @@ public class BukkitPlayerFunctions {
*/
public static void clear(final Player player, final String world, final Plot plot, final boolean isDelete) {
final long start = System.currentTimeMillis();
Runnable whenDone = new Runnable() {
final Runnable whenDone = new Runnable() {
@Override
public void run() {
if ((player != null) && player.isOnline()) {

View File

@ -0,0 +1,28 @@
package com.intellectualcrafters.plot.util.bukkit;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Chunk;
import org.bukkit.World;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.util.BlockUpdateUtil;
public abstract class BukkitSetBlockManager extends BlockUpdateUtil {
public static BukkitSetBlockManager setBlockManager = null;
public abstract void set(final org.bukkit.World world, final int x, final int y, final int z, final int blockId, final byte data);
public abstract void update(List<Chunk> list);
@Override
public void update(final String worldname, final List<ChunkLoc> chunkLocs) {
final World world = BukkitUtil.getWorld(worldname);
final ArrayList<Chunk> chunks = new ArrayList<Chunk>();
for (final ChunkLoc loc : chunkLocs) {
chunks.add(world.getChunkAt(loc.x, loc.z));
}
setBlockManager.update(chunks);
}
}

View File

@ -12,27 +12,27 @@ public class BukkitTaskManager extends TaskManager {
}
@Override
public int taskAsync(final Runnable r) {
return BukkitMain.THIS.getServer().getScheduler().runTaskAsynchronously(BukkitMain.THIS, r).getTaskId();
public void taskAsync(final Runnable r) {
BukkitMain.THIS.getServer().getScheduler().runTaskAsynchronously(BukkitMain.THIS, r).getTaskId();
}
@Override
public int task(final Runnable r) {
return BukkitMain.THIS.getServer().getScheduler().runTask(BukkitMain.THIS, r).getTaskId();
public void task(final Runnable r) {
BukkitMain.THIS.getServer().getScheduler().runTask(BukkitMain.THIS, r).getTaskId();
}
@Override
public int taskLater(final Runnable r, final int delay) {
return BukkitMain.THIS.getServer().getScheduler().runTaskLater(BukkitMain.THIS, r, delay).getTaskId();
public void taskLater(final Runnable r, final int delay) {
BukkitMain.THIS.getServer().getScheduler().runTaskLater(BukkitMain.THIS, r, delay).getTaskId();
}
@Override
public int taskLaterAsync(final Runnable r, final int delay) {
return BukkitMain.THIS.getServer().getScheduler().runTaskLaterAsynchronously(BukkitMain.THIS, r, delay).getTaskId();
public void taskLaterAsync(final Runnable r, final int delay) {
BukkitMain.THIS.getServer().getScheduler().runTaskLaterAsynchronously(BukkitMain.THIS, r, delay);
}
@Override
public void cancelTask(int task) {
public void cancelTask(final int task) {
if (task != -1) {
Bukkit.getScheduler().cancelTask(task);
}

View File

@ -15,11 +15,15 @@ import org.bukkit.block.BlockState;
import org.bukkit.block.Sign;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import com.intellectualcrafters.plot.object.BukkitPlayer;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.schematic.PlotItem;
import com.intellectualcrafters.plot.util.BlockManager;
public class BukkitUtil extends BlockManager {
@ -30,8 +34,8 @@ public class BukkitUtil extends BlockManager {
private static Player lastPlayer = null;
private static PlotPlayer lastPlotPlayer = null;
public static void removePlayer(String plr) {
if (lastPlayer != null && lastPlayer.getName().equals(plr)) {
public static void removePlayer(final String plr) {
if ((lastPlayer != null) && lastPlayer.getName().equals(plr)) {
lastPlayer = null;
lastPlotPlayer = null;
}
@ -39,11 +43,11 @@ public class BukkitUtil extends BlockManager {
}
@Override
public boolean isWorld(String world) {
public boolean isWorld(final String world) {
return getWorld(world) != null;
}
public static PlotPlayer getPlayer(Player player) {
public static PlotPlayer getPlayer(final Player player) {
if (player == lastPlayer) {
return lastPlotPlayer;
}
@ -58,7 +62,7 @@ public class BukkitUtil extends BlockManager {
return getWorld(loc.getWorld()).getBiome(loc.getX(), loc.getZ()).name();
}
public static Location getLocation(org.bukkit.Location loc) {
public static Location getLocation(final org.bukkit.Location loc) {
return new Location(loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
}
@ -96,7 +100,7 @@ public class BukkitUtil extends BlockManager {
chunks.add(chunk);
}
}
SetBlockManager.setBlockManager.update(chunks);
BukkitSetBlockManager.setBlockManager.update(chunks);
}
public static String getWorld(final Entity entity) {
@ -114,10 +118,10 @@ public class BukkitUtil extends BlockManager {
public static void setBlock(final World world, final int x, final int y, final int z, final int id, final byte data) {
try {
SetBlockManager.setBlockManager.set(world, x, y, z, id, data);
BukkitSetBlockManager.setBlockManager.set(world, x, y, z, id, data);
} catch (final Throwable e) {
SetBlockManager.setBlockManager = new SetBlockSlow();
SetBlockManager.setBlockManager.set(world, x, y, z, id, data);
BukkitSetBlockManager.setBlockManager = new SetBlockSlow();
BukkitSetBlockManager.setBlockManager.set(world, x, y, z, id, data);
}
}
@ -160,6 +164,12 @@ public class BukkitUtil extends BlockManager {
return new Location(world, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
}
public static Location getLocationFull(final Entity entity) {
final org.bukkit.Location loc = entity.getLocation();
final String world = loc.getWorld().getName();
return new Location(world, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), loc.getYaw(), loc.getPitch());
}
@Override
public void functionSetBlocks(final String worldname, final int[] x, final int[] y, final int[] z, final int[] id, final byte[] data) {
final World world = getWorld(worldname);
@ -188,22 +198,22 @@ public class BukkitUtil extends BlockManager {
}
@Override
public void functionSetBiomes(String worldname, int[] x, int[] z, int[] biome) {
World world = getWorld(worldname);
Biome[] biomes = Biome.values();
public void functionSetBiomes(final String worldname, final int[] x, final int[] z, final int[] biome) {
final World world = getWorld(worldname);
final Biome[] biomes = Biome.values();
for (int i = 0; i < x.length; i++) {
world.setBiome(x[i], z[i], biomes[biome[i]]);
}
}
@Override
public void functionSetBlock(String worldname, int x, int y, int z, int id, byte data) {
public void functionSetBlock(final String worldname, final int x, final int y, final int z, final int id, final byte data) {
BukkitUtil.setBlock(getWorld(worldname), x, y, z, id, data);
}
@Override
public String[] getSign(Location loc) {
Block block = getWorld(loc.getWorld()).getBlockAt(loc.getX(), loc.getY(), loc.getZ());
public String[] getSign(final Location loc) {
final Block block = getWorld(loc.getWorld()).getBlockAt(loc.getX(), loc.getY(), loc.getZ());
if (block != null) {
if (block.getState() instanceof Sign) {
final Sign sign = (Sign) block.getState();
@ -214,19 +224,19 @@ public class BukkitUtil extends BlockManager {
}
@Override
public Location getSpawn(String world) {
org.bukkit.Location temp = getWorld(world).getSpawnLocation();
public Location getSpawn(final String world) {
final org.bukkit.Location temp = getWorld(world).getSpawnLocation();
return new Location(world, temp.getBlockX(), temp.getBlockY(), temp.getBlockZ());
}
@Override
public int getHeighestBlock(Location loc) {
public int getHeighestBlock(final Location loc) {
return getWorld(loc.getWorld()).getHighestBlockAt(loc.getX(), loc.getZ()).getY();
}
@Override
public int getBiomeFromString(String biomeStr) {
Biome biome = Biome.valueOf(biomeStr.toUpperCase());
public int getBiomeFromString(final String biomeStr) {
final Biome biome = Biome.valueOf(biomeStr.toUpperCase());
if (biome == null) {
return -1;
}
@ -235,20 +245,42 @@ public class BukkitUtil extends BlockManager {
@Override
public String[] getBiomeList() {
Biome[] biomes = Biome.values();
String[] list = new String[biomes.length];
for (int i = 0; i< biomes.length; i++) {
final Biome[] biomes = Biome.values();
final String[] list = new String[biomes.length];
for (int i = 0; i < biomes.length; i++) {
list[i] = biomes[i].name();
}
return list;
}
@Override
public int getBlockIdFromString(String block) {
Material material = Material.valueOf(block.toUpperCase());
public int getBlockIdFromString(final String block) {
final Material material = Material.valueOf(block.toUpperCase());
if (material == null) {
return -1;
}
return material.getId();
}
@Override
public boolean addItems(String worldname, PlotItem items) {
World world = getWorld(worldname);
Block block = world.getBlockAt(items.x, items.y, items.z);
if (block == null) {
return false;
}
BlockState state = block.getState();
if (state != null && state instanceof InventoryHolder) {
InventoryHolder holder = ((InventoryHolder) state);
Inventory inv = holder.getInventory();
for (int i = 0; i < items.id.length; i++) {
ItemStack item = new ItemStack(items.id[i], items.amount[i], items.data[i]);
inv.addItem(item);
}
state.update(true);
return true;
}
return false;
}
}

View File

@ -49,6 +49,8 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.scheduler.BukkitTask;
import com.intellectualcrafters.plot.PlotSquared;
public class Metrics {
/**
* The current revision number
@ -523,7 +525,7 @@ public class Metrics {
connection.addRequestProperty("Connection", "close");
connection.setDoOutput(true);
if (this.debug) {
System.out.println("[Metrics] Prepared request for " + pluginName + " uncompressed=" + uncompressed.length + " compressed=" + compressed.length);
PlotSquared.log("[Metrics] Prepared request for " + pluginName + " uncompressed=" + uncompressed.length + " compressed=" + compressed.length);
}
// Write the data
final OutputStream os = connection.getOutputStream();

View File

@ -42,9 +42,18 @@ import com.sk89q.worldedit.regions.CuboidRegion;
* @author Empire92
*/
public class PWE {
public static LocalSession getSession(PlotPlayer p) {
if (PlotSquared.worldEdit == null) {
return WorldEdit.getInstance().getSession(p.getName());
} else {
return PlotSquared.worldEdit.getSession(((BukkitPlayer) p).player);
}
}
public static void setMask(final PlotPlayer p, final Location l, final boolean force) {
try {
LocalSession s = WorldEdit.getInstance().getSession(p.getName());
LocalSession s = getSession(p);
if (!PlotSquared.isPlotWorld(l.getWorld())) {
removeMask(p);
}
@ -63,7 +72,6 @@ public class PWE {
final Vector bvec = new Vector(bloc.getX() + 1, bloc.getY(), bloc.getZ() + 1);
final Vector tvec = new Vector(tloc.getX(), tloc.getY(), tloc.getZ());
// FIXME unchecked casting
final LocalWorld lw = PlotSquared.worldEdit.wrapPlayer(((BukkitPlayer) p).player).getWorld();
final CuboidRegion region = new CuboidRegion(lw, bvec, tvec);
@ -85,7 +93,7 @@ public class PWE {
}
public static boolean hasMask(final PlotPlayer p) {
LocalSession s = WorldEdit.getInstance().getSession(p.getName());
LocalSession s = getSession(p);
return !noMask(s);
}
@ -96,7 +104,7 @@ public class PWE {
@SuppressWarnings("deprecation")
public static void setNoMask(final PlotPlayer p) {
try {
LocalSession s = WorldEdit.getInstance().getSession(p.getName());
LocalSession s = getSession(p);
final com.sk89q.worldedit.bukkit.BukkitPlayer plr = PlotSquared.worldEdit.wrapPlayer(((BukkitPlayer) p).player);
final Vector p1 = new Vector(69, 69, 69), p2 = new Vector(69, 69, 69);
s.setMask(new RegionMask(new CuboidRegion(plr.getWorld(), p1, p2)));
@ -112,7 +120,7 @@ public class PWE {
public static void removeMask(final PlotPlayer p) {
try {
LocalSession s = WorldEdit.getInstance().getSession(p.getName());
LocalSession s = getSession(p);
removeMask(p, s);
} catch (final Exception e) {
// throw new

View File

@ -36,7 +36,7 @@ import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod;
*
* @author Empire92
*/
public class SetBlockFast extends SetBlockManager {
public class SetBlockFast extends BukkitSetBlockManager {
private static final RefClass classBlock = getRefClass("{nms}.Block");
private static final RefClass classChunk = getRefClass("{nms}.Chunk");
private static final RefClass classWorld = getRefClass("{nms}.World");

View File

@ -38,7 +38,7 @@ import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod;
*
* @author Empire92
*/
public class SetBlockFast_1_8 extends SetBlockManager {
public class SetBlockFast_1_8 extends BukkitSetBlockManager {
private static final RefClass classBlock = getRefClass("{nms}.Block");
private static final RefClass classBlockPosition = getRefClass("{nms}.BlockPosition");
private static final RefClass classIBlockData = getRefClass("{nms}.IBlockData");
@ -83,6 +83,9 @@ public class SetBlockFast_1_8 extends SetBlockManager {
case 130:
case 146:
case 27:
case 63:
case 68:
case 313:
case 28:
case 66:
case 157:

View File

@ -1,13 +0,0 @@
package com.intellectualcrafters.plot.util.bukkit;
import java.util.List;
import org.bukkit.Chunk;
public abstract class SetBlockManager {
public static SetBlockManager setBlockManager = null;
public abstract void set(final org.bukkit.World world, final int x, final int y, final int z, final int blockId, final byte data);
public abstract void update(List<Chunk> list);
}

View File

@ -6,7 +6,7 @@ import org.bukkit.Chunk;
import org.bukkit.World;
import org.bukkit.block.Block;
public class SetBlockSlow extends SetBlockManager {
public class SetBlockSlow extends BukkitSetBlockManager {
@Override
public void set(final World world, final int x, final int y, final int z, final int id, final byte data) {
final Block block = world.getBlockAt(x, y, z);

View File

@ -35,10 +35,8 @@ public class UUIDHandler {
if ((uuid == null) || (name == null)) {
return;
}
if (!uuidMap.containsKey(name) && !uuidMap.inverse().containsKey(uuid)) {
uuidMap.put(name, uuid);
}
}
/**
* Get the map containing all names/uuids
@ -77,7 +75,7 @@ public class UUIDHandler {
return uuidMap.containsKey(name);
}
public static void cacheAll(String world) {
public static void cacheAll(final String world) {
if (CACHED) {
return;
}
@ -168,8 +166,8 @@ public class UUIDHandler {
return null;
}
public static PlotPlayer getPlayer(UUID uuid) {
for (PlotPlayer player : players.values()) {
public static PlotPlayer getPlayer(final UUID uuid) {
for (final PlotPlayer player : players.values()) {
if (player.getUUID().equals(uuid)) {
return player;
}
@ -177,7 +175,7 @@ public class UUIDHandler {
return null;
}
public static PlotPlayer getPlayer(String name) {
public static PlotPlayer getPlayer(final String name) {
return players.get(name);
}

View File

@ -11,6 +11,7 @@ import org.bukkit.entity.Player;
import com.google.common.base.Charsets;
import com.google.common.collect.BiMap;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.object.BukkitOfflinePlayer;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.StringWrapper;
@ -81,7 +82,7 @@ public class OfflineUUIDWrapper extends UUIDWrapper {
return p.toArray(new Player[0]);
}
} catch (final Exception e) {
System.out.print("Failed to resolve online players");
PlotSquared.log("Failed to resolve online players");
this.getOnline = null;
return Bukkit.getOnlinePlayers().toArray(new Player[0]);
}

Some files were not shown because too many files have changed in this diff Show More