Created an "END" event for challenges

This commit is contained in:
Morten 2015-09-25 17:04:47 +02:00
parent 7838ad2bce
commit 59d1a949c4
4 changed files with 88 additions and 65 deletions

View File

@ -12,6 +12,7 @@ import mineplex.core.hologram.Hologram;
import mineplex.core.hologram.Hologram.HologramTarget; import mineplex.core.hologram.Hologram.HologramTarget;
import mineplex.core.projectile.ProjectileUser; import mineplex.core.projectile.ProjectileUser;
import mineplex.minecraft.game.core.condition.Condition.ConditionType; import mineplex.minecraft.game.core.condition.Condition.ConditionType;
import nautilus.game.arcade.game.games.mineware.events.challengeEndEvent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
@ -98,6 +99,7 @@ public abstract class Challenge implements Listener
setupPlayers(); setupPlayers();
Completed.clear(); Completed.clear();
Lost.clear();
StartTime = System.currentTimeMillis(); StartTime = System.currentTimeMillis();
Duration = getMaxTime(); Duration = getMaxTime();
Places = (int) Math.ceil(getChallengers().size() / 2D); Places = (int) Math.ceil(getChallengers().size() / 2D);
@ -240,6 +242,7 @@ public abstract class Challenge implements Listener
_invisPlayers.add(player); _invisPlayers.add(player);
Host.Manager.GetCondition().Factory().Cloak("Completed", player, player, 7777, true, false); Host.Manager.GetCondition().Factory().Cloak("Completed", player, player, 7777, true, false);
} }
Lost.add(player);
Host.LoseLife(player, false); Host.LoseLife(player, false);
UtilInv.Clear(player); UtilInv.Clear(player);
} }

View File

@ -54,6 +54,7 @@ import nautilus.game.arcade.game.SoloGame;
import nautilus.game.arcade.game.GameTeam.PlayerState; import nautilus.game.arcade.game.GameTeam.PlayerState;
import nautilus.game.arcade.game.games.holeinwall.KitNormal; import nautilus.game.arcade.game.games.holeinwall.KitNormal;
import nautilus.game.arcade.game.games.mineware.challenges.*; import nautilus.game.arcade.game.games.mineware.challenges.*;
import nautilus.game.arcade.game.games.mineware.events.challengeEndEvent;
import nautilus.game.arcade.kit.Kit; import nautilus.game.arcade.kit.Kit;
public class MineWare extends SoloGame implements IThrown public class MineWare extends SoloGame implements IThrown
@ -149,28 +150,27 @@ public class MineWare extends SoloGame implements IThrown
public void PopulateOrders() public void PopulateOrders()
{ {
_challenges.add(ChallengePickASide.class); // _challenges.add(ChallengePickASide.class);
_challenges.add(ChallengeKOTL.class); // _challenges.add(ChallengeKOTL.class);
_challenges.add(ChallengeWaveCrush.class); _challenges.add(ChallengeWaveCrush.class);
_challenges.add(ChallengePunchThePig.class); // _challenges.add(ChallengePunchThePig.class);
_challenges.add(ChallengeDogvsCat.class); // _challenges.add(ChallengeDogvsCat.class); // TODO
_challenges.add(ChallengeShootChickens.class); // _challenges.add(ChallengeShootChickens.class);
_challenges.add(ChallengeReverseTag.class); // _challenges.add(ChallengeReverseTag.class);
_challenges.add(ChallengeKangarooJump.class); _challenges.add(ChallengeKangarooJump.class);
_challenges.add(ChallengeMiniOITQ.class); _challenges.add(ChallengeMiniOITQ.class);
_challenges.add(ChallengeMineADiamond.class); // _challenges.add(ChallengeMineADiamond.class);
_challenges.add(ChallengeRushPush.class); // _challenges.add(ChallengeRushPush.class);
_challenges.add(ChallengeBlockLobbers.class); _challenges.add(ChallengeBlockLobbers.class);
_challenges.add(ChallengeStandOnColor.class); // _challenges.add(ChallengeStandOnColor.class);
_challenges.add(ChallengeMilkACow.class); // _challenges.add(ChallengeMilkACow.class);
_challenges.add(ChallengeDragonEgg.class); // _challenges.add(ChallengeDragonEgg.class);
_challenges.add(ChallengeChestLoot.class); // _challenges.add(ChallengeChestLoot.class);
_challenges.add(ChallengeLavaRun.class); // _challenges.add(ChallengeLavaRun.class);
_challenges.add(ChallengeNavigateMaze.class); _challenges.add(ChallengeNavigateMaze.class);
_challenges.add(ChallengeHitTargets.class); // _challenges.add(ChallengeVolleyPig.class);
_challenges.add(ChallengeVolleyPig.class); // _challenges.add(ChallengeSmashOff.class);
_challenges.add(ChallengeSmashOff.class); // _challenges.add(ChallengeTntLauncher.class);
_challenges.add(ChallengeTntLauncher.class);
// _challenges.add(ChallengeHitTargets.class); // _challenges.add(ChallengeHitTargets.class);
//_challenges.add(ChallengeTameTheWolf.class); //_challenges.add(ChallengeTameTheWolf.class);
@ -317,6 +317,7 @@ public class MineWare extends SoloGame implements IThrown
return; return;
// Deregister // Deregister
Bukkit.getServer().getPluginManager().callEvent(new challengeEndEvent(_challenge));
HandlerList.unregisterAll(_challenge); HandlerList.unregisterAll(_challenge);
_challenge.EndOrder(); _challenge.EndOrder();
@ -546,6 +547,7 @@ public class MineWare extends SoloGame implements IThrown
} }
// Deregister // Deregister
Bukkit.getServer().getPluginManager().callEvent(new challengeEndEvent(_challenge));
HandlerList.unregisterAll(_challenge); HandlerList.unregisterAll(_challenge);
_challenge.EndOrder(); _challenge.EndOrder();

View File

@ -11,6 +11,7 @@ import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.game.games.mineware.Challenge; import nautilus.game.arcade.game.games.mineware.Challenge;
import nautilus.game.arcade.game.games.mineware.MineWare; import nautilus.game.arcade.game.games.mineware.MineWare;
import nautilus.game.arcade.game.games.mineware.events.challengeEndEvent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
@ -28,14 +29,13 @@ import org.bukkit.util.Vector;
public class ChallengeWaveCrush extends Challenge public class ChallengeWaveCrush extends Challenge
{ {
private boolean _inProgress = false; private boolean _inProgress = false;
private boolean _endHandling = true;
private int _waveAmount = 0; private int _waveAmount = 0;
private int _waveSpeed = 40; // in ticks private int _waveSpeed = 40; // in ticks
private ArrayList<Integer> _colorList = new ArrayList<Integer>(Arrays.asList(14, 11, 9, 3, 1, 4, 13, 5)); private ArrayList<Integer> _colorList = new ArrayList<Integer>(Arrays.asList(14, 11, 9, 3, 1, 4, 13, 5));
public ChallengeWaveCrush(MineWare host) public ChallengeWaveCrush(MineWare host)
{ {
super(host, ChallengeType.FirstComplete, "Wave Crush", "Avoid the crushing waves!"); super(host, ChallengeType.LastStanding, "Wave Crush", "Avoid the crushing waves!");
} }
@Override @Override
@ -145,7 +145,7 @@ public class ChallengeWaveCrush extends Challenge
} }
} }
} }
if(var % 5 == 0 && (colorPicker != _colorList.size() - 1)) if(var % 4 == 0 && (colorPicker != _colorList.size() - 1))
{ {
colorPicker++; colorPicker++;
} }
@ -153,32 +153,6 @@ public class ChallengeWaveCrush extends Challenge
} }
} }
public void OnChallengeEnd()
{
for(Player player : Host.GetPlayers(true))
{
if(!isDone(player))
{
SetCompleted(player);
}
}
new BukkitRunnable()
{
@Override
public void run()
{
for(Entity fBlocks : Host.WorldData.World.getEntities())
{
if(fBlocks instanceof FallingBlock)
{
fBlocks.remove();
}
}
}
}.runTaskLater(Host.Manager.getPlugin(), 20);
}
@Override @Override
public void onCollide(LivingEntity target, Block block, ProjectileUser data) public void onCollide(LivingEntity target, Block block, ProjectileUser data)
{ {
@ -203,25 +177,6 @@ public class ChallengeWaveCrush extends Challenge
"Wave crush"); "Wave crush");
} }
@EventHandler
public void onEndHandling(UpdateEvent event)
{
if(!Host.IsLive())
{
return;
}
if(event.getType() != UpdateType.TICK)
{
return;
}
if(!_inProgress && _endHandling)
{
Bukkit.broadcastMessage("End event heard!");
OnChallengeEnd();
_endHandling = false;
}
}
public void waveStartingPoint(Block block, int radius) public void waveStartingPoint(Block block, int radius)
{ {
Block pickedBlock = Host.WorldData.World.getBlockAt(block.getX(), block.getY(), block.getZ() - radius); Block pickedBlock = Host.WorldData.World.getBlockAt(block.getX(), block.getY(), block.getZ() - radius);
@ -238,6 +193,34 @@ public class ChallengeWaveCrush extends Challenge
} }
} }
@EventHandler
public void OnChallengeEnd(challengeEndEvent event)
{
Bukkit.broadcastMessage("End event Heard");
for(Player player : Host.GetPlayers(true))
{
if(!isDone(player))
{
SetCompleted(player);
}
}
new BukkitRunnable()
{
@Override
public void run()
{
for(Entity fBlocks : Host.WorldData.World.getEntities())
{
if(fBlocks instanceof FallingBlock)
{
fBlocks.remove();
}
}
}
}.runTaskLater(Host.Manager.getPlugin(), 30);
}
public void waveCreation(final Block block) public void waveCreation(final Block block)
{ {
new BukkitRunnable() new BukkitRunnable()

View File

@ -0,0 +1,35 @@
package nautilus.game.arcade.game.games.mineware.events;
import nautilus.game.arcade.game.games.mineware.Challenge;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class challengeEndEvent extends Event
{
private Challenge _endedChallenge;
private static final HandlerList _handlers = new HandlerList();
public challengeEndEvent(Challenge challenge)
{
this._endedChallenge = challenge;
}
public Challenge getEndedChallenge()
{
return _endedChallenge;
}
public static HandlerList getHandlerList()
{
return _handlers;
}
@Override
public HandlerList getHandlers()
{
return getHandlerList();
}
}