Search in sources :

Example 6 with Location

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;
}
Also used : Location(com.plotsquared.core.location.Location) MetaDataAccess(com.plotsquared.core.player.MetaDataAccess) Permissions(com.plotsquared.core.util.Permissions) NonNull(org.checkerframework.checker.nullness.qual.NonNull) Plot(com.plotsquared.core.plot.Plot) PlotAreaManager(com.plotsquared.core.plot.world.PlotAreaManager) RunnableVal(com.plotsquared.core.util.task.RunnableVal) URL(java.net.URL) Inject(com.google.inject.Inject) TaskManager(com.plotsquared.core.util.task.TaskManager) PlotId(com.plotsquared.core.plot.PlotId) Permission(com.plotsquared.core.permissions.Permission) UUID(java.util.UUID) List(java.util.List) PlotPlayer(com.plotsquared.core.player.PlotPlayer) SchematicHandler(com.plotsquared.core.util.SchematicHandler) TranslatableCaption(com.plotsquared.core.configuration.caption.TranslatableCaption) PlayerMetaDataKeys(com.plotsquared.core.player.PlayerMetaDataKeys) Template(net.kyori.adventure.text.minimessage.Template) PlotId(com.plotsquared.core.plot.PlotId) Plot(com.plotsquared.core.plot.Plot) UUID(java.util.UUID) MetaDataAccess(com.plotsquared.core.player.MetaDataAccess) URL(java.net.URL) Location(com.plotsquared.core.location.Location)

Example 7 with Location

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;
}
Also used : Plot(com.plotsquared.core.plot.Plot) PlotPlayer(com.plotsquared.core.player.PlotPlayer) UUID(java.util.UUID) Location(com.plotsquared.core.location.Location) TimeoutException(java.util.concurrent.TimeoutException)

Example 8 with Location

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;
}
Also used : PlotArea(com.plotsquared.core.plot.PlotArea) HybridPlotManager(com.plotsquared.core.generator.HybridPlotManager) PlotManager(com.plotsquared.core.plot.PlotManager) HybridPlotManager(com.plotsquared.core.generator.HybridPlotManager) Plot(com.plotsquared.core.plot.Plot) Location(com.plotsquared.core.location.Location)

Example 9 with Location

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;
    }
}
Also used : PlotArea(com.plotsquared.core.plot.PlotArea) Plot(com.plotsquared.core.plot.Plot) Location(com.plotsquared.core.location.Location)

Example 10 with Location

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;
}
Also used : TeleportCause(com.plotsquared.core.events.TeleportCause) Location(com.plotsquared.core.location.Location) Permissions(com.plotsquared.core.util.Permissions) NonNull(org.checkerframework.checker.nullness.qual.NonNull) Plot(com.plotsquared.core.plot.Plot) Inject(com.google.inject.Inject) TaskManager(com.plotsquared.core.util.task.TaskManager) Permission(com.plotsquared.core.permissions.Permission) EconHandler(com.plotsquared.core.util.EconHandler) Result(com.plotsquared.core.events.Result) PlotPlayer(com.plotsquared.core.player.PlotPlayer) TranslatableCaption(com.plotsquared.core.configuration.caption.TranslatableCaption) PlotExpression(com.plotsquared.core.util.PlotExpression) Settings(com.plotsquared.core.configuration.Settings) PlotArea(com.plotsquared.core.plot.PlotArea) Template(net.kyori.adventure.text.minimessage.Template) EventDispatcher(com.plotsquared.core.util.EventDispatcher) PlotExpression(com.plotsquared.core.util.PlotExpression) PlotArea(com.plotsquared.core.plot.PlotArea) Plot(com.plotsquared.core.plot.Plot) Location(com.plotsquared.core.location.Location) Result(com.plotsquared.core.events.Result)

Aggregations

Location (com.plotsquared.core.location.Location)82 Plot (com.plotsquared.core.plot.Plot)41 PlotArea (com.plotsquared.core.plot.PlotArea)26 EventHandler (org.bukkit.event.EventHandler)15 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)14 PlotPlayer (com.plotsquared.core.player.PlotPlayer)12 UUID (java.util.UUID)12 HashSet (java.util.HashSet)10 TranslatableCaption (com.plotsquared.core.configuration.caption.TranslatableCaption)9 NonNull (org.checkerframework.checker.nullness.qual.NonNull)9 QueueCoordinator (com.plotsquared.core.queue.QueueCoordinator)8 Caption (com.plotsquared.core.configuration.caption.Caption)7 BlockLoc (com.plotsquared.core.location.BlockLoc)7 Template (net.kyori.adventure.text.minimessage.Template)7 Entity (org.bukkit.entity.Entity)7 Settings (com.plotsquared.core.configuration.Settings)6 ClassicPlotWorld (com.plotsquared.core.generator.ClassicPlotWorld)6 PlotFlag (com.plotsquared.core.plot.flag.PlotFlag)6 SinglePlotArea (com.plotsquared.core.plot.world.SinglePlotArea)6 PlotSquared (com.plotsquared.core.PlotSquared)5