use of com.solinia.solinia.Exceptions.SoliniaItemException in project solinia3-core by mixxit.
the class CommandEquip method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player) && !(sender instanceof CommandSender))
return false;
Player player = (Player) sender;
try {
ISoliniaPlayer solPlayer = SoliniaPlayerAdapter.Adapt(player);
showCurrentEquippedItems(solPlayer);
ItemStack primaryItem = player.getInventory().getItemInMainHand();
if (primaryItem.getType().equals(Material.AIR)) {
player.sendMessage(ChatColor.GRAY + "Empty item in primary hand. You must hold the item you want to equip in your main hand");
return false;
}
if (!Utils.IsSoliniaItem(primaryItem)) {
player.sendMessage("You can only equip solinia items this way");
return true;
}
ISoliniaItem item = SoliniaItemAdapter.Adapt(primaryItem);
if (item == null) {
player.sendMessage("You cannot equip this item this way");
return true;
}
if (item.getMinLevel() > solPlayer.getLevel()) {
player.sendMessage("You cannot equip this item (minlevel: " + item.getMinLevel() + ")");
return true;
}
if (solPlayer.getClassObj() == null) {
player.sendMessage(ChatColor.GRAY + "Your class cannot wear this equipment");
return true;
}
if (item.isSpellscroll()) {
player.sendMessage("You cannot equip this item");
return true;
}
if (!item.getAllowedClassNames().contains(solPlayer.getClassObj().getName().toUpperCase())) {
player.sendMessage(ChatColor.GRAY + "Your class cannot wear this equipment");
return true;
}
if (item.getMinLevel() > solPlayer.getLevel()) {
player.sendMessage(ChatColor.GRAY + "Your are not sufficient level to wear this equipment");
return true;
}
if (item.isFingersItem())
if (solPlayer.getFingersItem() > 0) {
player.sendMessage("You have already equipped an item in that slot");
return true;
} else {
solPlayer.setFingersItem(item.getId());
player.getInventory().setItemInMainHand(null);
player.updateInventory();
player.sendMessage("You have equipped this item");
return true;
}
if (item.isShouldersItem())
if (solPlayer.getShouldersItem() > 0) {
player.sendMessage("You have already equipped an item in that slot");
return true;
} else {
solPlayer.setShouldersItem(item.getId());
player.getInventory().setItemInMainHand(null);
player.updateInventory();
player.sendMessage("You have equipped this item");
return true;
}
if (item.isNeckItem())
if (solPlayer.getNeckItem() > 0) {
player.sendMessage("You have already equipped an item in that slot");
return true;
} else {
solPlayer.setNeckItem(item.getId());
player.getInventory().setItemInMainHand(null);
player.updateInventory();
player.sendMessage("You have equipped this item");
return true;
}
return false;
} catch (CoreStateInitException e) {
return false;
} catch (SoliniaItemException e) {
player.sendMessage("You cannot equip this item");
return true;
}
}
use of com.solinia.solinia.Exceptions.SoliniaItemException in project solinia3-core by mixxit.
the class SoliniaActiveSpell method applyBackstab.
private void applyBackstab(SpellEffect spellEffect, ISoliniaSpell soliniaSpell, int casterLevel) {
if (getLivingEntity().isDead())
return;
if (Bukkit.getEntity(getSourceUuid()) == null)
return;
Entity sourceEntity = Bukkit.getEntity(getSourceUuid());
if (sourceEntity == null)
return;
if (!(sourceEntity instanceof LivingEntity))
return;
LivingEntity sourceLivingEntity = (LivingEntity) sourceEntity;
try {
ISoliniaLivingEntity solSourceEntity = SoliniaLivingEntityAdapter.Adapt(sourceLivingEntity);
if (solSourceEntity == null)
return;
int backstabSkill = solSourceEntity.getSkill("BACKSTAB");
if (backstabSkill < 1)
backstabSkill = 1;
EntityDamageSource source = new EntityDamageSource("thorns", ((CraftEntity) Bukkit.getEntity(getSourceUuid())).getHandle());
source.setMagic();
source.ignoresArmor();
int weaponDamage = 0;
// Offhand item only
ItemStack mainitem = sourceLivingEntity.getEquipment().getItemInOffHand();
if (mainitem != null) {
try {
ISoliniaItem item = SoliniaItemAdapter.Adapt(mainitem);
if (item != null)
if (item.getDamage() > 0) {
weaponDamage = item.getDamage();
}
} catch (SoliniaItemException e) {
}
}
if (weaponDamage < 1)
weaponDamage = 1;
int hpToRemove = weaponDamage;
// back stab formula
if (solSourceEntity.isBehindEntity(this.getLivingEntity()))
hpToRemove = (int) Math.floor((2 + backstabSkill / 50) * weaponDamage);
((CraftEntity) getLivingEntity()).getHandle().damageEntity(source, hpToRemove);
solSourceEntity.tryIncreaseSkill("BACKSTAB", 1);
} catch (CoreStateInitException e) {
}
}
use of com.solinia.solinia.Exceptions.SoliniaItemException in project solinia3-core by mixxit.
the class Utils method getPlayerTotalCountOfItemId.
public static int getPlayerTotalCountOfItemId(Player player, int itemid) {
int total = 0;
for (int i = 0; i < 36; i++) {
ItemStack itemstack = player.getInventory().getItem(i);
if (itemstack == null)
continue;
if (itemstack.getType().equals(Material.AIR))
continue;
if (!Utils.IsSoliniaItem(itemstack))
continue;
int tmpitemid = itemstack.getEnchantmentLevel(Enchantment.DURABILITY);
// covers cases of negative tmp ids
if (tmpitemid >= 0 && tmpitemid < 1000)
continue;
try {
tmpitemid = SoliniaItemAdapter.Adapt(itemstack).getId();
} catch (SoliniaItemException e) {
continue;
} catch (CoreStateInitException e) {
continue;
}
if (tmpitemid == itemid) {
total = total + itemstack.getAmount();
}
}
return total;
}
use of com.solinia.solinia.Exceptions.SoliniaItemException in project solinia3-core by mixxit.
the class PlayerInventoryValidatorTimer method validatePlayerItems.
private void validatePlayerItems(Player player) {
try {
ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(player);
List<Integer> slots = new ArrayList<Integer>();
slots.add(36);
slots.add(37);
slots.add(38);
slots.add(39);
slots.add(40);
for (int slotId = 0; slotId < 36; slotId++) {
if (player.getInventory().getItem(slotId) == null)
continue;
try {
ISoliniaItem i = SoliniaItemAdapter.Adapt(player.getInventory().getItem(slotId));
if (i.isTemporary()) {
boolean foundFadedItem = false;
for (String loreLine : player.getInventory().getItem(slotId).getItemMeta().getLore()) {
if (!loreLine.startsWith("Temporary: "))
continue;
if (!loreLine.equals("Temporary: " + StateManager.getInstance().getInstanceGuid())) {
// Delete temporary item
player.sendMessage("Your temporary item has faded from existence");
player.getInventory().setItem(slotId, null);
player.updateInventory();
break;
}
}
if (foundFadedItem)
continue;
}
// Only monitor the defined slots
if (!slots.contains(slotId))
continue;
if (i.getMinLevel() > solplayer.getLevel()) {
player.getWorld().dropItemNaturally(player.getLocation(), player.getInventory().getItem(slotId));
player.getInventory().setItem(slotId, null);
player.updateInventory();
player.sendMessage(ChatColor.GRAY + "You cannot wear " + i.getDisplayname() + " so it has been dropped");
continue;
}
if (i.getAllowedClassNames().size() < 1)
continue;
if (solplayer.getClassObj() == null) {
player.getWorld().dropItemNaturally(player.getLocation(), player.getInventory().getItem(slotId));
player.getInventory().setItem(slotId, null);
player.updateInventory();
player.sendMessage(ChatColor.GRAY + "You cannot wear " + i.getDisplayname() + " so it has been dropped");
continue;
}
if (!i.getAllowedClassNames().contains(solplayer.getClassObj().getName().toUpperCase())) {
player.getWorld().dropItemNaturally(player.getLocation(), player.getInventory().getItem(slotId));
player.getInventory().setItem(slotId, null);
player.updateInventory();
player.sendMessage(ChatColor.GRAY + "You cannot wear " + i.getDisplayname() + " so it has been dropped");
continue;
}
} catch (SoliniaItemException e) {
continue;
}
}
} catch (CoreStateInitException e) {
// try next loop
return;
}
}
use of com.solinia.solinia.Exceptions.SoliniaItemException in project solinia3-core by mixxit.
the class CommandCreateAllArmourSets method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player) && !(sender instanceof CommandSender))
return false;
try {
if (sender instanceof Player) {
Player player = (Player) sender;
if (!player.isOp() && !player.hasPermission("solinia.createallarmorsets")) {
player.sendMessage("You do not have permission to access this command");
return false;
}
}
if (args.length < 3) {
return false;
}
// args
// lootdropid
// armourtier
// chance
// suffixname
int lootdropid = Integer.parseInt(args[0]);
int armourtier = Integer.parseInt(args[1]);
ISoliniaLootDrop lootdrop = StateManager.getInstance().getConfigurationManager().getLootDrop(lootdropid);
if (lootdrop == null) {
sender.sendMessage("Lootdrop ID does not exist");
return true;
}
if (lootdrop.isOperatorCreated() && !sender.isOp()) {
sender.sendMessage("This lootdrop was op created and you are not an op. Only ops can edit op lootdrop items");
return false;
}
int chance = Integer.parseInt(args[2]);
if (chance < 1 || chance > 100) {
sender.sendMessage("Chance must be between 1 and 100");
return true;
}
String partialname = "";
int count = 0;
for (String entry : args) {
if (count < 3) {
count++;
continue;
}
partialname += entry + " ";
count++;
}
partialname = partialname.trim();
if (partialname.equals("")) {
sender.sendMessage("Blank suffix name not allowed when creating armour set");
return false;
}
String itemscreated = "";
for (ISoliniaClass classEntry : StateManager.getInstance().getConfigurationManager().getClasses()) {
List<Integer> items = SoliniaItemFactory.CreateClassItemSet(classEntry, armourtier, partialname, true, sender.isOp());
for (Integer item : items) {
SoliniaLootFactory.CreateLootDropItem(lootdropid, item, 1, false, chance, sender.isOp());
itemscreated += item + " ";
}
}
sender.sendMessage("Created items as IDs: " + itemscreated + " with " + chance + "% chance in lootdrop: " + lootdropid);
} catch (CoreStateInitException e) {
sender.sendMessage(e.getMessage());
} catch (SoliniaItemException e) {
// TODO Auto-generated catch block
sender.sendMessage(e.getMessage());
}
return true;
}
Aggregations