use of com.solinia.solinia.Interfaces.ISoliniaItem in project solinia3-core by mixxit.
the class SoliniaCraft method editSetting.
public void editSetting(String setting, String value) throws InvalidCraftSettingException, NumberFormatException, CoreStateInitException {
switch(setting.toLowerCase()) {
case "recipename":
if (value.equals(""))
throw new InvalidCraftSettingException("Name is empty");
if (StateManager.getInstance().getConfigurationManager().getCraft(value.toUpperCase()) != null)
throw new InvalidCraftSettingException("Recipe already exists with this name");
setRecipeName(value.toUpperCase());
break;
case "classid":
ISoliniaClass classObj = StateManager.getInstance().getConfigurationManager().getClassObj(Integer.parseInt(value));
if (classObj == null)
throw new InvalidCraftSettingException("Class does not exist");
setClassId(Integer.parseInt(value));
break;
case "skilltype":
setSkilltype(SkillType.valueOf(value));
break;
case "minskill":
if (Integer.parseInt(value) < 0)
throw new InvalidCraftSettingException("Skill must be greater than or equal to 0");
setMinSkill(Integer.parseInt(value));
break;
case "item1":
int itemId1 = Integer.parseInt(value);
ISoliniaItem solitem1 = StateManager.getInstance().getConfigurationManager().getItem(itemId1);
if (solitem1 == null) {
throw new InvalidCraftSettingException("Invalid item id (in item 1)");
}
setItem1(itemId1);
break;
case "item2":
int itemId2 = Integer.parseInt(value);
ISoliniaItem solitem2 = StateManager.getInstance().getConfigurationManager().getItem(itemId2);
if (solitem2 == null) {
throw new InvalidCraftSettingException("Invalid item id (in item 2)");
}
setItem2(itemId2);
break;
case "outputitem":
int outputitem = Integer.parseInt(value);
ISoliniaItem soloutitem = StateManager.getInstance().getConfigurationManager().getItem(outputitem);
if (soloutitem == null) {
throw new InvalidCraftSettingException("Invalid item id (out item)");
}
setOutputItem(outputitem);
break;
default:
throw new InvalidCraftSettingException("Invalid zone setting. Valid Options are: recipename,item1,item2,outputitem");
}
}
use of com.solinia.solinia.Interfaces.ISoliniaItem 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.Interfaces.ISoliniaItem in project solinia3-core by mixxit.
the class ItemStackUtils method applyAugmentationToItemStack.
public static ItemMeta applyAugmentationToItemStack(ItemStack targetItemStack, Integer sourceItemId) {
ItemMeta newMeta = targetItemStack.getItemMeta();
List<String> lore = targetItemStack.getItemMeta().getLore();
List<String> newLore = new ArrayList<String>();
for (int i = 0; i < lore.size(); i++) {
// skip, we will re-add it
if (lore.get(i).startsWith("Attached Augmentation: "))
continue;
if (lore.get(i).startsWith("AUG:"))
continue;
newLore.add(lore.get(i));
}
try {
ISoliniaItem soliniaItem = StateManager.getInstance().getConfigurationManager().getItem(sourceItemId);
if (soliniaItem != null) {
newLore.add("Attached Augmentation: " + sourceItemId);
String stattxt = "";
if (soliniaItem.getStrength() > 0) {
stattxt = ChatColor.WHITE + "STR: " + ChatColor.GREEN + soliniaItem.getStrength() + ChatColor.RESET + " ";
}
if (soliniaItem.getAgility() > 0) {
stattxt = ChatColor.WHITE + "AGI: " + ChatColor.GREEN + soliniaItem.getAgility() + ChatColor.RESET + " ";
}
if (soliniaItem.getDexterity() > 0) {
stattxt = ChatColor.WHITE + "DEX: " + ChatColor.GREEN + soliniaItem.getDexterity() + ChatColor.RESET + " ";
}
if (soliniaItem.getIntelligence() > 0) {
stattxt += ChatColor.WHITE + "INT: " + ChatColor.GREEN + soliniaItem.getIntelligence() + ChatColor.RESET + " ";
}
if (soliniaItem.getWisdom() > 0) {
stattxt += ChatColor.WHITE + "WIS: " + ChatColor.GREEN + soliniaItem.getWisdom() + ChatColor.RESET + " ";
}
if (soliniaItem.getCharisma() > 0) {
stattxt += ChatColor.WHITE + "CHA: " + ChatColor.GREEN + soliniaItem.getCharisma() + ChatColor.RESET + " ";
}
if (!stattxt.equals("")) {
newLore.add("AUG: " + stattxt);
}
String actxt = "";
if (soliniaItem.getAC() > 0) {
actxt += ChatColor.WHITE + "Armour Class: " + ChatColor.AQUA + soliniaItem.getAC() + ChatColor.RESET + " ";
}
if (!actxt.equals("")) {
newLore.add("AUG: " + actxt);
}
String hptxt = "";
if (soliniaItem.getHp() > 0) {
hptxt += ChatColor.WHITE + "HP: " + ChatColor.AQUA + soliniaItem.getHp() + ChatColor.RESET + " ";
}
if (!hptxt.equals("")) {
newLore.add("AUG: " + hptxt);
}
String manatxt = "";
if (soliniaItem.getMana() > 0) {
manatxt += ChatColor.WHITE + "Mana: " + ChatColor.AQUA + soliniaItem.getMana() + ChatColor.RESET + " ";
}
if (!manatxt.equals("")) {
newLore.add("AUG: " + manatxt);
}
String resisttxt = "";
if (soliniaItem.getFireResist() > 0) {
resisttxt += ChatColor.WHITE + "FR: " + ChatColor.AQUA + soliniaItem.getFireResist() + ChatColor.RESET + " ";
}
if (soliniaItem.getColdResist() > 0) {
resisttxt += ChatColor.WHITE + "CR: " + ChatColor.AQUA + soliniaItem.getColdResist() + ChatColor.RESET + " ";
}
if (soliniaItem.getMagicResist() > 0) {
resisttxt += ChatColor.WHITE + "MR: " + ChatColor.AQUA + soliniaItem.getMagicResist() + ChatColor.RESET + " ";
}
if (soliniaItem.getPoisonResist() > 0) {
resisttxt += ChatColor.WHITE + "PR: " + ChatColor.AQUA + soliniaItem.getPoisonResist() + ChatColor.RESET + " ";
}
if (!resisttxt.equals("")) {
newLore.add("AUG: " + resisttxt);
}
String regentxt = "";
if (soliniaItem.getHpregen() > 0 || soliniaItem.getMpregen() > 0) {
if (soliniaItem.getHpregen() > 0) {
regentxt = ChatColor.WHITE + "HPRegen: " + ChatColor.YELLOW + soliniaItem.getHpregen() + ChatColor.RESET;
}
if (soliniaItem.getMpregen() > 0) {
if (!regentxt.equals(""))
regentxt += " ";
regentxt += ChatColor.WHITE + "MPRegen: " + ChatColor.YELLOW + soliniaItem.getMpregen() + ChatColor.RESET;
}
}
if (!regentxt.equals("")) {
newLore.add("AUG: " + regentxt);
}
}
} catch (CoreStateInitException e) {
}
newMeta.setLore(newLore);
return newMeta;
}
use of com.solinia.solinia.Interfaces.ISoliniaItem 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.Interfaces.ISoliniaItem in project solinia3-core by mixxit.
the class CommandCraft method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player)) {
return false;
}
Player player = (Player) sender;
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 use in your crafting recipe");
return false;
}
ItemStack secondaryItem = player.getInventory().getItemInOffHand();
if (secondaryItem.getType().equals(Material.AIR)) {
player.sendMessage(ChatColor.GRAY + "Empty item in offhand. You must hold the item you want to use in your crafting recipe");
return false;
}
if (primaryItem.getAmount() > 1) {
player.sendMessage(ChatColor.GRAY + "Stack size in primary hand is too high (max 1)");
return false;
}
if (secondaryItem.getAmount() > 1) {
player.sendMessage(ChatColor.GRAY + "Stack size in secondary hand is too high (max 1)");
return false;
}
if (!Utils.IsSoliniaItem(primaryItem)) {
player.sendMessage("You can only create a new item from solinia items, not minecraft items");
return true;
}
if (!Utils.IsSoliniaItem(secondaryItem)) {
player.sendMessage("You can only create a new item from solinia items, not minecraft items");
return true;
}
try {
ISoliniaPlayer solPlayer = SoliniaPlayerAdapter.Adapt(player);
ISoliniaItem primarysolItem = SoliniaItemAdapter.Adapt(primaryItem);
ISoliniaItem secondarysolItem = SoliniaItemAdapter.Adapt(secondaryItem);
List<SoliniaCraft> craft = StateManager.getInstance().getConfigurationManager().getCrafts(primarysolItem.getId(), secondarysolItem.getId());
if (craft.size() < 1) {
player.sendMessage("You do not seem to know how to make anything with these items");
return true;
}
int createCount = 0;
for (SoliniaCraft craftEntry : craft) {
if (craftEntry.getClassId() > 0) {
if (solPlayer.getClassObj() == null) {
player.sendMessage("You do not seem to know how to make anything with these items");
continue;
}
if (solPlayer.getClassObj().getId() != craftEntry.getClassId()) {
player.sendMessage("You do not seem to know how to make anything with these items");
continue;
}
}
if (craftEntry.getSkilltype() != SkillType.None) {
if (craftEntry.getMinSkill() > 0) {
SoliniaPlayerSkill skill = solPlayer.getSkill(craftEntry.getSkilltype().name().toUpperCase());
if (skill == null) {
player.sendMessage("You do not seem to know how to make anything with these items");
continue;
}
if (skill.getValue() < craftEntry.getMinSkill()) {
player.sendMessage("You do not seem to know how to make anything with these items");
continue;
}
}
}
ISoliniaItem outputItem = StateManager.getInstance().getConfigurationManager().getItem(craftEntry.getOutputItem());
if (outputItem != null) {
player.getWorld().dropItemNaturally(player.getLocation(), outputItem.asItemStack());
player.sendMessage("You fashion the items together to make something new!");
createCount++;
if (craftEntry.getSkilltype() != SkillType.None) {
solPlayer.tryIncreaseSkill(craftEntry.getSkilltype().name().toUpperCase(), 1);
}
}
}
if (createCount > 0) {
player.getInventory().setItemInMainHand(null);
player.getInventory().setItemInOffHand(null);
player.updateInventory();
}
} catch (CoreStateInitException e) {
} catch (SoliniaItemException e) {
player.sendMessage("Item no longer exists");
}
return true;
}
Aggregations