Fix bugs in purge classes, cleanup

- OfflinePlayer objects were never mapped to names
- Essentials purge was run even if setting was disabled
- Console user saw messages twice
- Misc: trivial field reorderings, change DefaultPermission to be null safe
- Permissions: do not expose PermissionHandler just to get its type
This commit is contained in:
ljacqu 2016-06-19 17:56:50 +02:00
parent a0abe3d19d
commit ff2f8a63bb
6 changed files with 18 additions and 25 deletions

View File

@ -234,11 +234,6 @@ public class AuthMe extends JavaPlugin {
// Some statically injected things
initializer.register(PlayerCache.class, PlayerCache.getInstance());
// Note ljacqu 20160612: Instantiate LimboCache first to make sure it is instantiated
// (because sometimes it's used via LimboCache.getInstance())
// Once LimboCache#getInstance() no longer exists this can be removed!
initializer.get(LimboCache.class);
permsMan = initializer.get(PermissionsManager.class);
bukkitService = initializer.get(BukkitService.class);
pluginHooks = initializer.get(PluginHooks.class);
@ -296,8 +291,7 @@ public class AuthMe extends JavaPlugin {
ConsoleLogger.info("AuthMe " + this.getDescription().getVersion() + " correctly enabled!");
// If server is using PermissionsBukkit, print a warning that some features may not be supported
if (permsMan.isEnabled() &&
permsMan.getHandler().getPermissionSystem() == PermissionsSystemType.PERMISSIONS_BUKKIT) {
if (PermissionsSystemType.PERMISSIONS_BUKKIT.equals(permsMan.getPermissionSystem())) {
ConsoleLogger.info("Warning! This server uses PermissionsBukkit for permissions! Some permissions features may not be supported!");
}
@ -497,7 +491,7 @@ public class AuthMe extends JavaPlugin {
ConsoleLogger.showError("THE SERVER IS GOING TO SHUT DOWN AS DEFINED IN THE CONFIGURATION!");
getServer().shutdown();
} else {
getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
getServer().getPluginManager().disablePlugin(this);
}
}

View File

@ -11,11 +11,11 @@ public class LimboPlayer {
private final String name;
private final boolean fly;
private Location loc = null;
private final boolean operator;
private final String group;
private final Location loc;
private BukkitTask timeoutTask = null;
private BukkitTask messageTask = null;
private boolean operator = false;
private String group;
public LimboPlayer(String name, Location loc, boolean operator,
String group, boolean fly) {

View File

@ -1,6 +1,5 @@
package fr.xephi.authme.permission;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
/**
@ -30,8 +29,8 @@ public enum DefaultPermission {
@Override
public boolean evaluateOffline(String name) {
// TODO Gnat008 20160617: Is this safe?
return Bukkit.getOfflinePlayer(name).isOp();
// TODO #784: Check if there is an elegant way to evaluate OP status
return false;
}
},

View File

@ -217,12 +217,12 @@ public class PermissionsManager {
}
/**
* Get the current permissions system handler.
* Return the permissions system that is hooked into.
*
* @return The permissions system handler.
* @return The permissions system, or null.
*/
public PermissionHandler getHandler() {
return handler;
public PermissionsSystemType getPermissionSystem() {
return isEnabled() ? handler.getPermissionSystem() : null;
}
/**

View File

@ -15,6 +15,7 @@ import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
@ -238,7 +239,7 @@ public class PurgeService implements Reloadable {
* @param cleared List of String
*/
synchronized void purgeEssentials(Set<OfflinePlayer> cleared) {
if (!settings.getProperty(PurgeSettings.REMOVE_ESSENTIALS_FILES) && !pluginHooks.isEssentialsAvailable()) {
if (!settings.getProperty(PurgeSettings.REMOVE_ESSENTIALS_FILES)) {
return;
}
@ -281,7 +282,8 @@ public class PurgeService implements Reloadable {
private static void logAndSendMessage(CommandSender sender, String message) {
ConsoleLogger.info(message);
if (sender != null) {
// Make sure sender is not console user, which will see the message from ConsoleLogger already
if (sender != null && !(sender instanceof ConsoleCommandSender)) {
sender.sendMessage(message);
}
}

View File

@ -14,11 +14,10 @@ import java.util.UUID;
public class PurgeTask extends BukkitRunnable {
private PurgeService purgeService;
//how many players we should check for each tick
private static final int INTERVALL_CHECK = 5;
private final PurgeService purgeService;
private final UUID sender;
private final Set<String> toPurge;
@ -52,15 +51,14 @@ public class PurgeTask extends BukkitRunnable {
Set<String> namePortion = new HashSet<String>(INTERVALL_CHECK);
for (int i = 0; i < INTERVALL_CHECK; i++) {
int nextPosition = (currentPage * INTERVALL_CHECK) + i;
if (offlinePlayers.length >= nextPosition) {
if (offlinePlayers.length <= nextPosition) {
//no more offline players on this page
break;
}
OfflinePlayer offlinePlayer = offlinePlayers[nextPosition];
String offlineName = offlinePlayer.getName();
//remove to speed up later lookups
if (toPurge.remove(offlineName.toLowerCase())) {
if (toPurge.remove(offlinePlayer.getName().toLowerCase())) {
playerPortion.add(offlinePlayer);
namePortion.add(offlinePlayer.getName());
}