Search in sources :

Example 11 with PlayerRegion

use of br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion in project RedProtect by FabioZumbi12.

the class Region method addAdmin.

/**
 * Add an admin to the Region. The string need to be UUID if Online Mode, or Player Name if Offline Mode.
 *
 * @param uuid - UUID or Player Name.
 */
public void addAdmin(String uuid) {
    setToSave(true);
    String name = RedProtect.get().getUtil().UUIDtoPlayer(uuid).toLowerCase();
    PlayerRegion pInfo = new PlayerRegion(RedProtect.get().getUtil().PlayerToUUID(uuid), name);
    this.members.removeIf(m -> m.getUUID().equalsIgnoreCase(uuid) || m.getPlayerName().equalsIgnoreCase(uuid));
    this.leaders.removeIf(m -> m.getUUID().equalsIgnoreCase(uuid) || m.getPlayerName().equalsIgnoreCase(uuid));
    this.admins.add(pInfo);
    RedProtect.get().getRegionManager().updateLiveRegion(this, "leaders", serializeMembers(leaders));
    RedProtect.get().getRegionManager().updateLiveRegion(this, "admins", serializeMembers(admins));
    RedProtect.get().getRegionManager().updateLiveRegion(this, "members", serializeMembers(members));
}
Also used : PlayerRegion(br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion)

Example 12 with PlayerRegion

use of br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion in project RedProtect by FabioZumbi12.

the class PlayerListener method EnterExitNotify.

private void EnterExitNotify(Region r, Player p) {
    if (RedProtect.get().getConfigManager().configRoot().notify.region_enter_mode.equalsIgnoreCase("OFF")) {
        return;
    }
    if (!r.canEnter(p)) {
        return;
    }
    String leaderstring;
    String m = "";
    // Enter-Exit notifications
    if (r.getWelcome().equals("")) {
        if (RedProtect.get().getConfigManager().configRoot().notify.region_enter_mode.equalsIgnoreCase("BOSSBAR") || RedProtect.get().getConfigManager().configRoot().notify.region_enter_mode.equalsIgnoreCase("ACTIONBAR") || RedProtect.get().getConfigManager().configRoot().notify.region_enter_mode.equalsIgnoreCase("CHAT")) {
            StringBuilder leaderstringBuilder = new StringBuilder();
            for (PlayerRegion leader : r.getLeaders()) {
                leaderstringBuilder.append(", ").append(leader.getPlayerName());
            }
            leaderstring = leaderstringBuilder.toString();
            if (r.getLeaders().size() > 0) {
                leaderstring = leaderstring.substring(2);
            } else {
                leaderstring = "None";
            }
            m = RedProtect.get().getLanguageManager().get("playerlistener.region.entered");
            m = m.replace("{leaders}", leaderstring);
            m = m.replace("{region}", r.getName());
        }
        if (RedProtect.get().bukkitVersion >= 1110) {
            SendNotifyMsg(p, m, "GREEN");
        } else {
            SendNotifyMsg(p, m, null);
        }
    } else {
        String wel = ChatColor.translateAlternateColorCodes('&', r.getWelcome().replace("{r}", r.getName()).replace("{player}", p.getName()));
        SendWelcomeMsg(p, RedProtect.get().getLanguageManager().get("playerlistener.region.welcome").replace("{region}", r.getName()).replace("{message}", wel));
    }
}
Also used : PlayerRegion(br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion)

Example 13 with PlayerRegion

use of br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion in project RedProtect by FabioZumbi12.

the class WEHook method pasteWithWE.

public static Region pasteWithWE(Player p, File file) {
    World world = p.getWorld();
    Location loc = p.getLocation();
    final Region[] r = { null };
    if (!p.getLocation().getBlock().getRelative(BlockFace.DOWN).getType().isSolid()) {
        RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.needground");
        return null;
    }
    Clipboard clipboard = null;
    ClipboardFormat format = ClipboardFormats.findByFile(file);
    if (format == null) {
        RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.copyfail");
        return null;
    }
    try (ClipboardReader reader = format.getReader(new FileInputStream(file))) {
        clipboard = reader.read();
    } catch (IOException e) {
        CoreUtil.printJarVersion();
        e.printStackTrace();
    }
    if (clipboard != null) {
        try (EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(world), -1)) {
            BlockVector3 to = BlockVector3.at(loc.getX(), loc.getY(), loc.getZ());
            // Rotate to player looking direction
            float yaw = loc.getYaw();
            if (yaw < 0) {
                yaw += 360;
            }
            int rotate = 0;
            if (yaw >= 315 || yaw < 45) {
                rotate = 180;
            } else if (yaw < 135) {
                rotate = 270;
            } else if (yaw < 225) {
                rotate = 0;
            } else if (yaw < 315) {
                rotate = 90;
            }
            ClipboardHolder holder = new ClipboardHolder(clipboard);
            AffineTransform transform = new AffineTransform();
            transform = transform.rotateY(-rotate);
            holder.setTransform(holder.getTransform().combine(transform));
            Operation operation = holder.createPaste(editSession).to(to).ignoreAirBlocks(false).build();
            Operations.complete(operation);
            // Select the region min and max
            BlockVector3 clipboardOffset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin());
            Vector3 realTo = to.toVector3().add(holder.getTransform().apply(clipboardOffset.toVector3()));
            Vector3 locMax = realTo.add(holder.getTransform().apply(clipboard.getRegion().getMaximumPoint().subtract(clipboard.getRegion().getMinimumPoint()).toVector3()));
            Location min = new Location(world, realTo.getX(), realTo.getY(), realTo.getZ());
            Location max = new Location(world, locMax.getX(), locMax.getY(), locMax.getZ());
            if (RedProtect.get().getConfigManager().configRoot().region_settings.autoexpandvert_ondefine) {
                min.setY(p.getWorld().getMinHeight());
                max.setY(p.getWorld().getMaxHeight());
                if (RedProtect.get().getConfigManager().configRoot().region_settings.claim.miny != -1)
                    min.setY(RedProtect.get().getConfigManager().configRoot().region_settings.claim.miny);
                if (RedProtect.get().getConfigManager().configRoot().region_settings.claim.maxy != -1)
                    max.setY(RedProtect.get().getConfigManager().configRoot().region_settings.claim.maxy);
            }
            RedProtect.get().getLanguageManager().sendMessage(p, "regionbuilder.creating");
            // Run claim async
            Bukkit.getScheduler().runTaskAsynchronously(RedProtect.get(), () -> {
                RegionBuilder rb2 = new DefineRegionBuilder(p, min, max, "", new PlayerRegion(p.getUniqueId().toString(), p.getName()), new HashSet<>(), false);
                if (rb2.ready()) {
                    r[0] = rb2.build();
                }
            });
        } catch (WorldEditException e) {
            CoreUtil.printJarVersion();
            e.printStackTrace();
            r[0] = null;
        }
    }
    return r[0];
}
Also used : PlayerRegion(br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion) ClipboardHolder(com.sk89q.worldedit.session.ClipboardHolder) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Vector3(com.sk89q.worldedit.math.Vector3) IOException(java.io.IOException) Operation(com.sk89q.worldedit.function.operation.Operation) World(org.bukkit.World) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) BlockVector3(com.sk89q.worldedit.math.BlockVector3) ClipboardFormat(com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat) FileInputStream(java.io.FileInputStream) PlayerRegion(br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) AffineTransform(com.sk89q.worldedit.math.transform.AffineTransform) DefineRegionBuilder(br.net.fabiozumbi12.RedProtect.Bukkit.actions.DefineRegionBuilder) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) ClipboardReader(com.sk89q.worldedit.extent.clipboard.io.ClipboardReader) DefineRegionBuilder(br.net.fabiozumbi12.RedProtect.Bukkit.actions.DefineRegionBuilder) RegionBuilder(br.net.fabiozumbi12.RedProtect.Bukkit.region.RegionBuilder) Location(org.bukkit.Location)

Example 14 with PlayerRegion

use of br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion in project RedProtect by FabioZumbi12.

the class WEHook method pasteWithWE.

public static Region pasteWithWE(Player p, File file) {
    Location<World> loc = p.getLocation();
    Region r = null;
    if (p.getLocation().getBlockRelative(Direction.DOWN).getBlock().getType().equals(BlockTypes.WATER) || p.getLocation().getBlockRelative(Direction.DOWN).getBlock().getType().equals(BlockTypes.FLOWING_WATER)) {
        RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.needground");
        return null;
    }
    SpongePlayer sp = SpongeWorldEdit.inst().wrapPlayer(p);
    SpongeWorld ws = SpongeWorldEdit.inst().getWorld(p.getWorld());
    LocalSession session = SpongeWorldEdit.inst().getSession(p);
    Closer closer = Closer.create();
    try {
        ClipboardFormat format = ClipboardFormat.findByAlias("schematic");
        FileInputStream fis = closer.register(new FileInputStream(file));
        BufferedInputStream bis = closer.register(new BufferedInputStream(fis));
        ClipboardReader reader = format.getReader(bis);
        WorldData worldData = ws.getWorldData();
        Clipboard clipboard = reader.read(ws.getWorldData());
        session.setClipboard(new ClipboardHolder(clipboard, worldData));
        Vector bmin = clipboard.getMinimumPoint();
        Vector bmax = clipboard.getMaximumPoint();
        Location<World> min = loc.add(bmin.getX(), bmin.getY(), bmin.getZ());
        Location<World> max = loc.add(bmax.getX(), bmax.getY(), bmax.getZ());
        PlayerRegion leader = new PlayerRegion(p.getUniqueId().toString(), p.getName());
        RegionBuilder rb2 = new DefineRegionBuilder(p, min, max, "", leader, new HashSet<>(), false);
        if (rb2.ready()) {
            r = rb2.build();
        }
        ClipboardHolder holder = session.getClipboard();
        Operation op = holder.createPaste(session.createEditSession(sp), ws.getWorldData()).to(session.getPlacementPosition(sp)).build();
        Operations.completeLegacy(op);
    } catch (IOException | EmptyClipboardException | IncompleteRegionException | MaxChangedBlocksException e) {
        CoreUtil.printJarVersion();
        e.printStackTrace();
    }
    return r;
}
Also used : SpongePlayer(com.sk89q.worldedit.sponge.SpongePlayer) Operation(com.sk89q.worldedit.function.operation.Operation) SpongeWorld(com.sk89q.worldedit.sponge.SpongeWorld) World(org.spongepowered.api.world.World) ClipboardFormat(com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat) BufferedInputStream(java.io.BufferedInputStream) SpongeWorld(com.sk89q.worldedit.sponge.SpongeWorld) DefineRegionBuilder(br.net.fabiozumbi12.RedProtect.Sponge.actions.DefineRegionBuilder) Closer(com.sk89q.worldedit.util.io.Closer) PlayerRegion(br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion) ClipboardHolder(com.sk89q.worldedit.session.ClipboardHolder) WorldData(com.sk89q.worldedit.world.registry.WorldData) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) PlayerRegion(br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) ClipboardReader(com.sk89q.worldedit.extent.clipboard.io.ClipboardReader) DefineRegionBuilder(br.net.fabiozumbi12.RedProtect.Sponge.actions.DefineRegionBuilder) RegionBuilder(br.net.fabiozumbi12.RedProtect.Sponge.region.RegionBuilder)

Example 15 with PlayerRegion

use of br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion in project RedProtect by FabioZumbi12.

the class PlayerListener method onInteractBlock.

// listen all
@Listener(order = Order.FIRST)
public void onInteractBlock(InteractBlockEvent event, @First Player p) {
    BlockSnapshot b = event.getTargetBlock();
    BlockState bstate = b.getState();
    Location<World> l;
    if (!b.getState().getType().equals(BlockTypes.AIR)) {
        l = b.getLocation().get();
        RedProtect.get().logger.debug(LogLevel.PLAYER, "PlayerListener - Is InteractBlockEvent event. The block is " + bstate.getType().getName());
    } else {
        l = p.getLocation();
    }
    Region r = RedProtect.get().getRegionManager().getTopRegion(l, this.getClass().getName());
    ItemType itemInHand = ItemTypes.NONE;
    ItemStack stack;
    if (!RedProtect.get().getVersionHelper().getItemMainHand(p).isEmpty()) {
        stack = RedProtect.get().getVersionHelper().getItemMainHand(p);
        itemInHand = RedProtect.get().getVersionHelper().getItemType(stack);
        if (RedProtect.get().getUtil().removeGuiItem(stack)) {
            p.setItemInHand(HandTypes.MAIN_HAND, ItemStack.of(ItemTypes.NONE, 1));
            event.setCancelled(true);
        }
    } else if (!RedProtect.get().getVersionHelper().getItemOffHand(p).isEmpty()) {
        stack = RedProtect.get().getVersionHelper().getItemOffHand(p);
        itemInHand = RedProtect.get().getVersionHelper().getItemType(stack);
        if (RedProtect.get().getUtil().removeGuiItem(stack)) {
            p.setItemInHand(HandTypes.OFF_HAND, ItemStack.of(ItemTypes.NONE, 1));
            event.setCancelled(true);
        }
    }
    if (itemInHand.getId().equalsIgnoreCase(RedProtect.get().getConfigManager().configRoot().wands.infoWandID)) {
        r = RedProtect.get().getRegionManager().getTopRegion(l, this.getClass().getName());
        if (r == null) {
            RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.noregion.atblock");
        } else if (RedProtect.get().getPermissionHandler().hasRegionPermMember(p, "infowand", r)) {
            p.sendMessage(RedProtect.get().getUtil().toText(RedProtect.get().getLanguageManager().get("general.color") + "--------------- [&e" + r.getName() + RedProtect.get().getLanguageManager().get("general.color") + "] ---------------"));
            p.sendMessage(r.info());
            p.sendMessage(RedProtect.get().getUtil().toText(RedProtect.get().getLanguageManager().get("general.color") + "-----------------------------------------"));
        } else {
            p.sendMessage(RedProtect.get().getUtil().toText(RedProtect.get().getLanguageManager().get("playerlistener.region.entered").replace("{region}", r.getName()).replace("{leaders}", r.getLeadersDesc())));
        }
        event.setCancelled(true);
        return;
    }
    // start player checks
    if (r == null) {
        if (bstate instanceof Container || RedProtect.get().getConfigManager().configRoot().private_cat.allowed_blocks.stream().anyMatch(bstate.getType().getName()::matches)) {
            boolean out = RedProtect.get().getConfigManager().configRoot().private_cat.allow_outside;
            if (out && !cont.canOpen(b, p)) {
                if (!RedProtect.get().getPermissionHandler().hasPerm(p, "redprotect.bypass")) {
                    RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.cantopen");
                    event.setCancelled(true);
                } else {
                    int x = b.getLocation().get().getBlockX();
                    int y = b.getLocation().get().getBlockY();
                    int z = b.getLocation().get().getBlockZ();
                    RedProtect.get().getLanguageManager().sendMessage(p, RedProtect.get().getLanguageManager().get("playerlistener.region.opened").replace("{region}", "X:" + x + " Y:" + y + " Z:" + z));
                }
            }
        }
    } else {
        // if (r != null) && (b != null) >>
        if (b.getState().getType().equals(BlockTypes.LOG) || b.getState().getType().equals(BlockTypes.LOG2) || b.getState().getType().equals(BlockTypes.LEAVES) || b.getState().getType().equals(BlockTypes.LEAVES2)) {
            if (!r.canTree(b) && !r.canBuild(p)) {
                event.setCancelled(true);
                RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.cantinteract");
            }
        } else if (b.getState().getType().getName().contains("_pressure_plate")) {
            if (!r.allowPressPlate(p)) {
                event.setCancelled(true);
                RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.cantpressplate");
            }
        } else if (bstate.getType().equals(BlockTypes.DRAGON_EGG) || bstate.getType().equals(BlockTypes.NOTEBLOCK) || bstate.getType().getName().contains("repeater") || bstate.getType().getName().contains("comparator")) {
            if (!r.canBuild(p)) {
                RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.cantinteract");
                event.setCancelled(true);
            }
        } else if (bstate.getType().equals(BlockTypes.BED)) {
            if (!r.isHomeAllowed(p) && !r.canBuild(p)) {
                RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.cantinteract");
                event.setCancelled(true);
            }
        } else if (l.getTileEntity().isPresent() && l.getTileEntity().get() instanceof Sign && RedProtect.get().getConfigManager().configRoot().region_settings.enable_flag_sign) {
            Sign s = (Sign) l.getTileEntity().get();
            if (s.lines().get(0).toPlain().equalsIgnoreCase("[flag]") && r.getFlags().containsKey(s.lines().get(1).toPlain())) {
                String flag = s.lines().get(1).toPlain();
                if (!(r.getFlags().get(flag) instanceof Boolean)) {
                    RedProtect.get().getLanguageManager().sendMessage(p, RedProtect.get().getLanguageManager().get("playerlistener.region.sign.cantflag"));
                    return;
                }
                if (RedProtect.get().getPermissionHandler().hasFlagPerm(p, flag) && (RedProtect.get().getConfigManager().configRoot().flags.containsKey(flag) || RedProtect.get().getConfigManager().ADMIN_FLAGS.contains(flag))) {
                    if (r.isAdmin(p) || r.isLeader(p) || RedProtect.get().getPermissionHandler().hasPerm(p, "redprotect.admin.flag." + flag)) {
                        if (RedProtect.get().getConfigManager().configRoot().flags_configuration.change_flag_delay.enable) {
                            if (RedProtect.get().getConfigManager().configRoot().flags_configuration.change_flag_delay.flags.contains(flag)) {
                                if (!RedProtect.get().changeWait.contains(r.getName() + flag)) {
                                    RedProtect.get().getUtil().startFlagChanger(r.getName(), flag, p);
                                    changeFlag(r, flag, p, s);
                                    return;
                                } else {
                                    RedProtect.get().getLanguageManager().sendMessage(p, RedProtect.get().getLanguageManager().get("gui.needwait.tochange").replace("{seconds}", "" + RedProtect.get().getConfigManager().configRoot().flags_configuration.change_flag_delay.seconds));
                                    return;
                                }
                            }
                        }
                        changeFlag(r, flag, p, s);
                        return;
                    }
                }
                RedProtect.get().getLanguageManager().sendMessage(p, "cmdmanager.region.flag.nopermregion");
            }
        } else if (bstate.getType().equals(BlockTypes.ENDER_CHEST)) {
            if (!r.canEnderChest(p)) {
                RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.cantopen");
                event.setCancelled(true);
            }
        } else if (bstate.getType().getName().contains("spawner")) {
            if (!r.canPlaceSpawner(p)) {
                RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.cantuse");
                event.setCancelled(true);
            }
        } else if (b.getState() instanceof Container || RedProtect.get().getConfigManager().configRoot().private_cat.allowed_blocks.stream().anyMatch(bstate.getType().getName()::matches)) {
            if ((r.canChest(p) && !cont.canOpen(b, p) || (!r.canChest(p) && cont.canOpen(b, p)) || (!r.canChest(p) && !cont.canOpen(b, p)))) {
                RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.cantopen");
                event.setCancelled(true);
            }
        } else if (bstate.getType().getName().contains("lever")) {
            if (!r.canLever(p)) {
                RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.cantlever");
                event.setCancelled(true);
            }
        } else if (bstate.getType().getName().contains("redstone") || bstate.getType().getName().contains("daylight") || bstate.getType().getName().contains("comparator") || bstate.getType().getName().contains("repeater")) {
            if (!r.canRedstone(p)) {
                RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.cantinteract");
                event.setCancelled(true);
            }
        } else if (bstate.getType().getName().contains("button")) {
            if (!r.canButton(p)) {
                RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.cantbutton");
                event.setCancelled(true);
            }
        } else if (DoorManager.isOpenable(b)) {
            if (!r.canDoor(p)) /* || (r.canDoor(p) && !cont.canOpen(b, p))*/
            {
                RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.cantdoor");
                event.setCancelled(true);
            } else {
                DoorManager.ChangeDoor(b, r);
            }
        } else if (bstate.getType().getName().contains("rail")) {
            if (!r.canMinecart(p)) {
                RedProtect.get().getLanguageManager().sendMessage(p, "blocklistener.region.cantplace");
                event.setCancelled(true);
            }
        } else if (bstate.getType().getName().contains("sign") && event instanceof InteractBlockEvent.Secondary) {
            Sign sign = (Sign) b.getLocation().get().getTileEntity().get();
            if (sign.get(Keys.SIGN_LINES).isPresent() && sign.get(Keys.SIGN_LINES).get().get(0).toPlain().equalsIgnoreCase("[flag]") && r.getFlags().containsKey(sign.get(Keys.SIGN_LINES).get().get(1).toPlain())) {
                String flag = sign.get(Keys.SIGN_LINES).get().get(1).toPlain();
                if (!(r.getFlags().get(flag) instanceof Boolean)) {
                    RedProtect.get().getLanguageManager().sendMessage(p, RedProtect.get().getLanguageManager().get("playerlistener.region.sign.cantflag"));
                    return;
                }
                if (RedProtect.get().getPermissionHandler().hasFlagPerm(p, flag) && (RedProtect.get().getConfigManager().configRoot().flags.containsKey(flag) || RedProtect.get().getConfigManager().ADMIN_FLAGS.contains(flag))) {
                    if (r.isAdmin(p) || r.isLeader(p) || RedProtect.get().getPermissionHandler().hasPerm(p, "redprotect.admin.flag." + flag)) {
                        if (RedProtect.get().getConfigManager().configRoot().flags_configuration.change_flag_delay.enable) {
                            if (RedProtect.get().getConfigManager().configRoot().flags_configuration.change_flag_delay.flags.contains(flag)) {
                                if (!RedProtect.get().changeWait.contains(r.getName() + flag)) {
                                    RedProtect.get().getUtil().startFlagChanger(r.getName(), flag, p);
                                    changeFlag(r, flag, p, sign);
                                    return;
                                } else {
                                    RedProtect.get().getLanguageManager().sendMessage(p, RedProtect.get().getLanguageManager().get("gui.needwait.tochange").replace("{seconds}", "" + RedProtect.get().getConfigManager().configRoot().flags_configuration.change_flag_delay.seconds));
                                    return;
                                }
                            }
                        }
                        changeFlag(r, flag, p, sign);
                        return;
                    }
                }
                RedProtect.get().getLanguageManager().sendMessage(p, "cmdmanager.region.flag.nopermregion");
                event.setCancelled(true);
            } else if (!r.canSign(p)) {
                if (b.get(Keys.SIGN_LINES).isPresent()) {
                    List<Text> lines = b.get(Keys.SIGN_LINES).get();
                    for (String tag : RedProtect.get().getConfigManager().configRoot().region_settings.allow_sign_interact_tags) {
                        // check first rule
                        if (tag.equalsIgnoreCase(lines.get(0).toPlain())) {
                            return;
                        }
                        // check if tag is leaders or members names
                        if (tag.equalsIgnoreCase("{membername}")) {
                            for (PlayerRegion leader : r.getLeaders()) {
                                if (lines.get(0).toPlain().equalsIgnoreCase(leader.getPlayerName())) {
                                    return;
                                }
                            }
                            for (PlayerRegion member : r.getMembers()) {
                                if (lines.get(0).toPlain().equalsIgnoreCase(member.getPlayerName())) {
                                    return;
                                }
                            }
                            for (PlayerRegion admin : r.getAdmins()) {
                                if (lines.get(0).toPlain().equalsIgnoreCase(admin.getPlayerName())) {
                                    return;
                                }
                            }
                        }
                        // check if tag is player name
                        if (tag.equalsIgnoreCase("{playername}")) {
                            if (lines.get(0).toPlain().equalsIgnoreCase(RedProtect.get().getUtil().UUIDtoPlayer(p.getName()))) {
                                return;
                            }
                        }
                    }
                }
                RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.cantinteract.signs");
                event.setCancelled(true);
            }
        } else if ((itemInHand.equals(ItemTypes.FLINT_AND_STEEL) || itemInHand.equals(ItemTypes.WATER_BUCKET) || itemInHand.equals(ItemTypes.BUCKET) || itemInHand.equals(ItemTypes.LAVA_BUCKET) || itemInHand.equals(ItemTypes.ITEM_FRAME) || itemInHand.equals(ItemTypes.END_CRYSTAL) || itemInHand.equals(ItemTypes.PAINTING)) && !r.canBuild(p)) {
            RedProtect.get().getLanguageManager().sendMessage(p, RedProtect.get().getLanguageManager().get("playerlistener.region.cantuse"));
            event.setCancelled(true);
        } else if (!r.allowMod(p) && !RedProtect.get().getUtil().isBukkitBlock(bstate)) {
            RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.cantinteract");
            event.setCancelled(true);
        }
    }
}
Also used : PlayerRegion(br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion) ItemType(org.spongepowered.api.item.ItemType) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Text(org.spongepowered.api.text.Text) World(org.spongepowered.api.world.World) Container(org.spongepowered.api.item.inventory.Container) BlockState(org.spongepowered.api.block.BlockState) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) PlayerRegion(br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion) Sign(org.spongepowered.api.block.tileentity.Sign) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Listener(org.spongepowered.api.event.Listener)

Aggregations

PlayerRegion (br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion)31 Region (br.net.fabiozumbi12.RedProtect.Bukkit.Region)11 Region (br.net.fabiozumbi12.RedProtect.Sponge.Region)6 World (org.spongepowered.api.world.World)6 DefineRegionBuilder (br.net.fabiozumbi12.RedProtect.Bukkit.actions.DefineRegionBuilder)4 RegionBuilder (br.net.fabiozumbi12.RedProtect.Bukkit.region.RegionBuilder)4 File (java.io.File)4 IOException (java.io.IOException)4 Player (org.bukkit.entity.Player)4 CoreUtil (br.net.fabiozumbi12.RedProtect.Core.helpers.CoreUtil)3 java.util (java.util)3 Collectors (java.util.stream.Collectors)3 Location (org.bukkit.Location)3 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)3 RedProtect (br.net.fabiozumbi12.RedProtect.Bukkit.RedProtect)2 LogLevel (br.net.fabiozumbi12.RedProtect.Core.helpers.LogLevel)2 Clipboard (com.sk89q.worldedit.extent.clipboard.Clipboard)2 ClipboardFormat (com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat)2 ClipboardReader (com.sk89q.worldedit.extent.clipboard.io.ClipboardReader)2 Operation (com.sk89q.worldedit.function.operation.Operation)2