From 05d37326e0a06bf57415aa30e118434e7573304b Mon Sep 17 00:00:00 2001 From: pickernickel Date: Wed, 18 May 2016 23:54:48 -0500 Subject: [PATCH] Circumvented some deprecated API usage. --- .../limitedcreative/FeatureBlockItemSpawn.java | 4 ++-- .../blockstate/BlockStateCommand.java | 6 ++---- .../blockstate/HangingStandingListener.java | 1 - .../limitedcreative/blockstate/PlayerListener.java | 4 ++-- .../limitedcreative/inventories/store/Fallback.java | 12 ++++++------ .../minecraft/limitedcreative/limits/BlackList.java | 2 +- .../limitedcreative/limits/BlackListEntity.java | 2 +- .../limitedcreative/limits/NoLimitPermissions.java | 6 +++--- .../limitedcreative/limits/PlayerListener.java | 4 ++-- .../limitedcreative/regions/RegionsCommand.java | 10 +++++----- .../regions/worldguard/ApplicableRegions.java | 9 +++++---- .../regions/worldguard/CustomRegionManager.java | 6 +----- .../worldguard/events/PlayerUpdateAreaEvent.java | 7 +++---- 13 files changed, 33 insertions(+), 40 deletions(-) diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/FeatureBlockItemSpawn.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/FeatureBlockItemSpawn.java index 33817ec..e0b29ed 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/FeatureBlockItemSpawn.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/FeatureBlockItemSpawn.java @@ -74,11 +74,11 @@ public class FeatureBlockItemSpawn extends CoreModule implement } public void block(Block block, Player player) { - if (player.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) { + if (player.getInventory().getItemInMainHand().containsEnchantment(Enchantment.SILK_TOUCH)) { block(block.getLocation(), block.getType()); } else { // doesn't include silktouch - for (ItemStack i : block.getDrops(player.getItemInHand())) { + for (ItemStack i : block.getDrops(player.getInventory().getItemInMainHand())) { block(block.getLocation(), i.getType()); } } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateCommand.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateCommand.java index 7d5bd9a..5aac8df 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateCommand.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateCommand.java @@ -7,8 +7,6 @@ import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; -import org.bukkit.scheduler.BukkitRunnable; - import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.bukkit.selections.Selection; @@ -105,7 +103,7 @@ public class BlockStateCommand extends BukkitCommand implements IHelpDescribed { if (mod.getConfig().getLogSurvival()) { context.responseFormatted(ChatFormattings.INFO, L("command.blockstate.nothing_to_cleanup")); } else { - mod.getPlugin().getServer().getScheduler().runTaskAsynchronously(mod.getPlugin(), new BukkitRunnable() { + mod.getPlugin().getServer().getScheduler().runTaskAsynchronously(mod.getPlugin(), new Runnable() { @Override public void run() { int countDeleted = mod.getModel().cleanUp(DBModel.Cleanup.SURVIVAL); @@ -168,7 +166,7 @@ public class BlockStateCommand extends BukkitCommand implements IHelpDescribed { final Location min = selection.getMinimumPoint(); final Location max = selection.getMaximumPoint(); - mod.getPlugin().getServer().getScheduler().runTaskAsynchronously(mod.getPlugin(), new BukkitRunnable() { + mod.getPlugin().getServer().getScheduler().runTaskAsynchronously(mod.getPlugin(), new Runnable() { @Override public void run() { if (mod.isDebug()) diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/HangingStandingListener.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/HangingStandingListener.java index fa70363..9c7c161 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/HangingStandingListener.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/HangingStandingListener.java @@ -11,7 +11,6 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.hanging.HangingBreakEvent; diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/PlayerListener.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/PlayerListener.java index b00bca5..62d37a1 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/PlayerListener.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/PlayerListener.java @@ -29,7 +29,7 @@ public class PlayerListener implements Listener { public void onInteract(PlayerInteractEvent event) { if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { Block b = event.getClickedBlock(); - if (b != null && event.getPlayer().getItemInHand().getType().equals(mod.getConfig().getTool()) && mod.getPlugin().getPermManager().hasPermission(event.getPlayer(), BlockStatePermissions.TOOL)) { + if (b != null && event.getPlayer().getInventory().getItemInMainHand().getType().equals(mod.getConfig().getTool()) && mod.getPlugin().getPermManager().hasPermission(event.getPlayer(), BlockStatePermissions.TOOL)) { if (mod.getConfig().getIgnoredWorlds().contains(event.getClickedBlock().getWorld().getName())) { event.getPlayer().sendMessage(mod.getPlugin().getLocale().trans("command.blockstate.world_ignored", event.getClickedBlock().getWorld().getName())); } else { @@ -41,7 +41,7 @@ public class PlayerListener implements Listener { @EventHandler(priority = EventPriority.HIGH) public void onInteractEntity(PlayerInteractEntityEvent event) { Entity e = event.getRightClicked(); - if (e != null && e instanceof ItemFrame && event.getPlayer().getItemInHand().getType().equals(mod.getConfig().getTool()) && mod.getPlugin().getPermManager().hasPermission(event.getPlayer(), BlockStatePermissions.TOOL)) { + if (e != null && e instanceof ItemFrame && event.getPlayer().getInventory().getItemInMainHand().getType().equals(mod.getConfig().getTool()) && mod.getPlugin().getPermManager().hasPermission(event.getPlayer(), BlockStatePermissions.TOOL)) { if (mod.getConfig().getIgnoredWorlds().contains(e.getWorld().getName())) { event.getPlayer().sendMessage(mod.getPlugin().getLocale().trans("command.blockstate.world_ignored", e.getWorld().getName())); } else { diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/store/Fallback.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/store/Fallback.java index cc08897..c0a44aa 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/store/Fallback.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/store/Fallback.java @@ -47,7 +47,7 @@ public class Fallback { @Override public void store(ConfigurationSection section) { for (int i = 0; i < inv.getSize(); i++) { - if (inv.getItem(i) != null && inv.getItem(i).getTypeId() != 0) + if (inv.getItem(i) != null && !inv.getItem(i).getType().equals(Material.AIR)) sectionSetItem(section, String.valueOf(i), inv.getItem(i)); } } @@ -97,7 +97,7 @@ public class Fallback { public static Map storeInventory(PlayerInventory inv) { Map map = new HashMap(); for (int i = 0; i < inv.getSize(); i++) { - if (inv.getItem(i) != null && inv.getItem(i).getTypeId() != 0) { + if (inv.getItem(i) != null && !inv.getItem(i).getType().equals(Material.AIR)) { map.put(i, inv.getItem(i)); } } @@ -133,13 +133,13 @@ public class Fallback { @Override public void store(ConfigurationSection section) { - if (inv.getHelmet() != null && inv.getHelmet().getTypeId() != 0) + if (inv.getHelmet() != null && !inv.getHelmet().getType().equals(Material.AIR)) Items.sectionSetItem(section, "helmet", inv.getHelmet()); - if (inv.getChestplate() != null && inv.getChestplate().getTypeId() != 0) + if (inv.getChestplate() != null && !inv.getChestplate().getType().equals(Material.AIR)) Items.sectionSetItem(section, "chestplate", inv.getChestplate()); - if (inv.getLeggings() != null && inv.getLeggings().getTypeId() != 0) + if (inv.getLeggings() != null && !inv.getLeggings().getType().equals(Material.AIR)) Items.sectionSetItem(section, "leggins", inv.getLeggings()); - if (inv.getBoots() != null && inv.getBoots().getTypeId() != 0) + if (inv.getBoots() != null && !inv.getBoots().getType().equals(Material.AIR)) Items.sectionSetItem(section, "boots", inv.getBoots()); } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/BlackList.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/BlackList.java index d7ebfd8..0b7dd04 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/BlackList.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/BlackList.java @@ -55,7 +55,7 @@ public class BlackList extends ArrayList implements Confi } public boolean matches(Block block) { if (hasData) { - return md.equals(new MaterialData(block.getType(), block.getData())); + return md.equals(block.getState().getData()); } else { return block.getType().equals(md.getItemType()); } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/BlackListEntity.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/BlackListEntity.java index a25cedd..0eb4b41 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/BlackListEntity.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/BlackListEntity.java @@ -52,7 +52,7 @@ public class BlackListEntity extends ArrayList impl type = null; } if (type == null) - type = EntityType.fromName(rep); + type = EntityType.valueOf(rep); try { if (type == null) type = EntityType.valueOf(rep); diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/NoLimitPermissions.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/NoLimitPermissions.java index 383e370..14e1b32 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/NoLimitPermissions.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/NoLimitPermissions.java @@ -118,16 +118,16 @@ public class NoLimitPermissions extends SimplePermissionContainerNode { return new InventoryPermission(CHEST, invtype); } public static IDynamicPermission INTERACT(Block block) { - return new MaterialPermission(BASE_INTERACT, new MaterialData(block.getType(), block.getData())); + return new MaterialPermission(BASE_INTERACT, block.getState().getData()); } public static IDynamicPermission USE(Block block) { - return new MaterialPermission(BASE_USE, new MaterialData(block.getType(), block.getData())); + return new MaterialPermission(BASE_USE, block.getState().getData()); } public static IDynamicPermission USE(MaterialData m) { return new MaterialPermission(BASE_USE, m); } public static IDynamicPermission BREAK(Block block) { - return new MaterialPermission(BASE_BREAK, new MaterialData(block.getType(), block.getData())); + return new MaterialPermission(BASE_BREAK, block.getState().getData()); } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/PlayerListener.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/PlayerListener.java index 4c3dc80..4155538 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/PlayerListener.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/PlayerListener.java @@ -195,8 +195,8 @@ public class PlayerListener implements Listener { @EventHandler public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { if (!event.isCancelled() && event.getPlayer().getGameMode() == GameMode.CREATIVE) { - if (mod.getConfig().getBlockUse().isListed(event.getPlayer().getItemInHand())) { - if (!checkPermission(event, NoLimitPermissions.USE(event.getPlayer().getItemInHand().getData()))) { + if (mod.getConfig().getBlockUse().isListed(event.getPlayer().getInventory().getItemInMainHand())) { + if (!checkPermission(event, NoLimitPermissions.USE(event.getPlayer().getInventory().getItemInMainHand().getData()))) { event.setCancelled(true); event.getPlayer().sendMessage(mod.getPlugin().getLocale().trans("blocked.use")); return; diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/RegionsCommand.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/RegionsCommand.java index 5c99f56..7d385e9 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/RegionsCommand.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/RegionsCommand.java @@ -138,7 +138,7 @@ public class RegionsCommand extends BukkitCommand implements IHelpDescribed { if (idx > -1 && context.getArgument(idx) != null) w = Bukkit.getWorld(context.getArgument(idx)); if (w != null) { - RegionManager mgr = getWorldGuard().getGlobalRegionManager().get(w); + RegionManager mgr = getWorldGuard().getRegionManager(w); if (mgr != null) { List hints = new ArrayList(); for (String rId : mgr.getRegions().keySet()) { @@ -174,7 +174,7 @@ public class RegionsCommand extends BukkitCommand implements IHelpDescribed { if (w == null) throw new CommandException(L("command.worldguard.world_not_found")); - RegionManager mgr = getWorldGuard().getGlobalRegionManager().get(w); + RegionManager mgr = getWorldGuard().getRegionManager(w); ProtectedRegion region = mgr.getRegion(params.getArgument(0)); if (region == null && params.getArgument(0).equalsIgnoreCase("__global__")) { region = new GlobalProtectedRegion(params.getArgument(0)); @@ -238,16 +238,16 @@ public class RegionsCommand extends BukkitCommand implements IHelpDescribed { ProtectedRegion region = null; if (params.getArgumentCount() == 0 && context.isPlayer()) { - RegionManager mgr = getWorldGuard().getGlobalRegionManager().get(context.getPlayer().getWorld()); + RegionManager mgr = getWorldGuard().getRegionManager(context.getPlayer().getWorld()); ApplicableRegionSet set = mgr.getApplicableRegions(context.getPlayer().getLocation()); if (set.size() > 0) { region = set.iterator().next(); } else { - region = getWorldGuard().getGlobalRegionManager().get(w).getRegion(GLOBAL_REGION); + region = getWorldGuard().getRegionManager(w).getRegion(GLOBAL_REGION); } } else { int rpc = params.getArgumentCount() > 1 ? 1 : 0; - RegionManager mgr = getWorldGuard().getGlobalRegionManager().get(w); + RegionManager mgr = getWorldGuard().getRegionManager(w); region = mgr.getRegion(params.getArgument(rpc)); if (region == null && params.getArgument(rpc).equalsIgnoreCase(GLOBAL_REGION)) { region = new GlobalProtectedRegion(params.getArgument(rpc)); diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/worldguard/ApplicableRegions.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/worldguard/ApplicableRegions.java index 1dba934..986ca81 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/worldguard/ApplicableRegions.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/worldguard/ApplicableRegions.java @@ -22,6 +22,7 @@ import org.bukkit.entity.Player; import com.sk89q.worldguard.protection.ApplicableRegionSet; import com.sk89q.worldguard.protection.flags.Flag; import com.sk89q.worldguard.protection.flags.StateFlag; +import com.sk89q.worldguard.protection.flags.StateFlag.State; import com.sk89q.worldguard.protection.regions.ProtectedRegion; public class ApplicableRegions { @@ -36,28 +37,28 @@ public class ApplicableRegions { public boolean allows(StateFlag flag) { extendRegionFlags(); - boolean r = regions.allows(flag); + boolean r = regions.queryState(null, flag).equals(State.ALLOW); contractRegionFlags(); return r; } public boolean allows(StateFlag flag, Player player) { extendRegionFlags(); - boolean r = regions.allows(flag, mgr.getWorldGuard().wrapPlayer(player)); + boolean r = regions.queryState(mgr.getWorldGuard().wrapPlayer(player), flag).equals(State.ALLOW); contractRegionFlags(); return r; } public , V> V getFlag(T flag) { extendRegionFlags(); - V r = regions.getFlag(flag); + V r = regions.queryValue(null, flag); contractRegionFlags(); return r; } public , V> V getFlag(T flag, Player player) { extendRegionFlags(); - V r = regions.getFlag(flag, mgr.getWorldGuard().wrapPlayer(player)); + V r = regions.queryValue(mgr.getWorldGuard().wrapPlayer(player), flag); contractRegionFlags(); return r; } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/worldguard/CustomRegionManager.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/worldguard/CustomRegionManager.java index 227481e..ba15f6f 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/worldguard/CustomRegionManager.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/worldguard/CustomRegionManager.java @@ -34,7 +34,6 @@ import org.bukkit.entity.Player; import com.sk89q.worldguard.bukkit.BukkitUtil; import com.sk89q.worldguard.bukkit.WorldGuardPlugin; -import com.sk89q.worldguard.protection.GlobalRegionManager; import com.sk89q.worldguard.protection.flags.Flag; import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.regions.ProtectedRegion; @@ -160,10 +159,7 @@ public class CustomRegionManager { private WorldGuardPlugin getWorldGuard() { return ((WorldGuardPlugin) mod.getPlugin().getServer().getPluginManager().getPlugin(WorldGuardIntegration.PLUGIN_NAME)); } - - public GlobalRegionManager getWGGlobalManager() { - return getWorldGuard().getGlobalRegionManager(); - } + public RegionManager getWGManager(World world) { return getWorldGuard().getRegionManager(world); } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/worldguard/events/PlayerUpdateAreaEvent.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/worldguard/events/PlayerUpdateAreaEvent.java index fcf0274..49e8c4f 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/worldguard/events/PlayerUpdateAreaEvent.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/worldguard/events/PlayerUpdateAreaEvent.java @@ -17,7 +17,6 @@ */ package de.jaschastarke.minecraft.limitedcreative.regions.worldguard.events; -import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; @@ -25,11 +24,11 @@ import de.jaschastarke.minecraft.limitedcreative.regions.worldguard.ApplicableRe import de.jaschastarke.minecraft.limitedcreative.regions.worldguard.CustomRegionManager; public class PlayerUpdateAreaEvent extends PlayerAreaEvent { - private String player; + private Player player; private String hash; protected CustomRegionManager mgr; - public PlayerUpdateAreaEvent(CustomRegionManager mgr, String player, String hash) { + public PlayerUpdateAreaEvent(CustomRegionManager mgr, Player player, String hash) { this.mgr = mgr; this.player = player; this.hash = hash; @@ -46,7 +45,7 @@ public class PlayerUpdateAreaEvent extends PlayerAreaEvent { @Override public Player getPlayer() { - return Bukkit.getServer().getPlayerExact(player); + return player; } private static final HandlerList handlers = new HandlerList();