Search in sources :

Example 6 with SinglePlotArea

use of com.plotsquared.core.plot.world.SinglePlotArea in project PlotSquared by IntellectualSites.

the class DebugImportWorlds method execute.

@Override
public CompletableFuture<Boolean> execute(PlotPlayer<?> player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm, RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
    // UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8))
    if (!(this.plotAreaManager instanceof SinglePlotAreaManager)) {
        player.sendMessage(TranslatableCaption.of("debugimportworlds.single_plot_area"));
        return CompletableFuture.completedFuture(false);
    }
    SinglePlotArea area = ((SinglePlotAreaManager) this.plotAreaManager).getArea();
    PlotId id = PlotId.of(0, 0);
    File container = PlotSquared.platform().worldContainer();
    if (container.equals(new File("."))) {
        player.sendMessage(TranslatableCaption.of("debugimportworlds.world_container"));
        return CompletableFuture.completedFuture(false);
    }
    for (File folder : container.listFiles()) {
        String name = folder.getName();
        if (!this.worldUtil.isWorld(name) && PlotId.fromStringOrNull(name) == null) {
            UUID uuid;
            if (name.length() > 16) {
                uuid = UUID.fromString(name);
            } else {
                player.sendMessage(TranslatableCaption.of("players.fetching_player"));
                uuid = PlotSquared.get().getImpromptuUUIDPipeline().getSingle(name, 60000L);
            }
            if (uuid == null) {
                uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8));
            }
            while (new File(container, id.toCommaSeparatedString()).exists()) {
                id = id.getNextId();
            }
            File newDir = new File(container, id.toCommaSeparatedString());
            if (folder.renameTo(newDir)) {
                area.getPlot(id).setOwner(uuid);
            }
        }
    }
    player.sendMessage(TranslatableCaption.of("players.done"));
    return CompletableFuture.completedFuture(true);
}
Also used : SinglePlotArea(com.plotsquared.core.plot.world.SinglePlotArea) PlotId(com.plotsquared.core.plot.PlotId) SinglePlotAreaManager(com.plotsquared.core.plot.world.SinglePlotAreaManager) UUID(java.util.UUID) File(java.io.File)

Aggregations

SinglePlotArea (com.plotsquared.core.plot.world.SinglePlotArea)6 Location (com.plotsquared.core.location.Location)5 BlockLoc (com.plotsquared.core.location.BlockLoc)2 Plot (com.plotsquared.core.plot.Plot)2 PlotArea (com.plotsquared.core.plot.PlotArea)2 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)2 EventBus (com.google.common.eventbus.EventBus)1 Settings (com.plotsquared.core.configuration.Settings)1 TranslatableCaption (com.plotsquared.core.configuration.caption.TranslatableCaption)1 PlayerAutoPlotEvent (com.plotsquared.core.events.PlayerAutoPlotEvent)1 PlayerAutoPlotsChosenEvent (com.plotsquared.core.events.PlayerAutoPlotsChosenEvent)1 PlayerClaimPlotEvent (com.plotsquared.core.events.PlayerClaimPlotEvent)1 PlayerEnterPlotEvent (com.plotsquared.core.events.PlayerEnterPlotEvent)1 PlayerLeavePlotEvent (com.plotsquared.core.events.PlayerLeavePlotEvent)1 PlayerPlotDeniedEvent (com.plotsquared.core.events.PlayerPlotDeniedEvent)1 PlayerPlotHelperEvent (com.plotsquared.core.events.PlayerPlotHelperEvent)1 PlayerPlotTrustedEvent (com.plotsquared.core.events.PlayerPlotTrustedEvent)1 PlayerTeleportToPlotEvent (com.plotsquared.core.events.PlayerTeleportToPlotEvent)1 PlotAutoMergeEvent (com.plotsquared.core.events.PlotAutoMergeEvent)1 PlotChangeOwnerEvent (com.plotsquared.core.events.PlotChangeOwnerEvent)1