mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-11-27 13:15:52 +01:00
Attempt to restore compatibility with MCPC/Cauldron
Addresses aadnk#90, aadnk#83, and aadnk#71
This commit is contained in:
parent
92fabb31b2
commit
b32d0d5fcd
@ -42,12 +42,10 @@ class CommandProtocol extends CommandBase {
|
|||||||
public static final String NAME = "protocol";
|
public static final String NAME = "protocol";
|
||||||
|
|
||||||
private Plugin plugin;
|
private Plugin plugin;
|
||||||
private ProtocolConfig config;
|
|
||||||
|
|
||||||
public CommandProtocol(ErrorReporter reporter, Plugin plugin, ProtocolConfig config) {
|
public CommandProtocol(ErrorReporter reporter, Plugin plugin) {
|
||||||
super(reporter, CommandBase.PERMISSION_ADMIN, NAME, 1);
|
super(reporter, CommandBase.PERMISSION_ADMIN, NAME, 1);
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.config = config;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -140,16 +138,6 @@ class CommandProtocol extends CommandBase {
|
|||||||
sender.sendMessage(ChatColor.WHITE + "Issues: " + ChatColor.GREEN + "https://github.com/dmulloy2/ProtocolLib/issues");
|
sender.sendMessage(ChatColor.WHITE + "Issues: " + ChatColor.GREEN + "https://github.com/dmulloy2/ProtocolLib/issues");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Prevent further automatic updates until the next delay.
|
|
||||||
*/
|
|
||||||
public void updateFinished() {
|
|
||||||
long currentTime = System.currentTimeMillis() / ProtocolLibrary.MILLI_PER_SECOND;
|
|
||||||
|
|
||||||
config.setAutoLastTime(currentTime);
|
|
||||||
config.saveAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void reloadConfiguration(CommandSender sender) {
|
public void reloadConfiguration(CommandSender sender) {
|
||||||
plugin.reloadConfig();
|
plugin.reloadConfig();
|
||||||
sender.sendMessage(ChatColor.YELLOW + "Reloaded configuration!");
|
sender.sendMessage(ChatColor.YELLOW + "Reloaded configuration!");
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*
|
/**
|
||||||
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
|
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
|
||||||
* Copyright (C) 2012 Kristian S. Stangeland
|
* Copyright (C) 2012 Kristian S. Stangeland
|
||||||
*
|
*
|
||||||
@ -14,11 +14,10 @@
|
|||||||
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
* 02111-1307 USA
|
* 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.comphenix.protocol;
|
package com.comphenix.protocol;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.configuration.Configuration;
|
import org.bukkit.configuration.Configuration;
|
||||||
@ -26,10 +25,8 @@ import org.bukkit.configuration.ConfigurationSection;
|
|||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import com.comphenix.protocol.injector.PacketFilterManager.PlayerInjectHooks;
|
import com.comphenix.protocol.injector.PacketFilterManager.PlayerInjectHooks;
|
||||||
import com.google.common.base.Charsets;
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.io.Files;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the configuration of ProtocolLib.
|
* Represents the configuration of ProtocolLib.
|
||||||
@ -37,237 +34,123 @@ import com.google.common.io.Files;
|
|||||||
* @author Kristian
|
* @author Kristian
|
||||||
*/
|
*/
|
||||||
public class ProtocolConfig {
|
public class ProtocolConfig {
|
||||||
private static final String LAST_UPDATE_FILE = "lastupdate";
|
|
||||||
|
|
||||||
private static final String SECTION_GLOBAL = "global";
|
private static final String SECTION_GLOBAL = "global";
|
||||||
private static final String SECTION_AUTOUPDATER = "auto updater";
|
|
||||||
|
|
||||||
private static final String METRICS_ENABLED = "metrics";
|
private static final String METRICS_ENABLED = "metrics";
|
||||||
|
|
||||||
private static final String IGNORE_VERSION_CHECK = "ignore version check";
|
private static final String IGNORE_VERSION_CHECK = "ignore version check";
|
||||||
private static final String BACKGROUND_COMPILER_ENABLED = "background compiler";
|
private static final String BACKGROUND_COMPILER_ENABLED = "background compiler";
|
||||||
|
|
||||||
private static final String DEBUG_MODE_ENABLED = "debug";
|
private static final String DEBUG_MODE_ENABLED = "debug";
|
||||||
private static final String DETAILED_ERROR = "detailed error";
|
private static final String DETAILED_ERROR = "detailed error";
|
||||||
private static final String INJECTION_METHOD = "injection method";
|
private static final String INJECTION_METHOD = "injection method";
|
||||||
|
|
||||||
private static final String SCRIPT_ENGINE_NAME = "script engine";
|
private static final String SCRIPT_ENGINE_NAME = "script engine";
|
||||||
private static final String SUPPRESSED_REPORTS = "suppressed reports";
|
private static final String SUPPRESSED_REPORTS = "suppressed reports";
|
||||||
|
|
||||||
private static final String UPDATER_NOTIFY = "notify";
|
|
||||||
private static final String UPDATER_DOWNLAD = "download";
|
|
||||||
private static final String UPDATER_DELAY = "delay";
|
|
||||||
|
|
||||||
// Defaults
|
|
||||||
private static final long DEFAULT_UPDATER_DELAY = 43200;
|
|
||||||
|
|
||||||
private Plugin plugin;
|
private Plugin plugin;
|
||||||
private Configuration config;
|
private Configuration config;
|
||||||
private boolean loadingSections;
|
|
||||||
|
|
||||||
private ConfigurationSection global;
|
private ConfigurationSection global;
|
||||||
private ConfigurationSection updater;
|
|
||||||
|
|
||||||
// Last update time
|
|
||||||
private long lastUpdateTime;
|
|
||||||
private boolean configChanged;
|
private boolean configChanged;
|
||||||
private boolean valuesChanged;
|
|
||||||
|
|
||||||
// Modifications
|
// Modifications
|
||||||
private int modCount;
|
private int modCount;
|
||||||
|
|
||||||
public ProtocolConfig(Plugin plugin) {
|
public ProtocolConfig(Plugin plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
reloadConfig();
|
reloadConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reload configuration file.
|
* Reload configuration file.
|
||||||
*/
|
*/
|
||||||
public void reloadConfig() {
|
public void reloadConfig() {
|
||||||
// Reset
|
// Reset
|
||||||
configChanged = false;
|
configChanged = false;
|
||||||
valuesChanged = false;
|
|
||||||
modCount++;
|
modCount++;
|
||||||
|
|
||||||
this.config = plugin.getConfig();
|
this.config = plugin.getConfig();
|
||||||
this.lastUpdateTime = loadLastUpdate();
|
|
||||||
loadSections(!loadingSections);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load the last update time stamp from the file system.
|
|
||||||
* @return Last update time stamp.
|
|
||||||
*/
|
|
||||||
private long loadLastUpdate() {
|
|
||||||
File dataFile = getLastUpdateFile();
|
|
||||||
|
|
||||||
if (dataFile.exists()) {
|
|
||||||
try {
|
|
||||||
return Long.parseLong(Files.toString(dataFile, Charsets.UTF_8));
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
plugin.getLogger().warning("Cannot parse " + dataFile + " as a number.");
|
|
||||||
} catch (IOException e) {
|
|
||||||
plugin.getLogger().warning("Cannot read " + dataFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Default last update
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Store the given time stamp.
|
|
||||||
* @param value - time stamp to store.
|
|
||||||
*/
|
|
||||||
private void saveLastUpdate(long value) {
|
|
||||||
File dataFile = getLastUpdateFile();
|
|
||||||
|
|
||||||
// The data folder must exist
|
|
||||||
dataFile.getParentFile().mkdirs();
|
|
||||||
|
|
||||||
if (dataFile.exists())
|
|
||||||
dataFile.delete();
|
|
||||||
|
|
||||||
try {
|
|
||||||
Files.write(Long.toString(value), dataFile, Charsets.UTF_8);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException("Cannot write " + dataFile, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve the file that is used to store the update time stamp.
|
|
||||||
* @return File storing the update time stamp.
|
|
||||||
*/
|
|
||||||
private File getLastUpdateFile() {
|
|
||||||
return new File(plugin.getDataFolder(), LAST_UPDATE_FILE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load data sections.
|
|
||||||
* @param copyDefaults - whether or not to copy configuration defaults.
|
|
||||||
*/
|
|
||||||
private void loadSections(boolean copyDefaults) {
|
|
||||||
if (config != null) {
|
if (config != null) {
|
||||||
|
config.options().copyDefaults(true);
|
||||||
global = config.getConfigurationSection(SECTION_GLOBAL);
|
global = config.getConfigurationSection(SECTION_GLOBAL);
|
||||||
}
|
}
|
||||||
if (global != null) {
|
|
||||||
updater = global.getConfigurationSection(SECTION_AUTOUPDATER);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Automatically copy defaults
|
|
||||||
if (copyDefaults && (!getFile().exists() || global == null || updater == null)) {
|
|
||||||
loadingSections = true;
|
|
||||||
|
|
||||||
if (config != null)
|
|
||||||
config.options().copyDefaults(true);
|
|
||||||
plugin.saveDefaultConfig();
|
|
||||||
plugin.reloadConfig();
|
|
||||||
loadingSections = false;
|
|
||||||
|
|
||||||
// Inform the user
|
|
||||||
ProtocolLibrary.log("Created default configuration.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set a particular configuration key value pair.
|
|
||||||
* @param section - the configuration root.
|
|
||||||
* @param path - the path to the key.
|
|
||||||
* @param value - the value to set.
|
|
||||||
*/
|
|
||||||
private void setConfig(ConfigurationSection section, String path, Object value) {
|
private void setConfig(ConfigurationSection section, String path, Object value) {
|
||||||
configChanged = true;
|
configChanged = true;
|
||||||
section.set(path, value);
|
section.set(path, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private <T> T getGlobalValue(String name, T def) {
|
||||||
|
try {
|
||||||
|
return (T) global.get(name, def);
|
||||||
|
} catch (Throwable ex) {
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a reference to the configuration file.
|
* Retrieve a reference to the configuration file.
|
||||||
|
*
|
||||||
* @return Configuration file on disk.
|
* @return Configuration file on disk.
|
||||||
*/
|
*/
|
||||||
public File getFile() {
|
public File getFile() {
|
||||||
return new File(plugin.getDataFolder(), "config.yml");
|
return new File(plugin.getDataFolder(), "config.yml");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if detailed error reporting is enabled. Default FALSE.
|
* Determine if detailed error reporting is enabled. Default FALSE.
|
||||||
|
*
|
||||||
* @return TRUE if it is enabled, FALSE otherwise.
|
* @return TRUE if it is enabled, FALSE otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean isDetailedErrorReporting() {
|
public boolean isDetailedErrorReporting() {
|
||||||
return global.getBoolean(DETAILED_ERROR, false);
|
return getGlobalValue(DETAILED_ERROR, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set whether or not detailed error reporting is enabled.
|
* Set whether or not detailed error reporting is enabled.
|
||||||
|
*
|
||||||
* @param value - TRUE if it is enabled, FALSE otherwise.
|
* @param value - TRUE if it is enabled, FALSE otherwise.
|
||||||
*/
|
*/
|
||||||
public void setDetailedErrorReporting(boolean value) {
|
public void setDetailedErrorReporting(boolean value) {
|
||||||
global.set(DETAILED_ERROR, value);
|
global.set(DETAILED_ERROR, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve whether or not ProtocolLib should determine if a new version has been released.
|
|
||||||
* @return TRUE if it should do this automatically, FALSE otherwise.
|
|
||||||
*/
|
|
||||||
public boolean isAutoNotify() {
|
|
||||||
return updater.getBoolean(UPDATER_NOTIFY, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set whether or not ProtocolLib should determine if a new version has been released.
|
|
||||||
* @param value - TRUE to do this automatically, FALSE otherwise.
|
|
||||||
*/
|
|
||||||
public void setAutoNotify(boolean value) {
|
|
||||||
setConfig(updater, UPDATER_NOTIFY, value);
|
|
||||||
modCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve whether or not ProtocolLib should automatically download the new version.
|
|
||||||
* @return TRUE if it should, FALSE otherwise.
|
|
||||||
*/
|
|
||||||
public boolean isAutoDownload() {
|
|
||||||
return updater != null && updater.getBoolean(UPDATER_DOWNLAD, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set whether or not ProtocolLib should automatically download the new version.
|
|
||||||
* @param value - TRUE if it should. FALSE otherwise.
|
|
||||||
*/
|
|
||||||
public void setAutoDownload(boolean value) {
|
|
||||||
setConfig(updater, UPDATER_DOWNLAD, value);
|
|
||||||
modCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine whether or not debug mode is enabled.
|
* Determine whether or not debug mode is enabled.
|
||||||
* <p>
|
* <p>
|
||||||
* This grants access to the filter command.
|
* This grants access to the filter command.
|
||||||
|
*
|
||||||
* @return TRUE if it is, FALSE otherwise.
|
* @return TRUE if it is, FALSE otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean isDebug() {
|
public boolean isDebug() {
|
||||||
return global.getBoolean(DEBUG_MODE_ENABLED, false);
|
return getGlobalValue(DEBUG_MODE_ENABLED, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set whether or not debug mode is enabled.
|
* Set whether or not debug mode is enabled.
|
||||||
|
*
|
||||||
* @param value - TRUE if it is enabled, FALSE otherwise.
|
* @param value - TRUE if it is enabled, FALSE otherwise.
|
||||||
*/
|
*/
|
||||||
public void setDebug(boolean value) {
|
public void setDebug(boolean value) {
|
||||||
setConfig(global, DEBUG_MODE_ENABLED, value);
|
setConfig(global, DEBUG_MODE_ENABLED, value);
|
||||||
modCount++;
|
modCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve an immutable list of every suppressed report type.
|
* Retrieve an immutable list of every suppressed report type.
|
||||||
|
*
|
||||||
* @return Every suppressed report type.
|
* @return Every suppressed report type.
|
||||||
*/
|
*/
|
||||||
public ImmutableList<String> getSuppressedReports() {
|
public ImmutableList<String> getSuppressedReports() {
|
||||||
return ImmutableList.copyOf(global.getStringList(SUPPRESSED_REPORTS));
|
return ImmutableList.copyOf(getGlobalValue(SUPPRESSED_REPORTS, new ArrayList<String>()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the list of suppressed report types,
|
* Set the list of suppressed report types,
|
||||||
|
*
|
||||||
* @param reports - suppressed report types.
|
* @param reports - suppressed report types.
|
||||||
*/
|
*/
|
||||||
public void setSuppressedReports(List<String> reports) {
|
public void setSuppressedReports(List<String> reports) {
|
||||||
@ -275,42 +158,19 @@ public class ProtocolConfig {
|
|||||||
modCount++;
|
modCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve the amount of time to wait until checking for a new update.
|
|
||||||
* @return The amount of time to wait.
|
|
||||||
*/
|
|
||||||
public long getAutoDelay() {
|
|
||||||
// Note that the delay must be greater than 59 seconds
|
|
||||||
return Math.max(updater.getInt(UPDATER_DELAY, 0), DEFAULT_UPDATER_DELAY);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the amount of time to wait until checking for a new update.
|
|
||||||
* <p>
|
|
||||||
* This time must be greater than 59 seconds.
|
|
||||||
* @param delaySeconds - the amount of time to wait.
|
|
||||||
*/
|
|
||||||
public void setAutoDelay(long delaySeconds) {
|
|
||||||
// Silently fix the delay
|
|
||||||
if (delaySeconds < DEFAULT_UPDATER_DELAY)
|
|
||||||
delaySeconds = DEFAULT_UPDATER_DELAY;
|
|
||||||
setConfig(updater, UPDATER_DELAY, delaySeconds);
|
|
||||||
modCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The version of Minecraft to ignore the built-in safety feature.
|
* The version of Minecraft to ignore the built-in safety feature.
|
||||||
|
*
|
||||||
* @return The version to ignore ProtocolLib's satefy.
|
* @return The version to ignore ProtocolLib's satefy.
|
||||||
*/
|
*/
|
||||||
public String getIgnoreVersionCheck() {
|
public String getIgnoreVersionCheck() {
|
||||||
return global.getString(IGNORE_VERSION_CHECK, "");
|
return getGlobalValue(IGNORE_VERSION_CHECK, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets under which version of Minecraft the version safety feature will be ignored.
|
* Sets under which version of Minecraft the version safety feature will be ignored.
|
||||||
* <p>
|
* <p>
|
||||||
* This is useful if a server operator has tested and verified that a version of ProtocolLib works,
|
* This is useful if a server operator has tested and verified that a version of ProtocolLib works, but doesn't want or can't upgrade to a newer version.
|
||||||
* but doesn't want or can't upgrade to a newer version.
|
|
||||||
*
|
*
|
||||||
* @param ignoreVersion - the version of Minecraft where the satefy will be disabled.
|
* @param ignoreVersion - the version of Minecraft where the satefy will be disabled.
|
||||||
*/
|
*/
|
||||||
@ -318,15 +178,16 @@ public class ProtocolConfig {
|
|||||||
setConfig(global, IGNORE_VERSION_CHECK, ignoreVersion);
|
setConfig(global, IGNORE_VERSION_CHECK, ignoreVersion);
|
||||||
modCount++;
|
modCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve whether or not metrics is enabled.
|
* Retrieve whether or not metrics is enabled.
|
||||||
|
*
|
||||||
* @return TRUE if metrics is enabled, FALSE otherwise.
|
* @return TRUE if metrics is enabled, FALSE otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean isMetricsEnabled() {
|
public boolean isMetricsEnabled() {
|
||||||
return global.getBoolean(METRICS_ENABLED, true);
|
return getGlobalValue(METRICS_ENABLED, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set whether or not metrics is enabled.
|
* Set whether or not metrics is enabled.
|
||||||
* <p>
|
* <p>
|
||||||
@ -338,117 +199,102 @@ public class ProtocolConfig {
|
|||||||
setConfig(global, METRICS_ENABLED, enabled);
|
setConfig(global, METRICS_ENABLED, enabled);
|
||||||
modCount++;
|
modCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve whether or not the background compiler for structure modifiers is enabled or not.
|
* Retrieve whether or not the background compiler for structure modifiers is enabled or not.
|
||||||
|
*
|
||||||
* @return TRUE if it is enabled, FALSE otherwise.
|
* @return TRUE if it is enabled, FALSE otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean isBackgroundCompilerEnabled() {
|
public boolean isBackgroundCompilerEnabled() {
|
||||||
return global.getBoolean(BACKGROUND_COMPILER_ENABLED, true);
|
return getGlobalValue(BACKGROUND_COMPILER_ENABLED, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set whether or not the background compiler for structure modifiers is enabled or not.
|
* Set whether or not the background compiler for structure modifiers is enabled or not.
|
||||||
* <p>
|
* <p>
|
||||||
* This setting will take effect next time ProtocolLib is started.
|
* This setting will take effect next time ProtocolLib is started.
|
||||||
|
*
|
||||||
* @param enabled - TRUE if is enabled/running, FALSE otherwise.
|
* @param enabled - TRUE if is enabled/running, FALSE otherwise.
|
||||||
*/
|
*/
|
||||||
public void setBackgroundCompilerEnabled(boolean enabled) {
|
public void setBackgroundCompilerEnabled(boolean enabled) {
|
||||||
setConfig(global, BACKGROUND_COMPILER_ENABLED, enabled);
|
setConfig(global, BACKGROUND_COMPILER_ENABLED, enabled);
|
||||||
modCount++;
|
modCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve the last time we updated, in seconds since 1970.01.01 00:00.
|
|
||||||
* @return Last update time.
|
|
||||||
*/
|
|
||||||
public long getAutoLastTime() {
|
|
||||||
return lastUpdateTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the last time we updated, in seconds since 1970.01.01 00:00.
|
|
||||||
* <p>
|
|
||||||
* Note that this is not considered to modify the configuration, so the modification count
|
|
||||||
* will not be incremented.
|
|
||||||
* @param lastTimeSeconds - new last update time.
|
|
||||||
*/
|
|
||||||
public void setAutoLastTime(long lastTimeSeconds) {
|
|
||||||
this.valuesChanged = true;
|
|
||||||
this.lastUpdateTime = lastTimeSeconds;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the unique name of the script engine to use for filtering.
|
* Retrieve the unique name of the script engine to use for filtering.
|
||||||
|
*
|
||||||
* @return Script engine to use.
|
* @return Script engine to use.
|
||||||
*/
|
*/
|
||||||
public String getScriptEngineName() {
|
public String getScriptEngineName() {
|
||||||
return global.getString(SCRIPT_ENGINE_NAME, "JavaScript");
|
return global.getString(SCRIPT_ENGINE_NAME, "JavaScript");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the unique name of the script engine to use for filtering.
|
* Set the unique name of the script engine to use for filtering.
|
||||||
* <p>
|
* <p>
|
||||||
* This setting will take effect next time ProtocolLib is started.
|
* This setting will take effect next time ProtocolLib is started.
|
||||||
|
*
|
||||||
* @param name - name of the script engine to use.
|
* @param name - name of the script engine to use.
|
||||||
*/
|
*/
|
||||||
public void setScriptEngineName(String name) {
|
public void setScriptEngineName(String name) {
|
||||||
setConfig(global, SCRIPT_ENGINE_NAME, name);
|
setConfig(global, SCRIPT_ENGINE_NAME, name);
|
||||||
modCount++;
|
modCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the default injection method.
|
* Retrieve the default injection method.
|
||||||
|
*
|
||||||
* @return Default method.
|
* @return Default method.
|
||||||
*/
|
*/
|
||||||
public PlayerInjectHooks getDefaultMethod() {
|
public PlayerInjectHooks getDefaultMethod() {
|
||||||
return PlayerInjectHooks.NETWORK_SERVER_OBJECT;
|
return PlayerInjectHooks.NETWORK_SERVER_OBJECT;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the injection method that has been set in the configuration, or use a default value.
|
* Retrieve the injection method that has been set in the configuration, or use a default value.
|
||||||
|
*
|
||||||
* @return Injection method to use.
|
* @return Injection method to use.
|
||||||
* @throws IllegalArgumentException If the configuration option is malformed.
|
* @throws IllegalArgumentException If the configuration option is malformed.
|
||||||
*/
|
*/
|
||||||
public PlayerInjectHooks getInjectionMethod() throws IllegalArgumentException {
|
public PlayerInjectHooks getInjectionMethod() throws IllegalArgumentException {
|
||||||
String text = global.getString(INJECTION_METHOD);
|
String text = global.getString(INJECTION_METHOD);
|
||||||
|
|
||||||
// Default hook if nothing has been set
|
// Default hook if nothing has been set
|
||||||
PlayerInjectHooks hook = getDefaultMethod();
|
PlayerInjectHooks hook = getDefaultMethod();
|
||||||
|
|
||||||
if (text != null)
|
if (text != null)
|
||||||
hook = PlayerInjectHooks.valueOf(text.toUpperCase().replace(" ", "_"));
|
hook = PlayerInjectHooks.valueOf(text.toUpperCase().replace(" ", "_"));
|
||||||
return hook;
|
return hook;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the starting injection method to use.
|
* Set the starting injection method to use.
|
||||||
|
*
|
||||||
* @param hook Injection method
|
* @param hook Injection method
|
||||||
*/
|
*/
|
||||||
public void setInjectionMethod(PlayerInjectHooks hook) {
|
public void setInjectionMethod(PlayerInjectHooks hook) {
|
||||||
setConfig(global, INJECTION_METHOD, hook.name());
|
setConfig(global, INJECTION_METHOD, hook.name());
|
||||||
modCount++;
|
modCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the number of modifications made to this configuration.
|
* Retrieve the number of modifications made to this configuration.
|
||||||
|
*
|
||||||
* @return The number of modifications.
|
* @return The number of modifications.
|
||||||
*/
|
*/
|
||||||
public int getModificationCount() {
|
public int getModificationCount() {
|
||||||
return modCount;
|
return modCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save the current configuration file.
|
* Save the current configuration file.
|
||||||
*/
|
*/
|
||||||
public void saveAll() {
|
public void saveAll() {
|
||||||
if (valuesChanged)
|
|
||||||
saveLastUpdate(lastUpdateTime);
|
|
||||||
if (configChanged)
|
if (configChanged)
|
||||||
plugin.saveConfig();
|
plugin.saveConfig();
|
||||||
|
|
||||||
// And we're done
|
// And we're done
|
||||||
valuesChanged = false;
|
|
||||||
configChanged = false;
|
configChanged = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -169,6 +169,10 @@ public class ProtocolLibrary extends JavaPlugin {
|
|||||||
DetailedErrorReporter detailedReporter = new DetailedErrorReporter(this);
|
DetailedErrorReporter detailedReporter = new DetailedErrorReporter(this);
|
||||||
reporter = getFilteredReporter(detailedReporter);
|
reporter = getFilteredReporter(detailedReporter);
|
||||||
|
|
||||||
|
// Configuration
|
||||||
|
saveDefaultConfig();
|
||||||
|
reloadConfig();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
config = new ProtocolConfig(this);
|
config = new ProtocolConfig(this);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -248,7 +252,7 @@ public class ProtocolLibrary extends JavaPlugin {
|
|||||||
try {
|
try {
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case PROTOCOL:
|
case PROTOCOL:
|
||||||
commandProtocol = new CommandProtocol(reporter, this, config);
|
commandProtocol = new CommandProtocol(reporter, this);
|
||||||
break;
|
break;
|
||||||
case FILTER:
|
case FILTER:
|
||||||
commandFilter = new CommandFilter(reporter, this, config);
|
commandFilter = new CommandFilter(reporter, this, config);
|
||||||
|
@ -38,18 +38,19 @@ class LoginPackets {
|
|||||||
}
|
}
|
||||||
serverSide.add(Packets.Server.KICK_DISCONNECT);
|
serverSide.add(Packets.Server.KICK_DISCONNECT);
|
||||||
|
|
||||||
// MCPC++ contains Forge, which uses packet 250 during login
|
// MCPC+/Cauldron contains Forge, which uses packet 250 during login
|
||||||
if (isMCPC()) {
|
if (isCauldronOrMCPC()) {
|
||||||
clientSide.add(Packets.Client.CUSTOM_PAYLOAD);
|
clientSide.add(Packets.Client.CUSTOM_PAYLOAD);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if we are runnign MCPC.
|
* Determine if we are running MCPC or Cauldron.
|
||||||
* @return TRUE if we are, FALSE otherwise.
|
* @return TRUE if we are, FALSE otherwise.
|
||||||
*/
|
*/
|
||||||
private static boolean isMCPC() {
|
private static boolean isCauldronOrMCPC() {
|
||||||
return Bukkit.getServer().getVersion().contains("MCPC-Plus");
|
String version = Bukkit.getServer().getVersion();
|
||||||
|
return version.contains("MCPC") || version.contains("Cauldron");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1070,7 +1070,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
|
|||||||
playerInjection.uninjectPlayer(event.getPlayer().getAddress());
|
playerInjection.uninjectPlayer(event.getPlayer().getAddress());
|
||||||
playerInjection.injectPlayer(event.getPlayer(), ConflictStrategy.OVERRIDE);
|
playerInjection.injectPlayer(event.getPlayer(), ConflictStrategy.OVERRIDE);
|
||||||
} catch (ServerHandlerNull e) {
|
} catch (ServerHandlerNull e) {
|
||||||
// Caused by logged out players, or fake login events in MCPC++. Ignore it.
|
// Caused by logged out players, or fake login events in MCPC+/Cauldron. Ignore it.
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
reporter.reportDetailed(PacketFilterManager.this,
|
reporter.reportDetailed(PacketFilterManager.this,
|
||||||
Report.newBuilder(REPORT_CANNOT_INJECT_PLAYER).callerParam(event).error(e)
|
Report.newBuilder(REPORT_CANNOT_INJECT_PLAYER).callerParam(event).error(e)
|
||||||
|
@ -334,7 +334,7 @@ class ProxyPacketInjector implements PacketInjector {
|
|||||||
return packetRecieved(packet, client, buffered);
|
return packetRecieved(packet, client, buffered);
|
||||||
} else {
|
} else {
|
||||||
// The timeout elapsed!
|
// The timeout elapsed!
|
||||||
reporter.reportWarning(this, Report.newBuilder(REPORT_UNKNOWN_ORIGIN_FOR_PACKET).messageParam(input, packet.getType()));
|
reporter.reportDetailed(this, Report.newBuilder(REPORT_UNKNOWN_ORIGIN_FOR_PACKET).messageParam(input, packet.getType()));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -743,7 +743,7 @@ public abstract class PlayerInjector implements SocketInjector {
|
|||||||
/**
|
/**
|
||||||
* Indicates that a player's NetServerHandler or PlayerConnection was NULL.
|
* Indicates that a player's NetServerHandler or PlayerConnection was NULL.
|
||||||
* <p>
|
* <p>
|
||||||
* This is usually because the player has just logged out, or due to it being a "fake" player in MCPC++.
|
* This is usually because the player has just logged out, or due to it being a "fake" player in MCPC+/Cauldron.
|
||||||
* @author Kristian
|
* @author Kristian
|
||||||
*/
|
*/
|
||||||
public static class ServerHandlerNull extends IllegalAccessError {
|
public static class ServerHandlerNull extends IllegalAccessError {
|
||||||
|
@ -74,9 +74,9 @@ import com.google.common.collect.Maps;
|
|||||||
* @author Kristian
|
* @author Kristian
|
||||||
*/
|
*/
|
||||||
public class MinecraftReflection {
|
public class MinecraftReflection {
|
||||||
public static final ReportType REPORT_CANNOT_FIND_MCPC_REMAPPER = new ReportType("Cannot find MCPC remapper.");
|
public static final ReportType REPORT_CANNOT_FIND_MCPC_REMAPPER = new ReportType("Cannot find MCPC/Cauldron remapper.");
|
||||||
public static final ReportType REPORT_CANNOT_LOAD_CPC_REMAPPER = new ReportType("Unable to load MCPC remapper.");
|
public static final ReportType REPORT_CANNOT_LOAD_CPC_REMAPPER = new ReportType("Unable to load MCPC/Cauldron remapper.");
|
||||||
public static final ReportType REPORT_NON_CRAFTBUKKIT_LIBRARY_PACKAGE = new ReportType("Cannot find standard Minecraft library location. Assuming MCPC.");
|
public static final ReportType REPORT_NON_CRAFTBUKKIT_LIBRARY_PACKAGE = new ReportType("Cannot find standard Minecraft library location. Assuming MCPC/Cauldron.");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Regular expression that matches a canonical Java class.
|
* Regular expression that matches a canonical Java class.
|
||||||
|
@ -24,6 +24,7 @@ package com.comphenix.protocol.utility;
|
|||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Server;
|
||||||
|
|
||||||
import com.comphenix.protocol.reflect.FieldUtils;
|
import com.comphenix.protocol.reflect.FieldUtils;
|
||||||
import com.comphenix.protocol.reflect.MethodUtils;
|
import com.comphenix.protocol.reflect.MethodUtils;
|
||||||
@ -56,11 +57,17 @@ class RemappedClassSource extends ClassSource {
|
|||||||
*/
|
*/
|
||||||
public RemappedClassSource initialize() {
|
public RemappedClassSource initialize() {
|
||||||
try {
|
try {
|
||||||
if (Bukkit.getServer() == null || !Bukkit.getServer().getVersion().contains("MCPC-Plus")) {
|
Server server = Bukkit.getServer();
|
||||||
|
if (server == null) {
|
||||||
|
throw new IllegalStateException("Bukkit not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
String version = server.getVersion();
|
||||||
|
if (!server.getVersion().contains("MCPC-Plus") && !version.contains("Cauldron")) {
|
||||||
throw new RemapperUnavaibleException(Reason.MCPC_NOT_PRESENT);
|
throw new RemapperUnavaibleException(Reason.MCPC_NOT_PRESENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtain the Class remapper used by MCPC+
|
// Obtain the Class remapper used by MCPC+/Cauldron
|
||||||
this.classRemapper = FieldUtils.readField(getClass().getClassLoader(), "remapper", true);
|
this.classRemapper = FieldUtils.readField(getClass().getClassLoader(), "remapper", true);
|
||||||
|
|
||||||
if (this.classRemapper == null) {
|
if (this.classRemapper == null) {
|
||||||
@ -112,8 +119,8 @@ class RemappedClassSource extends ClassSource {
|
|||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
public enum Reason {
|
public enum Reason {
|
||||||
MCPC_NOT_PRESENT("The server is not running MCPC+"),
|
MCPC_NOT_PRESENT("The server is not running MCPC+/Cauldron"),
|
||||||
REMAPPER_DISABLED("Running an MCPC+ server but the remapper is unavailable. Please turn it on!");
|
REMAPPER_DISABLED("Running an MCPC+/Cauldron server but the remapper is unavailable. Please turn it on!");
|
||||||
|
|
||||||
private final String message;
|
private final String message;
|
||||||
|
|
||||||
|
@ -1,12 +1,4 @@
|
|||||||
global:
|
global:
|
||||||
# Settings for the automatic version updater
|
|
||||||
auto updater:
|
|
||||||
notify: true
|
|
||||||
download: false
|
|
||||||
|
|
||||||
# Number of seconds to wait until a new update is downloaded
|
|
||||||
delay: 43200 # 12 hours
|
|
||||||
|
|
||||||
metrics: true
|
metrics: true
|
||||||
|
|
||||||
# Automatically compile structure modifiers
|
# Automatically compile structure modifiers
|
||||||
|
Loading…
Reference in New Issue
Block a user