Load booster groups for arcade

This commit is contained in:
Shaun Bennett 2016-06-10 16:33:53 -05:00
parent 0a204a3b90
commit ceb4de8b35
10 changed files with 52 additions and 24 deletions

View File

@ -98,19 +98,19 @@ public class BoosterManager extends MiniPlugin
_boosterCache.entrySet().stream()
.filter(entry -> entry.getValue().size() > 0)
.filter(entry -> boosterMap.get(entry.getKey()) == null)
.forEach(entry -> callNextTick(new BoosterDeactivateEvent(entry.getValue().get(0))));
.forEach(entry -> callNextTick(new BoosterDeactivateEvent(entry.getKey(), entry.getValue().get(0))));
for (Map.Entry<String, List<Booster>> entry : boosterMap.entrySet())
{
List<Booster> current = _boosterCache.get(entry.getKey());
if (current == null || current.get(0) == null)
{
callNextTick(new BoosterActivateEvent(entry.getValue().get(0)));
callNextTick(new BoosterActivateEvent(entry.getKey(), entry.getValue().get(0)));
}
else if (!current.get(0).equals(entry.getValue().get(0)))
{
callNextTick(new BoosterDeactivateEvent(current.get(0)));
callNextTick(new BoosterActivateEvent(entry.getValue().get(0)));
callNextTick(new BoosterDeactivateEvent(entry.getKey(), current.get(0)));
callNextTick(new BoosterActivateEvent(entry.getKey(), entry.getValue().get(0)));
}
}
@ -120,9 +120,9 @@ public class BoosterManager extends MiniPlugin
private void tickBoosterCache()
{
for (List<Booster> boosters : _boosterCache.values())
for (Map.Entry<String, List<Booster>> entry : _boosterCache.entrySet())
{
Iterator<Booster> iterator = boosters.iterator();
Iterator<Booster> iterator = entry.getValue().iterator();
boolean removedOne = false;
while (iterator.hasNext())
{
@ -132,11 +132,11 @@ public class BoosterManager extends MiniPlugin
iterator.remove();
removedOne = true;
System.out.println("booster removed from tick");
Bukkit.getPluginManager().callEvent(new BoosterDeactivateEvent(booster));
Bukkit.getPluginManager().callEvent(new BoosterDeactivateEvent(entry.getKey(), booster));
}
else
{
if (removedOne) Bukkit.getPluginManager().callEvent(new BoosterActivateEvent(booster));
if (removedOne) Bukkit.getPluginManager().callEvent(new BoosterActivateEvent(entry.getKey(), booster));
break;
}
}
@ -152,9 +152,9 @@ public class BoosterManager extends MiniPlugin
tickBoosterCache();
}
public Booster getActiveBoosterFromCache(String serverGroup)
public Booster getActiveBoosterFromCache(String boosterGroup)
{
List<Booster> boosters = _boosterCache.get(serverGroup);
List<Booster> boosters = _boosterCache.get(boosterGroup);
if (boosters != null)
{
for (Booster booster : boosters)

View File

@ -9,13 +9,20 @@ import org.bukkit.event.HandlerList;
*/
public class BoosterActivateEvent extends Event
{
private String _boosterGroup;
private Booster _booster;
public BoosterActivateEvent(Booster booster)
public BoosterActivateEvent(String boosterGroup, Booster booster)
{
_boosterGroup = boosterGroup;
_booster = booster;
}
public String getBoosterGroup()
{
return _boosterGroup;
}
public Booster getBooster()
{
return _booster;

View File

@ -9,13 +9,20 @@ import org.bukkit.event.HandlerList;
*/
public class BoosterDeactivateEvent extends Event
{
private String _boosterGroup;
private Booster _booster;
public BoosterDeactivateEvent(Booster booster)
public BoosterDeactivateEvent(String boosterGroup, Booster booster)
{
_boosterGroup = boosterGroup;
_booster = booster;
}
public String getBoosterGroup()
{
return _boosterGroup;
}
public Booster getBooster()
{
return _booster;

View File

@ -160,7 +160,7 @@ public class PersonalServerManager extends MiniPlugin
}
final ServerGroup serverGroup = new ServerGroup(serverName, serverName, host.getName(), ram, cpu, 1, 0, UtilMath.random.nextInt(250) + 19999, true, "arcade.zip", "Arcade.jar", "plugins/Arcade/", minPlayers, maxPlayers,
true, false, false, games, "", "Player", true, event, false, true, false, true, true, false, false, false, false, true, true, true, false, false, "", _us ? Region.US : Region.EU, "", "", "", "");
true, false, false, games, "", "", "Player", true, event, false, true, false, true, true, false, false, false, false, true, true, true, false, false, "", _us ? Region.US : Region.EU, "", "", "", "");
getPlugin().getServer().getScheduler().runTaskAsynchronously(getPlugin(), new Runnable()
{

View File

@ -51,6 +51,7 @@ public class ServerGroup
private String _games;
private String _modes;
private String _boosterGroup;
private String _serverType;
private boolean _addNoCheat;
private boolean _addWorldEdit;
@ -89,6 +90,7 @@ public class ServerGroup
_generateFreeVersions = Boolean.valueOf(data.get("generateFreeVersions"));
_games = data.get("games");
_modes = data.get("modes");
_boosterGroup = data.get("boosterGroup");
_serverType = data.get("serverType");
_addNoCheat = Boolean.valueOf(data.get("addNoCheat"));
_addWorldEdit = Boolean.valueOf(data.get("addWorldEdit"));
@ -119,7 +121,7 @@ public class ServerGroup
}
public ServerGroup(String name, String prefix, String host, int ram, int cpu, int totalServers, int joinable, int portSection, boolean arcade, String worldZip, String plugin, String configPath
, int minPlayers, int maxPlayers, boolean pvp, boolean tournament, boolean tournamentPoints, String games, String modes, String serverType, boolean noCheat, boolean worldEdit, boolean teamRejoin
, int minPlayers, int maxPlayers, boolean pvp, boolean tournament, boolean tournamentPoints, String games, String modes, String boosterGroup, String serverType, boolean noCheat, boolean worldEdit, boolean teamRejoin
, boolean teamAutoJoin, boolean teamForceBalance, boolean gameAutoStart, boolean gameTimeout, boolean rewardGems, boolean rewardItems, boolean rewardStats
, boolean rewardAchievements, boolean hotbarInventory, boolean hotbarHubClock, boolean playerKickIdle, boolean staffOnly, boolean whitelist, String resourcePack, Region region
, String teamServerKey, String portalBottomCornerLocation, String portalTopCornerLocation, String npcName)
@ -143,6 +145,7 @@ public class ServerGroup
_tournamentPoints = tournamentPoints;
_games = games;
_modes = modes;
_boosterGroup = boosterGroup;
_serverType = serverType;
_addNoCheat = noCheat;
_addWorldEdit = worldEdit;
@ -214,6 +217,8 @@ public class ServerGroup
public String getGames() { return _games; }
public String getModes() { return _modes; }
public String getBoosterGroup() { return _boosterGroup; }
public String getServerType() { return _serverType; }
public boolean getAddNoCheat() { return _addNoCheat; }
public boolean getAddWorldEdit() { return _addWorldEdit; }

View File

@ -219,6 +219,7 @@ public class Arcade extends JavaPlugin
try
{
config.ServerGroup = _serverConfiguration.getServerGroup().getName();
config.BoosterGroup = _serverConfiguration.getServerGroup().getBoosterGroup();
config.HostName = _serverConfiguration.getServerGroup().getHost();
config.ServerType = _serverConfiguration.getServerGroup().getServerType();
config.MinPlayers = _serverConfiguration.getServerGroup().getMinPlayers();

View File

@ -319,7 +319,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
new ValentinesGiftManager(plugin, clientManager, _bonusManager.getRewardManager(), inventoryManager, _cosmeticManager.getGadgetManager(), statsManager);
new GameTestingManager(this);
new PlayerDisguiseManager(plugin, _clientManager);
new GameBoosterManager(plugin, boosterManager, disguiseManager, hologramManager, serverConfig);
new GameBoosterManager(plugin, boosterManager, disguiseManager, hologramManager, serverConfig.BoosterGroup);
// Game Addons
new CompassAddon(plugin, this);

View File

@ -56,9 +56,7 @@ public class BoosterPodium extends MiniPlugin
public void updateNpcs()
{
System.out.println("Updating Npcs.");
Booster activeBooster = _gameBoosterManager.getActiveBooster();
System.out.println("Active booster: " + activeBooster);
if (activeBooster != null)
{
if (_activeArmorStand != null)

View File

@ -27,24 +27,27 @@ import java.util.List;
*/
public class GameBoosterManager extends MiniPlugin
{
private GameServerConfig _gameServerConfig;
private String _boosterGroup;
private BoosterManager _boosterManager;
private BoosterPodium _boosterPodium;
public GameBoosterManager(JavaPlugin plugin, BoosterManager boosterManager, DisguiseManager disguiseManager, HologramManager hologramManager, GameServerConfig gameServerConfig)
public GameBoosterManager(JavaPlugin plugin, BoosterManager boosterManager, DisguiseManager disguiseManager, HologramManager hologramManager, String boosterGroup)
{
super("Arcade Boosters", plugin);
_gameServerConfig = gameServerConfig;
_boosterGroup = boosterGroup;
_boosterManager = boosterManager;
_boosterPodium = new BoosterPodium(plugin, this, disguiseManager, hologramManager, new Location(UtilWorld.getWorld("world"), 0, 101.5, -12));
if (boosterGroup != null && boosterGroup.length() > 0)
{
_boosterPodium = new BoosterPodium(plugin, this, disguiseManager, hologramManager, new Location(UtilWorld.getWorld("world"), 0, 101.5, -12));
}
}
public Booster getActiveBooster()
{
return _boosterManager.getActiveBoosterFromCache(_gameServerConfig.ServerGroup);
return _boosterManager.getActiveBoosterFromCache(_boosterGroup);
}
public void attemptTip(Player player)
@ -76,9 +79,15 @@ public class GameBoosterManager extends MiniPlugin
@EventHandler
public void onActivate(BoosterActivateEvent event)
{
System.out.println("booster activate: " + event.getBooster());
Booster booster = event.getBooster();
Bukkit.broadcastMessage(F.main("Booster", F.name(booster.getPlayerName()) + " has activated a booster for " + booster.getMultiplier() + "x Gems!" ));
if (event.getBoosterGroup().equals(_boosterGroup))
{
Bukkit.broadcastMessage(F.main("Booster", F.name(booster.getPlayerName()) + " has activated a booster for " + booster.getMultiplier() + "x Gems!" ));
}
else
{
Bukkit.broadcastMessage(F.main("Booster", F.name(booster.getPlayerName()) + " has activated a booster on " + F.elem(event.getBoosterGroup())));
}
}
@EventHandler

View File

@ -9,6 +9,7 @@ public class GameServerConfig
{
public String ServerGroup = null;
public String ServerType = null;
public String BoosterGroup = null;
public int MinPlayers = -1;
public int MaxPlayers = -1;
public ArrayList<GameType> GameList = new ArrayList<GameType>();