mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-23 05:36:45 +01:00
playerfunctions
This commit is contained in:
parent
0d382ac9c3
commit
d381f0ff6a
@ -273,8 +273,8 @@ public class PlotHelper {
|
||||
break;
|
||||
}
|
||||
count++;
|
||||
final PlotId bot = PlayerFunctions.getBottomPlot(world, plot).id;
|
||||
final PlotId top = PlayerFunctions.getTopPlot(world, plot).id;
|
||||
final PlotId bot = getBottomPlot(world, plot).id;
|
||||
final PlotId top = getTopPlot(world, plot).id;
|
||||
plots = getPlotSelectionIds(new PlotId(bot.x, bot.y - 1), new PlotId(top.x, top.y));
|
||||
if (ownsPlots(world, plots, uuid, 0)) {
|
||||
final boolean result = mergePlots(world, plots, true);
|
||||
@ -320,11 +320,11 @@ public class PlotHelper {
|
||||
if ((myplot == null) || !myplot.hasOwner() || !(myplot.getOwner().equals(uuid))) {
|
||||
return false;
|
||||
}
|
||||
final PlotId top = PlayerFunctions.getTopPlot(world, myplot).id;
|
||||
final PlotId top = getTopPlot(world, myplot).id;
|
||||
if (((top.x > id_max.x) && (dir != 1)) || ((top.y > id_max.y) && (dir != 2))) {
|
||||
return false;
|
||||
}
|
||||
final PlotId bot = PlayerFunctions.getBottomPlot(world, myplot).id;
|
||||
final PlotId bot = getBottomPlot(world, myplot).id;
|
||||
if (((bot.x < id_min.x) && (dir != 3)) || ((bot.y < id_min.y) && (dir != 0))) {
|
||||
return false;
|
||||
}
|
||||
@ -398,7 +398,7 @@ public class PlotHelper {
|
||||
* @param requester
|
||||
* @param plot
|
||||
*/
|
||||
public static boolean clear(final UUID uuid, final Plot plot, final boolean isDelete, final Runnable whenDone) {
|
||||
public static boolean clearAsPlayer(final Plot plot, final boolean isDelete, final Runnable whenDone) {
|
||||
if (runners.containsKey(plot)) {
|
||||
return false;
|
||||
}
|
||||
@ -665,7 +665,7 @@ public class PlotHelper {
|
||||
public static Location getPlotTopLoc(final String world, PlotId id) {
|
||||
final Plot plot = PlotSquared.getPlots(world).get(id);
|
||||
if (plot != null) {
|
||||
id = PlayerFunctions.getTopPlot(world, plot).id;
|
||||
id = getTopPlot(world, plot).id;
|
||||
}
|
||||
final PlotWorld plotworld = PlotSquared.getWorldSettings(world);
|
||||
final PlotManager manager = PlotSquared.getPlotManager(world);
|
||||
@ -684,7 +684,7 @@ public class PlotHelper {
|
||||
public static Location getPlotBottomLoc(final String world, PlotId id) {
|
||||
final Plot plot = PlotSquared.getPlots(world).get(id);
|
||||
if (plot != null) {
|
||||
id = PlayerFunctions.getBottomPlot(world, plot).id;
|
||||
id = getBottomPlot(world, plot).id;
|
||||
}
|
||||
final PlotWorld plotworld = PlotSquared.getWorldSettings(world);
|
||||
final PlotManager manager = PlotSquared.getPlotManager(world);
|
||||
@ -713,8 +713,8 @@ public class PlotHelper {
|
||||
if (currentPlot.owner == null) {
|
||||
return false;
|
||||
}
|
||||
final Plot pos1 = PlayerFunctions.getBottomPlot(world, currentPlot);
|
||||
final Plot pos2 = PlayerFunctions.getTopPlot(world, currentPlot);
|
||||
final Plot pos1 = getBottomPlot(world, currentPlot);
|
||||
final Plot pos2 = getTopPlot(world, currentPlot);
|
||||
final PlotId size = PlotHelper.getSize(world, currentPlot);
|
||||
if (!PlotHelper.isUnowned(world, newPlot, new PlotId((newPlot.x + size.x) - 1, (newPlot.y + size.y) - 1))) {
|
||||
return false;
|
||||
@ -741,23 +741,46 @@ public class PlotHelper {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static Plot getBottomPlot(final String world, final Plot plot) {
|
||||
if (plot.settings.getMerged(0)) {
|
||||
final Plot p = PlotSquared.getPlots(world).get(new PlotId(plot.id.x, plot.id.y - 1));
|
||||
if (p == null) {
|
||||
return plot;
|
||||
}
|
||||
return getBottomPlot(world, p);
|
||||
}
|
||||
if (plot.settings.getMerged(3)) {
|
||||
final Plot p = PlotSquared.getPlots(world).get(new PlotId(plot.id.x - 1, plot.id.y));
|
||||
if (p == null) {
|
||||
return plot;
|
||||
}
|
||||
return getBottomPlot(world, p);
|
||||
}
|
||||
return plot;
|
||||
}
|
||||
|
||||
public static Plot getTopPlot(final String world, final Plot plot) {
|
||||
if (plot.settings.getMerged(2)) {
|
||||
return getTopPlot(world, PlotSquared.getPlots(world).get(new PlotId(plot.id.x, plot.id.y + 1)));
|
||||
}
|
||||
if (plot.settings.getMerged(1)) {
|
||||
return getTopPlot(world, PlotSquared.getPlots(world).get(new PlotId(plot.id.x + 1, plot.id.y)));
|
||||
}
|
||||
return plot;
|
||||
}
|
||||
|
||||
public static PlotId getSize(final String world, final Plot plot) {
|
||||
final PlotSettings settings = plot.settings;
|
||||
if (!settings.isMerged()) {
|
||||
return new PlotId(1, 1);
|
||||
}
|
||||
final Plot top = PlayerFunctions.getTopPlot(world, plot);
|
||||
final Plot bot = PlayerFunctions.getBottomPlot(world, plot);
|
||||
final Plot top = getTopPlot(world, plot);
|
||||
final Plot bot = getBottomPlot(world, plot);
|
||||
return new PlotId((top.id.x - bot.id.x) + 1, (top.id.y - bot.id.y) + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the plot from the main class
|
||||
*
|
||||
* @param world
|
||||
* @param id
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Plot getPlot(final String world, final PlotId id) {
|
||||
if (id == null) {
|
||||
@ -769,21 +792,40 @@ public class PlotHelper {
|
||||
return new Plot(id, null, new ArrayList<UUID>(), new ArrayList<UUID>(), world);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the plot at a given location
|
||||
*
|
||||
* Returns the plot at a location (mega plots are not considered, all plots are treated as small plots)
|
||||
* @param loc
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Plot getCurrentPlot(final Location loc) {
|
||||
final PlotId id = PlayerFunctions.getPlot(loc);
|
||||
if (id == null) {
|
||||
public static PlotId getPlotAbs(final Location loc) {
|
||||
final String world = loc.getWorld();
|
||||
final PlotManager manager = PlotSquared.getPlotManager(world);
|
||||
if (manager == null) {
|
||||
return null;
|
||||
}
|
||||
if (PlotSquared.getPlots(loc.getWorld()).containsKey(id)) {
|
||||
return PlotSquared.getPlots(loc.getWorld()).get(id);
|
||||
final PlotWorld plotworld = PlotSquared.getWorldSettings(world);
|
||||
return manager.getPlotIdAbs(plotworld, loc.getX(), loc.getY(), loc.getZ());
|
||||
}
|
||||
return new Plot(id, null, new ArrayList<UUID>(), new ArrayList<UUID>(), loc.getWorld());
|
||||
|
||||
/**
|
||||
* Returns the plot id at a location (mega plots are considered)
|
||||
* @param loc
|
||||
* @return
|
||||
*/
|
||||
public static PlotId getPlot(final Location loc) {
|
||||
final String world = loc.getWorld();
|
||||
final PlotManager manager = PlotSquared.getPlotManager(world);
|
||||
if (manager == null) {
|
||||
return null;
|
||||
}
|
||||
final PlotWorld plotworld = PlotSquared.getWorldSettings(world);
|
||||
final PlotId id = manager.getPlotId(plotworld, loc.getX(), loc.getY(), loc.getZ());
|
||||
if ((id != null) && (plotworld.TYPE == 2)) {
|
||||
if (ClusterManager.getCluster(world, id) == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
@ -25,32 +25,25 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.ChatPaginator;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
|
||||
import com.intellectualcrafters.plot.BukkitMain;
|
||||
import com.intellectualcrafters.plot.PlotSquared;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotManager;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.AChunkManager;
|
||||
import com.intellectualcrafters.plot.util.ClusterManager;
|
||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
||||
|
||||
/**
|
||||
* Functions involving players, plots and locations.
|
||||
*
|
||||
* @author Citymonstret
|
||||
*/
|
||||
@SuppressWarnings("javadoc")
|
||||
public class PlayerFunctions {
|
||||
/**
|
||||
* Clear a plot. Use null player if no player is present
|
||||
@ -60,46 +53,18 @@ public class PlayerFunctions {
|
||||
* @param isDelete
|
||||
*/
|
||||
public static void clear(final Player player, final String world, final Plot plot, final boolean isDelete) {
|
||||
if (runners.containsKey(plot)) {
|
||||
PlayerFunctions.sendMessage(null, C.WAIT_FOR_TIMER);
|
||||
return;
|
||||
}
|
||||
final PlotManager manager = PlotSquared.getPlotManager(world);
|
||||
final Location pos1 = PlotHelper.getPlotBottomLoc(world, plot.id).add(1, 0, 1);
|
||||
final int prime = 31;
|
||||
int h = 1;
|
||||
h = (prime * h) + pos1.getX();
|
||||
h = (prime * h) + pos1.getZ();
|
||||
state = h;
|
||||
final long start = System.currentTimeMillis();
|
||||
final Location location = PlotHelper.getPlotHomeDefault(plot);
|
||||
final PlotWorld plotworld = PlotSquared.getWorldSettings(world);
|
||||
runners.put(plot, 1);
|
||||
if (plotworld.TERRAIN != 0) {
|
||||
final Location pos2 = PlotHelper.getPlotTopLoc(world, plot.id);
|
||||
AChunkManager.manager.regenerateRegion(pos1, pos2, new Runnable() {
|
||||
Runnable whenDone = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if ((player != null) && player.isOnline()) {
|
||||
PlayerFunctions.sendMessage(player, C.CLEARING_DONE.s().replaceAll("%time%", "" + ((System.currentTimeMillis() - start))));
|
||||
PlayerFunctions.sendMessage(player, C.CLEARING_DONE, "" + (System.currentTimeMillis() - start));
|
||||
}
|
||||
runners.remove(plot);
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
final Runnable run = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PlotHelper.setBiome(world, plot, Biome.FOREST);
|
||||
runners.remove(plot);
|
||||
if ((player != null) && player.isOnline()) {
|
||||
PlayerFunctions.sendMessage(player, C.CLEARING_DONE.s().replaceAll("%time%", "" + ((System.currentTimeMillis() - start))));
|
||||
}
|
||||
update(location);
|
||||
}
|
||||
};
|
||||
manager.clearPlot(plotworld, plot, isDelete, run);
|
||||
if (!PlotHelper.clearAsPlayer(plot, isDelete, whenDone)) {
|
||||
PlayerFunctions.sendMessage(null, C.WAIT_FOR_TIMER);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -125,7 +90,7 @@ public class PlayerFunctions {
|
||||
PlayerFunctions.sendMessage(plr, C.REMOVED_BALANCE, cost + "");
|
||||
}
|
||||
}
|
||||
return mergePlots(world, plotIds, true);
|
||||
return PlotHelper.mergePlots(world, plotIds, true);
|
||||
}
|
||||
|
||||
public static String getPlayerName(final UUID uuid) {
|
||||
@ -152,10 +117,10 @@ public class PlayerFunctions {
|
||||
final Plot plot1 = PlotSquared.getPlots(world).get(pos1);
|
||||
final Plot plot2 = PlotSquared.getPlots(world).get(pos2);
|
||||
if (plot1 != null) {
|
||||
pos1 = getBottomPlot(world, plot1).id;
|
||||
pos1 = PlotHelper.getBottomPlot(world, plot1).id;
|
||||
}
|
||||
if (plot2 != null) {
|
||||
pos2 = getTopPlot(world, plot2).id;
|
||||
pos2 = PlotHelper.getTopPlot(world, plot2).id;
|
||||
}
|
||||
final ArrayList<PlotId> myplots = new ArrayList<>();
|
||||
for (int x = pos1.x; x <= pos2.x; x++) {
|
||||
@ -166,74 +131,6 @@ public class PlayerFunctions {
|
||||
return myplots;
|
||||
}
|
||||
|
||||
public static Plot getBottomPlot(final String world, final Plot plot) {
|
||||
if (plot.settings.getMerged(0)) {
|
||||
final Plot p = PlotSquared.getPlots(world).get(new PlotId(plot.id.x, plot.id.y - 1));
|
||||
if (p == null) {
|
||||
return plot;
|
||||
}
|
||||
return getBottomPlot(world, p);
|
||||
}
|
||||
if (plot.settings.getMerged(3)) {
|
||||
final Plot p = PlotSquared.getPlots(world).get(new PlotId(plot.id.x - 1, plot.id.y));
|
||||
if (p == null) {
|
||||
return plot;
|
||||
}
|
||||
return getBottomPlot(world, p);
|
||||
}
|
||||
return plot;
|
||||
}
|
||||
|
||||
public static Plot getTopPlot(final String world, final Plot plot) {
|
||||
if (plot.settings.getMerged(2)) {
|
||||
return getTopPlot(world, PlotSquared.getPlots(world).get(new PlotId(plot.id.x, plot.id.y + 1)));
|
||||
}
|
||||
if (plot.settings.getMerged(1)) {
|
||||
return getTopPlot(world, PlotSquared.getPlots(world).get(new PlotId(plot.id.x + 1, plot.id.y)));
|
||||
}
|
||||
return plot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the plot at a location (mega plots are not considered, all plots are treated as small plots)
|
||||
*
|
||||
* @param loc
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static PlotId getPlotAbs(final Location loc) {
|
||||
final String world = loc.getWorld();
|
||||
final PlotManager manager = PlotSquared.getPlotManager(world);
|
||||
if (manager == null) {
|
||||
return null;
|
||||
}
|
||||
final PlotWorld plotworld = PlotSquared.getWorldSettings(world);
|
||||
return manager.getPlotIdAbs(plotworld, loc.getX(), loc.getY(), loc.getZ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the plot id at a location (mega plots are considered)
|
||||
*
|
||||
* @param loc
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static PlotId getPlot(final Location loc) {
|
||||
final String world = loc.getWorld();
|
||||
final PlotManager manager = PlotSquared.getPlotManager(world);
|
||||
if (manager == null) {
|
||||
return null;
|
||||
}
|
||||
final PlotWorld plotworld = PlotSquared.getWorldSettings(world);
|
||||
final PlotId id = manager.getPlotId(plotworld, loc.getX(), loc.getY(), loc.getZ());
|
||||
if ((id != null) && (plotworld.TYPE == 2)) {
|
||||
if (ClusterManager.getCluster(world, id) == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the plot a player is currently in.
|
||||
*
|
||||
@ -245,7 +142,7 @@ public class PlayerFunctions {
|
||||
if (!PlotSquared.isPlotWorld(player.getWorld().getName())) {
|
||||
return null;
|
||||
}
|
||||
final PlotId id = getPlot(BukkitUtil.getLocation(player));
|
||||
final PlotId id = PlotHelper.getPlot(BukkitUtil.getLocation(player));
|
||||
final String world = player.getWorld().getName();
|
||||
if (id == null) {
|
||||
return null;
|
||||
@ -256,18 +153,6 @@ public class PlayerFunctions {
|
||||
return new Plot(id, null, new ArrayList<UUID>(), new ArrayList<UUID>(), world);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a given plot with another instance
|
||||
*
|
||||
* @param plot
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
public static void set(final Plot plot) {
|
||||
PlotSquared.updatePlot(plot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plots for a player
|
||||
*
|
||||
@ -312,16 +197,6 @@ public class PlayerFunctions {
|
||||
return BukkitMain.hasPermissionRange(p, "plots.plot", Settings.MAX_PLOTS);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PlotSquared.getPlots();
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
public static Set<Plot> getPlots() {
|
||||
return PlotSquared.getPlots();
|
||||
}
|
||||
|
||||
/**
|
||||
* \\previous\\
|
||||
*
|
||||
|
@ -8,6 +8,7 @@ import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
|
Loading…
Reference in New Issue
Block a user