Java Code Examples for org.spongepowered.api.entity.living.player.User#hasPermission()
The following examples show how to use
org.spongepowered.api.entity.living.player.User#hasPermission() .
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: CommandClaimFlagPlayer.java From GriefDefender with MIT License | 6 votes |
@CommandCompletion("@gdplayers @gdflags @gdmcids @gdtristates @gdcontexts @gddummy") @CommandAlias("cfp") @Description("Gets/Sets flag permission for a player in claim you are standing in.") @Syntax("<player> <flag> <target> <value> [context[key=value]]") @Subcommand("flag player") public void execute(Player player, User user, @Optional String[] args) throws InvalidCommandArgument { this.subject = PermissionHolderCache.getInstance().getOrCreateUser(user); this.friendlySubjectName = user.getName(); if (user.hasPermission(GDPermissions.COMMAND_ADMIN_CLAIMS) && !player.hasPermission(GDPermissions.SET_ADMIN_FLAGS)) { GriefDefenderPlugin.sendMessage(player, MessageCache.getInstance().PERMISSION_PLAYER_ADMIN_FLAGS); return; } super.execute(player, args); }
Example 2
Source File: BuildPermListener.java From Nations with MIT License | 6 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onSignChanged(ChangeSignEvent event, @First User player) { if (!ConfigHandler.getNode("worlds").getNode(event.getTargetTile().getLocation().getExtent().getName()).getNode("enabled").getBoolean()) { return; } if (player.hasPermission("nations.admin.bypass.perm.build")) { return; } if (!DataHandler.getPerm("build", player.getUniqueId(), event.getTargetTile().getLocation())) { event.setCancelled(true); } }
Example 3
Source File: GPClaim.java From GriefPrevention with MIT License | 6 votes |
public Text allowEdit(User user) { if (this.isUserTrusted(user, TrustType.MANAGER)) { return null; } // anyone with deleteclaims permission can modify non-admin claims at any time if (user.hasPermission(GPPermissions.COMMAND_DELETE_CLAIMS)) { return null; } if (this.parent != null && this.getData().doesInheritParent()) { return this.parent.allowEdit(user); } final Text message = GriefPreventionPlugin.instance.messageData.claimOwnerOnly .apply(ImmutableMap.of( "owner", Text.of(this.getOwnerName()) )).build(); return message; }
Example 4
Source File: PermissionHandler.java From RedProtect with GNU General Public License v3.0 | 6 votes |
private int getBlockLimit(User user) { int limit = RedProtect.get().config.configRoot().region_settings.limit_amount; List<Integer> limits = new ArrayList<>(); if (limit > 0) { if (!user.hasPermission("redprotect.limits.blocks.unlimited")) { for (String perm : RedProtect.get().config.configRoot().permissions_limits.blocks) { RedProtect.get().logger.debug(LogLevel.DEFAULT, "Perm: " + perm); if (user.hasPermission(perm)) { RedProtect.get().logger.debug(LogLevel.DEFAULT, "Has block perm: " + perm); String pStr = perm.replaceAll("[^-?0-9]+", ""); if (!pStr.isEmpty()) { limits.add(Integer.parseInt(pStr)); } } } } else { return -1; } } if (limits.size() > 0) { limit = Collections.max(limits); } return limit; }
Example 5
Source File: PermissionHandler.java From RedProtect with GNU General Public License v3.0 | 6 votes |
private int getClaimLimit(User user) { int limit = RedProtect.get().config.configRoot().region_settings.claim.amount_per_player; List<Integer> limits = new ArrayList<>(); if (limit > 0) { if (!user.hasPermission("redprotect.limits.claim.unlimited")) { for (String perm : RedProtect.get().config.configRoot().permissions_limits.claims) { RedProtect.get().logger.debug(LogLevel.DEFAULT, "Perm: " + perm); if (user.hasPermission(perm)) { RedProtect.get().logger.debug(LogLevel.DEFAULT, "Has claim perm: " + perm); String pStr = perm.replaceAll("[^-?0-9]+", ""); if (!pStr.isEmpty()) { limits.add(Integer.parseInt(pStr)); } } } } else { return -1; } } if (limits.size() > 0) { limit = Collections.max(limits); } return limit; }
Example 6
Source File: BuildPermListener.java From Nations with MIT License | 5 votes |
@Listener(order=Order.FIRST, beforeModifications = true) public void onPlayerBreaksBlock(ChangeBlockEvent.Break event) { User user = Utils.getUser(event); if (user != null && user.hasPermission("nations.admin.bypass.perm.build")) { return; } event .getTransactions() .stream() .forEach(trans -> trans.getOriginal().getLocation().ifPresent(loc -> { if (!ConfigHandler.isWhitelisted("break", trans.getFinal().getState().getType().getId()) && ConfigHandler.getNode("worlds").getNode(trans.getFinal().getLocation().get().getExtent().getName()).getNode("enabled").getBoolean()) { if (user == null || !DataHandler.getPerm("build", user.getUniqueId(), loc)) { trans.setValid(false); if (user != null && user instanceof Player) { try { ((Player) user).sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_PERM_BUILD)); } catch (Exception e) {} } } } })); }
Example 7
Source File: AbstractPreventListener.java From FlexibleLogin with MIT License | 5 votes |
private boolean isAllowed(User player) { if (settings.getGeneral().isBypassed(player)) { return true; } if (settings.getGeneral().isCommandOnlyProtection()) { //check if the user is already registered return plugin.getDatabase().getAccount(player).isPresent() || !player.hasPermission(PomData.ARTIFACT_ID + ".registerRequired"); } return plugin.getDatabase().isLoggedIn(player); }
Example 8
Source File: ProtectionManagerImpl.java From EagleFactions with MIT License | 4 votes |
private ProtectionResult canUseItem(final Location<World> location, final User user, final ItemStackSnapshot usedItem) { if(EagleFactionsPlugin.DEBUG_MODE_PLAYERS.contains(user.getUniqueId())) { if(user instanceof Player) { Player player = (Player)user; player.sendMessage(PluginInfo.PLUGIN_PREFIX.concat(Text.of("Usage of item:"))); player.sendMessage(PluginInfo.PLUGIN_PREFIX.concat(Text.of("Location: " + location.toString()))); player.sendMessage(PluginInfo.PLUGIN_PREFIX.concat(Text.of("User: " + user.getName()))); player.sendMessage(PluginInfo.PLUGIN_PREFIX.concat(Text.of("Block at location: " + location.getBlockType().getName()))); player.sendMessage(PluginInfo.PLUGIN_PREFIX.concat(Text.of("Used item: " + usedItem.getType().getName()))); } } final World world = location.getExtent(); //Not claimable worlds should be always ignored by protection system. if(this.protectionConfig.getNotClaimableWorldNames().contains(world.getName())) return ProtectionResult.ok(); if (this.playerManager.hasAdminMode(user)) return ProtectionResult.okAdmin(); final Set<String> safeZoneWorlds = this.protectionConfig.getSafeZoneWorldNames(); final Set<String> warZoneWorlds = this.protectionConfig.getWarZoneWorldNames(); if (safeZoneWorlds.contains(world.getName())) { if (isItemWhitelisted(usedItem.getType().getId(), FactionType.SAFE_ZONE)) return ProtectionResult.okSafeZone(); if (user.hasPermission(PluginPermissions.SAFE_ZONE_INTERACT)) return ProtectionResult.okSafeZone(); else return ProtectionResult.forbiddenSafeZone(); } if (warZoneWorlds.contains(world.getName())) { if (isItemWhitelisted(usedItem.getType().getId(), FactionType.WAR_ZONE)) return ProtectionResult.okWarZone(); if (user.hasPermission(PluginPermissions.WAR_ZONE_INTERACT)) return ProtectionResult.okWarZone(); else return ProtectionResult.forbiddenWarZone(); } final Optional<Faction> optionalChunkFaction = this.factionLogic.getFactionByChunk(world.getUniqueId(), location.getChunkPosition()); final Optional<Faction> optionalPlayerFaction = this.factionLogic.getFactionByPlayerUUID(user.getUniqueId()); if (!optionalChunkFaction.isPresent()) { if (!this.protectionConfig.shouldProtectWildernessFromPlayers()) return ProtectionResult.ok(); else return ProtectionResult.forbidden(); } final Faction chunkFaction = optionalChunkFaction.get(); if (chunkFaction.isSafeZone()) { if (isItemWhitelisted(usedItem.getType().getId(), FactionType.SAFE_ZONE)) return ProtectionResult.okSafeZone(); if (user.hasPermission(PluginPermissions.SAFE_ZONE_INTERACT)) return ProtectionResult.okSafeZone(); else return ProtectionResult.forbiddenSafeZone(); } if (chunkFaction.isWarZone()) { if (isItemWhitelisted(usedItem.getType().getId(), FactionType.WAR_ZONE)) return ProtectionResult.okWarZone(); if (user.hasPermission(PluginPermissions.WAR_ZONE_INTERACT)) return ProtectionResult.okWarZone(); else return ProtectionResult.forbiddenWarZone(); } if (isItemWhitelisted(usedItem.getType().getId(), FactionType.FACTION)) return ProtectionResult.ok(); //If player is not in a faction but there is a faction at chunk if(!optionalPlayerFaction.isPresent()) return ProtectionResult.forbidden(); Faction playerFaction = optionalPlayerFaction.get(); if(this.permsManager.canInteract(user.getUniqueId(), playerFaction, chunkFaction, chunkFaction.getClaimAt(world.getUniqueId(), location.getChunkPosition()).get())) return ProtectionResult.okFactionPerm(); else return ProtectionResult.forbidden(); }
Example 9
Source File: ProtectionManagerImpl.java From EagleFactions with MIT License | 4 votes |
private ProtectionResult canBreak(final Location<World> location, final User user) { if(EagleFactionsPlugin.DEBUG_MODE_PLAYERS.contains(user.getUniqueId())) { if(user instanceof Player) { Player player = (Player)user; player.sendMessage(PluginInfo.PLUGIN_PREFIX.concat(Text.of(TextColors.GOLD, "Block break event!"))); player.sendMessage(PluginInfo.PLUGIN_PREFIX.concat(Text.of(TextColors.GOLD, "Location: " + location.toString()))); player.sendMessage(PluginInfo.PLUGIN_PREFIX.concat(Text.of(TextColors.GOLD, "User: " + user.getName()))); player.sendMessage(PluginInfo.PLUGIN_PREFIX.concat(Text.of(TextColors.GOLD, "Block at location: " + location.getBlockType().getName()))); player.sendMessage(PluginInfo.PLUGIN_PREFIX.concat(Text.of(TextColors.GOLD, "Block id: " + location.getBlockType().getId()))); } } final World world = location.getExtent(); //Not claimable worlds should be always ignored by protection system. if(this.protectionConfig.getNotClaimableWorldNames().contains(world.getName())) return ProtectionResult.ok(); if(this.playerManager.hasAdminMode(user)) return ProtectionResult.okAdmin(); final Set<String> safeZoneWorlds = this.protectionConfig.getSafeZoneWorldNames(); final Set<String> warZoneWorlds = this.protectionConfig.getWarZoneWorldNames(); if (safeZoneWorlds.contains(world.getName())) { if (isBlockWhitelistedForPlaceDestroy(location.getBlockType().getId(), FactionType.SAFE_ZONE)) return ProtectionResult.okSafeZone(); if (user.hasPermission(PluginPermissions.SAFE_ZONE_BUILD)) return ProtectionResult.okSafeZone(); else return ProtectionResult.forbiddenSafeZone(); } if (warZoneWorlds.contains(world.getName())) { if (isBlockWhitelistedForPlaceDestroy(location.getBlockType().getId(), FactionType.WAR_ZONE)) return ProtectionResult.okWarZone(); if (user.hasPermission(PluginPermissions.WAR_ZONE_BUILD)) return ProtectionResult.okWarZone(); else return ProtectionResult.forbiddenWarZone(); } final Optional<Faction> optionalChunkFaction = this.factionLogic.getFactionByChunk(world.getUniqueId(), location.getChunkPosition()); final Optional<Faction> optionalPlayerFaction = this.factionLogic.getFactionByPlayerUUID(user.getUniqueId()); if(optionalChunkFaction.isPresent()) { if(optionalChunkFaction.get().isSafeZone() || optionalChunkFaction.get().isWarZone()) { if(optionalChunkFaction.get().isSafeZone()) { if (isBlockWhitelistedForPlaceDestroy(location.getBlockType().getId(), FactionType.SAFE_ZONE)) return ProtectionResult.okSafeZone(); if (user.hasPermission(PluginPermissions.SAFE_ZONE_BUILD)) return ProtectionResult.okSafeZone(); else return ProtectionResult.forbiddenSafeZone(); } else //WarZone { if (isBlockWhitelistedForPlaceDestroy(location.getBlockType().getId(), FactionType.WAR_ZONE)) return ProtectionResult.okWarZone(); if (user.hasPermission(PluginPermissions.WAR_ZONE_BUILD)) return ProtectionResult.okWarZone(); else return ProtectionResult.forbiddenWarZone(); } } if (isBlockWhitelistedForPlaceDestroy(location.getBlockType().getId(), FactionType.FACTION)) return ProtectionResult.ok(); final Faction chunkFaction = optionalChunkFaction.get(); final Optional<Claim> optionalClaim = chunkFaction.getClaimAt(world.getUniqueId(), location.getChunkPosition()); if (optionalPlayerFaction.filter(faction -> this.permsManager.canBreakBlock(user.getUniqueId(), faction, optionalChunkFaction.get(), optionalClaim.get())).isPresent()) return ProtectionResult.okFactionPerm(); else return ProtectionResult.forbidden(); } else { if (!this.protectionConfig.shouldProtectWildernessFromPlayers()) return ProtectionResult.ok(); else return ProtectionResult.forbidden(); } }
Example 10
Source File: ProtectionManagerImpl.java From EagleFactions with MIT License | 4 votes |
private ProtectionResult canPlace(final Location<World> location, final User user) { if(EagleFactionsPlugin.DEBUG_MODE_PLAYERS.contains(user.getUniqueId())) { if(user instanceof Player) { Player player = (Player)user; player.sendMessage(PluginInfo.PLUGIN_PREFIX.concat(Text.of("Block place:"))); player.sendMessage(PluginInfo.PLUGIN_PREFIX.concat(Text.of("Location: " + location.toString()))); player.sendMessage(PluginInfo.PLUGIN_PREFIX.concat(Text.of("User: " + user.getName()))); player.sendMessage(PluginInfo.PLUGIN_PREFIX.concat(Text.of("Block at location: " + location.getBlockType().getName()))); player.sendMessage(PluginInfo.PLUGIN_PREFIX.concat(Text.of("Item in hand: " + (user.getItemInHand(HandTypes.MAIN_HAND).isPresent() ? user.getItemInHand(HandTypes.MAIN_HAND).get().getType().getName() : "")))); } } World world = location.getExtent(); final String itemId = user.getItemInHand(HandTypes.MAIN_HAND).isPresent() ? user.getItemInHand(HandTypes.MAIN_HAND).get().getType().getId() : ""; //Not claimable worlds should be always ignored by protection system. if(this.protectionConfig.getNotClaimableWorldNames().contains(world.getName())) return ProtectionResult.ok(); if(this.playerManager.hasAdminMode(user)) return ProtectionResult.okAdmin(); final Set<String> safeZoneWorlds = this.protectionConfig.getSafeZoneWorldNames(); final Set<String> warZoneWorlds = this.protectionConfig.getWarZoneWorldNames(); if (safeZoneWorlds.contains(world.getName())) { if (isBlockWhitelistedForPlaceDestroy(itemId, FactionType.SAFE_ZONE)) return ProtectionResult.okSafeZone(); if (user.hasPermission(PluginPermissions.SAFE_ZONE_BUILD)) return ProtectionResult.okSafeZone(); else return ProtectionResult.forbiddenSafeZone(); } if (warZoneWorlds.contains(world.getName())) { if (isBlockWhitelistedForPlaceDestroy(itemId, FactionType.WAR_ZONE)) return ProtectionResult.okWarZone(); if (user.hasPermission(PluginPermissions.WAR_ZONE_BUILD)) return ProtectionResult.okWarZone(); else return ProtectionResult.forbiddenWarZone(); } Optional<Faction> optionalPlayerFaction = this.factionLogic.getFactionByPlayerUUID(user.getUniqueId()); Optional<Faction> optionalChunkFaction = this.factionLogic.getFactionByChunk(world.getUniqueId(), location.getChunkPosition()); if(optionalChunkFaction.isPresent()) { if(optionalChunkFaction.get().isSafeZone() || optionalChunkFaction.get().isWarZone()) { if(optionalChunkFaction.get().isSafeZone()) { if (isBlockWhitelistedForPlaceDestroy(itemId, FactionType.SAFE_ZONE)) return ProtectionResult.okSafeZone(); if (user.hasPermission(PluginPermissions.SAFE_ZONE_BUILD)) return ProtectionResult.okSafeZone(); else return ProtectionResult.forbiddenSafeZone(); } else //WarZone { if (isBlockWhitelistedForPlaceDestroy(itemId, FactionType.WAR_ZONE)) return ProtectionResult.okWarZone(); if (user.hasPermission(PluginPermissions.WAR_ZONE_BUILD)) return ProtectionResult.okWarZone(); else return ProtectionResult.forbiddenWarZone(); } } if (isBlockWhitelistedForPlaceDestroy(location.getBlockType().getId(), FactionType.FACTION)) return ProtectionResult.ok(); final Faction chunkFaction = optionalChunkFaction.get(); if (optionalPlayerFaction.filter(faction -> this.permsManager.canPlaceBlock(user.getUniqueId(), faction, chunkFaction, chunkFaction.getClaimAt(world.getUniqueId(), location.getChunkPosition()).get())).isPresent()) return ProtectionResult.okFactionPerm(); else return ProtectionResult.forbidden(); } else { if (!this.protectionConfig.shouldProtectWildernessFromPlayers()) return ProtectionResult.ok(); else return ProtectionResult.forbidden(); } }
Example 11
Source File: ProtectionManagerImpl.java From EagleFactions with MIT License | 4 votes |
private ProtectionResult canExplode(final Location<World> location, final User user) { final World world = location.getExtent(); if(EagleFactionsPlugin.DEBUG_MODE_PLAYERS.contains(user.getUniqueId())) { if(user instanceof Player) { final Player player = (Player)user; player.sendMessage(PluginInfo.PLUGIN_PREFIX.concat(Text.of("Explosion:"))); player.sendMessage(PluginInfo.PLUGIN_PREFIX.concat(Text.of("Location: " + location.toString()))); player.sendMessage(PluginInfo.PLUGIN_PREFIX.concat(Text.of("User: " + user.getName()))); player.sendMessage(PluginInfo.PLUGIN_PREFIX.concat(Text.of("Block at location: " + location.getBlockType().getName()))); } } //Not claimable worlds should be always ignored by protection system. if(this.protectionConfig.getNotClaimableWorldNames().contains(world.getName())) return ProtectionResult.ok(); boolean shouldProtectWarZoneFromPlayers = this.protectionConfig.shouldProtectWarzoneFromPlayers(); boolean allowExplosionsByOtherPlayersInClaims = this.protectionConfig.shouldAllowExplosionsByOtherPlayersInClaims(); //Check if admin if(this.playerManager.hasAdminMode(user)) return ProtectionResult.okAdmin(); //Check world if (this.protectionConfig.getSafeZoneWorldNames().contains(world.getName())) return ProtectionResult.forbiddenSafeZone(); else if (this.protectionConfig.getWarZoneWorldNames().contains(world.getName())) { if (!shouldProtectWarZoneFromPlayers) return ProtectionResult.okWarZone(); return ProtectionResult.forbiddenWarZone(); } //If no faction final Optional<Faction> optionalChunkFaction = this.factionLogic.getFactionByChunk(world.getUniqueId(), location.getChunkPosition()); if (!optionalChunkFaction.isPresent()) { if (!this.protectionConfig.shouldProtectWildernessFromPlayers()) return ProtectionResult.ok(); else return ProtectionResult.forbidden(); } //If SafeZone or WarZone final Faction chunkFaction = optionalChunkFaction.get(); if(chunkFaction.isSafeZone() || chunkFaction.isWarZone()) { if(chunkFaction.isSafeZone()) { if (user.hasPermission(PluginPermissions.SAFE_ZONE_BUILD)) return ProtectionResult.okSafeZone(); else return ProtectionResult.okWarZone(); } else { if (chunkFaction.isWarZone() && user.hasPermission(PluginPermissions.WAR_ZONE_BUILD)) return ProtectionResult.okWarZone(); else return ProtectionResult.forbiddenWarZone(); } } //If player is in faction final Optional<Faction> optionalPlayerFaction = this.factionLogic.getFactionByPlayerUUID(user.getUniqueId()); if(optionalPlayerFaction.isPresent()) { final Faction playerFaction = optionalPlayerFaction.get(); if (chunkFaction.getName().equalsIgnoreCase(playerFaction.getName())) { if (this.permsManager.canPlaceBlock(user.getUniqueId(), playerFaction, chunkFaction, chunkFaction.getClaimAt(world.getUniqueId(), location.getChunkPosition()).get())) return ProtectionResult.okFactionPerm(); else return ProtectionResult.forbidden(); } } if (allowExplosionsByOtherPlayersInClaims) return ProtectionResult.ok(); else return ProtectionResult.forbidden(); }
Example 12
Source File: PlayerEventHandler.java From GriefPrevention with MIT License | 4 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onPlayerLogin(ClientConnectionEvent.Login event) { GPTimings.PLAYER_LOGIN_EVENT.startTimingIfSync(); User player = event.getTargetUser(); if (!GriefPreventionPlugin.instance.claimsEnabledForWorld(event.getToTransform().getExtent().getProperties())) { GPTimings.PLAYER_LOGIN_EVENT.stopTimingIfSync(); return; } final InetAddress ipAddress = event.getConnection().getAddress().getAddress(); // all this is anti-spam code if (GriefPreventionPlugin.getGlobalConfig().getConfig().spam.monitorEnabled) { // FEATURE: login cooldown to prevent login/logout spam with custom clients long now = Calendar.getInstance().getTimeInMillis(); // if allowed to join and login cooldown enabled if (GriefPreventionPlugin.getGlobalConfig().getConfig().spam.loginCooldown > 0 && !player.hasPermission(GPPermissions.OVERRIDE_SPAM)) { // determine how long since last login and cooldown remaining Date lastLoginThisSession = lastLoginThisServerSessionMap.get(player.getUniqueId()); if (lastLoginThisSession != null) { long millisecondsSinceLastLogin = now - lastLoginThisSession.getTime(); long secondsSinceLastLogin = millisecondsSinceLastLogin / 1000; long cooldownRemaining = GriefPreventionPlugin.getGlobalConfig().getConfig().spam.loginCooldown - secondsSinceLastLogin; // if cooldown remaining if (cooldownRemaining > 0) { // DAS BOOT!; event.setMessage(Text.of("You must wait " + cooldownRemaining + " seconds before logging-in again.")); event.setCancelled(true); GPTimings.PLAYER_LOGIN_EVENT.stopTimingIfSync(); return; } } } // if logging-in account is banned, remember IP address for later if (GriefPreventionPlugin.getGlobalConfig().getConfig().general.smartBan && (this.banService.isBanned(player.getProfile()) || this.banService.isBanned(ipAddress))) { this.tempBannedIps.add(new IpBanInfo(ipAddress, now + this.MILLISECONDS_IN_DAY, player.getName())); } } // remember the player's ip address final WorldProperties worldProperties = event.getToTransform().getExtent().getProperties(); final UUID playerUniqueId = player.getUniqueId(); final GPPlayerData playerData = this.dataStore.getOrCreatePlayerData(worldProperties, playerUniqueId); // Always reload playerdata storage on login in case a server is sharing data across servers playerData.getStorageData().load(); playerData.receivedDropUnlockAdvertisement = false; playerData.ipAddress = ipAddress; final GPClaimManager claimWorldManager = this.dataStore.getClaimWorldManager(worldProperties); final Instant dateNow = Instant.now(); for (Claim claim : claimWorldManager.getWorldClaims()) { if (claim.getType() != ClaimType.ADMIN && claim.getOwnerUniqueId().equals(playerUniqueId)) { // update lastActive timestamp for claim claim.getData().setDateLastActive(dateNow); // update timestamps for subdivisions for (Claim subdivision : ((GPClaim) claim).children) { subdivision.getData().setDateLastActive(dateNow); } ((GPClaim) claim).getInternalClaimData().setRequiresSave(true); } } GPTimings.PLAYER_LOGIN_EVENT.stopTimingIfSync(); }
Example 13
Source File: BlockEventHandler.java From GriefPrevention with MIT License | 4 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onSignChanged(ChangeSignEvent event) { final User user = CauseContextHelper.getEventUser(event); if (user == null) { return; } if (!GriefPreventionPlugin.instance.claimsEnabledForWorld(event.getTargetTile().getLocation().getExtent().getProperties())) { return; } GPTimings.SIGN_CHANGE_EVENT.startTimingIfSync(); Location<World> location = event.getTargetTile().getLocation(); // Prevent users exploiting signs GPClaim claim = GriefPreventionPlugin.instance.dataStore.getClaimAt(location); if (GPPermissionHandler.getClaimPermission(event, location, claim, GPPermissions.INTERACT_BLOCK_SECONDARY, user, location.getBlock(), user, TrustType.ACCESSOR, true) == Tristate.FALSE) { if (user instanceof Player) { event.setCancelled(true); final Text message = GriefPreventionPlugin.instance.messageData.permissionAccess .apply(ImmutableMap.of( "player", Text.of(claim.getOwnerName()))).build(); GriefPreventionPlugin.sendClaimDenyMessage(claim, (Player) user, message); return; } } // send sign content to online administrators if (!GriefPreventionPlugin.getActiveConfig(location.getExtent().getProperties()) .getConfig().general.generalAdminSignNotifications) { GPTimings.SIGN_CHANGE_EVENT.stopTimingIfSync(); return; } World world = location.getExtent(); StringBuilder lines = new StringBuilder(" placed a sign @ " + GriefPreventionPlugin.getfriendlyLocationString(event.getTargetTile().getLocation())); boolean notEmpty = false; for (int i = 0; i < event.getText().lines().size(); i++) { String withoutSpaces = Text.of(event.getText().lines().get(i)).toPlain().replace(" ", ""); if (!withoutSpaces.isEmpty()) { notEmpty = true; lines.append("\n " + event.getText().lines().get(i)); } } String signMessage = lines.toString(); // prevent signs with blocked IP addresses if (!user.hasPermission(GPPermissions.OVERRIDE_SPAM) && GriefPreventionPlugin.instance.containsBlockedIP(signMessage)) { event.setCancelled(true); GPTimings.SIGN_CHANGE_EVENT.stopTimingIfSync(); return; } // if not empty and wasn't the same as the last sign, log it and remember it for later GPPlayerData playerData = this.dataStore.getOrCreatePlayerData(world, user.getUniqueId()); if (notEmpty && playerData.lastMessage != null && !playerData.lastMessage.equals(signMessage)) { GriefPreventionPlugin.addLogEntry(user.getName() + lines.toString().replace("\n ", ";"), null); //PlayerEventHandler.makeSocialLogEntry(player.get().getName(), signMessage); playerData.lastMessage = signMessage; if (!user.hasPermission(GPPermissions.EAVES_DROP_SIGNS)) { Collection<Player> players = (Collection<Player>) Sponge.getGame().getServer().getOnlinePlayers(); for (Player otherPlayer : players) { if (otherPlayer.hasPermission(GPPermissions.EAVES_DROP_SIGNS)) { otherPlayer.sendMessage(Text.of(TextColors.GRAY, user.getName(), signMessage)); } } } } GPTimings.SIGN_CHANGE_EVENT.stopTimingIfSync(); }
Example 14
Source File: GPClaim.java From GriefPrevention with MIT License | 4 votes |
public boolean isUserTrusted(User user, TrustType type, Set<Context> contexts) { if (user == null) { return false; } final GPPlayerData playerData = GriefPreventionPlugin.instance.dataStore.getOrCreatePlayerData(world, user.getUniqueId()); if (!playerData.canIgnoreClaim(this) && this.getInternalClaimData() != null && this.getInternalClaimData().isExpired()) { return false; } if (!playerData.executingClaimDebug && !playerData.debugClaimPermissions) { if (user.getUniqueId().equals(this.getOwnerUniqueId())) { return true; } if (this.isAdminClaim() && playerData.canManageAdminClaims) { return true; } if (this.isWilderness() && playerData.canManageWilderness) { return true; } if (playerData.canIgnoreClaim(this)) { return true; } } if (type == null) { return true; } if (this.isPublicTrusted(type)) { return true; } if (type == TrustType.ACCESSOR) { if (this.claimData.getAccessors().contains(user.getUniqueId())) { return true; } if (this.claimData.getBuilders().contains(user.getUniqueId())) { return true; } if (this.claimData.getContainers().contains(user.getUniqueId())) { return true; } if (this.claimData.getManagers().contains(user.getUniqueId())) { return true; } } else if (type == TrustType.BUILDER) { if (this.claimData.getBuilders().contains(user.getUniqueId())) { return true; } if (this.claimData.getManagers().contains(user.getUniqueId())) { return true; } } else if (type == TrustType.CONTAINER) { if (this.claimData.getContainers().contains(user.getUniqueId())) { return true; } if (this.claimData.getBuilders().contains(user.getUniqueId())) { return true; } if (this.claimData.getManagers().contains(user.getUniqueId())) { return true; } } else if (type == TrustType.MANAGER) { if (this.claimData.getManagers().contains(user.getUniqueId())) { return true; } } if (contexts == null) { contexts = new HashSet<>(); contexts.add(this.getContext()); } if (user.hasPermission(contexts, GPPermissions.getTrustPermission(type))) { return true; } // Only check parent if this claim inherits if (this.parent != null && this.getData().doesInheritParent()) { return this.parent.isUserTrusted(user, type, contexts); } return false; }
Example 15
Source File: CommandClaimFlagPlayer.java From GriefPrevention with MIT License | 4 votes |
@Override public CommandResult execute(CommandSource src, CommandContext ctx) { Player player; try { player = GriefPreventionPlugin.checkPlayer(src); } catch (CommandException e) { src.sendMessage(e.getText()); return CommandResult.success(); } User user = ctx.<User>getOne("player").get(); String name = user.getName(); String flag = ctx.<String>getOne("flag").orElse(null); String source = ctx.<String>getOne("source").orElse(null); String target = null; // Workaround command API issue not handling onlyOne arguments with sequences properly List<String> targetValues = new ArrayList<>(ctx.<String>getAll("target")); if (targetValues.size() > 0) { if (targetValues.size() > 1) { target = targetValues.get(1); } else { target = targetValues.get(0); } } if (source != null && source.equalsIgnoreCase("any")) { source = null; } this.subject = user; this.friendlySubjectName = user.getName(); Tristate value = ctx.<Tristate>getOne("value").orElse(null); String context = ctx.<String>getOne("context").orElse(null); GPPlayerData playerData = GriefPreventionPlugin.instance.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId()); GPClaim claim = GriefPreventionPlugin.instance.dataStore.getClaimAtPlayer(playerData, player.getLocation()); String reason = ctx.<String>getOne("reason").orElse(null); Text reasonText = null; if (reason != null) { reasonText = TextSerializers.FORMATTING_CODE.deserialize(reason); } if (flag == null && value == null) { showFlagPermissions(src, claim, FlagType.ALL, source); return CommandResult.success(); } if (!ClaimFlag.contains(flag)) { src.sendMessage(Text.of(TextColors.RED, "Flag not found.")); return CommandResult.success(); } Context claimContext = claim.getContext(); if (context != null) { claimContext = CommandHelper.validateCustomContext(src, claim, context); if (claimContext == null) { final Text message = GriefPreventionPlugin.instance.messageData.flagInvalidContext .apply(ImmutableMap.of( "context", context, "flag", flag)).build(); GriefPreventionPlugin.sendMessage(src, message); return CommandResult.success(); } } if (user.hasPermission(GPPermissions.COMMAND_ADMIN_CLAIMS) && !src.hasPermission(GPPermissions.SET_ADMIN_FLAGS)) { GriefPreventionPlugin.sendMessage(src, GriefPreventionPlugin.instance.messageData.permissionSetAdminFlags.toText()); return CommandResult.success(); } try (final CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) { Sponge.getCauseStackManager().pushCause(src); claim.setPermission(user, name, ClaimFlag.getEnum(flag), source, target, value, claimContext, reasonText); } return CommandResult.success(); }
Example 16
Source File: PermissionHandler.java From RedProtect with GNU General Public License v3.0 | 4 votes |
public boolean hasPerm(User user, String perm) { return user != null && (user.hasPermission(perm) || user.hasPermission("redprotect.command.admin")); }