Fix minecart dance double life loss

This commit is contained in:
Thanos Paravantis 2016-04-27 22:09:06 +03:00
parent ddad17855f
commit aff4b6b270
2 changed files with 71 additions and 90 deletions

View File

@ -755,8 +755,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
if (lives > 0) if (lives > 0)
{ {
loseLife(player); _challenge.setLost(player);
taskFailedMessage(player, lives(player));
} }
else else
{ {

View File

@ -8,7 +8,6 @@ import org.bukkit.FireworkEffect.Type;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Minecart; import org.bukkit.entity.Minecart;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -20,6 +19,7 @@ import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilEnt; import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilFirework; import mineplex.core.common.util.UtilFirework;
import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTextMiddle; import mineplex.core.common.util.UtilTextMiddle;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
@ -28,7 +28,6 @@ import nautilus.game.arcade.game.games.mineware.BawkBawkBattles;
import nautilus.game.arcade.game.games.mineware.challenge.Challenge; import nautilus.game.arcade.game.games.mineware.challenge.Challenge;
import nautilus.game.arcade.game.games.mineware.challenge.ChallengeType; import nautilus.game.arcade.game.games.mineware.challenge.ChallengeType;
import net.minecraft.server.v1_8_R3.BlockPosition; import net.minecraft.server.v1_8_R3.BlockPosition;
import net.minecraft.server.v1_8_R3.EntityPlayer;
import net.minecraft.server.v1_8_R3.PacketPlayOutWorldEvent; import net.minecraft.server.v1_8_R3.PacketPlayOutWorldEvent;
public class ChallengeMinecartDance extends Challenge public class ChallengeMinecartDance extends Challenge
@ -38,9 +37,9 @@ public class ChallengeMinecartDance extends Challenge
WAITING, STARTED, ENDED WAITING, STARTED, ENDED
} }
private volatile MinecartDancePhase _phase = MinecartDancePhase.WAITING; private MinecartDancePhase _phase = MinecartDancePhase.WAITING;
private long _timeSinceLastPhase; private long _timeSinceLastPhase;
private boolean _isPlayingMusic = false; private boolean _isPlayingMusic;
private int _availableMinecarts; private int _availableMinecarts;
private HashSet<Minecart> _minecarts = new HashSet<Minecart>(); private HashSet<Minecart> _minecarts = new HashSet<Minecart>();
@ -109,22 +108,18 @@ public class ChallengeMinecartDance extends Challenge
@Override @Override
public void onStart() public void onStart()
{ {
Host.Manager.GetExplosion().SetLiquidDamage(false);
_timeSinceLastPhase = System.currentTimeMillis(); _timeSinceLastPhase = System.currentTimeMillis();
} }
@Override @Override
public void onEnd() public void onEnd()
{ {
Host.Manager.GetExplosion().SetLiquidDamage(true);
if (_isPlayingMusic) if (_isPlayingMusic)
{ {
_isPlayingMusic = false; stopPlayingMusic();
PacketPlayOutWorldEvent packet = new PacketPlayOutWorldEvent(1005, new BlockPosition(getCenter().getBlockX(), getCenter().getBlockY() + 5, getCenter().getBlockZ()), 0, false);
for (Player player : UtilServer.getPlayers())
{
EntityPlayer entity = ((CraftPlayer) player).getHandle();
entity.playerConnection.sendPacket(packet);
}
} }
for (Minecart minecarts : _minecarts) for (Minecart minecarts : _minecarts)
@ -136,7 +131,43 @@ public class ChallengeMinecartDance extends Challenge
} }
@EventHandler @EventHandler
public void onMinecartInteractionUpdate(UpdateEvent event) public void onUpdate(UpdateEvent event)
{
if (!isChallengeValid())
return;
if (_phase == MinecartDancePhase.WAITING && event.getType() == UpdateType.SEC)
{
if (!_isPlayingMusic)
{
startPlayingMusic();
}
spawnRedFireworks();
}
else if (_phase == MinecartDancePhase.STARTED)
{
spawnGreenFireworks();
if (_isPlayingMusic)
{
stopPlayingMusic();
}
spawnMinecarts();
_phase = MinecartDancePhase.ENDED;
startTimerWhenReady();
}
else if (_phase == MinecartDancePhase.ENDED)
{
showMinecartsLeft();
}
}
@EventHandler
public void onInteractionUpdate(UpdateEvent event)
{ {
if (event.getType() != UpdateType.FASTEST) if (event.getType() != UpdateType.FASTEST)
return; return;
@ -160,47 +191,6 @@ public class ChallengeMinecartDance extends Challenge
} }
} }
@EventHandler
public void onMinecartUpdate(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC)
return;
if (!isChallengeValid())
return;
if (_phase == MinecartDancePhase.WAITING)
{
if (!_isPlayingMusic)
{
_isPlayingMusic = true;
startPlayingMusic();
}
spawnRedFireworks();
}
else if (_phase == MinecartDancePhase.STARTED)
{
spawnGreenFireworks();
if (_isPlayingMusic)
{
_isPlayingMusic = false;
stopPlayingMusic();
}
spawnMinecarts();
_phase = MinecartDancePhase.ENDED;
startTimerWhenReady();
}
else
{
showMinecartsLeft();
}
}
@EventHandler @EventHandler
public void onVehicleDamage(VehicleDamageEvent event) public void onVehicleDamage(VehicleDamageEvent event)
{ {
@ -235,9 +225,13 @@ public class ChallengeMinecartDance extends Challenge
for (Minecart minecart : _minecarts) for (Minecart minecart : _minecarts)
{ {
if (!minecart.isEmpty()) if (!minecart.isEmpty())
{
continue; continue;
}
else else
{
count++; count++;
}
} }
return count; return count;
@ -247,12 +241,9 @@ public class ChallengeMinecartDance extends Challenge
{ {
for (Player player : getPlayersIn(true)) for (Player player : getPlayersIn(true))
{ {
if (player.isInsideVehicle()) if (!player.isInsideVehicle())
{
setCompleted(player);
}
else
{ {
setLost(player);
Host.WorldData.World.strikeLightningEffect(player.getLocation()); Host.WorldData.World.strikeLightningEffect(player.getLocation());
} }
} }
@ -275,12 +266,13 @@ public class ChallengeMinecartDance extends Challenge
private void startPlayingMusic() private void startPlayingMusic()
{ {
_isPlayingMusic = true;
PacketPlayOutWorldEvent packet = new PacketPlayOutWorldEvent(1005, new BlockPosition(getCenter().getBlockX(), getCenter().getBlockY() + 5, getCenter().getBlockZ()), 2259, false); PacketPlayOutWorldEvent packet = new PacketPlayOutWorldEvent(1005, new BlockPosition(getCenter().getBlockX(), getCenter().getBlockY() + 5, getCenter().getBlockZ()), 2259, false);
for (Player player : UtilServer.getPlayers()) for (Player player : UtilServer.getPlayers())
{ {
EntityPlayer entity = ((CraftPlayer) player).getHandle(); UtilPlayer.sendPacket(player, packet);
entity.playerConnection.sendPacket(packet);
} }
} }
@ -289,9 +281,13 @@ public class ChallengeMinecartDance extends Challenge
if (_timeSinceLastPhase + 5500 < System.currentTimeMillis()) if (_timeSinceLastPhase + 5500 < System.currentTimeMillis())
{ {
if (UtilMath.r(4) == 0) if (UtilMath.r(4) == 0)
{
_phase = MinecartDancePhase.STARTED; _phase = MinecartDancePhase.STARTED;
}
else else
{
spawnFireworkAtCorners(Color.RED); spawnFireworkAtCorners(Color.RED);
}
} }
else else
{ {
@ -316,18 +312,19 @@ public class ChallengeMinecartDance extends Challenge
private void stopPlayingMusic() private void stopPlayingMusic()
{ {
_isPlayingMusic = false;
PacketPlayOutWorldEvent packet = new PacketPlayOutWorldEvent(1005, new BlockPosition(getCenter().getBlockX(), getCenter().getBlockY() + 5, getCenter().getBlockZ()), 0, false); PacketPlayOutWorldEvent packet = new PacketPlayOutWorldEvent(1005, new BlockPosition(getCenter().getBlockX(), getCenter().getBlockY() + 5, getCenter().getBlockZ()), 0, false);
for (Player player : UtilServer.getPlayers()) for (Player player : UtilServer.getPlayers())
{ {
EntityPlayer entity = ((CraftPlayer) player).getHandle(); UtilPlayer.sendPacket(player, packet);
entity.playerConnection.sendPacket(packet);
} }
} }
private void spawnMinecarts() private void spawnMinecarts()
{ {
for (int i = 0; i < getPlayersIn(true).size() / 2; i++) for (int i = 0; i < Math.round(getPlayersIn(true).size() / 2); i++)
{ {
Minecart minecart = Host.WorldData.World.spawn(getCenter().add(UtilMath.r(getArenaSize(7) * 2) - (getArenaSize(7)), 2, UtilMath.r(getArenaSize(7) * 2) - (getArenaSize(7))), Minecart.class); Minecart minecart = Host.WorldData.World.spawn(getCenter().add(UtilMath.r(getArenaSize(7) * 2) - (getArenaSize(7)), 2, UtilMath.r(getArenaSize(7) * 2) - (getArenaSize(7))), Minecart.class);
UtilEnt.ghost(minecart, true, false); UtilEnt.ghost(minecart, true, false);
@ -337,10 +334,14 @@ public class ChallengeMinecartDance extends Challenge
private void startTimerWhenReady() private void startTimerWhenReady()
{ {
if (getPlayersIn(false).size() >= 10) if (getPlayersIn(true).size() >= 10)
startTimer(Math.round(getPlayersIn(false).size() / 2)); {
startTimer(Math.round(getPlayersIn(true).size() / 2));
}
else else
startTimer(Math.round(5)); {
startTimer(5);
}
} }
private void showMinecartsLeft() private void showMinecartsLeft()
@ -379,31 +380,12 @@ public class ChallengeMinecartDance extends Challenge
{ {
if (_phase == MinecartDancePhase.ENDED) if (_phase == MinecartDancePhase.ENDED)
{ {
for (Player player : getPlayersIn(true)) playersLooseIfOutsideMinecart();
{
if (!player.isInsideVehicle())
{
Host.WorldData.World.strikeLightningEffect(player.getLocation());
setLost(player);
// UtilPlayer.message(player, F.main("Minecart Dance", "You didn't make it inside a Minecart in time!"));
}
}
_timeSinceLastPhase = System.currentTimeMillis(); _timeSinceLastPhase = System.currentTimeMillis();
_phase = MinecartDancePhase.WAITING; _phase = MinecartDancePhase.WAITING;
for (Minecart minecarts : _minecarts) removeAndClearMinecarts();
{
if (!minecarts.isEmpty())
{
minecarts.eject();
}
minecarts.remove();
}
_minecarts.clear();
} }
else else
{ {