Search in sources :

Example 1 with Location

use of com.plotsquared.core.location.Location in project Bookshelf by LOOHP.

the class PlotSquared6Events method onPlotSquaredCheck.

@SuppressWarnings("unchecked")
@EventHandler(priority = EventPriority.LOWEST)
public void onPlotSquaredCheck(PlayerOpenBookshelfEvent event) {
    if (!Bookshelf.plotSquaredHook) {
        return;
    }
    if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(event.getLocation().getWorld().getName())) {
        return;
    }
    org.bukkit.entity.Player bukkitPlayer = event.getPlayer();
    PlotPlayer<?> player = PlotPlayer.from(bukkitPlayer);
    if (player.hasPermission("plots.admin.interact.other")) {
        return;
    }
    org.bukkit.Location bukkitLocation = event.getLocation();
    Location location = Location.at(bukkitLocation.getWorld().getName(), bukkitLocation.getBlockX(), bukkitLocation.getBlockY(), bukkitLocation.getBlockZ());
    PlotArea plotarea = PlotSquared.get().getPlotAreaManager().getApplicablePlotArea(location);
    if (plotarea == null) {
        return;
    }
    Plot plot = plotarea.getPlot(location);
    if (plot == null) {
        return;
    }
    for (PlotFlag<?, ?> flag : plot.getFlags()) {
        if (flag instanceof UseFlag) {
            for (BlockTypeWrapper blockTypeWarpper : (List<BlockTypeWrapper>) flag.getValue()) {
                if (blockTypeWarpper.accepts(ADAPTED_BOOKSHELF_TYPE)) {
                    return;
                }
            }
        }
    }
    if (plot.getOwners().contains(player.getUUID())) {
        return;
    }
    if (plot.getTrusted().contains(player.getUUID())) {
        return;
    }
    if (plot.getOwners().stream().anyMatch(each -> Bukkit.getPlayer(each) != null)) {
        if (plot.getMembers().contains(player.getUUID())) {
            return;
        }
    }
    try {
        plotPlayerSendMessageMethod.invoke(player, TranslatableCaption.of("permission.no_permission_event"), Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_OTHER)));
    } catch (Exception ignore) {
    }
    event.setCancelled(true);
}
Also used : PlotArea(com.plotsquared.core.plot.PlotArea) Plot(com.plotsquared.core.plot.Plot) UseFlag(com.plotsquared.core.plot.flag.implementations.UseFlag) BlockTypeWrapper(com.plotsquared.core.plot.flag.types.BlockTypeWrapper) List(java.util.List) Location(com.plotsquared.core.location.Location) EventHandler(org.bukkit.event.EventHandler)

Example 2 with Location

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

the class WorldUtil method upload.

public void upload(@NonNull final Plot plot, @Nullable final UUID uuid, @Nullable final String file, @NonNull final RunnableVal<URL> whenDone) {
    plot.getHome(home -> SchematicHandler.upload(uuid, file, "zip", new RunnableVal<>() {

        @Override
        public void run(OutputStream output) {
            try (final ZipOutputStream zos = new ZipOutputStream(output)) {
                File dat = getDat(plot.getWorldName());
                Location spawn = getSpawn(plot.getWorldName());
                if (dat != null) {
                    ZipEntry ze = new ZipEntry("world" + File.separator + dat.getName());
                    zos.putNextEntry(ze);
                    try (NBTInputStream nis = new NBTInputStream(new GZIPInputStream(new FileInputStream(dat)))) {
                        Map<String, Tag> tag = ((CompoundTag) nis.readNamedTag().getTag()).getValue();
                        Map<String, Tag> newMap = new HashMap<>();
                        for (Map.Entry<String, Tag> entry : tag.entrySet()) {
                            if (!entry.getKey().equals("Data")) {
                                newMap.put(entry.getKey(), entry.getValue());
                                continue;
                            }
                            Map<String, Tag> data = new HashMap<>(((CompoundTag) entry.getValue()).getValue());
                            data.put("SpawnX", new IntTag(home.getX()));
                            data.put("SpawnY", new IntTag(home.getY()));
                            data.put("SpawnZ", new IntTag(home.getZ()));
                            newMap.put("Data", new CompoundTag(data));
                        }
                        try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
                            try (NBTOutputStream out = new NBTOutputStream(new GZIPOutputStream(baos, true))) {
                                // TODO Find what this should be called
                                out.writeNamedTag("Schematic????", new CompoundTag(newMap));
                            }
                            zos.write(baos.toByteArray());
                        }
                    }
                }
                setSpawn(spawn);
                byte[] buffer = new byte[1024];
                Set<BlockVector2> added = new HashSet<>();
                for (Plot current : plot.getConnectedPlots()) {
                    Location bot = current.getBottomAbs();
                    Location top = current.getTopAbs();
                    int brx = bot.getX() >> 9;
                    int brz = bot.getZ() >> 9;
                    int trx = top.getX() >> 9;
                    int trz = top.getZ() >> 9;
                    Set<BlockVector2> files = getChunkChunks(bot.getWorldName());
                    for (BlockVector2 mca : files) {
                        if (mca.getX() >= brx && mca.getX() <= trx && mca.getZ() >= brz && mca.getZ() <= trz && !added.contains(mca)) {
                            final File file = getMcr(plot.getWorldName(), mca.getX(), mca.getZ());
                            if (file != null) {
                                // final String name = "r." + (x - cx) + "." + (z - cz) + ".mca";
                                String name = file.getName();
                                final ZipEntry ze = new ZipEntry("world" + File.separator + "region" + File.separator + name);
                                zos.putNextEntry(ze);
                                added.add(mca);
                                try (FileInputStream in = new FileInputStream(file)) {
                                    int len;
                                    while ((len = in.read(buffer)) > 0) {
                                        zos.write(buffer, 0, len);
                                    }
                                }
                                zos.closeEntry();
                            }
                        }
                    }
                }
                zos.closeEntry();
                zos.flush();
                zos.finish();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }, whenDone));
}
Also used : HashMap(java.util.HashMap) ZipOutputStream(java.util.zip.ZipOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) NBTOutputStream(com.sk89q.jnbt.NBTOutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) ZipEntry(java.util.zip.ZipEntry) GZIPInputStream(java.util.zip.GZIPInputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) CompoundTag(com.sk89q.jnbt.CompoundTag) IntTag(com.sk89q.jnbt.IntTag) HashSet(java.util.HashSet) Plot(com.plotsquared.core.plot.Plot) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) NBTOutputStream(com.sk89q.jnbt.NBTOutputStream) BlockVector2(com.sk89q.worldedit.math.BlockVector2) FileInputStream(java.io.FileInputStream) ZipOutputStream(java.util.zip.ZipOutputStream) RunnableVal(com.plotsquared.core.util.task.RunnableVal) NBTInputStream(com.sk89q.jnbt.NBTInputStream) IntTag(com.sk89q.jnbt.IntTag) CompoundTag(com.sk89q.jnbt.CompoundTag) Tag(com.sk89q.jnbt.Tag) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) Location(com.plotsquared.core.location.Location)

Example 3 with Location

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

the class Middle method onCommand.

@Override
public boolean onCommand(PlotPlayer<?> player, String[] arguments) {
    Location location = player.getLocation();
    Plot plot = location.getPlot();
    if (plot == null) {
        player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
        return false;
    }
    plot.getCenter(center -> player.teleport(center, TeleportCause.COMMAND_MIDDLE));
    player.sendMessage(TranslatableCaption.of("teleport.teleported_to_plot"));
    return true;
}
Also used : Plot(com.plotsquared.core.plot.Plot) Location(com.plotsquared.core.location.Location)

Example 4 with Location

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

the class Remove method onCommand.

@Override
public boolean onCommand(PlotPlayer<?> player, String[] args) {
    Location location = player.getLocation();
    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_REMOVE)) {
        player.sendMessage(TranslatableCaption.of("permission.no_plot_perms"));
        return true;
    }
    PlayerManager.getUUIDsFromString(args[0], (uuids, throwable) -> {
        int count = 0;
        if (throwable instanceof TimeoutException) {
            player.sendMessage(TranslatableCaption.of("players.fetching_players_timeout"));
            return;
        } else if (throwable != null) {
            player.sendMessage(TranslatableCaption.of("errors.invalid_player"), Template.of("value", args[0]));
            return;
        } else if (!uuids.isEmpty()) {
            for (UUID uuid : uuids) {
                if (plot.getTrusted().contains(uuid)) {
                    if (plot.removeTrusted(uuid)) {
                        this.eventDispatcher.callTrusted(player, plot, uuid, false);
                        count++;
                    }
                } else if (plot.getMembers().contains(uuid)) {
                    if (plot.removeMember(uuid)) {
                        this.eventDispatcher.callMember(player, plot, uuid, false);
                        count++;
                    }
                } else if (plot.getDenied().contains(uuid)) {
                    if (plot.removeDenied(uuid)) {
                        this.eventDispatcher.callDenied(player, plot, uuid, false);
                        count++;
                    }
                } else if (uuid == DBFunc.EVERYONE) {
                    if (plot.removeTrusted(uuid)) {
                        this.eventDispatcher.callTrusted(player, plot, uuid, false);
                        count++;
                    } else if (plot.removeMember(uuid)) {
                        this.eventDispatcher.callMember(player, plot, uuid, false);
                        count++;
                    } else if (plot.removeDenied(uuid)) {
                        this.eventDispatcher.callDenied(player, plot, uuid, false);
                        count++;
                    }
                }
            }
        }
        if (count == 0) {
            player.sendMessage(TranslatableCaption.of("errors.invalid_player"), Template.of("value", args[0]));
        } else {
            player.sendMessage(TranslatableCaption.of("member.removed_players"), Template.of("amount", count + ""));
        }
    });
    return true;
}
Also used : Plot(com.plotsquared.core.plot.Plot) UUID(java.util.UUID) Location(com.plotsquared.core.location.Location) TimeoutException(java.util.concurrent.TimeoutException)

Example 5 with Location

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

the class Remove method tab.

@Override
public Collection<Command> tab(final PlotPlayer<?> player, final String[] args, final boolean space) {
    Location location = player.getLocation();
    Plot plot = location.getPlotAbs();
    if (plot == null) {
        return Collections.emptyList();
    }
    return TabCompletions.completeAddedPlayers(player, plot, String.join(",", args).trim(), Collections.singletonList(player.getName()));
}
Also used : Plot(com.plotsquared.core.plot.Plot) 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