Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Ursprung
c24bc49f6d
Commit
bee858695f
290
FightSystem_15/src/org/bukkit/plugin/java/JavaPlugin.java
Normale Datei
290
FightSystem_15/src/org/bukkit/plugin/java/JavaPlugin.java
Normale Datei
@ -0,0 +1,290 @@
|
|||||||
|
//
|
||||||
|
// Source code recreated from a .class file by IntelliJ IDEA
|
||||||
|
// (powered by FernFlower decompiler)
|
||||||
|
//
|
||||||
|
|
||||||
|
package org.bukkit.plugin.java;
|
||||||
|
|
||||||
|
import com.google.common.base.Charsets;
|
||||||
|
import org.apache.commons.lang.Validate;
|
||||||
|
import org.bukkit.Server;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.PluginCommand;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.generator.ChunkGenerator;
|
||||||
|
import org.bukkit.plugin.PluginBase;
|
||||||
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
|
import org.bukkit.plugin.PluginLoader;
|
||||||
|
import org.bukkit.plugin.PluginLogger;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
public abstract class JavaPlugin extends PluginBase {
|
||||||
|
private boolean isEnabled = false;
|
||||||
|
private PluginLoader loader = null;
|
||||||
|
private Server server = null;
|
||||||
|
private File file = null;
|
||||||
|
private PluginDescriptionFile description = null;
|
||||||
|
private File dataFolder = null;
|
||||||
|
private ClassLoader classLoader = null;
|
||||||
|
private boolean naggable = true;
|
||||||
|
private FileConfiguration newConfig = null;
|
||||||
|
private File configFile = null;
|
||||||
|
private PluginLogger logger = null;
|
||||||
|
|
||||||
|
public JavaPlugin() {
|
||||||
|
init(PluginClassLoader.current.loader, PluginClassLoader.current.loader.server, PluginClassLoader.current.description, PluginClassLoader.current.dataFolder, PluginClassLoader.current.file, PluginClassLoader.current);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected JavaPlugin( JavaPluginLoader loader, PluginDescriptionFile description, File dataFolder, File file) {
|
||||||
|
ClassLoader classLoader = this.getClass().getClassLoader();
|
||||||
|
if (classLoader instanceof PluginClassLoader) {
|
||||||
|
throw new IllegalStateException("Cannot use initialization constructor at runtime");
|
||||||
|
} else {
|
||||||
|
this.init(loader, loader.server, description, dataFolder, file, classLoader);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public final File getDataFolder() {
|
||||||
|
return this.dataFolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public final PluginLoader getPluginLoader() {
|
||||||
|
return this.loader;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public final Server getServer() {
|
||||||
|
return this.server;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final boolean isEnabled() {
|
||||||
|
return this.isEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected File getFile() {
|
||||||
|
return this.file;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public final PluginDescriptionFile getDescription() {
|
||||||
|
return this.description;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public FileConfiguration getConfig() {
|
||||||
|
if (this.newConfig == null) {
|
||||||
|
this.reloadConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.newConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected final Reader getTextResource( String file) {
|
||||||
|
InputStream in = this.getResource(file);
|
||||||
|
return in == null ? null : new InputStreamReader(in, Charsets.UTF_8);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reloadConfig() {
|
||||||
|
this.newConfig = YamlConfiguration.loadConfiguration(this.configFile);
|
||||||
|
InputStream defConfigStream = this.getResource("config.yml");
|
||||||
|
if (defConfigStream != null) {
|
||||||
|
this.newConfig.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(defConfigStream, Charsets.UTF_8)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveConfig() {
|
||||||
|
try {
|
||||||
|
this.getConfig().save(this.configFile);
|
||||||
|
} catch (IOException var2) {
|
||||||
|
this.logger.log(Level.SEVERE, "Could not save config to " + this.configFile, var2);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveDefaultConfig() {
|
||||||
|
if (!this.configFile.exists()) {
|
||||||
|
this.saveResource("config.yml", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveResource( String resourcePath, boolean replace) {
|
||||||
|
if (resourcePath != null && !resourcePath.equals("")) {
|
||||||
|
resourcePath = resourcePath.replace('\\', '/');
|
||||||
|
InputStream in = this.getResource(resourcePath);
|
||||||
|
if (in == null) {
|
||||||
|
throw new IllegalArgumentException("The embedded resource '" + resourcePath + "' cannot be found in " + this.file);
|
||||||
|
} else {
|
||||||
|
File outFile = new File(this.dataFolder, resourcePath);
|
||||||
|
int lastIndex = resourcePath.lastIndexOf(47);
|
||||||
|
File outDir = new File(this.dataFolder, resourcePath.substring(0, lastIndex >= 0 ? lastIndex : 0));
|
||||||
|
if (!outDir.exists()) {
|
||||||
|
outDir.mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (outFile.exists() && !replace) {
|
||||||
|
this.logger.log(Level.WARNING, "Could not save " + outFile.getName() + " to " + outFile + " because " + outFile.getName() + " already exists.");
|
||||||
|
} else {
|
||||||
|
OutputStream out = new FileOutputStream(outFile);
|
||||||
|
byte[] buf = new byte[1024];
|
||||||
|
|
||||||
|
int len;
|
||||||
|
while((len = in.read(buf)) > 0) {
|
||||||
|
out.write(buf, 0, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
out.close();
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
|
} catch (IOException var10) {
|
||||||
|
this.logger.log(Level.SEVERE, "Could not save " + outFile.getName() + " to " + outFile, var10);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("ResourcePath cannot be null or empty");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public InputStream getResource( String filename) {
|
||||||
|
try {
|
||||||
|
URL url = this.getClassLoader().getResource(filename);
|
||||||
|
if (url == null) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
URLConnection connection = url.openConnection();
|
||||||
|
connection.setUseCaches(false);
|
||||||
|
return connection.getInputStream();
|
||||||
|
}
|
||||||
|
} catch (IOException var4) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected final ClassLoader getClassLoader() {
|
||||||
|
return this.classLoader;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final void setEnabled(boolean enabled) {
|
||||||
|
if (this.isEnabled != enabled) {
|
||||||
|
this.isEnabled = enabled;
|
||||||
|
if (this.isEnabled) {
|
||||||
|
this.onEnable();
|
||||||
|
} else {
|
||||||
|
this.onDisable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
final void init( PluginLoader loader, Server server, PluginDescriptionFile description, File dataFolder, File file, ClassLoader classLoader) {
|
||||||
|
this.loader = loader;
|
||||||
|
this.server = server;
|
||||||
|
this.file = file;
|
||||||
|
this.description = description;
|
||||||
|
this.dataFolder = dataFolder;
|
||||||
|
this.classLoader = classLoader;
|
||||||
|
this.configFile = new File(dataFolder, "config.yml");
|
||||||
|
this.logger = new PluginLogger(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean onCommand( CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<String> onTabComplete( CommandSender sender, Command command, String alias, String[] args) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public PluginCommand getCommand( String name) {
|
||||||
|
String alias = name.toLowerCase(Locale.ENGLISH);
|
||||||
|
PluginCommand command = this.getServer().getPluginCommand(alias);
|
||||||
|
if (command == null || command.getPlugin() != this) {
|
||||||
|
command = this.getServer().getPluginCommand(this.description.getName().toLowerCase(Locale.ENGLISH) + ":" + alias);
|
||||||
|
}
|
||||||
|
|
||||||
|
return command != null && command.getPlugin() == this ? command : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onLoad() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onDisable() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onEnable() {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public ChunkGenerator getDefaultWorldGenerator( String worldName, String id) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final boolean isNaggable() {
|
||||||
|
return this.naggable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void setNaggable(boolean canNag) {
|
||||||
|
this.naggable = canNag;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Logger getLogger() {
|
||||||
|
return this.logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return this.description.getFullName();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static <T extends JavaPlugin> T getPlugin( Class<T> clazz) {
|
||||||
|
Validate.notNull(clazz, "Null class cannot have a plugin");
|
||||||
|
if (!JavaPlugin.class.isAssignableFrom(clazz)) {
|
||||||
|
throw new IllegalArgumentException(clazz + " does not extend " + JavaPlugin.class);
|
||||||
|
} else {
|
||||||
|
ClassLoader cl = clazz.getClassLoader();
|
||||||
|
if (!(cl instanceof PluginClassLoader)) {
|
||||||
|
throw new IllegalArgumentException(clazz + " is not initialized by " + PluginClassLoader.class);
|
||||||
|
} else {
|
||||||
|
JavaPlugin plugin = ((PluginClassLoader)cl).plugin;
|
||||||
|
if (plugin == null) {
|
||||||
|
throw new IllegalStateException("Cannot get plugin for " + clazz + " from a static initializer");
|
||||||
|
} else {
|
||||||
|
return clazz.cast(plugin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static JavaPlugin getProvidingPlugin( Class<?> clazz) {
|
||||||
|
Validate.notNull(clazz, "Null class cannot have a plugin");
|
||||||
|
ClassLoader cl = clazz.getClassLoader();
|
||||||
|
if (!(cl instanceof PluginClassLoader)) {
|
||||||
|
throw new IllegalArgumentException(clazz + " is not provided by " + PluginClassLoader.class);
|
||||||
|
} else {
|
||||||
|
JavaPlugin plugin = ((PluginClassLoader)cl).plugin;
|
||||||
|
return plugin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
239
FightSystem_15/src/org/bukkit/plugin/java/PluginClassLoader.java
Normale Datei
239
FightSystem_15/src/org/bukkit/plugin/java/PluginClassLoader.java
Normale Datei
@ -0,0 +1,239 @@
|
|||||||
|
/*
|
||||||
|
This file is a part of the SteamWar software.
|
||||||
|
|
||||||
|
Copyright (C) 2021 SteamWar.de-Serverteam
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//
|
||||||
|
// Source code recreated from a .class file by IntelliJ IDEA
|
||||||
|
// (powered by FernFlower decompiler)
|
||||||
|
//
|
||||||
|
|
||||||
|
package org.bukkit.plugin.java;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
|
import org.apache.commons.lang.Validate;
|
||||||
|
import org.bukkit.plugin.InvalidPluginException;
|
||||||
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
|
import org.bukkit.plugin.SimplePluginManager;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
import java.security.CodeSigner;
|
||||||
|
import java.security.CodeSource;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.jar.JarEntry;
|
||||||
|
import java.util.jar.JarFile;
|
||||||
|
import java.util.jar.Manifest;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
final class PluginClassLoader extends URLClassLoader {
|
||||||
|
|
||||||
|
static PluginClassLoader current;
|
||||||
|
|
||||||
|
final JavaPluginLoader loader;
|
||||||
|
private final Map<String, Class<?>> classes = new ConcurrentHashMap();
|
||||||
|
final PluginDescriptionFile description;
|
||||||
|
final File dataFolder;
|
||||||
|
final File file;
|
||||||
|
private final JarFile jar;
|
||||||
|
private final Manifest manifest;
|
||||||
|
private final URL url;
|
||||||
|
final JavaPlugin plugin;
|
||||||
|
private JavaPlugin pluginInit;
|
||||||
|
private IllegalStateException pluginState;
|
||||||
|
private final Set<String> seenIllegalAccess = Collections.newSetFromMap(new ConcurrentHashMap());
|
||||||
|
|
||||||
|
static {
|
||||||
|
ClassLoader.registerAsParallelCapable();
|
||||||
|
}
|
||||||
|
|
||||||
|
PluginClassLoader( JavaPluginLoader loader, ClassLoader parent, PluginDescriptionFile description, File dataFolder, File file) throws IOException, InvalidPluginException, MalformedURLException {
|
||||||
|
super(new URL[]{file.toURI().toURL()}, parent);
|
||||||
|
Validate.notNull(loader, "Loader cannot be null");
|
||||||
|
this.loader = loader;
|
||||||
|
this.description = description;
|
||||||
|
this.dataFolder = dataFolder;
|
||||||
|
this.file = file;
|
||||||
|
this.jar = new JarFile(file);
|
||||||
|
this.manifest = this.jar.getManifest();
|
||||||
|
this.url = file.toURI().toURL();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Class jarClass;
|
||||||
|
try {
|
||||||
|
jarClass = Class.forName(description.getMain(), true, this);
|
||||||
|
} catch (ClassNotFoundException var10) {
|
||||||
|
throw new InvalidPluginException("Cannot find main class `" + description.getMain() + "'", var10);
|
||||||
|
}
|
||||||
|
|
||||||
|
Class pluginClass;
|
||||||
|
try {
|
||||||
|
pluginClass = jarClass.asSubclass(JavaPlugin.class);
|
||||||
|
} catch (ClassCastException var9) {
|
||||||
|
throw new InvalidPluginException("main class `" + description.getMain() + "' does not extend JavaPlugin", var9);
|
||||||
|
}
|
||||||
|
|
||||||
|
current = this;
|
||||||
|
this.plugin = (JavaPlugin)pluginClass.newInstance();
|
||||||
|
} catch (IllegalAccessException var11) {
|
||||||
|
throw new InvalidPluginException("No public constructor", var11);
|
||||||
|
} catch (InstantiationException var12) {
|
||||||
|
throw new InvalidPluginException("Abnormal plugin type", var12);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public URL getResource(String name) {
|
||||||
|
return this.findResource(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Enumeration<URL> getResources(String name) throws IOException {
|
||||||
|
return this.findResources(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Class<?> findClass(String name) throws ClassNotFoundException {
|
||||||
|
return this.findClass(name, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
Class<?> findClass( String name, boolean checkGlobal) throws ClassNotFoundException {
|
||||||
|
if (!name.startsWith("org.bukkit.") && !name.startsWith("net.minecraft.")) {
|
||||||
|
Class<?> result = (Class)this.classes.get(name);
|
||||||
|
if (result == null) {
|
||||||
|
if (checkGlobal) {
|
||||||
|
result = this.loader.getClassByName(name);
|
||||||
|
if (result != null) {
|
||||||
|
PluginDescriptionFile provider = ((PluginClassLoader)result.getClassLoader()).description;
|
||||||
|
if (provider != this.description && !this.seenIllegalAccess.contains(provider.getName()) && !((SimplePluginManager)this.loader.server.getPluginManager()).isTransitiveDepend(this.description, provider)) {
|
||||||
|
this.seenIllegalAccess.add(provider.getName());
|
||||||
|
if (this.plugin != null) {
|
||||||
|
this.plugin.getLogger().log(Level.WARNING, "Loaded class {0} from {1} which is not a depend, softdepend or loadbefore of this plugin.", new Object[]{name, provider.getFullName()});
|
||||||
|
} else {
|
||||||
|
this.loader.server.getLogger().log(Level.WARNING, "[{0}] Loaded class {1} from {2} which is not a depend, softdepend or loadbefore of this plugin.", new Object[]{this.description.getName(), name, provider.getFullName()});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result == null) {
|
||||||
|
String path = name.replace('.', '/').concat(".class");
|
||||||
|
JarEntry entry = this.jar.getJarEntry(path);
|
||||||
|
if (entry != null) {
|
||||||
|
byte[] classBytes;
|
||||||
|
String pkgName;
|
||||||
|
try {
|
||||||
|
Throwable var7 = null;
|
||||||
|
pkgName = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
InputStream is = this.jar.getInputStream(entry);
|
||||||
|
|
||||||
|
try {
|
||||||
|
classBytes = ByteStreams.toByteArray(is);
|
||||||
|
} finally {
|
||||||
|
if (is != null) {
|
||||||
|
is.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
} catch (Throwable var19) {
|
||||||
|
if (var7 == null) {
|
||||||
|
var7 = var19;
|
||||||
|
} else if (var7 != var19) {
|
||||||
|
var7.addSuppressed(var19);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw var19;
|
||||||
|
}
|
||||||
|
} catch (IOException var20) {
|
||||||
|
throw new ClassNotFoundException(name, var20);
|
||||||
|
}
|
||||||
|
|
||||||
|
classBytes = this.loader.server.getUnsafe().processClass(this.description, path, classBytes);
|
||||||
|
int dot = name.lastIndexOf(46);
|
||||||
|
if (dot != -1) {
|
||||||
|
pkgName = name.substring(0, dot);
|
||||||
|
if (this.getPackage(pkgName) == null) {
|
||||||
|
try {
|
||||||
|
if (this.manifest != null) {
|
||||||
|
this.definePackage(pkgName, this.manifest, this.url);
|
||||||
|
} else {
|
||||||
|
this.definePackage(pkgName, (String)null, (String)null, (String)null, (String)null, (String)null, (String)null, (URL)null);
|
||||||
|
}
|
||||||
|
} catch (IllegalArgumentException var21) {
|
||||||
|
if (this.getPackage(pkgName) == null) {
|
||||||
|
throw new IllegalStateException("Cannot find package " + pkgName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CodeSigner[] signers = entry.getCodeSigners();
|
||||||
|
CodeSource source = new CodeSource(this.url, signers);
|
||||||
|
result = this.defineClass(name, classBytes, 0, classBytes.length, source);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result == null) {
|
||||||
|
result = super.findClass(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result != null) {
|
||||||
|
this.loader.setClass(name, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.classes.put(name, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
} else {
|
||||||
|
throw new ClassNotFoundException(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close() throws IOException {
|
||||||
|
try {
|
||||||
|
super.close();
|
||||||
|
} finally {
|
||||||
|
this.jar.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Set<String> getClasses() {
|
||||||
|
return this.classes.keySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized void initialize( JavaPlugin javaPlugin) {
|
||||||
|
Validate.notNull(javaPlugin, "Initializing plugin cannot be null");
|
||||||
|
Validate.isTrue(javaPlugin.getClass().getClassLoader() == this, "Cannot initialize plugin outside of this class loader");
|
||||||
|
if (this.plugin == null && this.pluginInit == null) {
|
||||||
|
this.pluginState = new IllegalStateException("Initial initialization");
|
||||||
|
this.pluginInit = javaPlugin;
|
||||||
|
javaPlugin.init(this.loader, this.loader.server, this.description, this.dataFolder, this.file, this);
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("Plugin already initialized!", this.pluginState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -67,7 +67,6 @@ public class FightSystem extends JavaPlugin {
|
|||||||
new Permanent();
|
new Permanent();
|
||||||
new PistonListener();
|
new PistonListener();
|
||||||
new Chat();
|
new Chat();
|
||||||
new HotbarGUI();
|
|
||||||
new ArenaBorder();
|
new ArenaBorder();
|
||||||
new TeamArea();
|
new TeamArea();
|
||||||
new IngameDeath();
|
new IngameDeath();
|
||||||
|
@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
This file is a part of the SteamWar software.
|
||||||
|
|
||||||
|
Copyright (C) 2022 SteamWar.de-Serverteam
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.fightsystem.entity;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public interface PacketEntity {
|
||||||
|
void showPlayer(Player player);
|
||||||
|
void hidePlayer();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -103,12 +103,6 @@ public class FightSchematic extends StateDependent {
|
|||||||
setSchematic(publics.get(new Random().nextInt(publics.size())));
|
setSchematic(publics.get(new Random().nextInt(publics.size())));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!ArenaMode.Test.contains(Config.mode)){
|
|
||||||
FightPlayer leader = team.getLeader();
|
|
||||||
if(leader != null)
|
|
||||||
leader.getPlayer().getInventory().clear(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ArenaMode.AntiReplay.contains(Config.mode)) {
|
if(ArenaMode.AntiReplay.contains(Config.mode)) {
|
||||||
if(team.isBlue())
|
if(team.isBlue())
|
||||||
GlobalRecorder.getInstance().blueSchem(schematic);
|
GlobalRecorder.getInstance().blueSchem(schematic);
|
||||||
|
@ -23,6 +23,7 @@ import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
|||||||
import de.steamwar.fightsystem.ArenaMode;
|
import de.steamwar.fightsystem.ArenaMode;
|
||||||
import de.steamwar.fightsystem.Config;
|
import de.steamwar.fightsystem.Config;
|
||||||
import de.steamwar.fightsystem.FightSystem;
|
import de.steamwar.fightsystem.FightSystem;
|
||||||
|
import de.steamwar.fightsystem.commands.GUI;
|
||||||
import de.steamwar.fightsystem.countdown.Countdown;
|
import de.steamwar.fightsystem.countdown.Countdown;
|
||||||
import de.steamwar.fightsystem.listener.FightScoreboard;
|
import de.steamwar.fightsystem.listener.FightScoreboard;
|
||||||
import de.steamwar.fightsystem.listener.PersonalKitCreator;
|
import de.steamwar.fightsystem.listener.PersonalKitCreator;
|
||||||
@ -38,7 +39,6 @@ import net.md_5.bungee.api.ChatMessageType;
|
|||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
import org.bukkit.scoreboard.NameTagVisibility;
|
import org.bukkit.scoreboard.NameTagVisibility;
|
||||||
import org.bukkit.scoreboard.Team;
|
import org.bukkit.scoreboard.Team;
|
||||||
|
|
||||||
@ -47,6 +47,39 @@ import java.util.*;
|
|||||||
|
|
||||||
public class FightTeam {
|
public class FightTeam {
|
||||||
|
|
||||||
|
private static void setKitButton(HotbarKit kit, boolean leader) {
|
||||||
|
if (Kit.getAvailableKits(leader).size() > 1 || Config.PersonalKits)
|
||||||
|
kit.setItem(1, "CHOOSE_KIT", new ItemBuilder(Material.LEATHER_CHESTPLATE).removeAllAttributes().addEnchantment(Enchantment.DURABILITY, 1).build(), player -> GUI.kitSelection(player, ""));
|
||||||
|
else
|
||||||
|
kit.setItem(1, null, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final HotbarKit memberKit = new HotbarKit();
|
||||||
|
static {
|
||||||
|
setKitButton(memberKit, false);
|
||||||
|
memberKit.setItem(7, "RESPAWN", new ItemBuilder(Material.BEACON).removeAllAttributes().build(), player -> player.teleport(Objects.requireNonNull(Fight.getPlayerTeam(player)).getSpawn()));
|
||||||
|
}
|
||||||
|
private static final HotbarKit notReadyKit = new HotbarKit(memberKit);
|
||||||
|
static {
|
||||||
|
setKitButton(notReadyKit, true);
|
||||||
|
|
||||||
|
if(!ArenaMode.RankedEvent.contains(Config.mode)){
|
||||||
|
notReadyKit.setItem(2, "INVITE_PLAYERS", new ItemBuilder(Material.PAPER).removeAllAttributes().build(), GUI::chooseInvitation);
|
||||||
|
notReadyKit.setItem(3, "REMOVE_PLAYERS", new ItemBuilder(SWItem.getMaterial("FIREWORK_CHARGE")).removeAllAttributes().build(), GUI::chooseRemove);
|
||||||
|
}
|
||||||
|
|
||||||
|
notReadyKit.setItem(4, "TEAM_NOT_READY", new ItemBuilder(SWItem.getDye(10), (short) 10).removeAllAttributes().addEnchantment(Enchantment.DURABILITY, 1).build(), player -> Objects.requireNonNull(Fight.getPlayerTeam(player)).setReady(true));
|
||||||
|
}
|
||||||
|
private static final HotbarKit chooseSchemKit = new HotbarKit(notReadyKit);
|
||||||
|
static {
|
||||||
|
chooseSchemKit.setItem(4, "CHOOSE_SCHEMATIC", new ItemBuilder(SWItem.getMaterial("CAULDRON_ITEM")).removeAllAttributes().addEnchantment(Enchantment.DURABILITY, 1).build(), GUI::preSchemDialog);
|
||||||
|
}
|
||||||
|
private static final HotbarKit readyKit = new HotbarKit(memberKit);
|
||||||
|
static {
|
||||||
|
readyKit.setItem(1, null);
|
||||||
|
readyKit.setItem(4, "TEAM_READY", new ItemBuilder(SWItem.getDye(8), (short) 8).removeAllAttributes().addEnchantment(Enchantment.DURABILITY,1 ).build(), player -> Objects.requireNonNull(Fight.getPlayerTeam(player)).setReady(false));
|
||||||
|
}
|
||||||
|
|
||||||
private UUID designatedLeader;
|
private UUID designatedLeader;
|
||||||
private FightPlayer leader;
|
private FightPlayer leader;
|
||||||
private int schemRank;
|
private int schemRank;
|
||||||
@ -69,7 +102,7 @@ public class FightTeam {
|
|||||||
private final Region extendRegion;
|
private final Region extendRegion;
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public FightTeam(String name, String prefix, Location spawn, Region schemRegion, Region extendRegion, boolean rotate, boolean blue, UUID designatedLeader) {
|
public FightTeam(String name, String prefix, Location spawn, Region schemRegion, Region extendRegion, boolean rotate, boolean blue, UUID designatedLeader) { //TODO: Static TeamConfig object
|
||||||
this.spawn = spawn;
|
this.spawn = spawn;
|
||||||
this.schemRegion = schemRegion;
|
this.schemRegion = schemRegion;
|
||||||
this.extendRegion = extendRegion;
|
this.extendRegion = extendRegion;
|
||||||
@ -95,6 +128,10 @@ public class FightTeam {
|
|||||||
|
|
||||||
new OneShotStateDependent(ArenaMode.Restartable, FightState.PreLeaderSetup, () -> Bukkit.getScheduler().runTask(FightSystem.getPlugin(), this::reset));
|
new OneShotStateDependent(ArenaMode.Restartable, FightState.PreLeaderSetup, () -> Bukkit.getScheduler().runTask(FightSystem.getPlugin(), this::reset));
|
||||||
new OneShotStateDependent(Config.replayserver(), FightState.PreLeaderSetup, () -> Bukkit.getScheduler().runTask(FightSystem.getPlugin(), this::reset));
|
new OneShotStateDependent(Config.replayserver(), FightState.PreLeaderSetup, () -> Bukkit.getScheduler().runTask(FightSystem.getPlugin(), this::reset));
|
||||||
|
new OneShotStateDependent(ArenaMode.AntiTest, FightState.PostSchemSetup, () -> {
|
||||||
|
if(leader != null)
|
||||||
|
notReadyKit.loadToPlayer(leader.getPlayer());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPrefixAndName(String prefix, String name){
|
public void setPrefixAndName(String prefix, String name){
|
||||||
@ -216,9 +253,7 @@ public class FightTeam {
|
|||||||
player.getInventory().clear();
|
player.getInventory().clear();
|
||||||
BountifulWrapper.impl.setAttackSpeed(player);
|
BountifulWrapper.impl.setAttackSpeed(player);
|
||||||
player.teleport(spawn);
|
player.teleport(spawn);
|
||||||
if(Kit.getAvailableKits(false).size() > 1 || Config.PersonalKits)
|
memberKit.loadToPlayer(player);
|
||||||
player.getInventory().setItem(1, new ItemBuilder(Material.LEATHER_CHESTPLATE).removeAllAttributes().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName(FightSystem.getMessage().parse("CHOOSE_KIT", player)).build());
|
|
||||||
player.getInventory().setItem(7, new ItemBuilder(Material.BEACON).removeAllAttributes().setDisplayName(FightSystem.getMessage().parse("RESPAWN", player)).build());
|
|
||||||
GlobalRecorder.getInstance().playerJoins(player);
|
GlobalRecorder.getInstance().playerJoins(player);
|
||||||
TechHider.reloadChunks(player, chunksToReload, false);
|
TechHider.reloadChunks(player, chunksToReload, false);
|
||||||
|
|
||||||
@ -293,21 +328,10 @@ public class FightTeam {
|
|||||||
leader.setKit(Kit.getKitByName(Config.LeaderDefault));
|
leader.setKit(Kit.getKitByName(Config.LeaderDefault));
|
||||||
|
|
||||||
Player player = leader.getPlayer();
|
Player player = leader.getPlayer();
|
||||||
Inventory inventory = leader.getPlayer().getInventory();
|
|
||||||
if (Kit.getAvailableKits(true).size() > 1 || Config.PersonalKits)
|
|
||||||
inventory.setItem(1, new ItemBuilder(Material.LEATHER_CHESTPLATE).removeAllAttributes().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName(FightSystem.getMessage().parse("CHOOSE_KIT", player)).build());
|
|
||||||
else
|
|
||||||
inventory.setItem(1, new ItemBuilder(Material.AIR).build());
|
|
||||||
|
|
||||||
if(!ArenaMode.RankedEvent.contains(Config.mode)){
|
|
||||||
inventory.setItem(2, new ItemBuilder(Material.PAPER).removeAllAttributes().setDisplayName(FightSystem.getMessage().parse("INVITE_PLAYERS", player)).build());
|
|
||||||
inventory.setItem(3, new ItemBuilder(SWItem.getMaterial("FIREWORK_CHARGE")).removeAllAttributes().setDisplayName(FightSystem.getMessage().parse("REMOVE_PLAYERS", player)).build());
|
|
||||||
}
|
|
||||||
|
|
||||||
inventory.setItem(4, new ItemBuilder(SWItem.getDye(10), (short) 10).removeAllAttributes().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName(FightSystem.getMessage().parse("TEAM_NOT_READY", player)).build());
|
|
||||||
|
|
||||||
if(Config.test() || FightState.getFightState() != FightState.POST_SCHEM_SETUP)
|
if(Config.test() || FightState.getFightState() != FightState.POST_SCHEM_SETUP)
|
||||||
inventory.setItem(0, new ItemBuilder(SWItem.getMaterial("CAULDRON_ITEM")).removeAllAttributes().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName(FightSystem.getMessage().parse("CHOOSE_SCHEMATIC", player, Config.GameName)).build());
|
chooseSchemKit.loadToPlayer(player);
|
||||||
|
else
|
||||||
|
notReadyKit.loadToPlayer(player);
|
||||||
|
|
||||||
if(FightState.getFightState() == FightState.PRE_LEADER_SETUP && !Fight.getOpposite(this).isLeaderless()){
|
if(FightState.getFightState() == FightState.PRE_LEADER_SETUP && !Fight.getOpposite(this).isLeaderless()){
|
||||||
FightState.setFightState(FightState.PRE_SCHEM_SETUP);
|
FightState.setFightState(FightState.PRE_SCHEM_SETUP);
|
||||||
@ -363,13 +387,13 @@ public class FightTeam {
|
|||||||
|
|
||||||
this.ready = ready;
|
this.ready = ready;
|
||||||
if(ready) {
|
if(ready) {
|
||||||
l.getInventory().setItem(4, new ItemBuilder(SWItem.getDye(8), (short) 8).removeAllAttributes().addEnchantment(Enchantment.DURABILITY,1 ).setDisplayName(FightSystem.getMessage().parse("TEAM_READY", l)).build());
|
|
||||||
broadcast("TEAM_READY");
|
broadcast("TEAM_READY");
|
||||||
|
readyKit.loadToPlayer(l);
|
||||||
if(Fight.getOpposite(this).isReady() || ArenaMode.SoloLeader.contains(Config.mode))
|
if(Fight.getOpposite(this).isReady() || ArenaMode.SoloLeader.contains(Config.mode))
|
||||||
FightState.setFightState(FightState.PRE_RUNNING);
|
FightState.setFightState(FightState.PRE_RUNNING);
|
||||||
} else {
|
} else {
|
||||||
l.getInventory().setItem(4, new ItemBuilder(SWItem.getDye(10), (short) 10).removeAllAttributes().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName(FightSystem.getMessage().parse("TEAM_NOT_READY", l)).build());
|
|
||||||
broadcast("TEAM_NOT_READY");
|
broadcast("TEAM_NOT_READY");
|
||||||
|
notReadyKit.loadToPlayer(l);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -450,8 +474,6 @@ public class FightTeam {
|
|||||||
PersonalKitCreator.closeIfInKitCreator(player);
|
PersonalKitCreator.closeIfInKitCreator(player);
|
||||||
|
|
||||||
player.closeInventory();
|
player.closeInventory();
|
||||||
player.getInventory().clear();
|
|
||||||
Fight.setPlayerGamemode(player, GameMode.SURVIVAL);
|
|
||||||
fightPlayer.getKit().loadToPlayer(player);
|
fightPlayer.getKit().loadToPlayer(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
87
FightSystem_Core/src/de/steamwar/fightsystem/fight/HotbarKit.java
Normale Datei
87
FightSystem_Core/src/de/steamwar/fightsystem/fight/HotbarKit.java
Normale Datei
@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
This file is a part of the SteamWar software.
|
||||||
|
|
||||||
|
Copyright (C) 2022 SteamWar.de-Serverteam
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.fightsystem.fight;
|
||||||
|
|
||||||
|
import de.steamwar.fightsystem.ArenaMode;
|
||||||
|
import de.steamwar.fightsystem.Config;
|
||||||
|
import de.steamwar.fightsystem.FightSystem;
|
||||||
|
import de.steamwar.fightsystem.listener.PersonalKitCreator;
|
||||||
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
|
import de.steamwar.fightsystem.states.StateDependentListener;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public class HotbarKit extends Kit implements Listener {
|
||||||
|
|
||||||
|
private static final int HOTBAR_SIZE = 9;
|
||||||
|
|
||||||
|
private final String[] nameTags;
|
||||||
|
private final Consumer<Player>[] onClicks;
|
||||||
|
|
||||||
|
protected HotbarKit(String name, ItemStack[] inventory, ItemStack[] armor, Collection<PotionEffect> effects, String[] nameTags, Consumer<Player>[] onClicks) {
|
||||||
|
super(name, inventory, armor, effects);
|
||||||
|
this.nameTags = nameTags;
|
||||||
|
this.onClicks = onClicks;
|
||||||
|
new StateDependentListener(ArenaMode.AntiReplay, FightState.Setup, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public HotbarKit() {
|
||||||
|
this(null, new ItemStack[HOTBAR_SIZE], null, null, new String[HOTBAR_SIZE], new Consumer[HOTBAR_SIZE]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public HotbarKit(HotbarKit kit) {
|
||||||
|
this(kit.getName(), kit.getInventory().clone(), kit.getArmor().clone(), kit.getEffects(), kit.nameTags.clone(), kit.onClicks.clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setItem(int id, String nameTag, ItemStack stack, Consumer<Player> onClick) {
|
||||||
|
super.setItem(id, stack);
|
||||||
|
nameTags[id] = nameTag;
|
||||||
|
onClicks[id] = onClick;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized void loadToPlayer(Player player) {
|
||||||
|
for(int i = 0; i < HOTBAR_SIZE; i++) {
|
||||||
|
if(nameTags[i] != null)
|
||||||
|
Objects.requireNonNull(getInventory()[i].getItemMeta()).setDisplayName(FightSystem.getMessage().parse(nameTags[i], player, Config.GameName));
|
||||||
|
}
|
||||||
|
super.loadToPlayer(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void handlePlayerInteract(PlayerInteractEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
int slot = player.getInventory().getHeldItemSlot();
|
||||||
|
Kit activeKit = activeKits.get(player);
|
||||||
|
if(activeKit != this || PersonalKitCreator.inKitCreator(player) || getInventory()[slot] == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
event.setCancelled(true);
|
||||||
|
onClicks[slot].accept(player);
|
||||||
|
}
|
||||||
|
}
|
@ -50,6 +50,8 @@ public class Kit {
|
|||||||
private static final File kits = new File(FightSystem.getPlugin().getDataFolder(), Config.KitFile);
|
private static final File kits = new File(FightSystem.getPlugin().getDataFolder(), Config.KitFile);
|
||||||
private static final ArrayList<Kit> loadedKits = new ArrayList<>();
|
private static final ArrayList<Kit> loadedKits = new ArrayList<>();
|
||||||
|
|
||||||
|
protected static final Map<Player, Kit> activeKits = new HashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
if(!kits.exists()) {
|
if(!kits.exists()) {
|
||||||
Bukkit.getLogger().log(Level.SEVERE, "Kitconfig fehlend!" + kits.getAbsolutePath());
|
Bukkit.getLogger().log(Level.SEVERE, "Kitconfig fehlend!" + kits.getAbsolutePath());
|
||||||
@ -72,17 +74,29 @@ public class Kit {
|
|||||||
private final boolean leaderAllowed;
|
private final boolean leaderAllowed;
|
||||||
private final boolean memberAllowed;
|
private final boolean memberAllowed;
|
||||||
|
|
||||||
public Kit(String name, Player player) {
|
protected Kit(String name, ItemStack[] inventory, ItemStack[] armor, Collection<PotionEffect> effects) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.inventory = player.getInventory().getContents();
|
this.inventory = inventory;
|
||||||
this.armor = player.getInventory().getArmorContents();
|
this.armor = armor;
|
||||||
this.effects = player.getActivePotionEffects();
|
this.effects = effects;
|
||||||
this.leaderAllowed = true;
|
this.leaderAllowed = true;
|
||||||
this.memberAllowed = true;
|
this.memberAllowed = true;
|
||||||
this.enterStage = 0;
|
this.enterStage = 0;
|
||||||
this.tnt = true;
|
this.tnt = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Kit(Kit kit) {
|
||||||
|
this(kit.name, kit.inventory.clone(), kit.armor, kit.effects);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Kit(String name, Player player) {
|
||||||
|
this(name, player.getInventory().getContents(), player.getInventory().getArmorContents(), player.getActivePotionEffects());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Kit(PersonalKit kit){
|
||||||
|
this(kit.getName(), kit.getInventory(), kit.getArmor(), Collections.emptyList());
|
||||||
|
}
|
||||||
|
|
||||||
public Kit(ConfigurationSection kit){
|
public Kit(ConfigurationSection kit){
|
||||||
name = kit.getName();
|
name = kit.getName();
|
||||||
inventory = Objects.requireNonNull(kit.getList("Items")).toArray(new ItemStack[0]);
|
inventory = Objects.requireNonNull(kit.getList("Items")).toArray(new ItemStack[0]);
|
||||||
@ -100,15 +114,8 @@ public class Kit {
|
|||||||
tnt = kit.getBoolean("TNT", true);
|
tnt = kit.getBoolean("TNT", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Kit(PersonalKit kit){
|
protected void setItem(int id, ItemStack stack) {
|
||||||
this.name = kit.getName();
|
inventory[id] = stack;
|
||||||
this.inventory = kit.getInventory();
|
|
||||||
this.armor = kit.getArmor();
|
|
||||||
this.effects = Collections.emptyList();
|
|
||||||
this.leaderAllowed = true;
|
|
||||||
this.memberAllowed = true;
|
|
||||||
this.enterStage = 0;
|
|
||||||
this.tnt = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Kit getKitByName(String kitName) {
|
public static Kit getKitByName(String kitName) {
|
||||||
@ -153,6 +160,10 @@ public class Kit {
|
|||||||
return armor;
|
return armor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Collection<PotionEffect> getEffects() {
|
||||||
|
return effects;
|
||||||
|
}
|
||||||
|
|
||||||
/* Is this kit allowed to set/handle tnt? */
|
/* Is this kit allowed to set/handle tnt? */
|
||||||
public boolean isTnt(){
|
public boolean isTnt(){
|
||||||
return tnt;
|
return tnt;
|
||||||
@ -241,6 +252,9 @@ public class Kit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void loadToPlayer(Player player) {
|
public void loadToPlayer(Player player) {
|
||||||
|
activeKits.put(player, this);
|
||||||
|
|
||||||
|
player.getInventory().clear();
|
||||||
player.getInventory().setContents(inventory);
|
player.getInventory().setContents(inventory);
|
||||||
if(armor != null)
|
if(armor != null)
|
||||||
player.getInventory().setArmorContents(armor);
|
player.getInventory().setArmorContents(armor);
|
||||||
|
@ -1,76 +0,0 @@
|
|||||||
/*
|
|
||||||
This file is a part of the SteamWar software.
|
|
||||||
|
|
||||||
Copyright (C) 2020 SteamWar.de-Serverteam
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU Affero General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU Affero General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Affero General Public License
|
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.fightsystem.listener;
|
|
||||||
|
|
||||||
import de.steamwar.fightsystem.ArenaMode;
|
|
||||||
import de.steamwar.fightsystem.Config;
|
|
||||||
import de.steamwar.fightsystem.FightSystem;
|
|
||||||
import de.steamwar.fightsystem.commands.GUI;
|
|
||||||
import de.steamwar.fightsystem.fight.Fight;
|
|
||||||
import de.steamwar.fightsystem.fight.FightTeam;
|
|
||||||
import de.steamwar.fightsystem.states.FightState;
|
|
||||||
import de.steamwar.fightsystem.states.StateDependentListener;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
|
|
||||||
public class HotbarGUI implements Listener {
|
|
||||||
|
|
||||||
public HotbarGUI() {
|
|
||||||
new StateDependentListener(ArenaMode.AntiReplay, FightState.Setup, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void handlePlayerInteract(PlayerInteractEvent event) {
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
|
|
||||||
if(PersonalKitCreator.inKitCreator(player))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(event.getItem() == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
FightTeam fightTeam = Fight.getPlayerTeam(player);
|
|
||||||
if(fightTeam == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
ItemMeta itemMeta = event.getItem().getItemMeta();
|
|
||||||
String displayName = itemMeta.getDisplayName();
|
|
||||||
|
|
||||||
if(displayName == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
event.setCancelled(true);
|
|
||||||
onMatch(player, displayName, "CHOOSE_SCHEMATIC", () -> GUI.preSchemDialog(player), Config.GameName);
|
|
||||||
onMatch(player, displayName, "INVITE_PLAYERS", () -> GUI.chooseInvitation(player));
|
|
||||||
onMatch(player, displayName, "REMOVE_PLAYERS", () -> GUI.chooseRemove(player));
|
|
||||||
onMatch(player, displayName, "TEAM_NOT_READY", () -> fightTeam.setReady(true));
|
|
||||||
onMatch(player, displayName, "TEAM_READY", () -> fightTeam.setReady(false));
|
|
||||||
onMatch(player, displayName, "CHOOSE_KIT", () -> GUI.kitSelection(player, ""));
|
|
||||||
onMatch(player, displayName, "RESPAWN", () -> player.teleport(fightTeam.getSpawn()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void onMatch(Player player, String displayName, String message, Runnable run, Object... params) {
|
|
||||||
if(displayName.equals(FightSystem.getMessage().parse(message, player, params)))
|
|
||||||
run.run();
|
|
||||||
}
|
|
||||||
}
|
|
In neuem Issue referenzieren
Einen Benutzer sperren