Refactored getting item count for ClientInventory

Fixed up Arcade gem boosters so they are hooked into inventory.
Cleaned up unused code.
This commit is contained in:
Jonathan Williams 2014-08-08 22:10:02 -05:00
parent db90bcc958
commit 6bd9273edf
7 changed files with 83 additions and 48 deletions

View File

@ -5,11 +5,6 @@ import mineplex.core.common.util.NautHashMap;
public class ClientInventory
{
public NautHashMap<String, ClientItem> Items = new NautHashMap<String, ClientItem>();
public int getChestCount()
{
return Items.containsKey("LootChest") ? Items.get("LootChest").Count : 0;
}
public void addItem(ClientItem item)
{
@ -29,4 +24,9 @@ public class ClientInventory
if (Items.get(item.Item.Name).Count == 0)
Items.remove(item.Item.Name);
}
public int getItemCount(String name)
{
return Items.containsKey(name) ? Items.get(name).Count : 0;
}
}

View File

@ -43,15 +43,23 @@ public class InventoryManager extends MiniClientPlugin<ClientInventory>
private NautHashMap<String, Item> _items = new NautHashMap<String, Item>();
private NautHashMap<String, Category> _categories = new NautHashMap<String, Category>();
private boolean _userInterface = false;
public InventoryManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, GadgetManager gadgetManager, MountManager mountManager, PetManager petManager)
{
this(plugin, clientManager, donationManager, gadgetManager, mountManager, petManager, true);
}
public InventoryManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, GadgetManager gadgetManager, MountManager mountManager, PetManager petManager, boolean userInterface)
{
super("Inventory Manager", plugin);
_gadgetManager = gadgetManager;
_mountManager = mountManager;
_petManager = petManager;
_userInterface = userInterface;
_inventoryShop = new InventoryShop(this, clientManager, donationManager, _moduleName);
_inventoryShop = new InventoryShop(this, clientManager, donationManager, "Inventory");
_repository = new InventoryRepository(plugin);
@ -151,12 +159,18 @@ public class InventoryManager extends MiniClientPlugin<ClientInventory>
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event)
{
if (!_userInterface)
return;
event.getPlayer().getInventory().setItem(4, ItemStackFactory.Instance.CreateStack(Material.CHEST, (byte)0, 1, ChatColor.RESET + C.cGreen + "Inventory Menu"));
}
@EventHandler
public void orderThatChest(final PlayerDropItemEvent event)
{
if (!_userInterface)
return;
if (event.getItemDrop().getItemStack().getType() == Material.CHEST)
{
Bukkit.getScheduler().scheduleSyncDelayedTask(GetPlugin(), new Runnable()
@ -177,6 +191,9 @@ public class InventoryManager extends MiniClientPlugin<ClientInventory>
@EventHandler
public void openShop(PlayerInteractEvent event)
{
if (!_userInterface)
return;
if (event.hasItem() && event.getItem().getType() == Material.CHEST)
{
event.setCancelled(true);

View File

@ -5,7 +5,6 @@ import org.bukkit.entity.Player;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.CurrencyType;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.donation.DonationManager;
import mineplex.core.gadget.types.Gadget;
@ -40,10 +39,9 @@ public class Menu extends ShopPageBase<InventoryManager, InventoryShop>
protected void BuildPage()
{
AddItem(11, new ShopItem(175, DonationManager.Get(Player.getName()).getCoins() + " Coins", 1, false));
AddItem(13, new ShopItem(Material.CHEST, Plugin.Get(Player).getChestCount() + " Chests", 1, false));
AddItem(13, new ShopItem(Material.CHEST, Plugin.Get(Player).getItemCount("Treasure Chest") + " Chests", 1, false));
int gemBoosters = Plugin.Get(Player).Items.containsKey("Gem Booster") ? Plugin.Get(Player).Items.get("Gem Booster").Count : 0;
final GemBooster gemBoosterItem = new GemBooster(gemBoosters);
final GemBooster gemBoosterItem = new GemBooster(Plugin.Get(Player).getItemCount("Gem Booster"));
if (DonationManager.Get(Player.getName()).GetBalance(CurrencyType.Coins) >= gemBoosterItem.GetCost(CurrencyType.Coins))
{

View File

@ -11,6 +11,7 @@ import java.io.InputStreamReader;
import mineplex.core.account.CoreClientManager;
import mineplex.core.antihack.AntiHack;
import mineplex.core.antistack.AntiStack;
import mineplex.core.blockrestore.BlockRestore;
import mineplex.core.blood.Blood;
import mineplex.core.command.CommandCenter;
import mineplex.core.common.util.FileUtil;
@ -18,13 +19,17 @@ import mineplex.core.common.util.UtilServer;
import mineplex.core.creature.Creature;
import mineplex.core.disguise.DisguiseManager;
import mineplex.core.donation.DonationManager;
import mineplex.core.gadget.GadgetManager;
import mineplex.core.inventory.InventoryManager;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.logger.Logger;
import mineplex.core.memory.MemoryFix;
import mineplex.core.message.MessageManager;
import mineplex.core.monitor.LagMeter;
import mineplex.core.mount.MountManager;
import mineplex.core.npc.NpcManager;
import mineplex.core.packethandler.PacketHandler;
import mineplex.core.pet.PetManager;
import mineplex.core.portal.Portal;
import mineplex.core.preferences.PreferencesManager;
import mineplex.core.punish.Punish;
@ -96,8 +101,14 @@ public class Arcade extends JavaPlugin
Punish punish = new Punish(this, webServerAddress, _clientManager);
AntiHack.Initialize(this, punish, portal);
BlockRestore blockRestore = new BlockRestore(this);
PetManager petManager = new PetManager(this, _clientManager, _donationManager, creature, webServerAddress);
MountManager mountManager = new MountManager(this, _clientManager, _donationManager, blockRestore);
InventoryManager inventoryManager = new InventoryManager(this, _clientManager, _donationManager, new GadgetManager(this, _clientManager, _donationManager, mountManager, petManager, preferenceManager, disguiseManager, blockRestore), mountManager, petManager);
//Arcade Manager
_gameManager = new ArcadeManager(this, serverStatusManager, ReadServerConfig(), _clientManager, _donationManager, _damageManager, disguiseManager, creature, teleport, new Blood(this), antistack, portal, packetHandler, preferenceManager, webServerAddress);
_gameManager = new ArcadeManager(this, serverStatusManager, ReadServerConfig(), _clientManager, _donationManager, _damageManager, disguiseManager, creature, teleport, new Blood(this), antistack, portal, packetHandler, preferenceManager, inventoryManager, webServerAddress);
new MemoryFix(this);

View File

@ -50,6 +50,7 @@ import mineplex.minecraft.game.core.condition.Condition.ConditionType;
import mineplex.minecraft.game.core.damage.DamageManager;
import mineplex.minecraft.game.core.fire.Fire;
import mineplex.core.MiniPlugin;
import mineplex.core.inventory.InventoryManager;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.account.CoreClientManager;
import mineplex.core.achievement.AchievementManager;
@ -105,6 +106,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
private GameLobbyManager _gameLobbyManager;
private GameWorldManager _gameWorldManager;
private ServerStatusManager _serverStatusManager;
private InventoryManager _inventoryManager;
private AchievementManager _achievementManager;
private StatsManager _statsManager;
@ -129,7 +131,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
public ArcadeManager(Arcade plugin, ServerStatusManager serverStatusManager, GameServerConfig serverConfig,
CoreClientManager clientManager, DonationManager donationManager, DamageManager damageManager,
DisguiseManager disguiseManager, Creature creature, Teleport teleport, Blood blood, AntiStack antistack,
Portal portal, PacketHandler packetHandler, PreferencesManager preferences, String webAddress)
Portal portal, PacketHandler packetHandler, PreferencesManager preferences, InventoryManager inventoryManager, String webAddress)
{
super("Game Manager", plugin);
@ -200,7 +202,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
_statsManager = new StatsManager(plugin);
_achievementManager = new AchievementManager(_statsManager);
_inventoryManager = inventoryManager;
_portal = portal;
// Shop
@ -796,4 +798,9 @@ public class ArcadeManager extends MiniPlugin implements IRelation
System.out.println("Teleporting: " + event.getPlayer().getName() + " to "
+ event.getTo().getWorld().getWorldFolder().getName());
}
public InventoryManager getInventoryManager()
{
return _inventoryManager;
}
}

View File

@ -3,17 +3,13 @@ package nautilus.game.arcade.game;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import mineplex.core.timing.TimingManager;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.updater.UpdateType;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTime;
@ -25,7 +21,6 @@ import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.events.PlayerGameRespawnEvent;
import nautilus.game.arcade.events.PlayerStateChangeEvent;
import nautilus.game.arcade.game.GameTeam.PlayerState;
import nautilus.game.arcade.game.games.GameScore;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
@ -33,7 +28,6 @@ import nautilus.game.arcade.managers.GameLobbyManager;
import nautilus.game.arcade.scoreboard.GameScoreboard;
import nautilus.game.arcade.world.WorldData;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
@ -44,13 +38,8 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Score;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team;
import org.bukkit.util.Vector;
public abstract class Game implements Listener
@ -1063,6 +1052,7 @@ public abstract class Game implements Listener
Announce(F.elem(player.getName()) + " used a " + F.elem(C.cGreen + "Gem Booster") + " for " + F.elem("+" + (100-(GemBoosters.size()*25)) + "% Gems") + "!");
GemBoosters.add(player.getName());
Manager.getInventoryManager().addItemToInventory(player, "Utility", "Gem Booster", -1);
}
public double GetGemBoostAmount()

View File

@ -3,7 +3,6 @@ package nautilus.game.arcade.managers;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
@ -29,10 +28,9 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityCombustEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Scoreboard;
@ -44,7 +42,6 @@ import mineplex.core.common.util.MapUtil;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilText;
import mineplex.core.common.util.UtilText.TextAlign;
@ -1110,6 +1107,21 @@ public class GameLobbyManager implements IPacketRunnable, Listener
}
}
@EventHandler
public void gemBoosterMovement(InventoryClickEvent event)
{
if (Manager.IsTournamentServer())
return;
if (Manager.GetGame() == null)
return;
if (Manager.GetGame().GetState() != GameState.Recruit)
return;
UtilInv.DisallowMovementOf(event, C.cGreen + "Gem Booster", Material.EMERALD, (byte)0, true);
}
@EventHandler
public void GemBoosterUpdate(UpdateEvent event)
{
@ -1127,31 +1139,28 @@ public class GameLobbyManager implements IPacketRunnable, Listener
for (Player player : UtilServer.getPlayers())
{
if (!player.getInventory().contains(Material.EMERALD))
{
player.getInventory().setItem(
7,
ItemStackFactory.Instance.CreateStack(Material.EMERALD, (byte) 0, 1, (short) 0, C.cGreen
+ "Gem Booster", new String[] { "", ChatColor.RESET + "Boosts Gems earned for",
ChatColor.RESET + "everyone in the game." }));
}
int gemBoosters = Manager.getInventoryManager().Get(player).Items.containsKey("Gem Booster") ? Manager.getInventoryManager().Get(player).Items.get("Gem Booster").Count : 0;
for (int i : player.getInventory().all(Material.EMERALD).keySet())
{
ItemStack stack = player.getInventory().getItem(i);
ItemMeta itemMeta = stack.getItemMeta();
itemMeta.setDisplayName(C.cGreen + "Gem Booster" +
" " + C.cWhite + "Click for " + (100-Manager.GetGame().GemBoosters.size()*25) + "% Boost");
stack.setItemMeta(itemMeta);
player.getInventory().setItem(i, stack);
}
player.getInventory().setItem(
7,
ItemStackFactory.Instance.CreateStack(Material.EMERALD, (byte) 0, 1, (short) 0, C.cGreen
+ "Gem Booster",
new String[]
{
C.cYellow + "Click for " + C.cGreen + (100-Manager.GetGame().GemBoosters.size()*25) + "%" + C.cYellow + " Boost",
" ",
ChatColor.RESET + "Boosts Gems earned for",
ChatColor.RESET + "everyone in the game.",
" ",
C.cWhite + "Your Gem Boosters: " + C.cGreen + gemBoosters,
}
)
);
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void HubClockInteract(PlayerInteractEvent event)
public void GemBoosterInteract(PlayerInteractEvent event)
{
if (Manager.IsTournamentServer())
return;
@ -1167,6 +1176,9 @@ public class GameLobbyManager implements IPacketRunnable, Listener
if (Manager.GetGame() == null)
return;
if (Manager.getInventoryManager().Get(player).getItemCount("Gem Booster") <= 0)
return;
Manager.GetGame().AddGemBooster(player);
}
}