diff --git a/.idea/encodings.xml b/.idea/encodings.xml
index 89fa671..63e9001 100644
--- a/.idea/encodings.xml
+++ b/.idea/encodings.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
index f00ffb2..c49fb0e 100644
--- a/.idea/jarRepositories.xml
+++ b/.idea/jarRepositories.xml
@@ -31,6 +31,11 @@
+
+
+
+
+
diff --git a/WyCore.iml b/WyCore.iml
index c462275..f5de878 100644
--- a/WyCore.iml
+++ b/WyCore.iml
@@ -4,6 +4,7 @@
+ PAPER
ADVENTURE
diff --git a/pom.xml b/pom.xml
index 6577fc0..66bb88f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,67 +1,92 @@
-
4.0.0
ir.wy
WyCore
jar
- 0.7.3
+ 2.0.1
- 16
- 16
+ UTF-8
+ 1.8
+ 1.7.0
org.apache.maven.plugins
- maven-compiler-plugin
- 3.8.1
+ maven-shade-plugin
+ 3.1.1
-
- 1.8
+
+
+ dev.triumphteam.gui
+ ir.wy.wycore.spigot.gui
+
+
-
-
- org.apache.maven.plugins
- maven-shade-plugin
- 3.2.4
package
shade
-
- false
-
- org.apache.maven.plugins
- maven-shade-plugin
- 3.1.1
+ org.jetbrains.kotlin
+ kotlin-maven-plugin
+ ${kotlin.version}
+
+
+ compile
+ compile
+
+ compile
+
+
+
+ test-compile
+ test-compile
+
+ test-compile
+
+
+
-
-
- dev.triumphteam.gui
- ir.wy.wycore.gui
-
-
+ 1.8
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.8.1
- package
+ compile
+ compile
- shade
+ compile
+
+
+
+ testCompile
+ test-compile
+
+ testCompile
+
+
+ 1.8
+
@@ -100,10 +125,6 @@
codemc-releases
https://repo.codemc.io/repository/maven-releases/
-
- iridiumdevelopment
- https://nexus.iridiumdevelopment.net/repository/maven-releases/
-
codemc-repo
https://repo.codemc.org/repository/maven-public/
@@ -113,6 +134,26 @@
jitpack.io
https://jitpack.io
+
+ mineacademy-repo
+ https://bitbucket.org/kangarko/libraries/raw/master
+
+
+ iridiumdevelopment
+ https://nexus.iridiumdevelopment.net/repository/maven-releases/
+
+
+ local-repo
+ file:///${project.basedir}/libs/
+
+
+ janmm14-public
+ https://repo.janmm14.de/repository/public/
+
+
+ essentials-releases
+ https://repo.essentialsx.net/releases/
+
@@ -124,54 +165,148 @@
com.fasterxml.jackson.core
jackson-core
- 2.13.2
+ 2.14.0
+
+
+ de.janmm14
+ aac-api
+ 5.0.0
+
+
+ com.github.MWHunter
+ GrimAPI
+ master
+
+
+ me.vagdedes
+ SpartanAPI
+ 9.1
+ system
+ ${project.basedir}/libs/SpartanAPI.jar
+
+
+ me.frep
+ VulcanAPI
+ 2.6.9
+ system
+ ${project.basedir}/libs/Vulcan-2.6.9.jar
+
+
+ net.essentialsx
+ EssentialsX
+ 2.19.7
+ system
+ ${project.basedir}/libs/EssentialsX-2.19.7.jar
com.fasterxml.jackson.core
jackson-databind
- 2.13.2.1
+ 2.14.0
+
+
+ com.github.Sparky-Tech
+ SparkyAPIV2
+ 2.8
+ system
+ ${project.basedir}/libs/SparkyAPI.jar
com.fasterxml.jackson.core
jackson-annotations
- 2.13.2
+ 2.14.0
+
+
+ com.iridium
+ IridiumColorAPI
+ 1.0.6
com.fasterxml.jackson.dataformat
jackson-dataformat-xml
- 2.13.2
+ 2.14.0
com.fasterxml.jackson.dataformat
jackson-dataformat-yaml
- 2.13.2
+ 2.14.0
org.projectlombok
lombok
- 1.18.22
- provided
+ 1.18.24
io.papermc.paper
paper-api
- 1.18.1-R0.1-SNAPSHOT
+ 1.19.2-R0.1-SNAPSHOT
provided
+
+ me.filoghost.holographicdisplays
+ holographicdisplays
+ 3.0.0
+ system
+ ${project.basedir}/libs/HolographicDisplays.jar
+
io.papermc
paperlib
1.0.7
-
- com.iridium
- IridiumColorAPI
- LATEST
-
com.github.cryptomorin
XSeries
- 8.7.0
+ 9.1.0
+
+
+ org.mineacademy.plugin
+ CMI-API
+ 9.0.0.0
+
+
+ com.github.decentsoftware-eu
+ decentholograms
+ 2.7.7
+ provided
+
+
+ net.Zrips.CMILib
+ CMILib
+ 2.3.7
+ system
+ ${project.basedir}/libs/CMILib1.2.3.7.jar
+
+
+ org.mineacademy.plugin
+ Multiverse-Core
+ 4.3.2-SNAPSHOT-870
+
+
+ org.mineacademy.plugin
+ PlaceholderAPI
+ 2.11.1
+
+
+ org.mineacademy.plugin
+ Vault
+ 1.7.3
+
+
+ org.mineacademy.plugin
+ WorldEdit
+ 7.2.10
+
+
+
+ org.jetbrains.kotlin
+ kotlin-test
+ ${kotlin.version}
+ test
+
+
+ org.jetbrains.kotlin
+ kotlin-stdlib-jdk8
+ ${kotlin.version}
diff --git a/src/main/java/ir/wy/wycore/WyCore.java b/src/main/java/ir/wy/wycore/WyCore.java
index 7551420..4f84d72 100644
--- a/src/main/java/ir/wy/wycore/WyCore.java
+++ b/src/main/java/ir/wy/wycore/WyCore.java
@@ -1,8 +1,8 @@
package ir.wy.wycore;
-import ir.wy.wycore.gui.*;
-import ir.wy.wycore.Heart;
-import io.papermc.lib.*;
+import io.papermc.lib.PaperLib;
+import ir.wy.wycore.spigot.Heart;
+import ir.wy.wycore.spigot.gui.GUI;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.bukkit.Bukkit;
@@ -18,11 +18,10 @@
@Getter
@NoArgsConstructor
public class WyCore extends JavaPlugin {
+ private static WyCore instance;
private BukkitTask saveTask;
private boolean isTesting = false;
-
private Heart heart;
- private static WyCore instance;
// Testing & Debug Logger
public WyCore(JavaPluginLoader loader, PluginDescriptionFile description, File dataFolder, File file) {
@@ -31,6 +30,10 @@ public WyCore(JavaPluginLoader loader, PluginDescriptionFile description, File d
getLogger().setFilter(record -> false);
}
+ public static WyCore getInstance() {
+ return instance;
+ }
+
@Override
public void onLoad() {
getDataFolder().mkdirs();
@@ -39,11 +42,12 @@ public void onLoad() {
loadConfigs();
saveConfigs();
}
+
@Override
public void onEnable() {
instance = this;
- if(!PaperLib.isSpigot() && !isTesting) {
+ if (!PaperLib.isSpigot() && !isTesting) {
getLogger().warning("Use Spigot and other forks etc Paper instead of craftbukkit or sponge.");
Bukkit.getPluginManager().disablePlugin(this);
return;
@@ -81,7 +85,7 @@ public void onDisable() {
public void registerListeners() {
}
- public void saveData(){
+ public void saveData() {
}
public void loadConfigs() {
@@ -89,8 +93,4 @@ public void loadConfigs() {
public void saveConfigs() {
}
-
- public static WyCore getInstance() {
- return instance;
- }
}
diff --git a/src/main/java/ir/wy/wycore/behind/event/ArmorChangeEvent.java b/src/main/java/ir/wy/wycore/behind/event/ArmorChangeEvent.java
new file mode 100644
index 0000000..2f687d4
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/behind/event/ArmorChangeEvent.java
@@ -0,0 +1,38 @@
+package ir.wy.wycore.behind.event;
+
+import org.bukkit.entity.Player;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.player.PlayerEvent;
+import org.bukkit.inventory.ItemStack;
+import org.jetbrains.annotations.NotNull;
+import java.util.List;
+
+public class ArmorChangeEvent extends PlayerEvent {
+
+ private static final HandlerList HANDLERS = new HandlerList();
+ private final List before;
+ private final List after;
+
+ public ArmorChangeEvent(@NotNull final Player player, @NotNull final List after, @NotNull final List before) {
+ super(player);
+ this.before = before;
+ this.after = after;
+ }
+
+ @Override @NotNull
+ public HandlerList getHandlers() {
+ return HANDLERS;
+ }
+
+ public static HandlerList getHandlerList() {
+ return HANDLERS;
+ }
+
+ public List getBefore() {
+ return this.before;
+ }
+
+ public List getAfter() {
+ return this.after;
+ }
+}
diff --git a/src/main/java/ir/wy/wycore/behind/event/ArmorEquipEvent.java b/src/main/java/ir/wy/wycore/behind/event/ArmorEquipEvent.java
new file mode 100644
index 0000000..dea4f44
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/behind/event/ArmorEquipEvent.java
@@ -0,0 +1,25 @@
+package ir.wy.wycore.behind.event;
+
+import com.Zrips.CMI.Modules.BungeeCord.ServerListPing;
+import org.bukkit.entity.Player;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.player.PlayerEvent;
+import org.jetbrains.annotations.NotNull;
+
+public class ArmorEquipEvent extends PlayerEvent {
+
+ private static final HandlerList HANDLERS = new HandlerList();
+
+ public ArmorEquipEvent(@NotNull final Player player) {
+ super(player);
+ }
+
+ @Override @NotNull
+ public HandlerList getHandlers() {
+ return HANDLERS;
+ }
+
+ public static HandlerList getHandlerList() {
+ return HANDLERS;
+ }
+}
diff --git a/src/main/java/ir/wy/wycore/behind/event/EventHandling.kt b/src/main/java/ir/wy/wycore/behind/event/EventHandling.kt
new file mode 100644
index 0000000..7481a55
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/behind/event/EventHandling.kt
@@ -0,0 +1,9 @@
+package ir.wy.wycore.behind.event
+
+import org.bukkit.event.Listener
+
+interface EventHandling {
+ fun registerListener(listener: Listener)
+ fun unregisterListener(listener: Listener)
+ fun unregisterAllListeners()
+}
\ No newline at end of file
diff --git a/src/main/java/ir/wy/wycore/behind/event/EventManager.kt b/src/main/java/ir/wy/wycore/behind/event/EventManager.kt
new file mode 100644
index 0000000..344f005
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/behind/event/EventManager.kt
@@ -0,0 +1,19 @@
+package ir.wy.wycore.behind.event
+
+import ir.wy.wycore.WyCore
+import org.bukkit.Bukkit
+import org.bukkit.event.HandlerList
+import org.bukkit.event.Listener
+
+class EventManager (private val plugin: WyCore) : EventHandling {
+ override fun registerListener(listener: Listener) {
+ Bukkit.getPluginManager().registerEvents(listener, plugin)
+ }
+
+ override fun unregisterListener(listener: Listener) {
+ HandlerList.unregisterAll(listener)
+ }
+ override fun unregisterAllListeners() {
+ HandlerList.unregisterAll(plugin)
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/ir/wy/wycore/behind/particle/AvailableParticle.java b/src/main/java/ir/wy/wycore/behind/particle/AvailableParticle.java
new file mode 100644
index 0000000..2460b43
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/behind/particle/AvailableParticle.java
@@ -0,0 +1,12 @@
+package ir.wy.wycore.behind.particle;
+
+import org.bukkit.Location;
+import org.jetbrains.annotations.NotNull;
+
+public interface AvailableParticle {
+
+ void spawn(@NotNull Location location, int amount);
+ default void spawn(@NotNull Location location) {
+ spawn(location, 1);
+ }
+}
diff --git a/src/main/java/ir/wy/wycore/behind/particle/ParticleFactory.java b/src/main/java/ir/wy/wycore/behind/particle/ParticleFactory.java
new file mode 100644
index 0000000..07011c7
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/behind/particle/ParticleFactory.java
@@ -0,0 +1,11 @@
+package ir.wy.wycore.behind.particle;
+
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import java.util.List;
+
+public interface ParticleFactory {
+
+ @NotNull List getNames();
+ @Nullable AvailableParticle create(@NotNull String key);
+}
diff --git a/src/main/java/ir/wy/wycore/behind/particle/main/BaseParticle.java b/src/main/java/ir/wy/wycore/behind/particle/main/BaseParticle.java
new file mode 100644
index 0000000..a82c9be
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/behind/particle/main/BaseParticle.java
@@ -0,0 +1,27 @@
+package ir.wy.wycore.behind.particle.main;
+
+import ir.wy.wycore.behind.particle.AvailableParticle;
+import org.bukkit.Location;
+import org.bukkit.Particle;
+import org.bukkit.World;
+import org.jetbrains.annotations.NotNull;
+
+public final class BaseParticle implements AvailableParticle {
+
+ private final Particle particle;
+
+ public BaseParticle(@NotNull final Particle particle) {
+ this.particle = particle;
+ }
+
+ @Override
+ public void spawn(@NotNull final Location location,
+ final int amount) {
+ World world = location.getWorld();
+
+ if (world == null) {
+ return;
+ }
+ world.spawnParticle(particle, location, amount, 0, 0, 0, 0, null);
+ }
+}
diff --git a/src/main/java/ir/wy/wycore/behind/particle/main/ColoredParticle.kt b/src/main/java/ir/wy/wycore/behind/particle/main/ColoredParticle.kt
new file mode 100644
index 0000000..a9c9af3
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/behind/particle/main/ColoredParticle.kt
@@ -0,0 +1,36 @@
+package ir.wy.wycore.behind.particle.main
+
+import ir.wy.wycore.behind.particle.ParticleFactory
+import ir.wy.wycore.behind.particle.AvailableParticle
+import org.bukkit.Color
+import org.bukkit.Location
+import org.bukkit.Particle
+
+class ColoredParticle : ParticleFactory {
+ override fun getNames() = listOf(
+ "color",
+ "hex",
+ "rgb"
+ )
+
+ override fun create(key: String): AvailableParticle? {
+ val hex = key.toIntOrNull(16) ?: return null
+ val color = try {
+ Color.fromRGB(hex)
+ } catch (e: IllegalArgumentException) {
+ return null
+ }
+
+ return AvailableParticleColor(Particle.DustOptions(color, 1.0f))
+ }
+
+ private class AvailableParticleColor(
+ private val options: Particle.DustOptions
+ ) : AvailableParticle {
+ override fun spawn(location: Location, amount: Int) {
+ val world = location.world ?: return
+
+ world.spawnParticle(Particle.REDSTONE, location, amount, 0.0, 0.0, 0.0, 0.0, options)
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/ir/wy/wycore/behind/particle/main/EmptyParticle.kt b/src/main/java/ir/wy/wycore/behind/particle/main/EmptyParticle.kt
new file mode 100644
index 0000000..6e4fadf
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/behind/particle/main/EmptyParticle.kt
@@ -0,0 +1,10 @@
+package ir.wy.wycore.behind.particle.main
+
+import ir.wy.wycore.behind.particle.AvailableParticle
+import org.bukkit.Location
+
+class EmptyParticle : AvailableParticle {
+ override fun spawn(location: Location, amount: Int) {
+ // lol again nothing lmao
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/ir/wy/wycore/behind/placeholders/EnterablePlaceholder.java b/src/main/java/ir/wy/wycore/behind/placeholders/EnterablePlaceholder.java
new file mode 100644
index 0000000..c321a76
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/behind/placeholders/EnterablePlaceholder.java
@@ -0,0 +1,7 @@
+package ir.wy.wycore.behind.placeholders;
+
+import ir.wy.wycore.WyCore;
+
+public class EnterablePlaceholder {
+ // WIP
+}
diff --git a/src/main/java/ir/wy/wycore/behind/placeholders/Placeholder.java b/src/main/java/ir/wy/wycore/behind/placeholders/Placeholder.java
new file mode 100644
index 0000000..1f1f4a7
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/behind/placeholders/Placeholder.java
@@ -0,0 +1,6 @@
+package ir.wy.wycore.behind.placeholders;
+
+import ir.wy.wycore.WyCore;
+
+public class Placeholder {
+}
diff --git a/src/main/java/ir/wy/wycore/behind/proxy/ProxyFactory.kt b/src/main/java/ir/wy/wycore/behind/proxy/ProxyFactory.kt
new file mode 100644
index 0000000..0d004f0
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/behind/proxy/ProxyFactory.kt
@@ -0,0 +1,5 @@
+package ir.wy.wycore.behind.proxy
+
+interface ProxyFactory {
+ fun getProxy(proxyClass: Class): T
+}
\ No newline at end of file
diff --git a/src/main/java/ir/wy/wycore/behind/proxy/Versions.kt b/src/main/java/ir/wy/wycore/behind/proxy/Versions.kt
new file mode 100644
index 0000000..097081d
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/behind/proxy/Versions.kt
@@ -0,0 +1,22 @@
+package ir.wy.wycore.behind.proxy
+
+import org.bukkit.Bukkit
+import java.util.*
+
+open class Versions private constructor() {
+ init {
+ throw UnsupportedOperationException("This is a utility class and cannot be instantiated")
+ }
+
+ companion object {
+ val NMS_VERSION =
+ Bukkit.getServer().javaClass.getPackage().name.split("\\.".toRegex()).dropLastWhile { it.isEmpty() }
+ .toTypedArray()[3]
+ val SUPPORTED_VERSIONS = Arrays.asList( // i dont like to support other nms versions, maybe 1.16.5 at least
+ "v1_17_R1",
+ "v1_18_R1",
+ "v1_18_R2",
+ "v1_19_R1"
+ )
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/ir/wy/wycore/behind/proxy/errors/ProxyExcp.java b/src/main/java/ir/wy/wycore/behind/proxy/errors/ProxyExcp.java
new file mode 100644
index 0000000..82c0d32
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/behind/proxy/errors/ProxyExcp.java
@@ -0,0 +1,10 @@
+package ir.wy.wycore.behind.proxy.errors;
+
+import org.jetbrains.annotations.NotNull;
+
+public class ProxyExcp extends Error {
+
+ public ProxyExcp(@NotNull final String message, @NotNull final Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/src/main/java/ir/wy/wycore/behind/support/afk/AFKManager.java b/src/main/java/ir/wy/wycore/behind/support/afk/AFKManager.java
new file mode 100644
index 0000000..890f574
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/behind/support/afk/AFKManager.java
@@ -0,0 +1,31 @@
+package ir.wy.wycore.behind.support.afk;
+
+import ir.wy.wycore.behind.support.afk.AFKSupport;
+import org.bukkit.entity.Player;
+import org.jetbrains.annotations.NotNull;
+import java.util.HashSet;
+import java.util.Set;
+
+public final class AFKManager {
+
+ private static final Set REGISTERED = new HashSet<>();
+
+ public static void register(@NotNull final AFKSupport support) {
+ REGISTERED.removeIf(it -> it.getPluginName().equalsIgnoreCase(support.getPluginName()));
+ REGISTERED.add(support);
+ }
+
+ public static boolean isAfk(@NotNull final Player player) {
+ for (AFKSupport integration : REGISTERED) {
+ if (integration.isAfk(player)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ private AFKManager() {
+ throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
+ }
+}
diff --git a/src/main/java/ir/wy/wycore/behind/support/afk/AFKSupport.java b/src/main/java/ir/wy/wycore/behind/support/afk/AFKSupport.java
new file mode 100644
index 0000000..252e561
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/behind/support/afk/AFKSupport.java
@@ -0,0 +1,10 @@
+package ir.wy.wycore.behind.support.afk;
+
+import ir.wy.wycore.spigot.support.Support;
+import org.bukkit.entity.Player;
+import org.jetbrains.annotations.NotNull;
+
+public interface AFKSupport extends Support {
+
+ boolean isAfk(@NotNull Player player);
+}
diff --git a/src/main/java/ir/wy/wycore/behind/support/anticheat/AntiCheatManager.java b/src/main/java/ir/wy/wycore/behind/support/anticheat/AntiCheatManager.java
new file mode 100644
index 0000000..f877731
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/behind/support/anticheat/AntiCheatManager.java
@@ -0,0 +1,25 @@
+package ir.wy.wycore.behind.support.anticheat;
+
+import ir.wy.wycore.behind.support.anticheat.AntiCheatSupport;
+import org.bukkit.entity.Player;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class AntiCheatManager {
+
+ private static final Set ANTICHEATS = new HashSet<>();
+
+ public static void exemptPlayer(@NotNull final Player player) {
+ ANTICHEATS.forEach(anticheat -> anticheat.exempt(player));
+ }
+
+ public static void unexemptPlayer(@NotNull final Player player) {
+ ANTICHEATS.forEach(anticheat -> anticheat.unexempt(player));
+ }
+
+ private AntiCheatManager() {
+ throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
+ }
+}
diff --git a/src/main/java/ir/wy/wycore/behind/support/anticheat/AntiCheatSupport.java b/src/main/java/ir/wy/wycore/behind/support/anticheat/AntiCheatSupport.java
new file mode 100644
index 0000000..33d5bb4
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/behind/support/anticheat/AntiCheatSupport.java
@@ -0,0 +1,11 @@
+package ir.wy.wycore.behind.support.anticheat;
+
+import ir.wy.wycore.spigot.support.Support;
+import org.bukkit.entity.Player;
+import org.jetbrains.annotations.NotNull;
+
+public interface AntiCheatSupport extends Support {
+ void exempt(@NotNull Player player);
+
+ void unexempt(@NotNull Player player);
+}
diff --git a/src/main/java/ir/wy/wycore/behind/support/hologram/EmptyHologram.kt b/src/main/java/ir/wy/wycore/behind/support/hologram/EmptyHologram.kt
new file mode 100644
index 0000000..7385bb5
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/behind/support/hologram/EmptyHologram.kt
@@ -0,0 +1,11 @@
+package ir.wy.wycore.behind.support.hologram
+
+class EmptyHologram : Hologram {
+ override fun remove() {
+ // Nothing
+ }
+
+ override fun setContents(contents: List) {
+ // Nothing
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/ir/wy/wycore/behind/support/hologram/Hologram.java b/src/main/java/ir/wy/wycore/behind/support/hologram/Hologram.java
new file mode 100644
index 0000000..1f8cb57
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/behind/support/hologram/Hologram.java
@@ -0,0 +1,11 @@
+package ir.wy.wycore.behind.support.hologram;
+
+import org.jetbrains.annotations.NotNull;
+import java.util.List;
+
+public interface Hologram {
+
+ void remove();
+
+ void setContents(@NotNull List contents);
+}
diff --git a/src/main/java/ir/wy/wycore/behind/support/hologram/HologramManager.java b/src/main/java/ir/wy/wycore/behind/support/hologram/HologramManager.java
new file mode 100644
index 0000000..3b57676
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/behind/support/hologram/HologramManager.java
@@ -0,0 +1,29 @@
+package ir.wy.wycore.behind.support.hologram;
+
+import org.bukkit.Location;
+import org.jetbrains.annotations.NotNull;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+public final class HologramManager {
+
+ private static final Set REGISTERED = new HashSet<>();
+
+ private static void register (@NotNull final HologramSupport support) {
+ REGISTERED.removeIf(it -> it.getPluginName().equalsIgnoreCase(support.getPluginName()));
+ REGISTERED.add(support);
+ }
+
+ //
+ // private static Hologram createHologram(@NotNull final Location location, @NotNull final List contents) {
+ // for (HologramSupport support : REGISTERED) {
+ // return support.createHologram(location, contents);
+ // }
+ // return new EmptyHologram();
+ // }
+
+ private HologramManager() {
+ throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
+ }
+}
diff --git a/src/main/java/ir/wy/wycore/behind/support/hologram/HologramSupport.java b/src/main/java/ir/wy/wycore/behind/support/hologram/HologramSupport.java
new file mode 100644
index 0000000..c3772b7
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/behind/support/hologram/HologramSupport.java
@@ -0,0 +1,12 @@
+package ir.wy.wycore.behind.support.hologram;
+
+import ir.wy.wycore.spigot.support.Support;
+import org.bukkit.Location;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.List;
+
+public interface HologramSupport extends Support {
+
+ Hologram createHologram(@NotNull Location location, @NotNull List contents);
+}
diff --git a/src/main/java/ir/wy/wycore/behind/support/placeholder/PlaceholderSupport.java b/src/main/java/ir/wy/wycore/behind/support/placeholder/PlaceholderSupport.java
new file mode 100644
index 0000000..e2138a9
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/behind/support/placeholder/PlaceholderSupport.java
@@ -0,0 +1,18 @@
+package ir.wy.wycore.behind.support.placeholder;
+
+import ir.wy.wycore.spigot.support.Support;
+import org.bukkit.entity.Player;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import java.util.ArrayList;
+import java.util.List;
+
+public interface PlaceholderSupport extends Support {
+ void registerSupport();
+
+ String translate(@NotNull String text, @Nullable Player player);
+
+ default List findPlaceholdersIn(@NotNull String text) {
+ return new ArrayList<>();
+ }
+}
diff --git a/src/main/java/ir/wy/wycore/exception/Exception.java b/src/main/java/ir/wy/wycore/exception/Exception.java
new file mode 100644
index 0000000..c40b2ea
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/exception/Exception.java
@@ -0,0 +1,31 @@
+package ir.wy.wycore.exception;
+
+import lombok.Getter;
+import lombok.Setter;
+
+@Deprecated
+public class Exception extends RuntimeException {
+
+ private static final long serialVersionUID = 1L;
+
+ @Getter
+ @Setter
+ private static boolean errorSavedAutomatically = true;
+
+ public Exception(String t) {
+ super(t);
+ }
+
+ public Exception(String message, Throwable t) {
+ this(t, message);
+ }
+
+ public Exception(Throwable t, String message) {
+ super(message, t);
+ }
+
+ @Override
+ public String getMessage() {
+ return "LOG " + super.getMessage();
+ }
+}
diff --git a/src/main/java/ir/wy/wycore/server/LockingDown.kt b/src/main/java/ir/wy/wycore/server/LockingDown.kt
new file mode 100644
index 0000000..1a11366
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/server/LockingDown.kt
@@ -0,0 +1,28 @@
+package ir.wy.wycore.server
+
+import org.bukkit.event.EventHandler
+import org.bukkit.event.Listener
+import org.bukkit.event.player.PlayerLoginEvent
+
+class LockingDown : Listener {
+ private var lockReason: String? = null
+
+ @Suppress("DEPRECATION")
+ @EventHandler
+ fun handle(event: PlayerLoginEvent) {
+ if (lockReason != null) {
+ event.disallow(
+ PlayerLoginEvent.Result.KICK_OTHER,
+ lockReason!!
+ )
+ }
+ }
+
+ fun lock(reason: String) {
+ lockReason = reason
+ }
+
+ fun unlock() {
+ lockReason = null
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/ir/wy/wycore/DefaultFontInfo.java b/src/main/java/ir/wy/wycore/spigot/DefaultFontInfo.java
similarity index 98%
rename from src/main/java/ir/wy/wycore/DefaultFontInfo.java
rename to src/main/java/ir/wy/wycore/spigot/DefaultFontInfo.java
index e3aae40..5d08dac 100644
--- a/src/main/java/ir/wy/wycore/DefaultFontInfo.java
+++ b/src/main/java/ir/wy/wycore/spigot/DefaultFontInfo.java
@@ -1,4 +1,4 @@
-package ir.wy.wycore;
+package ir.wy.wycore.spigot;
public enum DefaultFontInfo {
@@ -107,6 +107,13 @@ public enum DefaultFontInfo {
this.length = length;
}
+ public static DefaultFontInfo getDefaultFontInfo(char c) {
+ for (DefaultFontInfo dFI : DefaultFontInfo.values()) {
+ if (dFI.getCharacter() == c) return dFI;
+ }
+ return DefaultFontInfo.DEFAULT;
+ }
+
public char getCharacter() {
return this.character;
}
@@ -119,11 +126,4 @@ public int getBoldLength() {
if (this == DefaultFontInfo.SPACE) return this.getLength();
return this.length + 1;
}
-
- public static DefaultFontInfo getDefaultFontInfo(char c) {
- for (DefaultFontInfo dFI : DefaultFontInfo.values()) {
- if (dFI.getCharacter() == c) return dFI;
- }
- return DefaultFontInfo.DEFAULT;
- }
}
diff --git a/src/main/java/ir/wy/wycore/Design.java b/src/main/java/ir/wy/wycore/spigot/Design.java
similarity index 94%
rename from src/main/java/ir/wy/wycore/Design.java
rename to src/main/java/ir/wy/wycore/spigot/Design.java
index 3dd7e50..2ee460e 100644
--- a/src/main/java/ir/wy/wycore/Design.java
+++ b/src/main/java/ir/wy/wycore/spigot/Design.java
@@ -1,7 +1,8 @@
-package ir.wy.wycore;
+package ir.wy.wycore.spigot;
import com.cryptomorin.xseries.XMaterial;
import lombok.NoArgsConstructor;
+
import java.util.Collections;
import java.util.Map;
diff --git a/src/main/java/ir/wy/wycore/Heart.java b/src/main/java/ir/wy/wycore/spigot/Heart.java
similarity index 99%
rename from src/main/java/ir/wy/wycore/Heart.java
rename to src/main/java/ir/wy/wycore/spigot/Heart.java
index 44fba6d..fc9c886 100644
--- a/src/main/java/ir/wy/wycore/Heart.java
+++ b/src/main/java/ir/wy/wycore/spigot/Heart.java
@@ -1,4 +1,4 @@
-package ir.wy.wycore;
+package ir.wy.wycore.spigot;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
@@ -7,9 +7,8 @@
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
-// Java Imports
-import java.io.IOException;
import java.io.File;
+import java.io.IOException;
import java.lang.reflect.Type;
public class Heart {
diff --git a/src/main/java/ir/wy/wycore/Item.java b/src/main/java/ir/wy/wycore/spigot/Item.java
similarity index 98%
rename from src/main/java/ir/wy/wycore/Item.java
rename to src/main/java/ir/wy/wycore/spigot/Item.java
index 305fb77..ecbb662 100644
--- a/src/main/java/ir/wy/wycore/Item.java
+++ b/src/main/java/ir/wy/wycore/spigot/Item.java
@@ -1,7 +1,8 @@
-package ir.wy.wycore;
+package ir.wy.wycore.spigot;
import com.cryptomorin.xseries.XMaterial;
import lombok.NoArgsConstructor;
+
import java.util.List;
import java.util.UUID;
diff --git a/src/main/java/ir/wy/wycore/JavaUtils.java b/src/main/java/ir/wy/wycore/spigot/JavaUtils.java
similarity index 79%
rename from src/main/java/ir/wy/wycore/JavaUtils.java
rename to src/main/java/ir/wy/wycore/spigot/JavaUtils.java
index fbc2c57..a2a30e4 100644
--- a/src/main/java/ir/wy/wycore/JavaUtils.java
+++ b/src/main/java/ir/wy/wycore/spigot/JavaUtils.java
@@ -1,4 +1,4 @@
-package ir.wy.wycore;
+package ir.wy.wycore.spigot;
import org.bukkit.plugin.java.JavaPlugin;
diff --git a/src/main/java/ir/wy/wycore/spigot/Versions.java b/src/main/java/ir/wy/wycore/spigot/Versions.java
new file mode 100644
index 0000000..261e314
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/spigot/Versions.java
@@ -0,0 +1,119 @@
+package ir.wy.wycore.spigot;
+
+import ir.wy.wycore.exception.Exception;
+import lombok.Getter;
+import org.bukkit.Bukkit;
+
+public final class Versions {
+
+ private static String serverVersion;
+
+ @Getter
+ private static Ver current;
+
+ static {
+ try {
+ final String packageName = Bukkit.getServer() == null ? "" : Bukkit.getServer().getClass().getPackage().getName();
+ final String curr = packageName.substring(packageName.lastIndexOf('.') + 1);
+ final boolean hasGatekeeper = !"craftbukkit".equals(curr) && !"".equals(packageName);
+
+ serverVersion = curr;
+
+ if (hasGatekeeper) {
+ int pos = 0;
+
+ for (final char channel : curr.toCharArray()) {
+ pos++;
+ if (pos > 2 && channel == 'R') {
+ break;
+ }
+
+ final String numericVersion = curr.substring(1, pos - 2).replace("_", ".");
+ int found = 0;
+
+ for (final char ch : numericVersion.toCharArray())
+ if (ch == '.')
+ found++;
+
+ current = Ver.parse(Integer.parseInt(numericVersion.split("\\.")[1]));
+ }
+ } else
+ current = Ver.ver1_6_LOWER;
+ } catch (NumberFormatException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private static int compareWith(Ver ver) {
+ try {
+ return getCurrent().minorVersionNumber - ver.minorVersionNumber;
+ } catch (final Throwable t) {
+ t.printStackTrace();
+ return 0;
+ }
+ }
+
+ public static boolean equals(Ver ver) {
+ return compareWith(ver) == 0;
+ }
+
+ public static boolean newer(Ver ver) {
+ return compareWith(ver) > 0;
+ }
+
+ public static boolean atLeast(Ver ver) {
+ return equals(ver) || newer(ver);
+ }
+
+ public static String getServerVersion() {
+ return serverVersion.equals("craftbukkit") ? "" : serverVersion;
+ }
+
+ public enum Ver {
+ ver1_6_LOWER(6),
+ ver1_7(7),
+ ver1_8(8),
+ ver1_9(9),
+ ver1_10(10),
+ ver1_11(11),
+ ver1_12(12),
+ ver1_13(13),
+ ver1_14(14),
+ ver1_15(15),
+ ver1_16(16),
+ ver1_17(17),
+ ver1_18(18),
+ ver1_19(19);
+
+ private final int minorVersionNumber;
+
+ @Getter
+ private final boolean tested;
+
+ Ver(int version) {
+ this(version, true);
+ }
+
+ Ver(int version, boolean tested) {
+ this.minorVersionNumber = version;
+ this.tested = tested;
+ }
+
+ protected static Ver parse(int number) {
+ for (final Ver v : values())
+ if (v.minorVersionNumber == number)
+ return v;
+
+ throw new Exception("Invalid version number: " + number);
+ }
+
+ /**
+ * @see java.lang.Enum#toString()
+ */
+ @Override
+ public String toString() {
+ return "1." + this.minorVersionNumber;
+ }
+ }
+
+}
diff --git a/src/main/java/ir/wy/wycore/spigot/chat/ChatInforms.java b/src/main/java/ir/wy/wycore/spigot/chat/ChatInforms.java
new file mode 100644
index 0000000..b2c053d
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/spigot/chat/ChatInforms.java
@@ -0,0 +1,171 @@
+package ir.wy.wycore.spigot.chat;
+
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.Listener;
+import org.bukkit.event.player.AsyncPlayerChatEvent;
+import org.bukkit.event.player.PlayerCommandPreprocessEvent;
+import org.bukkit.plugin.Plugin;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+import java.util.logging.Level;
+
+public class ChatInforms implements Listener {
+ private static final List registered = new ArrayList<>();
+
+ private final Plugin plugin;
+ private final ChatConfirmHandler handler;
+ private int taskId;
+ private OnClose onClose = null;
+ private OnCancel onCancel = null;
+ private Listener listener;
+
+ private ChatInforms(Plugin plugin, Player player, ChatConfirmHandler handler) {
+ this.plugin = plugin;
+ this.handler = handler;
+
+ registered.add(player.getUniqueId());
+ }
+
+ public static ChatInforms showPrompt(Plugin plugin, Player player, ChatConfirmHandler hander) {
+ return showPrompt(plugin, player, null, hander);
+ }
+
+ public static ChatInforms showPrompt(Plugin plugin, Player player, String message, ChatConfirmHandler hander) {
+ ChatInforms prompt = new ChatInforms(plugin, player, hander);
+ prompt.startListener(plugin);
+ player.closeInventory();
+
+ if (message != null) {
+ player.sendMessage(message);
+ }
+
+ return prompt;
+ }
+
+ public static boolean isRegistered(Player player) {
+ return registered.contains(player.getUniqueId());
+ }
+
+ public static boolean unregister(Player player) {
+ return registered.remove(player.getUniqueId());
+ }
+
+ public ChatInforms setOnClose(OnClose onClose) {
+ this.onClose = onClose;
+ return this;
+ }
+
+ public ChatInforms setOnCancel(OnCancel onCancel) {
+ this.onCancel = onCancel;
+ return this;
+ }
+
+ public ChatInforms setTimeOut(Player player, long ticks) {
+ taskId = Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> {
+ if (onClose != null) {
+ plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () ->
+ onClose.onClose(), 0L);
+ }
+
+ HandlerList.unregisterAll(listener);
+ player.sendMessage("Your action has timed out.");
+ }, ticks);
+
+ return this;
+ }
+
+ private void startListener(Plugin plugin) {
+ this.listener = new Listener() {
+ @EventHandler(priority = EventPriority.LOWEST)
+ public void onChat(AsyncPlayerChatEvent event) {
+ Player player = event.getPlayer();
+
+ if (!ChatInforms.isRegistered(player)) {
+ return;
+ }
+
+ ChatInforms.unregister(player);
+ event.setCancelled(true);
+
+ ChatConfirmEvent chatConfirmEvent = new ChatConfirmEvent(player, event.getMessage());
+
+ player.sendMessage("\u00BB " + event.getMessage());
+
+ try {
+ handler.onChat(chatConfirmEvent);
+ } catch (Throwable t) {
+ plugin.getLogger().log(Level.SEVERE, "Failed to process chat prompt", t);
+ }
+
+ if (onClose != null) {
+ plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> onClose.onClose(), 0L);
+ }
+
+ HandlerList.unregisterAll(listener);
+ Bukkit.getScheduler().cancelTask(taskId);
+ }
+
+ @EventHandler(priority = EventPriority.LOWEST)
+ public void onCancel(PlayerCommandPreprocessEvent event) {
+ Player player = event.getPlayer();
+
+ if (!ChatInforms.isRegistered(player)) {
+ return;
+ }
+
+ ChatInforms.unregister(player);
+
+ if (event.getMessage().toLowerCase().startsWith("/cancel")) {
+ event.setCancelled(true);
+ }
+
+ if (onCancel != null) {
+ plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> onCancel.onCancel(), 0L);
+ } else if (onClose != null) {
+ plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> onClose.onClose(), 0L);
+ }
+
+ HandlerList.unregisterAll(listener);
+ Bukkit.getScheduler().cancelTask(taskId);
+ }
+ };
+
+ Bukkit.getPluginManager().registerEvents(listener, plugin);
+ }
+
+ public interface ChatConfirmHandler {
+ void onChat(ChatConfirmEvent event);
+ }
+
+ public interface OnClose {
+ void onClose();
+ }
+
+ public interface OnCancel {
+ void onCancel();
+ }
+
+ public static class ChatConfirmEvent {
+ private final Player player;
+ private final String message;
+
+ public ChatConfirmEvent(Player player, String message) {
+ this.player = player;
+ this.message = message;
+ }
+
+ public Player getPlayer() {
+ return player;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+ }
+}
diff --git a/src/main/java/ir/wy/wycore/spigot/chat/color/ColorCode.java b/src/main/java/ir/wy/wycore/spigot/chat/color/ColorCode.java
new file mode 100644
index 0000000..93d4cff
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/spigot/chat/color/ColorCode.java
@@ -0,0 +1,64 @@
+package ir.wy.wycore.spigot.chat.color;
+
+import org.bukkit.ChatColor;
+import java.util.HashMap;
+import java.util.Map;
+
+public enum ColorCode {
+ BLACK('0', ChatColor.BLACK, true),
+ DARK_BLUE('1', ChatColor.DARK_BLUE, true),
+ DARK_GREEN('2', ChatColor.DARK_GREEN, true),
+ DARK_AQUA('3', ChatColor.DARK_AQUA, true),
+ DARK_RED('4', ChatColor.DARK_RED, true),
+ DARK_PURPLE('5', ChatColor.DARK_PURPLE, true),
+ GOLD('6', ChatColor.GOLD, true),
+ GRAY('7', ChatColor.GRAY, true),
+ DARK_GRAY('8', ChatColor.DARK_GRAY, true),
+ BLUE('9', ChatColor.BLUE, true),
+ GREEN('a', ChatColor.GREEN, true),
+ AQUA('b', ChatColor.AQUA, true),
+ RED('c', ChatColor.RED, true),
+ LIGHT_PURPLE('d', ChatColor.LIGHT_PURPLE, true),
+ YELLOW('e', ChatColor.YELLOW, true),
+ WHITE('f', ChatColor.WHITE, true),
+ OBFUSCATED('k', ChatColor.MAGIC, false),
+ BOLD('l', ChatColor.BOLD, false),
+ STRIKETHROUGH('m', ChatColor.STRIKETHROUGH, false),
+ UNDERLINED('n', ChatColor.UNDERLINE, false),
+ ITALIC('o', ChatColor.ITALIC, false),
+ RESET('r', ChatColor.RESET, false);
+
+ private final char code;
+ private final ChatColor chatColor;
+ private final boolean isColor;
+
+ private static final Map BY_CHAR = new HashMap<>();
+
+ ColorCode(char code, ChatColor chatColor, boolean isColor) {
+ this.code = code;
+ this.chatColor = chatColor;
+ this.isColor = isColor;
+ }
+
+ static {
+ for (ColorCode color : values()) {
+ BY_CHAR.put(color.code, color);
+ }
+ }
+
+ public static ColorCode getByChar(char code) {
+ return BY_CHAR.get(code);
+ }
+
+ public char getCode() {
+ return code;
+ }
+
+ public ChatColor getChatColor() {
+ return chatColor;
+ }
+
+ public boolean isColor() {
+ return this.isColor;
+ }
+}
diff --git a/src/main/java/ir/wy/wycore/spigot/chat/color/ColorSystem.java b/src/main/java/ir/wy/wycore/spigot/chat/color/ColorSystem.java
new file mode 100644
index 0000000..b17b2ca
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/spigot/chat/color/ColorSystem.java
@@ -0,0 +1,5 @@
+package ir.wy.wycore.spigot.chat.color;
+
+public class ColorSystem {
+ // WIP
+}
diff --git a/src/main/java/ir/wy/wycore/gui/BackGUI.java b/src/main/java/ir/wy/wycore/spigot/gui/BackGUI.java
similarity index 81%
rename from src/main/java/ir/wy/wycore/gui/BackGUI.java
rename to src/main/java/ir/wy/wycore/spigot/gui/BackGUI.java
index 59ca2c9..ed5f039 100644
--- a/src/main/java/ir/wy/wycore/gui/BackGUI.java
+++ b/src/main/java/ir/wy/wycore/spigot/gui/BackGUI.java
@@ -1,9 +1,9 @@
-package ir.wy.wycore.gui;
+package ir.wy.wycore.spigot.gui;
-import ir.wy.wycore.Design;
-import ir.wy.wycore.Item;
-import ir.wy.wycore.utils.InventoryUtils;
-import ir.wy.wycore.utils.ItemStackUtils;
+import ir.wy.wycore.spigot.Design;
+import ir.wy.wycore.spigot.Item;
+import ir.wy.wycore.spigot.utils.InventoryUtils;
+import ir.wy.wycore.spigot.utils.ItemStackUtils;
import lombok.AllArgsConstructor;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
diff --git a/src/main/java/ir/wy/wycore/gui/GUI.java b/src/main/java/ir/wy/wycore/spigot/gui/GUI.java
similarity index 89%
rename from src/main/java/ir/wy/wycore/gui/GUI.java
rename to src/main/java/ir/wy/wycore/spigot/gui/GUI.java
index 672e7e1..23f6a4c 100644
--- a/src/main/java/ir/wy/wycore/gui/GUI.java
+++ b/src/main/java/ir/wy/wycore/spigot/gui/GUI.java
@@ -1,4 +1,4 @@
-package ir.wy.wycore.gui;
+package ir.wy.wycore.spigot.gui;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
@@ -6,5 +6,6 @@
public interface GUI extends InventoryHolder {
void onInventoryClick(InventoryClickEvent event);
+
void addContent(Inventory inventory);
}
diff --git a/src/main/java/ir/wy/wycore/gui/PagedGUI.java b/src/main/java/ir/wy/wycore/spigot/gui/PagedGUI.java
similarity index 81%
rename from src/main/java/ir/wy/wycore/gui/PagedGUI.java
rename to src/main/java/ir/wy/wycore/spigot/gui/PagedGUI.java
index e26c154..5867b58 100644
--- a/src/main/java/ir/wy/wycore/gui/PagedGUI.java
+++ b/src/main/java/ir/wy/wycore/spigot/gui/PagedGUI.java
@@ -1,11 +1,9 @@
-package ir.wy.wycore.gui;
-
-import ir.wy.wycore.Design;
-import ir.wy.wycore.Item;
-import ir.wy.wycore.utils.InventoryUtils;
-import ir.wy.wycore.utils.ItemStackUtils;
-
+package ir.wy.wycore.spigot.gui;
+import ir.wy.wycore.spigot.Design;
+import ir.wy.wycore.spigot.Item;
+import ir.wy.wycore.spigot.utils.InventoryUtils;
+import ir.wy.wycore.spigot.utils.ItemStackUtils;
import lombok.AllArgsConstructor;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
@@ -13,8 +11,8 @@
import java.util.Collection;
import java.util.HashMap;
-import java.util.Map;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
@@ -22,7 +20,6 @@
public abstract class PagedGUI implements GUI {
- private int page;
private final int size;
private final Design design;
private final Item previousPage;
@@ -30,6 +27,7 @@ public abstract class PagedGUI implements GUI {
private final Inventory previousInventory;
private final Item backButton;
private final Map items = new HashMap<>();
+ private int page;
public PagedGUI(int page, int size, Design background, Item previousPage, Item nextPage) {
this.page = page;
@@ -99,14 +97,15 @@ public void onInventoryClick(InventoryClickEvent event) {
} else if (previousInventory != null && backButton != null) {
if (event.getSlot() == event.getInventory().getSize() + backButton.slot) {
event.getWhoClicked().openInventory(previousInventory);
+ }
+ } else if (event.getSlot() == getInventory().getSize() - 3) {
+ if ((event.getInventory().getSize() - 9) * page < getPageObjects().size()) {
+ page++;
+ event.getWhoClicked().openInventory(getInventory());
+ }
+ } else if (previousInventory != null && backButton != null && event.getSlot() == (event.getInventory().getSize() + backButton.slot)) {
+ event.getWhoClicked().openInventory(previousInventory);
}
- } else if (event.getSlot() == getInventory().getSize() - 3) {
- if ((event.getInventory().getSize() - 9) * page < getPageObjects().size()) {
- page++;
- event.getWhoClicked().openInventory(getInventory());
- }
- } else if (previousInventory != null && backButton != null && event.getSlot() == (event.getInventory().getSize() + backButton.slot)) {
- event.getWhoClicked().openInventory(previousInventory);
}
}
-}}
+}
diff --git a/src/main/java/ir/wy/wycore/spigot/support/Support.java b/src/main/java/ir/wy/wycore/spigot/support/Support.java
new file mode 100644
index 0000000..f4d1f6d
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/spigot/support/Support.java
@@ -0,0 +1,5 @@
+package ir.wy.wycore.spigot.support;
+
+public interface Support {
+ String getPluginName();
+}
diff --git a/src/main/java/ir/wy/wycore/spigot/support/SupportManager.kt b/src/main/java/ir/wy/wycore/spigot/support/SupportManager.kt
new file mode 100644
index 0000000..eff8cd3
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/spigot/support/SupportManager.kt
@@ -0,0 +1,29 @@
+package ir.wy.wycore.spigot.support
+
+import org.bukkit.Bukkit
+import org.bukkit.plugin.Plugin
+import java.util.*
+import java.util.stream.Collectors
+
+class SupportManager(
+ val pluginName: String,
+ private val runnable: Runnable
+) {
+
+ fun loadIfPresent() {
+ if (LOADED_PLUGINS.contains(pluginName.lowercase(Locale.getDefault()))) {
+ load()
+ }
+ }
+
+ fun load() {
+ runnable.run()
+ }
+
+ companion object {
+ private val LOADED_PLUGINS = Arrays.stream(Bukkit.getPluginManager().plugins)
+ .map { obj: Plugin -> obj.name }
+ .map { obj: String -> obj.lowercase(Locale.getDefault()) }
+ .collect(Collectors.toSet())
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/ir/wy/wycore/spigot/support/afk/CMIAFK.kt b/src/main/java/ir/wy/wycore/spigot/support/afk/CMIAFK.kt
new file mode 100644
index 0000000..c0bca7c
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/spigot/support/afk/CMIAFK.kt
@@ -0,0 +1,15 @@
+package ir.wy.wycore.spigot.support.afk
+
+import com.Zrips.CMI.CMI
+import ir.wy.wycore.behind.support.afk.AFKSupport
+import org.bukkit.entity.Player
+
+class CMIAFK : AFKSupport {
+ override fun getPluginName(): String {
+ return "CMI"
+ }
+
+ override fun isAfk(player: Player): Boolean {
+ return CMI.getInstance().playerManager.getUser(player)?.isAfk ?: false
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/ir/wy/wycore/spigot/support/afk/EssentialsAFK.kt b/src/main/java/ir/wy/wycore/spigot/support/afk/EssentialsAFK.kt
new file mode 100644
index 0000000..c8af041
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/spigot/support/afk/EssentialsAFK.kt
@@ -0,0 +1,18 @@
+package ir.wy.wycore.spigot.support.afk
+
+import com.earth2me.essentials.Essentials
+import ir.wy.wycore.behind.support.afk.AFKSupport
+import org.bukkit.entity.Player
+import org.bukkit.plugin.java.JavaPlugin
+
+class EssentialsAFK : AFKSupport {
+ private val ess = JavaPlugin.getPlugin(Essentials::class.java)
+
+ override fun isAfk(player: Player): Boolean {
+ return ess.getUser(player) != null && ess.getUser(player).isAfk
+ }
+
+ override fun getPluginName(): String {
+ return "Essentials"
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/ir/wy/wycore/spigot/support/anticheat/AACAntiCheat.kt b/src/main/java/ir/wy/wycore/spigot/support/anticheat/AACAntiCheat.kt
new file mode 100644
index 0000000..71ebd8e
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/spigot/support/anticheat/AACAntiCheat.kt
@@ -0,0 +1,26 @@
+package ir.wy.wycore.spigot.support.anticheat
+
+
+import ir.wy.wycore.behind.support.anticheat.AntiCheatSupport
+import me.konsolas.aac.api.AACExemption;
+import me.konsolas.aac.api.AACAPI
+import org.bukkit.Bukkit
+import org.bukkit.entity.Player
+import org.bukkit.event.Listener
+
+class AACAntiCheat : AntiCheatSupport, Listener {
+ private val wyAACExemption = AACExemption("wy")
+ private val api = Bukkit.getServicesManager().load(AACAPI::class.java)!!
+
+ override fun getPluginName(): String {
+ return "AAC"
+ }
+
+ override fun exempt(player: Player) {
+ api.addExemption(player, wyAACExemption)
+ }
+
+ override fun unexempt(player: Player) {
+ api.removeExemption(player, wyAACExemption)
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/ir/wy/wycore/spigot/support/anticheat/EchoAntiCheat.kt b/src/main/java/ir/wy/wycore/spigot/support/anticheat/EchoAntiCheat.kt
new file mode 100644
index 0000000..e542b4d
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/spigot/support/anticheat/EchoAntiCheat.kt
@@ -0,0 +1,5 @@
+package ir.wy.wycore.spigot.support.anticheat
+
+class EchoAntiCheat {
+ // WIP
+}
\ No newline at end of file
diff --git a/src/main/java/ir/wy/wycore/spigot/support/anticheat/GrimAntiCheat.kt b/src/main/java/ir/wy/wycore/spigot/support/anticheat/GrimAntiCheat.kt
new file mode 100644
index 0000000..9f64f6d
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/spigot/support/anticheat/GrimAntiCheat.kt
@@ -0,0 +1,33 @@
+package ir.wy.wycore.spigot.support.anticheat
+
+import ac.grim.grimac.events.FlagEvent;
+import ir.wy.wycore.behind.support.anticheat.AntiCheatSupport
+import org.bukkit.entity.Player
+import org.bukkit.event.EventHandler
+import org.bukkit.event.EventPriority
+import org.bukkit.event.Listener
+import java.util.UUID
+
+class GrimAntiCheat : AntiCheatSupport, Listener{
+ private val exempt: MutableSet = HashSet()
+ override fun getPluginName(): String {
+ return "Grim"
+ }
+
+ override fun exempt(player: Player) {
+ exempt.add(player.uniqueId)
+ }
+
+ override fun unexempt(player: Player) {
+ exempt.remove(player.uniqueId)
+ }
+
+ @EventHandler(priority = EventPriority.LOWEST)
+ private fun onViolate(event: FlagEvent) {
+ if (!exempt.contains(event.player.uniqueId)) {
+ return
+ }
+ event.isCancelled = true
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/ir/wy/wycore/spigot/support/anticheat/IntaveAntiCheat.kt b/src/main/java/ir/wy/wycore/spigot/support/anticheat/IntaveAntiCheat.kt
new file mode 100644
index 0000000..ba6a4a7
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/spigot/support/anticheat/IntaveAntiCheat.kt
@@ -0,0 +1,4 @@
+package ir.wy.wycore.spigot.support.anticheat
+
+class IntaveAntiCheat {
+}
\ No newline at end of file
diff --git a/src/main/java/ir/wy/wycore/spigot/support/anticheat/NoCheatPlusAntiCheat.kt b/src/main/java/ir/wy/wycore/spigot/support/anticheat/NoCheatPlusAntiCheat.kt
new file mode 100644
index 0000000..372c92b
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/spigot/support/anticheat/NoCheatPlusAntiCheat.kt
@@ -0,0 +1,5 @@
+package ir.wy.wycore.spigot.support.anticheat
+
+class NoCheatPlusAntiCheat {
+ // WIP
+}
\ No newline at end of file
diff --git a/src/main/java/ir/wy/wycore/spigot/support/anticheat/SparkyAntiCheat.kt b/src/main/java/ir/wy/wycore/spigot/support/anticheat/SparkyAntiCheat.kt
new file mode 100644
index 0000000..ea6c262
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/spigot/support/anticheat/SparkyAntiCheat.kt
@@ -0,0 +1,33 @@
+package ir.wy.wycore.spigot.support.anticheat
+
+
+import ac.sparky.api.events.SparkyViolationEvent
+import ir.wy.wycore.behind.support.anticheat.AntiCheatSupport
+import org.bukkit.entity.Player
+import org.bukkit.event.EventHandler
+import org.bukkit.event.EventPriority
+import org.bukkit.event.Listener
+import java.util.UUID
+
+class SparkyAntiCheat : AntiCheatSupport, Listener {
+ private val exempt: MutableSet = HashSet()
+ override fun getPluginName(): String {
+ return "Sparky"
+ }
+
+ override fun exempt(player: Player) {
+ exempt.add(player.uniqueId)
+ }
+
+ override fun unexempt(player: Player) {
+ exempt.remove(player.uniqueId)
+ }
+
+ @EventHandler(priority = EventPriority.LOWEST)
+ private fun onViolate(event: SparkyViolationEvent) {
+ if (!exempt.contains(event.player.uniqueId)) {
+ return
+ }
+ event.isCancelled = true
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/ir/wy/wycore/spigot/support/anticheat/SpartanAntiCheat.kt b/src/main/java/ir/wy/wycore/spigot/support/anticheat/SpartanAntiCheat.kt
new file mode 100644
index 0000000..cfbf25d
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/spigot/support/anticheat/SpartanAntiCheat.kt
@@ -0,0 +1,32 @@
+package ir.wy.wycore.spigot.support.anticheat
+
+import ir.wy.wycore.behind.support.anticheat.AntiCheatSupport
+import me.vagdedes.spartan.api.PlayerViolationEvent
+import org.bukkit.entity.Player
+import org.bukkit.event.EventHandler
+import org.bukkit.event.EventPriority
+import org.bukkit.event.Listener
+import java.util.UUID
+
+class SpartanAntiCheat : AntiCheatSupport, Listener {
+ private val exempt: MutableSet = HashSet()
+ override fun getPluginName(): String {
+ return "Spartan"
+ }
+
+ override fun exempt(player: Player) {
+ exempt.add(player.uniqueId)
+ }
+
+ override fun unexempt(player: Player) {
+ exempt.remove(player.uniqueId)
+ }
+
+ @EventHandler(priority = EventPriority.LOWEST)
+ private fun onViolate(event: PlayerViolationEvent) {
+ if (!exempt.contains(event.player.uniqueId)) {
+ return
+ }
+ event.isCancelled = true
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/ir/wy/wycore/spigot/support/anticheat/VulcanAntiCheat.kt b/src/main/java/ir/wy/wycore/spigot/support/anticheat/VulcanAntiCheat.kt
new file mode 100644
index 0000000..8293f57
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/spigot/support/anticheat/VulcanAntiCheat.kt
@@ -0,0 +1,32 @@
+package ir.wy.wycore.spigot.support.anticheat
+
+import ir.wy.wycore.behind.support.anticheat.AntiCheatSupport
+import me.frep.vulcan.api.event.VulcanFlagEvent
+import org.bukkit.entity.Player
+import org.bukkit.event.EventHandler
+import org.bukkit.event.EventPriority
+import org.bukkit.event.Listener
+import java.util.UUID
+
+class VulcanAntiCheat : AntiCheatSupport, Listener {
+ private val exempt: MutableSet = HashSet()
+ override fun getPluginName(): String {
+ return "Vulcan"
+ }
+
+ override fun exempt(player: Player) {
+ exempt.add(player.uniqueId)
+ }
+
+ override fun unexempt(player: Player) {
+ exempt.remove(player.uniqueId)
+ }
+
+ @EventHandler(priority = EventPriority.LOWEST)
+ private fun onViolate(event: VulcanFlagEvent) {
+ if (!exempt.contains(event.player.uniqueId)) {
+ return
+ }
+ event.isCancelled = true
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/ir/wy/wycore/spigot/support/hologram/CMIHologram.kt b/src/main/java/ir/wy/wycore/spigot/support/hologram/CMIHologram.kt
new file mode 100644
index 0000000..1d4ce7d
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/spigot/support/hologram/CMIHologram.kt
@@ -0,0 +1,41 @@
+package ir.wy.wycore.spigot.support.hologram
+
+import com.Zrips.CMI.CMI
+import com.Zrips.CMI.Modules.Holograms.CMIHologram
+import ir.wy.wycore.behind.support.hologram.Hologram
+import ir.wy.wycore.behind.support.hologram.HologramSupport
+import net.Zrips.CMILib.Container.CMILocation
+import org.bukkit.Location
+import java.util.UUID
+
+@Suppress("DEPRECATION")
+class CMIHologram : HologramSupport {
+
+ override fun createHologram(location: Location, contents: MutableList): Hologram {
+ val cmiHolo = CMIHologram(UUID.randomUUID().toString(), CMILocation(location))
+ CMI.getInstance().hologramManager.addHologram(cmiHolo)
+
+ val holo = HologramImplCMI(cmiHolo)
+ holo.setContents(contents)
+
+ cmiHolo.enable()
+
+ return holo
+ }
+
+ override fun getPluginName(): String {
+ return "CMI"
+ }
+
+ class HologramImplCMI(
+ private val handle: CMIHologram
+ ) : Hologram {
+ override fun remove() {
+ CMI.getInstance().hologramManager.removeHolo(handle)
+ }
+
+ override fun setContents(contents: MutableList) {
+ handle.lines = contents
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/ir/wy/wycore/spigot/support/hologram/DecentHologram.kt b/src/main/java/ir/wy/wycore/spigot/support/hologram/DecentHologram.kt
new file mode 100644
index 0000000..7e32cc0
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/spigot/support/hologram/DecentHologram.kt
@@ -0,0 +1,33 @@
+package ir.wy.wycore.spigot.support.hologram
+
+import eu.decentsoftware.holograms.api.DHAPI
+import ir.wy.wycore.behind.support.hologram.Hologram
+import ir.wy.wycore.behind.support.hologram.HologramSupport
+import org.bukkit.Location
+import java.util.UUID
+
+class DecentHologram : HologramSupport {
+ override fun createHologram(location: Location, contents: MutableList): Hologram {
+ val id = UUID.randomUUID().toString()
+
+ DHAPI.createHologram(id, location, contents)
+
+ return HologramImplDecentHolograms(id)
+ }
+
+ override fun getPluginName(): String {
+ return "DecentHolograms"
+ }
+
+ class HologramImplDecentHolograms(
+ private val id: String,
+ ) : Hologram {
+ override fun remove() {
+ DHAPI.getHologram(id)?.destroy()
+ }
+
+ override fun setContents(contents: MutableList) {
+ DHAPI.setHologramLines(DHAPI.getHologram(id), contents)
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/ir/wy/wycore/spigot/support/hologram/HolographicDisplaysHologram.kt b/src/main/java/ir/wy/wycore/spigot/support/hologram/HolographicDisplaysHologram.kt
new file mode 100644
index 0000000..d18f40f
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/spigot/support/hologram/HolographicDisplaysHologram.kt
@@ -0,0 +1,6 @@
+package ir.wy.wycore.spigot.support.hologram
+
+class HolographicDisplaysHologram {
+ // WIP
+}
+
diff --git a/src/main/java/ir/wy/wycore/spigot/support/placeholder/PAPISupport.kt b/src/main/java/ir/wy/wycore/spigot/support/placeholder/PAPISupport.kt
new file mode 100644
index 0000000..c312302
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/spigot/support/placeholder/PAPISupport.kt
@@ -0,0 +1,31 @@
+package ir.wy.wycore.spigot.support.placeholder
+
+import ir.wy.wycore.behind.support.placeholder.PlaceholderSupport
+import me.clip.placeholderapi.PlaceholderAPI
+import org.bukkit.entity.Player
+import java.util.regex.Pattern
+
+class PAPISupport : PlaceholderSupport {
+ private val pattern = Pattern.compile("[%]([^% ]+)[%]")
+
+ override fun registerSupport() {
+ // - lmao nothing
+ }
+
+ override fun getPluginName(): String {
+ return "PlaceholderAPI"
+ }
+
+ override fun translate(text: String, player: Player?): String {
+ return PlaceholderAPI.setPlaceholders(player, text)
+ }
+
+ override fun findPlaceholdersIn(text: String): MutableList {
+ val placeholders = mutableListOf()
+ val matcher = pattern.matcher(text)
+ while (matcher.find()) {
+ placeholders.add(matcher.group())
+ }
+ return placeholders
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/ir/wy/wycore/spigot/utils/DiscordWebhook.java b/src/main/java/ir/wy/wycore/spigot/utils/DiscordWebhook.java
new file mode 100644
index 0000000..c5aab54
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/spigot/utils/DiscordWebhook.java
@@ -0,0 +1,390 @@
+package ir.wy.wycore.spigot.utils;
+
+import javax.net.ssl.HttpsURLConnection;
+import java.awt.*;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.reflect.Array;
+import java.net.URL;
+import java.util.List;
+import java.util.*;
+
+/*
+ * Java DiscordWebhook class to easily execute Discord Webhooks
+ * Created by: k3kdude
+ * Source: https://gist.github.com/k3kdude/fba6f6b37594eae3d6f9475330733bdb
+ */
+
+public class DiscordWebhook {
+ private final String url;
+ private String content;
+ private String username;
+ private String avatarUrl;
+ private boolean tts;
+ private List embeds = new ArrayList<>();
+
+ /**
+ * Constructs a new DiscordWebhook instance
+ *
+ * @param url The webhook URL obtained in Discord
+ */
+ public DiscordWebhook(String url) {
+ this.url = url;
+ }
+
+ public void setContent(String content) {
+ this.content = content;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public void setAvatarUrl(String avatarUrl) {
+ this.avatarUrl = avatarUrl;
+ }
+
+ public void setTts(boolean tts) {
+ this.tts = tts;
+ }
+
+ public void addEmbed(EmbedObject embed) {
+ this.embeds.add(embed);
+ }
+
+ public void execute() throws IOException {
+ if (this.content == null && this.embeds.isEmpty()) {
+ throw new IllegalArgumentException("Set content or add at least one EmbedObject");
+ }
+
+ JSONObject json = new JSONObject();
+
+ json.put("content", this.content);
+ json.put("username", this.username);
+ json.put("avatar_url", this.avatarUrl);
+ json.put("tts", this.tts);
+
+ if (!this.embeds.isEmpty()) {
+ List embedObjects = new ArrayList<>();
+
+ for (EmbedObject embed : this.embeds) {
+ JSONObject jsonEmbed = new JSONObject();
+
+ jsonEmbed.put("title", embed.getTitle());
+ jsonEmbed.put("description", embed.getDescription());
+ jsonEmbed.put("url", embed.getUrl());
+
+ if (embed.getColor() != null) {
+ Color color = embed.getColor();
+ int rgb = color.getRed();
+ rgb = (rgb << 8) + color.getGreen();
+ rgb = (rgb << 8) + color.getBlue();
+
+ jsonEmbed.put("color", rgb);
+ }
+
+ EmbedObject.Footer footer = embed.getFooter();
+ EmbedObject.Image image = embed.getImage();
+ EmbedObject.Thumbnail thumbnail = embed.getThumbnail();
+ EmbedObject.Author author = embed.getAuthor();
+ List fields = embed.getFields();
+
+ if (footer != null) {
+ JSONObject jsonFooter = new JSONObject();
+
+ jsonFooter.put("text", footer.getText());
+ jsonFooter.put("icon_url", footer.getIconUrl());
+ jsonEmbed.put("footer", jsonFooter);
+ }
+
+ if (image != null) {
+ JSONObject jsonImage = new JSONObject();
+
+ jsonImage.put("url", image.getUrl());
+ jsonEmbed.put("image", jsonImage);
+ }
+
+ if (thumbnail != null) {
+ JSONObject jsonThumbnail = new JSONObject();
+
+ jsonThumbnail.put("url", thumbnail.getUrl());
+ jsonEmbed.put("thumbnail", jsonThumbnail);
+ }
+
+ if (author != null) {
+ JSONObject jsonAuthor = new JSONObject();
+
+ jsonAuthor.put("name", author.getName());
+ jsonAuthor.put("url", author.getUrl());
+ jsonAuthor.put("icon_url", author.getIconUrl());
+ jsonEmbed.put("author", jsonAuthor);
+ }
+
+ List jsonFields = new ArrayList<>();
+ for (EmbedObject.Field field : fields) {
+ JSONObject jsonField = new JSONObject();
+
+ jsonField.put("name", field.getName());
+ jsonField.put("value", field.getValue());
+ jsonField.put("inline", field.isInline());
+
+ jsonFields.add(jsonField);
+ }
+
+ jsonEmbed.put("fields", jsonFields.toArray());
+ embedObjects.add(jsonEmbed);
+ }
+
+ json.put("embeds", embedObjects.toArray());
+ }
+
+ URL url = new URL(this.url);
+ HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
+ connection.addRequestProperty("Content-Type", "application/json");
+ connection.addRequestProperty("User-Agent", "Java-DiscordWebhook-BY-Gelox_");
+ connection.setDoOutput(true);
+ connection.setRequestMethod("POST");
+
+ OutputStream stream = connection.getOutputStream();
+ stream.write(json.toString().getBytes());
+ stream.flush();
+ stream.close();
+
+ connection.getInputStream().close(); //I'm not sure why but it doesn't work without getting the InputStream
+ connection.disconnect();
+ }
+
+ public static class EmbedObject {
+ private String title;
+ private String description;
+ private String url;
+ private Color color;
+
+ private Footer footer;
+ private Thumbnail thumbnail;
+ private Image image;
+ private Author author;
+ private List fields = new ArrayList<>();
+
+ public String getTitle() {
+ return title;
+ }
+
+ public EmbedObject setTitle(String title) {
+ this.title = title;
+ return this;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public EmbedObject setDescription(String description) {
+ this.description = description;
+ return this;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public EmbedObject setUrl(String url) {
+ this.url = url;
+ return this;
+ }
+
+ public Color getColor() {
+ return color;
+ }
+
+ public EmbedObject setColor(Color color) {
+ this.color = color;
+ return this;
+ }
+
+ public Footer getFooter() {
+ return footer;
+ }
+
+ public Thumbnail getThumbnail() {
+ return thumbnail;
+ }
+
+ public EmbedObject setThumbnail(String url) {
+ this.thumbnail = new Thumbnail(url);
+ return this;
+ }
+
+ public Image getImage() {
+ return image;
+ }
+
+ public EmbedObject setImage(String url) {
+ this.image = new Image(url);
+ return this;
+ }
+
+ public Author getAuthor() {
+ return author;
+ }
+
+ public List getFields() {
+ return fields;
+ }
+
+ public EmbedObject setFooter(String text, String icon) {
+ this.footer = new Footer(text, icon);
+ return this;
+ }
+
+ public EmbedObject setAuthor(String name, String url, String icon) {
+ this.author = new Author(name, url, icon);
+ return this;
+ }
+
+ public EmbedObject addField(String name, String value, boolean inline) {
+ this.fields.add(new Field(name, value, inline));
+ return this;
+ }
+
+ private class Footer {
+ private String text;
+ private String iconUrl;
+
+ private Footer(String text, String iconUrl) {
+ this.text = text;
+ this.iconUrl = iconUrl;
+ }
+
+ private String getText() {
+ return text;
+ }
+
+ private String getIconUrl() {
+ return iconUrl;
+ }
+ }
+
+ private class Thumbnail {
+ private String url;
+
+ private Thumbnail(String url) {
+ this.url = url;
+ }
+
+ private String getUrl() {
+ return url;
+ }
+ }
+
+ private class Image {
+ private String url;
+
+ private Image(String url) {
+ this.url = url;
+ }
+
+ private String getUrl() {
+ return url;
+ }
+ }
+
+ private class Author {
+ private String name;
+ private String url;
+ private String iconUrl;
+
+ private Author(String name, String url, String iconUrl) {
+ this.name = name;
+ this.url = url;
+ this.iconUrl = iconUrl;
+ }
+
+ private String getName() {
+ return name;
+ }
+
+ private String getUrl() {
+ return url;
+ }
+
+ private String getIconUrl() {
+ return iconUrl;
+ }
+ }
+
+ private class Field {
+ private String name;
+ private String value;
+ private boolean inline;
+
+ private Field(String name, String value, boolean inline) {
+ this.name = name;
+ this.value = value;
+ this.inline = inline;
+ }
+
+ private String getName() {
+ return name;
+ }
+
+ private String getValue() {
+ return value;
+ }
+
+ private boolean isInline() {
+ return inline;
+ }
+ }
+ }
+
+ private class JSONObject {
+
+ private final HashMap map = new HashMap<>();
+
+ void put(String key, Object value) {
+ if (value != null) {
+ map.put(key, value);
+ }
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ Set> entrySet = map.entrySet();
+ builder.append("{");
+
+ int i = 0;
+ for (Map.Entry entry : entrySet) {
+ Object val = entry.getValue();
+ builder.append(quote(entry.getKey())).append(":");
+
+ if (val instanceof String) {
+ builder.append(quote(String.valueOf(val)));
+ } else if (val instanceof Integer) {
+ builder.append(Integer.valueOf(String.valueOf(val)));
+ } else if (val instanceof Boolean) {
+ builder.append(val);
+ } else if (val instanceof JSONObject) {
+ builder.append(val.toString());
+ } else if (val.getClass().isArray()) {
+ builder.append("[");
+ int len = Array.getLength(val);
+ for (int j = 0; j < len; j++) {
+ builder.append(Array.get(val, j).toString()).append(j != len - 1 ? "," : "");
+ }
+ builder.append("]");
+ }
+
+ builder.append(++i == entrySet.size() ? "}" : ",");
+ }
+
+ return builder.toString();
+ }
+
+ private String quote(String string) {
+ return "\"" + string + "\"";
+ }
+ }
+
+}
diff --git a/src/main/java/ir/wy/wycore/utils/InventoryUtils.java b/src/main/java/ir/wy/wycore/spigot/utils/InventoryUtils.java
similarity index 97%
rename from src/main/java/ir/wy/wycore/utils/InventoryUtils.java
rename to src/main/java/ir/wy/wycore/spigot/utils/InventoryUtils.java
index 744969a..fe0c0a1 100644
--- a/src/main/java/ir/wy/wycore/utils/InventoryUtils.java
+++ b/src/main/java/ir/wy/wycore/spigot/utils/InventoryUtils.java
@@ -1,9 +1,10 @@
-package ir.wy.wycore.utils;
+package ir.wy.wycore.spigot.utils;
import com.cryptomorin.xseries.XMaterial;
-import ir.wy.wycore.Design;
+import ir.wy.wycore.spigot.Design;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
+
import java.util.List;
public class InventoryUtils {
diff --git a/src/main/java/ir/wy/wycore/utils/ItemStackUtils.java b/src/main/java/ir/wy/wycore/spigot/utils/ItemStackUtils.java
similarity index 98%
rename from src/main/java/ir/wy/wycore/utils/ItemStackUtils.java
rename to src/main/java/ir/wy/wycore/spigot/utils/ItemStackUtils.java
index 2d2c675..28be36a 100644
--- a/src/main/java/ir/wy/wycore/utils/ItemStackUtils.java
+++ b/src/main/java/ir/wy/wycore/spigot/utils/ItemStackUtils.java
@@ -1,16 +1,17 @@
-package ir.wy.wycore.utils;
+package ir.wy.wycore.spigot.utils;
import com.cryptomorin.xseries.XMaterial;
-import ir.wy.wycore.WyCore;
-import ir.wy.wycore.Item;
import de.tr7zw.changeme.nbtapi.NBTCompound;
import de.tr7zw.changeme.nbtapi.NBTItem;
import de.tr7zw.changeme.nbtapi.NBTListCompound;
+import ir.wy.wycore.spigot.Item;
+import ir.wy.wycore.WyCore;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.util.io.BukkitObjectInputStream;
import org.bukkit.util.io.BukkitObjectOutputStream;
+
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.Base64;
diff --git a/src/main/java/ir/wy/wycore/spigot/utils/LocationUtils.java b/src/main/java/ir/wy/wycore/spigot/utils/LocationUtils.java
new file mode 100644
index 0000000..498429b
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/spigot/utils/LocationUtils.java
@@ -0,0 +1,25 @@
+package ir.wy.wycore.spigot.utils;
+
+import org.bukkit.Location;
+
+public class LocationUtils {
+ public static boolean isLocationMatching(Location location1, Location location2) {
+ return location1.getBlockX() == location2.getBlockX() &&
+ location1.getBlockY() == location2.getBlockY() &&
+ location1.getBlockZ() == location2.getBlockZ();
+ }
+
+ public static boolean isInArea(Location l, Location pos1, Location pos2) {
+ double x1 = Math.min(pos1.getX(), pos2.getX());
+ double y1 = Math.min(pos1.getY(), pos2.getY());
+ double z1 = Math.min(pos1.getZ(), pos2.getZ());
+
+ double x2 = Math.max(pos1.getX(), pos2.getX());
+ double y2 = Math.max(pos1.getY(), pos2.getY());
+ double z2 = Math.max(pos1.getZ(), pos2.getZ());
+
+ return l.getX() >= x1 && l.getX() <= x2 &&
+ l.getY() >= y1 && l.getY() <= y2 &&
+ l.getZ() >= z1 && l.getZ() <= z2;
+ }
+}
diff --git a/src/main/java/ir/wy/wycore/utils/Placeholder.java b/src/main/java/ir/wy/wycore/spigot/utils/Placeholder.java
similarity index 91%
rename from src/main/java/ir/wy/wycore/utils/Placeholder.java
rename to src/main/java/ir/wy/wycore/spigot/utils/Placeholder.java
index 88f6a29..2e2a520 100644
--- a/src/main/java/ir/wy/wycore/utils/Placeholder.java
+++ b/src/main/java/ir/wy/wycore/spigot/utils/Placeholder.java
@@ -1,4 +1,4 @@
-package ir.wy.wycore.utils;
+package ir.wy.wycore.spigot.utils;
import lombok.Getter;
diff --git a/src/main/java/ir/wy/wycore/spigot/utils/RotationUtils.java b/src/main/java/ir/wy/wycore/spigot/utils/RotationUtils.java
new file mode 100644
index 0000000..f0c7513
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/spigot/utils/RotationUtils.java
@@ -0,0 +1,40 @@
+package ir.wy.wycore.spigot.utils;
+
+import org.bukkit.block.BlockFace;
+
+public class RotationUtils {
+ public static float facetoYaw(BlockFace face) {
+ switch (face) {
+ case NORTH:
+ return 180F;
+ case EAST:
+ return -90F;
+ case SOUTH:
+ return 0F;
+ case WEST:
+ return 90F;
+ default:
+ return 0F;
+ }
+ }
+
+ public static BlockFace yawToFace(float face) {
+ switch (Math.round((face + 360) / 90) * 90) {
+ case 0:
+ case 360:
+ return BlockFace.SOUTH;
+ case 180:
+ case 540:
+ return BlockFace.NORTH;
+ case 270:
+ case 630:
+ return BlockFace.EAST;
+ case 90:
+ case 450:
+ return BlockFace.WEST;
+ default:
+ // idk
+ return BlockFace.SOUTH;
+ }
+ }
+}
diff --git a/src/main/java/ir/wy/wycore/utils/SkinUtils.java b/src/main/java/ir/wy/wycore/spigot/utils/SkinUtils.java
similarity index 98%
rename from src/main/java/ir/wy/wycore/utils/SkinUtils.java
rename to src/main/java/ir/wy/wycore/spigot/utils/SkinUtils.java
index 13dd921..c5bf73f 100644
--- a/src/main/java/ir/wy/wycore/utils/SkinUtils.java
+++ b/src/main/java/ir/wy/wycore/spigot/utils/SkinUtils.java
@@ -1,4 +1,4 @@
-package ir.wy.wycore.utils;
+package ir.wy.wycore.spigot.utils;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
@@ -107,7 +107,7 @@ private static boolean validateUsername(String input) {
return false;
}
- for (int i =0, len = input.length(); i < len; i++) {
+ for (int i = 0, len = input.length(); i < len; i++) {
char c = input.charAt(i);
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || (c == '_')) {
continue;
diff --git a/src/main/java/ir/wy/wycore/utils/SortList.java b/src/main/java/ir/wy/wycore/spigot/utils/SortList.java
similarity index 87%
rename from src/main/java/ir/wy/wycore/utils/SortList.java
rename to src/main/java/ir/wy/wycore/spigot/utils/SortList.java
index 90194e4..009638b 100644
--- a/src/main/java/ir/wy/wycore/utils/SortList.java
+++ b/src/main/java/ir/wy/wycore/spigot/utils/SortList.java
@@ -1,4 +1,4 @@
-package ir.wy.wycore.utils;
+package ir.wy.wycore.spigot.utils;
import java.util.ArrayList;
import java.util.Collections;
@@ -12,7 +12,7 @@ public SortList(final Comparator comparator) {
}
@Override
- public boolean add (T t) {
+ public boolean add(T t) {
int index = Collections.binarySearch(this, t, comparator);
if (index < 0) index = ~index;
super.add(index, t);
diff --git a/src/main/java/ir/wy/wycore/utils/StringUtils.java b/src/main/java/ir/wy/wycore/spigot/utils/StringUtils.java
similarity index 96%
rename from src/main/java/ir/wy/wycore/utils/StringUtils.java
rename to src/main/java/ir/wy/wycore/spigot/utils/StringUtils.java
index 2d61a0c..1680118 100644
--- a/src/main/java/ir/wy/wycore/utils/StringUtils.java
+++ b/src/main/java/ir/wy/wycore/spigot/utils/StringUtils.java
@@ -1,8 +1,8 @@
-package ir.wy.wycore.utils;
+package ir.wy.wycore.spigot.utils;
-import ir.wy.wycore.DefaultFontInfo;
-import org.bukkit.ChatColor;
import com.iridium.iridiumcolorapi.IridiumColorAPI;
+import ir.wy.wycore.spigot.DefaultFontInfo;
+import org.bukkit.ChatColor;
import java.util.List;
import java.util.stream.Collectors;
@@ -10,6 +10,7 @@
public class StringUtils {
private final static int CENTER_PX = 154;
+
public static String color(String string) {
return IridiumColorAPI.process(string);
}
diff --git a/src/main/java/ir/wy/wycore/spigot/utils/TextUtils.java b/src/main/java/ir/wy/wycore/spigot/utils/TextUtils.java
new file mode 100644
index 0000000..6476338
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/spigot/utils/TextUtils.java
@@ -0,0 +1,179 @@
+package ir.wy.wycore.spigot.utils;
+
+
+import org.bukkit.ChatColor;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CodingErrorAction;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class TextUtils {
+ private static final List supportedCharsets = new ArrayList<>();
+
+ static {
+ supportedCharsets.add(StandardCharsets.UTF_8);
+ supportedCharsets.add(StandardCharsets.ISO_8859_1);
+
+ try {
+ supportedCharsets.add(Charset.forName("windows-1253"));
+ supportedCharsets.add(Charset.forName("ISO-8859-7"));
+ } catch (Exception ignore) {}
+
+ supportedCharsets.add(StandardCharsets.US_ASCII);
+ }
+
+ public static String formatText(String text) {
+ return formatText(text, false);
+ }
+
+ public static String formatText(String text, boolean capitalize) {
+ if (text == null || text.equals("")) {
+ return "";
+ }
+
+ if (capitalize) {
+ text = text.substring(0, 1).toUpperCase() + text.substring(1);
+ }
+
+ return ChatColor.translateAlternateColorCodes('&', text);
+ }
+
+ public static List formatText(List list) {
+ return list.stream()
+ .map(TextUtils::formatText)
+ .collect(Collectors.toList());
+ }
+
+ public static List formatText(String... list) {
+ return Arrays.stream(list)
+ .map(TextUtils::formatText)
+ .collect(Collectors.toList());
+ }
+
+ public static List wrap(String line) {
+ return wrap(null, line);
+ }
+ public static List wrap(String color, String line) {
+ if (color != null) {
+ color = "&" + color;
+ } else {
+ color = "";
+ }
+
+ List lore = new ArrayList<>();
+ int lastIndex = 0;
+ for (int n = 0; n < line.length(); ++n) {
+ if (n - lastIndex < 25) {
+ continue;
+ }
+
+ if (line.charAt(n) == ' ') {
+ lore.add(TextUtils.formatText(color + TextUtils.formatText(line.substring(lastIndex, n))));
+ lastIndex = n;
+ }
+ }
+
+ if (lastIndex - line.length() < 25) {
+ lore.add(TextUtils.formatText(color + TextUtils.formatText(line.substring(lastIndex))));
+ }
+
+ return lore;
+ }
+
+ public static String convertToInvisibleLoreString(String s) {
+ if (s == null || s.equals("")) {
+ return "";
+ }
+
+ StringBuilder hidden = new StringBuilder();
+
+ for (char c : s.toCharArray()) {
+ hidden.append(ChatColor.COLOR_CHAR)
+ .append(';')
+ .append(ChatColor.COLOR_CHAR)
+ .append(c);
+ }
+
+ return hidden.toString();
+ }
+
+
+ public static Charset detectCharset(File f, Charset def) {
+ byte[] buffer = new byte[2048];
+ int len;
+
+ try (FileInputStream input = new FileInputStream(f)) {
+ len = input.read(buffer);
+ } catch (Exception ex) {
+ return null;
+ }
+
+ return len != -1 ? detectCharset(buffer, len, def) : def;
+ }
+
+ public static Charset detectCharset(BufferedInputStream reader, Charset def) {
+ byte[] buffer = new byte[2048];
+ int len;
+
+ try {
+ reader.mark(2048);
+ len = reader.read(buffer);
+
+ reader.reset();
+ } catch (Exception ex) {
+ return null;
+ }
+
+ return len != -1 ? detectCharset(buffer, len, def) : def;
+ }
+
+ public static Charset detectCharset(byte[] data, int len, Charset def) {
+ if (len > 4) {
+ if (data[0] == (byte) 0xFF && data[1] == (byte) 0xFE) {
+ return StandardCharsets.UTF_16LE;
+ } else if (data[0] == (byte) 0xFE && data[1] == (byte) 0xFF) {
+ return StandardCharsets.UTF_16BE;
+ } else if (data[0] == (byte) 0xEF && data[1] == (byte) 0xBB && data[2] == (byte) 0xBF) { // UTF-8 with BOM
+ return StandardCharsets.UTF_8;
+ }
+ }
+
+ int newLen = len;
+ for (; newLen > 0; --newLen) {
+ if (Character.isWhitespace(data[newLen - 1])) break;
+ }
+
+ if (len > 512 && newLen < 512) {
+ newLen = len;
+ }
+
+ ByteBuffer bBuff = ByteBuffer.wrap(data, 0, newLen).asReadOnlyBuffer();
+ for (Charset charset : supportedCharsets) {
+ if (charset != null && isCharset(bBuff, charset)) {
+ return charset;
+ }
+
+ bBuff.rewind();
+ }
+
+ return def;
+ }
+
+ public static boolean isCharset(ByteBuffer data, Charset charset) {
+ CharsetDecoder decoder = charset.newDecoder();
+ decoder.onMalformedInput(CodingErrorAction.REPORT);
+ decoder.onUnmappableCharacter(CodingErrorAction.REPORT);
+
+ return decoder.decode(data, CharBuffer.allocate(data.capacity()), true).isUnderflow();
+ }
+}
diff --git a/src/main/java/ir/wy/wycore/spigot/utils/TimeUtils.java b/src/main/java/ir/wy/wycore/spigot/utils/TimeUtils.java
new file mode 100644
index 0000000..b70636b
--- /dev/null
+++ b/src/main/java/ir/wy/wycore/spigot/utils/TimeUtils.java
@@ -0,0 +1,264 @@
+package ir.wy.wycore.spigot.utils;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+import java.sql.Timestamp;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Utils: calculating time from ticks and back.
+ */
+
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class TimeUtils {
+
+ private static final DateFormat DATE_FORMAT = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
+
+ private static final DateFormat DATE_FORMAT_SHORT = new SimpleDateFormat("dd.MM.yyyy HH:mm");
+
+ private static final DateFormat DATE_FORMAT_MONTH = new SimpleDateFormat("dd.MM HH:mm");
+
+ private static final Pattern TOKEN_PATTERN = Pattern.compile("(?:([0-9]+)\\s*y[a-z]*[,\\s]*)?"
+ // Months
+ + "(?:([0-9]+)\\s*mo[a-z]*[,\\s]*)?"
+
+ // Weeks
+ + "(?:([0-9]+)\\s*w[a-z]*[,\\s]*)?"
+
+ // Days
+ + "(?:([0-9]+)\\s*d[a-z]*[,\\s]*)?"
+
+ // Hours
+ + "(?:([0-9]+)\\s*h[a-z]*[,\\s]*)?"
+
+ // Minutes
+ + "(?:([0-9]+)\\s*m[a-z]*[,\\s]*)?"
+
+ // Seconds (the "s" may be left out)
+ + "(?:([0-9]+)\\s*(?:s[a-z]*)?)?",
+
+ Pattern.CASE_INSENSITIVE);
+
+
+ public static long currentTimeSeconds() {
+ return System.currentTimeMillis() / 1000;
+ }
+
+ public static long currentTimeTicks() {
+ return System.currentTimeMillis() / 50;
+ }
+
+ public static String getFormattedDate() {
+ return getFormattedDate(System.currentTimeMillis());
+ }
+
+ public static String getFormattedDate(final long time) {
+ return DATE_FORMAT.format(time);
+ }
+
+ public static String getFormattedDateShort() {
+ return DATE_FORMAT_SHORT.format(System.currentTimeMillis());
+ }
+
+ public static String getFormattedDateShort(final long time) {
+ return DATE_FORMAT_SHORT.format(time);
+ }
+
+ public static String getFormattedDateMonth(final long time) {
+ return DATE_FORMAT_MONTH.format(time);
+ }
+
+ public static long toTicks(final String humanReadableTime) {
+ long seconds = 0L;
+ final String[] split = humanReadableTime.split(" ");
+ if (split.length < 2)
+ throw new IllegalArgumentException("Expected human readable time like '1 second', got '" + humanReadableTime + "' instead");
+
+ for (int i = 1; i < split.length; i++) {
+ final String sub = split[i].toLowerCase();
+ int multiplier = 0; // e.g 2 hours = 2
+ long unit = 0; // e.g hours = 3600
+ boolean isTicks = false;
+
+ try {
+ multiplier = Integer.parseInt(split[i - 1]);
+ } catch (final NumberFormatException e) {
+ continue;
+ }
+
+ // attempt to match the unit time
+ if (sub.startsWith("tick"))
+ isTicks = true;
+
+ else if (sub.startsWith("second"))
+ unit = 1;
+
+ else if (sub.startsWith("minute"))
+ unit = 60;
+
+ else if (sub.startsWith("hour"))
+ unit = 3600;
+
+ else if (sub.startsWith("day"))
+ unit = 86400;
+
+ else if (sub.startsWith("week"))
+ unit = 604800;
+
+ else if (sub.startsWith("month"))
+ unit = 2629743;
+
+ else if (sub.startsWith("year"))
+ unit = 31556926;
+
+ else if (sub.startsWith("potato"))
+ unit = 1337;
+
+ else
+ throw new IllegalArgumentException("Must define date type! Example: '1 second' (Got '" + sub + "')");
+
+ seconds += multiplier * (isTicks ? 1 : unit * 20);
+ }
+
+ return seconds;
+ }
+
+ public static String formatTimeGeneric(final long seconds) {
+ final long second = seconds % 60;
+ long minute = seconds / 60;
+ String hourMsg = "";
+
+ if (minute >= 60) {
+ final long hour = seconds / 60 / 60;
+ minute %= 60;
+
+ hourMsg = hour + (hour == 1 ? " hour" : " hours") + " ";
+ }
+
+ return hourMsg + (minute != 0 ? minute : "") + (minute > 0 ? (minute == 1 ? " minute" : " minutes") + " " : "") + Long.parseLong(String.valueOf(second)) + (Long.parseLong(String.valueOf(second)) == 1 ? " second" : " seconds");
+
+ }
+
+ public static String formatTimeDays(final long seconds) {
+ final long minutes = seconds / 60;
+ final long hours = minutes / 60;
+ final long days = hours / 24;
+
+ return days + " days " + hours % 24 + " hours " + minutes % 60 + " minutes " + seconds % 60 + " seconds";
+ }
+
+ public static String formatTimeShort(long seconds) {
+ long minutes = seconds / 60;
+ long hours = minutes / 60;
+ final long days = hours / 24;
+
+ hours = hours % 24;
+ minutes = minutes % 60;
+ seconds = seconds % 60;
+
+ return (days > 0 ? days + "d " : "") + (hours > 0 ? hours + "h " : "") + (minutes > 0 ? minutes + "m " : "") + seconds + "s";
+ }
+
+ public static String formatTimeColon(long seconds) {
+ long minutes = seconds / 60;
+ long hours = minutes / 60;
+ final long days = hours / 24;
+
+ hours = hours % 24;
+ minutes = minutes % 60;
+ seconds = seconds % 60;
+
+ return (days > 0 ? (days < 10 ? "0" : "") + days + ":" : "") +
+ (hours > 0 ? (hours < 10 ? "0" : "") + hours + ":" : "") +
+ (minutes > 0 ? (minutes < 10 ? "0" : "") + minutes + ":" : "00") +
+ (seconds < 10 ? "0" : "") + seconds;
+ }
+
+ public static long parseToken(String text) {
+ final Matcher matcher = TOKEN_PATTERN.matcher(text);
+
+ long years = 0, months = 0, weeks = 0, days = 0, hours = 0, minutes = 0, seconds = 0;
+ boolean found = false;
+
+ while (matcher.find()) {
+
+ if (matcher.group() == null || matcher.group().isEmpty())
+ continue;
+
+ for (int i = 0; i < matcher.groupCount(); i++)
+ if (matcher.group(i) != null && !matcher.group(i).isEmpty()) {
+ found = true;
+
+ break;
+ }
+
+ if (found) {
+ for (int i = 1; i < 8; i++)
+ if (matcher.group(i) != null && !matcher.group(i).isEmpty()) {
+ final long output = Long.parseLong(matcher.group(i));
+
+ if (i == 1) {
+ checkLimit("years", output, 10);
+
+ years = output;
+ } else if (i == 2) {
+ checkLimit("months", output, 12 * 100);
+
+ months = output;
+ } else if (i == 3) {
+ checkLimit("weeks", output, 4 * 100);
+
+ weeks = output;
+ } else if (i == 4) {
+ checkLimit("days", output, 31 * 100);
+
+ days = output;
+ } else if (i == 5) {
+ checkLimit("hours", output, 24 * 100);
+
+ hours = output;
+ } else if (i == 6) {
+ checkLimit("minutes", output, 60 * 100);
+
+ minutes = output;
+ } else if (i == 7) {
+ checkLimit("seconds", output, 60 * 100);
+
+ seconds = output;
+ }
+ }
+
+ break;
+ }
+ }
+
+ if (!found)
+ throw new NumberFormatException("Date not found from: " + text);
+
+ return (seconds + (minutes * 60) + (hours * 3600) + (days * 86400) + (weeks * 7 * 86400) + (months * 30 * 86400) + (years * 365 * 86400)) * 1000;
+ }
+
+ private static void checkLimit(String type, long value, int maxLimit) {
+ if (value > maxLimit)
+ throw new IllegalArgumentException("Value type " + type + " is out of bounds! Max limit: " + maxLimit + ", given: " + value);
+ }
+
+ public static String toSQLTimestamp() {
+ return toSQLTimestamp(System.currentTimeMillis());
+ }
+
+ public static String toSQLTimestamp(long timestamp) {
+ final java.util.Date date = new Date(timestamp);
+
+ return new Timestamp(date.getTime()).toString();
+ }
+
+ public static long fromSQLTimestamp(String timestamp) {
+ return Timestamp.valueOf(timestamp).getTime();
+ }
+}
diff --git a/src/main/java/ir/wy/wycore/utils/BungeeChannelApi.java b/src/main/java/ir/wy/wycore/utils/BungeeChannelApi.java
deleted file mode 100644
index d707718..0000000
--- a/src/main/java/ir/wy/wycore/utils/BungeeChannelApi.java
+++ /dev/null
@@ -1,539 +0,0 @@
-package ir.wy.wycore.utils;
-
-
-import java.net.InetSocketAddress;
-import java.util.ArrayDeque;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Queue;
-import java.util.WeakHashMap;
-import java.util.concurrent.CompletableFuture;
-import java.util.function.BiFunction;
-
-import org.bukkit.Bukkit;
-import org.bukkit.entity.Player;
-import org.bukkit.plugin.Plugin;
-import org.bukkit.plugin.messaging.Messenger;
-import org.bukkit.plugin.messaging.PluginMessageListener;
-
-import com.google.common.collect.Iterables;
-import com.google.common.io.ByteArrayDataInput;
-import com.google.common.io.ByteArrayDataOutput;
-import com.google.common.io.ByteStreams;
-
-/**
- * Documentation copied from https://www.spigotmc.org/wiki/bukkit-bungee-plugin-messaging-channel/
- *
- * @author leonardosnt (leonrdsnt@gmail.com)
- * @see https://www.spigotmc.org/wiki/bukkit-bungee-plugin-messaging-channel/
- */
-public class BungeeChannelApi {
-
- private static WeakHashMap registeredInstances = new WeakHashMap<>();
-
- private final PluginMessageListener messageListener;
- private final Plugin plugin;
- private final Map>> callbackMap;
-
- private Map forwardListeners;
- private ForwardConsumer globalForwardListener;
-
- /**
- * Get or create new BungeeChannelApi instance
- *
- * @param plugin the plugin instance.
- * @return the BungeeChannelApi instance for the {@code plugin}
- * @throws NullPointerException if the {@code plugin} is {@code null}
- */
- public synchronized static BungeeChannelApi of(Plugin plugin) {
- return registeredInstances.compute(plugin, (k, v) -> {
- if (v == null) v = new BungeeChannelApi(plugin);
- return v;
- });
- }
-
- public BungeeChannelApi(Plugin plugin) {
- this.plugin = Objects.requireNonNull(plugin, "plugin cannot be null");
- this.callbackMap = new HashMap<>();
-
- // Prevent dev's from registering multiple channel listeners,
- // by unregistering the old instance.
- synchronized (registeredInstances) {
- registeredInstances.compute(plugin, (k, oldInstance) -> {
- if (oldInstance != null) oldInstance.unregister();
- return this;
- });
- }
-
- this.messageListener = this::onPluginMessageReceived;
-
- Messenger messenger = Bukkit.getServer().getMessenger();
- messenger.registerOutgoingPluginChannel(plugin, "BungeeCord");
- messenger.registerIncomingPluginChannel(plugin, "BungeeCord", messageListener);
- }
-
- /**
- * Set a global listener for all 'forwarded' messages.
- *
- * @param globalListener the listener
- * @see https://www.spigotmc.org/wiki/bukkit-bungee-plugin-messaging-channel/#forward
- */
- public void registerForwardListener(ForwardConsumer globalListener) {
- this.globalForwardListener = globalListener;
- }
-
- /**
- * Set a listener for all 'forwarded' messages in a specific subchannel.
- *
- * @param channelName the subchannel name
- * @param listener the listener
- * @see https://www.spigotmc.org/wiki/bukkit-bungee-plugin-messaging-channel/#forward
- */
- public void registerForwardListener(String channelName, ForwardConsumer listener) {
- if (forwardListeners == null) {
- forwardListeners = new HashMap<>();
- }
- synchronized (forwardListeners) {
- forwardListeners.put(channelName, listener);
- }
- }
-
- /**
- * Get the amount of players on a certain server, or on ALL the servers.
- *
- * @param serverName the server name of the server to get the player count of, or ALL to get the global player count
- * @return A {@link CompletableFuture} that, when completed, will return
- * the amount of players on a certain server, or on ALL the servers.
- * @throws IllegalArgumentException if there is no players online.
- */
- public CompletableFuture getPlayerCount(String serverName) {
- Player player = getFirstPlayer();
- CompletableFuture future = new CompletableFuture<>();
-
- synchronized (callbackMap) {
- callbackMap.compute("PlayerCount-" + serverName, this.computeQueueValue(future));
- }
-
- ByteArrayDataOutput output = ByteStreams.newDataOutput();
- output.writeUTF("PlayerCount");
- output.writeUTF(serverName);
- player.sendPluginMessage(this.plugin, "BungeeCord", output.toByteArray());
- return future;
- }
-
- /**
- * Get a list of players connected on a certain server, or on ALL the servers.
- *
- * @param serverName the name of the server to get the list of connected players, or ALL for global online player list
- * @return A {@link CompletableFuture} that, when completed, will return a
- * list of players connected on a certain server, or on ALL the servers.
- * @throws IllegalArgumentException if there is no players online.
- */
- public CompletableFuture> getPlayerList(String serverName) {
- Player player = getFirstPlayer();
- CompletableFuture> future = new CompletableFuture<>();
-
- synchronized (callbackMap) {
- callbackMap.compute("PlayerList-" + serverName, this.computeQueueValue(future));
- }
-
- ByteArrayDataOutput output = ByteStreams.newDataOutput();
- output.writeUTF("PlayerList");
- output.writeUTF(serverName);
- player.sendPluginMessage(this.plugin, "BungeeCord", output.toByteArray());
- return future;
- }
-
- /**
- * Get a list of server name strings, as defined in BungeeCord's config.yml.
- *
- * @return A {@link CompletableFuture} that, when completed, will return a
- * list of server name strings, as defined in BungeeCord's config.yml.
- * @throws IllegalArgumentException if there is no players online.
- */
- public CompletableFuture> getServers() {
- Player player = getFirstPlayer();
- CompletableFuture> future = new CompletableFuture<>();
-
- synchronized (callbackMap) {
- callbackMap.compute("GetServers", this.computeQueueValue(future));
- }
-
- ByteArrayDataOutput output = ByteStreams.newDataOutput();
- output.writeUTF("GetServers");
- player.sendPluginMessage(this.plugin, "BungeeCord", output.toByteArray());
- return future;
- }
-
- /**
- * Connects a player to said subserver.
- *
- * @param player the player you want to teleport.
- * @param serverName the name of server to connect to, as defined in BungeeCord config.yml.
- */
- public void connect(Player player, String serverName) {
- ByteArrayDataOutput output = ByteStreams.newDataOutput();
- output.writeUTF("Connect");
- output.writeUTF(serverName);
- player.sendPluginMessage(this.plugin, "BungeeCord", output.toByteArray());
- }
-
- /**
- * Connect a named player to said subserver.
- *
- * @param playerName name of the player to teleport.
- * @param server name of server to connect to, as defined in BungeeCord config.yml.
- * @throws IllegalArgumentException if there is no players online.
- */
- public void connectOther(String playerName, String server) {
- Player player = getFirstPlayer();
- ByteArrayDataOutput output = ByteStreams.newDataOutput();
-
- output.writeUTF("ConnectOther");
- output.writeUTF(playerName);
- output.writeUTF(server);
-
- player.sendPluginMessage(this.plugin, "BungeeCord", output.toByteArray());
- }
-
- /**
- * Get the (real) IP of a player.
- *
- * @param player The player you wish to get the IP of.
- * @return A {@link CompletableFuture} that, when completed, will return the (real) IP of {@code player}.
- */
- public CompletableFuture getIp(Player player) {
- CompletableFuture future = new CompletableFuture<>();
-
- synchronized (callbackMap) {
- callbackMap.compute("IP", this.computeQueueValue(future));
- }
-
- ByteArrayDataOutput output = ByteStreams.newDataOutput();
- output.writeUTF("IP");
- player.sendPluginMessage(this.plugin, "BungeeCord", output.toByteArray());
- return future;
- }
-
- /**
- * Send a message (as in, a chat message) to the specified player.
- *
- * @param playerName the name of the player to send the chat message.
- * @param message the message to send to the player.
- * @throws IllegalArgumentException if there is no players online.
- */
- public void sendMessage(String playerName, String message) {
- Player player = getFirstPlayer();
- ByteArrayDataOutput output = ByteStreams.newDataOutput();
-
- output.writeUTF("Message");
- output.writeUTF(playerName);
- output.writeUTF(message);
- player.sendPluginMessage(this.plugin, "BungeeCord", output.toByteArray());
- }
-
- /**
- * Get this server's name, as defined in BungeeCord's config.yml
- *
- * @return A {@link CompletableFuture} that, when completed, will return
- * the {@code server's} name, as defined in BungeeCord's config.yml.
- * @throws IllegalArgumentException if there is no players online.
- */
- public CompletableFuture getServer() {
- Player player = getFirstPlayer();
- CompletableFuture future = new CompletableFuture<>();
-
- synchronized (callbackMap) {
- callbackMap.compute("GetServer", this.computeQueueValue(future));
- }
-
- ByteArrayDataOutput output = ByteStreams.newDataOutput();
- output.writeUTF("GetServer");
- player.sendPluginMessage(this.plugin, "BungeeCord", output.toByteArray());
- return future;
- }
-
- /**
- * Request the UUID of this player.
- *
- * @param player The player whose UUID you requested.
- * @return A {@link CompletableFuture} that, when completed, will return the UUID of {@code player}.
- */
- public CompletableFuture getUUID(Player player) {
- CompletableFuture future = new CompletableFuture<>();
-
- synchronized (callbackMap) {
- callbackMap.compute("UUID", this.computeQueueValue(future));
- }
-
- ByteArrayDataOutput output = ByteStreams.newDataOutput();
- output.writeUTF("UUID");
- player.sendPluginMessage(this.plugin, "BungeeCord", output.toByteArray());
- return future;
- }
-
- /**
- * Request the UUID of any player connected to the BungeeCord proxy.
- *
- * @param playerName the name of the player whose UUID you would like.
- * @return A {@link CompletableFuture} that, when completed, will return the UUID of {@code playerName}.
- * @throws IllegalArgumentException if there is no players online.
- */
- public CompletableFuture getUUID(String playerName) {
- Player player = getFirstPlayer();
- CompletableFuture future = new CompletableFuture<>();
-
- synchronized (callbackMap) {
- callbackMap.compute("UUIDOther-" + playerName, this.computeQueueValue(future));
- }
-
- ByteArrayDataOutput output = ByteStreams.newDataOutput();
- output.writeUTF("UUIDOther");
- output.writeUTF(playerName);
- player.sendPluginMessage(this.plugin, "BungeeCord", output.toByteArray());
- return future;
- }
-
- /**
- * Request the IP of any server on this proxy.
- *
- * @param serverName the name of the server.
- * @return A {@link CompletableFuture} that, when completed, will return the requested ip.
- * @throws IllegalArgumentException if there is no players online.
- */
- public CompletableFuture getServerIp(String serverName) {
- Player player = getFirstPlayer();
- CompletableFuture future = new CompletableFuture<>();
-
- synchronized (callbackMap) {
- callbackMap.compute("ServerIP-" + serverName, this.computeQueueValue(future));
- }
-
- ByteArrayDataOutput output = ByteStreams.newDataOutput();
- output.writeUTF("ServerIP");
- output.writeUTF(serverName);
- player.sendPluginMessage(this.plugin, "BungeeCord", output.toByteArray());
- return future;
- }
-
- /**
- * Kick any player on this proxy.
- *
- * @param playerName the name of the player.
- * @param kickMessage the reason the player is kicked with.
- * @throws IllegalArgumentException if there is no players online.
- */
- public void kickPlayer(String playerName, String kickMessage) {
- Player player = getFirstPlayer();
- CompletableFuture future = new CompletableFuture<>();
-
- synchronized (callbackMap) {
- callbackMap.compute("KickPlayer", this.computeQueueValue(future));
- }
-
- ByteArrayDataOutput output = ByteStreams.newDataOutput();
- output.writeUTF("KickPlayer");
- output.writeUTF(playerName);
- output.writeUTF(kickMessage);
- player.sendPluginMessage(this.plugin, "BungeeCord", output.toByteArray());
- }
-
- /**
- * Send a custom plugin message to said server. This is one of the most useful channels ever.
- * Remember, the sending and receiving server(s) need to have a player online.
- *
- * @param server the name of the server to send to,
- * ALL to send to every server (except the one sending the plugin message),
- * or ONLINE to send to every server that's online (except the one sending the plugin message).
- *
- * @param channelName Subchannel for plugin usage.
- * @param data data to send.
- * @throws IllegalArgumentException if there is no players online.
- */
- public void forward(String server, String channelName, byte[] data) {
- Player player = getFirstPlayer();
-
- ByteArrayDataOutput output = ByteStreams.newDataOutput();
- output.writeUTF("Forward");
- output.writeUTF(server);
- output.writeUTF(channelName);
- output.writeShort(data.length);
- output.write(data);
- player.sendPluginMessage(this.plugin, "BungeeCord", output.toByteArray());
- }
-
- /**
- * Send a custom plugin message to specific player.
- *
- * @param playerName the name of the player to send to.
- * @param channelName Subchannel for plugin usage.
- * @param data data to send.
- * @throws IllegalArgumentException if there is no players online.
- */
- public void forwardToPlayer(String playerName, String channelName, byte[] data) {
- Player player = getFirstPlayer();
-
- ByteArrayDataOutput output = ByteStreams.newDataOutput();
- output.writeUTF("ForwardToPlayer");
- output.writeUTF(playerName);
- output.writeUTF(channelName);
- output.writeShort(data.length);
- output.write(data);
- player.sendPluginMessage(this.plugin, "BungeeCord", output.toByteArray());
- }
-
- @SuppressWarnings("unchecked")
- private void onPluginMessageReceived(String channel, Player player, byte[] message) {
- if (!channel.equalsIgnoreCase("BungeeCord")) return;
-
- ByteArrayDataInput input = ByteStreams.newDataInput(message);
- String subchannel = input.readUTF();
-
- synchronized (callbackMap) {
- Queue> callbacks;
-
- if (subchannel.equals("PlayerCount") || subchannel.equals("PlayerList") ||
- subchannel.equals("UUIDOther") || subchannel.equals("ServerIP")) {
- String identifier = input.readUTF(); // Server/player name
- callbacks = callbackMap.get(subchannel + "-" + identifier);
-
- if (callbacks == null || callbacks.isEmpty()) {
- return;
- }
-
- CompletableFuture> callback = callbacks.poll();
-
- try {
- switch (subchannel) {
- case "PlayerCount":
- ((CompletableFuture) callback).complete(Integer.valueOf(input.readInt()));
- break;
-
- case "PlayerList":
- ((CompletableFuture>) callback).complete(Arrays.asList(input.readUTF().split(", ")));
- break;
-
- case "UUIDOther":
- ((CompletableFuture) callback).complete(input.readUTF());
- break;
-
- case "ServerIP": {
- String ip = input.readUTF();
- int port = input.readUnsignedShort();
- ((CompletableFuture) callback).complete(new InetSocketAddress(ip, port));
- break;
- }
- }
- } catch(Exception ex) {
- callback.completeExceptionally(ex);
- }
-
- return;
- }
-
- callbacks = callbackMap.get(subchannel);
-
- if (callbacks == null) {
- short dataLength = input.readShort();
- byte[] data = new byte[dataLength];
- input.readFully(data);
-
- if (globalForwardListener != null) {
- globalForwardListener.accept(subchannel, player, data);
- }
-
- if (forwardListeners != null) {
- synchronized (forwardListeners) {
- ForwardConsumer listener = forwardListeners.get(subchannel);
- if (listener != null) {
- listener.accept(subchannel, player, data);
- }
- }
- }
-
- return;
- }
-
- if (callbacks.isEmpty()) {
- return;
- }
-
- final CompletableFuture> callback = callbacks.poll();
-
- try {
- switch (subchannel) {
- case "GetServers":
- ((CompletableFuture>) callback).complete(Arrays.asList(input.readUTF().split(", ")));
- break;
-
- case "GetServer":
- case "UUID":
- ((CompletableFuture) callback).complete(input.readUTF());
- break;
-
- case "IP": {
- String ip = input.readUTF();
- int port = input.readInt();
- ((CompletableFuture) callback).complete(new InetSocketAddress(ip, port));
- break;
- }
-
- default:
- break;
- }
- } catch(Exception ex) {
- callback.completeExceptionally(ex);
- }
- }
- }
-
- /**
- * Unregister message channels.
- */
- public void unregister() {
- Messenger messenger = Bukkit.getServer().getMessenger();
- messenger.unregisterIncomingPluginChannel(plugin, "BungeeCord", messageListener);
- messenger.unregisterOutgoingPluginChannel(plugin);
- callbackMap.clear();
- }
-
- private BiFunction>, Queue>> computeQueueValue(CompletableFuture> queueValue) {
- return (key, value) -> {
- if (value == null) value = new ArrayDeque>();
- value.add(queueValue);
- return value;
- };
- }
-
- private Player getFirstPlayer() {
- /**
- * if Bukkit Version < 1.7.10 then Bukkit.getOnlinePlayers() will return
- * a Player[] otherwise it'll return a Collection extends Player>.
- */
- Player firstPlayer = getFirstPlayer0(Bukkit.getOnlinePlayers());
-
- if (firstPlayer == null) {
- throw new IllegalArgumentException("Bungee Messaging Api requires at least one player to be online.");
- }
-
- return firstPlayer;
- }
-
- @SuppressWarnings("unused")
- private Player getFirstPlayer0(Player[] playerArray) {
- return playerArray.length > 0 ? playerArray[0] : null;
- }
-
- private Player getFirstPlayer0(Collection extends Player> playerCollection) {
- return Iterables.getFirst(playerCollection, null);
- }
-
- @FunctionalInterface
- public interface ForwardConsumer {
- void accept(String channel, Player player, byte[] data);
- }
-}
diff --git a/src/main/java/ir/wy/wycore/utils/DiscordWebhook.java b/src/main/java/ir/wy/wycore/utils/DiscordWebhook.java
deleted file mode 100644
index b8add54..0000000
--- a/src/main/java/ir/wy/wycore/utils/DiscordWebhook.java
+++ /dev/null
@@ -1,393 +0,0 @@
-package ir.wy.wycore.utils;
-
-import javax.net.ssl.HttpsURLConnection;
-import java.awt.Color;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.lang.reflect.Array;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-/*
- * Java DiscordWebhook class to easily execute Discord Webhooks
- * Created by: k3kdude
- * Source: https://gist.github.com/k3kdude/fba6f6b37594eae3d6f9475330733bdb
- */
-
-public class DiscordWebhook {
- private final String url;
- private String content;
- private String username;
- private String avatarUrl;
- private boolean tts;
- private List embeds = new ArrayList<>();
-
- /**
- * Constructs a new DiscordWebhook instance
- *
- * @param url The webhook URL obtained in Discord
- */
- public DiscordWebhook(String url) {
- this.url = url;
- }
-
- public void setContent(String content) {
- this.content = content;
- }
-
- public void setUsername(String username) {
- this.username = username;
- }
-
- public void setAvatarUrl(String avatarUrl) {
- this.avatarUrl = avatarUrl;
- }
-
- public void setTts(boolean tts) {
- this.tts = tts;
- }
-
- public void addEmbed(EmbedObject embed) {
- this.embeds.add(embed);
- }
-
- public void execute() throws IOException {
- if (this.content == null && this.embeds.isEmpty()) {
- throw new IllegalArgumentException("Set content or add at least one EmbedObject");
- }
-
- JSONObject json = new JSONObject();
-
- json.put("content", this.content);
- json.put("username", this.username);
- json.put("avatar_url", this.avatarUrl);
- json.put("tts", this.tts);
-
- if (!this.embeds.isEmpty()) {
- List embedObjects = new ArrayList<>();
-
- for (EmbedObject embed : this.embeds) {
- JSONObject jsonEmbed = new JSONObject();
-
- jsonEmbed.put("title", embed.getTitle());
- jsonEmbed.put("description", embed.getDescription());
- jsonEmbed.put("url", embed.getUrl());
-
- if (embed.getColor() != null) {
- Color color = embed.getColor();
- int rgb = color.getRed();
- rgb = (rgb << 8) + color.getGreen();
- rgb = (rgb << 8) + color.getBlue();
-
- jsonEmbed.put("color", rgb);
- }
-
- EmbedObject.Footer footer = embed.getFooter();
- EmbedObject.Image image = embed.getImage();
- EmbedObject.Thumbnail thumbnail = embed.getThumbnail();
- EmbedObject.Author author = embed.getAuthor();
- List fields = embed.getFields();
-
- if (footer != null) {
- JSONObject jsonFooter = new JSONObject();
-
- jsonFooter.put("text", footer.getText());
- jsonFooter.put("icon_url", footer.getIconUrl());
- jsonEmbed.put("footer", jsonFooter);
- }
-
- if (image != null) {
- JSONObject jsonImage = new JSONObject();
-
- jsonImage.put("url", image.getUrl());
- jsonEmbed.put("image", jsonImage);
- }
-
- if (thumbnail != null) {
- JSONObject jsonThumbnail = new JSONObject();
-
- jsonThumbnail.put("url", thumbnail.getUrl());
- jsonEmbed.put("thumbnail", jsonThumbnail);
- }
-
- if (author != null) {
- JSONObject jsonAuthor = new JSONObject();
-
- jsonAuthor.put("name", author.getName());
- jsonAuthor.put("url", author.getUrl());
- jsonAuthor.put("icon_url", author.getIconUrl());
- jsonEmbed.put("author", jsonAuthor);
- }
-
- List jsonFields = new ArrayList<>();
- for (EmbedObject.Field field : fields) {
- JSONObject jsonField = new JSONObject();
-
- jsonField.put("name", field.getName());
- jsonField.put("value", field.getValue());
- jsonField.put("inline", field.isInline());
-
- jsonFields.add(jsonField);
- }
-
- jsonEmbed.put("fields", jsonFields.toArray());
- embedObjects.add(jsonEmbed);
- }
-
- json.put("embeds", embedObjects.toArray());
- }
-
- URL url = new URL(this.url);
- HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
- connection.addRequestProperty("Content-Type", "application/json");
- connection.addRequestProperty("User-Agent", "Java-DiscordWebhook-BY-Gelox_");
- connection.setDoOutput(true);
- connection.setRequestMethod("POST");
-
- OutputStream stream = connection.getOutputStream();
- stream.write(json.toString().getBytes());
- stream.flush();
- stream.close();
-
- connection.getInputStream().close(); //I'm not sure why but it doesn't work without getting the InputStream
- connection.disconnect();
- }
-
- public static class EmbedObject {
- private String title;
- private String description;
- private String url;
- private Color color;
-
- private Footer footer;
- private Thumbnail thumbnail;
- private Image image;
- private Author author;
- private List fields = new ArrayList<>();
-
- public String getTitle() {
- return title;
- }
-
- public String getDescription() {
- return description;
- }
-
- public String getUrl() {
- return url;
- }
-
- public Color getColor() {
- return color;
- }
-
- public Footer getFooter() {
- return footer;
- }
-
- public Thumbnail getThumbnail() {
- return thumbnail;
- }
-
- public Image getImage() {
- return image;
- }
-
- public Author getAuthor() {
- return author;
- }
-
- public List getFields() {
- return fields;
- }
-
- public EmbedObject setTitle(String title) {
- this.title = title;
- return this;
- }
-
- public EmbedObject setDescription(String description) {
- this.description = description;
- return this;
- }
-
- public EmbedObject setUrl(String url) {
- this.url = url;
- return this;
- }
-
- public EmbedObject setColor(Color color) {
- this.color = color;
- return this;
- }
-
- public EmbedObject setFooter(String text, String icon) {
- this.footer = new Footer(text, icon);
- return this;
- }
-
- public EmbedObject setThumbnail(String url) {
- this.thumbnail = new Thumbnail(url);
- return this;
- }
-
- public EmbedObject setImage(String url) {
- this.image = new Image(url);
- return this;
- }
-
- public EmbedObject setAuthor(String name, String url, String icon) {
- this.author = new Author(name, url, icon);
- return this;
- }
-
- public EmbedObject addField(String name, String value, boolean inline) {
- this.fields.add(new Field(name, value, inline));
- return this;
- }
-
- private class Footer {
- private String text;
- private String iconUrl;
-
- private Footer(String text, String iconUrl) {
- this.text = text;
- this.iconUrl = iconUrl;
- }
-
- private String getText() {
- return text;
- }
-
- private String getIconUrl() {
- return iconUrl;
- }
- }
-
- private class Thumbnail {
- private String url;
-
- private Thumbnail(String url) {
- this.url = url;
- }
-
- private String getUrl() {
- return url;
- }
- }
-
- private class Image {
- private String url;
-
- private Image(String url) {
- this.url = url;
- }
-
- private String getUrl() {
- return url;
- }
- }
-
- private class Author {
- private String name;
- private String url;
- private String iconUrl;
-
- private Author(String name, String url, String iconUrl) {
- this.name = name;
- this.url = url;
- this.iconUrl = iconUrl;
- }
-
- private String getName() {
- return name;
- }
-
- private String getUrl() {
- return url;
- }
-
- private String getIconUrl() {
- return iconUrl;
- }
- }
-
- private class Field {
- private String name;
- private String value;
- private boolean inline;
-
- private Field(String name, String value, boolean inline) {
- this.name = name;
- this.value = value;
- this.inline = inline;
- }
-
- private String getName() {
- return name;
- }
-
- private String getValue() {
- return value;
- }
-
- private boolean isInline() {
- return inline;
- }
- }
- }
-
- private class JSONObject {
-
- private final HashMap map = new HashMap<>();
-
- void put(String key, Object value) {
- if (value != null) {
- map.put(key, value);
- }
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- Set> entrySet = map.entrySet();
- builder.append("{");
-
- int i = 0;
- for (Map.Entry entry : entrySet) {
- Object val = entry.getValue();
- builder.append(quote(entry.getKey())).append(":");
-
- if (val instanceof String) {
- builder.append(quote(String.valueOf(val)));
- } else if (val instanceof Integer) {
- builder.append(Integer.valueOf(String.valueOf(val)));
- } else if (val instanceof Boolean) {
- builder.append(val);
- } else if (val instanceof JSONObject) {
- builder.append(val.toString());
- } else if (val.getClass().isArray()) {
- builder.append("[");
- int len = Array.getLength(val);
- for (int j = 0; j < len; j++) {
- builder.append(Array.get(val, j).toString()).append(j != len - 1 ? "," : "");
- }
- builder.append("]");
- }
-
- builder.append(++i == entrySet.size() ? "}" : ",");
- }
-
- return builder.toString();
- }
-
- private String quote(String string) {
- return "\"" + string + "\"";
- }
- }
-
- }
diff --git a/src/main/java/ir/wy/wycore/utils/NumFormatter.java b/src/main/java/ir/wy/wycore/utils/NumFormatter.java
deleted file mode 100644
index baee686..0000000
--- a/src/main/java/ir/wy/wycore/utils/NumFormatter.java
+++ /dev/null
@@ -1,65 +0,0 @@
-package ir.wy.wycore.utils;
-
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import java.math.BigDecimal;
-import java.math.RoundingMode;
-
-
-public class NumFormatter {
-
- public int numberAbbreviationDecimalPlaces = 2;
- public String thousandAbbreviation = "K";
- public String millionAbbreviation = "M";
- public String billionAbbreviation = "B";
- public String trillionAbbreviation = "T";
- public boolean displayNumberAbbreviations = true;
- @JsonIgnore
- private final BigDecimal ONE_THOUSAND = new BigDecimal(1_000L);
- @JsonIgnore
- private final BigDecimal ONE_MILLION = new BigDecimal(1_000_000L);
- @JsonIgnore
- private final BigDecimal ONE_BILLION = new BigDecimal(1_000_000_000L);
- @JsonIgnore
- private final BigDecimal ONE_TRILLION = new BigDecimal(1_000_000_000_000L);
-
- public String format(double number) {
- if (displayNumberAbbreviations) {
- return formatNumber(BigDecimal.valueOf(number));
- } else {
- return String.format("%." + numberAbbreviationDecimalPlaces + "f", number);
- }
- }
-
- private String formatNumber(BigDecimal bigDecimal) {
- bigDecimal = bigDecimal.setScale(numberAbbreviationDecimalPlaces, RoundingMode.HALF_DOWN);
- StringBuilder outputStringBuilder = new StringBuilder();
-
- if (bigDecimal.compareTo(BigDecimal.ZERO) < 0) {
- outputStringBuilder
- .append("-")
- .append(formatNumber(bigDecimal.negate()));
- } else if (bigDecimal.compareTo(ONE_THOUSAND) < 0) {
- outputStringBuilder
- .append(bigDecimal.stripTrailingZeros().toPlainString());
- } else if (bigDecimal.compareTo(ONE_MILLION) < 0) {
- outputStringBuilder
- .append(bigDecimal.divide(ONE_THOUSAND, RoundingMode.HALF_DOWN).stripTrailingZeros().toPlainString())
- .append(thousandAbbreviation);
- } else if (bigDecimal.compareTo(ONE_BILLION) < 0) {
- outputStringBuilder
- .append(bigDecimal.divide(ONE_MILLION, RoundingMode.HALF_DOWN).stripTrailingZeros().toPlainString())
- .append(millionAbbreviation);
- } else if (bigDecimal.compareTo(ONE_TRILLION) < 0) {
- outputStringBuilder
- .append(bigDecimal.divide(ONE_BILLION, RoundingMode.HALF_DOWN).stripTrailingZeros().toPlainString())
- .append(billionAbbreviation);
- } else {
- outputStringBuilder
- .append(bigDecimal.divide(ONE_TRILLION, RoundingMode.HALF_DOWN).stripTrailingZeros().toPlainString())
- .append(trillionAbbreviation);
- }
-
- return outputStringBuilder.toString();
- }
-
-}