Fixed invisibility bug

This commit is contained in:
Cheese 2015-03-13 11:34:45 +11:00
parent 3ceb0ff678
commit c5d48a82a3
17 changed files with 206 additions and 139 deletions

View File

@ -49,6 +49,7 @@ import mineplex.core.packethandler.PacketInfo;
import mineplex.core.timing.TimingManager;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.visibility.VisibilityManager;
public class DisguiseManager extends MiniPlugin implements IPacketHandler
{
@ -130,8 +131,8 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
if (disguise.GetEntity() instanceof EntityPlayer)
{
player.hidePlayer(Bukkit.getPlayer(disguise.GetEntity().getName()));
player.showPlayer(Bukkit.getPlayer(disguise.GetEntity().getName()));
VisibilityManager.Instance.setVisibility(Bukkit.getPlayer(disguise.GetEntity().getName()), false, player);
VisibilityManager.Instance.setVisibility(Bukkit.getPlayer(disguise.GetEntity().getName()), true, player);
}
else
{

View File

@ -11,6 +11,7 @@ import mineplex.core.common.util.UtilServer;
import mineplex.core.disguise.disguises.DisguiseSkeleton;
import mineplex.core.gadget.GadgetManager;
import mineplex.core.gadget.types.MorphGadget;
import mineplex.core.visibility.VisibilityManager;
public class MorphPumpkinKing extends MorphGadget
{
@ -43,17 +44,8 @@ public class MorphPumpkinKing extends MorphGadget
player.getInventory().setHelmet(new ItemStack(Material.JACK_O_LANTERN));
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Manager.getPlugin(), new Runnable()
{
public void run()
{
for (Player other : UtilServer.getPlayers())
{
other.hidePlayer(player);
other.showPlayer(player);
}
}
}, 0);
VisibilityManager.Instance.setVisibility(player, false, UtilServer.getPlayers());
VisibilityManager.Instance.setVisibility(player, true, UtilServer.getPlayers());
}
@Override

View File

@ -0,0 +1,66 @@
package mineplex.core.visibility;
import java.util.Iterator;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.recharge.Recharge;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
import org.bukkit.entity.Player;
public class VisibilityData
{
private NautHashMap<Player, Boolean> _shouldHide = new NautHashMap<Player, Boolean>();
public void updatePlayer(Player player, Player target, boolean hide)
{
if (attemptToProcess(player, target, hide))
{
//Clear old
_shouldHide.remove(target);
}
else
{
//Store
_shouldHide.put(target, hide);
}
}
//Process New
private boolean attemptToProcess(Player player, Player target, boolean hide)
{
if (Recharge.Instance.use(player, "VIS " + target.getName(), 250, false, false))
{
//Use craftplayer because i recall jon added something where
//it would still send the packet, even if the client thought it was already the state.
if (hide)
((CraftPlayer)player).hidePlayer(target);
else
((CraftPlayer)player).showPlayer(target);
return true;
}
return false;
}
//Process Update
public void attemptToProcessUpdate(Player player)
{
Iterator<Player> targetIter = _shouldHide.keySet().iterator();
while (targetIter.hasNext())
{
Player target = targetIter.next();
boolean hide = _shouldHide.get(target);
if (attemptToProcess(player, target, hide))
{
targetIter.remove();
}
}
}
}

View File

@ -0,0 +1,87 @@
package mineplex.core.visibility;
import java.util.Iterator;
import mineplex.core.MiniPlugin;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilServer;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;
public class VisibilityManager extends MiniPlugin
{
public static VisibilityManager Instance;
private NautHashMap<Player, VisibilityData> _data = new NautHashMap<Player, VisibilityData>();
protected VisibilityManager(JavaPlugin plugin)
{
super("Visibility Manager", plugin);
}
public static void Initialize(JavaPlugin plugin)
{
Instance = new VisibilityManager(plugin);
}
public VisibilityData getDataFor(Player player)
{
if (!_data.containsKey(player))
_data.put(player, new VisibilityData());
return _data.get(player);
}
public void setVisibility(Player target, boolean isVisible, Player... viewers)
{
for (Player player : viewers)
{
if (player.equals(target))
continue;
getDataFor(player).updatePlayer(player, target, !isVisible);
}
}
public void refreshPlayerToAll(Player player)
{
setVisibility(player, false, UtilServer.getPlayers());
setVisibility(player, true, UtilServer.getPlayers());
}
@EventHandler
public void update(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
Iterator<Player> playerIter = _data.keySet().iterator();
while (playerIter.hasNext())
{
Player player = playerIter.next();
if (!player.isOnline() || !player.isValid())
{
playerIter.remove();
continue;
}
VisibilityData data = _data.get(player);
data.attemptToProcessUpdate(player);
}
}
@EventHandler
public void quit(PlayerQuitEvent event)
{
_data.remove(event.getPlayer());
}
}

View File

@ -42,6 +42,7 @@ import mineplex.core.task.TaskManager;
import mineplex.core.teleport.Teleport;
import mineplex.core.updater.FileUpdater;
import mineplex.core.updater.Updater;
import mineplex.core.visibility.VisibilityManager;
import mineplex.hub.modules.StackerManager;
import mineplex.hub.poll.PollManager;
import mineplex.hub.queue.QueueManager;
@ -80,6 +81,7 @@ public class Hub extends JavaPlugin implements IRelation
ItemStackFactory.Initialize(this, false);
Recharge.Initialize(this);
VisibilityManager.Initialize(this);
Punish punish = new Punish(this, webServerAddress, clientManager);
BlockRestore blockRestore = new BlockRestore(this);
DonationManager donationManager = new DonationManager(this, clientManager, webServerAddress);

View File

@ -91,7 +91,7 @@ import mineplex.hub.modules.NewsManager;
import mineplex.hub.modules.ParkourManager;
import mineplex.hub.modules.TextManager;
import mineplex.hub.modules.UHCManager;
import mineplex.hub.modules.VisibilityManager;
import mineplex.hub.modules.HubVisibilityManager;
import mineplex.hub.modules.WorldManager;
import mineplex.hub.poll.PollManager;
import mineplex.hub.tutorial.TutorialManager;
@ -116,7 +116,7 @@ public class HubManager extends MiniClientPlugin<HubClient>
private StatsManager _statsManager;
private GadgetManager _gadgetManager;
private MountManager _mountManager;
private VisibilityManager _visibilityManager;
private HubVisibilityManager _visibilityManager;
private TutorialManager _tutorialManager;
private TextManager _textCreator;
private ParkourManager _parkour;
@ -183,7 +183,7 @@ public class HubManager extends MiniClientPlugin<HubClient>
_partyManager = partyManager;
_preferences = preferences;
_tutorialManager = new TutorialManager(this, donationManager, taskManager, _textCreator);
_visibilityManager = new VisibilityManager(this);
_visibilityManager = new HubVisibilityManager(this);
_forcefieldManager = new ForcefieldManager(this);
addCommand(new ForcefieldRadius(_forcefieldManager));
@ -909,7 +909,7 @@ public class HubManager extends MiniClientPlugin<HubClient>
return _statsManager;
}
public VisibilityManager GetVisibility()
public HubVisibilityManager GetVisibility()
{
return _visibilityManager;
}

View File

@ -20,16 +20,17 @@ import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilServer;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.visibility.VisibilityManager;
import mineplex.hub.HubManager;
public class VisibilityManager extends MiniPlugin
public class HubVisibilityManager extends MiniPlugin
{
public HubManager Manager;
private HashMap<Player, Integer> _particle = new HashMap<Player, Integer>();
private HashSet<Player> _hiddenPlayers = new HashSet<Player>();
public VisibilityManager(HubManager manager)
public HubVisibilityManager(HubManager manager)
{
super("Visibility Manager", manager.getPlugin());
@ -71,11 +72,11 @@ public class VisibilityManager extends MiniPlugin
if (hideMe || !Manager.getPreferences().Get(other).ShowPlayers || UtilMath.offset2d(player.getLocation(), Manager.GetSpawn()) == 0 ||
Manager.GetTutorial().InTutorial(other) || Manager.GetTutorial().InTutorial(player))
{
((CraftPlayer)other).hidePlayer(player, true, false);
VisibilityManager.Instance.setVisibility(player, false, other);
}
else
{
other.showPlayer(player);
VisibilityManager.Instance.setVisibility(player, true, other);
}
}
}

View File

@ -4,6 +4,7 @@ import mineplex.minecraft.game.core.condition.Condition.ConditionType;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.updater.UpdateType;
import mineplex.core.visibility.VisibilityManager;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilTime;
@ -18,7 +19,6 @@ import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityTargetEvent;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
public class ConditionEffect implements Listener
@ -81,14 +81,20 @@ public class ConditionEffect implements Listener
//Hide
if (Manager.IsCloaked(ent))
for (Player other : Bukkit.getServer().getOnlinePlayers())
((CraftPlayer)other).hidePlayer(player, true, false);
//Show
else
{
for (Player other : Bukkit.getServer().getOnlinePlayers())
{
other.showPlayer(player);
VisibilityManager.Instance.setVisibility(player, false, other);
}
}
//Show
else
{
for (Player other : Bukkit.getServer().getOnlinePlayers())
{
VisibilityManager.Instance.setVisibility(player, true, other);
}
}
}
}

View File

@ -6,6 +6,8 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import mineplex.core.common.util.UtilServer;
import mineplex.core.visibility.VisibilityManager;
import mineplex.minecraft.game.core.condition.Condition;
import mineplex.minecraft.game.core.condition.ConditionManager;
@ -30,10 +32,7 @@ public class Cloak extends Condition
if (!(_ent instanceof Player))
return;
for (Player other : _ent.getServer().getOnlinePlayers())
{
other.hidePlayer((Player)_ent);
}
VisibilityManager.Instance.setVisibility((Player)_ent, false, UtilServer.getPlayers());
for (Entity ent : _ent.getWorld().getEntities())
{
@ -54,10 +53,6 @@ public class Cloak extends Condition
{
super.Remove();
for (Player other : _ent.getServer().getOnlinePlayers())
{
//other.hidePlayer((Player)_ent);
other.showPlayer((Player)_ent);
}
VisibilityManager.Instance.setVisibility((Player)_ent, true, UtilServer.getPlayers());
}
}

View File

@ -44,6 +44,7 @@ import mineplex.core.status.ServerStatusManager;
import mineplex.core.teleport.Teleport;
import mineplex.core.updater.FileUpdater;
import mineplex.core.updater.Updater;
import mineplex.core.visibility.VisibilityManager;
import mineplex.minecraft.game.core.combat.CombatManager;
import mineplex.minecraft.game.core.damage.DamageManager;
import nautilus.game.arcade.game.GameServerConfig;
@ -83,6 +84,7 @@ public class Arcade extends JavaPlugin
ItemStackFactory.Initialize(this, false);
Recharge.Initialize(this);
VisibilityManager.Initialize(this);
_donationManager = new DonationManager(this, _clientManager, webServerAddress);

View File

@ -10,6 +10,7 @@ import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.visibility.VisibilityManager;
import nautilus.game.arcade.game.GameTeam.PlayerState;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
@ -140,14 +141,7 @@ public class GameTeam
UtilPlayer.message(player, F.main("Team", _color + C.Bold + "You joined " + _name + " Team") + ".");
for (Player other : UtilServer.getPlayers())
{
if (other.equals(player))
continue;
other.hidePlayer(player);
other.showPlayer(player);
}
VisibilityManager.Instance.refreshPlayerToAll(player);
}
public void RemovePlayer(Player player)

View File

@ -19,6 +19,7 @@ import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.visibility.VisibilityManager;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType;
import nautilus.game.arcade.events.GameStateChangeEvent;
@ -248,11 +249,7 @@ public class DeathTag extends SoloGame
newKit.ApplyKit(player);
//Refresh
for (Player other : UtilServer.getPlayers())
{
other.hidePlayer(player);
other.showPlayer(player);
}
VisibilityManager.Instance.refreshPlayerToAll(player);
if (forced)
{
@ -291,11 +288,7 @@ public class DeathTag extends SoloGame
GetKit(player).ApplyKit(player);
//Refresh on Spawn
for (Player other : UtilServer.getPlayers())
{
other.hidePlayer(player);
other.showPlayer(player);
}
VisibilityManager.Instance.refreshPlayerToAll(player);
}
}, 0);
}

View File

@ -63,6 +63,7 @@ import mineplex.core.mount.event.MountActivateEvent;
import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.visibility.VisibilityManager;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.GameTeam.PlayerState;
import nautilus.game.arcade.game.games.event.kits.*;
@ -152,11 +153,7 @@ public class EventGame extends SoloGame
GetKits()[0].ApplyKit(player);
//Refresh
for (Player other : UtilServer.getPlayers())
{
other.hidePlayer(player);
other.showPlayer(player);
}
VisibilityManager.Instance.refreshPlayerToAll(player);
//Spawn
GetTeamList().get(0).SpawnTeleport(player);
@ -1193,47 +1190,6 @@ public class EventGame extends SoloGame
event.blockList().clear();
}
// @EventHandler
// public void updateVisibility(UpdateEvent event)
// {
// if (!InProgress())
// return;
//
// if (event.getType() != UpdateType.FAST)
// return;
//
// for (Player player : UtilServer.getPlayers())
// {
// if (!Manager.getPreferences().Get(player).ShowPlayers)
// {
// for (Player other : UtilServer.getPlayers())
// {
// if (player.equals(other))
// continue;
//
// ((CraftPlayer)player).hidePlayer(other, true, false);
// }
// }
// else
// {
// for (Player other : UtilServer.getPlayers())
// {
// if (player.equals(other))
// continue;
//
// if ((Manager.getPreferences().Get(player).Invisibility && _mps.isAdmin(player, false)) || )
// {
// ((CraftPlayer)other).hidePlayer(player, true, false);
// }
// else
// {
// other.showPlayer(player);
// }
// }
// }
// }
// }
@Override
public void EndCheck()
{

View File

@ -73,6 +73,7 @@ import mineplex.core.packethandler.PacketInfo;
import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.visibility.VisibilityManager;
import mineplex.minecraft.game.core.combat.DeathMessageType;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.ArcadeManager;
@ -1035,11 +1036,7 @@ public class HideSeek extends TeamGame
GetKits()[5].ApplyKit(player);
// Refresh
for (Player other : UtilServer.getPlayers())
{
other.hidePlayer(player);
other.showPlayer(player);
}
VisibilityManager.Instance.refreshPlayerToAll(player);
if (forced)
{

View File

@ -35,6 +35,7 @@ import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.visibility.VisibilityManager;
import mineplex.minecraft.game.core.combat.event.CombatDeathEvent;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.ArcadeManager;
@ -293,11 +294,7 @@ public class MilkCow extends SoloGame
newKit.ApplyKit(player);
//Refresh
for (Player other : UtilServer.getPlayers())
{
other.hidePlayer(player);
other.showPlayer(player);
}
VisibilityManager.Instance.refreshPlayerToAll(player);
if (forced)
{

View File

@ -42,6 +42,7 @@ import mineplex.core.common.util.UtilServer;
import mineplex.minecraft.game.core.condition.Condition.ConditionType;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.visibility.VisibilityManager;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType;
@ -143,22 +144,6 @@ public class Paintball extends TeamGame
CleanColorArmor(event.GetPlayer());
}
@EventHandler(priority = EventPriority.HIGH)
public void RefreshPlayers(GameStateChangeEvent event)
{
if (event.GetState() != GameState.Live)
return;
for (Player player : GetPlayers(true))
{
for (Player other : GetPlayers(true))
{
other.hidePlayer(player);
other.showPlayer(player);
}
}
}
@EventHandler
public void HealthRegen(EntityRegainHealthEvent event)
{

View File

@ -24,6 +24,7 @@ import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.visibility.VisibilityManager;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType;
import nautilus.game.arcade.events.GameStateChangeEvent;
@ -157,11 +158,7 @@ public class ZombieSurvival extends SoloGame
newKit.ApplyKit(player);
//Refresh
for (Player other : UtilServer.getPlayers())
{
other.hidePlayer(player);
other.showPlayer(player);
}
VisibilityManager.Instance.refreshPlayerToAll(player);
if (forced)
{
@ -198,11 +195,7 @@ public class ZombieSurvival extends SoloGame
GetKit(player).ApplyKit(player);
//Refresh on Spawn
for (Player other : UtilServer.getPlayers())
{
other.hidePlayer(player);
other.showPlayer(player);
}
VisibilityManager.Instance.refreshPlayerToAll(player);
}
}, 0);
}