diff --git a/AreaShop/pom.xml b/AreaShop/pom.xml index b956059a..571efa13 100644 --- a/AreaShop/pom.xml +++ b/AreaShop/pom.xml @@ -5,7 +5,7 @@ areashop jar AreaShop - 2.2.1 + 2.2.2 UTF-8 @@ -116,7 +116,7 @@ org.apache.maven.plugins maven-shade-plugin - 1.4 + 2.4.3 package @@ -128,7 +128,7 @@ maven-compiler-plugin - 3.3 + 3.5.1 1.7 1.7 diff --git a/AreaShop/src/main/java/nl/evolutioncoding/areashop/AreaShop.java b/AreaShop/src/main/java/nl/evolutioncoding/areashop/AreaShop.java index 730f3265..bc6c22c2 100644 --- a/AreaShop/src/main/java/nl/evolutioncoding/areashop/AreaShop.java +++ b/AreaShop/src/main/java/nl/evolutioncoding/areashop/AreaShop.java @@ -245,7 +245,7 @@ public void run() { new BukkitRunnable() { @Override public void run() { - for(Player player : Bukkit.getOnlinePlayers()) { + for(Player player : Utils.getOnlinePlayers()) { if(player.hasPermission("areashop.notifyupdate")) { AreaShop.getInstance().message(player, "update-playerNotify", AreaShop.getInstance().getDescription().getVersion(), AreaShop.getInstance().getUpdater().getLatestName()); } diff --git a/AreaShop/src/main/java/nl/evolutioncoding/areashop/Utils.java b/AreaShop/src/main/java/nl/evolutioncoding/areashop/Utils.java index 2a01a638..59cebd0b 100644 --- a/AreaShop/src/main/java/nl/evolutioncoding/areashop/Utils.java +++ b/AreaShop/src/main/java/nl/evolutioncoding/areashop/Utils.java @@ -9,14 +9,13 @@ import nl.evolutioncoding.areashop.regions.GeneralRegion; import nl.evolutioncoding.areashop.regions.GeneralRegion.RegionType; import nl.evolutioncoding.areashop.regions.RentRegion; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.World; +import org.bukkit.*; import org.bukkit.block.BlockFace; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; +import java.lang.reflect.Method; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.*; @@ -58,6 +57,26 @@ public static void initialize(YamlConfiguration pluginConfig) { identifiers.addAll(years); } + /** + * Gets the online players + * Provides backwards compatibility for 1.7- where it returns an array + * @return Online players + */ + @SuppressWarnings("unchecked") + public static Collection getOnlinePlayers() { + try { + Method onlinePlayerMethod = Server.class.getMethod("getOnlinePlayers"); + if(onlinePlayerMethod.getReturnType().equals(Collection.class)) { + return ((Collection)onlinePlayerMethod.invoke(Bukkit.getServer())); + } else { + return Arrays.asList((Player[])onlinePlayerMethod.invoke(Bukkit.getServer())); + } + } catch(Exception ex) { + AreaShop.debug("getOnlinePlayers error: "+ex.getMessage()); + } + return new HashSet<>(); + } + /** * Create a map from a location, to save it in the config * @param location The location to transform diff --git a/AreaShop/src/main/java/nl/evolutioncoding/areashop/commands/AddfriendCommand.java b/AreaShop/src/main/java/nl/evolutioncoding/areashop/commands/AddfriendCommand.java index e05090e2..bb26eeeb 100644 --- a/AreaShop/src/main/java/nl/evolutioncoding/areashop/commands/AddfriendCommand.java +++ b/AreaShop/src/main/java/nl/evolutioncoding/areashop/commands/AddfriendCommand.java @@ -126,7 +126,7 @@ public void execute(CommandSender sender, String[] args) { public List getTabCompleteList(int toComplete, String[] start, CommandSender sender) { ArrayList result = new ArrayList<>(); if(toComplete == 2) { - for(Player player : Bukkit.getOnlinePlayers()) { + for(Player player : Utils.getOnlinePlayers()) { result.add(player.getName()); } } else if(toComplete == 3) { diff --git a/AreaShop/src/main/java/nl/evolutioncoding/areashop/commands/DelfriendCommand.java b/AreaShop/src/main/java/nl/evolutioncoding/areashop/commands/DelfriendCommand.java index b7633306..6123eb5c 100644 --- a/AreaShop/src/main/java/nl/evolutioncoding/areashop/commands/DelfriendCommand.java +++ b/AreaShop/src/main/java/nl/evolutioncoding/areashop/commands/DelfriendCommand.java @@ -108,7 +108,7 @@ public void execute(CommandSender sender, String[] args) { public List getTabCompleteList(int toComplete, String[] start, CommandSender sender) { ArrayList result = new ArrayList<>(); if(toComplete == 2) { - for(Player player : Bukkit.getOnlinePlayers()) { + for(Player player : Utils.getOnlinePlayers()) { result.add(player.getName()); } } else if(toComplete == 3) { diff --git a/AreaShop/src/main/java/nl/evolutioncoding/areashop/commands/InfoCommand.java b/AreaShop/src/main/java/nl/evolutioncoding/areashop/commands/InfoCommand.java index 566af8b0..a76804b6 100644 --- a/AreaShop/src/main/java/nl/evolutioncoding/areashop/commands/InfoCommand.java +++ b/AreaShop/src/main/java/nl/evolutioncoding/areashop/commands/InfoCommand.java @@ -7,7 +7,6 @@ import nl.evolutioncoding.areashop.regions.RegionGroup; import nl.evolutioncoding.areashop.regions.RentRegion; import org.apache.commons.lang.StringUtils; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -384,7 +383,7 @@ public List getTabCompleteList(int toComplete, String[] start, CommandSe result.addAll(Arrays.asList("all", "rented", "forrent", "sold", "forsale", "player", "region", "nogroup")); } else if(toComplete == 3) { if(start[2].equalsIgnoreCase("player")) { - for(Player player : Bukkit.getOnlinePlayers()) { + for(Player player : Utils.getOnlinePlayers()) { result.add(player.getName()); } } else if(start[2].equalsIgnoreCase("region")) { diff --git a/AreaShop/src/main/java/nl/evolutioncoding/areashop/commands/SetlandlordCommand.java b/AreaShop/src/main/java/nl/evolutioncoding/areashop/commands/SetlandlordCommand.java index a6d0fbea..6438ba7a 100644 --- a/AreaShop/src/main/java/nl/evolutioncoding/areashop/commands/SetlandlordCommand.java +++ b/AreaShop/src/main/java/nl/evolutioncoding/areashop/commands/SetlandlordCommand.java @@ -80,7 +80,7 @@ public void execute(CommandSender sender, String[] args) { public List getTabCompleteList(int toComplete, String[] start, CommandSender sender) { ArrayList result = new ArrayList<>(); if(toComplete == 2) { - for(Player player : Bukkit.getOnlinePlayers()) { + for(Player player : Utils.getOnlinePlayers()) { result.add(player.getName()); } } else if(toComplete == 3) { diff --git a/AreaShop/src/main/java/nl/evolutioncoding/areashop/commands/SetownerCommand.java b/AreaShop/src/main/java/nl/evolutioncoding/areashop/commands/SetownerCommand.java index e83a72af..f6a88158 100644 --- a/AreaShop/src/main/java/nl/evolutioncoding/areashop/commands/SetownerCommand.java +++ b/AreaShop/src/main/java/nl/evolutioncoding/areashop/commands/SetownerCommand.java @@ -126,7 +126,7 @@ public void execute(CommandSender sender, String[] args) { public List getTabCompleteList(int toComplete, String[] start, CommandSender sender) { ArrayList result = new ArrayList<>(); if(toComplete == 2) { - for(Player player : Bukkit.getOnlinePlayers()) { + for(Player player : Utils.getOnlinePlayers()) { result.add(player.getName()); } } else if(toComplete == 3) {