Added RareItemFactory (will add shine when lib helps me with it) and other small little fixes. Added a way to specify the amount of items in a single line in GearPage, so that armor and weapon type listings look more aesthetically pleasing.

This commit is contained in:
NewGarbo 2015-10-26 12:21:33 +00:00
parent 63406e9ce1
commit eb350a79c3
16 changed files with 140 additions and 287 deletions

View File

@ -96,5 +96,20 @@ public class UtilMath
return null;
return array[random.nextInt(array.length)];
}
public static double clamp(double num, double min, double max)
{
return num < min ? min : (num > max ? max : num);
}
public static long clamp(long num, long min, long max)
{
return num < min ? min : (num > max ? max : num);
}
public static int clamp(int num, int min, int max)
{
return num < min ? min : (num > max ? max : num);
}
}

View File

@ -5,8 +5,6 @@ import org.bukkit.World;
import org.bukkit.craftbukkit.v1_7_R4.CraftWorld;
import org.bukkit.plugin.java.JavaPlugin;
import net.minecraft.server.v1_7_R4.MinecraftServer;
import mineplex.core.FoodDupeFix;
import mineplex.core.TablistFix;
import mineplex.core.account.CoreClientManager;
@ -26,12 +24,9 @@ import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.memory.MemoryFix;
import mineplex.core.message.MessageManager;
import mineplex.core.monitor.LagMeter;
import mineplex.game.clans.clans.observer.ObserverManager;
import mineplex.game.clans.items.GearManager;
import mineplex.core.packethandler.PacketHandler;
import mineplex.core.portal.Portal;
import mineplex.core.preferences.PreferencesManager;
import mineplex.core.profileCache.ProfileCacheManager;
import mineplex.core.punish.Punish;
import mineplex.core.recharge.Recharge;
import mineplex.core.serverConfig.ServerConfiguration;
@ -43,11 +38,14 @@ import mineplex.core.updater.FileUpdater;
import mineplex.core.updater.Updater;
import mineplex.core.visibility.VisibilityManager;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.items.GearManager;
import mineplex.game.clans.items.RareItemFactory;
import mineplex.game.clans.shop.building.BuildingShop;
import mineplex.game.clans.shop.farming.FarmingShop;
import mineplex.game.clans.shop.mining.MiningShop;
import mineplex.game.clans.shop.pvp.PvpShop;
import mineplex.game.clans.spawn.travel.TravelShop;
import net.minecraft.server.v1_7_R4.MinecraftServer;
public class Clans extends JavaPlugin
{
@ -77,6 +75,7 @@ public class Clans extends JavaPlugin
CommandCenter.Instance.setClientManager(_clientManager);
ItemStackFactory.Initialize(this, false);
Recharge.Initialize(this);
VisibilityManager.Initialize(this);
// new ProfileCacheManager(this);

View File

@ -52,7 +52,6 @@ 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.gear.GearShop;
import mineplex.game.clans.items.generation.Weight;
import mineplex.game.clans.items.generation.WeightSet;
import mineplex.game.clans.items.legendaries.AlligatorsTooth;
@ -62,6 +61,7 @@ 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;

View File

@ -29,7 +29,7 @@ private static ValueDistribution knockbackGen = generateDistribution(-0.5d, 1.0d
@Override
public String getDescription()
{
return String.format("Reverse knockback and modify amount to %.2f percent!", (1.0d + _knockbackModifier) * 100d);
return String.format("Reverse knockback and modify amount to %.2f percent", (1.0d + _knockbackModifier) * 100d);
}
@Override

View File

@ -30,7 +30,7 @@ public class LeechingAttribute extends ItemAttribute
@Override
public String getDescription()
{
return String.format("Heal yourself for %d percentage of damage dealt to enemy players", _healPercent);
return String.format("Heal for %d percentage of damage dealt", _healPercent);
}
@Override

View File

@ -26,7 +26,7 @@ public class RecursiveAttribute extends DamageAttribute
@Override
public String getDescription()
{
return String.format("Increase damage by %.2f half-hearts!", getBonusDamage());
return String.format("Increase damage by %.2f half-hearts", getBonusDamage());
}
@Override

View File

@ -27,7 +27,7 @@ public class SlayingAttribute extends DamageAttribute
@Override
public String getDescription()
{
return String.format("Increase damage by %.2f half-hearts against mobs & bosses!", getBonusDamage());
return String.format("Increase damage by %.2f half-hearts against mobs & bosses", getBonusDamage());
}
@Override

View File

@ -12,7 +12,7 @@ public class GearCommand extends CommandBase<GearManager>
public GearCommand(GearManager plugin)
{
super(plugin, Rank.ADMIN, "gear", "custom-gear");
super(plugin, Rank.ALL, "gear", "custom-gear");
_gearManager = plugin;
}

View File

@ -1,15 +1,13 @@
package mineplex.game.clans.items.legendaries;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector;
import mineplex.game.clans.items.generation.ValueDistribution;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
public class AlligatorsTooth extends LegendaryItem
{

View File

@ -1,19 +1,13 @@
package mineplex.game.clans.items.legendaries;
import java.util.HashSet;
import java.util.Set;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
public class GiantsBroadsword extends LegendaryItem
{
public static final int SLOW_AMPLIFIER = 4;
public static final int REGEN_AMPLIFIER = 1;
public static final int EFFECT_DURATION = 10; // Duration of potion effect (in ticks)

View File

@ -1,14 +1,13 @@
package mineplex.game.clans.items.legendaries;
import mineplex.game.clans.items.generation.ValueDistribution;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import mineplex.game.clans.items.generation.ValueDistribution;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
public class HyperBlade extends LegendaryItem
{
public static final long ATTACK_RATE_DURATION = 100;

View File

@ -1,20 +1,17 @@
package mineplex.game.clans.items.legendaries;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilMath;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.util.Vector;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
public class MagneticBlade extends LegendaryItem
{
public static final double PULL_RANGE = 10d;
public MagneticBlade()

View File

@ -1,15 +1,10 @@
package mineplex.game.clans.items.legendaries;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
public class MeteorBow extends LegendaryItem
{
public static final int MAX_FLIGHT_TIME = 80; // Max flight of 80 ticks
private long _flightTime; // Time (in ticks) since last touching ground and flying

View File

@ -1,17 +1,12 @@
package mineplex.game.clans.items.legendaries;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.util.Vector;
public class WindBlade extends LegendaryItem
{
public static final double FLIGHT_VELOCITY = 0.75d;
public static final int MAX_FLIGHT_TIME = 80; // Max flight of 80 ticks

View File

@ -1,7 +1,7 @@
package mineplex.game.clans.items.gear;
package mineplex.game.clans.items.ui;
import java.util.HashSet;
import java.util.Set;
import java.util.Arrays;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@ -11,13 +11,14 @@ import org.bukkit.inventory.ItemStack;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.Pair;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilMath;
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.CustomItem;
import mineplex.game.clans.items.GearManager;
import mineplex.game.clans.items.ItemType;
import mineplex.game.clans.items.RareItemFactory;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.attributes.armor.ConqueringArmorAttribute;
import mineplex.game.clans.items.attributes.armor.LavaAttribute;
@ -38,7 +39,6 @@ import mineplex.game.clans.items.attributes.weapon.HasteAttribute;
import mineplex.game.clans.items.attributes.weapon.HeavyAttribute;
import mineplex.game.clans.items.attributes.weapon.JaggedAttribute;
import mineplex.game.clans.items.attributes.weapon.SharpAttribute;
import mineplex.game.clans.items.attributes.weapon.VampiricAttribute;
import mineplex.game.clans.items.legendaries.AlligatorsTooth;
import mineplex.game.clans.items.legendaries.GiantsBroadsword;
import mineplex.game.clans.items.legendaries.HyperBlade;
@ -52,8 +52,7 @@ public class GearPage extends ShopPageBase<GearManager, GearShop>
{
private int _stage = 0;
private ItemType _itemType;
private CustomItem _item;
private RareItemFactory _factory;
private final IButton _nextButton;
private final IButton _backButton;
@ -62,22 +61,22 @@ public class GearPage extends ShopPageBase<GearManager, GearShop>
private Class<? extends ItemAttribute> _prefix;
private Class<? extends ItemAttribute> _suffix;
private Set<Class<? extends ItemAttribute>> _armourSuperPrefixes;
private Set<Class<? extends ItemAttribute>> _armourPrefixes;
private Set<Class<? extends ItemAttribute>> _armourSuffixes;
private List<Class<? extends ItemAttribute>> _armourSuperPrefixes;
private List<Class<? extends ItemAttribute>> _armourPrefixes;
private List<Class<? extends ItemAttribute>> _armourSuffixes;
private Set<Class<? extends ItemAttribute>> _weaponSuperPrefixes;
private Set<Class<? extends ItemAttribute>> _weaponPrefixes;
private Set<Class<? extends ItemAttribute>> _weaponSuffixes;
private List<Class<? extends ItemAttribute>> _weaponSuperPrefixes;
private List<Class<? extends ItemAttribute>> _weaponPrefixes;
private List<Class<? extends ItemAttribute>> _weaponSuffixes;
private Set<Class<? extends ItemAttribute>> _bowSuperPrefixes;
private Set<Class<? extends ItemAttribute>> _bowPrefixes;
private Set<Class<? extends ItemAttribute>> _bowSuffixes;
private List<Class<? extends ItemAttribute>> _bowSuperPrefixes;
private List<Class<? extends ItemAttribute>> _bowPrefixes;
private List<Class<? extends ItemAttribute>> _bowSuffixes;
private Set<Class<? extends LegendaryItem>> _legendaryItems;
private List<Class<? extends LegendaryItem>> _legendaryItems;
private Set<Material> _weaponTypes;
private Set<Material> _armourTypes;
private List<Material> _weaponTypes;
private List<Material> _armourTypes;
public GearPage(final GearManager gearManager, final GearShop shop, final CoreClientManager clientManager, final DonationManager donationManager, final String name, final Player player)
{
@ -99,149 +98,48 @@ public class GearPage extends ShopPageBase<GearManager, GearShop>
}
};
_armourSuperPrefixes = new HashSet<Class<? extends ItemAttribute>>()
{
private static final long serialVersionUID = 1L;
_legendaryItems = Arrays.<Class<? extends LegendaryItem>> asList(AlligatorsTooth.class, WindBlade.class, GiantsBroadsword.class, HyperBlade.class, MagneticBlade.class);
{
add(LavaAttribute.class);
}
};
_armourSuperPrefixes = Arrays.<Class<? extends ItemAttribute>> asList(LavaAttribute.class);
_armourPrefixes = Arrays.<Class<? extends ItemAttribute>> asList(PaddedAttribute.class, ReinforcedAttribute.class, SlantedAttribute.class);
_armourSuffixes = Arrays.<Class<? extends ItemAttribute>> asList(ConqueringArmorAttribute.class);
_armourPrefixes = new HashSet<Class<? extends ItemAttribute>>()
{
private static final long serialVersionUID = 1L;
_weaponSuperPrefixes = Arrays.<Class<? extends ItemAttribute>> asList(FlamingAttribute.class, FrostedAttribute.class);
_weaponPrefixes = Arrays.<Class<? extends ItemAttribute>> asList(HeavyAttribute.class, JaggedAttribute.class, SharpAttribute.class);
_weaponSuffixes = Arrays.<Class<? extends ItemAttribute>> asList(ConqueringAttribute.class, HasteAttribute.class);
{
add(PaddedAttribute.class);
add(ReinforcedAttribute.class);
add(SlantedAttribute.class);
}
};
_bowSuperPrefixes = Arrays.<Class<? extends ItemAttribute>> asList(LeechingAttribute.class, ScorchingAttribute.class);
_bowPrefixes = Arrays.<Class<? extends ItemAttribute>> asList(HeavyArrowsAttribute.class, HuntingAttribute.class, InverseAttribute.class, RecursiveAttribute.class);
_bowSuffixes = Arrays.<Class<? extends ItemAttribute>> asList(SlayingAttribute.class);
_armourSuffixes = new HashSet<Class<? extends ItemAttribute>>()
{
private static final long serialVersionUID = 1L;
{
add(ConqueringArmorAttribute.class);
}
};
_weaponSuperPrefixes = new HashSet<Class<? extends ItemAttribute>>()
{
private static final long serialVersionUID = 1L;
{
add(FlamingAttribute.class);
add(FrostedAttribute.class);
}
};
_weaponPrefixes = new HashSet<Class<? extends ItemAttribute>>()
{
private static final long serialVersionUID = 1L;
{
add(HeavyAttribute.class);
add(JaggedAttribute.class);
add(SharpAttribute.class);
}
};
_legendaryItems = new HashSet<Class<? extends LegendaryItem>>()
{
private static final long serialVersionUID = 1L;
{
add(AlligatorsTooth.class);
add(WindBlade.class);
add(GiantsBroadsword.class);
add(HyperBlade.class);
add(MagneticBlade.class);
}
};
_weaponSuffixes = new HashSet<Class<? extends ItemAttribute>>()
{
private static final long serialVersionUID = 1L;
{
add(ConqueringAttribute.class);
add(HasteAttribute.class);
}
};
_bowSuperPrefixes = new HashSet<Class<? extends ItemAttribute>>()
{
private static final long serialVersionUID = 1L;
{
add(LeechingAttribute.class);
add(ScorchingAttribute.class);
}
};
_bowPrefixes = new HashSet<Class<? extends ItemAttribute>>()
{
private static final long serialVersionUID = 1L;
{
add(HeavyArrowsAttribute.class);
add(HuntingAttribute.class);
add(InverseAttribute.class);
add(RecursiveAttribute.class);
}
};
_bowSuffixes = new HashSet<Class<? extends ItemAttribute>>()
{
private static final long serialVersionUID = 1L;
{
add(SlayingAttribute.class);
}
};
_armourTypes = new HashSet<Material>()
{
private static final long serialVersionUID = 1L;
{
add(Material.DIAMOND_HELMET);
add(Material.DIAMOND_CHESTPLATE);
add(Material.DIAMOND_LEGGINGS);
add(Material.DIAMOND_BOOTS);
add(Material.IRON_HELMET);
add(Material.IRON_CHESTPLATE);
add(Material.IRON_LEGGINGS);
add(Material.IRON_BOOTS);
add(Material.GOLD_HELMET);
add(Material.GOLD_CHESTPLATE);
add(Material.GOLD_LEGGINGS);
add(Material.GOLD_BOOTS);
}
};
_weaponTypes = new HashSet<Material>()
{
private static final long serialVersionUID = 1L;
{
add(Material.DIAMOND_SWORD);
add(Material.IRON_SWORD);
add(Material.GOLD_SWORD);
add(Material.STONE_SWORD);
add(Material.DIAMOND_AXE);
add(Material.IRON_AXE);
add(Material.GOLD_AXE);
add(Material.STONE_AXE);
}
};
_armourTypes = Arrays.asList(Material.DIAMOND_HELMET, Material.DIAMOND_CHESTPLATE, Material.DIAMOND_LEGGINGS, Material.DIAMOND_BOOTS, Material.IRON_HELMET, Material.IRON_CHESTPLATE, Material.IRON_LEGGINGS, Material.IRON_BOOTS, Material.GOLD_HELMET, Material.GOLD_CHESTPLATE, Material.GOLD_LEGGINGS, Material.GOLD_BOOTS);
_weaponTypes = Arrays.asList(Material.DIAMOND_SWORD, Material.DIAMOND_AXE, Material.IRON_SWORD, Material.IRON_AXE, Material.GOLD_SWORD, Material.GOLD_AXE, Material.STONE_SWORD, Material.STONE_AXE);
buildPage();
}
private static int[] getIndicesFor(int size, int itemsPerLine)
{
itemsPerLine = UtilMath.clamp(itemsPerLine, 1, 5);
int[] indices = new int[size];
int lines = (int) Math.ceil(size / ((double) itemsPerLine));
for (int ln = 0; ln < lines; ln++)
{
int items = ln == lines - 1 ? size - (ln * itemsPerLine) : itemsPerLine;
int start = 9 * ln - items + 14;
for (int item = 0; item < items; item++)
{
indices[(ln * itemsPerLine) + item] = start + (item * 2);
}
}
return indices;
}
protected void buildPage()
{
clearPage();
@ -327,7 +225,6 @@ public class GearPage extends ShopPageBase<GearManager, GearShop>
{
public void onClick(Player player, ClickType clickType)
{
}
});
@ -344,37 +241,37 @@ public class GearPage extends ShopPageBase<GearManager, GearShop>
{
public void onClick(Player player, ClickType clickType)
{
_itemType = ItemType.LEGENDARY;
_factory = RareItemFactory.begin(ItemType.LEGENDARY);
buildPage();
}
}, new String[] { ItemType.LEGENDARY.equals(_itemType) ? C.cGreen + "Selected" : C.cRed + "Not Selected" });
}, new String[] { _factory != null && ItemType.LEGENDARY.equals(_factory.getItemType()) ? 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)
{
_itemType = ItemType.WEAPON;
_factory = RareItemFactory.begin(ItemType.WEAPON);
buildPage();
}
}, new String[] { ItemType.WEAPON.equals(_itemType) ? C.cGreen + "Selected" : C.cRed + "Not Selected" });
}, new String[] { _factory != null && ItemType.WEAPON.equals(_factory.getItemType()) ? 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)
{
_itemType = ItemType.ARMOUR;
_factory = RareItemFactory.begin(ItemType.ARMOUR);
buildPage();
}
}, new String[] { ItemType.ARMOUR.equals(_itemType) ? C.cGreen + "Selected" : C.cRed + "Not Selected" });
}, new String[] { _factory != null && ItemType.ARMOUR.equals(_factory.getItemType()) ? 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)
{
_itemType = ItemType.BOW;
_factory = RareItemFactory.begin(ItemType.BOW);
buildPage();
}
}, new String[] { ItemType.BOW.equals(_itemType) ? C.cGreen + "Selected" : C.cRed + "Not Selected" });
}, new String[] { _factory != null && ItemType.BOW.equals(_factory.getItemType()) ? C.cGreen + "Selected" : C.cRed + "Not Selected" });
return Pair.create(stageTitle, null);
}
@ -385,21 +282,21 @@ public class GearPage extends ShopPageBase<GearManager, GearShop>
Material stageMaterial = null;
boolean _return = false;
if (_itemType == null)
if (_factory.getItemType() == null)
{
performBack();
return Triple.of(true, stageTitle, stageMaterial);
}
if (_itemType.equals(ItemType.LEGENDARY))
if (_factory.getItemType().equals(ItemType.LEGENDARY))
{
stageTitle = "2. Select Legendary Item";
stageMaterial = _item == null ? stageMaterial : _item.toItemStack().getType();
stageMaterial = _factory.getMaterial() == null ? stageMaterial : _factory.getMaterial();
int[] indices = getIndicesFor(_legendaryItems.size());
int[] indices = getIndicesFor(_legendaryItems.size(), 5);
int index = 0;
for (Class<? extends LegendaryItem> legendary : _legendaryItems)
for (final Class<? extends LegendaryItem> legendary : _legendaryItems)
{
final LegendaryItem item = legendary.newInstance();
@ -407,23 +304,23 @@ public class GearPage extends ShopPageBase<GearManager, GearShop>
{
public void onClick(Player player, ClickType clickType)
{
_item = item;
_factory.setLegendary(legendary);
buildPage();
}
}, new String[] { C.cWhite + item.getDescription(), "", item.getDisplayName().equals(_item == null ? null : _item.getDisplayName()) ? C.cGreen + "Selected" : C.cRed + "Not Selected" });
}, new String[] { C.cWhite + item.getDescription(), "", item.getDisplayName().equals(_factory.getWrapper() == null ? null : _factory.getWrapper().getDisplayName()) ? C.cGreen + "Selected" : C.cRed + "Not Selected" });
index++;
}
}
else
{
switch (_itemType)
switch (_factory.getItemType())
{
case WEAPON:
{
stageTitle = "Select Weapon Type";
int[] indices = getIndicesFor(_weaponTypes.size());
int[] indices = getIndicesFor(_weaponTypes.size(), 2);
int index = 0;
for (final Material type : _weaponTypes)
@ -432,10 +329,10 @@ public class GearPage extends ShopPageBase<GearManager, GearShop>
{
public void onClick(Player player, ClickType clickType)
{
_item = new CustomItem(type);
_factory.setType(type);
buildPage();
}
}, new String[] { _item == null ? C.cRed + "Not Selected" : (_item.toItemStack().getType().equals(type) ? C.cGreen + "Selected" : C.cRed + "Not Selected") });
}, new String[] { type.equals(_factory.getMaterial()) ? C.cGreen + "Selected" : C.cRed + "Not Selected" });
index++;
}
break;
@ -444,7 +341,7 @@ public class GearPage extends ShopPageBase<GearManager, GearShop>
{
stageTitle = "Select Armour Type";
int[] indices = getIndicesFor(_armourTypes.size());
int[] indices = getIndicesFor(_armourTypes.size(), 4);
int index = 0;
for (final Material type : _armourTypes)
@ -453,10 +350,10 @@ public class GearPage extends ShopPageBase<GearManager, GearShop>
{
public void onClick(Player player, ClickType clickType)
{
_item = new CustomItem(type);
_factory.setType(type);
buildPage();
}
}, new String[] { _item == null ? C.cRed + "Not Selected" : (_item.toItemStack().getType().equals(type) ? C.cGreen + "Selected" : C.cRed + "Not Selected") });
}, new String[] { type.equals(_factory.getMaterial()) ? C.cGreen + "Selected" : C.cRed + "Not Selected" });
index++;
}
break;
@ -470,7 +367,7 @@ public class GearPage extends ShopPageBase<GearManager, GearShop>
* seperately, and ARMOUR, and WEAPON have their own cases.
*/
_item = new CustomItem(Material.BOW);
_factory.setType(Material.BOW);
_stage = 2;
buildPage();
_return = true;
@ -484,27 +381,27 @@ public class GearPage extends ShopPageBase<GearManager, GearShop>
{
String stageTitle;
if (_item == null)
if (_factory.getMaterial() == null)
{
return Triple.of(true, null, null);
}
Material stageMaterial = _item.toItemStack().getType();
Material stageMaterial = _factory.getMaterial();
if (_item != null && _itemType.equals(ItemType.LEGENDARY))
if (_factory.getItemType().equals(ItemType.LEGENDARY))
{
finish();
stageTitle = "The End";
}
else
{
switch (_itemType)
switch (_factory.getItemType())
{
case WEAPON:
{
stageTitle = "Select Super Prefix";
int[] indices = getIndicesFor(_weaponSuperPrefixes.size());
int[] indices = getIndicesFor(_weaponSuperPrefixes.size(), 5);
int index = 0;
for (final Class<? extends ItemAttribute> attribute : _weaponSuperPrefixes)
@ -528,7 +425,7 @@ public class GearPage extends ShopPageBase<GearManager, GearShop>
case ARMOUR:
{
stageTitle = "Select Super Prefix";
int[] indices = getIndicesFor(_armourSuperPrefixes.size());
int[] indices = getIndicesFor(_armourSuperPrefixes.size(), 5);
int index = 0;
for (final Class<? extends ItemAttribute> attribute : _armourSuperPrefixes)
@ -553,7 +450,7 @@ public class GearPage extends ShopPageBase<GearManager, GearShop>
{
stageTitle = "Select Super Prefix";
int[] indices = getIndicesFor(_bowSuperPrefixes.size());
int[] indices = getIndicesFor(_bowSuperPrefixes.size(), 5);
int index = 0;
for (final Class<? extends ItemAttribute> attribute : _bowSuperPrefixes)
@ -588,22 +485,22 @@ public class GearPage extends ShopPageBase<GearManager, GearShop>
private Pair<String, Material> doStageFour() throws InstantiationException, IllegalAccessException
{
String stageTitle;
Material stageMaterial = _item.toItemStack().getType();
Material stageMaterial = _factory.getMaterial();
if (_item != null && _itemType.equals(ItemType.LEGENDARY))
if (_factory.getItemType().equals(ItemType.LEGENDARY))
{
finish();
stageTitle = "The End";
}
else
{
switch (_itemType)
switch (_factory.getItemType())
{
case WEAPON:
{
stageTitle = "Select Prefix";
int[] indices = getIndicesFor(_weaponPrefixes.size());
int[] indices = getIndicesFor(_weaponPrefixes.size(), 5);
int index = 0;
for (final Class<? extends ItemAttribute> attribute : _weaponPrefixes)
@ -628,7 +525,7 @@ public class GearPage extends ShopPageBase<GearManager, GearShop>
{
stageTitle = "Select Prefix";
int[] indices = getIndicesFor(_armourPrefixes.size());
int[] indices = getIndicesFor(_armourPrefixes.size(), 5);
int index = 0;
for (final Class<? extends ItemAttribute> attribute : _armourPrefixes)
@ -653,7 +550,7 @@ public class GearPage extends ShopPageBase<GearManager, GearShop>
{
stageTitle = "Select Prefix";
int[] indices = getIndicesFor(_bowPrefixes.size());
int[] indices = getIndicesFor(_bowPrefixes.size(), 5);
int index = 0;
for (final Class<? extends ItemAttribute> attribute : _bowPrefixes)
@ -688,22 +585,22 @@ public class GearPage extends ShopPageBase<GearManager, GearShop>
private Pair<String, Material> doStageFive() throws InstantiationException, IllegalAccessException
{
String stageTitle;
Material stageMaterial = _item.toItemStack().getType();
Material stageMaterial = _factory.getMaterial();
if (_item != null && _itemType.equals(ItemType.LEGENDARY))
if (_factory.getItemType().equals(ItemType.LEGENDARY))
{
finish();
stageTitle = "The End";
}
else
{
switch (_itemType)
switch (_factory.getItemType())
{
case WEAPON:
{
stageTitle = "Select Suffix";
int[] indices = getIndicesFor(_weaponSuffixes.size());
int[] indices = getIndicesFor(_weaponSuffixes.size(), 5);
int index = 0;
for (final Class<? extends ItemAttribute> attribute : _weaponSuffixes)
@ -728,7 +625,7 @@ public class GearPage extends ShopPageBase<GearManager, GearShop>
{
stageTitle = "Select Suffix";
int[] indices = getIndicesFor(_armourSuffixes.size());
int[] indices = getIndicesFor(_armourSuffixes.size(), 5);
int index = 0;
for (final Class<? extends ItemAttribute> attribute : _armourSuffixes)
@ -752,7 +649,7 @@ public class GearPage extends ShopPageBase<GearManager, GearShop>
{
stageTitle = "Select Suffix";
int[] indices = getIndicesFor(_bowSuffixes.size());
int[] indices = getIndicesFor(_bowSuffixes.size(), 5);
int index = 0;
for (final Class<? extends ItemAttribute> attribute : _bowSuffixes)
@ -784,26 +681,6 @@ public class GearPage extends ShopPageBase<GearManager, GearShop>
return Pair.create(stageTitle, stageMaterial);
}
private static int[] getIndicesFor(int size)
{
int[] indices = new int[size];
int lines = (int) Math.ceil(size / 5D);
for (int line = 0; line < lines; line++)
{
int itemsInLine = line == lines - 1 ? size - (line * 5) : 5;
int startingPoint = 9 + (line * 9) + (4 - (itemsInLine - 1));
for (int i = 0; i < itemsInLine; i++)
{
indices[line * 5 + i] = startingPoint + (i * 2);
}
}
return indices;
}
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);
@ -827,33 +704,17 @@ public class GearPage extends ShopPageBase<GearManager, GearShop>
{
clearPage();
try
{
if (_superPrefix != null)
{
_item.getAttributes().addAttribute(_superPrefix.newInstance());
}
_factory.setSuperPrefix(_superPrefix);
_factory.setPrefix(_prefix);
_factory.setSuffix(_suffix);
if (_prefix != null)
{
_item.getAttributes().addAttribute(_prefix.newInstance());
}
final ItemStack item = _factory.fabricate();
if (_suffix != null)
{
_item.getAttributes().addAttribute(_suffix.newInstance());
}
}
catch (InstantiationException | IllegalAccessException e)
{
e.printStackTrace();
}
addButton(9 + 4, _item.toItemStack(), new IButton()
addButton(9 + 4, item, new IButton()
{
public void onClick(Player player, ClickType clickType)
{
player.getInventory().addItem(_item.toItemStack());
player.getInventory().addItem(item);
}
}, new String[] { C.cWhite + "Click to get item" });
}

View File

@ -1,4 +1,4 @@
package mineplex.game.clans.items.gear;
package mineplex.game.clans.items.ui;
import org.bukkit.entity.Player;