Merge remote-tracking branch 'origin/master'

This commit is contained in:
Shaun Bennett 2014-09-29 17:42:13 -05:00
commit c7d34e70ef
19 changed files with 495 additions and 115 deletions

View File

@ -94,6 +94,14 @@ public class BlockRestore extends MiniPlugin
_blocks.remove(block).restore();
}
public void RestoreAll()
{
for (BlockRestoreData data : _blocks.values())
data.restore();
_blocks.clear();
}
public HashSet<Location> RestoreBlockAround(Material type, Location location, int radius)
{
HashSet<Location> restored = new HashSet<Location>();

View File

@ -112,8 +112,11 @@ public class Menu extends ShopPageBase<CosmeticManager, CosmeticShop>
final GemBooster gemBoosterItem = new GemBooster(Shop.getBoosterEnabled(), Plugin.getInventoryManager().Get(Player).getItemCount("Gem Booster"));
AddButton(6, new ShopItem(
if (DonationManager.Get(Player.getName()).GetBalance(CurrencyType.Coins) >= gemBoosterItem.GetCost(CurrencyType.Coins)
|| (Shop.getBoosterEnabled() && Plugin.getInventoryManager().Get(Player).getItemCount("Gem Booster") > 0))
{
AddButton(6, new ShopItem(
gemBoosterItem.GetDisplayMaterial(),
gemBoosterItem.GetDisplayName(),
gemBoosterItem.GetDescription(),
@ -144,15 +147,11 @@ public class Menu extends ShopPageBase<CosmeticManager, CosmeticShop>
purchaseGemBooster(gemBoosterItem, player);
}
}
);
if (DonationManager.Get(Player.getName()).GetBalance(CurrencyType.Coins) >= gemBoosterItem.GetCost(CurrencyType.Coins))
{
);
}
else
{
AddItem(15, new ShopItem(
AddItem(6, new ShopItem(
gemBoosterItem.GetDisplayMaterial(),
gemBoosterItem.GetDisplayName(),
gemBoosterItem.GetDescription(),

View File

@ -131,7 +131,7 @@ public class PetPage extends ShopPageBase<CosmeticManager, CosmeticShop>
PetTagPage petTagPage = new PetTagPage(Plugin, Shop, ClientManager, DonationManager, "Repairing", Player, pet, petPurchase);
EntityPlayer entityPlayer = ((CraftPlayer)Player).getHandle();
int containerCounter = entityPlayer.nextContainerCounter();
entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(containerCounter, 8, "Repairing", 9, true));
entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(containerCounter, 8, "Repairing", 0, true));
entityPlayer.activeContainer = new AnvilContainer(entityPlayer.inventory, petTagPage.getInventory());
entityPlayer.activeContainer.windowId = containerCounter;
entityPlayer.activeContainer.addSlotListener(entityPlayer);

View File

@ -62,7 +62,10 @@ public class PetTagPage extends ShopPageBase<CosmeticManager, CosmeticShop>
public void SelectTag()
{
if (ChatColor.stripColor(_tagName).length() > 16)
_tagName = ChatColor.stripColor(_tagName);
_tagName = _tagName.replaceAll("[^A-Za-z0-9]", "");
if (_tagName.length() > 16)
{
UtilPlayer.message(Player, F.main(Plugin.GetName(), ChatColor.RED + "Pet name cannot be longer than 16 characters."));
PlayDenySound(Player);

View File

@ -56,6 +56,7 @@ public class MusicGadget extends Gadget
return;
}
//Near Portal
for (Block block : UtilBlock.getInRadius(player.getLocation(), 3).keySet())
{
if (block.getType() == Material.PORTAL)
@ -65,6 +66,28 @@ public class MusicGadget extends Gadget
}
}
//Invalid Location
Block block = player.getLocation().getBlock();
for (int x=-1 ; x<=1 ; x++)
for (int z=-1 ; z<=1 ; z++)
if (!UtilBlock.airFoliage(block.getRelative(x, 0, z)))
{
UtilPlayer.message(player, F.main("Music", "You cannot place a Jukebox here."));
return;
}
//Near Parkour
ArrayList<Block> blocks = new ArrayList<Block>();
blocks.add(block);
GadgetBlockEvent gadgetBlockEvent = new GadgetBlockEvent(this, blocks);
Bukkit.getServer().getPluginManager().callEvent(gadgetBlockEvent);
if (gadgetEvent.isCancelled())
{
UtilPlayer.message(player, F.main("Music", "You cannot place a Jukebox here."));
return;
}
player.getWorld().playEffect(player.getLocation(), Effect.RECORD_PLAY, _id);
_songs.add(new SongData(player.getLocation().getBlock(), _duration));

View File

@ -1,11 +1,6 @@
package mineplex.core.mount.types;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Horse;
import org.bukkit.entity.Horse.Color;
import org.bukkit.entity.Horse.Style;
@ -13,7 +8,6 @@ import org.bukkit.entity.Horse.Variant;
import org.bukkit.event.EventHandler;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.mount.HorseMount;
@ -46,39 +40,39 @@ public class MountFrost extends HorseMount
UtilParticle.PlayParticle(ParticleType.SNOW_SHOVEL, horse.getLocation().add(0, 1, 0), 0.25f, 0.25f, 0.25f, 0.1f, 4);
}
@EventHandler
public void SnowAura(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
for (Horse horse : GetActive().values())
{
//Blocks
double duration = 2000;
HashMap<Block, Double> blocks = UtilBlock.getInRadius(horse.getLocation(), 2.5d);
for (Iterator<Entry<Block, Double>> blockIterator = blocks.entrySet().iterator(); blockIterator.hasNext();)
{
Block block = blockIterator.next().getKey();
HashMap<Block, Double> snowBlocks = UtilBlock.getInRadius(block.getLocation(), 2d);
boolean addSnow = true;
for (Block surroundingBlock : snowBlocks.keySet())
{
if (surroundingBlock.getType() == Material.PORTAL || surroundingBlock.getType() == Material.CACTUS)
{
blockIterator.remove();
addSnow = false;
break;
}
}
if (addSnow)
Manager.getBlockRestore().Snow(block, (byte)1, (byte)1, (long)(duration * (1 + blocks.get(block))), 250, 0);
}
}
}
// @EventHandler
// public void SnowAura(UpdateEvent event)
// {
// if (event.getType() != UpdateType.TICK)
// return;
//
// for (Horse horse : GetActive().values())
// {
// //Blocks
// double duration = 2000;
// HashMap<Block, Double> blocks = UtilBlock.getInRadius(horse.getLocation(), 2.5d);
//
// for (Iterator<Entry<Block, Double>> blockIterator = blocks.entrySet().iterator(); blockIterator.hasNext();)
// {
// Block block = blockIterator.next().getKey();
// HashMap<Block, Double> snowBlocks = UtilBlock.getInRadius(block.getLocation(), 2d);
//
// boolean addSnow = true;
//
// for (Block surroundingBlock : snowBlocks.keySet())
// {
// if (surroundingBlock.getType() == Material.PORTAL || surroundingBlock.getType() == Material.CACTUS)
// {
// blockIterator.remove();
// addSnow = false;
// break;
// }
// }
//
//
// if (addSnow)
// Manager.getBlockRestore().Snow(block, (byte)1, (byte)1, (long)(duration * (1 + blocks.get(block))), 250, 0);
// }
// }
// }
}

View File

@ -275,10 +275,13 @@ public class DDoSProtectionSwitcher
private static void switchServer(final String privateIp, String currentIp, String newIp, String currentGateway,
String newGateway)
{
String cmd = "/home/mineplex/switchBungeeIp.sh";
String cmd = "/usr/bin/ssh";
String args = "-to StrictHostKeyChecking=no -o ServerAliveInterval=10 mineplex@" + privateIp + " -p 5191";
String remoteCmd = "\"sh /home/mineplex/config/switchBungeeIpRemote.sh";
String remoteCmdEnd = "\"";
ProcessRunner pr = new ProcessRunner(new String[] { "/bin/sh", cmd, privateIp, currentIp, newIp,
currentGateway, newGateway });
ProcessRunner pr = new ProcessRunner(new String[] { cmd, args, remoteCmd, currentIp, newIp,
currentGateway, newGateway, remoteCmdEnd });
pr.start(new GenericRunnable<Boolean>()
{
public void run(Boolean error)

View File

@ -12,7 +12,7 @@
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="true"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value=""/>
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_BUILDER_ENABLED" value="true"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${build_files}${BUILD_FILES}\common.xml"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${BUILD_FILES}\common.xml"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,auto,clean"/>
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${workspace_loc:/Mineplex.Hub}"/>

View File

@ -83,6 +83,7 @@ import mineplex.hub.modules.MapManager;
import mineplex.hub.modules.NewsManager;
import mineplex.hub.modules.ParkourManager;
import mineplex.hub.modules.TextManager;
import mineplex.hub.modules.TournamentInviter;
import mineplex.hub.modules.VisibilityManager;
import mineplex.hub.modules.WorldManager;
import mineplex.hub.party.Party;
@ -155,8 +156,9 @@ public class HubManager extends MiniClientPlugin<HubClient>
new MapManager(this);
new WorldManager(this);
new JumpManager(this);
//new UHCManager(this);
//new UHCManager(this);
new TournamentInviter(this);
_news = new NewsManager(this);
_mountManager = new MountManager(_plugin, clientManager, donationManager, blockRestore, _disguiseManager);

View File

@ -0,0 +1,135 @@
package mineplex.hub.modules;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
import mineplex.core.MiniPlugin;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilPlayer;
import mineplex.hub.HubManager;
public class TournamentInviter extends MiniPlugin
{
private String[] invitees = new String[]
{
"Bluestone_FTW",
"adrien5d",
"zed0155",
"SubSonicDPS",
"charger134",
"rensy69",
"ghikft",
"ParaJon",
"Mmmmhbeans",
"Zilcor",
"kwcd",
"orangeguyy",
"kingcamas",
"TheHyperAsian",
"BossesCraftCake",
"Shadowsnippp3r",
"MySquishyTurtle",
"pyrodamage",
"Blazespot1",
"WiiTarted",
"Ghostgunner97",
"bbran21",
"StudlyWafflez",
"FrozenAodC",
"PikaBoyCraft",
"NoNowGetOut",
"CandleBlob",
"sad6boy",
"RacgiMan",
"stafford9",
"Wincraft12",
"13en2000",
};
private String[] backups = new String[]
{
"DeCouto_05",
"krusher430",
"duble11",
"IcyCaress",
"HeroG_ruha",
"TheCherry_Guy",
"Infernova86",
"epicswords02",
"lion2x",
"Brandon_Nish",
"LTplaysminecraft",
"BootFruit",
"Markus4445",
"jamescrafts8",
"iamlinked",
"axle1313",
"KainFTW",
"CreeperRain",
"thomasjinksybean",
"GamerFletch",
"Thepiggyassassin",
"Patu2010",
"Flying_pigglet",
"PowerMovingBacca",
"arduent",
"Aubble",
"MattaTackk22",
"boomdigity102",
"Creeper2341455",
"Amazing105",
};
public TournamentInviter(HubManager manager)
{
super("Map Manager", manager.GetPlugin());
}
@EventHandler
public void PlayerJoin(PlayerJoinEvent event)
{
for (String name : invitees)
{
if (!name.equalsIgnoreCase(event.getPlayer().getName()))
continue;
inviteMessage(event.getPlayer());
}
for (String name : backups)
{
if (!name.equalsIgnoreCase(event.getPlayer().getName()))
continue;
backupMessage(event.getPlayer());
}
}
private void inviteMessage(Player player)
{
UtilPlayer.message(player, C.cBlue + C.Strike + "----------------------------------------------------");
UtilPlayer.message(player, C.cAqua + C.Bold + " Fall Invitational");
UtilPlayer.message(player, "");
UtilPlayer.message(player, C.cWhite + "Congratulations! You have earned an invite to the final event");
UtilPlayer.message(player, C.cWhite + "for the 2014 Fall Invitational on September 27 at 3pm EST!");
UtilPlayer.message(player, "");
UtilPlayer.message(player, C.cWhite + "Please confirm that you can attend at this link;");
UtilPlayer.message(player, C.cGreen + C.Line + "www.tinyurl.com/fallinvitational");
UtilPlayer.message(player, "");
UtilPlayer.message(player, C.cBlue + C.Strike + "----------------------------------------------------");
}
private void backupMessage(Player player)
{
UtilPlayer.message(player, C.cBlue + C.Strike + "----------------------------------------------------");
UtilPlayer.message(player, C.cAqua + C.Bold + " Fall Invitational");
UtilPlayer.message(player, "");
UtilPlayer.message(player, C.cWhite + "You have earned a backup invite to the final event for the");
UtilPlayer.message(player, C.cWhite + "2014 Fall Invitational on September 27 at 3pm EST!");
UtilPlayer.message(player, "");
UtilPlayer.message(player, C.cWhite + "Please confirm that you can attend at this link;");
UtilPlayer.message(player, C.cGreen + C.Line + "www.tinyurl.com/fallinvitational");
UtilPlayer.message(player, "");
UtilPlayer.message(player, C.cBlue + C.Strike + "----------------------------------------------------");
}
}

View File

@ -31,6 +31,7 @@ import org.bukkit.entity.Chicken;
import org.bukkit.entity.Cow;
import org.bukkit.entity.Creature;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Minecart;
import org.bukkit.entity.Pig;
@ -202,6 +203,22 @@ public class WorldManager extends MiniPlugin
event.setCancelled(true);
}
@EventHandler(priority = EventPriority.LOW)
public void ItemDespawn(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
for (Entity ent : UtilWorld.getWorld("world").getEntities())
{
if (!(ent instanceof Item))
continue;
if (ent.getTicksLived() > 600)
ent.remove();
}
}
@EventHandler
public void UpdateWeather(UpdateEvent event)

View File

@ -183,6 +183,10 @@ public class Arcade extends JavaPlugin
{
config.Tournament = Boolean.parseBoolean(tokens[1]);
}
else if (tokens[0].equals("TOURNAMENT_POINTS"))
{
config.TournamentPoints = Boolean.parseBoolean(tokens[1]);
}
else if (tokens[0].equals("TEAM_REJOIN"))
{
config.TeamRejoin = Boolean.parseBoolean(tokens[1]);
@ -289,6 +293,8 @@ public class Arcade extends JavaPlugin
out.write("\nTOURNAMENT=" + config.Tournament + "\n");
out.write("\nTOURNAMENT_POINTS=" + config.TournamentPoints + "\n");
out.write("\nTEAM_REJOIN=" + config.TeamRejoin + "\n");
out.write("TEAM_AUTO_JOIN=" + config.TeamAutoJoin + "\n");
out.write("TEAM_FORCE_BALANCE=" + config.TeamForceBalance + "\n");

View File

@ -96,6 +96,7 @@ import nautilus.game.arcade.managers.GameLootManager;
import nautilus.game.arcade.managers.GameManager;
import nautilus.game.arcade.managers.GamePlayerManager;
import nautilus.game.arcade.managers.GameStatManager;
import nautilus.game.arcade.managers.GameTournamentManager;
import nautilus.game.arcade.managers.GameWorldManager;
import nautilus.game.arcade.managers.IdleManager;
import nautilus.game.arcade.managers.MiscManager;
@ -130,6 +131,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
private GameManager _gameManager;
private GameLobbyManager _gameLobbyManager;
private GamePlayerManager _gamePlayerManager;
private GameTournamentManager _gameTournamentManager;
private GameWorldManager _gameWorldManager;
private ServerStatusManager _serverStatusManager;
private InventoryManager _inventoryManager;
@ -155,8 +157,6 @@ public class ArcadeManager extends MiniPlugin implements IRelation
// Games
private Game _game;
private HashMap<String, String> _tournamentTeam = new HashMap<String, String>();
public ArcadeManager(Arcade plugin, ServerStatusManager serverStatusManager, GameServerConfig serverConfig,
CoreClientManager clientManager, DonationManager donationManager, DamageManager damageManager,
DisguiseManager disguiseManager, Creature creature, Teleport teleport, Blood blood, AntiStack antistack,
@ -247,6 +247,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
new GameFlagManager(this);
_gamePlayerManager = new GamePlayerManager(this);
new GameAchievementManager(this);
_gameTournamentManager = new GameTournamentManager(this);
new GameStatManager(this);
new GameLootManager(this, petManager);
_gameWorldManager = new GameWorldManager(this);
@ -401,6 +402,16 @@ public class ArcadeManager extends MiniPlugin implements IRelation
{
return _gameGemManager;
}
public GamePlayerManager GetGamePlayerManager()
{
return _gamePlayerManager;
}
public GameTournamentManager GetGameTournamentManager()
{
return _gameTournamentManager;
}
public GameWorldManager GetGameWorldManager()
{
@ -486,7 +497,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
+ "|" + ((_game == null || _game.WorldData == null) ? "Unknown" : _game.WorldData.MapName);
//Always Joinable
if (_game.JoinInProgress)
if (_game != null && _game.JoinInProgress)
{
event.setMotd(ChatColor.GREEN + "Recruiting" + extrainformation);
}
@ -530,8 +541,6 @@ public class ArcadeManager extends MiniPlugin implements IRelation
event.setQuitMessage(F.sys("Quit", GetColor(event.getPlayer()) + event.getPlayer().getName()));
else
event.setQuitMessage(null);
_tournamentTeam.remove(event.getPlayer().getName());
}
public Game GetGame()
@ -861,6 +870,11 @@ public class ArcadeManager extends MiniPlugin implements IRelation
{
return _serverConfig.Tournament;
}
public boolean IsTournamentPoints()
{
return _serverConfig.TournamentPoints;
}
public boolean IsTeamRejoin()
{
@ -958,43 +972,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
}
}
}
public void setTournamentTeam(Player player, GameTeam team)
{
if (!IsTeamRejoin())
return;
_tournamentTeam.put(player.getName(), team.GetName());
}
public void rejoinTournamentTeam(Player player)
{
if (_game == null)
return;
if (!_tournamentTeam.containsKey(player.getName()))
return;
GameTeam curPref = _game.GetTeamPreference(player);
if (curPref != null)
return;
GameTeam curTeam = _game.GetTeam(player);
if (curTeam != null)
return;
String teamName = _tournamentTeam.get(player.getName());
for (GameTeam team : _game.GetTeamList())
{
if (team.GetName().equalsIgnoreCase(teamName))
{
_gamePlayerManager.AddTeamPreference(_game, player, team);
break;
}
}
}
public ArcadeRepository getArcadeRepository()
{
return _arcadeRepository;

View File

@ -501,7 +501,7 @@ public abstract class Game implements Listener
Manager.GetLobby().AddPlayerToScoreboards(player, team.GetName().toUpperCase());
//Save Tournament Team
Manager.setTournamentTeam(player, team);
Manager.GetGameTournamentManager().setTournamentTeam(player, team);
}
public GameTeam ChooseTeam(Player player)

View File

@ -14,6 +14,8 @@ public class GameServerConfig
//Flags
public boolean Tournament = false;
public boolean TournamentPoints = false;
public boolean TeamRejoin = false;
public boolean TeamAutoJoin = true;
public boolean TeamForceBalance = true;

View File

@ -1910,6 +1910,7 @@ public class MineStrike extends TeamGame
//Incendiary
_incendiary.clear();
Manager.GetBlockRestore().RestoreAll();
//Restock Ammo
for (Gun gun : _gunsEquipped.keySet())

View File

@ -16,6 +16,7 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilFirework;
@ -113,6 +114,18 @@ public class GameLootManager implements Listener
{
double chance = Math.min(0.5, 0.12 + (System.currentTimeMillis() - _startTime)/3600000d);
if (Manager.GetClients().Get(player).GetRank().Has(Rank.ULTRA))
{
if (Manager.GetClients().Get(player).GetRank().Has(Rank.HERO))
{
chance *= 1.5;
}
else
{
chance *= 1.25;
}
}
if (Math.random() > chance)
return;

View File

@ -485,21 +485,7 @@ public class GameManager implements Listener
}
}
@EventHandler
public void TeamTournamentAutoJoin(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST)
return;
Game game = Manager.GetGame();
if (game == null) return;
if (game.GetState() != GameState.Recruit)
return;
for (Player player : UtilServer.getPlayers())
Manager.rejoinTournamentTeam(player);
}
public boolean PlayerAdd(Game game, Player player, GameTeam team)
{

View File

@ -0,0 +1,210 @@
package nautilus.game.arcade.managers;
import java.util.ArrayList;
import java.util.HashMap;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
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.events.PlayerStateChangeEvent;
import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.game.GameTeam.PlayerState;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Scoreboard;
public class GameTournamentManager implements Listener
{
ArcadeManager Manager;
private HashMap<String, String> _tournamentTeam = new HashMap<String, String>();
private HashMap<String, Integer> _tournamentPoints = new HashMap<String, Integer>();
public GameTournamentManager(ArcadeManager manager)
{
Manager = manager;
Manager.GetPluginManager().registerEvents(this, Manager.GetPlugin());
}
@EventHandler
public void TeamTournamentAutoJoin(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST)
return;
Game game = Manager.GetGame();
if (game == null) return;
if (game.GetState() != GameState.Recruit)
return;
for (Player player : UtilServer.getPlayers())
rejoinTournamentTeam(player);
}
public void setTournamentTeam(Player player, GameTeam team)
{
if (!Manager.IsTeamRejoin())
return;
_tournamentTeam.put(player.getName(), team.GetName());
}
public void rejoinTournamentTeam(Player player)
{
if (Manager.GetGame() == null)
return;
if (!_tournamentTeam.containsKey(player.getName()))
return;
GameTeam curPref = Manager.GetGame().GetTeamPreference(player);
if (curPref != null)
return;
GameTeam curTeam = Manager.GetGame().GetTeam(player);
if (curTeam != null)
return;
String teamName = _tournamentTeam.get(player.getName());
for (GameTeam team : Manager.GetGame().GetTeamList())
{
if (team.GetName().equalsIgnoreCase(teamName))
{
Manager.GetGamePlayerManager().AddTeamPreference(Manager.GetGame(), player, team);
break;
}
}
}
@EventHandler
public void pointsReward(GameStateChangeEvent event)
{
if (!Manager.IsTournamentPoints())
return;
if (event.GetState() != GameState.End)
return;
ArrayList<Player> places = event.GetGame().GetTeamList().get(0).GetPlacements(true);
for (int i=0 ; i<places.size() ; i++)
{
Player player = places.get(i);
int points = places.size() - i;
addTournamentPoints(player, points);
UtilPlayer.message(player,
F.main("Tournament", "You received " + F.elem(points + " Points") + " for placing " + F.elem((i+1)+"/"+places.size()) + "."));
}
}
@EventHandler
public void pointsScoreboard(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
if (!Manager.IsTournamentPoints())
return;
for (Scoreboard scoreboard : Manager.GetLobby().GetScoreboards())
{
Objective objective = scoreboard.getObjective(DisplaySlot.BELOW_NAME);
if (objective == null)
{
objective = scoreboard.registerNewObjective("Points", "dummy");
objective.setDisplaySlot(DisplaySlot.BELOW_NAME);
}
for (Player player : UtilServer.getPlayers())
objective.getScore(player.getName()).setScore(getTournamentPoints(player.getName()));
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void pointsDisplay(GameStateChangeEvent event)
{
if (!Manager.IsTournamentPoints())
return;
if (event.GetState() != GameState.Dead)
return;
ArrayList<String> ranks = new ArrayList<String>();
while (ranks.size() < _tournamentPoints.size())
{
int bestPoints = 0;
String bestPlayer = null;
for (String cur : _tournamentPoints.keySet())
{
if (ranks.contains(cur))
continue;
int points = _tournamentPoints.get(cur);
if (points == 0)
continue;
if (bestPlayer == null || points < bestPoints)
{
bestPlayer = cur;
bestPoints = points;
}
}
if (bestPlayer == null)
break;
ranks.add(bestPlayer);
}
Bukkit.broadcastMessage(C.cBlue + C.Strike + C.Bold + "--------------------------------------------");
for (int i=0 ; i<ranks.size() ; i++)
{
Bukkit.broadcastMessage(C.cGold + getTournamentPoints(ranks.get(i)) + " Points" + " " + C.cWhite + ranks.get(i));
}
Bukkit.broadcastMessage(C.cBlue + C.Strike + C.Bold + "--------------------------------------------");
}
public int getTournamentPoints(String player)
{
if (!_tournamentPoints.containsKey(player))
_tournamentPoints.put(player, 0);
return _tournamentPoints.get(player);
}
public void addTournamentPoints(Player player, int points)
{
_tournamentPoints.put(player.getName(), points + getTournamentPoints(player.getName()));
}
@EventHandler
public void clean(PlayerQuitEvent event)
{
_tournamentTeam.remove(event.getPlayer().getName());
}
}