- * 开始下载文件
- */
- public EagletTask start() {
- // create thread pool for download
- executorService = Executors.newFixedThreadPool(threadAmount);
- // check if is already running
- if (running) {
- throw new AlreadyStartException();
- }
- // start the monitor thread
- monitor = new Thread(() -> {
- lock.lock();
- // fire a new start event
- if (onStart != null) {
- onStart.handle(new StartEvent(this));
- }
- try {
- // create the target file
- if (!dest.exists()) {
- dest.createNewFile();
- }
- HttpURLConnection connection = (HttpURLConnection) url.openConnection();
- // set the connection properties
- httpHeader.forEach(connection::addRequestProperty);
- connection.setRequestMethod(requestMethod);
- connection.setConnectTimeout(30000);
- connection.setReadTimeout(30000);
- connection.connect();
- contentLength = connection.getContentLengthLong();
- // fire a new connected event
- // contains connection properties
- if (onConnected != null) {
- onConnected.handle(new ConnectedEvent(contentLength, this));
- }
- // if this is an unknown length task
- if (contentLength == -1 || threadAmount == 1) {
- // pass the connection instance to this new thread
- SingleThreadDownload download = new SingleThreadDownload(connection, dest, this);
- executorService.execute(download);
- long last = 0;
- do {
- Thread.sleep(500);
- // check the progress
- long progress = download.getCurrentProgress();
- // fire a new progress event
- if (onProgress != null) {
- onProgress.handle(new ProgressEvent(progress - last < 0 ? 0 : progress - last, this, ((double) progress) / Math.max((double) contentLength, 0D)));
- }
- last = progress;
- // check complete
- } while (last != contentLength && !download.isComplete());
- // close the thread pool, DoNotSupportMultipleThreadExceptionrelease resources
- executorService.shutdown();
- // change the running flag to false
- running = false;
- } else {
- List splitDownloads = new ArrayList<>();
- // Assign download task length
- long blockSize = contentLength / threadAmount;
- for (int threadId = 0; threadId < threadAmount; threadId++) {
- long startIndex = threadId * blockSize;
- long endIndex = (threadId + 1) * blockSize - 1;
- if (threadId == (threadAmount - 1)) {
- endIndex = contentLength - 1;
- }
- SplitDownload download = new SplitDownload(url, startIndex, endIndex, dest, this);
- // Start downloading
- executorService.execute(download);
- splitDownloads.add(download);
- }
- long last = 0;
- do {
- Thread.sleep(500);
- long progress = 0;
- // Collect download progress
- for (SplitDownload splitDownload : splitDownloads) {
- progress += splitDownload.getCurrentIndex() - splitDownload.startIndex;
- // blocked then restart from current index
- if (!splitDownload.isComplete() && System.currentTimeMillis() - splitDownload.getLastUpdateTime() > maxBlockingTime) {
- splitDownload.setStartIndex(splitDownload.getCurrentIndex());
- if (splitDownload.getRetry() <= maxRetry) {
- executorService.execute(splitDownload);
- } else {
- throw new RetryFailedException(this);
- }
- }
- }
- // Fire a progress event
- if (onProgress != null) {
- onProgress.handle(new ProgressEvent(progress - last, this,
- ((double) progress) / ((double) contentLength)));
- }
- last = progress;
- // check complete
- } while (last < contentLength);
- // close the thread pool, release resources
- executorService.shutdown();
- // change the running flag to false
- running = false;
- }
- // check hash
- if (md5 != null && !md5.equalsIgnoreCase(HashUtil.md5(dest))) {
- throw new HashNotMatchException();
- }
- if (sha1 != null && !sha1.equalsIgnoreCase(HashUtil.sha1(dest))) {
- throw new HashNotMatchException();
- }
- if (sha256 != null && !sha256.equalsIgnoreCase(HashUtil.sha256(dest))) {
- throw new HashNotMatchException();
- }
- if (onComplete != null) {
- onComplete.handle(new CompleteEvent(this, true));
- }
- } catch (Exception e) {
- onError.handle(new ErrorEvent(e, this));
- executorService.shutdown();
- if (onComplete != null) {
- onComplete.handle(new CompleteEvent(this, false));
- }
- } finally {
- lock.unlock();
- }
- }, "EagletTaskMonitor");
- monitor.start();
- return this;
- }
-
- public EagletTask waitUntil() {
- while (lock.tryLock()) {
- lock.unlock();
- }
- lock.lock();
- lock.unlock();
- return this;
- }
-
- public EagletTask waitFor(long timeout, TimeUnit unit) {
- while (lock.tryLock()) {
- lock.unlock();
- }
- try {
- lock.tryLock(timeout, unit);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- return this;
- }
-
- public EagletTask maxRetry(int maxRetry) {
- this.maxRetry = maxRetry;
- return this;
- }
-
- /**
- * Set the sha256 hash of the download file. Case is not sensitive.
- *
- * If the hash check failed, an error event will be fired.
- *
- * @param sha256 file sha1
- * @return task instance
- */
- public EagletTask sha256(String sha256) {
- this.sha256 = sha256;
- return this;
- }
-
- /**
- * Set the sha1 hash of the download file. Case is not sensitive.
- *
- * If the hash check failed, an error event will be fired.
- *
- * @param sha1 file sha1
- * @return task instance
- */
- public EagletTask sha1(String sha1) {
- this.sha1 = sha1;
- return this;
- }
-
- /**
- * Set the md5 hash of the download file. Case is not sensitive.
- *
- * If the hash check failed, an error event will be fired.
- *
- * @param md5 file md5
- * @return task instance
- */
- public EagletTask md5(String md5) {
- this.md5 = md5;
- return this;
- }
-
- /**
- * Set the max blocked time per download thread.
- *
- * If the thread blocks exceeded the provided time, this thread will re-start the task.
- *
- * @param maxBlockingTime time
- * @return task instance
- */
- private EagletTask maxBlocking(long maxBlockingTime) {
- this.maxBlockingTime = maxBlockingTime;
- return this;
- }
-
- /**
- * Set the progress handler
- *
- * This handler will be called every 1000 milli seconds.
- *
+ * 阻塞线程进行下载/加载
+ *
+ * @param type 依赖名,格式为 groupId:artifactId:version
+ * @return 是否成功加载库,如果加载成功,插件将可以任意调用使用的类
+ */
+ public static boolean requestLib(String type, String repo, String url) {
+ // 清理大小为 0 的依赖文件
+ File libFolder = new File(TabooLib.getPlugin().getDataFolder(), "/libs");
+ if (libFolder.exists()) {
+ Arrays.stream(libFolder.listFiles()).filter(listFile -> listFile.length() == 0).forEach(File::delete);
+ }
+ if (type.matches(".*:.*:.*")) {
+ String[] arr = type.split(":");
+ File file = new File(TabooLib.getPlugin().getDataFolder(), "/libs/" + String.join("-", arr) + ".jar");
+ if (file.exists()) {
+ TDependencyLoader.addToPath(TabooLib.getPlugin(), file);
+ return true;
+ } else {
+ if (downloadMaven(repo, arr[0], arr[1], arr[2], file, url)) {
+ TDependencyLoader.addToPath(TabooLib.getPlugin(), file);
+ return true;
+ } else {
+ return false;
+ }
+ }
+ }
+ return false;
+ }
+
+ private static boolean downloadMaven(String url, String groupId, String artifactId, String version, File target, String dl) {
+ Files.toFile(Files.readFromURL(dl.length() == 0 ? url + "/" + groupId.replace('.', '/') + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + ".jar" : dl, ""), Files.file(target));
+ return target.length() > 0;
+ }
+}
diff --git a/src/main/scala/io/izzel/taboolib/module/dependency/TDependencyInjector.java b/src/main/scala/io/izzel/taboolib/module/dependency/TDependencyInjector.java
new file mode 100644
index 0000000..c35294c
--- /dev/null
+++ b/src/main/scala/io/izzel/taboolib/module/dependency/TDependencyInjector.java
@@ -0,0 +1,40 @@
+package io.izzel.taboolib.module.dependency;
+
+import io.izzel.taboolib.TabooLibAPI;
+import io.izzel.taboolib.module.locale.TLocale;
+import org.bukkit.plugin.Plugin;
+
+/**
+ * @author Izzel_Aliz
+ */
+public class TDependencyInjector {
+
+ public static Dependency[] getDependencies(Class> clazz) {
+ Dependency[] dependencies = new Dependency[0];
+ Dependencies d = clazz.getAnnotation(Dependencies.class);
+ if (d != null) {
+ dependencies = d.value();
+ }
+ Dependency d2 = clazz.getAnnotation(Dependency.class);
+ if (d2 != null) {
+ dependencies = new Dependency[] {d2};
+ }
+ return dependencies;
+ }
+
+ public static void inject(Plugin plugin, Class> clazz) {
+ inject(plugin.getName(), clazz);
+ }
+
+ public static void inject(String name, Class> clazz) {
+ for (Dependency dependency : getDependencies(clazz)) {
+ if (dependency.type() == Dependency.Type.LIBRARY) {
+ if (TDependency.requestLib(dependency.maven(), dependency.mavenRepo(), dependency.url())) {
+ TabooLibAPI.debug(" Loaded " + String.join(":", dependency.maven()) + " (" + name + ")");
+ } else {
+ TLocale.Logger.warn("DEPENDENCY.LIBRARY-LOAD-FAIL", name, String.join(":", dependency.maven()));
+ }
+ }
+ }
+ }
+}
diff --git a/src/main/scala/com/ilummc/tlib/dependency/TDependencyLoader.java b/src/main/scala/io/izzel/taboolib/module/dependency/TDependencyLoader.java
similarity index 95%
rename from src/main/scala/com/ilummc/tlib/dependency/TDependencyLoader.java
rename to src/main/scala/io/izzel/taboolib/module/dependency/TDependencyLoader.java
index 3c52502..e9efb01 100644
--- a/src/main/scala/com/ilummc/tlib/dependency/TDependencyLoader.java
+++ b/src/main/scala/io/izzel/taboolib/module/dependency/TDependencyLoader.java
@@ -1,4 +1,4 @@
-package com.ilummc.tlib.dependency;
+package io.izzel.taboolib.module.dependency;
import org.bukkit.plugin.Plugin;
diff --git a/src/main/scala/me/skymc/taboolib/common/playercontainer/Container.java b/src/main/scala/io/izzel/taboolib/module/inject/Container.java
similarity index 88%
rename from src/main/scala/me/skymc/taboolib/common/playercontainer/Container.java
rename to src/main/scala/io/izzel/taboolib/module/inject/Container.java
index 2d9dcbf..c5319fe 100644
--- a/src/main/scala/me/skymc/taboolib/common/playercontainer/Container.java
+++ b/src/main/scala/io/izzel/taboolib/module/inject/Container.java
@@ -1,4 +1,4 @@
-package me.skymc.taboolib.common.playercontainer;
+package io.izzel.taboolib.module.inject;
/**
* @author sky
diff --git a/src/main/scala/me/skymc/taboolib/common/playercontainer/PlayerContainer.java b/src/main/scala/io/izzel/taboolib/module/inject/PlayerContainer.java
similarity index 87%
rename from src/main/scala/me/skymc/taboolib/common/playercontainer/PlayerContainer.java
rename to src/main/scala/io/izzel/taboolib/module/inject/PlayerContainer.java
index 3f35b81..a586d9d 100644
--- a/src/main/scala/me/skymc/taboolib/common/playercontainer/PlayerContainer.java
+++ b/src/main/scala/io/izzel/taboolib/module/inject/PlayerContainer.java
@@ -1,4 +1,4 @@
-package me.skymc.taboolib.common.playercontainer;
+package io.izzel.taboolib.module.inject;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
diff --git a/src/main/scala/me/skymc/taboolib/common/playercontainer/PlayerContainerLoader.java b/src/main/scala/io/izzel/taboolib/module/inject/PlayerContainerLoader.java
similarity index 84%
rename from src/main/scala/me/skymc/taboolib/common/playercontainer/PlayerContainerLoader.java
rename to src/main/scala/io/izzel/taboolib/module/inject/PlayerContainerLoader.java
index 5cbc001..7fff410 100644
--- a/src/main/scala/me/skymc/taboolib/common/playercontainer/PlayerContainerLoader.java
+++ b/src/main/scala/io/izzel/taboolib/module/inject/PlayerContainerLoader.java
@@ -1,9 +1,7 @@
-package me.skymc.taboolib.common.playercontainer;
+package io.izzel.taboolib.module.inject;
-import com.ilummc.tlib.logger.TLogger;
-import me.skymc.taboolib.TabooLib;
-import me.skymc.taboolib.TabooLibLoader;
-import org.bukkit.Bukkit;
+import io.izzel.taboolib.TabooLibLoader;
+import io.izzel.taboolib.module.locale.logger.TLogger;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@@ -21,13 +19,10 @@ import java.util.concurrent.ConcurrentHashMap;
* @Author sky
* @Since 2018-09-14 23:45
*/
+@TListener
public class PlayerContainerLoader implements Listener, TabooLibLoader.Loader {
- Map> pluginContainer = new ConcurrentHashMap<>();
-
- PlayerContainerLoader() {
- Bukkit.getPluginManager().registerEvents(this, TabooLib.instance());
- }
+ static Map> pluginContainer = new ConcurrentHashMap<>();
@Override
public void postLoad(Plugin plugin, Class> pluginClass) {
diff --git a/src/main/scala/me/skymc/taboolib/common/function/TFunction.java b/src/main/scala/io/izzel/taboolib/module/inject/TFunction.java
similarity index 90%
rename from src/main/scala/me/skymc/taboolib/common/function/TFunction.java
rename to src/main/scala/io/izzel/taboolib/module/inject/TFunction.java
index 4bc3925..15905d2 100644
--- a/src/main/scala/me/skymc/taboolib/common/function/TFunction.java
+++ b/src/main/scala/io/izzel/taboolib/module/inject/TFunction.java
@@ -1,4 +1,4 @@
-package me.skymc.taboolib.common.function;
+package io.izzel.taboolib.module.inject;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
diff --git a/src/main/scala/me/skymc/taboolib/common/function/TFunctionLoader.java b/src/main/scala/io/izzel/taboolib/module/inject/TFunctionLoader.java
similarity index 82%
rename from src/main/scala/me/skymc/taboolib/common/function/TFunctionLoader.java
rename to src/main/scala/io/izzel/taboolib/module/inject/TFunctionLoader.java
index 1ab3d4e..115dc33 100644
--- a/src/main/scala/me/skymc/taboolib/common/function/TFunctionLoader.java
+++ b/src/main/scala/io/izzel/taboolib/module/inject/TFunctionLoader.java
@@ -1,8 +1,8 @@
-package me.skymc.taboolib.common.function;
+package io.izzel.taboolib.module.inject;
-import com.ilummc.tlib.logger.TLogger;
-import me.skymc.taboolib.TabooLib;
-import me.skymc.taboolib.TabooLibLoader;
+import io.izzel.taboolib.TabooLibAPI;
+import io.izzel.taboolib.TabooLibLoader;
+import io.izzel.taboolib.module.locale.logger.TLogger;
import org.bukkit.plugin.Plugin;
import java.lang.reflect.Method;
@@ -26,7 +26,7 @@ public class TFunctionLoader implements TabooLibLoader.Loader {
}
method.setAccessible(true);
method.invoke(null);
- TabooLib.debug("Function " + pluginClass.getSimpleName() + " loaded. (" + plugin.getName() + ")");
+ TabooLibAPI.debug("Function " + pluginClass.getSimpleName() + " loaded. (" + plugin.getName() + ")");
} catch (NoSuchMethodException ignore) {
} catch (Exception e) {
TLogger.getGlobalLogger().warn("TFunction load Failed: " + pluginClass.getName());
@@ -47,7 +47,7 @@ public class TFunctionLoader implements TabooLibLoader.Loader {
}
method.setAccessible(true);
method.invoke(null);
- TabooLib.debug("Function " + pluginClass.getSimpleName() + " unloaded. (" + plugin.getName() + ")");
+ TabooLibAPI.debug("Function " + pluginClass.getSimpleName() + " unloaded. (" + plugin.getName() + ")");
} catch (NoSuchMethodException ignore) {
} catch (Exception e) {
TLogger.getGlobalLogger().warn("TFunction unload Failed: " + pluginClass.getName());
diff --git a/src/main/scala/me/skymc/taboolib/common/inject/TInject.java b/src/main/scala/io/izzel/taboolib/module/inject/TInject.java
similarity index 89%
rename from src/main/scala/me/skymc/taboolib/common/inject/TInject.java
rename to src/main/scala/io/izzel/taboolib/module/inject/TInject.java
index c1d9e5d..08b617e 100644
--- a/src/main/scala/me/skymc/taboolib/common/inject/TInject.java
+++ b/src/main/scala/io/izzel/taboolib/module/inject/TInject.java
@@ -1,4 +1,4 @@
-package me.skymc.taboolib.common.inject;
+package io.izzel.taboolib.module.inject;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
diff --git a/src/main/scala/me/skymc/taboolib/common/inject/TInjectLoader.java b/src/main/scala/io/izzel/taboolib/module/inject/TInjectLoader.java
similarity index 77%
rename from src/main/scala/me/skymc/taboolib/common/inject/TInjectLoader.java
rename to src/main/scala/io/izzel/taboolib/module/inject/TInjectLoader.java
index d0423bb..acb4189 100644
--- a/src/main/scala/me/skymc/taboolib/common/inject/TInjectLoader.java
+++ b/src/main/scala/io/izzel/taboolib/module/inject/TInjectLoader.java
@@ -1,15 +1,15 @@
-package me.skymc.taboolib.common.inject;
+package io.izzel.taboolib.module.inject;
import com.google.common.collect.Maps;
-import com.ilummc.tlib.logger.TLogger;
-import me.skymc.taboolib.TabooLib;
-import me.skymc.taboolib.TabooLibLoader;
-import me.skymc.taboolib.commands.builder.SimpleCommandBuilder;
-import me.skymc.taboolib.common.configuration.TConfiguration;
-import me.skymc.taboolib.common.packet.TPacketHandler;
-import me.skymc.taboolib.common.packet.TPacketListener;
-import me.skymc.taboolib.cooldown.seconds.CooldownPack2;
-import me.skymc.taboolib.cooldown.seconds.CooldownUtils2;
+import io.izzel.taboolib.TabooLibAPI;
+import io.izzel.taboolib.TabooLibLoader;
+import io.izzel.taboolib.module.command.lite.CommandBuilder;
+import io.izzel.taboolib.module.config.TConfig;
+import io.izzel.taboolib.module.locale.logger.TLogger;
+import io.izzel.taboolib.module.packet.TPacketHandler;
+import io.izzel.taboolib.module.packet.TPacketListener;
+import io.izzel.taboolib.util.lite.cooldown.Cooldown;
+import io.izzel.taboolib.util.lite.cooldown.Cooldowns;
import org.bukkit.plugin.Plugin;
import java.lang.reflect.Field;
@@ -50,17 +50,17 @@ public class TInjectLoader implements TabooLibLoader.Loader {
}
});
// TConfiguration Inject
- injectTypes.put(TConfiguration.class, (plugin, field, args, instance) -> {
+ injectTypes.put(TConfig.class, (plugin, field, args, instance) -> {
try {
- field.set(instance, TConfiguration.createInResource(plugin, args.length == 0 ? "config.yml" : args[0]));
+ field.set(instance, TConfig.create(plugin, args.length == 0 ? "config.yml" : args[0]));
} catch (Exception e) {
e.printStackTrace();
}
});
// SimpleCommandBuilder Inject
- injectTypes.put(SimpleCommandBuilder.class, (plugin, field, args, instance) -> {
+ injectTypes.put(CommandBuilder.class, (plugin, field, args, instance) -> {
try {
- SimpleCommandBuilder builder = (SimpleCommandBuilder) field.get(instance);
+ CommandBuilder builder = (CommandBuilder) field.get(instance);
if (builder.isBuild()) {
TLogger.getGlobalLogger().error("Command was registered. (" + field.getType().getName() + ")");
} else {
@@ -74,9 +74,9 @@ public class TInjectLoader implements TabooLibLoader.Loader {
}
});
// CooldownPack Inject
- injectTypes.put(CooldownPack2.class, (plugin, field, args, instance) -> {
+ injectTypes.put(Cooldown.class, (plugin, field, args, instance) -> {
try {
- CooldownUtils2.register((CooldownPack2) field.get(instance), plugin);
+ Cooldowns.register((Cooldown) field.get(instance), plugin);
} catch (Throwable t) {
t.printStackTrace();
}
@@ -103,7 +103,7 @@ public class TInjectLoader implements TabooLibLoader.Loader {
if (pluginClass.equals(plugin.getClass())) {
instance = plugin;
} else {
- TLogger.getGlobalLogger().error(declaredField.getName() + " is not a static field. (" + declaredField.getType().getName() + ")");
+ TLogger.getGlobalLogger().error(declaredField.getName() + " is not a static field. (" + pluginClass.getName() + ")");
continue;
}
}
@@ -125,7 +125,7 @@ public class TInjectLoader implements TabooLibLoader.Loader {
if (pluginClass.equals(plugin.getClass())) {
instance = plugin;
} else {
- TLogger.getGlobalLogger().error(declaredField.getName() + " is not a static field. (" + declaredField.getType().getName() + ")");
+ TLogger.getGlobalLogger().error(declaredField.getName() + " is not a static field. (" + pluginClass.getName() + ")");
continue;
}
}
@@ -133,7 +133,7 @@ public class TInjectLoader implements TabooLibLoader.Loader {
if (tInjectTask != null) {
inject(plugin, declaredField, instance, annotation, tInjectTask);
} else {
- TLogger.getGlobalLogger().error(declaredField.getName() + " is an invalid inject type. (" + declaredField.getType().getName() + ")");
+ TLogger.getGlobalLogger().error(declaredField.getName() + " is an invalid inject type. (" + pluginClass.getName() + ")");
}
}
}
@@ -142,7 +142,7 @@ public class TInjectLoader implements TabooLibLoader.Loader {
try {
field.setAccessible(true);
injectTask.run(plugin, field, annotation.value(), instance);
- TabooLib.debug(field.getName() + " injected. (" + field.getType().getName() + ")");
+ TabooLibAPI.debug(field.getName() + " injected. (" + field.getType().getName() + ")");
} catch (Throwable e) {
TLogger.getGlobalLogger().error(field.getName() + " inject failed: " + e.getMessage() + " (" + field.getType().getName() + ")");
if (e.getMessage() == null) {
diff --git a/src/main/scala/me/skymc/taboolib/common/inject/TInjectTask.java b/src/main/scala/io/izzel/taboolib/module/inject/TInjectTask.java
similarity index 84%
rename from src/main/scala/me/skymc/taboolib/common/inject/TInjectTask.java
rename to src/main/scala/io/izzel/taboolib/module/inject/TInjectTask.java
index 8dc7b76..e0f342a 100644
--- a/src/main/scala/me/skymc/taboolib/common/inject/TInjectTask.java
+++ b/src/main/scala/io/izzel/taboolib/module/inject/TInjectTask.java
@@ -1,4 +1,4 @@
-package me.skymc.taboolib.common.inject;
+package io.izzel.taboolib.module.inject;
import org.bukkit.plugin.Plugin;
diff --git a/src/main/scala/me/skymc/taboolib/listener/TListener.java b/src/main/scala/io/izzel/taboolib/module/inject/TListener.java
similarity index 94%
rename from src/main/scala/me/skymc/taboolib/listener/TListener.java
rename to src/main/scala/io/izzel/taboolib/module/inject/TListener.java
index 2ce6682..4f2d4ae 100644
--- a/src/main/scala/me/skymc/taboolib/listener/TListener.java
+++ b/src/main/scala/io/izzel/taboolib/module/inject/TListener.java
@@ -1,4 +1,4 @@
-package me.skymc.taboolib.listener;
+package io.izzel.taboolib.module.inject;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
diff --git a/src/main/scala/me/skymc/taboolib/listener/TListenerHandler.java b/src/main/scala/io/izzel/taboolib/module/inject/TListenerHandler.java
similarity index 77%
rename from src/main/scala/me/skymc/taboolib/listener/TListenerHandler.java
rename to src/main/scala/io/izzel/taboolib/module/inject/TListenerHandler.java
index 92243bd..2d2bd62 100644
--- a/src/main/scala/me/skymc/taboolib/listener/TListenerHandler.java
+++ b/src/main/scala/io/izzel/taboolib/module/inject/TListenerHandler.java
@@ -1,18 +1,15 @@
-package me.skymc.taboolib.listener;
+package io.izzel.taboolib.module.inject;
-import com.ilummc.tlib.logger.TLogger;
-import com.ilummc.tlib.util.Strings;
-import me.skymc.taboolib.TabooLib;
-import me.skymc.taboolib.TabooLibLoader;
-import me.skymc.taboolib.cronus.util.StringExpression;
-import me.skymc.taboolib.events.TPluginEnableEvent;
-import me.skymc.taboolib.methods.ReflectionUtils;
+import io.izzel.taboolib.TabooLibAPI;
+import io.izzel.taboolib.TabooLibLoader;
+import io.izzel.taboolib.Version;
+import io.izzel.taboolib.module.locale.logger.TLogger;
+import io.izzel.taboolib.cronus.util.StringExpression;
+import io.izzel.taboolib.util.Strings;
+import io.izzel.taboolib.util.Reflection;
import org.bukkit.Bukkit;
-import org.bukkit.event.EventHandler;
-import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
-import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.plugin.Plugin;
import java.lang.reflect.Method;
@@ -22,8 +19,7 @@ import java.util.*;
* @Author sky
* @Since 2018-08-22 13:48
*/
-@TListener
-public class TListenerHandler implements Listener {
+public class TListenerHandler {
private static HashMap> listeners = new HashMap<>();
@@ -52,7 +48,7 @@ public class TListenerHandler implements Listener {
try {
TListener tListener = pluginClass.getAnnotation(TListener.class);
// 检查版本
- if (!new StringExpression(tListener.version()).isSelect(TabooLib.getVersionNumber())) {
+ if (!new StringExpression(tListener.version()).isSelect(Version.getCurrentVersion().getVersionInt())) {
continue;
}
// 检查注册条件
@@ -62,16 +58,16 @@ public class TListenerHandler implements Listener {
}
}
// 实例化监听器
- Listener listener = plugin.getClass().equals(pluginClass) ? (Listener) plugin : (Listener) ReflectionUtils.instantiateObject(pluginClass);
+ Listener listener = plugin.getClass().equals(pluginClass) ? (Listener) plugin : (Listener) Reflection.instantiateObject(pluginClass);
try {
listeners.computeIfAbsent(plugin.getName(), name -> new ArrayList<>()).add(listener);
- TabooLib.debug("Listener " + listener.getClass().getSimpleName() + " setup successfully. (" + plugin.getName() + ")");
+ TabooLibAPI.debug("Listener " + listener.getClass().getSimpleName() + " setup successfully. (" + plugin.getName() + ")");
} catch (Exception e) {
TLogger.getGlobalLogger().warn("TListener setup Failed: " + pluginClass.getName());
e.printStackTrace();
}
} catch (Exception e) {
- TabooLib.debug("Listener " + pluginClass.getSimpleName() + "(" + plugin.getName() + ")" + " setup failed: " + e.toString());
+ TabooLibAPI.debug("Listener " + pluginClass.getSimpleName() + "(" + plugin.getName() + ")" + " setup failed: " + e.toString());
}
}
}
@@ -124,7 +120,7 @@ public class TListenerHandler implements Listener {
}
// 注册监听
Bukkit.getPluginManager().registerEvents(listener, plugin);
- TabooLib.debug("Listener " + listener.getClass().getSimpleName() + " registered. (" + plugin.getName() + ")");
+ TabooLibAPI.debug("Listener " + listener.getClass().getSimpleName() + " registered. (" + plugin.getName() + ")");
}
});
}
@@ -169,21 +165,4 @@ public class TListenerHandler implements Listener {
public static HashMap> getListeners() {
return listeners;
}
-
- @EventHandler(priority = EventPriority.LOW)
- public void onPluginEnable(TPluginEnableEvent e) {
- try {
- setupListener(e.getPlugin());
- Bukkit.getScheduler().runTask(TabooLib.instance(), () -> registerListener(e.getPlugin()));
- } catch (Exception ignored) {
- }
- }
-
- @EventHandler
- public void onPluginDisable(PluginDisableEvent e) {
- try {
- cancelListener(e.getPlugin());
- } catch (Exception ignored) {
- }
- }
}
diff --git a/src/main/scala/me/skymc/taboolib/common/schedule/TSchedule.java b/src/main/scala/io/izzel/taboolib/module/inject/TSchedule.java
similarity index 90%
rename from src/main/scala/me/skymc/taboolib/common/schedule/TSchedule.java
rename to src/main/scala/io/izzel/taboolib/module/inject/TSchedule.java
index c83281d..90b1b7b 100644
--- a/src/main/scala/me/skymc/taboolib/common/schedule/TSchedule.java
+++ b/src/main/scala/io/izzel/taboolib/module/inject/TSchedule.java
@@ -1,4 +1,4 @@
-package me.skymc.taboolib.common.schedule;
+package io.izzel.taboolib.module.inject;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
diff --git a/src/main/scala/me/skymc/taboolib/common/schedule/TScheduleData.java b/src/main/scala/io/izzel/taboolib/module/inject/TScheduleData.java
similarity index 92%
rename from src/main/scala/me/skymc/taboolib/common/schedule/TScheduleData.java
rename to src/main/scala/io/izzel/taboolib/module/inject/TScheduleData.java
index 15ab627..befedce 100644
--- a/src/main/scala/me/skymc/taboolib/common/schedule/TScheduleData.java
+++ b/src/main/scala/io/izzel/taboolib/module/inject/TScheduleData.java
@@ -1,4 +1,4 @@
-package me.skymc.taboolib.common.schedule;
+package io.izzel.taboolib.module.inject;
import org.bukkit.scheduler.BukkitRunnable;
diff --git a/src/main/scala/me/skymc/taboolib/common/schedule/TScheduleLoader.java b/src/main/scala/io/izzel/taboolib/module/inject/TScheduleLoader.java
similarity index 69%
rename from src/main/scala/me/skymc/taboolib/common/schedule/TScheduleLoader.java
rename to src/main/scala/io/izzel/taboolib/module/inject/TScheduleLoader.java
index a093291..b6510bd 100644
--- a/src/main/scala/me/skymc/taboolib/common/schedule/TScheduleLoader.java
+++ b/src/main/scala/io/izzel/taboolib/module/inject/TScheduleLoader.java
@@ -1,14 +1,10 @@
-package me.skymc.taboolib.common.schedule;
+package io.izzel.taboolib.module.inject;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
-import com.ilummc.tlib.logger.TLogger;
-import me.skymc.taboolib.TabooLib;
-import me.skymc.taboolib.TabooLibLoader;
-import org.bukkit.Bukkit;
-import org.bukkit.event.EventHandler;
-import org.bukkit.event.Listener;
-import org.bukkit.event.server.PluginEnableEvent;
+import io.izzel.taboolib.TabooLib;
+import io.izzel.taboolib.TabooLibLoader;
+import io.izzel.taboolib.module.locale.logger.TLogger;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
@@ -16,18 +12,20 @@ import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.List;
import java.util.Map;
-import java.util.Optional;
/**
* @Author 坏黑
* @Since 2018-12-15 15:09
*/
-public class TScheduleLoader implements Listener, TabooLibLoader.Loader {
+public class TScheduleLoader implements TabooLibLoader.Loader {
- private Map> schedules = Maps.newHashMap();
+ static Map> schedules = Maps.newHashMap();
- TScheduleLoader() {
- Bukkit.getPluginManager().registerEvents(this, TabooLib.instance());
+ public static void run(Plugin plugin) {
+ List list = schedules.get(plugin.getName());
+ if (list != null) {
+ list.forEach(data -> run(plugin, data.getRunnable(), data.getAnnotation().delay(), data.getAnnotation().period(), data.getAnnotation().async()));
+ }
}
public static void run(Plugin plugin, BukkitRunnable runnable, int delay, int period, boolean async) {
@@ -38,13 +36,6 @@ public class TScheduleLoader implements Listener, TabooLibLoader.Loader {
}
}
- @EventHandler
- public void onEnable(PluginEnableEvent e) {
- Optional.ofNullable(schedules.remove(e.getPlugin().getName())).ifPresent(list -> list.forEach(scheduleData -> {
- run(e.getPlugin(), scheduleData.getRunnable(), scheduleData.getAnnotation().delay(), scheduleData.getAnnotation().period(), scheduleData.getAnnotation().async());
- }));
- }
-
@Override
public void postLoad(Plugin plugin, Class> loadClass) {
for (Method method : loadClass.getDeclaredMethods()) {
@@ -61,7 +52,7 @@ public class TScheduleLoader implements Listener, TabooLibLoader.Loader {
}
method.setAccessible(true);
// 如果是本插件
- if (plugin.equals(TabooLib.instance())) {
+ if (plugin.equals(TabooLib.getPlugin())) {
run(plugin, new BukkitRunnable() {
@Override
diff --git a/src/main/scala/me/skymc/taboolib/common/versioncontrol/SimpleClassVisitor.java b/src/main/scala/io/izzel/taboolib/module/lite/SimpleClassVisitor.java
similarity index 97%
rename from src/main/scala/me/skymc/taboolib/common/versioncontrol/SimpleClassVisitor.java
rename to src/main/scala/io/izzel/taboolib/module/lite/SimpleClassVisitor.java
index b17c54c..1cd94fe 100644
--- a/src/main/scala/me/skymc/taboolib/common/versioncontrol/SimpleClassVisitor.java
+++ b/src/main/scala/io/izzel/taboolib/module/lite/SimpleClassVisitor.java
@@ -1,4 +1,4 @@
-package me.skymc.taboolib.common.versioncontrol;
+package io.izzel.taboolib.module.lite;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.FieldVisitor;
diff --git a/src/main/scala/me/skymc/taboolib/common/util/SimpleCounter.java b/src/main/scala/io/izzel/taboolib/module/lite/SimpleCounter.java
similarity index 95%
rename from src/main/scala/me/skymc/taboolib/common/util/SimpleCounter.java
rename to src/main/scala/io/izzel/taboolib/module/lite/SimpleCounter.java
index 430857f..1630a61 100644
--- a/src/main/scala/me/skymc/taboolib/common/util/SimpleCounter.java
+++ b/src/main/scala/io/izzel/taboolib/module/lite/SimpleCounter.java
@@ -1,4 +1,4 @@
-package me.skymc.taboolib.common.util;
+package io.izzel.taboolib.module.lite;
/**
* @Author sky
diff --git a/src/main/scala/me/skymc/taboolib/inventory/TEquipment.java b/src/main/scala/io/izzel/taboolib/module/lite/SimpleEquip.java
similarity index 80%
rename from src/main/scala/me/skymc/taboolib/inventory/TEquipment.java
rename to src/main/scala/io/izzel/taboolib/module/lite/SimpleEquip.java
index 4e131ec..e6d16d0 100644
--- a/src/main/scala/me/skymc/taboolib/inventory/TEquipment.java
+++ b/src/main/scala/io/izzel/taboolib/module/lite/SimpleEquip.java
@@ -1,4 +1,4 @@
-package me.skymc.taboolib.inventory;
+package io.izzel.taboolib.module.lite;
import com.google.common.collect.Maps;
import org.bukkit.entity.Player;
@@ -12,7 +12,7 @@ import java.util.Map;
* @Author 坏黑
* @Since 2019-04-25 22:01
*/
-public enum TEquipment {
+public enum SimpleEquip {
HAND(EquipmentSlot.HAND, -1),
@@ -29,7 +29,7 @@ public enum TEquipment {
private EquipmentSlot bukkit;
private int slot;
- TEquipment(EquipmentSlot bukkit, int slot) {
+ SimpleEquip(EquipmentSlot bukkit, int slot) {
this.bukkit = bukkit;
this.slot = slot;
}
@@ -50,13 +50,13 @@ public enum TEquipment {
}
}
- public static TEquipment fromBukkit(EquipmentSlot bukkit) {
+ public static SimpleEquip fromBukkit(EquipmentSlot bukkit) {
return Arrays.stream(values()).filter(tEquipment -> tEquipment.bukkit == bukkit).findFirst().orElse(null);
}
- public static Map getItems(Player player) {
- Map map = Maps.newHashMap();
- for (TEquipment equipment : values()) {
+ public static Map getItems(Player player) {
+ Map map = Maps.newHashMap();
+ for (SimpleEquip equipment : values()) {
map.put(equipment, equipment.getItem(player));
}
return map;
diff --git a/src/main/scala/me/skymc/taboolib/common/util/SimpleI18n.java b/src/main/scala/io/izzel/taboolib/module/lite/SimpleI18n.java
similarity index 60%
rename from src/main/scala/me/skymc/taboolib/common/util/SimpleI18n.java
rename to src/main/scala/io/izzel/taboolib/module/lite/SimpleI18n.java
index 017cfcf..6053a3a 100644
--- a/src/main/scala/me/skymc/taboolib/common/util/SimpleI18n.java
+++ b/src/main/scala/io/izzel/taboolib/module/lite/SimpleI18n.java
@@ -1,13 +1,12 @@
-package me.skymc.taboolib.common.util;
+package io.izzel.taboolib.module.lite;
-import com.ilummc.tlib.resources.TLocaleLoader;
-import me.skymc.taboolib.Main;
-import me.skymc.taboolib.TabooLib;
-import me.skymc.taboolib.common.function.TFunction;
-import me.skymc.taboolib.common.nms.NMSHandler;
-import me.skymc.taboolib.common.nms.nbt.NBTCompound;
-import me.skymc.taboolib.fileutils.ConfigUtils;
-import me.skymc.taboolib.fileutils.FileUtils;
+import io.izzel.taboolib.TabooLib;
+import io.izzel.taboolib.Version;
+import io.izzel.taboolib.module.locale.TLocaleLoader;
+import io.izzel.taboolib.module.inject.TFunction;
+import io.izzel.taboolib.module.nms.NMS;
+import io.izzel.taboolib.module.nms.nbt.NBTCompound;
+import io.izzel.taboolib.util.Files;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Entity;
@@ -31,15 +30,15 @@ public class SimpleI18n {
private static boolean released;
static void init() {
- File localeFile = getLocaleFile(TabooLib.instance());
+ File localeFile = getLocaleFile(TabooLib.getPlugin());
if (localeFile == null) {
lang = new YamlConfiguration();
} else {
- lang = ConfigUtils.load(TabooLib.instance(), localeFile);
+ lang = Files.load(localeFile);
}
if (lang.getInt("version") < 3 && !released) {
released = true;
- FileUtils.deleteAllFile(new File(Main.getInst().getDataFolder(), "simpleI18n"));
+ Files.deepDelete(new File(TabooLib.getPlugin().getDataFolder(), "simpleI18n"));
init();
}
}
@@ -57,7 +56,7 @@ public class SimpleI18n {
}
public static String getName(Entity entity) {
- return entity == null ? "-" : lang.getString(NMSHandler.getHandler().getName(entity).replace(".", "_"), entity.getName());
+ return entity == null ? "-" : lang.getString(NMS.handle().getName(entity).replace(".", "_"), entity.getName());
}
public static String getName(ItemStack item) {
@@ -68,35 +67,35 @@ public class SimpleI18n {
if (itemMeta instanceof BookMeta && ((BookMeta) itemMeta).getTitle() != null) {
return ((BookMeta) itemMeta).getTitle();
}
- if (TabooLib.getVersionNumber() < 11100) {
+ if (!Version.isAfter(Version.v1_11)) {
if (item.getType().name().equals("MONSTER_EGG")) {
- NBTCompound nbtCompound = NMSHandler.getHandler().loadNBT(item);
+ NBTCompound nbtCompound = NMS.handle().loadNBT(item);
if (nbtCompound.containsKey("EntityTag")) {
return lang.getString("item_monsterPlacer_name") + " " + lang.getString("entity_" + nbtCompound.get("EntityTag").asCompound().get("id").asString() + "_name");
}
return lang.getString("item_monsterPlacer_name");
}
- } else if (TabooLib.getVersionNumber() < 11300) {
+ } else if (!Version.isAfter(Version.v1_13)) {
if (itemMeta instanceof SpawnEggMeta) {
String spawnEggType = lang.getString("entity_" + ((SpawnEggMeta) itemMeta).getSpawnedType().getEntityClass().getSimpleName().replace(".", "_") + "_name");
if (spawnEggType != null) {
- return lang.getString(NMSHandler.getHandler().getName(item).replace(".", "_"), item.getType().name().toLowerCase().replace("_", "")) + " " + spawnEggType;
+ return lang.getString(NMS.handle().getName(item).replace(".", "_"), item.getType().name().toLowerCase().replace("_", "")) + " " + spawnEggType;
}
}
}
- return lang.getString(NMSHandler.getHandler().getName(item).replace(".", "_"), item.getType().name().toLowerCase().replace("_", ""));
+ return lang.getString(NMS.handle().getName(item).replace(".", "_"), item.getType().name().toLowerCase().replace("_", ""));
}
private static void releaseLocales(Plugin plugin) {
- TLocaleLoader.getLocalePriority().stream().filter(localeName -> !new File(plugin.getDataFolder(), "simpleI18n/" + getVersion() + "/" + localeName + ".yml").exists() && plugin.getResource("simpleI18n/" + getVersion() + "/" + localeName + ".yml") != null).forEach(localeName -> plugin.saveResource("simpleI18n/" + getVersion() + "/" + localeName + ".yml", true));
+ TLocaleLoader.getLocalePriority().stream().filter(localeName -> !new File("plugins/TabooLib/simpleI18n/" + getVersion() + "/" + localeName + ".yml").exists() && plugin.getResource("simpleI18n/" + getVersion() + "/" + localeName + ".yml") != null).forEach(localeName -> plugin.saveResource("simpleI18n/" + getVersion() + "/" + localeName + ".yml", true));
}
private static File getLocaleFile(Plugin plugin) {
releaseLocales(plugin);
- return TLocaleLoader.getLocalePriority().stream().map(localeName -> new File(plugin.getDataFolder(), "simpleI18n/" + getVersion() + "/" + localeName + ".yml")).filter(File::exists).findFirst().orElse(null);
+ return TLocaleLoader.getLocalePriority().stream().map(localeName -> new File("plugins/TabooLib/simpleI18n/" + getVersion() + "/" + localeName + ".yml")).filter(File::exists).findFirst().orElse(null);
}
private static String getVersion() {
- return TabooLib.getVersionNumber() < 11300 ? "low" : "high";
+ return Version.isAfter(Version.v1_13) ? "high" : "low";
}
}
diff --git a/src/main/scala/me/skymc/taboolib/common/util/SimpleIterator.java b/src/main/scala/io/izzel/taboolib/module/lite/SimpleIterator.java
similarity index 96%
rename from src/main/scala/me/skymc/taboolib/common/util/SimpleIterator.java
rename to src/main/scala/io/izzel/taboolib/module/lite/SimpleIterator.java
index 88ce0be..f64f2c4 100644
--- a/src/main/scala/me/skymc/taboolib/common/util/SimpleIterator.java
+++ b/src/main/scala/io/izzel/taboolib/module/lite/SimpleIterator.java
@@ -1,4 +1,4 @@
-package me.skymc.taboolib.common.util;
+package io.izzel.taboolib.module.lite;
import com.google.common.collect.Lists;
diff --git a/src/main/scala/me/skymc/taboolib/common/versioncontrol/SimpleMethodVisitor.java b/src/main/scala/io/izzel/taboolib/module/lite/SimpleMethodVisitor.java
similarity index 98%
rename from src/main/scala/me/skymc/taboolib/common/versioncontrol/SimpleMethodVisitor.java
rename to src/main/scala/io/izzel/taboolib/module/lite/SimpleMethodVisitor.java
index 292d81a..8c61071 100644
--- a/src/main/scala/me/skymc/taboolib/common/versioncontrol/SimpleMethodVisitor.java
+++ b/src/main/scala/io/izzel/taboolib/module/lite/SimpleMethodVisitor.java
@@ -1,4 +1,4 @@
-package me.skymc.taboolib.common.versioncontrol;
+package io.izzel.taboolib.module.lite;
import org.objectweb.asm.*;
diff --git a/src/main/scala/me/skymc/taboolib/common/util/SimpleReflection.java b/src/main/scala/io/izzel/taboolib/module/lite/SimpleReflection.java
similarity index 99%
rename from src/main/scala/me/skymc/taboolib/common/util/SimpleReflection.java
rename to src/main/scala/io/izzel/taboolib/module/lite/SimpleReflection.java
index c499ada..5b0c8bf 100644
--- a/src/main/scala/me/skymc/taboolib/common/util/SimpleReflection.java
+++ b/src/main/scala/io/izzel/taboolib/module/lite/SimpleReflection.java
@@ -1,4 +1,4 @@
-package me.skymc.taboolib.common.util;
+package io.izzel.taboolib.module.lite;
import com.google.common.collect.Maps;
diff --git a/src/main/scala/me/skymc/taboolib/common/versioncontrol/SimpleVersionControl.java b/src/main/scala/io/izzel/taboolib/module/lite/SimpleVersionControl.java
similarity index 88%
rename from src/main/scala/me/skymc/taboolib/common/versioncontrol/SimpleVersionControl.java
rename to src/main/scala/io/izzel/taboolib/module/lite/SimpleVersionControl.java
index 1a1fc41..2e52361 100644
--- a/src/main/scala/me/skymc/taboolib/common/versioncontrol/SimpleVersionControl.java
+++ b/src/main/scala/io/izzel/taboolib/module/lite/SimpleVersionControl.java
@@ -1,10 +1,10 @@
-package me.skymc.taboolib.common.versioncontrol;
+package io.izzel.taboolib.module.lite;
import com.google.common.collect.Lists;
-import com.ilummc.tlib.util.asm.AsmClassLoader;
-import me.skymc.taboolib.Main;
-import me.skymc.taboolib.TabooLib;
-import me.skymc.taboolib.fileutils.FileUtils;
+import io.izzel.taboolib.TabooLib;
+import io.izzel.taboolib.Version;
+import io.izzel.taboolib.util.Files;
+import io.izzel.taboolib.util.asm.AsmClassLoader;
import org.bukkit.plugin.Plugin;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
@@ -35,11 +35,11 @@ public class SimpleVersionControl {
}
public static SimpleVersionControl create() {
- return new SimpleVersionControl().to(TabooLib.getVersion()).plugin(Main.getInst());
+ return new SimpleVersionControl().to(Version.getBukkitVersion()).plugin(TabooLib.getPlugin());
}
public static SimpleVersionControl create(String toVersion) {
- return new SimpleVersionControl().to(toVersion).plugin(Main.getInst());
+ return new SimpleVersionControl().to(toVersion).plugin(TabooLib.getPlugin());
}
public static SimpleVersionControl createSimple(String target, String... from) {
@@ -113,7 +113,7 @@ public class SimpleVersionControl {
if (useCache && cacheClasses.containsKey(target)) {
return cacheClasses.get(target);
}
- ClassReader classReader = new ClassReader(FileUtils.getResource(plugin, target.replace(".", "/") + ".class"));
+ ClassReader classReader = new ClassReader(Files.getResource(plugin, target.replace(".", "/") + ".class"));
ClassWriter classWriter = new ClassWriter(0);
ClassVisitor classVisitor = new SimpleClassVisitor(this, classWriter);
classReader.accept(classVisitor, ClassReader.EXPAND_FRAMES);
diff --git a/src/main/scala/com/ilummc/tlib/resources/TLocale.java b/src/main/scala/io/izzel/taboolib/module/locale/TLocale.java
similarity index 83%
rename from src/main/scala/com/ilummc/tlib/resources/TLocale.java
rename to src/main/scala/io/izzel/taboolib/module/locale/TLocale.java
index 1b41f23..7620c9d 100644
--- a/src/main/scala/com/ilummc/tlib/resources/TLocale.java
+++ b/src/main/scala/io/izzel/taboolib/module/locale/TLocale.java
@@ -1,16 +1,15 @@
-package com.ilummc.tlib.resources;
+package io.izzel.taboolib.module.locale;
-import com.ilummc.tlib.TLib;
-import com.ilummc.tlib.bungee.api.ChatColor;
-import com.ilummc.tlib.bungee.api.chat.TextComponent;
-import com.ilummc.tlib.bungee.chat.ComponentSerializer;
-import com.ilummc.tlib.inject.TLoggerManager;
-import com.ilummc.tlib.util.Ref;
-import com.ilummc.tlib.util.Strings;
+import io.izzel.taboolib.TabooLib;
+import io.izzel.taboolib.module.locale.logger.TLoggerManager;
+import io.izzel.taboolib.module.nms.NMS;
+import io.izzel.taboolib.module.tellraw.TellrawCreator;
+import io.izzel.taboolib.util.Ref;
+import io.izzel.taboolib.util.Strings;
+import io.izzel.taboolib.util.chat.ChatColor;
+import io.izzel.taboolib.util.chat.ComponentSerializer;
+import io.izzel.taboolib.util.chat.TextComponent;
import me.clip.placeholderapi.PlaceholderAPI;
-import me.skymc.taboolib.Main;
-import me.skymc.taboolib.common.nms.NMSHandler;
-import me.skymc.taboolib.json.tellraw.TellrawCreator;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -58,19 +57,19 @@ public class TLocale {
public static String asString(String path, String... args) {
try {
- return asString(path, Ref.getCallerClass(3).orElse(Main.class), args);
+ return asString(path, Ref.getCallerClass(3).orElse(TabooLib.class), args);
} catch (Exception e) {
- TLib.getTLib().getLogger().error(Strings.replaceWithOrder(TLib.getInternalLanguage().getString("FETCH-LOCALE-ERROR"), path));
- TLib.getTLib().getLogger().error(Strings.replaceWithOrder(TLib.getInternalLanguage().getString("LOCALE-ERROR-REASON"), e.getMessage()));
+ TabooLib.getLogger().error(Strings.replaceWithOrder(TabooLib.getInst().getInternal().getString("FETCH-LOCALE-ERROR"), path));
+ TabooLib.getLogger().error(Strings.replaceWithOrder(TabooLib.getInst().getInternal().getString("LOCALE-ERROR-REASON"), e.getMessage()));
return "§4<" + path + "§4>";
}
}
public static List asStringList(String path, String... args) {
try {
- return asStringList(path, Ref.getCallerClass(3).orElse(Main.class), args);
+ return asStringList(path, Ref.getCallerClass(3).orElse(TabooLib.class), args);
} catch (Exception e) {
- TLib.getTLib().getLogger().error(Strings.replaceWithOrder(TLib.getInternalLanguage().getString("LOCALE-ERROR-REASON"), e.getMessage()));
+ TabooLib.getLogger().error(Strings.replaceWithOrder(TabooLib.getInst().getInternal().getString("LOCALE-ERROR-REASON"), e.getMessage()));
return Collections.singletonList("§4<" + path + "§4>");
}
}
@@ -97,18 +96,18 @@ public class TLocale {
}
public static void sendTitle(Player player, String title, String subTitle, int fadein, int stay, int fadeout) {
- NMSHandler.getHandler().sendTitle(player, title, fadein, stay, fadeout, subTitle, fadein, stay, fadeout);
+ NMS.handle().sendTitle(player, title, fadein, stay, fadeout, subTitle, fadein, stay, fadeout);
}
public static void sendActionBar(Player player, String text) {
- NMSHandler.getHandler().sendActionBar(player, text);
+ NMS.handle().sendActionBar(player, text);
}
}
public static final class Translate extends TLocale {
public static boolean isPlaceholderUseDefault() {
- return Main.getInst().getConfig().getBoolean("LOCALE.USE_PAPI", false);
+ return TabooLib.getConfig().getBoolean("LOCALE.USE_PAPI", false);
}
public static boolean isPlaceholderPluginEnabled() {
diff --git a/src/main/scala/com/ilummc/tlib/resources/TLocaleInstance.java b/src/main/scala/io/izzel/taboolib/module/locale/TLocaleInstance.java
similarity index 87%
rename from src/main/scala/com/ilummc/tlib/resources/TLocaleInstance.java
rename to src/main/scala/io/izzel/taboolib/module/locale/TLocaleInstance.java
index 5994aa2..8effd83 100644
--- a/src/main/scala/com/ilummc/tlib/resources/TLocaleInstance.java
+++ b/src/main/scala/io/izzel/taboolib/module/locale/TLocaleInstance.java
@@ -1,10 +1,9 @@
-package com.ilummc.tlib.resources;
+package io.izzel.taboolib.module.locale;
import com.google.common.collect.ImmutableList;
-import com.ilummc.tlib.TLib;
-import com.ilummc.tlib.resources.type.TLocaleText;
-import com.ilummc.tlib.util.Strings;
-import me.skymc.taboolib.TabooLib;
+import io.izzel.taboolib.TabooLib;
+import io.izzel.taboolib.module.locale.type.TLocaleText;
+import io.izzel.taboolib.util.Strings;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
@@ -12,7 +11,10 @@ import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
import javax.annotation.concurrent.ThreadSafe;
-import java.util.*;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
@@ -59,8 +61,8 @@ class TLocaleInstance {
}
});
} catch (Exception | Error e) {
- TLib.getTLib().getLogger().error(Strings.replaceWithOrder(TLib.getInternalLanguage().getString("SEND-LOCALE-ERROR"), path));
- TLib.getTLib().getLogger().error(Strings.replaceWithOrder(TLib.getInternalLanguage().getString("LOCALE-ERROR-REASON"), e.toString()));
+ TabooLib.getLogger().error(Strings.replaceWithOrder(TabooLib.getInst().getInternal().getString("SEND-LOCALE-ERROR"), path));
+ TabooLib.getLogger().error(Strings.replaceWithOrder(TabooLib.getInst().getInternal().getString("LOCALE-ERROR-REASON"), e.toString()));
}
}
diff --git a/src/main/scala/com/ilummc/tlib/resources/TLocaleLoader.java b/src/main/scala/io/izzel/taboolib/module/locale/TLocaleLoader.java
similarity index 66%
rename from src/main/scala/com/ilummc/tlib/resources/TLocaleLoader.java
rename to src/main/scala/io/izzel/taboolib/module/locale/TLocaleLoader.java
index 749e222..ef0a6b1 100644
--- a/src/main/scala/com/ilummc/tlib/resources/TLocaleLoader.java
+++ b/src/main/scala/io/izzel/taboolib/module/locale/TLocaleLoader.java
@@ -1,15 +1,13 @@
-package com.ilummc.tlib.resources;
+package io.izzel.taboolib.module.locale;
-import com.ilummc.tlib.TLib;
-import com.ilummc.tlib.annotations.TLocalePlugin;
-import com.ilummc.tlib.logger.TLogger;
-import com.ilummc.tlib.resources.type.*;
-import com.ilummc.tlib.util.IO;
-import com.ilummc.tlib.util.Strings;
-import me.skymc.taboolib.Main;
-import me.skymc.taboolib.TabooLib;
-import me.skymc.taboolib.fileutils.ConfigUtils;
-import me.skymc.taboolib.fileutils.FileUtils;
+import io.izzel.taboolib.TabooLib;
+import io.izzel.taboolib.TabooLibAPI;
+import io.izzel.taboolib.module.locale.type.*;
+import io.izzel.taboolib.module.config.TConfigWatcher;
+import io.izzel.taboolib.module.locale.logger.TLogger;
+import io.izzel.taboolib.util.Files;
+import io.izzel.taboolib.util.IO;
+import io.izzel.taboolib.util.Strings;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.YamlConfiguration;
@@ -26,7 +24,7 @@ public class TLocaleLoader {
private static final Map map = new ConcurrentHashMap<>();
- public static void init() {
+ static {
ConfigurationSerialization.registerClass(TLocaleText.class, "TEXT");
ConfigurationSerialization.registerClass(TLocaleJson.class, "JSON");
ConfigurationSerialization.registerClass(TLocaleBook.class, "BOOK");
@@ -37,7 +35,7 @@ public class TLocaleLoader {
}
public static void sendTo(Plugin plugin, String path, CommandSender sender, String... args) {
- TabooLib.debug(plugin, "TLocaleLoader.sendTo: " + plugin + ", path: " + path + ", sender: " + sender + ", args: " + Arrays.asList(args));
+ TabooLibAPI.debug(plugin, "TLocaleLoader.sendTo: " + plugin + ", path: " + path + ", sender: " + sender + ", args: " + Arrays.asList(args));
if (Bukkit.isPrimaryThread()) {
Optional.ofNullable(map.get(plugin.getName())).ifPresent(localeInstance -> localeInstance.sendTo(path, sender, args));
} else {
@@ -48,7 +46,7 @@ public class TLocaleLoader {
}
public static String asString(Plugin plugin, String path, String... args) {
- TabooLib.debug(plugin, "TLocaleLoader.asString: " + plugin.getName() + ", path: " + path + ", args: " + Arrays.asList(args));
+ TabooLibAPI.debug(plugin, "TLocaleLoader.asString: " + plugin.getName() + ", path: " + path + ", args: " + Arrays.asList(args));
TLocaleInstance tLocaleInstance = map.get(plugin.getName());
if (tLocaleInstance != null) {
return tLocaleInstance.asString(path, args);
@@ -58,7 +56,7 @@ public class TLocaleLoader {
}
public static List asStringList(Plugin plugin, String path, String... args) {
- TabooLib.debug(plugin, "TLocaleLoader.asStringList: " + plugin + ", path: " + path + ", args: " + Arrays.asList(args));
+ TabooLibAPI.debug(plugin, "TLocaleLoader.asStringList: " + plugin + ", path: " + path + ", args: " + Arrays.asList(args));
TLocaleInstance tLocaleInstance = map.get(plugin.getName());
if (tLocaleInstance != null) {
return tLocaleInstance.asStringList(path, args);
@@ -67,12 +65,6 @@ public class TLocaleLoader {
}
}
- /**
- * 载入语言文件
- *
- * @param plugin 载入插件
- * @param isCover 是否覆盖
- */
public static void load(Plugin plugin, boolean isCover) {
try {
if (isLoadLocale(plugin, isCover)) {
@@ -82,53 +74,54 @@ public class TLocaleLoader {
return;
}
// 加载文件
- YamlConfiguration localeConfiguration = ConfigUtils.loadYaml(plugin, localeFile);
+ YamlConfiguration localeConfiguration = Files.loadYaml(localeFile);
YamlConfiguration localeConfigurationAtStream = getLocaleAtStream(plugin, localeFile);
// 载入配置
loadPluginLocale(plugin, localeFile, localeConfiguration, localeConfigurationAtStream);
// 注册监听
- TLib.getTLib().getConfigWatcher().removeListener(localeFile);
- TLib.getTLib().getConfigWatcher().addListener(localeFile, null, obj -> {
- loadPluginLocale(plugin, localeFile, ConfigUtils.loadYaml(plugin, localeFile), getLocaleAtStream(plugin, localeFile));
- });
+ TConfigWatcher.getInst().removeListener(localeFile);
+ TConfigWatcher.getInst().addListener(localeFile, null, obj -> loadPluginLocale(plugin, localeFile, Files.loadYaml(localeFile), getLocaleAtStream(plugin, localeFile)));
}
} catch (Exception e) {
- errorLogger("ERROR-LOADING-LANG", plugin.getName(), e.toString());
- e.printStackTrace();
+ errorLogger("ERROR-LOADING-LANG", plugin.getName(), e.toString() + "\n" + e.getStackTrace()[0].toString());
}
}
+ public static void unload(Plugin plugin) {
+ map.remove(plugin.getName());
+ }
+
public static boolean isLocaleLoaded(Plugin plugin) {
return map.containsKey(plugin.getName());
}
public static boolean isDependWithTabooLib(Plugin plugin) {
- return plugin.getClass().getAnnotation(TLocalePlugin.class) != null || plugin.getDescription().getDepend().contains(Main.getInst().getName()) || plugin.getDescription().getSoftDepend().contains(Main.getInst().getName());
+ return plugin.getClass().getSuperclass().getSimpleName().equals("TabooPlugin");
}
public static List getLocalePriority() {
- return Main.getInst().getConfig().contains("LOCALE.PRIORITY") ? Main.getInst().getConfig().getStringList("LOCALE.PRIORITY") : Collections.singletonList("zh_CN");
+ return TabooLib.getConfig().contains("LOCALE.PRIORITY") ? TabooLib.getConfig().getStringList("LOCALE.PRIORITY") : Collections.singletonList("zh_CN");
}
private static boolean isLoadLocale(Plugin plugin, boolean isCover) {
- return (isCover || !isLocaleLoaded(plugin)) && (plugin.equals(Main.getInst()) || isDependWithTabooLib(plugin));
+ return isCover || !isLocaleLoaded(plugin);
}
private static void infoLogger(String path, String... args) {
- TLogger.getGlobalLogger().info(Strings.replaceWithOrder(TLib.getInternalLanguage().getString(path), args));
+ TLogger.getGlobalLogger().info(Strings.replaceWithOrder(io.izzel.taboolib.TabooLib.getInst().getInternal().getString(path), args));
}
private static void errorLogger(String path, String... args) {
- TLogger.getGlobalLogger().error(Strings.replaceWithOrder(TLib.getInternalLanguage().getString(path), args));
+ TLogger.getGlobalLogger().error(Strings.replaceWithOrder(io.izzel.taboolib.TabooLib.getInst().getInternal().getString(path), args));
}
private static File getLocaleFile(Plugin plugin) {
releaseLocales(plugin);
- return getLocalePriority().stream().map(localeName -> new File(plugin.getDataFolder(), "lang/" + localeName + ".yml")).filter(File::exists).findFirst().orElse(null);
+ return getLocalePriority().stream().map(localeName -> new File("plugins/" + plugin.getName() + "/lang/" + localeName + ".yml")).filter(File::exists).findFirst().orElse(null);
}
private static void releaseLocales(Plugin plugin) {
- getLocalePriority().stream().filter(localeName -> !new File(plugin.getDataFolder(), "lang/" + localeName + ".yml").exists() && plugin.getResource("lang/" + localeName + ".yml") != null).forEach(localeName -> plugin.saveResource("lang/" + localeName + ".yml", true));
+ getLocalePriority().stream().filter(localeName -> !new File("plugins/" + plugin.getName() + "/lang/" + localeName + ".yml").exists() && plugin.getResource("lang/" + localeName + ".yml") != null).forEach(localeName -> plugin.saveResource("lang/" + localeName + ".yml", true));
}
private static TLocaleInstance getLocaleInstance(Plugin plugin) {
@@ -138,11 +131,10 @@ public class TLocaleLoader {
}
private static YamlConfiguration getLocaleAtStream(Plugin plugin, File localeFile) {
- InputStream localeInputSteam = FileUtils.getResource(plugin, "lang/" + localeFile.getName());
+ InputStream localeInputSteam = Files.getResource(plugin, "lang/" + localeFile.getName());
try {
- String yamlText = new String(IO.readFully(localeInputSteam), Charset.forName("utf-8"));
YamlConfiguration yaml = new YamlConfiguration();
- yaml.loadFromString(yamlText);
+ yaml.loadFromString(IO.readFully(localeInputSteam, Charset.forName("utf-8")));
return yaml;
} catch (Exception ignored) {
return null;
diff --git a/src/main/scala/io/izzel/taboolib/module/locale/TLocaleSender.java b/src/main/scala/io/izzel/taboolib/module/locale/TLocaleSender.java
new file mode 100644
index 0000000..f5f013d
--- /dev/null
+++ b/src/main/scala/io/izzel/taboolib/module/locale/TLocaleSender.java
@@ -0,0 +1,19 @@
+package io.izzel.taboolib.module.locale;
+
+import org.bukkit.command.CommandSender;
+
+import java.util.List;
+
+/**
+ * @Author sky
+ * @Since 2018-05-12 13:58
+ */
+public interface TLocaleSender {
+
+ void sendTo(CommandSender sender, String... args);
+
+ String asString(String... args);
+
+ List asStringList(String... args);
+
+}
diff --git a/src/main/scala/com/ilummc/tlib/resources/TLocaleSerialize.java b/src/main/scala/io/izzel/taboolib/module/locale/TLocaleSerialize.java
similarity index 98%
rename from src/main/scala/com/ilummc/tlib/resources/TLocaleSerialize.java
rename to src/main/scala/io/izzel/taboolib/module/locale/TLocaleSerialize.java
index 3155d74..7f3b662 100644
--- a/src/main/scala/com/ilummc/tlib/resources/TLocaleSerialize.java
+++ b/src/main/scala/io/izzel/taboolib/module/locale/TLocaleSerialize.java
@@ -1,4 +1,4 @@
-package com.ilummc.tlib.resources;
+package io.izzel.taboolib.module.locale;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
diff --git a/src/main/scala/com/ilummc/tlib/logger/TLogger.java b/src/main/scala/io/izzel/taboolib/module/locale/logger/TLogger.java
similarity index 67%
rename from src/main/scala/com/ilummc/tlib/logger/TLogger.java
rename to src/main/scala/io/izzel/taboolib/module/locale/logger/TLogger.java
index 2b3b664..f74b152 100644
--- a/src/main/scala/com/ilummc/tlib/logger/TLogger.java
+++ b/src/main/scala/io/izzel/taboolib/module/locale/logger/TLogger.java
@@ -1,9 +1,8 @@
-package com.ilummc.tlib.logger;
+package io.izzel.taboolib.module.locale.logger;
-import com.ilummc.tlib.resources.TLocale;
-import com.ilummc.tlib.util.Strings;
-import me.skymc.taboolib.Main;
-import me.skymc.taboolib.TabooLib;
+import io.izzel.taboolib.TabooLibAPI;
+import io.izzel.taboolib.module.locale.TLocale;
+import io.izzel.taboolib.util.Strings;
import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
@@ -13,13 +12,32 @@ public class TLogger {
public static final int VERBOSE = 0, FINEST = 1, FINE = 2, INFO = 3, WARN = 4, ERROR = 5, FATAL = 6;
- private static TLogger globalLogger = new TLogger("§8[§3§lTabooLib§8][§r{1}§8] §f{2}", Main.getInst(), TLogger.FINE);
private final String pattern;
- private String name;
+ private final String name;
private int level;
+ public TLogger(String pattern, Plugin plugin, int level) {
+ this.pattern = pattern;
+ this.name = plugin.getName();
+ this.level = level;
+ }
+
+ public TLogger(String pattern, String name, int level) {
+ this.pattern = pattern;
+ this.name = name;
+ this.level = level;
+ }
+
public static TLogger getGlobalLogger() {
- return globalLogger;
+ return io.izzel.taboolib.TabooLib.getLogger();
+ }
+
+ public static TLogger getUnformatted(Plugin plugin) {
+ return new TLogger("§8[§3§l{0}§8][§r{1}§8] §f{2}", plugin, TLogger.FINE);
+ }
+
+ public static TLogger getUnformatted(String name) {
+ return new TLogger("§8[§3§l{0}§8][§r{1}§8] §f{2}", name, TLogger.FINE);
}
public String getPattern() {
@@ -38,93 +56,73 @@ public class TLogger {
this.level = level;
}
- public TLogger(String pattern, Plugin plugin, int level) {
- this.pattern = pattern;
- this.name = plugin.getName();
- this.level = level;
- }
-
- public TLogger(String pattern, String name, int level) {
- this.pattern = pattern;
- this.name = name;
- this.level = level;
- }
-
public void verbose(String msg) {
if (level <= VERBOSE) {
- if (TabooLib.isSpigot()) {
- Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, name, "§f全部", TLocale.Translate.setColored(msg)));
+ if (TabooLibAPI.isBukkit()) {
+ Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, name, "§fVERBOSE", TLocale.Translate.setColored(msg)));
} else {
- BungeeCord.getInstance().getConsole().sendMessage(TextComponent.fromLegacyText(Strings.replaceWithOrder(pattern, name, "§f全部", TLocale.Translate.setColored(msg))));
+ BungeeCord.getInstance().getConsole().sendMessage(TextComponent.fromLegacyText(Strings.replaceWithOrder(pattern, name, "§fVERBOSE", TLocale.Translate.setColored(msg))));
}
}
}
public void finest(String msg) {
if (level <= FINEST) {
- if (TabooLib.isSpigot()) {
- Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, name, "§e良好", TLocale.Translate.setColored(msg)));
+ if (TabooLibAPI.isBukkit()) {
+ Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, name, "§eFINEST", TLocale.Translate.setColored(msg)));
} else {
- BungeeCord.getInstance().getConsole().sendMessage(TextComponent.fromLegacyText(Strings.replaceWithOrder(pattern, name, "§e良好", TLocale.Translate.setColored(msg))));
+ BungeeCord.getInstance().getConsole().sendMessage(TextComponent.fromLegacyText(Strings.replaceWithOrder(pattern, name, "§eFINEST", TLocale.Translate.setColored(msg))));
}
}
}
public void fine(String msg) {
if (level <= FINE) {
- if (TabooLib.isSpigot()) {
- Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, name, "§a正常", TLocale.Translate.setColored(msg)));
+ if (TabooLibAPI.isBukkit()) {
+ Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, name, "§aFINE", TLocale.Translate.setColored(msg)));
} else {
- BungeeCord.getInstance().getConsole().sendMessage(TextComponent.fromLegacyText(Strings.replaceWithOrder(pattern, name, "§a正常", TLocale.Translate.setColored(msg))));
+ BungeeCord.getInstance().getConsole().sendMessage(TextComponent.fromLegacyText(Strings.replaceWithOrder(pattern, name, "§aFINE", TLocale.Translate.setColored(msg))));
}
}
}
public void info(String msg) {
if (level <= INFO) {
- if (TabooLib.isSpigot()) {
- Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, name, "§b信息", TLocale.Translate.setColored(msg)));
+ if (TabooLibAPI.isBukkit()) {
+ Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, name, "§bINFO", TLocale.Translate.setColored(msg)));
} else {
- BungeeCord.getInstance().getConsole().sendMessage(TextComponent.fromLegacyText(Strings.replaceWithOrder(pattern, name, "§b信息", TLocale.Translate.setColored(msg))));
+ BungeeCord.getInstance().getConsole().sendMessage(TextComponent.fromLegacyText(Strings.replaceWithOrder(pattern, name, "§bINFO", TLocale.Translate.setColored(msg))));
}
}
}
public void warn(String msg) {
if (level <= WARN) {
- if (TabooLib.isSpigot()) {
- Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, name, "§6警告", "§6" + TLocale.Translate.setColored(msg)));
+ if (TabooLibAPI.isBukkit()) {
+ Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, name, "§6WARN", "§6" + TLocale.Translate.setColored(msg)));
} else {
- BungeeCord.getInstance().getConsole().sendMessage(TextComponent.fromLegacyText(Strings.replaceWithOrder(pattern, name, "§6警告", "§6" + TLocale.Translate.setColored(msg))));
+ BungeeCord.getInstance().getConsole().sendMessage(TextComponent.fromLegacyText(Strings.replaceWithOrder(pattern, name, "§6WARN", "§6" + TLocale.Translate.setColored(msg))));
}
}
}
public void error(String msg) {
if (level <= ERROR) {
- if (TabooLib.isSpigot()) {
- Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, name, "§c错误", "§c" + TLocale.Translate.setColored(msg)));
+ if (TabooLibAPI.isBukkit()) {
+ Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, name, "§cERROR", "§c" + TLocale.Translate.setColored(msg)));
} else {
- BungeeCord.getInstance().getConsole().sendMessage(TextComponent.fromLegacyText(Strings.replaceWithOrder(pattern, name, "§c错误", "§c" + TLocale.Translate.setColored(msg))));
+ BungeeCord.getInstance().getConsole().sendMessage(TextComponent.fromLegacyText(Strings.replaceWithOrder(pattern, name, "§cERROR", "§c" + TLocale.Translate.setColored(msg))));
}
}
}
public void fatal(String msg) {
if (level <= FATAL) {
- if (TabooLib.isSpigot()) {
- Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, name, "§4致命错误", "§4" + TLocale.Translate.setColored(msg)));
+ if (TabooLibAPI.isBukkit()) {
+ Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, name, "§4FATAL", "§4" + TLocale.Translate.setColored(msg)));
} else {
- BungeeCord.getInstance().getConsole().sendMessage(TextComponent.fromLegacyText(Strings.replaceWithOrder(pattern, name, "§4致命错误", "§4" + TLocale.Translate.setColored(msg))));
+ BungeeCord.getInstance().getConsole().sendMessage(TextComponent.fromLegacyText(Strings.replaceWithOrder(pattern, name, "§4FATAL", "§4" + TLocale.Translate.setColored(msg))));
}
}
}
-
- public static TLogger getUnformatted(Plugin plugin) {
- return new TLogger("§8[§3§l{0}§8][§r{1}§8] §f{2}", plugin, TLogger.FINE);
- }
-
- public static TLogger getUnformatted(String name) {
- return new TLogger("§8[§3§l{0}§8][§r{1}§8] §f{2}", name, TLogger.FINE);
- }
}
diff --git a/src/main/scala/com/ilummc/tlib/inject/TLoggerManager.java b/src/main/scala/io/izzel/taboolib/module/locale/logger/TLoggerManager.java
similarity index 88%
rename from src/main/scala/com/ilummc/tlib/inject/TLoggerManager.java
rename to src/main/scala/io/izzel/taboolib/module/locale/logger/TLoggerManager.java
index 98f30f4..0522804 100644
--- a/src/main/scala/com/ilummc/tlib/inject/TLoggerManager.java
+++ b/src/main/scala/io/izzel/taboolib/module/locale/logger/TLoggerManager.java
@@ -1,6 +1,5 @@
-package com.ilummc.tlib.inject;
+package io.izzel.taboolib.module.locale.logger;
-import com.ilummc.tlib.logger.TLogger;
import org.bukkit.plugin.Plugin;
import java.util.HashMap;
diff --git a/src/main/scala/com/ilummc/tlib/resources/type/TLocaleActionBar.java b/src/main/scala/io/izzel/taboolib/module/locale/type/TLocaleActionBar.java
similarity index 85%
rename from src/main/scala/com/ilummc/tlib/resources/type/TLocaleActionBar.java
rename to src/main/scala/io/izzel/taboolib/module/locale/type/TLocaleActionBar.java
index ec7296c..5679094 100644
--- a/src/main/scala/com/ilummc/tlib/resources/type/TLocaleActionBar.java
+++ b/src/main/scala/io/izzel/taboolib/module/locale/type/TLocaleActionBar.java
@@ -1,11 +1,10 @@
-package com.ilummc.tlib.resources.type;
+package io.izzel.taboolib.module.locale.type;
import com.google.common.collect.Maps;
-import com.ilummc.tlib.compat.PlaceholderHook;
-import com.ilummc.tlib.resources.TLocale;
-import com.ilummc.tlib.resources.TLocaleSerialize;
-import com.ilummc.tlib.util.Strings;
-import me.skymc.taboolib.display.ActionUtils;
+import io.izzel.taboolib.module.locale.TLocale;
+import io.izzel.taboolib.module.locale.TLocaleSerialize;
+import io.izzel.taboolib.module.compat.PlaceholderHook;
+import io.izzel.taboolib.util.Strings;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.serialization.SerializableAs;
diff --git a/src/main/scala/com/ilummc/tlib/resources/type/TLocaleBook.java b/src/main/scala/io/izzel/taboolib/module/locale/type/TLocaleBook.java
similarity index 84%
rename from src/main/scala/com/ilummc/tlib/resources/type/TLocaleBook.java
rename to src/main/scala/io/izzel/taboolib/module/locale/type/TLocaleBook.java
index 24c8008..66251c6 100644
--- a/src/main/scala/com/ilummc/tlib/resources/type/TLocaleBook.java
+++ b/src/main/scala/io/izzel/taboolib/module/locale/type/TLocaleBook.java
@@ -1,14 +1,14 @@
-package com.ilummc.tlib.resources.type;
+package io.izzel.taboolib.module.locale.type;
import com.google.common.collect.Maps;
-import com.ilummc.tlib.bungee.chat.ComponentSerializer;
-import com.ilummc.tlib.resources.TLocale;
-import com.ilummc.tlib.resources.TLocaleSerialize;
-import com.ilummc.tlib.util.Strings;
-import me.skymc.taboolib.Main;
-import me.skymc.taboolib.bookformatter.BookFormatter;
-import me.skymc.taboolib.bookformatter.builder.BookBuilder;
-import me.skymc.taboolib.json.tellraw.TellrawJson;
+import io.izzel.taboolib.TabooLib;
+import io.izzel.taboolib.module.locale.TLocale;
+import io.izzel.taboolib.module.locale.TLocaleSerialize;
+import io.izzel.taboolib.module.tellraw.TellrawJson;
+import io.izzel.taboolib.util.book.BookFormatter;
+import io.izzel.taboolib.util.book.builder.BookBuilder;
+import io.izzel.taboolib.util.Strings;
+import io.izzel.taboolib.util.chat.ComponentSerializer;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.serialization.SerializableAs;
import org.bukkit.entity.Player;
@@ -77,9 +77,9 @@ public class TLocaleBook extends TLocaleSerialize {
public void run() {
BookFormatter.forceOpen((Player) sender, bookBuilder.build());
}
- }.runTask(Main.getInst());
+ }.runTask(TabooLib.getPlugin());
}
- }.runTaskAsynchronously(Main.getInst());
+ }.runTaskAsynchronously(TabooLib.getPlugin());
}
private String format(TellrawJson jsonPage, CommandSender sender, String[] args) {
diff --git a/src/main/scala/com/ilummc/tlib/resources/type/TLocaleBossBar.java b/src/main/scala/io/izzel/taboolib/module/locale/type/TLocaleBossBar.java
similarity index 79%
rename from src/main/scala/com/ilummc/tlib/resources/type/TLocaleBossBar.java
rename to src/main/scala/io/izzel/taboolib/module/locale/type/TLocaleBossBar.java
index 62261ca..c4c4b7b 100644
--- a/src/main/scala/com/ilummc/tlib/resources/type/TLocaleBossBar.java
+++ b/src/main/scala/io/izzel/taboolib/module/locale/type/TLocaleBossBar.java
@@ -1,14 +1,14 @@
-package com.ilummc.tlib.resources.type;
+package io.izzel.taboolib.module.locale.type;
-import com.ilummc.tlib.resources.TLocale;
-import com.ilummc.tlib.resources.TLocaleSerialize;
-import com.ilummc.tlib.util.Strings;
-import me.skymc.taboolib.other.NumberUtils;
+import io.izzel.taboolib.module.locale.TLocale;
+import io.izzel.taboolib.module.locale.TLocaleSerialize;
+import io.izzel.taboolib.util.Strings;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.serialization.SerializableAs;
import org.bukkit.entity.Player;
+import org.bukkit.util.NumberConversions;
import org.inventivetalent.bossbar.BossBar;
import org.inventivetalent.bossbar.BossBarAPI;
@@ -72,7 +72,14 @@ public class TLocaleBossBar extends TLocaleSerialize {
}
public static TLocaleBossBar valueOf(Map map) {
- return new TLocaleBossBar(map.getOrDefault("text", "§4* Invalid Text*").toString(), getColor(String.valueOf(map.get("color"))), getStyle(String.valueOf(map.get("style"))), (float) NumberUtils.getDouble(String.valueOf(map.getOrDefault("progress", 1))), NumberUtils.getInteger(String.valueOf(map.getOrDefault("timeout", 20))), NumberUtils.getInteger(String.valueOf(map.getOrDefault("timeout-interval", 2))), isPlaceholderEnabled(map));
+ return new TLocaleBossBar(
+ map.getOrDefault("text", "§4* Invalid Text*").toString(),
+ getColor(String.valueOf(map.get("color"))),
+ getStyle(String.valueOf(map.get("style"))),
+ NumberConversions.toFloat(map.getOrDefault("progress", 1)),
+ NumberConversions.toInt(map.getOrDefault("timeout", 20)),
+ NumberConversions.toInt(map.getOrDefault("timeout-interval", 2)),
+ isPlaceholderEnabled(map));
}
private static BossBarAPI.Color getColor(String color) {
diff --git a/src/main/scala/com/ilummc/tlib/resources/type/TLocaleJson.java b/src/main/scala/io/izzel/taboolib/module/locale/type/TLocaleJson.java
similarity index 90%
rename from src/main/scala/com/ilummc/tlib/resources/type/TLocaleJson.java
rename to src/main/scala/io/izzel/taboolib/module/locale/type/TLocaleJson.java
index 456f862..6eb160b 100644
--- a/src/main/scala/com/ilummc/tlib/resources/type/TLocaleJson.java
+++ b/src/main/scala/io/izzel/taboolib/module/locale/type/TLocaleJson.java
@@ -1,21 +1,19 @@
-package com.ilummc.tlib.resources.type;
+package io.izzel.taboolib.module.locale.type;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
-import com.ilummc.tlib.TLib;
-import com.ilummc.tlib.bungee.api.chat.*;
-import com.ilummc.tlib.bungee.chat.ComponentSerializer;
-import com.ilummc.tlib.compat.PlaceholderHook;
-import com.ilummc.tlib.resources.TLocale;
-import com.ilummc.tlib.resources.TLocaleSerialize;
-import com.ilummc.tlib.util.Strings;
-import me.skymc.taboolib.inventory.ItemUtils;
-import me.skymc.taboolib.json.tellraw.TellrawJson;
-import me.skymc.taboolib.other.NumberUtils;
-import me.skymc.taboolib.string.VariableFormatter;
+import io.izzel.taboolib.TabooLib;
+import io.izzel.taboolib.module.locale.TLocale;
+import io.izzel.taboolib.module.locale.TLocaleSerialize;
+import io.izzel.taboolib.module.compat.PlaceholderHook;
+import io.izzel.taboolib.module.tellraw.TellrawJson;
+import io.izzel.taboolib.util.Strings;
+import io.izzel.taboolib.util.Variables;
+import io.izzel.taboolib.util.chat.*;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.serialization.SerializableAs;
+import org.bukkit.util.NumberConversions;
import javax.annotation.concurrent.ThreadSafe;
import java.util.*;
@@ -88,7 +86,7 @@ public class TLocaleJson extends TLocaleSerialize {
} else {
// 这个参数节点并没有找到,于是随便放点字符串进去
builder.addAll(Arrays.asList(TextComponent.fromLegacyText(text)));
- TLib.getTLib().getLogger().warn(Strings.replaceWithOrder(TLib.getInternalLanguage().getString("MISSING-ARGUMENT"), node));
+ TabooLib.getLogger().warn(Strings.replaceWithOrder(TabooLib.getInst().getInternal().getString("MISSING-ARGUMENT"), node));
}
// 有可能一开头就是 <@xxx>,然后 split 出来就少了一些,于是直接加上
if (index < template.length) {
@@ -171,7 +169,7 @@ public class TLocaleJson extends TLocaleSerialize {
// 遍历本页文本
for (int i = 0; i < textList.size(); i++) {
// 捕捉变量
- for (VariableFormatter.Variable variable : new VariableFormatter(TLocale.Translate.setColored(textList.get(i)), pattern).find().getVariableList()) {
+ for (Variables.Variable variable : new Variables(TLocale.Translate.setColored(textList.get(i)), pattern).find().getVariableList()) {
// 如果是变量
if (variable.isVariable()) {
String[] split = variable.getText().split("@");
@@ -199,9 +197,6 @@ public class TLocaleJson extends TLocaleSerialize {
// 文本
pageJson.append(args.getOrDefault("text", text).toString());
// 功能
- if (args.containsKey("item")) {
- pageJson.hoverItem(ItemUtils.getCacheItem(args.get("item").toString()));
- }
if (args.containsKey("hover")) {
pageJson.hoverText(args.get("hover").toString());
}
@@ -212,7 +207,7 @@ public class TLocaleJson extends TLocaleSerialize {
pageJson.clickCommand(args.get("command").toString());
}
if (args.containsKey("page")) {
- pageJson.clickChangePage(NumberUtils.getInteger(args.get("page").toString()));
+ pageJson.clickChangePage(NumberConversions.toInt(args.get("page").toString()));
}
if (args.containsKey("url")) {
pageJson.clickOpenURL(args.get("url").toString());
diff --git a/src/main/scala/com/ilummc/tlib/resources/type/TLocaleSound.java b/src/main/scala/io/izzel/taboolib/module/locale/type/TLocaleSound.java
similarity index 92%
rename from src/main/scala/com/ilummc/tlib/resources/type/TLocaleSound.java
rename to src/main/scala/io/izzel/taboolib/module/locale/type/TLocaleSound.java
index 5aec6e1..aeb2310 100644
--- a/src/main/scala/com/ilummc/tlib/resources/type/TLocaleSound.java
+++ b/src/main/scala/io/izzel/taboolib/module/locale/type/TLocaleSound.java
@@ -1,8 +1,8 @@
-package com.ilummc.tlib.resources.type;
+package io.izzel.taboolib.module.locale.type;
import com.google.common.collect.Maps;
-import com.ilummc.tlib.resources.TLocaleSerialize;
-import me.skymc.taboolib.sound.SoundPack;
+import io.izzel.taboolib.module.locale.TLocaleSerialize;
+import io.izzel.taboolib.util.lite.SoundPack;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.serialization.SerializableAs;
import org.bukkit.entity.Player;
diff --git a/src/main/scala/com/ilummc/tlib/resources/type/TLocaleText.java b/src/main/scala/io/izzel/taboolib/module/locale/type/TLocaleText.java
similarity index 93%
rename from src/main/scala/com/ilummc/tlib/resources/type/TLocaleText.java
rename to src/main/scala/io/izzel/taboolib/module/locale/type/TLocaleText.java
index fc5e587..b4b1166 100644
--- a/src/main/scala/com/ilummc/tlib/resources/type/TLocaleText.java
+++ b/src/main/scala/io/izzel/taboolib/module/locale/type/TLocaleText.java
@@ -1,13 +1,11 @@
-package com.ilummc.tlib.resources.type;
+package io.izzel.taboolib.module.locale.type;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
-import com.ilummc.tlib.compat.PlaceholderHook;
-import com.ilummc.tlib.resources.TLocale;
-import com.ilummc.tlib.resources.TLocaleSerialize;
-import com.ilummc.tlib.util.Strings;
-import me.skymc.taboolib.Main;
+import io.izzel.taboolib.module.locale.TLocale;
+import io.izzel.taboolib.module.locale.TLocaleSerialize;
+import io.izzel.taboolib.util.Strings;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.serialization.SerializableAs;
diff --git a/src/main/scala/com/ilummc/tlib/resources/type/TLocaleTitle.java b/src/main/scala/io/izzel/taboolib/module/locale/type/TLocaleTitle.java
similarity index 92%
rename from src/main/scala/com/ilummc/tlib/resources/type/TLocaleTitle.java
rename to src/main/scala/io/izzel/taboolib/module/locale/type/TLocaleTitle.java
index 1b1a710..f29cc7b 100644
--- a/src/main/scala/com/ilummc/tlib/resources/type/TLocaleTitle.java
+++ b/src/main/scala/io/izzel/taboolib/module/locale/type/TLocaleTitle.java
@@ -1,10 +1,9 @@
-package com.ilummc.tlib.resources.type;
+package io.izzel.taboolib.module.locale.type;
import com.google.common.collect.Maps;
-import com.ilummc.tlib.resources.TLocale;
-import com.ilummc.tlib.resources.TLocaleSerialize;
-import com.ilummc.tlib.util.Strings;
-import me.skymc.taboolib.display.TitleUtils;
+import io.izzel.taboolib.module.locale.TLocale;
+import io.izzel.taboolib.module.locale.TLocaleSerialize;
+import io.izzel.taboolib.util.Strings;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.serialization.SerializableAs;
import org.bukkit.entity.Player;
diff --git a/src/main/scala/me/skymc/taboolib/common/nms/NMSHandler.java b/src/main/scala/io/izzel/taboolib/module/nms/NMS.java
similarity index 60%
rename from src/main/scala/me/skymc/taboolib/common/nms/NMSHandler.java
rename to src/main/scala/io/izzel/taboolib/module/nms/NMS.java
index 843fa49..f3dc202 100644
--- a/src/main/scala/me/skymc/taboolib/common/nms/NMSHandler.java
+++ b/src/main/scala/io/izzel/taboolib/module/nms/NMS.java
@@ -1,8 +1,9 @@
-package me.skymc.taboolib.common.nms;
+package io.izzel.taboolib.module.nms;
-import me.skymc.taboolib.common.function.TFunction;
-import me.skymc.taboolib.common.nms.nbt.NBTCompound;
-import me.skymc.taboolib.common.versioncontrol.SimpleVersionControl;
+import io.izzel.taboolib.module.inject.TFunction;
+import io.izzel.taboolib.module.lite.SimpleVersionControl;
+import io.izzel.taboolib.module.nms.nbt.NBTCompound;
+import org.bukkit.Particle;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@@ -12,22 +13,26 @@ import org.bukkit.inventory.ItemStack;
* @Since 2018-11-09 14:38
*/
@TFunction(enable = "init")
-public abstract class NMSHandler {
+public abstract class NMS {
- private static NMSHandler handler;
+ private static NMS impl;
- public static NMSHandler getHandler() {
- return handler;
+ public static NMS handle() {
+ return impl;
}
static void init() {
try {
- handler = (NMSHandler) SimpleVersionControl.createNMS("me.skymc.taboolib.common.nms.NMSHandlerImpl").translate().newInstance();
+ impl = (NMS) SimpleVersionControl.createNMS("io.izzel.taboolib.module.nms.NMSImpl").translate().newInstance();
} catch (Exception e) {
e.printStackTrace();
}
}
+ abstract public boolean isRunning();
+
+ abstract public Object toPacketPlayOutWorldParticles(Particle var1, boolean var2, float var3, float var4, float var5, float var6, float var7, float var8, float var9, int var10, Object var11);
+
abstract public double[] getTPS();
abstract public String getName(ItemStack itemStack);
diff --git a/src/main/scala/me/skymc/taboolib/common/nms/NMSHandlerImpl.java b/src/main/scala/io/izzel/taboolib/module/nms/NMSImpl.java
similarity index 81%
rename from src/main/scala/me/skymc/taboolib/common/nms/NMSHandlerImpl.java
rename to src/main/scala/io/izzel/taboolib/module/nms/NMSImpl.java
index e856d65..e42f5e6 100644
--- a/src/main/scala/me/skymc/taboolib/common/nms/NMSHandlerImpl.java
+++ b/src/main/scala/io/izzel/taboolib/module/nms/NMSImpl.java
@@ -1,17 +1,20 @@
-package me.skymc.taboolib.common.nms;
+package io.izzel.taboolib.module.nms;
-import me.skymc.taboolib.TabooLib;
-import me.skymc.taboolib.common.nms.nbt.NBTCompound;
-import me.skymc.taboolib.common.nms.nbt.NBTList;
-import me.skymc.taboolib.common.packet.TPacketHandler;
-import me.skymc.taboolib.common.util.SimpleReflection;
-import me.skymc.taboolib.nms.NMSUtils;
+import io.izzel.taboolib.Version;
+import io.izzel.taboolib.module.lite.SimpleReflection;
+import io.izzel.taboolib.module.nms.nbt.NBTCompound;
+import io.izzel.taboolib.module.nms.nbt.NBTList;
+import io.izzel.taboolib.module.packet.TPacketHandler;
import net.minecraft.server.v1_12_R1.ChatMessageType;
import net.minecraft.server.v1_12_R1.EntityVillager;
import net.minecraft.server.v1_12_R1.MinecraftServer;
import net.minecraft.server.v1_12_R1.NBTTagCompound;
import net.minecraft.server.v1_13_R2.IRegistry;
import net.minecraft.server.v1_8_R3.*;
+import org.bukkit.Bukkit;
+import org.bukkit.Particle;
+import org.bukkit.craftbukkit.v1_12_R1.CraftParticle;
+import org.bukkit.craftbukkit.v1_13_R2.CraftServer;
import org.bukkit.craftbukkit.v1_13_R2.entity.CraftVillager;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
import org.bukkit.entity.Entity;
@@ -28,9 +31,8 @@ import java.util.Map;
* @Author 坏黑
* @Since 2018-11-09 14:42
*/
-public class NMSHandlerImpl extends NMSHandler {
+public class NMSImpl extends NMS {
- private final int VERSION = TabooLib.getVersionNumber();
private Field entityTypesField;
static {
@@ -47,16 +49,27 @@ public class NMSHandlerImpl extends NMSHandler {
SimpleReflection.saveField(NBTTagCompound.class);
}
- public NMSHandlerImpl() {
- if (TabooLib.getVersionNumber() >= 11300) {
- for (Field declaredField : NMSUtils.getNMSClass("Entity").getDeclaredFields()) {
+ public NMSImpl() {
+ if (Version.isAfter(Version.v1_13)) {
+ SimpleReflection.saveField(net.minecraft.server.v1_12_R1.Entity.class);
+ for (Field declaredField : SimpleReflection.getFields(net.minecraft.server.v1_12_R1.Entity.class).values()) {
if (declaredField.getType().getSimpleName().equals("EntityTypes")) {
- declaredField.setAccessible(true);
entityTypesField = declaredField;
break;
}
}
}
+ SimpleReflection.saveField(MinecraftServer.class);
+ }
+
+ @Override
+ public boolean isRunning() {
+ return !SimpleReflection.getFieldValue(MinecraftServer.class, ((CraftServer) Bukkit.getServer()).getServer(), "hasStopped", false);
+ }
+
+ @Override
+ public Object toPacketPlayOutWorldParticles(Particle var1, boolean var2, float var3, float var4, float var5, float var6, float var7, float var8, float var9, int var10, Object var11) {
+ return new net.minecraft.server.v1_12_R1.PacketPlayOutWorldParticles(CraftParticle.toNMS(var1), var2, var3, var4, var5, var6, var7, var8, var9, var10, CraftParticle.toData(var1, var11));
}
@Override
@@ -67,13 +80,13 @@ public class NMSHandlerImpl extends NMSHandler {
@Override
public String getName(ItemStack itemStack) {
Object nmsItem = CraftItemStack.asNMSCopy(itemStack);
- if (TabooLib.getVersionNumber() >= 11300) {
+ if (Version.isAfter(Version.v1_13)) {
String name = ((net.minecraft.server.v1_8_R3.ItemStack) nmsItem).getItem().getName();
if (itemStack.getItemMeta() instanceof PotionMeta) {
name += ".effect." + ((net.minecraft.server.v1_8_R3.ItemStack) nmsItem).getTag().getString("Potion").replaceAll("minecraft:(strong_|long_)?", "");
}
return name;
- } else if (TabooLib.getVersionNumber() >= 11100) {
+ } else if (Version.isAfter(Version.v1_11)) {
String name = ((net.minecraft.server.v1_12_R1.ItemStack) nmsItem).getItem().a((net.minecraft.server.v1_12_R1.ItemStack) nmsItem);
if (itemStack.getItemMeta() instanceof PotionMeta) {
return name.replace("item.", "") + ".effect." + ((net.minecraft.server.v1_8_R3.ItemStack) nmsItem).getTag().getString("Potion").replaceAll("(minecraft:)?(strong_|long_)?", "");
@@ -90,10 +103,10 @@ public class NMSHandlerImpl extends NMSHandler {
@Override
public String getName(Entity entity) {
- if (TabooLib.getVersionNumber() >= 11400) {
+ if (Version.isAfter(Version.v1_14)) {
net.minecraft.server.v1_14_R1.MinecraftKey minecraftKey = net.minecraft.server.v1_14_R1.EntityTypes.getName(((org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity) entity).getHandle().getEntityType());
return "entity.minecraft." + minecraftKey.getKey();
- } else if (TabooLib.getVersionNumber() == 11300) {
+ } else if (Version.isAfter(Version.v1_13)) {
try {
String name = "entity.minecraft." + IRegistry.ENTITY_TYPE.getKey((net.minecraft.server.v1_13_R2.EntityTypes>) entityTypesField.get(((org.bukkit.craftbukkit.v1_13_R2.entity.CraftEntity) entity).getHandle())).getKey();
if (entity instanceof Villager && ((CraftVillager) entity).getCareer() != null) {
@@ -177,7 +190,7 @@ public class NMSHandlerImpl extends NMSHandler {
@Override
public void sendActionBar(Player player, String text) {
- if (TabooLib.getVersionNumber() > 11100) {
+ if (Version.isAfter(Version.v1_12)) {
TPacketHandler.sendPacket(player, new net.minecraft.server.v1_12_R1.PacketPlayOutChat(new net.minecraft.server.v1_12_R1.ChatComponentText(String.valueOf(text)), ChatMessageType.GAME_INFO));
} else {
TPacketHandler.sendPacket(player, new PacketPlayOutChat(new ChatComponentText(String.valueOf(text)), (byte) 2));
@@ -188,7 +201,7 @@ public class NMSHandlerImpl extends NMSHandler {
public ItemStack _NBT(ItemStack itemStack, Object compound) {
Object nmsItem = CraftItemStack.asNMSCopy(itemStack);
try {
- ((net.minecraft.server.v1_8_R3.ItemStack) nmsItem).setTag((net.minecraft.server.v1_8_R3.NBTTagCompound) toNBTBase((me.skymc.taboolib.common.nms.nbt.NBTBase) compound));
+ ((net.minecraft.server.v1_8_R3.ItemStack) nmsItem).setTag((net.minecraft.server.v1_8_R3.NBTTagCompound) toNBTBase((io.izzel.taboolib.module.nms.nbt.NBTBase) compound));
} catch (Throwable t) {
t.printStackTrace();
}
@@ -206,7 +219,7 @@ public class NMSHandlerImpl extends NMSHandler {
return new NBTCompound();
}
- private Object toNBTBase(me.skymc.taboolib.common.nms.nbt.NBTBase base) {
+ private Object toNBTBase(io.izzel.taboolib.module.nms.nbt.NBTBase base) {
switch (base.getType().getId()) {
case 1:
return new NBTTagByte(base.asByte());
@@ -228,13 +241,13 @@ public class NMSHandlerImpl extends NMSHandler {
return new NBTTagString(base.asString());
case 9:
Object nmsList = new NBTTagList();
- for (me.skymc.taboolib.common.nms.nbt.NBTBase value : base.asList()) {
+ for (io.izzel.taboolib.module.nms.nbt.NBTBase value : base.asList()) {
// 1.14+
- if (TabooLib.getVersionNumber() >= 11400) {
+ if (Version.isAfter(Version.v1_14)) {
((net.minecraft.server.v1_14_R1.NBTTagList) nmsList).add(((net.minecraft.server.v1_14_R1.NBTTagList) nmsList).size(), (net.minecraft.server.v1_14_R1.NBTBase) toNBTBase(value));
}
// 1.13
- else if (TabooLib.getVersionNumber() == 11300) {
+ else if (Version.isAfter(Version.v1_13)) {
((net.minecraft.server.v1_13_R2.NBTTagList) nmsList).add((net.minecraft.server.v1_13_R2.NBTBase) toNBTBase(value));
}
// 1.12-
@@ -245,7 +258,7 @@ public class NMSHandlerImpl extends NMSHandler {
return nmsList;
case 10:
Object nmsTag = new net.minecraft.server.v1_8_R3.NBTTagCompound();
- for (Map.Entry entry : base.asCompound().entrySet()) {
+ for (Map.Entry entry : base.asCompound().entrySet()) {
((Map) SimpleReflection.getFieldValue(NBTTagCompound.class, nmsTag, "map")).put(entry.getKey(), toNBTBase(entry.getValue()));
}
return nmsTag;
@@ -257,33 +270,33 @@ public class NMSHandlerImpl extends NMSHandler {
if (base instanceof net.minecraft.server.v1_8_R3.NBTTagCompound) {
NBTCompound nbtCompound = new NBTCompound();
for (Map.Entry entry : ((Map) SimpleReflection.getFieldValue(NBTTagCompound.class, base, "map")).entrySet()) {
- nbtCompound.put(entry.getKey(), (me.skymc.taboolib.common.nms.nbt.NBTBase) fromNBTBase(entry.getValue()));
+ nbtCompound.put(entry.getKey(), (io.izzel.taboolib.module.nms.nbt.NBTBase) fromNBTBase(entry.getValue()));
}
return nbtCompound;
} else if (base instanceof NBTTagList) {
NBTList nbtList = new NBTList();
for (Object v : (List) SimpleReflection.getFieldValue(NBTTagList.class, base, "list")) {
- nbtList.add((me.skymc.taboolib.common.nms.nbt.NBTBase) fromNBTBase(v));
+ nbtList.add((io.izzel.taboolib.module.nms.nbt.NBTBase) fromNBTBase(v));
}
return nbtList;
} else if (base instanceof NBTTagString) {
- return new me.skymc.taboolib.common.nms.nbt.NBTBase(SimpleReflection.getFieldValue(NBTTagString.class, base, "data", ""));
+ return new io.izzel.taboolib.module.nms.nbt.NBTBase(SimpleReflection.getFieldValue(NBTTagString.class, base, "data", ""));
} else if (base instanceof NBTTagDouble) {
- return new me.skymc.taboolib.common.nms.nbt.NBTBase(SimpleReflection.getFieldValue(NBTTagDouble.class, base, "data", 0D));
+ return new io.izzel.taboolib.module.nms.nbt.NBTBase(SimpleReflection.getFieldValue(NBTTagDouble.class, base, "data", 0D));
} else if (base instanceof NBTTagInt) {
- return new me.skymc.taboolib.common.nms.nbt.NBTBase(SimpleReflection.getFieldValue(NBTTagInt.class, base, "data", 0));
+ return new io.izzel.taboolib.module.nms.nbt.NBTBase(SimpleReflection.getFieldValue(NBTTagInt.class, base, "data", 0));
} else if (base instanceof NBTTagFloat) {
- return new me.skymc.taboolib.common.nms.nbt.NBTBase(SimpleReflection.getFieldValue(NBTTagFloat.class, base, "data", (float) 0));
+ return new io.izzel.taboolib.module.nms.nbt.NBTBase(SimpleReflection.getFieldValue(NBTTagFloat.class, base, "data", (float) 0));
} else if (base instanceof NBTTagShort) {
- return new me.skymc.taboolib.common.nms.nbt.NBTBase(SimpleReflection.getFieldValue(NBTTagShort.class, base, "data", (short) 0));
+ return new io.izzel.taboolib.module.nms.nbt.NBTBase(SimpleReflection.getFieldValue(NBTTagShort.class, base, "data", (short) 0));
} else if (base instanceof NBTTagLong) {
- return new me.skymc.taboolib.common.nms.nbt.NBTBase(SimpleReflection.getFieldValue(NBTTagLong.class, base, "data", 0L));
+ return new io.izzel.taboolib.module.nms.nbt.NBTBase(SimpleReflection.getFieldValue(NBTTagLong.class, base, "data", 0L));
} else if (base instanceof NBTTagByte) {
- return new me.skymc.taboolib.common.nms.nbt.NBTBase(SimpleReflection.getFieldValue(NBTTagByte.class, base, "data", (byte) 0D));
+ return new io.izzel.taboolib.module.nms.nbt.NBTBase(SimpleReflection.getFieldValue(NBTTagByte.class, base, "data", (byte) 0D));
} else if (base instanceof NBTTagIntArray) {
- return new me.skymc.taboolib.common.nms.nbt.NBTBase(SimpleReflection.getFieldValue(NBTTagIntArray.class, base, "data", new int[0]));
+ return new io.izzel.taboolib.module.nms.nbt.NBTBase(SimpleReflection.getFieldValue(NBTTagIntArray.class, base, "data", new int[0]));
} else if (base instanceof NBTTagByteArray) {
- return new me.skymc.taboolib.common.nms.nbt.NBTBase(SimpleReflection.getFieldValue(NBTTagByteArray.class, base, "data", new byte[0]));
+ return new io.izzel.taboolib.module.nms.nbt.NBTBase(SimpleReflection.getFieldValue(NBTTagByteArray.class, base, "data", new byte[0]));
}
return null;
}
diff --git a/src/main/scala/me/skymc/taboolib/common/nms/nbt/NBTBase.java b/src/main/scala/io/izzel/taboolib/module/nms/nbt/NBTBase.java
similarity index 98%
rename from src/main/scala/me/skymc/taboolib/common/nms/nbt/NBTBase.java
rename to src/main/scala/io/izzel/taboolib/module/nms/nbt/NBTBase.java
index ad5ebce..d76f69b 100644
--- a/src/main/scala/me/skymc/taboolib/common/nms/nbt/NBTBase.java
+++ b/src/main/scala/io/izzel/taboolib/module/nms/nbt/NBTBase.java
@@ -1,4 +1,4 @@
-package me.skymc.taboolib.common.nms.nbt;
+package io.izzel.taboolib.module.nms.nbt;
import java.util.Arrays;
import java.util.Objects;
diff --git a/src/main/scala/me/skymc/taboolib/common/nms/nbt/NBTCompound.java b/src/main/scala/io/izzel/taboolib/module/nms/nbt/NBTCompound.java
similarity index 98%
rename from src/main/scala/me/skymc/taboolib/common/nms/nbt/NBTCompound.java
rename to src/main/scala/io/izzel/taboolib/module/nms/nbt/NBTCompound.java
index d7a34ef..f475678 100644
--- a/src/main/scala/me/skymc/taboolib/common/nms/nbt/NBTCompound.java
+++ b/src/main/scala/io/izzel/taboolib/module/nms/nbt/NBTCompound.java
@@ -1,4 +1,4 @@
-package me.skymc.taboolib.common.nms.nbt;
+package io.izzel.taboolib.module.nms.nbt;
import com.google.common.collect.Maps;
diff --git a/src/main/scala/me/skymc/taboolib/common/nms/nbt/NBTList.java b/src/main/scala/io/izzel/taboolib/module/nms/nbt/NBTList.java
similarity index 96%
rename from src/main/scala/me/skymc/taboolib/common/nms/nbt/NBTList.java
rename to src/main/scala/io/izzel/taboolib/module/nms/nbt/NBTList.java
index 83a47c3..06ed845 100644
--- a/src/main/scala/me/skymc/taboolib/common/nms/nbt/NBTList.java
+++ b/src/main/scala/io/izzel/taboolib/module/nms/nbt/NBTList.java
@@ -1,8 +1,7 @@
-package me.skymc.taboolib.common.nms.nbt;
-
-import com.google.common.collect.Lists;
+package io.izzel.taboolib.module.nms.nbt;
import java.util.*;
+import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;
@@ -14,7 +13,7 @@ import java.util.stream.Stream;
*/
public class NBTList extends NBTBase implements List {
- private List value = Lists.newCopyOnWriteArrayList();
+ private List value = new CopyOnWriteArrayList<>();
public NBTList() {
super(0);
diff --git a/src/main/scala/me/skymc/taboolib/common/nms/nbt/NBTType.java b/src/main/scala/io/izzel/taboolib/module/nms/nbt/NBTType.java
similarity index 90%
rename from src/main/scala/me/skymc/taboolib/common/nms/nbt/NBTType.java
rename to src/main/scala/io/izzel/taboolib/module/nms/nbt/NBTType.java
index b1769cd..21f06d1 100644
--- a/src/main/scala/me/skymc/taboolib/common/nms/nbt/NBTType.java
+++ b/src/main/scala/io/izzel/taboolib/module/nms/nbt/NBTType.java
@@ -1,4 +1,4 @@
-package me.skymc.taboolib.common.nms.nbt;
+package io.izzel.taboolib.module.nms.nbt;
/**
* @Author 坏黑
diff --git a/src/main/scala/me/skymc/taboolib/common/packet/TPacketHandler.java b/src/main/scala/io/izzel/taboolib/module/packet/TPacketHandler.java
similarity index 87%
rename from src/main/scala/me/skymc/taboolib/common/packet/TPacketHandler.java
rename to src/main/scala/io/izzel/taboolib/module/packet/TPacketHandler.java
index 5a00d14..4dee6a7 100644
--- a/src/main/scala/me/skymc/taboolib/common/packet/TPacketHandler.java
+++ b/src/main/scala/io/izzel/taboolib/module/packet/TPacketHandler.java
@@ -1,10 +1,10 @@
-package me.skymc.taboolib.common.packet;
+package io.izzel.taboolib.module.packet;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
-import me.skymc.taboolib.common.packet.channel.ChannelExecutor;
-import me.skymc.taboolib.common.versioncontrol.SimpleVersionControl;
-import me.skymc.taboolib.listener.TListener;
+import io.izzel.taboolib.module.packet.channel.ChannelExecutor;
+import io.izzel.taboolib.module.lite.SimpleVersionControl;
+import io.izzel.taboolib.module.inject.TListener;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@@ -30,7 +30,7 @@ public class TPacketHandler implements Listener {
public TPacketHandler() {
try {
- channelExecutor = (ChannelExecutor) SimpleVersionControl.createNMS("me.skymc.taboolib.common.packet.channel.InternalChannelExecutor").translate().newInstance();
+ channelExecutor = (ChannelExecutor) SimpleVersionControl.createNMS("io.izzel.taboolib.module.packet.channel.InternalChannelExecutor").translate().newInstance();
} catch (Exception e) {
e.printStackTrace();
}
diff --git a/src/main/scala/me/skymc/taboolib/common/packet/TPacketListener.java b/src/main/scala/io/izzel/taboolib/module/packet/TPacketListener.java
similarity index 88%
rename from src/main/scala/me/skymc/taboolib/common/packet/TPacketListener.java
rename to src/main/scala/io/izzel/taboolib/module/packet/TPacketListener.java
index 03bc82b..cc36ce4 100644
--- a/src/main/scala/me/skymc/taboolib/common/packet/TPacketListener.java
+++ b/src/main/scala/io/izzel/taboolib/module/packet/TPacketListener.java
@@ -1,4 +1,4 @@
-package me.skymc.taboolib.common.packet;
+package io.izzel.taboolib.module.packet;
import org.bukkit.entity.Player;
diff --git a/src/main/scala/me/skymc/taboolib/common/packet/channel/ChannelExecutor.java b/src/main/scala/io/izzel/taboolib/module/packet/channel/ChannelExecutor.java
similarity index 96%
rename from src/main/scala/me/skymc/taboolib/common/packet/channel/ChannelExecutor.java
rename to src/main/scala/io/izzel/taboolib/module/packet/channel/ChannelExecutor.java
index 20143cb..e0c0045 100644
--- a/src/main/scala/me/skymc/taboolib/common/packet/channel/ChannelExecutor.java
+++ b/src/main/scala/io/izzel/taboolib/module/packet/channel/ChannelExecutor.java
@@ -1,10 +1,10 @@
-package me.skymc.taboolib.common.packet.channel;
+package io.izzel.taboolib.module.packet.channel;
import io.netty.channel.Channel;
import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
-import me.skymc.taboolib.common.packet.TPacketHandler;
+import io.izzel.taboolib.module.packet.TPacketHandler;
import org.bukkit.entity.Player;
import java.util.Collection;
diff --git a/src/main/scala/me/skymc/taboolib/common/packet/channel/InternalChannelExecutor.java b/src/main/scala/io/izzel/taboolib/module/packet/channel/InternalChannelExecutor.java
similarity index 88%
rename from src/main/scala/me/skymc/taboolib/common/packet/channel/InternalChannelExecutor.java
rename to src/main/scala/io/izzel/taboolib/module/packet/channel/InternalChannelExecutor.java
index bbaf842..3b59a64 100644
--- a/src/main/scala/me/skymc/taboolib/common/packet/channel/InternalChannelExecutor.java
+++ b/src/main/scala/io/izzel/taboolib/module/packet/channel/InternalChannelExecutor.java
@@ -1,6 +1,6 @@
-package me.skymc.taboolib.common.packet.channel;
+package io.izzel.taboolib.module.packet.channel;
-import com.ilummc.tlib.logger.TLogger;
+import io.izzel.taboolib.module.locale.logger.TLogger;
import io.netty.channel.Channel;
import net.minecraft.server.v1_8_R3.Packet;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
diff --git a/src/main/scala/me/skymc/taboolib/json/tellraw/TellrawCreator.java b/src/main/scala/io/izzel/taboolib/module/tellraw/TellrawCreator.java
similarity index 71%
rename from src/main/scala/me/skymc/taboolib/json/tellraw/TellrawCreator.java
rename to src/main/scala/io/izzel/taboolib/module/tellraw/TellrawCreator.java
index d65397c..a792500 100644
--- a/src/main/scala/me/skymc/taboolib/json/tellraw/TellrawCreator.java
+++ b/src/main/scala/io/izzel/taboolib/module/tellraw/TellrawCreator.java
@@ -1,26 +1,26 @@
-package me.skymc.taboolib.json.tellraw;
+package io.izzel.taboolib.module.tellraw;
-import me.skymc.taboolib.common.loader.Instantiable;
-import me.skymc.taboolib.common.versioncontrol.SimpleVersionControl;
-import me.skymc.taboolib.json.tellraw.internal.AbstractTellraw;
+import io.izzel.taboolib.module.inject.TFunction;
+import io.izzel.taboolib.module.lite.SimpleVersionControl;
+import io.izzel.taboolib.module.tellraw.internal.AbstractTellraw;
import org.bukkit.Bukkit;
/**
* @Author 坏黑
* @Since 2018-11-07 22:58
*/
-@Instantiable("TabooLib|TellrawCreator")
+@TFunction(enable = "init")
public class TellrawCreator {
private static AbstractTellraw abstractTellraw;
private static boolean viaVersionLoaded;
private static boolean protocolSupportLoaded;
- public TellrawCreator() {
+ public static void init() {
viaVersionLoaded = Bukkit.getPluginManager().getPlugin("ViaVersion") != null;
protocolSupportLoaded = Bukkit.getPluginManager().getPlugin("ProtocolSupport") != null;
try {
- abstractTellraw = (AbstractTellraw) SimpleVersionControl.createNMS("me.skymc.taboolib.json.tellraw.internal.InternalTellraw").translate().newInstance();
+ abstractTellraw = (AbstractTellraw) SimpleVersionControl.createNMS("io.izzel.taboolib.module.tellraw.internal.InternalTellraw").translate().newInstance();
} catch (Exception e) {
e.printStackTrace();
}
diff --git a/src/main/scala/me/skymc/taboolib/json/tellraw/TellrawJson.java b/src/main/scala/io/izzel/taboolib/module/tellraw/TellrawJson.java
similarity index 89%
rename from src/main/scala/me/skymc/taboolib/json/tellraw/TellrawJson.java
rename to src/main/scala/io/izzel/taboolib/module/tellraw/TellrawJson.java
index 12e0fb0..3ce5607 100644
--- a/src/main/scala/me/skymc/taboolib/json/tellraw/TellrawJson.java
+++ b/src/main/scala/io/izzel/taboolib/module/tellraw/TellrawJson.java
@@ -1,11 +1,9 @@
-package me.skymc.taboolib.json.tellraw;
+package io.izzel.taboolib.module.tellraw;
-import com.ilummc.tlib.bungee.api.chat.*;
-import com.ilummc.tlib.bungee.chat.ComponentSerializer;
-import com.ilummc.tlib.resources.TLocale;
-import com.ilummc.tlib.util.Strings;
-import me.skymc.taboolib.TabooLib;
-import me.skymc.taboolib.string.ArrayUtils;
+import io.izzel.taboolib.module.locale.TLocale;
+import io.izzel.taboolib.util.ArrayUtil;
+import io.izzel.taboolib.util.Strings;
+import io.izzel.taboolib.util.chat.*;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -13,10 +11,7 @@ import org.bukkit.inventory.ItemStack;
import protocolsupport.api.ProtocolSupportAPI;
import us.myles.ViaVersion.api.Via;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import java.util.stream.Collectors;
/**
@@ -26,11 +21,10 @@ import java.util.stream.Collectors;
*/
public class TellrawJson {
- private int bukkitVersion = TabooLib.getVersionNumber();
private List components = new ArrayList<>();
private List componentsLatest = new ArrayList<>();
private Map itemTag = new HashMap<>();
- private List nbtWhitelist = ArrayUtils.asList(
+ private List nbtWhitelist = ArrayUtil.asList(
// 附魔
"ench",
// 附魔书
@@ -113,13 +107,13 @@ public class TellrawJson {
public TellrawJson append(String text) {
appendComponents();
- componentsLatest.addAll(ArrayUtils.asList(TextComponent.fromLegacyText(text)));
+ componentsLatest.addAll(Arrays.asList(TextComponent.fromLegacyText(text)));
return this;
}
public TellrawJson append(TellrawJson json) {
appendComponents();
- componentsLatest.addAll(ArrayUtils.asList(json.getComponentsAll()));
+ componentsLatest.addAll(Arrays.asList(json.getComponentsAll()));
itemTag.putAll(json.itemTag);
return this;
}
@@ -188,7 +182,7 @@ public class TellrawJson {
}
private void setLatestComponent(BaseComponent... component) {
- componentsLatest.addAll(ArrayUtils.asList(component));
+ componentsLatest.addAll(Arrays.asList(component));
}
private void appendComponents() {
@@ -203,17 +197,13 @@ public class TellrawJson {
// *********************************
public void setComponents(BaseComponent[] components) {
- this.components = ArrayUtils.asList(components);
+ this.components = Arrays.asList(components);
}
public BaseComponent[] getComponents() {
return components.toArray(new BaseComponent[0]);
}
- public int getBukkitVersion() {
- return bukkitVersion;
- }
-
public List getComponentsLatest() {
return componentsLatest;
}
diff --git a/src/main/scala/me/skymc/taboolib/json/tellraw/TellrawVersion.java b/src/main/scala/io/izzel/taboolib/module/tellraw/TellrawVersion.java
similarity index 76%
rename from src/main/scala/me/skymc/taboolib/json/tellraw/TellrawVersion.java
rename to src/main/scala/io/izzel/taboolib/module/tellraw/TellrawVersion.java
index 81bc02d..c52526f 100644
--- a/src/main/scala/me/skymc/taboolib/json/tellraw/TellrawVersion.java
+++ b/src/main/scala/io/izzel/taboolib/module/tellraw/TellrawVersion.java
@@ -1,4 +1,4 @@
-package me.skymc.taboolib.json.tellraw;
+package io.izzel.taboolib.module.tellraw;
/**
* @Author 坏黑
diff --git a/src/main/scala/me/skymc/taboolib/json/tellraw/internal/AbstractTellraw.java b/src/main/scala/io/izzel/taboolib/module/tellraw/internal/AbstractTellraw.java
similarity index 82%
rename from src/main/scala/me/skymc/taboolib/json/tellraw/internal/AbstractTellraw.java
rename to src/main/scala/io/izzel/taboolib/module/tellraw/internal/AbstractTellraw.java
index f20ad06..1dfa35c 100644
--- a/src/main/scala/me/skymc/taboolib/json/tellraw/internal/AbstractTellraw.java
+++ b/src/main/scala/io/izzel/taboolib/module/tellraw/internal/AbstractTellraw.java
@@ -1,6 +1,6 @@
-package me.skymc.taboolib.json.tellraw.internal;
+package io.izzel.taboolib.module.tellraw.internal;
-import me.skymc.taboolib.json.tellraw.TellrawVersion;
+import io.izzel.taboolib.module.tellraw.TellrawVersion;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
diff --git a/src/main/scala/me/skymc/taboolib/json/tellraw/internal/InternalTellraw.java b/src/main/scala/io/izzel/taboolib/module/tellraw/internal/InternalTellraw.java
similarity index 88%
rename from src/main/scala/me/skymc/taboolib/json/tellraw/internal/InternalTellraw.java
rename to src/main/scala/io/izzel/taboolib/module/tellraw/internal/InternalTellraw.java
index 32bf0ef..0cecd9d 100644
--- a/src/main/scala/me/skymc/taboolib/json/tellraw/internal/InternalTellraw.java
+++ b/src/main/scala/io/izzel/taboolib/module/tellraw/internal/InternalTellraw.java
@@ -1,10 +1,10 @@
-package me.skymc.taboolib.json.tellraw.internal;
+package io.izzel.taboolib.module.tellraw.internal;
-import me.skymc.taboolib.TabooLib;
-import me.skymc.taboolib.common.packet.TPacketHandler;
-import me.skymc.taboolib.common.util.SimpleReflection;
-import me.skymc.taboolib.inventory.ItemUtils;
-import me.skymc.taboolib.json.tellraw.TellrawVersion;
+import io.izzel.taboolib.Version;
+import io.izzel.taboolib.util.item.Items;
+import io.izzel.taboolib.module.lite.SimpleReflection;
+import io.izzel.taboolib.module.packet.TPacketHandler;
+import io.izzel.taboolib.module.tellraw.TellrawVersion;
import net.minecraft.server.v1_8_R3.*;
import org.bukkit.Material;
import org.bukkit.block.ShulkerBox;
@@ -13,6 +13,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BlockStateMeta;
+import org.bukkit.inventory.meta.ItemMeta;
import java.util.List;
import java.util.Map;
@@ -23,8 +24,6 @@ import java.util.Map;
*/
public class InternalTellraw implements AbstractTellraw {
- private int bukkitVersion = TabooLib.getVersionNumber();
-
public InternalTellraw() {
SimpleReflection.saveField(NBTTagCompound.class, "map");
SimpleReflection.saveField(NBTTagList.class, "list");
@@ -74,10 +73,12 @@ public class InternalTellraw implements AbstractTellraw {
ItemStack[] contentsClone = new ItemStack[contents.length];
for (int i = 0; i < contents.length; i++) {
ItemStack content = contents[i];
- if (!ItemUtils.isNull(content)) {
+ if (!Items.isNull(content)) {
ItemStack contentClone = new ItemStack(Material.STONE, content.getAmount(), content.getDurability());
if (content.getItemMeta().hasDisplayName()) {
- ItemUtils.setName(contentClone, content.getItemMeta().getDisplayName());
+ ItemMeta itemMeta = contentClone.getItemMeta();
+ itemMeta.setDisplayName(content.getItemMeta().getDisplayName());
+ contentClone.setItemMeta(itemMeta);
}
contentsClone[i] = contentClone;
}
@@ -127,7 +128,7 @@ public class InternalTellraw implements AbstractTellraw {
if (i != 0) {
builder.append(',');
}
- if (version == TellrawVersion.HIGH_VERSION || (this.bukkitVersion >= 11200 && version == TellrawVersion.CURRENT_VERSION)) {
+ if (version == TellrawVersion.HIGH_VERSION || (Version.isAfter(Version.v1_12) && version == TellrawVersion.CURRENT_VERSION)) {
builder.append(list.get(i));
} else {
builder.append(i).append(':').append(list.get(i));
diff --git a/src/main/scala/me/skymc/taboolib/string/ArrayUtils.java b/src/main/scala/io/izzel/taboolib/util/ArrayUtil.java
similarity index 74%
rename from src/main/scala/me/skymc/taboolib/string/ArrayUtils.java
rename to src/main/scala/io/izzel/taboolib/util/ArrayUtil.java
index b2da4df..17c96f5 100644
--- a/src/main/scala/me/skymc/taboolib/string/ArrayUtils.java
+++ b/src/main/scala/io/izzel/taboolib/util/ArrayUtil.java
@@ -1,9 +1,5 @@
-package me.skymc.taboolib.string;
+package io.izzel.taboolib.util;
-import com.ilummc.tlib.util.Strings;
-
-import java.io.*;
-import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -14,7 +10,7 @@ import java.util.stream.IntStream;
* @author Bkm016
* @since 2018-04-16
*/
-public class ArrayUtils {
+public class ArrayUtil {
public static int indexOf(T[] array, T obj) {
return array == null || array.length == 0 ? -1 : IntStream.range(0, array.length).filter(i -> array[i] != null && array[i].equals(obj)).findFirst().orElse(-1);
@@ -47,29 +43,20 @@ public class ArrayUtils {
@SuppressWarnings("SuspiciousSystemArraycopy")
public static T arrayExpand(T oldArray, int expand) {
- int length = Array.getLength(oldArray);
- Object newArray = Array.newInstance(oldArray.getClass().getComponentType(), length + expand);
+ int length = java.lang.reflect.Array.getLength(oldArray);
+ Object newArray = java.lang.reflect.Array.newInstance(oldArray.getClass().getComponentType(), length + expand);
System.arraycopy(oldArray, 0, newArray, 0, length);
return (T) newArray;
}
@SuppressWarnings("SuspiciousSystemArraycopy")
public static T arrayExpandAtFirst(T oldArray, int expand) {
- int length = Array.getLength(oldArray);
- Object newArray = Array.newInstance(oldArray.getClass().getComponentType(), length + expand);
+ int length = java.lang.reflect.Array.getLength(oldArray);
+ Object newArray = java.lang.reflect.Array.newInstance(oldArray.getClass().getComponentType(), length + expand);
System.arraycopy(oldArray, 0, newArray, expand, length);
return (T) newArray;
}
- public static T cloneAsByte(T obj) throws IOException, ClassNotFoundException {
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
- objectOutputStream.writeObject(obj);
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
- ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
- return (T) objectInputStream.readObject();
- }
-
public static T skipEmpty(T obj) {
return skipEmpty(obj, null);
}
diff --git a/src/main/scala/io/izzel/taboolib/util/Files.java b/src/main/scala/io/izzel/taboolib/util/Files.java
new file mode 100644
index 0000000..c01d766
--- /dev/null
+++ b/src/main/scala/io/izzel/taboolib/util/Files.java
@@ -0,0 +1,269 @@
+package io.izzel.taboolib.util;
+
+import io.izzel.taboolib.TabooLib;
+import io.izzel.taboolib.common.plugin.InternalPlugin;
+import org.bukkit.configuration.file.FileConfiguration;
+import org.bukkit.configuration.file.YamlConfiguration;
+import org.bukkit.plugin.Plugin;
+import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
+
+import java.io.*;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.nio.channels.FileChannel;
+import java.nio.charset.Charset;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.jar.JarFile;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+/**
+ * @author sky
+ */
+public class Files {
+
+ public static List getClasses(Plugin plugin) {
+ return getClasses(plugin, new String[0]);
+ }
+
+ public static List getClasses(Plugin plugin, String[] ignore) {
+ List classes = new CopyOnWriteArrayList<>();
+ URL url = plugin.getClass().getProtectionDomain().getCodeSource().getLocation();
+ try {
+ File src;
+ try {
+ src = new File(url.toURI());
+ } catch (URISyntaxException e) {
+ src = new File(url.getPath());
+ }
+ new JarFile(src).stream().filter(entry -> entry.getName().endsWith(".class")).forEach(entry -> {
+ String className = entry.getName().replace('/', '.').substring(0, entry.getName().length() - 6);
+ try {
+ if (Arrays.stream(ignore).noneMatch(className::startsWith)) {
+ classes.add(Class.forName(className, false, plugin.getClass().getClassLoader()));
+ }
+ } catch (Throwable ignored) {
+ }
+ });
+ } catch (Throwable ignored) {
+ }
+ return classes;
+ }
+
+ public static InputStream getResource(String filename) {
+ return getResource(TabooLib.getPlugin(), filename);
+ }
+
+ public static InputStream getResource(Plugin plugin, String filename) {
+ return plugin instanceof InternalPlugin ? getResourceTabooLib(filename) : plugin.getClass().getClassLoader().getResourceAsStream(filename);
+ }
+
+ public static InputStream getResourceTabooLib(String filename) {
+ try {
+ ZipFile zipFile = new ZipFile(new File("TabooLib.jar"));
+ ZipEntry entry = zipFile.getEntry(filename);
+ if (entry != null) {
+ return zipFile.getInputStream(entry);
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return TabooLib.class.getResourceAsStream(filename);
+ }
+
+ public static void releaseResource(Plugin plugin, String path, boolean replace) {
+ File file = new File(plugin.getDataFolder(), path);
+ if (!file.exists() || replace) {
+ toFile(getResource(plugin, path), Files.file(file));
+ }
+ }
+
+ public static void toFile(String in, File file) {
+ try (FileWriter fileWriter = new FileWriter(file); BufferedWriter bufferedWriter = new BufferedWriter(fileWriter)) {
+ bufferedWriter.write(in);
+ bufferedWriter.flush();
+ } catch (Exception ignored) {
+ }
+ }
+
+ public static void toFile(InputStream inputStream, File file) {
+ try (FileOutputStream fos = new FileOutputStream(file); BufferedOutputStream bos = new BufferedOutputStream(fos)) {
+ byte[] buf = new byte[1024];
+ int len;
+ while ((len = inputStream.read(buf)) > 0) {
+ bos.write(buf, 0, len);
+ }
+ bos.flush();
+ } catch (Exception ignored) {
+ }
+ }
+
+ public static File file(File path, String filePath) {
+ return file(new File(path, filePath));
+ }
+
+ public static File file(String filePath) {
+ return file(new File(filePath));
+ }
+
+ public static File file(File file) {
+ if (!file.exists()) {
+ folder(file);
+ try {
+ file.createNewFile();
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ }
+ return file;
+ }
+
+ public static File folder(File path, String filePath) {
+ return folder(new File(path, filePath));
+ }
+
+ public static File folder(String filePath) {
+ return folder(new File(filePath));
+ }
+
+ public static File folder(File file) {
+ if (!file.exists()) {
+ String filePath = file.getPath();
+ int index = filePath.lastIndexOf(File.separator);
+ String folderPath;
+ File folder;
+ if ((index >= 0) && (!(folder = new File(filePath.substring(0, index))).exists())) {
+ folder.mkdirs();
+ }
+ }
+ return file;
+ }
+
+ public static void deepDelete(File file) {
+ if (!file.exists()) {
+ return;
+ }
+ if (file.isFile()) {
+ file.delete();
+ return;
+ }
+ for (File file1 : Objects.requireNonNull(file.listFiles())) {
+ deepDelete(file1);
+ }
+ file.delete();
+ }
+
+ public static void deepCopy(String originFileName, String targetFileName) {
+ File originFile = new File(originFileName);
+ File targetFile = new File(targetFileName);
+ if (!targetFile.exists()) {
+ if (!originFile.isDirectory()) {
+ file(targetFile);
+ } else {
+ targetFile.mkdirs();
+ }
+ }
+ if (originFile.isDirectory()) {
+ for (File file : Objects.requireNonNull(originFile.listFiles())) {
+ if (file.isDirectory()) {
+ deepCopy(file.getAbsolutePath(), targetFileName + "/" + file.getName());
+ } else {
+ weekCopy(file, new File(targetFileName + "/" + file.getName()));
+ }
+ }
+ } else {
+ weekCopy(originFile, targetFile);
+ }
+ }
+
+ public static void weekCopy(File file1, File file2) {
+ try (FileInputStream fileIn = new FileInputStream(file1);
+ FileOutputStream fileOut = new FileOutputStream(file2);
+ FileChannel channelIn = fileIn.getChannel();
+ FileChannel channelOut = fileOut.getChannel()) {
+ channelIn.transferTo(0, channelIn.size(), channelOut);
+ } catch (IOException t) {
+ t.printStackTrace();
+ }
+ }
+
+ public static String readFromURL(String url, String def) {
+ String s = readFromURL(url, 1024);
+ return s == null ? def : s;
+ }
+
+ public static String readFromURL(String url, int size) {
+ URLConnection conn = null;
+ BufferedInputStream bin = null;
+ try {
+ conn = new URL(url).openConnection();
+ bin = new BufferedInputStream(conn.getInputStream());
+ return readFromStream(bin, size, conn.getContentEncoding() == null ? "UTF-8" : conn.getContentEncoding());
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ IO.close(conn);
+ IO.closeQuietly(bin);
+ }
+ return null;
+ }
+
+ public static String readFromFile(File file, int size, String encode) {
+ try (FileInputStream fin = new FileInputStream(file); BufferedInputStream bin = new BufferedInputStream(fin)) {
+ return readFromStream(fin, size, encode);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public static String readFromStream(InputStream in, int size, String encode) {
+ try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
+ byte[] b = new byte[size];
+ int i;
+ while ((i = in.read(b)) > 0) {
+ bos.write(b, 0, i);
+ }
+ return new String(bos.toByteArray(), encode);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public static String encodeYAML(FileConfiguration file) {
+ return Base64Coder.encodeLines(file.saveToString().getBytes()).replaceAll("\\s+", "");
+ }
+
+ public static FileConfiguration decodeYAML(String args) {
+ return YamlConfiguration.loadConfiguration(new StringReader(Base64Coder.decodeString(args)));
+ }
+
+ public static FileConfiguration load(File file) {
+ return loadYaml(file);
+ }
+
+ public static YamlConfiguration loadYaml( File file) {
+ YamlConfiguration configuration = new YamlConfiguration();
+ try {
+ String yaml = com.google.common.io.Files.toString(file, Charset.forName("utf-8"));
+ configuration.loadFromString(yaml);
+ return configuration;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return configuration;
+ }
+
+ private static Class getCaller(Class> obj) {
+ try {
+ return Class.forName(Thread.currentThread().getStackTrace()[3].getClassName(), false, obj.getClassLoader());
+ } catch (ClassNotFoundException ignored) {
+ }
+ return null;
+ }
+}
diff --git a/src/main/scala/me/skymc/taboolib/common/io/IOUtils.java b/src/main/scala/io/izzel/taboolib/util/IO.java
similarity index 74%
rename from src/main/scala/me/skymc/taboolib/common/io/IOUtils.java
rename to src/main/scala/io/izzel/taboolib/util/IO.java
index 49f3da8..4dcd9e9 100644
--- a/src/main/scala/me/skymc/taboolib/common/io/IOUtils.java
+++ b/src/main/scala/io/izzel/taboolib/util/IO.java
@@ -1,4 +1,4 @@
-package me.skymc.taboolib.common.io;
+package io.izzel.taboolib.util;
import java.io.*;
import java.net.HttpURLConnection;
@@ -6,12 +6,23 @@ import java.net.ServerSocket;
import java.net.Socket;
import java.net.URLConnection;
import java.nio.channels.Selector;
+import java.nio.charset.Charset;
-/**
- * from org.apache.commons.io
- * support for 1.14
- */
-public class IOUtils {
+public class IO {
+
+ public static String readFully(InputStream inputStream, Charset charset) throws IOException {
+ return new String(readFully(inputStream), charset);
+ }
+
+ public static byte[] readFully(InputStream inputStream) throws IOException {
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ byte[] buf = new byte[1024];
+ int len = 0;
+ while ((len = inputStream.read(buf)) > 0) {
+ stream.write(buf, 0, len);
+ }
+ return stream.toByteArray();
+ }
public static void close(URLConnection v) {
if (v instanceof HttpURLConnection) {
diff --git a/src/main/scala/com/ilummc/tlib/util/Ref.java b/src/main/scala/io/izzel/taboolib/util/Ref.java
similarity index 93%
rename from src/main/scala/com/ilummc/tlib/util/Ref.java
rename to src/main/scala/io/izzel/taboolib/util/Ref.java
index bd9c35b..8d05d90 100644
--- a/src/main/scala/com/ilummc/tlib/util/Ref.java
+++ b/src/main/scala/io/izzel/taboolib/util/Ref.java
@@ -1,9 +1,8 @@
-package com.ilummc.tlib.util;
+package io.izzel.taboolib.util;
import com.google.gson.annotations.SerializedName;
-import com.ilummc.tlib.TLib;
-import com.ilummc.tlib.util.asm.AsmAnalyser;
-import me.skymc.taboolib.Main;
+import io.izzel.taboolib.TabooLib;
+import io.izzel.taboolib.util.asm.AsmAnalyser;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.objectweb.asm.ClassReader;
@@ -38,12 +37,6 @@ public class Ref {
public static List getDeclaredFields(Class> clazz, int excludeModifiers, boolean cache) {
try {
-
- // 特殊判断
- if (clazz == TLib.class) {
- return Arrays.asList(clazz.getDeclaredFields());
- }
-
List fields;
if ((fields = cachedFields.get(clazz.getName())) != null) {
return fields;
@@ -100,6 +93,9 @@ public class Ref {
}
public static Plugin getCallerPlugin(Class> callerClass) {
+ if (callerClass.getName().startsWith("io.izzel.taboolib") || callerClass.getName().startsWith("io.izzel.tlibscala")) {
+ return TabooLib.getPlugin();
+ }
try {
return JavaPlugin.getProvidingPlugin(callerClass);
} catch (Exception ignored) {
@@ -110,7 +106,7 @@ public class Ref {
Object o = pluginF.get(loader);
return (JavaPlugin) o;
} catch (Exception e) {
- return Main.getInst();
+ return TabooLib.getPlugin();
}
}
}
diff --git a/src/main/scala/me/skymc/taboolib/methods/ReflectionUtils.java b/src/main/scala/io/izzel/taboolib/util/Reflection.java
similarity index 99%
rename from src/main/scala/me/skymc/taboolib/methods/ReflectionUtils.java
rename to src/main/scala/io/izzel/taboolib/util/Reflection.java
index eede188..5ee962f 100644
--- a/src/main/scala/me/skymc/taboolib/methods/ReflectionUtils.java
+++ b/src/main/scala/io/izzel/taboolib/util/Reflection.java
@@ -1,4 +1,4 @@
-package me.skymc.taboolib.methods;
+package io.izzel.taboolib.util;
import org.bukkit.Bukkit;
@@ -25,9 +25,9 @@ import java.util.Map;
* @author DarkBlade12
* @version 1.1
*/
-public final class ReflectionUtils {
+public final class Reflection {
// Prevent accidental construction
- private ReflectionUtils() {
+ private Reflection() {
}
/**
diff --git a/src/main/scala/me/skymc/taboolib/string/StringUtils.java b/src/main/scala/io/izzel/taboolib/util/Strings.java
similarity index 67%
rename from src/main/scala/me/skymc/taboolib/string/StringUtils.java
rename to src/main/scala/io/izzel/taboolib/util/Strings.java
index 20a24d5..8530124 100644
--- a/src/main/scala/me/skymc/taboolib/string/StringUtils.java
+++ b/src/main/scala/io/izzel/taboolib/util/Strings.java
@@ -1,15 +1,51 @@
-package me.skymc.taboolib.string;
+package io.izzel.taboolib.util;
+
+import com.google.common.collect.Lists;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
-/**
- * @author sky
- * @since 2018年2月6日 下午1:28:38
- */
-public class StringUtils {
-
- public static String hashKeyForDisk(String key) {
+public class Strings {
+
+ public static boolean isBlank(String var) {
+ return var == null || var.trim().isEmpty();
+ }
+
+ public static boolean isEmpty(CharSequence var) {
+ return var == null || var.length() == 0;
+ }
+
+ public static String replaceWithOrder(String template, String... args) {
+ return replaceWithOrder(template, Lists.newArrayList(args).toArray());
+ }
+
+ /**
+ * 优化过的 String#replace,比默认快了大概 5 倍
+ *
+ * @param template 模板替换文件
+ * @param args 替换的参数
+ * @return 替换好的字符串
+ */
+ public static String replaceWithOrder(String template, Object... args) {
+ if (args.length == 0 || template.length() == 0) {
+ return template;
+ }
+ char[] arr = template.toCharArray();
+ StringBuilder stringBuilder = new StringBuilder(template.length());
+ for (int i = 0; i < arr.length; i++) {
+ if (arr[i] == '{' && Character.isDigit(arr[Math.min(i + 1, arr.length - 1)])
+ && arr[Math.min(i + 1, arr.length - 1)] - '0' < args.length
+ && arr[Math.min(i + 2, arr.length - 1)] == '}') {
+ stringBuilder.append(args[arr[i + 1] - '0']);
+ i += 2;
+ } else {
+ stringBuilder.append(arr[i]);
+ }
+ }
+ return stringBuilder.toString();
+ }
+
+ public static String hashKeyForDisk(String key) {
String cacheKey;
try {
final MessageDigest mDigest = MessageDigest.getInstance("MD5");
@@ -21,18 +57,6 @@ public class StringUtils {
return cacheKey;
}
- private static String bytesToHexString(byte[] bytes) {
- StringBuilder sb = new StringBuilder();
- for (byte aByte : bytes) {
- String hex = Integer.toHexString(0xFF & aByte);
- if (hex.length() == 1) {
- sb.append('0');
- }
- sb.append(hex);
- }
- return sb.toString();
- }
-
public static double similarDegree(String strA, String strB){
String newStrA = removeSign(max(strA, strB));
String newStrB = removeSign(min(strA, strB));
@@ -45,6 +69,18 @@ public class StringUtils {
}
}
+ private static String bytesToHexString(byte[] bytes) {
+ StringBuilder sb = new StringBuilder();
+ for (byte aByte : bytes) {
+ String hex = Integer.toHexString(0xFF & aByte);
+ if (hex.length() == 1) {
+ sb.append('0');
+ }
+ sb.append(hex);
+ }
+ return sb.toString();
+ }
+
private static String max(String strA, String strB) {
return strA.length() >= strB.length() ? strA : strB;
}
@@ -100,5 +136,4 @@ public class StringUtils {
}
return new String(result);
}
-
}
diff --git a/src/main/scala/me/skymc/taboolib/timeutil/TimeFormatter.java b/src/main/scala/io/izzel/taboolib/util/Times.java
similarity index 93%
rename from src/main/scala/me/skymc/taboolib/timeutil/TimeFormatter.java
rename to src/main/scala/io/izzel/taboolib/util/Times.java
index edb73d3..d4a184f 100644
--- a/src/main/scala/me/skymc/taboolib/timeutil/TimeFormatter.java
+++ b/src/main/scala/io/izzel/taboolib/util/Times.java
@@ -1,4 +1,4 @@
-package me.skymc.taboolib.timeutil;
+package io.izzel.taboolib.util;
import java.util.concurrent.TimeUnit;
@@ -6,7 +6,7 @@ import java.util.concurrent.TimeUnit;
* @author sky
* @since 2018-04-10 22:11:04
*/
-public class TimeFormatter {
+public class Times {
private long days;
private long hours;
@@ -14,7 +14,7 @@ public class TimeFormatter {
private long seconds;
private long milliseconds;
- public TimeFormatter(long millisecond) {
+ public Times(long millisecond) {
days = TimeUnit.MILLISECONDS.toDays(millisecond);
hours = TimeUnit.MILLISECONDS.toHours(millisecond) - days * 24L;
minutes = TimeUnit.MILLISECONDS.toMinutes(millisecond) - TimeUnit.MILLISECONDS.toHours(millisecond) * 60L;
diff --git a/src/main/scala/me/skymc/taboolib/string/VariableFormatter.java b/src/main/scala/io/izzel/taboolib/util/Variables.java
similarity index 88%
rename from src/main/scala/me/skymc/taboolib/string/VariableFormatter.java
rename to src/main/scala/io/izzel/taboolib/util/Variables.java
index 84567e0..7ee842c 100644
--- a/src/main/scala/me/skymc/taboolib/string/VariableFormatter.java
+++ b/src/main/scala/io/izzel/taboolib/util/Variables.java
@@ -1,6 +1,4 @@
-package me.skymc.taboolib.string;
-
-import com.ilummc.tlib.util.Strings;
+package io.izzel.taboolib.util;
import java.util.ArrayList;
import java.util.List;
@@ -11,34 +9,34 @@ import java.util.regex.Pattern;
* @Author sky
* @Since 2018-05-27 11:33
*/
-public class VariableFormatter {
+public class Variables {
private Pattern pattern;
private String text;
private String textOrigin;
private List variableList = new ArrayList<>();
- public VariableFormatter(String text) {
+ public Variables(String text) {
this(text, "<([^<>]+)>");
}
- public VariableFormatter(String text, String regex) {
+ public Variables(String text, String regex) {
this(text, Pattern.compile(regex));
}
- public VariableFormatter(String text, Pattern pattern) {
+ public Variables(String text, Pattern pattern) {
this.text = text;
this.textOrigin = text;
this.pattern = pattern;
}
- public VariableFormatter reset() {
+ public Variables reset() {
text = textOrigin;
variableList.clear();
return this;
}
- public VariableFormatter find() {
+ public Variables find() {
reset();
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
diff --git a/src/main/scala/com/ilummc/tlib/util/asm/AsmAnalyser.java b/src/main/scala/io/izzel/taboolib/util/asm/AsmAnalyser.java
similarity index 96%
rename from src/main/scala/com/ilummc/tlib/util/asm/AsmAnalyser.java
rename to src/main/scala/io/izzel/taboolib/util/asm/AsmAnalyser.java
index 58ce0d5..e1a81e2 100644
--- a/src/main/scala/com/ilummc/tlib/util/asm/AsmAnalyser.java
+++ b/src/main/scala/io/izzel/taboolib/util/asm/AsmAnalyser.java
@@ -1,4 +1,4 @@
-package com.ilummc.tlib.util.asm;
+package io.izzel.taboolib.util.asm;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.FieldVisitor;
diff --git a/src/main/scala/com/ilummc/tlib/util/asm/AsmClassLoader.java b/src/main/scala/io/izzel/taboolib/util/asm/AsmClassLoader.java
similarity index 93%
rename from src/main/scala/com/ilummc/tlib/util/asm/AsmClassLoader.java
rename to src/main/scala/io/izzel/taboolib/util/asm/AsmClassLoader.java
index e65beeb..72ea750 100644
--- a/src/main/scala/com/ilummc/tlib/util/asm/AsmClassLoader.java
+++ b/src/main/scala/io/izzel/taboolib/util/asm/AsmClassLoader.java
@@ -1,4 +1,4 @@
-package com.ilummc.tlib.util.asm;
+package io.izzel.taboolib.util.asm;
public class AsmClassLoader extends ClassLoader {
diff --git a/src/main/scala/com/ilummc/tlib/util/asm/AsmClassTransformer.java b/src/main/scala/io/izzel/taboolib/util/asm/AsmClassTransformer.java
similarity index 99%
rename from src/main/scala/com/ilummc/tlib/util/asm/AsmClassTransformer.java
rename to src/main/scala/io/izzel/taboolib/util/asm/AsmClassTransformer.java
index 7819a46..a4048d0 100644
--- a/src/main/scala/com/ilummc/tlib/util/asm/AsmClassTransformer.java
+++ b/src/main/scala/io/izzel/taboolib/util/asm/AsmClassTransformer.java
@@ -1,4 +1,4 @@
-package com.ilummc.tlib.util.asm;
+package io.izzel.taboolib.util.asm;
import org.bukkit.Bukkit;
diff --git a/src/main/scala/me/skymc/taboolib/bookformatter/BookAchievement.java b/src/main/scala/io/izzel/taboolib/util/book/BookAchievement.java
similarity index 98%
rename from src/main/scala/me/skymc/taboolib/bookformatter/BookAchievement.java
rename to src/main/scala/io/izzel/taboolib/util/book/BookAchievement.java
index c6fb671..352aee0 100644
--- a/src/main/scala/me/skymc/taboolib/bookformatter/BookAchievement.java
+++ b/src/main/scala/io/izzel/taboolib/util/book/BookAchievement.java
@@ -1,4 +1,4 @@
-package me.skymc.taboolib.bookformatter;
+package io.izzel.taboolib.util.book;
import org.bukkit.Achievement;
diff --git a/src/main/scala/me/skymc/taboolib/bookformatter/BookFormatter.java b/src/main/scala/io/izzel/taboolib/util/book/BookFormatter.java
similarity index 52%
rename from src/main/scala/me/skymc/taboolib/bookformatter/BookFormatter.java
rename to src/main/scala/io/izzel/taboolib/util/book/BookFormatter.java
index 0931219..37cf2c4 100644
--- a/src/main/scala/me/skymc/taboolib/bookformatter/BookFormatter.java
+++ b/src/main/scala/io/izzel/taboolib/util/book/BookFormatter.java
@@ -1,8 +1,6 @@
-package me.skymc.taboolib.bookformatter;
+package io.izzel.taboolib.util.book;
-import me.skymc.taboolib.bookformatter.builder.BookBuilder;
-import me.skymc.taboolib.events.CustomBookOpenEvent;
-import org.bukkit.Bukkit;
+import io.izzel.taboolib.util.book.builder.BookBuilder;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@@ -15,33 +13,6 @@ public final class BookFormatter {
* @param p the player
* @param book the book to be opened
*/
- public static void openPlayer(Player p, ItemStack book) {
- CustomBookOpenEvent event = new CustomBookOpenEvent(p, book, false);
- //Call the CustomBookOpenEvent
- Bukkit.getPluginManager().callEvent(event);
- //Check if it's cancelled
- if(event.isCancelled()) {
- return;
- }
-
- //Close inventory currently
- p.closeInventory();
- //Store the previous item
- ItemStack hand = p.getItemInHand();
- p.setItemInHand(event.getBook());
-
- //Opening the GUI
- BookReflection.openBook(p, event.getBook(), event.getHand() == CustomBookOpenEvent.Hand.OFF_HAND);
-
- //Returning whatever was on hand.
- p.setItemInHand(hand);
- }
-
- /**
- * Opens a book GUI to the player, Bypass the {@link CustomBookOpenEvent}
- * @param p the player
- * @param book the book to be opened
- */
public static void forceOpen(Player p, ItemStack book) {
//Close inventory currently
p.closeInventory();
diff --git a/src/main/scala/me/skymc/taboolib/bookformatter/BookReflection.java b/src/main/scala/io/izzel/taboolib/util/book/BookReflection.java
similarity index 97%
rename from src/main/scala/me/skymc/taboolib/bookformatter/BookReflection.java
rename to src/main/scala/io/izzel/taboolib/util/book/BookReflection.java
index b090544..d3ed8a6 100644
--- a/src/main/scala/me/skymc/taboolib/bookformatter/BookReflection.java
+++ b/src/main/scala/io/izzel/taboolib/util/book/BookReflection.java
@@ -1,10 +1,9 @@
-package me.skymc.taboolib.bookformatter;
+package io.izzel.taboolib.util.book;
-import com.ilummc.tlib.bungee.api.chat.BaseComponent;
-import com.ilummc.tlib.bungee.api.chat.TextComponent;
-import com.ilummc.tlib.bungee.chat.ComponentSerializer;
-import com.ilummc.tlib.logger.TLogger;
-import com.ilummc.tlib.resources.TLocale;
+import io.izzel.taboolib.util.chat.BaseComponent;
+import io.izzel.taboolib.util.chat.TextComponent;
+import io.izzel.taboolib.util.chat.ComponentSerializer;
+import io.izzel.taboolib.module.locale.logger.TLogger;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@@ -14,7 +13,6 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
diff --git a/src/main/scala/me/skymc/taboolib/bookformatter/action/ClickAction.java b/src/main/scala/io/izzel/taboolib/util/book/action/ClickAction.java
similarity index 96%
rename from src/main/scala/me/skymc/taboolib/bookformatter/action/ClickAction.java
rename to src/main/scala/io/izzel/taboolib/util/book/action/ClickAction.java
index 428c447..ec68a81 100644
--- a/src/main/scala/me/skymc/taboolib/bookformatter/action/ClickAction.java
+++ b/src/main/scala/io/izzel/taboolib/util/book/action/ClickAction.java
@@ -1,6 +1,6 @@
-package me.skymc.taboolib.bookformatter.action;
+package io.izzel.taboolib.util.book.action;
-import com.ilummc.tlib.bungee.api.chat.ClickEvent;
+import io.izzel.taboolib.util.chat.ClickEvent;
/**
* @author sky
diff --git a/src/main/scala/me/skymc/taboolib/bookformatter/action/HoverAction.java b/src/main/scala/io/izzel/taboolib/util/book/action/HoverAction.java
similarity index 93%
rename from src/main/scala/me/skymc/taboolib/bookformatter/action/HoverAction.java
rename to src/main/scala/io/izzel/taboolib/util/book/action/HoverAction.java
index 48bad9f..3f8c53a 100644
--- a/src/main/scala/me/skymc/taboolib/bookformatter/action/HoverAction.java
+++ b/src/main/scala/io/izzel/taboolib/util/book/action/HoverAction.java
@@ -1,10 +1,10 @@
-package me.skymc.taboolib.bookformatter.action;
+package io.izzel.taboolib.util.book.action;
-import com.ilummc.tlib.bungee.api.chat.BaseComponent;
-import com.ilummc.tlib.bungee.api.chat.HoverEvent;
-import com.ilummc.tlib.bungee.api.chat.TextComponent;
-import me.skymc.taboolib.bookformatter.BookAchievement;
-import me.skymc.taboolib.bookformatter.BookReflection;
+import io.izzel.taboolib.util.chat.BaseComponent;
+import io.izzel.taboolib.util.chat.HoverEvent;
+import io.izzel.taboolib.util.chat.TextComponent;
+import io.izzel.taboolib.util.book.BookAchievement;
+import io.izzel.taboolib.util.book.BookReflection;
import org.bukkit.Achievement;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack;
@@ -55,7 +55,7 @@ public interface HoverAction {
* @return a new HoverAction instance
*/
static HoverAction showItem(ItemStack item) {
- return new SimpleHoverAction(HoverEvent.Action.SHOW_ITEM, BookReflection.itemToComponents(item));
+ return new SimpleHoverAction(HoverEvent.Action.SHOW_ITEM, io.izzel.taboolib.util.book.BookReflection.itemToComponents(item));
}
/**
diff --git a/src/main/scala/me/skymc/taboolib/bookformatter/builder/BookBuilder.java b/src/main/scala/io/izzel/taboolib/util/book/builder/BookBuilder.java
similarity index 91%
rename from src/main/scala/me/skymc/taboolib/bookformatter/builder/BookBuilder.java
rename to src/main/scala/io/izzel/taboolib/util/book/builder/BookBuilder.java
index d79d6f5..239d2f6 100644
--- a/src/main/scala/me/skymc/taboolib/bookformatter/builder/BookBuilder.java
+++ b/src/main/scala/io/izzel/taboolib/util/book/builder/BookBuilder.java
@@ -1,7 +1,7 @@
-package me.skymc.taboolib.bookformatter.builder;
+package io.izzel.taboolib.util.book.builder;
-import com.ilummc.tlib.bungee.api.chat.BaseComponent;
-import me.skymc.taboolib.bookformatter.BookReflection;
+import io.izzel.taboolib.util.chat.BaseComponent;
+import io.izzel.taboolib.util.book.BookReflection;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BookMeta;
@@ -93,7 +93,7 @@ public class BookBuilder {
* @return the BookBuilder's calling instance
*/
public BookBuilder pages(BaseComponent[]... pages) {
- BookReflection.setPages(meta, pages);
+ io.izzel.taboolib.util.book.BookReflection.setPages(meta, pages);
return this;
}
@@ -103,7 +103,7 @@ public class BookBuilder {
* @return the BookBuilder's calling instance
*/
public BookBuilder pages(List pages) {
- BookReflection.setPages(meta, pages.toArray(new BaseComponent[0][]));
+ io.izzel.taboolib.util.book.BookReflection.setPages(meta, pages.toArray(new BaseComponent[0][]));
return this;
}
diff --git a/src/main/scala/me/skymc/taboolib/bookformatter/builder/PageBuilder.java b/src/main/scala/io/izzel/taboolib/util/book/builder/PageBuilder.java
similarity index 82%
rename from src/main/scala/me/skymc/taboolib/bookformatter/builder/PageBuilder.java
rename to src/main/scala/io/izzel/taboolib/util/book/builder/PageBuilder.java
index f95e033..3675af2 100644
--- a/src/main/scala/me/skymc/taboolib/bookformatter/builder/PageBuilder.java
+++ b/src/main/scala/io/izzel/taboolib/util/book/builder/PageBuilder.java
@@ -1,12 +1,8 @@
-package me.skymc.taboolib.bookformatter.builder;
+package io.izzel.taboolib.util.book.builder;
-import com.ilummc.tlib.bungee.api.chat.*;
-import me.skymc.taboolib.string.ArrayUtils;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
+import io.izzel.taboolib.util.ArrayUtil;
+import io.izzel.taboolib.util.chat.BaseComponent;
+import io.izzel.taboolib.util.chat.TextComponent;
/**
* @author sky
@@ -22,7 +18,7 @@ public class PageBuilder {
* @return the PageBuilder's calling instance
*/
public PageBuilder add(String text) {
- Arrays.stream(TextComponent.fromLegacyText(text)).forEach(component -> this.text = ArrayUtils.arrayAppend(this.text, component));
+ java.util.Arrays.stream(TextComponent.fromLegacyText(text)).forEach(component -> this.text = ArrayUtil.arrayAppend(this.text, component));
return this;
}
@@ -32,7 +28,7 @@ public class PageBuilder {
* @return the PageBuilder's calling instance
*/
public PageBuilder add(BaseComponent component) {
- this.text = ArrayUtils.arrayAppend(this.text, component);
+ this.text = ArrayUtil.arrayAppend(this.text, component);
return this;
}
@@ -42,7 +38,7 @@ public class PageBuilder {
* @return the PageBuilder's calling instance
*/
public PageBuilder add(BaseComponent... components) {
- Arrays.stream(components).forEach(component -> this.text = ArrayUtils.arrayAppend(this.text, component));
+ java.util.Arrays.stream(components).forEach(component -> this.text = ArrayUtil.arrayAppend(this.text, component));
return this;
}
diff --git a/src/main/scala/me/skymc/taboolib/bookformatter/builder/TextBuilder.java b/src/main/scala/io/izzel/taboolib/util/book/builder/TextBuilder.java
similarity index 81%
rename from src/main/scala/me/skymc/taboolib/bookformatter/builder/TextBuilder.java
rename to src/main/scala/io/izzel/taboolib/util/book/builder/TextBuilder.java
index 34a271c..a587ac7 100644
--- a/src/main/scala/me/skymc/taboolib/bookformatter/builder/TextBuilder.java
+++ b/src/main/scala/io/izzel/taboolib/util/book/builder/TextBuilder.java
@@ -1,8 +1,11 @@
-package me.skymc.taboolib.bookformatter.builder;
+package io.izzel.taboolib.util.book.builder;
-import com.ilummc.tlib.bungee.api.chat.*;
-import me.skymc.taboolib.bookformatter.action.ClickAction;
-import me.skymc.taboolib.bookformatter.action.HoverAction;
+import io.izzel.taboolib.util.chat.BaseComponent;
+import io.izzel.taboolib.util.chat.ClickEvent;
+import io.izzel.taboolib.util.chat.HoverEvent;
+import io.izzel.taboolib.util.chat.TextComponent;
+import io.izzel.taboolib.util.book.action.ClickAction;
+import io.izzel.taboolib.util.book.action.HoverAction;
/**
* @author sky
diff --git a/src/main/scala/com/ilummc/tlib/bungee/api/chat/BaseComponent.java b/src/main/scala/io/izzel/taboolib/util/chat/BaseComponent.java
similarity index 93%
rename from src/main/scala/com/ilummc/tlib/bungee/api/chat/BaseComponent.java
rename to src/main/scala/io/izzel/taboolib/util/chat/BaseComponent.java
index 493fc45..c16b044 100644
--- a/src/main/scala/com/ilummc/tlib/bungee/api/chat/BaseComponent.java
+++ b/src/main/scala/io/izzel/taboolib/util/chat/BaseComponent.java
@@ -1,7 +1,4 @@
-package com.ilummc.tlib.bungee.api.chat;
-
-import com.ilummc.tlib.bungee.api.ChatColor;
-import com.ilummc.tlib.bungee.api.chat.ComponentBuilder.FormatRetention;
+package io.izzel.taboolib.util.chat;
import java.util.ArrayList;
import java.util.List;
@@ -129,7 +126,7 @@ public abstract class BaseComponent {
}
BaseComponent(BaseComponent old) {
- copyFormatting(old, FormatRetention.ALL, true);
+ copyFormatting(old, ComponentBuilder.FormatRetention.ALL, true);
if (old.getExtra() != null) {
for (BaseComponent extra : old.getExtra()) {
@@ -145,7 +142,7 @@ public abstract class BaseComponent {
* @param component the component to copy from
*/
public void copyFormatting(BaseComponent component) {
- copyFormatting(component, FormatRetention.ALL, true);
+ copyFormatting(component, ComponentBuilder.FormatRetention.ALL, true);
}
/**
@@ -156,7 +153,7 @@ public abstract class BaseComponent {
* component
*/
public void copyFormatting(BaseComponent component, boolean replace) {
- copyFormatting(component, FormatRetention.ALL, replace);
+ copyFormatting(component, ComponentBuilder.FormatRetention.ALL, replace);
}
/**
@@ -167,8 +164,8 @@ public abstract class BaseComponent {
* @param replace if already set formatting should be replaced by the new
* component
*/
- public void copyFormatting(BaseComponent component, FormatRetention retention, boolean replace) {
- if (retention == FormatRetention.EVENTS || retention == FormatRetention.ALL) {
+ public void copyFormatting(BaseComponent component, ComponentBuilder.FormatRetention retention, boolean replace) {
+ if (retention == ComponentBuilder.FormatRetention.EVENTS || retention == ComponentBuilder.FormatRetention.ALL) {
if (replace || clickEvent == null) {
setClickEvent(component.getClickEvent());
}
@@ -176,7 +173,7 @@ public abstract class BaseComponent {
setHoverEvent(component.getHoverEvent());
}
}
- if (retention == FormatRetention.FORMATTING || retention == FormatRetention.ALL) {
+ if (retention == ComponentBuilder.FormatRetention.FORMATTING || retention == ComponentBuilder.FormatRetention.ALL) {
if (replace || color == null) {
setColor(component.getColorRaw());
}
@@ -206,12 +203,12 @@ public abstract class BaseComponent {
*
* @param retention the formatting to retain
*/
- public void retain(FormatRetention retention) {
- if (retention == FormatRetention.FORMATTING || retention == FormatRetention.NONE) {
+ public void retain(ComponentBuilder.FormatRetention retention) {
+ if (retention == ComponentBuilder.FormatRetention.FORMATTING || retention == ComponentBuilder.FormatRetention.NONE) {
setClickEvent(null);
setHoverEvent(null);
}
- if (retention == FormatRetention.EVENTS || retention == FormatRetention.NONE) {
+ if (retention == ComponentBuilder.FormatRetention.EVENTS || retention == ComponentBuilder.FormatRetention.NONE) {
setColor(null);
setBold(null);
setItalic(null);
@@ -238,7 +235,7 @@ public abstract class BaseComponent {
@Deprecated
public BaseComponent duplicateWithoutFormatting() {
BaseComponent component = duplicate();
- component.retain(FormatRetention.NONE);
+ component.retain(ComponentBuilder.FormatRetention.NONE);
return component;
}
diff --git a/src/main/scala/com/ilummc/tlib/bungee/chat/BaseComponentSerializer.java b/src/main/scala/io/izzel/taboolib/util/chat/BaseComponentSerializer.java
similarity index 95%
rename from src/main/scala/com/ilummc/tlib/bungee/chat/BaseComponentSerializer.java
rename to src/main/scala/io/izzel/taboolib/util/chat/BaseComponentSerializer.java
index e01e51a..a7be0db 100644
--- a/src/main/scala/com/ilummc/tlib/bungee/chat/BaseComponentSerializer.java
+++ b/src/main/scala/io/izzel/taboolib/util/chat/BaseComponentSerializer.java
@@ -1,13 +1,9 @@
-package com.ilummc.tlib.bungee.chat;
+package io.izzel.taboolib.util.chat;
import com.google.common.base.Preconditions;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
-import com.ilummc.tlib.bungee.api.ChatColor;
-import com.ilummc.tlib.bungee.api.chat.BaseComponent;
-import com.ilummc.tlib.bungee.api.chat.ClickEvent;
-import com.ilummc.tlib.bungee.api.chat.HoverEvent;
import java.util.Arrays;
import java.util.HashSet;
diff --git a/src/main/scala/com/ilummc/tlib/bungee/api/ChatColor.java b/src/main/scala/io/izzel/taboolib/util/chat/ChatColor.java
similarity index 99%
rename from src/main/scala/com/ilummc/tlib/bungee/api/ChatColor.java
rename to src/main/scala/io/izzel/taboolib/util/chat/ChatColor.java
index 752b7be..1a895f4 100644
--- a/src/main/scala/com/ilummc/tlib/bungee/api/ChatColor.java
+++ b/src/main/scala/io/izzel/taboolib/util/chat/ChatColor.java
@@ -1,4 +1,4 @@
-package com.ilummc.tlib.bungee.api;
+package io.izzel.taboolib.util.chat;
import java.util.HashMap;
import java.util.Map;
diff --git a/src/main/scala/com/ilummc/tlib/bungee/api/ChatMessageType.java b/src/main/scala/io/izzel/taboolib/util/chat/ChatMessageType.java
similarity index 81%
rename from src/main/scala/com/ilummc/tlib/bungee/api/ChatMessageType.java
rename to src/main/scala/io/izzel/taboolib/util/chat/ChatMessageType.java
index 788cf5e..4429e41 100644
--- a/src/main/scala/com/ilummc/tlib/bungee/api/ChatMessageType.java
+++ b/src/main/scala/io/izzel/taboolib/util/chat/ChatMessageType.java
@@ -1,4 +1,4 @@
-package com.ilummc.tlib.bungee.api;
+package io.izzel.taboolib.util.chat;
/**
* Represents the position on the screen where a message will appear.
diff --git a/src/main/scala/com/ilummc/tlib/bungee/api/chat/ClickEvent.java b/src/main/scala/io/izzel/taboolib/util/chat/ClickEvent.java
similarity index 96%
rename from src/main/scala/com/ilummc/tlib/bungee/api/chat/ClickEvent.java
rename to src/main/scala/io/izzel/taboolib/util/chat/ClickEvent.java
index c7124e8..1a302b2 100644
--- a/src/main/scala/com/ilummc/tlib/bungee/api/chat/ClickEvent.java
+++ b/src/main/scala/io/izzel/taboolib/util/chat/ClickEvent.java
@@ -1,4 +1,4 @@
-package com.ilummc.tlib.bungee.api.chat;
+package io.izzel.taboolib.util.chat;
/**
* @author md_5
diff --git a/src/main/scala/com/ilummc/tlib/bungee/api/chat/ComponentBuilder.java b/src/main/scala/io/izzel/taboolib/util/chat/ComponentBuilder.java
similarity index 99%
rename from src/main/scala/com/ilummc/tlib/bungee/api/chat/ComponentBuilder.java
rename to src/main/scala/io/izzel/taboolib/util/chat/ComponentBuilder.java
index 1b0100f..b5bdf48 100644
--- a/src/main/scala/com/ilummc/tlib/bungee/api/chat/ComponentBuilder.java
+++ b/src/main/scala/io/izzel/taboolib/util/chat/ComponentBuilder.java
@@ -1,7 +1,6 @@
-package com.ilummc.tlib.bungee.api.chat;
+package io.izzel.taboolib.util.chat;
import com.google.common.base.Preconditions;
-import com.ilummc.tlib.bungee.api.ChatColor;
import java.util.ArrayList;
import java.util.List;
diff --git a/src/main/scala/com/ilummc/tlib/bungee/chat/ComponentSerializer.java b/src/main/scala/io/izzel/taboolib/util/chat/ComponentSerializer.java
similarity index 89%
rename from src/main/scala/com/ilummc/tlib/bungee/chat/ComponentSerializer.java
rename to src/main/scala/io/izzel/taboolib/util/chat/ComponentSerializer.java
index 6d19961..f91c0c0 100644
--- a/src/main/scala/com/ilummc/tlib/bungee/chat/ComponentSerializer.java
+++ b/src/main/scala/io/izzel/taboolib/util/chat/ComponentSerializer.java
@@ -1,12 +1,8 @@
-package com.ilummc.tlib.bungee.chat;
+package io.izzel.taboolib.util.chat;
import com.google.gson.*;
-import com.ilummc.tlib.bungee.api.chat.BaseComponent;
-import com.ilummc.tlib.bungee.api.chat.TextComponent;
-import com.ilummc.tlib.bungee.api.chat.TranslatableComponent;
import java.lang.reflect.Type;
-import java.util.Arrays;
import java.util.HashSet;
/**
diff --git a/src/main/scala/com/ilummc/tlib/bungee/api/chat/HoverEvent.java b/src/main/scala/io/izzel/taboolib/util/chat/HoverEvent.java
similarity index 94%
rename from src/main/scala/com/ilummc/tlib/bungee/api/chat/HoverEvent.java
rename to src/main/scala/io/izzel/taboolib/util/chat/HoverEvent.java
index 1825ce4..7313068 100644
--- a/src/main/scala/com/ilummc/tlib/bungee/api/chat/HoverEvent.java
+++ b/src/main/scala/io/izzel/taboolib/util/chat/HoverEvent.java
@@ -1,4 +1,4 @@
-package com.ilummc.tlib.bungee.api.chat;
+package io.izzel.taboolib.util.chat;
import java.util.Arrays;
diff --git a/src/main/scala/com/ilummc/tlib/bungee/api/chat/TextComponent.java b/src/main/scala/io/izzel/taboolib/util/chat/TextComponent.java
similarity index 98%
rename from src/main/scala/com/ilummc/tlib/bungee/api/chat/TextComponent.java
rename to src/main/scala/io/izzel/taboolib/util/chat/TextComponent.java
index 28d935c..6c7652f 100644
--- a/src/main/scala/com/ilummc/tlib/bungee/api/chat/TextComponent.java
+++ b/src/main/scala/io/izzel/taboolib/util/chat/TextComponent.java
@@ -3,9 +3,7 @@
// (powered by Fernflower decompiler)
//
-package com.ilummc.tlib.bungee.api.chat;
-
-import com.ilummc.tlib.bungee.api.ChatColor;
+package io.izzel.taboolib.util.chat;
import java.beans.ConstructorProperties;
import java.util.ArrayList;
diff --git a/src/main/scala/com/ilummc/tlib/bungee/chat/TextComponentSerializer.java b/src/main/scala/io/izzel/taboolib/util/chat/TextComponentSerializer.java
similarity index 89%
rename from src/main/scala/com/ilummc/tlib/bungee/chat/TextComponentSerializer.java
rename to src/main/scala/io/izzel/taboolib/util/chat/TextComponentSerializer.java
index 9fccef9..4f6dee7 100644
--- a/src/main/scala/com/ilummc/tlib/bungee/chat/TextComponentSerializer.java
+++ b/src/main/scala/io/izzel/taboolib/util/chat/TextComponentSerializer.java
@@ -3,11 +3,9 @@
// (powered by Fernflower decompiler)
//
-package com.ilummc.tlib.bungee.chat;
+package io.izzel.taboolib.util.chat;
import com.google.gson.*;
-import com.ilummc.tlib.bungee.api.chat.BaseComponent;
-import com.ilummc.tlib.bungee.api.chat.TextComponent;
import java.lang.reflect.Type;
import java.util.List;
diff --git a/src/main/scala/com/ilummc/tlib/bungee/api/chat/TranslatableComponent.java b/src/main/scala/io/izzel/taboolib/util/chat/TranslatableComponent.java
similarity index 98%
rename from src/main/scala/com/ilummc/tlib/bungee/api/chat/TranslatableComponent.java
rename to src/main/scala/io/izzel/taboolib/util/chat/TranslatableComponent.java
index 23e3864..1683af6 100644
--- a/src/main/scala/com/ilummc/tlib/bungee/api/chat/TranslatableComponent.java
+++ b/src/main/scala/io/izzel/taboolib/util/chat/TranslatableComponent.java
@@ -1,6 +1,4 @@
-package com.ilummc.tlib.bungee.api.chat;
-
-import com.ilummc.tlib.bungee.api.ChatColor;
+package io.izzel.taboolib.util.chat;
import java.util.ArrayList;
import java.util.List;
diff --git a/src/main/scala/com/ilummc/tlib/bungee/chat/TranslatableComponentSerializer.java b/src/main/scala/io/izzel/taboolib/util/chat/TranslatableComponentSerializer.java
similarity index 90%
rename from src/main/scala/com/ilummc/tlib/bungee/chat/TranslatableComponentSerializer.java
rename to src/main/scala/io/izzel/taboolib/util/chat/TranslatableComponentSerializer.java
index e2be31f..dfbd165 100644
--- a/src/main/scala/com/ilummc/tlib/bungee/chat/TranslatableComponentSerializer.java
+++ b/src/main/scala/io/izzel/taboolib/util/chat/TranslatableComponentSerializer.java
@@ -3,11 +3,9 @@
// (powered by Fernflower decompiler)
//
-package com.ilummc.tlib.bungee.chat;
+package io.izzel.taboolib.util.chat;
import com.google.gson.*;
-import com.ilummc.tlib.bungee.api.chat.BaseComponent;
-import com.ilummc.tlib.bungee.api.chat.TranslatableComponent;
import java.lang.reflect.Type;
import java.util.Arrays;
diff --git a/src/main/scala/me/skymc/taboolib/inventory/builder/ItemBuilder.java b/src/main/scala/io/izzel/taboolib/util/item/ItemBuilder.java
similarity index 88%
rename from src/main/scala/me/skymc/taboolib/inventory/builder/ItemBuilder.java
rename to src/main/scala/io/izzel/taboolib/util/item/ItemBuilder.java
index b418223..6de7988 100644
--- a/src/main/scala/me/skymc/taboolib/inventory/builder/ItemBuilder.java
+++ b/src/main/scala/io/izzel/taboolib/util/item/ItemBuilder.java
@@ -1,9 +1,8 @@
-package me.skymc.taboolib.inventory.builder;
+package io.izzel.taboolib.util.item;
-import com.ilummc.tlib.resources.TLocale;
-import me.skymc.taboolib.TabooLib;
-import me.skymc.taboolib.string.ArrayUtils;
-import org.bukkit.Bukkit;
+import io.izzel.taboolib.Version;
+import io.izzel.taboolib.module.locale.TLocale;
+import io.izzel.taboolib.util.ArrayUtil;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
@@ -16,7 +15,6 @@ import org.bukkit.inventory.meta.*;
import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionEffect;
-import java.util.Arrays;
import java.util.List;
/**
@@ -88,7 +86,7 @@ public class ItemBuilder {
}
public ItemBuilder lore(String... lore) {
- itemMeta.setLore(ArrayUtils.asList(lore));
+ itemMeta.setLore(ArrayUtil.asList(lore));
return this;
}
@@ -119,7 +117,7 @@ public class ItemBuilder {
public ItemBuilder banner(Pattern... patterns) {
if (itemMeta instanceof BannerMeta) {
- Arrays.stream(patterns).forEach(pattern -> ((BannerMeta) itemMeta).addPattern(pattern));
+ java.util.Arrays.stream(patterns).forEach(pattern -> ((BannerMeta) itemMeta).addPattern(pattern));
}
return this;
}
@@ -167,7 +165,7 @@ public class ItemBuilder {
}
public ItemBuilder unbreakable(boolean value) {
- if (TabooLib.getVersionNumber() >= 12000) {
+ if (Version.isAfter(Version.v1_12)) {
itemMeta.setUnbreakable(value);
} else {
itemMeta.spigot().setUnbreakable(value);
@@ -192,14 +190,4 @@ public class ItemBuilder {
}
return buildItem;
}
-
- /**
- * 从文本中获取物品(name:名字;lore:描述||描述;material:材质)
- *
- * @param str
- * @return
- */
- public static ItemStack fromString(String str) {
- return null;
- }
}
diff --git a/src/main/scala/io/izzel/taboolib/util/item/Items.java b/src/main/scala/io/izzel/taboolib/util/item/Items.java
new file mode 100644
index 0000000..1a3a444
--- /dev/null
+++ b/src/main/scala/io/izzel/taboolib/util/item/Items.java
@@ -0,0 +1,286 @@
+package io.izzel.taboolib.util.item;
+
+import io.izzel.taboolib.Version;
+import io.izzel.taboolib.module.locale.TLocale;
+import io.izzel.taboolib.module.lite.SimpleI18n;
+import io.izzel.taboolib.module.nms.NMS;
+import io.izzel.taboolib.module.nms.nbt.NBTBase;
+import io.izzel.taboolib.module.nms.nbt.NBTCompound;
+import io.izzel.taboolib.module.nms.nbt.NBTList;
+import io.izzel.taboolib.util.lite.Numbers;
+import org.bukkit.Color;
+import org.bukkit.Material;
+import org.bukkit.configuration.ConfigurationSection;
+import org.bukkit.enchantments.Enchantment;
+import org.bukkit.entity.Player;
+import org.bukkit.inventory.Inventory;
+import org.bukkit.inventory.ItemFlag;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.ItemMeta;
+import org.bukkit.inventory.meta.LeatherArmorMeta;
+import org.bukkit.inventory.meta.PotionMeta;
+import org.bukkit.potion.PotionEffect;
+import org.bukkit.potion.PotionEffectType;
+import org.bukkit.util.NumberConversions;
+
+import java.util.List;
+
+/**
+ * @Author 坏黑
+ * @Since 2019-07-05 16:44
+ */
+public class Items {
+
+ public final static Integer[] INVENTORY_CENTER = {
+ 10, 11, 12, 13, 14, 15, 16,
+ 19, 20, 21, 22, 23, 24, 25,
+ 28, 29, 30, 31, 32, 33, 34,
+ 37, 38, 39, 40, 41, 42, 43
+ };
+
+ public static String getName(ItemStack item) {
+ return SimpleI18n.getCustomName(item);
+ }
+
+ public static boolean isNull(ItemStack item) {
+ return item == null || item.getType().equals(Material.AIR);
+ }
+
+ public static boolean hasLore(ItemStack i, String a) {
+ return hasLore(i) && i.getItemMeta().getLore().toString().contains(a);
+ }
+
+ public static boolean hasLore(ItemStack i) {
+ return !isNull(i) && i.getItemMeta().hasLore();
+ }
+
+ public static boolean hasName(ItemStack i) {
+ return !isNull(i) && i.getItemMeta().hasDisplayName();
+ }
+
+ public static Material asMaterial(String args) {
+ try {
+ Material material = Material.getMaterial(args.toUpperCase());
+ return material != null ? material : Material.getMaterial(Integer.valueOf(args));
+ } catch (Exception e) {
+ return Material.STONE;
+ }
+ }
+
+ public static Enchantment asEnchantment(String enchant) {
+ try {
+ Enchantment enchantment = Enchantment.getByName(enchant);
+ return enchantment != null ? enchantment : Enchantment.getById(Integer.valueOf(enchant));
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ public static PotionEffectType asPotionEffectType(String potion) {
+ try {
+ PotionEffectType type = PotionEffectType.getByName(potion);
+ return type != null ? type : PotionEffectType.getById(Integer.valueOf(potion));
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ public static ItemFlag asItemFlag(String flag) {
+ try {
+ return ItemFlag.valueOf(flag);
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ public static Color asColor(String color) {
+ try {
+ return Color.fromBGR(Integer.valueOf(color.split("-")[0]), Integer.valueOf(color.split("-")[1]), Integer.valueOf(color.split("-")[2]));
+ } catch (Exception e) {
+ return Color.fromBGR(0, 0, 0);
+ }
+ }
+
+ public static String asAttribute(String name) {
+ switch (name.toLowerCase()) {
+ case "damage":
+ return "generic.attackDamage";
+ case "attackspeed":
+ return "generic.attackSpeed";
+ case "health":
+ return "generic.maxHealth";
+ case "speed":
+ return "generic.movementSpeed";
+ case "knockback":
+ return "generic.knockbackResistance";
+ case "armor":
+ return "generic.armor";
+ case "luck":
+ return "generic.luck";
+ default:
+ return null;
+ }
+ }
+
+ public static ItemStack replaceLore(ItemStack item, String loreOld, String loreNew) {
+ if (hasLore(item)) {
+ ItemMeta meta = item.getItemMeta();
+ List lore = meta.getLore();
+ for (int i = 0; i < lore.size(); i++) {
+ lore.set(i, lore.get(i).replace(loreOld, loreNew));
+ }
+ meta.setLore(lore);
+ item.setItemMeta(meta);
+ }
+ return item;
+ }
+
+ public static boolean checkItem(Player player, ItemStack item, int amount, boolean remove) {
+ return checkItem(player.getInventory(), item, amount, remove);
+ }
+
+ public static boolean checkItem(Inventory inventory, ItemStack item, int amount, boolean remove) {
+ int hasAmount = 0;
+ for (ItemStack _item : inventory) {
+ if (item.isSimilar(_item)) {
+ hasAmount += _item.getAmount();
+ }
+ }
+ if (hasAmount < amount) {
+ return false;
+ }
+ int requireAmount = amount;
+ for (int i = 0; i < inventory.getSize() && remove; i++) {
+ ItemStack _item = inventory.getItem(i);
+ if (_item != null && _item.isSimilar(item)) {
+ if (_item.getAmount() < requireAmount) {
+ inventory.setItem(i, null);
+ requireAmount -= _item.getAmount();
+ } else if (_item.getAmount() == requireAmount) {
+ inventory.setItem(i, null);
+ return true;
+ } else {
+ _item.setAmount(_item.getAmount() - requireAmount);
+ return true;
+ }
+ }
+ }
+ return true;
+ }
+
+ public static ItemStack loadItem(ConfigurationSection section) {
+ if (section.get("bukkit") instanceof ItemStack) {
+ return section.getItemStack("bukkit");
+ }
+ // 材质
+ ItemStack item = new ItemStack(asMaterial(section.getString("material")));
+ // 数量
+ item.setAmount(section.contains("amount") ? section.getInt("amount") : 1);
+ // 耐久
+ item.setDurability((short) section.getInt("data"));
+ // 元数据
+ ItemMeta meta = item.getItemMeta();
+ // 展示名
+ if (section.contains("name")) {
+ meta.setDisplayName(section.getString("name"));
+ }
+ // 描述
+ if (section.contains("lore")) {
+ meta.setLore(section.getStringList("lore"));
+ }
+ // 附魔
+ if (section.contains("enchant")) {
+ for (String preEnchant : section.getConfigurationSection("enchant").getKeys(false)) {
+ Enchantment enchant = asEnchantment(preEnchant);
+ if (enchant != null) {
+ meta.addEnchant(enchant, section.getInt("enchant." + preEnchant), true);
+ } else {
+ TLocale.Logger.error("ITEM-UTILS.FAIL-LOAD-ENCHANTS", preEnchant);
+ }
+ }
+ }
+ // 标签
+ if (section.contains("flags") && Version.isAfter(Version.v1_8)) {
+ for (String preFlag : section.getStringList("flags")) {
+ ItemFlag flag = asItemFlag(preFlag);
+ if (flag != null) {
+ meta.addItemFlags(flag);
+ } else {
+ TLocale.Logger.error("ITEM-UTILS.FAIL-LOAD-FLAG", preFlag);
+ }
+ }
+ }
+ // 皮革
+ if (meta instanceof LeatherArmorMeta && section.contains("color")) {
+ ((LeatherArmorMeta) meta).setColor(asColor(section.getString("color")));
+ }
+ // 药水
+ if (meta instanceof PotionMeta && section.contains("potions")) {
+ PotionMeta potionMeta = (PotionMeta) meta;
+ for (String prePotionName : section.getConfigurationSection("potions").getKeys(false)) {
+ PotionEffectType potionEffectType = asPotionEffectType(prePotionName);
+ if (potionEffectType != null) {
+ potionMeta.addCustomEffect(new PotionEffect(
+ potionEffectType,
+ NumberConversions.toInt(section.getString("potions." + prePotionName).split("-")[0]),
+ NumberConversions.toInt(section.getString("potions." + prePotionName).split("-")[1]) - 1), true);
+ } else {
+ TLocale.Logger.error("ITEM-UTILS.FAIL-LOAD-POTION", prePotionName);
+ }
+ }
+ }
+ // 元数据
+ item.setItemMeta(meta);
+ // 数据
+ NBTCompound nbt = NMS.handle().loadNBT(item);
+ // 物品标签
+ if (section.contains("nbt")) {
+ for (String name : section.getConfigurationSection("nbt").getKeys(false)) {
+ Object obj = section.get("nbt." + name);
+ if (obj instanceof String) {
+ nbt.put(name, new NBTBase(obj.toString()));
+ } else if (obj instanceof Double) {
+ nbt.put(name, new NBTBase(NumberConversions.toDouble(obj)));
+ } else if (obj instanceof Integer) {
+ nbt.put(name, new NBTBase(NumberConversions.toInt(obj)));
+ } else if (obj instanceof Long) {
+ nbt.put(name, new NBTBase(NumberConversions.toLong(obj)));
+ }
+ }
+ }
+ // 物品属性
+ if (section.contains("attributes")) {
+ NBTList attr = new NBTList();
+ for (String hand : section.getConfigurationSection("attributes").getKeys(false)) {
+ for (String name : section.getConfigurationSection("attributes." + hand).getKeys(false)) {
+ if (asAttribute(name) != null) {
+ try {
+ NBTCompound a = new NBTCompound();
+ String num = section.getString("attributes." + hand + "." + name);
+ if (num.endsWith("%")) {
+ a.put("Amount", new NBTBase(NumberConversions.toDouble(num.substring(0, num.length() - 1)) / 100D));
+ a.put("Operation", new NBTBase(1));
+ } else {
+ a.put("Amount", new NBTBase(NumberConversions.toDouble(num)));
+ a.put("Operation", new NBTBase(0));
+ }
+ a.put("AttributeName", new NBTBase(asAttribute(name)));
+ a.put("UUIDMost", new NBTBase(Numbers.getRandom().nextInt(Integer.MAX_VALUE)));
+ a.put("UUIDLeast", new NBTBase(Numbers.getRandom().nextInt(Integer.MAX_VALUE)));
+ a.put("Name", new NBTBase(asAttribute(name)));
+ if (!hand.equals("all")) {
+ a.put("Slot", new NBTBase(hand));
+ }
+ attr.add(a);
+ } catch (Exception ignored) {
+ }
+ } else {
+ TLocale.Logger.error("ITEM-UTILS.FAIL-LOAD-POTION", name);
+ }
+ }
+ }
+ nbt.put("AttributeModifiers", attr);
+ }
+ return NMS.handle().saveNBT(item, nbt);
+ }
+}
diff --git a/src/main/scala/me/skymc/taboolib/inventory/builder/v2/ClickEvent.java b/src/main/scala/io/izzel/taboolib/util/item/inventory/ClickEvent.java
similarity index 95%
rename from src/main/scala/me/skymc/taboolib/inventory/builder/v2/ClickEvent.java
rename to src/main/scala/io/izzel/taboolib/util/item/inventory/ClickEvent.java
index 913797f..6d50c32 100644
--- a/src/main/scala/me/skymc/taboolib/inventory/builder/v2/ClickEvent.java
+++ b/src/main/scala/io/izzel/taboolib/util/item/inventory/ClickEvent.java
@@ -1,4 +1,4 @@
-package me.skymc.taboolib.inventory.builder.v2;
+package io.izzel.taboolib.util.item.inventory;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
diff --git a/src/main/scala/me/skymc/taboolib/inventory/builder/v2/ClickListener.java b/src/main/scala/io/izzel/taboolib/util/item/inventory/ClickListener.java
similarity index 96%
rename from src/main/scala/me/skymc/taboolib/inventory/builder/v2/ClickListener.java
rename to src/main/scala/io/izzel/taboolib/util/item/inventory/ClickListener.java
index 5cbb4b7..3aab994 100644
--- a/src/main/scala/me/skymc/taboolib/inventory/builder/v2/ClickListener.java
+++ b/src/main/scala/io/izzel/taboolib/util/item/inventory/ClickListener.java
@@ -1,6 +1,6 @@
-package me.skymc.taboolib.inventory.builder.v2;
+package io.izzel.taboolib.util.item.inventory;
-import me.skymc.taboolib.listener.TListener;
+import io.izzel.taboolib.module.inject.TListener;
import org.bukkit.Bukkit;
import org.bukkit.entity.HumanEntity;
import org.bukkit.event.EventHandler;
diff --git a/src/main/scala/me/skymc/taboolib/inventory/builder/v2/ClickListener1_9.java b/src/main/scala/io/izzel/taboolib/util/item/inventory/ClickListenerOffhand.java
similarity index 78%
rename from src/main/scala/me/skymc/taboolib/inventory/builder/v2/ClickListener1_9.java
rename to src/main/scala/io/izzel/taboolib/util/item/inventory/ClickListenerOffhand.java
index 206f02e..4296c2e 100644
--- a/src/main/scala/me/skymc/taboolib/inventory/builder/v2/ClickListener1_9.java
+++ b/src/main/scala/io/izzel/taboolib/util/item/inventory/ClickListenerOffhand.java
@@ -1,6 +1,6 @@
-package me.skymc.taboolib.inventory.builder.v2;
+package io.izzel.taboolib.util.item.inventory;
-import me.skymc.taboolib.listener.TListener;
+import io.izzel.taboolib.module.inject.TListener;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerSwapHandItemsEvent;
@@ -10,7 +10,7 @@ import org.bukkit.event.player.PlayerSwapHandItemsEvent;
* @Since 2019-05-21 22:04
*/
@TListener(version = ">=10900")
-class ClickListener1_9 implements Listener {
+class ClickListenerOffhand implements Listener {
@EventHandler
public void onSwap(PlayerSwapHandItemsEvent e) {
diff --git a/src/main/scala/me/skymc/taboolib/inventory/builder/v2/ClickTask.java b/src/main/scala/io/izzel/taboolib/util/item/inventory/ClickTask.java
similarity index 71%
rename from src/main/scala/me/skymc/taboolib/inventory/builder/v2/ClickTask.java
rename to src/main/scala/io/izzel/taboolib/util/item/inventory/ClickTask.java
index fec7922..c474756 100644
--- a/src/main/scala/me/skymc/taboolib/inventory/builder/v2/ClickTask.java
+++ b/src/main/scala/io/izzel/taboolib/util/item/inventory/ClickTask.java
@@ -1,4 +1,4 @@
-package me.skymc.taboolib.inventory.builder.v2;
+package io.izzel.taboolib.util.item.inventory;
/**
* @Author 坏黑
diff --git a/src/main/scala/me/skymc/taboolib/inventory/builder/v2/ClickType.java b/src/main/scala/io/izzel/taboolib/util/item/inventory/ClickType.java
similarity index 67%
rename from src/main/scala/me/skymc/taboolib/inventory/builder/v2/ClickType.java
rename to src/main/scala/io/izzel/taboolib/util/item/inventory/ClickType.java
index 5af5852..cb16edc 100644
--- a/src/main/scala/me/skymc/taboolib/inventory/builder/v2/ClickType.java
+++ b/src/main/scala/io/izzel/taboolib/util/item/inventory/ClickType.java
@@ -1,4 +1,4 @@
-package me.skymc.taboolib.inventory.builder.v2;
+package io.izzel.taboolib.util.item.inventory;
/**
* @Author 坏黑
diff --git a/src/main/scala/me/skymc/taboolib/inventory/builder/v2/CloseTask.java b/src/main/scala/io/izzel/taboolib/util/item/inventory/CloseTask.java
similarity index 79%
rename from src/main/scala/me/skymc/taboolib/inventory/builder/v2/CloseTask.java
rename to src/main/scala/io/izzel/taboolib/util/item/inventory/CloseTask.java
index 3e672a8..587aedc 100644
--- a/src/main/scala/me/skymc/taboolib/inventory/builder/v2/CloseTask.java
+++ b/src/main/scala/io/izzel/taboolib/util/item/inventory/CloseTask.java
@@ -1,4 +1,4 @@
-package me.skymc.taboolib.inventory.builder.v2;
+package io.izzel.taboolib.util.item.inventory;
import org.bukkit.event.inventory.InventoryCloseEvent;
diff --git a/src/main/scala/me/skymc/taboolib/inventory/builder/v2/MenuBuilder.java b/src/main/scala/io/izzel/taboolib/util/item/inventory/MenuBuilder.java
similarity index 95%
rename from src/main/scala/me/skymc/taboolib/inventory/builder/v2/MenuBuilder.java
rename to src/main/scala/io/izzel/taboolib/util/item/inventory/MenuBuilder.java
index 835fa52..8921eee 100644
--- a/src/main/scala/me/skymc/taboolib/inventory/builder/v2/MenuBuilder.java
+++ b/src/main/scala/io/izzel/taboolib/util/item/inventory/MenuBuilder.java
@@ -1,8 +1,8 @@
-package me.skymc.taboolib.inventory.builder.v2;
+package io.izzel.taboolib.util.item.inventory;
import com.google.common.collect.Maps;
-import com.ilummc.tlib.util.Ref;
-import me.skymc.taboolib.Main;
+import io.izzel.taboolib.TabooLib;
+import io.izzel.taboolib.util.Ref;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.inventory.Inventory;
@@ -35,7 +35,7 @@ public class MenuBuilder {
}
public static MenuBuilder builder() {
- return new MenuBuilder(Ref.getCallerPlugin(Ref.getCallerClass(3).orElse(Main.class)));
+ return new MenuBuilder(Ref.getCallerPlugin(Ref.getCallerClass(3).orElse(TabooLib.class)));
}
public MenuBuilder lockHand() {
diff --git a/src/main/scala/me/skymc/taboolib/inventory/builder/v2/MenuHolder.java b/src/main/scala/io/izzel/taboolib/util/item/inventory/MenuHolder.java
similarity index 90%
rename from src/main/scala/me/skymc/taboolib/inventory/builder/v2/MenuHolder.java
rename to src/main/scala/io/izzel/taboolib/util/item/inventory/MenuHolder.java
index 09912d3..44ee84f 100644
--- a/src/main/scala/me/skymc/taboolib/inventory/builder/v2/MenuHolder.java
+++ b/src/main/scala/io/izzel/taboolib/util/item/inventory/MenuHolder.java
@@ -1,4 +1,4 @@
-package me.skymc.taboolib.inventory.builder.v2;
+package io.izzel.taboolib.util.item.inventory;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
diff --git a/src/main/scala/io/izzel/taboolib/util/lite/Catchers.java b/src/main/scala/io/izzel/taboolib/util/lite/Catchers.java
new file mode 100644
index 0000000..ff04a86
--- /dev/null
+++ b/src/main/scala/io/izzel/taboolib/util/lite/Catchers.java
@@ -0,0 +1,70 @@
+package io.izzel.taboolib.util.lite;
+
+import io.izzel.taboolib.TabooLib;
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.player.AsyncPlayerChatEvent;
+import org.bukkit.event.player.PlayerQuitEvent;
+
+import java.util.HashMap;
+import java.util.LinkedList;
+
+public class Catchers implements Listener {
+
+ private static HashMap> playerdata = new HashMap<>();
+
+ public static HashMap> getPlayerdata() {
+ return playerdata;
+ }
+
+ public static boolean contains(Player player) {
+ return playerdata.containsKey(player.getName()) && playerdata.get(player.getName()).size() > 0;
+ }
+
+ public static void call(Player player, Catcher catcher) {
+ if (!playerdata.containsKey(player.getName())) {
+ playerdata.put(player.getName(), new LinkedList<>());
+ }
+ playerdata.get(player.getName()).add(catcher.before());
+ }
+
+ @EventHandler
+ public void quit(PlayerQuitEvent e) {
+ playerdata.remove(e.getPlayer().getName());
+ }
+
+ @EventHandler
+ public void chat(AsyncPlayerChatEvent e) {
+ if (playerdata.containsKey(e.getPlayer().getName()) && contains(e.getPlayer())) {
+ e.setCancelled(true);
+ // 1.14 supported.
+ Bukkit.getScheduler().runTask(TabooLib.getPlugin(), () -> {
+ // 退出
+ if (e.getMessage().equalsIgnoreCase("quit()")) {
+ playerdata.get(e.getPlayer().getName()).removeFirst().cancel();
+ }
+ // 默认
+ else {
+ Catcher catcher = playerdata.get(e.getPlayer().getName()).getFirst();
+ // 如果终止引导
+ if (!catcher.after(e.getMessage())) {
+ playerdata.get(e.getPlayer().getName()).removeFirst();
+ } else {
+ catcher.before();
+ }
+ }
+ });
+ }
+ }
+
+ public interface Catcher {
+
+ Catcher before();
+
+ boolean after(String message);
+
+ void cancel();
+ }
+}
diff --git a/src/main/scala/me/skymc/taboolib/fileutils/TLogs.java b/src/main/scala/io/izzel/taboolib/util/lite/Logs.java
similarity index 66%
rename from src/main/scala/me/skymc/taboolib/fileutils/TLogs.java
rename to src/main/scala/io/izzel/taboolib/util/lite/Logs.java
index 49f6c89..5f51572 100644
--- a/src/main/scala/me/skymc/taboolib/fileutils/TLogs.java
+++ b/src/main/scala/io/izzel/taboolib/util/lite/Logs.java
@@ -1,13 +1,14 @@
-package me.skymc.taboolib.fileutils;
+package io.izzel.taboolib.util.lite;
-import com.ilummc.tlib.resources.TLocale;
-import com.ilummc.tlib.util.Strings;
-import me.skymc.taboolib.TabooLib;
-import me.skymc.taboolib.commands.internal.BaseMainCommand;
-import me.skymc.taboolib.commands.internal.BaseSubCommand;
-import me.skymc.taboolib.commands.internal.TCommand;
-import me.skymc.taboolib.commands.internal.type.CommandArgument;
-import me.skymc.taboolib.commands.internal.type.CommandRegister;
+import io.izzel.taboolib.TabooLib;
+import io.izzel.taboolib.module.locale.TLocale;
+import io.izzel.taboolib.module.command.base.BaseCommand;
+import io.izzel.taboolib.module.command.base.BaseMainCommand;
+import io.izzel.taboolib.module.command.base.BaseSubCommand;
+import io.izzel.taboolib.module.command.base.Argument;
+import io.izzel.taboolib.module.command.base.SubCommand;
+import io.izzel.taboolib.util.Files;
+import io.izzel.taboolib.util.Strings;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@@ -20,12 +21,11 @@ import java.text.SimpleDateFormat;
/**
* @author sky
*/
-@TCommand(
- name = "tabooliblogs",
- aliases = {"tlog", "tlogs"},
+@BaseCommand(
+ name = "tLogs",
permission = "taboolib.admin"
)
-public class TLogs extends BaseMainCommand {
+public class Logs extends BaseMainCommand {
private static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
@@ -34,7 +34,7 @@ public class TLogs extends BaseMainCommand {
return TLocale.asString("COMMANDS.TLOGS.COMMAND-TITLE");
}
- @CommandRegister(priority = 0)
+ @SubCommand(priority = 0)
BaseSubCommand info = new BaseSubCommand() {
@Override
public String getLabel() {
@@ -47,10 +47,10 @@ public class TLogs extends BaseMainCommand {
}
@Override
- public CommandArgument[] getArguments() {
- return new CommandArgument[] {
- new CommandArgument(TLocale.asString("COMMANDS.TLOGS.INFO.ARGUMENTS.0")),
- new CommandArgument(TLocale.asString("COMMANDS.TLOGS.INFO.ARGUMENTS.1"))
+ public Argument[] getArguments() {
+ return new Argument[] {
+ new Argument(TLocale.asString("COMMANDS.TLOGS.INFO.ARGUMENTS.0")),
+ new Argument(TLocale.asString("COMMANDS.TLOGS.INFO.ARGUMENTS.1"))
};
}
@@ -63,7 +63,7 @@ public class TLogs extends BaseMainCommand {
}
};
- @CommandRegister(priority = 1)
+ @SubCommand(priority = 1)
BaseSubCommand error = new BaseSubCommand() {
@Override
public String getLabel() {
@@ -76,10 +76,10 @@ public class TLogs extends BaseMainCommand {
}
@Override
- public CommandArgument[] getArguments() {
- return new CommandArgument[] {
- new CommandArgument(TLocale.asString("COMMANDS.TLOGS.ERROR.ARGUMENTS.0")),
- new CommandArgument(TLocale.asString("COMMANDS.TLOGS.ERROR.ARGUMENTS.1"))
+ public Argument[] getArguments() {
+ return new Argument[] {
+ new Argument(TLocale.asString("COMMANDS.TLOGS.ERROR.ARGUMENTS.0")),
+ new Argument(TLocale.asString("COMMANDS.TLOGS.ERROR.ARGUMENTS.1"))
};
}
@@ -92,7 +92,7 @@ public class TLogs extends BaseMainCommand {
}
};
- @CommandRegister(priority = 2)
+ @SubCommand(priority = 2)
BaseSubCommand warning = new BaseSubCommand() {
@Override
public String getLabel() {
@@ -105,10 +105,10 @@ public class TLogs extends BaseMainCommand {
}
@Override
- public CommandArgument[] getArguments() {
- return new CommandArgument[] {
- new CommandArgument(TLocale.asString("COMMANDS.TLOGS.WARNING.ARGUMENTS.0")),
- new CommandArgument(TLocale.asString("COMMANDS.TLOGS.WARNING.ARGUMENTS.1"))
+ public Argument[] getArguments() {
+ return new Argument[] {
+ new Argument(TLocale.asString("COMMANDS.TLOGS.WARNING.ARGUMENTS.0")),
+ new Argument(TLocale.asString("COMMANDS.TLOGS.WARNING.ARGUMENTS.1"))
};
}
@@ -146,9 +146,8 @@ public class TLogs extends BaseMainCommand {
}
public static void write(File file, String format, String text) {
- Bukkit.getScheduler().runTask(TabooLib.instance(), () -> {
- FileUtils.createNewFileAndPath(file);
- try (FileWriter writer = new FileWriter(file, true)) {
+ Bukkit.getScheduler().runTask(TabooLib.getPlugin(), () -> {
+ try (FileWriter writer = new FileWriter(Files.file(file), true)) {
writer.write(Strings.replaceWithOrder(format, dateFormat.format(System.currentTimeMillis()), text));
} catch (Exception ignored) {
}
diff --git a/src/main/scala/io/izzel/taboolib/util/lite/Numbers.java b/src/main/scala/io/izzel/taboolib/util/lite/Numbers.java
new file mode 100644
index 0000000..caec533
--- /dev/null
+++ b/src/main/scala/io/izzel/taboolib/util/lite/Numbers.java
@@ -0,0 +1,48 @@
+package io.izzel.taboolib.util.lite;
+
+import java.text.DecimalFormat;
+import java.util.Random;
+
+/**
+ * @Author 坏黑
+ * @Since 2019-07-05 19:02
+ */
+public class Numbers {
+
+ private static Random random = new Random();
+ private static DecimalFormat doubleFormat = new DecimalFormat("#.##");
+
+ public static Random getRandom() {
+ return random;
+ }
+
+ public static Double format(Double num) {
+ return Double.valueOf(doubleFormat.format(num));
+ }
+
+ public static int getRandomInteger(Number num1, Number num2) {
+ int min = Math.min(num1.intValue(), num2.intValue());
+ int max = Math.max(num1.intValue(), num2.intValue());
+ return (int) (random.nextDouble() * (max - min) + min);
+ }
+
+ public static double getRandomDouble(Number num1, Number num2) {
+ double min = Math.min(num1.doubleValue(), num2.doubleValue());
+ double max = Math.max(num1.doubleValue(), num2.doubleValue());
+ return random.nextDouble() * (max - min) + min;
+ }
+
+ public static Boolean getBoolean(String str) {
+ if (str == null || str.isEmpty()) {
+ return false;
+ }
+ char var = str.charAt(0);
+ if (var == 'y' || var == 'Y' || var == 't' || var == 'T' || var == '1') {
+ return true;
+ }
+ if (var == 'n' || var == 'N' || var == 'f' || var == 'F' || var == '0') {
+ return false;
+ }
+ return false;
+ }
+}
diff --git a/src/main/scala/io/izzel/taboolib/util/lite/Particles.java b/src/main/scala/io/izzel/taboolib/util/lite/Particles.java
new file mode 100644
index 0000000..66c3fb5
--- /dev/null
+++ b/src/main/scala/io/izzel/taboolib/util/lite/Particles.java
@@ -0,0 +1,967 @@
+package io.izzel.taboolib.util.lite;
+
+import io.izzel.taboolib.Version;
+import io.izzel.taboolib.module.nms.NMS;
+import io.izzel.taboolib.module.packet.TPacketHandler;
+import io.izzel.taboolib.util.Reflection;
+import org.bukkit.Bukkit;
+import org.bukkit.Color;
+import org.bukkit.Location;
+import org.bukkit.block.data.BlockData;
+import org.bukkit.configuration.MemorySection;
+import org.bukkit.entity.LivingEntity;
+import org.bukkit.entity.Player;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.material.MaterialData;
+import org.bukkit.util.NumberConversions;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+
+/**
+ * ParticleEffect Library
+ *
+ * This library was created by @DarkBlade12 and allows you to display all Minecraft particle effects on a Bukkit server
+ *
+ * You are welcome to use it, modify it and redistribute it under the following conditions:
+ *
+ *
Don't claim this class as your own
+ *
Don't remove this disclaimer
+ *
+ *
+ * Special thanks:
+ *
+ *
@microgeek (original idea, names and packet parameters)
+ *
@ShadyPotato (1.8 names, ids and packet parameters)
+ *
@RingOfStorms (particle behavior)
+ *
@Cybermaxke (particle behavior)
+ *
@JamieSinn (hosting a jenkins server and documentation for particleeffect)
+ *
@SkytAsul (updating to 1.13)
+ *
+ *
+ * It would be nice if you provide credit to me if you use this class in a published project
+ *
+ * @author DarkBlade12
+ * @version 1.8
+ */
+public enum Particles {
+
+ BARRIER,
+ BLOCK_CRACK(ParticleProperty.REQUIRES_DATA),
+ BLOCK_DUST(ParticleProperty.REQUIRES_DATA),
+ BUBBLE_COLUMN_UP(13),
+ BUBBLE_POP(13),
+ CLOUD,
+ CRIT,
+ CRIT_MAGIC,
+ CURRENT_DOWN(13),
+ DAMAGE_INDICATOR(9),
+ DOLPHIN(13),
+ DRAGON_BREATH(9),
+ DRIP_LAVA,
+ DRIP_WATER,
+ ENCHANTMENT_TABLE,
+ END_ROD(9),
+ EXPLOSION_HUGE,
+ EXPLOSION_LARGE,
+ EXPLOSION_NORMAL,
+ FALLING_DUST(10),
+ FIREWORKS_SPARK,
+ FLAME,
+ FOOTSTEP(0, 12),
+ HEART,
+ ITEM_CRACK(ParticleProperty.REQUIRES_DATA),
+ ITEM_TAKE,
+ LAVA,
+ MOB_APPEARANCE,
+ NAUTILUS(13),
+ NOTE(ParticleProperty.COLORABLE),
+ PORTAL,
+ REDSTONE(ParticleProperty.COLORABLE),
+ SLIME,
+ SMOKE_LARGE,
+ SMOKE_NORMAL,
+ SNOW_SHOVEL,
+ SNOWBALL,
+ SPELL,
+ SPELL_INSTANT,
+ SPELL_MOB(ParticleProperty.COLORABLE),
+ SPELL_MOB_AMBIENT(ParticleProperty.COLORABLE),
+ SPELL_WITCH,
+ SPIT(11),
+ SQUID_INK(13),
+ SUSPENDED,
+ SUSPENDED_DEPTH(0, 12),
+ SWEEP_ATTACK(9),
+ TOTEM(11),
+ TOWN_AURA,
+ VILLAGER_ANGRY,
+ VILLAGER_HAPPY,
+ WATER_BUBBLE,
+ WATER_DROP,
+ WATER_SPLASH,
+ WATER_WAKE,
+ ;
+
+ private static int mcVersion = NumberConversions.toInt(Version.getBukkitVersion().split("_")[1]);
+ private org.bukkit.Particle bukkitParticle;
+ private final List properties;
+ private int min, max;
+
+ Particles(ParticleProperty... properties) {
+ this(0, 0, properties);
+ }
+
+ Particles(int min, ParticleProperty... properties) {
+ this(min, 0, properties);
+ }
+
+ Particles(int min, int max, ParticleProperty... properties) {
+ this.properties = Arrays.asList(properties);
+ this.min = min;
+ this.max = max;
+ try {
+ bukkitParticle = org.bukkit.Particle.valueOf(this.name());
+ } catch (IllegalArgumentException ex) {
+ bukkitParticle = null;
+ }
+ }
+
+ public org.bukkit.Particle getBukkitParticle() {
+ return bukkitParticle;
+ }
+
+ public int getMinimumVersion() {
+ return min;
+ }
+
+ public int getMaximumVersion() {
+ return max;
+ }
+
+
+ /**
+ * Determine if this particle effect has a specific property
+ *
+ * @param property Property tested
+ * @return Whether it has the property or not
+ */
+ public boolean hasProperty(ParticleProperty property) {
+ return properties.contains(property);
+ }
+
+ /**
+ * Determine if this particle effect is supported by your current server version
+ *
+ * @return Whether the particle effect is supported or not
+ */
+ public boolean isSupported() {
+ if (min != 0 && min > mcVersion) {
+ return false;
+ }
+ if (max != 0 && max < mcVersion) {
+ return false;
+ }
+ return bukkitParticle != null;
+ }
+
+ /**
+ * Returns the particle effect with the given name
+ *
+ * @param name Name of the particle effect
+ * @return The particle effect
+ */
+ public static Particles fromName(String name) {
+ for (Particles effect : values()) {
+ if (effect.name().equalsIgnoreCase(name)) {
+ if (!effect.isSupported()) {
+ throw new ParticleVersionException();
+ }
+ return effect;
+ }
+ }
+ throw new IllegalArgumentException("ParticleEffect " + name + " doesn't exist.");
+ }
+
+ /**
+ * Determine if the distance between @param location and one of the players exceeds 256
+ *
+ * @param location Location to check
+ * @return Whether the distance exceeds 256 or not
+ */
+ private static boolean isLongDistance(Location location, List players) {
+ String world = location.getWorld().getName();
+ for (Player player : players) {
+ if (player == null) {
+ continue;
+ }
+ Location playerLocation = player.getLocation();
+ if (!world.equals(playerLocation.getWorld().getName()) || playerLocation.distanceSquared(location) < 65536) {
+ continue;
+ }
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Determine if the data type for a particle effect is correct
+ *
+ * @param effect Particle effect
+ * @param data Particle data
+ * @return Whether the data type is correct or not
+ */
+ private static boolean isDataCorrect(Particles effect, Object data) {
+ return ((effect == BLOCK_CRACK || effect == BLOCK_DUST) && (mcVersion < 13 ? data instanceof MaterialData : data instanceof BlockData)) || (effect == ITEM_CRACK && data instanceof ItemStack);
+ }
+
+ /**
+ * Determine if the color type for a particle effect is correct
+ *
+ * @param effect Particle effect
+ * @param color Particle color
+ * @return Whether the color type is correct or not
+ */
+ private static boolean isColorCorrect(Particles effect, ParticleColor color) {
+ return ((effect == SPELL_MOB || effect == SPELL_MOB_AMBIENT || effect == REDSTONE) && color instanceof OrdinaryColor) || (effect == NOTE && color instanceof NoteColor);
+ }
+
+ /**
+ * Displays a particle effect which is only visible for all players within a certain range in the world of @param center
+ *
+ * @param offsetX Maximum distance particles can fly away from the center on the x-axis
+ * @param offsetY Maximum distance particles can fly away from the center on the y-axis
+ * @param offsetZ Maximum distance particles can fly away from the center on the z-axis
+ * @param speed Display speed of the particles
+ * @param amount Amount of particles
+ * @param center Center location of the effect
+ * @param range Range of the visibility
+ * @throws ParticleVersionException If the particle effect is not supported by the server version
+ * @throws ObjectException If the particle effect requires additional data
+ * @throws IllegalArgumentException If the particle effect requires water and none is at the center location
+ */
+ public void display(double offsetX, double offsetY, double offsetZ, double speed, int amount, Location center, double range) throws ParticleVersionException, ObjectException, IllegalArgumentException {
+ if (!isSupported()) {
+ throw new ParticleVersionException();
+ }
+ if (hasProperty(ParticleProperty.REQUIRES_DATA)) {
+ throw new ObjectException("This particle effect requires additional data");
+ }
+ /*if (hasProperty(ParticleProperty.REQUIRES_WATER) && !isWater(center)) {
+ throw new IllegalArgumentException("There is no water at the center location");
+ }*/
+ new ParticlePacket(this, offsetX, offsetY, offsetZ, speed, amount, range > 256, null).sendTo(center, range);
+ }
+
+ /**
+ * Displays a particle effect which is only visible for the specified players
+ *
+ * @param offsetX Maximum distance particles can fly away from the center on the x-axis
+ * @param offsetY Maximum distance particles can fly away from the center on the y-axis
+ * @param offsetZ Maximum distance particles can fly away from the center on the z-axis
+ * @param speed Display speed of the particles
+ * @param amount Amount of particles
+ * @param center Center location of the effect
+ * @param players Receivers of the effect
+ * @throws ParticleVersionException If the particle effect is not supported by the server version
+ * @throws ObjectException If the particle effect requires additional data
+ * @throws IllegalArgumentException If the particle effect requires water and none is at the center location
+ */
+ public void display(double offsetX, double offsetY, double offsetZ, double speed, int amount, Location center, List players) throws ParticleVersionException, ObjectException, IllegalArgumentException {
+ if (!isSupported()) {
+ throw new ParticleVersionException();
+ }
+ if (hasProperty(ParticleProperty.REQUIRES_DATA)) {
+ throw new ObjectException("This particle effect requires additional data");
+ }
+ /*if (hasProperty(ParticleProperty.REQUIRES_WATER) && !isWater(center)) {
+ throw new IllegalArgumentException("There is no water at the center location");
+ }*/
+ new ParticlePacket(this, offsetX, offsetY, offsetZ, speed, amount, isLongDistance(center, players), null).sendTo(center, players);
+ }
+
+ /**
+ * Displays a single particle which is colored and only visible for all players within a certain range in the world of @param center
+ *
+ * @param color Color of the particle
+ * @param offsetX Maximum distance particles can fly away from the center on the x-axis
+ * @param offsetY Maximum distance particles can fly away from the center on the y-axis
+ * @param offsetZ Maximum distance particles can fly away from the center on the z-axis
+ * @param amount Amount of particles
+ * @param center Center location of the effect
+ * @param range Range of the visibility
+ * @throws ParticleVersionException If the particle effect is not supported by the server version
+ * @throws ParticleColorException If the particle effect is not colorable or the color type is incorrect
+ */
+ public void display(ParticleColor color, double offsetX, double offsetY, double offsetZ, int amount, Location center, double range) throws ParticleVersionException, ParticleColorException {
+ if (!isSupported()) {
+ throw new ParticleVersionException();
+ }
+ if (!hasProperty(ParticleProperty.COLORABLE)) {
+ throw new ParticleColorException("This particle effect is not colorable");
+ }
+ if (!isColorCorrect(this, color)) {
+ throw new ParticleColorException("The particle color type is incorrect");
+ }
+ new ParticlePacket(this, offsetX, offsetY, offsetZ, 1, amount, range > 256, color).sendTo(center, range);
+ }
+
+ /**
+ * Displays a single particle which is colored and only visible for the specified players
+ *
+ * @param color Color of the particle
+ * @param offsetX Maximum distance particles can fly away from the center on the x-axis
+ * @param offsetY Maximum distance particles can fly away from the center on the y-axis
+ * @param offsetZ Maximum distance particles can fly away from the center on the z-axis
+ * @param amount Amount of particles
+ * @param center Center location of the effect
+ * @param players Receivers of the effect
+ * @throws ParticleVersionException If the particle effect is not supported by the server version
+ * @throws ParticleColorException If the particle effect is not colorable or the color type is incorrect
+ */
+ public void display(ParticleColor color, double offsetX, double offsetY, double offsetZ, int amount, Location center, List players) throws ParticleVersionException, ParticleColorException {
+ if (!isSupported()) {
+ throw new ParticleVersionException();
+ }
+ if (!hasProperty(ParticleProperty.COLORABLE)) {
+ throw new ParticleColorException("This particle effect is not colorable");
+ }
+ if (!isColorCorrect(this, color)) {
+ throw new ParticleColorException("The particle color type is incorrect");
+ }
+ new ParticlePacket(this, offsetX, offsetY, offsetZ, 1, amount, isLongDistance(center, players), color).sendTo(center, players);
+ }
+
+ /**
+ * Displays a particle effect which requires additional data and is only visible for the specified players
+ *
+ * @param data Data of the effect
+ * @param offsetX Maximum distance particles can fly away from the center on the x-axis
+ * @param offsetY Maximum distance particles can fly away from the center on the y-axis
+ * @param offsetZ Maximum distance particles can fly away from the center on the z-axis
+ * @param speed Display speed of the particles
+ * @param amount Amount of particles
+ * @param center Center location of the effect
+ * @param players Receivers of the effect
+ * @throws ParticleVersionException If the particle effect is not supported by the server version
+ * @throws ObjectException If the particle effect does not require additional data or if the data type is incorrect
+ */
+ public void display(Object data, double offsetX, double offsetY, double offsetZ, double speed, int amount, Location center, List players) throws ParticleVersionException, ObjectException {
+ if (!isSupported()) {
+ throw new ParticleVersionException();
+ }
+ if (!hasProperty(ParticleProperty.REQUIRES_DATA)) {
+ throw new ObjectException("This particle effect does not require additional data");
+ }
+ if (!isDataCorrect(this, data)) {
+ throw new ObjectException("The particle data type is incorrect");
+ }
+ new ParticlePacket(this, offsetX, offsetY, offsetZ, speed, amount, isLongDistance(center, players), data).sendTo(center, players);
+ }
+
+ /**
+ * Represents the property of a particle effect
+ *
+ * This class is part of the ParticleEffect Library and follows the same usage conditions
+ *
+ * @author DarkBlade12
+ * @since 1.7
+ */
+ public enum ParticleProperty {
+ /**
+ * The particle effect requires water to be displayed
+ */
+ @Deprecated
+ REQUIRES_WATER,
+ /**
+ * The particle effect requires block or item data to be displayed
+ */
+ REQUIRES_DATA,
+ /**
+ * The particle effect uses the offsets as direction values
+ */
+ @Deprecated
+ DIRECTIONAL,
+ /**
+ * The particle effect uses the offsets as color values
+ */
+ COLORABLE
+ }
+
+ /**
+ * Represents the color for effects like {@link Particles#SPELL_MOB}, {@link Particles#SPELL_MOB_AMBIENT}, {@link Particles#REDSTONE} and {@link Particles#NOTE}
+ *
+ * This class is part of the ParticleEffect Library and follows the same usage conditions
+ *
+ * @author DarkBlade12
+ * @since 1.7
+ */
+ public static abstract class ParticleColor {
+ /**
+ * Returns the value for the offsetX field
+ *
+ * @return The offsetX value
+ */
+ public abstract float getValueX();
+
+ /**
+ * Returns the value for the offsetY field
+ *
+ * @return The offsetY value
+ */
+ public abstract float getValueY();
+
+ /**
+ * Returns the value for the offsetZ field
+ *
+ * @return The offsetZ value
+ */
+ public abstract float getValueZ();
+ }
+
+ /**
+ * Represents the color for effects like {@link Particles#SPELL_MOB}, {@link Particles#SPELL_MOB_AMBIENT} and {@link Particles#NOTE}
+ *
+ * This class is part of the ParticleEffect Library and follows the same usage conditions
+ *
+ * @author DarkBlade12
+ * @since 1.7
+ */
+ public static class OrdinaryColor extends ParticleColor {
+ private final int red;
+ private final int green;
+ private final int blue;
+
+ /**
+ * Construct a new ordinary color
+ *
+ * @param red Red value of the RGB format
+ * @param green Green value of the RGB format
+ * @param blue Blue value of the RGB format
+ * @throws IllegalArgumentException If one of the values is lower than 0 or higher than 255
+ */
+ public OrdinaryColor(int red, int green, int blue) throws IllegalArgumentException {
+ if (red < 0) {
+ throw new IllegalArgumentException("The red value is lower than 0");
+ }
+ if (red > 255) {
+ throw new IllegalArgumentException("The red value is higher than 255");
+ }
+ this.red = red;
+ if (green < 0) {
+ throw new IllegalArgumentException("The green value is lower than 0");
+ }
+ if (green > 255) {
+ throw new IllegalArgumentException("The green value is higher than 255");
+ }
+ this.green = green;
+ if (blue < 0) {
+ throw new IllegalArgumentException("The blue value is lower than 0");
+ }
+ if (blue > 255) {
+ throw new IllegalArgumentException("The blue value is higher than 255");
+ }
+ this.blue = blue;
+ }
+
+ /**
+ * Construct a new ordinary color
+ *
+ * @param color Bukkit color
+ */
+ public OrdinaryColor(Color color) {
+ this(color.getRed(), color.getGreen(), color.getBlue());
+ }
+
+ /**
+ * Returns the red value of the RGB format
+ *
+ * @return The red value
+ */
+ public int getRed() {
+ return red;
+ }
+
+ /**
+ * Returns the green value of the RGB format
+ *
+ * @return The green value
+ */
+ public int getGreen() {
+ return green;
+ }
+
+ /**
+ * Returns the blue value of the RGB format
+ *
+ * @return The blue value
+ */
+ public int getBlue() {
+ return blue;
+ }
+
+ /**
+ * Returns the red value divided by 255
+ *
+ * @return The offsetX value
+ */
+
+ public float getValueX() {
+ return (float) red / 255F;
+ }
+
+ /**
+ * Returns the green value divided by 255
+ *
+ * @return The offsetY value
+ */
+
+ public float getValueY() {
+ return (float) green / 255F;
+ }
+
+ /**
+ * Returns the blue value divided by 255
+ *
+ * @return The offsetZ value
+ */
+
+ public float getValueZ() {
+ return (float) blue / 255F;
+ }
+ }
+
+ /**
+ * Represents the color for the {@link Particles#NOTE} effect
+ *
+ * This class is part of the ParticleEffect Library and follows the same usage conditions
+ *
+ * @author DarkBlade12
+ * @since 1.7
+ */
+ public static final class NoteColor extends ParticleColor {
+ private final int note;
+
+ /**
+ * Construct a new note color
+ *
+ * @param note Note id which determines color
+ * @throws IllegalArgumentException If the note value is lower than 0 or higher than 24
+ */
+ public NoteColor(int note) throws IllegalArgumentException {
+ if (note < 0) {
+ throw new IllegalArgumentException("The note value is lower than 0");
+ }
+ if (note > 24) {
+ throw new IllegalArgumentException("The note value is higher than 24");
+ }
+ this.note = note;
+ }
+
+ /**
+ * Returns the note value divided by 24
+ *
+ * @return The offsetX value
+ */
+
+ public float getValueX() {
+ return (float) note / 24F;
+ }
+
+ /**
+ * Returns zero because the offsetY value is unused
+ *
+ * @return zero
+ */
+
+ public float getValueY() {
+ return 0;
+ }
+
+ /**
+ * Returns zero because the offsetZ value is unused
+ *
+ * @return zero
+ */
+
+ public float getValueZ() {
+ return 0;
+ }
+
+ }
+
+ public enum ParticleShape {
+ POINT, NEAR, BAR, EXCLAMATION, SPOT
+ }
+
+ public static class Particle {
+ private static Random random = new Random();
+
+ private Particles effect;
+ private ParticleShape shape;
+ private OrdinaryColor color;
+
+ private byte typeCode;
+
+ public Particle(Particles effect, ParticleShape shape, OrdinaryColor color) {
+ this.effect = effect;
+ this.shape = shape;
+ this.color = color;
+
+ this.typeCode = (byte) (effect == Particles.NOTE ? 2 : (effect.hasProperty(ParticleProperty.COLORABLE) ? 1 : 0));
+ }
+
+ public String toString() {
+ return effect.name() + " in shape " + shape.name() + (typeCode != 0 ? " with color \"R" + (typeCode == 1 ? color.getRed() + " G" + color.getGreen() + " B" + color.getBlue() : "random") + "\"" : "");
+ }
+
+ public void send(LivingEntity en, List p) {
+ if (p.isEmpty()) {
+ return;
+ }
+
+ Location lc = en.getEyeLocation();
+ switch (shape) {
+ case POINT:
+ sendParticle(lc.add(0, 1, 0), p, 0.1, 0.1, 0.1, 1);
+ break;
+ case NEAR:
+ sendParticle(lc.add(random.nextDouble() * 1.2 - 0.6, random.nextDouble() * 2 - en.getEyeHeight(), random.nextDouble() * 1.2 - 0.6), p, 0.1, 0.1, 0.1, 1);
+ break;
+ case BAR:
+ sendParticle(lc.add(0, 1, 0), p, 0.01, 0.15, 0.01, 3);
+ break;
+ case EXCLAMATION:
+ sendParticle(lc.add(0, 0.9, 0), p, 0.001, 0.001, 0.001, 2); // POINT
+ sendParticle(lc.add(0, 0.7, 0), p, 0.01, 0.2, 0.01, 4); // BAR
+ break;
+ case SPOT:
+ sendParticle(lc.add(0, 0.2, 0), p, 0.2, 0.4, 0.2, 15);
+ break;
+ }
+ }
+
+ private void sendParticle(Location lc, List p, double offX, double offY, double offZ, int amount) {
+ switch (typeCode) {
+ case 1:
+ effect.display(color, offX, offY, offZ, amount, lc, p);
+ break;
+ case 2:
+ Particles.NOTE.display(new Particles.NoteColor(random.nextInt(24)), offX, offY, offZ, amount, lc, /*p.getPlayer(),*/ p);
+ break;
+ case 0:
+ effect.display(offX, offY, offZ, 0.001, amount, lc, p);
+ break;
+ }
+ }
+
+ public static Particle deserialize(Map map) {
+ return new Particle(Particles.fromName((String) map.get("particleEffect")), ParticleShape.valueOf(((String) map.get("particleShape")).toUpperCase()), new OrdinaryColor(Color.deserialize(((MemorySection) map.get("particleColor")).getValues(false))));
+ }
+ }
+
+ /**
+ * Represents a runtime exception that is thrown either if the displayed particle effect requires data and has none or vice-versa or if the data type is incorrect
+ *
+ * This class is part of the ParticleEffect Library and follows the same usage conditions
+ *
+ * @author DarkBlade12
+ * @since 1.6
+ */
+ private static final class ObjectException extends RuntimeException {
+ private static final long serialVersionUID = 3203085387160737484L;
+
+ /**
+ * Construct a new particle data exception
+ *
+ * @param message Message that will be logged
+ */
+ public ObjectException(String message) {
+ super(message);
+ }
+ }
+
+ /**
+ * Represents a runtime exception that is thrown either if the displayed particle effect is not colorable or if the particle color type is incorrect
+ *
+ * This class is part of the ParticleEffect Library and follows the same usage conditions
+ *
+ * @author DarkBlade12
+ * @since 1.7
+ */
+ private static final class ParticleColorException extends RuntimeException {
+ private static final long serialVersionUID = 3203085387160737484L;
+
+ /**
+ * Construct a new particle color exception
+ *
+ * @param message Message that will be logged
+ */
+ public ParticleColorException(String message) {
+ super(message);
+ }
+ }
+
+ /**
+ * Represents a runtime exception that is thrown if the displayed particle effect requires a newer version
+ *
+ * This class is part of the ParticleEffect Library and follows the same usage conditions
+ *
+ * @author DarkBlade12
+ * @since 1.6
+ */
+ private static final class ParticleVersionException extends RuntimeException {
+ private static final long serialVersionUID = 3203085387160737484L;
+
+ /**
+ * Construct a new particle version exception
+ */
+ public ParticleVersionException() {
+ super("This particle effect is not supported by your server version");
+ }
+ }
+
+ /**
+ * Represents a particle effect packet with all attributes which is used for sending packets to the players
+ *
+ * This class is part of the ParticleEffect Library and follows the same usage conditions
+ *
+ * @author DarkBlade12
+ * @since 1.5
+ */
+ public static final class ParticlePacket {
+ private static boolean initialized;
+ /*private static Class> enumParticle;
+ private static String ver;
+ private static String pack;*/
+ private final Particles effect;
+ private float offsetX;
+ private float offsetY;
+ private float offsetZ;
+ private final float speed;
+ private int amount;
+ private int size = 1;
+ private final boolean longDistance;
+ private Object data;
+ private Object packet;
+
+ private int timesSending = 1;
+
+ /**
+ * Construct a new particle packet
+ *
+ * @param effect Particle effect
+ * @param offsetX Maximum distance particles can fly away from the center on the x-axis
+ * @param offsetY Maximum distance particles can fly away from the center on the y-axis
+ * @param offsetZ Maximum distance particles can fly away from the center on the z-axis
+ * @param speed Display speed of the particles
+ * @param amount Amount of particles
+ * @param longDistance Indicates whether the maximum distance is increased from 256 to 65536
+ * @param data Data of the effect
+ * @throws IllegalArgumentException If the speed or amount is lower than 0
+ */
+ public ParticlePacket(Particles effect, double offsetX, double offsetY, double offsetZ, double speed, int amount, boolean longDistance, Object data) throws IllegalArgumentException {
+ initialize();
+ if (speed < 0) {
+ throw new IllegalArgumentException("The speed is lower than 0");
+ }
+ if (amount < 0) {
+ throw new IllegalArgumentException("The amount is lower than 0");
+ }
+ this.effect = effect;
+ this.offsetX = (float) offsetX;
+ this.offsetY = (float) offsetY;
+ this.offsetZ = (float) offsetZ;
+ this.speed = (float) speed;
+ this.amount = amount;
+ this.longDistance = longDistance;
+ this.data = data;
+ }
+
+ /**
+ * Construct a new particle packet of a single particle flying into a determined direction
+ *
+ * @param effect Particle effect
+ * @param direction Direction of the particle
+ * @param speed Display speed of the particle
+ * @param longDistance Indicates whether the maximum distance is increased from 256 to 65536
+ * @param data Data of the effect
+ * @throws IllegalArgumentException If the speed is lower than 0
+ */
+ /*public ParticlePacket(ParticleEffect effect, Vector direction, float speed, boolean longDistance, Object data) throws IllegalArgumentException {
+ this(effect, (float) direction.getX(), (float) direction.getY(), (float) direction.getZ(), speed, 0, longDistance, data);
+ }*/
+
+ /**
+ * Initializes and sets initialized to true if it succeeds
+ *
+ * Note: These fields only have to be initialized once, so it will return if initialized is already set to true
+ */
+ public static void initialize() {
+ if (initialized) {
+ return;
+ }
+ initialized = true;
+ }
+
+ /**
+ * Determine if packet is initialized
+ *
+ * @return Whether these fields are initialized or not
+ */
+ public static boolean isInitialized() {
+ return initialized;
+ }
+
+ /**
+ * Initializes packet with all set values
+ *
+ * @param center Center location of the effect
+ * @throws PacketInstantiationException If instantion fails due to an unknown error
+ */
+ private void initializePacket(Location center) throws PacketInstantiationException {
+ if (packet != null) {
+ return;
+ }
+ try {
+ //int tmpAmount = amount;
+ if (effect.hasProperty(ParticleProperty.COLORABLE) && data instanceof ParticleColor) {
+ if (mcVersion < 13 || data instanceof NoteColor) {
+ ParticleColor color = (ParticleColor) data;
+ offsetX = color.getValueX();
+ offsetY = color.getValueY();
+ offsetZ = color.getValueZ();
+ timesSending = amount < 2 ? 1 : amount;
+ amount = 0;
+ data = null;
+ if (color instanceof OrdinaryColor && ((OrdinaryColor) color).getRed() == 0) {
+ offsetX = Float.MIN_NORMAL;
+ }
+ } else if (mcVersion >= 13 && data instanceof OrdinaryColor) {
+ data = getDustColor((OrdinaryColor) data, size);
+ }
+ }
+ this.packet = NMS.handle().toPacketPlayOutWorldParticles(effect.getBukkitParticle(), longDistance, (float) center.getX(), (float) center.getY(), (float) center.getZ(), offsetX, offsetY, offsetZ, speed, amount, data);
+ } catch (Throwable exception) {
+ throw new PacketInstantiationException("Packet instantiation failed", exception);
+ }
+ }
+
+ public static Object getDustColor(OrdinaryColor color, int size) {
+ try {
+ return Reflection.instantiateObject(Class.forName("org.bukkit.Particle$DustOptions"), Color.fromBGR(color.getBlue(), color.getGreen(), color.getRed()), size);
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ /**
+ * Sends the packet to a single player and caches it
+ *
+ * @param center Center location of the effect
+ * @param player Receiver of the packet
+ * @throws PacketInstantiationException If instantion fails due to an unknown error
+ * @throws PacketSendingException If sending fails due to an unknown error
+ */
+ public void sendTo(Location center, Player player) throws PacketInstantiationException, PacketSendingException {
+ initializePacket(center);
+ try {
+ if (timesSending == 1) {
+ TPacketHandler.sendPacket(player, packet);
+ } else {
+ for (int i = 0; i < timesSending; i++) {
+ TPacketHandler.sendPacket(player, packet);
+ }
+ }
+ //sendPacket.invoke(playerConnection.get(getHandle.invoke(player)), packet);
+ //((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
+ } catch (Throwable exception) {
+ throw new PacketSendingException("Failed to send the packet to player '" + player.getName() + "'", exception);
+ }
+ }
+
+ /**
+ * Sends the packet to all players in the list
+ *
+ * @param center Center location of the effect
+ * @param players Receivers of the packet
+ * @throws IllegalArgumentException If the player list is empty
+ */
+ public void sendTo(Location center, List players) throws IllegalArgumentException {
+ if (players.isEmpty()) {
+ throw new IllegalArgumentException("The player list is empty");
+ }
+ for (Player player : players) {
+ sendTo(center, player);
+ }
+ }
+
+ /**
+ * Sends the packet to all players in a certain range
+ *
+ * @param center Center location of the effect
+ * @param range Range in which players will receive the packet (Maximum range for particles is usually 16, but it can differ for some types)
+ * @throws IllegalArgumentException If the range is lower than 1
+ */
+ public void sendTo(Location center, double range) throws IllegalArgumentException {
+ if (range < 1) {
+ throw new IllegalArgumentException("The range is lower than 1");
+ }
+ String worldName = center.getWorld().getName();
+ double squared = range * range;
+ for (Player player : Bukkit.getOnlinePlayers()) {
+ if (!player.getWorld().getName().equals(worldName) || player.getLocation().distanceSquared(center) > squared) {
+ continue;
+ }
+ sendTo(center, player);
+ }
+ }
+
+ /**
+ * Represents a runtime exception that is thrown if packet instantiation fails
+ *
+ * This class is part of the ParticleEffect Library and follows the same usage conditions
+ *
+ * @author DarkBlade12
+ * @since 1.4
+ */
+ private static final class PacketInstantiationException extends RuntimeException {
+ private static final long serialVersionUID = 3203085387160737484L;
+
+ /**
+ * Construct a new packet instantiation exception
+ *
+ * @param message Message that will be logged
+ * @param cause Cause of the exception
+ */
+ public PacketInstantiationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+ }
+
+ /**
+ * Represents a runtime exception that is thrown if packet sending fails
+ *