Search in sources :

Example 1 with EliteMobEntity

use of com.magmaguy.elitemobs.mobconstructor.EliteMobEntity in project GDHooks by bloodmc.

the class EliteMobsProvider method getEliteMobId.

public String getEliteMobId(Entity entity) {
    final EliteMobEntity eliteMobEntity = EntityTracker.getEliteMobEntity(entity);
    if (eliteMobEntity == null) {
        return null;
    }
    String eliteMobName = eliteMobEntity.getName();
    if (eliteMobName == null) {
        final EliteMobProperties eliteMobProperties = EliteMobProperties.getPluginData(entity.getType());
        eliteMobName = eliteMobProperties.getName();
    }
    String id = "elitemobs:" + ChatColor.stripColor(eliteMobName).replace(" ", "_").replace(String.valueOf(eliteMobEntity.getLevel()), "").replace("Lvl_$level_", "").replaceAll("[^A-Za-z0-9_]", "").toLowerCase();
    if (id.startsWith("_")) {
        id = id.substring(1);
    }
    return id;
}
Also used : EliteMobEntity(com.magmaguy.elitemobs.mobconstructor.EliteMobEntity) EliteMobProperties(com.magmaguy.elitemobs.mobconstructor.mobdata.aggressivemobs.EliteMobProperties)

Example 2 with EliteMobEntity

use of com.magmaguy.elitemobs.mobconstructor.EliteMobEntity 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)

Aggregations

EliteMobEntity (com.magmaguy.elitemobs.mobconstructor.EliteMobEntity)2 EliteMobProperties (com.magmaguy.elitemobs.mobconstructor.mobdata.aggressivemobs.EliteMobProperties)2 Tristate (com.griefdefender.api.Tristate)1 Claim (com.griefdefender.api.claim.Claim)1 Context (com.griefdefender.api.permission.Context)1 World (org.bukkit.World)1 Entity (org.bukkit.entity.Entity)1 EventHandler (org.bukkit.event.EventHandler)1