mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2025-02-15 19:21:26 +01:00
Protect Stackables from explosions
This commit is contained in:
parent
8be6bdfe7e
commit
9ae191c4c4
@ -6,6 +6,7 @@ import com.songoda.skyblock.config.FileManager;
|
|||||||
import com.songoda.skyblock.config.FileManager.Config;
|
import com.songoda.skyblock.config.FileManager.Config;
|
||||||
import com.songoda.skyblock.island.*;
|
import com.songoda.skyblock.island.*;
|
||||||
import com.songoda.skyblock.limit.impl.EntityLimitaton;
|
import com.songoda.skyblock.limit.impl.EntityLimitaton;
|
||||||
|
import com.songoda.skyblock.stackable.Stackable;
|
||||||
import com.songoda.skyblock.stackable.StackableManager;
|
import com.songoda.skyblock.stackable.StackableManager;
|
||||||
import com.songoda.skyblock.upgrade.Upgrade;
|
import com.songoda.skyblock.upgrade.Upgrade;
|
||||||
import com.songoda.skyblock.utils.version.NMSUtil;
|
import com.songoda.skyblock.utils.version.NMSUtil;
|
||||||
@ -14,6 +15,7 @@ import com.songoda.skyblock.world.WorldManager;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.entity.*;
|
import org.bukkit.entity.*;
|
||||||
import org.bukkit.entity.Projectile;
|
import org.bukkit.entity.Projectile;
|
||||||
@ -343,21 +345,8 @@ public class Entity implements Listener {
|
|||||||
.getBoolean("Island.Block.Level.Enable"))
|
.getBoolean("Island.Block.Level.Enable"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CompatibleMaterial materials = CompatibleMaterial.getBlockMaterial(block.getType());
|
removeBlockFromLevel(island, block);
|
||||||
|
CompatibleMaterial materials;
|
||||||
if (materials != null) {
|
|
||||||
IslandLevel level = island.getLevel();
|
|
||||||
|
|
||||||
if (level.hasMaterial(materials.name())) {
|
|
||||||
long materialAmount = level.getMaterialAmount(materials.name());
|
|
||||||
|
|
||||||
if (materialAmount - 1 <= 0) {
|
|
||||||
level.removeMaterial(materials.name());
|
|
||||||
} else {
|
|
||||||
level.setMaterialAmount(materials.name(), materialAmount - 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.getTo() != null && event.getTo() != Material.AIR) {
|
if (event.getTo() != null && event.getTo() != Material.AIR) {
|
||||||
materials = CompatibleMaterial.getBlockMaterial(event.getTo());
|
materials = CompatibleMaterial.getBlockMaterial(event.getTo());
|
||||||
@ -377,7 +366,7 @@ public class Entity implements Listener {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
public void onEntityExplode(EntityExplodeEvent event) {
|
public void onEntityExplode(EntityExplodeEvent event) {
|
||||||
org.bukkit.entity.Entity entity = event.getEntity();
|
org.bukkit.entity.Entity entity = event.getEntity();
|
||||||
|
|
||||||
@ -387,47 +376,91 @@ public class Entity implements Listener {
|
|||||||
if (skyblock.getWorldManager().isIslandWorld(entity.getWorld())) {
|
if (skyblock.getWorldManager().isIslandWorld(entity.getWorld())) {
|
||||||
// Check permissions.
|
// Check permissions.
|
||||||
Island island = islandManager.getIslandAtLocation(entity.getLocation());
|
Island island = islandManager.getIslandAtLocation(entity.getLocation());
|
||||||
|
|
||||||
skyblock.getPermissionManager().processPermission(event, null, island);
|
skyblock.getPermissionManager().processPermission(event, null, island);
|
||||||
|
|
||||||
if (!event.isCancelled()) {
|
if (!event.isCancelled()) {
|
||||||
if (skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration()
|
|
||||||
.getBoolean("Island.Block.Level.Enable")) {
|
|
||||||
for (org.bukkit.block.Block blockList : event.blockList()) {
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
CompatibleMaterial materials = CompatibleMaterial.getBlockMaterial(blockList.getType());
|
|
||||||
|
|
||||||
if (materials != null) {
|
StackableManager stackableManager = skyblock.getStackableManager();
|
||||||
IslandLevel level = island.getLevel();
|
|
||||||
|
|
||||||
if (level.hasMaterial(materials.name())) {
|
boolean removed;
|
||||||
long materialAmount = level.getMaterialAmount(materials.name());
|
Iterator<org.bukkit.block.Block> it = event.blockList().iterator();
|
||||||
|
while (it.hasNext()){
|
||||||
|
removed = false;
|
||||||
|
org.bukkit.block.Block block = it.next();
|
||||||
|
if (SkyBlock.getInstance().getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration()
|
||||||
|
.getBoolean("Island.Spawn.Protection")) {
|
||||||
|
IslandWorld world = worldManager.getIslandWorld(event.getEntity().getWorld());
|
||||||
|
if (LocationUtil.isLocationLocation(block.getLocation(),
|
||||||
|
island.getLocation(world, IslandEnvironment.Main).clone().subtract(0.0D, 1.0D, 0.0D))) {
|
||||||
|
it.remove();
|
||||||
|
removed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (materialAmount - 1 <= 0) {
|
Location blockLocation = block.getLocation();
|
||||||
level.removeMaterial(materials.name());
|
|
||||||
} else {
|
if (stackableManager != null && stackableManager.isStacked(blockLocation)) {
|
||||||
level.setMaterialAmount(materials.name(), materialAmount - 1);
|
Stackable stackable = stackableManager.getStack(block.getLocation(), CompatibleMaterial.getMaterial(block));
|
||||||
}
|
if (stackable != null) {
|
||||||
|
CompatibleMaterial material = CompatibleMaterial.getMaterial(block);
|
||||||
|
byte data = block.getData();
|
||||||
|
|
||||||
|
int removedAmount = (int) (Math.random() * Math.min(64, stackable.getSize()-1));
|
||||||
|
stackable.take(removedAmount);
|
||||||
|
Bukkit.getScheduler().runTask(skyblock, () -> {
|
||||||
|
block.getWorld().dropItemNaturally(blockLocation.clone().add(.5, 1, .5),
|
||||||
|
new ItemStack(material.getMaterial(), (int) (Math.random() * removedAmount), data));
|
||||||
|
});
|
||||||
|
|
||||||
|
if (stackable.getSize() <= 1) {
|
||||||
|
stackableManager.removeStack(stackable);
|
||||||
|
}
|
||||||
|
|
||||||
|
Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml"));
|
||||||
|
FileConfiguration configLoad = config.getFileConfiguration();
|
||||||
|
|
||||||
|
if (configLoad.getBoolean("Island.Block.Level.Enable")) {
|
||||||
|
removeBlockFromLevel(island, block);
|
||||||
|
}
|
||||||
|
|
||||||
|
it.remove();
|
||||||
|
if(!removed){
|
||||||
|
removed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if (skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration()
|
||||||
|
.getBoolean("Island.Block.Level.Enable")) {
|
||||||
if (SkyBlock.getInstance().getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration()
|
if(!removed){
|
||||||
.getBoolean("Island.Spawn.Protection")) {
|
removeBlockFromLevel(island, block);
|
||||||
IslandWorld world = worldManager.getIslandWorld(event.getEntity().getWorld());
|
|
||||||
for (org.bukkit.block.Block block : event.blockList()) {
|
|
||||||
if (LocationUtil.isLocationLocation(block.getLocation(),
|
|
||||||
island.getLocation(world, IslandEnvironment.Main).clone().subtract(0.0D, 1.0D, 0.0D))) {
|
|
||||||
event.blockList().remove(block);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void removeBlockFromLevel(Island island, CompatibleMaterial material){
|
||||||
|
if (material != null) {
|
||||||
|
IslandLevel level = island.getLevel();
|
||||||
|
|
||||||
|
if (level.hasMaterial(material.name())) {
|
||||||
|
long materialAmount = level.getMaterialAmount(material.name());
|
||||||
|
|
||||||
|
if (materialAmount - 1 <= 0) {
|
||||||
|
level.removeMaterial(material.name());
|
||||||
|
} else {
|
||||||
|
level.setMaterialAmount(material.name(), materialAmount - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeBlockFromLevel(Island island, Block block) {
|
||||||
|
removeBlockFromLevel(island, CompatibleMaterial.getBlockMaterial(block.getType()));
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onEntityDeath(EntityDeathEvent event) {
|
public void onEntityDeath(EntityDeathEvent event) {
|
||||||
LivingEntity livingEntity = event.getEntity();
|
LivingEntity livingEntity = event.getEntity();
|
||||||
|
Loading…
Reference in New Issue
Block a user