diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilWorld.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilWorld.java index f156f7f5a..19281c9ce 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilWorld.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilWorld.java @@ -1,8 +1,8 @@ package mineplex.core.common.util; import java.util.Collection; +import java.util.Iterator; import java.util.List; -import java.util.function.Predicate; import org.bukkit.Chunk; import org.bukkit.Location; @@ -10,10 +10,18 @@ import org.bukkit.World; import org.bukkit.World.Environment; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; import org.bukkit.util.Vector; import com.google.common.collect.Lists; +import net.minecraft.server.v1_8_R3.EntityHuman; +import net.minecraft.server.v1_8_R3.EntityPlayer; +import net.minecraft.server.v1_8_R3.Explosion; +import net.minecraft.server.v1_8_R3.PacketPlayOutExplosion; +import net.minecraft.server.v1_8_R3.Vec3D; + public class UtilWorld { public static World getWorld(String world) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java index e48801344..902aa968a 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java @@ -112,6 +112,7 @@ public class SiegeManager extends MiniPlugin if (!part) { + System.out.println("Removing slime..."); slime.remove(); } else @@ -162,11 +163,13 @@ public class SiegeManager extends MiniPlugin { if (((ArmorStand) entity).getHelmet() != null && ((ArmorStand) entity).getHelmet().getType().equals(Material.SPONGE)) { + System.out.println("Removing armor stand"); entity.remove(); } if (entity.getPassenger() != null && entity.getPassenger() instanceof Slime && entity.getPassenger().getPassenger() instanceof Slime) { + System.out.println("Removing armostand + children"); entity.getPassenger().getPassenger().remove(); entity.getPassenger().remove(); entity.remove(); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/SiegeWeaponRepository.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/SiegeWeaponRepository.java index b43d47d23..af1820380 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/SiegeWeaponRepository.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/SiegeWeaponRepository.java @@ -126,7 +126,6 @@ public class SiegeWeaponRepository extends MinecraftRepository token.Health = columns.getShort("health"); token.Yaw = columns.getShort("yaw"); token.LastFired = columns.getTimestamp("lastFired").getTime(); - token.Entities = decodeEntities(columns.getString("entities")); System.out.println("Siege Repo> Loaded weapon " + token.UniqueId); } @@ -158,41 +157,10 @@ public class SiegeWeaponRepository extends MinecraftRepository new ColumnInt("health", token.Health), new ColumnInt("yaw", token.Yaw), new ColumnTimestamp("lastFired", new Timestamp(token.LastFired)), - new ColumnVarChar("entities", 100, encodeEntities(token.Entities))) + new ColumnVarChar("entities", 100, "")) ); } - private String encodeEntities(Map entities) - { - StringBuilder builder = new StringBuilder(); - - int l = 0; - for (String name : entities.keySet()) - { - if (l != 0) - { - builder.append(","); - } - - builder.append(name + ":" + entities.get(name)); - l++; - } - - return builder.toString(); - } - - private Map decodeEntities(String data) - { - Map map = new HashMap<>(); - - for (String entries : data.split(",")) - { - map.put(entries.split(":")[0], entries.split(":")[1]); - } - - return map; - } - @Override protected void initialize() { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/tokens/SiegeWeaponToken.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/tokens/SiegeWeaponToken.java index 876e73935..638aa800c 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/tokens/SiegeWeaponToken.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/tokens/SiegeWeaponToken.java @@ -16,6 +16,5 @@ public class SiegeWeaponToken public int Health; public int Yaw; public long LastFired; - public Map Entities; } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java index 45510438c..cd0e77876 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java @@ -55,6 +55,13 @@ public class Cannon extends SiegeWeapon { super(300, "Cannon", token, siegeManager.getClansManager(), siegeManager); + if (_ownerClan == null) + { + System.out.println("[cannon] owner clan null, killing"); + kill(); + return; + } + System.out.println("Siege> Loading Cannon from token " + token.UniqueId); setBoundingBox(1); @@ -107,11 +114,11 @@ public class Cannon extends SiegeWeapon enableInventory(UtilServer.getServer().createInventory(null, InventoryType.DISPENSER, C.cDAquaB + _name), new AccessRule(AccessType.RCLICK_BB, player -> player.equals(getRider()))); setRideable(new AccessRule(AccessType.RCLICK_BB, player -> { -// if (!_ownerClan.isMember(player)) -// { -// UtilPlayer.message(player, F.main("Clans", "This Cannon is not owned by your Clan.")); -// return false; -// } + if (!_ownerClan.isMember(player)) + { + UtilPlayer.message(player, F.main("Clans", "This Cannon is not owned by your Clan.")); + return false; + } if (getRider() != null && !getRider().equals(player)) { @@ -140,7 +147,7 @@ public class Cannon extends SiegeWeapon setStateInfo("Unloaded", new WeaponStateInfo(Material.SPONGE, (byte) 1)); setStateInfo("Loaded", new WeaponStateInfo(Material.SPONGE, (byte) 0)); - loadEntities(); + loadEntities(true); setFirepowerType(Material.SULPHUR); setAmmunitionType(Material.TNT); @@ -179,9 +186,9 @@ public class Cannon extends SiegeWeapon return false; } - if (System.currentTimeMillis() - _lastFired < 20000) + if (System.currentTimeMillis() - _lastFired < 30000) { - UtilPlayer.message(player, F.main("Clans", "Cannon is cooling down (" + F.time(UtilTime.MakeStr(20000 - (System.currentTimeMillis() - _lastFired))) + ")")); + UtilPlayer.message(player, F.main("Clans", "Cannon is cooling down (" + F.time(UtilTime.MakeStr(30000 - (System.currentTimeMillis() - _lastFired))) + ")")); return false; } @@ -191,11 +198,11 @@ public class Cannon extends SiegeWeapon enableInventory(UtilServer.getServer().createInventory(null, InventoryType.DISPENSER, C.cDAquaB + _name), new AccessRule(AccessType.RCLICK_BB, player -> player.equals(getRider()))); setRideable(new AccessRule(AccessType.RCLICK_BB, player -> { -// if (!_ownerClan.isMember(player)) -// { -// UtilPlayer.message(player, F.main("Clans", "This Cannon is not owned by your Clan.")); -// return false; -// } + if (!_ownerClan.isMember(player)) + { + UtilPlayer.message(player, F.main("Clans", "This Cannon is not owned by your Clan.")); + return false; + } if (getRider() != null && !getRider().equals(player)) { @@ -298,7 +305,7 @@ public class Cannon extends SiegeWeapon return true; // all slots are now filled; slot == 0 || slot == 1 || slot == 2; } - private void loadEntities() + private void loadEntities(boolean insert) { Slime filler = _location.getWorld().spawn(_location.clone(), Slime.class); @@ -332,8 +339,10 @@ public class Cannon extends SiegeWeapon addEntity(weapon, "WEAPON"); - - insert(); + if (insert) + { + insert(); + } } @Override @@ -341,20 +350,13 @@ public class Cannon extends SiegeWeapon { Lists.newArrayList(_location.getWorld().getEntities()) .forEach(entity -> { - for (Entry entry : _loadedToken.Entities.entrySet()) + if (Integer.toString(_uniqueId).equals(entity.getCustomName())) { - if (entity.getUniqueId().toString().equals(entry.getValue())) - { - addEntity(entity, entry.getKey()); - } + entity.remove(); } }); - if (getEntity("WEAPON") == null || getEntity("Filler_1") == null || getEntity("PLAYERMOUNT") == null) - { - System.out.println("[Cannon] Could not find all entities, killing."); - kill(); - } + loadEntities(false); } @Override @@ -428,12 +430,12 @@ public class Cannon extends SiegeWeapon @EventHandler public void explosionEffects(SiegeWeaponExplodeEvent event) { - for (int i = 0; i < 8; i++) - { - // Explosion particle effects. - Location point = UtilAlg.getRandomLocation(event.getProjectile().getLocation(), 5); - UtilParticle.PlayParticle(ParticleType.HUGE_EXPLOSION, point, 0, 0, 0, 1, 2, ViewDist.MAX); - } +// for (int i = 0; i < 8; i++) +// { +// // Explosion particle effects. +// Location point = UtilAlg.getRandomLocation(event.getProjectile().getLocation(), 5); +// UtilParticle.PlayParticle(ParticleType.HUGE_EXPLOSION, point, 0, 0, 0, 1, 2, ViewDist.MAX); +// } // Block explosion. ArrayList blocks = new ArrayList<>(); @@ -449,7 +451,7 @@ public class Cannon extends SiegeWeapon attempts++; } - _siegeManager.getClansManager().getExplosion().BlockExplosion( + _clans.getExplosion().BlockExplosion( blocks, event.getProjectile().getLocation(), false diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java index ba9089851..474b3f7d2 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java @@ -536,6 +536,9 @@ public abstract class SiegeWeapon implements Listener protected final void addEntity(Entity entity, String uniqueName) { + entity.setCustomName(Integer.toString(_uniqueId)); + entity.setCustomNameVisible(false); + _comprisedOf.add(entity); _entityMapping.put(uniqueName, entity); @@ -942,29 +945,19 @@ public abstract class SiegeWeapon implements Listener token.Location = _location; token.Health = _health; token.Yaw = (int) _yaw; - token.Entities = new HashMap<>(); - - _entityMapping.entrySet().forEach(entry -> - token.Entities.put(entry.getKey(), entry.getValue().getUniqueId().toString()) - ); return token; } public boolean isPartOf(UUID uniqueId) { - if (_loadedToken == null) + for (Entity entity : _comprisedOf) { - for (Entity entity : _comprisedOf) - { - if (entity.getUniqueId().equals(uniqueId)) - return true; - } - - return false; + if (entity.getUniqueId().equals(uniqueId)) + return true; } - return _loadedToken.Entities.values().contains(uniqueId.toString()); + return false; } public void setInvincible(boolean invincible) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/Crater.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/Crater.java index 6443697b8..c16f4f5c5 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/Crater.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/Crater.java @@ -26,9 +26,9 @@ import mineplex.core.common.util.UtilServer; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.clans.ClansManager; -import mineplex.game.clans.clans.nameblacklist.ClansBlacklist; import mineplex.game.clans.clans.siege.weapon.SiegeWeapon; import mineplex.game.clans.core.repository.ClanTerritory; +import net.minecraft.server.v1_8_R3.Explosion; public class Crater implements Listener { @@ -108,124 +108,52 @@ public class Crater implements Listener return; } - _blocks.add(new CraterBlock(_origin, 0, Material.AIR)); + boolean explosion = _origin.getWorld().createExplosion(_origin, 2.6f); - HashMap blockList = new HashMap(); - int iR = (int) _size + 1; + boolean floating = _origin.distance(UtilBlock.nearestFloor(_origin)) > 0.6; - for (int x = -iR; x <= iR; x++) + if (explosion) { - for (int z = -iR; z <= iR; z++) + for (Block block : UtilBlock.getInRadius(_origin.getBlock(), 2.6f).keySet()) { - for (int y = -iR; y <= iR; y++) + boolean charred = false; + double dist = block.getLocation().distance(_origin); + + if (floating) { - Block curBlock = _origin.getBlock().getRelative(x, y, z); - - double offset = UtilMath.offset(_origin, curBlock.getLocation()); - - if (offset <= _size) + if (!block.getRelative(BlockFace.DOWN).getType().equals(CHARRED_TYPE) + && !block.getRelative(BlockFace.DOWN).getType().equals(Material.AIR) + && Math.random() > 0.79) { - blockList.put(curBlock, Double.valueOf(offset)); + charred = true; } } + else + { + if (block.getRelative(BlockFace.UP).getType().equals(Material.AIR) + && !block.getRelative(BlockFace.DOWN).getType().equals(CHARRED_TYPE) + && !block.getRelative(BlockFace.DOWN).getType().equals(Material.AIR) + && Math.random() > 0.79) + { + charred = true; + } + } + + if (block.getType().equals(Material.SMOOTH_BRICK)) + { + charred = false; + } + + if (charred) + { + CraterBlock charredBlock = new CraterBlock(block.getLocation(), dist, CHARRED_TYPE, (byte) 0); + + charredBlock.set(); + + _blocks.add(charredBlock); + } } } - - for (Entry entry : blockList.entrySet()) - { - Block block = entry.getKey(); - - ClanTerritory territory = _weapon.getClans().getClanUtility().getClaim(block.getLocation()); - - if (territory != null && !ClansManager.getInstance().getBlacklist().allowed(territory.Owner)) - { - continue; - } - - double distance = entry.getValue().doubleValue(); - - boolean air = distance <= _airChance || (Math.random() > (distance) / 3.65d); - - if (block.getState() instanceof Chest) continue; - - if (block.getType() == Material.AIR) continue; - - if (air) - { - _blocks.add(new CraterBlock(block.getLocation(), distance, Material.AIR)); - - Block above = block; - - while (!UtilItem.isBoundless((above = above.getRelative(BlockFace.UP)).getType())) - { - _blocks.add(new CraterBlock(above.getLocation(), distance, Material.AIR)); - } - - if (!UtilItem.isBoundless(block.getRelative(BlockFace.DOWN).getType())) - { - if (_fire && Math.random() >= .5) - { - _blocks.add(new CraterBlock(block.getLocation(), distance, Material.FIRE)); - } - } - } - } - - _blocks.forEach(CraterBlock::set); - - for (Entry entry : blockList.entrySet()) - { - Block block = entry.getKey(); - - ClanTerritory territory = _weapon.getClans().getClanUtility().getClaim(block.getLocation()); - - if (territory != null && !ClansManager.getInstance().getBlacklist().allowed(territory.Owner)) - { - continue; - } - - double distance = entry.getValue().doubleValue(); - - if (block.getType() == Material.AIR) continue; - - if (block.getState() instanceof Chest) - { - Chest chest = (Chest) block.getState(); - - for (ItemStack item : chest.getBlockInventory().getContents()) - { - if (item == null) - { - continue; - } - - if (item.getType() == Material.AIR) - { - continue; - } - - _origin.getWorld().dropItemNaturally(_origin, item); - } - } - - if ( - distance > _airChance && - Math.random() > .75 && - UtilItem.isBoundless(block.getRelative(BlockFace.UP).getType()) && - !UtilItem.isBoundless(block.getRelative(BlockFace.DOWN).getType()) && - !block.getRelative(BlockFace.UP).getType().equals(CHARRED_TYPE) && - !block.getRelative(BlockFace.DOWN).getType().equals(CHARRED_TYPE)) - { - _blocks.add(new CraterBlock(block.getLocation(), distance, CHARRED_TYPE)); - - if (_fire) - { - _blocks.add(new CraterBlock(block.getRelative(BlockFace.UP).getLocation(), distance, Material.FIRE)); - } - } - } - - _blocks.forEach(CraterBlock::set); } }