Update treasure digger to use new set block method and apply minor improvements on chicken attack

This commit is contained in:
Thanos Paravantis 2016-06-10 15:11:48 +03:00
parent 47c4e57ce4
commit 00f14131df
4 changed files with 103 additions and 87 deletions

View File

@ -528,15 +528,13 @@ public class BawkBawkBattles extends TeamGame implements IThrown
} }
} }
@SuppressWarnings("deprecation")
private void removeSolidBlock(Location location) private void removeSolidBlock(Location location)
{ {
Block block = location.getBlock(); Block block = location.getBlock();
if (!block.isEmpty() && _challenge.getData().isModifiedBlock(block)) if (!block.isEmpty() && _challenge.getData().isModifiedBlock(block))
{ {
block.setType(Material.AIR); _challenge.setBlock(block, Material.AIR, (byte) 0);
block.setData((byte) 0);
_challenge.getData().removeModifiedBlock(block); _challenge.getData().removeModifiedBlock(block);
} }
} }
@ -692,7 +690,6 @@ public class BawkBawkBattles extends TeamGame implements IThrown
} }
} }
@SuppressWarnings("deprecation")
private void resetLastChallengeMap() private void resetLastChallengeMap()
{ {
_settings.setCrumbling(false); _settings.setCrumbling(false);
@ -705,7 +702,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
holder.getInventory().clear(); holder.getInventory().clear();
} }
block.setTypeIdAndData(Material.AIR.getId(), (byte) 0, false); _challenge.setBlock(block, Material.AIR, (byte) 0);
} }
} }
@ -921,6 +918,9 @@ public class BawkBawkBattles extends TeamGame implements IThrown
public void endCurrentChallenge() public void endCurrentChallenge()
{ {
if (_challenge == null)
return;
_delay = System.currentTimeMillis(); _delay = System.currentTimeMillis();
_challenge.end(); _challenge.end();
@ -1145,7 +1145,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
if (!_chickenTeam.HasPlayer(player)) if (!_chickenTeam.HasPlayer(player))
return; return;
_chickenAttack.kill(player); _chickenAttack.kill(player, true);
} }
@EventHandler @EventHandler
@ -1195,7 +1195,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
while (bottom.getVehicle() != null) while (bottom.getVehicle() != null)
bottom = bottom.getVehicle(); bottom = bottom.getVehicle();
UtilAction.velocity(bottom, UtilAlg.getTrajectory2d(player, bottom), 1.6, true, 0.8, 0, 10, true); UtilAction.velocity(bottom, UtilAlg.getTrajectory2d(player, bottom), 1.6, true, 0.9, 0, 10, true);
other.playSound(other.getLocation(), Sound.CHICKEN_EGG_POP, 2.0F, 0.5F); other.playSound(other.getLocation(), Sound.CHICKEN_EGG_POP, 2.0F, 0.5F);
} }
} }
@ -1754,7 +1754,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
if (_chickenTeam.HasPlayer(player) && IsAlive(player)) if (_chickenTeam.HasPlayer(player) && IsAlive(player))
{ {
player.playSound(player.getLocation(), Sound.CHICKEN_HURT, 2.0F, 1.0F); player.playSound(player.getLocation(), Sound.CHICKEN_HURT, 2.0F, 1.0F);
player.damage(4.0D); player.damage(5.0D);
if (UtilMath.random.nextBoolean()) if (UtilMath.random.nextBoolean())
{ {

View File

@ -27,6 +27,7 @@ import org.bukkit.scheduler.BukkitRunnable;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.MapUtil; import mineplex.core.common.util.MapUtil;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilInv; import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
@ -453,6 +454,22 @@ public abstract class Challenge implements Listener
Host.Manager.GetCondition().Factory().Cloak(reason, player, player, 7777, true, false); Host.Manager.GetCondition().Factory().Cloak(reason, player, player, 7777, true, false);
} }
@SuppressWarnings("deprecation")
public void setBlock(Block block, Material type, byte data)
{
UtilBlock.setQuick(block.getWorld(), block.getX(), block.getY(), block.getZ(), type.getId(), data);
}
public void setBlock(Block block, Material type)
{
setBlock(block, type, (byte) 0);
}
public void setData(Block block, byte data)
{
setBlock(block, block.getType(), data);
}
protected void addBlock(Block... blocks) protected void addBlock(Block... blocks)
{ {
for (Block block : blocks) for (Block block : blocks)
@ -556,7 +573,6 @@ public abstract class Challenge implements Listener
return block; return block;
} }
@SuppressWarnings("deprecation")
private void makeFlower(Block block) private void makeFlower(Block block)
{ {
Material flower = Material.YELLOW_FLOWER; Material flower = Material.YELLOW_FLOWER;
@ -572,8 +588,7 @@ public abstract class Challenge implements Listener
} }
} }
block.setType(flower); setBlock(block, flower, data);
block.setData(data);
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@ -584,11 +599,8 @@ public abstract class Challenge implements Listener
Block above = block.getRelative(BlockFace.UP); Block above = block.getRelative(BlockFace.UP);
byte plantData = (byte) UtilMath.r(5); byte plantData = (byte) UtilMath.r(5);
block.setType(Material.DOUBLE_PLANT); setBlock(block, Material.DOUBLE_PLANT, plantData);
block.setData(plantData); setBlock(block, Material.DOUBLE_PLANT, (byte) 8);
above.setType(Material.DOUBLE_PLANT);
above.setData((byte) 8);
addBlock(above); addBlock(above);
} }

View File

@ -46,44 +46,44 @@ public class ChallengeTreasureDigger extends Challenge
"Find weapons to kill the others!"); "Find weapons to kill the others!");
Settings.setUseMapHeight(); Settings.setUseMapHeight();
Settings.setMinPlayers(4); Settings.setMinPlayers(2);
_lootChance.put(Material.BONE, 20.0); _lootChance.put(Material.BONE, 0.2);
_lootChance.put(Material.STRING, 20.0); _lootChance.put(Material.STRING, 0.2);
_lootChance.put(Material.WOOD_SWORD, 30.0); _lootChance.put(Material.WOOD_SWORD, 0.3);
_lootChance.put(Material.STONE_SWORD, 20.0); _lootChance.put(Material.STONE_SWORD, 0.2);
_lootChance.put(Material.IRON_SWORD, 10.0); _lootChance.put(Material.IRON_SWORD, 0.1);
_lootChance.put(Material.GOLD_SWORD, 10.0); _lootChance.put(Material.GOLD_SWORD, 0.1);
_lootChance.put(Material.DIAMOND_SWORD, 5.0); _lootChance.put(Material.DIAMOND_SWORD, 0.05);
_lootChance.put(Material.IRON_SPADE, 15.0); _lootChance.put(Material.IRON_SPADE, 0.15);
_lootChance.put(Material.IRON_PICKAXE, 15.0); _lootChance.put(Material.IRON_PICKAXE, 0.15);
_lootChance.put(Material.GOLDEN_APPLE, 5.0); _lootChance.put(Material.GOLDEN_APPLE, 0.05);
_lootChance.put(Material.FISHING_ROD, 10.0); _lootChance.put(Material.FISHING_ROD, 0.1);
_lootChance.put(Material.BOW, 20.0); _lootChance.put(Material.BOW, 0.2);
_lootChance.put(Material.ARROW, 30.0); _lootChance.put(Material.ARROW, 0.3);
_lootChance.put(Material.LEATHER_HELMET, 20.0); _lootChance.put(Material.LEATHER_HELMET, 0.2);
_lootChance.put(Material.LEATHER_CHESTPLATE, 15.0); _lootChance.put(Material.LEATHER_CHESTPLATE, 0.15);
_lootChance.put(Material.LEATHER_LEGGINGS, 12.0); _lootChance.put(Material.LEATHER_LEGGINGS, 0.12);
_lootChance.put(Material.LEATHER_BOOTS, 20.0); _lootChance.put(Material.LEATHER_BOOTS, 0.2);
_lootChance.put(Material.CHAINMAIL_HELMET, 10.0); _lootChance.put(Material.CHAINMAIL_HELMET, 0.1);
_lootChance.put(Material.CHAINMAIL_CHESTPLATE, 5.0); _lootChance.put(Material.CHAINMAIL_CHESTPLATE, 0.05);
_lootChance.put(Material.CHAINMAIL_LEGGINGS, 7.0); _lootChance.put(Material.CHAINMAIL_LEGGINGS, 0.07);
_lootChance.put(Material.CHAINMAIL_BOOTS, 10.0); _lootChance.put(Material.CHAINMAIL_BOOTS, 0.1);
_lootChance.put(Material.IRON_HELMET, 10.0); _lootChance.put(Material.IRON_HELMET, 0.1);
_lootChance.put(Material.IRON_CHESTPLATE, 5.0); _lootChance.put(Material.IRON_CHESTPLATE, 0.05);
_lootChance.put(Material.IRON_LEGGINGS, 7.0); _lootChance.put(Material.IRON_LEGGINGS, 0.07);
_lootChance.put(Material.IRON_BOOTS, 10.0); _lootChance.put(Material.IRON_BOOTS, 0.1);
_lootChance.put(Material.DIAMOND_HELMET, 5.0); _lootChance.put(Material.DIAMOND_HELMET, 0.05);
_lootChance.put(Material.DIAMOND_CHESTPLATE, 2.0); _lootChance.put(Material.DIAMOND_CHESTPLATE, 0.02);
_lootChance.put(Material.DIAMOND_LEGGINGS, 4.0); _lootChance.put(Material.DIAMOND_LEGGINGS, 0.04);
_lootChance.put(Material.DIAMOND_BOOTS, 5.0); _lootChance.put(Material.DIAMOND_BOOTS, 0.05);
_lootContents = _lootChance.keySet().toArray(new Material[_lootChance.keySet().size()]); _lootContents = _lootChance.keySet().toArray(new Material[_lootChance.keySet().size()]);
} }
@ -102,7 +102,6 @@ public class ChallengeTreasureDigger extends Challenge
return spawns; return spawns;
} }
@SuppressWarnings("deprecation")
@Override @Override
public void createMap() public void createMap()
{ {
@ -118,63 +117,62 @@ public class ChallengeTreasureDigger extends Challenge
for (Location location : circle(center, getArenaSize(), 1, false, false, 0)) for (Location location : circle(center, getArenaSize(), 1, false, false, 0))
{ {
Block block = location.getBlock(); Block block = location.getBlock();
double chance = Math.random() * 100; double chance = Math.random();
if (i == 0) if (i == 0)
{ {
block.setType(Material.BEDROCK); setBlock(block, Material.BEDROCK);
} }
else if (i == 1) else if (i == 1)
{ {
block.setType(Material.SAND); if (chance < 0.15)
if (chance < 45.0) // 20%
{
block.setData((byte) 1);
}
if (chance < 25.0) // 10%
{
block.setType(Material.SANDSTONE);
block.setData((byte) 0);
}
if (chance < 15.0) // 15%
{ {
makeChestWithTreasure(block); makeChestWithTreasure(block);
} }
else if (chance < 0.25)
{
setBlock(block, Material.SANDSTONE);
}
else
{
setBlock(block, Material.SAND);
}
} }
else if (i == 2) else if (i == 2)
{ {
block.setType(Material.SAND); if (chance < 0.1)
if (chance < 30.0) // 20%
{ {
block.setData((byte) 1); setBlock(block, Material.SANDSTONE);
} }
else
if (chance < 10.0) // 10%
{ {
block.setType(Material.SANDSTONE); setBlock(block, Material.SAND);
block.setData((byte) 0); chance = Math.random();
if (chance < 0.3)
{
setData(block, (byte) 1);
}
} }
} }
else if (i == 3) else if (i == 3)
{ {
block.setType(Material.SAND); if (chance < 0.1)
if (chance < 10.0) // 10%
{ {
block.setType(Material.SANDSTONE); setBlock(block, Material.SANDSTONE);
}
else
{
setBlock(block, Material.SAND);
} }
} }
else if (i == 4) else if (i == 4)
{ {
Block below = block.getRelative(BlockFace.DOWN); Block below = block.getRelative(BlockFace.DOWN);
if (chance < 1.5 && !createSpawns().contains(block.getLocation()) && below.getType() == Material.SAND) if (chance < 0.015 && below.getType() == Material.SAND)
{ {
block.setType(Material.DEAD_BUSH); setBlock(block, Material.DEAD_BUSH);
} }
} }
@ -274,14 +272,15 @@ public class ChallengeTreasureDigger extends Challenge
} }
} }
@SuppressWarnings("deprecation")
private void makeChestWithTreasure(Block block) private void makeChestWithTreasure(Block block)
{ {
if (!areChestsNearby(block)) if (areChestsNearby(block))
{ {
block.setType(Material.CHEST); setBlock(block, Material.SAND);
block.setData((byte) UtilMath.r(4)); }
else
{
setBlock(block, Material.CHEST, (byte) UtilMath.r(4));
Chest chest = (Chest) block.getState(); Chest chest = (Chest) block.getState();
fillChestWithLoot(chest); fillChestWithLoot(chest);
} }
@ -303,13 +302,13 @@ public class ChallengeTreasureDigger extends Challenge
for (int i = 0; i <= UtilMath.r(2) + 1; i++) for (int i = 0; i <= UtilMath.r(2) + 1; i++)
{ {
double chance = Math.random() * 100; double chance = Math.random();
Material loot = getRandomLootMaterial(); Material loot = getRandomLootMaterial();
double lootChance = getLootChance(loot); double lootChance = getLootChance(loot);
while (chance >= lootChance) while (chance >= lootChance)
{ {
chance = Math.random() * 100; chance = Math.random();
loot = getRandomLootMaterial(); loot = getRandomLootMaterial();
lootChance = getLootChance(loot); lootChance = getLootChance(loot);
} }

View File

@ -73,7 +73,7 @@ public class ChickenAttack
player.teleport(_center); player.teleport(_center);
UtilTextMiddle.display(C.cRed + "Chicken Attack!", "You ran out of lives.", 5, 40, 5, player); UtilTextMiddle.display(C.cRed + "Chicken Attack!", "You ran out of lives.", 5, 40, 5, player);
UtilPlayer.message(player, F.main("Game", "You ran out lives, Bawk Bawk's followers are attacking you!")); UtilPlayer.message(player, F.main("Game", "Bawk Bawk's followers are attacking you!"));
player.playSound(player.getLocation(), Sound.WITHER_SPAWN, 1.0F, 1.0F); player.playSound(player.getLocation(), Sound.WITHER_SPAWN, 1.0F, 1.0F);
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, 1)); player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, 1));
@ -91,7 +91,7 @@ public class ChickenAttack
if (_host.IsLive() && _host.getChickenTeam().HasPlayer(player) && _host.IsAlive(player)) if (_host.IsLive() && _host.getChickenTeam().HasPlayer(player) && _host.IsAlive(player))
{ {
UtilPlayer.message(player, F.main("Game", "You have been moved to spectators.")); UtilPlayer.message(player, F.main("Game", "You have been moved to spectators."));
kill(player); kill(player, false);
} }
else else
{ {
@ -101,10 +101,15 @@ public class ChickenAttack
}.runTaskLater(_plugin, 400L); }.runTaskLater(_plugin, 400L);
} }
public void kill(Player player) public void kill(Player player, boolean inform)
{ {
_host.Manager.Clear(player); _host.Manager.Clear(player);
if (inform)
{
UtilPlayer.message(player, F.main("Game", "You are now spectating, others can see you as a chicken."));
}
new BukkitRunnable() new BukkitRunnable()
{ {
@Override @Override