LibsDisguises/src/main/java/me/libraryaddict/disguise/LibsDisguises.java
libraryaddict 897a6629ae
Read for information...
Now using ASM manipulation to remove invalid methods on load
Fixed imports
Fixed Chat Components being used in 1.12
Fixed tab complete showing args for disguise options you can't use
Disguise option permissions now demand a parameter to be the method name
Falling block disguises are now only usable with blocks
LibsDisguises command now tab completes the new options
Libs Disguises command lets you create a vanilla compatible item string
If a vehicle is disguised as a vehicle, don't give no gravity
Fixed horse disguise using almost random values for its flagwatcher settings
Renamed horse disguise setMouthOpen to setEating
Slightly better string for premium info jar location
Skip attributes packets if using older ProtocolLib jar
Don't cancel entity death if entity is dead
Improved disguise permissions checking
Fixed time parameter not being attributed properly
2020-02-19 12:57:39 +13:00

179 lines
6.7 KiB
Java

package me.libraryaddict.disguise;
import me.libraryaddict.disguise.commands.*;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.metrics.MetricsInitalizer;
import me.libraryaddict.disguise.utilities.packets.PacketsManager;
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import me.libraryaddict.disguise.utilities.reflection.asm.WatcherSanitizer;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.PluginCommand;
import org.bukkit.command.TabCompleter;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.util.Arrays;
import java.util.stream.Collectors;
public class LibsDisguises extends JavaPlugin {
private static LibsDisguises instance;
private DisguiseListener listener;
private String buildNumber;
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!");
}
@Override
public void onEnable() {
if (reloaded) {
getLogger()
.severe("Lib's Disguises was reloaded! Please do not report any bugs! This plugin can't handle " +
"reloads gracefully!");
}
instance = this;
if (!new File(getDataFolder(), "disguises.yml").exists()) {
saveResource("disguises.yml", false);
}
YamlConfiguration pluginYml = ReflectionManager.getPluginYaml(getClassLoader());
buildNumber = StringUtils.stripToNull(pluginYml.getString("build-number"));
getLogger().info("Discovered nms version: " + ReflectionManager.getBukkitVersion());
getLogger().info("Jenkins Build: " + (isNumberedBuild() ? "#" : "") + getBuildNo());
getLogger().info("Build Date: " + pluginYml.getString("build-date"));
LibsPremium.check(getDescription().getVersion(), getFile());
if (!LibsPremium.isPremium()) {
getLogger()
.info("You are running the free version, commands limited to non-players and operators. (Console," +
" Command " + "Blocks, Admins)");
}
if (ReflectionManager.getVersion() == null) {
getLogger().severe("You're using the wrong version of Lib's Disguises for your server! This is " +
"intended for " + StringUtils
.join(Arrays.stream(NmsVersion.values()).map(v -> v.name().replace("_", "."))
.collect(Collectors.toList()), " & ") + "!");
getPluginLoader().disablePlugin(this);
return;
}
WatcherSanitizer.init();
ReflectionManager.init();
PacketsManager.init();
DisguiseUtilities.init();
ReflectionManager.registerValues();
DisguiseConfig.loadConfig();
DisguiseParser.createDefaultMethods();
PacketsManager.addPacketListeners();
listener = new DisguiseListener(this);
registerCommand("libsdisguises", new LibsDisguisesCommand());
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("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());
registerCommand("grabskin", new GrabSkinCommand());
registerCommand("savedisguise", new SaveDisguiseCommand());
} else {
getLogger().info("Commands has been disabled, as per config");
}
new MetricsInitalizer();
}
@Override
public void onDisable() {
DisguiseUtilities.saveDisguises();
for (Player player : Bukkit.getOnlinePlayers()) {
DisguiseUtilities.removeSelfDisguiseScoreboard(player);
}
}
public boolean isReleaseBuild() {
return !getDescription().getVersion().contains("-SNAPSHOT");
}
public String getBuildNo() {
return buildNumber;
}
public boolean isNumberedBuild() {
return getBuildNo() != null && getBuildNo().matches("[0-9]+");
}
private void registerCommand(String commandName, CommandExecutor executioner) {
PluginCommand command = getCommand(commandName);
command.setExecutor(executioner);
if (executioner instanceof TabCompleter) {
command.setTabCompleter((TabCompleter) executioner);
}
}
/**
* Reloads the config with new config options.
*/
@Deprecated
public void reload() {
DisguiseConfig.loadConfig();
}
public DisguiseListener getListener() {
return listener;
}
/**
* External APIs shouldn't actually need this instance. DisguiseAPI should be enough to handle most cases.
*
* @return The instance of this plugin
*/
public static LibsDisguises getInstance() {
return instance;
}
}