TotalFreedomMod/src/main/java/me/totalfreedom/totalfreedommod/command/Command_saconfig.java

313 lines
9.8 KiB
Java
Raw Normal View History

package me.totalfreedom.totalfreedommod.command;
2019-01-29 04:57:41 +00:00
import java.util.ArrayList;
2019-01-28 01:49:07 +00:00
import java.util.Arrays;
2019-01-29 04:57:41 +00:00
import java.util.Collections;
import java.util.Date;
2019-01-28 01:49:07 +00:00
import java.util.List;
import me.totalfreedom.totalfreedommod.admin.Admin;
2019-04-21 00:16:00 +00:00
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
2020-09-12 19:42:12 +00:00
import me.totalfreedom.totalfreedommod.discord.Discord;
import me.totalfreedom.totalfreedommod.player.FPlayer;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.OP, source = SourceType.BOTH)
@CommandParameters(description = "List, add, remove, or set the rank of admins, clean or reload the admin list, or view admin information.", usage = "/<command> <list | clean | reload | | setrank <username> <rank> | <add | remove | info> <username>>", aliases = "slconfig")
public class Command_saconfig extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length < 1)
{
return false;
}
switch (args[0])
{
case "list":
{
msg("Admins: " + StringUtils.join(plugin.al.getAdminNames(), ", "), ChatColor.GOLD);
return true;
}
case "clean":
{
2020-07-20 02:10:51 +00:00
checkConsole();
checkRank(Rank.SENIOR_ADMIN);
FUtil.adminAction(sender.getName(), "Cleaning the admin list", true);
plugin.al.deactivateOldEntries(true);
msg("Admins: " + StringUtils.join(plugin.al.getAdminNames(), ", "), ChatColor.GOLD);
return true;
}
case "reload":
{
checkRank(Rank.SENIOR_ADMIN);
FUtil.adminAction(sender.getName(), "Reloading the admin list", true);
plugin.al.load();
msg("Admin list reloaded!");
return true;
}
case "setrank":
{
2020-07-20 02:10:51 +00:00
checkConsole();
checkRank(Rank.SENIOR_ADMIN);
TotalFreedomMod Electrum Version 5.0 This TotalFreedomMod release implements many changes. Most notably, the internals have been completely revamped. TotalFreedomMod now relies on the Aero library for core mechanics such as command handling and services. Another important change is the UUID system. In TotalFreedomMod Electrum, it has been completely removed. The core reason for this is that the system as a whole was very bugged. Additionally, it did not solve the primary reason for its conception: preserving player data when the player changes their username. This is because TotalFreedomMod servers usually run in offline-mode. This meaning that some of the players joining do not have a registerd Mojang UUID whatsoever. All in all, the UUID system was buggy, and it did not fix the reason it was implemented, so it has been completely removed. The admin list and the ban list now use usernames and IPs again. Lastly, many smaller changes have been implemented. Due to the amount of changes, they have not been named individualy. Please refer to the issues below for more details. Fixes #342 Fixes #350 Fixes #380 Fixes #684 Fixes #704 Fixes #716 Fixes #735 Fixes #745 Fixes #784 Fixes #765 Fixes #791 Fixes #805 Fixes #826 Fixes #883 Fixes #1524 Fixes #1534 Fixes #1536 Fixes #1538 Fixes #1545 Fixes #1546 Fixes #1568 Fixes #1627 Resolves #403 Resolves #435 Resolves #597 Resolves #603 Resolves #628 Resolves #690 Resolves #708 Resolves #747 Resolves #748 Resolves #749 Resolves #764 Resolves #767 Resolves #782 Resolves #809 Resolves #803 Resolves #811 Resolves #813 Resolves #830 Resolves #848 Resolves #856 Resolves #876 Resolves #908 Resolves #992 Resolves #1018 Resolves #1432 Resolves #1446 Resolves #1494 Resolves #1501 Resolves #1526 Resolves #1540 Resolves #1550 Resolves #1560 Resolves #1561 Resolves #1578 Resolves #1613
2016-05-12 19:40:39 +00:00
if (args.length < 3)
{
return false;
}
Rank rank = Rank.findRank(args[2]);
TotalFreedomMod Electrum Version 5.0 This TotalFreedomMod release implements many changes. Most notably, the internals have been completely revamped. TotalFreedomMod now relies on the Aero library for core mechanics such as command handling and services. Another important change is the UUID system. In TotalFreedomMod Electrum, it has been completely removed. The core reason for this is that the system as a whole was very bugged. Additionally, it did not solve the primary reason for its conception: preserving player data when the player changes their username. This is because TotalFreedomMod servers usually run in offline-mode. This meaning that some of the players joining do not have a registerd Mojang UUID whatsoever. All in all, the UUID system was buggy, and it did not fix the reason it was implemented, so it has been completely removed. The admin list and the ban list now use usernames and IPs again. Lastly, many smaller changes have been implemented. Due to the amount of changes, they have not been named individualy. Please refer to the issues below for more details. Fixes #342 Fixes #350 Fixes #380 Fixes #684 Fixes #704 Fixes #716 Fixes #735 Fixes #745 Fixes #784 Fixes #765 Fixes #791 Fixes #805 Fixes #826 Fixes #883 Fixes #1524 Fixes #1534 Fixes #1536 Fixes #1538 Fixes #1545 Fixes #1546 Fixes #1568 Fixes #1627 Resolves #403 Resolves #435 Resolves #597 Resolves #603 Resolves #628 Resolves #690 Resolves #708 Resolves #747 Resolves #748 Resolves #749 Resolves #764 Resolves #767 Resolves #782 Resolves #809 Resolves #803 Resolves #811 Resolves #813 Resolves #830 Resolves #848 Resolves #856 Resolves #876 Resolves #908 Resolves #992 Resolves #1018 Resolves #1432 Resolves #1446 Resolves #1494 Resolves #1501 Resolves #1526 Resolves #1540 Resolves #1550 Resolves #1560 Resolves #1561 Resolves #1578 Resolves #1613
2016-05-12 19:40:39 +00:00
if (rank == null)
{
2020-07-20 02:10:51 +00:00
msg("Unknown rank: " + args[2]);
TotalFreedomMod Electrum Version 5.0 This TotalFreedomMod release implements many changes. Most notably, the internals have been completely revamped. TotalFreedomMod now relies on the Aero library for core mechanics such as command handling and services. Another important change is the UUID system. In TotalFreedomMod Electrum, it has been completely removed. The core reason for this is that the system as a whole was very bugged. Additionally, it did not solve the primary reason for its conception: preserving player data when the player changes their username. This is because TotalFreedomMod servers usually run in offline-mode. This meaning that some of the players joining do not have a registerd Mojang UUID whatsoever. All in all, the UUID system was buggy, and it did not fix the reason it was implemented, so it has been completely removed. The admin list and the ban list now use usernames and IPs again. Lastly, many smaller changes have been implemented. Due to the amount of changes, they have not been named individualy. Please refer to the issues below for more details. Fixes #342 Fixes #350 Fixes #380 Fixes #684 Fixes #704 Fixes #716 Fixes #735 Fixes #745 Fixes #784 Fixes #765 Fixes #791 Fixes #805 Fixes #826 Fixes #883 Fixes #1524 Fixes #1534 Fixes #1536 Fixes #1538 Fixes #1545 Fixes #1546 Fixes #1568 Fixes #1627 Resolves #403 Resolves #435 Resolves #597 Resolves #603 Resolves #628 Resolves #690 Resolves #708 Resolves #747 Resolves #748 Resolves #749 Resolves #764 Resolves #767 Resolves #782 Resolves #809 Resolves #803 Resolves #811 Resolves #813 Resolves #830 Resolves #848 Resolves #856 Resolves #876 Resolves #908 Resolves #992 Resolves #1018 Resolves #1432 Resolves #1446 Resolves #1494 Resolves #1501 Resolves #1526 Resolves #1540 Resolves #1550 Resolves #1560 Resolves #1561 Resolves #1578 Resolves #1613
2016-05-12 19:40:39 +00:00
return true;
}
if (rank.isConsole())
{
msg("You cannot set players to a console rank");
return true;
}
2020-09-28 03:17:01 +00:00
if (!rank.isAtLeast(Rank.ADMIN))
{
msg("Rank must be Admin or higher.", ChatColor.RED);
return true;
}
Admin admin = plugin.al.getEntryByName(args[1]);
if (admin == null)
{
msg("Unknown admin: " + args[1]);
return true;
}
FUtil.adminAction(sender.getName(), "Setting " + admin.getName() + "'s rank to " + rank.getName(), true);
TotalFreedomMod Electrum Version 5.0 This TotalFreedomMod release implements many changes. Most notably, the internals have been completely revamped. TotalFreedomMod now relies on the Aero library for core mechanics such as command handling and services. Another important change is the UUID system. In TotalFreedomMod Electrum, it has been completely removed. The core reason for this is that the system as a whole was very bugged. Additionally, it did not solve the primary reason for its conception: preserving player data when the player changes their username. This is because TotalFreedomMod servers usually run in offline-mode. This meaning that some of the players joining do not have a registerd Mojang UUID whatsoever. All in all, the UUID system was buggy, and it did not fix the reason it was implemented, so it has been completely removed. The admin list and the ban list now use usernames and IPs again. Lastly, many smaller changes have been implemented. Due to the amount of changes, they have not been named individualy. Please refer to the issues below for more details. Fixes #342 Fixes #350 Fixes #380 Fixes #684 Fixes #704 Fixes #716 Fixes #735 Fixes #745 Fixes #784 Fixes #765 Fixes #791 Fixes #805 Fixes #826 Fixes #883 Fixes #1524 Fixes #1534 Fixes #1536 Fixes #1538 Fixes #1545 Fixes #1546 Fixes #1568 Fixes #1627 Resolves #403 Resolves #435 Resolves #597 Resolves #603 Resolves #628 Resolves #690 Resolves #708 Resolves #747 Resolves #748 Resolves #749 Resolves #764 Resolves #767 Resolves #782 Resolves #809 Resolves #803 Resolves #811 Resolves #813 Resolves #830 Resolves #848 Resolves #856 Resolves #876 Resolves #908 Resolves #992 Resolves #1018 Resolves #1432 Resolves #1446 Resolves #1494 Resolves #1501 Resolves #1526 Resolves #1540 Resolves #1550 Resolves #1560 Resolves #1561 Resolves #1578 Resolves #1613
2016-05-12 19:40:39 +00:00
admin.setRank(rank);
plugin.al.save(admin);
Player player = getPlayer(admin.getName());
2018-03-03 04:29:08 +00:00
if (player != null)
{
plugin.rm.updateDisplay(player);
}
2019-04-21 00:16:00 +00:00
if (plugin.dc.enabled && ConfigEntry.DISCORD_ROLE_SYNC.getBoolean())
{
Discord.syncRoles(admin, plugin.pl.getData(admin.getName()).getDiscordID());
2019-04-21 00:16:00 +00:00
}
plugin.ptero.updateAccountStatus(admin);
2020-08-08 05:51:09 +00:00
msg("Set " + admin.getName() + "'s rank to " + rank.getName());
return true;
}
case "info":
{
if (args.length < 2)
{
return false;
}
2020-09-28 03:17:01 +00:00
checkRank(Rank.ADMIN);
Admin admin = plugin.al.getEntryByName(args[1]);
if (admin == null)
{
final Player player = getPlayer(args[1]);
if (player != null)
{
admin = plugin.al.getAdmin(player);
}
}
if (admin == null)
{
msg("Admin not found: " + args[1]);
}
else
{
msg(admin.toString());
}
return true;
}
case "add":
{
if (args.length < 2)
{
return false;
}
2020-07-20 02:10:51 +00:00
checkConsole();
2020-09-28 03:17:01 +00:00
checkRank(Rank.ADMIN);
// Player already admin?
final Player player = getPlayer(args[1]);
if (player == null)
{
msg(FreedomCommand.PLAYER_NOT_FOUND);
return true;
}
if (plugin.al.isAdmin(player))
{
msg("That player is already an admin.");
return true;
}
// Find the old admin entry
String name = player.getName();
Admin admin = null;
for (Admin loopAdmin : plugin.al.getAllAdmins())
{
if (loopAdmin.getName().equalsIgnoreCase(name) || loopAdmin.getIps().contains(FUtil.getIp(player)))
{
admin = loopAdmin;
break;
}
}
if (admin == null) // New admin
{
FUtil.adminAction(sender.getName(), "Adding " + player.getName() + " to the admin list", true);
admin = new Admin(player);
2019-04-21 00:16:00 +00:00
plugin.al.addAdmin(admin);
2020-05-29 10:14:21 +00:00
plugin.rm.updateDisplay(player);
}
else // Existing admin
{
FUtil.adminAction(sender.getName(), "Re-adding " + player.getName() + " to the admin list", true);
admin.addIp(FUtil.getIp(player));
admin.setActive(true);
admin.setLastLogin(new Date());
plugin.al.save(admin);
plugin.al.updateTables();
plugin.rm.updateDisplay(player);
2019-04-21 00:16:00 +00:00
if (plugin.dc.enabled && ConfigEntry.DISCORD_ROLE_SYNC.getBoolean())
{
Discord.syncRoles(admin, plugin.pl.getData(player).getDiscordID());
2019-04-21 00:16:00 +00:00
}
}
plugin.ptero.updateAccountStatus(admin);
final FPlayer fPlayer = plugin.pl.getPlayer(player);
if (fPlayer.getFreezeData().isFrozen())
{
fPlayer.getFreezeData().setFrozen(false);
msg(player, "You have been unfrozen.");
}
2018-03-03 04:29:08 +00:00
if (!player.isOp())
{
player.setOp(true);
Right, so this change applies only to commands. For the sake of code consistency, I tried to change as many as possible to use `FreedomCommand.msg` instead of `CommandSender.sendMessage` for their messages. Here are a list of the files containing those changes: * Command_adminworld.java * Command_adventure.java * Command_banip.java * Command_blockedit.java * Command_blockpvp.java * Command_cage.java * Command_cartsit.java * Command_clearchat.java * Command_clearinventory.java * Command_commandlist.java * Command_creative.java * Command_deop.java * Command_deopall.java * Command_dispfill.java * Command_doom.java * Command_gcmd.java * Command_hubworld.java * Command_inspect.java * Command_list.java * Command_lockup.java * Command_manageshop.java * Command_manuallyverify.java * Command_masterbuilderworld.java * Command_mbconfig.java * Command_moblimiter.java * Command_mp44.java * Command_mute.java * Command_nickfilter.java * Command_op.java * Command_opall.java * Command_opme.java * Command_potion.java (Also corrected the inconsistent "player not found" message's color) * Command_rank.java * Command_ride.java * Command_saconfig.java * Command_scare.java * Command_setplayerlimit.java * Command_settotalvotes.java * Command_smite.java * Command_spectator.java * Command_survival.java * Command_unblockcmd.java * Command_uncage.java * Command_unmute.java * Command_verifynoadmin.java Here are some commands I added functionality to: * Command_dispfill.java: Added some code that hooks into the CoreProtect API to log the items being removed from and added into the dispensers. * Command_setlever.java: Added some code that hooks into the CoreProtect API to log the levers being interacted with. Here's a command I fixed a critical bug in: * Command_setlever.java
2021-04-05 23:13:26 +00:00
msg(player, YOU_ARE_OP);
}
return true;
}
case "remove":
{
if (args.length < 2)
{
return false;
}
2020-07-20 02:10:51 +00:00
checkConsole();
2020-09-28 03:17:01 +00:00
checkRank(Rank.ADMIN);
Player player = getPlayer(args[1]);
Admin admin = player != null ? plugin.al.getAdmin(player) : plugin.al.getEntryByName(args[1]);
String adminName = admin.getName();
if (admin == null)
{
msg("Admin not found: " + args[1]);
return true;
}
FUtil.adminAction(sender.getName(), "Removing " + admin.getName() + " from the admin list", true);
admin.setActive(false);
2020-08-09 03:20:06 +00:00
plugin.al.save(admin);
plugin.al.updateTables();
2018-03-03 04:29:08 +00:00
if (player != null)
{
plugin.rm.updateDisplay(player);
}
2019-04-21 00:16:00 +00:00
if (plugin.dc.enabled && ConfigEntry.DISCORD_ROLE_SYNC.getBoolean())
{
Discord.syncRoles(admin, plugin.pl.getData(adminName).getDiscordID());
2019-04-21 00:16:00 +00:00
}
plugin.ptero.updateAccountStatus(admin);
2020-08-08 05:51:09 +00:00
return true;
}
default:
{
return false;
}
}
}
2019-01-28 01:49:07 +00:00
2019-01-29 04:57:41 +00:00
@Override
public List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args)
2019-01-28 01:49:07 +00:00
{
2020-07-01 03:21:44 +00:00
if (args.length == 1)
2019-01-29 04:57:41 +00:00
{
2020-07-01 03:21:44 +00:00
List<String> arguments = new ArrayList<>();
arguments.add("list");
if (plugin.al.isAdmin(sender))
2019-01-29 04:57:41 +00:00
{
2020-07-01 03:21:44 +00:00
arguments.add("info");
arguments.add("add");
arguments.add("remove");
2019-01-29 04:57:41 +00:00
}
if (plugin.al.isSeniorAdmin(sender))
2019-01-29 04:57:41 +00:00
{
2020-07-01 03:21:44 +00:00
arguments.add("reload");
arguments.add("clean");
arguments.add("setrank");
2019-01-29 04:57:41 +00:00
}
2020-07-01 03:21:44 +00:00
return arguments;
}
if (args.length == 2 && (args[0].equals("add") || args[0].equals("remove") || args[0].equals("setrank") || args[0].equals("info")))
{
return FUtil.getPlayerList();
}
if (args.length == 3 && args[0].equals("setrank"))
{
2020-11-10 02:16:26 +00:00
return Arrays.asList("ADMIN", "SENIOR_ADMIN");
2019-01-29 04:57:41 +00:00
}
return Collections.emptyList();
}
2020-08-09 03:20:06 +00:00
}