Lots of progress towards a /gear gui, not finished though. commiting now because I'm leaving and don't want to lose the code.

This commit is contained in:
NewGarbo 2015-10-24 07:16:13 +01:00
parent 0c29805756
commit 089c4420b2
7 changed files with 310 additions and 91 deletions

View File

@ -119,7 +119,7 @@ public class Clans extends JavaPlugin
// Enable custom-gear related managers
PacketHandler packetHandler = new PacketHandler(this);
GearManager customGear = new GearManager(this, packetHandler);
GearManager customGear = new GearManager(this, packetHandler, _clientManager, _donationManager);
HologramManager hologram = new HologramManager(this);
_clansManager = new ClansManager(this, serverStatusManager.getCurrentServerName(), _clientManager, _donationManager, blockRestore, teleport, chat, customGear, hologram, webServerAddress);

View File

@ -6,44 +6,8 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.packethandler.IPacketHandler;
import mineplex.core.packethandler.PacketHandler;
import mineplex.core.packethandler.PacketInfo;
import mineplex.core.portal.TransferHandler;
import mineplex.core.portal.Commands.SendCommand;
import mineplex.core.portal.Commands.ServerCommand;
import mineplex.game.clans.items.attributes.AttributeContainer;
import mineplex.game.clans.items.attributes.AttributeType;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.attributes.weapon.*;
import mineplex.game.clans.items.attributes.armor.*;
import mineplex.game.clans.items.attributes.bow.*;
import mineplex.game.clans.items.commands.GearCommand;
import mineplex.game.clans.items.economy.GoldToken;
import mineplex.game.clans.items.generation.Weight;
import mineplex.game.clans.items.generation.WeightSet;
import mineplex.game.clans.items.legendaries.*;
import mineplex.game.clans.items.smelting.SmeltingListener;
import mineplex.serverdata.Region;
import mineplex.serverdata.Utility;
import mineplex.serverdata.commands.ServerCommandManager;
import mineplex.serverdata.commands.TransferCommand;
import mineplex.serverdata.serialization.RuntimeTypeAdapterFactory;
import mineplex.serverdata.servers.ServerManager;
import net.minecraft.server.v1_7_R4.Packet;
import net.minecraft.server.v1_7_R4.PacketPlayOutSetSlot;
import net.minecraft.server.v1_7_R4.PacketPlayOutWindowItems;
import net.minecraft.util.com.google.common.collect.Sets;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
@ -56,6 +20,53 @@ import org.bukkit.plugin.java.JavaPlugin;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.donation.DonationManager;
import mineplex.core.packethandler.IPacketHandler;
import mineplex.core.packethandler.PacketHandler;
import mineplex.core.packethandler.PacketInfo;
import mineplex.game.clans.items.attributes.AttributeContainer;
import mineplex.game.clans.items.attributes.AttributeType;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.attributes.armor.ConqueringArmorAttribute;
import mineplex.game.clans.items.attributes.armor.LavaAttribute;
import mineplex.game.clans.items.attributes.armor.PaddedAttribute;
import mineplex.game.clans.items.attributes.armor.ReinforcedAttribute;
import mineplex.game.clans.items.attributes.armor.SlantedAttribute;
import mineplex.game.clans.items.attributes.bow.HeavyArrowsAttribute;
import mineplex.game.clans.items.attributes.bow.HuntingAttribute;
import mineplex.game.clans.items.attributes.bow.InverseAttribute;
import mineplex.game.clans.items.attributes.bow.LeechingAttribute;
import mineplex.game.clans.items.attributes.bow.RecursiveAttribute;
import mineplex.game.clans.items.attributes.bow.ScorchingAttribute;
import mineplex.game.clans.items.attributes.bow.SlayingAttribute;
import mineplex.game.clans.items.attributes.weapon.ConqueringAttribute;
import mineplex.game.clans.items.attributes.weapon.FlamingAttribute;
import mineplex.game.clans.items.attributes.weapon.FrostedAttribute;
import mineplex.game.clans.items.attributes.weapon.HasteAttribute;
import mineplex.game.clans.items.attributes.weapon.JaggedAttribute;
import mineplex.game.clans.items.attributes.weapon.SharpAttribute;
import mineplex.game.clans.items.commands.GearCommand;
import mineplex.game.clans.items.economy.GoldToken;
import mineplex.game.clans.items.generation.Weight;
import mineplex.game.clans.items.generation.WeightSet;
import mineplex.game.clans.items.legendaries.AlligatorsTooth;
import mineplex.game.clans.items.legendaries.GiantsBroadsword;
import mineplex.game.clans.items.legendaries.HyperBlade;
import mineplex.game.clans.items.legendaries.LegendaryItem;
import mineplex.game.clans.items.legendaries.MagneticBlade;
import mineplex.game.clans.items.legendaries.WindBlade;
import mineplex.game.clans.items.smelting.SmeltingListener;
import mineplex.game.clans.items.ui.GearShop;
import mineplex.serverdata.serialization.RuntimeTypeAdapterFactory;
import net.minecraft.server.v1_7_R4.Packet;
import net.minecraft.server.v1_7_R4.PacketPlayOutSetSlot;
import net.minecraft.server.v1_7_R4.PacketPlayOutWindowItems;
/**
* Manages creation and retrieval of associated {@link PlayerGear}s with online players, as well
* as offering methods for parsing and handling {@link CustomItem}s.
@ -64,36 +75,40 @@ import com.google.gson.GsonBuilder;
*/
public class GearManager extends MiniPlugin implements IPacketHandler, Runnable
{
private static final String ITEM_SERIALIZATION_TAG = "-JSON-";
private static Gson _gson;
private static GearManager _instance; // Singleton instance
protected static final String ITEM_SERIALIZATION_TAG = "-JSON-";
protected static Gson _gson;
protected 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<ItemType> _typeWeights; // Weightings for randomly selecting item type (legendary/weapon/armour/bow)
private Set<String> _creativePlayers; // Set of names for all players currently in Creative gamemode
protected Map<String, PlayerGear> _playerGears; // Mapping of player names (key) to cached gear set (value).
protected WeightSet<Integer> _attributeWeights; // Weightings for randomly selecting number of attributes (1, 2, 3)
protected WeightSet<ItemType> _typeWeights; // Weightings for randomly selecting item type (legendary/weapon/armour/bow)
protected Set<String> _creativePlayers; // Set of names for all players currently in Creative gamemode
// Legendary generation
private WeightSet<Class<? extends LegendaryItem>> _legendaryWeights;
protected WeightSet<Class<? extends LegendaryItem>> _legendaryWeights;
// Weapon generation
private WeightSet<Material> _weaponTypes;
protected WeightSet<Material> _weaponTypes;
// Armour generation
private WeightSet<Material> _armourTypes;
protected WeightSet<Material> _armourTypes;
// Attribute generation
private WeightSet<Class<? extends ItemAttribute>> _weaponAttributes;
private WeightSet<Class<? extends ItemAttribute>> _armourAttributes;
private WeightSet<Class<? extends ItemAttribute>> _bowAttributes;
protected WeightSet<Class<? extends ItemAttribute>> _weaponAttributes;
protected WeightSet<Class<? extends ItemAttribute>> _armourAttributes;
protected WeightSet<Class<? extends ItemAttribute>> _bowAttributes;
protected GearShop _shop;
public GearManager(JavaPlugin plugin, PacketHandler packetHandler)
public GearManager(JavaPlugin plugin, PacketHandler packetHandler, CoreClientManager clientManager, DonationManager donationManager)
{
super("CustomGear", plugin);
_instance = this;
_shop = new GearShop(this, clientManager, donationManager);
_creativePlayers = new HashSet<String>();
_playerGears = new HashMap<String, PlayerGear>();
// TODO: Introduce configurable non-hardcoded values for generation weights?
@ -243,7 +258,7 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable
return item;
}
private CustomItem generateItem(ItemType itemType)
protected CustomItem generateItem(ItemType itemType)
{
switch(itemType)
{
@ -262,7 +277,7 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable
}
}
private void generateAttributes(AttributeContainer container, ItemType type, int count)
protected void generateAttributes(AttributeContainer container, ItemType type, int count)
{
for (int i = 0; i < count; i++)
{
@ -348,7 +363,7 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable
* @param type - the class-type of the object to be instantiated. (must have zero-argument constructor)
* @return a newly instantiated instance of {@code type} class-type. Instantied with zero argument constructor.
*/
private static <T> T instantiate(Class<T> type)
protected static <T> T instantiate(Class<T> type)
{
try
{
@ -360,7 +375,7 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable
}
}
private static String getItemSerialization(ItemStack item)
protected static String getItemSerialization(ItemStack item)
{
if (item == null || item.getItemMeta() == null
|| item.getItemMeta().getLore() == null) return null;
@ -419,7 +434,7 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable
* masked on CustomGear items.
* @return true, if the player should have their gear lore masked, false otherwise.
*/
private boolean maskGearPacket(Player player)
protected boolean maskGearPacket(Player player)
{
return player.getGameMode() != GameMode.CREATIVE && !_creativePlayers.contains(player.getName());
}
@ -448,7 +463,7 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable
}
}
private net.minecraft.server.v1_7_R4.ItemStack maskItem(net.minecraft.server.v1_7_R4.ItemStack item)
protected net.minecraft.server.v1_7_R4.ItemStack maskItem(net.minecraft.server.v1_7_R4.ItemStack item)
{
if (item == null) return null; // Cannot mask a null item
@ -474,4 +489,9 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable
newCopy.setItemMeta(newMeta);
return newItem;
}
public void openShop(Player player)
{
_shop.attemptShopOpen(player);
}
}

View File

@ -1,51 +1,25 @@
package mineplex.game.clans.items.commands;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Chunk;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.util.Vector;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilInput;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.core.common.util.UtilWorld;
import mineplex.core.recharge.Recharge;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClanRole;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.ClansUtility.ClanRelation;
import mineplex.game.clans.clans.ClientClan;
import mineplex.game.clans.items.CustomItem;
import mineplex.game.clans.items.GearManager;
import mineplex.game.clans.items.attributes.weapon.FlamingAttribute;
import mineplex.game.clans.items.attributes.weapon.FrostedAttribute;
import mineplex.game.clans.items.attributes.weapon.SharpAttribute;
import mineplex.game.clans.items.legendaries.LegendaryItem;
import mineplex.game.clans.items.legendaries.WindBlade;
public class GearCommand extends CommandBase<GearManager>
{
private GearManager _gearManager;
public GearCommand(GearManager plugin)
{
super(plugin, Rank.ADMIN, "gear", "custom-gear");
// Rank change is temporary, because I need to be able to test it.
super(plugin, Rank.ALL, "gear", "custom-gear");
_gearManager = plugin;
}
@Override
public void Execute(Player caller, String[] args)
{
@ -55,13 +29,15 @@ public class GearCommand extends CommandBase<GearManager>
{
Vector direction = caller.getLocation().getDirection().normalize();
_gearManager.spawnItem(caller.getEyeLocation().add(direction));
// _gearManager.openShop(caller);
}
else
{
caller.updateInventory();
//caller.setFoodLevel(10);
//return;
// caller.setFoodLevel(10);
// return;
}
}
}

View File

@ -3,7 +3,6 @@ package mineplex.game.clans.items.legendaries;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
@ -14,7 +13,6 @@ import mineplex.minecraft.game.core.damage.CustomDamageEvent;
public class LegendaryItem extends CustomItem
{
public final long BLOCK_COOLDOWN = 200l; // Right clicking activates right click for 200ms
private long _lastBlock; // Timestamp of last block from wielder

View File

@ -0,0 +1,155 @@
package mineplex.game.clans.items.ui;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.C;
import mineplex.core.donation.DonationManager;
import mineplex.core.shop.item.IButton;
import mineplex.core.shop.item.ShopItem;
import mineplex.core.shop.page.ShopPageBase;
import mineplex.game.clans.items.GearManager;
import mineplex.game.clans.items.ItemType;
import mineplex.game.clans.items.attributes.ItemAttribute;
public class GearPage extends ShopPageBase<GearManager, GearShop>
{
private final int _stages = 5;
private int _stage = 0;
private ItemType _itemType;
private List<ItemAttribute> _attributes;
private final IButton _nextButton;
private final IButton _backButton;
public GearPage(GearManager gearManager, GearShop shop, CoreClientManager clientManager, DonationManager donationManager, String name, Player player)
{
super(gearManager, shop, clientManager, donationManager, name, player);
_nextButton = new IButton()
{
public void onClick(Player player, ClickType clickType)
{
performNext();
}
};
_backButton = new IButton()
{
public void onClick(Player player, ClickType clickType)
{
performBack();
}
};
_attributes = new ArrayList<>();
}
protected void buildPage()
{
clear();
final String stageTitle;
if (_stage == 0)
{
stageTitle = "Select Item Type";
addButton(9 + 1, Material.GOLD_RECORD, 0, C.cGold + "Legendary", new IButton()
{
public void onClick(Player player, ClickType clickType)
{
}
}, new String[] { ItemType.LEGENDARY.equals(_itemType) ? C.cGreen + "Selected" : C.cRed + "Not Selected" });
addButton(9 + 3, Material.DIAMOND_AXE, 0, C.cDAqua + "Weapon", new IButton()
{
public void onClick(Player player, ClickType clickType)
{
}
}, new String[] { ItemType.WEAPON.equals(_itemType) ? C.cGreen + "Selected" : C.cRed + "Not Selected" });
addButton(9 + 5, Material.DIAMOND_CHESTPLATE, 0, C.cDGreen + "Armour", new IButton()
{
public void onClick(Player player, ClickType clickType)
{
}
}, new String[] { ItemType.ARMOUR.equals(_itemType) ? C.cGreen + "Selected" : C.cRed + "Not Selected" });
addButton(9 + 7, Material.BOW, 0, C.cDGreen + "Bow", new IButton()
{
public void onClick(Player player, ClickType clickType)
{
}
}, new String[] { ItemType.BOW.equals(_itemType) ? C.cGreen + "Selected" : C.cRed + "Not Selected" });
}
else
{
stageTitle = "Fatal Error";
}
addButton(4, Material.WOOL, 0, stageTitle);
addButton(55, Material.REDSTONE_BLOCK, 0, C.cRed + "Previous page", _backButton);
addButton(53, Material.EMERALD_BLOCK, 0, C.cGreen + "Next page", _nextButton);
}
private void addButton(final int index, final Material type, final int data, final String name, final IButton ibutton, final String... description)
{
addButton(index, new ShopItem(type, (byte) data, name, description, 1, ibutton == null, false), ibutton);
}
private void addButton(final int index, final Material type, final int data, final String name, final String... description)
{
addButton(index, new ShopItem(type, (byte) data, name, description, 1, false, false), new IButton()
{
public void onClick(Player player, ClickType clickType)
{
onClicked(player, clickType, name);
}
});
}
private void onClicked(Player player, ClickType clickType, String name)
{
}
private void performBack()
{
if (_stage > 0)
{
_stage--;
}
buildPage();
}
protected void buildItem()
{
}
protected void performNext()
{
if (_stage < _stages)
{
_stage++;
}
else
{
// This shouldn't happen...?
}
buildPage();
}
}

View File

@ -0,0 +1,23 @@
package mineplex.game.clans.items.ui;
import org.bukkit.entity.Player;
import mineplex.core.account.CoreClientManager;
import mineplex.core.donation.DonationManager;
import mineplex.core.shop.ShopBase;
import mineplex.core.shop.page.ShopPageBase;
import mineplex.game.clans.items.GearManager;
public class GearShop extends ShopBase<GearManager>
{
public GearShop(GearManager plugin, CoreClientManager clientManager, DonationManager donationManager)
{
super(plugin, clientManager, donationManager, "Customize New Gear");
}
@Override
protected ShopPageBase<GearManager, ? extends ShopBase<GearManager>> buildPagesFor(Player player)
{
return new GearPage(getPlugin(), this, getClientManager(), getDonationManager(), "Customize New Gear", player);
}
}

View File

@ -0,0 +1,47 @@
package mineplex.game.clans.items.ui;
import org.bukkit.Material;
public class StageButton
{
private int _index;
private byte _data;
private String[] _description;
private String _name;
private Material _material;
public StageButton(int index, Material material, byte data, String name, String... description)
{
_index = index;
_data = data;
_description = description;
_name = name;
_material = material;
}
public int getIndex()
{
return _index;
}
public Material getMaterial()
{
return _material;
}
public byte getData()
{
return _data;
}
public String getName()
{
return _name;
}
public String[] getDescription()
{
return _description;
}
}