Merge remote-tracking branch 'origin/master'

This commit is contained in:
Shaun Bennett 2015-05-12 17:14:57 -05:00
commit bdfffa3a4c
7 changed files with 324 additions and 104 deletions

View File

@ -84,6 +84,7 @@ import mineplex.core.status.ServerStatusManager;
import mineplex.core.task.TaskManager;
import mineplex.core.teleport.Teleport;
import mineplex.core.timing.TimingManager;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.classcombat.Class.ClassManager;
import mineplex.minecraft.game.classcombat.Condition.SkillConditionManager;

View File

@ -139,11 +139,19 @@ public class GameTeam
{
_players.put(player, in ? PlayerState.IN : PlayerState.OUT);
UtilPlayer.message(player, F.main("Team", _color + C.Bold + "You joined " + _name + " Team") + ".");
UtilPlayer.message(player, F.main("Team", _color + C.Bold + "You joined " + _name + " Team."));
VisibilityManager.Instance.refreshPlayerToAll(player);
}
public void DisbandTeam()
{
for (Player player : _players.keySet())
UtilPlayer.message(player, F.main("Team", _color + C.Bold + _name + " Team was disbanded."));
_players.clear();
}
public void RemovePlayer(Player player)
{
_players.remove(player);
@ -375,4 +383,6 @@ public class GameTeam
return _places;
}
}

View File

@ -11,6 +11,7 @@ import nautilus.game.arcade.kit.*;
import nautilus.game.arcade.stats.TeamDeathsStatTracker;
import nautilus.game.arcade.stats.TeamKillsStatTracker;
import org.bukkit.Bukkit;
import org.bukkit.entity.*;
import org.bukkit.event.*;
import org.bukkit.event.player.*;
@ -111,21 +112,39 @@ public abstract class TeamGame extends Game
if (kit != null)
_playerKit.put(event.getPlayer(), kit);
if (RejoinHealth.containsKey(event.getPlayer().getName()))
event.getPlayer().setHealth(RejoinHealth.remove(event.getPlayer().getName()));
// final Player player = event.getPlayer();
// Bukkit.getScheduler().runTaskLater(Manager.getPlugin(), new Runnable()
// {
// @Override
// public void run()
// {
// if (RejoinHealth.containsKey(player.getName()))
// {
// double health = RejoinHealth.remove(player.getName());
// player.setHealth(health);
// player.sendMessage("DEBUG: restored hp to " + health);
// }
// }
// }, 20);
return;
}
}
/*
//Owner Bypass
if (Manager.GetClients().Get(event.getPlayer()).GetRank().Has(Rank.OWNER))
//Do this on Join, not Login, otherwise player no get heal.
@EventHandler
public void playerRejoinGame(PlayerJoinEvent event)
{
if (!InProgress() || QuitOut)
return;
//Disallow
event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, ChatColor.YELLOW + "You cannot join this UHC.");
*/
Player player = event.getPlayer();
if (RejoinHealth.containsKey(player.getName()))
{
double health = RejoinHealth.remove(player.getName());
player.setHealth(health);
}
}
@EventHandler

View File

@ -14,11 +14,9 @@ import org.bukkit.Sound;
import org.bukkit.World.Environment;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftLargeFireball;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Fireball;
import org.bukkit.entity.Ghast;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Monster;
@ -37,6 +35,7 @@ import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
import org.bukkit.event.inventory.PrepareItemCraftEvent;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerKickEvent;
@ -44,6 +43,8 @@ import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.event.player.PlayerPortalEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.ChunkUnloadEvent;
import org.bukkit.inventory.CraftingInventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.ShapedRecipe;
@ -54,7 +55,6 @@ import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.util.Vector;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
@ -65,14 +65,11 @@ import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilEvent;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilWorld;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilTextMiddle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.packethandler.PacketPlayOutWorldBorder;
import mineplex.core.recharge.Recharge;
@ -81,22 +78,30 @@ import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.combat.CombatLog;
import mineplex.minecraft.game.core.combat.event.CombatDeathEvent;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import mineplex.serverdata.Utility;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.TeamGame;
import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.kit.Kit;
import net.minecraft.server.v1_7_R4.EntityLargeFireball;
public class UHC extends TeamGame
{
private NautHashMap<Player, Player> _teamReqs = new NautHashMap<Player, Player>();
private NautHashMap<String, Long> _deathTime = new NautHashMap<String, Long>();
// private NautHashMap<String, Long> _combatTime = new NautHashMap<String, Long>();
private int _yMax = 0;
private boolean _mapLoaded = false;
private double _mapLoadPercent = 0;
private int _chunksPerTick = 2;
private int _chunkTotal;
private Chunk _chunk = null;
private int _chunkX = 0;
private int _chunkZ = 0;
@ -110,7 +115,7 @@ public class UHC extends TeamGame
private long _createTime;
private long _serverTime;
private boolean _mapLoaded = false;
private boolean xrayDebug = false;
@ -211,6 +216,7 @@ public class UHC extends TeamGame
_chunkX = (int) -(_currentBorder / 16);
_chunkZ = (int) -(_currentBorder / 16);
_chunkTotal = (int) ((_currentBorder * 2 / 16) * (_currentBorder * 2 / 16));
WorldData.MinX = -1000;
WorldData.MinZ = -1000;
@ -296,9 +302,6 @@ public class UHC extends TeamGame
double border = (_previousBorder - 0.3D) + distanceMovedSince;
// 24 @ 100+ reduced to 0 at 32-
double borderAttackDist = Math.max(8, (Math.min(100, border) - 28d) / 3d);
for (Player player : UtilServer.getPlayers())
{
Location loc = player.getLocation();
@ -394,18 +397,13 @@ public class UHC extends TeamGame
if (WorldData.World == null)
return;
int chunksPerTick = 20;
if (GetState() != GameState.Recruit)
return;
// Print Debug
if (event.getType() == UpdateType.SLOW)
{
int chunkTotal = (int) ((_currentBorder * 2 / 16) * (_currentBorder * 2 / 16));
int chunksToGo = chunkTotal - _chunksLoaded;
Announce(C.cGreen + C.Bold + "Generating Map: " + ChatColor.RESET
+ UtilTime.MakeStr((long) ((double) chunksToGo / (double) (20 * chunksPerTick) * 1000d), 1) + " Remaining...");
System.out.println("Map Generation: " + _chunksLoaded + "/" + _chunkTotal);
TimingManager.endTotal("UHC Generation", true);
return;
}
@ -416,7 +414,7 @@ public class UHC extends TeamGame
// Timings
TimingManager.startTotal("UHC Generation");
for (int i = 0; i < chunksPerTick; i++)
for (int i = 0; i < _chunksPerTick ; i++)
{
// Unload Previous
// if (_chunk != null)
@ -438,8 +436,6 @@ public class UHC extends TeamGame
}
else
{
Announce(C.cGreen + C.Bold + "Generating Map: " + ChatColor.RESET + "Complete!");
_mapLoaded = true;
System.out.println("Map Loading Finished!");
generateSpawns();
@ -449,10 +445,26 @@ public class UHC extends TeamGame
_chunksLoaded++;
}
_mapLoadPercent = (double)_chunksLoaded / (double)_chunkTotal;
// Timings
TimingManager.stopTotal("UHC Generation");
}
@EventHandler
public void chunkUnload(ChunkUnloadEvent event)
{
//Allow unloading after players in
if (IsLive())
return;
if (WorldData.World != null && event.getWorld().equals(WorldData.World))
{
System.out.println("Disallowing Unload of World");
event.setCancelled(true);
}
}
public void generateSpawns()
{
// Wipe Spawns
@ -473,8 +485,8 @@ public class UHC extends TeamGame
// Dynamically scale distance requirement based on how many teams need to fit
double dist = (2 * _currentBorder) / (Math.sqrt(this.GetPlayers(true).size()) + 3);
// Ensure distance between Teams
while (true)
// Ensure distance between Teams - 500 Attempts
for (int i=0 ; i<500 ; i++)
{
boolean clash = false;
@ -506,8 +518,8 @@ public class UHC extends TeamGame
// Dynamically scale distance requirement based on how many teams need to fit
double dist = (2 * _currentBorder) / (Math.sqrt(GetTeamList().size()) + 3);
// Ensure distance between Teams
while (true)
// Ensure distance between Teams - 500 Attempts
for (int i=0 ; i<500 ; i++)
{
boolean clash = false;
@ -1458,7 +1470,7 @@ public class UHC extends TeamGame
// Not Loaded (but still joinable)
if (!_mapLoaded)
{
return ChatColor.GOLD + "Generating Map...";
return ChatColor.GREEN + "Generating Map (" + C.cWhite + getMapLoadETA() + C.cGreen + ")";
}
return ChatColor.GREEN + "Recruiting";
@ -1638,4 +1650,147 @@ public class UHC extends TeamGame
{
return _mapLoaded;
}
public String getMapLoadPercent()
{
return (int)(_mapLoadPercent * 100) + "%";
}
public String getMapLoadETA()
{
int chunksToGo = _chunkTotal - _chunksLoaded;
return UtilTime.MakeStr((long) ((double)chunksToGo / (double)(2 * 20) * 1000d), 1);
}
@EventHandler(priority = EventPriority.HIGH)
public void teamSelectInteract(PlayerInteractEntityEvent event)
{
if (GetState() != GameState.Recruit)
return;
if (event.getRightClicked() == null)
return;
if (!(event.getRightClicked() instanceof Player))
return;
Player player = event.getPlayer();
//Observer
if (Manager.IsObserver(player))
{
UtilPlayer.message(player, F.main("Game", "Spectators cannot partake in games."));
return;
}
selectTeamMate(player, (Player)event.getRightClicked());
}
@EventHandler
public void teamSelectCommand(PlayerCommandPreprocessEvent event)
{
if (GetState() != GameState.Recruit)
return;
if (!event.getMessage().toLowerCase().startsWith("/team "))
return;
event.setCancelled(true);
Player target = UtilPlayer.searchOnline(event.getPlayer(), event.getMessage().split(" ")[1], true);
if (target == null)
return;
//Observer
if (Manager.IsObserver(event.getPlayer()))
{
UtilPlayer.message(event.getPlayer(), F.main("Game", "Spectators cannot partake in games."));
return;
}
selectTeamMate(event.getPlayer(), target);
}
public void selectTeamMate(Player player, Player ally)
{
//Accept Invite
if (_teamReqs.containsKey(ally) && _teamReqs.get(ally).equals(player))
{
//Remove Prefs
_teamReqs.remove(player);
_teamReqs.remove(ally);
//Inform
UtilPlayer.message(player, F.main("Game", "You accepted " + ally.getName() + "'s Team Request!"));
UtilPlayer.message(ally, F.main("Game", player.getName() + " accepted your Team Request!"));
//Leave Old Teams
if (GetTeam(player) != null)
GetTeam(player).DisbandTeam();
if (GetTeam(ally) != null)
GetTeam(ally).DisbandTeam();
//Get Team
GameTeam team = getEmptyTeam();
//team.SetName(player.getName() + " & " + ally.getName());
//Join Team
SetPlayerTeam(player, team, true);
SetPlayerTeam(ally, team, true);
}
//Send Invite
else
{
//Already on Team with Target
if (GetTeam(player) != null)
if (GetTeam(player).HasPlayer(ally))
return;
//Inform Player
UtilPlayer.message(player, F.main("Game", "You sent a Team Request to " + ally.getName() + "!"));
//Inform Target
if (Recharge.Instance.use(player, "Team Req " + ally.getName(), 2000, false, false))
{
UtilPlayer.message(ally, F.main("Game", player.getName() + " sent you a Team Request!"));
UtilPlayer.message(ally, F.main("Game", "Type " + F.elem("/team " + player.getName()) + " to accept!"));
}
//Add Pref
_teamReqs.put(player, ally);
}
}
@EventHandler
public void teamQuit(PlayerQuitEvent event)
{
if (GetState() != GameState.Recruit)
return;
Player player = event.getPlayer();
if (GetTeam(player) != null)
GetTeam(player).DisbandTeam();
Iterator<Player> teamIter = _teamReqs.keySet().iterator();
while (teamIter.hasNext())
{
Player sender = teamIter.next();
if (sender.equals(player) || _teamReqs.get(sender).equals(player))
teamIter.remove();
}
}
public GameTeam getEmptyTeam()
{
for (GameTeam team : GetTeamList())
{
if (team.GetPlayers(false).isEmpty())
return team;
}
return null;
}
}

View File

@ -35,10 +35,10 @@ import org.bukkit.event.player.PlayerVelocityEvent;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Scoreboard;
import net.minecraft.server.v1_7_R4.Packet;
import net.minecraft.server.v1_7_R4.PacketPlayOutEntityMetadata;
import net.minecraft.server.v1_7_R4.WatchableObject;
import mineplex.core.account.CoreClient;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
@ -70,6 +70,7 @@ import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.games.uhc.UHC;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.KitSorter;
@ -111,6 +112,8 @@ public class GameLobbyManager implements Listener, IPacketHandler
private boolean _handlingPacket = false;
private String _serverName;
private boolean _colorTick = false;
public GameLobbyManager(ArcadeManager manager, PacketHandler packetHandler)
{
Manager = manager;
@ -327,50 +330,52 @@ public class GameLobbyManager implements Listener, IPacketHandler
//UHC
if (game.GetType() == GameType.UHC)
{
if (game.GetTeamList().size() > 1)
{
//Text
WriteTeamLine("", 0, 159, (byte)15);
WriteTeamLine("", 1, 159, (byte)4);
for (int i=0 ; i<game.GetTeamList().size() ; i++)
{
GameTeam team = game.GetTeamList().get(i);
//Circle Math
double lead = i * ((2d * Math.PI)/game.GetTeamList().size());
double sizeMod = 32;
double oX = -Math.sin(lead) * sizeMod;
double oZ = Math.cos(lead) * sizeMod;
//Location
Location entLoc = spawn.clone().add(oX, 0, oZ);
entLoc.setY(_teamDisplay.getY());
//Blocks
SetKitTeamBlocks(entLoc.clone(), 35, team.GetColorData(), _teamBlocks);
entLoc.add(0, 1.5, 0);
entLoc.getChunk().load();
//NPC
Sheep ent = (Sheep)Manager.GetCreature().SpawnEntity(entLoc, EntityType.SHEEP);
ent.setRemoveWhenFarAway(false);
ent.setCustomNameVisible(false);
ent.setColor(DyeColor.getByWoolData(team.GetColorData()));
UtilEnt.Vegetate(ent);
team.SetTeamEntity(ent);
_teams.put(ent, new LobbyEnt(ent, entLoc, team));
}
// if (game.GetTeamList().size() > 1)
// {
// //Text
// WriteTeamLine("", 0, 159, (byte)15);
// WriteTeamLine("", 1, 159, (byte)4);
//
// for (int i=0 ; i<game.GetTeamList().size() ; i++)
// {
// GameTeam team = game.GetTeamList().get(i);
//
// //Circle Math
// double lead = i * ((2d * Math.PI)/game.GetTeamList().size());
// double sizeMod = 32;
// double oX = -Math.sin(lead) * sizeMod;
// double oZ = Math.cos(lead) * sizeMod;
//
// //Location
// Location entLoc = spawn.clone().add(oX, 0, oZ);
// entLoc.setY(_teamDisplay.getY());
//
// //Blocks
// SetKitTeamBlocks(entLoc.clone(), 35, team.GetColorData(), _teamBlocks);
//
// entLoc.add(0, 1.5, 0);
//
// entLoc.getChunk().load();
//
// //NPC
// Sheep ent = (Sheep)Manager.GetCreature().SpawnEntity(entLoc, EntityType.SHEEP);
// ent.setRemoveWhenFarAway(false);
// ent.setCustomNameVisible(false);
//
// ent.setColor(DyeColor.getByWoolData(team.GetColorData()));
//
// UtilEnt.Vegetate(ent);
//
// team.SetTeamEntity(ent);
//
// _teams.put(ent, new LobbyEnt(ent, entLoc, team));
// }
//
// return;
//
// }
return;
}
}
//Standard
@ -916,7 +921,7 @@ public class GameLobbyManager implements Listener, IPacketHandler
Manager.GetGame().GetState() != GameState.Recruit))
{
for (Player player : UtilServer.getPlayers())
player.setScoreboard(Manager.GetGame().GetScoreboard().GetScoreboard());
player.setScoreboard(Manager.GetGame().GetScoreboard().GetScoreboard()); //XXX
}
else
@ -935,7 +940,7 @@ public class GameLobbyManager implements Listener, IPacketHandler
}
}
@EventHandler
//this is called from above
public void ScoreboardSet(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST)
@ -946,6 +951,8 @@ public class GameLobbyManager implements Listener, IPacketHandler
return;
}
_colorTick = !_colorTick;
for (Entry<Player, Scoreboard> entry : _scoreboardMap.entrySet())
{
Objective objective = entry.getValue().getObjective("§l" + "Lobby");
@ -958,9 +965,16 @@ public class GameLobbyManager implements Listener, IPacketHandler
objective.setDisplayName(ChatColor.WHITE + "§lIn Progress...");
}
else
{
if (Manager.GetGame() instanceof UHC && !((UHC)Manager.GetGame()).isMapLoaded())
{
objective.setDisplayName(((UHC)Manager.GetGame()).getMapLoadPercent() + " " + (_colorTick ? ChatColor.GREEN : ChatColor.YELLOW) + "§l" + "Generating Map");
}
else
{
objective.setDisplayName(ChatColor.GREEN + "§l" + "Waiting for Players");
}
}
int line = 15;
@ -1203,23 +1217,44 @@ public class GameLobbyManager implements Listener, IPacketHandler
rankName = Rank.ULTRA.Name;
}
teamName = rankName + teamName;
String rankTeamName = rankName + teamName;
for (Scoreboard scoreboard : GetScoreboards())
{
try
{
scoreboard.getTeam(teamName).addPlayer(player);
scoreboard.getTeam(rankTeamName).addPlayer(player);
}
catch (Exception e)
{
//UHC adds people to teams earlier than usual, which can case this
if (Manager.GetGame() instanceof UHC)
{
try
{
Manager.GetGame().GetScoreboard().GetScoreboard().getTeam(teamName).addPlayer(player);
System.out.println("GameLobbyManager UHC Team Assignment Success");
break;
}
catch(Exception f)
{
System.out.println("GameLobbyManager AddPlayerToScoreboard UHC Error");
System.out.println("[" + teamName + "] adding [" + player.getName() + "]");
System.out.println("Team is Null [" + (Manager.GetGame().GetScoreboard().GetScoreboard().getTeam(teamName) == null) + "]");
}
}
else
{
System.out.println("GameLobbyManager AddPlayerToScoreboard Error");
System.out.println("[" + rankName + teamName + "] adding [" + player.getName() + "]");
System.out.println("Team is Null [" + (scoreboard.getTeam(rankName + teamName) == null) + "]");
System.out.println("[" + rankTeamName + "] adding [" + player.getName() + "]");
System.out.println("Team is Null [" + (scoreboard.getTeam(rankTeamName) == null) + "]");
}
}
}
}
@EventHandler
public void disallowInventoryClick(InventoryClickEvent event)
{

View File

@ -100,7 +100,7 @@ public class WorldData
creator.seed(UtilMath.r(999999999));
creator.environment(Environment.NORMAL);
creator.generateStructures(true);
World = creator.createWorld();
World = WorldUtil.LoadWorld(creator);
}
else
{