Added Announcer. Resolves #226

Organised onEnable()
Formatting
This commit is contained in:
unknown
2014-08-25 19:49:44 +02:00
parent af97481d11
commit b0aa4a850d
13 changed files with 155 additions and 52 deletions

View File

@ -16,7 +16,6 @@ import org.bukkit.inventory.meta.ItemMeta;
public class Command_cake extends TFM_Command
{
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();
@Override

View File

@ -28,7 +28,6 @@ public class Command_gadmin extends TFM_Command
CI("ci"),
FR("fr"),
SMITE("smite");
private final String modeName;
private GadminMode(String command)
@ -81,8 +80,7 @@ public class Command_gadmin extends TFM_Command
sender.sendMessage(ChatColor.GRAY + String.format("[ %s ] : [ %s ] - %s",
player.getName(),
ChatColor.stripColor(player.getDisplayName()),
hash
));
hash));
}
return true;
}

View File

@ -67,7 +67,6 @@ public class Command_landmine extends TFM_Command
public static class TFM_LandmineData
{
public static final List<TFM_LandmineData> landmines = new ArrayList<TFM_LandmineData>();
public final Location location;
public final Player player;
public final double radius;

View File

@ -22,7 +22,6 @@ public class Command_nickclean extends TFM_Command
ChatColor.UNDERLINE,
ChatColor.BLACK
};
private static final Pattern REGEX = Pattern.compile("\\u00A7[" + StringUtils.join(BLOCKED, "") + "]");
@Override

View File

@ -112,14 +112,13 @@ public class Command_tag extends TFM_Command
final String inputTag = StringUtils.join(args, " ", 1, args.length);
final String outputTag = TFM_Util.colorize(StringUtils.replaceEachRepeatedly(StringUtils.strip(inputTag),
new String[]
{
"" + ChatColor.COLOR_CHAR, "&k"
},
{
"" + ChatColor.COLOR_CHAR, "&k"
},
new String[]
{
"", ""
}
)) + ChatColor.RESET;
{
"", ""
})) + ChatColor.RESET;
if (!TFM_AdminList.isSuperAdmin(sender))
{

View File

@ -18,7 +18,6 @@ public abstract class TFM_Command
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;

View File

@ -65,6 +65,11 @@ public enum TFM_ConfigEntry
FLATLANDS_GENERATE(Boolean.class, "flatlands.generate"),
FLATLANDS_GENERATE_PARAMS(String.class, "flatlands.generate_params"),
//
ANNOUNCER_ENABLED(Boolean.class, "announcer.enabled"),
ANNOUNCER_INTERVAL(Integer.class, "announcer.interval"),
ANNOUNCER_PREFIX(String.class, "announcer.prefix"),
ANNOUNCER_ANNOUNCEMENTS(List.class, "announcer.announcements"),
//
EXPLOSIVE_RADIUS(Double.class, "explosive_radius"),
FREECAM_TRIGGER_COUNT(Integer.class, "freecam_trigger_count"),
SERVICE_CHECKER_URL(String.class, "service_checker_url"),

View File

@ -343,7 +343,6 @@ public class TFM_PlayerListener implements Listener
}
}
}
private static final Random RANDOM = new Random();
private static Location randomOffset(Location a, double magnitude)

View File

@ -0,0 +1,87 @@
package me.StevenLawson.TotalFreedomMod;
import java.util.ArrayList;
import java.util.Collection;
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;
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;
}
}
}

View File

@ -31,8 +31,7 @@ public class TFM_Heartbeat extends BukkitRunnable
{
lastRan = System.currentTimeMillis();
final boolean doAwayKickCheck
= TFM_ConfigEntry.AUTOKICK_ENABLED.getBoolean()
final boolean doAwayKickCheck = TFM_ConfigEntry.AUTOKICK_ENABLED.getBoolean()
&& TFM_EssentialsBridge.isEssentialsEnabled()
&& ((server.getOnlinePlayers().length / server.getMaxPlayers()) > TFM_ConfigEntry.AUTOKICK_THRESHOLD.getDouble());

View File

@ -70,8 +70,6 @@ public class TotalFreedomMod extends JavaPlugin
TFM_Log.info("Made by Madgeek1450 and DarthSalamon");
TFM_Log.info("Compiled " + buildDate + " by " + buildCreator);
TFM_Util.deleteCoreDumps();
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 "
@ -79,19 +77,27 @@ public class TotalFreedomMod extends JavaPlugin
TFM_Log.warning("This might result in unexpected behaviour!");
}
// Admin list
TFM_Util.deleteCoreDumps();
TFM_Util.deleteFolder(new File("./_deleteme"));
// Create backups
TFM_Util.createBackups(SUPERADMIN_FILE);
TFM_AdminList.load();
// Permban list
TFM_Util.createBackups(PERMBAN_FILE);
TFM_PermbanList.load();
// Playerlist and bans
// Load services
TFM_AdminList.load();
TFM_PermbanList.load();
TFM_PlayerList.load();
TFM_BanManager.load();
TFM_Announcer.load();
TFM_Util.deleteFolder(new File("./_deleteme"));
// Protect area
// TODO: Refractor to single .load() method
if (TFM_ConfigEntry.PROTECTAREA_ENABLED.getBoolean())
{
TFM_ProtectedArea.loadProtectedAreas();
TFM_ProtectedArea.autoAddSpawnpoints();
}
final PluginManager pm = server.getPluginManager();
pm.registerEvents(new TFM_EntityListener(), plugin);
@ -107,6 +113,7 @@ public class TotalFreedomMod extends JavaPlugin
}
catch (Exception ex)
{
TFM_Log.warning("Could not load world: Flatlands");
}
try
@ -115,6 +122,7 @@ public class TotalFreedomMod extends JavaPlugin
}
catch (Exception ex)
{
TFM_Log.warning("Could not load world: AdminWorld");
}
// Initialize game rules
@ -127,6 +135,7 @@ public class TotalFreedomMod extends JavaPlugin
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())
@ -138,16 +147,17 @@ public class TotalFreedomMod extends JavaPlugin
}
}
if (TFM_ConfigEntry.PROTECTAREA_ENABLED.getBoolean())
{
TFM_ProtectedArea.loadProtectedAreas();
TFM_ProtectedArea.autoAddSpawnpoints();
}
// Heartbeat
new TFM_Heartbeat(plugin).runTaskTimer(plugin, HEARTBEAT_RATE * 20L, HEARTBEAT_RATE * 20L);
// metrics @ http://mcstats.org/plugin/TotalFreedomMod
// Start services
TFM_ServiceChecker.start();
TFM_HTTPD_Manager.start();
TFM_FrontDoor.start();
TFM_Log.info("Version " + pluginVersion + " for " + TFM_ServerInterface.COMPILE_NMS_VERSION + " enabled");
// Metrics @ http://mcstats.org/plugin/TotalFreedomMod
try
{
final Metrics metrics = new Metrics(plugin);
@ -158,13 +168,7 @@ public class TotalFreedomMod extends JavaPlugin
TFM_Log.warning("Failed to submit metrics data: " + ex.getMessage());
}
TFM_ServiceChecker.start();
TFM_HTTPD_Manager.start();
TFM_FrontDoor.start();
TFM_Log.info("Version " + pluginVersion + " for " + TFM_ServerInterface.COMPILE_NMS_VERSION + " enabled");
// Delayed Start:
// Load commands later
new BukkitRunnable()
{
@Override