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;
}
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) {
}
}
}
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
}
}
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;
}
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");
}
Aggregations