From dc4bbcd15fbc17cefc12be43ea55862ff2bd0355 Mon Sep 17 00:00:00 2001 From: Kieran Date: Thu, 2 Jun 2016 17:40:14 +0100 Subject: [PATCH] Added compatibility for 1.8-1.9.x - Changed to use 1.9 sound ENUM, uses fallback to legacy - Changed getOnlinePlayers().length to getOnlinePlayers().size() as it changed from an array to a collection - Added annotation for deprecated methods - Organised imports - Corrected some null elements --- .../plugins/buttonwarp/ButtonWarp.java | 10 +++++++--- .../plugins/buttonwarp/ButtonWarpCommand.java | 14 +++++++------- .../buttonwarp/ButtonWarpDelayListener.java | 2 +- .../buttonwarp/ButtonWarpVehicleListener.java | 1 - src/com/codisimus/plugins/buttonwarp/Econ.java | 11 ++++++----- .../codisimus/plugins/buttonwarp/Metrics.java | 17 +++++++++-------- src/com/codisimus/plugins/buttonwarp/Warp.java | 8 ++++++-- src/plugin.yml | 2 +- 8 files changed, 37 insertions(+), 28 deletions(-) diff --git a/src/com/codisimus/plugins/buttonwarp/ButtonWarp.java b/src/com/codisimus/plugins/buttonwarp/ButtonWarp.java index 791c326..3b516f0 100644 --- a/src/com/codisimus/plugins/buttonwarp/ButtonWarp.java +++ b/src/com/codisimus/plugins/buttonwarp/ButtonWarp.java @@ -4,10 +4,12 @@ import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; -import java.util.*; +import java.util.Arrays; +import java.util.Collection; +import java.util.Properties; +import java.util.TreeMap; import java.util.logging.Logger; -import net.milkbowl.vault.economy.Economy; -import net.milkbowl.vault.permission.Permission; + import org.bukkit.Server; import org.bukkit.block.Block; import org.bukkit.entity.Player; @@ -16,6 +18,8 @@ import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.java.JavaPlugin; +import net.milkbowl.vault.economy.Economy; + /** * Loads Plugin and manages Data/Permissions * diff --git a/src/com/codisimus/plugins/buttonwarp/ButtonWarpCommand.java b/src/com/codisimus/plugins/buttonwarp/ButtonWarpCommand.java index a5cb06c..fd9bccd 100644 --- a/src/com/codisimus/plugins/buttonwarp/ButtonWarpCommand.java +++ b/src/com/codisimus/plugins/buttonwarp/ButtonWarpCommand.java @@ -497,7 +497,7 @@ private static void move(Player player, String name, boolean noWhere) { */ private static void link(Player player, String name) { //Cancel if the Player is not targeting a correct Block type - Block block = player.getTargetBlock(null, 10); + Block block = player.getTargetBlock((Set)null, 10); Material type = block.getType(); if (!LINKABLE.contains(type)) { player.sendMessage("§4You are targeting a §6" + type.name() @@ -533,7 +533,7 @@ private static void link(Player player, String name) { */ private static void unlink(Player player) { //Cancel if the Player is not targeting a correct Block type - Block block = player.getTargetBlock(null, 10); + Block block = player.getTargetBlock((Set)null, 10); Material type = block.getType(); if (!LINKABLE.contains(type)) { player.sendMessage("§4You are targeting a §6" + type.name() @@ -780,7 +780,7 @@ private static void global(Player player, String name, boolean global) { * @param max The new maximum amount */ private static void max(Player player, int max) { - Block block = player.getTargetBlock(null, 10); + Block block = player.getTargetBlock((Set)null, 10); //Find the Warp that will be modified using the target Block Warp warp = ButtonWarp.findWarp(block); @@ -805,7 +805,7 @@ private static void max(Player player, int max) { * @param player The Player modifying the Button */ private static void allow(Player player) { - Block block = player.getTargetBlock(null, 10); + Block block = player.getTargetBlock((Set)null, 10); //Find the Warp that will be modified using the target Block Warp warp = ButtonWarp.findWarp(block); @@ -829,7 +829,7 @@ private static void allow(Player player) { * @param player The Player modifying the Button */ private static void deny(Player player) { - Block block = player.getTargetBlock(null, 10); + Block block = player.getTargetBlock((Set)null, 10); //Find the Warp that will be modified using the target Block Warp warp = ButtonWarp.findWarp(block); @@ -924,7 +924,7 @@ private static void reset(Player player, String name) { //Reset the target Button if a name was not provided if (name == null) { //Find the Warp that will be reset using the given name - Block block = player.getTargetBlock(null, 10); + Block block = player.getTargetBlock((Set)null, 10); Warp warp = ButtonWarp.findWarp(block); //Cancel if the Warp does not exist @@ -1088,7 +1088,7 @@ private static Warp getWarp(Player player, String name) { if (name == null) { //Find the Warp using the target Block - warp = ButtonWarp.findWarp(player.getTargetBlock(null, 10)); + warp = ButtonWarp.findWarp(player.getTargetBlock((Set)null, 10)); //Cancel if the Warp does not exist if (warp == null ) { diff --git a/src/com/codisimus/plugins/buttonwarp/ButtonWarpDelayListener.java b/src/com/codisimus/plugins/buttonwarp/ButtonWarpDelayListener.java index 72162b9..8fb81d3 100644 --- a/src/com/codisimus/plugins/buttonwarp/ButtonWarpDelayListener.java +++ b/src/com/codisimus/plugins/buttonwarp/ButtonWarpDelayListener.java @@ -1,7 +1,7 @@ package com.codisimus.plugins.buttonwarp; import java.util.HashMap; -import java.util.HashSet; + import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; diff --git a/src/com/codisimus/plugins/buttonwarp/ButtonWarpVehicleListener.java b/src/com/codisimus/plugins/buttonwarp/ButtonWarpVehicleListener.java index 30cad3b..5806cbd 100644 --- a/src/com/codisimus/plugins/buttonwarp/ButtonWarpVehicleListener.java +++ b/src/com/codisimus/plugins/buttonwarp/ButtonWarpVehicleListener.java @@ -8,7 +8,6 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.vehicle.VehicleMoveEvent; -import org.bukkit.util.Vector; /** * Listens for interactions with Warps diff --git a/src/com/codisimus/plugins/buttonwarp/Econ.java b/src/com/codisimus/plugins/buttonwarp/Econ.java index b36488c..221d381 100644 --- a/src/com/codisimus/plugins/buttonwarp/Econ.java +++ b/src/com/codisimus/plugins/buttonwarp/Econ.java @@ -1,10 +1,9 @@ package com.codisimus.plugins.buttonwarp; +import org.bukkit.entity.Player; + import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.EconomyResponse.ResponseType; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; /** * Manages payment/rewards of using Warps @@ -22,7 +21,8 @@ public class Econ { * @param amount The amount that will be charged * @return True if the transaction was successful */ - public static boolean charge(Player player, String source, double amount) { + @SuppressWarnings("deprecation") + public static boolean charge(Player player, String source, double amount) { String name = player.getName(); //Cancel if the Player cannot afford the transaction @@ -57,7 +57,8 @@ public static boolean charge(Player player, String source, double amount) { * @param source The Player/Bank that will give the reward * @param amount The amount that will be rewarded */ - public static void reward(Player player, String source, double amount) { + @SuppressWarnings("deprecation") + public static void reward(Player player, String source, double amount) { //Charge the source if it is not the server if (!source.equalsIgnoreCase("server")) { //Check if money comes from a Player or a Bank diff --git a/src/com/codisimus/plugins/buttonwarp/Metrics.java b/src/com/codisimus/plugins/buttonwarp/Metrics.java index 58dd58f..5efff64 100644 --- a/src/com/codisimus/plugins/buttonwarp/Metrics.java +++ b/src/com/codisimus/plugins/buttonwarp/Metrics.java @@ -1,11 +1,5 @@ package com.codisimus.plugins.buttonwarp; -import org.bukkit.Bukkit; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.configuration.InvalidConfigurationException; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.PluginDescriptionFile; - import java.io.BufferedReader; import java.io.File; import java.io.IOException; @@ -24,6 +18,12 @@ import java.util.UUID; import java.util.logging.Level; +import org.bukkit.Bukkit; +import org.bukkit.configuration.InvalidConfigurationException; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginDescriptionFile; + /** *

* The metrics class obtains data about a plugin and submits statistics about it to the metrics backend. @@ -181,7 +181,8 @@ public void addCustomData(final Plotter plotter) { * * @return True if statistics measuring is running, otherwise false. */ - public boolean start() { + @SuppressWarnings("deprecation") + public boolean start() { synchronized (optOutLock) { // Did we opt out? if (isOptOut()) { @@ -303,7 +304,7 @@ private void postPlugin(final boolean isPing) throws IOException { data.append(encode("guid")).append('=').append(encode(guid)); encodeDataPair(data, "version", description.getVersion()); encodeDataPair(data, "server", Bukkit.getVersion()); - encodeDataPair(data, "players", Integer.toString(Bukkit.getServer().getOnlinePlayers().length)); + encodeDataPair(data, "players", Integer.toString(Bukkit.getOnlinePlayers().size())); encodeDataPair(data, "revision", String.valueOf(REVISION)); // If we're pinging, append it diff --git a/src/com/codisimus/plugins/buttonwarp/Warp.java b/src/com/codisimus/plugins/buttonwarp/Warp.java index 4d4fd3f..fe5a074 100644 --- a/src/com/codisimus/plugins/buttonwarp/Warp.java +++ b/src/com/codisimus/plugins/buttonwarp/Warp.java @@ -17,6 +17,7 @@ * * @author Codisimus */ +@SuppressWarnings("rawtypes") public class Warp implements Comparable { static boolean log; static boolean broadcast; @@ -237,7 +238,8 @@ private boolean hasAccess(Player player) { * @param player The Player who is being checked for smuggling * @return true if the Player is smuggling */ - private boolean isSmuggling(Player player, Button button) { + @SuppressWarnings("deprecation") + private boolean isSmuggling(Player player, Button button) { //Return false if smuggling is allowed if (button.takeItems) { return false; @@ -404,7 +406,9 @@ public void teleport(Player player) { player.teleport(sendTo); if (sound) { - player.playSound(sendTo, Sound.ENDERMAN_TELEPORT, 0.8F, 0.075F); + Sound s; + try { s = Sound.valueOf("ENTITY_ENDERMEN_TELEPORT"); } catch (Exception e) { s = Sound.valueOf("ENDERMAN_TELEPORT"); } + player.playSound(sendTo, s, 0.8F, 0.075F); } } diff --git a/src/plugin.yml b/src/plugin.yml index d2f8f1f..13e95e2 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ name: ButtonWarp main: com.codisimus.plugins.buttonwarp.ButtonWarp -version: 2.2.3 +version: 2.2.3 1.9-BUILD author: Codisimus website: www.codisimus.com description: Teleport using buttons with price/reward/custom messages