mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-11-02 08:40:01 +01:00
Fix some reloading issues.
This commit is contained in:
parent
47f78f8b02
commit
da420ec877
@ -5,6 +5,7 @@ import java.io.InputStreamReader;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -28,6 +29,7 @@ import fr.neatmonster.nocheatplus.checks.fight.FightListener;
|
|||||||
import fr.neatmonster.nocheatplus.checks.inventory.InventoryListener;
|
import fr.neatmonster.nocheatplus.checks.inventory.InventoryListener;
|
||||||
import fr.neatmonster.nocheatplus.checks.moving.MovingListener;
|
import fr.neatmonster.nocheatplus.checks.moving.MovingListener;
|
||||||
import fr.neatmonster.nocheatplus.command.CommandHandler;
|
import fr.neatmonster.nocheatplus.command.CommandHandler;
|
||||||
|
import fr.neatmonster.nocheatplus.command.INotifyReload;
|
||||||
import fr.neatmonster.nocheatplus.config.ConfPaths;
|
import fr.neatmonster.nocheatplus.config.ConfPaths;
|
||||||
import fr.neatmonster.nocheatplus.config.ConfigFile;
|
import fr.neatmonster.nocheatplus.config.ConfigFile;
|
||||||
import fr.neatmonster.nocheatplus.config.ConfigManager;
|
import fr.neatmonster.nocheatplus.config.ConfigManager;
|
||||||
@ -55,12 +57,27 @@ public class NoCheatPlus extends JavaPlugin implements Listener {
|
|||||||
/** The event listeners. */
|
/** The event listeners. */
|
||||||
private final List<Listener> listeners = new ArrayList<Listener>();
|
private final List<Listener> listeners = new ArrayList<Listener>();
|
||||||
|
|
||||||
|
/** Components that need notification on reloading.
|
||||||
|
* (Kept here, for if during runtime some might get added.)*/
|
||||||
|
private final List<INotifyReload> notifyReload = new LinkedList<INotifyReload>();
|
||||||
|
|
||||||
/** Is the configuration outdated? */
|
/** Is the configuration outdated? */
|
||||||
private boolean configOutdated = false;
|
private boolean configOutdated = false;
|
||||||
|
|
||||||
/** Is a new update available? */
|
/** Is a new update available? */
|
||||||
private boolean updateAvailable = false;
|
private boolean updateAvailable = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience method to add to listeners and notifyReload lists.
|
||||||
|
* @param listener
|
||||||
|
*/
|
||||||
|
private void addListener(final Listener listener){
|
||||||
|
listeners.add(listener);
|
||||||
|
if (listener instanceof INotifyReload){
|
||||||
|
notifyReload.add((INotifyReload) listener);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.bukkit.plugin.java.JavaPlugin#onDisable()
|
* @see org.bukkit.plugin.java.JavaPlugin#onDisable()
|
||||||
*/
|
*/
|
||||||
@ -78,15 +95,18 @@ public class NoCheatPlus extends JavaPlugin implements Listener {
|
|||||||
// Stop the lag measuring task.
|
// Stop the lag measuring task.
|
||||||
LagMeasureTask.cancel();
|
LagMeasureTask.cancel();
|
||||||
|
|
||||||
|
// Remove listeners.
|
||||||
|
listeners.clear();
|
||||||
|
|
||||||
|
// Remove config listeners.
|
||||||
|
notifyReload.clear();
|
||||||
|
|
||||||
// Cleanup the configuration manager.
|
// Cleanup the configuration manager.
|
||||||
ConfigManager.cleanup();
|
ConfigManager.cleanup();
|
||||||
|
|
||||||
// Just to be sure nothing gets left out.
|
// Just to be sure nothing gets left out.
|
||||||
getServer().getScheduler().cancelTasks(this);
|
getServer().getScheduler().cancelTasks(this);
|
||||||
|
|
||||||
// Remove listeners.
|
|
||||||
listeners.clear();
|
|
||||||
|
|
||||||
// Tell the server administrator the we finished unloading NoCheatPlus.
|
// Tell the server administrator the we finished unloading NoCheatPlus.
|
||||||
System.out.println("[NoCheatPlus] Version " + pdfFile.getVersion() + " is disabled.");
|
System.out.println("[NoCheatPlus] Version " + pdfFile.getVersion() + " is disabled.");
|
||||||
}
|
}
|
||||||
@ -108,14 +128,18 @@ public class NoCheatPlus extends JavaPlugin implements Listener {
|
|||||||
|
|
||||||
// List the events listeners.
|
// List the events listeners.
|
||||||
listeners.clear();
|
listeners.clear();
|
||||||
listeners.add(new BlockBreakListener());
|
for (final Listener listener : new Listener[]{
|
||||||
listeners.add(new BlockInteractListener());
|
new BlockBreakListener(),
|
||||||
listeners.add(new BlockPlaceListener());
|
new BlockInteractListener(),
|
||||||
listeners.add(new ChatListener());
|
new BlockPlaceListener(),
|
||||||
listeners.add(new FightListener());
|
new ChatListener(),
|
||||||
listeners.add(new InventoryListener());
|
new FightListener(),
|
||||||
listeners.add(new MovingListener());
|
new InventoryListener(),
|
||||||
listeners.add(new Workarounds());
|
new MovingListener(),
|
||||||
|
new Workarounds(),
|
||||||
|
}){
|
||||||
|
addListener(listener);
|
||||||
|
}
|
||||||
|
|
||||||
// Set up a task to monitor server lag.
|
// Set up a task to monitor server lag.
|
||||||
LagMeasureTask.start(this);
|
LagMeasureTask.start(this);
|
||||||
@ -126,7 +150,7 @@ public class NoCheatPlus extends JavaPlugin implements Listener {
|
|||||||
Bukkit.getPluginManager().registerEvents(this, this);
|
Bukkit.getPluginManager().registerEvents(this, this);
|
||||||
|
|
||||||
// Register the commands handler.
|
// Register the commands handler.
|
||||||
getCommand("nocheatplus").setExecutor(new CommandHandler(this));
|
getCommand("nocheatplus").setExecutor(new CommandHandler(this, notifyReload));
|
||||||
|
|
||||||
ConfigFile config = ConfigManager.getConfigFile();
|
ConfigFile config = ConfigManager.getConfigFile();
|
||||||
|
|
||||||
@ -337,4 +361,5 @@ public class NoCheatPlus extends JavaPlugin implements Listener {
|
|||||||
if (!message.equals(""))
|
if (!message.equals(""))
|
||||||
player.sendMessage(message);
|
player.sendMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import org.bukkit.event.player.PlayerLoginEvent.Result;
|
|||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
|
|
||||||
import fr.neatmonster.nocheatplus.checks.chat.analysis.ds.SimpleCharPrefixTree;
|
import fr.neatmonster.nocheatplus.checks.chat.analysis.ds.SimpleCharPrefixTree;
|
||||||
|
import fr.neatmonster.nocheatplus.command.INotifyReload;
|
||||||
import fr.neatmonster.nocheatplus.config.ConfPaths;
|
import fr.neatmonster.nocheatplus.config.ConfPaths;
|
||||||
import fr.neatmonster.nocheatplus.config.ConfigFile;
|
import fr.neatmonster.nocheatplus.config.ConfigFile;
|
||||||
import fr.neatmonster.nocheatplus.config.ConfigManager;
|
import fr.neatmonster.nocheatplus.config.ConfigManager;
|
||||||
@ -31,7 +32,7 @@ import fr.neatmonster.nocheatplus.players.Permissions;
|
|||||||
*
|
*
|
||||||
* @see ChatEvent
|
* @see ChatEvent
|
||||||
*/
|
*/
|
||||||
public class ChatListener implements Listener {
|
public class ChatListener implements Listener, INotifyReload {
|
||||||
|
|
||||||
/** The color check. */
|
/** The color check. */
|
||||||
private final Color color = new Color();
|
private final Color color = new Color();
|
||||||
@ -47,12 +48,18 @@ public class ChatListener implements Listener {
|
|||||||
private final SimpleCharPrefixTree chatCommands = new SimpleCharPrefixTree();
|
private final SimpleCharPrefixTree chatCommands = new SimpleCharPrefixTree();
|
||||||
|
|
||||||
public ChatListener(){
|
public ChatListener(){
|
||||||
// Read some things from the global config file.
|
|
||||||
ConfigFile config = ConfigManager.getConfigFile();
|
ConfigFile config = ConfigManager.getConfigFile();
|
||||||
commandExclusions.feedAll(config.getStringList(ConfPaths.CHAT_NOPWNAGE_EXCLUSIONS), false, true);
|
initFilters(config);
|
||||||
chatCommands.feedAll(config.getStringList(ConfPaths.CHAT_GLOBALCHAT_COMMANDS), false, true);
|
// (globalChat inits in constructor.)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initFilters(ConfigFile config) {
|
||||||
|
commandExclusions.clear();
|
||||||
|
commandExclusions.feedAll(config.getStringList(ConfPaths.CHAT_NOPWNAGE_EXCLUSIONS), false, true);
|
||||||
|
chatCommands.clear();
|
||||||
|
chatCommands.feedAll(config.getStringList(ConfPaths.CHAT_GLOBALCHAT_COMMANDS), false, true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We listen to PlayerChat events for obvious reasons.
|
* We listen to PlayerChat events for obvious reasons.
|
||||||
*
|
*
|
||||||
@ -195,4 +202,13 @@ public class ChatListener implements Listener {
|
|||||||
*/
|
*/
|
||||||
ChatData.getData(event.getPlayer()).noPwnageLastMovedTime = System.currentTimeMillis();
|
ChatData.getData(event.getPlayer()).noPwnageLastMovedTime = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReload() {
|
||||||
|
// Read some things from the global config file.
|
||||||
|
ConfigFile config = ConfigManager.getConfigFile();
|
||||||
|
initFilters(config);
|
||||||
|
globalChat.onReload();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import fr.neatmonster.nocheatplus.checks.CheckType;
|
|||||||
import fr.neatmonster.nocheatplus.checks.chat.analysis.MessageLetterCount;
|
import fr.neatmonster.nocheatplus.checks.chat.analysis.MessageLetterCount;
|
||||||
import fr.neatmonster.nocheatplus.checks.chat.analysis.WordLetterCount;
|
import fr.neatmonster.nocheatplus.checks.chat.analysis.WordLetterCount;
|
||||||
import fr.neatmonster.nocheatplus.checks.chat.analysis.engine.LetterEngine;
|
import fr.neatmonster.nocheatplus.checks.chat.analysis.engine.LetterEngine;
|
||||||
|
import fr.neatmonster.nocheatplus.command.INotifyReload;
|
||||||
import fr.neatmonster.nocheatplus.config.ConfigFile;
|
import fr.neatmonster.nocheatplus.config.ConfigFile;
|
||||||
import fr.neatmonster.nocheatplus.config.ConfigManager;
|
import fr.neatmonster.nocheatplus.config.ConfigManager;
|
||||||
import fr.neatmonster.nocheatplus.hooks.NCPExemptionManager;
|
import fr.neatmonster.nocheatplus.hooks.NCPExemptionManager;
|
||||||
@ -16,15 +17,13 @@ import fr.neatmonster.nocheatplus.hooks.NCPExemptionManager;
|
|||||||
* @author mc_dev
|
* @author mc_dev
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class GlobalChat extends Check{
|
public class GlobalChat extends Check implements INotifyReload{
|
||||||
|
|
||||||
private final LetterEngine engine;
|
private LetterEngine engine;
|
||||||
|
|
||||||
public GlobalChat() {
|
public GlobalChat() {
|
||||||
super(CheckType.CHAT_GLOBALCHAT);
|
super(CheckType.CHAT_GLOBALCHAT);
|
||||||
// Set some things from the global config.
|
onReload();
|
||||||
ConfigFile config = ConfigManager.getConfigFile();
|
|
||||||
engine = new LetterEngine(config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -52,6 +51,14 @@ public class GlobalChat extends Check{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReload() {
|
||||||
|
// Set some things from the global config.
|
||||||
|
ConfigFile config = ConfigManager.getConfigFile();
|
||||||
|
engine = new LetterEngine(config);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check without further synchronization.
|
* Check without further synchronization.
|
||||||
* @param player
|
* @param player
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package fr.neatmonster.nocheatplus.command;
|
package fr.neatmonster.nocheatplus.command;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -74,13 +75,13 @@ public class CommandHandler implements CommandExecutor {
|
|||||||
* @param plugin
|
* @param plugin
|
||||||
* the instance of NoCheatPlus
|
* the instance of NoCheatPlus
|
||||||
*/
|
*/
|
||||||
public CommandHandler(final NoCheatPlus plugin) {
|
public CommandHandler(final NoCheatPlus plugin, final Collection<INotifyReload> notifyReload) {
|
||||||
// Register sub commands:
|
// Register sub commands:
|
||||||
for (NCPCommand cmd : new NCPCommand[]{
|
for (NCPCommand cmd : new NCPCommand[]{
|
||||||
new BanCommand(plugin),
|
new BanCommand(plugin),
|
||||||
new InfoCommand(plugin),
|
new InfoCommand(plugin),
|
||||||
new KickCommand(plugin),
|
new KickCommand(plugin),
|
||||||
new ReloadCommand(plugin),
|
new ReloadCommand(plugin, notifyReload),
|
||||||
new TellCommand(plugin),
|
new TellCommand(plugin),
|
||||||
new DelayCommand(plugin),
|
new DelayCommand(plugin),
|
||||||
}){
|
}){
|
||||||
|
10
src/fr/neatmonster/nocheatplus/command/INotifyReload.java
Normal file
10
src/fr/neatmonster/nocheatplus/command/INotifyReload.java
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package fr.neatmonster.nocheatplus.command;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for a component that needs to be notified about a reload.
|
||||||
|
* @author mc_dev
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public interface INotifyReload {
|
||||||
|
public void onReload();
|
||||||
|
}
|
@ -1,5 +1,7 @@
|
|||||||
package fr.neatmonster.nocheatplus.command;
|
package fr.neatmonster.nocheatplus.command;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -18,8 +20,12 @@ import fr.neatmonster.nocheatplus.players.Permissions;
|
|||||||
|
|
||||||
public class ReloadCommand extends NCPCommand {
|
public class ReloadCommand extends NCPCommand {
|
||||||
|
|
||||||
public ReloadCommand(NoCheatPlus plugin) {
|
/** Components that need to be notified on reload */
|
||||||
|
private final Collection<INotifyReload> notifyReload;
|
||||||
|
|
||||||
|
public ReloadCommand(NoCheatPlus plugin, Collection<INotifyReload> notifyReload) {
|
||||||
super(plugin, "reload", Permissions.ADMINISTRATION_RELOAD);
|
super(plugin, "reload", Permissions.ADMINISTRATION_RELOAD);
|
||||||
|
this.notifyReload = notifyReload;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -51,6 +57,11 @@ public class ReloadCommand extends NCPCommand {
|
|||||||
InventoryConfig.clear();
|
InventoryConfig.clear();
|
||||||
MovingConfig.clear();
|
MovingConfig.clear();
|
||||||
|
|
||||||
|
// Tell the plugin to adapt to new config.
|
||||||
|
for (INotifyReload component : notifyReload){
|
||||||
|
component.onReload();
|
||||||
|
}
|
||||||
|
|
||||||
// Say to the other plugins that we've reloaded the configuration.
|
// Say to the other plugins that we've reloaded the configuration.
|
||||||
Bukkit.getPluginManager().callEvent(new NCPReloadEvent());
|
Bukkit.getPluginManager().callEvent(new NCPReloadEvent());
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user