mirror of
https://github.com/darksaid98/nightcore-spigot.git
synced 2026-12-04 14:38:46 +00:00
v2.5.2
This commit is contained in:
1 parent
0a8196eb8d
commit
722e9acf36
13 files changed
+173
-47
No files matched your search
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>su.nightexpress.nightcore</groupId>
|
<groupId>su.nightexpress.nightcore</groupId>
|
||||||
<artifactId>nightcore</artifactId>
|
<artifactId>nightcore</artifactId>
|
||||||
<version>2.5.1</version>
|
<version>2.5.2</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
|||||||
@@ -33,6 +33,10 @@ public interface NightCorePlugin extends Plugin {
|
|||||||
|
|
||||||
@NotNull PluginDetails getDetails();
|
@NotNull PluginDetails getDetails();
|
||||||
|
|
||||||
|
void extractResources(@NotNull String jarPath);
|
||||||
|
|
||||||
|
void extractResources(@NotNull String jarParh, @NotNull String toPath);
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
default String getNameLocalized() {
|
default String getNameLocalized() {
|
||||||
return this.getDetails().getName();
|
return this.getDetails().getName();
|
||||||
|
|||||||
@@ -9,12 +9,10 @@ import su.nightexpress.nightcore.config.FileConfig;
|
|||||||
import su.nightexpress.nightcore.config.PluginDetails;
|
import su.nightexpress.nightcore.config.PluginDetails;
|
||||||
import su.nightexpress.nightcore.language.LangManager;
|
import su.nightexpress.nightcore.language.LangManager;
|
||||||
import su.nightexpress.nightcore.menu.impl.AbstractMenu;
|
import su.nightexpress.nightcore.menu.impl.AbstractMenu;
|
||||||
import su.nightexpress.nightcore.util.Lists;
|
import su.nightexpress.nightcore.util.*;
|
||||||
import su.nightexpress.nightcore.util.Plugins;
|
|
||||||
import su.nightexpress.nightcore.util.Reflex;
|
|
||||||
import su.nightexpress.nightcore.util.Version;
|
|
||||||
import su.nightexpress.nightcore.util.wrapper.UniPermission;
|
import su.nightexpress.nightcore.util.wrapper.UniPermission;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
public abstract class NightPlugin extends JavaPlugin implements NightCorePlugin {
|
public abstract class NightPlugin extends JavaPlugin implements NightCorePlugin {
|
||||||
@@ -180,4 +178,24 @@ public abstract class NightPlugin extends JavaPlugin implements NightCorePlugin
|
|||||||
public final CommandManager getCommandManager() {
|
public final CommandManager getCommandManager() {
|
||||||
return this.commandManager;
|
return this.commandManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void extractResources(@NotNull String jarPath) {
|
||||||
|
this.extractResources(jarPath, this.getDataFolder() + jarPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void extractResources(@NotNull String jarPath, @NotNull String targetPath) {
|
||||||
|
File destination = new File(targetPath);
|
||||||
|
if (destination.exists()) return;
|
||||||
|
|
||||||
|
if (jarPath.startsWith("/")) {
|
||||||
|
jarPath = jarPath.substring(1);
|
||||||
|
}
|
||||||
|
if (jarPath.endsWith("/")) {
|
||||||
|
jarPath = jarPath.substring(0, jarPath.length() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
FileUtil.extractResources(this.getFile(), jarPath, destination);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -143,7 +143,7 @@ public abstract class AbstractCommand<P extends NightCorePlugin> implements Nigh
|
|||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public Collection<NightCommand> getChildrens() {
|
public Collection<NightCommand> getChildrens() {
|
||||||
return new HashSet<>(this.childrens.values());
|
return new ArrayList<>(this.childrens.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -26,14 +26,17 @@ import java.util.stream.IntStream;
|
|||||||
|
|
||||||
public class FileConfig extends YamlConfiguration {
|
public class FileConfig extends YamlConfiguration {
|
||||||
|
|
||||||
|
public static final String EXTENSION = ".yml";
|
||||||
|
|
||||||
private final File file;
|
private final File file;
|
||||||
private boolean isChanged = false;
|
private boolean changed;
|
||||||
|
|
||||||
public FileConfig(@NotNull String path, @NotNull String file) {
|
public FileConfig(@NotNull String path, @NotNull String file) {
|
||||||
this(new File(path, file));
|
this(new File(path, file));
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileConfig(@NotNull File file) {
|
public FileConfig(@NotNull File file) {
|
||||||
|
this.changed = false;
|
||||||
this.options().width(512);
|
this.options().width(512);
|
||||||
|
|
||||||
FileUtil.create(file);
|
FileUtil.create(file);
|
||||||
@@ -41,6 +44,20 @@ public class FileConfig extends YamlConfiguration {
|
|||||||
this.reload();
|
this.reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isConfig(@NotNull File file) {
|
||||||
|
return file.getName().endsWith(EXTENSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static String getName(@NotNull File file) {
|
||||||
|
String name = file.getName();
|
||||||
|
|
||||||
|
if (isConfig(file)) {
|
||||||
|
return name.substring(0, name.length() - EXTENSION.length());
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static FileConfig loadOrExtract(@NotNull NightCorePlugin plugin, @NotNull String path, @NotNull String file) {
|
public static FileConfig loadOrExtract(@NotNull NightCorePlugin plugin, @NotNull String path, @NotNull String file) {
|
||||||
if (!path.endsWith("/")) {
|
if (!path.endsWith("/")) {
|
||||||
@@ -61,8 +78,8 @@ public class FileConfig extends YamlConfiguration {
|
|||||||
InputStream input = plugin.getClass().getResourceAsStream(filePath);
|
InputStream input = plugin.getClass().getResourceAsStream(filePath);
|
||||||
if (input != null) FileUtil.copy(input, file);
|
if (input != null) FileUtil.copy(input, file);
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception exception) {
|
||||||
ex.printStackTrace();
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new FileConfig(file);
|
return new FileConfig(file);
|
||||||
@@ -70,23 +87,25 @@ public class FileConfig extends YamlConfiguration {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static List<FileConfig> loadAll(@NotNull String path) {
|
public static List<FileConfig> loadAll(@NotNull String path) {
|
||||||
return loadAll(path, false);
|
return FileUtil.getConfigFiles(path).stream().map(FileConfig::new).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
@Deprecated
|
||||||
public static List<FileConfig> loadAll(@NotNull String path, boolean deep) {
|
public static List<FileConfig> loadAll(@NotNull String path, boolean deep) {
|
||||||
return FileUtil.getFiles(path, deep).stream().filter(file -> file.getName().endsWith(".yml")).map(FileConfig::new).toList();
|
return loadAll(path);
|
||||||
|
//return FileUtil.getConfigFiles(path).stream().map(FileConfig::new).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initializeOptions(@NotNull Class<?> clazz) {
|
public void initializeOptions(@NotNull Class<?> clazz) {
|
||||||
initializeOptions(clazz, this);
|
initializeOptions(clazz, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void initializeOptions(@NotNull Class<?> clazz, @NotNull FileConfig cfg) {
|
public static void initializeOptions(@NotNull Class<?> clazz, @NotNull FileConfig config) {
|
||||||
for (ConfigValue<?> value : Reflex.getFields(clazz, ConfigValue.class)) {
|
for (ConfigValue<?> value : Reflex.getFields(clazz, ConfigValue.class)) {
|
||||||
value.read(cfg);
|
value.read(config);
|
||||||
}
|
}
|
||||||
cfg.saveChanges();
|
//config.saveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -104,17 +123,17 @@ public class FileConfig extends YamlConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean saveChanges() {
|
public boolean saveChanges() {
|
||||||
if (!this.isChanged) return false;
|
if (!this.changed) return false;
|
||||||
|
|
||||||
this.save();
|
this.save();
|
||||||
this.isChanged = false;
|
this.changed = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean reload() {
|
public boolean reload() {
|
||||||
try {
|
try {
|
||||||
this.load(this.file);
|
this.load(this.file);
|
||||||
this.isChanged = false;
|
this.changed = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (IOException | InvalidConfigurationException exception) {
|
catch (IOException | InvalidConfigurationException exception) {
|
||||||
@@ -146,7 +165,7 @@ public class FileConfig extends YamlConfiguration {
|
|||||||
value = en.name();
|
value = en.name();
|
||||||
}
|
}
|
||||||
super.set(path, value);
|
super.set(path, value);
|
||||||
this.isChanged = true;
|
this.changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setComments(@NotNull String path, @Nullable String... comments) {
|
public void setComments(@NotNull String path, @Nullable String... comments) {
|
||||||
@@ -162,7 +181,7 @@ public class FileConfig extends YamlConfiguration {
|
|||||||
if (this.getComments(path).equals(comments)) return;
|
if (this.getComments(path).equals(comments)) return;
|
||||||
|
|
||||||
super.setComments(path, comments);
|
super.setComments(path, comments);
|
||||||
this.isChanged = true;
|
this.changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import su.nightexpress.nightcore.language.entry.LangText;
|
|||||||
import su.nightexpress.nightcore.util.Placeholders;
|
import su.nightexpress.nightcore.util.Placeholders;
|
||||||
|
|
||||||
import static su.nightexpress.nightcore.util.Placeholders.*;
|
import static su.nightexpress.nightcore.util.Placeholders.*;
|
||||||
import static su.nightexpress.nightcore.language.tag.MessageTags.*;
|
|
||||||
import static su.nightexpress.nightcore.util.text.tag.Tags.*;
|
import static su.nightexpress.nightcore.util.text.tag.Tags.*;
|
||||||
|
|
||||||
public class CoreLang {
|
public class CoreLang {
|
||||||
@@ -33,8 +32,11 @@ public class CoreLang {
|
|||||||
public static final LangString COMMAND_CHECKPERM_DESC = LangString.of("Command.CheckPerm.Desc", "Print player permission info.");
|
public static final LangString COMMAND_CHECKPERM_DESC = LangString.of("Command.CheckPerm.Desc", "Print player permission info.");
|
||||||
public static final LangString COMMAND_CHECKPERM_USAGE = LangString.of("Command.CheckPerm.Usage", "<player>");
|
public static final LangString COMMAND_CHECKPERM_USAGE = LangString.of("Command.CheckPerm.Usage", "<player>");
|
||||||
|
|
||||||
public static final LangString COMMAND_RELOAD_DESC = LangString.of("Command.Reload.Desc", "Reload the plugin.");
|
public static final LangString COMMAND_RELOAD_DESC = LangString.of("Command.Reload.Desc",
|
||||||
public static final LangText COMMAND_RELOAD_DONE = LangText.of("Command.Reload.Done", "Plugin " + GREEN.enclose("reloaded") + "!");
|
"Reload the plugin.");
|
||||||
|
|
||||||
|
public static final LangText COMMAND_RELOAD_DONE = LangText.of("Command.Reload.Done",
|
||||||
|
LIGHT_GRAY.enclose("Plugin " + LIGHT_GREEN.enclose("reloaded") + "!"));
|
||||||
|
|
||||||
public static final LangString TIME_DAY = LangString.of("Time.Day", GENERIC_AMOUNT + "d.");
|
public static final LangString TIME_DAY = LangString.of("Time.Day", GENERIC_AMOUNT + "d.");
|
||||||
public static final LangString TIME_HOUR = LangString.of("Time.Hour", GENERIC_AMOUNT + "h.");
|
public static final LangString TIME_HOUR = LangString.of("Time.Hour", GENERIC_AMOUNT + "h.");
|
||||||
@@ -68,6 +70,7 @@ public class CoreLang {
|
|||||||
|
|
||||||
public static final LangText EDITOR_ACTION_EXIT = LangText.of("Editor.Action.Exit",
|
public static final LangText EDITOR_ACTION_EXIT = LangText.of("Editor.Action.Exit",
|
||||||
TAG_NO_PREFIX,
|
TAG_NO_PREFIX,
|
||||||
|
"",
|
||||||
GRAY.enclose("Click " +
|
GRAY.enclose("Click " +
|
||||||
CLICK.enclose(
|
CLICK.enclose(
|
||||||
ClickEvent.Action.RUN_COMMAND,
|
ClickEvent.Action.RUN_COMMAND,
|
||||||
@@ -75,7 +78,7 @@ public class CoreLang {
|
|||||||
"/" + Dialog.EXIT
|
"/" + Dialog.EXIT
|
||||||
)
|
)
|
||||||
+ " to leave input mode."),
|
+ " to leave input mode."),
|
||||||
" ");
|
"");
|
||||||
|
|
||||||
public static final LangString EDITOR_INPUT_HEADER_MAIN = LangString.of("Editor.Input.Header.Main", GREEN.enclose(BOLD.enclose("Input Mode")));
|
public static final LangString EDITOR_INPUT_HEADER_MAIN = LangString.of("Editor.Input.Header.Main", GREEN.enclose(BOLD.enclose("Input Mode")));
|
||||||
public static final LangString EDITOR_INPUT_HEADER_ERROR = LangString.of("Editor.Input.Header.Error", RED.enclose(BOLD.enclose("ERROR")));
|
public static final LangString EDITOR_INPUT_HEADER_ERROR = LangString.of("Editor.Input.Header.Error", RED.enclose(BOLD.enclose("ERROR")));
|
||||||
|
|||||||
@@ -3,15 +3,13 @@ package su.nightexpress.nightcore.language;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import su.nightexpress.nightcore.NightCorePlugin;
|
import su.nightexpress.nightcore.NightCorePlugin;
|
||||||
import su.nightexpress.nightcore.config.FileConfig;
|
import su.nightexpress.nightcore.config.FileConfig;
|
||||||
import su.nightexpress.nightcore.manager.SimpleManager;
|
|
||||||
import su.nightexpress.nightcore.language.entry.LangEntry;
|
import su.nightexpress.nightcore.language.entry.LangEntry;
|
||||||
import su.nightexpress.nightcore.util.FileUtil;
|
import su.nightexpress.nightcore.manager.SimpleManager;
|
||||||
import su.nightexpress.nightcore.util.Plugins;
|
import su.nightexpress.nightcore.util.Plugins;
|
||||||
import su.nightexpress.nightcore.util.Reflex;
|
import su.nightexpress.nightcore.util.Reflex;
|
||||||
import su.nightexpress.nightcore.util.StringUtil;
|
import su.nightexpress.nightcore.util.StringUtil;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
|
||||||
|
|
||||||
public class LangManager extends SimpleManager<NightCorePlugin> {
|
public class LangManager extends SimpleManager<NightCorePlugin> {
|
||||||
|
|
||||||
@@ -26,9 +24,10 @@ public class LangManager extends SimpleManager<NightCorePlugin> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onLoad() {
|
protected void onLoad() {
|
||||||
|
this.plugin.extractResources(DIR_LANG);
|
||||||
String langCode = this.plugin.getLanguage();
|
String langCode = this.plugin.getLanguage();
|
||||||
String realCode = this.extractConfig(langCode);
|
String realCode = this.validateConfig(langCode);
|
||||||
this.config = new FileConfig(this.plugin.getDataFolder() + DIR_LANG, this.getFileName(realCode));
|
this.config = FileConfig.loadOrExtract(this.plugin, DIR_LANG, this.getFileName(realCode));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -36,12 +35,30 @@ public class LangManager extends SimpleManager<NightCorePlugin> {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isPacked(@NotNull String filePath) {
|
||||||
|
if (!filePath.startsWith("/")) {
|
||||||
|
filePath = "/" + filePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
return plugin.getClass().getResourceAsStream(filePath) != null;
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private String extractConfig(@NotNull String langCode) {
|
private String validateConfig(@NotNull String langCode) {
|
||||||
String fileName = this.getFileName(langCode);
|
String fileName = this.getFileName(langCode);
|
||||||
|
|
||||||
File file = new File(plugin.getDataFolder() + DIR_LANG, fileName);
|
File file = new File(plugin.getDataFolder() + DIR_LANG, fileName);
|
||||||
if (file.exists()) return langCode;
|
if (!file.exists() && !isDefault(langCode)) {
|
||||||
|
if (this.isPacked(DIR_LANG + fileName)) {
|
||||||
|
return langCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.plugin.warn("Locale file for '" + langCode + "' language not found. Using default '" + DEFAULT_LANGUAGE + "' locale.");
|
||||||
|
return DEFAULT_LANGUAGE;
|
||||||
|
}
|
||||||
|
return langCode;
|
||||||
|
|
||||||
|
/*if (file.exists()) return langCode;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
InputStream input = plugin.getClass().getResourceAsStream(DIR_LANG + fileName);
|
InputStream input = plugin.getClass().getResourceAsStream(DIR_LANG + fileName);
|
||||||
@@ -55,7 +72,7 @@ public class LangManager extends SimpleManager<NightCorePlugin> {
|
|||||||
catch (Exception exception) {
|
catch (Exception exception) {
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
return isDefault(langCode) ? langCode : this.extractConfig(DEFAULT_LANGUAGE);
|
return isDefault(langCode) ? langCode : this.extractConfig(DEFAULT_LANGUAGE);
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadEntries(@NotNull Class<?> clazz) {
|
public void loadEntries(@NotNull Class<?> clazz) {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public abstract class AbstractFileData<P extends NightCorePlugin> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public AbstractFileData(@NotNull P plugin, @NotNull File file) {
|
public AbstractFileData(@NotNull P plugin, @NotNull File file) {
|
||||||
this(plugin, file, file.getName().replace(".yml", ""));
|
this(plugin, file, FileConfig.getName(file));
|
||||||
}
|
}
|
||||||
|
|
||||||
public AbstractFileData(@NotNull P plugin, @NotNull String filePath, @NotNull String id) {
|
public AbstractFileData(@NotNull P plugin, @NotNull String filePath, @NotNull String id) {
|
||||||
@@ -45,20 +45,15 @@ public abstract class AbstractFileData<P extends NightCorePlugin> {
|
|||||||
config.saveChanges();
|
config.saveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract boolean onLoad(@NotNull FileConfig cfg);
|
protected abstract boolean onLoad(@NotNull FileConfig config);
|
||||||
|
|
||||||
protected abstract void onSave(@NotNull FileConfig cfg);
|
protected abstract void onSave(@NotNull FileConfig config);
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public final File getFile() {
|
public final File getFile() {
|
||||||
return this.file;
|
return this.file;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*@NotNull
|
|
||||||
public P plugin() {
|
|
||||||
return this.plugin;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public final String getId() {
|
public final String getId() {
|
||||||
return this.id;
|
return this.id;
|
||||||
|
|||||||
@@ -21,14 +21,17 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||||||
|
|
||||||
public abstract class ConfigMenu<P extends NightCorePlugin> extends AbstractMenu<P> {
|
public abstract class ConfigMenu<P extends NightCorePlugin> extends AbstractMenu<P> {
|
||||||
|
|
||||||
|
protected static final String DEFAULT_ITEM_SECTION = "Content";
|
||||||
|
|
||||||
protected final FileConfig cfg;
|
protected final FileConfig cfg;
|
||||||
protected final Map<String, ItemHandler> handlerMap;
|
protected final Map<String, ItemHandler> handlerMap;
|
||||||
protected String itemSection = "Content";
|
protected String itemSection;
|
||||||
|
|
||||||
public ConfigMenu(@NotNull P plugin, @NotNull FileConfig cfg) {
|
public ConfigMenu(@NotNull P plugin, @NotNull FileConfig cfg) {
|
||||||
super(plugin);
|
super(plugin);
|
||||||
this.cfg = cfg;
|
this.cfg = cfg;
|
||||||
this.handlerMap = new HashMap<>();
|
this.handlerMap = new HashMap<>();
|
||||||
|
this.itemSection = DEFAULT_ITEM_SECTION;
|
||||||
|
|
||||||
this.addHandler(ItemHandler.forClose(this));
|
this.addHandler(ItemHandler.forClose(this));
|
||||||
if (this instanceof AutoFilled<?>) {
|
if (this instanceof AutoFilled<?>) {
|
||||||
|
|||||||
@@ -2,12 +2,21 @@ package su.nightexpress.nightcore.menu.link;
|
|||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import su.nightexpress.nightcore.menu.MenuViewer;
|
||||||
import su.nightexpress.nightcore.menu.api.Menu;
|
import su.nightexpress.nightcore.menu.api.Menu;
|
||||||
|
|
||||||
public interface Linked<T> extends Menu {
|
public interface Linked<T> extends Menu {
|
||||||
|
|
||||||
@NotNull ViewLink<T> getLink();
|
@NotNull ViewLink<T> getLink();
|
||||||
|
|
||||||
|
default T getLink(@NotNull MenuViewer viewer) {
|
||||||
|
return this.getLink(viewer.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
default T getLink(@NotNull Player player) {
|
||||||
|
return this.getLink().get(player);
|
||||||
|
}
|
||||||
|
|
||||||
default boolean open(@NotNull Player player, @NotNull T obj) {
|
default boolean open(@NotNull Player player, @NotNull T obj) {
|
||||||
this.getLink().set(player, obj);
|
this.getLink().set(player, obj);
|
||||||
|
|
||||||
|
|||||||
@@ -83,7 +83,6 @@ public class Colorizer {
|
|||||||
String start = matcher.group(1);
|
String start = matcher.group(1);
|
||||||
String end = matcher.group(3);
|
String end = matcher.group(3);
|
||||||
String content = matcher.group(2);
|
String content = matcher.group(2);
|
||||||
System.out.println("content legacy = " + content);
|
|
||||||
|
|
||||||
java.awt.Color colorStart = new java.awt.Color(Integer.parseInt(start, 16));
|
java.awt.Color colorStart = new java.awt.Color(Integer.parseInt(start, 16));
|
||||||
java.awt.Color colorEnd = new java.awt.Color(Integer.parseInt(end, 16));
|
java.awt.Color colorEnd = new java.awt.Color(Integer.parseInt(end, 16));
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package su.nightexpress.nightcore.util;
|
package su.nightexpress.nightcore.util;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import su.nightexpress.nightcore.config.FileConfig;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
@@ -8,7 +10,10 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Enumeration;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.jar.JarEntry;
|
||||||
|
import java.util.jar.JarFile;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class FileUtil {
|
public class FileUtil {
|
||||||
@@ -24,8 +29,8 @@ public class FileUtil {
|
|||||||
outputStream.close();
|
outputStream.close();
|
||||||
inputStream.close();
|
inputStream.close();
|
||||||
}
|
}
|
||||||
catch (IOException ex) {
|
catch (IOException exception) {
|
||||||
ex.printStackTrace();
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,14 +44,29 @@ public class FileUtil {
|
|||||||
try {
|
try {
|
||||||
return file.createNewFile();
|
return file.createNewFile();
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException exception) {
|
||||||
e.printStackTrace();
|
exception.printStackTrace();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static List<File> getConfigFiles(@NotNull String path) {
|
||||||
|
return getFiles(path, FileConfig.EXTENSION, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static List<File> getFiles(@NotNull String path) {
|
||||||
|
return getFiles(path, false);
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static List<File> getFiles(@NotNull String path, boolean deep) {
|
public static List<File> getFiles(@NotNull String path, boolean deep) {
|
||||||
|
return getFiles(path, null, deep);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static List<File> getFiles(@NotNull String path, @Nullable String extension, boolean deep) {
|
||||||
List<File> files = new ArrayList<>();
|
List<File> files = new ArrayList<>();
|
||||||
|
|
||||||
File folder = new File(path);
|
File folder = new File(path);
|
||||||
@@ -55,8 +75,10 @@ public class FileUtil {
|
|||||||
|
|
||||||
for (File file : listOfFiles) {
|
for (File file : listOfFiles) {
|
||||||
if (file.isFile()) {
|
if (file.isFile()) {
|
||||||
|
if (extension == null || file.getName().endsWith(extension)) {
|
||||||
files.add(file);
|
files.add(file);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if (file.isDirectory() && deep) {
|
else if (file.isDirectory() && deep) {
|
||||||
files.addAll(getFiles(file.getPath(), true));
|
files.addAll(getFiles(file.getPath(), true));
|
||||||
}
|
}
|
||||||
@@ -88,4 +110,41 @@ public class FileUtil {
|
|||||||
}
|
}
|
||||||
return dir.delete();
|
return dir.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void extractResources(@NotNull File pluginFile, @NotNull String fromPath, @NotNull File destination) {
|
||||||
|
if (!destination.exists()) {
|
||||||
|
if (!destination.mkdirs()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
JarFile jar = new JarFile(pluginFile);
|
||||||
|
Enumeration<JarEntry> entries = jar.entries();
|
||||||
|
|
||||||
|
while (entries.hasMoreElements()) {
|
||||||
|
JarEntry entry = entries.nextElement();
|
||||||
|
String path = entry.getName();
|
||||||
|
if (entry.isDirectory() || !path.startsWith(fromPath)) continue;
|
||||||
|
|
||||||
|
File file = new File(destination, path.replaceFirst(fromPath, ""));
|
||||||
|
if (file.exists()) continue;
|
||||||
|
|
||||||
|
FileUtil.create(file);
|
||||||
|
InputStream inputStream = jar.getInputStream(entry);
|
||||||
|
FileOutputStream outputStream = new FileOutputStream(file);
|
||||||
|
|
||||||
|
while (inputStream.available() > 0) {
|
||||||
|
outputStream.write(inputStream.read());
|
||||||
|
}
|
||||||
|
outputStream.close();
|
||||||
|
inputStream.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
jar.close();
|
||||||
|
}
|
||||||
|
catch (IOException exception) {
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -113,12 +113,12 @@ public class Players {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static String getPermissionGroup(@NotNull Player player) {
|
public static String getPermissionGroup(@NotNull Player player) {
|
||||||
return Plugins.hasVault() ? VaultHook.getPermissionGroup(player).toLowerCase() : Placeholders.DEFAULT;
|
return Plugins.hasVault() && VaultHook.hasPermissions() ? VaultHook.getPermissionGroup(player).toLowerCase() : Placeholders.DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static Set<String> getPermissionGroups(@NotNull Player player) {
|
public static Set<String> getPermissionGroups(@NotNull Player player) {
|
||||||
return Plugins.hasVault() ? VaultHook.getPermissionGroups(player) : Collections.emptySet();
|
return Plugins.hasVault() && VaultHook.hasPermissions() ? VaultHook.getPermissionGroups(player) : Set.of(Placeholders.DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
Reference in new issue
Block a user