use of com.github.sirblobman.api.nms.EntityHandler in project CombatLogX by SirBlobman.
the class ListenerLogger method getEntityName.
private String getEntityName(Entity entity) {
if (entity == null) {
CommandSender console = Bukkit.getConsoleSender();
LanguageManager languageManager = getLanguageManager();
return languageManager.getMessage(console, "placeholder.unknown-enemy", null, true);
}
ICombatLogX combatLogX = getCombatLogX();
MultiVersionHandler multiVersionHandler = combatLogX.getMultiVersionHandler();
EntityHandler entityHandler = multiVersionHandler.getEntityHandler();
return entityHandler.getName(entity);
}
use of com.github.sirblobman.api.nms.EntityHandler in project CombatLogX by SirBlobman.
the class ListenerJoin method setHealth.
private void setHealth(Player player, double health) {
if (Double.isInfinite(health) || Double.isNaN(health)) {
health = 0.0D;
}
ICombatLogX combatLogX = getCombatLogX();
MultiVersionHandler multiVersionHandler = combatLogX.getMultiVersionHandler();
EntityHandler entityHandler = multiVersionHandler.getEntityHandler();
double maxHealth = entityHandler.getMaxHealth(player);
if (maxHealth < health) {
entityHandler.setMaxHealth(player, health);
}
player.setHealth(health);
}
use of com.github.sirblobman.api.nms.EntityHandler in project CombatLogX by SirBlobman.
the class CombatNpcManager method createNPC.
public void createNPC(Player player) {
if (player == null || player.hasMetadata("NPC")) {
printDebug("player was null or an NPC, not spawning.");
return;
}
UUID uuid = player.getUniqueId();
String playerName = player.getName();
printDebug("Spawning NPC for player '" + playerName + "'.");
EntityType entityType = getEntityType();
NPCRegistry npcRegistry = CitizensAPI.getNPCRegistry();
NPC npc = npcRegistry.createNPC(entityType, playerName);
printDebug("Created NPC with entity type " + entityType + ".");
Location location = player.getLocation();
boolean spawn = npc.spawn(location);
if (!spawn) {
printDebug("Failed to spawn an NPC. (npc.spawn() returned false)");
return;
}
Entity entity = npc.getEntity();
if (!(entity instanceof LivingEntity)) {
printDebug("NPC for player '" + playerName + "' is not a LivingEntity, removing...");
npc.destroy();
return;
}
LivingEntity livingEntity = (LivingEntity) entity;
npc.setProtected(false);
if (npc.hasTrait(Owner.class)) {
npc.removeTrait(Owner.class);
}
ICombatLogX plugin = this.expansion.getPlugin();
MultiVersionHandler multiVersionHandler = plugin.getMultiVersionHandler();
EntityHandler entityHandler = multiVersionHandler.getEntityHandler();
double health = player.getHealth();
double maxHealth = entityHandler.getMaxHealth(livingEntity);
if (maxHealth < health)
entityHandler.setMaxHealth(livingEntity, health);
livingEntity.setHealth(health);
YamlConfiguration configuration = getConfiguration();
if (configuration.getBoolean("mob-target")) {
double radius = configuration.getDouble("mob-target-radius");
List<Entity> nearbyEntityList = livingEntity.getNearbyEntities(radius, radius, radius);
for (Entity nearby : nearbyEntityList) {
if (!(nearby instanceof Monster)) {
continue;
}
Monster monster = (Monster) nearby;
monster.setTarget(livingEntity);
}
}
CombatNPC combatNPC = new CombatNPC(this.expansion, npc, player);
this.playerNpcMap.put(uuid, combatNPC);
this.npcCombatMap.put(npc.getUniqueId(), combatNPC);
ICombatManager combatManager = plugin.getCombatManager();
LivingEntity enemyEntity = combatManager.getEnemy(player);
if (enemyEntity instanceof Player)
combatNPC.setEnemy((Player) enemyEntity);
saveLocation(player, npc);
saveInventory(player);
equipNPC(player, npc);
CitizensExpansion citizensExpansion = getExpansion();
if (citizensExpansion.isSentinelEnabled()) {
if (enemyEntity != null && configuration.getBoolean("attack-first")) {
SentinelTrait sentinelTrait = npc.getOrAddTrait(SentinelTrait.class);
sentinelTrait.setInvincible(false);
sentinelTrait.respawnTime = -1;
UUID enemyId = enemyEntity.getUniqueId();
String enemyIdString = enemyId.toString();
SentinelTargetLabel targetLabel = new SentinelTargetLabel("uuid:" + enemyIdString);
targetLabel.addToList(sentinelTrait.allTargets);
}
}
combatNPC.start();
}
use of com.github.sirblobman.api.nms.EntityHandler in project CombatLogX by SirBlobman.
the class PlaceholderHelper method getEnemyName.
public static String getEnemyName(ICombatLogX plugin, Player player) {
ICombatManager combatManager = plugin.getCombatManager();
LivingEntity enemy = combatManager.getEnemy(player);
if (enemy == null)
return getUnknownEnemy(plugin, player);
MultiVersionHandler multiVersionHandler = plugin.getMultiVersionHandler();
EntityHandler entityHandler = multiVersionHandler.getEntityHandler();
return entityHandler.getName(enemy);
}
use of com.github.sirblobman.api.nms.EntityHandler in project CombatLogX by SirBlobman.
the class ListenerDamage method getName.
private String getName(Entity entity) {
ICombatLogX plugin = getCombatLogX();
if (entity == null) {
CommandSender console = Bukkit.getConsoleSender();
LanguageManager languageManager = plugin.getLanguageManager();
return languageManager.getMessage(console, "placeholder.unknown-enemy", null, true);
}
MultiVersionHandler multiVersionHandler = plugin.getMultiVersionHandler();
EntityHandler entityHandler = multiVersionHandler.getEntityHandler();
return entityHandler.getName(entity);
}
Aggregations