- Initial broadcast stuff
This commit is contained in:
parent
6c1c40a972
commit
09528a9262
@ -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);
|
||||
|
@ -202,6 +202,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
|
||||
|
||||
// Observers
|
||||
private HashSet<Player> _specList = new HashSet<Player>();
|
||||
private HashSet<Player> _fakeObserve = new HashSet<Player>();
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
@ -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<Player> _gamePlayers;
|
||||
private List<Player> _recentlyViewed;
|
||||
private Player _currentlyViewing;
|
||||
|
||||
public BroadcastData(Player player, BroadcastManager plugin)
|
||||
{
|
||||
_player = player;
|
||||
_plugin = plugin;
|
||||
|
||||
_recentlyViewed = new ArrayList<Player>();
|
||||
|
||||
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<Player> 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);
|
||||
}
|
||||
}
|
@ -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<Player, BroadcastData> _broadcasters;
|
||||
|
||||
public BroadcastManager(JavaPlugin plugin, ArcadeManager manager)
|
||||
{
|
||||
super("Broadcasting Manager", plugin);
|
||||
ArcadeManager = manager;
|
||||
_broadcasters = new ConcurrentHashMap<Player, BroadcastData>();
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
@ -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<BroadcastManager>
|
||||
{
|
||||
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 <Player>", "Puts a player in Broadcast mode for this game", Rank.ADMIN));
|
||||
UtilPlayer.message(caller, F.help("/broadcaster remove <Player>", "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!"));
|
||||
}
|
||||
|
||||
}
|
@ -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<BroadcastManager>
|
||||
{
|
||||
public RotateCommand(BroadcastManager plugin) {
|
||||
super(plugin, Rank.TWITCH, "rotate");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Execute(Player caller, String[] args)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -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<BroadcastManager>
|
||||
{
|
||||
public AddCommand(BroadcastManager plugin)
|
||||
{
|
||||
super(plugin, Rank.ADMIN, new Rank[] {Rank.JNR_DEV}, "add");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Execute(Player caller, String[] args)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -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<BroadcastManager>
|
||||
{
|
||||
public RemoveCommand(BroadcastManager plugin)
|
||||
{
|
||||
super(plugin, Rank.ADMIN, new Rank[] {Rank.JNR_DEV}, "remove");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Execute(Player caller, String[] args)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user