mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-12-25 02:27:42 +01:00
Add support for slightly older versions of Bukkit 1.7.9.
This commit is contained in:
parent
c3bdc33215
commit
53132ce83a
@ -19,6 +19,7 @@
|
||||
|
||||
package com.sk89q.worldguard.bukkit;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BlockID;
|
||||
@ -26,28 +27,21 @@
|
||||
import com.sk89q.worldedit.blocks.ItemID;
|
||||
import com.sk89q.worldguard.blacklist.target.MaterialTarget;
|
||||
import com.sk89q.worldguard.blacklist.target.Target;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.ExperienceOrb;
|
||||
import org.bukkit.entity.FallingBlock;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
public class BukkitUtil {
|
||||
|
||||
private static Method ONLINE_PLAYERS_METHOD;
|
||||
|
||||
private BukkitUtil() {
|
||||
|
||||
}
|
||||
@ -350,4 +344,42 @@ public static Target createTarget(Material material) {
|
||||
return new MaterialTarget(material.getId(), (short) 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a collection of the currently online players.
|
||||
*
|
||||
* @return The online players
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Collection<? extends Player> getOnlinePlayers() {
|
||||
try {
|
||||
return Bukkit.getServer().getOnlinePlayers();
|
||||
} catch (NoSuchMethodError ignored) {
|
||||
}
|
||||
|
||||
try {
|
||||
if (ONLINE_PLAYERS_METHOD == null) {
|
||||
ONLINE_PLAYERS_METHOD = getOnlinePlayersMethod();
|
||||
}
|
||||
|
||||
Object result = ONLINE_PLAYERS_METHOD.invoke(Bukkit.getServer());
|
||||
if (result instanceof Player[]) {
|
||||
return ImmutableList.copyOf((Player[]) result);
|
||||
} else if (result instanceof Collection<?>) {
|
||||
return (Collection<? extends Player>) result;
|
||||
} else {
|
||||
throw new RuntimeException("Result of getOnlinePlayers() call was not a known data type");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("WorldGuard is not compatible with this version of Bukkit", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static Method getOnlinePlayersMethod() throws NoSuchMethodException {
|
||||
try {
|
||||
return Server.class.getMethod("getOnlinePlayers");
|
||||
} catch (NoSuchMethodException e1) {
|
||||
return Server.class.getMethod("_INVALID_getOnlinePlayers");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -207,7 +207,7 @@ public void run() {
|
||||
}
|
||||
worldListener.registerEvents();
|
||||
|
||||
for (Player player : getServer().getOnlinePlayers()) {
|
||||
for (Player player : BukkitUtil.getOnlinePlayers()) {
|
||||
ProcessPlayerEvent event = new ProcessPlayerEvent(player);
|
||||
Events.fire(event);
|
||||
}
|
||||
@ -510,7 +510,7 @@ public Player checkPlayer(CommandSender sender)
|
||||
* @return A {@link List} of players who match {@code filter}
|
||||
*/
|
||||
public List<Player> matchPlayerNames(String filter) {
|
||||
Collection<? extends Player> players = getServer().getOnlinePlayers();
|
||||
Collection<? extends Player> players = BukkitUtil.getOnlinePlayers();
|
||||
|
||||
filter = filter.toLowerCase();
|
||||
|
||||
@ -591,12 +591,12 @@ protected Iterable<? extends Player> checkPlayerMatch(List<? extends Player> pla
|
||||
public Iterable<? extends Player> matchPlayers(CommandSender source, String filter)
|
||||
throws CommandException {
|
||||
|
||||
if (getServer().getOnlinePlayers().isEmpty()) {
|
||||
if (BukkitUtil.getOnlinePlayers().isEmpty()) {
|
||||
throw new CommandException("No players matched query.");
|
||||
}
|
||||
|
||||
if (filter.equals("*")) {
|
||||
return checkPlayerMatch(Lists.newArrayList(getServer().getOnlinePlayers()));
|
||||
return checkPlayerMatch(Lists.newArrayList(BukkitUtil.getOnlinePlayers()));
|
||||
}
|
||||
|
||||
// Handle special hash tag groups
|
||||
@ -608,7 +608,7 @@ public Iterable<? extends Player> matchPlayers(CommandSender source, String filt
|
||||
Player sourcePlayer = checkPlayer(source);
|
||||
World sourceWorld = sourcePlayer.getWorld();
|
||||
|
||||
for (Player player : getServer().getOnlinePlayers()) {
|
||||
for (Player player : BukkitUtil.getOnlinePlayers()) {
|
||||
if (player.getWorld().equals(sourceWorld)) {
|
||||
players.add(player);
|
||||
}
|
||||
@ -624,7 +624,7 @@ public Iterable<? extends Player> matchPlayers(CommandSender source, String filt
|
||||
org.bukkit.util.Vector sourceVector
|
||||
= sourcePlayer.getLocation().toVector();
|
||||
|
||||
for (Player player : getServer().getOnlinePlayers()) {
|
||||
for (Player player : BukkitUtil.getOnlinePlayers()) {
|
||||
if (player.getWorld().equals(sourceWorld)
|
||||
&& player.getLocation().toVector().distanceSquared(
|
||||
sourceVector) < 900) {
|
||||
@ -916,7 +916,7 @@ public void createDefaultConfiguration(File actual,
|
||||
public void broadcastNotification(String msg) {
|
||||
getServer().broadcast(msg, "worldguard.notify");
|
||||
Set<Permissible> subs = getServer().getPluginManager().getPermissionSubscriptions("worldguard.notify");
|
||||
for (Player player : getServer().getOnlinePlayers()) {
|
||||
for (Player player : BukkitUtil.getOnlinePlayers()) {
|
||||
if (!(subs.contains(player) && player.hasPermission("worldguard.notify")) &&
|
||||
hasPermission(player, "worldguard.notify")) { // Make sure the player wasn't already broadcasted to.
|
||||
player.sendMessage(msg);
|
||||
@ -994,7 +994,7 @@ public PlayerMoveListener getPlayerMoveListener() {
|
||||
* @return The message with macros replaced
|
||||
*/
|
||||
public String replaceMacros(CommandSender sender, String message) {
|
||||
Collection<? extends Player> online = getServer().getOnlinePlayers();
|
||||
Collection<? extends Player> online = BukkitUtil.getOnlinePlayers();
|
||||
|
||||
message = message.replace("%name%", toName(sender));
|
||||
message = message.replace("%id%", toUniqueName(sender));
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package com.sk89q.worldguard.bukkit.listener;
|
||||
|
||||
import com.sk89q.worldguard.bukkit.BukkitUtil;
|
||||
import com.sk89q.worldguard.bukkit.ConfigurationManager;
|
||||
import com.sk89q.worldguard.bukkit.WorldConfiguration;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
@ -62,7 +63,7 @@ public FlagStateManager(WorldGuardPlugin plugin) {
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
Collection<? extends Player> players = plugin.getServer().getOnlinePlayers();
|
||||
Collection<? extends Player> players = BukkitUtil.getOnlinePlayers();
|
||||
ConfigurationManager config = plugin.getGlobalStateManager();
|
||||
|
||||
for (Player player : players) {
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package com.sk89q.worldguard.bukkit.util.report;
|
||||
|
||||
import com.sk89q.worldguard.bukkit.BukkitUtil;
|
||||
import com.sk89q.worldguard.util.report.DataReport;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
@ -34,7 +35,7 @@ public ServerReport() {
|
||||
append("Server Name", server.getServerName());
|
||||
append("Bukkit Version", server.getBukkitVersion());
|
||||
append("Implementation", server.getVersion());
|
||||
append("Player Count", "%d/%d", server.getOnlinePlayers().size(), server.getMaxPlayers());
|
||||
append("Player Count", "%d/%d", BukkitUtil.getOnlinePlayers().size(), server.getMaxPlayers());
|
||||
|
||||
DataReport spawning = new DataReport("Spawning");
|
||||
spawning.append("Ambient Spawn Limit", server.getAmbientSpawnLimit());
|
||||
|
Loading…
Reference in New Issue
Block a user