Redo respawning
This commit is contained in:
parent
f29b855667
commit
4e3bc018e9
@ -18,13 +18,13 @@ public class UtilMath
|
||||
|
||||
public static double trim(int degree, double d)
|
||||
{
|
||||
String format = "#.#";
|
||||
StringBuilder format = new StringBuilder("#.#");
|
||||
|
||||
for (int i = 1; i < degree; i++)
|
||||
format += "#";
|
||||
format.append("#");
|
||||
|
||||
DecimalFormatSymbols symb = new DecimalFormatSymbols(Locale.US);
|
||||
DecimalFormat twoDForm = new DecimalFormat(format, symb);
|
||||
DecimalFormat twoDForm = new DecimalFormat(format.toString(), symb);
|
||||
return Double.valueOf(twoDForm.format(d));
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,8 @@
|
||||
package nautilus.game.arcade.managers;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import net.minecraft.server.v1_8_R3.EntityPlayer;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -44,10 +40,9 @@ import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import mineplex.core.Managers;
|
||||
import mineplex.core.account.permissions.Permission;
|
||||
@ -65,7 +60,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.ItemStackFactory;
|
||||
import mineplex.core.preferences.Preference;
|
||||
import mineplex.core.recharge.Recharge;
|
||||
@ -94,8 +88,6 @@ public class GameFlagManager implements Listener
|
||||
|
||||
final ArcadeManager Manager;
|
||||
private SecondaryDamageManager Secondary;
|
||||
private final Map<Player, Long> _respawnTimers = new HashMap<>();
|
||||
private final Map<Player, Integer> _respawnRunnables = new HashMap<>();
|
||||
|
||||
public GameFlagManager(ArcadeManager manager)
|
||||
{
|
||||
@ -734,117 +726,136 @@ public class GameFlagManager implements Listener
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void PlayerDeath(PlayerDeathEvent event)
|
||||
{
|
||||
final Game game = Manager.GetGame();
|
||||
if (game == null) return;
|
||||
Game game = Manager.GetGame();
|
||||
|
||||
final Player player = event.getEntity();
|
||||
if (game == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//Remove all conditions
|
||||
Player player = event.getEntity();
|
||||
Location location = player.getLocation();
|
||||
|
||||
// Remove all conditions
|
||||
Manager.GetCondition().EndCondition(player, null, null);
|
||||
for (PotionEffect potion : player.getActivePotionEffects())
|
||||
{
|
||||
player.removePotionEffect(potion.getType());
|
||||
}
|
||||
|
||||
//Visual
|
||||
// Manager.GetCondition().Factory().Blind("Ghost", player, player, 2.5, 0, false, false, false);
|
||||
|
||||
player.setFireTicks(0);
|
||||
player.setFallDistance(0);
|
||||
|
||||
//Drop Items
|
||||
// Drop Items
|
||||
if (game.DeathDropItems)
|
||||
for (ItemStack stack : event.getDrops())
|
||||
player.getWorld().dropItem(player.getLocation(), stack);
|
||||
{
|
||||
event.getDrops().forEach(itemStack -> player.getWorld().dropItem(location, itemStack));
|
||||
}
|
||||
|
||||
event.getDrops().clear();
|
||||
|
||||
//DEATH OUT
|
||||
if (game.GetState() == GameState.Live && game.DeathOut)
|
||||
if (!game.IsLive())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Death Out
|
||||
if (game.DeathOut)
|
||||
{
|
||||
//Event
|
||||
PlayerDeathOutEvent outEvent = new PlayerDeathOutEvent(game, player);
|
||||
UtilServer.getServer().getPluginManager().callEvent(outEvent);
|
||||
UtilServer.CallEvent(outEvent);
|
||||
|
||||
if (!outEvent.isCancelled())
|
||||
{
|
||||
game.SetPlayerState(player, PlayerState.OUT);
|
||||
Manager.addSpectator(player, game.DeathTeleport);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//RESPAWN
|
||||
if (game.DeathSpectateSecs <= 0 && (game.GetTeam(player) == null || game.GetTeam(player).GetRespawnTime() <= 0))
|
||||
double respawnTime = game.DeathSpectateSecs;
|
||||
GameTeam team = game.GetTeam(player);
|
||||
|
||||
if (team.GetRespawnTime() > respawnTime)
|
||||
{
|
||||
//Teleport
|
||||
if (game.AutomaticRespawn && game.IsAlive(player))
|
||||
respawnTime = team.GetRespawnTime();
|
||||
}
|
||||
|
||||
// Respawn Now
|
||||
if (respawnTime <= 0)
|
||||
{
|
||||
// Auto handle respawning
|
||||
if (game.AutomaticRespawn)
|
||||
{
|
||||
game.RespawnPlayer(player);
|
||||
}
|
||||
else
|
||||
{
|
||||
Manager.addSpectator(player, game.DeathTeleport);
|
||||
}
|
||||
|
||||
Manager.getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(Manager.getPlugin(), () ->
|
||||
Manager.runSyncLater(() ->
|
||||
{
|
||||
player.setFallDistance(0);
|
||||
player.setFireTicks(0);
|
||||
UtilAction.zeroVelocity(player);
|
||||
}, 0);
|
||||
}
|
||||
//TIMER
|
||||
// Respawn Later
|
||||
else
|
||||
{
|
||||
double time = game.DeathSpectateSecs;
|
||||
if (game.GetTeam(player) != null)
|
||||
if (game.GetTeam(player).GetRespawnTime() > time)
|
||||
time = game.GetTeam(player).GetRespawnTime();
|
||||
|
||||
final double timeF = time;
|
||||
|
||||
UtilInv.Clear(player);
|
||||
Manager.GetCondition().Factory().Cloak("Ghost", player, player, time, false, false);
|
||||
Manager.GetCondition().Factory().Cloak("Ghost", player, player, respawnTime, false, false);
|
||||
player.setAllowFlight(true);
|
||||
player.setFlying(true);
|
||||
((CraftPlayer) player).getHandle().spectating = true;
|
||||
((CraftPlayer) player).getHandle().setGhost(true);
|
||||
((CraftPlayer) player).getHandle().k = false;
|
||||
|
||||
for (int i = 0; i < 9; i++)
|
||||
player.getInventory().setItem(i, new ItemStack(Material.SKULL));
|
||||
EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
|
||||
entityPlayer.spectating = true;
|
||||
entityPlayer.setGhost(true);
|
||||
entityPlayer.k = false;
|
||||
|
||||
UtilAction.velocity(player, new Vector(0, 0, 0), 1, true, 0.4, 0, 1, true);
|
||||
|
||||
if (!game.IsAlive(player))
|
||||
if (!team.IsAlive(player))
|
||||
{
|
||||
Manager.addSpectator(player, game.DeathTeleport);
|
||||
return;
|
||||
}
|
||||
|
||||
if (time > 3)
|
||||
if (respawnTime > 3)
|
||||
{
|
||||
UtilPlayer.message(player, C.cWhite + C.Bold + "You will respawn in " + time + " seconds...");
|
||||
UtilTextMiddle.display(null, "Respawning in " + time + " seconds...", 5, 40, 5, player);
|
||||
UtilTextMiddle.display(null, "Respawning in " + UtilMath.trim(1, respawnTime) + " seconds...", 0, 30, 10, player);
|
||||
}
|
||||
Manager.getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(Manager.getPlugin(), () ->
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
long length = (long) (respawnTime * 1000);
|
||||
|
||||
Manager.runSyncTimer(new BukkitRunnable()
|
||||
{
|
||||
Long t = Double.valueOf(timeF).longValue();
|
||||
_respawnTimers.put(player, System.currentTimeMillis() + UtilTime.convert(t, TimeUnit.SECONDS, TimeUnit.MILLISECONDS));
|
||||
}, 6);
|
||||
int run = Manager.getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(Manager.getPlugin(), () ->
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
//Teleport
|
||||
if (game.IsAlive(player))
|
||||
if (!game.IsLive())
|
||||
{
|
||||
game.RespawnPlayer(player);
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
else
|
||||
|
||||
long left = start + length - System.currentTimeMillis();
|
||||
double percentage = left / (double) length;
|
||||
|
||||
if (left <= 0)
|
||||
{
|
||||
cancel();
|
||||
|
||||
if (!game.IsAlive(player))
|
||||
{
|
||||
Manager.addSpectator(player, game.DeathTeleport);
|
||||
}
|
||||
|
||||
player.setFireTicks(0);
|
||||
UtilAction.zeroVelocity(player);
|
||||
|
||||
_respawnRunnables.remove(player);
|
||||
}, (int) (time * 20d));
|
||||
_respawnRunnables.put(player, run);
|
||||
else if (game.AutomaticRespawn)
|
||||
{
|
||||
game.RespawnPlayer(player);
|
||||
UtilTextBottom.display(C.cGreenB + "Respawned", player);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
UtilTextBottom.displayProgress("Respawning", percentage, UtilTime.MakeStr(left), player);
|
||||
}
|
||||
}
|
||||
}, 0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -990,7 +1001,7 @@ public class GameFlagManager implements Listener
|
||||
}
|
||||
|
||||
//Riding a Projectile, edgecase
|
||||
if (player.getVehicle() != null && player.getVehicle() instanceof Projectile)
|
||||
if (player.getVehicle() instanceof Projectile)
|
||||
{
|
||||
player.getVehicle().remove();
|
||||
player.leaveVehicle();
|
||||
@ -1029,7 +1040,7 @@ public class GameFlagManager implements Listener
|
||||
}
|
||||
else
|
||||
{
|
||||
Manager.GetDamage().NewDamageEvent(player, null, null, DamageCause.VOID, 9001, false, false, false, "Border", "Border Damage");
|
||||
Manager.GetDamage().NewDamageEvent(player, null, null, DamageCause.VOID, 9001, false, true, false, "Border", "Border Damage");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1346,59 +1357,4 @@ public class GameFlagManager implements Listener
|
||||
|
||||
UtilTextMiddle.display(C.cGold + C.Bold + Manager.GetGame().GetType().getName(), "Make sure you accept the Resource Pack", 20, 120, 20, event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void displayRespawnTimer(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.FASTEST)
|
||||
return;
|
||||
|
||||
if (Manager.GetGame() == null)
|
||||
{
|
||||
_respawnTimers.clear();
|
||||
for (Integer r : _respawnRunnables.values())
|
||||
{
|
||||
Bukkit.getScheduler().cancelTask(r);
|
||||
}
|
||||
_respawnRunnables.clear();
|
||||
return;
|
||||
}
|
||||
if (!Manager.GetGame().IsLive())
|
||||
{
|
||||
_respawnTimers.clear();
|
||||
for (Integer r : _respawnRunnables.values())
|
||||
{
|
||||
Bukkit.getScheduler().cancelTask(r);
|
||||
}
|
||||
_respawnRunnables.clear();
|
||||
return;
|
||||
}
|
||||
Iterator<Entry<Player, Long>> respawnIterator = _respawnTimers.entrySet().iterator();
|
||||
while (respawnIterator.hasNext())
|
||||
{
|
||||
Entry<Player, Long> next = respawnIterator.next();
|
||||
Player player = next.getKey();
|
||||
if (!player.isOnline())
|
||||
{
|
||||
respawnIterator.remove();
|
||||
continue;
|
||||
}
|
||||
if (System.currentTimeMillis() >= next.getValue())
|
||||
{
|
||||
respawnIterator.remove();
|
||||
continue;
|
||||
}
|
||||
long sec = UtilTime.convert(next.getValue() - System.currentTimeMillis(), TimeUnit.MILLISECONDS, TimeUnit.SECONDS);
|
||||
ChatColor color = ChatColor.RED;
|
||||
if (sec < 8)
|
||||
{
|
||||
color = ChatColor.YELLOW;
|
||||
}
|
||||
if (sec < 4)
|
||||
{
|
||||
color = ChatColor.GREEN;
|
||||
}
|
||||
UtilTextBottom.display(color + "Respawning In: " + sec + " Seconds", player);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user