Java Code Examples for com.griefcraft.model.Protection#getType()
The following examples show how to use
com.griefcraft.model.Protection#getType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LWCBlockListener.java From Modern-LWC with MIT License | 5 votes |
@SuppressWarnings("deprecation") @EventHandler(ignoreCancelled = true) public void onBlockPlace(BlockPlaceEvent event) { if (!LWC.ENABLED) { return; } LWC lwc = plugin.getLWC(); Player player = event.getPlayer(); Block block = event.getBlockPlaced(); ProtectionCache cache = lwc.getProtectionCache(); String cacheKey = cache.cacheKey(block.getLocation()); // In the event they place a block, remove any known nulls there if (cache.isKnownNull(cacheKey)) { cache.remove(cacheKey); } // check if the block is blacklisted if (blacklistedBlocks.contains(block.getType())) { // it's blacklisted, check for a protected chest for (Protection protection : lwc.findAdjacentProtectionsOnAllSides(block)) { if (protection != null) { if (!lwc.canAccessProtection(player, protection) || (protection.getType() == Protection.Type.DONATION && !lwc.canAdminProtection(player, protection))) { // they can't access the protection .. event.setCancelled(true); return; } } } } }
Example 2
Source File: LWC114Listener.java From Modern-LWC with MIT License | 5 votes |
@EventHandler(ignoreCancelled = true) public void onPlayerTakeLecternBook(PlayerTakeLecternBookEvent event) { LWC lwc = LWC.getInstance(); Protection protection = lwc.findProtection(event.getLectern()); if (protection == null || protection.isOwner(event.getPlayer()) || protection.getType() == Protection.Type.PUBLIC) { return; } if (protection.getAccess(event.getPlayer().getUniqueId().toString(), Permission.Type.PLAYER) == Permission.Access.NONE) { event.setCancelled(true); } }
Example 3
Source File: InfoModule.java From Modern-LWC with MIT License | 4 votes |
@Override public void onProtectionInteract(LWCProtectionInteractEvent event) { if (event.getResult() != Result.DEFAULT) { return; } if (!event.hasAction("info")) { return; } LWC lwc = event.getLWC(); Protection protection = event.getProtection(); Player player = event.getPlayer(); event.setResult(Result.CANCEL); String type = lwc.getPlugin().getMessageParser().parseMessage(protection.typeToString().toLowerCase()); lwc.sendLocale(player, "lwc.info", "owner", protection.getFormattedOwnerPlayerName(), "type", type); if (event.canAdmin()) { if (protection.getType() == Protection.Type.PRIVATE || protection.getType() == Protection.Type.DONATION) { lwc.sendLocale(player, "lwc.acl", "size", protection.getPermissions().size()); int index = 0; for (Permission permission : protection.getPermissions()) { if (index >= 9) { break; } player.sendMessage(permission.toString()); index++; } if (index == 0) { lwc.sendLocale(player, "lwc.acl.empty"); } else if (index >= 9) { lwc.sendLocale(player, "lwc.acl.limitreached"); } player.sendMessage(""); } } if (lwc.isAdmin(player)) { lwc.sendLocale(player, "protection.interact.info.raw", "raw", protection.toString()); } lwc.removeModes(player); }
Example 4
Source File: UnlockModule.java From Modern-LWC with MIT License | 4 votes |
@Override public void onCommand(LWCCommandEvent event) { if (event.isCancelled()) { return; } if (!event.hasFlag("u", "unlock")) { return; } LWC lwc = event.getLWC(); CommandSender sender = event.getSender(); String[] args = event.getArgs(); event.setCancelled(true); if (!(sender instanceof Player)) { lwc.sendLocale(sender, "lwc.onlyrealplayers"); return; } if (!lwc.hasPlayerPermission(sender, "lwc.unlock")) { lwc.sendLocale(sender, "protection.accessdenied"); return; } if (args.length < 1) { lwc.sendSimpleUsage(sender, "/lwc -u <Password>"); return; } LWCPlayer player = lwc.wrapPlayer(sender); String password = join(args, 0); password = encrypt(password); // see if they have the protection interaction action Action action = player.getAction("interacted"); if (action == null) { lwc.sendLocale(sender, "lwc.unlock.noselection"); } else { Protection protection = action.getProtection(); if (protection == null) { lwc.sendLocale(player, "protection.internalerror", "id", "unlock"); return; } if (protection.getType() != Protection.Type.PASSWORD) { lwc.sendLocale(player, "protection.unlock.notpassword"); return; } if (protection.getPassword().equals(password)) { player.addAccessibleProtection(protection); player.removeAction(action); lwc.sendLocale(player, "protection.unlock.password.valid"); } else { lwc.sendLocale(player, "protection.unlock.password.invalid"); } } }
Example 5
Source File: Towny.java From Modern-LWC with MIT License | 4 votes |
@Override public void onAccessRequest(LWCAccessEvent event) { Player player = event.getPlayer(); Protection protection = event.getProtection(); if (event.getAccess() != Permission.Access.NONE) { return; } if (protection.getType() != Protection.Type.PRIVATE) { return; } if (towny == null) { return; } for (Permission permission : protection.getPermissions()) { if (permission.getType() != Permission.Type.TOWN) { continue; } // Does the town exist? try { Town town = WorldCoord.parseWorldCoord(event.getProtection().getBlock()).getTownBlock().getTown(); if (town == null) { return; } // check if the player is a resident of said town if (!town.hasResident(player.getName())) { // Uh-oh! event.setAccess(Permission.Access.NONE); } else if (town.getMayor().getName().equalsIgnoreCase(player.getName())) { event.setAccess(Permission.Access.ADMIN); } else { // They're in the town :-) event.setAccess(Permission.Access.PLAYER); } } catch (Exception e) { System.out.println(e.getMessage()); } } }
Example 6
Source File: TownyModule.java From Modern-LWC with MIT License | 4 votes |
@SuppressWarnings("deprecation") @Override public void onAccessRequest(LWCAccessEvent event) { Player player = event.getPlayer(); Protection protection = event.getProtection(); if (event.getAccess() != Permission.Access.NONE) { return; } if (protection.getType() != Protection.Type.PRIVATE) { return; } if (towny == null) { return; } for (Permission permission : protection.getPermissions()) { if (permission.getType() != Permission.Type.TOWN) { continue; } String townName = permission.getName(); // Does the town exist? try { Town town = towny.getTownyUniverse().getTown(townName); if (town == null) { return; } // check if the player is a resident of said town if (!town.hasResident(player.getName())) { // Uh-oh! event.setAccess(Permission.Access.NONE); } else { // They're in the town :-) event.setAccess(Permission.Access.PLAYER); } // If they're the major, let them admin the protection if (town.getMayor().getName().equalsIgnoreCase(player.getName())) { event.setAccess(Permission.Access.ADMIN); } } catch (Exception e) { } } }
Example 7
Source File: LWC.java From Modern-LWC with MIT License | 4 votes |
/** * Check if a player has the ability to administrate a protection * * @param player * @param protection * @return */ public boolean canAdminProtection(Player player, Protection protection) { if (protection == null || player == null) { return true; } if (isAdmin(player)) { return true; } // Their access level Permission.Access access = Permission.Access.NONE; switch (protection.getType()) { case PUBLIC: if (protection.isOwner(player)) { return true; } break; case PASSWORD: if (protection.isOwner(player) && wrapPlayer(player).getAccessibleProtections().contains(protection)) { return true; } break; case PRIVATE: case DONATION: if (protection.isOwner(player)) { return true; } if (protection.getAccess(player.getUniqueId().toString(), Permission.Type.PLAYER) == Permission.Access.ADMIN) { return true; } if (protection.getAccess(player.getName(), Permission.Type.PLAYER) == Permission.Access.ADMIN) { return true; } for (String groupName : permissions.getGroups(player)) { if (protection.getAccess(groupName, Permission.Type.GROUP) == Permission.Access.ADMIN) { return true; } } break; default: break; } // call the canAccessProtection hook LWCAccessEvent event = new LWCAccessEvent(player, protection, access); moduleLoader.dispatchEvent(event); return event.getAccess() == Permission.Access.ADMIN; }
Example 8
Source File: LWC.java From Modern-LWC with MIT License | 4 votes |
/** * Check if a player has the ability to access a protection * * @param player * @param protection * @return */ @SuppressWarnings("deprecation") public boolean canAccessProtection(Player player, Protection protection) { if (protection == null || player == null) { return true; } if (isAdmin(player)) { return true; } if (isMod(player)) { Player protectionOwner = protection.getBukkitOwner(); if (protectionOwner == null) { return true; } if (!isAdmin(protectionOwner)) { return true; } } // Their access level Permission.Access access = Permission.Access.NONE; switch (protection.getType()) { case PUBLIC: case DONATION: return true; case PASSWORD: if (wrapPlayer(player).getAccessibleProtections().contains(protection)) { return true; } break; case PRIVATE: if (protection.isOwner(player)) { return true; } if (protection.getAccess(player.getUniqueId().toString(), Permission.Type.PLAYER) .ordinal() >= Permission.Access.PLAYER.ordinal()) { return true; } if (protection.getAccess(player.getName(), Permission.Type.PLAYER).ordinal() >= Permission.Access.PLAYER .ordinal()) { return true; } // Check for item keys for (Permission permission : protection.getPermissions()) { if (permission.getType() != Permission.Type.ITEM) { continue; } // Get the item they need to have int item = Integer.parseInt(permission.getName()); // Are they wielding it? BlockCache blockCache = BlockCache.getInstance(); if (blockCache.getBlockId(player.getItemInHand().getType()) == item) { return true; } } for (String groupName : permissions.getGroups(player)) { if (protection.getAccess(groupName, Permission.Type.GROUP).ordinal() >= Permission.Access.PLAYER .ordinal()) { return true; } } break; default: break; } // call the canAccessProtection hook LWCAccessEvent event = new LWCAccessEvent(player, protection, access); moduleLoader.dispatchEvent(event); return event.getAccess() == Permission.Access.PLAYER || event.getAccess() == Permission.Access.ADMIN; }