diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilParser.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilParser.java new file mode 100644 index 000000000..453904e1e --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilParser.java @@ -0,0 +1,59 @@ +package mineplex.core.common.util; + +import org.bukkit.event.entity.EntityDamageEvent; + +public class UtilParser +{ + public static String parseDamageCause(EntityDamageEvent.DamageCause cause) + { + switch (cause) + { + case CONTACT: + return "Cactus"; + case ENTITY_ATTACK: + return "Attack"; + case PROJECTILE: + return "Ranged Weapon"; + case SUFFOCATION: + return "Suffocation"; + case FALL: + return "Fall"; + case FIRE: + return "Fire"; + case FIRE_TICK: + return "Burning"; + case MELTING: + return "Melting"; + case LAVA: + return "Lava"; + case DROWNING: + return "Drowning"; + case BLOCK_EXPLOSION: + return "Explosion"; + case ENTITY_EXPLOSION: + return "Explosion"; + case VOID: + return "Void"; + case LIGHTNING: + return "Lightning"; + case SUICIDE: + return "Suicide"; + case STARVATION: + return "Hunger"; + case POISON: + return "Poison"; + case MAGIC: + return "Thrown Potion"; + case WITHER: + return "Wither Effect"; + case FALLING_BLOCK: + return "Falling Block"; + case THORNS: + return "Thorns Enchantment"; + case CUSTOM: + return "Custom"; + default: + return "The Mighty defek7"; + } + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/command/TestRank.java b/Plugins/Mineplex.Core/src/mineplex/core/account/command/TestRank.java index 7d976f0ce..9387b2cf2 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/account/command/TestRank.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/command/TestRank.java @@ -22,9 +22,9 @@ public class TestRank extends CommandBase @Override public void Execute(final Player caller, String[] args) { - if (!Plugin.Get(caller).GetRank(true).has(Rank.JNR_DEV)) + if (!Plugin.Get(caller).GetRank(true).has(Rank.SNR_MODERATOR)) { - UtilPlayer.message(caller, F.main("Permissions", "This requires Permission Rank [" + Rank.JNR_DEV.getTag(false, true) + C.cGray + "].")); + UtilPlayer.message(caller, F.main("Permissions", "This requires Permission Rank [" + Rank.SNR_MODERATOR.getTag(false, true) + C.cGray + "].")); return; } @@ -65,6 +65,14 @@ public class TestRank extends CommandBase UtilPlayer.message(caller, F.main(Plugin.getName(), ChatColor.RED + "" + ChatColor.BOLD + "Invalid rank!")); return; } + if (Plugin.Get(caller).GetRank(true) == Rank.SNR_MODERATOR) + { + if (tempRank.has(Rank.TWITCH)) + { + UtilPlayer.message(caller, F.main("Command", "You can only test Player ranks!")); + return; + } + } Plugin.Get(caller).SetRank(tempRank, true); UtilPlayer.message(caller, F.main(Plugin.getName(), "Your rank has been set to " + tempRank.getTag(false, false) + C.cGray + "!")); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/achievement/Achievement.java b/Plugins/Mineplex.Core/src/mineplex/core/achievement/Achievement.java index a0fedc46e..058c0e255 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/achievement/Achievement.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/achievement/Achievement.java @@ -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"}, diff --git a/Plugins/Mineplex.Core/src/mineplex/core/achievement/AchievementCategory.java b/Plugins/Mineplex.Core/src/mineplex/core/achievement/AchievementCategory.java index 1770f85c3..21c3b2466 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/achievement/AchievementCategory.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/achievement/AchievementCategory.java @@ -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()), diff --git a/Plugins/Mineplex.Core/src/mineplex/core/achievement/ui/page/AchievementMainPage.java b/Plugins/Mineplex.Core/src/mineplex/core/achievement/ui/page/AchievementMainPage.java index 3817df163..280e3ba54 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/achievement/ui/page/AchievementMainPage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/achievement/ui/page/AchievementMainPage.java @@ -46,7 +46,7 @@ public class AchievementMainPage extends ShopPageBase pageLayout = new ItemLayout( - "XXXXOXXXO", + "XXXXOXOXO", "OXOXOXOXO", "OXOXOXOXO", "OXOXOXOXO").getItemSlots(); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java index 45736c3d6..f31e9ce0a 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java @@ -277,7 +277,7 @@ public class BonusManager extends MiniClientPlugin implements I // return _voteStreak; // } - public void handleVote(final Player player, final int gemsReceived) + public void handleVote(final Player player, final int shardsReceived) { final int accountId = _clientManager.getAccountId(player); @@ -303,7 +303,7 @@ public class BonusManager extends MiniClientPlugin implements I _statsManager.incrementStat(player, "Global.DailyVote", 1); addPendingExplosion(player, player.getName()); UtilPlayer.message(player, F.main("Carl", "Thanks for voting for Mineplex!")); - UtilPlayer.message(player, F.main("Carl", "You received " + F.elem(gemsReceived + " Gems") + " and " + F.elem("1 Carl Spinner Ticket") + "!")); + UtilPlayer.message(player, F.main("Carl", "You received " + F.elem("1 Carl Spinner Ticket") + "!")); } }); } @@ -618,16 +618,16 @@ public class BonusManager extends MiniClientPlugin implements I BonusClientData client = Get(player); int streak = client.getDailyStreak(); - int multiplyer = Math.min(200, 5 * streak); - if (streak >= 40) multiplyer += (1 * (streak - 40)); - return multiplyer; + int multiplier = Math.min(200, 5 * streak); + if (streak >= 40) multiplier += (1 * (streak - 40)); + return multiplier; } - public int getVoteMultiplyer(int streak) + public int getVoteMultiplier(int streak) { - int multiplyer = Math.min(100, 5 * streak); - if (streak >= 20) multiplyer += (1 * (streak - 40)); - return multiplyer; + int multiplier = Math.min(100, 5 * streak); + if (streak >= 20) multiplier += (1 * (streak - 40)); + return multiplier; } public BonusAmount getDailyBonusAmount(Player player) @@ -656,12 +656,10 @@ public class BonusManager extends MiniClientPlugin implements I public BonusAmount getVoteBonusAmount(int voteStreak) { - double mult = getVoteMultiplyer(voteStreak) / 100.0; + double mult = getVoteMultiplier(voteStreak) / 100.0; BonusAmount amount = new BonusAmount(); amount.setTickets(1); - amount.setGems(400); - amount.setBonusGems((int) (mult * 400)); return amount; } @@ -1200,4 +1198,4 @@ public class BonusManager extends MiniClientPlugin implements I { return _boosterManager; } -} \ No newline at end of file +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/VoteButton.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/VoteButton.java index 1b69a3fd9..2d758624e 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/VoteButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/VoteButton.java @@ -129,7 +129,7 @@ public class VoteButton implements GuiItem, Listener { lore.add(" "); lore.add(C.cYellow + "Current Streak: " + C.cWhite + client.getVoteStreak()); - lore.add(C.cYellow + "Streak Bonus: " + C.cWhite + "+" + _bonusManager.getVoteMultiplyer(client.getVoteStreak()) + "%"); + lore.add(C.cYellow + "Streak Bonus: " + C.cWhite + "+" + _bonusManager.getVoteMultiplier(client.getVoteStreak()) + "%"); if (client.getVoteTime() != null) { long lastBonus = _bonusManager.getLocalTime(client.getVoteTime().getTime()); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/redis/VoteHandler.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/redis/VoteHandler.java index 54f2a820b..0a2d370ba 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/redis/VoteHandler.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/redis/VoteHandler.java @@ -25,7 +25,7 @@ public class VoteHandler implements CommandCallback if (player != null) { - _bonusManager.handleVote(player, v.getGemsReceived()); + _bonusManager.handleVote(player, v.getShardsReceived()); } } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/redis/VotifierCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/redis/VotifierCommand.java index 95dbb06a4..7281d5805 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/redis/VotifierCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/redis/VotifierCommand.java @@ -5,14 +5,14 @@ import mineplex.serverdata.commands.ServerCommand; public class VotifierCommand extends ServerCommand { private String _playerName; - private int _gemsReceived; + private int _shardsReceived; - public VotifierCommand(String playerName, int gemsReceived, String... targetServer) + public VotifierCommand(String playerName, int shardsReceived, String... targetServer) { super(targetServer); _playerName = playerName; - _gemsReceived = gemsReceived; + _shardsReceived = shardsReceived; } public String getPlayerName() @@ -20,9 +20,9 @@ public class VotifierCommand extends ServerCommand return _playerName; } - public int getGemsReceived() + public int getShardsReceived() { - return _gemsReceived; + return _shardsReceived; } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/boosters/gui/BoosterPage.java b/Plugins/Mineplex.Core/src/mineplex/core/boosters/gui/BoosterPage.java index e3a9da071..3a6315ec9 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/boosters/gui/BoosterPage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/boosters/gui/BoosterPage.java @@ -81,7 +81,7 @@ public class BoosterPage extends ShopPageBase { lore.add(" "); lore.add(C.cGray + "Game Amplifiers allow you to"); - lore.add(C.cGray + "increase the gems and shards"); + lore.add(C.cGray + "increase the shards"); lore.add(C.cGray + "earned in that game for 1 hour."); lore.add(C.cGray + "You will also earn bonus rewards"); lore.add(C.cGray + "from players thanking you while"); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java index f4f95e586..c60d7594e 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java @@ -592,7 +592,7 @@ public class GadgetManager extends MiniPlugin if (armor.getSlot() == slot) { - armor.removeArmor(player); + armor.removeArmor(player, true); } } } @@ -671,7 +671,7 @@ public class GadgetManager extends MiniPlugin } for (Gadget gadget : _gadgets.get(gadgetType)) { - gadget.disable(player); + gadget.disable(player, false); } } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/balloons/BabyCowBalloon.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/balloons/BabyCowBalloon.java index 883957f59..4b1e7e23f 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/balloons/BabyCowBalloon.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/balloons/BabyCowBalloon.java @@ -41,7 +41,7 @@ public class BabyCowBalloon extends BalloonGadget } @Override - public void disableCustom(Player player) + public void disableCustom(Player player, boolean message) { _entityStand.remove(); _balloonEntity.remove(); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/item/ItemBatGun.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/item/ItemBatGun.java index a9add458a..f0c658846 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/item/ItemBatGun.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/item/ItemBatGun.java @@ -47,9 +47,9 @@ public class ItemBatGun extends ItemGadget } @Override - public void disableCustom(Player player) + public void disableCustom(Player player, boolean message) { - super.disableCustom(player); + super.disableCustom(player, message); Clear(player); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/item/ItemEtherealPearl.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/item/ItemEtherealPearl.java index 973d2f55d..96fa54ed6 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/item/ItemEtherealPearl.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/item/ItemEtherealPearl.java @@ -42,9 +42,9 @@ public class ItemEtherealPearl extends ItemGadget } @Override - public void disableCustom(Player player) + public void disableCustom(Player player, boolean message) { - super.disableCustom(player); + super.disableCustom(player, message); } @Override diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/item/ItemPaintbrush.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/item/ItemPaintbrush.java index 0c75b1a81..98171d0c3 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/item/ItemPaintbrush.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/item/ItemPaintbrush.java @@ -89,13 +89,13 @@ public class ItemPaintbrush extends ItemGadget @Override - public void disableCustom(Player player) + public void disableCustom(Player player, boolean message) { _brushColor.remove(player.getName()); _brushPrevious.remove(player.getName()); _playerLocation.remove(player.getName()); - RemoveItem(player); + RemoveItem(player, message); } @EventHandler diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphBat.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphBat.java index d8ca2a8eb..5a3e85f68 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphBat.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphBat.java @@ -65,7 +65,7 @@ public class MorphBat extends MorphGadget implements IThrown } @Override - public void disableCustom(Player player) + public void disableCustom(Player player, boolean message) { this.RemoveArmor(player); Manager.getDisguiseManager().undisguise(player); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphBlaze.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphBlaze.java index 57bb92473..0708fe148 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphBlaze.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphBlaze.java @@ -48,7 +48,7 @@ public class MorphBlaze extends MorphGadget } @Override - public void disableCustom(Player player) + public void disableCustom(Player player, boolean message) { this.RemoveArmor(player); Manager.getDisguiseManager().undisguise(player); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphBlock.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphBlock.java index c04d0eba3..e1c9a15aa 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphBlock.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphBlock.java @@ -54,7 +54,7 @@ public class MorphBlock extends MorphGadget } @Override - public void disableCustom(Player player) + public void disableCustom(Player player, boolean message) { this.RemoveArmor(player); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphBunny.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphBunny.java index 60bd653e9..762dc9a7c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphBunny.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphBunny.java @@ -79,7 +79,7 @@ public class MorphBunny extends MorphGadget } @Override - public void disableCustom(Player player) + public void disableCustom(Player player, boolean message) { _jumpCharge.remove(player); this.RemoveArmor(player); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphChicken.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphChicken.java index 34a3cd6b9..20c997d91 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphChicken.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphChicken.java @@ -54,7 +54,7 @@ public class MorphChicken extends MorphGadget } @Override - public void disableCustom(Player player) + public void disableCustom(Player player, boolean message) { this.RemoveArmor(player); Manager.getDisguiseManager().undisguise(player); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphCow.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphCow.java index 4cbe53990..652c35330 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphCow.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphCow.java @@ -42,7 +42,7 @@ public class MorphCow extends MorphGadget } @Override - public void disableCustom(Player player) + public void disableCustom(Player player, boolean message) { this.RemoveArmor(player); Manager.getDisguiseManager().undisguise(player); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphCreeper.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphCreeper.java index fe68c21f0..149c59a82 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphCreeper.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphCreeper.java @@ -56,7 +56,7 @@ public class MorphCreeper extends MorphGadget } @Override - public void disableCustom(Player player) + public void disableCustom(Player player, boolean message) { this.RemoveArmor(player); Manager.getDisguiseManager().undisguise(player); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphEnderman.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphEnderman.java index e167ec7c8..59e7d9e2f 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphEnderman.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphEnderman.java @@ -53,7 +53,7 @@ public class MorphEnderman extends MorphGadget } @Override - public void disableCustom(Player player) + public void disableCustom(Player player, boolean message) { this.RemoveArmor(player); Manager.getDisguiseManager().undisguise(player); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphPig.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphPig.java index b8a94970b..5a0e4f4c2 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphPig.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphPig.java @@ -55,7 +55,7 @@ public class MorphPig extends MorphGadget } @Override - public void disableCustom(Player player) + public void disableCustom(Player player, boolean message) { this.RemoveArmor(player); Manager.getDisguiseManager().undisguise(player); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphPumpkinKing.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphPumpkinKing.java index 7bed212fc..ae4aa8913 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphPumpkinKing.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphPumpkinKing.java @@ -1,6 +1,5 @@ package mineplex.core.gadget.gadgets.morph; -import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.entity.Skeleton.SkeletonType; @@ -47,7 +46,7 @@ public class MorphPumpkinKing extends MorphGadget } @Override - public void disableCustom(Player player) + public void disableCustom(Player player, boolean message) { this.RemoveArmor(player); Manager.getDisguiseManager().undisguise(player); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphSlime.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphSlime.java index a184823ac..7ea51f3f0 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphSlime.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphSlime.java @@ -65,7 +65,7 @@ public class MorphSlime extends MorphGadget } @Override - public void disableCustom(Player player) + public void disableCustom(Player player, boolean message) { this.RemoveArmor(player); Manager.getDisguiseManager().undisguise(player); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphSnowman.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphSnowman.java index e8b1786ef..3996d5626 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphSnowman.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphSnowman.java @@ -66,7 +66,7 @@ public class MorphSnowman extends MorphGadget } @Override - public void disableCustom(Player player) + public void disableCustom(Player player, boolean message) { this.RemoveArmor(player); Manager.getDisguiseManager().undisguise(player); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphTitan.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphTitan.java index 9881ffa93..c2bcd1cc7 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphTitan.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphTitan.java @@ -70,7 +70,7 @@ public class MorphTitan extends MorphGadget } @Override - public void disableCustom(Player player) + public void disableCustom(Player player, boolean message) { this.RemoveArmor(player); Manager.getDisguiseManager().undisguise(player); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphUncleSam.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphUncleSam.java index 5c525b591..44cad0b25 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphUncleSam.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphUncleSam.java @@ -46,7 +46,7 @@ public class MorphUncleSam extends MorphGadget } @Override - public void disableCustom(Player player) + public void disableCustom(Player player, boolean message) { this.RemoveArmor(player); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphVillager.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphVillager.java index 9290bd13b..3480504e3 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphVillager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphVillager.java @@ -64,7 +64,7 @@ public class MorphVillager extends MorphGadget implements IThrown } @Override - public void disableCustom(Player player) + public void disableCustom(Player player, boolean message) { this.RemoveArmor(player); Manager.getDisguiseManager().undisguise(player); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphWither.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphWither.java index aa1f7a03f..505551d3b 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphWither.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphWither.java @@ -73,7 +73,7 @@ public class MorphWither extends MorphGadget } @Override - public void disableCustom(Player player) + public void disableCustom(Player player, boolean message) { this.RemoveArmor(player); Manager.getDisguiseManager().undisguise(player); @@ -200,7 +200,7 @@ public class MorphWither extends MorphGadget if (disguise == null || !(disguise instanceof DisguiseWither)) { - disableCustom(player); + disableCustom(player, true); activeIterator.remove(); continue; } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/OutfitTeam.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/OutfitTeam.java index 8aa3d98ad..087893c88 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/OutfitTeam.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/OutfitTeam.java @@ -77,7 +77,7 @@ public class OutfitTeam extends OutfitGadget } @Override - public void removeArmor(Player player) + public void removeArmor(Player player, boolean message) { if (!_active.remove(player)) return; @@ -96,9 +96,9 @@ public class OutfitTeam extends OutfitGadget } @Override - public void disableCustom(Player player) + public void disableCustom(Player player, boolean message) { - removeArmor(player); + removeArmor(player, message); } @EventHandler(priority=EventPriority.LOWEST) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/ravesuit/OutfitRaveSuit.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/ravesuit/OutfitRaveSuit.java index 4140410f4..adfef82bc 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/ravesuit/OutfitRaveSuit.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/ravesuit/OutfitRaveSuit.java @@ -43,9 +43,9 @@ public class OutfitRaveSuit extends OutfitGadget } @Override - public void disableCustom(Player player) + public void disableCustom(Player player, boolean message) { - removeArmor(player); + removeArmor(player, message); _colorPhase.remove(player.getName()); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/spacesuit/OutfitSpaceSuit.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/spacesuit/OutfitSpaceSuit.java index d27a3f56c..bac66d1ae 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/spacesuit/OutfitSpaceSuit.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/spacesuit/OutfitSpaceSuit.java @@ -32,9 +32,9 @@ public class OutfitSpaceSuit extends OutfitGadget } @Override - public void disableCustom(Player player) + public void disableCustom(Player player, boolean message) { - removeArmor(player); + removeArmor(player, message); } @EventHandler diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/windupsuit/OutfitWindUpSuit.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/windupsuit/OutfitWindUpSuit.java index c67e5a9c2..974ff360a 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/windupsuit/OutfitWindUpSuit.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/windupsuit/OutfitWindUpSuit.java @@ -41,9 +41,9 @@ public class OutfitWindUpSuit extends OutfitGadget } @Override - public void disableCustom(Player player) + public void disableCustom(Player player, boolean message) { - removeArmor(player); + removeArmor(player, message); _colorPhase.remove(player); _percentage.remove(player); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleFairy.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleFairy.java index a72364d41..2116e7604 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleFairy.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleFairy.java @@ -36,7 +36,7 @@ public class ParticleFairy extends ParticleGadget } @Override - public void disableCustom(Player player) + public void disableCustom(Player player, boolean message) { if (_active.remove(player)) UtilPlayer.message(player, F.main("Gadget", "You unsummoned " + F.elem(getName()) + ".")); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleKronos.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleKronos.java index da57bfcb6..1b3751877 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleKronos.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleKronos.java @@ -61,7 +61,7 @@ public class ParticleKronos extends ParticleGadget } @Override - public void disableCustom(Player player) + public void disableCustom(Player player, boolean message) { if (_active.remove(player)) UtilPlayer.message(player, F.main("Gadget", "You unsummoned " + F.elem(getName()) + ".")); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/cupidslove/ParticleHeart.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/cupidslove/ParticleHeart.java index b10b946f5..db4464335 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/cupidslove/ParticleHeart.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/cupidslove/ParticleHeart.java @@ -46,7 +46,7 @@ public class ParticleHeart extends ParticleGadget } @Override - public void disableCustom(Player player) + public void disableCustom(Player player, boolean message) { if (_active.remove(player)) UtilPlayer.message(player, F.main("Gadget", "You unsummoned " + F.elem(getName()) + ".")); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/Gadget.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/Gadget.java index 136fd8093..20742f4f3 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/Gadget.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/Gadget.java @@ -123,13 +123,18 @@ public abstract class Gadget extends SalesPackageBase implements Listener } public void disable(Player player) + { + disable(player, true); + } + + public void disable(Player player, boolean message) { if (isActive(player)) { Manager.removeActive(player, this); GadgetDisableEvent event = new GadgetDisableEvent(player, this); Bukkit.getServer().getPluginManager().callEvent(event); - disableCustom(player); + disableCustom(player, message); } } @@ -141,12 +146,12 @@ public abstract class Gadget extends SalesPackageBase implements Listener UtilPlayer.message(player, F.main("Gadget", "You enabled " + F.elem(getName()) + ".")); } - public void disableCustom(Player player) + public void disableCustom(Player player, boolean message) { - if (_active.remove(player)) + if (_active.remove(player) && message) UtilPlayer.message(player, F.main("Gadget", "You disabled " + F.elem(getName()) + ".")); } - + @Override public void sold(Player player, CurrencyType currencyType) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/HatGadget.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/HatGadget.java index 55c249907..6c647876c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/HatGadget.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/HatGadget.java @@ -59,12 +59,13 @@ public abstract class HatGadget extends OutfitGadget player.getInventory().setHelmet(getHelmetItem()); } - public void removeArmor(Player player) + public void removeArmor(Player player, boolean message) { if (!_active.remove(player)) return; - - UtilPlayer.message(player, F.main("Gadget", "You took off " + F.elem(getName()) + ".")); + + if (message) + UtilPlayer.message(player, F.main("Gadget", "You took off " + F.elem(getName()) + ".")); player.getInventory().setHelmet(null); } @@ -96,9 +97,9 @@ public abstract class HatGadget extends OutfitGadget } @Override - public void disableCustom(Player player) + public void disableCustom(Player player, boolean message) { - removeArmor(player); + removeArmor(player, message); } public HatType getHatType() diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/ItemGadget.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/ItemGadget.java index e6125a64f..657ad67ac 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/ItemGadget.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/ItemGadget.java @@ -56,9 +56,9 @@ public abstract class ItemGadget extends Gadget } @Override - public void disableCustom(Player player) + public void disableCustom(Player player, boolean message) { - RemoveItem(player); + RemoveItem(player, message); } public HashSet getActive() @@ -113,13 +113,14 @@ public abstract class ItemGadget extends Gadget } } - public void RemoveItem(Player player) + public void RemoveItem(Player player, boolean message) { if (_active.remove(player)) { player.getInventory().setItem(Manager.getActiveItemSlot(), null); - - UtilPlayer.message(player, F.main("Gadget", "You unequipped " + F.elem(getName()) + ".")); + + if (message) + UtilPlayer.message(player, F.main("Gadget", "You unequipped " + F.elem(getName()) + ".")); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/OutfitGadget.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/OutfitGadget.java index 1b0d32d54..72edc0486 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/OutfitGadget.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/OutfitGadget.java @@ -68,12 +68,13 @@ public abstract class OutfitGadget extends Gadget ItemStackFactory.Instance.CreateStack(getDisplayMaterial().getId(), getDisplayData(), 1, getName())); } - public void removeArmor(Player player) + public void removeArmor(Player player, boolean message) { if (!_active.remove(player)) return; - - UtilPlayer.message(player, F.main("Gadget", "You took off " + F.elem(getName()) + ".")); + + if (message) + UtilPlayer.message(player, F.main("Gadget", "You took off " + F.elem(getName()) + ".")); if (_slot == ArmorSlot.Helmet) player.getInventory().setHelmet(null); else if (_slot == ArmorSlot.Chest) player.getInventory().setChestplate(null); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/ParticleGadget.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/ParticleGadget.java index aaaeb60d0..06af3908b 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/ParticleGadget.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/ParticleGadget.java @@ -41,7 +41,7 @@ public abstract class ParticleGadget extends Gadget } @Override - public void disableCustom(Player player) + public void disableCustom(Player player, boolean message) { if (_active.remove(player)) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/WinEffectGadget.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/WinEffectGadget.java index 76b052693..7be83f481 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/WinEffectGadget.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/WinEffectGadget.java @@ -303,7 +303,7 @@ public abstract class WinEffectGadget extends Gadget public Schematic pasteScematic(String schematicName) { try { - Schematic schematic = UtilSchematic.loadSchematic(new File("schematic" + File.separator + schematicName + ".schematic")); + Schematic schematic = UtilSchematic.loadSchematic(new File("../../update/schematic/" + schematicName + ".schematic")); if (schematic != null) schematic.paste(getBaseLocation(), false, true); return schematic; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/game/GameDisplay.java b/Plugins/Mineplex.Core/src/mineplex/core/game/GameDisplay.java index 084b0bc12..5bc78f8a3 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/game/GameDisplay.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/game/GameDisplay.java @@ -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.CLASSICS, 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), diff --git a/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/GlobalPacketManager.java b/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/GlobalPacketManager.java index b05a3d4ac..29a908e16 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/GlobalPacketManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/GlobalPacketManager.java @@ -16,7 +16,6 @@ import mineplex.core.globalpacket.command.GlobalPacketCommand; import mineplex.core.globalpacket.listeners.GlobalGiveCoins; import mineplex.core.globalpacket.listeners.GlobalGiveGems; import mineplex.core.globalpacket.listeners.GlobalGiveItem; -import mineplex.core.globalpacket.listeners.GlobalRawr; import mineplex.core.globalpacket.redis.GlobalPacketHandler; import mineplex.core.globalpacket.redis.GlobalPacketMessage; import mineplex.core.inventory.InventoryManager; @@ -49,7 +48,6 @@ public class GlobalPacketManager extends MiniPlugin getPluginManager().registerEvents(new GlobalGiveItem(inventoryManager, _rewardManager), getPlugin()); getPluginManager().registerEvents(new GlobalGiveGems(donationManager), getPlugin()); getPluginManager().registerEvents(new GlobalGiveCoins(donationManager, clientManager), getPlugin()); - getPluginManager().registerEvents(new GlobalRawr(), getPlugin()); } public void callGlobalCommand(Player caller, String[] args) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/listeners/GlobalRawr.java b/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/listeners/GlobalRawr.java deleted file mode 100644 index ffba8fb83..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/listeners/GlobalRawr.java +++ /dev/null @@ -1,50 +0,0 @@ -package mineplex.core.globalpacket.listeners; - -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; - -import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilPlayer; -import mineplex.core.common.util.UtilServer; -import mineplex.core.common.util.UtilTextMiddle; -import mineplex.core.globalpacket.event.GlobalPacketEvent; - -/** - * Created by William (WilliamTiger). - * 18/11/15 - */ -public class GlobalRawr implements Listener -{ - - @EventHandler - public void globalRawr(GlobalPacketEvent e) - { - if (e.getParts() == null || e.getParts().length < 1) - return; - - if (!e.getParts()[0].equalsIgnoreCase("rawr")) - return; - - if (e.getParts().length < 2) - { - if (e.getCaller() != null) - UtilPlayer.message(e.getCaller(), F.main("Global", "/global rawr ")); - - return; - } - - String msg = ""; - for (int i = 1; i < e.getParts().length; i++) - { - msg += e.getParts()[i] + " "; - } - msg = msg.trim(); - - for (Player p : UtilServer.getPlayers()) - { - UtilTextMiddle.display("§6§lRAWR!", "§e" + msg, p); - } - } - -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/inventory/InventoryManager.java b/Plugins/Mineplex.Core/src/mineplex/core/inventory/InventoryManager.java index 43a1d22e8..d3a3c4107 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/inventory/InventoryManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/inventory/InventoryManager.java @@ -227,7 +227,8 @@ public class InventoryManager extends MiniDbClientPlugin event.getInventory().setItem(1, new ItemStack(Material.INK_SACK, level, (byte) 4)); } - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + // fixme broken cast +// @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onBlockBreak(BlockBreakEvent event) { if (event.getBlock().getType() != Material.ENCHANTMENT_TABLE) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/personalServer/PersonalServerManager.java b/Plugins/Mineplex.Core/src/mineplex/core/personalServer/PersonalServerManager.java index 93db55bf3..10648f4ed 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/personalServer/PersonalServerManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/personalServer/PersonalServerManager.java @@ -159,7 +159,7 @@ public class PersonalServerManager extends MiniPlugin } } - final ServerGroup serverGroup = new ServerGroup(serverName, serverName, host.getName(), ram, cpu, 1, 0, UtilMath.random.nextInt(250) + 19999, true, "arcade.zip", "Arcade.jar", "plugins/Arcade/", minPlayers, maxPlayers, + final ServerGroup serverGroup = new ServerGroup(serverName, serverName, host.getName(), ram, cpu, 1, 0, UtilMath.random.nextInt(250) + 19999, "", true, "arcade.zip", "Arcade.jar", "plugins/Arcade/", minPlayers, maxPlayers, true, false, false, games, "", "", "Player", true, event, false, true, false, true, true, false, false, false, false, true, true, true, false, false, "", _us ? Region.US : Region.EU, "", "", "", ""); getPlugin().getServer().getScheduler().runTaskAsynchronously(getPlugin(), new Runnable() diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardManager.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardManager.java index 508a59d2c..947cb4494 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardManager.java @@ -5,62 +5,44 @@ import java.util.EnumMap; import java.util.List; import java.util.Random; -import mineplex.core.common.util.banner.CountryFlag; -import mineplex.core.gadget.gadgets.arrowtrail.freedom.ArrowTrailFreedom; -import mineplex.core.gadget.gadgets.death.freedom.DeathFreedom; -import mineplex.core.gadget.gadgets.doublejump.freedom.DoubleJumpFreedom; -import mineplex.core.gadget.gadgets.hat.*; -import mineplex.core.gadget.gadgets.morph.*; -import mineplex.core.gadget.gadgets.particle.*; -import mineplex.core.gadget.gadgets.particle.candycane.ParticleCandyCane; -import mineplex.core.gadget.gadgets.particle.cupidslove.ParticleHeart; -import mineplex.core.gadget.gadgets.particle.emerald.ParticleEmerald; -import mineplex.core.gadget.gadgets.particle.freedom.ParticleFreedom; -import mineplex.core.gadget.gadgets.particle.frostlord.ParticleFrostLord; -import mineplex.core.gadget.gadgets.particle.howlingwinds.ParticleRain; -import mineplex.core.gadget.gadgets.particle.music.ParticleMusic; -import mineplex.core.gadget.gadgets.particle.party.ParticlePartyTime; -import mineplex.core.gadget.gadgets.particle.shadow.ParticleFoot; -import mineplex.core.gadget.gadgets.particle.vampire.ParticleBlood; -import mineplex.core.gadget.gadgets.particle.wisdom.ParticleEnchant; -import mineplex.core.mount.types.*; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - import mineplex.core.account.CoreClientManager; import mineplex.core.common.Rank; +import mineplex.core.common.util.banner.CountryFlag; import mineplex.core.donation.DonationManager; import mineplex.core.gadget.GadgetManager; -import mineplex.core.gadget.gadgets.arrowtrail.vampire.ArrowTrailBlood; -import mineplex.core.gadget.gadgets.arrowtrail.party.ArrowTrailConfetti; import mineplex.core.gadget.gadgets.arrowtrail.cupidslove.ArrowTrailCupid; import mineplex.core.gadget.gadgets.arrowtrail.emerald.ArrowTrailEmerald; -import mineplex.core.gadget.gadgets.arrowtrail.wisdom.ArrowTrailEnchant; +import mineplex.core.gadget.gadgets.arrowtrail.freedom.ArrowTrailFreedom; import mineplex.core.gadget.gadgets.arrowtrail.frostlord.ArrowTrailFrostLord; -import mineplex.core.gadget.gadgets.arrowtrail.music.ArrowTrailMusic; -import mineplex.core.gadget.gadgets.arrowtrail.shadow.ArrowTrailShadow; import mineplex.core.gadget.gadgets.arrowtrail.howlingwinds.ArrowTrailStorm; -import mineplex.core.gadget.gadgets.death.vampire.DeathBlood; +import mineplex.core.gadget.gadgets.arrowtrail.music.ArrowTrailMusic; +import mineplex.core.gadget.gadgets.arrowtrail.party.ArrowTrailConfetti; +import mineplex.core.gadget.gadgets.arrowtrail.shadow.ArrowTrailShadow; +import mineplex.core.gadget.gadgets.arrowtrail.vampire.ArrowTrailBlood; +import mineplex.core.gadget.gadgets.arrowtrail.wisdom.ArrowTrailEnchant; import mineplex.core.gadget.gadgets.death.candycane.DeathCandyCane; import mineplex.core.gadget.gadgets.death.cupidslove.DeathCupidsBrokenHeart; import mineplex.core.gadget.gadgets.death.emerald.DeathEmerald; -import mineplex.core.gadget.gadgets.death.wisdom.DeathEnchant; +import mineplex.core.gadget.gadgets.death.freedom.DeathFreedom; import mineplex.core.gadget.gadgets.death.frostlord.DeathFrostLord; +import mineplex.core.gadget.gadgets.death.howlingwinds.DeathStorm; import mineplex.core.gadget.gadgets.death.music.DeathMusic; import mineplex.core.gadget.gadgets.death.party.DeathPinataBurst; import mineplex.core.gadget.gadgets.death.shadow.DeathShadow; -import mineplex.core.gadget.gadgets.death.howlingwinds.DeathStorm; -import mineplex.core.gadget.gadgets.doublejump.vampire.DoubleJumpBlood; +import mineplex.core.gadget.gadgets.death.vampire.DeathBlood; +import mineplex.core.gadget.gadgets.death.wisdom.DeathEnchant; import mineplex.core.gadget.gadgets.doublejump.cupidslove.DoubleJumpCupidsWings; import mineplex.core.gadget.gadgets.doublejump.emerald.DoubleJumpEmerald; -import mineplex.core.gadget.gadgets.doublejump.wisdom.DoubleJumpEnchant; -import mineplex.core.gadget.gadgets.doublejump.party.DoubleJumpFirecracker; +import mineplex.core.gadget.gadgets.doublejump.freedom.DoubleJumpFreedom; import mineplex.core.gadget.gadgets.doublejump.frostlord.DoubleJumpFrostLord; -import mineplex.core.gadget.gadgets.doublejump.music.DoubleJumpMusic; -import mineplex.core.gadget.gadgets.doublejump.shadow.DoubleJumpShadow; import mineplex.core.gadget.gadgets.doublejump.howlingwinds.DoubleJumpStorm; +import mineplex.core.gadget.gadgets.doublejump.music.DoubleJumpMusic; +import mineplex.core.gadget.gadgets.doublejump.party.DoubleJumpFirecracker; +import mineplex.core.gadget.gadgets.doublejump.shadow.DoubleJumpShadow; +import mineplex.core.gadget.gadgets.doublejump.vampire.DoubleJumpBlood; +import mineplex.core.gadget.gadgets.doublejump.wisdom.DoubleJumpEnchant; import mineplex.core.gadget.gadgets.gamemodifiers.minestrike.MineStrikeSkin; +import mineplex.core.gadget.gadgets.hat.HatType; import mineplex.core.gadget.gadgets.item.ItemBatGun; import mineplex.core.gadget.gadgets.item.ItemBow; import mineplex.core.gadget.gadgets.item.ItemCoal; @@ -74,6 +56,15 @@ import mineplex.core.gadget.gadgets.item.ItemPaintballGun; import mineplex.core.gadget.gadgets.item.ItemPartyPopper; import mineplex.core.gadget.gadgets.item.ItemSnowball; import mineplex.core.gadget.gadgets.item.ItemTNT; +import mineplex.core.gadget.gadgets.morph.MorphBat; +import mineplex.core.gadget.gadgets.morph.MorphBlock; +import mineplex.core.gadget.gadgets.morph.MorphChicken; +import mineplex.core.gadget.gadgets.morph.MorphCow; +import mineplex.core.gadget.gadgets.morph.MorphEnderman; +import mineplex.core.gadget.gadgets.morph.MorphSlime; +import mineplex.core.gadget.gadgets.morph.MorphSnowman; +import mineplex.core.gadget.gadgets.morph.MorphUncleSam; +import mineplex.core.gadget.gadgets.morph.MorphVillager; import mineplex.core.gadget.gadgets.outfit.ravesuit.OutfitRaveSuitBoots; import mineplex.core.gadget.gadgets.outfit.ravesuit.OutfitRaveSuitChestplate; import mineplex.core.gadget.gadgets.outfit.ravesuit.OutfitRaveSuitHelmet; @@ -82,6 +73,24 @@ import mineplex.core.gadget.gadgets.outfit.spacesuit.OutfitSpaceSuitBoots; import mineplex.core.gadget.gadgets.outfit.spacesuit.OutfitSpaceSuitChestplate; import mineplex.core.gadget.gadgets.outfit.spacesuit.OutfitSpaceSuitHelmet; import mineplex.core.gadget.gadgets.outfit.spacesuit.OutfitSpaceSuitLeggings; +import mineplex.core.gadget.gadgets.particle.ParticleFairy; +import mineplex.core.gadget.gadgets.particle.ParticleFireRings; +import mineplex.core.gadget.gadgets.particle.ParticleWingsAngel; +import mineplex.core.gadget.gadgets.particle.ParticleWingsDemons; +import mineplex.core.gadget.gadgets.particle.ParticleWingsInfernal; +import mineplex.core.gadget.gadgets.particle.ParticleWingsPixie; +import mineplex.core.gadget.gadgets.particle.ParticleYinYang; +import mineplex.core.gadget.gadgets.particle.candycane.ParticleCandyCane; +import mineplex.core.gadget.gadgets.particle.cupidslove.ParticleHeart; +import mineplex.core.gadget.gadgets.particle.emerald.ParticleEmerald; +import mineplex.core.gadget.gadgets.particle.freedom.ParticleFreedom; +import mineplex.core.gadget.gadgets.particle.frostlord.ParticleFrostLord; +import mineplex.core.gadget.gadgets.particle.howlingwinds.ParticleRain; +import mineplex.core.gadget.gadgets.particle.music.ParticleMusic; +import mineplex.core.gadget.gadgets.particle.party.ParticlePartyTime; +import mineplex.core.gadget.gadgets.particle.shadow.ParticleFoot; +import mineplex.core.gadget.gadgets.particle.vampire.ParticleBlood; +import mineplex.core.gadget.gadgets.particle.wisdom.ParticleEnchant; import mineplex.core.gadget.gadgets.wineffect.WinEffectBabyChicken; import mineplex.core.gadget.gadgets.wineffect.WinEffectLavaTrap; import mineplex.core.gadget.gadgets.wineffect.WinEffectLightningStrike; @@ -93,6 +102,13 @@ import mineplex.core.gadget.types.HatGadget; import mineplex.core.gadget.types.ItemGadget; import mineplex.core.inventory.InventoryManager; import mineplex.core.mount.Mount; +import mineplex.core.mount.types.MountBabyReindeer; +import mineplex.core.mount.types.MountCart; +import mineplex.core.mount.types.MountFreedomHorse; +import mineplex.core.mount.types.MountFrost; +import mineplex.core.mount.types.MountMule; +import mineplex.core.mount.types.MountSlime; +import mineplex.core.mount.types.MountUndead; import mineplex.core.pet.Pet; import mineplex.core.pet.PetManager; import mineplex.core.reward.RewardPool.Type; @@ -105,6 +121,10 @@ import mineplex.core.reward.rewards.TreasureShardReward; import mineplex.core.reward.rewards.UnknownPackageReward; import mineplex.core.stats.StatsManager; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + public class RewardManager { private EnumMap _rewardPools; @@ -553,8 +573,7 @@ public class RewardManager { RewardRarity rarity = RewardRarity.COMMON; - addReward(Type.CARL_SPINNER, new GemReward(_donationManager, getAmmoMin(rarity), getAmmoMax(rarity), 25, 0, rarity)); - addReward(Type.CARL_SPINNER, new ExperienceReward(_statsManager, getAmmoMin(rarity)*5, getAmmoMax(rarity)*5, 25, 0, rarity)); + addReward(Type.CARL_SPINNER, new TreasureShardReward(_clientManager, _donationManager, getAmmoMin(rarity), getAmmoMax(rarity), 25, rarity)); //Normal Gadgets addInventoryReward(Type.NORMAL, getGadget(ItemBatGun.class), rarity, 10, getShards(rarity), 4, 10); @@ -580,8 +599,7 @@ public class RewardManager { RewardRarity rarity = RewardRarity.UNCOMMON; - addReward(Type.CARL_SPINNER, new GemReward(_donationManager, getAmmoMin(rarity), getAmmoMax(rarity), 1200, 0, rarity)); - addReward(Type.CARL_SPINNER, new ExperienceReward(_statsManager, getAmmoMin(rarity)*5, getAmmoMax(rarity)*5, 1200, 0, rarity)); + addReward(Type.CARL_SPINNER, new TreasureShardReward(_clientManager, _donationManager, getAmmoMin(rarity), getAmmoMax(rarity), 1200, rarity)); //Gadgets addInventoryReward(Type.NORMAL, getGadget(ItemBatGun.class), rarity, 250, 0, 20, 40); @@ -631,8 +649,7 @@ public class RewardManager { RewardRarity rarity = RewardRarity.RARE; - addReward(Type.CARL_SPINNER, new GemReward(_donationManager, getAmmoMin(rarity), getAmmoMax(rarity), 150, 0, rarity)); - addReward(Type.CARL_SPINNER, new ExperienceReward(_statsManager, getAmmoMin(rarity)*5, getAmmoMax(rarity)*5, 150, 0, rarity)); + addReward(Type.CARL_SPINNER, new TreasureShardReward(_clientManager, _donationManager, getAmmoMin(rarity), getAmmoMax(rarity), 150, rarity)); //Morphs addGadget(Type.NORMAL, getGadget(MorphVillager.class), rarity, 83); @@ -726,8 +743,7 @@ public class RewardManager { RewardRarity rarity = RewardRarity.LEGENDARY; - addReward(Type.CARL_SPINNER, new GemReward(_donationManager, getAmmoMin(rarity), getAmmoMax(rarity), 10, 0, rarity)); - addReward(Type.CARL_SPINNER, new ExperienceReward(_statsManager, getAmmoMin(rarity)*5, getAmmoMax(rarity)*5, 10, 0, rarity)); + addReward(Type.CARL_SPINNER, new TreasureShardReward(_clientManager, _donationManager, getAmmoMin(rarity), getAmmoMax(rarity), 10, rarity)); //REGULAR diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardPool.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardPool.java index 05ecc8971..c52d63dce 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardPool.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardPool.java @@ -4,10 +4,11 @@ import java.util.ArrayList; import java.util.EnumMap; import java.util.List; -import org.bukkit.entity.Player; - +import mineplex.core.reward.rewards.GemReward; import mineplex.core.reward.rewards.InventoryReward; +import org.bukkit.entity.Player; + /** * Used to separate different "Reward Pools". This allows us to have treasure chests with different loot. * @@ -75,6 +76,13 @@ public class RewardPool return false; } } + if (this == Type.CARL_SPINNER) + { + if (reward instanceof GemReward) + { + return false; + } + } return true; } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java index a92a99b2e..3e0ac74e7 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java @@ -924,6 +924,11 @@ public class ServerManager extends MiniDbClientPlugin implement return _serverNpcShopMap.get("Weekend Brawl"); } + public ShopBase getBawkShop() + { + return _serverNpcShopMap.get("Bawk Bawk Battles"); + } + @Override public String getQuery(int accountId, String uuid, String name) { diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerGameMenu.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerGameMenu.java index 517720f53..a176467a8 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerGameMenu.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerGameMenu.java @@ -41,25 +41,32 @@ public class ServerGameMenu extends ShopPageBase @Override protected void buildPage() { - add(2, Material.QUARTZ_BLOCK, C.cYellowB + "Speed Builders " + C.cGray + "Competitive Building", new String[] + add(1, Material.EGG, C.cYellowB + "Bawk Bawk Battles " + C.cGray + "Challenges", new String[] { (_extraValue ? C.cAquaB : C.cWhiteB) + "NEW GAME", + C.Reset + "", + C.Reset + "Follow Bawk Bawk's instructions", + C.Reset + "Complete different tasks", + C.Reset + "If you lose, chickens will devour you!" + }, "BBB", "Bawk_Bawk_Battles", new SelectBawkButton(this)); + + add(3, Material.QUARTZ_BLOCK, C.cYellowB + "Speed Builders " + C.cGray + "Competitive Building", new String[] + { C.Reset + "", C.Reset + "Memorize Gwen the Guardian's builds", C.Reset + "Then recreate them in a short amount of time.", C.Reset + "The least correct builder is eliminated.", }, "SB", "Speed_Builders", new SelectSBButton(this)); - add(4, Material.BOOK_AND_QUILL, C.cYellowB + "Draw My Thing " + C.cGray + "Pictionary", new String[] + add(5, Material.BOOK_AND_QUILL, C.cYellowB + "Draw My Thing " + C.cGray + "Pictionary", new String[] { - (_extraValue ? C.cAquaB : C.cWhiteB) + "NEW UPDATE", C.Reset + "", C.Reset + "Players take turns at drawing a random", C.Reset + "word. Whoever guesses it within the time", C.Reset + "limit gets some points!", }, "DMT", "Draw_My_Thing", new SelectDMTButton(this)); - add(6, Material.TNT, C.cYellowB + "Dragon Escape " + C.cGray + "Fast Paced Parkour", new String[] + add(7, Material.TNT, C.cYellowB + "Dragon Escape " + C.cGray + "Fast Paced Parkour", new String[] { (_extraValue ? C.cAquaB : C.cWhiteB) + "FEATURED ARCADE GAME", C.Reset + "", @@ -192,7 +199,6 @@ public class ServerGameMenu extends ShopPageBase add(41, Material.BREWING_STAND_ITEM, C.cYellowB + "Monster Maze " + C.cGray + "Snow Sprint", new String[] { - (_extraValue ? C.cAquaB : C.cWhiteB) + "BETA GAME", C.Reset + "", C.Reset + "Run along a maze avoiding", C.Reset + "evil monsters. Get to the", @@ -220,7 +226,7 @@ public class ServerGameMenu extends ShopPageBase { // append to start of lore builder.getLore().add(0, C.cWhite + "Amplified by " + C.cGreen + booster.getPlayerName() + C.cWhite + " - " + C.cGreen + booster.getTimeRemainingString()); - builder.getLore().add(1, C.cWhite + "All players earn " + C.cGreen + "2x Gems" + C.cWhite + " and " + C.cAqua + "2x Shards"); + builder.getLore().add(1, C.cWhite + "All players earn "+ C.cAqua + "2x Shards"); builder.setGlow(true); } } @@ -570,6 +576,11 @@ public class ServerGameMenu extends ShopPageBase { getPlugin().getValentinesShop().attemptShopOpen(player); } + + public void openBawk(Player player) + { + getPlugin().getBawkShop().attemptShopOpen(player); + } /* ADDITIONAL LORES; diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/button/SelectBawkButton.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/button/SelectBawkButton.java new file mode 100644 index 000000000..8e9edf8c0 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/button/SelectBawkButton.java @@ -0,0 +1,23 @@ +package mineplex.hub.server.ui.button; + +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; + +import mineplex.core.shop.item.IButton; +import mineplex.hub.server.ui.ServerGameMenu; + +public class SelectBawkButton implements IButton +{ + private ServerGameMenu _menu; + + public SelectBawkButton(ServerGameMenu menu) + { + _menu = menu; + } + + @Override + public void onClick(Player player, ClickType clickType) + { + _menu.openBawk(player); + } +} diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/data/ServerGroup.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/data/ServerGroup.java index 7e40bed4c..ba3295037 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/data/ServerGroup.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/data/ServerGroup.java @@ -24,6 +24,8 @@ public class ServerGroup private int _requiredTotalServers; private int _requiredJoinableServers; + private String _uptimes = ""; + private boolean _arcadeGroup; private String _worldZip; private String _plugin; @@ -78,6 +80,7 @@ public class ServerGroup _requiredTotalServers = Integer.valueOf(data.get("totalServers")); _requiredJoinableServers = Integer.valueOf(data.get("joinableServers")); _portSection = Integer.valueOf(data.get("portSection")); + _uptimes = data.containsKey("uptimes") ? data.get("uptimes") : ""; _arcadeGroup = Boolean.valueOf(data.get("arcadeGroup")); _worldZip = data.get("worldZip"); _plugin = data.get("plugin"); @@ -120,7 +123,7 @@ public class ServerGroup parseServers(serverStatuses); } - public ServerGroup(String name, String prefix, String host, int ram, int cpu, int totalServers, int joinable, int portSection, boolean arcade, String worldZip, String plugin, String configPath + public ServerGroup(String name, String prefix, String host, int ram, int cpu, int totalServers, int joinable, int portSection, String uptimes, boolean arcade, String worldZip, String plugin, String configPath , int minPlayers, int maxPlayers, boolean pvp, boolean tournament, boolean tournamentPoints, String games, String modes, String boosterGroup, String serverType, boolean noCheat, boolean worldEdit, boolean teamRejoin , boolean teamAutoJoin, boolean teamForceBalance, boolean gameAutoStart, boolean gameTimeout, boolean rewardGems, boolean rewardItems, boolean rewardStats , boolean rewardAchievements, boolean hotbarInventory, boolean hotbarHubClock, boolean playerKickIdle, boolean staffOnly, boolean whitelist, String resourcePack, Region region @@ -134,6 +137,7 @@ public class ServerGroup _requiredTotalServers = totalServers; _requiredJoinableServers = joinable; _portSection = portSection; + _uptimes = uptimes; _arcadeGroup = arcade; _worldZip = worldZip; _plugin = plugin; @@ -232,6 +236,7 @@ public class ServerGroup public String getServerNpcName() { return _npcName; } public String getPortalBottomCornerLocation() { return _portalBottomCornerLocation; } public String getPortalTopCornerLocation() { return _portalTopCornerLocation; } + public String getUptimes() { return _uptimes; } public Set getServers() { return _servers; } @@ -358,6 +363,7 @@ public class ServerGroup _dataMap.put("totalServers", _requiredTotalServers + ""); _dataMap.put("joinableServers", _requiredJoinableServers + ""); _dataMap.put("portSection", _portSection + ""); + _dataMap.put("uptimes", _uptimes); _dataMap.put("arcadeGroup", _arcadeGroup + ""); _dataMap.put("worldZip", _worldZip); _dataMap.put("plugin", _plugin); @@ -368,6 +374,7 @@ public class ServerGroup _dataMap.put("tournament", _tournament + ""); _dataMap.put("tournamentPoints", _tournamentPoints + ""); _dataMap.put("games", _games); + _dataMap.put("modes", _modes); _dataMap.put("serverType", _serverType); _dataMap.put("addNoCheat", _addNoCheat + ""); _dataMap.put("teamRejoin", _teamRejoin + ""); diff --git a/Plugins/Mineplex.Votifier/src/mineplex/votifier/VotifierManager.java b/Plugins/Mineplex.Votifier/src/mineplex/votifier/VotifierManager.java index de1e9e7c7..5e9393d2a 100644 --- a/Plugins/Mineplex.Votifier/src/mineplex/votifier/VotifierManager.java +++ b/Plugins/Mineplex.Votifier/src/mineplex/votifier/VotifierManager.java @@ -3,37 +3,38 @@ package mineplex.votifier; import java.sql.Date; import java.util.UUID; -import org.bukkit.event.EventHandler; -import org.bukkit.plugin.java.JavaPlugin; - -import com.vexsoftware.votifier.model.Vote; -import com.vexsoftware.votifier.model.VotifierEvent; import mineplex.core.MiniPlugin; import mineplex.core.account.CoreClientManager; import mineplex.core.bonuses.BonusAmount; import mineplex.core.bonuses.BonusManager; +import mineplex.core.bonuses.redis.VotifierCommand; import mineplex.core.common.Pair; import mineplex.core.common.util.Callback; import mineplex.core.common.util.UUIDFetcher; -import mineplex.serverdata.database.DBPool; import mineplex.core.donation.DonationManager; -import mineplex.core.bonuses.redis.VotifierCommand; import mineplex.database.Tables; import mineplex.database.tables.records.BonusRecord; import mineplex.serverdata.Region; import mineplex.serverdata.Utility; import mineplex.serverdata.commands.ServerCommand; import mineplex.serverdata.data.PlayerStatus; +import mineplex.serverdata.database.DBPool; import mineplex.serverdata.redis.RedisConfig; import mineplex.serverdata.redis.RedisDataRepository; import mineplex.serverdata.servers.ServerManager; + +import org.bukkit.event.EventHandler; +import org.bukkit.plugin.java.JavaPlugin; import org.jooq.DSLContext; import org.jooq.Record1; import org.jooq.SQLDialect; import org.jooq.impl.DSL; + import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; -import redis.clients.jedis.exceptions.JedisConnectionException; + +import com.vexsoftware.votifier.model.Vote; +import com.vexsoftware.votifier.model.VotifierEvent; /** * Created by shaun on 15-08-05. @@ -106,7 +107,7 @@ public class VotifierManager extends MiniPlugin awardBonus(playerName, finalUuid, new Callback() { @Override - public void run(final Integer gems) + public void run(final Integer shards) { runSync(new Runnable() { @@ -116,13 +117,13 @@ public class VotifierManager extends MiniPlugin if (usStatus != null) { System.out.println("Found " + playerName + " on US " + usStatus.getServer()); - notifyServer(playerName, gems, Region.US, usStatus.getServer()); + notifyServer(playerName, shards, Region.US, usStatus.getServer()); } if (euStatus != null) { System.out.println("Found " + playerName + " on EU " + euStatus.getServer()); - notifyServer(playerName, gems, Region.EU, euStatus.getServer()); + notifyServer(playerName, shards, Region.EU, euStatus.getServer()); } } }); @@ -168,11 +169,11 @@ public class VotifierManager extends MiniPlugin // notifyServer(playerName, true); } - private void notifyServer(String playerName, int gems, Region region, String targetServer) + private void notifyServer(String playerName, int shards, Region region, String targetServer) { JedisPool writePool = region == Region.EU ? _euWritePool : _usWritePool; - VotifierCommand command = new VotifierCommand(playerName, gems, targetServer); + VotifierCommand command = new VotifierCommand(playerName, shards, targetServer); publishCommand(command, writePool); } @@ -222,9 +223,9 @@ public class VotifierManager extends MiniPlugin public void run(Boolean data) { if (data) - System.out.println("Gave " + amount.getGems() + " coins to " + playerName); + System.out.println("Gave " + amount.getCoins() + " coins to " + playerName); else - System.out.println("Failed to give " + amount.getGems() + " coins to " + playerName); + System.out.println("Failed to give " + amount.getCoins() + " coins to " + playerName); } }, "Votifier", playerName, accountId, amount.getTotalCoins()); } @@ -238,7 +239,7 @@ public class VotifierManager extends MiniPlugin client.store(); System.out.println("Awarded carl ticket to " + playerName); - onComplete.run(amount.getTotalGems()); + onComplete.run(amount.getTotalCoins()); } else { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java index e40f97219..6805583b7 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java @@ -222,6 +222,7 @@ public class Arcade extends JavaPlugin config.ServerType = _serverConfiguration.getServerGroup().getServerType(); config.MinPlayers = _serverConfiguration.getServerGroup().getMinPlayers(); config.MaxPlayers = _serverConfiguration.getServerGroup().getMaxPlayers(); + config.Uptimes = _serverConfiguration.getServerGroup().getUptimes(); config.Tournament = _serverConfiguration.getServerGroup().getTournament(); config.TournamentPoints = _serverConfiguration.getServerGroup().getTournamentPoints(); config.TeamRejoin = _serverConfiguration.getServerGroup().getTeamRejoin(); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java index 75aea7dfa..c47833359 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java @@ -173,7 +173,8 @@ public class ArcadeManager extends MiniPlugin implements IRelation private ProgressingKitManager _progressionKitManager; private BoosterManager _boosterManager; private GameSpectatorManager _spectatorManager; - + private ServerUptimeManager _serverUptimeManager; + private IncognitoManager _incognitoManager; private TaskManager _taskManager; @@ -331,7 +332,8 @@ public class ArcadeManager extends MiniPlugin implements IRelation _kitProgressionManager = new KitProgressionManager(getPlugin(), clientManager); _progressionKitManager = new ProgressingKitManager(this); - + _serverUptimeManager = new ServerUptimeManager(this); + if (GetHost() != null && !GetHost().isEmpty()) { Bukkit.getScheduler().runTaskLater(plugin, () -> Portal.transferPlayer(GetHost(), _serverStatusManager.getCurrentServerName()), 80L); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameMode.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameMode.java index bfc40cc26..468447539 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameMode.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameMode.java @@ -1,5 +1,7 @@ package nautilus.game.arcade; +import mineplex.core.common.MinecraftVersion; +import mineplex.core.common.Pair; import nautilus.game.arcade.game.Game; /** @@ -14,16 +16,34 @@ public class GameMode private GameType _gameType; private String _name; + private Pair[] _resourcePackUrls; + private boolean _enforceResourcePack; + /** * * @param gameMode Game class that in most cases extends the host game class * @param name Gamemode name */ public GameMode(Class gameMode, GameType gameType, String name) + { + this(gameMode, gameType, name, null, false); + } + + /** + * + * @param gameMode Game class that in most cases extends the host game class + * @param gameType original GameType of modded game + * @param name Gamemode name + * @param resourcePackUrls URLs to 1.8/1.9 resource pack + * @param enforceResourcePack enforece resource pack on players + */ + public GameMode(Class gameMode, GameType gameType, String name, Pair[] resourcePackUrls, boolean enforceResourcePack) { _gameMode = gameMode; _gameType = gameType; _name = name; + _resourcePackUrls = resourcePackUrls; + _enforceResourcePack = enforceResourcePack; } /** @@ -52,5 +72,23 @@ public class GameMode { return _gameType; } + + /** + * + * @return Gamemode resource pack URLs + */ + public Pair[] getResPackURLs() + { + return _resourcePackUrls; + } + + /** + * + * @return Gamemode enforcing of resource packs + */ + public boolean enforceResourcePack() + { + return _enforceResourcePack; + } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java index 0e44d3a63..5984b025c 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java @@ -1,5 +1,7 @@ package nautilus.game.arcade; +import org.bukkit.Material; + import mineplex.core.common.MinecraftVersion; import mineplex.core.common.Pair; import mineplex.core.game.GameCategory; @@ -10,6 +12,7 @@ import nautilus.game.arcade.game.games.barbarians.Barbarians; import nautilus.game.arcade.game.games.bossbattles.BossBattles; import nautilus.game.arcade.game.games.bouncyballs.BouncyBalls; import nautilus.game.arcade.game.games.bridge.Bridge; +import nautilus.game.arcade.game.games.bridge.modes.LuckyBridges; import nautilus.game.arcade.game.games.bridge.modes.OverpoweredBridge; import nautilus.game.arcade.game.games.bridge.modes.SpeedBridges ; import nautilus.game.arcade.game.games.build.Build; @@ -20,6 +23,7 @@ import nautilus.game.arcade.game.games.castlesiege.CastleSiege; import nautilus.game.arcade.game.games.champions.ChampionsCTF; import nautilus.game.arcade.game.games.champions.ChampionsDominate; import nautilus.game.arcade.game.games.champions.ChampionsTDM; +import nautilus.game.arcade.game.games.champions.modes.SmashDom; import nautilus.game.arcade.game.games.christmas.Christmas; import nautilus.game.arcade.game.games.deathtag.DeathTag; import nautilus.game.arcade.game.games.dragonescape.DragonEscape; @@ -33,6 +37,7 @@ import nautilus.game.arcade.game.games.evolution.Evolution; import nautilus.game.arcade.game.games.gladiators.Gladiators; import nautilus.game.arcade.game.games.gladiators.modes.ChampionsGladiators; import nautilus.game.arcade.game.games.gladiators.modes.OverpoweredGladiators; +import nautilus.game.arcade.game.games.gladiators.modes.SmashGladiators; import nautilus.game.arcade.game.games.gravity.Gravity; import nautilus.game.arcade.game.games.halloween.Halloween; import nautilus.game.arcade.game.games.hideseek.HideSeek; @@ -41,11 +46,14 @@ import nautilus.game.arcade.game.games.holeinwall.HoleInTheWall; import nautilus.game.arcade.game.games.horsecharge.Horse; import nautilus.game.arcade.game.games.lobbers.BombLobbers; import nautilus.game.arcade.game.games.micro.Micro; +import nautilus.game.arcade.game.games.micro.modes.CookieFight; +import nautilus.game.arcade.game.games.micro.modes.OverpoweredMicroBattles; +import nautilus.game.arcade.game.games.micro.modes.TinySmash; 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.minestrike.Minestrike; +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; @@ -59,9 +67,12 @@ import nautilus.game.arcade.game.games.runner.modes.FasterThanLight; import nautilus.game.arcade.game.games.searchanddestroy.SearchAndDestroy; import nautilus.game.arcade.game.games.sheep.SheepGame; import nautilus.game.arcade.game.games.sheep.modes.EweHeroes; +import nautilus.game.arcade.game.games.sheep.modes.OverpoweredSheepQuest; +import nautilus.game.arcade.game.games.sheep.modes.SmashSheep; import nautilus.game.arcade.game.games.skywars.SoloSkywars; import nautilus.game.arcade.game.games.skywars.TeamSkywars; import nautilus.game.arcade.game.games.skywars.modes.OverpoweredSkywars; +import nautilus.game.arcade.game.games.skywars.modes.SkySmash; import nautilus.game.arcade.game.games.skywars.modes.UHCSkywars; import nautilus.game.arcade.game.games.smash.SoloSuperSmash; import nautilus.game.arcade.game.games.smash.SuperSmashDominate; @@ -78,7 +89,9 @@ import nautilus.game.arcade.game.games.squidshooter.SquidShooter; import nautilus.game.arcade.game.games.stacker.Stacker; import nautilus.game.arcade.game.games.survivalgames.SoloSurvivalGames; import nautilus.game.arcade.game.games.survivalgames.TeamSurvivalGames; +import nautilus.game.arcade.game.games.survivalgames.modes.ChangingKits; import nautilus.game.arcade.game.games.survivalgames.modes.OverpoweredSurvival; +import nautilus.game.arcade.game.games.survivalgames.modes.StrikeGames; import nautilus.game.arcade.game.games.survivalgames.modes.UHCSurvivalgames; import nautilus.game.arcade.game.games.tug.Tug; import nautilus.game.arcade.game.games.turfforts.TurfForts; @@ -92,7 +105,6 @@ import nautilus.game.arcade.game.games.valentines.Valentines; import nautilus.game.arcade.game.games.wither.WitherGame; import nautilus.game.arcade.game.games.wizards.Wizards; import nautilus.game.arcade.game.games.zombiesurvival.ZombieSurvival; -import org.bukkit.Material; public enum GameType { @@ -132,12 +144,12 @@ public enum GameType Lobbers(BombLobbers.class, GameDisplay.Lobbers), Micro(Micro.class, GameDisplay.Micro), MilkCow(MilkCow.class, GameDisplay.MilkCow), - MineStrike(MineStrike.class, GameDisplay.MineStrike, new Pair[] + MineStrike(Minestrike.class, GameDisplay.MineStrike, new Pair[] { 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), @@ -187,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, @@ -195,20 +207,42 @@ public enum GameType GameType.WitherAssault, GameType.Wizards, GameType.ZombieSurvival}, true), Brawl(null, new GameMode[]{ - new GameMode(OverpoweredBridge.class, GameType.Bridge, "OP Bridges"), new GameMode(SpeedBridges.class, GameType.Bridge, "Speed Bridges"), - new GameMode(OverpoweredGladiators.class, GameType.Gladiators, "OP Gladiators"), new GameMode(ChampionsGladiators.class, GameType.Gladiators, "Champions Gladiators"), - new GameMode(OverpoweredSkywars.class, GameType.Skywars, "OP Skywars"), new GameMode(UHCSkywars.class, GameType.Skywars, "UHC Skywars"), - new GameMode(TeamBuild.class, GameType.Build, "Team Master Builders"), new GameMode(DukesOfDecoration.class, GameType.Build, "Dukes Of Decoration"), - new GameMode(CutClean.class, GameType.UHC, "Cut Clean"), new GameMode(GodBattles.class, GameType.UHC, "God Battles"), - new GameMode(BloodDiamonds.class, GameType.UHC, "Blood Diamonds"), new GameMode(Assassins.class, GameType.UHC, "Assassins"), - new GameMode(OverpoweredSurvival.class, GameType.SurvivalGames, "OP Survival Games"), new GameMode(UHCSurvivalgames.class, GameType.SurvivalGames, "UHC Survivalgames"), - new GameMode(UltraSpleef.class, GameType.Spleef, "Ultra Spleef"), - new GameMode(RandomKitSSM.class, GameType.Smash, "Random Kit SSM"), - new GameMode(EweHeroes.class, GameType.Sheep, "Heroes Of The Ewe"), - new GameMode(FasterThanLight.class, GameType.Runner, "Faster Than Light"), - new GameMode(BunnyHop.class, GameType.Quiver, "Bunny Hop"), + new GameMode(OverpoweredBridge.class, GameType.Bridge, "OP Bridges"), + new GameMode(SpeedBridges.class, GameType.Bridge, "Speed Bridges"), + new GameMode(LuckyBridges.class, GameType.Bridge, "Lucky Bridges"), + new GameMode(OverpoweredGladiators.class, GameType.Gladiators, "OP Gladiators"), + new GameMode(ChampionsGladiators.class, GameType.Gladiators, "Champions Gladiators"), + new GameMode(SmashGladiators.class, GameType.Gladiators, "Smash Gladiators"), + new GameMode(OverpoweredSkywars.class, GameType.Skywars, "OP Skywars"), + new GameMode(UHCSkywars.class, GameType.Skywars, "UHC Skywars"), + new GameMode(SkySmash.class, GameType.Skywars, "Sky Smash"), + new GameMode(TeamBuild.class, GameType.Build, "Team Master Builders"), + new GameMode(DukesOfDecoration.class, GameType.Build, "Dukes Of Decoration"), + new GameMode(CutClean.class, GameType.UHC, "Cut Clean"), + new GameMode(GodBattles.class, GameType.UHC, "God Battles"), + new GameMode(BloodDiamonds.class, GameType.UHC, "Blood Diamonds"), + new GameMode(Assassins.class, GameType.UHC, "Assassins"), + new GameMode(OverpoweredSurvival.class, GameType.SurvivalGames, "OP Survival Games"), + new GameMode(UHCSurvivalgames.class, GameType.SurvivalGames, "UHC Survivalgames"), + new GameMode(ChangingKits.class, GameType.SurvivalGames, "Changing Kits"), + new GameMode(StrikeGames.class, GameType.SurvivalGames, "Strike Games", new Pair[] + { + Pair.create(MinecraftVersion.Version1_8, "http://file.mineplex.com/ResStrikeGames18.zip"), + Pair.create(MinecraftVersion.Version1_9, "http://file.mineplex.com/ResStrikeGames19.zip") + }, true), new GameMode(TinyWinners.class, GameType.Micro, "Tiny Winners"), - new GameMode(Countdown.class, GameType.HideSeek, "Countdown"), + new GameMode(OverpoweredMicroBattles.class, GameType.Micro, "OP Micro Battles"), + new GameMode(CookieFight.class, GameType.Micro, "Cookie Fight"), + new GameMode(TinySmash.class, GameType.Micro, "Tiny Smash"), + new GameMode(UltraSpleef.class, GameType.Spleef, "Ultra Spleef"), + new GameMode(RandomKitSSM.class, GameType.Smash, "Random Kit SSM"), + new GameMode(EweHeroes.class, GameType.Sheep, "Heroes Of The Ewe"), + new GameMode(SmashSheep.class, GameType.Sheep, "Smash Sheep"), + new GameMode(OverpoweredSheepQuest.class, GameType.Sheep, "OP Sheep Quest"), + new GameMode(FasterThanLight.class, GameType.Runner, "Faster Than Light"), + new GameMode(BunnyHop.class, GameType.Quiver, "Bunny Hop"), + new GameMode(Countdown.class, GameType.HideSeek, "Countdown"), + new GameMode(SmashDom.class, GameType.ChampionsDominate, "Smash Dominate"), }, GameDisplay.Brawl, null, false, null, false, true); GameDisplay _display; @@ -277,13 +311,21 @@ public enum GameType return _gameModes; } - public boolean isEnforceResourcePack() + public boolean isEnforceResourcePack(Game game) { + if (hasGamemodes()) + { + return getGameMode(game.getClass()).enforceResourcePack(); + } return _enforceResourcePack; } - public Pair[] getResourcePackUrls() + public Pair[] getResourcePackUrls(Game game) { + if (hasGamemodes()) + { + return getGameMode(game.getClass()).getResPackURLs(); + } return _resourcePacks; } @@ -331,18 +373,28 @@ public enum GameType return _display.getKitGameName(); } - public GameType getModeGameType(Class game) + public boolean isUsingGameModes() + { + return _gameMaps; + } + + public GameMode getGameMode(Class game) { for (GameMode mode : getGameModes()) { if (mode.getGameClass() != null && mode.getGameClass().getName().contentEquals(game.getName())) { - return mode.getType(); + return mode; } } return null; } + public GameType getModeGameType(Class game) + { + return getGameMode(game).getType(); + } + public boolean isUsingGameModesMaps() { return _gameMaps; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/addons/compass/CompassAddon.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/addons/compass/CompassAddon.java index 732df5661..eb003303f 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/addons/compass/CompassAddon.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/addons/compass/CompassAddon.java @@ -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) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/booster/GameBoosterManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/booster/GameBoosterManager.java index 5fe291f44..764fc09ef 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/booster/GameBoosterManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/booster/GameBoosterManager.java @@ -55,7 +55,7 @@ public class GameBoosterManager extends MiniPlugin if (active == null) { - UtilPlayer.message(player, F.main("Thanks", "There is no active booster to Thank!")); + UtilPlayer.message(player, F.main("Thanks", "There is no active amplifier to Thank!")); return; } @@ -81,10 +81,10 @@ public class GameBoosterManager extends MiniPlugin Booster booster = event.getBooster(); if (event.getBoosterGroup().equals(_boosterGroup)) { - Bukkit.broadcastMessage(F.main("Amplifier", F.name(booster.getPlayerName()) + " has activated an Amplifier for " + booster.getMultiplier() + "x Gems and Shards!")); + Bukkit.broadcastMessage(F.main("Amplifier", F.name(booster.getPlayerName()) + " has activated a Game Amplifier for " + booster.getMultiplier() + "x Shards!")); } else { - Bukkit.broadcastMessage(F.main("Amplifier", F.name(booster.getPlayerName()) + " has activated an Amplifier on " + F.elem(event.getBoosterGroup().replaceAll("_", " ")) + "!")); + Bukkit.broadcastMessage(F.main("Amplifier", F.name(booster.getPlayerName()) + " has activated a Game Amplifier on " + F.elem(event.getBoosterGroup().replaceAll("_", " ")) + "!")); } } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java index 6926eb565..76a31e27e 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java @@ -201,10 +201,12 @@ public abstract class Game implements Listener public boolean WorldLeavesDecay = false; public boolean WorldSoilTrample = false; public boolean WorldBoneMeal = false; + public boolean WorldChunkUnload = false; public int HungerSet = -1; public int HealthSet = -1; + public boolean SpawnTeleport = true; public boolean PrepareFreeze = true; private double _itemMergeRadius = 0; @@ -239,6 +241,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; @@ -325,7 +328,6 @@ public abstract class Game implements Listener private NautHashMap _deadBodies = new NautHashMap(); private NautHashMap _deadBodiesExpire = new NautHashMap(); - public ArrayList GemBoosters = new ArrayList(); private final Set> _statTrackers = new HashSet<>(); private NautHashMap _teamReqs = new NautHashMap(); @@ -396,7 +398,7 @@ public abstract class Game implements Listener new ExperienceStatTracker(this), new WinStatTracker(this), new LoseStatTracker(this), new DamageDealtStatTracker( this), new DamageTakenStatTracker(this), new GamesPlayedStatTracker(this)); - Manager.getResourcePackManager().setResourcePack(gameType.getResourcePackUrls(), gameType.isEnforceResourcePack()); + Manager.getResourcePackManager().setResourcePack(gameType.getResourcePackUrls(this), gameType.isEnforceResourcePack(this)); _useEntityPacketHandler = new IPacketHandler() { @@ -419,13 +421,14 @@ public abstract class Game implements Listener System.out.println("Loading " + GetName() + "..."); } - public void registerModule(Module module) + public T registerModule(T module) { if (!_modules.containsKey(module.getClass())) { - module.initialize(this); _modules.put(module.getClass(), module); UtilServer.RegisterEvents(module); + module.initialize(this); + return module; } else { @@ -433,6 +436,16 @@ public abstract class Game implements Listener } } + public void unregisterModule(Module module) + { + if (_modules.containsKey(module.getClass()) && _modules.get(module.getClass()) == module) + { + _modules.remove(module.getClass()); + module.cleanup(); + HandlerList.unregisterAll(module); + } + } + public void setKits(Kit[] kits) { _kits = kits; @@ -865,6 +878,11 @@ public abstract class Game implements Listener } public void SetKit(Player player, Kit kit, boolean announce) + { + SetKit(player, kit, announce, true); + } + + public void SetKit(Player player, Kit kit, boolean announce, boolean apply) { GameTeam team = GetTeam(player); if (team != null) @@ -895,7 +913,7 @@ public abstract class Game implements Listener UtilPlayer.message(player, F.main("Kit", "You equipped " + F.elem(kit.GetFormattedName() + " Kit") + ".")); } - if (InProgress()) + if (InProgress() && apply) { kit.ApplyKit(player); } @@ -1458,46 +1476,6 @@ public abstract class Game implements Listener SetState(GameState.End); } - public void AddGemBooster(Player player) - { - if (!GemBoosterEnabled) - { - UtilPlayer.message(player, F.main("Game", "You cannot use " + F.elem("Gem Boosters")) + " for this game."); - return; - } - - if (GemBoosters.size() >= 4) - { - UtilPlayer.message(player, F.main("Game", "Games cannot have more than " + F.elem("4 Gem Boosters")) + "."); - return; - } - - if (GemBoosters.contains(player.getName())) - { - UtilPlayer.message(player, F.main("Game", "You can only use " + F.elem("1 Gem Booster")) + " per game."); - return; - } - - Announce(F.elem(player.getName()) + " used a " + F.elem(C.cGreen + "Gem Booster") + " for " - + F.elem("+" + (100 - (GemBoosters.size() * 25)) + "% Gems") + "!"); - - GemBoosters.add(player.getName()); - } - - public double GetGemBoostAmount() - { - if (GemBoosters.size() == 1) - return 1; - if (GemBoosters.size() == 2) - return 1.75; - if (GemBoosters.size() == 3) - return 2.25; - if (GemBoosters.size() == 4) - return 2.5; - - return 0; - } - public void AddStat(Player player, String stat, int amount, boolean limitTo1, boolean global) { if (!Manager.IsRewardStats()) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/GameServerConfig.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/GameServerConfig.java index f2b60267d..617588f8f 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/GameServerConfig.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/GameServerConfig.java @@ -12,6 +12,9 @@ public class GameServerConfig public String BoosterGroup = null; public int MinPlayers = -1; public int MaxPlayers = -1; + + public String Uptimes; + public ArrayList GameList = new ArrayList(); public ArrayList GameModeList = new ArrayList(); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/GameTeam.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/GameTeam.java index 701dfe0cf..d6302e4b1 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/GameTeam.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/GameTeam.java @@ -115,7 +115,7 @@ public class GameTeam return _spawns; } - private Location fixFacing(Location loc) + public Location fixFacing(Location loc) { if (Host.FixSpawnFacing) { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/TeamGame.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/TeamGame.java index 48ae4e9de..1f55a9039 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/TeamGame.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/TeamGame.java @@ -1,33 +1,38 @@ package nautilus.game.arcade.game; -import mineplex.core.common.util.*; -import mineplex.core.common.util.UtilTime.*; -import mineplex.core.updater.*; -import mineplex.core.updater.event.*; -import nautilus.game.arcade.*; -import nautilus.game.arcade.events.*; -import nautilus.game.arcade.game.GameTeam.*; -import nautilus.game.arcade.kit.*; -import nautilus.game.arcade.stats.TeamDeathsStatTracker; -import nautilus.game.arcade.stats.TeamKillsStatTracker; +import mineplex.core.common.util.C; +import mineplex.core.common.util.NautHashMap; +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 nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.GameType; +import nautilus.game.arcade.events.PlayerStateChangeEvent; +import nautilus.game.arcade.game.GameTeam.PlayerState; +import nautilus.game.arcade.kit.Kit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerLoginEvent; +import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.Bukkit; -import org.bukkit.entity.*; -import org.bukkit.event.*; -import org.bukkit.event.player.*; - -import java.util.*; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; public abstract class TeamGame extends Game { + public long RejoinTime = 120000; + protected ArrayList _places = new ArrayList(); - private NautHashMap _rejoinTime = new NautHashMap(); - protected NautHashMap RejoinTeam = new NautHashMap(); - protected NautHashMap RejoinKit = new NautHashMap(); - protected NautHashMap RejoinHealth = new NautHashMap(); - - protected long RejoinTime = 120000; + public NautHashMap RejoinTimes = new NautHashMap(); + public NautHashMap RejoinTeam = new NautHashMap(); + public NautHashMap RejoinKit = new NautHashMap(); + public NautHashMap RejoinHealth = new NautHashMap(); public TeamGame(ArcadeManager manager, GameType gameType, Kit[] kits, String[] gameDesc) { @@ -54,7 +59,7 @@ public abstract class TeamGame extends Game return _places; } - @EventHandler(priority = EventPriority.LOWEST) + @EventHandler(priority = EventPriority.LOW) public void PlayerQuit(PlayerQuitEvent event) { if (!InProgress()) @@ -79,7 +84,7 @@ public abstract class TeamGame extends Game if (!QuitOut) { //Store - _rejoinTime.put(player.getName(), System.currentTimeMillis()); + RejoinTimes.put(player.getName(), System.currentTimeMillis()); RejoinTeam.put(player.getName(), team); if (GetKit(player) != null) @@ -102,7 +107,7 @@ public abstract class TeamGame extends Game //Rejoined GameTeam team = RejoinTeam.remove(event.getPlayer().getName()); - if (team != null && _rejoinTime.remove(event.getPlayer().getName()) != null) + if (team != null && RejoinTimes.remove(event.getPlayer().getName()) != null) { team.AddPlayer(event.getPlayer(), true); Announce(team.GetColor() + C.Bold + event.getPlayer().getName() + " has reconnected!", false); @@ -126,8 +131,6 @@ public abstract class TeamGame extends Game // } // } // }, 20); - - return; } } @@ -143,7 +146,21 @@ public abstract class TeamGame extends Game if (RejoinHealth.containsKey(player.getName())) { double health = RejoinHealth.remove(player.getName()); - player.setHealth(health); + if (health > 0) + { + getArcadeManager().runSyncLater(() -> + { + player.setHealth(health); + }, 1L); + } + } + + if (GetLocationStore().containsKey(player.getName())) + { + getArcadeManager().runSyncLater(() -> + { + player.teleport(GetLocationStore().remove(player.getName())); + }, 1L); } } @@ -153,13 +170,13 @@ public abstract class TeamGame extends Game if (event.getType() != UpdateType.SEC || QuitOut) return; - Iterator rejoinIterator = _rejoinTime.keySet().iterator(); + Iterator rejoinIterator = RejoinTimes.keySet().iterator(); while (rejoinIterator.hasNext()) { String name = rejoinIterator.next(); - if (!UtilTime.elapsed(_rejoinTime.get(name), RejoinTime)) + if (!UtilTime.elapsed(RejoinTimes.get(name), RejoinTime)) continue; rejoinIterator.remove(); @@ -187,7 +204,7 @@ public abstract class TeamGame extends Game } else { - _rejoinTime.put(toks[1], System.currentTimeMillis()); + RejoinTimes.put(toks[1], System.currentTimeMillis()); event.getPlayer().sendMessage("Allowed " + toks[1] + " to rejoin!"); } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/modes/LuckyBridges.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/modes/LuckyBridges.java new file mode 100644 index 000000000..fcf06d09e --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/modes/LuckyBridges.java @@ -0,0 +1,74 @@ +package nautilus.game.arcade.game.games.bridge.modes; + +import mineplex.core.common.util.UtilMath; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.GameType; +import nautilus.game.arcade.game.games.AbsorptionFix; +import nautilus.game.arcade.game.games.bridge.Bridge; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.event.EventHandler; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.inventory.ItemStack; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; + +/** + * LuckyBridges gamemode for Bridges + * + * @author xXVevzZXx + */ +public class LuckyBridges extends Bridge +{ + + private HashMap> _drops; + + public LuckyBridges(ArcadeManager manager) + { + super(manager, GameType.Brawl); + + _drops = new HashMap<>(); + + _drops.put(Material.DIAMOND_ORE, Arrays.asList( + Material.DIAMOND_HELMET, Material.DIAMOND_CHESTPLATE, Material.DIAMOND_LEGGINGS, Material.DIAMOND_BOOTS, + Material.DIAMOND_PICKAXE, Material.DIAMOND_AXE, Material.DIAMOND_SWORD)); + + + _drops.put(Material.IRON_ORE, Arrays.asList( + Material.IRON_HELMET, Material.IRON_CHESTPLATE, Material.IRON_LEGGINGS, Material.IRON_BOOTS, + Material.IRON_PICKAXE, Material.IRON_AXE, Material.IRON_SWORD)); + + + _drops.put(Material.GOLD_ORE, Arrays.asList( + Material.GOLD_HELMET, Material.GOLD_CHESTPLATE, Material.GOLD_LEGGINGS, Material.GOLD_BOOTS, + Material.GOLD_PICKAXE, Material.GOLD_AXE, Material.GOLD_SWORD, Material.GOLDEN_APPLE)); + + new AbsorptionFix(this); + } + + @EventHandler + public void mine(BlockBreakEvent event) + { + List blockDrops = _drops.get(event.getBlock().getType()); + if (blockDrops != null) + { + event.setCancelled(true); + event.getBlock().setType(Material.AIR); + + Bukkit.getScheduler().runTask(Manager.getPlugin(), () -> + event.getBlock().getWorld().dropItem( + event.getBlock().getLocation().add(0.5, 0.2, 0.5), + new ItemStack(blockDrops.get(UtilMath.r(blockDrops.size())))) + ); + } + } + + @Override + public String GetMode() + { + return "Lucky Bridges"; + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/modes/OverpoweredBridge.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/modes/OverpoweredBridge.java index 7627cc3ee..7fcf95f0e 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/modes/OverpoweredBridge.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/modes/OverpoweredBridge.java @@ -54,12 +54,6 @@ public class OverpoweredBridge extends Bridge Manager.GetDamage().SetEnabled(false); new AbsorptionFix(this); - } - - @Override - public void ParseData() - { - _starterChests = new HashMap<>(); _starterItems = new HashMap<>(); _starterItems.put(Material.WOOD, 64); @@ -72,6 +66,12 @@ public class OverpoweredBridge extends Bridge _starterItems.put(Material.EXP_BOTTLE, 64); _starterItems.put(Material.COOKED_BEEF, 64); _starterItems.put(Material.DIAMOND, 300); + } + + @Override + public void ParseData() + { + _starterChests = new HashMap<>(); ParseLavaBridge(); ParseWoodBridge(); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/champions/modes/SmashDom.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/champions/modes/SmashDom.java new file mode 100644 index 000000000..f5825a5fe --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/champions/modes/SmashDom.java @@ -0,0 +1,109 @@ +package nautilus.game.arcade.game.games.champions.modes; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; + +import mineplex.minecraft.game.core.damage.CustomDamageEvent; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.GameType; +import nautilus.game.arcade.game.games.common.Domination; +import nautilus.game.arcade.game.games.smash.kits.KitBlaze; +import nautilus.game.arcade.game.games.smash.kits.KitChicken; +import nautilus.game.arcade.game.games.smash.kits.KitCow; +import nautilus.game.arcade.game.games.smash.kits.KitCreeper; +import nautilus.game.arcade.game.games.smash.kits.KitEnderman; +import nautilus.game.arcade.game.games.smash.kits.KitGolem; +import nautilus.game.arcade.game.games.smash.kits.KitMagmaCube; +import nautilus.game.arcade.game.games.smash.kits.KitPig; +import nautilus.game.arcade.game.games.smash.kits.KitSheep; +import nautilus.game.arcade.game.games.smash.kits.KitSkeletalHorse; +import nautilus.game.arcade.game.games.smash.kits.KitSkeleton; +import nautilus.game.arcade.game.games.smash.kits.KitSkySquid; +import nautilus.game.arcade.game.games.smash.kits.KitSlime; +import nautilus.game.arcade.game.games.smash.kits.KitSnowman; +import nautilus.game.arcade.game.games.smash.kits.KitSpider; +import nautilus.game.arcade.game.games.smash.kits.KitWitch; +import nautilus.game.arcade.game.games.smash.kits.KitWitherSkeleton; +import nautilus.game.arcade.game.games.smash.kits.KitWolf; +import nautilus.game.arcade.game.games.smash.kits.KitZombie; +import nautilus.game.arcade.kit.Kit; + +/** + * SmashDom + * + * @author xXVevzZXx + */ +public class SmashDom extends Domination +{ + + public SmashDom(ArcadeManager manager) + { + super(manager, GameType.Brawl, new Kit[] + { + new KitSkeleton(manager), + new KitGolem(manager), + new KitSpider(manager), + new KitSlime(manager), + + new KitCreeper(manager), + new KitEnderman(manager), + new KitSnowman(manager), + new KitWolf(manager), + + + new KitBlaze(manager), + new KitWitch(manager), + new KitChicken(manager), + new KitSkeletalHorse(manager), + new KitPig(manager), + new KitSkySquid(manager), + new KitWitherSkeleton(manager), + new KitMagmaCube(manager), + new KitZombie(manager), + new KitCow(manager), + + new KitSheep(manager) + }); + + + Manager.GetDamage().UseSimpleWeaponDamage = false; + Manager.getCosmeticManager().setHideParticles(true); + + Manager.getClassManager().GetItemFactory().getProximityManager().setProxyLimit(6); + Manager.getClassManager().deregisterSelf(); + + StrictAntiHack = true; + + InventoryOpenChest = true; + + EnableSupply = false; + } + + @EventHandler(priority = EventPriority.LOWEST) + public void noFallDamage(CustomDamageEvent event) + { + if (event.IsCancelled()) + return; + + if (event.GetCause() == DamageCause.FALL) + event.SetCancelled("No Fall Damage"); + } + + @EventHandler(priority = EventPriority.HIGH) + public void customKnockback(CustomDamageEvent event) + { + if (event.IsCancelled()) + return; + + if (event.GetDamageePlayer() != null) + event.AddKnockback("Smash Knockback", 1 + 0.1 * (20 - event.GetDamageePlayer().getHealth())); + } + + @Override + public String GetMode() + { + return "Smash Dominate"; + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/common/Domination.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/common/Domination.java index e1ec075d2..80fa91b70 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/common/Domination.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/common/Domination.java @@ -48,6 +48,10 @@ import nautilus.game.arcade.kit.Kit; public class Domination extends TeamGame { + //Configuration + public boolean EnableEmerald = true; + public boolean EnableSupply = true; + //Map Data private ArrayList _points = new ArrayList(); private ArrayList _emerald = new ArrayList(); @@ -179,10 +183,20 @@ public class Domination extends TeamGame public void PowerupPickup(PlayerPickupItemEvent event) { for (Emerald cur : _emerald) - cur.Pickup(event.getPlayer(), event.getItem()); + { + if (EnableEmerald) + cur.Pickup(event.getPlayer(), event.getItem()); + else + return; + } for (Resupply cur : _resupply) - cur.Pickup(event.getPlayer(), event.getItem()); + { + if (EnableSupply) + cur.Pickup(event.getPlayer(), event.getItem()); + else + return; + } } @EventHandler diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/gladiators/modes/SmashGladiators.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/gladiators/modes/SmashGladiators.java new file mode 100644 index 000000000..fc7be6e29 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/gladiators/modes/SmashGladiators.java @@ -0,0 +1,109 @@ +package nautilus.game.arcade.game.games.gladiators.modes; + +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; + +import mineplex.minecraft.game.core.damage.CustomDamageEvent; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.GameType; +import nautilus.game.arcade.game.games.gladiators.ArenaType; +import nautilus.game.arcade.game.games.gladiators.Gladiators; +import nautilus.game.arcade.game.games.smash.kits.KitBlaze; +import nautilus.game.arcade.game.games.smash.kits.KitChicken; +import nautilus.game.arcade.game.games.smash.kits.KitCow; +import nautilus.game.arcade.game.games.smash.kits.KitCreeper; +import nautilus.game.arcade.game.games.smash.kits.KitEnderman; +import nautilus.game.arcade.game.games.smash.kits.KitGolem; +import nautilus.game.arcade.game.games.smash.kits.KitMagmaCube; +import nautilus.game.arcade.game.games.smash.kits.KitPig; +import nautilus.game.arcade.game.games.smash.kits.KitSheep; +import nautilus.game.arcade.game.games.smash.kits.KitSkeletalHorse; +import nautilus.game.arcade.game.games.smash.kits.KitSkeleton; +import nautilus.game.arcade.game.games.smash.kits.KitSkySquid; +import nautilus.game.arcade.game.games.smash.kits.KitSlime; +import nautilus.game.arcade.game.games.smash.kits.KitSnowman; +import nautilus.game.arcade.game.games.smash.kits.KitSpider; +import nautilus.game.arcade.game.games.smash.kits.KitWitch; +import nautilus.game.arcade.game.games.smash.kits.KitWitherSkeleton; +import nautilus.game.arcade.game.games.smash.kits.KitWolf; +import nautilus.game.arcade.game.games.smash.kits.KitZombie; +import nautilus.game.arcade.kit.Kit; + +/** + * SmashGladiators + * + * @author xXVevzZXx + */ +public class SmashGladiators extends Gladiators +{ + public SmashGladiators(ArcadeManager manager) + { + super(manager, new Kit[] + { + new KitSkeleton(manager), + new KitGolem(manager), + new KitSpider(manager), + new KitSlime(manager), + + new KitCreeper(manager), + new KitEnderman(manager), + new KitSnowman(manager), + new KitWolf(manager), + + + new KitBlaze(manager), + new KitWitch(manager), + new KitChicken(manager), + new KitSkeletalHorse(manager), + new KitPig(manager), + new KitSkySquid(manager), + new KitWitherSkeleton(manager), + new KitMagmaCube(manager), + new KitZombie(manager), + new KitCow(manager), + + new KitSheep(manager) + }, GameType.Brawl); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void noFallDamage(CustomDamageEvent event) + { + if (event.IsCancelled()) + return; + + if (event.GetCause() == DamageCause.FALL) + event.SetCancelled("No Fall Damage"); + } + + @EventHandler(priority = EventPriority.HIGH) + public void customKnockback(CustomDamageEvent event) + { + if (event.IsCancelled()) + return; + + if (event.GetDamageePlayer() != null) + event.AddKnockback("Smash Knockback", 1 + 0.1 * (20 - event.GetDamageePlayer().getHealth())); + } + + + @Override + protected void giveLoadout(Player p, ArenaType type) + { + if (!GetPlayers(true).contains(p)) + return; + + GetKit(p).ApplyKit(p); + + p.playSound(p.getLocation(), Sound.LEVEL_UP, 1f, 1f); + } + + @Override + public String GetMode() + { + return "Smash Gladiators"; + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/micro/Micro.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/micro/Micro.java index 9ad6382c3..0b62093a5 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/micro/Micro.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/micro/Micro.java @@ -30,6 +30,19 @@ public class Micro extends TeamGame private ArrayList _blocks = new ArrayList(); private ArrayList _glass = new ArrayList(); + public Micro(ArcadeManager manager, GameType type) + { + this(manager, + + new Kit[] + { + new KitArcher(manager), + new KitWorker(manager), + new KitFighter(manager) + }, + GameType.Micro); + } + public Micro(ArcadeManager manager, Kit[] kits, GameType type) { super(manager, type, kits, @@ -54,16 +67,8 @@ public class Micro extends TeamGame public Micro(ArcadeManager manager) { - this(manager, - - new Kit[] - { - new KitArcher(manager), - new KitWorker(manager), - new KitFighter(manager) - }, - GameType.Micro); - + this(manager, GameType.Micro); + registerStatTrackers( new KillsWithinGameStatTracker(this, 8, "Annihilation") ); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/micro/modes/CookieFight.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/micro/modes/CookieFight.java new file mode 100644 index 000000000..526797798 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/micro/modes/CookieFight.java @@ -0,0 +1,55 @@ +package nautilus.game.arcade.game.games.micro.modes; + +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.GameType; +import nautilus.game.arcade.events.GameStateChangeEvent; +import nautilus.game.arcade.game.games.micro.Micro; + +/** + * CookieFight + * + * @author xXVevzZXx + */ +public class CookieFight extends Micro +{ + + private int _enchantmentLevel; + + public CookieFight(ArcadeManager manager) + { + super(manager, GameType.Brawl); + + _enchantmentLevel = 250; + } + + @EventHandler + public void cookie(GameStateChangeEvent event) + { + if (event.GetState() != GameState.Live) + return; + + for (Player player : GetPlayers(true)) + { + ItemStack item = new ItemStack(Material.COOKIE); + item.addUnsafeEnchantment(Enchantment.KNOCKBACK, _enchantmentLevel); + player.getInventory().addItem(item); + + UtilPlayer.message(player, F.main("Game", "Oh look, you got a Cookie!")); + } + } + + @Override + public String GetMode() + { + return "Cookie Fight"; + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/micro/modes/OverpoweredMicroBattles.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/micro/modes/OverpoweredMicroBattles.java new file mode 100644 index 000000000..cc6d27444 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/micro/modes/OverpoweredMicroBattles.java @@ -0,0 +1,38 @@ +package nautilus.game.arcade.game.games.micro.modes; + +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.GameType; +import nautilus.game.arcade.game.games.AbsorptionFix; +import nautilus.game.arcade.game.games.micro.Micro; +import nautilus.game.arcade.game.games.micro.modes.kits.KitOverlord; +import nautilus.game.arcade.kit.Kit; + +/** + * OPMicroBattles + * + * @author xXVevzZXx + */ +public class OverpoweredMicroBattles extends Micro +{ + + public OverpoweredMicroBattles(ArcadeManager manager) + { + super(manager, + new Kit[] + { + new KitOverlord(manager) + }, + GameType.Brawl); + + TeamArmor = false; + + new AbsorptionFix(this); + } + + @Override + public String GetMode() + { + return "OP Micro Battles"; + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/micro/modes/TinySmash.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/micro/modes/TinySmash.java new file mode 100644 index 000000000..983a37481 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/micro/modes/TinySmash.java @@ -0,0 +1,96 @@ +package nautilus.game.arcade.game.games.micro.modes; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; + +import mineplex.minecraft.game.core.damage.CustomDamageEvent; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.GameType; +import nautilus.game.arcade.game.games.micro.Micro; +import nautilus.game.arcade.game.games.smash.kits.KitBlaze; +import nautilus.game.arcade.game.games.smash.kits.KitChicken; +import nautilus.game.arcade.game.games.smash.kits.KitCow; +import nautilus.game.arcade.game.games.smash.kits.KitCreeper; +import nautilus.game.arcade.game.games.smash.kits.KitEnderman; +import nautilus.game.arcade.game.games.smash.kits.KitGolem; +import nautilus.game.arcade.game.games.smash.kits.KitMagmaCube; +import nautilus.game.arcade.game.games.smash.kits.KitPig; +import nautilus.game.arcade.game.games.smash.kits.KitSheep; +import nautilus.game.arcade.game.games.smash.kits.KitSkeletalHorse; +import nautilus.game.arcade.game.games.smash.kits.KitSkeleton; +import nautilus.game.arcade.game.games.smash.kits.KitSkySquid; +import nautilus.game.arcade.game.games.smash.kits.KitSlime; +import nautilus.game.arcade.game.games.smash.kits.KitSnowman; +import nautilus.game.arcade.game.games.smash.kits.KitSpider; +import nautilus.game.arcade.game.games.smash.kits.KitWitch; +import nautilus.game.arcade.game.games.smash.kits.KitWitherSkeleton; +import nautilus.game.arcade.game.games.smash.kits.KitWolf; +import nautilus.game.arcade.game.games.smash.kits.KitZombie; +import nautilus.game.arcade.kit.Kit; + +/** + * TinySmash + * + * @author xXVevzZXx + */ +public class TinySmash extends Micro +{ + + public TinySmash(ArcadeManager manager) + { + super(manager, new Kit[] + { + new KitSkeleton(manager), + new KitGolem(manager), + new KitSpider(manager), + new KitSlime(manager), + + new KitCreeper(manager), + new KitEnderman(manager), + new KitSnowman(manager), + new KitWolf(manager), + + + new KitBlaze(manager), + new KitWitch(manager), + new KitChicken(manager), + new KitSkeletalHorse(manager), + new KitPig(manager), + new KitSkySquid(manager), + new KitWitherSkeleton(manager), + new KitMagmaCube(manager), + new KitZombie(manager), + new KitCow(manager), + + new KitSheep(manager) + }, GameType.Brawl); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void noFallDamage(CustomDamageEvent event) + { + if (event.IsCancelled()) + return; + + if (event.GetCause() == DamageCause.FALL) + event.SetCancelled("No Fall Damage"); + } + + @EventHandler(priority = EventPriority.HIGH) + public void customKnockback(CustomDamageEvent event) + { + if (event.IsCancelled()) + return; + + if (event.GetDamageePlayer() != null) + event.AddKnockback("Smash Knockback", 1 + 0.1 * (20 - event.GetDamageePlayer().getHealth())); + } + + @Override + public String GetMode() + { + return "Tiny Smash"; + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/micro/modes/kits/KitOverlord.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/micro/modes/kits/KitOverlord.java new file mode 100644 index 000000000..ff46e7414 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/micro/modes/kits/KitOverlord.java @@ -0,0 +1,49 @@ +package nautilus.game.arcade.game.games.micro.modes.kits; + +import org.bukkit.Material; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.itemstack.ItemStackFactory; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.kit.KitAvailability; +import nautilus.game.arcade.kit.Perk; +import nautilus.game.arcade.kit.ProgressingKit; +import nautilus.game.arcade.kit.perks.PerkFletcher; + +public class KitOverlord extends ProgressingKit +{ + private static final String[] DESCRIPTION = { + "You tell me I'm OP?!", + }; + + private static final Perk[] PERKS = { + new PerkFletcher(3, 16, true) + }; + + private static final ItemStack IN_HAND = new ItemStack(Material.GOLDEN_APPLE); + + private static final ItemStack[] PLAYER_ITEMS = { + ItemStackFactory.Instance.CreateStack(Material.DIAMOND_SWORD), + ItemStackFactory.Instance.CreateStack(Material.DIAMOND_PICKAXE), + ItemStackFactory.Instance.CreateStack(Material.BOW), + ItemStackFactory.Instance.CreateStack(Material.GOLDEN_APPLE, 5) + }; + + public KitOverlord(ArcadeManager manager) + { + super(manager, "Overlord", "microoverlord", KitAvailability.Free, DESCRIPTION, PERKS, EntityType.ZOMBIE, IN_HAND); + } + + @Override + public void GiveItems(Player player) + { + player.getInventory().addItem(PLAYER_ITEMS); + + player.getInventory().setHelmet(new ItemStack(Material.DIAMOND_HELMET)); + player.getInventory().setChestplate(new ItemStack(Material.DIAMOND_CHESTPLATE)); + player.getInventory().setLeggings(new ItemStack(Material.DIAMOND_LEGGINGS)); + player.getInventory().setBoots(new ItemStack(Material.DIAMOND_BOOTS)); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/CustomGunDamageEvent.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/CustomGunDamageEvent.java new file mode 100644 index 000000000..023f90950 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/CustomGunDamageEvent.java @@ -0,0 +1,59 @@ +package nautilus.game.arcade.game.games.minestrike; + +import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerEvent; + +import mineplex.minecraft.game.core.damage.CustomDamageEvent; +import nautilus.game.arcade.game.games.minestrike.data.Bullet; + +public class CustomGunDamageEvent extends PlayerEvent +{ + private static final HandlerList handlers = new HandlerList(); + + public static HandlerList getHandlerList() + { + return handlers; + } + + @Override + public HandlerList getHandlers() + { + return getHandlerList(); + } + + private Bullet _bullet; + private final boolean _headshot; + private CustomDamageEvent _damageEvent; + private GunModule _game; + + public CustomGunDamageEvent(Bullet _bullet, Player _target, boolean _headshot, CustomDamageEvent _damageEvent, GunModule game) + { + super(_target); + this._bullet = _bullet; + this._headshot = _headshot; + this._damageEvent = _damageEvent; + this._game = game; + } + + public Bullet getBullet() + { + return _bullet; + } + + public boolean isHeadshot() + { + return _headshot; + } + + public CustomDamageEvent getDamageEvent() + { + return _damageEvent; + } + + public GunModule getGame() + { + return _game; + } + +} \ No newline at end of file diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/MineStrike.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/GunModule.java similarity index 55% rename from Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/MineStrike.java rename to Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/GunModule.java index 33e1bd360..5bdc95677 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/MineStrike.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/GunModule.java @@ -1,14 +1,12 @@ package nautilus.game.arcade.game.games.minestrike; import java.lang.reflect.Field; -import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import org.bukkit.Bukkit; import org.bukkit.ChatColor; -import org.bukkit.Color; import org.bukkit.Effect; import org.bukkit.Location; import org.bukkit.Material; @@ -29,32 +27,24 @@ import org.bukkit.event.Event; 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.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityRegainHealthEvent; import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; import org.bukkit.event.entity.ItemDespawnEvent; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.entity.ProjectileHitEvent; -import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.painting.PaintingBreakEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerDropItemEvent; -import org.bukkit.event.player.PlayerEvent; import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerPickupItemEvent; -import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; import org.bukkit.event.player.PlayerToggleSneakEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.inventory.meta.LeatherArmorMeta; -import org.bukkit.scoreboard.DisplaySlot; -import org.bukkit.scoreboard.NameTagVisibility; -import org.bukkit.scoreboard.Objective; -import org.bukkit.scoreboard.Team; import org.bukkit.util.Vector; import mineplex.core.common.util.C; @@ -89,13 +79,10 @@ import mineplex.minecraft.game.core.combat.event.CombatDeathEvent; import mineplex.minecraft.game.core.condition.Condition.ConditionType; 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.events.PlayerKitGiveEvent; import nautilus.game.arcade.game.Game; +import nautilus.game.arcade.game.Game.GameState; import nautilus.game.arcade.game.GameTeam; -import nautilus.game.arcade.game.GameTeam.PlayerState; -import nautilus.game.arcade.game.TeamGame; import nautilus.game.arcade.game.games.minestrike.data.Bomb; import nautilus.game.arcade.game.games.minestrike.data.Bullet; import nautilus.game.arcade.game.games.minestrike.items.StrikeItem; @@ -103,108 +90,13 @@ import nautilus.game.arcade.game.games.minestrike.items.StrikeItemType; import nautilus.game.arcade.game.games.minestrike.items.equipment.armor.Armor; import nautilus.game.arcade.game.games.minestrike.items.grenades.Grenade; import nautilus.game.arcade.game.games.minestrike.items.guns.Gun; -import nautilus.game.arcade.game.games.minestrike.items.guns.GunStats; import nautilus.game.arcade.game.games.minestrike.items.guns.GunType; -import nautilus.game.arcade.game.games.minestrike.kits.KitPlayer; -import nautilus.game.arcade.kit.Kit; -import nautilus.game.arcade.managers.chat.ChatStatData; -import nautilus.game.arcade.stats.KaboomStatTracker; -import nautilus.game.arcade.stats.KillAllOpposingMineStrikeRoundStatTracker; -import nautilus.game.arcade.stats.KillFastStatTracker; -import nautilus.game.arcade.stats.KillReasonStatTracker; -import nautilus.game.arcade.stats.KillsWithConditionStatTracker; -import nautilus.game.arcade.stats.MineStrikeGunStats; -import nautilus.game.arcade.stats.MineStrikeLastAliveKillStatTracker; -import nautilus.game.arcade.stats.TeamDeathsStatTracker; -import nautilus.game.arcade.stats.TeamKillsStatTracker; import net.minecraft.server.v1_8_R3.EntityArrow; -public class MineStrike extends TeamGame +public class GunModule implements Listener { - public static float RECOIL = 0.8f; - public static float CONE = 0.7f; - public static float MOVE_PENALTY = 0.8f; - - public static class PlayerHeadshotEvent extends PlayerEvent - { - private static final HandlerList handlers = new HandlerList(); - - public static HandlerList getHandlerList() - { - return handlers; - } - - @Override - public HandlerList getHandlers() - { - return getHandlerList(); - } - - private final Player _shooter; - - public PlayerHeadshotEvent(Player who, Player shooter) - { - super(who); - - _shooter = shooter; - } - - public Player getShooter() - { - return _shooter; - } - } - - public static class CustomGunDamageEvent extends PlayerEvent - { - private static final HandlerList handlers = new HandlerList(); - - public static HandlerList getHandlerList() - { - return handlers; - } - - @Override - public HandlerList getHandlers() - { - return getHandlerList(); - } - - private Bullet _bullet; - private final boolean _headshot; - private CustomDamageEvent _damageEvent; - private MineStrike _game; - - public CustomGunDamageEvent(Bullet _bullet, Player _target, boolean _headshot, CustomDamageEvent _damageEvent, MineStrike game) - { - super(_target); - this._bullet = _bullet; - this._headshot = _headshot; - this._damageEvent = _damageEvent; - this._game = game; - } - - public Bullet getBullet() - { - return _bullet; - } - - public boolean isHeadshot() - { - return _headshot; - } - - public CustomDamageEvent getDamageEvent() - { - return _damageEvent; - } - - public MineStrike getGame() - { - return _game; - } - - } + public ArcadeManager Manager; + private Game _host; public static class RoundOverEvent extends Event { @@ -234,27 +126,28 @@ public class MineStrike extends TeamGame } } - //Managers - private ShopManager _shopManager; + + public static float RECOIL = 0.8f; + public static float CONE = 0.7f; + public static float MOVE_PENALTY = 0.8f; + + public boolean Debug = false; + public int BulletInstant = 2; //0 = Slow, 1 = Instant, 2 = Mix + public boolean CustomHitbox = true; + public boolean BulletAlternate = false; - //Data - private int _roundsToWin = 8; - private long _roundTime = 120000; - - private boolean _debug = false; - private int _bulletInstant = 2; //0 = Slow, 1 = Instant, 2 = Mix - private boolean _customHitbox = true; - private boolean _bulletAlternate = false; - - //Map Data - private ArrayList _bombSites; + public boolean EnablePickup = true; + public boolean EnableDrop = true; + public boolean EnableCleaning = true; + + private long _freezeTime = -1; + + private int _round; //Ongoing Data private HashMap _gunsEquipped = new HashMap(); private HashMap _grenadesEquipped = new HashMap(); - private HashMap _score = new HashMap(); - private HashMap _disguise = new HashMap(); //Round Data (wiped at end of each round) @@ -274,211 +167,24 @@ public class MineStrike extends TeamGame private Player _bombHolder = null; private long _bombHolderLastMove = 0; - private Player _bombPlanter; - private Player _bombDefuser; - private Player _bombPlantedBy; - - private boolean _bombScoreboardFlash = false; - private HashMap _scoped = new HashMap(); - - //Round Data - private String _winText = null; - private boolean _roundOver = false; - private int _freezeTime = 0; - - //Money Data - private boolean _bombPlanted = false; - private boolean _ctWonLast = false; - private int _winStreak = 0; - - //Scoreboard - private Objective _scoreObj; - - public MineStrike(ArcadeManager manager) + + public GunModule(Game host) { - super(manager, GameType.MineStrike, - - new Kit[] - { - new KitPlayer(manager), - }, - - new String[] - { - C.cAqua + "SWAT" + C.cWhite + " Defend the Bomb Sites", - C.cAqua + "SWAT" + C.cWhite + " Kill the Bombers", - " ", - C.cRed + "Bombers" + C.cWhite + " Plant the Bomb at Bomb Site", - C.cRed + "Bombers" + C.cWhite + " Kill the SWAT Team", - }); - - _shopManager = new ShopManager(this); - Manager.getCosmeticManager().setHideParticles(true); - - this.StrictAntiHack = true; - - AnnounceStay = false; - - this.HungerSet = 20; - - this.ItemDrop = true; - - this.DeathTeleport = false; - - this.InventoryClick = true; - - this.JoinInProgress = true; - - this.DontAllowOverfill = true; - - _scoreObj = Scoreboard.GetScoreboard().registerNewObjective("HP", "dummy"); - _scoreObj.setDisplaySlot(DisplaySlot.BELOW_NAME); - - this._help = new String[] - { - //"Tap Crouch when close to an ally to Boost", - "Open Inventory at spawn to buy guns", - "Hold Right-Click to Plant Bomb", - "Look at the Bomb to Defuse it", - "Moving decreases accuracy", - "Sprinting heavily decreases accuracy", - "Jumping massively decreases accuracy", - "Crouching increases accuracy", - "Left-Click to drop Grenades", - "Right-Click to throw Grenades", - "Burst Fire for greater accuracy", - "Sniper Rifles are only accurate while scoped", - "Rifles have 30% recoil reduction while scoped", - "Pick up better weapons from dead players" - }; - - registerStatTrackers( - new KillReasonStatTracker(this, "Headshot", "BoomHeadshot", true), - new KillAllOpposingMineStrikeRoundStatTracker(this), - new KaboomStatTracker(this), - new KillReasonStatTracker(this, "Backstab", "Assassination", false), - new MineStrikeLastAliveKillStatTracker(this), - new KillFastStatTracker(this, 4, 5, "KillingSpree"), - new KillsWithConditionStatTracker(this, "Blindfolded", ConditionType.BLINDNESS, "Flash Bang", 2), - - new TeamDeathsStatTracker(this), - new TeamKillsStatTracker(this), - - new MineStrikeGunStats(this) - ); - - registerChatStats( - Kills, - Deaths, - KDRatio, - BlankLine, - new ChatStatData("BoomHeadshot", "Headshots", true), - Assists - ); - } - - @Override - public void ParseData() - { - _bombSites = WorldData.GetDataLocs("RED"); - } - - @EventHandler - public void CustomTeamGeneration(GameStateChangeEvent event) - { - if (event.GetState() != GameState.Recruit) - return; + _host = host; + Manager = host.Manager; + _round = 1; - this.GetTeamList().get(0).SetColor(ChatColor.AQUA); - this.GetTeamList().get(0).SetName("SWAT"); - - this.GetTeamList().get(1).SetColor(ChatColor.RED); - this.GetTeamList().get(1).SetName("Bombers"); + Manager.registerEvents(this); } @EventHandler - public void SetScoreboardNameVisibility(GameStateChangeEvent event) + public void unregisterSelf(GameStateChangeEvent event) { - if (event.GetState() != GameState.Prepare) + if (event.GetState() != GameState.Dead) return; - System.out.println("Hiding Scoreboard Nametags for Other Teams"); - for (Team curTeam : Scoreboard.GetScoreboard().getTeams()) - { - curTeam.setNameTagVisibility(NameTagVisibility.HIDE_FOR_OTHER_TEAMS); - //UtilServer.getServer().dispatchCommand(UtilServer.getServer().getConsoleSender(), - // "scoreboard teams option " + curTeam.getName() + " nametagVisibility hideForOtherTeams"); - } - } - - @EventHandler - public void giveStartEquipment(PlayerKitGiveEvent event) - { - GameTeam team = GetTeam(event.getPlayer()); - if (team == null) - return; - - GadgetManager gadgetManager = Manager.getCosmeticManager().getGadgetManager(); - GameModifierMineStrikeSkin knifeSkin = (GameModifierMineStrikeSkin) gadgetManager.getActiveGameModifier(event.getPlayer(), - GameModifierType.MineStrike, GameModifierMineStrikeSkin.getWeaponFilter("Knife")); - - Material mat = Material.IRON_AXE; - byte data = 0; - String name = "Knife"; - - if(knifeSkin != null) - { - mat = knifeSkin.getSkinMaterial(); - data = knifeSkin.getSkinData(); - name = knifeSkin.getName(); - } - - ItemStack knife = ItemStackFactory.Instance.CreateStack(mat, data, 1, name); - - if (team.GetColor() == ChatColor.RED) - { - if (IsAlive(event.getPlayer())) - { - //Pistol - Gun gun = new Gun(GunStats.GLOCK_18); - registerGun(gun, event.getPlayer()); - gun.giveToPlayer(event.getPlayer(), true); - gun.updateSkin(event.getPlayer(), getArcadeManager().getCosmeticManager().getGadgetManager()); - gun.updateWeaponName(event.getPlayer(), this); - - //Knife - if(knifeSkin == null) knife.setType(Material.IRON_AXE); - - event.getPlayer().getInventory().setItem(2, knife); - - //Armor - giveTeamArmor(event.getPlayer(), Color.fromRGB(255, 75, 75)); - } - } - else if (team.GetColor() == ChatColor.AQUA) - { - if (IsAlive(event.getPlayer())) - { - //Pistol - Gun gun = new Gun(GunStats.P2000); - registerGun(gun, event.getPlayer()); - gun.giveToPlayer(event.getPlayer(), true); - gun.updateWeaponName(event.getPlayer(), this); - gun.updateSkin(event.getPlayer(), getArcadeManager().getCosmeticManager().getGadgetManager()); - - //Knife - if(knifeSkin == null) knife.setType(Material.IRON_SWORD); - - event.getPlayer().getInventory().setItem(2, knife); - - //Armor - giveTeamArmor(event.getPlayer(), Color.fromRGB(125, 200, 255)); - } - } - - //Enter Shop - _shopManager.enterShop(event.getPlayer()); + HandlerList.unregisterAll(this); } @EventHandler(priority = EventPriority.MONITOR) @@ -515,133 +221,6 @@ public class MineStrike extends TeamGame // } // } - public void giveTeamArmor(Player player, Color color) - { - ItemStack armor = new ItemStack(Material.LEATHER_CHESTPLATE); - LeatherArmorMeta meta = (LeatherArmorMeta)armor.getItemMeta(); - meta.setColor(color); - armor.setItemMeta(meta); - player.getInventory().setChestplate(armor); - - ItemStack legs = new ItemStack(Material.LEATHER_LEGGINGS); - LeatherArmorMeta metaLegs = (LeatherArmorMeta)legs.getItemMeta(); - metaLegs.setColor(color); - legs.setItemMeta(metaLegs); - player.getInventory().setLeggings(legs); - - ItemStack boots = new ItemStack(Material.LEATHER_BOOTS); - LeatherArmorMeta metaBoots = (LeatherArmorMeta)boots.getItemMeta(); - metaBoots.setColor(color); - boots.setItemMeta(metaBoots); - player.getInventory().setBoots(boots); - } - - @EventHandler - public void shopInventoryClick(InventoryClickEvent event) - { - _shopManager.inventoryClick(event); - } - - - - @EventHandler - public void shopUpdate(UpdateEvent event) - { - if (event.getType() != UpdateType.SEC) - return; - - _shopManager.update(); - } - - @EventHandler - public void quitClean(PlayerQuitEvent event) - { - _shopManager.leaveShop(event.getPlayer(), false, true); - _disguise.remove(event.getPlayer()); - _scoped.remove(event.getPlayer()); - dropInventory(event.getPlayer()); - } - - @EventHandler - public void giveBombInitial(GameStateChangeEvent event) - { - if (event.GetState() != GameState.Prepare) - return; - - UtilServer.getServer().getScheduler().scheduleSyncDelayedTask(Manager.getPlugin(), new Runnable() - { - public void run() - { - Player player = UtilAlg.Random(GetTeam(ChatColor.RED).GetPlayers(true)); - - giveBombToPlayer(player); - } - }, 40); - } - - public void giveBombToPlayer(Player player) - { - if (player == null) - return; - - GameTeam team = GetTeam(player); - if (team == null) - return; - - if (team.GetColor() != ChatColor.RED) - return; - - //Bomb - player.getInventory().setItem(8, ItemStackFactory.Instance.CreateStack(Material.GOLD_SWORD, (byte)0, 1, C.cGold + C.Bold + "C4 Explosive")); - - //Inform - if (!IsLive() || _freezeTime > 0) - { - for (Player other : team.GetPlayers(false)) - if (!other.equals(player)) - { - UtilTextMiddle.display(null, player.getName() + " has the Bomb", 10, 80, 10, other); - UtilPlayer.message(other, C.cGold + C.Bold + player.getName() + " has the Bomb!"); - } - - //Chat - UtilPlayer.message(player, C.cGold + C.Bold + "You have the Bomb!"); - UtilPlayer.message(player, C.cGold + C.Bold + "Hold Right-Click to place at a Bomb Site!"); - - //Title - UtilTextMiddle.display(C.cRed + "You have the Bomb", "Hold Right-Click to place at a Bomb Site!", 10, 80, 10, player); - } - else - { - for (Player other : team.GetPlayers(false)) - if (!other.equals(player)) - { - UtilPlayer.message(other, C.cGold + C.Bold + player.getName() + " picked up the Bomb!"); - - //Title - UtilTextMiddle.display(null, player.getName() + " picked up the Bomb", 10, 50, 10, other); - } - - - //Chat - UtilPlayer.message(player, C.cGold + C.Bold + "You picked up the Bomb!"); - - //Title - UtilTextMiddle.display(null, "You picked up the Bomb", 10, 50, 10, player); - } - - - player.playSound(player.getLocation(), Sound.NOTE_PLING, 1f, 2f); - _bombHolder = player; - _bombHolderLastMove = System.currentTimeMillis(); - - if (_bombItem != null) - { - _bombItem.remove(); - _bombItem = null; - } - } - public void registerGun(Gun gun, Player player) { _gunsEquipped.put(gun, player); @@ -766,10 +345,10 @@ public class MineStrike extends TeamGame if (_freezeTime > 0) return; - if (!IsLive()) + if (!_host.IsLive()) return; - if (!IsAlive(event.getPlayer())) + if (!_host.IsAlive(event.getPlayer())) return; if (!UtilEvent.isAction(event, ActionType.R)) @@ -793,10 +372,10 @@ public class MineStrike extends TeamGame if (_freezeTime > 0) return; - if (!IsLive()) + if (!_host.IsLive()) return; - if (!IsAlive(event.getPlayer())) + if (!_host.IsAlive(event.getPlayer())) return; if (!UtilEvent.isAction(event, ActionType.L)) @@ -822,10 +401,10 @@ public class MineStrike extends TeamGame if (!UtilEvent.isAction(event, ActionType.L) && !UtilEvent.isAction(event, ActionType.R)) return; - if (!IsLive()) + if (!_host.IsLive()) return; - if (!IsAlive(event.getPlayer())) + if (!_host.IsAlive(event.getPlayer())) return; Grenade grenade = getGrenadeInHand(event.getPlayer(), null); @@ -833,7 +412,7 @@ public class MineStrike extends TeamGame if (grenade == null) return; - if (!UtilTime.elapsed(GetStateTime(), 10000)) + if (!UtilTime.elapsed(_host.GetStateTime(), 10000)) { UtilPlayer.message(event.getPlayer(), F.main("Game", "You cannot throw Grenades yet.")); return; @@ -846,7 +425,10 @@ public class MineStrike extends TeamGame @EventHandler public void triggerDrop(PlayerDropItemEvent event) { - if (!InProgress()) + if(!EnableDrop) + return; + + if (!_host.InProgress()) return; //Without this, the event is cancelled in pre-game by managers @@ -880,7 +462,7 @@ public class MineStrike extends TeamGame _bombHolder = null; //Radio - playSound(Radio.T_BOMB_DROP, null, GetTeam(event.getPlayer())); + playSound(Radio.T_BOMB_DROP, null, _host.GetTeam(event.getPlayer())); return; } @@ -897,7 +479,7 @@ public class MineStrike extends TeamGame public void dropInventory(Player player) { - if (!InProgress()) + if (!_host.InProgress()) return; for (int i=0 ; i<9 ; i++) @@ -979,7 +561,7 @@ public class MineStrike extends TeamGame _bombHolder = null; //Radio - playSound(Radio.T_BOMB_DROP, null, GetTeam(ChatColor.RED)); + playSound(Radio.T_BOMB_DROP, null, _host.GetTeam(ChatColor.RED)); } } @@ -989,7 +571,10 @@ public class MineStrike extends TeamGame @EventHandler public void triggerPickup(PlayerPickupItemEvent event) { - if (!InProgress()) + if (!EnablePickup) + return; + + if (!_host.InProgress()) return; if (event.getItem().getTicksLived() < 10) @@ -998,7 +583,7 @@ public class MineStrike extends TeamGame if (UtilMath.offset(event.getItem(), event.getPlayer()) > 1) return; - if (!IsAlive(event.getPlayer())) + if (!_host.IsAlive(event.getPlayer())) return; //Guns @@ -1020,7 +605,7 @@ public class MineStrike extends TeamGame //Defusal if (UtilGear.isMat(event.getItem().getItemStack(), Material.SHEARS)) { - if (GetTeam(event.getPlayer()).GetColor() == ChatColor.RED) + if (_host.GetTeam(event.getPlayer()).GetColor() == ChatColor.RED) return; if (UtilInv.contains(event.getPlayer(), Material.SHEARS, (byte)0, 1)) @@ -1296,7 +881,7 @@ public class MineStrike extends TeamGame if (event.GetCause() == DamageCause.FALL) { - event.AddMod(GetName(), "Fall Reduction", -2, false); + event.AddMod(_host.GetName(), "Fall Reduction", -2, false); return; } @@ -1368,7 +953,7 @@ public class MineStrike extends TeamGame //Get Hit Area int hitArea = 0; - if (_customHitbox) + if (CustomHitbox) { if (event.GetProjectile() instanceof Arrow) hitArea = getArrowHitArea(event.GetDamageePlayer(), bullet.Origin.clone(), bullet.Direction.clone()); @@ -1394,7 +979,7 @@ public class MineStrike extends TeamGame if (!Manager.canHurt(event.GetDamageePlayer(), event.GetDamagerPlayer(true))) event.SetCancelled("Team Damage"); - event.AddMod(GetName(), "Negate Default", -event.GetDamageInitial(), false); + event.AddMod(_host.GetName(), "Negate Default", -event.GetDamageInitial(), false); //Damage + Dropoff double damage = bullet.getDamage(); @@ -1504,62 +1089,6 @@ public class MineStrike extends TeamGame loc.getY() >= player.getEyeLocation().getY() + 0.0 && loc.getY() < player.getEyeLocation().getY() + 0.2; } - - - @EventHandler - public void killReward(CombatDeathEvent event) - { - if (!(event.GetEvent().getEntity() instanceof Player)) - return; - - Player killed = (Player)event.GetEvent().getEntity(); - - if (event.GetLog().GetKiller() != null) - { - Player killer = UtilPlayer.searchExact(event.GetLog().GetKiller().GetName()); - - if (killer == null || killer.equals(killed)) - return; - - if (GetTeam(killed).equals(GetTeam(killer))) - return; - - int amount = 300; - - if (event.GetLog().GetLastDamager().GetReason().contains("AWP")) - amount = 100; - - else if (event.GetLog().GetLastDamager().GetReason().contains("PP-Bizon")) - amount = 600; - - else if (event.GetLog().GetLastDamager().GetReason().contains("Nova")) - amount = 900; - - else if (event.GetLog().GetLastDamager().GetReason().contains("Knife")) - amount = 1500; - - _shopManager.addMoney(killer, amount, "kill with " + event.GetLog().GetLastDamager().GetReason()); - - /* - if(event.GetLog().GetLastDamager().GetReason().contains("Knife")) - { - GadgetManager gadgetManager = Manager.getCosmeticManager().getGadgetManager(); - GameModifierMineStrikeSkin knifeSkin = (GameModifierMineStrikeSkin) gadgetManager.getActiveGameModifier(event.getPlayer(), - GameModifierType.MineStrike, GameModifierMineStrikeSkin.getWeaponFilter("Knife")); - - if(knifeSkin != null) - { - int kills = GetStats().get(killer).get("") - ItemStack item = killer.getInventory().getItem(2); - ItemMeta im = item.getItemMeta(); - im.setDisplayName(C.cYellow + C.Bold + knifeSkin.getName() + " - Kills: " + kills); - - AddStat(killer, "Knife." + knifeSkin.getName() + ".Kills", 1, false, false); - } - } - */ - } - } @EventHandler(priority = EventPriority.LOWEST) public void killMessage(CombatDeathEvent event) @@ -1581,7 +1110,7 @@ public class MineStrike extends TeamGame { reason = ""; - GameTeam team = GetTeam(killer); + GameTeam team = _host.GetTeam(killer); if (team != null) reason += team.GetColor(); @@ -1639,7 +1168,10 @@ public class MineStrike extends TeamGame { if (!_gunsEquipped.get(gun).equals(player)) continue; - + + if (player.getInventory().getItem(slot) == null) + continue; + if (gun.isStack(player.getInventory().getItem(slot))) { gun.drop(this, player, false, false); @@ -1649,294 +1181,10 @@ public class MineStrike extends TeamGame } } - @EventHandler - public void plantBomb(PlayerInteractEvent event) - { - Player player = event.getPlayer(); - - if (!UtilGear.isMat(player.getItemInHand(), Material.GOLD_SWORD)) - return; - - // Fixed bomb able to be planted after the round is over. - if (_roundOver) - { - UtilPlayer.message(player, F.main("Game", "You cannot plant the bomb once the round is over.")); - event.setCancelled(true); - return; - } - - // Added a small tip for players that are trying to right-click with the bomb. - if (UtilEvent.isAction(event, ActionType.L)) - { - UtilPlayer.message(player, F.main("Game", "You must " + F.elem("Right-Click") + " while holding the bomb to plant it.")); - event.setCancelled(true); - return; - } - - if (!UtilEnt.isGrounded(player)) - { - UtilPlayer.message(player, F.main("Game", "You can only plant the bomb on the ground.")); - event.setCancelled(true); - return; - } - - //Should never occur with 1 Bomb - if (_bombPlanter != null) - { - UtilPlayer.message(player, F.main("Game", "Someone else is planting the bomb.")); - event.setCancelled(true); - return; - } - - //Check Bomb Sites - boolean near = false; - for (Location loc : _bombSites) - { - if (UtilMath.offset(player.getLocation(), loc) < 5) - { - near = true; - break; - } - } - - //Too Far - if (!near) - { - UtilPlayer.message(player, F.main("Game", "You can only plant the bomb at a bomb site.")); - event.setCancelled(true); - return; - } - - _bombPlanter = player; - _bombPlanter.setExp(0f); - - UtilPlayer.message(player, F.main("Game", "You are now placing the bomb.")); - - //Radio - playSound(Radio.T_BOMB_PLANT, null, GetTeam(_bombPlanter)); - } - - @EventHandler - public void plantBombUpdate(UpdateEvent event) - { - if (event.getType() != UpdateType.TICK) - return; - - // Added to check if the round is over when a bomb is being planted. - if (_roundOver) - return; - - if (_bombPlanter == null) - return; - - if (!_bombPlanter.isBlocking() || !_bombPlanter.isOnline()) - { - _bombPlanter.setExp(0f); - UtilTextMiddle.clear(_bombPlanter); - _bombPlanter = null; - return; - } - - _bombPlanter.setExp(Math.min(_bombPlanter.getExp() + 0.017f, 0.99999f)); - - if (Math.random() > 0.90) - _bombPlanter.getWorld().playSound(_bombPlanter.getLocation(), Sound.NOTE_PLING, 2f, 3f); - - UtilTextMiddle.display(C.cRed + C.Bold + "Planting Bomb", UtilTextMiddle.progress(_bombPlanter.getExp()), 0, 10, 0, _bombPlanter); - - if (_bombPlanter.getExp() >= 0.98f) - { - _bomb = new Bomb(_bombPlanter); - - _shopManager.addMoney(_bombPlanter, 300, "planting the bomb"); - - Announce(C.cRed + C.Bold + _bombPlanter.getName() + " has planted the bomb!"); - - _bombPlantedBy = _bombPlanter; - - _bombPlanter.setExp(0f); - _bombPlanter.setItemInHand(null); - _bombPlanter = null; - _bombHolder = null; - - //Sound - playSound(Radio.BOMB_PLANT, null, null); - - //Title - UtilTextMiddle.display(null, C.cRed + C.Bold + "Bomb has been planted!", 10, 50, 10); - } - } - - @EventHandler - public void plantDefuseBombRestrictMovement(PlayerMoveEvent event) - { - if (_bombPlanter != null && _bombPlanter.equals(event.getPlayer())) - if (UtilMath.offset(event.getFrom(), event.getTo()) > 0) - event.setTo(event.getFrom()); - - // if (_bombDefuser != null && _bombDefuser.equals(event.getPlayer())) - // if (UtilMath.offset(event.getFrom(), event.getTo()) > 0) - // event.setTo(event.getFrom()); - } - - @EventHandler - public void defuseKitMessage(PlayerInteractEvent event) - { - Player player = event.getPlayer(); - - if (!UtilGear.isMat(player.getItemInHand(), Material.SHEARS)) - return; - - UtilPlayer.message(player, F.main("Game", "Look at the Bomb to defuse it.")); - } - - public void startDefuse() - { - for (Player player : GetTeam(ChatColor.AQUA).GetPlayers(true)) - { - HashSet ignoreBlocks = new HashSet(); - ignoreBlocks.add(Material.AIR); - ignoreBlocks.add(Material.PORTAL); - - Block block = player.getTargetBlock(ignoreBlocks, 5); - - if (block == null || !_bomb.isBlock(block)) - continue; - - if (UtilMath.offset(player.getLocation(), block.getLocation().add(0.5, 0, 0.5)) > 3) - continue; - - if (_bombDefuser != null) - { - if (Recharge.Instance.use(player, "Defuse Message", 2000, false, false)) - UtilPlayer.message(player, F.main("Game", _bombDefuser.getName() + " is already defusing the Bomb.")); - - continue; - } - - _bombDefuser = player; - _bombDefuser.setExp(0f); - - UtilPlayer.message(player, F.main("Game", "You are defusing the Bomb.")); - - _bombDefuser.getWorld().playSound(_bombDefuser.getLocation(), Sound.PISTON_RETRACT, 2f, 1f); - } - } - - @EventHandler - public void defuseBombUpdate(UpdateEvent event) - { - if (_bomb == null) - return; - - if (!IsLive()) - return; - - if (event.getType() != UpdateType.TICK) - return; - - if (_bombDefuser == null) - { - startDefuse(); - } - - if (_bombDefuser == null) - return; - - HashSet ignoreBlocks = new HashSet(); - ignoreBlocks.add(Material.AIR); - ignoreBlocks.add(Material.PORTAL); - - Block block = _bombDefuser.getTargetBlock(ignoreBlocks, 5); - - if (!IsAlive(_bombDefuser) || block == null || !_bomb.isBlock(block) || !_bombDefuser.isOnline() || UtilMath.offset(_bombDefuser.getLocation(), block.getLocation().add(0.5, 0, 0.5)) > 3) - { - _bombDefuser.setExp(0f); - _bombDefuser = null; - return; - } - - //Kit or Not? - float defuseRate = 0.005f; - if (UtilGear.isMat(_bombDefuser.getInventory().getItem(8), Material.SHEARS)) - defuseRate = 0.01f; - - _bombDefuser.setExp(Math.min(_bombDefuser.getExp() + defuseRate, 0.99999f)); - - UtilTextMiddle.display(C.cAqua + C.Bold + "Defusing Bomb", UtilTextMiddle.progress(_bombDefuser.getExp()), 0, 10, 0, _bombDefuser); - - if (_bombDefuser.getExp() >= 0.98f) - { - _bomb.defuse(); - - _winText = _bombDefuser.getName() + " defused the bomb!"; - - _bomb = null; - _bombDefuser.setExp(0f); - _bombDefuser = null; - - //Sound - playSound(Radio.BOMB_DEFUSE, null, null); - - setWinner(GetTeam(ChatColor.AQUA), true); - } - } - - @EventHandler - public void bombUpdate(UpdateEvent event) - { - if (!IsLive()) - return; - - if (event.getType() != UpdateType.TICK) - return; - - if (_bomb == null) - return; - - if (!_bomb.update()) - return; - - /* - Set blocks = UtilBlock.getInRadius(_bomb.Block.getLocation(), 10d).keySet(); - - Iterator blockIterator = blocks.iterator(); - while (blockIterator.hasNext()) - { - Block block = blockIterator.next(); - - if (block.getY() < 2) - blockIterator.remove(); - } - - Manager.GetExplosion().BlockExplosion(blocks, _bomb.Block.getLocation(), false); - */ - - - HashMap players = UtilPlayer.getInRadius(_bomb.Block.getLocation(), 48); - for (Player player : players.keySet()) - { - if (!IsAlive(player)) - continue; - - // Damage Event - Manager.GetDamage().NewDamageEvent(player, null, null, - DamageCause.CUSTOM, 1 + (players.get(player) * 40), - true, true, false, "Bomb", "C4 Explosion"); - } - - - _bomb = null; - - _winText = _bombPlantedBy.getName() + " destroyed the bomb site!"; - - setWinner(GetTeam(ChatColor.RED), false); - } - @EventHandler public void bombItemUpdate(UpdateEvent event) { - if (!InProgress()) + if (!_host.InProgress()) return; if (event.getType() != UpdateType.SEC) @@ -1948,331 +1196,9 @@ public class MineStrike extends TeamGame UtilParticle.PlayParticle(ParticleType.HAPPY_VILLAGER, _bombItem.getLocation().add(0.0, 0.2, 0.0), 0, 0, 0, 0, 1, ViewDist.LONG, UtilServer.getPlayers()); } - - public int getScore(GameTeam team) + + public void reset() { - if (!_score.containsKey(team)) - _score.put(team, 0); - - return _score.get(team); - } - - public void addScore(GameTeam team) - { - _score.put(team, getScore(team) + 1); - } - - @EventHandler - public void roundTimerUpdate(UpdateEvent event) - { - if (!IsLive()) - return; - - if (event.getType() != UpdateType.TICK) - return; - - if (_bomb != null) - return; - - if (UtilTime.elapsed(GetStateTime(), _roundTime)) - { - _winText = "Bomb sites were successfully defended!"; - drawScoreboard(); - setWinner(GetTeam(ChatColor.AQUA), false); - } - } - - @EventHandler - public void roundPlayerCheck(UpdateEvent event) - { - if (!IsLive()) - return; - - if (event.getType() != UpdateType.TICK) - return; - - ArrayList teamsAlive = new ArrayList(); - - for (GameTeam team : this.GetTeamList()) - if (team.GetPlayers(true).size() > 0) - teamsAlive.add(team); - - if (teamsAlive.size() == 1) - { - //Bomb Planted - CT cannot win without defusing - if (_bomb != null) - { - if (teamsAlive.size() > 0) - { - if (teamsAlive.get(0).GetColor() == ChatColor.AQUA) - { - return; - } - } - } - - setWinner(teamsAlive.get(0), false); - } - else if (teamsAlive.size() == 0) - { - if (_bomb == null) - { - _winText = "Bomb sites were successfully defended!"; - setWinner(GetTeam(ChatColor.AQUA), false); - } - else - { - _winText = "Bomb site will be destroyed!"; - setWinner(GetTeam(ChatColor.RED), false); - } - } - } - - public void setWinner(final GameTeam winner, boolean defuse) - { - if (_roundOver) - return; - - Bukkit.getPluginManager().callEvent(new RoundOverEvent(this)); - - _roundOver = true; - - String winnerLine = C.Bold + "The round was a draw!"; - ChatColor color = ChatColor.GRAY; - if (winner != null) - { - if(winner.GetName().contains("Bombers")) { - winnerLine= winner.GetColor() + C.Bold + winner.GetName() + " have won the round!"; - } else { - winnerLine= winner.GetColor() + C.Bold + winner.GetName() + " has won the round!"; - } - addScore(winner); - drawScoreboard(); - color = winner.GetColor(); - - - } - - //Sound - if (winner != null) - { - UtilServer.getServer().getScheduler().scheduleSyncDelayedTask(Manager.getPlugin(), new Runnable() - { - public void run() - { - if (winner.GetColor() == ChatColor.RED) - playSound(Radio.T_WIN, null, null); - else - playSound(Radio.CT_WIN, null, null); - } - }, defuse ? 60 : 0); - } - - //Record Streak for Money - if (winner.GetColor() == ChatColor.RED) - { - _winStreak++; - - if (_ctWonLast) - { - _ctWonLast = false; - _winStreak = 0; - } - } - else - { - _winStreak++; - - if (!_ctWonLast) - { - _ctWonLast = true; - _winStreak = 0; - } - } - - //Announce - Announce("", false); - Announce(color + "===================================", false); - Announce("", false); - Announce(winnerLine, false); - if (_winText != null) - Announce(_winText, false); - Announce("", false); - Announce(color + "===================================", false); - - for (Player player : UtilServer.getPlayers()) - { - player.playSound(player.getLocation(), Sound.LEVEL_UP, 1f, 1f); - removeScope(player); - - Recharge.Instance.Reset(player, "reload"); - } - - UtilTextMiddle.display(null, winnerLine, 20, 120, 20); - - //Check for total game win - EndCheck(); - - //Next Round (if not over) - if (IsLive()) - { - UtilServer.getServer().getScheduler().scheduleSyncDelayedTask(Manager.getPlugin(), new Runnable() - { - public void run() - { - restartRound(); - } - }, 100); - } - } - - public void restartRound() - { - giveMoney(); - - //Clean - resetGame(); - - //Teleport to Spawn - for (GameTeam team : GetTeamList()) - team.SpawnTeleport(false); - - //Revive Dead Players - for (Player player : GetPlayers(false)) - { - if (Manager.isVanished(player)) - { - continue; - } - - if (!IsAlive(player)) - { - SetPlayerState(player, PlayerState.IN); - - GameTeam team = GetTeam(player); - - //Teleport - team.SpawnTeleport(player); - - Manager.Clear(player); - UtilInv.Clear(player); - - ValidateKit(player, GetTeam(player)); - - if (GetKit(player) != null) - GetKit(player).ApplyKit(player); - } - } - - //Remove Scope - for (Player player : GetPlayers(false)) - removeScope(player); - - //Get Hit By Bullets - for (Player player : GetPlayers(false)) - ((CraftPlayer) player).getHandle().spectating = false; - - //Prepare Sound - for (Player player : GetPlayers(false)) - { - player.playSound(player.getLocation(), Sound.HORSE_ARMOR, 1f, 2f); - Manager.GetCondition().Factory().Blind("Respawn", player, null, 2, 0, false, false, false); - UtilPlayer.message(player, F.main("Game", "You have " + F.elem(C.cGreen + "$" + _shopManager.getMoney(player)) + ". Open your Inventory to spend it.")); - - UtilTextMiddle.display(C.cGreen + "$" + _shopManager.getMoney(player), "Open your Inventory to buy new equipment", 10, 120, 10, player); - } - - //Update Scoreboard Teams - for (GameTeam team : GetTeamList()) - for (Player teamMember : team.GetPlayers(true)) - GetScoreboard().SetPlayerTeam(teamMember, team.GetName().toUpperCase()); - - //Alternate Bullets - if (_bulletAlternate) - _bulletInstant = (_bulletInstant + 1)%3; - - //Debug Details - if (_debug) - { - Announce(C.cDPurple + C.Bold + "ROUND SETTINGS:"); - - if (_customHitbox) - Announce(C.cPurple + C.Bold + "Hitbox: " + ChatColor.RESET + "Accurate with Headshots"); - else - Announce(C.cPurple + C.Bold + "Hitbox: " + ChatColor.RESET + "Default with No Headshot"); - - if (_bulletInstant == 0) - Announce(C.cPurple + C.Bold + "Bullets: " + ChatColor.RESET + "Slow and Visible"); - else if (_bulletInstant == 1) - Announce(C.cPurple + C.Bold + "Bullets: " + ChatColor.RESET + "Instant and Invisible"); - else - Announce(C.cPurple + C.Bold + "Bullets: " + ChatColor.RESET + "Slow and Visible with Instant Sniper"); - } - } - - public void giveMoney() - { - if (_ctWonLast) - { - int ctMoney = 3250; - int tMoney = 1400 + (Math.min(4,_winStreak) * 500); - - if (_bombPlanted) - { - ctMoney += 250; - tMoney += 800; - } - - //Award - for (Player player : GetTeam(ChatColor.RED).GetPlayers(false)) - _shopManager.addMoney(player, tMoney, "losing the round"); - - for (Player player : GetTeam(ChatColor.AQUA).GetPlayers(false)) - _shopManager.addMoney(player, ctMoney, "winning the round"); - } - else - { - int tMoney = 3250; - int ctMoney = 1400 + (Math.min(4,_winStreak) * 500); - - //Award - for (Player player : GetTeam(ChatColor.RED).GetPlayers(false)) - _shopManager.addMoney(player, tMoney, "winning the round"); - - for (Player player : GetTeam(ChatColor.AQUA).GetPlayers(false)) - _shopManager.addMoney(player, ctMoney, "losing the round"); - } - } - - public void resetGame() - { - //General - _roundOver = false; - SetStateTime(System.currentTimeMillis()); - _freezeTime = 10; - _winText = null; - - //Bomb - if (_bomb != null) - _bomb.clean(); - - if (_bombItem != null) - _bombItem.remove(); - - if (_bombHolder != null) - { - _bombHolder.getInventory().remove(Material.GOLD_SWORD); - _bombHolder = null; - } - - _bomb = null; - _bombItem = null; - - _bombPlanter = null; - _bombDefuser = null; - _bombPlantedBy = null; - _bombPlanted = false; - //Dropped Guns for (Entity ent : _gunsDropped.keySet()) ent.remove(); @@ -2309,84 +1235,7 @@ public class MineStrike extends TeamGame //Restock Ammo for (Gun gun : _gunsEquipped.keySet()) - gun.restockAmmo(_gunsEquipped.get(gun)); - - //Health - for (Player player : UtilServer.getPlayers()) - player.setHealth(20); - - //Reset Shop - for (Player player : UtilServer.getPlayers()) - _shopManager.leaveShop(player, false, false); - } - - @EventHandler(priority = EventPriority.HIGHEST) - public void specToTeam(PlayerJoinEvent event) - { - if (GetState() == GameState.Recruit || GetState() == GameState.Loading) - return; - - if (Manager.isVanished(event.getPlayer())) - { - return; - } - - //Target Team - GameTeam targetTeam = null; - if (GetTeamList().get(0).GetPlayers(false).size() < GetTeamList().get(1).GetPlayers(false).size()) - targetTeam = GetTeamList().get(0); - else if (GetTeamList().get(0).GetPlayers(false).size() > GetTeamList().get(1).GetPlayers(false).size()) - targetTeam = GetTeamList().get(1); - else if (Math.random() > 0.5) - targetTeam = GetTeamList().get(1); - else - targetTeam = GetTeamList().get(0); - - SetPlayerTeam(event.getPlayer(), targetTeam, false); - - ((CraftPlayer) event.getPlayer()).getHandle().spectating = true; - } - - @EventHandler(priority = EventPriority.HIGHEST) - public void quitLeaveTeam(PlayerQuitEvent event) - { - GameTeam team = GetTeam(event.getPlayer()); - - if (team != null) - { - team.RemovePlayer(event.getPlayer()); - } - } - - @EventHandler - public void restartFreezeCountdown(UpdateEvent event) - { - if (event.getType() != UpdateType.SEC) - return; - - if (_freezeTime <= 0) - return; - - _freezeTime--; - - for (Player player : UtilServer.getPlayers()) - { - if (_freezeTime > 0) - player.playSound(player.getLocation(), Sound.NOTE_STICKS, 1f, 1f); - else - player.playSound(player.getLocation(), Sound.NOTE_SNARE_DRUM, 1f, 1f); - } - - if (_freezeTime == 0) - { - //Give Bomb - Player bombPlayer = UtilAlg.Random(GetTeam(ChatColor.RED).GetPlayers(true)); - giveBombToPlayer(bombPlayer); - - //Sound - playSound(Radio.CT_START, null, GetTeam(ChatColor.AQUA)); - playSound(Radio.T_START, null, GetTeam(ChatColor.RED)); - } + gun.restockAmmo(_gunsEquipped.get(gun)); } @EventHandler @@ -2395,7 +1244,7 @@ public class MineStrike extends TeamGame if (_freezeTime <= 0) return; - if (!IsAlive(event.getPlayer())) + if (!_host.IsAlive(event.getPlayer())) return; if (UtilMath.offset2d(event.getFrom(), event.getTo()) <= 0) @@ -2410,13 +1259,13 @@ public class MineStrike extends TeamGame //@EventHandler public void boostClimb(PlayerToggleSneakEvent event) { - if (!IsLive()) + if (!_host.IsLive()) return; Player player = event.getPlayer(); boolean nearOther = false; - for (Player other : GetPlayers(true)) + for (Player other : _host.GetPlayers(true)) { if (player.equals(other)) continue; @@ -2451,7 +1300,7 @@ public class MineStrike extends TeamGame @EventHandler(priority = EventPriority.MONITOR) public void scopeUpdate(PlayerToggleSneakEvent event) { - if (!IsLive()) + if (!_host.IsLive()) return; Gun gun = getGunInHand(event.getPlayer(), null); @@ -2482,17 +1331,17 @@ public class MineStrike extends TeamGame removeScope(event.getPlayer()); } } - + @EventHandler public void scopeUpdate(UpdateEvent event) { - if (!IsLive()) + if (!_host.IsLive()) return; if (event.getType() != UpdateType.TICK) return; - - for (Player player : GetPlayers(true)) + + for (Player player : _host.GetPlayers(true)) { if (!_scoped.containsKey(player)) continue; @@ -2524,13 +1373,13 @@ public class MineStrike extends TeamGame //@EventHandler public void speedUpdate(UpdateEvent event) { - if (!IsLive()) + if (!_host.IsLive()) return; if (event.getType() != UpdateType.TICK) return; - for (Player player : GetPlayers(true)) + for (Player player : _host.GetPlayers(true)) { if (UtilGear.isMat(player.getItemInHand(), Material.IRON_AXE) || UtilGear.isMat(player.getItemInHand(), Material.IRON_SWORD)) Manager.GetCondition().Factory().Speed("Knife", player, player, 1.9, 0, false, false, false); @@ -2566,7 +1415,7 @@ public class MineStrike extends TeamGame @EventHandler public void gunUpdate(UpdateEvent event) { - if (!IsLive()) + if (!_host.IsLive()) return; if (event.getType() != UpdateType.TICK) @@ -2623,143 +1472,20 @@ public class MineStrike extends TeamGame } } - @Override - @EventHandler - public void ScoreboardUpdate(UpdateEvent event) - { - if (event != null && event.getType() != UpdateType.FAST) - return; - - drawScoreboard(); - } - - public void drawScoreboard() - { - Scoreboard.Reset(); - - for (GameTeam team : this.GetTeamList()) - { - - Scoreboard.WriteBlank(); - - Scoreboard.Write(getScore(team) + " " + team.GetColor() + C.Bold + team.GetName()); - //Scoreboard.Write(team.GetColor() + "" + getScore(team) + "" + " Wins" + team.GetColor()); - Scoreboard.Write(team.GetPlayers(true).size() + "" + " Alive" + team.GetColor()); - - } - - Scoreboard.WriteBlank(); - Scoreboard.Write(C.cGold + C.Bold + "Playing To"); - Scoreboard.Write(_roundsToWin + " Wins"); - - if (InProgress()) - { - Scoreboard.WriteBlank(); - - if (_bomb == null) - { - Scoreboard.Write(C.cGold + C.Bold + "Time Left"); - Scoreboard.Write(UtilTime.MakeStr(_roundTime - (System.currentTimeMillis() - this.GetStateTime()), 1)); - } - else - { - if (_bombScoreboardFlash) - Scoreboard.Write(C.cRed + C.Bold + "Bomb Active"); - else - Scoreboard.Write(C.cWhite + C.Bold + "Bomb Active"); - - _bombScoreboardFlash = !_bombScoreboardFlash; - } - } - - - Scoreboard.Draw(); - } - - @Override - public void EndCheck() - { - endCheckScore(); - endCheckPlayer(); - } - - public void endCheckScore() - { - if (!IsLive()) - return; - - for (GameTeam team : GetTeamList()) - { - if (getScore(team) >= _roundsToWin) - { - //Announce - AnnounceEnd(team); - - for (GameTeam other : GetTeamList()) - { - if (WinnerTeam != null && other.equals(WinnerTeam)) - { - for (Player player : other.GetPlayers(false)) - AddGems(player, 10, "Winning Team", false, false); - } - - for (Player player : other.GetPlayers(false)) - if (player.isOnline()) - AddGems(player, 10, "Participation", false, false); - } - - //End - SetState(GameState.End); - } - } - } - - public void endCheckPlayer() - { - if (!IsLive()) - return; - - ArrayList teamsAlive = new ArrayList(); - - for (GameTeam team : this.GetTeamList()) - if (team.GetPlayers(false).size() > 0) - teamsAlive.add(team); - - if (teamsAlive.size() <= 1) - { - //Announce - if (teamsAlive.size() > 0) - AnnounceEnd(teamsAlive.get(0)); - - for (GameTeam team : GetTeamList()) - { - if (WinnerTeam != null && team.equals(WinnerTeam)) - { - for (Player player : team.GetPlayers(false)) - AddGems(player, 10, "Winning Team", false, false); - } - - for (Player player : team.GetPlayers(false)) - if (player.isOnline()) - AddGems(player, 10, "Participation", false, false); - } - - //End - SetState(GameState.End); - } - } - //Cleans entities that may not have been removed due to unloaded chunks @EventHandler public void clean(UpdateEvent event) { - if (!IsLive()) + if(!EnableCleaning) + return; + + if (!_host.IsLive()) return; if (event.getType() != UpdateType.SEC) return; - for (Entity ent : WorldData.World.getEntities()) + for (Entity ent : _host.WorldData.World.getEntities()) { if (ent instanceof Player) continue; @@ -2821,7 +1547,7 @@ public class MineStrike extends TeamGame @EventHandler public void terroristCompass(UpdateEvent event) { - if (!IsLive()) + if (!_host.IsLive()) return; if (event.getType() != UpdateType.TICK) @@ -2835,7 +1561,10 @@ public class MineStrike extends TeamGame else if (_bomb != null) target = _bomb.Block.getLocation(); - for (Player player : GetTeam(ChatColor.RED).GetPlayers(true)) + if (_host.GetTeam(ChatColor.RED) == null) + return; + + for (Player player : _host.GetTeam(ChatColor.RED).GetPlayers(true)) { //Has Bomb if (player.getInventory().contains(Material.GOLD_SWORD)) @@ -2883,41 +1612,18 @@ public class MineStrike extends TeamGame player.getInventory().setItem(8, stack); } } - - @EventHandler - public void healthUpdate(UpdateEvent event) - { - if (!IsLive()) - return; - - if (event.getType() != UpdateType.SEC) - return; - - for (Player player : UtilServer.getPlayers()) - _scoreObj.getScore(player.getName()).setScore((int)(player.getHealth() * 5)); - } - - @EventHandler(priority = EventPriority.MONITOR) - public void damageHealth(CustomDamageEvent event) - { - Player player = event.GetDamagerPlayer(true); - if (player == null) - return; - - _scoreObj.getScore(player.getName()).setScore((int)(player.getHealth() * 5)); - } @EventHandler public void fireDamage(CustomDamageEvent event) { if (event.GetCause() == DamageCause.FIRE) - event.AddMod(this.GetName(), "Fire", 1, false); + event.AddMod(_host.GetName(), "Fire", 1, false); } @EventHandler public void teleportCancel(PlayerTeleportEvent event) { - if (!IsLive()) + if (!_host.IsLive()) return; if (event.getCause() == TeleportCause.ENDER_PEARL) @@ -2926,7 +1632,7 @@ public class MineStrike extends TeamGame public int getBulletType() { - return _bulletInstant; + return BulletInstant; } public void playSound(Radio radio, Player player, GameTeam team) @@ -2943,7 +1649,7 @@ public class MineStrike extends TeamGame } else if (player != null) { - GameTeam playerTeam = GetTeam(player); + GameTeam playerTeam = _host.GetTeam(player); if (playerTeam == null) return; @@ -2956,20 +1662,16 @@ public class MineStrike extends TeamGame public void debug(PlayerCommandPreprocessEvent event) { if (!event.getPlayer().isOp()) - return; - - if (event.getMessage().contains("money")) { - _shopManager.addMoney(event.getPlayer(), 16000, "Debug"); - event.setCancelled(true); + return; } if (event.getMessage().contains("recoil")) { try { - MineStrike.RECOIL = Float.parseFloat(event.getMessage().split(" ")[1]); - this.Announce(C.cPurple + C.Bold + "Recoil Bloom: " + ChatColor.RESET + (int)(MineStrike.RECOIL * 100) + "%"); + RECOIL = Float.parseFloat(event.getMessage().split(" ")[1]); + _host.Announce(C.cPurple + C.Bold + "Recoil Bloom: " + ChatColor.RESET + (int)(RECOIL * 100) + "%"); } catch (Exception e) { @@ -2982,8 +1684,8 @@ public class MineStrike extends TeamGame { try { - MineStrike.CONE = Float.parseFloat(event.getMessage().split(" ")[1]); - this.Announce(C.cPurple + C.Bold + "Cone of Fire: " + ChatColor.RESET + (int)(MineStrike.CONE * 100) + "%"); + CONE = Float.parseFloat(event.getMessage().split(" ")[1]); + _host.Announce(C.cPurple + C.Bold + "Cone of Fire: " + ChatColor.RESET + (int)(CONE * 100) + "%"); } catch (Exception e) { @@ -2996,8 +1698,8 @@ public class MineStrike extends TeamGame { try { - MineStrike.MOVE_PENALTY = Float.parseFloat(event.getMessage().split(" ")[1]); - this.Announce(C.cPurple + C.Bold + "Move/Sprint/Jump Penalties: " + ChatColor.RESET + (int)(MineStrike.MOVE_PENALTY * 100) + "%"); + MOVE_PENALTY = Float.parseFloat(event.getMessage().split(" ")[1]); + _host.Announce(C.cPurple + C.Bold + "Move/Sprint/Jump Penalties: " + ChatColor.RESET + (int)(MOVE_PENALTY * 100) + "%"); } catch (Exception e) { @@ -3008,14 +1710,14 @@ public class MineStrike extends TeamGame if (event.getMessage().contains("instant")) { - _bulletInstant = (_bulletInstant + 1)%3; + BulletInstant = (BulletInstant + 1)%3; - if (_bulletInstant == 0) - Announce(C.cPurple + C.Bold + "Bullets: " + ChatColor.RESET + "Slow and Visible"); - else if (_bulletInstant == 1) - Announce(C.cPurple + C.Bold + "Bullets: " + ChatColor.RESET + "Instant and Invisible"); + if (BulletInstant == 0) + _host.Announce(C.cPurple + C.Bold + "Bullets: " + ChatColor.RESET + "Slow and Visible"); + else if (BulletInstant == 1) + _host.Announce(C.cPurple + C.Bold + "Bullets: " + ChatColor.RESET + "Instant and Invisible"); else - Announce(C.cPurple + C.Bold + "Bullets: " + ChatColor.RESET + "Slow and Visible with Instant Sniper"); + _host.Announce(C.cPurple + C.Bold + "Bullets: " + ChatColor.RESET + "Slow and Visible with Instant Sniper"); event.setCancelled(true); @@ -3023,48 +1725,48 @@ public class MineStrike extends TeamGame if (event.getMessage().contains("hitbox")) { - _customHitbox = !_customHitbox; + CustomHitbox = !CustomHitbox; - if (_customHitbox) - Announce(C.cPurple + C.Bold + "Hitbox: " + ChatColor.RESET + "Accurate with Headshots"); + if (CustomHitbox) + _host.Announce(C.cPurple + C.Bold + "Hitbox: " + ChatColor.RESET + "Accurate with Headshots"); else - Announce(C.cPurple + C.Bold + "Hitbox: " + ChatColor.RESET + "Default with No Headshot"); + _host.Announce(C.cPurple + C.Bold + "Hitbox: " + ChatColor.RESET + "Default with No Headshot"); event.setCancelled(true); } if (event.getMessage().contains("alternate")) { - _bulletAlternate = !_bulletAlternate; + BulletAlternate = !BulletAlternate; - Announce(C.cPurple + C.Bold + "Alternate Bullet Type: " + ChatColor.RESET + _bulletAlternate); + _host.Announce(C.cPurple + C.Bold + "Alternate Bullet Type: " + ChatColor.RESET + BulletAlternate); event.setCancelled(true); } if (event.getMessage().contains("god")) { - if (HealthSet == 20) - HealthSet = -1; + if (_host.HealthSet == 20) + _host.HealthSet = -1; else - HealthSet = 20; + _host.HealthSet = 20; - Announce(C.cPurple + C.Bold + "God Mode: " + ChatColor.RESET + (HealthSet == 20)); + _host.Announce(C.cPurple + C.Bold + "God Mode: " + ChatColor.RESET + (_host.HealthSet == 20)); event.setCancelled(true); } if (event.getMessage().contains("debugplayer")) { - Announce(C.Bold + "PLAYER DEBUG:"); + _host.Announce(C.Bold + "PLAYER DEBUG:"); for (Player player : UtilServer.getPlayers()) { - GameTeam team = GetTeam(player); + GameTeam team = _host.GetTeam(player); - Announce(player.getName() + " " + + _host.Announce(player.getName() + " " + (team != null ? team.GetColor() + team.GetName() : C.cGray + "No Team") + " " + - (IsAlive(player) ? C.cGreen + "ALIVE" : C.cRed + "DEAD") + " " + + (_host.IsAlive(player) ? C.cGreen + "ALIVE" : C.cRed + "DEAD") + " " + C.cGray + UtilWorld.locToStrClean(player.getLocation()) ); } @@ -3074,14 +1776,14 @@ public class MineStrike extends TeamGame if (event.getMessage().contains("debugteam")) { - Announce(C.Bold + "TEAM DEBUG:"); + _host.Announce(C.Bold + "TEAM DEBUG:"); - for (GameTeam team : GetTeamList()) + for (GameTeam team : _host.GetTeamList()) for (Player player : team.GetPlayers(false)) { - Announce(player.getName() + " " + + _host.Announce(player.getName() + " " + (team != null ? team.GetColor() + team.GetName() : C.cGray + "No Team") + " " + - (IsAlive(player) ? C.cGreen + "ALIVE" : C.cRed + "DEAD") + " " + + (_host.IsAlive(player) ? C.cGreen + "ALIVE" : C.cRed + "DEAD") + " " + C.cGray + UtilWorld.locToStrClean(player.getLocation()) ); } @@ -3090,17 +1792,6 @@ public class MineStrike extends TeamGame } } - //Used for fire grenade spread - public int getRound() - { - int rounds = 0; - - for (int i : _score.values()) - rounds += i; - - return rounds; - } - public boolean isFreezeTime() { return _freezeTime > 0; @@ -3112,7 +1803,7 @@ public class MineStrike extends TeamGame // This is an extra event added in order to prevent players from // extinguishing fire that gets generated from moltovs and incendiary grenades. - if (!IsLive()) + if (!_host.IsLive()) return; if (UtilEvent.isAction(event, ActionType.L_BLOCK)) @@ -3162,77 +1853,12 @@ public class MineStrike extends TeamGame _bombItem.setPickupDelay(60); //Radio - playSound(Radio.T_BOMB_DROP, null, GetTeam(_bombHolder)); + playSound(Radio.T_BOMB_DROP, null, _host.GetTeam(_bombHolder)); _bombHolder = null; } } - @Override - public Location GetSpectatorLocation() - { - if (SpectatorSpawn != null) - return SpectatorSpawn; - - Vector vec = new Vector(0, 0, 0); - double count = 0; - - for (GameTeam team : this.GetTeamList()) - { - for (Location spawn : team.GetSpawns()) - { - count++; - vec.add(spawn.toVector()); - } - } - - SpectatorSpawn = new Location(this.WorldData.World, 0, 0, 0); - - vec.multiply(1d / count); - - SpectatorSpawn.setX(vec.getX()); - SpectatorSpawn.setY(vec.getY() + 7); //ADD 7 - SpectatorSpawn.setZ(vec.getZ()); - - // Move Up - Out Of Blocks - while (!UtilBlock.airFoliage(SpectatorSpawn.getBlock()) - || !UtilBlock.airFoliage(SpectatorSpawn.getBlock().getRelative(BlockFace.UP))) - { - SpectatorSpawn.add(0, 1, 0); - } - - int Up = 0; - - // Move Up - Through Air - for (int i = 0; i < 15; i++) - { - if (UtilBlock.airFoliage(SpectatorSpawn.getBlock().getRelative(BlockFace.UP))) - { - SpectatorSpawn.add(0, 1, 0); - Up++; - } - else - { - break; - } - } - - // Move Down - Out Of Blocks - while (Up > 0 && !UtilBlock.airFoliage(SpectatorSpawn.getBlock()) - || !UtilBlock.airFoliage(SpectatorSpawn.getBlock().getRelative(BlockFace.UP))) - { - SpectatorSpawn.subtract(0, 1, 0); - Up--; - } - - SpectatorSpawn = SpectatorSpawn.getBlock().getLocation().add(0.5, 0.1, 0.5); - - while (SpectatorSpawn.getBlock().getTypeId() != 0 || SpectatorSpawn.getBlock().getRelative(BlockFace.UP).getTypeId() != 0) - SpectatorSpawn.add(0, 1, 0); - - return SpectatorSpawn; - } - @EventHandler public void enableScpResPack(PlayerCommandPreprocessEvent event) { @@ -3251,4 +1877,160 @@ public class MineStrike extends TeamGame UtilPlayer.message(event.getPlayer(), F.main("Resource Pack", "Type " + F.elem("/rpoff") + " to disable.")); } } + + public void giveBombToPlayer(Player player) + { + if (player == null) + return; + + GameTeam team = _host.GetTeam(player); + if (team == null) + return; + + if (team.GetColor() != ChatColor.RED) + return; + + //Bomb + player.getInventory().setItem(8, ItemStackFactory.Instance.CreateStack(Material.GOLD_SWORD, (byte)0, 1, C.cGold + C.Bold + "C4 Explosive")); + + //Inform + if (!_host.IsLive() || _freezeTime > 0) + { + for (Player other : team.GetPlayers(false)) + if (!other.equals(player)) + { + UtilTextMiddle.display(null, player.getName() + " has the Bomb", 10, 80, 10, other); + UtilPlayer.message(other, C.cGold + C.Bold + player.getName() + " has the Bomb!"); + } + + //Chat + UtilPlayer.message(player, C.cGold + C.Bold + "You have the Bomb!"); + UtilPlayer.message(player, C.cGold + C.Bold + "Hold Right-Click to place at a Bomb Site!"); + + //Title + UtilTextMiddle.display(C.cRed + "You have the Bomb", "Hold Right-Click to place at a Bomb Site!", 10, 80, 10, player); + } + else + { + for (Player other : team.GetPlayers(false)) + if (!other.equals(player)) + { + UtilPlayer.message(other, C.cGold + C.Bold + player.getName() + " picked up the Bomb!"); + + //Title + UtilTextMiddle.display(null, player.getName() + " picked up the Bomb", 10, 50, 10, other); + } + + + //Chat + UtilPlayer.message(player, C.cGold + C.Bold + "You picked up the Bomb!"); + + //Title + UtilTextMiddle.display(null, "You picked up the Bomb", 10, 50, 10, player); + } + + + player.playSound(player.getLocation(), Sound.NOTE_PLING, 1f, 2f); + _bombHolder = player; + _bombHolderLastMove = System.currentTimeMillis(); + + if (_bombItem != null) + { + _bombItem.remove(); + _bombItem = null; + } + } + + public void undisguise(Player player) + { + _disguise.remove(player); + } + + public Player getBombHolder() + { + return _bombHolder; + } + + public void setBombHolder(Player player) + { + _bombHolder = player; + } + + public Bomb getBomb() + { + return _bomb; + } + + public void setBomb(Bomb bomb) + { + _bomb = bomb; + } + + public Item getBombItem() + { + return _bombItem; + } + + public void setBombItem(Item bomb) + { + _bombItem = bomb; + } + + public long getFreezeTime() + { + return _freezeTime; + } + + public void setFreezeTime(long time) + { + _freezeTime = time; + } + + public int getRound() + { + if (_host instanceof Minestrike) + return ((Minestrike) _host).getRound(); + + return _round; + } + + public void setRound(int round) + { + _round = round; + } + + public void setEnablePickup(boolean pickup) + { + EnablePickup = pickup; + } + + public void setEnableDrop(boolean drop) + { + EnableDrop = drop; + } + + public void setEnableCleaning(boolean cleaning) + { + EnableCleaning = cleaning; + } + + public Game getHost() + { + return _host; + } + + public HashMap getDroppedGuns() + { + return _gunsDropped; + } + + public HashMap getDroppedGrenades() + { + return _grenadesDropped; + } + + public HashMap getScoped() + { + return _scoped; + } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/Minestrike.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/Minestrike.java new file mode 100644 index 000000000..862ead445 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/Minestrike.java @@ -0,0 +1,1347 @@ +package nautilus.game.arcade.game.games.minestrike; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Color; +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.craftbukkit.v1_8_R3.entity.CraftPlayer; +import org.bukkit.entity.Entity; +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.inventory.InventoryClickEvent; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.LeatherArmorMeta; +import org.bukkit.scoreboard.DisplaySlot; +import org.bukkit.scoreboard.NameTagVisibility; +import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.Team; +import org.bukkit.util.Vector; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.util.UtilEnt; +import mineplex.core.common.util.UtilEvent; +import mineplex.core.common.util.UtilGear; +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.UtilTime; +import mineplex.core.common.util.UtilEvent.ActionType; +import mineplex.core.gadget.GadgetManager; +import mineplex.core.gadget.gadgets.gamemodifiers.GameModifierType; +import mineplex.core.gadget.gadgets.gamemodifiers.minestrike.GameModifierMineStrikeSkin; +import mineplex.core.itemstack.ItemStackFactory; +import mineplex.core.recharge.Recharge; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.minecraft.game.core.combat.event.CombatDeathEvent; +import mineplex.minecraft.game.core.condition.Condition.ConditionType; +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.events.PlayerKitGiveEvent; +import nautilus.game.arcade.game.GameTeam; +import nautilus.game.arcade.game.TeamGame; +import nautilus.game.arcade.game.GameTeam.PlayerState; +import nautilus.game.arcade.game.games.minestrike.GunModule.RoundOverEvent; +import nautilus.game.arcade.game.games.minestrike.data.Bomb; +import nautilus.game.arcade.game.games.minestrike.items.guns.Gun; +import nautilus.game.arcade.game.games.minestrike.items.guns.GunStats; +import nautilus.game.arcade.game.games.minestrike.kits.KitPlayer; +import nautilus.game.arcade.kit.Kit; +import nautilus.game.arcade.managers.chat.ChatStatData; +import nautilus.game.arcade.stats.KaboomStatTracker; +import nautilus.game.arcade.stats.KillAllOpposingMineStrikeRoundStatTracker; +import nautilus.game.arcade.stats.KillFastStatTracker; +import nautilus.game.arcade.stats.KillReasonStatTracker; +import nautilus.game.arcade.stats.KillsWithConditionStatTracker; +import nautilus.game.arcade.stats.MineStrikeGunStats; +import nautilus.game.arcade.stats.MineStrikeLastAliveKillStatTracker; +import nautilus.game.arcade.stats.TeamDeathsStatTracker; +import nautilus.game.arcade.stats.TeamKillsStatTracker; + +/** + * Minestrike + * + * @author xXVevzZXx + */ +public class Minestrike extends TeamGame +{ + + //Managers + private ShopManager _shopManager; + + //Data + private int _roundsToWin = 8; + private long _roundTime = 120000; + + //Round Data + private String _winText = null; + private boolean _roundOver = false; + + //Money Data + private boolean _bombPlanted = false; + private boolean _ctWonLast = false; + private int _winStreak = 0; + + private HashMap _score = new HashMap(); + + //Map Data + private ArrayList _bombSites; + + private Player _bombPlanter; + private Player _bombDefuser; + private Player _bombPlantedBy; + + private boolean _bombScoreboardFlash = false; + + private GunModule _gunModule; + + //Scoreboard + private Objective _scoreObj; + + public Minestrike(ArcadeManager manager) + { + super(manager, GameType.MineStrike, + + new Kit[] + { + new KitPlayer(manager), + }, + + new String[] + { + C.cAqua + "SWAT" + C.cWhite + " Defend the Bomb Sites", + C.cAqua + "SWAT" + C.cWhite + " Kill the Bombers", + " ", + C.cRed + "Bombers" + C.cWhite + " Plant the Bomb at Bomb Site", + C.cRed + "Bombers" + C.cWhite + " Kill the SWAT Team", + }); + + _shopManager = new ShopManager(this); + Manager.getCosmeticManager().setHideParticles(true); + + this.StrictAntiHack = true; + + AnnounceStay = false; + + this.HungerSet = 20; + + this.ItemDrop = true; + + this.DeathTeleport = false; + + this.InventoryClick = true; + + this.JoinInProgress = true; + + this.DontAllowOverfill = true; + + _scoreObj = Scoreboard.GetScoreboard().registerNewObjective("HP", "dummy"); + _scoreObj.setDisplaySlot(DisplaySlot.BELOW_NAME); + + this._help = new String[] + { + //"Tap Crouch when close to an ally to Boost", + "Open Inventory at spawn to buy guns", + "Hold Right-Click to Plant Bomb", + "Look at the Bomb to Defuse it", + "Moving decreases accuracy", + "Sprinting heavily decreases accuracy", + "Jumping massively decreases accuracy", + "Crouching increases accuracy", + "Left-Click to drop Grenades", + "Right-Click to throw Grenades", + "Burst Fire for greater accuracy", + "Sniper Rifles are only accurate while scoped", + "Rifles have 30% recoil reduction while scoped", + "Pick up better weapons from dead players" + }; + + registerStatTrackers( + new KillReasonStatTracker(this, "Headshot", "BoomHeadshot", true), + new KillAllOpposingMineStrikeRoundStatTracker(this), + new KaboomStatTracker(this), + new KillReasonStatTracker(this, "Backstab", "Assassination", false), + new MineStrikeLastAliveKillStatTracker(this), + new KillFastStatTracker(this, 4, 5, "KillingSpree"), + new KillsWithConditionStatTracker(this, "Blindfolded", ConditionType.BLINDNESS, "Flash Bang", 2), + + new TeamDeathsStatTracker(this), + new TeamKillsStatTracker(this), + + new MineStrikeGunStats(this) + ); + + registerChatStats( + Kills, + Deaths, + KDRatio, + BlankLine, + new ChatStatData("BoomHeadshot", "Headshots", true), + Assists + ); + + _gunModule = new GunModule(this); + } + + @EventHandler + public void CustomTeamGeneration(GameStateChangeEvent event) + { + if (event.GetState() != GameState.Recruit) + return; + + this.GetTeamList().get(0).SetColor(ChatColor.AQUA); + this.GetTeamList().get(0).SetName("SWAT"); + + this.GetTeamList().get(1).SetColor(ChatColor.RED); + this.GetTeamList().get(1).SetName("Bombers"); + } + + @EventHandler + public void SetScoreboardNameVisibility(GameStateChangeEvent event) + { + if (event.GetState() != GameState.Prepare) + return; + + System.out.println("Hiding Scoreboard Nametags for Other Teams"); + for (Team curTeam : Scoreboard.GetScoreboard().getTeams()) + { + curTeam.setNameTagVisibility(NameTagVisibility.HIDE_FOR_OTHER_TEAMS); + //UtilServer.getServer().dispatchCommand(UtilServer.getServer().getConsoleSender(), + // "scoreboard teams option " + curTeam.getName() + " nametagVisibility hideForOtherTeams"); + } + } + + @Override + public void ParseData() + { + _bombSites = WorldData.GetDataLocs("RED"); + } + + @EventHandler + public void giveStartEquipment(PlayerKitGiveEvent event) + { + GameTeam team = GetTeam(event.getPlayer()); + if (team == null) + return; + + GadgetManager gadgetManager = Manager.getCosmeticManager().getGadgetManager(); + GameModifierMineStrikeSkin knifeSkin = (GameModifierMineStrikeSkin) gadgetManager.getActiveGameModifier(event.getPlayer(), + GameModifierType.MineStrike, GameModifierMineStrikeSkin.getWeaponFilter("Knife")); + + Material mat = Material.IRON_AXE; + byte data = 0; + String name = "Knife"; + + if(knifeSkin != null) + { + mat = knifeSkin.getSkinMaterial(); + data = knifeSkin.getSkinData(); + name = knifeSkin.getName(); + } + + ItemStack knife = ItemStackFactory.Instance.CreateStack(mat, data, 1, name); + + if (team.GetColor() == ChatColor.RED) + { + if (IsAlive(event.getPlayer())) + { + //Pistol + Gun gun = new Gun(GunStats.GLOCK_18, _gunModule); + _gunModule.registerGun(gun, event.getPlayer()); + gun.giveToPlayer(event.getPlayer(), true); + gun.updateSkin(event.getPlayer(), getArcadeManager().getCosmeticManager().getGadgetManager()); + gun.updateWeaponName(event.getPlayer(), _gunModule); + + //Knife + if(knifeSkin == null) knife.setType(Material.IRON_AXE); + + event.getPlayer().getInventory().setItem(2, knife); + + //Armor + giveTeamArmor(event.getPlayer(), Color.fromRGB(255, 75, 75)); + } + } + else if (team.GetColor() == ChatColor.AQUA) + { + if (IsAlive(event.getPlayer())) + { + //Pistol + Gun gun = new Gun(GunStats.P2000, _gunModule); + _gunModule.registerGun(gun, event.getPlayer()); + gun.giveToPlayer(event.getPlayer(), true); + gun.updateWeaponName(event.getPlayer(), _gunModule); + gun.updateSkin(event.getPlayer(), getArcadeManager().getCosmeticManager().getGadgetManager()); + + //Knife + if(knifeSkin == null) knife.setType(Material.IRON_SWORD); + + event.getPlayer().getInventory().setItem(2, knife); + + //Armor + giveTeamArmor(event.getPlayer(), Color.fromRGB(125, 200, 255)); + } + } + + //Enter Shop + _shopManager.enterShop(event.getPlayer()); + } + + public void giveTeamArmor(Player player, Color color) + { + ItemStack armor = new ItemStack(Material.LEATHER_CHESTPLATE); + LeatherArmorMeta meta = (LeatherArmorMeta)armor.getItemMeta(); + meta.setColor(color); + armor.setItemMeta(meta); + player.getInventory().setChestplate(armor); + + ItemStack legs = new ItemStack(Material.LEATHER_LEGGINGS); + LeatherArmorMeta metaLegs = (LeatherArmorMeta)legs.getItemMeta(); + metaLegs.setColor(color); + legs.setItemMeta(metaLegs); + player.getInventory().setLeggings(legs); + + ItemStack boots = new ItemStack(Material.LEATHER_BOOTS); + LeatherArmorMeta metaBoots = (LeatherArmorMeta)boots.getItemMeta(); + metaBoots.setColor(color); + boots.setItemMeta(metaBoots); + player.getInventory().setBoots(boots); + } + + @EventHandler + public void shopInventoryClick(InventoryClickEvent event) + { + _shopManager.inventoryClick(event); + } + + @EventHandler + public void shopUpdate(UpdateEvent event) + { + if (event.getType() != UpdateType.SEC) + return; + + _shopManager.update(); + } + + @EventHandler + public void quitClean(PlayerQuitEvent event) + { + _shopManager.leaveShop(event.getPlayer(), false, true); + _gunModule.undisguise(event.getPlayer()); + _gunModule.removeScope(event.getPlayer()); + _gunModule.dropInventory(event.getPlayer()); + } + + @EventHandler + public void giveBombInitial(GameStateChangeEvent event) + { + if (event.GetState() != GameState.Prepare) + return; + + UtilServer.getServer().getScheduler().scheduleSyncDelayedTask(Manager.getPlugin(), new Runnable() + { + public void run() + { + Player player = UtilAlg.Random(GetTeam(ChatColor.RED).GetPlayers(true)); + + _gunModule.giveBombToPlayer(player); + } + }, 40); + } + + + @EventHandler + public void killReward(CombatDeathEvent event) + { + if (!(event.GetEvent().getEntity() instanceof Player)) + return; + + Player killed = (Player)event.GetEvent().getEntity(); + + if (event.GetLog().GetKiller() != null) + { + Player killer = UtilPlayer.searchExact(event.GetLog().GetKiller().GetName()); + + if (killer == null || killer.equals(killed)) + return; + + if (GetTeam(killed).equals(GetTeam(killer))) + return; + + int amount = 300; + + if (event.GetLog().GetLastDamager().GetReason().contains("AWP")) + amount = 100; + + else if (event.GetLog().GetLastDamager().GetReason().contains("PP-Bizon")) + amount = 600; + + else if (event.GetLog().GetLastDamager().GetReason().contains("Nova")) + amount = 900; + + else if (event.GetLog().GetLastDamager().GetReason().contains("Knife")) + amount = 1500; + + _shopManager.addMoney(killer, amount, "kill with " + event.GetLog().GetLastDamager().GetReason()); + + /* + if(event.GetLog().GetLastDamager().GetReason().contains("Knife")) + { + GadgetManager gadgetManager = Manager.getCosmeticManager().getGadgetManager(); + GameModifierMineStrikeSkin knifeSkin = (GameModifierMineStrikeSkin) gadgetManager.getActiveGameModifier(event.getPlayer(), + GameModifierType.MineStrike, GameModifierMineStrikeSkin.getWeaponFilter("Knife")); + + if(knifeSkin != null) + { + int kills = GetStats().get(killer).get("") + ItemStack item = killer.getInventory().getItem(2); + ItemMeta im = item.getItemMeta(); + im.setDisplayName(C.cYellow + C.Bold + knifeSkin.GetName() + " - Kills: " + kills); + + AddStat(killer, "Knife." + knifeSkin.GetName() + ".Kills", 1, false, false); + } + } + */ + } + } + + @EventHandler + public void plantBomb(PlayerInteractEvent event) + { + Player player = event.getPlayer(); + + if (!UtilGear.isMat(player.getItemInHand(), Material.GOLD_SWORD)) + return; + + // Fixed bomb able to be planted after the round is over. + if (_roundOver) + { + UtilPlayer.message(player, F.main("Game", "You cannot plant the bomb once the round is over.")); + event.setCancelled(true); + return; + } + + // Added a small tip for players that are trying to right-click with the bomb. + if (UtilEvent.isAction(event, ActionType.L)) + { + UtilPlayer.message(player, F.main("Game", "You must " + F.elem("Right-Click") + " while holding the bomb to plant it.")); + event.setCancelled(true); + return; + } + + if (!UtilEnt.isGrounded(player)) + { + UtilPlayer.message(player, F.main("Game", "You can only plant the bomb on the ground.")); + event.setCancelled(true); + return; + } + + //Should never occur with 1 Bomb + if (_bombPlanter != null) + { + UtilPlayer.message(player, F.main("Game", "Someone else is planting the bomb.")); + event.setCancelled(true); + return; + } + + //Check Bomb Sites + boolean near = false; + for (Location loc : _bombSites) + { + if (UtilMath.offset(player.getLocation(), loc) < 5) + { + near = true; + break; + } + } + + //Too Far + if (!near) + { + UtilPlayer.message(player, F.main("Game", "You can only plant the bomb at a bomb site.")); + event.setCancelled(true); + return; + } + + _bombPlanter = player; + _bombPlanter.setExp(0f); + + UtilPlayer.message(player, F.main("Game", "You are now placing the bomb.")); + + //Radio + _gunModule.playSound(Radio.T_BOMB_PLANT, null, GetTeam(_bombPlanter)); + } + + @EventHandler + public void plantBombUpdate(UpdateEvent event) + { + if (event.getType() != UpdateType.TICK) + return; + + // Added to check if the round is over when a bomb is being planted. + if (_roundOver) + return; + + if (_bombPlanter == null) + return; + + if (!_bombPlanter.isBlocking() || !_bombPlanter.isOnline()) + { + _bombPlanter.setExp(0f); + UtilTextMiddle.clear(_bombPlanter); + _bombPlanter = null; + return; + } + + _bombPlanter.setExp(Math.min(_bombPlanter.getExp() + 0.017f, 0.99999f)); + + if (Math.random() > 0.90) + _bombPlanter.getWorld().playSound(_bombPlanter.getLocation(), Sound.NOTE_PLING, 2f, 3f); + + UtilTextMiddle.display(C.cRed + C.Bold + "Planting Bomb", UtilTextMiddle.progress(_bombPlanter.getExp()), 0, 10, 0, _bombPlanter); + + if (_bombPlanter.getExp() >= 0.98f) + { + _gunModule.setBomb(new Bomb(_bombPlanter)); + + _shopManager.addMoney(_bombPlanter, 300, "planting the bomb"); + + Announce(C.cRed + C.Bold + _bombPlanter.getName() + " has planted the bomb!"); + + _bombPlantedBy = _bombPlanter; + + _bombPlanter.setExp(0f); + _bombPlanter.setItemInHand(null); + _bombPlanter = null; + _gunModule.setBombHolder(null); + + //Sound + _gunModule.playSound(Radio.BOMB_PLANT, null, null); + + //Title + UtilTextMiddle.display(null, C.cRed + C.Bold + "Bomb has been planted!", 10, 50, 10); + } + } + + @EventHandler + public void plantDefuseBombRestrictMovement(PlayerMoveEvent event) + { + if (_bombPlanter != null && _bombPlanter.equals(event.getPlayer())) + if (UtilMath.offset(event.getFrom(), event.getTo()) > 0) + event.setTo(event.getFrom()); + + // if (_bombDefuser != null && _bombDefuser.equals(event.getPlayer())) + // if (UtilMath.offset(event.getFrom(), event.getTo()) > 0) + // event.setTo(event.getFrom()); + } + + @EventHandler + public void defuseKitMessage(PlayerInteractEvent event) + { + Player player = event.getPlayer(); + + if (!UtilGear.isMat(player.getItemInHand(), Material.SHEARS)) + return; + + UtilPlayer.message(player, F.main("Game", "Look at the Bomb to defuse it.")); + } + + public void startDefuse() + { + for (Player player : GetTeam(ChatColor.AQUA).GetPlayers(true)) + { + HashSet ignoreBlocks = new HashSet(); + ignoreBlocks.add(Material.AIR); + ignoreBlocks.add(Material.PORTAL); + + Block block = player.getTargetBlock(ignoreBlocks, 5); + + if (block == null || !_gunModule.getBomb().isBlock(block)) + continue; + + if (UtilMath.offset(player.getLocation(), block.getLocation().add(0.5, 0, 0.5)) > 3) + continue; + + if (_bombDefuser != null) + { + if (Recharge.Instance.use(player, "Defuse Message", 2000, false, false)) + UtilPlayer.message(player, F.main("Game", _bombDefuser.getName() + " is already defusing the Bomb.")); + + continue; + } + + _bombDefuser = player; + _bombDefuser.setExp(0f); + + UtilPlayer.message(player, F.main("Game", "You are defusing the Bomb.")); + + _bombDefuser.getWorld().playSound(_bombDefuser.getLocation(), Sound.PISTON_RETRACT, 2f, 1f); + } + } + + @EventHandler + public void defuseBombUpdate(UpdateEvent event) + { + if (_gunModule.getBomb() == null) + return; + + if (!IsLive()) + return; + + if (event.getType() != UpdateType.TICK) + return; + + if (_bombDefuser == null) + { + startDefuse(); + } + + if (_bombDefuser == null) + return; + + HashSet ignoreBlocks = new HashSet(); + ignoreBlocks.add(Material.AIR); + ignoreBlocks.add(Material.PORTAL); + + Block block = _bombDefuser.getTargetBlock(ignoreBlocks, 5); + + if (!IsAlive(_bombDefuser) || block == null || !_gunModule.getBomb().isBlock(block) || !_bombDefuser.isOnline() || UtilMath.offset(_bombDefuser.getLocation(), block.getLocation().add(0.5, 0, 0.5)) > 3) + { + _bombDefuser.setExp(0f); + _bombDefuser = null; + return; + } + + //Kit or Not? + float defuseRate = 0.005f; + if (UtilGear.isMat(_bombDefuser.getInventory().getItem(8), Material.SHEARS)) + defuseRate = 0.01f; + + _bombDefuser.setExp(Math.min(_bombDefuser.getExp() + defuseRate, 0.99999f)); + + UtilTextMiddle.display(C.cAqua + C.Bold + "Defusing Bomb", UtilTextMiddle.progress(_bombDefuser.getExp()), 0, 10, 0, _bombDefuser); + + if (_bombDefuser.getExp() >= 0.98f) + { + _gunModule.getBomb().defuse(); + + _winText = _bombDefuser.getName() + " defused the bomb!"; + + _gunModule.setBomb(null); + _bombDefuser.setExp(0f); + _bombDefuser = null; + + //Sound + _gunModule.playSound(Radio.BOMB_DEFUSE, null, null); + + setWinner(GetTeam(ChatColor.AQUA), true); + } + } + + @EventHandler + public void bombUpdate(UpdateEvent event) + { + if (!IsLive()) + return; + + if (event.getType() != UpdateType.TICK) + return; + + if (_gunModule.getBomb() == null) + return; + + if (!_gunModule.getBomb().update()) + return; + + /* + Set blocks = UtilBlock.getInRadius(_bomb.Block.getLocation(), 10d).keySet(); + + Iterator blockIterator = blocks.iterator(); + while (blockIterator.hasNext()) + { + Block block = blockIterator.next(); + + if (block.getY() < 2) + blockIterator.remove(); + } + + Manager.GetExplosion().BlockExplosion(blocks, _bomb.Block.getLocation(), false); + */ + + + HashMap players = UtilPlayer.getInRadius(_gunModule.getBomb().Block.getLocation(), 48); + for (Player player : players.keySet()) + { + if (!IsAlive(player)) + continue; + + // Damage Event + Manager.GetDamage().NewDamageEvent(player, null, null, + DamageCause.CUSTOM, 1 + (players.get(player) * 40), + true, true, false, "Bomb", "C4 Explosion"); + } + + + _gunModule.setBomb(null); + + _winText = _bombPlantedBy.getName() + " destroyed the bomb site!"; + + setWinner(GetTeam(ChatColor.RED), false); + } + + public int getScore(GameTeam team) + { + if (!_score.containsKey(team)) + _score.put(team, 0); + + return _score.get(team); + } + + public void addScore(GameTeam team) + { + _score.put(team, getScore(team) + 1); + } + + @EventHandler + public void roundTimerUpdate(UpdateEvent event) + { + if (!IsLive()) + return; + + if (event.getType() != UpdateType.TICK) + return; + + if (_gunModule.getBomb() != null) + return; + + if (UtilTime.elapsed(GetStateTime(), _roundTime)) + { + _winText = "Bomb sites were successfully defended!"; + drawScoreboard(); + setWinner(GetTeam(ChatColor.AQUA), false); + } + } + + @EventHandler + public void roundPlayerCheck(UpdateEvent event) + { + if (!IsLive()) + return; + + if (event.getType() != UpdateType.TICK) + return; + + ArrayList teamsAlive = new ArrayList(); + + for (GameTeam team : this.GetTeamList()) + if (team.GetPlayers(true).size() > 0) + teamsAlive.add(team); + + if (teamsAlive.size() == 1) + { + //Bomb Planted - CT cannot win without defusing + if (_gunModule.getBomb() != null) + { + if (teamsAlive.size() > 0) + { + if (teamsAlive.get(0).GetColor() == ChatColor.AQUA) + { + return; + } + } + } + + setWinner(teamsAlive.get(0), false); + } + else if (teamsAlive.size() == 0) + { + if (_gunModule.getBomb() == null) + { + _winText = "Bomb sites were successfully defended!"; + setWinner(GetTeam(ChatColor.AQUA), false); + } + else + { + _winText = "Bomb site will be destroyed!"; + setWinner(GetTeam(ChatColor.RED), false); + } + } + } + + public void setWinner(final GameTeam winner, boolean defuse) + { + if (_roundOver) + return; + + Bukkit.getPluginManager().callEvent(new RoundOverEvent(this)); + + _roundOver = true; + + String winnerLine = C.Bold + "The round was a draw!"; + ChatColor color = ChatColor.GRAY; + if (winner != null) + { + if(winner.GetName().contains("Bombers")) { + winnerLine= winner.GetColor() + C.Bold + winner.GetName() + " have won the round!"; + } else { + winnerLine= winner.GetColor() + C.Bold + winner.GetName() + " has won the round!"; + } + addScore(winner); + drawScoreboard(); + color = winner.GetColor(); + + + } + + //Sound + if (winner != null) + { + UtilServer.getServer().getScheduler().scheduleSyncDelayedTask(Manager.getPlugin(), new Runnable() + { + public void run() + { + if (winner.GetColor() == ChatColor.RED) + _gunModule.playSound(Radio.T_WIN, null, null); + else + _gunModule.playSound(Radio.CT_WIN, null, null); + } + }, defuse ? 60 : 0); + } + + //Record Streak for Money + if (winner.GetColor() == ChatColor.RED) + { + _winStreak++; + + if (_ctWonLast) + { + _ctWonLast = false; + _winStreak = 0; + } + } + else + { + _winStreak++; + + if (!_ctWonLast) + { + _ctWonLast = true; + _winStreak = 0; + } + } + + //Announce + Announce("", false); + Announce(color + "===================================", false); + Announce("", false); + Announce(winnerLine, false); + if (_winText != null) + Announce(_winText, false); + Announce("", false); + Announce(color + "===================================", false); + + for (Player player : UtilServer.getPlayers()) + { + player.playSound(player.getLocation(), Sound.LEVEL_UP, 1f, 1f); + _gunModule.removeScope(player); + + Recharge.Instance.Reset(player, "reload"); + } + + UtilTextMiddle.display(null, winnerLine, 20, 120, 20); + + //Check for total game win + EndCheck(); + + //Next Round (if not over) + if (IsLive()) + { + UtilServer.getServer().getScheduler().scheduleSyncDelayedTask(Manager.getPlugin(), new Runnable() + { + public void run() + { + restartRound(); + } + }, 100); + } + } + + public void restartRound() + { + giveMoney(); + + //Clean + resetGame(); + + //Teleport to Spawn + for (GameTeam team : GetTeamList()) + team.SpawnTeleport(false); + + //Revive Dead Players + for (Player player : GetPlayers(false)) + if (!IsAlive(player)) + { + SetPlayerState(player, PlayerState.IN); + + GameTeam team = GetTeam(player); + + //Teleport + team.SpawnTeleport(player); + + Manager.Clear(player); + UtilInv.Clear(player); + + ValidateKit(player, GetTeam(player)); + + if (GetKit(player) != null) + GetKit(player).ApplyKit(player); + } + + //Remove Scope + for (Player player : GetPlayers(false)) + _gunModule.removeScope(player); + + //Get Hit By Bullets + for (Player player : GetPlayers(false)) + ((CraftPlayer) player).getHandle().spectating = false; + + //Prepare Sound + for (Player player : GetPlayers(false)) + { + player.playSound(player.getLocation(), Sound.HORSE_ARMOR, 1f, 2f); + Manager.GetCondition().Factory().Blind("Respawn", player, null, 2, 0, false, false, false); + UtilPlayer.message(player, F.main("Game", "You have " + F.elem(C.cGreen + "$" + _shopManager.getMoney(player)) + ". Open your Inventory to spend it.")); + + UtilTextMiddle.display(C.cGreen + "$" + _shopManager.getMoney(player), "Open your Inventory to buy new equipment", 10, 120, 10, player); + } + + //Update Scoreboard Teams + for (GameTeam team : GetTeamList()) + for (Player teamMember : team.GetPlayers(true)) + GetScoreboard().SetPlayerTeam(teamMember, team.GetName().toUpperCase()); + + //Alternate Bullets + if (_gunModule.BulletAlternate) + _gunModule.BulletInstant = (_gunModule.BulletInstant + 1)%3; + + //Debug Details + if (_gunModule.Debug) + { + Announce(C.cDPurple + C.Bold + "ROUND SETTINGS:"); + + if (_gunModule.CustomHitbox) + Announce(C.cPurple + C.Bold + "Hitbox: " + ChatColor.RESET + "Accurate with Headshots"); + else + Announce(C.cPurple + C.Bold + "Hitbox: " + ChatColor.RESET + "Default with No Headshot"); + + if (_gunModule.BulletInstant == 0) + Announce(C.cPurple + C.Bold + "Bullets: " + ChatColor.RESET + "Slow and Visible"); + else if (_gunModule.BulletInstant == 1) + Announce(C.cPurple + C.Bold + "Bullets: " + ChatColor.RESET + "Instant and Invisible"); + else + Announce(C.cPurple + C.Bold + "Bullets: " + ChatColor.RESET + "Slow and Visible with Instant Sniper"); + } + } + + public void giveMoney() + { + if (_ctWonLast) + { + int ctMoney = 3250; + int tMoney = 1400 + (Math.min(4,_winStreak) * 500); + + if (_bombPlanted) + { + ctMoney += 250; + tMoney += 800; + } + + //Award + for (Player player : GetTeam(ChatColor.RED).GetPlayers(false)) + _shopManager.addMoney(player, tMoney, "losing the round"); + + for (Player player : GetTeam(ChatColor.AQUA).GetPlayers(false)) + _shopManager.addMoney(player, ctMoney, "winning the round"); + } + else + { + int tMoney = 3250; + int ctMoney = 1400 + (Math.min(4,_winStreak) * 500); + + //Award + for (Player player : GetTeam(ChatColor.RED).GetPlayers(false)) + _shopManager.addMoney(player, tMoney, "winning the round"); + + for (Player player : GetTeam(ChatColor.AQUA).GetPlayers(false)) + _shopManager.addMoney(player, ctMoney, "losing the round"); + } + } + + public void resetGame() + { + //General + _roundOver = false; + SetStateTime(System.currentTimeMillis()); + _gunModule.setFreezeTime(10); + _winText = null; + + //Bomb + if (_gunModule.getBomb() != null) + _gunModule.getBomb().clean(); + + if (_gunModule.getBombItem() != null) + _gunModule.getBombItem().remove(); + + if (_gunModule.getBombHolder() != null) + { + _gunModule.getBombHolder().getInventory().remove(Material.GOLD_SWORD); + _gunModule.setBombHolder(null); + } + + _gunModule.setBomb(null); + _gunModule.setBombItem(null); + + _bombPlanter = null; + _bombDefuser = null; + _bombPlantedBy = null; + _bombPlanted = false; + + _gunModule.reset(); + + //Health + for (Player player : UtilServer.getPlayers()) + player.setHealth(20); + + //Reset Shop + for (Player player : UtilServer.getPlayers()) + _shopManager.leaveShop(player, false, false); + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void specToTeam(PlayerJoinEvent event) + { + if (GetState() == GameState.Recruit || GetState() == GameState.Loading) + return; + + //Target Team + GameTeam targetTeam = null; + if (GetTeamList().get(0).GetPlayers(false).size() < GetTeamList().get(1).GetPlayers(false).size()) + targetTeam = GetTeamList().get(0); + else if (GetTeamList().get(0).GetPlayers(false).size() > GetTeamList().get(1).GetPlayers(false).size()) + targetTeam = GetTeamList().get(1); + else if (Math.random() > 0.5) + targetTeam = GetTeamList().get(1); + else + targetTeam = GetTeamList().get(0); + + SetPlayerTeam(event.getPlayer(), targetTeam, false); + + ((CraftPlayer) event.getPlayer()).getHandle().spectating = true; + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void quitLeaveTeam(PlayerQuitEvent event) + { + GameTeam team = GetTeam(event.getPlayer()); + + if (team != null) + { + team.RemovePlayer(event.getPlayer()); + } + } + + @EventHandler + public void restartFreezeCountdown(UpdateEvent event) + { + if (event.getType() != UpdateType.SEC) + return; + + if (_gunModule.getFreezeTime() <= 0) + return; + + _gunModule.setFreezeTime(_gunModule.getFreezeTime() - 1); + + for (Player player : UtilServer.getPlayers()) + { + if (_gunModule.getFreezeTime() > 0) + player.playSound(player.getLocation(), Sound.NOTE_STICKS, 1f, 1f); + else + player.playSound(player.getLocation(), Sound.NOTE_SNARE_DRUM, 1f, 1f); + } + + if (_gunModule.getFreezeTime() == 0) + { + //Give Bomb + Player bombPlayer = UtilAlg.Random(GetTeam(ChatColor.RED).GetPlayers(true)); + _gunModule.giveBombToPlayer(bombPlayer); + + //Sound + _gunModule.playSound(Radio.CT_START, null, GetTeam(ChatColor.AQUA)); + _gunModule.playSound(Radio.T_START, null, GetTeam(ChatColor.RED)); + } + } + + @Override + @EventHandler + public void ScoreboardUpdate(UpdateEvent event) + { + if (event != null && event.getType() != UpdateType.FAST) + return; + + drawScoreboard(); + } + + public void drawScoreboard() + { + Scoreboard.Reset(); + + for (GameTeam team : this.GetTeamList()) + { + + Scoreboard.WriteBlank(); + + Scoreboard.Write(getScore(team) + " " + team.GetColor() + C.Bold + team.GetName()); + //Scoreboard.Write(team.GetColor() + "" + getScore(team) + "" + " Wins" + team.GetColor()); + Scoreboard.Write(team.GetPlayers(true).size() + "" + " Alive" + team.GetColor()); + + } + + Scoreboard.WriteBlank(); + Scoreboard.Write(C.cGold + C.Bold + "Playing To"); + Scoreboard.Write(_roundsToWin + " Wins"); + + if (InProgress()) + { + Scoreboard.WriteBlank(); + + if (_gunModule.getBomb() == null) + { + Scoreboard.Write(C.cGold + C.Bold + "Time Left"); + Scoreboard.Write(UtilTime.MakeStr(_roundTime - (System.currentTimeMillis() - this.GetStateTime()), 1)); + } + else + { + if (_bombScoreboardFlash) + Scoreboard.Write(C.cRed + C.Bold + "Bomb Active"); + else + Scoreboard.Write(C.cWhite + C.Bold + "Bomb Active"); + + _bombScoreboardFlash = !_bombScoreboardFlash; + } + } + + + Scoreboard.Draw(); + } + + @Override + public void EndCheck() + { + endCheckScore(); + endCheckPlayer(); + } + + public void endCheckScore() + { + if (!IsLive()) + return; + + for (GameTeam team : GetTeamList()) + { + if (getScore(team) >= _roundsToWin) + { + //Announce + AnnounceEnd(team); + + for (GameTeam other : GetTeamList()) + { + if (WinnerTeam != null && other.equals(WinnerTeam)) + { + for (Player player : other.GetPlayers(false)) + AddGems(player, 10, "Winning Team", false, false); + } + + for (Player player : other.GetPlayers(false)) + if (player.isOnline()) + AddGems(player, 10, "Participation", false, false); + } + + //End + SetState(GameState.End); + } + } + } + + public void endCheckPlayer() + { + if (!IsLive()) + return; + + ArrayList teamsAlive = new ArrayList(); + + for (GameTeam team : this.GetTeamList()) + if (team.GetPlayers(false).size() > 0) + teamsAlive.add(team); + + if (teamsAlive.size() <= 1) + { + //Announce + if (teamsAlive.size() > 0) + AnnounceEnd(teamsAlive.get(0)); + + for (GameTeam team : GetTeamList()) + { + if (WinnerTeam != null && team.equals(WinnerTeam)) + { + for (Player player : team.GetPlayers(false)) + AddGems(player, 10, "Winning Team", false, false); + } + + for (Player player : team.GetPlayers(false)) + if (player.isOnline()) + AddGems(player, 10, "Participation", false, false); + } + + //End + SetState(GameState.End); + } + } + + @EventHandler + public void healthUpdate(UpdateEvent event) + { + if (!IsLive()) + return; + + if (event.getType() != UpdateType.SEC) + return; + + for (Player player : UtilServer.getPlayers()) + _scoreObj.getScore(player.getName()).setScore((int)(player.getHealth() * 5)); + } + + @EventHandler(priority = EventPriority.MONITOR) + public void damageHealth(CustomDamageEvent event) + { + Player player = event.GetDamagerPlayer(true); + if (player == null) + return; + + _scoreObj.getScore(player.getName()).setScore((int)(player.getHealth() * 5)); + } + + @EventHandler + public void debug(PlayerCommandPreprocessEvent event) + { + if (!event.getPlayer().isOp()) + return; + + if (event.getMessage().contains("money")) + { + _shopManager.addMoney(event.getPlayer(), 16000, "Debug"); + event.setCancelled(true); + } + } + + //Used for fire grenade spread + public int getRound() + { + int rounds = 0; + + for (int i : _score.values()) + rounds += i; + + return rounds; + } + + @Override + public Location GetSpectatorLocation() + { + if (SpectatorSpawn != null) + return SpectatorSpawn; + + Vector vec = new Vector(0, 0, 0); + double count = 0; + + for (GameTeam team : this.GetTeamList()) + { + for (Location spawn : team.GetSpawns()) + { + count++; + vec.add(spawn.toVector()); + } + } + + SpectatorSpawn = new Location(this.WorldData.World, 0, 0, 0); + + vec.multiply(1d / count); + + SpectatorSpawn.setX(vec.getX()); + SpectatorSpawn.setY(vec.getY() + 7); //ADD 7 + SpectatorSpawn.setZ(vec.getZ()); + + // Move Up - Out Of Blocks + while (!UtilBlock.airFoliage(SpectatorSpawn.getBlock()) + || !UtilBlock.airFoliage(SpectatorSpawn.getBlock().getRelative(BlockFace.UP))) + { + SpectatorSpawn.add(0, 1, 0); + } + + int Up = 0; + + // Move Up - Through Air + for (int i = 0; i < 15; i++) + { + if (UtilBlock.airFoliage(SpectatorSpawn.getBlock().getRelative(BlockFace.UP))) + { + SpectatorSpawn.add(0, 1, 0); + Up++; + } + else + { + break; + } + } + + // Move Down - Out Of Blocks + while (Up > 0 && !UtilBlock.airFoliage(SpectatorSpawn.getBlock()) + || !UtilBlock.airFoliage(SpectatorSpawn.getBlock().getRelative(BlockFace.UP))) + { + SpectatorSpawn.subtract(0, 1, 0); + Up--; + } + + SpectatorSpawn = SpectatorSpawn.getBlock().getLocation().add(0.5, 0.1, 0.5); + + while (SpectatorSpawn.getBlock().getTypeId() != 0 || SpectatorSpawn.getBlock().getRelative(BlockFace.UP).getTypeId() != 0) + SpectatorSpawn.add(0, 1, 0); + + return SpectatorSpawn; + } + + public GunModule getGunModule() + { + return _gunModule; + } +} \ No newline at end of file diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/PlayerHeadshotEvent.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/PlayerHeadshotEvent.java new file mode 100644 index 000000000..d84734bde --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/PlayerHeadshotEvent.java @@ -0,0 +1,35 @@ +package nautilus.game.arcade.game.games.minestrike; + +import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerEvent; + +public class PlayerHeadshotEvent extends PlayerEvent +{ + private static final HandlerList handlers = new HandlerList(); + + public static HandlerList getHandlerList() + { + return handlers; + } + + @Override + public HandlerList getHandlers() + { + return getHandlerList(); + } + + private final Player _shooter; + + public PlayerHeadshotEvent(Player who, Player shooter) + { + super(who); + + _shooter = shooter; + } + + public Player getShooter() + { + return _shooter; + } +} \ No newline at end of file diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/ShopManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/ShopManager.java index 3be74a24a..11ae6c4bf 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/ShopManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/ShopManager.java @@ -35,15 +35,15 @@ import org.bukkit.event.inventory.InventoryClickEvent; public class ShopManager { - private MineStrike Host; + private Minestrike Host; private HashMap> _shop = new HashMap>(); private HashMap _money = new HashMap(); private HashSet _inShop = new HashSet(); - public ShopManager(MineStrike host) + public ShopManager(Minestrike minestrike) { - Host = host; + Host = minestrike; } public void enterShop(Player player) @@ -60,27 +60,27 @@ public class ShopManager //Pistols slot = 9; - addItem(team.GetColor() == ChatColor.RED ? new Gun(GunStats.GLOCK_18) : new Gun(GunStats.P2000), player, slot++); - addItem(new Gun(GunStats.P250), player, slot++); - addItem(new Gun(GunStats.CZ75), player, slot++); - addItem(new Gun(GunStats.DEAGLE), player, slot++); + addItem(team.GetColor() == ChatColor.RED ? new Gun(GunStats.GLOCK_18, Host.getGunModule()) : new Gun(GunStats.P2000, Host.getGunModule()), player, slot++); + addItem(new Gun(GunStats.P250, Host.getGunModule()), player, slot++); + addItem(new Gun(GunStats.CZ75, Host.getGunModule()), player, slot++); + addItem(new Gun(GunStats.DEAGLE, Host.getGunModule()), player, slot++); //Shotgun slot = 18; - addItem(new Shotgun(GunStats.NOVA), player, slot++); - addItem(new Shotgun(GunStats.XM1014), player, slot++); + addItem(new Shotgun(GunStats.NOVA, Host.getGunModule()), player, slot++); + addItem(new Shotgun(GunStats.XM1014, Host.getGunModule()), player, slot++); //SMG - addItem(new Gun(GunStats.PPBIZON), player, slot++); - addItem(new Gun(GunStats.P90), player, slot++); + addItem(new Gun(GunStats.PPBIZON, Host.getGunModule()), player, slot++); + addItem(new Gun(GunStats.P90, Host.getGunModule()), player, slot++); //Rifles slot = 27; - addItem(team.GetColor() == ChatColor.RED ? new Gun(GunStats.GALIL) : new Gun(GunStats.FAMAS), player, slot++); - addItem(team.GetColor() == ChatColor.RED ? new Gun(GunStats.AK47) : new Gun(GunStats.M4A4), player, slot++); - addItem(team.GetColor() == ChatColor.RED ? new Gun(GunStats.SG553) : new Gun(GunStats.AUG), player, slot++); - addItem(new Gun(GunStats.SSG08), player, slot++); - addItem(new Gun(GunStats.AWP), player, slot++); + addItem(team.GetColor() == ChatColor.RED ? new Gun(GunStats.GALIL, Host.getGunModule()) : new Gun(GunStats.FAMAS, Host.getGunModule()), player, slot++); + addItem(team.GetColor() == ChatColor.RED ? new Gun(GunStats.AK47, Host.getGunModule()) : new Gun(GunStats.M4A4, Host.getGunModule()), player, slot++); + addItem(team.GetColor() == ChatColor.RED ? new Gun(GunStats.SG553, Host.getGunModule()) : new Gun(GunStats.AUG, Host.getGunModule()), player, slot++); + addItem(new Gun(GunStats.SSG08, Host.getGunModule()), player, slot++); + addItem(new Gun(GunStats.AWP, Host.getGunModule()), player, slot++); //Grenades addItem(new FlashBang(), player, 14); @@ -203,10 +203,11 @@ public class ShopManager if (item == null) return; - + if (hasItem(player, item)) return; + if (getMoney(player) < item.getCost()) { player.playSound(player.getLocation(), Sound.NOTE_BASS, 1f, 1f); @@ -217,11 +218,11 @@ public class ShopManager if (item instanceof Gun) { Gun gun = (Gun)item; - Host.dropSlotItem(player, gun.getSlot()); + Host.getGunModule().dropSlotItem(player, gun.getSlot()); gun.giveToPlayer(player, true); - gun.updateWeaponName(player, Host); + gun.updateWeaponName(player, Host.getGunModule()); gun.updateSkin(player, Host.getArcadeManager().getCosmeticManager().getGadgetManager()); - Host.registerGun(gun, player); + Host.getGunModule().registerGun(gun, player); } //Grenade @@ -235,7 +236,7 @@ public class ShopManager return; } - Host.registerGrenade(grenade, player); + Host.getGunModule().registerGrenade(grenade, player); } //Use 250 instead of 255, to show that its kevlar/helmet diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/data/Bullet.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/data/Bullet.java index 6c22a1042..3b3c275ac 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/data/Bullet.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/data/Bullet.java @@ -2,7 +2,7 @@ package nautilus.game.arcade.game.games.minestrike.data; import java.util.HashSet; -import nautilus.game.arcade.game.games.minestrike.MineStrike; +import nautilus.game.arcade.game.games.minestrike.GunModule; import nautilus.game.arcade.game.games.minestrike.items.guns.Gun; import org.bukkit.Location; @@ -25,7 +25,7 @@ public class Bullet public HashSet WhizzSound = new HashSet(); - public Bullet(Entity bullet, Gun gun, Player shooter, MineStrike game) + public Bullet(Entity bullet, Gun gun, Player shooter, GunModule game) { Bullet = bullet; Gun = gun; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/StrikeItem.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/StrikeItem.java index 7d93deed5..35e72fa1b 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/StrikeItem.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/StrikeItem.java @@ -1,6 +1,7 @@ package nautilus.game.arcade.game.games.minestrike.items; import java.util.ArrayList; +import java.util.Arrays; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -17,9 +18,10 @@ import mineplex.core.common.util.F; import mineplex.core.common.util.UtilAction; import mineplex.core.common.util.UtilGear; import mineplex.core.common.util.UtilInv; +import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilPlayer; import mineplex.core.itemstack.ItemStackFactory; -import nautilus.game.arcade.game.games.minestrike.MineStrike; +import nautilus.game.arcade.game.games.minestrike.GunModule; import nautilus.game.arcade.game.games.minestrike.items.grenades.Grenade; import nautilus.game.arcade.game.games.minestrike.items.guns.Gun; @@ -36,6 +38,8 @@ public abstract class StrikeItem private String _ownerName; private ItemStack _stack = null; + + private int _identifier; public StrikeItem(StrikeItemType type, String name, String[] desc, int cost, int gemCost, Material skin) { @@ -48,6 +52,11 @@ public abstract class StrikeItem //Make Stack _stack = new ItemStack(skin); + + _identifier = UtilMath.r(9000) + 1000; + + addID(); + fixStackName(); } @@ -86,12 +95,20 @@ public abstract class StrikeItem return _skinData; } + public void addID() + { + ItemMeta meta = _stack.getItemMeta(); + meta.setLore(Arrays.asList(ChatColor.RED + "" + ChatColor.BOLD + "Identifier: " + _identifier)); + _stack.setItemMeta(meta); + } + public void setSkin(Material skinMaterial, byte skinData) { _skinMaterial = skinMaterial; _skinData = skinData; _stack = new ItemStack(skinMaterial, 1, (short) 0, skinData); + addID(); } public String getOwnerName() @@ -104,7 +121,7 @@ public abstract class StrikeItem _ownerName = ownerName; } - public void drop(MineStrike game, Player player, boolean natural, boolean onlyDeregisterAndRemove) + public void drop(GunModule game, Player player, boolean natural, boolean onlyDeregisterAndRemove) { _stack.setAmount(1); @@ -160,6 +177,22 @@ public abstract class StrikeItem public boolean isStack(ItemStack stack) { + if (stack.hasItemMeta()) + { + if (stack.getItemMeta().hasLore()) + { + if (getStack().hasItemMeta()) + { + if (getStack().getItemMeta().hasLore()) + { + if (UtilGear.isMat(stack, _skinMaterial)) + return stack.getItemMeta().getLore().get(0).equalsIgnoreCase(getStack().getItemMeta().getLore().get(0)); + else + return false; + } + } + } + } return UtilGear.isMat(stack, _skinMaterial); } @@ -184,7 +217,7 @@ public abstract class StrikeItem _stack.setItemMeta(meta); } - public abstract boolean pickup(MineStrike game, Player player); + public abstract boolean pickup(GunModule game, Player player); public ItemStack getShopItem(int money, boolean alreadyHas) { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/equipment/DefusalKit.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/equipment/DefusalKit.java index c23f851e1..b93042442 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/equipment/DefusalKit.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/equipment/DefusalKit.java @@ -8,7 +8,7 @@ import org.bukkit.entity.Player; import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; -import nautilus.game.arcade.game.games.minestrike.MineStrike; +import nautilus.game.arcade.game.games.minestrike.GunModule; import nautilus.game.arcade.game.games.minestrike.items.StrikeItem; import nautilus.game.arcade.game.games.minestrike.items.StrikeItemType; @@ -24,7 +24,7 @@ public class DefusalKit extends StrikeItem } @Override - public boolean pickup(MineStrike game, Player player) + public boolean pickup(GunModule game, Player player) { return false; } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/equipment/armor/Armor.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/equipment/armor/Armor.java index 69f0de11a..d8a971131 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/equipment/armor/Armor.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/equipment/armor/Armor.java @@ -11,7 +11,7 @@ import org.bukkit.inventory.meta.LeatherArmorMeta; import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; -import nautilus.game.arcade.game.games.minestrike.MineStrike; +import nautilus.game.arcade.game.games.minestrike.GunModule; import nautilus.game.arcade.game.games.minestrike.items.StrikeItem; import nautilus.game.arcade.game.games.minestrike.items.StrikeItemType; @@ -23,7 +23,7 @@ public class Armor extends StrikeItem } @Override - public boolean pickup(MineStrike game, Player player) + public boolean pickup(GunModule game, Player player) { return false; } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/grenades/FireGrenadeBase.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/grenades/FireGrenadeBase.java index 493d836ba..2910721ff 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/grenades/FireGrenadeBase.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/grenades/FireGrenadeBase.java @@ -2,16 +2,6 @@ package nautilus.game.arcade.game.games.minestrike.items.grenades; import java.util.HashMap; -import mineplex.core.common.util.UtilBlock; -import mineplex.core.common.util.UtilParticle; -import mineplex.core.common.util.UtilServer; -import mineplex.core.common.util.UtilParticle.ParticleType; -import mineplex.core.common.util.UtilParticle.ViewDist; -import nautilus.game.arcade.game.GameTeam; -import nautilus.game.arcade.game.games.minestrike.MineStrike; -import nautilus.game.arcade.game.games.minestrike.Radio; - -import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; @@ -21,6 +11,15 @@ import org.bukkit.block.BlockFace; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; +import mineplex.core.common.util.UtilBlock; +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 nautilus.game.arcade.game.GameTeam; +import nautilus.game.arcade.game.games.minestrike.GunModule; +import nautilus.game.arcade.game.games.minestrike.Radio; + public abstract class FireGrenadeBase extends Grenade { private long _baseTime; @@ -37,7 +36,7 @@ public abstract class FireGrenadeBase extends Grenade } @Override - public boolean updateCustom(MineStrike game, Entity ent) + public boolean updateCustom(GunModule game, Entity ent) { // Fixed grenade effect not being activated when thrown in the ground. // Looks like ent.isOnGround() worked, while we previously used UtilEnt.isGrounded(ent). @@ -52,7 +51,7 @@ public abstract class FireGrenadeBase extends Grenade return false; } - private void createFire(final MineStrike game, final Location loc) + private void createFire(final GunModule game, final Location loc) { //Sound loc.getWorld().playSound(loc, Sound.IRONGOLEM_THROW, 1f, 1f); @@ -114,9 +113,9 @@ public abstract class FireGrenadeBase extends Grenade } @Override - public void playSound(MineStrike game, Player player) + public void playSound(GunModule game, Player player) { - GameTeam team = game.GetTeam(player); + GameTeam team = game.getHost().GetTeam(player); if (team == null) return; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/grenades/FlashBang.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/grenades/FlashBang.java index 21c4d3dab..f098df120 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/grenades/FlashBang.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/grenades/FlashBang.java @@ -9,7 +9,7 @@ import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilTime; import nautilus.game.arcade.game.GameTeam; -import nautilus.game.arcade.game.games.minestrike.MineStrike; +import nautilus.game.arcade.game.games.minestrike.GunModule; import nautilus.game.arcade.game.games.minestrike.Radio; import org.bukkit.ChatColor; @@ -33,7 +33,7 @@ public class FlashBang extends Grenade } @Override - public boolean updateCustom(MineStrike game, Entity ent) + public boolean updateCustom(GunModule game, Entity ent) { if (UtilTime.elapsed(_throwTime, 2000)) { @@ -43,7 +43,7 @@ public class FlashBang extends Grenade HashMap players = UtilPlayer.getInRadius(ent.getLocation(), 48); for (Player player : players.keySet()) { - if (!game.IsAlive(player)) + if (!game.getHost().IsAlive(player)) continue; //Line of Sight @@ -83,9 +83,9 @@ public class FlashBang extends Grenade } @Override - public void playSound(MineStrike game, Player player) + public void playSound(GunModule game, Player player) { - GameTeam team = game.GetTeam(player); + GameTeam team = game.getHost().GetTeam(player); if (team == null) return; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/grenades/Grenade.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/grenades/Grenade.java index 02c8bcb4d..3533a8973 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/grenades/Grenade.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/grenades/Grenade.java @@ -11,6 +11,7 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; +import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; import mineplex.core.common.util.C; @@ -20,7 +21,7 @@ import mineplex.core.common.util.UtilEnt; import mineplex.core.common.util.UtilInv; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilTime; -import nautilus.game.arcade.game.games.minestrike.MineStrike; +import nautilus.game.arcade.game.games.minestrike.GunModule; import nautilus.game.arcade.game.games.minestrike.items.StrikeItem; import nautilus.game.arcade.game.games.minestrike.items.StrikeItemType; @@ -132,9 +133,20 @@ public abstract class Grenade extends StrikeItem return true; } - public void throwGrenade(Player player, boolean wasLeftClick, MineStrike game) - { - player.setItemInHand(null); + public void throwGrenade(Player player, boolean wasLeftClick, GunModule game) + { + + if (player.getItemInHand().getAmount() < 2) + { + player.setItemInHand(null); + } + else + { + int amount = player.getItemInHand().getAmount(); + ItemStack stack = getStack(); + stack.setAmount(amount - 1); + player.setItemInHand(stack); + } _thrower = player; @@ -151,9 +163,13 @@ public abstract class Grenade extends StrikeItem _lastLoc = ent.getLocation(); UtilPlayer.message(player, F.main("Game", "You threw " + getName() + ".")); - + game.registerThrownGrenade(ent, this); - game.deregisterGrenade(this); + + if (player.getItemInHand().getAmount() < 2) + { + game.deregisterGrenade(this); + } //Sound playSound(game, player); @@ -161,7 +177,7 @@ public abstract class Grenade extends StrikeItem _throwTime = System.currentTimeMillis(); } - public boolean update(MineStrike game, Entity ent) + public boolean update(GunModule game, Entity ent) { if (UtilTime.elapsed(_throwTime, 20000)) return true; @@ -233,10 +249,10 @@ public abstract class Grenade extends StrikeItem _lastLoc = ent.getLocation(); } - public abstract boolean updateCustom(MineStrike game, Entity ent); + public abstract boolean updateCustom(GunModule game, Entity ent); @Override - public boolean pickup(MineStrike game, Player player) + public boolean pickup(GunModule game, Player player) { if (giveToPlayer(player, false)) { @@ -255,5 +271,5 @@ public abstract class Grenade extends StrikeItem return C.cDGreen + C.Bold + "Grenade" + ChatColor.RESET; } - public abstract void playSound(MineStrike game, Player player); + public abstract void playSound(GunModule game, Player player); } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/grenades/HighExplosive.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/grenades/HighExplosive.java index c46e246d7..a9d807596 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/grenades/HighExplosive.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/grenades/HighExplosive.java @@ -11,7 +11,7 @@ import mineplex.core.common.util.UtilParticle.ParticleType; import mineplex.core.common.util.UtilParticle.ViewDist; import mineplex.core.common.util.UtilPlayer; import nautilus.game.arcade.game.GameTeam; -import nautilus.game.arcade.game.games.minestrike.MineStrike; +import nautilus.game.arcade.game.games.minestrike.GunModule; import nautilus.game.arcade.game.games.minestrike.Radio; import org.bukkit.Bukkit; @@ -34,7 +34,7 @@ public class HighExplosive extends Grenade } @Override - public boolean updateCustom(MineStrike game, Entity ent) + public boolean updateCustom(GunModule game, Entity ent) { if (UtilTime.elapsed(_throwTime, 2000)) { @@ -48,12 +48,12 @@ public class HighExplosive extends Grenade List damagedPlayers = new ArrayList<>(); for (Player player : players.keySet()) { - if (!game.IsAlive(player)) + if (!game.getHost().IsAlive(player)) continue; // Damage Event Player damager = null; - if (game.IsAlive(_thrower)) + if (game.getHost().IsAlive(_thrower)) { damager = _thrower; } @@ -74,9 +74,9 @@ public class HighExplosive extends Grenade } @Override - public void playSound(MineStrike game, Player player) + public void playSound(GunModule game, Player player) { - GameTeam team = game.GetTeam(player); + GameTeam team = game.getHost().GetTeam(player); if (team == null) return; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/grenades/Smoke.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/grenades/Smoke.java index dbbd4dddb..b221404ae 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/grenades/Smoke.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/grenades/Smoke.java @@ -10,7 +10,7 @@ import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilParticle.ParticleType; import mineplex.core.common.util.UtilParticle.ViewDist; import nautilus.game.arcade.game.GameTeam; -import nautilus.game.arcade.game.games.minestrike.MineStrike; +import nautilus.game.arcade.game.games.minestrike.GunModule; import nautilus.game.arcade.game.games.minestrike.Radio; import org.bukkit.ChatColor; @@ -36,7 +36,7 @@ public class Smoke extends Grenade } @Override - public boolean updateCustom(final MineStrike game, Entity ent) + public boolean updateCustom(final GunModule game, Entity ent) { if (UtilTime.elapsed(_throwTime, 2000) && (UtilEnt.isGrounded(ent) || !ent.isValid())) { @@ -95,9 +95,9 @@ public class Smoke extends Grenade } @Override - public void playSound(MineStrike game, Player player) + public void playSound(GunModule game, Player player) { - GameTeam team = game.GetTeam(player); + GameTeam team = game.getHost().GetTeam(player); if (team == null) return; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/guns/Gun.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/guns/Gun.java index 102f87e3d..550d4df3f 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/guns/Gun.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/guns/Gun.java @@ -1,5 +1,6 @@ package nautilus.game.arcade.game.games.minestrike.items.guns; +import java.util.Arrays; import java.util.HashMap; import org.bukkit.ChatColor; @@ -32,10 +33,11 @@ import mineplex.core.common.util.UtilTime; import mineplex.core.gadget.GadgetManager; import mineplex.core.gadget.gadgets.gamemodifiers.GameModifierType; import mineplex.core.gadget.gadgets.gamemodifiers.minestrike.GameModifierMineStrikeSkin; +import mineplex.core.gadget.gadgets.gamemodifiers.minestrike.MineStrikeSkin; import mineplex.core.recharge.Recharge; import mineplex.core.recharge.RechargedEvent; import mineplex.core.stats.PlayerStats; -import nautilus.game.arcade.game.games.minestrike.MineStrike; +import nautilus.game.arcade.game.games.minestrike.GunModule; import nautilus.game.arcade.game.games.minestrike.data.Bullet; import nautilus.game.arcade.game.games.minestrike.items.StrikeItem; import nautilus.game.arcade.game.games.minestrike.items.StrikeItemType; @@ -59,11 +61,15 @@ public class Gun extends StrikeItem protected int _kills = -1; protected String _activeSkinName = "Default"; + + protected GunModule _module; - public Gun(GunStats gunStats) + public Gun(GunStats gunStats, GunModule module) { super(gunStats.getItemType(), gunStats.getName(), gunStats.getDesc(), gunStats.getCost(), gunStats.getGemCost(), gunStats.getSkin()); - + + _module = module; + _gunStats = gunStats; if (gunStats.getItemType() == StrikeItemType.PRIMARY_WEAPON) @@ -75,11 +81,11 @@ public class Gun extends StrikeItem _loadedAmmo = gunStats.getClipSize(); _reserveAmmo = gunStats.getClipReserve() * gunStats.getClipSize(); - + updateWeaponName(null, null); } - public void shoot(final Player player, final MineStrike game) + public void shoot(final Player player, final GunModule game) { if (_reloading) return; @@ -94,7 +100,7 @@ public class Gun extends StrikeItem { public void run() { - if (game.IsAlive(player)) + if (game.getHost().IsAlive(player)) shootOnce(player, game); } }, 2); @@ -109,7 +115,7 @@ public class Gun extends StrikeItem { public void run() { - if (game.IsAlive(player)) + if (game.getHost().IsAlive(player)) shootOnce(player, game); } }, i); @@ -117,7 +123,7 @@ public class Gun extends StrikeItem } } - public void shootOnce(Player player, MineStrike game) + public void shootOnce(Player player, GunModule game) { if (_reloading) return; @@ -167,7 +173,7 @@ public class Gun extends StrikeItem reload(player); } - public Bullet fireBullet(Player player, MineStrike game) + public Bullet fireBullet(Player player, GunModule game) { //Instant? boolean instant = game.getBulletType() == 1 || (game.getBulletType() == 2 && _gunStats.getGunType() == GunType.SNIPER); @@ -186,7 +192,7 @@ public class Gun extends StrikeItem Vector cof = new Vector(Math.random() - 0.5, (Math.random() - 0.2) * (5d/8d), Math.random() - 0.5); cof.normalize(); cof.multiply(cone); - cof.multiply(MineStrike.CONE); + cof.multiply(_module.CONE); cof.add(player.getLocation().getDirection()); cof.normalize(); @@ -307,12 +313,12 @@ public class Gun extends StrikeItem public void displayAmmo(Player player) { - if (!UtilGear.isMat(player.getItemInHand(), getStack().getType())) + if (_module.getGunInHand(player, null) != this) return; //Weapon Bob during reload if (_reloading) - updateWeaponName(player, null); + updateWeaponName(player, null, false); if (!Recharge.Instance.usable(player, getName() + " Reload")) return; @@ -323,7 +329,7 @@ public class Gun extends StrikeItem UtilTextBottom.display(C.cRed + "No Ammo", player); } - public void updateWeaponName(Player player, MineStrike game) + public void updateWeaponName(Player player, GunModule game, boolean setItem) { if(game != null) { @@ -331,24 +337,24 @@ public class Gun extends StrikeItem { new BukkitRunnable() { public void run() { - PlayerStats remoteStats = game.getArcadeManager().GetStatsManager().Get(player); - _kills = (int) remoteStats.getStat(game.GetName() + "." + getStatNameKills(true)); + PlayerStats remoteStats = game.getHost().getArcadeManager().GetStatsManager().Get(player);; + _kills = (int) remoteStats.getStat(game.getHost().GetName() + "." + getStatNameKills(true)); Player owner = UtilPlayer.searchExact(getOwnerName()); if(owner != null) { - HashMap localStatsMap = game.GetStats().get(owner); + HashMap localStatsMap = game.getHost().GetStats().get(owner); if(localStatsMap != null) { - Integer kills = localStatsMap.get(game.GetName() + "." + getStatNameKills(true)); + Integer kills = localStatsMap.get(game.getHost().GetName() + "." + getStatNameKills(true)); if(kills != null) { _kills += kills.intValue(); } } } - updateWeaponName(player, null); + updateWeaponName(player, null, setItem); } - }.runTaskAsynchronously(game.getArcadeManager().getPlugin()); + }.runTaskAsynchronously(game.getHost().getArcadeManager().getPlugin()); } } int kls = _kills; @@ -368,11 +374,18 @@ public class Gun extends StrikeItem if (player != null) { - player.getInventory().setItem(_slot, getStack()); + if (setItem) + player.getInventory().setItem(_slot, getStack()); + _reloadTick = !_reloadTick; } } + public void updateWeaponName(Player player, GunModule module) + { + updateWeaponName(player, module, true); + } + public void incrementKill() { _kills++; } @@ -399,7 +412,7 @@ public class Gun extends StrikeItem loc.getWorld().playSound(loc, Sound.PISTON_RETRACT, 1f, 0.8f); } - public void cancelReloadCheck(Player player, MineStrike game) + public void cancelReloadCheck(Player player, GunModule game) { if (!_reloading) return; @@ -457,6 +470,19 @@ public class Gun extends StrikeItem owner.getInventory().setItem(_slot, getStack()); } + + public void enableSkin() + { + MineStrikeSkin skin = null; + for (MineStrikeSkin otherSkin : MineStrikeSkin.values()) + { + if (otherSkin.getWeaponName().equalsIgnoreCase(_gunStats.getName())) + skin = otherSkin; + } + + setSkin(skin.getSkinMaterial(), skin.getSkinData()); + _activeSkinName = skin.getSkinName(); + } public int getSlot() { @@ -492,7 +518,7 @@ public class Gun extends StrikeItem } @Override - public boolean pickup(MineStrike game, Player player) + public boolean pickup(GunModule game, Player player) { if (player.getInventory().getItem(_slot) != null && player.getInventory().getItem(_slot).getType() != Material.AIR) return false; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/guns/GunFactory.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/guns/GunFactory.java index d6cc459ed..9cb4e430f 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/guns/GunFactory.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/guns/GunFactory.java @@ -1,12 +1,14 @@ package nautilus.game.arcade.game.games.minestrike.items.guns; +import nautilus.game.arcade.game.games.minestrike.GunModule; + public class GunFactory { - public Gun createGun(GunStats gun) + public Gun createGun(GunStats gun, GunModule module) { if (gun.getGunType() == GunType.SHOTGUN) - return new Shotgun(gun); + return new Shotgun(gun, module); - return new Gun(gun); + return new Gun(gun, module); } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/guns/GunStats.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/guns/GunStats.java index a7e777c70..fe59ff214 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/guns/GunStats.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/guns/GunStats.java @@ -1,6 +1,6 @@ package nautilus.game.arcade.game.games.minestrike.items.guns; -import nautilus.game.arcade.game.games.minestrike.MineStrike; +import nautilus.game.arcade.game.games.minestrike.GunModule; import nautilus.game.arcade.game.games.minestrike.items.StrikeItemType; import org.bukkit.Material; @@ -375,7 +375,7 @@ public enum GunStats public double getConeIncreaseRate() { - return _coneIncreaseRate * MineStrike.RECOIL; + return _coneIncreaseRate * GunModule.RECOIL; } public boolean getScope() diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/guns/GunType.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/guns/GunType.java index 3bdb407ac..f97e795da 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/guns/GunType.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/guns/GunType.java @@ -1,6 +1,6 @@ package nautilus.game.arcade.game.games.minestrike.items.guns; -import nautilus.game.arcade.game.games.minestrike.MineStrike; +import nautilus.game.arcade.game.games.minestrike.GunModule; public enum GunType { @@ -40,17 +40,17 @@ public enum GunType public double getMovePenalty() { - return _movePenalty * MineStrike.MOVE_PENALTY; + return _movePenalty * GunModule.MOVE_PENALTY; } public double getSprintPenalty() { - return _sprintPentalty * MineStrike.MOVE_PENALTY; + return _sprintPentalty * GunModule.MOVE_PENALTY; } public double getJumpPenalty() { - return _jumpPenalty * MineStrike.MOVE_PENALTY; + return _jumpPenalty * GunModule.MOVE_PENALTY; } public float getVolume() diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/guns/Shotgun.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/guns/Shotgun.java index 78f565db2..e613fb040 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/guns/Shotgun.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/guns/Shotgun.java @@ -5,7 +5,7 @@ import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilParticle.ParticleType; import mineplex.core.common.util.UtilParticle.ViewDist; import mineplex.core.recharge.Recharge; -import nautilus.game.arcade.game.games.minestrike.MineStrike; +import nautilus.game.arcade.game.games.minestrike.GunModule; import nautilus.game.arcade.game.games.minestrike.items.StrikeItemType; import org.bukkit.Location; @@ -18,15 +18,15 @@ public class Shotgun extends Gun { private int _pellets; - public Shotgun(GunStats gunStats) + public Shotgun(GunStats gunStats, GunModule module) { - super(gunStats); + super(gunStats, module); _pellets = gunStats.getPellets(); } @Override - public void shoot(Player player, MineStrike game) + public void shoot(Player player, GunModule game) { if (_reloading) return; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/BawkBawkBattles.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/BawkBawkBattles.java new file mode 100644 index 000000000..87f40aa8d --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/BawkBawkBattles.java @@ -0,0 +1,1746 @@ +package nautilus.game.arcade.game.games.mineware; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.bukkit.ChatColor; +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.Chicken; +import org.bukkit.entity.Item; +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.block.Action; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.event.entity.ItemSpawnEvent; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.player.PlayerArmorStandManipulateEvent; +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 org.bukkit.inventory.ItemStack; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.scheduler.BukkitRunnable; + +import com.google.common.collect.Lists; + +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.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.UtilTextTop; +import mineplex.core.common.util.UtilTime; +import mineplex.core.projectile.IThrown; +import mineplex.core.projectile.ProjectileUser; +import mineplex.core.recharge.Recharge; +import mineplex.core.teleport.event.MineplexTeleportEvent; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.minecraft.game.core.condition.Condition.ConditionType; +import mineplex.minecraft.game.core.condition.events.ConditionApplyEvent; +import mineplex.minecraft.game.core.damage.CustomDamageEvent; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.GameType; +import nautilus.game.arcade.events.GamePrepareCountdownCommence; +import nautilus.game.arcade.events.GameStateChangeEvent; +import nautilus.game.arcade.game.GameTeam; +import nautilus.game.arcade.game.TeamGame; +import nautilus.game.arcade.game.games.mineware.challenge.Challenge; +import nautilus.game.arcade.game.games.mineware.challenge.ChallengeData; +import nautilus.game.arcade.game.games.mineware.challenge.ChallengeList; +import nautilus.game.arcade.game.games.mineware.challenge.ChallengeSettings; +import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeAnvilDance; +import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeArrowRampage; +import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeBlockLobbers; +import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeBouncingBlock; +import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeBuildRace; +import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeChickenShooting; +import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeColorChange; +import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeDeadlyTnt; +import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeDiamondHunt; +import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeEggSmash; +import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeFallingBlocks; +import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeFastFood; +import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeKangarooJump; +import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeKingOfTheLadder; +import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeLavaRun; +import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeMilkACow; +import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeMinecartDance; +import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeMiniOneInTheQuiver; +import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeOreRun; +import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengePickASide; +import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengePunchThePig; +import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeRedLightGreenLight; +import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeReverseTag; +import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeRushPush; +import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeSmashOff; +import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeTreasureDigger; +import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeWaterHorror; +import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeWaveCrush; +import nautilus.game.arcade.game.games.mineware.effect.ChickenAttack; +import nautilus.game.arcade.game.games.mineware.effect.DeathEffect; +import nautilus.game.arcade.game.games.mineware.effect.DeathEffectData; +import nautilus.game.arcade.game.games.mineware.events.ChallengeEndEvent; +import nautilus.game.arcade.game.games.mineware.kit.KitBawksFood; +import nautilus.game.arcade.game.games.mineware.tracker.BouncingShadowTracker; +import nautilus.game.arcade.game.games.mineware.tracker.DragonKingTracker; +import nautilus.game.arcade.game.games.mineware.tracker.EliteArcherTracker; +import nautilus.game.arcade.game.games.mineware.tracker.MilkManTracker; +import nautilus.game.arcade.game.games.mineware.tracker.PinataMasterTracker; +import nautilus.game.arcade.game.games.mineware.tracker.PixelNinjaTracker; +import nautilus.game.arcade.game.games.mineware.tracker.SpeedyBuildersTracker; +import nautilus.game.arcade.game.games.mineware.tracker.SurfUpTracker; +import nautilus.game.arcade.game.games.mineware.tracker.TagMasterTracker; +import nautilus.game.arcade.game.games.mineware.tracker.VeteranTracker; +import nautilus.game.arcade.kit.Kit; + +/** + *

+ * Bawk Bawk Battles is a minigame based on MineWare that contains a set of + * challenges where players have to complete a list of tasks to maintain their lives. + *

+ * If a player fails to complete the task, he loses one life. + *
+ * If one runs out of lives, chickens will attack him. + */ +public class BawkBawkBattles extends TeamGame implements IThrown +{ + public static final int MAX_LIVES = 5; + private static final double SPAWN_CENTER_ADD = 0.5; + private static final double SPECTATOR_SPAWN_HEIGHT = 7; + + private static final int ROTATION_DELAY = 1000; // milliseconds + private static final int DESCRIPTION_DELAY = 1000; // milliseconds + + private static final int SILENCE_DURATION = 5000; + private static final int DESCRIPTION_LINE_DELAY = 1000; + private static final int DESCRIPTION_LINE_DELAY_MULTIPLIER = 55; + + private static final int COUNTDOWN_EFFECT_AMPLIFIER = 2; + private static final float DESCRIPTION_SOUND_VOLUME = 1.5F; + private static final float DESCRIPTION_SOUND_PITCH = 1.0F; + private static final int DESCRIPTION_TITLE_FADE_IN_TICKS = 0; + private static final int DESCRIPTION_TITLE_STAY_TICKS = 60; + private static final int DESCRIPTION_TITLE_FADE_OUT_TICKS = 20; + private static final float COUNTDOWN_FINISH_SOUND_VOLUME = 1.0F; + private static final float COUNTDOWN_FINISH_SOUND_PITCH = 1.0F; + private static final float COUNTDOWN_STEP_SOUND_VOLUME = 1.0F; + private static final float COUNTDOWN_STEP_SOUND_PITCH = 1.5F; + private static final int COUNTDOWN_SUBTRACT_TICKS = 15; + + private static final int SEMIFINAL_INDEX = 2; + private static final int FINAL_INDEX = 1; + private static final int FIRST_PLACE_GEM_REWARD = 40; + private static final int SECOND_PLACE_GEM_REWARD = 30; + private static final int THIRD_PLACE_GEM_REWARD = 20; + private static final int PARTICIPATION_GEMS = 10; + private static final int FIRST_WINNER_INDEX = 0; + private static final int SECOND_WINNER_INDEX = 1; + private static final int THIRD_WINNER_INDEX = 2; + + private static final int CRUMBLE_DIVIDER = 2; + + private static final float CHICKEN_ATTACK_SOUND_VOLUME = 1.0F; + private static final float CHICKEN_ATTACK_SOUND_PITCH = 1.3F; + private static final double CHICKEN_VELOCITY_HEIGHT = 0.4; + private static final double CHICKEN_VELOCITY_ADD = 0.6; + private static final float CHICKEN_ATTACK_HITBOX_GROW = 0.8F; + + private static final float CHICKEN_ATTACK_PARTICLE_OFFSET = 0.1F; + private static final float CHICKEN_ATTACK_PARTICLE_SPEED = 0.02F; + + private static final int SPECTATOR_KNOCKBACK_RADIUS = 6; + private static final int SPECTATOR_KNOCKBACK_NEXT_DELAY = 500; + private static final double SPECTATOR_KNOCKBACK_POWER = 1.6; + private static final double SPECTATOR_KNOCKBACK_HEIGHT = 0.9; + private static final double SPECTATOR_KNOCKBACK_HEIGHT_MAX = 10; + private static final float SPECTATOR_KNOCKBACK_SOUND_VOLUME = 2.0F; + private static final float SPECTATOR_KNOCKBACK_SOUND_PITCH = 0.5F; + + private static final int GENERIC_SCOREBOARD_PLAYER_COUNT = 15; + + private static final int LOST_ONE_LIFE = MAX_LIVES - 1; + private static final int LOST_TWO_LIVES = MAX_LIVES - 2; + private static final int LOST_THREE_LIVES = MAX_LIVES - 3; + private static final int LOST_FOUR_LIVES = MAX_LIVES - 4; + + private static final float CHICKEN_HIT_PLAYER_SOUND_VOLUME = 2.0F; + private static final float CHICKEN_HIT_PLAYER_SOUND_PITCH = 1.0F; + private static final double CHICKEN_HIT_PLAYER_DAMAGE = 5.0; + + private BawkBawkBattlesSettings _settings = new BawkBawkBattlesSettings(); + private ChallengeList _list = new ChallengeList(); + private Map _lives = new HashMap<>(); + private List _winners = new ArrayList(); + private GameTeam _playerTeam, _chickenTeam; + private DeathEffect _deathEffect = new DeathEffect(this); + private ChickenAttack _chickenAttack; + private Location _chickenAttackCenter; + private Challenge _challenge; + private List _lastChallengeBlocks; + private long _delay; + + private List _countdown = Arrays.asList( + C.cRed + C.Bold + "3", + C.cYellow + C.Bold + "2", + C.cGreen + C.Bold + "1", + C.cWhite + C.Bold + "GO!"); + + @SuppressWarnings("unchecked") + public BawkBawkBattles(ArcadeManager manager) + { + super(manager, + GameType.BawkBawkBattles, + new Kit[] { new KitBawksFood(manager) }, + new String[] { + "Follow Bawk Bawk's instructions in chat.", + "Complete a task first or be the last one to stay alive.", + "If you fail a challenge, you lose one life.", + "If you run out of lives, chickens will attack you.", + "Last player with lives wins.", + }); + + DamagePvP = false; + DamagePvE = false; + DamageEvP = false; + DamageSelf = false; + DamageFall = false; + DamageTeamSelf = true; + DamageTeamOther = false; + + SpawnTeleport = false; // Disabled for custom spawn teleportation. + + DeathOut = false; + DeathTeleport = false; + AutomaticRespawn = false; + DeathMessages = false; + FixSpawnFacing = false; + + TeleportsDisqualify = false; + GiveClock = false; + + CompassEnabled = false; + CompassGiveItem = false; + CompassGiveItemSpectators = false; + + Manager.GetCreature().SetDisableCustomDrops(true); + + populateChallenges(); + + registerStatTrackers( + new BouncingShadowTracker(this), + new DragonKingTracker(this), + new EliteArcherTracker(this), + new MilkManTracker(this), + new PinataMasterTracker(this), + new PixelNinjaTracker(this), + new SpeedyBuildersTracker(this), + new SurfUpTracker(this), + new TagMasterTracker(this), + new VeteranTracker(this)); + } + + public void populateChallenges() + { + _list.add( + new ChallengeAnvilDance(this), + new ChallengeArrowRampage(this), + new ChallengeBlockLobbers(this), + new ChallengeBouncingBlock(this), + new ChallengeBuildRace(this), + new ChallengeColorChange(this), + new ChallengeChickenShooting(this), + new ChallengeDeadlyTnt(this), + new ChallengeDiamondHunt(this), + new ChallengeEggSmash(this), + new ChallengeFallingBlocks(this), + new ChallengeFastFood(this), + new ChallengeWaterHorror(this), + new ChallengeKangarooJump(this), + new ChallengeKingOfTheLadder(this), + new ChallengeLavaRun(this), + new ChallengeMilkACow(this), + new ChallengeOreRun(this), + new ChallengeMinecartDance(this), + new ChallengeMiniOneInTheQuiver(this), + new ChallengePickASide(this), + new ChallengePunchThePig(this), + new ChallengeRedLightGreenLight(this), + new ChallengeReverseTag(this), + new ChallengeRushPush(this), + new ChallengeSmashOff(this), + new ChallengeTreasureDigger(this), + new ChallengeWaveCrush(this)); + + /* + * Removed: + * + * Cloud Fall + * Dogs Vs Cats + * Fishing Day + * Navigation Maze + * Volley Pig + * Zombie Infection + */ + } + + @Override + public void ParseData() // Load the location where all chickens on chicken attack will spawn. + { + _chickenAttackCenter = WorldData.GetDataLocs("WHITE").get(0); + } + + /* + * Team creation + */ + + @EventHandler(priority = EventPriority.HIGHEST) + public void createTeams(GameStateChangeEvent event) + { + if (event.GetState() == GameState.Recruit) + { + createPlayerTeam(); + } + else if (event.GetState() == GameState.Live) + { + createChickenTeam(); + } + } + + private void createPlayerTeam() + { + _playerTeam = new GameTeam(this, "Players", ChatColor.YELLOW, new ArrayList<>()); + AddTeam(_playerTeam); + } + + private void createChickenTeam() + { + _chickenTeam = new GameTeam(this, "Chickens", ChatColor.GRAY, _playerTeam.GetSpawns()); + _chickenTeam.SetVisible(false); + AddTeam(_chickenTeam); + } + + /* + * Preparing for start + */ + + @EventHandler(priority = EventPriority.HIGH) + public void prepare(GameStateChangeEvent event) + { + if (event.GetState() != GameState.Prepare) + return; + + addPlayerLives(); + + _challenge = selectChallenge(); + + if (isChallengeNull()) + return; + + setupChallengeSpawnLocations(); + _challenge.createMap(); + + spawnAndResetPlayers(true); + } + + private void addPlayerLives() + { + for (Player player : GetPlayers(true)) + { + _lives.put(player, MAX_LIVES); + } + } + + private Challenge selectChallenge() + { + int limit = _list.size(); + int attemps = 0; + + Challenge instance = _list.random(); + + while (!isSuitable(instance)) + { + if (attemps < limit) + { + instance = _list.random(); + attemps++; + } + else + { + _list.resetPlayed(); + attemps = 0; + } + } + + return instance; + } + + private boolean isSuitable(Challenge instance) + { + ChallengeSettings settings = instance.getSettings(); + + int participants = getPlayersWithRemainingLives(); + int minCount = settings.getMinPlayers(); + int maxCount = settings.getMaxPlayers(); + + return participants >= minCount && participants <= maxCount; + } + + private boolean isChallengeNull() + { + if (_challenge == null) + { + SetState(GameState.Dead); + UtilServer.broadcast(F.main("Game", "No suitable challenge was found.")); + return true; + } + else + { + return false; + } + } + + /* + * Spawns + */ + + private ArrayList setupChallengeSpawnLocations() + { + ArrayList selected = _challenge.createSpawns(); + + for (Location spawn : selected) + { + spawn = spawn.add(SPAWN_CENTER_ADD, SPAWN_CENTER_ADD, SPAWN_CENTER_ADD); + spawn.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory2d(spawn, _challenge.getCenter()))); + } + + _challenge.getData().setSpawns(selected); + _playerTeam.SetSpawns(selected); + SpectatorSpawn = _challenge.getCenter().add(0, SPECTATOR_SPAWN_HEIGHT, 0); + + return selected; + } + + private void spawnAndResetPlayers(boolean firstRun) + { + teleportPlayersToSpawns(firstRun); + resetPlayers(); + addEffectsToPlayers(); + teleportSpectatorsToSpawn(); + } + + private void resetPlayers() + { + for (Player player : GetPlayers(false)) + { + if (_lives.get(player) > 0) + { + Manager.Clear(player); + Scoreboard.SetPlayerTeam(player, _playerTeam.GetName().toUpperCase()); + } + } + } + + private void teleportSpectatorsToSpawn() + { + for (Player player : GetPlayers(false)) + { + if (!IsAlive(player)) + { + player.teleport(GetSpectatorLocation()); + } + } + } + + private void teleportPlayersToSpawns(boolean firstRun) + { + _challenge.spawn(firstRun); + removeSolidBlockForPlayers(); + } + + private void removeSolidBlockForPlayers() + { + for (Player player : GetPlayers(true)) + { + removeSolidBlock(player.getLocation()); + } + } + + private void removeSolidBlock(Location location) + { + Block block = location.getBlock(); + Block upper = block.getRelative(BlockFace.UP); + + if (!block.isEmpty() && _challenge.getData().isModifiedBlock(block)) + { + _challenge.resetBlock(block); + _challenge.getData().removeModifiedBlock(block); + } + + if (!upper.isEmpty() && _challenge.getData().isModifiedBlock(upper)) + { + _challenge.resetBlock(upper); + _challenge.getData().removeModifiedBlock(upper); + } + } + + /* + * Start + */ + + @EventHandler + public void start(GameStateChangeEvent event) + { + if (event.GetState() != GameState.Live) + return; + + _delay = System.currentTimeMillis(); + + _chickenAttack = new ChickenAttack(this, _chickenAttackCenter); + } + + @EventHandler + public void addEffectsDuringCountdown(GamePrepareCountdownCommence event) + { + for (Player player : GetPlayers(true)) + { + player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, Integer.MAX_VALUE, COUNTDOWN_EFFECT_AMPLIFIER)); + player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, Integer.MAX_VALUE, COUNTDOWN_EFFECT_AMPLIFIER)); + } + } + + @EventHandler + public void freeze(PlayerMoveEvent event) + { + if (!IsLive()) + return; + + Player player = event.getPlayer(); + + if (!IsAlive(player)) + return; + + if (!getPlayersAlive().contains(player)) + return; + + if (!PrepareFreeze) + return; + + if (!_settings.isWaiting()) + return; + + Location from = event.getFrom(); + Location to = event.getTo(); + + if (UtilMath.offset2d(from, to) <= 0) + return; + + from.setPitch(to.getPitch()); + from.setYaw(to.getYaw()); + event.setTo(from); + } + + /* + * Challenge rotation + */ + + @EventHandler + public void update(UpdateEvent event) + { + if (event.getType() != UpdateType.FASTER) + return; + + if (!IsLive()) + return; + + if (_challenge == null) // When challenge is null, a new one should start. + { + if (!UtilTime.elapsed(_delay, ROTATION_DELAY)) + { + return; + } + + _challenge = selectChallenge(); + + if (isChallengeNull()) + return; + + Damage = true; + resetLastChallengeMap(); + + _deathEffect.removeSpawnedEntities(); + + setupChallengeSpawnLocations(); + _challenge.createMap(); + + spawnAndResetPlayers(false); + + _delay = System.currentTimeMillis(); + _settings.setWaiting(true); + } + else if (_settings.isWaiting()) // If challenge is waiting, show description. + { + if (!UtilTime.elapsed(_delay, DESCRIPTION_DELAY)) + { + return; + } + + displayDescriptionAndStartChallenge(); + } + else // Otherwise, check if the challenge is ended. + { + checkChallengeEnd(); + } + } + + private void resetLastChallengeMap() + { + _settings.setCrumbling(false); + + for (Block block : _lastChallengeBlocks) + { + if (block.getState() instanceof InventoryHolder) + { + InventoryHolder holder = (InventoryHolder) block.getState(); + holder.getInventory().clear(); + } + + _challenge.resetBlock(block); + } + } + + private void displayDescriptionAndStartChallenge() + { + if (_settings.areMessagesSent()) + { + removeEffectsFromPlayers(); + + _settings.setWaiting(false); + _settings.setChallengeStarted(true); + + _challenge.start(); + + _settings.markMessagesAsSent(false); + } + else if (!_settings.areMessagesBeingSent()) + { + showChallengeDescription(); + } + } + + private void removeEffectsFromPlayers() + { + for (Player player : GetPlayers(true)) + { + if (player.hasPotionEffect(PotionEffectType.BLINDNESS) && player.hasPotionEffect(PotionEffectType.NIGHT_VISION)) + { + player.removePotionEffect(PotionEffectType.BLINDNESS); + player.removePotionEffect(PotionEffectType.NIGHT_VISION); + } + } + } + + private void addEffectsToPlayers() + { + for (Player player : GetPlayers(true)) + { + player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, Integer.MAX_VALUE, 2)); + player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, Integer.MAX_VALUE, 2)); + } + } + + private void showChallengeDescription() + { + silenceChat(); + setMessageState(); + showDescriptionText(); + } + + private void silenceChat() + { + if (Manager.GetChat().Silenced() < 0) + { + Manager.GetChat().Silence(SILENCE_DURATION, false); + } + } + + private void setMessageState() + { + _settings.markMessagesAsSending(true); + _settings.markMessagesAsSent(false); + } + + private void showDescriptionText() + { + List messages = Lists.newArrayList(_challenge.getDescription()); + messages.add(0, C.cGray + "Bawk Bawk commands..."); + + new BukkitRunnable() + { + private int index = 0; + private long delay = 0; + + @Override + public void run() + { + if (!IsLive() || _challenge == null) + { + cancel(); + return; + } + + if (delay > System.currentTimeMillis()) + { + return; + } + + if (index >= messages.size()) + { + prepareCountdown(); + cancel(); + return; + } + + delay = System.currentTimeMillis() + (DESCRIPTION_LINE_DELAY + (DESCRIPTION_LINE_DELAY_MULTIPLIER * messages.get(index).length())); + + String title = null; + String subtitle = C.cYellow + messages.get(index); + + if (index > 0) + { + if (index == 1) + { + showDescriptionInChat(); + } + + title = _challenge.getName(); + + for (Player player : GetPlayers(true)) + { + player.playSound(player.getLocation(), Sound.CHICKEN_IDLE, DESCRIPTION_SOUND_VOLUME, DESCRIPTION_SOUND_PITCH); + } + } + + for (Player player : GetPlayers(true)) + { + UtilTextMiddle.display(title, subtitle, DESCRIPTION_TITLE_FADE_IN_TICKS, DESCRIPTION_TITLE_STAY_TICKS, DESCRIPTION_TITLE_FADE_OUT_TICKS, player); + } + + index++; + } + }.runTaskTimer(Manager.getPlugin(), 0L, 1L); + } + + private void prepareCountdown() + { + new BukkitRunnable() + { + private int index = 0; + + @Override + public void run() + { + if (!IsLive() || _challenge == null) + { + cancel(); + return; + } + + for (Player player : GetPlayers(true)) + { + String message = _countdown.get(index); + UtilTextMiddle.display(message, null, player); + + if (index == _countdown.size() - 1) + { + player.playSound(player.getLocation(), Sound.CHICKEN_HURT, COUNTDOWN_FINISH_SOUND_VOLUME, COUNTDOWN_FINISH_SOUND_PITCH); + } + else + { + player.playSound(player.getLocation(), Sound.CHICKEN_EGG_POP, COUNTDOWN_STEP_SOUND_VOLUME, COUNTDOWN_STEP_SOUND_PITCH); + } + } + + index++; + + if (index >= _countdown.size()) + { + _settings.markMessagesAsSent(true); + _settings.markMessagesAsSending(false); + cancel(); + } + } + }.runTaskTimer(Manager.getPlugin(), 0, COUNTDOWN_SUBTRACT_TICKS); + } + + private void showDescriptionInChat() + { + List messages = Lists.newArrayList(_challenge.getDescription()); + String type = _challenge.getType().toString(); + + if (_challenge.getSettings().isTeamBased()) + { + type = "Team Based"; + } + + for (Player player : UtilServer.getPlayers()) + { + UtilPlayer.message(player, ""); + + UtilPlayer.message(player, " " + C.cYellow + _challenge.getName() + C.Reset + " " + C.cGray + type); + UtilPlayer.message(player, ""); + + for (String currentMessage : messages) + { + UtilPlayer.message(player, C.cGray + " - " + C.cWhite + currentMessage); + } + + UtilPlayer.message(player, ""); + } + } + + private void checkChallengeEnd() + { + if (_challenge.canFinish()) + { + endCurrentChallenge(); + return; + } + else + { + updateChallengeTimer(); + } + + if (hasCrumbleSetting() && canStartCrumbling()) + { + _settings.setCrumbling(true); + announceCrumbling(); + } + } + + public void endCurrentChallenge() + { + if (_challenge == null) + return; + + _delay = System.currentTimeMillis(); + + sortLastChallengeBlocks(); + _challenge.end(); + + _settings.setChallengeStarted(false); + _settings.setCrumbling(false); + _settings.markMessagesAsSending(false); + _settings.markMessagesAsSent(false); + + _list.addPlayed(_challenge); + + Damage = false; + _challenge = null; + EndCheck(); + } + + private void sortLastChallengeBlocks() + { + _lastChallengeBlocks = new ArrayList<>(_challenge.getData().getModifiedBlocks()); + + Collections.sort(_lastChallengeBlocks, new Comparator() + { + @Override + public int compare(Block o1, Block o2) + { + return new Integer(o2.getY()).compareTo(o1.getY()); + } + }); + } + + @Override + public void EndCheck() + { + if (!IsLive()) + return; + + if (getPlayersWithRemainingLives() <= 1) + { + if (getPlayersAlive().size() > 0) + { + Player additional = getPlayersAlive().get(0); + _winners.add(0, additional); + } + + if (_winners.size() > 2) + { + Collections.swap(_winners, SEMIFINAL_INDEX, FINAL_INDEX); + } + + if (_winners.size() >= 1) + { + AddGems(_winners.get(FIRST_WINNER_INDEX), FIRST_PLACE_GEM_REWARD, "First Place", false, false); + + if (_winners.size() >= 2) + { + AddGems(_winners.get(SECOND_WINNER_INDEX), SECOND_PLACE_GEM_REWARD, "Second Place", false, false); + + if (_winners.size() >= 3) + { + AddGems(_winners.get(THIRD_WINNER_INDEX), THIRD_PLACE_GEM_REWARD, "Third Place", false, false); + } + } + } + + for (Player player : super.GetPlayers(false)) + AddGems(player, PARTICIPATION_GEMS, "Participation", false, false); + + AnnounceEnd(_winners); + SetState(GameState.End); + } + } + + private void updateChallengeTimer() + { + for (Player player : UtilServer.getPlayers()) + { + UtilTextTop.displayTextBar(player, _challenge.getTimeLeftPercent(), C.cYellowB + _challenge.getName()); + player.setLevel(_challenge.getRemainingPlaces()); + player.setExp(_challenge.getTimeLeftPercent()); + } + } + + private boolean hasCrumbleSetting() + { + return _challenge.getSettings().canCrumble() && !_challenge.getData().getModifiedBlocks().isEmpty(); + } + + private boolean canStartCrumbling() + { + int lost = _challenge.getData().getLostPlayers().size(); + int current = getPlayersAlive().size(); + + return !_settings.isCrumbling() && lost > current / CRUMBLE_DIVIDER; + } + + private void announceCrumbling() + { + for (Player player : UtilServer.getPlayers()) + { + if (!_chickenTeam.HasPlayer(player)) + { + UtilPlayer.message(player, F.main("Game", "The map has started to crumble.")); + } + } + } + + /* + * Messages + */ + + public void showLivesLeft(Player player) + { + int lives = lives(player); + String suffix = "lives"; + + if (lives == 1) + suffix = "life"; + + String msg = "You have " + F.elem(lives) + " " + suffix + " left."; + + if (lives <= 0) + msg = "You don't have any lives left."; + + UtilPlayer.message(player, F.main("Game", msg)); + } + + /* + * End reset + */ + + @EventHandler + public void end(GameStateChangeEvent event) + { + if (event.GetState() != GameState.End) + return; + + if (_settings.isChallengeStarted()) + return; + + for (Player player : GetPlayers(true)) + { + UtilPlayer.clearPotionEffects(player); + UtilTextMiddle.display(null, null, player); + } + } + + /* + * Chicken attack + */ + + @EventHandler + public void chickenAttack(UpdateEvent event) + { + if (!IsLive()) + return; + + if (event.getType() != UpdateType.SEC) + return; + + if (_chickenTeam == null) + return; + + if (_chickenTeam.GetSize() == 0) + return; + + for (Player player : _chickenTeam.GetPlayers(true)) + { + Chicken chicken = UtilMath.randomElement(_chickenAttack.getChickens()); + Material feetType = chicken.getLocation().getBlock().getType(); + + if (chicken.isOnGround() && feetType != Material.STATIONARY_WATER && feetType != Material.WATER) + { + UtilEnt.CreatureLook(chicken, player); + player.playSound(chicken.getLocation(), Sound.BAT_TAKEOFF, CHICKEN_ATTACK_SOUND_VOLUME, CHICKEN_ATTACK_SOUND_PITCH); + UtilAction.velocity( + chicken, + UtilAlg.getTrajectory2d(chicken, player), + UtilAlg.calculateVelocity(chicken.getLocation().toVector(), player.getLocation().toVector(), CHICKEN_VELOCITY_HEIGHT).length() + CHICKEN_VELOCITY_ADD, + false, + 0, + CHICKEN_VELOCITY_HEIGHT, + CHICKEN_VELOCITY_HEIGHT + 1, + false); + + Manager.GetProjectile().AddThrow(chicken, null, this, -1, true, false, false, true, CHICKEN_ATTACK_HITBOX_GROW); + } + } + } + + @EventHandler + public void chickenAttackParticle(UpdateEvent event) + { + if (!IsLive()) + return; + + if (event.getType() != UpdateType.TICK) + return; + + for (Chicken chicken : _chickenAttack.getChickens()) + { + Material feetType = chicken.getLocation().getBlock().getType(); + Block below = chicken.getLocation().getBlock().getRelative(BlockFace.DOWN); + + if (!chicken.isOnGround() && feetType != Material.STATIONARY_WATER && feetType != Material.WATER && !below.isEmpty()) + { + UtilParticle.PlayParticle(ParticleType.FLAME, chicken.getLocation(), CHICKEN_ATTACK_PARTICLE_OFFSET, CHICKEN_ATTACK_PARTICLE_OFFSET, CHICKEN_ATTACK_PARTICLE_OFFSET, CHICKEN_ATTACK_PARTICLE_SPEED, 1, ViewDist.NORMAL); + } + } + } + + @EventHandler + public void chickenAttackPlayerDeath(PlayerDeathEvent event) + { + if (!IsLive()) + return; + + if (_challenge == null) + return; + + Player player = event.getEntity(); + + if (!_chickenTeam.HasPlayer(player)) + return; + + _chickenAttack.kill(player, true); + } + + @EventHandler + public void blockChickenAttackMemberDamage(EntityDamageEvent event) + { + if (!IsLive()) + return; + + if (event.getEntity() instanceof Chicken) + { + Chicken chicken = (Chicken) event.getEntity(); + + if (_chickenAttack.isGroupMember(chicken)) + { + event.setCancelled(true); + } + + if (event.getCause() == DamageCause.VOID) + { + chicken.teleport(_chickenAttack.getPlatformCenter()); + } + } + } + + @EventHandler + public void spectatorApproachPlayer(UpdateEvent event) + { + if (!IsLive()) + return; + + if (event.getType() != UpdateType.TICK) + return; + + for (Player player : GetPlayers(true)) + { + for (Player other : _chickenTeam.GetPlayers(false)) + { + if (player.equals(other)) + continue; + + if (UtilMath.offset(other, player) >= SPECTATOR_KNOCKBACK_RADIUS) + continue; + + if (Recharge.Instance.use(player, "Approach Alive Player", SPECTATOR_KNOCKBACK_NEXT_DELAY, false, false)) + { + UtilAction.velocity(other, UtilAlg.getTrajectory2d(player, other), SPECTATOR_KNOCKBACK_POWER, true, SPECTATOR_KNOCKBACK_HEIGHT, 0, SPECTATOR_KNOCKBACK_HEIGHT_MAX, true); + other.playSound(other.getLocation(), Sound.CHICKEN_EGG_POP, SPECTATOR_KNOCKBACK_SOUND_VOLUME, SPECTATOR_KNOCKBACK_SOUND_PITCH); + } + } + } + } + + /* + * Completed players + */ + + @EventHandler + public void preventVoidDeath(PlayerMoveEvent event) + { + if (!IsLive()) + return; + + if (_challenge == null) + return; + + Player player = event.getPlayer(); + + if (_challenge.getData().isDone(player) && !_chickenTeam.HasPlayer(player.getName(), false)) + { + if (event.getTo().getY() <= 0) + { + player.teleport(_challenge.getCenter().add(0, 1, 0)); + } + } + } + + @EventHandler + public void cancelSpectatorCloak(ConditionApplyEvent event) + { + if (!IsLive()) + return; + + if (event.GetCondition().GetType() != ConditionType.CLOAK) + return; + + if (!event.GetCondition().GetReason().equals("Spectator")) + return; + + if (!(event.GetCondition().GetEnt() instanceof Player)) + return; + + Player player = (Player) event.GetCondition().GetEnt(); + + if (GetTeam(player) == null) + return; + + event.setCancelled(true); + } + + /* + * Cancel/Quit + */ + + @EventHandler + public void cancel(GameStateChangeEvent event) + { + if (event.GetState() == GameState.Live) + return; + + if (_challenge == null) + return; + + if (_settings.isWaiting()) + return; + + Manager.getPluginManager().callEvent(new ChallengeEndEvent(_challenge)); + HandlerList.unregisterAll(_challenge); + + _challenge.end(); + _settings.setChallengeStarted(false); + } + + @EventHandler + public void quit(PlayerQuitEvent event) + { + Player player = event.getPlayer(); + + _lives.remove(player); + _winners.remove(player); + } + + // @EventHandler + // public void blockStartAttempt(UpdateEvent event) + // { + // if (event.getType() != UpdateType.TICK) + // return; + // + // // If there is only 1 player and the game starts, do not teleport him to the map. + // + // if (GetState() == GameState.Recruit && GetCountdown() >= 0 && GetPlayers(false).size() <= MIN_PLAYERS_BLOCK_ATTEMPT) + // { + // UtilServer.broadcast(F.main("Game", C.cRed + "This game requires at least 2 players to start.")); + // SetCountdown(-1); + // Manager.GetLobby().DisplayWaiting(); + // } + // } + + /* + * Miscellaneous + */ + + @EventHandler + public void blockTeleport(MineplexTeleportEvent event) + { + if (!IsLive()) + return; + + event.setCancelled(true); + } + + @EventHandler + public void blockDeathEffectHeadModification(PlayerArmorStandManipulateEvent event) + { + ArmorStand armorStand = event.getRightClicked(); + + for (DeathEffectData data : _deathEffect.getData()) + { + if (data.isChickenHead(armorStand)) + { + event.setCancelled(true); + break; + } + } + } + + @EventHandler + public void blockDeathEffectHeadDamage(EntityDamageByEntityEvent event) + { + if (event.getEntity() instanceof ArmorStand) + { + ArmorStand armorStand = (ArmorStand) event.getEntity(); + + for (DeathEffectData data : _deathEffect.getData()) + { + if (data.getChickenHead().equals(armorStand)) + { + event.setCancelled(true); + return; + } + } + } + } + + @SuppressWarnings("deprecation") + @EventHandler + public void blockBlood(ItemSpawnEvent event) + { + if (!IsLive()) + return; + + Item blood = event.getEntity(); + ItemStack bloodItem = blood.getItemStack(); + + if (bloodItem.getType() == Material.INK_SACK && bloodItem.getData().getData() == 1) + { + if (bloodItem.hasItemMeta()) + { + if (bloodItem.getItemMeta().hasDisplayName()) + { + event.setCancelled(true); + } + } + } + } + + @EventHandler + public void blockInteract(PlayerInteractEvent event) + { + if (!_settings.isWaiting()) + return; + + event.setCancelled(true); + } + + @EventHandler + public void blockDrops(PlayerDropItemEvent event) + { + event.getItemDrop().remove(); + } + + @EventHandler + public void damage(CustomDamageEvent event) + { + event.SetDamageToLevel(false); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void blockDragonEgg(PlayerInteractEvent event) + { + if (!IsLive()) + return; + + // Added to control dragon egg locations. + + 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) + { + if (event.isCancelled()) // If controlled by another challenge, do not continue. + return; + + event.setCancelled(true); + } + } + } + + @EventHandler + public void removeFeetBlocks(GamePrepareCountdownCommence event) + { + removeSolidBlockForPlayers(); + } + + /* + * Scoreboard + */ + + @Override + @EventHandler + public void ScoreboardUpdate(UpdateEvent event) + { + if (event.getType() != UpdateType.FAST) + return; + + Scoreboard.Reset(); + + if (getPlayersWithRemainingLives() >= GENERIC_SCOREBOARD_PLAYER_COUNT) + { + displayGenericScoreboard(); + } + else + { + displayDetailedScoreboard(); + } + + Scoreboard.Draw(); + } + + private void displayGenericScoreboard() + { + displayPlayerTotal(); + displayAlivePlayers(); + displayCompletedPlayers(); + displayDeadPlayers(); + } + + private void displayPlayerTotal() + { + Scoreboard.WriteBlank(); + Scoreboard.Write(C.cYellow + C.Bold + "Players"); + Scoreboard.Write(getPlayersWithRemainingLives() + " "); + } + + private void displayAlivePlayers() + { + Scoreboard.WriteBlank(); + Scoreboard.Write(C.cGreen + C.Bold + "Alive"); + + if (_settings.isChallengeStarted()) + { + int data = _challenge.getPlayersIn(false).size(); + Scoreboard.Write("" + data); + } + else + { + Scoreboard.Write("-"); + } + } + + private void displayCompletedPlayers() + { + Scoreboard.WriteBlank(); + Scoreboard.Write(C.cGold + C.Bold + "Completed"); + + if (_settings.isChallengeStarted()) + { + int data = _challenge.getData().getCompletedPlayers().size(); + Scoreboard.Write("" + data); + } + else + { + Scoreboard.Write("-"); + } + } + + private void displayDeadPlayers() + { + Scoreboard.WriteBlank(); + Scoreboard.Write(C.cGray + C.Bold + "Dead"); + + if (_settings.isChallengeStarted()) + { + int data = _challenge.getData().getLostPlayers().size(); + Scoreboard.Write("" + data); + } + else + { + Scoreboard.Write("-"); + } + } + + private void displayDetailedScoreboard() + { + Scoreboard.WriteBlank(); + + for (Player player : super.GetPlayers(true)) // Use super.GetPlayers(true) to show players during chicken attack. + { + displayPersonalScore(player); + } + } + + private void displayPersonalScore(Player player) + { + int lives = lives(player); + String state = definePlayerState(player); + String display = definePlayerDisplay(player.getName(), lives, state); + + Scoreboard.WriteOrdered("Lives Left", display, lives, true); + } + + private String definePlayerDisplay(String name, int lives, String state) + { + switch (lives) + { + case MAX_LIVES: + return state + C.cGreen + name; + case LOST_ONE_LIFE: + return state + C.cYellow + name; + case LOST_TWO_LIVES: + return state + C.cGold + name; + case LOST_THREE_LIVES: + return state + C.cRed + name; + case LOST_FOUR_LIVES: + return state + C.cRed + name; + default: + return C.cGray + C.Strike + name; + } + } + + private String definePlayerState(Player player) + { + if (_settings.isChallengeStarted()) + { + ChallengeData data = _challenge.getData(); + + if (data.isLost(player)) + { + return C.cDRed + "X "; + } + else if (data.isCompleted(player)) + { + return C.cGreen + "✔ "; + } + } + + return ""; + } + + // @EventHandler + // public void debugCommands(PlayerCommandPreprocessEvent event) + // { + // Player player = event.getPlayer(); + // String message = event.getMessage(); + // + // if (Manager.GetClients().hasRank(player, Rank.SNR_MODERATOR)) + // { + // if (message.startsWith("/restrict")) + // { + // String[] pieces = message.split(" "); + // + // if (pieces.length > 1) + // { + // String challenge = F.combine(pieces, 1, null, false).trim(); + // + // if (_list.restrict(challenge)) + // { + // UtilPlayer.message(player, F.main("Game", "Restricted to " + F.elem(challenge) + " challenge.")); + // } + // else + // { + // UtilPlayer.message(player, F.main("Game", "Could not find any challenge by that name.")); + // } + // } + // else + // { + // UtilPlayer.message(player, F.main("Game", "All challenge restrictions were cleared.")); + // _list.unrestrict(); + // } + // + // event.setCancelled(true); + // } + // else if (message.startsWith("/skip")) + // { + // if (IsLive()) + // { + // endCurrentChallenge(); + // + // Announce(C.cAqua + C.Bold + player.getName() + " skipped this challenge."); + // } + // else + // { + // UtilPlayer.message(player, F.main("Game", "You cannot skip a challenge if the game is not started.")); + // } + // + // event.setCancelled(true); + // } + // else if (message.startsWith("/lose")) + // { + // if (IsLive() && _challenge != null && IsAlive(player)) + // { + // setLives(player, 0); + // _challenge.getData().addLostPlayer(player); + // _deathEffect.playDeath(player, player.getLocation()); + // GetScoreboard().ResetScore(player.getName()); + // _chickenAttack.start(player); + // } + // else + // { + // UtilPlayer.message(player, F.main("Game", "You cannot lose at this time.")); + // } + // + // event.setCancelled(true); + // } + // } + // } + + /* + * Helper methods + */ + + @Override + public boolean isInsideMap(Player player) + { + if (_challenge != null && !_settings.isWaiting()) + { + return _challenge.isInsideMap(player); + } + + return true; + } + + public int lives(Player player) + { + if (!_lives.containsKey(player)) + return 0; + + return _lives.get(player); + } + + /* + * Setter methods + */ + + public void setLives(Player player, int amount) + { + _lives.put(player, amount); + } + + /* + * Getter methods + */ + + public GameTeam getPlayerTeam() + { + return _playerTeam; + } + + public GameTeam getChickenTeam() + { + return _chickenTeam; + } + + public Challenge getCurrentChallenge() + { + return _challenge; + } + + public long getCurrentDelay() + { + return _delay; + } + + @Override + public List getWinners() + { + return _winners; + } + + public Map getLives() + { + return _lives; + } + + public BawkBawkBattlesSettings getSettings() + { + return _settings; + } + + public ChallengeList getChallengeList() + { + return _list; + } + + public DeathEffect getDeathEffect() + { + return _deathEffect; + } + + public ChickenAttack getChickenAttack() + { + return _chickenAttack; + } + + /* + * Player related getter methods + */ + + /** + * Returns the list of players contained on the player's team. + * + * @param aliveOnly Whether or not to select all players. + */ + @Override + public ArrayList GetPlayers(boolean aliveOnly) + { + if (_playerTeam != null) + return _playerTeam.GetPlayers(aliveOnly); + else + return super.GetPlayers(aliveOnly); + } + + /** + * Returns the list of players that are alive. + *
+ * Players are considered to be alive after they are teleported to challenge spawn locations. + */ + public ArrayList getPlayersAlive() + { + ArrayList list = new ArrayList(); + + for (Player player : GetPlayers(true)) + { + if (!UtilPlayer.isSpectator(player)) + { + list.add(player); + } + } + + return list; + } + + /** + * Returns the amount of players with more than one life. + */ + public int getPlayersWithRemainingLives() + { + int amount = 0; + + for (Player player : _lives.keySet()) + { + if (lives(player) > 0) + { + amount++; + } + } + + return amount; + } + + /* + * Inherited methods + */ + + @Override + public void Collide(LivingEntity target, Block block, ProjectileUser data) + { + if (_challenge != null) + { + if (_challenge.isChallengeValid()) + { + _challenge.onCollide(target, block, data); + } + } + + if (data.getThrown() instanceof Chicken) + { + if (target instanceof Player) + { + Player player = (Player) target; + + if (_chickenTeam.HasPlayer(player) && IsAlive(player)) + { + player.playSound(player.getLocation(), Sound.CHICKEN_HURT, CHICKEN_HIT_PLAYER_SOUND_VOLUME, CHICKEN_HIT_PLAYER_SOUND_PITCH); + player.damage(CHICKEN_HIT_PLAYER_DAMAGE); + + if (UtilMath.random.nextBoolean()) + { + UtilTextBottom.display(C.cRed + C.Bold + "bawk bawk!", player); + } + } + } + } + } + + @Override + public void Idle(ProjectileUser data) + { + + } + + @Override + public void Expire(ProjectileUser data) + { + + } +} \ No newline at end of file diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/BawkBawkBattlesSettings.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/BawkBawkBattlesSettings.java new file mode 100644 index 000000000..0336c9ae6 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/BawkBawkBattlesSettings.java @@ -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; + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/Challenge.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/Challenge.java deleted file mode 100644 index baf73e9e9..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/Challenge.java +++ /dev/null @@ -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 Completed = new HashSet(); - protected HashSet Lost = new HashSet(); - private HashSet _modifiedBlocks = new HashSet(); - 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 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 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 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 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 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(); - } - -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/ChallengeSeperateRooms.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/ChallengeSeperateRooms.java deleted file mode 100644 index 4038d9fc3..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/ChallengeSeperateRooms.java +++ /dev/null @@ -1,150 +0,0 @@ -package nautilus.game.arcade.game.games.mineware; - -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; - -public abstract class ChallengeSeperateRooms extends Challenge -{ - private HashMap _borders = new HashMap(); - private HashMap> _spawns = new HashMap>(); - private HashMap _rooms = new HashMap(); - private double _borderX, _borderZ; - - public ChallengeSeperateRooms(MineWare host, ChallengeType challengeType, String challengeName) - { - super(host, challengeType, challengeName); - } - - public Location getRoom(Player player) - { - System.out.print("2. " + player.getName()); - return _rooms.get(player.getName()).clone(); - } - - public void assignRooms() - { - for (Player player : getChallengers()) - { - for (Entry> entry : _spawns.entrySet()) - { - if (entry.getKey().distance(player.getLocation()) < 1) - { - System.out.print("1. " + player.getName()); - _rooms.put(player.getName(), entry.getValue().getValue()); - _borders.put(player.getName(), entry.getValue().getKey()); - break; - } - } - } - } - - public final void generateRoom() - { - int size = getChallengers().size(); - - int x = 1; - int z = 1; - - while (size > x * z) - { - if (x > z) - { - z++; - } - else - { - x++; - } - } - - _borderX = (x * getBorderX()) + (x * getDividersX()); - _borderZ = (z * getBorderZ()) + (z * getDividersZ()); - _borderX /= 2; - _borderZ /= 2; - _borderX = Math.ceil(_borderX); - _borderZ = Math.ceil(_borderZ); - - int players = 0; - - for (int x1 = 0; x1 < x; x1++) - { - for (int z1 = 0; z1 < z; z1++) - { - if (++players > size) - continue; - - double lX = (x1 * getBorderX()) + (x1 * getDividersX()); - double lZ = (z1 * getBorderZ()) + (z1 * getDividersZ()); - lX -= _borderX; - lZ -= _borderZ; - - Location loc = getCenter().clone().add(lX, 0, lZ); - - generateRoom(loc.clone()); - - _spawns.put(getSpawn(loc.clone()), new HashMap.SimpleEntry(new Integer[] - { - loc.getBlockX(), loc.getBlockX() + getBorderX(), - - loc.getBlockY(), loc.getBlockY() + getBorderY(), - - loc.getBlockZ(), loc.getBlockZ() + getBorderZ() - }, loc.clone())); - } - } - } - - @Override - public void StartOrder() - { - super.StartOrder(); - - setBorder((int) -Math.ceil(_borderX), (int) Math.ceil(_borderX), 0, 256, (int) -Math.ceil(_borderZ), - (int) Math.ceil(_borderZ)); - } - - public abstract void generateRoom(Location loc); - - public abstract int getBorderX(); - - public abstract int getBorderY(); - - public abstract int getBorderZ(); - - public abstract int getDividersX(); - - public abstract int getDividersZ(); - - public Location getSpawn(Location roomLocation) - { - return roomLocation.clone().add((getBorderX() + 1) / 2D, 1.1, (getBorderZ() + 1) / 2D); - } - - @Override - public ArrayList getSpawns() - { - return new ArrayList(_spawns.keySet()); - } - - public boolean isInsideMap(Player player) - { - Location loc = player.getLocation(); - - if (!_borders.containsKey(player.getName()) || UtilPlayer.isSpectator(player)) - { - return super.isInsideMap(player); - } - - Integer[] borders = _borders.get(player.getName()); - - return !(loc.getX() >= borders[1] + 1 || loc.getX() <= borders[0] || loc.getZ() >= borders[5] + 1 - || loc.getZ() <= borders[4] || loc.getY() >= borders[3] + 1 || loc.getY() <= borders[2]); - } - -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/MineWare.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/MineWare.java deleted file mode 100644 index ca74c8d3a..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/MineWare.java +++ /dev/null @@ -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 _lives = new HashMap(); - - private Challenge _order; - private ArrayList _lastOrderBlocks; - private long _orderTime; - private boolean _orderWaiting = true; - - private ArrayList> _orders = new ArrayList>(); - private ArrayList> _ordersCopy = new ArrayList>(); - - 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 getChallengers() - { - ArrayList challengers = new ArrayList(); - - 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 spawns = _order.getSpawns(); - - GetTeamList().get(0).SetSpawns(_order.getSpawns()); - SpectatorSpawn = UtilWorld.averageLocation(spawns).add(0, 7, 0); - - ArrayList toTeleport = new ArrayList(); - - 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( - _order.getModifiedBlocks()); - // Remove blocks from top to bottom, prevents blocks popping - // off. - Collections.sort(_lastOrderBlocks, new Comparator() - { - - @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(); - } -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/Challenge.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/Challenge.java new file mode 100644 index 000000000..384ab9280 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/Challenge.java @@ -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; + +/** + *

+ * 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()}. + *

+ * + * 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 + */ + public abstract ArrayList 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 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 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 players = new HashSet(); + 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 getPlayersAlive() + { + return Host.getPlayersAlive(); + } + + public ArrayList getPlayersIn(boolean ignoreCompleted) + { + ArrayList list = new ArrayList(); + + 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 circle(Location loc, Integer r, Integer h, Boolean hollow, Boolean sphere, int plusY) + { + List 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.
+ * Used for overriding purposes only. + */ + public void onTimerFinish() + { + + } + + public void onCollide(LivingEntity target, Block block, ProjectileUser data) + { + + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/ChallengeData.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/ChallengeData.java new file mode 100644 index 000000000..45fca3e1a --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/ChallengeData.java @@ -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 _spawns = new ArrayList<>(); + private Set _invisible = new HashSet<>(); + private Set _modifiedBlocks = new LinkedHashSet<>(); + private Set _completed = new HashSet<>(); + private Set _lost = new HashSet<>(); + + public void reset() + { + _spawns.clear(); + _invisible.clear(); + _modifiedBlocks.clear(); + _completed.clear(); + _lost.clear(); + } + + public void setSpawns(ArrayList spawns) + { + _spawns = spawns; + } + + public List 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 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 getModifiedBlocks() + { + return _modifiedBlocks; + } + + public void addCompletedPlayer(Player player) + { + _completed.add(player); + } + + public Set getCompletedPlayers() + { + return _completed; + } + + public boolean hasAnyoneCompleted() + { + return !_completed.isEmpty(); + } + + public void addLostPlayer(Player player) + { + _lost.add(player); + } + + public Set getLostPlayers() + { + return _lost; + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/ChallengeList.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/ChallengeList.java new file mode 100644 index 000000000..4a394b405 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/ChallengeList.java @@ -0,0 +1,87 @@ +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 _challenges = new ArrayList<>(); + private List _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)) + { + _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(); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/ChallengeSettings.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/ChallengeSettings.java new file mode 100644 index 000000000..52a4b4eb4 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/ChallengeSettings.java @@ -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 = 1; + 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; + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/ChallengeTeam.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/ChallengeTeam.java new file mode 100644 index 000000000..5610cc45a --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/ChallengeTeam.java @@ -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 _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 getPlayers() + { + return new ArrayList<>(_players); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/ChallengeType.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/ChallengeType.java new file mode 100644 index 000000000..a9d0e3d0a --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/ChallengeType.java @@ -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; + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/LogicTracker.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/LogicTracker.java new file mode 100644 index 000000000..312b58911 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/LogicTracker.java @@ -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); +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/NumberTracker.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/NumberTracker.java new file mode 100644 index 000000000..dc396837e --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/NumberTracker.java @@ -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); +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/TeamChallenge.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/TeamChallenge.java new file mode 100644 index 000000000..7c7ca7665 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/TeamChallenge.java @@ -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; + +/** + *

+ * 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()}. + *

+ * + * 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 firstTeam = _firstTeam.getPlayers(); + List secondTeam = _secondTeam.getPlayers(); + + int firstTeamIndex = 0; + int secondTeamIndex = 0; + + int players = Host.getPlayersWithRemainingLives(); + int teleported = 0; + + List 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 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; + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/other/ZombieWrapper.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/other/ZombieWrapper.java new file mode 100644 index 000000000..5e7e30c7f --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/other/ZombieWrapper.java @@ -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(); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeAnvilDance.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeAnvilDance.java new file mode 100644 index 000000000..dbbdd2be5 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeAnvilDance.java @@ -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 _landedAnvils = new HashSet<>(); + private Set _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 createSpawns() + { + ArrayList spawns = new ArrayList(); + 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 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 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 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()); + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeArrowRampage.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeArrowRampage.java new file mode 100644 index 000000000..08df13ac4 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeArrowRampage.java @@ -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 createSpawns() + { + ArrayList spawns = new ArrayList(); + 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 blocks = UtilBlock.getInRadius(arrow.getLocation(), ARROW_EXPLOSION_RADIUS).keySet(); + Iterator 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; + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeBlockLobbers.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeBlockLobbers.java new file mode 100644 index 000000000..cc784c0f4 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeBlockLobbers.java @@ -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 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 createSpawns() + { + ArrayList spawns = new ArrayList(); + + 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; + } + } + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeBouncingBlock.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeBouncingBlock.java new file mode 100644 index 000000000..dbe302bbc --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeBouncingBlock.java @@ -0,0 +1,359 @@ +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_DATA_RANGE = 16; + 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 _stepTracker = new ArrayList<>(); + private List _blocks = new ArrayList<>(); + private Map _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 createSpawns() + { + ArrayList spawns = new ArrayList(); + 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(false)) + { + 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(true); + } + + private void checkCompleted(Player player) + { + if (_score.get(player) >= SCORE_GOAL) + { + setCompleted(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 void spawnStartingWool() + { + for (int i = 0; i < Host.getPlayersWithRemainingLives() + 1; i++) + { + spawnRandomWool(false); + } + } + + private void spawnRandomWool(boolean firework) + { + 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; + + while (!Host.WorldData.World.getBlockAt(x, y, z).isEmpty()) + { + x = UtilMath.r(size * SCORE_BLOCK_BOUND_MULTIPLY) - size; + y = SCORE_BLOCK_HEIGHT + UtilMath.r(SCORE_BLOCK_HEIGHT_ADD); + z = UtilMath.r(size * SCORE_BLOCK_BOUND_MULTIPLY) - size; + } + + spawnRandomWoolAt(x, y, z, firework); + } + + @SuppressWarnings("deprecation") + private void spawnRandomWoolAt(int x, int y, int z, boolean firework) + { + 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); + + if (firework) + { + 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); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeBuildRace.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeBuildRace.java new file mode 100644 index 000000000..b2829b1b3 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeBuildRace.java @@ -0,0 +1,224 @@ +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 _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 createSpawns() + { + ArrayList spawns = new ArrayList(); + 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))) + { + 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 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 shuffledMaterials = new ArrayList(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); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeChickenShooting.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeChickenShooting.java new file mode 100644 index 000000000..abdec69e5 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeChickenShooting.java @@ -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 _chickens = new ArrayList<>(); + private List _chickenSpawns = new ArrayList<>(); + private Map _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 createSpawns() + { + ArrayList spawns = new ArrayList(); + 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) 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 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); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeCloudFall.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeCloudFall.java new file mode 100644 index 000000000..96661c9a9 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeCloudFall.java @@ -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. + * + * @deprecated + */ +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 createSpawns() + { + ArrayList spawns = new ArrayList(); + 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()); + } + } + + 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 }; + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeColorChange.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeColorChange.java new file mode 100644 index 000000000..67f62bdcf --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeColorChange.java @@ -0,0 +1,265 @@ +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 = 5000; + 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 _colors = new ArrayList<>(); + private int _currentColor; + private boolean _isFalling; + private long _lastSound; + private long _stageDelay; + private List> _lastGeneratedPlatforms = new ArrayList<>(); + + public ChallengeColorChange(BawkBawkBattles host) + { + super( + host, + ChallengeType.LastStanding, + "Color Change", + "Stand on the correct color."); + + Settings.setUseMapHeight(); + + populateColors(); + } + + @Override + public ArrayList createSpawns() + { + ArrayList spawns = new ArrayList(); + 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; + _lastGeneratedPlatforms.clear(); + } + + @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> 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 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 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); + } + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeDeadlyTnt.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeDeadlyTnt.java new file mode 100644 index 000000000..e61a8795f --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeDeadlyTnt.java @@ -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 createSpawns() + { + ArrayList spawns = new ArrayList(); + 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 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); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeDiamondHunt.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeDiamondHunt.java new file mode 100644 index 000000000..53fceeb9c --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeDiamondHunt.java @@ -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 createSpawns() + { + ArrayList spawns = new ArrayList(); + 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 inventories = new ArrayList(); + + 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(); + } + } + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeDogsVersusCats.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeDogsVersusCats.java new file mode 100644 index 000000000..86abbfedf --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeDogsVersusCats.java @@ -0,0 +1,337 @@ +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. + * + * @deprecated + */ +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 createSpawns() + { + ArrayList spawns = new ArrayList(); + 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; + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeEggSmash.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeEggSmash.java new file mode 100644 index 000000000..bf137e70a --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeEggSmash.java @@ -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 _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 createSpawns() + { + ArrayList spawns = new ArrayList(); + 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); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeEmpty.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeEmpty.java new file mode 100644 index 000000000..79ab58f6e --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeEmpty.java @@ -0,0 +1,42 @@ +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 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; + +/** + * This challenge is used to prevent the game from crashing if it's forced to start with only one player. + * + * @deprecated + */ +public class ChallengeEmpty extends Challenge +{ + public ChallengeEmpty(BawkBawkBattles host) + { + super(host, ChallengeType.FirstComplete, "Empty", "Not enough players"); + + Settings.setUseMapHeight(); + } + + @Override + public ArrayList createSpawns() + { + ArrayList spawns = new ArrayList<>(); + spawns.add(getCenter().add(0, 1, 0)); + return spawns; + } + + @Override + public void createMap() + { + Block center = getCenter().getBlock(); + center.setType(Material.BARRIER); + addBlock(center); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeFallingBlocks.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeFallingBlocks.java new file mode 100644 index 000000000..8024d10e7 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeFallingBlocks.java @@ -0,0 +1,383 @@ +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.6F; + + 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 _remaining = new HashSet<>(); + private int _arenaStartSize; + private Map _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 createSpawns() + { + ArrayList spawns = new ArrayList(); + 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; + + _waveTracker.remove(event.getPlayer()); + } + + 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); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeFastFood.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeFastFood.java new file mode 100644 index 000000000..221ca144d --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeFastFood.java @@ -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 createSpawns() + { + ArrayList spawns = new ArrayList(); + 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 items = UtilInv.getItems(player); + + if (items.size() == 0) + setCompleted(player); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeFishingDay.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeFishingDay.java new file mode 100644 index 000000000..d288ca70b --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeFishingDay.java @@ -0,0 +1,400 @@ +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. + * + * @deprecated + */ +public class ChallengeFishingDay extends Challenge +{ + private int _startingLureLevel = 8; + private Map _fishing = new HashMap<>(); + private Map _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 createSpawns() + { + int size = getArenaSize(); + ArrayList spawns = new ArrayList(); + + 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 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); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeKangarooJump.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeKangarooJump.java new file mode 100644 index 000000000..8cf448de8 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeKangarooJump.java @@ -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 createSpawns() + { + ArrayList spawns = new ArrayList(); + 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 heights = new HashMap<>(); + + for (Player player : getPlayersAlive()) + { + heights.put(player, player.getLocation().getBlockY()); + } + + List 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 sortHash(final Map unsortedMap) + { + ArrayList players = new ArrayList(unsortedMap.keySet()); + + Collections.sort(players, new Comparator() + { + @Override + public int compare(Player player1, Player player2) + { + Integer height1 = unsortedMap.get(player1); + Integer height2 = unsortedMap.get(player2); + + return height2.compareTo(height1); + } + }); + + return players; + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeKingOfTheLadder.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeKingOfTheLadder.java new file mode 100644 index 000000000..cc318c9e4 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeKingOfTheLadder.java @@ -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 createSpawns() + { + ArrayList spawns = new ArrayList(); + 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); + } + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeLavaRun.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeLavaRun.java new file mode 100644 index 000000000..311983f81 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeLavaRun.java @@ -0,0 +1,297 @@ +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 _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 createSpawns() + { + ArrayList spawns = new ArrayList(); + _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; + } + + _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 distance = new HashMap(); + + 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() + { + @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); + } + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeMilkACow.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeMilkACow.java new file mode 100644 index 000000000..d4fed513e --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeMilkACow.java @@ -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> _milkedCows = new HashMap<>(); + private Map _milkedCowsHolograms = new HashMap<>(); + private Map _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 createSpawns() + { + ArrayList spawns = new ArrayList(); + 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 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); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeMinecartDance.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeMinecartDance.java new file mode 100644 index 000000000..776ceed8e --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeMinecartDance.java @@ -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 _minecarts = new HashSet(); + + 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 createSpawns() + { + ArrayList spawns = new ArrayList(); + + 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); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeMiniOneInTheQuiver.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeMiniOneInTheQuiver.java new file mode 100644 index 000000000..76f2ce7db --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeMiniOneInTheQuiver.java @@ -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 _killTracker = new HashMap(); + + 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 createSpawns() + { + ArrayList spawns = new ArrayList(); + 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); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeNavigationMaze.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeNavigationMaze.java new file mode 100644 index 000000000..cbcc9648b --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeNavigationMaze.java @@ -0,0 +1,285 @@ +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. + * + * @deprecated + */ +public class ChallengeNavigationMaze extends Challenge implements NumberTracker +{ + private Map _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 createSpawns() + { + ArrayList spawns = new ArrayList(); + + 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 mazeBlocks = generateMaze(); + + for (Block mazeBlock : mazeBlocks) + { + addBlock(mazeBlock); + } + + // for (int i = 0; i < 30; i++) + // { + // ArrayList 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 blocks = new ArrayList(); + ArrayList nextLoop = new ArrayList(); + + 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 generateMaze() + { + ArrayList blocks = new ArrayList(); + 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); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeOreRun.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeOreRun.java new file mode 100644 index 000000000..cd55636cd --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeOreRun.java @@ -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 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 _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 createSpawns() + { + ArrayList spawns = new ArrayList(); + + 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); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengePickASide.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengePickASide.java new file mode 100644 index 000000000..4813e9532 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengePickASide.java @@ -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 createSpawns() + { + ArrayList spawns = new ArrayList(); + 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); + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengePunchThePig.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengePunchThePig.java new file mode 100644 index 000000000..907291010 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengePunchThePig.java @@ -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 _pigs = new HashSet<>(); + private Map _score = new HashMap<>(); + + public ChallengePunchThePig(BawkBawkBattles host) + { + super( + host, + ChallengeType.FirstComplete, + "Punch the Pig", + "Punch 5 pigs."); + + Settings.setUseMapHeight(); + } + + @Override + public ArrayList createSpawns() + { + ArrayList spawns = new ArrayList(); + 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)); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeRedLightGreenLight.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeRedLightGreenLight.java new file mode 100644 index 000000000..df3f3e458 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeRedLightGreenLight.java @@ -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 _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 createSpawns() + { + ArrayList spawns = new ArrayList(); + 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); + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeReverseTag.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeReverseTag.java new file mode 100644 index 000000000..2883ab39a --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeReverseTag.java @@ -0,0 +1,315 @@ +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 _cooldowns = new HashSet<>(); + private Map _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 createSpawns() + { + ArrayList spawns = new ArrayList(); + 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(); + + if (!isPlayerValid(player)) + return; + + _tagTracker.put(player, false); + } + + @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)) + { + _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; + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeRushPush.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeRushPush.java new file mode 100644 index 000000000..e87e88be6 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeRushPush.java @@ -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 the enemy team.", + "Push them off the platform."); + + Settings.setUseMapHeight(); + Settings.setCanCruble(); + Settings.setLockInventory(LOCKED_INVENTORY_SLOT); + Settings.setTeamBased(); + } + + @Override + public ArrayList createSpawns() + { + ArrayList spawns = new ArrayList(); + 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); + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeSmashOff.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeSmashOff.java new file mode 100644 index 000000000..ce05ed9bf --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeSmashOff.java @@ -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 createSpawns() + { + ArrayList spawns = new ArrayList(); + 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; + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeTreasureDigger.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeTreasureDigger.java new file mode 100644 index 000000000..2290d7452 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeTreasureDigger.java @@ -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 _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 createSpawns() + { + ArrayList spawns = new ArrayList(); + 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); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeVolleyPig.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeVolleyPig.java new file mode 100644 index 000000000..9c9f7c5d7 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeVolleyPig.java @@ -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. + * + * @deprecated + */ +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 createSpawns() + { + ArrayList spawns = new ArrayList(); + 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; + } + + @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; + } + } + + 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()); + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeWaterHorror.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeWaterHorror.java new file mode 100644 index 000000000..e6d5609bd --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeWaterHorror.java @@ -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 _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 createSpawns() + { + ArrayList spawns = new ArrayList(); + + 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 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); + } + } + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeWaveCrush.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeWaveCrush.java new file mode 100644 index 000000000..ace1cd80c --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeWaveCrush.java @@ -0,0 +1,307 @@ +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 _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 hit by them."); + + Settings.setUseMapHeight(); + } + + @Override + public ArrayList createSpawns() + { + ArrayList spawns = new ArrayList(); + 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; + + initializeWaveTracker(); + startWavesTask(); + } + + @Override + public void onEnd() + { + remove(EntityType.FALLING_BLOCK); + removeExtraBlocks(); + + _wavesPassed = 0; + _survivedWaves.clear(); + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) + { + if (!isChallengeValid()) + return; + + _survivedWaves.remove(event.getPlayer()); + } + + @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"); + subtractWaveCount(player); + } + } + } + + private byte getColor() + { + if (_colorCounter > COLOR_BLOCK_LENGTH) + { + _colorCounter = 0; + _colorIndex++; + + if (_colorIndex >= COLORS.length) + _colorIndex = 0; + } + + return COLORS[_colorIndex]; + } + + private void initializeWaveTracker() + { + for (Player player : getPlayersAlive()) + { + _survivedWaves.put(player, 0); + } + } + + private void subtractWaveCount(Player player) + { + if (Data.isLost(player) && _survivedWaves.get(player) > 0) + { + _survivedWaves.put(player, _survivedWaves.get(player) - 1); + } + } + + 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); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeZombieInfection.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeZombieInfection.java new file mode 100644 index 000000000..2d7dd04fe --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeZombieInfection.java @@ -0,0 +1,357 @@ +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. + * + * @deprecated + */ +public class ChallengeZombieInfection extends Challenge +{ + private ZombieWrapper _zombie; + private Set _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 createSpawns() + { + ArrayList spawns = new ArrayList(); + + 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"); + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/MazeGenerator.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/MazeGenerator.java similarity index 96% rename from Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/MazeGenerator.java rename to Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/MazeGenerator.java index 785911a54..ae65246eb 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/MazeGenerator.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/MazeGenerator.java @@ -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; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeBlockShot.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeBlockShot.java deleted file mode 100644 index 911c5e5a9..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeBlockShot.java +++ /dev/null @@ -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 _shotBlocks = new HashMap(); - private ArrayList _spawns = new ArrayList(); - private ArrayList _arrows = new ArrayList(); - - public ChallengeBlockShot(MineWare host) - { - super(host, ChallengeType.FirstComplete, "Shoot down 5 blocks"); - } - - @Override - public ArrayList 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(); - } - } - -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeBuildBuilding.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeBuildBuilding.java deleted file mode 100644 index 9d87a6adb..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeBuildBuilding.java +++ /dev/null @@ -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 _materials = new ArrayList(); - private HashMap _build = new HashMap(); - - 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); - } - } - -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeChestLoot.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeChestLoot.java deleted file mode 100644 index 9b28b87b5..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeChestLoot.java +++ /dev/null @@ -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 getSpawns() - { - ArrayList spawns = new ArrayList(); - - 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 invs = new ArrayList(); - - 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)); - } - } -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeChickenFishing.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeChickenFishing.java deleted file mode 100644 index 0e4a4b3db..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeChickenFishing.java +++ /dev/null @@ -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 _chickens = new ArrayList(); - private ArrayList _spawns = new ArrayList(); - private ArrayList _chickenSpawns = new ArrayList(); - - public ChallengeChickenFishing(MineWare host) - { - super(host, ChallengeType.FirstComplete, "Chicken Fishing"); - } - - @Override - public ArrayList getSpawns() - { - return _spawns; - } - - @EventHandler - public void onSecond(UpdateEvent event) - { - if (event.getType() != UpdateType.FAST) - { - return; - } - - Iterator 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)); - } - } -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeDiamondFall.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeDiamondFall.java deleted file mode 100644 index 6a40799fe..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeDiamondFall.java +++ /dev/null @@ -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 diamonds = new HashMap(); - ArrayList 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() - { - - @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 getSpawns() - { - ArrayList locations = new ArrayList(); - - 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() - { - } - -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeDragonEgg.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeDragonEgg.java deleted file mode 100644 index c472b72f3..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeDragonEgg.java +++ /dev/null @@ -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 _smashedEggs = new HashMap(); - private ArrayList _dragonEggs = new ArrayList(); - - public ChallengeDragonEgg(MineWare host) - { - super(host, ChallengeType.FirstComplete, "Whack a dragon egg 10 times"); - } - - @Override - public ArrayList getSpawns() - { - ArrayList spawns = new ArrayList(); - - 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); - } - } - -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeHitTargets.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeHitTargets.java deleted file mode 100644 index fbb0f7dd4..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeHitTargets.java +++ /dev/null @@ -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> _targets = new HashMap>(); - 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 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 getSpawns() - { - ArrayList spawns = new ArrayList(); - - 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 players = getChallengers(); - - for (Player player : players) - { - ArrayList names = new ArrayList(); - - 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); - } - } - } - } - } - -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeLavaRun.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeLavaRun.java deleted file mode 100644 index ce3d21651..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeLavaRun.java +++ /dev/null @@ -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 getSpawns() - { - ArrayList spawns = new ArrayList(); - - 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 glassBlocks = new ArrayList(); - - 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 distance = new HashMap(); - - for (Block b : glassBlocks) - { - distance.put(b, b.getLocation().add(0.5, 0, 0.5).distance(_obsidian)); - } - - Collections.sort(glassBlocks, new Comparator() - { - - @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); - } - -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeMilkACow.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeMilkACow.java deleted file mode 100644 index 2ce37789a..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeMilkACow.java +++ /dev/null @@ -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> _milked = new HashMap>(); - private HashMap _score = new HashMap(); - - 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()); - } - - 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 getSpawns() - { - ArrayList spawns = new ArrayList(); - - 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; - } -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeNameThatSound.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeNameThatSound.java deleted file mode 100644 index 1b84f183d..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeNameThatSound.java +++ /dev/null @@ -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 _sounds = new HashMap(); - private ArrayList, Float>> _toPlay = new ArrayList, Float>>(); - private HashMap _currentState = new HashMap(); - private HashMap> _mobs = new HashMap>(); - private HashMap _lastGuess = new HashMap(); - - 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, 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 = new ArrayList(); - - 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 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()); - - spawnMobs(player, 0); - player.playSound(player.getLocation(), _toPlay.get(0).getKey().getValue(), 5, _toPlay.get(0).getValue()); - } - } - -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeNavigateMaze.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeNavigateMaze.java deleted file mode 100644 index dbba0795d..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeNavigateMaze.java +++ /dev/null @@ -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 getSpawns() - { - ArrayList spawns = new ArrayList(); - - 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 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 blocks = new ArrayList(); - ArrayList nextLoop = new ArrayList(); - - 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 generateMaze() - { - ArrayList blocks = new ArrayList(); - 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; - } -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengePickASide.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengePickASide.java deleted file mode 100644 index 21bc945e7..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengePickASide.java +++ /dev/null @@ -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 getSpawns() - { - ArrayList spawns = new ArrayList(); - - 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 red = new ArrayList(); - ArrayList blue = new ArrayList(); - ArrayList misc = new ArrayList(); - - 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); - } - } - } - } - } - -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeRunner.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeRunner.java deleted file mode 100644 index 77c7ea2e0..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeRunner.java +++ /dev/null @@ -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 _fallingBlocks = new ArrayList(); - - public ChallengeRunner(MineWare host) - { - super(host, ChallengeType.LastStanding, - "Blocks are disappearing beneath you! Run away!"); - } - - @Override - public ArrayList getSpawns() - { - return _spawns; - } - - @Override - public void cleanupRoom() - { - for (Entity ent : _fallingBlocks) - { - ent.remove(); - } - } - - @Override - public void setupPlayers() - { - } - - private ArrayList _spawns = new ArrayList(); - - @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 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 _blocks = new HashMap(); - -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeShootChickens.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeShootChickens.java deleted file mode 100644 index 5bf0b4bab..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeShootChickens.java +++ /dev/null @@ -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 _chickens = new ArrayList(); - private HashMap _killedChickens = new HashMap(); - private ArrayList _arrows = new ArrayList(); - - 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 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 getSpawns() - { - ArrayList spawns = new ArrayList(); - - 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; - } -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeSkyFall.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeSkyFall.java deleted file mode 100644 index 1408f1d2d..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeSkyFall.java +++ /dev/null @@ -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 getSpawns() - { - ArrayList locations = new ArrayList(); - - 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); - } - } -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeSmashOff.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeSmashOff.java deleted file mode 100644 index 7527e633b..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeSmashOff.java +++ /dev/null @@ -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 _spawns = new ArrayList(); - - public ChallengeSmashOff(MineWare host) - { - super(host, ChallengeType.LastStanding, "Knock the other players off!"); - } - - @Override - public ArrayList 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; - } - } - } - } - -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeSpleef.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeSpleef.java deleted file mode 100644 index 3619626c2..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeSpleef.java +++ /dev/null @@ -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 getSpawns() - { - ArrayList spawns = new ArrayList(); - - 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); - } - } - } - } - -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeStandOnColor.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeStandOnColor.java deleted file mode 100644 index 34b9734cd..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeStandOnColor.java +++ /dev/null @@ -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 _colors = new ArrayList(); - 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> cords = new ArrayList>(); - - 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 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 getSpawns() - { - ArrayList spawns = new ArrayList(); - - 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)); - } - } - } - -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeTntLauncher.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeTntLauncher.java deleted file mode 100644 index d7879a713..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeTntLauncher.java +++ /dev/null @@ -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 _spawns = new ArrayList(); - private ArrayList _tnt = new ArrayList(); - - public ChallengeTntLauncher(MineWare host) - { - super(host, ChallengeType.LastStanding, "Throw TNT, don't get knocked off!"); - } - - @Override - public ArrayList 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 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)); - } - } - } - -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeVolleyPig.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeVolleyPig.java deleted file mode 100644 index ce69eba1f..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeVolleyPig.java +++ /dev/null @@ -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 getSpawns() - { - ArrayList locations = new ArrayList(); - - 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); - } - } - } - } - } - -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/effect/ChickenAttack.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/effect/ChickenAttack.java new file mode 100644 index 000000000..02f34c55d --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/effect/ChickenAttack.java @@ -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 _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 commands. Now his chickens will devour 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 getChickens() + { + return _chickens; + } + + public Location getPlatformCenter() + { + return _center; + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/effect/DeathEffect.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/effect/DeathEffect.java new file mode 100644 index 000000000..66aa34f60 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/effect/DeathEffect.java @@ -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 _data = new ArrayList(); + + 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 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 getData() + { + return _data; + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/effect/DeathEffectData.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/effect/DeathEffectData.java new file mode 100644 index 000000000..6ceb109dc --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/effect/DeathEffectData.java @@ -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 _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 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 getFoodItems() + { + return _foodItems; + } + + public ArmorStand getChickenHead() + { + return _chickenHead; + } + + public Hologram getHologram() + { + return _hologram; + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/effect/DeathText.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/effect/DeathText.java new file mode 100644 index 000000000..93b09a236 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/effect/DeathText.java @@ -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); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/events/ChallengeEndEvent.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/events/ChallengeEndEvent.java new file mode 100644 index 000000000..0710ae650 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/events/ChallengeEndEvent.java @@ -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(); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/events/ChallengeStartEvent.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/events/ChallengeStartEvent.java new file mode 100644 index 000000000..f26018f40 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/events/ChallengeStartEvent.java @@ -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(); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/kit/KitBawksFood.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/kit/KitBawksFood.java new file mode 100644 index 000000000..cb4bd631e --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/kit/KitBawksFood.java @@ -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; + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/tracker/BouncingShadowTracker.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/tracker/BouncingShadowTracker.java new file mode 100644 index 000000000..fa18c7066 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/tracker/BouncingShadowTracker.java @@ -0,0 +1,40 @@ +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. + *
+ *
+ * Challenge: Bouncing Block + *
+ * Goal: 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().isCompleted(player)) + { + addStat(player, "BouncingShadow", 1, false, false); + } + } + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/tracker/ChallengeStatTracker.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/tracker/ChallengeStatTracker.java new file mode 100644 index 000000000..8829f809b --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/tracker/ChallengeStatTracker.java @@ -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 +{ + 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); +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/tracker/DragonKingTracker.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/tracker/DragonKingTracker.java new file mode 100644 index 000000000..717363810 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/tracker/DragonKingTracker.java @@ -0,0 +1,45 @@ +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. + *
+ *
+ * Challenge: Egg Smash + *
+ * Goal: 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) + { + addStat(player, "DragonKing", score, false, false); + } + } + } + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/tracker/EliteArcherTracker.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/tracker/EliteArcherTracker.java new file mode 100644 index 000000000..ae654b4f3 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/tracker/EliteArcherTracker.java @@ -0,0 +1,45 @@ +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. + *
+ *
+ * Challenge: Mini OITQ + *
+ * Goal: 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) + { + addStat(player, "EliteArcher", score, false, false); + } + } + } + } + } +} \ No newline at end of file diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/tracker/MilkManTracker.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/tracker/MilkManTracker.java new file mode 100644 index 000000000..11c11a92e --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/tracker/MilkManTracker.java @@ -0,0 +1,45 @@ +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. + *
+ *
+ * Challenge: Milk a Cow + *
+ * Goal: 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) + { + addStat(player, "MilkMan", score, false, false); + } + } + } + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/tracker/PinataMasterTracker.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/tracker/PinataMasterTracker.java new file mode 100644 index 000000000..c45c23d71 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/tracker/PinataMasterTracker.java @@ -0,0 +1,45 @@ +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. + *
+ *
+ * Challenge: Chicken Shooting + *
+ * Goal: 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) + { + addStat(player, "PinataMaster", score, false, false); + } + } + } + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/tracker/PixelNinjaTracker.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/tracker/PixelNinjaTracker.java new file mode 100644 index 000000000..05401270e --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/tracker/PixelNinjaTracker.java @@ -0,0 +1,45 @@ +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. + *
+ *
+ * Challenge: Falling Blocks + *
+ * Goal: 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) + { + addStat(player, "PixelNinja", score, false, false); + } + } + } + } + } +} \ No newline at end of file diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/tracker/SpeedyBuildersTracker.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/tracker/SpeedyBuildersTracker.java new file mode 100644 index 000000000..205995bf2 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/tracker/SpeedyBuildersTracker.java @@ -0,0 +1,42 @@ +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. + *
+ *
+ * Challenge: Build Race + *
+ * Goal: 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)) + { + addStat(player, "SpeedyBuilders", 1, false, false); + } + } + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/tracker/SurfUpTracker.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/tracker/SurfUpTracker.java new file mode 100644 index 000000000..b976ca2d8 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/tracker/SurfUpTracker.java @@ -0,0 +1,45 @@ +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. + *
+ *
+ * Challenge: Wave Crush + *
+ * Goal: 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) + { + addStat(player, "SurfUp", score, false, false); + } + } + } + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/tracker/TagMasterTracker.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/tracker/TagMasterTracker.java new file mode 100644 index 000000000..fd672eebc --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/tracker/TagMasterTracker.java @@ -0,0 +1,40 @@ +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. + *
+ *
+ * Challenge: Tag Master + *
+ * Goal: 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 : getGame().GetPlayers(true)) + { + if (reverseTag.hasData(player)) + { + addStat(player, "TagMaster", 1, false, false); + } + } + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/tracker/VeteranTracker.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/tracker/VeteranTracker.java new file mode 100644 index 000000000..debcf47ae --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/tracker/VeteranTracker.java @@ -0,0 +1,38 @@ +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. + *
+ *
+ * Goal: Win 50 games of Bawk Bawk Battles + */ +public class VeteranTracker extends StatTracker +{ + 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) + { + addStat(winner, "Veteran", 1, true, false); + } + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sheep/modes/EweHeroes.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sheep/modes/EweHeroes.java index 71518e536..75895091d 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sheep/modes/EweHeroes.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sheep/modes/EweHeroes.java @@ -59,6 +59,9 @@ public class EweHeroes extends SheepGame { if (event.getType() != UpdateType.FASTER) return; + + if (!IsLive()) + return; for (Player player : GetPlayers(true)) { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sheep/modes/OverpoweredSheepQuest.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sheep/modes/OverpoweredSheepQuest.java new file mode 100644 index 000000000..7d924941d --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sheep/modes/OverpoweredSheepQuest.java @@ -0,0 +1,36 @@ +package nautilus.game.arcade.game.games.sheep.modes; + +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.GameType; +import nautilus.game.arcade.game.games.AbsorptionFix; +import nautilus.game.arcade.game.games.sheep.SheepGame; +import nautilus.game.arcade.game.games.sheep.modes.kits.KitShepherd; +import nautilus.game.arcade.kit.Kit; + +/** + * OverpoweredSheepQuest + * + * @author xXVevzZXx + */ +public class OverpoweredSheepQuest extends SheepGame +{ + + public OverpoweredSheepQuest(ArcadeManager manager) + { + super(manager, new Kit[] + { + new KitShepherd(manager) + }, GameType.Brawl); + + TeamArmor = false; + + new AbsorptionFix(this); + } + + @Override + public String GetMode() + { + return "OP Sheep Quest"; + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sheep/modes/SmashSheep.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sheep/modes/SmashSheep.java new file mode 100644 index 000000000..9d04af1f3 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sheep/modes/SmashSheep.java @@ -0,0 +1,116 @@ +package nautilus.game.arcade.game.games.sheep.modes; + +import org.bukkit.Material; +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.inventory.ItemStack; + +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.game.games.sheep.SheepGame; +import nautilus.game.arcade.game.games.smash.kits.KitBlaze; +import nautilus.game.arcade.game.games.smash.kits.KitChicken; +import nautilus.game.arcade.game.games.smash.kits.KitCow; +import nautilus.game.arcade.game.games.smash.kits.KitCreeper; +import nautilus.game.arcade.game.games.smash.kits.KitEnderman; +import nautilus.game.arcade.game.games.smash.kits.KitGolem; +import nautilus.game.arcade.game.games.smash.kits.KitMagmaCube; +import nautilus.game.arcade.game.games.smash.kits.KitPig; +import nautilus.game.arcade.game.games.smash.kits.KitSheep; +import nautilus.game.arcade.game.games.smash.kits.KitSkeletalHorse; +import nautilus.game.arcade.game.games.smash.kits.KitSkeleton; +import nautilus.game.arcade.game.games.smash.kits.KitSkySquid; +import nautilus.game.arcade.game.games.smash.kits.KitSlime; +import nautilus.game.arcade.game.games.smash.kits.KitSnowman; +import nautilus.game.arcade.game.games.smash.kits.KitSpider; +import nautilus.game.arcade.game.games.smash.kits.KitWitch; +import nautilus.game.arcade.game.games.smash.kits.KitWitherSkeleton; +import nautilus.game.arcade.game.games.smash.kits.KitWolf; +import nautilus.game.arcade.game.games.smash.kits.KitZombie; +import nautilus.game.arcade.kit.Kit; + +/** + * SheepSmash + * + * @author xXVevzZXx + */ +public class SmashSheep extends SheepGame +{ + + public SmashSheep(ArcadeManager manager) + { + super(manager, new Kit[] + { + new KitSkeleton(manager), + new KitGolem(manager), + new KitSpider(manager), + new KitSlime(manager), + + new KitCreeper(manager), + new KitEnderman(manager), + new KitSnowman(manager), + new KitWolf(manager), + + + new KitBlaze(manager), + new KitWitch(manager), + new KitChicken(manager), + new KitSkeletalHorse(manager), + new KitPig(manager), + new KitSkySquid(manager), + new KitWitherSkeleton(manager), + new KitMagmaCube(manager), + new KitZombie(manager), + new KitCow(manager), + + new KitSheep(manager) + }, GameType.Brawl); + } + + @EventHandler + public void saddle(UpdateEvent event) + { + if (event.getType() != UpdateType.FASTER) + return; + + if (!IsLive()) + return; + + for (Player player : GetPlayers(true)) + { + player.getInventory().setItem(7, new ItemStack(Material.SADDLE)); + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void noFallDamage(CustomDamageEvent event) + { + if (event.IsCancelled()) + return; + + if (event.GetCause() == DamageCause.FALL) + event.SetCancelled("No Fall Damage"); + } + + @EventHandler(priority = EventPriority.HIGH) + public void customKnockback(CustomDamageEvent event) + { + if (event.IsCancelled()) + return; + + if (event.GetDamageePlayer() != null) + event.AddKnockback("Smash Knockback", 1 + 0.1 * (20 - event.GetDamageePlayer().getHealth())); + } + + @Override + public String GetMode() + { + return "Smash Sheep"; + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sheep/modes/kits/KitShepherd.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sheep/modes/kits/KitShepherd.java new file mode 100644 index 000000000..9c52874ec --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sheep/modes/kits/KitShepherd.java @@ -0,0 +1,65 @@ +package nautilus.game.arcade.game.games.sheep.modes.kits; + +import mineplex.core.common.util.C; +import mineplex.core.itemstack.ItemStackFactory; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.kit.KitAvailability; +import nautilus.game.arcade.kit.Perk; +import nautilus.game.arcade.kit.ProgressingKit; +import nautilus.game.arcade.kit.perks.PerkDoubleJump; +import nautilus.game.arcade.kit.perks.PerkFletcher; + +import org.bukkit.Material; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +public class KitShepherd extends ProgressingKit +{ + private static final String[] DESCRIPTION = { + "Most skilled Shepherd from all over the World", + "", + C.cYellow + "Double tap " + C.cWhite + "your jump key to " + C.cGreen + "Double Jump" + }; + + private static final Perk[] PERKS = { + new PerkDoubleJump("Double Jump", 1.2, 1.2, true, 8000, true), + new PerkFletcher(4, 10, true) + }; + + private static final ItemStack IN_HAND = new ItemStack(Material.IRON_AXE); + + private static final ItemStack[] PLAYER_ITEMS = { + ItemStackFactory.Instance.CreateStack(Material.DIAMOND_SWORD), + ItemStackFactory.Instance.CreateStack(Material.GOLDEN_APPLE, 2), + ItemStackFactory.Instance.CreateStack(Material.BOW), + ItemStackFactory.Instance.CreateStack(Material.SADDLE, (byte) 0, 1, + C.cYellow + C.Bold + "Hold This" + C.cWhite + C.Bold + " - " + C.cGreen + C.Bold + "Grab/Hold Sheep") + }; + + public KitShepherd(ArcadeManager manager) + { + super(manager, "Shepherd of the gods", "sheepsheperd", KitAvailability.Free, DESCRIPTION, PERKS, EntityType.ZOMBIE, IN_HAND); + } + + @Override + public void GiveItems(Player player) + { + player.getInventory().addItem(PLAYER_ITEMS); + + player.getInventory().setHelmet(new ItemStack(Material.DIAMOND_HELMET)); + player.getInventory().setChestplate(new ItemStack(Material.DIAMOND_CHESTPLATE)); + player.getInventory().setLeggings(new ItemStack(Material.DIAMOND_LEGGINGS)); + player.getInventory().setBoots(new ItemStack(Material.DIAMOND_BOOTS)); + } + + @Override + public void SpawnCustom(LivingEntity ent) + { + ent.getEquipment().setHelmet(new ItemStack(Material.DIAMOND_HELMET)); + ent.getEquipment().setChestplate(new ItemStack(Material.DIAMOND_CHESTPLATE)); + ent.getEquipment().setLeggings(new ItemStack(Material.DIAMOND_LEGGINGS)); + ent.getEquipment().setBoots(new ItemStack(Material.DIAMOND_BOOTS)); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/Skywars.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/Skywars.java index a99565c9a..22bdc6d79 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/Skywars.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/Skywars.java @@ -133,17 +133,22 @@ public abstract class Skywars extends Game private ChestLoot _middleProjectile = new ChestLoot(); private ChestLoot _middleBlock = new ChestLoot(); - @SuppressWarnings("unchecked") public Skywars(ArcadeManager manager, GameType type, String[] description) { - super(manager, type, new Kit[] + this(manager, new Kit[] { new KitChicken(manager), new KitMiner(manager), new KitMadScientist(manager), new KitDestructor(manager), - }, description); + }, type, description); + } + + @SuppressWarnings("unchecked") + public Skywars(ArcadeManager manager, Kit[] kits, GameType type, String[] description) + { + super(manager, type, kits, description); PrepareFreeze = true; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/SoloSkywars.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/SoloSkywars.java index a77873967..207ee85e8 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/SoloSkywars.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/SoloSkywars.java @@ -17,7 +17,7 @@ import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.GameType; import nautilus.game.arcade.events.GameStateChangeEvent; import nautilus.game.arcade.game.GameTeam; -import nautilus.game.arcade.game.Game.GameState; +import nautilus.game.arcade.kit.Kit; import nautilus.game.arcade.stats.DeathBomberStatTracker; import nautilus.game.arcade.stats.SkywarsKillZombieStatTracker; import nautilus.game.arcade.stats.SkywarsTNTStatTracker; @@ -61,25 +61,20 @@ public class SoloSkywars extends Skywars "Last player alive wins!" }); - this.DamageTeamSelf = true; - - registerStatTrackers( - new SkywarsTNTStatTracker(this), - new DeathBomberStatTracker(this, 3), //TNT Kills - new SkywarsKillZombieStatTracker(this), - new WinWithoutOpeningChestStatTracker(this), - new WinWithoutWearingArmorStatTracker(this)); - - registerChatStats( - Kills, - Deaths, - KDRatio, - BlankLine, - Assists, - DamageTaken, - DamageDealt - ); + this.DamageTeamSelf = true; + } + + public SoloSkywars(ArcadeManager manager, Kit[] kits, GameType type) + { + super(manager, kits, type, + new String[] + { + "Free for all battle in the sky!", + "Craft or loot gear for combat", + "Last player alive wins!" + }); + this.DamageTeamSelf = true; } @EventHandler diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/modes/OverpoweredSkywars.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/modes/OverpoweredSkywars.java index 561acb4c4..7f971dc34 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/modes/OverpoweredSkywars.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/modes/OverpoweredSkywars.java @@ -7,8 +7,14 @@ import org.bukkit.block.Block; import org.bukkit.block.Chest; import org.bukkit.enchantments.Enchantment; 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.UtilAction; +import mineplex.core.common.util.UtilEvent; +import mineplex.core.common.util.UtilEvent.ActionType; import mineplex.core.common.util.UtilMath; import mineplex.core.loot.ChestLoot; import mineplex.core.loot.RandomItem; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/modes/SkySmash.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/modes/SkySmash.java new file mode 100644 index 000000000..bc3ac34ed --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/modes/SkySmash.java @@ -0,0 +1,121 @@ +package nautilus.game.arcade.game.games.skywars.modes; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; + +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.recharge.Recharge; +import mineplex.minecraft.game.core.damage.CustomDamageEvent; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.GameType; +import nautilus.game.arcade.game.games.skywars.SoloSkywars; +import nautilus.game.arcade.game.games.smash.kits.KitBlaze; +import nautilus.game.arcade.game.games.smash.kits.KitChicken; +import nautilus.game.arcade.game.games.smash.kits.KitCow; +import nautilus.game.arcade.game.games.smash.kits.KitCreeper; +import nautilus.game.arcade.game.games.smash.kits.KitEnderman; +import nautilus.game.arcade.game.games.smash.kits.KitGolem; +import nautilus.game.arcade.game.games.smash.kits.KitMagmaCube; +import nautilus.game.arcade.game.games.smash.kits.KitPig; +import nautilus.game.arcade.game.games.smash.kits.KitSheep; +import nautilus.game.arcade.game.games.smash.kits.KitSkeletalHorse; +import nautilus.game.arcade.game.games.smash.kits.KitSkeleton; +import nautilus.game.arcade.game.games.smash.kits.KitSkySquid; +import nautilus.game.arcade.game.games.smash.kits.KitSlime; +import nautilus.game.arcade.game.games.smash.kits.KitSnowman; +import nautilus.game.arcade.game.games.smash.kits.KitSpider; +import nautilus.game.arcade.game.games.smash.kits.KitWitch; +import nautilus.game.arcade.game.games.smash.kits.KitWitherSkeleton; +import nautilus.game.arcade.game.games.smash.kits.KitWolf; +import nautilus.game.arcade.game.games.smash.kits.KitZombie; +import nautilus.game.arcade.kit.Kit; + +/** + * SkySmash + * + * @author xXVevzZXx + */ +public class SkySmash extends SoloSkywars +{ + + public SkySmash(ArcadeManager manager) + { + super(manager, new Kit[] + { + new KitSkeleton(manager), + new KitGolem(manager), + new KitSpider(manager), + new KitSlime(manager), + + new KitCreeper(manager), + new KitEnderman(manager), + new KitSnowman(manager), + new KitWolf(manager), + + + new KitBlaze(manager), + new KitWitch(manager), + new KitChicken(manager), + new KitSkeletalHorse(manager), + new KitPig(manager), + new KitSkySquid(manager), + new KitWitherSkeleton(manager), + new KitMagmaCube(manager), + new KitZombie(manager), + new KitCow(manager), + + new KitSheep(manager) + }, GameType.Brawl); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void noFallDamage(CustomDamageEvent event) + { + if (event.IsCancelled()) + return; + + if (event.GetCause() == DamageCause.FALL) + event.SetCancelled("No Fall Damage"); + } + + @EventHandler(priority = EventPriority.HIGH) + public void customKnockback(CustomDamageEvent event) + { + if (event.IsCancelled()) + return; + + if (event.GetDamageePlayer() != null) + event.AddKnockback("Smash Knockback", 1 + 0.1 * (20 - event.GetDamageePlayer().getHealth())); + } + + @EventHandler(priority = EventPriority.MONITOR) + public void hungerOnHit(CustomDamageEvent event) + { + if (event.IsCancelled()) + return; + + Player damager = event.GetDamagerPlayer(true); + if (damager == null) + return; + + if (damager.equals(event.GetDamageeEntity())) + return; + + if (!(event.GetDamageeEntity() instanceof Player)) + return; + + if (!Recharge.Instance.use(damager, "Hunger Restore", 250, false, false)) + return; + + int amount = Math.max(1, (int)(event.GetDamage()/2)); + UtilPlayer.hunger(damager, amount); + } + + @Override + public String GetMode() + { + return "Sky Smash"; + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/modes/RandomKitSSM.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/modes/RandomKitSSM.java index e756c89e6..1f90c3a95 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/modes/RandomKitSSM.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/modes/RandomKitSSM.java @@ -31,7 +31,7 @@ import nautilus.game.arcade.game.games.smash.kits.KitWitch; import nautilus.game.arcade.game.games.smash.kits.KitWitherSkeleton; import nautilus.game.arcade.game.games.smash.kits.KitWolf; import nautilus.game.arcade.game.games.smash.kits.KitZombie; -import nautilus.game.arcade.game.games.smash.modes.kits.KitPlayer; +import nautilus.game.arcade.game.games.smash.modes.kits.KitHipster; import nautilus.game.arcade.kit.Kit; import nautilus.game.arcade.kit.Perk; @@ -49,7 +49,7 @@ public class RandomKitSSM extends SoloSuperSmash public RandomKitSSM(ArcadeManager manager) { - super(manager, new Kit[]{new KitPlayer(manager)}, GameType.Brawl); + super(manager, new Kit[]{new KitHipster(manager)}, GameType.Brawl); _maxLives = 5; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/modes/kits/KitPlayer.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/modes/kits/KitHipster.java similarity index 90% rename from Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/modes/kits/KitPlayer.java rename to Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/modes/kits/KitHipster.java index bce3ac6e4..f32ea4f82 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/modes/kits/KitPlayer.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/modes/kits/KitHipster.java @@ -16,10 +16,10 @@ import nautilus.game.arcade.kit.SmashKit; * * @author xXVevzZXx */ -public class KitPlayer extends SmashKit +public class KitHipster extends SmashKit { - public KitPlayer(ArcadeManager manager) + public KitHipster(ArcadeManager manager) { super(manager, "Hipster", KitAvailability.Free, 0, new String[]{"Always get another kit!"}, new Perk[]{}, EntityType.ZOMBIE, new ItemStack(Material.RECORD_10), "Super", diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/survivalgames/SoloSurvivalGames.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/survivalgames/SoloSurvivalGames.java index 78b4e352a..b97097648 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/survivalgames/SoloSurvivalGames.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/survivalgames/SoloSurvivalGames.java @@ -4,6 +4,10 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; + import mineplex.core.common.util.C; import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilTime.TimeUnit; @@ -13,17 +17,13 @@ import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.GameType; import nautilus.game.arcade.events.GameStateChangeEvent; import nautilus.game.arcade.game.GameTeam; -import nautilus.game.arcade.game.Game.GameState; +import nautilus.game.arcade.kit.Kit; import nautilus.game.arcade.managers.chat.ChatStatData; import nautilus.game.arcade.stats.FirstSupplyDropOpenStatTracker; import nautilus.game.arcade.stats.KillsWithinTimeLimitStatTracker; import nautilus.game.arcade.stats.SimultaneousSkeletonStatTracker; import nautilus.game.arcade.stats.WinWithoutWearingArmorStatTracker; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; - public class SoloSurvivalGames extends SurvivalGames { @@ -66,6 +66,23 @@ public class SoloSurvivalGames extends SurvivalGames this.DamageTeamSelf = true; } + public SoloSurvivalGames(ArcadeManager manager, Kit[] kits, GameType type) + { + super(manager, kits, type, + new String[] + { + "Search for chests to find loot", + + "Slaughter your opponents", + + "Stay away from the borders!", + + "Last tribute alive wins!" + }); + + this.DamageTeamSelf = true; + } + @EventHandler public void CustomTeamGeneration(GameStateChangeEvent event) { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/survivalgames/SurvivalGames.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/survivalgames/SurvivalGames.java index f59a36d02..d357ced98 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/survivalgames/SurvivalGames.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/survivalgames/SurvivalGames.java @@ -145,35 +145,38 @@ public abstract class SurvivalGames extends Game private int _chestRefillTime = 60 * 7; - public SurvivalGames(ArcadeManager manager, GameType type, + public SurvivalGames(ArcadeManager manager, GameType type, String[] description) + { + this(manager, new Kit[] + { + new KitAxeman(manager), + + // new KitLooter(manager), + + new KitKnight(manager), + + new KitArcher(manager), + + new KitBrawler(manager), + + new KitAssassin(manager), + + new KitBeastmaster(manager), + + new KitBomber(manager), + + new KitNecromancer(manager), + + new KitBarbarian(manager), + + new KitHorseman(manager), + }, type, description); + } + + public SurvivalGames(ArcadeManager manager, Kit[] kits, GameType type, String[] description) { - super(manager, type, - - new Kit[] - { - new KitAxeman(manager), - - // new KitLooter(manager), - - new KitKnight(manager), - - new KitArcher(manager), - - new KitBrawler(manager), - - new KitAssassin(manager), - - new KitBeastmaster(manager), - - new KitBomber(manager), - - new KitNecromancer(manager), - - new KitBarbarian(manager), - - new KitHorseman(manager), - }, description); + super(manager, type, kits, description); _help = new String[] { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/survivalgames/modes/ChangingKits.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/survivalgames/modes/ChangingKits.java new file mode 100644 index 000000000..4397ddd32 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/survivalgames/modes/ChangingKits.java @@ -0,0 +1,173 @@ +package nautilus.game.arcade.game.games.survivalgames.modes; + +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; +import org.bukkit.event.entity.EntityDeathEvent; + +import mineplex.core.common.util.UtilItem; +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilServer; +import mineplex.core.common.util.UtilTextBottom; +import mineplex.core.common.util.UtilTime; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.GameType; +import nautilus.game.arcade.events.GameStateChangeEvent; +import nautilus.game.arcade.game.Game.GameState; +import nautilus.game.arcade.game.games.smash.modes.kits.KitHipster; +import nautilus.game.arcade.game.games.survivalgames.SoloSurvivalGames; +import nautilus.game.arcade.game.games.survivalgames.kit.KitArcher; +import nautilus.game.arcade.game.games.survivalgames.kit.KitAssassin; +import nautilus.game.arcade.game.games.survivalgames.kit.KitAxeman; +import nautilus.game.arcade.game.games.survivalgames.kit.KitBarbarian; +import nautilus.game.arcade.game.games.survivalgames.kit.KitBeastmaster; +import nautilus.game.arcade.game.games.survivalgames.kit.KitBomber; +import nautilus.game.arcade.game.games.survivalgames.kit.KitBrawler; +import nautilus.game.arcade.game.games.survivalgames.kit.KitHorseman; +import nautilus.game.arcade.game.games.survivalgames.kit.KitKnight; +import nautilus.game.arcade.game.games.survivalgames.kit.KitNecromancer; +import nautilus.game.arcade.kit.Kit; +import nautilus.game.arcade.kit.Perk; + +/** + * ChangingKits + * + * @author xXVevzZXx + */ +public class ChangingKits extends SoloSurvivalGames +{ + private Kit[] _kits; + + private long _lastChanged; + private int _changeInterval; + + public ChangingKits(ArcadeManager manager) + { + super(manager, new Kit[] + { + new KitHipster(manager) + }, GameType.Brawl); + + _kits = new Kit[] + { + new KitAxeman(manager), + + // new KitLooter(manager), + + new KitKnight(manager), + + new KitArcher(manager), + + new KitBrawler(manager), + + new KitAssassin(manager), + + new KitBeastmaster(manager), + + new KitBomber(manager), + + new KitNecromancer(manager), + + new KitBarbarian(manager), + }; + + _lastChanged = 0; + _changeInterval = 60; + } + + @EventHandler + public void countdown(UpdateEvent event) + { + if (!IsLive()) + return; + + if (event.getType() == UpdateType.SEC) + { + if (System.currentTimeMillis() > _lastChanged + 25000) + { + for (Player player : UtilServer.getPlayers()) + { + player.playSound(player.getLocation(), Sound.NOTE_PLING, 2F, 2F); + } + } + } + + if (event.getType() != UpdateType.TICK) + return; + + double percentage = (double) (System.currentTimeMillis() - _lastChanged) / (_changeInterval*1000); + + for (Player player : UtilServer.getPlayers()) + { + UtilTextBottom.displayProgress("New Kit", percentage, + UtilTime.MakeStr(Math.max(0, (_changeInterval*1000) - (System.currentTimeMillis() - _lastChanged))), player); + } + } + + @EventHandler + public void KitRegister(GameStateChangeEvent event) + { + if (event.GetState() != event.GetGame().KitRegisterState) + return; + + for (Kit kit : _kits) + { + UtilServer.getServer().getPluginManager().registerEvents(kit, Manager.getPlugin()); + + for (Perk perk : kit.GetPerks()) + { + UtilServer.getServer().getPluginManager().registerEvents(perk, Manager.getPlugin()); + perk.registeredEvents(); + } + } + } + + @EventHandler + public void end(GameStateChangeEvent event) + { + if (event.GetState() != GameState.Dead) + return; + + for (Kit kit : _kits) + { + HandlerList.unregisterAll(kit); + + for (Perk perk : kit.GetPerks()) + { + HandlerList.unregisterAll(perk); + perk.unregisteredEvents(); + } + } + } + + @EventHandler + public void kitSwitch(UpdateEvent event) + { + if (event.getType() != UpdateType.SEC) + return; + + if (!IsLive()) + return; + + if (!UtilTime.elapsed(_lastChanged, _changeInterval*1000)) + return; + + _lastChanged = System.currentTimeMillis(); + + for (Player player : GetPlayers(true)) + { + Kit kit = _kits[UtilMath.r(_kits.length)]; + SetKit((Player) player, kit, true, false); + } + } + + @Override + public String GetMode() + { + return "Changing Kits"; + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/survivalgames/modes/StrikeGames.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/survivalgames/modes/StrikeGames.java new file mode 100644 index 000000000..2373b9537 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/survivalgames/modes/StrikeGames.java @@ -0,0 +1,571 @@ +package nautilus.game.arcade.game.games.survivalgames.modes; + +import java.util.HashMap; +import java.util.Iterator; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.Chest; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.enchantment.EnchantItemEvent; +import org.bukkit.event.entity.ItemSpawnEvent; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerItemDamageEvent; +import org.bukkit.event.player.PlayerPickupItemEvent; +import org.bukkit.event.player.PlayerToggleSneakEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; +import org.bukkit.inventory.meta.ItemMeta; + +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilEvent; +import mineplex.core.common.util.UtilEvent.ActionType; +import mineplex.core.common.util.UtilItem; +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilTime; +import mineplex.core.itemstack.ItemStackFactory; +import mineplex.core.loot.RandomItem; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.GameType; +import nautilus.game.arcade.events.GameStateChangeEvent; +import nautilus.game.arcade.events.PlayerKitGiveEvent; +import nautilus.game.arcade.game.GameTeam; +import nautilus.game.arcade.game.games.minestrike.GunModule; +import nautilus.game.arcade.game.games.minestrike.items.grenades.FlashBang; +import nautilus.game.arcade.game.games.minestrike.items.grenades.Grenade; +import nautilus.game.arcade.game.games.minestrike.items.grenades.HighExplosive; +import nautilus.game.arcade.game.games.minestrike.items.grenades.Incendiary; +import nautilus.game.arcade.game.games.minestrike.items.grenades.Molotov; +import nautilus.game.arcade.game.games.minestrike.items.grenades.Smoke; +import nautilus.game.arcade.game.games.minestrike.items.guns.Gun; +import nautilus.game.arcade.game.games.minestrike.items.guns.GunStats; +import nautilus.game.arcade.game.games.survivalgames.SoloSurvivalGames; +import nautilus.game.arcade.game.games.survivalgames.SupplyChestOpenEvent; +import nautilus.game.arcade.game.games.survivalgames.kit.KitLooter; +import nautilus.game.arcade.game.games.survivalgames.modes.kit.KitPlayer; +import nautilus.game.arcade.kit.Kit; + +/** + * StrikeGames + * + * @author xXVevzZXx + */ +public class StrikeGames extends SoloSurvivalGames +{ + + private GunModule _gunModule; + + private long _peacePhase; + + private HashMap _helmets; + + public StrikeGames(ArcadeManager manager) + { + super(manager, new Kit[] + { + new KitPlayer(manager) + }, GameType.Brawl); + + Damage = false; + + _helmets = new HashMap<>(); + + _peacePhase = 20000; + + _gunModule = new GunModule(this); + _gunModule.EnableCleaning = false; + _gunModule.EnableDrop = false; + _gunModule.EnablePickup = false; + } + + @EventHandler + public void enableDamage(UpdateEvent event) + { + if (event.getType() != UpdateType.SEC) + return; + + if (!IsLive()) + return; + + if (!UtilTime.elapsed(GetStateTime(), _peacePhase)) + return; + + if (Damage) + return; + + Announce(F.main("Game", "The Peace Phase has ended! You can now fight each other!")); + Damage = true; + } + + @EventHandler + public void informPeace(GameStateChangeEvent event) + { + if (event.GetState() != GameState.Live) + return; + + Announce(F.main("Game", "A Peace Phase of " + F.time((_peacePhase/1000) + "") + " seconds has started!")); + } + + @EventHandler(priority=EventPriority.HIGHEST) + public void addHelmet(PlayerToggleSneakEvent event) + { + if (!IsLive()) + return; + + if (!IsAlive(event.getPlayer())) + return; + + if (_gunModule.getScoped().containsKey(event.getPlayer())) + return; + + if (event.getPlayer().getInventory().getHelmet() != null) + _helmets.put(event.getPlayer(), event.getPlayer().getInventory().getHelmet()); + } + + @EventHandler(priority=EventPriority.HIGHEST) + public void pumpkinDrop(PlayerDeathEvent event) + { + Iterator itemIterator = event.getDrops().iterator(); + while (itemIterator.hasNext()) + { + ItemStack item = itemIterator.next(); + if (item.getType() == Material.PUMPKIN + || item.getType() == Material.PUMPKIN_STEM) + { + itemIterator.remove(); + } + } + if (_helmets.containsKey(event.getEntity())) + event.getDrops().add(_helmets.get(event.getEntity())); + } + + @EventHandler + public void disableCrafting(PlayerInteractEvent event) + { + if (!UtilEvent.isAction(event, ActionType.R_BLOCK)) + return; + + if (event.getClickedBlock().getType() == Material.WORKBENCH) + event.setCancelled(true); + } + + @EventHandler + public void weaponEnchantment(EnchantItemEvent event) + { + if (!UtilItem.isArmor(event.getItem())) + event.setCancelled(true); + } + + public void setupLoot() + { + // Food + getBaseLoot().addLoot(new RandomItem(Material.BAKED_POTATO, 30, 1, 3)); + getBaseLoot().addLoot(new RandomItem(Material.COOKED_BEEF, 30, 1, 2)); + getBaseLoot().addLoot(new RandomItem(Material.COOKED_CHICKEN, 30, 1, 2)); + getBaseLoot().addLoot(new RandomItem(Material.MUSHROOM_SOUP, 15, 1, 1)); + getBaseLoot().addLoot(new RandomItem(Material.WHEAT, 30, 1, 6)); + getBaseLoot().addLoot(new RandomItem(Material.ROTTEN_FLESH, 40, 1, 6)); + + // Weapons + getBaseLoot().addLoot(new RandomItem(Material.WOOD_SWORD, 70)); + getBaseLoot().addLoot(new RandomItem(Material.STONE_SWORD, 30)); + + // Leather armor + getBaseLoot().addLoot(new RandomItem(Material.LEATHER_BOOTS, 30)); + getBaseLoot().addLoot(new RandomItem(Material.LEATHER_LEGGINGS, 30)); + + // Gold armor + getBaseLoot().addLoot(new RandomItem(Material.GOLD_BOOTS, 25)); + getBaseLoot().addLoot(new RandomItem(Material.GOLD_CHESTPLATE, 25)); + getBaseLoot().addLoot(new RandomItem(Material.GOLD_HELMET, 25)); + getBaseLoot().addLoot(new RandomItem(Material.GOLD_LEGGINGS, 25)); + + // Grenades + getBaseLoot().addLoot(new RandomItem(Material.CARROT_ITEM, 15)); + getBaseLoot().addLoot(new RandomItem(Material.APPLE, 15)); + getBaseLoot().addLoot(new RandomItem(Material.PORK, 15)); + getBaseLoot().addLoot(new RandomItem(Material.GRILLED_PORK, 15)); + getBaseLoot().addLoot(new RandomItem(Material.POTATO_ITEM, 15)); + + // Chain armor + getBaseLoot().addLoot(new RandomItem(Material.CHAINMAIL_BOOTS, 20)); + getBaseLoot().addLoot(new RandomItem(Material.CHAINMAIL_CHESTPLATE, 20)); + getBaseLoot().addLoot(new RandomItem(Material.CHAINMAIL_HELMET, 20)); + getBaseLoot().addLoot(new RandomItem(Material.CHAINMAIL_LEGGINGS, 20)); + + // Throwable + getBaseLoot().addLoot(new RandomItem(Material.FISHING_ROD, 30)); + getBaseLoot().addLoot(new RandomItem(Material.EGG, 30, 1, 2)); + + // Misc + getBaseLoot().addLoot(new RandomItem(Material.EXP_BOTTLE, 30, 1, 2)); + getBaseLoot().addLoot(new RandomItem(Material.COMPASS, 20)); + getBaseLoot().addLoot(new RandomItem(Material.STICK, 30, 1, 2)); + getBaseLoot().addLoot(new RandomItem(Material.BOAT, 15)); + getBaseLoot().addLoot(new RandomItem(Material.FLINT, 30, 1, 2)); + getBaseLoot().addLoot(new RandomItem(Material.FEATHER, 30, 1, 2)); + getBaseLoot().addLoot(new RandomItem(Material.GOLD_INGOT, 20)); + getSpawnLoot().addLoot(new RandomItem(Material.MUSHROOM_SOUP, 15)); + + getSpawnLoot().cloneLoot(getBaseLoot()); + + // Food + getSpawnLoot().addLoot(new RandomItem(Material.BAKED_POTATO, 30, 1, 5)); + getSpawnLoot().addLoot(new RandomItem(Material.CAKE, 30)); + getSpawnLoot().addLoot(new RandomItem(Material.MUSHROOM_SOUP, 30, 1, 1)); + getSpawnLoot().addLoot(new RandomItem(Material.COOKED_BEEF, 30, 1, 3)); + getSpawnLoot().addLoot(new RandomItem(Material.COOKED_CHICKEN, 30, 1, 3)); + getSpawnLoot().addLoot(new RandomItem(Material.COOKED_FISH, 30, 1, 6)); + getSpawnLoot().addLoot(new RandomItem(Material.COOKIE, 30)); + getSpawnLoot().addLoot(new RandomItem(Material.PUMPKIN_PIE, 30, 1, 3)); + + // Loot for chests in spawn + // Weaponry and ores + getSpawnLoot().addLoot(new RandomItem(Material.STONE_SWORD, 30)); + getSpawnLoot().addLoot(new RandomItem(Material.IRON_INGOT, 30, 1, 2)); + + // Iron gear + getSpawnLoot().addLoot(new RandomItem(Material.IRON_BOOTS, 30)); + getSpawnLoot().addLoot(new RandomItem(Material.IRON_CHESTPLATE, 30)); + getSpawnLoot().addLoot(new RandomItem(Material.IRON_HELMET, 30)); + getSpawnLoot().addLoot(new RandomItem(Material.IRON_LEGGINGS, 30)); + + // Supply crate loot + // Diamond gear + getCrateLoot().addLoot(new RandomItem(Material.DIAMOND_HELMET, 10)); + getCrateLoot().addLoot(new RandomItem(Material.DIAMOND_CHESTPLATE, 6)); + getCrateLoot().addLoot(new RandomItem(Material.DIAMOND_LEGGINGS, 8)); + getCrateLoot().addLoot(new RandomItem(Material.DIAMOND_BOOTS, 10)); + + // Iron gear + getCrateLoot().addLoot(new RandomItem(Material.IRON_HELMET, 30)); + getCrateLoot().addLoot(new RandomItem(Material.IRON_CHESTPLATE, 24)); + getCrateLoot().addLoot(new RandomItem(Material.IRON_LEGGINGS, 27)); + getCrateLoot().addLoot(new RandomItem(Material.IRON_BOOTS, 30)); + + // Weapons + getCrateLoot().addLoot(new RandomItem(Material.IRON_SWORD, 24)); + getCrateLoot().addLoot(new RandomItem(Material.DIAMOND_SWORD, 8)); + getCrateLoot().addLoot(new RandomItem(Material.GOLD_SPADE, 12)); + + // Cooked furnace + getFurnace().addLoot(new RandomItem(Material.COOKED_BEEF, 3, 1, 2)); + getFurnace().addLoot(new RandomItem(Material.COOKED_CHICKEN, 3, 1, 2)); + getFurnace().addLoot(new RandomItem(Material.COOKED_FISH, 3, 1, 2)); + getFurnace().addLoot(new RandomItem(Material.BAKED_POTATO, 3, 1, 1)); + getFurnace().addLoot(new RandomItem(Material.PUMPKIN_PIE, 3, 1, 1)); + getFurnace().addLoot(new RandomItem(Material.IRON_INGOT, 1, 1, 1)); + + // Raw furnace + getRawFurnace().addLoot(new RandomItem(Material.RAW_BEEF, 1, 1, 3)); + getRawFurnace().addLoot(new RandomItem(Material.RAW_CHICKEN, 1, 1, 3)); + getRawFurnace().addLoot(new RandomItem(Material.RAW_FISH, 1, 1, 3)); + + // Deathmatch Loot + getDeathMatch().addLoot(new RandomItem(Material.PUMPKIN_PIE, 4)); + getDeathMatch().addLoot(new RandomItem(Material.BAKED_POTATO, 4)); + getDeathMatch().addLoot(new RandomItem(Material.CAKE, 4)); + getDeathMatch().addLoot(new RandomItem(Material.WOOD_SWORD, 3)); + getDeathMatch().addLoot(new RandomItem(Material.STONE_SWORD, 1)); + } + + @Override + public void fillChest(Player looter, Block block) + { + getLootedBlocks().add(block.getLocation()); + + Chest chest = (Chest) block.getState(); + + chest.getBlockInventory().clear(); + + int items = 2; + if (Math.random() > 0.50) + items++; + if (Math.random() > 0.65) + items++; + if (Math.random() > 0.80) + items++; + if (Math.random() > 0.95) + items++; + + boolean spawnChest = getChestRefillTime() > 0 + && UtilMath.offset(chest.getLocation(), getSpawn()) < 8; + + if (spawnChest) + items += 3; + + if (GetKit(looter) instanceof KitLooter) + { + items += UtilMath.r(3); + } + + if (getSupplyBlocks().contains(block)) + { + items = 5; + if (Math.random() > 0.50) + items++; + if (Math.random() > 0.60) + items++; + if (Math.random() > 0.70) + items++; + if (Math.random() > 0.80) + items++; + if (Math.random() > 0.90) + items++; + if (Math.random() > 0.95) + items++; + } + + for (int i = 0; i < items; i++) + { + ItemStack item; + + if (spawnChest) + { + item = getSpawnLoot().getLoot(); + } + else if (isDeathMatchTeleported()) + { + item = getDeathMatch().getLoot(); + } + else + { + item = GetChestItem(getSupplyBlocks().contains(block)); + } + + if (item.getType() == Material.COMPASS) + { + item = buildCompass(5); + } + if (UtilItem.isWeapon(item)) + { + GunStats gunStat = GunStats.values()[UtilMath.r(GunStats.values().length)]; + + int e = 0; + + while (gunStat == GunStats.AWP && e < 20) + { + gunStat = GunStats.values()[UtilMath.r(GunStats.values().length)]; + e++; + } + + item = ItemStackFactory.Instance.CreateStack(gunStat.getSkin(), (byte) 0, 1, gunStat.getName()); + } + + String name = null; + if (item.getType() == Material.APPLE) + { + name = "High Explosive"; + } + else if (item.getType() == Material.CARROT_ITEM) + { + name = "Flash Bang"; + } + else if (item.getType() == Material.POTATO_ITEM) + { + name = "Smoke"; + } + else if (item.getType() == Material.PORK) + { + name = "Incendiary"; + } + else if (item.getType() == Material.GRILLED_PORK) + { + name = "Molotov"; + } + if (name != null) + { + ItemMeta meta = item.getItemMeta(); + meta.setDisplayName(name); + item.setItemMeta(meta); + } + + chest.getBlockInventory().setItem(UtilMath.r(27), item); + } + + if (getSupplyBlocks().contains(block)) + { + Bukkit.getPluginManager().callEvent(new SupplyChestOpenEvent(looter, block)); + } + + getSupplyBlocks().remove(block); + } + + @EventHandler + public void addEquipment(InventoryClickEvent event) + { + if (event.getCurrentItem() == null) + return; + + if (!(event.getWhoClicked() instanceof Player)) + return; + + Player player = (Player) event.getWhoClicked(); + + if (!(event.getClickedInventory() instanceof PlayerInventory)) + { + ItemStack stack = event.getCurrentItem(); + for (GunStats stat : GunStats.values()) + { + if (stat.getSkin() == stack.getType()) + { + Gun gun = new Gun(stat, _gunModule); + gun.setStack(stack); + gun.updateWeaponName(player, null, false); + gun.addID(); + _gunModule.registerGun(gun, player); + return; + } + } + + Grenade grenade = null; + + if (stack.getType() == Material.APPLE) + { + grenade = new HighExplosive(); + } + else if (stack.getType() == Material.CARROT_ITEM) + { + grenade = new FlashBang(); + } + else if (stack.getType() == Material.POTATO_ITEM) + { + grenade = new Smoke(); + } + else if (stack.getType() == Material.PORK) + { + grenade = new Incendiary(); + } + else if (stack.getType() == Material.GRILLED_PORK) + { + grenade = new Molotov(); + } + + if (grenade != null) + { + ItemMeta meta = stack.getItemMeta(); + meta.setDisplayName(grenade.getName()); + stack.setItemMeta(meta); + grenade.setStack(stack); + _gunModule.registerGrenade(grenade, player); + } + } + } + + @EventHandler + public void triggerPickup(PlayerPickupItemEvent event) + { + + if (!InProgress()) + return; + + if (!IsAlive(event.getPlayer())) + return; + + //Guns + Gun gun = _gunModule.getDroppedGuns().get(event.getItem()); + if (gun != null) + { + _gunModule.deregisterDroppedGun(gun); + _gunModule.registerGun(gun, event.getPlayer()); + gun.setStack(event.getItem().getItemStack()); + } + + //Grenades + Grenade grenade = _gunModule.getDroppedGrenades().get(event.getItem()); + if (grenade != null) + { + _gunModule.deregisterDroppedGrenade(grenade); + _gunModule.registerGrenade(grenade, event.getPlayer()); + grenade.setStack(event.getItem().getItemStack()); + } + } + + @EventHandler + public void triggerDrop(PlayerDropItemEvent event) + { + if (!InProgress()) + return; + + //Guns + Gun gun = _gunModule.getGunInHand(event.getPlayer(), event.getItemDrop().getItemStack()); + if (gun != null) + { + gun.drop(_gunModule, event.getPlayer(), false, false); + event.getItemDrop().remove(); + event.getPlayer().setItemInHand(null); + return; + } + + //Grenades + Grenade grenade = _gunModule.getGrenadeInHand(event.getPlayer(), event.getItemDrop().getItemStack()); + if (grenade != null) + { + grenade.drop(_gunModule, event.getPlayer(), false, false); + event.getItemDrop().remove(); + event.getPlayer().setItemInHand(null); + return; + } + } + + @EventHandler + @Override + public void ItemSpawn(ItemSpawnEvent event) + { + if (event.getEntity().getItemStack().hasItemMeta()) + return; + + Material mat = event.getEntity().getItemStack().getType(); + + switch (mat) + { + case SEEDS: + case SAPLING: + case VINE: + case LEAVES: + case LONG_GRASS: + case RED_ROSE: + case YELLOW_FLOWER: + case DEAD_BUSH: + case WATER_LILY: + event.setCancelled(true); + return; + case CARROT_ITEM: + event.setCancelled(true); + return; + case POTATO_ITEM: + event.setCancelled(true); + return; + case WHEAT: + event.setCancelled(true); + return; + case WOOD: + event.setCancelled(true); + return; + + default: + break; + } + + for (Player player : GetPlayers(true)) + if (UtilMath.offset(player, event.getEntity()) < 6) + return; + + event.setCancelled(true); + } + + @Override + public String GetMode() + { + return "Strike Games"; + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/survivalgames/modes/kit/KitPlayer.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/survivalgames/modes/kit/KitPlayer.java new file mode 100644 index 000000000..9942e1cc3 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/survivalgames/modes/kit/KitPlayer.java @@ -0,0 +1,46 @@ +package nautilus.game.arcade.game.games.survivalgames.modes.kit; + +import org.bukkit.Material; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.common.util.C; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.kit.Kit; +import nautilus.game.arcade.kit.KitAvailability; +import nautilus.game.arcade.kit.Perk; + +public class KitPlayer extends Kit +{ + public KitPlayer(ArcadeManager manager) + { + super(manager, "Player", KitAvailability.Free, + new String[] + { + C.cGreen + "Right-Click" + C.cWhite + " - " + C.cYellow + "Fire Gun", + C.cGreen + "Left-Click" + C.cWhite + " - " + C.cYellow + "Reload Gun", + C.cGreen + "Crouch" + C.cWhite + " - " + C.cYellow + "Sniper Scope", + }, + new Perk[] + { + + }, + EntityType.PLAYER, + new ItemStack(Material.AIR)); + + } + + @Override + public void GiveItems(Player player) + { + + } + + @Override + public void SpawnCustom(LivingEntity ent) + { + + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/UHC.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/UHC.java index e4af92f98..5f563ab9e 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/UHC.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/UHC.java @@ -16,11 +16,12 @@ import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilEvent; import mineplex.core.common.util.UtilInv; import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilParser; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTextMiddle; import mineplex.core.common.util.UtilTime; -import mineplex.core.common.util.UtilWorld; +import mineplex.core.itemstack.ItemBuilder; import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.recharge.Recharge; import mineplex.core.timing.TimingManager; @@ -38,14 +39,17 @@ import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.game.TeamGame; import nautilus.game.arcade.game.games.uhc.helpers.ChunkLoadingThread; import nautilus.game.arcade.game.games.uhc.helpers.WorldGenThread; +import nautilus.game.arcade.game.modules.OreVeinEditorModule; import nautilus.game.arcade.game.modules.TeamModule; +import nautilus.game.arcade.game.modules.antixray.AntiXrayModule; +import nautilus.game.arcade.game.modules.combatlog.CombatLogModule; +import nautilus.game.arcade.game.modules.combatlog.CombatLogNPC; import nautilus.game.arcade.kit.Kit; -import net.minecraft.server.v1_8_R3.Chunk; -import net.minecraft.server.v1_8_R3.MathHelper; import net.minecraft.server.v1_8_R3.MinecraftServer; import net.minecraft.server.v1_8_R3.WorldServer; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.Chunk; import org.bukkit.Difficulty; import org.bukkit.Location; import org.bukkit.Material; @@ -54,9 +58,8 @@ import org.bukkit.World.Environment; import org.bukkit.WorldBorder; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; -import org.bukkit.craftbukkit.v1_8_R3.CraftChunk; +import org.bukkit.block.BlockState; import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; @@ -68,7 +71,9 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.HandlerList; -import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.Action; +import org.bukkit.event.block.BlockGrowEvent; +import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; @@ -81,6 +86,7 @@ import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.PrepareItemCraftEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerItemConsumeEvent; import org.bukkit.event.player.PlayerKickEvent; import org.bukkit.event.player.PlayerPickupItemEvent; @@ -88,6 +94,7 @@ import org.bukkit.event.player.PlayerPortalEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; import org.bukkit.event.world.ChunkUnloadEvent; +import org.bukkit.event.world.StructureGrowEvent; import org.bukkit.inventory.CraftingInventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ShapedRecipe; @@ -96,16 +103,17 @@ import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.material.MaterialData; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; +import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scoreboard.DisplaySlot; import org.bukkit.scoreboard.Objective; -import org.spigotmc.ActivationRange; -import java.lang.reflect.Field; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.UUID; import java.util.concurrent.atomic.AtomicInteger; @@ -120,12 +128,27 @@ public class UHC extends TeamGame implements NCPHook // The number of minutes after which PVP should be enabled public static final int SAFE_TIME_IN_MINUTES = 11; + // The number of chunks to unload per tick + public static final int CHUNKS_UNLOAD_PER_TICK = 1; + + // This is the region in which nothing can be done (block placing, flowing, etc) + public static final int SAFE_REGION = 36; + + // The amount of damage to give from hitting the world border + public static final int WORLD_BORDER_DAMAGE = 5; + // The thread responsible for generating the world private final WorldGenThread _worldGenThread = new WorldGenThread(this); // The thread responsible for loading and decorating the world private final ChunkLoadingThread _chunkLoadingThread = new ChunkLoadingThread(this); + // The chunks which we have prevented unloading + private final Set _loadedChunks = new HashSet<>(); + + // The task which will unload chunks periodically + private BukkitRunnable _chunkUnloadTask; + // The number of minutes passed in this game private int _minutesSinceStart = 0; @@ -139,8 +162,6 @@ public class UHC extends TeamGame implements NCPHook // Whether players are teleporting currently private volatile boolean _isTeleporting = false; - private boolean xrayDebug; - // Border private int _secondsSinceStart; private HashMap _borderPositions = new HashMap(); @@ -159,6 +180,11 @@ public class UHC extends TeamGame implements NCPHook DamageTaken, DamageDealt ); + + registerModule( + new OreVeinEditorModule() + .removeNonAirVeins() + ); } public UHC(ArcadeManager manager, GameType type) @@ -176,12 +202,12 @@ public class UHC extends TeamGame implements NCPHook "Borders shrink over time", "Last player/team alive wins!" }); + _gamesRun++; + this.HideTeamSheep = true; this.StrictAntiHack = true; - AnnounceStay = false; - this.GameTimeout = 10800000; this.DamagePvP = false; @@ -229,6 +255,10 @@ public class UHC extends TeamGame implements NCPHook WorldTimeSet = -1; this.WorldLeavesDecay = true; + this.WorldBlockGrow = true; + this.WorldSoilTrample = true; + this.WorldBoneMeal = true; + this.WorldChunkUnload = true; CraftRecipes(); @@ -247,6 +277,31 @@ public class UHC extends TeamGame implements NCPHook NCPHookManager.addHook(CheckType.ALL, this); registerModule(new TeamModule()); + registerModule(new AntiXrayModule()) + .setEnabled(true) + .setUpdateOnDamage(true) + .setAntiTexturePacksAndFreecam(false) + .setUseProximityHider(false) + .setEngineMode(2) + .setInitialRadius(1) + .setUpdateRadius(2) + .setObfuscateBlocks( + Material.GOLD_ORE, + Material.IRON_ORE, + Material.LAPIS_ORE, + Material.DIAMOND_ORE, + Material.REDSTONE_ORE, + Material.GLOWING_REDSTONE_ORE, + Material.EMERALD_ORE + ) + .setRandomBlocks( + Material.GOLD_ORE, + Material.IRON_ORE, + Material.LAPIS_ORE, + Material.DIAMOND_ORE, + Material.REDSTONE_ORE, + Material.EMERALD_ORE + ); } @Override @@ -345,7 +400,7 @@ public class UHC extends TeamGame implements NCPHook if (Manager.IsAlive(player)) { - Manager.GetDamage().NewDamageEvent(player, null, null, DamageCause.CUSTOM, 10, false, false, false, + Manager.GetDamage().NewDamageEvent(player, null, null, DamageCause.CUSTOM, WORLD_BORDER_DAMAGE, false, false, false, "Nether Field", "Vaporize"); player.getWorld().playSound(loc, Sound.NOTE_BASS, 2f, 1f); @@ -358,6 +413,36 @@ public class UHC extends TeamGame implements NCPHook } } } + + if (getModule(CombatLogModule.class) != null) + { + for (CombatLogNPC npc : getModule(CombatLogModule.class).getAllNPCs()) + { + LivingEntity ent = npc.getNPC(); + Location loc = ent.getLocation(); + + // Bump Players Back In + if (loc.getX() > border || loc.getX() < -border || loc.getZ() > border || loc.getZ() < -border) + { + // Can't use recharge on entities; blame bad design (mapping by name instead of uuid) +// if (Recharge.Instance.use(ent, "Hit by Border", 1000, false, false)) + { + Entity bottom = ent; + while (bottom.getVehicle() != null) + bottom = bottom.getVehicle(); + + UtilAction + .velocity(bottom, UtilAlg.getTrajectory2d(loc, GetSpectatorLocation()), 1.2, true, 0.4, 0, 10, true); + + Manager.GetDamage().NewDamageEvent(ent, null, null, DamageCause.CUSTOM, WORLD_BORDER_DAMAGE, false, false, false, + "Nether Field", "Vaporize"); + + ent.getWorld().playSound(loc, Sound.NOTE_BASS, 2f, 1f); + ent.getWorld().playSound(loc, Sound.NOTE_BASS, 2f, 1f); + } + } + } + } } private ArrayList buildBorders(int seconds, double border, double leaveRemaining) @@ -517,7 +602,70 @@ public class UHC extends TeamGame implements NCPHook this.DamagePvP = true; this.CompassGiveItem = true; - this.QuitOut = true; + this.RejoinTime = 300000; // 5 minutes + registerModule( + new CombatLogModule() + .setSpawnForCreative(false) + .setCombatLogTime(300000) + .setOnDeathAction(npc -> + { + if (npc.getLastDamager() instanceof Player) + { + Player killer = (Player) npc.getLastDamager(); + Announce(npc.getPlayerInfo().getTeamColor() + C.Bold + npc.getPlayerInfo().getName() + + C.cGray + C.Bold + " was killed by " + getArcadeManager().GetColor(killer) + + C.Bold + npc.getLastDamager().getName() + C.cGray + C.Bold + " while logged out."); + } + else + { + String cause = UtilParser.parseDamageCause(npc.getLastDamageCause()); + if (npc.getLastDamager() != null) + { + cause = npc.getLastDamager().getName(); + } + Announce(npc.getPlayerInfo().getTeamColor() + C.Bold + npc.getPlayerInfo().getName() + + C.cGray + C.Bold + " was killed by " + cause + " while logged out."); + } + + ItemStack stack = new ItemBuilder(Material.SKULL_ITEM) + .setData((byte) 3) + .setTitle(npc.getPlayerInfo().getTeamColor() + npc.getPlayerInfo().getName() + "'s Head") + .build(); + + SkullMeta meta = (SkullMeta) stack.getItemMeta(); + meta.setOwner(npc.getPlayerInfo().getName()); + stack.setItemMeta(meta); + + npc.getNPC().getWorld().dropItemNaturally(npc.getNPC().getLocation(), stack); + + Location location = npc.getNPC().getLocation(); + + for (ItemStack item : npc.getPlayerInfo().getItems()) + { + location.getWorld().dropItemNaturally(location, item); + } + }) + .setOnExpireAction(npc -> + { + ItemStack stack = new ItemBuilder(Material.SKULL_ITEM) + .setData((byte) 3) + .setTitle(npc.getPlayerInfo().getTeamColor() + npc.getPlayerInfo().getName() + "'s Head") + .build(); + + SkullMeta meta = (SkullMeta) stack.getItemMeta(); + meta.setOwner(npc.getPlayerInfo().getName()); + stack.setItemMeta(meta); + + npc.getNPC().getWorld().dropItemNaturally(npc.getNPC().getLocation(), stack); + + Location location = npc.getNPC().getLocation(); + + for (ItemStack item : npc.getPlayerInfo().getItems()) + { + location.getWorld().dropItemNaturally(location, item); + } + }) + ); } } @@ -581,6 +729,27 @@ public class UHC extends TeamGame implements NCPHook } HandlerList.unregisterAll(_chunkLoadingThread); NCPHookManager.removeHook(this); + + if (_chunkUnloadTask != null) + { + try + { + _chunkUnloadTask.cancel(); + } + catch (IllegalStateException ex) + { + // bukkit + } + } + + Iterator iterator = _loadedChunks.iterator(); + while (iterator.hasNext()) + { + Chunk chunk = iterator.next(); + WorldData.World.unloadChunk(chunk.getX(), chunk.getZ()); + iterator.remove(); + } + return; } @@ -592,16 +761,13 @@ public class UHC extends TeamGame implements NCPHook _worldGenThread.start(); } - @EventHandler (priority = EventPriority.MONITOR, ignoreCancelled = false) + @EventHandler(priority = EventPriority.MONITOR) public void on(ChunkUnloadEvent event) { - if (IsLive()) - { - event.setCancelled(false); - } - else + if (!IsLive()) { event.setCancelled(true); + _loadedChunks.add(event.getChunk()); } } @@ -641,11 +807,11 @@ public class UHC extends TeamGame implements NCPHook Location zero = WorldData.World.getSpawnLocation(); + // fixme if you leave while teleporting you'll rejoin at 0,0 + for (Player player : players) { player.teleport(zero); - player.hidePlayer(player); - // Heal player.setHealth(player.getMaxHealth()); // Resistance and regen @@ -711,14 +877,31 @@ public class UHC extends TeamGame implements NCPHook WorldData.World.setAutoSave(true); - int x = 0; - for (org.bukkit.Chunk chunk : WorldData.World.getLoadedChunks()) + _chunkUnloadTask = new BukkitRunnable() { - if (WorldData.World.unloadChunkRequest(chunk.getX(), chunk.getZ())) + @Override + public void run() { - System.out.println("Requesting unload of chunk #" + (++x) + " " + chunk.getX() + " " + chunk.getZ()); + Iterator iterator = _loadedChunks.iterator(); + int amount = 0; + + while (amount < CHUNKS_UNLOAD_PER_TICK && iterator.hasNext()) + { + Chunk next = iterator.next(); + if (WorldData.World.unloadChunkRequest(next.getX(), next.getZ())) + { + System.out.println("Requesting unload of chunk " + next.getX() + " " + next.getZ()); + } + iterator.remove(); + amount++; + } + + if (_loadedChunks.size() == 0) + { + cancel(); + } } - } + }; }, 10 * 20L); } }, 5 * 20L); @@ -821,17 +1004,90 @@ public class UHC extends TeamGame implements NCPHook return SpectatorSpawn; } + // fixme flowing water and stuff + @EventHandler - public void WorldBoundaryYLimit(BlockPlaceEvent event) + public void preventBlockPlacement(BlockPlaceEvent event) { - if (event.getBlock().getX() >= -36 && event.getBlock().getX() <= 36 && event.getBlock().getZ() >= -36 - && event.getBlock().getZ() <= 36) + if (isInSafeZone(event.getBlock().getLocation())) { UtilPlayer.message(event.getPlayer(), F.main("Game", "You cannot build this high near center of map.")); event.setCancelled(true); } } + @EventHandler + public void preventStructureGrow(StructureGrowEvent event) + { + Iterator blocks = event.getBlocks().iterator(); + while (blocks.hasNext()) + { + BlockState next = blocks.next(); + if (isInSafeZone(next.getLocation())) + { + blocks.remove(); + } + } + } + + @EventHandler + public void preventBlockGrow(BlockGrowEvent event) + { + if (isInSafeZone(event.getBlock().getLocation())) + { + event.setCancelled(true); + } + } + + @EventHandler + public void preventBoneMeal(PlayerInteractEvent event) + { + if (event.getAction() == Action.RIGHT_CLICK_BLOCK) + { + boolean isIllegal = false; + if (!isIllegal) + { + isIllegal = event.getPlayer().getItemInHand().getType() == Material.INK_SACK && + event.getPlayer().getItemInHand().getData().getData() == (byte) 15; + } + if (!isIllegal) + { + isIllegal = event.getPlayer().getItemInHand().getType() == Material.WATER_BUCKET + || event.getPlayer().getItemInHand().getType() == Material.LAVA_BUCKET; + } + + if (isIllegal && isInSafeZone(event.getClickedBlock().getLocation())) + { + event.setCancelled(true); + } + } + } + + @EventHandler + public void preventPistons(BlockPistonExtendEvent event) + { + boolean willBeUnsafe = false; + for (Block block : event.getBlocks()) + { + if (isInSafeZone(block.getRelative(event.getDirection()).getLocation())) + { + willBeUnsafe = true; + break; + } + } + if (willBeUnsafe) + { + event.setCancelled(true); + } + } + + private boolean isInSafeZone(Location location) + { + return location.getX() <= SAFE_REGION && location.getX() >= -SAFE_REGION + && location.getZ() < SAFE_REGION && location.getZ() >= -SAFE_REGION; + } + + // fixme world decoration means random spawns which were clear before might not be after public Location GetRandomSpawn(Location around) { // Sometimes getting a random spawn at 0,0 hangs forever @@ -1019,7 +1275,7 @@ public class UHC extends TeamGame implements NCPHook if (event.getType() != UpdateType.SLOW) return; - HashMap> ents = new HashMap>(); + Map> ents = new HashMap<>(); for (Entity ent : WorldData.World.getEntities()) { @@ -1573,82 +1829,12 @@ public class UHC extends TeamGame implements NCPHook return true; } + private static int _gamesRun = 0; + @EventHandler public void on(PlayerCommandPreprocessEvent event) { - if (event.getMessage().equals("/uhcentities")) - { - CoreClient client = getArcadeManager().GetClients().Get(event.getPlayer()); - if (client.GetRank().has(Rank.DEVELOPER)) - { - for (Entity entity : event.getPlayer().getNearbyEntities(5.0, 5.0, 5.0)) - { - net.minecraft.server.v1_8_R3.Entity nms = ((CraftEntity) entity).getHandle(); - String debug = "Entity: " + entity.getType() + " id:" + nms.getId() + " inac:" + ActivationRange.checkIfActive(nms); - debug += " at:" + nms.activatedTick + " dac:" + nms.defaultActivationState; - - int x = MathHelper.floor(nms.locX); - int z = MathHelper.floor(nms.locZ); - - net.minecraft.server.v1_8_R3.Chunk chunk = nms.world.getChunkIfLoaded(x >> 4, z >> 4); - debug += " c:" + chunk + " il:" + (chunk != null ? chunk.areNeighborsLoaded(1) : "null"); - event.getPlayer().sendMessage(debug); - } - event.setCancelled(true); - } - } - else if (event.getMessage().equals("/uhcchunk")) - { - CoreClient client = getArcadeManager().GetClients().Get(event.getPlayer()); - if (client.GetRank().has(Rank.DEVELOPER)) - { - net.minecraft.server.v1_8_R3.Chunk chunk = ((CraftChunk) event.getPlayer().getLocation().getChunk()).getHandle(); - try - { - Field neighbors = chunk.getClass().getDeclaredField("neighbors"); - neighbors.setAccessible(true); - int n = neighbors.getInt(chunk); - - for (int x = -1; x < 2; x++) - { - for (int z = -1; z < 2; z++) - { - if (x == 0 && z == 0) - { - continue; - } - - int mask = 0x1 << (x * 5 + z + 12); - - boolean should = chunk.world.getChunkIfLoaded(chunk.locX + x, chunk.locZ + z) != null; - boolean is = (n & mask) == mask; - if (is && should) - { - event.getPlayer().sendMessage(ChatColor.GREEN + "Chunk " + (chunk.locX + x) + "," + (chunk.locZ + z) + " (" + x + "," + z + ") is a neighbor"); - } - else if (is && !should) - { - event.getPlayer().sendMessage(ChatColor.RED + "Chunk " + (chunk.locX + x) + "," + (chunk.locZ + z) + " (" + x + "," + z + ") is a neighbor but should not be"); - } - else if (!is && should) - { - event.getPlayer().sendMessage(ChatColor.RED + "Chunk " + (chunk.locX + x) + "," + (chunk.locZ + z) + " (" + x + "," + z + ") is not a neighbor but should be"); - } - else if (!is && !should) - { - event.getPlayer().sendMessage(ChatColor.GREEN + "Chunk " + (chunk.locX + x) + "," + (chunk.locZ + z) + " (" + x + "," + z + ") is not a neighbor"); - } - } - } - } - catch (Throwable t) - { - t.printStackTrace(); - } - event.setCancelled(true); - } - } - else if (event.getMessage().equals("/uhcgc")) + if (event.getMessage().equals("/uhcgc")) { CoreClient client = getArcadeManager().GetClients().Get(event.getPlayer()); if (client.GetRank().has(Rank.DEVELOPER)) @@ -1658,53 +1844,6 @@ public class UHC extends TeamGame implements NCPHook event.setCancelled(true); } } - else if (event.getMessage().equals("/uhcallchunks")) - { - CoreClient client = getArcadeManager().GetClients().Get(event.getPlayer()); - if (client.GetRank().has(Rank.DEVELOPER)) - { - for (Chunk chunk : ((CraftWorld) event.getPlayer().getWorld()).getHandle().chunkProviderServer.chunks.values()) - { - try - { - Field neighbors = chunk.getClass().getDeclaredField("neighbors"); - neighbors.setAccessible(true); - int n = neighbors.getInt(chunk); - - for (int x = -1; x < 2; x++) - { - for (int z = -1; z < 2; z++) - { - if (x == 0 && z == 0) - { - continue; - } - - int mask = 0x1 << (x * 5 + z + 12); - - boolean should = chunk.world.getChunkIfLoaded(chunk.locX + x, chunk.locZ + z) != null; - boolean is = (n & mask) == mask; - if (is && !should) - { - event.getPlayer().sendMessage(ChatColor.RED + "Chunk " + (chunk.locX + x) + "," + (chunk.locZ + z) + " (" + x + "," + z + ") relative to " + (chunk.locX) + "," + chunk.locZ + " is a neighbor but should not be"); - } - else if (!is && should) - { - event.getPlayer().sendMessage(ChatColor.RED + "Chunk " + (chunk.locX + x) + "," + (chunk.locZ + z) + " (" + x + "," + z + ") relative to " + (chunk.locX) + "," + chunk.locZ + " is not a neighbor but should be"); - } - } - } - } - catch (Throwable t) - { - t.printStackTrace(); - } - } - - event.getPlayer().sendMessage("Done"); - event.setCancelled(true); - } - } else if (event.getMessage().equals("/uhcworlds")) { CoreClient client = getArcadeManager().GetClients().Get(event.getPlayer()); @@ -1734,183 +1873,14 @@ public class UHC extends TeamGame implements NCPHook event.setCancelled(true); } } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void xrayBlockBreak(BlockBreakEvent event) - { - if (event.isCancelled()) - return; - - if (xrayDebug) - TimingManager.start("Block Break"); - - int range = 3; - - // Find Nearby Ores - ArrayList ores = findOres(event.getBlock(), range); - - // Anti-Xray - removeNonAirVeins(generateVeins(ores)); - - if (xrayDebug) - TimingManager.stop("Block Break"); - } - - private ArrayList findOres(Block source, int range) - { - ArrayList ores = new ArrayList(); - - for (int x = -range; x <= range; x++) - for (int z = -range; z <= range; z++) - for (int y = -range; y <= range; y++) - { - Block block = source.getRelative(x, y, z); - - findOreFromBlock(ores, block); - } - - if (xrayDebug) - for (Block debug : ores) - System.out.println("Found " + debug.getType() + " at " + UtilWorld.locToStrClean(debug.getLocation())); - - return ores; - } - - public void findOreFromBlock(ArrayList ores, Block block) - { - if (ores.contains(block)) - return; - - if (isOre(block)) + else if (event.getMessage().equals("/uhcgames")) { - ores.add(block); - - for (Block neighbour : UtilBlock.getSurrounding(block, true)) + CoreClient client = getArcadeManager().GetClients().Get(event.getPlayer()); + if (client.GetRank().has(Rank.DEVELOPER)) { - findOreFromBlock(ores, neighbour); + event.getPlayer().sendMessage("Games run: " + _gamesRun); + event.setCancelled(true); } } } - - public boolean isOre(Block block) - { - return (block.getType() == Material.IRON_ORE || block.getType() == Material.GOLD_ORE || block.getType() == Material.DIAMOND_ORE); - } - - private ArrayList> generateVeins(ArrayList ores) - { - ArrayList> veins = new ArrayList>(); - - while (!ores.isEmpty()) - { - Block block = ores.remove(0); - - if (xrayDebug) - System.out.println("NEW VEIN - " + block.getType()); - - // Start New Vein - ArrayList vein = new ArrayList(); - veins.add(vein); - vein.add(block); - - // Find Vein Ores - boolean addedToVein = true; - while (addedToVein) - { - addedToVein = false; - - Iterator oreIterator = ores.iterator(); - - while (oreIterator.hasNext()) - { - Block ore = oreIterator.next(); - - boolean inVein = false; - - // Check if in Vein - for (Block veinOre : vein) - { - // if (veinOre.getType() != ore.getType()) - // continue; - - if (UtilMath.offset(ore.getLocation(), veinOre.getLocation()) <= 2) - { - inVein = true; - break; - } - } - - // Add to Vein - if (inVein) - { - vein.add(ore); - oreIterator.remove(); - addedToVein = true; - } - } - } - - if (xrayDebug) - for (Block veinOre : vein) - System.out.println(UtilWorld.locToStrClean(veinOre.getLocation())); - } - - return veins; - } - - private void removeNonAirVeins(ArrayList> oreVeins) - { - // Remove Non-Aired Veins - for (ArrayList vein : oreVeins) - { - boolean visible = false; - - // Check if Air is near Vein - for (Block ore : vein) - { - for (Block visibleCheckBlock : UtilBlock.getSurrounding(ore, true)) - { - if (visibleCheckBlock.getType() == Material.AIR || UtilBlock.isVisible(visibleCheckBlock)) - { - visible = true; - } - - if (visible) - break; - } - - if (visible) - break; - } - - if (visible) - setOreType(vein); - - // Remove Vein - if (!visible) - { - if (xrayDebug) - System.out.println("DELETING VEIN;"); - - for (Block ore : vein) - { - if (xrayDebug) - System.out.println(ore.getType() + " " + UtilWorld.locToStrClean(ore.getLocation())); - - ore.setType(Material.STONE); - } - } - else - { - if (xrayDebug) - System.out.println("VALID VEIN!"); - } - } - } - - public void setOreType(ArrayList blocks) - { - - } } \ No newline at end of file diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/modes/CutClean.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/modes/CutClean.java index fba15e38a..9cce1ec01 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/modes/CutClean.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/modes/CutClean.java @@ -1,112 +1,63 @@ package nautilus.game.arcade.game.games.uhc.modes; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; - -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.entity.EntityDeathEvent; -import org.bukkit.inventory.ItemStack; - -import mineplex.core.common.util.UtilInv; -import mineplex.core.common.util.UtilMath; -import mineplex.core.itemstack.ItemStackFactory; +import mineplex.core.itemstack.ItemBuilder; import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.GameType; -import nautilus.game.arcade.events.GameStateChangeEvent; import nautilus.game.arcade.game.games.uhc.UHC; +import nautilus.game.arcade.game.modules.CutCleanModule; +import nautilus.game.arcade.game.modules.ItemGiverModule; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; -/** - * CutClean gamemode for UHC +/* + * The CutClean variant of UHC * - * @author xXVevzZXx + * This is identical to UHC however iron and gold ore will immediately smelt + * and mob drops will be immediately cooked */ public class CutClean extends UHC { - - private int _steakAmount; - - private HashMap _oreDrops; - private HashMap _drops; + // The amount of steak to give at the start of the game + private static final int STEAK_AMOUNT = 15; public CutClean(ArcadeManager manager) { super(manager, GameType.Brawl); - _steakAmount = 15; + registerModule(new CutCleanModule() + .associateBlockDrop( + Material.GOLD_ORE, + new ItemBuilder(Material.GOLD_INGOT).build() + ) + .associateBlockDrop( + Material.IRON_ORE, + new ItemBuilder(Material.IRON_INGOT).build() + ) + .associateMobDrop( + Material.RAW_BEEF, + new ItemBuilder(Material.COOKED_BEEF).build() + ) + .associateMobDrop( + Material.RAW_CHICKEN, + new ItemBuilder(Material.COOKED_CHICKEN).build() + ) + .associateMobDrop( + Material.RAW_FISH, + new ItemBuilder(Material.COOKED_FISH).build() + ) + .associateMobDrop( + Material.PORK, + new ItemBuilder(Material.GRILLED_PORK).build() + ) + .associateMobDrop( + Material.RABBIT, + new ItemBuilder(Material.COOKED_RABBIT).build() + ) + ); - _oreDrops = new HashMap<>(); - _oreDrops.put(Material.GOLD_ORE, Material.GOLD_INGOT); - _oreDrops.put(Material.IRON_ORE, Material.IRON_INGOT); - - _drops = new HashMap<>(); - _drops.put(Material.RAW_BEEF, Material.COOKED_BEEF); - _drops.put(Material.RAW_CHICKEN, Material.COOKED_CHICKEN); - _drops.put(Material.RAW_FISH, Material.COOKED_FISH); - _drops.put(Material.PORK, Material.GRILLED_PORK); - _drops.put(Material.RABBIT, Material.COOKED_RABBIT); - } - - @EventHandler - public void giveSteak(GameStateChangeEvent event) - { - if (event.GetState() != GameState.Live) - return; - - for (Player player : GetPlayers(true)) - { - UtilInv.insert(player, - ItemStackFactory.Instance.CreateStack(Material.COOKED_BEEF, _steakAmount)); - } - } - - @EventHandler - public void smeltOres(BlockBreakEvent event) - { - for (Material mat : _oreDrops.keySet()) - { - if (event.getBlock().getType() == mat) - { - event.setCancelled(true); - event.getBlock().setType(Material.AIR); - - Bukkit.getScheduler().runTaskLater(Manager.getPlugin(), new Runnable() - { - @Override - public void run() - { - event.getBlock().getWorld().dropItem( - event.getBlock().getLocation().add(0.5, 0.2, 0.5), - new ItemStack(_oreDrops.get(mat))); - - } - }, 1); - } - } - } - - @EventHandler - public void smeltFood(EntityDeathEvent event) - { - List drops = event.getDrops(); - for (Material mat : _drops.keySet()) - { - Iterator itemIterator = drops.iterator(); - while (itemIterator.hasNext()) - { - ItemStack item = itemIterator.next(); - if (item.getType() == mat) - { - itemIterator.remove(); - drops.add(ItemStackFactory.Instance.CreateStack(_drops.get(mat), - 1 + UtilMath.r(3))); - } - } - } + registerModule(new ItemGiverModule() + .withItem(new ItemStack(Material.COOKED_BEEF, STEAK_AMOUNT)) + ); } @Override @@ -114,5 +65,4 @@ public class CutClean extends UHC { return "Cut Clean"; } - } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/modes/GodBattles.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/modes/GodBattles.java index ebf7d5d43..12b6906a9 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/modes/GodBattles.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/modes/GodBattles.java @@ -1,103 +1,74 @@ package nautilus.game.arcade.game.games.uhc.modes; -import java.util.ArrayList; -import java.util.HashMap; - -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.inventory.ItemStack; - +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilItem; import mineplex.core.common.util.UtilMath; +import mineplex.core.itemstack.ItemBuilder; import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.GameType; -import nautilus.game.arcade.events.GameStateChangeEvent; import nautilus.game.arcade.game.games.uhc.UHC; +import nautilus.game.arcade.game.modules.CutCleanModule; +import nautilus.game.arcade.game.modules.ItemGiverModule; +import nautilus.game.arcade.game.modules.OreVeinEditorModule; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.inventory.ItemStack; + +import java.util.List; +import java.util.Set; /** * GodBattles gamemode for UHC - * - * @author xXVevzZXx */ public class GodBattles extends UHC { + // The set of materials which will be considered as an ore + private static final Set ORE_MATERIALS = Sets.newHashSet( + Material.COAL_ORE, + Material.REDSTONE_ORE, + Material.IRON_ORE, + Material.GOLD_ORE, + Material.DIAMOND_ORE + ); - private ArrayList _ores; - private HashMap _oreDrops; + // The set of materials which will act as replacements + private static final List ORE_REPLACEMENTS = Lists.newArrayList( + Material.GOLD_ORE, + Material.DIAMOND_ORE + ); public GodBattles(ArcadeManager manager) { super(manager, GameType.Brawl); - _ores = new ArrayList<>(); + registerModule(new CutCleanModule() + .associateBlockDrop( + Material.GOLD_ORE, + new ItemBuilder(Material.GOLD_BLOCK).build() + ) + ); - _ores.add(Material.GOLD_ORE); - _ores.add(Material.DIAMOND_ORE); + registerModule(new ItemGiverModule() + .withItem(UtilItem.makeUnbreakable(new ItemStack(Material.DIAMOND_PICKAXE))) + ); - _oreDrops = new HashMap<>(); - _oreDrops.put(Material.GOLD_ORE, Material.GOLD_BLOCK); - } - - @EventHandler - public void blockOres(BlockBreakEvent event) - { - for (Material mat : _oreDrops.keySet()) - { - if (event.getBlock().getType() == mat) - { - event.setCancelled(true); - event.getBlock().setType(Material.AIR); - - Bukkit.getScheduler().runTaskLater(Manager.getPlugin(), new Runnable() + registerModule(new OreVeinEditorModule() + .useFilter(block -> ORE_MATERIALS.contains(block.getType())) + .useEditor(vein -> { - @Override - public void run() + Material ore = ORE_REPLACEMENTS.get(UtilMath.r(ORE_REPLACEMENTS.size())); + for (Block block : vein) { - event.getBlock().getWorld().dropItem( - event.getBlock().getLocation().add(0.5, 0.2, 0.5), - new ItemStack(_oreDrops.get(mat))); - + if(!ORE_REPLACEMENTS.contains(block.getType())) + { + if(!UtilBlock.isVisible(block)) + block.setType(ore); + } } - }, 1); - } - } - } - - @EventHandler - public void givePickaxe(GameStateChangeEvent event) - { - if(event.GetState() != GameState.Live) - return; - - for (Player player : GetPlayers(true)) - { - player.getInventory().addItem(UtilItem.makeUnbreakable(new ItemStack(Material.DIAMOND_PICKAXE))); - } - } - - @Override - public void setOreType(ArrayList blocks) - { - Material ore = _ores.get(UtilMath.r(_ores.size())); - for (Block block : blocks) - { - if(block.getType() != Material.DIAMOND_ORE && block.getType() != Material.GOLD_ORE) - { - if(!UtilBlock.isVisible(block)) - block.setType(ore); - } - } - } - - @Override - public boolean isOre(Block block) - { - return (block.getType() == Material.COAL_ORE || block.getType() == Material.REDSTONE_ORE || block.getType() == Material.IRON_ORE || block.getType() == Material.GOLD_ORE || block.getType() == Material.DIAMOND_ORE); + }) + ); } @Override @@ -105,5 +76,4 @@ public class GodBattles extends UHC { return "God Battles"; } - } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/CutCleanModule.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/CutCleanModule.java new file mode 100644 index 000000000..84e4f3a50 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/CutCleanModule.java @@ -0,0 +1,107 @@ +package nautilus.game.arcade.game.modules; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.event.EventHandler; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.entity.EntityDeathEvent; +import org.bukkit.inventory.ItemStack; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.EnumMap; +import java.util.Iterator; +import java.util.List; + +/* + * This module will implement CutClean-esque features within the game. + * + * In particular, the CutCleanModule#associateBlockDrop and CutCleanModule#associateMobDrop methods will + * allow you to drop different items for each block and mob killed + */ +public class CutCleanModule extends Module +{ + private final EnumMap> _blockDrops = new EnumMap<>(Material.class); + private final EnumMap> _mobDrops = new EnumMap<>(Material.class); + + /* + * Associates a material with a list of drops. + * + * Every time a block of that material is broken, the drops given will be dropped instead + * + * fixme does not support data ids + */ + public CutCleanModule associateBlockDrop(Material block, ItemStack... drops) + { + if (_blockDrops.containsKey(block)) + { + throw new IllegalStateException(block + " is already registered to " + _blockDrops.get(block)); + } + _blockDrops.put(block, new ArrayList<>(Arrays.asList(drops))); + return this; + } + + /* + * Associates a mob drop with a list of different drops + * + * Every time an item of the given type is dropped by a mob death, the alternative drops will be dropped instead + */ + public CutCleanModule associateMobDrop(Material drop, ItemStack... drops) + { + if (_mobDrops.containsKey(drop)) + { + throw new IllegalStateException(drop + " is already registered to " + _mobDrops.get(drop)); + } + _mobDrops.put(drop, new ArrayList<>(Arrays.asList(drops))); + return this; + } + + @EventHandler + public void on(BlockBreakEvent event) + { + List drops = _blockDrops.get(event.getBlock().getType()); + if (drops == null) + { + return; + } + + event.getBlock().setType(Material.AIR); + + getGame().getArcadeManager().getScheduler().runTaskLater(getGame().getArcadeManager().getPlugin(), () -> + { + Location dropLocation = event.getBlock().getLocation().add(0.5, 0.2, 0.5); + for (ItemStack drop : drops) + { + event.getBlock().getWorld().dropItem(dropLocation, drop.clone()); + } + }, 1L); + } + + @EventHandler + public void on(EntityDeathEvent event) + { + List drops = event.getDrops(); + List newDrops = new ArrayList<>(); + + Iterator itemIterator = drops.iterator(); + while (itemIterator.hasNext()) + { + ItemStack item = itemIterator.next(); + + List replacements = _mobDrops.get(item.getType()); + if (replacements == null) + { + continue; + } + + itemIterator.remove(); + + for (ItemStack replace : replacements) + { + newDrops.add(replace.clone()); + } + } + + drops.addAll(newDrops); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/ItemGiverModule.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/ItemGiverModule.java new file mode 100644 index 000000000..08130e94c --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/ItemGiverModule.java @@ -0,0 +1,55 @@ +package nautilus.game.arcade.game.modules; + +import mineplex.core.common.util.UtilInv; +import mineplex.core.common.util.UtilItem; +import nautilus.game.arcade.events.GameStateChangeEvent; +import nautilus.game.arcade.game.Game; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.inventory.ItemStack; + +import java.util.ArrayList; +import java.util.List; + +/* + * This module will give all players specific items at the start of the game + */ +public class ItemGiverModule extends Module +{ + private final List _itemsToGive = new ArrayList<>(); + + public ItemGiverModule withItem(ItemStack item) + { + _itemsToGive.add(item.clone()); + return this; + } + + public ItemGiverModule withItems(ItemStack... items) + { + List clones = new ArrayList<>(); + for (ItemStack item : items) + { + clones.add(item.clone()); + } + + _itemsToGive.addAll(clones); + return this; + } + + + @EventHandler + public void on(GameStateChangeEvent event) + { + if(event.GetState() != Game.GameState.Live) + return; + + for (Player player : getGame().GetPlayers(true)) + { + for (ItemStack toGive : _itemsToGive) + { + UtilInv.insert(player, toGive.clone()); + } + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/Module.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/Module.java index 0279e0da6..bff9ae688 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/Module.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/Module.java @@ -1,13 +1,34 @@ package nautilus.game.arcade.game.modules; +import com.google.gson.JsonElement; import nautilus.game.arcade.game.Game; +import nautilus.game.arcade.game.TeamGame; import org.bukkit.event.Listener; +/* + * This is a Module + * + * A Module represents something which will enhance or change the way games can be played. + * Modules should function independent of which specific gamemode is being played. + * If you need game-specific features, put it into that Game implementation or refactor it into a separate class (not a module). + * + * Modules should never directly access other Modules via the Game instance. + * Instead, the game which requires cross-contamination should do so itself. + * + * Modules should be associated per-game. Do not make them static + * + * If your module is able to accept custom configuration, override the configure(JsonElement) method + * You can define the format of the json you wish to use. + * This custom configuration will be used to dynamically adjust gamemodes via Redis if needed + */ public abstract class Module implements Listener { // The game this module belongs to private Game _game; + /* + * Initializes this module with the specific game instance. You should never do this as {@link Game} does it for you + */ public void initialize(Game game) { if (_game != null) @@ -15,13 +36,47 @@ public abstract class Module implements Listener throw new IllegalArgumentException("Attempting to initialize module which has already been initialized for " + _game); } this._game = game; + this.setup(); } + /* + * This method is called once initialization is complete. Do whatever you need to do with the {@link Game} here + */ + protected void setup() + { + + } + + /* + * If this module can be configured via a JsonObject/JsonPrimitive, then override this method + * to implement that feature + * + * You can define how the JsonElement should be formatted. + * + * It is recommended to have a "force" boolean which will reset this module to a clean state + * (to allow extensive customization using json) + */ + public void configure(JsonElement element) + { + + } + + /* + * This method is called once this module is no longer needed. + * This could be because the game is over + * Or because this module was unregistered + * + * The {@link Game} will unregister this module as a listener for you. + * All you need to do is clean up after yourself + */ public void cleanup() { } + /* + * Gets the game this module is associated with + */ public Game getGame() { return this._game; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/OreVeinEditorModule.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/OreVeinEditorModule.java new file mode 100644 index 000000000..a7582e28f --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/OreVeinEditorModule.java @@ -0,0 +1,219 @@ +package nautilus.game.arcade.game.modules; + +import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilWorld; +import mineplex.core.timing.TimingManager; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.BlockBreakEvent; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.function.Consumer; +import java.util.function.Predicate; + +/* + * This module will allow you to edit veins of ore live as players break them + */ +public class OreVeinEditorModule extends Module +{ + // Initial range to look for veins + // For example, if I break a block at 0,0,0 and RANGE is 3 + // Then this module will look for ores in the region of -3,-3,-3 to 3,3,3 + private static final int RANGE = 3; + + private boolean _debug = false; + private boolean _removeNonAirVeins = false; + + private Predicate _predicateIsOre = block -> + (block.getType() == Material.IRON_ORE || block.getType() == Material.GOLD_ORE || block.getType() == Material.DIAMOND_ORE); + + private Consumer> _consumerOreEditor = list -> + { + + }; + + public OreVeinEditorModule debug() + { + this._debug = true; + return this; + } + + public OreVeinEditorModule removeNonAirVeins() + { + this._removeNonAirVeins = true; + return this; + } + + public OreVeinEditorModule useFilter(Predicate filter) + { + this._predicateIsOre = filter; + return this; + } + + public OreVeinEditorModule useEditor(Consumer> editor) + { + this._consumerOreEditor = editor; + return this; + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void on(BlockBreakEvent event) + { + if (_debug) + TimingManager.start("Block Break"); + + // Find Nearby Ores + List ores = findOres(event.getBlock(), RANGE); + + // Anti-Xray + removeNonAirVeins(generateVeins(ores)); + + if (_debug) + TimingManager.stop("Block Break"); + } + + // Searches in a range x range x range cube for ores + private List findOres(Block source, int range) + { + List ores = new ArrayList<>(); + + for (int x = -range; x <= range; x++) + for (int z = -range; z <= range; z++) + for (int y = -range; y <= range; y++) + findOreFromBlock(ores, source.getRelative(x, y, z)); + + if (_debug) + for (Block debug : ores) + System.out.println("Found " + debug.getType() + " at " + UtilWorld.locToStrClean(debug.getLocation())); + + return ores; + } + + // Checks if the current block is ore + // If so, then search all blocks around it to see if they are ores + private void findOreFromBlock(List ores, Block block) + { + if (ores.contains(block)) + return; + + if (_predicateIsOre.test(block)) + { + ores.add(block); + + for (Block neighbour : UtilBlock.getSurrounding(block, true)) + { + findOreFromBlock(ores, neighbour); + } + } + } + + private List> generateVeins(List ores) + { + List> veins = new ArrayList<>(); + + while (!ores.isEmpty()) + { + Block block = ores.remove(0); + + if (_debug) + System.out.println("NEW VEIN - " + block.getType()); + + // Start New Vein + List vein = new ArrayList<>(); + veins.add(vein); + + vein.add(block); + + // Find Vein Ores + boolean addedToVein = true; + while (addedToVein) + { + addedToVein = false; + + Iterator oreIterator = ores.iterator(); + + while (oreIterator.hasNext()) + { + Block ore = oreIterator.next(); + + boolean inVein = false; + + // Check if in Vein + // fixme is this a good algorithm? + for (Block veinOre : vein) + { + if (UtilMath.offset(ore.getLocation(), veinOre.getLocation()) <= 2) + { + inVein = true; + break; + } + } + + // Add to Vein + if (inVein) + { + vein.add(ore); + oreIterator.remove(); + addedToVein = true; + } + } + } + + if (_debug) + for (Block veinOre : vein) + System.out.println(UtilWorld.locToStrClean(veinOre.getLocation())); + } + + return veins; + } + + private void removeNonAirVeins(List> oreVeins) + { + // Remove Non-Aired Veins + for (List vein : oreVeins) + { + boolean visible = false; + + // Check if Air is near Vein + outer: for (Block ore : vein) + { + for (Block visibleCheckBlock : UtilBlock.getSurrounding(ore, true)) + { + if (visibleCheckBlock.getType() == Material.AIR || UtilBlock.isVisible(visibleCheckBlock)) + { + visible = true; + break outer; + } + } + } + + if (visible) + _consumerOreEditor.accept(vein); + + // Remove Vein + if (!visible && _removeNonAirVeins) + { + if (_debug) + System.out.println("DELETING VEIN;"); + + for (Block ore : vein) + { + if (_debug) + System.out.println(ore.getType() + " " + UtilWorld.locToStrClean(ore.getLocation())); + + ore.setType(Material.STONE); + } + } + else + { + if (_debug) + System.out.println("VALID VEIN!"); + } + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/TeamModule.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/TeamModule.java index 60fb19d7d..38e54b55e 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/TeamModule.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/TeamModule.java @@ -1,7 +1,5 @@ package nautilus.game.arcade.game.modules; -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; import mineplex.core.recharge.Recharge; @@ -14,11 +12,14 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerQuitEvent; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; import java.util.UUID; public class TeamModule extends Module { - private BiMap _teamReqs = HashBiMap.create(); + private Map _teamReqs = new HashMap<>(); @EventHandler(priority = EventPriority.HIGH) public void teamSelectInteract(PlayerInteractEntityEvent event) @@ -147,8 +148,15 @@ public class TeamModule extends Module if (getGame().GetTeam(player) != null) getGame().GetTeam(player).DisbandTeam(); - _teamReqs.remove(player.getUniqueId()); - _teamReqs.inverse().remove(player.getUniqueId()); + Iterator> iterator = _teamReqs.entrySet().iterator(); + while (iterator.hasNext()) + { + Map.Entry entry = iterator.next(); + if (entry.getKey().equals(player.getUniqueId()) || entry.getValue().equals(player.getUniqueId())) + { + iterator.remove(); + } + } } private GameTeam getEmptyTeam() diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/antixray/AntiXrayModule.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/antixray/AntiXrayModule.java new file mode 100644 index 000000000..216cf8355 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/antixray/AntiXrayModule.java @@ -0,0 +1,111 @@ +package nautilus.game.arcade.game.modules.antixray; + +import mineplex.core.common.util.UtilServer; +import nautilus.game.arcade.game.modules.Module; +import org.bukkit.Material; +import org.bukkit.plugin.RegisteredServiceProvider; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +/* + * This module will enable antixray for this specific game + * + * NOTE: The game server must also have the Mineplex Orebfuscator plugin installed + */ +public class AntiXrayModule extends Module +{ + private AntiXrayService _service; + + @Override + protected void setup() + { + RegisteredServiceProvider rsp = UtilServer.getServer().getServicesManager().getRegistration(AntiXrayService.class); + if (rsp == null) + { + getGame().unregisterModule(this); + System.out.println("!!!ERROR!!! AntiXray module was registered but the Mineplex Orebfuscator Service was not registered"); + return; + } + AntiXrayService service = rsp.getProvider(); + if (service == null) + { + getGame().unregisterModule(this); + System.out.println("!!!ERROR!!! AntiXray module was registered but the Mineplex Orebfuscator Service was null"); + return; + } + _service = service; + } + + @Override + public void cleanup() + { + _service.setEnabled(false); + } + + public AntiXrayModule setEnabled(boolean enabled) + { + _service.setEnabled(enabled); + return this; + } + + public AntiXrayModule setUpdateOnDamage(boolean updateOnDamage) + { + _service.setUpdateOnDamage(updateOnDamage); + return this; + } + + public AntiXrayModule setEngineMode(int engineMode) + { + _service.setEngineMode(engineMode); + return this; + } + + public AntiXrayModule setInitialRadius(int initialRadius) + { + _service.setInitialRadius(initialRadius); + return this; + } + + public AntiXrayModule setUpdateRadius(int updateRadius) + { + _service.setUpdateRadius(updateRadius); + return this; + } + + public AntiXrayModule setUseProximityHider(boolean useProximityHider) + { + _service.setUseProximityHider(useProximityHider); + return this; + } + + public AntiXrayModule setAntiTexturePacksAndFreecam(boolean antiTexturePacksAndFreecam) + { + _service.setAntiTexturePacksAndFreecam(antiTexturePacksAndFreecam); + return this; + } + + public AntiXrayModule setObfuscateBlocks(Material... materials) + { + return setObfuscateBlocks(Arrays.asList(materials)); + } + + public AntiXrayModule setObfuscateBlocks(List materials) + { + _service.setObfuscateBlocks(materials); + return this; + } + + public AntiXrayModule setRandomBlocks(Material... materials) + { + return setRandomBlocks(Arrays.asList(materials)); + } + + public AntiXrayModule setRandomBlocks(List materials) + { + _service.setRandomBlocks(materials); + return this; + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/antixray/AntiXrayService.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/antixray/AntiXrayService.java new file mode 100644 index 000000000..9c1619bbf --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/antixray/AntiXrayService.java @@ -0,0 +1,27 @@ +package nautilus.game.arcade.game.modules.antixray; + +import org.bukkit.Material; + +import java.util.Arrays; +import java.util.List; + +public interface AntiXrayService +{ + void setEnabled(boolean enabled); + + void setUpdateOnDamage(boolean updateOnDamage); + + void setEngineMode(int engineMode); + + void setInitialRadius(int initialRadius); + + void setUpdateRadius(int updateRadius); + + void setUseProximityHider(boolean useProximityHider); + + void setAntiTexturePacksAndFreecam(boolean antiTexturePacksAndFreecam); + + void setObfuscateBlocks(List materials); + + void setRandomBlocks(List materials); +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/combatlog/CombatLogModule.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/combatlog/CombatLogModule.java new file mode 100644 index 000000000..25b2d3b73 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/combatlog/CombatLogModule.java @@ -0,0 +1,339 @@ +package nautilus.game.arcade.game.modules.combatlog; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilEvent; +import mineplex.core.common.util.UtilParser; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import nautilus.game.arcade.game.GameTeam; +import nautilus.game.arcade.game.TeamGame; +import nautilus.game.arcade.game.modules.Module; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.GameMode; +import org.bukkit.Sound; +import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityDeathEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.world.ChunkUnloadEvent; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.UUID; +import java.util.function.Consumer; + +/* + * This module will spawn combat log NPCs for players who disconnect + */ +public class CombatLogModule extends Module +{ + // The map of player UUIDs to their combat log NPCs + private Map _logoutNpcs = new HashMap<>(); + + // The map of player UUIDs and who killed their combat logged NPC + private Map _killedBy = new HashMap<>(); + + // The time that combat log npcs will stay spawned for, in milliseconds + private int _spawnTime = 60000; + // Whether to notify the combat logged player on join if they have been killed + private boolean _notifyPlayer = true; + // Whether to spawn a combat log NPC for creative players + private boolean _spawnForCreative = true; + // The action to take once a combat logged NPC has died + private Consumer _onKill = npc -> + { + + }; + // The action to take once a combat logged NPC has expired + private Consumer _onExpire = npc -> + { + + }; + + private int _locationTaskId = -1; + + protected void setup() + { + _locationTaskId = Bukkit.getScheduler().runTaskTimer(getGame().getArcadeManager().getPlugin(), () -> + { + for (CombatLogNPC npc : _logoutNpcs.values()) + { + getGame().GetLocationStore().put(npc.getPlayerInfo().getName(), npc.getNPC().getLocation()); + } + }, 0L, 1L).getTaskId(); + } + + public CombatLogModule setNotifyPlayer(boolean notifyPlayer) + { + this._notifyPlayer = notifyPlayer; + return this; + } + + public CombatLogModule setSpawnForCreative(boolean spawnForCreative) + { + this._spawnForCreative = spawnForCreative; + return this; + } + + public CombatLogModule setOnDeathAction(Consumer action) + { + this._onKill = action; + return this; + } + + public CombatLogModule setOnExpireAction(Consumer action) + { + this._onExpire = action; + return this; + } + + public CombatLogModule setCombatLogTime(int time) + { + this._spawnTime = time; + return this; + } + + /* + * Spawns a combat log NPC for the given player if that player does not already have one + */ + public void spawnLogoutNpc(Player player) + { + if (hasLogoutNpc(player)) + return; + if (player.getGameMode() == GameMode.CREATIVE && !_spawnForCreative) + return; + + CombatLogNPC npc = new CombatLogNPC(this, player, getGame().getArcadeManager()); + npc.spawn(); + _logoutNpcs.put(player.getUniqueId(), npc); + System.out.println(String.format("Spawned combat log NPC for %s!", player.getName())); + } + + public boolean hasLogoutNpc(Player player) + { + return _logoutNpcs.containsKey(player.getUniqueId()); + } + + public CombatLogNPC getLogoutNpc(Player player) + { + return _logoutNpcs.get(player.getUniqueId()); + } + + public void despawnLogoutNpc(Player player) + { + CombatLogNPC npc = getLogoutNpc(player); + + if (npc != null) + { + npc.despawn(); + _logoutNpcs.remove(player.getUniqueId()); + System.out.println(String.format("Despawned combat log NPC for %s!", player.getName())); + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void on(PlayerQuitEvent event) + { + if (getGame().InProgress() && getGame().IsAlive(event.getPlayer())) + { + spawnLogoutNpc(event.getPlayer()); + } + } + + @EventHandler + public void on(PlayerJoinEvent event) + { + if (hasLogoutNpc(event.getPlayer())) + { + despawnLogoutNpc(event.getPlayer()); + } + + if (_killedBy.containsKey(event.getPlayer().getUniqueId())) + { + String name = _killedBy.remove(event.getPlayer().getUniqueId()); + if (_notifyPlayer && name != null) + { + UtilPlayer.message(event.getPlayer(), F.main("Combat Log", "While you were gone, you were killed by " + ChatColor.GREEN + name + C.mBody + ".")); + } + } + } + + @Override + public void cleanup() + { + System.out.println("Killing combat log NPCs"); + + for (CombatLogNPC npc : _logoutNpcs.values()) + { + npc.despawn(); + } + + _logoutNpcs.clear(); + _killedBy.clear(); + } + + @EventHandler + public void onChunkUnload(ChunkUnloadEvent event) + { + for (CombatLogNPC npc : _logoutNpcs.values()) + { + if (npc.getNPC().getLocation().getChunk().equals(event.getChunk())) + { + event.setCancelled(true); + return; + } + } + } + + @EventHandler(ignoreCancelled = true) + public void onEntityDeath(EntityDeathEvent event) + { + CombatLogNPC logoutNpc = getLogoutNpc(event.getEntity()); + + if (logoutNpc == null) + return; + + _onKill.accept(logoutNpc); + logoutNpc.onDeath(); + event.getDrops().clear(); // Clear the entity's item drops. If drops are wanted they can be added + + if (logoutNpc.getLastDamager() != null) + { + _killedBy.put(logoutNpc.getPlayerInfo().getUniqueId(), logoutNpc.getLastDamager().getName()); + } + else + { + _killedBy.put(logoutNpc.getPlayerInfo().getUniqueId(), UtilParser.parseDamageCause(logoutNpc.getLastDamageCause())); + } + + + if (getGame() instanceof TeamGame) + { + TeamGame teamGame = (TeamGame) getGame(); + teamGame.RejoinTimes.remove(logoutNpc.getPlayerInfo().getName()); + teamGame.RejoinKit.remove(logoutNpc.getPlayerInfo().getName()); + teamGame.RejoinTeam.remove(logoutNpc.getPlayerInfo().getName()); + teamGame.RejoinHealth.remove(logoutNpc.getPlayerInfo().getName()); + } + } + + @EventHandler(ignoreCancelled = true) + public void onEntityDamaged(EntityDamageEvent event) + { + CombatLogNPC logoutNpc = getLogoutNpc(event.getEntity()); + + if (logoutNpc != null) + { + LivingEntity damager = UtilEvent.GetDamagerEntity(event, true); + + Player damagerPlayer = null; + if (damager instanceof Player) + { + damagerPlayer = (Player) damager; + } + + if (getGame() instanceof TeamGame && damagerPlayer != null) + { + GameTeam damagerTeam = getGame().GetTeam(damagerPlayer); + if (damagerTeam == logoutNpc.getPlayerInfo().getTeam()) + { + event.setCancelled(true); + return; + } + } + + logoutNpc.getNPC().getWorld().playSound(logoutNpc.getNPC().getLocation(), Sound.HURT_FLESH, 1, 1); + + if (getGame() instanceof TeamGame) + { + getGame().getArcadeManager().runSync(() -> + { + ((TeamGame) getGame()).RejoinHealth.put(logoutNpc.getPlayerInfo().getName(), logoutNpc.getNPC().getHealth()); + }); + } + + logoutNpc.handleDamageEvent(event); + } + } + + @EventHandler + public void onUpdate(UpdateEvent event) + { + if (event.getType() == UpdateType.FASTER) + { + for (CombatLogNPC npc : _logoutNpcs.values()) + { + npc.update(); + } + } + + if (event.getType() == UpdateType.SEC) + { + Iterator iterator = _logoutNpcs.values().iterator(); + + while (iterator.hasNext()) + { + CombatLogNPC npc = iterator.next(); + + if (Bukkit.getPlayerExact(npc.getPlayerInfo().getName()) != null) + { + System.out.println("Removing NPC " + npc.getPlayerInfo().getName() + " for 1"); + npc.despawn(); + iterator.remove(); + } + else if (!npc.isAlive()) + { + System.out.println("Removing NPC " + npc.getPlayerInfo().getName() + " for 2"); + npc.remove(); + iterator.remove(); + } + else if (npc.getAliveDuation() > this._spawnTime) + { + System.out.println("Removing NPC " + npc.getPlayerInfo().getName() + " for 3"); + _onExpire.accept(npc); + npc.despawn(); + iterator.remove(); + } + } + } + } + + private CombatLogNPC getLogoutNpc(Entity entity) + { + return getLogoutNpc(entity.getEntityId()); + } + + private CombatLogNPC getLogoutNpc(int entityId) + { + for (CombatLogNPC npc : _logoutNpcs.values()) + { + if (npc.getNPC().getEntityId() == entityId) + { + return npc; + } + } + + return null; + } + + public int getSpawnTime() + { + return _spawnTime; + } + + public Collection getAllNPCs() + { + return _logoutNpcs.values(); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/combatlog/CombatLogNPC.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/combatlog/CombatLogNPC.java new file mode 100644 index 000000000..66c7eac4c --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/combatlog/CombatLogNPC.java @@ -0,0 +1,183 @@ +package nautilus.game.arcade.game.modules.combatlog; + +import mineplex.core.common.util.UtilEnt; +import mineplex.core.common.util.UtilTime; +import mineplex.core.disguise.DisguiseManager; +import mineplex.core.disguise.disguises.DisguisePlayer; +import mineplex.core.hologram.Hologram; +import nautilus.game.arcade.ArcadeManager; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; +import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.Creeper; +import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.metadata.FixedMetadataValue; + +public class CombatLogNPC +{ + private CombatLogModule _module; + + private PlayerInfo _playerInfo; + + private Hologram _hologram; + + private DisguiseManager _disguiseManager; + private long _spawnDate; + private final long _endingTime; + private double _spawnHealth; + private double _maxHealth; + + private LivingEntity _npc; + + private EntityDamageEvent.DamageCause _lastDamageCause; + private Entity _lastDamager; + + public CombatLogNPC(CombatLogModule module, Player player, ArcadeManager arcadeManager) + { + this._module = module; + + _playerInfo = new PlayerInfo(player, arcadeManager); + + _endingTime = System.currentTimeMillis() + this._module.getSpawnTime(); + + _disguiseManager = arcadeManager.GetDisguise(); + _hologram = new Hologram(arcadeManager.getHologramManager(), player.getEyeLocation().add(0, 1, 0), "Quitting in " + UtilTime.MakeStr(Math.max(_endingTime - System.currentTimeMillis(), 0))); + _spawnDate = 0; + _spawnHealth = player.getHealth(); + _maxHealth = player.getMaxHealth(); + _hologram.start(); + } + + /** + * Called when the {@code _npc} associated with this CombatLogNPC is killed + * and thus drops all the owner's items. + */ + public void onDeath() + { + _disguiseManager.undisguise(_npc); + } + + public void update() + { + _hologram.setText("Quitting in " + UtilTime.MakeStr(Math.max(_endingTime - System.currentTimeMillis(), 0))); + if (_npc != null) + { + _hologram.setLocation(_npc.getEyeLocation().add(0, 1, 0)); + } + } + + /** + * @return true, if the {@code _npc} associated with this CombatLogNPC is + * alive, false otherwise. + */ + public boolean isAlive() + { + return _npc != null && !_npc.isDead(); + } + + /** + * @return the amount of time (in milliseconds) that this npc has been alive + * an spawned in. + */ + public long getAliveDuation() + { + return System.currentTimeMillis() - _spawnDate; + } + + public void spawn() + { + if (_npc != null) despawn(); + + _npc = spawnNpc(getPlayer()); + _spawnDate = System.currentTimeMillis(); + } + + public void despawn() + { + if (_npc != null) + { + _npc.remove(); + _npc = null; + _hologram.stop(); + _hologram = null; + } + } + + public void remove() + { + _hologram.stop(); + _hologram = null; + } + + public PlayerInfo getPlayerInfo() + { + return _playerInfo; + } + + public Player getPlayer() + { + return _playerInfo.getPlayer(); + } + + private LivingEntity spawnNpc(Player player) + { + Location spawnLoc = player.getLocation(); + LivingEntity skel = player.getWorld().spawn(spawnLoc, Creeper.class); + skel.setRemoveWhenFarAway(false); + skel.setMetadata("CombatLogNPC", new FixedMetadataValue(_disguiseManager.getPlugin(), player.getUniqueId().toString())); + skel.teleport(spawnLoc); + skel.setMaxHealth(_maxHealth); + skel.setHealth(_spawnHealth); + skel.setFallDistance(player.getFallDistance()); + // fixme potion effects, mobs don't target, entity collision (setting to ghost disables arrows and fishing rods), logging while sleeping + // best solution to spawn EntityPlayer? + UtilEnt.Vegetate(skel); + UtilEnt.silence(skel, true); + + skel.getEquipment().setHelmet(player.getInventory().getHelmet()); + skel.getEquipment().setChestplate(player.getInventory().getChestplate()); + skel.getEquipment().setLeggings(player.getInventory().getLeggings()); + skel.getEquipment().setBoots(player.getInventory().getBoots()); + skel.getEquipment().setItemInHand(player.getItemInHand()); + + // Disguise + DisguisePlayer disguise = new DisguisePlayer(skel, ((CraftPlayer) player).getHandle().getProfile()); + _disguiseManager.disguise(disguise); + + return skel; + } + + public Entity getLastDamager() + { + return _lastDamager; + } + + public LivingEntity getNPC() + { + return this._npc; + } + + public void handleDamageEvent(EntityDamageEvent event) + { + this._lastDamageCause = event.getCause(); + if (event instanceof EntityDamageByEntityEvent) + { + EntityDamageByEntityEvent entityDamageByEntityEvent = (EntityDamageByEntityEvent) event; + this._lastDamager = entityDamageByEntityEvent.getDamager(); + } + else + { + this._lastDamager = null; + } + } + + public EntityDamageEvent.DamageCause getLastDamageCause() + { + return _lastDamageCause; + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/combatlog/PlayerInfo.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/combatlog/PlayerInfo.java new file mode 100644 index 000000000..1a1405145 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/combatlog/PlayerInfo.java @@ -0,0 +1,69 @@ +package nautilus.game.arcade.game.modules.combatlog; + +import mineplex.core.common.util.UtilInv; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.game.GameTeam; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.UUID; + +public class PlayerInfo +{ + private String _playerName; + private UUID _playerUuid; + private List _items; + private ChatColor _teamColor = ChatColor.GRAY; + private GameTeam _team; + + public PlayerInfo(Player player, ArcadeManager arcadeManager) + { + _playerName = player.getName(); + _playerUuid = player.getUniqueId(); + _items = UtilInv.getItems(player); + _team = arcadeManager.GetGame().GetTeam(player); + if (_team != null) + { + _teamColor = _team.GetColor(); + } + } + + public String getName() + { + return _playerName; + } + + public UUID getUniqueId() + { + return _playerUuid; + } + + public Player getPlayer() + { + return Bukkit.getPlayerExact(_playerName); + } + + public ChatColor getTeamColor() + { + return _teamColor; + } + + public GameTeam getTeam() + { + return _team; + } + + public List getItems() + { + return this._items; + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/ProgressingKit.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/ProgressingKit.java index 4985238d4..9d8679a34 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/ProgressingKit.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/ProgressingKit.java @@ -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; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameCreationManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameCreationManager.java index 8a80e2dcf..9b47ccc27 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameCreationManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameCreationManager.java @@ -1,12 +1,15 @@ package nautilus.game.arcade.managers; +import java.lang.reflect.Array; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.Iterator; +import java.util.List; import java.util.Map; import org.bukkit.ChatColor; @@ -328,7 +331,7 @@ public class GameCreationManager implements Listener } classes.add(Game.class); - HashMap varSet = Manager.GetServerConfig().GameModeMods.get(mode.getName()); + HashMap varSet = Manager.GetServerConfig().GameModeMods.get(mode.getName().replaceAll(" ", "")); if (varSet == null) return; @@ -346,9 +349,15 @@ public class GameCreationManager implements Listener value = value.split("\\(")[1]; value = value.replace(")", ""); - processList(clazz, game, var, - value.contains(":") ? value.split("\\:") : new String[] - { value }, add, remove); + Field f = getField(clazz, var); + if (f == null) + continue; + + processList(clazz, game, var, value.contains(":") ? value.split("\\:") : new String[] + { + value + }, + add, remove, !List.class.isAssignableFrom(f.getType())); } else if (value.contains("[")) { @@ -414,7 +423,7 @@ public class GameCreationManager implements Listener @SuppressWarnings("unchecked") private void processList(Class clazz, Game game, String var, String[] value, - boolean add, boolean remove) + boolean add, boolean remove, boolean array) { Field f = getField(clazz, var); if (f == null) @@ -424,26 +433,37 @@ public class GameCreationManager implements Listener { f.setAccessible(true); - ParameterizedType type = (ParameterizedType) f.getGenericType(); - Type generic = type.getActualTypeArguments()[0]; - Class genericClazz = Class.forName(generic.getTypeName()); - - ArrayList currentList = (ArrayList) f.get(game); - if (!add && !remove) + if (array) { - add = true; - currentList.clear(); - } - - for (String finalValue : value) - { - if (add) + f.set(game, Array.newInstance(f.getType().getComponentType(), value.length)); + for (int i = 0; i < value.length; i++) { - currentList.add(parseValue(genericClazz, finalValue, game)); + ((Object[])f.get(game))[i] = parseValue(f.getType().getComponentType(), value[i], game); } - else if (remove) + } + else + { + ParameterizedType type = (ParameterizedType) f.getGenericType(); + Type generic = type.getActualTypeArguments()[0]; + Class genericClazz = Class.forName(generic.getTypeName()); + + ArrayList currentList = (ArrayList) f.get(game); + if (!add && !remove) { - currentList.remove(parseValue(genericClazz, finalValue, game)); + add = true; + currentList.clear(); + } + + for (String finalValue : value) + { + if (add) + { + currentList.add(parseValue(genericClazz, finalValue, game)); + } + else if (remove) + { + currentList.remove(parseValue(genericClazz, finalValue, game)); + } } } @@ -452,6 +472,7 @@ public class GameCreationManager implements Listener catch (Exception ex) { System.out.println("Error while editing list"); + ex.printStackTrace(); } } @@ -516,7 +537,7 @@ public class GameCreationManager implements Listener } else if (clazz == Material.class) { - return Material.getMaterial(value); + return Material.valueOf(value); } else if (clazz == ChatColor.class) { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameFlagManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameFlagManager.java index 4300dfd09..c00b8f81d 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameFlagManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameFlagManager.java @@ -1263,7 +1263,7 @@ public class GameFlagManager implements Listener if (Manager.GetGame() == null) return; - if (Manager.GetGame().GetType().getResourcePackUrls() == null || Manager.GetGame().GetType().getResourcePackUrls().length == 0) + if (Manager.GetGame().GetType().getResourcePackUrls(Manager.GetGame()) == null || Manager.GetGame().GetType().getResourcePackUrls(Manager.GetGame()).length == 0) return; UtilTextMiddle.display(C.cGold + C.Bold + Manager.GetGame().GetType().GetName(), "Make sure you accept the Resource Pack", 20, 120, 20, event.getPlayer()); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameGemManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameGemManager.java index 182fcb7ec..23ede3d63 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameGemManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameGemManager.java @@ -179,15 +179,16 @@ public class GameGemManager implements Listener System.out.println("Gems for " + Manager.GetClients().Get(player).GetPlayerName()); } + final int baseShards = total; + int shards = baseShards; + //Gem Boooster Booster booster = Manager.getBoosterManager().getActiveBooster(); if (game.GemBoosterEnabled && booster != null) { - total *= booster.getMultiplier(); + shards += baseShards * booster.getMultiplier(); } - int shards = total; - //Gem Finder if (game.GemHunterEnabled) { @@ -221,13 +222,13 @@ public class GameGemManager implements Listener int accountId = Manager.GetClients().getAccountId(player); if (rank == rank.ULTRA) - shards *= 1.5; + shards += baseShards * 0.5; else if (rank == rank.HERO) - shards *= 2; + shards += baseShards * 1; else if (rank == rank.LEGEND) - shards *= 2.5; + shards += baseShards * 1.5; else if (rank.has(Rank.TITAN)) - shards *= 3; + shards += baseShards * 2; Manager.GetDonation().RewardGems(null, "Earned " + game.GetName(), player.getName(), player.getUniqueId(), total); if (accountId != -1) @@ -313,18 +314,6 @@ public class GameGemManager implements Listener int totalGems = earnedGems; - //Gem Booster - Booster booster = Manager.getBoosterManager().getActiveBooster(); - if (game.GemBoosterEnabled && booster != null) - { - int addedGems = (int) (earnedGems * booster.getMultiplier()) - earnedGems; - UtilPlayer.message(player, F.elem(C.cGreen + "+" + addedGems + " Gems") + " for " + F.elem(booster.getPlayerName() + "'s Game Amplifier" + C.cGreen + " +" + booster.getIncreasePercent() + "%")); - - totalGems *= booster.getMultiplier(); - } - - int shards = totalGems; - //Gem Finder if (game.GemHunterEnabled) { @@ -370,28 +359,35 @@ public class GameGemManager implements Listener totalGems += earnedGems; } - int earnedShards = shards; - double mult = 1; + final int baseShards = totalGems; + int shards = baseShards; + double extraMult = 0; Rank rank = Manager.GetClients().Get(player).GetRank(); if (rank == rank.ULTRA) - mult = 1.5; + extraMult = 0.5; else if (rank == rank.HERO) - mult = 2; + extraMult = 1; else if (rank == rank.LEGEND) - mult = 2.5; + extraMult = 1.5; else if (rank.has(Rank.TITAN)) - mult = 3; + extraMult = 2; - shards *= mult; - mult--; - - UtilPlayer.message(player, F.elem(C.cAqua + "+" + earnedShards + " Treasure Shards") + " for " + F.elem("Earning " + earnedShards + " Gems")); + UtilPlayer.message(player, F.elem(C.cAqua + "+" + baseShards + " Treasure Shards") + " for " + F.elem("Earning " + baseShards + " Gems")); if (rank.has(Rank.ULTRA)) { - UtilPlayer.message(player, F.elem(C.cAqua + "+" + (shards - earnedShards) + " Treasure Shards") + " for " + - F.elem(rank.getTag(true, true)) + F.elem(" Rank" + C.cAqua + " +" + Math.round((mult*100)) + "%")); + int extraShards = ((int) (extraMult * baseShards)); + UtilPlayer.message(player, F.elem(C.cAqua + "+" + extraShards + " Treasure Shards") + " for " + + F.elem(rank.getTag(true, true)) + F.elem(" Rank" + C.cAqua + " +" + Math.round((extraMult*100)) + "%")); + } + Booster booster = Manager.getBoosterManager().getActiveBooster(); + if (game.GemBoosterEnabled && booster != null) + { + double multiplier = booster.getMultiplier() - 1; + int extraShards = ((int) (multiplier * baseShards)); + UtilPlayer.message(player, F.elem(C.cAqua + "+" + extraShards + " Treasure Shards") + " for " + + F.name(booster.getPlayerName()) + "'s" + F.elem(" Game Amplifier" + C.cAqua + " +" + Math.round((multiplier*100)) + "%")); } //Inform diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameManager.java index cc517cbf9..cadc5f53c 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameManager.java @@ -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); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameSpectatorManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameSpectatorManager.java index defc9f325..8e6088764 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameSpectatorManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameSpectatorManager.java @@ -1,20 +1,27 @@ package nautilus.game.arcade.managers; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.UUID; - +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; +import mineplex.core.common.util.UtilTextBottom; import mineplex.core.packethandler.IPacketHandler; import mineplex.core.packethandler.PacketHandler; import mineplex.core.packethandler.PacketInfo; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.game.Game.GameState; import net.minecraft.server.v1_8_R3.EntityPlayer; +import net.minecraft.server.v1_8_R3.EntityTracker; +import net.minecraft.server.v1_8_R3.EntityTrackerEntry; import net.minecraft.server.v1_8_R3.NetworkManager; import net.minecraft.server.v1_8_R3.PacketPlayOutCamera; import net.minecraft.server.v1_8_R3.PacketPlayOutGameStateChange; import net.minecraft.server.v1_8_R3.PacketPlayOutNamedEntitySpawn; import net.minecraft.server.v1_8_R3.WorldSettings; +import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; import org.bukkit.entity.Entity; @@ -30,41 +37,37 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerToggleSneakEvent; import org.bukkit.event.vehicle.VehicleDamageEvent; -import mineplex.core.common.util.C; -import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilMath; -import mineplex.core.common.util.UtilPlayer; -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.ArcadeManager; -import nautilus.game.arcade.game.Game.GameState; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; public class GameSpectatorManager implements Listener, IPacketHandler { - private Set _pendingSpectate = Collections.synchronizedSet(new HashSet<>()); + // A map of a player UUID to the UUID of the entity they want to spectate + private Map _pendingSpectate = Collections.synchronizedMap(new HashMap<>()); - ArcadeManager Manager; + private ArcadeManager _manager; public GameSpectatorManager(ArcadeManager manager) { - Manager = manager; + _manager = manager; - Manager.getPluginManager().registerEvents(this, Manager.getPlugin()); + _manager.getPluginManager().registerEvents(this, _manager.getPlugin()); - Manager.getPacketHandler().addPacketHandler(this, PacketHandler.ListenerPriority.HIGH, PacketPlayOutNamedEntitySpawn.class); + _manager.getPacketHandler().addPacketHandler(this, PacketHandler.ListenerPriority.HIGH, PacketPlayOutNamedEntitySpawn.class); } - @EventHandler(priority = EventPriority.LOW, ignoreCancelled=true) + @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void interactCancel(PlayerInteractEvent event) { - if (Manager.GetGame() == null) + if (_manager.GetGame() == null) return; Player player = event.getPlayer(); - if (!Manager.GetGame().IsAlive(player)) + if (!_manager.GetGame().IsAlive(player)) event.setCancelled(true); processClick(player, event.getAction()); @@ -72,45 +75,45 @@ public class GameSpectatorManager implements Listener, IPacketHandler public void processClick(Player player, Action action) { - if (Manager.GetGame() == null) + if (_manager.GetGame() == null) return; - if(!Manager.GetGame().AllowEntitySpectate) + if (!_manager.GetGame().AllowEntitySpectate) return; - if(!Manager.GetGame().IsLive()) + if (!_manager.GetGame().IsLive()) return; - if(player.getGameMode() != GameMode.SPECTATOR) + if (player.getGameMode() != GameMode.SPECTATOR) return; - if(player.getSpectatorTarget() == null) + if (player.getSpectatorTarget() == null) return; - if(!(player.getSpectatorTarget() instanceof Player)) + if (!(player.getSpectatorTarget() instanceof Player)) return; - List players = Manager.GetGame().GetPlayers(true); + List players = _manager.GetGame().GetPlayers(true); int currentPlayer = 0; - for(Player otherPlayer : players) + for (Player otherPlayer : players) { currentPlayer++; - if(((Player) player.getSpectatorTarget()) == otherPlayer) + if (player.getSpectatorTarget() == otherPlayer) break; } - if(action == Action.LEFT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK) + if (action == Action.LEFT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK) currentPlayer = currentPlayer - 2; else return; - if(currentPlayer < 0) + if (currentPlayer < 0) currentPlayer = players.size() - 1; - if(currentPlayer >= players.size()) + if (currentPlayer >= players.size()) currentPlayer = 0; - if(players.get(currentPlayer) == null) + if (players.get(currentPlayer) == null) return; Player specPlayer = players.get(currentPlayer); @@ -121,25 +124,25 @@ public class GameSpectatorManager implements Listener, IPacketHandler @EventHandler(priority = EventPriority.LOW) public void interactEntityCancel(PlayerInteractEntityEvent event) { - if (Manager.GetGame() == null) + if (_manager.GetGame() == null) return; Player player = event.getPlayer(); - if (Manager.GetGame().GetState() == GameState.Recruit) + if (_manager.GetGame().GetState() == GameState.Recruit) { - if (Manager.getCosmeticManager().getMountManager().isMount(event.getRightClicked())) + if (_manager.getCosmeticManager().getMountManager().isMount(event.getRightClicked())) { return; } } - if (!Manager.GetGame().IsAlive(player)) + if (!_manager.GetGame().IsAlive(player)) { event.setCancelled(true); - if(Manager.GetGame().IsLive()) + if (_manager.GetGame().IsLive()) { - if(Manager.GetGame().AllowEntitySpectate) + if (_manager.GetGame().AllowEntitySpectate) { setSpectating(player, event.getRightClicked()); } @@ -150,26 +153,25 @@ public class GameSpectatorManager implements Listener, IPacketHandler @EventHandler public void updateSpecEntitys(UpdateEvent event) { - if(event.getType() != UpdateType.FASTER) + if (event.getType() != UpdateType.FASTER) return; - if(Manager.GetGame() == null) + if (_manager.GetGame() == null) return; - if(Manager.GetGame().IsLive() || Manager.GetGame().GetState() == GameState.End) + if (_manager.GetGame().IsLive() || _manager.GetGame().GetState() == GameState.End) { - if(Manager.GetGame().AllowEntitySpectate) + if (_manager.GetGame().AllowEntitySpectate) { - for(Player player : UtilServer.getPlayers()) + for (Player player : UtilServer.getPlayers()) { - if (!Manager.GetGame().IsAlive(player)) + if (!_manager.GetGame().IsAlive(player)) { - if(player.getGameMode() == GameMode.SPECTATOR) + if (player.getGameMode() == GameMode.SPECTATOR) { - if(player.getSpectatorTarget() == null) + if (player.getSpectatorTarget() == null) { - player.setGameMode(GameMode.SURVIVAL); - player.setAllowFlight(true); + despectate(player); } } } @@ -181,28 +183,27 @@ public class GameSpectatorManager implements Listener, IPacketHandler @EventHandler(priority = EventPriority.LOW) public void spectatedEntityDeath(PlayerDeathEvent event) { - if(Manager.GetGame() == null) + if (_manager.GetGame() == null) return; - if(Manager.GetGame().IsLive() || Manager.GetGame().GetState() == GameState.End) + if (_manager.GetGame().IsLive() || _manager.GetGame().GetState() == GameState.End) { - if(Manager.GetGame().AllowEntitySpectate) + if (_manager.GetGame().AllowEntitySpectate) { - for(Player player : UtilServer.getPlayers()) + for (Player player : UtilServer.getPlayers()) { - if (!Manager.GetGame().IsAlive(player)) + if (!_manager.GetGame().IsAlive(player)) { - if(player.getGameMode() == GameMode.SPECTATOR) + if (player.getGameMode() == GameMode.SPECTATOR) { - if(player.getSpectatorTarget() == event.getEntity()) + if (player.getSpectatorTarget() == event.getEntity()) { - if(Manager.GetGame().GetPlayers(true).size() >= 1) + if (_manager.GetGame().GetPlayers(true).size() >= 1) { - setSpectating(player, Manager.GetGame().GetPlayers(true).get(UtilMath.r(Manager.GetGame().GetPlayers(true).size()))); + setSpectating(player, _manager.GetGame().GetPlayers(true).get(UtilMath.r(_manager.GetGame().GetPlayers(true).size()))); return; } - player.setGameMode(GameMode.SURVIVAL); - player.setAllowFlight(true); + despectate(player); } } } @@ -214,28 +215,53 @@ public class GameSpectatorManager implements Listener, IPacketHandler @EventHandler(priority = EventPriority.LOW) public void dismountEntity(PlayerToggleSneakEvent event) { - if(Manager.GetGame() == null) + if (_manager.GetGame() == null) return; - if(Manager.GetGame().IsLive() || Manager.GetGame().GetState() == GameState.End) + if (_manager.GetGame().IsLive() || _manager.GetGame().GetState() == GameState.End) { - if(Manager.GetGame().AllowEntitySpectate) + if (_manager.GetGame().AllowEntitySpectate) { - if(!Manager.GetGame().IsAlive(event.getPlayer())) + if (!_manager.GetGame().IsAlive(event.getPlayer())) { - if(event.getPlayer().getGameMode() == GameMode.SPECTATOR) + if (event.getPlayer().getGameMode() == GameMode.SPECTATOR) { - event.getPlayer().setGameMode(GameMode.SURVIVAL); - event.getPlayer().setAllowFlight(true); + despectate(event.getPlayer()); } } } } } + /* + * There's a reason this code is so complicated. + * + * Basically, when we want to set someone to spectate another entity, we send a PacketPlayOutCamera + * However, on the client side if the entity with the id as specified in PacketPlayOutCamera doesn't exist, + * the client simply ignores it + * This is alright if we're talking about small games like SSM or whatever, but in bigger games like SG and UHC + * the client does not get to keep the entire map loaded in memory + * Therefore, there is a chance that when we call Player#setSpectatorTarget, it has no effect because the client + * has not yet loaded the target + * + * To remedy this, we take a two pronged approach. + * + * First, we use Minecraft's internal EntityTracker to determine whether the client should have the entity loaded + * or not (if that's out of sync we're screwed anyways so oh well) + * + * If the client does have it loaded, then we simply use the Bukkit API to set the spectator target + * + * If the client doesn't have it loaded, we add it to a map of pending spectates and let the packet handler do the rest + * + * If at any point the client wants to stop spectating, we immediately replace the value in the map which notifies + * the packet handler to stop doing whatever it's doing. + * + * This is because the despectation code will work no matter what step of the spectating process is currently + * being executed + */ public void setSpectating(Player player, Entity target) { - if (Manager.GetGame().IsAlive(player)) + if (_manager.GetGame().IsAlive(player)) { return; } @@ -245,66 +271,78 @@ public class GameSpectatorManager implements Listener, IPacketHandler if (target instanceof Player) { playerTarget = (Player) target; - if (!Manager.GetGame().IsAlive(playerTarget)) + if (!_manager.GetGame().IsAlive(playerTarget)) { return; } } - _pendingSpectate.add(target.getUniqueId()); + // Not finished last spectate + if (_pendingSpectate.containsKey(player.getUniqueId())) + return; + _pendingSpectate.put(player.getUniqueId(), target.getUniqueId()); + + EntityPlayer ep = ((CraftPlayer) player).getHandle(); + EntityTracker tracker = ep.u().getTracker(); + EntityTrackerEntry entry = tracker.trackedEntities.get(target.getEntityId()); + + // If the server is tracking this entity (eg the player should have it loaded) we can spectate right away + if (entry.trackedPlayers.contains(ep)) + { + player.teleport(target.getLocation().add(0, 1, 0)); + + // If the player already has the entity loaded, we have to set it now + player.setGameMode(GameMode.SPECTATOR); + player.setSpectatorTarget(target); + if (playerTarget != null) + UtilTextBottom.display(C.cGray + "You are spectating " + F.elem(_manager.GetGame().GetTeam(playerTarget).GetColor() + playerTarget.getName()) + ".", player); + + UtilPlayer.message(player, F.main("Game", "Sneak to stop spectating.")); + _pendingSpectate.remove(player.getUniqueId()); + } + + // We still set spectating here even though it's pointless because of updateSpecEntites() above player.teleport(target.getLocation().add(0, 1, 0)); - - // If the player already has the entity loaded, we have to set it now - - // todo - // In the future, we could do some really cool stuff where we listen to all incoming and outgoing - // spawn/destroy packets and track whether the client has loaded the entity in memory - // However, that approach has the risk of desynchronization at which point we're screwed player.setGameMode(GameMode.SPECTATOR); player.setSpectatorTarget(target); - - if (playerTarget != null) - UtilTextBottom.display(C.cGray + "You are spectating " + F.elem(Manager.GetGame().GetTeam(playerTarget).GetColor() + playerTarget.getName()) + ".", player); - - UtilPlayer.message(player, F.main("Game", "Sneak to stop spectating.")); - - // And if the player did have the entity loaded, we also need to clean up after ourselves - // 20 ticks should be more than enough time considering we're just waiting for the server to attempt to - // send the packet - // and even if the server was lagging, the scheduler should be lagging too - Manager.runSyncLater(() -> - { - _pendingSpectate.remove(target.getUniqueId()); - }, 20L); } @EventHandler(priority = EventPriority.LOW) public void vehicleDamage(VehicleDamageEvent event) { - if (Manager.GetGame() == null) + if (_manager.GetGame() == null) return; if (!(event.getAttacker() instanceof Player)) return; - Player player = (Player)event.getAttacker(); + Player player = (Player) event.getAttacker(); - if (!Manager.GetGame().IsAlive(player)) + if (!_manager.GetGame().IsAlive(player)) event.setCancelled(true); } + // Yes, there are a lot of checks for _pendingSpectate + // This is needed because if at any point (keeping in mind this code is not executed sequentially, but with delays) + // spectation needs to be aborted (signaled by replacing the value in _pendingSpectate) + // Then we need to stop spectating right away + // Otherwise the client will be out of sync @Override public void handle(PacketInfo packetInfo) { if (packetInfo.getPacket() instanceof PacketPlayOutNamedEntitySpawn) { PacketPlayOutNamedEntitySpawn packet = (PacketPlayOutNamedEntitySpawn) packetInfo.getPacket(); - if (_pendingSpectate.remove(packet.b)) + if (_pendingSpectate.get(packetInfo.getPlayer().getUniqueId()) == packet.b) { // Handle Minestrike spam race condition - if (Manager.GetGame().IsAlive(packetInfo.getPlayer())) + if (_manager.GetGame().IsAlive(packetInfo.getPlayer())) { + _manager.runSync(() -> + { + _pendingSpectate.remove(packetInfo.getPlayer().getUniqueId()); + }); return; } @@ -313,31 +351,100 @@ public class GameSpectatorManager implements Listener, IPacketHandler EntityPlayer ep = ((CraftPlayer) packetInfo.getPlayer()).getHandle(); NetworkManager manager = ep.playerConnection.networkManager; + if (_pendingSpectate.get(packetInfo.getPlayer().getUniqueId()) != packet.b) + return; + manager.a(packet, future -> { - Manager.runSync(() -> + if (_pendingSpectate.get(packetInfo.getPlayer().getUniqueId()) != packet.b) + return; + + _manager.runSync(() -> { PlayerGameModeChangeEvent event = new PlayerGameModeChangeEvent(packetInfo.getPlayer(), GameMode.SPECTATOR); UtilServer.CallEvent(event); - if(event.isCancelled()) { + if (event.isCancelled()) + { + _manager.runSync(() -> + { + _pendingSpectate.remove(packetInfo.getPlayer().getUniqueId()); + }); return; } ep.playerInteractManager.setGameMode(WorldSettings.EnumGamemode.getById(GameMode.SPECTATOR.getValue())); ep.fallDistance = 0.0F; + + if (_pendingSpectate.get(packetInfo.getPlayer().getUniqueId()) != packet.b) + return; + manager.a(new PacketPlayOutCamera(ep), future1 -> { - manager.a(new PacketPlayOutGameStateChange(3, (float)GameMode.SPECTATOR.getValue()), future2 -> - { - PacketPlayOutCamera p1 = new PacketPlayOutCamera(); - p1.a = packet.a; - manager.handle(p1); - }); + if (_pendingSpectate.get(packetInfo.getPlayer().getUniqueId()) != packet.b) + return; + manager.a(new PacketPlayOutGameStateChange(3, (float) GameMode.SPECTATOR.getValue()), future2 -> + { + if (_pendingSpectate.get(packetInfo.getPlayer().getUniqueId()) != packet.b) + return; + + _manager.runSync(() -> + { + PacketPlayOutCamera p1 = new PacketPlayOutCamera(); + p1.a = packet.a; + + if (_pendingSpectate.get(packetInfo.getPlayer().getUniqueId()) != packet.b) + return; + + manager.a(p1, future3 -> + { + _manager.runSync(() -> + { + Player playerTarget = Bukkit.getPlayer(packet.b); + + if (playerTarget != null) + UtilTextBottom.display(C.cGray + "You are spectating " + F.elem(_manager.GetGame().GetTeam(playerTarget).GetColor() + playerTarget.getName()) + ".", packetInfo.getPlayer()); + + UtilPlayer.message(packetInfo.getPlayer(), F.main("Game", "Sneak to stop spectating.")); + _pendingSpectate.remove(packetInfo.getPlayer().getUniqueId()); + }); + }); + }); + }); }); }); }); } } } + + public void despectate(Player player) + { + // We want to override and tell any pending spectates that we are despectating now + _pendingSpectate.put(player.getUniqueId(), player.getUniqueId()); + + PlayerGameModeChangeEvent event = new PlayerGameModeChangeEvent(player, GameMode.SURVIVAL); + UtilServer.CallEvent(event); + if (event.isCancelled()) + { + _pendingSpectate.remove(player.getUniqueId()); + return; + } + + EntityPlayer ep = ((CraftPlayer) player).getHandle(); + ep.playerInteractManager.setGameMode(WorldSettings.EnumGamemode.getById(GameMode.SURVIVAL.getValue())); + ep.fallDistance = 0.0F; + NetworkManager manager = ep.playerConnection.networkManager; + manager.a(new PacketPlayOutCamera(ep), future1 -> + { + manager.a(new PacketPlayOutGameStateChange(3, (float) GameMode.SURVIVAL.getValue()), future2 -> + { + _manager.runSync(() -> + { + player.setAllowFlight(true); + _pendingSpectate.remove(player.getUniqueId()); + }); + }); + }); + } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameWorldManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameWorldManager.java index df3147fd4..fdaf4c271 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameWorldManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameWorldManager.java @@ -75,8 +75,23 @@ public class GameWorldManager implements Listener } if (Manager.GetGame() != null) + { if (Manager.GetGame().WorldData != null) - Manager.GetGame().WorldData.ChunkUnload(event); + { + + if (Manager.GetGame().WorldChunkUnload) + { + return; + } + if (Manager.GetGame().WorldData.World == null) + return; + + if (!event.getWorld().equals(Manager.GetGame().WorldData.World)) + return; + + event.setCancelled(true); + } + } } public void RegisterWorld(WorldData worldData) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/ServerUptimeManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/ServerUptimeManager.java new file mode 100644 index 000000000..963449a38 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/ServerUptimeManager.java @@ -0,0 +1,265 @@ +package nautilus.game.arcade.managers; + +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.HashMap; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +import mineplex.core.common.Rank; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilServer; +import mineplex.core.common.util.UtilTime; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.game.Game.GameState; + +/** + * ServerUptimeManager + * + * @author xXVevzZXx + */ +public class ServerUptimeManager implements Listener +{ + private static final long SHUTDOWN_DELAY = 10000; + private static final long KICK_AFTER_SENDING = 20*10; // 10 Seconds + + public ArcadeManager Manager; + + private HashMap _dates; + + private long _informed; + + private boolean _closeServer; + + private boolean _enabled; + + private boolean _closed; + + public ServerUptimeManager(ArcadeManager manager) + { + Manager = manager; + + _dates = new HashMap<>(); + _enabled = true; + updateDates(); + + Manager.getPluginManager().registerEvents(this, Manager.getPlugin()); + } + + @EventHandler + public void updateDates(UpdateEvent event) + { + if (!_enabled) + return; + + if (event.getType() != UpdateType.MIN_30) + return; + + if (isOpen()) + return; + + updateDates(); + } + + @EventHandler + public void changeState(UpdateEvent event) + { + if (!_enabled) + return; + + if (event.getType() != UpdateType.SLOWEST) + return; + + if (isOpen()) + { + if (!_closed) + return; + + System.out.println("Opening server!"); + UtilServer.getServer().setWhitelist(false); + Manager.setRequiredRank(null); + _closed = false; + } + else + { + if (_closed) + return; + + System.out.println("Closing server!"); + _informed = System.currentTimeMillis(); + _closeServer = true; + Manager.setRequiredRank(Rank.HELPER); + UtilServer.getServer().setWhitelist(true); + + UtilServer.broadcast(F.main("Server", "Servertime expired! I will shutdown soon.")); + } + } + + @EventHandler + public void closeServer(UpdateEvent event) + { + if (!_enabled) + return; + + if (event.getType() != UpdateType.SLOWER) + return; + + if (!_closeServer) + return; + + if (Manager.GetGame() == null) + return; + + if (Manager.GetGame().GetState() != GameState.Recruit) + return; + + if (!UtilTime.elapsed(Manager.GetGame().GetStateTime(), SHUTDOWN_DELAY) + || !UtilTime.elapsed(_informed, SHUTDOWN_DELAY)) + return; + + if (_closed) + return; + + _closeServer = false; + + for (Player player : UtilServer.getPlayers()) + { + Manager.GetPortal().sendToHub(player, "Servertime has expired!"); + } + + Manager.runSyncLater(new Runnable() + { + @Override + public void run() + { + while (UtilServer.getPlayers().length > 0) + { + UtilServer.getPlayers()[0].kickPlayer(F.main("Server", "Servertime has expired!")); + } + } + }, KICK_AFTER_SENDING); + + _closed = true; + + } + + public boolean isOpen() + { + for (Date start : _dates.keySet()) + { + Date end = _dates.get(start); + Date current = new Date(System.currentTimeMillis()); + + if (current.before(end) && current.after(start)) + return true; + } + return false; + } + + public void updateDates() + { + updateDates(Manager.GetServerConfig().Uptimes); + } + + public void updateDates(String uptimes) + { + System.out.println(uptimes); + if (Manager.GetServerConfig().Uptimes.isEmpty()) + { + _enabled = false; + return; + } + _dates.clear(); + + String[] pairs = uptimes.split(","); + + for (String pair : pairs) + { + GregorianCalendar firstDate = new GregorianCalendar(); + GregorianCalendar secondDate = new GregorianCalendar(); + + int i = 0; + for (String part : pair.split("-")) + { + i++; + GregorianCalendar current = i == 1 ? firstDate : secondDate; + + String[] date = part.split(":"); + + for (String token : date) + { + if (token.endsWith("Y")) + { + current.set(GregorianCalendar.YEAR, + Integer.parseInt(token.substring(0, token.length() - 1))); + } + else if (token.endsWith("MO")) + { + current.set(GregorianCalendar.MONTH, + Integer.parseInt(token.substring(0, token.length() - 2))); + } + else if (token.endsWith("W")) + { + current.set(GregorianCalendar.WEEK_OF_MONTH, + Integer.parseInt(token.substring(0, token.length() - 1))); + } + else if (token.endsWith("D")) + { + current.set(GregorianCalendar.DAY_OF_WEEK, + Integer.parseInt(token.substring(0, token.length() - 1))); + } + else if (token.endsWith("H")) + { + current.set(GregorianCalendar.HOUR_OF_DAY, + Integer.parseInt(token.substring(0, token.length() - 1))); + } + else if (token.endsWith("M")) + { + current.set(GregorianCalendar.MINUTE, + Integer.parseInt(token.substring(0, token.length() - 1))); + } + else if (token.endsWith("S")) + { + current.set(GregorianCalendar.SECOND, + Integer.parseInt(token.substring(0, token.length() - 1))); + } + } + + } + int[] types = + { GregorianCalendar.SECOND, GregorianCalendar.MINUTE, GregorianCalendar.HOUR_OF_DAY, + GregorianCalendar.DAY_OF_WEEK, GregorianCalendar.WEEK_OF_MONTH, + GregorianCalendar.MONTH, GregorianCalendar.YEAR }; + + int e = 0; + for (int type : types) + { + e++; + if (e == 7) + e = 6; + + if (firstDate.get(type) > secondDate.get(type)) + { + int time = secondDate.get(types[e]) + 1; + secondDate.set(types[e], time); + } + + if (secondDate.get(type) > Calendar.getInstance().getMaximum(type)) + { + secondDate.set(type, secondDate.get(type - 1)); + int time = secondDate.get(types[e]) + 1; + secondDate.set(types[e], time); + } + + } + + _dates.put(firstDate.getTime(), secondDate.getTime()); + } + } + +} \ No newline at end of file diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/HeadShotStatTracker.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/HeadShotStatTracker.java index 3e7c37303..c551e3e76 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/HeadShotStatTracker.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/HeadShotStatTracker.java @@ -4,7 +4,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import nautilus.game.arcade.game.Game; -import nautilus.game.arcade.game.games.minestrike.MineStrike; +import nautilus.game.arcade.game.games.minestrike.PlayerHeadshotEvent; public class HeadShotStatTracker extends StatTracker { @@ -23,7 +23,7 @@ public class HeadShotStatTracker extends StatTracker } @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) - public void onPlayerHeadshot(MineStrike.PlayerHeadshotEvent event) + public void onPlayerHeadshot(PlayerHeadshotEvent event) { addStat(event.getShooter(), "Headshot", 1, false, false); } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/KaboomStatTracker.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/KaboomStatTracker.java index 7f4387d6b..5110df7d2 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/KaboomStatTracker.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/KaboomStatTracker.java @@ -4,13 +4,13 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; -import nautilus.game.arcade.game.games.minestrike.MineStrike; +import nautilus.game.arcade.game.games.minestrike.Minestrike; import nautilus.game.arcade.game.games.minestrike.items.grenades.Grenade; import nautilus.game.arcade.game.games.minestrike.items.grenades.HighExplosive; -public class KaboomStatTracker extends StatTracker +public class KaboomStatTracker extends StatTracker { - public KaboomStatTracker(MineStrike game) + public KaboomStatTracker(Minestrike game) { super(game); } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/KillAllOpposingMineStrikeRoundStatTracker.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/KillAllOpposingMineStrikeRoundStatTracker.java index 949d01d41..e71bcffd8 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/KillAllOpposingMineStrikeRoundStatTracker.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/KillAllOpposingMineStrikeRoundStatTracker.java @@ -14,14 +14,14 @@ import mineplex.core.common.util.UtilPlayer; import mineplex.minecraft.game.core.combat.event.CombatDeathEvent; import nautilus.game.arcade.game.Game; import nautilus.game.arcade.game.GameTeam; -import nautilus.game.arcade.game.TeamGame; -import nautilus.game.arcade.game.games.minestrike.MineStrike; +import nautilus.game.arcade.game.games.minestrike.GunModule; +import nautilus.game.arcade.game.games.minestrike.Minestrike; -public class KillAllOpposingMineStrikeRoundStatTracker extends StatTracker +public class KillAllOpposingMineStrikeRoundStatTracker extends StatTracker { private final Map> _kills = new HashMap<>(); - public KillAllOpposingMineStrikeRoundStatTracker(MineStrike game) + public KillAllOpposingMineStrikeRoundStatTracker(Minestrike game) { super(game); } @@ -63,7 +63,7 @@ public class KillAllOpposingMineStrikeRoundStatTracker extends StatTracker { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/MineStrikeLastAliveKillStatTracker.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/MineStrikeLastAliveKillStatTracker.java index 958dfe1a3..fe53d5984 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/MineStrikeLastAliveKillStatTracker.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/MineStrikeLastAliveKillStatTracker.java @@ -13,13 +13,14 @@ import mineplex.core.common.util.UtilPlayer; import mineplex.minecraft.game.core.combat.event.CombatDeathEvent; import nautilus.game.arcade.game.Game; import nautilus.game.arcade.game.GameTeam; -import nautilus.game.arcade.game.games.minestrike.MineStrike; +import nautilus.game.arcade.game.games.minestrike.GunModule; +import nautilus.game.arcade.game.games.minestrike.Minestrike; -public class MineStrikeLastAliveKillStatTracker extends StatTracker +public class MineStrikeLastAliveKillStatTracker extends StatTracker { private final Map _killCount = new HashMap<>(); - public MineStrikeLastAliveKillStatTracker(MineStrike game) + public MineStrikeLastAliveKillStatTracker(Minestrike game) { super(game); } @@ -45,7 +46,7 @@ public class MineStrikeLastAliveKillStatTracker extends StatTracker } @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) - public void onRoundOver(MineStrike.RoundOverEvent event) + public void onRoundOver(GunModule.RoundOverEvent event) { for (GameTeam team : getGame().GetTeamList()) { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/world/WorldData.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/world/WorldData.java index 63b45effa..fdd9af536 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/world/WorldData.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/world/WorldData.java @@ -450,17 +450,6 @@ public class WorldData World = null; } - - public void ChunkUnload(ChunkUnloadEvent event) - { - if (World == null) - return; - - if (!event.getWorld().equals(World)) - return; - - event.setCancelled(true); - } public void ChunkLoad(ChunkPreLoadEvent event) {