You have your HologramManager presented in a light most fair.

Should be worth noting I didn't test it thoroughly
This commit is contained in:
libraryaddict 2014-11-26 10:28:37 +13:00
parent 3c76fde190
commit 03075fecae
9 changed files with 142 additions and 84 deletions

View File

@ -17,11 +17,9 @@ import net.minecraft.server.v1_7_R4.PacketPlayOutRelEntityMove;
import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntity;
import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntityLiving;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
import mineplex.core.common.util.UtilEnt;
@ -56,13 +54,14 @@ public class Hologram
private Packet[] _packets1_8;
private HashSet<String> _playersInList = new HashSet<String>();
private ArrayList<Player> _playersTracking = new ArrayList<Player>();
private BukkitRunnable _runnable;
private HologramTarget _target = HologramTarget.BLACKLIST;
private String[] _text = new String[0];
private int _viewDistance = 70;
private HologramManager _hologramManager;
public Hologram(Location location, String... text)
public Hologram(HologramManager hologramManager, Location location, String... text)
{
_hologramManager = hologramManager;
_location = location.clone();
setText(text);
}
@ -100,7 +99,7 @@ public class Hologram
return _playersInList.contains(player);
}
private Packet getDestroyPacket(Player player)
protected Packet getDestroyPacket(Player player)
{
if (_destroyPackets)
{
@ -129,7 +128,7 @@ public class Hologram
return _location.clone();
}
private ArrayList<Player> getNearbyPlayers()
protected ArrayList<Player> getNearbyPlayers()
{
ArrayList<Player> nearbyPlayers = new ArrayList<Player>();
for (Player player : getLocation().getWorld().getPlayers())
@ -142,7 +141,7 @@ public class Hologram
return nearbyPlayers;
}
private Packet[] getSpawnPackets(Player player)
protected Packet[] getSpawnPackets(Player player)
{
if (_makePackets)
{
@ -179,7 +178,7 @@ public class Hologram
*/
public boolean isInUse()
{
return _runnable != null;
return _lastMovement != null;
}
/**
@ -575,6 +574,11 @@ public class Hologram
return setLocation(getLocation());
}
protected ArrayList<Player> getPlayersTracking()
{
return _playersTracking;
}
/**
* Start the hologram
*/
@ -582,6 +586,7 @@ public class Hologram
{
if (!isInUse())
{
_hologramManager.addHologram(this);
_playersTracking.addAll(getNearbyPlayers());
for (Player player : _playersTracking)
{
@ -591,49 +596,6 @@ public class Hologram
}
}
_lastMovement = new Vector();
_runnable = new BukkitRunnable()
{
@Override
public void run()
{
if (!Bukkit.getWorlds().contains(getLocation().getWorld()))
{
stop();
}
else
{
ArrayList<Player> canSee = getNearbyPlayers();
Iterator<Player> itel = _playersTracking.iterator();
while (itel.hasNext())
{
Player player = itel.next();
if (!canSee.contains(player))
{
itel.remove();
if (player.getWorld() == getLocation().getWorld())
{
((CraftPlayer) player).getHandle().playerConnection.sendPacket(getDestroyPacket(player));
}
}
}
for (Player player : canSee)
{
if (!_playersTracking.contains(player))
{
_playersTracking.add(player);
for (Packet packet : getSpawnPackets(player))
{
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
}
}
}
}
};
_runnable.runTaskTimer(Bukkit.getPluginManager().getPlugin("Arcade"), 0, 0);
// TODO Remove that plugin call
}
return this;
}
@ -645,8 +607,7 @@ public class Hologram
{
if (isInUse())
{
_runnable.cancel();
_runnable = null;
_hologramManager.removeHologram(this);
for (Player player : _playersTracking)
{
((CraftPlayer) player).getHandle().playerConnection.sendPacket(getDestroyPacket(player));

View File

@ -0,0 +1,84 @@
package mineplex.core.hologram;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import net.minecraft.server.v1_7_R4.Packet;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
public class HologramManager implements Listener
{
private ArrayList<Hologram> _activeHolograms = new ArrayList<Hologram>();
public HologramManager(JavaPlugin arcadeManager)
{
Bukkit.getPluginManager().registerEvents(this, arcadeManager);
}
void addHologram(Hologram hologram)
{
_activeHolograms.add(hologram);
}
void removeHologram(Hologram hologram)
{
_activeHolograms.remove(hologram);
}
@EventHandler(priority = EventPriority.LOWEST)
public void onTick(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK || _activeHolograms.isEmpty())
return;
List<World> worlds = Bukkit.getWorlds();
Iterator<Hologram> itel = _activeHolograms.iterator();
while (itel.hasNext())
{
Hologram hologram = itel.next();
if (!worlds.contains(hologram.getLocation().getWorld()))
{
itel.remove();
hologram.stop();
}
else
{
ArrayList<Player> canSee = hologram.getNearbyPlayers();
Iterator<Player> itel2 = hologram.getPlayersTracking().iterator();
while (itel.hasNext())
{
Player player = itel2.next();
if (!canSee.contains(player))
{
itel2.remove();
if (player.getWorld() == hologram.getLocation().getWorld())
{
((CraftPlayer) player).getHandle().playerConnection.sendPacket(hologram.getDestroyPacket(player));
}
}
}
for (Player player : canSee)
{
if (!hologram.getPlayersTracking().contains(player))
{
hologram.getPlayersTracking().add(player);
for (Packet packet : hologram.getSpawnPackets(player))
{
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
}
}
}
}
}
}

View File

@ -14,12 +14,13 @@ import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_7_R4.util.CraftMagicNumbers;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_7_R4.PacketPlayOutBlockAction;
import net.minecraft.server.v1_7_R4.PacketPlayOutBlockAction;
import mineplex.core.blockrestore.BlockRestore;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.hologram.HologramManager;
import mineplex.core.reward.Reward;
import mineplex.core.reward.RewardData;
import mineplex.core.reward.RewardRarity;
@ -56,15 +57,16 @@ public class Treasure
private LinkedList<Animation> _animations;
private TreasureStyle _style;
private HologramManager _hologramManager;
public Treasure(Player player, Reward[] rewards, BlockRestore blockRestore)
public Treasure(Player player, Reward[] rewards, BlockRestore blockRestore, HologramManager hologramManager)
{
this(player, new Random(), rewards);
this(player, new Random(), rewards, hologramManager);
_blockRestore = blockRestore;
}
public Treasure(Player player, Random seed, Reward[] rewards)
public Treasure(Player player, Random seed, Reward[] rewards, HologramManager hologramManager)
{
_player = player;
_random = seed;
@ -73,6 +75,7 @@ public class Treasure
_centerBlock = player.getLocation().getBlock().getRelative(BlockFace.DOWN);
_animations = new LinkedList<Animation>();
_hologramManager = hologramManager;
// _animations.add(new ParticleAnimation(this));
@ -288,7 +291,7 @@ public class Treasure
RewardData rewardData = data.getReward().giveReward("Treasure", _player);
data.setOpened(true);
ChestOpenAnimation chestOpenTask = new ChestOpenAnimation(this, data, rewardData);
ChestOpenAnimation chestOpenTask = new ChestOpenAnimation(this, data, rewardData, _hologramManager);
_animations.add(chestOpenTask);
// Extra effects based off the rarity of the treasure

View File

@ -36,6 +36,7 @@ import mineplex.core.common.util.UtilPlayer;
import mineplex.core.donation.DonationManager;
import mineplex.core.event.StackerEvent;
import mineplex.core.gadget.event.GadgetBlockEvent;
import mineplex.core.hologram.HologramManager;
import mineplex.core.inventory.InventoryManager;
import mineplex.core.pet.PetManager;
import mineplex.core.reward.Reward;
@ -55,14 +56,16 @@ public class TreasureManager extends MiniPlugin
private RewardManager _rewardManager;
private InventoryManager _inventoryManager;
private BlockRestore _blockRestore;
private HologramManager _hologramManager;
public TreasureManager(JavaPlugin plugin, DonationManager donationManager, InventoryManager inventoryManager, PetManager petManager, BlockRestore blockRestore)
public TreasureManager(JavaPlugin plugin, DonationManager donationManager, InventoryManager inventoryManager, PetManager petManager, BlockRestore blockRestore, HologramManager hologramManager)
{
super("Treasure", plugin);
_playerTreasureMap = new NautHashMap<Player, Treasure>();
_inventoryManager = inventoryManager;
_blockRestore = blockRestore;
_hologramManager = hologramManager;
_rewardManager = new RewardManager(donationManager, inventoryManager, petManager,
250, 500,
750, 1500,
@ -108,7 +111,7 @@ public class TreasureManager extends MiniPlugin
Bukkit.broadcastMessage(F.main("Treasure", F.name(player.getName()) + " is opening a " + C.cGreen + "Treasure Chest"));
Reward[] rewards = _rewardManager.getRewards(player, true);
Treasure treasure = new Treasure(player, rewards, _blockRestore);
Treasure treasure = new Treasure(player, rewards, _blockRestore, _hologramManager);
_playerTreasureMap.put(player, treasure);
Location teleportLocation = treasure.getPlayerBlock().getLocation().add(0.5, 0, 0.5);

View File

@ -1,6 +1,12 @@
package mineplex.core.treasure.animation;
import java.util.ArrayList;
import mineplex.core.common.util.UtilServer;
import mineplex.core.hologram.Hologram;
import mineplex.core.hologram.HologramManager;
import mineplex.core.reward.RewardData;
import mineplex.core.treasure.ChestData;
import mineplex.core.treasure.Treasure;
import net.minecraft.server.v1_7_R4.PacketPlayOutBlockAction;
import org.bukkit.Location;
import org.bukkit.Sound;
@ -11,13 +17,6 @@ import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import net.minecraft.server.v1_7_R4.PacketPlayOutBlockAction;
import mineplex.core.common.util.UtilServer;
import mineplex.core.hologram.Hologram;
import mineplex.core.reward.RewardData;
import mineplex.core.treasure.ChestData;
import mineplex.core.treasure.Treasure;
/**
* Created by Shaun on 8/29/2014.
*/
@ -25,11 +24,12 @@ public class ChestOpenAnimation extends Animation
{
private ChestData _chestData;
private RewardData _rewardData;
private HologramManager _hologramManager;
private Item _itemEntity;
private ArrayList<Hologram> _holograms = new ArrayList<Hologram>();
private Hologram _hologram;
public ChestOpenAnimation(Treasure treasure, ChestData chestData, RewardData rewardData)
public ChestOpenAnimation(Treasure treasure, ChestData chestData, RewardData rewardData, HologramManager hologramManager)
{
super(treasure);
_chestData = chestData;
@ -58,21 +58,17 @@ public class ChestOpenAnimation extends Animation
}
else if (getTicks() == 15)
{
Hologram hologram = new Hologram(_chestData.getBlock().getLocation().add(0.5, 1.1, 0.5),
_hologram = new Hologram(_hologramManager, _chestData.getBlock().getLocation().add(0.5, 1.1, 0.5),
_rewardData.getFriendlyName());
hologram.start();
_holograms.add(hologram);
_hologram.start();
}
}
public void onFinish()
{
if (!_holograms.isEmpty())
if (_hologram != null)
{
for (Hologram hologram : _holograms)
{
hologram.stop();
}
_hologram.stop();
_itemEntity.remove();
}
}

View File

@ -17,6 +17,7 @@ import mineplex.core.donation.DonationManager;
import mineplex.core.elo.EloManager;
import mineplex.core.energy.Energy;
import mineplex.core.friend.FriendManager;
import mineplex.core.hologram.HologramManager;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.logger.Logger;
import mineplex.core.memory.MemoryFix;
@ -103,7 +104,7 @@ public class Hub extends JavaPlugin implements IRelation
DisguiseManager disguiseManager = new DisguiseManager(this, packetHandler);
StatsManager statsManager = new StatsManager(this);
AchievementManager achievementManager = new AchievementManager(statsManager, clientManager, donationManager);
HubManager hubManager = new HubManager(this, new BlockRestore(this), clientManager, donationManager, new ConditionManager(this), disguiseManager, new TaskManager(this, webServerAddress), portal, partyManager, preferenceManager, petManager, pollManager, statsManager, achievementManager);
HubManager hubManager = new HubManager(this, new BlockRestore(this), clientManager, donationManager, new ConditionManager(this), disguiseManager, new TaskManager(this, webServerAddress), portal, partyManager, preferenceManager, petManager, pollManager, statsManager, achievementManager, new HologramManager(this));
QueueManager queueManager = new QueueManager(this, clientManager, donationManager, new EloManager(this), partyManager);

View File

@ -65,6 +65,7 @@ import mineplex.core.donation.DonationManager;
import mineplex.core.gadget.GadgetManager;
import mineplex.core.gadget.event.GadgetActivateEvent;
import mineplex.core.gadget.event.GadgetCollideEntityEvent;
import mineplex.core.hologram.HologramManager;
import mineplex.core.inventory.InventoryManager;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.mount.MountManager;
@ -144,7 +145,7 @@ public class HubManager extends MiniClientPlugin<HubClient>
//Admin
private boolean _gadgetsEnabled = true;
public HubManager(JavaPlugin plugin, BlockRestore blockRestore, CoreClientManager clientManager, DonationManager donationManager, ConditionManager conditionManager, DisguiseManager disguiseManager, TaskManager taskManager, Portal portal, PartyManager partyManager, PreferencesManager preferences, PetManager petManager, PollManager pollManager, StatsManager statsManager, AchievementManager achievementManager)
public HubManager(JavaPlugin plugin, BlockRestore blockRestore, CoreClientManager clientManager, DonationManager donationManager, ConditionManager conditionManager, DisguiseManager disguiseManager, TaskManager taskManager, Portal portal, PartyManager partyManager, PreferencesManager preferences, PetManager petManager, PollManager pollManager, StatsManager statsManager, AchievementManager achievementManager, HologramManager hologramManager)
{
super("Hub Manager", plugin);
@ -173,7 +174,7 @@ public class HubManager extends MiniClientPlugin<HubClient>
_inventoryManager = new InventoryManager(plugin);
new RankBenefitsGiver9000(plugin, clientManager, _inventoryManager);
_gadgetManager = new GadgetManager(_plugin, clientManager, donationManager, _inventoryManager, _mountManager, petManager, preferences, disguiseManager, blockRestore, new ProjectileManager(plugin));
_treasureManager = new TreasureManager(_plugin, donationManager, _inventoryManager, petManager, _blockRestore);
_treasureManager = new TreasureManager(_plugin, donationManager, _inventoryManager, petManager, _blockRestore, hologramManager);
new CosmeticManager(_plugin, clientManager, donationManager, _inventoryManager, _gadgetManager, _mountManager, petManager, false, _treasureManager);
_partyManager = partyManager;

View File

@ -21,6 +21,7 @@ import mineplex.core.disguise.DisguiseManager;
import mineplex.core.donation.DonationManager;
import mineplex.core.friend.FriendManager;
import mineplex.core.gadget.GadgetManager;
import mineplex.core.hologram.HologramManager;
import mineplex.core.inventory.InventoryManager;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.logger.Logger;
@ -109,6 +110,7 @@ public class Arcade extends JavaPlugin
BlockRestore blockRestore = new BlockRestore(this);
ProjectileManager projectileManager = new ProjectileManager(this);
HologramManager hologramManager = new HologramManager(this);
//Inventory
InventoryManager inventoryManager = new InventoryManager(this);
@ -119,7 +121,7 @@ public class Arcade extends JavaPlugin
cosmeticManager.setInterfaceSlot(7);
//Arcade Manager
_gameManager = new ArcadeManager(this, serverStatusManager, ReadServerConfig(), _clientManager, _donationManager, _damageManager, disguiseManager, creature, teleport, new Blood(this), antistack, portal, preferenceManager, inventoryManager, packetHandler, cosmeticManager, projectileManager, petManager, webServerAddress);
_gameManager = new ArcadeManager(this, serverStatusManager, ReadServerConfig(), _clientManager, _donationManager, _damageManager, disguiseManager, creature, teleport, new Blood(this), antistack, portal, preferenceManager, inventoryManager, packetHandler, cosmeticManager, projectileManager, petManager, hologramManager, webServerAddress);
new MemoryFix(this);
new CustomTagFix(this, packetHandler);

View File

@ -55,6 +55,7 @@ import mineplex.core.donation.DonationManager;
import mineplex.core.elo.EloManager;
import mineplex.core.energy.Energy;
import mineplex.core.explosion.Explosion;
import mineplex.core.hologram.HologramManager;
import mineplex.core.inventory.InventoryManager;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.movement.Movement;
@ -147,7 +148,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
private InventoryManager _inventoryManager;
private CosmeticManager _cosmeticManager;
private final IdleManager _idleManager;
private HologramManager _hologramManager;
private AchievementManager _achievementManager;
private StatsManager _statsManager;
private ClassManager _classManager;
@ -175,7 +176,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
CoreClientManager clientManager, DonationManager donationManager, DamageManager damageManager,
DisguiseManager disguiseManager, Creature creature, Teleport teleport, Blood blood, AntiStack antistack,
Portal portal, PreferencesManager preferences, InventoryManager inventoryManager, PacketHandler packetHandler,
CosmeticManager cosmeticManager, ProjectileManager projectileManager, PetManager petManager, String webAddress)
CosmeticManager cosmeticManager, ProjectileManager projectileManager, PetManager petManager, HologramManager hologramManager, String webAddress)
{
super("Game Manager", plugin);
@ -248,6 +249,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
new GameSpectatorManager(this);
_gameWorldManager = new GameWorldManager(this);
new MiscManager(this);
_hologramManager = hologramManager;
_idleManager = new IdleManager(this);
//new HalloweenManager(this);
@ -344,6 +346,11 @@ public class ArcadeManager extends MiniPlugin implements IRelation
{
return _disguiseManager;
}
public HologramManager getHologramManager()
{
return _hologramManager;
}
public DamageManager GetDamage()
{