Paper 1.8.8 -> 1.12.2 by ViaVersion BlockPlaceEvent bug fix

This commit is contained in:
Esophose 2019-08-17 11:23:58 -06:00
parent 70374c7a7c
commit 4954880867

View File

@ -181,7 +181,7 @@ public class Block implements Listener {
} }
} }
@EventHandler(priority = EventPriority.LOW) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent event) { public void onBlockPlace(BlockPlaceEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
org.bukkit.block.Block block = event.getBlock(); org.bukkit.block.Block block = event.getBlock();
@ -269,28 +269,36 @@ public class Block implements Listener {
if (!configLoad.getBoolean("Island.Block.Level.Enable")) if (!configLoad.getBoolean("Island.Block.Level.Enable"))
return; return;
@SuppressWarnings("deprecation") // Fix a bug in Paper 1.8.8 when using ViaVersion on a 1.12.2 client.
Materials materials = Materials.getMaterials(block.getType(), block.getData()); // BUG: Player can infinitely increase their level by placing a block at their feet.
if (materials == null) // It doesn't take the block away but still increments the level.
return; // 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.
if (materials.equals(Materials.SPAWNER)) { // This shouldn't cause any issues besides the task number being increased insanely fast.
if (Bukkit.getPluginManager().isPluginEnabled("EpicSpawners") || Bukkit.getPluginManager().isPluginEnabled("WildStacker")) Bukkit.getScheduler().runTask(skyblock, () -> {
@SuppressWarnings("deprecation")
Materials materials = Materials.getMaterials(block.getType(), block.getData());
if (materials == null || materials == Materials.AIR)
return; return;
CreatureSpawner creatureSpawner = (CreatureSpawner) block.getState(); if (materials.equals(Materials.SPAWNER)) {
EntityType spawnerType = creatureSpawner.getSpawnedType(); if (Bukkit.getPluginManager().isPluginEnabled("EpicSpawners") || Bukkit.getPluginManager().isPluginEnabled("WildStacker"))
materials = Materials.getSpawner(spawnerType); return;
}
long materialAmount = 0; CreatureSpawner creatureSpawner = (CreatureSpawner) block.getState();
IslandLevel level = island.getLevel(); EntityType spawnerType = creatureSpawner.getSpawnedType();
materials = Materials.getSpawner(spawnerType);
}
if (level.hasMaterial(materials.name())) { long materialAmount = 0;
materialAmount = level.getMaterialAmount(materials.name()); IslandLevel level = island.getLevel();
}
level.setMaterialAmount(materials.name(), materialAmount + 1); if (level.hasMaterial(materials.name())) {
materialAmount = level.getMaterialAmount(materials.name());
}
level.setMaterialAmount(materials.name(), materialAmount + 1);
});
} }