Search in sources :

Example 31 with CoreStateInitException

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());
}
Also used : Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException)

Example 32 with CoreStateInitException

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;
    }
}
Also used : FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue) MobDisguise(me.libraryaddict.disguise.disguisetypes.MobDisguise) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) SoliniaLivingEntity(com.solinia.solinia.Models.SoliniaLivingEntity) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) Wolf(org.bukkit.entity.Wolf) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer)

Example 33 with CoreStateInitException

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();
            }
        }
    }
}
Also used : ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) SoliniaLivingEntity(com.solinia.solinia.Models.SoliniaLivingEntity) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) SoliniaLivingEntity(com.solinia.solinia.Models.SoliniaLivingEntity) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) Creature(org.bukkit.entity.Creature) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ArrayList(java.util.ArrayList)

Example 34 with CoreStateInitException

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();
    }
}
Also used : CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException)

Example 35 with CoreStateInitException

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;
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) Timestamp(java.sql.Timestamp)

Aggregations

CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)216 Player (org.bukkit.entity.Player)114 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)99 ISoliniaNPC (com.solinia.solinia.Interfaces.ISoliniaNPC)43 CommandSender (org.bukkit.command.CommandSender)42 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)41 ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)36 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)36 LivingEntity (org.bukkit.entity.LivingEntity)32 ArrayList (java.util.ArrayList)31 Entity (org.bukkit.entity.Entity)21 ItemStack (org.bukkit.inventory.ItemStack)20 SoliniaItemException (com.solinia.solinia.Exceptions.SoliniaItemException)17 ISoliniaSpell (com.solinia.solinia.Interfaces.ISoliniaSpell)16 EventHandler (org.bukkit.event.EventHandler)16 Timestamp (java.sql.Timestamp)13 TextComponent (net.md_5.bungee.api.chat.TextComponent)12 CraftEntity (org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity)11 CraftLivingEntity (org.bukkit.craftbukkit.v1_12_R1.entity.CraftLivingEntity)11 PathEntity (net.minecraft.server.v1_12_R1.PathEntity)10