Nettoyage automatique des données de joueurs Essentials et PermissionsEx qui ne sont pas inscrits

This commit is contained in:
Marc Baloup 2015-01-19 01:11:20 -05:00
parent 88cc48d99a
commit c777545158
8 changed files with 102 additions and 2 deletions

View File

@ -15,5 +15,6 @@
<classpathentry kind="lib" path="lib/PandacraftAuth.jar" sourcepath="R:/Dropbox/wspace_java_minecraft/xAuth.src"/> <classpathentry kind="lib" path="lib/PandacraftAuth.jar" sourcepath="R:/Dropbox/wspace_java_minecraft/xAuth.src"/>
<classpathentry kind="lib" path="lib/Essentials-Pre2.13.1.2.jar"/> <classpathentry kind="lib" path="lib/Essentials-Pre2.13.1.2.jar"/>
<classpathentry kind="lib" path="lib/worldguard-5.9.jar"/> <classpathentry kind="lib" path="lib/worldguard-5.9.jar"/>
<classpathentry kind="lib" path="lib/PermissionsEx.jar"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

BIN
lib/PermissionsEx.jar Normal file

Binary file not shown.

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<jardesc> <jardesc>
<jar path="PandacraftUtils/jar_export/PandacraftUtils-2.10.jar"/> <jar path="PandacraftUtils/jar_export/PandacraftUtils-2.11.jar"/>
<options buildIfNeeded="true" compress="true" descriptionLocation="/PandacraftUtils/make_jar.jardesc" exportErrors="true" exportWarnings="true" includeDirectoryEntries="false" overwrite="false" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/> <options buildIfNeeded="true" compress="true" descriptionLocation="/PandacraftUtils/make_jar.jardesc" exportErrors="true" exportWarnings="true" includeDirectoryEntries="false" overwrite="false" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/>
<storedRefactorings deprecationInfo="true" structuralOnly="false"/> <storedRefactorings deprecationInfo="true" structuralOnly="false"/>
<selectedProjects/> <selectedProjects/>

View File

@ -33,3 +33,8 @@ cubos:
# séparé avec des point-virgules # séparé avec des point-virgules
worlds: Survival worlds: Survival
cleaner:
users_cleaner_group: default

View File

@ -1,6 +1,6 @@
name: PandacraftUtils name: PandacraftUtils
main: net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils main: net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils
version: 2.10 version: 2.11

View File

@ -81,6 +81,8 @@ public class ConfigManager {
CuboCommand_worlds = Arrays.asList(configFile.getString("cubos.worlds").split(";")); CuboCommand_worlds = Arrays.asList(configFile.getString("cubos.worlds").split(";"));
UsersCleaner_users_cleaner_group = configFile.getString("cleaner.users_cleaner_group");
initChatAnalysisBadWord(); initChatAnalysisBadWord();
initCommandAlias(); initCommandAlias();
@ -105,6 +107,15 @@ public class ConfigManager {
/*
* Users cleaner
*/
public String UsersCleaner_users_cleaner_group;
/* /*
* Configuration AFK * Configuration AFK
*/ */

View File

@ -92,6 +92,13 @@ public class PandacraftUtils extends JavaPlugin {
calculatorManager = new CalculatorManager(this); calculatorManager = new CalculatorManager(this);
serverPingListener = new PacketOutServerInfoListener(this); serverPingListener = new PacketOutServerInfoListener(this);
getServer().getScheduler().runTaskLater(this, new Runnable() {
@Override public void run() { new PlayerDataCleaner(instance); }
}, 1);
} }

View File

@ -0,0 +1,76 @@
package net.mc_pandacraft.java.plugin.pandacraftutils;
import java.util.Set;
import net.mc_pandacraft.java.plugin.pandacraftutils.plugin_interface.EssentialsInterface;
import ru.tehkode.permissions.PermissionUser;
import ru.tehkode.permissions.bukkit.PermissionsEx;
import com.earth2me.essentials.User;
import com.earth2me.essentials.UserMap;
public class PlayerDataCleaner {
private PandacraftUtils plugin;
public PlayerDataCleaner(PandacraftUtils pl) {
plugin = pl;
try {
clean();
} catch (Throwable e) {
e.printStackTrace();
}
}
private void clean() {
String group_to_remove = ConfigManager.getInstance().UsersCleaner_users_cleaner_group;
// essentials players
UserMap players = EssentialsInterface.getPlugin().getUserMap();
plugin.getLogger().info("Group to remove : "+group_to_remove);
plugin.getLogger().info("Running Essentials players autoremove ..");
if (players == null) return;
plugin.getLogger().info("There are "+players.getUniqueUsers()+" players files in Essentials/userdata");
Set<String> users = players.getAllUniqueUsers();
for (String su : users) {
User u = players.getUser(su);
if (u.getBase() != null && u.getBase().isOnline()) continue;
if (!group_to_remove.equalsIgnoreCase(u.getGroup())) continue;
plugin.getLogger().info("Essentials players autoremove : "+su);
players.getUserFile(su).delete();
}
players.reloadConfig();
// permissions_ex players
PermissionUser[] pUsers = PermissionsEx.getPermissionManager().getUsers(group_to_remove);
plugin.getLogger().info("Running PermissionsEx players autoremove ..");
plugin.getLogger().info("There are "+pUsers.length+" players in 'default' group");
for (PermissionUser pUser : pUsers) {
if (pUser == null) continue;
if (pUser.getGroupsNames().length != 1) continue;
if (!pUser.getGroupsNames()[0].equalsIgnoreCase(group_to_remove)) continue;
plugin.getLogger().info("PermissionsEx players autoremove : "+pUser.getName());
pUser.remove();
}
PermissionsEx.getPlugin().reloadConfig();
}
}