Search in sources :

Example 31 with Location

use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.

the class BukkitRegionManager method regenerateRegion.

@Override
public boolean regenerateRegion(@NonNull final Location pos1, @NonNull final Location pos2, final boolean ignoreAugment, @Nullable final Runnable whenDone) {
    final BukkitWorld world = (BukkitWorld) worldUtil.getWeWorld(pos1.getWorldName());
    final int p1x = pos1.getX();
    final int p1z = pos1.getZ();
    final int p2x = pos2.getX();
    final int p2z = pos2.getZ();
    final int bcx = p1x >> 4;
    final int bcz = p1z >> 4;
    final int tcx = p2x >> 4;
    final int tcz = p2z >> 4;
    final QueueCoordinator queue = blockQueue.getNewQueue(world);
    final QueueCoordinator regenQueue = blockQueue.getNewQueue(world);
    queue.addReadChunks(new CuboidRegion(pos1.getBlockVector3(), pos2.getBlockVector3()).getChunks());
    queue.setChunkConsumer(chunk -> {
        int x = chunk.getX();
        int z = chunk.getZ();
        int xxb = x << 4;
        int zzb = z << 4;
        int xxt = xxb + 15;
        int zzt = zzb + 15;
        if (xxb >= p1x && xxt <= p2x && zzb >= p1z && zzt <= p2z) {
            AugmentedUtils.bypass(ignoreAugment, () -> regenQueue.regenChunk(chunk.getX(), chunk.getZ()));
            return;
        }
        boolean checkX1 = false;
        int xxb2;
        if (x == bcx) {
            xxb2 = p1x - 1;
            checkX1 = true;
        } else {
            xxb2 = xxb;
        }
        boolean checkX2 = false;
        int xxt2;
        if (x == tcx) {
            xxt2 = p2x + 1;
            checkX2 = true;
        } else {
            xxt2 = xxt;
        }
        boolean checkZ1 = false;
        int zzb2;
        if (z == bcz) {
            zzb2 = p1z - 1;
            checkZ1 = true;
        } else {
            zzb2 = zzb;
        }
        boolean checkZ2 = false;
        int zzt2;
        if (z == tcz) {
            zzt2 = p2z + 1;
            checkZ2 = true;
        } else {
            zzt2 = zzt;
        }
        final ContentMap map = new ContentMap();
        if (checkX1) {
            // 
            map.saveRegion(world, xxb, xxb2, zzb2, zzt2);
        }
        if (checkX2) {
            // 
            map.saveRegion(world, xxt2, xxt, zzb2, zzt2);
        }
        if (checkZ1) {
            // 
            map.saveRegion(world, xxb2, xxt2, zzb, zzb2);
        }
        if (checkZ2) {
            // 
            map.saveRegion(world, xxb2, xxt2, zzt2, zzt);
        }
        if (checkX1 && checkZ1) {
            // 
            map.saveRegion(world, xxb, xxb2, zzb, zzb2);
        }
        if (checkX2 && checkZ1) {
            // ?
            map.saveRegion(world, xxt2, xxt, zzb, zzb2);
        }
        if (checkX1 && checkZ2) {
            // ?
            map.saveRegion(world, xxb, xxb2, zzt2, zzt);
        }
        if (checkX2 && checkZ2) {
            // 
            map.saveRegion(world, xxt2, xxt, zzt2, zzt);
        }
        CuboidRegion currentPlotClear = new CuboidRegion(pos1.getBlockVector3(), pos2.getBlockVector3());
        map.saveEntitiesOut(Bukkit.getWorld(world.getName()).getChunkAt(x, z), currentPlotClear);
        AugmentedUtils.bypass(ignoreAugment, () -> ChunkManager.setChunkInPlotArea(null, new RunnableVal<ScopedQueueCoordinator>() {

            @Override
            public void run(ScopedQueueCoordinator value) {
                Location min = value.getMin();
                int bx = min.getX();
                int bz = min.getZ();
                for (int x1 = 0; x1 < 16; x1++) {
                    for (int z1 = 0; z1 < 16; z1++) {
                        PlotLoc plotLoc = new PlotLoc(bx + x1, bz + z1);
                        BaseBlock[] ids = map.allBlocks.get(plotLoc);
                        if (ids != null) {
                            int minY = value.getMin().getY();
                            for (int yIndex = 0; yIndex < ids.length; yIndex++) {
                                int y = yIndex + minY;
                                BaseBlock id = ids[yIndex];
                                if (id != null) {
                                    value.setBlock(x1, y, z1, id);
                                } else {
                                    value.setBlock(x1, y, z1, BlockTypes.AIR.getDefaultState());
                                }
                            }
                        }
                    }
                }
            }
        }, world.getName(), chunk));
        // map.restoreBlocks(worldObj, 0, 0);
        map.restoreEntities(Bukkit.getWorld(world.getName()));
    });
    regenQueue.setCompleteTask(whenDone);
    queue.setCompleteTask(regenQueue::enqueue);
    queue.enqueue();
    return true;
}
Also used : BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) ScopedQueueCoordinator(com.plotsquared.core.queue.ScopedQueueCoordinator) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock) PlotLoc(com.plotsquared.core.location.PlotLoc) RunnableVal(com.plotsquared.core.util.task.RunnableVal) ScopedQueueCoordinator(com.plotsquared.core.queue.ScopedQueueCoordinator) QueueCoordinator(com.plotsquared.core.queue.QueueCoordinator) Location(com.plotsquared.core.location.Location)

Example 32 with Location

use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.

the class ProjectileEventListener method onProjectileLaunch.

@EventHandler
public void onProjectileLaunch(ProjectileLaunchEvent event) {
    Projectile entity = event.getEntity();
    ProjectileSource shooter = entity.getShooter();
    if (!(shooter instanceof Player)) {
        return;
    }
    Location location = BukkitUtil.adapt(entity.getLocation());
    if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
        return;
    }
    PlotPlayer<Player> pp = BukkitUtil.adapt((Player) shooter);
    Plot plot = location.getOwnedPlot();
    if (plot == null) {
        if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_PROJECTILE_ROAD)) {
            pp.sendMessage(TranslatableCaption.of("permission.no_permission_event"), Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_PROJECTILE_ROAD)));
            entity.remove();
            event.setCancelled(true);
        }
    } else if (!plot.hasOwner()) {
        if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_PROJECTILE_UNOWNED)) {
            pp.sendMessage(TranslatableCaption.of("permission.no_permission_event"), Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_PROJECTILE_UNOWNED)));
            entity.remove();
            event.setCancelled(true);
        }
    } else if (!plot.isAdded(pp.getUUID())) {
        if (!plot.getFlag(ProjectilesFlag.class)) {
            if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_PROJECTILE_OTHER)) {
                pp.sendMessage(TranslatableCaption.of("permission.no_permission_event"), Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_PROJECTILE_OTHER)));
                entity.remove();
                event.setCancelled(true);
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) PlotPlayer(com.plotsquared.core.player.PlotPlayer) ProjectilesFlag(com.plotsquared.core.plot.flag.implementations.ProjectilesFlag) Plot(com.plotsquared.core.plot.Plot) ProjectileSource(org.bukkit.projectiles.ProjectileSource) BlockProjectileSource(org.bukkit.projectiles.BlockProjectileSource) Projectile(org.bukkit.entity.Projectile) Location(com.plotsquared.core.location.Location) EventHandler(org.bukkit.event.EventHandler)

Example 33 with Location

use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.

the class Plot method getDistanceFromOrigin.

public int getDistanceFromOrigin() {
    Location bot = getManager().getPlotBottomLocAbs(id);
    Location top = getManager().getPlotTopLocAbs(id);
    return Math.max(Math.max(Math.abs(bot.getX()), Math.abs(bot.getZ())), Math.max(Math.abs(top.getX()), Math.abs(top.getZ())));
}
Also used : Location(com.plotsquared.core.location.Location)

Example 34 with Location

use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.

the class Plot method getCenter.

public void getCenter(final Consumer<Location> result) {
    Location[] corners = getCorners();
    Location top = corners[0];
    Location bot = corners[1];
    Location location = Location.at(this.getWorldName(), MathMan.average(bot.getX(), top.getX()), MathMan.average(bot.getY(), top.getY()), MathMan.average(bot.getZ(), top.getZ()));
    this.worldUtil.getHighestBlock(getWorldName(), location.getX(), location.getZ(), y -> {
        int height = y;
        if (area.allowSigns()) {
            height = Math.max(y, getManager().getSignLoc(this).getY());
        }
        result.accept(location.withY(1 + height));
    });
}
Also used : Location(com.plotsquared.core.location.Location)

Example 35 with Location

use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.

the class Plot method format.

public CompletableFuture<Caption> format(final Caption iInfo, PlotPlayer<?> player, final boolean full) {
    final CompletableFuture<Caption> future = new CompletableFuture<>();
    int num = this.getConnectedPlots().size();
    String alias = !this.getAlias().isEmpty() ? this.getAlias() : TranslatableCaption.of("info.none").getComponent(player);
    Location bot = this.getCorners()[0];
    PlotSquared.platform().worldUtil().getBiome(Objects.requireNonNull(this.getWorldName()), bot.getX(), bot.getZ(), biome -> {
        Component trusted = PlayerManager.getPlayerList(this.getTrusted(), player);
        Component members = PlayerManager.getPlayerList(this.getMembers(), player);
        Component denied = PlayerManager.getPlayerList(this.getDenied(), player);
        String seen;
        if (Settings.Enabled_Components.PLOT_EXPIRY && ExpireManager.IMP != null) {
            if (this.isOnline()) {
                seen = TranslatableCaption.of("info.now").getComponent(player);
            } else {
                int time = (int) (ExpireManager.IMP.getAge(this, false) / 1000);
                if (time != 0) {
                    seen = TimeUtil.secToTime(time);
                } else {
                    seen = TranslatableCaption.of("info.unknown").getComponent(player);
                }
            }
        } else {
            seen = TranslatableCaption.of("info.never").getComponent(player);
        }
        String description = this.getFlag(DescriptionFlag.class);
        if (description.isEmpty()) {
            description = TranslatableCaption.of("info.plot_no_description").getComponent(player);
        }
        Component flags;
        Collection<PlotFlag<?, ?>> flagCollection = this.getApplicableFlags(true);
        if (flagCollection.isEmpty()) {
            flags = MINI_MESSAGE.parse(TranslatableCaption.of("info.none").getComponent(player));
        } else {
            TextComponent.Builder flagBuilder = Component.text();
            String prefix = "";
            for (final PlotFlag<?, ?> flag : flagCollection) {
                Object value;
                if (flag instanceof DoubleFlag && !Settings.General.SCIENTIFIC) {
                    value = FLAG_DECIMAL_FORMAT.format(flag.getValue());
                } else {
                    value = flag.toString();
                }
                Component snip = MINI_MESSAGE.parse(prefix + CaptionUtility.format(player, TranslatableCaption.of("info.plot_flag_list").getComponent(player)), Template.of("flag", flag.getName()), Template.of("value", CaptionUtility.formatRaw(player, value.toString())));
                flagBuilder.append(snip);
                prefix = ", ";
            }
            flags = flagBuilder.build();
        }
        boolean build = this.isAdded(player.getUUID());
        Component owner;
        if (this.getOwner() == null) {
            owner = Component.text("unowned");
        } else if (this.getOwner().equals(DBFunc.SERVER)) {
            owner = Component.text(MINI_MESSAGE.stripTokens(TranslatableCaption.of("info.server").getComponent(player)));
        } else {
            owner = PlayerManager.getPlayerList(this.getOwners(), player);
        }
        Template headerTemplate = Template.of("header", TranslatableCaption.of("info.plot_info_header").getComponent(player));
        Template footerTemplate = Template.of("footer", TranslatableCaption.of("info.plot_info_footer").getComponent(player));
        Template areaTemplate;
        if (this.getArea() != null) {
            areaTemplate = Template.of("area", this.getArea().getWorldName() + (this.getArea().getId() == null ? "" : "(" + this.getArea().getId() + ")"));
        } else {
            areaTemplate = Template.of("area", TranslatableCaption.of("info.none").getComponent(player));
        }
        long creationDate = Long.parseLong(String.valueOf(timestamp));
        SimpleDateFormat sdf = new SimpleDateFormat(Settings.Timeformat.DATE_FORMAT);
        sdf.setTimeZone(TimeZone.getTimeZone(Settings.Timeformat.TIME_ZONE));
        String newDate = sdf.format(creationDate);
        Template idTemplate = Template.of("id", this.getId().toString());
        Template aliasTemplate = Template.of("alias", alias);
        Template numTemplate = Template.of("num", String.valueOf(num));
        Template descTemplate = Template.of("desc", description);
        Template biomeTemplate = Template.of("biome", biome.toString().toLowerCase());
        Template ownerTemplate = Template.of("owner", owner);
        Template membersTemplate = Template.of("members", members);
        Template playerTemplate = Template.of("player", player.getName());
        Template trustedTemplate = Template.of("trusted", trusted);
        Template helpersTemplate = Template.of("helpers", members);
        Template deniedTemplate = Template.of("denied", denied);
        Template seenTemplate = Template.of("seen", seen);
        Template flagsTemplate = Template.of("flags", flags);
        Template creationTemplate = Template.of("creationdate", newDate);
        Template buildTemplate = Template.of("build", String.valueOf(build));
        Template sizeTemplate = Template.of("size", String.valueOf(getConnectedPlots().size()));
        String component = iInfo.getComponent(player);
        if (component.contains("<rating>") || component.contains("<likes>")) {
            TaskManager.runTaskAsync(() -> {
                Template ratingTemplate;
                Template likesTemplate;
                if (Settings.Ratings.USE_LIKES) {
                    ratingTemplate = Template.of("rating", String.format("%.0f%%", Like.getLikesPercentage(this) * 100D));
                    likesTemplate = Template.of("likes", String.format("%.0f%%", Like.getLikesPercentage(this) * 100D));
                } else {
                    int max = 10;
                    if (Settings.Ratings.CATEGORIES != null && !Settings.Ratings.CATEGORIES.isEmpty()) {
                        max = 8;
                    }
                    if (full && Settings.Ratings.CATEGORIES != null && Settings.Ratings.CATEGORIES.size() > 1) {
                        double[] ratings = this.getAverageRatings();
                        StringBuilder rating = new StringBuilder();
                        String prefix = "";
                        for (int i = 0; i < ratings.length; i++) {
                            rating.append(prefix).append(Settings.Ratings.CATEGORIES.get(i)).append('=').append(String.format("%.1f", ratings[i]));
                            prefix = ",";
                        }
                        ratingTemplate = Template.of("rating", rating.toString());
                    } else {
                        double rating = this.getAverageRating();
                        if (Double.isFinite(rating)) {
                            ratingTemplate = Template.of("rating", String.format("%.1f", rating) + '/' + max);
                        } else {
                            ratingTemplate = Template.of("rating", TranslatableCaption.of("info.none").getComponent(player));
                        }
                    }
                    likesTemplate = Template.of("likes", "N/A");
                }
                future.complete(StaticCaption.of(MINI_MESSAGE.serialize(MINI_MESSAGE.parse(iInfo.getComponent(player), headerTemplate, areaTemplate, idTemplate, aliasTemplate, numTemplate, descTemplate, biomeTemplate, ownerTemplate, membersTemplate, playerTemplate, trustedTemplate, helpersTemplate, deniedTemplate, seenTemplate, flagsTemplate, buildTemplate, ratingTemplate, creationTemplate, sizeTemplate, likesTemplate, footerTemplate))));
            });
            return;
        }
        future.complete(StaticCaption.of(MINI_MESSAGE.serialize(MINI_MESSAGE.parse(iInfo.getComponent(player), headerTemplate, areaTemplate, idTemplate, aliasTemplate, numTemplate, descTemplate, biomeTemplate, ownerTemplate, membersTemplate, playerTemplate, trustedTemplate, helpersTemplate, deniedTemplate, seenTemplate, flagsTemplate, buildTemplate, creationTemplate, sizeTemplate, footerTemplate))));
    });
    return future;
}
Also used : ServerPlotFlag(com.plotsquared.core.plot.flag.implementations.ServerPlotFlag) PlotFlag(com.plotsquared.core.plot.flag.PlotFlag) TextComponent(net.kyori.adventure.text.TextComponent) DoubleFlag(com.plotsquared.core.plot.flag.types.DoubleFlag) StaticCaption(com.plotsquared.core.configuration.caption.StaticCaption) Caption(com.plotsquared.core.configuration.caption.Caption) TranslatableCaption(com.plotsquared.core.configuration.caption.TranslatableCaption) Template(net.kyori.adventure.text.minimessage.Template) CompletableFuture(java.util.concurrent.CompletableFuture) TextComponent(net.kyori.adventure.text.TextComponent) Component(net.kyori.adventure.text.Component) SimpleDateFormat(java.text.SimpleDateFormat) Location(com.plotsquared.core.location.Location)

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