mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2024-11-07 03:00:29 +01:00
Cleanup, remove points when a block falls to break.
This commit is contained in:
parent
ebc6ec3d06
commit
2d296c4c77
@ -168,6 +168,7 @@ public class SkyBlock extends SongodaPlugin {
|
||||
pluginManager.registerEvents(new Food(this), this);
|
||||
pluginManager.registerEvents(new Grow(this), this);
|
||||
pluginManager.registerEvents(new Piston(this), this);
|
||||
pluginManager.registerEvents(new FallBreak(this), this);
|
||||
|
||||
if (pluginManager.isPluginEnabled("EpicSpawners")) pluginManager.registerEvents(new EpicSpawners(this), this);
|
||||
if (pluginManager.isPluginEnabled("WildStacker")) pluginManager.registerEvents(new WildStacker(this), this);
|
||||
|
79
src/main/java/com/songoda/skyblock/listeners/FallBreak.java
Normal file
79
src/main/java/com/songoda/skyblock/listeners/FallBreak.java
Normal file
@ -0,0 +1,79 @@
|
||||
package com.songoda.skyblock.listeners;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.skyblock.SkyBlock;
|
||||
import com.songoda.skyblock.config.FileManager;
|
||||
import com.songoda.skyblock.island.Island;
|
||||
import com.songoda.skyblock.island.IslandLevel;
|
||||
import com.songoda.skyblock.island.IslandManager;
|
||||
import com.songoda.skyblock.world.WorldManager;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.FallingBlock;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.ItemSpawnEvent;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
public class FallBreak implements Listener {
|
||||
|
||||
private final SkyBlock skyblock;
|
||||
|
||||
public FallBreak(SkyBlock skyblock) {
|
||||
this.skyblock = skyblock;
|
||||
}
|
||||
|
||||
/*
|
||||
* Removes island points when a block is broken by falling.
|
||||
* Checks for items spawning (because there's no other event called)
|
||||
* Then looks for the falling block (in a radius of 1), which should still be present on the event call.
|
||||
*
|
||||
* Couldn't find any other way to do this.
|
||||
* */
|
||||
@EventHandler
|
||||
public void onItemSpawn(ItemSpawnEvent event) {
|
||||
|
||||
// Basic world and island checks
|
||||
IslandManager islandManager = skyblock.getIslandManager();
|
||||
WorldManager worldManager = skyblock.getWorldManager();
|
||||
|
||||
if (!worldManager.isIslandWorld(event.getEntity().getWorld())) return;
|
||||
|
||||
FileManager.Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml"));
|
||||
FileConfiguration configLoad = config.getFileConfiguration();
|
||||
|
||||
if (!configLoad.getBoolean("Island.Block.Level.Enable")) return;
|
||||
|
||||
Island island = islandManager.getIslandAtLocation(event.getLocation());
|
||||
|
||||
if (island == null) return;
|
||||
|
||||
// Get entities in radius and look for our block
|
||||
List<Entity> entities = event.getEntity().getNearbyEntities(1, 1, 1);
|
||||
|
||||
for (Entity e : entities) {
|
||||
if (!(e instanceof FallingBlock)) continue;
|
||||
|
||||
FallingBlock fallingBlock = (FallingBlock) e;
|
||||
|
||||
// Get the block material
|
||||
CompatibleMaterial material = CompatibleMaterial.getMaterial(fallingBlock.getBlockData().getMaterial());
|
||||
|
||||
if (material == null) continue;
|
||||
|
||||
// Update count in the level
|
||||
IslandLevel level = island.getLevel();
|
||||
|
||||
if (!level.hasMaterial(material.name())) continue;
|
||||
|
||||
long materialAmount = level.getMaterialAmount(material.name());
|
||||
|
||||
if (materialAmount <= 1)
|
||||
level.removeMaterial(material.name());
|
||||
else
|
||||
level.setMaterialAmount(material.name(), materialAmount - 1);
|
||||
}
|
||||
}
|
||||
}
|
@ -6,7 +6,6 @@ import com.songoda.skyblock.config.FileManager;
|
||||
import com.songoda.skyblock.island.Island;
|
||||
import com.songoda.skyblock.island.IslandLevel;
|
||||
import com.songoda.skyblock.island.IslandManager;
|
||||
import com.songoda.skyblock.utils.version.Materials;
|
||||
import com.songoda.skyblock.world.WorldManager;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
@ -24,7 +23,7 @@ public class Piston implements Listener {
|
||||
this.skyblock = skyblock;
|
||||
}
|
||||
|
||||
// Prevent point farming with Dragon Egg
|
||||
// Prevent point farming dragon eggs.
|
||||
@EventHandler
|
||||
public void onPistonMove(BlockPistonExtendEvent event) {
|
||||
|
||||
@ -37,29 +36,26 @@ public class Piston implements Listener {
|
||||
|
||||
Island island = islandManager.getIslandAtLocation(block.getLocation());
|
||||
|
||||
if (island == null ||
|
||||
CompatibleMaterial.DRAGON_EGG != CompatibleMaterial.getMaterial(block)) return;
|
||||
if (island == null || CompatibleMaterial.DRAGON_EGG != CompatibleMaterial.getMaterial(block)) return;
|
||||
|
||||
FileManager.Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml"));
|
||||
FileConfiguration configLoad = config.getFileConfiguration();
|
||||
|
||||
if (!configLoad.getBoolean("Island.Block.Level.Enable")) return;
|
||||
|
||||
final Materials materials;
|
||||
CompatibleMaterial material = CompatibleMaterial.getMaterial(block);
|
||||
|
||||
materials = Materials.getMaterials(block.getType(), block.getData());
|
||||
|
||||
if (materials == null) return;
|
||||
if (material == null) return;
|
||||
|
||||
IslandLevel level = island.getLevel();
|
||||
|
||||
if (!level.hasMaterial(materials.name())) return;
|
||||
if (!level.hasMaterial(material.name())) return;
|
||||
|
||||
long materialAmount = level.getMaterialAmount(materials.name());
|
||||
long materialAmount = level.getMaterialAmount(material.name());
|
||||
|
||||
if (materialAmount <= 1)
|
||||
level.removeMaterial(materials.name());
|
||||
level.removeMaterial(material.name());
|
||||
else
|
||||
level.setMaterialAmount(materials.name(), materialAmount - 1);
|
||||
level.setMaterialAmount(material.name(), materialAmount - 1);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user