cleanup Utils.java

This commit is contained in:
DNx5 2015-09-13 21:56:42 +07:00
parent 680717dbca
commit 851eab2fd0

View File

@ -12,6 +12,7 @@ import org.bukkit.entity.Player;
import java.io.File; import java.io.File;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
@ -19,8 +20,7 @@ public class Utils {
private String currentGroup; private String currentGroup;
private static Utils singleton; private static Utils singleton;
int id; public final AuthMe plugin;
public AuthMe plugin;
public Utils(AuthMe plugin) { public Utils(AuthMe plugin) {
this.plugin = plugin; this.plugin = plugin;
@ -112,11 +112,7 @@ public class Utils {
} }
public boolean isUnrestricted(Player player) { public boolean isUnrestricted(Player player) {
if (!Settings.isAllowRestrictedIp) return Settings.isAllowRestrictedIp && !(Settings.getUnrestrictedName == null || Settings.getUnrestrictedName.isEmpty()) && (Settings.getUnrestrictedName.contains(player.getName()));
return false;
if (Settings.getUnrestrictedName == null || Settings.getUnrestrictedName.isEmpty())
return false;
return (Settings.getUnrestrictedName.contains(player.getName()));
} }
public static Utils getInstance() { public static Utils getInstance() {
@ -125,9 +121,7 @@ public class Utils {
} }
private boolean useGroupSystem() { private boolean useGroupSystem() {
if (Settings.isPermissionCheckEnabled && !Settings.getUnloggedinGroup.isEmpty()) return Settings.isPermissionCheckEnabled && !Settings.getUnloggedinGroup.isEmpty();
return true;
return false;
} }
public void packCoords(double x, double y, double z, String w, public void packCoords(double x, double y, double z, String w,
@ -189,15 +183,17 @@ public class Utils {
} }
public static Player[] getOnlinePlayers() { public static Player[] getOnlinePlayers() {
Player[] players = null; Player[] players;
try { try {
if (Bukkit.class.getMethod("getOnlinePlayers", new Class<?>[0]).getReturnType() == Collection.class) { Method m = Bukkit.class.getMethod("getOnlinePlayers");
players = (Player[]) ((Collection<?>) Bukkit.class.getMethod("getOnlinePlayers", new Class<?>[0]).invoke(null)).toArray(); if (m.getReturnType() == Collection.class) {
players = (Player[]) ((Collection<?>) m.invoke(null)).toArray();
} else { } else {
players = ((Player[]) Bukkit.class.getMethod("getOnlinePlayers", new Class<?>[0]).invoke(null)); players = ((Player[]) m.invoke(null));
} }
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) { } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) {
// can never happen // can never happen
players = null;
} }
return players; return players;
} }