Add remaining bow and armor based attributes, include base implementation of Legendary weapons. Fix smelting bug.

This commit is contained in:
Ty Sayers 2015-05-16 12:58:58 -04:00
parent 6b3028605e
commit a8a8d4961a
36 changed files with 822 additions and 14 deletions

View File

@ -101,6 +101,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
_clientManager = clientManager; _clientManager = clientManager;
_combatManager = new CombatManager(plugin); _combatManager = new CombatManager(plugin);
_blockRestore = blockRestore; _blockRestore = blockRestore;
_teleport = teleport; _teleport = teleport;
@ -113,7 +114,8 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
Energy energy = new Energy(plugin); Energy energy = new Energy(plugin);
PacketHandler packetHandler = new PacketHandler(plugin); PacketHandler packetHandler = new PacketHandler(plugin);
new CustomTagFix(plugin, packetHandler); // TODO: Re-enable customtagfix with NCP update?
//new CustomTagFix(plugin, packetHandler);
DisguiseManager disguiseManager = new DisguiseManager(plugin, packetHandler); DisguiseManager disguiseManager = new DisguiseManager(plugin, packetHandler);
_condition = new SkillConditionManager(plugin); _condition = new SkillConditionManager(plugin);
Creature creature = new Creature(plugin); Creature creature = new Creature(plugin);

View File

@ -12,6 +12,7 @@ import mineplex.game.clans.items.commands.GearCommand;
import mineplex.game.clans.items.generation.Weight; import mineplex.game.clans.items.generation.Weight;
import mineplex.game.clans.items.generation.WeightSet; import mineplex.game.clans.items.generation.WeightSet;
import mineplex.serverdata.Region; import mineplex.serverdata.Region;
import mineplex.serverdata.Utility;
import mineplex.serverdata.commands.ServerCommandManager; import mineplex.serverdata.commands.ServerCommandManager;
import mineplex.serverdata.commands.TransferCommand; import mineplex.serverdata.commands.TransferCommand;
import mineplex.serverdata.servers.ServerManager; import mineplex.serverdata.servers.ServerManager;
@ -29,6 +30,7 @@ import org.bukkit.plugin.java.JavaPlugin;
*/ */
public class GearManager extends MiniPlugin public class GearManager extends MiniPlugin
{ {
private static GearManager _instance; // Singleton instance private static GearManager _instance; // Singleton instance
private Map<String, PlayerGear> playerGears; // Mapping of player names (key) to cached gear set (value). private Map<String, PlayerGear> playerGears; // Mapping of player names (key) to cached gear set (value).
@ -46,6 +48,9 @@ public class GearManager extends MiniPlugin
_attributeWeights = new WeightSet<Integer>(new Weight<Integer>(3, 3), new Weight<Integer>(20, 2), new Weight<Integer>(77, 1)); _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>(90, true), new Weight<Boolean>(10, false));
_itemWeights = new WeightSet<Boolean>(new Weight<Boolean>(50, true), new Weight<Boolean>(50, 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 @Override

View File

@ -1,5 +1,7 @@
package mineplex.game.clans.items.attributes; package mineplex.game.clans.items.attributes;
import mineplex.game.clans.items.generation.ValueDistribution;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;

View File

@ -0,0 +1,24 @@
package mineplex.game.clans.items.attributes.armor;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
public class EscapeAttribute extends ItemAttribute
{
// TODO: Replace with your generators
private static ValueDistribution healGen = generateDistribution(4, 12); // Value generator for heal amount
private int _healPercent;
public EscapeAttribute()
{
_healPercent = healGen.generateIntValue();
}
@Override
public String getDisplayName()
{
return ""; // TODO: Fill in name
}
}

View File

@ -0,0 +1,23 @@
package mineplex.game.clans.items.attributes.armor;
import mineplex.game.clans.items.generation.ValueDistribution;
public abstract class FlatReductionAttribute extends ReductionAttribute
{
private double _reduction;
public FlatReductionAttribute(ValueDistribution reductionGen, ReductionConfig config)
{
super(config);
_reduction = reductionGen.generateValue();
}
@Override
public double getDamageReduction(double originalDamage)
{
return _reduction;
}
}

View File

@ -0,0 +1,26 @@
package mineplex.game.clans.items.attributes.armor;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
public class LavaAttribute extends PercentReductionAttribute
{
// TODO: Replace with your generators
private static ValueDistribution reductionGen = generateDistribution(0.2d, 1.0d); // Value generator for heal amount
private static ReductionConfig lavaConfig = new ReductionConfig(DamageCause.FIRE, DamageCause.LAVA, DamageCause.FIRE_TICK);
public LavaAttribute()
{
super(reductionGen, lavaConfig);
}
@Override
public String getDisplayName()
{
return "Lava Forged";
}
}

View File

@ -0,0 +1,25 @@
package mineplex.game.clans.items.attributes.armor;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
public class PaddedAttribute extends FlatReductionAttribute
{
// TODO: Replace with your generators
private static ValueDistribution reductionGen = generateDistribution(1.0d, 4.0d);
private static ReductionConfig config = new ReductionConfig(DamageCause.FALL);
public PaddedAttribute()
{
super(reductionGen, config);
}
@Override
public String getDisplayName()
{
return "Padded";
}
}

View File

@ -0,0 +1,22 @@
package mineplex.game.clans.items.attributes.armor;
import mineplex.game.clans.items.generation.ValueDistribution;
public abstract class PercentReductionAttribute extends ReductionAttribute
{
private double _reductionPercent;
public PercentReductionAttribute(ValueDistribution reductionGen, ReductionConfig config)
{
super(config);
_reductionPercent = reductionGen.generateValue();
}
@Override
public double getDamageReduction(double originalDamage)
{
return originalDamage * _reductionPercent;
}
}

View File

@ -0,0 +1,27 @@
package mineplex.game.clans.items.attributes.armor;
import org.bukkit.entity.EntityType;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
// A.K.A Conquering for Armor
public class ProtectionAttribute extends FlatReductionAttribute
{
// TODO: Replace with your generators
private static ValueDistribution reductionGen = generateDistribution(1.0d, 4.0d);
private static ReductionConfig config = new ReductionConfig(EntityType.values());
public ProtectionAttribute()
{
super(reductionGen, config);
}
@Override
public String getDisplayName()
{
return "Protection";
}
}

View File

@ -0,0 +1,41 @@
package mineplex.game.clans.items.attributes.armor;
import java.util.HashSet;
import java.util.Set;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
public abstract class ReductionAttribute extends ItemAttribute
{
private ReductionConfig _config;
public ReductionAttribute(ReductionConfig config)
{
_config = config;
}
@Override
public void onAttacked(EntityDamageByEntityEvent event)
{
DamageCause cause = event.getCause();
Entity attacker = event.getDamager();
if (_config.reducesDamage(cause, attacker))
{
double damage = event.getDamage();
double reduction = getDamageReduction(damage);
double reducedDamage = Math.max(0, damage - reduction);
event.setDamage(reducedDamage);
}
}
public abstract double getDamageReduction(double originalDamage);
}

View File

@ -0,0 +1,46 @@
package mineplex.game.clans.items.attributes.armor;
import java.util.HashSet;
import java.util.Set;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
public class ReductionConfig
{
private Set<EntityType> _reducedAttackers; // EntityTypes whose attacks are reduced by this attribute
private Set<DamageCause> _reducedCauses; // DamageCauses that are reduced by this attribute
public ReductionConfig()
{
_reducedAttackers = new HashSet<EntityType>();
_reducedCauses = new HashSet<DamageCause>();
}
public ReductionConfig(DamageCause... reducedCauses)
{
this();
for (DamageCause cause : reducedCauses)
{
_reducedCauses.add(cause);
}
}
public ReductionConfig(EntityType... reducedAttackers)
{
this();
for (EntityType attacker : reducedAttackers)
{
_reducedAttackers.add(attacker);
}
}
public boolean reducesDamage(DamageCause cause, Entity attacker)
{
return _reducedCauses.contains(cause) || _reducedAttackers.contains(attacker.getType());
}
}

View File

@ -0,0 +1,24 @@
package mineplex.game.clans.items.attributes.armor;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import mineplex.game.clans.items.generation.ValueDistribution;
public class ReinforcedAttribute extends FlatReductionAttribute
{
// TODO: Replace with your generators
private static ValueDistribution reductionGen = generateDistribution(0.5d, 1.0d);
private static ReductionConfig config = new ReductionConfig(DamageCause.ENTITY_ATTACK);
public ReinforcedAttribute()
{
super(reductionGen, config);
}
@Override
public String getDisplayName()
{
return "Reinforced";
}
}

View File

@ -0,0 +1,24 @@
package mineplex.game.clans.items.attributes.armor;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
public class SeaAttribute extends ItemAttribute
{
// TODO: Replace with your generators
private static ValueDistribution healGen = generateDistribution(4, 12); // Value generator for heal amount
private int _healPercent;
public SeaAttribute()
{
_healPercent = healGen.generateIntValue();
}
@Override
public String getDisplayName()
{
return ""; // TODO: Fill in name
}
}

View File

@ -0,0 +1,25 @@
package mineplex.game.clans.items.attributes.armor;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
public class SlantedAttribute extends FlatReductionAttribute
{
// TODO: Replace with your generators
private static ValueDistribution reductionGen = generateDistribution(0.5d, 1.5d);
private static ReductionConfig config = new ReductionConfig(DamageCause.PROJECTILE);
public SlantedAttribute()
{
super(reductionGen, config);
}
@Override
public String getDisplayName()
{
return "Slanted";
}
}

View File

@ -1,4 +1,6 @@
package mineplex.game.clans.items.attributes; package mineplex.game.clans.items.attributes.weapon;
import mineplex.game.clans.items.attributes.ItemAttribute;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;

View File

@ -1,4 +1,6 @@
package mineplex.game.clans.items.attributes; package mineplex.game.clans.items.attributes.weapon;
import mineplex.game.clans.items.generation.ValueDistribution;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

View File

@ -1,4 +1,7 @@
package mineplex.game.clans.items.attributes; package mineplex.game.clans.items.attributes.weapon;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;

View File

@ -1,4 +1,6 @@
package mineplex.game.clans.items.attributes; package mineplex.game.clans.items.attributes.weapon;
import mineplex.game.clans.items.generation.ValueDistribution;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;

View File

@ -1,4 +1,7 @@
package mineplex.game.clans.items.attributes; package mineplex.game.clans.items.attributes.weapon;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;

View File

@ -1,4 +1,6 @@
package mineplex.game.clans.items.attributes; package mineplex.game.clans.items.attributes.weapon;
import mineplex.game.clans.items.generation.ValueDistribution;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

View File

@ -1,4 +1,7 @@
package mineplex.game.clans.items.attributes; package mineplex.game.clans.items.attributes.weapon;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
public class HeavyAttribute extends ItemAttribute public class HeavyAttribute extends ItemAttribute
{ {

View File

@ -1,4 +1,6 @@
package mineplex.game.clans.items.attributes; package mineplex.game.clans.items.attributes.weapon;
import mineplex.game.clans.items.generation.ValueDistribution;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;

View File

@ -1,4 +1,6 @@
package mineplex.game.clans.items.attributes; package mineplex.game.clans.items.attributes.weapon;
import mineplex.game.clans.items.generation.ValueDistribution;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;

View File

@ -1,4 +1,7 @@
package mineplex.game.clans.items.attributes; package mineplex.game.clans.items.attributes.weapon;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
public class SmashingAttribute extends ItemAttribute public class SmashingAttribute extends ItemAttribute
{ {

View File

@ -1,4 +1,7 @@
package mineplex.game.clans.items.attributes; package mineplex.game.clans.items.attributes.weapon;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
public class SwiftAttribute extends ItemAttribute public class SwiftAttribute extends ItemAttribute
{ {

View File

@ -1,4 +1,7 @@
package mineplex.game.clans.items.attributes; package mineplex.game.clans.items.attributes.weapon;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;

View File

@ -1,4 +1,4 @@
package mineplex.game.clans.items.attributes; package mineplex.game.clans.items.generation;
import java.util.Random; import java.util.Random;

View File

@ -0,0 +1,51 @@
package mineplex.game.clans.items.legendaries;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
public class AlligatorsTooth extends LegendaryItem
{
private static ValueDistribution damageGen = generateDistribution(1.0d, 5.0d);
private double _damageBonus;
public AlligatorsTooth()
{
_damageBonus = damageGen.generateValue();
}
@Override
public void update(Player wielder)
{
if (isHoldingRightClick() && isInWater(wielder))
{
propelPlayer(wielder);
}
}
@Override
public void onAttack(EntityDamageByEntityEvent event, Player wielder)
{
if (isInWater(wielder))
{
double newDamage = event.getDamage() + _damageBonus;
event.setDamage(newDamage);
}
super.onAttack(event);
}
private void propelPlayer(Player player)
{
// TODO: Propel player forward with 0.6 to 1.2 velocity
}
private boolean isInWater(Player player)
{
return true; // TODO: Determine whether player is submerged in water
}
}

View File

@ -0,0 +1,44 @@
package mineplex.game.clans.items.legendaries;
import java.util.HashSet;
import java.util.Set;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
public class GiantsBroadsword extends LegendaryItem
{
@Override
public void update(Player wielder)
{
if (isHoldingRightClick())
{
buffPlayer(wielder);
}
}
@Override
public void onAttack(EntityDamageByEntityEvent event, Player wielder)
{
// TODO: Buff knockback and damage values (What are specific values?)
}
private void buffPlayer(Player player)
{
player.addPotionEffects(generateBlockBuff());
}
private Set<PotionEffect> generateBlockBuff()
{
Set<PotionEffect> potions = new HashSet<PotionEffect>();
// Slow 5 and Regen 1 for 5 ticks
potions.add(new PotionEffect(PotionEffectType.SLOW, 4, 5));
potions.add(new PotionEffect(PotionEffectType.REGENERATION, 0, 5));
return potions;
}
}

View File

@ -0,0 +1,49 @@
package mineplex.game.clans.items.legendaries;
import mineplex.game.clans.items.generation.ValueDistribution;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
public class HyperBlade extends LegendaryItem
{
private static ValueDistribution amountGen = generateDistribution(0, 3); // [1, 4] speed amount
private static ValueDistribution durationGen = generateDistribution(80, 320); // [4, 16] seconds speed duration
private int _speedAmount;
private int _speedDuration;
public HyperBlade()
{
_speedAmount = amountGen.generateIntValue();
_speedDuration = durationGen.generateIntValue();
}
@Override
public void update(Player wielder)
{
if (isHoldingRightClick() && canBuff())
{
buffPlayer(wielder);
}
}
@Override
public void onAttack(EntityDamageByEntityEvent event, Player wielder)
{
// TODO: Reduce after-attack cooldown against players to 100ms (instead of 400ms)
}
private void buffPlayer(Player wielder)
{
// Give player speed buff
wielder.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, _speedAmount, _speedDuration));
}
private boolean canBuff()
{
return true; // TODO: Implement cooldown? (None specified in docs, sounds OP)
}
}

View File

@ -0,0 +1,74 @@
package mineplex.game.clans.items.legendaries;
import org.bukkit.entity.Player;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import mineplex.game.clans.items.CustomItem;
import mineplex.game.clans.items.generation.ValueDistribution;
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
public long timeSinceLastBlock() { return System.currentTimeMillis() - _lastBlock; }
public LegendaryItem()
{
_lastBlock = 0l;
}
public void update(Player wielder)
{
// Leave implementation to potential subtypes
}
public void onAttack(EntityDamageByEntityEvent event, Player wielder)
{
// Leave implementation to potential subtypes
}
@Override
public void onAttack(EntityDamageByEntityEvent event)
{
if (event.getDamager() instanceof Player)
{
Player wielder = (Player) event.getDamager();
onAttack(event, wielder);
}
super.onAttack(event);
}
public void onInteract(PlayerInteractEvent event)
{
Action action = event.getAction();
if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK)
{
_lastBlock = System.currentTimeMillis();
}
super.onInteract(event);
}
public boolean isHoldingRightClick()
{
return timeSinceLastBlock() <= BLOCK_COOLDOWN;
}
/**
* @param minValue - the minimum value for attribute value range
* @param maxValue - the maximum value for attribute value range
* @return newly instantiated {@link ValueDistribution} for attribute values in range [{@code minValue}. {@code maxValue}].
*/
public static ValueDistribution generateDistribution(double minValue, double maxValue)
{
return new ValueDistribution(minValue, maxValue);
}
}

View File

@ -0,0 +1,38 @@
package mineplex.game.clans.items.legendaries;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
public class MagneticBlade extends LegendaryItem
{
public MagneticBlade()
{
}
@Override
public void update(Player wielder)
{
if (isHoldingRightClick() && canPull())
{
pullPlayers(wielder);
}
}
@Override
public void onAttack(EntityDamageByEntityEvent event, Player wielder)
{
// TODO: Apply negative knockback with [???] velocity/power to victims of attacks
}
private void pullPlayers(Player player)
{
// TODO: Grab all players in line of sight and pull towards player with ??? velocity
}
private boolean canPull()
{
return true; // TODO: Implement cooldown? (Sounds OP without one)
}
}

View File

@ -0,0 +1,40 @@
package mineplex.game.clans.items.legendaries;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
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
public MeteorBow()
{
_flightTime = 0;
}
@Override
public void update(Player wielder)
{
if (isHoldingRightClick() && canPropel())
{
propelPlayer(wielder);
}
}
private void propelPlayer(Player player)
{
_flightTime++;
// TODO: Propel player forward with ??? velocity
}
private boolean canPropel()
{
return _flightTime <= MAX_FLIGHT_TIME;
}
}

View File

@ -0,0 +1,40 @@
package mineplex.game.clans.items.legendaries;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
public class WindBlade 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
public WindBlade()
{
_flightTime = 0;
}
@Override
public void update(Player wielder)
{
if (isHoldingRightClick() && canPropel())
{
propelPlayer(wielder);
}
}
private void propelPlayer(Player player)
{
_flightTime++;
// TODO: Propel player forward with ??? velocity
}
private boolean canPropel()
{
return _flightTime <= MAX_FLIGHT_TIME;
}
}

View File

@ -0,0 +1,92 @@
package mineplex.game.clans.items.smelting;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class Smelter
{
public static void smeltItemInHand(Player player)
{
// Smelt item in hand for player
ItemStack item = player.getInventory().getItemInHand();
if (item != null)
{
ItemStack returns = smeltItem(item);
player.getInventory().setItemInHand(returns);
}
}
public static ItemStack smeltItem(ItemStack item)
{
Material material = getSmeltedType(item.getType());
int maxAmount = getSmeltAmount(item.getType());
int amount = maxAmount; // TODO: Determine proportional return on smelt depending on type/durability
return new ItemStack(material, amount);
}
private static int getSmeltAmount(Material itemType)
{
switch (itemType)
{
case IRON_BOOTS:
case DIAMOND_BOOTS:
case GOLD_BOOTS:
return 4;
case IRON_HELMET:
case DIAMOND_HELMET:
case GOLD_HELMET:
return 5;
case IRON_LEGGINGS:
case DIAMOND_LEGGINGS:
case GOLD_LEGGINGS:
return 7;
case IRON_CHESTPLATE:
case DIAMOND_CHESTPLATE:
case GOLD_CHESTPLATE:
return 8;
case IRON_SWORD:
case DIAMOND_SWORD:
case GOLD_SWORD:
return 2;
case IRON_AXE:
case DIAMOND_AXE:
case GOLD_AXE:
return 3;
default:
return 0;
}
}
private static Material getSmeltedType(Material itemType)
{
switch (itemType)
{
case IRON_BOOTS:
case IRON_LEGGINGS:
case IRON_CHESTPLATE:
case IRON_HELMET:
case IRON_SWORD:
case IRON_AXE:
return Material.IRON_ORE;
case DIAMOND_BOOTS:
case DIAMOND_LEGGINGS:
case DIAMOND_CHESTPLATE:
case DIAMOND_HELMET:
case DIAMOND_SWORD:
case DIAMOND_AXE:
return Material.DIAMOND_ORE;
case GOLD_BOOTS:
case GOLD_LEGGINGS:
case GOLD_CHESTPLATE:
case GOLD_HELMET:
case GOLD_SWORD:
case GOLD_AXE:
return Material.GOLD_ORE;
default:
return null;
}
}
}

View File

@ -0,0 +1,34 @@
package mineplex.game.clans.items.smelting;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
/**
* Listens for smelting related events triggered by players to carry out
* item smelting for base resources and ores.
* @author MrTwiggy
*
*/
public class SmeltingListener implements Listener
{
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event)
{
if (event.getAction() == Action.LEFT_CLICK_BLOCK)
{
Block clicked = event.getClickedBlock();
if (clicked.getType() == Material.FURNACE)
{
Smelter.smeltItemInHand(event.getPlayer());
}
}
}
}