2011-09-20 02:52:08 +00:00
|
|
|
package me.StevenLawson.TotalFreedomMod;
|
|
|
|
|
2011-09-26 15:26:52 +00:00
|
|
|
import java.io.File;
|
2011-09-21 03:31:59 +00:00
|
|
|
import java.util.ArrayList;
|
2011-10-19 00:37:00 +00:00
|
|
|
import java.util.Arrays;
|
2011-09-21 03:31:59 +00:00
|
|
|
import java.util.List;
|
2011-09-20 02:52:08 +00:00
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
2011-10-19 00:37:00 +00:00
|
|
|
import me.StevenLawson.TotalFreedomMod.Commands.TFM_Command;
|
|
|
|
import me.StevenLawson.TotalFreedomMod.Listener.*;
|
2011-09-20 02:52:08 +00:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.ChatColor;
|
2011-10-19 00:37:00 +00:00
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
2011-10-12 19:33:31 +00:00
|
|
|
import org.bukkit.configuration.file.FileConfiguration;
|
|
|
|
import org.bukkit.configuration.file.YamlConfiguration;
|
2011-10-13 23:07:52 +00:00
|
|
|
import org.bukkit.entity.Player;
|
2011-09-23 03:22:10 +00:00
|
|
|
import org.bukkit.event.Event;
|
|
|
|
import org.bukkit.plugin.PluginManager;
|
2011-09-20 02:52:08 +00:00
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
|
|
|
|
public class TotalFreedomMod extends JavaPlugin
|
|
|
|
{
|
2011-09-26 15:26:52 +00:00
|
|
|
private static final Logger log = Logger.getLogger("Minecraft");
|
2011-10-01 17:59:46 +00:00
|
|
|
|
2011-10-10 12:09:19 +00:00
|
|
|
public static final long HEARTBEAT_RATE = 5L; //Seconds
|
2011-10-12 22:45:43 +00:00
|
|
|
public static final String CONFIG_FILE = "config.yml";
|
2011-10-19 02:52:32 +00:00
|
|
|
public static final String SUPERADMIN_FILE = "superadmin.yml";
|
2011-11-08 00:29:33 +00:00
|
|
|
public static final String COMMAND_PATH = "me.StevenLawson.TotalFreedomMod.Commands";
|
|
|
|
public static final String COMMAND_PREFIX = "Command_";
|
2011-10-02 16:15:16 +00:00
|
|
|
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 CAKE_LYRICS = "But there's no sense crying over every mistake. You just keep on trying till you run out of cake.";
|
2011-10-16 06:00:37 +00:00
|
|
|
public static final String NOT_FROM_CONSOLE = "This command may not be used from the console.";
|
2011-10-13 23:45:01 +00:00
|
|
|
|
2011-11-08 00:29:33 +00:00
|
|
|
public static boolean allPlayersFrozen = false;
|
2011-10-01 17:59:46 +00:00
|
|
|
|
2011-10-02 16:15:16 +00:00
|
|
|
@Override
|
|
|
|
public void onEnable()
|
|
|
|
{
|
2011-10-19 02:52:32 +00:00
|
|
|
loadMainConfig();
|
|
|
|
loadSuperadminConfig();
|
2011-10-30 19:27:06 +00:00
|
|
|
|
2011-10-02 16:15:16 +00:00
|
|
|
registerEventHandlers();
|
2011-10-30 19:27:06 +00:00
|
|
|
|
2011-10-12 22:45:43 +00:00
|
|
|
Bukkit.getServer().getScheduler().scheduleAsyncRepeatingTask(this, new TFM_Heartbeat(this), HEARTBEAT_RATE * 20L, HEARTBEAT_RATE * 20L);
|
2011-09-30 19:32:13 +00:00
|
|
|
|
2011-10-13 01:33:58 +00:00
|
|
|
log.log(Level.INFO, "[" + getDescription().getName() + "] - Enabled! - Version: " + getDescription().getVersion() + " by Madgeek1450");
|
2011-10-30 19:27:06 +00:00
|
|
|
|
2011-10-14 05:31:21 +00:00
|
|
|
TFM_Util.deleteFolder(new File("./_deleteme"));
|
2011-10-02 16:15:16 +00:00
|
|
|
}
|
2011-09-26 15:26:52 +00:00
|
|
|
|
2011-10-02 16:15:16 +00:00
|
|
|
@Override
|
|
|
|
public void onDisable()
|
|
|
|
{
|
2011-10-12 22:45:43 +00:00
|
|
|
Bukkit.getScheduler().cancelTasks(this);
|
2011-10-13 01:33:58 +00:00
|
|
|
log.log(Level.INFO, "[" + getDescription().getName() + "] - Disabled.");
|
2011-10-12 22:45:43 +00:00
|
|
|
}
|
2011-10-19 00:37:00 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Player sender_p = null;
|
|
|
|
boolean senderIsConsole = false;
|
|
|
|
if (sender instanceof Player)
|
|
|
|
{
|
|
|
|
sender_p = (Player) sender;
|
|
|
|
log.info(String.format("[PLAYER_COMMAND] %s(%s): /%s %s",
|
|
|
|
sender_p.getName(),
|
|
|
|
ChatColor.stripColor(sender_p.getDisplayName()),
|
|
|
|
commandLabel,
|
|
|
|
TFM_Util.implodeStringList(" ", Arrays.asList(args))));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
senderIsConsole = true;
|
|
|
|
log.info(String.format("[CONSOLE_COMMAND] %s: /%s %s",
|
|
|
|
sender.getName(),
|
|
|
|
commandLabel,
|
|
|
|
TFM_Util.implodeStringList(" ", Arrays.asList(args))));
|
|
|
|
}
|
|
|
|
|
|
|
|
TFM_Command dispatcher;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
ClassLoader classLoader = TotalFreedomMod.class.getClassLoader();
|
|
|
|
dispatcher = (TFM_Command) classLoader.loadClass(String.format("%s.%s%s", COMMAND_PATH, COMMAND_PREFIX, cmd.getName().toLowerCase())).newInstance();
|
|
|
|
dispatcher.setPlugin(this);
|
|
|
|
}
|
|
|
|
catch (Throwable ex)
|
|
|
|
{
|
2011-10-19 02:52:32 +00:00
|
|
|
log.log(Level.SEVERE, "[" + getDescription().getName() + "] Command not loaded: " + cmd.getName(), ex);
|
2011-10-19 00:37:00 +00:00
|
|
|
sender.sendMessage(ChatColor.RED + "Command Error: Command not loaded: " + cmd.getName());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return dispatcher.run(sender, sender_p, cmd, commandLabel, args, senderIsConsole);
|
|
|
|
}
|
|
|
|
catch (Throwable ex)
|
|
|
|
{
|
|
|
|
sender.sendMessage(ChatColor.RED + "Command Error: " + ex.getMessage());
|
|
|
|
}
|
2011-10-30 19:27:06 +00:00
|
|
|
|
2011-10-24 02:43:52 +00:00
|
|
|
dispatcher = null;
|
2011-10-19 00:37:00 +00:00
|
|
|
}
|
|
|
|
catch (Throwable ex)
|
|
|
|
{
|
2011-10-19 02:52:32 +00:00
|
|
|
log.log(Level.SEVERE, "[" + getDescription().getName() + "] Command Error: " + commandLabel, ex);
|
2011-10-19 00:37:00 +00:00
|
|
|
sender.sendMessage(ChatColor.RED + "Unknown Command Error.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2011-10-12 22:45:43 +00:00
|
|
|
|
2011-11-08 00:29:33 +00:00
|
|
|
public static boolean allowFirePlace = false;
|
|
|
|
public static Boolean allowFireSpread = false;
|
|
|
|
public static Boolean allowLavaDamage = false;
|
|
|
|
public static boolean allowLavaPlace = false;
|
|
|
|
public static boolean allowWaterPlace = false;
|
|
|
|
public static Boolean allowExplosions = false;
|
|
|
|
public static double explosiveRadius = 4.0D;
|
|
|
|
public static boolean autoEntityWipe = true;
|
|
|
|
public static boolean nukeMonitor = true;
|
|
|
|
public static int nukeMonitorCountBreak = 100;
|
|
|
|
public static int nukeMonitorCountPlace = 25;
|
|
|
|
public static double nukeMonitorRange = 10.0D;
|
|
|
|
public static int freecamTriggerCount = 10;
|
|
|
|
public static Boolean preprocessLogEnabled = true;
|
|
|
|
public static Boolean disableNight = true;
|
|
|
|
public static Boolean disableWeather = true;
|
|
|
|
public static boolean landminesEnabled = false;
|
|
|
|
public static boolean mp44Enabled = false;
|
2011-10-12 22:45:43 +00:00
|
|
|
|
2011-10-19 02:52:32 +00:00
|
|
|
public void loadMainConfig()
|
2011-10-02 16:15:16 +00:00
|
|
|
{
|
2011-10-13 23:07:52 +00:00
|
|
|
TFM_Util.createDefaultConfiguration(CONFIG_FILE, this, getFile());
|
2011-10-12 22:45:43 +00:00
|
|
|
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(getDataFolder(), CONFIG_FILE));
|
|
|
|
|
|
|
|
allowFirePlace = config.getBoolean("allow_fire_place", allowFirePlace);
|
|
|
|
allowFireSpread = config.getBoolean("allow_fire_spread", allowFireSpread);
|
|
|
|
allowLavaDamage = config.getBoolean("allow_lava_damage", allowLavaDamage);
|
|
|
|
allowLavaPlace = config.getBoolean("allow_lava_place", allowLavaPlace);
|
|
|
|
allowWaterPlace = config.getBoolean("allow_water_place", allowWaterPlace);
|
|
|
|
allowExplosions = config.getBoolean("allow_explosions", allowExplosions);
|
|
|
|
explosiveRadius = config.getDouble("explosiveRadius", explosiveRadius);
|
|
|
|
autoEntityWipe = config.getBoolean("auto_wipe", autoEntityWipe);
|
|
|
|
nukeMonitor = config.getBoolean("nuke_monitor", nukeMonitor);
|
2011-10-18 04:08:40 +00:00
|
|
|
nukeMonitorCountBreak = config.getInt("nuke_monitor_count_break", nukeMonitorCountBreak);
|
|
|
|
nukeMonitorCountPlace = config.getInt("nuke_monitor_count_place", nukeMonitorCountPlace);
|
2011-10-12 22:45:43 +00:00
|
|
|
nukeMonitorRange = config.getDouble("nuke_monitor_range", nukeMonitorRange);
|
|
|
|
freecamTriggerCount = config.getInt("freecam_trigger_count", freecamTriggerCount);
|
|
|
|
preprocessLogEnabled = config.getBoolean("preprocess_log", preprocessLogEnabled);
|
2011-10-13 18:30:45 +00:00
|
|
|
disableNight = config.getBoolean("disable_night", disableNight);
|
2011-10-14 05:31:21 +00:00
|
|
|
disableWeather = config.getBoolean("disable_weather", disableWeather);
|
2011-10-24 02:43:52 +00:00
|
|
|
landminesEnabled = config.getBoolean("landmines_enabled", landminesEnabled);
|
|
|
|
mp44Enabled = config.getBoolean("mp44_enabled", mp44Enabled);
|
2011-10-19 02:52:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public List<String> superadmins = new ArrayList<String>();
|
|
|
|
public List<String> superadmin_ips = new ArrayList<String>();
|
|
|
|
|
|
|
|
public void loadSuperadminConfig()
|
|
|
|
{
|
|
|
|
TFM_Util.createDefaultConfiguration(SUPERADMIN_FILE, this, getFile());
|
2011-10-30 19:27:06 +00:00
|
|
|
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(getDataFolder(), SUPERADMIN_FILE));
|
2011-10-12 18:13:10 +00:00
|
|
|
|
2011-10-16 06:00:37 +00:00
|
|
|
superadmins = new ArrayList<String>();
|
|
|
|
superadmin_ips = new ArrayList<String>();
|
2011-10-30 19:27:06 +00:00
|
|
|
|
|
|
|
for (String user : config.getKeys(false))
|
2011-10-16 06:00:37 +00:00
|
|
|
{
|
2011-10-30 19:27:06 +00:00
|
|
|
superadmins.add(user.toLowerCase().trim());
|
|
|
|
|
|
|
|
List<String> user_ips = config.getStringList(user);
|
|
|
|
for (String ip : user_ips)
|
2011-10-16 06:00:37 +00:00
|
|
|
{
|
2011-10-30 19:27:06 +00:00
|
|
|
ip = ip.toLowerCase().trim();
|
|
|
|
if (!superadmin_ips.contains(ip))
|
|
|
|
{
|
|
|
|
superadmin_ips.add(ip);
|
|
|
|
}
|
2011-10-16 06:00:37 +00:00
|
|
|
}
|
|
|
|
}
|
2011-10-12 18:13:10 +00:00
|
|
|
}
|
2011-10-13 23:07:52 +00:00
|
|
|
|
2011-10-13 23:45:01 +00:00
|
|
|
private final TFM_EntityListener entityListener = new TFM_EntityListener(this);
|
|
|
|
private final TFM_BlockListener blockListener = new TFM_BlockListener(this);
|
|
|
|
private final TFM_PlayerListener playerListener = new TFM_PlayerListener(this);
|
2011-10-14 05:31:21 +00:00
|
|
|
private final TFM_WeatherListener weatherListener = new TFM_WeatherListener(this);
|
2011-10-30 19:27:06 +00:00
|
|
|
|
2011-10-02 16:15:16 +00:00
|
|
|
private void registerEventHandlers()
|
|
|
|
{
|
|
|
|
PluginManager pm = this.getServer().getPluginManager();
|
2011-10-30 19:27:06 +00:00
|
|
|
|
2011-10-02 16:15:16 +00:00
|
|
|
pm.registerEvent(Event.Type.ENTITY_EXPLODE, entityListener, Event.Priority.High, this);
|
|
|
|
pm.registerEvent(Event.Type.ENTITY_COMBUST, entityListener, Event.Priority.High, this);
|
|
|
|
pm.registerEvent(Event.Type.ENTITY_DAMAGE, entityListener, Event.Priority.High, this);
|
|
|
|
pm.registerEvent(Event.Type.EXPLOSION_PRIME, entityListener, Event.Priority.High, this);
|
|
|
|
|
|
|
|
pm.registerEvent(Event.Type.BLOCK_IGNITE, blockListener, Event.Priority.High, this);
|
|
|
|
pm.registerEvent(Event.Type.BLOCK_BURN, blockListener, Event.Priority.High, this);
|
|
|
|
pm.registerEvent(Event.Type.BLOCK_PLACE, blockListener, Event.Priority.High, this);
|
|
|
|
pm.registerEvent(Event.Type.BLOCK_BREAK, blockListener, Event.Priority.Normal, this);
|
|
|
|
|
|
|
|
pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, playerListener, Event.Priority.High, this);
|
|
|
|
pm.registerEvent(Event.Type.PLAYER_INTERACT, playerListener, Event.Priority.High, this);
|
|
|
|
pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener, Event.Priority.Normal, this);
|
|
|
|
pm.registerEvent(Event.Type.PLAYER_CHAT, playerListener, Event.Priority.Normal, this);
|
2011-10-16 06:00:37 +00:00
|
|
|
pm.registerEvent(Event.Type.PLAYER_DROP_ITEM, playerListener, Event.Priority.Normal, this);
|
|
|
|
pm.registerEvent(Event.Type.PLAYER_KICK, playerListener, Event.Priority.Monitor, this);
|
|
|
|
pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener, Event.Priority.Monitor, this);
|
2011-10-24 02:43:52 +00:00
|
|
|
pm.registerEvent(Event.Type.PLAYER_JOIN, playerListener, Event.Priority.Monitor, this);
|
2011-10-30 19:27:06 +00:00
|
|
|
|
2011-10-14 05:31:21 +00:00
|
|
|
pm.registerEvent(Event.Type.WEATHER_CHANGE, weatherListener, Event.Priority.High, this);
|
|
|
|
pm.registerEvent(Event.Type.THUNDER_CHANGE, weatherListener, Event.Priority.High, this);
|
2011-10-02 16:15:16 +00:00
|
|
|
}
|
2011-09-20 02:52:08 +00:00
|
|
|
}
|