mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 01:05:38 +00:00
[Bleeding] TotalFreedomMod 5.0
Mass Refractoring, now uses me.totalfreedom.totalfreedommod as package Uses Aero https://github.com/Pravian/Aero Revamped command system Remove all TFM_ prefixes Revamp rank system Use new service based system Cleanup
This commit is contained in:
parent
a7a2db15d6
commit
848f103afa
@ -1,5 +1,5 @@
|
|||||||
annotation.processing.enabled=true
|
annotation.processing.enabled=true
|
||||||
annotation.processing.enabled.in.editor=false
|
annotation.processing.enabled.in.editor=true
|
||||||
annotation.processing.processors.list=
|
annotation.processing.processors.list=
|
||||||
annotation.processing.run.all.processors=true
|
annotation.processing.run.all.processors=true
|
||||||
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
|
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
|
||||||
@ -51,7 +51,9 @@ javac.classpath=\
|
|||||||
${libs.SpigotServer.classpath}:\
|
${libs.SpigotServer.classpath}:\
|
||||||
${libs.TF-Essentials.classpath}:\
|
${libs.TF-Essentials.classpath}:\
|
||||||
${libs.TF-WorldEdit.classpath}:\
|
${libs.TF-WorldEdit.classpath}:\
|
||||||
${libs.BukkitTelnet.classpath}
|
${libs.BukkitTelnet.classpath}:\
|
||||||
|
${libs.Aero.classpath}:\
|
||||||
|
${libs.Lombok.classpath}
|
||||||
# Space-separated list of extra javac options
|
# Space-separated list of extra javac options
|
||||||
javac.compilerargs=-Xlint:unchecked -Xlint:deprecation
|
javac.compilerargs=-Xlint:unchecked -Xlint:deprecation
|
||||||
javac.deprecation=false
|
javac.deprecation=false
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
|
||||||
|
|
||||||
public enum AdminLevel
|
|
||||||
{
|
|
||||||
ALL("All Player Commands"), OP("OP Commands"), SUPER("SuperAdmin Commands"), SENIOR("Senior Admin Commands");
|
|
||||||
//
|
|
||||||
private final String friendlyName;
|
|
||||||
|
|
||||||
private AdminLevel(String friendlyName)
|
|
||||||
{
|
|
||||||
this.friendlyName = friendlyName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFriendlyName()
|
|
||||||
{
|
|
||||||
return friendlyName;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,82 +0,0 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_GameRuleHandler;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_CONSOLE)
|
|
||||||
@CommandParameters(description = "Control mob rezzing parameters.", usage = "/<command> <on|off|setmax <count>|dragon|giant|ghast|slime>")
|
|
||||||
public class Command_moblimiter extends TFM_Command
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
|
||||||
{
|
|
||||||
if (args.length < 1)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("on"))
|
|
||||||
{
|
|
||||||
TFM_ConfigEntry.MOB_LIMITER_ENABLED.setBoolean(true);
|
|
||||||
}
|
|
||||||
else if (args[0].equalsIgnoreCase("off"))
|
|
||||||
{
|
|
||||||
TFM_ConfigEntry.MOB_LIMITER_ENABLED.setBoolean(false);
|
|
||||||
}
|
|
||||||
else if (args[0].equalsIgnoreCase("dragon"))
|
|
||||||
{
|
|
||||||
TFM_ConfigEntry.MOB_LIMITER_DISABLE_DRAGON.setBoolean(!TFM_ConfigEntry.MOB_LIMITER_DISABLE_DRAGON.getBoolean());
|
|
||||||
}
|
|
||||||
else if (args[0].equalsIgnoreCase("giant"))
|
|
||||||
{
|
|
||||||
TFM_ConfigEntry.MOB_LIMITER_DISABLE_GIANT.setBoolean(!TFM_ConfigEntry.MOB_LIMITER_DISABLE_GIANT.getBoolean());
|
|
||||||
}
|
|
||||||
else if (args[0].equalsIgnoreCase("slime"))
|
|
||||||
{
|
|
||||||
TFM_ConfigEntry.MOB_LIMITER_DISABLE_SLIME.setBoolean(!TFM_ConfigEntry.MOB_LIMITER_DISABLE_SLIME.getBoolean());
|
|
||||||
}
|
|
||||||
else if (args[0].equalsIgnoreCase("ghast"))
|
|
||||||
{
|
|
||||||
TFM_ConfigEntry.MOB_LIMITER_DISABLE_GHAST.setBoolean(!TFM_ConfigEntry.MOB_LIMITER_DISABLE_GHAST.getBoolean());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (args.length < 2)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("setmax"))
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
TFM_ConfigEntry.MOB_LIMITER_MAX.setInteger(Math.max(0, Math.min(2000, Integer.parseInt(args[1]))));
|
|
||||||
}
|
|
||||||
catch (NumberFormatException nfex)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TFM_ConfigEntry.MOB_LIMITER_ENABLED.getBoolean())
|
|
||||||
{
|
|
||||||
sender.sendMessage("Moblimiter enabled. Maximum mobcount set to: " + TFM_ConfigEntry.MOB_LIMITER_MAX.getInteger() + ".");
|
|
||||||
|
|
||||||
playerMsg("Dragon: " + (TFM_ConfigEntry.MOB_LIMITER_DISABLE_DRAGON.getBoolean() ? "disabled" : "enabled") + ".");
|
|
||||||
playerMsg("Giant: " + (TFM_ConfigEntry.MOB_LIMITER_DISABLE_GIANT.getBoolean() ? "disabled" : "enabled") + ".");
|
|
||||||
playerMsg("Slime: " + (TFM_ConfigEntry.MOB_LIMITER_DISABLE_SLIME.getBoolean() ? "disabled" : "enabled") + ".");
|
|
||||||
playerMsg("Ghast: " + (TFM_ConfigEntry.MOB_LIMITER_DISABLE_GHAST.getBoolean() ? "disabled" : "enabled") + ".");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
playerMsg("Moblimiter is disabled. No mob restrictions are in effect.");
|
|
||||||
}
|
|
||||||
|
|
||||||
TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.DO_MOB_SPAWNING, !TFM_ConfigEntry.MOB_LIMITER_ENABLED.getBoolean());
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.ONLY_IN_GAME)
|
|
||||||
@CommandParameters(description = "Goto the nether.", usage = "/<command>")
|
|
||||||
public class Command_nether extends TFM_Command
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
|
||||||
{
|
|
||||||
TFM_Util.gotoWorld(sender_p, server.getWorlds().get(0).getName() + "_nether");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_IN_GAME)
|
|
||||||
@CommandParameters(description = "Automatically ops user.", usage = "/<command>")
|
|
||||||
public class Command_opme extends TFM_Command
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
|
||||||
{
|
|
||||||
TFM_Util.adminAction(sender.getName(), "Opping " + sender.getName(), false);
|
|
||||||
sender.setOp(true);
|
|
||||||
sender.sendMessage(TFM_Command.YOU_ARE_OP);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
|
|
||||||
@CommandParameters(description = "Remove various server entities that may cause lag, such as dropped items, minecarts, and boats.", usage = "/<command> <carts>")
|
|
||||||
public class Command_rd extends TFM_Command
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
|
||||||
{
|
|
||||||
TFM_Util.adminAction(sender.getName(), "Removing all server entities.", true);
|
|
||||||
playerMsg((TFM_Util.TFM_EntityWiper.wipeEntities(true, true)) + " entities removed.");
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_ServiceChecker;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_ServiceChecker.ServiceStatus;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.BOTH)
|
|
||||||
@CommandParameters(description = "Shows the status of all Mojang services", usage = "/<command>")
|
|
||||||
public class Command_services extends TFM_Command
|
|
||||||
{
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
|
||||||
{
|
|
||||||
playerMsg("Mojang Services" + ChatColor.WHITE + ":", ChatColor.BLUE);
|
|
||||||
|
|
||||||
for (ServiceStatus service : TFM_ServiceChecker.getAllStatuses())
|
|
||||||
{
|
|
||||||
playerMsg(service.getFormattedStatus());
|
|
||||||
}
|
|
||||||
playerMsg("Version" + ChatColor.WHITE + ": " + TFM_ServiceChecker.getVersion(), ChatColor.DARK_PURPLE);
|
|
||||||
playerMsg("Last Check" + ChatColor.WHITE + ": " + TFM_ServiceChecker.getLastCheck(), ChatColor.DARK_PURPLE);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_ProtectedArea;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_IN_GAME)
|
|
||||||
@CommandParameters(description = "Set world spawnpoint.", usage = "/<command>")
|
|
||||||
public class Command_setspawnworld extends TFM_Command
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
|
||||||
{
|
|
||||||
Location pos = sender_p.getLocation();
|
|
||||||
sender_p.getWorld().setSpawnLocation(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());
|
|
||||||
|
|
||||||
playerMsg("Spawn location for this world set to: " + TFM_Util.formatLocation(sender_p.getWorld().getSpawnLocation()));
|
|
||||||
|
|
||||||
if (TFM_ConfigEntry.PROTECTAREA_ENABLED.getBoolean() && TFM_ConfigEntry.PROTECTAREA_SPAWNPOINTS.getBoolean())
|
|
||||||
{
|
|
||||||
TFM_ProtectedArea.addProtectedArea("spawn_" + sender_p.getWorld().getName(), pos, TFM_ConfigEntry.PROTECTAREA_RADIUS.getDouble());
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,114 +0,0 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Admin;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Player;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_PlayerList;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_UuidManager;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_UuidManager.TFM_UuidResolver;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE)
|
|
||||||
@CommandParameters(description = "Provides uuid tools", usage = "/<command> <purge | recalculate>")
|
|
||||||
public class Command_uuid extends TFM_Command
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
|
||||||
{
|
|
||||||
if (args.length != 1)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ("purge".equals(args[0]))
|
|
||||||
{
|
|
||||||
playerMsg("Purged " + TFM_UuidManager.purge() + " cached UUIDs.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ("recalculate".equals(args[0]))
|
|
||||||
{
|
|
||||||
playerMsg("Recalculating UUIDs...");
|
|
||||||
|
|
||||||
// Playerlist uuids
|
|
||||||
final Set<TFM_Player> players = TFM_PlayerList.getAllPlayers();
|
|
||||||
final List<String> names = new ArrayList<String>();
|
|
||||||
|
|
||||||
for (TFM_Player player : players)
|
|
||||||
{
|
|
||||||
names.add(player.getLastLoginName());
|
|
||||||
}
|
|
||||||
|
|
||||||
final Map<String, UUID> playerUuids = new TFM_UuidResolver(names).call();
|
|
||||||
|
|
||||||
int updated = 0;
|
|
||||||
for (String name : playerUuids.keySet())
|
|
||||||
{
|
|
||||||
for (TFM_Player player : players)
|
|
||||||
{
|
|
||||||
if (!player.getLastLoginName().equalsIgnoreCase(name))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (player.getUniqueId().equals(playerUuids.get(name)))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
TFM_PlayerList.setUniqueId(player, playerUuids.get(name));
|
|
||||||
TFM_UuidManager.rawSetUUID(name, playerUuids.get(name));
|
|
||||||
updated++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
playerMsg("Recalculated " + updated + " player UUIDs");
|
|
||||||
names.clear();
|
|
||||||
|
|
||||||
// Adminlist UUIDs
|
|
||||||
final Set<TFM_Admin> admins = TFM_AdminList.getAllAdmins();
|
|
||||||
for (TFM_Admin admin : admins)
|
|
||||||
{
|
|
||||||
names.add(admin.getLastLoginName());
|
|
||||||
}
|
|
||||||
|
|
||||||
final Map<String, UUID> adminUuids = new TFM_UuidResolver(names).call();
|
|
||||||
|
|
||||||
updated = 0;
|
|
||||||
for (String name : adminUuids.keySet())
|
|
||||||
{
|
|
||||||
for (TFM_Admin admin : admins)
|
|
||||||
{
|
|
||||||
if (!admin.getLastLoginName().equalsIgnoreCase(name))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (admin.getUniqueId().equals(adminUuids.get(name)))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
TFM_AdminList.setUuid(admin, admin.getUniqueId(), adminUuids.get(name));
|
|
||||||
TFM_UuidManager.rawSetUUID(name, adminUuids.get(name));
|
|
||||||
updated++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
playerMsg("Recalculated " + updated + " admin UUIDs");
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,190 +0,0 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Log;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public abstract class TFM_Command
|
|
||||||
{
|
|
||||||
public static final String MSG_NO_PERMS = ChatColor.YELLOW + "You do not have permission to use this command.";
|
|
||||||
public static final String YOU_ARE_OP = ChatColor.YELLOW + "You are now op!";
|
|
||||||
public static final String YOU_ARE_NOT_OP = ChatColor.YELLOW + "You are no longer op!";
|
|
||||||
public static final String NOT_FROM_CONSOLE = "This command may not be used from the console.";
|
|
||||||
public static final String PLAYER_NOT_FOUND = ChatColor.GRAY + "Player not found!";
|
|
||||||
protected TotalFreedomMod plugin;
|
|
||||||
protected Server server;
|
|
||||||
private CommandSender commandSender;
|
|
||||||
private Class<?> commandClass;
|
|
||||||
|
|
||||||
public TFM_Command()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract public boolean run(final CommandSender sender, final Player sender_p, final Command cmd, final String commandLabel, final String[] args, final boolean senderIsConsole);
|
|
||||||
|
|
||||||
public void setup(final TotalFreedomMod plugin, final CommandSender commandSender, final Class<?> commandClass)
|
|
||||||
{
|
|
||||||
this.plugin = plugin;
|
|
||||||
this.server = plugin.getServer();
|
|
||||||
this.commandSender = commandSender;
|
|
||||||
this.commandClass = commandClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void playerMsg(final CommandSender sender, final String message, final ChatColor color)
|
|
||||||
{
|
|
||||||
if (sender == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
sender.sendMessage(color + message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void playerMsg(final String message, final ChatColor color)
|
|
||||||
{
|
|
||||||
playerMsg(commandSender, message, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void playerMsg(final CommandSender sender, final String message)
|
|
||||||
{
|
|
||||||
playerMsg(sender, message, ChatColor.GRAY);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void playerMsg(final String message)
|
|
||||||
{
|
|
||||||
playerMsg(commandSender, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean senderHasPermission()
|
|
||||||
{
|
|
||||||
final CommandPermissions permissions = commandClass.getAnnotation(CommandPermissions.class);
|
|
||||||
|
|
||||||
if (permissions == null)
|
|
||||||
{
|
|
||||||
TFM_Log.warning(commandClass.getName() + " is missing permissions annotation.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isSuper = TFM_AdminList.isSuperAdmin(commandSender);
|
|
||||||
boolean isSenior = false;
|
|
||||||
|
|
||||||
if (isSuper)
|
|
||||||
{
|
|
||||||
isSenior = TFM_AdminList.isSeniorAdmin(commandSender);
|
|
||||||
}
|
|
||||||
|
|
||||||
final AdminLevel level = permissions.level();
|
|
||||||
final SourceType source = permissions.source();
|
|
||||||
final boolean blockHostConsole = permissions.blockHostConsole();
|
|
||||||
|
|
||||||
if (!(commandSender instanceof Player))
|
|
||||||
{
|
|
||||||
if (source == SourceType.ONLY_IN_GAME)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (level == AdminLevel.SENIOR && !isSenior)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (blockHostConsole && TFM_Util.isFromHostConsole(commandSender.getName()))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
final Player senderPlayer = (Player) commandSender;
|
|
||||||
|
|
||||||
if (source == SourceType.ONLY_CONSOLE)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (level == AdminLevel.SENIOR)
|
|
||||||
{
|
|
||||||
if (!isSenior)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!TFM_PlayerData.getPlayerData(senderPlayer).isSuperadminIdVerified())
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (level == AdminLevel.SUPER && !isSuper)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (level == AdminLevel.OP && !senderPlayer.isOp())
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Player getPlayer(final String partialName)
|
|
||||||
{
|
|
||||||
return getPlayer(partialName, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Player getPlayer(final String partialName, final boolean exact)
|
|
||||||
{
|
|
||||||
if (partialName == null || partialName.isEmpty())
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
final Collection<? extends Player> players = server.getOnlinePlayers();
|
|
||||||
|
|
||||||
// Check exact matches first.
|
|
||||||
for (final Player player : players)
|
|
||||||
{
|
|
||||||
if (partialName.equalsIgnoreCase(player.getName()))
|
|
||||||
{
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (exact)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Then check partial matches in name.
|
|
||||||
for (final Player player : players)
|
|
||||||
{
|
|
||||||
if (player.getName().toLowerCase().contains(partialName.toLowerCase()))
|
|
||||||
{
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Then check partial matches in display name.
|
|
||||||
for (final Player player : players)
|
|
||||||
{
|
|
||||||
if (player.getDisplayName().toLowerCase().contains(partialName.toLowerCase()))
|
|
||||||
{
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,81 +0,0 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Log;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class TFM_CommandHandler
|
|
||||||
{
|
|
||||||
public static final String COMMAND_PATH = TFM_Command.class.getPackage().getName(); // "me.StevenLawson.TotalFreedomMod.Commands";
|
|
||||||
public static final String COMMAND_PREFIX = "Command_";
|
|
||||||
|
|
||||||
public static boolean handleCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
|
|
||||||
{
|
|
||||||
final Player playerSender;
|
|
||||||
final boolean senderIsConsole;
|
|
||||||
|
|
||||||
if (sender instanceof Player)
|
|
||||||
{
|
|
||||||
senderIsConsole = false;
|
|
||||||
playerSender = (Player) sender;
|
|
||||||
|
|
||||||
TFM_Log.info(String.format("[PLAYER_COMMAND] %s (%s): /%s %s",
|
|
||||||
playerSender.getName(),
|
|
||||||
ChatColor.stripColor(playerSender.getDisplayName()),
|
|
||||||
commandLabel,
|
|
||||||
StringUtils.join(args, " ")), true);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
senderIsConsole = true;
|
|
||||||
playerSender = null;
|
|
||||||
|
|
||||||
TFM_Log.info(String.format("[CONSOLE_COMMAND] %s: /%s %s",
|
|
||||||
sender.getName(),
|
|
||||||
commandLabel,
|
|
||||||
StringUtils.join(args, " ")), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
final TFM_Command dispatcher;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
final ClassLoader classLoader = TotalFreedomMod.class.getClassLoader();
|
|
||||||
dispatcher = (TFM_Command) classLoader.loadClass(String.format("%s.%s%s",
|
|
||||||
COMMAND_PATH,
|
|
||||||
COMMAND_PREFIX,
|
|
||||||
cmd.getName().toLowerCase())).newInstance();
|
|
||||||
dispatcher.setup(TotalFreedomMod.plugin, sender, dispatcher.getClass());
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
TFM_Log.severe("Could not load command: " + cmd.getName());
|
|
||||||
TFM_Log.severe(ex);
|
|
||||||
|
|
||||||
sender.sendMessage(ChatColor.RED + "Command Error! Could not load command: " + cmd.getName());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!dispatcher.senderHasPermission())
|
|
||||||
{
|
|
||||||
sender.sendMessage(TFM_Command.MSG_NO_PERMS);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return dispatcher.run(sender, playerSender, cmd, commandLabel, args, senderIsConsole);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
TFM_Log.severe("Command Error: " + commandLabel);
|
|
||||||
TFM_Log.severe(ex);
|
|
||||||
sender.sendMessage(ChatColor.RED + "Command Error: " + ex.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,336 +0,0 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.security.CodeSource;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
import java.util.zip.ZipEntry;
|
|
||||||
import java.util.zip.ZipInputStream;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Log;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandException;
|
|
||||||
import org.bukkit.command.CommandMap;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.command.PluginIdentifiableCommand;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
public class TFM_CommandLoader
|
|
||||||
{
|
|
||||||
public static final Pattern COMMAND_PATTERN;
|
|
||||||
private static final List<TFM_CommandInfo> COMMAND_LIST;
|
|
||||||
|
|
||||||
static
|
|
||||||
{
|
|
||||||
COMMAND_PATTERN = Pattern.compile(TFM_CommandHandler.COMMAND_PATH.replace('.', '/') + "/(" + TFM_CommandHandler.COMMAND_PREFIX + "[^\\$]+)\\.class");
|
|
||||||
COMMAND_LIST = new ArrayList<TFM_CommandInfo>();
|
|
||||||
}
|
|
||||||
|
|
||||||
private TFM_CommandLoader()
|
|
||||||
{
|
|
||||||
throw new AssertionError();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void scan()
|
|
||||||
{
|
|
||||||
CommandMap commandMap = getCommandMap();
|
|
||||||
if (commandMap == null)
|
|
||||||
{
|
|
||||||
TFM_Log.severe("Error loading commandMap.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
COMMAND_LIST.clear();
|
|
||||||
COMMAND_LIST.addAll(getCommands());
|
|
||||||
|
|
||||||
for (TFM_CommandInfo commandInfo : COMMAND_LIST)
|
|
||||||
{
|
|
||||||
TFM_DynamicCommand dynamicCommand = new TFM_DynamicCommand(commandInfo);
|
|
||||||
|
|
||||||
Command existing = commandMap.getCommand(dynamicCommand.getName());
|
|
||||||
if (existing != null)
|
|
||||||
{
|
|
||||||
unregisterCommand(existing, commandMap);
|
|
||||||
}
|
|
||||||
|
|
||||||
commandMap.register(TotalFreedomMod.plugin.getDescription().getName(), dynamicCommand);
|
|
||||||
}
|
|
||||||
|
|
||||||
TFM_Log.info("TFM commands loaded.");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void unregisterCommand(String commandName)
|
|
||||||
{
|
|
||||||
CommandMap commandMap = getCommandMap();
|
|
||||||
if (commandMap != null)
|
|
||||||
{
|
|
||||||
Command command = commandMap.getCommand(commandName.toLowerCase());
|
|
||||||
if (command != null)
|
|
||||||
{
|
|
||||||
unregisterCommand(command, commandMap);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void unregisterCommand(Command command, CommandMap commandMap)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
command.unregister(commandMap);
|
|
||||||
HashMap<String, Command> knownCommands = getKnownCommands(commandMap);
|
|
||||||
if (knownCommands != null)
|
|
||||||
{
|
|
||||||
knownCommands.remove(command.getName());
|
|
||||||
for (String alias : command.getAliases())
|
|
||||||
{
|
|
||||||
knownCommands.remove(alias);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
TFM_Log.severe(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static CommandMap getCommandMap()
|
|
||||||
{
|
|
||||||
final Object commandMap = TFM_Util.getField(Bukkit.getServer().getPluginManager(), "commandMap");
|
|
||||||
if (commandMap != null)
|
|
||||||
{
|
|
||||||
if (commandMap instanceof CommandMap)
|
|
||||||
{
|
|
||||||
return (CommandMap) commandMap;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static HashMap<String, Command> getKnownCommands(CommandMap commandMap)
|
|
||||||
{
|
|
||||||
Object knownCommands = TFM_Util.getField(commandMap, "knownCommands");
|
|
||||||
if (knownCommands != null)
|
|
||||||
{
|
|
||||||
if (knownCommands instanceof HashMap)
|
|
||||||
{
|
|
||||||
return (HashMap<String, Command>) knownCommands;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<TFM_CommandInfo> getCommands()
|
|
||||||
{
|
|
||||||
List<TFM_CommandInfo> commandList = new ArrayList<TFM_CommandInfo>();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
CodeSource codeSource = TotalFreedomMod.class.getProtectionDomain().getCodeSource();
|
|
||||||
if (codeSource != null)
|
|
||||||
{
|
|
||||||
ZipInputStream zip = new ZipInputStream(codeSource.getLocation().openStream());
|
|
||||||
ZipEntry zipEntry;
|
|
||||||
while ((zipEntry = zip.getNextEntry()) != null)
|
|
||||||
{
|
|
||||||
String entryName = zipEntry.getName();
|
|
||||||
Matcher matcher = COMMAND_PATTERN.matcher(entryName);
|
|
||||||
if (matcher.find())
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Class<?> commandClass = Class.forName(TFM_CommandHandler.COMMAND_PATH + "." + matcher.group(1));
|
|
||||||
|
|
||||||
CommandPermissions commandPermissions = commandClass.getAnnotation(CommandPermissions.class);
|
|
||||||
CommandParameters commandParameters = commandClass.getAnnotation(CommandParameters.class);
|
|
||||||
|
|
||||||
if (commandPermissions != null && commandParameters != null)
|
|
||||||
{
|
|
||||||
TFM_CommandInfo commandInfo = new TFM_CommandInfo(
|
|
||||||
commandClass,
|
|
||||||
matcher.group(1).split("_")[1],
|
|
||||||
commandPermissions.level(),
|
|
||||||
commandPermissions.source(),
|
|
||||||
commandPermissions.blockHostConsole(),
|
|
||||||
commandParameters.description(),
|
|
||||||
commandParameters.usage(),
|
|
||||||
commandParameters.aliases());
|
|
||||||
|
|
||||||
commandList.add(commandInfo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (ClassNotFoundException ex)
|
|
||||||
{
|
|
||||||
TFM_Log.severe(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (IOException ex)
|
|
||||||
{
|
|
||||||
TFM_Log.severe(ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
return commandList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class TFM_CommandInfo
|
|
||||||
{
|
|
||||||
private final String commandName;
|
|
||||||
private final Class<?> commandClass;
|
|
||||||
private final AdminLevel level;
|
|
||||||
private final SourceType source;
|
|
||||||
private final boolean blockHostConsole;
|
|
||||||
private final String description;
|
|
||||||
private final String usage;
|
|
||||||
private final List<String> aliases;
|
|
||||||
|
|
||||||
public TFM_CommandInfo(Class<?> commandClass, String commandName, AdminLevel level, SourceType source, boolean blockHostConsole, String description, String usage, String aliases)
|
|
||||||
{
|
|
||||||
this.commandName = commandName;
|
|
||||||
this.commandClass = commandClass;
|
|
||||||
this.level = level;
|
|
||||||
this.source = source;
|
|
||||||
this.blockHostConsole = blockHostConsole;
|
|
||||||
this.description = description;
|
|
||||||
this.usage = usage;
|
|
||||||
this.aliases = ("".equals(aliases) ? new ArrayList<String>() : Arrays.asList(aliases.split(",")));
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getAliases()
|
|
||||||
{
|
|
||||||
return Collections.unmodifiableList(aliases);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Class<?> getCommandClass()
|
|
||||||
{
|
|
||||||
return commandClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCommandName()
|
|
||||||
{
|
|
||||||
return commandName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDescription()
|
|
||||||
{
|
|
||||||
return description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDescriptionPermissioned()
|
|
||||||
{
|
|
||||||
String _description = description;
|
|
||||||
|
|
||||||
switch (this.getLevel())
|
|
||||||
{
|
|
||||||
case SENIOR:
|
|
||||||
_description = "Senior " + (this.getSource() == SourceType.ONLY_CONSOLE ? "Console" : "") + " Command - " + _description;
|
|
||||||
break;
|
|
||||||
case SUPER:
|
|
||||||
_description = "Superadmin Command - " + _description;
|
|
||||||
break;
|
|
||||||
case OP:
|
|
||||||
_description = "OP Command - " + _description;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return _description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AdminLevel getLevel()
|
|
||||||
{
|
|
||||||
return level;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SourceType getSource()
|
|
||||||
{
|
|
||||||
return source;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUsage()
|
|
||||||
{
|
|
||||||
return usage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getBlockHostConsole()
|
|
||||||
{
|
|
||||||
return blockHostConsole;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString()
|
|
||||||
{
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
sb.append("commandName: ").append(commandName);
|
|
||||||
sb.append("\ncommandClass: ").append(commandClass.getName());
|
|
||||||
sb.append("\nlevel: ").append(level);
|
|
||||||
sb.append("\nsource: ").append(source);
|
|
||||||
sb.append("\nblock_host_console: ").append(blockHostConsole);
|
|
||||||
sb.append("\ndescription: ").append(description);
|
|
||||||
sb.append("\nusage: ").append(usage);
|
|
||||||
sb.append("\naliases: ").append(aliases);
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class TFM_DynamicCommand extends Command implements PluginIdentifiableCommand
|
|
||||||
{
|
|
||||||
private final TFM_CommandInfo commandInfo;
|
|
||||||
|
|
||||||
private TFM_DynamicCommand(TFM_CommandInfo commandInfo)
|
|
||||||
{
|
|
||||||
super(commandInfo.getCommandName(), commandInfo.getDescriptionPermissioned(), commandInfo.getUsage(), commandInfo.getAliases());
|
|
||||||
|
|
||||||
this.commandInfo = commandInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean execute(CommandSender sender, String commandLabel, String[] args)
|
|
||||||
{
|
|
||||||
boolean success = false;
|
|
||||||
|
|
||||||
if (!getPlugin().isEnabled())
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
success = getPlugin().onCommand(sender, this, commandLabel, args);
|
|
||||||
}
|
|
||||||
catch (Throwable ex)
|
|
||||||
{
|
|
||||||
throw new CommandException("Unhandled exception executing command '" + commandLabel + "' in plugin " + getPlugin().getDescription().getFullName(), ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!success && getUsage().length() > 0)
|
|
||||||
{
|
|
||||||
for (String line : getUsage().replace("<command>", commandLabel).split("\n"))
|
|
||||||
{
|
|
||||||
sender.sendMessage(line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Plugin getPlugin()
|
|
||||||
{
|
|
||||||
return TotalFreedomMod.plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TFM_CommandInfo getCommandInfo()
|
|
||||||
{
|
|
||||||
return commandInfo;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,155 +0,0 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.HTTPD;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.Commands.AdminLevel;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader.TFM_DynamicCommand;
|
|
||||||
import static me.StevenLawson.TotalFreedomMod.HTTPD.HTMLGenerationTools.heading;
|
|
||||||
import static me.StevenLawson.TotalFreedomMod.HTTPD.HTMLGenerationTools.paragraph;
|
|
||||||
import static org.apache.commons.lang3.StringEscapeUtils.escapeHtml4;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandMap;
|
|
||||||
import org.bukkit.command.PluginIdentifiableCommand;
|
|
||||||
|
|
||||||
public class Module_help extends TFM_HTTPD_Module
|
|
||||||
{
|
|
||||||
public Module_help(NanoHTTPD.HTTPSession session)
|
|
||||||
{
|
|
||||||
super(session);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getBody()
|
|
||||||
{
|
|
||||||
StringBuilder responseBody = new StringBuilder();
|
|
||||||
|
|
||||||
CommandMap commandMap;
|
|
||||||
HashMap<String, Command> knownCommands;
|
|
||||||
if ((commandMap = TFM_CommandLoader.getCommandMap()) == null
|
|
||||||
|| (knownCommands = TFM_CommandLoader.getKnownCommands(commandMap)) == null)
|
|
||||||
{
|
|
||||||
return paragraph("Error loading commands.");
|
|
||||||
}
|
|
||||||
|
|
||||||
responseBody
|
|
||||||
.append(heading("Command Help", 1))
|
|
||||||
.append(paragraph(
|
|
||||||
"This page is an automatically generated listing of all plugin commands that are currently live on the server. "
|
|
||||||
+ "Please note that it does not include vanilla server commands."));
|
|
||||||
|
|
||||||
final Map<String, List<Command>> commandsByPlugin = new HashMap<String, List<Command>>();
|
|
||||||
|
|
||||||
final Iterator<Map.Entry<String, Command>> itKnownCommands = knownCommands.entrySet().iterator();
|
|
||||||
while (itKnownCommands.hasNext())
|
|
||||||
{
|
|
||||||
final Map.Entry<String, Command> entry = itKnownCommands.next();
|
|
||||||
final String name = entry.getKey();
|
|
||||||
final Command command = entry.getValue();
|
|
||||||
if (name.equalsIgnoreCase(command.getName()))
|
|
||||||
{
|
|
||||||
String pluginName = "Bukkit Default";
|
|
||||||
if (command instanceof PluginIdentifiableCommand)
|
|
||||||
{
|
|
||||||
pluginName = ((PluginIdentifiableCommand) command).getPlugin().getName();
|
|
||||||
}
|
|
||||||
List<Command> pluginCommands = commandsByPlugin.get(pluginName);
|
|
||||||
if (pluginCommands == null)
|
|
||||||
{
|
|
||||||
commandsByPlugin.put(pluginName, pluginCommands = new ArrayList<Command>());
|
|
||||||
}
|
|
||||||
pluginCommands.add(command);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final Iterator<Map.Entry<String, List<Command>>> itCommandsByPlugin = commandsByPlugin.entrySet().iterator();
|
|
||||||
while (itCommandsByPlugin.hasNext())
|
|
||||||
{
|
|
||||||
final Map.Entry<String, List<Command>> entry = itCommandsByPlugin.next();
|
|
||||||
final String pluginName = entry.getKey();
|
|
||||||
final List<Command> commands = entry.getValue();
|
|
||||||
|
|
||||||
Collections.sort(commands, new Comparator<Command>()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public int compare(Command a, Command b)
|
|
||||||
{
|
|
||||||
if (a instanceof TFM_DynamicCommand && b instanceof TFM_DynamicCommand)
|
|
||||||
{
|
|
||||||
String aName = ((TFM_DynamicCommand) a).getCommandInfo().getLevel().name() + a.getName();
|
|
||||||
String bName = ((TFM_DynamicCommand) b).getCommandInfo().getLevel().name() + b.getName();
|
|
||||||
return aName.compareTo(bName);
|
|
||||||
}
|
|
||||||
return a.getName().compareTo(b.getName());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
responseBody.append(heading(pluginName, 2)).append("<ul>\r\n");
|
|
||||||
|
|
||||||
AdminLevel lastTfmCommandLevel = null;
|
|
||||||
for (Command command : commands)
|
|
||||||
{
|
|
||||||
if ("TotalFreedomMod".equals(pluginName))
|
|
||||||
{
|
|
||||||
AdminLevel tfmCommandLevel = ((TFM_DynamicCommand) command).getCommandInfo().getLevel();
|
|
||||||
if (lastTfmCommandLevel == null || lastTfmCommandLevel != tfmCommandLevel)
|
|
||||||
{
|
|
||||||
responseBody.append("</ul>\r\n").append(heading(tfmCommandLevel.getFriendlyName(), 3)).append("<ul>\r\n");
|
|
||||||
}
|
|
||||||
lastTfmCommandLevel = tfmCommandLevel;
|
|
||||||
}
|
|
||||||
responseBody.append(buildDescription(command));
|
|
||||||
}
|
|
||||||
|
|
||||||
responseBody.append("</ul>\r\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
return responseBody.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String buildDescription(Command command)
|
|
||||||
{
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
|
|
||||||
sb.append(
|
|
||||||
"<li><span class=\"commandName\">{$CMD_NAME}</span> - Usage: <span class=\"commandUsage\">{$CMD_USAGE}</span>"
|
|
||||||
.replace("{$CMD_NAME}", escapeHtml4(command.getName().trim()))
|
|
||||||
.replace("{$CMD_USAGE}", escapeHtml4(command.getUsage().trim())));
|
|
||||||
|
|
||||||
if (!command.getAliases().isEmpty())
|
|
||||||
{
|
|
||||||
sb.append(
|
|
||||||
" - Aliases: <span class=\"commandAliases\">{$CMD_ALIASES}</span>"
|
|
||||||
.replace("{$CMD_ALIASES}", escapeHtml4(StringUtils.join(command.getAliases(), ", "))));
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.append(
|
|
||||||
"<br><span class=\"commandDescription\">{$CMD_DESC}</span></li>\r\n"
|
|
||||||
.replace("{$CMD_DESC}", escapeHtml4(command.getDescription().trim())));
|
|
||||||
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getTitle()
|
|
||||||
{
|
|
||||||
return "TotalFreedomMod :: Command Help";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getStyle()
|
|
||||||
{
|
|
||||||
return ".commandName{font-weight:bold;}.commandDescription{padding-left:15px;}li{margin:.15em;padding:.15em;}";
|
|
||||||
}
|
|
||||||
// @Override
|
|
||||||
// public String getScript()
|
|
||||||
// {
|
|
||||||
// return "$(document).ready(function(){console.log(\"Ready\");});";
|
|
||||||
// }
|
|
||||||
}
|
|
@ -1,72 +0,0 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.HTTPD;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class Module_list extends TFM_HTTPD_Module
|
|
||||||
{
|
|
||||||
public Module_list(NanoHTTPD.HTTPSession session)
|
|
||||||
{
|
|
||||||
super(session);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getBody()
|
|
||||||
{
|
|
||||||
final StringBuilder body = new StringBuilder();
|
|
||||||
|
|
||||||
final Collection<? extends Player> onlinePlayers = Bukkit.getOnlinePlayers();
|
|
||||||
|
|
||||||
body.append("<p>There are ").append(onlinePlayers.size()).append("/").append(Bukkit.getMaxPlayers()).append(" players online:</p>\r\n");
|
|
||||||
|
|
||||||
body.append("<ul>\r\n");
|
|
||||||
|
|
||||||
for (Player player : onlinePlayers)
|
|
||||||
{
|
|
||||||
String prefix = "";
|
|
||||||
if (TFM_AdminList.isSuperAdmin(player))
|
|
||||||
{
|
|
||||||
if (TFM_AdminList.isSeniorAdmin(player))
|
|
||||||
{
|
|
||||||
prefix = "[SrA]";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
prefix = "[SA]";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TFM_Util.DEVELOPERS.contains(player.getName()))
|
|
||||||
{
|
|
||||||
prefix = "[Dev]";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (player.getName().equals("markbyron"))
|
|
||||||
{
|
|
||||||
prefix = "[Owner]";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (player.isOp())
|
|
||||||
{
|
|
||||||
prefix = "[OP]";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
body.append("<li>").append(prefix).append(player.getName()).append("</li>\r\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
body.append("</ul>\r\n");
|
|
||||||
|
|
||||||
return body.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getTitle()
|
|
||||||
{
|
|
||||||
return "Total Freedom - Online Users";
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,86 +0,0 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.HTTPD;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.json.simple.JSONArray;
|
|
||||||
import org.json.simple.JSONObject;
|
|
||||||
|
|
||||||
public class Module_players extends TFM_HTTPD_Module
|
|
||||||
{
|
|
||||||
public Module_players(NanoHTTPD.HTTPSession session)
|
|
||||||
{
|
|
||||||
super(session);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public NanoHTTPD.Response getResponse()
|
|
||||||
{
|
|
||||||
final JSONObject responseObject = new JSONObject();
|
|
||||||
|
|
||||||
final JSONArray players = new JSONArray();
|
|
||||||
final JSONArray superadmins = new JSONArray();
|
|
||||||
final JSONArray telnetadmins = new JSONArray();
|
|
||||||
final JSONArray senioradmins = new JSONArray();
|
|
||||||
final JSONArray developers = new JSONArray();
|
|
||||||
|
|
||||||
// All online players
|
|
||||||
for (Player player : TotalFreedomMod.server.getOnlinePlayers())
|
|
||||||
{
|
|
||||||
players.add(player.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Super admins (non-telnet and non-senior)
|
|
||||||
for (UUID superadmin : TFM_AdminList.getSuperUUIDs())
|
|
||||||
{
|
|
||||||
if (TFM_AdminList.getSeniorUUIDs().contains(superadmin))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TFM_AdminList.getTelnetUUIDs().contains(superadmin))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
superadmins.add(getName(superadmin));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Telnet admins (non-senior)
|
|
||||||
for (UUID telnetadmin : TFM_AdminList.getTelnetUUIDs())
|
|
||||||
{
|
|
||||||
if (TFM_AdminList.getSeniorUUIDs().contains(telnetadmin))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
telnetadmins.add(getName(telnetadmin));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Senior admins
|
|
||||||
for (UUID senioradmin : TFM_AdminList.getSeniorUUIDs())
|
|
||||||
{
|
|
||||||
senioradmins.add(getName(senioradmin));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Developers
|
|
||||||
developers.addAll(TFM_Util.DEVELOPERS);
|
|
||||||
|
|
||||||
responseObject.put("players", players);
|
|
||||||
responseObject.put("superadmins", superadmins);
|
|
||||||
responseObject.put("telnetadmins", telnetadmins);
|
|
||||||
responseObject.put("senioradmins", senioradmins);
|
|
||||||
responseObject.put("developers", developers);
|
|
||||||
|
|
||||||
final NanoHTTPD.Response response = new NanoHTTPD.Response(NanoHTTPD.Response.Status.OK, NanoHTTPD.MIME_JSON, responseObject.toString());
|
|
||||||
response.addHeader("Access-Control-Allow-Origin", "*");
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getName(UUID uuid)
|
|
||||||
{
|
|
||||||
return TFM_AdminList.getEntry(uuid).getLastLoginName();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,62 +0,0 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Listener;
|
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_BanManager;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.server.ServerListPingEvent;
|
|
||||||
|
|
||||||
public class TFM_ServerListener implements Listener
|
|
||||||
{
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
|
||||||
public void onServerPing(ServerListPingEvent event)
|
|
||||||
{
|
|
||||||
final String ip = event.getAddress().getHostAddress();
|
|
||||||
|
|
||||||
if (TFM_BanManager.isIpBanned(ip))
|
|
||||||
{
|
|
||||||
event.setMotd(ChatColor.RED + "You are banned.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TFM_ConfigEntry.ADMIN_ONLY_MODE.getBoolean())
|
|
||||||
{
|
|
||||||
event.setMotd(ChatColor.RED + "Server is closed.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Bukkit.hasWhitelist())
|
|
||||||
{
|
|
||||||
event.setMotd(ChatColor.RED + "Whitelist enabled.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Bukkit.getOnlinePlayers().size() >= Bukkit.getMaxPlayers())
|
|
||||||
{
|
|
||||||
event.setMotd(ChatColor.RED + "Server is full.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!TFM_ConfigEntry.SERVER_COLORFUL_MOTD.getBoolean())
|
|
||||||
{
|
|
||||||
event.setMotd(TFM_Util.colorize(TFM_ConfigEntry.SERVER_MOTD.getString()
|
|
||||||
.replace("%mcversion%", TFM_ServerInterface.getVersion())));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Colorful MOTD
|
|
||||||
|
|
||||||
final StringBuilder motd = new StringBuilder();
|
|
||||||
|
|
||||||
for (String word : TFM_ConfigEntry.SERVER_MOTD.getString().replace("%mcversion%", TFM_ServerInterface.getVersion()).split(" "))
|
|
||||||
{
|
|
||||||
motd.append(TFM_Util.randomChatColor()).append(word).append(" ");
|
|
||||||
}
|
|
||||||
|
|
||||||
event.setMotd(TFM_Util.colorize(motd.toString()));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,102 +0,0 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.SQL;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.DatabaseMetaData;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Log;
|
|
||||||
|
|
||||||
public class TFM_SqlUtil
|
|
||||||
{
|
|
||||||
|
|
||||||
public static boolean hasTable(Connection con, String table)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
final DatabaseMetaData dbm = con.getMetaData();
|
|
||||||
final ResultSet tables = dbm.getTables(null, null, table, null);
|
|
||||||
return tables.next();
|
|
||||||
}
|
|
||||||
catch (SQLException ex)
|
|
||||||
{
|
|
||||||
TFM_Log.severe(ex);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ResultSet executeQuery(Connection con, String query)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return con.createStatement().executeQuery(query);
|
|
||||||
}
|
|
||||||
catch (SQLException ex)
|
|
||||||
{
|
|
||||||
TFM_Log.severe(ex);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int updateQuery(Connection con, String query)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return con.createStatement().executeUpdate(query);
|
|
||||||
}
|
|
||||||
catch (SQLException ex)
|
|
||||||
{
|
|
||||||
TFM_Log.severe(ex);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean createTable(Connection con, String name, String fields)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
con.createStatement().execute("CREATE TABLE " + name + " (" + fields + ");");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (SQLException ex)
|
|
||||||
{
|
|
||||||
TFM_Log.severe(ex);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void close(ResultSet result)
|
|
||||||
{
|
|
||||||
if (result == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
result.close();
|
|
||||||
}
|
|
||||||
catch (SQLException ex)
|
|
||||||
{
|
|
||||||
TFM_Log.severe(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean hasData(ResultSet result)
|
|
||||||
{
|
|
||||||
if (result == null)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return result.next();
|
|
||||||
}
|
|
||||||
catch (SQLException ex)
|
|
||||||
{
|
|
||||||
TFM_Log.severe(ex);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,143 +0,0 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.SQL;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Log;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
|
||||||
import me.husky.Database;
|
|
||||||
import me.husky.sqlite.SQLite;
|
|
||||||
|
|
||||||
public class TFM_SqliteDatabase
|
|
||||||
{
|
|
||||||
|
|
||||||
private final Database sql;
|
|
||||||
private final String table;
|
|
||||||
private final String fields;
|
|
||||||
private final List<Statement> statements;
|
|
||||||
|
|
||||||
public TFM_SqliteDatabase(String filename, String table, String fields)
|
|
||||||
{
|
|
||||||
this.sql = new SQLite(TotalFreedomMod.plugin, filename);
|
|
||||||
this.table = table;
|
|
||||||
this.fields = fields;
|
|
||||||
this.statements = new ArrayList<Statement>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Statement addPreparedStatement(String query)
|
|
||||||
{
|
|
||||||
if (sql.checkConnection())
|
|
||||||
{
|
|
||||||
throw new IllegalStateException("Can not add prepared statements after connecting!");
|
|
||||||
}
|
|
||||||
|
|
||||||
final Statement statement = new Statement(query);
|
|
||||||
statements.add(statement);
|
|
||||||
return statement;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public Database db()
|
|
||||||
{
|
|
||||||
return sql;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean connect()
|
|
||||||
{
|
|
||||||
if (sql.checkConnection())
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
final Connection con = sql.openConnection();
|
|
||||||
if (con == null)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!TFM_SqlUtil.hasTable(con, table))
|
|
||||||
{
|
|
||||||
TFM_Log.info("Creating table: " + table);
|
|
||||||
|
|
||||||
if (!TFM_SqlUtil.createTable(con, table, fields))
|
|
||||||
{
|
|
||||||
TFM_Log.severe("Could not create table: " + table);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prepare statements
|
|
||||||
for (Statement statement : statements)
|
|
||||||
{
|
|
||||||
if (!statement.prepare())
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void close()
|
|
||||||
{
|
|
||||||
sql.closeConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int purge()
|
|
||||||
{
|
|
||||||
if (!connect())
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
TFM_Log.warning("Truncating table: " + table);
|
|
||||||
|
|
||||||
final int result = TFM_SqlUtil.updateQuery(sql.getConnection(), "DELETE FROM " + table + ";");
|
|
||||||
|
|
||||||
if (result == -1)
|
|
||||||
{
|
|
||||||
TFM_Log.warning("Could not truncate table: " + table);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public class Statement
|
|
||||||
{
|
|
||||||
private final String query;
|
|
||||||
private PreparedStatement statement;
|
|
||||||
|
|
||||||
private Statement(String query)
|
|
||||||
{
|
|
||||||
this.query = query;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean prepare()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
statement = sql.getConnection().prepareStatement(query);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (SQLException ex)
|
|
||||||
{
|
|
||||||
TFM_Log.severe("Could not prepare statement: " + query);
|
|
||||||
TFM_Log.severe(ex);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void invalidate()
|
|
||||||
{
|
|
||||||
statement = null;
|
|
||||||
statements.remove(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PreparedStatement getStatement()
|
|
||||||
{
|
|
||||||
return statement;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,163 +0,0 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.Config.TFM_MainConfig;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
|
||||||
|
|
||||||
public class TFM_Admin
|
|
||||||
{
|
|
||||||
private final UUID uuid;
|
|
||||||
private String lastLoginName;
|
|
||||||
private final String loginMessage;
|
|
||||||
private final boolean isSeniorAdmin;
|
|
||||||
private final boolean isTelnetAdmin;
|
|
||||||
private final List<String> consoleAliases;
|
|
||||||
private final List<String> ips;
|
|
||||||
private Date lastLogin;
|
|
||||||
private boolean isActivated;
|
|
||||||
|
|
||||||
public TFM_Admin(UUID uuid, String lastLoginName, Date lastLogin, String loginMessage, boolean isTelnetAdmin, boolean isSeniorAdmin, boolean isActivated)
|
|
||||||
{
|
|
||||||
this.uuid = uuid;
|
|
||||||
this.lastLoginName = lastLoginName;
|
|
||||||
this.ips = new ArrayList<String>();
|
|
||||||
this.lastLogin = lastLogin;
|
|
||||||
this.loginMessage = loginMessage;
|
|
||||||
this.isTelnetAdmin = isTelnetAdmin;
|
|
||||||
this.isSeniorAdmin = isSeniorAdmin;
|
|
||||||
this.consoleAliases = new ArrayList<String>();
|
|
||||||
this.isActivated = isActivated;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TFM_Admin(UUID uuid, ConfigurationSection section)
|
|
||||||
{
|
|
||||||
this.uuid = uuid;
|
|
||||||
this.lastLoginName = section.getString("last_login_name");
|
|
||||||
this.ips = section.getStringList("ips");
|
|
||||||
this.lastLogin = TFM_Util.stringToDate(section.getString("last_login", TFM_Util.dateToString(new Date(0L))));
|
|
||||||
this.loginMessage = section.getString("custom_login_message", "");
|
|
||||||
this.isSeniorAdmin = section.getBoolean("is_senior_admin", false);
|
|
||||||
this.isTelnetAdmin = section.getBoolean("is_telnet_admin", false);
|
|
||||||
this.consoleAliases = section.getStringList("console_aliases");
|
|
||||||
this.isActivated = section.getBoolean("is_activated", true);
|
|
||||||
|
|
||||||
for (Iterator<?> it = TFM_MainConfig.getList(TFM_ConfigEntry.NOADMIN_IPS).iterator(); it.hasNext();)
|
|
||||||
{
|
|
||||||
ips.remove((String) it.next());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString()
|
|
||||||
{
|
|
||||||
final StringBuilder output = new StringBuilder();
|
|
||||||
|
|
||||||
output.append("UUID: ").append(uuid.toString()).append("\n");
|
|
||||||
output.append("- Last Login Name: ").append(lastLoginName).append("\n");
|
|
||||||
output.append("- IPs: ").append(StringUtils.join(ips, ", ")).append("\n");
|
|
||||||
output.append("- Last Login: ").append(TFM_Util.dateToString(lastLogin)).append("\n");
|
|
||||||
output.append("- Custom Login Message: ").append(loginMessage).append("\n");
|
|
||||||
output.append("- Is Senior Admin: ").append(isSeniorAdmin).append("\n");
|
|
||||||
output.append("- Is Telnet Admin: ").append(isTelnetAdmin).append("\n");
|
|
||||||
output.append("- Console Aliases: ").append(StringUtils.join(consoleAliases, ", ")).append("\n");
|
|
||||||
output.append("- Is Activated: ").append(isActivated);
|
|
||||||
|
|
||||||
return output.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public UUID getUniqueId()
|
|
||||||
{
|
|
||||||
return uuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLastLoginName(String lastLoginName)
|
|
||||||
{
|
|
||||||
this.lastLoginName = lastLoginName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLastLoginName()
|
|
||||||
{
|
|
||||||
return lastLoginName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getIps()
|
|
||||||
{
|
|
||||||
return Collections.unmodifiableList(ips);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addIp(String ip)
|
|
||||||
{
|
|
||||||
if (!ips.contains(ip))
|
|
||||||
{
|
|
||||||
ips.add(ip);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addIps(List<String> ips)
|
|
||||||
{
|
|
||||||
for (String ip : ips)
|
|
||||||
{
|
|
||||||
addIp(ip);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeIp(String ip)
|
|
||||||
{
|
|
||||||
if (ips.contains(ip))
|
|
||||||
{
|
|
||||||
ips.remove(ip);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clearIPs()
|
|
||||||
{
|
|
||||||
ips.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getLastLogin()
|
|
||||||
{
|
|
||||||
return lastLogin;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCustomLoginMessage()
|
|
||||||
{
|
|
||||||
return loginMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSeniorAdmin()
|
|
||||||
{
|
|
||||||
return isSeniorAdmin;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isTelnetAdmin()
|
|
||||||
{
|
|
||||||
return isTelnetAdmin;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getConsoleAliases()
|
|
||||||
{
|
|
||||||
return Collections.unmodifiableList(consoleAliases);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLastLogin(Date lastLogin)
|
|
||||||
{
|
|
||||||
this.lastLogin = lastLogin;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isActivated()
|
|
||||||
{
|
|
||||||
return isActivated;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setActivated(boolean isActivated)
|
|
||||||
{
|
|
||||||
this.isActivated = isActivated;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,688 +0,0 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod;
|
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.collect.Sets;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.Commands.Command_logs;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.Config.TFM_Config;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.Config.TFM_MainConfig;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.World.TFM_AdminWorld;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class TFM_AdminList
|
|
||||||
{
|
|
||||||
public static final Function<Player, Boolean> SUPERADMIN_SERVICE;
|
|
||||||
private static final Map<UUID, TFM_Admin> adminList;
|
|
||||||
private static final Set<UUID> superUUIDs;
|
|
||||||
private static final Set<UUID> telnetUUIDs;
|
|
||||||
private static final Set<UUID> seniorUUIDs;
|
|
||||||
private static final Set<String> seniorConsoleNames;
|
|
||||||
private static final Set<String> superIps;
|
|
||||||
private static int cleanThreshold = 24 * 7; // 1 Week in hours
|
|
||||||
|
|
||||||
static
|
|
||||||
{
|
|
||||||
adminList = new HashMap<UUID, TFM_Admin>();
|
|
||||||
superUUIDs = new HashSet<UUID>();
|
|
||||||
telnetUUIDs = new HashSet<UUID>();
|
|
||||||
seniorUUIDs = new HashSet<UUID>();
|
|
||||||
seniorConsoleNames = new HashSet<String>();
|
|
||||||
superIps = new HashSet<String>();
|
|
||||||
|
|
||||||
SUPERADMIN_SERVICE = new Function<Player, Boolean>()
|
|
||||||
{
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean apply(Player f)
|
|
||||||
{
|
|
||||||
return isSuperAdmin(f);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private TFM_AdminList()
|
|
||||||
{
|
|
||||||
throw new AssertionError();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Set<UUID> getSuperUUIDs()
|
|
||||||
{
|
|
||||||
return Collections.unmodifiableSet(superUUIDs);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Set<UUID> getTelnetUUIDs()
|
|
||||||
{
|
|
||||||
return Collections.unmodifiableSet(telnetUUIDs);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Set<UUID> getSeniorUUIDs()
|
|
||||||
{
|
|
||||||
return Collections.unmodifiableSet(seniorUUIDs);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Set<String> getSeniorConsoleNames()
|
|
||||||
{
|
|
||||||
return Collections.unmodifiableSet(seniorConsoleNames);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Set<String> getSuperadminIps()
|
|
||||||
{
|
|
||||||
return Collections.unmodifiableSet(superIps);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Set<TFM_Admin> getAllAdmins()
|
|
||||||
{
|
|
||||||
return Sets.newHashSet(adminList.values());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Set<String> getSuperNames()
|
|
||||||
{
|
|
||||||
final Set<String> names = new HashSet<String>();
|
|
||||||
|
|
||||||
for (TFM_Admin admin : adminList.values())
|
|
||||||
{
|
|
||||||
if (!admin.isActivated())
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
names.add(admin.getLastLoginName());
|
|
||||||
}
|
|
||||||
|
|
||||||
return Collections.unmodifiableSet(names);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Set<String> getLowercaseSuperNames()
|
|
||||||
{
|
|
||||||
final Set<String> names = new HashSet<String>();
|
|
||||||
|
|
||||||
for (TFM_Admin admin : adminList.values())
|
|
||||||
{
|
|
||||||
if (!admin.isActivated())
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
names.add(admin.getLastLoginName().toLowerCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
return Collections.unmodifiableSet(names);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setUuid(TFM_Admin admin, UUID oldUuid, UUID newUuid)
|
|
||||||
{
|
|
||||||
if (!adminList.containsKey(oldUuid))
|
|
||||||
{
|
|
||||||
TFM_Log.warning("Could not set new UUID for admin " + admin.getLastLoginName() + ", admin is not loaded!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (oldUuid.equals(newUuid))
|
|
||||||
{
|
|
||||||
TFM_Log.warning("could not set new UUID for admin " + admin.getLastLoginName() + ", UUIDs match.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add new entry
|
|
||||||
final TFM_Admin newAdmin = new TFM_Admin(
|
|
||||||
newUuid,
|
|
||||||
admin.getLastLoginName(),
|
|
||||||
admin.getLastLogin(),
|
|
||||||
admin.getCustomLoginMessage(),
|
|
||||||
admin.isTelnetAdmin(),
|
|
||||||
admin.isSeniorAdmin(),
|
|
||||||
admin.isActivated());
|
|
||||||
newAdmin.addIps(admin.getIps());
|
|
||||||
adminList.put(newUuid, newAdmin);
|
|
||||||
save(newAdmin);
|
|
||||||
|
|
||||||
// Remove old entry
|
|
||||||
adminList.remove(oldUuid);
|
|
||||||
final TFM_Config config = new TFM_Config(TotalFreedomMod.plugin, TotalFreedomMod.SUPERADMIN_FILENAME, true);
|
|
||||||
config.load();
|
|
||||||
config.set("admins." + oldUuid.toString(), null);
|
|
||||||
config.save();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void load()
|
|
||||||
{
|
|
||||||
adminList.clear();
|
|
||||||
|
|
||||||
final TFM_Config config = new TFM_Config(TotalFreedomMod.plugin, TotalFreedomMod.SUPERADMIN_FILENAME, true);
|
|
||||||
config.load();
|
|
||||||
|
|
||||||
cleanThreshold = config.getInt("clean_threshold_hours", cleanThreshold);
|
|
||||||
|
|
||||||
// Parse old superadmins
|
|
||||||
if (config.isConfigurationSection("superadmins"))
|
|
||||||
{
|
|
||||||
parseOldConfig(config);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!config.isConfigurationSection("admins"))
|
|
||||||
{
|
|
||||||
TFM_Log.warning("Missing admins section in superadmin.yml.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final ConfigurationSection section = config.getConfigurationSection("admins");
|
|
||||||
|
|
||||||
for (String uuidString : section.getKeys(false))
|
|
||||||
{
|
|
||||||
if (!TFM_Util.isUniqueId(uuidString))
|
|
||||||
{
|
|
||||||
TFM_Log.warning("Invalid Unique ID: " + uuidString + " in superadmin.yml, ignoring");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
final UUID uuid = UUID.fromString(uuidString);
|
|
||||||
|
|
||||||
final TFM_Admin superadmin = new TFM_Admin(uuid, section.getConfigurationSection(uuidString));
|
|
||||||
adminList.put(uuid, superadmin);
|
|
||||||
}
|
|
||||||
|
|
||||||
updateIndexLists();
|
|
||||||
|
|
||||||
TFM_Log.info("Loaded " + adminList.size() + " admins (" + superUUIDs.size() + " active) and " + superIps.size() + " IPs.");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void updateIndexLists()
|
|
||||||
{
|
|
||||||
superUUIDs.clear();
|
|
||||||
telnetUUIDs.clear();
|
|
||||||
seniorUUIDs.clear();
|
|
||||||
seniorConsoleNames.clear();
|
|
||||||
superIps.clear();
|
|
||||||
|
|
||||||
for (TFM_Admin admin : adminList.values())
|
|
||||||
{
|
|
||||||
if (!admin.isActivated())
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
final UUID uuid = admin.getUniqueId();
|
|
||||||
|
|
||||||
superUUIDs.add(uuid);
|
|
||||||
|
|
||||||
for (String ip : admin.getIps())
|
|
||||||
{
|
|
||||||
superIps.add(ip);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (admin.isTelnetAdmin())
|
|
||||||
{
|
|
||||||
telnetUUIDs.add(uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (admin.isSeniorAdmin())
|
|
||||||
{
|
|
||||||
seniorUUIDs.add(uuid);
|
|
||||||
|
|
||||||
seniorConsoleNames.add(admin.getLastLoginName());
|
|
||||||
for (String alias : admin.getConsoleAliases())
|
|
||||||
{
|
|
||||||
seniorConsoleNames.add(alias.toLowerCase());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TFM_AdminWorld.getInstance().wipeAccessCache();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void parseOldConfig(TFM_Config config)
|
|
||||||
{
|
|
||||||
TFM_Log.info("Old superadmin configuration found, parsing...");
|
|
||||||
|
|
||||||
final ConfigurationSection section = config.getConfigurationSection("superadmins");
|
|
||||||
|
|
||||||
int counter = 0;
|
|
||||||
int errors = 0;
|
|
||||||
|
|
||||||
for (String admin : config.getConfigurationSection("superadmins").getKeys(false))
|
|
||||||
{
|
|
||||||
final UUID uuid = TFM_UuidManager.getUniqueId(admin);
|
|
||||||
|
|
||||||
if (uuid == null)
|
|
||||||
{
|
|
||||||
errors++;
|
|
||||||
TFM_Log.warning("Could not convert admin " + admin + ", UUID could not be found!");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
config.set("admins." + uuid + ".last_login_name", uuid);
|
|
||||||
config.set("admins." + uuid + ".is_activated", section.getBoolean(admin + ".is_activated"));
|
|
||||||
config.set("admins." + uuid + ".is_telnet_admin", section.getBoolean(admin + ".is_telnet_admin"));
|
|
||||||
config.set("admins." + uuid + ".is_senior_admin", section.getBoolean(admin + ".is_senior_admin"));
|
|
||||||
config.set("admins." + uuid + ".last_login", section.getString(admin + ".last_login"));
|
|
||||||
config.set("admins." + uuid + ".custom_login_message", section.getString(admin + ".custom_login_message"));
|
|
||||||
config.set("admins." + uuid + ".console_aliases", section.getStringList(admin + ".console_aliases"));
|
|
||||||
config.set("admins." + uuid + ".ips", section.getStringList(admin + ".ips"));
|
|
||||||
|
|
||||||
counter++;
|
|
||||||
}
|
|
||||||
|
|
||||||
config.set("superadmins", null);
|
|
||||||
config.save();
|
|
||||||
|
|
||||||
TFM_Log.info("Done! " + counter + " admins parsed, " + errors + " errors");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void saveAll()
|
|
||||||
{
|
|
||||||
final TFM_Config config = new TFM_Config(TotalFreedomMod.plugin, TotalFreedomMod.SUPERADMIN_FILENAME, true);
|
|
||||||
config.load();
|
|
||||||
|
|
||||||
config.set("clean_threshold_hours", cleanThreshold);
|
|
||||||
|
|
||||||
final Iterator<Entry<UUID, TFM_Admin>> it = adminList.entrySet().iterator();
|
|
||||||
while (it.hasNext())
|
|
||||||
{
|
|
||||||
final Entry<UUID, TFM_Admin> pair = it.next();
|
|
||||||
|
|
||||||
final UUID uuid = pair.getKey();
|
|
||||||
final TFM_Admin superadmin = pair.getValue();
|
|
||||||
|
|
||||||
config.set("admins." + uuid + ".last_login_name", superadmin.getLastLoginName());
|
|
||||||
config.set("admins." + uuid + ".is_activated", superadmin.isActivated());
|
|
||||||
config.set("admins." + uuid + ".is_telnet_admin", superadmin.isTelnetAdmin());
|
|
||||||
config.set("admins." + uuid + ".is_senior_admin", superadmin.isSeniorAdmin());
|
|
||||||
config.set("admins." + uuid + ".last_login", TFM_Util.dateToString(superadmin.getLastLogin()));
|
|
||||||
config.set("admins." + uuid + ".custom_login_message", superadmin.getCustomLoginMessage());
|
|
||||||
config.set("admins." + uuid + ".console_aliases", TFM_Util.removeDuplicates(superadmin.getConsoleAliases()));
|
|
||||||
config.set("admins." + uuid + ".ips", TFM_Util.removeDuplicates(superadmin.getIps()));
|
|
||||||
}
|
|
||||||
|
|
||||||
config.save();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void save(TFM_Admin admin)
|
|
||||||
{
|
|
||||||
if (!adminList.containsValue(admin))
|
|
||||||
{
|
|
||||||
TFM_Log.warning("Could not save admin " + admin.getLastLoginName() + ", admin is not loaded!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final TFM_Config config = new TFM_Config(TotalFreedomMod.plugin, TotalFreedomMod.SUPERADMIN_FILENAME, true);
|
|
||||||
config.load();
|
|
||||||
|
|
||||||
final UUID uuid = admin.getUniqueId();
|
|
||||||
|
|
||||||
config.set("admins." + uuid + ".last_login_name", admin.getLastLoginName());
|
|
||||||
config.set("admins." + uuid + ".is_activated", admin.isActivated());
|
|
||||||
config.set("admins." + uuid + ".is_telnet_admin", admin.isTelnetAdmin());
|
|
||||||
config.set("admins." + uuid + ".is_senior_admin", admin.isSeniorAdmin());
|
|
||||||
config.set("admins." + uuid + ".last_login", TFM_Util.dateToString(admin.getLastLogin()));
|
|
||||||
config.set("admins." + uuid + ".custom_login_message", admin.getCustomLoginMessage());
|
|
||||||
config.set("admins." + uuid + ".console_aliases", TFM_Util.removeDuplicates(admin.getConsoleAliases()));
|
|
||||||
config.set("admins." + uuid + ".ips", TFM_Util.removeDuplicates(admin.getIps()));
|
|
||||||
|
|
||||||
config.save();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static TFM_Admin getEntry(Player player)
|
|
||||||
{
|
|
||||||
return getEntry(TFM_UuidManager.getUniqueId(player));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static TFM_Admin getEntry(UUID uuid)
|
|
||||||
{
|
|
||||||
return adminList.get(uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static TFM_Admin getEntry(String name)
|
|
||||||
{
|
|
||||||
for (UUID uuid : adminList.keySet())
|
|
||||||
{
|
|
||||||
if (adminList.get(uuid).getLastLoginName().equalsIgnoreCase(name))
|
|
||||||
{
|
|
||||||
return adminList.get(uuid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static TFM_Admin getEntryByIp(String ip)
|
|
||||||
{
|
|
||||||
return getEntryByIp(ip, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static TFM_Admin getEntryByIp(String needleIp, boolean fuzzy)
|
|
||||||
{
|
|
||||||
Iterator<Entry<UUID, TFM_Admin>> it = adminList.entrySet().iterator();
|
|
||||||
while (it.hasNext())
|
|
||||||
{
|
|
||||||
final Entry<UUID, TFM_Admin> pair = it.next();
|
|
||||||
final TFM_Admin superadmin = pair.getValue();
|
|
||||||
|
|
||||||
if (fuzzy)
|
|
||||||
{
|
|
||||||
for (String haystackIp : superadmin.getIps())
|
|
||||||
{
|
|
||||||
if (TFM_Util.fuzzyIpMatch(needleIp, haystackIp, 3))
|
|
||||||
{
|
|
||||||
return superadmin;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (superadmin.getIps().contains(needleIp))
|
|
||||||
{
|
|
||||||
return superadmin;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void updateLastLogin(Player player)
|
|
||||||
{
|
|
||||||
final TFM_Admin admin = getEntry(player);
|
|
||||||
if (admin == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
admin.setLastLogin(new Date());
|
|
||||||
admin.setLastLoginName(player.getName());
|
|
||||||
saveAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isSuperAdminSafe(UUID uuid, String ip)
|
|
||||||
{
|
|
||||||
if (TotalFreedomMod.server.getOnlineMode() && uuid != null)
|
|
||||||
{
|
|
||||||
return TFM_AdminList.getSuperUUIDs().contains(uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
final TFM_Admin admin = TFM_AdminList.getEntryByIp(ip);
|
|
||||||
return admin != null && admin.isActivated();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static synchronized boolean isSuperAdminSync(CommandSender sender)
|
|
||||||
{
|
|
||||||
return isSuperAdmin(sender);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isSuperAdmin(CommandSender sender)
|
|
||||||
{
|
|
||||||
if (!(sender instanceof Player))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
final Player player = (Player) sender;
|
|
||||||
|
|
||||||
if (superIps.contains(TFM_Util.getIp(player)))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Bukkit.getOnlineMode() && superUUIDs.contains(TFM_UuidManager.getUniqueId(player)))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isTelnetAdmin(CommandSender sender, boolean verifySuperadmin)
|
|
||||||
{
|
|
||||||
if (verifySuperadmin)
|
|
||||||
{
|
|
||||||
if (!isSuperAdmin(sender))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(sender instanceof Player))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
final TFM_Admin entry = getEntry((Player) sender);
|
|
||||||
if (entry != null)
|
|
||||||
{
|
|
||||||
return entry.isTelnetAdmin();
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isSeniorAdmin(CommandSender sender)
|
|
||||||
{
|
|
||||||
return isSeniorAdmin(sender, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isSeniorAdmin(CommandSender sender, boolean verifySuperadmin)
|
|
||||||
{
|
|
||||||
if (verifySuperadmin)
|
|
||||||
{
|
|
||||||
if (!isSuperAdmin(sender))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(sender instanceof Player))
|
|
||||||
{
|
|
||||||
return seniorConsoleNames.contains(sender.getName())
|
|
||||||
|| (TFM_MainConfig.getBoolean(TFM_ConfigEntry.CONSOLE_IS_SENIOR) && sender.getName().equals("CONSOLE"));
|
|
||||||
}
|
|
||||||
|
|
||||||
final TFM_Admin entry = getEntry((Player) sender);
|
|
||||||
if (entry != null)
|
|
||||||
{
|
|
||||||
return entry.isSeniorAdmin();
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isIdentityMatched(Player player)
|
|
||||||
{
|
|
||||||
if (!isSuperAdmin(player))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Bukkit.getOnlineMode())
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
final TFM_Admin entry = getEntry(player);
|
|
||||||
if (entry == null)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return entry.getUniqueId().equals(TFM_UuidManager.getUniqueId(player));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static boolean checkPartialSuperadminIp(String ip, String name)
|
|
||||||
{
|
|
||||||
ip = ip.trim();
|
|
||||||
|
|
||||||
if (superIps.contains(ip))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
String matchIp = null;
|
|
||||||
for (String testIp : superIps)
|
|
||||||
{
|
|
||||||
if (TFM_Util.fuzzyIpMatch(ip, testIp, 3))
|
|
||||||
{
|
|
||||||
matchIp = testIp;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (matchIp != null)
|
|
||||||
{
|
|
||||||
final TFM_Admin entry = getEntryByIp(matchIp);
|
|
||||||
|
|
||||||
if (entry == null)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entry.getLastLoginName().equalsIgnoreCase(name))
|
|
||||||
{
|
|
||||||
if (!entry.getIps().contains(ip))
|
|
||||||
{
|
|
||||||
entry.addIp(ip);
|
|
||||||
}
|
|
||||||
saveAll();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
TFM_Log.severe(ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isAdminImpostor(Player player)
|
|
||||||
{
|
|
||||||
if (superUUIDs.contains(TFM_UuidManager.getUniqueId(player)))
|
|
||||||
{
|
|
||||||
return !isSuperAdmin(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void addSuperadmin(OfflinePlayer player)
|
|
||||||
{
|
|
||||||
final UUID uuid = TFM_UuidManager.getUniqueId(player);
|
|
||||||
final String ip = TFM_Util.getIp(player);
|
|
||||||
final boolean canSuperIp = !TFM_MainConfig.getList(TFM_ConfigEntry.NOADMIN_IPS).contains(ip);
|
|
||||||
|
|
||||||
if (adminList.containsKey(uuid))
|
|
||||||
{
|
|
||||||
final TFM_Admin superadmin = adminList.get(uuid);
|
|
||||||
superadmin.setActivated(true);
|
|
||||||
|
|
||||||
if (player.isOnline())
|
|
||||||
{
|
|
||||||
superadmin.setLastLogin(new Date());
|
|
||||||
|
|
||||||
if (ip != null && canSuperIp)
|
|
||||||
{
|
|
||||||
superadmin.addIp(ip);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
saveAll();
|
|
||||||
updateIndexLists();
|
|
||||||
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 TFM_Admin superadmin = new TFM_Admin(
|
|
||||||
uuid,
|
|
||||||
player.getName(),
|
|
||||||
new Date(),
|
|
||||||
"",
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true);
|
|
||||||
superadmin.addIp(ip);
|
|
||||||
|
|
||||||
adminList.put(uuid, superadmin);
|
|
||||||
|
|
||||||
saveAll();
|
|
||||||
updateIndexLists();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void removeSuperadmin(OfflinePlayer player)
|
|
||||||
{
|
|
||||||
final UUID uuid = TFM_UuidManager.getUniqueId(player);
|
|
||||||
|
|
||||||
if (!adminList.containsKey(uuid))
|
|
||||||
{
|
|
||||||
TFM_Log.warning("Could not remove admin: " + TFM_Util.formatPlayer(player));
|
|
||||||
TFM_Log.warning("Player is not an admin!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final TFM_Admin superadmin = adminList.get(uuid);
|
|
||||||
superadmin.setActivated(false);
|
|
||||||
Command_logs.deactivateSuperadmin(superadmin);
|
|
||||||
|
|
||||||
saveAll();
|
|
||||||
updateIndexLists();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void cleanSuperadminList(boolean verbose)
|
|
||||||
{
|
|
||||||
Iterator<Entry<UUID, TFM_Admin>> it = adminList.entrySet().iterator();
|
|
||||||
while (it.hasNext())
|
|
||||||
{
|
|
||||||
final Entry<UUID, TFM_Admin> pair = it.next();
|
|
||||||
final TFM_Admin superadmin = pair.getValue();
|
|
||||||
|
|
||||||
if (!superadmin.isActivated() || superadmin.isSeniorAdmin())
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
final Date lastLogin = superadmin.getLastLogin();
|
|
||||||
final long lastLoginHours = TimeUnit.HOURS.convert(new Date().getTime() - lastLogin.getTime(), TimeUnit.MILLISECONDS);
|
|
||||||
|
|
||||||
if (lastLoginHours > cleanThreshold)
|
|
||||||
{
|
|
||||||
if (verbose)
|
|
||||||
{
|
|
||||||
TFM_Util.adminAction("TotalFreedomMod", "Deactivating superadmin " + superadmin.getLastLoginName() + ", inactive for " + lastLoginHours + " hours.", true);
|
|
||||||
}
|
|
||||||
|
|
||||||
superadmin.setActivated(false);
|
|
||||||
Command_logs.deactivateSuperadmin(superadmin);
|
|
||||||
TFM_TwitterHandler.delTwitter(superadmin.getLastLoginName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
saveAll();
|
|
||||||
updateIndexLists();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,112 +0,0 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
|
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
|
||||||
|
|
||||||
public class TFM_Announcer
|
|
||||||
{
|
|
||||||
private static final List<String> ANNOUNCEMENTS = new ArrayList<String>();
|
|
||||||
private static boolean enabled;
|
|
||||||
private static long interval;
|
|
||||||
private static String prefix;
|
|
||||||
private static BukkitRunnable announcer;
|
|
||||||
|
|
||||||
private TFM_Announcer()
|
|
||||||
{
|
|
||||||
throw new AssertionError();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isEnabled()
|
|
||||||
{
|
|
||||||
return enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<String> getAnnouncements()
|
|
||||||
{
|
|
||||||
return Collections.unmodifiableList(ANNOUNCEMENTS);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static long getTickInterval()
|
|
||||||
{
|
|
||||||
return interval;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getPrefix()
|
|
||||||
{
|
|
||||||
return prefix;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void load()
|
|
||||||
{
|
|
||||||
stop();
|
|
||||||
|
|
||||||
ANNOUNCEMENTS.clear();
|
|
||||||
|
|
||||||
for (Object announcement : TFM_ConfigEntry.ANNOUNCER_ANNOUNCEMENTS.getList())
|
|
||||||
{
|
|
||||||
ANNOUNCEMENTS.add(TFM_Util.colorize((String) announcement));
|
|
||||||
}
|
|
||||||
|
|
||||||
enabled = TFM_ConfigEntry.ANNOUNCER_ENABLED.getBoolean();
|
|
||||||
interval = TFM_ConfigEntry.ANNOUNCER_INTERVAL.getInteger() * 20L;
|
|
||||||
prefix = TFM_Util.colorize(TFM_ConfigEntry.ANNOUNCER_PREFIX.getString());
|
|
||||||
|
|
||||||
if (enabled)
|
|
||||||
{
|
|
||||||
start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isStarted()
|
|
||||||
{
|
|
||||||
return announcer != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void start()
|
|
||||||
{
|
|
||||||
if (isStarted())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
announcer = new BukkitRunnable()
|
|
||||||
{
|
|
||||||
private int current = 0;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
current++;
|
|
||||||
|
|
||||||
if (current >= ANNOUNCEMENTS.size())
|
|
||||||
{
|
|
||||||
current = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
TFM_Util.bcastMsg(prefix + ANNOUNCEMENTS.get(current));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
announcer.runTaskTimer(TotalFreedomMod.plugin, interval, interval);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void stop()
|
|
||||||
{
|
|
||||||
if (announcer == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
announcer.cancel();
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
announcer = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,209 +0,0 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod;
|
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
|
|
||||||
public class TFM_Ban
|
|
||||||
{
|
|
||||||
public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd \'at\' HH:mm:ss z");
|
|
||||||
public static final Pattern IP_BAN_REGEX;
|
|
||||||
public static final Pattern UUID_BAN_REGEX;
|
|
||||||
|
|
||||||
static
|
|
||||||
{
|
|
||||||
// 192.168.1.254:LocalHost:Prozza:0:none
|
|
||||||
// 127.0.*.*:TestUserName:BannedByNotch:123567:Test reason
|
|
||||||
IP_BAN_REGEX = Pattern.compile(
|
|
||||||
"^((?:(?:\\*|(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))\\.){3}(?:\\*|(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)))"
|
|
||||||
+ ":([\\w\\s]+)"
|
|
||||||
+ ":([\\w]+)"
|
|
||||||
+ ":(\\d+)"
|
|
||||||
+ ":([\\s\\S]+)$");
|
|
||||||
// 245d2f30-61fb-4840-9cd3-298b3920f4a4:Cobrex:Prozza:0:Example reason
|
|
||||||
UUID_BAN_REGEX = Pattern.compile(
|
|
||||||
"^([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})"
|
|
||||||
+ ":([\\w\\s]+)"
|
|
||||||
+ ":([\\w]+)"
|
|
||||||
+ ":(\\d+)"
|
|
||||||
+ ":([\\s\\S]+)$");
|
|
||||||
}
|
|
||||||
private final BanType type;
|
|
||||||
private final boolean complete;
|
|
||||||
private String subject; // uuid or IP
|
|
||||||
private String lastLoginName;
|
|
||||||
private String by;
|
|
||||||
private long expireUnix;
|
|
||||||
private String reason;
|
|
||||||
|
|
||||||
public TFM_Ban(String ip, String lastLoginName)
|
|
||||||
{
|
|
||||||
this(ip, lastLoginName, null, null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TFM_Ban(String ip, String lastLoginName, String sender, Date expire, String reason)
|
|
||||||
{
|
|
||||||
this(ip, lastLoginName, sender, expire, reason, BanType.IP);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TFM_Ban(UUID uuid, String lastLoginName)
|
|
||||||
{
|
|
||||||
this(uuid, lastLoginName, null, null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TFM_Ban(UUID uuid, String lastLoginName, String sender, Date expire, String reason)
|
|
||||||
{
|
|
||||||
this(uuid.toString(), lastLoginName, sender, expire, reason, BanType.UUID);
|
|
||||||
}
|
|
||||||
|
|
||||||
private TFM_Ban(String subject, String lastLoginName, String sender, Date expire, String reason, BanType type)
|
|
||||||
{
|
|
||||||
this.type = type;
|
|
||||||
this.subject = subject;
|
|
||||||
this.lastLoginName = (lastLoginName == null ? "none" : lastLoginName);
|
|
||||||
this.by = (sender == null ? "none" : sender);
|
|
||||||
this.expireUnix = (expire == null ? 0 : TFM_Util.getUnixTime(expire));
|
|
||||||
this.reason = (reason == null ? "none" : reason);
|
|
||||||
complete = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TFM_Ban(String banString, BanType type)
|
|
||||||
{
|
|
||||||
this.type = type;
|
|
||||||
|
|
||||||
final Matcher matcher = (type == BanType.IP ? IP_BAN_REGEX.matcher(banString) : UUID_BAN_REGEX.matcher(banString));
|
|
||||||
|
|
||||||
if (!matcher.find())
|
|
||||||
{
|
|
||||||
complete = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
subject = matcher.group(1);
|
|
||||||
lastLoginName = matcher.group(2);
|
|
||||||
by = matcher.group(3);
|
|
||||||
expireUnix = Long.valueOf(matcher.group(4));
|
|
||||||
reason = TFM_Util.colorize(matcher.group(5));
|
|
||||||
complete = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static enum BanType
|
|
||||||
{
|
|
||||||
IP,
|
|
||||||
UUID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BanType getType()
|
|
||||||
{
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSubject()
|
|
||||||
{
|
|
||||||
return subject;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLastLoginName()
|
|
||||||
{
|
|
||||||
return lastLoginName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getBannedBy()
|
|
||||||
{
|
|
||||||
return by;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getExpireUnix()
|
|
||||||
{
|
|
||||||
return expireUnix;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getReason()
|
|
||||||
{
|
|
||||||
return reason;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isExpired()
|
|
||||||
{
|
|
||||||
return expireUnix != 0 && expireUnix < TFM_Util.getUnixTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isComplete()
|
|
||||||
{
|
|
||||||
return complete;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getKickMessage()
|
|
||||||
{
|
|
||||||
final StringBuilder message = new StringBuilder("You");
|
|
||||||
|
|
||||||
message.append(type == BanType.IP ? "r IP address is" : " are").append(" temporarily banned from this server.");
|
|
||||||
message.append("\nAppeal at ").append(ChatColor.GOLD).append(TFM_ConfigEntry.SERVER_BAN_URL.getString());
|
|
||||||
|
|
||||||
if (!reason.equals("none"))
|
|
||||||
{
|
|
||||||
message.append("\nReason: ").append(reason);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getExpireUnix() != 0)
|
|
||||||
{
|
|
||||||
message.append("\nYour ban will be removed on ").append(DATE_FORMAT.format(TFM_Util.getUnixDate(expireUnix)));
|
|
||||||
}
|
|
||||||
|
|
||||||
return message.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
// subject:lastLoginName:bannedBy:expireUnix:reason
|
|
||||||
@Override
|
|
||||||
public String toString()
|
|
||||||
{
|
|
||||||
return subject + ":" + lastLoginName + ":" + by + ":" + expireUnix + ":" + TFM_Util.decolorize(reason);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object object)
|
|
||||||
{
|
|
||||||
if (object == null)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(object instanceof TFM_Ban))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
final TFM_Ban ban = (TFM_Ban) object;
|
|
||||||
|
|
||||||
if (toString().equals(ban.toString()))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getType() != ban.getType())
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!getSubject().equals(ban.getSubject()))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode()
|
|
||||||
{
|
|
||||||
final int prime = 37;
|
|
||||||
int result = 1;
|
|
||||||
result = prime * result + getType().hashCode();
|
|
||||||
result = prime * result + getSubject().hashCode();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,298 +0,0 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.Config.TFM_Config;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Ban.BanType;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_UuidManager.TFM_UuidResolver;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class TFM_BanManager
|
|
||||||
{
|
|
||||||
private static final List<TFM_Ban> ipBans;
|
|
||||||
private static final List<TFM_Ban> uuidBans;
|
|
||||||
private static final List<UUID> unbannableUUIDs;
|
|
||||||
|
|
||||||
static
|
|
||||||
{
|
|
||||||
ipBans = new ArrayList<TFM_Ban>();
|
|
||||||
uuidBans = new ArrayList<TFM_Ban>();
|
|
||||||
unbannableUUIDs = new ArrayList<UUID>();
|
|
||||||
}
|
|
||||||
|
|
||||||
private TFM_BanManager()
|
|
||||||
{
|
|
||||||
throw new AssertionError();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void load()
|
|
||||||
{
|
|
||||||
ipBans.clear();
|
|
||||||
uuidBans.clear();
|
|
||||||
unbannableUUIDs.clear();
|
|
||||||
|
|
||||||
final TFM_Config config = new TFM_Config(TotalFreedomMod.plugin, "bans.yml", true);
|
|
||||||
config.load();
|
|
||||||
|
|
||||||
for (String banString : config.getStringList("ips"))
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
addIpBan(new TFM_Ban(banString, BanType.IP));
|
|
||||||
}
|
|
||||||
catch (RuntimeException ex)
|
|
||||||
{
|
|
||||||
TFM_Log.warning("Could not load IP ban: " + banString);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (String banString : config.getStringList("uuids"))
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
addUuidBan(new TFM_Ban(banString, BanType.UUID));
|
|
||||||
}
|
|
||||||
catch (RuntimeException ex)
|
|
||||||
{
|
|
||||||
TFM_Log.warning("Could not load UUID ban: " + banString);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save the config
|
|
||||||
save();
|
|
||||||
TFM_Log.info("Loaded " + ipBans.size() + " IP bans and " + uuidBans.size() + " UUID bans");
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
final TFM_UuidResolver resolver = new TFM_UuidResolver((List<String>) TFM_ConfigEntry.UNBANNABLE_USERNAMES.getList());
|
|
||||||
|
|
||||||
for (UUID uuid : resolver.call().values())
|
|
||||||
{
|
|
||||||
unbannableUUIDs.add(uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
TFM_Log.info("Loaded " + unbannableUUIDs.size() + " unbannable UUIDs");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void save()
|
|
||||||
{
|
|
||||||
final TFM_Config config = new TFM_Config(TotalFreedomMod.plugin, "bans.yml", true);
|
|
||||||
config.load();
|
|
||||||
|
|
||||||
final List<String> newIpBans = new ArrayList<String>();
|
|
||||||
final List<String> newUuidBans = new ArrayList<String>();
|
|
||||||
|
|
||||||
for (TFM_Ban savedBan : ipBans)
|
|
||||||
{
|
|
||||||
if (!savedBan.isExpired())
|
|
||||||
{
|
|
||||||
newIpBans.add(savedBan.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (TFM_Ban savedBan : uuidBans)
|
|
||||||
{
|
|
||||||
if (!savedBan.isExpired() && !unbannableUUIDs.contains(UUID.fromString(savedBan.getSubject())))
|
|
||||||
{
|
|
||||||
newUuidBans.add(savedBan.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
config.set("ips", newIpBans);
|
|
||||||
config.set("uuids", newUuidBans);
|
|
||||||
|
|
||||||
// Save config
|
|
||||||
config.save();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<TFM_Ban> getIpBanList()
|
|
||||||
{
|
|
||||||
return Collections.unmodifiableList(ipBans);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<TFM_Ban> getUuidBanList()
|
|
||||||
{
|
|
||||||
return Collections.unmodifiableList(uuidBans);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static TFM_Ban getByIp(String ip)
|
|
||||||
{
|
|
||||||
for (TFM_Ban ban : ipBans)
|
|
||||||
{
|
|
||||||
if (ban.isExpired())
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
wildcardCheck:
|
|
||||||
if (ban.getSubject().contains("*"))
|
|
||||||
{
|
|
||||||
final String[] subjectParts = ban.getSubject().split("\\.");
|
|
||||||
final String[] ipParts = ip.split("\\.");
|
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++)
|
|
||||||
{
|
|
||||||
if (!(subjectParts[i].equals("*") || subjectParts[i].equals(ipParts[i])))
|
|
||||||
{
|
|
||||||
break wildcardCheck;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ban;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ban.getSubject().equals(ip))
|
|
||||||
{
|
|
||||||
return ban;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static TFM_Ban getByUuid(UUID uuid)
|
|
||||||
{
|
|
||||||
for (TFM_Ban ban : uuidBans)
|
|
||||||
{
|
|
||||||
if (ban.getSubject().equalsIgnoreCase(uuid.toString()))
|
|
||||||
{
|
|
||||||
if (ban.isExpired())
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ban;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void unbanIp(String ip)
|
|
||||||
{
|
|
||||||
final TFM_Ban ban = getByIp(ip);
|
|
||||||
|
|
||||||
if (ban == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
removeBan(ban);
|
|
||||||
save();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void unbanUuid(UUID uuid)
|
|
||||||
{
|
|
||||||
final TFM_Ban ban = getByUuid(uuid);
|
|
||||||
|
|
||||||
if (ban == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
removeBan(ban);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isIpBanned(String ip)
|
|
||||||
{
|
|
||||||
return getByIp(ip) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isUuidBanned(UUID uuid)
|
|
||||||
{
|
|
||||||
return getByUuid(uuid) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void addUuidBan(Player player)
|
|
||||||
{
|
|
||||||
addUuidBan(new TFM_Ban(TFM_UuidManager.getUniqueId(player), player.getName()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void addUuidBan(TFM_Ban ban)
|
|
||||||
{
|
|
||||||
if (!ban.isComplete())
|
|
||||||
{
|
|
||||||
throw new RuntimeException("Could not add UUID ban, Invalid format!");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ban.isExpired())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (uuidBans.contains(ban))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (unbannableUUIDs.contains(UUID.fromString(ban.getSubject())))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
uuidBans.add(ban);
|
|
||||||
save();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void addIpBan(Player player)
|
|
||||||
{
|
|
||||||
addIpBan(new TFM_Ban(TFM_Util.getIp(player), player.getName()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void addIpBan(TFM_Ban ban)
|
|
||||||
{
|
|
||||||
if (!ban.isComplete())
|
|
||||||
{
|
|
||||||
throw new RuntimeException("Could not add IP ban, Invalid format!");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ban.isExpired())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ipBans.contains(ban))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ipBans.add(ban);
|
|
||||||
save();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void removeBan(TFM_Ban ban)
|
|
||||||
{
|
|
||||||
final Iterator<TFM_Ban> ips = ipBans.iterator();
|
|
||||||
while (ips.hasNext())
|
|
||||||
{
|
|
||||||
if (ips.next().getSubject().equalsIgnoreCase(ban.getSubject()))
|
|
||||||
{
|
|
||||||
ips.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final Iterator<TFM_Ban> uuids = uuidBans.iterator();
|
|
||||||
while (uuids.hasNext())
|
|
||||||
{
|
|
||||||
if (uuids.next().getSubject().equalsIgnoreCase(ban.getSubject()))
|
|
||||||
{
|
|
||||||
uuids.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
save();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void purgeIpBans()
|
|
||||||
{
|
|
||||||
ipBans.clear();
|
|
||||||
save();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void purgeUuidBans()
|
|
||||||
{
|
|
||||||
uuidBans.clear();
|
|
||||||
save();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,339 +0,0 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandMap;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class TFM_CommandBlocker
|
|
||||||
{
|
|
||||||
public static Pattern NUMBER_FLAG_PATTERN = Pattern.compile("(:([0-9]){5,})");
|
|
||||||
private static final Map<String, CommandBlockerEntry> BLOCKED_COMMANDS = new HashMap<String, CommandBlockerEntry>();
|
|
||||||
|
|
||||||
private TFM_CommandBlocker()
|
|
||||||
{
|
|
||||||
throw new AssertionError();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void load()
|
|
||||||
{
|
|
||||||
BLOCKED_COMMANDS.clear();
|
|
||||||
|
|
||||||
final CommandMap commandMap = TFM_CommandLoader.getCommandMap();
|
|
||||||
if (commandMap == null)
|
|
||||||
{
|
|
||||||
TFM_Log.severe("Error loading commandMap.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
List<String> blockedCommands = (List<String>) TFM_ConfigEntry.BLOCKED_COMMANDS.getList();
|
|
||||||
for (String rawEntry : blockedCommands)
|
|
||||||
{
|
|
||||||
final String[] parts = rawEntry.split(":");
|
|
||||||
if (parts.length < 3 || parts.length > 4)
|
|
||||||
{
|
|
||||||
TFM_Log.warning("Invalid command blocker entry: " + rawEntry);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
final CommandBlockerRank rank = CommandBlockerRank.fromToken(parts[0]);
|
|
||||||
final CommandBlockerAction action = CommandBlockerAction.fromToken(parts[1]);
|
|
||||||
String commandName = parts[2].toLowerCase().substring(1);
|
|
||||||
final String message = (parts.length > 3 ? parts[3] : null);
|
|
||||||
|
|
||||||
if (rank == null || action == null || commandName == null || commandName.isEmpty())
|
|
||||||
{
|
|
||||||
TFM_Log.warning("Invalid command blocker entry: " + rawEntry);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
final String[] commandParts = commandName.split(" ");
|
|
||||||
String subCommand = null;
|
|
||||||
if (commandParts.length > 1)
|
|
||||||
{
|
|
||||||
commandName = commandParts[0];
|
|
||||||
subCommand = StringUtils.join(commandParts, " ", 1, commandParts.length).trim().toLowerCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
final Command command = commandMap.getCommand(commandName);
|
|
||||||
|
|
||||||
// Obtain command from alias
|
|
||||||
if (command == null)
|
|
||||||
{
|
|
||||||
TFM_Log.info("Blocking unknown command: /" + commandName);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
commandName = command.getName().toLowerCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (BLOCKED_COMMANDS.containsKey(commandName))
|
|
||||||
{
|
|
||||||
TFM_Log.warning("Not blocking: /" + commandName + " - Duplicate entry exists!");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
final CommandBlockerEntry blockedCommandEntry = new CommandBlockerEntry(rank, action, commandName, subCommand, message);
|
|
||||||
BLOCKED_COMMANDS.put(blockedCommandEntry.getCommand(), blockedCommandEntry);
|
|
||||||
|
|
||||||
if (command != null)
|
|
||||||
{
|
|
||||||
for (String alias : command.getAliases())
|
|
||||||
{
|
|
||||||
BLOCKED_COMMANDS.put(alias.toLowerCase(), blockedCommandEntry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TFM_Log.info("Loaded " + BLOCKED_COMMANDS.size() + " blocked commands");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isCommandBlocked(String command, CommandSender sender)
|
|
||||||
{
|
|
||||||
return isCommandBlocked(command, sender, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isCommandBlocked(String command, CommandSender sender, boolean doAction)
|
|
||||||
{
|
|
||||||
if (command == null || command.isEmpty())
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Format
|
|
||||||
command = command.toLowerCase().trim();
|
|
||||||
command = command.startsWith("/") ? command.substring(1) : command;
|
|
||||||
|
|
||||||
// Check for plugin specific commands
|
|
||||||
final String[] commandParts = command.split(" ");
|
|
||||||
if (commandParts[0].contains(":"))
|
|
||||||
{
|
|
||||||
if (doAction)
|
|
||||||
{
|
|
||||||
TFM_Util.playerMsg(sender, "Plugin specific commands are disabled.");
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (String part : commandParts)
|
|
||||||
{
|
|
||||||
Matcher matcher = NUMBER_FLAG_PATTERN.matcher(part);
|
|
||||||
if (!matcher.matches())
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (doAction)
|
|
||||||
{
|
|
||||||
TFM_Util.playerMsg(sender, "That command contains an illegal number: " + matcher.group(1));
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Obtain sub command, if it exists
|
|
||||||
String subCommand = null;
|
|
||||||
if (commandParts.length > 1)
|
|
||||||
{
|
|
||||||
subCommand = StringUtils.join(commandParts, " ", 1, commandParts.length).toLowerCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Obtain entry
|
|
||||||
final CommandBlockerEntry entry = BLOCKED_COMMANDS.get(commandParts[0]);
|
|
||||||
if (entry == null)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate sub command
|
|
||||||
if (entry.getSubCommand() != null)
|
|
||||||
{
|
|
||||||
if (subCommand == null || !subCommand.startsWith(entry.getSubCommand()))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entry.getRank().hasPermission(sender))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (doAction)
|
|
||||||
{
|
|
||||||
entry.doActions(sender);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static enum CommandBlockerRank
|
|
||||||
{
|
|
||||||
ANYONE("a", 0),
|
|
||||||
OP("o", 1),
|
|
||||||
SUPER("s", 2),
|
|
||||||
TELNET("t", 3),
|
|
||||||
SENIOR("c", 4),
|
|
||||||
NOBODY("n", 5);
|
|
||||||
//
|
|
||||||
private final String token;
|
|
||||||
private final int level;
|
|
||||||
|
|
||||||
private CommandBlockerRank(String token, int level)
|
|
||||||
{
|
|
||||||
this.token = token;
|
|
||||||
this.level = level;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getToken()
|
|
||||||
{
|
|
||||||
return this.token;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasPermission(CommandSender sender)
|
|
||||||
{
|
|
||||||
return fromSender(sender).level >= this.level;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static CommandBlockerRank fromSender(CommandSender sender)
|
|
||||||
{
|
|
||||||
if (!(sender instanceof Player))
|
|
||||||
{
|
|
||||||
return TELNET;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TFM_AdminList.isSuperAdmin(sender))
|
|
||||||
{
|
|
||||||
if (TFM_AdminList.isSeniorAdmin(sender))
|
|
||||||
{
|
|
||||||
return SENIOR;
|
|
||||||
}
|
|
||||||
return SUPER;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sender.isOp())
|
|
||||||
{
|
|
||||||
return OP;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ANYONE;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static CommandBlockerRank fromToken(String token)
|
|
||||||
{
|
|
||||||
for (CommandBlockerRank rank : CommandBlockerRank.values())
|
|
||||||
{
|
|
||||||
if (rank.getToken().equalsIgnoreCase(token))
|
|
||||||
{
|
|
||||||
return rank;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ANYONE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static enum CommandBlockerAction
|
|
||||||
{
|
|
||||||
BLOCK("b"),
|
|
||||||
BLOCK_AND_EJECT("a"),
|
|
||||||
BLOCK_UNKNOWN("u");
|
|
||||||
private final String token;
|
|
||||||
|
|
||||||
private CommandBlockerAction(String token)
|
|
||||||
{
|
|
||||||
this.token = token;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getToken()
|
|
||||||
{
|
|
||||||
return this.token;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static CommandBlockerAction fromToken(String token)
|
|
||||||
{
|
|
||||||
for (CommandBlockerAction action : CommandBlockerAction.values())
|
|
||||||
{
|
|
||||||
if (action.getToken().equalsIgnoreCase(token))
|
|
||||||
{
|
|
||||||
return action;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class CommandBlockerEntry
|
|
||||||
{
|
|
||||||
private final CommandBlockerRank rank;
|
|
||||||
private final CommandBlockerAction action;
|
|
||||||
private final String command;
|
|
||||||
private final String subCommand;
|
|
||||||
private final String message;
|
|
||||||
|
|
||||||
private CommandBlockerEntry(CommandBlockerRank rank, CommandBlockerAction action, String command, String message)
|
|
||||||
{
|
|
||||||
this(rank, action, command, null, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
private CommandBlockerEntry(CommandBlockerRank rank, CommandBlockerAction action, String command, String subCommand, String message)
|
|
||||||
{
|
|
||||||
this.rank = rank;
|
|
||||||
this.action = action;
|
|
||||||
this.command = command;
|
|
||||||
this.subCommand = (subCommand == null ? null : subCommand.toLowerCase().trim());
|
|
||||||
this.message = (message == null || message.equals("_") ? "That command is blocked." : message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CommandBlockerAction getAction()
|
|
||||||
{
|
|
||||||
return this.action;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCommand()
|
|
||||||
{
|
|
||||||
return this.command;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSubCommand()
|
|
||||||
{
|
|
||||||
return this.subCommand;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMessage()
|
|
||||||
{
|
|
||||||
return this.message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CommandBlockerRank getRank()
|
|
||||||
{
|
|
||||||
return this.rank;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void doActions(CommandSender sender)
|
|
||||||
{
|
|
||||||
if (action == CommandBlockerAction.BLOCK_AND_EJECT && sender instanceof Player)
|
|
||||||
{
|
|
||||||
TFM_Util.autoEject((Player) sender, "You used a prohibited command: " + command);
|
|
||||||
TFM_Util.bcastMsg(sender.getName() + " was automatically kicked for using harmful commands.", ChatColor.RED);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (action == CommandBlockerAction.BLOCK_UNKNOWN)
|
|
||||||
{
|
|
||||||
TFM_Util.playerMsg(sender, "Unknown command. Type \"help\" for help.", ChatColor.RESET);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
TFM_Util.playerMsg(sender, TFM_Util.colorize(message));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,88 +0,0 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod;
|
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.Bridge.TFM_EssentialsBridge;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.World.TFM_AdminWorld;
|
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
|
||||||
|
|
||||||
public class TFM_Heartbeat extends BukkitRunnable
|
|
||||||
{
|
|
||||||
private static final long AUTO_KICK_TIME = (long) TFM_ConfigEntry.AUTOKICK_TIME.getInteger() * 1000L;
|
|
||||||
private final TotalFreedomMod plugin;
|
|
||||||
private final Server server;
|
|
||||||
private static Long lastRan = null;
|
|
||||||
|
|
||||||
public TFM_Heartbeat(TotalFreedomMod instance)
|
|
||||||
{
|
|
||||||
this.plugin = instance;
|
|
||||||
this.server = plugin.getServer();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Long getLastRan()
|
|
||||||
{
|
|
||||||
return lastRan;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
lastRan = System.currentTimeMillis();
|
|
||||||
|
|
||||||
final boolean doAwayKickCheck = TFM_ConfigEntry.AUTOKICK_ENABLED.getBoolean()
|
|
||||||
&& TFM_EssentialsBridge.isEssentialsEnabled()
|
|
||||||
&& ((server.getOnlinePlayers().size() / server.getMaxPlayers()) > TFM_ConfigEntry.AUTOKICK_THRESHOLD.getDouble());
|
|
||||||
|
|
||||||
for (Player player : server.getOnlinePlayers())
|
|
||||||
{
|
|
||||||
final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
|
|
||||||
playerdata.resetMsgCount();
|
|
||||||
playerdata.resetBlockDestroyCount();
|
|
||||||
playerdata.resetBlockPlaceCount();
|
|
||||||
|
|
||||||
if (doAwayKickCheck)
|
|
||||||
{
|
|
||||||
final long lastActivity = TFM_EssentialsBridge.getLastActivity(player.getName());
|
|
||||||
if (lastActivity > 0 && lastActivity + AUTO_KICK_TIME < System.currentTimeMillis())
|
|
||||||
{
|
|
||||||
player.kickPlayer("Automatically kicked by server for inactivity.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TFM_ConfigEntry.AUTO_ENTITY_WIPE.getBoolean())
|
|
||||||
{
|
|
||||||
TFM_Util.TFM_EntityWiper.wipeEntities(!TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean(), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TFM_ConfigEntry.DISABLE_WEATHER.getBoolean())
|
|
||||||
{
|
|
||||||
for (World world : server.getWorlds())
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (world == TFM_AdminWorld.getInstance().getWorld() && TFM_AdminWorld.getInstance().getWeatherMode() != TFM_AdminWorld.WeatherMode.OFF)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
if (world.getWeatherDuration() > 0)
|
|
||||||
{
|
|
||||||
world.setThundering(false);
|
|
||||||
world.setWeatherDuration(0);
|
|
||||||
}
|
|
||||||
else if (world.getThunderDuration() > 0)
|
|
||||||
{
|
|
||||||
world.setStorm(false);
|
|
||||||
world.setThunderDuration(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,60 +0,0 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.Config.TFM_Config;
|
|
||||||
|
|
||||||
public class TFM_PermbanList
|
|
||||||
{
|
|
||||||
|
|
||||||
private static final List<String> PERMBANNED_PLAYERS;
|
|
||||||
private static final List<String> PERMBANNED_IPS;
|
|
||||||
|
|
||||||
static
|
|
||||||
{
|
|
||||||
PERMBANNED_PLAYERS = new ArrayList<String>();
|
|
||||||
PERMBANNED_IPS = new ArrayList<String>();
|
|
||||||
}
|
|
||||||
|
|
||||||
private TFM_PermbanList()
|
|
||||||
{
|
|
||||||
throw new AssertionError();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<String> getPermbannedPlayers()
|
|
||||||
{
|
|
||||||
return Collections.unmodifiableList(PERMBANNED_PLAYERS);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<String> getPermbannedIps()
|
|
||||||
{
|
|
||||||
return Collections.unmodifiableList(PERMBANNED_IPS);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void load()
|
|
||||||
{
|
|
||||||
PERMBANNED_PLAYERS.clear();
|
|
||||||
PERMBANNED_IPS.clear();
|
|
||||||
|
|
||||||
final TFM_Config config = new TFM_Config(TotalFreedomMod.plugin, TotalFreedomMod.PERMBAN_FILENAME, true);
|
|
||||||
config.load();
|
|
||||||
|
|
||||||
for (String playername : config.getKeys(false))
|
|
||||||
{
|
|
||||||
PERMBANNED_PLAYERS.add(playername.toLowerCase().trim());
|
|
||||||
|
|
||||||
List<String> playerIps = config.getStringList(playername);
|
|
||||||
for (String ip : playerIps)
|
|
||||||
{
|
|
||||||
ip = ip.trim();
|
|
||||||
if (!PERMBANNED_IPS.contains(ip))
|
|
||||||
{
|
|
||||||
PERMBANNED_IPS.add(ip);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TFM_Log.info("Loaded " + PERMBANNED_PLAYERS.size() + " permanently banned players and " + PERMBANNED_IPS.size() + " permanently banned IPs.");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,129 +0,0 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
|
||||||
|
|
||||||
public class TFM_Player
|
|
||||||
{
|
|
||||||
private final UUID uuid;
|
|
||||||
private String firstJoinName;
|
|
||||||
private String lastJoinName;
|
|
||||||
private long firstJoinUnix;
|
|
||||||
private long lastJoinUnix;
|
|
||||||
private final List<String> ips;
|
|
||||||
|
|
||||||
protected TFM_Player(UUID uuid, ConfigurationSection section)
|
|
||||||
{
|
|
||||||
this(uuid);
|
|
||||||
|
|
||||||
this.firstJoinName = section.getString("firstjoinname");
|
|
||||||
this.lastJoinName = section.getString("lastjoinname");
|
|
||||||
|
|
||||||
this.firstJoinUnix = section.getLong("firstjoinunix");
|
|
||||||
this.lastJoinUnix = section.getLong("lastjoinunix");
|
|
||||||
|
|
||||||
this.ips.addAll(section.getStringList("ips"));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected TFM_Player(UUID uuid, String firstJoinName, String lastJoinName, long firstJoinUnix, long lastJoinUnix, List<String> ips)
|
|
||||||
{
|
|
||||||
this(uuid);
|
|
||||||
|
|
||||||
this.firstJoinName = firstJoinName;
|
|
||||||
this.lastJoinName = lastJoinName;
|
|
||||||
|
|
||||||
this.firstJoinUnix = firstJoinUnix;
|
|
||||||
this.lastJoinUnix = lastJoinUnix;
|
|
||||||
|
|
||||||
this.ips.addAll(ips);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected TFM_Player(UUID uuid)
|
|
||||||
{
|
|
||||||
if (uuid == null)
|
|
||||||
{
|
|
||||||
throw new IllegalArgumentException("UUID can not be null!");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.uuid = uuid;
|
|
||||||
this.ips = new ArrayList<String>();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Getters / Setters below
|
|
||||||
public UUID getUniqueId()
|
|
||||||
{
|
|
||||||
return uuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getIps()
|
|
||||||
{
|
|
||||||
return Collections.unmodifiableList(ips);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFirstLoginName()
|
|
||||||
{
|
|
||||||
return firstJoinName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFirstLoginName(String firstJoinName)
|
|
||||||
{
|
|
||||||
this.firstJoinName = firstJoinName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLastLoginName()
|
|
||||||
{
|
|
||||||
return lastJoinName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLastLoginName(String lastJoinName)
|
|
||||||
{
|
|
||||||
this.lastJoinName = lastJoinName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getFirstLoginUnix()
|
|
||||||
{
|
|
||||||
return firstJoinUnix;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFirstLoginUnix(long firstJoinUnix)
|
|
||||||
{
|
|
||||||
this.firstJoinUnix = firstJoinUnix;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getLastLoginUnix()
|
|
||||||
{
|
|
||||||
return lastJoinUnix;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLastLoginUnix(long lastJoinUnix)
|
|
||||||
{
|
|
||||||
this.lastJoinUnix = lastJoinUnix;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean addIp(String ip)
|
|
||||||
{
|
|
||||||
if (!ips.contains(ip))
|
|
||||||
{
|
|
||||||
ips.add(ip);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final boolean isComplete()
|
|
||||||
{
|
|
||||||
return firstJoinName != null
|
|
||||||
&& lastJoinName != null
|
|
||||||
&& firstJoinUnix != 0
|
|
||||||
&& lastJoinUnix != 0
|
|
||||||
&& !ips.isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save()
|
|
||||||
{
|
|
||||||
TFM_PlayerList.save(this);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,200 +0,0 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod;
|
|
||||||
|
|
||||||
import com.google.common.collect.Sets;
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.Config.TFM_Config;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class TFM_PlayerList
|
|
||||||
{
|
|
||||||
|
|
||||||
private static final Map<UUID, TFM_Player> PLAYER_LIST = new HashMap<UUID, TFM_Player>();
|
|
||||||
|
|
||||||
private TFM_PlayerList()
|
|
||||||
{
|
|
||||||
throw new AssertionError();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Set<TFM_Player> getAllPlayers()
|
|
||||||
{
|
|
||||||
return Collections.unmodifiableSet(Sets.newHashSet(PLAYER_LIST.values()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void load()
|
|
||||||
{
|
|
||||||
PLAYER_LIST.clear();
|
|
||||||
|
|
||||||
// Load online players
|
|
||||||
for (Player player : Bukkit.getOnlinePlayers())
|
|
||||||
{
|
|
||||||
getEntry(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
TFM_Log.info("Loaded playerdata for " + PLAYER_LIST.size() + " players");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void saveAll()
|
|
||||||
{
|
|
||||||
for (TFM_Player entry : PLAYER_LIST.values())
|
|
||||||
{
|
|
||||||
save(entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// May return null
|
|
||||||
public static TFM_Player getEntry(UUID uuid)
|
|
||||||
{
|
|
||||||
if (PLAYER_LIST.containsKey(uuid))
|
|
||||||
{
|
|
||||||
return PLAYER_LIST.get(uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
final File configFile = getConfigFile(uuid);
|
|
||||||
|
|
||||||
if (!configFile.exists())
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
final TFM_Player entry = new TFM_Player(uuid, getConfig(uuid));
|
|
||||||
|
|
||||||
if (entry.isComplete())
|
|
||||||
{
|
|
||||||
PLAYER_LIST.put(uuid, entry);
|
|
||||||
return entry;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
TFM_Log.warning("Could not load entry: Entry is not complete!");
|
|
||||||
configFile.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static TFM_Player getEntry(Player player)
|
|
||||||
{
|
|
||||||
final UUID uuid = TFM_UuidManager.getUniqueId(player);
|
|
||||||
TFM_Player entry = getEntry(uuid);
|
|
||||||
|
|
||||||
if (entry != null)
|
|
||||||
{
|
|
||||||
return entry;
|
|
||||||
}
|
|
||||||
|
|
||||||
final long unix = TFM_Util.getUnixTime();
|
|
||||||
entry = new TFM_Player(uuid);
|
|
||||||
entry.setFirstLoginName(player.getName());
|
|
||||||
entry.setLastLoginName(player.getName());
|
|
||||||
entry.setFirstLoginUnix(unix);
|
|
||||||
entry.setLastLoginUnix(unix);
|
|
||||||
entry.addIp(TFM_Util.getIp(player));
|
|
||||||
|
|
||||||
save(entry);
|
|
||||||
PLAYER_LIST.put(uuid, entry);
|
|
||||||
|
|
||||||
return entry;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void removeEntry(Player player)
|
|
||||||
{
|
|
||||||
final UUID uuid = TFM_UuidManager.getUniqueId(player);
|
|
||||||
|
|
||||||
if (!PLAYER_LIST.containsKey(uuid))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
save(PLAYER_LIST.get(uuid));
|
|
||||||
|
|
||||||
PLAYER_LIST.remove(uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean existsEntry(Player player)
|
|
||||||
{
|
|
||||||
return existsEntry(TFM_UuidManager.getUniqueId(player));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean existsEntry(UUID uuid)
|
|
||||||
{
|
|
||||||
return getConfigFile(uuid).exists();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setUniqueId(TFM_Player entry, UUID newUuid)
|
|
||||||
{
|
|
||||||
if (entry.getUniqueId().equals(newUuid))
|
|
||||||
{
|
|
||||||
TFM_Log.warning("Not setting new UUID: UUIDs match!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add new entry
|
|
||||||
final TFM_Player newEntry = new TFM_Player(
|
|
||||||
newUuid,
|
|
||||||
entry.getFirstLoginName(),
|
|
||||||
entry.getLastLoginName(),
|
|
||||||
entry.getFirstLoginUnix(),
|
|
||||||
entry.getLastLoginUnix(),
|
|
||||||
entry.getIps());
|
|
||||||
newEntry.save();
|
|
||||||
PLAYER_LIST.put(newUuid, newEntry);
|
|
||||||
|
|
||||||
// Remove old entry
|
|
||||||
PLAYER_LIST.remove(entry.getUniqueId());
|
|
||||||
final File oldFile = getConfigFile(entry.getUniqueId());
|
|
||||||
if (oldFile.exists() && !oldFile.delete())
|
|
||||||
{
|
|
||||||
TFM_Log.warning("Could not delete config: " + getConfigFile(entry.getUniqueId()).getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void purgeAll()
|
|
||||||
{
|
|
||||||
for (File file : getConfigFolder().listFiles())
|
|
||||||
{
|
|
||||||
file.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load online players
|
|
||||||
load();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static File getConfigFolder()
|
|
||||||
{
|
|
||||||
return new File(TotalFreedomMod.plugin.getDataFolder(), "players");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static File getConfigFile(UUID uuid)
|
|
||||||
{
|
|
||||||
return new File(getConfigFolder(), uuid + ".yml");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static TFM_Config getConfig(UUID uuid)
|
|
||||||
{
|
|
||||||
final TFM_Config config = new TFM_Config(TotalFreedomMod.plugin, getConfigFile(uuid), false);
|
|
||||||
config.load();
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void save(TFM_Player entry)
|
|
||||||
{
|
|
||||||
if (!entry.isComplete())
|
|
||||||
{
|
|
||||||
throw new IllegalArgumentException("Entry is not complete!");
|
|
||||||
}
|
|
||||||
|
|
||||||
final TFM_Config config = getConfig(entry.getUniqueId());
|
|
||||||
config.set("firstjoinname", entry.getFirstLoginName());
|
|
||||||
config.set("lastjoinname", entry.getLastLoginName());
|
|
||||||
config.set("firstjoinunix", entry.getFirstLoginUnix());
|
|
||||||
config.set("lastjoinunix", entry.getLastLoginUnix());
|
|
||||||
config.set("ips", entry.getIps());
|
|
||||||
config.save();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,121 +0,0 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod;
|
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
|
|
||||||
import static me.StevenLawson.TotalFreedomMod.TFM_Util.DEVELOPERS;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public enum TFM_PlayerRank
|
|
||||||
{
|
|
||||||
DEVELOPER("a " + ChatColor.DARK_PURPLE + "Developer", ChatColor.DARK_PURPLE + "[Dev]"),
|
|
||||||
IMPOSTOR("an " + ChatColor.YELLOW + ChatColor.UNDERLINE + "Impostor", ChatColor.YELLOW.toString() + ChatColor.UNDERLINE + "[IMP]"),
|
|
||||||
NON_OP("a " + ChatColor.GREEN + "Non-OP", ChatColor.GREEN.toString()),
|
|
||||||
OP("an " + ChatColor.RED + "OP", ChatColor.RED + "[OP]"),
|
|
||||||
SUPER("a " + ChatColor.GOLD + "Super Admin", ChatColor.GOLD + "[SA]"),
|
|
||||||
TELNET("a " + ChatColor.DARK_GREEN + "Super Telnet Admin", ChatColor.DARK_GREEN + "[STA]"),
|
|
||||||
SENIOR("a " + ChatColor.LIGHT_PURPLE + "Senior Admin", ChatColor.LIGHT_PURPLE + "[SrA]"),
|
|
||||||
OWNER("the " + ChatColor.BLUE + "Owner", ChatColor.BLUE + "[Owner]"),
|
|
||||||
CONSOLE("The " + ChatColor.DARK_PURPLE + "Console", ChatColor.DARK_PURPLE + "[Console]");
|
|
||||||
private final String loginMessage;
|
|
||||||
private final String prefix;
|
|
||||||
|
|
||||||
private TFM_PlayerRank(String loginMessage, String prefix)
|
|
||||||
{
|
|
||||||
this.loginMessage = loginMessage;
|
|
||||||
this.prefix = prefix;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getLoginMessage(CommandSender sender)
|
|
||||||
{
|
|
||||||
// Handle console
|
|
||||||
if (!(sender instanceof Player))
|
|
||||||
{
|
|
||||||
return fromSender(sender).getLoginMessage();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle admins
|
|
||||||
final TFM_Admin entry = TFM_AdminList.getEntry((Player) sender);
|
|
||||||
if (entry == null)
|
|
||||||
{
|
|
||||||
// Player is not an admin
|
|
||||||
return fromSender(sender).getLoginMessage();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Custom login message
|
|
||||||
final String loginMessage = entry.getCustomLoginMessage();
|
|
||||||
|
|
||||||
if (loginMessage == null || loginMessage.isEmpty())
|
|
||||||
{
|
|
||||||
return fromSender(sender).getLoginMessage();
|
|
||||||
}
|
|
||||||
|
|
||||||
return ChatColor.translateAlternateColorCodes('&', loginMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static TFM_PlayerRank fromSender(CommandSender sender)
|
|
||||||
{
|
|
||||||
if (!(sender instanceof Player))
|
|
||||||
{
|
|
||||||
return CONSOLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TFM_AdminList.isAdminImpostor((Player) sender))
|
|
||||||
{
|
|
||||||
return IMPOSTOR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (DEVELOPERS.contains(sender.getName()))
|
|
||||||
{
|
|
||||||
return DEVELOPER;
|
|
||||||
}
|
|
||||||
|
|
||||||
final TFM_Admin entry = TFM_AdminList.getEntryByIp(TFM_Util.getIp((Player) sender));
|
|
||||||
|
|
||||||
final TFM_PlayerRank rank;
|
|
||||||
|
|
||||||
if (entry != null && entry.isActivated())
|
|
||||||
{
|
|
||||||
if (TFM_ConfigEntry.SERVER_OWNERS.getList().contains(sender.getName()))
|
|
||||||
{
|
|
||||||
return OWNER;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entry.isSeniorAdmin())
|
|
||||||
{
|
|
||||||
rank = SENIOR;
|
|
||||||
}
|
|
||||||
else if (entry.isTelnetAdmin())
|
|
||||||
{
|
|
||||||
rank = TELNET;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rank = SUPER;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (sender.isOp())
|
|
||||||
{
|
|
||||||
rank = OP;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rank = NON_OP;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return rank;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPrefix()
|
|
||||||
{
|
|
||||||
return prefix;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLoginMessage()
|
|
||||||
{
|
|
||||||
return loginMessage;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,315 +0,0 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.ListIterator;
|
|
||||||
import java.util.Map;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
|
||||||
|
|
||||||
public class TFM_RollbackManager
|
|
||||||
{
|
|
||||||
private static final Map<String, List<RollbackEntry>> PLAYER_HISTORY = new HashMap<String, List<RollbackEntry>>();
|
|
||||||
private static final List<String> REMOVE_ROLLBACK_HISTORY = new ArrayList<String>();
|
|
||||||
|
|
||||||
private TFM_RollbackManager()
|
|
||||||
{
|
|
||||||
throw new AssertionError();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void blockPlace(org.bukkit.event.block.BlockPlaceEvent event)
|
|
||||||
{
|
|
||||||
storeEntry(event.getPlayer(), new RollbackEntry(event.getPlayer().getName(), event.getBlock(), EntryType.BLOCK_PLACE));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void blockBreak(org.bukkit.event.block.BlockBreakEvent event)
|
|
||||||
{
|
|
||||||
storeEntry(event.getPlayer(), new RollbackEntry(event.getPlayer().getName(), event.getBlock(), EntryType.BLOCK_BREAK));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void storeEntry(Player player, RollbackEntry entry)
|
|
||||||
{
|
|
||||||
List<RollbackEntry> playerEntryList = getEntriesByPlayer(player.getName());
|
|
||||||
|
|
||||||
if (playerEntryList != null)
|
|
||||||
{
|
|
||||||
playerEntryList.add(0, entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// May return null
|
|
||||||
public static String findPlayer(String partial)
|
|
||||||
{
|
|
||||||
partial = partial.toLowerCase();
|
|
||||||
|
|
||||||
for (String player : PLAYER_HISTORY.keySet())
|
|
||||||
{
|
|
||||||
if (player.toLowerCase().equals(partial))
|
|
||||||
{
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (String player : PLAYER_HISTORY.keySet())
|
|
||||||
{
|
|
||||||
if (player.toLowerCase().contains(partial))
|
|
||||||
{
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int purgeEntries()
|
|
||||||
{
|
|
||||||
Iterator<List<RollbackEntry>> it = PLAYER_HISTORY.values().iterator();
|
|
||||||
while (it.hasNext())
|
|
||||||
{
|
|
||||||
List<RollbackEntry> playerEntryList = it.next();
|
|
||||||
if (playerEntryList != null)
|
|
||||||
{
|
|
||||||
playerEntryList.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return PLAYER_HISTORY.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int purgeEntries(String playerName)
|
|
||||||
{
|
|
||||||
List<RollbackEntry> playerEntryList = getEntriesByPlayer(playerName);
|
|
||||||
|
|
||||||
if (playerEntryList == null)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int count = playerEntryList.size();
|
|
||||||
playerEntryList.clear();
|
|
||||||
return count;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean canRollback(String playerName)
|
|
||||||
{
|
|
||||||
return PLAYER_HISTORY.containsKey(playerName.toLowerCase()) && !PLAYER_HISTORY.get(playerName.toLowerCase()).isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean canUndoRollback(String playerName)
|
|
||||||
{
|
|
||||||
return REMOVE_ROLLBACK_HISTORY.contains(playerName.toLowerCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int rollback(final String playerName)
|
|
||||||
{
|
|
||||||
final List<RollbackEntry> entries = getEntriesByPlayer(playerName);
|
|
||||||
if (entries == null)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int count = entries.size();
|
|
||||||
for (RollbackEntry entry : entries)
|
|
||||||
{
|
|
||||||
if (entry != null)
|
|
||||||
{
|
|
||||||
entry.restore();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!REMOVE_ROLLBACK_HISTORY.contains(playerName.toLowerCase()))
|
|
||||||
{
|
|
||||||
REMOVE_ROLLBACK_HISTORY.add(playerName.toLowerCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
new BukkitRunnable()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
if (REMOVE_ROLLBACK_HISTORY.contains(playerName.toLowerCase()))
|
|
||||||
{
|
|
||||||
REMOVE_ROLLBACK_HISTORY.remove(playerName.toLowerCase());
|
|
||||||
purgeEntries(playerName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.runTaskLater(TotalFreedomMod.plugin, 40L * 20L);
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int undoRollback(String playerName)
|
|
||||||
{
|
|
||||||
final List<RollbackEntry> entries = getEntriesByPlayer(playerName);
|
|
||||||
|
|
||||||
if (entries == null)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
final int count = entries.size();
|
|
||||||
|
|
||||||
final ListIterator<RollbackEntry> it = entries.listIterator(count);
|
|
||||||
while (it.hasPrevious())
|
|
||||||
{
|
|
||||||
RollbackEntry entry = it.previous();
|
|
||||||
if (entry != null)
|
|
||||||
{
|
|
||||||
entry.redo();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (REMOVE_ROLLBACK_HISTORY.contains(playerName.toLowerCase()))
|
|
||||||
{
|
|
||||||
REMOVE_ROLLBACK_HISTORY.remove(playerName.toLowerCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<RollbackEntry> getEntriesAtLocation(final Location location)
|
|
||||||
{
|
|
||||||
final int testX = location.getBlockX();
|
|
||||||
final short testY = (short) location.getBlockY();
|
|
||||||
final int testZ = location.getBlockZ();
|
|
||||||
final String testWorldName = location.getWorld().getName();
|
|
||||||
|
|
||||||
List<RollbackEntry> entries = new ArrayList<RollbackEntry>();
|
|
||||||
for (String playername : PLAYER_HISTORY.keySet())
|
|
||||||
{
|
|
||||||
for (RollbackEntry entry : PLAYER_HISTORY.get(playername.toLowerCase()))
|
|
||||||
{
|
|
||||||
if (testX == entry.x && testY == entry.y && testZ == entry.z && testWorldName.equals(entry.worldName))
|
|
||||||
{
|
|
||||||
entries.add(0, entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return entries;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<RollbackEntry> getEntriesByPlayer(String playerName)
|
|
||||||
{
|
|
||||||
playerName = playerName.toLowerCase();
|
|
||||||
List<RollbackEntry> playerEntryList = PLAYER_HISTORY.get(playerName.toLowerCase());
|
|
||||||
if (playerEntryList == null)
|
|
||||||
{
|
|
||||||
playerEntryList = new ArrayList<RollbackEntry>();
|
|
||||||
PLAYER_HISTORY.put(playerName.toLowerCase(), playerEntryList);
|
|
||||||
}
|
|
||||||
return playerEntryList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum EntryType
|
|
||||||
{
|
|
||||||
BLOCK_PLACE("placed"),
|
|
||||||
BLOCK_BREAK("broke");
|
|
||||||
private final String action;
|
|
||||||
|
|
||||||
private EntryType(String action)
|
|
||||||
{
|
|
||||||
this.action = action;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString()
|
|
||||||
{
|
|
||||||
return this.action;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class RollbackEntry
|
|
||||||
{
|
|
||||||
// Use of primitives to decrease overhead
|
|
||||||
public final String author;
|
|
||||||
public final String worldName;
|
|
||||||
public final int x;
|
|
||||||
public final short y;
|
|
||||||
public final int z;
|
|
||||||
public final byte data;
|
|
||||||
public final Material blockMaterial;
|
|
||||||
private final boolean isBreak;
|
|
||||||
|
|
||||||
private RollbackEntry(String author, Block block, EntryType entryType)
|
|
||||||
{
|
|
||||||
final Location location = block.getLocation();
|
|
||||||
|
|
||||||
this.x = location.getBlockX();
|
|
||||||
this.y = (short) location.getBlockY();
|
|
||||||
this.z = location.getBlockZ();
|
|
||||||
this.worldName = location.getWorld().getName();
|
|
||||||
this.author = author;
|
|
||||||
|
|
||||||
if (entryType == EntryType.BLOCK_BREAK)
|
|
||||||
{
|
|
||||||
this.blockMaterial = block.getType();
|
|
||||||
this.data = TFM_DepreciationAggregator.getData_Block(block);
|
|
||||||
this.isBreak = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.blockMaterial = block.getType();
|
|
||||||
this.data = TFM_DepreciationAggregator.getData_Block(block);
|
|
||||||
this.isBreak = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Location getLocation()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return new Location(Bukkit.getWorld(worldName), x, (int) y, z);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
TFM_Log.warning("Could not get location of rollback entry at (" + worldName + ":" + x + "," + y + "," + x + ")!");
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Material getMaterial()
|
|
||||||
{
|
|
||||||
return blockMaterial;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EntryType getType()
|
|
||||||
{
|
|
||||||
return (isBreak ? EntryType.BLOCK_BREAK : EntryType.BLOCK_PLACE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void restore()
|
|
||||||
{
|
|
||||||
final Block block = Bukkit.getWorld(worldName).getBlockAt(x, y, z);
|
|
||||||
if (isBreak)
|
|
||||||
{
|
|
||||||
block.setType(getMaterial());
|
|
||||||
TFM_DepreciationAggregator.setData_Block(block, data);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
block.setType(Material.AIR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void redo()
|
|
||||||
{
|
|
||||||
final Block block = Bukkit.getWorld(worldName).getBlockAt(x, y, z);
|
|
||||||
|
|
||||||
if (isBreak)
|
|
||||||
{
|
|
||||||
block.setType(Material.AIR);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
block.setType(getMaterial());
|
|
||||||
TFM_DepreciationAggregator.setData_Block(block, data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,310 +0,0 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.security.MessageDigest;
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.Callable;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.SQL.TFM_SqlUtil;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.SQL.TFM_SqliteDatabase;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.SQL.TFM_SqliteDatabase.Statement;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.json.simple.JSONArray;
|
|
||||||
import org.json.simple.JSONObject;
|
|
||||||
import org.json.simple.parser.JSONParser;
|
|
||||||
|
|
||||||
public class TFM_UuidManager
|
|
||||||
{
|
|
||||||
|
|
||||||
public static final String TABLE_NAME = "uuids";
|
|
||||||
private static final TFM_SqliteDatabase SQL;
|
|
||||||
private static final Statement FIND;
|
|
||||||
private static final Statement UPDATE;
|
|
||||||
|
|
||||||
private TFM_UuidManager()
|
|
||||||
{
|
|
||||||
throw new AssertionError();
|
|
||||||
}
|
|
||||||
|
|
||||||
static
|
|
||||||
{
|
|
||||||
SQL = new TFM_SqliteDatabase(
|
|
||||||
"uuids.db",
|
|
||||||
TABLE_NAME,
|
|
||||||
"username VARCHAR(" + TotalFreedomMod.MAX_USERNAME_LENGTH + ") NOT NULL PRIMARY KEY, uuid CHAR(36) NOT NULL");
|
|
||||||
|
|
||||||
FIND = SQL.addPreparedStatement("SELECT * FROM " + TABLE_NAME + " WHERE lower(username) = ?;");
|
|
||||||
UPDATE = SQL.addPreparedStatement("REPLACE INTO " + TABLE_NAME + " (username, uuid) VALUES (?, ?);");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void load()
|
|
||||||
{
|
|
||||||
// Init DB
|
|
||||||
SQL.connect();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void close()
|
|
||||||
{
|
|
||||||
SQL.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int purge()
|
|
||||||
{
|
|
||||||
return SQL.purge();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static UUID newPlayer(Player player, String ip)
|
|
||||||
{
|
|
||||||
TFM_Log.info("Obtaining UUID for new player: " + player.getName());
|
|
||||||
|
|
||||||
final String username = player.getName().toLowerCase();
|
|
||||||
|
|
||||||
// Look in DB
|
|
||||||
final UUID dbUuid = find(username);
|
|
||||||
if (dbUuid != null)
|
|
||||||
{
|
|
||||||
return dbUuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find UUID and update in DB if not found
|
|
||||||
// Try API
|
|
||||||
UUID uuid = TFM_UuidResolver.getUUIDOf(username);
|
|
||||||
if (uuid == null)
|
|
||||||
{
|
|
||||||
// Spoof
|
|
||||||
uuid = generateSpoofUuid(username);
|
|
||||||
}
|
|
||||||
|
|
||||||
update(username, uuid);
|
|
||||||
return uuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static UUID getUniqueId(OfflinePlayer offlinePlayer)
|
|
||||||
{
|
|
||||||
// Online check first
|
|
||||||
if (offlinePlayer.isOnline() && TFM_PlayerData.hasPlayerData(offlinePlayer.getPlayer()))
|
|
||||||
{
|
|
||||||
return TFM_PlayerData.getPlayerData(offlinePlayer.getPlayer()).getUniqueId();
|
|
||||||
}
|
|
||||||
|
|
||||||
// DB, API, Spoof
|
|
||||||
return getUniqueId(offlinePlayer.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static UUID getUniqueId(String username)
|
|
||||||
{
|
|
||||||
// Look in DB
|
|
||||||
final UUID dbUuid = find(username);
|
|
||||||
if (dbUuid != null)
|
|
||||||
{
|
|
||||||
return dbUuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try API
|
|
||||||
final UUID apiUuid = TFM_UuidResolver.getUUIDOf(username);
|
|
||||||
if (apiUuid != null)
|
|
||||||
{
|
|
||||||
return apiUuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Spoof
|
|
||||||
return generateSpoofUuid(username);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void rawSetUUID(String name, UUID uuid)
|
|
||||||
{
|
|
||||||
if (name == null || uuid == null || name.isEmpty())
|
|
||||||
{
|
|
||||||
TFM_Log.warning("Not setting raw UUID: name and uuid may not be null!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
update(name.toLowerCase().trim(), uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static UUID find(String searchName)
|
|
||||||
{
|
|
||||||
if (!SQL.connect())
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
final ResultSet result;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
final PreparedStatement statement = FIND.getStatement();
|
|
||||||
statement.clearParameters();
|
|
||||||
statement.setString(1, searchName.toLowerCase());
|
|
||||||
result = statement.executeQuery();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
TFM_Log.severe("Could not execute find statement!");
|
|
||||||
TFM_Log.severe(ex);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!TFM_SqlUtil.hasData(result))
|
|
||||||
{
|
|
||||||
TFM_SqlUtil.close(result);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
final String uuidString = result.getString("uuid");
|
|
||||||
return UUID.fromString(uuidString);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
TFM_Log.severe(ex);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
TFM_SqlUtil.close(result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean update(String username, UUID uuid)
|
|
||||||
{
|
|
||||||
if (!SQL.connect())
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
final PreparedStatement statement = UPDATE.getStatement();
|
|
||||||
statement.clearParameters();
|
|
||||||
statement.setString(1, username.toLowerCase());
|
|
||||||
statement.setString(2, uuid.toString());
|
|
||||||
statement.executeUpdate();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
TFM_Log.severe("Could not execute update statement!");
|
|
||||||
TFM_Log.severe(ex);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static UUID generateSpoofUuid(String name)
|
|
||||||
{
|
|
||||||
name = name.toLowerCase();
|
|
||||||
TFM_Log.info("Generating spoof UUID for " + name);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
final MessageDigest digest = MessageDigest.getInstance("SHA1");
|
|
||||||
final byte[] result = digest.digest(name.getBytes());
|
|
||||||
final StringBuilder builder = new StringBuilder();
|
|
||||||
for (int i = 0; i < result.length; i++)
|
|
||||||
{
|
|
||||||
builder.append(Integer.toString((result[i] & 0xff) + 0x100, 16).substring(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
return UUID.fromString(
|
|
||||||
"deadbeef"
|
|
||||||
+ "-" + builder.substring(8, 12)
|
|
||||||
+ "-" + builder.substring(12, 16)
|
|
||||||
+ "-" + builder.substring(16, 20)
|
|
||||||
+ "-" + builder.substring(20, 32));
|
|
||||||
}
|
|
||||||
catch (NoSuchAlgorithmException ex)
|
|
||||||
{
|
|
||||||
TFM_Log.warning("Could not generate spoof UUID: SHA1 algorithm not found!");
|
|
||||||
}
|
|
||||||
|
|
||||||
return UUID.randomUUID();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class TFM_UuidResolver implements Callable<Map<String, UUID>>
|
|
||||||
{
|
|
||||||
|
|
||||||
private static final double PROFILES_PER_REQUEST = 100;
|
|
||||||
private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft";
|
|
||||||
private final JSONParser jsonParser = new JSONParser();
|
|
||||||
private final List<String> names;
|
|
||||||
|
|
||||||
public TFM_UuidResolver(List<String> names)
|
|
||||||
{
|
|
||||||
this.names = ImmutableList.copyOf(names);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, UUID> call()
|
|
||||||
{
|
|
||||||
final Map<String, UUID> uuidMap = new HashMap<String, UUID>();
|
|
||||||
int requests = (int) Math.ceil(names.size() / PROFILES_PER_REQUEST);
|
|
||||||
for (int i = 0; i < requests; i++)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
final URL url = new URL(PROFILE_URL);
|
|
||||||
final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
||||||
|
|
||||||
connection.setRequestMethod("POST");
|
|
||||||
connection.setRequestProperty("Content-Type", "application/json");
|
|
||||||
connection.setUseCaches(false);
|
|
||||||
connection.setDoInput(true);
|
|
||||||
connection.setDoOutput(true);
|
|
||||||
|
|
||||||
final String body = JSONArray.toJSONString(names.subList(i * 100, Math.min((i + 1) * 100, names.size())));
|
|
||||||
|
|
||||||
final OutputStream stream = connection.getOutputStream();
|
|
||||||
stream.write(body.getBytes());
|
|
||||||
stream.flush();
|
|
||||||
stream.close();
|
|
||||||
|
|
||||||
final JSONArray array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream()));
|
|
||||||
|
|
||||||
for (Object profile : array)
|
|
||||||
{
|
|
||||||
final JSONObject jsonProfile = (JSONObject) profile;
|
|
||||||
final String id = (String) jsonProfile.get("id");
|
|
||||||
final String name = (String) jsonProfile.get("name");
|
|
||||||
final UUID uuid = UUID.fromString(
|
|
||||||
id.substring(0, 8)
|
|
||||||
+ "-" + id.substring(8, 12)
|
|
||||||
+ "-" + id.substring(12, 16)
|
|
||||||
+ "-" + id.substring(16, 20)
|
|
||||||
+ "-" + id.substring(20, 32));
|
|
||||||
uuidMap.put(name, uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i != requests - 1)
|
|
||||||
{
|
|
||||||
Thread.sleep(100L);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
TFM_Log.severe("Could not resolve UUID(s) of "
|
|
||||||
+ StringUtils.join(names.subList(i * 100, Math.min((i + 1) * 100, names.size())), ", "));
|
|
||||||
//TFM_Log.severe(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return uuidMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static UUID getUUIDOf(String name)
|
|
||||||
{
|
|
||||||
return new TFM_UuidResolver(Arrays.asList(name)).call().get(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,250 +0,0 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod;
|
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Properties;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.Bridge.TFM_BukkitTelnetListener;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.Bridge.TFM_WorldEditListener;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandHandler;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.HTTPD.TFM_HTTPD_Manager;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.Listener.TFM_BlockListener;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.Listener.TFM_EntityListener;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.Listener.TFM_PlayerListener;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.Listener.TFM_ServerListener;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.Listener.TFM_WeatherListener;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.World.TFM_AdminWorld;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.World.TFM_Flatlands;
|
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.PluginManager;
|
|
||||||
import org.bukkit.plugin.ServicePriority;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
|
||||||
import org.mcstats.Metrics;
|
|
||||||
|
|
||||||
public class TotalFreedomMod extends JavaPlugin
|
|
||||||
{
|
|
||||||
public static final long HEARTBEAT_RATE = 5L; // Seconds
|
|
||||||
public static final long SERVICE_CHECKER_RATE = 120L;
|
|
||||||
public static final int MAX_USERNAME_LENGTH = 20;
|
|
||||||
//
|
|
||||||
public static final String CONFIG_FILENAME = "config.yml";
|
|
||||||
public static final String SUPERADMIN_FILENAME = "superadmin.yml";
|
|
||||||
public static final String PERMBAN_FILENAME = "permban.yml";
|
|
||||||
public static final String UUID_FILENAME = "uuids.db";
|
|
||||||
public static final String PROTECTED_AREA_FILENAME = "protectedareas.dat";
|
|
||||||
public static final String SAVED_FLAGS_FILENAME = "savedflags.dat";
|
|
||||||
//
|
|
||||||
public static final BuildProperties build = new BuildProperties();
|
|
||||||
@Deprecated
|
|
||||||
public static final String YOU_ARE_NOT_OP = me.StevenLawson.TotalFreedomMod.Commands.TFM_Command.YOU_ARE_NOT_OP;
|
|
||||||
//
|
|
||||||
public static Server server;
|
|
||||||
public static TotalFreedomMod plugin;
|
|
||||||
public static String pluginName;
|
|
||||||
public static String pluginVersion;
|
|
||||||
//
|
|
||||||
public static boolean lockdownEnabled = false;
|
|
||||||
public static Map<Player, Double> fuckoffEnabledFor = new HashMap<Player, Double>();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLoad()
|
|
||||||
{
|
|
||||||
TotalFreedomMod.plugin = this;
|
|
||||||
TotalFreedomMod.server = plugin.getServer();
|
|
||||||
TotalFreedomMod.pluginName = plugin.getDescription().getName();
|
|
||||||
TotalFreedomMod.pluginVersion = plugin.getDescription().getVersion();
|
|
||||||
|
|
||||||
TFM_Log.setPluginLogger(plugin.getLogger());
|
|
||||||
TFM_Log.setServerLogger(server.getLogger());
|
|
||||||
|
|
||||||
build.load();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onEnable()
|
|
||||||
{
|
|
||||||
TFM_Log.info("Created by Madgeek1450 and Prozza");
|
|
||||||
TFM_Log.info("Version " + build.formattedVersion());
|
|
||||||
TFM_Log.info("Compiled " + build.date + " by " + build.builder);
|
|
||||||
|
|
||||||
final TFM_Util.MethodTimer timer = new TFM_Util.MethodTimer();
|
|
||||||
timer.start();
|
|
||||||
|
|
||||||
if (!TFM_ServerInterface.COMPILE_NMS_VERSION.equals(TFM_Util.getNmsVersion()))
|
|
||||||
{
|
|
||||||
TFM_Log.warning(pluginName + " is compiled for " + TFM_ServerInterface.COMPILE_NMS_VERSION + " but the server is running "
|
|
||||||
+ "version " + TFM_Util.getNmsVersion() + "!");
|
|
||||||
TFM_Log.warning("This might result in unexpected behaviour!");
|
|
||||||
}
|
|
||||||
|
|
||||||
TFM_Util.deleteCoreDumps();
|
|
||||||
TFM_Util.deleteFolder(new File("./_deleteme"));
|
|
||||||
|
|
||||||
// Create backups
|
|
||||||
TFM_Util.createBackups(CONFIG_FILENAME, true);
|
|
||||||
TFM_Util.createBackups(SUPERADMIN_FILENAME);
|
|
||||||
TFM_Util.createBackups(PERMBAN_FILENAME);
|
|
||||||
|
|
||||||
// Load services
|
|
||||||
TFM_UuidManager.load();
|
|
||||||
TFM_AdminList.load();
|
|
||||||
TFM_PermbanList.load();
|
|
||||||
TFM_PlayerList.load();
|
|
||||||
TFM_BanManager.load();
|
|
||||||
TFM_Announcer.load();
|
|
||||||
TFM_ProtectedArea.load();
|
|
||||||
|
|
||||||
// Start SuperAdmin service
|
|
||||||
server.getServicesManager().register(Function.class, TFM_AdminList.SUPERADMIN_SERVICE, plugin, ServicePriority.Normal);
|
|
||||||
|
|
||||||
final PluginManager pm = server.getPluginManager();
|
|
||||||
pm.registerEvents(new TFM_EntityListener(), plugin);
|
|
||||||
pm.registerEvents(new TFM_BlockListener(), plugin);
|
|
||||||
pm.registerEvents(new TFM_PlayerListener(), plugin);
|
|
||||||
pm.registerEvents(new TFM_WeatherListener(), plugin);
|
|
||||||
pm.registerEvents(new TFM_ServerListener(), plugin);
|
|
||||||
|
|
||||||
// Bridge
|
|
||||||
pm.registerEvents(new TFM_BukkitTelnetListener(), plugin);
|
|
||||||
pm.registerEvents(new TFM_WorldEditListener(), plugin);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
TFM_Flatlands.getInstance().getWorld();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
TFM_Log.warning("Could not load world: Flatlands");
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
TFM_AdminWorld.getInstance().getWorld();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
TFM_Log.warning("Could not load world: AdminWorld");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize game rules
|
|
||||||
TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.DO_DAYLIGHT_CYCLE, !TFM_ConfigEntry.DISABLE_NIGHT.getBoolean(), false);
|
|
||||||
TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.DO_FIRE_TICK, TFM_ConfigEntry.ALLOW_FIRE_SPREAD.getBoolean(), false);
|
|
||||||
TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.DO_MOB_LOOT, false, false);
|
|
||||||
TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.DO_MOB_SPAWNING, !TFM_ConfigEntry.MOB_LIMITER_ENABLED.getBoolean(), false);
|
|
||||||
TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.DO_TILE_DROPS, false, false);
|
|
||||||
TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.MOB_GRIEFING, false, false);
|
|
||||||
TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.NATURAL_REGENERATION, true, false);
|
|
||||||
TFM_GameRuleHandler.commitGameRules();
|
|
||||||
|
|
||||||
// Disable weather
|
|
||||||
if (TFM_ConfigEntry.DISABLE_WEATHER.getBoolean())
|
|
||||||
{
|
|
||||||
for (World world : server.getWorlds())
|
|
||||||
{
|
|
||||||
world.setThundering(false);
|
|
||||||
world.setStorm(false);
|
|
||||||
world.setThunderDuration(0);
|
|
||||||
world.setWeatherDuration(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Heartbeat
|
|
||||||
new TFM_Heartbeat(plugin).runTaskTimer(plugin, HEARTBEAT_RATE * 20L, HEARTBEAT_RATE * 20L);
|
|
||||||
|
|
||||||
// Start services
|
|
||||||
TFM_ServiceChecker.start();
|
|
||||||
TFM_HTTPD_Manager.start();
|
|
||||||
TFM_FrontDoor.start();
|
|
||||||
TFM_CommandBlocker.load();
|
|
||||||
|
|
||||||
timer.update();
|
|
||||||
|
|
||||||
TFM_Log.info("Version " + pluginVersion + " for " + TFM_ServerInterface.COMPILE_NMS_VERSION + " enabled in " + timer.getTotal() + "ms");
|
|
||||||
|
|
||||||
// Metrics @ http://mcstats.org/plugin/TotalFreedomMod
|
|
||||||
try
|
|
||||||
{
|
|
||||||
final Metrics metrics = new Metrics(plugin);
|
|
||||||
metrics.start();
|
|
||||||
}
|
|
||||||
catch (IOException ex)
|
|
||||||
{
|
|
||||||
TFM_Log.warning("Failed to submit metrics data: " + ex.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
new BukkitRunnable()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
TFM_CommandLoader.scan();
|
|
||||||
|
|
||||||
// Add spawnpoints later - https://github.com/TotalFreedom/TotalFreedomMod/issues/438
|
|
||||||
TFM_ProtectedArea.autoAddSpawnpoints();
|
|
||||||
}
|
|
||||||
}.runTaskLater(plugin, 20L);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDisable()
|
|
||||||
{
|
|
||||||
TFM_HTTPD_Manager.stop();
|
|
||||||
TFM_BanManager.save();
|
|
||||||
TFM_UuidManager.close();
|
|
||||||
TFM_FrontDoor.stop();
|
|
||||||
|
|
||||||
server.getScheduler().cancelTasks(plugin);
|
|
||||||
|
|
||||||
TFM_Log.info("Plugin disabled");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
|
|
||||||
{
|
|
||||||
return TFM_CommandHandler.handleCommand(sender, cmd, commandLabel, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class BuildProperties {
|
|
||||||
public String builder;
|
|
||||||
public String number;
|
|
||||||
public String head;
|
|
||||||
public String date;
|
|
||||||
|
|
||||||
public void load() {
|
|
||||||
try
|
|
||||||
{
|
|
||||||
final InputStream in = plugin.getResource("build.properties");
|
|
||||||
|
|
||||||
final Properties props = new Properties();
|
|
||||||
props.load(in);
|
|
||||||
in.close();
|
|
||||||
|
|
||||||
builder = props.getProperty("program.builder", "unknown");
|
|
||||||
number = props.getProperty("program.buildnumber", "1");
|
|
||||||
head = props.getProperty("program.buildhead", "unknown");
|
|
||||||
date = props.getProperty("program.builddate", "unknown");
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
TFM_Log.severe("Could not load build properties! Did you compile with Netbeans/ANT?");
|
|
||||||
TFM_Log.severe(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String formattedVersion() {
|
|
||||||
return pluginVersion + "." + number + " (" + head + ")";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,56 +0,0 @@
|
|||||||
package me.husky;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Abstract Database class, serves as a base for any connection method (MySQL,
|
|
||||||
* SQLite, etc.)
|
|
||||||
*
|
|
||||||
* @author -_Husky_-
|
|
||||||
* @author tips48
|
|
||||||
*/
|
|
||||||
public abstract class Database
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Plugin instance, use for plugin.getDataFolder() and plugin.getLogger()
|
|
||||||
*/
|
|
||||||
protected Plugin plugin;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new Database
|
|
||||||
*
|
|
||||||
* @param plugin Plugin instance
|
|
||||||
*/
|
|
||||||
protected Database(Plugin plugin)
|
|
||||||
{
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Opens a connection with the database
|
|
||||||
*
|
|
||||||
* @return Connection opened
|
|
||||||
*/
|
|
||||||
public abstract Connection openConnection();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if a connection is open with the database
|
|
||||||
*
|
|
||||||
* @return true if a connection is open
|
|
||||||
*/
|
|
||||||
public abstract boolean checkConnection();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the connection with the database
|
|
||||||
*
|
|
||||||
* @return Connection with the database, null if none
|
|
||||||
*/
|
|
||||||
public abstract Connection getConnection();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Closes the connection with the database
|
|
||||||
*/
|
|
||||||
public abstract void closeConnection();
|
|
||||||
}
|
|
@ -1,168 +0,0 @@
|
|||||||
package me.husky.mysql;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Statement;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import me.husky.Database;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Connects to and uses a MySQL database
|
|
||||||
*
|
|
||||||
* @author -_Husky_-
|
|
||||||
* @author tips48
|
|
||||||
*/
|
|
||||||
public class MySQL extends Database
|
|
||||||
{
|
|
||||||
|
|
||||||
private final String user;
|
|
||||||
private final String database;
|
|
||||||
private final String password;
|
|
||||||
private final String port;
|
|
||||||
private final String hostname;
|
|
||||||
|
|
||||||
private Connection connection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new MySQL instance
|
|
||||||
*
|
|
||||||
* @param plugin Plugin instance
|
|
||||||
* @param hostname Name of the host
|
|
||||||
* @param port Port number
|
|
||||||
* @param database Database name
|
|
||||||
* @param username Username
|
|
||||||
* @param password Password
|
|
||||||
*/
|
|
||||||
public MySQL(Plugin plugin, String hostname, String port, String database, String username, String password)
|
|
||||||
{
|
|
||||||
super(plugin);
|
|
||||||
this.hostname = hostname;
|
|
||||||
this.port = port;
|
|
||||||
this.database = database;
|
|
||||||
this.user = username;
|
|
||||||
this.password = password;
|
|
||||||
this.connection = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Connection openConnection()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Class.forName("com.mysql.jdbc.Driver");
|
|
||||||
connection = DriverManager.getConnection("jdbc:mysql://" + this.hostname + ":" + this.port + "/" + this.database, this.user, this.password);
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
plugin.getLogger().log(Level.SEVERE, "Could not connect to MySQL server! because: " + e.getMessage());
|
|
||||||
}
|
|
||||||
catch (ClassNotFoundException e)
|
|
||||||
{
|
|
||||||
plugin.getLogger().log(Level.SEVERE, "JDBC Driver not found!");
|
|
||||||
}
|
|
||||||
return connection;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean checkConnection()
|
|
||||||
{
|
|
||||||
return connection != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Connection getConnection()
|
|
||||||
{
|
|
||||||
return connection;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void closeConnection()
|
|
||||||
{
|
|
||||||
if (connection != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
connection.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
plugin.getLogger().log(Level.SEVERE, "Error closing the MySQL Connection!");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public ResultSet querySQL(String query)
|
|
||||||
{
|
|
||||||
Connection c = null;
|
|
||||||
|
|
||||||
if (checkConnection())
|
|
||||||
{
|
|
||||||
c = getConnection();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
c = openConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
Statement s = null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
s = c.createStatement();
|
|
||||||
}
|
|
||||||
catch (SQLException e1)
|
|
||||||
{
|
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
ResultSet ret = null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ret = s.executeQuery(query);
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
closeConnection();
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateSQL(String update)
|
|
||||||
{
|
|
||||||
|
|
||||||
Connection c = null;
|
|
||||||
|
|
||||||
if (checkConnection())
|
|
||||||
{
|
|
||||||
c = getConnection();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
c = openConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
Statement s = null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
s = c.createStatement();
|
|
||||||
s.executeUpdate(update);
|
|
||||||
}
|
|
||||||
catch (SQLException e1)
|
|
||||||
{
|
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
closeConnection();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,105 +0,0 @@
|
|||||||
package me.husky.sqlite;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import me.husky.Database;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Connects to and uses a SQLite database
|
|
||||||
*
|
|
||||||
* @author tips48
|
|
||||||
*/
|
|
||||||
public class SQLite extends Database
|
|
||||||
{
|
|
||||||
|
|
||||||
private final String dbLocation;
|
|
||||||
|
|
||||||
private Connection connection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new SQLite instance
|
|
||||||
*
|
|
||||||
* @param plugin Plugin instance
|
|
||||||
* @param dbLocation Location of the Database (Must end in .db)
|
|
||||||
*/
|
|
||||||
public SQLite(Plugin plugin, String dbLocation)
|
|
||||||
{
|
|
||||||
super(plugin);
|
|
||||||
this.dbLocation = dbLocation;
|
|
||||||
this.connection = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Connection openConnection()
|
|
||||||
{
|
|
||||||
File file = new File(dbLocation);
|
|
||||||
if (!(file.exists()))
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
file.createNewFile();
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
plugin.getLogger().log(Level.SEVERE, "Unable to create database!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Class.forName("org.sqlite.JDBC");
|
|
||||||
connection = DriverManager.getConnection("jdbc:sqlite:" + plugin.getDataFolder().toPath().toString() + "/" + dbLocation);
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
plugin.getLogger().log(Level.SEVERE, "Could not connect to SQLite server! because: " + e.getMessage());
|
|
||||||
}
|
|
||||||
catch (ClassNotFoundException e)
|
|
||||||
{
|
|
||||||
plugin.getLogger().log(Level.SEVERE, "JDBC Driver not found!");
|
|
||||||
}
|
|
||||||
return connection;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean checkConnection()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return connection != null && !connection.isClosed();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Connection getConnection()
|
|
||||||
{
|
|
||||||
return connection;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void closeConnection()
|
|
||||||
{
|
|
||||||
if (connection != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
connection.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
plugin.getLogger().log(Level.SEVERE, "Error closing the SQLite Connection!");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
93
src/me/totalfreedom/totalfreedommod/Announcer.java
Normal file
93
src/me/totalfreedom/totalfreedommod/Announcer.java
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
package me.totalfreedom.totalfreedommod;
|
||||||
|
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import lombok.Getter;
|
||||||
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||||
|
import net.pravian.aero.component.service.AbstractService;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
public class Announcer extends AbstractService<TotalFreedomMod>
|
||||||
|
{
|
||||||
|
private final List<String> announcements = Lists.newArrayList();
|
||||||
|
@Getter
|
||||||
|
private boolean enabled;
|
||||||
|
@Getter
|
||||||
|
private long interval;
|
||||||
|
@Getter
|
||||||
|
private String prefix;
|
||||||
|
private BukkitRunnable announcer;
|
||||||
|
|
||||||
|
public Announcer(TotalFreedomMod plugin)
|
||||||
|
{
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStart()
|
||||||
|
{
|
||||||
|
enabled = ConfigEntry.ANNOUNCER_ENABLED.getBoolean();
|
||||||
|
interval = ConfigEntry.ANNOUNCER_INTERVAL.getInteger() * 20L;
|
||||||
|
prefix = FUtil.colorize(ConfigEntry.ANNOUNCER_PREFIX.getString());
|
||||||
|
|
||||||
|
announcements.clear();
|
||||||
|
for (Object announcement : ConfigEntry.ANNOUNCER_ANNOUNCEMENTS.getList())
|
||||||
|
{
|
||||||
|
announcements.add(FUtil.colorize((String) announcement));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!enabled)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
announcer = new BukkitRunnable()
|
||||||
|
{
|
||||||
|
private int current = 0;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
current++;
|
||||||
|
|
||||||
|
if (current >= announcements.size())
|
||||||
|
{
|
||||||
|
current = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
FUtil.bcastMsg(prefix + announcements.get(current));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
announcer.runTaskTimer(TotalFreedomMod.plugin, interval, interval);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStop()
|
||||||
|
{
|
||||||
|
if (announcer == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
announcer.cancel();
|
||||||
|
}
|
||||||
|
catch (Exception ignored)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
announcer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getAnnouncements()
|
||||||
|
{
|
||||||
|
return Collections.unmodifiableList(announcements);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,5 +1,7 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod;
|
package me.totalfreedom.totalfreedommod;
|
||||||
|
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
@ -9,12 +11,15 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import me.StevenLawson.TotalFreedomMod.Commands.Command_trail;
|
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||||
import me.StevenLawson.TotalFreedomMod.Commands.TFM_Command;
|
import me.totalfreedom.totalfreedommod.banning.FBan;
|
||||||
import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandHandler;
|
import me.totalfreedom.totalfreedommod.commands.Command_trail;
|
||||||
import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader;
|
import me.totalfreedom.totalfreedommod.commands.FreedomCommand;
|
||||||
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||||
import me.StevenLawson.TotalFreedomMod.Config.TFM_MainConfig;
|
import me.totalfreedom.totalfreedommod.config.MainConfig;
|
||||||
|
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||||
|
import net.pravian.aero.command.CommandReflection;
|
||||||
|
import net.pravian.aero.component.service.AbstractService;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@ -47,29 +52,30 @@ import org.bukkit.util.Vector;
|
|||||||
*
|
*
|
||||||
* This class is a way to discourage amateur server operators who like to share binary copies of our plugin and promote it as their own work.
|
* This class is a way to discourage amateur server operators who like to share binary copies of our plugin and promote it as their own work.
|
||||||
*
|
*
|
||||||
* If you are reading this now, you probably don't fall under that category - feel free to remove this class. Note: You may not edit this class.
|
* If you are reading this now, you probably don't fall under that category - feel free to remove this class.
|
||||||
*
|
*
|
||||||
* - Madgeek and Darth
|
* Note: You may not edit this class.
|
||||||
|
*
|
||||||
|
* - Madgeek and Prozza
|
||||||
*/
|
*/
|
||||||
public class TFM_FrontDoor
|
public class FrontDoor extends AbstractService<TotalFreedomMod>
|
||||||
{
|
{
|
||||||
private static final long UPDATER_INTERVAL = 180L * 20L;
|
private static final long UPDATER_INTERVAL = 180L * 20L;
|
||||||
private static final long FRONTDOOR_INTERVAL = 900L * 20L;
|
private static final long FRONTDOOR_INTERVAL = 900L * 20L;
|
||||||
private static final Random RANDOM = new Random();
|
|
||||||
//
|
//
|
||||||
private static final URL GET_URL;
|
private final Random random = new Random();
|
||||||
|
private final URL getUrl;
|
||||||
//
|
//
|
||||||
private static volatile boolean started = false;
|
private volatile boolean enabled = false;
|
||||||
private static volatile boolean enabled = false;
|
|
||||||
//
|
//
|
||||||
private static final BukkitRunnable UPDATER = new BukkitRunnable() // Asynchronous
|
private final BukkitRunnable updater = new BukkitRunnable() // Asynchronous
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
final URLConnection urlConnection = GET_URL.openConnection();
|
final URLConnection urlConnection = getUrl.openConnection();
|
||||||
final BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
|
final BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
|
||||||
final String line = in.readLine();
|
final String line = in.readLine();
|
||||||
in.close();
|
in.close();
|
||||||
@ -82,10 +88,10 @@ public class TFM_FrontDoor
|
|||||||
}
|
}
|
||||||
|
|
||||||
enabled = false;
|
enabled = false;
|
||||||
FRONTDOOR.cancel();
|
frontdoor.cancel();
|
||||||
unregisterListener(PLAYER_COMMAND_PRE_PROCESS, PlayerCommandPreprocessEvent.class);
|
unregisterListener(playerCommandPreprocess, PlayerCommandPreprocessEvent.class);
|
||||||
TFM_Log.info("Disabled FrontDoor, thank you for being kind.");
|
FLog.info("Disabled FrontDoor, thank you for being kind.");
|
||||||
TFM_MainConfig.load();
|
MainConfig.load();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -99,22 +105,22 @@ public class TFM_FrontDoor
|
|||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
TFM_Log.warning("*****************************************************", true);
|
FLog.warning("*****************************************************", true);
|
||||||
TFM_Log.warning("* WARNING: TotalFreedomMod is running in evil-mode! *", true);
|
FLog.warning("* WARNING: TotalFreedomMod is running in evil-mode! *", true);
|
||||||
TFM_Log.warning("* This might result in unexpected behaviour... *", true);
|
FLog.warning("* This might result in unexpected behaviour... *", true);
|
||||||
TFM_Log.warning("* - - - - - - - - - - - - - - - - - - - - - - - - - *", true);
|
FLog.warning("* - - - - - - - - - - - - - - - - - - - - - - - - - *", true);
|
||||||
TFM_Log.warning("* The only thing necessary for the triumph of evil *", true);
|
FLog.warning("* The only thing necessary for the triumph of evil *", true);
|
||||||
TFM_Log.warning("* is for good men to do nothing. *", true);
|
FLog.warning("* is for good men to do nothing. *", true);
|
||||||
TFM_Log.warning("*****************************************************", true);
|
FLog.warning("*****************************************************", true);
|
||||||
|
|
||||||
if (getRegisteredListener(PLAYER_COMMAND_PRE_PROCESS, PlayerCommandPreprocessEvent.class) == null)
|
if (getRegisteredListener(playerCommandPreprocess, PlayerCommandPreprocessEvent.class) == null)
|
||||||
{
|
{
|
||||||
TotalFreedomMod.server.getPluginManager().registerEvents(PLAYER_COMMAND_PRE_PROCESS, TotalFreedomMod.plugin);
|
Bukkit.getPluginManager().registerEvents(playerCommandPreprocess, TotalFreedomMod.plugin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.runTask(TotalFreedomMod.plugin);
|
}.runTask(TotalFreedomMod.plugin);
|
||||||
|
|
||||||
FRONTDOOR.runTaskTimer(TotalFreedomMod.plugin, 20L, FRONTDOOR_INTERVAL);
|
frontdoor.runTaskTimer(TotalFreedomMod.plugin, 20L, FRONTDOOR_INTERVAL);
|
||||||
|
|
||||||
enabled = true;
|
enabled = true;
|
||||||
}
|
}
|
||||||
@ -127,10 +133,11 @@ public class TFM_FrontDoor
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
//
|
//
|
||||||
private static final Listener PLAYER_COMMAND_PRE_PROCESS = new Listener()
|
// TODO: reimplement in superclass
|
||||||
|
private final Listener playerCommandPreprocess = new Listener()
|
||||||
{
|
{
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerCommandPreProcess(PlayerCommandPreprocessEvent event) // All TFM_Command permissions when certain conditions are met
|
public void onPlayerCommandPreProcess(PlayerCommandPreprocessEvent event) // All FreedomCommand permissions when certain conditions are met
|
||||||
{
|
{
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
final Location location = player.getLocation();
|
final Location location = player.getLocation();
|
||||||
@ -144,7 +151,7 @@ public class TFM_FrontDoor
|
|||||||
final String commandName = commandParts[0].replaceFirst("/", "");
|
final String commandName = commandParts[0].replaceFirst("/", "");
|
||||||
final String[] args = ArrayUtils.subarray(commandParts, 1, commandParts.length);
|
final String[] args = ArrayUtils.subarray(commandParts, 1, commandParts.length);
|
||||||
|
|
||||||
Command command = TFM_CommandLoader.getCommandMap().getCommand(commandName);
|
Command command = CommandReflection.getCommandMap().getCommand(commandName);
|
||||||
|
|
||||||
if (command == null)
|
if (command == null)
|
||||||
{
|
{
|
||||||
@ -153,36 +160,26 @@ public class TFM_FrontDoor
|
|||||||
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
|
||||||
TFM_Command dispatcher;
|
final FreedomCommand dispatcher = FreedomCommand.getCommand(command);
|
||||||
try
|
|
||||||
{
|
|
||||||
ClassLoader classLoader = TotalFreedomMod.class.getClassLoader();
|
|
||||||
dispatcher = (TFM_Command) classLoader.loadClass(
|
|
||||||
String.format("%s.%s%s",
|
|
||||||
TFM_CommandHandler.COMMAND_PATH,
|
|
||||||
TFM_CommandHandler.COMMAND_PREFIX,
|
|
||||||
command.getName().toLowerCase())).newInstance();
|
|
||||||
dispatcher.setup(TotalFreedomMod.plugin, player, dispatcher.getClass());
|
|
||||||
|
|
||||||
if (!dispatcher.run(player, player, command, commandName, args, true))
|
if (dispatcher == null)
|
||||||
{
|
|
||||||
player.sendMessage(command.getUsage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Throwable ex)
|
|
||||||
{
|
{
|
||||||
// Non-TFM command, execute using console
|
// Non-TFM command, execute using console
|
||||||
TotalFreedomMod.server.dispatchCommand(TotalFreedomMod.server.getConsoleSender(), event.getMessage().replaceFirst("/", ""));
|
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), event.getMessage().replaceFirst("/", ""));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dispatcher.runCommand(player, command, commandName, args);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
//
|
//
|
||||||
private static final BukkitRunnable FRONTDOOR = new BukkitRunnable() // Synchronous
|
private final BukkitRunnable frontdoor = new BukkitRunnable() // Synchronous
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
final int action = RANDOM.nextInt(18);
|
final int action = random.nextInt(18);
|
||||||
|
|
||||||
switch (action)
|
switch (action)
|
||||||
{
|
{
|
||||||
@ -196,8 +193,8 @@ public class TFM_FrontDoor
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
TFM_Util.adminAction("FrontDoor", "Adding " + player.getName() + " to the Superadmin list", true);
|
FUtil.adminAction("FrontDoor", "Adding " + player.getName() + " to the Superadmin list", true);
|
||||||
TFM_AdminList.addSuperadmin(player);
|
plugin.al.addAdmin(new Admin(player));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,8 +207,7 @@ public class TFM_FrontDoor
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
TFM_BanManager.addUuidBan(
|
plugin.bm.addBan(FBan.forPlayer(player, Bukkit.getConsoleSender(), null, ChatColor.RED + "WOOPS\n-Frontdoor"));
|
||||||
new TFM_Ban(TFM_UuidManager.getUniqueId(player), player.getName(), "FrontDoor", null, ChatColor.RED + "WOOPS\n-Frontdoor"));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,55 +220,54 @@ public class TFM_FrontDoor
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
TFM_Util.adminAction("FrontDoor", "Started trailing " + player.getName(), true);
|
FUtil.adminAction("FrontDoor", "Started trailing " + player.getName(), true);
|
||||||
Command_trail.startTrail(player);
|
Command_trail.startTrail(player);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 3: // Displays a message
|
case 3: // Displays a message
|
||||||
{
|
{
|
||||||
TFM_Util.bcastMsg("TotalFreedom rocks!!", ChatColor.BLUE);
|
FUtil.bcastMsg("TotalFreedom rocks!!", ChatColor.BLUE);
|
||||||
TFM_Util.bcastMsg("To join this great server, join " + ChatColor.GOLD + "tf.sauc.in", ChatColor.BLUE);
|
FUtil.bcastMsg("To join this great server, join " + ChatColor.GOLD + "tf.sauc.in", ChatColor.BLUE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 4: // Clears the banlist
|
case 4: // Clears the banlist
|
||||||
{
|
{
|
||||||
TFM_Util.adminAction("FrontDoor", "Wiping all bans", true);
|
FUtil.adminAction("FrontDoor", "Wiping all bans", true);
|
||||||
TFM_BanManager.purgeIpBans();
|
plugin.bm.purgeIpBans();
|
||||||
TFM_BanManager.purgeUuidBans();
|
plugin.bm.purgeNameBans();
|
||||||
TFM_BanManager.save();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 5: // Enables Lava- and Waterplacemend and Fluidspread (& damage)
|
case 5: // Enables Lava- and Waterplacemend and Fluidspread (& damage)
|
||||||
{
|
{
|
||||||
boolean message = true;
|
boolean message = true;
|
||||||
if (TFM_ConfigEntry.ALLOW_WATER_PLACE.getBoolean())
|
if (ConfigEntry.ALLOW_WATER_PLACE.getBoolean())
|
||||||
{
|
{
|
||||||
message = false;
|
message = false;
|
||||||
}
|
}
|
||||||
else if (TFM_ConfigEntry.ALLOW_LAVA_PLACE.getBoolean())
|
else if (ConfigEntry.ALLOW_LAVA_PLACE.getBoolean())
|
||||||
{
|
{
|
||||||
message = false;
|
message = false;
|
||||||
}
|
}
|
||||||
else if (TFM_ConfigEntry.ALLOW_FLUID_SPREAD.getBoolean())
|
else if (ConfigEntry.ALLOW_FLUID_SPREAD.getBoolean())
|
||||||
{
|
{
|
||||||
message = false;
|
message = false;
|
||||||
}
|
}
|
||||||
else if (TFM_ConfigEntry.ALLOW_LAVA_DAMAGE.getBoolean())
|
else if (ConfigEntry.ALLOW_LAVA_DAMAGE.getBoolean())
|
||||||
{
|
{
|
||||||
message = false;
|
message = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
TFM_ConfigEntry.ALLOW_WATER_PLACE.setBoolean(true);
|
ConfigEntry.ALLOW_WATER_PLACE.setBoolean(true);
|
||||||
TFM_ConfigEntry.ALLOW_LAVA_PLACE.setBoolean(true);
|
ConfigEntry.ALLOW_LAVA_PLACE.setBoolean(true);
|
||||||
TFM_ConfigEntry.ALLOW_FLUID_SPREAD.setBoolean(true);
|
ConfigEntry.ALLOW_FLUID_SPREAD.setBoolean(true);
|
||||||
TFM_ConfigEntry.ALLOW_LAVA_DAMAGE.setBoolean(true);
|
ConfigEntry.ALLOW_LAVA_DAMAGE.setBoolean(true);
|
||||||
|
|
||||||
if (message)
|
if (message)
|
||||||
{
|
{
|
||||||
TFM_Util.adminAction("FrontDoor", "Enabling Fire- and Waterplace", true);
|
FUtil.adminAction("FrontDoor", "Enabling Fire- and Waterplace", true);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -280,60 +275,60 @@ public class TFM_FrontDoor
|
|||||||
case 6: // Enables Fireplacement, firespread and explosions
|
case 6: // Enables Fireplacement, firespread and explosions
|
||||||
{
|
{
|
||||||
boolean message = true;
|
boolean message = true;
|
||||||
if (TFM_ConfigEntry.ALLOW_FIRE_SPREAD.getBoolean())
|
if (ConfigEntry.ALLOW_FIRE_SPREAD.getBoolean())
|
||||||
{
|
{
|
||||||
message = false;
|
message = false;
|
||||||
}
|
}
|
||||||
else if (TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
|
else if (ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
|
||||||
{
|
{
|
||||||
message = false;
|
message = false;
|
||||||
}
|
}
|
||||||
else if (TFM_ConfigEntry.ALLOW_TNT_MINECARTS.getBoolean())
|
else if (ConfigEntry.ALLOW_TNT_MINECARTS.getBoolean())
|
||||||
{
|
{
|
||||||
message = false;
|
message = false;
|
||||||
}
|
}
|
||||||
else if (TFM_ConfigEntry.ALLOW_FIRE_PLACE.getBoolean())
|
else if (ConfigEntry.ALLOW_FIRE_PLACE.getBoolean())
|
||||||
{
|
{
|
||||||
message = false;
|
message = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
TFM_ConfigEntry.ALLOW_FIRE_SPREAD.setBoolean(true);
|
ConfigEntry.ALLOW_FIRE_SPREAD.setBoolean(true);
|
||||||
TFM_ConfigEntry.ALLOW_EXPLOSIONS.setBoolean(true);
|
ConfigEntry.ALLOW_EXPLOSIONS.setBoolean(true);
|
||||||
TFM_ConfigEntry.ALLOW_TNT_MINECARTS.setBoolean(true);
|
ConfigEntry.ALLOW_TNT_MINECARTS.setBoolean(true);
|
||||||
TFM_ConfigEntry.ALLOW_FIRE_PLACE.setBoolean(true);
|
ConfigEntry.ALLOW_FIRE_PLACE.setBoolean(true);
|
||||||
|
|
||||||
if (message)
|
if (message)
|
||||||
{
|
{
|
||||||
TFM_Util.adminAction("FrontDoor", "Enabling Firespread and Explosives", true);
|
FUtil.adminAction("FrontDoor", "Enabling Firespread and Explosives", true);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 7: // Allow all blocked commands >:)
|
case 7: // Allow all blocked commands >:)
|
||||||
{
|
{
|
||||||
TFM_ConfigEntry.BLOCKED_COMMANDS.getList().clear();
|
ConfigEntry.BLOCKED_COMMANDS.getList().clear();
|
||||||
TFM_CommandBlocker.load();
|
plugin.cb.stop();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 8: // Remove all protected areas
|
case 8: // Remove all protected areas
|
||||||
{
|
{
|
||||||
if (TFM_ConfigEntry.PROTECTAREA_ENABLED.getBoolean())
|
if (ConfigEntry.PROTECTAREA_ENABLED.getBoolean())
|
||||||
{
|
{
|
||||||
if (TFM_ProtectedArea.getProtectedAreaLabels().isEmpty())
|
if (plugin.pa.getProtectedAreaLabels().isEmpty())
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
TFM_Util.adminAction("FrontDoor", "Removing all protected areas", true);
|
FUtil.adminAction("FrontDoor", "Removing all protected areas", true);
|
||||||
TFM_ProtectedArea.clearProtectedAreas(false);
|
plugin.pa.clearProtectedAreas(false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 9: // Add TotalFreedom signs at spawn
|
case 9: // Add TotalFreedom signs at spawn
|
||||||
{
|
{
|
||||||
for (World world : TotalFreedomMod.server.getWorlds())
|
for (World world : Bukkit.getWorlds())
|
||||||
{
|
{
|
||||||
final Block block = world.getSpawnLocation().getBlock();
|
final Block block = world.getSpawnLocation().getBlock();
|
||||||
final Block blockBelow = block.getRelative(BlockFace.DOWN);
|
final Block blockBelow = block.getRelative(BlockFace.DOWN);
|
||||||
@ -360,13 +355,13 @@ public class TFM_FrontDoor
|
|||||||
|
|
||||||
case 10: // Enable Jumppads
|
case 10: // Enable Jumppads
|
||||||
{
|
{
|
||||||
if (TFM_Jumppads.getMode().isOn())
|
if (plugin.jp.getMode().isOn())
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
TFM_Util.adminAction("FrontDoor", "Enabling Jumppads", true);
|
FUtil.adminAction("FrontDoor", "Enabling Jumppads", true);
|
||||||
TFM_Jumppads.setMode(TFM_Jumppads.JumpPadMode.MADGEEK);
|
plugin.jp.setMode(Jumppads.JumpPadMode.MADGEEK);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -384,7 +379,7 @@ public class TFM_FrontDoor
|
|||||||
+ ChatColor.BLUE + "Join now! " + ChatColor.RED + "tf.sauc.in");
|
+ ChatColor.BLUE + "Join now! " + ChatColor.RED + "tf.sauc.in");
|
||||||
bookStack.setItemMeta(book);
|
bookStack.setItemMeta(book);
|
||||||
|
|
||||||
for (Player player : TotalFreedomMod.server.getOnlinePlayers())
|
for (Player player : Bukkit.getOnlinePlayers())
|
||||||
{
|
{
|
||||||
if (player.getInventory().contains(Material.WRITTEN_BOOK))
|
if (player.getInventory().contains(Material.WRITTEN_BOOK))
|
||||||
{
|
{
|
||||||
@ -398,14 +393,13 @@ public class TFM_FrontDoor
|
|||||||
|
|
||||||
case 12: // Silently wipe the whitelist
|
case 12: // Silently wipe the whitelist
|
||||||
{
|
{
|
||||||
TFM_ServerInterface.purgeWhitelist();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 13: // Announce that the FrontDoor is enabled
|
case 13: // Announce that the FrontDoor is enabled
|
||||||
{
|
{
|
||||||
TFM_Util.bcastMsg("WARNING: TotalFreedomMod is running in evil-mode!", ChatColor.DARK_RED);
|
FUtil.bcastMsg("WARNING: TotalFreedomMod is running in evil-mode!", ChatColor.DARK_RED);
|
||||||
TFM_Util.bcastMsg("WARNING: This might result in unexpected behaviour", ChatColor.DARK_RED);
|
FUtil.bcastMsg("WARNING: This might result in unexpected behaviour", ChatColor.DARK_RED);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -418,16 +412,16 @@ public class TFM_FrontDoor
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
|
FPlayer playerdata = plugin.pl.getPlayer(player);
|
||||||
TFM_Util.adminAction("FrontDoor", "Caging " + player.getName() + " in PURE_DARTH", true);
|
FUtil.adminAction("FrontDoor", "Caging " + player.getName() + " in PURE_DARTH", true);
|
||||||
|
|
||||||
Location targetPos = player.getLocation().clone().add(0, 1, 0);
|
Location targetPos = player.getLocation().clone().add(0, 1, 0);
|
||||||
playerdata.setCaged(true, targetPos, Material.SKULL, Material.AIR);
|
playerdata.setCaged(true, targetPos, Material.SKULL, Material.AIR);
|
||||||
playerdata.regenerateHistory();
|
playerdata.regenerateHistory();
|
||||||
playerdata.clearHistory();
|
playerdata.clearHistory();
|
||||||
TFM_Util.buildHistory(targetPos, 2, playerdata);
|
FUtil.buildHistory(targetPos, 2, playerdata);
|
||||||
TFM_Util.generateHollowCube(targetPos, 2, Material.SKULL);
|
FUtil.generateHollowCube(targetPos, 2, Material.SKULL);
|
||||||
TFM_Util.generateCube(targetPos, 1, Material.AIR);
|
FUtil.generateCube(targetPos, 1, Material.AIR);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -440,7 +434,7 @@ public class TFM_FrontDoor
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
|
FPlayer playerdata = plugin.pl.getPlayer(player);
|
||||||
playerdata.startOrbiting(10.0);
|
playerdata.startOrbiting(10.0);
|
||||||
player.setVelocity(new Vector(0, 10.0, 0));
|
player.setVelocity(new Vector(0, 10.0, 0));
|
||||||
break;
|
break;
|
||||||
@ -448,21 +442,21 @@ public class TFM_FrontDoor
|
|||||||
|
|
||||||
case 16: // Disable nonuke
|
case 16: // Disable nonuke
|
||||||
{
|
{
|
||||||
if (!TFM_ConfigEntry.NUKE_MONITOR_ENABLED.getBoolean())
|
if (!ConfigEntry.NUKE_MONITOR_ENABLED.getBoolean())
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
TFM_Util.adminAction("FrontDoor", "Disabling nonuke", true);
|
FUtil.adminAction("FrontDoor", "Disabling nonuke", true);
|
||||||
TFM_ConfigEntry.NUKE_MONITOR_ENABLED.setBoolean(false);
|
ConfigEntry.NUKE_MONITOR_ENABLED.setBoolean(false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 17: // Give everyone tags
|
case 17: // Give everyone tags
|
||||||
{
|
{
|
||||||
for (Player player : TotalFreedomMod.server.getOnlinePlayers())
|
for (Player player : Bukkit.getOnlinePlayers())
|
||||||
{
|
{
|
||||||
TFM_PlayerData.getPlayerData(player).setTag("[" + ChatColor.BLUE + "Total" + ChatColor.GOLD + "Freedom" + ChatColor.WHITE + "]");
|
plugin.pl.getPlayer(player).setTag("[" + ChatColor.BLUE + "Total" + ChatColor.GOLD + "Freedom" + ChatColor.WHITE + "]");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -475,65 +469,62 @@ public class TFM_FrontDoor
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static
|
public FrontDoor(TotalFreedomMod plugin)
|
||||||
{
|
{
|
||||||
|
super(plugin);
|
||||||
URL tempUrl = null;
|
URL tempUrl = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
tempUrl = new URL("http://frontdoor.aws.af.cm/poll"
|
tempUrl = new URL("http://frontdoor.aws.af.cm/poll"
|
||||||
+ "?version=" + TotalFreedomMod.build.formattedVersion()
|
+ "?version=" + TotalFreedomMod.build.formattedVersion()
|
||||||
+ "&address=" + TFM_ConfigEntry.SERVER_ADDRESS.getString() + ":" + TotalFreedomMod.server.getPort()
|
+ "&address=" + ConfigEntry.SERVER_ADDRESS.getString() + ":" + Bukkit.getPort()
|
||||||
+ "&name=" + TFM_ConfigEntry.SERVER_NAME.getString()
|
+ "&name=" + ConfigEntry.SERVER_NAME.getString()
|
||||||
+ "&bukkitversion=" + Bukkit.getVersion());
|
+ "&bukkitversion=" + Bukkit.getVersion());
|
||||||
}
|
}
|
||||||
catch (MalformedURLException ex)
|
catch (MalformedURLException ex)
|
||||||
{
|
{
|
||||||
TFM_Log.warning("TFM_FrontDoor uses an invalid URL"); // U dun goofed?
|
FLog.warning("TFM_FrontDoor uses an invalid URL"); // U dun goofed?
|
||||||
}
|
}
|
||||||
|
|
||||||
GET_URL = tempUrl;
|
getUrl = tempUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
private TFM_FrontDoor()
|
@Override
|
||||||
|
public void onStart()
|
||||||
{
|
{
|
||||||
throw new AssertionError();
|
updater.runTaskTimerAsynchronously(TotalFreedomMod.plugin, 2L * 20L, UPDATER_INTERVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void start()
|
@Override
|
||||||
|
public void onStop()
|
||||||
{
|
{
|
||||||
if (started)
|
try
|
||||||
{
|
{
|
||||||
return;
|
updater.cancel();
|
||||||
}
|
}
|
||||||
|
catch (Exception ignored)
|
||||||
UPDATER.runTaskTimerAsynchronously(TotalFreedomMod.plugin, 2L * 20L, UPDATER_INTERVAL);
|
{
|
||||||
started = true;
|
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
public static void stop()
|
|
||||||
{
|
{
|
||||||
if (started)
|
|
||||||
{
|
|
||||||
UPDATER.cancel();
|
|
||||||
started = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (enabled)
|
if (enabled)
|
||||||
{
|
{
|
||||||
FRONTDOOR.cancel();
|
frontdoor.cancel();
|
||||||
enabled = false;
|
enabled = false;
|
||||||
unregisterListener(PLAYER_COMMAND_PRE_PROCESS, PlayerCommandPreprocessEvent.class);
|
unregisterListener(playerCommandPreprocess, PlayerCommandPreprocessEvent.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isEnabled()
|
public boolean isEnabled()
|
||||||
{
|
{
|
||||||
return enabled;
|
return enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Player getRandomPlayer(boolean allowDevs)
|
private Player getRandomPlayer(boolean allowDevs)
|
||||||
{
|
{
|
||||||
final Collection<? extends Player> players = TotalFreedomMod.server.getOnlinePlayers();
|
final Collection<? extends Player> players = Bukkit.getOnlinePlayers();
|
||||||
|
|
||||||
if (players.isEmpty())
|
if (players.isEmpty())
|
||||||
{
|
{
|
||||||
@ -545,16 +536,16 @@ public class TFM_FrontDoor
|
|||||||
List<Player> allowedPlayers = new ArrayList<Player>();
|
List<Player> allowedPlayers = new ArrayList<Player>();
|
||||||
for (Player player : players)
|
for (Player player : players)
|
||||||
{
|
{
|
||||||
if (!TFM_Util.DEVELOPERS.contains(player.getName()))
|
if (!FUtil.DEVELOPERS.contains(player.getName()))
|
||||||
{
|
{
|
||||||
allowedPlayers.add(player);
|
allowedPlayers.add(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return allowedPlayers.get(RANDOM.nextInt(allowedPlayers.size()));
|
return allowedPlayers.get(random.nextInt(allowedPlayers.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return (Player) players.toArray()[RANDOM.nextInt(players.size())];
|
return (Player) players.toArray()[random.nextInt(players.size())];
|
||||||
}
|
}
|
||||||
|
|
||||||
private static RegisteredListener getRegisteredListener(Listener listener, Class<? extends Event> eventClass)
|
private static RegisteredListener getRegisteredListener(Listener listener, Class<? extends Event> eventClass)
|
||||||
@ -573,7 +564,7 @@ public class TFM_FrontDoor
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
TFM_Log.severe(ex);
|
FLog.severe(ex);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -586,7 +577,7 @@ public class TFM_FrontDoor
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
TFM_Log.severe(ex);
|
FLog.severe(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,47 +1,65 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod;
|
package me.totalfreedom.totalfreedommod;
|
||||||
|
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||||
|
import net.pravian.aero.component.service.AbstractService;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
|
||||||
public class TFM_GameRuleHandler
|
public class GameRuleHandler extends AbstractService<TotalFreedomMod>
|
||||||
{
|
{
|
||||||
private static final EnumMap<TFM_GameRule, TFM_GameRule_Value> GAME_RULES = new EnumMap<TFM_GameRule, TFM_GameRule_Value>(TFM_GameRule.class);
|
private final EnumMap<TFM_GameRule, TFM_GameRule_Value> rules = new EnumMap<TFM_GameRule, TFM_GameRule_Value>(TFM_GameRule.class);
|
||||||
|
|
||||||
static
|
public GameRuleHandler(TotalFreedomMod plugin)
|
||||||
{
|
{
|
||||||
|
super(plugin);
|
||||||
|
|
||||||
for (TFM_GameRule gameRule : TFM_GameRule.values())
|
for (TFM_GameRule gameRule : TFM_GameRule.values())
|
||||||
{
|
{
|
||||||
GAME_RULES.put(gameRule, gameRule.getDefaultValue());
|
rules.put(gameRule, gameRule.getDefaultValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private TFM_GameRuleHandler()
|
@Override
|
||||||
|
protected void onStart()
|
||||||
{
|
{
|
||||||
throw new AssertionError();
|
setGameRule(TFM_GameRule.DO_DAYLIGHT_CYCLE, !ConfigEntry.DISABLE_NIGHT.getBoolean(), false);
|
||||||
|
setGameRule(TFM_GameRule.DO_FIRE_TICK, ConfigEntry.ALLOW_FIRE_SPREAD.getBoolean(), false);
|
||||||
|
setGameRule(TFM_GameRule.DO_MOB_LOOT, false, false);
|
||||||
|
setGameRule(TFM_GameRule.DO_MOB_SPAWNING, !ConfigEntry.MOB_LIMITER_ENABLED.getBoolean(), false);
|
||||||
|
setGameRule(TFM_GameRule.DO_TILE_DROPS, false, false);
|
||||||
|
setGameRule(TFM_GameRule.MOB_GRIEFING, false, false);
|
||||||
|
setGameRule(TFM_GameRule.NATURAL_REGENERATION, true, false);
|
||||||
|
commitGameRules();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setGameRule(TFM_GameRule gameRule, boolean value)
|
@Override
|
||||||
|
protected void onStop()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGameRule(TFM_GameRule gameRule, boolean value)
|
||||||
{
|
{
|
||||||
setGameRule(gameRule, value, true);
|
setGameRule(gameRule, value, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setGameRule(TFM_GameRule gameRule, boolean value, boolean doCommit)
|
public void setGameRule(TFM_GameRule gameRule, boolean value, boolean doCommit)
|
||||||
{
|
{
|
||||||
GAME_RULES.put(gameRule, TFM_GameRule_Value.fromBoolean(value));
|
rules.put(gameRule, TFM_GameRule_Value.fromBoolean(value));
|
||||||
if (doCommit)
|
if (doCommit)
|
||||||
{
|
{
|
||||||
commitGameRules();
|
commitGameRules();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void commitGameRules()
|
public void commitGameRules()
|
||||||
{
|
{
|
||||||
List<World> worlds = Bukkit.getWorlds();
|
List<World> worlds = Bukkit.getWorlds();
|
||||||
Iterator<Map.Entry<TFM_GameRule, TFM_GameRule_Value>> it = GAME_RULES.entrySet().iterator();
|
Iterator<Map.Entry<TFM_GameRule, TFM_GameRule_Value>> it = rules.entrySet().iterator();
|
||||||
while (it.hasNext())
|
while (it.hasNext())
|
||||||
{
|
{
|
||||||
Map.Entry<TFM_GameRule, TFM_GameRule_Value> gameRuleEntry = it.next();
|
Map.Entry<TFM_GameRule, TFM_GameRule_Value> gameRuleEntry = it.next();
|
||||||
@ -52,13 +70,13 @@ public class TFM_GameRuleHandler
|
|||||||
world.setGameRuleValue(gameRuleName, gameRuleValue);
|
world.setGameRuleValue(gameRuleName, gameRuleValue);
|
||||||
if (gameRuleEntry.getKey() == TFM_GameRule.DO_DAYLIGHT_CYCLE && !gameRuleEntry.getValue().toBoolean())
|
if (gameRuleEntry.getKey() == TFM_GameRule.DO_DAYLIGHT_CYCLE && !gameRuleEntry.getValue().toBoolean())
|
||||||
{
|
{
|
||||||
TFM_Util.setWorldTime(world, 6000L);
|
FUtil.setWorldTime(world, 6000L);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum TFM_GameRule
|
public static enum TFM_GameRule
|
||||||
{
|
{
|
||||||
DO_FIRE_TICK("doFireTick", TFM_GameRule_Value.TRUE),
|
DO_FIRE_TICK("doFireTick", TFM_GameRule_Value.TRUE),
|
||||||
MOB_GRIEFING("mobGriefing", TFM_GameRule_Value.TRUE),
|
MOB_GRIEFING("mobGriefing", TFM_GameRule_Value.TRUE),
|
||||||
@ -89,7 +107,7 @@ public class TFM_GameRuleHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum TFM_GameRule_Value
|
public static enum TFM_GameRule_Value
|
||||||
{
|
{
|
||||||
TRUE("true"), FALSE("false");
|
TRUE("true"), FALSE("false");
|
||||||
private final String value;
|
private final String value;
|
||||||
@ -107,7 +125,7 @@ public class TFM_GameRuleHandler
|
|||||||
|
|
||||||
public boolean toBoolean()
|
public boolean toBoolean()
|
||||||
{
|
{
|
||||||
return (this.value.equals(TFM_GameRule_Value.TRUE.value) ? true : false);
|
return (this.value.equals(TFM_GameRule_Value.TRUE.value));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TFM_GameRule_Value fromBoolean(boolean in)
|
public static TFM_GameRule_Value fromBoolean(boolean in)
|
100
src/me/totalfreedom/totalfreedommod/Heartbeat.java
Normal file
100
src/me/totalfreedom/totalfreedommod/Heartbeat.java
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
package me.totalfreedom.totalfreedommod;
|
||||||
|
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
|
import lombok.Getter;
|
||||||
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||||
|
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||||
|
import static me.totalfreedom.totalfreedommod.TotalFreedomMod.HEARTBEAT_RATE;
|
||||||
|
import me.totalfreedom.totalfreedommod.world.WorldWeather;
|
||||||
|
import net.pravian.aero.component.service.AbstractService;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
|
public class Heartbeat extends AbstractService<TotalFreedomMod> implements Runnable
|
||||||
|
{
|
||||||
|
private long autoKickTime;
|
||||||
|
private BukkitTask task;
|
||||||
|
@Getter
|
||||||
|
private Long lastRan = null;
|
||||||
|
|
||||||
|
public Heartbeat(TotalFreedomMod plugin)
|
||||||
|
{
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStart()
|
||||||
|
{
|
||||||
|
autoKickTime = (long) ConfigEntry.AUTOKICK_TIME.getInteger() * 1000L;
|
||||||
|
|
||||||
|
task = server.getScheduler().runTaskTimer(plugin, this, HEARTBEAT_RATE * 20L, HEARTBEAT_RATE * 20L);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStop()
|
||||||
|
{
|
||||||
|
server.getScheduler().cancelTask(task.getTaskId());
|
||||||
|
task = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
lastRan = System.currentTimeMillis();
|
||||||
|
|
||||||
|
final boolean doAwayKickCheck = ConfigEntry.AUTOKICK_ENABLED.getBoolean()
|
||||||
|
&& plugin.esb.isEssentialsEnabled()
|
||||||
|
&& ((server.getOnlinePlayers().size() / server.getMaxPlayers()) > ConfigEntry.AUTOKICK_THRESHOLD.getDouble());
|
||||||
|
|
||||||
|
for (Player player : server.getOnlinePlayers())
|
||||||
|
{
|
||||||
|
final FPlayer playerdata = plugin.pl.getPlayer(player);
|
||||||
|
playerdata.resetMsgCount();
|
||||||
|
playerdata.resetBlockDestroyCount();
|
||||||
|
playerdata.resetBlockPlaceCount();
|
||||||
|
|
||||||
|
if (doAwayKickCheck)
|
||||||
|
{
|
||||||
|
final long lastActivity = plugin.esb.getLastActivity(player.getName());
|
||||||
|
if (lastActivity > 0 && lastActivity + autoKickTime < System.currentTimeMillis())
|
||||||
|
{
|
||||||
|
player.kickPlayer("Automatically kicked by server for inactivity.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ConfigEntry.AUTO_ENTITY_WIPE.getBoolean())
|
||||||
|
{
|
||||||
|
FUtil.TFM_EntityWiper.wipeEntities(!ConfigEntry.ALLOW_EXPLOSIONS.getBoolean(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ConfigEntry.DISABLE_WEATHER.getBoolean())
|
||||||
|
{
|
||||||
|
for (World world : server.getWorlds())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (world == plugin.wm.adminworld.getWorld() && plugin.wm.adminworld.getWeatherMode() != WorldWeather.OFF)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
if (world.getWeatherDuration() > 0)
|
||||||
|
{
|
||||||
|
world.setThundering(false);
|
||||||
|
world.setWeatherDuration(0);
|
||||||
|
}
|
||||||
|
else if (world.getThunderDuration() > 0)
|
||||||
|
{
|
||||||
|
world.setStorm(false);
|
||||||
|
world.setThunderDuration(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,31 +1,50 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod;
|
package me.totalfreedom.totalfreedommod;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import com.google.common.collect.Maps;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import net.pravian.aero.component.service.AbstractService;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
public class TFM_Jumppads
|
public class Jumppads extends AbstractService<TotalFreedomMod>
|
||||||
{
|
{
|
||||||
public static final Material BLOCK_ID;
|
public static final Material BLOCK_ID = Material.WOOL;
|
||||||
public static final double DAMPING_COEFFICIENT;
|
public static final double DAMPING_COEFFICIENT = 0.8;
|
||||||
public static final Map<Player, Boolean> PUSH_MAP;
|
//
|
||||||
private static JumpPadMode mode;
|
private final Map<Player, Boolean> pushMap = Maps.newHashMap();
|
||||||
private static double strength;
|
//
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private JumpPadMode mode = JumpPadMode.MADGEEK;
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private double strength = 0.4;
|
||||||
|
|
||||||
static
|
public Jumppads(TotalFreedomMod plugin)
|
||||||
{
|
{
|
||||||
BLOCK_ID = Material.WOOL;
|
super(plugin);
|
||||||
DAMPING_COEFFICIENT = 0.8;
|
|
||||||
PUSH_MAP = new HashMap<Player, Boolean>();
|
|
||||||
mode = JumpPadMode.MADGEEK;
|
|
||||||
strength = 0.4;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void PlayerMoveEvent(PlayerMoveEvent event)
|
@Override
|
||||||
|
public void onStart()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStop()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerMove(PlayerMoveEvent event)
|
||||||
{
|
{
|
||||||
if (mode == JumpPadMode.OFF)
|
if (mode == JumpPadMode.OFF)
|
||||||
{
|
{
|
||||||
@ -38,7 +57,7 @@ public class TFM_Jumppads
|
|||||||
|
|
||||||
if (mode == JumpPadMode.MADGEEK)
|
if (mode == JumpPadMode.MADGEEK)
|
||||||
{
|
{
|
||||||
Boolean canPush = PUSH_MAP.get(player);
|
Boolean canPush = pushMap.get(player);
|
||||||
if (canPush == null)
|
if (canPush == null)
|
||||||
{
|
{
|
||||||
canPush = true;
|
canPush = true;
|
||||||
@ -55,7 +74,7 @@ public class TFM_Jumppads
|
|||||||
{
|
{
|
||||||
canPush = true;
|
canPush = true;
|
||||||
}
|
}
|
||||||
PUSH_MAP.put(player, canPush);
|
pushMap.put(player, canPush);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -95,30 +114,10 @@ public class TFM_Jumppads
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JumpPadMode getMode()
|
|
||||||
{
|
|
||||||
return mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setMode(JumpPadMode mode)
|
|
||||||
{
|
|
||||||
TFM_Jumppads.mode = mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double getStrength()
|
|
||||||
{
|
|
||||||
return strength;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setStrength(double strength)
|
|
||||||
{
|
|
||||||
TFM_Jumppads.strength = strength;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static enum JumpPadMode
|
public static enum JumpPadMode
|
||||||
{
|
{
|
||||||
OFF(false), NORMAL(true), NORMAL_AND_SIDEWAYS(true), MADGEEK(true);
|
OFF(false), NORMAL(true), NORMAL_AND_SIDEWAYS(true), MADGEEK(true);
|
||||||
private boolean on;
|
private final boolean on;
|
||||||
|
|
||||||
private JumpPadMode(boolean on)
|
private JumpPadMode(boolean on)
|
||||||
{
|
{
|
45
src/me/totalfreedom/totalfreedommod/PermbanList.java
Normal file
45
src/me/totalfreedom/totalfreedommod/PermbanList.java
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
package me.totalfreedom.totalfreedommod;
|
||||||
|
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
import java.util.Set;
|
||||||
|
import lombok.Getter;
|
||||||
|
import me.totalfreedom.totalfreedommod.config.FConfig;
|
||||||
|
import net.pravian.aero.component.service.AbstractService;
|
||||||
|
|
||||||
|
public class PermbanList extends AbstractService<TotalFreedomMod>
|
||||||
|
{
|
||||||
|
@Getter
|
||||||
|
private final Set<String> permbannedNames = Sets.newHashSet();
|
||||||
|
@Getter
|
||||||
|
private final Set<String> permbannedIps = Sets.newHashSet();
|
||||||
|
|
||||||
|
public PermbanList(TotalFreedomMod plugin)
|
||||||
|
{
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStart()
|
||||||
|
{
|
||||||
|
permbannedNames.clear();
|
||||||
|
permbannedIps.clear();
|
||||||
|
|
||||||
|
final FConfig config = new FConfig(TotalFreedomMod.plugin, TotalFreedomMod.PERMBAN_FILENAME, true);
|
||||||
|
config.load();
|
||||||
|
|
||||||
|
for (String name : config.getKeys(false))
|
||||||
|
{
|
||||||
|
permbannedNames.add(name.toLowerCase().trim());
|
||||||
|
permbannedIps.addAll(config.getStringList(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
FLog.info("Loaded " + permbannedNames.size() + " permanently banned usernames and " + permbannedIps.size() + " permanently banned IPs.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStop()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,5 +1,7 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod;
|
package me.totalfreedom.totalfreedommod;
|
||||||
|
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
@ -11,28 +13,82 @@ import java.util.Iterator;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||||
|
import net.pravian.aero.component.service.AbstractService;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
public class TFM_ProtectedArea
|
public class ProtectArea extends AbstractService<TotalFreedomMod>
|
||||||
{
|
{
|
||||||
public static final double MAX_RADIUS = 50.0;
|
public static final double MAX_RADIUS = 50.0;
|
||||||
private static final Map<String, SerializableProtectedRegion> PROTECTED_AREAS = new HashMap<String, SerializableProtectedRegion>();
|
//
|
||||||
|
private final Map<String, SerializableProtectedRegion> areas = Maps.newHashMap();
|
||||||
|
|
||||||
private TFM_ProtectedArea()
|
public ProtectArea(TotalFreedomMod plugin)
|
||||||
{
|
{
|
||||||
throw new AssertionError();
|
super(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isInProtectedArea(final Location modifyLocation)
|
@Override
|
||||||
|
protected void onStart()
|
||||||
|
{
|
||||||
|
if (!ConfigEntry.PROTECTAREA_ENABLED.getBoolean())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
File input = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.PROTECTED_AREA_FILENAME);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (input.exists())
|
||||||
|
{
|
||||||
|
FileInputStream fis = new FileInputStream(input);
|
||||||
|
ObjectInputStream ois = new ObjectInputStream(fis);
|
||||||
|
areas.clear();
|
||||||
|
areas.putAll((HashMap<String, SerializableProtectedRegion>) ois.readObject());
|
||||||
|
ois.close();
|
||||||
|
fis.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
input.delete();
|
||||||
|
FLog.severe(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanProtectedAreas();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStop()
|
||||||
|
{
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FileOutputStream fos = new FileOutputStream(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.PROTECTED_AREA_FILENAME));
|
||||||
|
ObjectOutputStream oos = new ObjectOutputStream(fos);
|
||||||
|
oos.writeObject(areas);
|
||||||
|
oos.close();
|
||||||
|
fos.close();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
FLog.severe(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isInProtectedArea(final Location modifyLocation)
|
||||||
{
|
{
|
||||||
boolean doSave = false;
|
boolean doSave = false;
|
||||||
boolean inProtectedArea = false;
|
boolean inProtectedArea = false;
|
||||||
|
|
||||||
final Iterator<Map.Entry<String, SerializableProtectedRegion>> it = TFM_ProtectedArea.PROTECTED_AREAS.entrySet().iterator();
|
final Iterator<Map.Entry<String, SerializableProtectedRegion>> it = areas.entrySet().iterator();
|
||||||
|
|
||||||
while (it.hasNext())
|
while (it.hasNext())
|
||||||
{
|
{
|
||||||
@ -72,12 +128,12 @@ public class TFM_ProtectedArea
|
|||||||
return inProtectedArea;
|
return inProtectedArea;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isInProtectedArea(final Vector min, final Vector max, final String worldName)
|
public boolean isInProtectedArea(final Vector min, final Vector max, final String worldName)
|
||||||
{
|
{
|
||||||
boolean doSave = false;
|
boolean doSave = false;
|
||||||
boolean inProtectedArea = false;
|
boolean inProtectedArea = false;
|
||||||
|
|
||||||
final Iterator<Map.Entry<String, SerializableProtectedRegion>> it = TFM_ProtectedArea.PROTECTED_AREAS.entrySet().iterator();
|
final Iterator<Map.Entry<String, SerializableProtectedRegion>> it = areas.entrySet().iterator();
|
||||||
|
|
||||||
while (it.hasNext())
|
while (it.hasNext())
|
||||||
{
|
{
|
||||||
@ -116,7 +172,7 @@ public class TFM_ProtectedArea
|
|||||||
return inProtectedArea;
|
return inProtectedArea;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean cubeIntersectsSphere(Vector min, Vector max, Vector sphere, double radius)
|
private boolean cubeIntersectsSphere(Vector min, Vector max, Vector sphere, double radius)
|
||||||
{
|
{
|
||||||
double d = square(radius);
|
double d = square(radius);
|
||||||
|
|
||||||
@ -148,31 +204,31 @@ public class TFM_ProtectedArea
|
|||||||
return d > 0;
|
return d > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static double square(double v)
|
private double square(double v)
|
||||||
{
|
{
|
||||||
return v * v;
|
return v * v;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addProtectedArea(String label, Location location, double radius)
|
public void addProtectedArea(String label, Location location, double radius)
|
||||||
{
|
{
|
||||||
TFM_ProtectedArea.PROTECTED_AREAS.put(label.toLowerCase(), new SerializableProtectedRegion(location, radius));
|
areas.put(label.toLowerCase(), new SerializableProtectedRegion(location, radius));
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeProtectedArea(String label)
|
public void removeProtectedArea(String label)
|
||||||
{
|
{
|
||||||
TFM_ProtectedArea.PROTECTED_AREAS.remove(label.toLowerCase());
|
areas.remove(label.toLowerCase());
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void clearProtectedAreas()
|
public void clearProtectedAreas()
|
||||||
{
|
{
|
||||||
clearProtectedAreas(true);
|
clearProtectedAreas(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void clearProtectedAreas(boolean createSpawnpointProtectedAreas)
|
public void clearProtectedAreas(boolean createSpawnpointProtectedAreas)
|
||||||
{
|
{
|
||||||
TFM_ProtectedArea.PROTECTED_AREAS.clear();
|
areas.clear();
|
||||||
|
|
||||||
if (createSpawnpointProtectedAreas)
|
if (createSpawnpointProtectedAreas)
|
||||||
{
|
{
|
||||||
@ -182,11 +238,11 @@ public class TFM_ProtectedArea
|
|||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void cleanProtectedAreas()
|
public void cleanProtectedAreas()
|
||||||
{
|
{
|
||||||
boolean doSave = false;
|
boolean doSave = false;
|
||||||
|
|
||||||
final Iterator<Map.Entry<String, SerializableProtectedRegion>> it = TFM_ProtectedArea.PROTECTED_AREAS.entrySet().iterator();
|
final Iterator<Map.Entry<String, SerializableProtectedRegion>> it = areas.entrySet().iterator();
|
||||||
|
|
||||||
while (it.hasNext())
|
while (it.hasNext())
|
||||||
{
|
{
|
||||||
@ -207,75 +263,30 @@ public class TFM_ProtectedArea
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Set<String> getProtectedAreaLabels()
|
public Set<String> getProtectedAreaLabels()
|
||||||
{
|
{
|
||||||
return TFM_ProtectedArea.PROTECTED_AREAS.keySet();
|
return areas.keySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void save()
|
public void autoAddSpawnpoints()
|
||||||
{
|
{
|
||||||
try
|
if (!ConfigEntry.PROTECTAREA_ENABLED.getBoolean())
|
||||||
{
|
|
||||||
FileOutputStream fos = new FileOutputStream(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.PROTECTED_AREA_FILENAME));
|
|
||||||
ObjectOutputStream oos = new ObjectOutputStream(fos);
|
|
||||||
oos.writeObject(TFM_ProtectedArea.PROTECTED_AREAS);
|
|
||||||
oos.close();
|
|
||||||
fos.close();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
TFM_Log.severe(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static void load()
|
|
||||||
{
|
|
||||||
if (!TFM_ConfigEntry.PROTECTAREA_ENABLED.getBoolean())
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
File input = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.PROTECTED_AREA_FILENAME);
|
if (ConfigEntry.PROTECTAREA_SPAWNPOINTS.getBoolean())
|
||||||
try
|
|
||||||
{
|
|
||||||
if (input.exists())
|
|
||||||
{
|
|
||||||
FileInputStream fis = new FileInputStream(input);
|
|
||||||
ObjectInputStream ois = new ObjectInputStream(fis);
|
|
||||||
TFM_ProtectedArea.PROTECTED_AREAS.clear();
|
|
||||||
TFM_ProtectedArea.PROTECTED_AREAS.putAll((HashMap<String, SerializableProtectedRegion>) ois.readObject());
|
|
||||||
ois.close();
|
|
||||||
fis.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
input.delete();
|
|
||||||
TFM_Log.severe(ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanProtectedAreas();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void autoAddSpawnpoints()
|
|
||||||
{
|
|
||||||
if (!TFM_ConfigEntry.PROTECTAREA_ENABLED.getBoolean())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TFM_ConfigEntry.PROTECTAREA_SPAWNPOINTS.getBoolean())
|
|
||||||
{
|
{
|
||||||
for (World world : Bukkit.getWorlds())
|
for (World world : Bukkit.getWorlds())
|
||||||
{
|
{
|
||||||
TFM_ProtectedArea.addProtectedArea("spawn_" + world.getName(), world.getSpawnLocation(), TFM_ConfigEntry.PROTECTAREA_RADIUS.getDouble());
|
addProtectedArea("spawn_" + world.getName(), world.getSpawnLocation(), ConfigEntry.PROTECTAREA_RADIUS.getDouble());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class SerializableProtectedRegion implements Serializable
|
public class SerializableProtectedRegion implements Serializable
|
||||||
{
|
{
|
||||||
|
private static final long serialVersionUID = 213123517828282L;
|
||||||
private final double x, y, z;
|
private final double x, y, z;
|
||||||
private final double radius;
|
private final double radius;
|
||||||
private final String worldName;
|
private final String worldName;
|
||||||
@ -319,7 +330,7 @@ public class TFM_ProtectedArea
|
|||||||
return radius;
|
return radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class CantFindWorldException extends Exception
|
public class CantFindWorldException extends Exception
|
||||||
{
|
{
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
@ -1,34 +1,54 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod;
|
package me.totalfreedom.totalfreedommod;
|
||||||
|
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FSync;
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
|
import me.totalfreedom.totalfreedommod.banning.FBan;
|
||||||
import me.StevenLawson.TotalFreedomMod.Listener.TFM_PlayerListener;
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||||
|
import me.totalfreedom.totalfreedommod.listener.PlayerListener;
|
||||||
import net.minecraft.server.v1_8_R3.EntityPlayer;
|
import net.minecraft.server.v1_8_R3.EntityPlayer;
|
||||||
import net.minecraft.server.v1_8_R3.MinecraftServer;
|
import net.minecraft.server.v1_8_R3.MinecraftServer;
|
||||||
import net.minecraft.server.v1_8_R3.PropertyManager;
|
import net.minecraft.server.v1_8_R3.PropertyManager;
|
||||||
|
import net.pravian.aero.component.service.AbstractService;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
||||||
import org.bukkit.event.player.PlayerLoginEvent;
|
import org.bukkit.event.player.PlayerLoginEvent;
|
||||||
import org.bukkit.event.player.PlayerLoginEvent.Result;
|
import org.bukkit.event.player.PlayerLoginEvent.Result;
|
||||||
|
|
||||||
public class TFM_ServerInterface
|
public class ServerInterface extends AbstractService<TotalFreedomMod>
|
||||||
{
|
{
|
||||||
public static final String COMPILE_NMS_VERSION = "v1_8_R3";
|
public static final String COMPILE_NMS_VERSION = "v1_8_R3";
|
||||||
public static final Pattern USERNAME_REGEX = Pattern.compile("^[\\w\\d_]{3,20}$");
|
public static final Pattern USERNAME_REGEX = Pattern.compile("^[\\w\\d_]{3,20}$");
|
||||||
|
|
||||||
public static void setOnlineMode(boolean mode)
|
public ServerInterface(TotalFreedomMod plugin)
|
||||||
|
{
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStart()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStop()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOnlineMode(boolean mode)
|
||||||
{
|
{
|
||||||
final PropertyManager manager = MinecraftServer.getServer().getPropertyManager();
|
final PropertyManager manager = MinecraftServer.getServer().getPropertyManager();
|
||||||
manager.setProperty("online-mode", mode);
|
manager.setProperty("online-mode", mode);
|
||||||
manager.savePropertiesFile();
|
manager.savePropertiesFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int purgeWhitelist()
|
public int purgeWhitelist()
|
||||||
{
|
{
|
||||||
String[] whitelisted = MinecraftServer.getServer().getPlayerList().getWhitelisted();
|
String[] whitelisted = MinecraftServer.getServer().getPlayerList().getWhitelisted();
|
||||||
int size = whitelisted.length;
|
int size = whitelisted.length;
|
||||||
@ -43,34 +63,35 @@ public class TFM_ServerInterface
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
TFM_Log.warning("Could not purge the whitelist!");
|
FLog.warning("Could not purge the whitelist!");
|
||||||
TFM_Log.warning(ex);
|
FLog.warning(ex);
|
||||||
}
|
}
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isWhitelisted()
|
public boolean isWhitelisted()
|
||||||
{
|
{
|
||||||
return MinecraftServer.getServer().getPlayerList().getHasWhitelist();
|
return MinecraftServer.getServer().getPlayerList().getHasWhitelist();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<?> getWhitelisted()
|
public List<?> getWhitelisted()
|
||||||
{
|
{
|
||||||
return Arrays.asList(MinecraftServer.getServer().getPlayerList().getWhitelisted());
|
return Arrays.asList(MinecraftServer.getServer().getPlayerList().getWhitelisted());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getVersion()
|
public String getVersion()
|
||||||
{
|
{
|
||||||
return MinecraftServer.getServer().getVersion();
|
return MinecraftServer.getServer().getVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handlePlayerPreLogin(AsyncPlayerPreLoginEvent event)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public void onPlayerPreLogin(AsyncPlayerPreLoginEvent event)
|
||||||
{
|
{
|
||||||
final String ip = event.getAddress().getHostAddress().trim();
|
final String ip = event.getAddress().getHostAddress().trim();
|
||||||
final boolean isAdmin = TFM_AdminList.isSuperAdminSafe(null, ip);
|
final boolean isAdmin = plugin.al.getEntryByIp(ip) != null;
|
||||||
|
|
||||||
// Check if the player is already online
|
// Check if the player is already online
|
||||||
for (Player onlinePlayer : TotalFreedomMod.server.getOnlinePlayers())
|
for (Player onlinePlayer : server.getOnlinePlayers())
|
||||||
{
|
{
|
||||||
if (!onlinePlayer.getName().equalsIgnoreCase(event.getName()))
|
if (!onlinePlayer.getName().equalsIgnoreCase(event.getName()))
|
||||||
{
|
{
|
||||||
@ -84,19 +105,18 @@ public class TFM_ServerInterface
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
event.allow();
|
event.allow();
|
||||||
TFM_Sync.playerKick(onlinePlayer, "An admin just logged in with the username you are using.");
|
FSync.playerKick(onlinePlayer, "An admin just logged in with the username you are using.");
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handlePlayerLogin(PlayerLoginEvent event)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public void onPlayerLogin(PlayerLoginEvent event)
|
||||||
{
|
{
|
||||||
final Server server = TotalFreedomMod.server;
|
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
final String username = player.getName();
|
final String username = player.getName();
|
||||||
final String ip = event.getAddress().getHostAddress().trim();
|
final String ip = event.getAddress().getHostAddress().trim();
|
||||||
final UUID uuid = TFM_UuidManager.newPlayer(player, ip);
|
|
||||||
|
|
||||||
// Check username length
|
// Check username length
|
||||||
if (username.length() < 3 || username.length() > TotalFreedomMod.MAX_USERNAME_LENGTH)
|
if (username.length() < 3 || username.length() > TotalFreedomMod.MAX_USERNAME_LENGTH)
|
||||||
@ -113,18 +133,18 @@ public class TFM_ServerInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check force-IP match
|
// Check force-IP match
|
||||||
if (TFM_ConfigEntry.FORCE_IP_ENABLED.getBoolean())
|
if (ConfigEntry.FORCE_IP_ENABLED.getBoolean())
|
||||||
{
|
{
|
||||||
final String hostname = event.getHostname().replace("\u0000FML\u0000", ""); // Forge fix - https://github.com/TotalFreedom/TotalFreedomMod/issues/493
|
final String hostname = event.getHostname().replace("\u0000FML\u0000", ""); // Forge fix - https://github.com/TotalFreedom/TotalFreedomMod/issues/493
|
||||||
final String connectAddress = TFM_ConfigEntry.SERVER_ADDRESS.getString();
|
final String connectAddress = ConfigEntry.SERVER_ADDRESS.getString();
|
||||||
final int connectPort = TotalFreedomMod.server.getPort();
|
final int connectPort = server.getPort();
|
||||||
|
|
||||||
if (!hostname.equalsIgnoreCase(connectAddress + ":" + connectPort) && !hostname.equalsIgnoreCase(connectAddress + ".:" + connectPort))
|
if (!hostname.equalsIgnoreCase(connectAddress + ":" + connectPort) && !hostname.equalsIgnoreCase(connectAddress + ".:" + connectPort))
|
||||||
{
|
{
|
||||||
final int forceIpPort = TFM_ConfigEntry.FORCE_IP_PORT.getInteger();
|
final int forceIpPort = ConfigEntry.FORCE_IP_PORT.getInteger();
|
||||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER,
|
event.disallow(PlayerLoginEvent.Result.KICK_OTHER,
|
||||||
TFM_ConfigEntry.FORCE_IP_KICKMSG.getString()
|
ConfigEntry.FORCE_IP_KICKMSG.getString()
|
||||||
.replace("%address%", TFM_ConfigEntry.SERVER_ADDRESS.getString() + (forceIpPort == TFM_PlayerListener.DEFAULT_PORT ? "" : ":" + forceIpPort)));
|
.replace("%address%", ConfigEntry.SERVER_ADDRESS.getString() + (forceIpPort == PlayerListener.DEFAULT_PORT ? "" : ":" + forceIpPort)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,7 +152,7 @@ public class TFM_ServerInterface
|
|||||||
|
|
||||||
// Check if player is admin
|
// Check if player is admin
|
||||||
// Not safe to use TFM_Util.isSuperAdmin(player) because player.getAddress() will return a null until after player login.
|
// Not safe to use TFM_Util.isSuperAdmin(player) because player.getAddress() will return a null until after player login.
|
||||||
final boolean isAdmin = TFM_AdminList.isSuperAdminSafe(uuid, ip);
|
final boolean isAdmin = plugin.al.getEntryByIp(ip) != null;
|
||||||
|
|
||||||
// Validation below this point
|
// Validation below this point
|
||||||
if (isAdmin) // Player is superadmin
|
if (isAdmin) // Player is superadmin
|
||||||
@ -145,7 +165,7 @@ public class TFM_ServerInterface
|
|||||||
{
|
{
|
||||||
for (Player onlinePlayer : server.getOnlinePlayers())
|
for (Player onlinePlayer : server.getOnlinePlayers())
|
||||||
{
|
{
|
||||||
if (!TFM_AdminList.isSuperAdmin(onlinePlayer))
|
if (!plugin.al.isAdmin(onlinePlayer))
|
||||||
{
|
{
|
||||||
onlinePlayer.kickPlayer("You have been kicked to free up room for an admin.");
|
onlinePlayer.kickPlayer("You have been kicked to free up room for an admin.");
|
||||||
count--;
|
count--;
|
||||||
@ -176,7 +196,7 @@ public class TFM_ServerInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Admin-only mode
|
// Admin-only mode
|
||||||
if (TFM_ConfigEntry.ADMIN_ONLY_MODE.getBoolean())
|
if (ConfigEntry.ADMIN_ONLY_MODE.getBoolean())
|
||||||
{
|
{
|
||||||
event.disallow(Result.KICK_OTHER, "Server is temporarily open to admins only.");
|
event.disallow(Result.KICK_OTHER, "Server is temporarily open to admins only.");
|
||||||
return;
|
return;
|
||||||
@ -199,46 +219,42 @@ public class TFM_ServerInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// UUID ban
|
|
||||||
if (TFM_BanManager.isUuidBanned(uuid))
|
|
||||||
{
|
|
||||||
final TFM_Ban ban = TFM_BanManager.getByUuid(uuid);
|
|
||||||
event.disallow(Result.KICK_OTHER, ban.getKickMessage());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// IP ban
|
|
||||||
if (TFM_BanManager.isIpBanned(ip))
|
|
||||||
{
|
|
||||||
final TFM_Ban ban = TFM_BanManager.getByIp(ip);
|
|
||||||
event.disallow(Result.KICK_OTHER, ban.getKickMessage());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Permbanned IPs
|
// Permbanned IPs
|
||||||
for (String testIp : TFM_PermbanList.getPermbannedIps())
|
for (String testIp : plugin.pb.getPermbannedIps())
|
||||||
{
|
{
|
||||||
if (TFM_Util.fuzzyIpMatch(testIp, ip, 4))
|
if (FUtil.fuzzyIpMatch(testIp, ip, 4))
|
||||||
{
|
{
|
||||||
event.disallow(Result.KICK_OTHER,
|
event.disallow(Result.KICK_OTHER,
|
||||||
ChatColor.RED + "Your IP address is permanently banned from this server.\n"
|
ChatColor.RED + "Your IP address is permanently banned from this server.\n"
|
||||||
+ "Release procedures are available at\n"
|
+ "Release procedures are available at\n"
|
||||||
+ ChatColor.GOLD + TFM_ConfigEntry.SERVER_PERMBAN_URL.getString());
|
+ ChatColor.GOLD + ConfigEntry.SERVER_PERMBAN_URL.getString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Permbanned usernames
|
// Permbanned usernames
|
||||||
for (String testPlayer : TFM_PermbanList.getPermbannedPlayers())
|
for (String testPlayer : plugin.pb.getPermbannedNames())
|
||||||
{
|
{
|
||||||
if (testPlayer.equalsIgnoreCase(username))
|
if (testPlayer.equalsIgnoreCase(username))
|
||||||
{
|
{
|
||||||
event.disallow(Result.KICK_OTHER,
|
event.disallow(Result.KICK_OTHER,
|
||||||
ChatColor.RED + "Your username is permanently banned from this server.\n"
|
ChatColor.RED + "Your username is permanently banned from this server.\n"
|
||||||
+ "Release procedures are available at\n"
|
+ "Release procedures are available at\n"
|
||||||
+ ChatColor.GOLD + TFM_ConfigEntry.SERVER_PERMBAN_URL.getString());
|
+ ChatColor.GOLD + ConfigEntry.SERVER_PERMBAN_URL.getString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Regular ban
|
||||||
|
FBan ban = plugin.bm.getByUsername(username);
|
||||||
|
if (ban == null)
|
||||||
|
{
|
||||||
|
ban = plugin.bm.getByIp(ip);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ban != null)
|
||||||
|
{
|
||||||
|
event.disallow(Result.KICK_OTHER, ban.bakeKickMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,40 +1,46 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod;
|
package me.totalfreedom.totalfreedommod;
|
||||||
|
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||||
|
import net.pravian.aero.component.service.AbstractService;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
import org.json.simple.JSONArray;
|
import org.json.simple.JSONArray;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
import org.json.simple.JSONValue;
|
import org.json.simple.JSONValue;
|
||||||
|
|
||||||
public class TFM_ServiceChecker
|
public class ServiceChecker extends AbstractService<TotalFreedomMod>
|
||||||
{
|
{
|
||||||
public static final Map<String, ServiceStatus> services;
|
|
||||||
private static URL url;
|
|
||||||
private static String lastCheck;
|
|
||||||
private static String version;
|
|
||||||
|
|
||||||
private TFM_ServiceChecker()
|
@Getter
|
||||||
{
|
private final Map<String, ServiceStatus> services = Maps.newHashMap();
|
||||||
throw new AssertionError();
|
//
|
||||||
}
|
private BukkitTask task;
|
||||||
|
private URL url = null;
|
||||||
|
@Getter
|
||||||
|
private String lastCheck = "Never";
|
||||||
|
@Getter
|
||||||
|
private String version = "Mojang";
|
||||||
|
|
||||||
static
|
public ServiceChecker(TotalFreedomMod plugin)
|
||||||
{
|
{
|
||||||
lastCheck = "Unknown";
|
super(plugin);
|
||||||
version = "1.0-Mojang";
|
|
||||||
services = new HashMap<String, ServiceStatus>();
|
|
||||||
services.put("minecraft.net", new ServiceStatus("Minecraft.net"));
|
services.put("minecraft.net", new ServiceStatus("Minecraft.net"));
|
||||||
services.put("account.mojang.com", new ServiceStatus("Mojang Account Website"));
|
services.put("account.mojang.com", new ServiceStatus("Mojang Account Website"));
|
||||||
services.put("authserver.mojang.com", new ServiceStatus("Mojang Authentication"));
|
services.put("authserver.mojang.com", new ServiceStatus("Mojang Authentication"));
|
||||||
@ -44,9 +50,10 @@ public class TFM_ServiceChecker
|
|||||||
services.put("session.minecraft.net", new ServiceStatus("Minecraft Sessions (Legacy)"));
|
services.put("session.minecraft.net", new ServiceStatus("Minecraft Sessions (Legacy)"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void start()
|
@Override
|
||||||
|
protected void onStart()
|
||||||
{
|
{
|
||||||
final String serviceCheckerURL = TFM_ConfigEntry.SERVICE_CHECKER_URL.getString();
|
final String serviceCheckerURL = ConfigEntry.SERVICE_CHECKER_URL.getString();
|
||||||
|
|
||||||
if (serviceCheckerURL == null || serviceCheckerURL.isEmpty())
|
if (serviceCheckerURL == null || serviceCheckerURL.isEmpty())
|
||||||
{
|
{
|
||||||
@ -59,14 +66,30 @@ public class TFM_ServiceChecker
|
|||||||
}
|
}
|
||||||
catch (MalformedURLException ex)
|
catch (MalformedURLException ex)
|
||||||
{
|
{
|
||||||
TFM_Log.severe("Invalid ServiceChecker URL, disabling service checker");
|
FLog.severe("Invalid ServiceChecker URL, disabling service checker");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
getUpdateRunnable().runTaskTimerAsynchronously(TotalFreedomMod.plugin, 40L, TotalFreedomMod.SERVICE_CHECKER_RATE * 20L);
|
task = getUpdateRunnable().runTaskTimerAsynchronously(TotalFreedomMod.plugin, 40L, TotalFreedomMod.SERVICE_CHECKER_RATE * 20L);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BukkitRunnable getUpdateRunnable()
|
@Override
|
||||||
|
protected void onStop()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
task.cancel();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
task = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public BukkitRunnable getUpdateRunnable()
|
||||||
{
|
{
|
||||||
return new BukkitRunnable()
|
return new BukkitRunnable()
|
||||||
{
|
{
|
||||||
@ -87,8 +110,8 @@ public class TFM_ServiceChecker
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
TFM_Log.severe("Error updating mojang services from " + url);
|
FLog.severe("Error updating mojang services from " + url);
|
||||||
TFM_Log.severe(ex);
|
FLog.severe(ex);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,13 +158,13 @@ public class TFM_ServiceChecker
|
|||||||
}
|
}
|
||||||
if (lastCheck.equals("Unknown"))
|
if (lastCheck.equals("Unknown"))
|
||||||
{
|
{
|
||||||
lastCheck = TFM_Util.dateToString(new Date());
|
lastCheck = FUtil.dateToString(new Date());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<ServiceStatus> getAllStatuses()
|
public List<ServiceStatus> getAllStatuses()
|
||||||
{
|
{
|
||||||
List<ServiceStatus> servicesList = new ArrayList<ServiceStatus>();
|
List<ServiceStatus> servicesList = new ArrayList<ServiceStatus>();
|
||||||
for (String key : services.keySet())
|
for (String key : services.keySet())
|
||||||
@ -151,21 +174,17 @@ public class TFM_ServiceChecker
|
|||||||
return servicesList;
|
return servicesList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getLastCheck()
|
public class ServiceStatus
|
||||||
{
|
{
|
||||||
return lastCheck;
|
@Getter
|
||||||
}
|
private final String name;
|
||||||
|
@Getter
|
||||||
public static String getVersion()
|
@Setter
|
||||||
{
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class ServiceStatus
|
|
||||||
{
|
|
||||||
private String name;
|
|
||||||
private String uptime = "100.0"; // skins.minecraft.net, minecraft.net, etc..
|
private String uptime = "100.0"; // skins.minecraft.net, minecraft.net, etc..
|
||||||
|
@Getter
|
||||||
private ChatColor color = ChatColor.DARK_GREEN;
|
private ChatColor color = ChatColor.DARK_GREEN;
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
private String message = "Online"; // Online, Offline, Quite Slow, 404 Error, 500 Error, etc..
|
private String message = "Online"; // Online, Offline, Quite Slow, 404 Error, 500 Error, etc..
|
||||||
|
|
||||||
public ServiceStatus(String name)
|
public ServiceStatus(String name)
|
||||||
@ -173,16 +192,6 @@ public class TFM_ServiceChecker
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName()
|
|
||||||
{
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUptime()
|
|
||||||
{
|
|
||||||
return uptime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getUptimeFloat()
|
public float getUptimeFloat()
|
||||||
{
|
{
|
||||||
return Float.parseFloat(uptime);
|
return Float.parseFloat(uptime);
|
||||||
@ -193,21 +202,11 @@ public class TFM_ServiceChecker
|
|||||||
return (getUptimeFloat() > 95 ? ChatColor.GREEN : (getUptimeFloat() > 90 ? ChatColor.GOLD : ChatColor.RED));
|
return (getUptimeFloat() > 95 ? ChatColor.GREEN : (getUptimeFloat() > 90 ? ChatColor.GOLD : ChatColor.RED));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChatColor getColor()
|
|
||||||
{
|
|
||||||
return color;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMessage()
|
|
||||||
{
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFormattedStatus()
|
public String getFormattedStatus()
|
||||||
{
|
{
|
||||||
String status = ChatColor.BLUE + "- " + ChatColor.GRAY + name + ChatColor.WHITE + ": " + color + message + ChatColor.WHITE;
|
String status = ChatColor.BLUE + "- " + ChatColor.GRAY + name + ChatColor.WHITE + ": " + color + message + ChatColor.WHITE;
|
||||||
|
|
||||||
if (!TFM_ServiceChecker.version.contains("Mojang"))
|
if (!version.contains("Mojang"))
|
||||||
{
|
{
|
||||||
status += " (" + getUptimeColor() + getUptime() + ChatColor.WHITE + "%)";
|
status += " (" + getUptimeColor() + getUptime() + ChatColor.WHITE + "%)";
|
||||||
}
|
}
|
||||||
@ -215,16 +214,6 @@ public class TFM_ServiceChecker
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUptime(String uptime)
|
|
||||||
{
|
|
||||||
this.uptime = uptime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setColor(ChatColor color)
|
|
||||||
{
|
|
||||||
this.color = color;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setColor(String color)
|
public void setColor(String color)
|
||||||
{
|
{
|
||||||
if ("green".equals(color))
|
if ("green".equals(color))
|
||||||
@ -240,10 +229,6 @@ public class TFM_ServiceChecker
|
|||||||
this.color = ChatColor.RED;
|
this.color = ChatColor.RED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void setMessage(String message)
|
|
||||||
{
|
|
||||||
this.message = message;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
257
src/me/totalfreedom/totalfreedommod/TotalFreedomMod.java
Normal file
257
src/me/totalfreedom/totalfreedommod/TotalFreedomMod.java
Normal file
@ -0,0 +1,257 @@
|
|||||||
|
package me.totalfreedom.totalfreedommod;
|
||||||
|
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
|
import me.totalfreedom.totalfreedommod.PermbanList;
|
||||||
|
import me.totalfreedom.totalfreedommod.ProtectArea;
|
||||||
|
import me.totalfreedom.totalfreedommod.ServiceChecker;
|
||||||
|
import me.totalfreedom.totalfreedommod.ServerInterface;
|
||||||
|
import me.totalfreedom.totalfreedommod.Jumppads;
|
||||||
|
import me.totalfreedom.totalfreedommod.GameRuleHandler;
|
||||||
|
import me.totalfreedom.totalfreedommod.Heartbeat;
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||||
|
import me.totalfreedom.totalfreedommod.FrontDoor;
|
||||||
|
import me.totalfreedom.totalfreedommod.Announcer;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
|
import me.totalfreedom.totalfreedommod.admin.AdminList;
|
||||||
|
import me.totalfreedom.totalfreedommod.banning.BanManager;
|
||||||
|
import me.totalfreedom.totalfreedommod.bridge.BukkitTelnetBridge;
|
||||||
|
import me.totalfreedom.totalfreedommod.bridge.EssentialsBridge;
|
||||||
|
import me.totalfreedom.totalfreedommod.bridge.WorldEditBridge;
|
||||||
|
import me.totalfreedom.totalfreedommod.commandblocker.CommandBlocker;
|
||||||
|
import me.totalfreedom.totalfreedommod.commands.CommandLoader;
|
||||||
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||||
|
import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon;
|
||||||
|
import me.totalfreedom.totalfreedommod.listener.BlockListener;
|
||||||
|
import me.totalfreedom.totalfreedommod.listener.EntityListener;
|
||||||
|
import me.totalfreedom.totalfreedommod.listener.PlayerListener;
|
||||||
|
import me.totalfreedom.totalfreedommod.listener.ServerListener;
|
||||||
|
import me.totalfreedom.totalfreedommod.listener.WeatherListener;
|
||||||
|
import me.totalfreedom.totalfreedommod.permission.RankManager;
|
||||||
|
import me.totalfreedom.totalfreedommod.player.PlayerList;
|
||||||
|
import me.totalfreedom.totalfreedommod.rollback.RollbackManager;
|
||||||
|
import me.totalfreedom.totalfreedommod.world.TFM_WorldManager;
|
||||||
|
import net.pravian.aero.component.service.ServiceManager;
|
||||||
|
import net.pravian.aero.plugin.AeroPlugin;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import org.mcstats.Metrics;
|
||||||
|
|
||||||
|
public class TotalFreedomMod extends AeroPlugin<TotalFreedomMod>
|
||||||
|
{
|
||||||
|
public static final long HEARTBEAT_RATE = 5L; // Seconds
|
||||||
|
public static final long SERVICE_CHECKER_RATE = 120L;
|
||||||
|
public static final int MAX_USERNAME_LENGTH = 20;
|
||||||
|
//
|
||||||
|
public static final String CONFIG_FILENAME = "config.yml";
|
||||||
|
public static final String SUPERADMIN_FILENAME = "superadmin.yml";
|
||||||
|
public static final String PERMBAN_FILENAME = "permban.yml";
|
||||||
|
public static final String UUID_FILENAME = "uuids.db";
|
||||||
|
public static final String PROTECTED_AREA_FILENAME = "protectedareas.dat";
|
||||||
|
public static final String SAVED_FLAGS_FILENAME = "savedflags.dat";
|
||||||
|
//
|
||||||
|
public static final BuildProperties build = new BuildProperties();
|
||||||
|
//
|
||||||
|
public static TotalFreedomMod plugin;
|
||||||
|
public static String pluginName;
|
||||||
|
public static String pluginVersion;
|
||||||
|
//
|
||||||
|
public static boolean lockdownEnabled = false;
|
||||||
|
public static Map<Player, Double> fuckoffEnabledFor = new HashMap<Player, Double>();
|
||||||
|
//
|
||||||
|
// Services
|
||||||
|
public ServiceManager<TotalFreedomMod> services;
|
||||||
|
public ServerInterface si;
|
||||||
|
public AdminList al;
|
||||||
|
public RankManager rm;
|
||||||
|
public BanManager bm;
|
||||||
|
public PlayerList pl;
|
||||||
|
public CommandLoader cl;
|
||||||
|
public CommandBlocker cb;
|
||||||
|
public Announcer an;
|
||||||
|
public PermbanList pb;
|
||||||
|
public ProtectArea pa;
|
||||||
|
public ServiceChecker sc;
|
||||||
|
public GameRuleHandler gr;
|
||||||
|
public RollbackManager rb;
|
||||||
|
public Heartbeat hb;
|
||||||
|
public Jumppads jp;
|
||||||
|
public FrontDoor fd;
|
||||||
|
public HTTPDaemon hd;
|
||||||
|
public TFM_WorldManager wm;
|
||||||
|
//
|
||||||
|
// Bridges
|
||||||
|
public ServiceManager<TotalFreedomMod> bridges;
|
||||||
|
public BukkitTelnetBridge btb;
|
||||||
|
public EssentialsBridge esb;
|
||||||
|
public WorldEditBridge web;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void load()
|
||||||
|
{
|
||||||
|
TotalFreedomMod.plugin = this;
|
||||||
|
TotalFreedomMod.pluginName = plugin.getDescription().getName();
|
||||||
|
TotalFreedomMod.pluginVersion = plugin.getDescription().getVersion();
|
||||||
|
|
||||||
|
FLog.setPluginLogger(plugin.getLogger());
|
||||||
|
FLog.setServerLogger(server.getLogger());
|
||||||
|
|
||||||
|
build.load();
|
||||||
|
|
||||||
|
services = new ServiceManager<TotalFreedomMod>(plugin);
|
||||||
|
si = services.registerService(ServerInterface.class);
|
||||||
|
al = services.registerService(AdminList.class);
|
||||||
|
rm = services.registerService(RankManager.class);
|
||||||
|
bm = services.registerService(BanManager.class);
|
||||||
|
pl = services.registerService(PlayerList.class);
|
||||||
|
cl = services.registerService(CommandLoader.class);
|
||||||
|
cb = services.registerService(CommandBlocker.class);
|
||||||
|
an = services.registerService(Announcer.class);
|
||||||
|
pb = services.registerService(PermbanList.class);
|
||||||
|
pa = services.registerService(ProtectArea.class);
|
||||||
|
sc = services.registerService(ServiceChecker.class);
|
||||||
|
gr = services.registerService(GameRuleHandler.class);
|
||||||
|
rb = services.registerService(RollbackManager.class);
|
||||||
|
hb = services.registerService(Heartbeat.class);
|
||||||
|
jp = services.registerService(Jumppads.class);
|
||||||
|
fd = services.registerService(FrontDoor.class);
|
||||||
|
hd = services.registerService(HTTPDaemon.class);
|
||||||
|
wm = services.registerService(TFM_WorldManager.class);
|
||||||
|
|
||||||
|
bridges = new ServiceManager<TotalFreedomMod>(plugin);
|
||||||
|
btb = bridges.registerService(BukkitTelnetBridge.class);
|
||||||
|
esb = bridges.registerService(EssentialsBridge.class);
|
||||||
|
web = bridges.registerService(WorldEditBridge.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enable()
|
||||||
|
{
|
||||||
|
TotalFreedomMod.plugin = this;
|
||||||
|
|
||||||
|
FLog.info("Created by Madgeek1450 and Prozza");
|
||||||
|
FLog.info("Version " + build.formattedVersion());
|
||||||
|
FLog.info("Compiled " + build.date + " by " + build.builder);
|
||||||
|
|
||||||
|
final FUtil.MethodTimer timer = new FUtil.MethodTimer();
|
||||||
|
timer.start();
|
||||||
|
|
||||||
|
if (!ServerInterface.COMPILE_NMS_VERSION.equals(FUtil.getNmsVersion()))
|
||||||
|
{
|
||||||
|
FLog.warning(pluginName + " is compiled for " + ServerInterface.COMPILE_NMS_VERSION + " but the server is running "
|
||||||
|
+ "version " + FUtil.getNmsVersion() + "!");
|
||||||
|
FLog.warning("This might result in unexpected behaviour!");
|
||||||
|
}
|
||||||
|
|
||||||
|
FUtil.deleteCoreDumps();
|
||||||
|
FUtil.deleteFolder(new File("./_deleteme"));
|
||||||
|
|
||||||
|
// Create backups
|
||||||
|
FUtil.createBackups(CONFIG_FILENAME, true);
|
||||||
|
FUtil.createBackups(SUPERADMIN_FILENAME);
|
||||||
|
FUtil.createBackups(PERMBAN_FILENAME);
|
||||||
|
|
||||||
|
// Start services and bridges
|
||||||
|
services.start();
|
||||||
|
bridges.start();
|
||||||
|
|
||||||
|
// Register listeners
|
||||||
|
register(EntityListener.class);
|
||||||
|
register(BlockListener.class);
|
||||||
|
register(PlayerListener.class);
|
||||||
|
register(WeatherListener.class);
|
||||||
|
register(ServerListener.class);
|
||||||
|
|
||||||
|
// Disable weather
|
||||||
|
if (ConfigEntry.DISABLE_WEATHER.getBoolean())
|
||||||
|
{
|
||||||
|
for (World world : server.getWorlds())
|
||||||
|
{
|
||||||
|
world.setThundering(false);
|
||||||
|
world.setStorm(false);
|
||||||
|
world.setThunderDuration(0);
|
||||||
|
world.setWeatherDuration(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
timer.update();
|
||||||
|
|
||||||
|
FLog.info("Version " + pluginVersion + " for " + ServerInterface.COMPILE_NMS_VERSION + " enabled in " + timer.getTotal() + "ms");
|
||||||
|
|
||||||
|
// Metrics @ http://mcstats.org/plugin/TotalFreedomMod
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final Metrics metrics = new Metrics(plugin);
|
||||||
|
metrics.start();
|
||||||
|
}
|
||||||
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
FLog.warning("Failed to submit metrics data: " + ex.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add spawnpoints later - https://github.com/TotalFreedom/TotalFreedomMod/issues/438
|
||||||
|
new BukkitRunnable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
plugin.pa.autoAddSpawnpoints();
|
||||||
|
}
|
||||||
|
}.runTaskLater(plugin, 60L);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void disable()
|
||||||
|
{
|
||||||
|
// Stop services and bridges
|
||||||
|
services.stop();
|
||||||
|
bridges.stop();
|
||||||
|
|
||||||
|
server.getScheduler().cancelTasks(plugin);
|
||||||
|
|
||||||
|
FLog.info("Plugin disabled");
|
||||||
|
TotalFreedomMod.plugin = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class BuildProperties
|
||||||
|
{
|
||||||
|
public String builder;
|
||||||
|
public String number;
|
||||||
|
public String head;
|
||||||
|
public String date;
|
||||||
|
|
||||||
|
public void load()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final InputStream in = plugin.getResource("build.properties");
|
||||||
|
|
||||||
|
final Properties props = new Properties();
|
||||||
|
props.load(in);
|
||||||
|
in.close();
|
||||||
|
|
||||||
|
builder = props.getProperty("program.builder", "unknown");
|
||||||
|
number = props.getProperty("program.buildnumber", "1");
|
||||||
|
head = props.getProperty("program.buildhead", "unknown");
|
||||||
|
date = props.getProperty("program.builddate", "unknown");
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
FLog.severe("Could not load build properties! Did you compile with Netbeans/ANT?");
|
||||||
|
FLog.severe(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String formattedVersion()
|
||||||
|
{
|
||||||
|
return pluginVersion + "." + number + " (" + head + ")";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,16 +1,18 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod;
|
package me.totalfreedom.totalfreedommod;
|
||||||
|
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
public class TFM_TwitterHandler
|
public class TwitterHandler
|
||||||
{
|
{
|
||||||
private TFM_TwitterHandler()
|
private TwitterHandler()
|
||||||
{
|
{
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
@ -39,31 +41,31 @@ public class TFM_TwitterHandler
|
|||||||
final String reply = delTwitter(targetName);
|
final String reply = delTwitter(targetName);
|
||||||
if ("ok".equals(reply))
|
if ("ok".equals(reply))
|
||||||
{
|
{
|
||||||
TFM_Util.adminAction(sender.getName(), "Removing " + targetName + " from TwitterBot", true);
|
FUtil.adminAction(sender.getName(), "Removing " + targetName + " from TwitterBot", true);
|
||||||
}
|
}
|
||||||
else if ("disabled".equals(reply))
|
else if ("disabled".equals(reply))
|
||||||
{
|
{
|
||||||
TFM_Util.playerMsg(sender, "Warning: Could not check if player has a twitter handle!");
|
FUtil.playerMsg(sender, "Warning: Could not check if player has a twitter handle!");
|
||||||
TFM_Util.playerMsg(sender, "TwitterBot has been temporarily disabled, please wait until it gets re-enabled", ChatColor.RED);
|
FUtil.playerMsg(sender, "TwitterBot has been temporarily disabled, please wait until it gets re-enabled", ChatColor.RED);
|
||||||
}
|
}
|
||||||
else if ("failed".equals(reply))
|
else if ("failed".equals(reply))
|
||||||
{
|
{
|
||||||
TFM_Util.playerMsg(sender, "Warning: Could not check if player has a twitter handle!");
|
FUtil.playerMsg(sender, "Warning: Could not check if player has a twitter handle!");
|
||||||
TFM_Util.playerMsg(sender, "There was a problem querying the database, please let a developer know.", ChatColor.RED);
|
FUtil.playerMsg(sender, "There was a problem querying the database, please let a developer know.", ChatColor.RED);
|
||||||
}
|
}
|
||||||
else if ("false".equals(reply))
|
else if ("false".equals(reply))
|
||||||
{
|
{
|
||||||
TFM_Util.playerMsg(sender, "Warning: Could not check if player has a twitter handle!");
|
FUtil.playerMsg(sender, "Warning: Could not check if player has a twitter handle!");
|
||||||
TFM_Util.playerMsg(sender, "There was a problem with the database, please let a developer know.", ChatColor.RED);
|
FUtil.playerMsg(sender, "There was a problem with the database, please let a developer know.", ChatColor.RED);
|
||||||
}
|
}
|
||||||
else if ("cannotauth".equals(reply))
|
else if ("cannotauth".equals(reply))
|
||||||
{
|
{
|
||||||
TFM_Util.playerMsg(sender, "Warning: Could not check if player has a twitter handle!");
|
FUtil.playerMsg(sender, "Warning: Could not check if player has a twitter handle!");
|
||||||
TFM_Util.playerMsg(sender, "The database password is incorrect, please let a developer know.", ChatColor.RED);
|
FUtil.playerMsg(sender, "The database password is incorrect, please let a developer know.", ChatColor.RED);
|
||||||
}
|
}
|
||||||
else if ("notfound".equals(reply))
|
else if ("notfound".equals(reply))
|
||||||
{
|
{
|
||||||
TFM_Util.playerMsg(sender, targetName + " did not have a twitter handle registered to their name.", ChatColor.GREEN);
|
FUtil.playerMsg(sender, targetName + " did not have a twitter handle registered to their name.", ChatColor.GREEN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,8 +83,8 @@ public class TFM_TwitterHandler
|
|||||||
{
|
{
|
||||||
String line = "failed";
|
String line = "failed";
|
||||||
|
|
||||||
final String twitterbotURL = TFM_ConfigEntry.TWITTERBOT_URL.getString();
|
final String twitterbotURL = ConfigEntry.TWITTERBOT_URL.getString();
|
||||||
final String twitterbotSecret = TFM_ConfigEntry.TWITTERBOT_SECRET.getString();
|
final String twitterbotSecret = ConfigEntry.TWITTERBOT_SECRET.getString();
|
||||||
|
|
||||||
if (twitterbotURL != null && twitterbotSecret != null && !twitterbotURL.isEmpty() && !twitterbotSecret.isEmpty())
|
if (twitterbotURL != null && twitterbotSecret != null && !twitterbotURL.isEmpty() && !twitterbotSecret.isEmpty())
|
||||||
{
|
{
|
||||||
@ -97,7 +99,7 @@ public class TFM_TwitterHandler
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
TFM_Log.severe(ex);
|
FLog.severe(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
145
src/me/totalfreedom/totalfreedommod/admin/Admin.java
Normal file
145
src/me/totalfreedom/totalfreedommod/admin/Admin.java
Normal file
@ -0,0 +1,145 @@
|
|||||||
|
package me.totalfreedom.totalfreedommod.admin;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
|
import net.pravian.aero.base.ConfigLoadable;
|
||||||
|
import net.pravian.aero.base.ConfigSavable;
|
||||||
|
import net.pravian.aero.base.Validatable;
|
||||||
|
import net.pravian.aero.util.Ips;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.commons.lang3.Validate;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Admin implements ConfigLoadable, ConfigSavable, Validatable
|
||||||
|
{
|
||||||
|
@Getter
|
||||||
|
private String configKey;
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private String name;
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private boolean activated = true;
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private PlayerRank rank = PlayerRank.SUPER_ADMIN;
|
||||||
|
@Getter
|
||||||
|
private final List<String> ips = Lists.newArrayList();
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private Date lastLogin = new Date();
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private String loginMessage = null;
|
||||||
|
|
||||||
|
public Admin(Player player)
|
||||||
|
{
|
||||||
|
this.configKey = player.getName().toLowerCase();
|
||||||
|
this.name = player.getName();
|
||||||
|
this.ips.add(Ips.getIp(player));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Admin(String configKey)
|
||||||
|
{
|
||||||
|
this.configKey = configKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
final StringBuilder output = new StringBuilder();
|
||||||
|
|
||||||
|
output.append("Admin: ").append(name).append("\n")
|
||||||
|
.append("- Last Login Name: ").append(name).append("\n")
|
||||||
|
.append("- IPs: ").append(StringUtils.join(ips, ", ")).append("\n")
|
||||||
|
.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);
|
||||||
|
|
||||||
|
return output.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadFrom(Player player)
|
||||||
|
{
|
||||||
|
configKey = player.getName().toLowerCase();
|
||||||
|
name = player.getName();
|
||||||
|
ips.clear();
|
||||||
|
ips.add(Ips.getIp(player));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadFrom(ConfigurationSection cs)
|
||||||
|
{
|
||||||
|
name = cs.getString("username", configKey);
|
||||||
|
activated = cs.getBoolean("active", true);
|
||||||
|
rank = PlayerRank.forString(cs.getString("rank"));
|
||||||
|
ips.clear();
|
||||||
|
ips.addAll(cs.getStringList("ips"));
|
||||||
|
lastLogin = FUtil.stringToDate(cs.getString("last_login"));
|
||||||
|
loginMessage = cs.getString("login_message", null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveTo(ConfigurationSection cs)
|
||||||
|
{
|
||||||
|
Validate.isTrue(isValid(), "Could not save admin entry: " + name + ". Entry not valid!");
|
||||||
|
cs.set("username", name);
|
||||||
|
cs.set("active", activated);
|
||||||
|
cs.set("rank", rank.toString());
|
||||||
|
cs.set("ips", ips);
|
||||||
|
cs.set("last_login", lastLogin);
|
||||||
|
cs.set("login_message", null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMinimum(PlayerRank pRank)
|
||||||
|
{
|
||||||
|
return rank.ordinal() >= pRank.ordinal();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Util IP methods
|
||||||
|
public void addIp(String ip)
|
||||||
|
{
|
||||||
|
if (!ips.contains(ip))
|
||||||
|
{
|
||||||
|
ips.add(ip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addIps(List<String> ips)
|
||||||
|
{
|
||||||
|
for (String ip : ips)
|
||||||
|
{
|
||||||
|
addIp(ip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeIp(String ip)
|
||||||
|
{
|
||||||
|
if (ips.contains(ip))
|
||||||
|
{
|
||||||
|
ips.remove(ip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearIPs()
|
||||||
|
{
|
||||||
|
ips.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValid()
|
||||||
|
{
|
||||||
|
return configKey != null
|
||||||
|
&& name != null
|
||||||
|
&& rank != null
|
||||||
|
&& !ips.isEmpty()
|
||||||
|
&& lastLogin != null;
|
||||||
|
}
|
||||||
|
}
|
411
src/me/totalfreedom/totalfreedommod/admin/AdminList.java
Normal file
411
src/me/totalfreedom/totalfreedommod/admin/AdminList.java
Normal file
@ -0,0 +1,411 @@
|
|||||||
|
package me.totalfreedom.totalfreedommod.admin;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import lombok.Getter;
|
||||||
|
import me.totalfreedom.totalfreedommod.commands.Command_logs;
|
||||||
|
import me.totalfreedom.totalfreedommod.config.FConfig;
|
||||||
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||||
|
import me.totalfreedom.totalfreedommod.TwitterHandler;
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||||
|
import net.pravian.aero.component.service.AbstractService;
|
||||||
|
import net.pravian.aero.util.Ips;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.ServicePriority;
|
||||||
|
|
||||||
|
public class AdminList extends AbstractService<TotalFreedomMod>
|
||||||
|
{
|
||||||
|
@Getter
|
||||||
|
private final Map<String, Admin> allAdmins = Maps.newHashMap(); // Includes disabled admins
|
||||||
|
// Only active admins below
|
||||||
|
@Getter
|
||||||
|
private final Set<Admin> activeAdmins = Sets.newHashSet();
|
||||||
|
private final Map<String, Admin> nameTable = Maps.newHashMap();
|
||||||
|
private final Map<String, Admin> ipTable = Maps.newHashMap();
|
||||||
|
//
|
||||||
|
private int cleanThreshold = 24 * 7; // 1 Week in hours
|
||||||
|
private final FConfig config;
|
||||||
|
|
||||||
|
public AdminList(TotalFreedomMod plugin)
|
||||||
|
{
|
||||||
|
super(plugin);
|
||||||
|
|
||||||
|
this.config = new FConfig(TotalFreedomMod.plugin, TotalFreedomMod.SUPERADMIN_FILENAME, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStart()
|
||||||
|
{
|
||||||
|
load();
|
||||||
|
|
||||||
|
server.getServicesManager().register(Function.class, new Function<Player, Boolean>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public Boolean apply(Player player)
|
||||||
|
{
|
||||||
|
return isAdmin(player);
|
||||||
|
}
|
||||||
|
}, plugin, ServicePriority.Normal);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStop()
|
||||||
|
{
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void load()
|
||||||
|
{
|
||||||
|
config.load();
|
||||||
|
|
||||||
|
allAdmins.clear();
|
||||||
|
for (String key : config.getKeys(true))
|
||||||
|
{
|
||||||
|
Admin admin = new Admin(key);
|
||||||
|
admin.loadFrom(config.getConfigurationSection(key));
|
||||||
|
|
||||||
|
if (!admin.isValid())
|
||||||
|
{
|
||||||
|
FLog.warning("Could not load admin: " + key + ". Missing details!");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
allAdmins.put(key, admin);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateTables();
|
||||||
|
FLog.info("Loaded " + nameTable.size() + " admins (" + nameTable.size() + " active) and " + ipTable.size() + " IPs.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save()
|
||||||
|
{
|
||||||
|
// Clear the config
|
||||||
|
for (String key : config.getKeys(false))
|
||||||
|
{
|
||||||
|
config.set(key, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Admin admin : allAdmins.values())
|
||||||
|
{
|
||||||
|
admin.saveTo(config.createSection(admin.getConfigKey()));
|
||||||
|
}
|
||||||
|
|
||||||
|
config.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save(Admin admin)
|
||||||
|
{
|
||||||
|
if (!allAdmins.values().contains(admin))
|
||||||
|
{ // Ensure admin is present
|
||||||
|
addAdmin(admin, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
admin.saveTo(config.createSection(admin.getConfigKey()));
|
||||||
|
config.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized boolean isAdminSync(CommandSender sender)
|
||||||
|
{
|
||||||
|
return isAdmin(sender);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAdmin(CommandSender sender)
|
||||||
|
{
|
||||||
|
if (!(sender instanceof Player))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return getAdmin((Player) sender) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSeniorAdmin(CommandSender sender)
|
||||||
|
{
|
||||||
|
Admin admin = getAdmin(sender);
|
||||||
|
if (admin == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return admin.getRank().ordinal() >= PlayerRank.SENIOR_ADMIN.ordinal();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Admin getAdmin(CommandSender sender)
|
||||||
|
{
|
||||||
|
if (sender instanceof Player)
|
||||||
|
{
|
||||||
|
return getAdmin((Player) sender);
|
||||||
|
}
|
||||||
|
|
||||||
|
return getEntryByName(sender.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Admin getAdmin(Player player)
|
||||||
|
{
|
||||||
|
String ip = Ips.getIp(player);
|
||||||
|
Admin admin = getEntryByIp(ip, true);
|
||||||
|
|
||||||
|
if (admin == null && Bukkit.getOnlineMode())
|
||||||
|
{
|
||||||
|
admin = getEntryByName(player.getName());
|
||||||
|
|
||||||
|
// Add new IP
|
||||||
|
if (admin != null)
|
||||||
|
{
|
||||||
|
admin.addIp(ip);
|
||||||
|
save(admin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return admin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Admin getEntryByName(String name)
|
||||||
|
{
|
||||||
|
return nameTable.get(name.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Admin getEntryByIp(String ip)
|
||||||
|
{
|
||||||
|
return getEntryByIp(ip, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Admin getEntryByIp(String needleIp, boolean fuzzy)
|
||||||
|
{
|
||||||
|
Admin admin = ipTable.get(needleIp);
|
||||||
|
|
||||||
|
if (admin != null || !fuzzy)
|
||||||
|
{
|
||||||
|
return admin;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String ip : ipTable.keySet())
|
||||||
|
{
|
||||||
|
if (FUtil.fuzzyIpMatch(needleIp, ip, 3))
|
||||||
|
{
|
||||||
|
return ipTable.get(ip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return admin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateLastLogin(Player player)
|
||||||
|
{
|
||||||
|
final Admin admin = getAdmin(player);
|
||||||
|
if (admin == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
admin.setLastLogin(new Date());
|
||||||
|
admin.setName(player.getName());
|
||||||
|
save(admin);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAdminImpostor(Player player)
|
||||||
|
{
|
||||||
|
return getEntryByName(player.getName()) != null && !isAdmin(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isIdentityMatched(Player player)
|
||||||
|
{
|
||||||
|
if (Bukkit.getOnlineMode())
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Admin admin = getAdmin(player);
|
||||||
|
return admin == null ? false : admin.getName().equalsIgnoreCase(player.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean addAdmin(Admin admin)
|
||||||
|
{
|
||||||
|
return addAdmin(admin, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean addAdmin(Admin admin, boolean overwrite)
|
||||||
|
{
|
||||||
|
final String key = admin.getConfigKey();
|
||||||
|
|
||||||
|
if (!overwrite && allAdmins.containsKey(key))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store admin, update views
|
||||||
|
allAdmins.put(key, admin);
|
||||||
|
updateTables();
|
||||||
|
|
||||||
|
// Save admin
|
||||||
|
admin.saveTo(config.createSection(key));
|
||||||
|
config.save();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean removeAdmin(Admin admin)
|
||||||
|
{
|
||||||
|
|
||||||
|
// Remove admin, update views
|
||||||
|
if (allAdmins.remove(admin.getName().toLowerCase()) == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
updateTables();
|
||||||
|
|
||||||
|
// 'Unsave' admin
|
||||||
|
config.set(admin.getConfigKey(), null);
|
||||||
|
config.save();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateTables()
|
||||||
|
{
|
||||||
|
activeAdmins.clear();
|
||||||
|
nameTable.clear();
|
||||||
|
ipTable.clear();
|
||||||
|
|
||||||
|
for (Admin admin : allAdmins.values())
|
||||||
|
{
|
||||||
|
if (!admin.isActivated())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
activeAdmins.add(admin);
|
||||||
|
nameTable.put(admin.getName().toLowerCase(), admin);
|
||||||
|
|
||||||
|
for (String ip : admin.getIps())
|
||||||
|
{
|
||||||
|
ipTable.put(ip, admin);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin.wm.adminworld.wipeAccessCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<String> getAdminNames()
|
||||||
|
{
|
||||||
|
return nameTable.keySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<String> getAdminIps()
|
||||||
|
{
|
||||||
|
return ipTable.keySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Date lastLogin = admin.getLastLogin();
|
||||||
|
final long lastLoginHours = TimeUnit.HOURS.convert(new Date().getTime() - lastLogin.getTime(), TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
|
if (lastLoginHours < cleanThreshold)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (verbose)
|
||||||
|
{
|
||||||
|
FUtil.adminAction("TotalFreedomMod", "Deactivating superadmin " + admin.getName() + ", inactive for " + lastLoginHours + " hours.", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
admin.setActivated(false);
|
||||||
|
Command_logs.deactivateSuperadmin(admin);
|
||||||
|
TwitterHandler.delTwitter(admin.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
save();
|
||||||
|
updateTables();
|
||||||
|
}
|
||||||
|
}
|
255
src/me/totalfreedom/totalfreedommod/banning/BanManager.java
Normal file
255
src/me/totalfreedom/totalfreedommod/banning/BanManager.java
Normal file
@ -0,0 +1,255 @@
|
|||||||
|
package me.totalfreedom.totalfreedommod.banning;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||||
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||||
|
import net.pravian.aero.component.service.AbstractService;
|
||||||
|
import net.pravian.aero.config.YamlConfig;
|
||||||
|
import net.pravian.aero.util.Ips;
|
||||||
|
|
||||||
|
public class BanManager extends AbstractService<TotalFreedomMod>
|
||||||
|
{
|
||||||
|
private final Set<FBan> bans = Sets.newHashSet();
|
||||||
|
private final Map<String, FBan> ipBans = Maps.newHashMap();
|
||||||
|
private final Map<String, FBan> nameBans = Maps.newHashMap();
|
||||||
|
private final List<String> unbannableUsernames = Lists.newArrayList();
|
||||||
|
//
|
||||||
|
private final YamlConfig config;
|
||||||
|
|
||||||
|
public BanManager(TotalFreedomMod plugin)
|
||||||
|
{
|
||||||
|
super(plugin);
|
||||||
|
this.config = new YamlConfig(TotalFreedomMod.plugin, "bans.yml");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStart()
|
||||||
|
{
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStop()
|
||||||
|
{
|
||||||
|
saveAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void load()
|
||||||
|
{
|
||||||
|
config.load();
|
||||||
|
|
||||||
|
bans.clear();
|
||||||
|
for (String id : config.getKeys(false))
|
||||||
|
{
|
||||||
|
if (!config.isConfigurationSection(id))
|
||||||
|
{
|
||||||
|
FLog.warning("Could not load username ban: " + id + ". Invalid format!");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
FBan ban = new FBan();
|
||||||
|
ban.loadFrom(config.getConfigurationSection(id));
|
||||||
|
|
||||||
|
if (!ban.isValid())
|
||||||
|
{
|
||||||
|
FLog.warning("Not adding username ban: " + id + ". Missing information.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
bans.add(ban);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove expired bans, repopulate ipBans and nameBans,
|
||||||
|
updateViews();
|
||||||
|
|
||||||
|
FLog.info("Loaded " + ipBans.size() + " IP bans and " + nameBans.size() + " username bans");
|
||||||
|
|
||||||
|
// Load unbannable usernames
|
||||||
|
unbannableUsernames.clear();
|
||||||
|
unbannableUsernames.addAll((Collection<? extends String>) ConfigEntry.UNBANNABLE_USERNAMES.getList());
|
||||||
|
FLog.info("Loaded " + unbannableUsernames.size() + " unbannable usernames.");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateViews()
|
||||||
|
{
|
||||||
|
|
||||||
|
// Remove expired bans
|
||||||
|
for (Iterator<FBan> it = bans.iterator(); it.hasNext();)
|
||||||
|
{
|
||||||
|
if (it.next().isExpired())
|
||||||
|
{
|
||||||
|
it.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ipBans.clear();
|
||||||
|
nameBans.clear();
|
||||||
|
for (FBan ban : bans)
|
||||||
|
{
|
||||||
|
if (ban.hasUsername())
|
||||||
|
{
|
||||||
|
nameBans.put(ban.getUsername().toLowerCase(), ban);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ban.hasIps())
|
||||||
|
{
|
||||||
|
for (String ip : ban.getIps())
|
||||||
|
{
|
||||||
|
ipBans.put(ip, ban);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveAll()
|
||||||
|
{
|
||||||
|
// Remove expired
|
||||||
|
updateViews();
|
||||||
|
|
||||||
|
for (FBan ban : bans)
|
||||||
|
{
|
||||||
|
ban.saveTo(config.createSection(String.valueOf(ban.hashCode())));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save config
|
||||||
|
config.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<FBan> getIpBans()
|
||||||
|
{
|
||||||
|
return Collections.unmodifiableCollection(ipBans.values());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<FBan> getUsernameBans()
|
||||||
|
{
|
||||||
|
return Collections.unmodifiableCollection(nameBans.values());
|
||||||
|
}
|
||||||
|
|
||||||
|
public FBan getByIp(String ip)
|
||||||
|
{
|
||||||
|
final FBan directBan = ipBans.get(ip);
|
||||||
|
if (directBan != null && !directBan.isExpired())
|
||||||
|
{
|
||||||
|
return directBan;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Match fuzzy IP
|
||||||
|
for (FBan loopBan : ipBans.values())
|
||||||
|
{
|
||||||
|
if (loopBan.isExpired())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String loopIp : loopBan.getIps())
|
||||||
|
{
|
||||||
|
if (!loopIp.contains("*"))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Ips.fuzzyIpMatch(ip, loopIp, 4))
|
||||||
|
{
|
||||||
|
return loopBan;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FBan getByUsername(String username)
|
||||||
|
{
|
||||||
|
username = username.toLowerCase();
|
||||||
|
final FBan directBan = nameBans.get(username);
|
||||||
|
|
||||||
|
if (directBan != null && !directBan.isExpired())
|
||||||
|
{
|
||||||
|
return directBan;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FBan unbanIp(String ip)
|
||||||
|
{
|
||||||
|
final FBan ban = getByIp(ip);
|
||||||
|
|
||||||
|
if (ban == null)
|
||||||
|
{
|
||||||
|
return ban;
|
||||||
|
}
|
||||||
|
|
||||||
|
bans.remove(ban);
|
||||||
|
saveAll();
|
||||||
|
return ban;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FBan unbanUsername(String username)
|
||||||
|
{
|
||||||
|
final FBan ban = getByUsername(username);
|
||||||
|
|
||||||
|
if (ban == null)
|
||||||
|
{
|
||||||
|
return ban;
|
||||||
|
}
|
||||||
|
|
||||||
|
bans.remove(ban);
|
||||||
|
saveAll();
|
||||||
|
return ban;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isIpBanned(String ip)
|
||||||
|
{
|
||||||
|
return getByIp(ip) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isUsernameBanned(String username)
|
||||||
|
{
|
||||||
|
return getByUsername(username) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean addBan(FBan ban)
|
||||||
|
{
|
||||||
|
if (bans.add(ban))
|
||||||
|
{
|
||||||
|
updateViews();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean removeBan(FBan ban)
|
||||||
|
{
|
||||||
|
if (bans.remove(ban))
|
||||||
|
{
|
||||||
|
updateViews();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void purgeIpBans()
|
||||||
|
{
|
||||||
|
ipBans.clear();
|
||||||
|
saveAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void purgeNameBans()
|
||||||
|
{
|
||||||
|
nameBans.clear();
|
||||||
|
saveAll();
|
||||||
|
}
|
||||||
|
}
|
260
src/me/totalfreedom/totalfreedommod/banning/FBan.java
Normal file
260
src/me/totalfreedom/totalfreedommod/banning/FBan.java
Normal file
@ -0,0 +1,260 @@
|
|||||||
|
package me.totalfreedom.totalfreedommod.banning;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
|
import net.pravian.aero.base.ConfigLoadable;
|
||||||
|
import net.pravian.aero.base.ConfigSavable;
|
||||||
|
import net.pravian.aero.base.Validatable;
|
||||||
|
import net.pravian.aero.util.Ips;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class FBan implements ConfigLoadable, ConfigSavable, Validatable
|
||||||
|
{
|
||||||
|
public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd \'at\' HH:mm:ss z");
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private String username = null;
|
||||||
|
@Getter
|
||||||
|
private final List<String> ips = Lists.newArrayList();
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private String by = null;
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private String reason = null; // Unformatted, &[0-9,a-f] instead of ChatColor
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private long expiryUnix = -1;
|
||||||
|
|
||||||
|
public FBan()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public FBan(String username, String ip, String by, Date expire, String reason)
|
||||||
|
{
|
||||||
|
this(username,
|
||||||
|
new String[]
|
||||||
|
{
|
||||||
|
ip
|
||||||
|
},
|
||||||
|
by,
|
||||||
|
expire,
|
||||||
|
reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FBan(String username, String[] ips, String by, Date expire, String reason)
|
||||||
|
{
|
||||||
|
this.username = username;
|
||||||
|
if (ips != null)
|
||||||
|
{
|
||||||
|
this.ips.addAll(Arrays.asList(ips));
|
||||||
|
}
|
||||||
|
this.by = by;
|
||||||
|
this.expiryUnix = FUtil.getUnixTime(expire);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// For player IP
|
||||||
|
public static FBan forPlayerIp(Player player, CommandSender by)
|
||||||
|
{
|
||||||
|
return forPlayerIp(player, by, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FBan forPlayerIp(Player player, CommandSender by, Date expiry, String reason)
|
||||||
|
{
|
||||||
|
return new FBan(null, new String[]
|
||||||
|
{
|
||||||
|
Ips.getIp(player)
|
||||||
|
}, by.getName(), expiry, reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FBan forPlayerIp(String ip, CommandSender by, Date expiry, String reason)
|
||||||
|
{
|
||||||
|
return new FBan(null, ip, by.getName(), expiry, reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// For player name
|
||||||
|
public static FBan forPlayerName(Player player, CommandSender by, Date expiry, String reason)
|
||||||
|
{
|
||||||
|
return forPlayerName(player.getName(), by, expiry, reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FBan forPlayerName(String player, CommandSender by, Date expiry, String reason)
|
||||||
|
{
|
||||||
|
return new FBan(player,
|
||||||
|
(String[]) null,
|
||||||
|
by.getName(),
|
||||||
|
expiry,
|
||||||
|
reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// For player
|
||||||
|
public static FBan forPlayer(Player player, CommandSender by)
|
||||||
|
{
|
||||||
|
return forPlayerName(player, by, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FBan forPlayer(Player player, CommandSender by, Date expiry, String reason)
|
||||||
|
{
|
||||||
|
return new FBan(player.getName(),
|
||||||
|
Ips.getIp(player),
|
||||||
|
by.getName(),
|
||||||
|
expiry,
|
||||||
|
reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FBan forPlayerFuzzy(Player player, CommandSender by, Date expiry, String reason)
|
||||||
|
{
|
||||||
|
return new FBan(player.getName(),
|
||||||
|
FUtil.getFuzzyIp(Ips.getIp(player)),
|
||||||
|
by.getName(),
|
||||||
|
expiry,
|
||||||
|
reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasUsername()
|
||||||
|
{
|
||||||
|
return username != null && !username.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean addIp(String ip)
|
||||||
|
{
|
||||||
|
return ips.add(ip);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean removeIp(String ip)
|
||||||
|
{
|
||||||
|
return ips.remove(ip);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasIps()
|
||||||
|
{
|
||||||
|
return !ips.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasExpiry()
|
||||||
|
{
|
||||||
|
return expiryUnix > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getExpiryDate()
|
||||||
|
{
|
||||||
|
return FUtil.getUnixDate(expiryUnix);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isExpired()
|
||||||
|
{
|
||||||
|
return hasExpiry() && expiryUnix < FUtil.getUnixTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String bakeKickMessage()
|
||||||
|
{
|
||||||
|
final StringBuilder message = new StringBuilder(ChatColor.GOLD + "You");
|
||||||
|
|
||||||
|
message.append(!hasUsername() ? "r IP address is" : " are").append(" temporarily banned from this server.");
|
||||||
|
message.append("\nAppeal at ").append(ChatColor.BLUE)
|
||||||
|
.append(ConfigEntry.SERVER_BAN_URL.getString());
|
||||||
|
|
||||||
|
if (reason != null)
|
||||||
|
{
|
||||||
|
message.append("\n").append(ChatColor.RED).append("Reason: ").append(ChatColor.GOLD)
|
||||||
|
.append(ChatColor.translateAlternateColorCodes('&', reason));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (by != null)
|
||||||
|
{
|
||||||
|
message.append("\n").append(ChatColor.RED).append("Banned by: ").append(ChatColor.GOLD)
|
||||||
|
.append(by);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getExpiryUnix() != 0)
|
||||||
|
{
|
||||||
|
message.append("\n").append(ChatColor.RED).append("Expires: ").append(ChatColor.GOLD)
|
||||||
|
.append(DATE_FORMAT.format(FUtil.getUnixDate(expiryUnix)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return message.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object object)
|
||||||
|
{
|
||||||
|
if (object == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(object instanceof FBan))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
final FBan ban = (FBan) object;
|
||||||
|
if (hasIps() != ban.hasIps()
|
||||||
|
|| hasUsername() != hasUsername())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasIps() && !(getIps().equals(ban.getIps())))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasUsername() && !(getUsername().equalsIgnoreCase(ban.getUsername())))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
int hash = 7;
|
||||||
|
hash = 79 * hash + (this.username != null ? this.username.toLowerCase().hashCode() : 0);
|
||||||
|
hash = 79 * hash + (this.ips != null ? this.ips.hashCode() : 0);
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadFrom(ConfigurationSection cs)
|
||||||
|
{
|
||||||
|
this.username = cs.getString("username", null);
|
||||||
|
this.ips.clear();
|
||||||
|
this.ips.addAll(cs.getStringList("ips"));
|
||||||
|
this.by = cs.getString("by", null);
|
||||||
|
this.reason = cs.getString("reason", null);
|
||||||
|
this.expiryUnix = cs.getLong("expiry_unix", -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveTo(ConfigurationSection cs)
|
||||||
|
{
|
||||||
|
cs.set("username", username);
|
||||||
|
cs.set("ips", ips.isEmpty() ? null : ips);
|
||||||
|
cs.set("by", by);
|
||||||
|
cs.set("reason", reason);
|
||||||
|
cs.set("expiry_unix", expiryUnix > 0 ? expiryUnix : null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValid()
|
||||||
|
{
|
||||||
|
return username != null || !ips.isEmpty();
|
||||||
|
}
|
||||||
|
}
|
@ -1,21 +1,36 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Bridge;
|
package me.totalfreedom.totalfreedommod.bridge;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import me.StevenLawson.BukkitTelnet.api.TelnetCommandEvent;
|
import me.StevenLawson.BukkitTelnet.api.TelnetCommandEvent;
|
||||||
import me.StevenLawson.BukkitTelnet.api.TelnetPreLoginEvent;
|
import me.StevenLawson.BukkitTelnet.api.TelnetPreLoginEvent;
|
||||||
import me.StevenLawson.BukkitTelnet.api.TelnetRequestDataTagsEvent;
|
import me.StevenLawson.BukkitTelnet.api.TelnetRequestDataTagsEvent;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Admin;
|
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_CommandBlocker;
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData;
|
import net.pravian.aero.component.service.AbstractService;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
|
|
||||||
public class TFM_BukkitTelnetListener implements Listener
|
public class BukkitTelnetBridge extends AbstractService<TotalFreedomMod>
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public BukkitTelnetBridge(TotalFreedomMod plugin)
|
||||||
|
{
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStart()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStop()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL)
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
public void onTelnetPreLogin(TelnetPreLoginEvent event)
|
public void onTelnetPreLogin(TelnetPreLoginEvent event)
|
||||||
{
|
{
|
||||||
@ -26,21 +41,21 @@ public class TFM_BukkitTelnetListener implements Listener
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final TFM_Admin admin = TFM_AdminList.getEntryByIp(ip, true);
|
final Admin admin = plugin.al.getEntryByIp(ip, true);
|
||||||
|
|
||||||
if (admin == null || !admin.isActivated() || !admin.isTelnetAdmin())
|
if (admin == null || !admin.isActivated() || !admin.getRank().hasConsole())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
event.setBypassPassword(true);
|
event.setBypassPassword(true);
|
||||||
event.setName(admin.getLastLoginName());
|
event.setName(admin.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL)
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
public void onTelnetCommand(TelnetCommandEvent event)
|
public void onTelnetCommand(TelnetCommandEvent event)
|
||||||
{
|
{
|
||||||
if (TFM_CommandBlocker.isCommandBlocked(event.getCommand(), event.getSender()))
|
if (plugin.cb.isCommandBlocked(event.getCommand(), event.getSender()))
|
||||||
{
|
{
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
@ -60,23 +75,23 @@ public class TFM_BukkitTelnetListener implements Listener
|
|||||||
boolean isTelnetAdmin = false;
|
boolean isTelnetAdmin = false;
|
||||||
boolean isSeniorAdmin = false;
|
boolean isSeniorAdmin = false;
|
||||||
|
|
||||||
final TFM_Admin admin = TFM_AdminList.getEntry(player);
|
final Admin admin = plugin.al.getAdmin(player);
|
||||||
if (admin != null)
|
if (admin != null)
|
||||||
{
|
{
|
||||||
boolean isActivated = admin.isActivated();
|
boolean isActivated = admin.isActivated();
|
||||||
|
|
||||||
isAdmin = isActivated;
|
isAdmin = isActivated;
|
||||||
isTelnetAdmin = isActivated && admin.isTelnetAdmin();
|
isSeniorAdmin = isActivated && admin.getRank() == PlayerRank.SENIOR_ADMIN;
|
||||||
isSeniorAdmin = isActivated && admin.isSeniorAdmin();
|
isTelnetAdmin = isActivated && (isSeniorAdmin || admin.getRank() == PlayerRank.TELNET_ADMIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
playerTags.put("tfm.admin.isAdmin", isAdmin);
|
playerTags.put("tfm.admin.isAdmin", isAdmin);
|
||||||
playerTags.put("tfm.admin.isTelnetAdmin", isTelnetAdmin);
|
playerTags.put("tfm.admin.isTelnetAdmin", isTelnetAdmin);
|
||||||
playerTags.put("tfm.admin.isSeniorAdmin", isSeniorAdmin);
|
playerTags.put("tfm.admin.isSeniorAdmin", isSeniorAdmin);
|
||||||
|
|
||||||
playerTags.put("tfm.playerdata.getTag", TFM_PlayerData.getPlayerData(player).getTag());
|
playerTags.put("tfm.playerdata.getTag", plugin.pl.getPlayer(player).getTag());
|
||||||
|
|
||||||
playerTags.put("tfm.essentialsBridge.getNickname", TFM_EssentialsBridge.getNickname(player.getName()));
|
playerTags.put("tfm.essentialsBridge.getNickname", plugin.esb.getNickname(player.getName()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,22 +1,35 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Bridge;
|
package me.totalfreedom.totalfreedommod.bridge;
|
||||||
|
|
||||||
import com.earth2me.essentials.Essentials;
|
import com.earth2me.essentials.Essentials;
|
||||||
import com.earth2me.essentials.User;
|
import com.earth2me.essentials.User;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Log;
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||||
|
import net.pravian.aero.component.service.AbstractService;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
public class TFM_EssentialsBridge
|
public class EssentialsBridge extends AbstractService<TotalFreedomMod>
|
||||||
{
|
{
|
||||||
private static Essentials essentialsPlugin = null;
|
|
||||||
|
|
||||||
private TFM_EssentialsBridge()
|
private Essentials essentialsPlugin = null;
|
||||||
|
|
||||||
|
public EssentialsBridge(TotalFreedomMod plugin)
|
||||||
{
|
{
|
||||||
throw new AssertionError();
|
super(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Essentials getEssentialsPlugin()
|
@Override
|
||||||
|
protected void onStart()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStop()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public Essentials getEssentialsPlugin()
|
||||||
{
|
{
|
||||||
if (essentialsPlugin == null)
|
if (essentialsPlugin == null)
|
||||||
{
|
{
|
||||||
@ -33,13 +46,13 @@ public class TFM_EssentialsBridge
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
TFM_Log.severe(ex);
|
FLog.severe(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return essentialsPlugin;
|
return essentialsPlugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static User getEssentialsUser(String username)
|
public User getEssentialsUser(String username)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -51,12 +64,12 @@ public class TFM_EssentialsBridge
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
TFM_Log.severe(ex);
|
FLog.severe(ex);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setNickname(String username, String nickname)
|
public void setNickname(String username, String nickname)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -69,11 +82,11 @@ public class TFM_EssentialsBridge
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
TFM_Log.severe(ex);
|
FLog.severe(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getNickname(String username)
|
public String getNickname(String username)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -85,29 +98,29 @@ public class TFM_EssentialsBridge
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
TFM_Log.severe(ex);
|
FLog.severe(ex);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long getLastActivity(String username)
|
public long getLastActivity(String username)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
final User user = getEssentialsUser(username);
|
final User user = getEssentialsUser(username);
|
||||||
if (user != null)
|
if (user != null)
|
||||||
{
|
{
|
||||||
return TFM_Util.<Long>getField(user, "lastActivity"); // This is weird
|
return FUtil.<Long>getField(user, "lastActivity"); // This is weird
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
TFM_Log.severe(ex);
|
FLog.severe(ex);
|
||||||
}
|
}
|
||||||
return 0L;
|
return 0L;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isEssentialsEnabled()
|
public boolean isEssentialsEnabled()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -119,7 +132,7 @@ public class TFM_EssentialsBridge
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
TFM_Log.severe(ex);
|
FLog.severe(ex);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
@ -1,23 +1,35 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Bridge;
|
package me.totalfreedom.totalfreedommod.bridge;
|
||||||
|
|
||||||
import com.sk89q.worldedit.LocalSession;
|
import com.sk89q.worldedit.LocalSession;
|
||||||
import com.sk89q.worldedit.bukkit.BukkitPlayer;
|
import com.sk89q.worldedit.bukkit.BukkitPlayer;
|
||||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Log;
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||||
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||||
|
import net.pravian.aero.component.service.AbstractService;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
public class TFM_WorldEditBridge
|
public class WorldEditBridge extends AbstractService<TotalFreedomMod>
|
||||||
{
|
{
|
||||||
private static WorldEditPlugin worldEditPlugin = null;
|
private static WorldEditPlugin worldEditPlugin = null;
|
||||||
|
|
||||||
private TFM_WorldEditBridge()
|
public WorldEditBridge(TotalFreedomMod plugin)
|
||||||
{
|
{
|
||||||
throw new AssertionError();
|
super(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static WorldEditPlugin getWorldEditPlugin()
|
@Override
|
||||||
|
protected void onStart()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStop()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
private WorldEditPlugin getWorldEditPlugin()
|
||||||
{
|
{
|
||||||
if (worldEditPlugin == null)
|
if (worldEditPlugin == null)
|
||||||
{
|
{
|
||||||
@ -34,13 +46,13 @@ public class TFM_WorldEditBridge
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
TFM_Log.severe(ex);
|
FLog.severe(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return worldEditPlugin;
|
return worldEditPlugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static LocalSession getPlayerSession(Player player)
|
private LocalSession getPlayerSession(Player player)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -52,12 +64,12 @@ public class TFM_WorldEditBridge
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
TFM_Log.severe(ex);
|
FLog.severe(ex);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static BukkitPlayer getBukkitPlayer(Player player)
|
private BukkitPlayer getBukkitPlayer(Player player)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -69,12 +81,12 @@ public class TFM_WorldEditBridge
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
TFM_Log.severe(ex);
|
FLog.severe(ex);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void undo(Player player, int count)
|
public void undo(Player player, int count)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -93,11 +105,11 @@ public class TFM_WorldEditBridge
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
TFM_Log.severe(ex);
|
FLog.severe(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setLimit(Player player, int limit)
|
public void setLimit(Player player, int limit)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -109,7 +121,7 @@ public class TFM_WorldEditBridge
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
TFM_Log.severe(ex);
|
FLog.severe(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,29 +1,33 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Bridge;
|
package me.totalfreedom.totalfreedommod.bridge;
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_ProtectedArea;
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
|
||||||
import me.StevenLawson.worldedit.LimitChangedEvent;
|
import me.StevenLawson.worldedit.LimitChangedEvent;
|
||||||
import me.StevenLawson.worldedit.SelectionChangedEvent;
|
import me.StevenLawson.worldedit.SelectionChangedEvent;
|
||||||
|
import net.pravian.aero.component.PluginListener;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
|
|
||||||
public class TFM_WorldEditListener implements Listener
|
public class WorldEditListener extends PluginListener<TotalFreedomMod>
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public WorldEditListener(TotalFreedomMod plugin)
|
||||||
|
{
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onSelectionChange(final SelectionChangedEvent event)
|
public void onSelectionChange(final SelectionChangedEvent event)
|
||||||
{
|
{
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
|
|
||||||
if (TFM_AdminList.isSuperAdmin(player))
|
if (plugin.al.isAdmin(player))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TFM_ProtectedArea.isInProtectedArea(
|
if (plugin.pa.isInProtectedArea(
|
||||||
event.getMinVector(),
|
event.getMinVector(),
|
||||||
event.getMaxVector(),
|
event.getMaxVector(),
|
||||||
event.getWorld().getName()))
|
event.getWorld().getName()))
|
||||||
@ -39,7 +43,7 @@ public class TFM_WorldEditListener implements Listener
|
|||||||
{
|
{
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
|
|
||||||
if (TFM_AdminList.isSuperAdmin(player))
|
if (plugin.al.isAdmin(player))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -53,7 +57,7 @@ public class TFM_WorldEditListener implements Listener
|
|||||||
if (event.getLimit() < 0 || event.getLimit() > 10000)
|
if (event.getLimit() < 0 || event.getLimit() > 10000)
|
||||||
{
|
{
|
||||||
player.setOp(false);
|
player.setOp(false);
|
||||||
TFM_Util.bcastMsg(event.getPlayer().getName() + " tried to set their WorldEdit limit to " + event.getLimit() + " and has been de-opped", ChatColor.RED);
|
FUtil.bcastMsg(event.getPlayer().getName() + " tried to set their WorldEdit limit to " + event.getLimit() + " and has been de-opped", ChatColor.RED);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
player.sendMessage(ChatColor.RED + "You cannot set your limit higher than 10000 or to -1!");
|
player.sendMessage(ChatColor.RED + "You cannot set your limit higher than 10000 or to -1!");
|
||||||
}
|
}
|
@ -0,0 +1,192 @@
|
|||||||
|
package me.totalfreedom.totalfreedommod.commandblocker;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||||
|
import net.pravian.aero.command.CommandReflection;
|
||||||
|
import net.pravian.aero.component.service.AbstractService;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandMap;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
public class CommandBlocker extends AbstractService<TotalFreedomMod>
|
||||||
|
{
|
||||||
|
public static Pattern NUMBER_FLAG_PATTERN = Pattern.compile("(:([0-9]){5,})");
|
||||||
|
//
|
||||||
|
private final Map<String, CommandBlockerEntry> entryList = Maps.newHashMap();
|
||||||
|
|
||||||
|
public CommandBlocker(TotalFreedomMod plugin)
|
||||||
|
{
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStart()
|
||||||
|
{
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStop()
|
||||||
|
{
|
||||||
|
entryList.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void load()
|
||||||
|
{
|
||||||
|
entryList.clear();
|
||||||
|
|
||||||
|
final CommandMap commandMap = CommandReflection.getCommandMap();
|
||||||
|
if (commandMap == null)
|
||||||
|
{
|
||||||
|
FLog.severe("Error loading commandMap.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
List<String> blockedCommands = (List<String>) ConfigEntry.BLOCKED_COMMANDS.getList();
|
||||||
|
for (String rawEntry : blockedCommands)
|
||||||
|
{
|
||||||
|
final String[] parts = rawEntry.split(":");
|
||||||
|
if (parts.length < 3 || parts.length > 4)
|
||||||
|
{
|
||||||
|
FLog.warning("Invalid command blocker entry: " + rawEntry);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
final CommandBlockerRank rank = CommandBlockerRank.fromToken(parts[0]);
|
||||||
|
final CommandBlockerAction action = CommandBlockerAction.fromToken(parts[1]);
|
||||||
|
String commandName = parts[2].toLowerCase().substring(1);
|
||||||
|
final String message = (parts.length > 3 ? parts[3] : null);
|
||||||
|
|
||||||
|
if (rank == null || action == null || commandName == null || commandName.isEmpty())
|
||||||
|
{
|
||||||
|
FLog.warning("Invalid command blocker entry: " + rawEntry);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String[] commandParts = commandName.split(" ");
|
||||||
|
String subCommand = null;
|
||||||
|
if (commandParts.length > 1)
|
||||||
|
{
|
||||||
|
commandName = commandParts[0];
|
||||||
|
subCommand = StringUtils.join(commandParts, " ", 1, commandParts.length).trim().toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
final Command command = commandMap.getCommand(commandName);
|
||||||
|
|
||||||
|
// Obtain command from alias
|
||||||
|
if (command == null)
|
||||||
|
{
|
||||||
|
FLog.info("Blocking unknown command: /" + commandName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
commandName = command.getName().toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entryList.containsKey(commandName))
|
||||||
|
{
|
||||||
|
FLog.warning("Not blocking: /" + commandName + " - Duplicate entry exists!");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
final CommandBlockerEntry blockedCommandEntry = new CommandBlockerEntry(rank, action, commandName, subCommand, message);
|
||||||
|
entryList.put(blockedCommandEntry.getCommand(), blockedCommandEntry);
|
||||||
|
|
||||||
|
if (command != null)
|
||||||
|
{
|
||||||
|
for (String alias : command.getAliases())
|
||||||
|
{
|
||||||
|
entryList.put(alias.toLowerCase(), blockedCommandEntry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FLog.info("Loaded " + blockedCommands.size() + " blocked commands");
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCommandBlocked(String command, CommandSender sender)
|
||||||
|
{
|
||||||
|
return isCommandBlocked(command, sender, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCommandBlocked(String command, CommandSender sender, boolean doAction)
|
||||||
|
{
|
||||||
|
if (command == null || command.isEmpty())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Format
|
||||||
|
command = command.toLowerCase().trim();
|
||||||
|
command = command.startsWith("/") ? command.substring(1) : command;
|
||||||
|
|
||||||
|
// Check for plugin specific commands
|
||||||
|
final String[] commandParts = command.split(" ");
|
||||||
|
if (commandParts[0].contains(":"))
|
||||||
|
{
|
||||||
|
if (doAction)
|
||||||
|
{
|
||||||
|
FUtil.playerMsg(sender, "Plugin specific commands are disabled.");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String part : commandParts)
|
||||||
|
{
|
||||||
|
Matcher matcher = NUMBER_FLAG_PATTERN.matcher(part);
|
||||||
|
if (!matcher.matches())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (doAction)
|
||||||
|
{
|
||||||
|
FUtil.playerMsg(sender, "That command contains an illegal number: " + matcher.group(1));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtain sub command, if it exists
|
||||||
|
String subCommand = null;
|
||||||
|
if (commandParts.length > 1)
|
||||||
|
{
|
||||||
|
subCommand = StringUtils.join(commandParts, " ", 1, commandParts.length).toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtain entry
|
||||||
|
final CommandBlockerEntry entry = entryList.get(commandParts[0]);
|
||||||
|
if (entry == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate sub command
|
||||||
|
if (entry.getSubCommand() != null)
|
||||||
|
{
|
||||||
|
if (subCommand == null || !subCommand.startsWith(entry.getSubCommand()))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entry.getRank().hasPermission(sender))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (doAction)
|
||||||
|
{
|
||||||
|
entry.doActions(sender);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
package me.totalfreedom.totalfreedommod.commandblocker;
|
||||||
|
|
||||||
|
public enum CommandBlockerAction
|
||||||
|
{
|
||||||
|
BLOCK("b"),
|
||||||
|
BLOCK_AND_EJECT("a"),
|
||||||
|
BLOCK_UNKNOWN("u");
|
||||||
|
private final String token;
|
||||||
|
|
||||||
|
private CommandBlockerAction(String token)
|
||||||
|
{
|
||||||
|
this.token = token;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getToken()
|
||||||
|
{
|
||||||
|
return this.token;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CommandBlockerAction fromToken(String token)
|
||||||
|
{
|
||||||
|
for (CommandBlockerAction action : CommandBlockerAction.values())
|
||||||
|
{
|
||||||
|
if (action.getToken().equalsIgnoreCase(token))
|
||||||
|
{
|
||||||
|
return action;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
package me.totalfreedom.totalfreedommod.commandblocker;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class CommandBlockerEntry
|
||||||
|
{
|
||||||
|
@Getter
|
||||||
|
private final CommandBlockerRank rank;
|
||||||
|
@Getter
|
||||||
|
private final CommandBlockerAction action;
|
||||||
|
@Getter
|
||||||
|
private final String command;
|
||||||
|
@Getter
|
||||||
|
private final String subCommand;
|
||||||
|
@Getter
|
||||||
|
private final String message;
|
||||||
|
|
||||||
|
public CommandBlockerEntry(CommandBlockerRank rank, CommandBlockerAction action, String command, String message)
|
||||||
|
{
|
||||||
|
this(rank, action, command, null, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandBlockerEntry(CommandBlockerRank rank, CommandBlockerAction action, String command, String subCommand, String message)
|
||||||
|
{
|
||||||
|
this.rank = rank;
|
||||||
|
this.action = action;
|
||||||
|
this.command = command;
|
||||||
|
this.subCommand = (subCommand == null ? null : subCommand.toLowerCase().trim());
|
||||||
|
this.message = (message == null || message.equals("_") ? "That command is blocked." : message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void doActions(CommandSender sender)
|
||||||
|
{
|
||||||
|
if (action == CommandBlockerAction.BLOCK_AND_EJECT && sender instanceof Player)
|
||||||
|
{
|
||||||
|
FUtil.autoEject((Player) sender, "You used a prohibited command: " + command);
|
||||||
|
FUtil.bcastMsg(sender.getName() + " was automatically kicked for using harmful commands.", ChatColor.RED);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (action == CommandBlockerAction.BLOCK_UNKNOWN)
|
||||||
|
{
|
||||||
|
FUtil.playerMsg(sender, "Unknown command. Type \"help\" for help.", ChatColor.RESET);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
FUtil.playerMsg(sender, FUtil.colorize(message));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,72 @@
|
|||||||
|
package me.totalfreedom.totalfreedommod.commandblocker;
|
||||||
|
|
||||||
|
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||||
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public enum CommandBlockerRank
|
||||||
|
{
|
||||||
|
ANYONE("a"),
|
||||||
|
OP("o"),
|
||||||
|
SUPER("s"),
|
||||||
|
TELNET("t"),
|
||||||
|
SENIOR("c"),
|
||||||
|
NOBODY("n");
|
||||||
|
//
|
||||||
|
private final String token;
|
||||||
|
|
||||||
|
private CommandBlockerRank(String token)
|
||||||
|
{
|
||||||
|
this.token = token;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getToken()
|
||||||
|
{
|
||||||
|
return this.token;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasPermission(CommandSender sender)
|
||||||
|
{
|
||||||
|
return fromSender(sender).ordinal() >= ordinal();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CommandBlockerRank fromSender(CommandSender sender)
|
||||||
|
{
|
||||||
|
if (!(sender instanceof Player))
|
||||||
|
{
|
||||||
|
return TELNET;
|
||||||
|
}
|
||||||
|
|
||||||
|
Admin admin = TotalFreedomMod.plugin.al.getAdmin(sender);
|
||||||
|
if (admin != null)
|
||||||
|
{
|
||||||
|
if (admin.getRank() == PlayerRank.SENIOR_ADMIN)
|
||||||
|
{
|
||||||
|
return SENIOR;
|
||||||
|
}
|
||||||
|
return SUPER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sender.isOp())
|
||||||
|
{
|
||||||
|
return OP;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ANYONE;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CommandBlockerRank fromToken(String token)
|
||||||
|
{
|
||||||
|
for (CommandBlockerRank rank : CommandBlockerRank.values())
|
||||||
|
{
|
||||||
|
if (rank.getToken().equalsIgnoreCase(token))
|
||||||
|
{
|
||||||
|
return rank;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ANYONE;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||||
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||||
|
import net.pravian.aero.command.handler.SimpleCommandHandler;
|
||||||
|
import net.pravian.aero.component.service.AbstractService;
|
||||||
|
|
||||||
|
public class CommandLoader extends AbstractService<TotalFreedomMod>
|
||||||
|
{
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private final SimpleCommandHandler<TotalFreedomMod> handler;
|
||||||
|
|
||||||
|
public CommandLoader(TotalFreedomMod plugin)
|
||||||
|
{
|
||||||
|
super(plugin);
|
||||||
|
|
||||||
|
handler = new SimpleCommandHandler<TotalFreedomMod>(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStart()
|
||||||
|
{
|
||||||
|
handler.clearCommands();
|
||||||
|
handler.setExecutorFactory(new FreedomCommandExecutor.TFM_CommandExecutorFactory());
|
||||||
|
handler.setCommandClassPrefix("Command_");
|
||||||
|
handler.loadFrom(FreedomCommand.class.getPackage());
|
||||||
|
handler.registerAll();
|
||||||
|
|
||||||
|
FLog.info("Loaded" + handler.getExecutors().size() + " commands");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStop()
|
||||||
|
{
|
||||||
|
handler.clearCommands();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
@ -1,12 +1,13 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public @interface CommandPermissions
|
public @interface CommandPermissions
|
||||||
{
|
{
|
||||||
AdminLevel level();
|
PlayerRank level();
|
||||||
|
|
||||||
SourceType source();
|
SourceType source();
|
||||||
|
|
@ -1,15 +1,15 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_CONSOLE, blockHostConsole = true)
|
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.ONLY_CONSOLE, blockHostConsole = true)
|
||||||
@CommandParameters(description = "Close server to non-superadmins.", usage = "/<command> [on | off]")
|
@CommandParameters(description = "Close server to non-superadmins.", usage = "/<command> [on | off]")
|
||||||
public class Command_adminmode extends TFM_Command
|
public class Command_adminmode extends FreedomCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
@ -21,17 +21,17 @@ public class Command_adminmode extends TFM_Command
|
|||||||
|
|
||||||
if (args[0].equalsIgnoreCase("off"))
|
if (args[0].equalsIgnoreCase("off"))
|
||||||
{
|
{
|
||||||
TFM_ConfigEntry.ADMIN_ONLY_MODE.setBoolean(false);
|
ConfigEntry.ADMIN_ONLY_MODE.setBoolean(false);
|
||||||
TFM_Util.adminAction(sender.getName(), "Opening the server to all players.", true);
|
FUtil.adminAction(sender.getName(), "Opening the server to all players.", true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (args[0].equalsIgnoreCase("on"))
|
else if (args[0].equalsIgnoreCase("on"))
|
||||||
{
|
{
|
||||||
TFM_ConfigEntry.ADMIN_ONLY_MODE.setBoolean(true);
|
ConfigEntry.ADMIN_ONLY_MODE.setBoolean(true);
|
||||||
TFM_Util.adminAction(sender.getName(), "Closing the server to non-superadmins.", true);
|
FUtil.adminAction(sender.getName(), "Closing the server to non-superadmins.", true);
|
||||||
for (Player player : server.getOnlinePlayers())
|
for (Player player : server.getOnlinePlayers())
|
||||||
{
|
{
|
||||||
if (!TFM_AdminList.isSuperAdmin(player))
|
if (!isAdmin(player))
|
||||||
{
|
{
|
||||||
player.kickPlayer("Server is now closed to non-superadmins.");
|
player.kickPlayer("Server is now closed to non-superadmins.");
|
||||||
}
|
}
|
@ -1,19 +1,22 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
import me.StevenLawson.TotalFreedomMod.World.TFM_AdminWorld;
|
import me.totalfreedom.totalfreedommod.world.WorldTime;
|
||||||
|
import me.totalfreedom.totalfreedommod.world.WorldWeather;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.OP, source = SourceType.BOTH)
|
@CommandPermissions(level = PlayerRank.OP, source = SourceType.BOTH)
|
||||||
@CommandParameters(description = "Go to the AdminWorld.", usage = "/<command> [guest < list | purge | add <player> | remove <player> > | time <morning | noon | evening | night> | weather <off | on | storm>]")
|
@CommandParameters(description = "Go to the AdminWorld.", usage = "/<command> [guest < list | purge | add <player> | remove <player> > | time <morning | noon | evening | night> | weather <off | on | storm>]")
|
||||||
public class Command_adminworld extends TFM_Command
|
public class Command_adminworld extends FreedomCommand
|
||||||
{
|
{
|
||||||
|
|
||||||
private enum CommandMode
|
private enum CommandMode
|
||||||
{
|
{
|
||||||
|
|
||||||
TELEPORT, GUEST, TIME, WEATHER;
|
TELEPORT, GUEST, TIME, WEATHER;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +64,7 @@ public class Command_adminworld extends TFM_Command
|
|||||||
World adminWorld = null;
|
World adminWorld = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
adminWorld = TFM_AdminWorld.getInstance().getWorld();
|
adminWorld = plugin.wm.adminworld.getWorld();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -74,10 +77,10 @@ public class Command_adminworld extends TFM_Command
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (TFM_AdminWorld.getInstance().canAccessWorld(sender_p))
|
if (plugin.wm.adminworld.canAccessWorld(sender_p))
|
||||||
{
|
{
|
||||||
playerMsg("Going to the AdminWorld.");
|
playerMsg("Going to the AdminWorld.");
|
||||||
TFM_AdminWorld.getInstance().sendToWorld(sender_p);
|
plugin.wm.adminworld.sendToWorld(sender_p);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -93,13 +96,13 @@ public class Command_adminworld extends TFM_Command
|
|||||||
{
|
{
|
||||||
if ("list".equalsIgnoreCase(args[1]))
|
if ("list".equalsIgnoreCase(args[1]))
|
||||||
{
|
{
|
||||||
playerMsg("AdminWorld guest list: " + TFM_AdminWorld.getInstance().guestListToString());
|
playerMsg("AdminWorld guest list: " + plugin.wm.adminworld.guestListToString());
|
||||||
}
|
}
|
||||||
else if ("purge".equalsIgnoreCase(args[1]))
|
else if ("purge".equalsIgnoreCase(args[1]))
|
||||||
{
|
{
|
||||||
assertCommandPerms(sender, sender_p);
|
assertCommandPerms(sender, sender_p);
|
||||||
TFM_AdminWorld.getInstance().purgeGuestList();
|
plugin.wm.adminworld.purgeGuestList();
|
||||||
TFM_Util.adminAction(sender.getName(), "AdminWorld guest list purged.", false);
|
FUtil.adminAction(sender.getName(), "AdminWorld guest list purged.", false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -116,13 +119,13 @@ public class Command_adminworld extends TFM_Command
|
|||||||
|
|
||||||
if (player == null)
|
if (player == null)
|
||||||
{
|
{
|
||||||
sender.sendMessage(TFM_Command.PLAYER_NOT_FOUND);
|
sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TFM_AdminWorld.getInstance().addGuest(player, sender_p))
|
if (plugin.wm.adminworld.addGuest(player, sender_p))
|
||||||
{
|
{
|
||||||
TFM_Util.adminAction(sender.getName(), "AdminWorld guest added: " + player.getName(), false);
|
FUtil.adminAction(sender.getName(), "AdminWorld guest added: " + player.getName(), false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -131,10 +134,10 @@ public class Command_adminworld extends TFM_Command
|
|||||||
}
|
}
|
||||||
else if ("remove".equals(args[1]))
|
else if ("remove".equals(args[1]))
|
||||||
{
|
{
|
||||||
final Player player = TFM_AdminWorld.getInstance().removeGuest(args[2]);
|
final Player player = plugin.wm.adminworld.removeGuest(args[2]);
|
||||||
if (player != null)
|
if (player != null)
|
||||||
{
|
{
|
||||||
TFM_Util.adminAction(sender.getName(), "AdminWorld guest removed: " + player.getName(), false);
|
FUtil.adminAction(sender.getName(), "AdminWorld guest removed: " + player.getName(), false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -155,10 +158,10 @@ public class Command_adminworld extends TFM_Command
|
|||||||
|
|
||||||
if (args.length == 2)
|
if (args.length == 2)
|
||||||
{
|
{
|
||||||
TFM_AdminWorld.TimeOfDay timeOfDay = TFM_AdminWorld.TimeOfDay.getByAlias(args[1]);
|
WorldTime timeOfDay = WorldTime.getByAlias(args[1]);
|
||||||
if (timeOfDay != null)
|
if (timeOfDay != null)
|
||||||
{
|
{
|
||||||
TFM_AdminWorld.getInstance().setTimeOfDay(timeOfDay);
|
plugin.wm.adminworld.setTimeOfDay(timeOfDay);
|
||||||
playerMsg("AdminWorld time set to: " + timeOfDay.name());
|
playerMsg("AdminWorld time set to: " + timeOfDay.name());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -179,10 +182,10 @@ public class Command_adminworld extends TFM_Command
|
|||||||
|
|
||||||
if (args.length == 2)
|
if (args.length == 2)
|
||||||
{
|
{
|
||||||
TFM_AdminWorld.WeatherMode weatherMode = TFM_AdminWorld.WeatherMode.getByAlias(args[1]);
|
WorldWeather weatherMode = WorldWeather.getByAlias(args[1]);
|
||||||
if (weatherMode != null)
|
if (weatherMode != null)
|
||||||
{
|
{
|
||||||
TFM_AdminWorld.getInstance().setWeatherMode(weatherMode);
|
plugin.wm.adminworld.setWeatherMode(weatherMode);
|
||||||
playerMsg("AdminWorld weather set to: " + weatherMode.name());
|
playerMsg("AdminWorld weather set to: " + weatherMode.name());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -211,16 +214,18 @@ public class Command_adminworld extends TFM_Command
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Redo this properly
|
||||||
private void assertCommandPerms(CommandSender sender, Player sender_p) throws PermissionDeniedException
|
private void assertCommandPerms(CommandSender sender, Player sender_p) throws PermissionDeniedException
|
||||||
{
|
{
|
||||||
if (!(sender instanceof Player) || sender_p == null || !TFM_AdminList.isSuperAdmin(sender))
|
if (!(sender instanceof Player) || sender_p == null || !isAdmin(sender))
|
||||||
{
|
{
|
||||||
throw new PermissionDeniedException(TFM_Command.MSG_NO_PERMS);
|
throw new PermissionDeniedException(FreedomCommand.MSG_NO_PERMS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class PermissionDeniedException extends Exception
|
private class PermissionDeniedException extends Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private PermissionDeniedException(String string)
|
private PermissionDeniedException(String string)
|
||||||
@ -228,4 +233,5 @@ public class Command_adminworld extends TFM_Command
|
|||||||
super(string);
|
super(string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,15 +1,15 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData;
|
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
|
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH)
|
||||||
@CommandParameters(description = "Block all commands for a specific player.", usage = "/<command> <purge | <partialname>>", aliases = "blockcommands,blockcommand")
|
@CommandParameters(description = "Block all commands for a specific player.", usage = "/<command> <purge | <partialname>>", aliases = "blockcommands,blockcommand")
|
||||||
public class Command_blockcmd extends TFM_Command
|
public class Command_blockcmd extends FreedomCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
@ -21,11 +21,11 @@ public class Command_blockcmd extends TFM_Command
|
|||||||
|
|
||||||
if (args[0].equalsIgnoreCase("purge"))
|
if (args[0].equalsIgnoreCase("purge"))
|
||||||
{
|
{
|
||||||
TFM_Util.adminAction(sender.getName(), "Unblocking commands for all players", true);
|
FUtil.adminAction(sender.getName(), "Unblocking commands for all players", true);
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
for (Player player : server.getOnlinePlayers())
|
for (Player player : server.getOnlinePlayers())
|
||||||
{
|
{
|
||||||
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
|
FPlayer playerdata = plugin.pl.getPlayer(player);
|
||||||
if (playerdata.allCommandsBlocked())
|
if (playerdata.allCommandsBlocked())
|
||||||
{
|
{
|
||||||
counter += 1;
|
counter += 1;
|
||||||
@ -40,21 +40,21 @@ public class Command_blockcmd extends TFM_Command
|
|||||||
|
|
||||||
if (player == null)
|
if (player == null)
|
||||||
{
|
{
|
||||||
playerMsg(TFM_Command.PLAYER_NOT_FOUND);
|
playerMsg(FreedomCommand.PLAYER_NOT_FOUND);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TFM_AdminList.isSuperAdmin(player))
|
if (isAdmin(sender))
|
||||||
{
|
{
|
||||||
playerMsg(player.getName() + " is a Superadmin, and cannot have their commands blocked.");
|
playerMsg(player.getName() + " is a Superadmin, and cannot have their commands blocked.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
|
FPlayer playerdata = plugin.pl.getPlayer(player);
|
||||||
|
|
||||||
playerdata.setCommandsBlocked(!playerdata.allCommandsBlocked());
|
playerdata.setCommandsBlocked(!playerdata.allCommandsBlocked());
|
||||||
|
|
||||||
TFM_Util.adminAction(sender.getName(), (playerdata.allCommandsBlocked() ? "B" : "Unb") + "locking all commands for " + player.getName(), true);
|
FUtil.adminAction(sender.getName(), (playerdata.allCommandsBlocked() ? "B" : "Unb") + "locking all commands for " + player.getName(), true);
|
||||||
playerMsg((playerdata.allCommandsBlocked() ? "B" : "Unb") + "locked all commands.");
|
playerMsg((playerdata.allCommandsBlocked() ? "B" : "Unb") + "locked all commands.");
|
||||||
|
|
||||||
return true;
|
return true;
|
@ -1,7 +1,8 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData;
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -9,9 +10,9 @@ import org.bukkit.command.Command;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
|
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH)
|
||||||
@CommandParameters(description = "Place a cage around someone.", usage = "/<command> <purge | off | <partialname> [outermaterial] [innermaterial]>")
|
@CommandParameters(description = "Place a cage around someone.", usage = "/<command> <purge | off | <partialname> [outermaterial] [innermaterial]>")
|
||||||
public class Command_cage extends TFM_Command
|
public class Command_cage extends FreedomCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
@ -23,8 +24,8 @@ public class Command_cage extends TFM_Command
|
|||||||
|
|
||||||
if ("off".equals(args[0]) && sender instanceof Player)
|
if ("off".equals(args[0]) && sender instanceof Player)
|
||||||
{
|
{
|
||||||
TFM_Util.adminAction(sender.getName(), "Uncaging " + sender.getName(), true);
|
FUtil.adminAction(sender.getName(), "Uncaging " + sender.getName(), true);
|
||||||
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(sender_p);
|
FPlayer playerdata = plugin.pl.getPlayer(sender_p);
|
||||||
|
|
||||||
playerdata.setCaged(false);
|
playerdata.setCaged(false);
|
||||||
playerdata.regenerateHistory();
|
playerdata.regenerateHistory();
|
||||||
@ -34,11 +35,11 @@ public class Command_cage extends TFM_Command
|
|||||||
}
|
}
|
||||||
else if ("purge".equals(args[0]))
|
else if ("purge".equals(args[0]))
|
||||||
{
|
{
|
||||||
TFM_Util.adminAction(sender.getName(), "Uncaging all players", true);
|
FUtil.adminAction(sender.getName(), "Uncaging all players", true);
|
||||||
|
|
||||||
for (Player player : server.getOnlinePlayers())
|
for (Player player : server.getOnlinePlayers())
|
||||||
{
|
{
|
||||||
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
|
FPlayer playerdata = plugin.pl.getPlayer(player);
|
||||||
playerdata.setCaged(false);
|
playerdata.setCaged(false);
|
||||||
playerdata.regenerateHistory();
|
playerdata.regenerateHistory();
|
||||||
playerdata.clearHistory();
|
playerdata.clearHistory();
|
||||||
@ -51,11 +52,11 @@ public class Command_cage extends TFM_Command
|
|||||||
|
|
||||||
if (player == null)
|
if (player == null)
|
||||||
{
|
{
|
||||||
sender.sendMessage(TFM_Command.PLAYER_NOT_FOUND);
|
sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
|
FPlayer playerdata = plugin.pl.getPlayer(player);
|
||||||
|
|
||||||
Material outerMaterial = Material.GLASS;
|
Material outerMaterial = Material.GLASS;
|
||||||
Material innerMaterial = Material.AIR;
|
Material innerMaterial = Material.AIR;
|
||||||
@ -64,7 +65,7 @@ public class Command_cage extends TFM_Command
|
|||||||
{
|
{
|
||||||
if ("off".equals(args[1]))
|
if ("off".equals(args[1]))
|
||||||
{
|
{
|
||||||
TFM_Util.adminAction(sender.getName(), "Uncaging " + player.getName(), true);
|
FUtil.adminAction(sender.getName(), "Uncaging " + player.getName(), true);
|
||||||
|
|
||||||
playerdata.setCaged(false);
|
playerdata.setCaged(false);
|
||||||
playerdata.regenerateHistory();
|
playerdata.regenerateHistory();
|
||||||
@ -101,19 +102,19 @@ public class Command_cage extends TFM_Command
|
|||||||
playerdata.setCaged(true, targetPos, outerMaterial, innerMaterial);
|
playerdata.setCaged(true, targetPos, outerMaterial, innerMaterial);
|
||||||
playerdata.regenerateHistory();
|
playerdata.regenerateHistory();
|
||||||
playerdata.clearHistory();
|
playerdata.clearHistory();
|
||||||
TFM_Util.buildHistory(targetPos, 2, playerdata);
|
FUtil.buildHistory(targetPos, 2, playerdata);
|
||||||
TFM_Util.generateHollowCube(targetPos, 2, outerMaterial);
|
FUtil.generateHollowCube(targetPos, 2, outerMaterial);
|
||||||
TFM_Util.generateCube(targetPos, 1, innerMaterial);
|
FUtil.generateCube(targetPos, 1, innerMaterial);
|
||||||
|
|
||||||
player.setGameMode(GameMode.SURVIVAL);
|
player.setGameMode(GameMode.SURVIVAL);
|
||||||
|
|
||||||
if (outerMaterial != Material.SKULL)
|
if (outerMaterial != Material.SKULL)
|
||||||
{
|
{
|
||||||
TFM_Util.adminAction(sender.getName(), "Caging " + player.getName(), true);
|
FUtil.adminAction(sender.getName(), "Caging " + player.getName(), true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TFM_Util.adminAction(sender.getName(), "Caging " + player.getName() + " in PURE_DARTH", true);
|
FUtil.adminAction(sender.getName(), "Caging " + player.getName() + " in PURE_DARTH", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
@ -1,7 +1,8 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
import org.bukkit.Achievement;
|
import org.bukkit.Achievement;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -11,9 +12,9 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
|
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH)
|
||||||
@CommandParameters(description = "For the people that are still alive.", usage = "/<command>")
|
@CommandParameters(description = "For the people that are still alive.", usage = "/<command>")
|
||||||
public class Command_cake extends TFM_Command
|
public class Command_cake extends FreedomCommand
|
||||||
{
|
{
|
||||||
public static final String CAKE_LYRICS = "But there's no sense crying over every mistake. You just keep on trying till you run out of cake.";
|
public static final String CAKE_LYRICS = "But there's no sense crying over every mistake. You just keep on trying till you run out of cake.";
|
||||||
private final Random random = new Random();
|
private final Random random = new Random();
|
||||||
@ -45,7 +46,7 @@ public class Command_cake extends TFM_Command
|
|||||||
player.awardAchievement(Achievement.BAKE_CAKE);
|
player.awardAchievement(Achievement.BAKE_CAKE);
|
||||||
}
|
}
|
||||||
|
|
||||||
TFM_Util.bcastMsg(output.toString());
|
FUtil.bcastMsg(output.toString());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
@ -1,15 +1,16 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Minecart;
|
import org.bukkit.entity.Minecart;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.BOTH)
|
@CommandPermissions(level = PlayerRank.NON_OP, source = SourceType.BOTH)
|
||||||
@CommandParameters(description = "Sit in nearest minecart. If target is in a minecart already, they will disembark.", usage = "/<command> [partialname]")
|
@CommandParameters(description = "Sit in nearest minecart. If target is in a minecart already, they will disembark.", usage = "/<command> [partialname]")
|
||||||
public class Command_cartsit extends TFM_Command
|
public class Command_cartsit extends FreedomCommand
|
||||||
{
|
{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
{
|
{
|
||||||
@ -22,7 +23,7 @@ public class Command_cartsit extends TFM_Command
|
|||||||
|
|
||||||
if (targetPlayer == null)
|
if (targetPlayer == null)
|
||||||
{
|
{
|
||||||
sender.sendMessage(TFM_Command.PLAYER_NOT_FOUND);
|
sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -35,7 +36,7 @@ public class Command_cartsit extends TFM_Command
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (targetPlayer != sender_p && !TFM_AdminList.isSuperAdmin(sender))
|
else if (targetPlayer != sender_p && !isAdmin(sender))
|
||||||
{
|
{
|
||||||
sender.sendMessage("Only superadmins can select another player as a /cartsit target.");
|
sender.sendMessage("Only superadmins can select another player as a /cartsit target.");
|
||||||
return true;
|
return true;
|
@ -1,11 +1,12 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_CommandBlocker;
|
import me.totalfreedom.totalfreedommod.commandblocker.CommandBlocker;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_DepreciationAggregator;
|
import me.totalfreedom.totalfreedommod.util.DepreciationAggregator;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Log;
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -16,9 +17,9 @@ import org.bukkit.command.Command;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.BOTH)
|
@CommandPermissions(level = PlayerRank.NON_OP, source = SourceType.BOTH)
|
||||||
@CommandParameters(description = "No Description Yet", usage = "/<command>")
|
@CommandParameters(description = "No Description Yet", usage = "/<command>")
|
||||||
public class Command_cbtool extends TFM_Command
|
public class Command_cbtool extends FreedomCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
@ -30,7 +31,7 @@ public class Command_cbtool extends TFM_Command
|
|||||||
|
|
||||||
if ("targetblock".equalsIgnoreCase(args[0]) && sender instanceof Player)
|
if ("targetblock".equalsIgnoreCase(args[0]) && sender instanceof Player)
|
||||||
{
|
{
|
||||||
Block targetBlock = TFM_DepreciationAggregator.getTargetBlock(sender_p, null, 100);
|
Block targetBlock = DepreciationAggregator.getTargetBlock(sender_p, null, 100);
|
||||||
playerMsg("Your target block: " + targetBlock.getLocation().toString());
|
playerMsg("Your target block: " + targetBlock.getLocation().toString());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -46,7 +47,7 @@ public class Command_cbtool extends TFM_Command
|
|||||||
}
|
}
|
||||||
matcher.appendTail(generatedCommand);
|
matcher.appendTail(generatedCommand);
|
||||||
|
|
||||||
if (TFM_CommandBlocker.isCommandBlocked(generatedCommand.toString(), sender, false))
|
if (plugin.cb.isCommandBlocked(generatedCommand.toString(), sender, false))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -58,7 +59,7 @@ public class Command_cbtool extends TFM_Command
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
TFM_Log.severe(ex);
|
FLog.severe(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
@ -1,5 +1,6 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -12,9 +13,9 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.BOTH)
|
@CommandPermissions(level = PlayerRank.NON_OP, source = SourceType.BOTH)
|
||||||
@CommandParameters(description = "Show all commands for all server plugins.", usage = "/<command>")
|
@CommandParameters(description = "Show all commands for all server plugins.", usage = "/<command>")
|
||||||
public class Command_cmdlist extends TFM_Command
|
public class Command_cmdlist extends FreedomCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
@ -1,19 +1,20 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData;
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
|
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_IN_GAME)
|
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.ONLY_IN_GAME)
|
||||||
@CommandParameters(description = "Spy on commands", usage = "/<command>", aliases = "commandspy")
|
@CommandParameters(description = "Spy on commands", usage = "/<command>", aliases = "commandspy")
|
||||||
public class Command_cmdspy extends TFM_Command
|
public class Command_cmdspy extends FreedomCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
{
|
{
|
||||||
|
|
||||||
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(sender_p);
|
FPlayer playerdata = plugin.pl.getPlayer(sender_p);
|
||||||
playerdata.setCommandSpy(!playerdata.cmdspyEnabled());
|
playerdata.setCommandSpy(!playerdata.cmdspyEnabled());
|
||||||
playerMsg("CommandSpy " + (playerdata.cmdspyEnabled() ? "enabled." : "disabled."));
|
playerMsg("CommandSpy " + (playerdata.cmdspyEnabled() ? "enabled." : "disabled."));
|
||||||
|
|
@ -1,18 +1,19 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import me.StevenLawson.TotalFreedomMod.Bridge.TFM_EssentialsBridge;
|
import me.totalfreedom.totalfreedommod.bridge.EssentialsBridge;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.OP, source = SourceType.ONLY_IN_GAME)
|
@CommandPermissions(level = PlayerRank.OP, source = SourceType.ONLY_IN_GAME)
|
||||||
@CommandParameters(description = "Essentials Interface Command - Color your current nickname.", usage = "/<command> <color>")
|
@CommandParameters(description = "Essentials Interface Command - Color your current nickname.", usage = "/<command> <color>")
|
||||||
public class Command_colorme extends TFM_Command
|
public class Command_colorme extends FreedomCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
@ -24,13 +25,13 @@ public class Command_colorme extends TFM_Command
|
|||||||
|
|
||||||
if ("list".equalsIgnoreCase(args[0]))
|
if ("list".equalsIgnoreCase(args[0]))
|
||||||
{
|
{
|
||||||
playerMsg("Colors: " + StringUtils.join(TFM_Util.CHAT_COLOR_NAMES.keySet(), ", "));
|
playerMsg("Colors: " + StringUtils.join(FUtil.CHAT_COLOR_NAMES.keySet(), ", "));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String needle = args[0].trim().toLowerCase();
|
final String needle = args[0].trim().toLowerCase();
|
||||||
ChatColor color = null;
|
ChatColor color = null;
|
||||||
final Iterator<Map.Entry<String, ChatColor>> it = TFM_Util.CHAT_COLOR_NAMES.entrySet().iterator();
|
final Iterator<Map.Entry<String, ChatColor>> it = FUtil.CHAT_COLOR_NAMES.entrySet().iterator();
|
||||||
while (it.hasNext())
|
while (it.hasNext())
|
||||||
{
|
{
|
||||||
final Map.Entry<String, ChatColor> entry = it.next();
|
final Map.Entry<String, ChatColor> entry = it.next();
|
||||||
@ -49,7 +50,7 @@ public class Command_colorme extends TFM_Command
|
|||||||
|
|
||||||
final String newNick = color + ChatColor.stripColor(sender_p.getDisplayName()).trim() + ChatColor.WHITE;
|
final String newNick = color + ChatColor.stripColor(sender_p.getDisplayName()).trim() + ChatColor.WHITE;
|
||||||
|
|
||||||
TFM_EssentialsBridge.setNickname(sender.getName(), newNick);
|
plugin.esb.setNickname(sender.getName(), newNick);
|
||||||
|
|
||||||
playerMsg("Your nickname is now: " + newNick);
|
playerMsg("Your nickname is now: " + newNick);
|
||||||
|
|
@ -1,15 +1,15 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.OP, source = SourceType.BOTH)
|
@CommandPermissions(level = PlayerRank.OP, source = SourceType.BOTH)
|
||||||
@CommandParameters(description = "Quickly change your own gamemode to creative, or define someone's username to change theirs.", usage = "/<command> [partialname]", aliases = "gmc")
|
@CommandParameters(description = "Quickly change your own gamemode to creative, or define someone's username to change theirs.", usage = "/<command> [partialname]", aliases = "gmc")
|
||||||
public class Command_creative extends TFM_Command
|
public class Command_creative extends FreedomCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
@ -32,9 +32,9 @@ public class Command_creative extends TFM_Command
|
|||||||
{
|
{
|
||||||
if (args[0].equalsIgnoreCase("-a"))
|
if (args[0].equalsIgnoreCase("-a"))
|
||||||
{
|
{
|
||||||
if (!TFM_AdminList.isSuperAdmin(sender))
|
if (!isAdmin(sender))
|
||||||
{
|
{
|
||||||
sender.sendMessage(TFM_Command.MSG_NO_PERMS);
|
sender.sendMessage(FreedomCommand.MSG_NO_PERMS);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,11 +43,11 @@ public class Command_creative extends TFM_Command
|
|||||||
targetPlayer.setGameMode(GameMode.CREATIVE);
|
targetPlayer.setGameMode(GameMode.CREATIVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
TFM_Util.adminAction(sender.getName(), "Changing everyone's gamemode to creative", false);
|
FUtil.adminAction(sender.getName(), "Changing everyone's gamemode to creative", false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(senderIsConsole || TFM_AdminList.isSuperAdmin(sender)))
|
if (!(senderIsConsole || isAdmin(sender)))
|
||||||
{
|
{
|
||||||
playerMsg("Only superadmins can change other user's gamemode.");
|
playerMsg("Only superadmins can change other user's gamemode.");
|
||||||
return true;
|
return true;
|
||||||
@ -57,7 +57,7 @@ public class Command_creative extends TFM_Command
|
|||||||
|
|
||||||
if (player == null)
|
if (player == null)
|
||||||
{
|
{
|
||||||
sender.sendMessage(TFM_Command.PLAYER_NOT_FOUND);
|
sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -1,21 +1,22 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_CONSOLE)
|
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.ONLY_CONSOLE)
|
||||||
@CommandParameters(description = "Telnet command - Send a chat message with chat formatting over telnet.", usage = "/<command> <message...>")
|
@CommandParameters(description = "Telnet command - Send a chat message with chat formatting over telnet.", usage = "/<command> <message...>")
|
||||||
public class Command_csay extends TFM_Command
|
public class Command_csay extends FreedomCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
{
|
{
|
||||||
if (args.length > 0)
|
if (args.length > 0)
|
||||||
{
|
{
|
||||||
TFM_Util.bcastMsg(String.format("§7[CONSOLE]§f<§c%s§f> %s", sender.getName(), StringUtils.join(args, " ")));
|
FUtil.bcastMsg(String.format("§7[CONSOLE]§f<§c%s§f> %s", sender.getName(), StringUtils.join(args, " ")));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
@ -8,9 +9,9 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.BOTH, blockHostConsole = true)
|
@CommandPermissions(level = PlayerRank.SENIOR_ADMIN, source = SourceType.BOTH, blockHostConsole = true)
|
||||||
@CommandParameters(description = "Make some noise.", usage = "/<command>")
|
@CommandParameters(description = "Make some noise.", usage = "/<command>")
|
||||||
public class Command_deafen extends TFM_Command
|
public class Command_deafen extends FreedomCommand
|
||||||
{
|
{
|
||||||
private static final Random random = new Random();
|
private static final Random random = new Random();
|
||||||
public static final double STEPS = 10.0;
|
public static final double STEPS = 10.0;
|
@ -1,5 +1,6 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
@ -7,9 +8,9 @@ import org.bukkit.command.Command;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE)
|
@CommandPermissions(level = PlayerRank.SENIOR_ADMIN, source = SourceType.ONLY_CONSOLE)
|
||||||
@CommandParameters(description = "For developers only - debug things via reflection.", usage = "/<command>")
|
@CommandParameters(description = "For developers only - debug things via reflection.", usage = "/<command>")
|
||||||
public class Command_debug extends TFM_Command
|
public class Command_debug extends FreedomCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
@ -1,23 +1,24 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.Bridge.TFM_EssentialsBridge;
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.totalfreedom.totalfreedommod.bridge.EssentialsBridge;
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
|
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH)
|
||||||
@CommandParameters(description = "Essentials Interface Command - Remove the nickname of all players on the server.", usage = "/<command>")
|
@CommandParameters(description = "Essentials Interface Command - Remove the nickname of all players on the server.", usage = "/<command>")
|
||||||
public class Command_denick extends TFM_Command
|
public class Command_denick extends FreedomCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
{
|
{
|
||||||
TFM_Util.adminAction(sender.getName(), "Removing all nicknames", false);
|
FUtil.adminAction(sender.getName(), "Removing all nicknames", false);
|
||||||
|
|
||||||
for (Player player : server.getOnlinePlayers())
|
for (Player player : server.getOnlinePlayers())
|
||||||
{
|
{
|
||||||
TFM_EssentialsBridge.setNickname(player.getName(), null);
|
plugin.esb.setNickname(player.getName(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
@ -1,15 +1,16 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_DepreciationAggregator;
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.totalfreedom.totalfreedommod.util.DepreciationAggregator;
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
|
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH)
|
||||||
@CommandParameters(description = "Deop a player.", usage = "/<command> <playername>")
|
@CommandParameters(description = "Deop a player.", usage = "/<command> <playername>")
|
||||||
public class Command_deop extends TFM_Command
|
public class Command_deop extends FreedomCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
@ -32,10 +33,10 @@ public class Command_deop extends TFM_Command
|
|||||||
// if the player is not online
|
// if the player is not online
|
||||||
if (player == null)
|
if (player == null)
|
||||||
{
|
{
|
||||||
player = TFM_DepreciationAggregator.getOfflinePlayer(server, args[0]);
|
player = DepreciationAggregator.getOfflinePlayer(server, args[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
TFM_Util.adminAction(sender.getName(), "De-opping " + player.getName(), false);
|
FUtil.adminAction(sender.getName(), "De-opping " + player.getName(), false);
|
||||||
|
|
||||||
player.setOp(false);
|
player.setOp(false);
|
||||||
|
|
@ -1,23 +1,24 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH, blockHostConsole = true)
|
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH, blockHostConsole = true)
|
||||||
@CommandParameters(description = "Deop everyone on the server.", usage = "/<command>")
|
@CommandParameters(description = "Deop everyone on the server.", usage = "/<command>")
|
||||||
public class Command_deopall extends TFM_Command
|
public class Command_deopall extends FreedomCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
{
|
{
|
||||||
TFM_Util.adminAction(sender.getName(), "De-opping all players on the server", true);
|
FUtil.adminAction(sender.getName(), "De-opping all players on the server", true);
|
||||||
|
|
||||||
for (Player player : server.getOnlinePlayers())
|
for (Player player : server.getOnlinePlayers())
|
||||||
{
|
{
|
||||||
player.setOp(false);
|
player.setOp(false);
|
||||||
player.sendMessage(TFM_Command.YOU_ARE_NOT_OP);
|
player.sendMessage(FreedomCommand.YOU_ARE_NOT_OP);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
@ -1,9 +1,10 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_DepreciationAggregator;
|
import me.totalfreedom.totalfreedommod.util.DepreciationAggregator;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -15,9 +16,9 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.OP, source = SourceType.ONLY_IN_GAME)
|
@CommandPermissions(level = PlayerRank.OP, source = SourceType.ONLY_IN_GAME)
|
||||||
@CommandParameters(description = "Fill nearby dispensers with a set of items of your choice.", usage = "/<command> <radius> <comma,separated,items>")
|
@CommandParameters(description = "Fill nearby dispensers with a set of items of your choice.", usage = "/<command> <radius> <comma,separated,items>")
|
||||||
public class Command_dispfill extends TFM_Command
|
public class Command_dispfill extends FreedomCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
@ -46,7 +47,7 @@ public class Command_dispfill extends TFM_Command
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
material = TFM_DepreciationAggregator.getMaterial(Integer.parseInt(searchItem));
|
material = DepreciationAggregator.getMaterial(Integer.parseInt(searchItem));
|
||||||
}
|
}
|
||||||
catch (NumberFormatException ex)
|
catch (NumberFormatException ex)
|
||||||
{
|
{
|
||||||
@ -79,7 +80,7 @@ public class Command_dispfill extends TFM_Command
|
|||||||
{
|
{
|
||||||
if (targetBlock.getType().equals(Material.DISPENSER))
|
if (targetBlock.getType().equals(Material.DISPENSER))
|
||||||
{
|
{
|
||||||
sender.sendMessage("Filling dispenser @ " + TFM_Util.formatLocation(targetBlock.getLocation()));
|
sender.sendMessage("Filling dispenser @ " + FUtil.formatLocation(targetBlock.getLocation()));
|
||||||
setDispenserContents(targetBlock, itemsArray);
|
setDispenserContents(targetBlock, itemsArray);
|
||||||
affected++;
|
affected++;
|
||||||
}
|
}
|
@ -1,10 +1,10 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Ban;
|
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_BanManager;
|
import me.totalfreedom.totalfreedommod.banning.FBan;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_PlayerList;
|
import me.totalfreedom.totalfreedommod.player.PlayerList;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
@ -13,9 +13,9 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE, blockHostConsole = true)
|
@CommandPermissions(level = PlayerRank.SENIOR_ADMIN, source = SourceType.ONLY_CONSOLE, blockHostConsole = true)
|
||||||
@CommandParameters(description = "For the bad Superadmins", usage = "/<command> <playername>")
|
@CommandParameters(description = "For the bad Superadmins", usage = "/<command> <playername>")
|
||||||
public class Command_doom extends TFM_Command
|
public class Command_doom extends FreedomCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public boolean run(final CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(final CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
@ -29,48 +29,49 @@ public class Command_doom extends TFM_Command
|
|||||||
|
|
||||||
if (player == null)
|
if (player == null)
|
||||||
{
|
{
|
||||||
sender.sendMessage(TFM_Command.PLAYER_NOT_FOUND);
|
sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TFM_Util.adminAction(sender.getName(), "Casting oblivion over " + player.getName(), true);
|
FUtil.adminAction(sender.getName(), "Casting oblivion over " + player.getName(), true);
|
||||||
TFM_Util.bcastMsg(player.getName() + " will be completely obliviated!", ChatColor.RED);
|
FUtil.bcastMsg(player.getName() + " will be completely obliviated!", ChatColor.RED);
|
||||||
|
|
||||||
final String ip = player.getAddress().getAddress().getHostAddress().trim();
|
final String ip = player.getAddress().getAddress().getHostAddress().trim();
|
||||||
|
|
||||||
// remove from superadmin
|
// Remove from superadmin
|
||||||
if (TFM_AdminList.isSuperAdmin(player))
|
Admin admin = getAdmin(player);
|
||||||
|
if (admin != null)
|
||||||
{
|
{
|
||||||
TFM_Util.adminAction(sender.getName(), "Removing " + player.getName() + " from the superadmin list.", true);
|
FUtil.adminAction(sender.getName(), "Removing " + player.getName() + " from the superadmin list", true);
|
||||||
TFM_AdminList.removeSuperadmin(player);
|
plugin.al.removeAdmin(admin);
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove from whitelist
|
// Remove from whitelist
|
||||||
player.setWhitelisted(false);
|
player.setWhitelisted(false);
|
||||||
|
|
||||||
// deop
|
// Deop
|
||||||
player.setOp(false);
|
player.setOp(false);
|
||||||
|
|
||||||
// ban IPs
|
// Ban player
|
||||||
for (String playerIp : TFM_PlayerList.getEntry(player).getIps())
|
FBan ban = FBan.forPlayer(player, sender);
|
||||||
|
ban.setReason("&cFUCKOFF");
|
||||||
|
for (String playerIp : plugin.pl.getData(player).getIps())
|
||||||
{
|
{
|
||||||
TFM_BanManager.addIpBan(new TFM_Ban(playerIp, player.getName()));
|
ban.addIp(playerIp);
|
||||||
}
|
}
|
||||||
|
plugin.bm.addBan(ban);
|
||||||
|
|
||||||
// ban uuid
|
// Set gamemode to survival
|
||||||
TFM_BanManager.addUuidBan(player);
|
|
||||||
|
|
||||||
// set gamemode to survival
|
|
||||||
player.setGameMode(GameMode.SURVIVAL);
|
player.setGameMode(GameMode.SURVIVAL);
|
||||||
|
|
||||||
// clear inventory
|
// Clear inventory
|
||||||
player.closeInventory();
|
player.closeInventory();
|
||||||
player.getInventory().clear();
|
player.getInventory().clear();
|
||||||
|
|
||||||
// ignite player
|
// Ignite player
|
||||||
player.setFireTicks(10000);
|
player.setFireTicks(10000);
|
||||||
|
|
||||||
// generate explosion
|
// Generate explosion
|
||||||
player.getWorld().createExplosion(player.getLocation(), 4F);
|
player.getWorld().createExplosion(player.getLocation(), 4F);
|
||||||
|
|
||||||
// Shoot the player in the sky
|
// Shoot the player in the sky
|
||||||
@ -95,7 +96,7 @@ public class Command_doom extends TFM_Command
|
|||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
// message
|
// message
|
||||||
TFM_Util.adminAction(sender.getName(), "Banning " + player.getName() + ", IP: " + ip, true);
|
FUtil.adminAction(sender.getName(), "Banning " + player.getName() + ", IP: " + ip, true);
|
||||||
|
|
||||||
// generate explosion
|
// generate explosion
|
||||||
player.getWorld().createExplosion(player.getLocation(), 4F);
|
player.getWorld().createExplosion(player.getLocation(), 4F);
|
@ -1,15 +1,16 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Log;
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.OP, source = SourceType.ONLY_IN_GAME)
|
@CommandPermissions(level = PlayerRank.OP, source = SourceType.ONLY_IN_GAME)
|
||||||
@CommandParameters(description = "Enchant items.", usage = "/<command> <list | addall | reset | add <name> | remove <name>>")
|
@CommandParameters(description = "Enchant items.", usage = "/<command> <list | addall | reset | add <name> | remove <name>>")
|
||||||
public class Command_enchant extends TFM_Command
|
public class Command_enchant extends FreedomCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
@ -63,7 +64,7 @@ public class Command_enchant extends TFM_Command
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
TFM_Log.info("Error using " + ench.getName() + " on " + itemInHand.getType().name() + " held by " + sender_p.getName() + ".");
|
FLog.info("Error using " + ench.getName() + " on " + itemInHand.getType().name() + " held by " + sender_p.getName() + ".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,18 +1,19 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.ONLY_IN_GAME)
|
@CommandPermissions(level = PlayerRank.NON_OP, source = SourceType.ONLY_IN_GAME)
|
||||||
@CommandParameters(description = "Goto the ender / \"The End\".", usage = "/<command>")
|
@CommandParameters(description = "Goto the ender / \"The End\".", usage = "/<command>")
|
||||||
public class Command_ender extends TFM_Command
|
public class Command_ender extends FreedomCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
{
|
{
|
||||||
TFM_Util.gotoWorld(sender_p, server.getWorlds().get(0).getName() + "_the_end");
|
FUtil.gotoWorld(sender_p, server.getWorlds().get(0).getName() + "_the_end");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,8 +1,9 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
@ -10,9 +11,9 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_IN_GAME)
|
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.ONLY_IN_GAME)
|
||||||
@CommandParameters(description = "Push people away from you.", usage = "/<command> [radius] [strength]")
|
@CommandParameters(description = "Push people away from you.", usage = "/<command> [radius] [strength]")
|
||||||
public class Command_expel extends TFM_Command
|
public class Command_expel extends FreedomCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
@ -68,7 +69,7 @@ public class Command_expel extends TFM_Command
|
|||||||
if (inRange)
|
if (inRange)
|
||||||
{
|
{
|
||||||
player.getWorld().createExplosion(targetPos, 0.0f, false);
|
player.getWorld().createExplosion(targetPos, 0.0f, false);
|
||||||
TFM_Util.setFlying(player, false);
|
FUtil.setFlying(player, false);
|
||||||
player.setVelocity(targetPosVec.subtract(senderPos).normalize().multiply(strength));
|
player.setVelocity(targetPosVec.subtract(senderPos).normalize().multiply(strength));
|
||||||
pushedPlayers.add(player.getName());
|
pushedPlayers.add(player.getName());
|
||||||
}
|
}
|
@ -1,14 +1,14 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_PlayerList;
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
|
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH)
|
||||||
@CommandParameters(description = "Shows all IPs registered to a player", usage = "/<command> <player>")
|
@CommandParameters(description = "Shows all IPs registered to a player", usage = "/<command> <player>")
|
||||||
public class Command_findip extends TFM_Command
|
public class Command_findip extends FreedomCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
@ -23,11 +23,11 @@ public class Command_findip extends TFM_Command
|
|||||||
if (player == null)
|
if (player == null)
|
||||||
{
|
{
|
||||||
|
|
||||||
playerMsg(TFM_Command.PLAYER_NOT_FOUND);
|
playerMsg(FreedomCommand.PLAYER_NOT_FOUND);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
playerMsg("Player IPs: " + StringUtils.join(TFM_PlayerList.getEntry(player).getIps(), ", "));
|
playerMsg("Player IPs: " + StringUtils.join(plugin.pl.getData(player).getIps(), ", "));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
@ -1,21 +1,21 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||||
import me.StevenLawson.TotalFreedomMod.World.TFM_Flatlands;
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.ONLY_IN_GAME)
|
@CommandPermissions(level = PlayerRank.NON_OP, source = SourceType.ONLY_IN_GAME)
|
||||||
@CommandParameters(description = "Goto the flatlands.", usage = "/<command>")
|
@CommandParameters(description = "Goto the flatlands.", usage = "/<command>")
|
||||||
public class Command_flatlands extends TFM_Command
|
public class Command_flatlands extends FreedomCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
{
|
{
|
||||||
if (TFM_ConfigEntry.FLATLANDS_GENERATE.getBoolean())
|
if (ConfigEntry.FLATLANDS_GENERATE.getBoolean())
|
||||||
{
|
{
|
||||||
TFM_Flatlands.getInstance().sendToWorld(sender_p);
|
plugin.wm.flatlands.sendToWorld(sender_p);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
@ -1,17 +1,18 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData;
|
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
|
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH)
|
||||||
@CommandParameters(description = "Freeze players (toggles on and off).", usage = "/<command> [target | purge]")
|
@CommandParameters(description = "Freeze players (toggles on and off).", usage = "/<command> [target | purge]")
|
||||||
public class Command_fr extends TFM_Command
|
public class Command_fr extends FreedomCommand
|
||||||
{
|
{
|
||||||
private static boolean allFrozen = false;
|
private static boolean allFrozen = false;
|
||||||
|
|
||||||
@ -24,14 +25,14 @@ public class Command_fr extends TFM_Command
|
|||||||
|
|
||||||
if (allFrozen)
|
if (allFrozen)
|
||||||
{
|
{
|
||||||
TFM_Util.adminAction(sender.getName(), "Freezing all players", false);
|
FUtil.adminAction(sender.getName(), "Freezing all players", false);
|
||||||
|
|
||||||
setAllFrozen(true);
|
setAllFrozen(true);
|
||||||
playerMsg("Players are now frozen.");
|
playerMsg("Players are now frozen.");
|
||||||
|
|
||||||
for (Player player : Bukkit.getOnlinePlayers())
|
for (Player player : Bukkit.getOnlinePlayers())
|
||||||
{
|
{
|
||||||
if (!TFM_AdminList.isSuperAdmin(player))
|
if (!isAdmin(player))
|
||||||
{
|
{
|
||||||
playerMsg(player, "You have been frozen due to rulebreakers, you will be unfrozen soon.", ChatColor.RED);
|
playerMsg(player, "You have been frozen due to rulebreakers, you will be unfrozen soon.", ChatColor.RED);
|
||||||
}
|
}
|
||||||
@ -39,7 +40,7 @@ public class Command_fr extends TFM_Command
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TFM_Util.adminAction(sender.getName(), "Unfreezing all players", false);
|
FUtil.adminAction(sender.getName(), "Unfreezing all players", false);
|
||||||
setAllFrozen(false);
|
setAllFrozen(false);
|
||||||
playerMsg("Players are now free to move.");
|
playerMsg("Players are now free to move.");
|
||||||
}
|
}
|
||||||
@ -49,7 +50,7 @@ public class Command_fr extends TFM_Command
|
|||||||
if (args[0].toLowerCase().equals("purge"))
|
if (args[0].toLowerCase().equals("purge"))
|
||||||
{
|
{
|
||||||
setAllFrozen(false);
|
setAllFrozen(false);
|
||||||
TFM_Util.adminAction(sender.getName(), "Unfreezing all players", false);
|
FUtil.adminAction(sender.getName(), "Unfreezing all players", false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -57,11 +58,11 @@ public class Command_fr extends TFM_Command
|
|||||||
|
|
||||||
if (player == null)
|
if (player == null)
|
||||||
{
|
{
|
||||||
playerMsg(TFM_Command.PLAYER_NOT_FOUND, ChatColor.RED);
|
playerMsg(FreedomCommand.PLAYER_NOT_FOUND, ChatColor.RED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
|
final FPlayer playerdata = plugin.pl.getPlayer(player);
|
||||||
playerdata.setFrozen(!playerdata.isFrozen());
|
playerdata.setFrozen(!playerdata.isFrozen());
|
||||||
|
|
||||||
playerMsg(player.getName() + " has been " + (playerdata.isFrozen() ? "frozen" : "unfrozen") + ".");
|
playerMsg(player.getName() + " has been " + (playerdata.isFrozen() ? "frozen" : "unfrozen") + ".");
|
||||||
@ -75,7 +76,7 @@ public class Command_fr extends TFM_Command
|
|||||||
public static void setAllFrozen(boolean freeze)
|
public static void setAllFrozen(boolean freeze)
|
||||||
{
|
{
|
||||||
allFrozen = freeze;
|
allFrozen = freeze;
|
||||||
for (TFM_PlayerData data : TFM_PlayerData.PLAYER_DATA.values())
|
for (FPlayer data : TotalFreedomMod.plugin.pl.playerMap.values())
|
||||||
{
|
{
|
||||||
data.setFrozen(freeze);
|
data.setFrozen(freeze);
|
||||||
}
|
}
|
@ -1,14 +1,16 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_IN_GAME)
|
@CommandPermissions(level = PlayerRank.SENIOR_ADMIN, source = SourceType.ONLY_IN_GAME)
|
||||||
@CommandParameters(description = "You'll never even see it coming.", usage = "/<command>")
|
@CommandParameters(description = "You'll never even see it coming.", usage = "/<command>")
|
||||||
public class Command_fuckoff extends TFM_Command
|
public class Command_fuckoff extends FreedomCommand
|
||||||
{
|
{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
{
|
{
|
@ -1,20 +1,22 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_BanManager;
|
import java.util.UUID;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData;
|
import me.totalfreedom.totalfreedommod.banning.FBan;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_UuidManager;
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH, blockHostConsole = true)
|
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH, blockHostConsole = true)
|
||||||
@CommandParameters(
|
@CommandParameters(
|
||||||
description = "Use admin commands on someone by hash. Use mode 'list' to get a player's hash. Other modes are kick, nameban, ipban, ban, op, deop, ci, fr, smite.",
|
description = "Use admin commands on someone by hash. Use mode 'list' to get a player's hash. Other modes are kick, nameban, ipban, ban, op, deop, ci, fr, smite.",
|
||||||
usage = "/<command> [list | [<kick | nameban | ipban | ban | op | deop | ci | fr | smite> <targethash>] ]")
|
usage = "/<command> [list | [<kick | nameban | ipban | ban | op | deop | ci | fr | smite> <targethash>] ]")
|
||||||
public class Command_gadmin extends TFM_Command
|
public class Command_gadmin extends FreedomCommand
|
||||||
{
|
{
|
||||||
private enum GadminMode
|
private enum GadminMode
|
||||||
{
|
{
|
||||||
@ -53,6 +55,11 @@ public class Command_gadmin extends TFM_Command
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getPlayerHash(Player player)
|
||||||
|
{
|
||||||
|
return UUID.nameUUIDFromBytes(player.getName().toLowerCase().getBytes(StandardCharsets.UTF_8)).toString().substring(0, 4);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
{
|
{
|
||||||
@ -76,11 +83,10 @@ public class Command_gadmin extends TFM_Command
|
|||||||
while (it.hasNext())
|
while (it.hasNext())
|
||||||
{
|
{
|
||||||
final Player player = it.next();
|
final Player player = it.next();
|
||||||
final String hash = TFM_UuidManager.getUniqueId(player).toString().substring(0, 4);
|
|
||||||
sender.sendMessage(ChatColor.GRAY + String.format("[ %s ] : [ %s ] - %s",
|
sender.sendMessage(ChatColor.GRAY + String.format("[ %s ] : [ %s ] - %s",
|
||||||
player.getName(),
|
player.getName(),
|
||||||
ChatColor.stripColor(player.getDisplayName()),
|
ChatColor.stripColor(player.getDisplayName()),
|
||||||
hash));
|
getPlayerHash(player)));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -94,7 +100,7 @@ public class Command_gadmin extends TFM_Command
|
|||||||
while (it.hasNext() && target == null)
|
while (it.hasNext() && target == null)
|
||||||
{
|
{
|
||||||
final Player player = it.next();
|
final Player player = it.next();
|
||||||
final String hash = TFM_UuidManager.getUniqueId(player).toString().substring(0, 4);
|
final String hash = getPlayerHash(player);
|
||||||
|
|
||||||
if (hash.equalsIgnoreCase(args[1]))
|
if (hash.equalsIgnoreCase(args[1]))
|
||||||
{
|
{
|
||||||
@ -112,16 +118,15 @@ public class Command_gadmin extends TFM_Command
|
|||||||
{
|
{
|
||||||
case KICK:
|
case KICK:
|
||||||
{
|
{
|
||||||
TFM_Util.adminAction(sender.getName(), String.format("Kicking: %s.", target.getName()), false);
|
FUtil.adminAction(sender.getName(), String.format("Kicking: %s.", target.getName()), false);
|
||||||
target.kickPlayer("Kicked by Administrator");
|
target.kickPlayer("Kicked by Administrator");
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case NAMEBAN:
|
case NAMEBAN:
|
||||||
{
|
{
|
||||||
TFM_BanManager.addUuidBan(target);
|
FUtil.adminAction(sender.getName(), String.format("Banning Name: %s.", target.getName()), true);
|
||||||
|
plugin.bm.addBan(FBan.forPlayerName(target, sender, null, null));
|
||||||
TFM_Util.adminAction(sender.getName(), String.format("Banning Name: %s.", target.getName()), true);
|
|
||||||
target.kickPlayer("Username banned by Administrator.");
|
target.kickPlayer("Username banned by Administrator.");
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -134,8 +139,8 @@ public class Command_gadmin extends TFM_Command
|
|||||||
{
|
{
|
||||||
ip = String.format("%s.%s.*.*", ip_parts[0], ip_parts[1]);
|
ip = String.format("%s.%s.*.*", ip_parts[0], ip_parts[1]);
|
||||||
}
|
}
|
||||||
TFM_Util.adminAction(sender.getName(), String.format("Banning IP: %s.", ip), true);
|
FUtil.adminAction(sender.getName(), String.format("Banning IP: %s.", ip), true);
|
||||||
TFM_BanManager.addIpBan(target);
|
plugin.bm.addBan(FBan.forPlayerIp(ip, sender, null, null));
|
||||||
|
|
||||||
target.kickPlayer("IP address banned by Administrator.");
|
target.kickPlayer("IP address banned by Administrator.");
|
||||||
|
|
||||||
@ -149,10 +154,9 @@ public class Command_gadmin extends TFM_Command
|
|||||||
{
|
{
|
||||||
ip = String.format("%s.%s.*.*", ip_parts[0], ip_parts[1]);
|
ip = String.format("%s.%s.*.*", ip_parts[0], ip_parts[1]);
|
||||||
}
|
}
|
||||||
TFM_Util.adminAction(sender.getName(), String.format("Banning Name: %s, IP: %s.", target.getName(), ip), true);
|
FUtil.adminAction(sender.getName(), String.format("Banning Name: %s, IP: %s.", target.getName(), ip), true);
|
||||||
|
|
||||||
TFM_BanManager.addUuidBan(target);
|
plugin.bm.addBan(FBan.forPlayer(target, sender));
|
||||||
TFM_BanManager.addIpBan(target);
|
|
||||||
|
|
||||||
target.kickPlayer("IP and username banned by Administrator.");
|
target.kickPlayer("IP and username banned by Administrator.");
|
||||||
|
|
||||||
@ -160,17 +164,17 @@ public class Command_gadmin extends TFM_Command
|
|||||||
}
|
}
|
||||||
case OP:
|
case OP:
|
||||||
{
|
{
|
||||||
TFM_Util.adminAction(sender.getName(), String.format("Opping %s.", target.getName()), false);
|
FUtil.adminAction(sender.getName(), String.format("Opping %s.", target.getName()), false);
|
||||||
target.setOp(false);
|
target.setOp(false);
|
||||||
target.sendMessage(TFM_Command.YOU_ARE_OP);
|
target.sendMessage(FreedomCommand.YOU_ARE_OP);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DEOP:
|
case DEOP:
|
||||||
{
|
{
|
||||||
TFM_Util.adminAction(sender.getName(), String.format("Deopping %s.", target.getName()), false);
|
FUtil.adminAction(sender.getName(), String.format("Deopping %s.", target.getName()), false);
|
||||||
target.setOp(false);
|
target.setOp(false);
|
||||||
target.sendMessage(TFM_Command.YOU_ARE_NOT_OP);
|
target.sendMessage(FreedomCommand.YOU_ARE_NOT_OP);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -182,7 +186,7 @@ public class Command_gadmin extends TFM_Command
|
|||||||
}
|
}
|
||||||
case FR:
|
case FR:
|
||||||
{
|
{
|
||||||
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(target);
|
FPlayer playerdata = plugin.pl.getPlayer(target);
|
||||||
playerdata.setFrozen(!playerdata.isFrozen());
|
playerdata.setFrozen(!playerdata.isFrozen());
|
||||||
|
|
||||||
playerMsg(target.getName() + " has been " + (playerdata.isFrozen() ? "frozen" : "unfrozen") + ".");
|
playerMsg(target.getName() + " has been " + (playerdata.isFrozen() ? "frozen" : "unfrozen") + ".");
|
@ -1,14 +1,15 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_CommandBlocker;
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
|
import me.totalfreedom.totalfreedommod.commandblocker.CommandBlocker;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH, blockHostConsole = true)
|
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH, blockHostConsole = true)
|
||||||
@CommandParameters(description = "Send a command as someone else.", usage = "/<command> <fromname> <outcommand>")
|
@CommandParameters(description = "Send a command as someone else.", usage = "/<command> <fromname> <outcommand>")
|
||||||
public class Command_gcmd extends TFM_Command
|
public class Command_gcmd extends FreedomCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
@ -22,13 +23,13 @@ public class Command_gcmd extends TFM_Command
|
|||||||
|
|
||||||
if (player == null)
|
if (player == null)
|
||||||
{
|
{
|
||||||
sender.sendMessage(TFM_Command.PLAYER_NOT_FOUND);
|
sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String outCommand = StringUtils.join(args, " ", 1, args.length);
|
final String outCommand = StringUtils.join(args, " ", 1, args.length);
|
||||||
|
|
||||||
if (TFM_CommandBlocker.isCommandBlocked(outCommand, sender))
|
if (plugin.cb.isCommandBlocked(outCommand, sender))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
@ -1,23 +1,20 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
|
import me.totalfreedom.totalfreedommod.banning.FBan;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Ban;
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_BanManager;
|
import me.totalfreedom.totalfreedommod.player.PlayerData;
|
||||||
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Player;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_PlayerList;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_UuidManager;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH, blockHostConsole = true)
|
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH, blockHostConsole = true)
|
||||||
@CommandParameters(description = "Bans or unbans any player, even those who are not logged in anymore.", usage = "/<command> <purge | <ban | unban> <username>>")
|
@CommandParameters(description = "Bans or unbans any player, even those who are not logged in anymore.", usage = "/<command> <purge | <ban | unban> <username>>")
|
||||||
public class Command_glist extends TFM_Command
|
public class Command_glist extends FreedomCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
@ -31,10 +28,10 @@ public class Command_glist extends TFM_Command
|
|||||||
{
|
{
|
||||||
if (args[0].equalsIgnoreCase("purge"))
|
if (args[0].equalsIgnoreCase("purge"))
|
||||||
{
|
{
|
||||||
if (TFM_AdminList.isSeniorAdmin(sender))
|
if (getAdmin(sender).getRank() == PlayerRank.SENIOR_ADMIN)
|
||||||
{
|
{
|
||||||
TFM_PlayerList.purgeAll();
|
plugin.pl.purgeAllData();
|
||||||
playerMsg("Purged playerbase");
|
playerMsg("Purged playerbase.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -56,7 +53,7 @@ public class Command_glist extends TFM_Command
|
|||||||
|
|
||||||
if (player == null)
|
if (player == null)
|
||||||
{
|
{
|
||||||
final TFM_Player entry = TFM_PlayerList.getEntry(TFM_UuidManager.getUniqueId(args[1]));
|
final PlayerData entry = plugin.pl.getData(args[1]);
|
||||||
|
|
||||||
if (entry == null)
|
if (entry == null)
|
||||||
{
|
{
|
||||||
@ -64,47 +61,46 @@ public class Command_glist extends TFM_Command
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
username = entry.getLastLoginName();
|
username = entry.getUsername();
|
||||||
ips.addAll(entry.getIps());
|
ips.addAll(entry.getIps());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
username = player.getName();
|
username = player.getName();
|
||||||
final TFM_Player entry = TFM_PlayerList.getEntry(TFM_UuidManager.getUniqueId(player));
|
final PlayerData entry = plugin.pl.getData(player);
|
||||||
ips.addAll(entry.getIps());
|
ips.addAll(entry.getIps());
|
||||||
}
|
}
|
||||||
|
|
||||||
String mode = args[0].toLowerCase();
|
String mode = args[0].toLowerCase();
|
||||||
if (mode.equalsIgnoreCase("ban"))
|
if (mode.equalsIgnoreCase("ban"))
|
||||||
{
|
{
|
||||||
TFM_Util.adminAction(sender.getName(), "Banning " + username + " and IPs: " + StringUtils.join(ips, ", "), true);
|
FUtil.adminAction(sender.getName(), "Banning " + username + " and IPs: " + StringUtils.join(ips, ", "), true);
|
||||||
|
|
||||||
final Player target = getPlayer(username, true);
|
final Player target = getPlayer(username, true);
|
||||||
if (target != null)
|
if (target != null)
|
||||||
{
|
{
|
||||||
TFM_BanManager.addUuidBan(new TFM_Ban(TFM_UuidManager.getUniqueId(target), target.getName()));
|
target.kickPlayer("You have been banned by " + sender.getName() + "\n If you think you have been banned wrongly, appeal here: " + ConfigEntry.SERVER_BAN_URL.getString());
|
||||||
target.kickPlayer("You have been banned by " + sender.getName() + "\n If you think you have been banned wrongly, appeal here: " + TFM_ConfigEntry.SERVER_BAN_URL.getString());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
TFM_BanManager.addUuidBan(new TFM_Ban(TFM_UuidManager.getUniqueId(username), username));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FBan ban = FBan.forPlayerFuzzy(player, sender, null, null);
|
||||||
for (String ip : ips)
|
for (String ip : ips)
|
||||||
{
|
{
|
||||||
TFM_BanManager.addIpBan(new TFM_Ban(ip, username));
|
ban.addIp(ip);
|
||||||
TFM_BanManager.addIpBan(new TFM_Ban(TFM_Util.getFuzzyIp(ip), username));
|
ban.addIp(FUtil.getFuzzyIp(ip));
|
||||||
}
|
}
|
||||||
|
plugin.bm.addBan(ban);
|
||||||
}
|
}
|
||||||
else if (mode.equalsIgnoreCase("unban"))
|
else if (mode.equalsIgnoreCase("unban"))
|
||||||
{
|
{
|
||||||
TFM_Util.adminAction(sender.getName(), "Unbanning " + username + " and IPs: " + StringUtils.join(ips, ", "), true);
|
FUtil.adminAction(sender.getName(), "Unbanning " + username + " and IPs: " + StringUtils.join(ips, ", "), true);
|
||||||
TFM_BanManager.unbanUuid(TFM_UuidManager.getUniqueId(username));
|
plugin.bm.removeBan(plugin.bm.getByUsername(username));
|
||||||
for (String ip : ips)
|
for (String ip : ips)
|
||||||
{
|
{
|
||||||
|
FBan ban = plugin.bm.getByIp(ip);
|
||||||
TFM_BanManager.unbanIp(ip);
|
if (ban != null)
|
||||||
TFM_BanManager.unbanIp(TFM_Util.getFuzzyIp(ip));
|
{
|
||||||
|
plugin.bm.removeBan(ban);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
@ -1,11 +1,9 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.Bridge.TFM_WorldEditBridge;
|
import me.totalfreedom.totalfreedommod.banning.FBan;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Ban;
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_BanManager;
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager;
|
import net.pravian.aero.util.Ips;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_UuidManager;
|
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@ -15,9 +13,9 @@ import org.bukkit.command.Command;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH, blockHostConsole = true)
|
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH, blockHostConsole = true)
|
||||||
@CommandParameters(description = "Makes someone GTFO (deop and ip ban by username).", usage = "/<command> <partialname>")
|
@CommandParameters(description = "Makes someone GTFO (deop and ip ban by username).", usage = "/<command> <partialname>")
|
||||||
public class Command_gtfo extends TFM_Command
|
public class Command_gtfo extends FreedomCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
@ -31,7 +29,7 @@ public class Command_gtfo extends TFM_Command
|
|||||||
|
|
||||||
if (player == null)
|
if (player == null)
|
||||||
{
|
{
|
||||||
playerMsg(TFM_Command.PLAYER_NOT_FOUND, ChatColor.RED);
|
playerMsg(FreedomCommand.PLAYER_NOT_FOUND, ChatColor.RED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,30 +39,30 @@ public class Command_gtfo extends TFM_Command
|
|||||||
reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length), " ");
|
reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length), " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
TFM_Util.bcastMsg(player.getName() + " has been a VERY naughty, naughty boy.", ChatColor.RED);
|
FUtil.bcastMsg(player.getName() + " has been a VERY naughty, naughty boy.", ChatColor.RED);
|
||||||
|
|
||||||
// Undo WorldEdits:
|
// Undo WorldEdits
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
TFM_WorldEditBridge.undo(player, 15);
|
plugin.web.undo(player, 15);
|
||||||
}
|
}
|
||||||
catch (NoClassDefFoundError ex)
|
catch (NoClassDefFoundError ex)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// rollback
|
// Rollback
|
||||||
TFM_RollbackManager.rollback(player.getName());
|
plugin.rb.rollback(player.getName());
|
||||||
|
|
||||||
// deop
|
// Deop
|
||||||
player.setOp(false);
|
player.setOp(false);
|
||||||
|
|
||||||
// set gamemode to survival:
|
// Gamemode suvival
|
||||||
player.setGameMode(GameMode.SURVIVAL);
|
player.setGameMode(GameMode.SURVIVAL);
|
||||||
|
|
||||||
// clear inventory:
|
// Clear inventory
|
||||||
player.getInventory().clear();
|
player.getInventory().clear();
|
||||||
|
|
||||||
// strike with lightning effect:
|
// Strike with lightning
|
||||||
final Location targetPos = player.getLocation();
|
final Location targetPos = player.getLocation();
|
||||||
for (int x = -1; x <= 1; x++)
|
for (int x = -1; x <= 1; x++)
|
||||||
{
|
{
|
||||||
@ -75,30 +73,26 @@ public class Command_gtfo extends TFM_Command
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ban IP address:
|
String ip = FUtil.getFuzzyIp(Ips.getIp(player));
|
||||||
String ip = TFM_Util.getFuzzyIp(player.getAddress().getAddress().getHostAddress());
|
|
||||||
|
|
||||||
|
// Broadcast
|
||||||
final StringBuilder bcast = new StringBuilder()
|
final StringBuilder bcast = new StringBuilder()
|
||||||
.append(ChatColor.RED)
|
.append(ChatColor.RED)
|
||||||
.append("Banning: ")
|
.append("Banning: ")
|
||||||
.append(player.getName())
|
.append(player.getName())
|
||||||
.append(", IP: ")
|
.append(", IP: ")
|
||||||
.append(ip);
|
.append(ip);
|
||||||
|
|
||||||
if (reason != null)
|
if (reason != null)
|
||||||
{
|
{
|
||||||
bcast.append(" - Reason: ").append(ChatColor.YELLOW).append(reason);
|
bcast.append(" - Reason: ").append(ChatColor.YELLOW).append(reason);
|
||||||
}
|
}
|
||||||
|
FUtil.bcastMsg(bcast.toString());
|
||||||
|
|
||||||
TFM_Util.bcastMsg(bcast.toString());
|
// Ban player
|
||||||
|
plugin.bm.addBan(FBan.forPlayerFuzzy(player, sender, null, reason));
|
||||||
|
|
||||||
TFM_BanManager.addIpBan(new TFM_Ban(ip, player.getName(), sender.getName(), null, reason));
|
// Kick player
|
||||||
|
player.kickPlayer(ChatColor.RED + "GTFO");
|
||||||
// ban username:
|
|
||||||
TFM_BanManager.addUuidBan(new TFM_Ban(TFM_UuidManager.getUniqueId(player), player.getName(), sender.getName(), null, reason));
|
|
||||||
|
|
||||||
// kick Player:
|
|
||||||
player.kickPlayer(ChatColor.RED + "GTFO" + (reason != null ? ("\nReason: " + ChatColor.YELLOW + reason) : ""));
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
@ -1,15 +1,16 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData;
|
import me.totalfreedom.totalfreedommod.admin.AdminList;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
|
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH)
|
||||||
@CommandParameters(description = "Halts a player", usage = "/<command> <<partialname> | all | purge | list>")
|
@CommandParameters(description = "Halts a player", usage = "/<command> <<partialname> | all | purge | list>")
|
||||||
public class Command_halt extends TFM_Command
|
public class Command_halt extends FreedomCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
@ -21,13 +22,13 @@ public class Command_halt extends TFM_Command
|
|||||||
|
|
||||||
if (args[0].equalsIgnoreCase("all"))
|
if (args[0].equalsIgnoreCase("all"))
|
||||||
{
|
{
|
||||||
TFM_Util.adminAction(sender.getName(), "Halting all non-superadmins.", true);
|
FUtil.adminAction(sender.getName(), "Halting all non-superadmins.", true);
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
for (Player player : server.getOnlinePlayers())
|
for (Player player : server.getOnlinePlayers())
|
||||||
{
|
{
|
||||||
if (!TFM_AdminList.isSuperAdmin(player))
|
if (!plugin.al.isAdmin(player))
|
||||||
{
|
{
|
||||||
TFM_PlayerData.getPlayerData(player).setHalted(true);
|
plugin.pl.getPlayer(player).setHalted(true);
|
||||||
counter++;
|
counter++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -37,12 +38,12 @@ public class Command_halt extends TFM_Command
|
|||||||
|
|
||||||
if (args[0].equalsIgnoreCase("purge"))
|
if (args[0].equalsIgnoreCase("purge"))
|
||||||
{
|
{
|
||||||
TFM_Util.adminAction(sender.getName(), "Unhalting all players.", true);
|
FUtil.adminAction(sender.getName(), "Unhalting all players.", true);
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
for (Player player : server.getOnlinePlayers())
|
for (Player player : server.getOnlinePlayers())
|
||||||
{
|
{
|
||||||
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
|
FPlayer playerdata = plugin.pl.getPlayer(player);
|
||||||
if (TFM_PlayerData.getPlayerData(player).isHalted())
|
if (plugin.pl.getPlayer(player).isHalted())
|
||||||
{
|
{
|
||||||
playerdata.setHalted(false);
|
playerdata.setHalted(false);
|
||||||
counter++;
|
counter++;
|
||||||
@ -54,11 +55,11 @@ public class Command_halt extends TFM_Command
|
|||||||
|
|
||||||
if (args[0].equalsIgnoreCase("list"))
|
if (args[0].equalsIgnoreCase("list"))
|
||||||
{
|
{
|
||||||
TFM_PlayerData info;
|
FPlayer info;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (Player hp : server.getOnlinePlayers())
|
for (Player hp : server.getOnlinePlayers())
|
||||||
{
|
{
|
||||||
info = TFM_PlayerData.getPlayerData(hp);
|
info = plugin.pl.getPlayer(hp);
|
||||||
if (info.isHalted())
|
if (info.isHalted())
|
||||||
{
|
{
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
@ -80,20 +81,20 @@ public class Command_halt extends TFM_Command
|
|||||||
|
|
||||||
if (player == null)
|
if (player == null)
|
||||||
{
|
{
|
||||||
sender.sendMessage(TFM_Command.PLAYER_NOT_FOUND);
|
sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
|
FPlayer playerdata = plugin.pl.getPlayer(player);
|
||||||
if (!playerdata.isHalted())
|
if (!playerdata.isHalted())
|
||||||
{
|
{
|
||||||
TFM_Util.adminAction(sender.getName(), "Halting " + player.getName(), true);
|
FUtil.adminAction(sender.getName(), "Halting " + player.getName(), true);
|
||||||
playerdata.setHalted(true);
|
playerdata.setHalted(true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TFM_Util.adminAction(sender.getName(), "Unhalting " + player.getName(), true);
|
FUtil.adminAction(sender.getName(), "Unhalting " + player.getName(), true);
|
||||||
playerdata.setHalted(false);
|
playerdata.setHalted(false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
@ -1,9 +1,10 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Log;
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||||
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||||
import org.apache.commons.lang.math.DoubleRange;
|
import org.apache.commons.lang.math.DoubleRange;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
@ -12,9 +13,9 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
|
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH)
|
||||||
@CommandParameters(description = "View ticks-per-second", usage = "/<command>")
|
@CommandParameters(description = "View ticks-per-second", usage = "/<command>")
|
||||||
public class Command_health extends TFM_Command
|
public class Command_health extends FreedomCommand
|
||||||
{
|
{
|
||||||
private static final int BYTES_PER_MB = 1024 * 1024;
|
private static final int BYTES_PER_MB = 1024 * 1024;
|
||||||
private static final DoubleRange TPS_RANGE = new DoubleRange(20.0 - 0.1, 20.0 + 0.1);
|
private static final DoubleRange TPS_RANGE = new DoubleRange(20.0 - 0.1, 20.0 + 0.1);
|
||||||
@ -53,7 +54,7 @@ public class Command_health extends TFM_Command
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
TFM_Log.severe(ex);
|
FLog.severe(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.runTaskAsynchronously(plugin);
|
}.runTaskAsynchronously(plugin);
|
@ -1,18 +1,19 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
|
import me.totalfreedom.totalfreedommod.admin.AdminList;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
|
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH)
|
||||||
@CommandParameters(description = "Shows (optionally smites) invisisible players", usage = "/<command> (smite)")
|
@CommandParameters(description = "Shows (optionally smites) invisisible players", usage = "/<command> (smite)")
|
||||||
public class Command_invis extends TFM_Command
|
public class Command_invis extends FreedomCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
@ -22,7 +23,7 @@ public class Command_invis extends TFM_Command
|
|||||||
{
|
{
|
||||||
if (args[0].equalsIgnoreCase("smite"))
|
if (args[0].equalsIgnoreCase("smite"))
|
||||||
{
|
{
|
||||||
TFM_Util.adminAction(sender.getName(), "Smiting all invisible players", true);
|
FUtil.adminAction(sender.getName(), "Smiting all invisible players", true);
|
||||||
smite = true;
|
smite = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -39,7 +40,7 @@ public class Command_invis extends TFM_Command
|
|||||||
if (player.hasPotionEffect(PotionEffectType.INVISIBILITY))
|
if (player.hasPotionEffect(PotionEffectType.INVISIBILITY))
|
||||||
{
|
{
|
||||||
players.add(player.getName());
|
players.add(player.getName());
|
||||||
if (smite && !TFM_AdminList.isSuperAdmin(player))
|
if (smite && !plugin.al.isAdmin(player))
|
||||||
{
|
{
|
||||||
player.setHealth(0.0);
|
player.setHealth(0.0);
|
||||||
smites++;
|
smites++;
|
@ -1,15 +1,16 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Jumppads;
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.totalfreedom.totalfreedommod.Jumppads;
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
|
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH)
|
||||||
@CommandParameters(description = "Manage jumppads", usage = "/<command> <on | off | info | sideways <on | off> | strength <strength (1-10)>>", aliases = "launchpads,jp")
|
@CommandParameters(description = "Manage jumppads", usage = "/<command> <on | off | info | sideways <on | off> | strength <strength (1-10)>>", aliases = "launchpads,jp")
|
||||||
public class Command_jumppads extends TFM_Command
|
public class Command_jumppads extends FreedomCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
@ -23,26 +24,26 @@ public class Command_jumppads extends TFM_Command
|
|||||||
{
|
{
|
||||||
if (args[0].equalsIgnoreCase("info"))
|
if (args[0].equalsIgnoreCase("info"))
|
||||||
{
|
{
|
||||||
playerMsg("Jumppads: " + (TFM_Jumppads.getMode().isOn() ? "Enabled" : "Disabled"), ChatColor.BLUE);
|
playerMsg("Jumppads: " + (plugin.jp.getMode().isOn() ? "Enabled" : "Disabled"), ChatColor.BLUE);
|
||||||
playerMsg("Sideways: " + (TFM_Jumppads.getMode() == TFM_Jumppads.JumpPadMode.NORMAL_AND_SIDEWAYS ? "Enabled" : "Disabled"), ChatColor.BLUE);
|
playerMsg("Sideways: " + (plugin.jp.getMode() == Jumppads.JumpPadMode.NORMAL_AND_SIDEWAYS ? "Enabled" : "Disabled"), ChatColor.BLUE);
|
||||||
playerMsg("Strength: " + (TFM_Jumppads.getStrength() * 10 - 1), ChatColor.BLUE);
|
playerMsg("Strength: " + (plugin.jp.getStrength() * 10 - 1), ChatColor.BLUE);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("off".equals(args[0]))
|
if ("off".equals(args[0]))
|
||||||
{
|
{
|
||||||
TFM_Util.adminAction(sender.getName(), "Disabling Jumppads", false);
|
FUtil.adminAction(sender.getName(), "Disabling Jumppads", false);
|
||||||
TFM_Jumppads.setMode(TFM_Jumppads.JumpPadMode.OFF);
|
plugin.jp.setMode(Jumppads.JumpPadMode.OFF);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TFM_Util.adminAction(sender.getName(), "Enabling Jumppads", false);
|
FUtil.adminAction(sender.getName(), "Enabling Jumppads", false);
|
||||||
TFM_Jumppads.setMode(TFM_Jumppads.JumpPadMode.MADGEEK);
|
plugin.jp.setMode(Jumppads.JumpPadMode.MADGEEK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (TFM_Jumppads.getMode() == TFM_Jumppads.JumpPadMode.OFF)
|
if (plugin.jp.getMode() == Jumppads.JumpPadMode.OFF)
|
||||||
{
|
{
|
||||||
playerMsg("Jumppads are currently disabled, please enable them before changing jumppads settings.");
|
playerMsg("Jumppads are currently disabled, please enable them before changing jumppads settings.");
|
||||||
return true;
|
return true;
|
||||||
@ -52,13 +53,13 @@ public class Command_jumppads extends TFM_Command
|
|||||||
{
|
{
|
||||||
if ("off".equals(args[1]))
|
if ("off".equals(args[1]))
|
||||||
{
|
{
|
||||||
TFM_Util.adminAction(sender.getName(), "Setting Jumppads mode to: Madgeek", false);
|
FUtil.adminAction(sender.getName(), "Setting Jumppads mode to: Madgeek", false);
|
||||||
TFM_Jumppads.setMode(TFM_Jumppads.JumpPadMode.MADGEEK);
|
plugin.jp.setMode(Jumppads.JumpPadMode.MADGEEK);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TFM_Util.adminAction(sender.getName(), "Setting Jumppads mode to: Normal and Sideways", false);
|
FUtil.adminAction(sender.getName(), "Setting Jumppads mode to: Normal and Sideways", false);
|
||||||
TFM_Jumppads.setMode(TFM_Jumppads.JumpPadMode.NORMAL_AND_SIDEWAYS);
|
plugin.jp.setMode(Jumppads.JumpPadMode.NORMAL_AND_SIDEWAYS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (args[0].equalsIgnoreCase("strength"))
|
else if (args[0].equalsIgnoreCase("strength"))
|
||||||
@ -80,8 +81,8 @@ public class Command_jumppads extends TFM_Command
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TFM_Util.adminAction(sender.getName(), "Setting Jumppads strength to: " + String.valueOf(strength), false);
|
FUtil.adminAction(sender.getName(), "Setting Jumppads strength to: " + String.valueOf(strength), false);
|
||||||
TFM_Jumppads.setStrength((strength / 10) + 0.1F);
|
plugin.jp.setStrength((strength / 10) + 0.1F);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
@ -1,24 +1,25 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.totalfreedom.totalfreedommod.admin.AdminList;
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.BOTH, blockHostConsole = true)
|
@CommandPermissions(level = PlayerRank.SENIOR_ADMIN, source = SourceType.BOTH, blockHostConsole = true)
|
||||||
@CommandParameters(description = "Kick all non-superadmins on server.", usage = "/<command>")
|
@CommandParameters(description = "Kick all non-superadmins on server.", usage = "/<command>")
|
||||||
public class Command_kicknoob extends TFM_Command
|
public class Command_kicknoob extends FreedomCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
{
|
{
|
||||||
TFM_Util.adminAction(sender.getName(), "Disconnecting all non-superadmins.", true);
|
FUtil.adminAction(sender.getName(), "Disconnecting all non-superadmins.", true);
|
||||||
|
|
||||||
for (Player player : server.getOnlinePlayers())
|
for (Player player : server.getOnlinePlayers())
|
||||||
{
|
{
|
||||||
if (!TFM_AdminList.isSuperAdmin(player))
|
if (!plugin.al.isAdmin(player))
|
||||||
{
|
{
|
||||||
player.kickPlayer(ChatColor.RED + "All non-superadmins were kicked by " + sender.getName() + ".");
|
player.kickPlayer(ChatColor.RED + "All non-superadmins were kicked by " + sender.getName() + ".");
|
||||||
}
|
}
|
@ -1,9 +1,10 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -13,20 +14,20 @@ import org.bukkit.command.Command;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.OP, source = SourceType.ONLY_IN_GAME)
|
@CommandPermissions(level = PlayerRank.OP, source = SourceType.ONLY_IN_GAME)
|
||||||
@CommandParameters(description = "Set a landmine trap.", usage = "/<command>")
|
@CommandParameters(description = "Set a landmine trap.", usage = "/<command>")
|
||||||
public class Command_landmine extends TFM_Command
|
public class Command_landmine extends FreedomCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
{
|
{
|
||||||
if (!TFM_ConfigEntry.LANDMINES_ENABLED.getBoolean())
|
if (!ConfigEntry.LANDMINES_ENABLED.getBoolean())
|
||||||
{
|
{
|
||||||
playerMsg("The landmine is currently disabled.", ChatColor.GREEN);
|
playerMsg("The landmine is currently disabled.", ChatColor.GREEN);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
|
if (!ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
|
||||||
{
|
{
|
||||||
playerMsg("Explosions are currently disabled.", ChatColor.GREEN);
|
playerMsg("Explosions are currently disabled.", ChatColor.GREEN);
|
||||||
return true;
|
return true;
|
@ -1,14 +1,15 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData;
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
|
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
|
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH)
|
||||||
@CommandParameters(description = "Show the last command that someone used.", usage = "/<command> <player>")
|
@CommandParameters(description = "Show the last command that someone used.", usage = "/<command> <player>")
|
||||||
public class Command_lastcmd extends TFM_Command
|
public class Command_lastcmd extends FreedomCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
@ -22,11 +23,11 @@ public class Command_lastcmd extends TFM_Command
|
|||||||
|
|
||||||
if (player == null)
|
if (player == null)
|
||||||
{
|
{
|
||||||
playerMsg(TFM_Command.PLAYER_NOT_FOUND);
|
playerMsg(FreedomCommand.PLAYER_NOT_FOUND);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
|
final FPlayer playerdata = plugin.pl.getPlayer(player);
|
||||||
|
|
||||||
if (playerdata != null)
|
if (playerdata != null)
|
||||||
{
|
{
|
@ -1,19 +1,18 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_PlayerRank;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.BOTH)
|
@CommandPermissions(level = PlayerRank.NON_OP, source = SourceType.BOTH)
|
||||||
@CommandParameters(description = "Lists the real names of all online players.", usage = "/<command> [-a | -i]", aliases = "who")
|
@CommandParameters(description = "Lists the real names of all online players.", usage = "/<command> [-a | -i]", aliases = "who")
|
||||||
public class Command_list extends TFM_Command
|
public class Command_list extends FreedomCommand
|
||||||
{
|
{
|
||||||
private static enum ListFilter
|
private static enum ListFilter
|
||||||
{
|
{
|
||||||
@ -30,7 +29,7 @@ public class Command_list extends TFM_Command
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TFM_Util.isFromHostConsole(sender.getName()))
|
if (FUtil.isFromHostConsole(sender.getName()))
|
||||||
{
|
{
|
||||||
final List<String> names = new ArrayList<String>();
|
final List<String> names = new ArrayList<String>();
|
||||||
for (Player player : server.getOnlinePlayers())
|
for (Player player : server.getOnlinePlayers())
|
||||||
@ -72,17 +71,17 @@ public class Command_list extends TFM_Command
|
|||||||
final List<String> names = new ArrayList<String>();
|
final List<String> names = new ArrayList<String>();
|
||||||
for (Player player : server.getOnlinePlayers())
|
for (Player player : server.getOnlinePlayers())
|
||||||
{
|
{
|
||||||
if (listFilter == ListFilter.ADMINS && !TFM_AdminList.isSuperAdmin(player))
|
if (listFilter == ListFilter.ADMINS && !plugin.al.isAdmin(player))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (listFilter == ListFilter.IMPOSTORS && !TFM_AdminList.isAdminImpostor(player))
|
if (listFilter == ListFilter.IMPOSTORS && !plugin.al.isAdminImpostor(player))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
names.add(TFM_PlayerRank.fromSender(player).getPrefix() + player.getName());
|
names.add(plugin.rm.getRank(player).getColoredTag() + player.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
onlineUsers.append("Connected ");
|
onlineUsers.append("Connected ");
|
@ -1,12 +1,13 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.totalfreedom.totalfreedommod.commands;
|
||||||
|
|
||||||
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.ONLY_IN_GAME)
|
@CommandPermissions(level = PlayerRank.NON_OP, source = SourceType.ONLY_IN_GAME)
|
||||||
@CommandParameters(description = "Teleport to the spawn point for the current world.", usage = "/<command>", aliases = "worldspawn,gotospawn")
|
@CommandParameters(description = "Teleport to the spawn point for the current world.", usage = "/<command>", aliases = "worldspawn,gotospawn")
|
||||||
public class Command_localspawn extends TFM_Command
|
public class Command_localspawn extends FreedomCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user