use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.
the class Save method onCommand.
@Override
public boolean onCommand(final PlotPlayer<?> player, final String[] args) {
final String world = player.getLocation().getWorldName();
if (!this.plotAreaManager.hasPlotArea(world)) {
player.sendMessage(TranslatableCaption.of("errors.not_in_plot_world"));
return false;
}
final Plot plot = player.getCurrentPlot();
if (plot == null) {
player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
return false;
}
if (!plot.hasOwner()) {
player.sendMessage(TranslatableCaption.of("info.plot_unowned"));
return false;
}
if (plot.getVolume() > Integer.MAX_VALUE) {
player.sendMessage(TranslatableCaption.of("schematics.schematic_too_large"));
return false;
}
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_SAVE)) {
player.sendMessage(TranslatableCaption.of("permission.no_plot_perms"));
return false;
}
if (plot.getRunning() > 0) {
player.sendMessage(TranslatableCaption.of("errors.wait_for_timer"));
return false;
}
plot.addRunning();
this.schematicHandler.getCompoundTag(plot).whenComplete((compoundTag, throwable) -> {
TaskManager.runTaskAsync(() -> {
String time = (System.currentTimeMillis() / 1000) + "";
Location[] corners = plot.getCorners();
corners[0] = corners[0].withY(plot.getArea().getMinBuildHeight());
corners[1] = corners[1].withY(plot.getArea().getMaxBuildHeight());
int size = (corners[1].getX() - corners[0].getX()) + 1;
PlotId id = plot.getId();
String world1 = plot.getArea().toString().replaceAll(";", "-").replaceAll("[^A-Za-z0-9]", "");
final String file = time + '_' + world1 + '_' + id.getX() + '_' + id.getY() + '_' + size;
UUID uuid = player.getUUID();
schematicHandler.upload(compoundTag, uuid, file, new RunnableVal<>() {
@Override
public void run(URL url) {
plot.removeRunning();
if (url == null) {
player.sendMessage(TranslatableCaption.of("backups.backup_save_failed"));
return;
}
player.sendMessage(TranslatableCaption.of("web.save_success"));
player.sendMessage(TranslatableCaption.of("errors.deprecated_commands"), Template.of("replacement", "/plot download"));
try (final MetaDataAccess<List<String>> schematicAccess = player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_SCHEMATICS)) {
schematicAccess.get().ifPresent(schematics -> schematics.add(file + ".schem"));
}
}
});
});
});
return true;
}
use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.
the class Deny method onCommand.
@Override
public boolean onCommand(PlotPlayer<?> player, String[] args) {
Location location = player.getLocation();
final Plot plot = location.getPlotAbs();
if (plot == null) {
player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
return false;
}
if (!plot.hasOwner()) {
player.sendMessage(TranslatableCaption.of("info.plot_unowned"));
return false;
}
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_DENY)) {
player.sendMessage(TranslatableCaption.of("permission.no_plot_perms"));
return true;
}
int maxDenySize = Permissions.hasPermissionRange(player, Permission.PERMISSION_DENY, Settings.Limit.MAX_PLOTS);
int size = plot.getDenied().size();
if (size >= maxDenySize) {
player.sendMessage(TranslatableCaption.of("members.plot_max_members_denied"), Template.of("amount", String.valueOf(size)));
return false;
}
PlayerManager.getUUIDsFromString(args[0], (uuids, throwable) -> {
if (throwable instanceof TimeoutException) {
player.sendMessage(TranslatableCaption.of("players.fetching_players_timeout"));
} else if (throwable != null || uuids.isEmpty()) {
player.sendMessage(TranslatableCaption.of("errors.invalid_player"), Template.of("value", args[0]));
} else {
for (UUID uuid : uuids) {
if (uuid == DBFunc.EVERYONE && !(Permissions.hasPermission(player, Permission.PERMISSION_DENY_EVERYONE) || Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_DENY))) {
player.sendMessage(TranslatableCaption.of("errors.invalid_player"), Template.of("value", args[0]));
} else if (plot.isOwner(uuid)) {
player.sendMessage(TranslatableCaption.of("deny.cant_remove_owner"));
return;
} else if (plot.getDenied().contains(uuid)) {
player.sendMessage(TranslatableCaption.of("member.already_added"), Template.of("player", PlayerManager.resolveName(uuid).getComponent(player)));
return;
} else {
if (uuid != DBFunc.EVERYONE) {
plot.removeMember(uuid);
plot.removeTrusted(uuid);
}
plot.addDenied(uuid);
this.eventDispatcher.callDenied(player, plot, uuid, true);
if (!uuid.equals(DBFunc.EVERYONE)) {
handleKick(PlotSquared.platform().playerManager().getPlayerIfExists(uuid), plot);
} else {
for (PlotPlayer<?> plotPlayer : plot.getPlayersInPlot()) {
// Ignore plot-owners
if (plot.isAdded(plotPlayer.getUUID())) {
continue;
}
handleKick(plotPlayer, plot);
}
}
}
}
player.sendMessage(TranslatableCaption.of("deny.denied_added"));
}
});
return true;
}
use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.
the class DebugRoadRegen method regenRegion.
public boolean regenRegion(PlotPlayer<?> player, String[] args) {
int height = 0;
if (args.length == 1) {
try {
height = Integer.parseInt(args[0]);
} catch (NumberFormatException ignored) {
player.sendMessage(TranslatableCaption.of("invalid.not_valid_number"), Template.of("value", "0, 256"));
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"), Template.of("value", DebugRoadRegen.USAGE));
return false;
}
} else if (args.length != 0) {
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"), Template.of("value", DebugRoadRegen.USAGE));
return false;
}
Location location = player.getLocation();
PlotArea area = location.getPlotArea();
if (area == null) {
player.sendMessage(TranslatableCaption.of("errors.not_in_plot_world"));
}
Plot plot = player.getCurrentPlot();
PlotManager manager = area.getPlotManager();
if (!(manager instanceof HybridPlotManager)) {
player.sendMessage(TranslatableCaption.of("errors.invalid_plot_world"));
return true;
}
player.sendMessage(TranslatableCaption.of("debugroadregen.schematic"), Template.of("command", "/plot createroadschematic"));
player.sendMessage(TranslatableCaption.of("debugroadregen.regenallroads"), Template.of("command", "/plot regenallroads"));
boolean result = this.hybridUtils.scheduleSingleRegionRoadUpdate(plot, height);
if (!result) {
player.sendMessage(TranslatableCaption.of("debugexec.mass_schematic_update_in_progress"));
return false;
}
return true;
}
use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.
the class DebugRoadRegen method onCommand.
@Override
public boolean onCommand(PlotPlayer<?> player, String[] args) {
Location location = player.getLocation();
Plot plot = location.getPlotAbs();
if (args.length < 1) {
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"), Template.of("value", DebugRoadRegen.USAGE));
return false;
}
PlotArea area = player.getPlotAreaAbs();
check(area, TranslatableCaption.of("errors.not_in_plot_world"));
if (plot.getVolume() > Integer.MAX_VALUE) {
player.sendMessage(TranslatableCaption.of("schematics.schematic_too_large"));
return false;
}
String kind = args[0].toLowerCase();
switch(kind) {
case "plot":
return regenPlot(player);
case "region":
return regenRegion(player, Arrays.copyOfRange(args, 1, args.length));
default:
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"), Template.of("value", DebugRoadRegen.USAGE));
return false;
}
}
use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.
the class Delete method onCommand.
@Override
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
Location location = player.getLocation();
final Plot plot = location.getPlotAbs();
if (plot == null) {
player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
return false;
}
if (!plot.hasOwner()) {
player.sendMessage(TranslatableCaption.of("info.plot_unowned"));
return false;
}
if (plot.getVolume() > Integer.MAX_VALUE) {
player.sendMessage(TranslatableCaption.of("schematics.schematic_too_large"));
return false;
}
Result eventResult = this.eventDispatcher.callDelete(plot).getEventResult();
if (eventResult == Result.DENY) {
player.sendMessage(TranslatableCaption.of("events.event_denied"), Template.of("value", "Delete"));
return true;
}
boolean force = eventResult == Result.FORCE;
if (!force && !plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_DELETE)) {
player.sendMessage(TranslatableCaption.of("permission.no_plot_perms"));
return false;
}
final PlotArea plotArea = plot.getArea();
final java.util.Set<Plot> plots = plot.getConnectedPlots();
final int currentPlots = Settings.Limit.GLOBAL ? player.getPlotCount() : player.getPlotCount(location.getWorldName());
Runnable run = () -> {
if (plot.getRunning() > 0) {
player.sendMessage(TranslatableCaption.of("errors.wait_for_timer"));
return;
}
final long start = System.currentTimeMillis();
if (Settings.Teleport.ON_DELETE) {
plot.getPlayersInPlot().forEach(playerInPlot -> plot.teleportPlayer(playerInPlot, TeleportCause.COMMAND_DELETE, result -> {
}));
}
boolean result = plot.getPlotModificationManager().deletePlot(player, () -> {
plot.removeRunning();
if (this.econHandler.isEnabled(plotArea)) {
PlotExpression valueExr = plotArea.getPrices().get("sell");
double value = plots.size() * valueExr.evaluate(currentPlots);
if (value > 0d) {
this.econHandler.depositMoney(player, value);
player.sendMessage(TranslatableCaption.of("economy.added_balance"), Template.of("money", this.econHandler.format(value)));
}
}
player.sendMessage(TranslatableCaption.of("working.deleting_done"), Template.of("amount", String.valueOf(System.currentTimeMillis() - start)), Template.of("plot", plot.getId().toString()));
eventDispatcher.callPostDelete(plot);
});
if (result) {
plot.addRunning();
} else {
player.sendMessage(TranslatableCaption.of("errors.wait_for_timer"));
}
};
if (hasConfirmation(player)) {
CmdConfirm.addPending(player, getCommandString() + ' ' + plot.getId(), run);
} else {
TaskManager.runTask(run);
}
return true;
}
Aggregations