Refactor / Cleanup / Optimizations

This commit is contained in:
Jesse Boyd 2016-02-11 05:59:51 +11:00
parent 085f621f0f
commit c83378a91b
203 changed files with 9785 additions and 8701 deletions

15
pom.xml
View File

@ -190,9 +190,13 @@
</build> </build>
<repositories> <repositories>
<repository>
<id>empcraft-repo</id>
<url>http://empcraft.com/maven2</url>
</repository>
<repository> <repository>
<id>spigot-repo</id> <id>spigot-repo</id>
<url>http://hub.spigotmc.org/nexus/content/groups/public/</url> <url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository> </repository>
<!-- <!--
@ -261,13 +265,10 @@
--> -->
<dependency> <dependency>
<groupId>javax.websocket</groupId> <groupId>org.bukkit</groupId>
<artifactId>javax.websocket-api</artifactId> <artifactId>bukkit</artifactId>
<version>1.1</version> <version>1.8.8-R0.1-SNAPSHOT</version>
<scope>compile</scope>
<optional>true</optional>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.sk89q</groupId> <groupId>com.sk89q</groupId>
<artifactId>worldedit</artifactId> <artifactId>worldedit</artifactId>

View File

@ -1,10 +1,5 @@
package com.intellectualcrafters.configuration.file; package com.intellectualcrafters.configuration.file;
import com.intellectualcrafters.configuration.Configuration;
import com.intellectualcrafters.configuration.InvalidConfigurationException;
import com.intellectualcrafters.configuration.MemoryConfiguration;
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -19,6 +14,12 @@ import java.io.Writer;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
import com.intellectualcrafters.configuration.Configuration;
import com.intellectualcrafters.configuration.InvalidConfigurationException;
import com.intellectualcrafters.configuration.MemoryConfiguration;
/** /**
* This is a base class for all File based implementations of {@link * This is a base class for all File based implementations of {@link
* Configuration} * Configuration}

View File

@ -1,21 +1,24 @@
package com.intellectualcrafters.plot; package com.intellectualcrafters.plot;
import java.io.File; import java.io.File;
import java.util.List;
import com.intellectualcrafters.plot.generator.GeneratorWrapper;
import com.intellectualcrafters.plot.generator.HybridUtils; import com.intellectualcrafters.plot.generator.HybridUtils;
import com.intellectualcrafters.plot.generator.PlotGenerator; import com.intellectualcrafters.plot.generator.IndependentPlotGenerator;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.AbstractTitle; import com.intellectualcrafters.plot.util.AbstractTitle;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.ChatManager; import com.intellectualcrafters.plot.util.ChatManager;
import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.InventoryUtil; import com.intellectualcrafters.plot.util.InventoryUtil;
import com.intellectualcrafters.plot.util.PlotQueue;
import com.intellectualcrafters.plot.util.SchematicHandler; import com.intellectualcrafters.plot.util.SchematicHandler;
import com.intellectualcrafters.plot.util.SetupUtils; import com.intellectualcrafters.plot.util.SetupUtils;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandlerImplementation; import com.intellectualcrafters.plot.util.UUIDHandlerImplementation;
import com.intellectualcrafters.plot.util.WorldUtil;
public interface IPlotMain { public interface IPlotMain {
@ -129,10 +132,16 @@ public interface IPlotMain {
EconHandler getEconomyHandler(); EconHandler getEconomyHandler();
/** /**
* Get the block manager * Get the Plot Queue class
* @return * @return
*/ */
BlockManager initBlockManager(); PlotQueue initPlotQueue();
/**
* Get the World Util class
* @return
*/
WorldUtil initWorldUtil();
/** /**
* Get the EventUtil class * Get the EventUtil class
@ -199,7 +208,12 @@ public interface IPlotMain {
* @param name * @param name
* @return * @return
*/ */
PlotGenerator<?> getGenerator(final String world, final String name); GeneratorWrapper<?> getGenerator(final String world, final String name);
/**
*
*/
GeneratorWrapper<?> wrapPlotGenerator(String world, IndependentPlotGenerator generator);
/** /**
* Register the chunk processor which will clean out chunks that have too many blockstates or entities * Register the chunk processor which will clean out chunks that have too many blockstates or entities
@ -222,4 +236,6 @@ public interface IPlotMain {
* @return * @return
*/ */
AbstractTitle initTitleManager(); AbstractTitle initTitleManager();
List<String> getPluginIds();
} }

File diff suppressed because it is too large Load Diff

View File

@ -21,6 +21,17 @@
package com.intellectualcrafters.plot.api; package com.intellectualcrafters.plot.api;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import com.intellectualcrafters.configuration.file.YamlConfiguration; import com.intellectualcrafters.configuration.file.YamlConfiguration;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.commands.MainCommand; import com.intellectualcrafters.plot.commands.MainCommand;
@ -29,29 +40,17 @@ import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.flag.AbstractFlag; import com.intellectualcrafters.plot.flag.AbstractFlag;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer; 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.ChunkManager;
import com.intellectualcrafters.plot.util.ClusterManager;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.SchematicHandler; import com.intellectualcrafters.plot.util.SchematicHandler;
import com.intellectualcrafters.plot.util.SetQueue;
import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualcrafters.plot.uuid.UUIDWrapper; import com.intellectualcrafters.plot.uuid.UUIDWrapper;
import com.plotsquared.bukkit.util.BukkitSetBlockManager;
import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.bukkit.util.BukkitUtil;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Set;
import java.util.UUID;
/** /**
* PlotSquared API * PlotSquared API
@ -117,14 +116,14 @@ public class PlotAPI {
* Add a plot world * Add a plot world
* *
* @param world World Name * @param world World Name
* @param plotWorld Plot World Object * @param plotArea Plot World Object
* @param manager World Manager * @param manager World Manager
* *
* @see PS#addPlotWorld(String, com.intellectualcrafters.plot.object.PlotWorld, * @see PS#addPlotWorld(String, com.intellectualcrafters.plot.object.PlotArea,
* com.intellectualcrafters.plot.object.PlotManager) * com.intellectualcrafters.plot.object.PlotManager)
*/ */
public void addPlotWorld(final String world, final PlotWorld plotWorld, final PlotManager manager) { public void addPlotArea(final PlotArea plotArea) {
PS.get().addPlotWorld(world, plotWorld, manager); PS.get().addPlotArea(plotArea);
} }
/** /**
@ -172,27 +171,13 @@ public class PlotAPI {
public ChunkManager getChunkManager() { public ChunkManager getChunkManager() {
return ChunkManager.manager; return ChunkManager.manager;
} }
/** /**
* BlockManager class contains useful methods relating to blocks. * Get the block/biome set queue
* * @return SetQueue.IMP
* @return BlockManager
*
* @see com.intellectualcrafters.plot.util.BlockManager
*/ */
public BlockManager getBlockManager() { public SetQueue getSetQueue() {
return BlockManager.manager; return SetQueue.IMP;
}
/**
* BukkitSetBlockManager class contains useful methods relating to bukkit blocks.
*
* @return BukkitSetBlockManager
*
* @see com.plotsquared.bukkit.util.BukkitSetBlockManager
*/
public BukkitSetBlockManager getBukkitBlockManager() {
return BukkitSetBlockManager.setBlockManager;
} }
/** /**
@ -219,19 +204,6 @@ public class PlotAPI {
return new FlagManager(); return new FlagManager();
} }
/**
* Do not use this. Instead use ClusterManager.[method] in your code.
* - Plot cluster related stuff
*
* @return ClusterManager
*
* @see com.intellectualcrafters.plot.util.ClusterManager
*/
@Deprecated
public ClusterManager getClusterManager() {
return new ClusterManager();
}
/** /**
* Do not use this. Instead use MainUtil.[method] in your code. * Do not use this. Instead use MainUtil.[method] in your code.
* - Basic plot management stuff * - Basic plot management stuff
@ -297,10 +269,21 @@ public class PlotAPI {
* @see com.intellectualcrafters.plot.object.PlotManager * @see com.intellectualcrafters.plot.object.PlotManager
* @see PS#getPlotManager(String) * @see PS#getPlotManager(String)
*/ */
@Deprecated
public PlotManager getPlotManager(final World world) { public PlotManager getPlotManager(final World world) {
return PS.get().getPlotManager(world.getName()); if (world == null) {
return null;
}
return getPlotManager(world.getName());
} }
public Set<PlotArea> getPlotAreas(World world) {
if (world == null) {
return new HashSet<>();
}
return PS.get().getPlotAreas(world.getName());
}
/** /**
* Get the plot manager for a world. - Contains useful low level methods for plot merging, clearing, and * Get the plot manager for a world. - Contains useful low level methods for plot merging, clearing, and
* tessellation * tessellation
@ -312,37 +295,64 @@ public class PlotAPI {
* @see PS#getPlotManager(String) * @see PS#getPlotManager(String)
* @see com.intellectualcrafters.plot.object.PlotManager * @see com.intellectualcrafters.plot.object.PlotManager
*/ */
@Deprecated
public PlotManager getPlotManager(final String world) { public PlotManager getPlotManager(final String world) {
return PS.get().getPlotManager(world); Set<PlotArea> areas = PS.get().getPlotAreas(world);
switch (areas.size()) {
case 0:
return null;
case 1:
return areas.iterator().next().manager;
default:
PS.debug("PlotAPI#getPlotManager(org.bukkit.World) is deprecated and doesn't support multi plot area worlds.");
return null;
}
} }
/** /**
* Get the settings for a world (settings bundled in PlotWorld class) - You will need to downcast for the specific * Get the settings for a world (settings bundled in PlotArea class) - You will need to downcast for the specific
* settings a Generator has. e.g. DefaultPlotWorld class implements PlotWorld * settings a Generator has. e.g. DefaultPlotWorld class implements PlotArea
* *
* @param world (to get settings of) * @param world (to get settings of)
* *
* @return PlotWorld class for that world ! will return null if not a plot world world * @return PlotArea class for that world ! will return null if not a plot world world
* *
* @see PS#getPlotWorld(String) * @see #getPlotAreas(World)
* @see com.intellectualcrafters.plot.object.PlotWorld * @see com.intellectualcrafters.plot.object.PlotArea
*/ */
public PlotWorld getWorldSettings(final World world) { @Deprecated
return PS.get().getPlotWorld(world.getName()); public PlotArea getWorldSettings(final World world) {
if (world == null) {
return null;
}
return getWorldSettings(world.getName());
} }
/** /**
* Get the settings for a world (settings bundled in PlotWorld class) * Get the settings for a world (settings bundled in PlotArea class)
* *
* @param world (to get settings of) * @param world (to get settings of)
* *
* @return PlotWorld class for that world ! will return null if not a plot world world * @return PlotArea class for that world ! will return null if not a plot world world
* *
* @see PS#getPlotWorld(String) * @see PS#getPlotArea(String)
* @see com.intellectualcrafters.plot.object.PlotWorld * @see com.intellectualcrafters.plot.object.PlotArea
*/ */
public PlotWorld getWorldSettings(final String world) { @Deprecated
return PS.get().getPlotWorld(world); public PlotArea getWorldSettings(final String world) {
if (world == null) {
return null;
}
Set<PlotArea> areas = PS.get().getPlotAreas(world);
switch (areas.size()) {
case 0:
return null;
case 1:
return areas.iterator().next();
default:
PS.debug("PlotAPI#getWorldSettings(org.bukkit.World) is deprecated and doesn't support multi plot area worlds.");
return null;
}
} }
/** /**
@ -426,11 +436,18 @@ public class PlotAPI {
* *
* @return plot, null if ID is wrong * @return plot, null if ID is wrong
* *
* @see MainUtil#getPlotAbs(String, com.intellectualcrafters.plot.object.PlotId) * @see PlotArea#getPlot(PlotId)
* @see Plot
*/ */
@Deprecated
public Plot getPlot(final World world, final int x, final int z) { public Plot getPlot(final World world, final int x, final int z) {
return MainUtil.getPlotAbs(world.getName(), new PlotId(x, z)); if (world == null) {
return null;
}
PlotArea area = getWorldSettings(world);
if (area == null) {
return null;
}
return area.getPlot(new PlotId(x, z));
} }
/** /**
@ -444,7 +461,10 @@ public class PlotAPI {
* @see Plot * @see Plot
*/ */
public Plot getPlot(final Location l) { public Plot getPlot(final Location l) {
return MainUtil.getPlotAbs(BukkitUtil.getLocation(l)); if (l == null) {
return null;
}
return BukkitUtil.getLocation(l).getPlot();
} }
/** /**
@ -470,6 +490,7 @@ public class PlotAPI {
* *
* @see #getPlots(World, Player, boolean) * @see #getPlots(World, Player, boolean)
*/ */
@Deprecated
public boolean hasPlot(final World world, final Player player) { public boolean hasPlot(final World world, final Player player) {
return (getPlots(world, player, true) != null) && (getPlots(world, player, true).length > 0); return (getPlots(world, player, true) != null) && (getPlots(world, player, true).length > 0);
} }
@ -479,18 +500,18 @@ public class PlotAPI {
* *
* @param plr to search for * @param plr to search for
* @param just_owner should we just search for owner? Or with rights? * @param just_owner should we just search for owner? Or with rights?
*
* @see Plot
*/ */
@Deprecated
public Plot[] getPlots(final World world, final Player plr, final boolean just_owner) { public Plot[] getPlots(final World world, final Player plr, final boolean just_owner) {
final ArrayList<Plot> pPlots = new ArrayList<>(); final ArrayList<Plot> pPlots = new ArrayList<>();
for (final Plot plot : PS.get().getPlotsInWorld(world.getName())) { UUID uuid = BukkitUtil.getPlayer(plr).getUUID();
for (final Plot plot : PS.get().getPlots(world.getName())) {
if (just_owner) { if (just_owner) {
if ((plot.owner != null) && (plot.owner.equals(UUIDHandler.getUUID(BukkitUtil.getPlayer(plr))))) { if ((plot.owner != null) && (plot.owner.equals(uuid))) {
pPlots.add(plot); pPlots.add(plot);
} }
} else { } else {
if (plot.isAdded(UUIDHandler.getUUID(BukkitUtil.getPlayer(plr)))) { if (plot.isAdded(uuid)) {
pPlots.add(plot); pPlots.add(plot);
} }
} }
@ -508,9 +529,12 @@ public class PlotAPI {
* @see PS#getPlots(String) * @see PS#getPlots(String)
* @see Plot * @see Plot
*/ */
@Deprecated
public Plot[] getPlots(final World world) { public Plot[] getPlots(final World world) {
final Collection<Plot> plots = PS.get().getPlotsInWorld(world.getName()); if (world == null) {
return plots.toArray(new Plot[plots.size()]); return new Plot[0];
}
return PS.get().getPlots(world.getName()).toArray(new Plot[0]);
} }
/** /**
@ -520,9 +544,9 @@ public class PlotAPI {
* *
* @see PS#getPlotWorlds() * @see PS#getPlotWorlds()
*/ */
@Deprecated
public String[] getPlotWorlds() { public String[] getPlotWorlds() {
final Set<String> worlds = PS.get().getPlotWorlds(); return PS.get().getPlotWorldStrings().toArray(new String[0]);
return worlds.toArray(new String[worlds.size()]);
} }
/** /**
@ -532,10 +556,11 @@ public class PlotAPI {
* *
* @return boolean (if plot world or not) * @return boolean (if plot world or not)
* *
* @see PS#isPlotWorld(String) * @see PS#hasPlotArea(String)
*/ */
@Deprecated
public boolean isPlotWorld(final World world) { public boolean isPlotWorld(final World world) {
return PS.get().isPlotWorld(world.getName()); return PS.get().hasPlotArea(world.getName());
} }
/** /**
@ -545,16 +570,16 @@ public class PlotAPI {
* *
* @return [0] = bottomLc, [1] = topLoc, [2] = home * @return [0] = bottomLc, [1] = topLoc, [2] = home
* *
* @deprecated As merged plots may not have a rectangular shape
*
* @see MainUtil#getPlotBottomLocAbs(String, PlotId) * @see MainUtil#getPlotBottomLocAbs(String, PlotId)
* @see MainUtil#getPlotTopLocAbs(String, PlotId) * @see MainUtil#getPlotTopLocAbs(String, PlotId)
* @see MainUtil#getPlotHome(String, PlotId) * @see MainUtil#getPlotHome(String, PlotId)
* @see Plot * @see Plot
*/ */
@Deprecated
public Location[] getLocations(final Plot p) { public Location[] getLocations(final Plot p) {
return new Location[] { return new Location[] { BukkitUtil.getLocation(p.getBottom()), BukkitUtil.getLocation(p.getTop()), BukkitUtil.getLocation(p.getHome()) };
BukkitUtil.getLocation(MainUtil.getPlotBottomLocAbs(p.world, p.getId()).subtract(1, 0, 1)),
BukkitUtil.getLocation(MainUtil.getPlotTopLocAbs(p.world, p.getId())),
BukkitUtil.getLocation(MainUtil.getPlotHome(p.world, p.getId())) };
} }
/** /**
@ -568,7 +593,7 @@ public class PlotAPI {
* @see Plot * @see Plot
*/ */
public Location getHomeLocation(final Plot p) { public Location getHomeLocation(final Plot p) {
return BukkitUtil.getLocation(MainUtil.getPlotHome(p.world, p.getId())); return BukkitUtil.getLocation(p.getHome());
} }
/** /**
@ -578,11 +603,14 @@ public class PlotAPI {
* *
* @return plot bottom location * @return plot bottom location
* *
* @deprecated As merged plots may not have a rectangular shape
*
* @see MainUtil#getPlotBottomLocAbs(String, PlotId) * @see MainUtil#getPlotBottomLocAbs(String, PlotId)
* @see Plot * @see Plot
*/ */
@Deprecated
public Location getBottomLocation(final Plot p) { public Location getBottomLocation(final Plot p) {
return BukkitUtil.getLocation(MainUtil.getPlotBottomLocAbs(p.world, p.getId()).subtract(1, 0, 1)); return BukkitUtil.getLocation(p.getBottom());
} }
/** /**
@ -591,12 +619,15 @@ public class PlotAPI {
* @param p Plot that you want to get the location for * @param p Plot that you want to get the location for
* *
* @return plot top location * @return plot top location
*
* @deprecated As merged plots may not have a rectangular shape
* *
* @see MainUtil#getPlotTopLocAbs(String, PlotId) * @see MainUtil#getPlotTopLocAbs(String, PlotId)
* @see Plot * @see Plot
*/ */
@Deprecated
public Location getTopLocation(final Plot p) { public Location getTopLocation(final Plot p) {
return BukkitUtil.getLocation(MainUtil.getPlotTopLocAbs(p.world, p.getId())); return BukkitUtil.getLocation(p.getTop());
} }
/** /**
@ -609,7 +640,7 @@ public class PlotAPI {
* @see MainUtil#getPlotAbs(com.intellectualcrafters.plot.object.Location) * @see MainUtil#getPlotAbs(com.intellectualcrafters.plot.object.Location)
*/ */
public boolean isInPlot(final Player player) { public boolean isInPlot(final Player player) {
return MainUtil.getPlotAbs(BukkitUtil.getLocation(player)) != null; return getPlot(player) != null;
} }
/** /**
@ -649,7 +680,10 @@ public class PlotAPI {
* @see MainUtil#getPlayerPlotCount(String, PlotPlayer) * @see MainUtil#getPlayerPlotCount(String, PlotPlayer)
*/ */
public int getPlayerPlotCount(final World world, final Player player) { public int getPlayerPlotCount(final World world, final Player player) {
return MainUtil.getPlayerPlotCount(world.getName(), BukkitUtil.getPlayer(player)); if (world == null) {
return 0;
}
return BukkitUtil.getPlayer(player).getPlotCount(world.getName());
} }
/** /**
@ -665,7 +699,10 @@ public class PlotAPI {
* @see Plot * @see Plot
*/ */
public Set<Plot> getPlayerPlots(final World world, final Player player) { public Set<Plot> getPlayerPlots(final World world, final Player player) {
return PS.get().getPlots(world.getName(), BukkitUtil.getPlayer(player)); if (world == null) {
return new HashSet<>();
}
return BukkitUtil.getPlayer(player).getPlots(world.getName());
} }
/** /**
@ -678,7 +715,7 @@ public class PlotAPI {
*/ */
public int getAllowedPlots(final Player player) { public int getAllowedPlots(final Player player) {
final PlotPlayer pp = BukkitUtil.getPlayer(player); final PlotPlayer pp = BukkitUtil.getPlayer(player);
return MainUtil.getAllowedPlots(pp); return pp.getAllowedPlots();
} }
/** /**

View File

@ -20,6 +20,8 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.UUID;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
@ -32,8 +34,6 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.Argument; import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
import java.util.UUID;
@CommandDeclaration( @CommandDeclaration(
command = "add", command = "add",
aliases = { "a" }, aliases = { "a" },
@ -51,7 +51,7 @@ public class Add extends SubCommand {
@Override @Override
public boolean onCommand(final PlotPlayer plr, final String[] args) { public boolean onCommand(final PlotPlayer plr, final String[] args) {
final Location loc = plr.getLocation(); final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlotAbs(loc); final Plot plot = loc.getPlotAbs();
if (plot == null) { if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT); return !sendMessage(plr, C.NOT_IN_PLOT);
} }
@ -86,7 +86,7 @@ public class Add extends SubCommand {
if (plot.removeTrusted(uuid)) { if (plot.removeTrusted(uuid)) {
plot.addMember(uuid); plot.addMember(uuid);
} else { } else {
if ((plot.getMembers().size() + plot.getTrusted().size()) >= plot.getWorld().MAX_PLOT_MEMBERS) { if ((plot.getMembers().size() + plot.getTrusted().size()) >= plot.getArea().MAX_PLOT_MEMBERS) {
MainUtil.sendMessage(plr, C.PLOT_MAX_MEMBERS); MainUtil.sendMessage(plr, C.PLOT_MAX_MEMBERS);
return false; return false;
} }

View File

@ -54,13 +54,13 @@ public class Alias extends SetCommand {
C.NOT_VALID_VALUE.send(plr); C.NOT_VALID_VALUE.send(plr);
return false; return false;
} }
for (final Plot p : PS.get().getPlotsInWorld(plr.getLocation().getWorld())) { for (final Plot p : PS.get().getPlots(plot.area)) {
if (p.getAlias().equalsIgnoreCase(alias)) { if (p.getAlias().equalsIgnoreCase(alias)) {
MainUtil.sendMessage(plr, C.ALIAS_IS_TAKEN); MainUtil.sendMessage(plr, C.ALIAS_IS_TAKEN);
return false; return false;
} }
} }
if (UUIDHandler.nameExists(new StringWrapper(alias)) || PS.get().isPlotWorld(alias)) { if (UUIDHandler.nameExists(new StringWrapper(alias)) || PS.get().hasPlotArea(alias)) {
MainUtil.sendMessage(plr, C.ALIAS_IS_TAKEN); MainUtil.sendMessage(plr, C.ALIAS_IS_TAKEN);
return false; return false;
} }

View File

@ -20,15 +20,12 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.ByteArrayUtilities; import com.intellectualcrafters.plot.util.ByteArrayUtilities;
import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
@ -42,10 +39,10 @@ category = CommandCategory.CLAIMING,
requiredType = RequiredType.NONE, requiredType = RequiredType.NONE,
description = "Claim the nearest plot", description = "Claim the nearest plot",
aliases = { "a" }, aliases = { "a" },
usage = "/plot auto") usage = "/plot auto [length,width]")
public class Auto extends SubCommand { public class Auto extends SubCommand {
public static PlotId getNextPlot(final PlotId id, final int step) { public static PlotId getNextPlotId(final PlotId id, final int step) {
final int absX = Math.abs(id.x); final int absX = Math.abs(id.x);
final int absY = Math.abs(id.y); final int absY = Math.abs(id.y);
if (absX > absY) { if (absX > absY) {
@ -76,32 +73,23 @@ public class Auto extends SubCommand {
@Override @Override
public boolean onCommand(final PlotPlayer plr, final String[] args) { public boolean onCommand(final PlotPlayer plr, final String[] args) {
PlotArea plotarea = plr.getApplicablePlotArea();
String world; if (plotarea == null) {
MainUtil.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
return false;
}
int size_x = 1; int size_x = 1;
int size_z = 1; int size_z = 1;
String schematic = ""; String schematic = null;
if (PS.get().getPlotWorlds().size() == 1) {
world = PS.get().getPlotWorlds().iterator().next();
} else {
world = plr.getLocation().getWorld();
if (!PS.get().isPlotWorld(world)) {
MainUtil.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
return false;
}
}
if (args.length > 0) { if (args.length > 0) {
if (Permissions.hasPermission(plr, "plots.auto.mega")) { if (Permissions.hasPermission(plr, "plots.auto.mega")) {
try { try {
final String[] split = args[0].split(","); final String[] split = args[0].split(",|;");
size_x = Integer.parseInt(split[0]); size_x = Integer.parseInt(split[0]);
size_z = Integer.parseInt(split[1]); size_z = Integer.parseInt(split[1]);
if ((size_x < 1) || (size_z < 1)) { if ((size_x < 1) || (size_z < 1)) {
MainUtil.sendMessage(plr, "&cError: size<=0"); MainUtil.sendMessage(plr, "&cError: size<=0");
} }
if ((size_x > 4) || (size_z > 4)) {
MainUtil.sendMessage(plr, "&cError: size>4");
}
if (args.length > 1) { if (args.length > 1) {
schematic = args[1]; schematic = args[1];
} }
@ -123,11 +111,9 @@ public class Auto extends SubCommand {
MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, Settings.MAX_AUTO_SIZE + ""); MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, Settings.MAX_AUTO_SIZE + "");
return false; return false;
} }
int removeGrants = 0; int removeGrants = 0;
final int currentPlots = Settings.GLOBAL_LIMIT ? plr.getPlotCount() : plr.getPlotCount(plotarea.worldname);
final int currentPlots = Settings.GLOBAL_LIMIT ? MainUtil.getPlayerPlotCount(plr) : MainUtil.getPlayerPlotCount(world, plr); final int diff = currentPlots - plr.getAllowedPlots();
final int diff = currentPlots - MainUtil.getAllowedPlots(plr);
if ((diff + (size_x * size_z)) > 0) { if ((diff + (size_x * size_z)) > 0) {
if (diff < 0) { if (diff < 0) {
MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, (-diff) + ""); MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, (-diff) + "");
@ -148,9 +134,8 @@ public class Auto extends SubCommand {
return false; return false;
} }
} }
final PlotWorld pWorld = PS.get().getPlotWorld(world); if ((EconHandler.manager != null) && plotarea.USE_ECONOMY) {
if ((EconHandler.manager != null) && pWorld.USE_ECONOMY) { double cost = plotarea.PLOT_PRICE;
double cost = pWorld.PLOT_PRICE;
cost = (size_x * size_z) * cost; cost = (size_x * size_z) * cost;
if (cost > 0d) { if (cost > 0d) {
if (EconHandler.manager.getMoney(plr) < cost) { if (EconHandler.manager.getMoney(plr) < cost) {
@ -166,9 +151,8 @@ public class Auto extends SubCommand {
plr.setPersistentMeta("grantedPlots", ByteArrayUtilities.integerToBytes(grantedPlots - removeGrants)); plr.setPersistentMeta("grantedPlots", ByteArrayUtilities.integerToBytes(grantedPlots - removeGrants));
sendMessage(plr, C.REMOVED_GRANTED_PLOT, "" + removeGrants, "" + (grantedPlots - removeGrants)); sendMessage(plr, C.REMOVED_GRANTED_PLOT, "" + removeGrants, "" + (grantedPlots - removeGrants));
} }
if (!schematic.equals("")) { if (schematic != null && !schematic.equals("")) {
// if (pWorld.SCHEMATIC_CLAIM_SPECIFY) { if (!plotarea.SCHEMATICS.contains(schematic.toLowerCase())) {
if (!pWorld.SCHEMATICS.contains(schematic.toLowerCase())) {
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: " + schematic); sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: " + schematic);
return true; return true;
} }
@ -176,24 +160,10 @@ public class Auto extends SubCommand {
MainUtil.sendMessage(plr, C.NO_SCHEMATIC_PERMISSION, schematic); MainUtil.sendMessage(plr, C.NO_SCHEMATIC_PERMISSION, schematic);
return true; return true;
} }
// }
} }
final String worldname = world; if (plotarea.TYPE == 2) {
final PlotWorld plotworld = PS.get().getPlotWorld(worldname); final PlotId bot = plotarea.getMin();
if (plotworld.TYPE == 2) { final PlotId top = plotarea.getMax();
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlotAbs(new Location(worldname, loc.getX(), loc.getY(), loc.getZ()));
if (plot == null) {
return sendMessage(plr, C.NOT_IN_PLOT);
}
final PlotCluster cluster = plot.getCluster();
// Must be standing in a cluster
if (cluster == null) {
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
return false;
}
final PlotId bot = cluster.getP1();
final PlotId top = cluster.getP2();
final PlotId origin = new PlotId((bot.x + top.x) / 2, (bot.y + top.y) / 2); final PlotId origin = new PlotId((bot.x + top.x) / 2, (bot.y + top.y) / 2);
PlotId id = new PlotId(0, 0); PlotId id = new PlotId(0, 0);
final int width = Math.max((top.x - bot.x) + 1, (top.y - bot.y) + 1); final int width = Math.max((top.x - bot.x) + 1, (top.y - bot.y) + 1);
@ -201,12 +171,12 @@ public class Auto extends SubCommand {
// //
for (int i = 0; i <= max; i++) { for (int i = 0; i <= max; i++) {
final PlotId currentId = new PlotId(origin.x + id.x, origin.y + id.y); final PlotId currentId = new PlotId(origin.x + id.x, origin.y + id.y);
final Plot current = MainUtil.getPlotAbs(worldname, currentId); Plot current = plotarea.getPlotAbs(currentId);
if (MainUtil.canClaim(plr, current) && (current.isMerged() == false) && cluster.equals(current.getCluster())) { if (current.canClaim(plr)) {
Claim.claimPlot(plr, current, true, true); Claim.claimPlot(plr, current, true, true);
return true; return true;
} }
id = getNextPlot(id, 1); id = getNextPlotId(id, 1);
} }
// no free plots // no free plots
MainUtil.sendMessage(plr, C.NO_FREE_PLOTS); MainUtil.sendMessage(plr, C.NO_FREE_PLOTS);
@ -215,45 +185,44 @@ public class Auto extends SubCommand {
boolean br = false; boolean br = false;
if ((size_x == 1) && (size_z == 1)) { if ((size_x == 1) && (size_z == 1)) {
while (!br) { while (!br) {
final Plot plot = MainUtil.getPlotAbs(worldname, getLastPlot(worldname)); Plot plot = plotarea.getPlotAbs(getLastPlotId(plotarea));
if (MainUtil.canClaim(plr, plot)) { if (plot.canClaim(plr)) {
Claim.claimPlot(plr, plot, true, true); Claim.claimPlot(plr, plot, true, true);
br = true; br = true;
} }
MainUtil.lastPlot.put(worldname, getNextPlot(getLastPlot(worldname), 1)); plotarea.setMeta("lastPlot", getNextPlotId(plot.id, 1));
} }
} else { } else {
while (!br) { while (!br) {
final PlotId start = getNextPlot(getLastPlot(worldname), 1); final PlotId start = getNextPlotId(getLastPlotId(plotarea), 1);
// Checking if the current set of plots is a viable option.
MainUtil.lastPlot.put(worldname, start);
if ((PS.get().getPlot(worldname, start) != null) && (PS.get().getPlot(worldname, start).owner != null)) {
continue;
}
final PlotId end = new PlotId((start.x + size_x) - 1, (start.y + size_z) - 1); final PlotId end = new PlotId((start.x + size_x) - 1, (start.y + size_z) - 1);
if (MainUtil.canClaim(plr, worldname, start, end)) { plotarea.setMeta("lastPlot", start);
if (plotarea.canClaim(plr, start, end)) {
for (int i = start.x; i <= end.x; i++) { for (int i = start.x; i <= end.x; i++) {
for (int j = start.y; j <= end.y; j++) { for (int j = start.y; j <= end.y; j++) {
final Plot plot = MainUtil.getPlotAbs(worldname, new PlotId(i, j)); Plot plot = plotarea.getPlotAbs(new PlotId(i, j));
final boolean teleport = ((i == end.x) && (j == end.y)); final boolean teleport = ((i == end.x) && (j == end.y));
Claim.claimPlot(plr, plot, teleport, true); Claim.claimPlot(plr, plot, teleport, true);
} }
} }
if (!MainUtil.mergePlots(worldname, MainUtil.getPlotSelectionIds(start, end), true, true)) { if (!plotarea.mergePlots(MainUtil.getPlotSelectionIds(start, end), Settings.MERGE_REMOVES_ROADS, true)) {
return false; return false;
} }
br = true; br = true;
} }
} }
} }
MainUtil.lastPlot.put(worldname, new PlotId(0, 0)); plotarea.setMeta("lastPlot", new PlotId(0, 0));
return true; return true;
} }
public PlotId getLastPlot(final String world) { public PlotId getLastPlotId(final PlotArea area) {
if ((MainUtil.lastPlot == null) || !MainUtil.lastPlot.containsKey(world)) { PlotId value = (PlotId) area.getMeta("lastPlot");
MainUtil.lastPlot.put(world, new PlotId(0, 0)); if (value == null) {
value = new PlotId(0, 0);
area.setMeta("lastPlot", value);
return value;
} }
return MainUtil.lastPlot.get(world); return value;
} }
} }

View File

@ -40,7 +40,7 @@ public class BO3 extends SubCommand {
@Override @Override
public boolean onCommand(final PlotPlayer plr, final String[] args) { public boolean onCommand(final PlotPlayer plr, final String[] args) {
final Location loc = plr.getLocation(); final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlotAbs(loc); final Plot plot = loc.getPlotAbs();
if ((plot == null) || !plot.hasOwner()) { if ((plot == null) || !plot.hasOwner()) {
return !sendMessage(plr, C.NOT_IN_PLOT); return !sendMessage(plr, C.NOT_IN_PLOT);
} }

View File

@ -23,9 +23,9 @@ package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.WorldUtil;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration( @CommandDeclaration(
@ -40,9 +40,9 @@ public class Biome extends SetCommand {
@Override @Override
public boolean set(final PlotPlayer plr, final Plot plot, final String value) { public boolean set(final PlotPlayer plr, final Plot plot, final String value) {
final int biome = BlockManager.manager.getBiomeFromString(value); final int biome = WorldUtil.IMP.getBiomeFromString(value);
if (biome == -1) { if (biome == -1) {
String biomes = StringMan.join(BlockManager.manager.getBiomeList(), C.BLOCK_LIST_SEPARATER.s()); String biomes = StringMan.join(WorldUtil.IMP.getBiomeList(), C.BLOCK_LIST_SEPARATER.s());
C.NEED_BIOME.send(plr); C.NEED_BIOME.send(plr);
MainUtil.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + biomes); MainUtil.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + biomes);
return false; return false;

View File

@ -20,21 +20,20 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.Set;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
import java.util.Set;
@CommandDeclaration( @CommandDeclaration(
command = "buy", command = "buy",
aliases = { "b" }, aliases = { "b" },
@ -52,23 +51,24 @@ public class Buy extends SubCommand {
} }
final Location loc = plr.getLocation(); final Location loc = plr.getLocation();
final String world = loc.getWorld(); final String world = loc.getWorld();
if (!PS.get().isPlotWorld(world)) { if (!PS.get().hasPlotArea(world)) {
return sendMessage(plr, C.NOT_IN_PLOT_WORLD); return sendMessage(plr, C.NOT_IN_PLOT_WORLD);
} }
Set<Plot> plots; Set<Plot> plots;
Plot plot; Plot plot;
if (args.length > 0) { if (args.length > 0) {
try { try {
final String[] split = args[0].split(";"); plot = MainUtil.getPlotFromString(plr, world, true);
final PlotId id = new PlotId(Integer.parseInt(split[0]), Integer.parseInt(split[1])); if (plot == null) {
plot = MainUtil.getPlotAbs(world, id); return false;
plots = MainUtil.getConnectedPlots(plot); }
plots = plot.getConnectedPlots();
} catch (final Exception e) { } catch (final Exception e) {
return sendMessage(plr, C.NOT_VALID_PLOT_ID); return sendMessage(plr, C.NOT_VALID_PLOT_ID);
} }
} else { } else {
plot = MainUtil.getPlotAbs(loc); plot = loc.getPlotAbs();
plots = MainUtil.getConnectedPlots(plot); plots = plot.getConnectedPlots();
} }
if (plots == null) { if (plots == null) {
return sendMessage(plr, C.NOT_IN_PLOT); return sendMessage(plr, C.NOT_IN_PLOT);
@ -76,8 +76,8 @@ public class Buy extends SubCommand {
if (!plot.hasOwner()) { if (!plot.hasOwner()) {
return sendMessage(plr, C.PLOT_UNOWNED); return sendMessage(plr, C.PLOT_UNOWNED);
} }
final int currentPlots = MainUtil.getPlayerPlotCount(plr) + plots.size(); final int currentPlots = plr.getPlotCount() + plots.size();
if (currentPlots > MainUtil.getAllowedPlots(plr)) { if (currentPlots > plr.getAllowedPlots()) {
return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS); return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
} }
final Flag flag = FlagManager.getPlotFlagRaw(plot, "price"); final Flag flag = FlagManager.getPlotFlagRaw(plot, "price");

View File

@ -20,15 +20,19 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.*; import com.intellectualcrafters.plot.util.ByteArrayUtilities;
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; import com.intellectualcrafters.plot.util.SchematicHandler.Schematic;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
@ -52,16 +56,13 @@ public class Claim extends SubCommand {
} }
final boolean result = EventUtil.manager.callClaim(player, plot, false); final boolean result = EventUtil.manager.callClaim(player, plot, false);
if (result) { if (result) {
MainUtil.createPlot(player.getUUID(), plot); plot.create(player.getUUID(), true);
MainUtil.setSign(player.getName(), plot); plot.setSign(player.getName());
MainUtil.sendMessage(player, C.CLAIMED); MainUtil.sendMessage(player, C.CLAIMED);
final Location loc = player.getLocation();
if (teleport) { if (teleport) {
MainUtil.teleportPlayer(player, loc, plot); plot.teleportPlayer(player);
} }
final String world = plot.world; final PlotArea plotworld = plot.getArea();
final PlotWorld plotworld = plot.getWorld();
final Plot plot2 = PS.get().getPlot(world, plot.getId());
if (plotworld.SCHEMATIC_ON_CLAIM) { if (plotworld.SCHEMATIC_ON_CLAIM) {
Schematic sch; Schematic sch;
if (schematic.isEmpty()) { if (schematic.isEmpty()) {
@ -72,9 +73,9 @@ public class Claim extends SubCommand {
sch = SchematicHandler.manager.getSchematic(plotworld.SCHEMATIC_FILE); sch = SchematicHandler.manager.getSchematic(plotworld.SCHEMATIC_FILE);
} }
} }
SchematicHandler.manager.paste(sch, plot2, 0, 0, new RunnableVal<Boolean>() { SchematicHandler.manager.paste(sch, plot, 0, 0, new RunnableVal<Boolean>() {
@Override @Override
public void run() { public void run(Boolean value) {
if (value) { if (value) {
MainUtil.sendMessage(player, C.SCHEMATIC_PASTE_SUCCESS); MainUtil.sendMessage(player, C.SCHEMATIC_PASTE_SUCCESS);
} else { } else {
@ -83,7 +84,7 @@ public class Claim extends SubCommand {
} }
}); });
} }
PS.get().getPlotManager(world).claimPlot(plotworld, plot); plotworld.getPlotManager().claimPlot(plotworld, plot);
} }
return result; return result;
} }
@ -95,15 +96,13 @@ public class Claim extends SubCommand {
schematic = args[0]; schematic = args[0];
} }
final Location loc = plr.getLocation(); final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlotAbs(loc); final Plot plot = loc.getPlotAbs();
if (plot == null) { if (plot == null) {
return sendMessage(plr, C.NOT_IN_PLOT); return sendMessage(plr, C.NOT_IN_PLOT);
} }
final int currentPlots = Settings.GLOBAL_LIMIT ? MainUtil.getPlayerPlotCount(plr) : MainUtil.getPlayerPlotCount(loc.getWorld(), plr); final int currentPlots = Settings.GLOBAL_LIMIT ? plr.getPlotCount() : plr.getPlotCount(loc.getWorld());
boolean removeGrantedPlot = false; boolean removeGrantedPlot = false;
if (currentPlots >= plr.getAllowedPlots()) {
if (currentPlots >= MainUtil.getAllowedPlots(plr)) {
if (plr.hasPersistentMeta("grantedPlots")) { if (plr.hasPersistentMeta("grantedPlots")) {
int grantedPlots = ByteArrayUtilities.bytesToInteger(plr.getPersistentMeta("grantedPlots")); int grantedPlots = ByteArrayUtilities.bytesToInteger(plr.getPersistentMeta("grantedPlots"));
if (grantedPlots < 1) { if (grantedPlots < 1) {
@ -116,10 +115,10 @@ public class Claim extends SubCommand {
return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS); return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
} }
} }
if (!MainUtil.canClaim(plr, plot)) { if (!plot.canClaim(plr)) {
return sendMessage(plr, C.PLOT_IS_CLAIMED); return sendMessage(plr, C.PLOT_IS_CLAIMED);
} }
final PlotWorld world = plot.getWorld(); final PlotArea world = plot.getArea();
if ((EconHandler.manager != null) && world.USE_ECONOMY) { if ((EconHandler.manager != null) && world.USE_ECONOMY) {
final double cost = world.PLOT_PRICE; final double cost = world.PLOT_PRICE;
if (cost > 0d) { if (cost > 0d) {

View File

@ -31,7 +31,7 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.CmdConfirm; import com.intellectualcrafters.plot.util.CmdConfirm;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.SetBlockQueue; import com.intellectualcrafters.plot.util.SetQueue;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
@ -59,7 +59,7 @@ public class Clear extends SubCommand {
return false; return false;
} }
} else if (args.length == 0) { } else if (args.length == 0) {
plot = MainUtil.getPlotAbs(loc); plot = loc.getPlotAbs();
if (plot == null) { if (plot == null) {
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot clear [X;Z|mine]"); MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot clear [X;Z|mine]");
C.NOT_IN_PLOT.send(plr); C.NOT_IN_PLOT.send(plr);
@ -77,7 +77,7 @@ public class Clear extends SubCommand {
return false; return false;
} }
if ((FlagManager.getPlotFlagRaw(plot, "done") != null) if ((FlagManager.getPlotFlagRaw(plot, "done") != null)
&& (!Permissions.hasPermission(plr, "plots.continue") || (Settings.DONE_COUNTS_TOWARDS_LIMIT && (MainUtil.getAllowedPlots(plr) >= MainUtil.getPlayerPlotCount(plr))))) { && (!Permissions.hasPermission(plr, "plots.continue") || (Settings.DONE_COUNTS_TOWARDS_LIMIT && (plr.getAllowedPlots() >= plr.getPlotCount())))) {
MainUtil.sendMessage(plr, C.DONE_ALREADY_DONE); MainUtil.sendMessage(plr, C.DONE_ALREADY_DONE);
return false; return false;
} }
@ -85,11 +85,11 @@ public class Clear extends SubCommand {
@Override @Override
public void run() { public void run() {
final long start = System.currentTimeMillis(); final long start = System.currentTimeMillis();
final boolean result = MainUtil.clearAsPlayer(plot, plot.owner == null, new Runnable() { final boolean result = plot.clear(true, false, new Runnable() {
@Override @Override
public void run() { public void run() {
plot.unlink(); plot.unlink();
SetBlockQueue.addNotify(new Runnable() { SetQueue.IMP.addTask(new Runnable() {
@Override @Override
public void run() { public void run() {
plot.removeRunning(); plot.removeRunning();

View File

@ -31,20 +31,15 @@ import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.generator.PlotGenerator;
import com.intellectualcrafters.plot.object.BlockLoc; import com.intellectualcrafters.plot.object.BlockLoc;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotClusterId;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.ClusterManager;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.SetupUtils;
import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
//import com.plotsquared.bukkit.generator.AugmentedPopulator; //import com.plotsquared.bukkit.generator.AugmentedPopulator;
//import com.plotsquared.bukkit.generator.AugmentedPopulator; //import com.plotsquared.bukkit.generator.AugmentedPopulator;
@ -82,7 +77,8 @@ public class Cluster extends SubCommand {
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster list"); MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster list");
return false; return false;
} }
final HashSet<PlotCluster> clusters = ClusterManager.getClusters(plr.getLocation().getWorld()); PlotArea area = plr.getApplicablePlotArea();
final Set<PlotCluster> clusters = area.getClusters();
MainUtil.sendMessage(plr, C.CLUSTER_LIST_HEADING, clusters.size() + ""); MainUtil.sendMessage(plr, C.CLUSTER_LIST_HEADING, clusters.size() + "");
for (final PlotCluster cluster : clusters) { for (final PlotCluster cluster : clusters) {
// Ignore unmanaged clusters // Ignore unmanaged clusters
@ -105,10 +101,13 @@ public class Cluster extends SubCommand {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.create"); MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.create");
return false; return false;
} }
PlotArea area = plr.getApplicablePlotArea();
if (area == null) {
C.NOT_IN_PLOT_WORLD.send(plr);
return false;
}
if (args.length != 4) { if (args.length != 4) {
final PlotId id = ClusterManager.estimatePlotId(plr.getLocation());
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster create <name> <id-bot> <id-top>"); MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster create <name> <id-bot> <id-top>");
MainUtil.sendMessage(plr, C.CLUSTER_CURRENT_PLOTID, "" + id);
return false; return false;
} }
// check pos1 / pos2 // check pos1 / pos2
@ -120,11 +119,9 @@ public class Cluster extends SubCommand {
} }
// check if name is taken // check if name is taken
final String name = args[1]; final String name = args[1];
for (final PlotCluster cluster : ClusterManager.getClusters(plr.getLocation().getWorld())) { if (area.getCluster(name) != null) {
if (name.equals(cluster.getName())) { MainUtil.sendMessage(plr, C.ALIAS_IS_TAKEN);
MainUtil.sendMessage(plr, C.ALIAS_IS_TAKEN); return false;
return false;
}
} }
if ((pos2.x < pos1.x) || (pos2.y < pos1.y)) { if ((pos2.x < pos1.x) || (pos2.y < pos1.y)) {
PlotId tmp = new PlotId(Math.min(pos1.x, pos2.x), Math.min(pos1.y, pos2.y)); PlotId tmp = new PlotId(Math.min(pos1.x, pos2.x), Math.min(pos1.y, pos2.y));
@ -132,15 +129,13 @@ public class Cluster extends SubCommand {
pos1 = tmp; pos1 = tmp;
} }
//check if overlap //check if overlap
final String world = plr.getLocation().getWorld(); PlotCluster cluster = area.getFirstIntersectingCluster(pos1, pos2);
final PlotClusterId id = new PlotClusterId(pos1, pos2); if (cluster != null) {
final HashSet<PlotCluster> intersects = ClusterManager.getIntersects(world, id); MainUtil.sendMessage(plr, C.CLUSTER_INTERSECTION, cluster.getName());
if ((intersects.size() > 0)) {
MainUtil.sendMessage(plr, C.CLUSTER_INTERSECTION, intersects.size() + "");
return false; return false;
} }
// Check if it occupies existing plots // Check if it occupies existing plots
final Set<Plot> plots = MainUtil.getPlotSelectionOwned(world, pos1, pos2); final Set<Plot> plots = area.getPlotSelectionOwned(pos1, pos2);
if (plots.size() > 0) { if (plots.size() > 0) {
if (!Permissions.hasPermission(plr, "plots.cluster.create.other")) { if (!Permissions.hasPermission(plr, "plots.cluster.create.other")) {
final UUID uuid = plr.getUUID(); final UUID uuid = plr.getUUID();
@ -153,57 +148,22 @@ public class Cluster extends SubCommand {
} }
} }
// Check allowed cluster size // Check allowed cluster size
final PlotCluster cluster = new PlotCluster(world, pos1, pos2, plr.getUUID()); cluster = new PlotCluster(area, pos1, pos2, plr.getUUID());
int current; int current;
if (Settings.GLOBAL_LIMIT) { if (Settings.GLOBAL_LIMIT) {
current = ClusterManager.getPlayerClusterCount(plr); current = plr.getPlayerClusterCount();
} else { } else {
current = ClusterManager.getPlayerClusterCount(world, plr); current = plr.getPlayerClusterCount(plr.getLocation().getWorld());
} }
final int allowed = Permissions.hasPermissionRange(plr, "plots.cluster", Settings.MAX_PLOTS); final int allowed = Permissions.hasPermissionRange(plr, "plots.cluster", Settings.MAX_PLOTS);
if ((current + cluster.getArea()) > allowed) { if ((current + cluster.getArea()) > allowed) {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster." + (current + cluster.getArea())); MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster." + (current + cluster.getArea()));
return false; return false;
} }
// Set the generator (if applicable)
final PlotWorld plotworld = PS.get().getPlotWorld(world);
if (plotworld == null) {
PS.get().config.createSection("worlds." + world);
PS.get().loadWorld(world, PS.get().IMP.getGenerator(world, null));
} else {
String gen_string = PS.get().config.getString("worlds." + world + "." + "generator.plugin");
if (gen_string == null) {
gen_string = "PlotSquared";
}
final PlotGenerator<?> wrapper = PS.get().IMP.getGenerator(world, gen_string);
if (wrapper.isFull()) {
wrapper.augment(cluster, plotworld);
} else {
MainUtil.sendMessage(plr, C.SETUP_INVALID_GENERATOR, StringMan.join(SetupUtils.generators.keySet(), ","));
return false;
}
// BukkitPlotGenerator generator;
// if (gen_string == null) {
// generator = new HybridGen(world);
// } else {
// ChunkGenerator chunkgen = (ChunkGenerator) PS.get().IMP.getGenerator(world, gen_string).generator;
// if (chunkgen instanceof BukkitPlotGenerator) {
// generator = (BukkitPlotGenerator) chunkgen;
// }
// else {
// MainUtil.sendMessage(plr, C.SETUP_INVALID_GENERATOR, StringMan.join(SetupUtils.generators.keySet(), ","));
// return false;
// }
// }
// new AugmentedPopulator(world, generator, cluster, plotworld.TERRAIN == 2, plotworld.TERRAIN != 2);
}
// create cluster // create cluster
cluster.settings.setAlias(name); cluster.settings.setAlias(name);
DBFunc.createCluster(world, cluster); area.addCluster(cluster);
if (!ClusterManager.clusters.containsKey(world)) { DBFunc.createCluster(cluster);
ClusterManager.clusters.put(world, new HashSet<PlotCluster>());
}
ClusterManager.clusters.get(world).add(cluster);
// Add any existing plots to the current cluster // Add any existing plots to the current cluster
for (final Plot plot : plots) { for (final Plot plot : plots) {
if (plot.hasOwner()) { if (plot.hasOwner()) {
@ -211,7 +171,7 @@ public class Cluster extends SubCommand {
FlagManager.addPlotFlag(plot, flag); FlagManager.addPlotFlag(plot, flag);
if (!cluster.isAdded(plot.owner)) { if (!cluster.isAdded(plot.owner)) {
cluster.invited.add(plot.owner); cluster.invited.add(plot.owner);
DBFunc.setInvited(world, cluster, plot.owner); DBFunc.setInvited(cluster, plot.owner);
} }
} }
} }
@ -229,15 +189,20 @@ public class Cluster extends SubCommand {
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster delete [name]"); MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster delete [name]");
return false; return false;
} }
PlotArea area = plr.getApplicablePlotArea();
if (area == null) {
C.NOT_IN_PLOT_WORLD.send(plr);
return false;
}
PlotCluster cluster; PlotCluster cluster;
if (args.length == 2) { if (args.length == 2) {
cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]); cluster = area.getCluster(args[1]);
if (cluster == null) { if (cluster == null) {
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]); MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
return false; return false;
} }
} else { } else {
cluster = ClusterManager.getCluster(plr.getLocation()); cluster = area.getCluster(plr.getLocation());
if (cluster == null) { if (cluster == null) {
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER); MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
return false; return false;
@ -249,26 +214,7 @@ public class Cluster extends SubCommand {
return false; return false;
} }
} }
final PlotWorld plotworld = plr.getLocation().getPlotWorld();
if (plotworld.TYPE == 2) {
final ArrayList<Plot> toRemove = new ArrayList<>();
for (final Plot plot : PS.get().getPlotsInWorld(plr.getLocation().getWorld())) {
final PlotCluster other = ClusterManager.getCluster(plot);
if (cluster.equals(other)) {
toRemove.add(plot);
}
}
for (final Plot plot : toRemove) {
plot.unclaim();
}
}
DBFunc.delete(cluster); DBFunc.delete(cluster);
if (plotworld.TYPE == 2) {
SetupUtils.manager.removePopulator(plr.getLocation().getWorld(), cluster);
}
ClusterManager.last = null;
ClusterManager.clusters.get(cluster.world).remove(cluster);
ClusterManager.regenCluster(cluster);
MainUtil.sendMessage(plr, C.CLUSTER_DELETED); MainUtil.sendMessage(plr, C.CLUSTER_DELETED);
return true; return true;
} }
@ -294,9 +240,12 @@ public class Cluster extends SubCommand {
pos2 = new PlotId(Math.max(pos1.x, pos2.x), Math.max(pos1.y, pos2.y)); pos2 = new PlotId(Math.max(pos1.x, pos2.x), Math.max(pos1.y, pos2.y));
} }
// check if in cluster // check if in cluster
final Location loc = plr.getLocation(); PlotArea area = plr.getApplicablePlotArea();
final String world = loc.getWorld(); if (area == null) {
final PlotCluster cluster = ClusterManager.getCluster(loc); C.NOT_IN_PLOT_WORLD.send(plr);
return false;
}
final PlotCluster cluster = area.getCluster(plr.getLocation());
if (cluster == null) { if (cluster == null) {
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER); MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
return false; return false;
@ -308,14 +257,13 @@ public class Cluster extends SubCommand {
} }
} }
//check if overlap //check if overlap
final PlotClusterId id = new PlotClusterId(pos1, pos2); PlotCluster intersect = area.getFirstIntersectingCluster(pos1, pos2);
final HashSet<PlotCluster> intersects = ClusterManager.getIntersects(world, id); if (intersect != null) {
if (intersects.size() > 1) { MainUtil.sendMessage(plr, C.CLUSTER_INTERSECTION, intersect.getName());
MainUtil.sendMessage(plr, C.CLUSTER_INTERSECTION, (intersects.size() - 1) + "");
return false; return false;
} }
final HashSet<Plot> existing = MainUtil.getPlotSelectionOwned(world, cluster.getP1(), cluster.getP2()); final HashSet<Plot> existing = area.getPlotSelectionOwned(cluster.getP1(), cluster.getP2());
final HashSet<Plot> newplots = MainUtil.getPlotSelectionOwned(world, pos1, pos2); final HashSet<Plot> newplots = area.getPlotSelectionOwned(pos1, pos2);
final HashSet<Plot> removed = ((HashSet<Plot>) existing.clone()); final HashSet<Plot> removed = ((HashSet<Plot>) existing.clone());
removed.removeAll(newplots); removed.removeAll(newplots);
// Check expand / shrink // Check expand / shrink
@ -335,9 +283,9 @@ public class Cluster extends SubCommand {
// Check allowed cluster size // Check allowed cluster size
int current; int current;
if (Settings.GLOBAL_LIMIT) { if (Settings.GLOBAL_LIMIT) {
current = ClusterManager.getPlayerClusterCount(plr); current = plr.getPlayerClusterCount();
} else { } else {
current = ClusterManager.getPlayerClusterCount(world, plr); current = plr.getPlayerClusterCount(plr.getLocation().getWorld());
} }
current -= cluster.getArea() + (((1 + pos2.x) - pos1.x) * ((1 + pos2.y) - pos1.y)); current -= cluster.getArea() + (((1 + pos2.x) - pos1.x) * ((1 + pos2.y) - pos1.y));
final int allowed = Permissions.hasPermissionRange(plr, "plots.cluster", Settings.MAX_PLOTS); final int allowed = Permissions.hasPermissionRange(plr, "plots.cluster", Settings.MAX_PLOTS);
@ -352,46 +300,10 @@ public class Cluster extends SubCommand {
FlagManager.addPlotFlag(plot, new Flag(FlagManager.getFlag("cluster"), cluster)); FlagManager.addPlotFlag(plot, new Flag(FlagManager.getFlag("cluster"), cluster));
} }
// resize cluster // resize cluster
DBFunc.resizeCluster(cluster, id); DBFunc.resizeCluster(cluster, pos1, pos2);
MainUtil.sendMessage(plr, C.CLUSTER_RESIZED); MainUtil.sendMessage(plr, C.CLUSTER_RESIZED);
return true; return true;
} }
case "reg":
case "regenerate":
case "regen": {
if (!Permissions.hasPermission(plr, "plots.cluster.delete")) {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.regen");
return false;
}
if ((args.length != 1) && (args.length != 2)) {
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster regen [name]");
return false;
}
PlotCluster cluster;
if (args.length == 2) {
cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
if (cluster == null) {
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
return false;
}
} else {
cluster = ClusterManager.getCluster(plr.getLocation());
if (cluster == null) {
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
return false;
}
}
if (!cluster.owner.equals(plr.getUUID())) {
if (!Permissions.hasPermission(plr, "plots.cluster.regen.other")) {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.regen.other");
return false;
}
}
final long start = System.currentTimeMillis();
ClusterManager.regenCluster(cluster);
MainUtil.sendMessage(plr, C.CLUSTER_REGENERATED, (System.currentTimeMillis() - start) + "");
return true;
}
case "add": case "add":
case "inv": case "inv":
case "invite": { case "invite": {
@ -404,7 +316,11 @@ public class Cluster extends SubCommand {
return false; return false;
} }
// check if in cluster // check if in cluster
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation()); PlotArea area = plr.getApplicablePlotArea();
if (area == null) {
C.NOT_IN_PLOT_WORLD.send(plr);
}
final PlotCluster cluster = area.getCluster(plr.getLocation());
if (cluster == null) { if (cluster == null) {
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER); MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
return false; return false;
@ -425,7 +341,7 @@ public class Cluster extends SubCommand {
// add the user if not added // add the user if not added
cluster.invited.add(uuid); cluster.invited.add(uuid);
final String world = plr.getLocation().getWorld(); final String world = plr.getLocation().getWorld();
DBFunc.setInvited(world, cluster, uuid); DBFunc.setInvited(cluster, uuid);
final PlotPlayer player = UUIDHandler.getPlayer(uuid); final PlotPlayer player = UUIDHandler.getPlayer(uuid);
if (player != null) { if (player != null) {
MainUtil.sendMessage(player, C.CLUSTER_INVITED, cluster.getName()); MainUtil.sendMessage(player, C.CLUSTER_INVITED, cluster.getName());
@ -445,7 +361,11 @@ public class Cluster extends SubCommand {
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster kick <player>"); MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster kick <player>");
return false; return false;
} }
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation()); PlotArea area = plr.getApplicablePlotArea();
if (area == null) {
C.NOT_IN_PLOT_WORLD.send(plr);
}
final PlotCluster cluster = area.getCluster(plr.getLocation());
if (cluster == null) { if (cluster == null) {
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER); MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
return false; return false;
@ -478,7 +398,7 @@ public class Cluster extends SubCommand {
MainUtil.sendMessage(player, C.CLUSTER_REMOVED, cluster.getName()); MainUtil.sendMessage(player, C.CLUSTER_REMOVED, cluster.getName());
} }
for (final Plot plot : new ArrayList<>(PS.get().getPlots(plr.getLocation().getWorld(), uuid))) { for (final Plot plot : new ArrayList<>(PS.get().getPlots(plr.getLocation().getWorld(), uuid))) {
final PlotCluster current = ClusterManager.getCluster(plot); final PlotCluster current = plot.getCluster();
if ((current != null) && current.equals(cluster)) { if ((current != null) && current.equals(cluster)) {
plr.getLocation().getWorld(); plr.getLocation().getWorld();
plot.unclaim(); plot.unclaim();
@ -497,15 +417,19 @@ public class Cluster extends SubCommand {
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster leave [name]"); MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster leave [name]");
return false; return false;
} }
PlotArea area = plr.getApplicablePlotArea();
if (area == null) {
C.NOT_IN_PLOT_WORLD.send(plr);
}
PlotCluster cluster; PlotCluster cluster;
if (args.length == 2) { if (args.length == 2) {
cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]); cluster = area.getCluster(args[1]);
if (cluster == null) { if (cluster == null) {
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]); MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
return false; return false;
} }
} else { } else {
cluster = ClusterManager.getCluster(plr.getLocation()); cluster = area.getCluster(plr.getLocation());
if (cluster == null) { if (cluster == null) {
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER); MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
return false; return false;
@ -528,7 +452,7 @@ public class Cluster extends SubCommand {
DBFunc.removeInvited(cluster, uuid); DBFunc.removeInvited(cluster, uuid);
MainUtil.sendMessage(plr, C.CLUSTER_REMOVED, cluster.getName()); MainUtil.sendMessage(plr, C.CLUSTER_REMOVED, cluster.getName());
for (final Plot plot : new ArrayList<>(PS.get().getPlots(plr.getLocation().getWorld(), uuid))) { for (final Plot plot : new ArrayList<>(PS.get().getPlots(plr.getLocation().getWorld(), uuid))) {
final PlotCluster current = ClusterManager.getCluster(plot); final PlotCluster current = plot.getCluster();
if ((current != null) && current.equals(cluster)) { if ((current != null) && current.equals(cluster)) {
plr.getLocation().getWorld(); plr.getLocation().getWorld();
plot.unclaim(); plot.unclaim();
@ -547,7 +471,11 @@ public class Cluster extends SubCommand {
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster helpers <add|remove> <player>"); MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster helpers <add|remove> <player>");
return false; return false;
} }
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation()); PlotArea area = plr.getApplicablePlotArea();
if (area == null) {
C.NOT_IN_PLOT_WORLD.send(plr);
}
final PlotCluster cluster = area.getCluster(plr.getLocation());
if (cluster == null) { if (cluster == null) {
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER); MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
return false; return false;
@ -581,7 +509,11 @@ public class Cluster extends SubCommand {
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster tp <name>"); MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster tp <name>");
return false; return false;
} }
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]); PlotArea area = plr.getApplicablePlotArea();
if (area == null) {
C.NOT_IN_PLOT_WORLD.send(plr);
}
final PlotCluster cluster = area.getCluster(args[1]);
if (cluster == null) { if (cluster == null) {
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]); MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
return false; return false;
@ -593,7 +525,7 @@ public class Cluster extends SubCommand {
return false; return false;
} }
} }
plr.teleport(ClusterManager.getHome(cluster)); plr.teleport(cluster.getHome());
return MainUtil.sendMessage(plr, C.CLUSTER_TELEPORTING); return MainUtil.sendMessage(plr, C.CLUSTER_TELEPORTING);
} }
case "i": case "i":
@ -608,15 +540,19 @@ public class Cluster extends SubCommand {
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster info [name]"); MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster info [name]");
return false; return false;
} }
PlotArea area = plr.getApplicablePlotArea();
if (area == null) {
C.NOT_IN_PLOT_WORLD.send(plr);
}
PlotCluster cluster; PlotCluster cluster;
if (args.length == 2) { if (args.length == 2) {
cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]); cluster = area.getCluster(args[1]);
if (cluster == null) { if (cluster == null) {
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]); MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
return false; return false;
} }
} else { } else {
cluster = ClusterManager.getCluster(plr.getLocation()); cluster = area.getCluster(plr.getLocation());
if (cluster == null) { if (cluster == null) {
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER); MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
return false; return false;
@ -650,7 +586,11 @@ public class Cluster extends SubCommand {
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster sethome"); MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster sethome");
return false; return false;
} }
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation()); PlotArea area = plr.getApplicablePlotArea();
if (area == null) {
C.NOT_IN_PLOT_WORLD.send(plr);
}
final PlotCluster cluster = area.getCluster(plr.getLocation());
if (cluster == null) { if (cluster == null) {
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER); MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
return false; return false;
@ -661,7 +601,7 @@ public class Cluster extends SubCommand {
return false; return false;
} }
} }
final Location base = ClusterManager.getClusterBottom(cluster); final Location base = cluster.getClusterBottom();
final Location relative = plr.getLocation().subtract(base.getX(), 0, base.getZ()); final Location relative = plr.getLocation().subtract(base.getX(), 0, base.getZ());
final BlockLoc blockloc = new BlockLoc(relative.getX(), relative.getY(), relative.getZ()); final BlockLoc blockloc = new BlockLoc(relative.getX(), relative.getY(), relative.getZ());
cluster.settings.setPosition(blockloc); cluster.settings.setPosition(blockloc);

View File

@ -50,20 +50,19 @@ public class Comment extends SubCommand {
sendMessage(player, C.COMMENT_SYNTAX, StringMan.join(CommentManager.inboxes.keySet(), "|")); sendMessage(player, C.COMMENT_SYNTAX, StringMan.join(CommentManager.inboxes.keySet(), "|"));
return false; return false;
} }
Plot plot;
final Location loc = player.getLocation(); final Location loc = player.getLocation();
final PlotId id = PlotId.fromString(args[1]); final PlotId id = PlotId.fromString(args[1]);
Plot plot = MainUtil.getPlotFromString(player, args[1], false);
int index; int index;
if (id != null) { if (plot == null) {
index = 1;
plot = loc.getPlotAbs();
} else {
if (args.length < 4) { if (args.length < 4) {
sendMessage(player, C.COMMENT_SYNTAX, StringMan.join(CommentManager.inboxes.keySet(), "|")); sendMessage(player, C.COMMENT_SYNTAX, StringMan.join(CommentManager.inboxes.keySet(), "|"));
return false; return false;
} }
index = 2; index = 2;
plot = MainUtil.getPlotAbs(loc.getWorld(), id);
} else {
index = 1;
plot = MainUtil.getPlotAbs(loc);
} }
if (!inbox.canWrite(plot, player)) { if (!inbox.canWrite(plot, player)) {
sendMessage(player, C.NO_PERM_INBOX, ""); sendMessage(player, C.NO_PERM_INBOX, "");

View File

@ -30,12 +30,13 @@ import java.util.concurrent.atomic.AtomicBoolean;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.MathMan; import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.WorldUtil;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(command = "condense", permission = "plots.admin", description = "Condense a plotworld", category = CommandCategory.DEBUG, requiredType = RequiredType.CONSOLE) @CommandDeclaration(command = "condense", permission = "plots.admin", description = "Condense a plotworld", category = CommandCategory.DEBUG, requiredType = RequiredType.CONSOLE)
@ -46,18 +47,18 @@ public class Condense extends SubCommand {
@Override @Override
public boolean onCommand(final PlotPlayer plr, final String... args) { public boolean onCommand(final PlotPlayer plr, final String... args) {
if ((args.length != 2) && (args.length != 3)) { if ((args.length != 2) && (args.length != 3)) {
MainUtil.sendMessage(plr, "/plot condense <world> <start|stop|info> [radius]"); MainUtil.sendMessage(plr, "/plot condense <area> <start|stop|info> [radius]");
return false; return false;
} }
final String worldname = args[0]; PlotArea area = PS.get().getPlotAreaByString(args[0]);
if (!BlockManager.manager.isWorld(worldname) || !PS.get().isPlotWorld(worldname)) { if (area == null || !WorldUtil.IMP.isWorld(area.worldname)) {
MainUtil.sendMessage(plr, "INVALID WORLD"); MainUtil.sendMessage(plr, "INVALID AREA");
return false; return false;
} }
switch (args[1].toLowerCase()) { switch (args[1].toLowerCase()) {
case "start": { case "start": {
if (args.length == 2) { if (args.length == 2) {
MainUtil.sendMessage(plr, "/plot condense " + worldname + " start <radius>"); MainUtil.sendMessage(plr, "/plot condense " + area.toString() + " start <radius>");
return false; return false;
} }
if (TASK) { if (TASK) {
@ -65,7 +66,7 @@ public class Condense extends SubCommand {
return false; return false;
} }
if (args.length == 2) { if (args.length == 2) {
MainUtil.sendMessage(plr, "/plot condense " + worldname + " start <radius>"); MainUtil.sendMessage(plr, "/plot condense " + area.toString() + " start <radius>");
return false; return false;
} }
if (!MathMan.isInteger(args[2])) { if (!MathMan.isInteger(args[2])) {
@ -73,7 +74,7 @@ public class Condense extends SubCommand {
return false; return false;
} }
final int radius = Integer.parseInt(args[2]); final int radius = Integer.parseInt(args[2]);
ArrayList<Plot> plots = new ArrayList<>(PS.get().getPlotsInWorld(worldname)); ArrayList<Plot> plots = new ArrayList<>(PS.get().getPlots(area));
// remove non base plots // remove non base plots
Iterator<Plot> iter = plots.iterator(); Iterator<Plot> iter = plots.iterator();
int maxSize = 0; int maxSize = 0;
@ -119,11 +120,11 @@ public class Condense extends SubCommand {
final List<PlotId> free = new ArrayList<>(); final List<PlotId> free = new ArrayList<>();
PlotId start = new PlotId(0, 0); PlotId start = new PlotId(0, 0);
while ((start.x <= minimum_radius) && (start.y <= minimum_radius)) { while ((start.x <= minimum_radius) && (start.y <= minimum_radius)) {
final Plot plot = MainUtil.getPlotAbs(worldname, start); Plot plot = area.getPlotAbs(start);
if (!plot.hasOwner()) { if (plot != null && !plot.hasOwner()) {
free.add(plot.getId()); free.add(plot.getId());
} }
start = Auto.getNextPlot(start, 1); start = Auto.getNextPlotId(start, 1);
} }
if ((free.size() == 0) || (to_move.size() == 0)) { if ((free.size() == 0) || (to_move.size() == 0)) {
MainUtil.sendMessage(plr, "NO FREE PLOTS FOUND"); MainUtil.sendMessage(plr, "NO FREE PLOTS FOUND");
@ -145,14 +146,14 @@ public class Condense extends SubCommand {
final Plot origin = allPlots.remove(0); final Plot origin = allPlots.remove(0);
int i = 0; int i = 0;
while (free.size() > i) { while (free.size() > i) {
final Plot possible = MainUtil.getPlotAbs(origin.world, free.get(i)); final Plot possible = origin.area.getPlotAbs(free.get(i));
if (possible.owner != null) { if (possible.owner != null) {
free.remove(i); free.remove(i);
continue; continue;
} }
i++; i++;
final AtomicBoolean result = new AtomicBoolean(false); final AtomicBoolean result = new AtomicBoolean(false);
result.set(MainUtil.move(origin, possible, new Runnable() { result.set(origin.move(possible, new Runnable() {
@Override @Override
public void run() { public void run() {
if (result.get()) { if (result.get()) {
@ -190,7 +191,7 @@ public class Condense extends SubCommand {
} }
case "info": { case "info": {
if (args.length == 2) { if (args.length == 2) {
MainUtil.sendMessage(plr, "/plot condense " + worldname + " info <radius>"); MainUtil.sendMessage(plr, "/plot condense " + area.toString() + " info <radius>");
return false; return false;
} }
if (!MathMan.isInteger(args[2])) { if (!MathMan.isInteger(args[2])) {
@ -198,7 +199,7 @@ public class Condense extends SubCommand {
return false; return false;
} }
final int radius = Integer.parseInt(args[2]); final int radius = Integer.parseInt(args[2]);
final Collection<Plot> plots = PS.get().getPlotsInWorld(worldname); final Collection<Plot> plots = area.getPlots();
final int size = plots.size(); final int size = plots.size();
final int minimum_radius = (int) Math.ceil((Math.sqrt(size) / 2) + 1); final int minimum_radius = (int) Math.ceil((Math.sqrt(size) / 2) + 1);
if (radius < minimum_radius) { if (radius < minimum_radius) {
@ -218,7 +219,7 @@ public class Condense extends SubCommand {
return true; return true;
} }
} }
MainUtil.sendMessage(plr, "/plot condense " + worldname + " <start|stop|info> [radius]"); MainUtil.sendMessage(plr, "/plot condense " + area.worldname + " <start|stop|info> [radius]");
return false; return false;
} }

View File

@ -41,7 +41,7 @@ public class Continue extends SubCommand {
@Override @Override
public boolean onCommand(final PlotPlayer plr, final String[] args) { public boolean onCommand(final PlotPlayer plr, final String[] args) {
final Location loc = plr.getLocation(); final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlotAbs(loc); final Plot plot = loc.getPlotAbs();
if ((plot == null) || !plot.hasOwner()) { if ((plot == null) || !plot.hasOwner()) {
return !sendMessage(plr, C.NOT_IN_PLOT); return !sendMessage(plr, C.NOT_IN_PLOT);
} }
@ -53,7 +53,7 @@ public class Continue extends SubCommand {
MainUtil.sendMessage(plr, C.DONE_NOT_DONE); MainUtil.sendMessage(plr, C.DONE_NOT_DONE);
return false; return false;
} }
if (Settings.DONE_COUNTS_TOWARDS_LIMIT && (MainUtil.getAllowedPlots(plr) >= MainUtil.getPlayerPlotCount(plr))) { if (Settings.DONE_COUNTS_TOWARDS_LIMIT && (plr.getAllowedPlots() >= plr.getPlotCount())) {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.admin.command.continue"); MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.admin.command.continue");
return false; return false;
} }

View File

@ -41,7 +41,7 @@ public class Copy extends SubCommand {
@Override @Override
public boolean onCommand(final PlotPlayer plr, final String[] args) { public boolean onCommand(final PlotPlayer plr, final String[] args) {
final Location loc = plr.getLocation(); final Location loc = plr.getLocation();
final Plot plot1 = MainUtil.getPlotAbs(loc); final Plot plot1 = loc.getPlotAbs();
if (plot1 == null) { if (plot1 == null) {
return !MainUtil.sendMessage(plr, C.NOT_IN_PLOT); return !MainUtil.sendMessage(plr, C.NOT_IN_PLOT);
} }
@ -62,11 +62,11 @@ public class Copy extends SubCommand {
C.COMMAND_SYNTAX.send(plr, getUsage()); C.COMMAND_SYNTAX.send(plr, getUsage());
return false; return false;
} }
if (!plot1.getWorld().isCompatible(plot2.getWorld())) { if (!plot1.getArea().isCompatible(plot2.getArea())) {
C.PLOTWORLD_INCOMPATIBLE.send(plr); C.PLOTWORLD_INCOMPATIBLE.send(plr);
return false; return false;
} }
if (MainUtil.copy(plot1, plot2, new Runnable() { if (plot1.copy(plot2, new Runnable() {
@Override @Override
public void run() { public void run() {
MainUtil.sendMessage(plr, C.COPY_SUCCESS); MainUtil.sendMessage(plr, C.COPY_SUCCESS);

View File

@ -42,11 +42,11 @@ public class CreateRoadSchematic extends SubCommand {
@Override @Override
public boolean onCommand(final PlotPlayer player, final String... args) { public boolean onCommand(final PlotPlayer player, final String... args) {
final Location loc = player.getLocation(); final Location loc = player.getLocation();
final Plot plot = MainUtil.getPlotAbs(loc); final Plot plot = loc.getPlotAbs();
if (plot == null) { if (plot == null) {
return sendMessage(player, C.NOT_IN_PLOT); return sendMessage(player, C.NOT_IN_PLOT);
} }
if (!(loc.getPlotWorld() instanceof HybridPlotWorld)) { if (!(loc.getPlotArea() instanceof HybridPlotWorld)) {
return sendMessage(player, C.NOT_IN_PLOT_WORLD); return sendMessage(player, C.NOT_IN_PLOT_WORLD);
} }
HybridUtils.manager.setupRoadSchematic(plot); HybridUtils.manager.setupRoadSchematic(plot);

View File

@ -1,23 +1,24 @@
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map.Entry;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.database.MySQL; import com.intellectualcrafters.plot.database.MySQL;
import com.intellectualcrafters.plot.database.SQLManager; import com.intellectualcrafters.plot.database.SQLManager;
import com.intellectualcrafters.plot.database.SQLite; import com.intellectualcrafters.plot.database.SQLite;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
@CommandDeclaration( @CommandDeclaration(
command = "database", command = "database",
aliases = { "convert" }, aliases = { "convert" },
@ -25,7 +26,7 @@ category = CommandCategory.DEBUG,
permission = "plots.database", permission = "plots.database",
description = "Convert/Backup Storage", description = "Convert/Backup Storage",
requiredType = RequiredType.CONSOLE, requiredType = RequiredType.CONSOLE,
usage = "/plots database [world] <sqlite|mysql|import>" usage = "/plots database [area] <sqlite|mysql|import>"
) )
public class Database extends SubCommand { public class Database extends SubCommand {
@ -58,15 +59,16 @@ public class Database extends SubCommand {
@Override @Override
public boolean onCommand(final PlotPlayer player, String[] args) { public boolean onCommand(final PlotPlayer player, String[] args) {
if (args.length < 1) { if (args.length < 1) {
MainUtil.sendMessage(player, "/plot database [world] <sqlite|mysql|import>"); MainUtil.sendMessage(player, "/plot database [area] <sqlite|mysql|import>");
return false; return false;
} }
ArrayList<Plot> plots; ArrayList<Plot> plots;
if (PS.get().isPlotWorld(args[0])) { PlotArea area = PS.get().getPlotAreaByString(args[0]);
plots = PS.get().sortPlotsByTemp(PS.get().getPlotsInWorld(args[0])); if (area != null) {
plots = PS.get().sortPlotsByTemp(area.getPlots());
args = Arrays.copyOfRange(args, 1, args.length); args = Arrays.copyOfRange(args, 1, args.length);
} else { } else {
plots = PS.get().sortPlotsByTemp(PS.get().getPlotsRaw()); plots = PS.get().sortPlotsByTemp(PS.get().getPlots());
} }
if (args.length < 1) { if (args.length < 1) {
MainUtil.sendMessage(player, "/plot database [world] <sqlite|mysql|import>"); MainUtil.sendMessage(player, "/plot database [world] <sqlite|mysql|import>");
@ -90,18 +92,30 @@ public class Database extends SubCommand {
MainUtil.sendMessage(player, "&6Starting..."); MainUtil.sendMessage(player, "&6Starting...");
implementation = new SQLite(file.getPath()); implementation = new SQLite(file.getPath());
final SQLManager manager = new SQLManager(implementation, (args.length == 3) ? args[2] : "", true); final SQLManager manager = new SQLManager(implementation, (args.length == 3) ? args[2] : "", true);
final ConcurrentHashMap<String, ConcurrentHashMap<PlotId, Plot>> map = manager.getPlots(); final HashMap<String, HashMap<PlotId, Plot>> map = manager.getPlots();
plots = new ArrayList<Plot>(); plots = new ArrayList<Plot>();
for (final Entry<String, ConcurrentHashMap<PlotId, Plot>> entry : map.entrySet()) { for (final Entry<String, HashMap<PlotId, Plot>> entry : map.entrySet()) {
for (final Entry<PlotId, Plot> entry2 : entry.getValue().entrySet()) { String areaname = entry.getKey();
final Plot plot = entry2.getValue(); PlotArea pa = PS.get().getPlotAreaByString(areaname);
if (PS.get().getPlot(plot.world, plot.getId()) != null) { if (pa != null) {
MainUtil.sendMessage(player, "Skipping duplicate plot: " + plot + " | id=" + plot.temp); for (final Entry<PlotId, Plot> entry2 : entry.getValue().entrySet()) {
continue; final Plot plot = entry2.getValue();
if (pa.getOwnedPlotAbs(plot.getId()) != null) {
MainUtil.sendMessage(player, "Skipping duplicate plot: " + plot + " | id=" + plot.temp);
continue;
}
PS.get().updatePlot(plot);
plots.add(entry2.getValue());
} }
PS.get().updatePlot(plot);
plots.add(entry2.getValue());
} }
else {
HashMap<PlotId, Plot> plotmap = PS.get().plots_tmp.get(areaname);
if (plotmap == null) {
plotmap = new HashMap<>();
PS.get().plots_tmp.put(areaname, plotmap);
}
plotmap.putAll(entry.getValue());
}
} }
DBFunc.createPlotsAndData(plots, new Runnable() { DBFunc.createPlotsAndData(plots, new Runnable() {
@Override @Override

View File

@ -22,7 +22,9 @@ package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
@ -49,11 +51,14 @@ public class Debug extends SubCommand {
} }
{ {
final StringBuilder worlds = new StringBuilder(""); final StringBuilder worlds = new StringBuilder("");
for (final String world : PS.get().getPlotWorlds()) { PS.get().foreachPlotArea(new RunnableVal<PlotArea>() {
worlds.append(world).append(" "); @Override
} public void run(PlotArea value) {
worlds.append(value.toString()).append(" ");
}
});
information.append(header); information.append(header);
information.append(getSection(section, "PlotWorld")); information.append(getSection(section, "PlotArea"));
information.append(getLine(line, "Plot Worlds", worlds)); information.append(getLine(line, "Plot Worlds", worlds));
information.append(getLine(line, "Owned Plots", PS.get().getPlots().size())); information.append(getLine(line, "Owned Plots", PS.get().getPlots().size()));
information.append(getSection(section, "Messages")); information.append(getSection(section, "Messages"));

View File

@ -30,16 +30,16 @@ import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.StringWrapper; import com.intellectualcrafters.plot.object.StringWrapper;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualcrafters.plot.util.WorldUtil;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration( @CommandDeclaration(
@ -57,11 +57,11 @@ public class DebugClaimTest extends SubCommand {
public static boolean claimPlot(final PlotPlayer player, final Plot plot, final boolean teleport, final String schematic) { public static boolean claimPlot(final PlotPlayer player, final Plot plot, final boolean teleport, final String schematic) {
final boolean result = EventUtil.manager.callClaim(player, plot, false); final boolean result = EventUtil.manager.callClaim(player, plot, false);
if (result) { if (result) {
MainUtil.createPlot(player.getUUID(), plot); plot.create(player.getUUID(), true);
MainUtil.setSign(player.getName(), plot); plot.setSign(player.getName());
MainUtil.sendMessage(player, C.CLAIMED); MainUtil.sendMessage(player, C.CLAIMED);
if (teleport) { if (teleport) {
MainUtil.teleportPlayer(player, player.getLocation(), plot); plot.teleportPlayer(player);
} }
} }
return !result; return !result;
@ -75,9 +75,10 @@ public class DebugClaimTest extends SubCommand {
null, 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}"); "If you accidentally delete your database, this command will attempt to restore all plots based on the data from the plot signs. \n\n&cMissing world arg /plot debugclaimtest {world} {PlotId min} {PlotId max}");
} }
final String world = args[0]; PlotArea area = PS.get().getPlotAreaByString(args[0]);
if (!BlockManager.manager.isWorld(world) || !PS.get().isPlotWorld(world)) { if (area == null || !WorldUtil.IMP.isWorld(area.worldname)) {
return !MainUtil.sendMessage(plr, "&cInvalid plot world!"); C.NOT_VALID_PLOT_WORLD.send(plr, args[0]);
return false;
} }
PlotId min, max; PlotId min, max;
try { try {
@ -91,22 +92,21 @@ public class DebugClaimTest extends SubCommand {
} }
MainUtil.sendMessage(plr, "&3Sign Block&8->&3PlotSquared&8: &7Beginning sign to plot conversion. This may take a while..."); MainUtil.sendMessage(plr, "&3Sign Block&8->&3PlotSquared&8: &7Beginning sign to plot conversion. This may take a while...");
MainUtil.sendMessage(plr, "&3Sign Block&8->&3PlotSquared&8: Found an excess of 250,000 chunks. Limiting search radius... (~3.8 min)"); MainUtil.sendMessage(plr, "&3Sign Block&8->&3PlotSquared&8: Found an excess of 250,000 chunks. Limiting search radius... (~3.8 min)");
final PlotManager manager = PS.get().getPlotManager(world); final PlotManager manager = area.getPlotManager();
final PlotWorld plotworld = PS.get().getPlotWorld(world);
final ArrayList<Plot> plots = new ArrayList<>(); final ArrayList<Plot> plots = new ArrayList<>();
for (final PlotId id : MainUtil.getPlotSelectionIds(min, max)) { for (final PlotId id : MainUtil.getPlotSelectionIds(min, max)) {
final Plot plot = MainUtil.getPlotAbs(world, id); final Plot plot = area.getPlotAbs(id);
if (PS.get().getPlot(world, plot.getId()) != null) { if (plot.hasOwner()) {
MainUtil.sendMessage(plr, " - &cDB Already contains: " + plot.getId()); MainUtil.sendMessage(plr, " - &cDB Already contains: " + plot.getId());
continue; continue;
} }
final Location loc = manager.getSignLoc(plotworld, plot); final Location loc = manager.getSignLoc(area, plot);
final ChunkLoc chunk = new ChunkLoc(loc.getX() >> 4, loc.getZ() >> 4); final ChunkLoc chunk = new ChunkLoc(loc.getX() >> 4, loc.getZ() >> 4);
final boolean result = ChunkManager.manager.loadChunk(world, chunk, false); final boolean result = ChunkManager.manager.loadChunk(area.worldname, chunk, false);
if (!result) { if (!result) {
continue; continue;
} }
final String[] lines = BlockManager.manager.getSign(loc); final String[] lines = WorldUtil.IMP.getSign(loc);
if (lines != null) { if (lines != null) {
String line = lines[2]; String line = lines[2];
if ((line != null) && (line.length() > 2)) { if ((line != null) && (line.length() > 2)) {

View File

@ -20,40 +20,6 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import com.google.common.io.Files;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.generator.HybridUtils;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.ConsolePlayer;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotAnalysis;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.AbstractTitle;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.ExpireManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.SchematicHandler;
import com.intellectualcrafters.plot.util.SetupUtils;
import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.bukkit.util.BukkitHybridUtils;
import com.plotsquared.general.commands.Command;
import com.plotsquared.general.commands.CommandDeclaration;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
@ -74,6 +40,41 @@ import javax.script.ScriptEngineManager;
import javax.script.ScriptException; import javax.script.ScriptException;
import javax.script.SimpleScriptContext; import javax.script.SimpleScriptContext;
import com.google.common.io.Files;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.generator.HybridUtils;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.ConsolePlayer;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotAnalysis;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.AbstractTitle;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.ExpireManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.SchematicHandler;
import com.intellectualcrafters.plot.util.SetupUtils;
import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualcrafters.plot.util.WorldUtil;
import com.plotsquared.bukkit.util.BukkitHybridUtils;
import com.plotsquared.general.commands.Command;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(command = "debugexec", permission = "plots.admin", description = "Mutli-purpose debug command", aliases = { "exec" }, category = CommandCategory.DEBUG) @CommandDeclaration(command = "debugexec", permission = "plots.admin", description = "Mutli-purpose debug command", aliases = { "exec" }, category = CommandCategory.DEBUG)
public class DebugExec extends SubCommand { public class DebugExec extends SubCommand {
@ -135,7 +136,7 @@ public class DebugExec extends SubCommand {
scope.put("ConsolePlayer", ConsolePlayer.getConsole()); scope.put("ConsolePlayer", ConsolePlayer.getConsole());
scope.put("SchematicHandler", SchematicHandler.manager); scope.put("SchematicHandler", SchematicHandler.manager);
scope.put("ChunkManager", ChunkManager.manager); scope.put("ChunkManager", ChunkManager.manager);
scope.put("BlockManager", BlockManager.manager); scope.put("BlockManager", WorldUtil.IMP);
scope.put("SetupUtils", SetupUtils.manager); scope.put("SetupUtils", SetupUtils.manager);
scope.put("EventUtil", EventUtil.manager); scope.put("EventUtil", EventUtil.manager);
scope.put("EconHandler", EconHandler.manager); scope.put("EconHandler", EconHandler.manager);
@ -160,7 +161,7 @@ public class DebugExec extends SubCommand {
boolean async = false; boolean async = false;
switch (arg) { switch (arg) {
case "analyze": { case "analyze": {
final Plot plot = MainUtil.getPlotAbs(player.getLocation()); final Plot plot = player.getCurrentPlot();
if (plot == null) { if (plot == null) {
MainUtil.sendMessage(player, C.NOT_IN_PLOT); MainUtil.sendMessage(player, C.NOT_IN_PLOT);
return false; return false;
@ -175,7 +176,7 @@ public class DebugExec extends SubCommand {
MainUtil.sendMessage(player, "$1Starting task..."); MainUtil.sendMessage(player, "$1Starting task...");
HybridUtils.manager.analyzePlot(plot, new RunnableVal<PlotAnalysis>() { HybridUtils.manager.analyzePlot(plot, new RunnableVal<PlotAnalysis>() {
@Override @Override
public void run() { public void run(PlotAnalysis value) {
MainUtil.sendMessage(player, "$1Done: $2use $3/plot debugexec analyze$2 for more information"); MainUtil.sendMessage(player, "$1Done: $2use $3/plot debugexec analyze$2 for more information");
} }
}); });
@ -231,14 +232,15 @@ public class DebugExec extends SubCommand {
return false; return false;
} }
boolean result; boolean result;
if (!PS.get().isPlotWorld(args[1])) { PlotArea area = PS.get().getPlotAreaByString(args[1]);
if (area == null) {
MainUtil.sendMessage(player, C.NOT_VALID_PLOT_WORLD, args[1]); MainUtil.sendMessage(player, C.NOT_VALID_PLOT_WORLD, args[1]);
return false; return false;
} }
if (HybridUtils.regions != null) { if (HybridUtils.regions != null) {
result = ((BukkitHybridUtils) (HybridUtils.manager)).scheduleRoadUpdate(args[1], HybridUtils.regions, 0); result = ((BukkitHybridUtils) (HybridUtils.manager)).scheduleRoadUpdate(area, HybridUtils.regions, 0);
} else { } else {
result = HybridUtils.manager.scheduleRoadUpdate(args[1], 0); result = HybridUtils.manager.scheduleRoadUpdate(area, 0);
} }
if (!result) { if (!result) {
MainUtil.sendMessage(player, "&cCannot schedule mass schematic update! (Is one already in progress?)"); MainUtil.sendMessage(player, "&cCannot schedule mass schematic update! (Is one already in progress?)");
@ -265,12 +267,13 @@ public class DebugExec extends SubCommand {
} }
case "update-expired": { case "update-expired": {
if (args.length > 1) { if (args.length > 1) {
final String world = args[1]; PlotArea area = PS.get().getPlotAreaByString(args[1]);
if (!BlockManager.manager.isWorld(world)) { if (area == null || !WorldUtil.IMP.isWorld(area.worldname)) {
return MainUtil.sendMessage(player, "Invalid world: " + args[1]); C.NOT_VALID_PLOT_WORLD.send(player, args[1]);
return false;
} }
MainUtil.sendMessage(player, "Updating expired plot list"); MainUtil.sendMessage(player, "Updating expired plot list");
ExpireManager.updateExpired(args[1]); ExpireManager.updateExpired(area);
return true; return true;
} }
return MainUtil.sendMessage(player, "Use /plot debugexec update-expired <world>"); return MainUtil.sendMessage(player, "Use /plot debugexec update-expired <world>");
@ -278,7 +281,7 @@ public class DebugExec extends SubCommand {
case "show-expired": { case "show-expired": {
if (args.length > 1) { if (args.length > 1) {
final String world = args[1]; final String world = args[1];
if (!BlockManager.manager.isWorld(world)) { if (!WorldUtil.IMP.isWorld(world)) {
return MainUtil.sendMessage(player, "Invalid world: " + args[1]); return MainUtil.sendMessage(player, "Invalid world: " + args[1]);
} }
if (!ExpireManager.expiredPlots.containsKey(args[1])) { if (!ExpireManager.expiredPlots.containsKey(args[1])) {
@ -286,7 +289,8 @@ public class DebugExec extends SubCommand {
} }
MainUtil.sendMessage(player, "Expired plots (" + ExpireManager.expiredPlots.get(args[1]).size() + "):"); MainUtil.sendMessage(player, "Expired plots (" + ExpireManager.expiredPlots.get(args[1]).size() + "):");
for (final Plot plot : ExpireManager.expiredPlots.get(args[1])) { for (final Plot plot : ExpireManager.expiredPlots.get(args[1])) {
MainUtil.sendMessage(player, " - " + plot.world + ";" + plot.getId().x + ";" + plot.getId().y + ";" + UUIDHandler.getName(plot.owner) + " : " + ExpireManager.dates.get(plot.owner)); MainUtil.sendMessage(player,
" - " + plot.area + ";" + plot.getId().x + ";" + plot.getId().y + ";" + UUIDHandler.getName(plot.owner) + " : " + ExpireManager.dates.get(plot.owner));
} }
return true; return true;
} }
@ -320,7 +324,7 @@ public class DebugExec extends SubCommand {
return MainUtil.sendMessage(player, "&7 - Run after plot expiry has run"); return MainUtil.sendMessage(player, "&7 - Run after plot expiry has run");
} }
final String world = args[1]; final String world = args[1];
if (!BlockManager.manager.isWorld(world) || !PS.get().isPlotWorld(args[1])) { if (!WorldUtil.IMP.isWorld(world) || !PS.get().hasPlotArea(args[1])) {
return MainUtil.sendMessage(player, "Invalid world: " + args[1]); return MainUtil.sendMessage(player, "Invalid world: " + args[1]);
} }
final ArrayList<ChunkLoc> empty = new ArrayList<>(); final ArrayList<ChunkLoc> empty = new ArrayList<>();

View File

@ -30,9 +30,10 @@ import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.WorldUtil;
import com.plotsquared.general.commands.Argument; import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
@ -51,13 +52,13 @@ public class DebugFixFlags extends SubCommand {
@Override @Override
public boolean onCommand(final PlotPlayer plr, final String[] args) { public boolean onCommand(final PlotPlayer plr, final String[] args) {
final String world = args[0]; PlotArea area = PS.get().getPlotAreaByString(args[0]);
if (!BlockManager.manager.isWorld(world) || !PS.get().isPlotWorld(world)) { if (area == null || !WorldUtil.IMP.isWorld(area.worldname)) {
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_WORLD, args[0]); MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_WORLD, args[0]);
return false; return false;
} }
MainUtil.sendMessage(plr, "&8--- &6Starting task &8 ---"); MainUtil.sendMessage(plr, "&8--- &6Starting task &8 ---");
for (final Plot plot : PS.get().getPlotsInWorld(world)) { for (final Plot plot : area.getPlots()) {
final HashMap<String, Flag> flags = plot.getFlags(); final HashMap<String, Flag> flags = plot.getFlags();
final Iterator<Entry<String, Flag>> i = flags.entrySet().iterator(); final Iterator<Entry<String, Flag>> i = flags.entrySet().iterator();
boolean changed = false; boolean changed = false;

View File

@ -3,16 +3,14 @@ package com.intellectualcrafters.plot.commands;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.plugin.Plugin;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.HastebinUtility; import com.intellectualcrafters.plot.util.HastebinUtility;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.bukkit.BukkitMain; import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration( @CommandDeclaration(
@ -33,9 +31,9 @@ public class DebugPaste extends SubCommand {
final String settingsYML = HastebinUtility.upload(PS.get().configFile); final String settingsYML = HastebinUtility.upload(PS.get().configFile);
String latestLOG; String latestLOG;
try { try {
latestLOG = HastebinUtility.upload(new File(BukkitMain.THIS.getDirectory(), "../../logs/latest.log")); latestLOG = HastebinUtility.upload(new File(PS.get().IMP.getDirectory(), "../../logs/latest.log"));
} catch (final Exception e) { } catch (final Exception e) {
plr.sendMessage(ChatColor.RED + "latest.log is too big to be pasted, will ignore"); MainUtil.sendMessage(plr, "&clatest.log is too big to be pasted, will ignore");
latestLOG = "too big :("; latestLOG = "too big :(";
} }
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -43,12 +41,16 @@ public class DebugPaste extends SubCommand {
b.append("links.settings_yml: '").append(settingsYML).append("'\n"); b.append("links.settings_yml: '").append(settingsYML).append("'\n");
b.append("links.latest_log: '").append(latestLOG).append("'\n"); b.append("links.latest_log: '").append(latestLOG).append("'\n");
b.append("\n# YAAAS! Now let us move on to the server info\n"); b.append("\n# YAAAS! Now let us move on to the server info\n");
b.append("version.server: '").append(Bukkit.getServer().getVersion()).append("'\n"); b.append("version.server: '").append(PS.get().IMP.getServerVersion()).append("'\n");
b.append("version.bukkit: '").append(Bukkit.getBukkitVersion()).append("'\n"); b.append("online_mode: ").append(UUIDHandler.getUUIDWrapper() + ";" + !Settings.OFFLINE_MODE).append("\n");
b.append("online_mode: ").append(Bukkit.getServer().getOnlineMode()).append("\n");
b.append("plugins:"); b.append("plugins:");
for (final Plugin p : Bukkit.getPluginManager().getPlugins()) { for (String id : PS.get().IMP.getPluginIds()) {
b.append("\n ").append(p.getName()).append(":\n ").append("version: '").append(p.getDescription().getVersion()).append("'").append("\n enabled: ").append(p.isEnabled()); String[] split = id.split(":");
String[] split2 = split[0].split(";");
String enabled = split.length == 2 ? split[1] : "unknown";
String name = split2[0];
String version = split2.length == 2 ? split2[1] : "unknown";
b.append("\n ").append(name).append(":\n ").append("version: '").append(version).append("'").append("\n enabled: ").append(enabled);
} }
b.append("\n\n# YAY! Now, let's see what we can find in your JVM\n"); b.append("\n\n# YAY! Now, let's see what we can find in your JVM\n");
final Runtime runtime = Runtime.getRuntime(); final Runtime runtime = Runtime.getRuntime();

View File

@ -20,7 +20,6 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.generator.HybridPlotManager; import com.intellectualcrafters.plot.generator.HybridPlotManager;
import com.intellectualcrafters.plot.generator.HybridPlotWorld; import com.intellectualcrafters.plot.generator.HybridPlotWorld;
@ -28,8 +27,8 @@ import com.intellectualcrafters.plot.generator.HybridUtils;
import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.MathMan; import com.intellectualcrafters.plot.util.MathMan;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
@ -46,8 +45,7 @@ public class DebugRoadRegen extends SubCommand {
@Override @Override
public boolean onCommand(final PlotPlayer player, final String... args) { public boolean onCommand(final PlotPlayer player, final String... args) {
final Location loc = player.getLocation(); final Location loc = player.getLocation();
final String world = loc.getWorld(); final PlotArea plotworld = loc.getPlotArea();
final PlotWorld plotworld = loc.getPlotWorld();
if (!(plotworld instanceof HybridPlotWorld)) { if (!(plotworld instanceof HybridPlotWorld)) {
return sendMessage(player, C.NOT_IN_PLOT_WORLD); return sendMessage(player, C.NOT_IN_PLOT_WORLD);
} }
@ -65,11 +63,11 @@ public class DebugRoadRegen extends SubCommand {
} }
} }
} }
final boolean result = HybridUtils.manager.regenerateRoad(world, chunk, extend); final boolean result = HybridUtils.manager.regenerateRoad(plotworld, chunk, extend);
MainUtil.sendMessage(player, "&6Regenerating chunk: " + chunk.x + "," + chunk.z + "\n&6 - Result: " + (result ? "&aSuccess" : "&cFailed")); MainUtil.sendMessage(player, "&6Regenerating chunk: " + chunk.x + "," + chunk.z + "\n&6 - Result: " + (result ? "&aSuccess" : "&cFailed"));
MainUtil.sendMessage(player, "&cTo regenerate all roads: /plot regenallroads"); MainUtil.sendMessage(player, "&cTo regenerate all roads: /plot regenallroads");
} else { } else {
final HybridPlotManager manager = (HybridPlotManager) PS.get().getPlotManager(world); final HybridPlotManager manager = (HybridPlotManager) plotworld.getPlotManager();
manager.createRoadEast(plotworld, plot); manager.createRoadEast(plotworld, plot);
manager.createRoadSouth(plotworld, plot); manager.createRoadSouth(plotworld, plot);
manager.createRoadSouthEast(plotworld, plot); manager.createRoadSouthEast(plotworld, plot);

View File

@ -32,8 +32,6 @@ import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Bukkit;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.database.AbstractDB; import com.intellectualcrafters.plot.database.AbstractDB;
@ -46,6 +44,7 @@ import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualcrafters.plot.util.WorldUtil;
import com.intellectualcrafters.plot.uuid.UUIDWrapper; import com.intellectualcrafters.plot.uuid.UUIDWrapper;
import com.plotsquared.bukkit.uuid.DefaultUUIDWrapper; import com.plotsquared.bukkit.uuid.DefaultUUIDWrapper;
import com.plotsquared.bukkit.uuid.LowerOfflineUUIDWrapper; import com.plotsquared.bukkit.uuid.LowerOfflineUUIDWrapper;
@ -125,7 +124,7 @@ public class DebugUUID extends SubCommand {
MainUtil.sendMessage(player, "&7 - Collecting playerdata"); MainUtil.sendMessage(player, "&7 - Collecting playerdata");
final HashSet<String> worlds = new HashSet<>(); final HashSet<String> worlds = new HashSet<>();
worlds.add(Bukkit.getWorlds().get(0).getName()); worlds.add(WorldUtil.IMP.getMainWorld());
worlds.add("world"); worlds.add("world");
final HashSet<UUID> uuids = new HashSet<>(); final HashSet<UUID> uuids = new HashSet<>();
final HashSet<String> names = new HashSet<>(); final HashSet<String> names = new HashSet<>();
@ -259,7 +258,7 @@ public class DebugUUID extends SubCommand {
MainUtil.sendMessage(player, "&7 - Updating plot objects"); MainUtil.sendMessage(player, "&7 - Updating plot objects");
for (final Plot plot : PS.get().getPlotsRaw()) { for (final Plot plot : PS.get().getPlots()) {
final UUID value = uCMap.get(plot.owner); final UUID value = uCMap.get(plot.owner);
if (value != null) { if (value != null) {
plot.owner = value; plot.owner = value;

View File

@ -20,12 +20,14 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.HashSet;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.CmdConfirm; import com.intellectualcrafters.plot.util.CmdConfirm;
import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
@ -33,8 +35,6 @@ import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
import java.util.HashSet;
@CommandDeclaration( @CommandDeclaration(
command = "delete", command = "delete",
permission = "plots.delete", permission = "plots.delete",
@ -49,7 +49,7 @@ public class Delete extends SubCommand {
public boolean onCommand(final PlotPlayer plr, final String[] args) { public boolean onCommand(final PlotPlayer plr, final String[] args) {
final Location loc = plr.getLocation(); final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlotAbs(loc); final Plot plot = loc.getPlotAbs();
if (plot == null) { if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT); return !sendMessage(plr, C.NOT_IN_PLOT);
} }
@ -59,8 +59,8 @@ public class Delete extends SubCommand {
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.delete")) { if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.delete")) {
return !sendMessage(plr, C.NO_PLOT_PERMS); return !sendMessage(plr, C.NO_PLOT_PERMS);
} }
final PlotWorld plotworld = plot.getWorld(); final PlotArea plotworld = plot.getArea();
final HashSet<Plot> plots = MainUtil.getConnectedPlots(plot); final HashSet<Plot> plots = plot.getConnectedPlots();
final Runnable run = new Runnable() { final Runnable run = new Runnable() {
@Override @Override
public void run() { public void run() {

View File

@ -27,11 +27,11 @@ import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualcrafters.plot.util.WorldUtil;
import com.plotsquared.bukkit.uuid.SQLUUIDHandler; import com.plotsquared.bukkit.uuid.SQLUUIDHandler;
import com.plotsquared.general.commands.Argument; import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
@ -47,7 +47,7 @@ public class Deny extends SubCommand {
public boolean onCommand(final PlotPlayer plr, final String[] args) { public boolean onCommand(final PlotPlayer plr, final String[] args) {
final Location loc = plr.getLocation(); final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlotAbs(loc); final Plot plot = loc.getPlotAbs();
if (plot == null) { if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT); return !sendMessage(plr, C.NOT_IN_PLOT);
} }
@ -104,10 +104,10 @@ public class Deny extends SubCommand {
if (!plot.equals(pp.getCurrentPlot())) { if (!plot.equals(pp.getCurrentPlot())) {
return; return;
} }
if (pp.hasPermission("plots.admin.command.deny")) { if (pp.hasPermission("plots.admin.entry.denied")) {
return; return;
} }
pp.teleport(BlockManager.manager.getSpawn(pp.getLocation().getWorld())); pp.teleport(WorldUtil.IMP.getSpawn(pp.getLocation().getWorld()));
MainUtil.sendMessage(pp, C.YOU_GOT_DENIED); MainUtil.sendMessage(pp, C.YOU_GOT_DENIED);
} }
} }

View File

@ -40,7 +40,7 @@ public class Done extends SubCommand {
@Override @Override
public boolean onCommand(final PlotPlayer plr, final String[] args) { public boolean onCommand(final PlotPlayer plr, final String[] args) {
final Location loc = plr.getLocation(); final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlotAbs(loc); final Plot plot = loc.getPlotAbs();
if ((plot == null) || !plot.hasOwner()) { if ((plot == null) || !plot.hasOwner()) {
return !sendMessage(plr, C.NOT_IN_PLOT); return !sendMessage(plr, C.NOT_IN_PLOT);
} }
@ -60,7 +60,7 @@ public class Done extends SubCommand {
MainUtil.sendMessage(plr, C.GENERATING_LINK); MainUtil.sendMessage(plr, C.GENERATING_LINK);
HybridUtils.manager.analyzePlot(plot, new RunnableVal<PlotAnalysis>() { HybridUtils.manager.analyzePlot(plot, new RunnableVal<PlotAnalysis>() {
@Override @Override
public void run() { public void run(PlotAnalysis value) {
plot.removeRunning(); plot.removeRunning();
if ((value == null) || (value.getComplexity() >= Settings.CLEAR_THRESHOLD)) { if ((value == null) || (value.getComplexity() >= Settings.CLEAR_THRESHOLD)) {
final Flag flag = new Flag(FlagManager.getFlag("done"), (System.currentTimeMillis() / 1000)); final Flag flag = new Flag(FlagManager.getFlag("done"), (System.currentTimeMillis() / 1000));

View File

@ -27,10 +27,10 @@ public class Download extends SubCommand {
return false; return false;
} }
final String world = plr.getLocation().getWorld(); final String world = plr.getLocation().getWorld();
if (!PS.get().isPlotWorld(world)) { if (!PS.get().hasPlotArea(world)) {
return !sendMessage(plr, C.NOT_IN_PLOT_WORLD); return !sendMessage(plr, C.NOT_IN_PLOT_WORLD);
} }
final Plot plot = MainUtil.getPlotAbs(plr.getLocation()); final Plot plot = plr.getCurrentPlot();
if (plot == null) { if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT); return !sendMessage(plr, C.NOT_IN_PLOT);
} }
@ -48,9 +48,9 @@ public class Download extends SubCommand {
} }
plot.addRunning(); plot.addRunning();
MainUtil.sendMessage(plr, C.GENERATING_LINK); MainUtil.sendMessage(plr, C.GENERATING_LINK);
SchematicHandler.manager.getCompoundTag(plot.world, plot.getId(), new RunnableVal<CompoundTag>() { SchematicHandler.manager.getCompoundTag(plot, new RunnableVal<CompoundTag>() {
@Override @Override
public void run() { public void run(final CompoundTag value) {
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTaskAsync(new Runnable() {
@Override @Override
public void run() { public void run() {

View File

@ -68,7 +68,7 @@ public class FlagCmd extends SubCommand {
return false; return false;
} }
final Location loc = player.getLocation(); final Location loc = player.getLocation();
final Plot plot = MainUtil.getPlotAbs(loc); final Plot plot = loc.getPlotAbs();
if (plot == null) { if (plot == null) {
MainUtil.sendMessage(player, C.NOT_IN_PLOT); MainUtil.sendMessage(player, C.NOT_IN_PLOT);
return false; return false;

View File

@ -83,18 +83,18 @@ public class Inbox extends SubCommand {
@Override @Override
public boolean onCommand(final PlotPlayer player, final String[] args) { public boolean onCommand(final PlotPlayer player, final String[] args) {
final Plot plot = MainUtil.getPlotAbs(player.getLocation()); final Plot plot = player.getCurrentPlot();
if (args.length == 0) { if (args.length == 0) {
sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox [inbox] [delete <index>|clear|page]"); sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox [inbox] [delete <index>|clear|page]");
for (final CommentInbox inbox : CommentManager.inboxes.values()) { for (final CommentInbox inbox : CommentManager.inboxes.values()) {
if (inbox.canRead(plot, player)) { if (inbox.canRead(plot, player)) {
if (!inbox.getComments(plot, new RunnableVal() { if (!inbox.getComments(plot, new RunnableVal<List<PlotComment>>() {
@Override @Override
public void run() { public void run(List<PlotComment> value) {
if (value != null) { if (value != null) {
int total = 0; int total = 0;
int unread = 0; int unread = 0;
for (final PlotComment comment : (ArrayList<PlotComment>) value) { for (final PlotComment comment : value) {
total++; total++;
if (comment.timestamp > CommentManager.getTimestamp(player, inbox.toString())) { if (comment.timestamp > CommentManager.getTimestamp(player, inbox.toString())) {
unread++; unread++;
@ -149,10 +149,10 @@ public class Inbox extends SubCommand {
return false; return false;
} }
if (!inbox.getComments(plot, new RunnableVal() { if (!inbox.getComments(plot, new RunnableVal<List<PlotComment>>() {
@Override @Override
public void run() { public void run(List<PlotComment> value) {
final List<PlotComment> comments = (List<PlotComment>) value; final List<PlotComment> comments = value;
if (index > comments.size()) { if (index > comments.size()) {
sendMessage(player, C.NOT_VALID_INBOX_INDEX, index + ""); sendMessage(player, C.NOT_VALID_INBOX_INDEX, index + "");
return; return;
@ -196,10 +196,10 @@ public class Inbox extends SubCommand {
sendMessage(player, C.NO_PERM_INBOX); sendMessage(player, C.NO_PERM_INBOX);
return false; return false;
} }
if (!inbox.getComments(plot, new RunnableVal() { if (!inbox.getComments(plot, new RunnableVal<List<PlotComment>>() {
@Override @Override
public void run() { public void run(List<PlotComment> value) {
final List<PlotComment> comments = (List<PlotComment>) value; final List<PlotComment> comments = value;
displayComments(player, comments, page); displayComments(player, comments, page);
} }
})) { })) {

View File

@ -37,12 +37,10 @@ public class Info extends SubCommand {
@Override @Override
public boolean onCommand(final PlotPlayer player, String[] args) { public boolean onCommand(final PlotPlayer player, String[] args) {
String arg = null;
Plot plot; Plot plot;
String arg;
if (args.length > 0) { if (args.length > 0) {
arg = args[0] + ""; arg = args[0];
}
if (arg != null) {
switch (arg) { switch (arg) {
case "trusted": case "trusted":
case "alias": case "alias":
@ -66,11 +64,12 @@ public class Info extends SubCommand {
} }
break; break;
} }
if (plot == null) {
plot = player.getCurrentPlot();
}
} else { } else {
plot = MainUtil.getPlotFromString(player, null, false); arg = null;
} plot = player.getCurrentPlot();
if ((plot == null) && (arg != null)) {
plot = MainUtil.getPlotFromString(player, null, false);
} }
if (plot == null) { if (plot == null) {
MainUtil.sendMessage(player, C.NOT_IN_PLOT); MainUtil.sendMessage(player, C.NOT_IN_PLOT);
@ -138,7 +137,7 @@ public class Info extends SubCommand {
} }
MainUtil.format(info, plot, player, full, new RunnableVal<String>() { MainUtil.format(info, plot, player, full, new RunnableVal<String>() {
@Override @Override
public void run() { public void run(String value) {
MainUtil.sendMessage(player, C.PLOT_INFO_HEADER.s() + '\n' + value + '\n' + C.PLOT_INFO_FOOTER.s(), false); MainUtil.sendMessage(player, C.PLOT_INFO_HEADER.s() + '\n' + value + '\n' + C.PLOT_INFO_FOOTER.s(), false);
} }
}); });

View File

@ -24,10 +24,10 @@ import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualcrafters.plot.util.WorldUtil;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(command = "kick", aliases = { "k" }, description = "Kick a player from your plot", permission = "plots.kick", category = CommandCategory.ACTIONS, requiredType = RequiredType.NONE) @CommandDeclaration(command = "kick", aliases = { "k" }, description = "Kick a player from your plot", permission = "plots.kick", category = CommandCategory.ACTIONS, requiredType = RequiredType.NONE)
@ -36,7 +36,7 @@ public class Kick extends SubCommand {
@Override @Override
public boolean onCommand(final PlotPlayer plr, final String[] args) { public boolean onCommand(final PlotPlayer plr, final String[] args) {
final Location loc = plr.getLocation(); final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlotAbs(loc); final Plot plot = loc.getPlot();
if (plot == null) { if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT); return !sendMessage(plr, C.NOT_IN_PLOT);
} }
@ -54,15 +54,15 @@ public class Kick extends SubCommand {
return false; return false;
} }
final Location otherLoc = player.getLocation(); final Location otherLoc = player.getLocation();
if (!plr.getLocation().getWorld().equals(otherLoc.getWorld()) || !plot.equals(MainUtil.getPlotAbs(otherLoc))) { if (!plr.getLocation().getWorld().equals(otherLoc.getWorld()) || !plot.equals(otherLoc.getPlot())) {
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]); MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
return false; return false;
} }
if (player.hasPermission("plots.admin.command.kick")) { if (player.hasPermission("plots.admin.entry.denied")) {
C.CANNOT_KICK_PLAYER.send(plr, player.getName()); C.CANNOT_KICK_PLAYER.send(plr, player.getName());
return false; return false;
} }
player.teleport(BlockManager.manager.getSpawn(loc.getWorld())); player.teleport(WorldUtil.IMP.getSpawn(loc.getWorld()));
return true; return true;
} }
} }

View File

@ -36,10 +36,10 @@ public class Load extends SubCommand {
return false; return false;
} }
final String world = plr.getLocation().getWorld(); final String world = plr.getLocation().getWorld();
if (!PS.get().isPlotWorld(world)) { if (!PS.get().hasPlotArea(world)) {
return !sendMessage(plr, C.NOT_IN_PLOT_WORLD); return !sendMessage(plr, C.NOT_IN_PLOT_WORLD);
} }
final Plot plot = MainUtil.getPlotAbs(plr.getLocation()); final Plot plot = plr.getCurrentPlot();
if (plot == null) { if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT); return !sendMessage(plr, C.NOT_IN_PLOT);
} }
@ -93,7 +93,7 @@ public class Load extends SubCommand {
} }
SchematicHandler.manager.paste(schematic, plot, 0, 0, new RunnableVal<Boolean>() { SchematicHandler.manager.paste(schematic, plot, 0, 0, new RunnableVal<Boolean>() {
@Override @Override
public void run() { public void run(Boolean value) {
plot.removeRunning(); plot.removeRunning();
if (value) { if (value) {
sendMessage(plr, C.SCHEMATIC_PASTE_SUCCESS); sendMessage(plr, C.SCHEMATIC_PASTE_SUCCESS);

View File

@ -20,11 +20,19 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.object.ConsolePlayer; import com.intellectualcrafters.plot.object.ConsolePlayer;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.MathMan; import com.intellectualcrafters.plot.util.MathMan;
@ -37,13 +45,6 @@ import com.plotsquared.general.commands.Command;
import com.plotsquared.general.commands.CommandHandlingOutput; import com.plotsquared.general.commands.CommandHandlingOutput;
import com.plotsquared.general.commands.CommandManager; import com.plotsquared.general.commands.CommandManager;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
/** /**
* PlotSquared command class * PlotSquared command class
* *
@ -83,7 +84,6 @@ public class MainCommand extends CommandManager<PlotPlayer> {
createCommand(new Auto()); createCommand(new Auto());
createCommand(new Visit()); createCommand(new Visit());
createCommand(new Home()); createCommand(new Home());
createCommand(new TP());
createCommand(new Set()); createCommand(new Set());
createCommand(new Toggle()); createCommand(new Toggle());
createCommand(new Clear()); createCommand(new Clear());
@ -273,12 +273,12 @@ public class MainCommand extends CommandManager<PlotPlayer> {
} }
default: { default: {
if (args.length >= 2) { if (args.length >= 2) {
String world = player.getLocation().getWorld(); PlotArea area = player.getApplicablePlotArea();
Plot newPlot = Plot.fromString(world, args[0]); Plot newPlot = Plot.fromString(area, args[0]);
if (newPlot == null) { if (newPlot == null) {
break; break;
} }
if (!ConsolePlayer.isConsole(player) && (!newPlot.world.equals(world) || newPlot.isDenied(player.getUUID())) && !Permissions.hasPermission(player, C.PERMISSION_ADMIN)) { if (!ConsolePlayer.isConsole(player) && (!newPlot.area.equals(area) || newPlot.isDenied(player.getUUID())) && !Permissions.hasPermission(player, C.PERMISSION_ADMIN)) {
break; break;
} }
// Save meta // Save meta

View File

@ -20,12 +20,15 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.HashSet;
import java.util.UUID;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.CmdConfirm; import com.intellectualcrafters.plot.util.CmdConfirm;
import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
@ -34,9 +37,6 @@ import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
import java.util.HashSet;
import java.util.UUID;
@CommandDeclaration( @CommandDeclaration(
command = "merge", command = "merge",
aliases = { "m" }, aliases = { "m" },
@ -74,7 +74,7 @@ public class Merge extends SubCommand {
@Override @Override
public boolean onCommand(final PlotPlayer plr, final String[] args) { public boolean onCommand(final PlotPlayer plr, final String[] args) {
final Location loc = plr.getLocationFull(); final Location loc = plr.getLocationFull();
final Plot plot = MainUtil.getPlotAbs(loc); final Plot plot = loc.getPlotAbs();
if (plot == null) { if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT); return !sendMessage(plr, C.NOT_IN_PLOT);
} }
@ -92,7 +92,7 @@ public class Merge extends SubCommand {
uuid = plot.owner; uuid = plot.owner;
} }
} }
final PlotWorld plotworld = plot.getWorld(); final PlotArea plotworld = plot.getArea();
if ((EconHandler.manager != null) && plotworld.USE_ECONOMY && plotworld.MERGE_PRICE > 0d && EconHandler.manager.getMoney(plr) < plotworld.MERGE_PRICE) { if ((EconHandler.manager != null) && plotworld.USE_ECONOMY && plotworld.MERGE_PRICE > 0d && EconHandler.manager.getMoney(plr) < plotworld.MERGE_PRICE) {
sendMessage(plr, C.CANNOT_AFFORD_MERGE, plotworld.MERGE_PRICE + ""); sendMessage(plr, C.CANNOT_AFFORD_MERGE, plotworld.MERGE_PRICE + "");
return false; return false;
@ -125,7 +125,7 @@ public class Merge extends SubCommand {
if (args.length == 2) { if (args.length == 2) {
terrain = args[1].equalsIgnoreCase("true"); terrain = args[1].equalsIgnoreCase("true");
} }
if (MainUtil.autoMerge(plot, -1, maxSize - size, uuid, terrain)) { if (plot.autoMerge(-1, maxSize, uuid, terrain)) {
if ((EconHandler.manager != null) && plotworld.USE_ECONOMY && plotworld.MERGE_PRICE > 0d) { if ((EconHandler.manager != null) && plotworld.USE_ECONOMY && plotworld.MERGE_PRICE > 0d) {
EconHandler.manager.withdrawMoney(plr, plotworld.MERGE_PRICE); EconHandler.manager.withdrawMoney(plr, plotworld.MERGE_PRICE);
sendMessage(plr, C.REMOVED_BALANCE, plotworld.MERGE_PRICE + ""); sendMessage(plr, C.REMOVED_BALANCE, plotworld.MERGE_PRICE + "");
@ -155,7 +155,7 @@ public class Merge extends SubCommand {
} else { } else {
terrain = Settings.MERGE_REMOVES_ROADS; terrain = Settings.MERGE_REMOVES_ROADS;
} }
if (MainUtil.autoMerge(plot, direction, maxSize - size, uuid, terrain)) { if (plot.autoMerge(direction, maxSize - size, uuid, terrain)) {
if ((EconHandler.manager != null) && plotworld.USE_ECONOMY && plotworld.MERGE_PRICE > 0d) { if ((EconHandler.manager != null) && plotworld.USE_ECONOMY && plotworld.MERGE_PRICE > 0d) {
EconHandler.manager.withdrawMoney(plr, plotworld.MERGE_PRICE); EconHandler.manager.withdrawMoney(plr, plotworld.MERGE_PRICE);
sendMessage(plr, C.REMOVED_BALANCE, plotworld.MERGE_PRICE + ""); sendMessage(plr, C.REMOVED_BALANCE, plotworld.MERGE_PRICE + "");
@ -163,7 +163,7 @@ public class Merge extends SubCommand {
MainUtil.sendMessage(plr, C.SUCCESS_MERGE); MainUtil.sendMessage(plr, C.SUCCESS_MERGE);
return true; return true;
} }
Plot adjacent = MainUtil.getPlotAbs(plot.world, MainUtil.getPlotIdRelative(plot.getId(), direction)); Plot adjacent = plot.getRelative(direction);
if (adjacent == null || !adjacent.hasOwner() || adjacent.getMerged((direction + 2) % 4) || adjacent.isOwner(uuid)) { if (adjacent == null || !adjacent.hasOwner() || adjacent.getMerged((direction + 2) % 4) || adjacent.isOwner(uuid)) {
MainUtil.sendMessage(plr, C.NO_AVAILABLE_AUTOMERGE); MainUtil.sendMessage(plr, C.NO_AVAILABLE_AUTOMERGE);
return false; return false;
@ -185,7 +185,7 @@ public class Merge extends SubCommand {
@Override @Override
public void run() { public void run() {
MainUtil.sendMessage(accepter, C.MERGE_ACCEPTED); MainUtil.sendMessage(accepter, C.MERGE_ACCEPTED);
MainUtil.autoMerge(plot, dir, maxSize - size, owner, terrain); plot.autoMerge(dir, maxSize - size, owner, terrain);
final PlotPlayer pp = UUIDHandler.getPlayer(plr.getUUID()); final PlotPlayer pp = UUIDHandler.getPlayer(plr.getUUID());
if (pp == null) { if (pp == null) {
sendMessage(accepter, C.MERGE_NOT_VALID); sendMessage(accepter, C.MERGE_NOT_VALID);

View File

@ -4,8 +4,6 @@ import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.util.MainUtil;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
/** /**
@ -26,7 +24,7 @@ public class Middle extends SubCommand {
@Override @Override
public boolean onCommand(PlotPlayer player, String[] arguments) { public boolean onCommand(PlotPlayer player, String[] arguments) {
final Location location = player.getLocation(); final Location location = player.getLocation();
final Plot plot = MainUtil.getPlotAbs(location); final Plot plot = location.getPlot();
if (plot == null) { if (plot == null) {
return sendMessage(player, C.NOT_IN_PLOT); return sendMessage(player, C.NOT_IN_PLOT);
} }
@ -36,13 +34,7 @@ public class Middle extends SubCommand {
if (!player.hasPermission("plots.middle")) { if (!player.hasPermission("plots.middle")) {
return sendMessage(player, C.NO_PERMISSION, "plots.middle"); return sendMessage(player, C.NO_PERMISSION, "plots.middle");
} }
player.teleport(plot.getCenter());
RegionWrapper largestRegion = MainUtil.getLargestRegion(plot);
final int x = ((largestRegion.maxX - largestRegion.minX) / 2) + largestRegion.minX;
final int z = ((largestRegion.maxZ - largestRegion.minZ) / 2) + largestRegion.minZ;
final int y = MainUtil.getHeighestBlock(plot.getWorld().worldname, x, z) + 1;
player.teleport(new Location(plot.getWorld().worldname, x, y, z));
return true; return true;
} }
} }

View File

@ -41,7 +41,7 @@ public class Move extends SubCommand {
@Override @Override
public boolean onCommand(final PlotPlayer plr, final String[] args) { public boolean onCommand(final PlotPlayer plr, final String[] args) {
final Location loc = plr.getLocation(); final Location loc = plr.getLocation();
final Plot plot1 = MainUtil.getPlotAbs(loc); final Plot plot1 = loc.getPlotAbs();
if (plot1 == null) { if (plot1 == null) {
return !MainUtil.sendMessage(plr, C.NOT_IN_PLOT); return !MainUtil.sendMessage(plr, C.NOT_IN_PLOT);
} }
@ -62,11 +62,11 @@ public class Move extends SubCommand {
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot copy <X;Z>"); MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot copy <X;Z>");
return false; return false;
} }
if (!plot1.getWorld().isCompatible(plot2.getWorld())) { if (!plot1.area.isCompatible(plot2.area)) {
C.PLOTWORLD_INCOMPATIBLE.send(plr); C.PLOTWORLD_INCOMPATIBLE.send(plr);
return false; return false;
} }
if (MainUtil.move(plot1, plot2, new Runnable() { if (plot1.move(plot2, new Runnable() {
@Override @Override
public void run() { public void run() {
MainUtil.sendMessage(plr, C.MOVE_SUCCESS); MainUtil.sendMessage(plr, C.MOVE_SUCCESS);

View File

@ -29,8 +29,8 @@ import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotInventory; import com.intellectualcrafters.plot.object.PlotInventory;
import com.intellectualcrafters.plot.object.PlotItemStack; import com.intellectualcrafters.plot.object.PlotItemStack;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.WorldUtil;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(command = "music", permission = "plots.music", description = "Player music in a plot", usage = "/plot music", category = CommandCategory.ACTIONS, requiredType = RequiredType.NONE) @CommandDeclaration(command = "music", permission = "plots.music", description = "Player music in a plot", usage = "/plot music", category = CommandCategory.ACTIONS, requiredType = RequiredType.NONE)
@ -39,7 +39,7 @@ public class MusicSubcommand extends SubCommand {
@Override @Override
public boolean onCommand(final PlotPlayer player, final String[] args) { public boolean onCommand(final PlotPlayer player, final String[] args) {
final Location loc = player.getLocation(); final Location loc = player.getLocation();
final Plot plot = MainUtil.getPlotAbs(loc); final Plot plot = loc.getPlotAbs();
if (plot == null) { if (plot == null) {
return !sendMessage(player, C.NOT_IN_PLOT); return !sendMessage(player, C.NOT_IN_PLOT);
} }
@ -65,7 +65,7 @@ public class MusicSubcommand extends SubCommand {
}; };
int index = 0; int index = 0;
for (int i = 2256; i < 2268; i++) { for (int i = 2256; i < 2268; i++) {
final String name = "&r&6" + BlockManager.manager.getClosestMatchingName(new PlotBlock((short) i, (byte) 0)); final String name = "&r&6" + WorldUtil.IMP.getClosestMatchingName(new PlotBlock((short) i, (byte) 0));
final String[] lore = { "&r&aClick to play!" }; final String[] lore = { "&r&aClick to play!" };
final PlotItemStack item = new PlotItemStack(i, (byte) 0, 1, name, lore); final PlotItemStack item = new PlotItemStack(i, (byte) 0, 1, name, lore);
inv.setItem(index, item); inv.setItem(index, item);

View File

@ -44,7 +44,7 @@ public class Owner extends SetCommand {
@Override @Override
public boolean set(PlotPlayer plr, Plot plot, String value) { public boolean set(PlotPlayer plr, Plot plot, String value) {
HashSet<Plot> plots = MainUtil.getConnectedPlots(plot); HashSet<Plot> plots = plot.getConnectedPlots();
UUID uuid = null; UUID uuid = null;
String name = null; String name = null;
if (value.length() == 36) { if (value.length() == 36) {
@ -72,18 +72,18 @@ public class Owner extends SetCommand {
return false; return false;
} }
final int size = plots.size(); final int size = plots.size();
final int currentPlots = (Settings.GLOBAL_LIMIT ? MainUtil.getPlayerPlotCount(other) : MainUtil.getPlayerPlotCount(plot.world, other)) + size; final int currentPlots = (Settings.GLOBAL_LIMIT ? other.getPlotCount() : other.getPlotCount(plot.area.worldname)) + size;
if (currentPlots > MainUtil.getAllowedPlots(other)) { if (currentPlots > other.getAllowedPlots()) {
sendMessage(plr, C.CANT_TRANSFER_MORE_PLOTS); sendMessage(plr, C.CANT_TRANSFER_MORE_PLOTS);
return false; return false;
} }
} }
plot.setOwner(uuid); plot.setOwner(uuid);
MainUtil.setSign(name, plot); plot.setSign(name);
MainUtil.sendMessage(plr, C.SET_OWNER); MainUtil.sendMessage(plr, C.SET_OWNER);
if (other != null) { if (other != null) {
MainUtil.sendMessage(other, C.NOW_OWNER, plot.world + ";" + plot.getId()); MainUtil.sendMessage(other, C.NOW_OWNER, plot.area + ";" + plot.getId());
} }
return true; return true;
} }

View File

@ -20,8 +20,9 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.Collection; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
@ -29,136 +30,157 @@ import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.CmdConfirm;
import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(command = "purge", permission = "plots.admin", description = "Purge all plots for a world", category = CommandCategory.ACTIONS, requiredType = RequiredType.CONSOLE) @CommandDeclaration(
usage = "/plot purge world:<world> area:<area> id:<id> owner:<owner> shared:<shared> unknown:[true|false]",
command = "purge",
permission = "plots.admin",
description = "Purge all plots for a world",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.CONSOLE)
public class Purge extends SubCommand { public class Purge extends SubCommand {
public PlotId getId(final String id) {
try {
final String[] split = id.split(";");
return new PlotId(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
} catch (final Exception e) {
return null;
}
}
@Override @Override
public boolean onCommand(final PlotPlayer plr, final String[] args) { public boolean onCommand(final PlotPlayer plr, final String[] args) {
if (args.length == 1) { if (args.length == 0) {
final String arg = args[0].toLowerCase();
final PlotId id = getId(arg);
if (id != null) {
MainUtil.sendMessage(plr, "/plot purxe x;z &l<world>");
return false;
}
final UUID uuid = UUIDHandler.getUUID(args[0], null);
if (uuid != null) {
MainUtil.sendMessage(plr, "/plot purge " + args[0] + " &l<world>");
return false;
}
if (arg.equals("player")) {
MainUtil.sendMessage(plr, "/plot purge &l<player> <world>");
return false;
}
if (arg.equals("unowned")) {
MainUtil.sendMessage(plr, "/plot purge unowned &l<world>");
return false;
}
if (arg.equals("unknown")) {
MainUtil.sendMessage(plr, "/plot purge unknown &l<world>");
return false;
}
if (arg.equals("all")) {
MainUtil.sendMessage(plr, "/plot purge all &l<world>");
return false;
}
MainUtil.sendMessage(plr, C.PURGE_SYNTAX);
return false; return false;
} }
if (args.length != 2) {
MainUtil.sendMessage(plr, C.PURGE_SYNTAX); String world = null;
return false; PlotArea area = null;
} PlotId id = null;
final String worldname = args[1]; UUID owner = null;
if (!PS.get().isPlotWorld(worldname)) { UUID added = null;
C.NOT_VALID_PLOT_WORLD.send(plr); boolean unknown = false;
return false; for (String arg : args) {
} String[] split = arg.split(":");
final String arg = args[0].toLowerCase(); if (split.length != 2) {
final PlotId id = getId(arg); C.COMMAND_SYNTAX.send(plr, getUsage());
if (id != null) { return false;
final HashSet<Integer> ids = new HashSet<Integer>();
final int DBid = DBFunc.getId(MainUtil.getPlotAbs(worldname, id));
if (DBid != Integer.MAX_VALUE) {
ids.add(DBid);
} }
DBFunc.purgeIds(worldname, ids); switch (split[0].toLowerCase()) {
return finishPurge(DBid == Integer.MAX_VALUE ? 1 : 0); case "world":
} case "w": {
if (arg.equals("all")) { world = split[1];
final Set<PlotId> ids = PS.get().getPlots(worldname).keySet(); break;
final int length = ids.size(); }
if (length == 0) { case "area":
return MainUtil.sendMessage(plr, "&cNo plots found"); case "a": {
area = PS.get().getPlotAreaByString(split[1]);
if (area == null) {
C.NOT_VALID_PLOT_WORLD.send(plr, split[1]);
return false;
}
break;
}
case "plotid":
case "id": {
id = PlotId.fromString(split[1]);
if (id == null) {
C.NOT_VALID_PLOT_ID.send(plr, split[1]);
return false;
}
break;
}
case "owner":
case "o": {
owner = UUIDHandler.getUUID(split[1], null);
if (owner == null) {
C.INVALID_PLAYER.send(plr, split[1]);
return false;
}
break;
}
case "shared":
case "s": {
added = UUIDHandler.getUUID(split[1], null);
if (added == null) {
C.INVALID_PLAYER.send(plr, split[1]);
return false;
}
break;
}
case "unknown":
case "?":
case "u": {
unknown = Boolean.parseBoolean(split[1]);
break;
}
} }
DBFunc.purge(worldname, ids);
return finishPurge(length);
} }
if (arg.equals("unknown")) { final HashSet<Integer> toDelete = new HashSet<>();
final Collection<Plot> plots = PS.get().getPlotsInWorld(worldname); Set<Plot> basePlots = PS.get().getBasePlots();
final Set<PlotId> ids = new HashSet<>(); for (Plot plot : PS.get().getBasePlots()) {
for (final Plot plot : plots) { if (world != null && !plot.area.worldname.equalsIgnoreCase(world)) {
if (plot.owner != null) { continue;
final String name = UUIDHandler.getName(plot.owner); }
if (name == null) { if (area != null && !plot.area.equals(area)) {
ids.add(plot.getId()); continue;
}
if (id != null && !plot.id.equals(id)) {
continue;
}
if (owner != null && !plot.isOwner(owner)) {
continue;
}
if (added != null && !plot.isAdded(added)) {
continue;
}
if (unknown && UUIDHandler.getName(plot.owner) != null) {
continue;
}
for (Plot current : plot.getConnectedPlots()) {
final int DBid = DBFunc.getId(current);
if (DBid != Integer.MAX_VALUE) {
toDelete.add(DBid);
}
}
}
if (PS.get().plots_tmp != null) {
for (Entry<String, HashMap<PlotId, Plot>> entry : PS.get().plots_tmp.entrySet()) {
String worldname = entry.getKey();
if (world != null && !world.equalsIgnoreCase(worldname)) {
continue;
}
for (Entry<PlotId, Plot> entry2 : entry.getValue().entrySet()) {
Plot plot = entry2.getValue();
if (id != null && !plot.id.equals(id)) {
continue;
}
if (owner != null && !plot.isOwner(owner)) {
continue;
}
if (added != null && !plot.isAdded(added)) {
continue;
}
if (unknown && UUIDHandler.getName(plot.owner) != null) {
continue;
}
final int DBid = DBFunc.getId(plot);
if (DBid != Integer.MAX_VALUE) {
toDelete.add(DBid);
} }
} }
} }
final int length = ids.size();
if (length == 0) {
return MainUtil.sendMessage(plr, "&cNo plots found");
}
DBFunc.purge(worldname, ids);
return finishPurge(length);
} }
if (arg.equals("unowned")) { if (toDelete.size() == 0) {
final Collection<Plot> plots = PS.get().getPlotsInWorld(worldname); C.FOUND_NO_PLOTS.send(plr);
final Set<PlotId> ids = new HashSet<>(); return false;
for (final Plot plot : plots) {
if (plot.owner == null) {
ids.add(plot.getId());
}
}
final int length = ids.size();
if (length == 0) {
return MainUtil.sendMessage(plr, "&cNo plots found");
}
DBFunc.purge(worldname, ids);
return finishPurge(length);
} }
final UUID uuid = UUIDHandler.getUUID(args[0], null); String cmd = "/plot purge " + StringMan.join(args, " ") + " (" + toDelete.size() + " plots)";
if (uuid != null) { CmdConfirm.addPending(plr, cmd, new Runnable() {
final Set<Plot> plots = PS.get().getPlots(worldname, uuid); @Override
final Set<PlotId> ids = new HashSet<>(); public void run() {
for (final Plot plot : plots) { DBFunc.purgeIds(toDelete);
ids.add(plot.getId()); C.PURGE_SUCCESS.send(plr, toDelete.size() + "");
} }
final int length = ids.size(); });
DBFunc.purge(worldname, ids); return true;
return finishPurge(length);
}
MainUtil.sendMessage(plr, C.PURGE_SYNTAX);
return false;
}
private boolean finishPurge(final int amount) {
MainUtil.sendMessage(null, C.PURGE_SUCCESS, amount + "");
return false;
} }
} }

View File

@ -33,7 +33,6 @@ import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotInventory; import com.intellectualcrafters.plot.object.PlotInventory;
import com.intellectualcrafters.plot.object.PlotItemStack; import com.intellectualcrafters.plot.object.PlotItemStack;
@ -89,7 +88,7 @@ public class Rate extends SubCommand {
&& p.isBasePlot() && p.isBasePlot()
&& ((p.getSettings().ratings == null) || !p.getSettings().ratings.containsKey(uuid)) && ((p.getSettings().ratings == null) || !p.getSettings().ratings.containsKey(uuid))
&& !p.isAdded(uuid)) { && !p.isAdded(uuid)) {
MainUtil.teleportPlayer(player, player.getLocation(), p); p.teleportPlayer(player);
MainUtil.sendMessage(player, C.RATE_THIS); MainUtil.sendMessage(player, C.RATE_THIS);
return true; return true;
} }
@ -98,8 +97,7 @@ public class Rate extends SubCommand {
return false; return false;
} }
} }
final Location loc = player.getLocation(); final Plot plot = player.getCurrentPlot();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) { if (plot == null) {
return !sendMessage(player, C.NOT_IN_PLOT); return !sendMessage(player, C.NOT_IN_PLOT);
} }

View File

@ -27,10 +27,12 @@ import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.generator.HybridPlotManager; import com.intellectualcrafters.plot.generator.HybridPlotManager;
import com.intellectualcrafters.plot.generator.HybridUtils; import com.intellectualcrafters.plot.generator.HybridUtils;
import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.WorldUtil;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration( @CommandDeclaration(
@ -58,8 +60,13 @@ public class RegenAllRoads extends SubCommand {
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot regenallroads <world> [height]"); MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot regenallroads <world> [height]");
return false; return false;
} }
PlotArea area = PS.get().getPlotAreaByString(args[0]);
if (area == null || WorldUtil.IMP.isWorld(area.worldname)) {
C.NOT_VALID_PLOT_WORLD.send(plr, args[0]);
return false;
}
final String name = args[0]; final String name = args[0];
final PlotManager manager = PS.get().getPlotManager(name); final PlotManager manager = area.getPlotManager();
if ((manager == null) || !(manager instanceof HybridPlotManager)) { if ((manager == null) || !(manager instanceof HybridPlotManager)) {
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_WORLD); MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_WORLD);
return false; return false;
@ -69,7 +76,7 @@ public class RegenAllRoads extends SubCommand {
MainUtil.sendMessage(plr, "&7 - To set a schematic, stand in a plot and use &c/plot createroadschematic"); MainUtil.sendMessage(plr, "&7 - To set a schematic, stand in a plot and use &c/plot createroadschematic");
MainUtil.sendMessage(plr, "&6Potential chunks to update: &7" + (chunks.size() * 1024)); MainUtil.sendMessage(plr, "&6Potential chunks to update: &7" + (chunks.size() * 1024));
MainUtil.sendMessage(plr, "&6Estimated time: &7" + (chunks.size()) + " seconds"); MainUtil.sendMessage(plr, "&6Estimated time: &7" + (chunks.size()) + " seconds");
final boolean result = HybridUtils.manager.scheduleRoadUpdate(name, height); final boolean result = HybridUtils.manager.scheduleRoadUpdate(area, height);
if (!result) { if (!result) {
MainUtil.sendMessage(plr, "&cCannot schedule mass schematic update! (Is one already in progress?)"); MainUtil.sendMessage(plr, "&cCannot schedule mass schematic update! (Is one already in progress?)");
return false; return false;

View File

@ -20,11 +20,16 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.Objects;
import com.intellectualcrafters.configuration.ConfigurationSection; import com.intellectualcrafters.configuration.ConfigurationSection;
import com.intellectualcrafters.configuration.MemorySection;
import com.intellectualcrafters.configuration.file.YamlConfiguration;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
@ -40,12 +45,52 @@ public class Reload extends SubCommand {
PS.get().config.load(PS.get().configFile); PS.get().config.load(PS.get().configFile);
PS.get().setupConfig(); PS.get().setupConfig();
C.load(PS.get().translationFile); C.load(PS.get().translationFile);
for (final String pw : PS.get().getPlotWorlds()) { PS.get().foreachPlotArea(new RunnableVal<PlotArea>() {
final PlotWorld plotworld = PS.get().getPlotWorld(pw); @Override
final ConfigurationSection section = PS.get().config.getConfigurationSection("worlds." + pw); public void run(PlotArea area) {
plotworld.saveConfiguration(section); final ConfigurationSection worldSection = PS.get().config.getConfigurationSection("worlds." + area.worldname);
plotworld.loadDefaultConfiguration(section); if (area.TYPE != 2 || !worldSection.contains("areas")) {
} area.saveConfiguration(worldSection);
area.loadDefaultConfiguration(worldSection);
} else {
ConfigurationSection areaSection = worldSection.getConfigurationSection("areas." + area.id + "-" + area.getMin() + "-" + area.getMax());
YamlConfiguration clone = new YamlConfiguration();
for (String key : areaSection.getKeys(true)) {
if (areaSection.get(key) instanceof MemorySection) {
continue;
}
if (!clone.contains(key)) {
clone.set(key, areaSection.get(key));
}
}
for (String key : worldSection.getKeys(true)) {
if (worldSection.get(key) instanceof MemorySection) {
continue;
}
if (!key.startsWith("areas") && !clone.contains(key)) {
clone.set(key, worldSection.get(key));
}
}
area.saveConfiguration(clone);
// netSections is the combination of
for (String key : clone.getKeys(true)) {
if (clone.get(key) instanceof MemorySection) {
continue;
}
if (!worldSection.contains(key)) {
worldSection.set(key, clone.get(key));
} else {
Object value = worldSection.get(key);
if (Objects.equals(value, clone.get(key))) {
areaSection.set(key, clone.get(key));
}
}
}
area.loadDefaultConfiguration(clone);
}
}
});
PS.get().config.save(PS.get().configFile);
MainUtil.sendMessage(plr, C.RELOADED_CONFIGS); MainUtil.sendMessage(plr, C.RELOADED_CONFIGS);
} catch (final Exception e) { } catch (final Exception e) {
e.printStackTrace(); e.printStackTrace();

View File

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

View File

@ -30,10 +30,10 @@ public class Save extends SubCommand {
return false; return false;
} }
final String world = plr.getLocation().getWorld(); final String world = plr.getLocation().getWorld();
if (!PS.get().isPlotWorld(world)) { if (!PS.get().hasPlotArea(world)) {
return !sendMessage(plr, C.NOT_IN_PLOT_WORLD); return !sendMessage(plr, C.NOT_IN_PLOT_WORLD);
} }
final Plot plot = MainUtil.getPlotAbs(plr.getLocation()); final Plot plot = plr.getCurrentPlot();
if (plot == null) { if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT); return !sendMessage(plr, C.NOT_IN_PLOT);
} }
@ -50,18 +50,18 @@ public class Save extends SubCommand {
return false; return false;
} }
plot.addRunning(); plot.addRunning();
SchematicHandler.manager.getCompoundTag(plot.world, plot.getId(), new RunnableVal<CompoundTag>() { SchematicHandler.manager.getCompoundTag(plot, new RunnableVal<CompoundTag>() {
@Override @Override
public void run() { public void run(final CompoundTag value) {
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTaskAsync(new Runnable() {
@Override @Override
public void run() { public void run() {
final String time = (System.currentTimeMillis() / 1000) + ""; final String time = (System.currentTimeMillis() / 1000) + "";
final String name = PS.get().IMP.getServerName().replaceAll("[^A-Za-z0-9]", ""); final String name = PS.get().IMP.getServerName().replaceAll("[^A-Za-z0-9]", "");
Location[] corners = MainUtil.getCorners(plot); Location[] corners = plot.getCorners();
final int size = (corners[1].getX() - corners[0].getX()) + 1; final int size = (corners[1].getX() - corners[0].getX()) + 1;
final PlotId id = plot.getId(); final PlotId id = plot.getId();
final String world = plot.world.replaceAll("[^A-Za-z0-9]", ""); final String world = plot.area.toString().replaceAll(";", "-").replaceAll("[^A-Za-z0-9]", "");
final String file = time + "_" + world + "_" + id.x + "_" + id.y + "_" + size + "_" + name; final String file = time + "_" + world + "_" + id.x + "_" + id.y + "_" + size + "_" + name;
final UUID uuid = plr.getUUID(); final UUID uuid = plr.getUUID();

View File

@ -31,6 +31,7 @@ import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.object.ConsolePlayer; import com.intellectualcrafters.plot.object.ConsolePlayer;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
@ -71,7 +72,7 @@ public class SchematicCmd extends SubCommand {
break; break;
} }
final Location loc = plr.getLocation(); final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlotAbs(loc); final Plot plot = loc.getPlotAbs();
if (plot == null) { if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT); return !sendMessage(plr, C.NOT_IN_PLOT);
} }
@ -115,7 +116,7 @@ public class SchematicCmd extends SubCommand {
} }
SchematicHandler.manager.paste(schematic, plot, 0, 0, new RunnableVal<Boolean>() { SchematicHandler.manager.paste(schematic, plot, 0, 0, new RunnableVal<Boolean>() {
@Override @Override
public void run() { public void run(Boolean value) {
running = false; running = false;
if (value) { if (value) {
sendMessage(plr, C.SCHEMATIC_PASTE_SUCCESS); sendMessage(plr, C.SCHEMATIC_PASTE_SUCCESS);
@ -167,12 +168,17 @@ public class SchematicCmd extends SubCommand {
return false; return false;
} }
if (args.length != 2) { if (args.length != 2) {
MainUtil.sendMessage(plr, "&cNeed world arg. Use &7/plots sch exportall <world>"); MainUtil.sendMessage(plr, "&cNeed world arg. Use &7/plots sch exportall <area>");
return false; return false;
} }
final Collection<Plot> plots = PS.get().getPlotsInWorld(args[1]); PlotArea area = PS.get().getPlotAreaByString(args[1]);
if (area == null) {
C.NOT_VALID_PLOT_WORLD.send(plr, args[1]);
return false;
}
final Collection<Plot> plots = area.getPlots();
if ((plots.size() == 0)) { if ((plots.size() == 0)) {
MainUtil.sendMessage(plr, "&cInvalid world. Use &7/plots sch exportall <world>"); MainUtil.sendMessage(plr, "&cInvalid world. Use &7/plots sch exportall <area>");
return false; return false;
} }
final boolean result = SchematicHandler.manager.exportAll(plots, null, null, new Runnable() { final boolean result = SchematicHandler.manager.exportAll(plots, null, null, new Runnable() {
@ -202,7 +208,7 @@ public class SchematicCmd extends SubCommand {
} }
final Plot p2; final Plot p2;
final Location loc = plr.getLocation(); final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlotAbs(loc); final Plot plot = loc.getPlotAbs();
if (plot == null) { if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT); return !sendMessage(plr, C.NOT_IN_PLOT);
} }

View File

@ -20,28 +20,28 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Configuration; import com.intellectualcrafters.plot.config.Configuration;
import com.intellectualcrafters.plot.flag.AbstractFlag; import com.intellectualcrafters.plot.flag.AbstractFlag;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.SetBlockQueue; import com.intellectualcrafters.plot.util.SetQueue;
import com.intellectualcrafters.plot.util.StringComparison; import com.intellectualcrafters.plot.util.StringComparison;
import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.WorldUtil;
import com.plotsquared.general.commands.Command; import com.plotsquared.general.commands.Command;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
@CommandDeclaration( @CommandDeclaration(
command = "set", command = "set",
description = "Set a plot value", description = "Set a plot value",
@ -66,7 +66,7 @@ public class Set extends SubCommand {
@Override @Override
public boolean set(PlotPlayer plr, final Plot plot, String value) { public boolean set(PlotPlayer plr, final Plot plot, String value) {
final PlotWorld plotworld = plr.getLocation().getPlotWorld(); final PlotArea plotworld = plr.getLocation().getPlotArea();
final PlotManager manager = plr.getLocation().getPlotManager(); final PlotManager manager = plr.getLocation().getPlotManager();
final String[] components = manager.getPlotComponents(plotworld, plot.getId()); final String[] components = manager.getPlotComponents(plotworld, plot.getId());
final boolean allowUnsafe = DebugAllowUnsafe.unsafeAllowed.contains(plr.getUUID()); final boolean allowUnsafe = DebugAllowUnsafe.unsafeAllowed.contains(plr.getUUID());
@ -98,22 +98,22 @@ public class Set extends SubCommand {
} else { } else {
name = split[i]; name = split[i];
} }
final StringComparison<PlotBlock>.ComparisonResult match = BlockManager.manager.getClosestBlock(name); final StringComparison<PlotBlock>.ComparisonResult match = WorldUtil.IMP.getClosestBlock(name);
if (match != null) { if (match != null) {
name = BlockManager.manager.getClosestMatchingName(match.best); name = WorldUtil.IMP.getClosestMatchingName(match.best);
if (name != null) { if (name != null) {
MainUtil.sendMessage(plr, C.DID_YOU_MEAN, name.toLowerCase()); MainUtil.sendMessage(plr, C.DID_YOU_MEAN, name.toLowerCase());
} }
} }
return false; return false;
} else if (!allowUnsafe && !BlockManager.manager.isBlockSolid(block)) { } else if (!allowUnsafe && !WorldUtil.IMP.isBlockSolid(block)) {
MainUtil.sendMessage(plr, C.NOT_ALLOWED_BLOCK, block.toString()); MainUtil.sendMessage(plr, C.NOT_ALLOWED_BLOCK, block.toString());
return false; return false;
} }
} }
if (!allowUnsafe) { if (!allowUnsafe) {
for (final PlotBlock block : blocks) { for (final PlotBlock block : blocks) {
if (!BlockManager.manager.isBlockSolid(block)) { if (!WorldUtil.IMP.isBlockSolid(block)) {
MainUtil.sendMessage(plr, C.NOT_ALLOWED_BLOCK, block.toString()); MainUtil.sendMessage(plr, C.NOT_ALLOWED_BLOCK, block.toString());
return false; return false;
} }
@ -128,11 +128,11 @@ public class Set extends SubCommand {
return false; return false;
} }
plot.addRunning(); plot.addRunning();
for (Plot current : MainUtil.getConnectedPlots(plot)) { for (Plot current : plot.getConnectedPlots()) {
manager.setComponent(plotworld, current.getId(), component, blocks); manager.setComponent(plotworld, current.getId(), component, blocks);
} }
MainUtil.sendMessage(plr, C.GENERATING_COMPONENT); MainUtil.sendMessage(plr, C.GENERATING_COMPONENT);
SetBlockQueue.addNotify(new Runnable() { SetQueue.IMP.addTask(new Runnable() {
@Override @Override
public void run() { public void run() {
plot.removeRunning(); plot.removeRunning();
@ -151,7 +151,7 @@ public class Set extends SubCommand {
newValues.addAll(Arrays.asList("biome", "alias", "home", "flag")); newValues.addAll(Arrays.asList("biome", "alias", "home", "flag"));
Plot plot = plr.getCurrentPlot(); Plot plot = plr.getCurrentPlot();
if (plot != null) { if (plot != null) {
newValues.addAll(Arrays.asList(plot.getManager().getPlotComponents(plot.getWorld(), plot.getId()))); newValues.addAll(Arrays.asList(plot.getManager().getPlotComponents(plot.getArea(), plot.getId())));
} }
MainUtil.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + StringMan.join(newValues, C.BLOCK_LIST_SEPARATER.formatted())); MainUtil.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + StringMan.join(newValues, C.BLOCK_LIST_SEPARATER.formatted()));
return false; return false;
@ -173,7 +173,7 @@ public class Set extends SubCommand {
return false; return false;
} }
// components // components
HashSet<String> components = new HashSet<>(Arrays.asList(plot.getManager().getPlotComponents(plot.getWorld(), plot.getId()))); HashSet<String> components = new HashSet<>(Arrays.asList(plot.getManager().getPlotComponents(plot.getArea(), plot.getId())));
if (components.contains(args[0].toLowerCase())) { if (components.contains(args[0].toLowerCase())) {
return component.onCommand(plr, Arrays.copyOfRange(args, 0, args.length)); return component.onCommand(plr, Arrays.copyOfRange(args, 0, args.length));
} }

View File

@ -13,7 +13,7 @@ public abstract class SetCommand extends SubCommand {
@Override @Override
public boolean onCommand(PlotPlayer plr, String[] args) { public boolean onCommand(PlotPlayer plr, String[] args) {
final Location loc = plr.getLocation(); final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlotAbs(loc); final Plot plot = loc.getPlotAbs();
if (plot == null) { if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT); return !sendMessage(plr, C.NOT_IN_PLOT);
} }

View File

@ -20,24 +20,25 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.ConfigurationNode;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.generator.PlotGenerator;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.SetupObject;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.SetupUtils;
import com.intellectualcrafters.plot.util.StringMan;
import com.plotsquared.general.commands.CommandDeclaration;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.ConfigurationNode;
import com.intellectualcrafters.plot.generator.GeneratorWrapper;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.SetupObject;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.SetupUtils;
import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.WorldUtil;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration( @CommandDeclaration(
command = "setup", command = "setup",
permission = "plots.admin.command.setup", permission = "plots.admin.command.setup",
@ -50,7 +51,7 @@ public class Setup extends SubCommand {
public void displayGenerators(final PlotPlayer plr) { public void displayGenerators(final PlotPlayer plr) {
final StringBuilder message = new StringBuilder(); final StringBuilder message = new StringBuilder();
message.append("&6What generator do you want?"); message.append("&6What generator do you want?");
for (final Entry<String, PlotGenerator<?>> entry : SetupUtils.generators.entrySet()) { for (final Entry<String, GeneratorWrapper<?>> entry : SetupUtils.generators.entrySet()) {
if (entry.getKey().equals("PlotSquared")) { if (entry.getKey().equals("PlotSquared")) {
message.append("\n&8 - &2").append(entry.getKey()).append(" (Default Generator)"); message.append("\n&8 - &2").append(entry.getKey()).append(" (Default Generator)");
} else if (entry.getValue().isFull()) { } else if (entry.getValue().isFull()) {
@ -65,10 +66,10 @@ public class Setup extends SubCommand {
@Override @Override
public boolean onCommand(final PlotPlayer plr, final String[] args) { public boolean onCommand(final PlotPlayer plr, final String[] args) {
// going through setup // going through setup
final String name = plr.getName(); SetupObject object = (SetupObject) plr.getMeta("setup");
if (!SetupUtils.setupMap.containsKey(name)) { if (object == null) {
final SetupObject object = new SetupObject(); object = new SetupObject();
SetupUtils.setupMap.put(name, object); plr.setMeta("setup", object);
SetupUtils.manager.updateGenerators(); SetupUtils.manager.updateGenerators();
sendMessage(plr, C.SETUP_INIT); sendMessage(plr, C.SETUP_INIT);
displayGenerators(plr); displayGenerators(plr);
@ -76,12 +77,11 @@ public class Setup extends SubCommand {
} }
if (args.length == 1) { if (args.length == 1) {
if (args[0].equalsIgnoreCase("cancel")) { if (args[0].equalsIgnoreCase("cancel")) {
SetupUtils.setupMap.remove(name); plr.deleteMeta("setup");
MainUtil.sendMessage(plr, "&aCancelled setup"); MainUtil.sendMessage(plr, "&aCancelled setup");
return false; return false;
} }
if (args[0].equalsIgnoreCase("back")) { if (args[0].equalsIgnoreCase("back")) {
final SetupObject object = SetupUtils.setupMap.get(name);
if (object.setup_index > 0) { if (object.setup_index > 0) {
object.setup_index--; object.setup_index--;
final ConfigurationNode node = object.step[object.setup_index]; final ConfigurationNode node = object.step[object.setup_index];
@ -92,7 +92,6 @@ public class Setup extends SubCommand {
} }
} }
} }
final SetupObject object = SetupUtils.setupMap.get(name);
final int index = object.current; final int index = object.current;
switch (index) { switch (index) {
case 0: { // choose generator case 0: { // choose generator
@ -104,7 +103,7 @@ public class Setup extends SubCommand {
} }
object.setupGenerator = args[0]; object.setupGenerator = args[0];
object.current++; object.current++;
final String partial = Settings.ENABLE_CLUSTERS ? "\n&8 - &7PARTIAL&8 - &7Vanilla with clusters of plots" : ""; final String partial = "\n&8 - &7PARTIAL&8 - &7Vanilla with clusters of plots";
MainUtil.sendMessage(plr, "&6What world type do you want?" + "\n&8 - &2DEFAULT&8 - &7Standard plot generation" + "\n&8 - &7AUGMENTED&8 - &7Plot generation with terrain" + partial); MainUtil.sendMessage(plr, "&6What world type do you want?" + "\n&8 - &2DEFAULT&8 - &7Standard plot generation" + "\n&8 - &7AUGMENTED&8 - &7Plot generation with terrain" + partial);
break; break;
} }
@ -117,9 +116,7 @@ public class Setup extends SubCommand {
types.add("default"); types.add("default");
} }
types.add("augmented"); types.add("augmented");
if (Settings.ENABLE_CLUSTERS) { types.add("partial");
types.add("partial");
}
if ((args.length != 1) || !types.contains(args[0].toLowerCase())) { if ((args.length != 1) || !types.contains(args[0].toLowerCase())) {
MainUtil.sendMessage(plr, "&cYou must choose a world type!"); MainUtil.sendMessage(plr, "&cYou must choose a world type!");
for (final String type : types) { for (final String type : types) {
@ -133,16 +130,16 @@ public class Setup extends SubCommand {
return false; return false;
} }
object.type = allTypes.indexOf(args[0].toLowerCase()); object.type = allTypes.indexOf(args[0].toLowerCase());
final PlotGenerator<?> gen = SetupUtils.generators.get(object.setupGenerator); final GeneratorWrapper<?> gen = SetupUtils.generators.get(object.setupGenerator);
if (object.type == 0) { if (object.type == 0) {
object.current++; object.current = 7;
if (object.step == null) { if (object.step == null) {
object.plotManager = object.setupGenerator; object.plotManager = object.setupGenerator;
object.step = SetupUtils.generators.get(object.plotManager).getNewPlotWorld(null).getSettingNodes(); object.step = SetupUtils.generators.get(object.plotManager).getPlotGenerator().getNewPlotArea("CheckingPlotSquaredGenerator", null, null, null).getSettingNodes();
SetupUtils.generators.get(object.plotManager).processSetup(object); SetupUtils.generators.get(object.plotManager).getPlotGenerator().processSetup(object);
} }
if (object.step.length == 0) { if (object.step.length == 0) {
object.current = 4; object.current = 7;
MainUtil.sendMessage(plr, "&6What do you want your world to be called?"); MainUtil.sendMessage(plr, "&6What do you want your world to be called?");
object.setup_index = 0; object.setup_index = 0;
return true; return true;
@ -153,24 +150,75 @@ public class Setup extends SubCommand {
if (gen.isFull()) { if (gen.isFull()) {
object.plotManager = object.setupGenerator; object.plotManager = object.setupGenerator;
object.setupGenerator = null; object.setupGenerator = null;
object.step = SetupUtils.generators.get(object.plotManager).getNewPlotWorld(null).getSettingNodes(); object.step = SetupUtils.generators.get(object.plotManager).getPlotGenerator().getNewPlotArea("CheckingPlotSquaredGenerator", null, null, null).getSettingNodes();
SetupUtils.generators.get(object.plotManager).processSetup(object); SetupUtils.generators.get(object.plotManager).getPlotGenerator().processSetup(object);
} else { } else {
object.plotManager = "PlotSquared"; object.plotManager = "PlotSquared";
MainUtil.sendMessage(plr, "&c[WARNING] The specified generator does not identify as BukkitPlotGenerator"); MainUtil.sendMessage(plr, "&c[WARNING] The specified generator does not identify as BukkitPlotGenerator");
MainUtil.sendMessage(plr, "&7 - You may need to manually configure the other plugin"); MainUtil.sendMessage(plr, "&7 - You may need to manually configure the other plugin");
object.step = SetupUtils.generators.get(object.plotManager).getNewPlotWorld(null).getSettingNodes(); object.step = SetupUtils.generators.get(object.plotManager).getPlotGenerator().getNewPlotArea("CheckingPlotSquaredGenerator", null, null, null).getSettingNodes();
}
if (object.type == 2) {
MainUtil.sendMessage(plr, "What would you like this area called?");
object.current++;
} else {
MainUtil.sendMessage(plr, "&6What terrain would you like in plots?"
+ "\n&8 - &2NONE&8 - &7No terrain at all"
+ "\n&8 - &7ORE&8 - &7Just some ore veins and trees"
+ "\n&8 - &7ROAD&8 - &7Terrain separated by roads"
+ "\n&8 - &7ALL&8 - &7Entirely vanilla generation");
object.current = 5;
} }
MainUtil.sendMessage(plr, "&6What terrain would you like in plots?"
+ "\n&8 - &2NONE&8 - &7No terrain at all"
+ "\n&8 - &7ORE&8 - &7Just some ore veins and trees"
+ "\n&8 - &7ROAD&8 - &7Terrain separated by roads"
+ "\n&8 - &7ALL&8 - &7Entirely vanilla generation");
} }
object.current++;
break; break;
} }
case 2: { // Choose terrain case 2: { // area id
if (!StringMan.isAlphanumericUnd(args[0])) {
MainUtil.sendMessage(plr, "&cThe area id must be alphanumerical!");
return false;
}
for (PlotArea area : PS.get().getPlotAreas()) {
if (area.id != null && area.id.equalsIgnoreCase(args[0])) {
MainUtil.sendMessage(plr, "&cYou must choose an area id that is not in use!");
return false;
}
}
object.id = args[0];
object.current++;
MainUtil.sendMessage(plr, "&6What should be the minimum Plot Id?");
break;
}
case 3: { // min
object.min = PlotId.fromString(args[0]);
if (object.min == null) {
MainUtil.sendMessage(plr, "&cYou must choose a valid minimum PlotId!");
return false;
}
object.current++;
MainUtil.sendMessage(plr, "&6What should be the maximum Plot Id?");
break;
}
case 4: {
// max
PlotId id = PlotId.fromString(args[0]);
if (id == null) {
MainUtil.sendMessage(plr, "&cYou must choose a valid maximum PlotId!");
return false;
}
if (id.x <= object.min.x || id.y <= object.min.y) {
MainUtil.sendMessage(plr, "&cThe max PlotId must be greater than the minimum!");
return false;
}
object.max = id;
object.current++;
MainUtil.sendMessage(plr, "&6What terrain would you like in plots?"
+ "\n&8 - &2NONE&8 - &7No terrain at all"
+ "\n&8 - &7ORE&8 - &7Just some ore veins and trees"
+ "\n&8 - &7ROAD&8 - &7Terrain separated by roads"
+ "\n&8 - &7ALL&8 - &7Entirely vanilla generation");
break;
}
case 5: { // Choose terrain
final List<String> terrain = Arrays.asList("none", "ore", "road", "all"); final List<String> terrain = Arrays.asList("none", "ore", "road", "all");
if ((args.length != 1) || !terrain.contains(args[0].toLowerCase())) { if ((args.length != 1) || !terrain.contains(args[0].toLowerCase())) {
MainUtil.sendMessage(plr, "&cYou must choose the terrain!" MainUtil.sendMessage(plr, "&cYou must choose the terrain!"
@ -183,13 +231,13 @@ public class Setup extends SubCommand {
object.terrain = terrain.indexOf(args[0].toLowerCase()); object.terrain = terrain.indexOf(args[0].toLowerCase());
object.current++; object.current++;
if (object.step == null) { if (object.step == null) {
object.step = SetupUtils.generators.get(object.plotManager).getNewPlotWorld(null).getSettingNodes(); object.step = SetupUtils.generators.get(object.plotManager).getPlotGenerator().getNewPlotArea("CheckingPlotSquaredGenerator", null, null, null).getSettingNodes();
} }
final ConfigurationNode step = object.step[object.setup_index]; final ConfigurationNode step = object.step[object.setup_index];
sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + ""); sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + "");
break; break;
} }
case 3: { // world setup case 6: { // world setup
if (object.setup_index == object.step.length) { if (object.setup_index == object.step.length) {
MainUtil.sendMessage(plr, "&6What do you want your world to be called?"); MainUtil.sendMessage(plr, "&6What do you want your world to be called?");
object.setup_index = 0; object.setup_index = 0;
@ -219,13 +267,13 @@ public class Setup extends SubCommand {
return false; return false;
} }
} }
case 4: { case 7: {
if (args.length != 1) { if (args.length != 1) {
MainUtil.sendMessage(plr, "&cYou need to choose a world name!"); MainUtil.sendMessage(plr, "&cYou need to choose a world name!");
return false; return false;
} }
if (BlockManager.manager.isWorld(args[0])) { if (WorldUtil.IMP.isWorld(args[0])) {
if (PS.get().isPlotWorld(args[0])) { if (PS.get().hasPlotArea(args[0])) {
MainUtil.sendMessage(plr, "&cThat world name is already taken!"); MainUtil.sendMessage(plr, "&cThat world name is already taken!");
return false; return false;
} }
@ -233,7 +281,7 @@ public class Setup extends SubCommand {
"&cThe world you specified already exists. After restarting, new terrain will use PlotSquared, however you may need to reset the world for it to generate correctly!"); "&cThe world you specified already exists. After restarting, new terrain will use PlotSquared, however you may need to reset the world for it to generate correctly!");
} }
object.world = args[0]; object.world = args[0];
SetupUtils.setupMap.remove(name); plr.deleteMeta("setup");
final String world; final String world;
if (object.setupManager == null) { if (object.setupManager == null) {
world = SetupUtils.manager.setupWorld(object); world = SetupUtils.manager.setupWorld(object);
@ -241,13 +289,12 @@ public class Setup extends SubCommand {
world = object.setupManager.setupWorld(object); world = object.setupManager.setupWorld(object);
} }
try { try {
plr.teleport(BlockManager.manager.getSpawn(world)); plr.teleport(WorldUtil.IMP.getSpawn(world));
} catch (final Exception e) { } catch (final Exception e) {
plr.sendMessage("&cAn error occurred. See console for more information"); plr.sendMessage("&cAn error occurred. See console for more information");
e.printStackTrace(); e.printStackTrace();
} }
sendMessage(plr, C.SETUP_FINISHED, object.world); sendMessage(plr, C.SETUP_FINISHED, object.world);
SetupUtils.setupMap.remove(name);
} }
} }
return false; return false;

View File

@ -34,7 +34,7 @@ public class Swap extends SubCommand {
@Override @Override
public boolean onCommand(final PlotPlayer plr, final String[] args) { public boolean onCommand(final PlotPlayer plr, final String[] args) {
final Location loc = plr.getLocation(); final Location loc = plr.getLocation();
final Plot plot1 = MainUtil.getPlotAbs(loc); final Plot plot1 = loc.getPlotAbs();
if (plot1 == null) { if (plot1 == null) {
return !MainUtil.sendMessage(plr, C.NOT_IN_PLOT); return !MainUtil.sendMessage(plr, C.NOT_IN_PLOT);
} }
@ -55,11 +55,11 @@ public class Swap extends SubCommand {
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot copy <X;Z>"); MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot copy <X;Z>");
return false; return false;
} }
if (!plot1.getWorld().isCompatible(plot2.getWorld())) { if (!plot1.area.isCompatible(plot2.area)) {
C.PLOTWORLD_INCOMPATIBLE.send(plr); C.PLOTWORLD_INCOMPATIBLE.send(plr);
return false; return false;
} }
if (MainUtil.move(plot1, plot2, new Runnable() { if (plot1.move(plot2, new Runnable() {
@Override @Override
public void run() { public void run() {
MainUtil.sendMessage(plr, C.SWAP_SUCCESS); MainUtil.sendMessage(plr, C.SWAP_SUCCESS);

View File

@ -1,99 +0,0 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(command = "tp", description = "Teleport to a plot", permission = "plots.tp", usage = "/plot tp <alias|id>", requiredType = RequiredType.NONE, category = CommandCategory.TELEPORT)
public class TP extends SubCommand {
public TP() {
requiredArguments = new Argument[] { Argument.String };
}
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
final String id = args[0];
PlotId plotid;
final Location loc = plr.getLocation();
final String pworld = loc.getWorld();
String world = pworld;
if (args.length == 2) {
if (BlockManager.manager.isWorld(args[1])) {
world = args[1];
}
}
if (!PS.get().isPlotWorld(world)) {
MainUtil.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
return false;
}
Plot temp;
if ((temp = isAlias(world, id)) != null) {
MainUtil.teleportPlayer(plr, plr.getLocation(), temp);
return true;
}
try {
plotid = new PlotId(Integer.parseInt(id.split(";")[0]), Integer.parseInt(id.split(";")[1]));
MainUtil.teleportPlayer(plr, plr.getLocation(), MainUtil.getPlotAbs(world, plotid));
return true;
} catch (final Exception e) {
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
}
return false;
}
private Plot isAlias(final String world, String a) {
int index = 0;
if (a.contains(";")) {
final String[] split = a.split(";");
if ((split[1].length() > 0) && MathMan.isInteger(split[1])) {
index = Integer.parseInt(split[1]);
}
a = split[0];
}
final PlotPlayer player = UUIDHandler.getPlayer(a);
if (player != null) {
final java.util.Set<Plot> plotMainPlots = PS.get().getPlots(world, player);
final Plot[] plots = plotMainPlots.toArray(new Plot[plotMainPlots.size()]);
if (plots.length > index) {
return plots[index];
}
return null;
}
for (final Plot p : PS.get().getPlotsInWorld(world)) {
if ((p.getAlias().length() > 0) && p.getAlias().equalsIgnoreCase(a)) {
return p;
}
}
return null;
}
}

View File

@ -24,7 +24,6 @@ import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.StringMan;
@ -32,7 +31,7 @@ import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration( @CommandDeclaration(
command = "target", command = "target",
usage = "/plot target <X;Z|nearest>", usage = "/plot target <<plot>|nearest>",
description = "Target a plot with your compass", description = "Target a plot with your compass",
permission = "plots.target", permission = "plots.target",
requiredType = RequiredType.NONE, requiredType = RequiredType.NONE,
@ -42,30 +41,28 @@ public class Target extends SubCommand {
@Override @Override
public boolean onCommand(final PlotPlayer plr, final String[] args) { public boolean onCommand(final PlotPlayer plr, final String[] args) {
final Location ploc = plr.getLocation(); final Location ploc = plr.getLocation();
if (!PS.get().isPlotWorld(ploc.getWorld())) { if (!PS.get().hasPlotArea(ploc.getWorld())) {
MainUtil.sendMessage(plr, C.NOT_IN_PLOT_WORLD); MainUtil.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
return false; return false;
} }
PlotId id = PlotId.fromString(args[0]); Plot target = null;
if (id == null) { if (StringMan.isEqualIgnoreCaseToAny(args[0], "near", "nearest")) {
if (StringMan.isEqualIgnoreCaseToAny(args[0], "near", "nearest")) { int distance = Integer.MAX_VALUE;
Plot closest = null; for (final Plot plot : PS.get().getPlots(ploc.getWorld())) {
int distance = Integer.MAX_VALUE; final double current = plot.getCenter().getEuclideanDistanceSquared(ploc);
for (final Plot plot : PS.get().getPlotsInWorld(ploc.getWorld())) { if (current < distance) {
final double current = plot.getBottomAbs().getEuclideanDistanceSquared(ploc); distance = (int) current;
if (current < distance) { target = plot;
distance = (int) current;
closest = plot;
}
} }
id = closest.getId(); }
} else { if (target == null) {
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID); C.FOUND_NO_PLOTS.send(plr);
return false; return false;
} }
} else if ((target = MainUtil.getPlotFromString(plr, args[0], true)) == null) {
return false;
} }
final Location loc = MainUtil.getPlotHome(ploc.getWorld(), id); plr.setCompassTarget(target.getCenter());
plr.setCompassTarget(loc);
MainUtil.sendMessage(plr, C.COMPASS_TARGET); MainUtil.sendMessage(plr, C.COMPASS_TARGET);
return true; return true;
} }

View File

@ -35,15 +35,15 @@ import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.ConfigurationNode; import com.intellectualcrafters.plot.config.ConfigurationNode;
import com.intellectualcrafters.plot.object.FileBytes; import com.intellectualcrafters.plot.object.FileBytes;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.SetupObject; import com.intellectualcrafters.plot.object.SetupObject;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.SetBlockQueue; import com.intellectualcrafters.plot.util.SetQueue;
import com.intellectualcrafters.plot.util.SetupUtils; import com.intellectualcrafters.plot.util.SetupUtils;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.WorldUtil;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration( @CommandDeclaration(
@ -89,7 +89,7 @@ public class Template extends SubCommand {
} }
} }
public static byte[] getBytes(final PlotWorld plotworld) { public static byte[] getBytes(final PlotArea plotworld) {
final ConfigurationSection section = PS.get().config.getConfigurationSection("worlds." + plotworld.worldname); final ConfigurationSection section = PS.get().config.getConfigurationSection("worlds." + plotworld.worldname);
final YamlConfiguration config = new YamlConfiguration(); final YamlConfiguration config = new YamlConfiguration();
final String generator = SetupUtils.manager.getGenerator(plotworld); final String generator = SetupUtils.manager.getGenerator(plotworld);
@ -139,7 +139,7 @@ public class Template extends SubCommand {
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot template import <world> <template>"); MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot template import <world> <template>");
return false; return false;
} }
if (PS.get().isPlotWorld(world)) { if (PS.get().hasPlotArea(world)) {
MainUtil.sendMessage(plr, C.SETUP_WORLD_TAKEN, world); MainUtil.sendMessage(plr, C.SETUP_WORLD_TAKEN, world);
return false; return false;
} }
@ -177,11 +177,11 @@ public class Template extends SubCommand {
setup.step = new ConfigurationNode[0]; setup.step = new ConfigurationNode[0];
setup.world = world; setup.world = world;
SetupUtils.manager.setupWorld(setup); SetupUtils.manager.setupWorld(setup);
SetBlockQueue.addNotify(new Runnable() { SetQueue.IMP.addTask(new Runnable() {
@Override @Override
public void run() { public void run() {
MainUtil.sendMessage(plr, "Done!"); MainUtil.sendMessage(plr, "Done!");
plr.teleport(BlockManager.manager.getSpawn(world)); plr.teleport(WorldUtil.IMP.getSpawn(world));
} }
}); });
return true; return true;
@ -191,18 +191,18 @@ public class Template extends SubCommand {
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot template export <world>"); MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot template export <world>");
return false; return false;
} }
final PlotWorld plotworld = PS.get().getPlotWorld(world); final PlotArea area = PS.get().getPlotAreaByString(world);
if (!BlockManager.manager.isWorld(world) || (plotworld == null)) { if (area == null) {
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_WORLD); MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_WORLD);
return false; return false;
} }
final PlotManager manager = PS.get().getPlotManager(world); final PlotManager manager = area.getPlotManager();
final PlotPlayer finalPlr = plr; final PlotPlayer finalPlr = plr;
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTaskAsync(new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
manager.exportTemplate(plotworld); manager.exportTemplate(area);
} catch (final Exception e) { } catch (final Exception e) {
e.printStackTrace(); e.printStackTrace();
MainUtil.sendMessage(finalPlr, "Failed: " + e.getMessage()); MainUtil.sendMessage(finalPlr, "Failed: " + e.getMessage());

View File

@ -20,20 +20,6 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.ConsolePlayer;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.general.commands.CommandDeclaration;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
@ -43,6 +29,20 @@ import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.ConsolePlayer;
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.TaskManager;
import com.intellectualcrafters.plot.util.WorldUtil;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration( @CommandDeclaration(
command = "trim", command = "trim",
permission = "plots.admin", permission = "plots.admin",
@ -117,7 +117,7 @@ public class Trim extends SubCommand {
System.currentTimeMillis(); System.currentTimeMillis();
sendMessage("Collecting region data..."); sendMessage("Collecting region data...");
final ArrayList<Plot> plots = new ArrayList<>(); final ArrayList<Plot> plots = new ArrayList<>();
plots.addAll(PS.get().getPlotsInWorld(world)); plots.addAll(PS.get().getPlots(world));
final HashSet<ChunkLoc> chunks = new HashSet<>(ChunkManager.manager.getChunkChunks(world)); final HashSet<ChunkLoc> chunks = new HashSet<>(ChunkManager.manager.getChunkChunks(world));
sendMessage(" - MCA #: " + chunks.size()); sendMessage(" - MCA #: " + chunks.size());
sendMessage(" - CHUNKS: " + (chunks.size() * 1024) + " (max)"); sendMessage(" - CHUNKS: " + (chunks.size() * 1024) + " (max)");
@ -136,8 +136,8 @@ public class Trim extends SubCommand {
} }
final Plot plot = plots.remove(0); final Plot plot = plots.remove(0);
final Location pos1 = MainUtil.getPlotBottomLocAbs(world, plot.getId()); final Location pos1 = plot.getBottom();
final Location pos2 = MainUtil.getPlotTopLocAbs(world, plot.getId()); final Location pos2 = plot.getTop();
final int ccx1 = (pos1.getX() >> 9); final int ccx1 = (pos1.getX() >> 9);
final int ccz1 = (pos1.getZ() >> 9); final int ccz1 = (pos1.getZ() >> 9);
@ -199,7 +199,7 @@ public class Trim extends SubCommand {
return false; return false;
} }
final String world = args[1]; final String world = args[1];
if (!BlockManager.manager.isWorld(world) || (PS.get().getPlotWorld(world) == null)) { if (!WorldUtil.IMP.isWorld(world) || (!PS.get().hasPlotArea(world))) {
MainUtil.sendMessage(plr, C.NOT_VALID_WORLD); MainUtil.sendMessage(plr, C.NOT_VALID_WORLD);
return false; return false;
} }

View File

@ -20,6 +20,8 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.UUID;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
@ -33,8 +35,6 @@ import com.plotsquared.bukkit.uuid.SQLUUIDHandler;
import com.plotsquared.general.commands.Argument; import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
import java.util.UUID;
@CommandDeclaration( @CommandDeclaration(
command = "trust", command = "trust",
aliases = { "t" }, aliases = { "t" },
@ -52,7 +52,7 @@ public class Trust extends SubCommand {
public boolean onCommand(final PlotPlayer plr, final String[] args) { public boolean onCommand(final PlotPlayer plr, final String[] args) {
final Location loc = plr.getLocation(); final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlotAbs(loc); final Plot plot = loc.getPlotAbs();
if (plot == null) { if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT); return !sendMessage(plr, C.NOT_IN_PLOT);
} }
@ -90,7 +90,7 @@ public class Trust extends SubCommand {
if (plot.removeMember(uuid)) { if (plot.removeMember(uuid)) {
plot.addTrusted(uuid); plot.addTrusted(uuid);
} else { } else {
if ((plot.getMembers().size() + plot.getTrusted().size()) >= plot.getWorld().MAX_PLOT_MEMBERS) { if ((plot.getMembers().size() + plot.getTrusted().size()) >= plot.getArea().MAX_PLOT_MEMBERS) {
MainUtil.sendMessage(plr, C.PLOT_MAX_MEMBERS); MainUtil.sendMessage(plr, C.PLOT_MAX_MEMBERS);
return false; return false;
} }

View File

@ -42,7 +42,7 @@ public class Unclaim extends SubCommand {
@Override @Override
public boolean onCommand(final PlotPlayer plr, final String[] args) { public boolean onCommand(final PlotPlayer plr, final String[] args) {
final Location loc = plr.getLocation(); final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlotAbs(loc); final Plot plot = loc.getPlotAbs();
if (plot == null) { if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT); return !sendMessage(plr, C.NOT_IN_PLOT);
} }

View File

@ -51,7 +51,7 @@ public class Undeny extends SubCommand {
public boolean onCommand(final PlotPlayer plr, final String... args) { public boolean onCommand(final PlotPlayer plr, final String... args) {
final Location loc = plr.getLocation(); final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlotAbs(loc); final Plot plot = loc.getPlotAbs();
if (plot == null) { if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT); return !sendMessage(plr, C.NOT_IN_PLOT);
} }

View File

@ -28,6 +28,7 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.CmdConfirm; import com.intellectualcrafters.plot.util.CmdConfirm;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
@ -38,7 +39,7 @@ public class Unlink extends SubCommand {
public boolean onCommand(final PlotPlayer plr, final String[] args) { public boolean onCommand(final PlotPlayer plr, final String[] args) {
final Location loc = plr.getLocation(); final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlotAbs(loc); final Plot plot = loc.getPlotAbs();
if (plot == null) { if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT); return !sendMessage(plr, C.NOT_IN_PLOT);
} }
@ -51,10 +52,20 @@ public class Unlink extends SubCommand {
if (!plot.isMerged()) { if (!plot.isMerged()) {
return sendMessage(plr, C.UNLINK_IMPOSSIBLE); return sendMessage(plr, C.UNLINK_IMPOSSIBLE);
} }
final boolean createRoad;
if (args.length != 0) {
if (args.length != 1 || StringMan.isEqualIgnoreCaseToAny(args[1], "true", "false")) {
C.COMMAND_SYNTAX.send(plr, getUsage());
return false;
}
createRoad = Boolean.parseBoolean(args[1]);
} else {
createRoad = true;
}
final Runnable runnable = new Runnable() { final Runnable runnable = new Runnable() {
@Override @Override
public void run() { public void run() {
if (!MainUtil.unlinkPlot(plot, true, true)) { if (!plot.unlinkPlot(createRoad, createRoad)) {
MainUtil.sendMessage(plr, "&cUnlink has been cancelled"); MainUtil.sendMessage(plr, "&cUnlink has been cancelled");
return; return;
} }

View File

@ -52,7 +52,7 @@ public class Untrust extends SubCommand {
@Override @Override
public boolean onCommand(final PlotPlayer plr, final String[] args) { public boolean onCommand(final PlotPlayer plr, final String[] args) {
final Location loc = plr.getLocation(); final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlotAbs(loc); final Plot plot = loc.getPlotAbs();
if (plot == null) { if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT); return !sendMessage(plr, C.NOT_IN_PLOT);
} }

View File

@ -20,6 +20,14 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
@ -31,20 +39,12 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.Argument; import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
@CommandDeclaration( @CommandDeclaration(
command = "visit", command = "visit",
permission = "plots.visit", permission = "plots.visit",
description = "Visit someones plot", description = "Visit someones plot",
usage = "/plot visit [player|alias|world|id] [#]", usage = "/plot visit [player|alias|world|id] [#]",
aliases = { "v" }, aliases = { "v", "tp", "teleport", "goto" },
requiredType = RequiredType.NONE, requiredType = RequiredType.NONE,
category = CommandCategory.TELEPORT) category = CommandCategory.TELEPORT)
public class Visit extends SubCommand { public class Visit extends SubCommand {
@ -88,8 +88,8 @@ public class Visit extends SubCommand {
final UUID user = UUIDHandler.getCachedUUID(args[0], null); final UUID user = UUIDHandler.getCachedUUID(args[0], null);
if (user != null) { if (user != null) {
unsorted = PS.get().getPlots(user); unsorted = PS.get().getPlots(user);
} else if (PS.get().isPlotWorld(args[0])) { } else if (PS.get().getPlotAreaByString(args[0]) != null) {
unsorted = PS.get().getPlotsInWorld(args[0]); unsorted = PS.get().getPlotAreaByString(args[0]).getPlots();
} else { } else {
final Plot plot = MainUtil.getPlotFromString(player, args[0], true); final Plot plot = MainUtil.getPlotFromString(player, args[0], true);
if (plot != null) { if (plot != null) {
@ -147,7 +147,7 @@ public class Visit extends SubCommand {
return false; return false;
} }
} }
MainUtil.teleportPlayer(player, player.getLocation(), plot); plot.teleportPlayer(player);
return true; return true;
} }

View File

@ -21,6 +21,7 @@
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.Iterator; import java.util.Iterator;
@ -34,6 +35,7 @@ import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotMessage; import com.intellectualcrafters.plot.object.PlotMessage;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.Rating; import com.intellectualcrafters.plot.object.Rating;
@ -48,11 +50,11 @@ import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration( @CommandDeclaration(
command = "list", command = "list",
aliases = { "l" }, aliases = { "l", "find", "search" },
description = "List plots", description = "List plots",
permission = "plots.list", permission = "plots.list",
category = CommandCategory.INFO, category = CommandCategory.INFO,
usage = "/plot list <forsale|mine|shared|world|top|all|unowned|unknown|player|world|done> [#]") usage = "/plot list <forsale|mine|shared|world|top|all|unowned|unknown|player|world|done|fuzzy <search...>> [#]")
public class list extends SubCommand { public class list extends SubCommand {
private String[] getArgumentList(final PlotPlayer player) { private String[] getArgumentList(final PlotPlayer player) {
@ -90,6 +92,9 @@ public class list extends SubCommand {
if (Permissions.hasPermission(player, "plots.list.done")) { if (Permissions.hasPermission(player, "plots.list.done")) {
args.add("done"); args.add("done");
} }
if (Permissions.hasPermission(player, "plots.list.fuzzy")) {
args.add("fuzzy <search...>");
}
return args.toArray(new String[args.size()]); return args.toArray(new String[args.size()]);
} }
@ -106,19 +111,20 @@ public class list extends SubCommand {
int page = 0; int page = 0;
if (args.length > 1) { if (args.length > 1) {
try { try {
page = Integer.parseInt(args[1]); page = Integer.parseInt(args[args.length - 1]);
--page; --page;
if (page < 0) { if (page < 0) {
page = 0; page = 0;
} }
} catch (final Exception e) { } catch (final Exception e) {
page = 0; page = -1;
} }
} }
List<Plot> plots = null; List<Plot> plots = null;
final String world = plr.getLocation().getWorld(); final String world = plr.getLocation().getWorld();
final PlotArea area = plr.getApplicablePlotArea();
final String arg = args[0].toLowerCase(); final String arg = args[0].toLowerCase();
boolean sort = true; boolean sort = true;
switch (arg) { switch (arg) {
@ -153,7 +159,19 @@ public class list extends SubCommand {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.world." + world); MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.world." + world);
return false; return false;
} }
plots = new ArrayList<>(PS.get().getPlotsInWorld(world)); plots = new ArrayList<>(PS.get().getPlots(world));
break;
}
case "area": {
if (!Permissions.hasPermission(plr, "plots.list.area")) {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.area");
return false;
}
if (!Permissions.hasPermission(plr, "plots.list.world." + world)) {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.world." + world);
return false;
}
plots = area == null ? new ArrayList<Plot>() : new ArrayList<Plot>(area.getPlots());
break; break;
} }
case "all": { case "all": {
@ -278,8 +296,23 @@ public class list extends SubCommand {
} }
break; break;
} }
case "fuzzy": {
if (!Permissions.hasPermission(plr, "plots.list.fuzzy")) {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.fuzzy");
return false;
}
if (args.length < (page == -1 ? 2 : 3)) {
C.COMMAND_SYNTAX.send(plr, "/plot list fuzzy <search...> [#]");
return false;
}
String term = StringMan.join(Arrays.copyOfRange(args, 1, args.length - 2), " ");
//TODO improve search reliability / speed
plots = MainUtil.getPlotsBySearch(term);
sort = false;
break;
}
default: { default: {
if (PS.get().isPlotWorld(args[0])) { if (PS.get().hasPlotArea(args[0])) {
if (!Permissions.hasPermission(plr, "plots.list.world")) { if (!Permissions.hasPermission(plr, "plots.list.world")) {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.world"); MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.world");
return false; return false;
@ -288,7 +321,7 @@ public class list extends SubCommand {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.world." + args[0]); MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.world." + args[0]);
return false; return false;
} }
plots = new ArrayList<>(PS.get().getPlotsInWorld(args[0])); plots = new ArrayList<>(PS.get().getPlots(args[0]));
break; break;
} }
UUID uuid = UUIDHandler.getUUID(args[0], null); UUID uuid = UUIDHandler.getUUID(args[0], null);
@ -318,11 +351,11 @@ public class list extends SubCommand {
MainUtil.sendMessage(plr, C.FOUND_NO_PLOTS); MainUtil.sendMessage(plr, C.FOUND_NO_PLOTS);
return false; return false;
} }
displayPlots(plr, plots, 12, page, world, args, sort); displayPlots(plr, plots, 12, page, area, args, sort);
return true; return true;
} }
public void displayPlots(final PlotPlayer player, List<Plot> plots, final int pageSize, int page, final String world, final String[] args, final boolean sort) { public void displayPlots(final PlotPlayer player, List<Plot> plots, final int pageSize, int page, final PlotArea area, final String[] args, final boolean sort) {
int rawSize = plots.size(); int rawSize = plots.size();
Iterator<Plot> iter = plots.iterator(); Iterator<Plot> iter = plots.iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
@ -331,7 +364,7 @@ public class list extends SubCommand {
} }
} }
if (sort) { if (sort) {
plots = PS.get().sortPlots(plots, SortType.CREATION_DATE, world); plots = PS.get().sortPlots(plots, SortType.CREATION_DATE, area);
} }
if (page < 0) { if (page < 0) {
page = 0; page = 0;
@ -379,12 +412,12 @@ public class list extends SubCommand {
final PlotMessage flags = new PlotMessage().text(C.color(C.PLOT_INFO_FLAGS.s().replaceAll("%flags%", strFlags))).color("$1"); final PlotMessage flags = new PlotMessage().text(C.color(C.PLOT_INFO_FLAGS.s().replaceAll("%flags%", strFlags))).color("$1");
PlotMessage message = new PlotMessage().text("[").color("$3").text(i + "").command("/plot visit " + plot.world + ";" + plot.getId()).tooltip("/plot visit " + plot.world + ";" + plot PlotMessage message = new PlotMessage().text("[").color("$3").text(i + "").command("/plot visit " + plot.area + ";" + plot.getId()).tooltip("/plot visit " + plot.area + ";" + plot
.getId()) .getId())
.color("$1").text("]").color("$3").text(" " + plot.toString()) .color("$1").text("]").color("$3").text(" " + plot.toString())
.tooltip(trusted, members, flags).command("/plot info " + plot.world + ";" + plot.getId()) .tooltip(trusted, members, flags).command("/plot info " + plot.area + ";" + plot.getId())
.color(color).text(" - ").color("$2"); .color(color).text(" - ").color("$2");
String prefix = ""; String prefix = "";

View File

@ -125,7 +125,7 @@ public enum C {
"Cluster"), "Cluster"),
CLUSTER_LIST_HEADING("$2There are $1%s$2 clusters in this world", "Cluster"), CLUSTER_LIST_HEADING("$2There are $1%s$2 clusters in this world", "Cluster"),
CLUSTER_LIST_ELEMENT("$2 - $1%s&-", "Cluster"), CLUSTER_LIST_ELEMENT("$2 - $1%s&-", "Cluster"),
CLUSTER_INTERSECTION("$2The proposed area overlaps with $1%s$2 existing cluster/s", "Cluster"), CLUSTER_INTERSECTION("$2The proposed area overlaps with an existing cluster: %s0", "Cluster"),
CLUSTER_ADDED("$4Successfully created the cluster.", "Cluster"), CLUSTER_ADDED("$4Successfully created the cluster.", "Cluster"),
CLUSTER_DELETED("$4Successfully deleted the cluster.", "Cluster"), CLUSTER_DELETED("$4Successfully deleted the cluster.", "Cluster"),
CLUSTER_RESIZED("$4Successfully resized the cluster.", "Cluster"), CLUSTER_RESIZED("$4Successfully resized the cluster.", "Cluster"),
@ -142,7 +142,6 @@ public enum C {
CLUSTER_REGENERATED("$4Successfully started cluster regeneration", "Cluster"), CLUSTER_REGENERATED("$4Successfully started cluster regeneration", "Cluster"),
CLUSTER_TELEPORTING("$4Teleporting...", "Cluster"), CLUSTER_TELEPORTING("$4Teleporting...", "Cluster"),
CLUSTER_INFO("$1Current cluster: $2%id%&-$1Name: $2%name%&-$1Owner: $2%owner%&-$1Size: $2%size%&-$1Rights: $2%rights%", "Cluster"), CLUSTER_INFO("$1Current cluster: $2%id%&-$1Name: $2%name%&-$1Owner: $2%owner%&-$1Size: $2%size%&-$1Rights: $2%rights%", "Cluster"),
CLUSTER_CURRENT_PLOTID("$1Current plot: $2%s", "Cluster"),
/* /*
* Border * Border
*/ */
@ -167,7 +166,7 @@ public enum C {
WORLDEDIT_RESTRICTED("$1Your WorldEdit is now restricted.", "WorldEdit Masks"), WORLDEDIT_RESTRICTED("$1Your WorldEdit is now restricted.", "WorldEdit Masks"),
GAMEMODE_WAS_BYPASSED("$1You bypassed the gamemode ($2{gamemode}$1) $1set for $2{plot}", "Gamemode"), GAMEMODE_WAS_BYPASSED("$1You bypassed the gamemode ($2{gamemode}$1) $1set for $2{plot}", "Gamemode"),
HEIGHT_LIMIT("$1This plot world has a height limit of $2{limit}", "Height Limit"), HEIGHT_LIMIT("$1This plot area has a height limit of $2{limit}", "Height Limit"),
/* /*
* Records * Records
*/ */
@ -382,7 +381,6 @@ public enum C {
/* /*
* purge * purge
*/ */
PURGE_SYNTAX("Use /plot purge <x;z|player|unowned|unknown|all> <world>", "Purge"),
PURGE_SUCCESS("$4Successfully purged %s plots", "Purge"), PURGE_SUCCESS("$4Successfully purged %s plots", "Purge"),
/* /*
* trim * trim
@ -396,10 +394,10 @@ public enum C {
NO_FREE_PLOTS("$2There are no free plots available", "Errors"), NO_FREE_PLOTS("$2There are no free plots available", "Errors"),
NOT_IN_PLOT("$2You're not in a plot", "Errors"), NOT_IN_PLOT("$2You're not in a plot", "Errors"),
NOT_IN_CLUSTER("$2You must be within a plot cluster to perform that action", "Errors"), NOT_IN_CLUSTER("$2You must be within a plot cluster to perform that action", "Errors"),
NOT_IN_PLOT_WORLD("$2You're not in a plot world", "Errors"), NOT_IN_PLOT_WORLD("$2You're not in a plot area", "Errors"),
PLOTWORLD_INCOMPATIBLE("$2The two worlds must be compatible", "Errors"), PLOTWORLD_INCOMPATIBLE("$2The two worlds must be compatible", "Errors"),
NOT_VALID_WORLD("$2That is not a valid world (case sensitive)", "Errors"), NOT_VALID_WORLD("$2That is not a valid world (case sensitive)", "Errors"),
NOT_VALID_PLOT_WORLD("$2That is not a valid plot world (case sensitive)", "Errors"), NOT_VALID_PLOT_WORLD("$2That is not a valid plot area (case sensitive)", "Errors"),
NO_PLOTS("$2You don't have any plots", "Errors"), NO_PLOTS("$2You don't have any plots", "Errors"),
/* /*
* Block List * Block List
@ -457,7 +455,7 @@ public enum C {
NEED_PLOT_NUMBER("$2You've got to specify a plot number or alias", "Need"), NEED_PLOT_NUMBER("$2You've got to specify a plot number or alias", "Need"),
NEED_BLOCK("$2You've got to specify a block", "Need"), NEED_BLOCK("$2You've got to specify a block", "Need"),
NEED_PLOT_ID("$2You've got to specify a plot id.", "Need"), NEED_PLOT_ID("$2You've got to specify a plot id.", "Need"),
NEED_PLOT_WORLD("$2You've got to specify a plot world.", "Need"), NEED_PLOT_WORLD("$2You've got to specify a plot area.", "Need"),
NEED_USER("$2You need to specify a username", "Need"), NEED_USER("$2You need to specify a username", "Need"),
/* /*
* Info * Info

View File

@ -23,8 +23,8 @@ package com.intellectualcrafters.plot.config;
import java.util.ArrayList; import java.util.ArrayList;
import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.StringComparison; import com.intellectualcrafters.plot.util.StringComparison;
import com.intellectualcrafters.plot.util.WorldUtil;
/** /**
* Main Configuration Utility * Main Configuration Utility
@ -106,7 +106,7 @@ public class Configuration {
@Override @Override
public boolean validateValue(final String string) { public boolean validateValue(final String string) {
try { try {
final int biome = BlockManager.manager.getBiomeFromString(string.toUpperCase()); final int biome = WorldUtil.IMP.getBiomeFromString(string.toUpperCase());
return biome != -1; return biome != -1;
} catch (final Exception e) { } catch (final Exception e) {
return false; return false;
@ -125,7 +125,7 @@ public class Configuration {
@Override @Override
public boolean validateValue(final String string) { public boolean validateValue(final String string) {
try { try {
final StringComparison<PlotBlock>.ComparisonResult value = BlockManager.manager.getClosestBlock(string); final StringComparison<PlotBlock>.ComparisonResult value = WorldUtil.IMP.getClosestBlock(string);
if ((value == null) || (value.match > 1)) { if ((value == null) || (value.match > 1)) {
return false; return false;
} }
@ -136,7 +136,7 @@ public class Configuration {
@Override @Override
public PlotBlock parseString(final String string) { public PlotBlock parseString(final String string) {
final StringComparison<PlotBlock>.ComparisonResult value = BlockManager.manager.getClosestBlock(string); final StringComparison<PlotBlock>.ComparisonResult value = WorldUtil.IMP.getClosestBlock(string);
if ((value == null) || (value.match > 1)) { if ((value == null) || (value.match > 1)) {
return null; return null;
} }
@ -153,7 +153,7 @@ public class Configuration {
Integer.parseInt(split[0]); Integer.parseInt(split[0]);
block = split[1]; block = split[1];
} }
final StringComparison<PlotBlock>.ComparisonResult value = BlockManager.manager.getClosestBlock(block); final StringComparison<PlotBlock>.ComparisonResult value = WorldUtil.IMP.getClosestBlock(block);
if ((value == null) || (value.match > 1)) { if ((value == null) || (value.match > 1)) {
return false; return false;
} }
@ -187,7 +187,7 @@ public class Configuration {
min = 1; min = 1;
} }
} }
final StringComparison<PlotBlock>.ComparisonResult result = BlockManager.manager.getClosestBlock(blocks[i]); final StringComparison<PlotBlock>.ComparisonResult result = WorldUtil.IMP.getClosestBlock(blocks[i]);
if ((result != null) && (result.match < 2)) { if ((result != null) && (result.match < 2)) {
values[i] = result.best; values[i] = result.best;
} }

View File

@ -36,10 +36,9 @@ public class Settings {
*/ */
public static boolean UPDATE_NOTIFICATIONS = true; public static boolean UPDATE_NOTIFICATIONS = true;
public static boolean ENABLE_CLUSTERS = false;
public static boolean FAST_CLEAR = false; public static boolean FAST_CLEAR = false;
public static boolean MERGE_REMOVES_ROADS = true; public static boolean MERGE_REMOVES_ROADS = true;
/** /**`
* Default UUID_FECTHING: false * Default UUID_FECTHING: false
*/ */
public static boolean PERMISSION_CACHING = true; public static boolean PERMISSION_CACHING = true;
@ -59,7 +58,10 @@ public class Settings {
public static boolean REQUIRE_DONE = false; public static boolean REQUIRE_DONE = false;
public static boolean DONE_COUNTS_TOWARDS_LIMIT = false; public static boolean DONE_COUNTS_TOWARDS_LIMIT = false;
public static boolean DONE_RESTRICTS_BUILDING = false; public static boolean DONE_RESTRICTS_BUILDING = false;
/**
* Clusters
*/
public static boolean ENABLE_CLUSTERS = false;
/** /**
* PlotMe settings * PlotMe settings
*/ */
@ -85,10 +87,6 @@ public class Settings {
*/ */
public static boolean REDSTONE_DISABLER = false; public static boolean REDSTONE_DISABLER = false;
public static boolean REDSTONE_DISABLER_UNOCCUPIED = false; public static boolean REDSTONE_DISABLER_UNOCCUPIED = false;
/**
* Check for falling blocks when pistons extend?
*/
public static boolean PISTON_FALLING_BLOCK_CHECK = true;
/** /**
* Max auto claiming size * Max auto claiming size
*/ */
@ -102,15 +100,6 @@ public class Settings {
public static long WE_MAX_VOLUME = 500000; public static long WE_MAX_VOLUME = 500000;
public static long WE_MAX_ITERATIONS = 1000; public static long WE_MAX_ITERATIONS = 1000;
public static List<String> WE_BLACKLIST = new ArrayList<>(); public static List<String> WE_BLACKLIST = new ArrayList<>();
/**
* Default kill road mobs: true
*/
public final static boolean KILL_ROAD_MOBS_DEFAULT = false;
public final static boolean KILL_ROAD_VEHICLES_DEFAULT = false;
/**
* Default mob pathfinding: true
*/
public final static boolean MOB_PATHFINDING_DEFAULT = true;
/** /**
* Teleport to path on login * Teleport to path on login
*/ */
@ -146,12 +135,8 @@ public class Settings {
/** /**
* Kill road mobs? * Kill road mobs?
*/ */
public static boolean KILL_ROAD_MOBS; public static boolean KILL_ROAD_MOBS = false;
public static boolean KILL_ROAD_VEHICLES; public static boolean KILL_ROAD_VEHICLES = false;
/**
* mob pathfinding?
*/
public static boolean MOB_PATHFINDING;
/** /**
* Delete plots on ban? * Delete plots on ban?
*/ */

View File

@ -20,13 +20,22 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.database; package com.intellectualcrafters.plot.database;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.object.*;
import com.intellectualcrafters.plot.object.comment.PlotComment;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.*; import java.util.ArrayList;
import java.util.concurrent.ConcurrentHashMap; import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.comment.PlotComment;
/** /**
@ -124,7 +133,7 @@ public interface AbstractDB {
/** /**
* @return A linked hashmap containing all plots * @return A linked hashmap containing all plots
*/ */
ConcurrentHashMap<String, ConcurrentHashMap<PlotId, Plot>> getPlots(); HashMap<String, HashMap<PlotId, Plot>> getPlots();
/** /**
* *
@ -134,7 +143,7 @@ public interface AbstractDB {
/** /**
* @return A hashmap containing all plot clusters * @return A hashmap containing all plot clusters
*/ */
HashMap<String, HashSet<PlotCluster>> getClusters(); HashMap<String, Set<PlotCluster>> getClusters();
/** /**
* Set the merged status for a plot * Set the merged status for a plot
@ -186,14 +195,14 @@ public interface AbstractDB {
* @param world World in which the plot is located * @param world World in which the plot is located
* @param uniqueIds list of plot id (db) to be purged * @param uniqueIds list of plot id (db) to be purged
*/ */
void purgeIds(final String world, final Set<Integer> uniqueIds); void purgeIds(final Set<Integer> uniqueIds);
/** /**
* Purge a whole world * Purge a whole world
* *
* @param world World in which the plots should be purged * @param world World in which the plots should be purged
*/ */
void purge(final String world, final Set<PlotId> plotIds); void purge(final PlotArea area, final Set<PlotId> plotIds);
/** /**
* Set Plot Home Position * Set Plot Home Position
@ -318,13 +327,13 @@ public interface AbstractDB {
* @param plot Plot Object * @param plot Plot Object
* @return Plot Comments within the specified tier * @return Plot Comments within the specified tier
*/ */
void getComments(final Plot plot, final String inbox, final RunnableVal whenDone); void getComments(final Plot plot, final String inbox, final RunnableVal<List<PlotComment>> whenDone);
void createPlotAndSettings(final Plot plot, final Runnable whenDone); void createPlotAndSettings(final Plot plot, final Runnable whenDone);
void createCluster(final PlotCluster cluster); void createCluster(final PlotCluster cluster);
void resizeCluster(final PlotCluster current, final PlotClusterId resize); void resizeCluster(final PlotCluster current, PlotId min, PlotId max);
void movePlot(final Plot originalPlot, final Plot newPlot); void movePlot(final Plot originalPlot, final Plot newPlot);

View File

@ -26,15 +26,14 @@ import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotClusterId;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.comment.PlotComment; import com.intellectualcrafters.plot.object.comment.PlotComment;
@ -265,7 +264,7 @@ public class DBFunc {
/** /**
* @return Plots * @return Plots
*/ */
public static ConcurrentHashMap<String, ConcurrentHashMap<PlotId, Plot>> getPlots() { public static HashMap<String, HashMap<PlotId, Plot>> getPlots() {
return dbManager.getPlots(); return dbManager.getPlots();
} }
@ -298,12 +297,12 @@ public class DBFunc {
dbManager.setAlias(plot, alias); dbManager.setAlias(plot, alias);
} }
public static void purgeIds(final String world, final Set<Integer> uniqueIds) { public static void purgeIds(final Set<Integer> uniqueIds) {
dbManager.purgeIds(world, uniqueIds); dbManager.purgeIds(uniqueIds);
} }
public static void purge(final String world, final Set<PlotId> plotIds) { public static void purge(final PlotArea area, final Set<PlotId> plotIds) {
dbManager.purge(world, plotIds); dbManager.purge(area, plotIds);
} }
/** /**
@ -349,7 +348,7 @@ public class DBFunc {
/** /**
* @param plot * @param plot
*/ */
public static void getComments(final Plot plot, final String inbox, final RunnableVal whenDone) { public static void getComments(final Plot plot, final String inbox, final RunnableVal<List<PlotComment>> whenDone) {
if ((plot != null) && (plot.temp == -1)) { if ((plot != null) && (plot.temp == -1)) {
return; return;
} }
@ -379,7 +378,7 @@ public class DBFunc {
* @param world * @param world
* @param cluster * @param cluster
*/ */
public static void createCluster(final String world, final PlotCluster cluster) { public static void createCluster(final PlotCluster cluster) {
dbManager.createCluster(cluster); dbManager.createCluster(cluster);
} }
@ -387,8 +386,8 @@ public class DBFunc {
* @param current * @param current
* @param resize * @param resize
*/ */
public static void resizeCluster(final PlotCluster current, final PlotClusterId resize) { public static void resizeCluster(final PlotCluster current, final PlotId min, PlotId max) {
dbManager.resizeCluster(current, resize); dbManager.resizeCluster(current, min, max);
} }
/** /**
@ -437,7 +436,7 @@ public class DBFunc {
dbManager.setMember(plot, uuid); dbManager.setMember(plot, uuid);
} }
public static void setInvited(final String world, final PlotCluster cluster, final UUID uuid) { public static void setInvited(final PlotCluster cluster, final UUID uuid) {
dbManager.setInvited(cluster, uuid); dbManager.setInvited(cluster, uuid);
} }
@ -477,7 +476,7 @@ public class DBFunc {
dbManager.setRating(plot, rater, value); dbManager.setRating(plot, rater, value);
} }
public static HashMap<String, HashSet<PlotCluster>> getClusters() { public static HashMap<String, Set<PlotCluster>> getClusters() {
return dbManager.getClusters(); return dbManager.getClusters();
} }

View File

@ -20,24 +20,49 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.database; package com.intellectualcrafters.plot.database;
import java.lang.reflect.Field;
import java.sql.Blob;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Queue;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicInteger;
import com.intellectualcrafters.configuration.ConfigurationSection;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.*; import com.intellectualcrafters.plot.object.BlockLoc;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotSettings;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.comment.PlotComment; import com.intellectualcrafters.plot.object.comment.PlotComment;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import java.lang.reflect.Field;
import java.sql.*;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicInteger;
/** /**
*/ */
@ -97,7 +122,7 @@ public class SQLManager implements AbstractDB {
public synchronized void addPlotTask(Plot plot, UniqueStatement task) { public synchronized void addPlotTask(Plot plot, UniqueStatement task) {
if (plot == null) { if (plot == null) {
plot = new Plot("", new PlotId(Integer.MAX_VALUE, Integer.MAX_VALUE), null); plot = new Plot(null, new PlotId(Integer.MAX_VALUE, Integer.MAX_VALUE));
} }
Queue<UniqueStatement> tasks = plotTasks.get(plot); Queue<UniqueStatement> tasks = plotTasks.get(plot);
if (tasks == null) { if (tasks == null) {
@ -375,7 +400,7 @@ public class SQLManager implements AbstractDB {
statement.setString(1, uuid.toString()); statement.setString(1, uuid.toString());
statement.setInt(2, plot.getId().x); statement.setInt(2, plot.getId().x);
statement.setInt(3, plot.getId().y); statement.setInt(3, plot.getId().y);
statement.setString(4, plot.world); statement.setString(4, plot.area.toString());
} }
@Override @Override
@ -561,7 +586,7 @@ public class SQLManager implements AbstractDB {
} catch (final Exception e) { } catch (final Exception e) {
stmt.setString((i * 5) + 3, everyone.toString()); stmt.setString((i * 5) + 3, everyone.toString());
} }
stmt.setString((i * 5) + 4, plot.world); stmt.setString((i * 5) + 4, plot.area.toString());
stmt.setTimestamp((i * 5) + 5, new Timestamp(plot.getTimestamp())); stmt.setTimestamp((i * 5) + 5, new Timestamp(plot.getTimestamp()));
} }
@ -575,7 +600,7 @@ public class SQLManager implements AbstractDB {
} catch (final Exception e1) { } catch (final Exception e1) {
stmt.setString((i * 6) + 4, everyone.toString()); stmt.setString((i * 6) + 4, everyone.toString());
} }
stmt.setString((i * 6) + 5, plot.world); stmt.setString((i * 6) + 5, plot.area.toString());
stmt.setTimestamp((i * 6) + 6, new Timestamp(plot.getTimestamp())); stmt.setTimestamp((i * 6) + 6, new Timestamp(plot.getTimestamp()));
} }
@ -584,7 +609,7 @@ public class SQLManager implements AbstractDB {
stmt.setInt(1, plot.getId().x); stmt.setInt(1, plot.getId().x);
stmt.setInt(2, plot.getId().y); stmt.setInt(2, plot.getId().y);
stmt.setString(3, plot.owner.toString()); stmt.setString(3, plot.owner.toString());
stmt.setString(4, plot.world); stmt.setString(4, plot.area.toString());
stmt.setTimestamp(5, new Timestamp(plot.getTimestamp())); stmt.setTimestamp(5, new Timestamp(plot.getTimestamp()));
} }
@ -898,7 +923,7 @@ public class SQLManager implements AbstractDB {
stmt.setInt(1, plot.getId().x); stmt.setInt(1, plot.getId().x);
stmt.setInt(2, plot.getId().y); stmt.setInt(2, plot.getId().y);
stmt.setString(3, plot.owner.toString()); stmt.setString(3, plot.owner.toString());
stmt.setString(4, plot.world); stmt.setString(4, plot.area.toString());
stmt.setTimestamp(5, new Timestamp(plot.getTimestamp())); stmt.setTimestamp(5, new Timestamp(plot.getTimestamp()));
} }
@ -931,7 +956,7 @@ public class SQLManager implements AbstractDB {
stmt.setInt(1, plot.getId().x); stmt.setInt(1, plot.getId().x);
stmt.setInt(2, plot.getId().y); stmt.setInt(2, plot.getId().y);
stmt.setString(3, plot.owner.toString()); stmt.setString(3, plot.owner.toString());
stmt.setString(4, plot.world); stmt.setString(4, plot.area.toString());
stmt.setTimestamp(5, new Timestamp(plot.getTimestamp())); stmt.setTimestamp(5, new Timestamp(plot.getTimestamp()));
} }
@ -1267,7 +1292,7 @@ public class SQLManager implements AbstractDB {
addPlotTask(plot, new UniqueStatement("delete_plot_comments") { addPlotTask(plot, new UniqueStatement("delete_plot_comments") {
@Override @Override
public void set(final PreparedStatement stmt) throws SQLException { public void set(final PreparedStatement stmt) throws SQLException {
stmt.setString(1, plot.world); stmt.setString(1, plot.area.toString());
stmt.setInt(2, plot.hashCode()); stmt.setInt(2, plot.hashCode());
} }
@ -1361,7 +1386,7 @@ public class SQLManager implements AbstractDB {
stmt.setInt(2, cluster.getP1().y); stmt.setInt(2, cluster.getP1().y);
stmt.setInt(3, cluster.getP2().x); stmt.setInt(3, cluster.getP2().x);
stmt.setInt(4, cluster.getP2().y); stmt.setInt(4, cluster.getP2().y);
stmt.setString(5, cluster.world); stmt.setString(5, cluster.area.toString());
final ResultSet r = stmt.executeQuery(); final ResultSet r = stmt.executeQuery();
int c_id = Integer.MAX_VALUE; int c_id = Integer.MAX_VALUE;
while (r.next()) { while (r.next()) {
@ -1397,7 +1422,7 @@ public class SQLManager implements AbstractDB {
stmt = connection.prepareStatement("SELECT `id` FROM `" + prefix + "plot` WHERE `plot_id_x` = ? AND `plot_id_z` = ? AND world = ? ORDER BY `timestamp` ASC"); stmt = connection.prepareStatement("SELECT `id` FROM `" + prefix + "plot` WHERE `plot_id_x` = ? AND `plot_id_z` = ? AND world = ? ORDER BY `timestamp` ASC");
stmt.setInt(1, plot.getId().x); stmt.setInt(1, plot.getId().x);
stmt.setInt(2, plot.getId().y); stmt.setInt(2, plot.getId().y);
stmt.setString(3, plot.world); stmt.setString(3, plot.area.toString());
final ResultSet r = stmt.executeQuery(); final ResultSet r = stmt.executeQuery();
int id = Integer.MAX_VALUE; int id = Integer.MAX_VALUE;
while (r.next()) { while (r.next()) {
@ -1540,14 +1565,28 @@ public class SQLManager implements AbstractDB {
* Load all plots, helpers, denied, trusted, and every setting from DB into a hashmap * Load all plots, helpers, denied, trusted, and every setting from DB into a hashmap
*/ */
@Override @Override
public ConcurrentHashMap<String, ConcurrentHashMap<PlotId, Plot>> getPlots() { public HashMap<String, HashMap<PlotId, Plot>> getPlots() {
final ConcurrentHashMap<String, ConcurrentHashMap<PlotId, Plot>> newplots = new ConcurrentHashMap<>(); final HashMap<String, HashMap<PlotId, Plot>> newplots = new HashMap<>();
final HashMap<Integer, Plot> plots = new HashMap<>(); final HashMap<Integer, Plot> plots = new HashMap<>();
Statement stmt; Statement stmt;
try { try {
Set<String> worlds = new HashSet<>(); HashSet<String> areas = new HashSet<>();;
if (PS.get().config.contains("worlds")) { if (PS.get().config.contains("worlds")) {
worlds = PS.get().config.getConfigurationSection("worlds").getKeys(false); ConfigurationSection worldSection = PS.get().config.getConfigurationSection("worlds");
if (worldSection != null) {
for (String worldKey : worldSection.getKeys(false)) {
areas.add(worldKey);
ConfigurationSection areaSection = worldSection.getConfigurationSection(worldKey + ".areas");
if (areaSection != null) {
for (String areaKey : areaSection.getKeys(false)) {
String[] split = areaKey.split("-");
if (split.length == 3) {
areas.add(worldKey + ";" + split[0]);
}
}
}
}
}
} }
final HashMap<String, UUID> uuids = new HashMap<>(); final HashMap<String, UUID> uuids = new HashMap<>();
final HashMap<String, AtomicInteger> noExist = new HashMap<>(); final HashMap<String, AtomicInteger> noExist = new HashMap<>();
@ -1567,17 +1606,17 @@ public class SQLManager implements AbstractDB {
while (r.next()) { while (r.next()) {
plot_id = new PlotId(r.getInt("plot_id_x"), r.getInt("plot_id_z")); plot_id = new PlotId(r.getInt("plot_id_x"), r.getInt("plot_id_z"));
id = r.getInt("id"); id = r.getInt("id");
final String worldname = r.getString("world"); final String areaid = r.getString("world");
if (!worlds.contains(worldname)) { if (!areas.contains(areaid)) {
if (Settings.AUTO_PURGE) { if (Settings.AUTO_PURGE) {
toDelete.add(id); toDelete.add(id);
continue; continue;
} else { } else {
AtomicInteger value = noExist.get(worldname); AtomicInteger value = noExist.get(areaid);
if (value != null) { if (value != null) {
value.incrementAndGet(); value.incrementAndGet();
} else { } else {
noExist.put(worldname, new AtomicInteger(1)); noExist.put(areaid, new AtomicInteger(1));
} }
} }
} }
@ -1598,8 +1637,8 @@ public class SQLManager implements AbstractDB {
} else { } else {
time = timestamp.getTime(); time = timestamp.getTime();
} }
p = new Plot(plot_id, user, new HashSet<UUID>(), new HashSet<UUID>(), new HashSet<UUID>(), "", null, null, worldname, new boolean[] { false, false, false, false }, time, id); p = new Plot(plot_id, user, new HashSet<UUID>(), new HashSet<UUID>(), new HashSet<UUID>(), "", null, null, null, new boolean[] { false, false, false, false }, time, id);
ConcurrentHashMap<PlotId, Plot> map = newplots.get(worldname); HashMap<PlotId, Plot> map = newplots.get(areaid);
if (map != null) { if (map != null) {
Plot last = map.put(p.id, p); Plot last = map.put(p.id, p);
if (last != null) { if (last != null) {
@ -1612,8 +1651,8 @@ public class SQLManager implements AbstractDB {
continue; continue;
} }
} else { } else {
map = new ConcurrentHashMap<PlotId, Plot>(); map = new HashMap<PlotId, Plot>();
newplots.put(worldname, map); newplots.put(areaid, map);
map.put(p.id, p); map.put(p.id, p);
} }
plots.put(id, p); plots.put(id, p);
@ -1881,7 +1920,7 @@ public class SQLManager implements AbstractDB {
public void set(final PreparedStatement stmt) throws SQLException { public void set(final PreparedStatement stmt) throws SQLException {
stmt.setInt(1, newPlot.getId().x); stmt.setInt(1, newPlot.getId().x);
stmt.setInt(2, newPlot.getId().y); stmt.setInt(2, newPlot.getId().y);
stmt.setString(3, newPlot.world); stmt.setString(3, newPlot.area.toString());
stmt.setInt(4, getId(original)); stmt.setInt(4, getId(original));
} }
@ -1938,7 +1977,7 @@ public class SQLManager implements AbstractDB {
* Purge all plots with the following database IDs * Purge all plots with the following database IDs
*/ */
@Override @Override
public void purgeIds(final String world, final Set<Integer> uniqueIds) { public void purgeIds(final Set<Integer> uniqueIds) {
addGlobalTask(new Runnable() { addGlobalTask(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -1973,24 +2012,24 @@ public class SQLManager implements AbstractDB {
stmt.close(); stmt.close();
} catch (final SQLException e) { } catch (final SQLException e) {
e.printStackTrace(); e.printStackTrace();
PS.debug("&c[ERROR] " + "FAILED TO PURGE WORLD '" + world + "'!"); PS.debug("&c[ERROR] " + "FAILED TO PURGE PLOTS!");
return; return;
} }
} }
PS.debug("&6[INFO] " + "SUCCESSFULLY PURGED WORLD '" + world + "'!"); PS.debug("&6[INFO] " + "SUCCESSFULLY PURGED " + uniqueIds.size() + " PLOTS!");
} }
}); });
} }
@Override @Override
public void purge(final String world, final Set<PlotId> plots) { public void purge(final PlotArea area, final Set<PlotId> plots) {
addGlobalTask(new Runnable() { addGlobalTask(new Runnable() {
@Override @Override
public void run() { public void run() {
PreparedStatement stmt; PreparedStatement stmt;
try { try {
stmt = connection.prepareStatement("SELECT `id`, `plot_id_x`, `plot_id_z` FROM `" + prefix + "plot` WHERE `world` = ?"); stmt = connection.prepareStatement("SELECT `id`, `plot_id_x`, `plot_id_z` FROM `" + prefix + "plot` WHERE `world` = ?");
stmt.setString(1, world); stmt.setString(1, area.toString());
final ResultSet r = stmt.executeQuery(); final ResultSet r = stmt.executeQuery();
PlotId plot_id; PlotId plot_id;
final Set<Integer> ids = new HashSet<>(); final Set<Integer> ids = new HashSet<>();
@ -2000,18 +2039,18 @@ public class SQLManager implements AbstractDB {
ids.add(r.getInt("id")); ids.add(r.getInt("id"));
} }
} }
purgeIds(world, ids); purgeIds(ids);
stmt.close(); stmt.close();
r.close(); r.close();
for (final Iterator<PlotId> iter = plots.iterator(); iter.hasNext();) { for (final Iterator<PlotId> iter = plots.iterator(); iter.hasNext();) {
final PlotId plotId = iter.next(); final PlotId plotId = iter.next();
iter.remove(); iter.remove();
final PlotId id = new PlotId(plotId.x, plotId.y); final PlotId id = new PlotId(plotId.x, plotId.y);
PS.get().removePlot(world, new PlotId(id.x, id.y), true); area.removePlot(id);
} }
} catch (final SQLException e) { } catch (final SQLException e) {
e.printStackTrace(); e.printStackTrace();
PS.debug("&c[ERROR] " + "FAILED TO PURGE WORLD '" + world + "'!"); PS.debug("&c[ERROR] " + "FAILED TO PURGE AREA '" + area + "'!");
} }
} }
}); });
@ -2039,7 +2078,7 @@ public class SQLManager implements AbstractDB {
@Override @Override
public void set(final PreparedStatement statement) throws SQLException { public void set(final PreparedStatement statement) throws SQLException {
if (plot != null) { if (plot != null) {
statement.setString(1, plot.world); statement.setString(1, plot.area.toString());
statement.setInt(2, plot.getId().hashCode()); statement.setInt(2, plot.getId().hashCode());
statement.setString(3, comment.comment); statement.setString(3, comment.comment);
statement.setString(4, comment.inbox); statement.setString(4, comment.inbox);
@ -2067,7 +2106,7 @@ public class SQLManager implements AbstractDB {
@Override @Override
public void set(final PreparedStatement statement) throws SQLException { public void set(final PreparedStatement statement) throws SQLException {
if (plot != null) { if (plot != null) {
statement.setString(1, plot.world); statement.setString(1, plot.area.toString());
statement.setInt(2, plot.getId().hashCode()); statement.setInt(2, plot.getId().hashCode());
statement.setString(3, inbox); statement.setString(3, inbox);
} else { } else {
@ -2086,12 +2125,12 @@ public class SQLManager implements AbstractDB {
} }
@Override @Override
public void getComments(final Plot plot, final String inbox, final RunnableVal whenDone) { public void getComments(final Plot plot, final String inbox, final RunnableVal<List<PlotComment>> whenDone) {
addPlotTask(plot, new UniqueStatement("getComments_" + plot) { addPlotTask(plot, new UniqueStatement("getComments_" + plot) {
@Override @Override
public void set(final PreparedStatement statement) throws SQLException { public void set(final PreparedStatement statement) throws SQLException {
if (plot != null) { if (plot != null) {
statement.setString(1, plot.world); statement.setString(1, plot.area.toString());
statement.setInt(2, plot.getId().hashCode()); statement.setInt(2, plot.getId().hashCode());
statement.setString(3, inbox); statement.setString(3, inbox);
} else { } else {
@ -2141,7 +2180,7 @@ public class SQLManager implements AbstractDB {
addPlotTask(plot, new UniqueStatement("setComment") { addPlotTask(plot, new UniqueStatement("setComment") {
@Override @Override
public void set(final PreparedStatement statement) throws SQLException { public void set(final PreparedStatement statement) throws SQLException {
statement.setString(1, plot.world); statement.setString(1, plot.area.toString());
statement.setInt(2, plot.getId().hashCode()); statement.setInt(2, plot.getId().hashCode());
statement.setString(3, comment.comment); statement.setString(3, comment.comment);
statement.setString(4, comment.inbox); statement.setString(4, comment.inbox);
@ -2419,14 +2458,28 @@ public class SQLManager implements AbstractDB {
} }
@Override @Override
public HashMap<String, HashSet<PlotCluster>> getClusters() { public HashMap<String, Set<PlotCluster>> getClusters() {
final LinkedHashMap<String, HashSet<PlotCluster>> newClusters = new LinkedHashMap<>(); final LinkedHashMap<String, Set<PlotCluster>> newClusters = new LinkedHashMap<>();
final HashMap<Integer, PlotCluster> clusters = new HashMap<>(); final HashMap<Integer, PlotCluster> clusters = new HashMap<>();
Statement stmt = null; Statement stmt = null;
try { try {
Set<String> worlds = new HashSet<>(); HashSet<String> areas = new HashSet<>();;
if (PS.get().config.contains("worlds")) { if (PS.get().config.contains("worlds")) {
worlds = PS.get().config.getConfigurationSection("worlds").getKeys(false); ConfigurationSection worldSection = PS.get().config.getConfigurationSection("worlds");
if (worldSection != null) {
for (String worldKey : worldSection.getKeys(false)) {
areas.add(worldKey);
ConfigurationSection areaSection = worldSection.getConfigurationSection(worldKey + ".areas");
if (areaSection != null) {
for (String areaKey : areaSection.getKeys(false)) {
String[] split = areaKey.split("-");
if (split.length == 3) {
areas.add(worldKey + ";" + split[0]);
}
}
}
}
}
} }
final HashMap<String, UUID> uuids = new HashMap<>(); final HashMap<String, UUID> uuids = new HashMap<>();
final HashMap<String, Integer> noExist = new HashMap<>(); final HashMap<String, Integer> noExist = new HashMap<>();
@ -2439,19 +2492,19 @@ public class SQLManager implements AbstractDB {
PlotId pos2; PlotId pos2;
PlotCluster cluster; PlotCluster cluster;
String owner; String owner;
String worldname; String areaid;
UUID user; UUID user;
int id; int id;
while (r.next()) { while (r.next()) {
pos1 = new PlotId(r.getInt("pos1_x"), r.getInt("pos1_z")); pos1 = new PlotId(r.getInt("pos1_x"), r.getInt("pos1_z"));
pos2 = new PlotId(r.getInt("pos2_x"), r.getInt("pos2_z")); pos2 = new PlotId(r.getInt("pos2_x"), r.getInt("pos2_z"));
id = r.getInt("id"); id = r.getInt("id");
worldname = r.getString("world"); areaid = r.getString("world");
if (!worlds.contains(worldname)) { if (!areas.contains(areaid)) {
if (noExist.containsKey(worldname)) { if (noExist.containsKey(areaid)) {
noExist.put(worldname, noExist.get(worldname) + 1); noExist.put(areaid, noExist.get(areaid) + 1);
} else { } else {
noExist.put(worldname, 1); noExist.put(areaid, 1);
} }
} }
owner = r.getString("owner"); owner = r.getString("owner");
@ -2460,8 +2513,14 @@ public class SQLManager implements AbstractDB {
user = UUID.fromString(owner); user = UUID.fromString(owner);
uuids.put(owner, user); uuids.put(owner, user);
} }
cluster = new PlotCluster(worldname, pos1, pos2, user, id); cluster = new PlotCluster(null, pos1, pos2, user, id);
clusters.put(id, cluster); clusters.put(id, cluster);
Set<PlotCluster> set = newClusters.get(areaid);
if (set == null) {
set = new HashSet<>();
newClusters.put(areaid, set);
}
set.add(cluster);
} }
/* /*
* Getting helpers * Getting helpers
@ -2569,18 +2628,11 @@ public class SQLManager implements AbstractDB {
} }
stmt.close(); stmt.close();
r.close(); r.close();
for (final PlotCluster c : clusters.values()) {
final String world = c.world;
if (!newClusters.containsKey(world)) {
newClusters.put(world, new HashSet<PlotCluster>());
}
newClusters.get(world).add(c);
}
boolean invalidPlot = false; boolean invalidPlot = false;
for (final Entry<String, Integer> entry : noExist.entrySet()) { for (final Entry<String, Integer> entry : noExist.entrySet()) {
final String w = entry.getKey(); final String a = entry.getKey();
invalidPlot = true; invalidPlot = true;
PS.debug("&c[WARNING] Found " + noExist.get(w) + " clusters in DB for non existant world; '" + w + "'."); PS.debug("&c[WARNING] Found " + noExist.get(a) + " clusters in DB for non existant area; '" + a + "'.");
} }
if (invalidPlot) { if (invalidPlot) {
PS.debug("&c[WARNING] - Please create the world/s or remove the clusters using the purge command"); PS.debug("&c[WARNING] - Please create the world/s or remove the clusters using the purge command");
@ -2676,7 +2728,7 @@ public class SQLManager implements AbstractDB {
stmt.setInt(3, cluster.getP2().x); stmt.setInt(3, cluster.getP2().x);
stmt.setInt(4, cluster.getP2().y); stmt.setInt(4, cluster.getP2().y);
stmt.setString(5, cluster.owner.toString()); stmt.setString(5, cluster.owner.toString());
stmt.setString(6, cluster.world); stmt.setString(6, cluster.area.toString());
} }
@Override @Override
@ -2713,11 +2765,11 @@ public class SQLManager implements AbstractDB {
} }
@Override @Override
public void resizeCluster(final PlotCluster current, final PlotClusterId resize) { public void resizeCluster(final PlotCluster current, PlotId min, PlotId max) {
final PlotId pos1 = new PlotId(current.getP1().x, current.getP1().y); final PlotId pos1 = new PlotId(current.getP1().x, current.getP1().y);
final PlotId pos2 = new PlotId(current.getP2().x, current.getP2().y); final PlotId pos2 = new PlotId(current.getP2().x, current.getP2().y);
current.setP1(resize.pos1); current.setP1(min);
current.setP2(resize.pos2); current.setP2(max);
addClusterTask(current, new UniqueStatement("resizeCluster") { addClusterTask(current, new UniqueStatement("resizeCluster") {
@Override @Override
@ -2857,13 +2909,13 @@ public class SQLManager implements AbstractDB {
} catch (final SQLException e) { } catch (final SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
final ConcurrentHashMap<String, ConcurrentHashMap<PlotId, Plot>> database = getPlots(); final HashMap<String, HashMap<PlotId, Plot>> database = getPlots();
final ArrayList<Plot> toCreate = new ArrayList<>(); final ArrayList<Plot> toCreate = new ArrayList<>();
for (final Plot plot : PS.get().getPlotsRaw()) { for (final Plot plot : toValidate) {
if (plot.temp == -1) { if (plot.temp == -1) {
continue; continue;
} }
final ConcurrentHashMap<PlotId, Plot> worldplots = database.get(plot.world); final HashMap<PlotId, Plot> worldplots = database.get(plot.area.toString());
if (worldplots == null) { if (worldplots == null) {
PS.debug("&8 - &7Creating plot (1): " + plot); PS.debug("&8 - &7Creating plot (1): " + plot);
toCreate.add(plot); toCreate.add(plot);
@ -2948,14 +3000,10 @@ public class SQLManager implements AbstractDB {
setFlags(plot, pf.values()); setFlags(plot, pf.values());
} }
} }
// TODO comments (null)
// TODO ratings (null)
// TODO alias
// TODO unconnected entries from helpers, trusted, denied, comments, settings, rating
} }
for (final Entry<String, ConcurrentHashMap<PlotId, Plot>> entry : database.entrySet()) { for (final Entry<String, HashMap<PlotId, Plot>> entry : database.entrySet()) {
final ConcurrentHashMap<PlotId, Plot> map = entry.getValue(); final HashMap<PlotId, Plot> map = entry.getValue();
if (map.size() > 0) { if (map.size() > 0) {
for (final Entry<PlotId, Plot> entry2 : map.entrySet()) { for (final Entry<PlotId, Plot> entry2 : map.entrySet()) {
PS.debug("$1Plot was deleted: " + entry2.getValue() + "// TODO implement this when sure safe"); PS.debug("$1Plot was deleted: " + entry2.getValue() + "// TODO implement this when sure safe");

View File

@ -31,12 +31,12 @@ import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotSettings; import com.intellectualcrafters.plot.object.PlotSettings;
import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
/** /**
@ -97,20 +97,24 @@ public class FlagManager {
public static boolean addFlag(final AbstractFlag af, final boolean reserved) { public static boolean addFlag(final AbstractFlag af, final boolean reserved) {
PS.debug(C.PREFIX.s() + "&8 - Adding flag: &7" + af); PS.debug(C.PREFIX.s() + "&8 - Adding flag: &7" + af);
for (final PlotWorld plotworld : PS.get().getPlotWorldObjects()) { PS.get().foreachPlotArea(new RunnableVal<PlotArea>() {
final Flag flag = ((HashMap<String, Flag>) plotworld.DEFAULT_FLAGS.clone()).get(af.getKey()); @Override
if (flag != null) { public void run(PlotArea value) {
flag.setKey(af); final Flag flag = ((HashMap<String, Flag>) value.DEFAULT_FLAGS.clone()).get(af.getKey());
}
}
if (PS.get().getAllPlotsRaw() != null) {
for (final Plot plot : PS.get().getPlotsRaw()) {
final Flag flag = plot.getFlags().get(af.getKey());
if (flag != null) { if (flag != null) {
flag.setKey(af); flag.setKey(af);
} }
} }
} });
PS.get().foreachPlot(new RunnableVal<Plot>() {
@Override
public void run(Plot value) {
final Flag flag = value.getFlags().get(af.getKey());
if (flag != null) {
flag.setKey(af);
}
}
});
if ((getFlag(af.getKey()) == null) && flags.add(af)) { if ((getFlag(af.getKey()) == null) && flags.add(af)) {
if (reserved) { if (reserved) {
reserveFlag(af.getKey()); reserveFlag(af.getKey());
@ -120,17 +124,16 @@ public class FlagManager {
return false; return false;
} }
public static Flag getSettingFlag(final String world, final PlotSettings settings, final String id) { public static Flag getSettingFlag(final PlotArea area, final PlotSettings settings, final String id) {
Flag flag; Flag flag;
if ((settings.flags.size() == 0) || ((flag = settings.flags.get(id)) == null)) { if ((settings.flags.size() == 0) || ((flag = settings.flags.get(id)) == null)) {
final PlotWorld plotworld = PS.get().getPlotWorld(world); if (area == null) {
if (plotworld == null) {
return null; return null;
} }
if (plotworld.DEFAULT_FLAGS.size() == 0) { if (area.DEFAULT_FLAGS.size() == 0) {
return null; return null;
} }
return plotworld.DEFAULT_FLAGS.get(id); return area.DEFAULT_FLAGS.get(id);
} }
return flag; return flag;
} }
@ -170,7 +173,7 @@ public class FlagManager {
if (plot.owner == null) { if (plot.owner == null) {
return null; return null;
} }
return getSettingFlag(plot.world, plot.getSettings(), flag); return getSettingFlag(plot.area, plot.getSettings(), flag);
} }
public static boolean isPlotFlagTrue(final Plot plot, final String strFlag) { public static boolean isPlotFlagTrue(final Plot plot, final String strFlag) {
@ -219,9 +222,9 @@ public class FlagManager {
if (!result) { if (!result) {
return false; return false;
} }
for (Plot plot : MainUtil.getConnectedPlots(origin)) { for (Plot plot : origin.getConnectedPlots()) {
plot.getFlags().put(flag.getKey(), flag); plot.getFlags().put(flag.getKey(), flag);
MainUtil.reEnterPlot(plot); plot.reEnter();
DBFunc.setFlags(plot, plot.getFlags().values()); DBFunc.setFlags(plot, plot.getFlags().values());
} }
return true; return true;
@ -237,7 +240,7 @@ public class FlagManager {
} }
public static boolean addClusterFlag(final PlotCluster cluster, final Flag flag) { public static boolean addClusterFlag(final PlotCluster cluster, final Flag flag) {
getSettingFlag(cluster.world, cluster.settings, flag.getKey()); getSettingFlag(cluster.area, cluster.settings, flag.getKey());
cluster.settings.flags.put(flag.getKey(), flag); cluster.settings.flags.put(flag.getKey(), flag);
DBFunc.setFlags(cluster, cluster.settings.flags.values()); DBFunc.setFlags(cluster, cluster.settings.flags.values());
return true; return true;
@ -252,17 +255,14 @@ public class FlagManager {
if (!plot.hasOwner()) { if (!plot.hasOwner()) {
return null; return null;
} }
return getSettingFlags(plot.world, plot.getSettings()); return getSettingFlags(plot.area, plot.getSettings());
} }
public static HashMap<String, Flag> getPlotFlags(final String world, final PlotSettings settings, final boolean ignorePluginflags) { public static HashMap<String, Flag> getPlotFlags(PlotArea area, final PlotSettings settings, final boolean ignorePluginflags) {
final HashMap<String, Flag> flags = new HashMap<>(); final HashMap<String, Flag> flags = new HashMap<>();
if ((area != null) && (area.DEFAULT_FLAGS.size() != 0)) {
final PlotWorld plotWorld = PS.get().getPlotWorld(world); flags.putAll(area.DEFAULT_FLAGS);
if ((plotWorld != null) && (plotWorld.DEFAULT_FLAGS.size() != 0)) {
flags.putAll(plotWorld.DEFAULT_FLAGS);
} }
if (ignorePluginflags) { if (ignorePluginflags) {
for (final Map.Entry<String, Flag> flag : settings.flags.entrySet()) { for (final Map.Entry<String, Flag> flag : settings.flags.entrySet()) {
if (isReserved(flag.getValue().getAbstractFlag().getKey())) { if (isReserved(flag.getValue().getAbstractFlag().getKey())) {
@ -277,8 +277,8 @@ public class FlagManager {
return flags; return flags;
} }
public static HashMap<String, Flag> getSettingFlags(final String world, final PlotSettings settings) { public static HashMap<String, Flag> getSettingFlags(PlotArea area, final PlotSettings settings) {
return getPlotFlags(world, settings, false); return getPlotFlags(area, settings, false);
} }
public static boolean removePlotFlag(final Plot plot, final String id) { public static boolean removePlotFlag(final Plot plot, final String id) {
@ -291,7 +291,7 @@ public class FlagManager {
plot.getFlags().put(id, flag); plot.getFlags().put(id, flag);
return false; return false;
} }
MainUtil.reEnterPlot(plot); plot.reEnter();
DBFunc.setFlags(plot, plot.getFlags().values()); DBFunc.setFlags(plot, plot.getFlags().values());
return true; return true;
} }
@ -322,7 +322,7 @@ public class FlagManager {
} else { } else {
plot.getFlags().clear(); plot.getFlags().clear();
} }
MainUtil.reEnterPlot(plot); plot.reEnter();
DBFunc.setFlags(plot, plot.getFlags().values()); DBFunc.setFlags(plot, plot.getFlags().values());
} }
} }

View File

@ -6,9 +6,9 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.StringComparison; import com.intellectualcrafters.plot.util.StringComparison;
import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.WorldUtil;
/** /**
* Created 2014-11-17 for PlotSquared * Created 2014-11-17 for PlotSquared
@ -278,7 +278,7 @@ public abstract class FlagValue<T> {
final short id = Short.parseShort(split[0]); final short id = Short.parseShort(split[0]);
return new PlotBlock(id, data); return new PlotBlock(id, data);
} catch (final Exception e) { } catch (final Exception e) {
final StringComparison<PlotBlock>.ComparisonResult value = BlockManager.manager.getClosestBlock(t); final StringComparison<PlotBlock>.ComparisonResult value = WorldUtil.IMP.getClosestBlock(t);
if ((value == null) || (value.match > 1)) { if ((value == null) || (value.match > 1)) {
return null; return null;
} }
@ -331,7 +331,7 @@ public abstract class FlagValue<T> {
final short id = Short.parseShort(split[0]); final short id = Short.parseShort(split[0]);
block = new PlotBlock(id, data); block = new PlotBlock(id, data);
} catch (Exception e) { } catch (Exception e) {
final StringComparison<PlotBlock>.ComparisonResult value = BlockManager.manager.getClosestBlock(t); final StringComparison<PlotBlock>.ComparisonResult value = WorldUtil.IMP.getClosestBlock(t);
if ((value == null) || (value.match > 1)) { if ((value == null) || (value.match > 1)) {
continue; continue;
} }

View File

@ -0,0 +1,161 @@
package com.intellectualcrafters.plot.generator;
import java.util.Set;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PseudoRandom;
import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.util.PlotChunk;
import com.intellectualcrafters.plot.util.SetQueue;
import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper;
public class AugmentedUtils {
private static boolean enabled = true;
public static void bypass(boolean bypass, Runnable run) {
enabled = bypass;
run.run();
enabled = true;
}
public static void generate(String world, int cx, int cz) {
if (!enabled) {
return;
}
final int bx = cx << 4;
final int bz = cz << 4;
RegionWrapper region = new RegionWrapper(bx, bx + 16, bz, bz + 16);
Set<PlotArea> areas = PS.get().getPlotAreas(world, region);
if (areas.size() == 0) {
return;
}
final PseudoRandom r = new PseudoRandom();
r.state = (cx << 16) | (cz & 0xFFFF);;
PlotChunk<?> cache_chunk = null;
ChunkWrapper wrap = SetQueue.IMP.new ChunkWrapper(world, cx, cz);
for (final PlotArea area : areas) {
if (area.TYPE == 0) {
return;
}
if (area.TERRAIN == 3) {
continue;
}
IndependentPlotGenerator generator = area.getGenerator();
if (generator == null) {
continue;
}
if (cache_chunk == null) {
cache_chunk = SetQueue.IMP.queue.getChunk(wrap);
}
final PlotChunk<?> result = cache_chunk;
final PlotChunk<?> primaryMask;
// coords
int bxx = Math.max(0, area.getRegion().minX - bx);
int bzz = Math.max(0, area.getRegion().minZ - bz);
int txx = Math.min(16, area.getRegion().maxX - bx);
int tzz = Math.min(16, area.getRegion().maxZ - bz);
// gen
if (area.TYPE == 2) {
primaryMask = new PlotChunk<Object>(wrap) {
@Override
public Object getChunkAbs() {
return null;
}
@Override
public void setBlock(int x, int y, int z, int id, byte data) {
if (area.contains(bx + x, bz + z)) {
result.setBlock(x, y, z, id, data);
}
}
@Override
public void setBiome(int x, int z, int biome) {
if (area.contains(bx + x, bz + z)) {
result.setBiome(x, z, biome);
}
}
@Override
public PlotChunk clone() {
return null;
}
@Override
public PlotChunk shallowClone() {
return null;
}
};
} else {
primaryMask = result;
}
PlotChunk<?> secondaryMask;
PlotBlock air = new PlotBlock((short) 0, (byte) 0);
if (area.TERRAIN == 2) {
PlotManager manager = area.getPlotManager();
final boolean[][] canPlace = new boolean[16][16];
boolean has = false;
for (int x = bxx; x < txx; x++) {
for (int z = bzz; z < tzz; z++) {
int rx = x + bx;
int rz = z + bz;
boolean can = manager.getPlotIdAbs(area, rx, 0, rz) == null;
if (can) {
for (int y = 1; y < 128; y++) {
result.setBlock(x, y, z, air);
}
canPlace[x][z] = can;
has = true;
}
}
}
if (!has) {
continue;
}
secondaryMask = new PlotChunk<Object>(wrap) {
@Override
public Object getChunkAbs() {
return null;
}
@Override
public void setBlock(int x, int y, int z, int id, byte data) {
if (canPlace[x][z]) {
primaryMask.setBlock(x, y, z, id, data);
}
}
@Override
public void setBiome(int x, int z, int biome) {}
@Override
public PlotChunk clone() {
return null;
}
@Override
public PlotChunk shallowClone() {
return null;
}
};
} else {
secondaryMask = primaryMask;
for (int x = bxx; x < txx; x++) {
for (int z = bzz; z < tzz; z++) {
for (int y = 1; y < 128; y++) {
result.setBlock(x, y, z, air);
}
}
}
}
generator.generateChunk(secondaryMask, area, r);
}
if (cache_chunk != null) {
cache_chunk.addToQueue();
}
}
}

View File

@ -1,23 +1,23 @@
package com.intellectualcrafters.plot.generator; package com.intellectualcrafters.plot.generator;
import java.util.ArrayList;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.PseudoRandom; import com.intellectualcrafters.plot.object.PseudoRandom;
import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.SetBlockQueue; import com.intellectualcrafters.plot.util.SetQueue;
import java.util.ArrayList;
/** /**
* A plot manager with square plots which tessellate on a square grid with the following sections: ROAD, WALL, BORDER (wall), PLOT, FLOOR (plot) * A plot manager with square plots which tessellate on a square grid with the following sections: ROAD, WALL, BORDER (wall), PLOT, FLOOR (plot)
*/ */
public class ClassicPlotManager extends SquarePlotManager { public class ClassicPlotManager extends SquarePlotManager {
@Override @Override
public boolean setComponent(final PlotWorld plotworld, final PlotId plotid, final String component, final PlotBlock[] blocks) { public boolean setComponent(final PlotArea plotworld, final PlotId plotid, final String component, final PlotBlock[] blocks) {
switch (component) { switch (component) {
case "floor": { case "floor": {
setFloor(plotworld, plotid, blocks); setFloor(plotworld, plotid, blocks);
@ -56,95 +56,95 @@ public class ClassicPlotManager extends SquarePlotManager {
} }
@Override @Override
public boolean unclaimPlot(final PlotWorld plotworld, final Plot plot, final Runnable whenDone) { public boolean unclaimPlot(final PlotArea plotworld, final Plot plot, final Runnable whenDone) {
final ClassicPlotWorld dpw = ((ClassicPlotWorld) plotworld); final ClassicPlotWorld dpw = ((ClassicPlotWorld) plotworld);
setWallFilling(dpw, plot.getId(), new PlotBlock[] { dpw.WALL_FILLING }); setWallFilling(dpw, plot.getId(), new PlotBlock[] { dpw.WALL_FILLING });
if ((dpw.WALL_BLOCK.id != 0) || !dpw.WALL_BLOCK.equals(dpw.CLAIMED_WALL_BLOCK)) { if ((dpw.WALL_BLOCK.id != 0) || !dpw.WALL_BLOCK.equals(dpw.CLAIMED_WALL_BLOCK)) {
setWall(dpw, plot.getId(), new PlotBlock[] { dpw.WALL_BLOCK }); setWall(dpw, plot.getId(), new PlotBlock[] { dpw.WALL_BLOCK });
} }
SetBlockQueue.addNotify(whenDone); SetQueue.IMP.addTask(whenDone);
return true; return true;
} }
public boolean setFloor(final PlotWorld plotworld, final PlotId plotid, final PlotBlock[] blocks) { public boolean setFloor(final PlotArea plotworld, final PlotId plotid, final PlotBlock[] blocks) {
Plot plot = MainUtil.getPlotAbs(plotworld.worldname, plotid); Plot plot = plotworld.getPlotAbs(plotid);
if (plot.isBasePlot()) { if (plot.isBasePlot()) {
final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld; final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld;
for (RegionWrapper region : MainUtil.getRegions(plot)) { for (RegionWrapper region : plot.getRegions()) {
Location pos1 = new Location(plot.world, region.minX, dpw.PLOT_HEIGHT, region.minZ); Location pos1 = new Location(plotworld.worldname, region.minX, dpw.PLOT_HEIGHT, region.minZ);
Location pos2 = new Location(plot.world, region.maxX, dpw.PLOT_HEIGHT, region.maxZ); Location pos2 = new Location(plotworld.worldname, region.maxX, dpw.PLOT_HEIGHT, region.maxZ);
MainUtil.setCuboidAsync(plotworld.worldname, pos1, pos2, blocks); MainUtil.setCuboidAsync(plotworld.worldname, pos1, pos2, blocks);
} }
} }
return true; return true;
} }
public boolean setAll(final PlotWorld plotworld, final PlotId plotid, final PlotBlock[] blocks) { public boolean setAll(final PlotArea plotworld, final PlotId plotid, final PlotBlock[] blocks) {
Plot plot = MainUtil.getPlotAbs(plotworld.worldname, plotid); Plot plot = plotworld.getPlotAbs(plotid);
if (!plot.isBasePlot()) { if (!plot.isBasePlot()) {
return false; return false;
} }
for (RegionWrapper region : MainUtil.getRegions(plot)) { for (RegionWrapper region : plot.getRegions()) {
Location pos1 = new Location(plot.world, region.minX, 1, region.minZ); Location pos1 = new Location(plotworld.worldname, region.minX, 1, region.minZ);
Location pos2 = new Location(plot.world, region.maxX, 255, region.maxZ); Location pos2 = new Location(plotworld.worldname, region.maxX, 255, region.maxZ);
MainUtil.setCuboidAsync(plotworld.worldname, pos1, pos2, blocks); MainUtil.setCuboidAsync(plotworld.worldname, pos1, pos2, blocks);
} }
return true; return true;
} }
public boolean setAir(final PlotWorld plotworld, final PlotId plotid, final PlotBlock[] blocks) { public boolean setAir(final PlotArea plotworld, final PlotId plotid, final PlotBlock[] blocks) {
Plot plot = MainUtil.getPlotAbs(plotworld.worldname, plotid); Plot plot = plotworld.getPlotAbs(plotid);
if (!plot.isBasePlot()) { if (!plot.isBasePlot()) {
return false; return false;
} }
final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld; final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld;
for (RegionWrapper region : MainUtil.getRegions(plot)) { for (RegionWrapper region : plot.getRegions()) {
Location pos1 = new Location(plot.world, region.minX, dpw.PLOT_HEIGHT + 1, region.minZ); Location pos1 = new Location(plotworld.worldname, region.minX, dpw.PLOT_HEIGHT + 1, region.minZ);
Location pos2 = new Location(plot.world, region.maxX, 255, region.maxZ); Location pos2 = new Location(plotworld.worldname, region.maxX, 255, region.maxZ);
MainUtil.setCuboidAsync(plotworld.worldname, pos1, pos2, blocks); MainUtil.setCuboidAsync(plotworld.worldname, pos1, pos2, blocks);
} }
return true; return true;
} }
public boolean setMain(final PlotWorld plotworld, final PlotId plotid, final PlotBlock[] blocks) { public boolean setMain(final PlotArea plotworld, final PlotId plotid, final PlotBlock[] blocks) {
Plot plot = MainUtil.getPlotAbs(plotworld.worldname, plotid); Plot plot = plotworld.getPlotAbs(plotid);
if (!plot.isBasePlot()) { if (!plot.isBasePlot()) {
return false; return false;
} }
final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld; final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld;
for (RegionWrapper region : MainUtil.getRegions(plot)) { for (RegionWrapper region : plot.getRegions()) {
Location pos1 = new Location(plot.world, region.minX, 1, region.minZ); Location pos1 = new Location(plotworld.worldname, region.minX, 1, region.minZ);
Location pos2 = new Location(plot.world, region.maxX, dpw.PLOT_HEIGHT - 1, region.maxZ); Location pos2 = new Location(plotworld.worldname, region.maxX, dpw.PLOT_HEIGHT - 1, region.maxZ);
MainUtil.setCuboidAsync(plotworld.worldname, pos1, pos2, blocks); MainUtil.setCuboidAsync(plotworld.worldname, pos1, pos2, blocks);
} }
return true; return true;
} }
public boolean setMiddle(final PlotWorld plotworld, final PlotId plotid, final PlotBlock[] blocks) { public boolean setMiddle(final PlotArea plotworld, final PlotId plotid, final PlotBlock[] blocks) {
Plot plot = MainUtil.getPlotAbs(plotworld.worldname, plotid); Plot plot = plotworld.getPlotAbs(plotid);
if (!plot.isBasePlot()) { if (!plot.isBasePlot()) {
return false; return false;
} }
Location[] corners = plot.getCorners(); Location[] corners = plot.getCorners();
final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld; final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld;
SetBlockQueue.setBlock(plotworld.worldname, (corners[0].getX() + corners[1].getX()) / 2, dpw.PLOT_HEIGHT, (corners[0].getZ() + corners[1].getZ()) / 2, blocks[0]); SetQueue.IMP.setBlock(plotworld.worldname, (corners[0].getX() + corners[1].getX()) / 2, dpw.PLOT_HEIGHT, (corners[0].getZ() + corners[1].getZ()) / 2, blocks[0]);
return true; return true;
} }
public boolean setOutline(final PlotWorld plotworld, final PlotId plotid, final PlotBlock[] blocks) { public boolean setOutline(final PlotArea plotworld, final PlotId plotid, final PlotBlock[] blocks) {
final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld; final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld;
if (dpw.ROAD_WIDTH == 0) { if (dpw.ROAD_WIDTH == 0) {
return false; return false;
} }
Plot plot = MainUtil.getPlotAbs(plotworld.worldname, plotid); Plot plot = plotworld.getPlotAbs(plotid);
final Location bottom = MainUtil.getPlotBottomLocAbs(plotworld.worldname, plotid); final Location bottom = plot.getBottomAbs();
final Location top = MainUtil.getPlotTopLoc_(plot); final Location top = plot.getExtendedTopAbs();
final PseudoRandom random = new PseudoRandom(); final PseudoRandom random = new PseudoRandom();
if (!plot.getMerged(0)) { if (!plot.getMerged(0)) {
int z = bottom.getZ(); int z = bottom.getZ();
for (int x = bottom.getX(); x <= (top.getX()); x++) { for (int x = bottom.getX(); x <= (top.getX()); x++) {
for (int y = dpw.PLOT_HEIGHT; y <= 255; y++) { for (int y = dpw.PLOT_HEIGHT; y <= 255; y++) {
SetBlockQueue.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]); SetQueue.IMP.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]);
} }
} }
} }
@ -152,7 +152,7 @@ public class ClassicPlotManager extends SquarePlotManager {
int x = bottom.getX(); int x = bottom.getX();
for (int z = bottom.getZ(); z <= (top.getZ()); z++) { for (int z = bottom.getZ(); z <= (top.getZ()); z++) {
for (int y = dpw.PLOT_HEIGHT; y <= 255; y++) { for (int y = dpw.PLOT_HEIGHT; y <= 255; y++) {
SetBlockQueue.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]); SetQueue.IMP.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]);
} }
} }
} }
@ -161,7 +161,7 @@ public class ClassicPlotManager extends SquarePlotManager {
int z = top.getZ(); int z = top.getZ();
for (int x = bottom.getX(); x <= (top.getX()); x++) { for (int x = bottom.getX(); x <= (top.getX()); x++) {
for (int y = dpw.PLOT_HEIGHT; y <= 255; y++) { for (int y = dpw.PLOT_HEIGHT; y <= 255; y++) {
SetBlockQueue.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]); SetQueue.IMP.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]);
} }
} }
} }
@ -169,34 +169,34 @@ public class ClassicPlotManager extends SquarePlotManager {
int x = top.getX(); int x = top.getX();
for (int z = bottom.getZ(); z <= (top.getZ()); z++) { for (int z = bottom.getZ(); z <= (top.getZ()); z++) {
for (int y = dpw.PLOT_HEIGHT; y <= 255; y++) { for (int y = dpw.PLOT_HEIGHT; y <= 255; y++) {
SetBlockQueue.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]); SetQueue.IMP.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]);
} }
} }
} }
if (plot.isBasePlot()) { if (plot.isBasePlot()) {
for (RegionWrapper region : MainUtil.getRegions(plot)) { for (RegionWrapper region : plot.getRegions()) {
Location pos1 = new Location(plot.world, region.minX, 255, region.minZ); Location pos1 = new Location(plotworld.worldname, region.minX, 255, region.minZ);
Location pos2 = new Location(plot.world, region.maxX, 255, region.maxZ); Location pos2 = new Location(plotworld.worldname, region.maxX, 255, region.maxZ);
MainUtil.setCuboidAsync(plotworld.worldname, pos1, pos2, blocks); MainUtil.setCuboidAsync(plotworld.worldname, pos1, pos2, blocks);
} }
} }
return true; return true;
} }
public boolean setWallFilling(final PlotWorld plotworld, final PlotId plotid, final PlotBlock[] blocks) { public boolean setWallFilling(final PlotArea plotworld, final PlotId plotid, final PlotBlock[] blocks) {
final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld; final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld;
if (dpw.ROAD_WIDTH == 0) { if (dpw.ROAD_WIDTH == 0) {
return false; return false;
} }
Plot plot = MainUtil.getPlotAbs(plotworld.worldname, plotid); Plot plot = plotworld.getPlotAbs(plotid);
final Location bot = MainUtil.getPlotBottomLoc_(plot).subtract(plot.getMerged(3) ? 0 : 1, 0, plot.getMerged(0) ? 0 : 1); final Location bot = plot.getExtendedBottomAbs().subtract(plot.getMerged(3) ? 0 : 1, 0, plot.getMerged(0) ? 0 : 1);
final Location top = MainUtil.getPlotTopLoc_(plot).add(1, 0, 1); final Location top = plot.getExtendedTopAbs().add(1, 0, 1);
final PseudoRandom random = new PseudoRandom(); final PseudoRandom random = new PseudoRandom();
if (!plot.getMerged(0)) { if (!plot.getMerged(0)) {
int z = bot.getZ(); int z = bot.getZ();
for (int x = bot.getX(); x < (top.getX()); x++) { for (int x = bot.getX(); x < (top.getX()); x++) {
for (int y = 1; y <= dpw.WALL_HEIGHT; y++) { for (int y = 1; y <= dpw.WALL_HEIGHT; y++) {
SetBlockQueue.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]); SetQueue.IMP.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]);
} }
} }
} }
@ -204,7 +204,7 @@ public class ClassicPlotManager extends SquarePlotManager {
int x = bot.getX(); int x = bot.getX();
for (int z = bot.getZ(); z < (top.getZ()); z++) { for (int z = bot.getZ(); z < (top.getZ()); z++) {
for (int y = 1; y <= dpw.WALL_HEIGHT; y++) { for (int y = 1; y <= dpw.WALL_HEIGHT; y++) {
SetBlockQueue.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]); SetQueue.IMP.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]);
} }
} }
} }
@ -212,7 +212,7 @@ public class ClassicPlotManager extends SquarePlotManager {
int z = top.getZ(); int z = top.getZ();
for (int x = bot.getX(); x < (top.getX() + (plot.getMerged(1) ? 0 : 1)); x++) { for (int x = bot.getX(); x < (top.getX() + (plot.getMerged(1) ? 0 : 1)); x++) {
for (int y = 1; y <= dpw.WALL_HEIGHT; y++) { for (int y = 1; y <= dpw.WALL_HEIGHT; y++) {
SetBlockQueue.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]); SetQueue.IMP.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]);
} }
} }
} }
@ -220,45 +220,45 @@ public class ClassicPlotManager extends SquarePlotManager {
int x = top.getX(); int x = top.getX();
for (int z = bot.getZ(); z < (top.getZ() + (plot.getMerged(2) ? 0 : 1)); z++) { for (int z = bot.getZ(); z < (top.getZ() + (plot.getMerged(2) ? 0 : 1)); z++) {
for (int y = 1; y <= dpw.WALL_HEIGHT; y++) { for (int y = 1; y <= dpw.WALL_HEIGHT; y++) {
SetBlockQueue.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]); SetQueue.IMP.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]);
} }
} }
} }
return true; return true;
} }
public boolean setWall(final PlotWorld plotworld, final PlotId plotid, final PlotBlock[] blocks) { public boolean setWall(final PlotArea plotworld, final PlotId plotid, final PlotBlock[] blocks) {
final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld; final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld;
if (dpw.ROAD_WIDTH == 0) { if (dpw.ROAD_WIDTH == 0) {
return false; return false;
} }
Plot plot = MainUtil.getPlotAbs(plotworld.worldname, plotid); Plot plot = plotworld.getPlotAbs(plotid);
final Location bot = MainUtil.getPlotBottomLoc_(plot).subtract(plot.getMerged(3) ? 0 : 1, 0, plot.getMerged(0) ? 0 : 1); final Location bot = plot.getExtendedBottomAbs().subtract(plot.getMerged(3) ? 0 : 1, 0, plot.getMerged(0) ? 0 : 1);
final Location top = MainUtil.getPlotTopLoc_(plot).add(1, 0, 1); final Location top = plot.getExtendedTopAbs().add(1, 0, 1);
final PseudoRandom random = new PseudoRandom(); final PseudoRandom random = new PseudoRandom();
final int y = dpw.WALL_HEIGHT + 1; final int y = dpw.WALL_HEIGHT + 1;
if (!plot.getMerged(0)) { if (!plot.getMerged(0)) {
int z = bot.getZ(); int z = bot.getZ();
for (int x = bot.getX(); x < (top.getX()); x++) { for (int x = bot.getX(); x < (top.getX()); x++) {
SetBlockQueue.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]); SetQueue.IMP.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]);
} }
} }
if (!plot.getMerged(3)) { if (!plot.getMerged(3)) {
int x = bot.getX(); int x = bot.getX();
for (int z = bot.getZ(); z < (top.getZ()); z++) { for (int z = bot.getZ(); z < (top.getZ()); z++) {
SetBlockQueue.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]); SetQueue.IMP.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]);
} }
} }
if (!plot.getMerged(2)) { if (!plot.getMerged(2)) {
int z = top.getZ(); int z = top.getZ();
for (int x = bot.getX(); x < (top.getX() + (plot.getMerged(1) ? 0 : 1)); x++) { for (int x = bot.getX(); x < (top.getX() + (plot.getMerged(1) ? 0 : 1)); x++) {
SetBlockQueue.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]); SetQueue.IMP.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]);
} }
} }
if (!plot.getMerged(1)) { if (!plot.getMerged(1)) {
int x = top.getX(); int x = top.getX();
for (int z = bot.getZ(); z < (top.getZ() + (plot.getMerged(2) ? 0 : 1)); z++) { for (int z = bot.getZ(); z < (top.getZ() + (plot.getMerged(2) ? 0 : 1)); z++) {
SetBlockQueue.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]); SetQueue.IMP.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]);
} }
} }
return true; return true;
@ -268,7 +268,7 @@ public class ClassicPlotManager extends SquarePlotManager {
* PLOT MERGING * PLOT MERGING
*/ */
@Override @Override
public boolean createRoadEast(final PlotWorld plotworld, final Plot plot) { public boolean createRoadEast(final PlotArea plotworld, final Plot plot) {
final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld; final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld;
final Location pos1 = getPlotBottomLocAbs(plotworld, plot.getId()); final Location pos1 = getPlotBottomLocAbs(plotworld, plot.getId());
final Location pos2 = getPlotTopLocAbs(plotworld, plot.getId()); final Location pos2 = getPlotTopLocAbs(plotworld, plot.getId());
@ -290,7 +290,7 @@ public class ClassicPlotManager extends SquarePlotManager {
} }
@Override @Override
public boolean createRoadSouth(final PlotWorld plotworld, final Plot plot) { public boolean createRoadSouth(final PlotArea plotworld, final Plot plot) {
final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld; final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld;
final Location pos1 = getPlotBottomLocAbs(plotworld, plot.getId()); final Location pos1 = getPlotBottomLocAbs(plotworld, plot.getId());
final Location pos2 = getPlotTopLocAbs(plotworld, plot.getId()); final Location pos2 = getPlotTopLocAbs(plotworld, plot.getId());
@ -311,7 +311,7 @@ public class ClassicPlotManager extends SquarePlotManager {
} }
@Override @Override
public boolean createRoadSouthEast(final PlotWorld plotworld, final Plot plot) { public boolean createRoadSouthEast(final PlotArea plotworld, final Plot plot) {
final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld; final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld;
final Location pos2 = getPlotTopLocAbs(plotworld, plot.getId()); final Location pos2 = getPlotTopLocAbs(plotworld, plot.getId());
final int sx = pos2.getX() + 1; final int sx = pos2.getX() + 1;
@ -326,7 +326,7 @@ public class ClassicPlotManager extends SquarePlotManager {
} }
@Override @Override
public boolean removeRoadEast(final PlotWorld plotworld, final Plot plot) { public boolean removeRoadEast(final PlotArea plotworld, final Plot plot) {
final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld; final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld;
final Location pos1 = getPlotBottomLocAbs(plotworld, plot.getId()); final Location pos1 = getPlotBottomLocAbs(plotworld, plot.getId());
final Location pos2 = getPlotTopLocAbs(plotworld, plot.getId()); final Location pos2 = getPlotTopLocAbs(plotworld, plot.getId());
@ -341,7 +341,7 @@ public class ClassicPlotManager extends SquarePlotManager {
} }
@Override @Override
public boolean removeRoadSouth(final PlotWorld plotworld, final Plot plot) { public boolean removeRoadSouth(final PlotArea plotworld, final Plot plot) {
final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld; final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld;
final Location pos1 = getPlotBottomLocAbs(plotworld, plot.getId()); final Location pos1 = getPlotBottomLocAbs(plotworld, plot.getId());
final Location pos2 = getPlotTopLocAbs(plotworld, plot.getId()); final Location pos2 = getPlotTopLocAbs(plotworld, plot.getId());
@ -356,7 +356,7 @@ public class ClassicPlotManager extends SquarePlotManager {
} }
@Override @Override
public boolean removeRoadSouthEast(final PlotWorld plotworld, final Plot plot) { public boolean removeRoadSouthEast(final PlotArea plotworld, final Plot plot) {
final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld; final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld;
final Location loc = getPlotTopLocAbs(dpw, plot.getId()); final Location loc = getPlotTopLocAbs(dpw, plot.getId());
final int sx = loc.getX() + 1; final int sx = loc.getX() + 1;
@ -373,7 +373,7 @@ public class ClassicPlotManager extends SquarePlotManager {
* Finishing off plot merging by adding in the walls surrounding the plot (OPTIONAL)(UNFINISHED) * Finishing off plot merging by adding in the walls surrounding the plot (OPTIONAL)(UNFINISHED)
*/ */
@Override @Override
public boolean finishPlotMerge(final PlotWorld plotworld, final ArrayList<PlotId> plotIds) { public boolean finishPlotMerge(final PlotArea plotworld, final ArrayList<PlotId> plotIds) {
final PlotBlock block = ((ClassicPlotWorld) plotworld).CLAIMED_WALL_BLOCK; final PlotBlock block = ((ClassicPlotWorld) plotworld).CLAIMED_WALL_BLOCK;
final PlotBlock unclaim = ((ClassicPlotWorld) plotworld).WALL_BLOCK; final PlotBlock unclaim = ((ClassicPlotWorld) plotworld).WALL_BLOCK;
if ((block.id != 0) || !block.equals(unclaim)) { if ((block.id != 0) || !block.equals(unclaim)) {
@ -385,7 +385,7 @@ public class ClassicPlotManager extends SquarePlotManager {
} }
@Override @Override
public boolean finishPlotUnlink(final PlotWorld plotworld, final ArrayList<PlotId> plotIds) { public boolean finishPlotUnlink(final PlotArea plotworld, final ArrayList<PlotId> plotIds) {
final PlotBlock block = ((ClassicPlotWorld) plotworld).CLAIMED_WALL_BLOCK; final PlotBlock block = ((ClassicPlotWorld) plotworld).CLAIMED_WALL_BLOCK;
final PlotBlock unclaim = ((ClassicPlotWorld) plotworld).WALL_BLOCK; final PlotBlock unclaim = ((ClassicPlotWorld) plotworld).WALL_BLOCK;
for (final PlotId id : plotIds) { for (final PlotId id : plotIds) {
@ -397,17 +397,17 @@ public class ClassicPlotManager extends SquarePlotManager {
} }
@Override @Override
public boolean startPlotMerge(final PlotWorld plotworld, final ArrayList<PlotId> plotIds) { public boolean startPlotMerge(final PlotArea plotworld, final ArrayList<PlotId> plotIds) {
return true; return true;
} }
@Override @Override
public boolean startPlotUnlink(final PlotWorld plotworld, final ArrayList<PlotId> plotIds) { public boolean startPlotUnlink(final PlotArea plotworld, final ArrayList<PlotId> plotIds) {
return true; return true;
} }
@Override @Override
public boolean claimPlot(final PlotWorld plotworld, final Plot plot) { public boolean claimPlot(final PlotArea plotworld, final Plot plot) {
final PlotBlock unclaim = ((ClassicPlotWorld) plotworld).WALL_BLOCK; final PlotBlock unclaim = ((ClassicPlotWorld) plotworld).WALL_BLOCK;
final PlotBlock claim = ((ClassicPlotWorld) plotworld).CLAIMED_WALL_BLOCK; final PlotBlock claim = ((ClassicPlotWorld) plotworld).CLAIMED_WALL_BLOCK;
if ((claim.id != 0) || !claim.equals(unclaim)) { if ((claim.id != 0) || !claim.equals(unclaim)) {
@ -417,7 +417,7 @@ public class ClassicPlotManager extends SquarePlotManager {
} }
@Override @Override
public String[] getPlotComponents(final PlotWorld plotworld, final PlotId plotid) { public String[] getPlotComponents(final PlotArea plotworld, final PlotId plotid) {
return new String[] { "main", "floor", "air", "all", "border", "wall", "outline", "middle" }; return new String[] { "main", "floor", "air", "all", "border", "wall", "outline", "middle" };
} }
@ -425,7 +425,7 @@ public class ClassicPlotManager extends SquarePlotManager {
* Remove sign for a plot * Remove sign for a plot
*/ */
@Override @Override
public Location getSignLoc(final PlotWorld plotworld, Plot plot) { public Location getSignLoc(final PlotArea plotworld, Plot plot) {
final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld; final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld;
plot = plot.getBasePlot(false); plot = plot.getBasePlot(false);
final Location bot = plot.getBottomAbs(); final Location bot = plot.getBottomAbs();

View File

@ -4,9 +4,15 @@ import com.intellectualcrafters.configuration.ConfigurationSection;
import com.intellectualcrafters.plot.config.Configuration; import com.intellectualcrafters.plot.config.Configuration;
import com.intellectualcrafters.plot.config.ConfigurationNode; import com.intellectualcrafters.plot.config.ConfigurationNode;
import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.StringMan;
public abstract class ClassicPlotWorld extends SquarePlotWorld { public abstract class ClassicPlotWorld extends SquarePlotWorld {
public ClassicPlotWorld(String worldname, String id, IndependentPlotGenerator generator, PlotId min, PlotId max) {
super(worldname, id, generator, min, max);
}
public static int ROAD_HEIGHT_DEFAULT = 64; public static int ROAD_HEIGHT_DEFAULT = 64;
public static int PLOT_HEIGHT_DEFAULT = 64; public static int PLOT_HEIGHT_DEFAULT = 64;
public static int WALL_HEIGHT_DEFAULT = 64; public static int WALL_HEIGHT_DEFAULT = 64;
@ -69,8 +75,4 @@ public abstract class ClassicPlotWorld extends SquarePlotWorld {
WALL_HEIGHT = Math.min(254, config.getInt("wall.height")); WALL_HEIGHT = Math.min(254, config.getInt("wall.height"));
CLAIMED_WALL_BLOCK = Configuration.BLOCK.parseString(config.getString("wall.block_claimed")); CLAIMED_WALL_BLOCK = Configuration.BLOCK.parseString(config.getString("wall.block_claimed"));
} }
public ClassicPlotWorld(final String worldname) {
super(worldname);
}
} }

View File

@ -0,0 +1,39 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// 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.generator;
import com.intellectualcrafters.plot.object.PlotArea;
public interface GeneratorWrapper<T> {
public IndependentPlotGenerator getPlotGenerator();
public T getPlatformGenerator();
public void augment(PlotArea area);
public boolean isFull();
@Override
public String toString();
@Override
public boolean equals(Object obj);
}

View File

@ -1,11 +1,13 @@
package com.intellectualcrafters.plot.generator; package com.intellectualcrafters.plot.generator;
import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotId;
public abstract class GridPlotWorld extends PlotWorld { public abstract class GridPlotWorld extends PlotArea {
public short SIZE;
public GridPlotWorld(String worldname, String id, IndependentPlotGenerator generator, PlotId min, PlotId max) {
public GridPlotWorld(final String worldname) { super(worldname, id, generator, min, max);
super(worldname);
} }
public short SIZE;
} }

View File

@ -0,0 +1,187 @@
package com.intellectualcrafters.plot.generator;
import java.util.HashMap;
import java.util.Map.Entry;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PseudoRandom;
import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.PlotChunk;
public class HybridGen extends IndependentPlotGenerator {
@Override
public String getName() {
return "PlotSquared";
}
@Override
public void generateChunk(PlotChunk<?> result, PlotArea settings, PseudoRandom random) {
HybridPlotWorld hpw = (HybridPlotWorld) settings;
// Biome
for (short x = 0; x < 16; x++) {
for (short z = 0; z < 16; z++) {
result.setBiome(x, z, hpw.PLOT_BIOME);
}
}
// Bedrock
if (hpw.PLOT_BEDROCK) {
for (short x = 0; x < 16; x++) {
for (short z = 0; z < 16; z++) {
result.setBlock(x, 0, z, (short) 7, (byte) 0);
}
}
}
// Coords
int cx = result.getX();
int cz = result.getZ();
int bx = cx << 4;
int bz = cz << 4;
short rbx = (short) ((bx < 0) ? (hpw.SIZE + (bx % hpw.SIZE)) : bx % hpw.SIZE);
short rbz = (short) ((bz < 0) ? (hpw.SIZE + (bz % hpw.SIZE)) : bz % hpw.SIZE);
short[] rx = new short[16];
boolean[] gx = new boolean[16];
boolean[] wx = new boolean[16];
for (short i = 0; i < 16; i++) {
short v = (short) (rbx + i);
if (v >= hpw.SIZE) {
v -= hpw.SIZE;
}
rx[i] = v;
if (hpw.ROAD_WIDTH != 0) {
gx[i] = v < hpw.PATH_WIDTH_LOWER || v > hpw.PATH_WIDTH_UPPER;
wx[i] = v == hpw.PATH_WIDTH_LOWER || v == hpw.PATH_WIDTH_UPPER;
}
}
short[] rz = new short[16];
boolean[] gz = new boolean[16];
boolean[] wz = new boolean[16];
for (short i = 0; i < 16; i++) {
short v = (short) (rbz + i);
if (v >= hpw.SIZE) {
v -= hpw.SIZE;
}
rz[i] = v;
if (hpw.ROAD_WIDTH != 0) {
gz[i] = v < hpw.PATH_WIDTH_LOWER || v > hpw.PATH_WIDTH_UPPER;
wz[i] = v == hpw.PATH_WIDTH_LOWER || v == hpw.PATH_WIDTH_UPPER;
}
}
// generation
HashMap<Integer, HashMap<Integer, PlotBlock>> sch = hpw.G_SCH;
for (short x = 0; x < 16; x++) {
if (gx[x]) {
for (short z = 0; z < 16; z++) {
// Road
for (int y = 1; y <= hpw.ROAD_HEIGHT; y++) {
result.setBlock(x, y, z, hpw.ROAD_BLOCK);
}
if (hpw.ROAD_SCHEMATIC_ENABLED) {
HashMap<Integer, PlotBlock> map = sch.get(MathMan.pair(x, z));
if (map != null) {
for (Entry<Integer, PlotBlock> entry : map.entrySet()) {
result.setBlock(x, entry.getKey(), z, entry.getValue());
}
}
}
}
} else if (wx[x]) {
for (short z = 0; z < 16; z++) {
if (gz[z]) {
// road
for (int y = 1; y <= hpw.ROAD_HEIGHT; y++) {
result.setBlock(x, y, z, hpw.ROAD_BLOCK);
}
if (hpw.ROAD_SCHEMATIC_ENABLED) {
HashMap<Integer, PlotBlock> map = sch.get(MathMan.pair(x, z));
if (map != null) {
for (Entry<Integer, PlotBlock> entry : map.entrySet()) {
result.setBlock(x, entry.getKey(), z, entry.getValue());
}
}
}
} else {
// wall
for (int y = 1; y <= hpw.WALL_HEIGHT; y++) {
result.setBlock(x, y, z, hpw.WALL_FILLING);
}
if (!hpw.ROAD_SCHEMATIC_ENABLED) {
result.setBlock(x, hpw.WALL_HEIGHT + 1, z, hpw.WALL_BLOCK);
} else {
HashMap<Integer, PlotBlock> map = sch.get(MathMan.pair(x, z));
if (map != null) {
for (Entry<Integer, PlotBlock> entry : map.entrySet()) {
result.setBlock(x, entry.getKey(), z, entry.getValue());
}
}
}
}
}
} else {
for (short z = 0; z < 16; z++) {
if (gz[z]) {
// road
for (int y = 1; y <= hpw.ROAD_HEIGHT; y++) {
result.setBlock(x, y, z, hpw.ROAD_BLOCK);
}
if (hpw.ROAD_SCHEMATIC_ENABLED) {
HashMap<Integer, PlotBlock> map = sch.get(MathMan.pair(x, z));
if (map != null) {
for (Entry<Integer, PlotBlock> entry : map.entrySet()) {
result.setBlock(x, entry.getKey(), z, entry.getValue());
}
}
}
} else if (wz[z]) {
// wall
for (int y = 1; y <= hpw.WALL_HEIGHT; y++) {
result.setBlock(x, y, z, hpw.WALL_FILLING);
}
if (!hpw.ROAD_SCHEMATIC_ENABLED) {
result.setBlock(x, hpw.WALL_HEIGHT + 1, z, hpw.WALL_BLOCK);
} else {
HashMap<Integer, PlotBlock> map = sch.get(MathMan.pair(x, z));
if (map != null) {
for (Entry<Integer, PlotBlock> entry : map.entrySet()) {
result.setBlock(x, entry.getKey(), z, entry.getValue());
}
}
}
} else {
// plot
for (int y = 1; y < hpw.PLOT_HEIGHT; y++) {
result.setBlock(x, y, z, hpw.MAIN_BLOCK[random.random(hpw.MAIN_BLOCK.length)]);
}
result.setBlock(x, hpw.PLOT_HEIGHT, z, hpw.TOP_BLOCK[random.random(hpw.TOP_BLOCK.length)]);
if (hpw.PLOT_SCHEMATIC) {
HashMap<Integer, PlotBlock> map = sch.get(MathMan.pair(x, z));
if (map != null) {
for (Entry<Integer, PlotBlock> entry : map.entrySet()) {
result.setBlock(x, entry.getKey(), z, entry.getValue());
}
}
}
}
}
}
}
}
@Override
public PlotArea getNewPlotArea(String world, String id, PlotId min, PlotId max) {
return new HybridPlotWorld(world, id, this, min, max);
}
@Override
public PlotManager getNewPlotManager() {
return new HybridPlotManager();
}
@Override
public void initialize(PlotArea area) {
// All initialization is done in the PlotArea class
}
}

View File

@ -20,33 +20,34 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.generator; package com.intellectualcrafters.plot.generator;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.commands.Template;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.FileBytes;
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.PlotLoc;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.SetBlockQueue;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map.Entry;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.commands.Template;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.FileBytes;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.SetQueue;
import com.intellectualcrafters.plot.util.WorldUtil;
public class HybridPlotManager extends ClassicPlotManager { public class HybridPlotManager extends ClassicPlotManager {
@Override @Override
public void exportTemplate(final PlotWorld plotworld) throws IOException { public void exportTemplate(final PlotArea plotworld) throws IOException {
final HashSet<FileBytes> files = new HashSet<>( final HashSet<FileBytes> files = new HashSet<>(
Collections.singletonList(new FileBytes("templates/" + "tmp-data.yml", Template.getBytes(plotworld)))); Collections.singletonList(new FileBytes("templates/" + "tmp-data.yml", Template.getBytes(plotworld))));
final String psRoot = PS.get().IMP.getDirectory() + File.separator; final String psRoot = PS.get().IMP.getDirectory() + File.separator;
@ -72,7 +73,7 @@ public class HybridPlotManager extends ClassicPlotManager {
} }
@Override @Override
public boolean createRoadEast(final PlotWorld plotworld, final Plot plot) { public boolean createRoadEast(final PlotArea plotworld, final Plot plot) {
super.createRoadEast(plotworld, plot); super.createRoadEast(plotworld, plot);
final HybridPlotWorld hpw = (HybridPlotWorld) plotworld; final HybridPlotWorld hpw = (HybridPlotWorld) plotworld;
if (!hpw.ROAD_SCHEMATIC_ENABLED) { if (!hpw.ROAD_SCHEMATIC_ENABLED) {
@ -82,8 +83,8 @@ public class HybridPlotManager extends ClassicPlotManager {
final PlotId id2 = new PlotId(id.x + 1, id.y); final PlotId id2 = new PlotId(id.x + 1, id.y);
final Location bot = getPlotBottomLocAbs(hpw, id2); final Location bot = getPlotBottomLocAbs(hpw, id2);
final Location top = getPlotTopLocAbs(hpw, id); final Location top = getPlotTopLocAbs(hpw, id);
final Location pos1 = new Location(plot.world, top.getX() + 1, 0, bot.getZ() - 1); final Location pos1 = new Location(plotworld.worldname, top.getX() + 1, 0, bot.getZ() - 1);
final Location pos2 = new Location(plot.world, bot.getX(), 255, top.getZ() + 1); final Location pos2 = new Location(plotworld.worldname, bot.getX(), 255, top.getZ() + 1);
createSchemAbs(hpw, pos1, pos2, hpw.ROAD_HEIGHT, true); createSchemAbs(hpw, pos1, pos2, hpw.ROAD_HEIGHT, true);
return true; return true;
} }
@ -100,27 +101,15 @@ public class HybridPlotManager extends ClassicPlotManager {
if (absZ < 0) { if (absZ < 0) {
absZ += size; absZ += size;
} }
final PlotLoc loc = new PlotLoc(absX, absZ); final HashMap<Integer, PlotBlock> blocks = hpw.G_SCH.get(MathMan.pair(absX, absZ));
final HashMap<Short, Short> blocks = hpw.G_SCH.get(loc);
if (clear) { if (clear) {
for (short y = (short) (height); y <= (height + hpw.SCHEMATIC_HEIGHT); y++) { for (short y = (short) (height); y <= (height + hpw.SCHEMATIC_HEIGHT); y++) {
SetBlockQueue.setBlock(hpw.worldname, x, y + y, z, 0); SetQueue.IMP.setBlock(hpw.worldname, x, y + y, z, 0);
} }
} }
if (blocks != null) { if (blocks != null) {
final HashMap<Short, Byte> datas = hpw.G_SCH_DATA.get(loc); for (Entry<Integer, PlotBlock> entry : blocks.entrySet()) {
if (datas == null) { SetQueue.IMP.setBlock(hpw.worldname, x, height + entry.getKey(), z, entry.getValue());
for (final Short y : blocks.keySet()) {
SetBlockQueue.setBlock(hpw.worldname, x, height + y, z, blocks.get(y));
}
} else {
for (final Short y : blocks.keySet()) {
Byte data = datas.get(y);
if (data == null) {
data = 0;
}
SetBlockQueue.setBlock(hpw.worldname, x, height + y, z, new PlotBlock(blocks.get(y), data));
}
} }
} }
} }
@ -128,7 +117,7 @@ public class HybridPlotManager extends ClassicPlotManager {
} }
@Override @Override
public boolean createRoadSouth(final PlotWorld plotworld, final Plot plot) { public boolean createRoadSouth(final PlotArea plotworld, final Plot plot) {
super.createRoadSouth(plotworld, plot); super.createRoadSouth(plotworld, plot);
final HybridPlotWorld hpw = (HybridPlotWorld) plotworld; final HybridPlotWorld hpw = (HybridPlotWorld) plotworld;
if (!hpw.ROAD_SCHEMATIC_ENABLED) { if (!hpw.ROAD_SCHEMATIC_ENABLED) {
@ -138,14 +127,14 @@ public class HybridPlotManager extends ClassicPlotManager {
final PlotId id2 = new PlotId(id.x, id.y + 1); final PlotId id2 = new PlotId(id.x, id.y + 1);
final Location bot = getPlotBottomLocAbs(hpw, id2); final Location bot = getPlotBottomLocAbs(hpw, id2);
final Location top = getPlotTopLocAbs(hpw, id); final Location top = getPlotTopLocAbs(hpw, id);
final Location pos1 = new Location(plot.world, bot.getX() - 1, 0, top.getZ() + 1); final Location pos1 = new Location(plotworld.worldname, bot.getX() - 1, 0, top.getZ() + 1);
final Location pos2 = new Location(plot.world, top.getX() + 1, 255, bot.getZ()); final Location pos2 = new Location(plotworld.worldname, top.getX() + 1, 255, bot.getZ());
createSchemAbs(hpw, pos1, pos2, hpw.ROAD_HEIGHT, true); createSchemAbs(hpw, pos1, pos2, hpw.ROAD_HEIGHT, true);
return true; return true;
} }
@Override @Override
public boolean createRoadSouthEast(final PlotWorld plotworld, final Plot plot) { public boolean createRoadSouthEast(final PlotArea plotworld, final Plot plot) {
super.createRoadSouthEast(plotworld, plot); super.createRoadSouthEast(plotworld, plot);
final HybridPlotWorld hpw = (HybridPlotWorld) plotworld; final HybridPlotWorld hpw = (HybridPlotWorld) plotworld;
if (!hpw.ROAD_SCHEMATIC_ENABLED) { if (!hpw.ROAD_SCHEMATIC_ENABLED) {
@ -168,39 +157,36 @@ public class HybridPlotManager extends ClassicPlotManager {
* to have 512x512 sized plots * to have 512x512 sized plots
*/ */
@Override @Override
public boolean clearPlot(final PlotWorld plotworld, final Plot plot, final Runnable whenDone) { public boolean clearPlot(final PlotArea plotworld, final Plot plot, final Runnable whenDone) {
final String world = plotworld.worldname; final String world = plotworld.worldname;
final HybridPlotWorld dpw = ((HybridPlotWorld) plotworld); final HybridPlotWorld dpw = ((HybridPlotWorld) plotworld);
final Location pos1 = plot.getBottomAbs();
final Location pos1 = MainUtil.getPlotBottomLocAbs(world, plot.getId()); final Location pos2 = plot.getExtendedTopAbs();
final Location pos2 = MainUtil.getPlotTopLoc_(plot);
// If augmented // If augmented
final boolean canRegen = (plotworld.TYPE == 0) && (plotworld.TERRAIN == 0); final boolean canRegen = (plotworld.TYPE == 0) && (plotworld.TERRAIN == 0);
// The component blocks // The component blocks
final PlotBlock[] plotfloor = dpw.TOP_BLOCK; final PlotBlock[] plotfloor = dpw.TOP_BLOCK;
final PlotBlock[] filling = dpw.MAIN_BLOCK; final PlotBlock[] filling = dpw.MAIN_BLOCK;
final PlotBlock[] bedrock = (dpw.PLOT_BEDROCK ? new PlotBlock[] { new PlotBlock((short) 7, (byte) 0) } : filling); final PlotBlock bedrock = (dpw.PLOT_BEDROCK ? new PlotBlock((short) 7, (byte) 0) : new PlotBlock((short) 0, (byte) 0));
final PlotBlock air = new PlotBlock((short) 0, (byte) 0); final PlotBlock air = new PlotBlock((short) 0, (byte) 0);
final String biome = WorldUtil.IMP.getBiomeList()[dpw.PLOT_BIOME];
ChunkManager.chunkTask(pos1, pos2, new RunnableVal<int[]>() { ChunkManager.chunkTask(pos1, pos2, new RunnableVal<int[]>() {
@Override @Override
public void run() { public void run(int[] value) {
// If the chunk isn't near the edge and it isn't an augmented world we can just regen the whole chunk // If the chunk isn't near the edge and it isn't an augmented world we can just regen the whole chunk
if (canRegen && (value[6] == 0)) { if (canRegen && (value[6] == 0)) {
ChunkManager.CURRENT_PLOT_CLEAR = new RegionWrapper(value[2], value[4], value[3], value[5]);
ChunkManager.manager.regenerateChunk(world, new ChunkLoc(value[0], value[1])); ChunkManager.manager.regenerateChunk(world, new ChunkLoc(value[0], value[1]));
ChunkManager.CURRENT_PLOT_CLEAR = null;
return; return;
} }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Otherwise we need to set each component, as we don't want to regenerate the road or other plots that share the same chunk // // Otherwise we need to set each component, as we don't want to regenerate the road or other plots that share the same chunk //
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Set the biome // Set the biome
MainUtil.setBiome(world, value[2], value[3], value[4], value[5], dpw.PLOT_BIOME); MainUtil.setBiome(world, value[2], value[3], value[4], value[5], biome);
// These two locations are for each component (e.g. bedrock, main block, floor, air) // These two locations are for each component (e.g. bedrock, main block, floor, air)
final Location bot = new Location(world, value[2], 0, value[3]); final Location bot = new Location(world, value[2], 0, value[3]);
final Location top = new Location(world, value[4], 1, value[5]); final Location top = new Location(world, value[4], 1, value[5]);
MainUtil.setCuboidAsync(world, bot, top, bedrock); MainUtil.setSimpleCuboidAsync(world, bot, top, bedrock);
// Each component has a different layer // Each component has a different layer
bot.setY(1); bot.setY(1);
top.setY(dpw.PLOT_HEIGHT); top.setY(dpw.PLOT_HEIGHT);
@ -218,9 +204,9 @@ public class HybridPlotManager extends ClassicPlotManager {
@Override @Override
public void run() { public void run() {
// And notify whatever called this when plot clearing is done // And notify whatever called this when plot clearing is done
SetBlockQueue.addNotify(whenDone); SetQueue.IMP.addTask(whenDone);
} }
}, 5); }, 10);
return true; return true;
} }

View File

@ -26,15 +26,20 @@ import java.util.HashSet;
import com.intellectualcrafters.configuration.ConfigurationSection; import com.intellectualcrafters.configuration.ConfigurationSection;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotLoc; import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.schematic.PlotItem; import com.intellectualcrafters.plot.object.schematic.PlotItem;
import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.SchematicHandler; import com.intellectualcrafters.plot.util.SchematicHandler;
import com.intellectualcrafters.plot.util.SchematicHandler.Dimension; import com.intellectualcrafters.plot.util.SchematicHandler.Dimension;
import com.intellectualcrafters.plot.util.SchematicHandler.Schematic; import com.intellectualcrafters.plot.util.SchematicHandler.Schematic;
public class HybridPlotWorld extends ClassicPlotWorld { public class HybridPlotWorld extends ClassicPlotWorld {
public HybridPlotWorld(String worldname, String id, IndependentPlotGenerator generator, PlotId min, PlotId max) {
super(worldname, id, generator, min, max);
}
public boolean ROAD_SCHEMATIC_ENABLED; public boolean ROAD_SCHEMATIC_ENABLED;
public short SCHEMATIC_HEIGHT; public short SCHEMATIC_HEIGHT;
public boolean PLOT_SCHEMATIC = false; public boolean PLOT_SCHEMATIC = false;
@ -42,16 +47,8 @@ public class HybridPlotWorld extends ClassicPlotWorld {
public short PATH_WIDTH_LOWER; public short PATH_WIDTH_LOWER;
public short PATH_WIDTH_UPPER; public short PATH_WIDTH_UPPER;
/* public HashMap<Integer, HashMap<Integer, PlotBlock>> G_SCH;
* Here we are just calling the super method, nothing special public HashMap<Integer, HashSet<PlotItem>> G_SCH_STATE;
*/
public HybridPlotWorld(final String worldname) {
super(worldname);
}
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 * This method is called when a world loads. Make sure you set all your constants here. You are provided with the
@ -74,7 +71,7 @@ public class HybridPlotWorld extends ClassicPlotWorld {
} }
@Override @Override
public boolean isCompatible(PlotWorld plotworld) { public boolean isCompatible(PlotArea plotworld) {
if (plotworld == null || !(plotworld instanceof SquarePlotWorld)) { if (plotworld == null || !(plotworld instanceof SquarePlotWorld)) {
return false; return false;
} }
@ -82,7 +79,6 @@ public class HybridPlotWorld extends ClassicPlotWorld {
} }
public void setupSchematics() { public void setupSchematics() {
G_SCH_DATA = new HashMap<>();
G_SCH = new HashMap<>(); G_SCH = new HashMap<>();
final String schem1Str = "GEN_ROAD_SCHEMATIC/" + worldname + "/sideroad"; final String schem1Str = "GEN_ROAD_SCHEMATIC/" + worldname + "/sideroad";
final String schem2Str = "GEN_ROAD_SCHEMATIC/" + worldname + "/intersection"; final String schem2Str = "GEN_ROAD_SCHEMATIC/" + worldname + "/intersection";
@ -130,13 +126,13 @@ public class HybridPlotWorld extends ClassicPlotWorld {
item.x += shift + oddshift + center_shift_x; item.x += shift + oddshift + center_shift_x;
item.z += shift + oddshift + center_shift_z; item.z += shift + oddshift + center_shift_z;
item.y += PLOT_HEIGHT; item.y += PLOT_HEIGHT;
final int x = item.x; final short x = (short) item.x;
final int z = item.z; final short z = (short) item.z;
final PlotLoc loc = new PlotLoc(x, z); int pair = MathMan.pair(x, z);
if (!G_SCH_STATE.containsKey(loc)) { HashSet<PlotItem> v = G_SCH_STATE.putIfAbsent(pair, new HashSet<PlotItem>());
G_SCH_STATE.put(loc, new HashSet<PlotItem>()); if (v != null) {
v.add(item);
} }
G_SCH_STATE.get(loc).add(item);
} }
} }
} }
@ -314,11 +310,6 @@ public class HybridPlotWorld extends ClassicPlotWorld {
if (x < 0) { if (x < 0) {
x += SIZE; x += SIZE;
} }
final PlotLoc loc = new PlotLoc(x, z);
if (!G_SCH.containsKey(loc)) {
G_SCH.put(loc, new HashMap<Short, Short>());
}
G_SCH.get(loc).put(y, id);
if (rotate) { if (rotate) {
final byte newdata = rotate(id, data); final byte newdata = rotate(id, data);
if ((data == 0) && (newdata == 0)) { if ((data == 0) && (newdata == 0)) {
@ -326,9 +317,10 @@ public class HybridPlotWorld extends ClassicPlotWorld {
} }
data = newdata; data = newdata;
} }
if (!G_SCH_DATA.containsKey(loc)) { int pair = MathMan.pair(x, y);
G_SCH_DATA.put(loc, new HashMap<Short, Byte>()); HashMap<Integer, PlotBlock> v = G_SCH.putIfAbsent(pair, new HashMap<Integer, PlotBlock>());
if (v != null) {
v.put((int) y, new PlotBlock(id, data));
} }
G_SCH_DATA.get(loc).put(y, data);
} }
} }

View File

@ -1,5 +1,17 @@
package com.intellectualcrafters.plot.generator; package com.intellectualcrafters.plot.generator;
import java.io.File;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import com.intellectualcrafters.jnbt.CompoundTag; import com.intellectualcrafters.jnbt.CompoundTag;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
@ -9,30 +21,18 @@ import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotAnalysis; import com.intellectualcrafters.plot.object.PlotAnalysis;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotLoc;
import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.SchematicHandler; import com.intellectualcrafters.plot.util.SchematicHandler;
import com.intellectualcrafters.plot.util.SetBlockQueue; import com.intellectualcrafters.plot.util.SetQueue;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import java.io.File;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
public abstract class HybridUtils { public abstract class HybridUtils {
public static HybridUtils manager; public static HybridUtils manager;
@ -40,7 +40,7 @@ public abstract class HybridUtils {
public abstract void analyzeRegion(final String world, final RegionWrapper region, final RunnableVal<PlotAnalysis> whenDone); public abstract void analyzeRegion(final String world, final RegionWrapper region, final RunnableVal<PlotAnalysis> whenDone);
public void analyzePlot(final Plot origin, final RunnableVal<PlotAnalysis> whenDone) { public void analyzePlot(final Plot origin, final RunnableVal<PlotAnalysis> whenDone) {
final ArrayDeque<RegionWrapper> zones = new ArrayDeque<>(MainUtil.getRegions(origin)); final ArrayDeque<RegionWrapper> zones = new ArrayDeque<>(origin.getRegions());
final ArrayList<PlotAnalysis> analysis = new ArrayList<>(); final ArrayList<PlotAnalysis> analysis = new ArrayList<>();
Runnable run = new Runnable() { Runnable run = new Runnable() {
@Override @Override
@ -93,9 +93,9 @@ public abstract class HybridUtils {
} }
RegionWrapper region = zones.poll(); RegionWrapper region = zones.poll();
final Runnable task = this; final Runnable task = this;
analyzeRegion(origin.world, region, new RunnableVal<PlotAnalysis>() { analyzeRegion(origin.area.worldname, region, new RunnableVal<PlotAnalysis>() {
@Override @Override
public void run() { public void run(PlotAnalysis value) {
analysis.add(value); analysis.add(value);
TaskManager.runTaskLater(task, 1); TaskManager.runTaskLater(task, 1);
} }
@ -109,7 +109,7 @@ public abstract class HybridUtils {
public static Set<ChunkLoc> regions; public static Set<ChunkLoc> regions;
public static Set<ChunkLoc> chunks = new HashSet<>(); public static Set<ChunkLoc> chunks = new HashSet<>();
public static String world; public static PlotArea area;
public static boolean UPDATE = false; public static boolean UPDATE = false;
public final ArrayList<ChunkLoc> getChunks(final ChunkLoc region) { public final ArrayList<ChunkLoc> getChunks(final ChunkLoc region) {
@ -133,7 +133,7 @@ public abstract class HybridUtils {
if (whenDone == null) { if (whenDone == null) {
return; return;
} }
final PlotWorld plotworld = plot.getWorld(); final PlotArea plotworld = plot.getArea();
if (!(plotworld instanceof ClassicPlotWorld)) { if (!(plotworld instanceof ClassicPlotWorld)) {
whenDone.value = -1; whenDone.value = -1;
TaskManager.runTask(whenDone); TaskManager.runTask(whenDone);
@ -141,7 +141,7 @@ public abstract class HybridUtils {
} }
whenDone.value = 0; whenDone.value = 0;
final ClassicPlotWorld cpw = (ClassicPlotWorld) plotworld; final ClassicPlotWorld cpw = (ClassicPlotWorld) plotworld;
final ArrayDeque<RegionWrapper> zones = new ArrayDeque<>(MainUtil.getRegions(plot)); final ArrayDeque<RegionWrapper> zones = new ArrayDeque<>(plot.getRegions());
Runnable run = new Runnable() { Runnable run = new Runnable() {
@Override @Override
public void run() { public void run() {
@ -151,20 +151,20 @@ public abstract class HybridUtils {
return; return;
} }
RegionWrapper region = zones.poll(); RegionWrapper region = zones.poll();
Location pos1 = new Location(plot.world, region.minX, region.minY, region.minZ); Location pos1 = new Location(plot.area.worldname, region.minX, region.minY, region.minZ);
Location pos2 = new Location(plot.world, region.maxX, region.maxY, region.maxZ); Location pos2 = new Location(plot.area.worldname, region.maxX, region.maxY, region.maxZ);
ChunkManager.chunkTask(pos1, pos2, new RunnableVal<int[]>() { ChunkManager.chunkTask(pos1, pos2, new RunnableVal<int[]>() {
@Override @Override
public void run() { public void run(int[] value) {
final ChunkLoc loc = new ChunkLoc(value[0], value[1]); final ChunkLoc loc = new ChunkLoc(value[0], value[1]);
ChunkManager.manager.loadChunk(plot.world, loc, false); ChunkManager.manager.loadChunk(plot.area.worldname, loc, false);
final int bx = value[2]; final int bx = value[2];
final int bz = value[3]; final int bz = value[3];
final int ex = value[4]; final int ex = value[4];
final int ez = value[5]; final int ez = value[5];
whenDone.value += checkModified(plot.world, bx, ex, 1, cpw.PLOT_HEIGHT - 1, bz, ez, cpw.MAIN_BLOCK); whenDone.value += checkModified(plot.area.worldname, bx, ex, 1, cpw.PLOT_HEIGHT - 1, bz, ez, cpw.MAIN_BLOCK);
whenDone.value += checkModified(plot.world, bx, ex, cpw.PLOT_HEIGHT, cpw.PLOT_HEIGHT, bz, ez, cpw.TOP_BLOCK); whenDone.value += checkModified(plot.area.worldname, bx, ex, cpw.PLOT_HEIGHT, cpw.PLOT_HEIGHT, bz, ez, cpw.TOP_BLOCK);
whenDone.value += checkModified(plot.world, bx, ex, cpw.PLOT_HEIGHT + 1, 255, bz, ez, new PlotBlock[] { new PlotBlock((short) 0, (byte) 0) }); whenDone.value += checkModified(plot.area.worldname, bx, ex, cpw.PLOT_HEIGHT + 1, 255, bz, ez, new PlotBlock[] { new PlotBlock((short) 0, (byte) 0) });
} }
}, this, 5); }, this, 5);
@ -173,18 +173,18 @@ public abstract class HybridUtils {
run.run(); run.run();
} }
public boolean scheduleRoadUpdate(final String world, final int extend) { public boolean scheduleRoadUpdate(final PlotArea area, final int extend) {
if (HybridUtils.UPDATE) { if (HybridUtils.UPDATE) {
return false; return false;
} }
HybridUtils.UPDATE = true; HybridUtils.UPDATE = true;
final Set<ChunkLoc> regions = ChunkManager.manager.getChunkChunks(world); final Set<ChunkLoc> regions = ChunkManager.manager.getChunkChunks(area.worldname);
return scheduleRoadUpdate(world, regions, extend); return scheduleRoadUpdate(area, regions, extend);
} }
public boolean scheduleRoadUpdate(final String world, final Set<ChunkLoc> rgs, final int extend) { public boolean scheduleRoadUpdate(final PlotArea area, final Set<ChunkLoc> rgs, final int extend) {
HybridUtils.regions = rgs; HybridUtils.regions = rgs;
HybridUtils.world = world; HybridUtils.area = area;
chunks = new HashSet<>(); chunks = new HashSet<>();
final AtomicInteger count = new AtomicInteger(0); final AtomicInteger count = new AtomicInteger(0);
final long baseTime = System.currentTimeMillis(); final long baseTime = System.currentTimeMillis();
@ -198,8 +198,8 @@ public abstract class HybridUtils {
while (iter.hasNext()) { while (iter.hasNext()) {
final ChunkLoc chunk = iter.next(); final ChunkLoc chunk = iter.next();
iter.remove(); iter.remove();
regenerateRoad(world, chunk, extend); regenerateRoad(area, chunk, extend);
ChunkManager.manager.unloadChunk(world, chunk, true, true); ChunkManager.manager.unloadChunk(area.worldname, chunk, true, true);
} }
PS.debug("&cCancelled road task"); PS.debug("&cCancelled road task");
return; return;
@ -243,7 +243,7 @@ public abstract class HybridUtils {
TaskManager.runTask(new Runnable() { TaskManager.runTask(new Runnable() {
@Override @Override
public void run() { public void run() {
regenerateRoad(world, chunk, extend); regenerateRoad(area, chunk, extend);
} }
}); });
// DELAY TASK // DELAY TASK
@ -258,7 +258,7 @@ public abstract class HybridUtils {
TaskManager.runTask(new Runnable() { TaskManager.runTask(new Runnable() {
@Override @Override
public void run() { public void run() {
regenerateRoad(world, chunk, extend); regenerateRoad(area, chunk, extend);
} }
}); });
} }
@ -270,18 +270,18 @@ public abstract class HybridUtils {
Iterator<ChunkLoc> iter = regions.iterator(); Iterator<ChunkLoc> iter = regions.iterator();
final ChunkLoc loc = iter.next(); final ChunkLoc loc = iter.next();
iter.remove(); iter.remove();
PS.debug("&c[ERROR]&7 Could not update '" + world + "/region/r." + loc.x + "." + loc.z + ".mca' (Corrupt chunk?)"); PS.debug("&c[ERROR]&7 Could not update '" + area.worldname + "/region/r." + loc.x + "." + loc.z + ".mca' (Corrupt chunk?)");
final int sx = loc.x << 5; final int sx = loc.x << 5;
final int sz = loc.z << 5; final int sz = loc.z << 5;
for (int x = sx; x < (sx + 32); x++) { for (int x = sx; x < (sx + 32); x++) {
for (int z = sz; z < (sz + 32); z++) { for (int z = sz; z < (sz + 32); z++) {
ChunkManager.manager.unloadChunk(world, new ChunkLoc(x, z), true, true); ChunkManager.manager.unloadChunk(area.worldname, new ChunkLoc(x, z), true, true);
} }
} }
PS.debug("&d - Potentially skipping 1024 chunks"); PS.debug("&d - Potentially skipping 1024 chunks");
PS.debug("&d - TODO: recommend chunkster if corrupt"); PS.debug("&d - TODO: recommend chunkster if corrupt");
} }
SetBlockQueue.addNotify(new Runnable() { SetQueue.IMP.addTask(new Runnable() {
@Override @Override
public void run() { public void run() {
TaskManager.runTaskLater(task, 20); TaskManager.runTaskLater(task, 20);
@ -296,10 +296,10 @@ public abstract class HybridUtils {
} }
public boolean setupRoadSchematic(final Plot plot) { public boolean setupRoadSchematic(final Plot plot) {
final String world = plot.world; final String world = plot.area.worldname;
final Location bot = MainUtil.getPlotBottomLocAbs(world, plot.getId()).subtract(1, 0, 1); final Location bot = plot.getBottomAbs().subtract(1, 0, 1);
final Location top = MainUtil.getPlotTopLocAbs(world, plot.getId()); final Location top = plot.getTopAbs();
final HybridPlotWorld plotworld = (HybridPlotWorld) PS.get().getPlotWorld(world); final HybridPlotWorld plotworld = (HybridPlotWorld) plot.area;
final int sx = (bot.getX() - plotworld.ROAD_WIDTH) + 1; final int sx = (bot.getX() - plotworld.ROAD_WIDTH) + 1;
final int sz = bot.getZ() + 1; final int sz = bot.getZ() + 1;
final int sy = plotworld.ROAD_HEIGHT; final int sy = plotworld.ROAD_HEIGHT;
@ -313,14 +313,14 @@ public abstract class HybridUtils {
final Set<RegionWrapper> sideroad = new HashSet<>(Collections.singletonList(new RegionWrapper(sx, ex, sy, ey, sz, ez))); final Set<RegionWrapper> sideroad = new HashSet<>(Collections.singletonList(new RegionWrapper(sx, ex, sy, ey, sz, ez)));
final Set<RegionWrapper> intersection = new HashSet<>(Collections.singletonList(new RegionWrapper(sx, ex, sy, ty, bz, tz))); final Set<RegionWrapper> intersection = new HashSet<>(Collections.singletonList(new RegionWrapper(sx, ex, sy, ty, bz, tz)));
final String dir = PS.get().IMP.getDirectory() + File.separator + "schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator + plot.world + File.separator; final String dir = PS.get().IMP.getDirectory() + File.separator + "schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator + plot.area.toString() + File.separator;
SchematicHandler.manager.getCompoundTag(world, sideroad, new RunnableVal<CompoundTag>() { SchematicHandler.manager.getCompoundTag(world, sideroad, new RunnableVal<CompoundTag>() {
@Override @Override
public void run() { public void run(CompoundTag value) {
SchematicHandler.manager.save(value, dir + "sideroad.schematic"); SchematicHandler.manager.save(value, dir + "sideroad.schematic");
SchematicHandler.manager.getCompoundTag(world, intersection, new RunnableVal<CompoundTag>() { SchematicHandler.manager.getCompoundTag(world, intersection, new RunnableVal<CompoundTag>() {
@Override @Override
public void run() { public void run(CompoundTag value) {
SchematicHandler.manager.save(value, dir + "intersection.schematic"); SchematicHandler.manager.save(value, dir + "intersection.schematic");
plotworld.ROAD_SCHEMATIC_ENABLED = true; plotworld.ROAD_SCHEMATIC_ENABLED = true;
plotworld.setupSchematics(); plotworld.setupSchematics();
@ -333,42 +333,42 @@ public abstract class HybridUtils {
public abstract int get_ey(final String world, final int sx, final int ex, final int sz, final int ez, final int sy); public abstract int get_ey(final String world, final int sx, final int ex, final int sz, final int ez, final int sy);
public boolean regenerateRoad(final String world, final ChunkLoc chunk, int extend) { public boolean regenerateRoad(final PlotArea area, final ChunkLoc chunk, int extend) {
int x = chunk.x << 4; int x = chunk.x << 4;
int z = chunk.z << 4; int z = chunk.z << 4;
final int ex = x + 15; final int ex = x + 15;
final int ez = z + 15; final int ez = z + 15;
final HybridPlotWorld plotworld = (HybridPlotWorld) PS.get().getPlotWorld(world); final HybridPlotWorld plotworld = (HybridPlotWorld) area;
extend = Math.min(extend, 255 - plotworld.ROAD_HEIGHT - plotworld.SCHEMATIC_HEIGHT); extend = Math.min(extend, 255 - plotworld.ROAD_HEIGHT - plotworld.SCHEMATIC_HEIGHT);
if (!plotworld.ROAD_SCHEMATIC_ENABLED) { if (!plotworld.ROAD_SCHEMATIC_ENABLED) {
return false; return false;
} }
boolean toCheck = false; boolean toCheck = false;
if (plotworld.TYPE == 2) { if (plotworld.TYPE == 2) {
final boolean c1 = MainUtil.isPlotArea(new Location(plotworld.worldname, x, 1, z)); final boolean c1 = area.contains(x, z);
final boolean c2 = MainUtil.isPlotArea(new Location(plotworld.worldname, ex, 1, ez)); final boolean c2 = area.contains(ex, ez);
if (!c1 && !c2) { if (!c1 && !c2) {
return false; return false;
} else { } else {
toCheck = c1 ^ c2; toCheck = c1 ^ c2;
} }
} }
final PlotManager manager = PS.get().getPlotManager(world); final PlotManager manager = area.getPlotManager();
final PlotId id1 = manager.getPlotId(plotworld, x, 0, z); final PlotId id1 = manager.getPlotId(plotworld, x, 0, z);
final PlotId id2 = manager.getPlotId(plotworld, ex, 0, ez); final PlotId id2 = manager.getPlotId(plotworld, ex, 0, ez);
x -= plotworld.ROAD_OFFSET_X; x -= plotworld.ROAD_OFFSET_X;
z -= plotworld.ROAD_OFFSET_Z; z -= plotworld.ROAD_OFFSET_Z;
if ((id1 == null) || (id2 == null) || (id1 != id2)) { if ((id1 == null) || (id2 == null) || (id1 != id2)) {
final boolean result = ChunkManager.manager.loadChunk(world, chunk, false); final boolean result = ChunkManager.manager.loadChunk(area.worldname, chunk, false);
if (result) { if (result) {
if (id1 != null) { if (id1 != null) {
final Plot p1 = MainUtil.getPlotAbs(world, id1); final Plot p1 = area.getPlotAbs(id1);
if ((p1 != null) && p1.hasOwner() && p1.isMerged()) { if ((p1 != null) && p1.hasOwner() && p1.isMerged()) {
toCheck = true; toCheck = true;
} }
} }
if ((id2 != null) && !toCheck) { if ((id2 != null) && !toCheck) {
final Plot p2 = MainUtil.getPlotAbs(world, id2); final Plot p2 = area.getPlotAbs(id2);
if ((p2 != null) && p2.hasOwner() && p2.isMerged()) { if ((p2 != null) && p2.hasOwner() && p2.isMerged()) {
toCheck = true; toCheck = true;
} }
@ -397,34 +397,22 @@ public abstract class HybridUtils {
} }
if (condition) { if (condition) {
final int sy = plotworld.ROAD_HEIGHT; final int sy = plotworld.ROAD_HEIGHT;
final PlotLoc loc = new PlotLoc(absX, absZ); final HashMap<Integer, PlotBlock> blocks = plotworld.G_SCH.get(MathMan.pair(absX, absZ));
final HashMap<Short, Short> blocks = plotworld.G_SCH.get(loc);
for (short y = (short) (plotworld.ROAD_HEIGHT); y <= (plotworld.ROAD_HEIGHT + plotworld.SCHEMATIC_HEIGHT + extend); y++) { for (short y = (short) (plotworld.ROAD_HEIGHT); y <= (plotworld.ROAD_HEIGHT + plotworld.SCHEMATIC_HEIGHT + extend); y++) {
SetBlockQueue.setBlock(world, x + X + plotworld.ROAD_OFFSET_X, y, z + Z + plotworld.ROAD_OFFSET_Z, 0); SetQueue.IMP.setBlock(area.worldname, x + X + plotworld.ROAD_OFFSET_X, y, z + Z + plotworld.ROAD_OFFSET_Z, 0);
} }
if (blocks != null) { if (blocks != null) {
final HashMap<Short, Byte> datas = plotworld.G_SCH_DATA.get(loc); for (Entry<Integer, PlotBlock> entry : blocks.entrySet()) {
if (datas == null) { SetQueue.IMP.setBlock(area.worldname, x + X + plotworld.ROAD_OFFSET_X, sy + entry.getKey(), z + Z + plotworld.ROAD_OFFSET_Z, entry.getValue());
for (final Short y : blocks.keySet()) {
SetBlockQueue.setBlock(world, x + X + plotworld.ROAD_OFFSET_X, sy + y, z + Z + plotworld.ROAD_OFFSET_Z, blocks.get(y));
}
} else {
for (final Short y : blocks.keySet()) {
Byte data = datas.get(y);
if (data == null) {
data = 0;
}
SetBlockQueue.setBlock(world, x + X + plotworld.ROAD_OFFSET_X, sy + y, z + Z + plotworld.ROAD_OFFSET_Z, new PlotBlock(blocks.get(y), data));
}
} }
} }
} }
} }
} }
SetBlockQueue.addNotify(new Runnable() { SetQueue.IMP.addTask(new Runnable() {
@Override @Override
public void run() { public void run() {
ChunkManager.manager.unloadChunk(world, chunk, true, true); ChunkManager.manager.unloadChunk(area.worldname, chunk, true, true);
} }
}); });
return true; return true;

View File

@ -0,0 +1,72 @@
package com.intellectualcrafters.plot.generator;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PseudoRandom;
import com.intellectualcrafters.plot.object.SetupObject;
import com.intellectualcrafters.plot.util.PlotChunk;
public abstract class IndependentPlotGenerator {
/**
* Get the name of this generator
*/
public abstract String getName();
/**
* Use the setBlock or setBiome method of the PlotChunk result parameter to make changes.<br>
* The PlotArea settings is the same one this was initialized with<br>
* The PseudoRandom random is a fast random object<br>
* @param result
* @param settings
* @param random
*/
public abstract void generateChunk(PlotChunk<?> result, PlotArea settings, PseudoRandom random);
/**
* Return a new PlotArea object
* @param world world name
* @param id (May be null) Area name
* @param min Min plot id (may be null)
* @param max Max plot id (may be null)
* @return
*/
public abstract PlotArea getNewPlotArea(String world, String id, PlotId min, PlotId max);
/**
* Return a new PlotManager object
* @return
*/
public abstract PlotManager getNewPlotManager();
/**
* If any additional setup options need to be changed before world creation<br>
* - e.g. If setup doesn't support some standard options
* @param setup
*/
public void processSetup(SetupObject setup) {}
/**
* It is preferred for the PlotArea object to do most of the initialization necessary.<br>
* @param area
*/
public abstract void initialize(PlotArea area);
/**
* Get the generator for your specific implementation (bukkit/sponge).<br>
* - e.g. YourIndependentGenerator.&lt;ChunkGenerator&gt;specify() - Would return a ChunkGenerator object<br>
* @param <T>
* @param <T>
* @return
*/
public <T> GeneratorWrapper<T> specify(String world) {
return (GeneratorWrapper<T>) PS.get().IMP.wrapPlotGenerator(world, this);
}
@Override
public String toString() {
return getName();
}
}

View File

@ -1,20 +1,18 @@
package com.intellectualcrafters.plot.generator; package com.intellectualcrafters.plot.generator;
import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.SetupObject; import com.intellectualcrafters.plot.object.SetupObject;
public abstract class PlotGenerator<T> { public abstract class PlotGenerator<T> {
public final String world;
public T generator; public T generator;
public PlotGenerator(final String world, final T generator) { public PlotGenerator(final T generator) {
this.world = world;
this.generator = generator; this.generator = generator;
} }
public abstract void initialize(final PlotWorld plotworld); public abstract void initialize(final PlotArea plotworld);
/** /**
* TYPE = 2; * TYPE = 2;
@ -24,21 +22,9 @@ public abstract class PlotGenerator<T> {
* @param cluster Will be the cluster, or null * @param cluster Will be the cluster, or null
* @param plotworld * @param plotworld
*/ */
public abstract void augment(final PlotCluster cluster, final PlotWorld plotworld); public abstract void augment(PlotArea area);
/** public abstract PlotArea getNewPlotArea(final String world, final String id, PlotId min, PlotId max);
*
if (gen_string == null) {
generator = new HybridGen(world);
} else {
generator = (PlotGenerator) IMP.getGenerator(world, gen_string);
}
* @param generator
*/
public abstract void setGenerator(final String generator);
public abstract PlotWorld getNewPlotWorld(final String world);
public abstract PlotManager getPlotManager(); public abstract PlotManager getPlotManager();

View File

@ -1,25 +1,25 @@
package com.intellectualcrafters.plot.generator; package com.intellectualcrafters.plot.generator;
import com.intellectualcrafters.plot.PS;
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.object.RegionWrapper;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.MainUtil;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.MainUtil;
/** /**
* A plot manager with a square grid layout, with square shaped plots * A plot manager with a square grid layout, with square shaped plots
*/ */
public abstract class SquarePlotManager extends GridPlotManager { public abstract class SquarePlotManager extends GridPlotManager {
@Override @Override
public boolean clearPlot(final PlotWorld plotworld, final Plot plot, final Runnable whenDone) { public boolean clearPlot(final PlotArea plotworld, final Plot plot, final Runnable whenDone) {
final HashSet<RegionWrapper> regions = MainUtil.getRegions(plot); final HashSet<RegionWrapper> regions = plot.getRegions();
Runnable run = new Runnable() { Runnable run = new Runnable() {
@Override @Override
public void run() { public void run() {
@ -30,9 +30,9 @@ public abstract class SquarePlotManager extends GridPlotManager {
Iterator<RegionWrapper> iter = regions.iterator(); Iterator<RegionWrapper> iter = regions.iterator();
RegionWrapper region = iter.next(); RegionWrapper region = iter.next();
iter.remove(); iter.remove();
Location pos1 = new Location(plot.world, region.minX, region.minY, region.minZ); Location pos1 = new Location(plot.area.worldname, region.minX, region.minY, region.minZ);
Location pos2 = new Location(plot.world, region.maxX, region.maxY, region.maxZ); Location pos2 = new Location(plot.area.worldname, region.maxX, region.maxY, region.maxZ);
ChunkManager.manager.regenerateRegion(pos1, pos2, this); ChunkManager.manager.regenerateRegion(pos1, pos2, false, this);
} }
}; };
run.run(); run.run();
@ -40,7 +40,7 @@ public abstract class SquarePlotManager extends GridPlotManager {
} }
@Override @Override
public Location getPlotTopLocAbs(final PlotWorld plotworld, final PlotId plotid) { public Location getPlotTopLocAbs(final PlotArea plotworld, final PlotId plotid) {
final SquarePlotWorld dpw = ((SquarePlotWorld) plotworld); final SquarePlotWorld dpw = ((SquarePlotWorld) plotworld);
final int px = plotid.x; final int px = plotid.x;
final int pz = plotid.y; final int pz = plotid.y;
@ -50,7 +50,7 @@ public abstract class SquarePlotManager extends GridPlotManager {
} }
@Override @Override
public PlotId getPlotIdAbs(final PlotWorld plotworld, int x, final int y, int z) { public PlotId getPlotIdAbs(final PlotArea plotworld, int x, final int y, int z) {
final SquarePlotWorld dpw = ((SquarePlotWorld) plotworld); final SquarePlotWorld dpw = ((SquarePlotWorld) plotworld);
if (dpw.ROAD_OFFSET_X != 0) { if (dpw.ROAD_OFFSET_X != 0) {
x -= dpw.ROAD_OFFSET_X; x -= dpw.ROAD_OFFSET_X;
@ -92,7 +92,7 @@ public abstract class SquarePlotManager extends GridPlotManager {
} }
@Override @Override
public PlotId getPlotId(final PlotWorld plotworld, int x, final int y, int z) { public PlotId getPlotId(final PlotArea plotworld, int x, final int y, int z) {
try { try {
final SquarePlotWorld dpw = ((SquarePlotWorld) plotworld); final SquarePlotWorld dpw = ((SquarePlotWorld) plotworld);
if (plotworld == null) { if (plotworld == null) {
@ -139,7 +139,7 @@ public abstract class SquarePlotManager extends GridPlotManager {
if (hash == 0) { if (hash == 0) {
return id; return id;
} }
Plot plot = PS.get().getPlot(plotworld.worldname, id); Plot plot = plotworld.getOwnedPlotAbs(id);
// Not merged, and standing on road // Not merged, and standing on road
if (plot == null) { if (plot == null) {
return null; return null;
@ -181,7 +181,7 @@ public abstract class SquarePlotManager extends GridPlotManager {
* Get the bottom plot loc (some basic math) * Get the bottom plot loc (some basic math)
*/ */
@Override @Override
public Location getPlotBottomLocAbs(final PlotWorld plotworld, final PlotId plotid) { public Location getPlotBottomLocAbs(final PlotArea plotworld, final PlotId plotid) {
final SquarePlotWorld dpw = ((SquarePlotWorld) plotworld); final SquarePlotWorld dpw = ((SquarePlotWorld) plotworld);
final int px = plotid.x; final int px = plotid.x;
final int pz = plotid.y; final int pz = plotid.y;

View File

@ -2,8 +2,14 @@ package com.intellectualcrafters.plot.generator;
import com.intellectualcrafters.configuration.ConfigurationSection; import com.intellectualcrafters.configuration.ConfigurationSection;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.object.PlotId;
public abstract class SquarePlotWorld extends GridPlotWorld { public abstract class SquarePlotWorld extends GridPlotWorld {
public SquarePlotWorld(String worldname, String id, IndependentPlotGenerator generator, PlotId min, PlotId max) {
super(worldname, id, generator, min, max);
}
public static int PLOT_WIDTH_DEFAULT = 42; public static int PLOT_WIDTH_DEFAULT = 42;
public static int ROAD_WIDTH_DEFAULT = 7; public static int ROAD_WIDTH_DEFAULT = 7;
public static int ROAD_OFFSET_X_DEFAULT = 0; public static int ROAD_OFFSET_X_DEFAULT = 0;
@ -24,8 +30,4 @@ public abstract class SquarePlotWorld extends GridPlotWorld {
ROAD_OFFSET_Z = config.getInt("road.offset.z"); ROAD_OFFSET_Z = config.getInt("road.offset.z");
SIZE = (short) (PLOT_WIDTH + ROAD_WIDTH); SIZE = (short) (PLOT_WIDTH + ROAD_WIDTH);
} }
public SquarePlotWorld(final String worldname) {
super(worldname);
}
} }

View File

@ -1,7 +1,6 @@
package com.intellectualcrafters.plot.object; package com.intellectualcrafters.plot.object;
import java.util.HashMap; import java.util.HashMap;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
@ -30,15 +29,15 @@ public class ConsolePlayer extends PlotPlayer {
*/ */
@Deprecated @Deprecated
public ConsolePlayer() { public ConsolePlayer() {
String world; PlotArea area = PS.get().getFirstPlotArea();
final Set<String> plotworlds = PS.get().getPlotWorlds(); Location loc;
if (plotworlds.size() > 0) { if (area != null) {
world = plotworlds.iterator().next(); RegionWrapper region = area.getRegion();
loc = new Location(area.worldname, region.minX + region.maxX / 2, 0, region.minZ + region.maxZ / 2);
} else { } else {
world = "world"; loc = new Location("world", 0, 0, 0);
} }
meta = new HashMap<>(); meta = new HashMap<>();
Location loc = new Location(world, 0, 0, 0);
setMeta("location", loc); setMeta("location", loc);
} }
@ -83,7 +82,7 @@ public class ConsolePlayer extends PlotPlayer {
@Override @Override
public void teleport(final Location loc) { public void teleport(final Location loc) {
final Plot plot = MainUtil.getPlot(loc); final Plot plot = loc.getPlot();
setMeta("lastplot", plot); setMeta("lastplot", plot);
setMeta("location", loc); setMeta("location", loc);
} }

View File

@ -1,11 +1,6 @@
package com.intellectualcrafters.plot.object; package com.intellectualcrafters.plot.object;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.util.MainUtil;
/** /**
* Created 2015-02-11 for PlotSquared * Created 2015-02-11 for PlotSquared
@ -16,7 +11,7 @@ public class Location implements Cloneable, Comparable<Location> {
private float yaw, pitch; private float yaw, pitch;
private String world; private String world;
private boolean built; private boolean built;
private Object o; private final Object o;
@Override @Override
public Location clone() { public Location clone() {
@ -73,16 +68,53 @@ public class Location implements Cloneable, Comparable<Location> {
return world; return world;
} }
public PlotWorld getPlotWorld() { public PlotArea getPlotArea() {
return PS.get().getPlotWorld(world); return PS.get().getPlotAreaAbs(this);
} }
public Plot getOwnedPlot() {
PlotArea area = PS.get().getPlotAreaAbs(this);
return area != null ? area.getOwnedPlot(this) : null;
}
public Plot getOwnedPlotAbs() {
PlotArea area = PS.get().getPlotAreaAbs(this);
return area != null ? area.getOwnedPlotAbs(this) : null;
}
public boolean isPlotArea() {
return PS.get().getPlotAreaAbs(this) != null;
}
public boolean isPlotRoad() {
PlotArea area = PS.get().getPlotAreaAbs(this);
if (area == null) {
return false;
}
return area.getPlotAbs(this) == null;
}
public boolean isUnownedPlotArea() {
PlotArea area = PS.get().getPlotAreaAbs(this);
if (area == null) {
return false;
}
return area.getOwnedPlotAbs(this) == null;
}
public PlotManager getPlotManager() { public PlotManager getPlotManager() {
return PS.get().getPlotManager(world); PlotArea pa = getPlotArea();
return pa != null ? pa.getPlotManager() : null;
} }
public Plot getPlotAbs() {
PlotArea area = PS.get().getPlotAreaAbs(this);
return area != null ? area.getPlotAbs(this) : null;
}
public Plot getPlot() { public Plot getPlot() {
return MainUtil.getPlot(this); PlotArea area = PS.get().getPlotAreaAbs(this);
return area != null ? area.getPlot(this) : null;
} }
public ChunkLoc getChunkLoc() { public ChunkLoc getChunkLoc() {
@ -200,37 +232,4 @@ public class Location implements Cloneable, Comparable<Location> {
public String toString() { public String toString() {
return "\"plotsquaredlocation\":{" + "\"x\":" + x + ",\"y\":" + y + ",\"z\":" + z + ",\"yaw\":" + yaw + ",\"pitch\":" + pitch + ",\"world\":\"" + world + "\"}"; return "\"plotsquaredlocation\":{" + "\"x\":" + x + ",\"y\":" + y + ",\"z\":" + z + ",\"yaw\":" + yaw + ",\"pitch\":" + pitch + ",\"world\":\"" + world + "\"}";
} }
private Object getBukkitWorld() {
try {
final Class<?> clazz = Class.forName("org.bukkit.Bukkit");
return clazz.getMethod("getWorld", String.class).invoke(null, world);
} catch (final Exception e) {
return null;
}
}
public Object toBukkitLocation() {
if (built) {
return o;
}
try {
final Constructor<?> constructor = Class.forName("org.bukkit.Location").getConstructor(Class.forName("org.bukkit.World"), double.class, double.class, double.class, float.class,
float.class);
built = true;
return (o = constructor.newInstance(Class.forName("org.bukkit.World").cast(getBukkitWorld()), x, y, z, yaw, pitch));
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | ClassNotFoundException | NoSuchMethodException e) {
return null;
}
}
/**
* Please use utility class as this is not efficient
*/
public void teleport(final Object o) throws Exception {
if (o.getClass().getName().contains("org.bukkit.entity")) {
final Method m = o.getClass().getMethod("teleport", Class.forName("org.bukkit.Location"));
m.invoke(o, toBukkitLocation());
}
}
} }

File diff suppressed because it is too large Load Diff

View File

@ -169,7 +169,7 @@ public class PlotAnalysis {
public void run() { public void run() {
analyzePlot(queuePlot, new RunnableVal<PlotAnalysis>() { analyzePlot(queuePlot, new RunnableVal<PlotAnalysis>() {
@Override @Override
public void run() { public void run(PlotAnalysis value) {
try { try {
synchronized (this) { synchronized (this) {
wait(10000); wait(10000);

View File

@ -0,0 +1,883 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// 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.object;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import com.intellectualcrafters.configuration.ConfigurationSection;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Configuration;
import com.intellectualcrafters.plot.config.ConfigurationNode;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.generator.GridPlotWorld;
import com.intellectualcrafters.plot.generator.IndependentPlotGenerator;
import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.PlotGamemode;
import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.WorldUtil;
import com.intellectualcrafters.plot.util.area.QuadMap;
/**
* @author Jesse Boyd
*/
public abstract class PlotArea {
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;
public final static boolean SCHEMATIC_CLAIM_SPECIFY_DEFAULT = false;
public final static boolean SCHEMATIC_ON_CLAIM_DEFAULT = false;
public final static String SCHEMATIC_FILE_DEFAULT = "null";
public final static List<String> SCHEMATICS_DEFAULT = null;
public final static boolean USE_ECONOMY_DEFAULT = false;
public final static double PLOT_PRICE_DEFAULT = 100;
public final static double MERGE_PRICE_DEFAULT = 100;
public final static double SELL_PRICE_DEFAULT = 75;
public final static boolean SPAWN_EGGS_DEFAULT = false;
public final static boolean SPAWN_CUSTOM_DEFAULT = true;
public final static boolean SPAWN_BREEDING_DEFAULT = false;
public final static boolean WORLD_BORDER_DEFAULT = false;
public final static int MAX_PLOT_MEMBERS_DEFAULT = 128;
public final static int MAX_BUILD_HEIGHT_DEFAULT = 256;
public final static int MIN_BUILD_HEIGHT_DEFAULT = 1;
public final static PlotGamemode GAMEMODE_DEFAULT = PlotGamemode.CREATIVE;
public int MAX_PLOT_MEMBERS;
public boolean AUTO_MERGE;
public boolean ALLOW_SIGNS;
public boolean MOB_SPAWNING;
public int PLOT_BIOME;
public boolean PLOT_CHAT;
public boolean SCHEMATIC_CLAIM_SPECIFY = false;
public boolean SCHEMATIC_ON_CLAIM;
public String SCHEMATIC_FILE;
public List<String> SCHEMATICS;
public HashMap<String, Flag> DEFAULT_FLAGS;
public boolean USE_ECONOMY;
public double PLOT_PRICE;
public double MERGE_PRICE;
public double SELL_PRICE;
public boolean SPAWN_EGGS;
public boolean SPAWN_CUSTOM;
public boolean SPAWN_BREEDING;
public boolean WORLD_BORDER;
public int TYPE = 0;
public int TERRAIN = 0;
public boolean HOME_ALLOW_NONMEMBER;
public PlotLoc DEFAULT_HOME;
public int MAX_BUILD_HEIGHT;
public int MIN_BUILD_HEIGHT;
public PlotGamemode GAMEMODE = PlotGamemode.CREATIVE;
public final String worldname;
public final String id;
public final PlotManager manager;
private final PlotId min;
private final PlotId max;
private RegionWrapper region;
/**
* Please ignore
*/
@Deprecated
private int compatibility_id;
private ConcurrentHashMap<String, Object> meta;
private final ConcurrentHashMap<PlotId, Plot> plots = new ConcurrentHashMap<>();
private QuadMap<PlotCluster> clusters;
private final IndependentPlotGenerator generator;
public PlotArea(final String worldname, String id, IndependentPlotGenerator generator, PlotId min, PlotId max) {
this.worldname = worldname;
this.id = id;
this.manager = generator != null ? generator.getNewPlotManager() : null;
this.generator = generator;
if ((min == null) || (max == null)) {
if (min != max) {
throw new IllegalArgumentException("None of the ids can be null for this constructor");
}
this.min = null;
this.max = null;
} else {
this.min = min;
this.max = max;
}
this.worldhash = worldname.hashCode();
}
public static PlotArea createGeneric(String world) {
return new PlotArea(world, null, null, null, null) {
@Override
public void loadConfiguration(ConfigurationSection config) {}
@Override
public ConfigurationNode[] getSettingNodes() {return null;}
};
}
/**
* Returns the region for this PlotArea
* @return
*/
public RegionWrapper getRegion() {
if (region == null) {
if (min != null) {
Location bot = getPlotManager().getPlotBottomLocAbs(this, min);
Location top = getPlotManager().getPlotTopLocAbs(this, max);
this.region = new RegionWrapper(bot.getX() - 1, top.getX() + 1, bot.getZ() - 1, top.getZ() + 1);
} else {
return new RegionWrapper(Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE);
}
}
return region;
}
/**
* Returns the min PlotId
* @return
*/
public PlotId getMin() {
return min == null ? new PlotId(Integer.MIN_VALUE, Integer.MIN_VALUE) : min;
}
/**
* Returns the max PlotId
* @return
*/
public PlotId getMax() {
return max == null ? new PlotId(Integer.MAX_VALUE, Integer.MAX_VALUE) : max;
}
public IndependentPlotGenerator getGenerator() {
return generator;
}
public final int worldhash;
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final PlotArea plotarea = (PlotArea) obj;
return this.worldhash == plotarea.worldhash && this.worldname.equals(plotarea.worldname) && StringMan.isEqual(this.id, plotarea.id);
}
public Set<PlotCluster> getClusters() {
return clusters == null ? new HashSet<PlotCluster>() : clusters.getAll();
}
public void setCompatibility(String version) {
switch (version) {
case "3.2.X":
compatibility_id = 1;
break;
default:
throw new IllegalArgumentException("Not valid version");
}
}
public boolean isCompatible(PlotArea plotarea) {
final ConfigurationSection section = PS.get().config.getConfigurationSection("worlds");
for (final ConfigurationNode setting : plotarea.getSettingNodes()) {
final Object constant = section.get(plotarea.worldname + "." + setting.getConstant());
if (constant == null) {
return false;
}
if (!constant.equals(section.get(worldname + "." + setting.getConstant()))) {
return false;
}
}
return true;
}
/**
* When a world is created, the following method will be called for each
*
* @param config Configuration Section
*/
public void loadDefaultConfiguration(final ConfigurationSection config) {
if ((min != null || max != null) && !(this instanceof GridPlotWorld)) {
throw new IllegalArgumentException("Must extend GridPlotWorld to provide");
}
if (config.contains("generator.terrain")) {
TERRAIN = config.getInt("generator.terrain");
TYPE = config.getInt("generator.type");
}
MOB_SPAWNING = config.getBoolean("natural_mob_spawning");
AUTO_MERGE = config.getBoolean("plot.auto_merge");
MAX_PLOT_MEMBERS = config.getInt("limits.max-members");
ALLOW_SIGNS = config.getBoolean("plot.create_signs");
PLOT_BIOME = WorldUtil.IMP.getBiomeFromString(Configuration.BIOME.parseString(config.getString("plot.biome")));
SCHEMATIC_ON_CLAIM = config.getBoolean("schematic.on_claim");
SCHEMATIC_FILE = config.getString("schematic.file");
SCHEMATIC_CLAIM_SPECIFY = config.getBoolean("schematic.specify_on_claim");
SCHEMATICS = config.getStringList("schematic.schematics");
USE_ECONOMY = config.getBoolean("economy.use") && (EconHandler.manager != null);
PLOT_PRICE = config.getDouble("economy.prices.claim");
MERGE_PRICE = config.getDouble("economy.prices.merge");
SELL_PRICE = config.getDouble("economy.prices.sell");
PLOT_CHAT = config.getBoolean("chat.enabled");
WORLD_BORDER = config.getBoolean("world.border");
MAX_BUILD_HEIGHT = config.getInt("world.max_height");
MIN_BUILD_HEIGHT = config.getInt("min.max_height");
switch (config.getString("world.gamemode").toLowerCase()) {
case "survival":
case "s":
case "0":
GAMEMODE = PlotGamemode.SURVIVAL;
break;
case "creative":
case "c":
case "1":
GAMEMODE = PlotGamemode.CREATIVE;
break;
case "adventure":
case "a":
case "2":
GAMEMODE = PlotGamemode.ADVENTURE;
break;
case "spectator":
case "3":
GAMEMODE = PlotGamemode.SPECTATOR;
break;
default:
PS.debug("&cInvalid gamemode set for: " + worldname);
break;
}
HOME_ALLOW_NONMEMBER = config.getBoolean("home.allow-nonmembers");
final String homeDefault = config.getString("home.default");
if (homeDefault.equalsIgnoreCase("side")) {
DEFAULT_HOME = null;
} else if (homeDefault.equalsIgnoreCase("center")) {
DEFAULT_HOME = new PlotLoc(Integer.MAX_VALUE, Integer.MAX_VALUE);
} else {
try {
final String[] split = homeDefault.split(",");
DEFAULT_HOME = new PlotLoc(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
} catch (final Exception e) {
DEFAULT_HOME = null;
}
}
List<String> flags = config.getStringList("flags.default");
if ((flags == null) || (flags.size() == 0)) {
flags = config.getStringList("flags");
if ((flags == null) || (flags.size() == 0)) {
flags = new ArrayList<>();
final ConfigurationSection section = config.getConfigurationSection("flags");
final Set<String> keys = section.getKeys(false);
for (final String key : keys) {
if (!key.equals("default")) {
flags.add(key + ";" + section.get(key));
}
}
}
}
try {
DEFAULT_FLAGS = FlagManager.parseFlags(flags);
} catch (final Exception e) {
e.printStackTrace();
PS.debug("&cInvalid default flags for " + worldname + ": " + StringMan.join(flags, ","));
DEFAULT_FLAGS = new HashMap<>();
}
SPAWN_EGGS = config.getBoolean("event.spawn.egg");
SPAWN_CUSTOM = config.getBoolean("event.spawn.custom");
SPAWN_BREEDING = config.getBoolean("event.spawn.breeding");
loadConfiguration(config);
}
public abstract void loadConfiguration(final ConfigurationSection config);
/**
* Saving core plotarea settings
*
* @param config Configuration Section
*/
public void saveConfiguration(final ConfigurationSection config) {
final HashMap<String, Object> options = new HashMap<>();
options.put("natural_mob_spawning", PlotArea.MOB_SPAWNING_DEFAULT);
options.put("plot.auto_merge", PlotArea.AUTO_MERGE_DEFAULT);
options.put("plot.create_signs", PlotArea.ALLOW_SIGNS_DEFAULT);
options.put("plot.biome", PlotArea.PLOT_BIOME_DEFAULT);
options.put("schematic.on_claim", PlotArea.SCHEMATIC_ON_CLAIM_DEFAULT);
options.put("schematic.file", PlotArea.SCHEMATIC_FILE_DEFAULT);
options.put("schematic.specify_on_claim", PlotArea.SCHEMATIC_CLAIM_SPECIFY_DEFAULT);
options.put("schematic.schematics", PlotArea.SCHEMATICS_DEFAULT);
options.put("economy.use", PlotArea.USE_ECONOMY_DEFAULT);
options.put("economy.prices.claim", PlotArea.PLOT_PRICE_DEFAULT);
options.put("economy.prices.merge", PlotArea.MERGE_PRICE_DEFAULT);
options.put("economy.prices.sell", PlotArea.SELL_PRICE_DEFAULT);
options.put("chat.enabled", PlotArea.PLOT_CHAT_DEFAULT);
options.put("flags.default", null);
options.put("event.spawn.egg", PlotArea.SPAWN_EGGS_DEFAULT);
options.put("event.spawn.custom", PlotArea.SPAWN_CUSTOM_DEFAULT);
options.put("event.spawn.breeding", PlotArea.SPAWN_BREEDING_DEFAULT);
options.put("world.border", PlotArea.WORLD_BORDER_DEFAULT);
options.put("limits.max-members", PlotArea.MAX_PLOT_MEMBERS_DEFAULT);
options.put("home.default", "side");
options.put("home.allow-nonmembers", false);
options.put("world.max_height", PlotArea.MAX_BUILD_HEIGHT_DEFAULT);
options.put("world.min_height", PlotArea.MIN_BUILD_HEIGHT_DEFAULT);
options.put("world.gamemode", PlotArea.GAMEMODE_DEFAULT.name().toLowerCase());
if ((TYPE != 0)) {
options.put("generator.terrain", TERRAIN);
options.put("generator.type", TYPE);
}
final ConfigurationNode[] settings = getSettingNodes();
/*
* Saving generator specific settings
*/
for (final ConfigurationNode setting : settings) {
options.put(setting.getConstant(), setting.getValue());
}
for (final String option : options.keySet()) {
if (!config.contains(option)) {
config.set(option, options.get(option));
}
}
if (!config.contains("flags")) {
config.set("flags.use", "63,64,68,69,71,77,96,143,167,193,194,195,196,197,77,143,69,70,72,147,148,107,183,184,185,186,187,132");
}
}
@Override
public String toString() {
return (compatibility_id == 1 || id == null) ? worldname : worldname + ";" + id;
}
int hash;
@Override
public int hashCode() {
if (hash != 0) {
return hash;
}
return hash = toString().hashCode();
}
/**
* Used for the <b>/plot setup</b> command Return null if you do not want to support this feature
*
* @return ConfigurationNode[]
*/
public abstract ConfigurationNode[] getSettingNodes();
public Plot getPlotAbs(Location loc) {
PlotId pid = manager.getPlotId(this, loc.getX(), loc.getY(), loc.getZ());
if (pid == null) {
return null;
}
return getPlotAbs(pid);
}
public Plot getPlot(Location loc) {
PlotId pid = manager.getPlotId(this, loc.getX(), loc.getY(), loc.getZ());
if (pid == null) {
return null;
}
return getPlot(pid);
}
public Plot getOwnedPlot(Location loc) {
PlotId pid = manager.getPlotId(this, loc.getX(), loc.getY(), loc.getZ());
if (pid == null) {
return null;
}
Plot plot = plots.get(pid);
return plot == null ? null : plot.getBasePlot(false);
}
public Plot getOwnedPlotAbs(Location loc) {
PlotId pid = manager.getPlotId(this, loc.getX(), loc.getY(), loc.getZ());
if (pid == null) {
return null;
}
return plots.get(pid);
}
public Plot getOwnedPlotAbs(PlotId id) {
return plots.get(id);
}
public Plot getOwnedPlot(PlotId id) {
Plot plot = plots.get(id);
return plot == null ? null : plot.getBasePlot(false);
}
public boolean contains(Location loc) {
return StringMan.isEqual(loc.getWorld(), worldname) && (region == null || region.isIn(loc.getX(), loc.getZ()));
}
public Set<Plot> getPlotsAbs(UUID uuid) {
HashSet<Plot> plots = new HashSet<>();
for (Plot plot : plots) {
if (plot.owner.equals(uuid)) {
plots.add(plot);
}
}
return plots;
}
public Set<Plot> getPlots(UUID uuid) {
HashSet<Plot> plots = new HashSet<>();
for (Plot plot : getPlots()) {
if (plot.isBasePlot()) {
if (plot.isOwner(uuid)) {
plots.add(plot);
}
}
}
return plots;
}
public Set<Plot> getPlots(PlotPlayer player) {
return player != null ? getPlots(player.getUUID()) : new HashSet<Plot>();
}
public Set<Plot> getPlotsAbs(PlotPlayer player) {
return player != null ? getPlotsAbs(player.getUUID()) : new HashSet<Plot>();
}
public int getPlotCount(UUID uuid) {
int count = 0;
if (!Settings.DONE_COUNTS_TOWARDS_LIMIT) {
for (Plot plot : getPlotsAbs(uuid)) {
if (!plot.getFlags().containsKey("done")) {
count++;
}
}
} else {
count += getPlotsAbs(uuid).size();
}
return count;
}
public int getPlotCount(PlotPlayer player) {
return player != null ? getPlotCount(player.getUUID()) : 0;
}
public boolean contains(int x, int z) {
return region == null || region.isIn(x, z);
}
public Plot getPlotAbs(PlotId id) {
Plot plot = getOwnedPlotAbs(id);
if (plot == null) {
if (min != null && (id.x < min.x || id.x > max.x || id.y < min.y || id.y > max.y)) {
return null;
}
return new Plot(this, id);
}
return plot;
}
public Plot getPlot(PlotId id) {
Plot plot = getOwnedPlotAbs(id);
if (plot == null) {
if (min != null && (id.x < min.x || id.x > max.x || id.y < min.y || id.y > max.y)) {
return null;
}
return new Plot(this, id);
}
return plot.getBasePlot(false);
}
public int getPlotCount() {
return plots.size();
}
public PlotCluster getCluster(Location loc) {
if (!Settings.ENABLE_CLUSTERS) {
return null;
}
Plot plot = getPlot(loc);
if (plot == null) {
return null;
}
return clusters != null ? clusters.get(plot.id.x, plot.id.y) : null;
}
public PlotCluster getFirstIntersectingCluster(PlotId pos1, PlotId pos2) {
if (!Settings.ENABLE_CLUSTERS || clusters == null) {
return null;
}
for (PlotCluster cluster : clusters.getAll()) {
if (cluster.intersects(pos1, pos2)) {
return cluster;
}
}
return null;
}
public PlotCluster getCluster(PlotId id) {
if (!Settings.ENABLE_CLUSTERS) {
return null;
}
return clusters != null ? clusters.get(id.x, id.y) : null;
}
public PlotManager getPlotManager() {
return manager;
}
/**
* Session only plot metadata (session is until the server stops)<br>
* <br>
* For persistent metadata use the flag system
* @see FlagManager
* @param key
* @param value
*/
public void setMeta(final String key, final Object value) {
if (meta == null) {
meta = new ConcurrentHashMap<String, Object>();
}
meta.put(key, value);
}
/**
* Get the metadata for a key<br>
* <br>
* For persistent metadata use the flag system
* @param key
* @return
*/
public Object getMeta(final String key) {
if (meta != null) {
return meta.get(key);
}
return null;
}
public Collection<Plot> getPlots() {
return plots.values();
}
public Set<Plot> getBasePlots() {
HashSet<Plot> plots = new HashSet<>(getPlots());
Iterator<Plot> iter = plots.iterator();
while (iter.hasNext()) {
if (!iter.next().isBasePlot()) {
iter.remove();
}
}
return plots;
}
public void foreachBasePlot(RunnableVal<Plot> run) {
for (Plot plot : getPlots()) {
if (plot.isBasePlot()) {
run.run(plot);
}
}
}
public Map<PlotId, Plot> getPlotsRaw() {
return plots;
}
public Set<Entry<PlotId, Plot>> getPlotEntries() {
return plots.entrySet();
}
public boolean addPlot(Plot plot) {
for (PlotPlayer pp : plot.getPlayersInPlot()) {
pp.setMeta("lastplot", plot);
}
return plots.put(plot.id, plot) == null;
}
public boolean addPlotIfAbsent(Plot plot) {
if (plots.putIfAbsent(plot.id, plot) == null) {
for (PlotPlayer pp : plot.getPlayersInPlot()) {
pp.setMeta("lastplot", plot);
}
return true;
}
return false;
}
public boolean addPlotAbs(Plot plot) {
return plots.put(plot.id, plot) == null;
}
/**
* Check if the plots in a selection are unowned
* @param world
* @param pos1
* @param pos2
* @return
*/
public boolean isUnowned(final PlotId pos1, final PlotId pos2) {
int area = (pos2.x - pos1.x + 1) * (pos2.y - pos1.y + 1);
if (area > getPlotCount()) {
for (Plot plot : getPlots()) {
if (plot.id.x >= pos1.x && plot.id.x <= pos2.x && plot.id.y >= pos1.y && plot.id.y <= pos2.y) {
return false;
}
}
} else {
for (int x = pos1.x; x <= pos2.x; x++) {
for (int y = pos1.y; y <= pos2.y; y++) {
final PlotId id = new PlotId(x, y);
if (plots.get(id) != null) {
return false;
}
}
}
}
return true;
}
/**
* Get the plot border distance for a world<br>
* @param worldname
* @return The border distance or Integer.MAX_VALUE if no border is set
*/
public int getBorder() {
Integer meta = (Integer) getMeta("worldBorder");
if (meta != null) {
final int border = meta + 16;
if (border == 0) {
return Integer.MAX_VALUE;
} else {
return border;
}
}
return Integer.MAX_VALUE;
}
/**
* Setup the plot border for a world (usually done when the world is created)
* @param world
*/
public void setupBorder() {
if (!WORLD_BORDER) {
return;
}
Integer meta = (Integer) getMeta("worldBorder");
if (meta == null) {
setMeta("worldBorder", 1);
}
for (final Plot plot : getPlots()) {
plot.updateWorldBorder();
}
}
/**
* Delete the metadata for a key<br>
* - metadata is session only
* - deleting other plugin's metadata may cause issues
* @param key
*/
public void deleteMeta(final String key) {
if (meta != null) {
meta.remove(key);
}
}
public boolean canClaim(final PlotPlayer player, final PlotId pos1, final PlotId pos2) {
for (int x = pos1.x; x <= pos2.x; x++) {
for (int y = pos1.y; y <= pos2.y; y++) {
final PlotId id = new PlotId(x, y);
final Plot plot = getPlot(id);
if (!plot.canClaim(player)) {
return false;
}
}
}
return true;
}
public boolean mergePlots(final PlotPlayer player, final ArrayList<PlotId> plotIds) {
if ((EconHandler.manager != null) && USE_ECONOMY) {
final double cost = plotIds.size() * MERGE_PRICE;
if (cost > 0d) {
if (EconHandler.manager.getMoney(player) < cost) {
MainUtil.sendMessage(player, C.CANNOT_AFFORD_MERGE, "" + cost);
return false;
}
EconHandler.manager.withdrawMoney(player, cost);
MainUtil.sendMessage(player, C.REMOVED_BALANCE, cost + "");
}
}
return mergePlots(plotIds, true, true);
}
public boolean removePlot(PlotId id) {
return plots.remove(id) != null;
}
public boolean mergePlots(final ArrayList<PlotId> plotIds, final boolean removeRoads, final boolean updateDatabase) {
if (plotIds.size() < 2) {
return false;
}
final PlotId pos1 = plotIds.get(0);
final PlotId pos2 = plotIds.get(plotIds.size() - 1);
final PlotManager manager = getPlotManager();
final boolean result = EventUtil.manager.callMerge(getPlotAbs(pos1), plotIds);
if (!result) {
return false;
}
final HashSet<UUID> trusted = new HashSet<UUID>();
final HashSet<UUID> members = new HashSet<UUID>();
final HashSet<UUID> denied = new HashSet<UUID>();
manager.startPlotMerge(this, plotIds);
for (int x = pos1.x; x <= pos2.x; x++) {
for (int y = pos1.y; y <= pos2.y; y++) {
final PlotId id = new PlotId(x, y);
final Plot plot = getPlotAbs(id);
trusted.addAll(plot.getTrusted());
members.addAll(plot.getMembers());
denied.addAll(plot.getDenied());
if (removeRoads) {
plot.removeSign();
}
}
}
members.removeAll(trusted);
denied.removeAll(trusted);
denied.removeAll(members);
Plot plot2;
for (int x = pos1.x; x <= pos2.x; x++) {
for (int y = pos1.y; y <= pos2.y; y++) {
final boolean lx = x < pos2.x;
final boolean ly = y < pos2.y;
final PlotId id = new PlotId(x, y);
final Plot plot = getPlotAbs(id);
plot.setTrusted(trusted);
plot.setMembers(members);
plot.setDenied(denied);
if (lx) {
if (ly) {
if (!plot.getMerged(1) || !plot.getMerged(2)) {
if (removeRoads) {
plot.removeRoadSouthEast();
}
}
}
if (!plot.getMerged(1)) {
plot2 = plot.getRelative(1, 0);
plot.mergePlot(plot2, removeRoads);
}
}
if (ly) {
if (!plot.getMerged(2)) {
plot2 = plot.getRelative(0, 1);
plot.mergePlot(plot2, removeRoads);
}
}
}
}
manager.finishPlotMerge(this, plotIds);
return true;
}
/**
* Get a set of owned plots within a selection (chooses the best algorithm based on selection size.<br>
* i.e. A selection of billions of plots will work fine
* @param pos1
* @param pos2
* @return
*/
public HashSet<Plot> getPlotSelectionOwned(final PlotId pos1, final PlotId pos2) {
final int size = ((1 + pos2.x) - pos1.x) * ((1 + pos2.y) - pos1.y);
final HashSet<Plot> result = new HashSet<>();
if (size < 16 || size < getPlotCount()) {
for (final PlotId pid : MainUtil.getPlotSelectionIds(pos1, pos2)) {
final Plot plot = getPlotAbs(pid);
if (plot.hasOwner()) {
if ((plot.getId().x > pos1.x) || (plot.getId().y > pos1.y) || (plot.getId().x < pos2.x) || (plot.getId().y < pos2.y)) {
result.add(plot);
}
}
}
} else {
for (final Plot plot : getPlots()) {
if ((plot.getId().x > pos1.x) || (plot.getId().y > pos1.y) || (plot.getId().x < pos2.x) || (plot.getId().y < pos2.y)) {
result.add(plot);
}
}
}
return result;
}
public void removeCluster(PlotCluster plotCluster) {
if (!Settings.ENABLE_CLUSTERS || clusters == null) {
throw new IllegalAccessError("Clusters not enabled!");
}
clusters.remove(plotCluster);
}
public void addCluster(PlotCluster plotCluster) {
if (!Settings.ENABLE_CLUSTERS) {
throw new IllegalAccessError("Clusters not enabled!");
}
if (clusters == null) {
clusters = new QuadMap<PlotCluster>(Integer.MAX_VALUE, 0, 0, 64) {
@Override
public RegionWrapper getRegion(PlotCluster value) {
return new RegionWrapper(value.getP1().x, value.getP2().x, value.getP1().y, value.getP2().y);
}
};
}
clusters.add(plotCluster);
}
public PlotCluster getCluster(String string) {
for (PlotCluster cluster : getClusters()) {
if (cluster.getName().equalsIgnoreCase(string)) {
return cluster;
}
}
return null;
}
}

View File

@ -4,15 +4,17 @@ import java.util.HashSet;
import java.util.UUID; import java.util.UUID;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.util.MainUtil;
public class PlotCluster { public class PlotCluster {
public final String world; public PlotArea area;
public PlotSettings settings; public PlotSettings settings;
public UUID owner; public UUID owner;
public HashSet<UUID> helpers = new HashSet<UUID>(); public HashSet<UUID> helpers = new HashSet<UUID>();
public HashSet<UUID> invited = new HashSet<UUID>(); public HashSet<UUID> invited = new HashSet<UUID>();
private PlotId pos1; private PlotId pos1;
private PlotId pos2; private PlotId pos2;
private RegionWrapper region;
public int temp; public int temp;
@ -26,28 +28,40 @@ public class PlotCluster {
public void setP1(final PlotId id) { public void setP1(final PlotId id) {
pos1 = id; pos1 = id;
setRegion();
} }
public void setP2(final PlotId id) { public void setP2(final PlotId id) {
pos2 = id; pos2 = id;
setRegion();
} }
public PlotCluster(final String world, final PlotId pos1, final PlotId pos2, final UUID owner) { public PlotCluster(final PlotArea area, final PlotId pos1, final PlotId pos2, final UUID owner) {
this.world = world; this.area = area;
this.pos1 = pos1; this.pos1 = pos1;
this.pos2 = pos2; this.pos2 = pos2;
this.owner = owner; this.owner = owner;
settings = new PlotSettings(); settings = new PlotSettings();
this.temp = -1; this.temp = -1;
setRegion();
} }
public PlotCluster(final String world, final PlotId pos1, final PlotId pos2, final UUID owner, int temp) { public PlotCluster(final PlotArea area, final PlotId pos1, final PlotId pos2, final UUID owner, int temp) {
this.world = world; this.area = area;
this.pos1 = pos1; this.pos1 = pos1;
this.pos2 = pos2; this.pos2 = pos2;
this.owner = owner; this.owner = owner;
settings = new PlotSettings(); settings = new PlotSettings();
this.temp = temp; this.temp = temp;
setRegion();
}
private void setRegion() {
region = new RegionWrapper(pos1.x, pos2.x, pos1.y, pos2.y);
}
public RegionWrapper getRegion() {
return region;
} }
public boolean isAdded(final UUID uuid) { public boolean isAdded(final UUID uuid) {
@ -87,11 +101,69 @@ public class PlotCluster {
return false; return false;
} }
final PlotCluster other = (PlotCluster) obj; final PlotCluster other = (PlotCluster) obj;
return (world.equals(other.world) && pos1.equals(other.pos1) && pos2.equals(other.pos2)); return pos1.equals(other.pos1) && pos2.equals(other.pos2) && area.equals(other.area);
} }
@Override @Override
public String toString() { public String toString() {
return world + ";" + pos1.x + ";" + pos1.y + ";" + pos2.x + ";" + pos2.y; return area + ";" + pos1.x + ";" + pos1.y + ";" + pos2.x + ";" + pos2.y;
}
public Location getHome() {
final BlockLoc home = settings.getPosition();
Location toReturn;
if (home.y == 0) {
// default pos
final Plot center = getCenterPlot();
toReturn = center.getHome();
if (toReturn.getY() == 0) {
final PlotManager manager = area.getPlotManager();
final Location loc = manager.getSignLoc(area, center);
toReturn.setY(loc.getY());
}
} else {
toReturn = getClusterBottom().add(home.x, home.y, home.z);
}
final int max = MainUtil.getHeighestBlock(area.worldname, toReturn.getX(), toReturn.getZ());
if (max > toReturn.getY()) {
toReturn.setY(max);
}
return toReturn;
}
public PlotId getCenterPlotId() {
final PlotId bot = getP1();
final PlotId top = getP2();
return new PlotId((bot.x + top.x) / 2, (bot.y + top.y) / 2);
}
public Plot getCenterPlot() {
return area.getPlotAbs(getCenterPlotId());
}
public Location getClusterBottom() {
final PlotManager manager = area.getPlotManager();
return manager.getPlotBottomLocAbs(area, getP1());
}
public Location getClusterTop() {
final PlotManager manager = area.getPlotManager();
return manager.getPlotTopLocAbs(area, getP2());
}
public boolean intersects(PlotId pos1, PlotId pos2) {
return (pos1.x <= this.pos2.x) && (pos2.x >= this.pos1.x) && (pos1.y <= this.pos2.y) && (pos2.y >= this.pos1.y);
}
public void setArea(PlotArea plotarea) {
if (this.area != null) {
this.area.removeCluster(this);
}
this.area = plotarea;
plotarea.addCluster(this);
}
public boolean contains(final PlotId id) {
return (pos1.x <= id.x) && (pos1.y <= id.y) && (pos2.x >= id.x) && (pos2.y >= id.y);
} }
} }

View File

@ -1,11 +0,0 @@
package com.intellectualcrafters.plot.object;
public class PlotClusterId {
public final PlotId pos1;
public final PlotId pos2;
public PlotClusterId(final PlotId pos1, final PlotId pos2) {
this.pos1 = pos1;
this.pos2 = pos2;
}
}

View File

@ -1,7 +1,7 @@
package com.intellectualcrafters.plot.object; package com.intellectualcrafters.plot.object;
public abstract class PlotFilter { public abstract class PlotFilter {
public boolean allowsWorld(final String world) { public boolean allowsArea(final PlotArea area) {
return true; return true;
} }

View File

@ -1,23 +1,21 @@
package com.intellectualcrafters.plot.object; package com.intellectualcrafters.plot.object;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.UUIDHandler;
import org.bukkit.Bukkit;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.util.UUIDHandler;
public class PlotHandler { public class PlotHandler {
public static HashSet<UUID> getOwners(final Plot plot) { public static HashSet<UUID> getOwners(final Plot plot) {
if (plot.owner == null) { if (plot.owner == null) {
return new HashSet<UUID>(); return new HashSet<UUID>();
} }
if (plot.isMerged()) { if (plot.isMerged()) {
HashSet<Plot> plots = MainUtil.getConnectedPlots(plot); HashSet<Plot> plots = plot.getConnectedPlots();
final HashSet<UUID> owners = new HashSet<UUID>(2); final HashSet<UUID> owners = new HashSet<UUID>(2);
UUID last = plot.owner; UUID last = plot.owner;
owners.add(plot.owner); owners.add(plot.owner);
@ -42,8 +40,10 @@ public class PlotHandler {
if (!plot.isMerged()) { if (!plot.isMerged()) {
return false; return false;
} }
for (Plot current : MainUtil.getConnectedPlots(plot)) { HashSet<Plot> connected = plot.getConnectedPlots();
if (current.owner.equals(uuid)) { Iterator<Plot> iter = connected.iterator();
while (iter.hasNext()) {
if (uuid.equals(iter.next().owner)) {
return true; return true;
} }
} }
@ -57,7 +57,7 @@ public class PlotHandler {
if (!plot.isMerged()) { if (!plot.isMerged()) {
return UUIDHandler.getPlayer(plot.owner) != null; return UUIDHandler.getPlayer(plot.owner) != null;
} }
for (Plot current : MainUtil.getConnectedPlots(plot)) { for (Plot current : plot.getConnectedPlots()) {
if (current.owner != null && UUIDHandler.getPlayer(current.owner) != null) { if (current.owner != null && UUIDHandler.getPlayer(current.owner) != null) {
return true; return true;
} }
@ -78,7 +78,7 @@ public class PlotHandler {
} }
return; return;
} }
for (Plot current : MainUtil.getConnectedPlots(plot)) { for (Plot current : plot.getConnectedPlots()) {
if (!owner.equals(current.owner)) { if (!owner.equals(current.owner)) {
current.owner = owner; current.owner = owner;
DBFunc.setOwner(current, owner); DBFunc.setOwner(current, owner);
@ -177,7 +177,7 @@ public class PlotHandler {
} }
public static void addDenied(Plot plot, UUID uuid) { public static void addDenied(Plot plot, UUID uuid) {
for (Plot current : MainUtil.getConnectedPlots(plot)) { for (Plot current : plot.getConnectedPlots()) {
if (current.getDenied().add(uuid)) { if (current.getDenied().add(uuid)) {
DBFunc.setDenied(current, uuid); DBFunc.setDenied(current, uuid);
} }
@ -185,7 +185,7 @@ public class PlotHandler {
} }
public static void addMember(Plot plot, UUID uuid) { public static void addMember(Plot plot, UUID uuid) {
for (Plot current : MainUtil.getConnectedPlots(plot)) { for (Plot current : plot.getConnectedPlots()) {
if (current.getMembers().add(uuid)) { if (current.getMembers().add(uuid)) {
DBFunc.setMember(current, uuid); DBFunc.setMember(current, uuid);
} }
@ -193,7 +193,7 @@ public class PlotHandler {
} }
public static void addTrusted(Plot plot, UUID uuid) { public static void addTrusted(Plot plot, UUID uuid) {
for (Plot current : MainUtil.getConnectedPlots(plot)) { for (Plot current : plot.getConnectedPlots()) {
if (current.getTrusted().add(uuid)) { if (current.getTrusted().add(uuid)) {
DBFunc.setTrusted(current, uuid); DBFunc.setTrusted(current, uuid);
} }
@ -201,7 +201,7 @@ public class PlotHandler {
} }
public static boolean removeDenied(Plot plot, UUID uuid) { public static boolean removeDenied(Plot plot, UUID uuid) {
for (Plot current : MainUtil.getConnectedPlots(plot)) { for (Plot current : plot.getConnectedPlots()) {
if (current.getDenied().remove(uuid)) { if (current.getDenied().remove(uuid)) {
DBFunc.removeDenied(current, uuid); DBFunc.removeDenied(current, uuid);
} else { } else {
@ -212,7 +212,7 @@ public class PlotHandler {
} }
public static boolean removeMember(Plot plot, UUID uuid) { public static boolean removeMember(Plot plot, UUID uuid) {
for (Plot current : MainUtil.getConnectedPlots(plot)) { for (Plot current : plot.getConnectedPlots()) {
if (current.getMembers().remove(uuid)) { if (current.getMembers().remove(uuid)) {
DBFunc.removeMember(current, uuid); DBFunc.removeMember(current, uuid);
} else { } else {
@ -223,7 +223,7 @@ public class PlotHandler {
} }
public static boolean removeTrusted(Plot plot, UUID uuid) { public static boolean removeTrusted(Plot plot, UUID uuid) {
for (Plot current : MainUtil.getConnectedPlots(plot)) { for (Plot current : plot.getConnectedPlots()) {
if (current.getTrusted().remove(uuid)) { if (current.getTrusted().remove(uuid)) {
DBFunc.removeTrusted(current, uuid); DBFunc.removeTrusted(current, uuid);
} else { } else {
@ -237,8 +237,8 @@ public class PlotHandler {
if (plot.owner == null) { if (plot.owner == null) {
return false; return false;
} }
for (Plot current : MainUtil.getConnectedPlots(plot)) { for (Plot current : plot.getConnectedPlots()) {
PS.get().removePlot(current.world, current.id, true); plot.area.removePlot(plot.id);
DBFunc.delete(current); DBFunc.delete(current);
current.settings = null; current.settings = null;
} }

View File

@ -49,6 +49,9 @@ public class PlotId {
* @return null if the string is invalid * @return null if the string is invalid
*/ */
public static PlotId fromString(final String string) { public static PlotId fromString(final String string) {
if (string == null) {
return null;
}
int x, y; int x, y;
final String[] parts = string.split(";"); final String[] parts = string.split(";");
if (parts.length < 2) { if (parts.length < 2) {
@ -63,6 +66,24 @@ public class PlotId {
return new PlotId(x, y); return new PlotId(x, y);
} }
public PlotId getRelative(final int direction) {
switch (direction) {
case 0:
return new PlotId(this.x, this.y - 1);
case 1:
return new PlotId(this.x + 1, this.y);
case 2:
return new PlotId(this.x, this.y + 1);
case 3:
return new PlotId(this.x - 1, this.y);
}
return this;
}
public PlotId getRelative(int x, int y) {
return new PlotId(this.x + x, this.y + y);
}
@Override @Override
public boolean equals(final Object obj) { public boolean equals(final Object obj) {
if (this == obj) { if (this == obj) {

View File

@ -1,6 +1,7 @@
package com.intellectualcrafters.plot.object; package com.intellectualcrafters.plot.object;
import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.StringComparison;
import com.intellectualcrafters.plot.util.WorldUtil;
public class PlotItemStack { public class PlotItemStack {
public final int id; public final int id;
@ -19,7 +20,8 @@ public class PlotItemStack {
} }
public PlotItemStack(final String id, final int amount, final String name, final String... lore) { public PlotItemStack(final String id, final int amount, final String name, final String... lore) {
final PlotBlock block = BlockManager.manager.getPlotBlockFromString(id); StringComparison<PlotBlock>.ComparisonResult match = WorldUtil.IMP.getClosestBlock(id);
final PlotBlock block = match.best;
this.id = block.id; this.id = block.id;
data = block.data; data = block.data;
this.amount = amount; this.amount = amount;

View File

@ -20,72 +20,72 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.object; package com.intellectualcrafters.plot.object;
import com.intellectualcrafters.plot.commands.Template;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import com.intellectualcrafters.plot.commands.Template;
public abstract class PlotManager { public abstract class PlotManager {
/* /*
* Plot locations (methods with Abs in them will not need to consider mega * Plot locations (methods with Abs in them will not need to consider mega
* plots) * plots)
*/ */
public abstract PlotId getPlotIdAbs(final PlotWorld plotworld, final int x, final int y, final int z); public abstract PlotId getPlotIdAbs(final PlotArea plotworld, final int x, final int y, final int z);
public abstract PlotId getPlotId(final PlotWorld plotworld, final int x, final int y, final int z); public abstract PlotId getPlotId(final PlotArea plotworld, final int x, final int y, final int z);
// If you have a circular plot, just return the corner if it were a square // If you have a circular plot, just return the corner if it were a square
public abstract Location getPlotBottomLocAbs(final PlotWorld plotworld, final PlotId plotid); public abstract Location getPlotBottomLocAbs(final PlotArea plotworld, final PlotId plotid);
// the same applies here // the same applies here
public abstract Location getPlotTopLocAbs(final PlotWorld plotworld, final PlotId plotid); public abstract Location getPlotTopLocAbs(final PlotArea plotworld, final PlotId plotid);
/* /*
* Plot clearing (return false if you do not support some method) * Plot clearing (return false if you do not support some method)
*/ */
public abstract boolean clearPlot(final PlotWorld plotworld, final Plot plot, final Runnable whenDone); public abstract boolean clearPlot(final PlotArea plotworld, final Plot plot, final Runnable whenDone);
public abstract boolean claimPlot(final PlotWorld plotworld, final Plot plot); public abstract boolean claimPlot(final PlotArea plotworld, final Plot plot);
public abstract boolean unclaimPlot(final PlotWorld plotworld, final Plot plot, final Runnable whenDone); public abstract boolean unclaimPlot(final PlotArea plotworld, final Plot plot, final Runnable whenDone);
public abstract Location getSignLoc(final PlotWorld plotworld, final Plot plot); public abstract Location getSignLoc(final PlotArea plotworld, final Plot plot);
/* /*
* Plot set functions (return false if you do not support the specific set * Plot set functions (return false if you do not support the specific set
* method) * method)
*/ */
public abstract String[] getPlotComponents(final PlotWorld plotworld, final PlotId plotid); public abstract String[] getPlotComponents(final PlotArea plotworld, final PlotId plotid);
public abstract boolean setComponent(final PlotWorld plotworld, final PlotId plotid, final String component, final PlotBlock[] blocks); public abstract boolean setComponent(final PlotArea plotworld, final PlotId plotid, final String component, final PlotBlock[] blocks);
/* /*
* PLOT MERGING (return false if your generator does not support plot * PLOT MERGING (return false if your generator does not support plot
* merging) * merging)
*/ */
public abstract boolean createRoadEast(final PlotWorld plotworld, final Plot plot); public abstract boolean createRoadEast(final PlotArea plotworld, final Plot plot);
public abstract boolean createRoadSouth(final PlotWorld plotworld, final Plot plot); public abstract boolean createRoadSouth(final PlotArea plotworld, final Plot plot);
public abstract boolean createRoadSouthEast(final PlotWorld plotworld, final Plot plot); public abstract boolean createRoadSouthEast(final PlotArea plotworld, final Plot plot);
public abstract boolean removeRoadEast(final PlotWorld plotworld, final Plot plot); public abstract boolean removeRoadEast(final PlotArea plotworld, final Plot plot);
public abstract boolean removeRoadSouth(final PlotWorld plotworld, final Plot plot); public abstract boolean removeRoadSouth(final PlotArea plotworld, final Plot plot);
public abstract boolean removeRoadSouthEast(final PlotWorld plotworld, final Plot plot); public abstract boolean removeRoadSouthEast(final PlotArea plotworld, final Plot plot);
public abstract boolean startPlotMerge(final PlotWorld plotworld, final ArrayList<PlotId> plotIds); public abstract boolean startPlotMerge(final PlotArea plotworld, final ArrayList<PlotId> plotIds);
public abstract boolean startPlotUnlink(final PlotWorld plotworld, final ArrayList<PlotId> plotIds); public abstract boolean startPlotUnlink(final PlotArea plotworld, final ArrayList<PlotId> plotIds);
public abstract boolean finishPlotMerge(final PlotWorld plotworld, final ArrayList<PlotId> plotIds); public abstract boolean finishPlotMerge(final PlotArea plotworld, final ArrayList<PlotId> plotIds);
public abstract boolean finishPlotUnlink(final PlotWorld plotworld, final ArrayList<PlotId> plotIds); public abstract boolean finishPlotUnlink(final PlotArea plotworld, final ArrayList<PlotId> plotIds);
public void exportTemplate(final PlotWorld plotworld) throws IOException { public void exportTemplate(final PlotArea plotworld) throws IOException {
final HashSet<FileBytes> files = new HashSet<>( final HashSet<FileBytes> files = new HashSet<>(
Collections.singletonList(new FileBytes("templates/" + "tmp-data.yml", Template.getBytes(plotworld)))); Collections.singletonList(new FileBytes("templates/" + "tmp-data.yml", Template.getBytes(plotworld))));
Template.zipAll(plotworld.worldname, files); Template.zipAll(plotworld.worldname, files);

View File

@ -1,18 +1,26 @@
package com.intellectualcrafters.plot.object; package com.intellectualcrafters.plot.object;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.commands.RequiredType; import com.intellectualcrafters.plot.commands.RequiredType;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.util.*; import com.intellectualcrafters.plot.util.CmdConfirm;
import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.ExpireManager;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.PlotGamemode;
import com.intellectualcrafters.plot.util.PlotWeather;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandCaller; import com.plotsquared.general.commands.CommandCaller;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
/** /**
* The PlotPlayer class<br> * The PlotPlayer class<br>
* - Can cast to: BukkitPlayer / SpongePlayer, which are the current implementations<br> * - Can cast to: BukkitPlayer / SpongePlayer, which are the current implementations<br>
@ -63,16 +71,25 @@ public abstract class PlotPlayer implements CommandCaller {
/** /**
* Get the metadata for a key * Get the metadata for a key
* @param <T>
* @param key * @param key
* @return * @return
*/ */
public Object getMeta(final String key) { public <T> T getMeta(final String key) {
if (meta != null) { if (meta != null) {
return meta.get(key); return (T) meta.get(key);
} }
return null; return null;
} }
public <T> T getMeta(final String key, T def) {
if (meta != null) {
T value = (T) meta.get(key);
return value == null ? def : value;
}
return def;
}
/** /**
* Delete the metadata for a key<br> * Delete the metadata for a key<br>
* - metadata is session only * - metadata is session only
@ -108,7 +125,7 @@ public abstract class PlotPlayer implements CommandCaller {
* @return number of allowed plots within the scope (globally, or in the player's current world as defined in the settings.yml) * @return number of allowed plots within the scope (globally, or in the player's current world as defined in the settings.yml)
*/ */
public int getAllowedPlots() { public int getAllowedPlots() {
return MainUtil.getAllowedPlots(this); return Permissions.hasPermissionRange(this, "plots.plot", Settings.MAX_PLOTS);
} }
/** /**
@ -120,7 +137,26 @@ public abstract class PlotPlayer implements CommandCaller {
* @return number of plots within the scope (globally, or in the player's current world as defined in the settings.yml) * @return number of plots within the scope (globally, or in the player's current world as defined in the settings.yml)
*/ */
public int getPlotCount() { public int getPlotCount() {
return MainUtil.getPlayerPlotCount(this); if (!Settings.GLOBAL_LIMIT) {
return getPlotCount(getLocation().getWorld());
}
final AtomicInteger count = new AtomicInteger(0);
final UUID uuid = getUUID();
PS.get().foreachPlotArea(new RunnableVal<PlotArea>() {
@Override
public void run(PlotArea value) {
if (!Settings.DONE_COUNTS_TOWARDS_LIMIT) {
for (Plot plot : value.getPlotsAbs(uuid)) {
if (!plot.getFlags().containsKey("done")) {
count.incrementAndGet();
}
}
} else {
count.addAndGet(value.getPlotsAbs(uuid).size());
}
}
});
return count.get();
} }
/** /**
@ -129,7 +165,20 @@ public abstract class PlotPlayer implements CommandCaller {
* @return * @return
*/ */
public int getPlotCount(final String world) { public int getPlotCount(final String world) {
return MainUtil.getPlayerPlotCount(world, this); final UUID uuid = getUUID();
int count = 0;
for (PlotArea area : PS.get().getPlotAreas(world)) {
if (!Settings.DONE_COUNTS_TOWARDS_LIMIT) {
for (Plot plot : area.getPlotsAbs(uuid)) {
if (!plot.getFlags().containsKey("done")) {
count++;
}
}
} else {
count += area.getPlotsAbs(uuid).size();
}
}
return count;
} }
/** /**
@ -143,11 +192,15 @@ public abstract class PlotPlayer implements CommandCaller {
} }
/** /**
* Return the PlotWorld the player is currently in, or null * Return the PlotArea the player is currently in, or null
* @return * @return
*/ */
public PlotWorld getPlotWorld() { public PlotArea getPlotAreaAbs() {
return PS.get().getPlotWorld(getLocation().getWorld()); return PS.get().getPlotAreaAbs(getLocation());
}
public PlotArea getApplicablePlotArea() {
return PS.get().getApplicablePlotArea(getLocation());
} }
@Override @Override
@ -323,18 +376,50 @@ public abstract class PlotPlayer implements CommandCaller {
EventUtil.manager.callLeave(this, plot); EventUtil.manager.callLeave(this, plot);
} }
if (Settings.DELETE_PLOTS_ON_BAN && isBanned()) { if (Settings.DELETE_PLOTS_ON_BAN && isBanned()) {
for (final Plot owned : PS.get().getPlotsInWorld(getName())) { for (final Plot owned : getPlots()) {
owned.deletePlot(null); owned.deletePlot(null);
PS.debug(String.format("&cPlot &6%s &cwas deleted + cleared due to &6%s&c getting banned", plot.getId(), getName())); PS.debug(String.format("&cPlot &6%s &cwas deleted + cleared due to &6%s&c getting banned", plot.getId(), getName()));
} }
} }
String name = getName(); String name = getName();
ExpireManager.dates.put(getUUID(), System.currentTimeMillis()); ExpireManager.dates.put(getUUID(), System.currentTimeMillis());
SetupUtils.setupMap.remove(name);
CmdConfirm.removePending(name); CmdConfirm.removePending(name);
UUIDHandler.getPlayers().remove(name); UUIDHandler.getPlayers().remove(name);
PS.get().IMP.unregister(this); PS.get().IMP.unregister(this);
} }
public int getPlayerClusterCount(final String world) {
final UUID uuid = getUUID();
int count = 0;
for (final PlotCluster cluster : PS.get().getClusters(world)) {
if (uuid.equals(cluster.owner)) {
count += cluster.getArea();
}
}
return count;
}
public int getPlayerClusterCount() {
final AtomicInteger count = new AtomicInteger();
PS.get().foreachPlotArea(new RunnableVal<PlotArea>() {
@Override
public void run(PlotArea value) {
count.addAndGet(value.getClusters().size());
}
});
return count.get();
}
public Set<Plot> getPlots(String world) {
UUID uuid = getUUID();
HashSet<Plot> plots = new HashSet<>();
for (Plot plot : PS.get().getPlots(world)) {
if (plot.isOwner(uuid)) {
plots.add(plot);
}
}
return plots;
}
public void populatePersistentMetaMap() { public void populatePersistentMetaMap() {
DBFunc.dbManager.getPersistentMeta(this); DBFunc.dbManager.getPersistentMeta(this);

View File

@ -148,8 +148,8 @@ public class PlotSettings {
this.alias = alias; this.alias = alias;
} }
public String getJoinMessage(String world) { public String getJoinMessage(PlotArea area) {
final Flag greeting = FlagManager.getSettingFlag(world, this, "greeting"); final Flag greeting = FlagManager.getSettingFlag(area, this, "greeting");
if (greeting != null) { if (greeting != null) {
return greeting.getValueString(); return greeting.getValueString();
} }
@ -161,8 +161,8 @@ public class PlotSettings {
* *
* @return Farewell flag * @return Farewell flag
*/ */
public String getLeaveMessage(String world) { public String getLeaveMessage(PlotArea area) {
final Flag farewell = FlagManager.getSettingFlag(world, this, "farewell"); final Flag farewell = FlagManager.getSettingFlag(area, this, "farewell");
if (farewell != null) { if (farewell != null) {
return farewell.getValueString(); return farewell.getValueString();
} }

View File

@ -1,290 +0,0 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// 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.object;
import com.intellectualcrafters.configuration.ConfigurationSection;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.Configuration;
import com.intellectualcrafters.plot.config.ConfigurationNode;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.PlotGamemode;
import com.intellectualcrafters.plot.util.StringMan;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
/**
* @author Jesse Boyd
*/
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;
public final static boolean SCHEMATIC_CLAIM_SPECIFY_DEFAULT = false;
public final static boolean SCHEMATIC_ON_CLAIM_DEFAULT = false;
public final static String SCHEMATIC_FILE_DEFAULT = "null";
public final static List<String> SCHEMATICS_DEFAULT = null;
public final static boolean USE_ECONOMY_DEFAULT = false;
public final static double PLOT_PRICE_DEFAULT = 100;
public final static double MERGE_PRICE_DEFAULT = 100;
public final static double SELL_PRICE_DEFAULT = 75;
public final static boolean SPAWN_EGGS_DEFAULT = false;
public final static boolean SPAWN_CUSTOM_DEFAULT = true;
public final static boolean SPAWN_BREEDING_DEFAULT = false;
public final static boolean WORLD_BORDER_DEFAULT = false;
public final static int MAX_PLOT_MEMBERS_DEFAULT = 128;
public final static int MAX_BUILD_HEIGHT_DEFAULT = 256;
public final static int MIN_BUILD_HEIGHT_DEFAULT = 1;
public final static PlotGamemode GAMEMODE_DEFAULT = PlotGamemode.CREATIVE;
public final String worldname;
public int MAX_PLOT_MEMBERS;
public boolean AUTO_MERGE;
public boolean ALLOW_SIGNS;
public boolean MOB_SPAWNING;
public String PLOT_BIOME;
public boolean PLOT_CHAT;
public boolean SCHEMATIC_CLAIM_SPECIFY = false;
public boolean SCHEMATIC_ON_CLAIM;
public String SCHEMATIC_FILE;
public List<String> SCHEMATICS;
public HashMap<String, Flag> DEFAULT_FLAGS;
public boolean USE_ECONOMY;
public double PLOT_PRICE;
public double MERGE_PRICE;
public double SELL_PRICE;
public boolean SPAWN_EGGS;
public boolean SPAWN_CUSTOM;
public boolean SPAWN_BREEDING;
public boolean WORLD_BORDER;
public int TYPE = 0;
public int TERRAIN = 0;
public boolean HOME_ALLOW_NONMEMBER;
public PlotLoc DEFAULT_HOME;
public int MAX_BUILD_HEIGHT;
public int MIN_BUILD_HEIGHT;
public PlotGamemode GAMEMODE = PlotGamemode.CREATIVE;
public PlotWorld(final String worldname) {
this.worldname = worldname;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final PlotWorld plotworld = (PlotWorld) obj;
if (this.worldname.equals(plotworld.worldname)) {
return true;
}
final ConfigurationSection section = PS.get().config.getConfigurationSection("worlds");
for (final ConfigurationNode setting : plotworld.getSettingNodes()) {
final Object constant = section.get(plotworld.worldname + "." + setting.getConstant());
if (constant == null) {
return false;
}
if (!constant.equals(section.get(worldname + "." + setting.getConstant()))) {
return false;
}
}
return true;
}
public boolean isCompatible(PlotWorld plotworld) {
return equals(plotworld);
}
/**
* When a world is created, the following method will be called for each
*
* @param config Configuration Section
*/
public void loadDefaultConfiguration(final ConfigurationSection config) {
if (config.contains("generator.terrain")) {
TERRAIN = config.getInt("generator.terrain");
TYPE = config.getInt("generator.type");
}
MOB_SPAWNING = config.getBoolean("natural_mob_spawning");
AUTO_MERGE = config.getBoolean("plot.auto_merge");
MAX_PLOT_MEMBERS = config.getInt("limits.max-members");
ALLOW_SIGNS = config.getBoolean("plot.create_signs");
PLOT_BIOME = Configuration.BIOME.parseString(config.getString("plot.biome"));
SCHEMATIC_ON_CLAIM = config.getBoolean("schematic.on_claim");
SCHEMATIC_FILE = config.getString("schematic.file");
SCHEMATIC_CLAIM_SPECIFY = config.getBoolean("schematic.specify_on_claim");
SCHEMATICS = config.getStringList("schematic.schematics");
USE_ECONOMY = config.getBoolean("economy.use") && (EconHandler.manager != null);
PLOT_PRICE = config.getDouble("economy.prices.claim");
MERGE_PRICE = config.getDouble("economy.prices.merge");
SELL_PRICE = config.getDouble("economy.prices.sell");
PLOT_CHAT = config.getBoolean("chat.enabled");
WORLD_BORDER = config.getBoolean("world.border");
MAX_BUILD_HEIGHT = config.getInt("world.max_height");
MIN_BUILD_HEIGHT = config.getInt("min.max_height");
switch (config.getString("world.gamemode").toLowerCase()) {
case "survival":
case "s":
case "0":
GAMEMODE = PlotGamemode.SURVIVAL;
break;
case "creative":
case "c":
case "1":
GAMEMODE = PlotGamemode.CREATIVE;
break;
case "adventure":
case "a":
case "2":
GAMEMODE = PlotGamemode.ADVENTURE;
break;
case "spectator":
case "3":
GAMEMODE = PlotGamemode.SPECTATOR;
break;
default:
PS.debug("&cInvalid gamemode set for: " + worldname);
break;
}
HOME_ALLOW_NONMEMBER = config.getBoolean("home.allow-nonmembers");
final String homeDefault = config.getString("home.default");
if (homeDefault.equalsIgnoreCase("side")) {
DEFAULT_HOME = null;
} else if (homeDefault.equalsIgnoreCase("center")) {
DEFAULT_HOME = new PlotLoc(Integer.MAX_VALUE, Integer.MAX_VALUE);
} else {
try {
final String[] split = homeDefault.split(",");
DEFAULT_HOME = new PlotLoc(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
} catch (final Exception e) {
DEFAULT_HOME = null;
}
}
List<String> flags = config.getStringList("flags.default");
if ((flags == null) || (flags.size() == 0)) {
flags = config.getStringList("flags");
if ((flags == null) || (flags.size() == 0)) {
flags = new ArrayList<>();
final ConfigurationSection section = config.getConfigurationSection("flags");
final Set<String> keys = section.getKeys(false);
for (final String key : keys) {
if (!key.equals("default")) {
flags.add(key + ";" + section.get(key));
}
}
}
}
try {
DEFAULT_FLAGS = FlagManager.parseFlags(flags);
} catch (final Exception e) {
e.printStackTrace();
PS.debug("&cInvalid default flags for " + worldname + ": " + StringMan.join(flags, ","));
DEFAULT_FLAGS = new HashMap<>();
}
SPAWN_EGGS = config.getBoolean("event.spawn.egg");
SPAWN_CUSTOM = config.getBoolean("event.spawn.custom");
SPAWN_BREEDING = config.getBoolean("event.spawn.breeding");
loadConfiguration(config);
}
public abstract void loadConfiguration(final ConfigurationSection config);
/**
* Saving core plotworld settings
*
* @param config Configuration Section
*/
public void saveConfiguration(final ConfigurationSection config) {
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);
options.put("schematic.on_claim", PlotWorld.SCHEMATIC_ON_CLAIM_DEFAULT);
options.put("schematic.file", PlotWorld.SCHEMATIC_FILE_DEFAULT);
options.put("schematic.specify_on_claim", PlotWorld.SCHEMATIC_CLAIM_SPECIFY_DEFAULT);
options.put("schematic.schematics", PlotWorld.SCHEMATICS_DEFAULT);
options.put("economy.use", PlotWorld.USE_ECONOMY_DEFAULT);
options.put("economy.prices.claim", PlotWorld.PLOT_PRICE_DEFAULT);
options.put("economy.prices.merge", PlotWorld.MERGE_PRICE_DEFAULT);
options.put("economy.prices.sell", PlotWorld.SELL_PRICE_DEFAULT);
options.put("chat.enabled", PlotWorld.PLOT_CHAT_DEFAULT);
options.put("flags.default", null);
options.put("event.spawn.egg", PlotWorld.SPAWN_EGGS_DEFAULT);
options.put("event.spawn.custom", PlotWorld.SPAWN_CUSTOM_DEFAULT);
options.put("event.spawn.breeding", PlotWorld.SPAWN_BREEDING_DEFAULT);
options.put("world.border", PlotWorld.WORLD_BORDER_DEFAULT);
options.put("limits.max-members", PlotWorld.MAX_PLOT_MEMBERS_DEFAULT);
options.put("home.default", "side");
options.put("home.allow-nonmembers", false);
options.put("world.max_height", PlotWorld.MAX_BUILD_HEIGHT_DEFAULT);
options.put("world.min_height", PlotWorld.MIN_BUILD_HEIGHT_DEFAULT);
options.put("world.gamemode", PlotWorld.GAMEMODE_DEFAULT.name().toLowerCase());
if (Settings.ENABLE_CLUSTERS && (TYPE != 0)) {
options.put("generator.terrain", TERRAIN);
options.put("generator.type", TYPE);
}
final ConfigurationNode[] settings = getSettingNodes();
/*
* Saving generator specific settings
*/
for (final ConfigurationNode setting : settings) {
options.put(setting.getConstant(), setting.getValue());
}
for (final String option : options.keySet()) {
if (!config.contains(option)) {
config.set(option, options.get(option));
}
}
if (!config.contains("flags")) {
config.set("flags.use", "63,64,68,69,71,77,96,143,167,193,194,195,196,197,77,143,69,70,72,147,148,107,183,184,185,186,187,132");
}
}
@Override
public String toString() {
return worldname;
}
/**
* Used for the <b>/plot setup</b> command Return null if you do not want to support this feature
*
* @return ConfigurationNode[]
*/
public abstract ConfigurationNode[] getSettingNodes();
}

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