Update Treasure Digger, improved chest loot and map creation. Code refactoring on several challenges.

This commit is contained in:
Thanos paravantis 2015-11-14 11:23:25 +02:00
parent f242919759
commit 5ca96b5614
6 changed files with 420 additions and 435 deletions

View File

@ -30,7 +30,6 @@ import nautilus.game.arcade.game.SoloGame;
import nautilus.game.arcade.game.games.holeinwall.KitNormal; import nautilus.game.arcade.game.games.holeinwall.KitNormal;
import nautilus.game.arcade.game.games.mineware.challenges.ChallengeAnvilDance; import nautilus.game.arcade.game.games.mineware.challenges.ChallengeAnvilDance;
import nautilus.game.arcade.game.games.mineware.challenges.ChallengeBlockRunner; import nautilus.game.arcade.game.games.mineware.challenges.ChallengeBlockRunner;
import nautilus.game.arcade.game.games.mineware.challenges.ChallengeEvolutionOfCombat;
import nautilus.game.arcade.game.games.mineware.challenges.ChallengeFallingBlocks; import nautilus.game.arcade.game.games.mineware.challenges.ChallengeFallingBlocks;
import nautilus.game.arcade.game.games.mineware.challenges.ChallengeFastFood; import nautilus.game.arcade.game.games.mineware.challenges.ChallengeFastFood;
import nautilus.game.arcade.game.games.mineware.challenges.ChallengeTreasureDigger; import nautilus.game.arcade.game.games.mineware.challenges.ChallengeTreasureDigger;
@ -147,11 +146,11 @@ public class MineWare extends SoloGame implements IThrown
public void PopulateOrders() public void PopulateOrders()
{ {
_challenges.add(ChallengeTreasureDigger.class); _challenges.add(ChallengeTreasureDigger.class);
// _challenges.add(ChallengeFastFood.class); _challenges.add(ChallengeFastFood.class);
// _challenges.add(ChallengeEvolutionOfCombat.class); // _challenges.add(ChallengeEvolutionOfCombat.class);
// _challenges.add(ChallengeBlockRunner.class); _challenges.add(ChallengeBlockRunner.class);
// _challenges.add(ChallengeAnvilDance.class); _challenges.add(ChallengeAnvilDance.class);
// _challenges.add(ChallengeFallingBlocks.class); _challenges.add(ChallengeFallingBlocks.class);
// _challenges.add(ChallengeWaveCrush.class); // _challenges.add(ChallengeWaveCrush.class);
// _challenges.add(ChallengePickASide.class); // _challenges.add(ChallengePickASide.class);

View File

@ -24,6 +24,7 @@ import org.bukkit.entity.Item;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
@ -93,7 +94,61 @@ public class ChallengeAnvilDance extends Challenge
} }
} }
private void startItemClearTask() @Override
public void setupPlayers()
{
checkInvalidFallingBlocksTask();
startFallingTask();
startDancingTask();
}
@Override
public void cleanupRoom()
{
_paused = false;
for(Block block : _landedAnvils)
{
block.setType(Material.AIR);
}
_landedAnvils.clear();
_fallingAnvils.clear();
for(Entity entity : Host.WorldData.World.getEntities())
{
if(entity instanceof FallingBlock || entity instanceof Item)
{
entity.remove();
}
}
}
@EventHandler
public void onItemSpawn(ItemSpawnEvent event)
{
event.setCancelled(true);
}
@EventHandler
public void onEntityChangeBlockEvent(final EntityChangeBlockEvent event)
{
if(!Host.IsLive() || !Host.isChallengeStarted())
return;
if(event.getEntity() instanceof FallingBlock)
{
Block block = event.getBlock();
if(!_landedAnvils.contains(block))
{
_fallingAnvils.remove(event.getEntity());
_landedAnvils.add(block);
}
}
}
private void checkInvalidFallingBlocksTask()
{ {
new BukkitRunnable() new BukkitRunnable()
{ {
@ -106,11 +161,15 @@ public class ChallengeAnvilDance extends Challenge
return; return;
} }
for(Entity entity : Host.WorldData.World.getEntities()) Iterator<FallingBlock> blocks = _fallingAnvils.iterator();
while(blocks.hasNext())
{ {
if(entity instanceof Item && entity.isValid()) FallingBlock block = blocks.next();
if(!block.isValid())
{ {
entity.remove(); blocks.remove();
} }
} }
} }
@ -136,22 +195,6 @@ public class ChallengeAnvilDance extends Challenge
}.runTaskTimer(Host.getArcadeManager().getPlugin(), 20L, 1L); }.runTaskTimer(Host.getArcadeManager().getPlugin(), 20L, 1L);
} }
@SuppressWarnings("deprecation")
private void createAnvil()
{
Location center = new Location(Host.WorldData.World, 0, UtilMath.r(3) + WaveHeight, 0);
ArrayList<Location> locations = UtilShapes.getCircle(center, false, getArenaSize());
Location random = locations.get(UtilMath.r(locations.size()));
World world = random.getWorld();
final FallingBlock block = world.spawnFallingBlock(random, Material.ANVIL, (byte) UtilMath.r(3));
block.setDropItem(false);
damageNearby(block);
_fallingAnvils.add(block);
}
private void startDancingTask() private void startDancingTask()
{ {
new BukkitRunnable() new BukkitRunnable()
@ -198,32 +241,20 @@ public class ChallengeAnvilDance extends Challenge
}.runTaskTimer(Host.getArcadeManager().getPlugin(), 100L, DanceDelay * 20); }.runTaskTimer(Host.getArcadeManager().getPlugin(), 100L, DanceDelay * 20);
} }
private void checkInvalidFallingBlocksTask() @SuppressWarnings("deprecation")
private void createAnvil()
{ {
new BukkitRunnable() Location center = new Location(Host.WorldData.World, 0, UtilMath.r(3) + WaveHeight, 0);
{ ArrayList<Location> locations = UtilShapes.getCircle(center, false, getArenaSize());
@Override
public void run()
{
if(!Host.IsLive() || !Host.isChallengeStarted())
{
cancel();
return;
}
Iterator<FallingBlock> blocks = _fallingAnvils.iterator(); Location random = locations.get(UtilMath.r(locations.size()));
while(blocks.hasNext()) World world = random.getWorld();
{ final FallingBlock block = world.spawnFallingBlock(random, Material.ANVIL, (byte) UtilMath.r(3));
FallingBlock block = blocks.next(); block.setDropItem(false);
damageNearby(block);
if(!block.isValid()) _fallingAnvils.add(block);
{
blocks.remove();
}
}
}
}.runTaskTimer(Host.getArcadeManager().getPlugin(), 0L, 1L);
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@ -320,53 +351,4 @@ public class ChallengeAnvilDance extends Challenge
} }
}.runTaskTimer(Host.getArcadeManager().getPlugin(), 0L, 1L); }.runTaskTimer(Host.getArcadeManager().getPlugin(), 0L, 1L);
} }
@Override
public void setupPlayers()
{
startItemClearTask();
checkInvalidFallingBlocksTask();
startFallingTask();
startDancingTask();
}
@Override
public void cleanupRoom()
{
_paused = false;
for(Block block : _landedAnvils)
{
block.setType(Material.AIR);
}
_landedAnvils.clear();
_fallingAnvils.clear();
for(Entity entity : Host.WorldData.World.getEntities())
{
if(entity instanceof FallingBlock || entity instanceof Item)
{
entity.remove();
}
}
}
@EventHandler
public void onEntityChangeBlockEvent(final EntityChangeBlockEvent event)
{
if(!Host.IsLive() || !Host.isChallengeStarted())
return;
if(event.getEntity() instanceof FallingBlock)
{
Block block = event.getBlock();
if(!_landedAnvils.contains(block))
{
_fallingAnvils.remove(event.getEntity());
_landedAnvils.add(block);
}
}
}
} }

View File

@ -87,18 +87,6 @@ public class ChallengeBlockRunner extends Challenge
} }
} }
private void setupInventoryContents(Player player)
{
ArrayList<Material> shuffledMaterials = new ArrayList<Material>(Arrays.asList(_materials));
Collections.shuffle(shuffledMaterials);
for(Material material : shuffledMaterials)
{
ItemStack itemStack = new ItemStack(material, InventoryBlockAmount);
player.getInventory().addItem(itemStack);
}
}
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Override @Override
public void cleanupRoom() public void cleanupRoom()
@ -183,6 +171,18 @@ public class ChallengeBlockRunner extends Challenge
} }
} }
private void setupInventoryContents(Player player)
{
ArrayList<Material> shuffledMaterials = new ArrayList<Material>(Arrays.asList(_materials));
Collections.shuffle(shuffledMaterials);
for(Material material : shuffledMaterials)
{
ItemStack itemStack = new ItemStack(material, InventoryBlockAmount);
player.getInventory().addItem(itemStack);
}
}
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private void blockBreakEffect(Block block) private void blockBreakEffect(Block block)
{ {

View File

@ -21,20 +21,20 @@ import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.FallingBlock; import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockFadeEvent; import org.bukkit.event.block.BlockFadeEvent;
import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
public class ChallengeFallingBlocks extends Challenge public class ChallengeFallingBlocks extends Challenge
{ {
// The chance of an anvil to spawn in a single block. // The chance of an anvil to spawn in a single block.
private static final int SpawnChance = 15; private static final double SpawnChance = 20.0;
// The amount of times the spawn chance will increment after each wave. // The amount of times the spawn chance will increment after each wave.
private static final int IncrementRate = 5; private static final double IncrementRate = 5.0;
// The map height where all anvil waves will spawn. // The map height where all anvil waves will spawn.
private static final double WaveHeight = 10.0; private static final double WaveHeight = 10.0;
@ -49,7 +49,7 @@ public class ChallengeFallingBlocks extends Challenge
private int _wavesCompleted; private int _wavesCompleted;
// After each wave, the anvil spawn chance increases. // After each wave, the anvil spawn chance increases.
private int _modifiedSpawnChance; private double _modifiedSpawnChance;
// The remaining number of blocks before they dissapear. // The remaining number of blocks before they dissapear.
private HashSet<Block> _remaining = new HashSet<Block>(); private HashSet<Block> _remaining = new HashSet<Block>();
@ -117,28 +117,83 @@ public class ChallengeFallingBlocks extends Challenge
} }
} }
private void startItemClearTask() @Override
public void setupPlayers()
{ {
new BukkitRunnable() // startItemClearTask();
{ startWavesTask();
@Override startWaveTimerTask();
public void run() }
{
if(!Host.IsLive() || !Host.isChallengeStarted())
{
cancel();
return;
}
for(Entity entity : Host.WorldData.World.getEntities()) @Override
{ public void cleanupRoom()
if(entity instanceof Item && entity.isValid()) {
{ _time = 0;
entity.remove(); _wavesCompleted = 0;
} _modifiedSpawnChance = 0;
}
for(Block block : _remaining)
{
block.setType(Material.AIR);
}
_remaining.clear();
for(Entity entity : Host.WorldData.World.getEntities())
{
if(entity instanceof FallingBlock)
{
entity.remove();
} }
}.runTaskTimer(Host.getArcadeManager().getPlugin(), 0L, 1L); }
}
@EventHandler
public void onItemSpawn(ItemSpawnEvent event)
{
event.setCancelled(true);
}
@EventHandler
public void onEntityChangeBlockEvent(final EntityChangeBlockEvent event)
{
if(!Host.IsLive() || !Host.isChallengeStarted())
return;
if(event.getEntity() instanceof FallingBlock)
{
final Block block = event.getBlock();
_remaining.add(block);
new BukkitRunnable()
{
@Override
public void run()
{
if(!Host.IsLive() || !Host.isChallengeStarted())
{
cancel();
return;
}
UtilParticle.PlayParticle(ParticleType.BLOCK_CRACK.getParticle(block.getType(), 0), block.getLocation(), 0.3F, 0.3F, 0.3F, 0.0F,
3, ViewDist.LONG, UtilServer.getPlayers());
block.setType(Material.AIR);
_remaining.remove(block);
}
}.runTaskLater(Host.getArcadeManager().getPlugin(), 40L);
}
}
@EventHandler
public void onBlockFade(BlockFadeEvent event)
{
if(!Host.IsLive() || !Host.isChallengeStarted())
return;
if(event.getNewState().getType() == Material.DIRT || event.getNewState().getType() == Material.GRASS)
event.setCancelled(true);
} }
private void startWavesTask() private void startWavesTask()
@ -159,42 +214,6 @@ public class ChallengeFallingBlocks extends Challenge
}.runTaskTimer(Host.getArcadeManager().getPlugin(), 20 * NextWave, 20 * NextWave); }.runTaskTimer(Host.getArcadeManager().getPlugin(), 20 * NextWave, 20 * NextWave);
} }
private void createWave()
{
if(_modifiedSpawnChance < 100)
_modifiedSpawnChance += IncrementRate;
_wavesCompleted++;
Sound nextSound = _sounds[UtilMath.r(_sounds.length)];
for(Player player : Host.GetPlayers(true))
{
player.playSound(player.getLocation(), nextSound, 1.0F, 1.5F);
}
Location center = new Location(Host.WorldData.World, 0, WaveHeight, 0);
for(Location location : UtilShapes.getCircle(center, false, getArenaSize()))
{
if(UtilMath.r(100) <= _modifiedSpawnChance)
{
createFallingBlock(location);
}
}
// Prevent camping
for(Player player : Host.GetPlayers(true))
{
Location camp = player.getLocation();
if(camp.getY() >= 1 && camp.getY() <= 3)
{
createFallingBlock(new Location(Host.WorldData.World, camp.getX(), WaveHeight, camp.getZ()));
}
}
}
private void startWaveTimerTask() private void startWaveTimerTask()
{ {
new BukkitRunnable() new BukkitRunnable()
@ -230,6 +249,42 @@ public class ChallengeFallingBlocks extends Challenge
}.runTaskTimer(Host.getArcadeManager().getPlugin(), 0L, 20L); }.runTaskTimer(Host.getArcadeManager().getPlugin(), 0L, 20L);
} }
private void createWave()
{
if(_modifiedSpawnChance < 100.0)
_modifiedSpawnChance += IncrementRate;
_wavesCompleted++;
Sound nextSound = _sounds[UtilMath.r(_sounds.length)];
for(Player player : Host.GetPlayers(true))
{
player.playSound(player.getLocation(), nextSound, 1.0F, 1.5F);
}
Location center = new Location(Host.WorldData.World, 0, WaveHeight, 0);
for(Location location : UtilShapes.getCircle(center, false, getArenaSize()))
{
if(Math.random() * 100 <= _modifiedSpawnChance)
{
createFallingBlock(location);
}
}
// Prevent camping
for(Player player : Host.GetPlayers(true))
{
Location camp = player.getLocation();
if(camp.getY() >= 1 && camp.getY() <= 3)
{
createFallingBlock(new Location(Host.WorldData.World, camp.getX(), WaveHeight, camp.getZ()));
}
}
}
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private void createFallingBlock(Location location) private void createFallingBlock(Location location)
{ {
@ -276,77 +331,4 @@ public class ChallengeFallingBlocks extends Challenge
} }
}.runTaskTimer(Host.getArcadeManager().getPlugin(), 0L, 1L); }.runTaskTimer(Host.getArcadeManager().getPlugin(), 0L, 1L);
} }
@Override
public void setupPlayers()
{
startItemClearTask();
startWavesTask();
startWaveTimerTask();
}
@Override
public void cleanupRoom()
{
_time = 0;
_wavesCompleted = 0;
_modifiedSpawnChance = 0;
for(Block block : _remaining)
{
block.setType(Material.AIR);
}
_remaining.clear();
for(Entity entity : Host.WorldData.World.getEntities())
{
if(entity instanceof FallingBlock)
{
entity.remove();
}
}
}
@EventHandler
public void onEntityChangeBlockEvent(final EntityChangeBlockEvent event)
{
if(!Host.IsLive() || !Host.isChallengeStarted())
return;
if(event.getEntity() instanceof FallingBlock)
{
final Block block = event.getBlock();
_remaining.add(block);
new BukkitRunnable()
{
@Override
public void run()
{
if(!Host.IsLive() || !Host.isChallengeStarted())
{
cancel();
return;
}
UtilParticle.PlayParticle(ParticleType.BLOCK_CRACK.getParticle(block.getType(), 0), block.getLocation(), 0.3F, 0.3F, 0.3F, 0.0F,
3, ViewDist.LONG, UtilServer.getPlayers());
block.setType(Material.AIR);
_remaining.remove(block);
}
}.runTaskLater(Host.getArcadeManager().getPlugin(), 40L);
}
}
@EventHandler
public void onBlockFade(BlockFadeEvent event)
{
if(!Host.IsLive() || !Host.isChallengeStarted())
return;
if(event.getNewState().getType() == Material.DIRT || event.getNewState().getType() == Material.GRASS)
event.setCancelled(true);
}
} }

View File

@ -79,6 +79,34 @@ public class ChallengeFastFood extends Challenge
} }
} }
@Override
public void setupPlayers()
{
itemParticleTask();
for(Player player : Host.GetPlayers(true))
{
for(int i = 0; i < 9; i++)
{
player.getInventory().setItem(i, getRandomFood());
}
}
}
@Override
public void cleanupRoom()
{
itemSeperator = 0;
for(Entity entity : Host.WorldData.World.getEntities())
{
if(entity instanceof Item)
{
entity.remove();
}
}
}
@EventHandler @EventHandler
public void onPlayerInteract(PlayerInteractEvent event) public void onPlayerInteract(PlayerInteractEvent event)
{ {
@ -101,6 +129,53 @@ public class ChallengeFastFood extends Challenge
} }
} }
private void itemParticleTask()
{
new BukkitRunnable()
{
@Override
public void run()
{
if(!Host.IsLive() || !Host.isChallengeStarted())
{
cancel();
return;
}
for(Entity entity : Host.WorldData.World.getEntities())
{
if(entity instanceof Item)
{
Item item = (Item) entity;
if(!item.isValid() || item.isDead() || item.isOnGround() || item.getItemStack().getType() == Material.INK_SACK)
continue;
UtilParticle.PlayParticle(ParticleType.INSTANT_SPELL, item.getLocation(), 0, 0, 0, 0, 1, ViewDist.NORMAL,
UtilServer.getPlayers());
}
}
}
}.runTaskTimer(Host.getArcadeManager().getPlugin(), 0L, 1L);
}
private ItemStack getRandomFood()
{
Material foodMaterial = UtilMath.randomElement(_food);
byte data = 0;
if(foodMaterial == Material.RAW_FISH)
{
data = (byte) (UtilMath.r(3) + 1);
}
else if(foodMaterial == Material.COOKED_FISH)
{
data = (byte) UtilMath.r(1);
}
return new ItemStack(foodMaterial, 5, (byte) data);
}
private void chanceItemSlot(Player player) private void chanceItemSlot(Player player)
{ {
for(int i = 0; i < 9; i++) for(int i = 0; i < 9; i++)
@ -139,44 +214,6 @@ public class ChallengeFastFood extends Challenge
checkForWinner(player); checkForWinner(player);
} }
private void checkForWinner(Player player)
{
ArrayList<ItemStack> items = UtilInv.getItems(player);
if(items.size() == 0)
SetCompleted(player);
}
private void itemParticleTask()
{
new BukkitRunnable()
{
@Override
public void run()
{
if(!Host.IsLive() || !Host.isChallengeStarted())
{
cancel();
return;
}
for(Entity entity : Host.WorldData.World.getEntities())
{
if(entity instanceof Item)
{
Item item = (Item) entity;
if(!item.isValid() || item.isDead() || item.isOnGround() || item.getItemStack().getType() == Material.INK_SACK)
continue;
UtilParticle.PlayParticle(ParticleType.INSTANT_SPELL, item.getLocation(), 0, 0, 0, 0, 1, ViewDist.NORMAL,
UtilServer.getPlayers());
}
}
}
}.runTaskTimer(Host.getArcadeManager().getPlugin(), 0L, 1L);
}
private void growGrassTask(final Item item) private void growGrassTask(final Item item)
{ {
new BukkitRunnable() new BukkitRunnable()
@ -238,6 +275,14 @@ public class ChallengeFastFood extends Challenge
}.runTaskTimer(Host.getArcadeManager().getPlugin(), 0L, 1L); }.runTaskTimer(Host.getArcadeManager().getPlugin(), 0L, 1L);
} }
private void checkForWinner(Player player)
{
ArrayList<ItemStack> items = UtilInv.getItems(player);
if(items.size() == 0)
SetCompleted(player);
}
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private void blockBreakEffect(Block block) private void blockBreakEffect(Block block)
{ {
@ -245,49 +290,4 @@ public class ChallengeFastFood extends Challenge
10, ViewDist.NORMAL, UtilServer.getPlayers()); 10, ViewDist.NORMAL, UtilServer.getPlayers());
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getTypeId()); block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getTypeId());
} }
@Override
public void setupPlayers()
{
itemParticleTask();
for(Player player : Host.GetPlayers(true))
{
for(int i = 0; i < 9; i++)
{
player.getInventory().setItem(i, getRandomFood());
}
}
}
public ItemStack getRandomFood()
{
Material foodMaterial = UtilMath.randomElement(_food);
byte data = 0;
if(foodMaterial == Material.RAW_FISH)
{
data = (byte) (UtilMath.r(3) + 1);
}
else if(foodMaterial == Material.COOKED_FISH)
{
data = (byte) UtilMath.r(1);
}
return new ItemStack(foodMaterial, 5, (byte) data);
}
@Override
public void cleanupRoom()
{
itemSeperator = 0;
for(Entity entity : Host.WorldData.World.getEntities())
{
if(entity instanceof Item)
{
entity.remove();
}
}
}
} }

View File

@ -16,10 +16,14 @@ import org.bukkit.Sound;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.block.Chest; import org.bukkit.block.Chest;
import org.bukkit.entity.Entity;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -42,8 +46,8 @@ public class ChallengeTreasureDigger extends Challenge
_lootChance.put(Material.GOLD_SWORD, 10.0); _lootChance.put(Material.GOLD_SWORD, 10.0);
_lootChance.put(Material.DIAMOND_SWORD, 5.0); _lootChance.put(Material.DIAMOND_SWORD, 5.0);
_lootChance.put(Material.GOLD_SPADE, 5.0); _lootChance.put(Material.IRON_SPADE, 15.0);
_lootChance.put(Material.GOLD_PICKAXE, 5.0); _lootChance.put(Material.IRON_PICKAXE, 15.0);
_lootChance.put(Material.GOLDEN_APPLE, 5.0); _lootChance.put(Material.GOLDEN_APPLE, 5.0);
_lootChance.put(Material.FISHING_ROD, 10.0); _lootChance.put(Material.FISHING_ROD, 10.0);
@ -52,76 +56,27 @@ public class ChallengeTreasureDigger extends Challenge
_lootChance.put(Material.LEATHER_HELMET, 20.0); _lootChance.put(Material.LEATHER_HELMET, 20.0);
_lootChance.put(Material.LEATHER_CHESTPLATE, 15.0); _lootChance.put(Material.LEATHER_CHESTPLATE, 15.0);
_lootChance.put(Material.LEATHER_LEGGINGS, 10.0); _lootChance.put(Material.LEATHER_LEGGINGS, 12.0);
_lootChance.put(Material.LEATHER_BOOTS, 20.0); _lootChance.put(Material.LEATHER_BOOTS, 20.0);
_lootChance.put(Material.CHAINMAIL_HELMET, 10.0); _lootChance.put(Material.CHAINMAIL_HELMET, 10.0);
_lootChance.put(Material.CHAINMAIL_CHESTPLATE, 5.0); _lootChance.put(Material.CHAINMAIL_CHESTPLATE, 5.0);
_lootChance.put(Material.CHAINMAIL_LEGGINGS, 5.0); _lootChance.put(Material.CHAINMAIL_LEGGINGS, 7.0);
_lootChance.put(Material.CHAINMAIL_BOOTS, 10.0); _lootChance.put(Material.CHAINMAIL_BOOTS, 10.0);
_lootChance.put(Material.IRON_HELMET, 10.0); _lootChance.put(Material.IRON_HELMET, 10.0);
_lootChance.put(Material.IRON_CHESTPLATE, 5.0); _lootChance.put(Material.IRON_CHESTPLATE, 5.0);
_lootChance.put(Material.IRON_LEGGINGS, 5.0); _lootChance.put(Material.IRON_LEGGINGS, 7.0);
_lootChance.put(Material.IRON_BOOTS, 10.0); _lootChance.put(Material.IRON_BOOTS, 10.0);
_lootChance.put(Material.DIAMOND_HELMET, 5.0); _lootChance.put(Material.DIAMOND_HELMET, 5.0);
_lootChance.put(Material.DIAMOND_CHESTPLATE, 2.0); _lootChance.put(Material.DIAMOND_CHESTPLATE, 2.0);
_lootChance.put(Material.DIAMOND_LEGGINGS, 2.0); _lootChance.put(Material.DIAMOND_LEGGINGS, 4.0);
_lootChance.put(Material.DIAMOND_BOOTS, 5.0); _lootChance.put(Material.DIAMOND_BOOTS, 5.0);
_lootContents = _lootChance.keySet().toArray(new Material[_lootChance.keySet().size()]); _lootContents = _lootChance.keySet().toArray(new Material[_lootChance.keySet().size()]);
} }
private Material getRandomLootMaterial()
{
Material loot = UtilMath.randomElement(_lootContents);
return loot;
}
private double getLootChance(Material loot)
{
return _lootChance.get(loot);
}
private void fillChestWithLoot(Chest chest)
{
Inventory inv = chest.getInventory();
for(int i = 0; i <= UtilMath.r(2) + 1; i++)
{
double chance = Math.random() * 100;
Material loot = getRandomLootMaterial();
double lootChance = getLootChance(loot);
while(chance >= lootChance)
{
chance = Math.random() * 100;
loot = getRandomLootMaterial();
lootChance = getLootChance(loot);
}
if(chance < lootChance)
{
ItemStack item = new ItemStack(loot);
if(item.getType() == Material.ARROW || item.getType() == Material.BONE || item.getType() == Material.STRING)
{
item.setAmount(UtilMath.r(3) + 1);
}
int slot = UtilMath.r(inv.getSize());
while(inv.getItem(slot) != null && inv.getContents().length != inv.getSize())
{
slot = UtilMath.r(inv.getSize());
}
inv.setItem(slot, item);
}
}
}
@Override @Override
public ArrayList<Location> getSpawns() public ArrayList<Location> getSpawns()
{ {
@ -169,7 +124,7 @@ public class ChallengeTreasureDigger extends Challenge
{ {
block.setType(Material.SAND); block.setType(Material.SAND);
if (chance < 20.0) if(chance < 20.0)
{ {
block.setData((byte) 1); block.setData((byte) 1);
} }
@ -188,7 +143,7 @@ public class ChallengeTreasureDigger extends Challenge
{ {
block.setType(Material.SAND); block.setType(Material.SAND);
if (chance < 20.0) if(chance < 20.0)
{ {
block.setData((byte) 1); block.setData((byte) 1);
} }
@ -199,7 +154,7 @@ public class ChallengeTreasureDigger extends Challenge
block.setData((byte) 0); block.setData((byte) 0);
} }
} }
else if (i == 3) else if(i == 3)
{ {
block.setType(Material.SAND); block.setType(Material.SAND);
@ -221,56 +176,6 @@ public class ChallengeTreasureDigger extends Challenge
} }
} }
@EventHandler
public void onBlockBreak(BlockBreakEvent event)
{
event.getBlock().setType(Material.AIR);
}
@EventHandler
public void onEntityDamageByEntity(EntityDamageByEntityEvent event)
{
if(event.getEntity() instanceof Player && event.getDamager() instanceof Player)
{
Player damager = (Player) event.getDamager();
ItemStack item = damager.getItemInHand();
if(item != null)
{
if(!item.getType().name().toLowerCase().contains("sword"))
{
UtilTextMiddle.display("", C.cRed + "You cannot attack without a weapon.", 5, 40, 5, damager);
damager.playSound(damager.getLocation(), Sound.NOTE_BASS_GUITAR, 1.0F, 0.5F);
event.setCancelled(true);
}
}
}
}
@SuppressWarnings("deprecation")
private void makeChestWithTreasure(Block block)
{
if(!canCollapseWithChests(block))
{
block.setType(Material.CHEST);
block.setData((byte) UtilMath.r(4));
Chest chest = (Chest) block.getState();
fillChestWithLoot(chest);
}
}
private boolean canCollapseWithChests(Block block)
{
Block north = block.getRelative(BlockFace.NORTH);
Block south = block.getRelative(BlockFace.SOUTH);
Block east = block.getRelative(BlockFace.EAST);
Block west = block.getRelative(BlockFace.WEST);
return north.getType() == Material.CHEST || south.getType() == Material.CHEST || east.getType() == Material.CHEST
|| west.getType() == Material.CHEST;
}
@Override @Override
public void setupPlayers() public void setupPlayers()
{ {
@ -301,5 +206,122 @@ public class ChallengeTreasureDigger extends Challenge
Host.DamagePvP = false; Host.DamagePvP = false;
Host.WorldBlockBurn = false; Host.WorldBlockBurn = false;
Host.WorldFireSpread = false; Host.WorldFireSpread = false;
for(Entity entity : Host.WorldData.World.getEntities())
{
if(entity instanceof Item)
{
entity.remove();
}
}
}
@EventHandler
public void onItemSpawn(ItemSpawnEvent event)
{
event.setCancelled(true);
}
@EventHandler
public void onEntityChangeBlock(EntityChangeBlockEvent event)
{
if(event.getEntity() instanceof FallingBlock)
{
FallingBlock block = (FallingBlock) event.getEntity();
block.setDropItem(false);
}
}
@EventHandler
public void onEntityDamageByEntity(EntityDamageByEntityEvent event)
{
if(event.getEntity() instanceof Player && event.getDamager() instanceof Player)
{
Player damager = (Player) event.getDamager();
ItemStack item = damager.getItemInHand();
if(item != null)
{
if(!item.getType().name().toLowerCase().contains("sword"))
{
UtilTextMiddle.display("", C.cRed + "You cannot attack without a weapon.", 5, 40, 5, damager);
damager.playSound(damager.getLocation(), Sound.NOTE_BASS_GUITAR, 1.0F, 0.5F);
event.setCancelled(true);
}
}
}
}
@SuppressWarnings("deprecation")
private void makeChestWithTreasure(Block block)
{
if(!areChestsNearby(block))
{
block.setType(Material.CHEST);
block.setData((byte) UtilMath.r(4));
Chest chest = (Chest) block.getState();
fillChestWithLoot(chest);
}
}
private boolean areChestsNearby(Block block)
{
Block north = block.getRelative(BlockFace.NORTH);
Block south = block.getRelative(BlockFace.SOUTH);
Block east = block.getRelative(BlockFace.EAST);
Block west = block.getRelative(BlockFace.WEST);
return north.getType() == Material.CHEST || south.getType() == Material.CHEST || east.getType() == Material.CHEST
|| west.getType() == Material.CHEST;
}
private void fillChestWithLoot(Chest chest)
{
Inventory inv = chest.getInventory();
for(int i = 0; i <= UtilMath.r(2) + 1; i++)
{
double chance = Math.random() * 100;
Material loot = getRandomLootMaterial();
double lootChance = getLootChance(loot);
while(chance >= lootChance)
{
chance = Math.random() * 100;
loot = getRandomLootMaterial();
lootChance = getLootChance(loot);
}
if(chance < lootChance)
{
ItemStack item = new ItemStack(loot);
if(item.getType() == Material.ARROW || item.getType() == Material.BONE || item.getType() == Material.STRING)
{
item.setAmount(UtilMath.r(3) + 1);
}
int slot = UtilMath.r(inv.getSize());
while(inv.getItem(slot) != null && inv.getContents().length != inv.getSize())
{
slot = UtilMath.r(inv.getSize());
}
inv.setItem(slot, item);
}
}
}
private Material getRandomLootMaterial()
{
Material loot = UtilMath.randomElement(_lootContents);
return loot;
}
private double getLootChance(Material loot)
{
return _lootChance.get(loot);
} }
} }