Changes from SnD branch

This commit is contained in:
libraryaddict 2015-10-30 19:25:02 +13:00
parent ed18588a6a
commit ea1e4b79f7
14 changed files with 478 additions and 394 deletions

View File

@ -52,6 +52,7 @@ public class Hologram
private HologramTarget _target = HologramTarget.BLACKLIST;
private int _viewDistance = 70;
protected Vector relativeToEntity;
private boolean _hideBoundingBox;
public Hologram(HologramManager hologramManager, Location location, String... text)
{
@ -77,6 +78,17 @@ public class Hologram
return this;
}
/**
* Warning! Bounding box if hidden will hide holograms for 1.8 to 1.8.2
*
* @return
*/
public Hologram setHideBoundingBox()
{
_hideBoundingBox = true;
return this;
}
/**
* Is there a player entry in the hologram for Whitelist and Blacklist
*/
@ -268,7 +280,7 @@ public class Hologram
packet.a = entityId;
packet.b = 30;
packet.c = (int) (getLocation().getX() * 32);
packet.d = (int) ((getLocation().getY() + -2.1 + ((double) textRow * 0.285)) * 32);
packet.d = (int) ((getLocation().getY() + (_hideBoundingBox ? 0 : -2.1) + ((double) textRow * 0.285)) * 32);
packet.e = (int) (getLocation().getZ() * 32);
packet.l = watcher;
@ -276,7 +288,11 @@ public class Hologram
watcher.a(0, (byte) 32);
watcher.a(2, lineOfText);
watcher.a(3, (byte) 1);
// watcher.a(10, (byte) 16); // TODO Uncomment after we can enforce 1.8.3
if (_hideBoundingBox)
{
watcher.a(10, (byte) 16); // TODO Uncomment after we can enforce 1.8.3
}
// Also correct hologram positioning
return new Packet[]

View File

@ -9,9 +9,11 @@ import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.FireworkEffect;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.FireworkEffectMeta;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.inventory.meta.SkullMeta;
@ -54,8 +56,8 @@ public class ItemBuilder
public ItemBuilder(ItemStack item)
{
this(item.getType(), item.getDurability());
this._amount = item.getAmount();
this._enchants.putAll(item.getEnchantments());
_amount = item.getAmount();
_enchants.putAll(item.getEnchantments());
if (item.getType() == Material.POTION)
{
// setPotion(Potion.fromItemStack(item));
@ -63,19 +65,23 @@ public class ItemBuilder
if (item.hasItemMeta())
{
ItemMeta meta = item.getItemMeta();
if (meta.hasDisplayName())
{
this._title = meta.getDisplayName();
_title = meta.getDisplayName();
}
if (meta.hasLore())
{
this._lore.addAll(meta.getLore());
_lore.addAll(meta.getLore());
}
if (meta instanceof LeatherArmorMeta)
{
this.setColor(((LeatherArmorMeta) meta).getColor());
setColor(((LeatherArmorMeta) meta).getColor());
}
this._unbreakable = meta.spigot().isUnbreakable();
_unbreakable = meta.spigot().isUnbreakable();
}
}
@ -91,9 +97,9 @@ public class ItemBuilder
public ItemBuilder(Material mat, int amount, short data)
{
this._mat = mat;
this._amount = amount;
this._data = data;
_mat = mat;
_amount = amount;
_data = data;
}
public ItemBuilder(Material mat, short data)
@ -115,20 +121,20 @@ public class ItemBuilder
{
for (String lore : lores)
{
this._lore.add(ChatColor.GRAY + lore);
_lore.add(ChatColor.GRAY + lore);
}
return this;
}
public ItemBuilder addLore(String lore, int maxLength)
{
this._lore.addAll(split(lore, maxLength));
_lore.addAll(split(lore, maxLength));
return this;
}
public ItemBuilder addLores(List<String> lores)
{
this._lore.addAll(lores);
_lore.addAll(lores);
return this;
}
@ -148,7 +154,7 @@ public class ItemBuilder
public ItemStack build()
{
Material mat = this._mat;
Material mat = _mat;
if (mat == null)
{
mat = Material.AIR;
@ -158,32 +164,38 @@ public class ItemBuilder
{
Bukkit.getLogger().warning("Air material!");
}
ItemStack item = new ItemStack(mat, this._amount, this._data);
ItemStack item = new ItemStack(mat, _amount, _data);
ItemMeta meta = item.getItemMeta();
if (meta != null)
{
if (this._title != null)
if (_title != null)
{
meta.setDisplayName(this._title);
meta.setDisplayName(_title);
}
if (!this._lore.isEmpty())
if (!_lore.isEmpty())
{
meta.setLore(this._lore);
meta.setLore(_lore);
}
if (meta instanceof LeatherArmorMeta)
if (meta instanceof LeatherArmorMeta && _color != null)
{
((LeatherArmorMeta) meta).setColor(this._color);
((LeatherArmorMeta) meta).setColor(_color);
}
else if (meta instanceof SkullMeta && _playerHeadName != null)
{
((SkullMeta) meta).setOwner(_playerHeadName);
}
else if (meta instanceof FireworkEffectMeta && _color != null)
{
((FireworkEffectMeta) meta).setEffect(FireworkEffect.builder().withColor(_color).build());
}
meta.spigot().setUnbreakable(isUnbreakable());
item.setItemMeta(meta);
}
item.addUnsafeEnchantments(this._enchants);
// if (this.potion != null) {
// this.potion.apply(item);
item.addUnsafeEnchantments(_enchants);
// if (potion != null) {
// potion.apply(item);
// }
return item;
}
@ -191,150 +203,163 @@ public class ItemBuilder
@Override
public ItemBuilder clone()
{
ItemBuilder newBuilder = new ItemBuilder(this._mat);
ItemBuilder newBuilder = new ItemBuilder(_mat);
newBuilder.setTitle(this._title);
for (String lore : this._lore)
newBuilder.setTitle(_title);
for (String lore : _lore)
{
newBuilder.addLore(lore);
}
for (Map.Entry<Enchantment, Integer> entry : this._enchants.entrySet())
for (Map.Entry<Enchantment, Integer> entry : _enchants.entrySet())
{
newBuilder.addEnchantment(entry.getKey(), entry.getValue());
}
newBuilder.setColor(this._color);
// newBuilder.potion = this.potion;
newBuilder.setColor(_color);
// newBuilder.potion = potion;
return newBuilder;
}
public HashMap<Enchantment, Integer> getAllEnchantments()
{
return this._enchants;
return _enchants;
}
public Color getColor()
{
return this._color;
return _color;
}
public short getData()
{
return this._data;
return _data;
}
public int getEnchantmentLevel(Enchantment enchant)
{
return this._enchants.get(enchant);
return _enchants.get(enchant);
}
public List<String> getLore()
{
return this._lore;
return _lore;
}
public String getTitle()
{
return this._title;
return _title;
}
public Material getType()
{
return this._mat;
return _mat;
}
public boolean hasEnchantment(Enchantment enchant)
{
return this._enchants.containsKey(enchant);
return _enchants.containsKey(enchant);
}
public boolean isItem(ItemStack item)
{
ItemMeta meta = item.getItemMeta();
if (item.getType() != this.getType())
if (item.getType() != getType())
{
return false;
}
if (!meta.hasDisplayName() && this.getTitle() != null)
if (!meta.hasDisplayName() && getTitle() != null)
{
return false;
}
if (!meta.getDisplayName().equals(this.getTitle()))
if (!meta.getDisplayName().equals(getTitle()))
{
return false;
}
if (!meta.hasLore() && !this.getLore().isEmpty())
if (!meta.hasLore() && !getLore().isEmpty())
{
return false;
}
if (meta.hasLore())
{
for (String lore : meta.getLore())
{
if (!this.getLore().contains(lore))
if (!getLore().contains(lore))
{
return false;
}
}
}
for (Enchantment enchant : item.getEnchantments().keySet())
{
if (!this.hasEnchantment(enchant))
if (!hasEnchantment(enchant))
{
return false;
}
}
return true;
}
public boolean isUnbreakable()
{
return this._unbreakable;
return _unbreakable;
}
public ItemBuilder setAmount(int amount)
{
this._amount = amount;
_amount = amount;
return this;
}
public ItemBuilder setColor(Color color)
{
if (!this._mat.name().contains("LEATHER_"))
/* (!_mat.name().contains("LEATHER_"))
{
throw new IllegalArgumentException("Can only dye leather armor!");
}
this._color = color;
}*/
_color = color;
return this;
}
public ItemBuilder setData(short newData)
{
this._data = newData;
_data = newData;
return this;
}
public ItemBuilder setPotion(Potion potion)
{
if (this._mat != Material.POTION)
if (_mat != Material.POTION)
{
this._mat = Material.POTION;
_mat = Material.POTION;
}
// this.potion = potion;
return this;
}
public ItemBuilder setRawTitle(String title)
{
this._title = title;
_title = title;
return this;
}
public ItemBuilder setTitle(String title)
{
this._title = (title == null ? null
_title = (title == null ? null
: (title.length() > 2 && ChatColor.getLastColors(title.substring(0, 2)).length() == 0 ? ChatColor.WHITE : ""))
+ title;
return this;
}
@ -343,25 +368,29 @@ public class ItemBuilder
if (title != null && ChatColor.stripColor(title).length() > maxLength)
{
ArrayList<String> lores = split(title, maxLength);
for (int i = 1; i < lores.size(); i++)
{
this._lore.add(lores.get(i));
_lore.add(lores.get(i));
}
title = lores.get(0);
}
setTitle(title);
return this;
}
public ItemBuilder setType(Material mat)
{
this._mat = mat;
_mat = mat;
return this;
}
public ItemBuilder setUnbreakable(boolean setUnbreakable)
{
this._unbreakable = setUnbreakable;return this;
_unbreakable = setUnbreakable;
return this;
}
public ItemBuilder setPlayerHead(String playerName)

View File

@ -148,6 +148,7 @@ public class ProjectileManager extends MiniPlugin
if (cur.isDead() || !cur.isValid())
{
entry.getValue().getIThrown().Idle(entry.getValue());
iterator.remove();
continue;
}

View File

@ -288,6 +288,11 @@ public class ProjectileUser
return false;
}
public IThrown getIThrown()
{
return _callback;
}
public LivingEntity GetThrower()
{
return _thrower;

View File

@ -256,4 +256,25 @@ public class Recharge extends MiniPlugin
_recharge.get(player.getName()).get(ability).debug(player);
}
public void displayExpBar(Player player, String ability)
{
if (!_recharge.containsKey(player.getName()))
{
player.setExp(1F);
return;
}
RechargeData recharge = _recharge.get(player.getName()).get(ability);
if (recharge == null)
{
player.setExp(1F);
return;
}
float elasped = (float) (System.currentTimeMillis() - recharge.Time) / recharge.Recharge;
player.setExp(Math.max(Math.min(1, elasped), 0));
}
}

View File

@ -44,9 +44,9 @@ public class CustomDamageEvent extends Event implements Cancellable
private boolean _damageeBrute = false;
private boolean _damageToLevel = true;
public CustomDamageEvent(LivingEntity damagee, LivingEntity damager, Projectile projectile,
DamageCause cause, double damage, boolean knockback, boolean ignoreRate, boolean ignoreArmor,
String initialSource, String initialReason, boolean cancelled)
public CustomDamageEvent(LivingEntity damagee, LivingEntity damager, Projectile projectile, Location knockbackOrigin,
DamageCause cause, double damage, boolean knockback, boolean ignoreRate, boolean ignoreArmor, String initialSource,
String initialReason, boolean cancelled)
{
_eventCause = cause;
@ -73,6 +73,8 @@ public class CustomDamageEvent extends Event implements Cancellable
if (cancelled)
SetCancelled("Pre-Cancelled");
_knockbackOrigin = knockbackOrigin;
}
@Override

View File

@ -174,10 +174,15 @@ public class DamageManager extends MiniPlugin
DamageCause cause, double damage, boolean knockback, boolean ignoreRate, boolean ignoreArmor,
String source, String reason, boolean cancelled)
{
_plugin.getServer().getPluginManager().callEvent(
new CustomDamageEvent(damagee, damager, proj, cause, damage,
knockback, ignoreRate, ignoreArmor,
source, reason, cancelled));
NewDamageEvent(damagee, damager, proj, null, cause, damage, knockback, ignoreRate, ignoreArmor, source, reason, cancelled);
}
public void NewDamageEvent(LivingEntity damagee, LivingEntity damager, Projectile proj, Location knockbackOrigin,
DamageCause cause, double damage, boolean knockback, boolean ignoreRate, boolean ignoreArmor,
String source, String reason, boolean cancelled)
{
_plugin.getServer().getPluginManager().callEvent(new CustomDamageEvent(damagee, damager, proj, knockbackOrigin, cause,
damage, knockback, ignoreRate, ignoreArmor, source, reason, cancelled));
}
@EventHandler(priority = EventPriority.LOW)
@ -294,7 +299,7 @@ public class DamageManager extends MiniPlugin
if (e.equals(Enchantment.ARROW_KNOCKBACK) || e.equals(Enchantment.KNOCKBACK))
event.AddKnockback("Ench Knockback", 1 + (0.5 * (double)enchants.get(e)));
else if (e.equals(Enchantment.ARROW_DAMAGE))
else if (e.equals(Enchantment.ARROW_DAMAGE) || e.equals(Enchantment.DAMAGE_ALL))
event.AddMod("Enchant", "Ench Damage", 0.5 * (double)enchants.get(e), true);
else if (e.equals(Enchantment.ARROW_FIRE) || e.equals(Enchantment.FIRE_ASPECT))
@ -370,7 +375,7 @@ public class DamageManager extends MiniPlugin
((CraftLivingEntity)event.GetDamageeEntity()).getHandle().o(((CraftLivingEntity)event.GetDamageeEntity()).getHandle().bv() + 1);
//Knockback
if (event.IsKnockback() && event.GetDamagerEntity(true) != null)
if (event.IsKnockback() && (event.getKnockbackOrigin() != null || event.GetDamagerEntity(true) != null))
{
//Base
double knockback = event.GetDamage();
@ -382,9 +387,14 @@ public class DamageManager extends MiniPlugin
knockback = knockback * cur;
//Origin
Location origin = event.GetDamagerEntity(true).getLocation();
Location origin = null;
if (event.GetDamagerEntity(true) != null)
origin = event.GetDamagerEntity(true).getLocation();
if (event.getKnockbackOrigin() != null)
origin = event.getKnockbackOrigin();
else if (event.GetProjectile() != null)
origin = event.GetProjectile().getLocation();
//Vec
Vector trajectory = UtilAlg.getTrajectory2d(origin, event.GetDamageeEntity().getLocation());

View File

@ -87,6 +87,13 @@ public class CustomExplosion extends Explosion
return this;
}
public CustomExplosion setIgnoreNonLiving(boolean ignoreNonLiving)
{
_ignoreNonLiving = ignoreNonLiving;
return this;
}
public CustomExplosion setMaxDamage(float maxDamage)
{
_maxDamage = maxDamage;
@ -240,6 +247,9 @@ public class CustomExplosion extends Explosion
if (entity.getBukkitEntity() == _owner && !_damageOwner)
continue;
if (!(entity.getBukkitEntity() instanceof LivingEntity) && _ignoreNonLiving)
continue;
double d7 = entity.f(this.posX, this.posY, this.posZ) / this._size; // XXX
if (d7 <= 1.0D)
@ -272,8 +282,8 @@ public class CustomExplosion extends Explosion
if (entity.getBukkitEntity() instanceof LivingEntity)
{
_manager.NewDamageEvent((LivingEntity) entity.getBukkitEntity(), _owner, null,
DamageCause.ENTITY_EXPLOSION, damage, true, _ignoreRate, false, _damageReason, _damageReason);
_manager.NewDamageEvent((LivingEntity) entity.getBukkitEntity(), _owner, null, new Location(_world.getWorld(), posX, posY, posZ),
DamageCause.ENTITY_EXPLOSION, damage, true, _ignoreRate, false, _damageReason, _damageReason, false);
}
else
{

View File

@ -657,7 +657,10 @@ public abstract class Game implements Listener
HandlerList.unregisterAll(kit);
for (Perk perk : kit.GetPerks())
{
HandlerList.unregisterAll(perk);
perk.unregisteredEvents();
}
}
}

View File

@ -214,7 +214,7 @@ public class KitKnight extends SmashKit
Horse horse = (Horse)damagee.getVehicle();
//Damage Event
CustomDamageEvent newEvent = new CustomDamageEvent(horse, event.GetDamagerEntity(true), event.GetProjectile(),
CustomDamageEvent newEvent = new CustomDamageEvent(horse, event.GetDamagerEntity(true), event.GetProjectile(), null,
event.GetCause(), event.GetDamageInitial(), true, false, false,
UtilEnt.getName(event.GetDamagerPlayer(true)), event.GetReason(), false);
@ -246,7 +246,7 @@ public class KitKnight extends SmashKit
Player player = (Player)horse.getPassenger();
//Damage Event
final CustomDamageEvent newEvent = new CustomDamageEvent(player, event.GetDamagerEntity(true), event.GetProjectile(),
final CustomDamageEvent newEvent = new CustomDamageEvent(player, event.GetDamagerEntity(true), event.GetProjectile(), null,
event.GetCause(), event.GetDamageInitial(), true, false, false,
UtilEnt.getName(event.GetDamagerPlayer(true)), event.GetReason(), false);

View File

@ -153,7 +153,7 @@ public class SnowFight extends TeamGame
{
if(IsOnIce(player))
{
Bukkit.getPluginManager().callEvent(new CustomDamageEvent(player, null, null, DamageCause.CUSTOM, 2.0D, false, true, true, "Ice", "Ice", false));
Bukkit.getPluginManager().callEvent(new CustomDamageEvent(player, null, null, null, DamageCause.CUSTOM, 2.0D, false, true, true, "Ice", "Ice", false));
}
}
@ -510,7 +510,7 @@ public class SnowFight extends TeamGame
if(player instanceof Player)
{
Player damagee = (Player) player;
Bukkit.getPluginManager().callEvent(new CustomDamageEvent(damagee, null, null, DamageCause.CUSTOM, damage, false, true, true, "Ice Meteoroid", "Ice Meteoroid", false));
Bukkit.getPluginManager().callEvent(new CustomDamageEvent(damagee, null, null, null, DamageCause.CUSTOM, damage, false, true, true, "Ice Meteoroid", "Ice Meteoroid", false));
}
}

View File

@ -59,4 +59,9 @@ public abstract class Perk implements Listener
{
// When listener has been registered
}
public void unregisteredEvents()
{
// When listener has been registered
}
}

View File

@ -121,6 +121,15 @@ public class PerkZombieBile extends SmashPerk implements IThrown
}
}
@EventHandler
public void death(PlayerDeathEvent event)
{
if (_active.containsKey(event.getEntity()))
{
_active.remove(event.getEntity());
}
}
@Override
public void Collide(LivingEntity target, Block block, ProjectileUser data)
{

View File

@ -1,13 +1,8 @@
package nautilus.game.arcade.scoreboard;
import java.util.ArrayList;
import java.util.HashSet;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilTime.TimeUnit;
import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.GameTeam;
@ -16,6 +11,7 @@ import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Score;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team;
@ -27,7 +23,7 @@ public class GameScoreboard
private Objective _sideObjective;
private ArrayList<ScoreboardElement> _elements = new ArrayList<ScoreboardElement>();
private String[] _current = new String[15];
private char[] _chars = "1234567890abcdefghijklmnopqrstuvwxyz".toCharArray();
private String _title;
private int _shineIndex;
@ -251,79 +247,56 @@ public class GameScoreboard
for (ScoreboardElement elem : _elements)
{
for (String line : elem.GetLines())
{
//Ensure no duplicate lines
newLines.addAll(elem.GetLines());
}
int i = 0;
while (true)
{
boolean matched = false;
if (i >= _chars.length)
break;
for (String otherLine : newLines)
{
if (line.equals(otherLine))
{
line += ChatColor.RESET;
matched = true;
}
}
String str = ChatColor.COLOR_CHAR + "" + _chars[i];
if (!matched)
Score score = GetObjectiveSide().getScore(str);
if (newLines.size() <= i)
{
if (score.isScoreSet())
{
ResetScore(str);
}
else
{
break;
}
newLines.add(line);
}
}
//Find Changes
HashSet<Integer> toAdd = new HashSet<Integer>();
HashSet<Integer> toDelete = new HashSet<Integer>();
for (int i=0 ; i<15 ; i++)
else
{
//Delete Old Excess Row
if (i >= newLines.size())
Team team = GetScoreboard().getTeam(str);
if (team == null)
{
if (_current[i] != null)
{
if (_debug) System.out.println("Delete: " + i + " [" + _current[i] + "]");
toDelete.add(i);
team = GetScoreboard().registerNewTeam(str);
team.addEntry(str);
}
continue;
String line = newLines.get(i);
team.setPrefix(line);
if (!score.isScoreSet())
{
if (i == 15)
{
score.setScore(1);
}
//Update or Add Row
if (_current[i] == null || !_current[i].equals(newLines.get(i)))
{
if (_debug) System.out.println("Update: " + i + " [" + newLines.get(i) + "]");
toDelete.add(i);
toAdd.add(i);
score.setScore(15 - i);
}
}
//Delete Elements - Must happen before Add
for (int i : toDelete)
{
//Remove Old Line at Index
if (_current[i] != null)
{
if (_debug) System.out.println("Deleting: " + i + " [" + _current[i] + "]");
ResetScore(_current[i]);
_current[i] = null;
}
}
//Add Elements
for (int i : toAdd)
{
//Insert New Line
String newLine = newLines.get(i);
GetObjectiveSide().getScore(newLine).setScore(15-i);
_current[i] = newLine;
if (_debug) System.out.println("Setting: " + (15-i) + " [" + newLine + "]");
i++;
}
}