use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.
the class Copy method onCommand.
@Override
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
Location location = player.getLocation();
Plot plot1 = location.getPlotAbs();
if (plot1 == null) {
player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
return false;
}
if (!plot1.isOwner(player.getUUID()) && !Permissions.hasPermission(player, Permission.PERMISSION_ADMIN.toString())) {
player.sendMessage(TranslatableCaption.of("permission.no_plot_perms"));
return false;
}
if (args.length != 1) {
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"), Template.of("value", "/plot copy <X;Z>"));
return false;
}
Plot plot2 = Plot.getPlotFromString(player, args[0], true);
if (plot2 == null) {
return false;
}
if (plot1.equals(plot2)) {
player.sendMessage(TranslatableCaption.of("invalid.origin_cant_be_target"));
return false;
}
if (!plot1.getArea().isCompatible(plot2.getArea())) {
player.sendMessage(TranslatableCaption.of("errors.plotworld_incompatible"));
return false;
}
plot1.getPlotModificationManager().copy(plot2, player).thenAccept(result -> {
if (result) {
player.sendMessage(TranslatableCaption.of("move.copy_success"), Template.of("origin", String.valueOf(plot1)), Template.of("target", String.valueOf(plot2)));
} else {
player.sendMessage(TranslatableCaption.of("move.requires_unowned"));
}
});
return true;
}
use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.
the class PlotListener method plotExit.
public boolean plotExit(final PlotPlayer<?> player, Plot plot) {
try (final MetaDataAccess<Plot> lastPlot = player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
final Plot previous = lastPlot.remove();
this.eventDispatcher.callLeave(player, plot);
if (plot.hasOwner()) {
PlotArea pw = plot.getArea();
if (pw == null) {
return true;
}
try (final MetaDataAccess<Boolean> kickAccess = player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_KICK)) {
if (plot.getFlag(DenyExitFlag.class) && !Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_EXIT_DENIED) && !kickAccess.get().orElse(false)) {
if (previous != null) {
lastPlot.set(previous);
}
return false;
}
}
if (!plot.getFlag(GamemodeFlag.class).equals(GamemodeFlag.DEFAULT) || !plot.getFlag(GuestGamemodeFlag.class).equals(GamemodeFlag.DEFAULT)) {
if (player.getGameMode() != pw.getGameMode()) {
if (!Permissions.hasPermission(player, "plots.gamemode.bypass")) {
player.setGameMode(pw.getGameMode());
} else {
player.sendMessage(TranslatableCaption.of("gamemode.gamemode_was_bypassed"), Template.of("gamemode", pw.getGameMode().getName().toLowerCase()), Template.of("plot", plot.toString()));
}
}
}
String farewell = plot.getFlag(FarewellFlag.class);
if (!farewell.isEmpty()) {
if (!Settings.Chat.NOTIFICATION_AS_ACTIONBAR) {
plot.format(StaticCaption.of(farewell), player, false).thenAcceptAsync(player::sendMessage);
} else {
plot.format(StaticCaption.of(farewell), player, false).thenAcceptAsync(player::sendActionBar);
}
}
if (plot.getFlag(NotifyLeaveFlag.class)) {
if (!Permissions.hasPermission(player, "plots.flag.notify-leave.bypass")) {
for (UUID uuid : plot.getOwners()) {
final PlotPlayer<?> owner = PlotSquared.platform().playerManager().getPlayerIfExists(uuid);
if ((owner != null) && !owner.getUUID().equals(player.getUUID()) && owner.canSee(player)) {
Caption caption = TranslatableCaption.of("notification.notify_leave");
notifyPlotOwner(player, plot, owner, caption);
}
}
}
}
final FlyFlag.FlyStatus flyStatus = plot.getFlag(FlyFlag.class);
if (flyStatus != FlyFlag.FlyStatus.DEFAULT) {
try (final MetaDataAccess<Boolean> metaDataAccess = player.accessPersistentMetaData(PlayerMetaDataKeys.PERSISTENT_FLIGHT)) {
final Optional<Boolean> value = metaDataAccess.get();
if (value.isPresent()) {
player.setFlight(value.get());
metaDataAccess.remove();
} else {
GameMode gameMode = player.getGameMode();
if (gameMode == GameModes.SURVIVAL || gameMode == GameModes.ADVENTURE) {
player.setFlight(false);
} else if (!player.getFlight()) {
player.setFlight(true);
}
}
}
}
if (plot.getFlag(TimeFlag.class) != TimeFlag.TIME_DISABLED.getValue().longValue()) {
player.setTime(Long.MAX_VALUE);
}
final PlotWeather plotWeather = plot.getFlag(WeatherFlag.class);
if (plotWeather != PlotWeather.OFF) {
player.setWeather(PlotWeather.WORLD);
}
try (final MetaDataAccess<Location> musicAccess = player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_MUSIC)) {
musicAccess.get().ifPresent(lastLoc -> {
musicAccess.remove();
player.playMusic(lastLoc, ItemTypes.AIR);
});
}
feedRunnable.remove(player.getUUID());
healRunnable.remove(player.getUUID());
}
}
return true;
}
use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.
the class HybridPlotManager method createRoadSouth.
@Override
public boolean createRoadSouth(@NonNull final Plot plot, @Nullable QueueCoordinator queue) {
boolean enqueue = false;
if (queue == null) {
enqueue = true;
queue = hybridPlotWorld.getQueue();
}
super.createRoadSouth(plot, queue);
PlotId id = plot.getId();
PlotId id2 = PlotId.of(id.getX(), id.getY() + 1);
Location bot = getPlotBottomLocAbs(id2);
Location top = getPlotTopLocAbs(id);
Location pos1 = Location.at(hybridPlotWorld.getWorldName(), bot.getX() - 1, hybridPlotWorld.getMinGenHeight(), top.getZ() + 1);
Location pos2 = Location.at(hybridPlotWorld.getWorldName(), top.getX() + 1, hybridPlotWorld.getMaxGenHeight(), bot.getZ());
this.resetBiome(hybridPlotWorld, pos1, pos2);
if (!hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) {
return true;
}
createSchemAbs(queue, pos1, pos2, true);
return !enqueue || queue.enqueue();
}
use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.
the class Trim method onCommand.
@Override
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
if (args.length == 0) {
sendUsage(player);
return false;
}
final String world = args[0];
if (!this.worldUtil.isWorld(world) || !this.plotAreaManager.hasPlotArea(world)) {
player.sendMessage(TranslatableCaption.of("errors.not_valid_world"));
return false;
}
if (Trim.TASK) {
player.sendMessage(TranslatableCaption.of("trim.trim_in_progress"));
return false;
}
Trim.TASK = true;
final boolean regen = args.length == 2 && Boolean.parseBoolean(args[1]);
getTrimRegions(world, new RunnableVal2<>() {
@Override
public void run(Set<BlockVector2> viable, final Set<BlockVector2> nonViable) {
Runnable regenTask;
if (regen) {
LOGGER.info("Starting regen task");
LOGGER.info(" - This is a VERY slow command");
LOGGER.info(" - It will say 'Trim done!' when complete");
regenTask = new Runnable() {
@Override
public void run() {
if (nonViable.isEmpty()) {
Trim.TASK = false;
player.sendMessage(TranslatableCaption.of("trim.trim_done"));
LOGGER.info("Trim done!");
return;
}
Iterator<BlockVector2> iterator = nonViable.iterator();
BlockVector2 mcr = iterator.next();
iterator.remove();
int cbx = mcr.getX() << 5;
int cbz = mcr.getZ() << 5;
// get all 1024 chunks
HashSet<BlockVector2> chunks = new HashSet<>();
for (int x = cbx; x < cbx + 32; x++) {
for (int z = cbz; z < cbz + 32; z++) {
BlockVector2 loc = BlockVector2.at(x, z);
chunks.add(loc);
}
}
int bx = cbx << 4;
int bz = cbz << 4;
CuboidRegion region = RegionUtil.createRegion(bx, bx + 511, 0, 0, bz, bz + 511);
for (Plot plot : PlotQuery.newQuery().inWorld(world)) {
Location bot = plot.getBottomAbs();
Location top = plot.getExtendedTopAbs();
CuboidRegion plotReg = RegionUtil.createRegion(bot.getX(), top.getX(), 0, 0, bot.getZ(), top.getZ());
if (!RegionUtil.intersects(region, plotReg)) {
continue;
}
for (int x = plotReg.getMinimumPoint().getX() >> 4; x <= plotReg.getMaximumPoint().getX() >> 4; x++) {
for (int z = plotReg.getMinimumPoint().getZ() >> 4; z <= plotReg.getMaximumPoint().getZ() >> 4; z++) {
BlockVector2 loc = BlockVector2.at(x, z);
chunks.remove(loc);
}
}
}
final QueueCoordinator queue = blockQueue.getNewQueue(worldUtil.getWeWorld(world));
TaskManager.getPlatformImplementation().objectTask(chunks, new RunnableVal<>() {
@Override
public void run(BlockVector2 value) {
queue.regenChunk(value.getX(), value.getZ());
}
}).thenAccept(ignore -> TaskManager.getPlatformImplementation().taskLater(this, TaskTime.ticks(1L)));
}
};
} else {
regenTask = () -> {
Trim.TASK = false;
player.sendMessage(TranslatableCaption.of("trim.trim_done"));
LOGGER.info("Trim done!");
};
}
regionManager.deleteRegionFiles(world, viable, regenTask);
}
});
return true;
}
use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.
the class Unlink 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;
}
if (!plot.isMerged()) {
player.sendMessage(TranslatableCaption.of("merge.unlink_impossible"));
return false;
}
final boolean createRoad;
if (args.length != 0) {
if (args.length != 1 || !StringMan.isEqualIgnoreCaseToAny(args[0], "true", "false")) {
sendUsage(player);
return false;
}
createRoad = Boolean.parseBoolean(args[0]);
} else {
createRoad = true;
}
PlotUnlinkEvent event = this.eventDispatcher.callUnlink(plot.getArea(), plot, createRoad, createRoad, PlotUnlinkEvent.REASON.PLAYER_COMMAND);
if (event.getEventResult() == Result.DENY) {
player.sendMessage(TranslatableCaption.of("events.event_denied"), Template.of("value", "Unlink"));
return true;
}
boolean force = event.getEventResult() == Result.FORCE;
if (!force && !plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_UNLINK)) {
player.sendMessage(TranslatableCaption.of("permission.no_plot_perms"));
return true;
}
Runnable runnable = () -> {
if (!plot.getPlotModificationManager().unlinkPlot(createRoad, createRoad)) {
player.sendMessage(TranslatableCaption.of("merge.unmerge_cancelled"));
return;
}
player.sendMessage(TranslatableCaption.of("merge.unlink_success"));
eventDispatcher.callPostUnlink(plot, PlotUnlinkEvent.REASON.PLAYER_COMMAND);
};
if (hasConfirmation(player)) {
CmdConfirm.addPending(player, "/plot unlink " + plot.getId(), runnable);
} else {
TaskManager.runTask(runnable);
}
return true;
}
Aggregations