Memory leaks!
This commit is contained in:
parent
22b7ce60eb
commit
78a123156a
@ -251,8 +251,8 @@ public class ArcadeManager extends MiniPlugin implements IRelation
|
||||
|
||||
//Game commands
|
||||
public static final String GAME_CMD_MODE_FILE = "GAME_CMD_MODE.dat";
|
||||
private boolean _gameCommandMode;
|
||||
|
||||
private Rank _gameCommandRank;
|
||||
|
||||
public final boolean IsHolidayEnabled;
|
||||
|
||||
public ArcadeManager(Arcade plugin, ServerStatusManager serverStatusManager, GameServerConfig serverConfig,
|
||||
@ -388,7 +388,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
|
||||
|
||||
loadRequiredRank();
|
||||
|
||||
_gameCommandMode = checkGameCommandMode();
|
||||
_gameCommandRank = checkGameCommandMode() ? Rank.ALL : Rank.JNR_DEV;
|
||||
|
||||
Region region = new File("eu.dat").exists() ? Region.EU : Region.US;
|
||||
|
||||
@ -1883,23 +1883,25 @@ public class ArcadeManager extends MiniPlugin implements IRelation
|
||||
{
|
||||
return new File(GAME_CMD_MODE_FILE).exists();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Whether this server is in game command mode.
|
||||
* Returns the minimum rank requirement to use game commands.
|
||||
*
|
||||
* @return The minimum rank requirement.
|
||||
*/
|
||||
public boolean isGameCommandMode()
|
||||
public Rank getGameCommandRank()
|
||||
{
|
||||
return _gameCommandMode;
|
||||
return _gameCommandRank;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this server's game command mode state.
|
||||
* Sets this server's minimum rank requirement to use game commands.
|
||||
*
|
||||
* @param state Whether to enable or disable game commands.
|
||||
* @param rank The minimum rank requirement.
|
||||
*/
|
||||
public void setGameCommandMode(boolean state)
|
||||
public void setGameCommandMode(Rank rank)
|
||||
{
|
||||
_gameCommandMode = state;
|
||||
_gameCommandRank = rank;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1911,17 +1913,11 @@ public class ArcadeManager extends MiniPlugin implements IRelation
|
||||
* @return Whether or not the player can successfully use the command.
|
||||
*/
|
||||
public boolean canPlayerUseGameCmd(Player player)
|
||||
{
|
||||
if (_gameCommandMode)
|
||||
{
|
||||
// When enabled, anyone can use game commands.
|
||||
return true;
|
||||
}
|
||||
|
||||
{
|
||||
// Check whether they are of high enough rank status.
|
||||
if (!GetClients().hasRank(player, Rank.JNR_DEV))
|
||||
if (_gameCommandRank == null || !GetClients().hasRank(player, _gameCommandRank))
|
||||
{
|
||||
player.sendMessage(F.main("Server", "You are not allowed to use game commands."));
|
||||
player.sendMessage(F.main("Game", "You are not allowed to use game commands."));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,8 @@ import mineplex.core.command.CommandBase;
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
|
||||
import io.netty.util.internal.chmv8.ForkJoinPool.ManagedBlocker;
|
||||
import nautilus.game.arcade.ArcadeManager;
|
||||
|
||||
/**
|
||||
@ -18,29 +20,34 @@ public class GameCmdModeCommand extends CommandBase<ArcadeManager>
|
||||
{
|
||||
public GameCmdModeCommand(ArcadeManager plugin)
|
||||
{
|
||||
super(plugin, Rank.JNR_DEV, "gamecmdmode");
|
||||
super(plugin, Rank.JNR_DEV, "gamecmdrank");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Execute(Player caller, String[] args)
|
||||
{
|
||||
File file = new File(ArcadeManager.GAME_CMD_MODE_FILE);
|
||||
|
||||
if (Plugin.isGameCommandMode())
|
||||
if (args.length < 1)
|
||||
{
|
||||
// Disable game command mode.
|
||||
if (file.exists())
|
||||
{
|
||||
file.delete();
|
||||
}
|
||||
|
||||
Plugin.setGameCommandMode(false);
|
||||
caller.sendMessage(F.main("Server", "Game commands are now " + C.cRed + "disabled" +
|
||||
C.cGray + "."));
|
||||
caller.sendMessage(F.main("Game", "/gamecmdrank <rank>"));
|
||||
return;
|
||||
}
|
||||
else
|
||||
|
||||
File file = new File(ArcadeManager.GAME_CMD_MODE_FILE);
|
||||
Rank rank = Plugin.getGameCommandRank();
|
||||
Rank newRank = null;
|
||||
|
||||
try
|
||||
{
|
||||
newRank = Rank.valueOf(args[0]);
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
caller.sendMessage(F.main("Game", C.cRedB + "Invalid rank!"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (newRank == Rank.ALL)
|
||||
{
|
||||
// Enable game command mode.
|
||||
if (!file.exists())
|
||||
{
|
||||
try
|
||||
@ -52,10 +59,16 @@ public class GameCmdModeCommand extends CommandBase<ArcadeManager>
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
Plugin.setGameCommandMode(true);
|
||||
caller.sendMessage(F.main("Server", "Game commands are now " + C.cGreen + "enabled" +
|
||||
C.cGray + "."));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (file.exists())
|
||||
{
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
Plugin.setGameCommandMode(newRank);
|
||||
caller.sendMessage(F.main("Game", "Players now need at least rank " + rank.getTag(true, true) + " to use game commands."));
|
||||
}
|
||||
}
|
||||
|
@ -36,9 +36,7 @@ import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||
import org.bukkit.event.entity.ItemSpawnEvent;
|
||||
import org.bukkit.event.hanging.HangingBreakEvent;
|
||||
import org.bukkit.event.hanging.HangingPlaceEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.world.WorldLoadEvent;
|
||||
import org.bukkit.scoreboard.NameTagVisibility;
|
||||
@ -63,7 +61,6 @@ import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.common.util.UtilTabTitle;
|
||||
import mineplex.core.common.util.UtilTextMiddle;
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
import mineplex.core.common.util.UtilTime.TimeUnit;
|
||||
import mineplex.core.disguise.disguises.DisguisePlayer;
|
||||
import mineplex.core.elo.EloPlayer;
|
||||
import mineplex.core.elo.EloTeam;
|
||||
@ -295,9 +292,6 @@ public abstract class Game implements Listener
|
||||
public double XpMult = 1;
|
||||
|
||||
public boolean SpeedMeasurement = false;
|
||||
|
||||
// Rejoining the game
|
||||
public long RejoinTime = 120000;
|
||||
|
||||
// Chat Stats
|
||||
public final ChatStatData Kills = new ChatStatData("Kills", "Kills", true);
|
||||
@ -380,11 +374,6 @@ public abstract class Game implements Listener
|
||||
|
||||
private HashMap<UUID, LinkedList<Triple<Double, Double, Double>>> _playerPastLocs = new HashMap<>();
|
||||
private Set<DebugCommand> _debugCommands = new HashSet<>();
|
||||
|
||||
public NautHashMap<String, Long> RejoinTimes = new NautHashMap<String, Long>();
|
||||
public NautHashMap<String, GameTeam> RejoinTeam = new NautHashMap<String, GameTeam>();
|
||||
public NautHashMap<String, Kit> RejoinKit = new NautHashMap<String, Kit>();
|
||||
public NautHashMap<String, Double> RejoinHealth = new NautHashMap<String, Double>();
|
||||
|
||||
public Game(ArcadeManager manager, GameType gameType, Kit[] kits, String[] gameDesc)
|
||||
{
|
||||
@ -2451,169 +2440,4 @@ public abstract class Game implements Listener
|
||||
return clazz.cast(_modules.get(clazz));
|
||||
}
|
||||
|
||||
/*
|
||||
* All code related to rejoining games.
|
||||
* Moved here from TeamGame
|
||||
*/
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void PlayerQuit(PlayerQuitEvent event)
|
||||
{
|
||||
Bukkit.broadcastMessage(event.getEventName());
|
||||
|
||||
if (!InProgress())
|
||||
return;
|
||||
|
||||
Player player = event.getPlayer();
|
||||
|
||||
GameTeam team = GetTeam(player);
|
||||
if (team == null)
|
||||
{
|
||||
Bukkit.broadcastMessage("Team was null :(");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!IsAlive(player))
|
||||
{
|
||||
Bukkit.broadcastMessage("Player was dead? I mean they shouldn\'t be");
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.isDead())
|
||||
{
|
||||
Bukkit.broadcastMessage("So they are minecraft dead");
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.getWorld().getName().equalsIgnoreCase("world"))
|
||||
{
|
||||
Bukkit.broadcastMessage("They were in the Lobby?");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!QuitOut)
|
||||
{
|
||||
//Store
|
||||
RejoinTimes.put(player.getName(), System.currentTimeMillis());
|
||||
RejoinTeam.put(player.getName(), team);
|
||||
|
||||
if (GetKit(player) != null)
|
||||
{
|
||||
RejoinKit.put(player.getName(), GetKit(player));
|
||||
}
|
||||
|
||||
RejoinHealth.put(player.getName(), player.getHealth());
|
||||
|
||||
if (!GetLocationStore().containsKey(player.getName()))
|
||||
{
|
||||
GetLocationStore().put(player.getName(), player.getLocation());
|
||||
}
|
||||
|
||||
team.RemovePlayer(player);
|
||||
|
||||
//Announcement
|
||||
Announce(team.GetColor() + C.Bold + player.getName() + " has disconnected! " + UtilTime.convert(RejoinTime, 0, TimeUnit.MINUTES) + " minutes to rejoin.", false);
|
||||
}
|
||||
else
|
||||
{
|
||||
Bukkit.broadcastMessage("RIP game settings");
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void PlayerLoginAllow(PlayerLoginEvent event)
|
||||
{
|
||||
if (!InProgress() || QuitOut)
|
||||
return;
|
||||
|
||||
//Rejoined
|
||||
GameTeam team = RejoinTeam.remove(event.getPlayer().getName());
|
||||
if (team != null && RejoinTimes.remove(event.getPlayer().getName()) != null)
|
||||
{
|
||||
team.AddPlayer(event.getPlayer(), true);
|
||||
Announce(team.GetColor() + C.Bold + event.getPlayer().getName() + " has reconnected!", false);
|
||||
|
||||
Kit kit = RejoinKit.remove(event.getPlayer().getName());
|
||||
if (kit != null)
|
||||
_playerKit.put(event.getPlayer(), kit);
|
||||
}
|
||||
}
|
||||
|
||||
//Do this on Join, not Login, otherwise player no get heal.
|
||||
@EventHandler (priority = EventPriority.MONITOR)
|
||||
public void playerRejoinGame(PlayerJoinEvent event)
|
||||
{
|
||||
if (!InProgress() || QuitOut)
|
||||
return;
|
||||
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (RejoinHealth.containsKey(player.getName()))
|
||||
{
|
||||
double health = RejoinHealth.remove(player.getName());
|
||||
if (health > 0)
|
||||
{
|
||||
getArcadeManager().runSyncLater(() ->
|
||||
{
|
||||
player.setHealth(health);
|
||||
}, 1L);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void PlayerRejoinExpire(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.SEC || QuitOut)
|
||||
return;
|
||||
|
||||
Iterator<String> rejoinIterator = RejoinTimes.keySet().iterator();
|
||||
|
||||
while (rejoinIterator.hasNext())
|
||||
{
|
||||
String name = rejoinIterator.next();
|
||||
|
||||
if (!UtilTime.elapsed(RejoinTimes.get(name), RejoinTime))
|
||||
continue;
|
||||
|
||||
rejoinIterator.remove();
|
||||
|
||||
//Get Team (By Name)
|
||||
GameTeam team = RejoinTeam.remove(name);
|
||||
if (team != null)
|
||||
Announce(team.GetColor() + C.Bold + name + " did not reconnect in time!", false);
|
||||
|
||||
RejoinKit.remove(name);
|
||||
RejoinHealth.remove(name);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void RejoinCommand(PlayerCommandPreprocessEvent event)
|
||||
{
|
||||
if (!QuitOut && event.getPlayer().isOp() && event.getMessage().startsWith("/allowrejoin"))
|
||||
{
|
||||
String[] toks = event.getMessage().split(" ");
|
||||
|
||||
if (toks.length <= 1)
|
||||
{
|
||||
event.getPlayer().sendMessage("Missing Param!");
|
||||
}
|
||||
else
|
||||
{
|
||||
RejoinTimes.put(toks[1], System.currentTimeMillis());
|
||||
event.getPlayer().sendMessage("Allowed " + toks[1] + " to rejoin!");
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
protected void removePlayerFromRejoin(String name)
|
||||
{
|
||||
RejoinTimes.remove(name);
|
||||
RejoinKit.remove(name);
|
||||
RejoinTeam.remove(name);
|
||||
RejoinHealth.remove(name);
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,8 @@ import nautilus.game.arcade.ArcadeManager;
|
||||
import nautilus.game.arcade.GameType;
|
||||
import nautilus.game.arcade.events.PlayerStateChangeEvent;
|
||||
import nautilus.game.arcade.game.GameTeam.PlayerState;
|
||||
import nautilus.game.arcade.game.modules.RejoinModule;
|
||||
import nautilus.game.arcade.game.modules.RejoinModule.RejoinPlayerData;
|
||||
import nautilus.game.arcade.kit.Kit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -83,8 +85,13 @@ public abstract class TeamGame extends Game
|
||||
if (!QuitOut)
|
||||
{
|
||||
//Offline Player Team
|
||||
for (GameTeam team : RejoinTeam.values())
|
||||
teamsAlive.add(team);
|
||||
if (getModule(RejoinModule.class) != null)
|
||||
{
|
||||
for (RejoinPlayerData data : getModule(RejoinModule.class).getData())
|
||||
{
|
||||
teamsAlive.add(data.getTeam());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (teamsAlive.size() <= 1)
|
||||
|
@ -1583,12 +1583,12 @@ public class Bridge extends TeamGame implements OreObsfucation
|
||||
if (team.GetPlayers(true).size() > 0)
|
||||
teamsAlive.add(team);
|
||||
|
||||
if (!QuitOut)
|
||||
{
|
||||
//Offline Player Team
|
||||
for (GameTeam team : RejoinTeam.values())
|
||||
teamsAlive.add(team);
|
||||
}
|
||||
// if (!QuitOut)
|
||||
// {
|
||||
// //Offline Player Team
|
||||
// for (GameTeam team : RejoinTeam.values())
|
||||
// teamsAlive.add(team);
|
||||
// }
|
||||
|
||||
if (teamsAlive.size() <= 1)
|
||||
{
|
||||
|
@ -85,7 +85,7 @@ public class QuiverTeamBase extends TeamGame
|
||||
getQuiverTeamModule(ModuleSpawnBarrier.class);
|
||||
getQuiverTeamModule(ModuleKillstreak.class);
|
||||
|
||||
new VersionModule(MinecraftVersion.Version1_9, "One in the Quiver Payload requires Minecraft 1.9!").register(this);
|
||||
new VersionModule(MinecraftVersion.Version1_9).register(this);
|
||||
|
||||
// if (WorldData.GetCustomLocs(CUSTOM_LOCATION_GAME_KOTH) != null)
|
||||
// {
|
||||
|
@ -184,7 +184,7 @@ public abstract class Skyfall extends Game
|
||||
BlankLine
|
||||
);
|
||||
|
||||
new VersionModule(MinecraftVersion.Version1_9, "Skyfall requires Minecraft 1.9!").register(this);
|
||||
new VersionModule(MinecraftVersion.Version1_9).register(this);
|
||||
|
||||
// Disable specific GWEN checks for this game
|
||||
AntiHack antiHack = Managers.get(AntiHack.class);
|
||||
|
@ -94,6 +94,8 @@ import nautilus.game.arcade.game.games.uhc.components.UHCSpeedMode;
|
||||
import nautilus.game.arcade.game.modules.AntiExpOrbModule;
|
||||
import nautilus.game.arcade.game.modules.OreVeinEditorModule;
|
||||
import nautilus.game.arcade.game.modules.PlayerHeadModule;
|
||||
import nautilus.game.arcade.game.modules.RejoinModule;
|
||||
import nautilus.game.arcade.game.modules.RejoinModule.RejoinPlayerData;
|
||||
import nautilus.game.arcade.game.modules.SafezoneModule;
|
||||
import nautilus.game.arcade.game.modules.combatlog.CombatLogModule;
|
||||
import nautilus.game.arcade.game.modules.combatlog.CombatLogNPC;
|
||||
@ -444,7 +446,7 @@ public abstract class UHC extends Game
|
||||
{
|
||||
int timeout = Integer.parseInt(args[0]);
|
||||
module.setCombatLogTime(timeout);
|
||||
RejoinTime = timeout;
|
||||
getModule(RejoinModule.class).setRejoinTime(timeout);
|
||||
UtilPlayer.message(caller, F.main("Debug", "Set the new timeout to " + timeout));
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
@ -481,6 +483,10 @@ public abstract class UHC extends Game
|
||||
|
||||
public void createSpawns()
|
||||
{
|
||||
// Disable game commands
|
||||
Rank lastGameCommandsRank = Manager.getGameCommandRank();
|
||||
Manager.setGameCommandMode(null);
|
||||
|
||||
// Wipe Spawns
|
||||
for (GameTeam team : GetTeamList())
|
||||
{
|
||||
@ -488,19 +494,19 @@ public abstract class UHC extends Game
|
||||
}
|
||||
|
||||
double border = _border.getMaxCords();
|
||||
|
||||
|
||||
// Solo Game
|
||||
if (FillTeamsInOrderToCount == -1)
|
||||
{
|
||||
List<Player> players = GetPlayers(true);
|
||||
GameTeam gameTeam = GetTeamList().get(0);
|
||||
|
||||
getArcadeManager().runSyncTimer(new BukkitRunnable()
|
||||
{
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
GameTeam gameTeam = GetTeamList().get(0);
|
||||
List<Player> players = GetPlayers(true);
|
||||
|
||||
{
|
||||
if (gameTeam.GetSpawns().size() < Math.max(Manager.GetPlayerFull(), GetPlayers(true).size()))
|
||||
{
|
||||
Location loc = GetRandomSpawn(null, false);
|
||||
@ -533,6 +539,7 @@ public abstract class UHC extends Game
|
||||
}
|
||||
else
|
||||
{
|
||||
Manager.setGameCommandMode(lastGameCommandsRank);
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
@ -589,6 +596,7 @@ public abstract class UHC extends Game
|
||||
|
||||
if (currentTeamId.get() >= GetTeamList().size())
|
||||
{
|
||||
Manager.setGameCommandMode(lastGameCommandsRank);
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
@ -619,6 +627,19 @@ public abstract class UHC extends Game
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void end(GameStateChangeEvent event)
|
||||
{
|
||||
if (event.GetState() != GameState.End)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Bukkit.broadcastMessage("DIE OBJECTS, DIE!!!!");
|
||||
|
||||
_border = null;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void outsideBorder(UpdateEvent event)
|
||||
@ -771,9 +792,12 @@ public abstract class UHC extends Game
|
||||
}
|
||||
|
||||
DamagePvP = true;
|
||||
RejoinTime = 300000; // 5 minutes
|
||||
|
||||
RejoinModule rejoinModule = getModule(RejoinModule.class);
|
||||
|
||||
rejoinModule.setRejoinTime((int) TimeUnit.MINUTES.toMillis(5));
|
||||
getModule(CompassModule.class).setGiveCompass(true);
|
||||
new CombatLogModule().setCombatLogTime((int) RejoinTime).register(this);
|
||||
new CombatLogModule().setCombatLogTime((int) rejoinModule.getRejoinTime()).register(this);
|
||||
}
|
||||
|
||||
public void startPreDeathmatch()
|
||||
@ -793,7 +817,19 @@ public abstract class UHC extends Game
|
||||
Damage = false;
|
||||
|
||||
// Disable rejoining
|
||||
QuitOut = true;
|
||||
getModule(RejoinModule.class).stopAllPlayersFromRejoining();
|
||||
|
||||
// Set time
|
||||
WorldTimeSet = 0;
|
||||
|
||||
// Remove all monsters
|
||||
for (Entity entity : WorldData.World.getEntities())
|
||||
{
|
||||
if (entity instanceof Monster)
|
||||
{
|
||||
entity.remove();
|
||||
}
|
||||
}
|
||||
|
||||
// Set the border
|
||||
_border.setSize(DEATHMATCH_ARENA_SIZE, 0);
|
||||
@ -927,7 +963,7 @@ public abstract class UHC extends Game
|
||||
location.getWorld().dropItemNaturally(location, item);
|
||||
}
|
||||
|
||||
removePlayerFromRejoin(npc.getPlayerInfo().getName());
|
||||
getModule(RejoinModule.class).stopPlayerFromRejoining(npc.getPlayerInfo().getName());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -946,7 +982,7 @@ public abstract class UHC extends Game
|
||||
location.getWorld().dropItemNaturally(location, item);
|
||||
}
|
||||
|
||||
removePlayerFromRejoin(npc.getPlayerInfo().getName());
|
||||
getModule(RejoinModule.class).stopPlayerFromRejoining(npc.getPlayerInfo().getName());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -1503,8 +1539,13 @@ public abstract class UHC extends Game
|
||||
|
||||
// Offline Player Team
|
||||
if (teamsAlive.size() > 1)
|
||||
teamsAlive.addAll(RejoinTeam.values());
|
||||
|
||||
{
|
||||
for (RejoinPlayerData data : getModule(RejoinModule.class).getData())
|
||||
{
|
||||
teamsAlive.add(data.getTeam());
|
||||
}
|
||||
}
|
||||
|
||||
if (teamsAlive.size() <= 1)
|
||||
{
|
||||
if (teamsAlive.size() > 0)
|
||||
|
@ -0,0 +1,295 @@
|
||||
package nautilus.game.arcade.game.modules;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.NautHashMap;
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
import mineplex.core.common.util.UtilTime.TimeUnit;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
|
||||
import nautilus.game.arcade.game.DebugCommand;
|
||||
import nautilus.game.arcade.game.GameTeam;
|
||||
import nautilus.game.arcade.kit.Kit;
|
||||
|
||||
public class RejoinModule extends Module
|
||||
{
|
||||
|
||||
private Set<RejoinPlayerData> _data = new HashSet<>();
|
||||
|
||||
private int _rejoinTime;
|
||||
|
||||
@Override
|
||||
protected void setup()
|
||||
{
|
||||
getGame().registerDebugCommand(new DebugCommand("rejoin", Rank.ADMIN)
|
||||
{
|
||||
|
||||
@Override
|
||||
public void Execute(Player caller, String[] args)
|
||||
{
|
||||
if (args.length < 1)
|
||||
{
|
||||
caller.sendMessage(F.main("Debug", "/rejoin <name>"));
|
||||
return;
|
||||
}
|
||||
|
||||
String player = args[0];
|
||||
|
||||
RejoinPlayerData data = getRejoinPlayerData(player);
|
||||
|
||||
// Player wasn't alive earlier or was too slow
|
||||
if (data == null)
|
||||
{
|
||||
_data.add(new RejoinPlayerData(player, 20, null, null));
|
||||
}
|
||||
else
|
||||
{
|
||||
caller.sendMessage(F.main("Debug", "That player is already allowed to rejoin!"));
|
||||
return;
|
||||
}
|
||||
|
||||
caller.sendMessage(F.main("Debug", C.cYellow + player + C.cGray + " is now allowed to rejoin. If they are online tell them to relog."));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void playerQuit(PlayerQuitEvent event)
|
||||
{
|
||||
Bukkit.broadcastMessage(event.getEventName());
|
||||
|
||||
Player player = event.getPlayer();
|
||||
GameTeam team = getGame().GetTeam(player);
|
||||
|
||||
if (team == null)
|
||||
{
|
||||
Bukkit.broadcastMessage("Team was null :(");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!team.IsAlive(player))
|
||||
{
|
||||
Bukkit.broadcastMessage("Player was dead? I mean they shouldn\'t be");
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.isDead())
|
||||
{
|
||||
Bukkit.broadcastMessage("So they are minecraft dead");
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.getWorld().getName().equalsIgnoreCase("world"))
|
||||
{
|
||||
Bukkit.broadcastMessage("They were in the Lobby?");
|
||||
return;
|
||||
}
|
||||
|
||||
if (getGame().QuitOut)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_data.add(new RejoinPlayerData(player.getName(), player.getHealth(), getGame().GetKit(player), team));
|
||||
|
||||
NautHashMap<String, Location> location = getGame().GetLocationStore();
|
||||
|
||||
if (!location.containsKey(player.getName()))
|
||||
{
|
||||
location.put(player.getName(), player.getLocation());
|
||||
}
|
||||
|
||||
team.RemovePlayer(player);
|
||||
|
||||
// Announcement
|
||||
getGame().Announce(team.GetColor() + C.Bold + player.getName() + " has disconnected! " + UtilTime.convert(_rejoinTime, 0, TimeUnit.MINUTES) + " minutes to rejoin.", false);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void playerRejoinGame(PlayerLoginEvent event)
|
||||
{
|
||||
if (!getGame().InProgress() || getGame().QuitOut)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
RejoinPlayerData data = getRejoinPlayerData(player.getName());
|
||||
GameTeam team = data.getTeam();
|
||||
|
||||
if (data.getTeam() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
team.AddPlayer(player, true);
|
||||
getGame().Announce(team.GetColor() + C.Bold + event.getPlayer().getName() + " has reconnected!", false);
|
||||
|
||||
if (data.getKit() != null)
|
||||
{
|
||||
getGame().SetKit(player, data.getKit(), false);
|
||||
}
|
||||
}
|
||||
|
||||
// Do this on Join, not Login, otherwise player no get heal.
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void playerRejoinGame(PlayerJoinEvent event)
|
||||
{
|
||||
if (!getGame().InProgress() || getGame().QuitOut)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
RejoinPlayerData data = getRejoinPlayerData(player.getName());
|
||||
double health = data.getHealth();
|
||||
|
||||
if (!(health > 0))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
getGame().Manager.runSyncLater(() -> {
|
||||
player.setHealth(health);
|
||||
}, 1L);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void rejoinExpire(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.SEC || getGame().QuitOut)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Iterator<RejoinPlayerData> iterator = _data.iterator();
|
||||
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
RejoinPlayerData data = iterator.next();
|
||||
GameTeam team = data.getTeam();
|
||||
|
||||
if (!UtilTime.elapsed(data.getTime(), _rejoinTime))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
getGame().Announce(team.GetColor() + C.Bold + data.getName() + " did not reconnect in time!", false);
|
||||
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
public void setRejoinTime(int time)
|
||||
{
|
||||
_rejoinTime = time;
|
||||
}
|
||||
|
||||
public int getRejoinTime()
|
||||
{
|
||||
return _rejoinTime;
|
||||
}
|
||||
|
||||
public void stopPlayerFromRejoining(String name)
|
||||
{
|
||||
Iterator<RejoinPlayerData> iterator = _data.iterator();
|
||||
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
RejoinPlayerData data = iterator.next();
|
||||
|
||||
if (data.getName().equals(name))
|
||||
{
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void stopAllPlayersFromRejoining()
|
||||
{
|
||||
getGame().QuitOut = true;
|
||||
_data.clear();
|
||||
}
|
||||
|
||||
public RejoinPlayerData getRejoinPlayerData(String name)
|
||||
{
|
||||
for (RejoinPlayerData data : _data)
|
||||
{
|
||||
if (data.getName().equals(name))
|
||||
{
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Set<RejoinPlayerData> getData()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
public class RejoinPlayerData
|
||||
{
|
||||
private String _name;
|
||||
private double _health;
|
||||
private Kit _kit;
|
||||
private GameTeam _team;
|
||||
private long _time;
|
||||
|
||||
public RejoinPlayerData(String name, double health, Kit kit, GameTeam team)
|
||||
{
|
||||
_name = name;
|
||||
_health = health;
|
||||
_kit = kit;
|
||||
_team = team;
|
||||
_time = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void setHealth(double health)
|
||||
{
|
||||
_health = health;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
public double getHealth()
|
||||
{
|
||||
return _health;
|
||||
}
|
||||
|
||||
public Kit getKit()
|
||||
{
|
||||
return _kit;
|
||||
}
|
||||
|
||||
public GameTeam getTeam()
|
||||
{
|
||||
return _team;
|
||||
}
|
||||
|
||||
public long getTime()
|
||||
{
|
||||
return _time;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -21,17 +21,10 @@ public class VersionModule extends Module
|
||||
{
|
||||
|
||||
private MinecraftVersion _minecraftVersion;
|
||||
private String _kickMessage;
|
||||
|
||||
|
||||
public VersionModule(MinecraftVersion minecraftVersion)
|
||||
{
|
||||
this(minecraftVersion, "You have an outdated client for this game!");
|
||||
}
|
||||
|
||||
public VersionModule(MinecraftVersion minecraftVersion, String kickMessage)
|
||||
{
|
||||
_minecraftVersion = minecraftVersion;
|
||||
_kickMessage = kickMessage;
|
||||
|
||||
for (Player player : UtilServer.getPlayers())
|
||||
{
|
||||
|
@ -33,6 +33,7 @@ import mineplex.core.updater.event.UpdateEvent;
|
||||
import nautilus.game.arcade.game.GameTeam;
|
||||
import nautilus.game.arcade.game.TeamGame;
|
||||
import nautilus.game.arcade.game.modules.Module;
|
||||
import nautilus.game.arcade.game.modules.RejoinModule;
|
||||
import nautilus.game.arcade.game.modules.compass.CompassEntry;
|
||||
import nautilus.game.arcade.game.modules.compass.CompassModule;
|
||||
|
||||
@ -225,17 +226,14 @@ public class CombatLogModule extends Module
|
||||
logoutNpc.getNPC().getWorld().playSound(logoutNpc.getNPC().getLocation(), Sound.HURT_FLESH, 1, 1);
|
||||
logoutNpc.recordDamage(event);
|
||||
|
||||
if (getGame() instanceof TeamGame)
|
||||
getGame().getArcadeManager().runSync(() ->
|
||||
{
|
||||
getGame().getArcadeManager().runSync(() ->
|
||||
CombatLogNPC npc = getLogoutNpc(event.getEntity());
|
||||
if (npc != null)
|
||||
{
|
||||
CombatLogNPC npc = getLogoutNpc(event.getEntity());
|
||||
if (npc != null)
|
||||
{
|
||||
((TeamGame) getGame()).RejoinHealth.put(npc.getPlayerInfo().getName(), npc.getNPC().getHealth());
|
||||
}
|
||||
});
|
||||
}
|
||||
getGame().getModule(RejoinModule.class).getRejoinPlayerData(npc.getPlayerInfo().getName()).setHealth(npc.getNPC().getHealth());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean hasLogoutNpc(Player player)
|
||||
|
Loading…
Reference in New Issue
Block a user