Java Code Examples for org.spongepowered.api.util.Tristate#UNDEFINED
The following examples show how to use
org.spongepowered.api.util.Tristate#UNDEFINED .
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: CommandHelper.java From GriefPrevention with MIT License | 6 votes |
public static Consumer<CommandSource> createFlagConsumer(CommandSource src, Subject subject, String subjectName, Set<Context> contexts, GPClaim claim, String flagPermission, Tristate flagValue, String source) { return consumer -> { String target = flagPermission.replace(GPPermissions.FLAG_BASE + ".", ""); if (target.isEmpty()) { target = "any"; } Tristate newValue = Tristate.UNDEFINED; if (flagValue == Tristate.TRUE) { newValue = Tristate.FALSE; } else if (flagValue == Tristate.UNDEFINED) { newValue = Tristate.TRUE; } CommandHelper.applyFlagPermission(src, subject, subjectName, claim, flagPermission, source, target, newValue, null, FlagType.GROUP); }; }
Example 2
Source File: BlockPosCache.java From GriefPrevention with MIT License | 6 votes |
public Tristate getCacheResult(short pos) { int currentTick = SpongeImpl.getServer().getTickCounter(); if (this.lastBlockPos != pos) { this.lastBlockPos = pos; this.lastTickCounter = currentTick; return Tristate.UNDEFINED; } if ((currentTick - this.lastTickCounter) <= 2) { this.lastTickCounter = currentTick; return this.lastResult; } this.lastTickCounter = currentTick; return Tristate.UNDEFINED; }
Example 3
Source File: SpongeConnectionListener.java From LuckPerms with MIT License | 6 votes |
@Listener(order = Order.LAST) @IsCancelled(Tristate.UNDEFINED) public void onClientAuthMonitor(ClientConnectionEvent.Auth e) { /* Listen to see if the event was cancelled after we initially handled the connection If the connection was cancelled here, we need to do something to clean up the data that was loaded. */ // Check to see if this connection was denied at LOW. if (this.deniedAsyncLogin.remove(e.getProfile().getUniqueId())) { // This is a problem, as they were denied at low priority, but are now being allowed. if (e.isCancelled()) { this.plugin.getLogger().severe("Player connection was re-allowed for " + e.getProfile().getUniqueId()); e.setCancelled(true); } } }
Example 4
Source File: GPPermissionHandler.java From GriefPrevention with MIT License | 6 votes |
private static Tristate getClaimFlagPermission(GPClaim claim, String permission, String targetModPermission, String targetMetaPermission) { Set<Context> contexts = new HashSet<>(GriefPreventionPlugin.GLOBAL_SUBJECT.getActiveContexts()); contexts.add(claim.getContext()); Tristate value = GriefPreventionPlugin.GLOBAL_SUBJECT.getPermissionValue(contexts, permission); if (value != Tristate.UNDEFINED) { return processResult(claim, permission, value, GriefPreventionPlugin.GLOBAL_SUBJECT); } if (targetMetaPermission != null) { value = GriefPreventionPlugin.GLOBAL_SUBJECT.getPermissionValue(contexts, targetMetaPermission); if (value != Tristate.UNDEFINED) { return processResult(claim, targetMetaPermission, value, GriefPreventionPlugin.GLOBAL_SUBJECT); } } if (targetModPermission != null) { value = GriefPreventionPlugin.GLOBAL_SUBJECT.getPermissionValue(contexts, targetModPermission); if (value != Tristate.UNDEFINED) { return processResult(claim, targetModPermission, value, GriefPreventionPlugin.GLOBAL_SUBJECT); } } return getFlagDefaultPermission(claim, permission); }
Example 5
Source File: GPPermissionHandler.java From GriefPrevention with MIT License | 5 votes |
private static Tristate getFlagDefaultPermission(GPClaim claim, String permission) { // Fallback to defaults Set<Context> contexts = new HashSet<>(GriefPreventionPlugin.GLOBAL_SUBJECT.getActiveContexts()); if (claim.parent != null && claim.getData().doesInheritParent()) { if (claim.parent.parent != null && claim.parent.getData().doesInheritParent()) { claim = claim.parent.parent; } else { claim = claim.parent; } } if (claim.isAdminClaim()) { contexts.add(ClaimContexts.ADMIN_DEFAULT_CONTEXT); } else if (claim.isBasicClaim() || claim.isSubdivision()) { contexts.add(ClaimContexts.BASIC_DEFAULT_CONTEXT); } else if (claim.isTown()) { contexts.add(ClaimContexts.TOWN_DEFAULT_CONTEXT); } else { // wilderness contexts.add(ClaimContexts.WILDERNESS_DEFAULT_CONTEXT); } contexts.add(claim.world.getContext()); // check persisted/transient default data Tristate value = GriefPreventionPlugin.GLOBAL_SUBJECT.getPermissionValue(contexts, permission); if (value != Tristate.UNDEFINED) { return processResult(claim, permission, value, GriefPreventionPlugin.GLOBAL_SUBJECT); } return processResult(claim, permission, Tristate.UNDEFINED, GriefPreventionPlugin.GLOBAL_SUBJECT); }
Example 6
Source File: CommandHelper.java From GriefPrevention with MIT License | 5 votes |
public static Consumer<CommandSource> createFlagConsumer(CommandSource src, Subject subject, String subjectName, Set<Context> contexts, String flagPermission, Tristate flagValue, FlagType flagType) { return consumer -> { Tristate newValue = Tristate.UNDEFINED; if (flagValue == Tristate.TRUE) { newValue = Tristate.FALSE; } else if (flagValue == Tristate.UNDEFINED) { newValue = Tristate.TRUE; } Text flagTypeText = Text.of(); if (flagType == FlagType.OVERRIDE) { flagTypeText = Text.of(TextColors.RED, "OVERRIDE"); } else if (flagType == FlagType.DEFAULT) { flagTypeText = Text.of(TextColors.LIGHT_PURPLE, "DEFAULT"); } else if (flagType == FlagType.CLAIM) { flagTypeText = Text.of(TextColors.GOLD, "CLAIM"); } String target = flagPermission.replace(GPPermissions.FLAG_BASE + ".", ""); Set<Context> newContexts = new HashSet<>(contexts); subject.getSubjectData().setPermission(newContexts, flagPermission, newValue); src.sendMessage(Text.of( TextColors.GREEN, "Set ", flagTypeText, " permission ", TextColors.AQUA, target, TextColors.GREEN, "\n to ", TextColors.LIGHT_PURPLE, getClickableText(src, subject, subjectName, newContexts, flagPermission, newValue, flagType), TextColors.GREEN, " for ", TextColors.GOLD, subjectName)); }; }
Example 7
Source File: GPClaim.java From GriefPrevention with MIT License | 5 votes |
@Override public Tristate getPermissionValue(Subject subject, ClaimFlag flag, String target, Context context) { if (target.equalsIgnoreCase("any:any") || target.equalsIgnoreCase("any")) { target = null; } if (subject != GriefPreventionPlugin.GLOBAL_SUBJECT && (context == this.getDefaultContext() || context == this.getOverrideContext())) { return Tristate.UNDEFINED; } return GPPermissionHandler.getClaimPermission(this, flag, subject, null, target, context); }
Example 8
Source File: GPClaim.java From GriefPrevention with MIT License | 5 votes |
@Override public Tristate getPermissionValue(Subject subject, ClaimFlag flag, String source, String target, Context context) { if (source.equalsIgnoreCase("any:any") || source.equalsIgnoreCase("any")) { source = null; } if (target.equalsIgnoreCase("any:any") || target.equalsIgnoreCase("any")) { target = null; } if (subject != GriefPreventionPlugin.GLOBAL_SUBJECT && (context == this.getDefaultContext() || context == this.getOverrideContext())) { return Tristate.UNDEFINED; } return GPPermissionHandler.getClaimPermission(this, flag, subject, source, target, context); }
Example 9
Source File: GPClaim.java From GriefPrevention with MIT License | 5 votes |
public boolean isPvpEnabled() { Tristate value = this.claimData.getPvpOverride(); if (value != Tristate.UNDEFINED) { return value.asBoolean(); } return this.world.getProperties().isPVPEnabled(); }
Example 10
Source File: SpongeConnectionListener.java From LuckPerms with MIT License | 5 votes |
@Listener(order = Order.LAST) @IsCancelled(Tristate.UNDEFINED) public void onClientLoginMonitor(ClientConnectionEvent.Login e) { /* Listen to see if the event was cancelled after we initially handled the login If the connection was cancelled here, we need to do something to clean up the data that was loaded. */ // Check to see if this connection was denied at LOW. Even if it was denied at LOW, their data will still be present. if (this.deniedLogin.remove(e.getProfile().getUniqueId())) { // This is a problem, as they were denied at low priority, but are now being allowed. if (!e.isCancelled()) { this.plugin.getLogger().severe("Player connection was re-allowed for " + e.getProfile().getUniqueId()); e.setCancelled(true); } } }
Example 11
Source File: SpongeConnectionListener.java From LuckPerms with MIT License | 5 votes |
@Listener(order = Order.FIRST) @IsCancelled(Tristate.UNDEFINED) public void onClientLogin(ClientConnectionEvent.Login e) { /* Called when the player starts logging into the server. At this point, the users data should be present and loaded. Listening on LOW priority to allow plugins to further modify data here. (auth plugins, etc.) */ final GameProfile profile = e.getProfile(); if (this.plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) { this.plugin.getLogger().info("Processing login event for " + profile.getUniqueId() + " - " + profile.getName()); } final User user = this.plugin.getUserManager().getIfLoaded(profile.getUniqueId()); /* User instance is null for whatever reason. Could be that it was unloaded between asyncpre and now. */ if (user == null) { this.deniedLogin.add(profile.getUniqueId()); if (!getUniqueConnections().contains(profile.getUniqueId())) { this.plugin.getLogger().warn("User " + profile.getUniqueId() + " - " + profile.getName() + " doesn't have data pre-loaded, they have never been processed during pre-login in this session." + " - denying login."); } else { this.plugin.getLogger().warn("User " + profile.getUniqueId() + " - " + profile.getName() + " doesn't currently have data pre-loaded, but they have been processed before in this session." + " - denying login."); } e.setCancelled(true); e.setMessageCancelled(false); //noinspection deprecation e.setMessage(TextSerializers.LEGACY_FORMATTING_CODE.deserialize(Message.LOADING_STATE_ERROR.asString(this.plugin.getLocaleManager()))); } }
Example 12
Source File: FallbackPermActions.java From ChatUI with MIT License | 5 votes |
@Override public CompletableFuture<Boolean> setPermission(Player player, Subject subject, Set<Context> contexts, String permission, Tristate value) { Boolean perm = subject.getSubjectData().getPermissions(contexts).get(permission); if ((perm == null && value == Tristate.UNDEFINED) || (perm == Boolean.TRUE && value == Tristate.TRUE) || (perm == Boolean.FALSE && value == Tristate.FALSE)) { return CompletableFuture.completedFuture(true); } return subject.getSubjectData().setPermission(contexts, permission, value); }
Example 13
Source File: ChatUILib.java From ChatUI with MIT License | 5 votes |
@Listener(order = Order.PRE, beforeModifications = true) @IsCancelled(Tristate.UNDEFINED) public void onIncomingMessage(MessageChannelEvent.Chat event, @Root Player player) { if (getView(player).handleIncoming(event.getRawMessage())) { // No plugins should interpret this as chat event.setCancelled(true); event.setChannel(MessageChannel.TO_NONE); } }
Example 14
Source File: ClaimFlagBase.java From GriefPrevention with MIT License | 4 votes |
private Consumer<CommandSource> createFlagConsumer(CommandSource src, GPClaim claim, String flagPermission, Tristate flagValue, String source, FlagType displayType, FlagType flagType, boolean toggleType) { return consumer -> { // Toggle DEFAULT type final String sourceId = GPPermissionHandler.getSourcePermission(flagPermission); final String targetId = GPPermissionHandler.getTargetPermission(flagPermission); final ClaimFlag claimFlag = GPPermissionHandler.getFlagFromPermission(flagPermission); if (claimFlag == null) { return; } Context claimContext = claim.getContext(); Tristate newValue = Tristate.UNDEFINED; if (flagType == FlagType.DEFAULT) { if (toggleType) { if (flagValue == Tristate.TRUE) { newValue = Tristate.FALSE; } else { newValue = Tristate.TRUE; } ClaimType claimType = claim.getType(); if (claimType == ClaimType.SUBDIVISION) { claimType = ClaimType.BASIC; } final Boolean defaultValue = DataStore.CLAIM_FLAG_DEFAULTS.get(claimType).get(claimFlag.toString()); if (defaultValue != null && defaultValue == newValue.asBoolean()) { newValue = Tristate.UNDEFINED; } } claimContext = CommandHelper.validateCustomContext(src, claim, "default"); // Toggle CLAIM type } else if (flagType == FlagType.CLAIM) { if (flagValue == Tristate.TRUE) { newValue = Tristate.FALSE; } else if (flagValue == Tristate.UNDEFINED) { newValue = Tristate.TRUE; } // Toggle OVERRIDE type } else if (flagType == FlagType.OVERRIDE) { if (flagValue == Tristate.TRUE) { newValue = Tristate.FALSE; } else if (flagValue == Tristate.UNDEFINED) { newValue = Tristate.TRUE; } claimContext = CommandHelper.validateCustomContext(src, claim, "override"); } try (final CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) { Sponge.getCauseStackManager().pushCause(src); GPFlagClaimEvent.Set event = new GPFlagClaimEvent.Set(claim, this.subject, claimFlag, sourceId, targetId, toggleType ? newValue : flagValue, claimContext); Sponge.getEventManager().post(event); if (event.isCancelled()) { return; } FlagResult result = CommandHelper.applyFlagPermission(src, this.subject, "ALL", claim, flagPermission, source, "any", toggleType ? newValue : flagValue, claimContext, flagType, null, true); if (result.successful()) { showFlagPermissions(src, claim, displayType, source); } } }; }
Example 15
Source File: EntityEventHandler.java From GriefPrevention with MIT License | 4 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onEntityExplosionPre(ExplosionEvent.Pre event) { if (!GPFlags.EXPLOSION || !GriefPreventionPlugin.instance.claimsEnabledForWorld(event.getTargetWorld().getProperties())) { return; } if (GriefPreventionPlugin.isSourceIdBlacklisted(ClaimFlag.EXPLOSION.toString(), event.getSource(), event.getTargetWorld().getProperties())) { return; } GPTimings.ENTITY_EXPLOSION_PRE_EVENT.startTimingIfSync(); Location<World> location = event.getExplosion().getLocation(); GPClaim claim = GriefPreventionPlugin.instance.dataStore.getClaimAt(location); User user = CauseContextHelper.getEventUser(event); Object source = event.getSource(); if (source instanceof Explosion) { final Explosion explosion = (Explosion) source; if (explosion.getSourceExplosive().isPresent()) { source = explosion.getSourceExplosive().get(); } else { Entity exploder = event.getCause().first(Entity.class).orElse(null); if (exploder != null) { source = exploder; } } } Tristate result = Tristate.UNDEFINED; if (GPFlags.EXPLOSION_SURFACE && location.getPosition().getY() > ((net.minecraft.world.World) location.getExtent()).getSeaLevel()) { result = GPPermissionHandler.getClaimPermission(event, location, claim, GPPermissions.EXPLOSION_SURFACE, source, location.getBlock(), user, true); } else { result = GPPermissionHandler.getClaimPermission(event, location, claim, GPPermissions.EXPLOSION, source, location.getBlock(), user, true); } if(result == Tristate.FALSE) { event.setCancelled(true); GPTimings.ENTITY_EXPLOSION_PRE_EVENT.stopTimingIfSync(); return; } GPTimings.ENTITY_EXPLOSION_PRE_EVENT.stopTimingIfSync(); }
Example 16
Source File: PlayerEventHandler.java From GriefPrevention with MIT License | 4 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onPlayerDispenseItem(DropItemEvent.Dispense event, @Root Entity spawncause) { if (!GPFlags.ITEM_DROP || !(spawncause instanceof User)) { return; } final User user = (User) spawncause; final World world = spawncause.getWorld(); if (!GriefPreventionPlugin.instance.claimsEnabledForWorld(world.getProperties())) { return; } // in creative worlds, dropping items is blocked if (GriefPreventionPlugin.instance.claimModeIsActive(world.getProperties(), ClaimsMode.Creative)) { event.setCancelled(true); return; } GPTimings.PLAYER_DISPENSE_ITEM_EVENT.startTimingIfSync(); Player player = user instanceof Player ? (Player) user : null; GPPlayerData playerData = this.dataStore.getOrCreatePlayerData(world, user.getUniqueId()); // FEATURE: players in PvP combat, can't throw items on the ground to hide // them or give them away to other players before they are defeated // if in combat, don't let him drop it if (player != null && !GriefPreventionPlugin.getActiveConfig(world.getProperties()).getConfig().pvp.allowCombatItemDrops && playerData.inPvpCombat(player.getWorld())) { GriefPreventionPlugin.sendMessage(player, GriefPreventionPlugin.instance.messageData.pvpNoItemDrop.toText()); event.setCancelled(true); GPTimings.PLAYER_DISPENSE_ITEM_EVENT.stopTimingIfSync(); return; } for (Entity entityItem : event.getEntities()) { if (GriefPreventionPlugin.isTargetIdBlacklisted(ClaimFlag.ITEM_DROP.toString(), entityItem, world.getProperties())) { continue; } Location<World> location = entityItem.getLocation(); GPClaim claim = this.dataStore.getClaimAtPlayer(playerData, location); if (claim != null) { final Tristate override = GPPermissionHandler.getFlagOverride(event, location, claim, GPPermissions.ITEM_DROP, user, entityItem, user, playerData, true); if (override != Tristate.UNDEFINED) { if (override == Tristate.TRUE) { GPTimings.PLAYER_DISPENSE_ITEM_EVENT.stopTimingIfSync(); return; } event.setCancelled(true); GPTimings.PLAYER_DISPENSE_ITEM_EVENT.stopTimingIfSync(); return; } // allow trusted users if (claim.isUserTrusted(user, TrustType.ACCESSOR)) { GPTimings.PLAYER_DISPENSE_ITEM_EVENT.stopTimingIfSync(); return; } Tristate perm = GPPermissionHandler.getClaimPermission(event, location, claim, GPPermissions.ITEM_DROP, user, entityItem, user); if (perm == Tristate.TRUE) { GPTimings.PLAYER_DISPENSE_ITEM_EVENT.stopTimingIfSync(); return; } else if (perm == Tristate.FALSE) { event.setCancelled(true); if (spawncause instanceof Player) { final Text message = GriefPreventionPlugin.instance.messageData.permissionItemDrop .apply(ImmutableMap.of( "owner", claim.getOwnerName(), "item", entityItem.getType().getId())).build(); GriefPreventionPlugin.sendClaimDenyMessage(claim, player, message); } GPTimings.PLAYER_DISPENSE_ITEM_EVENT.stopTimingIfSync(); return; } } } GPTimings.PLAYER_DISPENSE_ITEM_EVENT.stopTimingIfSync(); }
Example 17
Source File: BlockEventHandler.java From GriefPrevention with MIT License | 4 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onExplosionDetonate(ExplosionEvent.Detonate event) { final World world = event.getExplosion().getWorld(); if (!GPFlags.EXPLOSION || !GriefPreventionPlugin.instance.claimsEnabledForWorld(world.getProperties())) { return; } Object source = event.getSource(); if (source instanceof Explosion) { final Explosion explosion = (Explosion) source; if (explosion.getSourceExplosive().isPresent()) { source = explosion.getSourceExplosive().get(); } else { Entity exploder = event.getCause().first(Entity.class).orElse(null); if (exploder != null) { source = exploder; } } } if (GriefPreventionPlugin.isSourceIdBlacklisted(ClaimFlag.EXPLOSION.toString(), source, event.getExplosion().getWorld().getProperties())) { return; } GPTimings.EXPLOSION_EVENT.startTimingIfSync(); final User user = CauseContextHelper.getEventUser(event); GPClaim targetClaim = null; final List<Location<World>> filteredLocations = new ArrayList<>(); for (Location<World> location : event.getAffectedLocations()) { targetClaim = GriefPreventionPlugin.instance.dataStore.getClaimAt(location, targetClaim); Tristate result = Tristate.UNDEFINED; if (GPFlags.EXPLOSION_SURFACE && location.getPosition().getY() > ((net.minecraft.world.World) world).getSeaLevel()) { result = GPPermissionHandler.getClaimPermission(event, location, targetClaim, GPPermissions.EXPLOSION_SURFACE, source, location.getBlock(), user, true); } else { result = GPPermissionHandler.getClaimPermission(event, location, targetClaim, GPPermissions.EXPLOSION, source, location.getBlock(), user, true); } if (result == Tristate.FALSE) { // Avoid lagging server from large explosions. if (event.getAffectedLocations().size() > 100) { event.setCancelled(true); break; } filteredLocations.add(location); } } // Workaround for SpongeForge bug if (event.isCancelled()) { event.getAffectedLocations().clear(); } else if (!filteredLocations.isEmpty()) { event.getAffectedLocations().removeAll(filteredLocations); } GPTimings.EXPLOSION_EVENT.stopTimingIfSync(); }
Example 18
Source File: SpongeConnectionListener.java From LuckPerms with MIT License | 4 votes |
@Listener(order = Order.EARLY) @IsCancelled(Tristate.UNDEFINED) public void onClientAuth(ClientConnectionEvent.Auth e) { /* Called when the player first attempts a connection with the server. Listening on AFTER_PRE priority to allow plugins to modify username / UUID data here. (auth plugins) Also, give other plugins a chance to cancel the event. */ final GameProfile profile = e.getProfile(); final String username = profile.getName().orElseThrow(() -> new RuntimeException("No username present for user " + profile.getUniqueId())); if (this.plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) { this.plugin.getLogger().info("Processing auth event for " + profile.getUniqueId() + " - " + profile.getName()); } if (e.isCancelled()) { // another plugin has disallowed the login. this.plugin.getLogger().info("Another plugin has cancelled the connection for " + profile.getUniqueId() + " - " + username + ". No permissions data will be loaded."); this.deniedAsyncLogin.add(profile.getUniqueId()); return; } /* Actually process the login for the connection. We do this here to delay the login until the data is ready. If the login gets cancelled later on, then this will be cleaned up. This includes: - loading uuid data - loading permissions - creating a user instance in the UserManager for this connection. - setting up cached data. */ try { User user = loadUser(profile.getUniqueId(), username); recordConnection(profile.getUniqueId()); this.plugin.getEventDispatcher().dispatchPlayerLoginProcess(profile.getUniqueId(), username, user); } catch (Exception ex) { this.plugin.getLogger().severe("Exception occurred whilst loading data for " + profile.getUniqueId() + " - " + profile.getName()); ex.printStackTrace(); this.deniedAsyncLogin.add(profile.getUniqueId()); e.setCancelled(true); e.setMessageCancelled(false); //noinspection deprecation e.setMessage(TextSerializers.LEGACY_FORMATTING_CODE.deserialize(Message.LOADING_DATABASE_ERROR.asString(this.plugin.getLocaleManager()))); this.plugin.getEventDispatcher().dispatchPlayerLoginProcess(profile.getUniqueId(), username, null); } }
Example 19
Source File: CommandClaimInfo.java From GriefPrevention with MIT License | 4 votes |
private static Consumer<CommandSource> createClaimInfoConsumer(CommandSource src, Claim claim, String title) { GPClaim gpClaim = (GPClaim) claim; return info -> { switch (title) { case INHERIT_PARENT : if (!claim.getParent().isPresent() || !src.hasPermission(GPPermissions.COMMAND_CLAIM_INHERIT)) { return; } gpClaim.getInternalClaimData().setInheritParent(!gpClaim.getInternalClaimData().doesInheritParent()); gpClaim.getInternalClaimData().setRequiresSave(true); claim.getData().save(); CommandHelper.executeCommand(src, "claiminfo", gpClaim.getUniqueId().toString()); return; case CLAIM_EXPIRATION : gpClaim.getInternalClaimData().setExpiration(!gpClaim.getInternalClaimData().allowExpiration()); gpClaim.getInternalClaimData().setRequiresSave(true); gpClaim.getClaimStorage().save(); break; case DENY_MESSAGES : gpClaim.getInternalClaimData().setDenyMessages(!gpClaim.getInternalClaimData().allowDenyMessages()); gpClaim.getInternalClaimData().setRequiresSave(true); gpClaim.getClaimStorage().save(); break; case FLAG_OVERRIDES : gpClaim.getInternalClaimData().setFlagOverrides(!gpClaim.getInternalClaimData().allowFlagOverrides()); gpClaim.getInternalClaimData().setRequiresSave(true); gpClaim.getClaimStorage().save(); break; case PVP_OVERRIDE : Tristate value = gpClaim.getInternalClaimData().getPvpOverride(); if (value == Tristate.UNDEFINED) { gpClaim.getInternalClaimData().setPvpOverride(Tristate.TRUE); } else if (value == Tristate.TRUE) { gpClaim.getInternalClaimData().setPvpOverride(Tristate.FALSE); } else { gpClaim.getInternalClaimData().setPvpOverride(Tristate.UNDEFINED); } gpClaim.getInternalClaimData().setRequiresSave(true); gpClaim.getClaimStorage().save(); break; case RESIZABLE : boolean resizable = gpClaim.getInternalClaimData().isResizable(); gpClaim.getInternalClaimData().setResizable(!resizable); gpClaim.getInternalClaimData().setRequiresSave(true); gpClaim.getClaimStorage().save(); break; case REQUIRES_CLAIM_BLOCKS : boolean requiresClaimBlocks = gpClaim.getInternalClaimData().requiresClaimBlocks(); gpClaim.getInternalClaimData().setRequiresClaimBlocks(!requiresClaimBlocks); gpClaim.getInternalClaimData().setRequiresSave(true); gpClaim.getClaimStorage().save(); break; case SIZE_RESTRICTIONS : boolean sizeRestrictions = gpClaim.getInternalClaimData().hasSizeRestrictions(); gpClaim.getInternalClaimData().setSizeRestrictions(!sizeRestrictions); gpClaim.getInternalClaimData().setRequiresSave(true); gpClaim.getClaimStorage().save(); break; case FOR_SALE : boolean forSale = gpClaim.getEconomyData().isForSale(); gpClaim.getEconomyData().setForSale(!forSale); gpClaim.getInternalClaimData().setRequiresSave(true); gpClaim.getClaimStorage().save(); CommandHelper.executeCommand(src, "claiminfo", gpClaim.getUniqueId().toString()); return; default: } executeAdminSettings(src, gpClaim); }; }
Example 20
Source File: PEXActions.java From ChatUI with MIT License | 4 votes |
@Override public Tristate getDefault(Subject subject, Set<Context> contexts) { Tristate[] val = new Tristate[] {Tristate.UNDEFINED}; command(new ForwardingSource(Sponge.getServer().getConsole()) { private final Pattern defRegex = Pattern.compile("\\s*Default permission:\\s*(\\-?\\d)"); private boolean capturePermissions; private Set<Map.Entry<String, String>> capturedContext; @Override public void sendMessage(Text message) { String text = message.toPlain(); if (!this.capturePermissions) { if (text.startsWith("Permissions:")) { this.capturePermissions = true; } return; } if (!text.startsWith(" ")) { this.capturePermissions = false; return; } if (text.equals(" Global:")) { this.capturedContext = Collections.emptySet(); return; } if (text.startsWith(" [") && text.endsWith("]:")) { this.capturedContext = Sets.newHashSet(); int start = text.indexOf('[') + 1; int end = text.indexOf(']'); String[] split = text.substring(start, end).split(",\\s*"); for (String pair : split) { String[] keyVal = pair.split("=", 2); this.capturedContext.add(Maps.immutableEntry(keyVal[0], keyVal[1])); } return; } if (!contexts.equals(this.capturedContext)) { return; } Matcher matcher = this.defRegex.matcher(text); if (matcher.matches()) { int v = Integer.parseInt(matcher.group(1)); val[0] = v == 0 ? Tristate.UNDEFINED : v > 0 ? Tristate.TRUE : Tristate.FALSE; this.capturePermissions = false; } } }, subjContext(subject, contexts).append("info").toString()); return val[0]; }