Fix egg smash eggs sometimes stay on the map
This commit is contained in:
parent
89bd325c81
commit
2b362ee4f1
@ -30,6 +30,7 @@ import nautilus.game.arcade.game.games.mineware.challenge.NumberTracker;
|
||||
*/
|
||||
public class ChallengeEggSmash extends Challenge implements NumberTracker
|
||||
{
|
||||
private int _mapStartSize;
|
||||
private static int _smashedEggsGoal = 10;
|
||||
private Map<Player, Integer> _score = new HashMap<>();
|
||||
|
||||
@ -67,6 +68,7 @@ public class ChallengeEggSmash extends Challenge implements NumberTracker
|
||||
@Override
|
||||
public void createMap()
|
||||
{
|
||||
_mapStartSize = getArenaSize();
|
||||
createFloorMapPart();
|
||||
createDragonEggsMapPart();
|
||||
}
|
||||
@ -91,8 +93,8 @@ public class ChallengeEggSmash extends Challenge implements NumberTracker
|
||||
@Override
|
||||
public void onEnd()
|
||||
{
|
||||
_score.clear();
|
||||
remove(EntityType.FALLING_BLOCK);
|
||||
removeDragonEggs();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@ -118,7 +120,7 @@ public class ChallengeEggSmash extends Challenge implements NumberTracker
|
||||
block.getWorld().playEffect(block.getLocation().add(0.5, 0.5, 0.5), Effect.STEP_SOUND, block.getTypeId());
|
||||
block.setType(Material.AIR);
|
||||
|
||||
searchAddNearbyDragonEgg();
|
||||
spawnDragonEgg();
|
||||
showAndIncrementScore(player, block);
|
||||
|
||||
event.setCancelled(true);
|
||||
@ -132,12 +134,7 @@ public class ChallengeEggSmash extends Challenge implements NumberTracker
|
||||
if (!isChallengeValid())
|
||||
return;
|
||||
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (_score.containsKey(player))
|
||||
{
|
||||
_score.remove(player);
|
||||
}
|
||||
_score.remove(event.getPlayer());
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@ -160,30 +157,39 @@ public class ChallengeEggSmash extends Challenge implements NumberTracker
|
||||
{
|
||||
for (int i = 0; i < 9; i++)
|
||||
{
|
||||
Block block = getCenter().getBlock().getRelative(UtilMath.r(getArenaSize() * 2) - (getArenaSize()), 1, UtilMath.r(getArenaSize() * 2) - (getArenaSize()));
|
||||
Block block = getRandomBlock();
|
||||
block.setType(Material.DRAGON_EGG);
|
||||
addBlock(block);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void searchAddNearbyDragonEgg()
|
||||
private void removeDragonEggs()
|
||||
{
|
||||
for (Location map : circle(getCenter(), _mapStartSize, 1, false, false, 0))
|
||||
{
|
||||
Block block = map.getBlock();
|
||||
|
||||
if (block.getType() == Material.DRAGON_EGG)
|
||||
{
|
||||
System.out.println("Removing dragon eggs");
|
||||
block.setTypeIdAndData(0, (byte) 0, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void spawnDragonEgg()
|
||||
{
|
||||
Host.CreatureAllow = true;
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
Block block = getCenter().add(UtilMath.r((getArenaSize() * 2)) - (getArenaSize()), 1, UtilMath.r((getArenaSize() * 2)) - (getArenaSize())).getBlock();
|
||||
Block block = getRandomBlock();
|
||||
|
||||
if (block.getType() == Material.AIR)
|
||||
if (block.isEmpty())
|
||||
{
|
||||
getCenter().getWorld().spawnFallingBlock(block.getLocation().add(0.5, 2, 0.5), Material.DRAGON_EGG, (byte) 0);
|
||||
|
||||
for (int y = 0; y <= 2; y++)
|
||||
{
|
||||
addBlock(block.getRelative(0, y, 0));
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -191,6 +197,14 @@ public class ChallengeEggSmash extends Challenge implements NumberTracker
|
||||
Host.CreatureAllow = false;
|
||||
}
|
||||
|
||||
private Block getRandomBlock()
|
||||
{
|
||||
return getCenter().add(
|
||||
UtilMath.r((getArenaSize() * 2)) - getArenaSize(),
|
||||
1,
|
||||
UtilMath.r((getArenaSize() * 2)) - getArenaSize()).getBlock();
|
||||
}
|
||||
|
||||
private void showAndIncrementScore(Player player, Block block)
|
||||
{
|
||||
int score = _score.get(player) + 1;
|
||||
@ -204,7 +218,7 @@ public class ChallengeEggSmash extends Challenge implements NumberTracker
|
||||
setCompleted(player);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String selectScoreColor(int score)
|
||||
{
|
||||
if (score == 1 || score == 2)
|
||||
|
Loading…
Reference in New Issue
Block a user