Challenge refactoring, modify challenge ending and chat messages, add generateGrass helper method.
This commit is contained in:
parent
4e6ba4ebd1
commit
1ee7a42b9c
@ -149,6 +149,8 @@ public class BawkBawkBattles extends TeamGame implements IThrown
|
||||
private String _restrictCommand = "restrict";
|
||||
private String _skipCommand = "skip";
|
||||
|
||||
// TODO: Do not trigger chicken attack if the game is about to end.
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public BawkBawkBattles(ArcadeManager manager)
|
||||
{
|
||||
@ -176,7 +178,6 @@ public class BawkBawkBattles extends TeamGame implements IThrown
|
||||
DeathTeleport = false;
|
||||
AutomaticRespawn = false;
|
||||
DeathMessages = false;
|
||||
CreatureAllow = true;
|
||||
|
||||
TeleportsDisqualify = false;
|
||||
GiveClock = false;
|
||||
@ -219,9 +220,9 @@ public class BawkBawkBattles extends TeamGame implements IThrown
|
||||
ChallengeInfestation.class, // Playable - Refactored
|
||||
ChallengeKangarooJump.class, // Playable - Refactored
|
||||
ChallengeKingOfTheHill.class, // Playable - Refactored
|
||||
ChallengeLavaRun.class, // Playable
|
||||
ChallengeMilkACow.class, // Playable- Check cow names.
|
||||
ChallengeMineADiamond.class, // Playable
|
||||
ChallengeLavaRun.class, // Playable - Refactored
|
||||
ChallengeMilkACow.class, // Playable - Refactored
|
||||
ChallengeMineADiamond.class, // Playable - Refactored
|
||||
ChallengeMinecartDance.class, // Playable
|
||||
ChallengeMiniOneInTheQuiver.class, // Playable
|
||||
ChallengeNavigateMaze.class, // Broken
|
||||
@ -614,8 +615,19 @@ public class BawkBawkBattles extends TeamGame implements IThrown
|
||||
}
|
||||
|
||||
if (_challenge.getData().hasAnyoneCompleted() && !_challenge.getData().isCompleted(player))
|
||||
//looseLife(player, true);
|
||||
handleDeath(player);
|
||||
{
|
||||
int lives = lives(player) - 1;
|
||||
|
||||
if (lives > 0)
|
||||
{
|
||||
looseLife(player);
|
||||
taskFailedMessage(player, lives(player));
|
||||
}
|
||||
else
|
||||
{
|
||||
handleDeath(player);
|
||||
}
|
||||
}
|
||||
|
||||
if (_challenge.getData().isCompleted(player))
|
||||
AddGems(player, 3, "Completed Challenge", true, true);
|
||||
@ -1141,29 +1153,31 @@ public class BawkBawkBattles extends TeamGame implements IThrown
|
||||
|
||||
private void gameLostMessage(Player player)
|
||||
{
|
||||
UtilPlayer.message(player, "");
|
||||
UtilPlayer.message(player, C.cRed + C.Bold + "You are out of the game.");
|
||||
UtilPlayer.message(player, F.main("Game", C.cRed + "You are out of the game."));
|
||||
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)
|
||||
{
|
||||
UtilPlayer.message(player, "");
|
||||
UtilPlayer.message(player, C.cRed + C.Bold + "You failed the task!");
|
||||
UtilPlayer.message(player, F.main("Game", C.cRed + "You have failed the task."));
|
||||
|
||||
String suffix = "lives";
|
||||
|
||||
if (lives == 1)
|
||||
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)
|
||||
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, "");
|
||||
UtilPlayer.message(player, F.main("Game", msg));
|
||||
|
||||
player.playSound(player.getLocation(), Sound.NOTE_BASS, 2.0F, 1.0F);
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import java.util.HashSet;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
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.UtilInv;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.common.util.UtilTextBottom;
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
import mineplex.core.hologram.Hologram;
|
||||
@ -135,7 +133,7 @@ public abstract class Challenge implements Listener
|
||||
player.addPotionEffect(new PotionEffect(type, duration, amplifier));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void removePrimedTNTEntities()
|
||||
{
|
||||
for (Entity entity : Host.WorldData.World.getEntities())
|
||||
@ -146,7 +144,7 @@ public abstract class Challenge implements Listener
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void removeBoatEntities()
|
||||
{
|
||||
for (Entity entity : Host.WorldData.World.getEntities())
|
||||
@ -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()
|
||||
{
|
||||
return Host.IsLive() && Host.getSettings().isChallengeStarted();
|
||||
@ -264,6 +281,8 @@ public abstract class Challenge implements Listener
|
||||
{
|
||||
if (Data.getCompletedPlayers().contains(player))
|
||||
return;
|
||||
|
||||
Host.taskWinMessage(player);
|
||||
|
||||
if (cloak)
|
||||
{
|
||||
@ -272,13 +291,7 @@ public abstract class Challenge implements Listener
|
||||
}
|
||||
|
||||
Data.addCompletedPlayer(player);
|
||||
|
||||
UtilPlayer.message(player, "");
|
||||
UtilPlayer.message(player, C.cGreen + C.Bold + "You completed the task!");
|
||||
UtilPlayer.message(player, "");
|
||||
|
||||
UtilInv.Clear(player);
|
||||
player.playSound(player.getLocation(), Sound.LEVEL_UP, 2.0F, 1.0F);
|
||||
}
|
||||
|
||||
public void setCompleted(Player player)
|
||||
@ -290,6 +303,8 @@ public abstract class Challenge implements Listener
|
||||
{
|
||||
if (Data.isDone(player))
|
||||
return;
|
||||
|
||||
Host.taskFailedMessage(player, Host.lives(player));
|
||||
|
||||
if (!Host.getSettings().isCrumbling())
|
||||
Data.addLostPlayer(player);
|
||||
@ -300,12 +315,8 @@ public abstract class Challenge implements Listener
|
||||
Host.Manager.GetCondition().Factory().Cloak("Lost", player, player, 7777, true, false);
|
||||
}
|
||||
|
||||
UtilInv.Clear(player);
|
||||
|
||||
Host.looseLife(player);
|
||||
Host.taskFailedMessage(player, Host.lives(player));
|
||||
|
||||
// Host.handleFailure(player, true);
|
||||
UtilInv.Clear(player);
|
||||
}
|
||||
|
||||
public void setLost(Player player)
|
||||
|
@ -1,6 +1,5 @@
|
||||
package nautilus.game.arcade.game.games.mineware.challenge;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
|
@ -10,7 +10,9 @@ import org.bukkit.block.Chest;
|
||||
import org.bukkit.block.DoubleChest;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -120,6 +122,31 @@ public class ChallengeDiamondSeeker extends Challenge
|
||||
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
|
||||
public void onInventoryClick(InventoryClickEvent event)
|
||||
{
|
||||
@ -144,6 +171,7 @@ public class ChallengeDiamondSeeker extends Challenge
|
||||
{
|
||||
event.setCurrentItem(new ItemStack(Material.AIR));
|
||||
setCompleted(player);
|
||||
player.closeInventory();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -106,17 +106,9 @@ public class ChallengeDogsVersusCats extends Challenge
|
||||
{
|
||||
block.setType(Material.FENCE);
|
||||
}
|
||||
else if (y == 1 && UtilMath.r(4) == 0)
|
||||
else if (y == 1)
|
||||
{
|
||||
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);
|
||||
}
|
||||
generateGrass(block);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,12 +25,11 @@ import nautilus.game.arcade.game.games.mineware.challenge.ChallengeType;
|
||||
|
||||
public class ChallengeLavaRun extends Challenge
|
||||
{
|
||||
private Block _obsidian;
|
||||
private int mapY = 4;
|
||||
|
||||
private long _delay;
|
||||
private long _minusDelay = 1000;
|
||||
private int _disappearingBlocks = 10;
|
||||
private Block _obsidian;
|
||||
|
||||
public ChallengeLavaRun(BawkBawkBattles host)
|
||||
{
|
||||
@ -41,7 +40,7 @@ public class ChallengeLavaRun extends Challenge
|
||||
"The lava is coming!",
|
||||
"Stand on the obsidian.",
|
||||
"Run! Run! Run!");
|
||||
|
||||
|
||||
Settings.setUseMapHeight();
|
||||
Settings.setMaxPlayers(30);
|
||||
}
|
||||
@ -84,39 +83,52 @@ public class ChallengeLavaRun extends Challenge
|
||||
_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
|
||||
public void onBlockFromTo(BlockFromToEvent event)
|
||||
{
|
||||
if (!Host.IsLive())
|
||||
if (!isChallengeValid())
|
||||
return;
|
||||
|
||||
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
|
||||
public void onDamage(CustomDamageEvent event)
|
||||
{
|
||||
if (event.GetDamagerEntity(true) != null)
|
||||
{
|
||||
if (!isChallengeValid())
|
||||
return;
|
||||
|
||||
if (event.GetDamagerEntity(true) != null)
|
||||
return;
|
||||
}
|
||||
|
||||
event.AddMod("Ensure Death", null, 9999, false);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventHandler
|
||||
public void onUpdate(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.TICK)
|
||||
return;
|
||||
|
||||
if (!isChallengeValid())
|
||||
return;
|
||||
|
||||
if (_delay > System.currentTimeMillis())
|
||||
return;
|
||||
|
||||
@ -152,11 +164,11 @@ public class ChallengeLavaRun extends Challenge
|
||||
{
|
||||
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++)
|
||||
{
|
||||
Block b = glassBlocks.remove(0);
|
||||
b.setTypeIdAndData(Material.AIR.getId(), (byte) 0, false);
|
||||
addBlock(b);
|
||||
Block block = glassBlocks.remove(0);
|
||||
block.setTypeIdAndData(Material.AIR.getId(), (byte) 0, false);
|
||||
addBlock(block);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart()
|
||||
private 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;
|
||||
}
|
||||
|
||||
private void createLava()
|
||||
{
|
||||
_delay = System.currentTimeMillis() + 2000;
|
||||
int size = getArenaSize() + 3;
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -40,6 +40,28 @@ public class ChallengeMilkACow extends Challenge
|
||||
private HashMap<Player, Integer> _score = new HashMap<Player, Integer>();
|
||||
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)
|
||||
{
|
||||
super(
|
||||
@ -48,8 +70,78 @@ public class ChallengeMilkACow extends Challenge
|
||||
"Milk a Cow",
|
||||
"Milk 5 different cows.",
|
||||
"Deliver the milk to the villager!");
|
||||
|
||||
|
||||
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
|
||||
@ -62,12 +154,16 @@ public class ChallengeMilkACow extends Challenge
|
||||
|
||||
cow.remove();
|
||||
}
|
||||
|
||||
_villager.remove();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void Damage(CustomDamageEvent event)
|
||||
public void onCustomDamage(CustomDamageEvent event)
|
||||
{
|
||||
if (!isChallengeValid())
|
||||
return;
|
||||
|
||||
if (event.GetProjectile() == null)
|
||||
return;
|
||||
|
||||
@ -76,6 +172,9 @@ public class ChallengeMilkACow extends Challenge
|
||||
if (player == null)
|
||||
return;
|
||||
|
||||
if (!isPlayerValid(player))
|
||||
return;
|
||||
|
||||
LivingEntity ent = event.GetDamageeEntity();
|
||||
|
||||
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
|
||||
public void cowIndicator(UpdateEvent event)
|
||||
public void onCowIndicatorUpdate(UpdateEvent event)
|
||||
{
|
||||
if (!Host.IsLive())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (event.getType() != UpdateType.SEC)
|
||||
{
|
||||
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))
|
||||
{
|
||||
holo.addPlayer(playerName);
|
||||
@ -221,19 +209,15 @@ public class ChallengeMilkACow extends Challenge
|
||||
@EventHandler
|
||||
public void onEntityInteract(PlayerInteractEntityEvent event)
|
||||
{
|
||||
Player p = event.getPlayer();
|
||||
|
||||
if (UtilPlayer.isSpectator(p))
|
||||
{
|
||||
if (!isChallengeValid())
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Host.IsLive())
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (!isPlayerValid(player))
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack item = p.getItemInHand();
|
||||
ItemStack item = player.getItemInHand();
|
||||
|
||||
if (item == null)
|
||||
return;
|
||||
@ -244,15 +228,14 @@ public class ChallengeMilkACow extends Challenge
|
||||
{
|
||||
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));
|
||||
_milked.get(ent).add(p.getName());
|
||||
Cow cow = (Cow) ent;
|
||||
player.setItemInHand(new ItemStack(Material.MILK_BUCKET));
|
||||
_milked.get(ent).add(player.getName());
|
||||
}
|
||||
else
|
||||
{
|
||||
p.updateInventory();
|
||||
player.updateInventory();
|
||||
}
|
||||
}
|
||||
|
||||
@ -262,17 +245,16 @@ public class ChallengeMilkACow extends Challenge
|
||||
{
|
||||
if (item.getType() == Material.MILK_BUCKET)
|
||||
{
|
||||
p.setItemInHand(new ItemStack(Material.BUCKET));
|
||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 2, 0);
|
||||
int score = _score.get(p) + 1;
|
||||
_score.put(p, score);
|
||||
player.setItemInHand(new ItemStack(Material.BUCKET));
|
||||
player.playSound(player.getLocation(), Sound.ORB_PICKUP, 2, 0);
|
||||
int score = _score.get(player) + 1;
|
||||
_score.put(player, score);
|
||||
|
||||
displayCount(p, ((Villager) ent).getEyeLocation().add(0, 0.3, 0), (score >= 5 ? C.cDGreen : score >= 3 ? C.cGreen
|
||||
: score >= 2 ? C.cRed : C.cDRed) + score);
|
||||
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);
|
||||
|
||||
if (score == 5)
|
||||
if (score >= 5)
|
||||
{
|
||||
setCompleted(p);
|
||||
setCompleted(player);
|
||||
}
|
||||
}
|
||||
|
||||
@ -281,30 +263,70 @@ public class ChallengeMilkACow extends Challenge
|
||||
}
|
||||
|
||||
@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.getPlayer().updateInventory();
|
||||
event.getPlayer().sendMessage(F.main("Mike the Cows", "Deliver the milk to the farmer!"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<Location> createSpawns()
|
||||
private void spawnCowsAndFarmer()
|
||||
{
|
||||
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++)
|
||||
{
|
||||
if (x % 2 == 0 && z % 2 == 0)
|
||||
{
|
||||
spawns.add(getCenter().clone().add(x + 0.5, 1.1, z + 0.5));
|
||||
}
|
||||
}
|
||||
chosenNames = _cowNames;
|
||||
}
|
||||
|
||||
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()
|
||||
|
@ -11,17 +11,23 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
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.challenge.Challenge;
|
||||
import nautilus.game.arcade.game.games.mineware.challenge.ChallengeType;
|
||||
|
||||
public class ChallengeMineADiamond extends Challenge
|
||||
{
|
||||
private ArrayList<Material> _ores = new ArrayList<Material>(Arrays.asList(Material.IRON_ORE, Material.GOLD_ORE,
|
||||
Material.REDSTONE_ORE, Material.EMERALD_ORE, Material.COAL_ORE, Material.LAPIS_ORE));
|
||||
private ArrayList<Material> _ores = new ArrayList<Material>(Arrays.asList(
|
||||
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>();
|
||||
|
||||
public ChallengeMineADiamond(BawkBawkBattles host)
|
||||
@ -31,46 +37,9 @@ public class ChallengeMineADiamond extends Challenge
|
||||
ChallengeType.FirstComplete,
|
||||
"Mine a Diamond",
|
||||
"Find a diamond around the map.");
|
||||
|
||||
|
||||
Settings.setUseMapHeight();
|
||||
}
|
||||
|
||||
@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;
|
||||
Settings.setLockInventory(4);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@ -87,34 +56,31 @@ public class ChallengeMineADiamond extends Challenge
|
||||
{
|
||||
double absX = Math.abs(x);
|
||||
double absZ = Math.abs(z);
|
||||
Block b = getCenter().getBlock().getRelative(x, y, z);
|
||||
Block block = getCenter().getBlock().getRelative(x, y, z);
|
||||
|
||||
if (y == 0)
|
||||
{
|
||||
b.setType(Material.DIRT);
|
||||
b.setData((byte) 2);
|
||||
block.setType(Material.DIRT);
|
||||
block.setData((byte) 2);
|
||||
}
|
||||
else if (y == 1)
|
||||
{
|
||||
if (absX == getArenaSize() || absZ == getArenaSize())
|
||||
{
|
||||
if (UtilMath.random.nextBoolean())
|
||||
b.setType(Material.STONE);
|
||||
block.setType(Material.STONE);
|
||||
else
|
||||
b.setType(Material.COBBLESTONE);
|
||||
block.setType(Material.COBBLESTONE);
|
||||
}
|
||||
else
|
||||
{
|
||||
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(
|
||||
UtilMath.r(getArenaSize() * 2) - (getArenaSize()), 1,
|
||||
UtilMath.r(getArenaSize() * 2) - (getArenaSize()));
|
||||
Block copy = getCenter().getBlock().getRelative(UtilMath.r(getArenaSize() * 2) - (getArenaSize()), 1, UtilMath.r(getArenaSize() * 2) - (getArenaSize()));
|
||||
|
||||
if (copy.getType() == Material.DIAMOND_ORE && Math.abs(copy.getX()) < getArenaSize()
|
||||
&& Math.abs(copy.getY()) < getArenaSize())
|
||||
if (copy.getType() == Material.DIAMOND_ORE && Math.abs(copy.getX()) < getArenaSize() && Math.abs(copy.getY()) < getArenaSize())
|
||||
{
|
||||
i--;
|
||||
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()))
|
||||
{
|
||||
b.setType(Material.FENCE);
|
||||
block.setType(Material.FENCE);
|
||||
}
|
||||
|
||||
if (b.getType() != Material.AIR)
|
||||
{
|
||||
addBlock(b);
|
||||
}
|
||||
addBlock(block);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDiamondMine(PlayerInteractEvent event)
|
||||
@Override
|
||||
public ArrayList<Location> createSpawns()
|
||||
{
|
||||
if (!Host.IsLive())
|
||||
ArrayList<Location> spawns = new ArrayList<Location>();
|
||||
|
||||
for (int x = -getArenaSize() + 1; x <= getArenaSize() - 1; x++)
|
||||
{
|
||||
return;
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!Host.IsAlive(event.getPlayer()))
|
||||
|
||||
return spawns;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
setItem(Settings.getLockedSlot(), new ItemBuilder(Material.DIAMOND_PICKAXE).setUnbreakable(true).build());
|
||||
|
||||
for (Block diamond : _diamonds)
|
||||
{
|
||||
return;
|
||||
diamond.setType(Material.DIAMOND_ORE);
|
||||
}
|
||||
if (Data.isCompleted(event.getPlayer()))
|
||||
|
||||
Host.BlockBreak = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnd()
|
||||
{
|
||||
Host.BlockBreak = false;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event)
|
||||
{
|
||||
if (!isChallengeValid())
|
||||
return;
|
||||
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (Data.isCompleted(player))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isPlayerValid(player))
|
||||
return;
|
||||
|
||||
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);
|
||||
event.getClickedBlock().setType(Material.AIR);
|
||||
setCompleted(player, true);
|
||||
block.setType(Material.AIR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMineblock(BlockBreakEvent event)
|
||||
public void onBlockBreak(BlockBreakEvent event)
|
||||
{
|
||||
if (!Host.IsLive())
|
||||
{
|
||||
if (!isChallengeValid())
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getBlock().getType() != Material.DIAMOND_ORE)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -129,6 +129,8 @@ public class ChickenAttack
|
||||
|
||||
private void spawnChickens()
|
||||
{
|
||||
_host.CreatureAllow = true;
|
||||
|
||||
int spawnAmount = _chickenSpawnAmount / _spawnpoints.length;
|
||||
|
||||
for (int i = 0; i < _spawnpoints.length; i++)
|
||||
@ -142,6 +144,8 @@ public class ChickenAttack
|
||||
customizeChicken(chicken);
|
||||
}
|
||||
}
|
||||
|
||||
_host.CreatureAllow = false;
|
||||
}
|
||||
|
||||
private void customizeChicken(Chicken chicken)
|
||||
|
Loading…
Reference in New Issue
Block a user