2016-06-12 19:43:41 +02:00
|
|
|
package me.libraryaddict.disguise;
|
|
|
|
|
2017-06-22 18:14:19 +02:00
|
|
|
import me.libraryaddict.disguise.commands.*;
|
2019-02-16 04:57:07 +01:00
|
|
|
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
|
|
|
import me.libraryaddict.disguise.utilities.LibsPremium;
|
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;
|
2019-01-03 03:13:03 +01:00
|
|
|
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
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;
|
2016-11-28 15:01:06 +01:00
|
|
|
import org.bukkit.command.CommandExecutor;
|
|
|
|
import org.bukkit.command.PluginCommand;
|
|
|
|
import org.bukkit.command.TabCompleter;
|
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;
|
2020-01-20 01:35:55 +01:00
|
|
|
import org.bukkit.scoreboard.Scoreboard;
|
|
|
|
import org.bukkit.scoreboard.Team;
|
2016-06-12 19:43:41 +02:00
|
|
|
|
2017-06-22 18:14:19 +02:00
|
|
|
import java.io.File;
|
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-01-18 03:12:32 +01:00
|
|
|
private boolean reloaded;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLoad() {
|
|
|
|
if (Bukkit.getServer().getWorlds().isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
reloaded = true;
|
|
|
|
getLogger().severe("Lib's Disguises was reloaded! Please do not report any bugs! This plugin can't handle " +
|
|
|
|
"reloads gracefully!");
|
|
|
|
}
|
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) {
|
|
|
|
getLogger()
|
|
|
|
.severe("Lib's Disguises was reloaded! Please do not report any bugs! This plugin can't handle " +
|
|
|
|
"reloads gracefully!");
|
|
|
|
}
|
|
|
|
|
2016-11-30 18:38:43 +01:00
|
|
|
instance = this;
|
2017-07-10 18:02:24 +02: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
|
|
|
|
2018-12-16 02:47:42 +01:00
|
|
|
YamlConfiguration pluginYml = ReflectionManager.getPluginYaml(getClassLoader());
|
|
|
|
buildNumber = StringUtils.stripToNull(pluginYml.getString("build-number"));
|
|
|
|
|
|
|
|
getLogger().info("Discovered nms version: " + ReflectionManager.getBukkitVersion());
|
|
|
|
|
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"));
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-12-14 01:10:11 +01:00
|
|
|
if (!ReflectionManager.getMinecraftVersion().startsWith("1.15")) {
|
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-01-11 01:37:45 +01:00
|
|
|
"intended for 1.15!");
|
2018-08-14 07:20:48 +02:00
|
|
|
getPluginLoader().disablePlugin(this);
|
2018-08-12 05:35:06 +02:00
|
|
|
return;
|
2018-08-05 10:34:02 +02:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
2018-11-08 09:04:18 +01:00
|
|
|
if (!DisguiseConfig.isDisableCommands()) {
|
|
|
|
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("libsdisguises", new LibsDisguisesCommand());
|
|
|
|
registerCommand("disguiseviewself", new DisguiseViewSelfCommand());
|
|
|
|
registerCommand("disguisemodify", new DisguiseModifyCommand());
|
|
|
|
registerCommand("disguisemodifyentity", new DisguiseModifyEntityCommand());
|
|
|
|
registerCommand("disguisemodifyplayer", new DisguiseModifyPlayerCommand());
|
|
|
|
registerCommand("disguisemodifyradius",
|
|
|
|
new DisguiseModifyRadiusCommand(getConfig().getInt("DisguiseRadiusMax")));
|
2020-01-02 05:10:36 +01:00
|
|
|
registerCommand("copydisguise", new CopyDisguiseCommand());
|
|
|
|
registerCommand("grabskin", new GrabSkinCommand());
|
|
|
|
registerCommand("savedisguise", new SaveDisguiseCommand());
|
2018-12-19 03:10:15 +01:00
|
|
|
} else {
|
|
|
|
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
|
|
|
|
2019-01-03 03:13:03 +01:00
|
|
|
new MetricsInitalizer();
|
2017-06-22 18:14:19 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
PluginCommand command = getCommand(commandName);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|