mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-26 17:05:01 +00:00
Revamp superadmin list.
TODO: Auto-add.
This commit is contained in:
parent
342ece9934
commit
5f9626921d
@ -2,8 +2,9 @@ package me.StevenLawson.TotalFreedomMod.Commands;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
@ -28,6 +29,47 @@ public class Command_saconfig extends TFM_Command
|
||||
return false;
|
||||
}
|
||||
|
||||
// if (args[0].equalsIgnoreCase("add"))
|
||||
// {
|
||||
// Player p;
|
||||
// try
|
||||
// {
|
||||
// p = getPlayer(args[1]);
|
||||
// }
|
||||
// catch (CantFindPlayerException ex)
|
||||
// {
|
||||
// sender.sendMessage(ex.getMessage());
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// String user_name = p.getName().toLowerCase().trim();
|
||||
// String user_ip = p.getAddress().getAddress().toString().replaceAll("/", "").trim();
|
||||
//
|
||||
// sender.sendMessage(ChatColor.GRAY + "Adding " + user_name + " as a superadmin, with current IP = " + user_ip);
|
||||
//
|
||||
// if (!plugin.superadmins.contains(user_name))
|
||||
// {
|
||||
// plugin.superadmins.add(user_name);
|
||||
// }
|
||||
//
|
||||
// if (!plugin.superadmin_ips.contains(user_ip))
|
||||
// {
|
||||
// plugin.superadmin_ips.add(user_ip);
|
||||
// }
|
||||
//
|
||||
// try
|
||||
// {
|
||||
// FileConfiguration config = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE));
|
||||
// config.set("superadmins", plugin.superadmins);
|
||||
// config.set("superadmin_ips", plugin.superadmin_ips);
|
||||
// config.save(new File(plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE));
|
||||
// }
|
||||
// catch (IOException ex)
|
||||
// {
|
||||
// Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex);
|
||||
// }
|
||||
// }
|
||||
|
||||
if (args[0].equalsIgnoreCase("add"))
|
||||
{
|
||||
Player p;
|
||||
@ -42,30 +84,51 @@ public class Command_saconfig extends TFM_Command
|
||||
}
|
||||
|
||||
String user_name = p.getName().toLowerCase().trim();
|
||||
String user_ip = p.getAddress().getAddress().toString().replaceAll("/", "").trim();
|
||||
String new_ip = p.getAddress().getAddress().toString().replaceAll("/", "").trim();
|
||||
|
||||
sender.sendMessage(ChatColor.GRAY + "Adding " + user_name + " as a superadmin, with current IP = " + user_ip);
|
||||
boolean something_changed = false;
|
||||
|
||||
if (!plugin.superadmins.contains(user_name))
|
||||
{
|
||||
plugin.superadmins.add(user_name);
|
||||
sender.sendMessage("Adding new superadmin: " + user_name);
|
||||
something_changed = true;
|
||||
}
|
||||
|
||||
if (!plugin.superadmin_ips.contains(user_ip))
|
||||
if (!plugin.superadmin_ips.contains(new_ip))
|
||||
{
|
||||
plugin.superadmin_ips.add(user_ip);
|
||||
plugin.superadmin_ips.add(new_ip);
|
||||
sender.sendMessage("Adding new superadmin IP: " + new_ip);
|
||||
something_changed = true;
|
||||
}
|
||||
|
||||
if (!something_changed)
|
||||
{
|
||||
sender.sendMessage("That superadmin/superadmin ip pair already exists. Nothing to change!");
|
||||
}
|
||||
|
||||
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE));
|
||||
|
||||
List<String> user_ips = new ArrayList<String>();
|
||||
if (config.contains(user_name))
|
||||
{
|
||||
user_ips = config.getStringList(user_name);
|
||||
}
|
||||
|
||||
if (!user_ips.contains(new_ip))
|
||||
{
|
||||
user_ips.add(new_ip);
|
||||
}
|
||||
|
||||
config.set(user_name, user_ips);
|
||||
|
||||
try
|
||||
{
|
||||
FileConfiguration sa_config = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE));
|
||||
sa_config.set("superadmins", plugin.superadmins);
|
||||
sa_config.set("superadmin_ips", plugin.superadmin_ips);
|
||||
sa_config.save(new File(plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE));
|
||||
config.save(new File(plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE));
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex);
|
||||
log.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -290,16 +290,18 @@ public class TFM_Util
|
||||
{
|
||||
tfm.superadmin_ips.add(user_ip);
|
||||
|
||||
try
|
||||
{
|
||||
FileConfiguration sa_config = YamlConfiguration.loadConfiguration(new File(tfm.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE));
|
||||
sa_config.set("superadmin_ips", tfm.superadmin_ips);
|
||||
sa_config.save(new File(tfm.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE));
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
Logger.getLogger(TFM_Util.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
log.severe("TODO: Implement add to superadmin list.");
|
||||
|
||||
// try
|
||||
// {
|
||||
// FileConfiguration sa_config = YamlConfiguration.loadConfiguration(new File(tfm.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE));
|
||||
// sa_config.set("superadmin_ips", tfm.superadmin_ips);
|
||||
// sa_config.save(new File(tfm.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE));
|
||||
// }
|
||||
// catch (IOException ex)
|
||||
// {
|
||||
// Logger.getLogger(TFM_Util.class.getName()).log(Level.SEVERE, null, ex);
|
||||
// }
|
||||
}
|
||||
|
||||
return match_found;
|
||||
|
@ -46,13 +46,13 @@ public class TotalFreedomMod extends JavaPlugin
|
||||
{
|
||||
loadMainConfig();
|
||||
loadSuperadminConfig();
|
||||
|
||||
|
||||
registerEventHandlers();
|
||||
|
||||
|
||||
Bukkit.getServer().getScheduler().scheduleAsyncRepeatingTask(this, new TFM_Heartbeat(this), HEARTBEAT_RATE * 20L, HEARTBEAT_RATE * 20L);
|
||||
|
||||
log.log(Level.INFO, "[" + getDescription().getName() + "] - Enabled! - Version: " + getDescription().getVersion() + " by Madgeek1450");
|
||||
|
||||
|
||||
TFM_Util.deleteFolder(new File("./_deleteme"));
|
||||
}
|
||||
|
||||
@ -110,7 +110,7 @@ public class TotalFreedomMod extends JavaPlugin
|
||||
{
|
||||
sender.sendMessage(ChatColor.RED + "Command Error: " + ex.getMessage());
|
||||
}
|
||||
|
||||
|
||||
dispatcher = null;
|
||||
}
|
||||
catch (Throwable ex)
|
||||
@ -168,38 +168,62 @@ public class TotalFreedomMod extends JavaPlugin
|
||||
|
||||
public List<String> superadmins = new ArrayList<String>();
|
||||
public List<String> superadmin_ips = new ArrayList<String>();
|
||||
|
||||
// public void loadSuperadminConfig()
|
||||
// {
|
||||
// TFM_Util.createDefaultConfiguration(SUPERADMIN_FILE, this, getFile());
|
||||
// FileConfiguration config = YamlConfiguration.loadConfiguration(new File(getDataFolder(), SUPERADMIN_FILE));
|
||||
//
|
||||
// superadmins = new ArrayList<String>();
|
||||
// List<String> superadmins_temp = config.getStringList("superadmins");
|
||||
// if (superadmins_temp == null || superadmins_temp.isEmpty())
|
||||
// {
|
||||
// superadmins.add("Madgeek1450");
|
||||
// superadmins.add("markbyron");
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// for (String admin_name : superadmins_temp)
|
||||
// {
|
||||
// superadmins.add(admin_name.toLowerCase().trim());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// superadmin_ips = new ArrayList<String>();
|
||||
// List<String> superadmin_ips_temp = config.getStringList("superadmin_ips");
|
||||
// if (superadmin_ips_temp == null || superadmin_ips_temp.isEmpty())
|
||||
// {
|
||||
// superadmin_ips.add("127.0.0.1");
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// for (String admin_ip : superadmin_ips_temp)
|
||||
// {
|
||||
// superadmin_ips.add(admin_ip.toLowerCase().trim());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
public void loadSuperadminConfig()
|
||||
{
|
||||
TFM_Util.createDefaultConfiguration(SUPERADMIN_FILE, this, getFile());
|
||||
FileConfiguration sa_config = YamlConfiguration.loadConfiguration(new File(getDataFolder(), SUPERADMIN_FILE));
|
||||
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(getDataFolder(), SUPERADMIN_FILE));
|
||||
|
||||
superadmins = new ArrayList<String>();
|
||||
List<String> superadmins_temp = (List<String>) sa_config.getList("superadmins", null);
|
||||
if (superadmins_temp == null || superadmins_temp.isEmpty())
|
||||
{
|
||||
superadmins.add("Madgeek1450");
|
||||
superadmins.add("markbyron");
|
||||
}
|
||||
else
|
||||
{
|
||||
for (String admin_name : superadmins_temp)
|
||||
{
|
||||
superadmins.add(admin_name.toLowerCase().trim());
|
||||
}
|
||||
}
|
||||
|
||||
superadmin_ips = new ArrayList<String>();
|
||||
List<String> superadmin_ips_temp = (List<String>) sa_config.getList("superadmin_ips", null);
|
||||
if (superadmin_ips_temp == null || superadmin_ips_temp.isEmpty())
|
||||
|
||||
for (String user : config.getKeys(false))
|
||||
{
|
||||
superadmin_ips.add("127.0.0.1");
|
||||
}
|
||||
else
|
||||
{
|
||||
for (String admin_ip : superadmin_ips_temp)
|
||||
superadmins.add(user.toLowerCase().trim());
|
||||
|
||||
List<String> user_ips = config.getStringList(user);
|
||||
for (String ip : user_ips)
|
||||
{
|
||||
superadmin_ips.add(admin_ip.toLowerCase().trim());
|
||||
ip = ip.toLowerCase().trim();
|
||||
if (!superadmin_ips.contains(ip))
|
||||
{
|
||||
superadmin_ips.add(ip);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -208,11 +232,11 @@ public class TotalFreedomMod extends JavaPlugin
|
||||
private final TFM_BlockListener blockListener = new TFM_BlockListener(this);
|
||||
private final TFM_PlayerListener playerListener = new TFM_PlayerListener(this);
|
||||
private final TFM_WeatherListener weatherListener = new TFM_WeatherListener(this);
|
||||
|
||||
|
||||
private void registerEventHandlers()
|
||||
{
|
||||
PluginManager pm = this.getServer().getPluginManager();
|
||||
|
||||
|
||||
pm.registerEvent(Event.Type.ENTITY_EXPLODE, entityListener, Event.Priority.High, this);
|
||||
pm.registerEvent(Event.Type.ENTITY_COMBUST, entityListener, Event.Priority.High, this);
|
||||
pm.registerEvent(Event.Type.ENTITY_DAMAGE, entityListener, Event.Priority.High, this);
|
||||
@ -231,7 +255,7 @@ public class TotalFreedomMod extends JavaPlugin
|
||||
pm.registerEvent(Event.Type.PLAYER_KICK, playerListener, Event.Priority.Monitor, this);
|
||||
pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener, Event.Priority.Monitor, this);
|
||||
pm.registerEvent(Event.Type.PLAYER_JOIN, playerListener, Event.Priority.Monitor, this);
|
||||
|
||||
|
||||
pm.registerEvent(Event.Type.WEATHER_CHANGE, weatherListener, Event.Priority.High, this);
|
||||
pm.registerEvent(Event.Type.THUNDER_CHANGE, weatherListener, Event.Priority.High, this);
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
superadmins:
|
||||
- Madgeek1450
|
||||
- markbyron
|
||||
superadmin_ips:
|
||||
madgeek1450:
|
||||
- 127.0.0.1
|
||||
- 8.8.8.8
|
||||
markbyron:
|
||||
- 74.125.224.72
|
||||
- 8.8.4.4
|
||||
|
Loading…
Reference in New Issue
Block a user