use of com.solinia.solinia.Exceptions.CoreStateInitException in project solinia3-core by mixxit.
the class EntityManager method getNPCMana.
@Override
public Integer getNPCMana(LivingEntity bukkitLivingEntity, ISoliniaNPC npc) {
if (bukkitLivingEntity instanceof Player)
return 0;
if (entityManaLevels.get(bukkitLivingEntity.getUniqueId()) == null) {
try {
ISoliniaLivingEntity soliniaLivingEntity = SoliniaLivingEntityAdapter.Adapt(bukkitLivingEntity);
entityManaLevels.put(bukkitLivingEntity.getUniqueId(), soliniaLivingEntity.getMaxMP());
} catch (CoreStateInitException e) {
entityManaLevels.put(bukkitLivingEntity.getUniqueId(), 1);
}
} else {
}
return entityManaLevels.get(bukkitLivingEntity.getUniqueId());
}
use of com.solinia.solinia.Exceptions.CoreStateInitException in project solinia3-core by mixxit.
the class EntityManager method SpawnPet.
@Override
public LivingEntity SpawnPet(Plugin plugin, Player owner, ISoliniaSpell spell) {
try {
LivingEntity pet = StateManager.getInstance().getEntityManager().getPet(owner);
if (pet != null) {
StateManager.getInstance().getEntityManager().killPet(owner);
}
ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getPetNPCByName(spell.getTeleportZone());
if (npc == null)
return null;
if (npc.isPet() == false)
return null;
Wolf entity = (Wolf) owner.getWorld().spawnEntity(owner.getLocation(), EntityType.WOLF);
entity.setMetadata("npcid", new FixedMetadataValue(plugin, "NPCID_" + npc.getId()));
StateManager.getInstance().getEntityManager().setPet(owner, entity);
entity.setAdult();
entity.setTamed(true);
entity.setOwner(owner);
entity.setBreed(false);
ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(owner);
entity.setCustomName(solplayer.getForename() + "'s Pet");
entity.setCustomNameVisible(true);
entity.setCanPickupItems(false);
ISoliniaLivingEntity solentity = SoliniaLivingEntityAdapter.Adapt(entity);
solentity.configurePetGoals();
entity.setMaxHealth(solentity.getMaxHP());
entity.setHealth(solentity.getMaxHP());
net.minecraft.server.v1_12_R1.EntityInsentient entityhandle = (net.minecraft.server.v1_12_R1.EntityInsentient) ((org.bukkit.craftbukkit.v1_12_R1.entity.CraftLivingEntity) entity).getHandle();
entityhandle.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).setValue((double) solentity.getMaxDamage());
owner.sendMessage("New Pet spawned with HP: " + entity.getMaxHealth() + " and " + solentity.getMaxDamage() + " dmg");
MobDisguise mob = new MobDisguise(DisguiseType.WOLF);
switch(npc.getMctype().toUpperCase()) {
case "WOLF":
mob = new MobDisguise(DisguiseType.WOLF);
break;
case "SQUID":
mob = new MobDisguise(DisguiseType.SQUID);
break;
case "PARROT":
mob = new MobDisguise(DisguiseType.PARROT);
break;
case "SKELETON":
mob = new MobDisguise(DisguiseType.SKELETON);
break;
case "BLAZE":
mob = new MobDisguise(DisguiseType.BLAZE);
break;
case "IRON_GOLEM":
mob = new MobDisguise(DisguiseType.IRON_GOLEM);
break;
case "GUARDIAN":
mob = new MobDisguise(DisguiseType.GUARDIAN);
break;
default:
mob = new MobDisguise(DisguiseType.WOLF);
break;
}
DisguiseAPI.disguiseEntity(entity, mob);
solentity.configurePetGoals();
return entity;
} catch (CoreStateInitException e) {
return null;
}
}
use of com.solinia.solinia.Exceptions.CoreStateInitException in project solinia3-core by mixxit.
the class EntityManager method doNPCSummon.
/*
@Override
public void removeTemporaryMerchantItem(int npcid, int itemid, int amount) throws InsufficientTemporaryMerchantItemException {
if (temporaryMerchantItems.get(npcid) == null)
temporaryMerchantItems.put(npcid, new ConcurrentHashMap<Integer, Integer>());
if (temporaryMerchantItems.get(npcid).get(itemid) == null)
temporaryMerchantItems.get(npcid).put(itemid, 0);
int currentCount = temporaryMerchantItems.get(npcid).get(itemid);
if (currentCount < amount)
throw new InsufficientTemporaryMerchantItemException("Vendor does not have sufficient items");
int newCount = currentCount - amount;
if (newCount < 0)
newCount = 0;
temporaryMerchantItems.get(npcid).put(itemid, newCount);
}
*/
@Override
public void doNPCSummon(Plugin plugin) {
List<Integer> completedNpcsIds = new ArrayList<Integer>();
for (Player player : Bukkit.getOnlinePlayers()) {
for (Entity entityThatWillSummon : player.getNearbyEntities(50, 50, 50)) {
if (entityThatWillSummon instanceof Player)
continue;
if (!(entityThatWillSummon instanceof LivingEntity))
continue;
LivingEntity livingEntityThatWillSummon = (LivingEntity) entityThatWillSummon;
if (!(entityThatWillSummon instanceof Creature))
continue;
if (entityThatWillSummon.isDead())
continue;
Creature creatureThatWillSummon = (Creature) entityThatWillSummon;
if (creatureThatWillSummon.getTarget() == null)
continue;
if (!Utils.isLivingEntityNPC(livingEntityThatWillSummon))
continue;
try {
ISoliniaLivingEntity solLivingEntityThatWillSummon = SoliniaLivingEntityAdapter.Adapt(livingEntityThatWillSummon);
if (completedNpcsIds.contains(solLivingEntityThatWillSummon.getNpcid()))
continue;
completedNpcsIds.add(solLivingEntityThatWillSummon.getNpcid());
solLivingEntityThatWillSummon.doSummon(plugin, creatureThatWillSummon.getTarget());
} catch (CoreStateInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
use of com.solinia.solinia.Exceptions.CoreStateInitException in project solinia3-core by mixxit.
the class CoreState method Commit.
public void Commit() throws CoreStateInitException {
if (isInitialised == false)
throw new CoreStateInitException("State not initialised");
System.out.println("Commit");
try {
playerManager.commit();
configurationManager.commit();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of com.solinia.solinia.Exceptions.CoreStateInitException in project solinia3-core by mixxit.
the class PlayerManager method loadPlayerAlt.
@Override
public ISoliniaPlayer loadPlayerAlt(Plugin plugin, Player player, UUID characterUUID) {
LocalDateTime datetime = LocalDateTime.now();
Timestamp nowtimestamp = Timestamp.valueOf(datetime);
ISoliniaPlayer solPlayer;
try {
solPlayer = SoliniaPlayerAdapter.Adapt(player);
// if its the same, why bother?
if (solPlayer.getCharacterId().equals(characterUUID))
return solPlayer;
solPlayer.removeAllEntityEffects(plugin);
solPlayer.killAllPets();
ISoliniaPlayer altSolPlayer = StateManager.getInstance().getConfigurationManager().getCharacterByCharacterUUID(characterUUID);
if (altSolPlayer == null)
return null;
if (!altSolPlayer.getUUID().equals(player.getUniqueId()))
return null;
// commit current player
StateManager.getInstance().getConfigurationManager().commitPlayerToCharacterLists(solPlayer);
// Now clear the player and load the old one
updatePlayer(player, altSolPlayer);
setPlayerLastChangeChar(player.getUniqueId(), nowtimestamp);
player.setHealth(player.getMaxHealth());
return altSolPlayer;
} catch (CoreStateInitException e) {
return null;
}
}
Aggregations