use of com.plotsquared.core.plot.PlotId in project PlotSquared by IntellectualSites.
the class SinglePlotArea method getOwnedPlot.
@Nullable
@Override
public Plot getOwnedPlot(@NonNull final Location location) {
PlotId pid = PlotId.fromStringOrNull(location.getWorldName());
Plot plot = pid == null ? null : this.plots.get(pid);
return plot == null ? null : plot.getBasePlot(false);
}
use of com.plotsquared.core.plot.PlotId in project PlotSquared by IntellectualSites.
the class SQLManager method validateAllPlots.
@SuppressWarnings({ "unchecked", "unused" })
@Override
public void validateAllPlots(Set<Plot> toValidate) {
if (!isValid()) {
reconnect();
}
LOGGER.info("All DB transactions during this session are being validated (This may take a while if corrections need to be made)");
commit();
while (true) {
if (!sendBatch()) {
break;
}
}
try {
if (this.connection.getAutoCommit()) {
this.connection.setAutoCommit(false);
}
} catch (SQLException e) {
e.printStackTrace();
}
HashMap<String, HashMap<PlotId, Plot>> database = getPlots();
ArrayList<Plot> toCreate = new ArrayList<>();
for (Plot plot : toValidate) {
if (plot.temp == -1) {
continue;
}
if (plot.getArea() == null) {
LOGGER.error("CRITICAL ERROR IN VALIDATION TASK: {}", plot);
LOGGER.error("PLOT AREA CANNOT BE NULL! SKIPPING PLOT!");
LOGGER.info("Delete this entry from your database or set `database-purger: true` in the settings.yml");
continue;
}
if (database == null) {
LOGGER.error("CRITICAL ERROR IN VALIDATION TASK!");
LOGGER.error("DATABASE VARIABLE CANNOT BE NULL! NOW ENDING VALIDATION!");
break;
}
HashMap<PlotId, Plot> worldPlots = database.get(plot.getArea().toString());
if (worldPlots == null) {
toCreate.add(plot);
continue;
}
Plot dataPlot = worldPlots.remove(plot.getId());
if (dataPlot == null) {
toCreate.add(plot);
continue;
}
// owner
if (!plot.getOwnerAbs().equals(dataPlot.getOwnerAbs())) {
setOwner(plot, plot.getOwnerAbs());
}
// trusted
if (!plot.getTrusted().equals(dataPlot.getTrusted())) {
HashSet<UUID> toAdd = (HashSet<UUID>) plot.getTrusted().clone();
HashSet<UUID> toRemove = (HashSet<UUID>) dataPlot.getTrusted().clone();
toRemove.removeAll(plot.getTrusted());
toAdd.removeAll(dataPlot.getTrusted());
if (!toRemove.isEmpty()) {
for (UUID uuid : toRemove) {
removeTrusted(plot, uuid);
}
}
if (!toAdd.isEmpty()) {
for (UUID uuid : toAdd) {
setTrusted(plot, uuid);
}
}
}
if (!plot.getMembers().equals(dataPlot.getMembers())) {
HashSet<UUID> toAdd = (HashSet<UUID>) plot.getMembers().clone();
HashSet<UUID> toRemove = (HashSet<UUID>) dataPlot.getMembers().clone();
toRemove.removeAll(plot.getMembers());
toAdd.removeAll(dataPlot.getMembers());
if (!toRemove.isEmpty()) {
for (UUID uuid : toRemove) {
removeMember(plot, uuid);
}
}
if (!toAdd.isEmpty()) {
for (UUID uuid : toAdd) {
setMember(plot, uuid);
}
}
}
if (!plot.getDenied().equals(dataPlot.getDenied())) {
HashSet<UUID> toAdd = (HashSet<UUID>) plot.getDenied().clone();
HashSet<UUID> toRemove = (HashSet<UUID>) dataPlot.getDenied().clone();
toRemove.removeAll(plot.getDenied());
toAdd.removeAll(dataPlot.getDenied());
if (!toRemove.isEmpty()) {
for (UUID uuid : toRemove) {
removeDenied(plot, uuid);
}
}
if (!toAdd.isEmpty()) {
for (UUID uuid : toAdd) {
setDenied(plot, uuid);
}
}
}
boolean[] pm = plot.getMerged();
boolean[] dm = dataPlot.getMerged();
if (pm[0] != dm[0] || pm[1] != dm[1]) {
setMerged(dataPlot, plot.getMerged());
}
Set<PlotFlag<?, ?>> pf = plot.getFlags();
Set<PlotFlag<?, ?>> df = dataPlot.getFlags();
if (!pf.isEmpty() && !df.isEmpty()) {
if (pf.size() != df.size() || !StringMan.isEqual(StringMan.joinOrdered(pf, ","), StringMan.joinOrdered(df, ","))) {
// setFlags(plot, pf);
// TODO: Re-implement
}
}
}
for (Entry<String, HashMap<PlotId, Plot>> entry : database.entrySet()) {
HashMap<PlotId, Plot> map = entry.getValue();
if (!map.isEmpty()) {
for (Entry<PlotId, Plot> entry2 : map.entrySet()) {
// TODO implement this when sure safe"
}
}
}
commit();
}
use of com.plotsquared.core.plot.PlotId in project PlotSquared by IntellectualSites.
the class Purge method onCommand.
@Override
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
if (args.length == 0) {
sendUsage(player);
return false;
}
String world = null;
PlotArea area = null;
PlotId id = null;
UUID owner = null;
UUID added = null;
boolean clear = false;
boolean unknown = false;
for (String arg : args) {
String[] split = arg.split(":");
if (split.length != 2) {
sendUsage(player);
return false;
}
switch(split[0].toLowerCase()) {
case "world":
case "w":
world = split[1];
break;
case "area":
case "a":
area = this.plotAreaManager.getPlotAreaByString(split[1]);
if (area == null) {
player.sendMessage(TranslatableCaption.of("errors.not_valid_plot_world"), Template.of("value", split[1]));
return false;
}
break;
case "plotid":
case "id":
try {
id = PlotId.fromString(split[1]);
} catch (IllegalArgumentException ignored) {
player.sendMessage(TranslatableCaption.of("invalid.not_valid_plot_id"), Template.of("value", split[1]));
return false;
}
break;
case "owner":
case "o":
UUIDMapping ownerMapping = PlotSquared.get().getImpromptuUUIDPipeline().getImmediately(split[1]);
if (ownerMapping == null) {
player.sendMessage(TranslatableCaption.of("errors.invalid_player"), Template.of("value", split[1]));
return false;
}
owner = ownerMapping.getUuid();
break;
case "shared":
case "s":
UUIDMapping addedMapping = PlotSquared.get().getImpromptuUUIDPipeline().getImmediately(split[1]);
if (addedMapping == null) {
player.sendMessage(TranslatableCaption.of("errors.invalid_player"), Template.of("value", split[1]));
return false;
}
added = addedMapping.getUuid();
break;
case "clear":
case "c":
case "delete":
case "d":
case "del":
clear = Boolean.parseBoolean(split[1]);
break;
case "unknown":
case "?":
case "u":
unknown = Boolean.parseBoolean(split[1]);
break;
default:
sendUsage(player);
return false;
}
}
final HashSet<Plot> toDelete = new HashSet<>();
for (Plot plot : PlotQuery.newQuery().whereBasePlot()) {
if (world != null && !plot.getWorldName().equalsIgnoreCase(world)) {
continue;
}
if (area != null && !plot.getArea().equals(area)) {
continue;
}
if (id != null && !plot.getId().equals(id)) {
continue;
}
if (owner != null && !plot.isOwner(owner)) {
continue;
}
if (added != null && !plot.isAdded(added)) {
continue;
}
if (unknown) {
UUIDMapping uuidMapping = PlotSquared.get().getImpromptuUUIDPipeline().getImmediately(plot.getOwner());
if (uuidMapping != null) {
continue;
}
}
toDelete.addAll(plot.getConnectedPlots());
}
if (PlotSquared.get().plots_tmp != null) {
for (Entry<String, HashMap<PlotId, Plot>> entry : PlotSquared.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 (area != null && !plot.getArea().equals(area)) {
continue;
}
if (id != null && !plot.getId().equals(id)) {
continue;
}
if (owner != null && !plot.isOwner(owner)) {
continue;
}
if (added != null && !plot.isAdded(added)) {
continue;
}
if (unknown) {
UUIDMapping addedMapping = PlotSquared.get().getImpromptuUUIDPipeline().getImmediately(plot.getOwner());
if (addedMapping != null) {
continue;
}
}
toDelete.add(plot);
}
}
}
if (toDelete.isEmpty()) {
player.sendMessage(TranslatableCaption.of("invalid.found_no_plots"));
return false;
}
String cmd = "/plot purge " + StringMan.join(args, " ") + " (" + toDelete.size() + " plots)";
boolean finalClear = clear;
Runnable run = () -> {
LOGGER.info("Calculating plots to purge, please wait...");
HashSet<Integer> ids = new HashSet<>();
Iterator<Plot> iterator = toDelete.iterator();
AtomicBoolean cleared = new AtomicBoolean(true);
Runnable runasync = new Runnable() {
@Override
public void run() {
while (iterator.hasNext() && cleared.get()) {
cleared.set(false);
Plot plot = iterator.next();
if (plot.temp != Integer.MAX_VALUE) {
try {
ids.add(plot.temp);
if (finalClear) {
plot.getPlotModificationManager().clear(false, true, player, () -> {
LOGGER.info("Plot {} cleared by purge", plot.getId());
});
} else {
plot.getPlotModificationManager().removeSign();
}
plot.getArea().removePlot(plot.getId());
for (PlotPlayer<?> pp : plot.getPlayersInPlot()) {
Purge.this.plotListener.plotEntry(pp, plot);
}
} catch (NullPointerException e) {
LOGGER.error("NullPointer during purge detected. This is likely" + " because you are deleting a world that has been removed", e);
}
}
cleared.set(true);
}
if (iterator.hasNext()) {
TaskManager.runTaskAsync(this);
} else {
TaskManager.runTask(() -> {
DBFunc.purgeIds(ids);
player.sendMessage(TranslatableCaption.of("purge.purge_success"), Template.of("amount", ids.size() + "/" + toDelete.size()));
});
}
}
};
TaskManager.runTaskAsync(runasync);
};
if (hasConfirmation(player)) {
if (unknown) {
if (Settings.UUID.BACKGROUND_CACHING_ENABLED) {
player.sendMessage(TranslatableCaption.of("purge.confirm_purge_unknown_bg_enabled"));
} else {
player.sendMessage(TranslatableCaption.of("purge.confirm_purge_unknown_bg_disabled"));
}
}
CmdConfirm.addPending(player, cmd, run);
} else {
run.run();
}
return true;
}
use of com.plotsquared.core.plot.PlotId in project PlotSquared by IntellectualSites.
the class SquarePlotManager method getPlotId.
@Override
public PlotId getPlotId(int x, int y, int z) {
try {
x -= squarePlotWorld.ROAD_OFFSET_X;
z -= squarePlotWorld.ROAD_OFFSET_Z;
int size = squarePlotWorld.PLOT_WIDTH + squarePlotWorld.ROAD_WIDTH;
int pathWidthLower;
int end;
if (squarePlotWorld.ROAD_WIDTH == 0) {
pathWidthLower = -1;
end = squarePlotWorld.PLOT_WIDTH;
} else {
if ((squarePlotWorld.ROAD_WIDTH % 2) == 0) {
pathWidthLower = (squarePlotWorld.ROAD_WIDTH / 2) - 1;
} else {
pathWidthLower = squarePlotWorld.ROAD_WIDTH / 2;
}
end = pathWidthLower + squarePlotWorld.PLOT_WIDTH;
}
int dx;
int rx;
if (x < 0) {
dx = x / size;
rx = size + (x % size);
} else {
dx = (x / size) + 1;
rx = x % size;
}
int dz;
int rz;
if (z < 0) {
dz = z / size;
rz = size + (z % size);
} else {
dz = (z / size) + 1;
rz = z % size;
}
PlotId id = PlotId.of(dx, dz);
boolean[] merged = new boolean[] { rz <= pathWidthLower, rx > end, rz > end, rx <= pathWidthLower };
int hash = HashUtil.hash(merged);
// Not merged, and no need to check if it is
if (hash == 0) {
return id;
}
Plot plot = squarePlotWorld.getOwnedPlotAbs(id);
// Not merged, and standing on road
if (plot == null) {
return null;
}
switch(hash) {
case 8:
// north
return plot.isMerged(Direction.NORTH) ? id : null;
case 4:
// east
return plot.isMerged(Direction.EAST) ? id : null;
case 2:
// south
return plot.isMerged(Direction.SOUTH) ? id : null;
case 1:
// west
return plot.isMerged(Direction.WEST) ? id : null;
case 12:
// northeast
return plot.isMerged(Direction.NORTHEAST) ? id : null;
case 6:
// southeast
return plot.isMerged(Direction.SOUTHEAST) ? id : null;
case 3:
// southwest
return plot.isMerged(Direction.SOUTHWEST) ? id : null;
case 9:
// northwest
return plot.isMerged(Direction.NORTHWEST) ? id : null;
}
} catch (Exception ignored) {
LOGGER.error("Invalid plot / road width in settings.yml for world: {}", squarePlotWorld.getWorldName());
}
return null;
}
use of com.plotsquared.core.plot.PlotId in project PlotSquared by IntellectualSites.
the class HybridPlotManager method createRoadSouthEast.
@Override
public boolean createRoadSouthEast(@NonNull final Plot plot, @Nullable QueueCoordinator queue) {
boolean enqueue = false;
if (queue == null) {
enqueue = true;
queue = hybridPlotWorld.getQueue();
}
super.createRoadSouthEast(plot, queue);
PlotId id = plot.getId();
PlotId id2 = PlotId.of(id.getX() + 1, id.getY() + 1);
Location pos1 = getPlotTopLocAbs(id).add(1, 0, 1);
Location pos2 = getPlotBottomLocAbs(id2);
createSchemAbs(queue, pos1, pos2, true);
if (hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) {
createSchemAbs(queue, pos1, pos2, true);
}
return !enqueue || queue.enqueue();
}
Aggregations