diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java index 5995d93d3..3a0e97fc6 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java @@ -37,7 +37,6 @@ import org.bukkit.event.inventory.CraftItemEvent; import org.bukkit.event.inventory.PrepareItemCraftEvent; import org.bukkit.event.player.PlayerBucketEmptyEvent; import org.bukkit.event.player.PlayerBucketFillEvent; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.inventory.CraftingInventory; @@ -70,12 +69,15 @@ 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.DebugCommand; import nautilus.game.arcade.game.Game; import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.game.TeamGame; import nautilus.game.arcade.game.games.bridge.animation.BridgeAnimation; import nautilus.game.arcade.game.games.bridge.animation.BridgeAnimationType; -import nautilus.game.arcade.game.games.bridge.animation.CustomBridgeAnimation; +import nautilus.game.arcade.game.games.bridge.animation.custom.CustomBridgeAnimation; +import nautilus.game.arcade.game.games.bridge.animation.custom.RadiusCustomBridgeAnimation; +import nautilus.game.arcade.game.games.bridge.animation.custom.RandomCustomBridgeAnimation; import nautilus.game.arcade.game.games.bridge.kits.KitApple; import nautilus.game.arcade.game.games.bridge.kits.KitArcher; import nautilus.game.arcade.game.games.bridge.kits.KitBerserker; @@ -114,11 +116,14 @@ public class Bridge extends TeamGame implements OreObsfucation */ private static final int WORLD_BORDER_PREPARE_TICKS = 20; + private static final String CUSTOM_BRIDGE_KEY = "TYPE"; + //Bridge private long _bridgeTime = BRIDGE_TIME; private boolean _bridgesDown = false; private BridgeAnimation _animation; - + private CustomBridgeAnimation[] _customAnimations; + private HashSet _bridgeParts = new HashSet(); //Animals @@ -249,6 +254,11 @@ public class Bridge extends TeamGame implements OreObsfucation _tournament = true; } + _customAnimations = new CustomBridgeAnimation[] { + new RandomCustomBridgeAnimation(this), + new RadiusCustomBridgeAnimation(this) + }; + new CompassModule() .setGiveCompassToAlive(true) .register(this); @@ -269,6 +279,34 @@ public class Bridge extends TeamGame implements OreObsfucation break; } } + + registerDebugCommand(new DebugCommand("bridge", Rank.ADMIN) + { + + @Override + public void Execute(Player caller, String[] args) + { + caller.sendMessage(F.main("Debug", "Spawning the bridges.")); + _bridgeTime = 3000; + } + }); + + registerDebugCommand(new DebugCommand("bridgeinfo", getArcadeManager().getGameCommandRank()) + { + + @Override + public void Execute(Player caller, String[] args) + { + if (_animation == null || !(_animation instanceof CustomBridgeAnimation)) + { + caller.sendMessage(F.main("Debug", "The bridge animation for this map isn't a custom one.")); + return; + } + + caller.sendMessage(F.main("Debug", "Bridge Info:")); + caller.sendMessage(_animation.toString()); + } + }); } @EventHandler @@ -354,15 +392,41 @@ public class Bridge extends TeamGame implements OreObsfucation } _animation = type.createInstance(this); - _animation.onParse(); + break; } + // If none of the premade ones are usable then we need a custom one! if (_animation == null) { - _animation = new CustomBridgeAnimation(this); - _animation.onParse(); + locationLoop : for (String key : WorldData.GetAllCustomLocs().keySet()) + { + if (!key.startsWith(CUSTOM_BRIDGE_KEY)) + { + continue; + } + + String[] split = key.split(" "); + + if (split.length < 2) + { + continue; + } + + String subKey = split[1]; + + for (CustomBridgeAnimation animation : _customAnimations) + { + if (animation.getTypeKey().equalsIgnoreCase(subKey)) + { + _animation = animation; + break locationLoop; + } + } + } } + _animation.onParse(); + ParseChests(); ParseOre(WorldData.GetCustomLocs("73")); // Red @@ -727,7 +791,7 @@ public class Bridge extends TeamGame implements OreObsfucation for (Player player : GetPlayers(true)) { - borderModule.setSize(player, 1000); + borderModule.setSize(player, 10000); } Manager.GetExplosion().SetLiquidDamage(true); @@ -1713,16 +1777,6 @@ public class Bridge extends TeamGame implements OreObsfucation else return 12; } - - @EventHandler - public void debug(PlayerCommandPreprocessEvent event) - { - if (Manager.GetClients().hasRank(event.getPlayer(), Rank.ADMIN) && event.getMessage().contains("/oretoggle")) - _ore.ToggleVisibility(); - - if (Manager.GetClients().hasRank(event.getPlayer(), Rank.ADMIN) && event.getMessage().contains("/bridge")) - _bridgeTime = 3000; - } @EventHandler public void disableIceForm(BlockFormEvent event) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/CustomBridgeAnimation.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/CustomBridgeAnimation.java deleted file mode 100644 index 921676590..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/CustomBridgeAnimation.java +++ /dev/null @@ -1,153 +0,0 @@ -package nautilus.game.arcade.game.games.bridge.animation; - -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.Sound; -import org.bukkit.block.Block; - -import mineplex.core.blockrestore.BlockRestore; -import mineplex.core.common.util.UtilBlock; -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.updater.UpdateType; -import nautilus.game.arcade.game.games.bridge.Bridge; - -public class CustomBridgeAnimation extends BridgeAnimation -{ - - private static final String REGION_KEY = "BRIDGE"; - private static final String BRIDGE_DATA_KEY = "CUSTOM_BRIDGE"; - private static final double RATE = 0.5; - - private final BlockRestore _restore; - private final Map _bridgeBlocks; - - private int[] _blockIds; - - private double _maxDistance; - private double _minDistance; - - public CustomBridgeAnimation(Bridge bridge) - { - super(bridge); - - _restore = bridge.getArcadeManager().GetBlockRestore(); - _bridgeBlocks = new HashMap<>(AVERAGE_BRIDGE_BLOCKS); - } - - @Override - public void onParse() - { - _maxDistance = 0; - - for (String key : _worldData.GetAllCustomLocs().keySet()) - { - if (!key.startsWith(BRIDGE_DATA_KEY)) - { - continue; - } - - String[] split = key.split(" "); - int[] blockIds = new int[split.length - 1]; - - for (int i = 1; i < split.length; i++) - { - try - { - blockIds[i - 1] = Integer.parseInt(split[i]); - } - catch (NumberFormatException e) - { - continue; - } - } - - _blockIds = blockIds; - } - - for (String key : _worldData.GetAllCustomLocs().keySet()) - { - if (!key.startsWith(REGION_KEY)) - { - continue; - } - - List locations = _worldData.GetCustomLocs(key); - - if (locations.size() < 2) - { - continue; - } - - for (Block block : UtilBlock.getInBoundingBox(locations.get(0), locations.get(1))) - { - boolean shouldAdd = false; - - for (int id : _blockIds) - { - if (block.getTypeId() == id) - { - shouldAdd = true; - break; - } - } - - if (!shouldAdd) - { - continue; - } - - double dist = UtilMath.offset2d(block.getLocation(), _bridge.GetSpectatorLocation()); - - if (dist > _maxDistance) - { - _maxDistance = dist; - } - - _restore.add(block, Material.AIR.getId(), (byte) 0, Integer.MAX_VALUE); - _bridgeBlocks.put(block.getLocation(), dist); - } - } - - _minDistance = _maxDistance; - } - - @Override - public void onUpdate(UpdateType type) - { - if (type != UpdateType.FAST) - { - return; - } - - _minDistance -= RATE; - - Iterator iterator = _bridgeBlocks.keySet().iterator(); - - while (iterator.hasNext()) - { - Location location = iterator.next(); - double dist = _bridgeBlocks.get(location); - - if (dist > _minDistance) - { - Block block = location.getBlock(); - - _restore.restore(block); - UtilParticle.PlayParticleToAll(ParticleType.FIREWORKS_SPARK, block.getLocation().add(0.5, 1.5, 0.5), 0.25F, 0.25F, 0.25F, 0.05F, 5, ViewDist.NORMAL); - - location.getWorld().playSound(location, Sound.ZOMBIE_UNFECT, 1.5F, 1); - - iterator.remove(); - } - } - } - -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/WoodBridgeAnimation.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/WoodBridgeAnimation.java index ecafe937b..e149f2bc3 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/WoodBridgeAnimation.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/WoodBridgeAnimation.java @@ -108,7 +108,7 @@ public class WoodBridgeAnimation extends BridgeAnimation } } - if (toDo.size() == 0) + if (toDo.isEmpty()) { return; } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/custom/CustomBridgeAnimation.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/custom/CustomBridgeAnimation.java new file mode 100644 index 000000000..18f45bd3f --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/custom/CustomBridgeAnimation.java @@ -0,0 +1,246 @@ +package nautilus.game.arcade.game.games.bridge.animation.custom; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.bukkit.Effect; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.World; +import org.bukkit.block.Block; + +import mineplex.core.blockrestore.BlockRestore; +import mineplex.core.common.util.UtilBlock; +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 nautilus.game.arcade.game.games.bridge.Bridge; +import nautilus.game.arcade.game.games.bridge.animation.BridgeAnimation; + +public abstract class CustomBridgeAnimation extends BridgeAnimation +{ + + private static final String BLOCK_IDS_KEY = "BLOCK_IDS"; + private static final String RATE_KEY = "RATE"; + private static final String PARTICLE_KEY = "PARTICLE"; + private static final String SOUND_KEY = "SOUND"; + private static final String REGION_KEY = "BRIDGE"; + + protected final BlockRestore _restore; + + private final String _typeKey; + protected final Map _bridgeBlocks; + + // Configuration + protected List _blockIds; + protected int _rate; + protected ParticleType _particle; + + // Sound + protected Sound _sound; + protected float _pitch; + + protected double _maxDistance; + + public CustomBridgeAnimation(Bridge bridge, String typeKey) + { + super(bridge); + + _restore = bridge.getArcadeManager().GetBlockRestore(); + + _typeKey = typeKey; + _bridgeBlocks = new HashMap<>(AVERAGE_BRIDGE_BLOCKS); + + // Defaults + // Wood, Logs, Fences + _blockIds = Arrays.asList(5, 17, 85); + _rate = 1; + _particle = ParticleType.BLOCK_DUST; + } + + @Override + public void onParse() + { + List blockIds = new ArrayList<>(); + + for (String key : _worldData.GetAllCustomLocs().keySet()) + { + String[] split = key.split(" "); + String subKey = split[0]; + + if (split.length < 2) + { + continue; + } + + switch (subKey) + { + + case BLOCK_IDS_KEY: + // Set the block ids that the animation will use + + for (int i = 1; i < split.length; i++) + { + try + { + blockIds.add(Integer.parseInt(split[i])); + } + catch (NumberFormatException e) + { + continue; + } + } + + break; + + case RATE_KEY: + // Set the rate at which the animation will run at + + try + { + _rate = Integer.parseInt(split[1]); + } + catch (NumberFormatException e) + { + continue; + } + + break; + + case PARTICLE_KEY: + // Set which type of particle will be displayed when a block + // spawns + + try + { + _particle = ParticleType.valueOf(split[1]); + } + catch (IllegalArgumentException e) + { + continue; + } + + break; + + case SOUND_KEY: + // Set the sound and pitch that will be played when a block + // spawns + + if (split.length < 3) + { + continue; + } + + try + { + _sound = Sound.valueOf(split[1]); + } + catch (IllegalArgumentException e) + { + continue; + } + + try + { + _pitch = Float.parseFloat(split[2]); + } + catch (NumberFormatException e) + { + continue; + } + + break; + + default: + break; + } + } + + // Set configuration values + _blockIds = blockIds; + + // Save all blocks in a big map. + for (String key : _worldData.GetAllCustomLocs().keySet()) + { + if (!key.startsWith(REGION_KEY)) + { + continue; + } + + List locations = _worldData.GetCustomLocs(key); + + if (locations.size() < 2) + { + continue; + } + + for (Block block : UtilBlock.getInBoundingBox(locations.get(0), locations.get(1))) + { + if (!_blockIds.contains(block.getTypeId())) + { + continue; + } + + double dist = UtilMath.offset2d(block.getLocation(), _bridge.GetSpectatorLocation()); + + if (dist > _maxDistance) + { + _maxDistance = dist; + } + + _restore.add(block, Material.AIR.getId(), (byte) 0, Integer.MAX_VALUE); + _bridgeBlocks.put(block.getLocation(), dist); + } + } + } + + public void onBlockSet(Block block) + { + World world = _worldData.World; + Location location = block.getLocation().add(0.5, 0.5, 0.5); + + if (_particle != null) + { + if (_particle == ParticleType.BLOCK_DUST) + { + world.playEffect(location, Effect.STEP_SOUND, block.getType(), block.getData()); + } + else + { + UtilParticle.PlayParticleToAll(_particle, block.getLocation(), 0.5F, 0.5F, 0.5F, 0.5F, 5, ViewDist.NORMAL); + } + } + + if (_sound != null) + { + world.playSound(location, _sound, 1, _pitch); + } + } + + public final String getTypeKey() + { + return _typeKey; + } + + @Override + public String toString() + { + StringBuilder builder = new StringBuilder(); + + builder.append("Type: " + _typeKey).append("\n"); + builder.append("Bridge Blocks: " + _bridgeBlocks.size()).append("\n"); + builder.append("Block Ids: " + _blockIds).append("\n"); + builder.append("Rate: " + _rate).append("\n"); + builder.append("Particle: " + (_particle == null ? "Null" : _particle.getFriendlyName())).append("\n"); + builder.append("Sound: " + (_sound == null ? "Null" : _sound.toString() + " Pitch: " + _pitch)).append("\n"); + builder.append("Max Distance: " + _maxDistance).append("\n"); + + return builder.toString(); + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/custom/RadiusCustomBridgeAnimation.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/custom/RadiusCustomBridgeAnimation.java new file mode 100644 index 000000000..fe0779c7c --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/custom/RadiusCustomBridgeAnimation.java @@ -0,0 +1,58 @@ +package nautilus.game.arcade.game.games.bridge.animation.custom; + +import java.util.Iterator; + +import org.bukkit.Location; +import org.bukkit.block.Block; + +import mineplex.core.updater.UpdateType; +import nautilus.game.arcade.game.games.bridge.Bridge; + +public class RadiusCustomBridgeAnimation extends CustomBridgeAnimation +{ + + private double _minDistance; + + public RadiusCustomBridgeAnimation(Bridge bridge) + { + super(bridge, "RADIUS"); + } + + @Override + public void onParse() + { + super.onParse(); + + _minDistance = _maxDistance; + } + + @Override + public void onUpdate(UpdateType type) + { + if (type != UpdateType.FAST) + { + return; + } + + _minDistance -= _rate; + + Iterator iterator = _bridgeBlocks.keySet().iterator(); + + while (iterator.hasNext()) + { + Location location = iterator.next(); + double dist = _bridgeBlocks.get(location); + + if (dist > _minDistance) + { + Block block = location.getBlock(); + + _restore.restore(block); + onBlockSet(block); + + iterator.remove(); + } + } + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/custom/RandomCustomBridgeAnimation.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/custom/RandomCustomBridgeAnimation.java new file mode 100644 index 000000000..badf135bb --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/custom/RandomCustomBridgeAnimation.java @@ -0,0 +1,44 @@ +package nautilus.game.arcade.game.games.bridge.animation.custom; + +import java.util.Iterator; + +import org.bukkit.Location; +import org.bukkit.block.Block; + +import mineplex.core.updater.UpdateType; +import nautilus.game.arcade.game.games.bridge.Bridge; + +public class RandomCustomBridgeAnimation extends CustomBridgeAnimation +{ + + public RandomCustomBridgeAnimation(Bridge bridge) + { + super(bridge, "RANDOM"); + } + + @Override + public void onUpdate(UpdateType type) + { + if (type != UpdateType.TICK) + { + return; + } + + Iterator iterator = _bridgeBlocks.keySet().iterator(); + int i = 0; + + while (iterator.hasNext() && i < _rate) + { + i++; + Location location = iterator.next(); + + Block block = location.getBlock(); + + _restore.restore(block); + onBlockSet(block); + + iterator.remove(); + } + } + +}