2016-06-12 19:43:41 +02:00
|
|
|
package me.libraryaddict.disguise;
|
|
|
|
|
2020-04-15 14:55:35 +02:00
|
|
|
import lombok.Getter;
|
2020-03-08 21:00:58 +01:00
|
|
|
import me.libraryaddict.disguise.commands.LibsDisguisesCommand;
|
|
|
|
import me.libraryaddict.disguise.commands.disguise.DisguiseCommand;
|
|
|
|
import me.libraryaddict.disguise.commands.disguise.DisguiseEntityCommand;
|
|
|
|
import me.libraryaddict.disguise.commands.disguise.DisguisePlayerCommand;
|
|
|
|
import me.libraryaddict.disguise.commands.disguise.DisguiseRadiusCommand;
|
|
|
|
import me.libraryaddict.disguise.commands.modify.DisguiseModifyCommand;
|
|
|
|
import me.libraryaddict.disguise.commands.modify.DisguiseModifyEntityCommand;
|
|
|
|
import me.libraryaddict.disguise.commands.modify.DisguiseModifyPlayerCommand;
|
|
|
|
import me.libraryaddict.disguise.commands.modify.DisguiseModifyRadiusCommand;
|
|
|
|
import me.libraryaddict.disguise.commands.undisguise.UndisguiseCommand;
|
|
|
|
import me.libraryaddict.disguise.commands.undisguise.UndisguiseEntityCommand;
|
|
|
|
import me.libraryaddict.disguise.commands.undisguise.UndisguisePlayerCommand;
|
|
|
|
import me.libraryaddict.disguise.commands.undisguise.UndisguiseRadiusCommand;
|
|
|
|
import me.libraryaddict.disguise.commands.utils.*;
|
2019-02-16 04:57:07 +01:00
|
|
|
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
|
|
|
import me.libraryaddict.disguise.utilities.LibsPremium;
|
2020-04-20 14:52:58 +02:00
|
|
|
import me.libraryaddict.disguise.utilities.listeners.DisguiseListener;
|
2019-01-03 03:13:03 +01:00
|
|
|
import me.libraryaddict.disguise.utilities.metrics.MetricsInitalizer;
|
|
|
|
import me.libraryaddict.disguise.utilities.packets.PacketsManager;
|
2019-12-31 07:35:21 +01:00
|
|
|
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
2020-02-06 00:15:20 +01:00
|
|
|
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
2019-01-03 03:13:03 +01:00
|
|
|
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
2020-02-19 00:57:39 +01:00
|
|
|
import me.libraryaddict.disguise.utilities.reflection.asm.WatcherSanitizer;
|
2020-05-01 16:09:24 +02:00
|
|
|
import me.libraryaddict.disguise.utilities.updates.UpdateChecker;
|
2019-05-18 08:54:51 +02:00
|
|
|
import org.apache.commons.lang.StringUtils;
|
2016-06-12 19:43:41 +02:00
|
|
|
import org.bukkit.Bukkit;
|
2020-04-27 14:09:05 +02:00
|
|
|
import org.bukkit.command.*;
|
2018-12-16 02:47:42 +01:00
|
|
|
import org.bukkit.configuration.file.YamlConfiguration;
|
2020-01-20 01:35:55 +01:00
|
|
|
import org.bukkit.entity.Player;
|
2016-06-12 19:43:41 +02:00
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
|
2017-06-22 18:14:19 +02:00
|
|
|
import java.io.File;
|
2020-02-13 07:47:02 +01:00
|
|
|
import java.util.Arrays;
|
2020-04-27 14:09:05 +02:00
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.Map;
|
2020-02-13 07:47:02 +01:00
|
|
|
import java.util.stream.Collectors;
|
2016-06-12 19:43:41 +02:00
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
public class LibsDisguises extends JavaPlugin {
|
2016-06-12 19:43:41 +02:00
|
|
|
private static LibsDisguises instance;
|
|
|
|
private DisguiseListener listener;
|
2018-12-16 02:47:42 +01:00
|
|
|
private String buildNumber;
|
2020-04-15 14:55:35 +02:00
|
|
|
@Getter
|
2020-01-18 03:12:32 +01:00
|
|
|
private boolean reloaded;
|
2020-04-19 04:55:39 +02:00
|
|
|
@Getter
|
|
|
|
private final UpdateChecker updateChecker = new UpdateChecker("32453");
|
2020-01-18 03:12:32 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLoad() {
|
2020-02-21 02:24:07 +01:00
|
|
|
instance = this;
|
|
|
|
|
2020-02-21 02:45:11 +01:00
|
|
|
if (!Bukkit.getServer().getWorlds().isEmpty()) {
|
|
|
|
reloaded = true;
|
2020-04-21 04:46:46 +02:00
|
|
|
getLogger().severe("Server was reloaded! Please do not report any bugs! This plugin can't handle " +
|
|
|
|
"reloads gracefully!");
|
2020-01-18 03:12:32 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-21 01:53:08 +01:00
|
|
|
WatcherSanitizer.init();
|
2020-01-18 03:12:32 +01:00
|
|
|
}
|
2016-06-12 19:43:41 +02:00
|
|
|
|
|
|
|
@Override
|
2016-11-25 13:07:02 +01:00
|
|
|
public void onEnable() {
|
2020-01-18 03:12:32 +01:00
|
|
|
if (reloaded) {
|
2020-04-21 04:46:46 +02:00
|
|
|
getLogger().severe("Server was reloaded! Please do not report any bugs! This plugin can't handle " +
|
|
|
|
"reloads gracefully!");
|
2020-01-18 03:12:32 +01:00
|
|
|
}
|
|
|
|
|
2016-11-30 18:38:43 +01:00
|
|
|
if (!new File(getDataFolder(), "disguises.yml").exists()) {
|
|
|
|
saveResource("disguises.yml", false);
|
|
|
|
}
|
2016-06-12 19:43:41 +02:00
|
|
|
|
2020-04-17 04:08:21 +02:00
|
|
|
YamlConfiguration pluginYml = ReflectionManager.getPluginYAML(getFile());
|
2018-12-16 02:47:42 +01:00
|
|
|
buildNumber = StringUtils.stripToNull(pluginYml.getString("build-number"));
|
|
|
|
|
2020-02-06 01:05:59 +01:00
|
|
|
getLogger().info("Discovered nms version: " + ReflectionManager.getBukkitVersion());
|
2018-12-16 02:47:42 +01:00
|
|
|
|
2018-12-16 05:19:59 +01:00
|
|
|
getLogger().info("Jenkins Build: " + (isNumberedBuild() ? "#" : "") + getBuildNo());
|
2018-12-16 02:47:42 +01:00
|
|
|
|
2019-02-16 04:57:07 +01:00
|
|
|
getLogger().info("Build Date: " + pluginYml.getString("build-date"));
|
|
|
|
|
2020-04-26 19:09:13 +02:00
|
|
|
DisguiseConfig.loadInternalConfig();
|
|
|
|
|
2019-06-29 03:38:20 +02:00
|
|
|
LibsPremium.check(getDescription().getVersion(), getFile());
|
2017-07-10 18:02:24 +02:00
|
|
|
|
2019-05-18 08:54:51 +02:00
|
|
|
if (!LibsPremium.isPremium()) {
|
2019-12-21 22:15:52 +01:00
|
|
|
getLogger()
|
|
|
|
.info("You are running the free version, commands limited to non-players and operators. (Console," +
|
|
|
|
" Command " + "Blocks, Admins)");
|
2019-05-18 08:54:51 +02:00
|
|
|
}
|
|
|
|
|
2020-02-06 00:15:20 +01:00
|
|
|
if (ReflectionManager.getVersion() == null) {
|
2018-08-14 02:42:35 +02:00
|
|
|
getLogger().severe("You're using the wrong version of Lib's Disguises for your server! This is " +
|
2020-02-13 07:47:02 +01:00
|
|
|
"intended for " + StringUtils
|
|
|
|
.join(Arrays.stream(NmsVersion.values()).map(v -> v.name().replace("_", "."))
|
|
|
|
.collect(Collectors.toList()), " & ") + "!");
|
|
|
|
getPluginLoader().disablePlugin(this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-26 19:09:13 +02:00
|
|
|
// If this is a release build, even if jenkins build..
|
|
|
|
if (isReleaseBuild()) {
|
|
|
|
// If downloaded from spigot, forcibly set release build to true
|
|
|
|
if (LibsPremium.getUserID().matches("[0-9]+")) {
|
|
|
|
DisguiseConfig.setUsingReleaseBuilds(true);
|
|
|
|
}
|
|
|
|
// Otherwise leave it untouched as they might've just happened to hit a dev build, which is a release build
|
|
|
|
} else {
|
|
|
|
DisguiseConfig.setUsingReleaseBuilds(false);
|
|
|
|
}
|
|
|
|
|
2019-12-24 05:40:56 +01:00
|
|
|
ReflectionManager.init();
|
|
|
|
|
2020-01-19 03:48:26 +01:00
|
|
|
PacketsManager.init();
|
|
|
|
DisguiseUtilities.init();
|
2016-06-12 19:43:41 +02:00
|
|
|
|
2020-01-19 03:48:26 +01:00
|
|
|
ReflectionManager.registerValues();
|
2016-11-30 18:38:43 +01:00
|
|
|
|
2018-08-24 00:01:01 +02:00
|
|
|
DisguiseConfig.loadConfig();
|
2016-06-12 19:43:41 +02:00
|
|
|
|
2019-12-31 07:35:21 +01:00
|
|
|
DisguiseParser.createDefaultMethods();
|
|
|
|
|
2016-06-12 19:43:41 +02:00
|
|
|
PacketsManager.addPacketListeners();
|
|
|
|
|
|
|
|
listener = new DisguiseListener(this);
|
|
|
|
|
2020-02-06 00:15:20 +01:00
|
|
|
registerCommand("libsdisguises", new LibsDisguisesCommand());
|
|
|
|
|
2020-04-17 04:30:29 +02:00
|
|
|
if (!DisguiseConfig.isDisableCommands()) {
|
|
|
|
if (!LibsPremium.isAPIPlugin()) {
|
|
|
|
registerCommand("disguise", new DisguiseCommand());
|
|
|
|
registerCommand("undisguise", new UndisguiseCommand());
|
|
|
|
registerCommand("disguiseplayer", new DisguisePlayerCommand());
|
|
|
|
registerCommand("undisguiseplayer", new UndisguisePlayerCommand());
|
|
|
|
registerCommand("undisguiseentity", new UndisguiseEntityCommand());
|
|
|
|
registerCommand("disguiseentity", new DisguiseEntityCommand());
|
|
|
|
registerCommand("disguiseradius", new DisguiseRadiusCommand(getConfig().getInt("DisguiseRadiusMax")));
|
|
|
|
registerCommand("undisguiseradius",
|
|
|
|
new UndisguiseRadiusCommand(getConfig().getInt("UndisguiseRadiusMax")));
|
|
|
|
registerCommand("disguisehelp", new DisguiseHelpCommand());
|
|
|
|
registerCommand("disguiseclone", new DisguiseCloneCommand());
|
|
|
|
registerCommand("disguiseviewself", new DisguiseViewSelfCommand());
|
|
|
|
registerCommand("disguisemodify", new DisguiseModifyCommand());
|
|
|
|
registerCommand("disguisemodifyentity", new DisguiseModifyEntityCommand());
|
|
|
|
registerCommand("disguisemodifyplayer", new DisguiseModifyPlayerCommand());
|
|
|
|
registerCommand("disguisemodifyradius",
|
|
|
|
new DisguiseModifyRadiusCommand(getConfig().getInt("DisguiseRadiusMax")));
|
|
|
|
registerCommand("copydisguise", new CopyDisguiseCommand());
|
|
|
|
} else {
|
|
|
|
getLogger().info("This is the API version! /grabskin and /savedisguise enabled!");
|
|
|
|
}
|
|
|
|
|
2020-01-02 05:10:36 +01:00
|
|
|
registerCommand("grabskin", new GrabSkinCommand());
|
|
|
|
registerCommand("savedisguise", new SaveDisguiseCommand());
|
2018-12-19 03:10:15 +01:00
|
|
|
} else {
|
2020-04-17 04:30:29 +02:00
|
|
|
getLogger().info("Commands has been disabled, as per config");
|
2018-11-08 09:04:18 +01:00
|
|
|
}
|
2016-06-12 19:43:41 +02:00
|
|
|
|
2020-04-27 14:09:05 +02:00
|
|
|
unregisterCommands();
|
|
|
|
|
2019-01-03 03:13:03 +01:00
|
|
|
new MetricsInitalizer();
|
2017-06-22 18:14:19 +02:00
|
|
|
}
|
|
|
|
|
2020-04-27 14:09:05 +02:00
|
|
|
private void unregisterCommands() {
|
|
|
|
CommandMap map = ReflectionManager.getCommandMap();
|
|
|
|
Map<String, Command> commands = ReflectionManager.getCommands(map);
|
|
|
|
|
|
|
|
for (String command : getDescription().getCommands().keySet()) {
|
|
|
|
PluginCommand cmd = getCommand("libsdisguises:" + command);
|
|
|
|
|
|
|
|
if (cmd.getExecutor() != this) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cmd.getPermission() != null && cmd.getPermission().startsWith("libsdisguises.seecmd")) {
|
|
|
|
Bukkit.getPluginManager().removePermission(cmd.getPermission());
|
|
|
|
}
|
|
|
|
|
|
|
|
Iterator<Map.Entry<String, Command>> itel = commands.entrySet().iterator();
|
|
|
|
|
|
|
|
while (itel.hasNext()) {
|
|
|
|
Map.Entry<String, Command> entry = itel.next();
|
|
|
|
|
|
|
|
if (entry.getValue() != cmd) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
itel.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-17 04:14:49 +02:00
|
|
|
@Override
|
|
|
|
public File getFile() {
|
|
|
|
return super.getFile();
|
|
|
|
}
|
|
|
|
|
2018-12-16 02:47:42 +01:00
|
|
|
@Override
|
|
|
|
public void onDisable() {
|
|
|
|
DisguiseUtilities.saveDisguises();
|
|
|
|
|
|
|
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
|
|
|
DisguiseUtilities.removeSelfDisguiseScoreboard(player);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isReleaseBuild() {
|
|
|
|
return !getDescription().getVersion().contains("-SNAPSHOT");
|
|
|
|
}
|
2018-08-24 00:01:01 +02:00
|
|
|
|
2018-12-16 02:47:42 +01:00
|
|
|
public String getBuildNo() {
|
|
|
|
return buildNumber;
|
2017-06-02 15:51:03 +02:00
|
|
|
}
|
|
|
|
|
2020-04-19 04:55:39 +02:00
|
|
|
public int getBuildNumber() {
|
|
|
|
return isNumberedBuild() ? Integer.parseInt(getBuildNo()) : 0;
|
|
|
|
}
|
|
|
|
|
2018-12-16 05:19:59 +01:00
|
|
|
public boolean isNumberedBuild() {
|
|
|
|
return getBuildNo() != null && getBuildNo().matches("[0-9]+");
|
|
|
|
}
|
|
|
|
|
2016-11-28 15:01:06 +01:00
|
|
|
private void registerCommand(String commandName, CommandExecutor executioner) {
|
2020-04-27 14:09:05 +02:00
|
|
|
PluginCommand command = getCommand("libsdisguises:" + commandName);
|
2016-11-28 15:01:06 +01:00
|
|
|
|
|
|
|
command.setExecutor(executioner);
|
|
|
|
|
|
|
|
if (executioner instanceof TabCompleter) {
|
|
|
|
command.setTabCompleter((TabCompleter) executioner);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-12 19:43:41 +02:00
|
|
|
/**
|
|
|
|
* Reloads the config with new config options.
|
|
|
|
*/
|
2018-08-24 00:01:01 +02:00
|
|
|
@Deprecated
|
2016-11-25 13:07:02 +01:00
|
|
|
public void reload() {
|
2018-08-24 00:01:01 +02:00
|
|
|
DisguiseConfig.loadConfig();
|
2016-06-12 19:43:41 +02:00
|
|
|
}
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
public DisguiseListener getListener() {
|
2016-06-12 19:43:41 +02:00
|
|
|
return listener;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* External APIs shouldn't actually need this instance. DisguiseAPI should be enough to handle most cases.
|
|
|
|
*
|
|
|
|
* @return The instance of this plugin
|
|
|
|
*/
|
2016-11-25 13:07:02 +01:00
|
|
|
public static LibsDisguises getInstance() {
|
2016-06-12 19:43:41 +02:00
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
}
|