mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2025-06-29 19:46:42 +00:00
Many changes for TFM 5.0
Improved admin system Improved Rank system Implemented config converter Improved command handling Updated Aero
This commit is contained in:
@ -5,7 +5,7 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.pravian.aero.base.ConfigLoadable;
|
||||
import net.pravian.aero.base.ConfigSavable;
|
||||
@ -26,10 +26,10 @@ public class Admin implements ConfigLoadable, ConfigSavable, Validatable
|
||||
private String name;
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean activated = true;
|
||||
private boolean active = true;
|
||||
@Getter
|
||||
@Setter
|
||||
private PlayerRank rank = PlayerRank.SUPER_ADMIN;
|
||||
private Rank rank = Rank.SUPER_ADMIN;
|
||||
@Getter
|
||||
private final List<String> ips = Lists.newArrayList();
|
||||
@Getter
|
||||
@ -62,7 +62,7 @@ public class Admin implements ConfigLoadable, ConfigSavable, Validatable
|
||||
.append("- Last Login: ").append(FUtil.dateToString(lastLogin)).append("\n")
|
||||
.append("- Custom Login Message: ").append(loginMessage).append("\n")
|
||||
.append("- Rank: ").append(rank.getName()).append("\n")
|
||||
.append("- Is Activated: ").append(activated);
|
||||
.append("- Is Active: ").append(active);
|
||||
|
||||
return output.toString();
|
||||
}
|
||||
@ -79,8 +79,8 @@ public class Admin implements ConfigLoadable, ConfigSavable, Validatable
|
||||
public void loadFrom(ConfigurationSection cs)
|
||||
{
|
||||
name = cs.getString("username", configKey);
|
||||
activated = cs.getBoolean("active", true);
|
||||
rank = PlayerRank.findRank(cs.getString("rank"));
|
||||
active = cs.getBoolean("active", true);
|
||||
rank = Rank.findRank(cs.getString("rank"));
|
||||
ips.clear();
|
||||
ips.addAll(cs.getStringList("ips"));
|
||||
lastLogin = FUtil.stringToDate(cs.getString("last_login"));
|
||||
@ -92,18 +92,23 @@ public class Admin implements ConfigLoadable, ConfigSavable, Validatable
|
||||
{
|
||||
Validate.isTrue(isValid(), "Could not save admin entry: " + name + ". Entry not valid!");
|
||||
cs.set("username", name);
|
||||
cs.set("active", activated);
|
||||
cs.set("active", active);
|
||||
cs.set("rank", rank.toString());
|
||||
cs.set("ips", Lists.newArrayList(ips));
|
||||
cs.set("last_login", FUtil.dateToString(lastLogin));
|
||||
cs.set("login_message", loginMessage);
|
||||
}
|
||||
|
||||
public boolean isAtLeast(PlayerRank pRank)
|
||||
public boolean isAtLeast(Rank pRank)
|
||||
{
|
||||
return rank.isAtLeast(pRank);
|
||||
}
|
||||
|
||||
public boolean hasLoginMessage()
|
||||
{
|
||||
return loginMessage != null && !loginMessage.isEmpty();
|
||||
}
|
||||
|
||||
// Util IP methods
|
||||
public void addIp(String ip)
|
||||
{
|
||||
|
@ -13,7 +13,7 @@ import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.command.Command_logs;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.pravian.aero.config.YamlConfig;
|
||||
@ -63,6 +63,8 @@ public class AdminList extends FreedomService
|
||||
return isAdmin(player);
|
||||
}
|
||||
}, plugin, ServicePriority.Normal);
|
||||
|
||||
deactivateOldEntries(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -151,7 +153,7 @@ public class AdminList extends FreedomService
|
||||
return false;
|
||||
}
|
||||
|
||||
return admin.getRank().ordinal() >= PlayerRank.SENIOR_ADMIN.ordinal();
|
||||
return admin.getRank().ordinal() >= Rank.SENIOR_ADMIN.ordinal();
|
||||
}
|
||||
|
||||
public Admin getAdmin(CommandSender sender)
|
||||
@ -297,7 +299,7 @@ public class AdminList extends FreedomService
|
||||
|
||||
for (Admin admin : allAdmins.values())
|
||||
{
|
||||
if (!admin.isActivated())
|
||||
if (!admin.isActive())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@ -347,85 +349,11 @@ public class AdminList extends FreedomService
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* public void addAdmin(OfflinePlayer player)
|
||||
* {
|
||||
* final String name = player.getName().toLowerCase();
|
||||
* final String ip = TFM_Util.getIp(player);
|
||||
* final boolean canSuperIp = !TFM_MainConfig.getList(TFM_ConfigEntry.NOADMIN_IPS).contains(ip);
|
||||
*
|
||||
* if (nameTable.containsKey(name))
|
||||
* {
|
||||
* final Admin superadmin = nameTable.;
|
||||
* superadmin.setActivated(true);
|
||||
*
|
||||
* if (player.isOnline())
|
||||
* {
|
||||
* superadmin.setLastLogin(new Date());
|
||||
*
|
||||
* if (ip != null && canSuperIp)
|
||||
* {
|
||||
* superadmin.addIp(ip);
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* save();
|
||||
* updateTables();
|
||||
* return;
|
||||
* }
|
||||
*
|
||||
* if (ip == null)
|
||||
* {
|
||||
* TFM_Log.severe("Could not add superadmin: " + TFM_Util.formatPlayer(player));
|
||||
* TFM_Log.severe("Could not retrieve IP!");
|
||||
* return;
|
||||
* }
|
||||
*
|
||||
* if (!canSuperIp)
|
||||
* {
|
||||
* TFM_Log.warning("Could not add superadmin: " + TFM_Util.formatPlayer(player));
|
||||
* TFM_Log.warning("IP " + ip + " may not be supered.");
|
||||
* return;
|
||||
* }
|
||||
*
|
||||
* final Admin superadmin = new Admin(
|
||||
* uuid,
|
||||
* player.getName(),
|
||||
* new Date(),
|
||||
* "",
|
||||
* false,
|
||||
* false,
|
||||
* true);
|
||||
* superadmin.addIp(ip);
|
||||
*
|
||||
* nameTable.put(uuid, superadmin);
|
||||
*
|
||||
* updateTables();
|
||||
* }
|
||||
*
|
||||
* public void removeAdmin(OfflinePlayer player)
|
||||
* {
|
||||
* final UUID uuid = TFM_UuidManager.getUniqueId(player);
|
||||
*
|
||||
* if (!nameTable.containsKey(uuid))
|
||||
* {
|
||||
* TFM_Log.warning("Could not remove admin: " + TFM_Util.formatPlayer(player));
|
||||
* TFM_Log.warning("Player is not an admin!");
|
||||
* return;
|
||||
* }
|
||||
*
|
||||
* final Admin superadmin = nameTable.get(uuid);
|
||||
* superadmin.setActivated(false);
|
||||
* Command_logs.deactivateSuperadmin(superadmin);
|
||||
*
|
||||
* updateTables();
|
||||
* }
|
||||
*/
|
||||
public void deactivateOldEntries(boolean verbose)
|
||||
{
|
||||
for (Admin admin : allAdmins.values())
|
||||
{
|
||||
if (!admin.isActivated() || admin.getRank() == PlayerRank.SENIOR_ADMIN)
|
||||
if (!admin.isActive() || admin.getRank().isAtLeast(Rank.SENIOR_ADMIN))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@ -440,10 +368,10 @@ public class AdminList extends FreedomService
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
FUtil.adminAction("TotalFreedomMod", "Deactivating superadmin " + admin.getName() + ", inactive for " + lastLoginHours + " hours.", true);
|
||||
FUtil.adminAction("TotalFreedomMod", "Deactivating superadmin " + admin.getName() + ", inactive for " + lastLoginHours + " hours", true);
|
||||
}
|
||||
|
||||
admin.setActivated(false);
|
||||
admin.setActive(false);
|
||||
Command_logs.deactivateSuperadmin(admin);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user