Mineplex2018-withcommit/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/GearManager.java

107 lines
3.4 KiB
Java
Raw Normal View History

package mineplex.game.clans.items;
import java.util.HashMap;
import java.util.Map;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.portal.TransferHandler;
import mineplex.core.portal.Commands.SendCommand;
import mineplex.core.portal.Commands.ServerCommand;
import mineplex.game.clans.items.commands.GearCommand;
import mineplex.game.clans.items.generation.Weight;
import mineplex.game.clans.items.generation.WeightSet;
import mineplex.serverdata.Region;
import mineplex.serverdata.Utility;
import mineplex.serverdata.commands.ServerCommandManager;
import mineplex.serverdata.commands.TransferCommand;
import mineplex.serverdata.servers.ServerManager;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
/**
* Manages creation and retrieval of associated {@link PlayerGear}s with online players, as well
* as offering methods for parsing and handling {@link CustomItem}s.
* @author MrTwiggy
*
*/
public class GearManager extends MiniPlugin
{
private static GearManager _instance; // Singleton instance
private Map<String, PlayerGear> playerGears; // Mapping of player names (key) to cached gear set (value).
private WeightSet<Integer> _attributeWeights; // Weightings for randomly selecting number of attributes (1, 2, 3)
private WeightSet<Boolean> _itemWeights; // Weightings for randomly selecting item type (legendary/rare)
private WeightSet<Boolean> _gearWeights; // Weightings for randomly selecting gear type (armour/weapon)
public GearManager(JavaPlugin plugin)
{
super("CustomGear", plugin);
_instance = this;
playerGears = new HashMap<String, PlayerGear>();
_attributeWeights = new WeightSet<Integer>(new Weight<Integer>(3, 3), new Weight<Integer>(20, 2), new Weight<Integer>(77, 1));
_itemWeights = new WeightSet<Boolean>(new Weight<Boolean>(90, true), new Weight<Boolean>(10, false));
_itemWeights = new WeightSet<Boolean>(new Weight<Boolean>(50, true), new Weight<Boolean>(50, false));
System.out.println("-Testting-testing");
System.out.println(Utility.currentTimeSeconds());
}
@Override
public void addCommands()
{
addCommand(new GearCommand(this));
}
/**
* @param player - the player whose {@link PlayerGear} set is to be fetched.
* @return the cached or newly instantiated {@link PlayerGear} associated with {@code player}.
*/
public PlayerGear getPlayerGear(Player player)
{
String playerName = player.getName();
if (!playerGears.containsKey(playerName))
{
PlayerGear gear = new PlayerGear(playerName);
playerGears.put(playerName, gear);
}
return playerGears.get(playerName);
}
public CustomItem generateItem()
{
int attributeCount = _attributeWeights.generateRandom();
boolean isLegendary = _itemWeights.generateRandom();
boolean isArmour = _gearWeights.generateRandom();
// TODO: Generate custom item randomly using generated values above
return null;
}
public static CustomItem parseItem(ItemStack item)
{
return null; // TODO: Parse CustomItem from hidden JSON-encoded lore string in item passed in
}
public static boolean isCustomItem(ItemStack item)
{
return parseItem(item) != null; // TODO: Check for JSON-encoded lore string instead of deserializing?
}
/**
* @return singleton instance of {@link GearManager}.
*/
public static GearManager getInstane()
{
return _instance;
}
}