mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-26 17:05:01 +00:00
More superadmin list updates.
This commit is contained in:
parent
6e266fcff2
commit
5845283bad
@ -1,7 +1,9 @@
|
||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_Superadmin;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
@ -18,67 +20,111 @@ public class Command_saconfig extends TFM_Command
|
||||
if (args[0].equals("list"))
|
||||
{
|
||||
sender.sendMessage(ChatColor.GOLD + "Superadmins: " + StringUtils.join(TFM_SuperadminList.getSuperadminNames(), ", "));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!senderIsConsole)
|
||||
{
|
||||
sender.sendMessage(ChatColor.GRAY + "This command may only be used from the console.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[0].equals("clean"))
|
||||
{
|
||||
TFM_Util.adminAction(sender.getName(), "Cleaning superadmin list.", true);
|
||||
TFM_SuperadminList.cleanSuperadminList(true);
|
||||
sender.sendMessage(ChatColor.GOLD + "Superadmins: " + StringUtils.join(TFM_SuperadminList.getSuperadminNames(), ", "));
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!senderIsConsole)
|
||||
{
|
||||
sender.sendMessage(ChatColor.GRAY + "This command may only be used from the console.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length < 2)
|
||||
else if (args.length == 2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("add"))
|
||||
{
|
||||
Player p;
|
||||
try
|
||||
if (!senderIsConsole)
|
||||
{
|
||||
p = getPlayer(args[1]);
|
||||
}
|
||||
catch (CantFindPlayerException ex)
|
||||
{
|
||||
sender.sendMessage(ex.getMessage());
|
||||
sender.sendMessage(ChatColor.GRAY + "This command may only be used from the console.");
|
||||
return true;
|
||||
}
|
||||
|
||||
TFM_Util.adminAction(sender.getName(), "Adding " + p.getName() + " to the superadmin list.", true);
|
||||
|
||||
TFM_SuperadminList.addSuperadmin(p);
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("delete") || args[0].equalsIgnoreCase("del") || args[0].equalsIgnoreCase("remove"))
|
||||
{
|
||||
String target_name = args[1];
|
||||
|
||||
try
|
||||
if (args[0].equalsIgnoreCase("add"))
|
||||
{
|
||||
target_name = getPlayer(target_name).getName();
|
||||
Player p = null;
|
||||
String admin_name = null;
|
||||
|
||||
try
|
||||
{
|
||||
p = getPlayer(args[1]);
|
||||
}
|
||||
catch (CantFindPlayerException ex)
|
||||
{
|
||||
TFM_Superadmin superadmin = TFM_SuperadminList.getAdminEntry(args[1].toLowerCase());
|
||||
if (superadmin != null)
|
||||
{
|
||||
admin_name = superadmin.getName();
|
||||
}
|
||||
else
|
||||
{
|
||||
sender.sendMessage(ex.getMessage());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (p != null)
|
||||
{
|
||||
TFM_Util.adminAction(sender.getName(), "Adding " + p.getName() + " to the superadmin list.", true);
|
||||
TFM_SuperadminList.addSuperadmin(p);
|
||||
}
|
||||
else if (admin_name != null)
|
||||
{
|
||||
TFM_Util.adminAction(sender.getName(), "Adding " + admin_name + " to the superadmin list.", true);
|
||||
TFM_SuperadminList.addSuperadmin(admin_name);
|
||||
}
|
||||
}
|
||||
catch (CantFindPlayerException ex)
|
||||
else if (args[0].equalsIgnoreCase("delete") || args[0].equalsIgnoreCase("del") || args[0].equalsIgnoreCase("remove"))
|
||||
{
|
||||
if (!TFM_SuperadminList.isSeniorAdmin(sender))
|
||||
{
|
||||
sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
|
||||
return true;
|
||||
}
|
||||
|
||||
String target_name = args[1];
|
||||
|
||||
try
|
||||
{
|
||||
target_name = getPlayer(target_name).getName();
|
||||
}
|
||||
catch (CantFindPlayerException ex)
|
||||
{
|
||||
}
|
||||
|
||||
if (!TFM_SuperadminList.getSuperadminNames().contains(target_name.toLowerCase()))
|
||||
{
|
||||
sender.sendMessage("Superadmin not found: " + target_name);
|
||||
return true;
|
||||
}
|
||||
|
||||
TFM_Util.adminAction(sender.getName(), "Removing " + target_name + " from the superadmin list.", true);
|
||||
|
||||
TFM_SuperadminList.removeSuperadmin(target_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!TFM_SuperadminList.getSuperadminNames().contains(target_name.toLowerCase()))
|
||||
{
|
||||
sender.sendMessage("Superadmin not found: " + target_name);
|
||||
return true;
|
||||
}
|
||||
|
||||
TFM_Util.adminAction(sender.getName(), "Removing " + target_name + " from the superadmin list.", true);
|
||||
|
||||
TFM_SuperadminList.removeSuperadmin(target_name);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
@ -23,6 +24,7 @@ public class TFM_SuperadminList
|
||||
private static List<String> superadminNames = new ArrayList<String>();
|
||||
private static List<String> superadminIPs = new ArrayList<String>();
|
||||
private static List<String> seniorAdminNames = new ArrayList<String>();
|
||||
private static int clean_threshold_hours = 24 * 7; // 1 Week
|
||||
|
||||
private TFM_SuperadminList()
|
||||
{
|
||||
@ -48,6 +50,8 @@ public class TFM_SuperadminList
|
||||
TFM_Util.createDefaultConfiguration(TotalFreedomMod.SUPERADMIN_FILE, TotalFreedomMod.plugin_file);
|
||||
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE));
|
||||
|
||||
clean_threshold_hours = config.getInt("clean_threshold_hours", clean_threshold_hours);
|
||||
|
||||
if (config.isConfigurationSection("superadmins"))
|
||||
{
|
||||
ConfigurationSection section = config.getConfigurationSection("superadmins");
|
||||
@ -121,6 +125,8 @@ public class TFM_SuperadminList
|
||||
|
||||
YamlConfiguration config = new YamlConfiguration();
|
||||
|
||||
config.set("clean_threshold_hours", clean_threshold_hours);
|
||||
|
||||
Iterator<Entry<String, TFM_Superadmin>> it = superadminList.entrySet().iterator();
|
||||
while (it.hasNext())
|
||||
{
|
||||
@ -366,4 +372,38 @@ public class TFM_SuperadminList
|
||||
{
|
||||
removeSuperadmin(p.getName());
|
||||
}
|
||||
|
||||
public static void cleanSuperadminList(boolean verbose)
|
||||
{
|
||||
try
|
||||
{
|
||||
Iterator<Entry<String, TFM_Superadmin>> it = superadminList.entrySet().iterator();
|
||||
while (it.hasNext())
|
||||
{
|
||||
Entry<String, TFM_Superadmin> pair = it.next();
|
||||
TFM_Superadmin superadmin = pair.getValue();
|
||||
if (superadmin.isActivated() && !superadmin.isSeniorAdmin())
|
||||
{
|
||||
Date last_login = superadmin.getLastLogin();
|
||||
|
||||
long hours_since_login = TimeUnit.HOURS.convert(new Date().getTime() - last_login.getTime(), TimeUnit.MILLISECONDS);
|
||||
|
||||
if (hours_since_login > clean_threshold_hours)
|
||||
{
|
||||
if (verbose)
|
||||
{
|
||||
TFM_Util.adminAction("TotalFreedomSystem", "Deactivating superadmin \"" + superadmin.getName() + "\", inactive for " + hours_since_login + " hours.", true);
|
||||
}
|
||||
|
||||
superadmin.setActivated(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
saveSuperadminList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TFM_Log.severe(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ commands:
|
||||
usage: /<command> <carts>
|
||||
saconfig:
|
||||
description: Owner command - Manage superadmins.
|
||||
usage: /<command> <list | <add|delete> <username>>
|
||||
usage: /<command> <list | clean | <add|delete> <username>>
|
||||
say:
|
||||
description: Broadcasts the given message as the console, includes sender name.
|
||||
usage: /<command> <message>
|
||||
|
@ -1,3 +1,4 @@
|
||||
clean_threshold_hours: 168
|
||||
superadmins:
|
||||
darthsalamon:
|
||||
ips:
|
||||
@ -8,6 +9,7 @@ superadmins:
|
||||
is_senior_admin: true
|
||||
console_aliases:
|
||||
- darth
|
||||
is_activated: true
|
||||
madgeek1450:
|
||||
ips:
|
||||
- 127.0.0.1
|
||||
@ -17,6 +19,7 @@ superadmins:
|
||||
is_senior_admin: true
|
||||
console_aliases:
|
||||
- madgeek
|
||||
is_activated: false
|
||||
markbyron:
|
||||
ips:
|
||||
- 74.125.224.72
|
||||
@ -25,3 +28,4 @@ superadmins:
|
||||
custom_login_message: the &downer&b.
|
||||
is_senior_admin: true
|
||||
console_aliases: []
|
||||
is_activated: true
|
||||
|
Loading…
Reference in New Issue
Block a user