Challenge refactoring, modify challenge ending and chat messages, add generateGrass helper method.

This commit is contained in:
Thanos paravantis 2016-03-07 18:32:33 +02:00
parent 4e6ba4ebd1
commit 1ee7a42b9c
9 changed files with 389 additions and 325 deletions

View File

@ -149,6 +149,8 @@ public class BawkBawkBattles extends TeamGame implements IThrown
private String _restrictCommand = "restrict"; private String _restrictCommand = "restrict";
private String _skipCommand = "skip"; private String _skipCommand = "skip";
// TODO: Do not trigger chicken attack if the game is about to end.
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public BawkBawkBattles(ArcadeManager manager) public BawkBawkBattles(ArcadeManager manager)
{ {
@ -176,7 +178,6 @@ public class BawkBawkBattles extends TeamGame implements IThrown
DeathTeleport = false; DeathTeleport = false;
AutomaticRespawn = false; AutomaticRespawn = false;
DeathMessages = false; DeathMessages = false;
CreatureAllow = true;
TeleportsDisqualify = false; TeleportsDisqualify = false;
GiveClock = false; GiveClock = false;
@ -219,9 +220,9 @@ public class BawkBawkBattles extends TeamGame implements IThrown
ChallengeInfestation.class, // Playable - Refactored ChallengeInfestation.class, // Playable - Refactored
ChallengeKangarooJump.class, // Playable - Refactored ChallengeKangarooJump.class, // Playable - Refactored
ChallengeKingOfTheHill.class, // Playable - Refactored ChallengeKingOfTheHill.class, // Playable - Refactored
ChallengeLavaRun.class, // Playable ChallengeLavaRun.class, // Playable - Refactored
ChallengeMilkACow.class, // Playable- Check cow names. ChallengeMilkACow.class, // Playable - Refactored
ChallengeMineADiamond.class, // Playable ChallengeMineADiamond.class, // Playable - Refactored
ChallengeMinecartDance.class, // Playable ChallengeMinecartDance.class, // Playable
ChallengeMiniOneInTheQuiver.class, // Playable ChallengeMiniOneInTheQuiver.class, // Playable
ChallengeNavigateMaze.class, // Broken ChallengeNavigateMaze.class, // Broken
@ -614,8 +615,19 @@ public class BawkBawkBattles extends TeamGame implements IThrown
} }
if (_challenge.getData().hasAnyoneCompleted() && !_challenge.getData().isCompleted(player)) if (_challenge.getData().hasAnyoneCompleted() && !_challenge.getData().isCompleted(player))
//looseLife(player, true); {
int lives = lives(player) - 1;
if (lives > 0)
{
looseLife(player);
taskFailedMessage(player, lives(player));
}
else
{
handleDeath(player); handleDeath(player);
}
}
if (_challenge.getData().isCompleted(player)) if (_challenge.getData().isCompleted(player))
AddGems(player, 3, "Completed Challenge", true, true); AddGems(player, 3, "Completed Challenge", true, true);
@ -1141,29 +1153,31 @@ public class BawkBawkBattles extends TeamGame implements IThrown
private void gameLostMessage(Player player) private void gameLostMessage(Player player)
{ {
UtilPlayer.message(player, ""); UtilPlayer.message(player, F.main("Game", C.cRed + "You are out of the game."));
UtilPlayer.message(player, C.cRed + C.Bold + "You are out of the game.");
player.playSound(player.getLocation(), Sound.EXPLODE, 2.0F, 1.0F); player.playSound(player.getLocation(), Sound.EXPLODE, 2.0F, 1.0F);
UtilPlayer.message(player, ""); }
public void taskWinMessage(Player player)
{
UtilPlayer.message(player, F.main("Game", C.cGreen + "You completed the task!"));
player.playSound(player.getLocation(), Sound.LEVEL_UP, 2.0F, 1.0F);
} }
public void taskFailedMessage(Player player, int lives) public void taskFailedMessage(Player player, int lives)
{ {
UtilPlayer.message(player, ""); UtilPlayer.message(player, F.main("Game", C.cRed + "You have failed the task."));
UtilPlayer.message(player, C.cRed + C.Bold + "You failed the task!");
String suffix = "lives"; String suffix = "lives";
if (lives == 1) if (lives == 1)
suffix = "life"; suffix = "life";
String msg = C.Bold + "You have " + F.elem(C.Bold + lives) + C.Bold + " " + suffix + " left."; String msg = "You have " + F.elem(lives) + " " + suffix + " left.";
if (lives <= 0) if (lives <= 0)
msg = C.Bold + "You don't have any lives left."; msg = "You don't have any lives left.";
UtilPlayer.message(player, C.cGray + msg); UtilPlayer.message(player, F.main("Game", msg));
UtilPlayer.message(player, "");
player.playSound(player.getLocation(), Sound.NOTE_BASS, 2.0F, 1.0F); player.playSound(player.getLocation(), Sound.NOTE_BASS, 2.0F, 1.0F);
} }

View File

@ -5,7 +5,6 @@ import java.util.HashSet;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
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.entity.Boat; import org.bukkit.entity.Boat;
@ -28,7 +27,6 @@ import mineplex.core.common.util.C;
import mineplex.core.common.util.MapUtil; import mineplex.core.common.util.MapUtil;
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.UtilTextBottom; import mineplex.core.common.util.UtilTextBottom;
import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilTime;
import mineplex.core.hologram.Hologram; import mineplex.core.hologram.Hologram;
@ -193,6 +191,25 @@ public abstract class Challenge implements Listener
} }
} }
@SuppressWarnings("deprecation")
protected Block generateGrass(Block block)
{
if (UtilMath.r(4) == 0)
{
if (UtilMath.r(8) == 0)
{
block.setType(UtilMath.random.nextBoolean() ? Material.YELLOW_FLOWER : Material.RED_ROSE);
}
else
{
block.setType(Material.LONG_GRASS);
block.setData((byte) 1);
}
}
return block;
}
protected boolean isChallengeValid() protected boolean isChallengeValid()
{ {
return Host.IsLive() && Host.getSettings().isChallengeStarted(); return Host.IsLive() && Host.getSettings().isChallengeStarted();
@ -265,6 +282,8 @@ public abstract class Challenge implements Listener
if (Data.getCompletedPlayers().contains(player)) if (Data.getCompletedPlayers().contains(player))
return; return;
Host.taskWinMessage(player);
if (cloak) if (cloak)
{ {
Data.addInvisiblePlayer(player); Data.addInvisiblePlayer(player);
@ -272,13 +291,7 @@ public abstract class Challenge implements Listener
} }
Data.addCompletedPlayer(player); Data.addCompletedPlayer(player);
UtilPlayer.message(player, "");
UtilPlayer.message(player, C.cGreen + C.Bold + "You completed the task!");
UtilPlayer.message(player, "");
UtilInv.Clear(player); UtilInv.Clear(player);
player.playSound(player.getLocation(), Sound.LEVEL_UP, 2.0F, 1.0F);
} }
public void setCompleted(Player player) public void setCompleted(Player player)
@ -291,6 +304,8 @@ public abstract class Challenge implements Listener
if (Data.isDone(player)) if (Data.isDone(player))
return; return;
Host.taskFailedMessage(player, Host.lives(player));
if (!Host.getSettings().isCrumbling()) if (!Host.getSettings().isCrumbling())
Data.addLostPlayer(player); Data.addLostPlayer(player);
@ -300,12 +315,8 @@ public abstract class Challenge implements Listener
Host.Manager.GetCondition().Factory().Cloak("Lost", player, player, 7777, true, false); Host.Manager.GetCondition().Factory().Cloak("Lost", player, player, 7777, true, false);
} }
UtilInv.Clear(player);
Host.looseLife(player); Host.looseLife(player);
Host.taskFailedMessage(player, Host.lives(player)); UtilInv.Clear(player);
// Host.handleFailure(player, true);
} }
public void setLost(Player player) public void setLost(Player player)

View File

@ -1,6 +1,5 @@
package nautilus.game.arcade.game.games.mineware.challenge; package nautilus.game.arcade.game.games.mineware.challenge;
import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import org.bukkit.block.Block; import org.bukkit.block.Block;

View File

@ -10,7 +10,9 @@ import org.bukkit.block.Chest;
import org.bukkit.block.DoubleChest; import org.bukkit.block.DoubleChest;
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.Action;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -120,6 +122,31 @@ public class ChallengeDiamondSeeker extends Challenge
Host.InventoryOpenBlock = false; Host.InventoryOpenBlock = false;
} }
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event)
{
if (!isChallengeValid())
return;
Player player = event.getPlayer();
if (getChallengers().contains(player) && Host.IsAlive(player) && Data.isDone(player))
{
if (event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_BLOCK)
{
Block block = event.getClickedBlock();
if (block == null)
return;
if (block.getType() == Material.CHEST)
{
event.setCancelled(true);
}
}
}
}
@EventHandler @EventHandler
public void onInventoryClick(InventoryClickEvent event) public void onInventoryClick(InventoryClickEvent event)
{ {
@ -144,6 +171,7 @@ public class ChallengeDiamondSeeker extends Challenge
{ {
event.setCurrentItem(new ItemStack(Material.AIR)); event.setCurrentItem(new ItemStack(Material.AIR));
setCompleted(player); setCompleted(player);
player.closeInventory();
} }
} }
} }

View File

@ -106,17 +106,9 @@ public class ChallengeDogsVersusCats extends Challenge
{ {
block.setType(Material.FENCE); block.setType(Material.FENCE);
} }
else if (y == 1 && UtilMath.r(4) == 0) else if (y == 1)
{ {
if (UtilMath.r(8) == 0) generateGrass(block);
{
block.setType(UtilMath.random.nextBoolean() ? Material.YELLOW_FLOWER : Material.RED_ROSE);
}
else
{
block.setType(Material.LONG_GRASS);
block.setData((byte) 1);
}
} }
} }

View File

@ -25,12 +25,11 @@ import nautilus.game.arcade.game.games.mineware.challenge.ChallengeType;
public class ChallengeLavaRun extends Challenge public class ChallengeLavaRun extends Challenge
{ {
private Block _obsidian;
private int mapY = 4; private int mapY = 4;
private long _delay; private long _delay;
private long _minusDelay = 1000; private long _minusDelay = 1000;
private int _disappearingBlocks = 10; private int _disappearingBlocks = 10;
private Block _obsidian;
public ChallengeLavaRun(BawkBawkBattles host) public ChallengeLavaRun(BawkBawkBattles host)
{ {
@ -84,39 +83,52 @@ public class ChallengeLavaRun extends Challenge
_obsidian = generateObsidianBlock(); _obsidian = generateObsidianBlock();
} }
@Override
public void onStart()
{
_delay = System.currentTimeMillis() + 2000;
createLava();
for (Player player : getChallengers())
{
DisguiseMagmaCube disguise = new DisguiseMagmaCube(player);
disguise.SetSize(1);
Host.getArcadeManager().GetDisguise().disguise(disguise);
}
}
@EventHandler @EventHandler
public void onBlockFromTo(BlockFromToEvent event) public void onBlockFromTo(BlockFromToEvent event)
{ {
if (!Host.IsLive()) if (!isChallengeValid())
return; return;
event.setCancelled(true); event.setCancelled(true);
} }
public Block generateObsidianBlock()
{
Block block = getCenter().clone().add(UtilMath.r(21) - 9.5, mapY, UtilMath.r(21) - 9.5).getBlock();
block.setType(Material.OBSIDIAN);
return block;
}
@EventHandler @EventHandler
public void onDamage(CustomDamageEvent event) public void onDamage(CustomDamageEvent event)
{ {
if (event.GetDamagerEntity(true) != null) if (!isChallengeValid())
{ return;
if (event.GetDamagerEntity(true) != null)
return; return;
}
event.AddMod("Ensure Death", null, 9999, false); event.AddMod("Ensure Death", null, 9999, false);
} }
@SuppressWarnings("deprecation")
@EventHandler @EventHandler
public void onUpdate(UpdateEvent event) public void onUpdate(UpdateEvent event)
{ {
if (event.getType() != UpdateType.TICK) if (event.getType() != UpdateType.TICK)
return; return;
if (!isChallengeValid())
return;
if (_delay > System.currentTimeMillis()) if (_delay > System.currentTimeMillis())
return; return;
@ -152,11 +164,11 @@ public class ChallengeLavaRun extends Challenge
{ {
for (int z = -getArenaSize(); z <= getArenaSize(); z++) for (int z = -getArenaSize(); z <= getArenaSize(); z++)
{ {
Block b = getCenter().getBlock().getRelative(x, mapY, z); Block block = getCenter().getBlock().getRelative(x, mapY, z);
if (b.getType() == Material.GLASS) if (block.getType() == Material.GLASS)
{ {
glassBlocks.add(b); glassBlocks.add(block);
} }
} }
} }
@ -186,18 +198,23 @@ public class ChallengeLavaRun extends Challenge
for (int i = 0; i < Math.min(_disappearingBlocks, glassBlocks.size()); i++) for (int i = 0; i < Math.min(_disappearingBlocks, glassBlocks.size()); i++)
{ {
Block b = glassBlocks.remove(0); Block block = glassBlocks.remove(0);
b.setTypeIdAndData(Material.AIR.getId(), (byte) 0, false); block.setTypeIdAndData(Material.AIR.getId(), (byte) 0, false);
addBlock(b); addBlock(block);
} }
} }
} }
} }
@Override private Block generateObsidianBlock()
public void onStart() {
Block block = getCenter().clone().add(UtilMath.r(21) - 9.5, mapY, UtilMath.r(21) - 9.5).getBlock();
block.setType(Material.OBSIDIAN);
return block;
}
private void createLava()
{ {
_delay = System.currentTimeMillis() + 2000;
int size = getArenaSize() + 3; int size = getArenaSize() + 3;
for (int x = -size; x <= size; x++) for (int x = -size; x <= size; x++)
@ -212,32 +229,5 @@ public class ChallengeLavaRun extends Challenge
} }
} }
} }
for (Player player : getChallengers())
{
DisguiseMagmaCube disguise = new DisguiseMagmaCube(player);
disguise.SetSize(1);
Host.getArcadeManager().GetDisguise().disguise(disguise);
} }
}
// for (int x = -15; x <= 15; x++)
// {
// for (int z = -15; z <= 15; z++)
// {
// Block block = getCenter().getBlock().getRelative(x, 0, z);
// block.setType(Material.LAVA);
// addBlock(block);
//
// if (Math.abs(x) <= 10 && Math.abs(z) <= 10)
// {
// Block b = block.getRelative(BlockFace.UP);
// b.setType(Material.GLASS);
// addBlock(b);
// }
// }
// }
//
// _obsidian = getCenter().add(UtilMath.r(21) - 9.5, 1, UtilMath.r(21) - 9.5);
// _obsidian.getBlock().setType(Material.OBSIDIAN);
} }

View File

@ -40,6 +40,28 @@ public class ChallengeMilkACow extends Challenge
private HashMap<Player, Integer> _score = new HashMap<Player, Integer>(); private HashMap<Player, Integer> _score = new HashMap<Player, Integer>();
private HashMap<Entity, Hologram> _cowIndicator = new HashMap<Entity, Hologram>(); private HashMap<Entity, Hologram> _cowIndicator = new HashMap<Entity, Hologram>();
String[] _humanNames = new String[] {
"Tom",
"Steve",
"John",
"Harry",
"Andrew",
"Daniel",
"Bobbae",
"Jim"
};
String[] _cowNames = new String[] {
"Moorten",
"Mooington",
"Mooley",
"Moose",
"Mooskee",
"Chicken",
"Mooffy",
"Moozzle",
};
public ChallengeMilkACow(BawkBawkBattles host) public ChallengeMilkACow(BawkBawkBattles host)
{ {
super( super(
@ -50,6 +72,76 @@ public class ChallengeMilkACow extends Challenge
"Deliver the milk to the villager!"); "Deliver the milk to the villager!");
Settings.setUseMapHeight(); Settings.setUseMapHeight();
Settings.setLockInventory(4);
}
@Override
public ArrayList<Location> createSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
int size = getArenaSize() - 1;
for (int x = -(size); x <= size; x++)
{
for (int z = -(size); z <= size; z++)
{
if (x % 2 == 0 && z % 2 == 0)
{
spawns.add(getCenter().add(x + 0.5, 1.1, z + 0.5));
}
}
}
return spawns;
}
@Override
public void createMap()
{
for (int x = -getArenaSize(); x <= getArenaSize(); x++)
{
for (int z = -getArenaSize(); z <= getArenaSize(); z++)
{
for (int y = 0; y <= 1; y++)
{
Block block = getCenter().getBlock().getRelative(x, y, z);
if (y == 0)
{
block.setType(Material.GRASS);
}
else
{
if (Math.abs(x) == getArenaSize() || Math.abs(z) == getArenaSize())
{
block.setType(Material.FENCE);
}
else
{
generateGrass(block);
}
}
addBlock(block);
}
}
}
spawnCowsAndFarmer();
}
@Override
public void onStart()
{
for (Player player : getChallengers())
{
DisguiseVillager disguise = new DisguiseVillager(player);
disguise.setBaby();
Host.getArcadeManager().GetDisguise().disguise(disguise);
player.getInventory().setItem(Settings.getLockedSlot(), new ItemStack(Material.BUCKET));
_score.put(player, 0);
}
} }
@Override @Override
@ -62,12 +154,16 @@ public class ChallengeMilkACow extends Challenge
cow.remove(); cow.remove();
} }
_villager.remove(); _villager.remove();
} }
@EventHandler @EventHandler
public void Damage(CustomDamageEvent event) public void onCustomDamage(CustomDamageEvent event)
{ {
if (!isChallengeValid())
return;
if (event.GetProjectile() == null) if (event.GetProjectile() == null)
return; return;
@ -76,6 +172,9 @@ public class ChallengeMilkACow extends Challenge
if (player == null) if (player == null)
return; return;
if (!isPlayerValid(player))
return;
LivingEntity ent = event.GetDamageeEntity(); LivingEntity ent = event.GetDamageeEntity();
if (!(ent instanceof Player)) if (!(ent instanceof Player))
@ -84,132 +183,21 @@ public class ChallengeMilkACow extends Challenge
} }
} }
@Override
public void onStart()
{
for (Player player : Host.GetPlayers(true))
{
DisguiseVillager disguise = new DisguiseVillager(player);
disguise.setBaby();
Host.getArcadeManager().GetDisguise().disguise(disguise);
player.getInventory().setItem(0, new ItemStack(Material.BUCKET));
_score.put(player, 0);
}
}
@Override
public void createMap()
{
for (int x = -getArenaSize(); x <= getArenaSize(); x++)
{
for (int z = -getArenaSize(); z <= getArenaSize(); z++)
{
for (int y = 0; y <= 1; y++)
{
Block b = getCenter().getBlock().getRelative(x, y, z);
if (y == 0)
{
b.setType(Material.GRASS);
}
else
{
if (Math.abs(x) == getArenaSize() || Math.abs(z) == getArenaSize())
{
b.setType(Material.FENCE);
}
else if (UtilMath.r(4) == 0)
{
if (UtilMath.r(8) == 0)
{
b.setType(UtilMath.random.nextBoolean() ? Material.YELLOW_FLOWER : Material.RED_ROSE);
}
else
{
b.setType(Material.LONG_GRASS);
b.setData((byte) 1);
}
}
}
if (b.getType() != Material.AIR)
{
addBlock(b);
}
}
}
}
Host.CreatureAllowOverride = true;
_villager = (Villager) getCenter().getWorld().spawnEntity(getCenter().clone().add(0, 1, 0), EntityType.VILLAGER);
_villager.setProfession(Profession.FARMER);
_villager.setCustomName(C.Bold + "Farmer Joe");
_villager.setCustomNameVisible(true);
String[] names = new String[] {
"Tom",
"Steve",
"John",
"Harry",
"Andrew",
"Daniel",
"Bobbae",
"Jim"
};
if (UtilMath.r(5) == 0)
{
names = new String[] {
"Moorten",
"Mooington",
"Mooley",
"Moose",
"Mooskee",
"Chicken",
"Mooffy",
"Moozzle",
};
}
for (int i = 0; i < 8; i++)
{
Location loc = getCenter().clone().add(UtilMath.r(((getArenaSize() * 2) - 1) - (getArenaSize() - 1)), 1,
UtilMath.r((getArenaSize() * 2) - 1) - (getArenaSize() - 1));
Cow cow = (Cow) loc.getWorld().spawnEntity(loc, EntityType.COW);
cow.setCustomName(C.cWhite + names[i]);
cow.setCustomNameVisible(true);
_milked.put(cow, new ArrayList<String>());
_cowIndicator.put(cow,
new Hologram(Host.Manager.getHologramManager(), cow.getLocation().clone().add(0, 2.5, 0), C.cRed + "Already Milked!"));
Hologram holo = _cowIndicator.get(cow);
holo.setHologramTarget(HologramTarget.WHITELIST);
holo.setFollowEntity(cow);
holo.start();
}
Host.CreatureAllowOverride = false;
}
@EventHandler @EventHandler
public void cowIndicator(UpdateEvent event) public void onCowIndicatorUpdate(UpdateEvent event)
{ {
if (!Host.IsLive())
{
return;
}
if (event.getType() != UpdateType.SEC) if (event.getType() != UpdateType.SEC)
{
return; return;
}
for (Entity entCow : _milked.keySet()) if (!isChallengeValid())
return;
for (Entity cow : _milked.keySet())
{ {
for (String playerName : _milked.get(entCow)) for (String playerName : _milked.get(cow))
{ {
Hologram holo = _cowIndicator.get(entCow); Hologram holo = _cowIndicator.get(cow);
if (!holo.containsPlayer(playerName)) if (!holo.containsPlayer(playerName))
{ {
holo.addPlayer(playerName); holo.addPlayer(playerName);
@ -221,19 +209,15 @@ public class ChallengeMilkACow extends Challenge
@EventHandler @EventHandler
public void onEntityInteract(PlayerInteractEntityEvent event) public void onEntityInteract(PlayerInteractEntityEvent event)
{ {
Player p = event.getPlayer(); if (!isChallengeValid())
if (UtilPlayer.isSpectator(p))
{
return; return;
}
if (!Host.IsLive()) Player player = event.getPlayer();
{
if (!isPlayerValid(player))
return; return;
}
ItemStack item = p.getItemInHand(); ItemStack item = player.getItemInHand();
if (item == null) if (item == null)
return; return;
@ -244,15 +228,14 @@ public class ChallengeMilkACow extends Challenge
{ {
if (item.getType() == Material.BUCKET) if (item.getType() == Material.BUCKET)
{ {
if (!_milked.get(ent).contains(p.getName())) if (!_milked.get(ent).contains(player.getName()))
{ {
p.setItemInHand(new ItemStack(Material.MILK_BUCKET)); player.setItemInHand(new ItemStack(Material.MILK_BUCKET));
_milked.get(ent).add(p.getName()); _milked.get(ent).add(player.getName());
Cow cow = (Cow) ent;
} }
else else
{ {
p.updateInventory(); player.updateInventory();
} }
} }
@ -262,17 +245,16 @@ public class ChallengeMilkACow extends Challenge
{ {
if (item.getType() == Material.MILK_BUCKET) if (item.getType() == Material.MILK_BUCKET)
{ {
p.setItemInHand(new ItemStack(Material.BUCKET)); player.setItemInHand(new ItemStack(Material.BUCKET));
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 2, 0); player.playSound(player.getLocation(), Sound.ORB_PICKUP, 2, 0);
int score = _score.get(p) + 1; int score = _score.get(player) + 1;
_score.put(p, score); _score.put(player, score);
displayCount(p, ((Villager) ent).getEyeLocation().add(0, 0.3, 0), (score >= 5 ? C.cDGreen : score >= 3 ? C.cGreen displayCount(player, ((Villager) ent).getEyeLocation().add(0, 0.3, 0), (score >= 5 ? C.cDGreen : score >= 3 ? C.cGreen : score >= 2 ? C.cRed : C.cDRed) + score);
: score >= 2 ? C.cRed : C.cDRed) + score);
if (score == 5) if (score >= 5)
{ {
setCompleted(p); setCompleted(player);
} }
} }
@ -281,30 +263,70 @@ public class ChallengeMilkACow extends Challenge
} }
@EventHandler @EventHandler
public void onConsume(PlayerItemConsumeEvent event) public void onPlayerItemConsume(PlayerItemConsumeEvent event)
{ {
if (!isChallengeValid())
return;
Player player = event.getPlayer();
if (!isPlayerValid(player))
return;
player.updateInventory();
UtilPlayer.message(player, F.main("Game", "Deliver the milk to the farmer!"));
event.setCancelled(true); event.setCancelled(true);
event.getPlayer().updateInventory();
event.getPlayer().sendMessage(F.main("Mike the Cows", "Deliver the milk to the farmer!"));
} }
@Override private void spawnCowsAndFarmer()
public ArrayList<Location> createSpawns()
{ {
ArrayList<Location> spawns = new ArrayList<Location>(); Host.CreatureAllow = true;
for (int x = -(getArenaSize() - 1); x <= getArenaSize() - 1; x++) spawnFarmerJoe();
String[] chosenNames = _humanNames;
if (UtilMath.r(5) == 0)
{ {
for (int z = -(getArenaSize() - 1); z <= getArenaSize() - 1; z++) chosenNames = _cowNames;
{
if (x % 2 == 0 && z % 2 == 0)
{
spawns.add(getCenter().clone().add(x + 0.5, 1.1, z + 0.5));
}
}
} }
return spawns; for (int i = 0; i < 8; i++)
{
spawnCow(chosenNames, i);
}
Host.CreatureAllow = false;
}
private void spawnFarmerJoe()
{
_villager = (Villager) getCenter().getWorld().spawnEntity(getCenter().add(0, 1, 0), EntityType.VILLAGER);
_villager.setProfession(Profession.FARMER);
_villager.setCustomName(C.Bold + "Farmer Joe");
_villager.setCustomNameVisible(true);
}
private void spawnCow(String[] chosenNames, int index)
{
Location loc = getRandomLocation();
Cow cow = (Cow) loc.getWorld().spawnEntity(loc, EntityType.COW);
cow.setCustomName(C.cWhite + chosenNames[index]);
cow.setCustomNameVisible(true);
_milked.put(cow, new ArrayList<String>());
_cowIndicator.put(cow, new Hologram(Host.Manager.getHologramManager(), cow.getLocation().add(0, 2.5, 0), C.cRed + "Already Milked!"));
Hologram holo = _cowIndicator.get(cow);
holo.setHologramTarget(HologramTarget.WHITELIST);
holo.setFollowEntity(cow);
holo.start();
}
private Location getRandomLocation()
{
return getCenter().add(UtilMath.r(((getArenaSize() * 2) - 1) - (getArenaSize() - 1)), 1, UtilMath.r((getArenaSize() * 2) - 1) - (getArenaSize() - 1));
} }
public HashMap<Player, Integer> getScore() public HashMap<Player, Integer> getScore()

View File

@ -11,17 +11,23 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilMath;
import mineplex.core.itemstack.ItemBuilder;
import nautilus.game.arcade.game.games.mineware.BawkBawkBattles; 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;
public class ChallengeMineADiamond extends Challenge public class ChallengeMineADiamond extends Challenge
{ {
private ArrayList<Material> _ores = new ArrayList<Material>(Arrays.asList(Material.IRON_ORE, Material.GOLD_ORE, private ArrayList<Material> _ores = new ArrayList<Material>(Arrays.asList(
Material.REDSTONE_ORE, Material.EMERALD_ORE, Material.COAL_ORE, Material.LAPIS_ORE)); Material.COAL_ORE,
Material.IRON_ORE,
Material.GOLD_ORE,
Material.EMERALD_ORE,
Material.REDSTONE_ORE,
Material.LAPIS_ORE));
private ArrayList<Block> _diamonds = new ArrayList<Block>(); private ArrayList<Block> _diamonds = new ArrayList<Block>();
public ChallengeMineADiamond(BawkBawkBattles host) public ChallengeMineADiamond(BawkBawkBattles host)
@ -33,44 +39,7 @@ public class ChallengeMineADiamond extends Challenge
"Find a diamond around the map."); "Find a diamond around the map.");
Settings.setUseMapHeight(); Settings.setUseMapHeight();
} Settings.setLockInventory(4);
@Override
public ArrayList<Location> createSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
for (int x = -getArenaSize() + 1; x <= getArenaSize() - 1; x++)
{
for (int z = -getArenaSize() + 1; z <= getArenaSize() - 1; z++)
{
if (x % 2 == 0 && z % 2 == 0)
{
spawns.add(getCenter().clone().add(x + 0.5, 2.1, z + 0.5));
}
}
}
return spawns;
}
@Override
public void onEnd()
{
Host.BlockBreak = false;
}
@Override
public void onStart()
{
for (Player player : Host.GetPlayers(true))
{
player.getInventory().addItem(new ItemStack(Material.DIAMOND_PICKAXE));
}
for (Block diamond : _diamonds)
{
diamond.setType(Material.DIAMOND_ORE);
}
Host.BlockBreak = true;
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@ -87,34 +56,31 @@ public class ChallengeMineADiamond extends Challenge
{ {
double absX = Math.abs(x); double absX = Math.abs(x);
double absZ = Math.abs(z); double absZ = Math.abs(z);
Block b = getCenter().getBlock().getRelative(x, y, z); Block block = getCenter().getBlock().getRelative(x, y, z);
if (y == 0) if (y == 0)
{ {
b.setType(Material.DIRT); block.setType(Material.DIRT);
b.setData((byte) 2); block.setData((byte) 2);
} }
else if (y == 1) else if (y == 1)
{ {
if (absX == getArenaSize() || absZ == getArenaSize()) if (absX == getArenaSize() || absZ == getArenaSize())
{ {
if (UtilMath.random.nextBoolean()) if (UtilMath.random.nextBoolean())
b.setType(Material.STONE); block.setType(Material.STONE);
else else
b.setType(Material.COBBLESTONE); block.setType(Material.COBBLESTONE);
} }
else else
{ {
if (amountOfDiamonds == 0) if (amountOfDiamonds == 0)
{ {
for (int i = 0; i < Math.ceil((Host.GetPlayers(true).size() + 1) / 2); i++) for (int i = 0; i < Math.ceil((getChallengers().size() + 1) / 2); i++)
{ {
Block copy = getCenter().getBlock().getRelative( Block copy = getCenter().getBlock().getRelative(UtilMath.r(getArenaSize() * 2) - (getArenaSize()), 1, UtilMath.r(getArenaSize() * 2) - (getArenaSize()));
UtilMath.r(getArenaSize() * 2) - (getArenaSize()), 1,
UtilMath.r(getArenaSize() * 2) - (getArenaSize()));
if (copy.getType() == Material.DIAMOND_ORE && Math.abs(copy.getX()) < getArenaSize() if (copy.getType() == Material.DIAMOND_ORE && Math.abs(copy.getX()) < getArenaSize() && Math.abs(copy.getY()) < getArenaSize())
&& Math.abs(copy.getY()) < getArenaSize())
{ {
i--; i--;
continue; continue;
@ -127,62 +93,100 @@ public class ChallengeMineADiamond extends Challenge
} }
} }
if (b.getType() != Material.DIAMOND_ORE) if (block.getType() != Material.DIAMOND_ORE)
{ {
b.setType(_ores.get(UtilMath.r(_ores.size()))); block.setType(UtilMath.randomElement(_ores));
} }
} }
} }
else if (y == 2 && (absX == getArenaSize() || absZ == getArenaSize())) else if (y == 2 && (absX == getArenaSize() || absZ == getArenaSize()))
{ {
b.setType(Material.FENCE); block.setType(Material.FENCE);
} }
if (b.getType() != Material.AIR) addBlock(block);
}
}
}
}
@Override
public ArrayList<Location> createSpawns()
{ {
addBlock(b); ArrayList<Location> spawns = new ArrayList<Location>();
for (int x = -getArenaSize() + 1; x <= getArenaSize() - 1; x++)
{
for (int z = -getArenaSize() + 1; z <= getArenaSize() - 1; z++)
{
if (x % 2 == 0 && z % 2 == 0)
{
spawns.add(getCenter().add(x + 0.5, 2.1, z + 0.5));
} }
} }
} }
return spawns;
} }
@Override
public void onStart()
{
setItem(Settings.getLockedSlot(), new ItemBuilder(Material.DIAMOND_PICKAXE).setUnbreakable(true).build());
for (Block diamond : _diamonds)
{
diamond.setType(Material.DIAMOND_ORE);
}
Host.BlockBreak = true;
}
@Override
public void onEnd()
{
Host.BlockBreak = false;
} }
@EventHandler @EventHandler
public void onDiamondMine(PlayerInteractEvent event) public void onPlayerInteract(PlayerInteractEvent event)
{
if (!Host.IsLive())
{ {
if (!isChallengeValid())
return; return;
}
if (!Host.IsAlive(event.getPlayer())) Player player = event.getPlayer();
{
return; if (Data.isCompleted(player))
}
if (Data.isCompleted(event.getPlayer()))
{ {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (!isPlayerValid(player))
return;
if (event.getAction() == Action.LEFT_CLICK_BLOCK) if (event.getAction() == Action.LEFT_CLICK_BLOCK)
{ {
if (event.getClickedBlock().getType() == Material.DIAMOND_ORE) Block block = event.getClickedBlock();
if (block == null)
return;
if (block.getType() == Material.DIAMOND_ORE)
{ {
setCompleted(event.getPlayer(), true); setCompleted(player, true);
event.getClickedBlock().setType(Material.AIR); block.setType(Material.AIR);
} }
} }
} }
@EventHandler @EventHandler
public void onPlayerMineblock(BlockBreakEvent event) public void onBlockBreak(BlockBreakEvent event)
{
if (!Host.IsLive())
{ {
if (!isChallengeValid())
return; return;
}
if (event.getBlock().getType() != Material.DIAMOND_ORE) if (event.getBlock().getType() != Material.DIAMOND_ORE)
{
event.setCancelled(true); event.setCancelled(true);
} }
}
} }

View File

@ -129,6 +129,8 @@ public class ChickenAttack
private void spawnChickens() private void spawnChickens()
{ {
_host.CreatureAllow = true;
int spawnAmount = _chickenSpawnAmount / _spawnpoints.length; int spawnAmount = _chickenSpawnAmount / _spawnpoints.length;
for (int i = 0; i < _spawnpoints.length; i++) for (int i = 0; i < _spawnpoints.length; i++)
@ -142,6 +144,8 @@ public class ChickenAttack
customizeChicken(chicken); customizeChicken(chicken);
} }
} }
_host.CreatureAllow = false;
} }
private void customizeChicken(Chicken chicken) private void customizeChicken(Chicken chicken)