More tweaks to durability system

This commit is contained in:
AlexTheCoder 2017-09-03 17:30:00 -04:00
parent 8fd19c4fd3
commit 250306302f
2 changed files with 48 additions and 20 deletions

View File

@ -11,15 +11,11 @@ import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemDamageEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilEvent;
import mineplex.core.common.util.UtilEvent.ActionType;
@ -136,7 +132,7 @@ public class DurabilityManager implements Listener
if (_itemDurabilities.containsKey(item.getType()))
{
int defaultDurability = _itemDurabilities.get(item.getType());
ItemStackFactory.Instance.SetLoreVar(item, "Durability", Math.min(defaultDurability, subtractFromDefault ? (defaultDurability - itemDamage) : itemDamage) + "");
ItemStackFactory.Instance.SetLoreVar(item, "Durability", String.valueOf(Math.min(defaultDurability, subtractFromDefault ? (defaultDurability - itemDamage) : itemDamage)));
}
else
{
@ -147,27 +143,31 @@ public class DurabilityManager implements Listener
@EventHandler
public void onDamageItem(PlayerItemDamageEvent event)
{
Gson gson = new GsonBuilder().setPrettyPrinting().create();
Bukkit.broadcastMessage("DAMAGING ITEM: " + gson.toJson(event.getItem().serialize()));
Bukkit.broadcastMessage("DAMAGE AMOUNT: " + event.getDamage());
}
@EventHandler
public void onDamageMob(EntityDamageByEntityEvent event)
{
if (event.getDamager() instanceof Player)
if (event.getItem() == null)
{
new Exception().printStackTrace();
return;
}
if (_itemDurabilities.containsKey(event.getItem().getType()))
{
int damage = event.getDamage();
int defaultDurability = _itemDurabilities.get(event.getItem().getType());
int currentDurability = ItemStackFactory.Instance.GetLoreVar(event.getItem(), "Durability", defaultDurability);
int newDurability = currentDurability - damage;
if (newDurability > 0)
{
event.setCancelled(true);
ItemStackFactory.Instance.SetLoreVar(event.getItem(), "Durability", String.valueOf(newDurability));
}
else
{
event.setDamage(999999);
}
}
}
@EventHandler
public void onUpdate(UpdateEvent event)
{
if (1 == 1)
{
return;
}
if (event.getType() == UpdateType.SEC)
{
Bukkit.getOnlinePlayers().forEach(player ->

View File

@ -9,7 +9,6 @@ import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemHeldEvent;
@ -21,7 +20,10 @@ import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.util.UtilEvent;
import mineplex.core.common.util.UtilEvent.ActionType;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilItem;
import mineplex.core.common.util.UtilServer;
import mineplex.game.clans.clans.invsee.InvseeModifyOnlineInventoryEvent;
import mineplex.game.clans.items.attributes.AttributeContainer;
@ -195,6 +197,32 @@ public class ItemListener implements Listener, Runnable
{
GearManager.getInstance().runSyncLater(() -> getGear(event.getModified()).updateCache(true), 1);
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onEquipArmor(PlayerInteractEvent event)
{
if (UtilEvent.isAction(event, ActionType.R))
{
Player player = event.getPlayer();
if (UtilItem.isHelmet(event.getItem()) && player.getInventory().getHelmet() == null)
{
GearManager.getInstance().runSyncLater(() -> getGear(player).updateCache(true), 1);
}
else if (UtilItem.isChestplate(event.getItem()) && player.getInventory().getChestplate() == null)
{
GearManager.getInstance().runSyncLater(() -> getGear(player).updateCache(true), 1);
}
else if (UtilItem.isLeggings(event.getItem()) && player.getInventory().getLeggings() == null)
{
GearManager.getInstance().runSyncLater(() -> getGear(player).updateCache(true), 1);
}
else if (UtilItem.isBoots(event.getItem()) && player.getInventory().getBoots() == null)
{
GearManager.getInstance().runSyncLater(() -> getGear(player).updateCache(true), 1);
}
}
}
/**
* @param player - the player whose gear is to be fetched