Wizards: Spell levels are now viewable on items in chest as item amount
This commit is contained in:
parent
8803941bd8
commit
25dfeacb09
@ -1,11 +1,13 @@
|
||||
package nautilus.game.arcade.game.games.wizards;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Random;
|
||||
|
||||
@ -28,6 +30,8 @@ import mineplex.core.common.util.UtilTime.TimeUnit;
|
||||
import mineplex.core.common.util.UtilWorld;
|
||||
import mineplex.core.hologram.Hologram;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
import mineplex.core.packethandler.IPacketHandler;
|
||||
import mineplex.core.packethandler.PacketInfo;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.minecraft.game.core.combat.CombatManager.AttackReason;
|
||||
@ -46,6 +50,8 @@ import nautilus.game.arcade.game.games.wizards.spellinterfaces.SpellClickBlock;
|
||||
import nautilus.game.arcade.game.games.wizards.spellinterfaces.SpellClickEntity;
|
||||
import nautilus.game.arcade.kit.Kit;
|
||||
import net.minecraft.server.v1_7_R4.EntityFireball;
|
||||
import net.minecraft.server.v1_7_R4.PacketPlayOutSetSlot;
|
||||
import net.minecraft.server.v1_7_R4.PacketPlayOutWindowItems;
|
||||
|
||||
import org.apache.commons.lang.IllegalClassException;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -59,6 +65,7 @@ import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.block.DoubleChest;
|
||||
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftFireball;
|
||||
import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Fireball;
|
||||
@ -117,6 +124,8 @@ public class Wizards extends SoloGame
|
||||
private NautHashMap<SpellType, Spell> _spells = new NautHashMap<SpellType, Spell>();
|
||||
private WizardSpellMenu _wizard;
|
||||
private NautHashMap<String, Wizard> _wizards = new NautHashMap<String, Wizard>();
|
||||
private Field _itemField;
|
||||
private IPacketHandler _wizardSpellLevelHandler;
|
||||
|
||||
public Wizards(ArcadeManager manager)
|
||||
{
|
||||
@ -158,11 +167,135 @@ public class Wizards extends SoloGame
|
||||
SoupEnabled = false;
|
||||
DamageTeamSelf = true;
|
||||
|
||||
try
|
||||
{
|
||||
_itemField = PacketPlayOutSetSlot.class.getDeclaredField("c");
|
||||
_itemField.setAccessible(true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
Manager.getCosmeticManager().setHideParticles(true);
|
||||
Manager.GetDamage().GetCombatManager().setUseWeaponName(AttackReason.DefaultWeaponName);
|
||||
|
||||
createLoot();
|
||||
|
||||
_wizardSpellLevelHandler = new IPacketHandler()
|
||||
{
|
||||
@Override
|
||||
public void handle(PacketInfo packetInfo)
|
||||
{
|
||||
if (packetInfo.getPacket() instanceof PacketPlayOutWindowItems
|
||||
|| packetInfo.getPacket() instanceof PacketPlayOutSetSlot)
|
||||
{
|
||||
Inventory inv = packetInfo.getPlayer().getOpenInventory().getTopInventory();
|
||||
|
||||
if (inv.getType() == InventoryType.CHEST)
|
||||
{
|
||||
if (packetInfo.getPacket() instanceof PacketPlayOutWindowItems)
|
||||
{
|
||||
Wizard wizard = getWizard(packetInfo.getPlayer());
|
||||
|
||||
if (wizard != null)
|
||||
{
|
||||
PacketPlayOutWindowItems packet = (PacketPlayOutWindowItems) packetInfo.getPacket();
|
||||
boolean ownPacket = false;
|
||||
|
||||
ItemStack[] items = new ItemStack[packet.b.length];
|
||||
|
||||
for (int i = 0; i < items.length; i++)
|
||||
{
|
||||
items[i] = CraftItemStack.asBukkitCopy(packet.b[i]);
|
||||
|
||||
ItemStack item = items[i];
|
||||
|
||||
if (item != null && item.getType() != Material.AIR)
|
||||
{
|
||||
SpellType spellType = getSpell(item);
|
||||
|
||||
if (spellType != null)
|
||||
{
|
||||
if (wizard.getSpellLevel(spellType) < spellType.getMaxLevel())
|
||||
{
|
||||
item.setAmount(wizard.getSpellLevel(spellType) + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
item.setAmount(0);
|
||||
}
|
||||
|
||||
ownPacket = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ownPacket)
|
||||
{
|
||||
List list = new ArrayList();
|
||||
|
||||
for (ItemStack item : items)
|
||||
{
|
||||
list.add(CraftItemStack.asNMSCopy(item));
|
||||
}
|
||||
|
||||
packetInfo.setCancelled(true);
|
||||
|
||||
packet = new PacketPlayOutWindowItems(packet.a, list);
|
||||
|
||||
packetInfo.getVerifier().bypassProcess(packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PacketPlayOutSetSlot packet = (PacketPlayOutSetSlot) packetInfo.getPacket();
|
||||
|
||||
ItemStack item = null;
|
||||
|
||||
try
|
||||
{
|
||||
item = CraftItemStack.asBukkitCopy((net.minecraft.server.v1_7_R4.ItemStack) _itemField
|
||||
.get(packet));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
if (item != null && item.getType() != Material.AIR)
|
||||
{
|
||||
SpellType spellType = getSpell(item);
|
||||
|
||||
if (spellType != null)
|
||||
{
|
||||
Wizard wizard = getWizard(packetInfo.getPlayer());
|
||||
|
||||
if (wizard != null)
|
||||
{
|
||||
if (wizard.getSpellLevel(spellType) < spellType.getMaxLevel())
|
||||
{
|
||||
item.setAmount(wizard.getSpellLevel(spellType) + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
item.setAmount(0);
|
||||
}
|
||||
|
||||
packetInfo.setCancelled(true);
|
||||
|
||||
packet = new PacketPlayOutSetSlot(packet.a, packet.b, CraftItemStack.asNMSCopy(item));
|
||||
|
||||
packetInfo.getVerifier().bypassProcess(packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void addRandomItem(int amount, Material itemType, int newDurability, int minAmount, int maxAmount)
|
||||
@ -404,6 +537,19 @@ public class Wizards extends SoloGame
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void handleEntityPacket(GameStateChangeEvent event)
|
||||
{
|
||||
if (event.GetState() == GameState.Live)
|
||||
{
|
||||
getArcadeManager().getPacketHandler().addPacketHandler(_wizardSpellLevelHandler);
|
||||
}
|
||||
else if (event.GetState() == GameState.Dead)
|
||||
{
|
||||
getArcadeManager().getPacketHandler().removePacketHandler(_wizardSpellLevelHandler);
|
||||
}
|
||||
}
|
||||
|
||||
private void createLoot()
|
||||
{
|
||||
for (SpellType spellType : SpellType.values())
|
||||
|
Loading…
Reference in New Issue
Block a user