From 60a468d03d661511bd420d009aaf433e9029129c Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 27 Feb 2018 16:33:27 +0000 Subject: [PATCH] Cake Wars 1.4 --- .../mineplex/core/common/util/UtilEnt.java | 35 ++++ .../src/mineplex/core/game/kit/GameKit.java | 3 +- .../arcade/game/games/cakewars/CakeWars.java | 42 ++++- .../cakewars/general/CakePlayerModule.java | 76 ++++++-- .../games/cakewars/kits/KitCakeArcher.java | 56 +++++- .../cakewars/kits/perk/PerkLifeSteal.java | 9 +- .../kits/perk/PerkPassiveWoolGain.java | 50 +++++- .../games/cakewars/shop/CakeShopModule.java | 51 +++++- .../games/cakewars/shop/CakeTeamItem.java | 4 +- .../game/games/cakewars/team/CakeTeam.java | 2 +- .../games/cakewars/team/CakeTeamModule.java | 3 +- .../games/cakewars/ui/CakeResourcePage.java | 2 +- .../game/games/turfforts/TurfForts.java | 166 ++++++++---------- .../game/arcade/kit/perks/PerkFletcher.java | 28 ++- 14 files changed, 380 insertions(+), 147 deletions(-) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEnt.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEnt.java index f7b4904a1..9d9cf6469 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEnt.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEnt.java @@ -10,6 +10,7 @@ import java.util.List; import java.util.Map; import net.minecraft.server.v1_8_R3.AxisAlignedBB; +import net.minecraft.server.v1_8_R3.EntityArrow; import net.minecraft.server.v1_8_R3.EntityBat; import net.minecraft.server.v1_8_R3.EntityCreature; import net.minecraft.server.v1_8_R3.EntityEnderDragon; @@ -37,10 +38,12 @@ import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; import org.bukkit.craftbukkit.v1_8_R3.TrigMath; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftArrow; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftCreature; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftLivingEntity; import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.Arrow; import org.bukkit.entity.Creature; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; @@ -1089,4 +1092,36 @@ public class UtilEnt entity.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); ((CraftWorld) location.getWorld()).getHandle().addEntity(entity, SpawnReason.CUSTOM); } + + public static Block getHitBlock(Entity arrow) + { + if (!(arrow instanceof Arrow)) + { + return null; + } + + try + { + EntityArrow entityArrow = ((CraftArrow) arrow).getHandle(); + + Field fieldX = EntityArrow.class.getDeclaredField("d"); + Field fieldY = EntityArrow.class.getDeclaredField("e"); + Field fieldZ = EntityArrow.class.getDeclaredField("f"); + + fieldX.setAccessible(true); + fieldY.setAccessible(true); + fieldZ.setAccessible(true); + + int x = fieldX.getInt(entityArrow); + int y = fieldY.getInt(entityArrow); + int z = fieldZ.getInt(entityArrow); + + return arrow.getWorld().getBlockAt(x, y, z); + } + catch (Exception ex) + { + ex.printStackTrace(); + return null; + } + } } \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/game/kit/GameKit.java b/Plugins/Mineplex.Core/src/mineplex/core/game/kit/GameKit.java index 2c48b4747..d573c556f 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/game/kit/GameKit.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/game/kit/GameKit.java @@ -495,7 +495,8 @@ public enum GameKit { "Get extra blocks to build with!", C.blankLine, - receiveItem("Wool Block", 1, 4, 32), + receiveItem("Knitted Wool", 1, 4, 32), + receiveItem("Knitted Platform", 1, 10, 5), }, new KitEntityData<> ( diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/CakeWars.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/CakeWars.java index 429bc928b..3341d750b 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/CakeWars.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/CakeWars.java @@ -13,11 +13,17 @@ import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.entity.EntityChangeBlockEvent; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; + import mineplex.core.Managers; import mineplex.core.common.util.C; import mineplex.core.common.util.UtilAlg; @@ -104,6 +110,7 @@ public class CakeWars extends TeamGame private static final LeaderboardManager LEADERBOARD_MANAGER = Managers.get(LeaderboardManager.class); private final Map _averages; + private final Cache _deathsInLastMinute; private final CakeTeamModule _cakeTeamModule; private final CakePlayerModule _cakePlayerModule; @@ -134,6 +141,9 @@ public class CakeWars extends TeamGame }, DESCRIPTION); _averages = new HashMap<>(4); + _deathsInLastMinute = CacheBuilder.newBuilder() + .expireAfterWrite(60, TimeUnit.SECONDS) + .build(); AnnounceStay = false; BlockPlace = true; @@ -573,7 +583,37 @@ public class CakeWars extends TeamGame @Override public double GetKillsGems(Player killer, Player killed, boolean assist) { - return assist ? 2 : 6; + if (getDeathsInLastMinute(killed) > 2) + { + return 0; + } + + return assist ? 1 : 3; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void playerDeath(PlayerDeathEvent event) + { + if (!IsLive()) + { + return; + } + + Player player = event.getEntity(); + _deathsInLastMinute.put(System.currentTimeMillis(), player); + } + + @EventHandler + public void playerQuit(PlayerQuitEvent event) + { + _deathsInLastMinute.asMap().values().removeIf(player -> player.equals(event.getPlayer())); + } + + public int getDeathsInLastMinute(Player player) + { + return (int) _deathsInLastMinute.asMap().values().stream() + .filter(player::equals) + .count(); } public Location getAverageLocation(GameTeam team) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/general/CakePlayerModule.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/general/CakePlayerModule.java index 1ba201d84..6104142b8 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/general/CakePlayerModule.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/general/CakePlayerModule.java @@ -1,7 +1,9 @@ package nautilus.game.arcade.game.games.cakewars.general; +import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; @@ -28,14 +30,19 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; 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.MapUtil; import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilInv; +import mineplex.core.common.util.UtilParticle.ParticleType; import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.particles.ColoredParticle; +import mineplex.core.common.util.particles.DustSpellColor; import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.recharge.Recharge; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.minecraft.game.core.damage.CustomDamageEvent; @@ -44,6 +51,7 @@ import nautilus.game.arcade.events.GameStateChangeEvent; import nautilus.game.arcade.events.PlayerGameRespawnEvent; import nautilus.game.arcade.events.PlayerKitGiveEvent; import nautilus.game.arcade.game.Game.GameState; +import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.game.games.cakewars.CakeModule; import nautilus.game.arcade.game.games.cakewars.CakeWars; @@ -66,7 +74,7 @@ public class CakePlayerModule extends CakeModule .setUnbreakable(true) .build(); private static final int PLATFORM_DELTA = 1; - private static final PotionEffect SPAWN_PROTECTION = new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 120, 0); + private static final int PLATFORM_WARMUP_TICKS = 40; private final Set _placedBlocks; // Used to store the inventory of a player when using the rune of holding @@ -128,7 +136,7 @@ public class CakePlayerModule extends CakeModule { event.setCancelled(true); } - else if (UtilBlock.airFoliage(event.getBlock())) + else if (UtilBlock.airFoliage(block) || block.getType() == Material.LEAVES || block.getType() == Material.LEAVES_2) { event.setCancelled(true); block.setType(Material.AIR); @@ -136,7 +144,7 @@ public class CakePlayerModule extends CakeModule else if (!_placedBlocks.contains(block)) { event.setCancelled(true); - event.getPlayer().sendMessage(F.main("Game", "You cannot break blocks that have not been placed by players.")); + player.sendMessage(F.main("Game", "You cannot break blocks that have not been placed by players.")); } } @@ -278,7 +286,7 @@ public class CakePlayerModule extends CakeModule { Player player = event.GetPlayer(); - _game.getArcadeManager().runSyncLater(() -> player.addPotionEffect(SPAWN_PROTECTION), 5); + _game.getArcadeManager().runSyncLater(() -> player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, (6 + _game.getDeathsInLastMinute(player) * 2) * 20, 0)), 5); } @EventHandler @@ -328,7 +336,8 @@ public class CakePlayerModule extends CakeModule } BlockFace face = UtilBlock.getFace(player.getLocation().getYaw()).getOppositeFace(); - byte teamData = _game.GetTeam(player).GetColorData(); + GameTeam team = _game.GetTeam(player); + byte teamData = team.GetColorData(); boolean blockChanged = false; if (itemStack.getType() == DEPLOY_PLATFORM.getType()) @@ -357,6 +366,12 @@ public class CakePlayerModule extends CakeModule { event.setCancelled(true); + if (!Recharge.Instance.use(player, "Place Wall", 500, false, false)) + { + return; + } + + List changed = new ArrayList<>(); boolean xAxis = face == BlockFace.NORTH || face == BlockFace.SOUTH; block = block.getRelative(BlockFace.UP).getRelative(BlockFace.UP); @@ -365,7 +380,6 @@ public class CakePlayerModule extends CakeModule for (int y = -PLATFORM_DELTA; y <= PLATFORM_DELTA; y++) { Block nearby = block.getRelative(xAxis ? x : 0, y, xAxis ? 0 : x); - Location nearbyLocation = nearby.getLocation(); if (isInvalidBlock(nearby)) { @@ -373,15 +387,53 @@ public class CakePlayerModule extends CakeModule } _placedBlocks.add(nearby); - MapUtil.QuickChangeBlockAt(nearbyLocation, Material.WOOL, teamData); + changed.add(nearby); blockChanged = true; - - if (Math.random() > 0.5) - { - nearbyLocation.getWorld().playEffect(nearbyLocation, Effect.STEP_SOUND, Material.WOOL, teamData); - } } } + + DustSpellColor color = new DustSpellColor(team.GetColorBase()); + + _game.getArcadeManager().runSyncTimer(new BukkitRunnable() + { + int ticks = 0; + + @Override + public void run() + { + if (++ticks == PLATFORM_WARMUP_TICKS) + { + cancel(); + + for (Block wall : changed) + { + MapUtil.QuickChangeBlockAt(wall.getLocation(), Material.WOOL, teamData); + + if (Math.random() > 0.5) + { + wall.getWorld().playEffect(wall.getLocation(), Effect.STEP_SOUND, Material.WOOL, teamData); + } + } + } + else + { + int index = 0; + double maxY = ((double) ticks / PLATFORM_WARMUP_TICKS) * 3; + + for (Block wall : changed) + { + if (index++ % 3 == 0) + { + for (double y = 0; y < maxY; y += 0.2) + { + new ColoredParticle(ParticleType.RED_DUST, color, wall.getLocation().add(xAxis ? Math.random() : 0.5, y, xAxis ? 0.5 : Math.random())) + .display(); + } + } + } + } + } + }, 0, 1); } if (blockChanged) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/kits/KitCakeArcher.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/kits/KitCakeArcher.java index a8bf42333..f3263e521 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/kits/KitCakeArcher.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/kits/KitCakeArcher.java @@ -1,7 +1,17 @@ package nautilus.game.arcade.game.games.cakewars.kits; -import org.bukkit.entity.Player; +import java.util.HashSet; +import java.util.Set; +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.entity.EntityShootBowEvent; +import org.bukkit.event.entity.ProjectileHitEvent; + +import mineplex.core.common.util.UtilEnt; import mineplex.core.game.kit.GameKit; import nautilus.game.arcade.ArcadeManager; @@ -14,12 +24,16 @@ public class KitCakeArcher extends Kit private static final Perk[] PERKS = { - new PerkFletcher(6, 3, true) + new PerkFletcher(6, 3, true, -1, true, "Piercing Arrows"), }; + private final Set _piercingArrows; + public KitCakeArcher(ArcadeManager manager) { super(manager, GameKit.CAKE_WARS_ARCHER, PERKS); + + _piercingArrows = new HashSet<>(); } @Override @@ -27,4 +41,42 @@ public class KitCakeArcher extends Kit { } + @EventHandler + public void bowShoot(EntityShootBowEvent event) + { + if (!(event.getEntity() instanceof Player)) + { + return; + } + + Player player = (Player) event.getEntity(); + + if (!HasKit(player) || event.getForce() != 1) + { + return; + } + + _piercingArrows.add(event.getProjectile()); + } + + @EventHandler + public void projectileHit(ProjectileHitEvent event) + { + if (!_piercingArrows.remove(event.getEntity())) + { + return; + } + + Manager.runSyncLater(() -> + { + Block block = UtilEnt.getHitBlock(event.getEntity()); + + if (block.getType() != Material.WOOL) + { + return; + } + + block.breakNaturally(); + }, 0); + } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/kits/perk/PerkLifeSteal.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/kits/perk/PerkLifeSteal.java index 16bcc0047..28eb23657 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/kits/perk/PerkLifeSteal.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/kits/perk/PerkLifeSteal.java @@ -6,6 +6,7 @@ import org.bukkit.event.entity.PlayerDeathEvent; import mineplex.core.common.util.UtilPlayer; +import nautilus.game.arcade.game.games.cakewars.CakeWars; import nautilus.game.arcade.kit.Perk; public class PerkLifeSteal extends Perk @@ -23,11 +24,15 @@ public class PerkLifeSteal extends Perk @EventHandler public void playerDeath(PlayerDeathEvent event) { - Player killer = event.getEntity().getKiller(); + Player player = event.getEntity(); + Player killer = player.getKiller(); if (killer != null && hasPerk(killer)) { - UtilPlayer.health(killer, _increase); + CakeWars game = (CakeWars) Manager.GetGame(); + double increase = Math.max(0, _increase - game.getDeathsInLastMinute(player)); + + UtilPlayer.health(killer, increase); } } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/kits/perk/PerkPassiveWoolGain.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/kits/perk/PerkPassiveWoolGain.java index 0cb93085e..7ec49f61e 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/kits/perk/PerkPassiveWoolGain.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/kits/perk/PerkPassiveWoolGain.java @@ -5,23 +5,35 @@ import java.util.concurrent.TimeUnit; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.inventory.ItemStack; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilInv; import mineplex.core.common.util.UtilPlayer; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.recharge.Recharge; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.game.games.cakewars.general.CakePlayerModule; import nautilus.game.arcade.kit.Perk; public class PerkPassiveWoolGain extends Perk { + private static final long WOOL_RECHARGE = TimeUnit.SECONDS.toMillis(4); private static final long PLATFORM_RECHARGE = TimeUnit.SECONDS.toMillis(10); private static final int MAX_WOOL = 32; - private static final int MAX_PLATFORMS = 8; + private static final int MAX_PLATFORMS = 5; + private static final String WOOL_NAME = "Knitted Wool"; + private static final String PLATFORM_NAME = "Knitted Platform"; + private static final ItemStack PLATFORM_ITEM = new ItemBuilder(CakePlayerModule.DEPLOY_PLATFORM) + .setTitle(C.cYellowB + PLATFORM_NAME) + .build(); public PerkPassiveWoolGain() { @@ -31,7 +43,7 @@ public class PerkPassiveWoolGain extends Perk @EventHandler public void updateGain(UpdateEvent event) { - if (event.getType() != UpdateType.SEC_05 || !Manager.GetGame().IsLive()) + if (event.getType() != UpdateType.SEC || !Manager.GetGame().IsLive()) { return; } @@ -43,16 +55,16 @@ public class PerkPassiveWoolGain extends Perk continue; } - if (!player.getInventory().contains(Material.WOOL, MAX_WOOL)) + if (!player.getInventory().contains(Material.WOOL, MAX_WOOL) && Recharge.Instance.use(player, WOOL_NAME, WOOL_RECHARGE, false, false)) { ItemStack itemStack = new ItemStack(Material.WOOL, 1, (short) 0, Manager.GetGame().GetTeam(player).GetColorData()); player.getInventory().addItem(itemStack); } - if (!player.getInventory().contains(Material.INK_SACK, MAX_PLATFORMS) && Recharge.Instance.use(player, "Knitted Platforms", PLATFORM_RECHARGE, false, false)) + if (!player.getInventory().contains(Material.INK_SACK, MAX_PLATFORMS) && Recharge.Instance.use(player, PLATFORM_NAME, PLATFORM_RECHARGE, false, false)) { - ItemStack itemStack = new ItemBuilder(CakePlayerModule.DEPLOY_PLATFORM) + ItemStack itemStack = new ItemBuilder(PLATFORM_ITEM) .setData(Manager.GetGame().GetTeam(player).getDyeColor().getDyeData()) .build(); @@ -60,4 +72,32 @@ public class PerkPassiveWoolGain extends Perk } } } + + @EventHandler + public void inventoryClick(InventoryClickEvent event) + { + Player player = (Player) event.getWhoClicked(); + GameTeam team = Manager.GetGame().GetTeam(player); + + if (!hasPerk(player) || team == null) + { + return; + } + + UtilInv.DisallowMovementOf(event, PLATFORM_NAME, PLATFORM_ITEM.getType(), team.getDyeColor().getDyeData(), true); + } + + @EventHandler + public void playerDrop(PlayerDropItemEvent event) + { + Player player = event.getPlayer(); + ItemStack itemStack = event.getItemDrop().getItemStack(); + GameTeam team = Manager.GetGame().GetTeam(player); + + if (hasPerk(player) && team != null && UtilInv.IsItem(itemStack, PLATFORM_NAME, PLATFORM_ITEM.getType(), team.getDyeColor().getDyeData())) + { + event.setCancelled(true); + event.getPlayer().sendMessage(F.main("Game", "You cannot drop " + F.item(PLATFORM_NAME) + ".")); + } + } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/shop/CakeShopModule.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/shop/CakeShopModule.java index 78353d82a..d48749add 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/shop/CakeShopModule.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/shop/CakeShopModule.java @@ -10,8 +10,8 @@ import java.util.Set; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.entity.LivingEntity; import org.bukkit.block.Block; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.Villager; import org.bukkit.event.EventHandler; @@ -29,7 +29,11 @@ import mineplex.core.common.util.MapUtil; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilItem; import mineplex.core.common.util.UtilMath; +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.particles.ColoredParticle; +import mineplex.core.common.util.particles.DustSpellColor; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.newnpc.NPC; import mineplex.core.newnpc.NewNPCManager; @@ -58,6 +62,7 @@ public class CakeShopModule extends CakeModule .setTitle(C.cPurpleB + "Ender Pearl") .addLore("", "Warning! Ender Pearls have a", C.cRed + "7 second" + C.cGray + " cooldown between uses.") .build(); + static final int HEALING_STATION_RADIUS = 5; private final NewNPCManager _manager; private final Map _npcs; @@ -81,8 +86,8 @@ public class CakeShopModule extends CakeModule // Iron Set new CakeShopItem(CakeShopItemType.HELMET, new ItemStack(Material.IRON_HELMET), 5), - new CakeShopItem(CakeShopItemType.CHESTPLATE, new ItemStack(Material.IRON_CHESTPLATE), 7), - new CakeShopItem(CakeShopItemType.LEGGINGS, new ItemStack(Material.IRON_LEGGINGS), 7), + new CakeShopItem(CakeShopItemType.CHESTPLATE, new ItemStack(Material.IRON_CHESTPLATE), 8), + new CakeShopItem(CakeShopItemType.LEGGINGS, new ItemStack(Material.IRON_LEGGINGS), 6), new CakeShopItem(CakeShopItemType.BOOTS, new ItemStack(Material.IRON_BOOTS), 5), // Sword @@ -98,7 +103,7 @@ public class CakeShopModule extends CakeModule new CakeShopItem(CakeShopItemType.AXE, new ItemStack(Material.IRON_AXE), 3), // Arrow - new CakeShopItem(CakeShopItemType.OTHER, new ItemStack(Material.ARROW, 3), 15), + new CakeShopItem(CakeShopItemType.OTHER, new ItemStack(Material.ARROW, 3), 12), // Blocks // Wool @@ -125,8 +130,8 @@ public class CakeShopModule extends CakeModule // Diamond Set new CakeShopItem(CakeShopItemType.HELMET, new ItemStack(Material.DIAMOND_HELMET), 10), - new CakeShopItem(CakeShopItemType.CHESTPLATE, new ItemStack(Material.DIAMOND_CHESTPLATE), 20), - new CakeShopItem(CakeShopItemType.LEGGINGS, new ItemStack(Material.DIAMOND_LEGGINGS), 20), + new CakeShopItem(CakeShopItemType.CHESTPLATE, new ItemStack(Material.DIAMOND_CHESTPLATE), 24), + new CakeShopItem(CakeShopItemType.LEGGINGS, new ItemStack(Material.DIAMOND_LEGGINGS), 16), new CakeShopItem(CakeShopItemType.BOOTS, new ItemStack(Material.DIAMOND_BOOTS), 10), // Sword @@ -154,7 +159,7 @@ public class CakeShopModule extends CakeModule new CakeShopItem(CakeShopItemType.OTHER, CakePlayerModule.RUNE_OF_HOLDING, 20), // Insta-Wall - new CakeShopItem(CakeShopItemType.OTHER, CakePlayerModule.INSTA_WALL, 3), + new CakeShopItem(CakeShopItemType.OTHER, CakePlayerModule.INSTA_WALL, 2), // Traps new CakeTNTTrap(8), @@ -307,6 +312,38 @@ public class CakeShopModule extends CakeModule }); } + @EventHandler + public void updateHealingParticles(UpdateEvent event) + { + if (event.getType() != UpdateType.FASTEST || !_game.IsLive()) + { + return; + } + + _game.getCakeTeamModule().getCakeTeams().forEach((team, cakeTeam) -> + { + if (cakeTeam.getUpgrades().getOrDefault(CakeTeamItem.REGENERATION, 0) == 0) + { + return; + } + + Location location = cakeTeam.getCake().clone(); + DustSpellColor color = new DustSpellColor(team.GetColorBase()); + + for (double theta = 0; theta < 2 * Math.PI; theta += Math.PI / 20) + { + double x = HEALING_STATION_RADIUS * Math.cos(theta), z = HEALING_STATION_RADIUS * Math.sin(theta); + + location.add(x, 0, z); + + new ColoredParticle(ParticleType.RED_DUST, color, location) + .display(); + + location.subtract(x, 0, z); + } + }); + } + @EventHandler public void playerDeath(PlayerDeathEvent event) { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/shop/CakeTeamItem.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/shop/CakeTeamItem.java index af179482f..e9826ff74 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/shop/CakeTeamItem.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/shop/CakeTeamItem.java @@ -72,7 +72,7 @@ public enum CakeTeamItem implements CakeItem "Resource Generator", new ItemStack(Material.NETHER_STAR), 10, - 18 + 20 ), REGENERATION( "Healing Station", @@ -83,7 +83,7 @@ public enum CakeTeamItem implements CakeItem @Override public void apply(Player player, int level, Location cake) { - if (UtilMath.offset2dSquared(player.getLocation(), cake) < 25) + if (UtilMath.offset2dSquared(player.getLocation(), cake) < CakeShopModule.HEALING_STATION_RADIUS * CakeShopModule.HEALING_STATION_RADIUS) { player.removePotionEffect(PotionEffectType.REGENERATION); player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 60, level - 1, true, false)); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/team/CakeTeam.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/team/CakeTeam.java index 42f0739f8..3d9e33c0a 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/team/CakeTeam.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/team/CakeTeam.java @@ -53,7 +53,7 @@ public class CakeTeam _chest = chest.getBlock().getLocation(); _generator = generator.add(0, 1, 0); - _cake = game.WorldData.GetDataLocs(team.GetName().toUpperCase()).get(0).getBlock().getLocation(); + _cake = game.WorldData.GetDataLocs(team.GetName().toUpperCase()).get(0).getBlock().getLocation().add(0.5, 0.5, 0.5); _cake.getBlock().setType(Material.CAKE_BLOCK); _upgrades = new HashMap<>(CakeTeamItem.values().length); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/team/CakeTeamModule.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/team/CakeTeamModule.java index 70b52ea34..c7b3f1bdb 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/team/CakeTeamModule.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/team/CakeTeamModule.java @@ -208,7 +208,7 @@ public class CakeTeamModule extends CakeModule _teams.forEach((team, cakeTeam) -> { - if (!block.getLocation().equals(cakeTeam.getCake())) + if (!block.equals(cakeTeam.getCake().getBlock())) { return; } @@ -393,6 +393,7 @@ public class CakeTeamModule extends CakeModule if (killer != null) { + _game.AddGems(killer, 2, "Final Kills", true, true); _game.AddStat(killer, "FinalKills", 1, false, false); } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/ui/CakeResourcePage.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/ui/CakeResourcePage.java index 5ffbc6ee4..ebad6bafb 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/ui/CakeResourcePage.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/ui/CakeResourcePage.java @@ -225,7 +225,7 @@ public class CakeResourcePage extends ShopPageBase _enemyTurf = new HashMap(); - + private Set playersThatNeedBlocks = new HashSet(); - + public TurfForts(ArcadeManager manager) { super(manager, GameType.TurfWars, @@ -159,7 +158,7 @@ public class TurfForts extends TeamGame new BlockShreadStatTracker(this), new BehindEnemyLinesStatTracker(this), new TheComebackStatTracker(this), - new BlockPlaceStatTracker(this, new Material[]{}), + new BlockPlaceStatTracker(this, new Material[] {}), _breakStatTracker ); @@ -305,7 +304,7 @@ public class TurfForts extends TeamGame EndCheck(); } } - + @EventHandler public void BowCancel(EntityShootBowEvent event) { @@ -313,7 +312,7 @@ public class TurfForts extends TeamGame { UtilPlayer.message(event.getEntity(), F.main("Game", "You cannot attack during Build Time!")); event.setCancelled(true); - + ((Player) event.getEntity()).updateInventory(); } } @@ -323,9 +322,8 @@ public class TurfForts extends TeamGame { if (event.isCancelled()) // this statement might save just a small amount of time return; - - - + + if (!IsAlive(event.getPlayer())) { event.setCancelled(true); @@ -337,9 +335,9 @@ public class TurfForts extends TeamGame event.setCancelled(true); return; } - + Block block = event.getBlock(); - + GameTeam team = GetTeam(event.getPlayer()); GameTeam otherTeam = GetOtherTeam(team); @@ -376,7 +374,7 @@ public class TurfForts extends TeamGame event.setCancelled(true); return; } - + //On Own Block block = event.getBlock().getRelative(BlockFace.DOWN); while (block.getTypeId() == 0 && block.getY() > 0) @@ -427,54 +425,30 @@ public class TurfForts extends TeamGame final Arrow arrow = (Arrow) event.getEntity(); - Manager.getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(Manager.getPlugin(), new Runnable() + Manager.runSyncLater(() -> { - public void run() + Block block = UtilEnt.getHitBlock(arrow); + + if (block.getTypeId() == 35) { - try + if (block.getData() == 14 /* && team.GetColor() != ChatColor.RED */) { - EntityArrow entityArrow = ((CraftArrow) arrow).getHandle(); - - Field fieldX = EntityArrow.class.getDeclaredField("d"); - Field fieldY = EntityArrow.class.getDeclaredField("e"); - Field fieldZ = EntityArrow.class.getDeclaredField("f"); - - fieldX.setAccessible(true); - fieldY.setAccessible(true); - fieldZ.setAccessible(true); - - int x = fieldX.getInt(entityArrow); - int y = fieldY.getInt(entityArrow); - int z = fieldZ.getInt(entityArrow); - - Block block = arrow.getWorld().getBlockAt(x, y, z); - - if (block.getTypeId() == 35) - { - if (block.getData() == 14 /* && team.GetColor() != ChatColor.RED */) - { - block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, Material.REDSTONE_BLOCK.getId()); - _breakStatTracker.addStat(shooter); - } - else if (block.getData() == 3 /* && team.GetColor() != ChatColor.AQUA */) - { - block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, Material.LAPIS_BLOCK.getId()); - _breakStatTracker.addStat(shooter); - } - - Bukkit.getPluginManager().callEvent(new ShredBlockEvent(block, arrow)); - - - block.setType(Material.AIR); - } - - arrow.remove(); + block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, Material.REDSTONE_BLOCK.getId()); + _breakStatTracker.addStat(shooter); } - catch (Exception e) + else if (block.getData() == 3 /* && team.GetColor() != ChatColor.AQUA */) { - e.printStackTrace(); + block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, Material.LAPIS_BLOCK.getId()); + _breakStatTracker.addStat(shooter); } + + Bukkit.getPluginManager().callEvent(new ShredBlockEvent(block, arrow)); + + + block.setType(Material.AIR); } + + arrow.remove(); }, 0); } @@ -593,18 +567,18 @@ public class TurfForts extends TeamGame } } } - + public void addBlocks(GameTeam team, Player player) { player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.WOOL, team.GetColorData(), 24)); } - + @EventHandler(ignoreCancelled = true) public void onQuit(PlayerQuitEvent event) { this.playersThatNeedBlocks.remove(event.getPlayer().getUniqueId()); } - + @EventHandler(ignoreCancelled = true) public void onSpawn(PlayerKitGiveEvent event) { @@ -615,9 +589,8 @@ public class TurfForts extends TeamGame this.addBlocks(GetTeam(player), player); } } - - - + + @Override @EventHandler public void ScoreboardUpdate(UpdateEvent event) @@ -718,8 +691,8 @@ public class TurfForts extends TeamGame { for (Player player : team.GetPlayers(true)) { - if (((CraftPlayer) player).getHandle().spectating) - continue; + if (((CraftPlayer) player).getHandle().spectating) + continue; //Slow if (_enemyTurf.containsKey(player)) @@ -731,20 +704,20 @@ public class TurfForts extends TeamGame } Block block = player.getLocation().getBlock().getRelative(BlockFace.DOWN); - + // Apply velocity even if the player is sneaking near turf edges. - + if (block.isEmpty() && player.isOnGround()) { Block[] nearby = { - block.getRelative(BlockFace.NORTH), - block.getRelative(BlockFace.SOUTH), - block.getRelative(BlockFace.WEST), - block.getRelative(BlockFace.EAST), - block.getRelative(BlockFace.NORTH_EAST), - block.getRelative(BlockFace.NORTH_WEST), - block.getRelative(BlockFace.SOUTH_EAST), - block.getRelative(BlockFace.SOUTH_WEST) + block.getRelative(BlockFace.NORTH), + block.getRelative(BlockFace.SOUTH), + block.getRelative(BlockFace.WEST), + block.getRelative(BlockFace.EAST), + block.getRelative(BlockFace.NORTH_EAST), + block.getRelative(BlockFace.NORTH_WEST), + block.getRelative(BlockFace.SOUTH_EAST), + block.getRelative(BlockFace.SOUTH_WEST) }; for (Block near : nearby) @@ -756,7 +729,7 @@ public class TurfForts extends TeamGame } } } - + while (block.getTypeId() != 159 && block.getY() > 0) block = block.getRelative(BlockFace.DOWN); @@ -786,7 +759,7 @@ public class TurfForts extends TeamGame player.playSound(player.getLocation(), Sound.NOTE_BASS, 2f, 1f); UtilPlayer.message(player, F.main("Game", "You cannot walk on the enemies turf!")); } - + // return; } //On Own Turf @@ -818,19 +791,22 @@ public class TurfForts extends TeamGame } } */ - - - public GameTeam GetOtherTeam(GameTeam team) { + + + public GameTeam GetOtherTeam(GameTeam team) + { return team.GetColor() == ChatColor.RED ? GetTeam(ChatColor.AQUA) : GetTeam(ChatColor.RED); } - + @EventHandler - public void onItem(ItemSpawnEvent e) { - if (e.getEntityType().equals(EntityType.DROPPED_ITEM)) { + public void onItem(ItemSpawnEvent e) + { + if (e.getEntityType().equals(EntityType.DROPPED_ITEM)) + { e.setCancelled(true); } } - + @Override public void EndCheck() { @@ -860,31 +836,31 @@ public class TurfForts extends TeamGame if (player.isOnline()) AddGems(player, 10, "Participation", false, false); } - + endElo(); - + //End SetState(GameState.End); } - + public Long getEnemyTurfEntranceTime(Player player) { return _enemyTurf.get(player); } - + // Fixed by TeddyDev. @EventHandler public void blockGlitchFix(PlayerInteractEvent event) { - if(event.getAction() != Action.RIGHT_CLICK_BLOCK) + if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return; - if(event.getPlayer().isOnGround()) + if (event.getPlayer().isOnGround()) return; Block block = event.getClickedBlock(); - if(block.getType() == Material.STAINED_CLAY || block.getType() == Material.WOOL) + if (block.getType() == Material.STAINED_CLAY || block.getType() == Material.WOOL) return; Player player = event.getPlayer(); @@ -894,7 +870,7 @@ public class TurfForts extends TeamGame ground = ground.getRelative(BlockFace.DOWN); } - if(ground.isLiquid()) + if (ground.isLiquid()) { Manager.GetDamage().NewDamageEvent(player, null, null, DamageCause.VOID, 9001, false, false, false, @@ -903,7 +879,7 @@ public class TurfForts extends TeamGame return; } - if(player.getLocation().distance(ground.getLocation()) < 4) + if (player.getLocation().distance(ground.getLocation()) < 4) return; Manager.GetDamage().NewDamageEvent(player, null, null, @@ -911,16 +887,16 @@ public class TurfForts extends TeamGame "Border", "Border Damage"); player.playSound(player.getLocation(), Sound.NOTE_BASS, 2f, 1f); } - + // Keep ladders placed on ice when block updates occur. @EventHandler public void ladderDestroyFix(BlockPhysicsEvent event) { if (!IsLive()) return; - + Block block = event.getBlock(); - + if (block.getType() == Material.LADDER) { event.setCancelled(true); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkFletcher.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkFletcher.java index 8c2245cba..314834591 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkFletcher.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkFletcher.java @@ -2,6 +2,7 @@ package nautilus.game.arcade.kit.perks; import java.util.HashSet; import java.util.Iterator; +import java.util.Set; import mineplex.core.Managers; import mineplex.core.common.util.F; @@ -32,7 +33,8 @@ import org.bukkit.inventory.meta.ItemMeta; public class PerkFletcher extends Perk { - private HashSet _fletchArrows = new HashSet(); + + private final Set _fletchArrows = new HashSet<>(); private int _max = 0; private int _time = 0; @@ -94,17 +96,13 @@ public class PerkFletcher extends Perk public boolean isFletchedArrow(ItemStack stack) { if (!UtilGear.isMat(stack, Material.ARROW)) + { return false; - + } + ItemMeta meta = stack.getItemMeta(); - - if (meta.getDisplayName() == null) - return false; - - if (!meta.getDisplayName().contains(_name)) - return false; - - return true; + + return meta.hasDisplayName() && meta.getDisplayName().contains(_name); } @EventHandler @@ -245,14 +243,10 @@ public class PerkFletcher extends Perk public void FletchClean(UpdateEvent event) { if (event.getType() != UpdateType.SEC) - return; - - for (Iterator arrowIterator = _fletchArrows.iterator(); arrowIterator.hasNext();) { - Entity arrow = arrowIterator.next(); - - if (arrow.isDead() || !arrow.isValid()) - arrowIterator.remove(); + return; } + + _fletchArrows.removeIf(arrow -> arrow.isDead() || !arrow.isValid()); } } \ No newline at end of file