Fixed a NoSuchMethodError on versions pre 1.13

This commit is contained in:
theone1000 2019-11-17 16:34:30 -07:00 committed by Brianna
parent 24c60dd35d
commit ed9126d278
2 changed files with 140 additions and 159 deletions

View File

@ -36,14 +36,15 @@ public class Grow implements Listener {
}
/**
* Checks that a structure like a tree is not growing outside or into another island.
* Checks that a structure like a tree is not growing outside or into another
* island.
*
* @author LimeGlass
*/
@EventHandler(ignoreCancelled = true)
public void onStructureGrow(StructureGrowEvent event) {
WorldManager worldManager = skyblock.getWorldManager();
if (!worldManager.isIslandWorld(event.getWorld()))
return;
if (!worldManager.isIslandWorld(event.getWorld())) return;
IslandManager islandManager = skyblock.getIslandManager();
Island origin = islandManager.getIslandAtLocation(event.getLocation());
@ -51,8 +52,7 @@ public class Grow implements Listener {
BlockState state = it.next();
Island growingTo = islandManager.getIslandAtLocation(state.getLocation());
// This block is ok to continue as it's not related to Skyblock islands.
if (origin == null && growingTo == null)
continue;
if (origin == null && growingTo == null) continue;
// A block from the structure is outside/inside that it's not suppose to.
if (origin == null || growingTo == null) {
it.remove();
@ -70,13 +70,11 @@ public class Grow implements Listener {
public void onCropUpgrade(BlockGrowEvent event) {
org.bukkit.block.Block block = event.getBlock();
WorldManager worldManager = skyblock.getWorldManager();
if (!skyblock.getWorldManager().isIslandWorld(block.getWorld()))
return;
if (!skyblock.getWorldManager().isIslandWorld(block.getWorld())) return;
IslandManager islandManager = skyblock.getIslandManager();
Island island = islandManager.getIslandAtLocation(block.getLocation());
if (island == null)
return;
if (island == null) return;
// Check spawn block protection
IslandWorld world = worldManager.getIslandWorld(block.getWorld());
@ -88,8 +86,7 @@ public class Grow implements Listener {
}
List<Upgrade> upgrades = skyblock.getUpgradeManager().getUpgrades(Upgrade.Type.Crop);
if (upgrades == null || upgrades.size() == 0 || !upgrades.get(0).isEnabled() || !island.isUpgrade(Upgrade.Type.Crop))
return;
if (upgrades == null || upgrades.size() == 0 || !upgrades.get(0).isEnabled() || !island.isUpgrade(Upgrade.Type.Crop)) return;
if (NMSUtil.getVersionNumber() > 12) {
try {
@ -97,26 +94,18 @@ public class Grow implements Listener {
if (blockData instanceof org.bukkit.block.data.Ageable) {
org.bukkit.block.data.Ageable ageable = (org.bukkit.block.data.Ageable) blockData;
ageable.setAge(ageable.getAge() + 1);
block.getClass()
.getMethod("setBlockData", Class.forName("org.bukkit.block.data.BlockData"))
.invoke(block, ageable);
block.getClass().getMethod("setBlockData", Class.forName("org.bukkit.block.data.BlockData")).invoke(block, ageable);
}
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
| NoSuchMethodException | SecurityException | ClassNotFoundException e) {
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException | ClassNotFoundException e) {
e.printStackTrace();
}
} else {
Material type = block.getType();
if (block.getState().getData() instanceof Crops
|| type.name().equals("BEETROOT_BLOCK")
|| type.name().equals("CARROT")
|| type.name().equals("POTATO")
|| type.name().equals("WHEAT")
|| type.name().equals("CROPS")) {
if (block.getState().getData() instanceof Crops || type.name().equals("BEETROOT_BLOCK") || type.name().equals("CARROT") || type.name().equals("POTATO")
|| type.name().equals("WHEAT") || type.name().equals("CROPS")) {
try {
block.getClass().getMethod("setData", byte.class).invoke(block, (byte) (block.getData() + 1));
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
| NoSuchMethodException | SecurityException e) {
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
e.printStackTrace();
}
}
@ -124,24 +113,23 @@ public class Grow implements Listener {
}
/**
* Checks that a block like a pumpkins and melons are not growing outside or into another island.
* Checks that a block like a pumpkins and melons are not growing outside or
* into another island.
*
* @author LimeGlass
*/
@EventHandler(ignoreCancelled = true)
public void onBlockGrow(BlockGrowEvent event) {
WorldManager worldManager = skyblock.getWorldManager();
BlockState state = event.getNewState();
if (!worldManager.isIslandWorld(state.getWorld()))
return;
if (state.getType() != Materials.PUMPKIN.parseMaterial() && state.getType() != Materials.MELON.parseMaterial())
return;
if (!worldManager.isIslandWorld(state.getWorld())) return;
if (state.getType() != Materials.PUMPKIN.parseMaterial() && state.getType() != Materials.MELON.parseMaterial()) return;
IslandManager islandManager = skyblock.getIslandManager();
Island origin = islandManager.getIslandAtLocation(event.getBlock().getLocation());
Island growingTo = islandManager.getIslandAtLocation(state.getLocation());
// This block is ok to continue as it's not related to Skyblock islands.
if (origin == null && growingTo == null)
return;
if (origin == null && growingTo == null) return;
// The growing block is outside/inside that it's not suppose to.
if (origin == null || growingTo == null) {
event.setCancelled(true);
@ -155,22 +143,20 @@ public class Grow implements Listener {
}
/**
* Checks that a structure growing like a tree, does not impact spawn location of the island.
* Checks that a structure growing like a tree, does not impact spawn location
* of the island.
*/
@EventHandler(ignoreCancelled = true)
public void onStructureCreate(StructureGrowEvent event) {
if (!skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration().getBoolean("Island.Spawn.Protection"))
return;
if (!skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration().getBoolean("Island.Spawn.Protection")) return;
List<BlockState> blocks = event.getBlocks();
if (blocks.isEmpty())
return;
if (blocks.isEmpty()) return;
WorldManager worldManager = skyblock.getWorldManager();
IslandManager islandManager = skyblock.getIslandManager();
Island island = islandManager.getIslandAtLocation(event.getLocation());
if (island == null)
return;
if (island == null) return;
// Check spawn block protection
IslandWorld world = worldManager.getIslandWorld(blocks.get(0).getWorld());
@ -184,27 +170,22 @@ public class Grow implements Listener {
@EventHandler
public void onFireSpread(BlockSpreadEvent event) {
if (event.getSource().getType() != Material.FIRE)
return;
if (event.getSource().getType() != Material.FIRE) return;
org.bukkit.block.Block block = event.getBlock();
if (!skyblock.getWorldManager().isIslandWorld(block.getWorld()))
return;
if (!skyblock.getWorldManager().isIslandWorld(block.getWorld())) return;
IslandManager islandManager = skyblock.getIslandManager();
if (!islandManager.hasSetting(block.getLocation(), IslandRole.Owner, "FireSpread"))
event.setCancelled(true);
if (!islandManager.hasSetting(block.getLocation(), IslandRole.Owner, "FireSpread")) event.setCancelled(true);
}
@EventHandler
public void onLeavesDecay(LeavesDecayEvent event) {
org.bukkit.block.Block block = event.getBlock();
if (!skyblock.getWorldManager().isIslandWorld(block.getWorld()))
return;
if (!skyblock.getWorldManager().isIslandWorld(block.getWorld())) return;
IslandManager islandManager = skyblock.getIslandManager();
if (!islandManager.hasSetting(block.getLocation(), IslandRole.Owner, "LeafDecay"))
event.setCancelled(true);
if (!islandManager.hasSetting(block.getLocation(), IslandRole.Owner, "LeafDecay")) event.setCancelled(true);
}
}

View File

@ -161,7 +161,7 @@ public class ScoreboardManager extends BukkitRunnable {
obj.setDisplayName(primaryObjective.getDisplayName());
obj.setDisplaySlot(primaryObjective.getDisplaySlot());
obj.setRenderType(primaryObjective.getRenderType());
if (VERSION > 12) obj.setRenderType(primaryObjective.getRenderType());
}
for (Team primaryTeam : teams) {