Search in sources :

Example 1 with ISoliniaItem

use of com.solinia.solinia.Interfaces.ISoliniaItem in project solinia3-core by mixxit.

the class CommandCreateItem method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player) && !(sender instanceof CommandSender))
        return false;
    if (sender instanceof Player) {
        Player player = (Player) sender;
        if (!player.isOp() && !player.hasPermission("solinia.createitem")) {
            player.sendMessage("You do not have permission to access this command");
            return false;
        }
    }
    ItemStack itemstack = null;
    if (args.length == 0 && sender instanceof Player) {
        Player player = (Player) sender;
        itemstack = player.getInventory().getItemInMainHand();
        if (itemstack.getType().equals(Material.AIR)) {
            player.sendMessage(ChatColor.GRAY + "Empty item in hand. You must hold the item you want to make a new item from");
            return false;
        }
        if (Utils.IsSoliniaItem(itemstack)) {
            player.sendMessage("You can only create a new item from core minecraft items, not solinia items");
            return true;
        }
    } else {
        itemstack = new ItemStack(Material.valueOf(args[0]));
    }
    sender.sendMessage("Building new item based on: " + itemstack.getType().name());
    try {
        ISoliniaItem item = SoliniaItemFactory.CreateItem(itemstack, sender.isOp());
        sender.sendMessage("New Item Created with ID: " + item.getId());
        sender.sendMessage("Use /edititem ID to further edit this item");
    } catch (Exception e) {
        sender.sendMessage(e.getMessage());
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) CommandSender(org.bukkit.command.CommandSender) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) ItemStack(org.bukkit.inventory.ItemStack)

Example 2 with ISoliniaItem

use of com.solinia.solinia.Interfaces.ISoliniaItem in project solinia3-core by mixxit.

the class Solinia3CoreEntityListener method onEntityDamage.

@EventHandler
public void onEntityDamage(EntityDamageEvent event) {
    if (event.isCancelled())
        return;
    if (!(event instanceof EntityDamageByEntityEvent)) {
        return;
    }
    EntityDamageByEntityEvent damagecause = (EntityDamageByEntityEvent) event;
    // If the event is being blocked by a shield negate 85% of it unless its thorns then always allow it through
    if (damagecause.getDamage(DamageModifier.BLOCKING) < 0) {
        if (event.getCause().equals(DamageCause.THORNS)) {
            damagecause.setDamage(DamageModifier.BLOCKING, 0);
        } else {
            // Only give them 15% blocking
            double newarmour = (damagecause.getDamage(DamageModifier.BLOCKING) / 100) * 15;
            damagecause.setDamage(DamageModifier.BLOCKING, newarmour);
        }
    }
    // and check they are not mezzed
    try {
        if (damagecause.getDamager() instanceof LivingEntity) {
            LivingEntity attacker = (LivingEntity) damagecause.getDamager();
            // Change attacker to archer
            if (damagecause.getDamager() instanceof Arrow) {
                Arrow arr = (Arrow) attacker;
                if (arr.getShooter() instanceof LivingEntity) {
                    attacker = (LivingEntity) arr.getShooter();
                } else {
                }
            }
            // cancel attacks on mobs mezzed
            if (attacker instanceof Creature && attacker instanceof LivingEntity && event.getEntity() instanceof LivingEntity) {
                ISoliniaLivingEntity solCreatureEntity = SoliniaLivingEntityAdapter.Adapt(attacker);
                if (solCreatureEntity.isPet() || !solCreatureEntity.isPlayer()) {
                    Timestamp mezExpiry = StateManager.getInstance().getEntityManager().getMezzed((LivingEntity) event.getEntity());
                    if (mezExpiry != null) {
                        ((Creature) attacker).setTarget(null);
                        if (solCreatureEntity.isPet()) {
                            Wolf wolf = (Wolf) attacker;
                            wolf.setTarget(null);
                            solCreatureEntity.say("Stopping attacking master, the target is mesmerized");
                        }
                        event.setCancelled(true);
                        return;
                    }
                }
            }
            try {
                Timestamp mzExpiry = StateManager.getInstance().getEntityManager().getMezzed((LivingEntity) attacker);
                if (mzExpiry != null) {
                    if (attacker instanceof Player) {
                        attacker.sendMessage("* You are mezzed!");
                    }
                    Utils.CancelEvent(event);
                    ;
                    return;
                }
            } catch (CoreStateInitException e) {
            }
            List<Integer> removeSpells = new ArrayList<Integer>();
            for (SoliniaActiveSpell spell : StateManager.getInstance().getEntityManager().getActiveEntitySpells((LivingEntity) attacker).getActiveSpells()) {
                if (spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsUndead) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.Mez) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsUndead2) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.Invisibility) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.Invisibility2) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsAnimals) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.ImprovedInvisAnimals)) {
                    if (!removeSpells.contains(spell.getSpell().getId()))
                        removeSpells.add(spell.getSpell().getId());
                }
            }
            for (Integer spellId : removeSpells) {
                StateManager.getInstance().getEntityManager().removeSpellEffectsOfSpellId(plugin, ((LivingEntity) attacker).getUniqueId(), spellId);
            }
        }
    } catch (CoreStateInitException e) {
    // skip
    }
    // Remove buffs on recipient (invis should drop)
    try {
        if (event.getEntity() instanceof LivingEntity) {
            List<Integer> removeSpells = new ArrayList<Integer>();
            for (SoliniaActiveSpell spell : StateManager.getInstance().getEntityManager().getActiveEntitySpells((LivingEntity) event.getEntity()).getActiveSpells()) {
                if (spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.Mez) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsUndead) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsUndead) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsUndead2) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.Invisibility) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.Invisibility2) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsAnimals) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.ImprovedInvisAnimals)) {
                    if (!removeSpells.contains(spell.getSpell().getId()))
                        removeSpells.add(spell.getSpell().getId());
                }
            }
            for (Integer spellId : removeSpells) {
                StateManager.getInstance().getEntityManager().removeSpellEffectsOfSpellId(plugin, ((LivingEntity) event.getEntity()).getUniqueId(), spellId);
            }
        }
        // Check for rune damage
        if (event.getEntity() instanceof LivingEntity) {
            ISoliniaLivingEntity soldefender = SoliniaLivingEntityAdapter.Adapt((LivingEntity) event.getEntity());
            if (soldefender.isInvulnerable()) {
                event.setDamage(0);
                Utils.CancelEvent(event);
                ;
                if (damagecause.getDamager() instanceof Player) {
                    ((Player) damagecause.getDamager()).sendMessage("* Your attack was prevented as the target is Invulnerable!");
                }
                if (event.getEntity() instanceof Player) {
                    ((Player) event.getEntity()).sendMessage("* Your invulnerability prevented the targets attack!");
                }
            }
        }
        // see if any runes want to reduce this damage
        if (event.getEntity() instanceof LivingEntity) {
            if (!event.getCause().equals(DamageCause.THORNS)) {
                ISoliniaLivingEntity soldefender = SoliniaLivingEntityAdapter.Adapt((LivingEntity) event.getEntity());
                event.setDamage(Utils.reduceDamage(soldefender, event.getDamage()));
            }
        }
        // Check for rune damage
        if (event.getEntity() instanceof LivingEntity) {
            ISoliniaLivingEntity soldefender = SoliniaLivingEntityAdapter.Adapt((LivingEntity) event.getEntity());
            if (soldefender.getRune() > 0) {
                event.setDamage(soldefender.reduceAndRemoveRunesAndReturnLeftover(plugin, (int) event.getDamage()));
                if (event.getDamage() <= 0) {
                    Utils.CancelEvent(event);
                    ;
                    if (damagecause.getDamager() instanceof Player) {
                        ((Player) damagecause.getDamager()).sendMessage("* Your attack was absorbed by the targets Rune");
                    }
                    if (event.getEntity() instanceof Player) {
                        ((Player) event.getEntity()).sendMessage("* Your rune spell absorbed the targets attack!");
                    }
                    return;
                }
            }
        }
    } catch (CoreStateInitException e) {
    // skip
    }
    if ((damagecause.getDamager() instanceof LivingEntity || damagecause.getDamager() instanceof Arrow) && event.getEntity() instanceof LivingEntity) {
        // code
        if (event.getCause().equals(DamageCause.THORNS)) {
            if (damagecause.getDamager() instanceof Player) {
                LivingEntity recipient = (LivingEntity) event.getEntity();
                DecimalFormat df = new DecimalFormat();
                df.setMaximumFractionDigits(2);
                String name = recipient.getName();
                if (recipient.getCustomName() != null)
                    name = recipient.getCustomName();
                ((Player) damagecause.getDamager()).spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent("You SPELLDMG'd " + name + " for " + df.format(event.getDamage()) + " [" + df.format(recipient.getHealth() - event.getDamage()) + "/" + df.format(recipient.getMaxHealth()) + "]"));
            }
            if (event.getEntity() instanceof LivingEntity) {
                ISoliniaLivingEntity solentity;
                try {
                    solentity = SoliniaLivingEntityAdapter.Adapt((LivingEntity) event.getEntity());
                    if (event.getDamage() > solentity.getBukkitLivingEntity().getHealth() && solentity.hasDeathSave() > 0) {
                        Utils.CancelEvent(event);
                        solentity.removeDeathSaves(plugin);
                        solentity.getBukkitLivingEntity().sendMessage("* Your death/divine save boon has saved you from death!");
                        return;
                    }
                    solentity.damageHook(event.getDamage(), damagecause.getDamager());
                } catch (CoreStateInitException e) {
                // skip
                }
            }
            return;
        }
        try {
            Entity damager = damagecause.getDamager();
            // Change attacker to archer
            if (damagecause.getDamager() instanceof Arrow) {
                Arrow arr = (Arrow) damagecause.getDamager();
                if (arr.getShooter() instanceof LivingEntity) {
                    damager = (LivingEntity) arr.getShooter();
                    // Modify Player Bow Damage
                    if (arr.getShooter() instanceof Player) {
                        Player shooter = (Player) arr.getShooter();
                        ItemStack mainitem = shooter.getInventory().getItemInMainHand();
                        if (mainitem != null) {
                            if (mainitem.getType() == Material.BOW) {
                                int dmgmodifier = 0;
                                if (Utils.IsSoliniaItem(mainitem)) {
                                    try {
                                        ISoliniaItem item = SoliniaItemAdapter.Adapt(mainitem);
                                        if (item.getDamage() > 0 && item.getBasename().equals("BOW")) {
                                            dmgmodifier = item.getDamage();
                                        }
                                    } catch (SoliniaItemException e) {
                                    // sok just skip
                                    }
                                }
                                event.setDamage(event.getDamage() + dmgmodifier);
                            }
                        }
                    }
                } else {
                }
            }
            if (!(damager instanceof LivingEntity))
                return;
            LivingEntity attacker = (LivingEntity) damager;
            // Change attacker to archer
            if (damagecause.getDamager() instanceof Arrow) {
                Arrow arr = (Arrow) damagecause.getDamager();
                if (arr.getShooter() instanceof LivingEntity) {
                    attacker = (LivingEntity) arr.getShooter();
                } else {
                }
            }
            if (attacker == null)
                return;
            ISoliniaLivingEntity soldefender = SoliniaLivingEntityAdapter.Adapt((LivingEntity) event.getEntity());
            ISoliniaLivingEntity solattacker = SoliniaLivingEntityAdapter.Adapt((LivingEntity) attacker);
            if (attacker instanceof Player && event.getEntity() instanceof Wolf) {
                if (soldefender.isPet()) {
                    Wolf wolf = (Wolf) event.getEntity();
                    if (wolf != null) {
                        if (wolf.getTarget() == null || !wolf.getTarget().equals(attacker)) {
                            Utils.CancelEvent(event);
                            ;
                            return;
                        }
                    } else {
                        Utils.CancelEvent(event);
                        ;
                        return;
                    }
                }
            }
            if (!(event instanceof EntityDamageByEntityEvent)) {
                soldefender.damageHook(event.getDamage(), damagecause.getDamager());
                return;
            }
            solattacker.Attack(soldefender, event, damagecause.getDamager() instanceof Arrow, plugin);
        } catch (CoreStateInitException e) {
        }
    }
}
Also used : Arrow(org.bukkit.entity.Arrow) TextComponent(net.md_5.bungee.api.chat.TextComponent) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) Creature(org.bukkit.entity.Creature) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) SoliniaItemException(com.solinia.solinia.Exceptions.SoliniaItemException) Timestamp(java.sql.Timestamp) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) Wolf(org.bukkit.entity.Wolf) ItemStack(org.bukkit.inventory.ItemStack) SoliniaActiveSpell(com.solinia.solinia.Models.SoliniaActiveSpell) EventHandler(org.bukkit.event.EventHandler)

Example 3 with ISoliniaItem

use of com.solinia.solinia.Interfaces.ISoliniaItem in project solinia3-core by mixxit.

the class Solinia3CoreItemPickupListener method PickupItem.

@EventHandler
public void PickupItem(PlayerPickupItemEvent e) {
    ItemStack pickedUpItemStack = e.getItem().getItemStack();
    // Replace oxygen items with durability items
    if (pickedUpItemStack.getEnchantmentLevel(Enchantment.OXYGEN) > 999) {
        e.getPlayer().sendMessage("Detected an item in the old format, converting to the new format. Please drop all your old items and pick them up if you are having problems with them");
        try {
            ISoliniaItem latestitem = StateManager.getInstance().getConfigurationManager().getItemByOxygen(pickedUpItemStack);
            if (pickedUpItemStack != null) {
                if (latestitem != null) {
                    ItemStack latestitemstack = latestitem.asItemStack();
                    pickedUpItemStack.setItemMeta(latestitemstack.getItemMeta());
                } else {
                    // this is an item that is broken
                    e.getPlayer().sendMessage("This item is no longer implemented");
                    Utils.CancelEvent(e);
                    e.getItem().remove();
                }
            }
        } catch (CoreStateInitException eOxy) {
        }
    }
    String temporaryGuid = null;
    Integer augmentationItemId = null;
    try {
        if (Utils.IsSoliniaItem(pickedUpItemStack) && pickedUpItemStack.getType().equals(Material.ENCHANTED_BOOK)) {
            e.getPlayer().sendMessage(ChatColor.GRAY + "You have picked up an ability! To use it, hold it in your hand and right click!");
            ISoliniaItem latestitem = StateManager.getInstance().getConfigurationManager().getItem(pickedUpItemStack);
            if (pickedUpItemStack != null) {
                if (latestitem != null) {
                    ItemStack latestitemstack = latestitem.asItemStack();
                    pickedUpItemStack.setItemMeta(latestitemstack.getItemMeta());
                } else {
                    // this is an item that is broken
                    e.getPlayer().sendMessage("This item is no longer implemented");
                    Utils.CancelEvent(e);
                    e.getItem().remove();
                }
            }
            if (latestitem.getDiscoverer() == null || latestitem.getDiscoverer().equals("")) {
                latestitem.setDiscoverer(e.getPlayer().getCustomName());
                e.getPlayer().getServer().broadcastMessage(ChatColor.YELLOW + "* " + latestitem.getDisplayname() + " was discovered by " + e.getPlayer().getCustomName() + "!");
                StateManager.getInstance().getChannelManager().sendToDiscordMC(null, StateManager.getInstance().getChannelManager().getDefaultDiscordChannel(), latestitem.getDisplayname() + " was discovered by " + e.getPlayer().getCustomName() + "!");
            }
        }
        if (Utils.IsSoliniaItem(pickedUpItemStack) && !(pickedUpItemStack.getType().equals(Material.ENCHANTED_BOOK))) {
            Map<Enchantment, Integer> oldenchantments = pickedUpItemStack.getEnchantments();
            ISoliniaItem latestitem = StateManager.getInstance().getConfigurationManager().getItem(pickedUpItemStack);
            if (latestitem.getDiscoverer() == null || latestitem.getDiscoverer().equals("")) {
                latestitem.setDiscoverer(e.getPlayer().getCustomName());
                e.getPlayer().getServer().broadcastMessage(ChatColor.YELLOW + "* " + latestitem.getDisplayname() + " was discovered by " + e.getPlayer().getCustomName() + "!");
                StateManager.getInstance().getChannelManager().sendToDiscordMC(null, StateManager.getInstance().getChannelManager().getDefaultDiscordChannel(), latestitem.getDisplayname() + " was discovered by " + e.getPlayer().getCustomName() + "!");
            }
            if (pickedUpItemStack != null) {
                ItemStack latestitemstack = latestitem.asItemStack();
                // We need to store this information before we change the itemmeta, so we can update it afterwards
                if (latestitem.isTemporary()) {
                    temporaryGuid = ItemStackUtils.getTemporaryItemGuid(pickedUpItemStack);
                }
                augmentationItemId = ItemStackUtils.getAugmentationItemId(pickedUpItemStack);
                // Now go and replace the itemmeta
                pickedUpItemStack.setItemMeta(latestitemstack.getItemMeta());
                // Now re-apply enchantments that it had before
                for (Map.Entry<Enchantment, Integer> entry : oldenchantments.entrySet()) {
                    Enchantment key = entry.getKey();
                    Integer value = entry.getValue();
                    if (value < 1000) {
                        pickedUpItemStack.addUnsafeEnchantment(key, value);
                    }
                }
                // Since the item is temporary, attempt to apply the temporary timestamp it had prior to this
                if (latestitem.isTemporary()) {
                    pickedUpItemStack.setItemMeta(ItemStackUtils.applyTemporaryStamp(pickedUpItemStack, temporaryGuid));
                }
                if (augmentationItemId != null && augmentationItemId != 0) {
                    pickedUpItemStack.setItemMeta(ItemStackUtils.applyAugmentationToItemStack(pickedUpItemStack, augmentationItemId));
                }
            }
        }
        // group messages
        if (Utils.IsSoliniaItem(pickedUpItemStack)) {
            ISoliniaItem item;
            try {
                item = SoliniaItemAdapter.Adapt(pickedUpItemStack);
                if (item.getAllowedClassNames().size() > 0) {
                    ISoliniaPlayer solPlayer = SoliniaPlayerAdapter.Adapt(e.getPlayer());
                    if (solPlayer.getGroup() != null && solPlayer.getGroup().getMembers() != null)
                        for (UUID playerUuid : solPlayer.getGroup().getMembers()) {
                            if (playerUuid.equals(e.getPlayer().getUniqueId()))
                                continue;
                            Player groupMember = Bukkit.getPlayer(playerUuid);
                            ISoliniaPlayer groupSolPlayer = SoliniaPlayerAdapter.Adapt(groupMember);
                            if (groupSolPlayer != null) {
                                if (groupSolPlayer.getClassObj() != null)
                                    if (item.getAllowedClassNames().contains(groupSolPlayer.getClassObj().getName().toUpperCase())) {
                                        TextComponent tc = new TextComponent();
                                        tc.setText("* " + groupSolPlayer.getFullName() + " picked up an item of interest to your class: [" + ChatColor.AQUA + item.getDisplayname() + ChatColor.RESET + "]");
                                        tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_ITEM, new ComponentBuilder(item.asJsonString()).create()));
                                        groupSolPlayer.getBukkitPlayer().spigot().sendMessage(tc);
                                    }
                            }
                        }
                }
            } catch (SoliniaItemException e1) {
            }
        }
    } catch (CoreStateInitException coreException) {
    // do nothing
    }
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) HoverEvent(net.md_5.bungee.api.chat.HoverEvent) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) SoliniaItemException(com.solinia.solinia.Exceptions.SoliniaItemException) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ItemStack(org.bukkit.inventory.ItemStack) Enchantment(org.bukkit.enchantments.Enchantment) UUID(java.util.UUID) Map(java.util.Map) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder) EventHandler(org.bukkit.event.EventHandler)

Example 4 with ISoliniaItem

use of com.solinia.solinia.Interfaces.ISoliniaItem in project solinia3-core by mixxit.

the class SoliniaItemFactory method CreateItem.

public static ISoliniaItem CreateItem(ItemStack itemStack, boolean operatorCreated) throws SoliniaItemException, CoreStateInitException {
    SoliniaItem item = new SoliniaItem();
    item.setOperatorCreated(operatorCreated);
    item.setId(StateManager.getInstance().getConfigurationManager().getNextItemId());
    item.setBasename(itemStack.getType().name());
    item.setDisplayname(itemStack.getType().name());
    if (itemStack.getData() != null) {
        try {
            item.setColor(itemStack.getData().getData());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    if (itemStack.getType().name().equals("SKULL_ITEM")) {
        net.minecraft.server.v1_12_R1.ItemStack stack = CraftItemStack.asNMSCopy(itemStack);
        NBTTagCompound tag = stack.hasTag() ? stack.getTag() : new NBTTagCompound();
        tag.getCompound("SkullOwner").getString("Id");
        String texturevalue = tag.getCompound("SkullOwner").getCompound("Properties").getList("textures", 10).get(0).getString("Value");
        item.setTexturebase64(texturevalue);
    }
    StateManager.getInstance().getConfigurationManager().addItem(item);
    System.out.println("New Item Added: " + item.getId() + " - " + item.getDisplayname());
    return item;
}
Also used : NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) SoliniaItem(com.solinia.solinia.Models.SoliniaItem) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) SoliniaItemException(com.solinia.solinia.Exceptions.SoliniaItemException)

Example 5 with ISoliniaItem

use of com.solinia.solinia.Interfaces.ISoliniaItem in project solinia3-core by mixxit.

the class JsonItemRepository method reload.

@Override
public void reload() {
    List<ISoliniaItem> file = new ArrayList<ISoliniaItem>();
    try {
        Gson gson = new Gson();
        BufferedReader br = new BufferedReader(new FileReader(filePath));
        file = gson.fromJson(br, new TypeToken<List<SoliniaItem>>() {
        }.getType());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    items.clear();
    for (ISoliniaItem i : file) {
        items.put(i.getId(), i);
    }
    System.out.println("Reloaded " + items.size() + " items");
}
Also used : ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) FileNotFoundException(java.io.FileNotFoundException) Gson(com.google.gson.Gson) FileReader(java.io.FileReader) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)41 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)37 ItemStack (org.bukkit.inventory.ItemStack)18 Player (org.bukkit.entity.Player)16 SoliniaItemException (com.solinia.solinia.Exceptions.SoliniaItemException)14 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)14 ArrayList (java.util.ArrayList)12 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)7 ISoliniaNPC (com.solinia.solinia.Interfaces.ISoliniaNPC)7 LivingEntity (org.bukkit.entity.LivingEntity)7 TextComponent (net.md_5.bungee.api.chat.TextComponent)5 CommandSender (org.bukkit.command.CommandSender)5 Entity (org.bukkit.entity.Entity)5 EventHandler (org.bukkit.event.EventHandler)5 ISoliniaLootDropEntry (com.solinia.solinia.Interfaces.ISoliniaLootDropEntry)4 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)4 ISoliniaLootDrop (com.solinia.solinia.Interfaces.ISoliniaLootDrop)3 ISoliniaLootTableEntry (com.solinia.solinia.Interfaces.ISoliniaLootTableEntry)3 ISoliniaSpell (com.solinia.solinia.Interfaces.ISoliniaSpell)3 ISoliniaLootTable (com.solinia.solinia.Interfaces.ISoliniaLootTable)2