Proxy limit fixes

This commit is contained in:
Cheese 2015-11-21 09:28:15 +11:00
parent 386032a4f5
commit 0bc64fec16
16 changed files with 226 additions and 190 deletions

View File

@ -166,7 +166,7 @@ public class Hub extends JavaPlugin implements IRelation
energy.setEnabled(false);
ItemFactory itemFactory = new ItemFactory(this, blockRestore, conditionManager, damage, energy, fire, throwManager, webServerAddress);
SkillFactory skillManager = new SkillFactory(this, damage, this, combatManager, conditionManager, throwManager, disguiseManager, blockRestore, itemFactory.ThrownManager, fire, new Movement(this), teleport, energy, webServerAddress);
SkillFactory skillManager = new SkillFactory(this, damage, this, combatManager, conditionManager, throwManager, disguiseManager, blockRestore, fire, new Movement(this), teleport, energy, webServerAddress);
ClassManager classManager = new ClassManager(this, clientManager, donationManager, hubManager.GetGadget(), skillManager, itemFactory, webServerAddress);
ClassShopManager shopManager = new ClassShopManager(this, classManager, skillManager, itemFactory, achievementManager, clientManager);

View File

@ -315,6 +315,11 @@ public class ClassManager extends MiniClientPlugin<ClientClass> implements IClas
{
return _skillFactory;
}
public ItemFactory GetItemFactory()
{
return _itemFactory;
}
@Override
protected ClientClass AddPlayer(String player)

View File

@ -18,18 +18,12 @@ import mineplex.core.common.util.F;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.projectile.IThrown;
import mineplex.core.projectile.ProjectileUser;
import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.minecraft.game.classcombat.Skill.SkillActive;
import mineplex.minecraft.game.classcombat.Skill.SkillFactory;
import mineplex.minecraft.game.classcombat.item.Throwable.ThrownManager.ThrowableType;
import mineplex.minecraft.game.core.condition.Condition;
import mineplex.minecraft.game.core.condition.Condition.ConditionType;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import org.bukkit.event.player.*;
@ -115,8 +109,6 @@ public class LightningOrb extends SkillActive implements IThrown
//Effect
item.getWorld().playSound(item.getLocation(), Sound.SILVERFISH_HIT, 2f, 1f);
Factory.ThrownManager.throwProjectile(player, ThrowableType.ORB, item);
}
@Override

View File

@ -98,7 +98,7 @@ import mineplex.minecraft.game.classcombat.Skill.Ranger.WolfsFury;
import mineplex.minecraft.game.classcombat.Skill.Ranger.WolfsPounce;
import mineplex.minecraft.game.classcombat.Skill.repository.SkillRepository;
import mineplex.minecraft.game.classcombat.Skill.repository.token.SkillToken;
import mineplex.minecraft.game.classcombat.item.Throwable.ThrownManager;
import mineplex.minecraft.game.classcombat.item.Throwable.ProximityManager;
import mineplex.minecraft.game.core.IRelation;
import mineplex.minecraft.game.core.combat.CombatManager;
import mineplex.minecraft.game.core.condition.ConditionManager;
@ -120,7 +120,6 @@ public class SkillFactory extends MiniPlugin implements ISkillFactory
private ProjectileManager _projectileManager;
private DisguiseManager _disguiseManager;
private BlockRestore _blockRestore;
public ThrownManager ThrownManager;
private Fire _fire;
private Movement _movement;
private Teleport _teleport;
@ -131,7 +130,7 @@ public class SkillFactory extends MiniPlugin implements ISkillFactory
public SkillFactory(JavaPlugin plugin, DamageManager damageManager, IRelation relation,
CombatManager combatManager, ConditionManager conditionManager, ProjectileManager projectileManager, DisguiseManager disguiseManager,
BlockRestore blockRestore, ThrownManager thrownManager, Fire fire, Movement movement, Teleport teleport, Energy energy, String webAddress)
BlockRestore blockRestore, Fire fire, Movement movement, Teleport teleport, Energy energy, String webAddress)
{
super("Skill Factory", plugin);
@ -143,7 +142,6 @@ public class SkillFactory extends MiniPlugin implements ISkillFactory
_projectileManager = projectileManager;
_blockRestore = blockRestore;
_disguiseManager = disguiseManager;
ThrownManager = thrownManager;
_fire = fire;
_movement = movement;
_teleport = teleport;

View File

@ -28,7 +28,7 @@ public class ItemFactory extends MiniPlugin implements IItemFactory
private Energy _energy;
private Fire _fire;
private ProjectileManager _projectileManager;
public ThrownManager ThrownManager;
private ProximityManager _proxyManager;
private java.lang.reflect.Field _itemMaxDurability;
private HashMap<String, Item> _items;
private HashSet<String> _ignore;
@ -48,7 +48,7 @@ public class ItemFactory extends MiniPlugin implements IItemFactory
_energy = energy;
_fire = fire;
_projectileManager = projectileManager;
ThrownManager = new ThrownManager(projectileManager);
_proxyManager = new ProximityManager();
_items = new HashMap<String, Item>();
_ignore = ignore;
@ -243,7 +243,7 @@ public class ItemFactory extends MiniPlugin implements IItemFactory
for (Item item : _items.values())
registerEvents(item);
registerEvents(ThrownManager);
registerEvents(_proxyManager);
}
@Override
@ -254,6 +254,11 @@ public class ItemFactory extends MiniPlugin implements IItemFactory
for (Item item : _items.values())
HandlerList.unregisterAll(item);
HandlerList.unregisterAll(ThrownManager);
HandlerList.unregisterAll(_proxyManager);
}
public ProximityManager getProximityManager()
{
return _proxyManager;
}
}

View File

@ -10,9 +10,6 @@ import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.projectile.IThrown;
import mineplex.core.projectile.ProjectileUser;
import mineplex.core.recharge.Recharge;
import mineplex.minecraft.game.classcombat.item.Throwable.ProximityExplosive;
import mineplex.minecraft.game.classcombat.item.Throwable.ProximityZapper;
import mineplex.minecraft.game.classcombat.item.Throwable.ThrownManager.ThrowableType;
import mineplex.minecraft.game.classcombat.item.event.ItemTriggerEvent;
import org.bukkit.Bukkit;
@ -162,15 +159,6 @@ public abstract class ItemUsable extends Item implements IThrown
UtilAction.velocity(ent, player.getLocation().getDirection(), _throwPower, false, 0, 0.2, 10, false);
Factory.Throw().AddThrow(ent, player, this, expire, _throwPlayer, _throwPlayer, _throwBlock, _throwIdle, _throwPickup, 0.5f);
if (this instanceof ProximityZapper)
{
Factory.ThrownManager.throwProjectile(player, ThrowableType.ZAPPER, ent);
}
else if (this instanceof ProximityExplosive)
{
Factory.ThrownManager.throwProjectile(player, ThrowableType.EXPLOSIVE, ent);
}
ThrowCustom(event, ent);
}

View File

@ -3,8 +3,8 @@ package mineplex.minecraft.game.classcombat.item.Throwable;
import java.util.HashMap;
import java.util.HashSet;
import org.bukkit.Bukkit;
import org.bukkit.Effect;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
@ -34,6 +34,7 @@ import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.minecraft.game.classcombat.item.ItemFactory;
import mineplex.minecraft.game.classcombat.item.ItemUsable;
import mineplex.minecraft.game.classcombat.item.event.ProximityUseEvent;
public class ProximityExplosive extends ItemUsable
{
@ -63,7 +64,14 @@ public class ProximityExplosive extends ItemUsable
@Override
public void UseAction(PlayerInteractEvent event)
{
}
@Override
public void ThrowCustom(PlayerInteractEvent event, org.bukkit.entity.Item ent)
{
ProximityUseEvent useEvent = new ProximityUseEvent(event.getPlayer(), this, ent);
Bukkit.getServer().getPluginManager().callEvent(useEvent);
}
@Override

View File

@ -0,0 +1,104 @@
package mineplex.minecraft.game.classcombat.item.Throwable;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.classcombat.item.event.ProximityUseEvent;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
public class ProximityManager implements Listener
{
private int _proxyLimit = 6;
private HashMap<Player, ArrayList<Entry<String, Entity>>> _proxyMap = new HashMap<Player, ArrayList<Entry<String, Entity>>>();
public void setProxyLimit(int limit)
{
_proxyLimit = limit;
}
@EventHandler(priority = EventPriority.HIGHEST)
public void proximityThrownEvent(ProximityUseEvent event)
{
//Don't bother if the proxy has been disallowed
if (!event.getEntity().isValid())
return;
if (!_proxyMap.containsKey(event.getPlayer()))
_proxyMap.put(event.getPlayer(), new ArrayList<Entry<String,Entity>>());
ArrayList<Entry<String, Entity>> proxies = _proxyMap.get(event.getPlayer());
//Store New
proxies.add(new AbstractMap.SimpleEntry<String, Entity>(event.getItemType().GetName(), event.getEntity()));
//Clean Excess
while (proxies.size() > _proxyLimit)
{
Entry<String, Entity> entry = proxies.remove(0);
UtilPlayer.message(event.getPlayer(), F.main("Game", "Your old " + entry.getKey() + " was removed. Limit of " + _proxyLimit + "."));
entry.getValue().remove();
}
}
@EventHandler
public void clean(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST)
return;
clean(null, 0);
}
public void clean(Location loc, int radius)
{
Iterator<Player> playerIter = _proxyMap.keySet().iterator();
while (playerIter.hasNext())
{
Player player = playerIter.next();
//Clean Offline Players
if (!player.isOnline())
{
playerIter.remove();
continue;
}
ArrayList<Entry<String,Entity>> proxies = _proxyMap.get(player);
Iterator<Entry<String,Entity>> proxyIter = proxies.iterator();
//Clean Dead Proxies
while (proxyIter.hasNext())
{
Entry<String,Entity> proxy = proxyIter.next();
if (!proxy.getValue().isValid() || //Dead
(loc != null && UtilMath.offset(proxy.getValue().getLocation(), loc) < radius)) //Around Radius
{
proxy.getValue().remove();
proxyIter.remove();
}
}
//Clean Empty Entries
if (proxies.isEmpty())
playerIter.remove();
}
}
}

View File

@ -3,6 +3,7 @@ package mineplex.minecraft.game.classcombat.item.Throwable;
import java.util.HashMap;
import java.util.HashSet;
import org.bukkit.Bukkit;
import org.bukkit.Effect;
import org.bukkit.GameMode;
import org.bukkit.Material;
@ -31,6 +32,7 @@ import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilEvent.ActionType;
import mineplex.minecraft.game.classcombat.item.ItemFactory;
import mineplex.minecraft.game.classcombat.item.ItemUsable;
import mineplex.minecraft.game.classcombat.item.event.ProximityUseEvent;
public class ProximityZapper extends ItemUsable
{
@ -62,6 +64,13 @@ public class ProximityZapper extends ItemUsable
{
}
@Override
public void ThrowCustom(PlayerInteractEvent event, org.bukkit.entity.Item ent)
{
ProximityUseEvent useEvent = new ProximityUseEvent(event.getPlayer(), this, ent);
Bukkit.getServer().getPluginManager().callEvent(useEvent);
}
@Override
public void Collide(LivingEntity target, Block block, ProjectileUser data)

View File

@ -1,114 +0,0 @@
package mineplex.minecraft.game.classcombat.item.Throwable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.projectile.ProjectileManager;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
public class ThrownManager implements Listener
{
private ConcurrentHashMap<Player, ConcurrentHashMap<ThrowableType, List<Entity>>> _thrown;
private ProjectileManager _projectile;
public ThrownManager(ProjectileManager projectile)
{
_projectile = projectile;
_thrown = new ConcurrentHashMap<Player, ConcurrentHashMap<ThrowableType, List<Entity>>>();
}
public void throwProjectile(Player player, ThrowableType type, Entity thrown)
{
ConcurrentHashMap<ThrowableType, List<Entity>> cmap;
if (_thrown.containsKey(player))
cmap = _thrown.get(player);
else
cmap = new ConcurrentHashMap<ThrowableType, List<Entity>>();
List<Entity> lent;
if (cmap.containsKey(type))
lent = cmap.get(type);
else
lent = new ArrayList<Entity>();
if (lent.size() >= 3)
{
_projectile.deleteThrown(lent.remove(0));
String message = "";
switch (type)
{
case EXPLOSIVE:
message = F.main("Game", "Your old Proximity Explosive was removed.");
break;
case ORB:
message = F.main("Game", "Your old Lightning Orb was removed.");
break;
case ZAPPER:
message = F.main("Game", "Your old Proximity Zapper was removed.");
break;
default:
break;
}
UtilPlayer.message(player, message);
}
lent.add(thrown);
cmap.put(type, lent);
_thrown.put(player, cmap);
}
public boolean isThrown(Entity e)
{
for (Player player : _thrown.keySet())
{
ConcurrentHashMap<ThrowableType, List<Entity>> cmap = _thrown.get(player);
for (ThrowableType type : cmap.keySet())
{
List<Entity> lent = cmap.get(type);
if (lent.contains(e))
return true;
}
}
return false;
}
@EventHandler
public void refresh(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST)
return;
for (Player player : _thrown.keySet())
{
ConcurrentHashMap<ThrowableType, List<Entity>> cmap = _thrown.get(player);
for (ThrowableType type : cmap.keySet())
{
List<Entity> lent = cmap.get(type);
Iterator<Entity> ient = lent.iterator();
for (Entity e = ient.next(); ient.hasNext();)
{
if (e.isDead() || !e.isValid())
lent.remove(e);
}
cmap.put(type, lent);
}
_thrown.put(player, cmap);
}
}
public enum ThrowableType
{
EXPLOSIVE, ZAPPER, ORB
}
}

View File

@ -0,0 +1,48 @@
package mineplex.minecraft.game.classcombat.item.event;
import mineplex.minecraft.game.classcombat.item.Item;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class ProximityUseEvent extends Event
{
private static final HandlerList handlers = new HandlerList();
private Player _player;
private Item _item;
private org.bukkit.entity.Item _entity;
public ProximityUseEvent(Player player, Item item, org.bukkit.entity.Item ent)
{
_player = player;
_item = item;
_entity = ent;
}
public HandlerList getHandlers()
{
return handlers;
}
public static HandlerList getHandlerList()
{
return handlers;
}
public Player getPlayer()
{
return _player;
}
public Item getItemType()
{
return _item;
}
public org.bukkit.entity.Item getEntity()
{
return _entity;
}
}

View File

@ -312,7 +312,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
_fire, _projectileManager, webAddress);
_skillFactory = new SkillFactory(plugin, damageManager, this, _damageManager.GetCombatManager(),
_conditionManager, _projectileManager, _disguiseManager, _blockRestore, _itemFactory.ThrownManager, _fire, new Movement(plugin), teleport,
_conditionManager, _projectileManager, _disguiseManager, _blockRestore, _fire, new Movement(plugin), teleport,
_energy, webAddress);
_classManager = new ClassManager(plugin, clientManager, donationManager, _cosmeticManager.getGadgetManager(), _skillFactory, _itemFactory,

View File

@ -1,7 +1,9 @@
package nautilus.game.arcade.game.games.champions;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.inventory.data.Item;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.combat.DeathMessageType;
@ -24,6 +26,8 @@ import nautilus.game.arcade.stats.SeismicSlamStatTracker;
import nautilus.game.arcade.stats.SpecialWinStatTracker;
import nautilus.game.arcade.stats.TheLongestShotStatTracker;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -60,6 +64,8 @@ public class ChampionsCTF extends CaptureTheFlag
Manager.GetDamage().UseSimpleWeaponDamage = false;
Manager.getCosmeticManager().setHideParticles(true);
Manager.getClassManager().GetItemFactory().getProximityManager().setProxyLimit(3);
this.StrictAntiHack = true;
InventoryOpenChest = true;
@ -81,7 +87,7 @@ public class ChampionsCTF extends CaptureTheFlag
new SpecialWinStatTracker(this, "SpecialWin")
);
new ChampsFixer(this);
new ChampionsFixes(this);
}
@Override
@ -142,4 +148,19 @@ public class ChampionsCTF extends CaptureTheFlag
}
}
}
@EventHandler
public void cleanProximities(UpdateEvent event)
{
if (!IsLive())
return;
if (event.getType() != UpdateType.FAST)
return;
for (Location loc : getLocations(true))
{
Manager.getClassManager().GetItemFactory().getProximityManager().clean(loc, 12);
}
}
}

View File

@ -59,6 +59,8 @@ public class ChampionsDominate extends Domination
Manager.GetDamage().UseSimpleWeaponDamage = false;
Manager.getCosmeticManager().setHideParticles(true);
Manager.getClassManager().GetItemFactory().getProximityManager().setProxyLimit(6);
this.StrictAntiHack = true;
InventoryOpenChest = true;
@ -77,7 +79,7 @@ public class ChampionsDominate extends Domination
new SeismicSlamStatTracker(this)
);
new ChampsFixer(this);
new ChampionsFixes(this);
}
@Override

View File

@ -3,6 +3,7 @@ package nautilus.game.arcade.game.games.champions;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilServer;
import mineplex.core.inventory.data.Item;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.classcombat.Skill.Skill;
import nautilus.game.arcade.events.GameStateChangeEvent;
@ -22,11 +23,11 @@ import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryType;
public class ChampsFixer implements Listener
public class ChampionsFixes implements Listener
{
private Game _host;
public ChampsFixer(Game game)
public ChampionsFixes(Game game)
{
_host = game;
Bukkit.getPluginManager().registerEvents(this, _host.getArcadeManager().getPlugin());
@ -38,7 +39,7 @@ public class ChampsFixer implements Listener
if (event.GetGame() != _host)
return;
if (event.GetState() == GameState.Dead)
if (event.GetState() == GameState.End || event.GetState() == GameState.Dead)
HandlerList.unregisterAll(this);
}
@ -55,7 +56,7 @@ public class ChampsFixer implements Listener
return;
event.setCancelled(true);
event.setCancelMessage("You cannot change kits while holding someone in Dwarf Toss!");
event.setCancelMessage("You cannot change kits while using Dwarf Toss!");
}
@EventHandler(priority = EventPriority.HIGHEST)
@ -71,11 +72,14 @@ public class ChampsFixer implements Listener
}
@EventHandler
public void onUpdate(UpdateEvent event)
public void resetSkillsWhileInInventory(UpdateEvent event)
{
if (!_host.IsLive())
return;
if (event.getType() != UpdateType.FAST)
return;
for (Player player : UtilServer.getPlayers())
{
if (player.getOpenInventory() == null || player.getOpenInventory().getTopInventory() == null)
@ -101,40 +105,4 @@ public class ChampsFixer implements Listener
{
event.setCancelled(true);
}
@EventHandler
public void fixThrown(UpdateEvent event)
{
if (!(_host instanceof ChampionsCTF))
return;
if (!_host.IsLive())
return;
ChampionsCTF game = (ChampionsCTF) _host;
for (Location loc : game.getLocations(true))
{
for (Entity e : UtilEnt.getAllInRadius(loc, 12).keySet())
{
if (e instanceof Item)
{
if (_host.getArcadeManager().getClassManager().GetSkillFactory().ThrownManager.isThrown(e))
_host.getArcadeManager().GetProjectile().deleteThrown(e);
}
}
}
for (Location loc : game.getLocations(false))
{
for (Entity e : UtilEnt.getAllInRadius(loc, 12).keySet())
{
if (e instanceof Item)
{
if (_host.getArcadeManager().getClassManager().GetSkillFactory().ThrownManager.isThrown(e))
_host.getArcadeManager().GetProjectile().deleteThrown(e);
}
}
}
}
}

View File

@ -59,6 +59,8 @@ public class ChampionsTDM extends TeamDeathmatch
this.Manager.GetDamage().UseSimpleWeaponDamage = false;
Manager.getCosmeticManager().setHideParticles(true);
Manager.getClassManager().GetItemFactory().getProximityManager().setProxyLimit(6);
this.StrictAntiHack = true;
@ -77,7 +79,7 @@ public class ChampionsTDM extends TeamDeathmatch
new SeismicSlamStatTracker(this)
);
new ChampsFixer(this);
new ChampionsFixes(this);
}
@Override