Forgot the actual UHC class...

This commit is contained in:
Sam 2016-11-13 12:35:48 +00:00
parent efc73d220f
commit faba1f2369

View File

@ -73,7 +73,6 @@ import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTextBottom;
import mineplex.core.common.util.UtilTextMiddle;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.recharge.Recharge;
@ -112,10 +111,12 @@ public abstract class UHC extends Game
public static final int VIEW_DISTANCE = 5;
// The number of milliseconds after which PVP should be enabled
public static int SAFE_TIME = 600000;
// Initialised in constructor
public static int SAFE_TIME;
// The number of milliseconds after which Deathmatch should start.
public static int MINING_TIME = 1200000;
// Initialised in constructor
public static int MINING_TIME;
// This is the region in which nothing can be done (block placing, flowing,
// etc)
@ -167,8 +168,8 @@ public abstract class UHC extends Game
// Pre-deathmatch
private int _secondsSincePreDeathmatch;
// Pvp
private boolean _hasPvpStarted;
// UHC State
private UHCState _state;
public UHC(ArcadeManager manager)
{
@ -190,6 +191,8 @@ public abstract class UHC extends Game
SAFE_TIME = 600000;
MINING_TIME = 1200000;
_state = UHCState.SAFE;
HideTeamSheep = true;
@ -277,12 +280,12 @@ public abstract class UHC extends Game
@Override
public void Execute(Player caller, String[] args)
{
if (GetState() != GameState.Live)
if (!IsLive())
{
UtilPlayer.message(caller, F.main("Debug", "You can't start the game right now!"));
return;
}
if (_hasPvpStarted)
if (_state.isPVP())
{
UtilPlayer.message(caller, F.main("Debug", "PvP has already been started!"));
return;
@ -610,6 +613,7 @@ public abstract class UHC extends Game
_border.prepare();
Manager.runSyncLater(() -> {
Announce(C.cGreenB + "Generating spawns... there maybe some lag for a few moments");
createSpawns();
}, 5 * 20);
}
@ -650,7 +654,7 @@ public abstract class UHC extends Game
UtilAction.velocity(bottom, UtilAlg.getTrajectory2d(loc, GetSpectatorLocation()), 1.2, true, 0.4, 0, 10, true);
if (Manager.IsAlive(player))
if (IsAlive(player))
{
Manager.GetDamage().NewDamageEvent(player, null, null, DamageCause.CUSTOM, WORLD_BORDER_DAMAGE, false, false, false, "Nether Field", "Vaporize");
@ -688,7 +692,7 @@ public abstract class UHC extends Game
// If nothing else has damaged the NPC, then
// lastDamageCause will be null
Manager.GetDamage().NewDamageEvent(ent, null, null, DamageCause.CUSTOM, WORLD_BORDER_DAMAGE, false, false, false, "Nether Field", "Vaporize");
Manager.GetDamage().NewDamageEvent(ent, null, null, DamageCause.VOID, WORLD_BORDER_DAMAGE, false, false, false, "Nether Field", "Vaporize");
ent.getWorld().playSound(loc, Sound.NOTE_BASS, 2f, 1f);
ent.getWorld().playSound(loc, Sound.NOTE_BASS, 2f, 1f);
@ -708,30 +712,33 @@ public abstract class UHC extends Game
@EventHandler
public void TimeUpdate(UpdateEvent event)
{
if (!IsLive())
if (event.getType() != UpdateType.SEC || !IsLive())
{
return;
if (event.getType() != UpdateType.SEC)
return;
}
if (UtilTime.elapsed(GetStateTime(), SAFE_TIME) && _state == UHCState.SAFE)
{
startPvp();
}
else if (UtilTime.elapsed(GetStateTime(), MINING_TIME) && _state == UHCState.MINING)
{
startPreDeathmatch();
}
}
public void updateActionbar()
{
String message = null;
long timeSinceStart = System.currentTimeMillis() - GetStateTime();
if (timeSinceStart < SAFE_TIME)
{
message = C.cYellow + "PVP enabled in " + UtilTime.MakeStr(SAFE_TIME - timeSinceStart);
}
else if ((int) timeSinceStart / 1000 == SAFE_TIME)
{
startPvp();
message = C.cYellow + "PVP enabled in " + C.Bold + UtilTime.MakeStr(SAFE_TIME - timeSinceStart);
}
else if (timeSinceStart < MINING_TIME)
{
message = C.cRed + "Deathmatch starts in " + UtilTime.MakeStr(MINING_TIME - timeSinceStart);
}
else if ((int) timeSinceStart / 1000 == MINING_TIME)
{
startPreDeathmatch();
message = C.cRed + "Deathmatch starts in " + C.Bold + UtilTime.MakeStr(MINING_TIME - timeSinceStart);
}
if (message != null)
@ -742,15 +749,21 @@ public abstract class UHC extends Game
public void startPvp()
{
if (_hasPvpStarted)
if (_state.isPVP())
{
return;
_hasPvpStarted = true;
UtilTextMiddle.display(null, "PvP has been enabled!", 5, 80, 5);
}
refreshVisability();
_state = UHCState.MINING;
UtilTextMiddle.display(null, C.cYellow + "PvP has been enabled!", 5, 80, 5);
for (Player player : UtilServer.getPlayers())
{
player.playSound(player.getLocation(), Sound.ENDERDRAGON_GROWL, 1f, 1f);
}
DamagePvP = true;
RejoinTime = 300000; // 5 minutes
getModule(CompassModule.class).setGiveCompass(true);
@ -761,6 +774,9 @@ public abstract class UHC extends Game
{
Announce(C.cRedB + "Deathmatch is starting... Players are being teleported!", false);
// Set the state
_state = UHCState.TELEPORTING;
// Freeze all players
for (Player player : GetPlayers(true))
{
@ -768,9 +784,11 @@ public abstract class UHC extends Game
}
// Toggle temporary game settings
TeleportsDisqualify = false;
Damage = false;
// Disable rejoining
RejoinTime = 0;
// Set the border
_border.setSize(DEATHMATCH_ARENA_SIZE, 0);
@ -800,29 +818,49 @@ public abstract class UHC extends Game
}
}
}
}, 20L);
}, GetPlayers(true).size() + 2);
}
public void startDeathmatch()
{
Announce(C.cRedB + "Fight!", false);
// Set the state
_state = UHCState.DEATHMATCH;
for (Player player : UtilServer.getPlayers())
{
player.playSound(player.getLocation(), Sound.ENDERDRAGON_GROWL, 1f, 1f);
}
refreshVisability();
// Unfreeze all players
_freezer.unfreeze();
// Toggle temporary game settings
TeleportsDisqualify = true;
Damage = true;
// Set the border
_border.setSize(0, DEATHMATCH_TIME_SECONDS);
}
public void refreshVisability()
{
for (Player player : GetPlayers(true))
{
for (Player other : GetPlayers(true))
{
player.showPlayer(other);
}
}
}
@EventHandler
public void deathmatchTimer(UpdateEvent event)
{
// Checks to see if it is pre-deathmatch
if (event.getType() != UpdateType.SEC || TeleportsDisqualify)
if (event.getType() != UpdateType.SEC || _state != UHCState.TELEPORTING)
{
return;
}
@ -890,8 +928,7 @@ public abstract class UHC extends Game
{
CombatLogNPC npc = event.getNpc();
ItemStack stack = new ItemBuilder(Material.SKULL_ITEM).setData((byte) 3).setTitle(npc.getPlayerInfo().getTeamColor() + npc.getPlayerInfo().getName() + "'s Head").setPlayerHead(npc
.getPlayerInfo().getName()).build();
ItemStack stack = PlayerHeadModule.getGoldenHead();
npc.getNPC().getWorld().dropItemNaturally(npc.getNPC().getLocation(), stack);
@ -914,7 +951,7 @@ public abstract class UHC extends Game
if (event.getType() != UpdateType.FAST)
return;
if (DamagePvP)
if (_state.isPVP())
return;
WorldData.World.setTime(2000);
@ -1013,8 +1050,6 @@ public abstract class UHC extends Game
game.GetKit(player).ApplyKit(player);
}
_border.setSize(MAX_ARENA_SIZE / 2, MINING_TIME / 1000);
Announce(C.cGreen + C.Bold + "Please wait, you will be teleported soon", false);
_totalPlayers = players.size();
@ -1029,6 +1064,7 @@ public abstract class UHC extends Game
_teleportedPlayers++;
if (_teleportedPlayers >= players.size())
{
_border.setSize(MAX_ARENA_SIZE / 2, MINING_TIME / 1000);
Announce(C.cGreen + C.Bold + "The game will start in 5 seconds", false);
Manager.runSyncLater(() -> {
try
@ -1519,9 +1555,14 @@ public abstract class UHC extends Game
@EventHandler
public void ScoreboardUpdate(UpdateEvent event)
{
if (event != null && event.getType() != UpdateType.FAST)
if (event.getType() != UpdateType.FAST || !InProgress())
{
return;
}
// Take this time to update the actionbar
updateActionbar();
Scoreboard.reset();
Scoreboard.writeNewLine();
@ -1530,7 +1571,7 @@ public abstract class UHC extends Game
{
if (GetPlayers(true).size() < 8)
{
Scoreboard.writeGroup(GetPlayers(true), player -> Pair.create(GetTeam(player).GetColor() + player.getName(), (int) Math.ceil(player.getHealth())), true);
Scoreboard.writeGroup(GetPlayers(true), player -> Pair.create(GetTeam(player).GetColor() + player.getName(), (int) player.getHealth()), true);
}
else
{
@ -1543,7 +1584,7 @@ public abstract class UHC extends Game
{
if (GetPlayers(true).size() < 8)
{
Scoreboard.writeGroup(GetPlayers(true), player -> Pair.create(GetTeam(player).GetColor() + player.getName(), (int) Math.ceil(player.getHealth())), true);
Scoreboard.writeGroup(GetPlayers(true), player -> Pair.create(GetTeam(player).GetColor() + player.getName(), (int) player.getHealth()), true);
}
else
{
@ -1572,9 +1613,12 @@ public abstract class UHC extends Game
double currentBorder = _border.getMaxCords();
Scoreboard.writeNewLine();
Scoreboard.write(C.cYellow + C.Bold + "Borders");
Scoreboard.write("-" + (int) currentBorder + " to " + "+" + (int) currentBorder);
if (InProgress())
{
Scoreboard.writeNewLine();
Scoreboard.write(C.cYellow + C.Bold + "Borders");
Scoreboard.write("-" + (int) currentBorder + " to " + "+" + (int) currentBorder);
}
Scoreboard.draw();
@ -1584,33 +1628,6 @@ public abstract class UHC extends Game
}
}
// @Override
// public boolean CanJoinTeam(GameTeam team)
// {
// return team.GetSize() < 2;
// }
//
// // Ensure 2 players per team
// @Override
// public GameTeam ChooseTeam(Player player)
// {
// GameTeam team = null;
//
// // Random Team
// for (GameTeam gameTeam : GetTeamList())
// {
// if (gameTeam.GetSize() == 1)
// return gameTeam;
//
// if (team == null || gameTeam.GetSize() < team.GetSize())
// {
// team = gameTeam;
// }
// }
//
// return team;
// }
@Override
public double GetKillsGems(Player killer, Player killed, boolean assist)
{
@ -1625,48 +1642,6 @@ public abstract class UHC extends Game
return 200;
}
// @EventHandler
// public void damageCancel(EntityDamageEvent event)
// {
// if (!IsLive())
// event.setCancelled(true);
//
// // Damagee
// Player damagee = null;
// if (event.getEntity() instanceof Player)
// {
// damagee = (Player) event.getEntity();
//
// // Dead
// if (!IsAlive(damagee))
// event.setCancelled(true);
// }
//
// // Damager
// LivingEntity damagerEnt = UtilEvent.GetDamagerEntity(event, true);
//
// if (damagerEnt instanceof Player)
// {
// // PvP
// if (!DamagePvP && damagee != null)
// event.setCancelled(true);
//
// Player damager = (Player) damagerEnt;
//
// // Dead
// if (!IsAlive(damager))
// event.setCancelled(true);
//
// // Same Team
// if (damagee != null)
// if (GetTeam(damager) != null && GetTeam(damagee) != null &&
// GetTeam(damager).equals(GetTeam(damagee)))
// {
// event.setCancelled(true);
// }
// }
// }
public void setViewDistance(int chunks)
{
@ -1680,4 +1655,14 @@ public abstract class UHC extends Game
{
return _border;
}
public enum UHCState
{
SAFE, MINING, TELEPORTING, DEATHMATCH;
public boolean isPVP()
{
return this != SAFE;
}
}
}