mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2025-01-09 01:07:58 +01:00
Fixed critical issue with block events
This commit is contained in:
parent
92e2769c55
commit
f54f2b30e8
@ -214,6 +214,10 @@ public class SkyBlock extends SongodaPlugin {
|
||||
pluginManager.registerEvents(new Piston(this), this);
|
||||
pluginManager.registerEvents(new FallBreak(this), this);
|
||||
pluginManager.registerEvents(new World(this), this);
|
||||
|
||||
if(ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) {
|
||||
pluginManager.registerEvents(new Sponge(this), this);
|
||||
}
|
||||
|
||||
if (pluginManager.isPluginEnabled("EpicSpawners"))
|
||||
pluginManager.registerEvents(new EpicSpawners(this), this);
|
||||
|
@ -836,47 +836,6 @@ public class Block implements Listener {
|
||||
return false;
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onSponge(SpongeAbsorbEvent event) {
|
||||
IslandLevelManager islandLevelManager = plugin.getLevellingManager();
|
||||
IslandManager islandManager = plugin.getIslandManager();
|
||||
StackableManager stackableManager = plugin.getStackableManager();
|
||||
WorldManager worldManager = plugin.getWorldManager();
|
||||
|
||||
org.bukkit.block.Block block = event.getBlock();
|
||||
|
||||
if (worldManager.isIslandWorld(block.getWorld())) {
|
||||
Location blockLocation = block.getLocation();
|
||||
|
||||
Island island = islandManager.getIslandAtLocation(blockLocation);
|
||||
if (island != null) {
|
||||
if (plugin.getPermissionManager().processPermission(event, island) && !event.isCancelled()) {
|
||||
if (stackableManager == null || !stackableManager.isStacked(blockLocation)) {
|
||||
IslandLevel level = island.getLevel();
|
||||
|
||||
CompatibleMaterial material = CompatibleMaterial.SPONGE;
|
||||
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);
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().runTask(plugin, () -> islandLevelManager.updateLevel(island, blockLocation));
|
||||
}
|
||||
} else {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBlockBurn(BlockBurnEvent event) {
|
||||
org.bukkit.block.Block block = event.getBlock();
|
||||
|
65
src/main/java/com/songoda/skyblock/listeners/Sponge.java
Normal file
65
src/main/java/com/songoda/skyblock/listeners/Sponge.java
Normal file
@ -0,0 +1,65 @@
|
||||
package com.songoda.skyblock.listeners;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.skyblock.SkyBlock;
|
||||
import com.songoda.skyblock.island.Island;
|
||||
import com.songoda.skyblock.island.IslandLevel;
|
||||
import com.songoda.skyblock.island.IslandManager;
|
||||
import com.songoda.skyblock.levelling.IslandLevelManager;
|
||||
import com.songoda.skyblock.stackable.StackableManager;
|
||||
import com.songoda.skyblock.world.WorldManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.SpongeAbsorbEvent;
|
||||
|
||||
public class Sponge implements Listener {
|
||||
|
||||
private final SkyBlock plugin;
|
||||
|
||||
public Sponge(SkyBlock plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onSponge(SpongeAbsorbEvent event) {
|
||||
IslandLevelManager islandLevelManager = plugin.getLevellingManager();
|
||||
IslandManager islandManager = plugin.getIslandManager();
|
||||
StackableManager stackableManager = plugin.getStackableManager();
|
||||
WorldManager worldManager = plugin.getWorldManager();
|
||||
|
||||
org.bukkit.block.Block block = event.getBlock();
|
||||
|
||||
if (worldManager.isIslandWorld(block.getWorld())) {
|
||||
Location blockLocation = block.getLocation();
|
||||
|
||||
Island island = islandManager.getIslandAtLocation(blockLocation);
|
||||
if (island != null) {
|
||||
if (plugin.getPermissionManager().processPermission(event, island) && !event.isCancelled()) {
|
||||
if (stackableManager == null || !stackableManager.isStacked(blockLocation)) {
|
||||
IslandLevel level = island.getLevel();
|
||||
|
||||
CompatibleMaterial material = CompatibleMaterial.SPONGE;
|
||||
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);
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().runTask(plugin, () -> islandLevelManager.updateLevel(island, blockLocation));
|
||||
}
|
||||
} else {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user