From 09528a926295b26f4fb46d3a3df19f862e8c9b69 Mon Sep 17 00:00:00 2001 From: AlexTheCoder Date: Fri, 18 Dec 2015 21:33:40 -0500 Subject: [PATCH] - Initial broadcast stuff --- .../src/nautilus/game/arcade/Arcade.java | 3 + .../nautilus/game/arcade/ArcadeManager.java | 10 ++ .../game/arcade/broadcast/BroadcastData.java | 97 ++++++++++++++ .../arcade/broadcast/BroadcastManager.java | 120 ++++++++++++++++++ .../broadcast/command/BroadcastCommand.java | 33 +++++ .../broadcast/command/RotateCommand.java | 21 +++ .../broadcast/command/manage/AddCommand.java | 22 ++++ .../command/manage/RemoveCommand.java | 22 ++++ 8 files changed, 328 insertions(+) create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/BroadcastData.java create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/BroadcastManager.java create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/command/BroadcastCommand.java create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/command/RotateCommand.java create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/command/manage/AddCommand.java create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/command/manage/RemoveCommand.java diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java index f49b61b7f..d26bc174a 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java @@ -59,6 +59,7 @@ import mineplex.core.velocity.VelocityFix; import mineplex.core.visibility.VisibilityManager; import mineplex.minecraft.game.core.combat.CombatManager; import mineplex.minecraft.game.core.damage.DamageManager; +import nautilus.game.arcade.broadcast.BroadcastManager; import nautilus.game.arcade.game.GameServerConfig; public class Arcade extends JavaPlugin @@ -156,6 +157,8 @@ public class Arcade extends JavaPlugin PollManager pollManager = new PollManager(this, _clientManager, _donationManager); _gameManager = new ArcadeManager(this, serverStatusManager, ReadServerConfig(), _clientManager, _donationManager, _damageManager, statsManager, achievementManager, disguiseManager, creature, teleport, new Blood(this), chat, portal, preferenceManager, inventoryManager, packetHandler, cosmeticManager, projectileManager, petManager, hologramManager, webServerAddress, pollManager, npcmanager, giveawayManager); + new BroadcastManager(this, _gameManager); + new MemoryFix(this); new CustomTagFix(this, packetHandler); new PacketsInteractionFix(this, packetHandler); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java index 7e9d4a156..1a971bfc7 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java @@ -202,6 +202,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation // Observers private HashSet _specList = new HashSet(); + private HashSet _fakeObserve = new HashSet(); // Server Games private GameServerConfig _serverConfig; @@ -1119,9 +1120,18 @@ public class ArcadeManager extends MiniPlugin implements IRelation { _specList.remove(event.getPlayer()); } + + public void toggleFakeObserver(Player player) + { + if (!_fakeObserve.remove(player)) + _fakeObserve.add(player); + } public boolean IsObserver(Player player) { + if (_fakeObserve.contains(player)) + return true; + return _specList.contains(player); } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/BroadcastData.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/BroadcastData.java new file mode 100644 index 000000000..fe4b389da --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/BroadcastData.java @@ -0,0 +1,97 @@ +package nautilus.game.arcade.broadcast; + +import java.util.ArrayList; +import java.util.List; + +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilTime; +import mineplex.core.common.util.UtilTime.TimeUnit; +import mineplex.core.recharge.Recharge; +import net.minecraft.server.v1_8_R3.PacketPlayOutCamera; + +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; +import org.bukkit.entity.Player; + +public class BroadcastData +{ + private Player _player; + private BroadcastManager _plugin; + + private boolean _rotate; + + private List _gamePlayers; + private List _recentlyViewed; + private Player _currentlyViewing; + + public BroadcastData(Player player, BroadcastManager plugin) + { + _player = player; + _plugin = plugin; + + _recentlyViewed = new ArrayList(); + + setRotating(false); + } + + private void setRotating(boolean rotate) + { + _rotate = rotate; + UtilPlayer.message(_player, F.main(_plugin.getName(), "Player Rotation: " + rotate)); + } + + public boolean isRotating() + { + return _rotate; + } + + public Player currentView() + { + return _currentlyViewing; + } + + public Player nextPlayer() + { + if (_gamePlayers.size() == _recentlyViewed.size()) + _recentlyViewed.clear(); + + for (Player player : _gamePlayers) + { + if (!player.isOnline() || !player.isValid() || player.isDead()) + continue; + + if (!_recentlyViewed.contains(player)) + return player; + } + + return null; + } + + public void toggleRotating(List gamePlayers) + { + if (!isRotating()) + { + if (gamePlayers == null) + return; + + if (gamePlayers.size() == 0) + return; + + _gamePlayers = gamePlayers; + } + if (isRotating()) + { + PacketPlayOutCamera restore = new PacketPlayOutCamera((net.minecraft.server.v1_8_R3.Entity)_player); + ((CraftPlayer)_player).getHandle().playerConnection.sendPacket(restore); + } + setRotating(!isRotating()); + } + + public void goToNext(Player player) + { + Recharge.Instance.useForce(_player, "Broadcaster Rotation", UtilTime.convert(10, TimeUnit.SECONDS, TimeUnit.MILLISECONDS), false); + _currentlyViewing = player; + PacketPlayOutCamera view = new PacketPlayOutCamera((net.minecraft.server.v1_8_R3.Entity)player); + ((CraftPlayer)_player).getHandle().playerConnection.sendPacket(view); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/BroadcastManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/BroadcastManager.java new file mode 100644 index 000000000..d3693e598 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/BroadcastManager.java @@ -0,0 +1,120 @@ +package nautilus.game.arcade.broadcast; + +import java.util.concurrent.ConcurrentHashMap; + +import mineplex.core.MiniPlugin; +import mineplex.core.recharge.Recharge; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.events.GameStateChangeEvent; +import nautilus.game.arcade.game.Game; +import nautilus.game.arcade.game.Game.GameState; + +import org.bukkit.GameMode; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.plugin.java.JavaPlugin; + +public class BroadcastManager extends MiniPlugin +{ + ArcadeManager ArcadeManager; + private ConcurrentHashMap _broadcasters; + + public BroadcastManager(JavaPlugin plugin, ArcadeManager manager) + { + super("Broadcasting Manager", plugin); + ArcadeManager = manager; + _broadcasters = new ConcurrentHashMap(); + } + + public boolean isBroadcaster(Player player) + { + return _broadcasters.containsKey(player); + } + + public void addBroadcaster(Player player) + { + _broadcasters.put(player, new BroadcastData(player, this)); + if (ArcadeManager.GetGame() != null) + { + ArcadeManager.GetGame().RemoveTeamPreference(player); + ArcadeManager.GetGame().GetPlayerKits().remove(player); + ArcadeManager.GetGame().GetPlayerGems().remove(player); + try + { + ArcadeManager.GetGame().GetTeam(player).RemovePlayer(player); + } + catch (Exception e) {} + ArcadeManager.Clear(player); + ArcadeManager.toggleFakeObserver(player); + } + player.getInventory().clear(); + player.setGameMode(GameMode.SPECTATOR); + } + + public void removeBroadcaster(Player player) + { + _broadcasters.remove(player); + ArcadeManager.toggleFakeObserver(player); + if (ArcadeManager.GetGame().InProgress()) + ArcadeManager.addSpectator(player, true); + player.setGameMode(GameMode.SURVIVAL); + } + + @EventHandler + public void handleBroadcasting(GameStateChangeEvent event) + { + if (event.GetState() == GameState.Dead) + { + for (BroadcastData data : _broadcasters.values()) + { + if (data.isRotating()) + data.toggleRotating(null); + } + _broadcasters.clear(); + } + } + + @EventHandler + public void handleRotation(UpdateEvent event) + { + if (event.getType() == UpdateType.FASTEST) + { + Game game = ArcadeManager.GetGame(); + if (game == null) + return; + if (!game.InProgress()) + return; + + for (Player player : _broadcasters.keySet()) + { + if (!Recharge.Instance.usable(player, "Broadcaster Rotation", false)) + continue; + } + } + } + + @EventHandler + public void handleRotation(PlayerQuitEvent event) + { + Game game = ArcadeManager.GetGame(); + if (game == null) + return; + if (!game.InProgress()) + return; + + if (_broadcasters.containsKey(event.getPlayer())) + _broadcasters.remove(event.getPlayer()); + + for (BroadcastData data : _broadcasters.values()) + { + if (data.currentView() == null) + continue; + + if (data.currentView() == event.getPlayer()); + data.goToNext(data.nextPlayer()); + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/command/BroadcastCommand.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/command/BroadcastCommand.java new file mode 100644 index 000000000..49d4858d2 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/command/BroadcastCommand.java @@ -0,0 +1,33 @@ +package nautilus.game.arcade.broadcast.command; + +import mineplex.core.command.MultiCommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import nautilus.game.arcade.broadcast.BroadcastManager; +import nautilus.game.arcade.broadcast.command.manage.AddCommand; +import nautilus.game.arcade.broadcast.command.manage.RemoveCommand; + +import org.bukkit.entity.Player; + +public class BroadcastCommand extends MultiCommandBase +{ + public BroadcastCommand(BroadcastManager plugin) + { + super(plugin, Rank.ADMIN, new Rank[] {Rank.TWITCH, Rank.YOUTUBE, Rank.YOUTUBE_SMALL, Rank.JNR_DEV}, "broadcaster"); + AddCommand(new AddCommand(plugin)); + AddCommand(new RemoveCommand(plugin)); + AddCommand(new RotateCommand(plugin)); + } + + @Override + protected void Help(Player caller, String[] args) + { + UtilPlayer.message(caller, F.main(Plugin.getName(), "Commands List:")); + UtilPlayer.message(caller, F.help("/broadcaster add ", "Puts a player in Broadcast mode for this game", Rank.ADMIN)); + UtilPlayer.message(caller, F.help("/broadcaster remove ", "Takes a player out of Broadcast mode", Rank.ADMIN)); + UtilPlayer.message(caller, F.help("/broadcaster rotate", "Toggles rotating view between game players", Rank.TWITCH)); + UtilPlayer.message(caller, F.main("Tip", "Rotation is great for a background to commentary!")); + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/command/RotateCommand.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/command/RotateCommand.java new file mode 100644 index 000000000..b455ce4af --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/command/RotateCommand.java @@ -0,0 +1,21 @@ +package nautilus.game.arcade.broadcast.command; + +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import nautilus.game.arcade.broadcast.BroadcastManager; + +public class RotateCommand extends CommandBase +{ + public RotateCommand(BroadcastManager plugin) { + super(plugin, Rank.TWITCH, "rotate"); + } + + @Override + public void Execute(Player caller, String[] args) + { + + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/command/manage/AddCommand.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/command/manage/AddCommand.java new file mode 100644 index 000000000..ee67c8609 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/command/manage/AddCommand.java @@ -0,0 +1,22 @@ +package nautilus.game.arcade.broadcast.command.manage; + +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import nautilus.game.arcade.broadcast.BroadcastManager; + +public class AddCommand extends CommandBase +{ + public AddCommand(BroadcastManager plugin) + { + super(plugin, Rank.ADMIN, new Rank[] {Rank.JNR_DEV}, "add"); + } + + @Override + public void Execute(Player caller, String[] args) + { + + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/command/manage/RemoveCommand.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/command/manage/RemoveCommand.java new file mode 100644 index 000000000..021202498 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/command/manage/RemoveCommand.java @@ -0,0 +1,22 @@ +package nautilus.game.arcade.broadcast.command.manage; + +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import nautilus.game.arcade.broadcast.BroadcastManager; + +public class RemoveCommand extends CommandBase +{ + public RemoveCommand(BroadcastManager plugin) + { + super(plugin, Rank.ADMIN, new Rank[] {Rank.JNR_DEV}, "remove"); + } + + @Override + public void Execute(Player caller, String[] args) + { + + } + +} \ No newline at end of file