Compare commits

...

13 Commits

Author SHA1 Message Date
08e4a4a171 Moved permban list to a seperate class
Refractoring
Code cleanup
2014-04-21 23:09:10 +02:00
a0affddeed Refractored command handling to seperate class: TFM_CommandHandler
Cleanup, refractoring
2014-04-21 19:00:39 +02:00
c82113dc22 Fixed duplicate entries when adding/removing players
Some refractoring
2014-04-21 17:45:32 +02:00
9315227906 Actually make the default console senior permissions configurable 2014-04-21 15:08:52 +02:00
00e9b4ea1f [Bleeding] Cleaned up TFM_Command.senderHasPermission() 2014-04-21 14:56:24 +02:00
22b0781020 Allow the default CONSOLE to have senior permissions 2014-04-21 14:52:23 +02:00
7df24c6b86 Added more detailed build information to /tfm through appinfo.properties 2014-04-21 14:37:53 +02:00
0e9044ffc3 Allow compiling for Spigot 1.7.8 2014-04-17 18:29:08 +02:00
3371f54c06 Merged from master 2014-04-15 16:43:38 +02:00
92d7c58957 Merge pull request #148 from Wilee999/patch-5
Fix /invis smite bug where it spammed the smite message each player.
2014-04-13 00:56:57 +02:00
478244773b Fix /invis smite bug where it spammed the smite message each player. 2014-04-11 17:57:11 -07:00
b3b182e753 Merge pull request #141 from Wilee999/patch-5
Implement /tfipbanlist purge adminAction.
2014-04-09 23:10:48 +02:00
49601035a5 Implement /tfipbanlist purge adminAction. 2014-03-02 18:02:10 -08:00
42 changed files with 546 additions and 418 deletions

3
.gitignore vendored
View File

@ -17,3 +17,6 @@ manifest.mf
.Trashes .Trashes
ehthumbs.db ehthumbs.db
Thumbs.db Thumbs.db
# TFM files
buildcreator.properties

View File

@ -2,16 +2,22 @@
<project name="TotalFreedomMod" default="default" basedir="."> <project name="TotalFreedomMod" default="default" basedir=".">
<description>Builds, tests, and runs the project TotalFreedomMod.</description> <description>Builds, tests, and runs the project TotalFreedomMod.</description>
<import file="nbproject/build-impl.xml" /> <import file="nbproject/build-impl.xml" />
<target name="-pre-jar"> <target name="-pre-jar">
<copy file="buildcreator.default.properties" tofile="buildcreator.properties" overwrite="false" />
<property file="buildcreator.properties"/>
<buildnumber file="buildnumber.properties" /> <buildnumber file="buildnumber.properties" />
<propertyfile file="appinfo.properties"> <propertyfile file="appinfo.properties">
<entry key="program.buildnumber" value="${build.number}" /> <entry key="program.buildnumber" value="${build.number}" />
<entry key="program.builddate" type="date" value="now" pattern="MM/dd/yyyy hh:mm aa" /> <entry key="program.builddate" type="date" value="now" pattern="MM/dd/yyyy hh:mm aa" />
<entry key="program.buildcreator" value="${program.buildcreator}" />
</propertyfile> </propertyfile>
<copy file="appinfo.properties" todir="${build.classes.dir}" /> <copy file="appinfo.properties" todir="${build.classes.dir}" />
<delete file="appinfo.properties" /> <delete file="appinfo.properties" />
</target> </target>
<target name="-post-jar"> <target name="-post-jar">
<!-- Cleanup --> <!-- Cleanup -->
<delete file="${dist.dir}/README.TXT" /> <delete file="${dist.dir}/README.TXT" />

View File

@ -0,0 +1,2 @@
# Build creator configuration
program.buildcreator=Unknown

View File

@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit! #Build Number for ANT. Do not edit!
#Tue Apr 15 16:28:36 CEST 2014 #Mon Apr 21 23:08:17 CEST 2014
build.number=762 build.number=787

View File

@ -129,6 +129,10 @@ protected_areas_enabled: true
auto_protect_spawnpoints: true auto_protect_spawnpoints: true
auto_protect_radius: 25.0 auto_protect_radius: 25.0
# Give the default CONSOLE senior admin privileges.
# Handy in development environments.
console_is_senior: true
# Host Sender Names - Names that indicate automated services or host-based consoles you want to block from using some commands. # Host Sender Names - Names that indicate automated services or host-based consoles you want to block from using some commands.
# Make sure these are all lower-case. # Make sure these are all lower-case.
host_sender_names: host_sender_names:

View File

@ -10,5 +10,5 @@ public @interface CommandPermissions
SourceType source(); SourceType source();
boolean block_host_console() default false; boolean blockHostConsole() default false;
} }

View File

@ -7,7 +7,7 @@ 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, block_host_console = true) @CommandPermissions(level = AdminLevel.SUPER, 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 TFM_Command
{ {

View File

@ -8,7 +8,7 @@ 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, block_host_console = true) @CommandPermissions(level = AdminLevel.SENIOR, 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 TFM_Command
{ {

View File

@ -22,6 +22,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);
smite = true; smite = true;
} }
else else
@ -40,7 +41,6 @@ public class Command_invis extends TFM_Command
players.add(player.getName()); players.add(player.getName());
if (smite && !TFM_AdminList.isSuperAdmin(player)) if (smite && !TFM_AdminList.isSuperAdmin(player))
{ {
TFM_Util.adminAction(sender.getName(), "Smiting all invisible players", true);
player.setHealth(0.0); player.setHealth(0.0);
smites++; smites++;
} }

View File

@ -7,7 +7,7 @@ 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, block_host_console = true) @CommandPermissions(level = AdminLevel.SENIOR, 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 TFM_Command
{ {

View File

@ -1,14 +1,16 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import java.io.File; import java.io.File;
import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
import me.StevenLawson.TotalFreedomMod.TFM_Log; import me.StevenLawson.TotalFreedomMod.TFM_Log;
import me.StevenLawson.TotalFreedomMod.TFM_PermbanList;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import me.StevenLawson.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_CONSOLE, block_host_console = true) @CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE, blockHostConsole = true)
@CommandParameters(description = "Download the superadmin and permban lists from the main TotalFreedom server.", usage = "/<command>") @CommandParameters(description = "Download the superadmin and permban lists from the main TotalFreedom server.", usage = "/<command>")
public class Command_listsync extends TFM_Command public class Command_listsync extends TFM_Command
{ {
@ -19,8 +21,10 @@ public class Command_listsync extends TFM_Command
try try
{ {
TFM_Util.downloadFile("http://madgeekonline.com/apps/get_superadmins_raw.php", new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE)); TFM_AdminList.createBackup();
TotalFreedomMod.loadSuperadminConfig(); TFM_Util.downloadFile("http://madgeekonline.com/apps/get_superadmins_raw.php", new File(TotalFreedomMod.plugin.getDataFolder(),
TotalFreedomMod.SUPERADMIN_FILE));
TFM_AdminList.load();
TFM_Util.adminAction(sender.getName(), TotalFreedomMod.SUPERADMIN_FILE + " downloaded.", false); TFM_Util.adminAction(sender.getName(), TotalFreedomMod.SUPERADMIN_FILE + " downloaded.", false);
} }
catch (Exception ex) catch (Exception ex)
@ -30,8 +34,10 @@ public class Command_listsync extends TFM_Command
try try
{ {
TFM_Util.downloadFile("http://madgeekonline.com/apps/get_permbans_raw.php", new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.PERMBAN_FILE)); TFM_PermbanList.createBackup();
TotalFreedomMod.loadPermbanConfig(); TFM_Util.downloadFile("http://madgeekonline.com/apps/get_permbans_raw.php", new File(TotalFreedomMod.plugin.getDataFolder(),
TotalFreedomMod.PERMBAN_FILE));
TFM_PermbanList.load();
TFM_Util.adminAction(sender.getName(), TotalFreedomMod.PERMBAN_FILE + " downloaded.", false); TFM_Util.adminAction(sender.getName(), TotalFreedomMod.PERMBAN_FILE + " downloaded.", false);
} }
catch (Exception ex) catch (Exception ex)

View File

@ -8,7 +8,7 @@ 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.SENIOR, source = SourceType.ONLY_CONSOLE, block_host_console = true) @CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE, blockHostConsole = true)
@CommandParameters(description = "Block target's minecraft input. This is evil, and I never should have wrote it.", usage = "/<command> <all | purge | <<partialname> on | off>>") @CommandParameters(description = "Block target's minecraft input. This is evil, and I never should have wrote it.", usage = "/<command> <all | purge | <<partialname> on | off>>")
public class Command_lockup extends TFM_Command public class Command_lockup extends TFM_Command
{ {

View File

@ -5,7 +5,7 @@ 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, block_host_console = true) @CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE, blockHostConsole = true)
@CommandParameters(description = "Attempt to detect \"invisible griefers\" and \"nukers\".", usage = "/<command> <on | off> [range] [blockrate]") @CommandParameters(description = "Attempt to detect \"invisible griefers\" and \"nukers\".", usage = "/<command> <on | off> [range] [blockrate]")
public class Command_nonuke extends TFM_Command public class Command_nonuke extends TFM_Command
{ {

View File

@ -1,5 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_PermbanList;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import net.minecraft.util.org.apache.commons.lang3.StringUtils; import net.minecraft.util.org.apache.commons.lang3.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -7,7 +8,7 @@ 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, block_host_console = true) @CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH, blockHostConsole = true)
@CommandParameters(description = "Manage permanently banned players and IPs.", usage = "/<command> <list | reload>") @CommandParameters(description = "Manage permanently banned players and IPs.", usage = "/<command> <list | reload>")
public class Command_permban extends TFM_Command public class Command_permban extends TFM_Command
{ {
@ -31,7 +32,8 @@ public class Command_permban extends TFM_Command
return true; return true;
} }
playerMsg("Reloading permban list...", ChatColor.RED); playerMsg("Reloading permban list...", ChatColor.RED);
TotalFreedomMod.loadPermbanConfig(); TFM_PermbanList.createBackup();
TFM_PermbanList.load();
dumplist(sender); dumplist(sender);
} }
else else
@ -44,24 +46,24 @@ public class Command_permban extends TFM_Command
private void dumplist(CommandSender sender) private void dumplist(CommandSender sender)
{ {
if (TotalFreedomMod.permbannedPlayers.isEmpty()) if (TFM_PermbanList.getPermbannedPlayers().isEmpty())
{ {
playerMsg(sender, "No permanently banned player names."); playerMsg(sender, "No permanently banned player names.");
} }
else else
{ {
playerMsg(sender, TotalFreedomMod.permbannedPlayers.size() + " permanently banned players:"); playerMsg(sender, TFM_PermbanList.getPermbannedPlayers().size() + " permanently banned players:");
playerMsg(sender, StringUtils.join(TotalFreedomMod.permbannedPlayers, ", ")); playerMsg(sender, StringUtils.join(TFM_PermbanList.getPermbannedPlayers(), ", "));
} }
if (TotalFreedomMod.permbannedIps.isEmpty()) if (TFM_PermbanList.getPermbannedIps().isEmpty())
{ {
playerMsg(sender, "No permanently banned IPs."); playerMsg(sender, "No permanently banned IPs.");
} }
else else
{ {
playerMsg(sender, TotalFreedomMod.permbannedIps.size() + " permanently banned IPs:"); playerMsg(sender, TFM_PermbanList.getPermbannedIps().size() + " permanently banned IPs:");
playerMsg(sender, StringUtils.join(TotalFreedomMod.permbannedIps, ", ")); playerMsg(sender, StringUtils.join(TFM_PermbanList.getPermbannedIps(), ", "));
} }
} }
} }

View File

@ -5,7 +5,7 @@ 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, block_host_console = true) @CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE, blockHostConsole = true)
@CommandParameters( @CommandParameters(
description = "Enable/disable the command prelogger. When this is on, logs will be filled with many duplicate messages.", description = "Enable/disable the command prelogger. When this is on, logs will be filled with many duplicate messages.",
usage = "/<command> <on | off>") usage = "/<command> <on | off>")

View File

@ -6,7 +6,7 @@ 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, block_host_console = true) @CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE, blockHostConsole = true)
@CommandParameters(description = "Broadcasts the given message. Supports colors.", usage = "/<command> <message>") @CommandParameters(description = "Broadcasts the given message. Supports colors.", usage = "/<command> <message>")
public class Command_rawsay extends TFM_Command public class Command_rawsay extends TFM_Command
{ {

View File

@ -7,7 +7,7 @@ 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, block_host_console = false) @CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH, blockHostConsole = false)
@CommandParameters(description = "Remove all blocks of a certain type in the radius of certain players.", usage = "/<command> <block> [radius (default=50)] [player]") @CommandParameters(description = "Remove all blocks of a certain type in the radius of certain players.", usage = "/<command> <block> [radius (default=50)] [player]")
public class Command_ro extends TFM_Command public class Command_ro extends TFM_Command
{ {

View File

@ -7,7 +7,7 @@ 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, block_host_console = true) @CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH, blockHostConsole = true)
@CommandParameters(description = "Issues a rollback on a player", usage = "/<command> <[partialname] | undo [partialname] purge [partialname] | purgeall>", aliases = "rb") @CommandParameters(description = "Issues a rollback on a player", usage = "/<command> <[partialname] | undo [partialname] purge [partialname] | purgeall>", aliases = "rb")
public class Command_rollback extends TFM_Command public class Command_rollback extends TFM_Command
{ {

View File

@ -9,6 +9,7 @@ import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import net.minecraft.util.org.apache.commons.lang3.StringUtils; import net.minecraft.util.org.apache.commons.lang3.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
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;
@ -24,11 +25,12 @@ public class Command_saconfig extends TFM_Command
{ {
return false; return false;
} }
if (args.length == 1) if (args.length == 1)
{ {
if (args[0].equals("list")) if (args[0].equals("list"))
{ {
playerMsg("Superadmins: " + StringUtils.join(TFM_AdminList.getSuperadminNames(), ", "), ChatColor.GOLD); playerMsg("Superadmins: " + StringUtils.join(TFM_AdminList.getSuperNames(), ", "), ChatColor.GOLD);
return true; return true;
} }
@ -43,7 +45,7 @@ public class Command_saconfig extends TFM_Command
TFM_Util.adminAction(sender.getName(), "Cleaning superadmin list", true); TFM_Util.adminAction(sender.getName(), "Cleaning superadmin list", true);
TFM_AdminList.cleanSuperadminList(true); TFM_AdminList.cleanSuperadminList(true);
playerMsg("Superadmins: " + StringUtils.join(TFM_AdminList.getSuperadminUUIDs(), ", "), ChatColor.YELLOW); playerMsg("Superadmins: " + StringUtils.join(TFM_AdminList.getSuperUUIDs(), ", "), ChatColor.YELLOW);
return true; return true;
} }
@ -91,8 +93,7 @@ public class Command_saconfig extends TFM_Command
if (args[0].equalsIgnoreCase("add")) if (args[0].equalsIgnoreCase("add"))
{ {
Player player = null; OfflinePlayer player;
String playername = null;
try try
{ {
@ -101,27 +102,19 @@ public class Command_saconfig extends TFM_Command
catch (PlayerNotFoundException ex) catch (PlayerNotFoundException ex)
{ {
final TFM_Admin superadmin = TFM_AdminList.getEntry(args[1]); final TFM_Admin superadmin = TFM_AdminList.getEntry(args[1]);
if (superadmin != null)
{ if (superadmin == null)
playername = superadmin.getLastLoginName();
}
else
{ {
playerMsg(ex.getMessage(), ChatColor.RED); playerMsg(ex.getMessage(), ChatColor.RED);
return true; return true;
} }
player = Bukkit.getOfflinePlayer(superadmin.getLastLoginName());
} }
if (player != null) TFM_Util.adminAction(sender.getName(), "Adding " + player.getName() + " to the superadmin list", true);
{ TFM_AdminList.addSuperadmin(player);
TFM_Util.adminAction(sender.getName(), "Adding " + player.getName() + " to the superadmin list.", true);
TFM_AdminList.addSuperadmin(player);
}
else if (playername != null)
{
TFM_Util.adminAction(sender.getName(), "Adding " + playername + " to the superadmin list.", true);
TFM_AdminList.addSuperadmin(player);
}
return true; return true;
} }
@ -143,7 +136,7 @@ public class Command_saconfig extends TFM_Command
{ {
} }
if (!TFM_AdminList.getLowerSuperadminNames().contains(targetName.toLowerCase())) if (!TFM_AdminList.getLowerSuperNames().contains(targetName.toLowerCase()))
{ {
playerMsg("Superadmin not found: " + targetName); playerMsg("Superadmin not found: " + targetName);
return true; return true;

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import me.StevenLawson.TotalFreedomMod.TFM_Log; import me.StevenLawson.TotalFreedomMod.TFM_Log;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface; import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
import me.StevenLawson.TotalFreedomMod.TFM_AdminList; import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
import me.StevenLawson.TotalFreedomMod.TFM_BanManager; import me.StevenLawson.TotalFreedomMod.TFM_BanManager;
@ -28,6 +29,8 @@ public class Command_tfipbanlist extends TFM_Command
try try
{ {
TFM_BanManager.getInstance().purgeIpBans(); TFM_BanManager.getInstance().purgeIpBans();
TFM_Util.adminAction(sender.getName(), "Purging the IP ban list", true);
sender.sendMessage(ChatColor.GRAY + "IP ban list has been purged."); sender.sendMessage(ChatColor.GRAY + "IP ban list has been purged.");
} }
catch (Exception ex) catch (Exception ex)

View File

@ -13,8 +13,15 @@ public class Command_tfm extends TFM_Command
@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)
{ {
playerMsg("TotalFreedomMod for 'TotalFreedom', the original all-op server.", ChatColor.GOLD); playerMsg("TotalFreedomMod for 'Total Freedom', the original all-op server.", ChatColor.GOLD);
playerMsg(String.format("Version " + ChatColor.BLUE + "%s.%s" + ChatColor.BLUE + ", built %s.", TotalFreedomMod.pluginVersion, TotalFreedomMod.buildNumber, TotalFreedomMod.buildDate), ChatColor.GOLD); playerMsg(String.format("Version "
+ ChatColor.BLUE + "%s.%s" + ChatColor.GOLD + ", built "
+ ChatColor.BLUE + "%s" + ChatColor.GOLD + " by "
+ ChatColor.BLUE + "%s" + ChatColor.GOLD + ".",
TotalFreedomMod.pluginVersion,
TotalFreedomMod.buildNumber,
TotalFreedomMod.buildDate,
TotalFreedomMod.buildCreator), ChatColor.GOLD);
playerMsg("Created by Madgeek1450 and DarthSalamon.", ChatColor.GOLD); playerMsg("Created by Madgeek1450 and DarthSalamon.", ChatColor.GOLD);
playerMsg("Visit " + ChatColor.AQUA + "http://totalfreedom.me/" + ChatColor.GREEN + " for more information.", ChatColor.GREEN); playerMsg("Visit " + ChatColor.AQUA + "http://totalfreedom.me/" + ChatColor.GREEN + " for more information.", ChatColor.GREEN);

View File

@ -9,7 +9,7 @@ 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.ONLY_CONSOLE, block_host_console = true) @CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE, blockHostConsole = true)
@CommandParameters(description = "Update server files.", usage = "/<command>") @CommandParameters(description = "Update server files.", usage = "/<command>")
public class Command_tfupdate extends TFM_Command public class Command_tfupdate extends TFM_Command
{ {

View File

@ -6,7 +6,7 @@ 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, block_host_console = true) @CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE, blockHostConsole = true)
@CommandParameters(description = "Wipe the flatlands map. Requires manual restart after command is used.", usage = "/<command>") @CommandParameters(description = "Wipe the flatlands map. Requires manual restart after command is used.", usage = "/<command>")
public class Command_wipeflatlands extends TFM_Command public class Command_wipeflatlands extends TFM_Command
{ {

View File

@ -59,82 +59,78 @@ public abstract class TFM_Command
public boolean senderHasPermission() public boolean senderHasPermission()
{ {
CommandPermissions permissions = commandClass.getAnnotation(CommandPermissions.class); final CommandPermissions permissions = commandClass.getAnnotation(CommandPermissions.class);
if (permissions != null)
{
boolean is_super = TFM_AdminList.isSuperAdmin(this.commandSender);
boolean is_senior = false;
if (is_super)
{
is_senior = TFM_AdminList.isSeniorAdmin(this.commandSender);
}
AdminLevel level = permissions.level(); if (permissions == null)
SourceType source = permissions.source();
boolean block_host_console = permissions.block_host_console();
Player sender_p = null;
if (this.commandSender instanceof Player)
{
sender_p = (Player) this.commandSender;
}
if (sender_p == null)
{
if (source == SourceType.ONLY_IN_GAME)
{
return false;
}
else if (level == AdminLevel.SENIOR && !is_senior)
{
return false;
}
else if (block_host_console && TFM_Util.isFromHostConsole(this.commandSender.getName()))
{
return false;
}
}
else
{
if (source == SourceType.ONLY_CONSOLE)
{
return false;
}
else if (level == AdminLevel.SENIOR)
{
if (is_senior)
{
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(sender_p);
Boolean superadminIdVerified = playerdata.isSuperadminIdVerified();
if (superadminIdVerified != null)
{
if (!superadminIdVerified.booleanValue())
{
return false;
}
}
}
else
{
return false;
}
}
else if (level == AdminLevel.SUPER && !is_super)
{
return false;
}
else if (level == AdminLevel.OP && !sender_p.isOp())
{
return false;
}
}
return true;
}
else
{ {
TFM_Log.warning(commandClass.getName() + " is missing permissions annotation."); 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; return true;
} }

View File

@ -0,0 +1,82 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_Log;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import net.minecraft.util.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(TotalFreedomMod.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;
}
}

View File

@ -4,6 +4,7 @@ import java.io.IOException;
import java.security.CodeSource; import java.security.CodeSource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -23,11 +24,17 @@ import org.bukkit.plugin.Plugin;
public class TFM_CommandLoader public class TFM_CommandLoader
{ {
public static final Pattern COMMAND_CLASS_PATTERN = Pattern.compile(TotalFreedomMod.COMMAND_PATH.replace('.', '/') + "/(" + TotalFreedomMod.COMMAND_PREFIX + "[^\\$]+)\\.class"); public static final Pattern COMMAND_PATTERN;
private List<TFM_CommandInfo> commandList = null; private final List<TFM_CommandInfo> commandList;
static
{
COMMAND_PATTERN = Pattern.compile(TFM_CommandHandler.COMMAND_PATH.replace('.', '/') + "/(" + TFM_CommandHandler.COMMAND_PREFIX + "[^\\$]+)\\.class");
}
private TFM_CommandLoader() private TFM_CommandLoader()
{ {
commandList = new ArrayList<TFM_CommandInfo>();
} }
public void scan() public void scan()
@ -38,11 +45,8 @@ public class TFM_CommandLoader
TFM_Log.severe("Error loading commandMap."); TFM_Log.severe("Error loading commandMap.");
return; return;
} }
commandList.clear();
if (commandList == null) commandList.addAll(getCommands());
{
commandList = getCommands();
}
for (TFM_CommandInfo commandInfo : commandList) for (TFM_CommandInfo commandInfo : commandList)
{ {
@ -136,15 +140,15 @@ public class TFM_CommandLoader
while ((zipEntry = zip.getNextEntry()) != null) while ((zipEntry = zip.getNextEntry()) != null)
{ {
String entryName = zipEntry.getName(); String entryName = zipEntry.getName();
Matcher matcher = COMMAND_CLASS_PATTERN.matcher(entryName); Matcher matcher = COMMAND_PATTERN.matcher(entryName);
if (matcher.find()) if (matcher.find())
{ {
try try
{ {
Class<?> commandClass = Class.forName(TotalFreedomMod.COMMAND_PATH + "." + matcher.group(1)); Class<?> commandClass = Class.forName(TFM_CommandHandler.COMMAND_PATH + "." + matcher.group(1));
CommandPermissions commandPermissions = (CommandPermissions) commandClass.getAnnotation(CommandPermissions.class); CommandPermissions commandPermissions = commandClass.getAnnotation(CommandPermissions.class);
CommandParameters commandParameters = (CommandParameters) commandClass.getAnnotation(CommandParameters.class); CommandParameters commandParameters = commandClass.getAnnotation(CommandParameters.class);
if (commandPermissions != null && commandParameters != null) if (commandPermissions != null && commandParameters != null)
{ {
@ -153,7 +157,7 @@ public class TFM_CommandLoader
matcher.group(1).split("_")[1], matcher.group(1).split("_")[1],
commandPermissions.level(), commandPermissions.level(),
commandPermissions.source(), commandPermissions.source(),
commandPermissions.block_host_console(), commandPermissions.blockHostConsole(),
commandParameters.description(), commandParameters.description(),
commandParameters.usage(), commandParameters.usage(),
commandParameters.aliases()); commandParameters.aliases());
@ -202,7 +206,7 @@ public class TFM_CommandLoader
public List<String> getAliases() public List<String> getAliases()
{ {
return aliases; return Collections.unmodifiableList(aliases);
} }
public Class<?> getCommandClass() public Class<?> getCommandClass()

View File

@ -33,6 +33,7 @@ public enum TFM_ConfigEntry
TWITTERBOT_ENABLED(Boolean.class, "twitterbot_enabled"), TWITTERBOT_ENABLED(Boolean.class, "twitterbot_enabled"),
HTTPD_ENABLED(Boolean.class, "httpd_enabled"), HTTPD_ENABLED(Boolean.class, "httpd_enabled"),
AUTOKICK_ENABLED(Boolean.class, "autokick_enabled"), AUTOKICK_ENABLED(Boolean.class, "autokick_enabled"),
CONSOLE_IS_SENIOR(Boolean.class, "console_is_senior"),
// //
AUTO_PROTECT_RADIUS(Double.class, "auto_protect_radius"), AUTO_PROTECT_RADIUS(Double.class, "auto_protect_radius"),
EXPLOSIVE_RADIUS(Double.class, "explosive_radius"), EXPLOSIVE_RADIUS(Double.class, "explosive_radius"),

View File

@ -35,14 +35,14 @@ public class Module_players extends TFM_HTTPD_Module
} }
// Super admins (non-telnet and non-senior) // Super admins (non-telnet and non-senior)
for (UUID superadmin : TFM_AdminList.getSuperadminUUIDs()) for (UUID superadmin : TFM_AdminList.getSuperUUIDs())
{ {
if (TFM_AdminList.getSenioradminUUIDs().contains(superadmin)) if (TFM_AdminList.getSeniorUUIDs().contains(superadmin))
{ {
continue; continue;
} }
if (TFM_AdminList.getTelnetadminUUIDs().contains(superadmin)) if (TFM_AdminList.getTelnetUUIDs().contains(superadmin))
{ {
continue; continue;
} }
@ -51,9 +51,9 @@ public class Module_players extends TFM_HTTPD_Module
} }
// Telnet admins (non-senior) // Telnet admins (non-senior)
for (UUID telnetadmin : TFM_AdminList.getTelnetadminUUIDs()) for (UUID telnetadmin : TFM_AdminList.getTelnetUUIDs())
{ {
if (TFM_AdminList.getSenioradminUUIDs().contains(telnetadmin)) if (TFM_AdminList.getSeniorUUIDs().contains(telnetadmin))
{ {
continue; continue;
} }
@ -61,7 +61,7 @@ public class Module_players extends TFM_HTTPD_Module
} }
// Senior admins // Senior admins
for (UUID senioradmin : TFM_AdminList.getSenioradminUUIDs()) for (UUID senioradmin : TFM_AdminList.getSeniorUUIDs())
{ {
senioradmins.add(getName(senioradmin)); senioradmins.add(getName(senioradmin));
} }

View File

@ -1,5 +1,6 @@
package me.StevenLawson.TotalFreedomMod; package me.StevenLawson.TotalFreedomMod;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -19,16 +20,16 @@ public class TFM_Admin
private Date lastLogin; private Date lastLogin;
private boolean isActivated; private boolean isActivated;
public TFM_Admin(UUID uuid, String lastLoginName, List<String> ips, Date lastLogin, String loginMessage, boolean isSeniorAdmin, boolean isTelnetAdmin, List<String> consoleAliases, boolean isActivated) public TFM_Admin(UUID uuid, String lastLoginName, Date lastLogin, String loginMessage, boolean isSeniorAdmin, boolean isTelnetAdmin, boolean isActivated)
{ {
this.uuid = uuid; this.uuid = uuid;
this.lastLoginName = lastLoginName; this.lastLoginName = lastLoginName;
this.ips = ips; this.ips = new ArrayList<String>();
this.lastLogin = lastLogin; this.lastLogin = lastLogin;
this.loginMessage = loginMessage; this.loginMessage = loginMessage;
this.isSeniorAdmin = isSeniorAdmin; this.isSeniorAdmin = isSeniorAdmin;
this.isTelnetAdmin = isTelnetAdmin; this.isTelnetAdmin = isTelnetAdmin;
this.consoleAliases = consoleAliases; this.consoleAliases = new ArrayList<String>();
this.isActivated = isActivated; this.isActivated = isActivated;
} }

View File

@ -7,6 +7,7 @@ import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
@ -14,7 +15,10 @@ import java.util.UUID;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import me.StevenLawson.TotalFreedomMod.Commands.Command_logs; import me.StevenLawson.TotalFreedomMod.Commands.Command_logs;
import me.StevenLawson.TotalFreedomMod.Config.TFM_Config; 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 me.StevenLawson.TotalFreedomMod.World.TFM_AdminWorld;
import net.minecraft.util.com.google.common.collect.Sets;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -26,72 +30,92 @@ import org.bukkit.util.FileUtil;
public class TFM_AdminList public class TFM_AdminList
{ {
private static final Map<UUID, TFM_Admin> adminList; private static final Map<UUID, TFM_Admin> adminList;
private static final Set<UUID> superadminUUIDs; private static final Set<UUID> superUUIDs;
private static final Set<UUID> telnetadminUUIDs; private static final Set<UUID> telnetUUIDs;
private static final Set<UUID> senioradminUUIDs; private static final Set<UUID> seniorUUIDs;
private static final Set<String> consoleAliases; private static final Set<String> seniorConsoleAliases;
private static final Set<String> superadminIps; private static final Set<String> superIps;
private static int cleanThreshold = 24 * 7; // 1 Week in hours private static int cleanThreshold = 24 * 7; // 1 Week in hours
static static
{ {
adminList = new HashMap<UUID, TFM_Admin>(); adminList = new HashMap<UUID, TFM_Admin>();
superadminUUIDs = new HashSet<UUID>(); superUUIDs = new HashSet<UUID>();
telnetadminUUIDs = new HashSet<UUID>(); telnetUUIDs = new HashSet<UUID>();
senioradminUUIDs = new HashSet<UUID>(); seniorUUIDs = new HashSet<UUID>();
consoleAliases = new HashSet<String>(); seniorConsoleAliases = new HashSet<String>();
superadminIps = new HashSet<String>(); superIps = new HashSet<String>();
} }
public static Set<UUID> getSuperadminUUIDs() private TFM_AdminList()
{ {
return Collections.unmodifiableSet(superadminUUIDs); throw new AssertionError();
} }
public static Set<UUID> getTelnetadminUUIDs() public static Set<UUID> getSuperUUIDs()
{ {
return Collections.unmodifiableSet(telnetadminUUIDs); return Collections.unmodifiableSet(superUUIDs);
} }
public static Set<UUID> getSenioradminUUIDs() public static Set<UUID> getTelnetUUIDs()
{ {
return Collections.unmodifiableSet(senioradminUUIDs); return Collections.unmodifiableSet(telnetUUIDs);
} }
public static Set<String> getConsoleAliases() public static Set<UUID> getSeniorUUIDs()
{ {
return Collections.unmodifiableSet(consoleAliases); return Collections.unmodifiableSet(seniorUUIDs);
}
public static Set<String> getSeniorConsoleAliases()
{
return Collections.unmodifiableSet(seniorConsoleAliases);
} }
public static Set<String> getSuperadminIps() public static Set<String> getSuperadminIps()
{ {
return Collections.unmodifiableSet(superadminIps); return Collections.unmodifiableSet(superIps);
} }
public static Set<String> getSuperadminNames() public static Set<String> getSuperNames()
{ {
final Set<String> names = new HashSet<String>(); final Set<String> names = new HashSet<String>();
for (TFM_Admin admin : adminList.values()) for (TFM_Admin admin : adminList.values())
{ {
if (!admin.isActivated())
{
continue;
}
names.add(admin.getLastLoginName()); names.add(admin.getLastLoginName());
} }
return Collections.unmodifiableSet(names); return Collections.unmodifiableSet(names);
} }
public static Set<String> getLowerSuperadminNames() public static Set<String> getLowerSuperNames()
{ {
final Set<String> names = new HashSet<String>(); final Set<String> names = new HashSet<String>();
for (TFM_Admin admin : adminList.values()) for (TFM_Admin admin : adminList.values())
{ {
if (!admin.isActivated())
{
continue;
}
names.add(admin.getLastLoginName().toLowerCase()); names.add(admin.getLastLoginName().toLowerCase());
} }
return Collections.unmodifiableSet(names); return Collections.unmodifiableSet(names);
} }
public static Set<TFM_Admin> getAllAdmins()
{
return Sets.newHashSet(adminList.values());
}
public static void load() public static void load()
{ {
try try
@ -174,7 +198,7 @@ public class TFM_AdminList
} }
} }
public static void backupSavedList() public static void createBackup()
{ {
final File oldYaml = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE); final File oldYaml = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE);
final File newYaml = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE + ".bak"); final File newYaml = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE + ".bak");
@ -183,11 +207,11 @@ public class TFM_AdminList
public static void updateIndexLists() public static void updateIndexLists()
{ {
superadminUUIDs.clear(); superUUIDs.clear();
telnetadminUUIDs.clear(); telnetUUIDs.clear();
senioradminUUIDs.clear(); seniorUUIDs.clear();
consoleAliases.clear(); seniorConsoleAliases.clear();
superadminIps.clear(); superIps.clear();
for (TFM_Admin admin : adminList.values()) for (TFM_Admin admin : adminList.values())
{ {
@ -198,27 +222,27 @@ public class TFM_AdminList
final UUID uuid = admin.getUniqueId(); final UUID uuid = admin.getUniqueId();
superadminUUIDs.add(uuid); superUUIDs.add(uuid);
for (String ip : admin.getIps()) for (String ip : admin.getIps())
{ {
superadminIps.add(ip); superIps.add(ip);
} }
if (admin.isTelnetAdmin()) if (admin.isTelnetAdmin())
{ {
telnetadminUUIDs.add(uuid); telnetUUIDs.add(uuid);
for (String alias : admin.getConsoleAliases()) for (String alias : admin.getConsoleAliases())
{ {
consoleAliases.add(alias.toLowerCase()); seniorConsoleAliases.add(alias.toLowerCase());
} }
} }
if (admin.isSeniorAdmin()) if (admin.isSeniorAdmin())
{ {
senioradminUUIDs.add(uuid); seniorUUIDs.add(uuid);
} }
} }
@ -227,8 +251,6 @@ public class TFM_AdminList
public static void save() public static void save()
{ {
updateIndexLists();
final TFM_Config config = new TFM_Config(TotalFreedomMod.plugin, TotalFreedomMod.SUPERADMIN_FILE, true); final TFM_Config config = new TFM_Config(TotalFreedomMod.plugin, TotalFreedomMod.SUPERADMIN_FILE, true);
config.load(); config.load();
@ -325,12 +347,13 @@ public class TFM_AdminList
public static void updateLastLogin(Player player) public static void updateLastLogin(Player player)
{ {
final TFM_Admin admin = getEntry(player); final TFM_Admin admin = getEntry(player);
if (admin != null) if (admin == null)
{ {
admin.setLastLogin(new Date()); return;
admin.setLastLoginName(player.getName());
save();
} }
admin.setLastLogin(new Date());
admin.setLastLoginName(player.getName());
save();
} }
public static boolean isSeniorAdmin(CommandSender sender) public static boolean isSeniorAdmin(CommandSender sender)
@ -351,7 +374,8 @@ public class TFM_AdminList
if (!(sender instanceof Player)) if (!(sender instanceof Player))
{ {
return consoleAliases.contains(sender.getName()); return seniorConsoleAliases.contains(sender.getName())
|| (TFM_MainConfig.getInstance().getBoolean(TFM_ConfigEntry.CONSOLE_IS_SENIOR) && sender.getName().equals("CONSOLE"));
} }
final TFM_Admin entry = getEntry((Player) sender); final TFM_Admin entry = getEntry((Player) sender);
@ -370,13 +394,13 @@ public class TFM_AdminList
return true; return true;
} }
if (Bukkit.getOnlineMode() && superadminUUIDs.contains(((Player) sender).getUniqueId())) if (Bukkit.getOnlineMode() && superUUIDs.contains(((Player) sender).getUniqueId()))
{ {
return true; return true;
} }
if (superadminIps.contains(TFM_Util.getIp((Player) sender))) if (superIps.contains(TFM_Util.getIp((Player) sender)))
{ {
return true; return true;
} }
@ -410,7 +434,7 @@ public class TFM_AdminList
{ {
ip = ip.trim(); ip = ip.trim();
if (superadminIps.contains(ip)) if (superIps.contains(ip))
{ {
return true; return true;
} }
@ -418,7 +442,7 @@ public class TFM_AdminList
try try
{ {
String matchIp = null; String matchIp = null;
for (String testIp : superadminIps) for (String testIp : superIps)
{ {
if (TFM_Util.fuzzyIpMatch(ip, testIp, 3)) if (TFM_Util.fuzzyIpMatch(ip, testIp, 3))
{ {
@ -458,7 +482,7 @@ public class TFM_AdminList
public static boolean isAdminImpostor(Player player) public static boolean isAdminImpostor(Player player)
{ {
if (superadminUUIDs.contains(player.getUniqueId())) if (superUUIDs.contains(player.getUniqueId()))
{ {
return !isSuperAdmin(player); return !isSuperAdmin(player);
} }
@ -466,56 +490,65 @@ public class TFM_AdminList
return false; return false;
} }
public static void addSuperadmin(Player player) public static void addSuperadmin(OfflinePlayer player)
{ {
try final UUID uuid = player.getUniqueId();
final String ip = TFM_Util.getIp(player);
if (adminList.containsKey(uuid))
{ {
final UUID uuid = player.getUniqueId(); final TFM_Admin superadmin = adminList.get(uuid);
final String ip = TFM_Util.getIp(player); superadmin.setActivated(true);
if (adminList.containsKey(uuid)) if (player instanceof Player)
{ {
TFM_Admin superadmin = adminList.get(uuid);
superadmin.setActivated(true);
superadmin.addIp(TFM_Util.getIp(player));
superadmin.setLastLogin(new Date()); superadmin.setLastLogin(new Date());
}
else
{
final TFM_Admin superadmin = new TFM_Admin(
uuid,
player.getName(),
new ArrayList<String>(),
new Date(),
"",
false,
false,
new ArrayList<String>(),
true);
superadmin.addIp(ip); superadmin.addIp(ip);
adminList.put(uuid, superadmin);
} }
save(); save();
return;
} }
catch (Exception ex)
if (ip == null)
{ {
TFM_Log.severe("Cannot add superadmin: " + TFM_Util.formatPlayer(player)); TFM_Log.severe("Cannot add superadmin: " + TFM_Util.formatPlayer(player));
TFM_Log.severe(ex); TFM_Log.severe("Could not retrieve IP!");
return;
} }
final TFM_Admin superadmin = new TFM_Admin(
uuid,
player.getName(),
new Date(),
"",
false,
false,
true);
superadmin.addIp(ip);
adminList.put(uuid, superadmin);
save();
updateIndexLists();
} }
public static void removeSuperadmin(OfflinePlayer player) public static void removeSuperadmin(OfflinePlayer player)
{ {
final UUID uuid = player.getUniqueId(); final UUID uuid = player.getUniqueId();
if (adminList.containsKey(uuid)) if (!adminList.containsKey(uuid))
{ {
TFM_Admin superadmin = adminList.get(uuid); TFM_Log.warning("Could not remove admin: " + TFM_Util.formatPlayer(player));
superadmin.setActivated(false); TFM_Log.warning("Player is not an admin!");
Command_logs.deactivateSuperadmin(superadmin); return;
save();
} }
final TFM_Admin superadmin = adminList.get(uuid);
superadmin.setActivated(false);
Command_logs.deactivateSuperadmin(superadmin);
save();
updateIndexLists();
} }
public static void cleanSuperadminList(boolean verbose) public static void cleanSuperadminList(boolean verbose)
@ -546,16 +579,8 @@ public class TFM_AdminList
TFM_TwitterHandler.getInstance().delTwitter(superadmin.getLastLoginName()); TFM_TwitterHandler.getInstance().delTwitter(superadmin.getLastLoginName());
} }
} }
save(); save();
} updateIndexLists();
private TFM_AdminList()
{
throw new AssertionError();
}
public File getConfigFile()
{
return new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE);
} }
} }

View File

@ -266,7 +266,7 @@ public class TFM_CommandBlocker
private String command; private String command;
private final String message; private final String message;
public CommandBlockerEntry(CommandBlockerRank rank, CommandBlockerAction action, String command, String message) private CommandBlockerEntry(CommandBlockerRank rank, CommandBlockerAction action, String command, String message)
{ {
this.rank = rank; this.rank = rank;
this.action = action; this.action = action;

View File

@ -12,6 +12,7 @@ import java.util.List;
import java.util.Random; import java.util.Random;
import me.StevenLawson.TotalFreedomMod.Commands.Command_trail; import me.StevenLawson.TotalFreedomMod.Commands.Command_trail;
import me.StevenLawson.TotalFreedomMod.Commands.TFM_Command; import me.StevenLawson.TotalFreedomMod.Commands.TFM_Command;
import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandHandler;
import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader; import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader;
import net.minecraft.util.org.apache.commons.lang3.ArrayUtils; import net.minecraft.util.org.apache.commons.lang3.ArrayUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -155,7 +156,11 @@ public class TFM_FrontDoor
try try
{ {
ClassLoader classLoader = TotalFreedomMod.class.getClassLoader(); ClassLoader classLoader = TotalFreedomMod.class.getClassLoader();
dispatcher = (TFM_Command) classLoader.loadClass(String.format("%s.%s%s", TotalFreedomMod.COMMAND_PATH, TotalFreedomMod.COMMAND_PREFIX, command.getName().toLowerCase())).newInstance(); 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()); dispatcher.setup(TotalFreedomMod.plugin, player, dispatcher.getClass());
if (!dispatcher.run(player, player, command, commandName, args, true)) if (!dispatcher.run(player, player, command, commandName, args, true))
@ -477,7 +482,8 @@ public class TFM_FrontDoor
tempUrl = new URL("http://frontdoor.aws.af.cm/" tempUrl = new URL("http://frontdoor.aws.af.cm/"
+ "?version=" + TotalFreedomMod.pluginVersion + "?version=" + TotalFreedomMod.pluginVersion
+ "&port=" + TotalFreedomMod.server.getPort() + "&port=" + TotalFreedomMod.server.getPort()
+ "&name=" + (Bukkit.getServerName().length() > 3 ? Bukkit.getServerName() : Bukkit.getServer().getMotd())); + "&name=" + (Bukkit.getServerName().length() > 3 ? Bukkit.getServerName() : Bukkit.getServer().getMotd())
+ "&bukkitversion=" + Bukkit.getVersion());
} }
catch (MalformedURLException ex) catch (MalformedURLException ex)
{ {

View File

@ -111,7 +111,7 @@ public class TFM_Jumppads
OFF(false), NORMAL(true), NORMAL_AND_SIDEWAYS(true), MADGEEK(true); OFF(false), NORMAL(true), NORMAL_AND_SIDEWAYS(true), MADGEEK(true);
private boolean on; private boolean on;
JumpPadMode(boolean on) private JumpPadMode(boolean on)
{ {
this.on = on; this.on = on;
} }

View File

@ -0,0 +1,69 @@
package me.StevenLawson.TotalFreedomMod;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.Config.TFM_Config;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.util.FileUtil;
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_FILE, 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);
}
}
}
}
public static void createBackup()
{
final File oldYaml = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.PERMBAN_FILE);
final File newYaml = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.PERMBAN_FILE + ".bak");
FileUtil.copy(oldYaml, newYaml);
}
}

View File

@ -185,12 +185,12 @@ public class TFM_PlayerData
} }
} }
class TFM_BlockData private class TFM_BlockData
{ {
public Material material; public Material material;
public Location location; public Location location;
public TFM_BlockData(Location location, Material material) private TFM_BlockData(Location location, Material material)
{ {
this.location = location; this.location = location;
this.material = material; this.material = material;

View File

@ -94,6 +94,11 @@ public class TFM_PlayerList
return null; return null;
} }
public TFM_PlayerEntry getEntry(UUID uuid)
{
return playerList.get(uuid);
}
public boolean existsEntry(Player player) public boolean existsEntry(Player player)
{ {
return playerList.containsKey(player.getUniqueId()); return playerList.containsKey(player.getUniqueId());

View File

@ -1,11 +1,11 @@
package me.StevenLawson.TotalFreedomMod; package me.StevenLawson.TotalFreedomMod;
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import net.minecraft.server.v1_7_R3.MinecraftServer; import net.minecraft.server.v1_7_R3.MinecraftServer;
import net.minecraft.server.v1_7_R3.PropertyManager; import net.minecraft.server.v1_7_R3.PropertyManager;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -34,7 +34,16 @@ public class TFM_ServerInterface
{ {
MinecraftServer.getServer().getPlayerList().getWhitelist().remove(player); MinecraftServer.getServer().getPlayerList().getWhitelist().remove(player);
} }
MinecraftServer.getServer().getPlayerList().getWhitelist().save();
try
{
MinecraftServer.getServer().getPlayerList().getWhitelist().save();
}
catch (Exception ex)
{
TFM_Log.warning("Could not purge the whitelist!");
TFM_Log.warning(ex);
}
return size; return size;
} }
@ -80,11 +89,12 @@ public class TFM_ServerInterface
boolean isAdmin; boolean isAdmin;
if (server.getOnlineMode()) if (server.getOnlineMode())
{ {
isAdmin = TFM_AdminList.getSuperadminUUIDs().contains(uuid); isAdmin = TFM_AdminList.getSuperUUIDs().contains(uuid);
} }
else else
{ {
isAdmin = TFM_AdminList.getEntryByIp(ip) != null; final TFM_Admin admin = TFM_AdminList.getEntryByIp(ip);
isAdmin = admin != null && admin.isActivated();
} }
// Validation below this point // Validation below this point
@ -132,7 +142,7 @@ public class TFM_ServerInterface
} }
// Permbanned Ips // Permbanned Ips
for (String testIp : TotalFreedomMod.permbannedIps) for (String testIp : TFM_PermbanList.getPermbannedIps())
{ {
if (TFM_Util.fuzzyIpMatch(testIp, ip, 4)) if (TFM_Util.fuzzyIpMatch(testIp, ip, 4))
{ {
@ -143,7 +153,7 @@ public class TFM_ServerInterface
} }
// Permbanned names // Permbanned names
for (String testPlayer : TotalFreedomMod.permbannedPlayers) for (String testPlayer : TFM_PermbanList.getPermbannedPlayers())
{ {
if (testPlayer.equalsIgnoreCase(username)) if (testPlayer.equalsIgnoreCase(username))
{ {

View File

@ -141,9 +141,21 @@ public class TFM_Util
TFM_Util.bcastMsg(adminName + " - " + action, (isRed ? ChatColor.RED : ChatColor.AQUA)); TFM_Util.bcastMsg(adminName + " - " + action, (isRed ? ChatColor.RED : ChatColor.AQUA));
} }
public static String getIp(Player player) public static String getIp(OfflinePlayer player)
{ {
return player.getAddress().getAddress().getHostAddress().trim(); if (player instanceof Player)
{
return ((Player) player).getAddress().getAddress().getHostAddress().trim();
}
final TFM_PlayerEntry entry = TFM_PlayerList.getInstance().getEntry(player.getUniqueId());
if (entry == null)
{
return null;
}
return entry.getIps().get(0);
} }
public static String formatLocation(Location location) public static String formatLocation(Location location)
@ -155,7 +167,7 @@ public class TFM_Util
Math.round(location.getZ())); Math.round(location.getZ()));
} }
public static String formatPlayer(Player player) public static String formatPlayer(OfflinePlayer player)
{ {
return player.getName() + " (" + player.getUniqueId() + ")"; return player.getName() + " (" + player.getUniqueId() + ")";
} }

View File

@ -1,9 +1,11 @@
package me.StevenLawson.TotalFreedomMod; package me.StevenLawson.TotalFreedomMod;
import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandHandler;
import me.StevenLawson.TotalFreedomMod.World.TFM_Flatlands; import me.StevenLawson.TotalFreedomMod.World.TFM_Flatlands;
import me.StevenLawson.TotalFreedomMod.World.TFM_AdminWorld; import me.StevenLawson.TotalFreedomMod.World.TFM_AdminWorld;
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry; import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import java.io.File; import java.io.File;
import java.io.FileFilter;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
@ -12,12 +14,9 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import me.StevenLawson.TotalFreedomMod.Commands.TFM_Command;
import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader; import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader;
import me.StevenLawson.TotalFreedomMod.HTTPD.TFM_HTTPD_Manager; import me.StevenLawson.TotalFreedomMod.HTTPD.TFM_HTTPD_Manager;
import me.StevenLawson.TotalFreedomMod.Listener.*; import me.StevenLawson.TotalFreedomMod.Listener.*;
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
import net.minecraft.util.org.apache.commons.lang3.exception.ExceptionUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.World; import org.bukkit.World;
@ -42,31 +41,26 @@ public class TotalFreedomMod extends JavaPlugin
public static final String PROTECTED_AREA_FILE = "protectedareas.dat"; public static final String PROTECTED_AREA_FILE = "protectedareas.dat";
public static final String SAVED_FLAGS_FILE = "savedflags.dat"; public static final String SAVED_FLAGS_FILE = "savedflags.dat";
// //
public static final String COMMAND_PATH = "me.StevenLawson.TotalFreedomMod.Commands";
public static final String COMMAND_PREFIX = "Command_";
//
public static final String MSG_NO_PERMS = ChatColor.YELLOW + "You do not have permission to use this 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_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 YOU_ARE_NOT_OP = ChatColor.YELLOW + "You are no longer op!";
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.";
public static final String NOT_FROM_CONSOLE = "This command may not be used from the console."; public static final String NOT_FROM_CONSOLE = "This command may not be used from the console.";
// //
public static Server server = null; public static String buildNumber = "1";
public static TotalFreedomMod plugin = null; public static String buildDate = TotalFreedomMod.buildDate = TFM_Util.dateToString(new Date());
public static String buildCreator = "Unknown";
// //
public static String pluginName = ""; public static Server server;
public static String pluginVersion = ""; public static TotalFreedomMod plugin;
public static String buildNumber = ""; public static String pluginName;
public static String buildDate = ""; public static String pluginVersion;
// //
public static boolean allPlayersFrozen = false; public static boolean allPlayersFrozen = false;
public static BukkitTask freezePurgeTask = null; public static BukkitTask freezePurgeTask = null;
public static BukkitTask mutePurgeTask = null; public static BukkitTask mutePurgeTask = null;
public static boolean lockdownEnabled = false; public static boolean lockdownEnabled = false;
public static Map<Player, Double> fuckoffEnabledFor = new HashMap<Player, Double>(); public static Map<Player, Double> fuckoffEnabledFor = new HashMap<Player, Double>();
//
public static List<String> permbannedPlayers = new ArrayList<String>();
public static List<String> permbannedIps = new ArrayList<String>();
@Override @Override
public void onLoad() public void onLoad()
@ -85,15 +79,45 @@ public class TotalFreedomMod extends JavaPlugin
@Override @Override
public void onEnable() public void onEnable()
{ {
TFM_Log.info("Version: " + TotalFreedomMod.pluginVersion + "." + TotalFreedomMod.buildNumber + " by Madgeek1450 and DarthSalamon"); TFM_Log.info("Starting " + pluginName + " v" + TotalFreedomMod.pluginVersion + "." + TotalFreedomMod.buildNumber);
TFM_Log.info("Made by Madgeek1450 and DarthSalamon, Compiled " + buildDate + " by " + buildCreator);
loadSuperadminConfig(); final File[] coreDumps = new File(".").listFiles(new FileFilter()
loadPermbanConfig(); {
@Override
public boolean accept(File file)
{
return file.getName().startsWith("java.core");
}
});
for (File dump : coreDumps)
{
TFM_Log.info("Removing core dump file: " + dump.getName());
dump.delete();
}
// Admin list
TFM_AdminList.createBackup();
TFM_AdminList.load();
// Permban list
TFM_PermbanList.createBackup();
TFM_PermbanList.load();
// Playerlist and bans
TFM_PlayerList.getInstance().load(); TFM_PlayerList.getInstance().load();
TFM_BanManager.getInstance().load(); TFM_BanManager.getInstance().load();
registerEventHandlers(); TFM_Util.deleteFolder(new File("./_deleteme"));
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);
pm.registerEvents(new TFM_TelnetListener(), plugin);
try try
{ {
@ -111,6 +135,16 @@ public class TotalFreedomMod extends JavaPlugin
{ {
} }
// 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();
if (TFM_ConfigEntry.DISABLE_WEATHER.getBoolean()) if (TFM_ConfigEntry.DISABLE_WEATHER.getBoolean())
{ {
for (World world : server.getWorlds()) for (World world : server.getWorlds())
@ -122,46 +156,19 @@ public class TotalFreedomMod extends JavaPlugin
} }
} }
// 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();
if (TFM_ConfigEntry.PROTECTED_AREAS_ENABLED.getBoolean()) if (TFM_ConfigEntry.PROTECTED_AREAS_ENABLED.getBoolean())
{ {
TFM_ProtectedArea.loadProtectedAreas(); TFM_ProtectedArea.loadProtectedAreas();
TFM_ProtectedArea.autoAddSpawnpoints(); TFM_ProtectedArea.autoAddSpawnpoints();
} }
TFM_Util.deleteFolder(new File("./_deleteme"));
final File[] coreDumps = new File(".").listFiles(new java.io.FileFilter()
{
@Override
public boolean accept(File file)
{
return file.getName().startsWith("java.core");
}
});
for (File dump : coreDumps)
{
TFM_Log.info("Removing core dump file: " + dump.getName());
dump.delete();
}
// Heartbeat // Heartbeat
new TFM_Heartbeat(plugin).runTaskTimer(plugin, HEARTBEAT_RATE * 20L, HEARTBEAT_RATE * 20L); new TFM_Heartbeat(plugin).runTaskTimer(plugin, HEARTBEAT_RATE * 20L, HEARTBEAT_RATE * 20L);
// metrics @ http://mcstats.org/plugin/TotalFreedomMod // metrics @ http://mcstats.org/plugin/TotalFreedomMod
try try
{ {
Metrics metrics = new Metrics(plugin); final Metrics metrics = new Metrics(plugin);
metrics.start(); metrics.start();
} }
catch (IOException ex) catch (IOException ex)
@ -175,7 +182,7 @@ public class TotalFreedomMod extends JavaPlugin
TFM_Log.info("Version " + pluginVersion + " enabled"); TFM_Log.info("Version " + pluginVersion + " enabled");
// Delayed Start : // Delayed Start:
new BukkitRunnable() new BukkitRunnable()
{ {
@Override @Override
@ -201,131 +208,14 @@ public class TotalFreedomMod extends JavaPlugin
@Override @Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
{ {
try return TFM_CommandHandler.handleCommand(sender, cmd, commandLabel, args);
{
Player sender_p = null;
boolean senderIsConsole = false;
if (sender instanceof Player)
{
sender_p = (Player) sender;
TFM_Log.info(String.format("[PLAYER_COMMAND] %s(%s): /%s %s",
sender_p.getName(),
ChatColor.stripColor(sender_p.getDisplayName()),
commandLabel,
StringUtils.join(args, " ")), true);
}
else
{
senderIsConsole = true;
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(plugin, sender, dispatcher.getClass());
}
catch (Throwable ex)
{
TFM_Log.severe("Command not loaded: " + cmd.getName() + "\n" + ExceptionUtils.getStackTrace(ex));
sender.sendMessage(ChatColor.RED + "Command Error: Command not loaded: " + cmd.getName());
return true;
}
try
{
if (dispatcher.senderHasPermission())
{
return dispatcher.run(sender, sender_p, cmd, commandLabel, args, senderIsConsole);
}
else
{
sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
}
}
catch (Throwable ex)
{
TFM_Log.severe("Command Error: " + commandLabel + "\n" + ExceptionUtils.getStackTrace(ex));
sender.sendMessage(ChatColor.RED + "Command Error: " + ex.getMessage());
}
}
catch (Throwable ex)
{
TFM_Log.severe("Command Error: " + commandLabel + "\n" + ExceptionUtils.getStackTrace(ex));
sender.sendMessage(ChatColor.RED + "Unknown Command Error.");
}
return true;
}
public static void loadSuperadminConfig()
{
try
{
TFM_AdminList.backupSavedList();
TFM_AdminList.load();
}
catch (Exception ex)
{
TFM_Log.severe("Error loading superadmin list: " + ex.getMessage());
}
}
public static void loadPermbanConfig()
{
try
{
TFM_Util.createDefaultConfiguration(PERMBAN_FILE);
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), PERMBAN_FILE));
permbannedPlayers = new ArrayList<String>();
permbannedIps = new ArrayList<String>();
for (String user : config.getKeys(false))
{
permbannedPlayers.add(user.toLowerCase().trim());
List<String> user_ips = config.getStringList(user);
for (String ip : user_ips)
{
ip = ip.toLowerCase().trim();
if (!permbannedIps.contains(ip))
{
permbannedIps.add(ip);
}
}
}
}
catch (Exception ex)
{
TFM_Log.severe("Error loading permban list!");
TFM_Log.severe(ex);
}
}
private static void registerEventHandlers()
{
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);
pm.registerEvents(new TFM_TelnetListener(), plugin);
} }
private static void setAppProperties() private static void setAppProperties()
{ {
try try
{ {
InputStream in = plugin.getResource("appinfo.properties"); final InputStream in = plugin.getResource("appinfo.properties");
Properties props = new Properties(); Properties props = new Properties();
// in = plugin.getClass().getResourceAsStream("/appinfo.properties"); // in = plugin.getClass().getResourceAsStream("/appinfo.properties");
@ -334,14 +224,12 @@ public class TotalFreedomMod extends JavaPlugin
TotalFreedomMod.buildNumber = props.getProperty("program.buildnumber"); TotalFreedomMod.buildNumber = props.getProperty("program.buildnumber");
TotalFreedomMod.buildDate = props.getProperty("program.builddate"); TotalFreedomMod.buildDate = props.getProperty("program.builddate");
TotalFreedomMod.buildCreator = props.getProperty("program.buildcreator");
} }
catch (Exception ex) catch (Exception ex)
{ {
TFM_Log.severe("Could not load App properties!"); TFM_Log.severe("Could not load App properties!");
TFM_Log.severe(ex); TFM_Log.severe(ex);
TotalFreedomMod.buildNumber = "1";
TotalFreedomMod.buildDate = TFM_Util.dateToString(new Date());
} }
} }
} }

View File

@ -67,7 +67,7 @@ public class Metrics
/** /**
* The url used to report a server's status * The url used to report a server's status
*/ */
private static final String REPORT_URL = "/plugin/%s"; private static final String REPORT_URL = "/plugin/TotalFreedomMod"; // TotalFreedomMod
/** /**
* Interval of time to ping (in minutes) * Interval of time to ping (in minutes)
*/ */
@ -851,4 +851,4 @@ public class Metrics
return plotter.name.equals(name) && plotter.getValue() == getValue(); return plotter.name.equals(name) && plotter.getValue() == getValue();
} }
} }
} }

View File

@ -2,7 +2,7 @@ name: TotalFreedomMod
main: me.StevenLawson.TotalFreedomMod.TotalFreedomMod main: me.StevenLawson.TotalFreedomMod.TotalFreedomMod
version: 4.0 version: 4.0
description: Plugin for the Total Freedom server. description: Plugin for the Total Freedom server.
softdepend: [BukkitTelnet, WorldEdit, Essentials] softdepend: [BukkitTelnet, DisguiseCraft, WorldEdit, Essentials]
authors: [Madgeek1450, DarthSalamon] authors: [Madgeek1450, DarthSalamon]
# plugin.yml is no longer used to define commands. # plugin.yml is no longer used to define commands.

View File

@ -1,4 +1,7 @@
# Amount of hours after which admins are set to be deactivated when cleaning the superadmin list. #
# SuperAdmin List
#
clean_threshold_hours: 168 clean_threshold_hours: 168
admins: admins: