org.spongepowered.api.util.Tristate Java Examples

The following examples show how to use org.spongepowered.api.util.Tristate. 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 vote down vote up
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: FactionKickListener.java    From EagleFactions with MIT License 6 votes vote down vote up
@Listener(order = Order.POST)
@IsCancelled(value = Tristate.FALSE)
public void onPlayerFactionKick(final FactionKickEvent event)
{
    final Faction faction = event.getFaction();
    final FactionPlayer kickedPlayer = event.getKickedPlayer();

    final List<Player> onlineFactionPlayers = super.getPlugin().getFactionLogic().getOnlinePlayers(faction);
    for(final Player player : onlineFactionPlayers)
    {
        if (player.equals(event.getCreator()))
            continue;

        if(player.getName().equals(kickedPlayer.getName()))
            continue;

        player.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, "Player " + kickedPlayer.getName() + " has been kicked from the faction."));
    }
}
 
Example #3
Source File: GPPermissionHandler.java    From GriefPrevention with MIT License 6 votes vote down vote up
public static void addEventLogEntry(Event event, Location<World> location, Object source, Object target, Subject permissionSubject, String permission, String trust, Tristate result) {
    if (GriefPreventionPlugin.debugActive) {
        String sourceId = getPermissionIdentifier(source, true);
        String targetPermission = permission;
        String targetId = getPermissionIdentifier(target);
        if (!targetId.isEmpty()) {
            // move target meta to end of permission
            Matcher m = PATTERN_META.matcher(targetId);
            String targetMeta = "";
            if (!permission.contains("command-execute")) {
                if (m.find()) {
                    targetMeta = m.group(0);
                    targetId = StringUtils.replace(targetId, targetMeta, "");
                }
            }
            targetPermission += "." + targetId + targetMeta;
        }
        if (permissionSubject == null) {
            permissionSubject = GriefPreventionPlugin.GLOBAL_SUBJECT;
        }
        GriefPreventionPlugin.addEventLogEntry(event, location, sourceId, targetId, permissionSubject, targetPermission, trust, result);
    }
}
 
Example #4
Source File: UCPerms8.java    From UltimateChat with GNU General Public License v3.0 6 votes vote down vote up
public UCPerms8() {
    this.permissionService = UChat.get().getGame().getServiceManager().getRegistration(PermissionService.class).get().getProvider();
    this.permissionService.getDefaults().getTransientSubjectData().setPermission(new HashSet<>(), "uchat.channel.local.read", Tristate.TRUE);
    this.permissionService.getDefaults().getTransientSubjectData().setPermission(new HashSet<>(), "uchat.channel.local.write", Tristate.TRUE);
    this.permissionService.getDefaults().getTransientSubjectData().setPermission(new HashSet<>(), "uchat.channel.global.read", Tristate.TRUE);
    this.permissionService.getDefaults().getTransientSubjectData().setPermission(new HashSet<>(), "uchat.channel.global.write", Tristate.TRUE);
    this.permissionService.getDefaults().getTransientSubjectData().setPermission(new HashSet<>(), "uchat.cmd.tell", Tristate.TRUE);
    this.permissionService.getDefaults().getTransientSubjectData().setPermission(new HashSet<>(), "uchat.chat.click-urls", Tristate.TRUE);
    this.permissionService.getDefaults().getTransientSubjectData().setPermission(new HashSet<>(), "uchat.cant-ignore.local", Tristate.TRUE);
    this.permissionService.getDefaults().getTransientSubjectData().setPermission(new HashSet<>(), "uchat.chat.hand", Tristate.TRUE);
    this.permissionService.getDefaults().getTransientSubjectData().setPermission(new HashSet<>(), "uchat.cmd.ignore.channel", Tristate.TRUE);
    this.permissionService.getDefaults().getTransientSubjectData().setPermission(new HashSet<>(), "uchat.cmd.ignore.player", Tristate.TRUE);
    this.permissionService.getDefaults().getTransientSubjectData().setPermission(new HashSet<>(), "uchat.cmd.clear", Tristate.TRUE);
    this.permissionService.getDefaults().getTransientSubjectData().setPermission(new HashSet<>(), "uchat.cmd.msgtoggle", Tristate.TRUE);
    this.permissionService.getDefaults().getTransientSubjectData().setPermission(new HashSet<>(), "uchat.password", Tristate.TRUE);
    this.permissionService.getDefaults().getTransientSubjectData().setPermission(new HashSet<>(), "uchat.discord-sync.cmd.base", Tristate.TRUE);
    this.permissionService.getDefaults().getTransientSubjectData().setPermission(new HashSet<>(), "uchat.discord-sync.cmd.generate", Tristate.TRUE);
}
 
Example #5
Source File: SpongeConnectionListener.java    From LuckPerms with MIT License 6 votes vote down vote up
@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 #6
Source File: GPPermissionHandler.java    From GriefPrevention with MIT License 6 votes vote down vote up
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 #7
Source File: CommandHelper.java    From GriefPrevention with MIT License 6 votes vote down vote up
public static Text getClickableText(CommandSource src, Subject subject, String subjectName, Set<Context> contexts, GPClaim claim, String flagPermission, Tristate flagValue, String source, FlagType type) {
    Text onClickText = Text.of("Click here to toggle flag value.");
    boolean hasPermission = true;
    if (type == FlagType.INHERIT) {
        onClickText = Text.of("This flag is inherited from parent claim ", claim.getName().orElse(claim.getFriendlyNameType()), " and ", TextStyles.UNDERLINE, "cannot", TextStyles.RESET, " be changed.");
        hasPermission = false;
    } else if (src instanceof Player) {
        Text denyReason = claim.allowEdit((Player) src);
        if (denyReason != null) {
            onClickText = denyReason;
            hasPermission = false;
        }
    }

    Text.Builder textBuilder = Text.builder()
    .append(Text.of(flagValue.toString().toLowerCase()))
    .onHover(TextActions.showText(Text.of(onClickText, "\n", getFlagTypeHoverText(type))));
    if (hasPermission) {
        textBuilder.onClick(TextActions.executeCallback(createFlagConsumer(src, subject, subjectName, contexts, claim, flagPermission, flagValue, source)));
    }
    return textBuilder.build();
}
 
Example #8
Source File: PlayerEventHandler.java    From GriefPrevention with MIT License 6 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerInteractInventoryClose(InteractInventoryEvent.Close event, @Root Player player) {
    final ItemStackSnapshot cursor = event.getCursorTransaction().getOriginal();
    if (cursor == ItemStackSnapshot.NONE || !GPFlags.ITEM_DROP || !GriefPreventionPlugin.instance.claimsEnabledForWorld(player.getWorld().getProperties())) {
        return;
    }
    if (GriefPreventionPlugin.isTargetIdBlacklisted(ClaimFlag.ITEM_DROP.toString(), cursor, player.getWorld().getProperties())) {
        return;
    }

    GPTimings.PLAYER_INTERACT_INVENTORY_CLOSE_EVENT.startTimingIfSync();
    final Location<World> location = player.getLocation();
    final GPClaim claim = this.dataStore.getClaimAt(location);
    if (GPPermissionHandler.getClaimPermission(event, location, claim, GPPermissions.ITEM_DROP, player, cursor, player, TrustType.ACCESSOR, true) == Tristate.FALSE) {
        Text message = GriefPreventionPlugin.instance.messageData.permissionItemDrop
                .apply(ImmutableMap.of(
                "owner", claim.getOwnerName(),
                "item", cursor.getType().getId())).build();
        GriefPreventionPlugin.sendClaimDenyMessage(claim, player, message);
        event.setCancelled(true);
    }

    GPTimings.PLAYER_INTERACT_INVENTORY_CLOSE_EVENT.stopTimingIfSync();
}
 
Example #9
Source File: PlayerEventHandler.java    From GriefPrevention with MIT License 6 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerUseItem(UseItemStackEvent.Start event, @First Player player) {
    if (!GPFlags.ITEM_USE || !GriefPreventionPlugin.instance.claimsEnabledForWorld(player.getWorld().getProperties())) {
        return;
    }
    if (GriefPreventionPlugin.isTargetIdBlacklisted(ClaimFlag.ITEM_USE.toString(), event.getItemStackInUse().getType(), player.getWorld().getProperties())) {
        return;
    }

    GPTimings.PLAYER_USE_ITEM_EVENT.startTimingIfSync();
    Location<World> location = player.getLocation();
    GPPlayerData playerData = this.dataStore.getOrCreatePlayerData(location.getExtent(), player.getUniqueId());
    GPClaim claim = this.dataStore.getClaimAtPlayer(playerData, location);

    final Tristate result = GPPermissionHandler.getClaimPermission(event, location, claim, GPPermissions.ITEM_USE, player, event.getItemStackInUse().getType(), player, TrustType.ACCESSOR, true);
    if (result == Tristate.FALSE) {
        final Text message = GriefPreventionPlugin.instance.messageData.permissionItemUse
                .apply(ImmutableMap.of(
                "item", event.getItemStackInUse().getType().getId())).build();
        GriefPreventionPlugin.sendClaimDenyMessage(claim, player,  message);
        event.setCancelled(true);
    }
    GPTimings.PLAYER_USE_ITEM_EVENT.stopTimingIfSync();
}
 
Example #10
Source File: GPPermissionMigrator.java    From GriefPrevention with MIT License 6 votes vote down vote up
public void migrateSubject(Subject subject) {
    GriefPreventionPlugin.instance.executor.execute(() -> {
        boolean migrated = false;
        for (Map.Entry<Set<Context>, Map<String, Boolean>> mapEntry : subject.getSubjectData().getAllPermissions().entrySet()) {
            final Set<Context> contextSet = mapEntry.getKey();
            Iterator<Map.Entry<String, Boolean>> iterator = mapEntry.getValue().entrySet().iterator();
            while (iterator.hasNext()) {
                final Map.Entry<String, Boolean> entry = iterator.next();
                final String currentPermission = entry.getKey();
                if (currentPermission.contains(".pixelmon.animal.pixelmon")) {
                    GriefPreventionPlugin.instance.getLogger().info("Detected legacy pixelmon permission '" + currentPermission + "'. Migrating...");
                    final String newPermission = currentPermission.replaceAll("\\.pixelmon\\.animal\\.pixelmon", "\\.pixelmon\\.animal");
                    subject.getSubjectData().setPermission(contextSet, currentPermission, Tristate.UNDEFINED);
                    GriefPreventionPlugin.instance.getLogger().info("Removed legacy pixelmon permission '" + currentPermission + "'.");
                    subject.getSubjectData().setPermission(contextSet, newPermission, Tristate.fromBoolean(entry.getValue()));
                    GriefPreventionPlugin.instance.getLogger().info("Set new permission '" + newPermission);
                    migrated = true;
                }
            }
        }
        if (migrated) {
            GriefPreventionPlugin.instance.getLogger().info("Finished migration of subject '" + subject.getIdentifier() + "'\n");
        }
    });
}
 
Example #11
Source File: BlockPosCache.java    From GriefPrevention with MIT License 6 votes vote down vote up
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 #12
Source File: LoanListener.java    From EconomyLite with MIT License 6 votes vote down vote up
@Listener
public void onLoanChange(LoanBalanceChangeEvent event) {
    UUID uuid = event.getUser();
    for (Player player : Sponge.getServer().getOnlinePlayers()) {
        if (player.getUniqueId().equals(uuid)) {
            if (event.getNewBalance() == 0) {
                // Remove the debtor permissions
                module.getPermissions().forEach((perm, val) -> {
                    player.getSubjectData().setPermission(SubjectData.GLOBAL_CONTEXT, perm, Tristate.fromBoolean(!val));
                });
            } else {
                // Add the debtor permissions
                module.getPermissions().forEach((perm, val) -> {
                    player.getSubjectData().setPermission(SubjectData.GLOBAL_CONTEXT, perm, Tristate.fromBoolean(val));
                });
            }
        }
    }
}
 
Example #13
Source File: FallbackPermActions.java    From ChatUI with MIT License 5 votes vote down vote up
@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 #14
Source File: SubjectViewer.java    From ChatUI with MIT License 5 votes vote down vote up
private boolean add(Player player, String permission) {
    if (this.tab.actions().setPermission(player, this.activeSubj, this.activeContext, permission, Tristate.TRUE).join()) {
        this.permList = null;
        return true;
    }
    return false;
}
 
Example #15
Source File: VirtualChestActionDispatcher.java    From VirtualChest with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static List<String> parseCommand(String commandSequence)
{
    StringBuilder stringBuilder = new StringBuilder();
    List<String> commands = new LinkedList<>();
    Tristate isCommandFinished = Tristate.TRUE;
    for (char c : commandSequence.toCharArray())
    {
        if (c != SEQUENCE_SPLITTER)
        {
            if (isCommandFinished == Tristate.UNDEFINED)
            {
                commands.add(stringBuilder.toString());
                stringBuilder.setLength(0);
            }
            if (isCommandFinished != Tristate.FALSE && Character.isWhitespace(c))
            {
                isCommandFinished = Tristate.TRUE;
                continue;
            }
        }
        else if (isCommandFinished != Tristate.UNDEFINED)
        {
            isCommandFinished = Tristate.UNDEFINED;
            continue;
        }
        isCommandFinished = Tristate.FALSE;
        stringBuilder.append(c);
    }
    commands.add(stringBuilder.toString());
    return commands;
}
 
Example #16
Source File: GPFlagClaimEvent.java    From GriefPrevention with MIT License 5 votes vote down vote up
public Set(Claim claim, Subject subject, ClaimFlag flag, String source, String target, Tristate value, Context context) {
    super(claim, subject);
    this.flag = flag;
    this.source = source;
    this.target = target;
    this.value = value;
    this.context = context;
}
 
Example #17
Source File: ChatLoggerListener.java    From FlexibleLogin with MIT License 5 votes vote down vote up
@Listener(order = Order.POST)
@IsCancelled(Tristate.TRUE)
public void onPostCommand(SendCommandEvent commandEvent) {
    String command = commandEvent.getCommand();
    if (isOurCommand(command)) {
        //re-enable it
        commandEvent.getContext();
        commandEvent.setCancelled(false);
    }
}
 
Example #18
Source File: SubjectDataProxy.java    From LuckPerms with MIT License 5 votes vote down vote up
@Override
public @NonNull CompletableFuture<Boolean> setPermission(@NonNull Set<Context> contexts, @NonNull String permission, @NonNull Tristate value) {
    return handle().thenCompose(handle -> handle.setPermission(
            CompatibilityUtil.convertContexts(contexts),
            permission,
            CompatibilityUtil.convertTristate(value)
    ));
}
 
Example #19
Source File: GPClaim.java    From GriefPrevention with MIT License 5 votes vote down vote up
@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 #20
Source File: GPClaim.java    From GriefPrevention with MIT License 5 votes vote down vote up
@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 #21
Source File: CommandUntrustAll.java    From GriefPrevention with MIT License 5 votes vote down vote up
private void removeAllGroupTrust(Claim claim, Subject group) {
    GPClaim gpClaim = (GPClaim) claim;
    Set<Context> contexts = new HashSet<>(); 
    contexts.add(gpClaim.getContext());
    for (TrustType type : TrustType.values()) {
        group.getSubjectData().setPermission(contexts, GPPermissions.getTrustPermission(type), Tristate.UNDEFINED);
        gpClaim.getGroupTrustList(type).remove(group);
        gpClaim.getInternalClaimData().setRequiresSave(true);
        for (Claim child : gpClaim.children) {
            this.removeAllGroupTrust(child, group);
        }
    }
}
 
Example #22
Source File: GPPermissionHandler.java    From GriefPrevention with MIT License 5 votes vote down vote up
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 #23
Source File: GPPermissionHandler.java    From GriefPrevention with MIT License 5 votes vote down vote up
public static Tristate getClaimPermission(GPClaim claim, ClaimFlag flag, Subject subject, String source, String target, Context context) {
    final String flagBasePermission = GPPermissions.FLAG_BASE + "." + flag.toString();
    String sourceId = getPermissionIdentifier(source, true);
    String targetPermission = flagBasePermission;
    String targetId = getPermissionIdentifier(target);
    String targetModPermission = null;
    if (!targetId.isEmpty()) {
        if (!sourceId.isEmpty()) {
            String[] parts = targetId.split(":");
            String targetMod = parts[0];
            // move target meta to end of permission
            Pattern p = Pattern.compile("\\.[\\d+]*$");
            Matcher m = p.matcher(targetId);
            String targetMeta = "";
            if (m.find()) {
                targetMeta = m.group(0);
                targetId = StringUtils.replace(targetId, targetMeta, "");
            }
            targetModPermission = flagBasePermission + "." + targetMod + ".source." + sourceId + targetMeta;
            targetModPermission = StringUtils.replace(targetModPermission, ":", ".");
            targetPermission += "." + targetId + ".source." + sourceId + targetMeta;
        } else {
            targetPermission += "." + targetId;
        }
    }
    targetPermission = StringUtils.replace(targetPermission, ":", ".");
    Set<Context> contexts = new HashSet<>();
    contexts.add(context);
    return subject.getPermissionValue(contexts, targetPermission);
}
 
Example #24
Source File: SetuppermissionsUltimatecoreCommand.java    From UltimateCore with MIT License 5 votes vote down vote up
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    PermissionLevel level = args.<PermissionLevel>getOne("level").get();
    Subject group = args.<Subject>getOne("group").get();

    //For each permission, grant if level is equal
    for (Permission perm : UltimateCore.get().getPermissionService().getPermissions()) {
        if (perm.getLevel() == level) {
            group.getSubjectData().setPermission(new HashSet<>(), perm.get(), Tristate.TRUE);
        }
    }

    Messages.send(src, "core.command.ultimatecore.setuppermissions.success", "%group%", group.getIdentifier(), "%level%", level.name().toLowerCase());
    return CommandResult.success();
}
 
Example #25
Source File: EntityEventHandler.java    From GriefPrevention with MIT License 5 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onEntityExplosionDetonate(ExplosionEvent.Detonate 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_DETONATE_EVENT.startTimingIfSync();
    final User user = CauseContextHelper.getEventUser(event);
    Iterator<Entity> iterator = event.getEntities().iterator();
    GPClaim targetClaim = null;
    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;
            }
        }
    }

    while (iterator.hasNext()) {
        Entity entity = iterator.next();
        targetClaim =  GriefPreventionPlugin.instance.dataStore.getClaimAt(entity.getLocation(), targetClaim);
        if (GPPermissionHandler.getClaimPermission(event, entity.getLocation(), targetClaim, GPPermissions.ENTITY_DAMAGE, source, entity, user) == Tristate.FALSE) {
            iterator.remove();
        }
    }
    GPTimings.ENTITY_EXPLOSION_DETONATE_EVENT.stopTimingIfSync();
}
 
Example #26
Source File: BlockEventHandler.java    From GriefPrevention with MIT License 5 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onProjectileImpactBlock(CollideBlockEvent.Impact event) {
    if (!GPFlags.PROJECTILE_IMPACT_BLOCK || !(event.getSource() instanceof Entity)) {
        return;
    }

    final Entity source = (Entity) event.getSource();
    if (GriefPreventionPlugin.isSourceIdBlacklisted(ClaimFlag.PROJECTILE_IMPACT_BLOCK.toString(), source.getType().getId(), source.getWorld().getProperties())) {
        return;
    }

    final User user = CauseContextHelper.getEventUser(event);
    if (user == null) {
        return;
    }

    if (!GriefPreventionPlugin.instance.claimsEnabledForWorld(event.getImpactPoint().getExtent().getProperties())) {
        return;
    }

    GPTimings.PROJECTILE_IMPACT_BLOCK_EVENT.startTimingIfSync();
    Location<World> impactPoint = event.getImpactPoint();
    GPClaim targetClaim = null;
    GPPlayerData playerData = null;
    if (user instanceof Player) {
        playerData = GriefPreventionPlugin.instance.dataStore.getOrCreatePlayerData(event.getTargetLocation().getExtent(), user.getUniqueId());
        targetClaim = this.dataStore.getClaimAtPlayer(playerData, impactPoint);
    } else {
        targetClaim = this.dataStore.getClaimAt(impactPoint);
    }

    Tristate result = GPPermissionHandler.getClaimPermission(event, impactPoint, targetClaim, GPPermissions.PROJECTILE_IMPACT_BLOCK, source, event.getTargetBlock(), user, TrustType.ACCESSOR, true);
    if (result == Tristate.FALSE) {
        event.setCancelled(true);
        GPTimings.PROJECTILE_IMPACT_BLOCK_EVENT.stopTimingIfSync();
        return;
    }

    GPTimings.PROJECTILE_IMPACT_BLOCK_EVENT.stopTimingIfSync();
}
 
Example #27
Source File: EntityEventHandler.java    From GriefPrevention with MIT License 5 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onProjectileImpactEntity(CollideEntityEvent.Impact event) {
    if (!GPFlags.PROJECTILE_IMPACT_ENTITY) {
        return;
    }
    if (GriefPreventionPlugin.isSourceIdBlacklisted(ClaimFlag.PROJECTILE_IMPACT_ENTITY.toString(), event.getSource(), event.getImpactPoint().getExtent().getProperties())) {
        return;
    }

    final User user = CauseContextHelper.getEventUser(event);
    if (user == null || !GriefPreventionPlugin.instance.claimsEnabledForWorld(event.getImpactPoint().getExtent().getProperties())) {
        return;
    }

    GPTimings.PROJECTILE_IMPACT_ENTITY_EVENT.startTimingIfSync();
    Object source = event.getCause().root();
    Location<World> impactPoint = event.getImpactPoint();
    GPClaim targetClaim = null;
    for (Entity entity : event.getEntities()) {
        if (GriefPreventionPlugin.isTargetIdBlacklisted(ClaimFlag.PROJECTILE_IMPACT_ENTITY.toString(), entity, event.getImpactPoint().getExtent().getProperties())) {
            return;
        }
        targetClaim = this.dataStore.getClaimAt(impactPoint, targetClaim);
        final Tristate result = GPPermissionHandler.getClaimPermission(event, impactPoint, targetClaim, GPPermissions.PROJECTILE_IMPACT_ENTITY, source, entity, user, TrustType.ACCESSOR, true);
        if (result == Tristate.FALSE) {
            if (GPPermissionHandler.getClaimPermission(event, impactPoint, targetClaim, GPPermissions.PROJECTILE_IMPACT_ENTITY, source, entity, user) == Tristate.TRUE) {
                GPTimings.PROJECTILE_IMPACT_ENTITY_EVENT.stopTimingIfSync();
                return;
            }

            event.setCancelled(true);
        }
    }
    GPTimings.PROJECTILE_IMPACT_ENTITY_EVENT.stopTimingIfSync();
}
 
Example #28
Source File: PlayerEventHandler.java    From GriefPrevention with MIT License 5 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerInteractInventoryOpen(InteractInventoryEvent.Open event, @First Player player) {
    if (!GPFlags.INTERACT_INVENTORY || !GriefPreventionPlugin.instance.claimsEnabledForWorld(player.getWorld().getProperties())) {
        return;
    }

    final Cause cause = event.getCause();
    final EventContext context = cause.getContext();
    final BlockSnapshot blockSnapshot = context.get(EventContextKeys.BLOCK_HIT).orElse(BlockSnapshot.NONE);
    if (blockSnapshot == BlockSnapshot.NONE) {
        return;
    }
    if (GriefPreventionPlugin.isTargetIdBlacklisted(ClaimFlag.INTERACT_INVENTORY.toString(), blockSnapshot, player.getWorld().getProperties())) {
        return;
    }

    GPTimings.PLAYER_INTERACT_INVENTORY_OPEN_EVENT.startTimingIfSync();
    final Location<World> location = blockSnapshot.getLocation().get();
    final GPClaim claim = this.dataStore.getClaimAt(location);
    final Tristate result = GPPermissionHandler.getClaimPermission(event, location, claim, GPPermissions.INVENTORY_OPEN, player, blockSnapshot, player, TrustType.CONTAINER, true);
    if (result == Tristate.FALSE) {
        Text message = GriefPreventionPlugin.instance.messageData.permissionInventoryOpen
                .apply(ImmutableMap.of(
                "owner", claim.getOwnerName(),
                "block", blockSnapshot.getState().getType().getId())).build();
        GriefPreventionPlugin.sendClaimDenyMessage(claim, player, message);
        ((EntityPlayerMP) player).closeScreen();
        event.setCancelled(true);
    }

    GPTimings.PLAYER_INTERACT_INVENTORY_OPEN_EVENT.stopTimingIfSync();
}
 
Example #29
Source File: PlayerEventHandler.java    From GriefPrevention with MIT License 5 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerInteractEntity(InteractEntityEvent.Primary event, @First Player player) {
    if (!GPFlags.INTERACT_ENTITY_PRIMARY || !GriefPreventionPlugin.instance.claimsEnabledForWorld(player.getWorld().getProperties())) {
        return;
    }

    final Entity targetEntity = event.getTargetEntity();
    final HandType handType = event.getHandType();
    final ItemStack itemInHand = player.getItemInHand(handType).orElse(ItemStack.empty());
    final Object source = !itemInHand.isEmpty() ? itemInHand : player;
    if (GriefPreventionPlugin.isTargetIdBlacklisted(ClaimFlag.INTERACT_ENTITY_PRIMARY.toString(), targetEntity, player.getWorld().getProperties())) {
        return;
    }

    GPTimings.PLAYER_INTERACT_ENTITY_PRIMARY_EVENT.startTimingIfSync();
    Location<World> location = targetEntity.getLocation();
    GPClaim claim = this.dataStore.getClaimAt(location);
    if (event.isCancelled() && claim.getData().getPvpOverride() == Tristate.TRUE && targetEntity instanceof Player) {
        event.setCancelled(false);
    }

    Tristate result = GPPermissionHandler.getClaimPermission(event, location, claim, GPPermissions.INTERACT_ENTITY_PRIMARY, source, targetEntity, player, TrustType.ACCESSOR, true);
    if (result == Tristate.FALSE) {
        final Text message = GriefPreventionPlugin.instance.messageData.claimProtectedEntity
                .apply(ImmutableMap.of(
                "owner", claim.getOwnerName())).build();
        GriefPreventionPlugin.sendMessage(player, message);
        event.setCancelled(true);
        this.sendInteractEntityDenyMessage(itemInHand, targetEntity, claim, player, handType);
        GPTimings.PLAYER_INTERACT_ENTITY_PRIMARY_EVENT.stopTimingIfSync();
        return;
    }
}
 
Example #30
Source File: FactionLeaveListener.java    From EagleFactions with MIT License 5 votes vote down vote up
@Listener(order = Order.POST)
@IsCancelled(value = Tristate.FALSE)
public void onFactionLeave(final FactionLeaveEvent event, @Root final Player player)
{
    //Notify other faction members about someone leaving the faction
    final Faction faction = event.getFaction();
    final List<Player> factionPlayers = super.getPlugin().getFactionLogic().getOnlinePlayers(faction);
    for (final Player factionPlayer : factionPlayers)
    {
        if (factionPlayer.getName().equals(player.getName()))
            continue;
        factionPlayer.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, TextColors.GOLD, player.getName(), TextColors.AQUA, " left your faction."));
    }
}