Fix memory leak in player gear management. Update custom gear display design for title and description to fit CJ's specified design, as well as updating attribute descriptions to match google doc more closely. Fix bug with damage reduction attributes adding instead of reducing damage. Fix bug with parse errors causing defective attribute bugs and console spam with certain custom gear attributes. Fix bug where legend was not being properly displayed for /c map command. Fix bug where chunks could be claimed diagonally to opposing enemy clans. Fix bug with redstone not properly being disabled. Fix bug with attribute effects taking place even when damage events were cancelled, such as in safe zones. Fix bug with dispensers being able to place lava and water blocks. Fix bug where holding a book caused debug chat spam for players in regards to custom damage events.

This commit is contained in:
Ty Sayers 2015-07-20 15:57:57 -05:00
parent d2f633f572
commit 0b49d053fe
24 changed files with 113 additions and 103 deletions

View File

@ -150,6 +150,10 @@ public class ClansDisplay extends MiniPlugin
else else
for (int i = 0 ; i < local.size() ; i++) for (int i = 0 ; i < local.size() ; i++)
UtilPlayer.message(player, local.get(i) + " " + home.get(i)); UtilPlayer.message(player, local.get(i) + " " + home.get(i));
// Display legend for map symbols
UtilPlayer.message(player, C.xNone + "X: Current, #: Claimed, H: Home");
UtilPlayer.message(player, C.xNone + "S: Safe, +: Admin, -: Unclaimed");
} }
public LinkedList<String> mLocalMap(Player player, Chunk chunk, boolean local) public LinkedList<String> mLocalMap(Player player, Chunk chunk, boolean local)

View File

@ -251,7 +251,7 @@ public class ClansGame extends MiniPlugin
mimic)); mimic));
} }
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOW)
public void Damage(CustomDamageEvent event) public void Damage(CustomDamageEvent event)
{ {
if (event.IsCancelled()) if (event.IsCancelled())

View File

@ -840,28 +840,24 @@ public class ClansCommand extends CommandBase<ClansManager>
if (adjClan == null) if (adjClan == null)
continue; continue;
if (x == 0 || z == 0) if (checkBox(caller.getWorld().getChunkAt(
caller.getLocation().getChunk().getX()+x,
caller.getLocation().getChunk().getZ()+z), 3))
{ {
if (checkBox(caller.getWorld().getChunkAt( UtilPlayer.message(caller, F.main("Clans", "You cannot claim this Territory, it causes a box."));
caller.getLocation().getChunk().getX()+x, UtilPlayer.message(caller, F.main("Clans", "This means a Territory has all sides claimed."));
caller.getLocation().getChunk().getZ()+z), 3)) return;
{ }
UtilPlayer.message(caller, F.main("Clans", "You cannot claim this Territory, it causes a box."));
UtilPlayer.message(caller, F.main("Clans", "This means a Territory has all sides claimed."));
return;
}
if (Plugin.getClanUtility().rel(clan, adjClan) == ClanRelation.SELF) if (Plugin.getClanUtility().rel(clan, adjClan) == ClanRelation.SELF)
{ {
selfAdj = true; selfAdj = true;
} }
else if (Plugin.getClanUtility().rel(clan, adjClan) != ClanRelation.SELF)
else if (Plugin.getClanUtility().rel(clan, adjClan) != ClanRelation.SELF) {
{ UtilPlayer.message(caller, F.main("Clans", "You cannot claim Territory next to " +
UtilPlayer.message(caller, F.main("Clans", "You cannot claim Territory next to " + Plugin.getClanUtility().mRel(Plugin.getClanUtility().rel(ownerClan, adjClan), adjClan.getName(), true) + "."));
Plugin.getClanUtility().mRel(Plugin.getClanUtility().rel(ownerClan, adjClan), adjClan.getName(), true) + ".")); return;
return;
}
} }
} }

View File

@ -38,6 +38,7 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockBurnEvent; import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockDamageEvent; import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockDispenseEvent;
import org.bukkit.event.block.BlockIgniteEvent; import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.block.BlockIgniteEvent.IgniteCause; import org.bukkit.event.block.BlockIgniteEvent.IgniteCause;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
@ -141,6 +142,28 @@ public class Gameplay extends MiniPlugin
} }
} }
@EventHandler(priority = EventPriority.LOWEST)
public void RedstoneCancel(BlockPlaceEvent event)
{
if (event.getBlock().getType().toString().startsWith("REDSTONE"))
{
UtilPlayer.message(event.getPlayer(), F.main("Game", "You cannot place redstone based items."));
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void DispenseLiquidCancel(BlockDispenseEvent event)
{
Material material = event.getItem().getType();
if (material == Material.LAVA_BUCKET || material == Material.LAVA
|| material == Material.WATER_BUCKET || material == Material.WATER)
{
event.setCancelled(true);
}
}
@EventHandler @EventHandler
public void WebBreak(BlockDamageEvent event) public void WebBreak(BlockDamageEvent event)
{ {

View File

@ -10,6 +10,7 @@ import mineplex.game.clans.items.attributes.AttributeContainer;
import mineplex.game.clans.items.attributes.ItemAttribute; import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.minecraft.game.core.damage.CustomDamageEvent; import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
@ -25,6 +26,9 @@ import org.bukkit.inventory.meta.ItemMeta;
public class CustomItem public class CustomItem
{ {
private static final ChatColor TITLE_COLOR = ChatColor.GOLD; // Chat color used for item display name
private static final ChatColor ATTRIBUTE_COLOR = ChatColor.WHITE; // Chat color used for attribute descriptions
private AttributeContainer _attributes; private AttributeContainer _attributes;
public AttributeContainer getAttributes() { return _attributes; } public AttributeContainer getAttributes() { return _attributes; }
@ -53,7 +57,7 @@ public class CustomItem
*/ */
public String getDisplayName() public String getDisplayName()
{ {
return _attributes.formatItemName(_displayName); return ChatColor.RESET.toString() + TITLE_COLOR + _attributes.formatItemName(_displayName);
} }
public String getDescription() public String getDescription()
@ -63,8 +67,6 @@ public class CustomItem
public List<String> getLore() public List<String> getLore()
{ {
String serialization = GearManager.getItemSerialization(this);
List<String> lore = new ArrayList<String>(); List<String> lore = new ArrayList<String>();
if (getDescription() != null) if (getDescription() != null)
@ -75,18 +77,13 @@ public class CustomItem
// Display attribute descriptions and stats in lore // Display attribute descriptions and stats in lore
for (ItemAttribute attribute : _attributes.getAttributes()) for (ItemAttribute attribute : _attributes.getAttributes())
{ {
String attributeLine = attribute.getDisplayName() + " - " + attribute.getDescription(); String attributeLine = ATTRIBUTE_COLOR + "-" + attribute.getDescription();
lore.add(attributeLine); lore.add(attributeLine);
} }
// Tack on serialized JSON encoded line for utility purposes. (Not seen by user) // Add encoded JSON form of this item, not seen by user.
List<String> serializedLines = new ArrayList<String>(); String serialization = GearManager.getItemSerialization(this);
String[] seri = serialization.split("\n"); lore.add(serialization);
for (String line : seri)
{
serializedLines.add(line);
}
lore.addAll(serializedLines);
return lore; return lore;
} }

View File

@ -181,7 +181,14 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable
{ {
for (PlayerGear gear : _playerGears.values()) for (PlayerGear gear : _playerGears.values())
{ {
gear.update(); if (gear.isOnline())
{
gear.update();
}
else
{
_playerGears.remove(gear.getPlayerName());
}
} }
} }

View File

@ -8,6 +8,7 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile; import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
@ -69,9 +70,11 @@ public class ItemListener implements Listener
* Handle the trigger of custom gear related effects and abilities. * Handle the trigger of custom gear related effects and abilities.
* @param event * @param event
*/ */
@EventHandler @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerAttack(CustomDamageEvent event) public void onPlayerAttack(CustomDamageEvent event)
{ {
if (event.IsCancelled()) return; // Checks for Pre-Cancelled event and stops
Player damager = event.GetDamagerPlayer(false); // For non-ranged attacks Player damager = event.GetDamagerPlayer(false); // For non-ranged attacks
Player damagee = event.GetDamageePlayer(); Player damagee = event.GetDamageePlayer();
Projectile projectile = event.GetProjectile(); Projectile projectile = event.GetProjectile();

View File

@ -23,6 +23,7 @@ import org.bukkit.inventory.PlayerInventory;
public class PlayerGear public class PlayerGear
{ {
private String _playerName; // Name of player who owns the gear private String _playerName; // Name of player who owns the gear
public String getPlayerName() { return _playerName; }
// Cached custom item information for player's gear // Cached custom item information for player's gear
private CustomItem weapon; private CustomItem weapon;

View File

@ -1,5 +1,6 @@
package mineplex.game.clans.items.attributes.armor; package mineplex.game.clans.items.attributes.armor;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
@ -11,7 +12,7 @@ import mineplex.game.clans.items.generation.ValueDistribution;
public class ConqueringArmorAttribute extends FlatReductionAttribute public class ConqueringArmorAttribute extends FlatReductionAttribute
{ {
private static ValueDistribution reductionGen = generateDistribution(1.0d, 4.0d); private static ValueDistribution reductionGen = generateDistribution(1.0d, 4.0d);
private static ReductionConfig config = new ReductionConfig(EntityType.values()); private static ReductionConfig config = new ReductionConfig();
public ConqueringArmorAttribute() public ConqueringArmorAttribute()
{ {
@ -27,6 +28,12 @@ public class ConqueringArmorAttribute extends FlatReductionAttribute
@Override @Override
public String getDescription() public String getDescription()
{ {
return String.format("Reduce incoming damage from mobs and bosses by %.2f half-hearts.", getFlatReduction()); return String.format("-%.1f damage taken from mobs & bosses.", getFlatReduction());
}
@Override
public boolean reducesDamage(DamageCause cause, Entity attacker)
{
return attacker != null; // Reduces damage from all entities
} }
} }

View File

@ -25,6 +25,6 @@ public class LavaAttribute extends PercentReductionAttribute
@Override @Override
public String getDescription() public String getDescription()
{ {
return String.format("Reduce fire-related damage by %.2f percent.", getReductionPercent()); return String.format("Reduces damage from fire and lava by %.1f%.", getReductionPercent() * 100d);
} }
} }

View File

@ -25,6 +25,6 @@ public class PaddedAttribute extends FlatReductionAttribute
@Override @Override
public String getDescription() public String getDescription()
{ {
return String.format("Reduce fall damage by %.2f half-hearts.", getFlatReduction()); return String.format("-%.1f damage taken from falls.", getFlatReduction());
} }
} }

View File

@ -31,11 +31,11 @@ public abstract class ReductionAttribute extends ItemAttribute
DamageCause cause = event.GetCause(); DamageCause cause = event.GetCause();
Entity attacker = event.GetDamagerEntity(true); Entity attacker = event.GetDamagerEntity(true);
if (_config.reducesDamage(cause, attacker)) if (reducesDamage(cause, attacker))
{ {
double damage = event.GetDamage(); double damage = event.GetDamage();
double reduction = getDamageReduction(damage); double reduction = getDamageReduction(damage);
event.AddMod("Reduction Armor", reduction); event.AddMod("Reduction Armor", -reduction);
System.out.println("Reduced damage by " + reduction); System.out.println("Reduced damage by " + reduction);
} }
else else
@ -44,5 +44,10 @@ public abstract class ReductionAttribute extends ItemAttribute
} }
} }
public boolean reducesDamage(DamageCause cause, Entity attacker)
{
return _config.reducesDamage(cause, attacker);
}
public abstract double getDamageReduction(double originalDamage); public abstract double getDamageReduction(double originalDamage);
} }

View File

@ -24,6 +24,6 @@ public class ReinforcedAttribute extends FlatReductionAttribute
@Override @Override
public String getDescription() public String getDescription()
{ {
return String.format("Reduce incoming melee damage by %.2f half-hearts.", getFlatReduction()); return String.format("-%.1f damage taken from melee.", getFlatReduction());
} }
} }

View File

@ -25,6 +25,6 @@ public class SlantedAttribute extends FlatReductionAttribute
@Override @Override
public String getDescription() public String getDescription()
{ {
return String.format("Reduce arrow damage by %.2f half-hearts.", getFlatReduction()); return String.format("-%.1f damage taken from projectiles.", getFlatReduction());
} }
} }

View File

@ -25,7 +25,7 @@ public class ConqueringAttribute extends DamageAttribute
@Override @Override
public String getDescription() public String getDescription()
{ {
return String.format("Deal an extra %.2f hearts of damage to mobs.", getBonusDamage()); return String.format("%.2f bonus damage against mobs & bosses.", getBonusDamage());
} }
@Override @Override

View File

@ -22,13 +22,13 @@ public class FlamingAttribute extends AttackAttribute
@Override @Override
public String getDisplayName() public String getDisplayName()
{ {
return "Flaming"; // TODO: Fill in name return "Flaming";
} }
@Override @Override
public String getDescription() public String getDescription()
{ {
return String.format("Enemies catch fire for %d ticks every %d attacks.", _fireDuration, getAttackLimit()); return String.format("Every %d attacks gives Fire for %.1f seconds.", getAttackLimit(), (_fireDuration / 20d));
} }
@Override @Override

View File

@ -36,7 +36,7 @@ public class HasteAttribute extends AttackAttribute
@Override @Override
public String getDescription() public String getDescription()
{ {
return String.format("Gain speed %s for %d ticks every %d attacks.", amplifierToRoman(_speedAmount), _speedDuration, getAttackLimit()); return String.format("Every %d attacks gives you Speed %s for %.1f seconds.", getAttackLimit(), amplifierToRoman(_speedAmount), (_speedDuration / 20f));
} }
@Override @Override

View File

@ -3,26 +3,37 @@ package mineplex.game.clans.items.attributes.weapon;
import mineplex.game.clans.items.attributes.AttributeType; import mineplex.game.clans.items.attributes.AttributeType;
import mineplex.game.clans.items.attributes.ItemAttribute; import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.game.clans.items.generation.ValueDistribution; import mineplex.game.clans.items.generation.ValueDistribution;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
public class HeavyAttribute extends ItemAttribute public class HeavyAttribute extends ItemAttribute
{ {
// TODO: Replace with your generators private static ValueDistribution knockbackGen = generateDistribution(25, 75); // Value generator for knockback % boost.
private static ValueDistribution healGen = generateDistribution(4, 12); // Value generator for heal amount
private int _healPercent; private double _knockbackBoost;
public HeavyAttribute() public HeavyAttribute()
{ {
super(AttributeType.PREFIX); super(AttributeType.PREFIX);
_healPercent = healGen.generateIntValue(); _knockbackBoost = knockbackGen.generateValue();
} }
@Override @Override
public String getDisplayName() public String getDisplayName()
{ {
return ""; // TODO: Fill in name return "Heavy";
}
@Override
public String getDescription()
{
return String.format("%.1f% additional knockback.", _knockbackBoost);
} }
@Override
public void onAttack(CustomDamageEvent event)
{
double knockback = (_knockbackBoost / 100d) * event.getKnockbackValue();
event.AddKnockback("Heavy Attribute", knockback);
}
} }

View File

@ -25,7 +25,7 @@ public class JaggedAttribute extends AttackAttribute
@Override @Override
public String getDescription() public String getDescription()
{ {
return String.format("Temporarily halt enemies every %d attacks.", getAttackLimit()); return String.format("Every %d attacks mini-stuns enemies.", getAttackLimit());
} }
@Override @Override

View File

@ -24,7 +24,7 @@ public class SharpAttribute extends DamageAttribute
@Override @Override
public String getDescription() public String getDescription()
{ {
return String.format("Deal an extra %.2f damage.", getBonusDamage()); return String.format("%.2f bonus damage.", getBonusDamage());
} }
@Override @Override

View File

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

View File

@ -1,23 +0,0 @@
package mineplex.hub.server.ui.button;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import mineplex.core.shop.item.IButton;
import mineplex.hub.server.ui.ServerGameMenu;
public class SelectBHButton implements IButton
{
private ServerGameMenu _menu;
public SelectBHButton(ServerGameMenu menu)
{
_menu = menu;
}
@Override
public void onClick(Player player, ClickType clickType)
{
_menu.OpenBH(player);
}
}

View File

@ -1,23 +0,0 @@
package mineplex.hub.server.ui.button;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import mineplex.core.shop.item.IButton;
import mineplex.hub.server.ui.ServerGameMenu;
public class SelectMSButton implements IButton
{
private ServerGameMenu _menu;
public SelectMSButton(ServerGameMenu menu)
{
_menu = menu;
}
@Override
public void onClick(Player player, ClickType clickType)
{
_menu.openMS(player);
}
}

View File

@ -248,7 +248,9 @@ public class DamageManager extends MiniPlugin
} }
} }
DisplayDamage(event); // TODO: What is this required for? Players with books in regular games are spammed. Is it meant for debugging?
// TODO: Temporarily commenting out
//DisplayDamage(event);
} }
private void Damage(CustomDamageEvent event) private void Damage(CustomDamageEvent event)