Merge branch 'thanos-mineware' into develop

This commit is contained in:
cnr 2016-07-13 05:04:50 -05:00
commit e40abd4859
98 changed files with 15072 additions and 4429 deletions

View File

@ -714,6 +714,67 @@ public enum Achievement
new int[]{1},
AchievementCategory.MINE_STRIKE),
//Bawk Bawk Battles
BAWK_BAWK_BATTLES_VETERAN("Veteran", 1000,
new String[]{"Bawk Bawk Battles.Veteran"},
new String[]{"Win 50 games of Bawk Bawk Battles"},
new int[] {50},
AchievementCategory.BAWK_BAWK_BATTLES),
BAWK_BAWK_BATTLES_PINATA_MASTER("Pinata Master", 1000,
new String[]{"Bawk Bawk Battles.PinataMaster"},
new String[]{C.cGray + "Chicken Shooting Challenge", "Shoot 500 chickens"},
new int[] {500},
AchievementCategory.BAWK_BAWK_BATTLES),
BAWK_BAWK_BATTLES_SURF_UP("Surf Up", 1000,
new String[]{"Bawk Bawk Battles.SurfUp"},
new String[]{C.cGray + "Wave Crush Challenge", "Avoid 500 waves"},
new int[] {500},
AchievementCategory.BAWK_BAWK_BATTLES),
BAWK_BAWK_BATTLES_MILK_MAN("Milk Man", 600,
new String[]{"Bawk Bawk Battles.MilkMan"},
new String[]{C.cGray + "Milk A Cow Challenge", "Deliver 300 buckets of milk to the farmer"},
new int[] {300},
AchievementCategory.BAWK_BAWK_BATTLES),
BAWK_BAWK_BATTLES_DRAGON_KING("Dragon King", 600,
new String[]{"Bawk Bawk Battles.DragonKing"},
new String[]{C.cGray + "Egg Smash Challenge", "Smash 300 dragon eggs"},
new int[] {300},
AchievementCategory.BAWK_BAWK_BATTLES),
BAWK_BAWK_BATTLES_PIXEL_NINJA("Pixel Ninja", 200,
new String[]{"Bawk Bawk Battles.PixelNinja"},
new String[]{C.cGray + "Falling Blocks Challenge", "Dodge 100 waves of falling blocks"},
new int[] {100},
AchievementCategory.BAWK_BAWK_BATTLES),
BAWK_BAWK_BATTLES_ELITE_ARCHER("Elite Archer", 200,
new String[]{"Bawk Bawk Battles.EliteArcher"},
new String[]{C.cGray + "Mini OITQ Challenge", "Kill 100 players"},
new int[] {100},
AchievementCategory.BAWK_BAWK_BATTLES),
BAWK_BAWK_BATTLES_TAG_MASTER("Tag Master", 500,
new String[]{"Bawk Bawk Battles.TagMaster"},
new String[]{C.cGray + "Reverse Tag Challenge", "Win 5 entire rounds", "without being untagged"},
new int[] {5},
AchievementCategory.BAWK_BAWK_BATTLES),
BAWK_BAWK_BATTLES_SPEEDY_BUILDERS("Speedy Builders", 500,
new String[]{"Bawk Bawk Battles.SpeedyBuilders"},
new String[]{C.cGray + "Build Race Challenge", "Place all blocks in your", "inventory within 15 seconds"},
new int[] {3},
AchievementCategory.BAWK_BAWK_BATTLES),
// BAWK_BAWK_BATTLES_BOUNCING_SHADOW("Bouncing Shadow", 500,
// new String[]{"Bawk Bawk Battles.BouncingShadow"},
// new String[]{C.cGray + "Bouncing Block Challenge", "Win 3 entire rounds", "without stepping on red wool"},
// new int[] {3},
// AchievementCategory.BAWK_BAWK_BATTLES),
//Bomb Lobbers
BOMB_LOBBERS_WINS("Master Bomber", 1200,
new String[]{"Bomb Lobbers.Wins"},

View File

@ -2,6 +2,10 @@ package mineplex.core.achievement;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
@ -10,10 +14,6 @@ import mineplex.core.game.GameDisplay;
import mineplex.core.stats.PlayerStats;
import mineplex.core.stats.StatsManager;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
public enum AchievementCategory
{
GLOBAL("Global", null,
@ -62,6 +62,10 @@ public enum AchievementCategory
new StatDisplay("Kills as Undead"), new StatDisplay("Deaths as Undead"), StatDisplay.GEMS_EARNED },
Material.DIAMOND_CHESTPLATE, 0, GameCategory.CLASSICS, null, false, GameDisplay.CastleSiege.getGameId()),
BAWK_BAWK_BATTLES("Bawk Bawk Battles", null,
new StatDisplay[] { StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.GEMS_EARNED },
Material.EGG, 0, GameCategory.CLASSICS, null, false, GameDisplay.BawkBawkBattles.getGameId()),
BLOCK_HUNT("Block Hunt", null,
new StatDisplay[] { StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED },
Material.GRASS, 0, GameCategory.CLASSICS, "Infestor Kit", false, GameDisplay.HideSeek.getGameId()),

View File

@ -46,7 +46,7 @@ public class AchievementMainPage extends ShopPageBase<AchievementManager, Achiev
protected void buildPage()
{
ArrayList<Integer> pageLayout = new ItemLayout(
"XXXXOXXXO",
"XXXXOXOXO",
"OXOXOXOXO",
"OXOXOXOXO",
"OXOXOXOXO").getItemSlots();

View File

@ -32,7 +32,7 @@ public enum GameDisplay
Micro("Micro Battle", Material.LAVA_BUCKET, (byte)0, GameCategory.ARCADE, 24),
MilkCow("Milk the Cow", Material.MILK_BUCKET, (byte)0, GameCategory.ARCADE, 27),
MineStrike("MineStrike", Material.TNT, (byte)0, GameCategory.CHAMPIONS, 25),// Temp set to CHAMPIONS to fix UI bug
MineWare("MineWare", Material.PAPER, (byte)0, GameCategory.EXTRA, 26),
BawkBawkBattles("Bawk Bawk Battles", Material.EGG, (byte)0, GameCategory.EXTRA, 26),
OldMineWare("Old MineWare", Material.PAPER, (byte)0, GameCategory.EXTRA, 26),
Paintball("Super Paintball", Material.ENDER_PEARL, (byte)0, GameCategory.ARCADE, 28),
Quiver("One in the Quiver", Material.ARROW, (byte)0, GameCategory.ARCADE, 29),

View File

@ -53,7 +53,7 @@ import nautilus.game.arcade.game.games.micro.modes.TinyWinners;
import nautilus.game.arcade.game.games.milkcow.MilkCow;
import nautilus.game.arcade.game.games.minecraftleague.MinecraftLeague;
import nautilus.game.arcade.game.games.minestrike.Minestrike;
import nautilus.game.arcade.game.games.mineware.MineWare;
import nautilus.game.arcade.game.games.mineware.BawkBawkBattles;
import nautilus.game.arcade.game.games.monsterleague.MonsterLeague;
import nautilus.game.arcade.game.games.monstermaze.MonsterMaze;
import nautilus.game.arcade.game.games.oldmineware.OldMineWare;
@ -149,7 +149,7 @@ public enum GameType
Pair.create(MinecraftVersion.Version1_8, "http://file.mineplex.com/ResMinestrike.zip"),
Pair.create(MinecraftVersion.Version1_9, "http://file.mineplex.com/ResMinestrike19.zip")
}, true),
MineWare(MineWare.class, GameDisplay.MineWare),
BawkBawkBattles(BawkBawkBattles.class, GameDisplay.BawkBawkBattles),
MinecraftLeague(MinecraftLeague.class, GameDisplay.Minecraft_League),
OldMineWare(OldMineWare.class, GameDisplay.OldMineWare),
Paintball(Paintball.class, GameDisplay.Paintball),
@ -199,7 +199,7 @@ public enum GameType
GameType.Cards, GameType.CastleSiege, GameType.ChampionsDominate, GameType.ChampionsTDM, GameType.Christmas,
GameType.DeathTag, GameType.DragonEscape, GameType.DragonEscapeTeams, GameType.DragonRiders, GameType.Dragons,
GameType.Draw, GameType.Evolution, GameType.Gravity, GameType.Halloween, GameType.HideSeek,
GameType.HoleInTheWall, GameType.Horse, GameType.Micro, GameType.MilkCow, GameType.MineStrike, GameType.MineWare,
GameType.HoleInTheWall, GameType.Horse, GameType.Micro, GameType.MilkCow, GameType.MineStrike, GameType.BawkBawkBattles,
GameType.OldMineWare, GameType.Paintball, GameType.Quiver, GameType.QuiverTeams, GameType.Runner, GameType.SearchAndDestroy,
GameType.Sheep, GameType.Skywars, GameType.SkywarsTeams, GameType.Smash, GameType.SmashDomination, GameType.SmashTeams,
GameType.Snake, GameType.SneakyAssassins, GameType.SnowFight, GameType.Spleef, GameType.SpleefTeams, GameType.SquidShooter,

View File

@ -99,7 +99,7 @@ public class CompassAddon extends MiniPlugin
if (target != null)
{
if (Manager.GetGame().CompassGiveItem || Manager.isSpectator(player))
if (Manager.GetGame().CompassGiveItem || (Manager.GetGame().CompassGiveItemSpectators && Manager.isSpectator(player)))
if (!player.getInventory().contains(Material.COMPASS))
{
if (player.getOpenInventory() == null || player.getOpenInventory().getCursor() == null || player.getOpenInventory().getCursor().getType() != Material.COMPASS)

View File

@ -208,6 +208,7 @@ public abstract class Game implements Listener
public int HungerSet = -1;
public int HealthSet = -1;
public boolean SpawnTeleport = true;
public boolean PrepareFreeze = true;
private double _itemMergeRadius = 0;
@ -242,6 +243,7 @@ public abstract class Game implements Listener
// Addons
public boolean CompassEnabled = false;
public boolean CompassGiveItem = true;
public boolean CompassGiveItemSpectators = true;
public boolean SoupEnabled = true;
public boolean TeamArmor = false;

View File

@ -115,7 +115,7 @@ public class GameTeam
return _spawns;
}
private Location fixFacing(Location loc)
public Location fixFacing(Location loc)
{
if (Host.FixSpawnFacing)
{

View File

@ -0,0 +1,63 @@
package nautilus.game.arcade.game.games.mineware;
/**
* This class contains a list of fields that are used as settings for the main game class.
*/
public class BawkBawkBattlesSettings
{
private boolean _crumbling = false;
private boolean _waiting = true;
private boolean _messagesSent = false;
private boolean _sendingMessages = false;
private boolean _challengeStarted = false;
public void setCrumbling(boolean flag)
{
_crumbling = flag;
}
public boolean isCrumbling()
{
return _crumbling;
}
public void setWaiting(boolean flag)
{
_waiting = flag;
}
public boolean isWaiting()
{
return _waiting;
}
public void markMessagesAsSent(boolean flag)
{
_messagesSent = flag;
}
public boolean areMessagesSent()
{
return _messagesSent;
}
public void markMessagesAsSending(boolean flag)
{
_sendingMessages = flag;
}
public boolean areMessagesBeingSent()
{
return _sendingMessages;
}
public void setChallengeStarted(boolean flag)
{
_challengeStarted = flag;
}
public boolean isChallengeStarted()
{
return _challengeStarted;
}
}

View File

@ -1,249 +0,0 @@
package nautilus.game.arcade.game.games.mineware;
import java.util.ArrayList;
import java.util.HashSet;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.hologram.Hologram;
import mineplex.core.hologram.Hologram.HologramTarget;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.scheduler.BukkitRunnable;
public abstract class Challenge implements Listener
{
public enum ChallengeType
{
LastStanding, FirstComplete
}
public MineWare Host;
private String _order;
protected long StartTime;
protected long Duration;
private Location _center;
protected HashSet<Player> Completed = new HashSet<Player>();
protected HashSet<Player> Lost = new HashSet<Player>();
private HashSet<Block> _modifiedBlocks = new HashSet<Block>();
protected int Places;
private ChallengeType _challengeType;
public Challenge(MineWare host, ChallengeType challengeType, String challengeName)
{
Host = host;
_order = challengeName;
_center = new Location(host.WorldData.World, 0, 0, 0);
_challengeType = challengeType;
setBorder(-100, 100, 0, 256, -100, 100);
}
public long getMaxTime()
{
return 60000;
}
public HashSet<Block> getModifiedBlocks()
{
return _modifiedBlocks;
}
public String getMessage(Player player)
{
return _order;
}
public void setBorder(int minX, int maxX, int minY, int maxY, int minZ, int maxZ)
{
Host.WorldData.MinX = minX;
Host.WorldData.MaxX = maxX;
Host.WorldData.MinY = minY;
Host.WorldData.MaxY = maxY;
Host.WorldData.MinZ = minZ;
Host.WorldData.MaxZ = maxZ;
}
protected void addBlock(Block block)
{
_modifiedBlocks.add(block);
}
public void StartOrder()
{
setupPlayers();
Completed.clear();
StartTime = System.currentTimeMillis();
Duration = getMaxTime();
Places = (int) Math.ceil(getChallengers().size() / 2D);
}
public void EndOrder()
{
cleanupRoom();
}
protected void displayCount(Player player, Location loc, String string)
{
final Hologram hologram = new Hologram(Host.Manager.getHologramManager(), loc, string);
hologram.setHologramTarget(HologramTarget.WHITELIST);
hologram.addPlayer(player);
hologram.start();
final long expires = System.currentTimeMillis() + 500;
new BukkitRunnable()
{
public void run()
{
if (!Host.IsLive() || expires < System.currentTimeMillis())
{
hologram.stop();
cancel();
}
else
{
hologram.setLocation(hologram.getLocation().add(0, 0.1, 0));
}
}
}.runTaskTimer(Host.Manager.getPlugin(), 0, 0);
}
public abstract ArrayList<Location> getSpawns();
public abstract void cleanupRoom();
/**
* Register border
*/
public abstract void setupPlayers();
public abstract void generateRoom();
public String GetOrder()
{
return _order.toUpperCase();
}
public boolean isInsideMap(Player player)
{
return Host.isInsideMap(player.getLocation());
}
public boolean Finish()
{
ArrayList<Player> players = getChallengers();
if (players.size() <= Completed.size())
return true;
if (_challengeType == ChallengeType.LastStanding)
{
if (players.size() <= Places)
{
for (Player player : players)
{
SetCompleted(player);
}
return true;
}
}
else if (_challengeType == ChallengeType.FirstComplete)
{
if (Completed.size() >= Places)
{
return true;
}
}
return UtilTime.elapsed(StartTime, Duration);
}
public int GetTimeLeft()
{
return (int) ((Duration - (System.currentTimeMillis() - StartTime)) / 1000);
}
public void SetCompleted(Player player)
{
if (Completed.contains(player))
return;
Completed.add(player);
UtilPlayer.message(player, C.cGreen + C.Bold + "You completed the task!");
player.playSound(player.getLocation(), Sound.LEVEL_UP, 2f, 1f);
UtilInv.Clear(player);
}
public HashSet<Player> getLost()
{
return Lost;
}
public void setLost(Player player)
{
Host.LoseLife(player, false);
UtilInv.Clear(player);
}
/**
* Get all players that are alive, regardless of having won or not.
*/
public ArrayList<Player> getChallengers()
{
return Host.getChallengers();
}
public boolean IsCompleted(Player player)
{
return Completed.contains(player);
}
public float GetTimeLeftPercent()
{
float a = (float) (Duration - (System.currentTimeMillis() - StartTime));
float b = (float) (Duration);
return a / b;
}
public final int GetRemainingPlaces()
{
if (_challengeType == ChallengeType.FirstComplete)
{
return Places - Completed.size();
}
else if (_challengeType == ChallengeType.LastStanding)
{
return getChallengers().size() - Places;
}
return 0;
}
public int getMinPlayers()
{
return 2;
}
public Location getCenter()
{
return _center.clone();
}
public boolean hasWinner()
{
return !Completed.isEmpty();
}
}

View File

@ -1,564 +0,0 @@
package nautilus.game.arcade.game.games.mineware;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.InventoryHolder;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTextMiddle;
import mineplex.core.common.util.UtilTextTop;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilWorld;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.SoloGame;
import nautilus.game.arcade.game.GameTeam.PlayerState;
import nautilus.game.arcade.game.games.holeinwall.KitNormal;
import nautilus.game.arcade.game.games.mineware.challenges.*;
import nautilus.game.arcade.kit.Kit;
public class MineWare extends SoloGame
{
private HashMap<Player, Integer> _lives = new HashMap<Player, Integer>();
private Challenge _order;
private ArrayList<Block> _lastOrderBlocks;
private long _orderTime;
private boolean _orderWaiting = true;
private ArrayList<Class<? extends Challenge>> _orders = new ArrayList<Class<? extends Challenge>>();
private ArrayList<Class<? extends Challenge>> _ordersCopy = new ArrayList<Class<? extends Challenge>>();
public MineWare(ArcadeManager manager)
{
super(manager, GameType.MineWare,
new Kit[]
{
new KitNormal(manager),
},
new String[]
{
"Follow the orders given in chat!",
"First half to follow it win the round.",
"Other players lose one life.", "Last player with lives wins!"
});
DamageTeamSelf = true;
DamagePvP = false;
DamagePvE = false;
DamageEvP = false;
DamageFall = false;
InventoryClick = true;
DamageSelf = false;
DeathOut = false;
AutomaticRespawn = false;
DeathMessages = false;
Manager.GetCreature().SetDisableCustomDrops(true);
PopulateOrders();
registerChatStats();
}
@Override
public void EndCheck()
{
if (!IsLive())
return;
int living = 0;
for (Player player : GetPlayers(false))
{
if (GetLives(player) > 0)
{
living++;
}
}
if (living <= 1)
{
SetState(GameState.End);
AnnounceEnd(getWinners());
}
}
@Override
public boolean isInsideMap(Player player)
{
if (_order != null && !_orderWaiting)
{
return _order.isInsideMap(player);
}
return true;
}
@EventHandler
public void onLive(GameStateChangeEvent event)
{
if (event.GetState() != GameState.Live)
{
return;
}
_orderTime = System.currentTimeMillis();
}
public void PopulateOrders()
{
_orders.add(ChallengeShootChickens.class);
_orders.add(ChallengeStandOnColor.class);
_orders.add(ChallengeMilkACow.class);
_orders.add(ChallengeDragonEgg.class);
// _orders.add(ChallengeBlockShot.class);
_orders.add(ChallengeChestLoot.class);
_orders.add(ChallengeLavaRun.class);
_orders.add(ChallengeNavigateMaze.class);
// _orders.add(ChallengePickASide.class);
_orders.add(ChallengeHitTargets.class);
// _orders.add(ChallengeNameThatSound.class);
_orders.add(ChallengeVolleyPig.class);
// _orders.add(ChallengeSkyFall.class);
_orders.add(ChallengeSmashOff.class);
_orders.add(ChallengeTntLauncher.class);
//_orders.add(ChallengeSpleef.class); TODO
//_orders.add(ChallengeRunner.class); TODO
// _orders.add(ChallengeDiamondFall.class);
}
public Challenge GetOrder()
{
for (int i = 0; i < _orders.size() * 4; i++)
{
try
{
if (_ordersCopy.isEmpty())
{
_ordersCopy.addAll(_orders);
}
Challenge challenge = _ordersCopy
.remove(UtilMath.r(_ordersCopy.size()))
.getConstructor(MineWare.class).newInstance(this);
if (getChallengers().size() >= challenge.getMinPlayers())
{
System.out.print("Using challenge "
+ challenge.getClass().getSimpleName());
return challenge;
}
else
{
System.out.print("Cannot use challenge "
+ challenge.getClass().getSimpleName()
+ ", not enough players");
}
}
catch (InvocationTargetException ex)
{
ex.getCause().printStackTrace();
}
catch (Exception e)
{
e.printStackTrace();
}
}
return null;
}
@EventHandler(priority = EventPriority.HIGH)
public void GameStateChange(GameStateChangeEvent event)
{
if (event.GetState() != GameState.Prepare)
return;
for (Player player : GetPlayers(true))
_lives.put(player, 5);
_order = GetOrder();
_order.generateRoom();
GetTeamList().get(0).SetSpawns(_order.getSpawns());
SpectatorSpawn = UtilWorld.averageLocation(_order.getSpawns()).add(0,
7, 0);
}
@EventHandler
public void CancelOrder(GameStateChangeEvent event)
{
if (_order == null)
return;
if (_orderWaiting)
return;
if (event.GetState() == GameState.Live)
return;
// Deregister
HandlerList.unregisterAll(_order);
_order.EndOrder();
}
@EventHandler
public void onDamage(CustomDamageEvent event)
{
event.SetDamageToLevel(false);
}
@EventHandler
public void onDeath(PlayerDeathEvent event)
{
if (_order == null)
return;
_order.getLost().add(event.getEntity());
LoseLife(event.getEntity(), true);
}
@EventHandler
public void onQuit(PlayerQuitEvent event)
{
_lives.remove(event.getPlayer());
}
public ArrayList<Player> getChallengers()
{
ArrayList<Player> challengers = new ArrayList<Player>();
for (Player player : GetPlayers(true))
{
if (!UtilPlayer.isSpectator(player))
{
challengers.add(player);
}
}
return challengers;
}
public void sayChallenge(Challenge challenge)
{
for (Player player : UtilServer.getPlayers())
{
player.playSound(player.getLocation(), Sound.NOTE_PLING, 1f, 1f);
String message = C.cYellow
+ C.Bold
+ (IsAlive(player) ? challenge.getMessage(player)
: challenge.GetOrder());
UtilPlayer.message(player, message);
UtilTextMiddle.display(message, null);
}
}
@EventHandler
public void onInteract(PlayerInteractEvent event)
{
if (!_orderWaiting)
{
return;
}
event.setCancelled(true);
}
@EventHandler
public void PlayerMoveCancel(PlayerMoveEvent event)
{
if (!PrepareFreeze)
return;
if (!_orderWaiting)
return;
if (!IsLive())
return;
if (!IsAlive(event.getPlayer()))
return;
if (UtilMath.offset2d(event.getFrom(), event.getTo()) <= 0)
return;
event.getFrom().setPitch(event.getTo().getPitch());
event.getFrom().setYaw(event.getTo().getYaw());
event.setTo(event.getFrom());
}
@EventHandler
public void UpdateOrder(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
if (!IsLive())
return;
// New Order
if (_order == null)
{
if (!UtilTime.elapsed(_orderTime, 1500))
return;
for (Player player : GetPlayers(false))
{
if (_lives.containsKey(player) && _lives.get(player) > 0)
{
Manager.Clear(player);
}
}
_order = GetOrder();
if (_order == null)
{
System.out.println("No challenge suitable");
SetState(GameState.Dead);
return;
}
for (Block block : _lastOrderBlocks)
{
if (block.getState() instanceof InventoryHolder)
{
((InventoryHolder) block.getState()).getInventory().clear();
}
block.setTypeIdAndData(Material.AIR.getId(), (byte) 0, false);
}
_order.generateRoom();
ArrayList<Location> spawns = _order.getSpawns();
GetTeamList().get(0).SetSpawns(_order.getSpawns());
SpectatorSpawn = UtilWorld.averageLocation(spawns).add(0, 7, 0);
ArrayList<Location> toTeleport = new ArrayList<Location>();
for (int i = 0; i < spawns.size(); i++)
{
Location furthest = null;
double furthestDist = 0;
for (Location spawn : spawns)
{
if (toTeleport.contains(spawn))
continue;
double dist = 0;
for (Location loc : toTeleport)
{
dist += loc.distance(spawn);
}
if (furthest == null || furthestDist < dist)
{
furthest = spawn;
furthestDist = dist;
}
}
toTeleport.add(furthest);
}
int i = 0;
for (Player player : getChallengers())
{
player.teleport(toTeleport.get(i++));
if (i >= toTeleport.size())
{
i = 0;
}
}
for (Player player : GetPlayers(false))
{
if (!IsAlive(player))
{
player.teleport(SpectatorSpawn);
}
}
if (_order instanceof ChallengeSeperateRooms)
{
((ChallengeSeperateRooms) _order).assignRooms();
}
_orderTime = System.currentTimeMillis();
_orderWaiting = true;
/*
* XXX GetObjectiveSide().setDisplayName( ChatColor.WHITE +
* "§lMineWare " + C.cGreen + "§l" + "Round " + _orderCount);
*/
}
else if (_orderWaiting)
{
if (!UtilTime.elapsed(_orderTime, 1000))
return;
_orderWaiting = false;
_order.StartOrder();
// Register
UtilServer.getServer().getPluginManager()
.registerEvents(_order, Manager.getPlugin());
sayChallenge(_order);
}
// Update Order
else
{
if (_order.Finish())
{
_orderTime = System.currentTimeMillis();
for (Player player : getChallengers())
{
getArcadeManager().GetDisguise().undisguise(player);
UtilInv.Clear(player);
if (_order.hasWinner() && !_order.IsCompleted(player))
{
LoseLife(player, true);
}
}
// Deregister
HandlerList.unregisterAll(_order);
_order.EndOrder();
_lastOrderBlocks = new ArrayList<Block>(
_order.getModifiedBlocks());
// Remove blocks from top to bottom, prevents blocks popping
// off.
Collections.sort(_lastOrderBlocks, new Comparator<Block>()
{
@Override
public int compare(Block o1, Block o2)
{
return new Integer(o2.getY()).compareTo(o1.getY());
}
});
_order = null;
EndCheck();
}
else
{
// Set Level
for (Player player : UtilServer.getPlayers())
{
UtilTextTop.display(C.cYellow
+ C.Bold
+ (IsAlive(player) ? _order.getMessage(player)
: _order.GetOrder()), player);
player.setLevel(_order.GetRemainingPlaces());
player.setExp(_order.GetTimeLeftPercent());
}
}
}
}
private int GetLives(Player player)
{
if (!_lives.containsKey(player))
return 0;
return _lives.get(player);
}
public void LoseLife(Player player, boolean isDeath)
{
if (!isDeath)
{
Manager.addSpectator(player, true);
}
if (_order == null || _order.IsCompleted(player))
return;
int lives = GetLives(player);
lives -= 1;
_lives.put(player, lives);
if (lives > 0)
{
UtilPlayer
.message(player, C.cRed + C.Bold + "You failed the task!");
UtilPlayer.message(player, C.cRed + C.Bold + "You have " + lives
+ " lives left!");
player.playSound(player.getLocation(), Sound.NOTE_BASS_GUITAR, 2f,
0.5f);
}
else
{
UtilPlayer.message(player, C.cRed + C.Bold
+ "You are out of the game!");
player.playSound(player.getLocation(), Sound.EXPLODE, 2f, 1f);
Scoreboard.ResetScore(player.getName());
SetPlayerState(player, PlayerState.OUT);
if (isDeath)
{
Manager.addSpectator(player, true);
}
}
}
@Override
public int GetScoreboardScore(Player player)
{
return GetLives(player);
}
@EventHandler
public void ItemDrop(PlayerDropItemEvent event)
{
event.getItemDrop().remove();
}
}

View File

@ -0,0 +1,951 @@
package nautilus.game.arcade.game.games.mineware.challenge;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.Effect;
import org.bukkit.FireworkEffect;
import org.bukkit.FireworkEffect.Type;
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.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitRunnable;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTextBottom;
import mineplex.core.common.util.UtilTextMiddle;
import mineplex.core.common.util.UtilTime;
import mineplex.core.hologram.Hologram;
import mineplex.core.hologram.Hologram.HologramTarget;
import mineplex.core.projectile.ProjectileUser;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.condition.Condition.ConditionType;
import nautilus.game.arcade.game.games.mineware.BawkBawkBattles;
import nautilus.game.arcade.game.games.mineware.events.ChallengeEndEvent;
import nautilus.game.arcade.game.games.mineware.events.ChallengeStartEvent;
import nautilus.game.arcade.kit.ProgressingKit.CustomFirework;
import nautilus.game.arcade.world.WorldData;
/**
* <p>
* This class contains the base structure of a challenge.
* All challenges should trigger any functionality inside
* {@link #createSpawns()}, {@link #createMap()}, {@link #onStart()} and {@link #onEnd()}.
* </p>
*
* Additionally, {@link #onTimerFinish()} and {@link #onCollide(LivingEntity, Block, ProjectileUser)} can be overrided.
*/
public abstract class Challenge implements Listener
{
protected static final int TICK_MULTIPLIER = 20;
private static final int TITLE_FADE_IN_TICKS = 5;
private static final int TITLE_STAY_TICKS = 40;
private static final int TITLE_FADE_OUT_TICKS = 5;
private static final int BORDER_MIN_X = -100;
private static final int BORDER_MAX_X = 100;
private static final int BORDER_MIN_Y = 0;
private static final int BORDER_MAX_Y = 256;
private static final int BORDER_MIN_Z = -100;
private static final int BORDER_MAX_Z = 100;
private static final int COMPLETE_COUNT_DIVIDER = 2;
private static final int WINNER_ADD_CRITERIA = 3; // players
private static final int CHICKEN_ATTACK_CRITERIA = 2; // players
private static final int CHALLENGE_CLOAK_DURATION = 7777;
private static final int COMPLETION_GEMS = 3;
private static final int STARTING_SOON_MESSAGE_CRITERIA = 2; // players
private static final double BLOCK_CENTER_ADD = 0.5;
private static final int CRUMBLE_CHANCE = 4;
private static final int PLAYER_COUNT_FOR_GAME_END = 1;
private static final int COMPLETION_TITLE_STAY_TICKS = 30;
private static final float COMPLETION_SOUND_VOLUME = 2.0F;
private static final float COMPLETION_SOUND_PITCH = 1.0F;
private static final float LOST_SOUND_VOLUME = 2.0F;
private static final float LOST_SOUND_PITCH = 1.0F;
protected static final int INVENTORY_HOTBAR_SLOTS = 8;
private static final int BLOCK_BREAK_PARTICLE_COUNT = 10;
private static final int GRASS_SPAWN_CHANCE = 4;
private static final int FLOWER_SPAWN_CHANCE = 8;
private static final int FLOWER_DATA_RANGE = 7;
private static final int DOUBLE_PLANT_CHANCE = 3;
private static final int DOUBLE_PLANT_DATA_RANGE = 5;
private static final byte DOUBLE_PLANT_PART_DATA = 8;
private static final int DISPLAY_COUNT_EXPIRE_AFTER = 1000;
private static final double DISPLAY_COUNT_ELEVATION_RATE = 0.05;
private static final int DEFAULT_ARENA_SIZE = 8;
private static final int ARENA_SIZE_DIVIDER = 2;
private static final int ARENA_SIZE_LIMIT = 40;
protected final BawkBawkBattles Host;
protected final ChallengeSettings Settings;
protected final ChallengeData Data;
private ChallengeType _type;
private String _name;
private String[] _description;
public Challenge(BawkBawkBattles host, ChallengeType type, String name, String... description)
{
Host = host;
_type = type;
_name = name;
_description = description;
Settings = new ChallengeSettings(this);
Data = new ChallengeData();
}
public void markSpawnLocations()
{
for (Location spawn : Data.getDefinedSpawns())
{
Block markedBlock = spawn.getBlock().getRelative(BlockFace.DOWN);
markedBlock.setType(Material.EMERALD_BLOCK);
addBlock(markedBlock);
}
}
/**
* The list of spawn locations where players will be teleported.
*
* @return ArrayList<Location>
*/
public abstract ArrayList<Location> createSpawns();
/**
* The list of actions to perform in order for the map to be created.
*/
public abstract void createMap();
/**
* The list of actions to perform once the challenge is started.
*/
public void onStart()
{
}
/**
* The list of actions to perform after the challenge has ended.
*/
public void onEnd()
{
}
public void spawn(boolean firstRun)
{
if (firstRun)
{
ArrayList<Player> players = Host.GetPlayers(false);
for (int i = 0; i < players.size(); i++)
{
Player player = players.get(i);
new BukkitRunnable()
{
@Override
public void run()
{
Host.getPlayerTeam().SpawnTeleport(player);
}
}.runTaskLater(Host.Manager.getPlugin(), i);
}
}
else
{
Host.getPlayerTeam().SpawnTeleport(false);
}
}
public void start()
{
setBorder(BORDER_MIN_X, BORDER_MAX_X, BORDER_MIN_Y, BORDER_MAX_Y, BORDER_MIN_Z, BORDER_MAX_Z);
Settings.setStartTime(System.currentTimeMillis());
Settings.setMaxCompletedCount((int) Math.ceil(getPlayersAlive().size() / COMPLETE_COUNT_DIVIDER));
if (Settings.isInventoryLocked())
{
setLockedInventorySlot();
}
onStart();
callStartEvent();
}
private void setLockedInventorySlot()
{
for (Player player : getPlayersAlive())
{
player.getInventory().setHeldItemSlot(Settings.getLockedSlot());
}
}
private void callStartEvent()
{
Bukkit.getServer().getPluginManager().callEvent(new ChallengeStartEvent(this));
Host.Manager.getPluginManager().registerEvents(this, Host.Manager.getPlugin());
}
public boolean canFinish()
{
ArrayList<Player> players = getPlayersAlive();
int alive = getPlayersIn(true).size();
int completed = Data.getCompletedPlayers().size();
int lost = Data.getLostPlayers().size();
boolean maxTimeReached = UtilTime.elapsed(Settings.getStartTime(), Settings.getDuration());
if (maxTimeReached)
{
if (!Settings.shouldHideTimerRanOutMessage())
{
UtilServer.broadcast(F.main("Game", "Challenge timer has ran out."));
}
onTimerFinish();
return true;
}
else if (alive <= completed)
{
return true;
}
else if (_type == ChallengeType.LastStanding)
{
if (alive <= Settings.getMaxCompletedCount())
{
for (Player player : players)
{
setCompleted(player);
}
return true;
}
else if (lost > alive)
{
return true;
}
}
else if (_type == ChallengeType.FirstComplete && completed >= Settings.getMaxCompletedCount())
{
return true;
}
return maxTimeReached;
}
public void end()
{
handleRemainingPlayers();
callEndEvent();
if (Data.hasInvisiblePlayers())
{
removeCloakedPlayers();
}
onEnd();
Data.reset();
}
private void removeCloakedPlayers()
{
for (Player player : Data.getInvisiblePlayers())
{
Host.Manager.GetCondition().EndCondition(player, ConditionType.CLOAK, "Challenge Ended");
}
}
private void callEndEvent()
{
Host.Manager.getPluginManager().callEvent(new ChallengeEndEvent(this));
HandlerList.unregisterAll(this);
}
@EventHandler(priority = EventPriority.MONITOR)
public void death(PlayerDeathEvent event)
{
if (!Host.IsLive() || Host.getChickenTeam().HasPlayer(event.getEntity()))
return;
Player player = event.getEntity();
Location death = player.getLocation().clone();
Data.addLostPlayer(player);
Host.getDeathEffect().playDeath(player, death);
handleDeath(player);
}
private void handleDeath(Player player)
{
int alive = Host.getPlayersWithRemainingLives();
int lives = loseLife(player);
if (lives <= 0 && alive <= WINNER_ADD_CRITERIA)
{
Host.getWinners().add(player);
}
if (lives <= 0 && alive > CHICKEN_ATTACK_CRITERIA)
{
Host.GetScoreboard().ResetScore(player.getName());
Host.getChickenAttack().start(player);
}
else
{
handleFailure(player);
}
}
private int loseLife(Player player)
{
int lives = Host.lives(player);
lives--;
if (lives >= 0)
{
Host.setLives(player, lives);
}
return lives;
}
private void handleFailure(Player player)
{
UtilPlayer.message(player, F.main("Game", C.cRed + "You failed to complete the task."));
Host.showLivesLeft(player);
Host.Manager.addSpectator(player, true);
Host.Manager.GetCondition().Factory().Cloak("Challenge Death", player, player, CHALLENGE_CLOAK_DURATION, true, true);
}
private void handleRemainingPlayers()
{
for (Player player : getPlayersAlive())
{
if (Data.hasAnyoneCompleted() && !Data.isDone(player))
{
int lives = Host.lives(player);
if (lives > 1)
{
setLost(player);
}
else
{
handleDeath(player);
}
}
addGems(player);
}
}
private void addGems(Player player)
{
if (Data.isCompleted(player))
{
Host.AddGems(player, COMPLETION_GEMS, "Completed Challenges", true, true);
}
}
@EventHandler
public void startingSoon(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC || !Host.IsLive() || Host.getPlayersWithRemainingLives() <= STARTING_SOON_MESSAGE_CRITERIA)
return;
HashSet<Player> players = new HashSet<Player>();
players.addAll(Data.getCompletedPlayers());
players.addAll(Data.getLostPlayers());
for (Player player : players)
{
if (!Host.getChickenTeam().HasPlayer(player) && Host.lives(player) > 0)
{
UtilTextBottom.display(C.Bold + "Next challenge will begin shortly.", player);
}
}
}
@EventHandler
public void lockInventory(PlayerItemHeldEvent event)
{
if (!isChallengeValid())
return;
Player player = event.getPlayer();
if (!isPlayerValid(player))
return;
if (Settings.isInventoryLocked())
event.setCancelled(true);
}
@SuppressWarnings("deprecation")
@EventHandler
public void crumble(UpdateEvent event)
{
if (event.getType() != UpdateType.FASTEST || !Host.IsLive() || !Settings.canCrumble() || !Host.getSettings().isCrumbling())
return;
Block qualifiedBlock = null;
double furthestDistance = 0;
if (Data.getModifiedBlocks().isEmpty())
{
Host.getSettings().setCrumbling(false);
return;
}
for (Block currentBlock : Data.getModifiedBlocks())
{
double theBlocksDistance = UtilMath.offset2d(Host.GetSpectatorLocation(), currentBlock.getLocation().add(BLOCK_CENTER_ADD, BLOCK_CENTER_ADD, BLOCK_CENTER_ADD));
if (qualifiedBlock == null || furthestDistance < theBlocksDistance)
{
qualifiedBlock = currentBlock;
furthestDistance = theBlocksDistance;
}
}
while (!qualifiedBlock.getRelative(BlockFace.DOWN).isEmpty())
{
qualifiedBlock = qualifiedBlock.getRelative(BlockFace.DOWN);
}
Data.removeModifiedBlock(qualifiedBlock);
if (UtilMath.r(CRUMBLE_CHANCE) == 0)
{
qualifiedBlock.getWorld().spawnFallingBlock(qualifiedBlock.getLocation().add(BLOCK_CENTER_ADD, BLOCK_CENTER_ADD, BLOCK_CENTER_ADD), qualifiedBlock.getType(), qualifiedBlock.getData());
}
resetBlock(qualifiedBlock);
}
@EventHandler
public void quit(PlayerQuitEvent event)
{
if (!Host.IsLive())
return;
Data.removePlayer(event.getPlayer());
}
protected void setCompleted(Player player, boolean cloak)
{
if (Data.isDone(player))
return;
if (shouldShowEffects()) // Check if the game is not about to end.
{
if (cloak)
{
cloak(player, true);
}
CustomFirework.spawn(
player.getLocation().add(0, 1, 0),
FireworkEffect.builder().with(Type.BALL_LARGE).withColor(Color.GREEN).build(),
player);
alert(player, C.cGreen + "You have completed the challenge!", COMPLETION_TITLE_STAY_TICKS);
player.playSound(player.getLocation(), Sound.LEVEL_UP, COMPLETION_SOUND_VOLUME, COMPLETION_SOUND_PITCH);
}
Data.addCompletedPlayer(player);
Host.Manager.GetDisguise().undisguise(player);
UtilPlayer.clearPotionEffects(player);
UtilInv.Clear(player);
}
private boolean shouldShowEffects()
{
if (Host.getPlayersWithRemainingLives() == PLAYER_COUNT_FOR_GAME_END)
{
int playerOneLives = Host.lives(getPlayersAlive().get(0));
int playerTwoLives = Host.lives(getPlayersAlive().get(1));
boolean playerOneCompleted = Data.isDone(getPlayersAlive().get(0));
boolean playerTwoCompleted = Data.isDone(getPlayersAlive().get(1));
if (!playerOneCompleted && !playerTwoCompleted && (playerOneLives == 1 || playerTwoLives == 2))
{
return false;
}
}
return true;
}
protected void setCompleted(Player player)
{
setCompleted(player, false);
}
protected void setLost(Player player, boolean cloak)
{
if (Data.isDone(player))
return;
Data.addLostPlayer(player);
loseLife(player);
if (cloak)
{
cloak(player, false);
}
UtilPlayer.message(player, F.main("Game", C.cRed + "You failed to complete the task."));
Host.showLivesLeft(player);
player.playSound(player.getLocation(), Sound.NOTE_BASS, LOST_SOUND_VOLUME, LOST_SOUND_PITCH);
Host.Manager.GetDisguise().undisguise(player);
UtilPlayer.clearPotionEffects(player);
UtilInv.Clear(player);
}
protected void setLost(Player player)
{
setLost(player, false);
}
private void cloak(Player player, boolean completed)
{
Data.addInvisiblePlayer(player);
String reason = "Lost";
if (completed)
{
reason = "Completed";
}
Host.Manager.GetCondition().Factory().Cloak(reason, player, player, CHALLENGE_CLOAK_DURATION, true, false);
}
protected void alert(Player player, String message)
{
alert(player, message, TITLE_STAY_TICKS);
}
protected void alert(Player player, String message, int stayTicks)
{
UtilTextMiddle.display(null, message, TITLE_FADE_IN_TICKS, stayTicks, TITLE_FADE_OUT_TICKS, player);
}
@SuppressWarnings("deprecation")
public void setBlock(Block block, Material type, byte data)
{
UtilBlock.setQuick(block.getWorld(), block.getX(), block.getY(), block.getZ(), type.getId(), data);
}
public void setBlock(Block block, Material type)
{
setBlock(block, type, (byte) 0);
}
public void setData(Block block, byte data)
{
setBlock(block, block.getType(), data);
}
public void resetBlock(Block block)
{
setBlock(block, Material.AIR, (byte) 0);
}
protected void addBlock(Block... blocks)
{
for (Block block : blocks)
{
if (!block.isEmpty())
{
Data.addModifiedBlock(block);
}
}
}
protected void addItem(ItemStack... items)
{
for (Player player : getPlayersAlive())
{
for (ItemStack item : items)
{
UtilInv.insert(player, item);
}
}
}
protected void setItem(int slot, ItemStack item)
{
for (Player player : getPlayersAlive())
{
player.getInventory().setItem(slot, item);
}
}
protected void fillItem(ItemStack item)
{
for (Player player : getPlayersAlive())
{
for (int i = 0; i <= INVENTORY_HOTBAR_SLOTS; i++)
{
player.getInventory().setItem(i, item);
}
}
}
protected void removeItem(Material type, byte data)
{
for (Player player : getPlayersAlive())
{
UtilInv.removeAll(player, type, data);
}
}
@SuppressWarnings("deprecation")
protected void blockBreakEffect(Block block, boolean resetBlock)
{
UtilParticle.PlayParticle(ParticleType.BLOCK_DUST.getParticle(block.getType(), block.getData()), block.getLocation(), 0, 0, 0, 0, BLOCK_BREAK_PARTICLE_COUNT, ViewDist.NORMAL, UtilServer.getPlayers());
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getTypeId());
if (resetBlock)
{
resetBlock(block);
}
}
protected void addEffect(PotionEffectType type, int duration, int amplifier)
{
for (Player player : getPlayersAlive())
{
player.addPotionEffect(new PotionEffect(type, duration, amplifier));
}
}
protected void addEffect(PotionEffectType type, int amplifier)
{
addEffect(type, Integer.MAX_VALUE, amplifier);
}
protected void removeEffect(PotionEffectType type)
{
for (Player player : getPlayersAlive())
{
player.removePotionEffect(type);
}
}
protected void remove(EntityType type)
{
for (Entity entity : Host.WorldData.World.getEntities())
{
if (entity.getType() == type && !Host.getDeathEffect().isDeathEffectItem(entity))
{
entity.remove();
}
}
}
protected Block generateGrass(Block block)
{
return generateGrass(block, false);
}
protected Block generateGrass(Block block, boolean bushes)
{
if (UtilMath.r(GRASS_SPAWN_CHANCE) == 0)
{
if (UtilMath.r(FLOWER_SPAWN_CHANCE) == 0)
{
makeFlower(block);
}
else
{
makeGrass(block, bushes);
}
}
return block;
}
private void makeFlower(Block block)
{
Material flower = Material.YELLOW_FLOWER;
byte data = 0;
if (UtilMath.random.nextBoolean())
{
flower = Material.RED_ROSE;
if (UtilMath.random.nextBoolean())
{
data = (byte) (UtilMath.r(FLOWER_DATA_RANGE) + 1);
}
}
setBlock(block, flower, data);
}
@SuppressWarnings("deprecation")
private void makeGrass(Block block, boolean bushes)
{
if (bushes && UtilMath.r(DOUBLE_PLANT_CHANCE) == 0)
{
Block above = block.getRelative(BlockFace.UP);
byte plantData = (byte) UtilMath.r(DOUBLE_PLANT_DATA_RANGE);
setBlock(block, Material.DOUBLE_PLANT, plantData);
setBlock(above, Material.DOUBLE_PLANT, DOUBLE_PLANT_PART_DATA);
addBlock(above);
}
else
{
block.setType(Material.LONG_GRASS);
block.setData((byte) 1);
}
}
public boolean isChallengeValid()
{
return Host.IsLive() && Host.getSettings().isChallengeStarted();
}
protected boolean isPlayerValid(Player player)
{
return getPlayersAlive().contains(player) && Host.IsAlive(player) && !Data.isDone(player);
}
public void setBorder(int minX, int maxX, int minY, int maxY, int minZ, int maxZ)
{
WorldData data = Host.WorldData;
data.MinX = minX;
data.MaxX = (int) (maxX + Settings.getMapCenter().getX());
data.MinY = minY;
data.MaxY = (int) (maxY + Settings.getMapCenter().getY());
data.MinZ = minZ;
data.MaxZ = (int) (maxZ + Settings.getMapCenter().getZ());
}
protected void displayCount(Player player, Location loc, String text)
{
Hologram hologram = createHologram(player, loc, text);
long expiry = System.currentTimeMillis() + DISPLAY_COUNT_EXPIRE_AFTER;
new BukkitRunnable()
{
public void run()
{
if (!Host.IsLive() || expiry < System.currentTimeMillis())
{
hologram.stop();
cancel();
}
else
{
elevateHologram(hologram);
}
}
}.runTaskTimer(Host.Manager.getPlugin(), 0L, 1L);
}
private Hologram createHologram(Player player, Location loc, String text)
{
Hologram hologram = new Hologram(Host.Manager.getHologramManager(), loc, text);
hologram.setHologramTarget(HologramTarget.WHITELIST);
hologram.addPlayer(player);
hologram.start();
return hologram;
}
private void elevateHologram(Hologram hologram)
{
hologram.setLocation(hologram.getLocation().add(0, DISPLAY_COUNT_ELEVATION_RATE, 0));
}
public boolean isInsideMap(Player player)
{
return Host.isInsideMap(player.getLocation());
}
private static final int TIME_LEFT_DIVIDER = 1000;
public int getTimeLeft()
{
return (int) ((Settings.getDuration() - (System.currentTimeMillis() - Settings.getStartTime())) / TIME_LEFT_DIVIDER);
}
public ArrayList<Player> getPlayersAlive()
{
return Host.getPlayersAlive();
}
public ArrayList<Player> getPlayersIn(boolean ignoreCompleted)
{
ArrayList<Player> list = new ArrayList<Player>();
for (Player player : getPlayersAlive())
{
if (Data.isLost(player) || (ignoreCompleted && Data.isCompleted(player)))
{
continue;
}
list.add(player);
}
return list;
}
public float getTimeLeftPercent()
{
float a = (float) (Settings.getDuration() - (System.currentTimeMillis() - Settings.getStartTime()));
float b = (float) (Settings.getDuration());
return a / b;
}
public final int getRemainingPlaces()
{
if (_type == ChallengeType.FirstComplete)
return Settings.getMaxCompletedCount() - Data.getCompletedPlayers().size();
else if (_type == ChallengeType.LastStanding)
return getPlayersAlive().size() - Settings.getMaxCompletedCount();
return 0;
}
public int getArenaSize()
{
return getArenaSize(DEFAULT_ARENA_SIZE);
}
public int getArenaSize(int minBlocks)
{
int size = (int) (minBlocks + Math.ceil(Host.getPlayersWithRemainingLives() / ARENA_SIZE_DIVIDER));
return size > ARENA_SIZE_LIMIT ? ARENA_SIZE_LIMIT : size;
}
public BawkBawkBattles getHost()
{
return Host;
}
public ChallengeType getType()
{
return _type;
}
public String getName()
{
return _name;
}
public String[] getDescription()
{
return _description;
}
public Location getCenter()
{
return Settings.getMapCenter();
}
public ChallengeSettings getSettings()
{
return Settings;
}
public ChallengeData getData()
{
return Data;
}
/**
* tadahtech's circle method (temporarily used instead of UtilShapes.getCircle)
*/
protected List<Location> circle(Location loc, Integer r, Integer h, Boolean hollow, Boolean sphere, int plusY)
{
List<Location> circleblocks = new ArrayList<>();
int cx = loc.getBlockX();
int cy = loc.getBlockY();
int cz = loc.getBlockZ();
for (int x = cx - r; x <= cx + r; x++)
{
for (int z = cz - r; z <= cz + r; z++)
{
for (int y = (sphere ? cy - r : cy); y < (sphere ? cy + r : cy + h); y++)
{
double dist = (cx - x) * (cx - x) + (cz - z) * (cz - z) + (sphere ? (cy - y) * (cy - y) : 0);
if (dist < r * r && !(hollow && dist < (r - 1) * (r - 1)))
{
Location l = new Location(loc.getWorld(), x, y + plusY, z);
circleblocks.add(l);
}
}
}
}
return circleblocks;
}
/**
* This method is called when the challenge timer runs out. <br>
* Used for overriding purposes only.
*/
public void onTimerFinish()
{
}
public void onCollide(LivingEntity target, Block block, ProjectileUser data)
{
}
}

View File

@ -0,0 +1,169 @@
package nautilus.game.arcade.game.games.mineware.challenge;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import mineplex.core.common.util.UtilAlg;
/**
* This class contains a list of collection fields to store challenge data.
*/
public class ChallengeData
{
private List<Location> _spawns = new ArrayList<>();
private Set<Player> _invisible = new HashSet<>();
private Set<Block> _modifiedBlocks = new LinkedHashSet<>();
private Set<Player> _completed = new HashSet<>();
private Set<Player> _lost = new HashSet<>();
public void reset()
{
_spawns.clear();
_invisible.clear();
_modifiedBlocks.clear();
_completed.clear();
_lost.clear();
}
public void setSpawns(ArrayList<Location> spawns)
{
_spawns = spawns;
}
public List<Location> getDefinedSpawns()
{
return _spawns;
}
public boolean isSpawnLocation(Location location)
{
for (Location spawn : _spawns)
{
if ((int) spawn.getX() == (int) location.getX() && (int) spawn.getY() == (int) location.getY() && (int) spawn.getZ() == (int) location.getZ())
{
return true;
}
}
return false;
}
public boolean isNearSpawnLocation(Location location)
{
for (Location spawn : _spawns)
{
Block spawnBlock = spawn.getBlock();
Block[] near = {
spawnBlock.getRelative(BlockFace.NORTH),
spawnBlock.getRelative(BlockFace.EAST),
spawnBlock.getRelative(BlockFace.SOUTH),
spawnBlock.getRelative(BlockFace.WEST),
spawnBlock.getRelative(BlockFace.NORTH_EAST),
spawnBlock.getRelative(BlockFace.NORTH_WEST),
spawnBlock.getRelative(BlockFace.SOUTH_EAST),
spawnBlock.getRelative(BlockFace.SOUTH_WEST)
};
for (Block block : near)
{
if (UtilAlg.isSimilar(block.getLocation(), location))
{
return true;
}
}
}
return false;
}
public void removePlayer(Player player)
{
_lost.remove(player);
_completed.remove(player);
_invisible.remove(player);
}
public boolean isCompleted(Player player)
{
return _completed.contains(player);
}
public boolean isDone(Player player)
{
return _completed.contains(player) || _lost.contains(player);
}
public boolean isLost(Player player)
{
return _lost.contains(player);
}
public void addInvisiblePlayer(Player player)
{
_invisible.add(player);
}
public Set<Player> getInvisiblePlayers()
{
return _invisible;
}
public boolean hasInvisiblePlayers()
{
return !_invisible.isEmpty();
}
public void addModifiedBlock(Block block)
{
_modifiedBlocks.add(block);
}
public boolean isModifiedBlock(Block block)
{
return _modifiedBlocks.contains(block);
}
public void removeModifiedBlock(Block block)
{
_modifiedBlocks.remove(block);
}
public Set<Block> getModifiedBlocks()
{
return _modifiedBlocks;
}
public void addCompletedPlayer(Player player)
{
_completed.add(player);
}
public Set<Player> getCompletedPlayers()
{
return _completed;
}
public boolean hasAnyoneCompleted()
{
return !_completed.isEmpty();
}
public void addLostPlayer(Player player)
{
_lost.add(player);
}
public Set<Player> getLostPlayers()
{
return _lost;
}
}

View File

@ -0,0 +1,88 @@
package nautilus.game.arcade.game.games.mineware.challenge;
import java.util.ArrayList;
import java.util.List;
import mineplex.core.common.util.UtilMath;
public class ChallengeList
{
private List<Challenge> _challenges = new ArrayList<>();
private List<Challenge> _played = new ArrayList<>();
private Challenge _restricted;
public Challenge random()
{
if (_restricted == null)
{
if (_played.size() == _challenges.size())
{
_played.clear();
return UtilMath.randomElement(_challenges);
}
else
{
Challenge challenge = UtilMath.randomElement(_challenges);
while (_played.contains(challenge))
{
challenge = UtilMath.randomElement(_challenges);
}
return challenge;
}
}
else
{
return _restricted;
}
}
public void add(Challenge... challenges)
{
for (Challenge challenge : challenges)
{
_challenges.add(challenge);
}
}
public void addPlayed(Challenge challenge)
{
_played.add(challenge);
}
public boolean restrict(String name)
{
for (Challenge challenge : _challenges)
{
if (challenge.getName().contains(name))
{
System.out.println("Restricted: " + challenge.getName());
_restricted = challenge;
return true;
}
}
return false;
}
public void resetPlayed()
{
_played.clear();
}
public void unrestrict()
{
_restricted = null;
}
public int size()
{
return _challenges.size();
}
public int played()
{
return _played.size();
}
}

View File

@ -0,0 +1,151 @@
package nautilus.game.arcade.game.games.mineware.challenge;
import org.bukkit.Location;
/**
* This class contains a list of fields that are used as settings for the challenge class.
*/
public class ChallengeSettings
{
private Challenge _challenge;
private int _minPlayers = 2;
private int _maxPlayers = 250;
private int _maxCompletedCount;
private long _startTime;
private long _duration = 60000;
private boolean _useMapHeight;
private boolean _lockInventory;
private int _lockedSlot = 0;
private boolean _teamBased;
private boolean _canCrumble;
private boolean _hideTimerRanOutMessage;
private double _centerX;
private double _centerY;
private double _centerZ;
public ChallengeSettings(Challenge challenge)
{
_challenge = challenge;
}
public Challenge getChallenge()
{
return _challenge;
}
public void setMinPlayers(int minPlayers)
{
_minPlayers = minPlayers;
}
public int getMinPlayers()
{
return _minPlayers;
}
public void setMaxPlayers(int maxPlayers)
{
_maxPlayers = maxPlayers;
}
public int getMaxPlayers()
{
return _maxPlayers;
}
public Location getMapCenter()
{
return new Location(_challenge.getHost().WorldData.World, _centerX, _centerY, _centerZ);
}
public void setMaxCompletedCount(int maxCompletedCount)
{
_maxCompletedCount = maxCompletedCount;
}
public int getMaxCompletedCount()
{
return _maxCompletedCount;
}
public void setStartTime(long startTime)
{
_startTime = startTime;
}
public long getStartTime()
{
return _startTime;
}
public void setDuration(long duration)
{
_duration = duration;
}
public long getDuration()
{
return _duration;
}
public void setUseMapHeight()
{
_useMapHeight = true;
_centerX = -1;
_centerY = 62;
_centerZ = 10;
}
public boolean canUseMapHeight()
{
return _useMapHeight;
}
public void setLockInventory(int lockedSlot)
{
_lockInventory = true;
_lockedSlot = lockedSlot;
}
public boolean isInventoryLocked()
{
return _lockInventory;
}
public int getLockedSlot()
{
return _lockedSlot;
}
public void setTeamBased()
{
_teamBased = true;
}
public boolean isTeamBased()
{
return _teamBased;
}
public void setCanCruble()
{
_canCrumble = true;
}
public boolean canCrumble()
{
return _canCrumble;
}
public void hideTimerRanOutMessage()
{
_hideTimerRanOutMessage = true;
}
public boolean shouldHideTimerRanOutMessage()
{
return _hideTimerRanOutMessage;
}
}

View File

@ -0,0 +1,57 @@
package nautilus.game.arcade.game.games.mineware.challenge;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import org.bukkit.entity.Player;
/**
* This class holds a list of players under a common group name, that represents a team.
*/
public class ChallengeTeam
{
private String _name;
private Set<Player> _players = new LinkedHashSet<>();
public ChallengeTeam(String name)
{
_name = name;
}
public String getName()
{
return _name;
}
public void add(Player player)
{
_players.add(player);
}
public void remove(Player player)
{
_players.remove(player);
}
public void reset()
{
_players.clear();
}
public boolean isMember(Player player)
{
return _players.contains(player);
}
public int getSize()
{
return _players.size();
}
public List<Player> getPlayers()
{
return new ArrayList<>(_players);
}
}

View File

@ -0,0 +1,23 @@
package nautilus.game.arcade.game.games.mineware.challenge;
/**
* The ending condition of a challenge.
*/
public enum ChallengeType
{
LastStanding("Last Standing"),
FirstComplete("First Complete");
private String _name;
ChallengeType(String name)
{
_name = name;
}
@Override
public String toString()
{
return _name;
}
}

View File

@ -0,0 +1,11 @@
package nautilus.game.arcade.game.games.mineware.challenge;
import org.bukkit.entity.Player;
/**
* Tracks boolean related data used for statistic trackers.
*/
public interface LogicTracker
{
public boolean hasData(Player player);
}

View File

@ -0,0 +1,13 @@
package nautilus.game.arcade.game.games.mineware.challenge;
import org.bukkit.entity.Player;
/**
* Tracks number related data used for statistic trackers.
*/
public interface NumberTracker
{
public Number getData(Player player);
public boolean hasData(Player player);
}

View File

@ -0,0 +1,300 @@
package nautilus.game.arcade.game.games.mineware.challenge;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.scheduler.BukkitRunnable;
import mineplex.core.common.util.UtilMath;
import mineplex.core.projectile.ProjectileUser;
import nautilus.game.arcade.game.games.mineware.BawkBawkBattles;
/**
* <p>
* This class contains the base structure of a team challenge.
* All challenges should trigger any functionality inside
* {@link #createSpawns()}, {@link #createMap()}, {@link #onStart()} and {@link #onEnd()}.
* </p>
*
* Additionally, {@link #onTimerFinish()} and {@link #onCollide(LivingEntity, Block, ProjectileUser)} can be overrided.
*/
public abstract class TeamChallenge extends Challenge
{
private static final int TEAM_EVEN_NUMBER = 2;
private static final int TEAM_SEPERATOR = 2;
private ChallengeTeam _firstTeam;
private ChallengeTeam _secondTeam;
private boolean _teamSpawn;
private byte _firstTeamSpawnBlockData;
private byte _secondTeamSpawnBlockData;
public TeamChallenge(BawkBawkBattles host, ChallengeType type, String firstTeam, String secondTeam, boolean teamSpawn, byte firstTeamSpawnBlockData, byte secondTeamSpawnBlockData, String name, String... description)
{
super(host, type, name, description);
_firstTeam = new ChallengeTeam(firstTeam);
_secondTeam = new ChallengeTeam(secondTeam);
_teamSpawn = teamSpawn;
_firstTeamSpawnBlockData = firstTeamSpawnBlockData;
_secondTeamSpawnBlockData = secondTeamSpawnBlockData;
}
public TeamChallenge(BawkBawkBattles host, ChallengeType type, String firstTeam, String secondTeam, String name, String... description)
{
this(host, type, firstTeam, secondTeam, false, (byte) 0, (byte) 0, name, description);
}
/*
* Called automatically only when _teamSpawn is true.
*/
@SuppressWarnings("deprecation")
@Override
public void spawn(boolean firstRun)
{
if (_teamSpawn)
{
autoSelectTeams();
List<Player> firstTeam = _firstTeam.getPlayers();
List<Player> secondTeam = _secondTeam.getPlayers();
int firstTeamIndex = 0;
int secondTeamIndex = 0;
int players = Host.getPlayersWithRemainingLives();
int teleported = 0;
List<Location> randomSpawns = Data.getDefinedSpawns();
Collections.shuffle(randomSpawns);
while (teleported < players)
{
for (Location spawn : randomSpawns)
{
Block block = spawn.getBlock().getRelative(BlockFace.DOWN);
if (block.getData() == _firstTeamSpawnBlockData && firstTeamIndex < firstTeam.size())
{
Player player = firstTeam.get(firstTeamIndex);
if (firstRun)
{
teleportWithDelay(player, spawn, teleported);
}
else
{
player.teleport(spawn);
}
firstTeamIndex++;
teleported++;
}
else if (block.getData() == _secondTeamSpawnBlockData && secondTeamIndex < secondTeam.size())
{
Player player = secondTeam.get(secondTeamIndex);
if (firstRun)
{
teleportWithDelay(player, spawn, teleported);
}
else
{
player.teleport(spawn);
}
secondTeamIndex++;
teleported++;
}
}
}
}
else
{
super.spawn(firstRun);
}
}
private void teleportWithDelay(Player player, final Location spawn, int teleported)
{
new BukkitRunnable()
{
@Override
public void run()
{
player.teleport(spawn);
}
}.runTaskLater(Host.Manager.getPlugin(), teleported);
}
/*
* Called automatically only when _teamSpawn is true.
*/
protected void autoSelectTeams()
{
ArrayList<Player> players = Host.GetPlayers(false);
Collections.shuffle(players);
int size = 0;
if (players.size() % TEAM_EVEN_NUMBER == 0)
{
for (Player player : players)
{
if (size < players.size() / TEAM_SEPERATOR)
{
_firstTeam.add(player);
}
else
{
_secondTeam.add(player);
}
size++;
}
}
else
{
for (int i = 0; i < players.size(); i++)
{
Player player = players.get(i);
if (i == players.size() - 1)
{
if (UtilMath.random.nextBoolean())
{
_firstTeam.add(player);
}
else
{
_secondTeam.add(player);
}
}
else
{
if (size < (int) players.size() / TEAM_SEPERATOR)
{
_firstTeam.add(player);
}
else
{
_secondTeam.add(player);
}
}
size++;
}
}
}
@Override
public void end()
{
_firstTeam.reset();
_secondTeam.reset();
super.end();
}
@Override
public boolean canFinish()
{
int firstTeamAlive = 0;
for (Player firstTeamPlayer : _firstTeam.getPlayers())
{
if (isPlayerValid(firstTeamPlayer))
{
firstTeamAlive++;
}
}
int secondTeamAlive = 0;
for (Player secondTeamPlayer : _secondTeam.getPlayers())
{
if (isPlayerValid(secondTeamPlayer))
{
secondTeamAlive++;
}
}
boolean firstTeamDominant = firstTeamAlive > 0 && secondTeamAlive == 0;
boolean secondTeamDominant = secondTeamAlive > 0 && firstTeamAlive == 0;
if (firstTeamDominant)
{
for (Player firstTeamPlayer : _firstTeam.getPlayers())
{
setCompleted(firstTeamPlayer);
}
return true;
}
else if (secondTeamDominant)
{
for (Player secondTeamPlayer : _secondTeam.getPlayers())
{
setCompleted(secondTeamPlayer);
}
return true;
}
return super.canFinish();
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event)
{
if (!isChallengeValid())
return;
Player player = event.getPlayer();
ChallengeTeam team = getTeam(player);
if (team != null)
{
team.remove(player);
}
}
public ChallengeTeam getTeam(Player player)
{
if (_firstTeam.isMember(player))
{
return _firstTeam;
}
else
{
return _secondTeam;
}
}
public boolean areOnSameTeam(Player player1, Player player2)
{
return (_firstTeam.isMember(player1) && _firstTeam.isMember(player2)) || (_secondTeam.isMember(player1) && _secondTeam.isMember(player2));
}
public ChallengeTeam getFirstTeam()
{
return _firstTeam;
}
public ChallengeTeam getSecondTeam()
{
return _secondTeam;
}
public boolean shouldTeamSpawn()
{
return _teamSpawn;
}
}

View File

@ -1,14 +1,21 @@
package nautilus.game.arcade.game.games.mineware;
package nautilus.game.arcade.game.games.mineware.challenge.other;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map.Entry;
import mineplex.core.common.util.UtilPlayer;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import mineplex.core.common.util.UtilPlayer;
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;
/**
* Not used.
* @deprecated
*/
public abstract class ChallengeSeperateRooms extends Challenge
{
private HashMap<String, Integer[]> _borders = new HashMap<String, Integer[]>();
@ -16,7 +23,7 @@ public abstract class ChallengeSeperateRooms extends Challenge
private HashMap<String, Location> _rooms = new HashMap<String, Location>();
private double _borderX, _borderZ;
public ChallengeSeperateRooms(MineWare host, ChallengeType challengeType, String challengeName)
public ChallengeSeperateRooms(BawkBawkBattles host, ChallengeType challengeType, String challengeName)
{
super(host, challengeType, challengeName);
}
@ -29,7 +36,7 @@ public abstract class ChallengeSeperateRooms extends Challenge
public void assignRooms()
{
for (Player player : getChallengers())
for (Player player : getPlayersAlive())
{
for (Entry<Location, Entry<Integer[], Location>> entry : _spawns.entrySet())
{
@ -44,9 +51,10 @@ public abstract class ChallengeSeperateRooms extends Challenge
}
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public final void generateRoom()
{
int size = getChallengers().size();
int size = getPlayersAlive().size();
int x = 1;
int z = 1;
@ -101,9 +109,9 @@ public abstract class ChallengeSeperateRooms extends Challenge
}
@Override
public void StartOrder()
public void start()
{
super.StartOrder();
super.start();
setBorder((int) -Math.ceil(_borderX), (int) Math.ceil(_borderX), 0, 256, (int) -Math.ceil(_borderZ),
(int) Math.ceil(_borderZ));
@ -127,7 +135,7 @@ public abstract class ChallengeSeperateRooms extends Challenge
}
@Override
public ArrayList<Location> getSpawns()
public ArrayList<Location> createSpawns()
{
return new ArrayList<Location>(_spawns.keySet());
}

View File

@ -0,0 +1,122 @@
package nautilus.game.arcade.game.games.mineware.challenge.other;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.entity.Zombie;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilEnt;
import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeZombieInfection;
/**
* This is a zombie wrapper class that holds the speed and a freeze timer.
*
* @see ChallengeZombieInfection
*/
public class ZombieWrapper
{
private ChallengeZombieInfection _challenge;
private Zombie _wrapper;
private boolean _frozen;
private long _freezeTime;
private float _speed;
public ZombieWrapper(ChallengeZombieInfection challenge)
{
_challenge = challenge;
}
public Zombie spawn()
{
Location center = _challenge.getCenter();
World world = center.getWorld();
_wrapper = (Zombie) world.spawnEntity(center.clone().add(0.5, 1, 0.5), EntityType.ZOMBIE);
UtilEnt.Vegetate(_wrapper);
UtilEnt.ghost(_wrapper, true, false);
_wrapper.setCustomName(C.cRedB + "Infected Zombie");
_wrapper.setCustomNameVisible(true);
return _wrapper;
}
public void move(Player target)
{
UtilEnt.CreatureLook(_wrapper, target);
UtilEnt.CreatureMove(_wrapper, target.getLocation(), _speed);
}
public void extinguish()
{
_wrapper.setFireTicks(0);
}
public Location getLocation()
{
return _wrapper.getLocation().clone();
}
public ChallengeZombieInfection getChallenge()
{
return _challenge;
}
public Zombie getEntity()
{
return _wrapper;
}
public void remove()
{
_wrapper.remove();
}
public void freeze()
{
_frozen = true;
}
public void unfreeze()
{
_frozen = false;
}
public boolean isFrozen()
{
return _frozen;
}
public void setFreezeTime(long freezeTime)
{
_freezeTime = freezeTime;
}
public long getFreezeTime()
{
return _freezeTime;
}
public void setSpeed(float speed)
{
_speed = speed;
}
public float getSpeed()
{
return _speed;
}
public void setTarget(Player target)
{
_wrapper.setTarget(target);
}
public Player getTarget()
{
return (Player) _wrapper.getTarget();
}
}

View File

@ -0,0 +1,365 @@
package nautilus.game.arcade.game.games.mineware.challenge.type;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.bukkit.Color;
import org.bukkit.FireworkEffect.Type;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.Vector;
import mineplex.core.common.util.UtilFirework;
import mineplex.core.common.util.UtilMath;
import mineplex.core.projectile.ProjectileUser;
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;
/**
* A challenge based on falling anvil blocks.
*/
public class ChallengeAnvilDance extends Challenge
{
private static final int MAP_HEIGHT = 1;
private static final int MAP_SPAWN_SHIFT = 2;
private static final int SMOOTH_BRICK_DATA_RANGE = 3;
private static final int WAVE_HEIGHT = 13;
private static final int WAVE_HEIGHT_RANDOM = 3;
private static final int ANVIL_SPAWN_START_DELAY = 1;
private static final int ANVIL_DATA_RANGE = 3;
private static final float ANVIL_HITBOX_GROW = 0.7F;
private static final int DANCE_TIMER = 10;
private static final int DANCE_STOP = DANCE_TIMER / 2;
private static final int DANCE_DELAY_START = 5;
private static final float DANCE_SOUND_PITCH = 1.3F;
private static final double DANCING_ANVIL_RANDOM_VELOCITY_X = 0.2;
private static final double DANCING_ANVIL_RANDOM_VELOCITY_Y = 2.0;
private static final double DANCING_ANVIL_RANDOM_VELOCITY_Z = 0.2;
private static final int FIREWORK_HEIGHT = 8;
private static final int FIREWORK_HEIGHT_INCREMENT = 4;
private static final int FIREWORK_COLOR_DATA_RANGE = 255;
private static final int FIREWORK_LAUNCH_LIMIT = 10;
private static final int FIREWORK_LAUNCH_TICK_TIMER = 5;
private int _arenaStartSize;
private boolean _paused;
private Set<Block> _landedAnvils = new HashSet<>();
private Set<FallingBlock> _fallingAnvils = new HashSet<>();
private BukkitTask _fireworkTask;
public ChallengeAnvilDance(BawkBawkBattles host)
{
super(
host,
ChallengeType.LastStanding,
"Anvil Dance",
"It's raining anvils!",
"Dodge them to stay alive.");
Settings.setUseMapHeight();
}
@Override
public ArrayList<Location> createSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
int size = getArenaSize() - MAP_SPAWN_SHIFT;
for (Location location : circle(getCenter(), size, 1, true, false, 0))
{
spawns.add(location.add(0, MAP_HEIGHT, 0));
}
return spawns;
}
@Override
public void createMap()
{
_arenaStartSize = getArenaSize();
for (Location location : circle(getCenter(), _arenaStartSize, 1, false, false, 0))
{
Block block = location.getBlock();
setBlock(block, Material.SMOOTH_BRICK);
if (UtilMath.random.nextBoolean())
{
setData(block, (byte) (UtilMath.r(SMOOTH_BRICK_DATA_RANGE)));
}
addBlock(location.getBlock());
}
}
@Override
public void onStart()
{
checkInvalidFallingBlocksTask();
startFallingTask();
startDancingTask();
}
@Override
public void onEnd()
{
if (_fireworkTask != null)
{
_fireworkTask.cancel();
_fireworkTask = null;
}
_paused = false;
for (Block block : _landedAnvils)
{
resetBlock(block);
}
remove(EntityType.FALLING_BLOCK);
remove(EntityType.DROPPED_ITEM);
_landedAnvils.clear();
_fallingAnvils.clear();
}
@EventHandler
public void onItemSpawn(ItemSpawnEvent event)
{
if (!isChallengeValid())
return;
event.setCancelled(true);
}
@EventHandler
public void onEntityChangeBlockEvent(final EntityChangeBlockEvent event)
{
if (!isChallengeValid())
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()
{
@Override
public void run()
{
if (!isChallengeValid())
{
cancel();
return;
}
Iterator<FallingBlock> blocks = _fallingAnvils.iterator();
while (blocks.hasNext())
{
FallingBlock block = blocks.next();
if (!block.isValid())
{
blocks.remove();
}
}
}
}.runTaskTimer(Host.getArcadeManager().getPlugin(), 0L, 1L);
}
private void startFallingTask()
{
new BukkitRunnable()
{
@Override
public void run()
{
if (!isChallengeValid())
{
cancel();
return;
}
if (!_paused)
{
createAnvil();
}
}
}.runTaskTimer(Host.getArcadeManager().getPlugin(), ANVIL_SPAWN_START_DELAY * TICK_MULTIPLIER, 1L);
}
private void startDancingTask()
{
new BukkitRunnable()
{
@Override
public void run()
{
if (!isChallengeValid())
{
cancel();
return;
}
_paused = true;
playFireworksTask();
for (Player player : getPlayersAlive())
{
player.playSound(player.getLocation(), Sound.BAT_TAKEOFF, 1.0F, DANCE_SOUND_PITCH);
}
Iterator<Block> anvils = _landedAnvils.iterator();
while (anvils.hasNext())
{
Block anvil = anvils.next();
if (UtilMath.random.nextBoolean())
{
createDancingAnvil(anvil);
}
resetBlock(anvil);
anvils.remove();
}
for (FallingBlock block : _fallingAnvils)
{
createDancingAnvil(block);
}
startUnpauseTask();
}
}.runTaskTimer(Host.getArcadeManager().getPlugin(), DANCE_DELAY_START * TICK_MULTIPLIER, DANCE_TIMER * TICK_MULTIPLIER);
}
@SuppressWarnings("deprecation")
private void createAnvil()
{
Location center = getCenter().add(0, UtilMath.r(WAVE_HEIGHT_RANDOM) + WAVE_HEIGHT, 0);
List<Location> locations = circle(center, _arenaStartSize, 1, false, false, 0);
Location random = locations.get(UtilMath.r(locations.size()));
World world = random.getWorld();
FallingBlock block = world.spawnFallingBlock(random, Material.ANVIL, (byte) UtilMath.r(ANVIL_DATA_RANGE));
block.setDropItem(false);
_fallingAnvils.add(block);
Host.Manager.GetProjectile().AddThrow(block, null, Host, -1, true, false, false, true, ANVIL_HITBOX_GROW);
}
@SuppressWarnings("deprecation")
private void createDancingAnvil(Block block)
{
World world = block.getWorld();
FallingBlock dancingBlock = world.spawnFallingBlock(block.getLocation(), block.getType(), block.getData());
dancingBlock.setDropItem(false);
dancingBlock.setVelocity(getRandomVelocity());
_fallingAnvils.add(dancingBlock);
Host.Manager.GetProjectile().AddThrow(dancingBlock, null, Host, -1, true, false, false, true, ANVIL_HITBOX_GROW);
}
private void createDancingAnvil(FallingBlock block)
{
block.setVelocity(getRandomVelocity());
}
private void startUnpauseTask()
{
new BukkitRunnable()
{
@Override
public void run()
{
_paused = false;
}
}.runTaskLater(Host.getArcadeManager().getPlugin(), DANCE_STOP * TICK_MULTIPLIER);
}
private void playFireworksTask()
{
_fireworkTask = new BukkitRunnable()
{
int height = FIREWORK_HEIGHT;
int times = 0;
@Override
public void run()
{
if (!isChallengeValid())
{
cancel();
return;
}
times++;
if (times <= FIREWORK_LAUNCH_LIMIT)
{
Location spawn = getCenter().add(0, height, 0);
UtilFirework.playFirework(spawn, Type.BALL_LARGE, Color.fromBGR(UtilMath.r(FIREWORK_COLOR_DATA_RANGE), UtilMath.r(FIREWORK_COLOR_DATA_RANGE), UtilMath.r(FIREWORK_COLOR_DATA_RANGE)), false, true);
}
height += FIREWORK_HEIGHT_INCREMENT;
}
}.runTaskTimer(Host.getArcadeManager().getPlugin(), 0L, FIREWORK_LAUNCH_TICK_TIMER);
}
private Vector getRandomVelocity()
{
return new Vector(
UtilMath.rr(DANCING_ANVIL_RANDOM_VELOCITY_X, true),
UtilMath.rr(DANCING_ANVIL_RANDOM_VELOCITY_Y, false) + 1,
UtilMath.rr(DANCING_ANVIL_RANDOM_VELOCITY_Z, true));
}
@Override
public void onCollide(LivingEntity target, Block block, ProjectileUser data)
{
if (target instanceof Player && data.getThrown() instanceof FallingBlock)
{
Player player = (Player) target;
if (!isPlayerValid(player))
return;
player.damage(player.getHealth());
}
}
}

View File

@ -0,0 +1,205 @@
package nautilus.game.arcade.game.games.mineware.challenge.type;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Set;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.BlockIterator;
import mineplex.core.common.util.UtilBlock;
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;
/**
* A challenge based on arrows and explosions.
*/
public class ChallengeArrowRampage extends Challenge
{
private static final int LOCKED_INVENTORY_SLOT = 4;
private static final int MAP_MIN_SIZE = 9;
private static final int MAP_SPAWN_SHIFT = 2;
private static final int MAP_HEIGHT = 3;
private static final int MAP_SPAWN_HEIGHT = MAP_HEIGHT + 1;
private static final int HEIGHT_LVL0 = 0;
private static final int HEIGHT_LVL1 = 1;
private static final int HEIGHT_LVL2 = 2;
private static final int HEIGHT_LVL3 = 3;
private static final byte WOOL_DATA_LVL0 = 14;
private static final byte WOOL_DATA_LVL1 = 4;
private static final byte WOOL_DATA_LVL2 = 5;
private static final int WOOL_DATA_RANGE_LVL3 = 16;
private static final int JUMP_EFFECT_AMPLIFIER = 2;
private static final int ARROW_EXPLOSION_RADIUS = 3;
private static final int ARROW_HIT_BLOCK_MAX_DISTANCE = 4;
public ChallengeArrowRampage(BawkBawkBattles host)
{
super(
host,
ChallengeType.LastStanding,
"Arrow Rampage",
"You are equipped with explosive arrows.",
"Force others into the void!");
Settings.setUseMapHeight();
Settings.setCanCruble();
Settings.setLockInventory(LOCKED_INVENTORY_SLOT);
}
@Override
public ArrayList<Location> createSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
int size = getArenaSize(MAP_MIN_SIZE) - MAP_SPAWN_SHIFT;
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, MAP_SPAWN_HEIGHT, z));
}
}
}
return spawns;
}
@Override
public void createMap()
{
int size = getArenaSize(MAP_MIN_SIZE);
for (int x = -size; x <= size; x++)
{
for (int z = -size; z <= size; z++)
{
for (int y = 0; y <= MAP_HEIGHT; y++)
{
Block block = getCenter().getBlock().getRelative(x, y, z);
setBlock(block, Material.WOOL);
if (y == HEIGHT_LVL0)
{
setData(block, WOOL_DATA_LVL0);
}
else if (y == HEIGHT_LVL1)
{
setData(block, (byte) WOOL_DATA_LVL1);
}
else if (y == HEIGHT_LVL2)
{
setData(block, (byte) WOOL_DATA_LVL2);
}
else if (y == HEIGHT_LVL3)
{
setData(block, (byte) UtilMath.r(WOOL_DATA_RANGE_LVL3));
}
addBlock(block);
}
}
}
}
@Override
public void onStart()
{
Host.StrictAntiHack = false;
ItemStack bow = new ItemBuilder(Material.BOW)
.setUnbreakable(true)
.addEnchantment(Enchantment.ARROW_INFINITE, 1)
.addItemFlags(ItemFlag.HIDE_ENCHANTS, ItemFlag.HIDE_UNBREAKABLE)
.build();
setItem(Settings.getLockedSlot(), bow);
setItem(31, new ItemStack(Material.ARROW)); // Place arrow above bow, not visible in the hotbar.
addEffect(PotionEffectType.JUMP, JUMP_EFFECT_AMPLIFIER);
}
@Override
public void onEnd()
{
Host.StrictAntiHack = true;
remove(EntityType.FALLING_BLOCK);
}
@EventHandler
public void onProjectileHit(ProjectileHitEvent event)
{
if (!isChallengeValid())
return;
if (!(event.getEntity() instanceof Arrow))
return;
Arrow arrow = (Arrow) event.getEntity();
if (arrow.getShooter() == null || !(arrow.getShooter() instanceof Player))
return;
Set<Block> blocks = UtilBlock.getInRadius(arrow.getLocation(), ARROW_EXPLOSION_RADIUS).keySet();
Iterator<Block> blockIterator = blocks.iterator();
Block block = getHitBlock(arrow);
if (!Data.getModifiedBlocks().contains(block))
return;
while (blockIterator.hasNext())
{
Block toDestroy = blockIterator.next();
if (toDestroy.isLiquid())
{
blockIterator.remove();
}
else if (toDestroy.getRelative(BlockFace.UP).isLiquid())
{
blockIterator.remove();
}
}
arrow.remove();
Host.Manager.GetExplosion().BlockExplosion(blocks, arrow.getLocation(), false);
}
public Block getHitBlock(Arrow arrow)
{
Block hit = null;
BlockIterator iterator = new BlockIterator(arrow.getLocation().getWorld(), arrow.getLocation().toVector(), arrow.getVelocity().normalize(), 0, ARROW_HIT_BLOCK_MAX_DISTANCE);
while (iterator.hasNext())
{
hit = iterator.next();
if (!hit.isEmpty())
{
break;
}
}
return hit;
}
}

View File

@ -0,0 +1,235 @@
package nautilus.game.arcade.game.games.mineware.challenge.type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilMath;
import mineplex.core.projectile.ProjectileUser;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
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;
/**
* A challenge based on bomb lobbers.
*/
public class ChallengeBlockLobbers extends Challenge
{
private static final int MAP_HEIGHT = 1;
private static final int MAP_MIN_SIZE = 11;
private static final int WOOL_DATA_RANGE = 16;
private static final int INVENTORY_HOTBAR_SIZE = 8;
private static final double FALLING_BLOCK_HEIGHT_ADD = 0.4;
private static final double FALLING_BLOCK_VECTOR_MULTIPLY = 1.5;
private static final double FALLING_BLOCK_VECTOR_HEIGHT_ADD = 0.3;
private static final double FALLING_BLOCK_VECTOR_HEIGHT_MAX = 10.0;
private static final float FALLING_BLOCK_HITBOX_GROW = 0.2F;
private static final double KNOCKBACK_VECTOR_MULTIPLY = 0.8;
private static final double KNOCKBACK_VECTOR_HEIGHT_ADD = 0.3;
private static final double KNOCKBACK_VECTOR_HEIGHT_MAX = 0.5;
private static final List<Material> THROW_TYPES = new ArrayList<>(Arrays.asList(
Material.STONE,
Material.COBBLESTONE,
Material.GRASS,
Material.DIRT,
Material.SPONGE,
Material.WOOD));
public ChallengeBlockLobbers(BawkBawkBattles host)
{
super(
host, ChallengeType.LastStanding,
"Block Lobbers",
"Throw blocks to other players.",
"Try to knock them off the platform!");
Settings.setUseMapHeight();
Settings.setCanCruble();
}
@Override
public ArrayList<Location> createSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
for (Location location : circle(getCenter(), getArenaSize(), 1, false, false, 0))
{
spawns.add(location.add(0, MAP_HEIGHT, 0));
}
return spawns;
}
@Override
public void createMap()
{
for (Location location : circle(getCenter(), getArenaSize(MAP_MIN_SIZE), 1, false, false, 0))
{
Block block = location.getBlock();
setBlock(block, Material.WOOL, (byte) UtilMath.r(WOOL_DATA_RANGE));
addBlock(block);
}
}
@Override
public void onEnd()
{
remove(EntityType.FALLING_BLOCK);
remove(EntityType.DROPPED_ITEM);
}
@EventHandler
public void onUpdate(UpdateEvent event)
{
if (!isChallengeValid())
return;
if (event.getType() != UpdateType.FAST)
return;
for (Player player : getPlayersIn(true))
{
PlayerInventory inventory = player.getInventory();
Material material = UtilMath.randomElement(THROW_TYPES);
if (inventory.contains(material))
{
if (UtilInv.getAmount(player, material) <= INVENTORY_HOTBAR_SIZE)
{
inventory.addItem(new ItemStack(material));
}
}
else
{
inventory.addItem(new ItemStack(material));
}
}
}
@SuppressWarnings("deprecation")
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event)
{
if (!isChallengeValid())
return;
Player player = event.getPlayer();
if (!isPlayerValid(player))
return;
switchToAvailableSlot(player);
Material material = player.getItemInHand().getType();
if (!THROW_TYPES.contains(material))
return;
FallingBlock falling = player.getWorld().spawnFallingBlock(player.getLocation().add(0, FALLING_BLOCK_HEIGHT_ADD, 0), material, (byte) 0);
UtilAction.velocity(falling, player.getLocation().getDirection(), FALLING_BLOCK_VECTOR_MULTIPLY, false, 0.0, FALLING_BLOCK_VECTOR_HEIGHT_ADD, FALLING_BLOCK_VECTOR_HEIGHT_MAX, true);
Host.Manager.GetProjectile().AddThrow(falling, player, Host, -1, true, false, true, true, FALLING_BLOCK_HITBOX_GROW);
UtilInv.remove(player, material, (byte) 0, 1);
}
@SuppressWarnings("deprecation")
@EventHandler
public void onEntityChangeBlock(EntityChangeBlockEvent event)
{
if (!isChallengeValid())
return;
Entity entity = event.getEntity();
if (entity instanceof FallingBlock)
{
FallingBlock falling = (FallingBlock) entity;
if (falling.isOnGround())
{
falling.getWorld().playEffect(falling.getLocation(), Effect.STEP_SOUND, falling.getBlockId());
event.setCancelled(true);
}
}
}
@EventHandler
public void onItemSpawn(ItemSpawnEvent event)
{
if (!isChallengeValid())
return;
if (THROW_TYPES.contains(event.getEntity().getItemStack().getType()))
{
event.setCancelled(true);
}
}
@Override
public void onCollide(LivingEntity target, Block block, ProjectileUser data)
{
if (!(data.getThrown() instanceof FallingBlock))
return;
if (!(data.getThrower() instanceof Player))
return;
if (!(target instanceof Player))
return;
if (!isPlayerValid((Player) target))
return;
if (target.equals(data.getThrower()))
return;
UtilAction.velocity(target, UtilAlg.getTrajectory2d(data.getThrown().getLocation(), target.getLocation()), KNOCKBACK_VECTOR_MULTIPLY, false, 0, KNOCKBACK_VECTOR_HEIGHT_ADD, KNOCKBACK_VECTOR_HEIGHT_MAX, true);
data.getThrown().remove();
}
public void switchToAvailableSlot(Player player)
{
Material handType = player.getItemInHand().getType();
if (handType == Material.AIR || handType == null)
{
for (int i = 0; i <= INVENTORY_HOTBAR_SIZE; i++)
{
ItemStack current = player.getInventory().getItem(i);
if (current == null)
continue;
if (current != null && current.getType() != Material.AIR)
{
player.getInventory().setHeldItemSlot(i);
break;
}
}
}
}
}

View File

@ -0,0 +1,374 @@
package nautilus.game.arcade.game.games.mineware.challenge.type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.DyeColor;
import org.bukkit.FireworkEffect.Type;
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.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.material.Wool;
import org.bukkit.potion.PotionEffectType;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilFirework;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilTextBottom;
import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
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;
import nautilus.game.arcade.game.games.mineware.challenge.LogicTracker;
/**
* A challenge based on jumping and hitting block targets.
*/
public class ChallengeBouncingBlock extends Challenge implements LogicTracker
{
private static final int SCORE_GOAL = 10;
private static final int MAP_MIN_SIZE = 9;
private static final int MAP_SPAWN_SHIFT = 2;
private static final int MAP_HEIGHT = 1;
private static final byte PLATFORM_BLOCK_DATA = 0;
private static final int JUMP_EFFECT_MULTIPLIER = 6;
private static final double TRAP_SPAWN_CHANCE = 0.2;
private static final byte TRAP_BLOCK_DATA = 14;
private static final int TRAP_SCORE_LOSS_MAX = 2;
private static final int TRAP_SCORE_LOSS_MIN = 1;
private static final float SCORE_SOUND_VOLUME = 0.2F;
private static final float SCORE_SOUND_PITCH = 0.2F;
private static final int SCORE_BLOCK_HEIGHT = 6;
private static final int SCORE_BLOCK_HEIGHT_ADD = 5;
private static final int SCORE_BLOCK_HEIGHT_MAX = SCORE_BLOCK_HEIGHT + SCORE_BLOCK_HEIGHT_ADD;
private static final int SCORE_BLOCK_SPAWN_SHIFT = 2;
private static final int SCORE_BLOCK_BOUND_MULTIPLY = 2;
private static final double SCORE_FIREWORK_LOCATION_ADD = 0.5;
private static final int MILLISECONDS_UNTIL_NEXT_SCORE_LOSS = 300;
private List<Player> _stepTracker = new ArrayList<>();
private List<Block> _blocks = new ArrayList<>();
private Map<Player, Integer> _score = new HashMap<>();
public ChallengeBouncingBlock(BawkBawkBattles host)
{
super(
host,
ChallengeType.FirstComplete,
"Bouncing Block",
"Jump and punch floating wool blocks.",
"Avoid landing on red wool.",
"First to " + SCORE_GOAL + " wins!");
Settings.setUseMapHeight();
}
@Override
public ArrayList<Location> createSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
int size = getArenaSize(MAP_MIN_SIZE) - MAP_SPAWN_SHIFT;
for (Location location : circle(getCenter(), size, 1, true, false, 0))
{
spawns.add(location.add(0, MAP_HEIGHT, 0));
}
return spawns;
}
@Override
public void createMap()
{
for (Location location : circle(getCenter(), getArenaSize(MAP_MIN_SIZE), 1, false, false, 0))
{
Block block = location.getBlock();
setBlock(block, Material.WOOL);
if (Math.random() < TRAP_SPAWN_CHANCE)
{
setData(block, (byte) TRAP_BLOCK_DATA);
}
else
{
setData(block, (byte) PLATFORM_BLOCK_DATA);
}
addBlock(block);
}
spawnStartingWool();
}
@Override
public void onStart()
{
Host.StrictAntiHack = false;
addEffect(PotionEffectType.JUMP, JUMP_EFFECT_MULTIPLIER);
for (Player player : getPlayersAlive())
{
_score.put(player, 0);
}
}
@Override
public void onEnd()
{
Host.StrictAntiHack = true;
_stepTracker.clear();
for (Block woolBlock : _blocks)
{
resetBlock(woolBlock);
}
_blocks.clear();
_score.clear();
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event)
{
if (!isChallengeValid())
return;
Player player = event.getPlayer();
if (!isPlayerValid(player))
return;
if (event.getClickedBlock() == null || event.getClickedBlock().getType() == Material.AIR)
return;
Block block = event.getClickedBlock();
if (!_blocks.contains(block))
return;
hitBlock(player, block);
checkCompleted(player);
}
@EventHandler
public void onUpdate(UpdateEvent event)
{
if (!isChallengeValid())
return;
if (event.getType() != UpdateType.TICK)
return;
for (Player player : getPlayersIn(true))
{
UtilTextBottom.display(C.Bold + "Score: " + C.Reset + C.cYellow + C.Bold + _score.get(player), player);
}
}
@EventHandler
public void onPlayerMove(PlayerMoveEvent event)
{
if (!isChallengeValid())
return;
Player player = event.getPlayer();
if (!isPlayerValid(player))
return;
if (isLooking(event.getFrom(), event.getTo()))
return;
Location loc = player.getLocation();
Block blockBelow = loc.getBlock().getRelative(BlockFace.DOWN);
if (canLooseScore(player) && blockBelow.getType() == Material.WOOL)
{
Wool woolBelow = (Wool) blockBelow.getState().getData();
if (woolBelow.getColor() == DyeColor.RED)
{
int amount = subtractFromScore(player);
showSubtractMessage(player, amount);
trackStep(player);
}
}
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event)
{
if (!isChallengeValid())
return;
Player player = event.getPlayer();
_stepTracker.remove(player);
_score.remove(player);
}
private void hitBlock(Player player, Block block)
{
increment(player, 1);
player.playSound(player.getLocation(), Sound.SUCCESSFUL_HIT, SCORE_SOUND_VOLUME, SCORE_SOUND_PITCH);
resetBlock(block);
spawnRandomWool();
}
private void checkCompleted(Player player)
{
if (_score.get(player) >= SCORE_GOAL)
{
setCompleted(player);
UtilTextBottom.display(C.cGreen + C.Bold + "Completed!", player);
}
}
private boolean isLooking(Location from, Location to)
{
return from.getX() == to.getX() && from.getZ() == to.getZ();
}
private boolean canLooseScore(Player player)
{
return Recharge.Instance.use(player, "Score Loss", MILLISECONDS_UNTIL_NEXT_SCORE_LOSS, false, false) && _score.get(player) > 0;
}
private int subtractFromScore(Player player)
{
int amount = TRAP_SCORE_LOSS_MAX;
if (_score.get(player) == 1)
{
amount = TRAP_SCORE_LOSS_MIN;
}
subtract(player, amount);
return amount;
}
private void showSubtractMessage(Player player, int amount)
{
alert(player, "Score decreased by " + C.cRed + amount + C.Reset + "!");
player.playSound(player.getLocation(), Sound.NOTE_BASS, 1.0F, 1.0F);
}
private void trackStep(Player player)
{
if (!_stepTracker.contains(player))
{
_stepTracker.add(player);
}
}
private static final double SCORE_BLOCK_SPAWN_CHANCE = 0.1;
private static final int SCORE_BLOCK_DATA_RANGE = 16;
private void spawnStartingWool()
{
whileLoop: while (_blocks.size() <= Settings.getMaxCompletedCount() + 1)
{
for (int x = -getArenaSize(); x <= getArenaSize(); x++)
{
for (int z = -getArenaSize(); z <= getArenaSize(); z++)
{
for (int y = SCORE_BLOCK_HEIGHT; y <= SCORE_BLOCK_HEIGHT_MAX; y++)
{
Block block = getCenter().getBlock().getRelative(x, y, z);
if (block.isEmpty() || block.getType() == null)
{
if (Math.random() < SCORE_BLOCK_SPAWN_CHANCE)
{
spawnRandomWoolAt(x, y, z);
if (_blocks.size() >= Settings.getMaxCompletedCount() + 1)
{
break whileLoop;
}
}
}
}
}
}
}
}
private void spawnRandomWool()
{
int size = getArenaSize(MAP_MIN_SIZE) - SCORE_BLOCK_SPAWN_SHIFT;
int x = UtilMath.r(size * SCORE_BLOCK_BOUND_MULTIPLY) - size;
int y = SCORE_BLOCK_HEIGHT + UtilMath.r(SCORE_BLOCK_HEIGHT_ADD);
int z = UtilMath.r(size * SCORE_BLOCK_BOUND_MULTIPLY) - size;
spawnRandomWoolAt(x, y, z);
}
@SuppressWarnings("deprecation")
private void spawnRandomWoolAt(int x, int y, int z)
{
Block b = getCenter().getBlock().getRelative(x, y, z);
Byte color = (byte) UtilMath.r(SCORE_BLOCK_DATA_RANGE);
while (color == TRAP_BLOCK_DATA)
{
color = (byte) UtilMath.r(SCORE_BLOCK_DATA_RANGE);
}
setBlock(b, Material.WOOL, color);
UtilFirework.playFirework(b.getLocation().add(SCORE_FIREWORK_LOCATION_ADD, SCORE_FIREWORK_LOCATION_ADD, SCORE_FIREWORK_LOCATION_ADD), Type.BALL, DyeColor.getByWoolData(b.getData()).getColor(), false, false);
_blocks.add(b);
}
private void increment(Player player, int amount)
{
int score = _score.get(player);
int updatedScore = score + amount;
if (updatedScore <= SCORE_GOAL)
{
_score.put(player, updatedScore);
}
}
private void subtract(Player player, int amount)
{
int score = _score.get(player);
int updatedScore = score - amount;
if (updatedScore > 0)
{
_score.put(player, updatedScore);
}
else
{
_score.put(player, 0);
}
}
@Override
public boolean hasData(Player player)
{
return !_stepTracker.contains(player);
}
}

View File

@ -0,0 +1,225 @@
package nautilus.game.arcade.game.games.mineware.challenge.type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilMath;
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;
import nautilus.game.arcade.game.games.mineware.challenge.LogicTracker;
import nautilus.game.arcade.game.games.mineware.tracker.SpeedyBuildersTracker;
/**
* A challenge based on fast block placement.
*/
public class ChallengeBuildRace extends Challenge implements LogicTracker
{
private static final int MAP_SPAWN_SHIFT = 2;
private static final int MAP_HEIGHT = 1;
private static final double UNPLACEABLE_BLOCK_RADIUS_FROM_PLAYER = 1.5;
private static final int BLOCK_TOWER_HEIGHT_LIMIT = 3;
private static final int BLOCK_AMOUNT = 5;
private static final Material[] MATERIALS = {
Material.DIRT,
Material.STONE,
Material.COBBLESTONE,
Material.LOG,
Material.WOOD,
Material.WOOL,
Material.BRICK,
Material.SMOOTH_BRICK,
Material.GLASS
};
private List<Player> _speedTracker = new ArrayList<>();
public ChallengeBuildRace(BawkBawkBattles host)
{
super(
host,
ChallengeType.FirstComplete,
"Build Race",
"Your inventory is filled with blocks.",
"Place them all in the ground!");
Settings.setUseMapHeight();
}
@Override
public ArrayList<Location> createSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
int size = getArenaSize() - MAP_SPAWN_SHIFT;
for (Location location : circle(getCenter(), size, 1, true, false, 0))
{
spawns.add(location.add(0, MAP_HEIGHT, 0));
}
return spawns;
}
@Override
public void createMap()
{
for (Location location : circle(getCenter(), getArenaSize(), 1, false, false, 0))
{
Block block = location.getBlock();
setBlock(block, Material.GRASS);
addBlock(location.getBlock());
}
}
@SuppressWarnings("deprecation")
@Override
public void onStart()
{
for (Material allowed : MATERIALS)
{
Host.BlockPlaceAllow.add(allowed.getId());
}
for (Player player : getPlayersAlive())
{
setupInventoryContents(player);
}
}
@SuppressWarnings("deprecation")
@Override
public void onEnd()
{
_speedTracker.clear();
for (Material allowed : MATERIALS)
{
Host.BlockPlaceAllow.remove(allowed.getId());
}
}
@EventHandler
public void onBlockPlace(BlockPlaceEvent event)
{
if (!isChallengeValid())
return;
Player player = event.getPlayer();
if (!isPlayerValid(player))
{
event.setCancelled(true);
return;
}
Block block = event.getBlock();
Block bottomVoid1 = block.getRelative(BlockFace.DOWN);
Block bottomVoid2 = bottomVoid1.getRelative(BlockFace.DOWN);
Block bottomVoid3 = bottomVoid2.getRelative(BlockFace.DOWN);
if (bottomVoid1.isEmpty() && bottomVoid2.isEmpty() && bottomVoid3.isEmpty())
{
alert(player, C.cRed + "You can't place blocks that far from the ground.");
blockBreakEffect(block, true);
event.setCancelled(true);
return;
}
if (!Data.isModifiedBlock(block.getRelative(BlockFace.DOWN)))
{
System.out.println("Cancel");
event.setCancelled(true);
return;
}
for (Player others : getPlayersAlive())
{
if (others.equals(player))
continue;
if (UtilMath.offset2d(block.getLocation(), others.getLocation()) < UNPLACEABLE_BLOCK_RADIUS_FROM_PLAYER)
{
alert(player, C.cRed + "You can't place blocks near other players.");
blockBreakEffect(block, true);
event.setCancelled(true);
return;
}
}
if (block.getLocation().getY() >= getCenter().getY() + BLOCK_TOWER_HEIGHT_LIMIT)
{
alert(player, C.cRed + "You can't build a tower that high.");
blockBreakEffect(block, true);
event.setCancelled(true);
return;
}
addBlock(block);
ArrayList<ItemStack> items = UtilInv.getItems(player);
if ((items.size() - 1) == 0)
{
if (items.get(0).getAmount() == 1)
{
trackSpeed(player);
setCompleted(player);
}
}
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event)
{
if (!isChallengeValid())
return;
_speedTracker.remove(event.getPlayer());
}
private void trackSpeed(Player player)
{
long startTime = Settings.getStartTime();
long finishTime = System.currentTimeMillis();
if (finishTime <= startTime + SpeedyBuildersTracker.GOAL)
{
_speedTracker.add(player);
}
}
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, BLOCK_AMOUNT);
player.getInventory().addItem(itemStack);
}
}
@Override
public boolean hasData(Player player)
{
return _speedTracker.contains(player);
}
}

View File

@ -0,0 +1,381 @@
package nautilus.game.arcade.game.games.mineware.challenge.type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Chicken;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilMath;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
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;
import nautilus.game.arcade.game.games.mineware.challenge.NumberTracker;
/**
* A challenge based around chickens.
*/
public class ChallengeChickenShooting extends Challenge implements NumberTracker
{
private static final int LOCKED_INVENTORY_SLOT = 4;
private static final int MAP_SPAWN_SHIFT = 1;
private static final int MAP_HEIGHT = 1;
private static final int SPAWN_COORDINATES_MULTIPLE = 2;
private static final int INVENTORY_ARROW_SLOT = 31;
private static final int PLAYER_SIZE_LARGE = 40;
private static final int PLAYER_SIZE_MID = 20;
private static final int CHICKEN_SPAWN_SHIFT = 2;
private static final int CHICKEN_SPAWN_HEIGHT = 15;
private static final int CHICKEN_AMOUNT_MIN = 10;
private static final int CHICKEN_AMOUNT_MULTIPLY = 3;
private static final double CHICKEN_HEATH = 0.1;
private static final double CHICKEN_BABY_SPAWN_CHANCE = 0.3;
private static final int SCORE_GOAL = 6;
private static final int SCORE_COLOR_CHANGE_1 = 1;
private static final int SCORE_COLOR_CHANGE_2 = 2;
private static final int SCORE_COLOR_CHANGE_3 = 3;
private static final int SCORE_COLOR_CHANGE_4 = 4;
private static final int SCORE_COLOR_CHANGE_5 = 5;
private List<Chicken> _chickens = new ArrayList<>();
private List<Location> _chickenSpawns = new ArrayList<>();
private Map<Player, Integer> _score = new HashMap<>();
public ChallengeChickenShooting(BawkBawkBattles host)
{
super(
host,
ChallengeType.FirstComplete,
"Chicken Shooting",
"Shoot 6 chickens.");
Settings.setUseMapHeight();
Settings.setLockInventory(LOCKED_INVENTORY_SLOT);
}
@Override
public ArrayList<Location> createSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
int size = getArenaSize() - MAP_SPAWN_SHIFT;
for (int x = -(size); x <= size; x++)
{
for (int z = -(size); z <= size; z++)
{
if (x % SPAWN_COORDINATES_MULTIPLE == 0 && z % SPAWN_COORDINATES_MULTIPLE == 0)
{
spawns.add(getCenter().add(x, MAP_HEIGHT, z));
}
}
}
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 <= MAP_HEIGHT; y++)
{
Block block = getCenter().getBlock().getRelative(x, y, z);
if (y == 0)
{
setBlock(block, Material.GRASS);
}
else
{
if (Math.abs(x) == getArenaSize() || Math.abs(z) == getArenaSize())
{
setBlock(block, Material.FENCE);
}
else
{
generateGrass(block);
}
}
addBlock(block);
}
}
}
initializeChickenSpawns();
}
@Override
public void onStart()
{
Host.DamagePvE = true;
addBowAndArrow();
}
@Override
public void onEnd()
{
Host.DamagePvE = false;
for (Chicken chicken : _chickens)
{
chicken.remove();
}
_chickens.clear();
_chickenSpawns.clear();
_score.clear();
remove(EntityType.ARROW);
}
@EventHandler
public void onProjectileHit(ProjectileHitEvent event)
{
if (!isChallengeValid())
return;
Projectile entity = event.getEntity();
if (entity instanceof Arrow)
{
entity.remove();
}
}
@EventHandler
public void onEntityDeath(EntityDeathEvent event)
{
if (!isChallengeValid())
return;
event.getDrops().clear();
event.setDroppedExp(0);
}
@EventHandler
public void onCustomDamage(CustomDamageEvent event)
{
if (!isChallengeValid())
return;
if (event.GetProjectile() == null)
{
event.SetCancelled("Not projectile damage");
return;
}
Player player = event.GetDamagerPlayer(true);
if (player == null)
return;
if (!isPlayerValid(player))
return;
LivingEntity entity = event.GetDamageeEntity();
if (!_chickens.remove(entity))
{
event.SetCancelled("Not a chicken");
return;
}
event.AddMod("Ensure Death", null, entity.getHealth(), false);
checkCompleted(player, entity);
}
@EventHandler
public void onUpdate(UpdateEvent event)
{
if (!isChallengeValid())
return;
UpdateType speed;
int alive = getPlayersIn(true).size();
if (alive >= PLAYER_SIZE_LARGE)
{
speed = UpdateType.FASTEST;
}
else if (alive >= PLAYER_SIZE_MID)
{
speed = UpdateType.FASTER;
}
else
{
speed = UpdateType.FAST;
}
if (event.getType() != speed)
return;
removeChickensOnGround();
spawnChicken();
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event)
{
if (!isChallengeValid())
return;
_score.remove(event.getPlayer());
}
private void initializeChickenSpawns()
{
_chickenSpawns = (ArrayList<Location>) circle(getCenter(), getArenaSize() - CHICKEN_SPAWN_SHIFT, 1, false, false, CHICKEN_SPAWN_HEIGHT);
}
private void addBowAndArrow()
{
ItemStack bow = new ItemBuilder(Material.BOW)
.setUnbreakable(true)
.addEnchantment(Enchantment.ARROW_INFINITE, 1)
.addItemFlags(ItemFlag.HIDE_ENCHANTS, ItemFlag.HIDE_UNBREAKABLE)
.build();
ItemStack arrow = new ItemStack(Material.ARROW);
for (Player player : getPlayersAlive())
{
PlayerInventory inv = player.getInventory();
inv.setItem(Settings.getLockedSlot(), bow);
inv.setItem(INVENTORY_ARROW_SLOT, arrow);
_score.put(player, 0);
}
}
private void checkCompleted(Player player, LivingEntity entity)
{
int score = showAndIncrementScore(player, entity);
if (score == SCORE_GOAL)
{
setCompleted(player);
}
}
private int showAndIncrementScore(Player player, LivingEntity entity)
{
int score = _score.get(player) + 1;
Location location = player.getEyeLocation();
location.add(UtilAlg.getTrajectory(location, entity.getEyeLocation()).multiply(Math.min(7, entity.getLocation().distance(location))));
displayCount(player, location, selectScoreColor(score));
_score.put(player, score);
return score;
}
private String selectScoreColor(int score)
{
if (score == SCORE_COLOR_CHANGE_1)
{
return C.cWhiteB + score;
}
else if (score == SCORE_COLOR_CHANGE_2)
{
return C.cGrayB + score;
}
else if (score == SCORE_COLOR_CHANGE_3)
{
return C.cGreenB + score;
}
else if (score == SCORE_COLOR_CHANGE_4)
{
return C.cYellowB + score;
}
else if (score == SCORE_COLOR_CHANGE_5)
{
return C.cGoldB + score;
}
else
{
return C.cRedB + score;
}
}
private void removeChickensOnGround()
{
Iterator<Chicken> iterator = _chickens.iterator();
while (iterator.hasNext())
{
Chicken chicken = iterator.next();
if (chicken.isOnGround() || !chicken.isValid())
{
chicken.remove();
iterator.remove();
}
}
}
private void spawnChicken()
{
if (_chickens.size() < CHICKEN_AMOUNT_MIN + (getPlayersIn(true).size() * CHICKEN_AMOUNT_MULTIPLY))
{
Location spawn = UtilMath.randomElement(_chickenSpawns);
Host.CreatureAllow = true;
Chicken chicken = (Chicken) spawn.getWorld().spawnEntity(spawn, EntityType.CHICKEN);
Host.CreatureAllow = false;
chicken.setMaxHealth(CHICKEN_HEATH);
chicken.setHealth(CHICKEN_HEATH);
if (Math.random() < CHICKEN_BABY_SPAWN_CHANCE)
{
chicken.setBaby();
}
_chickens.add(chicken);
}
}
@Override
public Number getData(Player player)
{
return _score.get(player);
}
@Override
public boolean hasData(Player player)
{
return _score.containsKey(player);
}
}

View File

@ -0,0 +1,256 @@
package nautilus.game.arcade.game.games.mineware.challenge.type;
import java.util.ArrayList;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilShapes;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
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;
/**
* A challenge based on dropping from a platform in the correct block.
*/
public class ChallengeCloudFall extends Challenge
{
private static final int MAP_SPAWN_SHIFT = 2;
private static final int MAP_HEIGHT = 85;
private static final int MAP_SIZE_HOLLOW_DIVIDER = 2;
private static final int WOOL_DATA_RANGE = 16;
private static final double OBSTANCE_SPAWN_CHANCE = 0.005;
private static final int OBSTACLE_MAX_HEIGHT = 70;
private static final int OBSTANCE_DISTANCE_FROM_GROUND = 10;
private static final byte OBSTANCE_COLOR_1 = 0;
private static final byte OBSTANCE_COLOR_2 = 8;
private static final double OBSTANCE_COLOR_CHANGE_CHANCE = 0.3;
private static final Material LANDING_PLATFORM_BLOCK_TYPE = Material.WOOL;
private static final byte LANDING_PLATFORM_BLOCK_DATA = 5;
private static final int LANDING_PLATFORMS_HEIGHT = 2;
private static final double LANDING_PLATFORM_SPAWN_CHANCE = 0.1;
public ChallengeCloudFall(BawkBawkBattles host)
{
super(
host,
ChallengeType.FirstComplete,
"Cloud Fall",
"Jump and land on green wool.",
"Avoid the deadly clouds!");
Settings.setUseMapHeight();
}
@Override
public ArrayList<Location> createSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
int size = getArenaSize() - MAP_SPAWN_SHIFT;
for (Location location : circle(getCenter(), size, 1, true, false, MAP_HEIGHT))
{
spawns.add(location.add(0, 1, 0));
}
return spawns;
}
@Override
public void createMap()
{
createBottomMiddleMapPart();
createPlatformMapPart();
}
@Override
public void onStart()
{
Host.DamageFall = true;
}
@Override
public void onEnd()
{
Host.DamageFall = false;
}
@EventHandler
public void onCustomDamage(CustomDamageEvent event)
{
if (!isChallengeValid())
return;
if (event.GetCause() != DamageCause.FALL)
return;
Player player = event.GetDamageePlayer();
if (!isPlayerValid(player))
return;
Block below = player.getLocation().getBlock().getRelative(BlockFace.DOWN);
if (below.getY() == (int) getCenter().getY() + LANDING_PLATFORMS_HEIGHT)
{
if (below.isEmpty())
{
Block[] nearby = {
below.getRelative(BlockFace.NORTH),
below.getRelative(BlockFace.EAST),
below.getRelative(BlockFace.SOUTH),
below.getRelative(BlockFace.WEST),
below.getRelative(BlockFace.NORTH_EAST),
below.getRelative(BlockFace.NORTH_WEST),
below.getRelative(BlockFace.SOUTH_EAST),
below.getRelative(BlockFace.SOUTH_WEST)
};
for (Block near : nearby)
{
if (isLandingBlock(near))
{
setCompleted(player);
event.SetCancelled("Fell on wool");
break;
}
}
}
else if (isLandingBlock(below))
{
setCompleted(player);
event.SetCancelled("Fell on wool");
}
else
{
event.AddMod("Fell into another block", player.getHealth());
}
}
else
{
event.AddMod("Fell into another block", player.getHealth());
}
}
@SuppressWarnings("deprecation")
private boolean isLandingBlock(Block block)
{
return block.getType() == LANDING_PLATFORM_BLOCK_TYPE && block.getData() == LANDING_PLATFORM_BLOCK_DATA;
}
private void createBottomMiddleMapPart()
{
int size = getArenaSize() - MAP_SPAWN_SHIFT;
for (int x = -getArenaSize(); x <= getArenaSize(); x++)
{
for (int z = -getArenaSize(); z <= getArenaSize(); z++)
{
for (int y = 0; y <= OBSTACLE_MAX_HEIGHT; y++)
{
Block block = getCenter().getBlock().getRelative(x, y, z);
if (y == 0)
{
setBlock(block, Material.WOOL);
}
else if (y == 1 && Math.random() < LANDING_PLATFORM_SPAWN_CHANCE && Math.abs(x) < size && Math.abs(z) < size)
{
Block upperBlock = block.getRelative(BlockFace.UP);
createLandingWool(block, upperBlock);
addBlock(upperBlock);
}
else if (canCreateObstacle(block) && y > OBSTANCE_DISTANCE_FROM_GROUND && Math.random() < OBSTANCE_SPAWN_CHANCE)
{
addBlock(createObstacle(block));
}
addBlock(block);
}
}
}
}
private void createPlatformMapPart()
{
Location platform = getCenter().add(0, MAP_HEIGHT, 0);
for (Location location : UtilShapes.getCircle(platform, false, getArenaSize()))
{
Block block = location.getBlock();
setBlock(block, Material.WOOL, (byte) UtilMath.r(WOOL_DATA_RANGE));
addBlock(block);
}
for (Location location : UtilShapes.getCircle(platform, false, (int) getArenaSize() / MAP_SIZE_HOLLOW_DIVIDER))
{
resetBlock(location.getBlock());
}
}
private void createLandingWool(Block bottom, Block top)
{
setBlock(bottom, Material.WOOL, LANDING_PLATFORM_BLOCK_DATA);
setBlock(top, Material.WOOL, LANDING_PLATFORM_BLOCK_DATA);
}
private boolean canCreateObstacle(Block center)
{
Block[] area = {
center.getRelative(BlockFace.DOWN),
center.getRelative(BlockFace.NORTH),
center.getRelative(BlockFace.EAST),
center.getRelative(BlockFace.SOUTH),
center.getRelative(BlockFace.WEST),
center.getRelative(BlockFace.NORTH).getRelative(BlockFace.DOWN),
center.getRelative(BlockFace.EAST).getRelative(BlockFace.DOWN),
center.getRelative(BlockFace.SOUTH).getRelative(BlockFace.DOWN),
center.getRelative(BlockFace.WEST).getRelative(BlockFace.DOWN)
};
boolean available = true;
for (Block part : area)
{
if (!part.isEmpty())
{
available = false;
break;
}
}
return available && center.isEmpty();
}
private Block[] createObstacle(Block center)
{
Block north = center.getRelative(BlockFace.NORTH);
Block east = center.getRelative(BlockFace.EAST);
Block south = center.getRelative(BlockFace.SOUTH);
Block west = center.getRelative(BlockFace.WEST);
byte data = OBSTANCE_COLOR_1;
if (Math.random() < OBSTANCE_COLOR_CHANGE_CHANCE)
{
data = OBSTANCE_COLOR_2;
}
setBlock(north, Material.WOOL, data);
setBlock(east, Material.WOOL, data);
setBlock(west, Material.WOOL, data);
setBlock(south, Material.WOOL, data);
return new Block[] { north, east, west, south };
}
}

View File

@ -0,0 +1,264 @@
package nautilus.game.arcade.game.games.mineware.challenge.type;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilTextBottom;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
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;
/**
* A challenge based on speed and colors.
*/
public class ChallengeColorChange extends Challenge
{
private static final int MAP_SPAWN_SHIFT = 2;
private static final int SPAWN_COORDINATES_MULTIPLE = 2;
private static final int MAP_HEIGHT = 1;
private static final long TIME_DELAY = 3000;
private static final int TIME_DELAY_DECREMENT_RATE = 100;
private static final int RESET_DELAY = 4000;
private static final int PLATFORM_MULTIPLIER = 2;
private static final int PLATFORM_SHIFT = 2;
private static final float FALL_SOUND_VOLUME = 2.0F;
private static final float FALL_SOUND_PITCH = 0.0F;
private static final int COUNTDOWN_SOUND_DELAY = 1000;
private long _modifiedTimeDelay;
private List<Integer> _colors = new ArrayList<>();
private int _currentColor;
private boolean _isFalling;
private long _lastSound;
private long _stageDelay;
private List<Entry<Integer, Integer>> _lastGeneratedPlatforms = new ArrayList<>();
public ChallengeColorChange(BawkBawkBattles host)
{
super(
host,
ChallengeType.LastStanding,
"Color Change",
"Stand on the correct color.");
Settings.setUseMapHeight();
populateColors();
}
@Override
public ArrayList<Location> createSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
int size = getArenaSize() - MAP_SPAWN_SHIFT;
for (int x = -size; x <= 7; x++)
{
for (int z = -size; z <= size; z++)
{
if (x % SPAWN_COORDINATES_MULTIPLE == 0 && z % SPAWN_COORDINATES_MULTIPLE == 0)
{
spawns.add(getCenter().add(x, MAP_HEIGHT, z));
}
}
}
return spawns;
}
@Override
public void createMap()
{
createPlatformCoordinates();
createPlatforms();
}
@Override
public void onStart()
{
_modifiedTimeDelay = TIME_DELAY;
_stageDelay = System.currentTimeMillis() + _modifiedTimeDelay;
_currentColor = UtilMath.randomElement(_colors);
fillItem(new ItemStack(Material.STAINED_CLAY, 1, (short) _currentColor));
}
@Override
public void onEnd()
{
_isFalling = false;
_lastSound = 0;
}
@EventHandler
public void onUpdate(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
if (!isChallengeValid())
return;
Player[] players = getPlayersAlive().toArray(new Player[0]);
if (_stageDelay < System.currentTimeMillis())
{
UtilTextBottom.displayProgress(0, players);
if (_isFalling)
{
playFallSound();
_isFalling = false;
_modifiedTimeDelay -= TIME_DELAY_DECREMENT_RATE;
_stageDelay = System.currentTimeMillis() + _modifiedTimeDelay;
_currentColor = UtilMath.randomElement(_colors);
createMap();
addCurrentColorToInventory();
}
else
{
_isFalling = true;
_stageDelay = System.currentTimeMillis() + RESET_DELAY;
removeDifferentColorPlatforms();
}
}
else if (!_isFalling)
{
double amount = (_stageDelay - System.currentTimeMillis()) / (double) _modifiedTimeDelay;
UtilTextBottom.displayProgress(amount, players);
playCountdownSound();
}
else
{
UtilTextBottom.displayProgress(0, players);
}
}
private void populateColors()
{
for (int i = 0; i <= 15; i++)
{
if (i != 2 && i != 6 && i != 7 && i != 9 && i != 12)
{
_colors.add(i);
}
}
}
@SuppressWarnings({ "unchecked", "rawtypes" })
private void createPlatformCoordinates()
{
List<Entry<Integer, Integer>> platforms = new ArrayList<>();
int size = getArenaSize() - PLATFORM_SHIFT;
for (int x = -size; x <= 4; x++)
{
for (int z = -size; z <= size; z++)
{
platforms.add(new HashMap.SimpleEntry(x * PLATFORM_MULTIPLIER, z * PLATFORM_MULTIPLIER));
}
}
Collections.shuffle(platforms);
_lastGeneratedPlatforms = platforms;
}
private void createPlatforms()
{
int i = UtilMath.randomElement(_colors);
for (Entry<Integer, Integer> platform : _lastGeneratedPlatforms)
{
if (i >= _colors.size())
{
i = 0;
}
byte color = (byte) (int) _colors.get(i);
i++;
createPlatformPart(platform.getKey(), platform.getValue(), color);
}
}
private void createPlatformPart(int platformX, int platformZ, byte color)
{
for (int x = 0; x <= 1; x++)
{
for (int z = 0; z <= 1; z++)
{
Block block = getCenter().getBlock().getRelative(platformX + x, 0, platformZ + z);
setBlock(block, Material.STAINED_CLAY, color);
addBlock(block);
}
}
}
private void playFallSound()
{
for (Player player : getPlayersAlive())
{
player.playSound(player.getLocation(), Sound.NOTE_PIANO, FALL_SOUND_VOLUME, FALL_SOUND_PITCH);
}
}
private void addCurrentColorToInventory()
{
fillItem(new ItemStack(Material.STAINED_CLAY, 1, (short) _currentColor));
}
@SuppressWarnings("deprecation")
private void removeDifferentColorPlatforms()
{
for (Entry<Integer, Integer> platform : _lastGeneratedPlatforms)
{
for (int x = 0; x <= 1; x++)
{
for (int z = 0; z <= 1; z++)
{
Block block = getCenter().getBlock().getRelative(platform.getKey() + x, 0, platform.getValue() + z);
if (block.getData() != _currentColor)
{
resetBlock(block);
}
}
}
}
}
private void playCountdownSound()
{
if (_lastSound < System.currentTimeMillis())
{
_lastSound = System.currentTimeMillis() + COUNTDOWN_SOUND_DELAY;
for (Player player : getPlayersAlive())
{
player.playSound(player.getLocation(), Sound.NOTE_STICKS, 1.0F, 1.0F);
}
}
}
}

View File

@ -0,0 +1,177 @@
package nautilus.game.arcade.game.games.mineware.challenge.type;
import java.util.ArrayList;
import java.util.HashMap;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.recharge.Recharge;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
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;
/**
* A challenge based on tnt.
*/
public class ChallengeDeadlyTnt extends Challenge
{
private static final int LOCKED_INVENTORY_SLOT = 4;
private static final int MAP_SPAWN_SHIFT = 2;
private static final int MAP_HEIGHT = 1;
private static final int STAINED_CLAY_DATA_RANGE = 16;
private static final int KNOCKBACK_APPLY_RADIUS_MIN = 4;
private static final double KNOCKBACK_APPLY_RADIUS_NORMALIZER = 10000;
private static final int KNOCKBACK_DIVIDER = 2;
private static final double KNOCKBACK_NORMALIZER = 20000;
private static final int KNOCKBACK_MULTIPLIER = 3;
private static final int KNOCKBACK_HEIGHT_MAX = 6;
private static final double KNOCKBACK_HEIGHT_MIN = 0.5;
private static final int KNOCKBACK_HEIGHT_MULTIPLIER = 2;
private static final int TNT_USE_COOLDOWN = 3000;
private static final double TNT_VELOCITY_POWER = 0.6;
private static final double TNT_VELOCICTY_HEIGHT = 0.2;
private static final double TNT_VELOCITY_HEIGHT_MAX = 1;
private static final int TNT_FUSE_TICKS_MULTIPLIER = 60;
private static final double TNT_FUSE_TICKS_DIVIDER = 70000;
public ChallengeDeadlyTnt(BawkBawkBattles host)
{
super(
host,
ChallengeType.LastStanding,
"Deadly TNT",
"Throw TNT at other players.",
"Do not get knocked off!");
Settings.setUseMapHeight();
Settings.setCanCruble();
Settings.setLockInventory(LOCKED_INVENTORY_SLOT);
}
@Override
public ArrayList<Location> createSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
int size = getArenaSize() - MAP_SPAWN_SHIFT;
for (Location location : circle(getCenter(), size, 1, true, false, 0))
{
spawns.add(location.add(0, MAP_HEIGHT, 0));
}
return spawns;
}
@Override
public void createMap()
{
for (Location location : circle(getCenter(), getArenaSize(), 1, false, false, 0))
{
Block block = location.getBlock();
setBlock(block, Material.STAINED_CLAY, (byte) UtilMath.r(STAINED_CLAY_DATA_RANGE));
addBlock(block);
}
}
@Override
public void onStart()
{
setItem(Settings.getLockedSlot(), new ItemStack(Material.TNT));
}
@Override
public void onEnd()
{
remove(EntityType.PRIMED_TNT);
}
@EventHandler(priority = EventPriority.LOW)
public void onEntityExplode(EntityExplodeEvent event)
{
if (!isChallengeValid())
return;
if (!(event.getEntity() instanceof TNTPrimed))
return;
event.blockList().clear();
dealKnockbackToNearbyPlayers(event.getLocation());
}
@EventHandler
public void onCustomDamage(CustomDamageEvent event)
{
if (!isChallengeValid())
return;
if (event.GetCause() != DamageCause.ENTITY_EXPLOSION)
return;
event.SetCancelled("No TNT damage");
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event)
{
if (!isChallengeValid())
return;
Player player = event.getPlayer();
if (!isPlayerValid(player))
return;
if (!Recharge.Instance.use(player, "TNT", TNT_USE_COOLDOWN, false, true))
return;
throwTnt(player);
}
private void dealKnockbackToNearbyPlayers(Location center)
{
HashMap<Player, Double> nearby = UtilPlayer.getInRadius(center, KNOCKBACK_APPLY_RADIUS_MIN + ((System.currentTimeMillis() - Settings.getStartTime()) / KNOCKBACK_APPLY_RADIUS_NORMALIZER));
for (Player player : nearby.keySet())
{
if (!isPlayerValid(player))
continue;
double mult = nearby.get(player) / KNOCKBACK_DIVIDER;
mult += (System.currentTimeMillis() - Settings.getStartTime()) / KNOCKBACK_NORMALIZER;
UtilAction.velocity(player, UtilAlg.getTrajectory(center, player.getLocation()), KNOCKBACK_MULTIPLIER * mult, false, 0, KNOCKBACK_HEIGHT_MIN + KNOCKBACK_HEIGHT_MULTIPLIER * mult, KNOCKBACK_HEIGHT_MAX, true);
}
}
private void throwTnt(Player player)
{
Location dropsite = player.getEyeLocation().add(player.getLocation().getDirection());
TNTPrimed tnt = player.getWorld().spawn(dropsite, TNTPrimed.class);
UtilAction.velocity(tnt, player.getLocation().getDirection(), TNT_VELOCITY_POWER, false, 0, TNT_VELOCICTY_HEIGHT, TNT_VELOCITY_HEIGHT_MAX, false);
int ticks = (int) (TNT_FUSE_TICKS_MULTIPLIER * (1 - ((System.currentTimeMillis() - Settings.getStartTime()) / TNT_FUSE_TICKS_DIVIDER)));
tnt.setFuseTicks(ticks);
player.playSound(player.getLocation(), Sound.FUSE, 1.0F, 1.0F);
}
}

View File

@ -0,0 +1,259 @@
package nautilus.game.arcade.game.games.mineware.challenge.type;
import java.util.ArrayList;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
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;
import mineplex.core.common.util.UtilMath;
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;
/**
* A challenge based on finding diamonds.
*/
public class ChallengeDiamondHunt extends Challenge
{
private static final int MAP_SPAWN_SHIFT = 1;
private static final int SPAWN_COORDINATES_MULTIPLE = 2;
private static final int MAP_HEIGHT = 2;
private static final int STAINED_CLAY_DATA_RANGE = 16;
private static final int CHEST_DATA_RANGE = 4;
private static final double CHEST_INVENTORY_SLOT_FILL_CHANCE = 0.7;
private static final int DIAMOND_AMOUNT_MIN = 10;
private static final Material[] CHEST_MATERIALS = {
Material.WOOD_SPADE,
Material.WOOD_PICKAXE,
Material.WOOD_AXE,
Material.WOOD_HOE,
Material.STONE_SPADE,
Material.STONE_PICKAXE,
Material.STONE_AXE,
Material.STONE_HOE,
Material.IRON_SPADE,
Material.IRON_PICKAXE,
Material.IRON_AXE,
Material.IRON_HOE,
Material.GOLD_SPADE,
Material.GOLD_PICKAXE,
Material.GOLD_AXE,
Material.GOLD_HOE,
Material.DIAMOND_SPADE,
Material.DIAMOND_PICKAXE,
Material.DIAMOND_AXE,
Material.DIAMOND_HOE,
Material.WOOD_SWORD,
Material.STONE_SWORD,
Material.IRON_SWORD,
Material.GOLD_SWORD,
Material.DIAMOND_SWORD,
Material.SNOW_BALL,
Material.PAPER,
Material.SLIME_BALL,
Material.BONE,
Material.ENDER_PEARL,
Material.EYE_OF_ENDER,
Material.COAL,
Material.IRON_INGOT,
Material.GOLD_INGOT,
Material.EMERALD,
Material.STICK,
Material.STRING,
Material.BOWL,
Material.FEATHER,
Material.SEEDS,
Material.MELON_SEEDS,
Material.PUMPKIN_SEEDS,
Material.SUGAR_CANE,
Material.WHEAT,
Material.BRICK,
Material.NETHER_STALK,
Material.EGG,
Material.FLINT,
Material.LEATHER,
Material.GOLD_NUGGET,
Material.NETHER_BRICK,
Material.FISHING_ROD,
Material.CARROT_STICK,
Material.SHEARS,
Material.LEASH,
Material.REDSTONE,
Material.GHAST_TEAR,
Material.IRON_BARDING,
Material.GOLD_BARDING,
Material.DIAMOND_BARDING,
Material.TRIPWIRE_HOOK,
Material.STONE,
Material.DIAMOND_ORE,
Material.DIAMOND_BLOCK,
Material.APPLE,
Material.BREAD,
Material.ROTTEN_FLESH,
Material.GOLDEN_APPLE
};
public ChallengeDiamondHunt(BawkBawkBattles host)
{
super(
host,
ChallengeType.FirstComplete,
"Diamond Hunt",
"Find a diamond in the chests.");
Settings.setUseMapHeight();
}
@Override
public ArrayList<Location> createSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
int size = getArenaSize() - MAP_SPAWN_SHIFT;
for (int x = -size; x <= size; x++)
{
for (int z = -size; z <= size; z++)
{
if (x % SPAWN_COORDINATES_MULTIPLE == 0 && z % SPAWN_COORDINATES_MULTIPLE == 0)
{
spawns.add(getCenter().add(x, MAP_HEIGHT, z));
}
}
}
return spawns;
}
@Override
public void createMap()
{
ArrayList<Inventory> inventories = new ArrayList<Inventory>();
for (int x = -getArenaSize(); x <= getArenaSize(); x++)
{
for (int z = -getArenaSize(); z <= getArenaSize(); z++)
{
Block block = getCenter().getBlock().getRelative(x, 0, z);
setBlock(block, Material.STAINED_CLAY, (byte) UtilMath.r(STAINED_CLAY_DATA_RANGE));
addBlock(block);
if (Math.abs(x) % SPAWN_COORDINATES_MULTIPLE == 0 && Math.abs(z) % SPAWN_COORDINATES_MULTIPLE == 0)
{
Block relativeBlock = block.getRelative(0, 1, 0);
setBlock(relativeBlock, Material.CHEST, (byte) UtilMath.r(CHEST_DATA_RANGE));
addBlock(relativeBlock);
Inventory inventory = ((Chest) relativeBlock.getState()).getInventory();
inventories.add(inventory);
for (int i = 0; i < inventory.getSize(); i++)
{
ItemStack item = new ItemStack(UtilMath.randomElement(CHEST_MATERIALS));
if (Math.random() < CHEST_INVENTORY_SLOT_FILL_CHANCE)
{
inventory.setItem(i, item);
}
}
}
else
{
Block relativeBlock = block.getRelative(BlockFace.UP);
setBlock(relativeBlock, Material.STAINED_CLAY, (byte) UtilMath.r(STAINED_CLAY_DATA_RANGE));
addBlock(relativeBlock);
}
}
}
for (int i = 0; i < DIAMOND_AMOUNT_MIN + Host.getPlayersWithRemainingLives(); i++)
{
Inventory inventory = UtilMath.randomElement(inventories);
inventory.setItem(UtilMath.r(inventory.getSize()), new ItemStack(Material.DIAMOND));
}
}
@Override
public void onStart()
{
Host.InventoryOpenChest = true;
Host.InventoryOpenBlock = true;
}
@Override
public void onEnd()
{
Host.InventoryOpenChest = false;
Host.InventoryOpenBlock = false;
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event)
{
if (!isChallengeValid())
return;
Player player = event.getPlayer();
if (getPlayersAlive().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)
{
if (!isChallengeValid())
return;
InventoryHolder holder = event.getInventory().getHolder();
Player player = (Player) event.getWhoClicked();
if (!(holder instanceof Player))
{
if (!isPlayerValid(player))
return;
event.setCancelled(true);
if (holder instanceof DoubleChest || holder instanceof Chest)
{
ItemStack item = event.getCurrentItem();
if (item != null && item.getType() == Material.DIAMOND)
{
event.setCurrentItem(new ItemStack(Material.AIR));
setCompleted(player);
player.closeInventory();
}
}
}
}
}

View File

@ -0,0 +1,335 @@
package nautilus.game.arcade.game.games.mineware.challenge.type;
import java.util.ArrayList;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTextBottom;
import mineplex.core.common.util.UtilTextMiddle;
import mineplex.core.disguise.disguises.DisguiseCat;
import mineplex.core.disguise.disguises.DisguiseWolf;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.game.games.mineware.BawkBawkBattles;
import nautilus.game.arcade.game.games.mineware.challenge.ChallengeTeam;
import nautilus.game.arcade.game.games.mineware.challenge.ChallengeType;
import nautilus.game.arcade.game.games.mineware.challenge.TeamChallenge;
/**
* A team based challenge with players disguised as dogs and cats.
*/
public class ChallengeDogsVersusCats extends TeamChallenge
{
private static final int CHALLENGE_DURATION = 75000;
private static final int LOCKED_INVENTORY_SLOT = 4;
private static final int TEAM_SEPERATOR_MULTIPLE = 2;
private static final int MAP_SPAWN_SHIFT = 1;
private static final int MAP_HEIGHT = 1;
private static final int SPAWN_COORDINATE_MULTIPLE = 2;
private static final double PARTICLE_LOCATION_ADD_X = 0.5;
private static final double PARTICLE_LOCATION_ADD_Y = 1;
private static final double PARTICLE_LOCATION_ADD_Z = 0.5;
private static final float PARTICLE_OFFSET = 0.5F;
private static final int PARTICLE_COUNT = 5;
private static final int SCORE_PER_PLAYER = 50;
private int _catScore = 0;
private int _dogScore = 0;
public ChallengeDogsVersusCats(BawkBawkBattles host)
{
super(
host,
ChallengeType.FirstComplete,
"Dogs",
"Cats",
"Dogs Vs Cats",
"If you are a dog, bark.",
"If you are a cat, meow.",
"First team to the end number wins!");
Settings.setUseMapHeight();
Settings.setTeamBased();
Settings.setDuration(CHALLENGE_DURATION);
Settings.setLockInventory(LOCKED_INVENTORY_SLOT);
}
@Override
public ArrayList<Location> createSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
int size = getArenaSize() - MAP_SPAWN_SHIFT;
for (int x = -size; x <= size; x++)
{
for (int z = -size; z <= size; z++)
{
if (x % SPAWN_COORDINATE_MULTIPLE == 0 && z % SPAWN_COORDINATE_MULTIPLE == 0)
{
spawns.add(getCenter().add(x, MAP_HEIGHT, z));
}
}
}
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 <= MAP_HEIGHT; y++)
{
Block block = getCenter().getBlock().getRelative(x, y, z);
if (y == 0)
{
setBlock(block, Material.GRASS);
}
else
{
if (Math.abs(x) == getArenaSize() || Math.abs(z) == getArenaSize())
{
setBlock(block, Material.FENCE);
}
else if (y == 1)
{
generateGrass(block);
}
}
addBlock(block);
}
}
}
}
@Override
public void onStart()
{
int looped = 0;
for (Player player : getPlayersAlive())
{
player.setGameMode(GameMode.ADVENTURE);
if (looped % TEAM_SEPERATOR_MULTIPLE == 0)
{
addToDogTeam(player);
}
else
{
addToCatTeam(player);
}
looped++;
}
}
@Override
public void onEnd()
{
_catScore = 0;
_dogScore = 0;
}
@EventHandler
public void onScoreUpdate(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
if (!isChallengeValid())
return;
int maxDogScore = calculateScore(getFirstTeam());
int maxCatScore = calculateScore(getSecondTeam());
displayScore(maxDogScore, maxCatScore);
checkScore(maxDogScore, maxCatScore);
}
@EventHandler
public void onMiddleTextUpdate(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC)
return;
if (!isChallengeValid())
return;
showTipsForDogs();
showTipsForCats();
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event)
{
if (!isChallengeValid())
return;
Player player = event.getPlayer();
if (!isPlayerValid(player))
return;
if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK)
{
ItemStack item = player.getItemInHand();
if (item.getType() == Material.BONE || item.getType() == Material.STRING)
{
Location loc = player.getLocation();
if (getFirstTeam().isMember(player))
{
incrementDogScore();
player.playSound(loc, Sound.WOLF_BARK, 1.0F, 1.0F);
}
else
{
incrementCatScore();
player.playSound(loc, Sound.CAT_MEOW, 1.0F, 1.0F);
}
UtilParticle.PlayParticle(
ParticleType.NOTE,
loc.add(PARTICLE_LOCATION_ADD_X, PARTICLE_LOCATION_ADD_Y, PARTICLE_LOCATION_ADD_Z),
PARTICLE_OFFSET,
PARTICLE_OFFSET,
PARTICLE_OFFSET,
0.0F,
PARTICLE_COUNT,
ViewDist.LONG,
UtilServer.getPlayers());
}
}
}
private void addToDogTeam(Player player)
{
getFirstTeam().add(player);
DisguiseWolf dog = new DisguiseWolf(player);
Host.getArcadeManager().GetDisguise().disguise(dog);
player.getInventory().setItem(Settings.getLockedSlot(), ItemStackFactory.Instance.CreateStack(Material.BONE, (byte) 0, 1, C.Reset + C.Bold + "Bark"));
UtilPlayer.message(player, F.main("Game", "You are a " + C.cGreen + "Dog" + C.mBody + ", bark!"));
}
private void addToCatTeam(Player player)
{
getSecondTeam().add(player);
DisguiseCat Dcat = new DisguiseCat(player);
Host.getArcadeManager().GetDisguise().disguise(Dcat);
player.getInventory().setItem(Settings.getLockedSlot(), ItemStackFactory.Instance.CreateStack(Material.STRING, (byte) 0, 1, C.Reset + C.Bold + "Meow"));
UtilPlayer.message(player, F.main("Game", "You are a " + C.cGreen + "Cat" + C.mBody + ", meow!"));
}
private void displayScore(int maxDogScore, int maxCatScore)
{
for (Player player : getPlayersAlive())
{
UtilTextMiddle.display(null, C.cBlueB + "Dogs: " + C.cWhite + _dogScore + "/" + maxDogScore + C.cGray + " - " + C.cRedB + "Cats: " + C.cWhite + _catScore + "/" + maxCatScore, player);
}
}
private void checkScore(int maxDogScore, int maxCatScore)
{
if (_dogScore >= maxDogScore)
{
for (Player player : getFirstTeam().getPlayers())
{
setCompleted(player);
}
}
else if (_catScore >= maxCatScore)
{
for (Player player : getSecondTeam().getPlayers())
{
setCompleted(player);
}
}
}
private void showTipsForDogs()
{
for (Player player : getFirstTeam().getPlayers())
{
if (isPlayerValid(player))
{
UtilTextBottom.display(C.Bold + "Left-Click to Woof!", player);
}
}
}
private void showTipsForCats()
{
for (Player player : getSecondTeam().getPlayers())
{
if (isPlayerValid(player))
{
UtilTextBottom.display(C.Bold + "Left-Click to Meow!", player);
}
}
}
private void incrementDogScore()
{
int maxScore = calculateScore(getFirstTeam());
if (_dogScore < maxScore)
{
_dogScore++;
}
}
private void incrementCatScore()
{
int maxScore = calculateScore(getSecondTeam());
if (_catScore < maxScore)
{
_catScore++;
}
}
@SuppressWarnings("unused")
private int calculateScore(ChallengeTeam team)
{
int amountOnTeam = 0;
for (Player player : team.getPlayers())
{
amountOnTeam++;
}
return amountOnTeam * SCORE_PER_PLAYER;
}
}

View File

@ -0,0 +1,297 @@
package nautilus.game.arcade.game.games.mineware.challenge.type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import mineplex.core.common.util.C;
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;
import nautilus.game.arcade.game.games.mineware.challenge.NumberTracker;
/**
* A challenge based on dragon eggs.
*/
public class ChallengeEggSmash extends Challenge implements NumberTracker
{
private static final int SCORE_GOAL = 10;
private static final int LOCKED_INVENTORY_SLOT = 4;
private static final int MAP_SPAWN_SHIFT = 1;
private static final int SPAWN_COORDINATE_MULTIPLE = 2;
private static final int MAP_HEIGHT = 1;
private static final double EFFECT_LOCATION_XYZ_ADD = 0.5;
private static final int WOOL_DATA_RANGE = 16;
private static final double FALLING_DRAGON_BLOCK_SPAWN_X_ADD = 0.5;
private static final double FALLING_DRAGON_BLOCK_SPAWN_Y_ADD = 2;
private static final double FALLING_DRAGON_BLOCK_SPAWN_Z_ADD = 0.5;
private static final double SCORE_LOCATION_X_ADD = 0.5;
private static final double SCORE_LOCATION_Y_ADD = 0.7;
private static final double SCORE_LOCATION_Z_ADD = 0.5;
private static final int SCORE_COLOR_CHANGE_1 = 1;
private static final int SCORE_COLOR_CHANGE_2 = 2;
private static final int SCORE_COLOR_CHANGE_3 = 3;
private static final int SCORE_COLOR_CHANGE_4 = 4;
private static final int SCORE_COLOR_CHANGE_5 = 5;
private static final int SCORE_COLOR_CHANGE_6 = 6;
private static final int SCORE_COLOR_CHANGE_7 = 7;
private static final int SCORE_COLOR_CHANGE_8 = 8;
private static final int SCORE_COLOR_CHANGE_9 = 9;
private Map<Player, Integer> _score = new HashMap<>();
public ChallengeEggSmash(BawkBawkBattles host)
{
super(
host,
ChallengeType.FirstComplete,
"Egg Smash",
"Smash " + SCORE_GOAL + " dragon eggs.");
Settings.setUseMapHeight();
Settings.setLockInventory(LOCKED_INVENTORY_SLOT);
}
@Override
public ArrayList<Location> createSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
int size = getArenaSize() - MAP_SPAWN_SHIFT;
for (int x = -(size); x < size; x++)
{
for (int z = -(size); z < size; z++)
{
if (x % SPAWN_COORDINATE_MULTIPLE == 0 && z % SPAWN_COORDINATE_MULTIPLE == 0)
{
spawns.add(getCenter().add(x, MAP_HEIGHT, z));
}
}
}
return spawns;
}
@Override
public void createMap()
{
createFloorMapPart();
createDragonEggsMapPart();
}
@Override
public void onStart()
{
ItemStack axe = new ItemBuilder(Material.IRON_AXE)
.setUnbreakable(true)
.setItemFlags(ItemFlag.HIDE_UNBREAKABLE)
.build();
for (Player player : getPlayersAlive())
{
_score.put(player, 0);
player.getInventory().setItem(Settings.getLockedSlot(), axe);
}
}
@Override
public void onEnd()
{
_score.clear();
remove(EntityType.FALLING_BLOCK);
}
@SuppressWarnings("deprecation")
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event)
{
if (!isChallengeValid())
return;
Player player = event.getPlayer();
if (!isPlayerValid(player))
return;
Action action = event.getAction();
if (action == Action.LEFT_CLICK_BLOCK || action == Action.RIGHT_CLICK_BLOCK)
{
Block block = event.getClickedBlock();
if (block.getType() == Material.DRAGON_EGG)
{
block.getWorld().playEffect(block.getLocation().add(EFFECT_LOCATION_XYZ_ADD, EFFECT_LOCATION_XYZ_ADD, EFFECT_LOCATION_XYZ_ADD), Effect.STEP_SOUND, block.getTypeId());
resetBlock(block);
spawnDragonEgg();
showAndIncrementScore(player, block);
event.setCancelled(true);
}
}
}
@EventHandler
public void onEntityChangeBlockEvent(EntityChangeBlockEvent event)
{
if (!isChallengeValid())
return;
if (event.getEntity() instanceof FallingBlock)
{
new BukkitRunnable()
{
@Override
public void run()
{
if (!isChallengeValid())
{
cancel();
return;
}
addBlock(event.getBlock());
}
}.runTaskLater(Host.getArcadeManager().getPlugin(), 1L);
}
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event)
{
if (!isChallengeValid())
return;
_score.remove(event.getPlayer());
}
private void createFloorMapPart()
{
for (int x = -getArenaSize(); x <= getArenaSize(); x++)
{
for (int z = -getArenaSize(); z <= getArenaSize(); z++)
{
Block block = getCenter().getBlock().getRelative(x, 0, z);
setBlock(block, Material.WOOL, (byte) UtilMath.r(WOOL_DATA_RANGE));
addBlock(block);
}
}
}
private static final int DRAGON_EGG_AMOUNT = 9;
private void createDragonEggsMapPart()
{
for (int i = 0; i < DRAGON_EGG_AMOUNT; i++)
{
Block block = getRandomBlock();
setBlock(block, Material.DRAGON_EGG);
addBlock(block);
}
}
@SuppressWarnings("deprecation")
private void spawnDragonEgg()
{
Host.CreatureAllow = true;
for (int i = 0; i < 10; i++)
{
Block block = getRandomBlock();
if (block.isEmpty())
{
getCenter().getWorld().spawnFallingBlock(block.getLocation().add(FALLING_DRAGON_BLOCK_SPAWN_X_ADD, FALLING_DRAGON_BLOCK_SPAWN_Y_ADD, FALLING_DRAGON_BLOCK_SPAWN_Z_ADD), Material.DRAGON_EGG, (byte) 0);
break;
}
}
Host.CreatureAllow = false;
}
private static final int DRAGON_SPAWN_LOCATION_MULTIPLIER = 2;
private Block getRandomBlock()
{
return getCenter().add(
UtilMath.r((getArenaSize() * DRAGON_SPAWN_LOCATION_MULTIPLIER)) - getArenaSize(),
1,
UtilMath.r((getArenaSize() * DRAGON_SPAWN_LOCATION_MULTIPLIER)) - getArenaSize()).getBlock();
}
private void showAndIncrementScore(Player player, Block block)
{
int score = _score.get(player) + 1;
displayCount(player, block.getLocation().add(SCORE_LOCATION_X_ADD, SCORE_LOCATION_Y_ADD, SCORE_LOCATION_Z_ADD), selectScoreColor(score));
_score.put(player, score);
if (score == SCORE_GOAL)
{
setCompleted(player);
}
}
private String selectScoreColor(int score)
{
if (score == SCORE_COLOR_CHANGE_1 || score == SCORE_COLOR_CHANGE_2)
{
return C.cWhiteB + score;
}
else if (score == SCORE_COLOR_CHANGE_3 || score == SCORE_COLOR_CHANGE_4)
{
return C.cGreenB + score;
}
else if (score == SCORE_COLOR_CHANGE_5 || score == SCORE_COLOR_CHANGE_6)
{
return C.cYellowB + score;
}
else if (score == SCORE_COLOR_CHANGE_7 || score == SCORE_COLOR_CHANGE_8)
{
return C.cGoldB + score;
}
else if (score == SCORE_COLOR_CHANGE_9)
{
return C.cRedB + score;
}
else
{
return C.cDRedB + score;
}
}
@Override
public Number getData(Player player)
{
return _score.get(player);
}
@Override
public boolean hasData(Player player)
{
return _score.containsKey(player);
}
}

View File

@ -0,0 +1,388 @@
package nautilus.game.arcade.game.games.mineware.challenge.type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockSpreadEvent;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.scheduler.BukkitRunnable;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilShapes;
import mineplex.core.common.util.UtilTextBottom;
import mineplex.core.projectile.ProjectileUser;
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;
import nautilus.game.arcade.game.games.mineware.challenge.NumberTracker;
/**
* A challenge based on falling blocks.
*/
public class ChallengeFallingBlocks extends Challenge implements NumberTracker
{
private static final int MAP_SPAWN_SHIFT = 2;
private static final int MAP_HEIGHT = 1;
private static final byte STONE_DATA = 5;
private static final double SPAWN_CHANCE = 0.2;
private static final double SPAWN_CHANCE_INCREMENT = 0.05;
private static final double SPAWN_HEIGHT = 13.0;
private static final int NEXT_WAVE = 5;
private static final float WAVE_SOUND_VOLUME = 1.0F;
private static final float WAVE_SOUND_PITCH = 1.5F;
private static final double SPAWN_CHANCE_MAX = 100;
private static final int PLAYER_CAMP_MAX_HEIGHT = 3;
private static final byte ADDITIONAL_BLOCK_DATA = 2;
private static final float BLOCK_HITBOX_GROW = 0.7F;
private static final Material[] MATERIALS = {
Material.GRASS,
Material.DIRT,
Material.STONE,
Material.LOG,
Material.WOOD,
Material.COBBLESTONE,
Material.GRAVEL,
Material.COAL_ORE,
Material.IRON_ORE,
Material.HAY_BLOCK,
Material.JUKEBOX,
Material.SMOOTH_BRICK,
Material.EMERALD_ORE,
Material.FURNACE };
private static final Material[] FLOOR = { Material.GRASS, Material.DIRT, Material.STONE, Material.COBBLESTONE };
private static final Sound[] SOUNDS = { Sound.DIG_GRASS, Sound.DIG_GRAVEL, Sound.DIG_SAND, Sound.DIG_SNOW, Sound.DIG_STONE, Sound.DIG_WOOD, Sound.DIG_WOOL };
private int _modifiedNextWave;
private double _modifiedSpawnChance;
private int _wavesCompleted;
private Set<Block> _remaining = new HashSet<>();
private int _arenaStartSize;
private Map<Player, Integer> _waveTracker = new HashMap<>();
private boolean _trackedWave = false;
public ChallengeFallingBlocks(BawkBawkBattles host)
{
super(
host,
ChallengeType.LastStanding,
"Falling Blocks",
"Blocks are falling from the sky!",
"Try to avoid getting hit.");
Settings.setUseMapHeight();
}
@Override
public ArrayList<Location> createSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
int size = getArenaSize() - MAP_SPAWN_SHIFT;
for (Location location : circle(getCenter(), size, 1, true, false, 0))
{
spawns.add(location.add(0, MAP_HEIGHT, 0));
}
return spawns;
}
@Override
public void createMap()
{
_arenaStartSize = getArenaSize();
for (Location location : circle(getCenter(), _arenaStartSize, 1, false, false, 0))
{
Material material = UtilMath.randomElement(FLOOR);
Block block = location.getBlock();
setBlock(block, material);
if (material == Material.STONE)
{
if (UtilMath.random.nextBoolean())
{
setData(block, STONE_DATA);
}
}
addBlock(location.getBlock());
}
}
@Override
public void onStart()
{
_modifiedNextWave = NEXT_WAVE;
_modifiedSpawnChance = SPAWN_CHANCE;
initializeWaveTracker();
startWavesTask();
startWaveTimerTask();
}
@Override
public void onEnd()
{
_wavesCompleted = 0;
_trackedWave = false;
_arenaStartSize = 0;
for (Block block : _remaining)
{
resetBlock(block);
}
_remaining.clear();
for (Entity entity : Host.WorldData.World.getEntities())
{
if (entity instanceof FallingBlock)
{
entity.remove();
}
}
_waveTracker.clear();
}
@EventHandler
public void onItemSpawn(ItemSpawnEvent event)
{
event.setCancelled(true);
}
@EventHandler
public void onEntityChangeBlockEvent(final EntityChangeBlockEvent event)
{
if (!isChallengeValid())
return;
if (event.getEntity() instanceof FallingBlock)
{
final Block block = event.getBlock();
_remaining.add(block);
if (!_trackedWave)
{
_trackedWave = true;
for (Player player : getPlayersAlive())
{
_waveTracker.put(player, _waveTracker.get(player) + 1);
}
}
new BukkitRunnable()
{
@Override
public void run()
{
if (!isChallengeValid())
{
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());
resetBlock(block);
_remaining.remove(block);
}
}.runTaskLater(Host.getArcadeManager().getPlugin(), 40L);
}
}
@EventHandler
public void onBlockSpread(BlockSpreadEvent event)
{
if (!isChallengeValid())
return;
if (event.getNewState().getType() == Material.GRASS)
event.setCancelled(true);
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event)
{
if (!isChallengeValid())
return;
Player player = event.getPlayer();
if (_waveTracker.containsKey(player))
{
_waveTracker.remove(player);
}
}
private void initializeWaveTracker()
{
for (Player player : getPlayersAlive())
{
_waveTracker.put(player, 0);
}
}
private void startWavesTask()
{
new BukkitRunnable()
{
@Override
public void run()
{
if (!isChallengeValid())
{
cancel();
return;
}
createWave();
}
}.runTaskTimer(Host.getArcadeManager().getPlugin(), NEXT_WAVE * TICK_MULTIPLIER, NEXT_WAVE * TICK_MULTIPLIER);
}
private void startWaveTimerTask()
{
new BukkitRunnable()
{
@Override
public void run()
{
if (!isChallengeValid())
{
cancel();
return;
}
if (_modifiedNextWave == 0)
{
_modifiedNextWave = NEXT_WAVE;
}
int wave = _wavesCompleted + 1;
String time = C.cWhite + C.Bold + _modifiedNextWave;
if (wave > 1)
{
UtilTextBottom.display(C.cYellow + C.Bold + "Next Wave: " + time, UtilServer.getPlayers());
}
else
{
UtilTextBottom.display(C.cYellow + C.Bold + "First Wave: " + time, UtilServer.getPlayers());
}
_modifiedNextWave--;
}
}.runTaskTimer(Host.getArcadeManager().getPlugin(), 0L, TICK_MULTIPLIER);
}
private void createWave()
{
_trackedWave = false;
if (_modifiedSpawnChance < SPAWN_CHANCE_MAX)
_modifiedSpawnChance += SPAWN_CHANCE_INCREMENT;
_wavesCompleted++;
Sound nextSound = UtilMath.randomElement(SOUNDS);
for (Player player : getPlayersAlive())
{
player.playSound(player.getLocation(), nextSound, WAVE_SOUND_VOLUME, WAVE_SOUND_PITCH);
}
Location center = getCenter().add(0, SPAWN_HEIGHT, 0);
for (Location location : UtilShapes.getCircle(center, false, _arenaStartSize))
{
if (Math.random() <= _modifiedSpawnChance)
{
createFallingBlock(location);
}
}
for (Player player : getPlayersAlive())
{
Location camp = player.getLocation();
if (camp.getY() >= getCenter().getY() + 1 && camp.getY() <= getCenter().getY() + PLAYER_CAMP_MAX_HEIGHT)
{
createFallingBlock(new Location(Host.WorldData.World, camp.getX(), getCenter().getY() + SPAWN_HEIGHT, camp.getZ()));
}
}
}
@SuppressWarnings("deprecation")
private void createFallingBlock(Location location)
{
Material material = UtilMath.randomElement(MATERIALS);
World world = location.getWorld();
FallingBlock block = world.spawnFallingBlock(location, material, (byte) 0);
block.setDropItem(false);
if ((material == Material.SMOOTH_BRICK || material == Material.DIRT) && UtilMath.random.nextBoolean())
{
block = world.spawnFallingBlock(location, material, ADDITIONAL_BLOCK_DATA);
}
Host.Manager.GetProjectile().AddThrow(block, null, Host, -1, true, false, false, true, BLOCK_HITBOX_GROW);
}
@Override
public void onCollide(LivingEntity target, Block block, ProjectileUser data)
{
if (target instanceof Player && data.getThrown() instanceof FallingBlock)
{
Player player = (Player) target;
if (!isPlayerValid(player))
return;
player.damage(player.getHealth());
}
}
@Override
public Number getData(Player player)
{
return _waveTracker.get(player);
}
@Override
public boolean hasData(Player player)
{
return _waveTracker.containsKey(player);
}
}

View File

@ -0,0 +1,306 @@
package nautilus.game.arcade.game.games.mineware.challenge.type;
import java.util.ArrayList;
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.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import mineplex.core.common.util.UtilEvent;
import mineplex.core.common.util.UtilEvent.ActionType;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.common.util.UtilServer;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.recharge.Recharge;
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;
/**
* A challenge based on click speed.
*/
public class ChallengeFastFood extends Challenge
{
private static final int MAP_SPAWN_SHIFT = 3;
private static final int MAP_HEIGHT = 1;
private static final int INVENTORY_HOTBAR_SIZE = 8;
private static final int RAW_FISH_DATA_RANGE = 3;
private static final int RANDOM_FOOD_AMOUNT = 5;
private static final int FOOD_THROW_COOLDOWN = 100;
private static final double FOOD_THROW_EYE_LOCATION_HEIGHT_SUBTRACT = 0.5;
private static final double FOOD_THROW_CREATE_DIRT_CHANCE = 0.3;
private static final int LONG_GRASS_DATA_RANGE = 2;
private static final int RED_ROSE_DATA_RANGE = 8;
private static final Material[] FOOD = {
Material.APPLE,
Material.BREAD,
Material.GRILLED_PORK,
Material.COOKED_BEEF,
Material.RAW_FISH,
Material.COOKED_FISH,
Material.CAKE,
Material.COOKIE,
Material.MELON,
Material.COOKED_CHICKEN,
Material.CARROT_ITEM,
Material.BAKED_POTATO,
Material.PUMPKIN_PIE };
private static final Material[] FLOWERS = { Material.LONG_GRASS, Material.YELLOW_FLOWER, Material.RED_ROSE };
private int _itemSeperator = 0;
public ChallengeFastFood(BawkBawkBattles host)
{
super(
host,
ChallengeType.FirstComplete,
"Fast Food",
"Your inventory is full of food.",
"Punch to throw it in the ground.");
Settings.setUseMapHeight();
}
@Override
public ArrayList<Location> createSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
int size = getArenaSize() - MAP_SPAWN_SHIFT;
for (Location location : circle(getCenter(), size, 1, true, false, 0))
{
spawns.add(location.add(0, MAP_HEIGHT, 0));
}
return spawns;
}
@Override
public void createMap()
{
for (Location location : circle(getCenter(), getArenaSize(), 1, false, false, 0))
{
Block block = location.getBlock();
setBlock(block, Material.GRASS);
addBlock(block);
}
}
@Override
public void onStart()
{
itemParticleTask();
for (Player player : getPlayersAlive())
{
for (int i = 0; i <= INVENTORY_HOTBAR_SIZE; i++)
{
player.getInventory().setItem(i, getRandomFood());
}
}
}
@Override
public void onEnd()
{
_itemSeperator = 0;
remove(EntityType.DROPPED_ITEM);
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event)
{
if (!isChallengeValid())
return;
Player player = event.getPlayer();
if (!isPlayerValid(player))
return;
if (UtilEvent.isAction(event, ActionType.L))
{
if (event.getItem() != null)
{
ItemStack item = event.getItem();
throwItemInGround(player, item);
}
else
{
changeItemSlot(player);
}
}
}
private void itemParticleTask()
{
new BukkitRunnable()
{
@Override
public void run()
{
if (!isChallengeValid())
{
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(RAW_FISH_DATA_RANGE) + 1);
}
else if (foodMaterial == Material.COOKED_FISH)
{
data = (byte) UtilMath.r(1);
}
ItemStack itemStack = new ItemStack(foodMaterial, RANDOM_FOOD_AMOUNT, (byte) data);
return itemStack;
}
private void changeItemSlot(Player player)
{
for (int i = 0; i <= INVENTORY_HOTBAR_SIZE; i++)
{
if (player.getInventory().getItem(i) != null)
{
ItemStack newItemSelection = player.getInventory().getItem(i);
if (newItemSelection.getType() != Material.AIR)
{
player.getInventory().setHeldItemSlot(i);
return;
}
}
}
}
@SuppressWarnings("deprecation")
private void throwItemInGround(Player player, ItemStack item)
{
if (!Recharge.Instance.use(player, "Food Throw", FOOD_THROW_COOLDOWN, false, false))
return;
player.getWorld().playSound(player.getLocation(), Sound.EAT, 0.5F, 1.1F);
UtilInv.remove(player, item.getType(), item.getData().getData(), 1);
_itemSeperator++;
ItemStack toThrow = ItemStackFactory.Instance.CreateStack(item.getType(), item.getData().getData(), 1, Integer.toString(_itemSeperator));
double randomMultiply = UtilMath.random.nextDouble();
Item thrownItem = player.getWorld().dropItem(player.getEyeLocation().subtract(0, FOOD_THROW_EYE_LOCATION_HEIGHT_SUBTRACT, 0), toThrow);
thrownItem.setVelocity(player.getLocation().getDirection().normalize().multiply(randomMultiply));
growGrassTask(thrownItem);
checkForWinner(player);
}
private void growGrassTask(final Item item)
{
new BukkitRunnable()
{
@Override
public void run()
{
if (!isChallengeValid() || !item.isValid() || item.isDead())
{
cancel();
return;
}
if (item.isOnGround())
{
if (Math.random() < FOOD_THROW_CREATE_DIRT_CHANCE)
{
Location drop = item.getLocation();
Block block = drop.getBlock();
Block below = block.getRelative(BlockFace.DOWN);
if (UtilMath.random.nextBoolean())
{
if (!below.isEmpty())
{
setBlock(below, Material.DIRT);
if (UtilMath.random.nextBoolean())
{
setData(below, (byte) 1);
}
}
}
if (block.isEmpty() && !below.isEmpty())
{
Material flower = UtilMath.randomElement(FLOWERS);
setBlock(block, flower);
if (flower == Material.LONG_GRASS)
{
setData(block, (byte) (UtilMath.r(LONG_GRASS_DATA_RANGE) + 1));
}
else if (flower == Material.RED_ROSE)
{
setData(block, (byte) UtilMath.r(RED_ROSE_DATA_RANGE));
}
blockBreakEffect(block, false);
addBlock(block);
item.remove();
}
}
cancel();
}
}
}.runTaskTimer(Host.getArcadeManager().getPlugin(), 0L, 1L);
}
private void checkForWinner(Player player)
{
ArrayList<ItemStack> items = UtilInv.getItems(player);
if (items.size() == 0)
setCompleted(player);
}
}

View File

@ -0,0 +1,399 @@
package nautilus.game.arcade.game.games.mineware.challenge.type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Fish;
import org.bukkit.entity.FishHook;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTextBottom;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.recharge.Recharge;
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;
/**
* A challenge based on fishing.
*/
@SuppressWarnings("deprecation")
public class ChallengeFishingDay extends Challenge
{
private int _startingLureLevel = 8;
private Map<Player, Boolean> _fishing = new HashMap<>();
private Map<TNTPrimed, Player> _explosives = new HashMap<>();
public ChallengeFishingDay(BawkBawkBattles host)
{
super(
host,
ChallengeType.FirstComplete,
"Fishing Day",
"Be the first to catch 5 fish.",
"Watch out for TNT if you miss one!");
Settings.setUseMapHeight();
Settings.setLockInventory(0);
}
@Override
public ArrayList<Location> createSpawns()
{
int size = getArenaSize();
ArrayList<Location> spawns = new ArrayList<Location>();
for (int x = -(size); x <= size; x++)
{
for (int z = -(size); z <= size; z++)
{
double absX = Math.abs(x);
double absZ = Math.abs(z);
int platform = size - 2;
if ((absX == platform || absZ == platform) && !(absX > platform || absZ > platform))
{
spawns.add(getCenter().add(x, 6, z));
}
}
}
return spawns;
}
@Override
public void createMap()
{
int size = getArenaSize();
for (int x = -size; x <= size; x++)
{
for (int z = -size; z <= size; z++)
{
for (int y = 0; y < 8; y++)
{
Block block = getCenter().getBlock().getRelative(x, y, z);
double absX = Math.abs(x);
double absZ = Math.abs(z);
// Bottom Layer
if (y == 0)
{
setBlock(block, Material.BEDROCK);
}
// Ground Layer
else if (y == 1)
{
setBlock(block, Material.SAND);
}
else
{
if (y < 6)
{
// Fishing Platform
if ((absX >= size - 3 && absX <= size) || (absZ >= size - 3 && absZ <= size))
{
double chance = Math.random() * 100;
if (chance < 25)
{
setBlock(block, Material.GRAVEL);
}
else
{
if (y == 5)
{
setBlock(block, Material.GRASS);
Block above = block.getRelative(BlockFace.UP);
generateGrass(above);
addBlock(above);
}
else
{
setBlock(block, Material.DIRT);
}
}
}
// Water Container
else if (absX <= size - 4 || absZ <= size - 4)
{
setBlock(block, Material.WATER);
}
}
// Border Walls
else if (y > 4 && (absX == size || absZ == size))
{
setBlock(block, Material.FENCE);
}
}
addBlock(block);
}
}
}
}
@Override
public void onStart()
{
Host.DamageEvP = false;
Host.ItemPickup = true;
Host.WorldWaterDamage = 1;
ItemStack fishingRod = new ItemBuilder(Material.FISHING_ROD)
.addEnchantment(Enchantment.LURE, _startingLureLevel)
.setUnbreakable(true)
.addItemFlags(ItemFlag.HIDE_ENCHANTS, ItemFlag.HIDE_UNBREAKABLE)
.build();
setItem(Settings.getLockedSlot(), fishingRod);
}
@Override
public void onEnd()
{
Host.DamageEvP = false;
Host.ItemPickup = false;
Host.InventoryClick = false;
Host.WorldWaterDamage = 0;
remove(EntityType.PRIMED_TNT);
_fishing.clear();
_explosives.clear();
}
@EventHandler
public void onPlayerFish(PlayerFishEvent event)
{
if (!isChallengeValid())
return;
Player fisher = event.getPlayer();
if (!isPlayerValid(fisher))
return;
Fish hook = event.getHook();
if (!_fishing.containsKey(fisher))
{
_fishing.put(fisher, false);
}
else
{
if (!_fishing.get(fisher))
{
_fishing.put(fisher, true);
}
}
if (event.getCaught() != null)
{
Entity entity = event.getCaught();
ItemStack item = new ItemStack(Material.RAW_FISH, 1, (byte) UtilMath.r(3));
fisher.getInventory().addItem(item);
UtilTextBottom.display("You caught a " + C.cGreen + getFishType(item.getData().getData()) + C.cWhite + "!",
fisher);
fisher.playSound(fisher.getLocation(), Sound.ORB_PICKUP, 1.0F, 1.0F);
waterSplashEffect(fisher.getLocation().add(0, 0.5, 0), true, true);
event.setExpToDrop(0);
entity.remove();
_fishing.put(fisher, false);
checkForWinner(fisher);
}
else
{
if (isFishingHookEmpty(fisher, hook))
{
createExplosion(fisher, hook.getLocation());
}
}
}
@EventHandler
public void onEntityDamageByEntity(EntityDamageByEntityEvent event)
{
if (!isChallengeValid())
return;
if (event.getEntity() instanceof Player && event.getDamager() instanceof FishHook)
event.setCancelled(true);
}
@EventHandler
public void onPlayerMove(PlayerMoveEvent event)
{
if (!isChallengeValid())
return;
if (!isPlayerValid(event.getPlayer()))
return;
if (Math.random() * 100 < 20)
{
Player player = event.getPlayer();
Location from = event.getFrom();
Location to = event.getTo();
double fromX = from.getX();
double fromZ = from.getZ();
double toX = to.getX();
double toZ = to.getZ();
if (fromX != toX || fromZ != toZ)
{
waterSplashEffect(player.getLocation().add(0, 0.1, 0), false, false);
}
}
}
@EventHandler
public void onEntityExplode(EntityExplodeEvent event)
{
if (!isChallengeValid())
return;
Location dropsite = event.getLocation();
World world = dropsite.getWorld();
world.playSound(dropsite, Sound.ZOMBIE_WOODBREAK, 0.5F, 1.0F);
world.playSound(dropsite, Sound.EXPLODE, 1.0F, 1.0F);
UtilParticle.PlayParticle(ParticleType.CLOUD, dropsite, 0.6F, 0.6F, 0.6F, 0.0F, 50, ViewDist.NORMAL, UtilServer.getPlayers());
UtilParticle.PlayParticle(ParticleType.SMOKE, dropsite, 0.3F, 0.3F, 0.3F, 0.5F, 50, ViewDist.NORMAL, UtilServer.getPlayers());
Player target = _explosives.get(event.getEntity());
if (UtilMath.offset(dropsite, target.getLocation()) <= 6.0)
{
setLost(target);
}
event.setCancelled(true);
}
private String getFishType(byte data)
{
if (data == 1)
{
return "Salmon";
}
else if (data == 2)
{
return "Clownfish";
}
else if (data == 3)
{
return "Pufferfish";
}
else
{
return "Fish";
}
}
private void checkForWinner(Player fisher)
{
ArrayList<ItemStack> contents = UtilInv.getItems(fisher);
int caughtFish = 0;
for (ItemStack item : contents)
{
if (item.getType() == Material.RAW_FISH)
{
caughtFish = caughtFish + item.getAmount();
}
}
if (caughtFish == 5)
{
setCompleted(fisher);
}
}
private boolean isFishingHookEmpty(Player fisher, Fish hook)
{
// Check if the player is retracting the hook.
// Once hook is retracted, the entity is valid but not on ground.
Location droppedHook = hook.getLocation();
Block below = droppedHook.getBlock().getRelative(BlockFace.DOWN);
return _fishing.get(fisher) && hook.isValid() && !hook.isOnGround() && below.getType() == Material.STATIONARY_WATER;
}
private void createExplosion(Player target, Location dropsite)
{
if (Recharge.Instance.use(target, "TNT Spawn", 700, false, false))
{
World world = dropsite.getWorld();
target.playSound(dropsite, Sound.ZOMBIE_WOODBREAK, 0.3F, 1.3F);
TNTPrimed explosive = world.spawn(dropsite, TNTPrimed.class);
explosive.setFuseTicks(40);
explosive.setYield(0.0F);
UtilAction.velocity(explosive, UtilAlg.getTrajectory(dropsite, target.getLocation()), 1.2D, false, 0.0D,
0.3D, 0.6D, false);
_explosives.put(explosive, target);
}
}
private void waterSplashEffect(Location location, boolean randomAmount, boolean sound)
{
int amount = 5;
if (randomAmount)
amount += UtilMath.r(10);
UtilParticle.PlayParticle(ParticleType.WATER_WAKE, location, 0.2F, 0.1F, 0.2F, 0.0F, amount, ViewDist.NORMAL, UtilServer.getPlayers());
if (sound)
location.getWorld().playSound(location, Sound.WATER, 0.3F, 1.0F);
}
}

View File

@ -0,0 +1,178 @@
package nautilus.game.arcade.game.games.mineware.challenge.type;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerMoveEvent;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilMath;
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;
/**
* A challenge based on jumping.
*/
public class ChallengeKangarooJump extends Challenge
{
private static final int DURATION_RANDOM_ADD = 5;
private static final int DURATION_MIN = 20;
private static final int DURATION_MULTIPLIER = 1000;
private static final int MAP_SPAWN_SHIFT = 1;
private static final int SPAWN_COORDINATE_MULTIPLE = 2;
private static final int MAP_HEIGHT = 1;
private static final int MAP_OBSTACLE_HEIGHT = 150;
private static final byte DIRT_DATA = 2;
private static final int OBSTACLE_START_HEIGHT = 2;
private static final double OBSTACLE_SPAWN_CHANCE = 0.05;
private static final int OBSTACLE_COLOR_RANGE = 16;
private static final double JUMP_POWER = 2;
private static final double JUMP_HEIGHT = 0.4;
private static final double JUMP_HEIGHT_MAX = 4;
private static final int TOTAL_HEIGHTS_DIVIDER = 2;
public ChallengeKangarooJump(BawkBawkBattles host)
{
super(
host,
ChallengeType.FirstComplete,
"Kangaroo Jump",
"Jump from block to block.",
"Player with the highest height wins!");
Settings.setUseMapHeight();
Settings.hideTimerRanOutMessage();
Settings.setDuration((UtilMath.r(DURATION_RANDOM_ADD) + DURATION_MIN) * DURATION_MULTIPLIER);
}
@Override
public ArrayList<Location> createSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
int size = getArenaSize() - MAP_SPAWN_SHIFT;
for (int x = -(size); x <= size; x++)
{
for (int z = -(size); z <= size; z++)
{
if (x % SPAWN_COORDINATE_MULTIPLE == 0 && z % SPAWN_COORDINATE_MULTIPLE == 0)
{
spawns.add(getCenter().add(x, MAP_HEIGHT, z));
}
}
}
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 <= MAP_OBSTACLE_HEIGHT; y++)
{
Block block = getCenter().getBlock().getRelative(x, y, z);
if (y == 0)
{
setBlock(block, Material.DIRT, DIRT_DATA);
}
else if (y > OBSTACLE_START_HEIGHT)
{
if (Math.random() < OBSTACLE_SPAWN_CHANCE)
{
setBlock(block, Material.WOOL, (byte) UtilMath.r(OBSTACLE_COLOR_RANGE));
}
}
else
{
if (Math.abs(x) == getArenaSize() || Math.abs(z) == getArenaSize())
{
setBlock(block, Material.FENCE);
}
}
addBlock(block);
}
}
}
}
@SuppressWarnings("deprecation")
@EventHandler
public void onPlayerJump(PlayerMoveEvent event)
{
if (!isChallengeValid())
return;
if (event.getFrom().getY() >= event.getTo().getY())
return;
Player player = event.getPlayer();
if (!isPlayerValid(player) || !player.isOnGround())
return;
UtilAction.velocity(player, JUMP_POWER, JUMP_HEIGHT, JUMP_HEIGHT_MAX, true);
}
@Override
public void onTimerFinish()
{
Map<Player, Integer> heights = new HashMap<>();
for (Player player : getPlayersAlive())
{
heights.put(player, player.getLocation().getBlockY());
}
List<Player> sortedHeights = sortHash(heights);
int indexMiddle = (int) sortedHeights.size() / TOTAL_HEIGHTS_DIVIDER - 1;
for (int i = 0; i < (sortedHeights.size()); i++)
{
Player player = sortedHeights.get(i);
if (isPlayerValid(player) && i <= indexMiddle)
{
setCompleted(player);
}
}
}
private ArrayList<Player> sortHash(final Map<Player, Integer> unsortedMap)
{
ArrayList<Player> players = new ArrayList<Player>(unsortedMap.keySet());
Collections.sort(players, new Comparator<Player>()
{
@Override
public int compare(Player player1, Player player2)
{
Integer height1 = unsortedMap.get(player1);
Integer height2 = unsortedMap.get(player2);
return height2.compareTo(height1);
}
});
return players;
}
}

View File

@ -0,0 +1,234 @@
package nautilus.game.arcade.game.games.mineware.challenge.type;
import java.util.ArrayList;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilMath;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
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;
/**
* A challenge based on climbling ladders.
*/
public class ChallengeKingOfTheLadder extends Challenge
{
private static final int CHALLENGE_PLAYERS_MAX = 15;
private static final int LOCKED_INVENTORY_SLOT = 4;
private static final int MAP_SPAWN_SHIFT = 1;
private static final int MAP_HEIGHT = 1;
private static final int LADDER_HEIGHT = 20;
private static final byte LADDER_NORTH_DATA = 2;
private static final byte LADDER_SOUTH_DATA = 3;
private static final byte LADDER_WEST_DATA = 4;
private static final byte LADDER_EAST_DATA = 5;
// Coordinates relative to map center.
private static final int WIN_CORNER_A_X = 1;
private static final int WIN_CORNER_A_Y = 20;
private static final int WIN_CORNER_A_Z = -1;
private static final int WIN_CORNER_B_X = 0;
private static final int WIN_CORNER_B_Y = 23;
private static final int WIN_CORNER_B_Z = 1;
private static final int STICK_KNOCKBACK_LEVEL = 5;
private static final int PLAYER_MAX_HEALTH = 20;
private Location _winCornerA;
private Location _winCornerB;
public ChallengeKingOfTheLadder(BawkBawkBattles host)
{
super(
host,
ChallengeType.FirstComplete,
"King of the Ladder",
"Reach the top of the ladder.");
Settings.setUseMapHeight();
Settings.setMaxPlayers(CHALLENGE_PLAYERS_MAX);
Settings.setLockInventory(LOCKED_INVENTORY_SLOT);
}
@Override
public ArrayList<Location> createSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
int size = getArenaSize() - MAP_SPAWN_SHIFT;
for (int x = -(size); x <= size; x++)
{
for (int z = -(size); z <= size; z++)
{
if (Math.abs(x) == size || Math.abs(z) == size)
{
spawns.add(getCenter().add(x, MAP_HEIGHT, z));
}
}
}
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 <= MAP_HEIGHT; y++)
{
Block block = getCenter().getBlock().getRelative(x, y, z);
if (y == 0)
{
setBlock(block, Material.GRASS);
if (x == 0 && z == 0)
{
for (int h = 1; h <= LADDER_HEIGHT; h++)
{
Block ladder = getCenter().getBlock().getRelative(x, h, z);
setBlock(ladder, Material.STONE);
setBlock(ladder.getRelative(BlockFace.NORTH), Material.LADDER, LADDER_NORTH_DATA);
setBlock(ladder.getRelative(BlockFace.SOUTH), Material.LADDER, LADDER_SOUTH_DATA);
setBlock(ladder.getRelative(BlockFace.WEST), Material.LADDER, LADDER_WEST_DATA);
setBlock(ladder.getRelative(BlockFace.EAST), Material.LADDER, LADDER_EAST_DATA);
}
}
}
else
{
if (Math.abs(x) == getArenaSize() || Math.abs(z) == getArenaSize())
{
setBlock(block, Material.FENCE);
}
else if (x != 0 && z != 0)
{
generateGrass(block);
}
}
addBlock(block);
}
}
}
}
@Override
public void onStart()
{
Host.DamagePvP = true;
_winCornerA = getCenter().add(WIN_CORNER_A_X, WIN_CORNER_A_Y, WIN_CORNER_A_Z);
_winCornerB = getCenter().add(WIN_CORNER_B_X, WIN_CORNER_B_Y, WIN_CORNER_B_Z);
ItemStack stick = new ItemBuilder(Material.STICK)
.addEnchantment(Enchantment.KNOCKBACK, STICK_KNOCKBACK_LEVEL)
.addItemFlags(ItemFlag.HIDE_ENCHANTS)
.build();
setItem(Settings.getLockedSlot(), stick);
}
@SuppressWarnings("deprecation")
@Override
public void onEnd()
{
Host.DamagePvP = false;
for (int h = 1; h <= LADDER_HEIGHT; h++)
{
Block block = getCenter().getBlock().getRelative(0, h, 0);
Block north = block.getRelative(BlockFace.NORTH);
Block south = block.getRelative(BlockFace.SOUTH);
Block east = block.getRelative(BlockFace.EAST);
Block west = block.getRelative(BlockFace.WEST);
if (north.getType() == Material.LADDER && south.getType() == Material.LADDER && east.getType() == Material.LADDER && west.getType() == Material.LADDER)
{
resetBlock(north);
resetBlock(south);
resetBlock(east);
resetBlock(west);
}
if (UtilMath.random.nextBoolean())
{
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getTypeId());
}
resetBlock(block);
}
}
@EventHandler
public void onWinnerCheck(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
if (!isChallengeValid())
return;
for (Player player : getPlayersAlive())
{
if (UtilAlg.inBoundingBox(player.getLocation(), _winCornerA, _winCornerB))
{
setCompleted(player, true);
}
}
}
@EventHandler
public void onCustomDamage(CustomDamageEvent event)
{
if (!isChallengeValid())
return;
if (event.GetDamageePlayer() == null)
return;
if (!isPlayerValid(event.GetDamagerPlayer(false)))
{
event.SetCancelled("Player already completed");
return;
}
if (event.GetCause() == DamageCause.FALL)
{
event.SetCancelled("Fall damage");
}
}
@EventHandler
public void onResetPlayerHealth(UpdateEvent event)
{
if (event.getType() == UpdateType.SEC)
{
for (Player player : getPlayersAlive())
{
player.setHealth(PLAYER_MAX_HEALTH);
}
}
}
}

View File

@ -0,0 +1,298 @@
package nautilus.game.arcade.game.games.mineware.challenge.type;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockFromToEvent;
import mineplex.core.common.util.UtilMath;
import mineplex.core.disguise.disguises.DisguiseMagmaCube;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
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;
/**
* A challenge based on running.
*/
public class ChallengeLavaRun extends Challenge
{
private static final int CHALLENGE_PLAYERS_MAX = 30;
private static final int MAP_HEIGHT = 4;
private static final int MAP_SPAWN_HEIGHT = MAP_HEIGHT + 1;
private static final int MAP_SPAWN_SHIFT = 3;
private static final int DELAY_START = 2000; // milliseconds
private static final int DELAY_MIN = 1000; // milliseconds
private static final int DISSAPEARING_BLOCKS = 10;
private static final int OBSIDIAN_LARGE_DISTANCE = 4; // blocks
private static final int DELAY_BOOST = 300; // milliseconds
private static final int DELAY_SUBTRACT = 200; // milliseconds
private static final int DELAY_AFTER_DESTURCTION = 1500; // milliseconds
private static final float DESTRUCTION_SOUND_VOLUME = 2.0F;
private static final float DESTRUCTION_SOUND_PITCH = 1.0F;
private static final double DISTANCE_XZ_ADD = 0.5;
private int _arenaStartSize;
private Block _obsidian;
private Location _lastObsidianLocation;
private boolean _shouldMoveObsidian;
private List<Block> _platform;
private long _modifiedDelay;
private long _modifiedDelayMin;
private int _disappearingBlocks;
public ChallengeLavaRun(BawkBawkBattles host)
{
super(
host,
ChallengeType.LastStanding,
"Lava Run",
"The lava is coming!",
"Stand on the obsidian.",
"Run! Run! Run!");
Settings.setUseMapHeight();
Settings.setMaxPlayers(CHALLENGE_PLAYERS_MAX);
}
@Override
public ArrayList<Location> createSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
_arenaStartSize = getArenaSize();
int size = getArenaSize() - MAP_SPAWN_SHIFT;
for (int x = -size; x <= size; x++)
{
for (int z = -size; z <= size; z++)
{
spawns.add(getCenter().add(x, MAP_SPAWN_HEIGHT, z));
}
}
return spawns;
}
@Override
public void createMap()
{
generatePlatform();
}
@Override
public void onStart()
{
_obsidian = createObsidianBlock();
_modifiedDelay = System.currentTimeMillis() + DELAY_START;
_modifiedDelayMin = DELAY_MIN;
_disappearingBlocks = DISSAPEARING_BLOCKS;
createLava();
disguisePlayers();
}
@Override
public void onEnd()
{
_obsidian = null;
_lastObsidianLocation = null;
_shouldMoveObsidian = false;
_platform.clear();
_modifiedDelay = 0;
_modifiedDelayMin = 0;
_disappearingBlocks = 0;
}
@EventHandler
public void onUpdate(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
if (!isChallengeValid())
return;
if (_modifiedDelay > System.currentTimeMillis())
return;
if (_shouldMoveObsidian)
{
resetBlock(_obsidian);
generatePlatform();
_obsidian = createObsidianBlock();
blockBreakEffect(_obsidian, false);
playSound();
_modifiedDelay = System.currentTimeMillis();
if (UtilMath.offset2d(_obsidian.getLocation(), _lastObsidianLocation) > OBSIDIAN_LARGE_DISTANCE) // Add 1 second if the obsidian is too far.
{
_modifiedDelay += DELAY_BOOST;
}
if (_modifiedDelayMin > 0)
{
_modifiedDelayMin -= DELAY_SUBTRACT;
_modifiedDelay += _modifiedDelayMin;
}
System.out.println("Delay: " + _modifiedDelay);
_disappearingBlocks++;
_shouldMoveObsidian = false;
}
else
{
if (isPlatformEmpty())
{
_modifiedDelay = System.currentTimeMillis() + DELAY_AFTER_DESTURCTION;
_lastObsidianLocation = _obsidian.getLocation();
_shouldMoveObsidian = true;
}
else
{
destroyPlatform();
}
}
}
@EventHandler
public void onBlockFromTo(BlockFromToEvent event)
{
if (!isChallengeValid())
return;
event.setCancelled(true);
}
@EventHandler
public void onDamage(CustomDamageEvent event)
{
if (!isChallengeValid())
return;
if (!isPlayerValid(event.GetDamageePlayer()))
return;
if (event.GetDamagerEntity(true) != null)
return;
event.AddMod("Ensure Death", null, event.GetDamageePlayer().getHealth(), false);
}
private void generatePlatform()
{
_platform = new ArrayList<>();
for (int x = -getArenaSize(); x <= getArenaSize(); x++)
{
for (int z = -getArenaSize(); z <= getArenaSize(); z++)
{
Block block = getCenter().getBlock().getRelative(x, MAP_HEIGHT, z);
setBlock(block, Material.GLASS);
_platform.add(block);
addBlock(block);
}
}
}
private void createLava()
{
int size = getArenaSize() + MAP_SPAWN_SHIFT;
for (int x = -size; x <= size; x++)
{
for (int z = -size; z <= size; z++)
{
for (int y = 0; y < MAP_HEIGHT; y++)
{
Block block = getCenter().getBlock().getRelative(x, y, z);
setBlock(block, Material.STATIONARY_LAVA);
addBlock(block);
}
}
}
}
private Block createObsidianBlock()
{
Block block = getCenter().add(UtilMath.r(_arenaStartSize), MAP_HEIGHT, UtilMath.r(_arenaStartSize)).getBlock();
setBlock(block, Material.OBSIDIAN);
return block;
}
private void disguisePlayers()
{
for (Player player : getPlayersAlive())
{
DisguiseMagmaCube disguise = new DisguiseMagmaCube(player);
disguise.SetSize(1);
Host.getArcadeManager().GetDisguise().disguise(disguise);
}
}
private void playSound()
{
for (Player player : getPlayersAlive())
{
player.playSound(player.getLocation(), Sound.NOTE_PIANO, DESTRUCTION_SOUND_VOLUME, DESTRUCTION_SOUND_PITCH);
}
}
private boolean isPlatformEmpty()
{
int emptyBlocks = 0;
for (Block part : _platform)
{
if (part.isEmpty())
{
emptyBlocks++;
}
}
return emptyBlocks == _platform.size() - 1;
}
private void destroyPlatform()
{
HashMap<Block, Double> distance = new HashMap<Block, Double>();
for (Block part : _platform)
{
distance.put(part, part.getLocation().add(DISTANCE_XZ_ADD, 0, DISTANCE_XZ_ADD).distance(_obsidian.getLocation()));
}
Collections.sort(_platform, new Comparator<Block>()
{
@Override
public int compare(Block o1, Block o2)
{
return distance.get(o2).compareTo(distance.get(o1));
}
});
for (int i = 0; i < Math.min(_disappearingBlocks, _platform.size()); i++)
{
Block block = _platform.get(0);
if (!block.equals(_obsidian)) // We do not want to remove the obsidian block.
{
_platform.remove(0);
resetBlock(block);
}
}
}
}

View File

@ -0,0 +1,391 @@
package nautilus.game.arcade.game.games.mineware.challenge.type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.entity.Cow;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Villager;
import org.bukkit.entity.Villager.Profession;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilMath;
import mineplex.core.disguise.disguises.DisguiseVillager;
import mineplex.core.hologram.Hologram;
import mineplex.core.hologram.Hologram.HologramTarget;
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;
import nautilus.game.arcade.game.games.mineware.challenge.NumberTracker;
/**
* A challenge based on cow milking.
*/
public class ChallengeMilkACow extends Challenge implements NumberTracker
{
private static final int SCORE_GOAL = 5;
private static final int LOCKED_INVENTORY_SLOT = 4;
private static final int MAP_SPAWN_SHIFT = 1;
private static final int SPAWN_COORDINATE_MULTIPLE = 2;
private static final int MAP_HEIGHT = 1;
private static final double COW_NAMES_CHANCE = 0.3;
private static final int COW_SPAWN_AMOUNT = 7;
private static final int COW_SPAWN_LOCATION_MULTIPLIER = 2;
private static final float MILK_DELIVERY_SOUND_VOLUME = 2.0F;
private static final float MILK_DELIVERY_SOUND_PITCH = 0.0F;
private static final int SCORE_DISPLAY_HEIGHT_ADD = 2;
private static final double MILKED_HOLOGRAM_HEIGHT_ADD = 2.3;
private static final String[] HUMAN_NAMES = new String[] {
"Tom",
"Steve",
"John",
"Harry",
"Andrew",
"Daniel",
"Josh",
"Jim"
};
private static final String[] COW_NAMES = new String[] {
"Moosly",
"Mooington",
"Mooley",
"Moose",
"Mooskee",
"Chicken",
"Mooffy",
"Moozzle",
};
private Villager _farmer;
private Map<Cow, ArrayList<String>> _milkedCows = new HashMap<>();
private Map<Cow, Hologram> _milkedCowsHolograms = new HashMap<>();
private Map<Player, Integer> _score = new HashMap<>();
private boolean _aquaColor;
public ChallengeMilkACow(BawkBawkBattles host)
{
super(
host,
ChallengeType.FirstComplete,
"Milk a Cow",
"Milk " + SCORE_GOAL + " different cows.",
"Deliver the milk to the villager!");
Settings.setUseMapHeight();
Settings.setLockInventory(LOCKED_INVENTORY_SLOT);
}
@Override
public ArrayList<Location> createSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
int size = getArenaSize() - MAP_SPAWN_SHIFT;
for (int x = -(size); x <= size; x++)
{
for (int z = -(size); z <= size; z++)
{
if (x % SPAWN_COORDINATE_MULTIPLE == 0 && z % SPAWN_COORDINATE_MULTIPLE == 0)
{
spawns.add(getCenter().add(x, MAP_HEIGHT, z));
}
}
}
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 <= MAP_HEIGHT; y++)
{
Block block = getCenter().getBlock().getRelative(x, y, z);
if (y == 0)
{
setBlock(block, Material.GRASS);
}
else
{
if (Math.abs(x) == getArenaSize() || Math.abs(z) == getArenaSize())
{
setBlock(block, Material.FENCE);
}
else
{
generateGrass(block);
}
}
addBlock(block);
}
}
}
spawnCowsAndFarmer();
}
@Override
public void onStart()
{
for (Player player : getPlayersAlive())
{
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
public void onEnd()
{
for (Cow cow : _milkedCows.keySet())
{
Hologram hologram = _milkedCowsHolograms.get(cow);
hologram.stop();
cow.remove();
}
_farmer.remove();
_farmer = null;
_milkedCows.clear();
_milkedCowsHolograms.clear();
_score.clear();
_aquaColor = false;
}
@EventHandler
public void onEntityInteract(PlayerInteractEntityEvent event)
{
if (!isChallengeValid())
return;
Player player = event.getPlayer();
if (!isPlayerValid(player))
return;
if (!(event.getRightClicked() instanceof LivingEntity))
return;
ItemStack item = player.getItemInHand();
if (item == null)
return;
LivingEntity entity = (LivingEntity) event.getRightClicked();
if (item.getType() == Material.BUCKET && _milkedCows.containsKey(entity))
{
milkCow(player, entity);
event.setCancelled(true);
}
else if (item.getType() == Material.MILK_BUCKET && entity.equals(_farmer))
{
deliverMilk(player);
int score = incrementScore(player);
displayScore(entity, player, score);
checkCompletion(player, score);
event.setCancelled(true);
}
}
@EventHandler
public void onPlayerItemConsume(PlayerItemConsumeEvent event)
{
if (!isChallengeValid())
return;
Player player = event.getPlayer();
if (!isPlayerValid(player))
return;
event.setCancelled(true);
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event)
{
if (!isChallengeValid())
return;
Player player = event.getPlayer();
_score.remove(player);
}
private void spawnCowsAndFarmer()
{
Host.CreatureAllow = true;
spawnFarmerJoe();
String[] chosenNames = HUMAN_NAMES;
if (Math.random() < COW_NAMES_CHANCE)
{
chosenNames = COW_NAMES;
}
for (int i = 0; i <= COW_SPAWN_AMOUNT; i++)
{
spawnCow(chosenNames, i);
}
Host.CreatureAllow = false;
}
private void spawnFarmerJoe()
{
_farmer = (Villager) getCenter().getWorld().spawnEntity(getCenter().add(0, 1, 0), EntityType.VILLAGER);
_farmer.setProfession(Profession.FARMER);
_farmer.setCustomName(C.cGreen + C.Bold + "Farmer Joe");
_farmer.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);
_milkedCows.put(cow, new ArrayList<>());
Location milkedLocation = cow.getLocation().add(0, MILKED_HOLOGRAM_HEIGHT_ADD, 0).clone();
_milkedCowsHolograms.put(cow, new Hologram(Host.Manager.getHologramManager(), milkedLocation, C.cRed + "Already Milked"));
Hologram holo = _milkedCowsHolograms.get(cow);
holo.setHologramTarget(HologramTarget.WHITELIST);
holo.setFollowEntity(cow);
holo.start();
}
private Location getRandomLocation()
{
return getCenter().add(
UtilMath.r(((getArenaSize() * COW_SPAWN_LOCATION_MULTIPLIER) - 1) - (getArenaSize() - 1)),
1,
UtilMath.r((getArenaSize() * COW_SPAWN_LOCATION_MULTIPLIER) - 1) - (getArenaSize() - 1));
}
private void milkCow(Player player, LivingEntity entity)
{
ArrayList<String> usernames = _milkedCows.get(entity);
if (!usernames.contains(player.getName()))
{
new BukkitRunnable()
{
@Override
public void run()
{
if (!isChallengeValid())
{
cancel();
return;
}
player.setItemInHand(new ItemStack(Material.MILK_BUCKET));
}
}.runTaskLater(Host.Manager.getPlugin(), 1L);
_milkedCows.get(entity).add(player.getName());
displayMilkedIndicator(player, entity);
}
}
private void displayMilkedIndicator(Player player, Entity entity)
{
Hologram indicator = _milkedCowsHolograms.get(entity);
if (!indicator.containsPlayer(player))
{
indicator.addPlayer(player);
}
}
private void deliverMilk(Player player)
{
player.setItemInHand(new ItemStack(Material.BUCKET));
player.playSound(player.getLocation(), Sound.ORB_PICKUP, MILK_DELIVERY_SOUND_VOLUME, MILK_DELIVERY_SOUND_PITCH);
}
private int incrementScore(Player player)
{
int score = _score.get(player) + 1;
_score.put(player, score);
return score;
}
private void displayScore(LivingEntity entity, Player player, int score)
{
Location displayLoc = entity.getLocation().add(0, SCORE_DISPLAY_HEIGHT_ADD, 0).clone();
displayCount(player, displayLoc, selectScoreColor(score));
}
private String selectScoreColor(int score)
{
if (_aquaColor)
{
_aquaColor = false;
return C.cAquaB + score;
}
else
{
_aquaColor = true;
return C.cWhiteB + score;
}
}
private void checkCompletion(Player player, int score)
{
if (score >= SCORE_GOAL)
{
setCompleted(player);
}
}
@Override
public Number getData(Player player)
{
return _score.get(player);
}
@Override
public boolean hasData(Player player)
{
return _score.containsKey(player);
}
}

View File

@ -0,0 +1,438 @@
package nautilus.game.arcade.game.games.mineware.challenge.type;
import java.util.ArrayList;
import java.util.HashSet;
import org.bukkit.Color;
import org.bukkit.FireworkEffect.Type;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Minecart;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.vehicle.VehicleDamageEvent;
import org.bukkit.event.vehicle.VehicleEnterEvent;
import org.bukkit.scheduler.BukkitRunnable;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilFirework;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTextMiddle;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
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;
import net.minecraft.server.v1_8_R3.BlockPosition;
import net.minecraft.server.v1_8_R3.PacketPlayOutWorldEvent;
/**
* A challenge based on speed and minecarts.
*/
public class ChallengeMinecartDance extends Challenge
{
private static final int MAP_SIZE_MIN = 7;
private static final int MAP_SPAWN_SHIFT = 1;
private static final int SPAWN_COORDINATE_MULTIPLE = 2;
private static final int MAP_HEIGHT = 1;
private static final int WOOL_DATA_RANGE = 16;
private static final int RED_FIREWORKS_DELAY = 5500;
private static final int GREEN_FIREWORKS_AMOUNT = 2;
private static final int MUSIC_TRACK_DATA = 2259;
private static final int WORLD_EVENT = 1005;
private static final int MINECART_DIVIDER = 2;
private static final int MINECART_MULTIPLIER = 2;
private static final int MINECART_SPAWN_HEIGHT = 2;
private static final int PLAYER_AMOUNT_MODIFY_TIMER = 10;
private static final int TIMER_DIVIDER = 2;
private static final int TIMER_MIN = 5;
private static final int MINECARTS_LEFT_FADE_IN_TICKS = 0;
private static final int MINECARTS_LEFT_STAY_TICKS = 60;
private static final int MINECARTS_LEFT_FADE_OUT_TICKS = 20;
private static final int FIREWORK_SHIFT_X = 5;
private static final int FIREWORK_SPAWN_Y = 10;
private static final int FIREWORK_SHIFT_Z = 5;
private enum MinecartDancePhase
{
WAITING, STARTED, ENDED
}
private MinecartDancePhase _phase;
private long _timeSinceLastPhase;
private boolean _isPlayingMusic;
private int _availableMinecarts;
private HashSet<Minecart> _minecarts = new HashSet<Minecart>();
public ChallengeMinecartDance(BawkBawkBattles host)
{
super(
host,
ChallengeType.LastStanding,
"Musical Minecart",
"Get ready when the fireworks change color.",
"Once they're green, get inside a minecart!");
Settings.setUseMapHeight();
}
@Override
public ArrayList<Location> createSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
for (int x = -(getArenaSize(MAP_SIZE_MIN) - MAP_SPAWN_SHIFT); x <= getArenaSize(MAP_SIZE_MIN); x++)
{
for (int z = -(getArenaSize(MAP_SIZE_MIN) - MAP_SPAWN_SHIFT); z <= getArenaSize(MAP_SIZE_MIN); z++)
{
if (x % SPAWN_COORDINATE_MULTIPLE == 0 && z % SPAWN_COORDINATE_MULTIPLE == 0)
{
spawns.add(getCenter().add(x, MAP_HEIGHT, z));
}
}
}
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 <= MAP_HEIGHT; y++)
{
Block block = getCenter().getBlock().getRelative(x, y, z);
if (y == 0)
{
setBlock(block, Material.WOOL, (byte) UtilMath.r(WOOL_DATA_RANGE));
}
else
{
if (Math.abs(x) == getArenaSize() || Math.abs(z) == getArenaSize())
{
setBlock(block, Material.FENCE);
}
}
addBlock(block);
}
}
}
}
@Override
public void onStart()
{
_phase = MinecartDancePhase.WAITING;
Host.Manager.GetExplosion().SetLiquidDamage(false);
_timeSinceLastPhase = System.currentTimeMillis();
}
@Override
public void onEnd()
{
Host.Manager.GetExplosion().SetLiquidDamage(true);
if (_isPlayingMusic)
{
stopPlayingMusic();
}
for (Minecart minecarts : _minecarts)
{
minecarts.remove();
}
_timeSinceLastPhase = 0;
_availableMinecarts = 0;
_minecarts.clear();
}
@EventHandler
public void onUpdate(UpdateEvent event)
{
if (!isChallengeValid())
return;
if (_phase == MinecartDancePhase.WAITING && event.getType() == UpdateType.SEC)
{
if (!_isPlayingMusic)
{
startPlayingMusic();
}
spawnRedFireworks();
}
else if (_phase == MinecartDancePhase.STARTED)
{
spawnGreenFireworks();
if (_isPlayingMusic)
{
stopPlayingMusic();
}
spawnMinecarts();
_phase = MinecartDancePhase.ENDED;
startTimerWhenReady();
}
else if (_phase == MinecartDancePhase.ENDED)
{
showMinecartsLeft();
}
}
@EventHandler
public void onInteractionUpdate(UpdateEvent event)
{
if (event.getType() != UpdateType.FASTEST)
return;
if (!isChallengeValid())
return;
if (_phase == MinecartDancePhase.ENDED)
{
_availableMinecarts = getAvailableMinecarts();
if (_availableMinecarts == 0)
{
playersLooseIfOutsideMinecart();
_timeSinceLastPhase = System.currentTimeMillis();
_phase = MinecartDancePhase.WAITING;
removeAndClearMinecarts();
}
}
}
@EventHandler
public void onVehicleDamage(VehicleDamageEvent event)
{
if (!isChallengeValid())
return;
if (event.getVehicle() instanceof Minecart)
event.setCancelled(true);
}
@EventHandler
public void onVehicleInteract(VehicleEnterEvent event)
{
if (!isChallengeValid())
return;
if (!(event.getEntered() instanceof Player))
return;
Player player = (Player) event.getEntered();
if (Data.isLost(player) || !Host.IsPlaying(player))
{
event.setCancelled(true);
}
}
private int getAvailableMinecarts()
{
int count = 0;
for (Minecart minecart : _minecarts)
{
if (!minecart.isEmpty())
{
continue;
}
else
{
count++;
}
}
return count;
}
private void playersLooseIfOutsideMinecart()
{
for (Player player : getPlayersIn(true))
{
if (!player.isInsideVehicle())
{
setLost(player);
Host.WorldData.World.strikeLightningEffect(player.getLocation());
}
}
}
private void removeAndClearMinecarts()
{
for (Minecart minecart : _minecarts)
{
if (!minecart.isEmpty())
{
minecart.eject();
}
minecart.remove();
}
_minecarts.clear();
}
private void startPlayingMusic()
{
_isPlayingMusic = true;
PacketPlayOutWorldEvent packet = new PacketPlayOutWorldEvent(WORLD_EVENT, new BlockPosition(getCenter().getBlockX(), getCenter().getBlockY() + 5, getCenter().getBlockZ()), MUSIC_TRACK_DATA, false);
for (Player player : UtilServer.getPlayers())
{
UtilPlayer.sendPacket(player, packet);
}
}
private void spawnRedFireworks()
{
if (_timeSinceLastPhase + RED_FIREWORKS_DELAY < System.currentTimeMillis())
{
if (UtilMath.r(4) == 0)
{
_phase = MinecartDancePhase.STARTED;
}
else
{
spawnFireworkAtCorners(Color.RED);
}
}
else
{
spawnFireworkAtCorners(Color.RED);
}
}
private void spawnGreenFireworks()
{
new BukkitRunnable()
{
@Override
public void run()
{
for (int i = 0; i <= GREEN_FIREWORKS_AMOUNT; i++)
{
spawnFireworkAtCorners(Color.GREEN);
}
}
}.runTaskLater(Host.Manager.getPlugin(), 0);
}
private void stopPlayingMusic()
{
_isPlayingMusic = false;
PacketPlayOutWorldEvent packet = new PacketPlayOutWorldEvent(WORLD_EVENT, new BlockPosition(getCenter().getBlockX(), getCenter().getBlockY() + 5, getCenter().getBlockZ()), 0, false);
for (Player player : UtilServer.getPlayers())
{
UtilPlayer.sendPacket(player, packet);
}
}
private void spawnMinecarts()
{
for (int i = 0; i < Math.round(getPlayersIn(true).size() / MINECART_DIVIDER); i++)
{
Minecart minecart = Host.WorldData.World.spawn(getCenter().add(UtilMath.r(getArenaSize(MAP_SIZE_MIN) * MINECART_MULTIPLIER) - (getArenaSize(MAP_SIZE_MIN)), MINECART_SPAWN_HEIGHT, UtilMath.r(getArenaSize(MAP_SIZE_MIN) * MINECART_MULTIPLIER) - (getArenaSize(MAP_SIZE_MIN))),
Minecart.class);
UtilEnt.ghost(minecart, true, false);
_minecarts.add(minecart);
}
}
private void startTimerWhenReady()
{
if (getPlayersIn(true).size() >= PLAYER_AMOUNT_MODIFY_TIMER)
{
startTimer(Math.round(getPlayersIn(true).size() / TIMER_DIVIDER));
}
else
{
startTimer(TIMER_MIN);
}
}
private void showMinecartsLeft()
{
new BukkitRunnable()
{
@Override
public void run()
{
if (_phase != MinecartDancePhase.ENDED || !isChallengeValid())
{
this.cancel();
}
int minecarts = 0;
for (Minecart minecart : _minecarts)
{
if (!minecart.isEmpty())
{
minecarts++;
}
}
UtilTextMiddle.display(C.cRed + (_minecarts.size() - minecarts), "Minecarts Left!", MINECARTS_LEFT_FADE_IN_TICKS, MINECARTS_LEFT_STAY_TICKS, MINECARTS_LEFT_FADE_OUT_TICKS);
}
}.runTaskLater(Host.Manager.getPlugin(), 0);
}
private void startTimer(long ticks)
{
new BukkitRunnable()
{
@Override
public void run()
{
if (_phase == MinecartDancePhase.ENDED)
{
playersLooseIfOutsideMinecart();
_timeSinceLastPhase = System.currentTimeMillis();
_phase = MinecartDancePhase.WAITING;
removeAndClearMinecarts();
}
else
{
this.cancel();
}
}
}.runTaskLater(Host.Manager.getPlugin(), ticks * TICK_MULTIPLIER);
}
private void spawnFireworkAtCorners(Color color)
{
UtilFirework.playFirework(getCenter().add(getArenaSize() + FIREWORK_SHIFT_X, FIREWORK_SPAWN_Y, getArenaSize() + FIREWORK_SHIFT_Z), Type.BALL_LARGE, color, false, false);
UtilFirework.playFirework(getCenter().add(-getArenaSize() - FIREWORK_SHIFT_X, FIREWORK_SPAWN_Y, getArenaSize() + FIREWORK_SHIFT_Z), Type.BALL_LARGE, color, false, false);
UtilFirework.playFirework(getCenter().add(getArenaSize() + FIREWORK_SHIFT_X, FIREWORK_SPAWN_Y, -getArenaSize() - FIREWORK_SHIFT_Z), Type.BALL_LARGE, color, false, false);
UtilFirework.playFirework(getCenter().add(-getArenaSize() - FIREWORK_SHIFT_X, FIREWORK_SPAWN_Y, -getArenaSize() - FIREWORK_SHIFT_Z), Type.BALL_LARGE, color, false, false);
}
}

View File

@ -0,0 +1,290 @@
package nautilus.game.arcade.game.games.mineware.challenge.type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
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.Arrow;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilMath;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
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;
import nautilus.game.arcade.game.games.mineware.challenge.NumberTracker;
/**
* A challenge based in one in the quiver.
*/
public class ChallengeMiniOneInTheQuiver extends Challenge implements NumberTracker
{
private static final int LOCKED_INVENTORY_SLOT = 0;
private static final int MAP_SPAWN_SHIFT = 1;
private static final int SPAWN_COORDINATE_MULTIPLE = 2;
private static final int MAP_HEIGHT = 1;
private static final int MAP_BARRIER_SHIFT_1 = 2;
private static final int MAP_BARRIER_SHIFT_2 = 4;
private static final int MAP_BARRIER_SPAWN_CHANCE_RANGE = 8;
private static final Material BARRIER_MATERIAL = Material.STAINED_CLAY;
private static final byte BARRIER_DATA = 14;
private Map<Player, Integer> _killTracker = new HashMap<Player, Integer>();
public ChallengeMiniOneInTheQuiver(BawkBawkBattles host)
{
super(
host,
ChallengeType.LastStanding,
"Mini OITQ",
"Shoot arrows to instant kill others.",
"Avoid getting hit by them.",
"Arrow supply every 4 seconds.");
Settings.setUseMapHeight();
Settings.setCanCruble();
Settings.setLockInventory(LOCKED_INVENTORY_SLOT);
}
@Override
public ArrayList<Location> createSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
int size = getArenaSize() - MAP_SPAWN_SHIFT;
for (int x = -(size); x <= size; x++)
{
for (int z = -(size); z <= size; z++)
{
if (x % SPAWN_COORDINATE_MULTIPLE == 0 && z % SPAWN_COORDINATE_MULTIPLE == 0)
{
spawns.add(getCenter().add(x, MAP_HEIGHT, z));
}
}
}
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 <= MAP_HEIGHT; y++)
{
Block block = getCenter().getBlock().getRelative(x, y, z);
int absX = Math.abs(x);
int absZ = Math.abs(z);
if (y == 0)
{
setBlock(block, Material.GRASS);
}
else
{
if (absX == getArenaSize() || absZ == getArenaSize())
{
setBlock(block, Material.FENCE);
}
else if (absX <= getArenaSize() - 1 || absZ <= getArenaSize() - 1)
{
if (((absX == getArenaSize() - MAP_BARRIER_SHIFT_1 || absZ == getArenaSize() - MAP_BARRIER_SHIFT_1) || (absX == getArenaSize() - MAP_BARRIER_SHIFT_2 || absZ == getArenaSize() - MAP_BARRIER_SHIFT_2)) && UtilMath.r(MAP_BARRIER_SPAWN_CHANCE_RANGE) == 0
&& canPlaceBarrier(block.getRelative(BlockFace.UP)) && !Data.isSpawnLocation(block.getLocation()))
{
generateBarrier(block);
}
else
{
generateGrass(block);
}
}
}
addBlock(block.getRelative(BlockFace.UP));
addBlock(block);
}
}
}
}
@Override
public void onStart()
{
Host.DamagePvP = true;
Host.DamagePvE = true;
ItemStack bow = new ItemBuilder(Material.BOW)
.setUnbreakable(true)
.setItemFlags(ItemFlag.HIDE_UNBREAKABLE)
.build();
addItem(bow, new ItemStack(Material.ARROW));
for (Player player : getPlayersAlive())
{
_killTracker.put(player, 0);
}
}
@Override
public void onEnd()
{
Host.DamagePvP = false;
Host.DamagePvE = false;
_killTracker.clear();
remove(EntityType.ARROW);
}
@EventHandler
public void onProjectileHit(ProjectileHitEvent event)
{
if (!isChallengeValid())
return;
Projectile entity = event.getEntity();
if (entity instanceof Arrow)
{
entity.remove();
}
}
@EventHandler
public void onArrowEquipUpdate(UpdateEvent event)
{
if (event.getType() != UpdateType.SLOW)
return;
if (!isChallengeValid())
return;
for (Player player : getPlayersIn(true))
{
if (UtilInv.contains(player, Material.ARROW, (byte) 0, 1))
continue;
player.getInventory().addItem(new ItemStack(Material.ARROW));
player.playSound(player.getLocation(), Sound.ITEM_PICKUP, 1.0F, 1.0F);
}
}
@EventHandler
public void onEntityDamageByEntity(EntityDamageByEntityEvent event)
{
if (!isChallengeValid())
return;
if (!(event.getDamager() instanceof Arrow))
return;
if (!(event.getEntity() instanceof Player))
return;
Arrow arrow = (Arrow) event.getDamager();
Player shooter = (Player) arrow.getShooter();
Player damaged = (Player) event.getEntity();
if (Data.isLost(shooter) || !Host.IsPlaying(shooter) || shooter.equals(damaged))
{
event.setCancelled(true);
return;
}
damaged.setHealth(1);
event.setDamage(event.getDamage());
}
@EventHandler
public void onPlayerDeath(PlayerDeathEvent event)
{
if (!isChallengeValid())
return;
Player victim = event.getEntity();
Player killer = victim.getKiller();
if (killer != null && isPlayerValid(killer) && _killTracker.containsKey(killer))
{
_killTracker.put(killer, _killTracker.get(killer) + 1);
}
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event)
{
if (!isChallengeValid())
return;
Player player = event.getPlayer();
if (_killTracker.containsKey(player))
{
_killTracker.remove(player);
}
}
private boolean canPlaceBarrier(Block block)
{
Block[] relatives = {
block.getRelative(BlockFace.NORTH_EAST),
block.getRelative(BlockFace.NORTH_WEST),
block.getRelative(BlockFace.SOUTH_EAST),
block.getRelative(BlockFace.SOUTH_WEST)
};
boolean foundOtherBarrier = false;
for (Block relative : relatives)
{
if (relative.getType() == Material.STAINED_CLAY)
{
foundOtherBarrier = true;
break;
}
}
return !foundOtherBarrier;
}
private void generateBarrier(Block block)
{
setBlock(block, BARRIER_MATERIAL, BARRIER_DATA);
setBlock(block.getRelative(BlockFace.UP), BARRIER_MATERIAL, BARRIER_DATA);
}
@Override
public Number getData(Player player)
{
return _killTracker.get(player);
}
@Override
public boolean hasData(Player player)
{
return _killTracker.containsKey(player);
}
}

View File

@ -0,0 +1,283 @@
package nautilus.game.arcade.game.games.mineware.challenge.type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
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;
import nautilus.game.arcade.game.games.mineware.challenge.NumberTracker;
/**
* A challenge based on mazes.
*/
public class ChallengeNavigationMaze extends Challenge implements NumberTracker
{
private Map<Player, Long> _completionTime = new HashMap<>();
public ChallengeNavigationMaze(BawkBawkBattles host)
{
super(
host,
ChallengeType.FirstComplete,
"Nagivation Maze",
"Go to the other side of the maze.");
Settings.setUseMapHeight();
}
@Override
public ArrayList<Location> createSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
for (int z = -9; z <= 12; z++)
{
spawns.add(getCenter().add(-15, 1, z));
}
return spawns;
}
@Override
public void createMap()
{
for (int x = -18; x <= 21; x++)
{
for (int z = -12; z <= 15; z++)
{
Block block = getCenter().getBlock().getRelative(x, 0, z);
if (z == -12 || z == 15)
{
for (int y = 1; y <= 3; y++)
{
Block relativeBlock = block.getRelative(0, y, 0);
setBlock(relativeBlock, Material.STONE, (byte) 0);
addBlock(relativeBlock);
}
}
if (x > 15 || x < -12)
{
setBlock(block, Material.WOOL, (byte) (x < 0 ? 14 : 13));
}
else
{
setBlock(block, Material.STONE);
Block relativeBlock = block.getRelative(0, 4, 0);
if (relativeBlock.getX() == -13 || relativeBlock.getX() == 14)
{
setBlock(relativeBlock, Material.STONE, (byte) 0);
}
else
{
setBlock(relativeBlock, Material.STAINED_GLASS, (byte) 8);
}
addBlock(relativeBlock);
}
addBlock(block);
}
}
ArrayList<Block> mazeBlocks = generateMaze();
for (Block mazeBlock : mazeBlocks)
{
addBlock(mazeBlock);
}
// for (int i = 0; i < 30; i++)
// {
// ArrayList<Block> mazeBlocks = generateMaze();
//
// if (isMazeValid())
// {
// for (Block mazeBlock : mazeBlocks)
// {
// addBlock(mazeBlock);
// }
//
// break;
// }
// else
// {
// System.out.print("Generated bad maze, trying again..");
//
// for (Block mazeBlock : mazeBlocks)
// {
// mazeBlock.setTypeIdAndData(Material.AIR.getId(), (byte) 0, false);
// }
// }
// }
}
@Override
public void onEnd()
{
_completionTime.clear();
}
@EventHandler
public void onPlayerMove(PlayerMoveEvent event)
{
if (!isChallengeValid())
return;
Player player = event.getPlayer();
if (!isPlayerValid(player))
return;
if (event.getTo().getY() >= getCenter().getY() + 1 && event.getTo().getX() > getCenter().getX() + 15)
{
setCompleted(player);
_completionTime.put(player, System.currentTimeMillis());
}
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event)
{
if (!isChallengeValid())
return;
Player player = event.getPlayer();
if (_completionTime.containsKey(player))
{
_completionTime.remove(player);
}
}
private boolean isMazeValid()
{
ArrayList<Block> blocks = new ArrayList<Block>();
ArrayList<Block> nextLoop = new ArrayList<Block>();
nextLoop.add(getCenter().getBlock().getRelative(-15, 1, 0));
blocks.addAll(nextLoop);
while (!nextLoop.isEmpty())
{
Block block = nextLoop.remove(0);
for (BlockFace face : new BlockFace[] { BlockFace.EAST, BlockFace.WEST, BlockFace.SOUTH, BlockFace.NORTH })
{
Block b = block.getRelative(face);
if (blocks.contains(b))
{
continue;
}
blocks.add(b);
if (b.getType() == Material.STONE || b.getX() < getCenter().getX() + -14 || b.getZ() < getCenter().getZ() + -12 || b.getZ() > getCenter().getZ() + 15)
{
continue;
}
if (b.getX() >= getCenter().getX() + 15)
{
return true;
}
nextLoop.add(b);
}
}
return false;
}
@SuppressWarnings("deprecation")
private ArrayList<Block> generateMaze()
{
ArrayList<Block> blocks = new ArrayList<Block>();
int[][] maze = new MazeGenerator(11, 10).getMaze();
for (int x = 1; x < 11; x++)
{
for (int z = 1; z < 10; z++)
{
Block b = getCenter().getBlock().getRelative((x - 5) * 3, 1, (z - 5) * 3);
for (int y = 0; y < 3; y++)
{
Block block = b.getRelative(0, y, 0);
if (block.getType() == Material.STONE)
continue;
setBlock(block, Material.STONE);
blocks.add(block);
}
if (x < 10 && (maze[x][z] & 8) == 0)
{
for (int i = 1; i <= 2; i++)
{
for (int y = 0; y < 3; y++)
{
Block block = b.getRelative(i, y, 0);
if (block.getType() == Material.STONE)
continue;
setBlock(block, Material.STONE);
blocks.add(block);
}
}
}
if ((maze[x][z] & 1) == 0)
{
for (int i = 1; i <= 2; i++)
{
for (int y = 0; y < 3; y++)
{
Block block = b.getRelative(0, y, i);
if (block.getType() == Material.STONE)
continue;
setBlock(block, Material.STONE);
blocks.add(block);
}
}
}
}
}
return blocks;
}
@Override
public Number getData(Player player)
{
return _completionTime.get(player);
}
@Override
public boolean hasData(Player player)
{
return _completionTime.containsKey(player);
}
}

View File

@ -0,0 +1,219 @@
package nautilus.game.arcade.game.games.mineware.challenge.type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
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.ItemFlag;
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;
/**
* A challenge based on finding and mining diamond ores.
*/
public class ChallengeOreRun extends Challenge
{
private static final int LOCKED_INVENTORY_SLOT = 4;
private static final int MAP_SPAWN_SHIFT = 1;
private static final int MAP_HEIGHT = 2;
private static final int SPAWN_COORDINATE_MULTIPLE = 2;
private static final byte DIRT_DATA = 2;
private static final int DIAMOND_AMOUNT_DIVIDER = 2;
private static final int DIAMOND_SPAWN_MULTIPLIER = 2;
private static final int BOTTOM_LEVEL = 0;
private static final int ORE_LEVEL = 1;
private static final int FENCE_LEVEL = 2;
private static final List<Material> ORES = new ArrayList<>(Arrays.asList(
Material.COAL_ORE,
Material.IRON_ORE,
Material.GOLD_ORE,
Material.EMERALD_ORE,
Material.REDSTONE_ORE,
Material.LAPIS_ORE));
private List<Block> _diamonds = new ArrayList<>();
public ChallengeOreRun(BawkBawkBattles host)
{
super(
host,
ChallengeType.FirstComplete,
"Ore Run",
"Find and mine a diamond around the map.");
Settings.setUseMapHeight();
Settings.setLockInventory(LOCKED_INVENTORY_SLOT);
}
@Override
public ArrayList<Location> createSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
for (int x = -getArenaSize() + MAP_SPAWN_SHIFT; x <= getArenaSize() - MAP_SPAWN_SHIFT; x++)
{
for (int z = -getArenaSize() + MAP_SPAWN_SHIFT; z <= getArenaSize() - MAP_SPAWN_SHIFT; z++)
{
if (x % SPAWN_COORDINATE_MULTIPLE == 0 && z % SPAWN_COORDINATE_MULTIPLE == 0)
{
spawns.add(getCenter().add(x, MAP_HEIGHT, z));
}
}
}
return spawns;
}
@Override
public void createMap()
{
int amountOfDiamonds = 0;
for (int x = -getArenaSize(); x <= getArenaSize(); x++)
{
for (int z = -getArenaSize(); z <= getArenaSize(); z++)
{
for (int y = 0; y <= MAP_HEIGHT; y++)
{
double absX = Math.abs(x);
double absZ = Math.abs(z);
Block block = getCenter().getBlock().getRelative(x, y, z);
if (y == BOTTOM_LEVEL)
{
setBlock(block, Material.DIRT, DIRT_DATA);
}
else if (y == ORE_LEVEL)
{
if (absX == getArenaSize() || absZ == getArenaSize())
{
if (UtilMath.random.nextBoolean())
{
setBlock(block, Material.STONE);
}
else
{
setBlock(block, Material.COBBLESTONE);
}
}
else
{
if (amountOfDiamonds == 0)
{
for (int i = 0; i < Math.ceil((Host.getPlayersWithRemainingLives() + 1) / DIAMOND_AMOUNT_DIVIDER); i++)
{
Block copy = getCenter().getBlock().getRelative(UtilMath.r(getArenaSize() * DIAMOND_SPAWN_MULTIPLIER) - (getArenaSize()), 1, UtilMath.r(getArenaSize() * DIAMOND_SPAWN_MULTIPLIER) - (getArenaSize()));
if (copy.getType() == Material.DIAMOND_ORE && Math.abs(copy.getX()) < getArenaSize() && Math.abs(copy.getY()) < getArenaSize())
{
i--;
continue;
}
_diamonds.add(copy);
addBlock(copy);
amountOfDiamonds++;
}
}
if (block.getType() != Material.DIAMOND_ORE)
{
setBlock(block, UtilMath.randomElement(ORES));
}
}
}
else if (y == FENCE_LEVEL && (absX == getArenaSize() || absZ == getArenaSize()))
{
setBlock(block, Material.FENCE);
}
addBlock(block);
}
}
}
}
@Override
public void onStart()
{
ItemStack pickaxe = new ItemBuilder(Material.DIAMOND_PICKAXE)
.setUnbreakable(true)
.setItemFlags(ItemFlag.HIDE_UNBREAKABLE)
.build();
setItem(Settings.getLockedSlot(), pickaxe);
for (Block diamond : _diamonds)
{
setBlock(diamond, Material.DIAMOND_ORE);
}
Host.BlockBreak = true;
}
@Override
public void onEnd()
{
Host.BlockBreak = false;
_diamonds.clear();
}
@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)
{
Block block = event.getClickedBlock();
if (block == null)
return;
if (block.getType() == Material.DIAMOND_ORE)
{
setCompleted(player, true);
resetBlock(block);
}
}
}
@EventHandler
public void onBlockBreak(BlockBreakEvent event)
{
if (!isChallengeValid())
return;
if (event.getBlock().getType() != Material.DIAMOND_ORE)
event.setCancelled(true);
}
}

View File

@ -0,0 +1,284 @@
package nautilus.game.arcade.game.games.mineware.challenge.type;
import java.util.ArrayList;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilTextMiddle;
import nautilus.game.arcade.game.games.mineware.BawkBawkBattles;
import nautilus.game.arcade.game.games.mineware.challenge.ChallengeType;
import nautilus.game.arcade.game.games.mineware.challenge.TeamChallenge;
/**
* A team based challenge where the side with the fewest players wins.
*/
public class ChallengePickASide extends TeamChallenge
{
private static final int CHALLENGE_PLAYERS_MIN = 3;
private static final int MAP_SPAWN_SHIFT = 1;
private static final int MAP_HEIGHT = 2;
private static final int MAP_SPAWN_HEIGHT = MAP_HEIGHT - 1;
private static final int MAP_X_START = -10;
private static final int MAP_X_STOP = 10;
private static final int MAP_SPAWN_X_START = MAP_X_START + 2;
private static final int MAP_SPAWN_X_STOP = MAP_X_STOP - 2;
private static final byte BLUE_STAINED_CLAY = 11;
private static final byte RED_STAINED_CLAY = 14;
private static final int COUNTER = 5;
private static final long COUNTDOWN_PREPARE_TICKS = 30L;
private static final long COUNTDOWN_START_TICKS = 80L;
private static final long COUNTDOWN_UPDATE_TICKS = 20L;
private static final float COUNTER_SOUND_VOLUME = 1.0F;
private static final float COUNTER_SOUND_PITCH = 1.5F;
private static final int COUNTER_COLOR_1 = 3;
private static final int COUNTER_COLOR_2 = 2;
private static final int COUNTER_COLOR_3 = 1;
private int _counter;
public ChallengePickASide(BawkBawkBattles host)
{
super(
host,
ChallengeType.FirstComplete,
"Blue",
"Red",
"Pick a Side",
"Choose one of the two sides.",
"The side with the fewest players wins.");
Settings.setMinPlayers(CHALLENGE_PLAYERS_MIN);
Settings.setUseMapHeight();
Settings.setTeamBased();
}
@Override
public ArrayList<Location> createSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
int size = getArenaSize() - MAP_SPAWN_SHIFT;
for (int x = MAP_SPAWN_X_START; x <= MAP_SPAWN_X_STOP; x++)
{
for (int z = -size; z <= size; z++)
{
if (x % 2 == 0 && z % 2 == 0)
{
spawns.add(getCenter().add(x, MAP_SPAWN_HEIGHT, z));
}
}
}
return spawns;
}
@Override
public void createMap()
{
for (int x = MAP_X_START; x <= MAP_X_STOP; x++)
{
for (int z = -getArenaSize(); z <= getArenaSize(); z++)
{
for (int y = 0; y <= MAP_HEIGHT; y++)
{
Block block = getCenter().getBlock().getRelative(x, y, z);
if (y == 0 || Math.abs(x) == MAP_X_STOP || Math.abs(z) == getArenaSize())
{
if (y > 0 && Math.abs(z) != getArenaSize())
continue;
setBlock(block, Material.STAINED_CLAY, (byte) (z < 0 ? BLUE_STAINED_CLAY : RED_STAINED_CLAY));
addBlock(block);
}
}
}
}
}
@Override
public void onStart()
{
_counter = COUNTER;
startMessageTask();
startCountdownTask();
}
private void startMessageTask()
{
new BukkitRunnable()
{
@Override
public void run()
{
if (!isChallengeValid())
{
cancel();
return;
}
for (Player player : getPlayersAlive())
{
alert(player, "Prepare to choose your side.");
}
}
}.runTaskLater(Host.Manager.getPlugin(), COUNTDOWN_PREPARE_TICKS);
}
private void startCountdownTask()
{
new BukkitRunnable()
{
@Override
public void run()
{
if (!isChallengeValid())
{
cancel();
return;
}
startCounterTask();
}
}.runTaskLater(Host.Manager.getPlugin(), COUNTDOWN_START_TICKS);
}
private void startCounterTask()
{
new BukkitRunnable()
{
@Override
public void run()
{
if (!isChallengeValid())
{
cancel();
return;
}
if (_counter > 0)
{
displayCounter();
}
else
{
cancel();
return;
}
_counter--;
}
}.runTaskTimer(Host.Manager.getPlugin(), 0L, COUNTDOWN_UPDATE_TICKS);
}
private void displayCounter()
{
for (Player player : getPlayersAlive())
{
UtilTextMiddle.display(C.Bold + formattedCounter(), null, player);
player.playSound(player.getLocation(), Sound.CHICKEN_EGG_POP, COUNTER_SOUND_VOLUME, COUNTER_SOUND_PITCH);
}
}
private String formattedCounter()
{
if (_counter == COUNTER_COLOR_1)
return C.cGreen + _counter;
else if (_counter == COUNTER_COLOR_2)
return C.cGold + _counter;
else if (_counter == COUNTER_COLOR_3)
return C.cRed + _counter;
else
return C.cWhite + _counter;
}
@Override
public boolean canFinish()
{
if (_counter <= 0)
{
determineSideSize();
if (getFirstTeam().getSize() < getSecondTeam().getSize())
{
selectBlueAsWinners();
}
else if (getFirstTeam().getSize() > getSecondTeam().getSize())
{
selectRedAsWinners();
}
else
{
if (UtilMath.random.nextBoolean())
{
selectRedAsWinners();
}
else
{
selectBlueAsWinners();
}
}
return true;
}
else
{
return false;
}
}
private void determineSideSize()
{
for (Player player : getPlayersAlive())
{
double z = player.getLocation().getZ();
if (z < 10)
{
getFirstTeam().add(player);
}
else
{
getSecondTeam().add(player);
}
}
}
private void selectBlueAsWinners()
{
for (Player bluePlayer : getFirstTeam().getPlayers())
{
setCompleted(bluePlayer);
}
for (Player redPlayer : getSecondTeam().getPlayers())
{
setLost(redPlayer);
}
}
private void selectRedAsWinners()
{
for (Player redPlayer : getSecondTeam().getPlayers())
{
setCompleted(redPlayer);
}
for (Player bluePlayer : getFirstTeam().getPlayers())
{
setLost(bluePlayer);
}
}
}

View File

@ -0,0 +1,244 @@
package nautilus.game.arcade.game.games.mineware.challenge.type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Pig;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.common.util.UtilServer;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
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;
/**
* A challenge based on killing pigs to increase the score.
*/
public class ChallengePunchThePig extends Challenge
{
private int _goal = 5;
private Set<Pig> _pigs = new HashSet<>();
private Map<Player, Integer> _score = new HashMap<>();
public ChallengePunchThePig(BawkBawkBattles host)
{
super(
host,
ChallengeType.FirstComplete,
"Punch the Pig",
"Punch 5 pigs.");
Settings.setUseMapHeight();
}
@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, 1, z));
}
}
}
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)
{
if (UtilMath.random.nextDouble() * 100 < 20)
{
setBlock(block, Material.DIRT);
if (UtilMath.random.nextBoolean())
{
setData(block, (byte) 1);
}
}
else
{
setBlock(block, Material.GRASS);
}
}
else
{
if (Math.abs(x) == getArenaSize() || Math.abs(z) == getArenaSize())
{
setBlock(block, Material.FENCE);
}
else
{
generateGrass(block);
}
}
addBlock(block);
}
}
}
}
@Override
public void onStart()
{
Host.DamagePvE = true;
spawnPigs();
initializeScores();
}
@Override
public void onEnd()
{
Host.DamagePvE = false;
for (Pig pigs : _pigs)
{
if (!pigs.isDead())
{
pigs.remove();
}
}
_pigs.clear();
_score.clear();
}
@EventHandler
public void onCustomDamage(CustomDamageEvent event)
{
if (!isChallengeValid())
return;
if (event.GetDamageeEntity() == null)
return;
if (event.GetDamagerPlayer(false) == null)
return;
if (event.GetDamageeEntity() instanceof Pig)
{
Player player = event.GetDamagerPlayer(false);
Pig pig = (Pig) event.GetDamageeEntity();
if (Data.isCompleted(player) || !isPlayerValid(player))
{
event.SetCancelled("Player already completed");
return;
}
if (_pigs.contains(pig))
{
killPig(player, pig);
}
}
}
@EventHandler
public void onEntityDeath(EntityDeathEvent event)
{
if (!isChallengeValid())
return;
if (event.getEntity() instanceof Pig)
event.getDrops().clear();
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event)
{
if (!isChallengeValid())
return;
_score.remove(event.getPlayer());
}
private void spawnPigs()
{
for (int i = 0; i <= Math.round(getPlayersAlive().size() * 5); i++)
{
Location spawn = getRandomPigSpawn();
Host.CreatureAllowOverride = true;
Pig pig = (Pig) spawn.getWorld().spawnEntity(spawn, EntityType.PIG);
Host.CreatureAllowOverride = false;
_pigs.add(pig);
}
}
private void initializeScores()
{
for (Player player : getPlayersAlive())
{
_score.put(player, 0);
}
}
private void killPig(Player player, Pig pig)
{
Location loc = pig.getLocation().add(0, 1, 0);
_score.put(player, _score.get(player) + 1);
int score = _score.get(player);
if (score < _goal)
{
displayCount(player, loc, C.cWhiteB + score);
}
else
{
setCompleted(player, true);
displayCount(player, loc, C.cGreenB + "Completed!");
}
UtilParticle.PlayParticle(ParticleType.CLOUD, loc.subtract(0, 0.5, 0), 0.3F, 0.3F, 0.3F, 0.0F, 20, ViewDist.NORMAL, UtilServer.getPlayers());
pig.remove();
_pigs.remove(pig);
if (_pigs.isEmpty())
{
end();
}
}
private Location getRandomPigSpawn()
{
return getCenter().add(UtilMath.r((getArenaSize() * 2) - 1) - (getArenaSize() - 1), 1, UtilMath.r((getArenaSize() * 2) - 1) - (getArenaSize() - 1));
}
}

View File

@ -0,0 +1,361 @@
package nautilus.game.arcade.game.games.mineware.challenge.type;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.FireworkEffect.Type;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.entity.Villager;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitRunnable;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilFirework;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
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;
/**
* A challenge based on racing.
*/
public class ChallengeRedLightGreenLight extends Challenge
{
private static final int MAP_SPAWN_SHIFT = 1;
private static final int MAP_HEIGHT = 2;
private static final int MAP_X_START = -36;
private static final int MAP_X_STOP = 23;
private static final int MAP_SPAWN_FIXED_X = -35;
private static final int VILLAGER_X = MAP_X_STOP - 4;
private static final int MIN_TIME_BEFORE_RED = 1500; // milliseconds
private static final int MIN_TIME_BEFORE_GREEN = 2500; // milliseconds
private static final int COOLDOWN_EXPIRE_TICKS = 35;
private static final int SLOW_EFFECT_AMPLIFIER = 2;
private static final int COLOR_TILE_SIZE = 6;
private static final int KNOCKBACK_HEIGHT = MAP_HEIGHT + 3;
private static final double KNOCKBACK_POWER = 1.5;
private static final double KNOCKBACK_Y = 0.4;
private static final int KNOCKBACK_Y_MAX = 10;
private static final int CANNOT_MOVE_RANDOMIZER = 2;
private static final int CAN_MOVE_RANDOMIZER = 3;
private static final float STATUS_SOUND_VOLUME = 2.0F;
private static final float STATUS_SOUND_PITCH = 1.0F;
private static final int DELAY_UNTIL_KNOCKBACK = 1500; // milliseconds
private static final int CUSTOM_TITLE_STAY_TICKS = 60;
private static final int FIREWORK_MULTIPLIER = 2;
private static final int FIREWORK_INCREMENTATION = 4;
private static final int FIREWORK_X = MAP_X_STOP - 1;
private static final int FIREWORK_Y = MAP_HEIGHT + 8;
private static final byte[] COLORS = { 0, 5, 4, 1, 6, 14, 11, 12 };
private long _timeSinceLastRed;
private long _timeSinceLastGreen;
private Villager _villager;
private boolean _canMove;
private long _timeBeforeAction;
private List<Player> _cooldown = new ArrayList<>();
private int _colorIndex;
private int _colorCounter;
public ChallengeRedLightGreenLight(BawkBawkBattles host)
{
super(
host,
ChallengeType.FirstComplete,
"Red Light, Green Light",
"Be the first to reach the end.",
"You can move when the fireworks are green.",
"Stay still when the fireworks turn red.");
Settings.setUseMapHeight();
}
@Override
public ArrayList<Location> createSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
int size = getArenaSize() - MAP_SPAWN_SHIFT;
for (int z = -size; z <= size; z++)
{
spawns.add(getCenter().add(MAP_SPAWN_FIXED_X, MAP_HEIGHT, z));
}
return spawns;
}
@Override
public void createMap()
{
for (int x = MAP_X_START; x <= MAP_X_STOP; x++)
{
for (int z = -getArenaSize(); z <= getArenaSize(); z++)
{
Block block = getCenter().getBlock().getRelative(x, 1, z);
if (x == VILLAGER_X)
{
setBlock(block, Material.COAL_BLOCK);
}
else
{
setBlock(block, Material.WOOL, getColor());
}
addBlock(block);
}
_colorCounter++;
}
}
@Override
public void onStart()
{
spawnVillager();
changeMoveState(true);
addEffect(PotionEffectType.SLOW, SLOW_EFFECT_AMPLIFIER);
}
@Override
public void onEnd()
{
if (_villager != null)
{
_villager.remove();
}
_villager = null;
_canMove = false;
_timeBeforeAction = 0;
_cooldown.clear();
_colorIndex = 0;
_colorCounter = 0;
}
@EventHandler
public void onUpdate(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST)
return;
if (!isChallengeValid())
return;
determineMoveState();
}
@EventHandler
public void onPlayerMove(PlayerMoveEvent event)
{
if (!isChallengeValid())
return;
Player player = event.getPlayer();
if (!isPlayerValid(player))
return;
if (player.getLocation().getX() > getCenter().getX() + VILLAGER_X)
{
setCompleted(player);
}
else if (!_canMove && !_cooldown.contains(player) && _timeBeforeAction < System.currentTimeMillis())
{
if (event.getFrom().getBlockX() == event.getTo().getBlockX())
return;
addCooldown(player);
expireCooldown(player);
}
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event)
{
if (!isChallengeValid())
return;
Player player = event.getPlayer();
if (_cooldown.contains(player))
{
_cooldown.remove(player);
}
}
private byte getColor()
{
if (_colorCounter >= COLOR_TILE_SIZE)
{
_colorCounter = 0;
_colorIndex++;
if (_colorIndex >= COLORS.length)
_colorIndex = 0;
}
return COLORS[_colorIndex];
}
private void spawnVillager()
{
Host.CreatureAllow = true;
Location spawn = getCenter().add(VILLAGER_X, MAP_HEIGHT, 0);
_villager = (Villager) getCenter().getWorld().spawnEntity(spawn, EntityType.VILLAGER);
UtilEnt.Vegetate(_villager);
UtilEnt.CreatureLook(_villager, Host.GetSpectatorLocation());
UtilEnt.ghost(_villager, true, false);
_villager.setCustomName(C.cGreenB + "Finish Line");
_villager.setCustomNameVisible(true);
Host.CreatureAllow = false;
}
private void addCooldown(Player player)
{
UtilAction.velocity(player, UtilAlg.getTrajectory2d(player.getLocation(), getCenter().add(MAP_X_START, KNOCKBACK_HEIGHT, 0)), KNOCKBACK_POWER, true, KNOCKBACK_Y, 0, KNOCKBACK_Y_MAX, true);
_cooldown.add(player);
}
private void expireCooldown(Player player)
{
new BukkitRunnable()
{
@Override
public void run()
{
if (!isChallengeValid() || player == null)
{
cancel();
return;
}
_cooldown.remove(player);
}
}.runTaskLater(Host.Manager.getPlugin(), COOLDOWN_EXPIRE_TICKS);
}
private void determineMoveState()
{
if (_canMove)
{
toggleCannotMoveState();
}
else
{
toggleCanMoveState();
}
}
private void toggleCannotMoveState()
{
if (_timeSinceLastRed + MIN_TIME_BEFORE_RED < System.currentTimeMillis())
{
if (UtilMath.r(CANNOT_MOVE_RANDOMIZER) == 0)
{
changeMoveState(false);
}
}
}
private void toggleCanMoveState()
{
if (_timeSinceLastGreen + MIN_TIME_BEFORE_GREEN < System.currentTimeMillis())
{
if (UtilMath.r(CAN_MOVE_RANDOMIZER) == 0)
{
changeMoveState(true);
}
}
}
private void changeMoveState(boolean flag)
{
if (flag != _canMove)
{
if (flag)
{
canMoveEffect();
}
else
{
cannotMoveEffect();
}
}
}
private void canMoveEffect()
{
_timeSinceLastRed = System.currentTimeMillis();
_canMove = true;
spawnFirework(Color.GREEN);
moveTextAndSound();
}
private void moveTextAndSound()
{
for (Player player : getPlayersIn(true))
{
UtilPlayer.message(player, F.main("Green Light", "You can now move."));
player.getWorld().playSound(player.getLocation(), Sound.SUCCESSFUL_HIT, STATUS_SOUND_VOLUME, STATUS_SOUND_PITCH);
}
}
private void cannotMoveEffect()
{
_timeSinceLastGreen = System.currentTimeMillis();
_timeBeforeAction = System.currentTimeMillis() + DELAY_UNTIL_KNOCKBACK;
_canMove = false;
spawnFirework(Color.RED);
cannotMoveTextAndSound();
}
private void cannotMoveTextAndSound()
{
for (Player player : getPlayersIn(true))
{
UtilPlayer.message(player, F.main("Red Light", "Freeze!"));
alert(player, ChatColor.RED + "Freeze!", CUSTOM_TITLE_STAY_TICKS);
player.getWorld().playSound(player.getLocation(), Sound.NOTE_BASS, STATUS_SOUND_VOLUME, STATUS_SOUND_PITCH);
}
}
private void spawnFirework(Color color)
{
for (int i = -getArenaSize(); i < getArenaSize() * FIREWORK_MULTIPLIER; i += FIREWORK_INCREMENTATION)
{
UtilFirework.playFirework(getCenter().add(FIREWORK_X, FIREWORK_Y, i), Type.BALL_LARGE, color, false, false);
}
}
}

View File

@ -0,0 +1,318 @@
package nautilus.game.arcade.game.games.mineware.challenge.type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.bukkit.Color;
import org.bukkit.FireworkEffect.Type;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilFirework;
import mineplex.core.common.util.UtilMath;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.game.games.mineware.BawkBawkBattles;
import nautilus.game.arcade.game.games.mineware.challenge.ChallengeType;
import nautilus.game.arcade.game.games.mineware.challenge.LogicTracker;
import nautilus.game.arcade.game.games.mineware.challenge.TeamChallenge;
/**
* A team based challenge based on tagging and untagging players.
*/
public class ChallengeReverseTag extends TeamChallenge implements LogicTracker
{
private static final int CHALLENGE_DURATION_RANDOMIZER = 5;
private static final int CHALLENGE_DURATION_MIN = 20;
private static final int CHALLENGE_DURATION_MULTIPLIER = 1000;
private static final int MAP_SIZE = 9;
private static final int MAP_SPAWN_SHIFT = 1;
private static final int MAP_HEIGHT = 1;
private static final int SPAWN_COORDINATE_MULTIPLIER = 2;
private static final int WOOL_DATA_RANGE = 16;
private static final int PLAYER_COUNT_HIDE_FIREWORKS = 24;
private static final int INVENTORY_HOTBAR_SLOTS = 8;
private static final Material TAG_MATERIAL = Material.WOOL;
private static final byte TAG_DATA = 5;
private static final int UNTAG_COOLDOWN = 2; // seconds
private Set<Player> _cooldowns = new HashSet<>();
private Map<Player, Boolean> _tagTracker = new HashMap<>();
public ChallengeReverseTag(BawkBawkBattles host)
{
super(
host,
ChallengeType.FirstComplete,
"Tagged",
"Non Tagged",
"Reverse Tag",
"Punch a sparkling person to become one.",
"Stay sparkling until the end.");
Settings.setUseMapHeight();
Settings.setTeamBased();
Settings.setDuration((UtilMath.r(CHALLENGE_DURATION_RANDOMIZER) + CHALLENGE_DURATION_MIN) * CHALLENGE_DURATION_MULTIPLIER);
}
@Override
public ArrayList<Location> createSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
int size = getArenaSize(MAP_SIZE) - MAP_SPAWN_SHIFT;
for (int x = -size; x <= size; x++)
{
for (int z = -size; z <= size; z++)
{
if (x % SPAWN_COORDINATE_MULTIPLIER == 0 && z % SPAWN_COORDINATE_MULTIPLIER == 0)
{
spawns.add(getCenter().add(x, MAP_HEIGHT, z));
}
}
}
return spawns;
}
@Override
public void createMap()
{
int size = getArenaSize(MAP_SIZE);
for (int x = -size; x <= size; x++)
{
for (int z = -size; z <= size; z++)
{
Block block = getCenter().getBlock().getRelative(x, 0, z);
setBlock(block, Material.WOOL, (byte) UtilMath.r(WOOL_DATA_RANGE));
addBlock(block);
}
}
}
@Override
public void onStart()
{
Host.DamagePvP = true;
autoSelectTeams();
for (Player tagged : getFirstTeam().getPlayers())
{
tagEffect(tagged);
_tagTracker.put(tagged, true);
}
}
@Override
public void onEnd()
{
Host.DamagePvP = false;
_cooldowns.clear();
_tagTracker.clear();
}
@Override
public void onTimerFinish()
{
for (Player tagged : getFirstTeam().getPlayers())
{
setCompleted(tagged);
}
}
@EventHandler
public void onUpdateFireworks(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC)
return;
if (!isChallengeValid())
return;
if (getPlayersAlive().size() > PLAYER_COUNT_HIDE_FIREWORKS)
return;
for (Player player : getFirstTeam().getPlayers())
{
UtilFirework.playFirework(player.getEyeLocation(), Type.BURST, Color.GREEN, false, false);
}
}
@EventHandler
public void onCustomDamage(CustomDamageEvent event)
{
if (!isChallengeValid())
return;
Player damager = event.GetDamagerPlayer(false);
Player damagee = event.GetDamageePlayer();
if (damager == null || damagee == null)
return;
if (!isPlayerValid(damager))
{
event.SetCancelled("Invalid Damager");
return;
}
if (!isPlayerValid(damagee))
{
event.SetCancelled("Invalid Damagee");
return;
}
if (getFirstTeam().isMember(damagee) && getSecondTeam().isMember(damager) && !_cooldowns.contains(damagee))
{
clear(damagee);
tag(damager);
event.SetCancelled("Successful Tag");
}
else
{
event.SetCancelled("Invalid Tag Attempt");
}
}
@EventHandler
public void onPlayerDeath(PlayerDeathEvent event)
{
if (!isChallengeValid())
return;
Player player = event.getEntity();
getFirstTeam().remove(player);
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event)
{
if (!isChallengeValid())
return;
Player player = event.getPlayer();
if (!isPlayerValid(player))
return;
_cooldowns.remove(player);
_tagTracker.remove(player);
}
private void clear(Player player)
{
if (getFirstTeam().isMember(player))
{
trackClear(player);
clearEffect(player);
getFirstTeam().remove(player);
getSecondTeam().add(player);
}
}
private void trackClear(Player player)
{
if (_tagTracker.containsKey(player))
{
if (_tagTracker.get(player))
{
_tagTracker.put(player, false);
}
}
}
private void clearEffect(Player player)
{
alert(player, C.cRed + "You are no longer tagged.");
player.getInventory().setHelmet(new ItemStack(Material.AIR));
for (int i = 0; i <= INVENTORY_HOTBAR_SLOTS; i++)
{
player.getInventory().clear(i);
}
}
private void tag(Player player)
{
if (getSecondTeam().isMember(player))
{
trackTag(player);
tagEffect(player);
getSecondTeam().remove(player);
getFirstTeam().add(player);
_cooldowns.add(player);
removeCooldown(player);
}
}
private void trackTag(Player player)
{
if (_tagTracker.containsKey(player))
{
if (_tagTracker.get(player))
{
_tagTracker.put(player, true);
}
}
else
{
_tagTracker.put(player, true);
}
}
private void tagEffect(Player player)
{
alert(player, C.cGreen + "You are now tagged, keep it up.");
player.getInventory().setHelmet(ItemStackFactory.Instance.CreateStack(TAG_MATERIAL, TAG_DATA));
for (int i = 0; i <= INVENTORY_HOTBAR_SLOTS; i++)
{
player.getInventory().setItem(i, ItemStackFactory.Instance.CreateStack(TAG_MATERIAL, TAG_DATA));
}
}
private void removeCooldown(Player player)
{
new BukkitRunnable()
{
@Override
public void run()
{
_cooldowns.remove(player);
}
}.runTaskLater(Host.Manager.getPlugin(), UNTAG_COOLDOWN * TICK_MULTIPLIER);
}
@Override
public boolean hasData(Player player)
{
if (_tagTracker.containsKey(player))
{
return _tagTracker.get(player);
}
else
{
return false;
}
}
}

View File

@ -0,0 +1,168 @@
package nautilus.game.arcade.game.games.mineware.challenge.type;
import java.util.ArrayList;
import org.bukkit.Color;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.game.games.mineware.BawkBawkBattles;
import nautilus.game.arcade.game.games.mineware.challenge.ChallengeType;
import nautilus.game.arcade.game.games.mineware.challenge.TeamChallenge;
/**
* A team based challenge where every team has to push the opposing team members to the void.
*/
public class ChallengeRushPush extends TeamChallenge
{
private static final int LOCKED_INVENTORY_SLOT = 4;
private static final int MAP_SPAWN_SHIFT = 1;
private static final int MAP_FIXED_Z = 6;
private static final int MAP_HEIGHT = 1;
private static final byte STAINED_CLAY_BLUE_DATA = 11;
private static final byte STAINED_CLAY_RED_DATA = 14;
private static final double DAMAGE = 0.001;
private static final double KNOCKBACK = 5.5;
public ChallengeRushPush(BawkBawkBattles host)
{
super(
host,
ChallengeType.LastStanding,
"Blue",
"Red",
true,
(byte) 11,
(byte) 14,
"Rush Push",
"Attack to the enemy team.",
"Push them off the platform.");
Settings.setUseMapHeight();
Settings.setCanCruble();
Settings.setLockInventory(LOCKED_INVENTORY_SLOT);
Settings.setTeamBased();
}
@Override
public ArrayList<Location> createSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
int size = getArenaSize() - MAP_SPAWN_SHIFT;
for (int x = -(size); x <= size; x++)
{
for (int z = -MAP_FIXED_Z; z <= MAP_FIXED_Z; z += MAP_FIXED_Z)
{
if (z == 0)
continue;
spawns.add(getCenter().add(x, MAP_HEIGHT, z));
}
}
return spawns;
}
@Override
public void createMap()
{
for (int x = -getArenaSize(); x <= getArenaSize(); x++)
{
for (int z = -MAP_FIXED_Z; z <= MAP_FIXED_Z; z++)
{
Block block = getCenter().getBlock().getRelative(x, 0, z);
setBlock(block, Material.STAINED_CLAY);
if (z != 0)
{
setData(block, (byte) (z < 0 ? STAINED_CLAY_BLUE_DATA : z > 0 ? STAINED_CLAY_RED_DATA : 0));
}
addBlock(block);
}
}
}
@Override
public void onStart()
{
Host.DamagePvP = true;
addDiamondSword();
equipTeamHelmets();
}
@Override
public void onEnd()
{
Host.DamagePvP = false;
}
@EventHandler
public void onCustomDamage(CustomDamageEvent event)
{
if (!isChallengeValid())
return;
Player damager = event.GetDamagerPlayer(false);
Player damagee = event.GetDamageePlayer();
if (!isPlayerValid(damager) || !isPlayerValid(damagee))
return;
if (areOnSameTeam(damager, damagee))
{
event.SetCancelled("Friendly Fire");
return;
}
if (event.GetCause() == DamageCause.ENTITY_ATTACK)
{
event.AddMult("No Damage", null, DAMAGE, false);
event.AddKnockback("Knockback", KNOCKBACK);
}
}
private void addDiamondSword()
{
ItemStack sword = new ItemBuilder(Material.DIAMOND_SWORD)
.setUnbreakable(true)
.setItemFlags(ItemFlag.HIDE_UNBREAKABLE)
.build();
setItem(Settings.getLockedSlot(), sword);
}
private void equipTeamHelmets()
{
ItemStack helmet = new ItemStack(Material.LEATHER_HELMET);
LeatherArmorMeta meta = (LeatherArmorMeta) helmet.getItemMeta();
meta.setColor(Color.BLUE);
helmet.setItemMeta(meta);
for (Player player : getFirstTeam().getPlayers())
{
player.getInventory().setHelmet(helmet);
}
meta.setColor(Color.RED);
helmet.setItemMeta(meta);
for (Player player : getSecondTeam().getPlayers())
{
player.getInventory().setHelmet(helmet);
}
}
}

View File

@ -0,0 +1,93 @@
package nautilus.game.arcade.game.games.mineware.challenge.type;
import java.util.ArrayList;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import mineplex.core.common.util.UtilMath;
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;
/**
* A challenge based on knocking players off a platform.
*/
public class ChallengeSmashOff extends Challenge
{
private static final int PLATFORM_SIZE = 4;
private static final double SPAWN_CENTER = 0.5;
private static final int PLATFORM_COLOR_RANGE = 16;
private static final int PLATFORM_ADD_Z = 2;
private static final int PLATFORM_COLOR_LIMIT = 14;
public ChallengeSmashOff(BawkBawkBattles host)
{
super(
host,
ChallengeType.LastStanding,
"Smash Off",
"Knock other players off their platform.");
Settings.setUseMapHeight();
Settings.setCanCruble();
}
@Override
public ArrayList<Location> createSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
int amount = (int) Math.ceil(Math.sqrt(Host.getPlayersWithRemainingLives()));
for (int pX = 0; pX < amount; pX++)
{
for (int pZ = 0; pZ < amount; pZ++)
{
spawns.add(getCenter().add((pX * PLATFORM_SIZE) + SPAWN_CENTER, 1, (pZ * PLATFORM_SIZE) + SPAWN_CENTER));
}
}
return spawns;
}
@Override
public void createMap()
{
int amount = (int) Math.ceil(Math.sqrt(Host.getPlayersWithRemainingLives()));
int a = UtilMath.r(PLATFORM_COLOR_RANGE);
for (int pX = 0; pX < amount; pX++)
{
for (int pZ = 0; pZ < amount; pZ++)
{
for (int x = pX * PLATFORM_SIZE; x < (pX * PLATFORM_SIZE) + PLATFORM_ADD_Z; x++)
{
for (int z = pZ * PLATFORM_SIZE; z < (pZ * PLATFORM_SIZE) + PLATFORM_ADD_Z; z++)
{
Block block = getCenter().getBlock().getRelative(x, 0, z);
setBlock(block, Material.STAINED_CLAY, (byte) a);
addBlock(block);
}
}
if (++a >= PLATFORM_COLOR_LIMIT)
{
a = 0;
}
}
}
}
@Override
public void onStart()
{
Host.DamagePvP = true;
}
@Override
public void onEnd()
{
Host.DamagePvP = false;
}
}

View File

@ -0,0 +1,375 @@
package nautilus.game.arcade.game.games.mineware.challenge.type;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;
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.block.Chest;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.Player;
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.ItemSpawnEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilMath;
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;
/**
* A PvP based challenge where players have to find weapons.
*/
public class ChallengeTreasureDigger extends Challenge
{
private static final int CHALLENGE_PLAYERS_MIN = 4;
private static final int MAP_SPAWN_SHIFT = 2;
private static final int MAP_HEIGHT = 4;
private static final int BEDROCK_LEVEL = 0;
private static final int TREASURE_LEVEL = 1;
private static final int RED_SANDSTONE_LEVEL = 2;
private static final int SANDSTONE_LEVEL = 3;
private static final int SAND_LEVEL = 4;
private static final double TREASURE_CHANCE = 0.15;
private static final double SANDSTONE_CHANCE = 0.1;
private static final double SANDSTONE_CHANCE_TREASURE_LEVEL = 0.25;
private static final double RED_SANDSTONE_CHANCE = 0.3;
private static final double DEAD_BUSH_CHANCE = 0.015;
private static final int SHOVEL_SLOT = 4;
private static final int CHEST_DATA_RANGE = 4;
private static final int CHEST_LOOT_AMOUNT_RANDOM = 2;
private static final int CHEST_COSMETIC_ITEM_AMOUNT_RANDOM = 3;
private Map<Material, Double> _lootChance = new LinkedHashMap<>();
private Material[] _lootContents;
public ChallengeTreasureDigger(BawkBawkBattles host)
{
super(
host,
ChallengeType.LastStanding,
"Treasure Digger",
"Search for treasure below the sand.",
"Find weapons to kill the others!");
Settings.setUseMapHeight();
Settings.setMinPlayers(CHALLENGE_PLAYERS_MIN);
_lootChance.put(Material.BONE, 0.2);
_lootChance.put(Material.STRING, 0.2);
_lootChance.put(Material.WOOD_SWORD, 0.3);
_lootChance.put(Material.STONE_SWORD, 0.2);
_lootChance.put(Material.IRON_SWORD, 0.1);
_lootChance.put(Material.GOLD_SWORD, 0.1);
_lootChance.put(Material.DIAMOND_SWORD, 0.05);
_lootChance.put(Material.IRON_SPADE, 0.15);
_lootChance.put(Material.IRON_PICKAXE, 0.15);
_lootChance.put(Material.GOLDEN_APPLE, 0.05);
_lootChance.put(Material.FISHING_ROD, 0.1);
_lootChance.put(Material.BOW, 0.2);
_lootChance.put(Material.ARROW, 0.3);
_lootChance.put(Material.LEATHER_HELMET, 0.2);
_lootChance.put(Material.LEATHER_CHESTPLATE, 0.15);
_lootChance.put(Material.LEATHER_LEGGINGS, 0.12);
_lootChance.put(Material.LEATHER_BOOTS, 0.2);
_lootChance.put(Material.CHAINMAIL_HELMET, 0.1);
_lootChance.put(Material.CHAINMAIL_CHESTPLATE, 0.05);
_lootChance.put(Material.CHAINMAIL_LEGGINGS, 0.07);
_lootChance.put(Material.CHAINMAIL_BOOTS, 0.1);
_lootChance.put(Material.IRON_HELMET, 0.1);
_lootChance.put(Material.IRON_CHESTPLATE, 0.05);
_lootChance.put(Material.IRON_LEGGINGS, 0.07);
_lootChance.put(Material.IRON_BOOTS, 0.1);
_lootChance.put(Material.DIAMOND_HELMET, 0.05);
_lootChance.put(Material.DIAMOND_CHESTPLATE, 0.02);
_lootChance.put(Material.DIAMOND_LEGGINGS, 0.04);
_lootChance.put(Material.DIAMOND_BOOTS, 0.05);
_lootContents = _lootChance.keySet().toArray(new Material[_lootChance.keySet().size()]);
}
@Override
public ArrayList<Location> createSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
int size = getArenaSize() - MAP_SPAWN_SHIFT;
for (Location location : circle(getCenter(), size, 1, true, false, 0))
{
spawns.add(location.add(0, MAP_HEIGHT, 0));
}
return spawns;
}
@Override
public void createMap()
{
for (int i = 0; i <= MAP_HEIGHT; i++)
{
Location center = getCenter();
if (i > 0)
{
center.add(0, i, 0);
}
for (Location location : circle(center, getArenaSize(), 1, false, false, 0))
{
Block block = location.getBlock();
double chance = Math.random();
if (i == BEDROCK_LEVEL)
{
setBlock(block, Material.BEDROCK);
}
else if (i == TREASURE_LEVEL)
{
if (chance < TREASURE_CHANCE)
{
makeChestWithTreasure(block);
}
else if (chance < SANDSTONE_CHANCE_TREASURE_LEVEL)
{
setBlock(block, Material.SANDSTONE);
}
else
{
setBlock(block, Material.SAND);
}
}
else if (i == RED_SANDSTONE_LEVEL)
{
if (chance < SANDSTONE_CHANCE)
{
setBlock(block, Material.SANDSTONE);
}
else
{
setBlock(block, Material.SAND);
chance = Math.random();
if (chance < RED_SANDSTONE_CHANCE)
{
setData(block, (byte) 1);
}
}
}
else if (i == SANDSTONE_LEVEL)
{
if (chance < SANDSTONE_CHANCE)
{
setBlock(block, Material.SANDSTONE);
}
else
{
setBlock(block, Material.SAND);
}
}
else if (i == SAND_LEVEL)
{
Block below = block.getRelative(BlockFace.DOWN);
if (chance < DEAD_BUSH_CHANCE && below.getType() == Material.SAND)
{
setBlock(block, Material.DEAD_BUSH);
}
}
addBlock(block);
}
}
}
@Override
public void onStart()
{
Host.DamagePvP = true;
Host.InventoryOpenChest = true;
Host.BlockBreak = true;
Host.InventoryOpenBlock = true;
Host.InventoryClick = true;
Host.WorldBlockBurn = true;
Host.WorldFireSpread = true;
for (Player players : getPlayersAlive())
{
ItemStack shovel = new ItemStack(Material.STONE_SPADE);
players.getInventory().setItem(SHOVEL_SLOT, shovel);
players.getInventory().setHeldItemSlot(SHOVEL_SLOT);
}
}
@Override
public void onEnd()
{
Host.DamagePvP = true;
Host.InventoryOpenChest = false;
Host.BlockBreak = false;
Host.InventoryOpenBlock = false;
Host.InventoryClick = false;
Host.DamagePvP = false;
Host.WorldBlockBurn = false;
Host.WorldFireSpread = false;
remove(EntityType.DROPPED_ITEM);
}
@EventHandler
public void onBlockBreak(BlockBreakEvent event)
{
if (!isChallengeValid())
return;
if (!isPlayerValid(event.getPlayer()) || !Data.isModifiedBlock(event.getBlock()))
{
event.setCancelled(true);
}
}
@EventHandler
public void onItemSpawn(ItemSpawnEvent event)
{
if (!isChallengeValid())
return;
if (!Host.getDeathEffect().isDeathEffectItem(event.getEntity()))
{
event.setCancelled(true);
}
}
@EventHandler
public void onEntityChangeBlock(EntityChangeBlockEvent event)
{
if (!isChallengeValid())
return;
if (event.getEntity() instanceof FallingBlock)
{
FallingBlock block = (FallingBlock) event.getEntity();
block.setDropItem(false);
}
}
@EventHandler
public void onEntityDamageByEntity(EntityDamageByEntityEvent event)
{
if (!isChallengeValid())
return;
if (event.getEntity() instanceof Player && event.getDamager() instanceof Player)
{
if (!isPlayerValid((Player) event.getEntity()))
return;
if (!isPlayerValid((Player) event.getDamager()))
return;
Player damager = (Player) event.getDamager();
ItemStack item = damager.getItemInHand();
if (item != null)
{
if (!item.getType().name().toLowerCase().contains("sword"))
{
alert(damager, C.cRed + "You cannot attack without a weapon.");
damager.playSound(damager.getLocation(), Sound.NOTE_BASS_GUITAR, 1.0F, 0.5F);
event.setCancelled(true);
}
}
}
}
private void makeChestWithTreasure(Block block)
{
if (areChestsNearby(block))
{
setBlock(block, Material.SAND);
}
else
{
setBlock(block, Material.CHEST, (byte) UtilMath.r(CHEST_DATA_RANGE));
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(CHEST_LOOT_AMOUNT_RANDOM) + 1; i++)
{
double chance = Math.random();
Material loot = getRandomLootMaterial();
double lootChance = getLootChance(loot);
while (chance >= lootChance)
{
chance = Math.random();
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(CHEST_COSMETIC_ITEM_AMOUNT_RANDOM) + 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);
}
}

View File

@ -0,0 +1,410 @@
package nautilus.game.arcade.game.games.mineware.challenge.type;
import java.util.ArrayList;
import org.bukkit.Color;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Pig;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.scheduler.BukkitRunnable;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTextBottom;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.recharge.Recharge;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.game.games.mineware.BawkBawkBattles;
import nautilus.game.arcade.game.games.mineware.challenge.ChallengeType;
import nautilus.game.arcade.game.games.mineware.challenge.TeamChallenge;
/**
* A challenge based on volley.
*/
public class ChallengeVolleyPig extends TeamChallenge
{
private static final int CHALLENGE_PLAYERS_MAX = 25;
private static final int LOCKED_INVENTORY_SLOT = 4;
private static final int CHALLENGE_DURATION = 30000;
private static final int MAP_SPAWN_SHIFT = 1;
private static final int MAP_X = 6;
private static final int MAP_SPAWN_X = MAP_X - 1;
private static final int MAP_HEIGHT = 3;
private static final int MAP_SPAWN_HEIGHT = MAP_HEIGHT - 2;
private static final byte BLUE_STAINED_GLASS = 11;
private static final byte RED_STAINED_GLASS = 14;
// Relative to map center.
private static final int BLUE_CENTER_X = 0;
private static final int BLUE_CENTER_Y = 3;
private static final int BLUE_CENTER_Z = 5;
private static final int RED_CENTER_X = 0;
private static final int RED_CENTER_Y = 3;
private static final int RED_CENTER_Z = -5;
private static final double PIG_PUSH_DAMAGE = 0.001;
// Relative to map center.
private static final double PIG_CENTER_X = 7.5;
private static final double PIG_CENTER_Y = 1;
private static final double PIG_CENTER_Z = 0.5;
private static final int KNOCKBACK_MESSAGE_COOLDOWN = 1000;
private static final double MAX_BLOCK_SHIFT = 0.3;
private static final int SCORE_GAIN = 50;
private static final int SCORE_GOAL = 10000;
private static final int BAR_AMOUNT = 24;
private Location _blueCenter, _redCenter;
private Pig _pig;
private long _blueSide, _redSide;
public ChallengeVolleyPig(BawkBawkBattles host)
{
super(
host,
ChallengeType.FirstComplete,
"Blue",
"Red",
true,
(byte) 11,
(byte) 14,
"Volley Pig",
"Punch the pig on the enemy side.");
Settings.setUseMapHeight();
Settings.setMaxPlayers(CHALLENGE_PLAYERS_MAX);
Settings.setTeamBased();
Settings.setLockInventory(LOCKED_INVENTORY_SLOT);
Settings.setDuration(CHALLENGE_DURATION);
}
@Override
public ArrayList<Location> createSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
int size = getArenaSize() - MAP_SPAWN_SHIFT;
for (int x = -size; x <= MAP_SPAWN_X; x++)
{
for (int z = -size; z <= size; z++)
{
if (z != 0)
{
spawns.add(getCenter().add(x, MAP_SPAWN_HEIGHT, z));
}
}
}
return spawns;
}
@Override
public void createMap()
{
for (int x = -getArenaSize(); x <= MAP_X; x++)
{
for (int z = -getArenaSize(); z <= getArenaSize(); z++)
{
for (int y = 0; y <= MAP_HEIGHT; y++)
{
Block block = getCenter().getBlock().getRelative(x, y, z);
if (x == MAP_X || x == -getArenaSize() || y == 0 || Math.abs(z) == getArenaSize())
{
setBlock(block, z == 0 ? Material.STAINED_GLASS : Material.STAINED_CLAY, (z < 0 ? BLUE_STAINED_GLASS : z > 0 ? RED_STAINED_GLASS : 0));
addBlock(block);
}
}
}
}
}
@Override
public void onStart()
{
Host.DamagePvE = true;
_blueCenter = getCenter().add(BLUE_CENTER_X, BLUE_CENTER_Y, BLUE_CENTER_Z);
_redCenter = getCenter().add(RED_CENTER_X, RED_CENTER_Y, RED_CENTER_Z);
spawnPig();
equipKnockbackStick();
equipTeamHelmets();
startMainTask();
}
@Override
public void onEnd()
{
Host.DamagePvE = false;
if (_pig != null)
{
_pig.remove();
}
_pig = null;
_blueSide = 0;
_redSide = 0;
}
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.LOW)
public void onPlayerMove(PlayerMoveEvent event)
{
if (!isChallengeValid())
return;
Player player = event.getPlayer();
if (!isPlayerValid(player))
return;
Location from = event.getFrom();
Location to = event.getTo();
Block fromBlock = from.getBlock().getRelative(BlockFace.DOWN);
Block toBlock = to.getBlock().getRelative(BlockFace.DOWN);
if (!fromBlock.isEmpty() && !toBlock.isEmpty())
{
boolean crossedBlue = getSecondTeam().isMember(player) && (fromBlock.getData() == BLUE_STAINED_GLASS || toBlock.getData() == BLUE_STAINED_GLASS);
boolean crossedRed = getFirstTeam().isMember(player) && (fromBlock.getData() == RED_STAINED_GLASS || toBlock.getData() == RED_STAINED_GLASS);
boolean fromStainedGlass = fromBlock.getType() == Material.STAINED_GLASS;
boolean toStainedGlass = toBlock.getType() == Material.STAINED_GLASS;
if (crossedBlue || crossedRed || fromStainedGlass || toStainedGlass)
{
knockback(player);
}
}
}
@EventHandler
public void onCustomDamage(CustomDamageEvent event)
{
if (!isChallengeValid())
return;
if (!event.GetDamageeEntity().equals(_pig))
return;
if (event.GetCause() == DamageCause.FALL)
return;
event.AddMult("Push", null, PIG_PUSH_DAMAGE, false);
_pig.setHealth(_pig.getMaxHealth());
}
private void startMainTask()
{
new BukkitRunnable()
{
@Override
public void run()
{
if (!isChallengeValid())
{
cancel();
return;
}
increaseTeamScore();
displayProgress();
selectWinners();
}
}.runTaskTimer(Host.getArcadeManager().getPlugin(), 0L, 1L);
}
private void spawnPig()
{
Host.CreatureAllow = true;
_pig = (Pig) getCenter().getWorld().spawn(
getCenter().add(PIG_CENTER_X, PIG_CENTER_Y, PIG_CENTER_Z).subtract(getArenaSize(), 0, 0),
Pig.class);
UtilEnt.Vegetate(_pig);
Host.CreatureAllow = false;
}
private void equipTeamHelmets()
{
ItemStack helmet = new ItemStack(Material.LEATHER_HELMET);
LeatherArmorMeta meta = (LeatherArmorMeta) helmet.getItemMeta();
meta.setColor(Color.BLUE);
helmet.setItemMeta(meta);
for (Player player : getFirstTeam().getPlayers())
{
player.getInventory().setHelmet(helmet);
}
meta.setColor(Color.RED);
helmet.setItemMeta(meta);
for (Player player : getSecondTeam().getPlayers())
{
player.getInventory().setHelmet(helmet);
}
}
private void equipKnockbackStick()
{
ItemStack stick = new ItemBuilder(Material.STICK)
.addEnchantment(Enchantment.KNOCKBACK, 1)
.addItemFlags(ItemFlag.HIDE_ENCHANTS)
.build();
setItem(Settings.getLockedSlot(), stick);
}
private void knockback(Player player)
{
UtilAction.velocity(
player,
UtilAlg.getTrajectory2d(player.getLocation(), getTeamCenter(player)),
-UtilAlg.calculateVelocity(player.getLocation().toVector(), getTeamCenter(player).toVector(), 0).length() + 0.2,
false,
0,
0,
0,
false);
if (Recharge.Instance.use(player, "Knockback Message", KNOCKBACK_MESSAGE_COOLDOWN, false, false))
{
alert(player, C.cRed + "You cannot cross to the enemy side.");
}
}
private Location getTeamCenter(Player player)
{
if (getFirstTeam().isMember(player))
{
return _blueCenter;
}
else
{
return _redCenter;
}
}
@SuppressWarnings("deprecation")
private void increaseTeamScore()
{
if (_pig.isValid())
{
Location loc = _pig.getLocation();
Block feetBlock = loc.getBlock().getRelative(BlockFace.DOWN);
Location feet = feetBlock.getLocation();
if (feetBlock.isEmpty()) // Retrieve the correct block if the pig is near a block edge.
{
double x = loc.getX();
double z = loc.getZ();
if ((x + MAX_BLOCK_SHIFT) >= Math.ceil(x))
{
feetBlock = feet.subtract(MAX_BLOCK_SHIFT, 0, 0).getBlock();
}
else if ((x - MAX_BLOCK_SHIFT) <= Math.floor(x))
{
feetBlock = feet.add(MAX_BLOCK_SHIFT, 0, 0).getBlock();
}
else if ((z + MAX_BLOCK_SHIFT) >= Math.ceil(z))
{
feetBlock = feet.subtract(0, 0, MAX_BLOCK_SHIFT).getBlock();
}
else if ((z - MAX_BLOCK_SHIFT) <= Math.floor(z))
{
feetBlock = feet.add(0, 0, MAX_BLOCK_SHIFT).getBlock();
}
}
if (feetBlock.getType() == Material.STAINED_CLAY)
{
byte data = feetBlock.getData();
if (data == BLUE_STAINED_GLASS)
{
_blueSide += SCORE_GAIN;
}
else
{
_redSide += SCORE_GAIN;
}
}
}
}
private void selectWinners()
{
if (_pig.isValid())
{
if (_redSide > SCORE_GOAL)
{
for (Player bluePlayer : getFirstTeam().getPlayers())
{
setCompleted(bluePlayer);
}
}
else if (_blueSide > SCORE_GOAL)
{
for (Player redPlayer : getSecondTeam().getPlayers())
{
setCompleted(redPlayer);
}
}
}
}
private void displayProgress()
{
double red = _redSide / (double) SCORE_GOAL;
double blue = _blueSide / (double) SCORE_GOAL;
boolean redFirst = red < blue;
String progressBar = (redFirst ? C.cRed : C.cBlue) + "";
int colorChange = 0;
for (int i = 0; i < BAR_AMOUNT; i++)
{
float d = (float) i / (float) BAR_AMOUNT;
if (colorChange == 0 && d >= (redFirst ? red : blue))
{
progressBar += (redFirst ? C.cBlue : C.cRed);
colorChange = 1;
}
if (colorChange != 2 && d >= Math.max(red, blue))
{
progressBar += C.cWhite;
colorChange = 2;
}
progressBar += "";
}
UtilTextBottom.display(progressBar, UtilServer.getPlayers());
}
}

View File

@ -0,0 +1,417 @@
package nautilus.game.arcade.game.games.mineware.challenge.type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.entity.Boat;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.vehicle.VehicleDestroyEvent;
import org.bukkit.scheduler.BukkitRunnable;
import org.spigotmc.event.entity.EntityDismountEvent;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.explosion.ExplosionEvent;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
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;
/**
* A challenge based on water, boats and tnt.
*/
public class ChallengeWaterHorror extends Challenge
{
private static final int MAP_SPAWN_SHIFT = 2;
private static final int MAP_SPAWN_HEIGHT = 6;
private static final int MAP_HEIGHT = MAP_SPAWN_HEIGHT + 1;
private static final int TNT_SPAWN_MAX = 3;
private static final int TNT_SPAWN_MIN = 1;
private static final int TNT_EXPLODE_AFTER = 2; // seconds
private static final int BEDROCK_LEVEL = 0;
private static final int SAND_LEVEL = 1;
private static final int MAIN_LEVEL = 5;
private static final int DROPSITE_HEIGHT = 7;
private static final float TNT_PARTICLE_OFFSET = 0.2F;
private static final int TNT_PARTICLE_AMOUNT = 2;
private static final float TNT_INCOMING_SOUND_VOLUME = 0.5F;
private static final float TNT_INCOMING_SOUND_PITCH = 1.0F;
private static final float SPAWNER_FLAME_OFFSET = 0.3F;
private static final float SPAWNER_FLAME_SPEED = 0.03F;
private static final int SPAWNER_FLAME_AMOUNT = 2;
private static final float SPAWNER_CLOUD_OFFSET = 0.1F;
private static final int SPAWNER_CLOUD_AMOUNT = 2;
private static final float TNT_SPAWN_SOUND_VOLUME = 0.5F;
private static final float TNT_SPAWN_SOUND_PITCH = 1.3F;
private static final int TNT_SPAWN_INTERVAL = 2; // seconds
private static final double TNT_VELOCITY_POWER_MIN = 0.2;
private static final double TNT_VELOCITY_HEIGHT = 0.4;
private Map<Player, Boat> _boats = new HashMap<>();
private Location _dropsite;
private Location _base;
public ChallengeWaterHorror(BawkBawkBattles host)
{
super(
host,
ChallengeType.LastStanding,
"Water Horror",
"TNT is spawning from the water!",
"Use your boat to dodge explosions.");
Settings.setUseMapHeight();
}
@Override
public ArrayList<Location> createSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
int size = getArenaSize();
int platform = size - MAP_SPAWN_SHIFT;
for (int x = -(size); x <= size; x++)
{
for (int z = -(size); z <= size; z++)
{
double absX = Math.abs(x);
double absZ = Math.abs(z);
if ((absX == platform || absZ == platform) && !(absX > platform || absZ > platform))
{
spawns.add(getCenter().add(x, MAP_SPAWN_HEIGHT, z));
}
}
}
return spawns;
}
@Override
public void createMap()
{
int size = getArenaSize();
for (int x = -size; x <= size; x++)
{
for (int z = -size; z <= size; z++)
{
for (int y = 0; y <= MAP_HEIGHT; y++)
{
Block block = getCenter().getBlock().getRelative(x, y, z);
double absX = Math.abs(x);
double absZ = Math.abs(z);
// Bottom Layer
if (y == BEDROCK_LEVEL)
{
setBlock(block, Material.BEDROCK);
}
// Ground Layer
else if (y == SAND_LEVEL)
{
setBlock(block, Material.SAND);
}
else
{
if (y <= MAIN_LEVEL)
{
// Container
if (absX == size || absZ == size)
{
if (y == MAIN_LEVEL)
{
setBlock(block, Material.GRASS);
}
else
{
setBlock(block, Material.DIRT);
}
}
// Water
else if (absX < size || absZ < size)
{
if (y == MAIN_LEVEL)
{
setBlock(block, Material.ICE);
}
else
{
setBlock(block, Material.WATER);
}
}
}
else
{
// Fences
if (absX == size || absZ == size)
{
setBlock(block, Material.FENCE);
}
}
}
addBlock(block);
}
}
}
}
@Override
public void onStart()
{
Host.getArcadeManager().GetExplosion().SetLiquidDamage(false);
_dropsite = getCenter().add(0, DROPSITE_HEIGHT, 0);
_base = _dropsite.clone().subtract(0, DROPSITE_HEIGHT, 0);
for (Player player : getPlayersAlive())
{
Boat boat = player.getWorld().spawn(player.getLocation(), Boat.class);
boat.setPassenger(player);
_boats.put(player, boat);
}
startTNTSpawnTask();
removeIce();
}
@Override
public void onEnd()
{
Host.getArcadeManager().GetExplosion().SetLiquidDamage(true);
remove(EntityType.BOAT);
remove(EntityType.PRIMED_TNT);
_boats.clear();
}
@EventHandler
public void onUpdateEntityTrail(UpdateEvent event)
{
if (!isChallengeValid())
return;
if (event.getType() != UpdateType.TICK)
return;
for (Entity entity : Host.WorldData.World.getEntities())
{
if (entity instanceof TNTPrimed)
{
if (entity.isValid() && !entity.isOnGround())
{
UtilParticle.PlayParticleToAll(ParticleType.FLAME, entity.getLocation(), TNT_PARTICLE_OFFSET, TNT_PARTICLE_OFFSET, TNT_PARTICLE_OFFSET, 0.0F, TNT_PARTICLE_AMOUNT, ViewDist.LONG);
new BukkitRunnable()
{
@Override
public void run()
{
entity.getWorld().playSound(entity.getLocation(), Sound.ORB_PICKUP, TNT_INCOMING_SOUND_VOLUME, TNT_INCOMING_SOUND_PITCH);
}
}.runTaskLater(Host.getArcadeManager().getPlugin(), TICK_MULTIPLIER);
}
}
}
}
@EventHandler
public void onUpdateSpawnerParticle(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
if (!isChallengeValid())
return;
UtilParticle.PlayParticleToAll(ParticleType.FLAME, _dropsite, SPAWNER_FLAME_OFFSET, SPAWNER_FLAME_OFFSET, SPAWNER_FLAME_OFFSET, SPAWNER_FLAME_SPEED, SPAWNER_FLAME_AMOUNT, ViewDist.LONG);
UtilParticle.PlayParticleToAll(ParticleType.CLOUD, _base, SPAWNER_CLOUD_OFFSET, SPAWNER_CLOUD_OFFSET, SPAWNER_CLOUD_OFFSET, 0.0F, SPAWNER_CLOUD_AMOUNT, ViewDist.LONG);
}
@EventHandler
public void onEntityDismount(EntityDismountEvent event)
{
if (!isChallengeValid())
return;
if (event.getEntity() instanceof Boat)
{
event.setCancelled(true);
}
}
@EventHandler
public void onVehicleDestroy(VehicleDestroyEvent event)
{
if (!isChallengeValid())
return;
if (event.getVehicle() instanceof Boat)
{
event.setCancelled(true);
}
}
@EventHandler
public void onExplosion(ExplosionEvent event)
{
if (!isChallengeValid())
return;
event.GetBlocks().clear();
}
@EventHandler
public void onBlockFromTo(BlockFromToEvent event)
{
if (!isChallengeValid())
return;
if (event.getBlock().getType() == Material.ICE)
{
event.setCancelled(true);
}
}
@EventHandler
public void onPlayerDeath(PlayerDeathEvent event)
{
if (!isChallengeValid())
return;
Player player = event.getEntity();
if (!isPlayerValid(player))
return;
player.eject();
Boat boat = _boats.get(player);
boat.remove();
_boats.remove(player);
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event)
{
if (!isChallengeValid())
return;
Player player = event.getPlayer();
if (!isPlayerValid(player))
return;
player.eject();
Boat boat = _boats.get(player);
boat.remove();
_boats.remove(player);
}
private void startTNTSpawnTask()
{
new BukkitRunnable()
{
@Override
public void run()
{
if (!isChallengeValid())
{
cancel();
return;
}
ArrayList<Player> players = getPlayersAlive();
int times = UtilMath.r(TNT_SPAWN_MAX) + TNT_SPAWN_MIN;
if (times > players.size())
times = players.size();
for (int i = 0; i < times; i++)
{
Player target = UtilMath.randomElement(players);
createExplosive(target, _dropsite);
}
_dropsite.getWorld().playSound(_dropsite, Sound.ZOMBIE_WOODBREAK, TNT_SPAWN_SOUND_VOLUME, TNT_SPAWN_SOUND_PITCH);
}
}.runTaskTimer(Host.getArcadeManager().getPlugin(), TNT_SPAWN_INTERVAL * TICK_MULTIPLIER, TNT_SPAWN_INTERVAL * TICK_MULTIPLIER);
}
private void createExplosive(Player player, Location dropsite)
{
Location target = player.getLocation();
TNTPrimed explosive = dropsite.getWorld().spawn(dropsite, TNTPrimed.class);
explosive.setFuseTicks(TNT_EXPLODE_AFTER * TICK_MULTIPLIER);
UtilAction.velocity(
explosive,
UtilAlg.getTrajectory2d(dropsite, target),
UtilAlg.calculateVelocity(dropsite.toVector(), target.toVector(), TNT_VELOCITY_HEIGHT).length() + TNT_VELOCITY_POWER_MIN,
true,
0,
TNT_VELOCITY_HEIGHT,
TNT_VELOCITY_HEIGHT + 1,
false);
}
private void removeIce()
{
int size = getArenaSize();
for (int x = -size; x <= size; x++)
{
for (int z = -size; z <= size; z++)
{
Block block = getCenter().getBlock().getRelative(x, MAIN_LEVEL, z);
if (block.getType() == Material.ICE)
{
setBlock(block, Material.WATER);
}
}
}
}
}

View File

@ -0,0 +1,299 @@
package nautilus.game.arcade.game.games.mineware.challenge.type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
import mineplex.core.common.util.UtilMath;
import mineplex.core.projectile.ProjectileUser;
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;
import nautilus.game.arcade.game.games.mineware.challenge.NumberTracker;
/**
* A challenge based on waves of falling wool blocks that can damage players.
*/
public class ChallengeWaveCrush extends Challenge implements NumberTracker
{
private static final int MAP_SPAWN_SHIFT = 1;
private static final int MAP_HEIGHT = 1;
private static final int MAP_SPAWN_HEIGHT = MAP_HEIGHT + 1;
private static final int MAP_SPAWN_X = -15;
private static final int SPAWN_COORDINATE_MULTIPLE = 2;
private static final int MAP_PLATFORM_X_START = -16;
private static final int MAP_PLATFORM_X_STOP = 13;
private static final int FIRST_WAVE_DELAY = 60; // ticks
private static final int NEXT_WAVE_DELAY = 30; // ticks
private static final int WAVE_LOCATION_MULTIPLIER = 2;
private static final int WAVE_LENGTH_MAX = 5;
private static final float WAVE_BLOCK_HITBOX_GROW = 0.7F;
private static final int WAVE_BLOCK_VELOCITY_Y = 10;
private static final int WAVE_BLOCK_SPAWN_DELAY = 2; // ticks
private static final int WAVE_DELAY_DECREMENT_CRITERIA = 3;
private static final int COLOR_BLOCK_LENGTH = 2;
private static final byte[] COLORS = { 0, 5, 4, 1, 6, 14, 11, 12, 10, 7 };
private int _modifiedNextWaveDelay;
private int _wavesPassed;
private int _colorIndex;
private int _colorCounter;
private Map<Player, Integer> _survivedWaves = new HashMap<>();
private int _arenaStartSize;
public ChallengeWaveCrush(BawkBawkBattles host)
{
super(
host,
ChallengeType.LastStanding,
"Wave Crush",
"Waves of blocks are coming towards you!",
"Avoid getting him by them.");
Settings.setUseMapHeight();
}
@Override
public ArrayList<Location> createSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
int size = getArenaSize() - MAP_SPAWN_SHIFT;
for (int z = -size; z <= size; z++)
{
if (z % SPAWN_COORDINATE_MULTIPLE == 0)
{
spawns.add(getCenter().add(MAP_SPAWN_X, MAP_SPAWN_HEIGHT, z));
}
}
return spawns;
}
@Override
public void createMap()
{
_arenaStartSize = getArenaSize();
for (int x = MAP_PLATFORM_X_START; x <= MAP_PLATFORM_X_STOP; x++)
{
for (int z = -getArenaSize(); z <= getArenaSize(); z++)
{
for (int y = 0; y <= MAP_HEIGHT; y++)
{
Block block = getCenter().getBlock().getRelative(x, y, z);
if (y == 0)
{
setBlock(block, Material.BEDROCK);
}
else
{
setBlock(block, Material.WOOL, getColor());
}
addBlock(block);
}
}
_colorCounter++;
}
}
@Override
public void onStart()
{
_modifiedNextWaveDelay = NEXT_WAVE_DELAY;
for (Player player : getPlayersAlive())
{
_survivedWaves.put(player, 0);
}
startWavesTask();
}
@Override
public void onEnd()
{
remove(EntityType.FALLING_BLOCK);
removeExtraBlocks();
_wavesPassed = 0;
_survivedWaves.clear();
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event)
{
if (!isChallengeValid())
return;
Player player = event.getPlayer();
if (_survivedWaves.containsKey(player))
{
_survivedWaves.remove(player);
}
}
@Override
public void onCollide(LivingEntity target, Block block, ProjectileUser data)
{
if (target instanceof Player && data.getThrown() instanceof FallingBlock)
{
Player player = (Player) target;
if (isPlayerValid(player))
{
Host.Manager.GetDamage().NewDamageEvent(target, null, null, DamageCause.PROJECTILE, player.getHealth(), false, false, false, "Falling Block", "Wave Crush");
}
}
}
private byte getColor()
{
if (_colorCounter > COLOR_BLOCK_LENGTH)
{
_colorCounter = 0;
_colorIndex++;
if (_colorIndex >= COLORS.length)
_colorIndex = 0;
}
return COLORS[_colorIndex];
}
private void startWavesTask()
{
new BukkitRunnable()
{
@Override
public void run()
{
if (!isChallengeValid())
{
cancel();
return;
}
_wavesPassed++;
startWave();
decreaseWaveDelay();
increaseSurvivedWaves();
}
}.runTaskTimer(Host.Manager.getPlugin(), FIRST_WAVE_DELAY, _modifiedNextWaveDelay);
}
private Block getWaveStartBlock()
{
Block block = getCenter().getBlock().getRelative(MAP_PLATFORM_X_STOP, 1, UtilMath.r(getArenaSize() * WAVE_LOCATION_MULTIPLIER) - getArenaSize());
while (block.isEmpty())
{
block = getCenter().getBlock().getRelative(MAP_PLATFORM_X_STOP, 1, UtilMath.r(getArenaSize() * WAVE_LOCATION_MULTIPLIER) - getArenaSize());
}
return block;
}
private void startWave()
{
Block startBlock = getWaveStartBlock();
for (int i = 0; i <= WAVE_LENGTH_MAX; i++)
{
createWaveBlock(startBlock.getLocation().clone().add(0, 0, i).getBlock());
}
}
private void createWaveBlock(final Block block)
{
new BukkitRunnable()
{
Block currentBlock = block;
@SuppressWarnings("deprecation")
@Override
public void run()
{
if (!isChallengeValid() || currentBlock.isEmpty())
{
cancel();
return;
}
Location spawn = currentBlock.getLocation().clone().add(0, 1, 0);
FallingBlock waveBlock = getCenter().getWorld().spawnFallingBlock(spawn, currentBlock.getType(), currentBlock.getData());
Host.Manager.GetProjectile().AddThrow(waveBlock, null, Host, -1, true, false, true, true, WAVE_BLOCK_HITBOX_GROW);
waveBlock.setVelocity(new Vector(0, WAVE_BLOCK_VELOCITY_Y, 0).normalize());
resetBlock(currentBlock);
currentBlock = getCenter().getWorld().getBlockAt(currentBlock.getX() - 1, currentBlock.getY(), currentBlock.getZ());
}
}.runTaskTimer(Host.Manager.getPlugin(), 0, WAVE_BLOCK_SPAWN_DELAY);
}
private void decreaseWaveDelay()
{
if (_wavesPassed % WAVE_DELAY_DECREMENT_CRITERIA == 0 && _modifiedNextWaveDelay > 0)
{
_modifiedNextWaveDelay--;
}
}
private void increaseSurvivedWaves()
{
for (Player player : _survivedWaves.keySet())
{
if (isPlayerValid(player))
{
_survivedWaves.put(player, _survivedWaves.get(player) + 1);
}
}
}
private void removeExtraBlocks()
{
for (int x = MAP_PLATFORM_X_START; x <= MAP_PLATFORM_X_STOP; x++)
{
for (int z = -_arenaStartSize; z <= _arenaStartSize; z++)
{
Block block = getCenter().getBlock().getRelative(x, MAP_SPAWN_HEIGHT, z);
if (!block.isEmpty())
{
resetBlock(block);
}
}
}
}
@Override
public Number getData(Player player)
{
return _survivedWaves.get(player);
}
@Override
public boolean hasData(Player player)
{
return _survivedWaves.containsKey(player);
}
}

View File

@ -0,0 +1,355 @@
package nautilus.game.arcade.game.games.mineware.challenge.type;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityCombustEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.disguise.disguises.DisguiseZombie;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
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;
import nautilus.game.arcade.game.games.mineware.challenge.other.ZombieWrapper;
/**
* A challenge based on zombie survival.
*/
public class ChallengeZombieInfection extends Challenge
{
private ZombieWrapper _zombie;
private Set<Player> _infected = new HashSet<>();
private float _defaultSpeed = 1.3F;
private float _speedIncrement = 0.2F;
private float _speedLimit = 3.1F;
private float _speedAfterInfection = 1.7F;
public ChallengeZombieInfection(BawkBawkBattles host)
{
super(
host,
ChallengeType.LastStanding,
"Zombie Infection",
"Avoid the infected zombie.",
"Infected humans can infect others!");
Settings.setUseMapHeight();
}
@Override
public ArrayList<Location> createSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
for (Location location : circle(getCenter(), getArenaSize(10), 1, true, false, 0))
{
spawns.add(location.add(0, 1, 0));
}
return spawns;
}
@Override
public void createMap()
{
for (Location location : circle(getCenter(), getArenaSize(15), 2, false, false, 0))
{
Block block = location.getBlock();
if (location.getY() == getCenter().getY())
{
double chance = Math.random();
if (chance < 0.5)
{
setBlock(block, Material.DIRT);
if (UtilMath.random.nextBoolean())
{
setData(block, (byte) 1);
}
}
else if (chance > 0.5 && chance < 0.8)
{
setBlock(block, Material.DIRT, (byte) 2);
}
else
{
setBlock(block, Material.GRASS);
}
}
else if (location.getY() == 1 + getCenter().getY())
{
generateGrass(block, true);
}
addBlock(block);
}
}
@Override
public void onStart()
{
Host.DamageEvP = true;
Host.DamagePvP = true;
_zombie = new ZombieWrapper(this);
spawnZombie();
}
@Override
public void onEnd()
{
Host.DamageEvP = false;
Host.DamagePvP = false;
removeZombie();
_infected.clear();
}
@EventHandler
public void onUpdateZombie(UpdateEvent event)
{
if (!isChallengeValid())
return;
if (event.getType() == UpdateType.TICK)
{
if (_zombie.isFrozen())
{
unfreezeZombieWhenNeeded();
}
else if (_zombie.getLocation().getY() < 0)
{
_zombie.getEntity().teleport(getCenter());
}
else if (UtilMath.r(20) == 0)
{
freeze(UtilMath.r(2) + 1 * 1000);
}
else
{
selectTarget();
}
}
else if (event.getType() == UpdateType.FAST)
{
increaseZombieSpeed();
Player target = _zombie.getTarget();
if (target != null)
{
if (UtilMath.offset2d(_zombie.getEntity(), target) <= 2)
{
damage(target);
}
}
}
}
@EventHandler
public void onCustomDamage(CustomDamageEvent event)
{
if (!isChallengeValid())
return;
Player damagee = event.GetDamageePlayer();
if (!isPlayerValid(damagee))
return;
if (_infected.contains(event.GetDamageePlayer()))
{
event.SetCancelled("Infected");
}
else
{
if (event.GetDamage() > damagee.getHealth())
{
damagee.setHealth(0.01);
infect(damagee);
}
else if (!damagee.hasPotionEffect(PotionEffectType.SLOW) && !damagee.hasPotionEffect(PotionEffectType.CONFUSION))
{
damagee.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 20, 1));
damagee.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 60, 1));
}
damagee.playSound(damagee.getLocation(), Sound.SPIDER_IDLE, 2.0F, 1.0F);
}
}
@EventHandler
public void onParticleUpdate(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
if (!isChallengeValid())
return;
showFlames(_zombie.getLocation());
for (Player infected : _infected)
{
showFlames(infected.getLocation());
}
}
@EventHandler
public void onUpdateEndCheck(UpdateEvent event)
{
if (!isChallengeValid())
return;
if (event.getType() != UpdateType.FASTER)
return;
if (_infected.size() >= Settings.getMaxCompletedCount())
{
for (Player player : getPlayersAlive())
{
if (!_infected.contains(player))
{
setCompleted(player);
}
}
}
}
@EventHandler
public void onEntityCombust(EntityCombustEvent event)
{
if (!isChallengeValid())
return;
if (_zombie.getEntity().equals(event.getEntity()))
{
_zombie.extinguish();
event.setCancelled(true);
}
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event)
{
if (!isChallengeValid())
return;
_infected.remove(event.getPlayer());
}
private void spawnZombie()
{
Host.CreatureAllow = true;
_zombie.spawn();
Host.CreatureAllow = false;
_zombie.setSpeed(_defaultSpeed);
_zombie.extinguish();
}
private void removeZombie()
{
if (_zombie != null)
{
if (_zombie.getEntity() != null)
{
_zombie.remove();
}
}
_zombie = null;
}
private void unfreezeZombieWhenNeeded()
{
if (System.currentTimeMillis() > _zombie.getFreezeTime())
{
_zombie.unfreeze();
}
}
private void selectTarget()
{
Player target = UtilPlayer.getClosest(_zombie.getLocation(), (Entity) null);
while (_infected.contains(target))
{
target = UtilMath.randomElement(getPlayersAlive());
}
_zombie.setTarget(target);
_zombie.move(target);
}
private void increaseZombieSpeed()
{
float increasedSpeed = _zombie.getSpeed() + _speedIncrement;
if (increasedSpeed <= _speedLimit)
{
_zombie.setSpeed(increasedSpeed);
}
else
{
_zombie.setSpeed(_defaultSpeed);
}
}
private void showFlames(Location loc)
{
UtilParticle.PlayParticle(ParticleType.FLAME, loc.add(0, 1.5, 0), 0.3F, 0.3F, 0.3F, 0.01F, 1, ViewDist.MAX, UtilServer.getPlayers());
}
private void freeze(long duration)
{
_zombie.setFreezeTime(System.currentTimeMillis() + duration);
_zombie.freeze();
}
private void infect(Player player)
{
if (!_infected.contains(player))
{
player.setHealth(20.0);
_infected.add(player);
_zombie.setSpeed(_speedAfterInfection);
Host.WorldData.World.strikeLightningEffect(player.getLocation());
Host.getArcadeManager().GetDisguise().disguise(new DisguiseZombie(player));
if (_infected.size() < Settings.getMaxCompletedCount()) // Check if the challenge is still running after the player is infected.
{
UtilPlayer.message(player, F.main("Game", "You have been infected, you now have to infect the rest."));
}
}
}
private void damage(Player player)
{
Host.Manager.GetDamage().NewDamageEvent(player, _zombie.getEntity(), null, DamageCause.ENTITY_ATTACK, 5.0, false, false, false, "Attack", "Infection");
}
}

View File

@ -1,4 +1,4 @@
package nautilus.game.arcade.game.games.mineware.challenges;
package nautilus.game.arcade.game.games.mineware.challenge.type;
import java.util.Arrays;
import java.util.Collections;

View File

@ -1,185 +0,0 @@
package nautilus.game.arcade.game.games.mineware.challenges;
import java.util.ArrayList;
import java.util.HashMap;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilFirework;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilShapes;
import mineplex.core.itemstack.ItemBuilder;
import nautilus.game.arcade.game.games.mineware.Challenge;
import nautilus.game.arcade.game.games.mineware.MineWare;
import org.bukkit.FireworkEffect.Type;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.Wool;
import org.bukkit.projectiles.ProjectileSource;
import org.bukkit.scheduler.BukkitRunnable;
public class ChallengeBlockShot extends Challenge
{
private HashMap<String, Integer> _shotBlocks = new HashMap<String, Integer>();
private ArrayList<Location> _spawns = new ArrayList<Location>();
private ArrayList<Entity> _arrows = new ArrayList<Entity>();
public ChallengeBlockShot(MineWare host)
{
super(host, ChallengeType.FirstComplete, "Shoot down 5 blocks");
}
@Override
public ArrayList<Location> getSpawns()
{
return _spawns;
}
@EventHandler
public void onShoot(ProjectileLaunchEvent event)
{
_arrows.add(event.getEntity());
}
@Override
public void cleanupRoom()
{
for (Entity arrow : _arrows)
{
arrow.remove();
}
}
@EventHandler
public void onProjectileHit(final ProjectileHitEvent event)
{
event.getEntity().remove();
new BukkitRunnable()
{
public void run()
{
ProjectileSource shooter = event.getEntity().getShooter();
if (shooter != null && shooter instanceof Player)
{
Player player = (Player) shooter;
for (double x = -0.5; x <= 0.5; x++)
{
for (double y = -0.5; y <= 0.5; y++)
{
for (double z = -0.5; z <= 0.5; z++)
{
Block block = event.getEntity().getLocation().add(x, y, z).getBlock();
if (block.getType() == Material.WOOL)
{
int score = _shotBlocks.get(player.getName()) + 1;
_shotBlocks.put(player.getName(), score);
Location sloc = player.getEyeLocation();
sloc.add(UtilAlg.getTrajectory(sloc, block.getLocation().add(0.5, 0.5, 0.5)).multiply(
Math.min(7, block.getLocation().distance(sloc))));
displayCount(player, sloc, (score >= 5 ? C.cDGreen : score >= 3 ? C.cGreen
: score >= 1 ? C.cRed : C.cDRed)
+ score);
if (score == 5)
{
SetCompleted(player);
}
Location loc = block.getLocation().add(0.5, 0.5, 0.5);
UtilParticle.PlayParticle(ParticleType.LARGE_EXPLODE, loc, 0, 0, 0, 0, 1, ViewDist.MAX,
UtilServer.getPlayers());
spawnBlock();
Wool wool = new Wool(block.getType(), block.getData());
UtilFirework.playFirework(loc, Type.BALL, wool.getColor().getColor(), true, true);
block.setTypeIdAndData(Material.AIR.getId(), (byte) 0, false);
addBlock(block);
return;
}
}
}
}
}
}
}.runTaskLater(Host.Manager.getPlugin(), 0);
}
private void spawnBlock()
{
while (true)
{
Block block = getCenter().add(UtilMath.r(40) - 20, 10 + UtilMath.r(10), UtilMath.r(40) - 20).getBlock();
if (block.getType() == Material.AIR)
{
block.setType(Material.WOOL);
block.setData((byte) UtilMath.r(16));
addBlock(block);
break;
}
}
}
@Override
public void setupPlayers()
{
setBorder(-16, 16, 0, 20, -16, 16);
for (Player player : Host.GetPlayers(true))
{
player.getInventory().setItem(0,
new ItemBuilder(Material.BOW).addEnchantment(Enchantment.ARROW_INFINITE, 1).setUnbreakable(true).build());
player.getInventory().setItem(9, new ItemStack(Material.ARROW));
_shotBlocks.put(player.getName(), 0);
}
}
@Override
public void generateRoom()
{
for (Location loc : UtilShapes.getPointsInCircle(getCenter(), getChallengers().size(), 10))
{
loc = loc.getBlock().getLocation().add(0.5, 7.1, 0.5);
_spawns.add(loc);
Block block = loc.getBlock().getRelative(BlockFace.DOWN);
block.setType(Material.DOUBLE_STEP);
block.setData((byte) 8);
addBlock(block);
}
for (int i = 0; i < 18; i++)
{
spawnBlock();
}
}
}

View File

@ -1,88 +0,0 @@
package nautilus.game.arcade.game.games.mineware.challenges;
import java.util.ArrayList;
import java.util.HashMap;
import nautilus.game.arcade.game.games.mineware.ChallengeSeperateRooms;
import nautilus.game.arcade.game.games.mineware.MineWare;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
public class ChallengeBuildBuilding extends ChallengeSeperateRooms
{
private ArrayList<Material> _materials = new ArrayList<Material>();
private HashMap<Location, Material> _build = new HashMap<Location, Material>();
public ChallengeBuildBuilding(MineWare host, String challengeName)
{
super(host, ChallengeType.FirstComplete, "Replicate the building!");
for (int x = 0; x < 3; x++)
{
for (int y = 0; y < 5; y++)
{
for (int z = 0; z < 3; z++)
{
}
}
}
}
@Override
public void generateRoom(Location loc)
{
// TODO Auto-generated method stub
}
@Override
public int getBorderX()
{
return 10;
}
@Override
public int getBorderY()
{
return 20;
}
@Override
public int getBorderZ()
{
return 10;
}
@Override
public int getDividersX()
{
return 5;
}
@Override
public int getDividersZ()
{
return 5;
}
@Override
public void cleanupRoom()
{
// TODO Auto-generated method stub
}
@Override
public void setupPlayers()
{
for (Player player : getChallengers())
{
player.setGameMode(GameMode.CREATIVE);
}
}
}

View File

@ -1,128 +0,0 @@
package nautilus.game.arcade.game.games.mineware.challenges;
import java.util.ArrayList;
import mineplex.core.common.util.UtilMath;
import nautilus.game.arcade.game.games.mineware.Challenge;
import nautilus.game.arcade.game.games.mineware.MineWare;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Chest;
import org.bukkit.block.DoubleChest;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
public class ChallengeChestLoot extends Challenge
{
public ChallengeChestLoot(MineWare host)
{
super(host, ChallengeType.FirstComplete, "Find a diamond in the chests");
}
@Override
public ArrayList<Location> getSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
for (int x = -7; x <= 7; x++)
{
for (int z = -7; z <= 7; z++)
{
if (x % 2 == 0 && z % 2 == 0)
{
spawns.add(getCenter().clone().add(x, 2.1, z));
}
}
}
return spawns;
}
@Override
public void cleanupRoom()
{
}
@Override
public void setupPlayers()
{
}
@EventHandler
public void onInventoryClick(InventoryClickEvent event)
{
if (!(event.getInventory().getHolder() instanceof Player))
{
event.setCancelled(true);
if (event.getInventory().getHolder() instanceof DoubleChest || event.getInventory().getHolder() instanceof Chest)
{
if (event.getCurrentItem() != null && event.getCurrentItem().getType() == Material.DIAMOND)
{
event.setCurrentItem(new ItemStack(Material.AIR));
SetCompleted((Player) event.getWhoClicked());
}
}
}
}
@Override
public void generateRoom()
{
ArrayList<Inventory> invs = new ArrayList<Inventory>();
for (int x = -7; x <= 7; x++)
{
for (int z = -7; z <= 7; z++)
{
Block b = getCenter().getBlock().getRelative(x, 0, z);
b.setType(Material.STAINED_CLAY);
b.setData((byte) UtilMath.r(16));
addBlock(b);
if (Math.abs(x) % 2 == 0 && Math.abs(z) % 2 == 0)
{
Block block = b.getRelative(0, 1, 0);
block.setType(Material.CHEST);
addBlock(block);
Inventory inventory = ((Chest) block.getState()).getInventory();
invs.add(inventory);
for (int i = 0; i < inventory.getSize(); i++)
{
ItemStack item = new ItemStack(Material.values()[UtilMath.r(Material.values().length)]);
if (item.getType() == Material.DIAMOND || item.getType() == Material.AIR)
{
i--;
continue;
}
inventory.setItem(i, item);
}
}
else
{
Block block = b.getRelative(BlockFace.UP);
block.setType(Material.STAINED_CLAY);
block.setData((byte) UtilMath.r(16));
addBlock(block);
}
}
}
for (int i = 0; i < 10 + getChallengers().size(); i++)
{
Inventory inv = invs.get(UtilMath.r(invs.size()));
inv.setItem(UtilMath.r(inv.getSize()), new ItemStack(Material.DIAMOND));
}
}
}

View File

@ -1,125 +0,0 @@
package nautilus.game.arcade.game.games.mineware.challenges;
import java.util.ArrayList;
import java.util.Iterator;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilShapes;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.game.games.mineware.Challenge;
import nautilus.game.arcade.game.games.mineware.MineWare;
public class ChallengeChickenFishing extends Challenge
{
private ArrayList<Entity> _chickens = new ArrayList<Entity>();
private ArrayList<Location> _spawns = new ArrayList<Location>();
private ArrayList<Location> _chickenSpawns = new ArrayList<Location>();
public ChallengeChickenFishing(MineWare host)
{
super(host, ChallengeType.FirstComplete, "Chicken Fishing");
}
@Override
public ArrayList<Location> getSpawns()
{
return _spawns;
}
@EventHandler
public void onSecond(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST)
{
return;
}
Iterator<Entity> itel = _chickens.iterator();
while (itel.hasNext())
{
Entity ent = itel.next();
// TODO Validate chicken is caught
if (!ent.isValid())
{
itel.remove();
}
}
for (Player player : getChallengers())
{
Block block = player.getLocation().getBlock();
if (block.isLiquid())
{
setLost(player);
}
}
}
@Override
public void cleanupRoom()
{
for (Entity chicken : _chickens)
{
chicken.remove();
}
}
@Override
public void setupPlayers()
{
for (Player player : getChallengers())
{
player.getInventory().addItem(new ItemStack(Material.FISHING_ROD));
}
}
@Override
public void generateRoom()
{
int size = (getChallengers().size() / 2) + 4;
for (Location location : UtilShapes.getCircle(getCenter(), true, size))
{
Block block = location.getBlock();
for (int y = 0; y <= 7; y++)
{
Block b = block.getRelative(0, y, 0);
if (y < 3 || (y < 5 && UtilMath.random.nextBoolean()))
{
b.setType(Material.STONE);
}
else if (y != 7)
{
b.setType(Material.DIRT);
}
else
{
b.setType(Material.GRASS);
}
}
_spawns.add(location.clone().add(0.5, 7.1, 0.5));
}
for (Location location : UtilShapes.getCircle(getCenter(), false,
size - 1))
{
_chickenSpawns.add(location.add(0.5, 0.5, 0.5));
}
}
}

View File

@ -1,168 +0,0 @@
package nautilus.game.arcade.game.games.mineware.challenges;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Chest;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilTime;
import nautilus.game.arcade.game.games.mineware.Challenge;
import nautilus.game.arcade.game.games.mineware.MineWare;
public class ChallengeDiamondFall extends Challenge
{
public ChallengeDiamondFall(MineWare host)
{
super(host, ChallengeType.LastStanding, "Loot the most diamonds from chests!");
}
@Override
public boolean Finish()
{
if (super.Finish())
{
final HashMap<Player, Integer> diamonds = new HashMap<Player, Integer>();
ArrayList<Player> players = getChallengers();
for (Player player : players)
{
int diamond = 0;
for (ItemStack item : UtilInv.getItems(player))
{
if (item != null && item.getType() == Material.DIAMOND)
{
diamond += item.getAmount();
}
}
diamonds.put(player, diamond);
}
Collections.sort(players, new Comparator<Player>()
{
@Override
public int compare(Player o1, Player o2)
{
return diamonds.get(o2).compareTo(diamonds.get(o1));
}
});
for (int places = 0; places < Math.min(players.size(), Places); places++)
{
SetCompleted(players.get(places));
}
}
return super.Finish();
}
@Override
public long getMaxTime()
{
return 30000;
}
@Override
public ArrayList<Location> getSpawns()
{
ArrayList<Location> locations = new ArrayList<Location>();
for (int x = -3; x <= 3; x++)
{
for (int z = -3; z <= 3; z++)
{
locations.add(getCenter().add(x + 0.5, 201.5, z + 0.5));
}
}
return locations;
}
@Override
public void generateRoom()
{
for (int x = -3; x <= 3; x++)
{
for (int z = -3; z <= 3; z++)
{
Block block = getCenter().getBlock().getRelative(x, 200, z);
block.setType(Material.STAINED_GLASS);
addBlock(block);
}
}
for (int x = -5; x <= 5; x++)
{
for (int z = -5; z <= 5; z++)
{
Block block = getCenter().getBlock().getRelative(x, 0, z);
block.setType(Material.STAINED_CLAY);
block.setData((byte) UtilMath.r(16));
addBlock(block);
}
}
for (int i = 0; i < 70; i++)
{
int y = UtilMath.r(160) + 10;
Block b = getCenter().getBlock().getRelative(UtilMath.r(16) - 8, y, UtilMath.r(16) - 8);
boolean chestFound = false;
for (BlockFace face : new BlockFace[]
{
BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH
})
{
Block block = b.getRelative(face);
if (block.getType() != Material.AIR)
{
chestFound = true;
break;
}
}
if (chestFound)
{
continue;
}
b.setType(Material.CHEST);
addBlock(b);
Inventory inventory = ((Chest) b.getState()).getInventory();
for (int a = 0; a < UtilMath.r(5); a++)
{
inventory.setItem(UtilMath.r(inventory.getSize()), new ItemStack(Material.DIAMOND));
}
}
}
@Override
public void cleanupRoom()
{
}
@Override
public void setupPlayers()
{
}
}

View File

@ -1,176 +0,0 @@
package nautilus.game.arcade.game.games.mineware.challenges;
import java.util.ArrayList;
import java.util.HashMap;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.itemstack.ItemBuilder;
import nautilus.game.arcade.game.games.mineware.Challenge;
import nautilus.game.arcade.game.games.mineware.MineWare;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
public class ChallengeDragonEgg extends Challenge
{
private HashMap<String, Integer> _smashedEggs = new HashMap<String, Integer>();
private ArrayList<Entity> _dragonEggs = new ArrayList<Entity>();
public ChallengeDragonEgg(MineWare host)
{
super(host, ChallengeType.FirstComplete, "Whack a dragon egg 10 times");
}
@Override
public ArrayList<Location> getSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
for (int x = -14; x < 15; x++)
{
for (int z = -14; z < 15; z++)
{
if (x % 2 == 0 && z % 2 == 0)
{
spawns.add(getCenter().clone().add(x, 1.1, z));
}
}
}
return spawns;
}
@EventHandler
public void onBlockHit(PlayerInteractEvent event)
{
if (event.getAction() != Action.LEFT_CLICK_BLOCK
&& event.getAction() != Action.RIGHT_CLICK_BLOCK)
{
return;
}
if (UtilPlayer.isSpectator(event.getPlayer()))
{
return;
}
Block block = event.getClickedBlock();
if (block.getType() != Material.DRAGON_EGG)
{
return;
}
event.setCancelled(true);
block.setType(Material.AIR);
UtilParticle.PlayParticle(ParticleType.PORTAL,
block.getLocation().add(0.5, 0.5, 0.5), 0.5F, 0.5F, 0.5F, 0,
11, ViewDist.MAX, UtilServer.getPlayers());
Host.CreatureAllowOverride = true;
for (int i = 0; i < 10; i++)
{
Block b = getCenter().clone()
.add(UtilMath.r(30) - 15, 1, UtilMath.r(30) - 15)
.getBlock();
if (b.getType() == Material.AIR)
{
Entity entity = getCenter().getWorld().spawnFallingBlock(
b.getLocation().add(0.5, 2, 0.5), Material.DRAGON_EGG,
(byte) 0);
_dragonEggs.add(entity);
for (int y = 0; y <= 2; y++)
{
addBlock(b.getRelative(0, y, 0));
}
break;
}
}
Host.CreatureAllowOverride = false;
Player player = event.getPlayer();
int score = _smashedEggs.get(player.getName()) + 1;
displayCount(player, block.getLocation().add(0.5, 1, 0.5),
(score >= 10 ? C.cDGreen : score >= 7 ? C.cGreen
: score >= 4 ? C.cRed : C.cDRed)
+ score);
_smashedEggs.put(player.getName(), score);
if (score == 10)
{
SetCompleted(player);
}
}
@Override
public void cleanupRoom()
{
for (Entity ent : _dragonEggs)
{
ent.remove();
}
}
@Override
public void setupPlayers()
{
setBorder(-18, 18, 0, 20, -18, 18);
for (Player player : getChallengers())
{
_smashedEggs.put(player.getName(), 0);
player.getInventory().setItem(
0,
new ItemBuilder(Material.IRON_AXE).setTitle(
C.cWhite + "Egg Smasher").build());
}
}
@Override
public void generateRoom()
{
for (int x = -15; x <= 15; x++)
{
for (int z = -15; z <= 15; z++)
{
Block b = getCenter().getBlock().getRelative(x, 0, z);
b.setType(Material.WOOL);
b.setData((byte) UtilMath.r(16));
addBlock(b);
}
}
for (int i = 0; i < 9; i++)
{
Block b = getCenter().getBlock().getRelative(UtilMath.r(30) - 15,
1, UtilMath.r(30) - 15);
b.setType(Material.DRAGON_EGG);
addBlock(b);
}
}
}

View File

@ -1,160 +0,0 @@
package nautilus.game.arcade.game.games.mineware.challenges;
import java.util.ArrayList;
import java.util.HashMap;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.game.games.mineware.Challenge;
import nautilus.game.arcade.game.games.mineware.MineWare;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
public class ChallengeHitTargets extends Challenge
{
private HashMap<String, ArrayList<String>> _targets = new HashMap<String, ArrayList<String>>();
private int _targetsEach;
public ChallengeHitTargets(MineWare host)
{
super(host, ChallengeType.FirstComplete, "Hit the chosen players");
}
@EventHandler
public void onDamage(CustomDamageEvent event)
{
Player p = event.GetDamagerPlayer(true);
if (p == null || UtilPlayer.isSpectator(p))
return;
if (event.GetDamageePlayer() == null)
return;
if (!_targets.containsKey(p.getName()))
return;
event.SetCancelled("No damage");
String name = event.GetDamageePlayer().getName();
ArrayList<String> targets = _targets.get(p.getName());
if (!targets.remove(name))
{
p.playSound(p.getLocation(), Sound.NOTE_PLING, 1f, 1f);
UtilPlayer.message(p, C.cYellow + "They are not your target! " + getMessage(p));
return;
}
displayCount(p, event.GetDamageeEntity().getEyeLocation().add(0, 0.3, 0), (targets.isEmpty() ? C.cDGreen
: targets.size() == 1 ? C.cRed : C.cDRed) + (_targetsEach - targets.size()));
if (targets.isEmpty())
{
SetCompleted(p);
}
}
@Override
public String getMessage(Player player)
{
return C.cYellow + "Hit the players " + C.cWhite
+ StringUtils.join(_targets.get(player.getName()), C.cYellow + ", " + C.cWhite);
}
@Override
public int getMinPlayers()
{
return 4;
}
@Override
public ArrayList<Location> getSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
for (int x = -8; x <= 8; x++)
{
for (int z = -8; z <= 8; z++)
{
if (x % 2 == 0 && z % 2 == 0)
{
spawns.add(getCenter().clone().add(x + 0.5, 1.1, z + 0.5));
}
}
}
return spawns;
}
@Override
public void cleanupRoom()
{
Host.DamagePvP = false;
}
@Override
public void setupPlayers()
{
Host.DamagePvP = true;
ArrayList<Player> players = getChallengers();
for (Player player : players)
{
ArrayList<String> names = new ArrayList<String>();
for (Player p : players)
{
if (p != player)
{
names.add(p.getName());
}
}
while (names.size() > 3)
{
names.remove(UtilMath.r(names.size()));
}
_targetsEach = names.size();
_targets.put(player.getName(), names);
}
}
@Override
public void generateRoom()
{
for (int x = -12; x <= 12; x++)
{
for (int z = -12; z <= 12; z++)
{
Block b = getCenter().clone().add(x, 0, z).getBlock();
b.setType(Material.SMOOTH_BRICK);
addBlock(b);
if (Math.abs(x) > 1 && Math.abs(x) < 8 && Math.abs(z) > 1 && Math.abs(z) < 8)
{
for (int y = 1; y < 3; y++)
{
Block block = b.getRelative(0, y, 0);
block.setType(Material.SMOOTH_BRICK);
block.setData((byte) (UtilMath.r(8) < 7 ? 0 : UtilMath.r(2) + 1));
addBlock(block);
}
}
}
}
}
}

View File

@ -1,196 +0,0 @@
package nautilus.game.arcade.game.games.mineware.challenges;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.disguise.disguises.DisguiseMagmaCube;
import mineplex.core.disguise.disguises.DisguiseVillager;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.game.games.mineware.Challenge;
import nautilus.game.arcade.game.games.mineware.MineWare;
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.Player;
import org.bukkit.event.EventHandler;
public class ChallengeLavaRun extends Challenge
{
private long _delay;
private long _minusDelay = 1000;
private int _disappearingBlocks = 10;
private Location _obsidian;
public ChallengeLavaRun(MineWare host)
{
super(host, ChallengeType.LastStanding, "The lava is coming! Stand on the obsidian!");
}
@Override
public ArrayList<Location> getSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
for (int x = -7; x <= 7; x++)
{
for (int z = -7; z <= 7; z++)
{
spawns.add(getCenter().clone().add(x + 0.5, 2, z + 0.5));
}
}
return spawns;
}
@EventHandler
public void onDamage(CustomDamageEvent event)
{
if (event.GetDamagerEntity(true) != null)
{
return;
}
event.AddMod("Ensure Death", null, 9999, false);
}
@EventHandler
public void onTick(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
{
return;
}
if (_delay > System.currentTimeMillis())
return;
if (_obsidian == null)
{
_obsidian = getCenter().add(UtilMath.r(21) - 9.5, 1, UtilMath.r(21) - 9.5);
for (int x = -10; x <= 10; x++)
{
for (int z = -10; z <= 10; z++)
{
Block b = getCenter().getBlock().getRelative(x, 1, z);
b.setType(Material.GLASS);
addBlock(b);
}
}
_obsidian.getBlock().setType(Material.OBSIDIAN);
for (Player player : UtilServer.getPlayers())
player.playSound(player.getLocation(), Sound.NOTE_PIANO, 2f, 0f);
_delay = System.currentTimeMillis() + _minusDelay;
_minusDelay -= 100;
_disappearingBlocks++;
}
else
{
ArrayList<Block> glassBlocks = new ArrayList<Block>();
for (int x = -10; x <= 10; x++)
{
for (int z = -10; z <= 10; z++)
{
Block b = getCenter().getBlock().getRelative(x, 1, z);
if (b.getType() == Material.GLASS)
{
glassBlocks.add(b);
}
}
}
if (glassBlocks.isEmpty())
{
_delay = System.currentTimeMillis() + 1500;
_obsidian = null;
}
else
{
final HashMap<Block, Double> distance = new HashMap<Block, Double>();
for (Block b : glassBlocks)
{
distance.put(b, b.getLocation().add(0.5, 0, 0.5).distance(_obsidian));
}
Collections.sort(glassBlocks, new Comparator<Block>()
{
@Override
public int compare(Block o1, Block o2)
{
return distance.get(o2).compareTo(distance.get(o1));
}
});
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);
}
}
}
}
@Override
public void cleanupRoom()
{
}
@Override
public void setupPlayers()
{
_delay = System.currentTimeMillis() + 2000;
for (Player player : getChallengers())
{
DisguiseMagmaCube disguise = new DisguiseMagmaCube(player);
disguise.SetSize(2);
Host.getArcadeManager().GetDisguise().disguise(disguise);
}
}
@Override
public void generateRoom()
{
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

@ -1,248 +0,0 @@
package nautilus.game.arcade.game.games.mineware.challenges;
import java.util.ArrayList;
import java.util.HashMap;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.disguise.disguises.DisguiseVillager;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.game.games.mineware.Challenge;
import nautilus.game.arcade.game.games.mineware.MineWare;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.entity.Cow;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Villager;
import org.bukkit.entity.Villager.Profession;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.inventory.ItemStack;
public class ChallengeMilkACow extends Challenge
{
private Villager _villager;
private HashMap<Entity, ArrayList<String>> _milked = new HashMap<Entity, ArrayList<String>>();
private HashMap<String, Integer> _score = new HashMap<String, Integer>();
public ChallengeMilkACow(MineWare host)
{
super(host, ChallengeType.FirstComplete, "Milk 5 different cows and deliver to the villager!");
}
@Override
public void cleanupRoom()
{
for (Entity cow : _milked.keySet())
{
cow.remove();
}
_villager.remove();
}
@EventHandler
public void Damage(CustomDamageEvent event)
{
if (event.GetProjectile() == null)
return;
Player player = event.GetDamagerPlayer(true);
if (player == null)
return;
LivingEntity ent = event.GetDamageeEntity();
if (!(ent instanceof Player))
{
event.SetCancelled("Non-Combat Entity");
}
}
@Override
public void setupPlayers()
{
setBorder(-16, 16, 0, 10, -16, 16);
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.getName(), 0);
}
}
@Override
public void generateRoom()
{
for (int x = -16; x <= 16; x++)
{
for (int z = -16; z <= 16; 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) == 16 || Math.abs(z) == 16)
{
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", "Jorge", "Jim"
};
if (UtilMath.r(5) == 0)
{
names = new String[]
{
"Moosworth", "Mooington", "Mooley", "Moose", "Mooskee", "Chicken", "Mooffy", "Moozzle"
};
}
for (int i = 0; i < 8; i++)
{
Location loc = getCenter().clone().add(UtilMath.r(26) - 13, 1, UtilMath.r(26) - 13);
Cow cow = (Cow) loc.getWorld().spawnEntity(loc, EntityType.COW);
cow.setCustomName(C.cWhite + names[i]);
cow.setCustomNameVisible(true);
_milked.put(cow, new ArrayList<String>());
}
Host.CreatureAllowOverride = false;
}
@EventHandler
public void onEntityInteract(PlayerInteractEntityEvent event)
{
Player p = event.getPlayer();
if (UtilPlayer.isSpectator(p))
{
return;
}
if (!Host.IsLive())
{
return;
}
ItemStack item = p.getItemInHand();
if (item == null)
return;
Entity ent = event.getRightClicked();
if (_milked.containsKey(ent))
{
if (item.getType() == Material.BUCKET)
{
if (!_milked.get(ent).contains(p.getName()))
{
p.setItemInHand(new ItemStack(Material.MILK_BUCKET));
_milked.get(ent).add(p.getName());
}
else
{
p.updateInventory();
}
}
event.setCancelled(true);
}
else if (ent == _villager)
{
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.getName()) + 1;
_score.put(p.getName(), 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);
if (score == 5)
{
SetCompleted(p);
}
}
event.setCancelled(true);
}
}
@EventHandler
public void onConsume(PlayerItemConsumeEvent event)
{
event.setCancelled(true);
event.getPlayer().updateInventory();
}
@Override
public ArrayList<Location> getSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
for (int x = -13; x <= 13; x++)
{
for (int z = -13; z <= 13; z++)
{
if (x % 2 == 0 && z % 2 == 0)
{
spawns.add(getCenter().clone().add(x + 0.5, 1.1, z + 0.5));
}
}
}
return spawns;
}
}

View File

@ -1,371 +0,0 @@
package nautilus.game.arcade.game.games.mineware.challenges;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map.Entry;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.game.games.mineware.ChallengeSeperateRooms;
import nautilus.game.arcade.game.games.mineware.MineWare;
public class ChallengeNameThatSound extends ChallengeSeperateRooms
{
private HashMap<EntityType, Sound[]> _sounds = new HashMap<EntityType, Sound[]>();
private ArrayList<Entry<Entry<EntityType, Sound>, Float>> _toPlay = new ArrayList<Entry<Entry<EntityType, Sound>, Float>>();
private HashMap<String, Integer> _currentState = new HashMap<String, Integer>();
private HashMap<String, ArrayList<Entity>> _mobs = new HashMap<String, ArrayList<Entity>>();
private HashMap<String, Long> _lastGuess = new HashMap<String, Long>();
public ChallengeNameThatSound(MineWare host)
{
super(host, ChallengeType.FirstComplete, "Hit the creature that makes the noises");
_sounds.put(EntityType.ZOMBIE, new Sound[]
{
Sound.ZOMBIE_DEATH, Sound.ZOMBIE_HURT, Sound.ZOMBIE_IDLE, Sound.ZOMBIE_INFECT, Sound.ZOMBIE_METAL,
Sound.ZOMBIE_REMEDY, Sound.ZOMBIE_UNFECT
});
_sounds.put(EntityType.PIG, new Sound[]
{
Sound.PIG_DEATH, Sound.PIG_IDLE
});
_sounds.put(EntityType.CHICKEN, new Sound[]
{
Sound.CHICKEN_EGG_POP, Sound.CHICKEN_HURT, Sound.CHICKEN_IDLE
});
/*_sounds.put(EntityType.SPIDER, new Sound[]
{
Sound.SPIDER_DEATH, Sound.SPIDER_IDLE
});*/
_sounds.put(EntityType.IRON_GOLEM, new Sound[]
{
Sound.IRONGOLEM_DEATH, Sound.IRONGOLEM_HIT, Sound.IRONGOLEM_THROW
});
_sounds.put(EntityType.ENDERMAN, new Sound[]
{
Sound.ENDERMAN_DEATH, Sound.ENDERMAN_HIT, Sound.ENDERMAN_IDLE, Sound.ENDERMAN_SCREAM, Sound.ENDERMAN_TELEPORT
});
_sounds.put(EntityType.COW, new Sound[]
{
Sound.COW_HURT, Sound.COW_IDLE, Sound.COW_WALK
});
_sounds.put(EntityType.HORSE, new Sound[]
{
Sound.HORSE_ANGRY, Sound.HORSE_BREATHE, Sound.HORSE_DEATH, Sound.HORSE_GALLOP, Sound.HORSE_ARMOR,
Sound.HORSE_HIT, Sound.HORSE_IDLE
});
_sounds.put(EntityType.OCELOT, new Sound[]
{
Sound.CAT_HISS, Sound.CAT_HIT, Sound.CAT_MEOW, Sound.CAT_PURR, Sound.CAT_PURREOW
});
_sounds.put(EntityType.VILLAGER, new Sound[]
{
Sound.VILLAGER_DEATH, Sound.VILLAGER_HAGGLE, Sound.VILLAGER_HIT, Sound.VILLAGER_IDLE, Sound.VILLAGER_NO,
Sound.VILLAGER_YES
});
_sounds.put(EntityType.WOLF, new Sound[]
{
Sound.WOLF_BARK, Sound.WOLF_DEATH, Sound.WOLF_GROWL, Sound.WOLF_HURT, Sound.WOLF_PANT, Sound.WOLF_SHAKE,
Sound.WOLF_WHINE
});
_sounds.put(EntityType.PIG_ZOMBIE, new Sound[]
{
Sound.ZOMBIE_PIG_ANGRY, Sound.ZOMBIE_PIG_DEATH, Sound.ZOMBIE_PIG_HURT, Sound.ZOMBIE_PIG_IDLE
});
_sounds.put(EntityType.SHEEP, new Sound[]
{
Sound.SHEEP_IDLE
});
_sounds.put(EntityType.SKELETON, new Sound[]
{
Sound.SKELETON_DEATH, Sound.SKELETON_HURT, Sound.SKELETON_IDLE
});
/*_sounds.put(EntityType.SLIME, new Sound[]
{
Sound.SLIME_ATTACK, Sound.SLIME_WALK, Sound.SLIME_WALK2, Sound.MAGMACUBE_JUMP, Sound.MAGMACUBE_WALK,
Sound.MAGMACUBE_WALK2
});*/
while (_toPlay.size() < 3)
{
EntityType entityType = EntityType.values()[UtilMath.r(EntityType.values().length)];
if (!_sounds.containsKey(entityType))
{
continue;
}
boolean allClear = true;
for (Entry<Entry<EntityType, Sound>, Float> entry : _toPlay)
{
if (entry.getKey().getKey() == entityType)
{
allClear = false;
break;
}
}
if (!allClear)
{
continue;
}
Sound sound = _sounds.get(entityType)[UtilMath.r(_sounds.get(entityType).length)];
_toPlay.add(new HashMap.SimpleEntry(new HashMap.SimpleEntry(entityType, sound), UtilMath.random.nextFloat() + 0.5));
}
}
private void spawnMobs(Player player, int stage)
{
if (!_mobs.containsKey(player.getName()))
{
return;
}
for (Entity entity : _mobs.get(player.getName()))
{
entity.remove();
}
if (stage > 2)
return;
ArrayList<EntityType> entityType = new ArrayList<EntityType>();
for (EntityType type : _sounds.keySet())
{
entityType.add(type);
}
entityType.remove(_toPlay.get(stage).getKey().getKey());
while (entityType.size() > 8)
{
entityType.remove(UtilMath.r(entityType.size()));
}
entityType.add(_toPlay.get(stage).getKey().getKey());
Collections.shuffle(entityType);
Host.CreatureAllowOverride = true;
int i = 0;
for (int x = 1; x <= 9; x++)
{
for (int z = 1; z <= 9; z++)
{
if ((x == 3 && z == 3) || (x % 3 != 0 || z % 3 != 0))
continue;
Location loc = getRoom(player).add(x, 1.1, z);
Entity entity = loc.getWorld().spawnEntity(loc, entityType.get(i++));
UtilEnt.Vegetate(entity, true);
_mobs.get(player.getName()).add(entity);
}
}
Host.CreatureAllowOverride = false;
}
@EventHandler
public void onInteract(PlayerInteractEntityEvent event)
{
event.setCancelled(true);
Player player = event.getPlayer();
if (UtilPlayer.isSpectator(player))
return;
if (_lastGuess.containsKey(player.getName()) && !UtilTime.elapsed(_lastGuess.get(player.getName()), 3000))
{
player.sendMessage(F.main(
"Guess",
"Wait "
+ UtilTime.convertString((_lastGuess.get(player.getName()) + 3000) - System.currentTimeMillis(), 1,
TimeUnit.SECONDS) + " before next guess"));
return;
}
EntityType entityType = event.getRightClicked().getType();
int stage = _currentState.get(player.getName());
if (_toPlay.get(stage).getKey().getKey() == entityType)
{
stage++;
displayCount(player, event.getRightClicked().getLocation(), stage == 1 ? C.cRed : stage == 2 ? C.cGreen : C.cDGreen);
spawnMobs(player, stage);
if (stage < 3)
{
player.playSound(player.getLocation(), _toPlay.get(stage).getKey().getValue(), 5, _toPlay.get(stage).getValue());
}
else
{
SetCompleted(player);
}
}
else
{
_lastGuess.put(player.getName(), System.currentTimeMillis());
player.playSound(player.getLocation(), Sound.NOTE_BASS_DRUM, 2, 0);
player.sendMessage(F.main("Name that sound", "Bad guess!"));
}
}
@EventHandler
public void onTwoSeconds(UpdateEvent event)
{
if (event.getType() != UpdateType.TWOSEC)
{
return;
}
for (Player player : getChallengers())
{
int stage = _currentState.get(player.getName());
if (stage < 3)
{
player.playSound(player.getLocation(), _toPlay.get(stage).getKey().getValue(), 5, _toPlay.get(stage).getValue());
}
}
}
@EventHandler
public void onAttack(CustomDamageEvent event)
{
if (event.GetDamagerPlayer(true) == null)
{
return;
}
onInteract(new PlayerInteractEntityEvent(event.GetDamagerPlayer(true), event.GetDamageeEntity()));
event.SetCancelled("No damage");
event.GetDamageeEntity().setFireTicks(0);
}
@Override
public void generateRoom(Location loc)
{
for (int x = 0; x <= 10; x++)
{
for (int z = 0; z <= 10; z++)
{
if (x == 0 || x == 10 || z == 0 || z == 10)
{
for (int y = 1; y <= 5; y++)
{
Block b = loc.getBlock().getRelative(x, y, z);
b.setType(Material.COAL_BLOCK);
addBlock(b);
}
}
Block b = loc.getBlock().getRelative(x, 0, z);
b.setType(Material.WOOL);
addBlock(b);
}
}
}
@Override
public int getBorderX()
{
return 10;
}
@Override
public int getBorderY()
{
return 10;
}
@Override
public int getBorderZ()
{
return 10;
}
@Override
public int getDividersX()
{
return 5;
}
@Override
public int getDividersZ()
{
return 5;
}
@Override
public void cleanupRoom()
{
for (ArrayList<Entity> entityList : _mobs.values())
{
for (Entity entity : entityList)
{
entity.remove();
}
}
}
@Override
public void setupPlayers()
{
for (Player player : getChallengers())
{
_currentState.put(player.getName(), 0);
_mobs.put(player.getName(), new ArrayList<Entity>());
spawnMobs(player, 0);
player.playSound(player.getLocation(), _toPlay.get(0).getKey().getValue(), 5, _toPlay.get(0).getValue());
}
}
}

View File

@ -1,246 +0,0 @@
package nautilus.game.arcade.game.games.mineware.challenges;
import java.util.ArrayList;
import mineplex.core.common.util.UtilPlayer;
import nautilus.game.arcade.game.games.mineware.Challenge;
import nautilus.game.arcade.game.games.mineware.MineWare;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerMoveEvent;
public class ChallengeNavigateMaze extends Challenge
{
public ChallengeNavigateMaze(MineWare host)
{
super(host, ChallengeType.FirstComplete, "Go to the other side of the maze");
}
@Override
public ArrayList<Location> getSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
for (int z = -9; z <= 12; z++)
{
Location loc = getCenter().clone().add(-16, 1.1, z);
spawns.add(loc);
}
return spawns;
}
@EventHandler
public void onMove(PlayerMoveEvent event)
{
if (UtilPlayer.isSpectator(event.getPlayer()))
return;
if (event.getTo().getY() >= 1 && event.getTo().getX() > 16)
{
SetCompleted(event.getPlayer());
}
}
@Override
public void cleanupRoom()
{
}
@Override
public void setupPlayers()
{
setBorder(-20, 22, 0, 10, -20, 22);
}
@Override
public void generateRoom()
{
for (int x = -18; x <= 21; x++)
{
for (int z = -12; z <= 15; z++)
{
Block b = getCenter().getBlock().getRelative(x, 0, z);
if (z == -12 || z == 15)
{
for (int y = 1; y <= 3; y++)
{
Block block = b.getRelative(0, y, 0);
block.setType(Material.STONE);
block.setData((byte) 0);
addBlock(block);
}
}
if (x > 15 || x < -12)
{
b.setType(Material.WOOL);
b.setData((byte) (x < 0 ? 14 : 13));
}
else
{
b.setType(Material.STONE);
b.setData((byte) 0);
Block block = b.getRelative(0, 4, 0);
if (block.getX() == -12)
{
block.setType(Material.STONE);
block.setData((byte) 0);
}
else
{
block.setType(Material.STAINED_GLASS);
block.setData((byte) 8);
}
addBlock(block);
}
addBlock(b);
}
}
for (int i = 0; i < 30; i++)
{
ArrayList<Block> mazeBlocks = generateMaze();
if (mazeValid())
{
for (Block b : mazeBlocks)
{
addBlock(b);
}
break;
}
else
{
System.out.print("Generated bad maze, trying again..");
for (Block b : mazeBlocks)
{
b.setTypeIdAndData(Material.AIR.getId(), (byte) 0, false);
}
}
}
}
private boolean mazeValid()
{
ArrayList<Block> blocks = new ArrayList<Block>();
ArrayList<Block> nextLoop = new ArrayList<Block>();
nextLoop.add(getCenter().getBlock().getRelative(-15, 1, 0));
blocks.addAll(nextLoop);
while (!nextLoop.isEmpty())
{
Block block = nextLoop.remove(0);
for (BlockFace face : new BlockFace[]
{
BlockFace.EAST, BlockFace.WEST, BlockFace.SOUTH, BlockFace.NORTH
})
{
Block b = block.getRelative(face);
if (blocks.contains(b))
continue;
blocks.add(b);
if (b.getType() == Material.STONE || b.getX() < -14 || b.getZ() < -12 || b.getZ() > 15)
continue;
if (b.getX() >= 15)
{
return true;
}
nextLoop.add(b);
}
}
return false;
}
private ArrayList<Block> generateMaze()
{
ArrayList<Block> blocks = new ArrayList<Block>();
int[][] maze = new MazeGenerator(11, 10).getMaze();
// Divisable by 2's are up and down walls
// Other's are left and right. All walls have a corner block.
// This means I need to loop over all of the blocks, figure out if its a corner if yes then set block
// Else if its a wall, then figure out if I'm making the wall or not
for (int x = 1; x < 11; x++)
{
for (int z = 1; z < 10; z++)
{
Block b = getCenter().getBlock().getRelative((x - 5) * 3, 1, (z - 5) * 3);
for (int y = 0; y < 3; y++)
{
Block block = b.getRelative(0, y, 0);
if (block.getType() == Material.STONE)
continue;
block.setType(Material.STONE);
block.setData((byte) 0);
blocks.add(block);
}
// Set blocks for x
if (x < 10 && (maze[x][z] & 8) == 0)
{
for (int i = 1; i <= 2; i++)
{
for (int y = 0; y < 3; y++)
{
Block block = b.getRelative(i, y, 0);
if (block.getType() == Material.STONE)
continue;
block.setType(Material.STONE);
block.setData((byte) 0);
blocks.add(block);
}
}
}
// Set blocks for z
if ((maze[x][z] & 1) == 0)
{
for (int i = 1; i <= 2; i++)
{
for (int y = 0; y < 3; y++)
{
Block block = b.getRelative(0, y, i);
if (block.getType() == Material.STONE)
continue;
block.setType(Material.STONE);
block.setData((byte) 0);
blocks.add(block);
}
}
}
}
}
return blocks;
}
}

View File

@ -1,190 +0,0 @@
package nautilus.game.arcade.game.games.mineware.challenges;
import java.util.ArrayList;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTextBottom;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.game.games.mineware.Challenge;
import nautilus.game.arcade.game.games.mineware.MineWare;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
public class ChallengePickASide extends Challenge
{
private long _stageExpires;
private long _lastSound;
private boolean _isFalling;
public ChallengePickASide(MineWare host)
{
super(host, ChallengeType.LastStanding, "Stand on the side with the least players! Don't be caught on the white blocks!");
}
public int getMinPlayers()
{
return 3;
}
@Override
public ArrayList<Location> getSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
for (int x = -8; x <= 8; x++)
{
for (int z = -8; z <= 8; z++)
{
if (x % 2 == 0 && z % 2 == 0)
{
spawns.add(getCenter().clone().add(x + 0.5, 1.1, z + 0.5));
}
}
}
return spawns;
}
@Override
public void cleanupRoom()
{
}
@Override
public void setupPlayers()
{
setBorder(-10, 10, 0, 10, -10, 10);
_stageExpires = System.currentTimeMillis() + 4000;
}
@EventHandler
public void OnTick(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
{
return;
}
if (!Host.IsLive())
{
return;
}
Player[] players = getChallengers().toArray(new Player[0]);
if (_stageExpires < System.currentTimeMillis())
{
UtilTextBottom.displayProgress(0, players);
if (_isFalling)
{
_isFalling = false;
_stageExpires = System.currentTimeMillis() + 1500;
}
else
{
_isFalling = true;
_stageExpires = System.currentTimeMillis() + 4000;
ArrayList<Player> red = new ArrayList<Player>();
ArrayList<Player> blue = new ArrayList<Player>();
ArrayList<Player> misc = new ArrayList<Player>();
for (Player player : getChallengers())
{
Location loc = player.getLocation();
loc.setY(0);
byte data = loc.getBlock().getType() == Material.STAINED_CLAY ? loc.getBlock().getData() : 0;
if (data == 14)
{
red.add(player);
}
else if (data == 11)
{
blue.add(player);
}
else
{
misc.add(player);
}
}
Host.Announce(C.cRed + "RED: " + red.size(), true);
Host.Announce(C.cRed + "BLUE: " + blue.size(), false);
if (misc.size() > 0)
{
Host.Announce(C.cRed + "MISC: " + misc.size(), false);
}
if (!red.isEmpty() && !blue.isEmpty())
{
if (red.size() < blue.size())
{
misc.addAll(blue);
}
else if (blue.size() < red.size())
{
misc.addAll(red);
}
for (Player player : misc)
{
setLost(player);
}
}
}
}
else if (!_isFalling)
{
UtilTextBottom.displayProgress(1 - ((_stageExpires - System.currentTimeMillis()) / 8000D), players);
if (_lastSound < System.currentTimeMillis())
{
_lastSound = System.currentTimeMillis() + 1000;
for (Player player : UtilServer.getPlayers())
player.playSound(player.getLocation(), Sound.NOTE_STICKS, 1f, 1f);
}
}
else
{
UtilTextBottom.displayProgress(0, players);
}
}
@Override
public void generateRoom()
{
for (int x = -10; x <= 10; x++)
{
for (int z = -10; z <= 10; z++)
{
for (int y = 0; y <= 2; y++)
{
Block b = getCenter().getBlock().getRelative(x, y, z);
if (y == 0 || Math.abs(x) == 10 || Math.abs(z) == 10)
{
if (y > 0 && Math.abs(z) != 10)
continue;
b.setType(Material.STAINED_CLAY);
b.setData((byte) (z < 0 ? 11 : z > 0 ? 14 : 0));
addBlock(b);
}
}
}
}
}
}

View File

@ -1,175 +0,0 @@
package nautilus.game.arcade.game.games.mineware.challenges;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Entity;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import mineplex.core.common.util.MapUtil;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilTime;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.game.games.mineware.Challenge;
import nautilus.game.arcade.game.games.mineware.MineWare;
public class ChallengeRunner extends Challenge
{
private ArrayList<Entity> _fallingBlocks = new ArrayList<Entity>();
public ChallengeRunner(MineWare host)
{
super(host, ChallengeType.LastStanding,
"Blocks are disappearing beneath you! Run away!");
}
@Override
public ArrayList<Location> getSpawns()
{
return _spawns;
}
@Override
public void cleanupRoom()
{
for (Entity ent : _fallingBlocks)
{
ent.remove();
}
}
@Override
public void setupPlayers()
{
}
private ArrayList<Location> _spawns = new ArrayList<Location>();
@Override
public void generateRoom()
{
int amount = (int) Math.ceil(Math.sqrt(getChallengers().size()));
int a = UtilMath.r(16);
for (int pX = 0; pX < amount; pX++)
{
for (int pZ = 0; pZ < amount; pZ++)
{
if (++a > 15)
{
a = 0;
}
else if (a == 14)
{
a++;
}
_spawns.add(getCenter()
.add((pX * 4) + 1.5, 1.1, (pZ * 4) + 1.5));
for (int x = pX * 4; x < (pX * 4) + 2; x++)
{
for (int z = pZ * 4; z < (pZ * 4) + 2; z++)
{
Block b = getCenter().getBlock().getRelative(x, 0, z);
b.setType(Material.STAINED_CLAY);
b.setData((byte) a);
addBlock(b);
}
}
}
}
}
@EventHandler
public void BlockBreak(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
// Add Blocks
for (Player player : getChallengers())
{
// Side Standing
double xMod = player.getLocation().getX() % 1;
if (player.getLocation().getX() < 0)
xMod += 1;
double zMod = player.getLocation().getZ() % 1;
if (player.getLocation().getZ() < 0)
zMod += 1;
int xMin = 0;
int xMax = 0;
int zMin = 0;
int zMax = 0;
if (xMod < 0.3)
xMin = -1;
if (xMod > 0.7)
xMax = 1;
if (zMod < 0.3)
zMin = -1;
if (zMod > 0.7)
zMax = 1;
for (int x = xMin; x <= xMax; x++)
{
for (int z = zMin; z <= zMax; z++)
{
AddBlock(player.getLocation().add(x, -0.5, z).getBlock());
}
}
}
Iterator<Block> blockIterator = _blocks.keySet().iterator();
while (blockIterator.hasNext())
{
Block block = blockIterator.next();
if (!UtilTime.elapsed(_blocks.get(block), 600))
continue;
// Fall
int id = block.getTypeId();
byte data = block.getData();
MapUtil.QuickChangeBlockAt(block.getLocation(), Material.AIR);
FallingBlock ent = block.getWorld().spawnFallingBlock(
block.getLocation(), id, data);
_fallingBlocks.add(ent);
blockIterator.remove();
}
}
public void AddBlock(Block block)
{
if (block == null || block.getTypeId() == 0 || block.getTypeId() == 7
|| block.isLiquid())
return;
if (block.getRelative(BlockFace.UP).getTypeId() != 0)
return;
if (_blocks.containsKey(block))
return;
_blocks.put(block, System.currentTimeMillis());
block.setTypeIdAndData(159, (byte) 14, false);
}
private HashMap<Block, Long> _blocks = new HashMap<Block, Long>();
}

View File

@ -1,232 +0,0 @@
package nautilus.game.arcade.game.games.mineware.challenges;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilMath;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.game.games.mineware.Challenge;
import nautilus.game.arcade.game.games.mineware.MineWare;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Chicken;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.inventory.ItemStack;
public class ChallengeShootChickens extends Challenge
{
private ArrayList<Chicken> _chickens = new ArrayList<Chicken>();
private HashMap<String, Integer> _killedChickens = new HashMap<String, Integer>();
private ArrayList<Projectile> _arrows = new ArrayList<Projectile>();
public ChallengeShootChickens(MineWare host)
{
super(host, ChallengeType.FirstComplete, "Shoot 6 chickens");
}
@Override
public void cleanupRoom()
{
for (Chicken chicken : _chickens)
{
chicken.remove();
}
for (Projectile arrow : _arrows)
{
arrow.remove();
}
Host.DamagePvE = false;
}
@EventHandler
public void onShoot(ProjectileLaunchEvent event)
{
_arrows.add(event.getEntity());
}
@EventHandler
public void onDeath(EntityDeathEvent event)
{
event.getDrops().clear();
event.setDroppedExp(0);
}
@EventHandler
public void Damage(CustomDamageEvent event)
{
if (event.GetProjectile() == null)
{
event.SetCancelled("Not projectile damage");
return;
}
Player player = event.GetDamagerPlayer(true);
if (player == null)
return;
if (event.isCancelled())
return;
LivingEntity ent = event.GetDamageeEntity();
if (!_chickens.remove(ent))
{
event.SetCancelled("Not a chicken");
return;
}
event.AddMod("Ensure Death", null, 10, false);
int score = _killedChickens.get(player.getName()) + 1;
Location sloc = player.getEyeLocation();
sloc.add(UtilAlg.getTrajectory(sloc, ent.getEyeLocation()).multiply(Math.min(7, ent.getLocation().distance(sloc))));
displayCount(player, sloc, (score >= 6 ? C.cDGreen : score >= 4 ? C.cGreen : score >= 2 ? C.cRed : C.cDRed) + score);
_killedChickens.put(player.getName(), score);
if (score == 6)
{
SetCompleted(player);
}
}
@EventHandler
public void onHalfSecond(UpdateEvent event)
{
if (!Host.IsLive())
{
return;
}
if (event.getType() != UpdateType.FAST)
{
return;
}
Iterator<Chicken> itel = _chickens.iterator();
while (itel.hasNext())
{
Chicken chicken = itel.next();
if (chicken.isOnGround() || !chicken.isValid())
{
chicken.remove();
itel.remove();
}
}
if (_chickens.size() < 11 + (getChallengers().size() * 2))
{
Location loc = getCenter().clone().add(UtilMath.r(20) - 10, 15, UtilMath.r(20) - 10);
Host.CreatureAllowOverride = true;
Chicken chicken = (Chicken) loc.getWorld().spawnEntity(loc, EntityType.CHICKEN);
Host.CreatureAllowOverride = false;
chicken.setMaxHealth(0.1);
chicken.setHealth(0.1);
_chickens.add(chicken);
}
}
@Override
public void setupPlayers()
{
setBorder(-10, 10, 0, 10, -10, 10);
for (Player player : Host.GetPlayers(true))
{
player.getInventory().setItem(0,
new ItemBuilder(Material.BOW).addEnchantment(Enchantment.ARROW_INFINITE, 1).setUnbreakable(true).build());
player.getInventory().setItem(9, new ItemStack(Material.ARROW));
_killedChickens.put(player.getName(), 0);
}
Host.DamagePvE = true;
}
@Override
public void generateRoom()
{
for (int x = -10; x <= 10; x++)
{
for (int z = -10; z <= 10; 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) == 10 || Math.abs(z) == 10)
{
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);
}
}
}
}
}
@Override
public ArrayList<Location> getSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
for (int x = -8; x <= 8; x++)
{
for (int z = -8; z <= 8; z++)
{
if (x % 2 == 0 && z % 2 == 0)
{
spawns.add(getCenter().clone().add(x + 0.5, 1.1, z + 0.5));
}
}
}
return spawns;
}
}

View File

@ -1,138 +0,0 @@
package nautilus.game.arcade.game.games.mineware.challenges;
import java.util.ArrayList;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.UtilMath;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.game.games.mineware.Challenge;
import nautilus.game.arcade.game.games.mineware.MineWare;
public class ChallengeSkyFall extends Challenge
{
public ChallengeSkyFall(MineWare host)
{
super(host, ChallengeType.FirstComplete, "Land on the bottom pad, knock players around with snowballs!");
}
@Override
public ArrayList<Location> getSpawns()
{
ArrayList<Location> locations = new ArrayList<Location>();
for (int x = -3; x <= 3; x++)
{
for (int z = -3; z <= 3; z++)
{
locations.add(getCenter().add(x + 0.5, 201.5, z + 0.5));
}
}
return locations;
}
@Override
public void cleanupRoom()
{
Host.DamageEvP = false;
}
@EventHandler
public void onSnowballDamage(CustomDamageEvent event)
{
if (event.GetDamageePlayer() == null)
{
return;
}
if (!IsCompleted(event.GetDamageePlayer()))
{
return;
}
event.SetCancelled("Has completed already");
}
@Override
public void setupPlayers()
{
setBorder(-50, 50, 0, 254, -50, 50);
Host.DamageEvP = true;
for (Player player : getChallengers())
{
player.getInventory().setItem(0, new ItemStack(Material.SNOW_BALL, 64));
}
}
@EventHandler
public void onTick(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
{
return;
}
for (Player player : getChallengers())
{
if (IsCompleted(player))
continue;
double y = player.getLocation().getY();
if (player.isOnGround() && y < 3)
{
SetCompleted(player);
}
}
}
@Override
public void generateRoom()
{
for (int x = -3; x <= 3; x++)
{
for (int z = -3; z <= 3; z++)
{
Block block = getCenter().getBlock().getRelative(x, 200, z);
block.setType(Material.STAINED_GLASS);
addBlock(block);
}
}
for (int x = -1; x <= 1; x++)
{
for (int z = -1; z <= 1; z++)
{
Block block = getCenter().getBlock().getRelative(x, 0, z);
block.setType(Material.STAINED_CLAY);
block.setData((byte) UtilMath.r(16));
addBlock(block);
}
}
for (int i = 0; i < 70; i++)
{
int y = UtilMath.r(160) + 10;
if (UtilMath.r(y) > 50)
continue;
Block b = getCenter().getBlock().getRelative(UtilMath.r(16) - 8, y, UtilMath.r(16) - 8);
b.setType(Material.CARPET);
b.setData((byte) UtilMath.r(16));
addBlock(b);
}
}
}

View File

@ -1,78 +0,0 @@
package nautilus.game.arcade.game.games.mineware.challenges;
import java.util.ArrayList;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import mineplex.core.common.util.UtilMath;
import nautilus.game.arcade.game.games.mineware.Challenge;
import nautilus.game.arcade.game.games.mineware.MineWare;
public class ChallengeSmashOff extends Challenge
{
private ArrayList<Location> _spawns = new ArrayList<Location>();
public ChallengeSmashOff(MineWare host)
{
super(host, ChallengeType.LastStanding, "Knock the other players off!");
}
@Override
public ArrayList<Location> getSpawns()
{
return _spawns;
}
@Override
public void cleanupRoom()
{
Host.DamagePvP = false;
for (Player player : getChallengers())
{
player.setHealth(player.getMaxHealth());
}
}
@Override
public void setupPlayers()
{
Host.DamagePvP = true;
}
@Override
public void generateRoom()
{
int amount = (int) Math.ceil(Math.sqrt(getChallengers().size()));
int a = UtilMath.r(16);
for (int pX = 0; pX < amount; pX++)
{
for (int pZ = 0; pZ < amount; pZ++)
{
_spawns.add(getCenter().add((pX * 4) + 1.5, 1.1, (pZ * 4) + 1.5));
for (int x = pX * 4; x < (pX * 4) + 2; x++)
{
for (int z = pZ * 4; z < (pZ * 4) + 2; z++)
{
Block b = getCenter().getBlock().getRelative(x, 0, z);
b.setType(Material.STAINED_CLAY);
b.setData((byte) a);
addBlock(b);
}
}
if (++a > 15)
{
a = 0;
}
}
}
}
}

View File

@ -1,103 +0,0 @@
package nautilus.game.arcade.game.games.mineware.challenges;
import java.util.ArrayList;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import nautilus.game.arcade.game.games.mineware.Challenge;
import nautilus.game.arcade.game.games.mineware.MineWare;
public class ChallengeSpleef extends Challenge
{
public ChallengeSpleef(MineWare host)
{
super(host, ChallengeType.LastStanding,
"Destroy the blocks beneath other players!");
}
@Override
public ArrayList<Location> getSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
for (int x = -7; x <= 7; x++)
{
for (int z = -7; z <= 7; z++)
{
spawns.add(getCenter().clone().add(x + 0.5, 2, z + 0.5));
}
}
return spawns;
}
@Override
public void cleanupRoom()
{
}
@Override
public void setupPlayers()
{
}
@EventHandler
public void onBreak(PlayerInteractEvent event)
{
if (event.getAction() != Action.LEFT_CLICK_BLOCK)
{
return;
}
if (UtilPlayer.isSpectator(event.getPlayer()))
{
return;
}
Block block = event.getClickedBlock();
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND,
block.getTypeId());
block.setType(Material.AIR);
}
@Override
public void generateRoom()
{
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(0, 5, 0);
if (Math.abs(x) == 10 || Math.abs(z) == 10)
{
b.setType(Material.IRON_BLOCK);
}
else
{
b.setType(Material.WOOL);
block.setData((byte) UtilMath.r(16));
}
addBlock(b);
}
}
}
}
}

View File

@ -1,213 +0,0 @@
package nautilus.game.arcade.game.games.mineware.challenges;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map.Entry;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTextBottom;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.game.games.mineware.Challenge;
import nautilus.game.arcade.game.games.mineware.MineWare;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.inventory.ItemStack;
public class ChallengeStandOnColor extends Challenge
{
private ArrayList<Integer> _colors = new ArrayList<Integer>();
private int _currentColor;
private boolean _isFalling;
private long _lastSound;
private long _stageExpires;
private long _timeDelay = 3000;
public ChallengeStandOnColor(MineWare host)
{
super(host, ChallengeType.LastStanding, "Stand on the correct color");
for (int i = 0; i <= 15; i++)
{
_colors.add(i);
}
_colors.remove(new Integer(2));
_colors.remove(new Integer(6));
_colors.remove(new Integer(7));
_colors.remove(new Integer(9));
_colors.remove(new Integer(12));
}
@Override
public void cleanupRoom()
{
for (Player player : Host.GetPlayers(true))
{
UtilInv.Clear(player);
}
}
private void generateFloor()
{
ArrayList<Entry<Integer, Integer>> cords = new ArrayList<Entry<Integer, Integer>>();
int i = UtilMath.r(_colors.size());
for (int x = -4; x <= 4; x++)
{
for (int z = -4; z <= 4; z++)
{
cords.add(new HashMap.SimpleEntry(x * 2, z * 2));
}
}
Collections.shuffle(cords);
for (Entry<Integer, Integer> entry : cords)
{
byte color = (byte) (int) _colors.get(i++);
if (i >= _colors.size())
{
i = 0;
}
for (int x = 0; x <= 1; x++)
{
for (int z = 0; z <= 1; z++)
{
Block b = getCenter().getBlock().getRelative(entry.getKey() + x, 0, entry.getValue() + z);
b.setTypeIdAndData(Material.STAINED_CLAY.getId(), color, false);
addBlock(b);
}
}
}
}
@Override
public void generateRoom()
{
setBorder(-20, 20, 0, 10, -20, 20);
generateFloor();
}
@Override
public ArrayList<Location> getSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
for (int x = -7; x <= 7; x++)
{
for (int z = -7; z <= 7; z++)
{
if (x % 2 == 0 && z % 2 == 0)
{
spawns.add(getCenter().clone().add(x + 0.5, 1.1, z + 0.5));
}
}
}
return spawns;
}
@EventHandler
public void OnTick(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
{
return;
}
if (!Host.IsLive())
{
return;
}
Player[] players = getChallengers().toArray(new Player[0]);
if (_stageExpires < System.currentTimeMillis())
{
UtilTextBottom.displayProgress(0, players);
if (_isFalling)
{
for (Player player : UtilServer.getPlayers())
player.playSound(player.getLocation(), Sound.NOTE_PIANO, 2f, 0f);
_timeDelay *= 0.8;
_isFalling = false;
_stageExpires = System.currentTimeMillis() + _timeDelay;
_currentColor = _colors.get(UtilMath.r(_colors.size()));
generateFloor();
for (Player player : getChallengers())
{
for (int i = 0; i < 9; i++)
{
player.getInventory().setItem(i, new ItemStack(Material.STAINED_CLAY, 1, (short) _currentColor));
}
}
}
else
{
_isFalling = true;
_stageExpires = System.currentTimeMillis() + 4000;
for (int x = -8; x <= 9; x++)
{
for (int z = -8; z <= 9; z++)
{
Block b = getCenter().getBlock().getRelative(x, 0, z);
if (b.getData() != _currentColor)
{
b.setTypeIdAndData(Material.AIR.getId(), (byte) 0, false);
addBlock(b);
}
}
}
}
}
else if (!_isFalling)
{
UtilTextBottom.displayProgress((_stageExpires - System.currentTimeMillis()) / (double) _timeDelay, players);
if (_lastSound < System.currentTimeMillis())
{
_lastSound = System.currentTimeMillis() + 1000;
for (Player player : UtilServer.getPlayers())
player.playSound(player.getLocation(), Sound.NOTE_STICKS, 1f, 1f);
}
}
else
{
UtilTextBottom.displayProgress(0, players);
}
}
@Override
public void setupPlayers()
{
_stageExpires = System.currentTimeMillis() + _timeDelay;
_currentColor = _colors.get(UtilMath.r(_colors.size()));
for (Player player : Host.GetPlayers(true))
{
for (int i = 0; i < 9; i++)
{
player.getInventory().setItem(i, new ItemStack(Material.STAINED_CLAY, 1, (short) _currentColor));
}
}
}
}

View File

@ -1,141 +0,0 @@
package nautilus.game.arcade.game.games.mineware.challenges;
import java.util.ArrayList;
import java.util.HashMap;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilShapes;
import mineplex.core.recharge.Recharge;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.game.games.mineware.Challenge;
import nautilus.game.arcade.game.games.mineware.MineWare;
public class ChallengeTntLauncher extends Challenge
{
private ArrayList<Location> _spawns = new ArrayList<Location>();
private ArrayList<Entity> _tnt = new ArrayList<Entity>();
public ChallengeTntLauncher(MineWare host)
{
super(host, ChallengeType.LastStanding, "Throw TNT, don't get knocked off!");
}
@Override
public ArrayList<Location> getSpawns()
{
return _spawns;
}
@Override
public void cleanupRoom()
{
Host.Damage = true;
for (Entity tnt : _tnt)
{
tnt.remove();
}
}
@EventHandler(priority = EventPriority.LOW)
public void Update(EntityExplodeEvent event)
{
if (!(event.getEntity() instanceof TNTPrimed))
return;
if (!_tnt.remove(event.getEntity()))
return;
HashMap<Player, Double> players = UtilPlayer.getInRadius(event.getLocation(),
4 + ((System.currentTimeMillis() - StartTime) / 10000D));
for (Player player : players.keySet())
{
double mult = players.get(player) / 2;
mult += (System.currentTimeMillis() - StartTime) / 20000D;
// Knockback
UtilAction.velocity(player, UtilAlg.getTrajectory(event.getLocation(), player.getLocation()), 3 * mult, false, 0,
0.5 + 2 * mult, 10, true);
}
event.blockList().clear();
}
@EventHandler
public void onDamage(CustomDamageEvent event)
{
if (event.GetCause() != DamageCause.ENTITY_EXPLOSION)
return;
event.SetCancelled("TNT no damage");
}
@EventHandler
public void onInteract(PlayerInteractEvent event)
{
Player player = event.getPlayer();
UtilInv.Update(player);
if (!Recharge.Instance.use(player, "TNT", 3000, true, false))
{
return;
}
TNTPrimed tnt = player.getWorld()
.spawn(player.getEyeLocation().add(player.getLocation().getDirection()), TNTPrimed.class);
UtilAction.velocity(tnt, player.getLocation().getDirection(), 0.6, false, 0, 0.2, 1, false);
tnt.setFuseTicks((int) (60 * (1 - ((System.currentTimeMillis() - StartTime) / 70000))));
_tnt.add(tnt);
}
@Override
public void setupPlayers()
{
for (Player player : getChallengers())
{
player.getInventory().setItem(0, new ItemStack(Material.TNT));
}
}
@Override
public void generateRoom()
{
double radius = 6 + (getChallengers().size() / 2D);
for (Location loc : UtilShapes.getCircle(getCenter(), false, radius))
{
Block block = loc.getBlock();
block.setType(Material.STAINED_CLAY);
block.setData((byte) UtilMath.r(16));
addBlock(block);
if (Math.abs(block.getLocation().add(0.5, 0, 0.5).distance(getCenter().add(0.5, 0, 0.5)) - (radius - 2)) < 1)
{
_spawns.add(block.getLocation().add(0.5, 1.1, 0.5));
}
}
}
}

View File

@ -1,232 +0,0 @@
package nautilus.game.arcade.game.games.mineware.challenges;
import java.util.ArrayList;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Damageable;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.player.PlayerMoveEvent;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTextBottom;
import mineplex.core.common.util.UtilTime;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.game.games.mineware.Challenge;
import nautilus.game.arcade.game.games.mineware.MineWare;
public class ChallengeVolleyPig extends Challenge
{
private long _redSide;
private long _blueSide;
private Entity _pig;
public ChallengeVolleyPig(MineWare host)
{
super(host, ChallengeType.FirstComplete, "Keep the pig on the other side and stack up the time!");
}
@Override
public ArrayList<Location> getSpawns()
{
ArrayList<Location> locations = new ArrayList<Location>();
for (int x = -5; x <= 5; x++)
{
for (int z = -9; z <= 9; z++)
{
if (z == 0)
continue;
locations.add(getCenter().add(x + 0.5, 1.1, z + 0.5));
}
}
return locations;
}
@Override
public void cleanupRoom()
{
_pig.remove();
Host.DamagePvE = false;
}
@Override
public void setupPlayers()
{
for (Player player : getChallengers())
{
player.getInventory().setItem(0, new ItemBuilder(Material.STICK).addEnchantment(Enchantment.KNOCKBACK, 1).build());
}
Host.DamagePvE = true;
}
@EventHandler(priority = EventPriority.LOW)
public void onMove(PlayerMoveEvent event)
{
if (UtilPlayer.isSpectator(event.getPlayer()))
return;
Location from = event.getFrom().clone();
from.setY(0);
Block bFrom = from.getBlock();
if (bFrom.getType() != Material.STAINED_CLAY)
return;
Location to = event.getTo().clone();
to.setY(0);
Block bTo = to.getBlock();
if (bTo.getType() == Material.AIR || bTo.getData() != bFrom.getData())
{
setLost(event.getPlayer());
}
}
@EventHandler
public void onDamage(CustomDamageEvent event)
{
if (event.GetDamageeEntity() != _pig || event.GetCause() == DamageCause.FALL)
return;
event.AddMult("Reduce damage", null, 0.001, false);
((Damageable) _pig).setHealth(((Damageable) _pig).getMaxHealth());
}
@EventHandler
public void onTick(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
if (_pig.isValid())
{
Location loc = _pig.getLocation();
if (Math.abs(loc.getZ()) > 0.05)
{
loc.setY(0);
Block block = loc.getBlock();
if (block.getType() != Material.AIR)
{
if (loc.getZ() < 0)
{
_blueSide += 50;
}
else
{
_redSide += 50;
}
}
else
{
_pig.remove();
}
}
}
displayProgress();
if (!_pig.isValid() || UtilTime.elapsed(StartTime, 30000) || _redSide > 10000 || _blueSide > 10000)
{
Duration = 0; // Instant game over
for (Player player : getChallengers())
{
Location loc = player.getLocation();
loc.setY(0);
Block block = loc.getBlock();
if (block.getType() == Material.STAINED_CLAY)
{
if (block.getData() == (_redSide > _blueSide ? 11 : 14))
{
SetCompleted(player);
}
}
}
}
}
private void displayProgress()
{
double red = _redSide / 10000D;
double blue = _blueSide / 10000D;
// Generate Bar
int bars = 24;
boolean redFirst = red < blue;
String progressBar = (redFirst ? C.cRed : C.cBlue) + "";
int colorChange = 0;
for (int i = 0; i < bars; i++)
{
float d = (float) i / (float) bars;
if (colorChange == 0 && d >= (redFirst ? red : blue))
{
progressBar += (redFirst ? C.cBlue : C.cRed);
colorChange = 1;
}
if (colorChange != 2 && d >= Math.max(red, blue))
{
progressBar += C.cWhite;
colorChange = 2;
}
progressBar += "";
}
UtilTextBottom.display(progressBar, UtilServer.getPlayers());
}
@Override
public void generateRoom()
{
Host.CreatureAllowOverride = true;
_pig = getCenter().getWorld().spawnEntity(getCenter().add(0, 1, 0), EntityType.PIG);
UtilEnt.Vegetate(_pig);
Host.CreatureAllowOverride = false;
for (int x = -6; x <= 6; x++)
{
for (int z = -10; z <= 10; z++)
{
for (int y = 0; y <= 3; y++)
{
Block b = getCenter().getBlock().getRelative(x, y, z);
if (y == 0 || Math.abs(x) == 6 || Math.abs(z) == 10)
{
b.setType(z == 0 ? Material.STAINED_GLASS : Material.STAINED_CLAY);
b.setData((byte) (z < 0 ? 11 : z > 0 ? 14 : 0));
addBlock(b);
}
}
}
}
}
}

View File

@ -0,0 +1,204 @@
package nautilus.game.arcade.game.games.mineware.effect;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Chicken;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTextMiddle;
import mineplex.core.disguise.disguises.DisguiseChicken;
import nautilus.game.arcade.game.GameTeam.PlayerState;
import nautilus.game.arcade.game.games.mineware.BawkBawkBattles;
/**
* This class simulates a chicken attack, that is triggered when a player runs out of lives.
*/
public class ChickenAttack
{
private static final int CHICKEN_SPAWN_AMOUNT = 12;
private static final int INFORM_TITLTE_FADE_IN_TICKS = 5;
private static final int INFORM_TITLTE_STAY_TICKS = 40;
private static final int INFORM_TITLTE_FADE_OUT_TICKS = 5;
private static final int ATTACK_EXPIRE_TICKS = 400;
private static final float FLY_SPEED_RESET = 0.1F;
private static final double CHICKEN_BABY_SPAWN_CHANCE = 0.1;
private static final int CHICKEN_LOOK_AT_PLAYER_DISTANCE = 4;
private BawkBawkBattles _host;
private JavaPlugin _plugin;
private Location _center;
private Location[] _spawnpoints = new Location[4];
private List<Chicken> _chickens = new ArrayList<>();
public ChickenAttack(BawkBawkBattles host, Location center)
{
_host = host;
_plugin = host.getArcadeManager().getPlugin();
_center = center;
Block block = _center.getBlock();
_spawnpoints = new Location[] {
block.getRelative(BlockFace.NORTH).getLocation().add(0, 1, 0),
block.getRelative(BlockFace.EAST).getLocation().add(0, 1, 0),
block.getRelative(BlockFace.SOUTH).getLocation().add(0, 1, 0),
block.getRelative(BlockFace.WEST).getLocation().add(0, 1, 0)
};
spawnChickens();
}
public void start(Player player)
{
_host.getPlayerTeam().RemovePlayer(player);
_host.getChickenTeam().AddPlayer(player, true);
UtilInv.Clear(player);
_host.Manager.Clear(player);
_center.getWorld().strikeLightningEffect(_center);
player.teleport(_center);
UtilTextMiddle.display(C.cRed + "Chicken Attack!", "You ran out of lives.", INFORM_TITLTE_FADE_IN_TICKS, INFORM_TITLTE_STAY_TICKS, INFORM_TITLTE_FADE_OUT_TICKS, player);
UtilPlayer.message(player, F.main("Game", "You failed to follow bawk bawk's instructions and you ran out of lives. His minions are now attacking you."));
player.playSound(player.getLocation(), Sound.WITHER_SPAWN, 1.0F, 1.0F);
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, 1));
ensurePlayerKill(player);
}
private void ensurePlayerKill(Player player)
{
new BukkitRunnable()
{
@Override
public void run()
{
if (_host.IsLive() && _host.getChickenTeam().HasPlayer(player) && _host.IsAlive(player))
{
UtilPlayer.message(player, F.main("Game", "You have been moved to spectators."));
kill(player, false);
}
else
{
cancel();
}
}
}.runTaskLater(_plugin, ATTACK_EXPIRE_TICKS);
}
public void kill(Player player, boolean inform)
{
_host.Manager.Clear(player);
if (inform)
{
UtilPlayer.message(player, F.main("Game", "You are now spectating, others can see you as a chicken."));
}
new BukkitRunnable()
{
@Override
public void run()
{
_host.SetPlayerState(player, PlayerState.OUT);
DisguiseChicken disguise = new DisguiseChicken(player);
disguise.setBaby();
_host.Manager.GetDisguise().disguise(disguise, UtilServer.getPlayers());
player.teleport(_host.GetSpectatorLocation());
UtilAction.velocity(player, new Vector(0, 1, 0));
player.setAllowFlight(true);
player.setFlying(true);
player.setFlySpeed(FLY_SPEED_RESET);
player.playSound(player.getLocation(), Sound.BAT_TAKEOFF, 1.0F, 1.0F);
}
}.runTaskLater(_plugin, 1L);
}
private void spawnChickens()
{
_host.CreatureAllow = true;
int spawnAmount = CHICKEN_SPAWN_AMOUNT / _spawnpoints.length;
for (int i = 0; i < _spawnpoints.length; i++)
{
Location spawn = _spawnpoints[i];
World world = spawn.getWorld();
for (int j = 0; j < spawnAmount; j++)
{
Chicken chicken = world.spawn(spawn, Chicken.class);
setupChicken(chicken);
}
}
_host.CreatureAllow = false;
}
private void setupChicken(Chicken chicken)
{
_chickens.add(chicken);
if (Math.random() < CHICKEN_BABY_SPAWN_CHANCE)
{
chicken.setBaby();
}
UtilEnt.addLookAtPlayerAI(chicken, CHICKEN_LOOK_AT_PLAYER_DISTANCE);
chicken.setCustomName("Chicken Minion");
chicken.setCustomNameVisible(true);
}
public boolean isGroupMember(Chicken chicken)
{
return _chickens.contains(chicken);
}
public void reset()
{
for (Chicken chicken : _chickens)
{
chicken.remove();
}
_chickens.clear();
}
public List<Chicken> getChickens()
{
return _chickens;
}
public Location getPlatformCenter()
{
return _center;
}
}

View File

@ -0,0 +1,294 @@
package nautilus.game.arcade.game.games.mineware.effect;
import java.util.ArrayList;
import java.util.List;
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.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.EulerAngle;
import org.bukkit.util.Vector;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.common.util.UtilSkull;
import mineplex.core.hologram.Hologram;
import mineplex.core.itemstack.ItemBuilder;
import nautilus.game.arcade.game.games.mineware.BawkBawkBattles;
/**
* Triggers a death effect that contains a rotating chicken head, food items and a hologram with random next.
*/
public class DeathEffect
{
private static final double FOOD_DROP_HEIGHT = 0.5;
private static final double HOLOGRAM_HEIGHT = 2.2;
private static final double CLOUD_PARTICLES_HEIGHT = 1.7;
private static final int FOOD_SPAWN_AMOUNT = 14;
private static final int FOOD_MERGE_RANDOM_SEED = 999999;
private static final String FOOD_ITEM_TITLE = "Food";
private static final double FOOD_VELOCITY_SUBTRACT = 0.5;
private static final double FOOD_VELOCITY_MULTIPLIER = 0.5;
private static final int FOOD_REMOVE_AFTER_TICKS = 60;
private static final byte CHICKEN_HEAD_DATA = 3;
private static final int CHICKEN_HEAD_ROTATION_ADD = 12;
private static final int CHICKEN_HEAD_ROTATION_LIMIT = 360;
private static final float CHICKEN_HEAD_REMOVE_PARTICLE_OFFSET = 0.2F;
private static final int CHICKEN_HEAD_REMOVE_PARTICLE_AMOUNT = 10;
private static final int CHICKEN_HEAD_REMOVE_AFTER_TICKS = 60;
private static final float CHICKEN_SOUND_VOLUME = 1.5F;
private static final float CHICKEN_SOUND_PITCH = 1.0F;
private static final float EAT_SOUND_VOLUME = 1.5F;
private static final float EAT_SOUND_PITCH = 1.0F;
private static final float BURP_SOUND_VOLUME = 1.5F;
private static final float BURP_SOUND_PITCH = 1.0F;
private static final int EAT_BURP_SOUND_EMIT_AFTER_TICKS = 10;
private BawkBawkBattles _host;
private JavaPlugin _plugin;
private DeathText _deathText = new DeathText();
private ArrayList<DeathEffectData> _data = new ArrayList<DeathEffectData>();
public DeathEffect(BawkBawkBattles host)
{
_host = host;
_plugin = host.Manager.getPlugin();
}
public void playDeath(Player player, Location death)
{
DeathEffectData data = new DeathEffectData(player, death);
_data.add(data);
Block belowFirst = death.getBlock().getRelative(BlockFace.DOWN);
Block belowSecond = belowFirst.getRelative(BlockFace.DOWN);
spawnChickenHead(data);
playChickenSounds(data);
if (!belowFirst.isEmpty() || !belowSecond.isEmpty())
{
startFoodSpawnTask(data);
}
}
private void startFoodSpawnTask(DeathEffectData data)
{
Location dropsite = data.getLocation().clone().add(0, FOOD_DROP_HEIGHT, 0);
List<Item> foodItems = new ArrayList<>();
for (int i = 0; i <= FOOD_SPAWN_AMOUNT; i++)
{
Material material = Material.EGG;
if (UtilMath.random.nextBoolean())
material = Material.COOKED_CHICKEN;
ItemBuilder builder = new ItemBuilder(material);
builder.setTitle(UtilMath.r(FOOD_MERGE_RANDOM_SEED) + FOOD_ITEM_TITLE);
Item food = dropsite.getWorld().dropItem(dropsite, builder.build());
Vector velocity = new Vector((Math.random() - FOOD_VELOCITY_SUBTRACT) * FOOD_VELOCITY_MULTIPLIER, 0, (Math.random() - FOOD_VELOCITY_SUBTRACT) * FOOD_VELOCITY_MULTIPLIER);
food.setVelocity(velocity);
foodItems.add(food);
}
data.addFoodItems(foodItems);
removeSpawnedFoodTask(data);
}
private void removeSpawnedFoodTask(DeathEffectData data)
{
new BukkitRunnable()
{
@Override
public void run()
{
for (Item food : data.getFoodItems())
{
if (food.isValid())
{
UtilParticle.PlayParticleToAll(ParticleType.HAPPY_VILLAGER, food.getLocation(), 0.0F, 0.0F, 0.0F, 0.0F, 1, ViewDist.NORMAL);
food.remove();
}
}
data.getFoodItems().clear();
}
}.runTaskLater(_plugin, FOOD_REMOVE_AFTER_TICKS);
}
@SuppressWarnings("deprecation")
private void spawnChickenHead(DeathEffectData data)
{
Location dropsite = data.getLocation();
_host.CreatureAllow = true;
ArmorStand chickenHead = _host.WorldData.World.spawn(dropsite, ArmorStand.class);
_host.CreatureAllow = false;
chickenHead.setVisible(false);
chickenHead.setGravity(false);
chickenHead.setBasePlate(false);
ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short) 0, CHICKEN_HEAD_DATA);
SkullMeta meta = (SkullMeta) skull.getItemMeta();
meta.setOwner(UtilSkull.getPlayerHeadName(EntityType.CHICKEN));
skull.setItemMeta(meta);
chickenHead.getEquipment().setHelmet(skull);
data.setChickenHead(chickenHead);
playHeadRotation(data);
Hologram hologram = getRandomHologram(dropsite);
hologram.start();
data.setHologram(hologram);
}
private Hologram getRandomHologram(Location loc)
{
Hologram hologram = new Hologram(
_host.getArcadeManager().getHologramManager(),
loc.clone().add(0, HOLOGRAM_HEIGHT, 0),
C.cAqua + C.Bold + _deathText.getRandom() + C.Reset);
return hologram;
}
private void playHeadRotation(DeathEffectData data)
{
ArmorStand chickenHead = data.getChickenHead();
new BukkitRunnable()
{
int i;
@Override
public void run()
{
if (!chickenHead.isValid())
{
cancel();
return;
}
i += CHICKEN_HEAD_ROTATION_ADD;
if (i <= CHICKEN_HEAD_ROTATION_LIMIT)
{
chickenHead.setHeadPose(new EulerAngle(0, Math.toRadians(i), 0));
}
else
{
removeChickenHead(data);
}
}
}.runTaskTimer(_plugin, 1L, 1L);
}
private void removeChickenHead(DeathEffectData data)
{
ArmorStand chickenHead = data.getChickenHead();
new BukkitRunnable()
{
@Override
public void run()
{
if (!chickenHead.isValid())
{
cancel();
return;
}
UtilParticle.PlayParticleToAll(ParticleType.CLOUD, data.getLocation().clone().add(0, CLOUD_PARTICLES_HEIGHT, 0), CHICKEN_HEAD_REMOVE_PARTICLE_OFFSET, CHICKEN_HEAD_REMOVE_PARTICLE_OFFSET, CHICKEN_HEAD_REMOVE_PARTICLE_OFFSET, 0.0F, CHICKEN_HEAD_REMOVE_PARTICLE_AMOUNT, ViewDist.NORMAL);
chickenHead.remove();
data.getHologram().stop();
}
}.runTaskLater(_plugin, CHICKEN_HEAD_REMOVE_AFTER_TICKS);
}
private void playChickenSounds(DeathEffectData data)
{
Location loc = data.getLocation();
loc.getWorld().playSound(loc, Sound.CHICKEN_HURT, CHICKEN_SOUND_VOLUME, CHICKEN_SOUND_PITCH);
new BukkitRunnable()
{
@Override
public void run()
{
loc.getWorld().playSound(loc, Sound.EAT, EAT_SOUND_VOLUME, EAT_SOUND_PITCH);
loc.getWorld().playSound(loc, Sound.BURP, BURP_SOUND_VOLUME, BURP_SOUND_PITCH);
}
}.runTaskLater(_plugin, EAT_BURP_SOUND_EMIT_AFTER_TICKS);
}
public void removeSpawnedEntities()
{
for (DeathEffectData data : _data)
{
if (data.hasDroppedFoodItems())
{
for (Item food : data.getFoodItems())
{
food.remove();
}
}
data.getFoodItems().clear();
data.getChickenHead().remove();
data.getHologram().stop();
}
_data.clear();
}
public boolean isDeathEffectItem(Entity entity)
{
if (entity instanceof Item)
{
Item item = (Item) entity;
ItemStack itemStack = item.getItemStack();
if (itemStack.hasItemMeta())
{
if (itemStack.getItemMeta().hasDisplayName())
{
String name = itemStack.getItemMeta().getDisplayName();
return name.contains(FOOD_ITEM_TITLE);
}
}
}
return false;
}
public ArrayList<DeathEffectData> getData()
{
return _data;
}
}

View File

@ -0,0 +1,84 @@
package nautilus.game.arcade.game.games.mineware.effect;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import mineplex.core.hologram.Hologram;
/**
* This class holds player specific objects regarding a triggered death effect.
*/
public class DeathEffectData
{
private Player _player;
private Location _death;
private List<Item> _foodItems = new ArrayList<>();
private ArmorStand _chickenHead;
private Hologram _hologram;
public DeathEffectData(Player player, Location death)
{
_player = player;
_death = death;
}
public boolean isChickenHead(ArmorStand armorStand)
{
return _chickenHead.equals(armorStand);
}
public void addFoodItems(List<Item> foodItems)
{
_foodItems = foodItems;
}
public boolean hasDroppedFoodItems()
{
return !_foodItems.isEmpty();
}
public void setChickenHead(ArmorStand chickenHead)
{
_chickenHead = chickenHead;
}
public boolean hasFinished()
{
return _foodItems.isEmpty() && _chickenHead.isDead();
}
public void setHologram(Hologram hologram)
{
_hologram = hologram;
}
public Player getPlayer()
{
return _player;
}
public Location getLocation()
{
return _death;
}
public List<Item> getFoodItems()
{
return _foodItems;
}
public ArmorStand getChickenHead()
{
return _chickenHead;
}
public Hologram getHologram()
{
return _hologram;
}
}

View File

@ -0,0 +1,22 @@
package nautilus.game.arcade.game.games.mineware.effect;
import mineplex.core.common.util.UtilMath;
/**
* This class provides random phrases that are shown when a death effect is triggered.
*/
public class DeathText
{
private String[] _text = {
"Nom nom nom!",
"Bawk Bawk!",
"Delicious Meal!",
"Nom nom, bawk!",
"Yummy, delicious!"
};
public String getRandom()
{
return UtilMath.randomElement(_text);
}
}

View File

@ -0,0 +1,36 @@
package nautilus.game.arcade.game.games.mineware.events;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import nautilus.game.arcade.game.games.mineware.challenge.Challenge;
/**
* An event that triggers when a challenge ends (the game may end afterwards).
*/
public class ChallengeEndEvent extends Event
{
private Challenge _endedChallenge;
private static final HandlerList _handlers = new HandlerList();
public ChallengeEndEvent(Challenge endedChallenge)
{
_endedChallenge = endedChallenge;
}
public Challenge getEndedChallenge()
{
return _endedChallenge;
}
public static HandlerList getHandlerList()
{
return _handlers;
}
@Override
public HandlerList getHandlers()
{
return getHandlerList();
}
}

View File

@ -0,0 +1,36 @@
package nautilus.game.arcade.game.games.mineware.events;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import nautilus.game.arcade.game.games.mineware.challenge.Challenge;
/**
* An event that triggers when a challenge starts.
*/
public class ChallengeStartEvent extends Event
{
private Challenge _startedChallenge;
private static final HandlerList _handlers = new HandlerList();
public ChallengeStartEvent(Challenge startedChallenge)
{
_startedChallenge = startedChallenge;
}
public Challenge getStartedChallenge()
{
return _startedChallenge;
}
public static HandlerList getHandlerList()
{
return _handlers;
}
@Override
public HandlerList getHandlers()
{
return getHandlerList();
}
}

View File

@ -0,0 +1,89 @@
package nautilus.game.arcade.game.games.mineware.kit;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.inventory.meta.SkullMeta;
import mineplex.core.common.util.UtilSkull;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.ProgressingKit;
/**
* The default bawk bawk battles game kit.
*/
public class KitBawksFood extends ProgressingKit
{
private static final byte SKULL_DATA = 3;
public KitBawksFood(ArcadeManager manager)
{
super(
manager,
"Bawk's Food",
"bawksfood",
KitAvailability.Free,
new String[] {
"Lord Bawk Bawk demands you follow his commands.",
"If you fail his tasks you will lose a life.",
"If you run out of lives Bawk Bawk's followers will eat you!"
},
new Perk[] {},
EntityType.SKELETON,
new ItemStack(Material.AIR));
}
@Override
public void GiveItems(Player player)
{
// Items may be added manually when a challenge starts.
}
@SuppressWarnings("deprecation")
@Override
public void SpawnCustom(LivingEntity ent)
{
EntityEquipment equipment = ent.getEquipment();
ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short) 0, SKULL_DATA);
SkullMeta meta = (SkullMeta) skull.getItemMeta();
meta.setOwner(UtilSkull.getPlayerHeadName(EntityType.CHICKEN));
skull.setItemMeta(meta);
ItemStack chestplate = new ItemStack(Material.LEATHER_CHESTPLATE);
LeatherArmorMeta chestplateMeta = (LeatherArmorMeta) chestplate.getItemMeta();
chestplateMeta.setColor(Color.WHITE);
chestplateMeta.spigot().setUnbreakable(true);
chestplate.setItemMeta(chestplateMeta);
ItemStack leggings = new ItemStack(Material.LEATHER_LEGGINGS);
LeatherArmorMeta leggingsMeta = (LeatherArmorMeta) leggings.getItemMeta();
leggingsMeta.setColor(Color.WHITE);
leggingsMeta.spigot().setUnbreakable(true);
leggings.setItemMeta(leggingsMeta);
ItemStack boots = new ItemStack(Material.LEATHER_BOOTS);
LeatherArmorMeta bootsMeta = (LeatherArmorMeta) boots.getItemMeta();
bootsMeta.setColor(Color.WHITE);
bootsMeta.spigot().setUnbreakable(true);
boots.setItemMeta(bootsMeta);
equipment.setHelmet(skull);
equipment.setChestplate(chestplate);
equipment.setLeggings(leggings);
equipment.setBoots(boots);
}
@Override
public Material getIcon()
{
return Material.FEATHER;
}
}

View File

@ -0,0 +1,41 @@
package nautilus.game.arcade.game.games.mineware.tracker;
import org.bukkit.entity.Player;
import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.games.mineware.challenge.Challenge;
import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeBouncingBlock;
/**
* A tracker for the Bouncing Shadow achievement.
* <br>
* <br>
* <b>Challenge:</b> Bouncing Block
* <br>
* <b>Goal:</b> Win 3 entire rounds without stepping on red wool
*/
public class BouncingShadowTracker extends ChallengeStatTracker
{
public BouncingShadowTracker(Game game)
{
super(game);
}
@Override
protected void track(Challenge challenge)
{
if (challenge instanceof ChallengeBouncingBlock)
{
ChallengeBouncingBlock bouncingBlock = (ChallengeBouncingBlock) challenge;
for (Player player : getGame().GetPlayers(true))
{
if (bouncingBlock.hasData(player) && bouncingBlock.getData().isDone(player))
{
System.out.println("Bouncing Shadow: " + player.getName());
addStat(player, "BouncingShadow", 1, false, false);
}
}
}
}
}

View File

@ -0,0 +1,32 @@
package nautilus.game.arcade.game.games.mineware.tracker;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.game.games.mineware.challenge.Challenge;
import nautilus.game.arcade.game.games.mineware.events.ChallengeEndEvent;
import nautilus.game.arcade.stats.StatTracker;
/**
* A statistic tracker that tracks data when a challenge ends.
*/
public abstract class ChallengeStatTracker extends StatTracker<Game>
{
public ChallengeStatTracker(Game game)
{
super(game);
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onChallengeEnd(ChallengeEndEvent event)
{
if (getGame().GetState() != GameState.Live)
return;
track(event.getEndedChallenge());
}
protected abstract void track(Challenge challenge);
}

View File

@ -0,0 +1,46 @@
package nautilus.game.arcade.game.games.mineware.tracker;
import org.bukkit.entity.Player;
import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.games.mineware.challenge.Challenge;
import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeEggSmash;
/**
* A tracker for the Dragon King achievement.
* <br>
* <br>
* <b>Challenge:</b> Egg Smash
* <br>
* <b>Goal:</b> Smash 300 dragon eggs
*/
public class DragonKingTracker extends ChallengeStatTracker
{
public DragonKingTracker(Game game)
{
super(game);
}
@Override
protected void track(Challenge challenge)
{
if (challenge instanceof ChallengeEggSmash)
{
ChallengeEggSmash eggSmash = (ChallengeEggSmash) challenge;
for (Player player : getGame().GetPlayers(true))
{
if (eggSmash.hasData(player))
{
int score = (int) eggSmash.getData(player);
if (score > 0)
{
System.out.println("Dragon King: " + player.getName());
addStat(player, "DragonKing", score, false, false);
}
}
}
}
}
}

View File

@ -0,0 +1,46 @@
package nautilus.game.arcade.game.games.mineware.tracker;
import org.bukkit.entity.Player;
import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.games.mineware.challenge.Challenge;
import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeMiniOneInTheQuiver;
/**
* A tracker for the Elite Archer achievement.
* <br>
* <br>
* <b>Challenge:</b> Mini OITQ
* <br>
* <b>Goal:</b> Kill 100 players
*/
public class EliteArcherTracker extends ChallengeStatTracker
{
public EliteArcherTracker(Game game)
{
super(game);
}
@Override
protected void track(Challenge challenge)
{
if (challenge instanceof ChallengeMiniOneInTheQuiver)
{
ChallengeMiniOneInTheQuiver miniOITQ = (ChallengeMiniOneInTheQuiver) challenge;
for (Player player : getGame().GetPlayers(true))
{
if (miniOITQ.hasData(player))
{
int score = (int) miniOITQ.getData(player);
if (score > 0)
{
System.out.println("Elite Archer: " + player.getName());
addStat(player, "EliteArcher", score, false, false);
}
}
}
}
}
}

View File

@ -0,0 +1,46 @@
package nautilus.game.arcade.game.games.mineware.tracker;
import org.bukkit.entity.Player;
import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.games.mineware.challenge.Challenge;
import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeMilkACow;
/**
* A tracker for the Milk Man achievement.
* <br>
* <br>
* <b>Challenge:</b> Milk a Cow
* <br>
* <b>Goal:</b> Deliver 300 buckets of milk to the farmer
*/
public class MilkManTracker extends ChallengeStatTracker
{
public MilkManTracker(Game game)
{
super(game);
}
@Override
protected void track(Challenge challenge)
{
if (challenge instanceof ChallengeMilkACow)
{
ChallengeMilkACow milkACow = (ChallengeMilkACow) challenge;
for (Player player : getGame().GetPlayers(true))
{
if (milkACow.hasData(player))
{
int score = (int) milkACow.getData(player);
if (score > 0)
{
System.out.println("Milk Man: " + player.getName());
addStat(player, "MilkMan", score, false, false);
}
}
}
}
}
}

View File

@ -0,0 +1,46 @@
package nautilus.game.arcade.game.games.mineware.tracker;
import org.bukkit.entity.Player;
import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.games.mineware.challenge.Challenge;
import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeChickenShooting;
/**
* A tracker for the Pinata Master achievement.
* <br>
* <br>
* <b>Challenge:</b> Chicken Shooting
* <br>
* <b>Goal:</b> Shoot 500 chickens
*/
public class PinataMasterTracker extends ChallengeStatTracker
{
public PinataMasterTracker(Game game)
{
super(game);
}
@Override
protected void track(Challenge challenge)
{
if (challenge instanceof ChallengeChickenShooting)
{
ChallengeChickenShooting chickenShooting = (ChallengeChickenShooting) challenge;
for (Player player : getGame().GetPlayers(true))
{
if (chickenShooting.hasData(player))
{
int score = (int) chickenShooting.getData(player);
if (score > 0)
{
System.out.println("Pinata Master: " + player.getName());
addStat(player, "PinataMaster", score, false, false);
}
}
}
}
}
}

View File

@ -0,0 +1,46 @@
package nautilus.game.arcade.game.games.mineware.tracker;
import org.bukkit.entity.Player;
import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.games.mineware.challenge.Challenge;
import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeFallingBlocks;
/**
* A tracker for the Pixel Ninja achievement.
* <br>
* <br>
* <b>Challenge:</b> Falling Blocks
* <br>
* <b>Goal:</b> Dodge 100 waves of falling blocks
*/
public class PixelNinjaTracker extends ChallengeStatTracker
{
public PixelNinjaTracker(Game game)
{
super(game);
}
@Override
protected void track(Challenge challenge)
{
if (challenge instanceof ChallengeFallingBlocks)
{
ChallengeFallingBlocks fallingBlocks = (ChallengeFallingBlocks) challenge;
for (Player player : getGame().GetPlayers(true))
{
if (fallingBlocks.hasData(player))
{
int score = (int) fallingBlocks.getData(player);
if (score > 0)
{
System.out.println("Pixel Ninja: " + player.getName());
addStat(player, "PixelNinja", score, false, false);
}
}
}
}
}
}

View File

@ -0,0 +1,43 @@
package nautilus.game.arcade.game.games.mineware.tracker;
import org.bukkit.entity.Player;
import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.games.mineware.challenge.Challenge;
import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeBuildRace;
/**
* A tracker for the Speedy Builders achievement.
* <br>
* <br>
* <b>Challenge:</b> Build Race
* <br>
* <b>Goal:</b> Place all blocks in your inventory within 15 seconds
*/
public class SpeedyBuildersTracker extends ChallengeStatTracker
{
public static final long GOAL = 15000;
public SpeedyBuildersTracker(Game game)
{
super(game);
}
@Override
protected void track(Challenge challenge)
{
if (challenge instanceof ChallengeBuildRace)
{
ChallengeBuildRace buildRace = (ChallengeBuildRace) challenge;
for (Player player : getGame().GetPlayers(true))
{
if (buildRace.hasData(player) && buildRace.getData().isDone(player))
{
System.out.println("Speedy Builders: " + player.getName());
addStat(player, "SpeedyBuilders", 1, false, false);
}
}
}
}
}

View File

@ -0,0 +1,46 @@
package nautilus.game.arcade.game.games.mineware.tracker;
import org.bukkit.entity.Player;
import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.games.mineware.challenge.Challenge;
import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeWaveCrush;
/**
* A tracker for the Surf Up achievement.
* <br>
* <br>
* <b>Challenge:</b> Wave Crush
* <br>
* <b>Goal:</b> Avoid 500 waves
*/
public class SurfUpTracker extends ChallengeStatTracker
{
public SurfUpTracker(Game game)
{
super(game);
}
@Override
protected void track(Challenge challenge)
{
if (challenge instanceof ChallengeWaveCrush)
{
ChallengeWaveCrush waveCrush = (ChallengeWaveCrush) challenge;
for (Player player : getGame().GetPlayers(true))
{
if (waveCrush.hasData(player))
{
int score = (int) waveCrush.getData(player);
if (score > 0)
{
System.out.println("Surf Up: " + player.getName());
addStat(player, "SurfUp", score, false, false);
}
}
}
}
}
}

View File

@ -0,0 +1,41 @@
package nautilus.game.arcade.game.games.mineware.tracker;
import org.bukkit.entity.Player;
import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.games.mineware.challenge.Challenge;
import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeReverseTag;
/**
* A tracker for the Tag Master achievement.
* <br>
* <br>
* <b>Challenge:</b> Tag Master
* <br>
* <b>Goal:</b> Win 5 entire rounds without being untagged
*/
public class TagMasterTracker extends ChallengeStatTracker
{
public TagMasterTracker(Game game)
{
super(game);
}
@Override
protected void track(Challenge challenge)
{
if (challenge instanceof ChallengeReverseTag)
{
ChallengeReverseTag reverseTag = (ChallengeReverseTag) challenge;
for (Player player : reverseTag.getFirstTeam().getPlayers())
{
if (reverseTag.hasData(player))
{
System.out.println("Tag Master: " + player.getName());
addStat(player, "TagMaster", 1, false, false);
}
}
}
}
}

View File

@ -0,0 +1,39 @@
package nautilus.game.arcade.game.games.mineware.tracker;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.stats.StatTracker;
/**
* A tracker for the Veteran achievement.
* <br>
* <br>
* <b>Goal:</b> Win 50 games of Bawk Bawk Battles
*/
public class VeteranTracker extends StatTracker<Game>
{
public VeteranTracker(Game game)
{
super(game);
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onGameStateChange(GameStateChangeEvent event)
{
if (event.GetState() == GameState.End && getGame().getWinners().size() > 0)
{
Player winner = getGame().getWinners().get(0);
if (winner != null)
{
System.out.println("Veteran: " + winner.getName());
addStat(winner, "Veteran", 1, true, false);
}
}
}
}

View File

@ -342,7 +342,7 @@ public abstract class ProgressingKit extends Kit implements ProgressiveKit
return C.cWhite + "Receive " + C.cGreen + amount + C.cWhite + " arrow" + (amount == 1 ? "" : "s") + " every " + C.cGreen + per + C.cWhite + " seconds. Max " + C.cGreen + max;
}
private static class CustomFirework extends EntityFireworks
public static class CustomFirework extends EntityFireworks
{
private Player[] players;

View File

@ -759,7 +759,8 @@ public class GameManager implements Listener
public void run()
{
//Teleport
team.SpawnTeleport(player);
if (game.SpawnTeleport)
team.SpawnTeleport(player);
game.addPlayerInTime(player);