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);
}
}
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);
}
}
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));
}
Aggregations