mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2024-11-30 06:03:29 +01:00
Simplify level manager
This commit is contained in:
parent
08e5046f52
commit
bf684fe4aa
@ -9,14 +9,18 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.compatibility.ServerVersion;
|
||||
import com.songoda.skyblock.island.IslandLevel;
|
||||
import com.songoda.skyblock.levelling.calculator.Calculator;
|
||||
import com.songoda.skyblock.levelling.calculator.CalculatorRegistry;
|
||||
import com.songoda.skyblock.levelling.calculator.impl.EpicSpawnerCalculator;
|
||||
import com.songoda.skyblock.levelling.calculator.impl.UltimateStackerCalculator;
|
||||
import com.songoda.skyblock.utils.version.CompatibleSpawners;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
import org.bukkit.configuration.Configuration;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -210,5 +214,49 @@ public final class IslandLevelManager {
|
||||
|
||||
return new AmountMaterialPair(compMaterial, amount + stackSize);
|
||||
}
|
||||
|
||||
|
||||
public void updateLevel(Island island, Location location) {
|
||||
// Fix a bug in Paper 1.8.8 when using ViaVersion on a 1.12.2 client.
|
||||
// BUG: Player can infinitely increase their level by placing a block at their
|
||||
// feet.
|
||||
// It doesn't take the block away but still increments the level.
|
||||
// This doesn't happen in Spigot, but does happen in PaperSpigot due to a
|
||||
// BlockPlaceEvent being incorrectly fired.
|
||||
// The solution is to wait a tick to make sure that the block was actually
|
||||
// placed.
|
||||
// This shouldn't cause any issues besides the task number being increased
|
||||
// insanely fast.
|
||||
if(ServerVersion.isServerVersion(ServerVersion.V1_8)){
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
updateLevelLocation(island, location);
|
||||
});
|
||||
} else {
|
||||
updateLevelLocation(island, location);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateLevelLocation(Island island, Location location) {
|
||||
Block block = location.getBlock();
|
||||
CompatibleMaterial material = CompatibleMaterial.getMaterial(block);
|
||||
|
||||
if (material == null || material == CompatibleMaterial.AIR) return;
|
||||
|
||||
if (material == CompatibleMaterial.SPAWNER) {
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("EpicSpawners") || Bukkit.getPluginManager().isPluginEnabled("WildStacker"))
|
||||
return;
|
||||
|
||||
CompatibleSpawners spawner = CompatibleSpawners.getSpawner(((CreatureSpawner) block.getState()).getSpawnedType());
|
||||
|
||||
if (spawner != null)
|
||||
material = CompatibleMaterial.getBlockMaterial(spawner.getMaterial());
|
||||
}
|
||||
|
||||
long materialAmount = 0;
|
||||
IslandLevel level = island.getLevel();
|
||||
|
||||
if (level.hasMaterial(material.name()))
|
||||
materialAmount = level.getMaterialAmount(material.name());
|
||||
|
||||
level.setMaterialAmount(material.name(), materialAmount + 1);
|
||||
}
|
||||
}
|
||||
|
@ -185,7 +185,7 @@ public class Block implements Listener {
|
||||
|
||||
IslandManager islandManager = skyblock.getIslandManager();
|
||||
WorldManager worldManager = skyblock.getWorldManager();
|
||||
IslandLevelManager levellingManager = skyblock.getLevellingManager();
|
||||
IslandLevelManager islandLevelManager = skyblock.getLevellingManager();
|
||||
if (!worldManager.isIslandWorld(block.getWorld())) return;
|
||||
|
||||
Location blockLoc = block.getLocation();
|
||||
@ -201,7 +201,7 @@ public class Block implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (levellingManager.isScanning(island)) {
|
||||
if (islandLevelManager.isScanning(island)) {
|
||||
skyblock.getMessageManager().sendMessage(player,
|
||||
skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration().getString("Command.Island.Level.Scanning.BlockPlacing.Message"));
|
||||
event.setCancelled(true);
|
||||
@ -286,8 +286,8 @@ public class Block implements Listener {
|
||||
|
||||
if (event.getBlock().getType() == CompatibleMaterial.END_PORTAL_FRAME.getMaterial()
|
||||
&& event.getPlayer().getItemInHand().getType() == CompatibleMaterial.ENDER_EYE.getMaterial()) return;
|
||||
|
||||
updateLevel(island, blockLoc);
|
||||
|
||||
islandLevelManager.updateLevel(island, blockLoc);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -297,6 +297,7 @@ public class Block implements Listener {
|
||||
GeneratorManager generatorManager = skyblock.getGeneratorManager();
|
||||
IslandManager islandManager = skyblock.getIslandManager();
|
||||
WorldManager worldManager = skyblock.getWorldManager();
|
||||
IslandLevelManager islandLevelManager = skyblock.getLevellingManager();
|
||||
|
||||
Island island = islandManager.getIslandAtLocation(event.getBlock().getLocation());
|
||||
IslandWorld world = worldManager.getIslandWorld(event.getBlock().getWorld());
|
||||
@ -382,7 +383,7 @@ public class Block implements Listener {
|
||||
toBlockState.setData(genState.getData());
|
||||
toBlockState.setType(genState.getType());
|
||||
toBlockState.update();
|
||||
updateLevel(island, genState.getLocation());
|
||||
islandLevelManager.updateLevel(island, genState.getLocation());
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -541,6 +542,8 @@ public class Block implements Listener {
|
||||
public void onBlockForm(BlockFormEvent event) {
|
||||
org.bukkit.block.Block block = event.getBlock();
|
||||
WorldManager worldManager = skyblock.getWorldManager();
|
||||
IslandLevelManager islandLevelManager = skyblock.getLevellingManager();
|
||||
|
||||
if (!worldManager.isIslandWorld(block.getWorld())) return;
|
||||
|
||||
// Check ice/snow forming
|
||||
@ -612,7 +615,7 @@ public class Block implements Listener {
|
||||
state.setType(genState.getType());
|
||||
|
||||
if (NMSUtil.getVersionNumber() < 13) state.setData(genState.getData());
|
||||
updateLevel(island, genState.getLocation());
|
||||
islandLevelManager.updateLevel(island, genState.getLocation());
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -715,42 +718,4 @@ public class Block implements Listener {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
private void updateLevel(Island island, Location location) {
|
||||
// Fix a bug in Paper 1.8.8 when using ViaVersion on a 1.12.2 client.
|
||||
// BUG: Player can infinitely increase their level by placing a block at their
|
||||
// feet.
|
||||
// It doesn't take the block away but still increments the level.
|
||||
// This doesn't happen in Spigot, but does happen in PaperSpigot due to a
|
||||
// BlockPlaceEvent being incorrectly fired.
|
||||
// The solution is to wait a tick to make sure that the block was actually
|
||||
// placed.
|
||||
// This shouldn't cause any issues besides the task number being increased
|
||||
// insanely fast.
|
||||
// TODO Do this only in 1.8.8
|
||||
Bukkit.getScheduler().runTask(skyblock, () -> {
|
||||
org.bukkit.block.Block block = location.getBlock();
|
||||
CompatibleMaterial material = CompatibleMaterial.getMaterial(block);
|
||||
|
||||
if (material == null || material == CompatibleMaterial.AIR) return;
|
||||
|
||||
if (material == CompatibleMaterial.SPAWNER) {
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("EpicSpawners") || Bukkit.getPluginManager().isPluginEnabled("WildStacker"))
|
||||
return;
|
||||
|
||||
CompatibleSpawners spawner = CompatibleSpawners.getSpawner(((CreatureSpawner) block.getState()).getSpawnedType());
|
||||
|
||||
if (spawner != null)
|
||||
material = CompatibleMaterial.getBlockMaterial(spawner.getMaterial());
|
||||
}
|
||||
|
||||
long materialAmount = 0;
|
||||
IslandLevel level = island.getLevel();
|
||||
|
||||
if (level.hasMaterial(material.name()))
|
||||
materialAmount = level.getMaterialAmount(material.name());
|
||||
|
||||
level.setMaterialAmount(material.name(), materialAmount + 1);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user