Fix attribute name positioning bug as well as duplicated attributes on randomly generated items. Fix misleading description of item attributes Conquering/Protection. Fix bug with unwanted entities spawning and targetting players in safe Spawn zones. Fix bug with WindBlade occasionally killing users via fall damage after a long flight even though close to the ground. Fix bug with MagneticBlade not properly pulling entities other than players. Fix bug with AlligatorsTooth not properly granting certain effects such as water breathing.

This commit is contained in:
Ty Sayers 2015-06-29 16:38:51 -04:00
parent 1541dc329e
commit d2f633f572
45 changed files with 303 additions and 157 deletions

View File

@ -3,6 +3,7 @@ package mineplex.game.clans.clans;
import java.util.HashSet;
import java.util.TimeZone;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;

View File

@ -25,14 +25,8 @@ import org.bukkit.inventory.meta.ItemMeta;
public class CustomItem
{
private ItemAttribute _superPrefix;
public void setSuperPrefix(ItemAttribute attribute) { _superPrefix = attribute; }
private ItemAttribute _prefix;
public void setPrefix(ItemAttribute attribute) { _prefix = attribute; }
private ItemAttribute _suffix;
public void setSuffix(ItemAttribute attribute) { _suffix = attribute; }
private AttributeContainer _attributes;
public AttributeContainer getAttributes() { return _attributes; }
protected String _displayName;
private String _description;
@ -59,25 +53,7 @@ public class CustomItem
*/
public String getDisplayName()
{
// Concatenate attribute prefixes/suffixes to display name.
String display = _displayName;
if (_prefix != null)
{
display = _prefix.getDisplayName() + " " + display;
}
if (_superPrefix != null)
{
display = _superPrefix.getDisplayName() + " " + display;
}
if (_suffix != null)
{
display += " of " + _suffix.getDisplayName();
}
return display;
return _attributes.formatItemName(_displayName);
}
public String getDescription()
@ -97,7 +73,7 @@ public class CustomItem
}
// Display attribute descriptions and stats in lore
for (ItemAttribute attribute : getAttributes())
for (ItemAttribute attribute : _attributes.getAttributes())
{
String attributeLine = attribute.getDisplayName() + " - " + attribute.getDescription();
lore.add(attributeLine);
@ -131,8 +107,7 @@ public class CustomItem
public void onInteract(PlayerInteractEvent event)
{
System.out.println("Triggered interact!");
for (ItemAttribute attribute : getAttributes())
for (ItemAttribute attribute : _attributes.getAttributes())
{
attribute.onInteract(event);
}
@ -140,8 +115,7 @@ public class CustomItem
public void onAttack(CustomDamageEvent event)
{
System.out.println("Triggered attack!");
for (ItemAttribute attribute : getAttributes())
for (ItemAttribute attribute : _attributes.getAttributes())
{
attribute.onAttack(event);
}
@ -149,25 +123,12 @@ public class CustomItem
public void onAttacked(CustomDamageEvent event)
{
System.out.println("Triggered damage!");
for (ItemAttribute attribute : getAttributes())
for (ItemAttribute attribute : _attributes.getAttributes())
{
attribute.onAttacked(event);
}
}
/**
* @return the (possibly empty) set of {@link ItemAttribute}s attached to this item.
*/
public Set<ItemAttribute> getAttributes()
{
Set<ItemAttribute> attributes = new HashSet<ItemAttribute>();
if (_superPrefix != null) attributes.add(_superPrefix);
if (_prefix != null) attributes.add(_prefix);
if (_suffix != null) attributes.add(_suffix);
return attributes;
}
/**
* @param item - the item to check for a matching link
* @return true, if {@code item} matches this CustomItem via UUID, false otherwise.
@ -194,27 +155,6 @@ public class CustomItem
item.setItemMeta(meta);
}
public void addAttribute(ItemAttribute attribute)
{
if (_superPrefix == null)
{
_superPrefix = attribute;
}
else if (_prefix == null)
{
_prefix = attribute;
}
else if (_suffix == null)
{
_suffix = attribute;
}
}
public AttributeContainer cloneAttributes()
{
return new AttributeContainer(_superPrefix, _prefix, _suffix);
}
public static String prettifyName(Material material)
{

View File

@ -18,6 +18,7 @@ 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.*;
@ -101,7 +102,7 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable
// Armour-based attributes
_armourAttributes = new WeightSet<Class<? extends ItemAttribute>>(SlantedAttribute.class, ReinforcedAttribute.class,
ProtectionAttribute.class, PaddedAttribute.class, LavaAttribute.class);
ConqueringArmorAttribute.class, PaddedAttribute.class, LavaAttribute.class);
// Bow-based attributes
_bowAttributes = new WeightSet<Class<? extends ItemAttribute>>(HeavyArrowsAttribute.class, HuntingAttribute.class, InverseAttribute.class,
@ -204,18 +205,11 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable
{
int attributeCount = _attributeWeights.generateRandom();
ItemType itemType = _typeWeights.generateRandom();
System.out.println("Generating item of type " + itemType.toString() + " with attribute count of " + attributeCount);
CustomItem item = generateItem(itemType);
System.out.println("Generated item!");
if (itemType != ItemType.LEGENDARY) // Only non-legendaries have attributes
{
for (ItemAttribute attribute : generateAttributes(itemType, attributeCount))
{
item.addAttribute(attribute);
}
// Add up to attributeCount attributes
generateAttributes(item.getAttributes(), itemType, attributeCount);
}
return item;
@ -240,29 +234,41 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable
}
}
private Set<ItemAttribute> generateAttributes(ItemType type, int count)
private void generateAttributes(AttributeContainer container, ItemType type, int count)
{
Set<ItemAttribute> attributes = new HashSet<ItemAttribute>();
for (int i = 0; i < count; i++)
{
switch (type)
int attempts = 0;
Set<AttributeType> remaining = container.getRemainingTypes();
ItemAttribute attribute = null;
while (remaining.size() > 0 && attempts < 10 && attribute == null)
{
case ARMOUR:
attributes.add(instantiate(_armourAttributes.generateRandom()));
break;
case WEAPON:
attributes.add(instantiate(_weaponAttributes.generateRandom()));
break;
case BOW:
attributes.add(instantiate(_bowAttributes.generateRandom()));
break;
default:
break;
ItemAttribute sampleAttribute = null;
switch (type)
{
case ARMOUR:
sampleAttribute = instantiate(_armourAttributes.generateRandom());
break;
case WEAPON:
sampleAttribute = instantiate(_weaponAttributes.generateRandom());
break;
case BOW:
sampleAttribute = instantiate(_bowAttributes.generateRandom());
break;
default:
break;
}
if (sampleAttribute != null && remaining.contains(sampleAttribute.getType()))
{
attribute = sampleAttribute; // Select valid attribute to add
}
}
container.addAttribute(attribute);
}
return attributes;
}
public void spawnItem(Location location)

View File

@ -76,14 +76,14 @@ public class ItemListener implements Listener
Player damagee = event.GetDamageePlayer();
Projectile projectile = event.GetProjectile();
// Trigger custom gear effects for attacker
if (damager != null)
// Trigger custom gear effects for attacker melee weapons
if (damager != null && event.GetCause() == DamageCause.ENTITY_ATTACK)
{
PlayerGear attackerGear = getGear(damager);
attackerGear.onAttack(event);
}
// Trigger custom gear effects for defender
// Trigger custom gear effects for defender armour
if (damagee != null)
{
PlayerGear defenderGear = getGear(damagee);
@ -126,7 +126,7 @@ public class ItemListener implements Listener
if (weapon != null)
{
// Copy weapon attributes onto projectile for later processing
AttributeContainer attributes = weapon.cloneAttributes();
AttributeContainer attributes = weapon.getAttributes();
String serialization = GearManager.serialize(attributes);
Entity projectile = event.getProjectile();

View File

@ -19,8 +19,10 @@ public abstract class AttackAttribute extends ItemAttribute
private int _attackCount;
public AttackAttribute(int attackLimit)
public AttackAttribute(AttributeType type, int attackLimit)
{
super(type);
_attackLimit = attackLimit;
_attackCount = 0;
}

View File

@ -6,16 +6,82 @@ import java.util.Set;
public class AttributeContainer
{
private Set<ItemAttribute> _attributes;
public Set<ItemAttribute> getAttributes() { return _attributes; }
private ItemAttribute _superPrefix;
public ItemAttribute getSuperPrefix() { return _superPrefix; }
public void setSuperPrefix(ItemAttribute attribute) { _superPrefix = attribute; }
private ItemAttribute _prefix;
public ItemAttribute getPrefix() { return _prefix; }
public void setPrefix(ItemAttribute attribute) { _prefix = attribute; }
public AttributeContainer(ItemAttribute... attributes)
private ItemAttribute _suffix;
public ItemAttribute getSuffix() { return _suffix; }
public void setSuffix(ItemAttribute attribute) { _suffix = attribute; }
public AttributeContainer(ItemAttribute superPrefix, ItemAttribute prefix, ItemAttribute suffix)
{
_attributes = new HashSet<ItemAttribute>();
for (ItemAttribute attribute : attributes)
_superPrefix = superPrefix;
_prefix = prefix;
_suffix = suffix;
}
public Set<ItemAttribute> getAttributes()
{
Set<ItemAttribute> attributes = new HashSet<ItemAttribute>();
if (_superPrefix != null) attributes.add(_superPrefix);
if (_prefix != null) attributes.add(_prefix);
if (_suffix != null) attributes.add(_suffix);
return attributes;
}
public Set<AttributeType> getRemainingTypes()
{
Set<AttributeType> remainingTypes = new HashSet<AttributeType>();
if (_superPrefix == null) remainingTypes.add(AttributeType.SUPER_PREFIX);
if (_prefix == null) remainingTypes.add(AttributeType.PREFIX);
if (_suffix == null) remainingTypes.add(AttributeType.SUFFIX);
return remainingTypes;
}
public String formatItemName(String displayName)
{
String itemName = displayName;
if (_prefix != null)
{
_attributes.add(attribute);
itemName = _prefix.getDisplayName() + " " + itemName;
}
if (_superPrefix != null)
{
itemName = _superPrefix.getDisplayName() + " " + itemName;
}
if (_suffix != null)
{
itemName += " of " + _suffix.getDisplayName();
}
return itemName;
}
public void addAttribute(ItemAttribute attribute)
{
switch(attribute.getType())
{
case SUPER_PREFIX:
setSuperPrefix(attribute);
break;
case PREFIX:
setPrefix(attribute);
break;
case SUFFIX:
setSuffix(attribute);
break;
}
}
}

View File

@ -0,0 +1,8 @@
package mineplex.game.clans.items.attributes;
public enum AttributeType
{
SUPER_PREFIX,
PREFIX,
SUFFIX;
}

View File

@ -11,8 +11,10 @@ public abstract class DamageAttribute extends ItemAttribute
private double _bonusDamage;
public double getBonusDamage() { return _bonusDamage; }
public DamageAttribute(ValueDistribution damageGen)
public DamageAttribute(AttributeType type, ValueDistribution damageGen)
{
super(type);
_bonusDamage = damageGen.generateValue();
}

View File

@ -14,6 +14,15 @@ import org.bukkit.event.player.PlayerInteractEvent;
*/
public abstract class ItemAttribute
{
private AttributeType _type;
public AttributeType getType() { return _type; }
public boolean matchesType(AttributeType type) { return _type == type; }
public ItemAttribute(AttributeType type)
{
_type = type;
}
/**
* @return the attribute name display to players.
@ -24,7 +33,7 @@ public abstract class ItemAttribute
* @return a user-friendly description of this attribute, entailing it's effects
* and current associated values.
*/
public String getDescription() { return "???IMPLEMENT"; }
public String getDescription() { return "???IMPLEMENT???"; }
public void onInteract(PlayerInteractEvent event)
{

View File

@ -3,29 +3,30 @@ 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.AttributeType;
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
public class ConqueringArmorAttribute extends FlatReductionAttribute
{
private static ValueDistribution reductionGen = generateDistribution(1.0d, 4.0d);
private static ReductionConfig config = new ReductionConfig(EntityType.values());
public ProtectionAttribute()
public ConqueringArmorAttribute()
{
super(reductionGen, config);
super(AttributeType.SUFFIX, reductionGen, config);
}
@Override
public String getDisplayName()
{
return "Protection";
return "Conquering";
}
@Override
public String getDescription()
{
return String.format("Reduce incoming attack damage by %.2f half-hearts.", getFlatReduction());
return String.format("Reduce incoming damage from mobs and bosses by %.2f half-hearts.", getFlatReduction());
}
}

View File

@ -1,5 +1,6 @@
package mineplex.game.clans.items.attributes.armor;
import mineplex.game.clans.items.attributes.AttributeType;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
@ -12,6 +13,8 @@ public class EscapeAttribute extends ItemAttribute
public EscapeAttribute()
{
super(AttributeType.SUFFIX);
_healPercent = healGen.generateIntValue();
}

View File

@ -1,5 +1,6 @@
package mineplex.game.clans.items.attributes.armor;
import mineplex.game.clans.items.attributes.AttributeType;
import mineplex.game.clans.items.generation.ValueDistribution;
public abstract class FlatReductionAttribute extends ReductionAttribute
@ -8,9 +9,9 @@ public abstract class FlatReductionAttribute extends ReductionAttribute
private double _reduction;
public double getFlatReduction() { return _reduction; }
public FlatReductionAttribute(ValueDistribution reductionGen, ReductionConfig config)
public FlatReductionAttribute(AttributeType type, ValueDistribution reductionGen, ReductionConfig config)
{
super(config);
super(type, config);
_reduction = reductionGen.generateValue();
}

View File

@ -2,6 +2,7 @@ package mineplex.game.clans.items.attributes.armor;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import mineplex.game.clans.items.attributes.AttributeType;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
@ -12,8 +13,7 @@ public class LavaAttribute extends PercentReductionAttribute
public LavaAttribute()
{
super(reductionGen, lavaConfig);
super(AttributeType.SUPER_PREFIX, reductionGen, lavaConfig);
}
@Override

View File

@ -2,6 +2,7 @@ package mineplex.game.clans.items.attributes.armor;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import mineplex.game.clans.items.attributes.AttributeType;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
@ -12,7 +13,7 @@ public class PaddedAttribute extends FlatReductionAttribute
public PaddedAttribute()
{
super(reductionGen, config);
super(AttributeType.PREFIX, reductionGen, config);
}
@Override

View File

@ -1,5 +1,6 @@
package mineplex.game.clans.items.attributes.armor;
import mineplex.game.clans.items.attributes.AttributeType;
import mineplex.game.clans.items.generation.ValueDistribution;
public abstract class PercentReductionAttribute extends ReductionAttribute
@ -7,9 +8,10 @@ public abstract class PercentReductionAttribute extends ReductionAttribute
private double _reductionPercent;
public double getReductionPercent() { return _reductionPercent; }
public PercentReductionAttribute(ValueDistribution reductionGen, ReductionConfig config)
public PercentReductionAttribute(AttributeType type, ValueDistribution reductionGen, ReductionConfig config)
{
super(config);
super(type, config);
_reductionPercent = reductionGen.generateValue();
}

View File

@ -8,6 +8,7 @@ import org.bukkit.entity.EntityType;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import mineplex.game.clans.items.attributes.AttributeType;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
@ -17,8 +18,10 @@ public abstract class ReductionAttribute extends ItemAttribute
private ReductionConfig _config;
public ReductionAttribute(ReductionConfig config)
public ReductionAttribute(AttributeType type, ReductionConfig config)
{
super(type);
_config = config;
}

View File

@ -1,7 +1,8 @@
package mineplex.game.clans.items.attributes.armor;
package mineplex.game.clans.items.attributes.armor;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import mineplex.game.clans.items.attributes.AttributeType;
import mineplex.game.clans.items.generation.ValueDistribution;
public class ReinforcedAttribute extends FlatReductionAttribute
@ -11,7 +12,7 @@ public class ReinforcedAttribute extends FlatReductionAttribute
public ReinforcedAttribute()
{
super(reductionGen, config);
super(AttributeType.PREFIX, reductionGen, config);
}
@Override
@ -23,6 +24,6 @@ public class ReinforcedAttribute extends FlatReductionAttribute
@Override
public String getDescription()
{
return String.format("Reduce incoming attacks by enemies by %.2f half-hearts.", getFlatReduction());
return String.format("Reduce incoming melee damage by %.2f half-hearts.", getFlatReduction());
}
}

View File

@ -1,5 +1,6 @@
package mineplex.game.clans.items.attributes.armor;
import mineplex.game.clans.items.attributes.AttributeType;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
@ -12,6 +13,8 @@ public class SeaAttribute extends ItemAttribute
public SeaAttribute()
{
super(AttributeType.SUFFIX);
_healPercent = healGen.generateIntValue();
}

View File

@ -2,6 +2,7 @@ package mineplex.game.clans.items.attributes.armor;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import mineplex.game.clans.items.attributes.AttributeType;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
@ -12,7 +13,7 @@ public class SlantedAttribute extends FlatReductionAttribute
public SlantedAttribute()
{
super(reductionGen, config);
super(AttributeType.PREFIX, reductionGen, config);
}
@Override

View File

@ -1,5 +1,6 @@
package mineplex.game.clans.items.attributes.bow;
import mineplex.game.clans.items.attributes.AttributeType;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
@ -14,7 +15,7 @@ public class DestructionAttribute extends ItemAttribute
public DestructionAttribute()
{
super(AttributeType.SUFFIX);
}
@Override

View File

@ -1,5 +1,6 @@
package mineplex.game.clans.items.attributes.bow;
import mineplex.game.clans.items.attributes.AttributeType;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
@ -14,6 +15,8 @@ public class HeavyArrowsAttribute extends ItemAttribute
public HeavyArrowsAttribute()
{
super(AttributeType.PREFIX);
_knockbackPercent = knockbackGen.generateValue();
}

View File

@ -1,5 +1,6 @@
package mineplex.game.clans.items.attributes.bow;
import mineplex.game.clans.items.attributes.AttributeType;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
@ -19,6 +20,8 @@ public class HuntingAttribute extends ItemAttribute
public HuntingAttribute()
{
super(AttributeType.PREFIX);
_slowAmount = amountGen.generateIntValue();
_slowDuration = durationGen.generateValue();
}

View File

@ -1,5 +1,6 @@
package mineplex.game.clans.items.attributes.bow;
import mineplex.game.clans.items.attributes.AttributeType;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
@ -14,6 +15,8 @@ private static ValueDistribution knockbackGen = generateDistribution(-0.5d, 1.0d
public InverseAttribute()
{
super(AttributeType.PREFIX);
_knockbackModifier = knockbackGen.generateValue();
}

View File

@ -1,5 +1,6 @@
package mineplex.game.clans.items.attributes.bow;
import mineplex.game.clans.items.attributes.AttributeType;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
@ -15,6 +16,8 @@ public class LeechingAttribute extends ItemAttribute
public LeechingAttribute()
{
super(AttributeType.SUPER_PREFIX);
_healPercent = healGen.generateIntValue();
}

View File

@ -1,5 +1,6 @@
package mineplex.game.clans.items.attributes.bow;
import mineplex.game.clans.items.attributes.AttributeType;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
@ -14,7 +15,7 @@ public class ReboundingAttribute extends ItemAttribute
public ReboundingAttribute()
{
super(AttributeType.SUPER_PREFIX);
}
@Override

View File

@ -1,5 +1,6 @@
package mineplex.game.clans.items.attributes.bow;
import mineplex.game.clans.items.attributes.AttributeType;
import mineplex.game.clans.items.attributes.DamageAttribute;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
@ -13,7 +14,7 @@ public class RecursiveAttribute extends DamageAttribute
public RecursiveAttribute()
{
super(attackGen);
super(AttributeType.PREFIX, attackGen);
}
@Override

View File

@ -1,6 +1,7 @@
package mineplex.game.clans.items.attributes.bow;
import mineplex.game.clans.items.attributes.AttackAttribute;
import mineplex.game.clans.items.attributes.AttributeType;
import mineplex.game.clans.items.generation.ValueDistribution;
import org.bukkit.entity.Entity;
@ -13,7 +14,7 @@ public class ScorchingAttribute extends AttackAttribute
public ScorchingAttribute()
{
super(1); // Activates every hit
super(AttributeType.SUPER_PREFIX, 1); // Activates every hit
_fireDuration = fireGen.generateValue();
}

View File

@ -1,5 +1,6 @@
package mineplex.game.clans.items.attributes.bow;
import mineplex.game.clans.items.attributes.AttributeType;
import mineplex.game.clans.items.attributes.DamageAttribute;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
@ -14,7 +15,7 @@ public class SlayingAttribute extends DamageAttribute
public SlayingAttribute()
{
super(attackGen);
super(AttributeType.SUFFIX, attackGen);
}
@Override

View File

@ -1,5 +1,6 @@
package mineplex.game.clans.items.attributes.bow;
import mineplex.game.clans.items.attributes.AttributeType;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
@ -14,7 +15,7 @@ public class SpectralAttribute extends ItemAttribute
public SpectralAttribute()
{
super(AttributeType.SUPER_PREFIX);
}
@Override

View File

@ -1,5 +1,6 @@
package mineplex.game.clans.items.attributes.weapon;
import mineplex.game.clans.items.attributes.AttributeType;
import mineplex.game.clans.items.attributes.DamageAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
@ -12,7 +13,7 @@ public class ConqueringAttribute extends DamageAttribute
public ConqueringAttribute()
{
super(damageGen);
super(AttributeType.SUFFIX, damageGen);
}
@Override

View File

@ -1,6 +1,7 @@
package mineplex.game.clans.items.attributes.weapon;
import mineplex.game.clans.items.attributes.AttackAttribute;
import mineplex.game.clans.items.attributes.AttributeType;
import mineplex.game.clans.items.generation.ValueDistribution;
import org.bukkit.entity.Entity;
@ -14,7 +15,7 @@ public class FlamingAttribute extends AttackAttribute
public FlamingAttribute()
{
super(attackGen.generateIntValue());
super(AttributeType.SUPER_PREFIX, attackGen.generateIntValue());
_fireDuration = fireGen.generateIntValue();
}

View File

@ -1,5 +1,6 @@
package mineplex.game.clans.items.attributes.weapon;
import mineplex.game.clans.items.attributes.AttributeType;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
@ -28,6 +29,8 @@ public class FrostedAttribute extends ItemAttribute
*/
public FrostedAttribute()
{
super(AttributeType.SUPER_PREFIX);
_slowAmount = amountGen.generateIntValue();
_slowDuration = durationGen.generateIntValue();
}

View File

@ -1,6 +1,7 @@
package mineplex.game.clans.items.attributes.weapon;
import mineplex.game.clans.items.attributes.AttackAttribute;
import mineplex.game.clans.items.attributes.AttributeType;
import mineplex.game.clans.items.generation.ValueDistribution;
import org.bukkit.entity.Entity;
@ -20,7 +21,7 @@ public class HasteAttribute extends AttackAttribute
public HasteAttribute()
{
super(attackGen.generateIntValue());
super(AttributeType.SUFFIX, attackGen.generateIntValue());
_speedAmount = speedGen.generateIntValue();
_speedDuration = durationGen.generateIntValue();

View File

@ -1,5 +1,6 @@
package mineplex.game.clans.items.attributes.weapon;
import mineplex.game.clans.items.attributes.AttributeType;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
@ -12,6 +13,8 @@ public class HeavyAttribute extends ItemAttribute
public HeavyAttribute()
{
super(AttributeType.PREFIX);
_healPercent = healGen.generateIntValue();
}

View File

@ -1,6 +1,7 @@
package mineplex.game.clans.items.attributes.weapon;
import mineplex.game.clans.items.attributes.AttackAttribute;
import mineplex.game.clans.items.attributes.AttributeType;
import mineplex.game.clans.items.generation.ValueDistribution;
import org.bukkit.entity.Entity;
@ -12,7 +13,7 @@ public class JaggedAttribute extends AttackAttribute
public JaggedAttribute()
{
super(attackGen.generateIntValue());
super(AttributeType.PREFIX, attackGen.generateIntValue());
}
@Override

View File

@ -1,5 +1,6 @@
package mineplex.game.clans.items.attributes.weapon;
import mineplex.game.clans.items.attributes.AttributeType;
import mineplex.game.clans.items.attributes.DamageAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
@ -11,7 +12,7 @@ public class SharpAttribute extends DamageAttribute
public SharpAttribute()
{
super(damageGen);
super(AttributeType.PREFIX, damageGen);
}
@Override

View File

@ -1,5 +1,6 @@
package mineplex.game.clans.items.attributes.weapon;
import mineplex.game.clans.items.attributes.AttributeType;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
@ -12,6 +13,7 @@ public class SmashingAttribute extends ItemAttribute
public SmashingAttribute()
{
super(AttributeType.SUFFIX);
_healPercent = healGen.generateIntValue();
}

View File

@ -1,5 +1,6 @@
package mineplex.game.clans.items.attributes.weapon;
import mineplex.game.clans.items.attributes.AttributeType;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
@ -12,6 +13,8 @@ public class SwiftAttribute extends ItemAttribute
public SwiftAttribute()
{
super(AttributeType.PREFIX);
_healPercent = healGen.generateIntValue();
}

View File

@ -1,5 +1,6 @@
package mineplex.game.clans.items.attributes.weapon;
import mineplex.game.clans.items.attributes.AttributeType;
import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.generation.ValueDistribution;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
@ -15,6 +16,8 @@ public class VampiricAttribute extends ItemAttribute
public VampiricAttribute()
{
super(AttributeType.SUPER_PREFIX);
_healPercent = healGen.generateIntValue();
}

View File

@ -7,6 +7,7 @@ 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;
public class AlligatorsTooth extends LegendaryItem
@ -29,9 +30,15 @@ public class AlligatorsTooth extends LegendaryItem
@Override
public void update(Player wielder)
{
if (isHoldingRightClick() && isInWater(wielder))
if (isInWater(wielder))
{
propelPlayer(wielder);
// Player gain water breathing while under water with legendary equipped
grantPotionEffect(wielder, PotionEffectType.WATER_BREATHING, 0, 20);
if (isHoldingRightClick())
{
propelPlayer(wielder);
}
}
}

View File

@ -14,6 +14,10 @@ import org.bukkit.potion.PotionEffectType;
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)
public GiantsBroadsword()
{
super("Giants Broadsword", "Deal huge damage and block to gain defensive abilities!", Material.RECORD_4);
@ -38,17 +42,7 @@ public class GiantsBroadsword extends LegendaryItem
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;
grantPotionEffect(player, PotionEffectType.SLOW, 4, 10);
grantPotionEffect(player, PotionEffectType.REGENERATION, 1, 10);
}
}

View File

@ -5,6 +5,8 @@ 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;
import mineplex.game.clans.items.CustomItem;
import mineplex.game.clans.items.generation.ValueDistribution;
@ -77,4 +79,17 @@ public class LegendaryItem extends CustomItem
{
return new ValueDistribution(minValue, maxValue);
}
/**
* Add a {@link PotionEffect} to {@code player} with specified {@code type}, {@code amplifier} (power) and
* {@code tickDuration} of the effect.
* @param player - the player to receive the potion effect
* @param type - the type of potion to apply
* @param tickDuration - the duration (in ticks) to apply the potion for
* @param amplifier - the amplifier (level/power, zero-based) of the potion effect
*/
public static void grantPotionEffect(Player player, PotionEffectType type, int tickDuration, int amplifier)
{
player.addPotionEffect(new PotionEffect(type, amplifier, tickDuration));
}
}

View File

@ -7,6 +7,7 @@ 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;
@ -26,7 +27,7 @@ public class MagneticBlade extends LegendaryItem
{
if (isHoldingRightClick() && canPull())
{
pullPlayers(wielder);
pullEntities(wielder);
}
}
@ -38,23 +39,24 @@ public class MagneticBlade extends LegendaryItem
// TODO: Apply negative knockback with [???] velocity/power to victims of attacks
}
private void pullPlayers(Player player)
{
log("Pulling players!");
private void pullEntities(Player player)
{
Vector direction = player.getLocation().getDirection().normalize().multiply(10.0d);
Location target = player.getEyeLocation().add(direction);
double targetDistance = player.getLocation().distance(target);
for (Player other : player.getWorld().getPlayers())
for (LivingEntity entity : player.getWorld().getLivingEntities())
{
double otherDistance = player.getLocation().distance(other.getLocation());
double otherTargetDistance = target.distance(other.getLocation());
if (entity.getEntityId() == player.getEntityId()) continue; // Skip player pulling
double otherDistance = player.getLocation().distance(entity.getLocation());
double otherTargetDistance = target.distance(entity.getLocation());
// If player is in-front of us and within pulling range
if (otherTargetDistance < targetDistance && otherDistance <= PULL_RANGE)
{
UtilAction.velocity(other, UtilAlg.getTrajectory(other, player), 0.3, false, 0, 0, 1, true);
UtilAction.velocity(entity, UtilAlg.getTrajectory(entity, player), 0.3, false, 0, 0, 1, true);
}
}
}

View File

@ -49,6 +49,7 @@ public class WindBlade extends LegendaryItem
direction.multiply(FLIGHT_VELOCITY); // Set velocity magnitude
player.setVelocity(direction);
player.setFallDistance(0f); // To prevent bug with fall distances killing players inappropriately.
}
private boolean canPropel()

View File

@ -13,6 +13,9 @@ import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.block.BlockIgniteEvent.IgniteCause;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.entity.EntityTargetEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.plugin.java.JavaPlugin;
@ -60,6 +63,33 @@ public class Spawn extends MiniPlugin
event.setRespawnLocation(getSpawnLocation());
}
@EventHandler
public void onPlayerFirstJoin(PlayerJoinEvent event)
{
if (!event.getPlayer().hasPlayedBefore()) // First time playing on server, teleport to a spawn
{
teleport(event.getPlayer(), getSpawnLocation(), 2); // Teleport player to spawn after 2-tick delay to prevent on-join bug
}
}
@EventHandler
public void onEntitySpawn(EntitySpawnEvent event)
{
if (isInSpawn(event.getLocation()))
{
event.setCancelled(true);
}
}
@EventHandler
public void onEntityTarget(EntityTargetEvent event)
{
if (isInSpawn(event.getTarget().getLocation()))
{
event.setCancelled(true);
}
}
@EventHandler
public void onBlockBreak(BlockBreakEvent event)
{
@ -157,4 +187,14 @@ public class Spawn extends MiniPlugin
{
}
private void teleport(final Player player, final Location location, int delay)
{
Bukkit.getScheduler().scheduleSyncDelayedTask(getPlugin(), new Runnable() {
@Override
public void run() {
player.teleport(location);
}
}, delay);
}
}