Search in sources :

Example 16 with Context

use of com.griefdefender.api.permission.Context in project GDHooks by bloodmc.

the class EliteMobsProvider method onEliteMobSpawn.

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onEliteMobSpawn(EliteMobSpawnEvent event) {
    final Entity entity = event.getEntity();
    final World world = entity.getWorld();
    if (!GriefDefender.getCore().isEnabled(world.getUID())) {
        return;
    }
    final EliteMobEntity eliteMobEntity = event.getEliteMobEntity();
    final Claim claim = GriefDefender.getCore().getClaimAt(entity.getLocation());
    final Set<Context> contexts = this.getEliteMobContexts(entity, eliteMobEntity);
    contexts.add(new Context("source", "spawnreason:" + event.getReason().name().toLowerCase()));
    contexts.add(new Context("source", "spawnreason:" + event.getReason().name().toLowerCase()));
    final EliteMobProperties eliteMobProperties = EliteMobProperties.getPluginData(entity.getType());
    final String name = "elitemobs:" + ChatColor.stripColor(eliteMobProperties.getName()).replace(" ", "_").replace(String.valueOf(eliteMobEntity.getLevel()), "").replace("Lvl_$level_", "").replaceAll("[^A-Za-z0-9_]", "").toLowerCase();
    contexts.add(new Context("target", name));
    final Tristate result = GriefDefender.getPermissionManager().getActiveFlagPermissionValue(event, entity.getLocation(), claim, null, Flags.ENTITY_SPAWN, event.getReason(), entity, contexts, null, true);
    if (result == Tristate.FALSE) {
        event.setCancelled(true);
    }
}
Also used : Context(com.griefdefender.api.permission.Context) Entity(org.bukkit.entity.Entity) EliteMobEntity(com.magmaguy.elitemobs.mobconstructor.EliteMobEntity) EliteMobEntity(com.magmaguy.elitemobs.mobconstructor.EliteMobEntity) Tristate(com.griefdefender.api.Tristate) EliteMobProperties(com.magmaguy.elitemobs.mobconstructor.mobdata.aggressivemobs.EliteMobProperties) World(org.bukkit.World) Claim(com.griefdefender.api.claim.Claim) EventHandler(org.bukkit.event.EventHandler)

Example 17 with Context

use of com.griefdefender.api.permission.Context in project GDHooks by bloodmc.

the class MMOItemsProvider method onAbilityUseEvent.

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onAbilityUseEvent(AbilityUseEvent event) {
    final Entity targetEntity = event.getTarget();
    if (targetEntity == null) {
        return;
    }
    final Player player = event.getPlayer();
    final World world = player.getWorld();
    if (!GriefDefender.getCore().isEnabled(world.getUID())) {
        return;
    }
    final Location location = targetEntity.getLocation();
    final PlayerData playerData = GriefDefender.getCore().getPlayerData(world.getUID(), player.getUniqueId());
    final ClaimManager claimManager = GriefDefender.getCore().getClaimManager(player.getWorld().getUID());
    final Claim claim = claimManager.getClaimAt(location.getBlockX(), location.getBlockY(), location.getBlockZ());
    final String ability = event.getAbility().getAbility().getLowerCaseID().replace(" ", "_");
    final Set<Context> contexts = new HashSet<>();
    final String targetEntityId = GriefDefender.getRegistry().lookupId(event.getTarget());
    contexts.add(new Context("mmoitems:target_entity", targetEntityId));
    final Tristate result = GriefDefender.getPermissionManager().getActiveFlagPermissionValue(event, location, claim, playerData.getUser(), ABILITY_USE, player, ability, contexts, null, true);
    if (result == Tristate.FALSE) {
        event.setCancelled(true);
    }
}
Also used : Context(com.griefdefender.api.permission.Context) Entity(org.bukkit.entity.Entity) ClaimManager(com.griefdefender.api.claim.ClaimManager) Player(org.bukkit.entity.Player) Tristate(com.griefdefender.api.Tristate) World(org.bukkit.World) PlayerData(com.griefdefender.api.data.PlayerData) Claim(com.griefdefender.api.claim.Claim) Location(org.bukkit.Location) HashSet(java.util.HashSet) EventHandler(org.bukkit.event.EventHandler)

Example 18 with Context

use of com.griefdefender.api.permission.Context in project GDHooks by bloodmc.

the class McMMOProvider method onPlayerAbilityActivate.

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerAbilityActivate(McMMOPlayerAbilityActivateEvent event) {
    final Player player = event.getPlayer();
    final World world = player.getWorld();
    if (!GriefDefender.getCore().isEnabled(world.getUID())) {
        return;
    }
    final Location location = player.getLocation();
    final PlayerData playerData = GriefDefender.getCore().getPlayerData(world.getUID(), player.getUniqueId());
    final Claim claim = GriefDefender.getCore().getClaimAt(location);
    final String ability = event.getAbility().name().toLowerCase().replace(" ", "_");
    final String skillType = event.getSkill().name().toLowerCase().replace(" ", "_");
    final Set<Context> contexts = new HashSet<>();
    contexts.add(new Context("mcmmo:skill_level", String.valueOf(event.getSkillLevel())));
    contexts.add(new Context("mcmmo:skill_type", skillType));
    final Tristate result = GriefDefender.getPermissionManager().getActiveFlagPermissionValue(event, location, claim, playerData.getUser(), ABILITY_ACTIVATE, player, ability, contexts, null, true);
    if (result == Tristate.FALSE) {
        event.setCancelled(true);
    }
    this.playerAbilityMap.put(player.getUniqueId(), new McMMOPlayerAbilityData(player.getUniqueId(), event.getAbility(), event.getSkill(), event.getSkillLevel(), contexts));
}
Also used : Context(com.griefdefender.api.permission.Context) Player(org.bukkit.entity.Player) McMMOPlayer(com.gmail.nossr50.datatypes.player.McMMOPlayer) McMMOPlayerAbilityData(com.griefdefender.hooks.provider.mcmmo.McMMOPlayerAbilityData) Tristate(com.griefdefender.api.Tristate) World(org.bukkit.World) PlayerData(com.griefdefender.api.data.PlayerData) Claim(com.griefdefender.api.claim.Claim) Location(org.bukkit.Location) HashSet(java.util.HashSet) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Context (com.griefdefender.api.permission.Context)18 HashSet (java.util.HashSet)16 World (org.bukkit.World)16 Player (org.bukkit.entity.Player)15 EventHandler (org.bukkit.event.EventHandler)15 Claim (com.griefdefender.api.claim.Claim)13 Tristate (com.griefdefender.api.Tristate)11 PlayerData (com.griefdefender.api.data.PlayerData)11 Location (org.bukkit.Location)11 McMMOPlayer (com.gmail.nossr50.datatypes.player.McMMOPlayer)9 Entity (org.bukkit.entity.Entity)3 Core (com.griefdefender.api.Core)1 User (com.griefdefender.api.User)1 ClaimManager (com.griefdefender.api.claim.ClaimManager)1 McMMOPlayerAbilityData (com.griefdefender.hooks.provider.mcmmo.McMMOPlayerAbilityData)1 EliteMobEntity (com.magmaguy.elitemobs.mobconstructor.EliteMobEntity)1 EliteMobProperties (com.magmaguy.elitemobs.mobconstructor.mobdata.aggressivemobs.EliteMobProperties)1 ElitePower (com.magmaguy.elitemobs.powers.ElitePower)1 UUID (java.util.UUID)1