diff --git a/.gitignore b/.gitignore
index 4f3e49966..865dc1b52 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,6 @@
+#DynamicGui
+core/mock_data/cooldowns.yml
+
# Compiled class file
*.class
@@ -22,6 +25,7 @@ hs_err_pid*
.gradle
build/
+out/
# Ignore Gradle GUI config
gradle-app.setting
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 4b4c7c790..e0c91e615 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -2,7 +2,6 @@
First off thank you for considering contributing to DynamicGui! Below are a few different ways you can contribute.
-
## Issues
If you run into a bug please report it, **please note if this is a bug that could result in item duplication or some other security risk please report it to `virustotal#0001` on the DynamicGui Discord server.** If the bug is not a security risk or could do damage to servers that are using the plugin please file a bug report at https://github.com/ClubObsidian/DynamicGui/issues
@@ -15,8 +14,6 @@ We gladly accept most contributions which do not break backwards compatability.
If you are updating documentation please put `[ci skip]` in your commit so that your commit gets skipped by github actions, you can [read more about that here.](https://github.blog/changelog/2021-02-08-github-actions-skip-pull-request-and-push-workflows-with-skip-ci/)
-**Please note before your code will be accepted please sign our [CLA.](https://cla-assistant.io/ClubObsidian/DynamicGui)**
-
## Features
diff --git a/LICENSE_HEADER b/HEADER.txt
similarity index 91%
rename from LICENSE_HEADER
rename to HEADER.txt
index 53369bc80..0a3862c3e 100644
--- a/LICENSE_HEADER
+++ b/HEADER.txt
@@ -1,4 +1,4 @@
- Copyright 2021 Club Obsidian and contributors.
+ Copyright 2022 virustotalop and contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
diff --git a/README.md b/README.md
index 5e90df3ee..48fcadad8 100644
--- a/README.md
+++ b/README.md
@@ -2,22 +2,15 @@
DynamicGui
[![build](https://github.com/ClubObsidian/DynamicGui/actions/workflows/build.yml/badge.svg)](https://github.com/ClubObsidian/DynamicGui/actions/workflows/build.yml)
-[![CLA assistant](https://cla-assistant.io/readme/badge/ClubObsidian/DynamicGui)](https://cla-assistant.io/ClubObsidian/DynamicGui)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
+A plugin designed to make writing menus for Minecraft easy. Menus can be written in the configuration language of your choice: yaml, hocon, json or xml.
-A rewrite of the plugin originally created at Club Obsidian.
-
-Designed to make writing menus easy.
-
-
## Features
-* Multi server support in one jar
- * Bukkit - Fully supported
- * Sponge - Support dropped for now
* A number of functions to use to customize menus
+ * Asynchronous functions
* Functions use latebinding
* Addons can be written for more functions
* Use conditions with replacers using [EvalEx](https://github.com/uklimaschewski/EvalEx)
@@ -44,6 +37,9 @@ Designed to make writing menus easy.
* Hopper
* Workbench
+## Future features
+
+* Support for sponge
## Use cases
@@ -59,18 +55,13 @@ Just a few uses for DynamicGui.
* Quests
* Shop
* Staff tools
- * Punishments
## Downloads
-You can get [development builds from our jenkins.](https://ci.ravenlab.dev/job/DynamicGui/)
+You can get [development builds from Github actions](https://github.com/ClubObsidian/DynamicGui/actions/workflows/build.yml) but you will need a Github account.
## Getting Started
-### Gui Examples
-
-You can find [gui examples here](https://github.com/ClubObsidian/DynamicGuiExamples).
-
### Gui Documentation
You find find [gui documentation here](https://dynamicgui.github.io/documentation/).
diff --git a/build.gradle b/build.gradle
index baa786606..a3ce5c9f7 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,22 +1,90 @@
plugins {
id 'java-library'
id 'com.github.johnrengelman.shadow' version '7.1.1'
+ id 'org.cadixdev.licenser' version '0.6.1'
id 'eclipse'
id 'idea'
+ id 'maven-publish'
+}
+
+allprojects {
+ group 'com.clubobsidian'
+ version '5.0.0'
+ ext {
+ junitVersion = '5.8.2'
+ cloudVersion = '1.6.2'
+ }
}
subprojects {
apply plugin: 'java-library'
apply plugin: 'com.github.johnrengelman.shadow'
+ apply plugin: 'org.cadixdev.licenser'
+ apply plugin: 'maven-publish'
- group 'com.clubobsidian'
- version '4.1.0'
+ publishing {
+ publications {
+ shadow(MavenPublication) {
+ groupId 'com.clubobsidian'
+ artifactId project.name
+ version '5.0.0'
+ artifact shadowJar
+ }
+ }
+ }
tasks.withType(JavaCompile) {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
+ license {
+ header = project.rootProject.file('HEADER.txt')
+ include '**/*.java'
+ }
+
+ test {
+ useJUnitPlatform()
+ }
+
+ shadowJar {
+ archiveClassifier.set('')
+ minimize() {
+ exclude(project(":core"))
+ }
+ relocate 'org.spongepowered.configurate', 'com.clubobsidian.dynamicgui.shaded.configurate'
+ relocate 'com.google.common', 'com.clubobsidian.dynamicgui.shaded.guava'
+ relocate 'com.google.gson', 'com.clubobsidian.dynamicgui.shaded.gson'
+ relocate 'org.yaml.snakeyaml', 'com.clubobsidian.dynamicgui.shaded.snakeyaml'
+ relocate 'com.clubobsidian.trident', 'com.clubobsidian.dynamicgui.shaded.trident'
+ relocate 'com.clubobsidian.wrappy', 'com.clubobsidian.dynamicgui.shaded.wrappy'
+ relocate 'net.kyori', 'com.clubobsidian.dynamicgui.shaded.kyori'
+ relocate 'com.clubobsidian.fuzzutil', 'com.clubobsidian.dynamicgui.shaded.fuzzutil'
+ relocate 'io.leangen', 'com.clubobsidian.dynamicgui.shaded.leangen'
+ relocate 'org.codehaus.mojo', 'com.clubobsidian.dynamicgui.shaded.mojo'
+ relocate 'org.checkerframework.framework', 'com.clubobsidian.dynamicgui.shaded.checkerframework.framework'
+ relocate 'org.checkerframework.common', 'com.clubobsidian.dynamicgui.shaded.checkerframework.common'
+ relocate 'org.checkerframework.checker', 'com.clubobsidian.dynamicgui.shaded.checkerframework.checker'
+ relocate 'org.checkerframework.dataflow', 'com.clubobsidian.dynamicgui.shaded.checkerframework.dataflow'
+ relocate 'org.apache.commons', 'com.clubobsidian.dynamicgui.shaded.apachecommons'
+ relocate 'org.aopalliance.intercept', 'com.clubobsidian.dynamicgui.shaded.aopalliance.intercept'
+ relocate 'org.aopalliance.aop', 'com.clubobsidian.dynamicgui.shaded.aopalliance.aop'
+ relocate 'javax.inject', 'com.clubobsidian.dynamicgui.shaded.javax.inject'
+ relocate 'com.udojava.evalex', 'com.clubobsidian.dynamicgui.shaded.evalex'
+ relocate 'com.typesafe.config', 'com.clubobsidian.dynamicgui.shaded.typesafeconfig'
+ relocate 'com.google.j2objc', 'com.clubobsidian.dynamicgui.shaded.j2objc'
+ relocate 'com.google.inject', 'com.clubobsidian.dynamicgui.shaded.guice'
+ relocate 'javax.annotation', 'com.clubobsidian.dynamicgui.shaded.javaxannotation'
+ relocate 'com.google.errorprone', 'com.clubobsidian.dynamicgui.shaded.errorprone'
+ relocate 'com.fasterxml.jackson', 'com.clubobsidian.dynamicgui.shaded.jackson'
+ relocate 'com.github.benmanes.caffeine', 'com.clubobsidian.dynamicgui.shaded.caffeine'
+ relocate 'cloud', 'com.clubobsidian.dynamicgui.shaded.cloud'
+ relocate 'com.google.thirdparty', 'com.clubobsidian.dynamicgui.shaded.google.thirdparty'
+ relocate 'io.github.classgraph', 'com.clubobsidian.dynamicgui.shaded.classgraph'
+ relocate 'nonapi.io.github.classgraph', 'com.clubobsidian.dynamicgui.shaded.nonapi.io.github.classgraph'
+ relocate 'javassist', 'com.clubobsidian.dynamicgui.shaded.javassist'
+ }
+
repositories {
maven { url "https://hub.spigotmc.org/nexus/content/repositories/snapshots"}
maven { url = "https://oss.sonatype.org/content/repositories/snapshots" }
@@ -24,9 +92,18 @@ subprojects {
maven { url 'https://jitpack.io' }
}
+
+
dependencies {
- testImplementation 'junit:junit:4.13.2'
+ testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
+ testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
+ testImplementation 'org.mockito:mockito-core:4.3.1'
api 'org.apache.commons:commons-lang3:3.12.0'
api 'com.github.clubobsidian:wrappy:2.3.2'
+ api 'com.github.ben-manes.caffeine:caffeine:3.0.4'
+ compileOnly "cloud.commandframework:cloud-core:$cloudVersion"
+ testImplementation "cloud.commandframework:cloud-core:$cloudVersion"
+ api "cloud.commandframework:cloud-annotations:$cloudVersion"
+ api "io.github.classgraph:classgraph:4.8.138"
}
}
\ No newline at end of file
diff --git a/bukkit/build.gradle b/bukkit/build.gradle
index a12df18ba..e7ca6ba90 100644
--- a/bukkit/build.gradle
+++ b/bukkit/build.gradle
@@ -9,39 +9,13 @@ processResources {
}
shadowJar {
- minimize()
- relocate 'org.spongepowered.configurate', 'com.clubobsidian.dynamicgui.shaded.configurate'
- relocate 'com.google.common', 'com.clubobsidian.dynamicgui.shaded.guava'
- relocate 'com.google.gson', 'com.clubobsidian.dynamicgui.shaded.gson'
- relocate 'org.yaml.snakeyaml', 'com.clubobsidian.dynamicgui.shaded.snakeyaml'
- relocate 'com.clubobsidian.trident', 'com.clubobsidian.dynamicgui.shaded.trident'
- relocate 'com.clubobsidian.wrappy', 'com.clubobsidian.dynamicgui.shaded.wrappy'
- relocate 'net.kyori', 'com.clubobsidian.dynamicgui.shaded.kyori'
- relocate 'com.clubobsidian.fuzzutil', 'com.clubobsidian.dynamicgui.shaded.fuzzutil'
- relocate 'io.leangen', 'com.clubobsidian.dynamicgui.shaded.leangen'
- relocate 'org.codehaus.mojo', 'com.clubobsidian.dynamicgui.shaded.mojo'
- relocate 'org.checkerframework.framework', 'com.clubobsidian.dynamicgui.shaded.checkerframework.framework'
- relocate 'org.checkerframework.common', 'com.clubobsidian.dynamicgui.shaded.checkerframework.common'
- relocate 'org.checkerframework.checker', 'com.clubobsidian.dynamicgui.shaded.checkerframework.checker'
- relocate 'org.apache.commons', 'com.clubobsidian.dynamicgui.shaded.apachecommons'
- relocate 'org.aopalliance.intercept', 'com.clubobsidian.dynamicgui.shaded.aopalliance.intercept'
- relocate 'org.aopalliance.aop', 'com.clubobsidian.dynamicgui.shaded.aopalliance.aop'
- relocate 'javax.inject', 'com.clubobsidian.dynamicgui.shaded.javax.inject'
- relocate 'com.udojava.evalex', 'com.clubobsidian.dynamicgui.shaded.evalex'
- relocate 'com.typesafe.config', 'com.clubobsidian.dynamicgui.shaded.typesafeconfig'
- relocate 'com.google.j2objc', 'com.clubobsidian.dynamicgui.shaded.j2objc'
- relocate 'com.google.inject', 'com.clubobsidian.dynamicgui.shaded.guice'
- relocate 'javax.annotation', 'com.clubobsidian.dynamicgui.shaded.javaxannotation'
- relocate 'com.google.errorprone', 'com.clubobsidian.dynamicgui.shaded.errorprone'
- relocate 'com.fasterxml.jackson', 'com.clubobsidian.dynamicgui.shaded.jackson'
-
- archiveBaseName.set('DynamicGui')
- archiveClassifier.set('')
+ archiveBaseName.set('DynamicGui-Bukkit')
}
dependencies {
implementation project(path: ':core')
- compileOnly 'com.github.clubobsidian:foundry:2.0.1'
+ compileOnly 'com.github.clubobsidian:foundry:2.0.2'
compileOnly 'org.spigotmc:spigot-api:1.8.8-R0.1-SNAPSHOT'
compileOnly 'net.md-5:bungeecord-api:1.8-SNAPSHOT'
+ implementation "cloud.commandframework:cloud-paper:$cloudVersion"
}
\ No newline at end of file
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/command/BukkitGuiCommandSender.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/command/BukkitGuiCommandSender.java
new file mode 100644
index 000000000..beb05bff3
--- /dev/null
+++ b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/command/BukkitGuiCommandSender.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.bukkit.command;
+
+import com.clubobsidian.dynamicgui.core.command.GuiCommandSender;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class BukkitGuiCommandSender implements GuiCommandSender {
+
+ private final CommandSender sender;
+
+ public BukkitGuiCommandSender(CommandSender sender) {
+ this.sender = sender;
+ }
+
+ @Override
+ public Object getNativeSender() {
+ return this.sender;
+ }
+
+ @Override
+ public boolean isPlayer() {
+ return this.sender instanceof Player;
+ }
+
+ @Override
+ public void sendMessage(String message) {
+ this.sender.sendMessage(message);
+ }
+}
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/command/cloud/BukkitCloudExtender.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/command/cloud/BukkitCloudExtender.java
new file mode 100644
index 000000000..7bcabad81
--- /dev/null
+++ b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/command/cloud/BukkitCloudExtender.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.bukkit.command.cloud;
+
+import cloud.commandframework.Command;
+import cloud.commandframework.CommandManager;
+import cloud.commandframework.arguments.CommandArgument;
+import cloud.commandframework.bukkit.BukkitPluginRegistrationHandler;
+import cloud.commandframework.internal.CommandRegistrationHandler;
+import com.clubobsidian.dynamicgui.core.Key;
+import com.clubobsidian.dynamicgui.core.command.cloud.CloudExtender;
+import com.clubobsidian.dynamicgui.core.util.ReflectionUtil;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+public class BukkitCloudExtender implements CloudExtender {
+
+ private final boolean brigadierEnabled = this.checkForBrigadier();
+
+ @Override
+ public boolean unregister(CommandManager commandManager, Command command, String alias) {
+ BukkitPluginRegistrationHandler handler = (BukkitPluginRegistrationHandler)
+ commandManager.getCommandRegistrationHandler();
+ boolean handlerUnregistered = this.unregisterHandler(handler, alias);
+ boolean aliasesUnregistered = this.unregisterAliases(handler, alias);
+ boolean bukkitUnregistered = this.unregisterBukkitCommand(handler, alias);
+ boolean brigadierUnregistered = this.unregisterBrigadier(alias);
+ return handlerUnregistered || aliasesUnregistered || bukkitUnregistered || brigadierUnregistered;
+ }
+
+ private boolean checkForBrigadier() {
+ try {
+ Class.forName("com.mojang.brigadier.CommandDispatcher");
+ return true;
+ } catch(ClassNotFoundException ex) {
+ return false;
+ }
+ }
+
+ private boolean unregisterBukkitCommand(BukkitPluginRegistrationHandler handler, String alias) {
+ Map bukkitCommands =
+ ReflectionUtil.get(handler, handler.getClass(), "bukkitCommands");
+ boolean removed = bukkitCommands.remove(alias) != null;
+ boolean namespaceRemoved = bukkitCommands.remove(Key.create(alias).toString()) != null;
+ return removed || namespaceRemoved;
+ }
+
+ private boolean unregisterHandler(CommandRegistrationHandler handler, String alias) {
+ Map, org.bukkit.command.Command> registeredCommands =
+ ReflectionUtil.get(handler, BukkitPluginRegistrationHandler.class, "registeredCommands");
+ Iterator, org.bukkit.command.Command>> it = registeredCommands.entrySet().iterator();
+ boolean removed = false;
+ String namespaceAlias = Key.create(alias).toString();
+ while (it.hasNext()) {
+ org.bukkit.command.Command command = it.next().getValue();
+ if(command.getName().equals(alias)
+ || command.getName().equals(namespaceAlias)
+ || command.getAliases().contains(alias)
+ || command.getAliases().contains(namespaceAlias)
+ || command.getLabel().equals(alias)
+ || command.getLabel().equals(namespaceAlias)) {
+ it.remove();
+ removed = true;
+ }
+ }
+ return removed;
+ }
+
+ private boolean unregisterAliases(BukkitPluginRegistrationHandler handler, String alias) {
+ Set aliases = ReflectionUtil.get(handler, handler.getClass(), "recognizedAliases");
+ boolean original = aliases.remove(alias);
+ boolean namespace = aliases.remove(Key.create(alias).toString());
+ return original || namespace;
+ }
+
+ private boolean unregisterBrigadier(String alias) {
+ if (this.brigadierEnabled) {
+ //TODO - implement unregistering brigadier
+ }
+ return false;
+ }
+}
\ No newline at end of file
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/economy/bukkit/VaultEconomy.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/economy/VaultEconomy.java
similarity index 75%
rename from bukkit/src/main/java/com/clubobsidian/dynamicgui/economy/bukkit/VaultEconomy.java
rename to bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/economy/VaultEconomy.java
index 932f3837b..0d4fde067 100644
--- a/bukkit/src/main/java/com/clubobsidian/dynamicgui/economy/bukkit/VaultEconomy.java
+++ b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/economy/VaultEconomy.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,10 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.economy.bukkit;
-import com.clubobsidian.dynamicgui.economy.Economy;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
+package com.clubobsidian.dynamicgui.bukkit.economy;
+
+import com.clubobsidian.dynamicgui.core.economy.Economy;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.plugin.Plugin;
@@ -36,18 +37,18 @@ public class VaultEconomy implements Economy {
@Override
public boolean setup() {
Plugin vault = Bukkit.getServer().getPluginManager().getPlugin("Vault");
- if(vault == null) {
+ if (vault == null) {
return false;
}
try {
economyClass = Class.forName("net.milkbowl.vault.economy.Economy");
- } catch(ClassNotFoundException e) {
+ } catch (ClassNotFoundException e) {
e.printStackTrace();
return false;
}
- if(this.economyClass == null) {
+ if (this.economyClass == null) {
return false;
}
@@ -58,18 +59,18 @@ public boolean setup() {
@Override
public BigDecimal getBalance(PlayerWrapper> playerWrapper) {
double balance = -1;
- if(this.getBalanceMethod == null) {
+ if (this.getBalanceMethod == null) {
try {
this.getBalanceMethod = this.economyClass.getDeclaredMethod("getBalance", OfflinePlayer.class);
this.getBalanceMethod.setAccessible(true);
- } catch(NoSuchMethodException | SecurityException e) {
+ } catch (NoSuchMethodException | SecurityException e) {
e.printStackTrace();
}
}
try {
balance = (double) this.getBalanceMethod.invoke(this.economy, playerWrapper.getPlayer());
- } catch(IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+ } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
}
@@ -78,14 +79,14 @@ public BigDecimal getBalance(PlayerWrapper> playerWrapper) {
@Override
public boolean withdraw(PlayerWrapper> playerWrapper, BigDecimal amt) {
- if(amt.doubleValue() < 0)
+ if (amt.doubleValue() < 0)
return false;
- if(this.withdrawPlayerMethod == null) {
+ if (this.withdrawPlayerMethod == null) {
try {
this.withdrawPlayerMethod = this.economyClass.getDeclaredMethod("withdrawPlayer", OfflinePlayer.class, double.class);
this.withdrawPlayerMethod.setAccessible(true);
- } catch(NoSuchMethodException | SecurityException e) {
+ } catch (NoSuchMethodException | SecurityException e) {
e.printStackTrace();
}
}
@@ -93,11 +94,11 @@ public boolean withdraw(PlayerWrapper> playerWrapper, BigDecimal amt) {
double amtDouble = amt.doubleValue();
double balance = this.getBalance(playerWrapper).doubleValue();
- if(balance >= amtDouble) {
+ if (balance >= amtDouble) {
try {
this.withdrawPlayerMethod.invoke(this.economy, playerWrapper.getPlayer(), amtDouble);
return true;
- } catch(IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+ } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
}
}
@@ -107,21 +108,21 @@ public boolean withdraw(PlayerWrapper> playerWrapper, BigDecimal amt) {
@Override
public boolean deposit(PlayerWrapper> playerWrapper, BigDecimal amt) {
- if(amt.doubleValue() < 0)
+ if (amt.doubleValue() < 0)
return false;
- if(this.depositPlayerMethod == null) {
+ if (this.depositPlayerMethod == null) {
try {
this.depositPlayerMethod = this.economyClass.getDeclaredMethod("depositPlayer", OfflinePlayer.class, double.class);
this.depositPlayerMethod.setAccessible(true);
- } catch(NoSuchMethodException | SecurityException e) {
+ } catch (NoSuchMethodException | SecurityException e) {
e.printStackTrace();
}
}
try {
this.depositPlayerMethod.invoke(this.economy, playerWrapper.getPlayer(), amt.doubleValue());
- } catch(IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+ } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
}
return true;
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/entity/bukkit/BukkitEntityWrapper.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/entity/BukkitEntityWrapper.java
similarity index 82%
rename from bukkit/src/main/java/com/clubobsidian/dynamicgui/entity/bukkit/BukkitEntityWrapper.java
rename to bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/entity/BukkitEntityWrapper.java
index 88210f30f..e75b494bc 100644
--- a/bukkit/src/main/java/com/clubobsidian/dynamicgui/entity/bukkit/BukkitEntityWrapper.java
+++ b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/entity/BukkitEntityWrapper.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,9 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.entity.bukkit;
-import com.clubobsidian.dynamicgui.entity.EntityWrapper;
+package com.clubobsidian.dynamicgui.bukkit.entity;
+
+import com.clubobsidian.dynamicgui.core.entity.EntityWrapper;
import org.bukkit.entity.Entity;
public class BukkitEntityWrapper extends EntityWrapper {
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/entity/bukkit/BukkitPlayerWrapper.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/entity/BukkitPlayerWrapper.java
similarity index 57%
rename from bukkit/src/main/java/com/clubobsidian/dynamicgui/entity/bukkit/BukkitPlayerWrapper.java
rename to bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/entity/BukkitPlayerWrapper.java
index 97ba19269..d6790d046 100644
--- a/bukkit/src/main/java/com/clubobsidian/dynamicgui/entity/bukkit/BukkitPlayerWrapper.java
+++ b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/entity/BukkitPlayerWrapper.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,32 +13,35 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.entity.bukkit;
-
-import com.clubobsidian.dynamicgui.DynamicGui;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.inventory.InventoryWrapper;
-import com.clubobsidian.dynamicgui.inventory.ItemStackWrapper;
-import com.clubobsidian.dynamicgui.inventory.bukkit.BukkitInventoryWrapper;
-import com.clubobsidian.dynamicgui.inventory.bukkit.BukkitItemStackWrapper;
-import com.clubobsidian.dynamicgui.manager.world.LocationManager;
-import com.clubobsidian.dynamicgui.plugin.DynamicGuiPlugin;
-import com.clubobsidian.dynamicgui.util.Statistic;
-import com.clubobsidian.dynamicgui.util.Statistic.StatisticType;
-import com.clubobsidian.dynamicgui.world.LocationWrapper;
+
+package com.clubobsidian.dynamicgui.bukkit.entity;
+
+import com.clubobsidian.dynamicgui.bukkit.inventory.BukkitInventoryWrapper;
+import com.clubobsidian.dynamicgui.bukkit.inventory.BukkitItemStackWrapper;
+import com.clubobsidian.dynamicgui.core.DynamicGui;
+import com.clubobsidian.dynamicgui.core.effect.ParticleWrapper;
+import com.clubobsidian.dynamicgui.core.effect.SoundWrapper;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.inventory.InventoryWrapper;
+import com.clubobsidian.dynamicgui.core.inventory.ItemStackWrapper;
+import com.clubobsidian.dynamicgui.core.manager.world.LocationManager;
+import com.clubobsidian.dynamicgui.core.plugin.DynamicGuiPlugin;
+import com.clubobsidian.dynamicgui.core.world.LocationWrapper;
+import com.google.common.collect.ForwardingMultimap;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.chat.ComponentSerializer;
import org.bukkit.Effect;
import org.bukkit.Location;
-import org.bukkit.Material;
import org.bukkit.Sound;
-import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Collection;
import java.util.UUID;
public class BukkitPlayerWrapper extends PlayerWrapper {
@@ -107,7 +110,7 @@ public int getLevel() {
@Override
public InventoryWrapper getOpenInventoryWrapper() {
InventoryView openInventory = this.getPlayer().getOpenInventory();
- if(openInventory == null) {
+ if (openInventory == null) {
return null;
}
return new BukkitInventoryWrapper(openInventory.getTopInventory());
@@ -121,7 +124,7 @@ public ItemStackWrapper getItemInHand() {
@Override
public void closeInventory() {
- if(this.getPlayer().getOpenInventory() != null) {
+ if (this.getPlayer().getOpenInventory() != null) {
this.getPlayer().getOpenInventory().close();
}
}
@@ -129,67 +132,84 @@ public void closeInventory() {
@Override
public void openInventory(InventoryWrapper> inventoryWrapper) {
Object inventory = inventoryWrapper.getInventory();
- if(inventory instanceof Inventory) {
+ if (inventory instanceof Inventory) {
this.getPlayer().openInventory((Inventory) inventory);
}
}
@Override
- public void sendPluginMessage(DynamicGuiPlugin plugin, String channel, byte[] message) {
- this.getPlayer().sendPluginMessage((Plugin) plugin, channel, message);
+ public void sendPluginMessage(String channel, byte[] message) {
+ this.getPlayer().sendPluginMessage((Plugin) DynamicGui.get().getPlugin(), channel, message);
}
@Override
- public void playSound(String sound, Float volume, Float pitch) {
+ public void playSound(SoundWrapper.SoundData soundData) {
+ String sound = soundData.getSound();
+ float volume = soundData.getVolume();
+ float pitch = soundData.getPitch();
Player player = this.getPlayer();
Location playerLocation = player.getLocation();
player.playSound(playerLocation, Sound.valueOf(sound), volume, pitch);
}
@Override
- public void playEffect(String effect, int data) {
+ public void playEffect(ParticleWrapper.ParticleData particleData) {
+ String effect = particleData.getEffect();
+ int extraData = particleData.getExtraData();
Player player = this.getPlayer();
Location playerLocation = player.getLocation();
- playerLocation.getWorld().playEffect(playerLocation, Effect.valueOf(effect), data);
+ playerLocation.getWorld().playEffect(playerLocation, Effect.valueOf(effect), extraData);
}
@Override
- public int getStatistic(Statistic statistic) {
- try {
- return this.getPlayer().getStatistic(org.bukkit.Statistic.valueOf(statistic.getBukkitID()));
- } catch(Exception ex) {
- return -1;
- }
+ public void updateInventory() {
+ this.getPlayer().updateInventory();
}
@Override
- public int getStatistic(Statistic statistic, String data) {
- if(data == null) {
- return -1;
- }
- String upperData = data.toUpperCase();
+ public LocationWrapper> getLocation() {
+ Location bukkitLoc = this.getPlayer().getLocation();
+ return LocationManager.get().toLocationWrapper(bukkitLoc);
+ }
- try {
- if(StatisticType.MATERIAL == statistic.getStatisticType()) {
- return this.getPlayer().getStatistic(org.bukkit.Statistic.valueOf(statistic.getBukkitID()), Material.valueOf(upperData));
- } else if(StatisticType.ENTITY == statistic.getStatisticType()) {
- return this.getPlayer().getStatistic(org.bukkit.Statistic.valueOf(statistic.getBukkitID()), EntityType.valueOf(upperData));
- }
- } catch(Exception ex) {
- //Ignore and return -1
- return -1;
- }
- return 0;
+ @Override
+ public boolean isOnline() {
+ return this.getPlayer().isOnline();
}
@Override
- public void updateInventory() {
- this.getPlayer().updateInventory();
+ public String getSkinTexture() {
+ try {
+ Object profile = this.getPlayer().getClass().getDeclaredMethod("getProfile").invoke(this.getPlayer());
+ Object properties = profile.getClass()
+ .getDeclaredMethod("getProperties")
+ .invoke(profile);
+ Class> forwardingMap = Class.forName(
+ new String(new byte[]{'c', 'o', 'm', '.'}) +
+ "google." +
+ "common." +
+ "collect." +
+ "ForwardingMultimap"); //We relocate guava so we have to do this
+ Object property = null;
+ for (Method m : forwardingMap.getDeclaredMethods()) {
+ if (m.getName().equals("get")) {
+ property = ((Collection) (m.invoke(properties, "textures")))
+ .stream().findFirst().orElse(null);
+ break;
+ }
+ }
+ if (property == null) {
+ return null;
+ }
+ return (String) property.getClass().getDeclaredMethod("getValue").invoke(property);
+ } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | ClassNotFoundException e) {
+ e.printStackTrace();
+ return null;
+ }
}
@Override
- public LocationWrapper> getLocation() {
- Location bukkitLoc = this.getPlayer().getLocation();
- return LocationManager.get().toLocationWrapper(bukkitLoc);
+ public void updateCursor() {
+ this.getPlayer().setItemOnCursor(this.getPlayer().getItemOnCursor());
}
}
\ No newline at end of file
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/inject/BukkitPluginModule.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/inject/BukkitPluginModule.java
new file mode 100644
index 000000000..793004bbf
--- /dev/null
+++ b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/inject/BukkitPluginModule.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.bukkit.inject;
+
+import cloud.commandframework.CommandManager;
+import com.clubobsidian.dynamicgui.bukkit.command.cloud.BukkitCloudExtender;
+import com.clubobsidian.dynamicgui.bukkit.manager.entity.BukkitEntityManager;
+import com.clubobsidian.dynamicgui.bukkit.manager.inventory.BukkitInventoryManager;
+import com.clubobsidian.dynamicgui.bukkit.manager.inventory.BukkitItemStackManager;
+import com.clubobsidian.dynamicgui.bukkit.manager.material.BukkitMaterialManager;
+import com.clubobsidian.dynamicgui.bukkit.manager.world.BukkitLocationManager;
+import com.clubobsidian.dynamicgui.core.command.GuiCommandSender;
+import com.clubobsidian.dynamicgui.core.command.cloud.CloudExtender;
+import com.clubobsidian.dynamicgui.core.inject.module.PluginModule;
+import com.clubobsidian.dynamicgui.core.logger.LoggerWrapper;
+import com.clubobsidian.dynamicgui.core.manager.entity.EntityManager;
+import com.clubobsidian.dynamicgui.core.manager.inventory.InventoryManager;
+import com.clubobsidian.dynamicgui.core.manager.inventory.ItemStackManager;
+import com.clubobsidian.dynamicgui.core.manager.material.MaterialManager;
+import com.clubobsidian.dynamicgui.core.manager.world.LocationManager;
+import com.clubobsidian.dynamicgui.core.platform.Platform;
+import com.clubobsidian.dynamicgui.core.plugin.DynamicGuiPlugin;
+
+public class BukkitPluginModule extends PluginModule {
+
+ public BukkitPluginModule(DynamicGuiPlugin plugin,
+ Platform platform,
+ LoggerWrapper> logger,
+ CommandManager commandManager) {
+ super(plugin, platform, logger, commandManager);
+ }
+
+ @Override
+ public Class extends EntityManager> getEntityManager() {
+ return BukkitEntityManager.class;
+ }
+
+ @Override
+ public Class extends InventoryManager> getInventoryManager() {
+ return BukkitInventoryManager.class;
+ }
+
+ @Override
+ public Class extends ItemStackManager> getItemStackManager() {
+ return BukkitItemStackManager.class;
+ }
+
+ @Override
+ public Class extends MaterialManager> getMaterialManager() {
+ return BukkitMaterialManager.class;
+ }
+
+ @Override
+ public Class extends LocationManager> getLocationManger() {
+ return BukkitLocationManager.class;
+ }
+
+ @Override
+ public Class extends CloudExtender> getPlatformExtender() {
+ return BukkitCloudExtender.class;
+ }
+}
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/inventory/bukkit/BukkitInventoryWrapper.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/inventory/BukkitInventoryWrapper.java
similarity index 81%
rename from bukkit/src/main/java/com/clubobsidian/dynamicgui/inventory/bukkit/BukkitInventoryWrapper.java
rename to bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/inventory/BukkitInventoryWrapper.java
index 3bbf2f8ec..e547e7fb1 100644
--- a/bukkit/src/main/java/com/clubobsidian/dynamicgui/inventory/bukkit/BukkitInventoryWrapper.java
+++ b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/inventory/BukkitInventoryWrapper.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,12 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.inventory.bukkit;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.inventory.InventoryWrapper;
-import com.clubobsidian.dynamicgui.inventory.ItemStackWrapper;
-import com.clubobsidian.dynamicgui.util.bukkit.BukkitPacketUtil;
+package com.clubobsidian.dynamicgui.bukkit.inventory;
+
+import com.clubobsidian.dynamicgui.bukkit.util.BukkitPacketUtil;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.inventory.InventoryWrapper;
+import com.clubobsidian.dynamicgui.core.inventory.ItemStackWrapper;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
@@ -41,7 +42,7 @@ public BukkitInventoryWrapper(T inventory) {
public ItemStackWrapper>[] getContents() {
ItemStack[] bukkitContents = this.getInventory().getContents();
ItemStackWrapper>[] wrapperContents = new ItemStackWrapper>[bukkitContents.length];
- for(int i = 0; i < bukkitContents.length; i++) {
+ for (int i = 0; i < bukkitContents.length; i++) {
ItemStack itemStack = bukkitContents[i];
ItemStackWrapper> wrapped = new BukkitItemStackWrapper<>(itemStack);
wrapperContents[i] = wrapped;
@@ -76,8 +77,8 @@ public int getSize() {
@Override
public int getCurrentContentSize() {
int contentSize = 0;
- for(ItemStack item : this.getInventory().getContents()) {
- if(item != null && item.getType() != Material.AIR) {
+ for (ItemStack item : this.getInventory().getContents()) {
+ if (item != null && item.getType() != Material.AIR) {
contentSize += 1;
}
}
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/inventory/bukkit/BukkitItemStackWrapper.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/inventory/BukkitItemStackWrapper.java
similarity index 84%
rename from bukkit/src/main/java/com/clubobsidian/dynamicgui/inventory/bukkit/BukkitItemStackWrapper.java
rename to bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/inventory/BukkitItemStackWrapper.java
index a35d0994d..a3834f81a 100644
--- a/bukkit/src/main/java/com/clubobsidian/dynamicgui/inventory/bukkit/BukkitItemStackWrapper.java
+++ b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/inventory/BukkitItemStackWrapper.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,12 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.inventory.bukkit;
-import com.clubobsidian.dynamicgui.enchantment.EnchantmentWrapper;
-import com.clubobsidian.dynamicgui.inventory.ItemStackWrapper;
-import com.clubobsidian.dynamicgui.manager.material.MaterialManager;
-import com.clubobsidian.dynamicgui.util.bukkit.BukkitNBTUtil;
+package com.clubobsidian.dynamicgui.bukkit.inventory;
+
+import com.clubobsidian.dynamicgui.bukkit.util.BukkitNBTUtil;
+import com.clubobsidian.dynamicgui.core.enchantment.EnchantmentWrapper;
+import com.clubobsidian.dynamicgui.core.inventory.ItemStackWrapper;
+import com.clubobsidian.dynamicgui.core.manager.material.MaterialManager;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemFlag;
@@ -48,7 +49,7 @@ private static Method setCustomModelData() {
Method set = ItemMeta.class.getDeclaredMethod("setCustomModelData", Integer.class);
set.setAccessible(true);
return set;
- } catch(NoSuchMethodException e) {
+ } catch (NoSuchMethodException e) {
return null;
}
}
@@ -58,7 +59,7 @@ private static Method hasCustomModelData() {
Method has = ItemMeta.class.getDeclaredMethod("hasCustomModelData");
has.setAccessible(true);
return has;
- } catch(NoSuchMethodException e) {
+ } catch (NoSuchMethodException e) {
return null;
}
}
@@ -68,7 +69,7 @@ private static Method getCustomModelData() {
Method get = ItemMeta.class.getDeclaredMethod("getCustomModelData");
get.setAccessible(true);
return get;
- } catch(NoSuchMethodException e) {
+ } catch (NoSuchMethodException e) {
return null;
}
}
@@ -99,7 +100,7 @@ public String getType() {
@Override
public boolean setType(final String type) {
- if(type == null) {
+ if (type == null) {
return false;
}
@@ -108,7 +109,7 @@ public boolean setType(final String type) {
try {
mat = Material.valueOf(normalizedType);
- } catch(Exception ex) {
+ } catch (Exception ex) {
return false;
}
@@ -119,7 +120,7 @@ public boolean setType(final String type) {
@Override
public String getName() {
ItemMeta itemMeta = this.getItemStack().getItemMeta();
- if(itemMeta.hasDisplayName()) {
+ if (itemMeta.hasDisplayName()) {
return itemMeta.getDisplayName();
}
return null;
@@ -135,7 +136,7 @@ public void setName(String name) {
@Override
public List getLore() {
ItemMeta itemMeta = this.getItemStack().getItemMeta();
- if(!itemMeta.hasLore()) {
+ if (!itemMeta.hasLore()) {
return new ArrayList<>();
}
@@ -177,9 +178,9 @@ public void removeEnchant(EnchantmentWrapper enchant) {
public List getEnchants() {
List enchants = new ArrayList<>();
ItemMeta itemMeta = this.getItemStack().getItemMeta();
- if(itemMeta.hasEnchants()) {
+ if (itemMeta.hasEnchants()) {
Iterator> it = itemMeta.getEnchants().entrySet().iterator();
- while(it.hasNext()) {
+ while (it.hasNext()) {
Entry next = it.next();
enchants.add(new EnchantmentWrapper(next.getKey().getName(), next.getValue()));
}
@@ -197,25 +198,25 @@ public void setNBT(String nbt) {
ItemStack oldItemStack = this.getItemStack();
ItemStack newItemStack = BukkitNBTUtil.setTag(this.getItemStack(), nbt);
- if(oldItemStack.hasItemMeta()) {
+ if (oldItemStack.hasItemMeta()) {
ItemMeta meta = oldItemStack.getItemMeta();
ItemMeta newMeta = newItemStack.getItemMeta();
- if(meta.hasDisplayName()) {
+ if (meta.hasDisplayName()) {
newMeta.setDisplayName(meta.getDisplayName());
}
- if(meta.hasEnchants()) {
+ if (meta.hasEnchants()) {
Iterator> it = meta.getEnchants().entrySet().iterator();
- while(it.hasNext()) {
+ while (it.hasNext()) {
Entry next = it.next();
newMeta.addEnchant(next.getKey(), next.getValue(), true);
}
}
- if(meta.hasLore()) {
+ if (meta.hasLore()) {
newMeta.setLore(meta.getLore());
}
- for(ItemFlag flag : meta.getItemFlags()) {
+ for (ItemFlag flag : meta.getItemFlags()) {
newMeta.addItemFlags(flag);
}
@@ -229,7 +230,7 @@ public void setNBT(String nbt) {
public void setGlowing(boolean glowing) {
ItemStack item = this.getItemStack();
ItemMeta meta = item.getItemMeta();
- if(glowing) {
+ if (glowing) {
meta.addEnchant(Enchantment.DIG_SPEED, -1, true);
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
} else {
@@ -237,7 +238,6 @@ public void setGlowing(boolean glowing) {
meta.removeItemFlags(ItemFlag.HIDE_ENCHANTS);
}
-
item.setItemMeta(meta);
}
@@ -245,9 +245,9 @@ public void setGlowing(boolean glowing) {
public void addItemFlags(List itemFlags) {
ItemStack item = this.getItemStack();
ItemMeta meta = item.getItemMeta();
- for(String itemFlag : itemFlags) {
+ for (String itemFlag : itemFlags) {
ItemFlag flag = ItemFlag.valueOf(itemFlag);
- if(flag != null) {
+ if (flag != null) {
meta.addItemFlags(flag);
}
}
@@ -261,7 +261,7 @@ public boolean isSimilar(ItemStackWrapper> compareTo) {
@Override
public boolean setModel(int data) {
- if(SET_CUSTOM_MODEL_DATA == null) {
+ if (SET_CUSTOM_MODEL_DATA == null) {
return false;
}
ItemMeta meta = getItemStack().getItemMeta();
@@ -269,7 +269,7 @@ public boolean setModel(int data) {
SET_CUSTOM_MODEL_DATA.invoke(meta, data);
this.getItemStack().setItemMeta(meta);
return true;
- } catch(IllegalAccessException | InvocationTargetException ex) {
+ } catch (IllegalAccessException | InvocationTargetException ex) {
ex.printStackTrace();
return false;
}
@@ -277,13 +277,13 @@ public boolean setModel(int data) {
@Override
public boolean hasCustomModel() {
- if(HAS_CUSTOM_MODEL_DATA == null) {
+ if (HAS_CUSTOM_MODEL_DATA == null) {
return false;
}
ItemMeta meta = getItemStack().getItemMeta();
try {
return (boolean) HAS_CUSTOM_MODEL_DATA.invoke(meta);
- } catch(IllegalAccessException | InvocationTargetException ex) {
+ } catch (IllegalAccessException | InvocationTargetException ex) {
ex.printStackTrace();
}
return false;
@@ -291,13 +291,13 @@ public boolean hasCustomModel() {
@Override
public int getModelData() {
- if(GET_CUSTOM_MODEL_DATA == null) {
+ if (GET_CUSTOM_MODEL_DATA == null) {
return -1;
}
ItemMeta meta = getItemStack().getItemMeta();
try {
return (int) GET_CUSTOM_MODEL_DATA.invoke(meta);
- } catch(IllegalAccessException | InvocationTargetException e) {
+ } catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
return -1;
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/listener/bukkit/EntityClickListener.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/listener/EntityClickListener.java
similarity index 68%
rename from bukkit/src/main/java/com/clubobsidian/dynamicgui/listener/bukkit/EntityClickListener.java
rename to bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/listener/EntityClickListener.java
index 3ebf231a9..2681110e8 100644
--- a/bukkit/src/main/java/com/clubobsidian/dynamicgui/listener/bukkit/EntityClickListener.java
+++ b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/listener/EntityClickListener.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,13 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.listener.bukkit;
-import com.clubobsidian.dynamicgui.DynamicGui;
-import com.clubobsidian.dynamicgui.entity.EntityWrapper;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.entity.bukkit.BukkitEntityWrapper;
-import com.clubobsidian.dynamicgui.entity.bukkit.BukkitPlayerWrapper;
+package com.clubobsidian.dynamicgui.bukkit.listener;
+
+import com.clubobsidian.dynamicgui.bukkit.entity.BukkitEntityWrapper;
+import com.clubobsidian.dynamicgui.bukkit.entity.BukkitPlayerWrapper;
+import com.clubobsidian.dynamicgui.core.DynamicGui;
+import com.clubobsidian.dynamicgui.core.entity.EntityWrapper;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@@ -30,11 +31,11 @@ public class EntityClickListener implements Listener {
@EventHandler
public void onEntityClick(PlayerInteractEntityEvent e) {
- if(e.getRightClicked() != null) {
+ if (e.getRightClicked() != null) {
PlayerWrapper playerWrapper = new BukkitPlayerWrapper(e.getPlayer());
EntityWrapper entityWrapper = new BukkitEntityWrapper(e.getRightClicked());
- DynamicGui.get().getEventBus().callEvent(new com.clubobsidian.dynamicgui.event.inventory.PlayerInteractEntityEvent(playerWrapper, entityWrapper));
+ DynamicGui.get().getEventBus().callEvent(new com.clubobsidian.dynamicgui.core.event.inventory.PlayerInteractEntityEvent(playerWrapper, entityWrapper));
}
}
}
\ No newline at end of file
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/listener/bukkit/InventoryCloseListener.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/listener/InventoryCloseListener.java
similarity index 72%
rename from bukkit/src/main/java/com/clubobsidian/dynamicgui/listener/bukkit/InventoryCloseListener.java
rename to bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/listener/InventoryCloseListener.java
index a75b9c693..1e900c19f 100644
--- a/bukkit/src/main/java/com/clubobsidian/dynamicgui/listener/bukkit/InventoryCloseListener.java
+++ b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/listener/InventoryCloseListener.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,13 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.listener.bukkit;
-import com.clubobsidian.dynamicgui.DynamicGui;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.entity.bukkit.BukkitPlayerWrapper;
-import com.clubobsidian.dynamicgui.inventory.InventoryWrapper;
-import com.clubobsidian.dynamicgui.inventory.bukkit.BukkitInventoryWrapper;
+package com.clubobsidian.dynamicgui.bukkit.listener;
+
+import com.clubobsidian.dynamicgui.bukkit.entity.BukkitPlayerWrapper;
+import com.clubobsidian.dynamicgui.bukkit.inventory.BukkitInventoryWrapper;
+import com.clubobsidian.dynamicgui.core.DynamicGui;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.inventory.InventoryWrapper;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@@ -32,22 +33,22 @@ public class InventoryCloseListener implements Listener {
@EventHandler
public void inventoryClose(InventoryCloseEvent e) {
- if(e.getPlayer() instanceof Player) {
+ if (e.getPlayer() instanceof Player) {
PlayerWrapper playerWrapper = new BukkitPlayerWrapper((Player) e.getPlayer());
InventoryWrapper inventoryWrapper = new BukkitInventoryWrapper(e.getInventory());
- DynamicGui.get().getEventBus().callEvent(new com.clubobsidian.dynamicgui.event.inventory.InventoryCloseEvent(playerWrapper, inventoryWrapper));
+ DynamicGui.get().getEventBus().callEvent(new com.clubobsidian.dynamicgui.core.event.inventory.InventoryCloseEvent(playerWrapper, inventoryWrapper));
}
}
@EventHandler
public void onQuit(PlayerQuitEvent e) {
PlayerWrapper playerWrapper = new BukkitPlayerWrapper(e.getPlayer());
- DynamicGui.get().getEventBus().callEvent(new com.clubobsidian.dynamicgui.event.player.PlayerQuitEvent(playerWrapper));
+ DynamicGui.get().getEventBus().callEvent(new com.clubobsidian.dynamicgui.core.event.player.PlayerQuitEvent(playerWrapper));
}
@EventHandler
public void onKick(PlayerKickEvent e) {
PlayerWrapper playerWrapper = new BukkitPlayerWrapper(e.getPlayer());
- DynamicGui.get().getEventBus().callEvent(new com.clubobsidian.dynamicgui.event.player.PlayerKickEvent(playerWrapper));
+ DynamicGui.get().getEventBus().callEvent(new com.clubobsidian.dynamicgui.core.event.player.PlayerKickEvent(playerWrapper));
}
}
\ No newline at end of file
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/listener/bukkit/InventoryInteractListener.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/listener/InventoryInteractListener.java
similarity index 70%
rename from bukkit/src/main/java/com/clubobsidian/dynamicgui/listener/bukkit/InventoryInteractListener.java
rename to bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/listener/InventoryInteractListener.java
index 9f24ca208..8ad9b9939 100644
--- a/bukkit/src/main/java/com/clubobsidian/dynamicgui/listener/bukkit/InventoryInteractListener.java
+++ b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/listener/InventoryInteractListener.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,17 +13,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.listener.bukkit;
-import com.clubobsidian.dynamicgui.DynamicGui;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.entity.bukkit.BukkitPlayerWrapper;
-import com.clubobsidian.dynamicgui.event.inventory.Click;
-import com.clubobsidian.dynamicgui.gui.InventoryView;
-import com.clubobsidian.dynamicgui.inventory.InventoryWrapper;
-import com.clubobsidian.dynamicgui.inventory.ItemStackWrapper;
-import com.clubobsidian.dynamicgui.inventory.bukkit.BukkitInventoryWrapper;
-import com.clubobsidian.dynamicgui.inventory.bukkit.BukkitItemStackWrapper;
+package com.clubobsidian.dynamicgui.bukkit.listener;
+
+import com.clubobsidian.dynamicgui.bukkit.entity.BukkitPlayerWrapper;
+import com.clubobsidian.dynamicgui.bukkit.inventory.BukkitInventoryWrapper;
+import com.clubobsidian.dynamicgui.bukkit.inventory.BukkitItemStackWrapper;
+import com.clubobsidian.dynamicgui.core.DynamicGui;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.event.inventory.Click;
+import com.clubobsidian.dynamicgui.core.gui.InventoryView;
+import com.clubobsidian.dynamicgui.core.inventory.InventoryWrapper;
+import com.clubobsidian.dynamicgui.core.inventory.ItemStackWrapper;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@@ -43,20 +44,20 @@ public class InventoryInteractListener implements Listener {
@EventHandler
public void onInventoryClick(InventoryClickEvent e) {
Inventory inventory = e.getInventory();
- if(inventory == null) {
+ if (inventory == null) {
return;
}
int slot = e.getSlot();
int rawSlot = e.getRawSlot();
InventoryView view = InventoryView.TOP;
- if(rawSlot >= e.getInventory().getSize()) {
+ if (rawSlot >= e.getInventory().getSize()) {
view = InventoryView.BOTTOM;
}
- if(e.getWhoClicked() instanceof Player) {
+ if (e.getWhoClicked() instanceof Player) {
Click clickType = null;
- if(this.isClick(e.getClick())) {
+ if (this.isClick(e.getClick())) {
clickType = Click.valueOf(e.getClick().toString());
}
@@ -64,22 +65,22 @@ public void onInventoryClick(InventoryClickEvent e) {
InventoryWrapper> inventoryWrapper = new BukkitInventoryWrapper(inventory);
PlayerWrapper> playerWrapper = new BukkitPlayerWrapper(player);
ItemStack itemStack = null;
- if(rawSlot >= inventory.getSize()) {
+ if (rawSlot >= inventory.getSize()) {
itemStack = e.getWhoClicked().getInventory().getItem(slot);
- } else if(slot >= 0 && slot < inventory.getSize()) {
+ } else if (slot >= 0 && slot < inventory.getSize()) {
itemStack = e.getInventory().getItem(slot);
}
ItemStackWrapper> itemStackWrapper = null;
- if(itemStack == null) {
+ if (itemStack == null) {
itemStackWrapper = new BukkitItemStackWrapper(null);
} else {
itemStackWrapper = new BukkitItemStackWrapper(itemStack);
}
- com.clubobsidian.dynamicgui.event.inventory.InventoryClickEvent clickEvent = new com.clubobsidian.dynamicgui.event.inventory.InventoryClickEvent(playerWrapper, inventoryWrapper, itemStackWrapper, slot, clickType, view);
+ com.clubobsidian.dynamicgui.core.event.inventory.InventoryClickEvent clickEvent = new com.clubobsidian.dynamicgui.core.event.inventory.InventoryClickEvent(playerWrapper, inventoryWrapper, itemStackWrapper, slot, clickType, view);
DynamicGui.get().getEventBus().callEvent(clickEvent);
- if(clickEvent.isCanceled()) {
+ if (clickEvent.isCancelled()) {
e.setCancelled(true);
}
}
@@ -88,18 +89,18 @@ public void onInventoryClick(InventoryClickEvent e) {
@EventHandler
public void onInventoryDrag(InventoryDragEvent e) {
Inventory inventory = e.getInventory();
- if(inventory == null) {
+ if (inventory == null) {
return;
}
- if(e.getWhoClicked() instanceof Player) {
+ if (e.getWhoClicked() instanceof Player) {
Player player = (Player) e.getWhoClicked();
PlayerWrapper> playerWrapper = new BukkitPlayerWrapper(player);
InventoryWrapper> inventoryWrapper = new BukkitInventoryWrapper(inventory);
Map> slotItems = this.wrapItemStacks(e.getNewItems());
- com.clubobsidian.dynamicgui.event.inventory.InventoryDragEvent dragEvent = new com.clubobsidian.dynamicgui.event.inventory.InventoryDragEvent(playerWrapper, inventoryWrapper, slotItems);
+ com.clubobsidian.dynamicgui.core.event.inventory.InventoryDragEvent dragEvent = new com.clubobsidian.dynamicgui.core.event.inventory.InventoryDragEvent(playerWrapper, inventoryWrapper, slotItems);
DynamicGui.get().getEventBus().callEvent(dragEvent);
- if(dragEvent.isCanceled()) {
+ if (dragEvent.isCancelled()) {
e.setCancelled(true);
}
}
@@ -108,7 +109,7 @@ public void onInventoryDrag(InventoryDragEvent e) {
private Map> wrapItemStacks(Map stackMap) {
Map> wrapperMap = new TreeMap<>();
Iterator> it = stackMap.entrySet().iterator();
- while(it.hasNext()) {
+ while (it.hasNext()) {
Entry next = it.next();
int rawSlot = next.getKey();
ItemStack original = next.getValue();
@@ -120,7 +121,7 @@ private Map> wrapItemStacks(Map
}
private boolean isClick(ClickType type) {
- switch(type) {
+ switch (type) {
case LEFT:
return true;
case RIGHT:
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/listener/bukkit/InventoryOpenListener.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/listener/InventoryOpenListener.java
similarity index 66%
rename from bukkit/src/main/java/com/clubobsidian/dynamicgui/listener/bukkit/InventoryOpenListener.java
rename to bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/listener/InventoryOpenListener.java
index ca3ec0e7c..c381cb2cc 100644
--- a/bukkit/src/main/java/com/clubobsidian/dynamicgui/listener/bukkit/InventoryOpenListener.java
+++ b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/listener/InventoryOpenListener.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,13 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.listener.bukkit;
-import com.clubobsidian.dynamicgui.DynamicGui;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.entity.bukkit.BukkitPlayerWrapper;
-import com.clubobsidian.dynamicgui.inventory.InventoryWrapper;
-import com.clubobsidian.dynamicgui.inventory.bukkit.BukkitInventoryWrapper;
+package com.clubobsidian.dynamicgui.bukkit.listener;
+
+import com.clubobsidian.dynamicgui.bukkit.entity.BukkitPlayerWrapper;
+import com.clubobsidian.dynamicgui.bukkit.inventory.BukkitInventoryWrapper;
+import com.clubobsidian.dynamicgui.core.DynamicGui;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.inventory.InventoryWrapper;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@@ -31,11 +32,11 @@ public class InventoryOpenListener implements Listener {
@EventHandler(priority = EventPriority.LOWEST)
public void inventoryOpen(InventoryOpenEvent e) {
- if(e.getPlayer() instanceof Player) {
+ if (e.getPlayer() instanceof Player) {
Player player = (Player) e.getPlayer();
PlayerWrapper> playerWrapper = new BukkitPlayerWrapper(player);
InventoryWrapper> inventoryWrapper = new BukkitInventoryWrapper(e.getInventory());
- com.clubobsidian.dynamicgui.event.inventory.InventoryOpenEvent inventoryOpenEvent = new com.clubobsidian.dynamicgui.event.inventory.InventoryOpenEvent(playerWrapper, inventoryWrapper);
+ com.clubobsidian.dynamicgui.core.event.inventory.InventoryOpenEvent inventoryOpenEvent = new com.clubobsidian.dynamicgui.core.event.inventory.InventoryOpenEvent(playerWrapper, inventoryWrapper);
DynamicGui.get().getEventBus().callEvent(inventoryOpenEvent);
}
}
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/listener/bukkit/PlayerInteractListener.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/listener/PlayerInteractListener.java
similarity index 59%
rename from bukkit/src/main/java/com/clubobsidian/dynamicgui/listener/bukkit/PlayerInteractListener.java
rename to bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/listener/PlayerInteractListener.java
index 372807bf5..20544974a 100644
--- a/bukkit/src/main/java/com/clubobsidian/dynamicgui/listener/bukkit/PlayerInteractListener.java
+++ b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/listener/PlayerInteractListener.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,14 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.listener.bukkit;
-import com.clubobsidian.dynamicgui.DynamicGui;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.entity.bukkit.BukkitPlayerWrapper;
-import com.clubobsidian.dynamicgui.manager.world.LocationManager;
-import com.clubobsidian.dynamicgui.world.LocationWrapper;
-import com.clubobsidian.dynamicgui.event.player.Action;
+package com.clubobsidian.dynamicgui.bukkit.listener;
+
+import com.clubobsidian.dynamicgui.bukkit.entity.BukkitPlayerWrapper;
+import com.clubobsidian.dynamicgui.core.DynamicGui;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.event.player.PlayerAction;
+import com.clubobsidian.dynamicgui.core.manager.world.LocationManager;
+import com.clubobsidian.dynamicgui.core.world.LocationWrapper;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@@ -30,13 +31,13 @@ public class PlayerInteractListener implements Listener {
@EventHandler
public void interact(final PlayerInteractEvent e) {
- if(e.getClickedBlock() != null) {
- Action action = Action.valueOf(e.getAction().toString());
+ if (e.getClickedBlock() != null) {
+ PlayerAction action = PlayerAction.valueOf(e.getAction().toString());
PlayerWrapper> playerWrapper = new BukkitPlayerWrapper(e.getPlayer());
LocationWrapper> locationWrapper = LocationManager.get().toLocationWrapper(e.getClickedBlock().getLocation());
- com.clubobsidian.dynamicgui.event.block.PlayerInteractEvent interactEvent = new com.clubobsidian.dynamicgui.event.block.PlayerInteractEvent(playerWrapper, locationWrapper, action);
+ com.clubobsidian.dynamicgui.core.event.block.PlayerInteractEvent interactEvent = new com.clubobsidian.dynamicgui.core.event.block.PlayerInteractEvent(playerWrapper, locationWrapper, action);
DynamicGui.get().getEventBus().callEvent(interactEvent);
- if(interactEvent.isCanceled()) {
+ if (interactEvent.isCancelled()) {
e.setCancelled(true);
}
}
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/manager/entity/bukkit/BukkitEntityManager.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/manager/entity/BukkitEntityManager.java
similarity index 78%
rename from bukkit/src/main/java/com/clubobsidian/dynamicgui/manager/entity/bukkit/BukkitEntityManager.java
rename to bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/manager/entity/BukkitEntityManager.java
index a0e2d36cb..038a78439 100644
--- a/bukkit/src/main/java/com/clubobsidian/dynamicgui/manager/entity/bukkit/BukkitEntityManager.java
+++ b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/manager/entity/BukkitEntityManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.manager.entity.bukkit;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.entity.bukkit.BukkitPlayerWrapper;
-import com.clubobsidian.dynamicgui.manager.entity.EntityManager;
+package com.clubobsidian.dynamicgui.bukkit.manager.entity;
+
+import com.clubobsidian.dynamicgui.bukkit.entity.BukkitPlayerWrapper;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.manager.entity.EntityManager;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
@@ -34,7 +35,7 @@ public BukkitEntityManager() {
private void loadEntityTypes() {
this.entityTypes = new ArrayList<>();
- for(EntityType type : EntityType.values()) {
+ for (EntityType type : EntityType.values()) {
this.entityTypes.add(type.name());
}
}
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/manager/inventory/bukkit/BukkitInventoryManager.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/manager/inventory/BukkitInventoryManager.java
similarity index 64%
rename from bukkit/src/main/java/com/clubobsidian/dynamicgui/manager/inventory/bukkit/BukkitInventoryManager.java
rename to bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/manager/inventory/BukkitInventoryManager.java
index 039d1f5fa..06256bded 100644
--- a/bukkit/src/main/java/com/clubobsidian/dynamicgui/manager/inventory/bukkit/BukkitInventoryManager.java
+++ b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/manager/inventory/BukkitInventoryManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.manager.inventory.bukkit;
-import com.clubobsidian.dynamicgui.inventory.InventoryWrapper;
-import com.clubobsidian.dynamicgui.inventory.bukkit.BukkitInventoryWrapper;
-import com.clubobsidian.dynamicgui.manager.inventory.InventoryManager;
+package com.clubobsidian.dynamicgui.bukkit.manager.inventory;
+
+import com.clubobsidian.dynamicgui.bukkit.inventory.BukkitInventoryWrapper;
+import com.clubobsidian.dynamicgui.core.inventory.InventoryWrapper;
+import com.clubobsidian.dynamicgui.core.manager.inventory.InventoryManager;
import org.bukkit.Bukkit;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
@@ -31,11 +32,16 @@ public Object createInventory(int size, String title) {
@Override
public Object createInventory(String title, String type) {
- return Bukkit.getServer().createInventory(null, InventoryType.valueOf(type), title);
+ try {
+ return Bukkit.getServer().createInventory(null, InventoryType.valueOf(type), title);
+ } catch(IllegalArgumentException ex) {
+ ex.printStackTrace();
+ return null;
+ }
}
@Override
public InventoryWrapper> createInventoryWrapper(Object inventory) {
- return new BukkitInventoryWrapper((Inventory) inventory);
+ return new BukkitInventoryWrapper<>((Inventory) inventory);
}
}
\ No newline at end of file
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/manager/inventory/bukkit/BukkitItemStackManager.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/manager/inventory/BukkitItemStackManager.java
similarity index 75%
rename from bukkit/src/main/java/com/clubobsidian/dynamicgui/manager/inventory/bukkit/BukkitItemStackManager.java
rename to bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/manager/inventory/BukkitItemStackManager.java
index 2aa79b999..356166195 100644
--- a/bukkit/src/main/java/com/clubobsidian/dynamicgui/manager/inventory/bukkit/BukkitItemStackManager.java
+++ b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/manager/inventory/BukkitItemStackManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.manager.inventory.bukkit;
-import com.clubobsidian.dynamicgui.inventory.ItemStackWrapper;
-import com.clubobsidian.dynamicgui.inventory.bukkit.BukkitItemStackWrapper;
-import com.clubobsidian.dynamicgui.manager.inventory.ItemStackManager;
+package com.clubobsidian.dynamicgui.bukkit.manager.inventory;
+
+import com.clubobsidian.dynamicgui.bukkit.inventory.BukkitItemStackWrapper;
+import com.clubobsidian.dynamicgui.core.inventory.ItemStackWrapper;
+import com.clubobsidian.dynamicgui.core.manager.inventory.ItemStackManager;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
@@ -30,7 +31,7 @@ public Object createItemStack(String type, int quantity) {
@Override
public ItemStackWrapper> createItemStackWrapper(Object itemStack) {
- if(itemStack == null) {
+ if (itemStack == null) {
return new BukkitItemStackWrapper<>(null);
}
return new BukkitItemStackWrapper<>((ItemStack) itemStack);
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/manager/material/bukkit/BukkitMaterialManager.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/manager/material/BukkitMaterialManager.java
similarity index 81%
rename from bukkit/src/main/java/com/clubobsidian/dynamicgui/manager/material/bukkit/BukkitMaterialManager.java
rename to bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/manager/material/BukkitMaterialManager.java
index 206679bae..bb08fce03 100644
--- a/bukkit/src/main/java/com/clubobsidian/dynamicgui/manager/material/bukkit/BukkitMaterialManager.java
+++ b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/manager/material/BukkitMaterialManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,9 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.manager.material.bukkit;
-import com.clubobsidian.dynamicgui.manager.material.MaterialManager;
+package com.clubobsidian.dynamicgui.bukkit.manager.material;
+
+import com.clubobsidian.dynamicgui.core.manager.material.MaterialManager;
import org.bukkit.Material;
import java.util.ArrayList;
@@ -31,7 +32,7 @@ public BukkitMaterialManager() {
private void loadMaterials() {
this.materials = new ArrayList<>();
- for(Material material : Material.values()) {
+ for (Material material : Material.values()) {
this.materials.add(material.name());
}
}
@@ -43,7 +44,7 @@ public List getMaterials() {
@Override
public String normalizeMaterial(String material) {
- if(material == null)
+ if (material == null)
return null;
return material.toUpperCase();
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/manager/package-info.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/manager/package-info.java
new file mode 100644
index 000000000..692ea238f
--- /dev/null
+++ b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/manager/package-info.java
@@ -0,0 +1,17 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.bukkit.manager;
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/manager/world/bukkit/BukkitLocationManager.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/manager/world/BukkitLocationManager.java
similarity index 79%
rename from bukkit/src/main/java/com/clubobsidian/dynamicgui/manager/world/bukkit/BukkitLocationManager.java
rename to bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/manager/world/BukkitLocationManager.java
index 49abd997e..16d4ea40e 100644
--- a/bukkit/src/main/java/com/clubobsidian/dynamicgui/manager/world/bukkit/BukkitLocationManager.java
+++ b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/manager/world/BukkitLocationManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.manager.world.bukkit;
-import com.clubobsidian.dynamicgui.manager.world.LocationManager;
-import com.clubobsidian.dynamicgui.world.LocationWrapper;
-import com.clubobsidian.dynamicgui.world.bukkit.BukkitWorldWrapper;
+package com.clubobsidian.dynamicgui.bukkit.manager.world;
+
+import com.clubobsidian.dynamicgui.bukkit.world.BukkitWorldWrapper;
+import com.clubobsidian.dynamicgui.core.manager.world.LocationManager;
+import com.clubobsidian.dynamicgui.core.world.LocationWrapper;
import org.bukkit.Location;
import org.bukkit.World;
@@ -31,7 +32,7 @@ public LocationWrapper> toLocationWrapper(String world, int x, int y, int z) {
@Override
public LocationWrapper> toLocationWrapper(Object obj) {
- if(!(obj instanceof Location)) {
+ if (!(obj instanceof Location)) {
return null;
}
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/inject/package-info.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/package-info.java
similarity index 86%
rename from core/src/main/java/com/clubobsidian/dynamicgui/inject/package-info.java
rename to bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/package-info.java
index e539abf5f..9e26e7c2d 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/inject/package-info.java
+++ b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/package-info.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,4 +14,4 @@
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.inject;
\ No newline at end of file
+package com.clubobsidian.dynamicgui.bukkit;
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/permission/bukkit/FoundryPermission.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/permission/FoundryPermission.java
similarity index 85%
rename from bukkit/src/main/java/com/clubobsidian/dynamicgui/permission/bukkit/FoundryPermission.java
rename to bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/permission/FoundryPermission.java
index 8c2f64323..45192ac21 100644
--- a/bukkit/src/main/java/com/clubobsidian/dynamicgui/permission/bukkit/FoundryPermission.java
+++ b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/permission/FoundryPermission.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,9 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.permission.bukkit;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
+package com.clubobsidian.dynamicgui.bukkit.permission;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
import com.clubobsidian.foundry.FoundryPlugin;
import org.bukkit.entity.Player;
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/permission/bukkit/VaultPermission.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/permission/VaultPermission.java
similarity index 76%
rename from bukkit/src/main/java/com/clubobsidian/dynamicgui/permission/bukkit/VaultPermission.java
rename to bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/permission/VaultPermission.java
index 71776dc31..601f9c78e 100644
--- a/bukkit/src/main/java/com/clubobsidian/dynamicgui/permission/bukkit/VaultPermission.java
+++ b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/permission/VaultPermission.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,10 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.permission.bukkit;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.permission.Permission;
+package com.clubobsidian.dynamicgui.bukkit.permission;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.permission.Permission;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.plugin.Plugin;
@@ -36,18 +37,18 @@ public class VaultPermission implements Permission {
@Override
public boolean setup() {
Plugin vault = Bukkit.getServer().getPluginManager().getPlugin("Vault");
- if(vault == null) {
+ if (vault == null) {
return false;
}
try {
this.permissionClass = Class.forName("net.milkbowl.vault.permission.Permission");
- } catch(ClassNotFoundException e) {
+ } catch (ClassNotFoundException e) {
e.printStackTrace();
return false;
}
- if(this.permissionClass == null) {
+ if (this.permissionClass == null) {
return false;
}
@@ -57,10 +58,10 @@ public boolean setup() {
@Override
public boolean hasPermission(PlayerWrapper> playerWrapper, String permission) {
- if(this.playerHas == null) {
+ if (this.playerHas == null) {
try {
this.playerHas = this.permissionClass.getDeclaredMethod("playerHas", String.class, OfflinePlayer.class, String.class);
- } catch(NoSuchMethodException | SecurityException e) {
+ } catch (NoSuchMethodException | SecurityException e) {
e.printStackTrace();
return false;
}
@@ -68,7 +69,7 @@ public boolean hasPermission(PlayerWrapper> playerWrapper, String permission)
try {
return (boolean) this.playerHas.invoke(this.permission, null, playerWrapper.getPlayer(), permission);
- } catch(IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+ } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
return false;
}
@@ -76,17 +77,17 @@ public boolean hasPermission(PlayerWrapper> playerWrapper, String permission)
@Override
public boolean addPermission(PlayerWrapper> playerWrapper, String permission) {
- if(this.playerAdd == null) {
+ if (this.playerAdd == null) {
try {
this.playerAdd = this.permissionClass.getDeclaredMethod("playerAdd", String.class, OfflinePlayer.class, String.class);
- } catch(NoSuchMethodException | SecurityException e) {
+ } catch (NoSuchMethodException | SecurityException e) {
e.printStackTrace();
return false;
}
}
try {
return (boolean) this.playerAdd.invoke(this.permission, null, playerWrapper.getPlayer(), permission);
- } catch(IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+ } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
return false;
}
@@ -94,10 +95,10 @@ public boolean addPermission(PlayerWrapper> playerWrapper, String permission)
@Override
public boolean removePermission(PlayerWrapper> playerWrapper, String permission) {
- if(this.playerRemove == null) {
+ if (this.playerRemove == null) {
try {
this.playerRemove = this.permissionClass.getDeclaredMethod("playerRemove", String.class, OfflinePlayer.class, String.class);
- } catch(NoSuchMethodException | SecurityException e) {
+ } catch (NoSuchMethodException | SecurityException e) {
e.printStackTrace();
return false;
}
@@ -105,7 +106,7 @@ public boolean removePermission(PlayerWrapper> playerWrapper, String permissio
try {
return (boolean) this.playerRemove.invoke(this.permission, null, playerWrapper.getPlayer(), permission);
- } catch(IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+ } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
return false;
}
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/server/bukkit/FakeBukkitServer.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/platform/BukkitPlatform.java
similarity index 71%
rename from bukkit/src/main/java/com/clubobsidian/dynamicgui/server/bukkit/FakeBukkitServer.java
rename to bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/platform/BukkitPlatform.java
index 9f485fe61..fec530cb0 100644
--- a/bukkit/src/main/java/com/clubobsidian/dynamicgui/server/bukkit/FakeBukkitServer.java
+++ b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/platform/BukkitPlatform.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,19 +13,21 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.server.bukkit;
-
-import com.clubobsidian.dynamicgui.DynamicGui;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.entity.bukkit.BukkitPlayerWrapper;
-import com.clubobsidian.dynamicgui.messaging.MessagingRunnable;
-import com.clubobsidian.dynamicgui.plugin.DynamicGuiPlugin;
-import com.clubobsidian.dynamicgui.proxy.Proxy;
-import com.clubobsidian.dynamicgui.scheduler.bukkit.BukkitScheduler;
-import com.clubobsidian.dynamicgui.server.FakeServer;
-import com.clubobsidian.dynamicgui.server.ServerType;
-import com.clubobsidian.dynamicgui.world.WorldWrapper;
-import com.clubobsidian.dynamicgui.world.bukkit.BukkitWorldWrapper;
+
+package com.clubobsidian.dynamicgui.bukkit.platform;
+
+import com.clubobsidian.dynamicgui.bukkit.entity.BukkitPlayerWrapper;
+import com.clubobsidian.dynamicgui.bukkit.scheduler.BukkitScheduler;
+import com.clubobsidian.dynamicgui.bukkit.world.BukkitWorldWrapper;
+import com.clubobsidian.dynamicgui.core.DynamicGui;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.messaging.MessagingRunnable;
+import com.clubobsidian.dynamicgui.core.platform.Platform;
+import com.clubobsidian.dynamicgui.core.platform.PlatformType;
+import com.clubobsidian.dynamicgui.core.plugin.DynamicGuiPlugin;
+import com.clubobsidian.dynamicgui.core.proxy.Proxy;
+import com.clubobsidian.dynamicgui.core.scheduler.Scheduler;
+import com.clubobsidian.dynamicgui.core.world.WorldWrapper;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.chat.ComponentSerializer;
import org.bukkit.Bukkit;
@@ -39,10 +41,18 @@
import java.util.List;
import java.util.UUID;
-public class FakeBukkitServer extends FakeServer {
+public class BukkitPlatform implements Platform {
+
+ private final Scheduler scheduler = new BukkitScheduler();
+
+ @Override
+ public Scheduler getScheduler() {
+ return this.scheduler;
+ }
- public FakeBukkitServer() {
- super(new BukkitScheduler());
+ @Override
+ public boolean isMainThread() {
+ return Bukkit.getServer().isPrimaryThread();
}
@Override
@@ -80,7 +90,7 @@ public Collection> getOnlinePlayers() {
@Override
public int getGlobalPlayerCount() {
- if(DynamicGui.get().getProxy() != Proxy.NONE) {
+ if (DynamicGui.get().getProxy() != Proxy.NONE) {
return DynamicGui.get().getGlobalServerPlayerCount();
}
@@ -88,8 +98,8 @@ public int getGlobalPlayerCount() {
}
@Override
- public ServerType getType() {
- return ServerType.SPIGOT;
+ public PlatformType getType() {
+ return PlatformType.BUKKIT;
}
@Override
@@ -102,7 +112,7 @@ public void registerIncomingPluginChannel(final DynamicGuiPlugin plugin, final S
PluginMessageListener listener = new PluginMessageListener() {
@Override
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
- if(channel.equals(incomingChannel)) {
+ if (channel.equals(incomingChannel)) {
PlayerWrapper> playerWrapper = new BukkitPlayerWrapper<>(player);
runnable.run(playerWrapper, message);
}
@@ -114,7 +124,7 @@ public void onPluginMessageReceived(String channel, Player player, byte[] messag
@Override
public WorldWrapper> getWorld(String worldName) {
World world = Bukkit.getServer().getWorld(worldName);
- if(world == null) {
+ if (world == null) {
return null;
}
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/plugin/DynamicGuiBukkitPlugin.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/plugin/DynamicGuiBukkitPlugin.java
new file mode 100644
index 000000000..9e56cb81b
--- /dev/null
+++ b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/plugin/DynamicGuiBukkitPlugin.java
@@ -0,0 +1,193 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.bukkit.plugin;
+
+import cloud.commandframework.CommandManager;
+import cloud.commandframework.bukkit.CloudBukkitCapabilities;
+import cloud.commandframework.execution.CommandExecutionCoordinator;
+import cloud.commandframework.paper.PaperCommandManager;
+import com.clubobsidian.dynamicgui.bukkit.command.BukkitGuiCommandSender;
+import com.clubobsidian.dynamicgui.bukkit.economy.VaultEconomy;
+import com.clubobsidian.dynamicgui.bukkit.inject.BukkitPluginModule;
+import com.clubobsidian.dynamicgui.bukkit.listener.EntityClickListener;
+import com.clubobsidian.dynamicgui.bukkit.listener.InventoryCloseListener;
+import com.clubobsidian.dynamicgui.bukkit.listener.InventoryInteractListener;
+import com.clubobsidian.dynamicgui.bukkit.listener.InventoryOpenListener;
+import com.clubobsidian.dynamicgui.bukkit.listener.PlayerInteractListener;
+import com.clubobsidian.dynamicgui.bukkit.permission.FoundryPermission;
+import com.clubobsidian.dynamicgui.bukkit.permission.VaultPermission;
+import com.clubobsidian.dynamicgui.bukkit.platform.BukkitPlatform;
+import com.clubobsidian.dynamicgui.bukkit.registry.model.ItemsAdderModelProvider;
+import com.clubobsidian.dynamicgui.bukkit.registry.model.OraxenModelProvider;
+import com.clubobsidian.dynamicgui.bukkit.registry.npc.CitizensRegistry;
+import com.clubobsidian.dynamicgui.bukkit.registry.replacer.PlaceholderApiReplacerRegistry;
+import com.clubobsidian.dynamicgui.core.DynamicGui;
+import com.clubobsidian.dynamicgui.core.command.GuiCommandSender;
+import com.clubobsidian.dynamicgui.core.economy.Economy;
+import com.clubobsidian.dynamicgui.core.logger.JavaLoggerWrapper;
+import com.clubobsidian.dynamicgui.core.logger.LoggerWrapper;
+import com.clubobsidian.dynamicgui.core.manager.dynamicgui.ModelManager;
+import com.clubobsidian.dynamicgui.core.manager.dynamicgui.ReplacerManager;
+import com.clubobsidian.dynamicgui.core.permission.Permission;
+import com.clubobsidian.dynamicgui.core.platform.Platform;
+import com.clubobsidian.dynamicgui.core.plugin.DynamicGuiPlugin;
+import com.clubobsidian.dynamicgui.core.registry.npc.NPCRegistry;
+import org.bukkit.command.CommandMap;
+import org.bukkit.command.CommandSender;
+import org.bukkit.plugin.PluginManager;
+import org.bukkit.plugin.java.JavaPlugin;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Level;
+
+public class DynamicGuiBukkitPlugin extends JavaPlugin implements DynamicGuiPlugin {
+
+ private Economy economy;
+ private Permission permission;
+ private List npcRegistries;
+ private CommandMap commandMap;
+
+ @Override
+ public void onEnable() {
+ this.start();
+ }
+
+ @Override
+ public void start() {
+ Platform platform = new BukkitPlatform();
+ LoggerWrapper> logger = new JavaLoggerWrapper<>(this.getLogger());
+
+ CommandManager commandManager = this.createCommandSender();
+
+ new BukkitPluginModule(this, platform, logger, commandManager).bootstrap();
+ PluginManager pm = this.getServer().getPluginManager();
+
+ boolean vault = false;
+ boolean foundry = false;
+ if (pm.getPlugin("Vault") != null) {
+ vault = true;
+ }
+ if (pm.getPlugin("Foundry") != null) {
+ foundry = true;
+ }
+
+ if (vault && foundry) {
+ this.permission = new FoundryPermission();
+ } else if (vault) {
+ this.permission = new VaultPermission();
+ }
+
+ if (this.permission != null && !this.permission.setup()) {
+ this.permission = null;
+ }
+
+ if (permission == null) {
+ this.getLogger().log(Level.SEVERE, "Vault is not installed, permissions will not work");
+ }
+
+ this.economy = new VaultEconomy();
+ if (!this.economy.setup()) {
+ this.economy = null;
+ }
+
+ if (this.economy == null) {
+ this.getLogger().log(Level.SEVERE, "Vault is not installed, economy functions will not work");
+ }
+
+ this.npcRegistries = new ArrayList<>();
+
+ //Hack for adding citizens late
+ //For some reason citizens sometimes will load after DynamicGui
+ this.getServer().getScheduler().scheduleSyncDelayedTask(this, () -> {
+ if (this.getServer().getPluginManager().getPlugin("Citizens") != null) {
+ this.getNPCRegistries().add(new CitizensRegistry());
+ }
+ }, 1);
+
+ this.registerModelProviders(pm);
+
+ if (this.getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
+ ReplacerManager.get().registerReplacerRegistry(new PlaceholderApiReplacerRegistry());
+ }
+
+ this.getServer().getPluginManager().registerEvents(new EntityClickListener(), this);
+ this.getServer().getPluginManager().registerEvents(new InventoryInteractListener(), this);
+ this.getServer().getPluginManager().registerEvents(new InventoryCloseListener(), this);
+ this.getServer().getPluginManager().registerEvents(new InventoryOpenListener(), this);
+ this.getServer().getPluginManager().registerEvents(new PlayerInteractListener(), this);
+ }
+
+ private CommandManager createCommandSender() {
+ try {
+ PaperCommandManager commandManager = new PaperCommandManager<>(this,
+ CommandExecutionCoordinator.simpleCoordinator(),
+ BukkitGuiCommandSender::new,
+ wrappedSender -> (CommandSender) wrappedSender.getNativeSender()
+
+ );
+ //Unfortunately is tied to bukkit so there is no way to do this in core
+ if (commandManager.queryCapability(CloudBukkitCapabilities.BRIGADIER)) {
+ commandManager.registerBrigadier();
+ }
+ if(commandManager.queryCapability(CloudBukkitCapabilities.ASYNCHRONOUS_COMPLETION)) {
+ commandManager.registerAsynchronousCompletions();
+ }
+ return commandManager;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ private void registerModelProviders(PluginManager pm) {
+ if (pm.getPlugin("Oraxen") != null) {
+ ModelManager.get().register(new OraxenModelProvider());
+ }
+ if (pm.getPlugin("ItemsAdder") != null) {
+ ModelManager.get().register(new ItemsAdderModelProvider());
+ }
+ }
+
+ @Override
+ public void onDisable() {
+ this.stop();
+ }
+
+ @Override
+ public void stop() {
+ DynamicGui.get().stop();
+ }
+
+ @Override
+ public Economy getEconomy() {
+ return this.economy;
+ }
+
+ @Override
+ public Permission getPermission() {
+ return this.permission;
+ }
+
+ @Override
+ public List getNPCRegistries() {
+ return this.npcRegistries;
+ }
+
+
+}
\ No newline at end of file
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/registry/model/bukkit/ItemsAdderModelProvider.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/registry/model/ItemsAdderModelProvider.java
similarity index 67%
rename from bukkit/src/main/java/com/clubobsidian/dynamicgui/registry/model/bukkit/ItemsAdderModelProvider.java
rename to bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/registry/model/ItemsAdderModelProvider.java
index 26070e1ef..7d46b785c 100644
--- a/bukkit/src/main/java/com/clubobsidian/dynamicgui/registry/model/bukkit/ItemsAdderModelProvider.java
+++ b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/registry/model/ItemsAdderModelProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,38 +14,30 @@
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.registry.model.bukkit;
+package com.clubobsidian.dynamicgui.bukkit.registry.model;
-import com.clubobsidian.dynamicgui.inventory.ItemStackWrapper;
-import com.clubobsidian.dynamicgui.manager.inventory.ItemStackManager;
-import com.clubobsidian.dynamicgui.registry.model.ModelProvider;
+import com.clubobsidian.dynamicgui.core.inventory.ItemStackWrapper;
+import com.clubobsidian.dynamicgui.core.manager.inventory.ItemStackManager;
+import com.clubobsidian.dynamicgui.core.registry.model.ModelProvider;
+import com.clubobsidian.dynamicgui.core.util.ReflectionUtil;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class ItemsAdderModelProvider implements ModelProvider {
- private static final boolean ITEMS_ADDER_EXISTS = exists();
+ private static final boolean ITEMS_ADDER_EXISTS = ReflectionUtil.classExists("dev.lone.itemsadder.api.CustomStack");
private static final Method GET_INSTANCE = instance();
private static final Method GET_ITEM_STACK = itemStack();
- private static boolean exists() {
- try {
- Class.forName("dev.lone.itemsadder.api.CustomStack");
- return true;
- } catch(ClassNotFoundException e) {
- return false;
- }
- }
-
private static Method instance() {
- if(ITEMS_ADDER_EXISTS) {
+ if (ITEMS_ADDER_EXISTS) {
try {
Class> customStack = Class.forName("dev.lone.itemsadder.api.CustomStack");
Method getInstance = customStack.getDeclaredMethod("getInstance", String.class);
getInstance.setAccessible(true);
return getInstance;
- } catch(ClassNotFoundException | NoSuchMethodException e) {
+ } catch (ClassNotFoundException | NoSuchMethodException e) {
e.printStackTrace();
}
}
@@ -53,13 +45,13 @@ private static Method instance() {
}
private static Method itemStack() {
- if(ITEMS_ADDER_EXISTS) {
+ if (ITEMS_ADDER_EXISTS) {
try {
- Class> customStack= Class.forName("dev.lone.itemsadder.api.CustomStack");
+ Class> customStack = Class.forName("dev.lone.itemsadder.api.CustomStack");
Method getItemStack = customStack.getDeclaredMethod("getItemStack");
getItemStack.setAccessible(true);
return getItemStack;
- } catch(ClassNotFoundException | NoSuchMethodException e) {
+ } catch (ClassNotFoundException | NoSuchMethodException e) {
e.printStackTrace();
}
}
@@ -73,18 +65,18 @@ public String name() {
@Override
public boolean applyModel(ItemStackWrapper> itemStack, String data) {
- if(ITEMS_ADDER_EXISTS) {
+ if (ITEMS_ADDER_EXISTS) {
try {
Object customStack = GET_INSTANCE.invoke(null, data);
- if(customStack != null) {
+ if (customStack != null) {
ItemStackWrapper> wrappedCustom = ItemStackManager
.get()
.createItemStackWrapper(GET_ITEM_STACK.invoke(customStack));
- if(wrappedCustom.hasCustomModel()) {
+ if (wrappedCustom.hasCustomModel()) {
return itemStack.setModel(wrappedCustom.getModelData());
}
}
- } catch(IllegalAccessException | InvocationTargetException e) {
+ } catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
}
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/registry/model/bukkit/OraxenModelProvider.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/registry/model/OraxenModelProvider.java
similarity index 70%
rename from bukkit/src/main/java/com/clubobsidian/dynamicgui/registry/model/bukkit/OraxenModelProvider.java
rename to bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/registry/model/OraxenModelProvider.java
index ce459487f..4e36859fe 100644
--- a/bukkit/src/main/java/com/clubobsidian/dynamicgui/registry/model/bukkit/OraxenModelProvider.java
+++ b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/registry/model/OraxenModelProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,38 +14,32 @@
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.registry.model.bukkit;
+package com.clubobsidian.dynamicgui.bukkit.registry.model;
-import com.clubobsidian.dynamicgui.inventory.ItemStackWrapper;
-import com.clubobsidian.dynamicgui.manager.inventory.ItemStackManager;
-import com.clubobsidian.dynamicgui.registry.model.ModelProvider;
+import com.clubobsidian.dynamicgui.core.inventory.ItemStackWrapper;
+import com.clubobsidian.dynamicgui.core.manager.inventory.ItemStackManager;
+import com.clubobsidian.dynamicgui.core.registry.model.ModelProvider;
+import com.clubobsidian.dynamicgui.core.util.ReflectionUtil;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class OraxenModelProvider implements ModelProvider {
- private static final boolean ORAXEN_EXISTS = exists();
+ private static final boolean ORAXEN_EXISTS = ReflectionUtil
+ .classExists("io.th0rgal.oraxen.items.OraxenItems");
private static final Method GET_ITEM_BY_ID = getItemById();
private static final Method BUILD = getBuild();
- private static boolean exists() {
- try {
- Class.forName("io.th0rgal.oraxen.items.OraxenItems");
- return true;
- } catch(ClassNotFoundException ex) {
- return false;
- }
- }
private static Method getItemById() {
- if(ORAXEN_EXISTS) {
+ if (ORAXEN_EXISTS) {
try {
Class> items = Class.forName("io.th0rgal.oraxen.items.OraxenItems");
Method getItem = items.getDeclaredMethod("getItemById", String.class);
getItem.setAccessible(true);
return getItem;
- } catch(ClassNotFoundException | NoSuchMethodException e) {
+ } catch (ClassNotFoundException | NoSuchMethodException e) {
e.printStackTrace();
}
}
@@ -53,13 +47,13 @@ private static Method getItemById() {
}
private static Method getBuild() {
- if(ORAXEN_EXISTS) {
+ if (ORAXEN_EXISTS) {
try {
Class> itemBuilder = Class.forName("io.th0rgal.oraxen.items.ItemBuilder");
Method build = itemBuilder.getDeclaredMethod("build");
build.setAccessible(true);
return build;
- } catch(ClassNotFoundException | NoSuchMethodException ex) {
+ } catch (ClassNotFoundException | NoSuchMethodException ex) {
ex.printStackTrace();
}
}
@@ -75,15 +69,15 @@ public String name() {
public boolean applyModel(ItemStackWrapper> itemStack, String data) {
try {
Object itemBuilder = GET_ITEM_BY_ID.invoke(null, data);
- if(itemBuilder == null) {
+ if (itemBuilder == null) {
return false;
}
ItemStackWrapper> built = ItemStackManager.get().createItemStackWrapper(BUILD.invoke(itemBuilder));
- if(built.hasCustomModel()) {
+ if (built.hasCustomModel()) {
return itemStack.setModel(built.getModelData());
}
return false;
- } catch(IllegalAccessException | InvocationTargetException e) {
+ } catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
return false;
}
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/registry/npc/bukkit/CitizensRegistry.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/registry/npc/CitizensRegistry.java
similarity index 79%
rename from bukkit/src/main/java/com/clubobsidian/dynamicgui/registry/npc/bukkit/CitizensRegistry.java
rename to bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/registry/npc/CitizensRegistry.java
index 933b3197c..ddfe6606c 100644
--- a/bukkit/src/main/java/com/clubobsidian/dynamicgui/registry/npc/bukkit/CitizensRegistry.java
+++ b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/registry/npc/CitizensRegistry.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,13 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.registry.npc.bukkit;
-import com.clubobsidian.dynamicgui.entity.EntityWrapper;
-import com.clubobsidian.dynamicgui.registry.npc.NPC;
-import com.clubobsidian.dynamicgui.registry.npc.NPCMeta;
-import com.clubobsidian.dynamicgui.registry.npc.NPCRegistry;
-import com.clubobsidian.dynamicgui.util.ReflectionUtil;
+package com.clubobsidian.dynamicgui.bukkit.registry.npc;
+
+import com.clubobsidian.dynamicgui.core.entity.EntityWrapper;
+import com.clubobsidian.dynamicgui.core.registry.npc.NPC;
+import com.clubobsidian.dynamicgui.core.registry.npc.NPCMeta;
+import com.clubobsidian.dynamicgui.core.registry.npc.NPCRegistry;
+import com.clubobsidian.dynamicgui.core.util.ReflectionUtil;
import org.bukkit.entity.Entity;
import java.lang.reflect.InvocationTargetException;
@@ -47,7 +48,7 @@ private Object getNPCRegistry() {
try {
return this.getNPCRegistryMethod.invoke(null);
- } catch(IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+ } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
}
@@ -68,14 +69,14 @@ public boolean isNPC(EntityWrapper> entityWrapper) {
public NPC getNPC(EntityWrapper> entityWrapper) {
try {
Object npc = this.getNPCMethod.invoke(this.npcRegistry, entityWrapper.getEntity());
- if(npc == null) {
+ if (npc == null) {
return null;
}
int id = (int) this.getIdMethod.invoke(npc);
NPCMeta meta = new NPCMeta(id, CitizensRegistry.PLUGIN_NAME);
return new NPC(entityWrapper, meta);
- } catch(IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+ } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
}
return null;
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/registry/package-info.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/registry/package-info.java
new file mode 100644
index 000000000..5180272ce
--- /dev/null
+++ b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/registry/package-info.java
@@ -0,0 +1,17 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.bukkit.registry;
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/registry/replacer/bukkit/PlaceholderApiReplacerRegistry.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/registry/replacer/PlaceholderApiReplacerRegistry.java
similarity index 77%
rename from bukkit/src/main/java/com/clubobsidian/dynamicgui/registry/replacer/bukkit/PlaceholderApiReplacerRegistry.java
rename to bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/registry/replacer/PlaceholderApiReplacerRegistry.java
index 12aa09377..b73469871 100644
--- a/bukkit/src/main/java/com/clubobsidian/dynamicgui/registry/replacer/bukkit/PlaceholderApiReplacerRegistry.java
+++ b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/registry/replacer/PlaceholderApiReplacerRegistry.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.registry.replacer.bukkit;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.registry.replacer.ReplacerRegistry;
-import com.clubobsidian.dynamicgui.util.ReflectionUtil;
+package com.clubobsidian.dynamicgui.bukkit.registry.replacer;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.registry.replacer.ReplacerRegistry;
+import com.clubobsidian.dynamicgui.core.util.ReflectionUtil;
import org.bukkit.OfflinePlayer;
import java.lang.reflect.InvocationTargetException;
@@ -35,7 +36,7 @@ public PlaceholderApiReplacerRegistry() {
public String replace(PlayerWrapper> playerWrapper, String text) {
try {
return (String) this.setPlaceHolders.invoke(null, playerWrapper.getPlayer(), text);
- } catch(IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+ } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
}
return null;
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/scheduler/BukkitScheduler.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/scheduler/BukkitScheduler.java
new file mode 100644
index 000000000..b22e6aa76
--- /dev/null
+++ b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/scheduler/BukkitScheduler.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.bukkit.scheduler;
+
+import com.clubobsidian.dynamicgui.core.DynamicGui;
+import com.clubobsidian.dynamicgui.core.scheduler.Scheduler;
+import org.bukkit.Bukkit;
+import org.bukkit.plugin.Plugin;
+
+public class BukkitScheduler extends Scheduler {
+
+ @Override
+ public void runSyncDelayedTask(Runnable runnable, long delay) {
+ Bukkit.getScheduler()
+ .scheduleSyncDelayedTask((Plugin) DynamicGui.get().getPlugin(), runnable, delay);
+ }
+
+ @Override
+ public void runAsynchronousDelayedTask(Runnable runnable, long delay) {
+ Bukkit.getScheduler()
+ .runTaskLaterAsynchronously((Plugin) DynamicGui.get().getPlugin(), runnable, delay);
+ }
+
+ @Override
+ public void scheduleSyncRepeatingTask(Runnable runnable, long delayInitial, long delayRepeating) {
+ Bukkit.getScheduler()
+ .scheduleSyncRepeatingTask((Plugin) DynamicGui.get().getPlugin(), runnable, delayInitial, delayRepeating);
+ }
+
+ @Override
+ public void scheduleAsyncRepeatingTask(Runnable runnable, long delayInitial, long delayRepeating) {
+ Bukkit.getServer().getScheduler()
+ .runTaskTimerAsynchronously((Plugin) DynamicGui.get().getPlugin(),
+ runnable, delayInitial, delayRepeating);
+ }
+}
\ No newline at end of file
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/util/BukkitNBTUtil.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/util/BukkitNBTUtil.java
new file mode 100644
index 000000000..bc990e67b
--- /dev/null
+++ b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/util/BukkitNBTUtil.java
@@ -0,0 +1,147 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.bukkit.util;
+
+import com.clubobsidian.dynamicgui.core.util.ReflectionUtil;
+import org.bukkit.inventory.ItemStack;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+public final class BukkitNBTUtil {
+
+ private static final String VERSION = VersionUtil.getVersion();
+ private static final Class> NMS_ITEM_STACK_CLASS = ReflectionUtil.getClassIfExists(
+ "net.minecraft.world.item.ItemStack",
+ "net.minecraft.server." + VERSION + ".ItemStack"
+ );
+ private static final Class> COMPOUND_CLASS = ReflectionUtil.getClassIfExists(
+ "net.minecraft.nbt.NBTTagCompound",
+ "net.minecraft.server." + VERSION + ".NBTTagCompound"
+ );
+ private static final Class> PARSER_CLASS = ReflectionUtil.getClassIfExists(
+ "net.minecraft.nbt.MojangsonParser",
+ "net.minecraft.server." + VERSION + ".MojangsonParser"
+ );
+
+ private static Method parse;
+ private static Method asNMSCopy;
+ private static Method setTag;
+ private static Method asBukkitCopy;
+ private static Method getTag;
+
+ public static Object parse(String nbtStr) {
+ if (parse == null) {
+ try {
+ parse = ReflectionUtil.getStaticMethod(PARSER_CLASS, COMPOUND_CLASS);
+ parse.setAccessible(true);
+ } catch (NullPointerException | SecurityException e) {
+ e.printStackTrace();
+ }
+ }
+ try {
+ return parse.invoke(null, nbtStr);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public static String getTag(ItemStack itemStack) {
+ String version = VersionUtil.getVersion();
+ try {
+ if (asNMSCopy == null) {
+ String craftItemStackClassName = "org.bukkit.craftbukkit." + version + ".inventory.CraftItemStack";
+ Class> craftItemStackClass;
+ craftItemStackClass = Class.forName(craftItemStackClassName);
+ asNMSCopy = craftItemStackClass.getDeclaredMethod("asNMSCopy", ItemStack.class);
+ asNMSCopy.setAccessible(true);
+ }
+
+ if (getTag == null) {
+ getTag = NMS_ITEM_STACK_CLASS.getDeclaredMethod("getTag");
+ getTag.setAccessible(true);
+ }
+
+ if (asBukkitCopy == null) {
+ String craftItemStackClassName = "org.bukkit.craftbukkit." + version + ".inventory.CraftItemStack";
+ Class> craftItemStackClass = Class.forName(craftItemStackClassName);
+ asBukkitCopy = craftItemStackClass.getDeclaredMethod("asBukkitCopy", NMS_ITEM_STACK_CLASS);
+ asBukkitCopy.setAccessible(true);
+ }
+
+ Object nmsItemStack = asNMSCopy.invoke(null, itemStack);
+ Object tag = getTag.invoke(nmsItemStack);
+ if (tag == null) {
+ return null;
+ }
+
+ return tag.toString();
+ } catch (ClassNotFoundException | NoSuchMethodException |
+ SecurityException | IllegalAccessException |
+ IllegalArgumentException | InvocationTargetException |
+ NullPointerException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public static ItemStack setTag(ItemStack itemStack, String nbt) {
+ String version = VersionUtil.getVersion();
+ try {
+ if (asNMSCopy == null) {
+ String craftItemStackClassName = "org.bukkit.craftbukkit." + version + ".inventory.CraftItemStack";
+ Class> craftItemStackClass = Class.forName(craftItemStackClassName);
+ asNMSCopy = craftItemStackClass.getDeclaredMethod("asNMSCopy", ItemStack.class);
+ asNMSCopy.setAccessible(true);
+ }
+
+ if (setTag == null) {
+ getSetTagMethod();
+ }
+
+ if (asBukkitCopy == null) {
+ String craftItemStackClassName = "org.bukkit.craftbukkit." + version + ".inventory.CraftItemStack";
+ Class> craftItemStackClass = Class.forName(craftItemStackClassName);
+ asBukkitCopy = craftItemStackClass.getDeclaredMethod("asBukkitCopy", NMS_ITEM_STACK_CLASS);
+ asBukkitCopy.setAccessible(true);
+ }
+
+ Object nmsItemStack = asNMSCopy.invoke(null, itemStack);
+ Object nbtCompound = BukkitNBTUtil.parse(nbt);
+ Object invokedSetTag = setTag.invoke(nmsItemStack, nbtCompound);
+ nmsItemStack = setTag.getReturnType().equals(void.class) ? nmsItemStack : invokedSetTag;
+ ItemStack bukkitItemStack = (ItemStack) asBukkitCopy.invoke(null, nmsItemStack);
+ return bukkitItemStack;
+ } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ private static void getSetTagMethod() {
+ try {
+ setTag = ReflectionUtil.getMethod(NMS_ITEM_STACK_CLASS, "setTag", "setTagClone");
+ setTag.setAccessible(true);
+ } catch (NullPointerException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private BukkitNBTUtil() {
+ }
+}
\ No newline at end of file
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/util/bukkit/BukkitPacketUtil.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/util/BukkitPacketUtil.java
similarity index 77%
rename from bukkit/src/main/java/com/clubobsidian/dynamicgui/util/bukkit/BukkitPacketUtil.java
rename to bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/util/BukkitPacketUtil.java
index a410f1dee..be92bf4c4 100644
--- a/bukkit/src/main/java/com/clubobsidian/dynamicgui/util/bukkit/BukkitPacketUtil.java
+++ b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/util/BukkitPacketUtil.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,9 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.util.bukkit;
-import com.clubobsidian.dynamicgui.util.ReflectionUtil;
+package com.clubobsidian.dynamicgui.bukkit.util;
+
+import com.clubobsidian.dynamicgui.core.util.ReflectionUtil;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@@ -29,7 +30,6 @@ public final class BukkitPacketUtil {
private BukkitPacketUtil() {
}
- private static final String ITEM_STACK_CLASS_NAME = getItemStackClass();
private static final String ENTITY_PLAYER_CLASS_NAME = getEntityPlayerClassName();
private static final String ENTITY_HUMAN_CLASS_NAME = getEntityHumanClassName();
private static final String PLAYER_CONNECTION_CLASS_NAME = getPlayerConnectionClassName();
@@ -59,33 +59,34 @@ private BukkitPacketUtil() {
public static void sendPacket(Player player, Object packet) {
String version = VersionUtil.getVersion();
try {
- if(craftPlayerClass == null) {
+ if (craftPlayerClass == null) {
craftPlayerClass = Class.forName("org.bukkit.craftbukkit." + version + ".entity.CraftPlayer");
}
- if(playerHandle == null) {
+ if (playerHandle == null) {
playerHandle = craftPlayerClass.getDeclaredMethod("getHandle");
}
- if(nmsPlayerClass == null) {
+ if (nmsPlayerClass == null) {
nmsPlayerClass = Class.forName(ENTITY_PLAYER_CLASS_NAME);
}
- if(playerConnection == null) {
+ if (playerConnection == null) {
Class> conClazz = Class.forName(PLAYER_CONNECTION_CLASS_NAME);
playerConnection = ReflectionUtil.getFieldByType(nmsPlayerClass, conClazz);
}
- if(networkManager == null) {
+ if (networkManager == null) {
Class> playerConnection = Class.forName(PLAYER_CONNECTION_CLASS_NAME);
Class> networkManagerClass = Class.forName(NETWORK_MANAGER_CLASS_NAME);
networkManager = ReflectionUtil.getFieldByType(playerConnection, networkManagerClass);
}
- if(sendPacket == null) {
+ if (sendPacket == null) {
Class> networkManagerClass = Class.forName(NETWORK_MANAGER_CLASS_NAME);
Class> packetClass = Class.forName(PACKET_CLASS_NAME);
- sendPacket = networkManagerClass.getDeclaredMethod("sendPacket", packetClass);
+ sendPacket = ReflectionUtil.getMethod(networkManagerClass, void.class, packetClass);
+
}
Object nmsPlayer = playerHandle.invoke(player);
@@ -93,7 +94,10 @@ public static void sendPacket(Player player, Object packet) {
Object manager = networkManager.get(con);
sendPacket.invoke(manager, packet);
- } catch(ClassNotFoundException | NoSuchMethodException | SecurityException | IllegalArgumentException | IllegalAccessException | InvocationTargetException e) {
+ } catch (NullPointerException | ClassNotFoundException |
+ NoSuchMethodException | SecurityException |
+ IllegalArgumentException | IllegalAccessException |
+ InvocationTargetException e) {
e.printStackTrace();
}
}
@@ -101,37 +105,37 @@ public static void sendPacket(Player player, Object packet) {
public static void sendSlotPacket(int index, Player player, ItemStack itemStack) {
String version = VersionUtil.getVersion();
try {
- if(craftPlayerClass == null) {
+ if (craftPlayerClass == null) {
craftPlayerClass = Class.forName("org.bukkit.craftbukkit." + version + ".entity.CraftPlayer");
}
- if(craftItemClass == null) {
+ if (craftItemClass == null) {
craftItemClass = Class.forName("org.bukkit.craftbukkit." + version + ".inventory.CraftItemStack");
}
- if(itemStackHandle == null) {
+ if (itemStackHandle == null) {
itemStackHandle = craftItemClass.getDeclaredField("handle");
itemStackHandle.setAccessible(true);
}
- if(playerHandle == null) {
+ if (playerHandle == null) {
playerHandle = craftPlayerClass.getDeclaredMethod("getHandle");
}
- if(nmsPlayerClass == null) {
+ if (nmsPlayerClass == null) {
nmsPlayerClass = Class.forName(ENTITY_PLAYER_CLASS_NAME);
}
- if(nmsHumanClass == null) {
+ if (nmsHumanClass == null) {
nmsHumanClass = Class.forName(ENTITY_HUMAN_CLASS_NAME);
}
- if(windowIdField == null) {
+ if (windowIdField == null) {
Class> containerClass = Class.forName(CONTAINER_CLASS_NAME);
windowIdField = ReflectionUtil.getDeclaredField(containerClass, "windowId", "j");
}
- if(activeContainer == null) {
+ if (activeContainer == null) {
Class> containerClass = Class.forName(CONTAINER_CLASS_NAME);
activeContainer = ReflectionUtil.getFieldByType(nmsHumanClass, containerClass);
}
@@ -145,18 +149,18 @@ public static void sendSlotPacket(int index, Player player, ItemStack itemStack)
//stateId is new in 1.17
//int windowID, int stateID, int slot, ItemStack itemstack
Object packet;
- if(SET_SLOT_CONSTRUCTOR_LENGTH == 3) {
+ if (SET_SLOT_CONSTRUCTOR_LENGTH == 3) {
packet = PACKET_PLAY_OUT_SET_SLOT_CONSTRUCTOR.newInstance(windowId, index, nmsItemStack);
} else {
- if(stateIdField == null) {
+ if (stateIdField == null) {
Class> containerClass = Class.forName(CONTAINER_CLASS_NAME);
- stateIdField = ReflectionUtil.getDeclaredField(containerClass, "q");
+ stateIdField = ReflectionUtil.getDeclaredField(container, containerClass, Integer.class, "r", "q");
}
int stateId = stateIdField.getInt(container);
packet = PACKET_PLAY_OUT_SET_SLOT_CONSTRUCTOR.newInstance(windowId, stateId, index, nmsItemStack);
}
sendPacket(player, packet);
- } catch(ClassNotFoundException | NoSuchFieldException | SecurityException | NoSuchMethodException | IllegalArgumentException | IllegalAccessException | InstantiationException | InvocationTargetException e) {
+ } catch (ClassNotFoundException | NoSuchFieldException | SecurityException | NoSuchMethodException | IllegalArgumentException | IllegalAccessException | InstantiationException | InvocationTargetException e) {
e.printStackTrace();
}
}
@@ -164,46 +168,29 @@ public static void sendSlotPacket(int index, Player player, ItemStack itemStack)
private static Constructor> getPacketPlayOutSetSlotConstructor() {
try {
Class> packetClass = Class.forName(PACKET_PLAY_OUT_SET_SLOT_CLASS_NAME);
- for(Constructor> con : packetClass.getDeclaredConstructors()) {
- if(con.getParameterTypes().length > 0 && con.getParameterTypes()[0].equals(int.class)) {
+ for (Constructor> con : packetClass.getDeclaredConstructors()) {
+ if (con.getParameterTypes().length > 0 && con.getParameterTypes()[0].equals(int.class)) {
return con;
}
}
- } catch(ClassNotFoundException e) {
+ } catch (ClassNotFoundException e) {
e.printStackTrace();
}
return null;
}
- private static String getItemStackClass() {
- try {
- String className = "net.minecraft.world.item.ItemStack";
- Class.forName(className);
- return className;
- } catch(ClassNotFoundException ex) {
- String version = VersionUtil.getVersion();
- String className = "net.minecraft.server." + version + ".ItemStack";
- try {
- Class.forName(className);
- return className;
- } catch(ClassNotFoundException e) {
- return null;
- }
- }
- }
-
private static String getEntityPlayerClassName() {
try {
String className = "net.minecraft.server.level.EntityPlayer";
Class.forName(className);
return className;
- } catch(ClassNotFoundException ex) {
+ } catch (ClassNotFoundException ex) {
String version = VersionUtil.getVersion();
String className = "net.minecraft.server." + version + ".EntityPlayer";
try {
Class.forName(className);
return className;
- } catch(ClassNotFoundException e) {
+ } catch (ClassNotFoundException e) {
return null;
}
}
@@ -214,13 +201,13 @@ private static String getEntityHumanClassName() {
String className = "net.minecraft.world.entity.player.EntityHuman";
Class.forName(className);
return className;
- } catch(ClassNotFoundException ex) {
+ } catch (ClassNotFoundException ex) {
String version = VersionUtil.getVersion();
String className = "net.minecraft.server." + version + ".EntityHuman";
try {
Class.forName(className);
return className;
- } catch(ClassNotFoundException e) {
+ } catch (ClassNotFoundException e) {
return null;
}
}
@@ -231,13 +218,13 @@ private static String getPlayerConnectionClassName() {
String className = "net.minecraft.server.network.PlayerConnection";
Class.forName(className);
return className;
- } catch(ClassNotFoundException ex) {
+ } catch (ClassNotFoundException ex) {
String version = VersionUtil.getVersion();
String className = "net.minecraft.server." + version + ".PlayerConnection";
try {
Class.forName(className);
return className;
- } catch(ClassNotFoundException e) {
+ } catch (ClassNotFoundException e) {
return null;
}
}
@@ -248,13 +235,13 @@ private static String getNetworkManagerClassName() {
String className = "net.minecraft.network.NetworkManager";
Class.forName(className);
return className;
- } catch(ClassNotFoundException ex) {
+ } catch (ClassNotFoundException ex) {
String version = VersionUtil.getVersion();
String className = "net.minecraft.server." + version + ".NetworkManager";
try {
Class.forName(className);
return className;
- } catch(ClassNotFoundException e) {
+ } catch (ClassNotFoundException e) {
return null;
}
}
@@ -265,13 +252,13 @@ private static String getContainerClassName() {
String className = "net.minecraft.world.inventory.Container";
Class.forName(className);
return className;
- } catch(ClassNotFoundException ex) {
+ } catch (ClassNotFoundException ex) {
String version = VersionUtil.getVersion();
String className = "net.minecraft.server." + version + ".Container";
try {
Class.forName(className);
return className;
- } catch(ClassNotFoundException e) {
+ } catch (ClassNotFoundException e) {
return null;
}
}
@@ -282,13 +269,13 @@ private static String getPacketClassName() {
String className = "net.minecraft.network.protocol.Packet";
Class.forName(className);
return className;
- } catch(ClassNotFoundException ex) {
+ } catch (ClassNotFoundException ex) {
String version = VersionUtil.getVersion();
String className = "net.minecraft.server." + version + ".Packet";
try {
Class.forName(className);
return className;
- } catch(ClassNotFoundException e) {
+ } catch (ClassNotFoundException e) {
return null;
}
}
@@ -299,13 +286,13 @@ private static String getPacketPlayOutSetClassName() {
String className = "net.minecraft.network.protocol.game.PacketPlayOutSetSlot";
Class.forName(className);
return className;
- } catch(ClassNotFoundException ex) {
+ } catch (ClassNotFoundException ex) {
String version = VersionUtil.getVersion();
String className = "net.minecraft.server." + version + ".PacketPlayOutSetSlot";
try {
Class.forName(className);
return className;
- } catch(ClassNotFoundException e) {
+ } catch (ClassNotFoundException e) {
return null;
}
}
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/util/bukkit/VersionUtil.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/util/VersionUtil.java
similarity index 86%
rename from bukkit/src/main/java/com/clubobsidian/dynamicgui/util/bukkit/VersionUtil.java
rename to bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/util/VersionUtil.java
index 1fceee725..9b3f45be4 100644
--- a/bukkit/src/main/java/com/clubobsidian/dynamicgui/util/bukkit/VersionUtil.java
+++ b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/util/VersionUtil.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,14 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.util.bukkit;
+
+package com.clubobsidian.dynamicgui.bukkit.util;
import org.bukkit.Bukkit;
public class VersionUtil {
public synchronized static String getVersion() {
- if(Bukkit.getServer() == null) {
+ if (Bukkit.getServer() == null) {
return null;
}
String packageName = Bukkit.getServer().getClass().getPackage().getName();
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/world/bukkit/BukkitWorldWrapper.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/world/BukkitWorldWrapper.java
similarity index 80%
rename from bukkit/src/main/java/com/clubobsidian/dynamicgui/world/bukkit/BukkitWorldWrapper.java
rename to bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/world/BukkitWorldWrapper.java
index 37e3e85b3..62fee7c21 100644
--- a/bukkit/src/main/java/com/clubobsidian/dynamicgui/world/bukkit/BukkitWorldWrapper.java
+++ b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/world/BukkitWorldWrapper.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,9 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.world.bukkit;
-import com.clubobsidian.dynamicgui.world.WorldWrapper;
+package com.clubobsidian.dynamicgui.bukkit.world;
+
+import com.clubobsidian.dynamicgui.core.world.WorldWrapper;
import org.bukkit.Bukkit;
import org.bukkit.World;
@@ -36,8 +37,8 @@ public World getWorld() {
}
@Override
- public void setGameRule(String rule, String value) {
- this.getWorld().setGameRuleValue(rule, value);
+ public void setGameRule(String key, String value) {
+ this.getWorld().setGameRuleValue(key, value);
}
@Override
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/command/bukkit/BukkitDynamicGuiCommand.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/command/bukkit/BukkitDynamicGuiCommand.java
deleted file mode 100644
index 5ccdd7e87..000000000
--- a/bukkit/src/main/java/com/clubobsidian/dynamicgui/command/bukkit/BukkitDynamicGuiCommand.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright 2021 Club Obsidian and contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.clubobsidian.dynamicgui.command.bukkit;
-
-import com.clubobsidian.dynamicgui.DynamicGui;
-import com.clubobsidian.dynamicgui.event.DynamicGuiReloadEvent;
-import com.clubobsidian.dynamicgui.gui.Gui;
-import com.clubobsidian.dynamicgui.manager.dynamicgui.GuiManager;
-import org.bukkit.Bukkit;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Player;
-
-import java.util.Iterator;
-import java.util.Map.Entry;
-import java.util.UUID;
-
-public class BukkitDynamicGuiCommand implements CommandExecutor {
-
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
- if(args.length == 1) {
- String first = args[0];
- if(sender.hasPermission("dynamicgui.reload")) {
- if(first.equalsIgnoreCase("reload")) {
- sender.sendMessage("Guis have been reloaded");
- GuiManager.get().reloadGuis(false);
- DynamicGui.get().getEventBus().callEvent(new DynamicGuiReloadEvent());
- return true;
- } else if(first.equals("forcereload")) {
- sender.sendMessage("Guis have been force reloaded");
- GuiManager.get().reloadGuis(true);
- DynamicGui.get().getEventBus().callEvent(new DynamicGuiReloadEvent());
- return true;
- }
- }
- } else if(args.length == 2) {
- String first = args[0];
- String second = args[1];
- if(first.equalsIgnoreCase("close")) {
- if(sender.hasPermission("dynamicgui.close")) {
- if(second.equalsIgnoreCase("all")) {
- sender.sendMessage("All open DynamicGui guis have been closed");
- for(UUID uuid : GuiManager.get().getPlayerGuis().keySet()) {
- Bukkit.getServer().getPlayer(uuid).closeInventory();
- }
- return true;
- } else {
- Player player = Bukkit.getServer().getPlayer(second);
- if(player == null) {
- sender.sendMessage("That player is not online, so their gui cannot be closed");
- return true;
- } else {
-
- if(GuiManager.get().getPlayerGuis().get(player.getUniqueId()) != null) {
- sender.sendMessage(player.getName() + "'s gui has been closed");
- player.closeInventory();
- return true;
- } else {
- sender.sendMessage(player.getName() + " did not have a DynamicGui gui open");
- return true;
- }
- }
- }
- }
- }
- } else if(args.length == 3) {
- String first = args[0];
- String second = args[1];
- String third = args[2];
- if(first.equalsIgnoreCase("close")) {
- if(second.equalsIgnoreCase("all")) {
- Gui gui = GuiManager.get().getGuiByName(third);
- if(gui == null) {
- sender.sendMessage("No gui can be found by that name");
- return true;
- } else {
- sender.sendMessage("Guis of type " + third + " are now closed");
- Iterator> it = GuiManager.get().getPlayerGuis().entrySet().iterator();
- while(it.hasNext()) {
- Entry next = it.next();
- if(next.getValue().getName().equals(third)) {
- Bukkit.getServer().getPlayer(next.getKey()).closeInventory();
- }
- }
- return true;
- }
- }
- }
- } else {
- sender.sendMessage("/dynamicgui reload");
- sender.sendMessage("/dynamicgui forcereload");
- sender.sendMessage("/dynamicgui close ");
- sender.sendMessage("/dynamicgui close ");
- return true;
- }
- return true;
- }
-}
\ No newline at end of file
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/command/bukkit/BukkitGuiCommand.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/command/bukkit/BukkitGuiCommand.java
deleted file mode 100644
index c1b323238..000000000
--- a/bukkit/src/main/java/com/clubobsidian/dynamicgui/command/bukkit/BukkitGuiCommand.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright 2021 Club Obsidian and contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.clubobsidian.dynamicgui.command.bukkit;
-
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.entity.bukkit.BukkitPlayerWrapper;
-import com.clubobsidian.dynamicgui.manager.dynamicgui.GuiManager;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Player;
-
-public class BukkitGuiCommand implements CommandExecutor {
-
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
- if(sender instanceof Player) {
- if(args.length == 1) {
- Player player = (Player) sender;
- PlayerWrapper> playerWrapper = new BukkitPlayerWrapper(player);
- GuiManager.get().openGui(playerWrapper, args[0]);
- return true;
- }
- }
- return false;
- }
-}
\ No newline at end of file
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/command/bukkit/CustomCommand.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/command/bukkit/CustomCommand.java
deleted file mode 100644
index c8450913f..000000000
--- a/bukkit/src/main/java/com/clubobsidian/dynamicgui/command/bukkit/CustomCommand.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright 2021 Club Obsidian and contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.clubobsidian.dynamicgui.command.bukkit;
-
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-
-public class CustomCommand extends Command {
-
- private CommandExecutor executer = null;
-
- public CustomCommand(String name) {
- super(name);
- }
-
- public boolean execute(CommandSender sender, String commandLabel, String[] args) {
- if(this.executer != null) {
- this.executer.onCommand(sender, this, commandLabel, args);
- }
- return false;
- }
-
- public void setExecutor(CommandExecutor executer) {
- this.executer = executer;
- }
-}
\ No newline at end of file
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/command/bukkit/CustomCommandExecutor.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/command/bukkit/CustomCommandExecutor.java
deleted file mode 100644
index 9ec0d5db7..000000000
--- a/bukkit/src/main/java/com/clubobsidian/dynamicgui/command/bukkit/CustomCommandExecutor.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright 2021 Club Obsidian and contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.clubobsidian.dynamicgui.command.bukkit;
-
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.entity.bukkit.BukkitPlayerWrapper;
-import com.clubobsidian.dynamicgui.manager.dynamicgui.GuiManager;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Player;
-
-public class CustomCommandExecutor implements CommandExecutor {
-
- private final String gui;
-
- public CustomCommandExecutor(String gui) {
- this.gui = gui;
- }
-
- @Override
- public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
- if(sender instanceof Player) {
- Player player = (Player) sender;
- PlayerWrapper> playerWrapper = new BukkitPlayerWrapper<>(player);
- return GuiManager.get().openGui(playerWrapper, this.gui);
- }
- return false;
- }
-}
\ No newline at end of file
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/manager/package-info.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/manager/package-info.java
deleted file mode 100644
index 5cf1cb544..000000000
--- a/bukkit/src/main/java/com/clubobsidian/dynamicgui/manager/package-info.java
+++ /dev/null
@@ -1 +0,0 @@
-package com.clubobsidian.dynamicgui.manager;
\ No newline at end of file
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/package-info.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/package-info.java
deleted file mode 100644
index 953e80505..000000000
--- a/bukkit/src/main/java/com/clubobsidian/dynamicgui/package-info.java
+++ /dev/null
@@ -1 +0,0 @@
-package com.clubobsidian.dynamicgui;
\ No newline at end of file
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/plugin/bukkit/BukkitPlugin.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/plugin/bukkit/BukkitPlugin.java
deleted file mode 100644
index 9979fdfa7..000000000
--- a/bukkit/src/main/java/com/clubobsidian/dynamicgui/plugin/bukkit/BukkitPlugin.java
+++ /dev/null
@@ -1,257 +0,0 @@
-/*
- * Copyright 2021 Club Obsidian and contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.clubobsidian.dynamicgui.plugin.bukkit;
-
-import com.clubobsidian.dynamicgui.DynamicGui;
-import com.clubobsidian.dynamicgui.command.bukkit.BukkitDynamicGuiCommand;
-import com.clubobsidian.dynamicgui.command.bukkit.BukkitGuiCommand;
-import com.clubobsidian.dynamicgui.command.bukkit.CustomCommand;
-import com.clubobsidian.dynamicgui.command.bukkit.CustomCommandExecutor;
-import com.clubobsidian.dynamicgui.economy.Economy;
-import com.clubobsidian.dynamicgui.economy.bukkit.VaultEconomy;
-import com.clubobsidian.dynamicgui.inject.module.PluginModule;
-import com.clubobsidian.dynamicgui.listener.bukkit.EntityClickListener;
-import com.clubobsidian.dynamicgui.listener.bukkit.InventoryCloseListener;
-import com.clubobsidian.dynamicgui.listener.bukkit.InventoryInteractListener;
-import com.clubobsidian.dynamicgui.listener.bukkit.InventoryOpenListener;
-import com.clubobsidian.dynamicgui.listener.bukkit.PlayerInteractListener;
-import com.clubobsidian.dynamicgui.logger.JavaLoggerWrapper;
-import com.clubobsidian.dynamicgui.manager.dynamicgui.ModelManager;
-import com.clubobsidian.dynamicgui.manager.dynamicgui.ReplacerManager;
-import com.clubobsidian.dynamicgui.manager.entity.bukkit.BukkitEntityManager;
-import com.clubobsidian.dynamicgui.manager.inventory.bukkit.BukkitInventoryManager;
-import com.clubobsidian.dynamicgui.manager.inventory.bukkit.BukkitItemStackManager;
-import com.clubobsidian.dynamicgui.manager.material.bukkit.BukkitMaterialManager;
-import com.clubobsidian.dynamicgui.manager.world.bukkit.BukkitLocationManager;
-import com.clubobsidian.dynamicgui.permission.Permission;
-import com.clubobsidian.dynamicgui.permission.bukkit.FoundryPermission;
-import com.clubobsidian.dynamicgui.permission.bukkit.VaultPermission;
-import com.clubobsidian.dynamicgui.plugin.DynamicGuiPlugin;
-import com.clubobsidian.dynamicgui.registry.model.bukkit.ItemsAdderModelProvider;
-import com.clubobsidian.dynamicgui.registry.model.bukkit.OraxenModelProvider;
-import com.clubobsidian.dynamicgui.registry.npc.NPCRegistry;
-import com.clubobsidian.dynamicgui.registry.npc.bukkit.CitizensRegistry;
-import com.clubobsidian.dynamicgui.registry.replacer.bukkit.PlaceholderApiReplacerRegistry;
-import com.clubobsidian.dynamicgui.server.bukkit.FakeBukkitServer;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandMap;
-import org.bukkit.command.SimpleCommandMap;
-import org.bukkit.plugin.PluginManager;
-import org.bukkit.plugin.java.JavaPlugin;
-
-import java.io.File;
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.logging.Level;
-
-public class BukkitPlugin extends JavaPlugin implements DynamicGuiPlugin {
-
- private File configFile;
- private File guiFolder;
- private File macroFolder;
- private Economy economy;
- private Permission permission;
- private List npcRegistries;
- private CommandMap commandMap;
- private List registeredCommands;
-
- @Override
- public void onEnable() {
- this.start();
- }
-
- @Override
- public void start() {
- this.registeredCommands = new ArrayList<>();
- this.configFile = new File(this.getDataFolder(), "config.yml");
- this.guiFolder = new File(this.getDataFolder(), "guis");
- this.macroFolder = new File(this.getDataFolder(), "macros");
-
- new PluginModule()
- .setEntity(BukkitEntityManager.class)
- .setInventory(BukkitInventoryManager.class)
- .setItemStack(BukkitItemStackManager.class)
- .setLocation(BukkitLocationManager.class)
- .setMaterial(BukkitMaterialManager.class)
- .setLogger(new JavaLoggerWrapper<>(this.getLogger()))
- .setPlugin(this)
- .setServer(new FakeBukkitServer())
- .bootstrap();
-
-
- PluginManager pm = this.getServer().getPluginManager();
-
- boolean vault = false;
- boolean foundry = false;
- if(pm.getPlugin("Vault") != null) {
- vault = true;
- }
- if(pm.getPlugin("Foundry") != null) {
- foundry = true;
- }
-
- if(vault && foundry) {
- this.permission = new FoundryPermission();
- } else if(vault) {
- this.permission = new VaultPermission();
- }
-
- if(this.permission != null && !this.permission.setup()) {
- this.permission = null;
- }
-
- if(permission == null) {
- this.getLogger().log(Level.SEVERE, "Vault is not installed, permissions will not work");
- }
-
- this.economy = new VaultEconomy();
- if(!this.economy.setup()) {
- this.economy = null;
- }
-
- if(this.economy == null) {
- this.getLogger().log(Level.SEVERE, "Vault is not installed, economy functions will not work");
- }
-
- this.npcRegistries = new ArrayList<>();
-
- //Hack for adding citizens late
- //For some reason citizens sometimes will load after DynamicGui
- this.getServer().getScheduler().scheduleSyncDelayedTask(this, () -> {
- if(this.getServer().getPluginManager().getPlugin("Citizens") != null) {
- this.getNPCRegistries().add(new CitizensRegistry());
- }
- }, 1);
-
- this.registerModelProviders(pm);
-
- if(this.getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
- ReplacerManager.get().registerReplacerRegistry(new PlaceholderApiReplacerRegistry());
- }
-
- this.getCommand("gui").setExecutor(new BukkitGuiCommand());
- this.getCommand("dynamicgui").setExecutor(new BukkitDynamicGuiCommand());
- this.getServer().getPluginManager().registerEvents(new EntityClickListener(), this);
- this.getServer().getPluginManager().registerEvents(new InventoryInteractListener(), this);
- this.getServer().getPluginManager().registerEvents(new InventoryCloseListener(), this);
- this.getServer().getPluginManager().registerEvents(new InventoryOpenListener(), this);
- this.getServer().getPluginManager().registerEvents(new PlayerInteractListener(), this);
- }
-
- private void registerModelProviders(PluginManager pm) {
- if(pm.getPlugin("Oraxen") != null) {
- ModelManager.get().register(new OraxenModelProvider());
- }
- if(pm.getPlugin("ItemsAdder") != null) {
- ModelManager.get().register(new ItemsAdderModelProvider());
- }
- }
-
- @Override
- public void onDisable() {
- this.stop();
- }
-
- @Override
- public void stop() {
- DynamicGui.get().shutdown();
- }
-
- @Override
- public Economy getEconomy() {
- return this.economy;
- }
-
- @Override
- public Permission getPermission() {
- return this.permission;
- }
-
- @Override
- public List getNPCRegistries() {
- return this.npcRegistries;
- }
-
- @Override
- public File getConfigFile() {
- return this.configFile;
- }
-
- @Override
- public File getGuiFolder() {
- return this.guiFolder;
- }
-
- @Override
- public File getMacroFolder() {
- return this.macroFolder;
- }
-
- private final CommandMap getCommandMap() {
- if(this.commandMap == null) {
- try {
- final Field f = this.getServer().getClass().getDeclaredField("commandMap");
- f.setAccessible(true);
- this.commandMap = (CommandMap) f.get(this.getServer());
- return this.commandMap;
- } catch(Exception e) {
- e.printStackTrace();
- }
- } else if(this.commandMap != null) {
- return this.commandMap;
- }
- return null;
- }
-
- public List getRegisteredCommands() {
- return this.registeredCommands;
- }
-
- private void unregisterCommand(String alias) {
- try {
- Field commandField = SimpleCommandMap.class.getDeclaredField("knownCommands");
- commandField.setAccessible(true);
- @SuppressWarnings("unchecked")
- Map commands = (Map) commandField.get(this.getCommandMap());
- commands.keySet().remove(alias);
- } catch(IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) {
- e.printStackTrace();
- }
- }
-
- @Override
- public void createCommand(String gui, String alias) {
- DynamicGui.get().getLogger().info("Registered the command \"" + alias + "\" for the gui " + gui);
-
- CustomCommand cmd = new CustomCommand(alias);
- this.unregisterCommand(alias);
-
- this.getCommandMap().register("", cmd);
-
-
- cmd.setExecutor(new CustomCommandExecutor(gui));
- this.getRegisteredCommands().add(alias);
- }
-
- @Override
- public void unloadCommands() {
- for(String cmd : this.getRegisteredCommands()) {
- this.unregisterCommand(cmd);
- }
- }
-}
\ No newline at end of file
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/registry/npc/bukkit/package-info.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/registry/npc/bukkit/package-info.java
deleted file mode 100644
index 0d406fc22..000000000
--- a/bukkit/src/main/java/com/clubobsidian/dynamicgui/registry/npc/bukkit/package-info.java
+++ /dev/null
@@ -1 +0,0 @@
-package com.clubobsidian.dynamicgui.registry.npc.bukkit;
\ No newline at end of file
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/registry/package-info.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/registry/package-info.java
deleted file mode 100644
index 794871f9c..000000000
--- a/bukkit/src/main/java/com/clubobsidian/dynamicgui/registry/package-info.java
+++ /dev/null
@@ -1 +0,0 @@
-package com.clubobsidian.dynamicgui.registry;
\ No newline at end of file
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/scheduler/bukkit/BukkitScheduler.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/scheduler/bukkit/BukkitScheduler.java
deleted file mode 100644
index 1f3e9e4f2..000000000
--- a/bukkit/src/main/java/com/clubobsidian/dynamicgui/scheduler/bukkit/BukkitScheduler.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright 2021 Club Obsidian and contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.clubobsidian.dynamicgui.scheduler.bukkit;
-
-import com.clubobsidian.dynamicgui.plugin.DynamicGuiPlugin;
-import com.clubobsidian.dynamicgui.scheduler.Scheduler;
-import org.bukkit.Bukkit;
-import org.bukkit.plugin.Plugin;
-
-public class BukkitScheduler extends Scheduler {
-
- @Override
- public void scheduleSyncDelayedTask(DynamicGuiPlugin plugin, Runnable runnable, Long delay) {
- Bukkit.getScheduler().scheduleSyncDelayedTask((Plugin) plugin, runnable, delay);
- }
-
- @Override
- public void scheduleSyncRepeatingTask(DynamicGuiPlugin plugin, Runnable runnable, Long delayInitial, Long delayRepeating) {
- Bukkit.getScheduler().scheduleSyncRepeatingTask((Plugin) plugin, runnable, delayInitial, delayRepeating);
- }
-
- @Override
- public void scheduleAsyncRepeatingTask(DynamicGuiPlugin plugin, Runnable runnable, Long delayInitial, Long delayRepeating) {
- Bukkit.getServer().getScheduler().runTaskTimerAsynchronously((Plugin) plugin, runnable, delayInitial, delayRepeating);
- }
-}
\ No newline at end of file
diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/util/bukkit/BukkitNBTUtil.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/util/bukkit/BukkitNBTUtil.java
deleted file mode 100644
index 5ba7daf2f..000000000
--- a/bukkit/src/main/java/com/clubobsidian/dynamicgui/util/bukkit/BukkitNBTUtil.java
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * Copyright 2021 Club Obsidian and contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.clubobsidian.dynamicgui.util.bukkit;
-
-import org.bukkit.inventory.ItemStack;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-public final class BukkitNBTUtil {
-
- private static final String ITEM_STACK_CLASS_NAME = getItemStackClass();
- private static final String PARSER_CLASS_NAME = getParserClass();
- private static final String COMPOUND_CLASS_NAME = getCompoundClass();
-
- private static Method parse;
- private static Method asNMSCopy;
- private static Method setTag;
- private static Method asBukkitCopy;
- private static Method getTag;
-
- private BukkitNBTUtil() {
- }
-
- public static Object parse(String nbtStr) {
- if(parse == null) {
- try {
- Class> mojangParser = Class.forName(PARSER_CLASS_NAME);
- parse = mojangParser.getDeclaredMethod("parse", String.class);
- parse.setAccessible(true);
- } catch(ClassNotFoundException | NoSuchMethodException | SecurityException e) {
- e.printStackTrace();
- }
- }
- try {
- return parse.invoke(null, nbtStr);
- } catch(Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
- public static String getTag(ItemStack itemStack) {
- String version = VersionUtil.getVersion();
- try {
- if(asNMSCopy == null) {
- String craftItemStackClassName = "org.bukkit.craftbukkit." + version + ".inventory.CraftItemStack";
- Class> craftItemStackClass;
- craftItemStackClass = Class.forName(craftItemStackClassName);
- asNMSCopy = craftItemStackClass.getDeclaredMethod("asNMSCopy", ItemStack.class);
- asNMSCopy.setAccessible(true);
- }
-
- if(getTag == null) {
- Class> nmsItemStackClass = Class.forName(ITEM_STACK_CLASS_NAME);
- getTag = nmsItemStackClass.getDeclaredMethod("getTag");
- getTag.setAccessible(true);
- }
-
- if(asBukkitCopy == null) {
- Class> nmsItemStackClass = Class.forName(ITEM_STACK_CLASS_NAME);
- String craftItemStackClassName = "org.bukkit.craftbukkit." + version + ".inventory.CraftItemStack";
- Class> craftItemStackClass = Class.forName(craftItemStackClassName);
- asBukkitCopy = craftItemStackClass.getDeclaredMethod("asBukkitCopy", nmsItemStackClass);
- asBukkitCopy.setAccessible(true);
- }
-
- Object nmsItemStack = asNMSCopy.invoke(null, itemStack);
- Object tag = getTag.invoke(nmsItemStack);
- if(tag == null) {
- return null;
- }
-
- return tag.toString();
- } catch(ClassNotFoundException | NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
- e.printStackTrace();
- }
- return null;
- }
-
- public static ItemStack setTag(ItemStack itemStack, String nbt) {
- String version = VersionUtil.getVersion();
- try {
- if(asNMSCopy == null) {
- String craftItemStackClassName = "org.bukkit.craftbukkit." + version + ".inventory.CraftItemStack";
- Class> craftItemStackClass = Class.forName(craftItemStackClassName);
- asNMSCopy = craftItemStackClass.getDeclaredMethod("asNMSCopy", ItemStack.class);
- asNMSCopy.setAccessible(true);
- }
-
- if(setTag == null) {
- Class> nmsItemStackClass = Class.forName(ITEM_STACK_CLASS_NAME);
- Class> nbtTagCompoundClass = Class.forName(COMPOUND_CLASS_NAME);
- setTag = nmsItemStackClass.getDeclaredMethod("setTag", nbtTagCompoundClass);
- setTag.setAccessible(true);
- }
-
- if(asBukkitCopy == null) {
- Class> nmsItemStackClass = Class.forName(ITEM_STACK_CLASS_NAME);
- String craftItemStackClassName = "org.bukkit.craftbukkit." + version + ".inventory.CraftItemStack";
- Class> craftItemStackClass = Class.forName(craftItemStackClassName);
- asBukkitCopy = craftItemStackClass.getDeclaredMethod("asBukkitCopy", nmsItemStackClass);
- asBukkitCopy.setAccessible(true);
- }
-
- Object nmsItemStack = asNMSCopy.invoke(null, itemStack);
- Object nbtCompound = BukkitNBTUtil.parse(nbt);
- setTag.invoke(nmsItemStack, nbtCompound);
- ItemStack bukkitItemStack = (ItemStack) asBukkitCopy.invoke(null, nmsItemStack);
- return bukkitItemStack;
- } catch(ClassNotFoundException | NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
- e.printStackTrace();
- }
- return null;
- }
-
- private static String getItemStackClass() {
- try {
- String className = "net.minecraft.world.item.ItemStack";
- Class.forName(className);
- return className;
- } catch(ClassNotFoundException ex) {
- String version = VersionUtil.getVersion();
- String className = "net.minecraft.server." + version + ".ItemStack";
- try {
- Class.forName(className);
- return className;
- } catch(ClassNotFoundException e) {
- return null;
- }
- }
- }
-
- private static String getParserClass() {
- try {
- String className = "net.minecraft.nbt.MojangsonParser";
- Class.forName(className);
- return className;
- } catch(ClassNotFoundException ex) {
- String version = VersionUtil.getVersion();
- String className = "net.minecraft.server." + version + ".MojangsonParser";
- try {
- Class.forName(className);
- return className;
- } catch(ClassNotFoundException e) {
- return null;
- }
- }
- }
-
- private static String getCompoundClass() {
- try {
- String className = "net.minecraft.nbt.NBTTagCompound";
- Class.forName(className);
- return className;
- } catch(ClassNotFoundException ex) {
- String version = VersionUtil.getVersion();
- String className = "net.minecraft.server." + version + ".NBTTagCompound";
- try {
- Class.forName(className);
- return className;
- } catch(ClassNotFoundException e) {
- return null;
- }
- }
- }
-}
\ No newline at end of file
diff --git a/bukkit/src/main/resources/plugin.yml b/bukkit/src/main/resources/plugin.yml
index 657be9ef3..cf638925c 100644
--- a/bukkit/src/main/resources/plugin.yml
+++ b/bukkit/src/main/resources/plugin.yml
@@ -1,14 +1,6 @@
name: DynamicGui
-main: com.clubobsidian.dynamicgui.plugin.bukkit.BukkitPlugin
+main: com.clubobsidian.dynamicgui.bukkit.plugin.DynamicGuiBukkitPlugin
version: ${pluginVersion}
author: VirusTotal
api-version: 1.13
-softdepend: [Vault, PlaceholderAPI, RedisBungee, PlayerPoints, Citizens, Rankup, Foundry, Oraxen, ItemsAdder]
-commands:
- gui:
- description: "DynamicGUI gui command!"
- guilist:
- description: "Lists out all the guis for DynamicGUI!"
- dynamicgui:
- descriptions: "Command for handling management of DynamicGui guis"
- aliases: ["dyngui"]
\ No newline at end of file
+softdepend: [Vault, PlaceholderAPI, RedisBungee, PlayerPoints, Citizens, Rankup, Foundry, Oraxen, ItemsAdder]
\ No newline at end of file
diff --git a/core/build.gradle b/core/build.gradle
index 86005ed18..3b7602aeb 100644
--- a/core/build.gradle
+++ b/core/build.gradle
@@ -2,6 +2,8 @@ plugins {
id 'java-library'
}
+def adventureVersion = "4.10.1"
+
dependencies {
api 'commons-io:commons-io:2.11.0'
api 'com.github.clubobsidian:trident:3.0.0'
@@ -9,6 +11,7 @@ dependencies {
api 'com.udojava:EvalEx:2.1'
api 'com.github.ClubObsidian:FuzzUtil:1.1.0'
api 'com.google.inject:guice:5.1.0'
- api 'net.kyori:adventure-text-minimessage:4.2.0-SNAPSHOT'
- api 'net.kyori:adventure-text-serializer-gson:4.9.3'
+ api "net.kyori:adventure-text-minimessage:$adventureVersion"
+ api "net.kyori:adventure-text-serializer-gson:$adventureVersion"
+ api "net.kyori:adventure-text-serializer-legacy:$adventureVersion"
}
\ No newline at end of file
diff --git a/core/mock_data/guis/multi-function-test.yml b/core/mock_data/guis/multi-function-test.yml
new file mode 100644
index 000000000..298ac4303
--- /dev/null
+++ b/core/mock_data/guis/multi-function-test.yml
@@ -0,0 +1,25 @@
+title: "test"
+rows: 5
+
+'0':
+ icon: "STONE"
+ functions:
+ load-1:
+ type: "load"
+ functions:
+ - "permission: test"
+ - "condition: STREQUAL(\"test1\", \"test2\")"
+ permission-failfunction:
+ type: fail
+ functions:
+ - "pmsg: test-failed"
+ fail-on: "permission"
+ condtion-failfunction:
+ type: fail
+ functions:
+ - "pmsg: condition failed"
+ fail-on: "condition"
+ click:
+ type: "click"
+ functions:
+ - "pmsg: test"
\ No newline at end of file
diff --git a/core/mock_data/guis/no-fail-function.yml b/core/mock_data/guis/no-fail-function.yml
new file mode 100644
index 000000000..772d66b92
--- /dev/null
+++ b/core/mock_data/guis/no-fail-function.yml
@@ -0,0 +1,10 @@
+title: "test"
+rows: 5
+
+'0':
+ icon: "STONE"
+ functions:
+ load-1:
+ type: "load"
+ functions:
+ - "permission: test"
\ No newline at end of file
diff --git a/core/mock_data/guis/test-fail-no-fail-type.yml b/core/mock_data/guis/test-fail-no-fail-type.yml
new file mode 100644
index 000000000..15bfce11e
--- /dev/null
+++ b/core/mock_data/guis/test-fail-no-fail-type.yml
@@ -0,0 +1,18 @@
+title: "&cTest"
+rows: 6
+mode: set
+
+'0':
+ icon: "DIRT"
+ amount: 1
+ functions:
+ load:
+ type: "load"
+ functions:
+ - 'permission: test'
+ check-type:
+ type: "fail"
+ fail-on:
+ - 'checktick'
+ functions:
+ - 'pmsg: test'
\ No newline at end of file
diff --git a/core/mock_data/guis/test-no-function-type.yml b/core/mock_data/guis/test-no-function-type.yml
new file mode 100644
index 000000000..7b641d8e0
--- /dev/null
+++ b/core/mock_data/guis/test-no-function-type.yml
@@ -0,0 +1,10 @@
+title: "test"
+rows: 5
+
+'0':
+ icon: "DIRT"
+ functions:
+ broadcast:
+ type: "left"
+ functions:
+ - 'broadcast: test'
\ No newline at end of file
diff --git a/core/mock_data/guis/test.yml b/core/mock_data/guis/test.yml
new file mode 100644
index 000000000..6f189fcea
--- /dev/null
+++ b/core/mock_data/guis/test.yml
@@ -0,0 +1,47 @@
+title: "test"
+rows: 5
+
+'0':
+ icon: "STONE"
+ functions:
+ click:
+ type: "click"
+ functions:
+ - "pmsg: test"
+'1':
+ icon: "STONE"
+ functions:
+ click:
+ type: "click"
+ functions:
+ - "haspermission: does.not.exist"
+ fail-haspermission:
+ fail-on: "haspermission"
+ type: "fail"
+ functions:
+ - "pmsg: fail"
+'2':
+ icon: "STONE"
+ functions:
+ click:
+ type: "click"
+ functions:
+ - "delay: 1000"
+ - "pmsg: async"
+'3':
+ icon: "STONE"
+ functions:
+ click:
+ type: "click"
+ functions:
+ - "delay: 1000"
+ - "IsMainThread"
+'4':
+ icon: "STONE"
+ functions:
+ click:
+ type: "click"
+ functions:
+ - "delay: 1000"
+ - "pmsg: test"
+ - "isasyncthread"
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/DynamicGui.java b/core/src/main/java/com/clubobsidian/dynamicgui/DynamicGui.java
deleted file mode 100644
index 8e61bb9c3..000000000
--- a/core/src/main/java/com/clubobsidian/dynamicgui/DynamicGui.java
+++ /dev/null
@@ -1,464 +0,0 @@
-/*
- * Copyright 2021 Club Obsidian and contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.clubobsidian.dynamicgui;
-
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.impl.AddPermissionFunction;
-import com.clubobsidian.dynamicgui.function.impl.CheckItemTypeInHandFunction;
-import com.clubobsidian.dynamicgui.function.impl.CheckLevelFunction;
-import com.clubobsidian.dynamicgui.function.impl.CheckMoveableFunction;
-import com.clubobsidian.dynamicgui.function.impl.CheckPlayerWorldFunction;
-import com.clubobsidian.dynamicgui.function.impl.ConsoleCmdFunction;
-import com.clubobsidian.dynamicgui.function.impl.GetGameRuleFunction;
-import com.clubobsidian.dynamicgui.function.impl.IsBedrockPlayerFunction;
-import com.clubobsidian.dynamicgui.function.impl.LogFunction;
-import com.clubobsidian.dynamicgui.function.impl.MoneyBalanceFunction;
-import com.clubobsidian.dynamicgui.function.impl.MoneyDepositFunction;
-import com.clubobsidian.dynamicgui.function.impl.MoneyWithdrawFunction;
-import com.clubobsidian.dynamicgui.function.impl.NoPermissionFunction;
-import com.clubobsidian.dynamicgui.function.impl.ParticleFunction;
-import com.clubobsidian.dynamicgui.function.impl.PermissionFunction;
-import com.clubobsidian.dynamicgui.function.impl.PlayerCmdFunction;
-import com.clubobsidian.dynamicgui.function.impl.PlayerMiniMsgFunction;
-import com.clubobsidian.dynamicgui.function.impl.PlayerMsgFunction;
-import com.clubobsidian.dynamicgui.function.impl.RandomFunction;
-import com.clubobsidian.dynamicgui.function.impl.RemovePermissionFunction;
-import com.clubobsidian.dynamicgui.function.impl.RemoveSlotFunction;
-import com.clubobsidian.dynamicgui.function.impl.ResetFrameFunction;
-import com.clubobsidian.dynamicgui.function.impl.ResetTickFunction;
-import com.clubobsidian.dynamicgui.function.impl.SendFunction;
-import com.clubobsidian.dynamicgui.function.impl.ServerBroadcastFunction;
-import com.clubobsidian.dynamicgui.function.impl.ServerMiniBroadcastFunction;
-import com.clubobsidian.dynamicgui.function.impl.SetAmountFunction;
-import com.clubobsidian.dynamicgui.function.impl.SetCloseFunction;
-import com.clubobsidian.dynamicgui.function.impl.SetDataFunction;
-import com.clubobsidian.dynamicgui.function.impl.SetEnchantsFunction;
-import com.clubobsidian.dynamicgui.function.impl.SetGameRuleFunction;
-import com.clubobsidian.dynamicgui.function.impl.SetGlowFunction;
-import com.clubobsidian.dynamicgui.function.impl.SetLoreFunction;
-import com.clubobsidian.dynamicgui.function.impl.SetMoveableFunction;
-import com.clubobsidian.dynamicgui.function.impl.SetNBTFunction;
-import com.clubobsidian.dynamicgui.function.impl.SetNameFunction;
-import com.clubobsidian.dynamicgui.function.impl.SetTypeFunction;
-import com.clubobsidian.dynamicgui.function.impl.SoundFunction;
-import com.clubobsidian.dynamicgui.function.impl.StatisticFunction;
-import com.clubobsidian.dynamicgui.function.impl.condition.CheckTickFunction;
-import com.clubobsidian.dynamicgui.function.impl.condition.ConditionFunction;
-import com.clubobsidian.dynamicgui.function.impl.cooldown.IsNotOnCooldownFunction;
-import com.clubobsidian.dynamicgui.function.impl.cooldown.IsOnCooldownFunction;
-import com.clubobsidian.dynamicgui.function.impl.cooldown.SetCooldownFunction;
-import com.clubobsidian.dynamicgui.function.impl.gui.BackFunction;
-import com.clubobsidian.dynamicgui.function.impl.gui.GuiFunction;
-import com.clubobsidian.dynamicgui.function.impl.gui.HasBackFunction;
-import com.clubobsidian.dynamicgui.function.impl.gui.RefreshGuiFunction;
-import com.clubobsidian.dynamicgui.function.impl.gui.RefreshSlotFunction;
-import com.clubobsidian.dynamicgui.function.impl.gui.SetBackFunction;
-import com.clubobsidian.dynamicgui.function.impl.meta.CopyBackMetadataFunction;
-import com.clubobsidian.dynamicgui.function.impl.meta.HasMetadataFunction;
-import com.clubobsidian.dynamicgui.function.impl.meta.IsGuiMetadataSet;
-import com.clubobsidian.dynamicgui.function.impl.meta.SetMetadataFunction;
-import com.clubobsidian.dynamicgui.logger.LoggerWrapper;
-import com.clubobsidian.dynamicgui.listener.EntityClickListener;
-import com.clubobsidian.dynamicgui.listener.GuiListener;
-import com.clubobsidian.dynamicgui.listener.InventoryCloseListener;
-import com.clubobsidian.dynamicgui.listener.InventoryInteractListener;
-import com.clubobsidian.dynamicgui.listener.InventoryOpenListener;
-import com.clubobsidian.dynamicgui.listener.PlayerInteractListener;
-import com.clubobsidian.dynamicgui.manager.dynamicgui.AnimationReplacerManager;
-import com.clubobsidian.dynamicgui.manager.dynamicgui.FunctionManager;
-import com.clubobsidian.dynamicgui.manager.dynamicgui.GuiManager;
-import com.clubobsidian.dynamicgui.manager.dynamicgui.ReplacerManager;
-import com.clubobsidian.dynamicgui.manager.dynamicgui.SlotManager;
-import com.clubobsidian.dynamicgui.manager.dynamicgui.cooldown.CooldownManager;
-import com.clubobsidian.dynamicgui.messaging.MessagingRunnable;
-import com.clubobsidian.dynamicgui.plugin.DynamicGuiPlugin;
-import com.clubobsidian.dynamicgui.proxy.Proxy;
-import com.clubobsidian.dynamicgui.registry.replacer.impl.CooldownReplacerRegistry;
-import com.clubobsidian.dynamicgui.registry.replacer.impl.DynamicGuiAnimationReplacerRegistry;
-import com.clubobsidian.dynamicgui.registry.replacer.impl.DynamicGuiReplacerRegistry;
-import com.clubobsidian.dynamicgui.registry.replacer.impl.MetadataReplacerRegistry;
-import com.clubobsidian.dynamicgui.replacer.Replacer;
-import com.clubobsidian.dynamicgui.server.FakeServer;
-import com.clubobsidian.dynamicgui.util.ChatColor;
-import com.clubobsidian.trident.EventBus;
-import com.clubobsidian.trident.eventbus.methodhandle.MethodHandleEventBus;
-import com.clubobsidian.wrappy.Configuration;
-import com.google.common.collect.Iterables;
-import com.google.common.io.ByteArrayDataInput;
-import com.google.common.io.ByteArrayDataOutput;
-import com.google.common.io.ByteStreams;
-import com.google.inject.Inject;
-import com.google.inject.Injector;
-import org.apache.commons.io.FileUtils;
-
-import java.io.IOException;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-public class DynamicGui {
-
- @Inject
- private static DynamicGui instance;
-
- public static DynamicGui get() {
- if(!instance.initialized) {
- instance.initialized = true;
- instance.init();
- }
-
- return instance;
- }
-
- private String noGui;
- private Proxy proxy;
- private String dateTimeFormat;
- private final Map serverPlayerCount;
- private final EventBus eventManager;
- private final DynamicGuiPlugin plugin;
- private final FakeServer server;
- private final LoggerWrapper> loggerWrapper;
- private final Injector injector;
- private boolean initialized;
-
- @Inject
- private DynamicGui(DynamicGuiPlugin plugin, FakeServer server, LoggerWrapper> loggerWrapper, Injector injector) {
- this.plugin = plugin;
- this.server = server;
- this.loggerWrapper = loggerWrapper;
- this.injector = injector;
- this.serverPlayerCount = new ConcurrentHashMap<>();
- this.initialized = false;
- this.setupFileStructure();
- this.saveDefaultConfig();
- this.eventManager = new MethodHandleEventBus();
- }
-
- private void init() {
- this.loadConfig();
- this.loadFunctions();
- this.loadGuis();
- this.checkForProxy();
- this.registerListeners();
- ReplacerManager.get().registerReplacerRegistry(DynamicGuiReplacerRegistry.get());
- ReplacerManager.get().registerReplacerRegistry(CooldownReplacerRegistry.get());
- ReplacerManager.get().registerReplacerRegistry(MetadataReplacerRegistry.get());
- AnimationReplacerManager.get().registerReplacerRegistry(DynamicGuiAnimationReplacerRegistry.get());
- SlotManager.get();
- CooldownManager.get();
- }
-
- public void shutdown() {
- CooldownManager.get().shutdown();
- }
-
- private void setupFileStructure() {
- if(!this.plugin.getDataFolder().exists()) {
- this.plugin.getDataFolder().mkdirs();
- }
-
- if(!this.plugin.getGuiFolder().exists()) {
- this.plugin.getGuiFolder().mkdirs();
- }
-
- if(!this.plugin.getMacroFolder().exists()) {
- this.plugin.getMacroFolder().mkdirs();
- }
- }
-
- private void saveDefaultConfig() {
- if(!this.plugin.getConfigFile().exists()) {
- try {
- FileUtils
- .copyInputStreamToFile(this.getClass().getClassLoader().getResourceAsStream("config.yml"),
- this.plugin.getConfigFile());
- } catch(IOException e) {
- e.printStackTrace();
- }
- }
- }
-
- private void loadConfig() {
- Configuration config = Configuration.load(this.plugin.getConfigFile());
- this.noGui = ChatColor.translateAlternateColorCodes('&', config.getString("no-gui"));
- String version = config.getString("version");
- if(version != null) {
- version = version.trim();
- }
-
- String proxyStr = config.getString("proxy");
- if(proxyStr == null) {
- proxyStr = version;
- config.set("proxy", proxyStr);
- config.save();
- } else {
- proxyStr = proxyStr.trim();
- }
-
- this.proxy = this.findProxyByString(proxyStr);
-
- String dateTimeFormat = config.getString("date-time-format");
- if(dateTimeFormat == null) {
- dateTimeFormat = "MM dd, yyyy HH:mm:ss";
- config.set("date-time-format", dateTimeFormat);
- config.save();
- } else {
- dateTimeFormat = dateTimeFormat.trim();
- }
-
- this.dateTimeFormat = dateTimeFormat;
-
- for(final String server : config.getStringList("servers")) {
- this.serverPlayerCount.put(server, 0);
-
- DynamicGuiReplacerRegistry.get().addReplacer(new Replacer("%" + server + "-playercount%") {
- @Override
- public String replacement(String text, PlayerWrapper> player) {
- return String.valueOf(serverPlayerCount.get(server));
- }
- });
- }
- }
-
- private void loadGuis() {
- GuiManager.get(); //Initialize manager
- }
-
- public void checkForProxy() {
- MessagingRunnable runnable = (playerWrapper, message) ->
- {
- if(message.length > 13) {
- ByteArrayDataInput in = ByteStreams.newDataInput(message);
- String packet = in.readUTF();
- if(packet != null) {
- if("PlayerCount".equals(packet)) {
- String server = in.readUTF();
- int playerCount = in.readInt();
- this.serverPlayerCount.put(server, playerCount);
- }
- }
- }
- };
-
- if(this.proxy == Proxy.BUNGEECORD) {
- this.getLogger().info("BungeeCord is enabled!");
- this.getServer().registerOutgoingPluginChannel(this.getPlugin(), "BungeeCord");
- this.getServer().registerIncomingPluginChannel(this.getPlugin(), "BungeeCord", runnable);
- } else if(this.proxy == Proxy.REDIS_BUNGEE) {
- this.getLogger().info("RedisBungee is enabled");
- this.getServer().registerOutgoingPluginChannel(this.getPlugin(), "RedisBungee");
- this.getServer().registerOutgoingPluginChannel(this.getPlugin(), "BungeeCord");
- this.getServer().registerIncomingPluginChannel(this.getPlugin(), "RedisBungee", runnable);
- } else {
- this.getLogger().info("A proxy is not in use, please configure the proxy config value if you need proxy support!");
- }
-
- if(this.proxy != Proxy.NONE) {
- this.startPlayerCountTimer();
- }
- }
-
- private void registerListeners() {
- this.eventManager.registerEvents(new EntityClickListener());
- this.eventManager.registerEvents(new InventoryInteractListener());
- this.eventManager.registerEvents(new InventoryCloseListener());
- this.eventManager.registerEvents(new InventoryOpenListener());
- this.eventManager.registerEvents(new PlayerInteractListener());
- this.eventManager.registerEvents(new GuiListener());
- }
-
- private void loadFunctions() {
- FunctionManager.get().addFunction(new CheckTickFunction("checktick"));
- FunctionManager.get().addFunction(new ConditionFunction("condition"));
- FunctionManager.get().addFunction(new ResetFrameFunction("resetframe"));
- FunctionManager.get().addFunction(new ResetTickFunction("resettick"));
-
- FunctionManager.get().addFunction(new ConsoleCmdFunction("executec"));
- FunctionManager.get().addFunction(new PlayerCmdFunction("executep"));
- //FunctionApi.get().addFunction(new ExpPayFunction("payexp"));
-
- FunctionManager.get().addFunction(new SetCooldownFunction("setcooldown"));
- FunctionManager.get().addFunction(new IsOnCooldownFunction("isoncooldown"));
- FunctionManager.get().addFunction(new IsNotOnCooldownFunction("isnotoncooldown"));
-
- FunctionManager.get().addFunction(new GuiFunction("gui"));
- FunctionManager.get().addFunction(new BackFunction("back"));
- FunctionManager.get().addFunction(new HasBackFunction("hasback"));
- FunctionManager.get().addFunction(new SetBackFunction("setback"));
-
- FunctionManager.get().addFunction(new RefreshGuiFunction("refreshgui"));
- FunctionManager.get().addFunction(new RefreshSlotFunction("refreshslot"));
-
- FunctionManager.get().addFunction(new MoneyWithdrawFunction("moneywithdraw"));
- FunctionManager.get().addFunction(new MoneyDepositFunction("moneydeposit"));
- FunctionManager.get().addFunction(new MoneyBalanceFunction("moneybalance"));
-
- FunctionManager.get().addFunction(new NoPermissionFunction("nopermission"));
- FunctionManager.get().addFunction(new PermissionFunction("permission"));
- FunctionManager.get().addFunction(new PermissionFunction("haspermission"));
- FunctionManager.get().addFunction(new AddPermissionFunction("addpermission"));
- FunctionManager.get().addFunction(new RemovePermissionFunction("removepermission"));
- FunctionManager.get().addFunction(new PlayerMsgFunction("pmsg"));
- FunctionManager.get().addFunction(new RandomFunction("random"));
- FunctionManager.get().addFunction(new SendFunction("send"));
- FunctionManager.get().addFunction(new ServerBroadcastFunction("broadcast"));
- FunctionManager.get().addFunction(new ParticleFunction("particles"));
- FunctionManager.get().addFunction(new SoundFunction("sound"));
- FunctionManager.get().addFunction(new SetNameFunction("setname"));
- FunctionManager.get().addFunction(new SetLoreFunction("setlore"));
- FunctionManager.get().addFunction(new SetTypeFunction("settype"));
- FunctionManager.get().addFunction(new SetDataFunction("setdata"));
- FunctionManager.get().addFunction(new SetAmountFunction("setamount"));
- FunctionManager.get().addFunction(new SetNBTFunction("setnbt"));
- FunctionManager.get().addFunction(new SetGlowFunction("setglow"));
- FunctionManager.get().addFunction(new CheckMoveableFunction("checkmoveable"));
- FunctionManager.get().addFunction(new SetMoveableFunction("setmoveable"));
- FunctionManager.get().addFunction(new SetEnchantsFunction("setenchants"));
- FunctionManager.get().addFunction(new SetCloseFunction("setclose"));
- FunctionManager.get().addFunction(new RemoveSlotFunction("removeslot"));
- FunctionManager.get().addFunction(new StatisticFunction("statistic"));
- FunctionManager.get().addFunction(new CheckLevelFunction("checklevel"));
- FunctionManager.get().addFunction(new LogFunction("log"));
-
- FunctionManager.get().addFunction(new CheckItemTypeInHandFunction("checkitemtypeinhand"));
-
- FunctionManager.get().addFunction(new SetGameRuleFunction("setgamerule"));
- FunctionManager.get().addFunction(new GetGameRuleFunction("getgamerule"));
-
- FunctionManager.get().addFunction(new CheckPlayerWorldFunction("checkplayerworld"));
-
- FunctionManager.get().addFunction(new PlayerMiniMsgFunction("minimsg"));
- FunctionManager.get().addFunction(new ServerMiniBroadcastFunction("minibroadcast"));
-
- FunctionManager.get().addFunction(new HasMetadataFunction("hasmetadata"));
- FunctionManager.get().addFunction(new HasMetadataFunction("getmetadata"));
- FunctionManager.get().addFunction(new SetMetadataFunction("setmetadata"));
- FunctionManager.get().addFunction(new IsGuiMetadataSet());
- FunctionManager.get().addFunction(new CopyBackMetadataFunction("copybackmetadata"));
-
- FunctionManager.get().addFunction(new IsBedrockPlayerFunction("isbedrockplayer"));
- }
-
- private void startPlayerCountTimer() {
- this.getServer().getScheduler().scheduleSyncRepeatingTask(this.getPlugin(), () -> {
- for(String server : serverPlayerCount.keySet()) {
- PlayerWrapper> player = Iterables.getFirst(this.getServer().getOnlinePlayers(), null);
- if(player != null) {
- ByteArrayDataOutput out = ByteStreams.newDataOutput();
- out.writeUTF("PlayerCount");
- out.writeUTF(server);
- String sendTo = "BungeeCord";
- if(this.proxy == Proxy.REDIS_BUNGEE) {
- sendTo = "RedisBungee";
- }
-
- player.sendPluginMessage(this.getPlugin(), sendTo, out.toByteArray());
- }
- }
- }, 1L, 20L);
- }
-
- public String getNoGui() {
- return this.noGui;
- }
-
- @Deprecated
- public boolean getBungeeCord() {
- return this.proxy == Proxy.BUNGEECORD;
- }
-
- @Deprecated
- public boolean getRedisBungee() {
- return this.proxy == Proxy.REDIS_BUNGEE;
- }
-
- public Proxy getProxy() {
- return this.proxy;
- }
-
- public String getDateTimeFormat() {
- return this.dateTimeFormat;
- }
-
- public DynamicGuiPlugin getPlugin() {
- return this.plugin;
- }
-
- public EventBus getEventBus() {
- return this.eventManager;
- }
-
- public FakeServer getServer() {
- return this.server;
- }
-
- public LoggerWrapper> getLogger() {
- return this.loggerWrapper;
- }
-
- public Integer getGlobalServerPlayerCount() {
- int globalPlayerCount = 0;
- for(int playerCount : this.serverPlayerCount.values()) {
- globalPlayerCount += playerCount;
- }
-
- return globalPlayerCount;
- }
-
- public Integer getServerPlayerCount(String server) {
- return this.serverPlayerCount.get(server);
- }
-
- public Injector getInjector() {
- return this.injector;
- }
-
- //Hack for checking for Java 8, temp work around for trident
- /*private EventBus getVersionEventBus()
- {
- String version = System.getProperty("java.version");
- if(version.startsWith("1.8") && !this.useReflectionEventBus)
- {
- return new JavassistEventBus();
- }
-
- this.loggerWrapper.info("Falling back to the reflection eventbus for better compatability");
- return new ReflectionEventBus();
- }*/
-
- private Proxy findProxyByString(String proxyStr) {
- if(proxyStr.equalsIgnoreCase("bungee") || proxyStr.equalsIgnoreCase("bungeecord")) {
- return Proxy.BUNGEECORD;
- } else if(proxyStr.equalsIgnoreCase("redis") || proxyStr.equalsIgnoreCase("redisbungee")) {
- return Proxy.REDIS_BUNGEE;
- }
-
- return Proxy.NONE;
- }
-
- public boolean sendToServer(PlayerWrapper> playerWrapper, String server) {
- if(this.server == null) {
- return false;
- } else if(this.proxy == Proxy.BUNGEECORD || this.proxy == Proxy.REDIS_BUNGEE) {
- ByteArrayDataOutput out = ByteStreams.newDataOutput();
- out.writeUTF("Connect");
- out.writeUTF(server);
- playerWrapper.sendPluginMessage(DynamicGui.get().getPlugin(), "BungeeCord", out.toByteArray());
- return true;
- }
-
- return false;
- }
-}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/Constant.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/Constant.java
new file mode 100644
index 000000000..3fa11558f
--- /dev/null
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/Constant.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.core;
+
+import java.util.function.Function;
+
+public final class Constant {
+
+ public static final String GUI_BASE_PERMISSION = "dynamicgui.command.gui";
+ public static final Function GUI_PERMISSION = (gui) -> GUI_BASE_PERMISSION + "." + gui;
+ public static final String DYNAMIC_GUI_COMMAND_BASE_PERMISSION = "dynamicgui.command.admin";
+ public static final String DYNAMIC_GUI_COMMAND_RELOAD_PERMISSION = DYNAMIC_GUI_COMMAND_BASE_PERMISSION + ".reload";
+ public static final String DYNAMIC_GUI_COMMAND_CLOSE_PERMISSION = DYNAMIC_GUI_COMMAND_BASE_PERMISSION + ".close";
+ public static final String DYNAMIC_GUI_LIST_PERMISSION = DYNAMIC_GUI_COMMAND_BASE_PERMISSION + ".list";
+
+ public static final String NATIVE_ANNOTATION = "native";
+ public static final String PLATFORM_ANNOTATION = "platform";
+ public static final String NAMESPACE = "dynamicgui";
+
+ private Constant() {
+ }
+}
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/DynamicGui.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/DynamicGui.java
new file mode 100644
index 000000000..a336b98d9
--- /dev/null
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/DynamicGui.java
@@ -0,0 +1,359 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.core;
+
+import com.clubobsidian.dynamicgui.core.command.CommandRegistrar;
+import com.clubobsidian.dynamicgui.core.command.DynamicGuiCommand;
+import com.clubobsidian.dynamicgui.core.command.GuiCommand;
+import com.clubobsidian.dynamicgui.core.config.ChatColorTransformer;
+import com.clubobsidian.dynamicgui.core.config.Message;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import com.clubobsidian.dynamicgui.core.listener.EntityClickListener;
+import com.clubobsidian.dynamicgui.core.listener.GuiListener;
+import com.clubobsidian.dynamicgui.core.listener.InventoryCloseListener;
+import com.clubobsidian.dynamicgui.core.listener.InventoryInteractListener;
+import com.clubobsidian.dynamicgui.core.listener.PlayerInteractListener;
+import com.clubobsidian.dynamicgui.core.logger.LoggerWrapper;
+import com.clubobsidian.dynamicgui.core.manager.dynamicgui.AnimationReplacerManager;
+import com.clubobsidian.dynamicgui.core.manager.dynamicgui.FunctionManager;
+import com.clubobsidian.dynamicgui.core.manager.dynamicgui.GuiManager;
+import com.clubobsidian.dynamicgui.core.manager.dynamicgui.ReplacerManager;
+import com.clubobsidian.dynamicgui.core.manager.dynamicgui.SlotManager;
+import com.clubobsidian.dynamicgui.core.manager.dynamicgui.cooldown.CooldownManager;
+import com.clubobsidian.dynamicgui.core.messaging.MessagingRunnable;
+import com.clubobsidian.dynamicgui.core.platform.Platform;
+import com.clubobsidian.dynamicgui.core.plugin.DynamicGuiPlugin;
+import com.clubobsidian.dynamicgui.core.proxy.Proxy;
+import com.clubobsidian.dynamicgui.core.registry.replacer.impl.CooldownReplacerRegistry;
+import com.clubobsidian.dynamicgui.core.registry.replacer.impl.DynamicGuiAnimationReplacerRegistry;
+import com.clubobsidian.dynamicgui.core.registry.replacer.impl.DynamicGuiReplacerRegistry;
+import com.clubobsidian.dynamicgui.core.registry.replacer.impl.MetadataReplacerRegistry;
+import com.clubobsidian.dynamicgui.core.replacer.Replacer;
+import com.clubobsidian.trident.EventBus;
+import com.clubobsidian.trident.eventbus.methodhandle.MethodHandleEventBus;
+import com.clubobsidian.wrappy.Configuration;
+import com.clubobsidian.wrappy.ConfigurationSection;
+import com.clubobsidian.wrappy.transformer.NodeTransformer;
+import com.google.common.collect.Iterables;
+import com.google.common.io.ByteArrayDataInput;
+import com.google.common.io.ByteArrayDataOutput;
+import com.google.common.io.ByteStreams;
+import com.google.inject.Injector;
+import io.github.classgraph.ClassGraph;
+import io.github.classgraph.ClassInfo;
+import io.github.classgraph.ScanResult;
+import org.apache.commons.io.FileUtils;
+
+import javax.inject.Inject;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class DynamicGui {
+
+ @Inject
+ private static DynamicGui instance;
+
+ public static DynamicGui get() {
+ return instance;
+ }
+
+ private Message message;
+ private Proxy proxy;
+ private String dateTimeFormat;
+ private final Map serverPlayerCount = new ConcurrentHashMap<>();
+ private final EventBus eventBus = new MethodHandleEventBus();
+ private final DynamicGuiPlugin plugin;
+ private final Platform platform;
+ private final LoggerWrapper> loggerWrapper;
+ private final Injector injector;
+ private final CommandRegistrar commandRegistrar;
+ private boolean initialized;
+
+ @Inject
+ private DynamicGui(DynamicGuiPlugin plugin,
+ Platform platform,
+ LoggerWrapper> loggerWrapper,
+ Injector injector,
+ CommandRegistrar commandRegistrar) {
+ this.plugin = plugin;
+ this.platform = platform;
+ this.loggerWrapper = loggerWrapper;
+ this.commandRegistrar = commandRegistrar;
+ this.injector = injector;
+ this.initialized = false;
+ this.setupFileStructure();
+ this.saveDefaultConfig();
+ }
+
+ public boolean start() {
+ if(!this.initialized) {
+ this.initialized = true;
+ this.loadConfig();
+ this.loadFunctions();
+ this.loadGuis();
+ this.checkForProxy();
+ this.registerListeners();
+ this.registerCommands();
+ ReplacerManager.get().registerReplacerRegistry(DynamicGuiReplacerRegistry.get());
+ ReplacerManager.get().registerReplacerRegistry(CooldownReplacerRegistry.get());
+ ReplacerManager.get().registerReplacerRegistry(MetadataReplacerRegistry.get());
+ AnimationReplacerManager.get().registerReplacerRegistry(DynamicGuiAnimationReplacerRegistry.get());
+ SlotManager.get();
+ CooldownManager.get();
+ return true;
+ }
+ return false;
+ }
+
+ public void stop() {
+ CooldownManager.get().shutdown();
+ this.commandRegistrar.unregisterCommand("gui");
+ this.commandRegistrar.unregisterCommand("dynamicgui");
+ this.commandRegistrar.unregisterCommand("dyngui");
+ this.commandRegistrar.unregisterGuiAliases();
+ }
+
+ private void setupFileStructure() {
+ if (!this.plugin.getDataFolder().exists()) {
+ this.plugin.getDataFolder().mkdirs();
+ }
+
+ if (!this.plugin.getGuiFolder().exists()) {
+ this.plugin.getGuiFolder().mkdirs();
+ }
+
+ if (!this.plugin.getMacroFolder().exists()) {
+ this.plugin.getMacroFolder().mkdirs();
+ }
+ }
+
+ private void saveDefaultConfig() {
+ if (!this.plugin.getConfigFile().exists()) {
+ try {
+ FileUtils.copyInputStreamToFile(this.getClass()
+ .getClassLoader()
+ .getResourceAsStream("config.yml"),
+ this.plugin.getConfigFile());
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private void loadConfig() {
+ this.message = new Message();
+ Configuration config = Configuration.load(this.plugin.getConfigFile());
+ ConfigurationSection messageSection = config.getConfigurationSection("message");
+ Collection transformers = new ArrayList<>();
+ transformers.add(new ChatColorTransformer());
+ messageSection.inject(this.message, transformers);
+ String version = config.getString("version");
+ if (version != null) {
+ version = version.trim();
+ }
+
+ String proxyStr = config.getString("proxy");
+ if (proxyStr == null) {
+ proxyStr = version;
+ config.set("proxy", proxyStr);
+ config.save();
+ } else {
+ proxyStr = proxyStr.trim();
+ }
+
+ this.proxy = Proxy.fromString(proxyStr);
+
+ String dateTimeFormat = config.getString("date-time-format");
+ if (dateTimeFormat == null) {
+ dateTimeFormat = "MM dd, yyyy HH:mm:ss";
+ config.set("date-time-format", dateTimeFormat);
+ config.save();
+ } else {
+ dateTimeFormat = dateTimeFormat.trim();
+ }
+
+ this.dateTimeFormat = dateTimeFormat;
+
+ for (final String server : config.getStringList("servers")) {
+ this.serverPlayerCount.put(server, 0);
+
+ DynamicGuiReplacerRegistry.get().addReplacer(new Replacer("%" + server + "-playercount%") {
+ @Override
+ public String replacement(String text, PlayerWrapper> player) {
+ return String.valueOf(getServerPlayerCount(server));
+ }
+ });
+ }
+ }
+
+ private void loadGuis() {
+ GuiManager.get(); //Initialize manager
+ }
+
+ public void checkForProxy() {
+ MessagingRunnable runnable = (playerWrapper, message) -> {
+ if (message.length > 13) {
+ ByteArrayDataInput in = ByteStreams.newDataInput(message);
+ String packet = in.readUTF();
+ if (packet != null) {
+ if ("PlayerCount".equals(packet)) {
+ String server = in.readUTF();
+ int playerCount = in.readInt();
+ this.serverPlayerCount.put(server, playerCount);
+ }
+ }
+ }
+ };
+
+ if (this.proxy == Proxy.BUNGEECORD) {
+ this.getLogger().info("BungeeCord is enabled!");
+ this.getPlatform().registerOutgoingPluginChannel(this.getPlugin(), "BungeeCord");
+ this.getPlatform().registerIncomingPluginChannel(this.getPlugin(), "BungeeCord", runnable);
+ } else if (this.proxy == Proxy.REDIS_BUNGEE) {
+ this.getLogger().info("RedisBungee is enabled");
+ this.getPlatform().registerOutgoingPluginChannel(this.getPlugin(), "RedisBungee");
+ this.getPlatform().registerOutgoingPluginChannel(this.getPlugin(), "BungeeCord");
+ this.getPlatform().registerIncomingPluginChannel(this.getPlugin(), "RedisBungee", runnable);
+ } else {
+ this.getLogger().info("A proxy is not in use, please configure the proxy config value if you need proxy support!");
+ }
+
+ if (this.proxy != Proxy.NONE) {
+ this.startPlayerCountTimer();
+ }
+ }
+
+ private void registerListeners() {
+ this.eventBus.registerEvents(new EntityClickListener());
+ this.eventBus.registerEvents(new InventoryInteractListener());
+ this.eventBus.registerEvents(new InventoryCloseListener());
+ this.eventBus.registerEvents(new PlayerInteractListener());
+ this.eventBus.registerEvents(new GuiListener());
+ }
+
+ private void registerCommands() {
+ this.commandRegistrar.registerCommand(GuiCommand.class);
+ this.commandRegistrar.registerCommand(DynamicGuiCommand.class);
+ }
+
+ private void loadFunctions() {
+ try (ScanResult scanResult = new ClassGraph()
+ .enableAllInfo()
+ .acceptPackages(Function.class.getPackageName())
+ .scan()) {
+ for (ClassInfo classInfo : scanResult.getSubclasses(Function.class)) {
+ try {
+ FunctionManager.get().addFunction((Function) classInfo
+ .loadClass()
+ .getDeclaredConstructor()
+ .newInstance());
+ } catch (InstantiationException | IllegalAccessException |
+ InvocationTargetException | NoSuchMethodException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ private void startPlayerCountTimer() {
+ this.getPlatform().getScheduler().scheduleSyncRepeatingTask(() -> {
+ for (String server : this.serverPlayerCount.keySet()) {
+ PlayerWrapper> player = Iterables.getFirst(this.getPlatform().getOnlinePlayers(), null);
+ if (player != null) {
+ ByteArrayDataOutput out = ByteStreams.newDataOutput();
+ out.writeUTF("PlayerCount");
+ out.writeUTF(server);
+ String sendTo = "BungeeCord";
+ if (this.proxy == Proxy.REDIS_BUNGEE) {
+ sendTo = "RedisBungee";
+ }
+ player.sendPluginMessage(sendTo, out.toByteArray());
+ }
+ }
+ }, 1L, 20L);
+ }
+
+ public Message getMessage() {
+ return this.message;
+ }
+
+ @Deprecated
+ public boolean getBungeeCord() {
+ return this.proxy == Proxy.BUNGEECORD;
+ }
+
+ @Deprecated
+ public boolean getRedisBungee() {
+ return this.proxy == Proxy.REDIS_BUNGEE;
+ }
+
+ public Proxy getProxy() {
+ return this.proxy;
+ }
+
+ public String getDateTimeFormat() {
+ return this.dateTimeFormat;
+ }
+
+ public DynamicGuiPlugin getPlugin() {
+ return this.plugin;
+ }
+
+ public EventBus getEventBus() {
+ return this.eventBus;
+ }
+
+ public Platform getPlatform() {
+ return this.platform;
+ }
+
+ public LoggerWrapper> getLogger() {
+ return this.loggerWrapper;
+ }
+
+ public int getGlobalServerPlayerCount() {
+ int globalPlayerCount = 0;
+ for (int playerCount : this.serverPlayerCount.values()) {
+ globalPlayerCount += playerCount;
+ }
+ return globalPlayerCount;
+ }
+
+ public int getServerPlayerCount(String server) {
+ return this.serverPlayerCount.getOrDefault(server, -1);
+ }
+
+ public Injector getInjector() {
+ return this.injector;
+ }
+
+ public boolean sendToServer(PlayerWrapper> playerWrapper, String server) {
+ if (this.platform != null && (this.proxy == Proxy.BUNGEECORD || this.proxy == Proxy.REDIS_BUNGEE)) {
+ ByteArrayDataOutput out = ByteStreams.newDataOutput();
+ out.writeUTF("Connect");
+ out.writeUTF(server);
+ playerWrapper.sendPluginMessage("BungeeCord", out.toByteArray());
+ return true;
+ }
+ return false;
+ }
+}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/Key.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/Key.java
new file mode 100644
index 000000000..f55195e95
--- /dev/null
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/Key.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.core;
+
+public class Key {
+
+ public static Key create(String value) {
+ return new Key(value);
+ }
+
+ private final String namespace;
+ private final String value;
+
+ public Key(String value) {
+ this(Constant.NAMESPACE, value);
+ }
+
+ public Key(String namespace, String value) {
+ this.namespace = namespace;
+ this.value = value;
+ }
+
+ public String toString() {
+ return this.namespace + ":" + value;
+ }
+}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/builder/EnchantmentBuilder.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/builder/EnchantmentBuilder.java
similarity index 83%
rename from core/src/main/java/com/clubobsidian/dynamicgui/builder/EnchantmentBuilder.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/builder/EnchantmentBuilder.java
index 376428944..6dc0cc411 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/builder/EnchantmentBuilder.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/builder/EnchantmentBuilder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,14 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.builder;
-import com.clubobsidian.dynamicgui.enchantment.EnchantmentWrapper;
+package com.clubobsidian.dynamicgui.core.builder;
+
+import com.clubobsidian.dynamicgui.core.enchantment.EnchantmentWrapper;
public class EnchantmentBuilder {
private String enchantment;
- private int level;
+ private int level = 0;
public EnchantmentBuilder setEnchantment(String enchantment) {
this.enchantment = enchantment;
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/builder/FunctionBuilder.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/builder/FunctionBuilder.java
similarity index 75%
rename from core/src/main/java/com/clubobsidian/dynamicgui/builder/FunctionBuilder.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/builder/FunctionBuilder.java
index d2fd1c755..a620c5936 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/builder/FunctionBuilder.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/builder/FunctionBuilder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.builder;
+
+package com.clubobsidian.dynamicgui.core.builder;
import com.clubobsidian.dynamicgui.parser.function.FunctionData;
import com.clubobsidian.dynamicgui.parser.function.FunctionModifier;
@@ -39,18 +40,6 @@ public FunctionBuilder setModifier(FunctionModifier modifier) {
return this;
}
- public FunctionData create(String name, String data) {
- return this.create(name, data, FunctionModifier.NONE);
- }
-
-
- public FunctionData create(String name, String data, FunctionModifier modifier) {
- this.setName(name);
- this.setData(data);
- this.setModifier(modifier);
- return this.build();
- }
-
public FunctionData build() {
return new FunctionData(this.name, this.data, this.modifier);
}
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/builder/FunctionTokenBuilder.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/builder/FunctionTokenBuilder.java
similarity index 81%
rename from core/src/main/java/com/clubobsidian/dynamicgui/builder/FunctionTokenBuilder.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/builder/FunctionTokenBuilder.java
index 3a8405a82..5967316fa 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/builder/FunctionTokenBuilder.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/builder/FunctionTokenBuilder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.builder;
+
+package com.clubobsidian.dynamicgui.core.builder;
import com.clubobsidian.dynamicgui.parser.function.FunctionData;
import com.clubobsidian.dynamicgui.parser.function.FunctionModifier;
@@ -26,17 +27,10 @@
public class FunctionTokenBuilder {
- private final String name;
- private final List types;
- private final List functions;
- private final List failOnFunctions;
-
- public FunctionTokenBuilder() {
- this.name = UUID.randomUUID().toString();
- this.types = new ArrayList<>();
- this.functions = new ArrayList<>();
- this.failOnFunctions = new ArrayList<>();
- }
+ private final String name = UUID.randomUUID().toString();
+ private final List types = new ArrayList<>();
+ private final List functions = new ArrayList<>();
+ private final List failOnFunctions = new ArrayList<>();
public FunctionTokenBuilder addType(String type) {
FunctionType functionType = FunctionType.valueOf(type.toUpperCase());
@@ -45,7 +39,7 @@ public FunctionTokenBuilder addType(String type) {
}
public FunctionTokenBuilder addType(String... types) {
- for(String t : types) {
+ for (String t : types) {
this.addType(t);
}
return this;
@@ -65,7 +59,7 @@ public FunctionTokenBuilder addFunction(FunctionData data) {
}
public FunctionTokenBuilder addFunction(FunctionData... datas) {
- for(FunctionData data : datas) {
+ for (FunctionData data : datas) {
this.addFunction(data);
}
@@ -86,7 +80,7 @@ public FunctionTokenBuilder addFailOnFunction(FunctionData data) {
}
public FunctionTokenBuilder addFailOnFunction(FunctionData... datas) {
- for(FunctionData data : datas) {
+ for (FunctionData data : datas) {
this.addFunction(data);
}
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/builder/GuiBuilder.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/builder/GuiBuilder.java
similarity index 73%
rename from core/src/main/java/com/clubobsidian/dynamicgui/builder/GuiBuilder.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/builder/GuiBuilder.java
index 57e33a4d7..3c4bed1d8 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/builder/GuiBuilder.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/builder/GuiBuilder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,14 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.builder;
-import com.clubobsidian.dynamicgui.gui.Gui;
-import com.clubobsidian.dynamicgui.gui.ModeEnum;
-import com.clubobsidian.dynamicgui.gui.Slot;
-import com.clubobsidian.dynamicgui.manager.dynamicgui.GuiManager;
+package com.clubobsidian.dynamicgui.core.builder;
+
+import com.clubobsidian.dynamicgui.core.gui.Gui;
+import com.clubobsidian.dynamicgui.core.gui.ModeEnum;
+import com.clubobsidian.dynamicgui.core.gui.Slot;
+import com.clubobsidian.dynamicgui.core.manager.dynamicgui.GuiManager;
+import com.clubobsidian.dynamicgui.core.world.LocationWrapper;
import com.clubobsidian.dynamicgui.parser.function.tree.FunctionTree;
-import com.clubobsidian.dynamicgui.world.LocationWrapper;
import java.util.ArrayList;
import java.util.HashMap;
@@ -37,20 +38,13 @@ public class GuiBuilder {
private int rows;
private Boolean close;
private ModeEnum modeEnum;
- private final Map> npcIds;
- private final List slots;
- private final List> locs;
- private FunctionTree functionTree;
- private final Map metadata;
+ private final Map> npcIds = new HashMap<>();
+ private final List slots = new ArrayList<>();
+ private final List> locations = new ArrayList<>();
+ private FunctionTree functionTree = new FunctionTree();
+ private final Map metadata = new HashMap<>();
private Gui backGui;
-
- public GuiBuilder() {
- this.npcIds = new HashMap<>();
- this.slots = new ArrayList<>();
- this.locs = new ArrayList<>();
- this.functionTree = new FunctionTree();
- this.metadata = new HashMap<>();
- }
+ private boolean isStatic = false;
public GuiBuilder setType(String type) {
this.type = type.toUpperCase();
@@ -89,7 +83,7 @@ public GuiBuilder setModeEnum(ModeEnum modeEnum) {
public GuiBuilder addNpcId(String plugin, Integer id) {
List npcs = this.npcIds.get(plugin);
- if(npcs == null) {
+ if (npcs == null) {
npcs = new ArrayList<>();
this.npcIds.put(plugin, npcs);
}
@@ -99,14 +93,14 @@ public GuiBuilder addNpcId(String plugin, Integer id) {
}
public GuiBuilder addNpcId(String plugin, Integer[] npcIds) {
- for(Integer id : npcIds) {
+ for (Integer id : npcIds) {
this.addNpcId(plugin, id);
}
return this;
}
public GuiBuilder addNpcId(String plugin, List npcIds) {
- for(Integer id : npcIds) {
+ for (Integer id : npcIds) {
this.addNpcId(plugin, id);
}
return this;
@@ -118,7 +112,7 @@ public GuiBuilder addSlot(Slot slot) {
}
public GuiBuilder addLocation(LocationWrapper> loc) {
- this.locs.add(loc);
+ this.locations.add(loc);
return this;
}
@@ -133,7 +127,7 @@ public GuiBuilder setBack(Gui backGui) {
}
public GuiBuilder setBack(String backGuiName) {
- this.backGui = GuiManager.get().getGuiByName(backGuiName);
+ this.backGui = GuiManager.get().getGui(backGuiName);
return this;
}
@@ -144,7 +138,7 @@ public GuiBuilder addMetadata(String key, String value) {
public GuiBuilder addMetadata(Map metadata) {
Iterator> it = metadata.entrySet().iterator();
- while(it.hasNext()) {
+ while (it.hasNext()) {
Entry next = it.next();
String key = next.getKey();
String value = next.getValue();
@@ -154,9 +148,16 @@ public GuiBuilder addMetadata(Map metadata) {
return this;
}
+ public GuiBuilder setStatic(boolean isStatic) {
+ this.isStatic = isStatic;
+ return this;
+ }
+
public Gui build() {
- Gui gui = new Gui(this.name, this.type, this.title, this.rows, this.close, this.modeEnum, this.npcIds, this.slots, this.locs, this.functionTree, this.metadata);
- if(this.backGui != null) {
+ Gui gui = new Gui(this.name, this.type, this.title, this.rows,
+ this.close, this.modeEnum, this.npcIds, this.slots, this.locations,
+ this.functionTree, this.metadata, this.isStatic);
+ if (this.backGui != null) {
gui.setBack(this.backGui);
}
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/builder/SlotBuilder.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/builder/SlotBuilder.java
similarity index 80%
rename from core/src/main/java/com/clubobsidian/dynamicgui/builder/SlotBuilder.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/builder/SlotBuilder.java
index fddc14c1d..e0f13f197 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/builder/SlotBuilder.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/builder/SlotBuilder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.builder;
-import com.clubobsidian.dynamicgui.enchantment.EnchantmentWrapper;
-import com.clubobsidian.dynamicgui.gui.Slot;
-import com.clubobsidian.dynamicgui.inventory.ItemStackWrapper;
+package com.clubobsidian.dynamicgui.core.builder;
+
+import com.clubobsidian.dynamicgui.core.enchantment.EnchantmentWrapper;
+import com.clubobsidian.dynamicgui.core.gui.Slot;
+import com.clubobsidian.dynamicgui.core.inventory.ItemStackWrapper;
import com.clubobsidian.dynamicgui.parser.function.tree.FunctionTree;
import java.util.ArrayList;
@@ -36,27 +37,19 @@ public class SlotBuilder {
private String nbt;
private short data;
private boolean glow;
- private boolean moveable;
+ private boolean movable;
private Boolean close;
private List lore;
- private final List enchants;
- private final List itemFlags;
+ private final List enchants = new ArrayList<>();
+ private final List itemFlags = new ArrayList<>();
private String modelProvider;
private String modelData;
private int index;
- private int amount;
- private int updateInterval;
- private FunctionTree functionTree;
- private final Map metadata;
+ private int amount = 1;
+ private int updateInterval = 0;
+ private FunctionTree functionTree = new FunctionTree();
+ private final Map metadata = new HashMap<>();
- public SlotBuilder() {
- this.enchants = new ArrayList<>();
- this.itemFlags = new ArrayList<>();
- this.amount = 1;
- this.updateInterval = 0;
- this.functionTree = new FunctionTree();
- this.metadata = new HashMap<>();
- }
public SlotBuilder setIcon(String icon) {
this.icon = icon;
@@ -98,8 +91,8 @@ public SlotBuilder setModelData(String modelData) {
return this;
}
- public SlotBuilder setMoveable(boolean moveable) {
- this.moveable = moveable;
+ public SlotBuilder setMovable(boolean movable) {
+ this.movable = movable;
return this;
}
@@ -124,7 +117,7 @@ public SlotBuilder setUpdateInterval(int interval) {
}
public SlotBuilder addLore(String lore) {
- if(this.lore == null) {
+ if (this.lore == null) {
this.lore = new ArrayList();
this.lore.add(lore);
} else {
@@ -134,7 +127,7 @@ public SlotBuilder addLore(String lore) {
}
public SlotBuilder addLore(String... lore) {
- for(String l : lore) {
+ for (String l : lore) {
this.addLore(l);
}
@@ -142,7 +135,7 @@ public SlotBuilder addLore(String... lore) {
}
public SlotBuilder addLore(List lore) {
- for(String l : lore) {
+ for (String l : lore) {
this.addLore(l);
}
@@ -155,7 +148,7 @@ public SlotBuilder addEnchant(EnchantmentWrapper enchant) {
}
public SlotBuilder addEnchant(EnchantmentWrapper... enchant) {
- for(EnchantmentWrapper ench : enchant) {
+ for (EnchantmentWrapper ench : enchant) {
this.addEnchant(ench);
}
@@ -163,7 +156,7 @@ public SlotBuilder addEnchant(EnchantmentWrapper... enchant) {
}
public SlotBuilder addEnchant(List enchant) {
- for(EnchantmentWrapper ench : enchant) {
+ for (EnchantmentWrapper ench : enchant) {
this.addEnchant(ench);
}
@@ -192,7 +185,7 @@ public SlotBuilder addMetadata(String key, String value) {
public SlotBuilder addMetadata(Map metadata) {
Iterator> it = metadata.entrySet().iterator();
- while(it.hasNext()) {
+ while (it.hasNext()) {
Entry next = it.next();
String key = next.getKey();
String value = next.getValue();
@@ -210,7 +203,7 @@ public SlotBuilder fromItemStackWrapper(ItemStackWrapper> itemStackWrapper) {
this.setAmount(itemStackWrapper.getAmount());
this.addLore(itemStackWrapper.getLore());
- for(EnchantmentWrapper enchant : itemStackWrapper.getEnchants()) {
+ for (EnchantmentWrapper enchant : itemStackWrapper.getEnchants()) {
this.addEnchant(enchant);
}
@@ -219,7 +212,7 @@ public SlotBuilder fromItemStackWrapper(ItemStackWrapper> itemStackWrapper) {
public Slot build() {
return new Slot(this.index, this.amount, this.icon, this.name,
- this.nbt, this.data, this.glow, this.moveable,
+ this.nbt, this.data, this.glow, this.movable,
this.close, this.lore, this.enchants, this.itemFlags,
this.modelProvider, this.modelData, this.functionTree,
this.updateInterval, this.metadata);
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/command/CommandRegistrar.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/command/CommandRegistrar.java
new file mode 100644
index 000000000..db4a1cbbd
--- /dev/null
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/command/CommandRegistrar.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.core.command;
+
+public interface CommandRegistrar {
+
+ void registerCommand(Class extends RegisteredCommand> command);
+ void registerGuiCommand(String guiName, String alias);
+ void unregisterCommand(String alias);
+ void unregisterGuiAliases();
+
+}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/command/CommandRegistrarImpl.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/command/CommandRegistrarImpl.java
new file mode 100644
index 000000000..940fa7a6e
--- /dev/null
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/command/CommandRegistrarImpl.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.core.command;
+
+import cloud.commandframework.Command;
+import cloud.commandframework.CommandManager;
+import cloud.commandframework.annotations.AnnotationParser;
+import cloud.commandframework.meta.SimpleCommandMeta;
+import com.clubobsidian.dynamicgui.core.command.cloud.CloudExtender;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.logger.LoggerWrapper;
+import com.clubobsidian.dynamicgui.core.manager.dynamicgui.GuiManager;
+import com.google.inject.Injector;
+
+import javax.inject.Inject;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class CommandRegistrarImpl implements CommandRegistrar {
+
+ private final CommandManager commandManager;
+ private final CloudExtender extender;
+ private final LoggerWrapper> logger;
+ private final Injector injector;
+ private final AnnotationParser commandParser;
+
+ private final List registeredAliases = new ArrayList<>();
+ private final Map cloudCommands = new HashMap<>();
+
+ @Inject
+ private CommandRegistrarImpl(CommandManager commandManager,
+ CloudExtender extender,
+ LoggerWrapper> logger,
+ Injector injector) {
+ this.commandManager = commandManager;
+ this.extender = extender;
+ this.logger = logger;
+ this.injector = injector;
+ this.commandParser = new AnnotationParser<>(this.commandManager,
+ GuiCommandSender.class,
+ parserParameters -> SimpleCommandMeta.empty());
+ this.commandManager.setSetting(CommandManager.ManagerSettings.ALLOW_UNSAFE_REGISTRATION, true);
+ this.commandManager.setSetting(CommandManager.ManagerSettings.OVERRIDE_EXISTING_COMMANDS, true);
+ }
+
+ @Override
+ public void registerCommand(Class extends RegisteredCommand> command) {
+ this.commandParser.parse(this.injector.getInstance(command));
+ }
+
+ @Override
+ public void registerGuiCommand(String guiName, String alias) {
+ this.unregisterCommand(alias);
+ Command command = this.commandManager.commandBuilder(alias)
+ .handler(context -> {
+ PlayerWrapper> playerWrapper = context.getSender().getPlayer().get();
+ if(playerWrapper != null) {
+ GuiManager.get().openGui(playerWrapper, guiName);
+ }
+ }).build();
+ this.commandManager.command(command);
+ this.cloudCommands.put(alias, command);
+ this.registeredAliases.add(alias);
+ this.logger.info(String.format("Registered the command \"%s\" for the gui %s",
+ alias,
+ guiName
+ ));
+ }
+
+ @Override
+ public void unregisterCommand(String alias) {
+ try {
+ this.extender.unregister(this.commandManager, this.cloudCommands.get(alias), alias);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ this.cloudCommands.remove(alias);
+ this.registeredAliases.remove(alias);
+ }
+
+ @Override
+ public void unregisterGuiAliases() {
+ for (int i = 0; i < this.registeredAliases.size(); i++) {
+ String cmd = this.registeredAliases.get(i);
+ this.unregisterCommand(cmd);
+ i--;
+ }
+ }
+}
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/command/DynamicGuiCommand.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/command/DynamicGuiCommand.java
new file mode 100644
index 000000000..dd7ba35c3
--- /dev/null
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/command/DynamicGuiCommand.java
@@ -0,0 +1,122 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.core.command;
+
+import cloud.commandframework.annotations.Argument;
+import cloud.commandframework.annotations.CommandMethod;
+import cloud.commandframework.annotations.CommandPermission;
+import com.clubobsidian.dynamicgui.core.DynamicGui;
+import com.clubobsidian.dynamicgui.core.Constant;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.event.plugin.DynamicGuiReloadEvent;
+import com.clubobsidian.dynamicgui.core.gui.Gui;
+import com.clubobsidian.dynamicgui.core.manager.dynamicgui.GuiManager;
+import com.clubobsidian.dynamicgui.core.platform.Platform;
+import com.clubobsidian.dynamicgui.core.util.ChatColor;
+
+import javax.inject.Inject;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.stream.Collectors;
+
+public class DynamicGuiCommand implements RegisteredCommand {
+
+ private final Platform platform;
+
+ @Inject
+ private DynamicGuiCommand(Platform platform) {
+ this.platform = platform;
+ }
+
+ @CommandMethod("dynamicgui|dyngui reload")
+ @CommandPermission(Constant.DYNAMIC_GUI_COMMAND_RELOAD_PERMISSION)
+ private void reload(GuiCommandSender sender) {
+ sender.sendMessage("Guis have been reloaded");
+ GuiManager.get().reloadGuis(false);
+ DynamicGui.get().getEventBus().callEvent(new DynamicGuiReloadEvent());
+ }
+
+ @CommandMethod("dynamicgui|dyngui forcereload")
+ @CommandPermission(Constant.DYNAMIC_GUI_COMMAND_RELOAD_PERMISSION)
+ private void forceReload(GuiCommandSender sender) {
+ sender.sendMessage("Guis have been force reloaded");
+ GuiManager.get().reloadGuis(true);
+ DynamicGui.get().getEventBus().callEvent(new DynamicGuiReloadEvent());
+ }
+
+ @CommandMethod("dynamicgui|dyngui close all [guiName]")
+ @CommandPermission(Constant.DYNAMIC_GUI_COMMAND_CLOSE_PERMISSION)
+ private void closeAll(GuiCommandSender sender, @Argument("guiName") String guiName) {
+ if(guiName == null) {
+ sender.sendMessage("All open DynamicGui guis have been closed");
+ for (UUID uuid : GuiManager.get().getPlayerGuis().keySet()) {
+ PlayerWrapper> playerWrapper = this.platform.getPlayer(uuid);
+ if (playerWrapper != null) {
+ playerWrapper.closeInventory();
+ }
+ }
+ } else {
+ Gui gui = GuiManager.get().getGui(guiName);
+ if (gui == null) {
+ sender.sendMessage("No gui can be found by that name");
+ } else {
+ sender.sendMessage(String.format("Guis of type %s are now closed", guiName));
+ Iterator> it = GuiManager.get().getPlayerGuis().entrySet().iterator();
+ while (it.hasNext()) {
+ Map.Entry next = it.next();
+ UUID uuid = next.getKey();
+ PlayerWrapper> playerWrapper = this.platform.getPlayer(uuid);
+ if (playerWrapper != null) {
+ playerWrapper.closeInventory();
+ }
+ }
+ }
+ }
+ }
+
+ @CommandMethod("dynamicgui|dyngui close ")
+ @CommandPermission(Constant.DYNAMIC_GUI_COMMAND_CLOSE_PERMISSION)
+ private void closePlayer(GuiCommandSender sender, @Argument("playerName") String playerName) {
+ PlayerWrapper> player = this.platform.getPlayer(playerName);
+ if (player == null) {
+ sender.sendMessage("That player is not online, so their gui cannot be closed");
+ } else {
+ if (GuiManager.get().getPlayerGuis().get(player.getUniqueId()) != null) {
+ sender.sendMessage(String.format("%s's gui has been closed", playerName));
+ player.closeInventory();
+ } else {
+ sender.sendMessage(String.format("%s did not have a DynamicGui gui open", playerName));
+ }
+ }
+ }
+
+ @CommandMethod("dynamicgui|dyngui list")
+ @CommandPermission(Constant.DYNAMIC_GUI_LIST_PERMISSION)
+ private void guiList(GuiCommandSender sender) {
+ List guiNames = GuiManager
+ .get()
+ .getGuis()
+ .stream()
+ .map((gui) -> "&a" + gui.getName())
+ .collect(Collectors.toList());
+ String built = ChatColor.translateAlternateColorCodes(String.join(" &f," + guiNames));
+ sender.sendMessage(built);
+ }
+}
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/command/GuiCommand.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/command/GuiCommand.java
new file mode 100644
index 000000000..ddde342f6
--- /dev/null
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/command/GuiCommand.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.core.command;
+
+import cloud.commandframework.annotations.Argument;
+import cloud.commandframework.annotations.CommandMethod;
+import cloud.commandframework.annotations.CommandPermission;
+import com.clubobsidian.dynamicgui.core.Constant;
+import com.clubobsidian.dynamicgui.core.DynamicGui;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.manager.dynamicgui.GuiManager;
+
+public class GuiCommand implements RegisteredCommand {
+
+ @CommandMethod("gui ")
+ @CommandPermission(Constant.GUI_BASE_PERMISSION)
+ private void gui(GuiCommandSender sender, @Argument("guiName") String guiName) {
+ PlayerWrapper> player = sender.getPlayer().orElse(null);
+ if(player != null) {
+ boolean hasPermission = player.hasPermission(Constant.GUI_PERMISSION.apply(guiName));
+ if (hasPermission) {
+ GuiManager.get().openGui(player, guiName);
+ } else {
+ sender.sendMessage(DynamicGui.get().getMessage().getNoGuiPermission());
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/command/GuiCommandSender.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/command/GuiCommandSender.java
new file mode 100644
index 000000000..cdef8c075
--- /dev/null
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/command/GuiCommandSender.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.core.command;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.manager.entity.EntityManager;
+
+import java.util.Optional;
+
+public interface GuiCommandSender {
+
+ Object getNativeSender();
+
+ boolean isPlayer();
+
+ void sendMessage(String message);
+
+ default Optional> getPlayer() {
+ return this.isPlayer() ?
+ Optional.of(EntityManager
+ .get()
+ .createPlayerWrapper(this.getNativeSender())) : Optional.empty();
+ }
+}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/command/RegisteredCommand.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/command/RegisteredCommand.java
new file mode 100644
index 000000000..d79f49c52
--- /dev/null
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/command/RegisteredCommand.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.core.command;
+
+public interface RegisteredCommand {
+}
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/command/cloud/CloudArgument.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/command/cloud/CloudArgument.java
new file mode 100644
index 000000000..10e7dc729
--- /dev/null
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/command/cloud/CloudArgument.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.core.command.cloud;
+
+import cloud.commandframework.arguments.CommandArgument;
+import cloud.commandframework.arguments.standard.BooleanArgument;
+import cloud.commandframework.arguments.standard.ByteArgument;
+import cloud.commandframework.arguments.standard.CharArgument;
+import cloud.commandframework.arguments.standard.DoubleArgument;
+import cloud.commandframework.arguments.standard.FloatArgument;
+import cloud.commandframework.arguments.standard.IntegerArgument;
+import cloud.commandframework.arguments.standard.LongArgument;
+import cloud.commandframework.arguments.standard.ShortArgument;
+import cloud.commandframework.arguments.standard.StringArgument;
+import cloud.commandframework.arguments.standard.UUIDArgument;
+
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Optional;
+import java.util.function.Function;
+
+public enum CloudArgument {
+
+ //TODO - implement enum & string_array
+ BOOLEAN((Function) s -> (BooleanArgument) BooleanArgument.of(s)),
+ BYTE((Function) s -> (ByteArgument) ByteArgument.of(s)),
+ CHAR((Function) s -> (CharArgument) CharArgument.of(s)),
+ DOUBLE((Function) s -> (DoubleArgument) DoubleArgument.of(s)),
+ FLOAT((Function) s -> (FloatArgument) FloatArgument.of(s)),
+ INTEGER((Function) s -> (IntegerArgument) IntegerArgument.of(s)),
+ LONG((Function) s -> (LongArgument) LongArgument.of(s)),
+ SHORT((Function) s -> (ShortArgument) ShortArgument.of(s)),
+ STRING((Function) s -> (StringArgument) StringArgument.of(s)),
+ UUID((Function) s -> (UUIDArgument) UUIDArgument.of(s));
+
+ private static final Map types = new HashMap<>();
+
+ static {
+ for(CloudArgument arg : CloudArgument.values()) {
+ types.put(arg.name().toLowerCase(Locale.ROOT), arg);
+ }
+ }
+
+ public static Optional fromType(String type) {
+ type = type.toLowerCase(Locale.ROOT);
+ switch (type) {
+ case "text":
+ type = "string";
+ break;
+ case "number":
+ type = "integer";
+ break;
+ default:
+ break;
+ }
+ return Optional.ofNullable(types.get(type));
+ }
+
+ private final Function function;
+
+ CloudArgument(Function function) {
+ this.function = function;
+ }
+
+ public T argument(String arg) {
+ return (T) this.function.apply(arg);
+ }
+}
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/command/cloud/CloudExtender.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/command/cloud/CloudExtender.java
new file mode 100644
index 000000000..a52445f08
--- /dev/null
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/command/cloud/CloudExtender.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.core.command.cloud;
+
+import cloud.commandframework.Command;
+import cloud.commandframework.CommandManager;
+
+public interface CloudExtender {
+
+ boolean unregister(CommandManager commandManager, Command command, String commandName);
+}
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/command/cloud/extender/CombinedCloudExtender.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/command/cloud/extender/CombinedCloudExtender.java
new file mode 100644
index 000000000..c2599de4c
--- /dev/null
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/command/cloud/extender/CombinedCloudExtender.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.core.command.cloud.extender;
+
+import cloud.commandframework.Command;
+import cloud.commandframework.CommandManager;
+import com.clubobsidian.dynamicgui.core.Constant;
+import com.clubobsidian.dynamicgui.core.command.cloud.CloudExtender;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+public class CombinedCloudExtender implements CloudExtender {
+
+ private final CloudExtender nativeExtender;
+ private final CloudExtender platformExtender;
+
+ @Inject
+ private CombinedCloudExtender(@Named(Constant.NATIVE_ANNOTATION) CloudExtender nativeExtender,
+ @Named(Constant.PLATFORM_ANNOTATION) CloudExtender platformExtender) {
+ this.nativeExtender = nativeExtender;
+ this.platformExtender = platformExtender;
+ }
+
+ @Override
+ public boolean unregister(CommandManager commandManager, Command command, String commandName) {
+ boolean nativeUnregistered = this.nativeExtender.unregister(commandManager, command, commandName);
+ boolean platformUnregistered = this.platformExtender.unregister(commandManager, command, commandName);
+ return nativeUnregistered || platformUnregistered;
+ }
+}
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/command/cloud/extender/CoreCloudExtender.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/command/cloud/extender/CoreCloudExtender.java
new file mode 100644
index 000000000..55947bb0e
--- /dev/null
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/command/cloud/extender/CoreCloudExtender.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.core.command.cloud.extender;
+
+import cloud.commandframework.Command;
+import cloud.commandframework.CommandManager;
+import cloud.commandframework.CommandTree;
+import com.clubobsidian.dynamicgui.core.command.cloud.CloudExtender;
+
+import java.lang.reflect.Field;
+import java.util.List;
+
+public class CoreCloudExtender implements CloudExtender {
+
+ @Override
+ public boolean unregister(CommandManager commandManager, Command command, String commandName) {
+ if(command == null) {
+ return false;
+ }
+ boolean commandsUnregistered;
+ boolean treeUnregistered;
+ try {
+ commandsUnregistered = unregisterCommandsField(commandManager, command);
+ treeUnregistered = unregisterTree(commandManager, commandName);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return false;
+ }
+ return commandsUnregistered || treeUnregistered;
+ }
+
+ private boolean unregisterTree(CommandManager commandManager, String commandName) throws Exception {
+ CommandTree commandTree = commandManager.getCommandTree();
+ CommandTree.Node commandNode = commandTree.getNamedNode(commandName);
+ Field internalTreeField = commandTree.getClass().getDeclaredField("internalTree");
+ internalTreeField.setAccessible(true);
+ CommandTree.Node internalTree = (CommandTree.Node) internalTreeField.get(commandTree);
+ Field childrenField = CommandTree.Node.class.getDeclaredField("children");
+ childrenField.setAccessible(true);
+ List children = (List) childrenField.get(internalTree);
+ return children.remove(commandNode);
+ }
+
+ private boolean unregisterCommandsField(CommandManager commandManager, Command command) throws Exception {
+ Field commandsField = CommandManager.class.getDeclaredField("commands");
+ commandsField.setAccessible(true);
+ List commands = (List) commandsField.get(commandManager);
+ return commands.remove(command);
+ }
+}
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/config/ChatColorTransformer.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/config/ChatColorTransformer.java
new file mode 100644
index 000000000..5790f8b9b
--- /dev/null
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/config/ChatColorTransformer.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.core.config;
+
+import com.clubobsidian.dynamicgui.core.util.ChatColor;
+import com.clubobsidian.wrappy.transformer.NodeTransformer;
+
+public class ChatColorTransformer extends NodeTransformer {
+
+ public ChatColorTransformer() {
+ super(String.class);
+ }
+
+ @Override
+ public String transform(String transform) {
+ return ChatColor.translateAlternateColorCodes(transform);
+ }
+}
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/config/Message.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/config/Message.java
new file mode 100644
index 000000000..353c66819
--- /dev/null
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/config/Message.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.core.config;
+
+import com.clubobsidian.wrappy.inject.Node;
+
+public class Message {
+
+ @Node("no-gui")
+ private String noGui;
+ @Node("no-gui-permission")
+ private String noGuiPermission;
+
+ public String getNoGui() {
+ return this.noGui;
+ }
+
+ public String getNoGuiPermission() {
+ return this.noGuiPermission;
+ }
+}
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/economy/Economy.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/economy/Economy.java
similarity index 84%
rename from core/src/main/java/com/clubobsidian/dynamicgui/economy/Economy.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/economy/Economy.java
index 3ff3c792d..7274f195d 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/economy/Economy.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/economy/Economy.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,9 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.economy;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
+package com.clubobsidian.dynamicgui.core.economy;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
import java.math.BigDecimal;
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/effect/ParticleWrapper.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/effect/ParticleWrapper.java
new file mode 100644
index 000000000..4714ca1c9
--- /dev/null
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/effect/ParticleWrapper.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.core.effect;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import org.apache.commons.lang3.math.NumberUtils;
+
+import java.io.Serializable;
+import java.util.Objects;
+
+public class ParticleWrapper implements Serializable {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -5003322741003989392L;
+
+ private final ParticleData data;
+
+ public ParticleWrapper(String str) {
+ this(ParticleData.fromString(str));
+ }
+
+ public ParticleWrapper(ParticleData data) {
+ this.data = data;
+ }
+
+ public ParticleData getData() {
+ return this.data;
+ }
+
+ public void spawnEffect(PlayerWrapper> player) {
+ player.playEffect(this.data);
+ }
+
+ public static class ParticleData {
+
+ public static ParticleData fromString(String str) {
+ if (str.contains(",")) {
+ String[] args = str.split(",");
+ return new ParticleData(args[0].toUpperCase(), NumberUtils.toInt(args[1]));
+ }
+ return new ParticleData(str, 0);
+ }
+
+ private final String effect;
+ private final int extraData;
+
+ private ParticleData(String effect, int data) {
+ this.effect = effect;
+ this.extraData = data;
+ }
+
+ public String getEffect() {
+ return this.effect;
+ }
+
+ public int getExtraData() {
+ return this.extraData;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof ParticleData)) return false;
+ ParticleData that = (ParticleData) o;
+ return extraData == that.extraData && Objects.equals(effect, that.effect);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(effect, extraData);
+ }
+ }
+}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/effect/SoundWrapper.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/effect/SoundWrapper.java
new file mode 100644
index 000000000..7d461cd40
--- /dev/null
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/effect/SoundWrapper.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.core.effect;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+
+import java.io.Serializable;
+import java.util.Objects;
+
+public class SoundWrapper implements Serializable {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -8096584636206059158L;
+
+ public static final String TEST_SOUND_STRING = "ambient_cave,1.0,1.0";
+
+ private final SoundData data;
+
+ public SoundWrapper(String str) {
+ this(SoundData.fromString(str));
+ }
+
+ public SoundWrapper(SoundData data) {
+ this.data = data;
+ }
+
+ public SoundData getData() {
+ return this.data;
+ }
+
+ public void playSoundToPlayer(PlayerWrapper> player) {
+ player.playSound(this.data);
+ }
+
+ public static class SoundData {
+
+ public static SoundData fromString(String str) {
+ if (str.contains(",")) {
+ String[] args = str.split(",");
+ if (args.length == 3) {
+ try {
+ String sound = args[0];
+ float volume = Float.parseFloat(args[1]);
+ float pitch = Float.parseFloat(args[2]);
+ return new SoundData(sound, volume, pitch);
+ } catch (NumberFormatException ex) {
+ //Don't do anything if invalid format
+ }
+ }
+ }
+ return new SoundData(null, 0f, 0f);
+ }
+
+ private final String sound;
+ private final float volume;
+ private final float pitch;
+
+ private SoundData(String sound, float volume, float pitch) {
+ this.sound = sound;
+ this.volume = volume;
+ this.pitch = pitch;
+ }
+
+ public String getSound() {
+ return this.sound;
+ }
+
+ public float getVolume() {
+ return this.volume;
+ }
+
+ public float getPitch() {
+ return this.pitch;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof SoundData)) {
+ return false;
+ }
+ SoundData soundData = (SoundData) o;
+ return Float.compare(soundData.volume, this.volume) == 0
+ && Float.compare(soundData.pitch, this.pitch) == 0
+ && Objects.equals(this.sound, soundData.sound);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(this.sound, this.volume, this.pitch);
+ }
+ }
+}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/enchantment/EnchantmentWrapper.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/enchantment/EnchantmentWrapper.java
similarity index 78%
rename from core/src/main/java/com/clubobsidian/dynamicgui/enchantment/EnchantmentWrapper.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/enchantment/EnchantmentWrapper.java
index 9c73d0dd1..6922b4195 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/enchantment/EnchantmentWrapper.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/enchantment/EnchantmentWrapper.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.enchantment;
+
+package com.clubobsidian.dynamicgui.core.enchantment;
import java.io.Serializable;
@@ -23,6 +24,11 @@ public class EnchantmentWrapper implements Serializable {
*
*/
private static final long serialVersionUID = 1056076873542226033L;
+
+ public static final String TEST_ENCHANT_1 = "enchant_1";
+ public static final String TEST_ENCHANT_2 = "enchant_2";
+ public static final String TEST_ENCHANT_3 = "enchant_3";
+
private final String enchant;
private final int level;
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/entity/EntityWrapper.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/entity/EntityWrapper.java
similarity index 88%
rename from core/src/main/java/com/clubobsidian/dynamicgui/entity/EntityWrapper.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/entity/EntityWrapper.java
index 1ea354be6..9ed771cd5 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/entity/EntityWrapper.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/entity/EntityWrapper.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.entity;
+
+package com.clubobsidian.dynamicgui.core.entity;
public abstract class EntityWrapper {
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/entity/PlayerWrapper.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/entity/PlayerWrapper.java
similarity index 67%
rename from core/src/main/java/com/clubobsidian/dynamicgui/entity/PlayerWrapper.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/entity/PlayerWrapper.java
index c1fb46320..e1bddbdd0 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/entity/PlayerWrapper.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/entity/PlayerWrapper.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,13 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.entity;
-import com.clubobsidian.dynamicgui.inventory.InventoryWrapper;
-import com.clubobsidian.dynamicgui.inventory.ItemStackWrapper;
-import com.clubobsidian.dynamicgui.plugin.DynamicGuiPlugin;
-import com.clubobsidian.dynamicgui.util.Statistic;
-import com.clubobsidian.dynamicgui.world.LocationWrapper;
+package com.clubobsidian.dynamicgui.core.entity;
+
+import com.clubobsidian.dynamicgui.core.effect.ParticleWrapper;
+import com.clubobsidian.dynamicgui.core.effect.SoundWrapper;
+import com.clubobsidian.dynamicgui.core.inventory.InventoryWrapper;
+import com.clubobsidian.dynamicgui.core.inventory.ItemStackWrapper;
+import com.clubobsidian.dynamicgui.core.plugin.DynamicGuiPlugin;
+import com.clubobsidian.dynamicgui.core.world.LocationWrapper;
import java.util.UUID;
@@ -65,18 +67,19 @@ public T getPlayer() {
public abstract void openInventory(InventoryWrapper> inventoryWrapper);
- public abstract void sendPluginMessage(DynamicGuiPlugin plugin, String channel, byte[] message);
-
- public abstract void playSound(String sound, Float volume, Float pitch);
-
- public abstract void playEffect(String effect, int data);
+ public abstract void sendPluginMessage(String channel, byte[] message);
- public abstract int getStatistic(Statistic statistic);
+ public abstract void playSound(SoundWrapper.SoundData soundData);
- public abstract int getStatistic(Statistic statistic, String data);
+ public abstract void playEffect(ParticleWrapper.ParticleData particleData);
public abstract void updateInventory();
public abstract LocationWrapper> getLocation();
+ public abstract boolean isOnline();
+
+ public abstract String getSkinTexture();
+
+ public abstract void updateCursor();
}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/event/InventoryEvent.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/event/InventoryEvent.java
similarity index 81%
rename from core/src/main/java/com/clubobsidian/dynamicgui/event/InventoryEvent.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/event/InventoryEvent.java
index 94d2969b5..07df0a3ea 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/event/InventoryEvent.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/event/InventoryEvent.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,10 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.event;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.inventory.InventoryWrapper;
+package com.clubobsidian.dynamicgui.core.event;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.inventory.InventoryWrapper;
public class InventoryEvent extends PlayerEvent {
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/event/LocationEvent.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/event/LocationEvent.java
similarity index 81%
rename from core/src/main/java/com/clubobsidian/dynamicgui/event/LocationEvent.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/event/LocationEvent.java
index 7d330e88f..e5272d00d 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/event/LocationEvent.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/event/LocationEvent.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,10 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.event;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.world.LocationWrapper;
+package com.clubobsidian.dynamicgui.core.event;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.world.LocationWrapper;
public class LocationEvent extends PlayerEvent {
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/event/PlayerEvent.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/event/PlayerEvent.java
similarity index 85%
rename from core/src/main/java/com/clubobsidian/dynamicgui/event/PlayerEvent.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/event/PlayerEvent.java
index 293d44e24..ad6d32fd0 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/event/PlayerEvent.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/event/PlayerEvent.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,9 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.event;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
+package com.clubobsidian.dynamicgui.core.event;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
import com.clubobsidian.trident.Event;
public class PlayerEvent extends Event {
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/event/block/PlayerInteractEvent.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/event/block/PlayerInteractEvent.java
similarity index 64%
rename from core/src/main/java/com/clubobsidian/dynamicgui/event/block/PlayerInteractEvent.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/event/block/PlayerInteractEvent.java
index e5c00c2e5..7d3d15493 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/event/block/PlayerInteractEvent.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/event/block/PlayerInteractEvent.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,40 +13,31 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.event.block;
+package com.clubobsidian.dynamicgui.core.event.block;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.event.LocationEvent;
-import com.clubobsidian.dynamicgui.event.player.Action;
-import com.clubobsidian.dynamicgui.world.LocationWrapper;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.event.LocationEvent;
+import com.clubobsidian.dynamicgui.core.event.player.PlayerAction;
+import com.clubobsidian.dynamicgui.core.world.LocationWrapper;
import com.clubobsidian.trident.Cancellable;
public class PlayerInteractEvent extends LocationEvent implements Cancellable {
- private final Action action;
+ private final PlayerAction action;
private boolean canceled;
- public PlayerInteractEvent(PlayerWrapper> playerWrapper, LocationWrapper> locationWrapper, Action action) {
+ public PlayerInteractEvent(PlayerWrapper> playerWrapper, LocationWrapper> locationWrapper, PlayerAction action) {
super(playerWrapper, locationWrapper);
this.action = action;
this.canceled = false;
}
- public Action getAction() {
+ public PlayerAction getAction() {
return this.action;
}
- @Deprecated
- public boolean isCanceled() {
- return this.canceled;
- }
-
- @Deprecated
- public void setCanceled(boolean cancel) {
- this.canceled = cancel;
- }
-
@Override
public boolean isCancelled() {
return this.canceled;
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/event/inventory/Click.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/event/inventory/Click.java
similarity index 85%
rename from core/src/main/java/com/clubobsidian/dynamicgui/event/inventory/Click.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/event/inventory/Click.java
index 8aa7d4eb1..507c08479 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/event/inventory/Click.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/event/inventory/Click.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.event.inventory;
+
+package com.clubobsidian.dynamicgui.core.event.inventory;
public enum Click {
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/event/inventory/GuiLoadEvent.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/event/inventory/GuiLoadEvent.java
similarity index 77%
rename from core/src/main/java/com/clubobsidian/dynamicgui/event/inventory/GuiLoadEvent.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/event/inventory/GuiLoadEvent.java
index bf1f25901..6bfe545ba 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/event/inventory/GuiLoadEvent.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/event/inventory/GuiLoadEvent.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.event.inventory;
+package com.clubobsidian.dynamicgui.core.event.inventory;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.gui.Gui;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.gui.Gui;
import com.clubobsidian.trident.Cancellable;
import com.clubobsidian.trident.Event;
@@ -41,16 +42,6 @@ public PlayerWrapper> getPlayerWrapper() {
return this.playerWrapper;
}
- @Deprecated
- public boolean isCanceled() {
- return this.cancelled;
- }
-
- @Deprecated
- public void setCanceled(boolean cancelled) {
- this.cancelled = cancelled;
- }
-
@Override
public boolean isCancelled() {
return this.cancelled;
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/event/inventory/GuiPreloadEvent.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/event/inventory/GuiPreloadEvent.java
similarity index 82%
rename from core/src/main/java/com/clubobsidian/dynamicgui/event/inventory/GuiPreloadEvent.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/event/inventory/GuiPreloadEvent.java
index 193485617..8bfa5f41d 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/event/inventory/GuiPreloadEvent.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/event/inventory/GuiPreloadEvent.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.event.inventory;
+package com.clubobsidian.dynamicgui.core.event.inventory;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.gui.Gui;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.gui.Gui;
import com.clubobsidian.trident.Event;
public class GuiPreloadEvent extends Event {
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/event/inventory/GuiSwitchEvent.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/event/inventory/GuiSwitchEvent.java
new file mode 100644
index 000000000..8b0a66833
--- /dev/null
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/event/inventory/GuiSwitchEvent.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.core.event.inventory;
+
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.gui.Gui;
+import com.clubobsidian.trident.Event;
+
+public class GuiSwitchEvent extends Event {
+
+ private final Gui switchFrom;
+ private final Gui switchTo;
+ private final PlayerWrapper> playerWrapper;
+
+ public GuiSwitchEvent(Gui switchFrom, Gui switchTo, PlayerWrapper> playerWrapper) {
+ this.switchFrom = switchFrom;
+ this.switchTo = switchTo;
+ this.playerWrapper = playerWrapper;
+ }
+
+ public Gui gui() {
+ return this.switchFrom;
+ }
+
+ public PlayerWrapper> getPlayerWrapper() {
+ return this.playerWrapper;
+ }
+
+ public Gui getSwitchFrom() {
+ return this.switchFrom;
+ }
+
+ public Gui getSwitchTo() {
+ return this.switchTo;
+ }
+}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/event/inventory/InventoryClickEvent.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/event/inventory/InventoryClickEvent.java
similarity index 74%
rename from core/src/main/java/com/clubobsidian/dynamicgui/event/inventory/InventoryClickEvent.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/event/inventory/InventoryClickEvent.java
index bf6872fd5..b0a377f53 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/event/inventory/InventoryClickEvent.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/event/inventory/InventoryClickEvent.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,14 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.event.inventory;
+package com.clubobsidian.dynamicgui.core.event.inventory;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.event.InventoryEvent;
-import com.clubobsidian.dynamicgui.gui.InventoryView;
-import com.clubobsidian.dynamicgui.inventory.InventoryWrapper;
-import com.clubobsidian.dynamicgui.inventory.ItemStackWrapper;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.event.InventoryEvent;
+import com.clubobsidian.dynamicgui.core.gui.InventoryView;
+import com.clubobsidian.dynamicgui.core.inventory.InventoryWrapper;
+import com.clubobsidian.dynamicgui.core.inventory.ItemStackWrapper;
import com.clubobsidian.trident.Cancellable;
public class InventoryClickEvent extends InventoryEvent implements Cancellable {
@@ -55,16 +56,6 @@ public Click getClick() {
return this.click;
}
- @Deprecated
- public boolean isCanceled() {
- return this.cancelled;
- }
-
- @Deprecated
- public void setCanceled(boolean cancelled) {
- this.cancelled = cancelled;
- }
-
@Override
public boolean isCancelled() {
return this.cancelled;
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/event/inventory/InventoryCloseEvent.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/event/inventory/InventoryCloseEvent.java
similarity index 72%
rename from core/src/main/java/com/clubobsidian/dynamicgui/event/inventory/InventoryCloseEvent.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/event/inventory/InventoryCloseEvent.java
index 0c9e72613..8107074ac 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/event/inventory/InventoryCloseEvent.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/event/inventory/InventoryCloseEvent.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.event.inventory;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.event.InventoryEvent;
-import com.clubobsidian.dynamicgui.inventory.InventoryWrapper;
+package com.clubobsidian.dynamicgui.core.event.inventory;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.event.InventoryEvent;
+import com.clubobsidian.dynamicgui.core.inventory.InventoryWrapper;
public class InventoryCloseEvent extends InventoryEvent {
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/event/inventory/InventoryDragEvent.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/event/inventory/InventoryDragEvent.java
similarity index 72%
rename from core/src/main/java/com/clubobsidian/dynamicgui/event/inventory/InventoryDragEvent.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/event/inventory/InventoryDragEvent.java
index 622e148df..368cc31b7 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/event/inventory/InventoryDragEvent.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/event/inventory/InventoryDragEvent.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,12 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.event.inventory;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.event.InventoryEvent;
-import com.clubobsidian.dynamicgui.inventory.InventoryWrapper;
-import com.clubobsidian.dynamicgui.inventory.ItemStackWrapper;
+package com.clubobsidian.dynamicgui.core.event.inventory;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.event.InventoryEvent;
+import com.clubobsidian.dynamicgui.core.inventory.InventoryWrapper;
+import com.clubobsidian.dynamicgui.core.inventory.ItemStackWrapper;
import com.clubobsidian.trident.Cancellable;
import java.util.Map;
@@ -38,16 +39,6 @@ public Map> getSlotItems() {
return this.slotItems;
}
- @Deprecated
- public boolean isCanceled() {
- return this.cancelled;
- }
-
- @Deprecated
- public void setCanceled(boolean cancel) {
- this.cancelled = cancel;
- }
-
@Override
public boolean isCancelled() {
return this.cancelled;
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/event/inventory/InventoryOpenEvent.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/event/inventory/InventoryOpenEvent.java
similarity index 72%
rename from core/src/main/java/com/clubobsidian/dynamicgui/event/inventory/InventoryOpenEvent.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/event/inventory/InventoryOpenEvent.java
index ddb69ca8f..ce0ce8a9a 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/event/inventory/InventoryOpenEvent.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/event/inventory/InventoryOpenEvent.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.event.inventory;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.event.InventoryEvent;
-import com.clubobsidian.dynamicgui.inventory.InventoryWrapper;
+package com.clubobsidian.dynamicgui.core.event.inventory;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.event.InventoryEvent;
+import com.clubobsidian.dynamicgui.core.inventory.InventoryWrapper;
public class InventoryOpenEvent extends InventoryEvent {
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/event/inventory/PlayerInteractEntityEvent.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/event/inventory/PlayerInteractEntityEvent.java
similarity index 76%
rename from core/src/main/java/com/clubobsidian/dynamicgui/event/inventory/PlayerInteractEntityEvent.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/event/inventory/PlayerInteractEntityEvent.java
index 15a5a7110..b48001c96 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/event/inventory/PlayerInteractEntityEvent.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/event/inventory/PlayerInteractEntityEvent.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.event.inventory;
-import com.clubobsidian.dynamicgui.entity.EntityWrapper;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.event.PlayerEvent;
+package com.clubobsidian.dynamicgui.core.event.inventory;
+
+import com.clubobsidian.dynamicgui.core.entity.EntityWrapper;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.event.PlayerEvent;
public class PlayerInteractEntityEvent extends PlayerEvent {
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/event/player/Action.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/event/player/PlayerAction.java
similarity index 70%
rename from core/src/main/java/com/clubobsidian/dynamicgui/event/player/Action.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/event/player/PlayerAction.java
index d6f54a420..2d6071acd 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/event/player/Action.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/event/player/PlayerAction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,14 +13,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.event.player;
-public enum Action {
+package com.clubobsidian.dynamicgui.core.event.player;
+
+public enum PlayerAction {
LEFT_CLICK_AIR,
LEFT_CLICK_BLOCK,
RIGHT_CLICK_AIR,
RIGHT_CLICK_BLOCK,
- PHYSICAL
+ PHYSICAL;
+ public boolean isBlockClick() {
+ return this == PlayerAction.RIGHT_CLICK_BLOCK || this == PlayerAction.LEFT_CLICK_BLOCK;
+ }
}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/event/player/PlayerKickEvent.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/event/player/PlayerKickEvent.java
similarity index 76%
rename from core/src/main/java/com/clubobsidian/dynamicgui/event/player/PlayerKickEvent.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/event/player/PlayerKickEvent.java
index 0a7af3426..ebfff7b0e 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/event/player/PlayerKickEvent.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/event/player/PlayerKickEvent.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,10 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.event.player;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.event.PlayerEvent;
+package com.clubobsidian.dynamicgui.core.event.player;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.event.PlayerEvent;
public class PlayerKickEvent extends PlayerEvent {
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/event/player/PlayerQuitEvent.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/event/player/PlayerQuitEvent.java
similarity index 76%
rename from core/src/main/java/com/clubobsidian/dynamicgui/event/player/PlayerQuitEvent.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/event/player/PlayerQuitEvent.java
index 2b3aad7ce..8a5af8db3 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/event/player/PlayerQuitEvent.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/event/player/PlayerQuitEvent.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,10 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.event.player;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.event.PlayerEvent;
+package com.clubobsidian.dynamicgui.core.event.player;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.event.PlayerEvent;
public class PlayerQuitEvent extends PlayerEvent {
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/event/DynamicGuiReloadEvent.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/event/plugin/DynamicGuiReloadEvent.java
similarity index 86%
rename from core/src/main/java/com/clubobsidian/dynamicgui/event/DynamicGuiReloadEvent.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/event/plugin/DynamicGuiReloadEvent.java
index c9cf2e402..f26d15af1 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/event/DynamicGuiReloadEvent.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/event/plugin/DynamicGuiReloadEvent.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.event;
+
+package com.clubobsidian.dynamicgui.core.event.plugin;
import com.clubobsidian.trident.Event;
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/function/Function.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/Function.java
new file mode 100644
index 000000000..c0176a0fc
--- /dev/null
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/Function.java
@@ -0,0 +1,131 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.core.function;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.gui.FunctionOwner;
+import com.clubobsidian.fuzzutil.StringFuzz;
+import org.apache.commons.lang3.SerializationUtils;
+
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Objects;
+import java.util.Set;
+
+public abstract class Function implements Cloneable, Serializable {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1492427006104061443L;
+
+ private static Set loadAliases(String name, Collection aliases) {
+ Set aliasSet = new HashSet<>();
+ aliasSet.add(name);
+ for (String alias : aliases) {
+ aliasSet.add(StringFuzz.normalize(alias));
+ }
+ return Collections.unmodifiableSet(aliasSet);
+ }
+
+ private final String name;
+ private String data;
+ private final boolean async;
+ private FunctionOwner owner;
+ private final Set aliases;
+ private int index = -1;
+
+ public Function(String name, String[] aliases, boolean async) {
+ this(name, Arrays.asList(aliases), async);
+ }
+
+ public Function(String name, Collection aliases, boolean async) {
+ this.name = StringFuzz.normalize(name);
+ this.aliases = loadAliases(this.name, aliases);
+ this.async = async;
+ }
+
+ public Function(String name, boolean async) {
+ this(name, new String[0], async);
+ }
+
+ public Function(String... aliases) {
+ this(aliases[0], aliases, false);
+ }
+
+ public abstract boolean function(PlayerWrapper> playerWrapper) throws Exception;
+
+ public boolean isAsync() {
+ return this.async;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public Set getAliases() {
+ return this.aliases;
+ }
+
+ public String getData() {
+ return this.data;
+ }
+
+ public void setData(String data) {
+ this.data = data;
+ }
+
+ public boolean setOwner(FunctionOwner owner) {
+ if (this.owner != null) {
+ return false;
+ }
+ this.owner = owner;
+ return true;
+ }
+
+ public FunctionOwner getOwner() {
+ return this.owner;
+ }
+
+ public void setIndex(int index) {
+ this.index = index;
+ }
+
+ public int getIndex() {
+ return this.index;
+ }
+
+ public Function clone() {
+ return SerializationUtils.clone(this);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof Function)) return false;
+ Function function = (Function) o;
+ return async == function.async && name.equals(function.name) && aliases.equals(function.aliases);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(name, async, aliases);
+ }
+}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/AddPermissionFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/AddPermissionFunction.java
similarity index 70%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/AddPermissionFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/AddPermissionFunction.java
index c2352c31b..4fcfce1d2 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/AddPermissionFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/AddPermissionFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,10 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
+package com.clubobsidian.dynamicgui.core.function.impl;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
public class AddPermissionFunction extends Function {
@@ -25,12 +26,15 @@ public class AddPermissionFunction extends Function {
*/
private static final long serialVersionUID = 6578996849784218130L;
- public AddPermissionFunction(String name) {
- super(name);
+ public AddPermissionFunction() {
+ super("addpermission");
}
@Override
public boolean function(final PlayerWrapper> playerWrapper) {
+ if (this.getData() == null) {
+ return false;
+ }
return playerWrapper.addPermission(this.getData());
}
}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/AsyncRunningFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/AsyncRunningFunction.java
new file mode 100644
index 000000000..f6b177084
--- /dev/null
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/AsyncRunningFunction.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.core.function.impl;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import com.clubobsidian.dynamicgui.core.manager.dynamicgui.FunctionManager;
+
+public class AsyncRunningFunction extends Function {
+
+ public AsyncRunningFunction() {
+ super("asyncrunning");
+ }
+
+ @Override
+ public boolean function(PlayerWrapper> playerWrapper) {
+ if(this.getData() == null) {
+ return FunctionManager.get().hasAsyncFunctionRunning(playerWrapper);
+ }
+ return FunctionManager.get().hasAsyncFunctionRunning(playerWrapper, this.getData());
+ }
+}
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/CheckItemTypeInHandFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/CheckItemTypeInHandFunction.java
similarity index 70%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/CheckItemTypeInHandFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/CheckItemTypeInHandFunction.java
index 0532fac3a..345bf5c38 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/CheckItemTypeInHandFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/CheckItemTypeInHandFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
-import com.clubobsidian.dynamicgui.inventory.ItemStackWrapper;
+package com.clubobsidian.dynamicgui.core.function.impl;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import com.clubobsidian.dynamicgui.core.inventory.ItemStackWrapper;
import java.util.ArrayList;
import java.util.Arrays;
@@ -30,21 +31,24 @@ public class CheckItemTypeInHandFunction extends Function {
*/
private static final long serialVersionUID = -2308186311331769892L;
- public CheckItemTypeInHandFunction(String name) {
- super(name);
+ public CheckItemTypeInHandFunction() {
+ super("checkitemtypeinhand");
}
@Override
public boolean function(PlayerWrapper> playerWrapper) {
+ if (this.getData() == null) {
+ return false;
+ }
List types = new ArrayList<>();
types.add(this.getData());
- if(this.getData().contains(",")) {
+ if (this.getData().contains(",")) {
types = Arrays.asList(this.getData().split(","));
}
//Uppercase
- for(int i = 0; i < types.size(); i++) {
+ for (int i = 0; i < types.size(); i++) {
types.set(i, types.get(i).toUpperCase());
}
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/CheckLevelFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/CheckLevelFunction.java
similarity index 63%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/CheckLevelFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/CheckLevelFunction.java
index 653506023..6ad2bef34 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/CheckLevelFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/CheckLevelFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,10 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
+package com.clubobsidian.dynamicgui.core.function.impl;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
public class CheckLevelFunction extends Function {
@@ -25,20 +26,21 @@ public class CheckLevelFunction extends Function {
*/
private static final long serialVersionUID = 4927665292013293816L;
- public CheckLevelFunction(String name) {
- super(name);
+ public CheckLevelFunction() {
+ super("checklevel");
}
@Override
public boolean function(PlayerWrapper> playerWrapper) {
- int level = -1;
+ if (this.getData() == null) {
+ return false;
+ }
try {
- level = Integer.parseInt(this.getData());
- } catch(NumberFormatException ex) {
+ int level = Integer.parseInt(this.getData());
+ return playerWrapper.getLevel() >= level;
+ } catch (NumberFormatException ex) {
ex.printStackTrace();
return false;
}
-
- return playerWrapper.getLevel() >= level;
}
}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/CheckMoveableFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/CheckMovableFunction.java
similarity index 61%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/CheckMoveableFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/CheckMovableFunction.java
index 527d06486..931945b87 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/CheckMoveableFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/CheckMovableFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,41 +14,37 @@
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl;
+package com.clubobsidian.dynamicgui.core.function.impl;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
-import com.clubobsidian.dynamicgui.gui.FunctionOwner;
-import com.clubobsidian.dynamicgui.gui.Slot;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import com.clubobsidian.dynamicgui.core.gui.FunctionOwner;
+import com.clubobsidian.dynamicgui.core.gui.Slot;
-public class CheckMoveableFunction extends Function {
+public class CheckMovableFunction extends Function {
/**
*
*/
private static final long serialVersionUID = 1037806025228025407L;
- public CheckMoveableFunction(String name) {
- super(name);
+ public CheckMovableFunction() {
+ super("checkmovable");
}
@Override
public boolean function(PlayerWrapper> playerWrapper) {
- if(this.getData() == null) {
+ if (this.getData() == null) {
return false;
}
FunctionOwner owner = this.getOwner();
- if(!(owner instanceof Slot)) {
+ if (!(owner instanceof Slot)) {
return false;
}
Slot slot = (Slot) owner;
Boolean value = Boolean.valueOf(this.getData());
- if(value == null) {
- return false;
- }
-
- return value.equals(slot.isMoveable());
+ return value.equals(slot.isMovable());
}
}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/CheckPlayerWorldFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/CheckPlayerWorldFunction.java
similarity index 72%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/CheckPlayerWorldFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/CheckPlayerWorldFunction.java
index fb13cd3e4..42b6dcacd 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/CheckPlayerWorldFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/CheckPlayerWorldFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
-import com.clubobsidian.dynamicgui.world.WorldWrapper;
+package com.clubobsidian.dynamicgui.core.function.impl;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import com.clubobsidian.dynamicgui.core.world.WorldWrapper;
public class CheckPlayerWorldFunction extends Function {
@@ -26,16 +27,15 @@ public class CheckPlayerWorldFunction extends Function {
*/
private static final long serialVersionUID = -7760274986999938696L;
- public CheckPlayerWorldFunction(String name) {
- super(name);
+ public CheckPlayerWorldFunction() {
+ super("checkplayerworld");
}
@Override
public boolean function(PlayerWrapper> playerWrapper) {
- if(this.getData() == null) {
+ if (this.getData() == null) {
return false;
}
-
String worldName = this.getData();
WorldWrapper> worldWrapper = playerWrapper.getLocation().getWorld();
return worldName.equals(worldWrapper.getName());
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/ConsoleCmdFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/ConsoleCommandFunction.java
similarity index 54%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/ConsoleCmdFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/ConsoleCommandFunction.java
index 8e305bc63..492a22a2b 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/ConsoleCmdFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/ConsoleCommandFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,27 +13,31 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl;
-import com.clubobsidian.dynamicgui.DynamicGui;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
-import com.clubobsidian.dynamicgui.manager.dynamicgui.ReplacerManager;
+package com.clubobsidian.dynamicgui.core.function.impl;
-public class ConsoleCmdFunction extends Function {
+import com.clubobsidian.dynamicgui.core.DynamicGui;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import com.clubobsidian.dynamicgui.core.manager.dynamicgui.ReplacerManager;
+
+public class ConsoleCommandFunction extends Function {
/**
*
*/
private static final long serialVersionUID = -4802600274176592465L;
- public ConsoleCmdFunction(String name) {
- super(name);
+ public ConsoleCommandFunction() {
+ super("executec");
}
@Override
public boolean function(final PlayerWrapper> playerWrapper) {
- DynamicGui.get().getServer().dispatchServerCommand(ReplacerManager.get().replace(this.getData(), playerWrapper));
+ if (this.getData() == null) {
+ return false;
+ }
+ DynamicGui.get().getPlatform().dispatchServerCommand(ReplacerManager.get().replace(this.getData(), playerWrapper));
return true;
}
}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/DelayFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/DelayFunction.java
new file mode 100644
index 000000000..9d0cdae0c
--- /dev/null
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/DelayFunction.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.core.function.impl;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import org.apache.commons.lang3.math.NumberUtils;
+
+public class DelayFunction extends Function {
+
+ public DelayFunction() {
+ super("delay", true);
+ }
+
+ @Override
+ public boolean function(PlayerWrapper> playerWrapper) {
+ if (this.getData() == null || !NumberUtils.isParsable(this.getData())) {
+ return false;
+ }
+ try {
+ Thread.sleep(Integer.parseInt(this.getData()));
+ return true;
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+}
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/GetGameRuleFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/GetGameRuleFunction.java
similarity index 65%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/GetGameRuleFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/GetGameRuleFunction.java
index a1f9cc36f..324a818b5 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/GetGameRuleFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/GetGameRuleFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,12 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl;
-import com.clubobsidian.dynamicgui.DynamicGui;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
-import com.clubobsidian.dynamicgui.world.WorldWrapper;
+package com.clubobsidian.dynamicgui.core.function.impl;
+
+import com.clubobsidian.dynamicgui.core.DynamicGui;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import com.clubobsidian.dynamicgui.core.world.WorldWrapper;
public class GetGameRuleFunction extends Function {
@@ -28,32 +29,27 @@ public class GetGameRuleFunction extends Function {
*/
private static final long serialVersionUID = -5840073572003297982L;
- public GetGameRuleFunction(String name) {
- super(name);
+ public GetGameRuleFunction() {
+ super("getgamerule");
}
@Override
public boolean function(PlayerWrapper> playerWrapper) {
- if(this.getData() == null) {
- return false;
- } else if(!this.getData().contains(",")) {
+ if (this.getData() == null || !this.getData().contains(",")) {
return false;
}
-
String[] split = this.getData().split(",");
- if(split.length == 3) {
+ if (split.length == 3) {
String worldName = split[0];
- WorldWrapper> world = DynamicGui.get().getServer().getWorld(worldName);
- if(world == null) {
+ WorldWrapper> world = DynamicGui.get().getPlatform().getWorld(worldName);
+ if (world == null) {
return false;
}
-
String rule = split[1];
String value = split[2];
String worldRule = world.getGameRule(rule);
return value.equals(worldRule);
}
-
return false;
}
}
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/IsBedrockPlayerFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/IsBedrockPlayerFunction.java
similarity index 74%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/IsBedrockPlayerFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/IsBedrockPlayerFunction.java
index b98acf2a2..865a12cb0 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/IsBedrockPlayerFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/IsBedrockPlayerFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,18 +13,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
+package com.clubobsidian.dynamicgui.core.function.impl;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
public class IsBedrockPlayerFunction extends Function {
private static final long serialVersionUID = -2186429958998223776L;
- public IsBedrockPlayerFunction(String name) {
- super(name);
+ public IsBedrockPlayerFunction() {
+ super("isbedrockplayer");
}
@Override
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/LogFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/LogFunction.java
similarity index 68%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/LogFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/LogFunction.java
index b96aa8678..cdc7a67ed 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/LogFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/LogFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl;
-import com.clubobsidian.dynamicgui.DynamicGui;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
+package com.clubobsidian.dynamicgui.core.function.impl;
+
+import com.clubobsidian.dynamicgui.core.DynamicGui;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
public class LogFunction extends Function {
@@ -26,12 +27,15 @@ public class LogFunction extends Function {
*/
private static final long serialVersionUID = 848178368629667482L;
- public LogFunction(String name) {
- super(name);
+ public LogFunction() {
+ super("log", "logger");
}
@Override
public boolean function(final PlayerWrapper> playerWrapper) {
+ if (this.getData() == null) {
+ return false;
+ }
DynamicGui.get().getLogger().info(this.getData());
return true;
}
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/LoggedInFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/LoggedInFunction.java
new file mode 100644
index 000000000..b0b9b93c7
--- /dev/null
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/LoggedInFunction.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.core.function.impl;
+
+import com.clubobsidian.dynamicgui.core.DynamicGui;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+
+import java.util.UUID;
+
+public class LoggedInFunction extends Function {
+
+ public LoggedInFunction() {
+ super("loggedin");
+ }
+
+ @Override
+ public boolean function(PlayerWrapper> playerWrapper) {
+ Object wrapperNative = playerWrapper.getPlayer();
+ UUID uuid = playerWrapper.getUniqueId();
+ PlayerWrapper> retrieved = DynamicGui.get().getPlatform().getPlayer(uuid);
+ Object retrievedNative = retrieved != null ? retrieved.getPlayer() : null;
+ return retrieved == null || !playerWrapper.isOnline() || !wrapperNative.equals(retrievedNative) ? false : true;
+ }
+}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/MoneyBalanceFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/MoneyBalanceFunction.java
similarity index 72%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/MoneyBalanceFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/MoneyBalanceFunction.java
index 69893b26c..e8586316c 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/MoneyBalanceFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/MoneyBalanceFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl;
-import com.clubobsidian.dynamicgui.DynamicGui;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
+package com.clubobsidian.dynamicgui.core.function.impl;
+
+import com.clubobsidian.dynamicgui.core.DynamicGui;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
import java.math.BigDecimal;
@@ -29,8 +30,8 @@ public class MoneyBalanceFunction extends Function {
*/
private static final long serialVersionUID = -2637510737725573158L;
- public MoneyBalanceFunction(String name) {
- super(name);
+ public MoneyBalanceFunction() {
+ super("moneybalance");
}
@Override
@@ -38,16 +39,16 @@ public boolean function(final PlayerWrapper> playerWrapper) {
double amt;
try {
amt = Double.parseDouble(this.getData());
- } catch(Exception ex) {
+ } catch (Exception ex) {
ex.printStackTrace();
return false;
}
- if(DynamicGui.get().getPlugin().getEconomy() == null)
+ if (DynamicGui.get().getPlugin().getEconomy() == null) {
return false;
+ }
BigDecimal decimalAmt = new BigDecimal(amt);
-
return DynamicGui.get().getPlugin().getEconomy().getBalance(playerWrapper).compareTo(decimalAmt) >= 0;
}
}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/MoneyDepositFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/MoneyDepositFunction.java
similarity index 72%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/MoneyDepositFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/MoneyDepositFunction.java
index 18a958fa8..89df47890 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/MoneyDepositFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/MoneyDepositFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl;
-import com.clubobsidian.dynamicgui.DynamicGui;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
+package com.clubobsidian.dynamicgui.core.function.impl;
+
+import com.clubobsidian.dynamicgui.core.DynamicGui;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
import java.math.BigDecimal;
@@ -29,8 +30,8 @@ public class MoneyDepositFunction extends Function {
*/
private static final long serialVersionUID = -2637510737725573158L;
- public MoneyDepositFunction(String name) {
- super(name);
+ public MoneyDepositFunction() {
+ super("moneydeposit");
}
@Override
@@ -38,16 +39,14 @@ public boolean function(final PlayerWrapper> playerWrapper) {
double amt;
try {
amt = Double.parseDouble(this.getData());
- } catch(Exception ex) {
+ } catch (Exception ex) {
ex.printStackTrace();
return false;
}
-
- if(DynamicGui.get().getPlugin().getEconomy() == null)
+ if (DynamicGui.get().getPlugin().getEconomy() == null) {
return false;
-
+ }
BigDecimal decimalAmt = new BigDecimal(amt);
-
return DynamicGui.get().getPlugin().getEconomy().deposit(playerWrapper, decimalAmt);
}
}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/MoneyWithdrawFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/MoneyWithdrawFunction.java
similarity index 68%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/MoneyWithdrawFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/MoneyWithdrawFunction.java
index aac94f965..71df91998 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/MoneyWithdrawFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/MoneyWithdrawFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl;
-import com.clubobsidian.dynamicgui.DynamicGui;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
+package com.clubobsidian.dynamicgui.core.function.impl;
+
+import com.clubobsidian.dynamicgui.core.DynamicGui;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
import java.math.BigDecimal;
@@ -28,8 +29,8 @@ public class MoneyWithdrawFunction extends Function {
*/
private static final long serialVersionUID = -8941864727381394744L;
- public MoneyWithdrawFunction(String name) {
- super(name);
+ public MoneyWithdrawFunction() {
+ super("moneywithdraw");
}
@Override
@@ -37,19 +38,17 @@ public boolean function(final PlayerWrapper> playerWrapper) {
double amt;
try {
amt = Double.parseDouble(this.getData());
- } catch(Exception ex) {
+ } catch (Exception ex) {
ex.printStackTrace();
return false;
}
-
- if(DynamicGui.get().getPlugin().getEconomy() == null)
+ if (DynamicGui.get().getPlugin().getEconomy() == null) {
return false;
-
+ }
BigDecimal decimalAmt = new BigDecimal(amt);
- if(DynamicGui.get().getPlugin().getEconomy().getBalance(playerWrapper).compareTo(decimalAmt) == -1) {
+ if (DynamicGui.get().getPlugin().getEconomy().getBalance(playerWrapper).compareTo(decimalAmt) == -1) {
return false;
}
-
return DynamicGui.get().getPlugin().getEconomy().withdraw(playerWrapper, decimalAmt);
}
}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/NoPermissionFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/NoPermissionFunction.java
similarity index 70%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/NoPermissionFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/NoPermissionFunction.java
index 12973702a..ab070eac1 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/NoPermissionFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/NoPermissionFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,10 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
+package com.clubobsidian.dynamicgui.core.function.impl;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
public class NoPermissionFunction extends Function {
@@ -25,12 +26,15 @@ public class NoPermissionFunction extends Function {
*/
private static final long serialVersionUID = 6907686728880861860L;
- public NoPermissionFunction(String name) {
- super(name);
+ public NoPermissionFunction() {
+ super("nopermission");
}
@Override
public boolean function(final PlayerWrapper> playerWrapper) {
+ if (this.getData() == null) {
+ return false;
+ }
return !playerWrapper.hasPermission(this.getData());
}
}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/ParticleFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/ParticleFunction.java
similarity index 68%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/ParticleFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/ParticleFunction.java
index 8fa503fcd..fd47282ff 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/ParticleFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/ParticleFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl;
-import com.clubobsidian.dynamicgui.effect.ParticleWrapper;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
+package com.clubobsidian.dynamicgui.core.function.impl;
+
+import com.clubobsidian.dynamicgui.core.effect.ParticleWrapper;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
public class ParticleFunction extends Function {
@@ -26,12 +27,15 @@ public class ParticleFunction extends Function {
*/
private static final long serialVersionUID = 6719256169872302172L;
- public ParticleFunction(String name) {
- super(name);
+ public ParticleFunction() {
+ super("particles", "particle");
}
@Override
public boolean function(PlayerWrapper> playerWrapper) {
+ if (this.getData() == null) {
+ return false;
+ }
ParticleWrapper wrapper = new ParticleWrapper(this.getData());
wrapper.spawnEffect(playerWrapper);
return true;
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/PermissionFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/PermissionFunction.java
similarity index 70%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/PermissionFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/PermissionFunction.java
index 16fa7882a..4244e96dd 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/PermissionFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/PermissionFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,10 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
+package com.clubobsidian.dynamicgui.core.function.impl;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
public class PermissionFunction extends Function {
@@ -25,12 +26,15 @@ public class PermissionFunction extends Function {
*/
private static final long serialVersionUID = 6578996849784218130L;
- public PermissionFunction(String name) {
- super(name);
+ public PermissionFunction() {
+ super("permission", "haspermission");
}
@Override
public boolean function(final PlayerWrapper> playerWrapper) {
+ if (this.getData() == null) {
+ return false;
+ }
return playerWrapper.hasPermission(this.getData());
}
}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/PlayerCmdFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/PlayerCommandFunction.java
similarity index 64%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/PlayerCmdFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/PlayerCommandFunction.java
index eb41e7638..0ccff0a7a 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/PlayerCmdFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/PlayerCommandFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,25 +13,29 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
-import com.clubobsidian.dynamicgui.manager.dynamicgui.ReplacerManager;
+package com.clubobsidian.dynamicgui.core.function.impl;
-public class PlayerCmdFunction extends Function {
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import com.clubobsidian.dynamicgui.core.manager.dynamicgui.ReplacerManager;
+
+public class PlayerCommandFunction extends Function {
/**
*
*/
private static final long serialVersionUID = 220426382325192292L;
- public PlayerCmdFunction(String name) {
- super(name);
+ public PlayerCommandFunction() {
+ super("executep");
}
@Override
public boolean function(PlayerWrapper> playerWrapper) {
+ if (this.getData() == null) {
+ return false;
+ }
playerWrapper.chat("/" + ReplacerManager.get().replace(this.getData(), playerWrapper));
return true;
}
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/PlayerMsgFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/PlayerMessageFunction.java
similarity index 61%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/PlayerMsgFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/PlayerMessageFunction.java
index ce392e0b7..ccec745a2 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/PlayerMsgFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/PlayerMessageFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,26 +13,30 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
-import com.clubobsidian.dynamicgui.manager.dynamicgui.ReplacerManager;
-import com.clubobsidian.dynamicgui.util.ChatColor;
+package com.clubobsidian.dynamicgui.core.function.impl;
-public class PlayerMsgFunction extends Function {
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import com.clubobsidian.dynamicgui.core.manager.dynamicgui.ReplacerManager;
+import com.clubobsidian.dynamicgui.core.util.ChatColor;
+
+public class PlayerMessageFunction extends Function {
/**
*
*/
private static final long serialVersionUID = 6244543904061733902L;
- public PlayerMsgFunction(String name) {
- super(name);
+ public PlayerMessageFunction() {
+ super("msg", "pmsg", "message", "playermessage");
}
@Override
public boolean function(final PlayerWrapper> playerWrapper) {
+ if (this.getData() == null) {
+ return false;
+ }
playerWrapper.sendMessage(ChatColor.translateAlternateColorCodes(ReplacerManager.get().replace(this.getData(), playerWrapper)));
return true;
}
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/PlayerMiniMsgFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/PlayerMiniMessageFunction.java
similarity index 66%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/PlayerMiniMsgFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/PlayerMiniMessageFunction.java
index 450f58bde..68c41e44d 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/PlayerMiniMsgFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/PlayerMiniMessageFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,29 +14,28 @@
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl;
+package com.clubobsidian.dynamicgui.core.function.impl;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
-import com.clubobsidian.dynamicgui.manager.dynamicgui.MiniMessageManager;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import com.clubobsidian.dynamicgui.core.manager.dynamicgui.MiniMessageManager;
-public class PlayerMiniMsgFunction extends Function {
+public class PlayerMiniMessageFunction extends Function {
/**
*
*/
private static final long serialVersionUID = 9216295481570082778L;
- public PlayerMiniMsgFunction(String name) {
- super(name);
+ public PlayerMiniMessageFunction() {
+ super("minimsg", "minimessage");
}
@Override
public boolean function(PlayerWrapper> playerWrapper) {
- if(this.getData() == null) {
+ if (this.getData() == null) {
return false;
}
-
String json = MiniMessageManager.get().toJson(this.getData());
playerWrapper.sendJsonMessage(json);
return true;
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/PlayerMsgJsonFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/PlayerMsgJsonFunction.java
similarity index 71%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/PlayerMsgJsonFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/PlayerMsgJsonFunction.java
index 232a4eec7..92109b135 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/PlayerMsgJsonFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/PlayerMsgJsonFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,10 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
+package com.clubobsidian.dynamicgui.core.function.impl;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
public class PlayerMsgJsonFunction extends Function {
@@ -25,16 +26,15 @@ public class PlayerMsgJsonFunction extends Function {
*/
private static final long serialVersionUID = -1691264533250689175L;
- public PlayerMsgJsonFunction(String name) {
- super(name);
+ public PlayerMsgJsonFunction() {
+ super("msgjson", "pmsgjson", "messagejson", "playermessagejson");
}
@Override
public boolean function(PlayerWrapper> playerWrapper) {
- if(this.getData() == null) {
+ if (this.getData() == null) {
return false;
}
-
playerWrapper.sendJsonMessage(this.getData());
return true;
}
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/RandomFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/RandomFunction.java
similarity index 73%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/RandomFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/RandomFunction.java
index c65e43604..51aefd98b 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/RandomFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/RandomFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,10 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
+package com.clubobsidian.dynamicgui.core.function.impl;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
import java.util.Random;
@@ -27,16 +28,19 @@ public class RandomFunction extends Function {
*/
private static final long serialVersionUID = -8056953555096911217L;
- public RandomFunction(String name) {
- super(name);
+ public RandomFunction() {
+ super("random", "rand");
}
@Override
public boolean function(PlayerWrapper> playerWrapper) {
+ if (this.getData() == null) {
+ return false;
+ }
try {
- if(this.getData().contains("-")) {
+ if (this.getData().contains("-")) {
String[] split = this.getData().split("-");
- if(split.length == 2) {
+ if (split.length == 2) {
final int end = Integer.parseInt(split[0]);
final int win = Integer.parseInt(split[1]);
final Random rand = new Random();
@@ -45,7 +49,7 @@ public boolean function(PlayerWrapper> playerWrapper) {
return generate == win;
}
}
- } catch(Exception ex) {
+ } catch (Exception ex) {
ex.printStackTrace();
}
return false;
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/RemovePermissionFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/RemovePermissionFunction.java
similarity index 70%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/RemovePermissionFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/RemovePermissionFunction.java
index 9b41a815e..95a1fa81d 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/RemovePermissionFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/RemovePermissionFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,10 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
+package com.clubobsidian.dynamicgui.core.function.impl;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
public class RemovePermissionFunction extends Function {
@@ -25,12 +26,15 @@ public class RemovePermissionFunction extends Function {
*/
private static final long serialVersionUID = 6578996849784218130L;
- public RemovePermissionFunction(String name) {
- super(name);
+ public RemovePermissionFunction() {
+ super("removepermission");
}
@Override
public boolean function(final PlayerWrapper> playerWrapper) {
+ if (this.getData() == null) {
+ return false;
+ }
return playerWrapper.removePermission(this.getData());
}
}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/RemoveSlotFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/RemoveSlotFunction.java
similarity index 62%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/RemoveSlotFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/RemoveSlotFunction.java
index 795e0d03e..c644baed2 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/RemoveSlotFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/RemoveSlotFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,15 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
-import com.clubobsidian.dynamicgui.gui.FunctionOwner;
-import com.clubobsidian.dynamicgui.gui.Gui;
-import com.clubobsidian.dynamicgui.gui.Slot;
-import com.clubobsidian.dynamicgui.inventory.InventoryWrapper;
-import com.clubobsidian.dynamicgui.inventory.ItemStackWrapper;
+package com.clubobsidian.dynamicgui.core.function.impl;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import com.clubobsidian.dynamicgui.core.gui.FunctionOwner;
+import com.clubobsidian.dynamicgui.core.gui.Gui;
+import com.clubobsidian.dynamicgui.core.gui.Slot;
+import com.clubobsidian.dynamicgui.core.inventory.InventoryWrapper;
+import com.clubobsidian.dynamicgui.core.inventory.ItemStackWrapper;
public class RemoveSlotFunction extends Function {
@@ -30,22 +31,21 @@ public class RemoveSlotFunction extends Function {
*/
private static final long serialVersionUID = -88925446185236878L;
- public RemoveSlotFunction(String name) {
- super(name);
+ public RemoveSlotFunction() {
+ super("removeslot");
}
@Override
public boolean function(PlayerWrapper> playerWrapper) {
FunctionOwner owner = this.getOwner();
-
- if(this.getData() == null || this.getData().equals("this")) {
- if(owner != null) {
- if(owner instanceof Slot) {
+ if (this.getData() == null || this.getData().equals("this")) {
+ if (owner != null) {
+ if (owner instanceof Slot) {
Slot slot = (Slot) owner;
Gui gui = slot.getOwner();
- if(gui != null) {
+ if (gui != null) {
InventoryWrapper> inv = gui.getInventoryWrapper();
- if(inv != null) {
+ if (inv != null) {
ItemStackWrapper> item = slot.getItemStack();
item.setType("AIR");
inv.setItem(slot.getIndex(), item);
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/ResetFrameFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/ResetFrameFunction.java
similarity index 71%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/ResetFrameFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/ResetFrameFunction.java
index d3d9f77f4..506011b55 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/ResetFrameFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/ResetFrameFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
-import com.clubobsidian.dynamicgui.gui.Slot;
+package com.clubobsidian.dynamicgui.core.function.impl;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import com.clubobsidian.dynamicgui.core.gui.Slot;
public class ResetFrameFunction extends Function {
@@ -26,13 +27,13 @@ public class ResetFrameFunction extends Function {
*/
private static final long serialVersionUID = -2386244760460728686L;
- public ResetFrameFunction(String name) {
- super(name);
+ public ResetFrameFunction() {
+ super("resetframe");
}
@Override
public boolean function(PlayerWrapper> playerWrapper) {
- if(this.getOwner() instanceof Slot) {
+ if (this.getOwner() instanceof Slot) {
Slot slot = (Slot) this.getOwner();
slot.resetFrame();
return true;
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/ResetTickFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/ResetTickFunction.java
similarity index 71%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/ResetTickFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/ResetTickFunction.java
index 54145edf7..e86104cec 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/ResetTickFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/ResetTickFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
-import com.clubobsidian.dynamicgui.gui.Slot;
+package com.clubobsidian.dynamicgui.core.function.impl;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import com.clubobsidian.dynamicgui.core.gui.Slot;
public class ResetTickFunction extends Function {
@@ -26,13 +27,13 @@ public class ResetTickFunction extends Function {
*/
private static final long serialVersionUID = 6376946053337191934L;
- public ResetTickFunction(String name) {
- super(name);
+ public ResetTickFunction() {
+ super("resettick");
}
@Override
public boolean function(PlayerWrapper> playerWrapper) {
- if(this.getOwner() instanceof Slot) {
+ if (this.getOwner() instanceof Slot) {
Slot slot = (Slot) this.getOwner();
slot.resetTick();
return true;
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/SendFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/SendFunction.java
similarity index 68%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/SendFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/SendFunction.java
index 3031ad51f..52c3ca005 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/SendFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/SendFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl;
-import com.clubobsidian.dynamicgui.DynamicGui;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
+package com.clubobsidian.dynamicgui.core.function.impl;
+
+import com.clubobsidian.dynamicgui.core.DynamicGui;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
public class SendFunction extends Function {
@@ -26,12 +27,15 @@ public class SendFunction extends Function {
*/
private static final long serialVersionUID = 2329250573729355253L;
- public SendFunction(String name) {
- super(name);
+ public SendFunction() {
+ super("send");
}
@Override
public boolean function(PlayerWrapper> playerWrapper) {
+ if (this.getData() == null) {
+ return false;
+ }
return DynamicGui.get().sendToServer(playerWrapper, this.getData());
}
}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/ServerBroadcastFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/ServerBroadcastFunction.java
similarity index 51%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/ServerBroadcastFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/ServerBroadcastFunction.java
index 709ac4a44..d5fd4f822 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/ServerBroadcastFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/ServerBroadcastFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,13 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl;
-import com.clubobsidian.dynamicgui.DynamicGui;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
-import com.clubobsidian.dynamicgui.manager.dynamicgui.ReplacerManager;
-import com.clubobsidian.dynamicgui.util.ChatColor;
+package com.clubobsidian.dynamicgui.core.function.impl;
+
+import com.clubobsidian.dynamicgui.core.DynamicGui;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import com.clubobsidian.dynamicgui.core.manager.dynamicgui.ReplacerManager;
+import com.clubobsidian.dynamicgui.core.util.ChatColor;
public class ServerBroadcastFunction extends Function {
@@ -29,13 +30,20 @@ public class ServerBroadcastFunction extends Function {
*/
private static final long serialVersionUID = 8252199196221271208L;
- public ServerBroadcastFunction(String name) {
- super(name);
+ public ServerBroadcastFunction() {
+ super("broadcast");
}
@Override
public boolean function(PlayerWrapper> playerWrapper) {
- DynamicGui.get().getServer().broadcastMessage(ChatColor.translateAlternateColorCodes('&', ReplacerManager.get().replace(this.getData(), playerWrapper)));
+ if (this.getData() == null) {
+ return false;
+ }
+ String colorized = ChatColor.translateAlternateColorCodes(
+ ReplacerManager
+ .get()
+ .replace(this.getData(), playerWrapper));
+ DynamicGui.get().getPlatform().broadcastMessage(colorized);
return true;
}
}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/ServerBroadcastJsonFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/ServerBroadcastJsonFunction.java
similarity index 65%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/ServerBroadcastJsonFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/ServerBroadcastJsonFunction.java
index 34c05bdac..f3f52860b 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/ServerBroadcastJsonFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/ServerBroadcastJsonFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl;
-import com.clubobsidian.dynamicgui.DynamicGui;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
+package com.clubobsidian.dynamicgui.core.function.impl;
+
+import com.clubobsidian.dynamicgui.core.DynamicGui;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
public class ServerBroadcastJsonFunction extends Function {
@@ -26,17 +27,16 @@ public class ServerBroadcastJsonFunction extends Function {
*/
private static final long serialVersionUID = 7108356107897317545L;
- public ServerBroadcastJsonFunction(String name) {
- super(name);
+ public ServerBroadcastJsonFunction() {
+ super("broadcastjson", "bjson");
}
@Override
public boolean function(PlayerWrapper> playerWrapper) {
- if(this.getData() == null) {
+ if (this.getData() == null) {
return false;
}
-
- DynamicGui.get().getServer().broadcastJsonMessage(this.getData());
+ DynamicGui.get().getPlatform().broadcastJsonMessage(this.getData());
return true;
}
}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/ServerMiniBroadcastFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/ServerMiniBroadcastFunction.java
similarity index 64%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/ServerMiniBroadcastFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/ServerMiniBroadcastFunction.java
index 7a967ca1a..66f580f95 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/ServerMiniBroadcastFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/ServerMiniBroadcastFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,12 +14,12 @@
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl;
+package com.clubobsidian.dynamicgui.core.function.impl;
-import com.clubobsidian.dynamicgui.DynamicGui;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
-import com.clubobsidian.dynamicgui.manager.dynamicgui.MiniMessageManager;
+import com.clubobsidian.dynamicgui.core.DynamicGui;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import com.clubobsidian.dynamicgui.core.manager.dynamicgui.MiniMessageManager;
public class ServerMiniBroadcastFunction extends Function {
@@ -28,18 +28,17 @@ public class ServerMiniBroadcastFunction extends Function {
*/
private static final long serialVersionUID = 9216295481570082778L;
- public ServerMiniBroadcastFunction(String name) {
- super(name);
+ public ServerMiniBroadcastFunction() {
+ super("minibroadcast");
}
@Override
public boolean function(PlayerWrapper> playerWrapper) {
- if(this.getData() == null) {
+ if (this.getData() == null) {
return false;
}
-
String json = MiniMessageManager.get().toJson(this.getData());
- DynamicGui.get().getServer().broadcastJsonMessage(json);
+ DynamicGui.get().getPlatform().broadcastJsonMessage(json);
return true;
}
}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/SetAmountFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/SetAmountFunction.java
new file mode 100644
index 000000000..07945a49c
--- /dev/null
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/SetAmountFunction.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.core.function.impl;
+
+import com.clubobsidian.dynamicgui.core.DynamicGui;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import com.clubobsidian.dynamicgui.core.gui.FunctionOwner;
+import com.clubobsidian.dynamicgui.core.gui.Gui;
+import com.clubobsidian.dynamicgui.core.gui.Slot;
+import com.clubobsidian.dynamicgui.core.inventory.InventoryWrapper;
+import com.clubobsidian.dynamicgui.core.inventory.ItemStackWrapper;
+
+public class SetAmountFunction extends Function {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 6943230273788425141L;
+
+ public SetAmountFunction() {
+ super("setamount");
+ }
+
+ @Override
+ public boolean function(PlayerWrapper> playerWrapper) {
+ if (this.getData() == null) {
+ return false;
+ }
+ FunctionOwner owner = this.getOwner();
+ if (owner != null && owner instanceof Slot) {
+ Slot slot = (Slot) owner;
+ Gui gui = slot.getOwner();
+ if (gui != null) {
+ InventoryWrapper> inv = gui.getInventoryWrapper();
+ if (inv != null) {
+ ItemStackWrapper> item = slot.getItemStack();
+ try {
+ Integer amount = Integer.parseInt(this.getData());
+ item.setAmount(amount);
+ inv.setItem(slot.getIndex(), item);
+ return true;
+ } catch (Exception ex) {
+ DynamicGui.get().getLogger().info("Unable to parse + " + this.getData() + " as an amount");
+ return false;
+ }
+ }
+ }
+
+ }
+ return false;
+ }
+}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/SetCloseFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/SetCloseFunction.java
new file mode 100644
index 000000000..5ee2237b6
--- /dev/null
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/SetCloseFunction.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.core.function.impl;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import com.clubobsidian.dynamicgui.core.gui.property.CloseableComponent;
+
+public class SetCloseFunction extends Function {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -5671625221707551692L;
+
+ public SetCloseFunction() {
+ super("setclose");
+ }
+
+ @Override
+ public boolean function(PlayerWrapper> playerWrapper) {
+ if (this.getData() == null) {
+ return false;
+ }
+ boolean value = Boolean.valueOf(this.getData());
+ if (this.getOwner() instanceof CloseableComponent) {
+ CloseableComponent component = (CloseableComponent) this.getOwner();
+ component.setClose(value);
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/SetDurabilityFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/SetDurabilityFunction.java
new file mode 100644
index 000000000..c4ec59ef8
--- /dev/null
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/SetDurabilityFunction.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.core.function.impl;
+
+import com.clubobsidian.dynamicgui.core.DynamicGui;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import com.clubobsidian.dynamicgui.core.gui.FunctionOwner;
+import com.clubobsidian.dynamicgui.core.gui.Gui;
+import com.clubobsidian.dynamicgui.core.gui.Slot;
+import com.clubobsidian.dynamicgui.core.inventory.InventoryWrapper;
+import com.clubobsidian.dynamicgui.core.inventory.ItemStackWrapper;
+
+public class SetDurabilityFunction extends Function {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 6943230273788425141L;
+
+ public SetDurabilityFunction() {
+ super("setdata", "setdura", "setdurability");
+ }
+
+ @Override
+ public boolean function(PlayerWrapper> playerWrapper) {
+ if (this.getData() == null) {
+ return false;
+ }
+ FunctionOwner owner = this.getOwner();
+ if (owner != null && owner instanceof Slot) {
+ Slot slot = (Slot) owner;
+ Gui gui = slot.getOwner();
+ if (gui != null) {
+ InventoryWrapper> inv = gui.getInventoryWrapper();
+ if (inv != null) {
+ ItemStackWrapper> item = slot.getItemStack();
+ try {
+ short durability = Short.parseShort(this.getData());
+ item.setDurability(durability);
+ inv.setItem(slot.getIndex(), item);
+ return true;
+ } catch (Exception ex) {
+ DynamicGui.get().getLogger().info("Unable to parse + " + this.getData() + " as durability");
+ return false;
+ }
+ }
+ }
+ }
+ return false;
+ }
+}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/SetEnchantsFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/SetEnchantsFunction.java
new file mode 100644
index 000000000..7fab2b575
--- /dev/null
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/SetEnchantsFunction.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.core.function.impl;
+
+import com.clubobsidian.dynamicgui.core.enchantment.EnchantmentWrapper;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import com.clubobsidian.dynamicgui.core.gui.FunctionOwner;
+import com.clubobsidian.dynamicgui.core.gui.Gui;
+import com.clubobsidian.dynamicgui.core.gui.Slot;
+import com.clubobsidian.dynamicgui.core.inventory.InventoryWrapper;
+import com.clubobsidian.dynamicgui.core.inventory.ItemStackWrapper;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class SetEnchantsFunction extends Function {
+
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 8291956007296368761L;
+
+ public SetEnchantsFunction() {
+ super("setenchants");
+ }
+
+ @Override
+ public boolean function(PlayerWrapper> playerWrapper) {
+ if (this.getData() == null) {
+ return false;
+ }
+ FunctionOwner owner = this.getOwner();
+ if (owner != null && owner instanceof Slot) {
+ Slot slot = (Slot) owner;
+ Gui gui = slot.getOwner();
+ if (gui != null) {
+ InventoryWrapper> inv = gui.getInventoryWrapper();
+ if (inv != null) {
+ ItemStackWrapper> item = slot.getItemStack();
+ Map enchants = new HashMap<>();
+ if (this.getData().contains(";")) {
+ for (String str : this.getData().split(";")) {
+ String[] split = str.split(",");
+ enchants.put(split[0], Integer.valueOf(split[1]));
+ }
+ } else {
+ String[] split = this.getData().split(",");
+ enchants.put(split[0], Integer.valueOf(split[1]));
+ }
+
+ for (EnchantmentWrapper wrapper : item.getEnchants()) {
+ item.removeEnchant(wrapper);
+ }
+
+ for (String str : enchants.keySet()) {
+ item.addEnchant(new EnchantmentWrapper(str, enchants.get(str)));
+ }
+
+ inv.setItem(slot.getIndex(), item);
+ return true;
+ }
+ }
+
+ }
+ return false;
+ }
+}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/SetGameRuleFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/SetGameRuleFunction.java
similarity index 64%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/SetGameRuleFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/SetGameRuleFunction.java
index a29ae30d6..521e02401 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/SetGameRuleFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/SetGameRuleFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,12 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl;
-import com.clubobsidian.dynamicgui.DynamicGui;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
-import com.clubobsidian.dynamicgui.world.WorldWrapper;
+package com.clubobsidian.dynamicgui.core.function.impl;
+
+import com.clubobsidian.dynamicgui.core.DynamicGui;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import com.clubobsidian.dynamicgui.core.world.WorldWrapper;
public class SetGameRuleFunction extends Function {
@@ -27,23 +28,21 @@ public class SetGameRuleFunction extends Function {
*/
private static final long serialVersionUID = 664632502310692150L;
- public SetGameRuleFunction(String name) {
- super(name);
+ public SetGameRuleFunction() {
+ super("setgamerule");
}
@Override
public boolean function(PlayerWrapper> playerWrapper) {
- if(this.getData() == null) {
- return false;
- } else if(!this.getData().contains(",")) {
+ if (this.getData() == null || !this.getData().contains(",")) {
return false;
}
String[] split = this.getData().split(",");
- if(split.length == 3) {
+ if (split.length == 3) {
String worldName = split[0];
- WorldWrapper> world = DynamicGui.get().getServer().getWorld(worldName);
- if(world == null) {
+ WorldWrapper> world = DynamicGui.get().getPlatform().getWorld(worldName);
+ if (world == null) {
return false;
}
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/SetGlowFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/SetGlowFunction.java
new file mode 100644
index 000000000..b9356ec21
--- /dev/null
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/SetGlowFunction.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.core.function.impl;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import com.clubobsidian.dynamicgui.core.gui.FunctionOwner;
+import com.clubobsidian.dynamicgui.core.gui.Gui;
+import com.clubobsidian.dynamicgui.core.gui.Slot;
+import com.clubobsidian.dynamicgui.core.inventory.InventoryWrapper;
+import com.clubobsidian.dynamicgui.core.inventory.ItemStackWrapper;
+
+public class SetGlowFunction extends Function {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -3727112026677117024L;
+
+ public SetGlowFunction() {
+ super("setglow", "setglowing");
+ }
+
+ @Override
+ public boolean function(PlayerWrapper> playerWrapper) {
+ if (this.getData() == null) {
+ return false;
+ }
+ FunctionOwner owner = this.getOwner();
+ if (owner != null && owner instanceof Slot) {
+ Slot slot = (Slot) owner;
+ Gui gui = slot.getOwner();
+ if (gui != null) {
+ InventoryWrapper> inv = gui.getInventoryWrapper();
+ if (inv != null) {
+ boolean value = Boolean.parseBoolean(this.getData());
+ ItemStackWrapper> item = slot.getItemStack();
+ item.setGlowing(value);
+ inv.setItem(slot.getIndex(), item);
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/SetLoreFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/SetLoreFunction.java
new file mode 100644
index 000000000..bed8fca6b
--- /dev/null
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/SetLoreFunction.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.core.function.impl;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import com.clubobsidian.dynamicgui.core.gui.FunctionOwner;
+import com.clubobsidian.dynamicgui.core.gui.Gui;
+import com.clubobsidian.dynamicgui.core.gui.Slot;
+import com.clubobsidian.dynamicgui.core.inventory.InventoryWrapper;
+import com.clubobsidian.dynamicgui.core.inventory.ItemStackWrapper;
+import com.clubobsidian.dynamicgui.core.manager.dynamicgui.AnimationReplacerManager;
+import com.clubobsidian.dynamicgui.core.manager.dynamicgui.ReplacerManager;
+import com.clubobsidian.dynamicgui.core.util.ChatColor;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class SetLoreFunction extends Function {
+
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -6723628078978301156L;
+
+ public SetLoreFunction() {
+ super("setlore");
+ }
+
+ @Override
+ public boolean function(PlayerWrapper> playerWrapper) {
+ FunctionOwner owner = this.getOwner();
+ if (owner != null && owner instanceof Slot) {
+ Slot slot = (Slot) owner;
+ Gui gui = slot.getOwner();
+ if (gui != null) {
+ InventoryWrapper> inv = gui.getInventoryWrapper();
+ if (inv != null) {
+ ItemStackWrapper> item = slot.getItemStack();
+ List lore = new ArrayList<>();
+ if (this.getData() == null) {
+ lore = null;
+ } else {
+ String newData = ReplacerManager.get().replace(this.getData(), playerWrapper);
+ newData = AnimationReplacerManager.get().replace(slot, playerWrapper, newData);
+ newData = ChatColor.translateAlternateColorCodes(newData);
+ if (newData.contains("\n")) {
+ for (String str : this.getData().split("\n")) {
+ lore.add(str);
+ }
+ } else {
+ lore.add(newData);
+ }
+ }
+ item.setLore(lore);
+ inv.setItem(slot.getIndex(), item);
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/SetMovableFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/SetMovableFunction.java
new file mode 100644
index 000000000..14a482fb7
--- /dev/null
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/SetMovableFunction.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.core.function.impl;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import com.clubobsidian.dynamicgui.core.gui.FunctionOwner;
+import com.clubobsidian.dynamicgui.core.gui.Gui;
+import com.clubobsidian.dynamicgui.core.gui.Slot;
+
+public class SetMovableFunction extends Function {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 453447798953153174L;
+
+ public SetMovableFunction() {
+ super("setmovable");
+ }
+
+ @Override
+ public boolean function(PlayerWrapper> playerWrapper) {
+ if (this.getData() == null) {
+ return false;
+ }
+ if (this.getOwner() != null && this.getOwner() instanceof Slot) {
+ boolean value = Boolean.parseBoolean(this.getData());
+ FunctionOwner owner = this.getOwner();
+ if (owner != null) {
+ if (owner instanceof Slot) {
+ Slot slot = (Slot) owner;
+ Gui gui = slot.getOwner();
+ if (gui != null) {
+ slot.setMovable(value);
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/SetNBTFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/SetNBTFunction.java
new file mode 100644
index 000000000..e318a5586
--- /dev/null
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/SetNBTFunction.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.core.function.impl;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import com.clubobsidian.dynamicgui.core.gui.FunctionOwner;
+import com.clubobsidian.dynamicgui.core.gui.Gui;
+import com.clubobsidian.dynamicgui.core.gui.Slot;
+import com.clubobsidian.dynamicgui.core.inventory.InventoryWrapper;
+import com.clubobsidian.dynamicgui.core.inventory.ItemStackWrapper;
+
+public class SetNBTFunction extends Function {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 6943230273788425141L;
+
+ public SetNBTFunction() {
+ super("setnbt");
+ }
+
+ @Override
+ public boolean function(PlayerWrapper> playerWrapper) {
+ if (this.getData() == null) {
+ return false;
+ }
+ FunctionOwner owner = this.getOwner();
+ if (owner != null && owner instanceof Slot) {
+ Slot slot = (Slot) owner;
+ Gui gui = slot.getOwner();
+ if (gui != null) {
+ InventoryWrapper> inv = gui.getInventoryWrapper();
+ if (inv != null) {
+ ItemStackWrapper> item = slot.getItemStack();
+ item.setNBT(this.getData());
+ inv.setItem(slot.getIndex(), item);
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/SetNameFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/SetNameFunction.java
new file mode 100644
index 000000000..ac04183f6
--- /dev/null
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/SetNameFunction.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.core.function.impl;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import com.clubobsidian.dynamicgui.core.gui.FunctionOwner;
+import com.clubobsidian.dynamicgui.core.gui.Gui;
+import com.clubobsidian.dynamicgui.core.gui.Slot;
+import com.clubobsidian.dynamicgui.core.inventory.InventoryWrapper;
+import com.clubobsidian.dynamicgui.core.inventory.ItemStackWrapper;
+import com.clubobsidian.dynamicgui.core.manager.dynamicgui.AnimationReplacerManager;
+import com.clubobsidian.dynamicgui.core.manager.dynamicgui.ReplacerManager;
+import com.clubobsidian.dynamicgui.core.util.ChatColor;
+
+public class SetNameFunction extends Function {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -5599516930903780834L;
+
+ public SetNameFunction() {
+ super("setname");
+ }
+
+ @Override
+ public boolean function(PlayerWrapper> playerWrapper) {
+ if (this.getData() == null) {
+ return false;
+ }
+ FunctionOwner owner = this.getOwner();
+ if (owner != null && owner instanceof Slot) {
+ Slot slot = (Slot) owner;
+ Gui gui = slot.getOwner();
+ if (gui != null) {
+ InventoryWrapper> inv = gui.getInventoryWrapper();
+ if (inv != null) {
+ ItemStackWrapper> item = slot.getItemStack();
+ String newName = ChatColor.translateAlternateColorCodes(this.getData());
+ newName = ReplacerManager.get().replace(newName, playerWrapper);
+ newName = AnimationReplacerManager.get().replace(slot, playerWrapper, newName);
+ item.setName(newName);
+ inv.setItem(slot.getIndex(), item);
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/SetTypeFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/SetTypeFunction.java
new file mode 100644
index 000000000..d4060b2e9
--- /dev/null
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/SetTypeFunction.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.core.function.impl;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import com.clubobsidian.dynamicgui.core.gui.FunctionOwner;
+import com.clubobsidian.dynamicgui.core.gui.Gui;
+import com.clubobsidian.dynamicgui.core.gui.Slot;
+import com.clubobsidian.dynamicgui.core.inventory.InventoryWrapper;
+import com.clubobsidian.dynamicgui.core.inventory.ItemStackWrapper;
+
+public class SetTypeFunction extends Function {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 6943230273788425141L;
+
+ public SetTypeFunction() {
+ super("settype");
+ }
+
+ @Override
+ public boolean function(PlayerWrapper> playerWrapper) {
+ if (this.getData() == null) {
+ return false;
+ }
+ FunctionOwner owner = this.getOwner();
+ if (owner != null && owner instanceof Slot) {
+ Slot slot = (Slot) owner;
+ Gui gui = slot.getOwner();
+ if (gui != null) {
+ InventoryWrapper> inv = gui.getInventoryWrapper();
+ if (inv != null) {
+ ItemStackWrapper> item = slot.getItemStack();
+ item.setType(this.getData());
+ inv.setItem(slot.getIndex(), item);
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/SoundFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/SoundFunction.java
similarity index 69%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/SoundFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/SoundFunction.java
index b70275c41..1fb9e5e91 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/SoundFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/SoundFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
-import com.clubobsidian.dynamicgui.sound.SoundWrapper;
+package com.clubobsidian.dynamicgui.core.function.impl;
+
+import com.clubobsidian.dynamicgui.core.effect.SoundWrapper;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
public class SoundFunction extends Function {
@@ -26,12 +27,15 @@ public class SoundFunction extends Function {
*/
private static final long serialVersionUID = -8363807525418126179L;
- public SoundFunction(String name) {
- super(name);
+ public SoundFunction() {
+ super("sound");
}
@Override
public boolean function(PlayerWrapper> playerWrapper) {
+ if (this.getData() == null) {
+ return false;
+ }
SoundWrapper wrapper = new SoundWrapper(this.getData());
wrapper.playSoundToPlayer(playerWrapper);
return true;
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/condition/AfterDateLazyFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/condition/AfterDateLazyFunction.java
similarity index 55%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/condition/AfterDateLazyFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/condition/AfterDateLazyFunction.java
index 72e5800f7..d20addb26 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/condition/AfterDateLazyFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/condition/AfterDateLazyFunction.java
@@ -1,34 +1,50 @@
-package com.clubobsidian.dynamicgui.function.impl.condition;
-
-import com.clubobsidian.dynamicgui.DynamicGui;
-import com.udojava.evalex.AbstractLazyFunction;
-import com.udojava.evalex.Expression.LazyNumber;
-
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.time.Instant;
-import java.util.Date;
-import java.util.List;
-
-public class AfterDateLazyFunction extends AbstractLazyFunction {
-
- protected AfterDateLazyFunction() {
- super("AFTERDATE", 1, true);
- }
-
- @Override
- public LazyNumber lazyEval(List lazyParams) {
- try {
- String format = DynamicGui.get().getDateTimeFormat();
- Date now = Date.from(Instant.now());
- Date expected = new SimpleDateFormat(format).parse(lazyParams.get(0).getString());
- if(now.after(expected)) {
- return ConditionFunction.ONE;
- }
- } catch (ParseException ignore) {
- DynamicGui.get().getLogger().error(String.format("Invalid Date: %s",
- lazyParams.get(0).getString()));
- }
- return ConditionFunction.ZERO;
- }
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.core.function.impl.condition;
+
+import com.clubobsidian.dynamicgui.core.DynamicGui;
+import com.udojava.evalex.AbstractLazyFunction;
+import com.udojava.evalex.Expression.LazyNumber;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.time.Instant;
+import java.util.Date;
+import java.util.List;
+
+public class AfterDateLazyFunction extends AbstractLazyFunction {
+
+ protected AfterDateLazyFunction() {
+ super("AFTERDATE", 1, true);
+ }
+
+ @Override
+ public LazyNumber lazyEval(List lazyParams) {
+ try {
+ String format = DynamicGui.get().getDateTimeFormat();
+ Date now = Date.from(Instant.now());
+ Date expected = new SimpleDateFormat(format).parse(lazyParams.get(0).getString());
+ if (now.after(expected)) {
+ return ConditionFunction.ONE;
+ }
+ } catch (ParseException ignore) {
+ DynamicGui.get().getLogger().error(String.format("Invalid Date: %s",
+ lazyParams.get(0).getString()));
+ }
+ return ConditionFunction.ZERO;
+ }
}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/condition/BeforeDateLazyFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/condition/BeforeDateLazyFunction.java
similarity index 55%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/condition/BeforeDateLazyFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/condition/BeforeDateLazyFunction.java
index 6ffbfe1a7..25453c0e9 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/condition/BeforeDateLazyFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/condition/BeforeDateLazyFunction.java
@@ -1,34 +1,50 @@
-package com.clubobsidian.dynamicgui.function.impl.condition;
-
-import com.clubobsidian.dynamicgui.DynamicGui;
-import com.udojava.evalex.AbstractLazyFunction;
-import com.udojava.evalex.Expression.LazyNumber;
-
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.time.Instant;
-import java.util.Date;
-import java.util.List;
-
-public class BeforeDateLazyFunction extends AbstractLazyFunction {
-
- protected BeforeDateLazyFunction() {
- super("BEFOREDATE", 1, true);
- }
-
- @Override
- public LazyNumber lazyEval(List lazyParams) {
- try {
- String format = DynamicGui.get().getDateTimeFormat();
- Date now = Date.from(Instant.now());
- Date expected = new SimpleDateFormat(format).parse(lazyParams.get(0).getString());
- if(now.before(expected)) {
- return ConditionFunction.ONE;
- }
- } catch (ParseException ignore) {
- DynamicGui.get().getLogger().error(String.format("Invalid Date: %s",
- lazyParams.get(0).getString()));
- }
- return ConditionFunction.ZERO;
- }
-}
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.core.function.impl.condition;
+
+import com.clubobsidian.dynamicgui.core.DynamicGui;
+import com.udojava.evalex.AbstractLazyFunction;
+import com.udojava.evalex.Expression.LazyNumber;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.time.Instant;
+import java.util.Date;
+import java.util.List;
+
+public class BeforeDateLazyFunction extends AbstractLazyFunction {
+
+ protected BeforeDateLazyFunction() {
+ super("BEFOREDATE", 1, true);
+ }
+
+ @Override
+ public LazyNumber lazyEval(List lazyParams) {
+ try {
+ String format = DynamicGui.get().getDateTimeFormat();
+ Date now = Date.from(Instant.now());
+ Date expected = new SimpleDateFormat(format).parse(lazyParams.get(0).getString());
+ if (now.before(expected)) {
+ return ConditionFunction.ONE;
+ }
+ } catch (ParseException ignore) {
+ DynamicGui.get().getLogger().error(String.format("Invalid Date: %s",
+ lazyParams.get(0).getString()));
+ }
+ return ConditionFunction.ZERO;
+ }
+}
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/condition/CheckTickFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/condition/CheckTickFunction.java
similarity index 75%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/condition/CheckTickFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/condition/CheckTickFunction.java
index f40263160..25ba73d7e 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/condition/CheckTickFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/condition/CheckTickFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,12 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl.condition;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
-import com.clubobsidian.dynamicgui.gui.FunctionOwner;
-import com.clubobsidian.dynamicgui.gui.Slot;
+package com.clubobsidian.dynamicgui.core.function.impl.condition;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import com.clubobsidian.dynamicgui.core.gui.FunctionOwner;
+import com.clubobsidian.dynamicgui.core.gui.Slot;
import com.udojava.evalex.Expression;
public class CheckTickFunction extends Function {
@@ -28,14 +29,14 @@ public class CheckTickFunction extends Function {
*/
private static final long serialVersionUID = 9209750645416892269L;
- public CheckTickFunction(String name) {
- super(name);
+ public CheckTickFunction() {
+ super("checktick");
}
@Override
public boolean function(PlayerWrapper> playerWrapper) {
FunctionOwner owner = this.getOwner();
- if(owner instanceof Slot) {
+ if (owner instanceof Slot) {
Slot slot = (Slot) owner;
int tick = slot.getCurrentTick();
int frame = slot.getFrame();
@@ -47,12 +48,12 @@ public boolean function(PlayerWrapper> playerWrapper) {
Expression expr = new Expression(tickData);
expr.addLazyFunction(new EqualLazyFunction());
- if(!expr.isBoolean()) {
+ if (!expr.isBoolean()) {
return false;
}
return expr.eval().intValue() == 1;
- } catch(Exception ex) {
+ } catch (Exception ex) {
ex.printStackTrace();
return false;
}
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/condition/ConditionFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/condition/ConditionFunction.java
similarity index 84%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/condition/ConditionFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/condition/ConditionFunction.java
index 5a31f1c96..4f4e7ef65 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/condition/ConditionFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/condition/ConditionFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,10 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl.condition;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
+package com.clubobsidian.dynamicgui.core.function.impl.condition;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
import com.udojava.evalex.Expression;
import com.udojava.evalex.Expression.LazyNumber;
@@ -29,8 +30,8 @@ public class ConditionFunction extends Function {
*/
private static final long serialVersionUID = -3905599553938205838L;
- public ConditionFunction(String name) {
- super(name);
+ public ConditionFunction() {
+ super("condition");
}
@Override
@@ -46,11 +47,11 @@ public boolean function(PlayerWrapper> playerWrapper) {
expr.addLazyFunction(new AfterDateLazyFunction());
expr.addLazyFunction(new BeforeDateLazyFunction());
- if(!expr.isBoolean())
+ if (!expr.isBoolean())
return false;
return expr.eval().intValue() == 1;
- } catch(Exception ex) {
+ } catch (Exception ex) {
ex.printStackTrace();
return false;
}
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/condition/ContainsLazyFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/condition/ContainsLazyFunction.java
similarity index 83%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/condition/ContainsLazyFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/condition/ContainsLazyFunction.java
index d50932df0..9b6c293c3 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/condition/ContainsLazyFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/condition/ContainsLazyFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl.condition;
+
+package com.clubobsidian.dynamicgui.core.function.impl.condition;
import com.udojava.evalex.AbstractLazyFunction;
import com.udojava.evalex.Expression.LazyNumber;
@@ -28,7 +29,7 @@ protected ContainsLazyFunction() {
@Override
public LazyNumber lazyEval(List lazyParams) {
- if(lazyParams.get(0).getString().contains(lazyParams.get(1).getString())) {
+ if (lazyParams.get(0).getString().contains(lazyParams.get(1).getString())) {
return ConditionFunction.ONE;
}
return ConditionFunction.ZERO;
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/condition/EndsWithLazyFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/condition/EndsWithLazyFunction.java
similarity index 83%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/condition/EndsWithLazyFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/condition/EndsWithLazyFunction.java
index ece6d2bdb..b84061f8a 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/condition/EndsWithLazyFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/condition/EndsWithLazyFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl.condition;
+
+package com.clubobsidian.dynamicgui.core.function.impl.condition;
import com.udojava.evalex.AbstractLazyFunction;
import com.udojava.evalex.Expression.LazyNumber;
@@ -28,7 +29,7 @@ protected EndsWithLazyFunction() {
@Override
public LazyNumber lazyEval(List lazyParams) {
- if(lazyParams.get(0).getString().endsWith(lazyParams.get(1).getString())) {
+ if (lazyParams.get(0).getString().endsWith(lazyParams.get(1).getString())) {
return ConditionFunction.ONE;
}
return ConditionFunction.ZERO;
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/condition/EqualLazyFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/condition/EqualLazyFunction.java
similarity index 83%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/condition/EqualLazyFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/condition/EqualLazyFunction.java
index f34d248b6..1e85440a6 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/condition/EqualLazyFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/condition/EqualLazyFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl.condition;
+
+package com.clubobsidian.dynamicgui.core.function.impl.condition;
import com.udojava.evalex.AbstractLazyFunction;
import com.udojava.evalex.Expression.LazyNumber;
@@ -28,7 +29,7 @@ protected EqualLazyFunction() {
@Override
public LazyNumber lazyEval(List lazyParams) {
- if(lazyParams.get(0).getString().equals(lazyParams.get(1).getString())) {
+ if (lazyParams.get(0).getString().equals(lazyParams.get(1).getString())) {
return ConditionFunction.ONE;
}
return ConditionFunction.ZERO;
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/condition/IgnoreCaseEqualLazyFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/condition/IgnoreCaseEqualLazyFunction.java
similarity index 83%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/condition/IgnoreCaseEqualLazyFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/condition/IgnoreCaseEqualLazyFunction.java
index e649d6151..8fc804b89 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/condition/IgnoreCaseEqualLazyFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/condition/IgnoreCaseEqualLazyFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl.condition;
+
+package com.clubobsidian.dynamicgui.core.function.impl.condition;
import com.udojava.evalex.AbstractLazyFunction;
import com.udojava.evalex.Expression.LazyNumber;
@@ -28,7 +29,7 @@ protected IgnoreCaseEqualLazyFunction() {
@Override
public LazyNumber lazyEval(List lazyParams) {
- if(lazyParams.get(0).getString().equalsIgnoreCase(lazyParams.get(1).getString())) {
+ if (lazyParams.get(0).getString().equalsIgnoreCase(lazyParams.get(1).getString())) {
return ConditionFunction.ONE;
}
return ConditionFunction.ZERO;
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/condition/StartsWithLazyFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/condition/StartsWithLazyFunction.java
similarity index 83%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/condition/StartsWithLazyFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/condition/StartsWithLazyFunction.java
index 1ead07bfb..43b626334 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/condition/StartsWithLazyFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/condition/StartsWithLazyFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl.condition;
+
+package com.clubobsidian.dynamicgui.core.function.impl.condition;
import com.udojava.evalex.AbstractLazyFunction;
import com.udojava.evalex.Expression.LazyNumber;
@@ -28,7 +29,7 @@ protected StartsWithLazyFunction() {
@Override
public LazyNumber lazyEval(List lazyParams) {
- if(lazyParams.get(0).getString().startsWith(lazyParams.get(1).getString())) {
+ if (lazyParams.get(0).getString().startsWith(lazyParams.get(1).getString())) {
return ConditionFunction.ONE;
}
return ConditionFunction.ZERO;
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/cooldown/IsNotOnCooldownFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/cooldown/IsNotOnCooldownFunction.java
similarity index 68%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/cooldown/IsNotOnCooldownFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/cooldown/IsNotOnCooldownFunction.java
index 8fde4f7dd..41da04fe2 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/cooldown/IsNotOnCooldownFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/cooldown/IsNotOnCooldownFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl.cooldown;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
-import com.clubobsidian.dynamicgui.manager.dynamicgui.cooldown.CooldownManager;
+package com.clubobsidian.dynamicgui.core.function.impl.cooldown;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import com.clubobsidian.dynamicgui.core.manager.dynamicgui.cooldown.CooldownManager;
public class IsNotOnCooldownFunction extends Function {
@@ -27,16 +28,15 @@ public class IsNotOnCooldownFunction extends Function {
*/
private static final long serialVersionUID = 2369277150280303056L;
- public IsNotOnCooldownFunction(String name) {
- super(name);
+ public IsNotOnCooldownFunction() {
+ super("isnotoncooldown");
}
@Override
public boolean function(PlayerWrapper> playerWrapper) {
- if(this.getData() == null) {
+ if (this.getData() == null) {
return false;
}
-
return !CooldownManager.get().isOnCooldown(playerWrapper, this.getData());
}
}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/cooldown/IsOnCooldownFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/cooldown/IsOnCooldownFunction.java
similarity index 69%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/cooldown/IsOnCooldownFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/cooldown/IsOnCooldownFunction.java
index ac10a1eb4..9567a3c2c 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/cooldown/IsOnCooldownFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/cooldown/IsOnCooldownFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl.cooldown;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
-import com.clubobsidian.dynamicgui.manager.dynamicgui.cooldown.CooldownManager;
+package com.clubobsidian.dynamicgui.core.function.impl.cooldown;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import com.clubobsidian.dynamicgui.core.manager.dynamicgui.cooldown.CooldownManager;
public class IsOnCooldownFunction extends Function {
@@ -27,16 +28,15 @@ public class IsOnCooldownFunction extends Function {
*/
private static final long serialVersionUID = 2369277150280303056L;
- public IsOnCooldownFunction(String name) {
- super(name);
+ public IsOnCooldownFunction() {
+ super("isoncooldown");
}
@Override
public boolean function(PlayerWrapper> playerWrapper) {
- if(this.getData() == null) {
+ if (this.getData() == null) {
return false;
}
-
return CooldownManager.get().isOnCooldown(playerWrapper, this.getData());
}
}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/cooldown/SetCooldownFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/cooldown/SetCooldownFunction.java
similarity index 68%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/cooldown/SetCooldownFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/cooldown/SetCooldownFunction.java
index 52817e796..987ac9940 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/cooldown/SetCooldownFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/cooldown/SetCooldownFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl.cooldown;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
-import com.clubobsidian.dynamicgui.manager.dynamicgui.cooldown.CooldownManager;
+package com.clubobsidian.dynamicgui.core.function.impl.cooldown;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import com.clubobsidian.dynamicgui.core.manager.dynamicgui.cooldown.CooldownManager;
public class SetCooldownFunction extends Function {
@@ -26,28 +27,26 @@ public class SetCooldownFunction extends Function {
*/
private static final long serialVersionUID = -3204581055961888388L;
- public SetCooldownFunction(String name) {
- super(name);
+ public SetCooldownFunction() {
+ super("setcooldown");
}
@Override
public boolean function(PlayerWrapper> playerWrapper) {
- if(this.getData() == null) {
- return false;
- } else if(!this.getData().contains(",")) {
+ if (this.getData() == null || !this.getData().contains(",")) {
return false;
}
String[] split = this.getData().split(",");
- if(split.length != 2) {
+ if (split.length != 2) {
return false;
}
String name = split[0];
- Long cooldownTime = 0L;
+ long cooldownTime;
try {
cooldownTime = Long.parseLong(split[1]);
- } catch(NumberFormatException ex) {
+ } catch (NumberFormatException ex) {
return false;
}
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/gui/BackFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/gui/BackFunction.java
similarity index 53%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/gui/BackFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/gui/BackFunction.java
index 93ffdf8c8..b7bb1a152 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/gui/BackFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/gui/BackFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,14 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl.gui;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
-import com.clubobsidian.dynamicgui.gui.FunctionOwner;
-import com.clubobsidian.dynamicgui.gui.Gui;
-import com.clubobsidian.dynamicgui.gui.Slot;
-import com.clubobsidian.dynamicgui.manager.dynamicgui.GuiManager;
+package com.clubobsidian.dynamicgui.core.function.impl.gui;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import com.clubobsidian.dynamicgui.core.gui.FunctionOwner;
+import com.clubobsidian.dynamicgui.core.gui.Gui;
+import com.clubobsidian.dynamicgui.core.gui.Slot;
+import com.clubobsidian.dynamicgui.core.manager.dynamicgui.GuiManager;
+
+import java.util.concurrent.ExecutionException;
public class BackFunction extends Function {
@@ -29,43 +32,43 @@ public class BackFunction extends Function {
*/
private static final long serialVersionUID = 7851730396417693718L;
- public BackFunction(String name) {
- super(name);
+ public BackFunction() {
+ super("back", true);
}
@Override
public boolean function(PlayerWrapper> playerWrapper) {
Gui gui = null;
FunctionOwner owner = this.getOwner();
- if(owner instanceof Slot) {
+ if (owner instanceof Slot) {
Slot slot = (Slot) owner;
gui = slot.getOwner();
slot.setClose(false);
- } else if(owner instanceof Gui) {
+ } else if (owner instanceof Gui) {
gui = (Gui) owner;
}
-
Gui back = gui.getBack();
- if(back != null) {
- if(this.getData() != null) {
+ if (back != null) {
+ if (this.getData() != null) {
try {
- Integer backAmount = Integer.parseInt(this.getData());
- for(int i = 1; i < backAmount; i++) {
+ int backAmount = Integer.parseInt(this.getData());
+ for (int i = 1; i < backAmount; i++) {
Gui nextBack = back.getBack();
- if(nextBack != null) {
+ if (nextBack != null) {
back = nextBack;
}
}
- } catch(NumberFormatException ex) {
+ } catch (NumberFormatException ex) {
return false;
}
}
-
- GuiManager.get().openGui(playerWrapper, back);
- return true;
+ try {
+ return GuiManager.get().openGui(playerWrapper, back).get();
+ } catch (InterruptedException | ExecutionException e) {
+ e.printStackTrace();
+ }
}
-
return false;
}
}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/gui/GuiFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/gui/GuiFunction.java
similarity index 55%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/gui/GuiFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/gui/GuiFunction.java
index b7a552e6a..96ca6da86 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/gui/GuiFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/gui/GuiFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,14 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl.gui;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
-import com.clubobsidian.dynamicgui.gui.FunctionOwner;
-import com.clubobsidian.dynamicgui.gui.Gui;
-import com.clubobsidian.dynamicgui.gui.Slot;
-import com.clubobsidian.dynamicgui.manager.dynamicgui.GuiManager;
+package com.clubobsidian.dynamicgui.core.function.impl.gui;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import com.clubobsidian.dynamicgui.core.gui.FunctionOwner;
+import com.clubobsidian.dynamicgui.core.gui.Gui;
+import com.clubobsidian.dynamicgui.core.gui.Slot;
+import com.clubobsidian.dynamicgui.core.manager.dynamicgui.GuiManager;
+
+import java.util.concurrent.ExecutionException;
public class GuiFunction extends Function {
@@ -29,34 +32,41 @@ public class GuiFunction extends Function {
*/
private static final long serialVersionUID = 848178368629667482L;
- public GuiFunction(String name) {
- super(name);
+ public GuiFunction() {
+ super("gui", true);
}
@Override
public boolean function(final PlayerWrapper> playerWrapper) {
final String gui = this.getData();
-
- if(!GuiManager.get().hasGuiName(gui)) {
+ if (gui == null) {
+ return false;
+ }
+ if (!GuiManager.get().isGuiLoaded(gui)) {
return false;
}
Gui back = null;
FunctionOwner owner = this.getOwner();
//Find root gui
- if(owner instanceof Slot) {
+ if (owner instanceof Slot) {
Slot slot = (Slot) owner;
back = slot.getOwner();
- } else if(owner instanceof Gui) {
+ } else if (owner instanceof Gui) {
back = (Gui) owner;
}
//Make it so the gui doesn't close
- if(owner instanceof Slot) {
+ if (owner instanceof Slot) {
Slot slot = (Slot) owner;
slot.setClose(false);
}
back.setClose(false);
- return GuiManager.get().openGui(playerWrapper, gui, back);
+ try {
+ return GuiManager.get().openGui(playerWrapper, gui, back).get();
+ } catch (InterruptedException | ExecutionException e) {
+ e.printStackTrace();
+ return false;
+ }
}
}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/gui/HasBackFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/gui/HasBackFunction.java
similarity index 66%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/gui/HasBackFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/gui/HasBackFunction.java
index 564cf1ff3..96697b15b 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/gui/HasBackFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/gui/HasBackFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,13 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl.gui;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
-import com.clubobsidian.dynamicgui.gui.FunctionOwner;
-import com.clubobsidian.dynamicgui.gui.Gui;
-import com.clubobsidian.dynamicgui.gui.Slot;
+package com.clubobsidian.dynamicgui.core.function.impl.gui;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import com.clubobsidian.dynamicgui.core.gui.FunctionOwner;
+import com.clubobsidian.dynamicgui.core.gui.Gui;
+import com.clubobsidian.dynamicgui.core.gui.Slot;
public class HasBackFunction extends Function {
@@ -29,18 +30,18 @@ public class HasBackFunction extends Function {
*/
private static final long serialVersionUID = -6693867193877376679L;
- public HasBackFunction(String name) {
- super(name);
+ public HasBackFunction() {
+ super("hasback");
}
@Override
public boolean function(PlayerWrapper> playerWrapper) {
Gui gui = null;
FunctionOwner owner = this.getOwner();
- if(owner instanceof Slot) {
+ if (owner instanceof Slot) {
Slot slot = (Slot) owner;
gui = slot.getOwner();
- } else if(owner instanceof Gui) {
+ } else if (owner instanceof Gui) {
gui = (Gui) owner;
}
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/gui/RefreshGuiFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/gui/RefreshGuiFunction.java
similarity index 65%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/gui/RefreshGuiFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/gui/RefreshGuiFunction.java
index 9913e75d6..70b72141a 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/gui/RefreshGuiFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/gui/RefreshGuiFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,13 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl.gui;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
-import com.clubobsidian.dynamicgui.gui.FunctionOwner;
-import com.clubobsidian.dynamicgui.gui.Gui;
-import com.clubobsidian.dynamicgui.gui.Slot;
+package com.clubobsidian.dynamicgui.core.function.impl.gui;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import com.clubobsidian.dynamicgui.core.gui.FunctionOwner;
+import com.clubobsidian.dynamicgui.core.gui.Gui;
+import com.clubobsidian.dynamicgui.core.gui.Slot;
public class RefreshGuiFunction extends Function {
@@ -28,22 +29,22 @@ public class RefreshGuiFunction extends Function {
*/
private static final long serialVersionUID = -8608158103976585358L;
- public RefreshGuiFunction(String name) {
- super(name);
+ public RefreshGuiFunction() {
+ super("refreshgui");
}
@Override
public boolean function(PlayerWrapper> playerWrapper) {
Gui gui = null;
FunctionOwner owner = this.getOwner();
- if(owner instanceof Slot) {
+ if (owner instanceof Slot) {
Slot slot = (Slot) owner;
gui = slot.getOwner();
- } else if(owner instanceof Gui) {
+ } else if (owner instanceof Gui) {
gui = (Gui) owner;
}
- for(Slot slot : gui.getSlots()) {
+ for (Slot slot : gui.getSlots()) {
slot.setUpdate(true);
}
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/gui/RefreshSlotFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/gui/RefreshSlotFunction.java
similarity index 68%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/gui/RefreshSlotFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/gui/RefreshSlotFunction.java
index 630294e1f..a7b77a278 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/gui/RefreshSlotFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/gui/RefreshSlotFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,13 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl.gui;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
-import com.clubobsidian.dynamicgui.gui.FunctionOwner;
-import com.clubobsidian.dynamicgui.gui.Gui;
-import com.clubobsidian.dynamicgui.gui.Slot;
+package com.clubobsidian.dynamicgui.core.function.impl.gui;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import com.clubobsidian.dynamicgui.core.gui.FunctionOwner;
+import com.clubobsidian.dynamicgui.core.gui.Gui;
+import com.clubobsidian.dynamicgui.core.gui.Slot;
import java.util.ArrayList;
import java.util.List;
@@ -31,14 +32,14 @@ public class RefreshSlotFunction extends Function {
*/
private static final long serialVersionUID = 1079816229207205846L;
- public RefreshSlotFunction(String name) {
- super(name);
+ public RefreshSlotFunction() {
+ super("refreshslot");
}
@Override
public boolean function(PlayerWrapper> playerWrapper) {
- if(this.getData() == null) {
- if(this.getOwner() instanceof Gui) {
+ if (this.getData() == null) {
+ if (this.getOwner() instanceof Gui) {
return false;
}
@@ -50,12 +51,12 @@ public boolean function(PlayerWrapper> playerWrapper) {
try {
String data = this.getData();
List slotIndexs = new ArrayList<>();
- if(!data.contains(",")) {
+ if (!data.contains(",")) {
int parsed = Integer.parseInt(data);
slotIndexs.add(parsed);
} else {
String[] split = data.split(",");
- for(String str : split) {
+ for (String str : split) {
Integer parsed = Integer.parseInt(str);
slotIndexs.add(parsed);
}
@@ -63,22 +64,22 @@ public boolean function(PlayerWrapper> playerWrapper) {
Gui gui = null;
FunctionOwner owner = this.getOwner();
- if(owner instanceof Slot) {
+ if (owner instanceof Slot) {
Slot slot = (Slot) owner;
gui = slot.getOwner();
- } else if(owner instanceof Gui) {
+ } else if (owner instanceof Gui) {
gui = (Gui) owner;
}
List slots = gui.getSlots();
- for(Slot slot : slots) {
- if(slotIndexs.contains(slot.getIndex())) {
+ for (Slot slot : slots) {
+ if (slotIndexs.contains(slot.getIndex())) {
slot.setUpdate(true);
}
}
return true;
- } catch(NumberFormatException ex) {
+ } catch (NumberFormatException ex) {
return false;
}
}
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/gui/SetBackFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/gui/SetBackFunction.java
similarity index 60%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/gui/SetBackFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/gui/SetBackFunction.java
index 05d65d4b7..6be502b02 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/gui/SetBackFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/gui/SetBackFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,14 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl.gui;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
-import com.clubobsidian.dynamicgui.gui.FunctionOwner;
-import com.clubobsidian.dynamicgui.gui.Gui;
-import com.clubobsidian.dynamicgui.gui.Slot;
-import com.clubobsidian.dynamicgui.manager.dynamicgui.GuiManager;
+package com.clubobsidian.dynamicgui.core.function.impl.gui;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import com.clubobsidian.dynamicgui.core.gui.FunctionOwner;
+import com.clubobsidian.dynamicgui.core.gui.Gui;
+import com.clubobsidian.dynamicgui.core.gui.Slot;
+import com.clubobsidian.dynamicgui.core.manager.dynamicgui.GuiManager;
public class SetBackFunction extends Function {
@@ -29,34 +30,32 @@ public class SetBackFunction extends Function {
*/
private static final long serialVersionUID = 4999698612673673935L;
- public SetBackFunction(String name) {
- super(name);
+ public SetBackFunction() {
+ super("setback");
}
@Override
public boolean function(PlayerWrapper> playerWrapper) {
Gui gui = null;
FunctionOwner owner = this.getOwner();
- if(owner instanceof Slot) {
+ if (owner instanceof Slot) {
Slot slot = (Slot) owner;
gui = slot.getOwner();
- } else if(owner instanceof Gui) {
+ } else if (owner instanceof Gui) {
gui = (Gui) owner;
}
- if(gui == null) {
+ if (gui == null) {
return false;
- } else if(this.getData() == null) {
+ } else if (this.getData() == null) {
return false;
}
- Gui backGui = GuiManager.get().getGuiByName(this.getData());
- if(backGui == null) {
+ Gui backGui = GuiManager.get().getGui(this.getData());
+ if (backGui == null) {
return false;
}
-
gui.setBack(backGui);
-
return true;
}
}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/meta/CopyBackMetadataFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/meta/CopyBackMetadataFunction.java
similarity index 66%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/meta/CopyBackMetadataFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/meta/CopyBackMetadataFunction.java
index bda145a0f..fc5ea7c73 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/meta/CopyBackMetadataFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/meta/CopyBackMetadataFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,35 +13,36 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl.meta;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
-import com.clubobsidian.dynamicgui.gui.FunctionOwner;
-import com.clubobsidian.dynamicgui.gui.Gui;
-import com.clubobsidian.dynamicgui.gui.Slot;
+package com.clubobsidian.dynamicgui.core.function.impl.meta;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import com.clubobsidian.dynamicgui.core.gui.FunctionOwner;
+import com.clubobsidian.dynamicgui.core.gui.Gui;
+import com.clubobsidian.dynamicgui.core.gui.Slot;
public class CopyBackMetadataFunction extends Function {
private static final long serialVersionUID = -4524513696416744522L;
- public CopyBackMetadataFunction(String name) {
- super(name);
+ public CopyBackMetadataFunction() {
+ super("copybackmetadata");
}
@Override
public boolean function(PlayerWrapper> playerWrapper) {
Gui gui = null;
FunctionOwner owner = this.getOwner();
- if(owner instanceof Slot) {
+ if (owner instanceof Slot) {
Slot slot = (Slot) owner;
gui = slot.getOwner();
- } else if(owner instanceof Gui) {
+ } else if (owner instanceof Gui) {
gui = (Gui) owner;
}
Gui back = gui.getBack();
- if(back == null) {
+ if (back == null) {
return false;
}
gui.getMetadata().putAll(back.getMetadata());
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/meta/HasMetadataFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/meta/HasMetadataFunction.java
similarity index 62%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/meta/HasMetadataFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/meta/HasMetadataFunction.java
index 21631fa72..d2b532da7 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/meta/HasMetadataFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/meta/HasMetadataFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,15 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl.meta;
-import com.clubobsidian.dynamicgui.DynamicGui;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
-import com.clubobsidian.dynamicgui.gui.FunctionOwner;
-import com.clubobsidian.dynamicgui.gui.Gui;
-import com.clubobsidian.dynamicgui.gui.Slot;
-import com.clubobsidian.dynamicgui.gui.property.MetadataHolder;
+package com.clubobsidian.dynamicgui.core.function.impl.meta;
+
+import com.clubobsidian.dynamicgui.core.DynamicGui;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import com.clubobsidian.dynamicgui.core.gui.FunctionOwner;
+import com.clubobsidian.dynamicgui.core.gui.Gui;
+import com.clubobsidian.dynamicgui.core.gui.Slot;
+import com.clubobsidian.dynamicgui.core.gui.property.MetadataHolder;
public class HasMetadataFunction extends Function {
@@ -31,15 +32,15 @@ public class HasMetadataFunction extends Function {
*/
private static final long serialVersionUID = -1651909249573158848L;
- public HasMetadataFunction(String name) {
- super(name);
+ public HasMetadataFunction() {
+ super("hasmetadata", "getmetadata");
}
@Override
public boolean function(PlayerWrapper> playerWrapper) {
- if(this.getData() == null) {
+ if (this.getData() == null) {
return false;
- } else if(!this.getData().contains(",")) {
+ } else if (!this.getData().contains(",")) {
return false;
}
@@ -49,51 +50,51 @@ public boolean function(PlayerWrapper> playerWrapper) {
String first = split[0];
Gui gui = null;
- if(owner instanceof Gui && split.length >= 2) {
- if(split.length == 2) {
+ if (owner instanceof Gui && split.length >= 2) {
+ if (split.length == 2) {
holder = (MetadataHolder) owner;
} else {
gui = (Gui) owner;
}
- } else if(owner instanceof Slot && split.length >= 2) {
- if(first.equals("gui")) {
+ } else if (owner instanceof Slot && split.length >= 2) {
+ if (first.equals("gui")) {
holder = ((Slot) this.getOwner()).getOwner();
- } else if(split.length == 2) {
+ } else if (split.length == 2) {
holder = (MetadataHolder) this.getOwner();
- } else if(split.length == 3) {
+ } else if (split.length == 3) {
gui = ((Slot) owner).getOwner();
}
}
//Check for slots
- if(holder == null) {
+ if (holder == null) {
int index = -1;
try {
index = Integer.valueOf(first);
- } catch(Exception ex) {
+ } catch (Exception ex) {
DynamicGui.get().getLogger().error("Invalid index " + first + " in HasMetadata function");
return false;
}
- for(Slot s : gui.getSlots()) {
- if(s.getIndex() == index) {
+ for (Slot s : gui.getSlots()) {
+ if (s.getIndex() == index) {
holder = s;
break;
}
}
}
- if(holder != null) {
+ if (holder != null) {
String key = null;
String value = null;
- if(split.length == 2) {
+ if (split.length == 2) {
key = split[0];
value = split[1];
- } else if(split.length == 3) {
+ } else if (split.length == 3) {
key = split[1];
value = split[2];
}
- if(key != null) {
+ if (key != null) {
String metaValue = holder.getMetadata().get(key);
return value.equals(metaValue);
}
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/meta/IsGuiMetadataSet.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/meta/IsGuiMetadataSet.java
similarity index 72%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/meta/IsGuiMetadataSet.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/meta/IsGuiMetadataSet.java
index 78a0fcd3f..bb13e22da 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/meta/IsGuiMetadataSet.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/meta/IsGuiMetadataSet.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,13 +14,13 @@
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl.meta;
+package com.clubobsidian.dynamicgui.core.function.impl.meta;
-import com.clubobsidian.dynamicgui.DynamicGui;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
-import com.clubobsidian.dynamicgui.gui.Gui;
-import com.clubobsidian.dynamicgui.gui.Slot;
+import com.clubobsidian.dynamicgui.core.DynamicGui;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import com.clubobsidian.dynamicgui.core.gui.Gui;
+import com.clubobsidian.dynamicgui.core.gui.Slot;
public class IsGuiMetadataSet extends Function {
@@ -33,9 +33,9 @@ public IsGuiMetadataSet() {
@Override
public boolean function(PlayerWrapper> playerWrapper) {
Gui gui;
- if(this.getOwner() instanceof Gui) {
+ if (this.getOwner() instanceof Gui) {
gui = (Gui) this.getOwner();
- } else if(this.getOwner() instanceof Slot) {
+ } else if (this.getOwner() instanceof Slot) {
gui = ((Slot) this.getOwner()).getOwner();
} else {
String clazzName = this.getOwner().getClass().getName();
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/meta/SetMetadataFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/meta/SetMetadataFunction.java
similarity index 62%
rename from core/src/main/java/com/clubobsidian/dynamicgui/function/impl/meta/SetMetadataFunction.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/meta/SetMetadataFunction.java
index 042a8321e..aeab27da2 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/meta/SetMetadataFunction.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/meta/SetMetadataFunction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,15 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.function.impl.meta;
-import com.clubobsidian.dynamicgui.DynamicGui;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.function.Function;
-import com.clubobsidian.dynamicgui.gui.FunctionOwner;
-import com.clubobsidian.dynamicgui.gui.Gui;
-import com.clubobsidian.dynamicgui.gui.Slot;
-import com.clubobsidian.dynamicgui.gui.property.MetadataHolder;
+package com.clubobsidian.dynamicgui.core.function.impl.meta;
+
+import com.clubobsidian.dynamicgui.core.DynamicGui;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import com.clubobsidian.dynamicgui.core.gui.FunctionOwner;
+import com.clubobsidian.dynamicgui.core.gui.Gui;
+import com.clubobsidian.dynamicgui.core.gui.Slot;
+import com.clubobsidian.dynamicgui.core.gui.property.MetadataHolder;
public class SetMetadataFunction extends Function {
@@ -31,17 +32,17 @@ public class SetMetadataFunction extends Function {
*/
private static final long serialVersionUID = -2376716466726111306L;
- public SetMetadataFunction(String name) {
- super(name);
+ public SetMetadataFunction() {
+ super("setmetadata");
}
//SetMetadata (index/gui),key,value
@Override
public boolean function(PlayerWrapper> playerWrapper) {
- if(this.getData() == null) {
+ if (this.getData() == null) {
return false;
- } else if(!this.getData().contains(",")) {
+ } else if (!this.getData().contains(",")) {
return false;
}
@@ -51,51 +52,51 @@ public boolean function(PlayerWrapper> playerWrapper) {
String first = split[0];
Gui gui = null;
- if(owner instanceof Gui && split.length >= 2) {
- if(split.length == 2) {
+ if (owner instanceof Gui && split.length >= 2) {
+ if (split.length == 2) {
holder = (MetadataHolder) owner;
} else {
gui = (Gui) owner;
}
- } else if(owner instanceof Slot && split.length >= 2) {
- if(first.equals("gui")) {
+ } else if (owner instanceof Slot && split.length >= 2) {
+ if (first.equals("gui")) {
holder = ((Slot) this.getOwner()).getOwner();
- } else if(split.length == 2) {
+ } else if (split.length == 2) {
holder = (MetadataHolder) this.getOwner();
- } else if(split.length == 3) {
+ } else if (split.length == 3) {
gui = ((Slot) owner).getOwner();
}
}
//Check for slots
- if(holder == null) {
+ if (holder == null) {
int index = -1;
try {
index = Integer.valueOf(first);
- } catch(Exception ex) {
+ } catch (Exception ex) {
DynamicGui.get().getLogger().error("Invalid index " + first + " in HasMetadata function");
return false;
}
- for(Slot s : gui.getSlots()) {
- if(s.getIndex() == index) {
+ for (Slot s : gui.getSlots()) {
+ if (s.getIndex() == index) {
holder = s;
break;
}
}
}
- if(holder != null && split.length >= 2) {
+ if (holder != null && split.length >= 2) {
String key = null;
String value = null;
- if(split.length == 2) {
+ if (split.length == 2) {
key = split[0];
value = split[1];
- } else if(split.length == 3) {
+ } else if (split.length == 3) {
key = split[1];
value = split[2];
}
- if(key != null) {
+ if (key != null) {
holder.getMetadata().put(key, value);
return true;
}
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/test/AsyncThreadFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/test/AsyncThreadFunction.java
new file mode 100644
index 000000000..ae742b51c
--- /dev/null
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/test/AsyncThreadFunction.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.core.function.impl.test;
+
+import com.clubobsidian.dynamicgui.core.DynamicGui;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+
+public class AsyncThreadFunction extends Function {
+
+ public AsyncThreadFunction() {
+ super("isasyncthread", true);
+ }
+
+ @Override
+ public boolean function(PlayerWrapper> playerWrapper) {
+ return !DynamicGui.get().getPlatform().isMainThread();
+ }
+}
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/test/FalseAsyncFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/test/FalseAsyncFunction.java
new file mode 100644
index 000000000..82476b48a
--- /dev/null
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/test/FalseAsyncFunction.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.core.function.impl.test;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+
+public class FalseAsyncFunction extends Function {
+
+ public FalseAsyncFunction() {
+ super("falseasync", true);
+ }
+
+ @Override
+ public boolean function(PlayerWrapper> playerWrapper) {
+ try {
+ Thread.sleep(5000);
+ return false;
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+}
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/test/MainThreadFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/test/MainThreadFunction.java
new file mode 100644
index 000000000..590fec5d6
--- /dev/null
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/impl/test/MainThreadFunction.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.core.function.impl.test;
+
+import com.clubobsidian.dynamicgui.core.DynamicGui;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+
+public class MainThreadFunction extends Function {
+
+ public MainThreadFunction() {
+ super("ismainthread");
+ }
+
+ @Override
+ public boolean function(PlayerWrapper> playerWrapper) {
+ return DynamicGui.get().getPlatform().isMainThread();
+ }
+}
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/gui/FunctionOwner.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/gui/FunctionOwner.java
similarity index 88%
rename from core/src/main/java/com/clubobsidian/dynamicgui/gui/FunctionOwner.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/gui/FunctionOwner.java
index d7b845159..6c289d601 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/gui/FunctionOwner.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/gui/FunctionOwner.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.gui;
+
+package com.clubobsidian.dynamicgui.core.gui;
import com.clubobsidian.dynamicgui.parser.function.tree.FunctionTree;
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/gui/Gui.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/gui/Gui.java
similarity index 63%
rename from core/src/main/java/com/clubobsidian/dynamicgui/gui/Gui.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/gui/Gui.java
index bc2d70bb1..aef7ec1c8 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/gui/Gui.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/gui/Gui.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,17 +13,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.gui;
-
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.gui.property.MetadataHolder;
-import com.clubobsidian.dynamicgui.inventory.InventoryWrapper;
-import com.clubobsidian.dynamicgui.inventory.ItemStackWrapper;
-import com.clubobsidian.dynamicgui.manager.dynamicgui.ReplacerManager;
-import com.clubobsidian.dynamicgui.manager.inventory.InventoryManager;
+
+package com.clubobsidian.dynamicgui.core.gui;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.gui.property.CloseableComponent;
+import com.clubobsidian.dynamicgui.core.gui.property.MetadataHolder;
+import com.clubobsidian.dynamicgui.core.inventory.InventoryWrapper;
+import com.clubobsidian.dynamicgui.core.inventory.ItemStackWrapper;
+import com.clubobsidian.dynamicgui.core.manager.dynamicgui.ReplacerManager;
+import com.clubobsidian.dynamicgui.core.manager.inventory.InventoryManager;
+import com.clubobsidian.dynamicgui.core.util.ChatColor;
+import com.clubobsidian.dynamicgui.core.world.LocationWrapper;
import com.clubobsidian.dynamicgui.parser.function.tree.FunctionTree;
-import com.clubobsidian.dynamicgui.util.ChatColor;
-import com.clubobsidian.dynamicgui.world.LocationWrapper;
import org.apache.commons.lang3.SerializationUtils;
import java.io.Serializable;
@@ -31,7 +33,7 @@
import java.util.Map;
-public class Gui implements Serializable, FunctionOwner, MetadataHolder {
+public class Gui implements Serializable, FunctionOwner, MetadataHolder, CloseableComponent {
/**
*
@@ -50,8 +52,12 @@ public class Gui implements Serializable, FunctionOwner, MetadataHolder {
private final FunctionTree functions;
private Gui back;
private final Map metadata;
+ private final boolean isStatic;
- public Gui(String name, String type, String title, int rows, Boolean close, ModeEnum modeEnum, Map> npcIds, List slots, List> locations, FunctionTree functions, Map metadata) {
+ public Gui(String name, String type, String title, int rows, Boolean close,
+ ModeEnum modeEnum, Map> npcIds, List slots,
+ List> locations, FunctionTree functions, Map metadata,
+ boolean isStatic) {
this.name = name;
this.type = type;
this.title = ChatColor.translateAlternateColorCodes(title);
@@ -65,32 +71,46 @@ public Gui(String name, String type, String title, int rows, Boolean close, Mode
this.functions = functions;
this.back = null;
this.metadata = metadata;
+ this.isStatic = isStatic;
}
public InventoryWrapper> buildInventory(PlayerWrapper> playerWrapper) {
+ if (this.isStatic && this.inventoryWrapper != null) { //Don't rebuild if gui is static
+ return this.inventoryWrapper;
+ }
+ String inventoryTitle = this.formatTitle(playerWrapper);
+ Object nativeInventory = this.createInventory(inventoryTitle);
+ InventoryWrapper> inventoryWrapper = InventoryManager.get().createInventoryWrapper(nativeInventory);
+ this.populateInventory(playerWrapper, inventoryWrapper);
+ this.inventoryWrapper = inventoryWrapper;
+ return inventoryWrapper;
+ }
+
+ private String formatTitle(PlayerWrapper> playerWrapper) {
String inventoryTitle = ReplacerManager.get().replace(this.title, playerWrapper);
- if(inventoryTitle.length() > 32) {
+ if (inventoryTitle.length() > 32) {
inventoryTitle = inventoryTitle.substring(0, 31);
}
+ return inventoryTitle;
+ }
- Object serverInventory = null;
- if(this.type == null || this.type.equals(InventoryType.CHEST.toString())) {
- serverInventory = InventoryManager.get().createInventory(this.rows * 9, inventoryTitle);
+ private Object createInventory(String inventoryTitle) {
+ if (this.type == null || this.type.equals(InventoryType.CHEST.toString())) {
+ return InventoryManager.get().createInventory(this.rows * 9, inventoryTitle);
} else {
- serverInventory = InventoryManager.get().createInventory(inventoryTitle, this.type);
+ return InventoryManager.get().createInventory(inventoryTitle, this.type);
}
+ }
- InventoryWrapper> inventoryWrapper = InventoryManager.get().createInventoryWrapper(serverInventory);
-
- for(int i = 0; i < this.slots.size(); i++) {
+ private void populateInventory(PlayerWrapper> playerWrapper, InventoryWrapper> inventoryWrapper) {
+ for (int i = 0; i < this.slots.size(); i++) {
Slot slot = this.slots.get(i);
- if(slot != null) {
+ if (slot != null) {
slot.setOwner(this);
ItemStackWrapper> item = slot.buildItemStack(playerWrapper);
-
- if(this.modeEnum == ModeEnum.ADD) {
+ if (this.modeEnum == ModeEnum.ADD) {
int itemIndex = inventoryWrapper.addItem(item);
- if(itemIndex != -1) {
+ if (itemIndex != -1) {
slot.setIndex(itemIndex);
}
} else {
@@ -98,9 +118,6 @@ public InventoryWrapper> buildInventory(PlayerWrapper> playerWrapper) {
}
}
}
-
- this.inventoryWrapper = inventoryWrapper;
- return inventoryWrapper;
}
public String getName() {
@@ -123,10 +140,12 @@ public List getSlots() {
return this.slots;
}
+ @Override
public Boolean getClose() {
return this.close;
}
+ @Override
public void setClose(Boolean close) {
this.close = close;
}
@@ -165,6 +184,10 @@ public void setBack(Gui back) {
this.back = back;
}
+ public boolean isStatic() {
+ return this.isStatic;
+ }
+
public Gui clone() {
return SerializationUtils.clone(this);
}
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/gui/InventoryType.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/gui/InventoryType.java
similarity index 90%
rename from core/src/main/java/com/clubobsidian/dynamicgui/gui/InventoryType.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/gui/InventoryType.java
index df2f16492..0dec21586 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/gui/InventoryType.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/gui/InventoryType.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.gui;
+
+package com.clubobsidian.dynamicgui.core.gui;
public enum InventoryType {
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/gui/InventoryView.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/gui/InventoryView.java
similarity index 86%
rename from core/src/main/java/com/clubobsidian/dynamicgui/gui/InventoryView.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/gui/InventoryView.java
index 0f5cae81a..3258c6227 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/gui/InventoryView.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/gui/InventoryView.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.gui;
+
+package com.clubobsidian.dynamicgui.core.gui;
public enum InventoryView {
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/gui/ModeEnum.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/gui/ModeEnum.java
similarity index 86%
rename from core/src/main/java/com/clubobsidian/dynamicgui/gui/ModeEnum.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/gui/ModeEnum.java
index 532d4950c..26815e41e 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/gui/ModeEnum.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/gui/ModeEnum.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.gui;
+
+package com.clubobsidian.dynamicgui.core.gui;
public enum ModeEnum {
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/gui/Slot.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/gui/Slot.java
similarity index 75%
rename from core/src/main/java/com/clubobsidian/dynamicgui/gui/Slot.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/gui/Slot.java
index ca569ca21..7e825823e 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/gui/Slot.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/gui/Slot.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,26 +13,28 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.gui;
-
-import com.clubobsidian.dynamicgui.animation.AnimationHolder;
-import com.clubobsidian.dynamicgui.enchantment.EnchantmentWrapper;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.gui.property.MetadataHolder;
-import com.clubobsidian.dynamicgui.inventory.ItemStackWrapper;
-import com.clubobsidian.dynamicgui.manager.dynamicgui.AnimationReplacerManager;
-import com.clubobsidian.dynamicgui.manager.dynamicgui.ModelManager;
-import com.clubobsidian.dynamicgui.manager.dynamicgui.ReplacerManager;
-import com.clubobsidian.dynamicgui.manager.inventory.ItemStackManager;
+
+package com.clubobsidian.dynamicgui.core.gui;
+
+import com.clubobsidian.dynamicgui.core.enchantment.EnchantmentWrapper;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.gui.property.CloseableComponent;
+import com.clubobsidian.dynamicgui.core.gui.property.MetadataHolder;
+import com.clubobsidian.dynamicgui.core.gui.property.animation.AnimationHolder;
+import com.clubobsidian.dynamicgui.core.inventory.ItemStackWrapper;
+import com.clubobsidian.dynamicgui.core.manager.dynamicgui.AnimationReplacerManager;
+import com.clubobsidian.dynamicgui.core.manager.dynamicgui.ModelManager;
+import com.clubobsidian.dynamicgui.core.manager.dynamicgui.ReplacerManager;
+import com.clubobsidian.dynamicgui.core.manager.inventory.ItemStackManager;
+import com.clubobsidian.dynamicgui.core.registry.model.ModelProvider;
import com.clubobsidian.dynamicgui.parser.function.tree.FunctionTree;
-import com.clubobsidian.dynamicgui.registry.model.ModelProvider;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
-public class Slot implements Serializable, FunctionOwner, AnimationHolder, MetadataHolder {
+public class Slot implements Serializable, FunctionOwner, AnimationHolder, MetadataHolder, CloseableComponent {
/**
*
@@ -40,6 +42,7 @@ public class Slot implements Serializable, FunctionOwner, AnimationHolder, Metad
private static final long serialVersionUID = 2366997214615469494L;
public final static String IGNORE_MATERIAL = "AIR";
+ public static final String TEST_MATERIAL = "STONE";
private int index;
private final String icon;
@@ -47,7 +50,7 @@ public class Slot implements Serializable, FunctionOwner, AnimationHolder, Metad
private final String nbt;
private final short data;
private final boolean glow;
- private boolean moveable;
+ private boolean movable;
private final List lore;
private final List enchants;
@@ -66,7 +69,7 @@ public class Slot implements Serializable, FunctionOwner, AnimationHolder, Metad
private boolean update;
public Slot(int index, int amount, String icon, String name, String nbt, short data, boolean glow,
- boolean moveable, Boolean close, List lore,
+ boolean movable, Boolean close, List lore,
List enchants, List itemFlags,
String modelProvider, String modelData,
FunctionTree functions, int updateInterval, Map metadata) {
@@ -75,7 +78,7 @@ public Slot(int index, int amount, String icon, String name, String nbt, short d
this.name = name;
this.nbt = nbt;
this.glow = glow;
- this.moveable = moveable;
+ this.movable = movable;
this.lore = lore;
this.enchants = enchants;
this.itemFlags = itemFlags;
@@ -120,12 +123,12 @@ public boolean getGlow() {
return this.glow;
}
- public boolean isMoveable() {
- return this.moveable;
+ public boolean isMovable() {
+ return this.movable;
}
- public void setMoveable(boolean moveable) {
- this.moveable = moveable;
+ public void setMovable(boolean movable) {
+ this.movable = movable;
}
public short getData() {
@@ -144,10 +147,12 @@ public List getItemFlags() {
return this.itemFlags;
}
+ @Override
public Boolean getClose() {
return this.close;
}
+ @Override
public void setClose(Boolean close) {
this.close = close;
}
@@ -160,41 +165,41 @@ public FunctionTree getFunctions() {
public ItemStackWrapper> buildItemStack(PlayerWrapper> playerWrapper) {
ItemStackWrapper> builderItem = this.itemStack;
- if(builderItem == null) {
+ if (builderItem == null) {
builderItem = ItemStackManager.get().createItemStackWrapper(this.icon, this.amount);
} else {
builderItem.setType(this.icon);
builderItem.setAmount(this.amount);
}
- if(!this.icon.toUpperCase().equals(IGNORE_MATERIAL)) {
- if(this.data != 0) {
+ if (!this.icon.equalsIgnoreCase(IGNORE_MATERIAL)) {
+ if (this.data != 0) {
builderItem.setDurability(this.data);
}
- if(this.modelProvider != null && this.modelData != null) {
+ if (this.modelProvider != null && this.modelData != null) {
ModelProvider provider = ModelManager.get().getProvider(this.modelProvider);
- if(provider != null) {
+ if (provider != null) {
provider.applyModel(builderItem, this.modelData);
}
}
- if(this.name != null) {
+ if (this.name != null) {
String newName = this.name;
newName = ReplacerManager.get().replace(newName, playerWrapper);
newName = AnimationReplacerManager.get().replace(this, playerWrapper, newName);
builderItem.setName(newName);
}
- if(this.lore != null) {
+ if (this.lore != null) {
List newLore = new ArrayList<>();
- for(String newString : this.lore) {
+ for (String newString : this.lore) {
String lore = ReplacerManager.get().replace(newString, playerWrapper);
lore = AnimationReplacerManager.get().replace(this, playerWrapper, lore);
- if(lore.contains("\n")) {
+ if (lore.contains("\n")) {
String[] split = lore.split("\n");
- for(String sp : split) {
+ for (String sp : split) {
newLore.add(sp);
}
} else {
@@ -205,19 +210,19 @@ public ItemStackWrapper> buildItemStack(PlayerWrapper> playerWrapper) {
builderItem.setLore(newLore);
}
- if(this.enchants != null) {
- for(EnchantmentWrapper ench : this.enchants) {
+ if (this.enchants != null) {
+ for (EnchantmentWrapper ench : this.enchants) {
builderItem.addEnchant(ench);
}
}
builderItem.addItemFlags(this.itemFlags);
- if(this.glow) {
+ if (this.glow) {
builderItem.setGlowing(true);
}
- if(this.nbt != null && !this.nbt.equals("")) {
+ if (this.nbt != null && !this.nbt.equals("")) {
builderItem.setNBT(ReplacerManager.get().replace(this.nbt, playerWrapper));
}
}
@@ -257,14 +262,14 @@ public void resetTick() {
public int tick() {
this.tick += 1;
- if((this.tick) % 20 == 0) {
+ if ((this.tick) % 20 == 0) {
this.frame += 1;
//Reset frame
- if(this.tick == Integer.MAX_VALUE) {
+ if (this.tick == Integer.MAX_VALUE) {
this.tick = 0;
}
- if(this.frame == Integer.MAX_VALUE) {
+ if (this.frame == Integer.MAX_VALUE) {
this.frame = 0;
}
}
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/proxy/Proxy.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/gui/property/CloseableComponent.java
similarity index 74%
rename from core/src/main/java/com/clubobsidian/dynamicgui/proxy/Proxy.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/gui/property/CloseableComponent.java
index 735bfc7c0..b7bc71157 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/proxy/Proxy.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/gui/property/CloseableComponent.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,12 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.proxy;
-public enum Proxy {
+package com.clubobsidian.dynamicgui.core.gui.property;
- BUNGEECORD,
- REDIS_BUNGEE,
- NONE
+public interface CloseableComponent {
+
+ Boolean getClose();
+
+ void setClose(Boolean close);
}
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/gui/property/MetadataHolder.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/gui/property/MetadataHolder.java
similarity index 86%
rename from core/src/main/java/com/clubobsidian/dynamicgui/gui/property/MetadataHolder.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/gui/property/MetadataHolder.java
index 161c3b52c..abc21fdb4 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/gui/property/MetadataHolder.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/gui/property/MetadataHolder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.gui.property;
+package com.clubobsidian.dynamicgui.core.gui.property;
import java.util.Map;
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/animation/AnimationHolder.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/gui/property/animation/AnimationHolder.java
similarity index 86%
rename from core/src/main/java/com/clubobsidian/dynamicgui/animation/AnimationHolder.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/gui/property/animation/AnimationHolder.java
index 24e42df0f..5933c73a8 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/animation/AnimationHolder.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/gui/property/animation/AnimationHolder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.animation;
+
+package com.clubobsidian.dynamicgui.core.gui.property.animation;
public interface AnimationHolder extends Refreshable {
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/animation/Refreshable.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/gui/property/animation/Refreshable.java
similarity index 84%
rename from core/src/main/java/com/clubobsidian/dynamicgui/animation/Refreshable.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/gui/property/animation/Refreshable.java
index 836e0f49c..895e4d4fa 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/animation/Refreshable.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/gui/property/animation/Refreshable.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.animation;
+
+package com.clubobsidian.dynamicgui.core.gui.property.animation;
public interface Refreshable {
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/inject/module/PluginModule.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/inject/module/PluginModule.java
new file mode 100644
index 000000000..b9c25e185
--- /dev/null
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/inject/module/PluginModule.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.core.inject.module;
+
+import cloud.commandframework.CommandManager;
+import com.clubobsidian.dynamicgui.core.DynamicGui;
+import com.clubobsidian.dynamicgui.core.Constant;
+import com.clubobsidian.dynamicgui.core.command.CommandRegistrar;
+import com.clubobsidian.dynamicgui.core.command.CommandRegistrarImpl;
+import com.clubobsidian.dynamicgui.core.command.DynamicGuiCommand;
+import com.clubobsidian.dynamicgui.core.command.GuiCommand;
+import com.clubobsidian.dynamicgui.core.command.GuiCommandSender;
+import com.clubobsidian.dynamicgui.core.command.cloud.CloudExtender;
+import com.clubobsidian.dynamicgui.core.command.cloud.extender.CombinedCloudExtender;
+import com.clubobsidian.dynamicgui.core.command.cloud.extender.CoreCloudExtender;
+import com.clubobsidian.dynamicgui.core.logger.LoggerWrapper;
+import com.clubobsidian.dynamicgui.core.manager.dynamicgui.GuiManager;
+import com.clubobsidian.dynamicgui.core.manager.entity.EntityManager;
+import com.clubobsidian.dynamicgui.core.manager.inventory.InventoryManager;
+import com.clubobsidian.dynamicgui.core.manager.inventory.ItemStackManager;
+import com.clubobsidian.dynamicgui.core.manager.material.MaterialManager;
+import com.clubobsidian.dynamicgui.core.manager.world.LocationManager;
+import com.clubobsidian.dynamicgui.core.platform.Platform;
+import com.clubobsidian.dynamicgui.core.plugin.DynamicGuiPlugin;
+import com.google.inject.Binder;
+import com.google.inject.Guice;
+import com.google.inject.Module;
+import com.google.inject.TypeLiteral;
+import com.google.inject.name.Names;
+
+public abstract class PluginModule implements Module {
+
+ private final Class extends EntityManager> entityClass = this.getEntityManager();
+ private final Class extends InventoryManager> inventoryClass = this.getInventoryManager();
+ private final Class extends ItemStackManager> itemStackClass = this.getItemStackManager();
+ private final Class extends MaterialManager> materialClass = this.getMaterialManager();
+ private final Class extends LocationManager> locationClass = this.getLocationManger();
+ private final DynamicGuiPlugin plugin;
+ private final Platform platform;
+ private final LoggerWrapper> logger;
+ private final CommandManager commandManager;
+
+ public PluginModule(DynamicGuiPlugin plugin,
+ Platform platform,
+ LoggerWrapper> logger,
+ CommandManager commandManager) {
+ this.plugin = plugin;
+ this.platform = platform;
+ this.logger = logger;
+ this.commandManager = commandManager;
+ }
+
+ public abstract Class extends EntityManager> getEntityManager();
+
+ public abstract Class extends InventoryManager> getInventoryManager();
+
+ public abstract Class extends ItemStackManager> getItemStackManager();
+
+ public abstract Class extends MaterialManager> getMaterialManager();
+
+ public abstract Class extends LocationManager> getLocationManger();
+
+ public abstract Class extends CloudExtender> getPlatformExtender();
+
+ @Override
+ public void configure(Binder binder) {
+ binder.bind(new TypeLiteral>() {}).toInstance(this.logger);
+
+ binder.bind(new TypeLiteral>(){}).toInstance(this.commandManager);
+ binder.bind(CloudExtender.class).annotatedWith(Names.named(Constant.NATIVE_ANNOTATION)).to(CoreCloudExtender.class);
+ binder.bind(CloudExtender.class).annotatedWith(Names.named(Constant.PLATFORM_ANNOTATION)).to(this.getPlatformExtender());
+ binder.bind(CloudExtender.class).to(CombinedCloudExtender.class);
+ binder.bind(CommandRegistrar.class).to(CommandRegistrarImpl.class).asEagerSingleton();
+
+ binder.bind(EntityManager.class).to(this.entityClass);
+ binder.bind(InventoryManager.class).to(this.inventoryClass);
+ binder.bind(ItemStackManager.class).to(this.itemStackClass);
+ binder.bind(MaterialManager.class).to(this.materialClass);
+ binder.bind(LocationManager.class).to(this.locationClass);
+ binder.bind(DynamicGuiPlugin.class).toInstance(this.plugin);
+ binder.bind(Platform.class).toInstance(this.platform);
+
+ binder.bind(GuiManager.class);
+
+ binder.bind(GuiCommand.class).asEagerSingleton();
+ binder.bind(DynamicGuiCommand.class).asEagerSingleton();
+
+ binder.requestStaticInjection(EntityManager.class);
+ binder.requestStaticInjection(InventoryManager.class);
+ binder.requestStaticInjection(ItemStackManager.class);
+ binder.requestStaticInjection(MaterialManager.class);
+ binder.requestStaticInjection(LocationManager.class);
+ binder.requestStaticInjection(GuiManager.class);
+ binder.requestStaticInjection(DynamicGui.class);
+ }
+
+ public boolean bootstrap() {
+ Guice.createInjector(this);
+ return DynamicGui.get().start();
+ }
+}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/registry/package-info.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/inject/package-info.java
similarity index 85%
rename from core/src/main/java/com/clubobsidian/dynamicgui/registry/package-info.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/inject/package-info.java
index 49dcf80db..87fd819fd 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/registry/package-info.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/inject/package-info.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,4 +13,5 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.registry;
+
+package com.clubobsidian.dynamicgui.core.inject;
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/inventory/InventoryWrapper.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/inventory/InventoryWrapper.java
similarity index 86%
rename from core/src/main/java/com/clubobsidian/dynamicgui/inventory/InventoryWrapper.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/inventory/InventoryWrapper.java
index 0b231e785..dabbe821b 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/inventory/InventoryWrapper.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/inventory/InventoryWrapper.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,9 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.inventory;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
+package com.clubobsidian.dynamicgui.core.inventory;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
import java.io.Serializable;
@@ -50,7 +51,7 @@ public T getInventory() {
public int addItem(ItemStackWrapper> itemStackWrapper) {
int index = this.getCurrentContentSize();
- if(index >= this.getSize())
+ if (index >= this.getSize())
return -1;
this.setItem(index, itemStackWrapper);
@@ -59,9 +60,9 @@ public int addItem(ItemStackWrapper> itemStackWrapper) {
@Override
public boolean equals(Object obj) {
- if(obj == null)
+ if (obj == null)
return false;
- if(!(obj instanceof InventoryWrapper))
+ if (!(obj instanceof InventoryWrapper))
return false;
InventoryWrapper> wrapper = (InventoryWrapper>) obj;
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/inventory/ItemStackWrapper.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/inventory/ItemStackWrapper.java
similarity index 92%
rename from core/src/main/java/com/clubobsidian/dynamicgui/inventory/ItemStackWrapper.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/inventory/ItemStackWrapper.java
index db6edb97d..628fcd267 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/inventory/ItemStackWrapper.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/inventory/ItemStackWrapper.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,9 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.inventory;
-import com.clubobsidian.dynamicgui.enchantment.EnchantmentWrapper;
+package com.clubobsidian.dynamicgui.core.inventory;
+
+import com.clubobsidian.dynamicgui.core.enchantment.EnchantmentWrapper;
import java.io.Serializable;
import java.util.List;
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/listener/EntityClickListener.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/listener/EntityClickListener.java
similarity index 59%
rename from core/src/main/java/com/clubobsidian/dynamicgui/listener/EntityClickListener.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/listener/EntityClickListener.java
index c86e5e821..753502da0 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/listener/EntityClickListener.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/listener/EntityClickListener.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,15 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.listener;
-import com.clubobsidian.dynamicgui.DynamicGui;
-import com.clubobsidian.dynamicgui.entity.EntityWrapper;
-import com.clubobsidian.dynamicgui.event.inventory.PlayerInteractEntityEvent;
-import com.clubobsidian.dynamicgui.gui.Gui;
-import com.clubobsidian.dynamicgui.manager.dynamicgui.GuiManager;
-import com.clubobsidian.dynamicgui.registry.npc.NPC;
-import com.clubobsidian.dynamicgui.registry.npc.NPCRegistry;
+package com.clubobsidian.dynamicgui.core.listener;
+
+import com.clubobsidian.dynamicgui.core.DynamicGui;
+import com.clubobsidian.dynamicgui.core.entity.EntityWrapper;
+import com.clubobsidian.dynamicgui.core.event.inventory.PlayerInteractEntityEvent;
+import com.clubobsidian.dynamicgui.core.gui.Gui;
+import com.clubobsidian.dynamicgui.core.manager.dynamicgui.GuiManager;
+import com.clubobsidian.dynamicgui.core.registry.npc.NPC;
+import com.clubobsidian.dynamicgui.core.registry.npc.NPCRegistry;
import com.clubobsidian.trident.EventHandler;
import java.util.Iterator;
@@ -32,23 +33,24 @@ public class EntityClickListener {
@EventHandler
public void onEntityClick(PlayerInteractEntityEvent e) {
- if(GuiManager.get().hasGuiCurrently(e.getPlayerWrapper()))
+ if (GuiManager.get().hasGuiCurrently(e.getPlayerWrapper())) {
return;
+ }
EntityWrapper> entityWrapper = e.getEntityWrapper();
- List registeries = DynamicGui.get().getPlugin().getNPCRegistries();
- for(NPCRegistry registry : registeries) {
- for(Gui gui : GuiManager.get().getGuis()) {
+ List registries = DynamicGui.get().getPlugin().getNPCRegistries();
+ for (NPCRegistry registry : registries) {
+ for (Gui gui : GuiManager.get().getGuis()) {
Iterator>> it = gui.getNpcIds().entrySet().iterator();
- while(it.hasNext()) {
+ while (it.hasNext()) {
Entry> next = it.next();
String registryName = next.getKey();
List ids = next.getValue();
- if(registryName.equalsIgnoreCase(registry.getName())) {
+ if (registryName.equalsIgnoreCase(registry.getName())) {
NPC npc = registry.getNPC(entityWrapper);
- if(npc != null) {
- if(ids.contains(npc.getMeta().getId())) {
+ if (npc != null) {
+ if (ids.contains(npc.getMeta().getId())) {
GuiManager.get().openGui(e.getPlayerWrapper(), gui);
break;
}
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/listener/GuiListener.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/listener/GuiListener.java
new file mode 100644
index 000000000..f7b2f603e
--- /dev/null
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/listener/GuiListener.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.core.listener;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.event.inventory.GuiLoadEvent;
+import com.clubobsidian.dynamicgui.core.event.inventory.GuiSwitchEvent;
+import com.clubobsidian.dynamicgui.core.event.inventory.InventoryCloseEvent;
+import com.clubobsidian.dynamicgui.core.gui.Gui;
+import com.clubobsidian.dynamicgui.core.manager.dynamicgui.FunctionManager;
+import com.clubobsidian.dynamicgui.core.manager.dynamicgui.GuiManager;
+import com.clubobsidian.dynamicgui.parser.function.FunctionType;
+import com.clubobsidian.trident.EventHandler;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.UUID;
+
+public class GuiListener {
+
+ private final Set users = new HashSet<>();
+
+ @EventHandler
+ public void onGuiSwitch(GuiSwitchEvent event) {
+ Gui gui = event.getSwitchFrom();
+ PlayerWrapper> playerWrapper = event.getPlayerWrapper();
+ FunctionManager.get().tryFunctions(gui, FunctionType.SWITCH_MENU, playerWrapper);
+ this.users.add(playerWrapper.getUniqueId());
+ }
+
+ @EventHandler
+ public void onClose(InventoryCloseEvent event) {
+ PlayerWrapper> playerWrapper = event.getPlayerWrapper();
+ UUID uuid = playerWrapper.getUniqueId();
+ if (!this.users.remove(uuid)) {
+ Gui gui = GuiManager.get().getPlayerGui(playerWrapper);
+ if (gui != null) {
+ FunctionManager.get().tryFunctions(gui, FunctionType.EXIT_MENU, playerWrapper);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/listener/InventoryCloseListener.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/listener/InventoryCloseListener.java
similarity index 69%
rename from core/src/main/java/com/clubobsidian/dynamicgui/listener/InventoryCloseListener.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/listener/InventoryCloseListener.java
index 4250ced2d..800c5de08 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/listener/InventoryCloseListener.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/listener/InventoryCloseListener.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,13 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.listener;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.event.inventory.InventoryCloseEvent;
-import com.clubobsidian.dynamicgui.event.player.PlayerKickEvent;
-import com.clubobsidian.dynamicgui.event.player.PlayerQuitEvent;
-import com.clubobsidian.dynamicgui.manager.dynamicgui.GuiManager;
+package com.clubobsidian.dynamicgui.core.listener;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.event.inventory.InventoryCloseEvent;
+import com.clubobsidian.dynamicgui.core.event.player.PlayerKickEvent;
+import com.clubobsidian.dynamicgui.core.event.player.PlayerQuitEvent;
+import com.clubobsidian.dynamicgui.core.manager.dynamicgui.GuiManager;
import com.clubobsidian.trident.EventHandler;
import com.clubobsidian.trident.EventPriority;
@@ -41,8 +42,8 @@ public void onKick(final PlayerKickEvent e) {
}
private void handleInventoryClose(PlayerWrapper> playerWrapper) {
- if(GuiManager.get().hasGuiCurrently(playerWrapper)) {
- GuiManager.get().cleanupGui(playerWrapper);
+ if (GuiManager.get().hasGuiCurrently(playerWrapper)) {
+ GuiManager.get().cleanupPlayerGui(playerWrapper);
}
}
}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/listener/InventoryInteractListener.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/listener/InventoryInteractListener.java
new file mode 100644
index 000000000..9ede24472
--- /dev/null
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/listener/InventoryInteractListener.java
@@ -0,0 +1,157 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.core.listener;
+
+import com.clubobsidian.dynamicgui.core.DynamicGui;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.event.inventory.Click;
+import com.clubobsidian.dynamicgui.core.event.inventory.InventoryClickEvent;
+import com.clubobsidian.dynamicgui.core.event.inventory.InventoryDragEvent;
+import com.clubobsidian.dynamicgui.core.gui.Gui;
+import com.clubobsidian.dynamicgui.core.gui.InventoryView;
+import com.clubobsidian.dynamicgui.core.gui.Slot;
+import com.clubobsidian.dynamicgui.core.inventory.InventoryWrapper;
+import com.clubobsidian.dynamicgui.core.inventory.ItemStackWrapper;
+import com.clubobsidian.dynamicgui.core.manager.dynamicgui.FunctionManager;
+import com.clubobsidian.dynamicgui.core.manager.dynamicgui.GuiManager;
+import com.clubobsidian.dynamicgui.core.platform.Platform;
+import com.clubobsidian.dynamicgui.parser.function.FunctionType;
+import com.clubobsidian.dynamicgui.parser.function.tree.FunctionNode;
+import com.clubobsidian.trident.EventHandler;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map.Entry;
+
+public class InventoryInteractListener {
+
+ @EventHandler
+ public void invClick(final InventoryClickEvent e) {
+ PlayerWrapper> player = e.getPlayerWrapper();
+ if (!GuiManager.get().hasGuiOpen(player)) {
+ return;
+ }
+
+ Gui gui = GuiManager.get().getPlayerGui(player);
+
+ Slot slot = this.getSlotFromIndex(gui, e.getSlot());
+ if (slot == null && e.getView() != InventoryView.BOTTOM) {
+ this.cancelClick(e);
+ return;
+ }
+
+ ItemStackWrapper> item = e.getItemStackWrapper();
+ if (e.getClick() == null) { //For other types of clicks besides left, right, middle
+ this.cancelClick(e);
+ return;
+ } else if (item.getItemStack() == null) {
+ return;
+ } else if (e.getView() == InventoryView.BOTTOM) {
+ if (e.getClick() == Click.SHIFT_LEFT || e.getClick() == Click.SHIFT_RIGHT) {
+ if (!this.canStack(gui, e.getInventoryWrapper(), item)) {
+ this.cancelClick(e);
+ }
+ }
+ return;
+ }
+
+ List functions = slot.getFunctions().getRootNodes();
+ if (functions.size() > 0) {
+ String clickString = e.getClick().toString();
+ FunctionManager.get().tryFunctions(slot, FunctionType.valueOf(clickString), player);
+ }
+
+ if (!slot.isMovable()) {
+ this.cancelClick(e);
+ }
+
+ boolean close = slot.getClose() != null ? slot.getClose() : (gui.getClose() != null ? gui.getClose() : true);
+ if (close) {
+ player.closeInventory();
+ }
+ }
+
+ private void cancelClick(InventoryClickEvent e) {
+ e.setCancelled(true);
+ Platform platform = DynamicGui.get().getPlatform();
+ platform.getScheduler().runSyncDelayedTask(() -> {
+ PlayerWrapper> futurePlayer = platform.getPlayer(e.getPlayerWrapper().getUniqueId());
+ if (futurePlayer != null) {
+ futurePlayer.updateCursor();
+ }
+ }, 1);
+ }
+
+ @EventHandler
+ public void onDrag(InventoryDragEvent e) {
+ PlayerWrapper> player = e.getPlayerWrapper();
+ if (!GuiManager.get().hasGuiOpen(player)) {
+ return;
+ }
+
+ Gui gui = GuiManager.get().getPlayerGui(player);
+
+ Iterator>> it = e.getSlotItems().entrySet().iterator();
+ while (it.hasNext()) {
+ Entry> next = it.next();
+ int rawSlot = next.getKey();
+ if (rawSlot < 0 || rawSlot >= e.getInventoryWrapper().getSize()) {
+ return;
+ }
+
+ Slot slot = this.getSlotFromIndex(gui, rawSlot);
+ if (slot == null || (slot != null && !slot.isMovable())) {
+ e.setCancelled(true);
+ return;
+ }
+ }
+ }
+
+ private Slot getSlotFromIndex(Gui gui, int index) {
+ for (Slot s : gui.getSlots()) {
+ if (index == s.getIndex()) {
+ return s;
+ }
+ }
+
+ return null;
+ }
+
+ private boolean canStack(Gui gui, InventoryWrapper> inventory, ItemStackWrapper> clickedItem) {
+ boolean canStack = false;
+ ItemStackWrapper>[] contents = inventory.getContents();
+ for (int i = 0; i < contents.length; i++) {
+ ItemStackWrapper> stackTo = contents[i];
+ if (stackTo.getItemStack() == null || (stackTo.isSimilar(clickedItem) && validSize(clickedItem, stackTo))) {
+ Slot slot = this.getSlotFromIndex(gui, i);
+ if (slot != null) {
+ if (slot.isMovable()) {
+ canStack = true;
+ } else if (canStack && !slot.isMovable()) {
+ canStack = false;
+ }
+ }
+ }
+ }
+
+ return canStack;
+ }
+
+ private boolean validSize(ItemStackWrapper> clickedItem, ItemStackWrapper> stackTo) {
+ return stackTo.getAmount() + clickedItem.getAmount() <= clickedItem.getMaxStackSize();
+ }
+}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/listener/PlayerInteractListener.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/listener/PlayerInteractListener.java
similarity index 56%
rename from core/src/main/java/com/clubobsidian/dynamicgui/listener/PlayerInteractListener.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/listener/PlayerInteractListener.java
index 8beae8122..08b4ea816 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/listener/PlayerInteractListener.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/listener/PlayerInteractListener.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,28 +13,28 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.listener;
-import com.clubobsidian.dynamicgui.event.block.PlayerInteractEvent;
-import com.clubobsidian.dynamicgui.event.player.Action;
-import com.clubobsidian.dynamicgui.gui.Gui;
-import com.clubobsidian.dynamicgui.manager.dynamicgui.GuiManager;
-import com.clubobsidian.dynamicgui.world.LocationWrapper;
+package com.clubobsidian.dynamicgui.core.listener;
+
+import com.clubobsidian.dynamicgui.core.event.block.PlayerInteractEvent;
+import com.clubobsidian.dynamicgui.core.gui.Gui;
+import com.clubobsidian.dynamicgui.core.manager.dynamicgui.GuiManager;
+import com.clubobsidian.dynamicgui.core.world.LocationWrapper;
import com.clubobsidian.trident.EventHandler;
public class PlayerInteractListener {
@EventHandler
public void playerInteract(final PlayerInteractEvent e) {
- if(e.getAction() == Action.RIGHT_CLICK_BLOCK || e.getAction() == Action.LEFT_CLICK_BLOCK) {
- if(GuiManager.get().hasGuiCurrently(e.getPlayerWrapper())) {
+ if (e.getAction().isBlockClick()) {
+ if (GuiManager.get().hasGuiCurrently(e.getPlayerWrapper())) {
return;
}
- for(Gui gui : GuiManager.get().getGuis()) {
- if(gui.getLocations() != null) {
- for(LocationWrapper> guiLocation : gui.getLocations()) {
- if(e.getLocationWrapper().equals(guiLocation)) {
+ for (Gui gui : GuiManager.get().getGuis()) {
+ if (gui.getLocations() != null) {
+ for (LocationWrapper> guiLocation : gui.getLocations()) {
+ if (e.getLocationWrapper().equals(guiLocation)) {
GuiManager.get().openGui(e.getPlayerWrapper(), gui);
e.setCancelled(true);
break;
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/logger/JavaLoggerWrapper.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/logger/JavaLoggerWrapper.java
similarity index 91%
rename from core/src/main/java/com/clubobsidian/dynamicgui/logger/JavaLoggerWrapper.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/logger/JavaLoggerWrapper.java
index f041742ae..b204c0552 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/logger/JavaLoggerWrapper.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/logger/JavaLoggerWrapper.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.logger;
+
+package com.clubobsidian.dynamicgui.core.logger;
import java.util.logging.Level;
import java.util.logging.Logger;
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/logger/LoggerWrapper.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/logger/LoggerWrapper.java
similarity index 89%
rename from core/src/main/java/com/clubobsidian/dynamicgui/logger/LoggerWrapper.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/logger/LoggerWrapper.java
index 3d8260dec..c7020e37c 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/logger/LoggerWrapper.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/logger/LoggerWrapper.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.logger;
+
+package com.clubobsidian.dynamicgui.core.logger;
public abstract class LoggerWrapper {
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/manager/dynamicgui/AnimationReplacerManager.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/manager/dynamicgui/AnimationReplacerManager.java
similarity index 76%
rename from core/src/main/java/com/clubobsidian/dynamicgui/manager/dynamicgui/AnimationReplacerManager.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/manager/dynamicgui/AnimationReplacerManager.java
index c057d5680..4bf98414a 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/manager/dynamicgui/AnimationReplacerManager.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/manager/dynamicgui/AnimationReplacerManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.manager.dynamicgui;
-import com.clubobsidian.dynamicgui.animation.AnimationHolder;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.registry.replacer.AnimationReplacerRegistry;
+package com.clubobsidian.dynamicgui.core.manager.dynamicgui;
+
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.gui.property.animation.AnimationHolder;
+import com.clubobsidian.dynamicgui.core.registry.replacer.AnimationReplacerRegistry;
import java.util.ArrayList;
import java.util.List;
@@ -33,7 +34,7 @@ private AnimationReplacerManager() {
}
public static AnimationReplacerManager get() {
- if(instance == null) {
+ if (instance == null) {
instance = new AnimationReplacerManager();
}
return instance;
@@ -41,7 +42,7 @@ public static AnimationReplacerManager get() {
public String replace(AnimationHolder holder, PlayerWrapper> playerWrapper, String text) {
String newText = text;
- for(AnimationReplacerRegistry registry : this.registries) {
+ for (AnimationReplacerRegistry registry : this.registries) {
newText = registry.replace(holder, playerWrapper, newText);
}
return newText;
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/manager/dynamicgui/FunctionManager.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/manager/dynamicgui/FunctionManager.java
new file mode 100644
index 000000000..f51276c94
--- /dev/null
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/manager/dynamicgui/FunctionManager.java
@@ -0,0 +1,330 @@
+/*
+ * Copyright 2022 virustotalop and contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.clubobsidian.dynamicgui.core.manager.dynamicgui;
+
+import com.clubobsidian.dynamicgui.core.DynamicGui;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.function.Function;
+import com.clubobsidian.dynamicgui.core.gui.FunctionOwner;
+import com.clubobsidian.dynamicgui.core.util.ThreadUtil;
+import com.clubobsidian.dynamicgui.parser.function.FunctionData;
+import com.clubobsidian.dynamicgui.parser.function.FunctionModifier;
+import com.clubobsidian.dynamicgui.parser.function.FunctionToken;
+import com.clubobsidian.dynamicgui.parser.function.FunctionType;
+import com.clubobsidian.dynamicgui.parser.function.tree.FunctionNode;
+import com.clubobsidian.fuzzutil.StringFuzz;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class FunctionManager {
+
+ private static FunctionManager instance;
+
+ public static FunctionManager get() {
+ if (instance == null) {
+ instance = new FunctionManager();
+ }
+ return instance;
+ }
+
+ private final Map functions = new HashMap<>();
+ private final Map> runningAsyncFunctions = new ConcurrentHashMap<>();
+
+ private FunctionManager() {
+ }
+
+ public Function getFunctionByName(String functionName) {
+ String normalized = StringFuzz.normalize(functionName);
+ Function function = this.functions.get(normalized);
+ if (function == null) {
+ return null;
+ }
+ return function.clone();
+ }
+
+ public List getFunctions() {
+ return new ArrayList<>(this.functions.values());
+ }
+
+ public boolean addFunction(Function function) {
+ boolean wasNotNull = this.functions.put(function.getName(), function) != null;
+ for (String alias : function.getAliases()) {
+ if (this.functions.put(alias, function) != null) {
+ wasNotNull = true;
+ }
+ }
+ return wasNotNull;
+ }
+
+ public boolean removeFunctionByName(String functionName) {
+ String normalized = StringFuzz.normalize(functionName);
+ return this.functions.remove(normalized) != null;
+ }
+
+ public boolean hasAsyncFunctionRunning(PlayerWrapper> playerWrapper) {
+ return this.hasAsyncFunctionRunning(playerWrapper.getUniqueId());
+ }
+
+ public boolean hasAsyncFunctionRunning(UUID uuid) {
+ Map running = this.runningAsyncFunctions.get(uuid);
+ return running != null && running.size() > 0;
+ }
+
+ public boolean hasAsyncFunctionRunning(PlayerWrapper> playerWrapper, String functionName) {
+ return this.hasAsyncFunctionRunning(playerWrapper.getUniqueId(), functionName);
+ }
+
+ public boolean hasAsyncFunctionRunning(UUID uuid, String functionName) {
+ Function function = this.functions.get(functionName);
+ Map functionMap = this.runningAsyncFunctions.get(uuid);
+ AtomicInteger num = functionMap == null ? null : functionMap.get(function);
+ return function != null
+ && function.isAsync()
+ && functionMap != null
+ && num != null
+ && num.get() != 0;
+ }
+
+ public CompletableFuture tryFunctions(FunctionOwner owner, FunctionType type, PlayerWrapper> playerWrapper) {
+ CompletableFuture future = new CompletableFuture<>();
+ future.exceptionally((ex) -> {
+ ex.printStackTrace();
+ return null;
+ });
+ List rootNodes = owner.getFunctions().getRootNodes();
+ recurFunctionNodes(null,
+ owner,
+ rootNodes,
+ type,
+ playerWrapper,
+ future,
+ new AtomicBoolean(true));
+ return future;
+ }
+
+ private void recurFunctionNodes(FunctionResponse response,
+ FunctionOwner owner,
+ List functionNodes,
+ FunctionType type,
+ PlayerWrapper> playerWrapper,
+ CompletableFuture future,
+ AtomicBoolean returnValue) {
+ if (functionNodes.size() == 0 || !hasFunctionType(functionNodes, type)) {
+ future.complete(returnValue.get());
+ }
+ boolean foundFail = false;
+ for (int i = 0 ; i < functionNodes.size(); i++) {
+ FunctionNode node = functionNodes.get(i);
+ FunctionToken functionToken = node.getToken();
+ List types = functionToken.getTypes();
+ if (types.contains(type) || (type.isClick() && types.contains(FunctionType.CLICK))) {
+ if (type != FunctionType.FAIL) {
+ runFunctionData(owner, functionToken.getFunctions(), playerWrapper)
+ .whenComplete((dataResponse, ex) -> {
+ if (ex != null) {
+ ex.printStackTrace();
+ future.complete(false);
+ } else {
+ if (!dataResponse.result) {
+ if (dataResponse.failedFunction == null) {
+ future.complete(false);
+ } else {
+ returnValue.set(false);
+ recurFunctionNodes(dataResponse, owner,
+ node.getChildren(), FunctionType.FAIL,
+ playerWrapper, future, returnValue);
+ }
+ } else {
+ recurFunctionNodes(dataResponse, owner,
+ node.getChildren(), type,
+ playerWrapper, future, returnValue);
+ }
+ }
+ });
+ } else {
+ if (isFail(response, functionToken)) {
+ foundFail = true;
+ runFunctionData(owner, functionToken.getFunctions(), playerWrapper)
+ .whenComplete((dataResponse, ex) -> {
+ if (ex != null) {
+ ex.printStackTrace();
+ future.complete(false);
+ } else {
+ recurFunctionNodes(dataResponse, owner,
+ node.getChildren(), FunctionType.FAIL,
+ playerWrapper, future, returnValue);
+ }
+ });
+ } else if(i == functionNodes.size() - 1 && !foundFail) {
+ future.complete(returnValue.get());
+ }
+ }
+ }
+ }
+ }
+
+ private boolean hasFunctionType(Collection nodes, FunctionType type) {
+ for (FunctionNode node : nodes) {
+ if (node.getToken().getTypes().contains(type)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private CompletableFuture runFunctionData(FunctionOwner owner, List functionDataList, PlayerWrapper> playerWrapper) {
+ UUID uuid = playerWrapper.getUniqueId();
+ CompletableFuture response = new CompletableFuture<>();
+ response.exceptionally((ex) -> {
+ ex.printStackTrace();
+ return null;
+ });
+ ThreadUtil.run(() -> {
+ for (int i = 0; i < functionDataList.size(); i++) {
+ FunctionData data = functionDataList.get(i);
+ String functionName = data.getName();
+ String functionData = data.getData();
+ Function function = FunctionManager.get().getFunctionByName(functionName);
+ if (function == null) {
+ DynamicGui.get().getLogger().error("Invalid function " + data.getName());
+ response.complete(new FunctionResponse(false));
+ return;
+ }
+ function.setOwner(owner);
+
+ if (data.getData() != null) {
+ String newData = ReplacerManager.get().replace(functionData, playerWrapper);
+ function.setData(newData);
+ }
+
+ boolean async = function.isAsync();
+ List futureData = async ? new ArrayList<>(functionDataList.size()) : functionDataList;
+ if (async) { //Load functions into new arraylist if the function is async
+ for (int j = i + 1; j < functionDataList.size(); j++) {
+ futureData.add(functionDataList.get(j));
+ }
+ }
+ ThreadUtil.run(() -> {
+ if (async) {
+ this.runningAsyncFunctions.compute(uuid, (key, value) -> {
+ if (value == null) {
+ return new ConcurrentHashMap<>();
+ }
+ return value;
+ }).compute(function, (key, value) -> {
+ if (value != null) {
+ value.incrementAndGet();
+ } else {
+ value = new AtomicInteger(1);
+ }
+ return value;
+ });
+ }
+ boolean ran = false;
+ try {
+ ran = function.function(playerWrapper);
+ } catch (Exception e) {
+ e.printStackTrace();
+ response.complete(new FunctionResponse(false, functionName, functionData));
+ }
+ if (data.getModifier() == FunctionModifier.NOT) {
+ ran = !ran;
+ }
+ if (!ran) {
+ cleanupAsync(uuid, function);
+ response.complete(new FunctionResponse(false, functionName, functionData));
+ } else if (async) {
+ runFunctionData(owner, futureData, playerWrapper)
+ .whenComplete((value, ex) -> {
+ if (ex != null) {
+ ex.printStackTrace();
+ response.complete(new FunctionResponse(false, value.failedFunction, value.data));
+ } else {
+ cleanupAsync(uuid, function);
+ response.complete(value);
+ }
+ });
+ }
+ }, async);
+ //Return if function is async since the async caller will hand
+ //control back to this method after completion or the function will
+ //fail and then complete
+ //Also return if the future is completed, this is done because if a function is completed
+ //with a sync function that failed the future will complete, but we don't want to continue
+ //the loop
+ if (async || response.isDone()) {
+ return;
+ }
+ }
+ response.complete(new FunctionResponse(true));
+ }, false);
+ return response;
+ }
+
+ private void cleanupAsync(UUID uuid, Function function) {
+ Map map = this.runningAsyncFunctions.get(uuid);
+ if(map != null) {
+ AtomicInteger num = map.get(function);
+ if(num != null) {
+ int ret = num.decrementAndGet();
+ if (ret <= 0) { //Less than 0 shouldn't happen but just to ensure that the map gets cleaned up
+ map.remove(function);
+ }
+ if (map.size() == 0) { //If the map is empty remove
+ this.runningAsyncFunctions.remove(uuid);
+ }
+ }
+ }
+ }
+
+ private boolean isFail(FunctionResponse response, FunctionToken token) {
+ for (FunctionData data : token.getFailOnFunctions()) {
+ if (data.getName().equals(response.failedFunction)) {
+ if (data.getData() == null || data.getData().equals(response.data)) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ private class FunctionResponse {
+ private final boolean result;
+ private final String failedFunction;
+ private final String data;
+
+ public FunctionResponse(boolean result) {
+ this(result, null, null);
+ }
+
+ public FunctionResponse(boolean result, String failedFunction, String data) {
+ this.result = result;
+ this.failedFunction = failedFunction;
+ this.data = data;
+ }
+ }
+}
\ No newline at end of file
diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/manager/dynamicgui/GuiManager.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/manager/dynamicgui/GuiManager.java
similarity index 55%
rename from core/src/main/java/com/clubobsidian/dynamicgui/manager/dynamicgui/GuiManager.java
rename to core/src/main/java/com/clubobsidian/dynamicgui/core/manager/dynamicgui/GuiManager.java
index 4bce351b6..7d4187dbe 100644
--- a/core/src/main/java/com/clubobsidian/dynamicgui/manager/dynamicgui/GuiManager.java
+++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/manager/dynamicgui/GuiManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Club Obsidian and contributors.
+ * Copyright 2022 virustotalop and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,41 +13,46 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.clubobsidian.dynamicgui.manager.dynamicgui;
-
-import com.clubobsidian.dynamicgui.DynamicGui;
-import com.clubobsidian.dynamicgui.enchantment.EnchantmentWrapper;
-import com.clubobsidian.dynamicgui.entity.PlayerWrapper;
-import com.clubobsidian.dynamicgui.event.inventory.GuiLoadEvent;
-import com.clubobsidian.dynamicgui.event.inventory.GuiPreloadEvent;
-import com.clubobsidian.dynamicgui.gui.Gui;
-import com.clubobsidian.dynamicgui.gui.ModeEnum;
-import com.clubobsidian.dynamicgui.gui.Slot;
-import com.clubobsidian.dynamicgui.inventory.InventoryWrapper;
-import com.clubobsidian.dynamicgui.logger.LoggerWrapper;
-import com.clubobsidian.dynamicgui.manager.entity.EntityManager;
-import com.clubobsidian.dynamicgui.manager.material.MaterialManager;
-import com.clubobsidian.dynamicgui.manager.world.LocationManager;
+
+package com.clubobsidian.dynamicgui.core.manager.dynamicgui;
+
+import com.clubobsidian.dynamicgui.core.DynamicGui;
+import com.clubobsidian.dynamicgui.core.command.CommandRegistrar;
+import com.clubobsidian.dynamicgui.core.enchantment.EnchantmentWrapper;
+import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper;
+import com.clubobsidian.dynamicgui.core.event.inventory.GuiLoadEvent;
+import com.clubobsidian.dynamicgui.core.event.inventory.GuiPreloadEvent;
+import com.clubobsidian.dynamicgui.core.event.inventory.GuiSwitchEvent;
+import com.clubobsidian.dynamicgui.core.gui.Gui;
+import com.clubobsidian.dynamicgui.core.gui.ModeEnum;
+import com.clubobsidian.dynamicgui.core.gui.Slot;
+import com.clubobsidian.dynamicgui.core.inventory.InventoryWrapper;
+import com.clubobsidian.dynamicgui.core.logger.LoggerWrapper;
+import com.clubobsidian.dynamicgui.core.manager.entity.EntityManager;
+import com.clubobsidian.dynamicgui.core.manager.material.MaterialManager;
+import com.clubobsidian.dynamicgui.core.manager.world.LocationManager;
+import com.clubobsidian.dynamicgui.core.platform.Platform;
+import com.clubobsidian.dynamicgui.core.platform.PlatformType;
+import com.clubobsidian.dynamicgui.core.plugin.DynamicGuiPlugin;
+import com.clubobsidian.dynamicgui.core.util.ChatColor;
+import com.clubobsidian.dynamicgui.core.util.HashUtil;
+import com.clubobsidian.dynamicgui.core.util.ThreadUtil;
+import com.clubobsidian.dynamicgui.core.world.LocationWrapper;
import com.clubobsidian.dynamicgui.parser.function.FunctionType;
import com.clubobsidian.dynamicgui.parser.gui.GuiToken;
import com.clubobsidian.dynamicgui.parser.macro.MacroToken;
import com.clubobsidian.dynamicgui.parser.slot.SlotToken;
-import com.clubobsidian.dynamicgui.plugin.DynamicGuiPlugin;
-import com.clubobsidian.dynamicgui.server.FakeServer;
-import com.clubobsidian.dynamicgui.server.ServerType;
-import com.clubobsidian.dynamicgui.util.ChatColor;
-import com.clubobsidian.dynamicgui.util.FunctionUtil;
-import com.clubobsidian.dynamicgui.util.HashUtil;
-import com.clubobsidian.dynamicgui.world.LocationWrapper;
import com.clubobsidian.wrappy.Configuration;
import com.clubobsidian.wrappy.ConfigurationSection;
import org.apache.commons.io.FileUtils;
+import javax.inject.Inject;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -57,64 +62,72 @@
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicInteger;
public class GuiManager {
+ @Inject
private static GuiManager instance;
+ public static GuiManager get() {
+ if (!instance.intialized) {
+ instance.intialized = true;
+ instance.loadGlobalMacros();
+ instance.loadGuis();
+ }
+ return instance;
+ }
+
+ private static Gui getOrCloneGui(Gui gui) {
+ return gui.isStatic() ? gui : gui.clone();
+ }
+
private Map guis;
- private final Map playerGuis;
+ private final Map playerGuis = new HashMap<>();
private Map cachedGuis;
private Map cachedTokens;
private Map> globalMacros;
private Map> cachedGlobalMacros;
private Map guiHashes;
private Map globalMacrosTimestamps;
- private final Set modifiedMacros;
+ private final Set modifiedMacros = new HashSet<>();
+ private final CommandRegistrar commandRegistrar;
+ private boolean intialized = false;
- private GuiManager() {
+ @Inject
+ private GuiManager(CommandRegistrar commandRegistrar) {
this.guis = new HashMap<>();
- this.playerGuis = new HashMap<>();
this.cachedGuis = new HashMap<>();
this.cachedTokens = new HashMap<>();
this.globalMacros = new LinkedHashMap<>();
this.cachedGlobalMacros = new HashMap<>();
this.guiHashes = new HashMap<>();
this.globalMacrosTimestamps = new HashMap<>();
- this.modifiedMacros = new HashSet<>();
+ this.commandRegistrar = commandRegistrar;
}
- public static GuiManager get() {
- if(instance == null) {
- instance = new GuiManager();
- instance.loadGlobalMacros();
- instance.loadGuis();
- }
- return instance;
- }
-
- public boolean hasGuiName(String name) {
+ public boolean isGuiLoaded(String name) {
return this.guis.containsKey(name);
}
- public Gui getGuiByName(String name) {
+ public Gui getGui(String name) {
Gui gui = this.guis.get(name);
- if(gui != null) {
- return gui.clone();
+ if (gui != null) {
+ return getOrCloneGui(gui);
}
-
return null;
}
public void reloadGuis(boolean force) {
DynamicGui.get().getLogger().info("Reloading guis!");
- DynamicGui.get().getPlugin().unloadCommands();
+ this.commandRegistrar.unregisterGuiAliases();
this.cachedGuis = this.guis;
this.guis = new HashMap<>();
this.cachedGlobalMacros = this.globalMacros;
this.globalMacros = new HashMap<>();
- if(force) {
+ if (force) {
this.cachedTokens = new HashMap<>();
this.cachedGuis = new HashMap<>();
this.guiHashes = new HashMap<>();
@@ -131,7 +144,7 @@ public List getGuis() {
}
public Map getPlayerGuis() {
- return this.playerGuis;
+ return Collections.unmodifiableMap(this.playerGuis);
}
public boolean hasGuiCurrently(PlayerWrapper> playerWrapper) {
@@ -139,98 +152,150 @@ public boolean hasGuiCurrently(PlayerWrapper> playerWrapper) {
}
public boolean hasGuiOpen(PlayerWrapper> playerWrapper) {
- if(playerWrapper.getOpenInventoryWrapper() == null) {
+ if (playerWrapper.getOpenInventoryWrapper() == null) {
return false;
- } else return this.hasGuiCurrently(playerWrapper);
+ }
+ return this.hasGuiCurrently(playerWrapper);
}
- public void cleanupGui(PlayerWrapper> playerWrapper) {
+ public void cleanupPlayerGui(PlayerWrapper> playerWrapper) {
this.playerGuis.remove(playerWrapper.getUniqueId());
}
- public Gui getCurrentGui(PlayerWrapper> playerWrapper) {
+ public Gui getPlayerGui(PlayerWrapper> playerWrapper) {
return this.playerGuis.get(playerWrapper.getUniqueId());
}
- public boolean openGui(Object player, String guiName) {
+ public CompletableFuture openGui(Object player, String guiName) {
return this.openGui(EntityManager.get().createPlayerWrapper(player), guiName);
}
- public boolean openGui(Object player, Gui gui) {
+ public CompletableFuture openGui(Object player, Gui gui) {
return this.openGui(EntityManager.get().createPlayerWrapper(player), gui);
}
- public boolean openGui(PlayerWrapper> playerWrapper, String guiName) {
+ public CompletableFuture openGui(PlayerWrapper> playerWrapper, String guiName) {
return this.openGui(playerWrapper, guiName, null);
}
- public boolean openGui(PlayerWrapper> playerWrapper, String guiName, Gui back) {
- return this.openGui(playerWrapper, this.getGuiByName(guiName), back);
+ public CompletableFuture openGui(PlayerWrapper> playerWrapper, String guiName, Gui back) {
+ return this.openGui(playerWrapper, this.getGui(guiName), back);
}
- public boolean openGui(PlayerWrapper> playerWrapper, Gui gui) {
+ public CompletableFuture openGui(PlayerWrapper> playerWrapper, Gui gui) {
return this.openGui(playerWrapper, gui, null);
}
- public boolean openGui(PlayerWrapper> playerWrapper, Gui gui, Gui back) {
- if(gui == null) {
- playerWrapper.sendMessage(DynamicGui.get().getNoGui());
- return false;
- }
-
- Gui clonedGui = gui.clone();
- if(back != null) {
- clonedGui.setBack(back.clone());
- }
-
- GuiPreloadEvent preloadEvent = new GuiPreloadEvent(clonedGui, playerWrapper);
- DynamicGui.get().getEventBus().callEvent(preloadEvent);
-
- //Run gui load functions
- boolean ran = FunctionUtil.tryFunctions(clonedGui, FunctionType.LOAD, playerWrapper);
- GuiLoadEvent event = new GuiLoadEvent(clonedGui, playerWrapper);
- if(!ran) {
- event.setCancelled(true);
- }
- DynamicGui.get().getEventBus().callEvent(event);
-
- if(ran) {
- InventoryWrapper> inventoryWrapper = clonedGui.buildInventory(playerWrapper);
-
- //Run slot load functions
- for(Slot slot : clonedGui.getSlots()) {
- FunctionUtil.tryFunctions(slot, FunctionType.LOAD, playerWrapper);
+ public CompletableFuture openGui(PlayerWrapper> playerWrapper, Gui gui, Gui back) {
+ CompletableFuture future = new CompletableFuture<>();
+ future.exceptionally((ex) -> {
+ ex.printStackTrace();
+ return null;
+ });
+ ThreadUtil.run(() -> {
+ if (gui == null) {
+ playerWrapper.sendMessage(DynamicGui.get().getMessage().getNoGui());
+ future.complete(false);
+ return;
}
- if(inventoryWrapper == null) {
- return false;
+ Gui clonedGui = getOrCloneGui(gui);
+ if (back != null) {
+ clonedGui.setBack(back.clone());
}
- FakeServer server = DynamicGui.get().getServer();
- if(server.getType() == ServerType.SPONGE) {
- server.getScheduler().scheduleSyncDelayedTask(DynamicGui.get().getPlugin(), () -> {
- playerWrapper.openInventory(inventoryWrapper);
- }, 1L);
- } else {
- playerWrapper.openInventory(inventoryWrapper);
- }
+ GuiPreloadEvent preloadEvent = new GuiPreloadEvent(clonedGui, playerWrapper);
+ DynamicGui.get().getEventBus().callEvent(preloadEvent);
+
+ //Run gui load functions
+ CompletableFuture result = FunctionManager.get().tryFunctions(clonedGui, FunctionType.LOAD, playerWrapper);
+ result.exceptionally((ex) -> {
+ ex.printStackTrace();
+ return null;
+ });
+ result.thenAccept((ran) -> ThreadUtil.run(() -> {
+ GuiLoadEvent event = new GuiLoadEvent(clonedGui, playerWrapper);
+ if (!ran) {
+ event.setCancelled(true);
+ }
+ DynamicGui.get().getEventBus().callEvent(event);
- this.playerGuis.put(playerWrapper.getUniqueId(), clonedGui);
- DynamicGui.get().getServer().getScheduler().scheduleSyncDelayedTask(DynamicGui.get().getPlugin(), () -> {
- playerWrapper.updateInventory();
- }, 2L);
- }
- return ran;
+ if (ran) {
+ Gui currentGui = this.getPlayerGui(playerWrapper);
+ if (back != null && back.equals(currentGui)) {
+ DynamicGui.get().getEventBus().callEvent(new GuiSwitchEvent(back, clonedGui, playerWrapper));
+ }
+ InventoryWrapper> inventoryWrapper = clonedGui.buildInventory(playerWrapper);
+ if (inventoryWrapper == null) {
+ future.complete(false);
+ return;
+ }
+
+ //Run slot load functions
+ CompletableFuture slotFuture = new CompletableFuture<>();
+ List slots = clonedGui.getSlots();
+ int slotSize = slots.size();
+ AtomicInteger slotCount = new AtomicInteger(0);
+ for (int i = 0; i < slotSize; i++) {
+ if(slotFuture.isDone()) {
+ return;
+ }
+ Slot slot = slots.get(i);
+ FunctionManager.get()
+ .tryFunctions(slot, FunctionType.LOAD, playerWrapper)
+ .whenComplete((slotResult, ex) -> {
+ if(slotFuture.isDone()) {
+ return;
+ }
+ if(ex != null) {
+ ex.printStackTrace();
+ slotFuture.complete(false);
+ } else {
+ int count = slotCount.incrementAndGet();
+ if(slotSize == count) {
+ slotFuture.complete(true);
+ }
+ }
+ });
+ }
+ slotFuture.whenComplete((completed, ex) -> {
+ if (ex != null) {
+ ex.printStackTrace();
+ future.complete(false);
+ } else {
+ ThreadUtil.run(() -> {
+ Platform platform = DynamicGui.get().getPlatform();
+ if (platform.getType() == PlatformType.SPONGE) {
+ platform.getScheduler().runSyncDelayedTask(() -> {
+ playerWrapper.openInventory(inventoryWrapper);
+ }, 1L);
+ } else {
+ playerWrapper.openInventory(inventoryWrapper);
+ }
+ this.playerGuis.put(playerWrapper.getUniqueId(), clonedGui);
+ platform.getScheduler().runSyncDelayedTask(() -> {
+ playerWrapper.updateInventory();
+ }, 2L);
+ future.complete(true);
+ }, false);
+ }
+ });
+ } else {
+ future.complete(false);
+ }
+ }, false));
+ }, false);
+ return future;
}
private void loadGlobalMacroFromFile(File file) {
String macroName = file.getName().substring(0, file.getName().lastIndexOf("."));
byte[] fileHash = HashUtil.getMD5(file);
byte[] cachedHash = this.globalMacrosTimestamps.get(macroName);
- if(cachedHash == null || fileHash != cachedHash) {
+ if (cachedHash == null || fileHash != cachedHash) {
List tokens = new ArrayList<>();
Configuration config = Configuration.load(file);
- for(String key : config.getKeys()) {
+ for (String key : config.getKeys()) {
ConfigurationSection section = config.getConfigurationSection(key);
MacroToken token = new MacroToken(section);
tokens.add(token);
@@ -250,15 +315,15 @@ private void loadGlobalMacros() {
Collection macroFiles = FileUtils.listFiles(macroFolder, new String[]{"yml", "json", "conf", "xml"}, true);
- for(File file : macroFiles) {
+ for (File file : macroFiles) {
this.loadGlobalMacroFromFile(file);
}
Iterator>> it = this.cachedGlobalMacros.entrySet().iterator();
- while(it.hasNext()) {
+ while (it.hasNext()) {
Entry> next = it.next();
String macroName = next.getKey();
- if(!this.globalMacros.containsKey(macroName)) {
+ if (!this.globalMacros.containsKey(macroName)) {
it.remove();
this.globalMacrosTimestamps.remove(macroName);
}
@@ -274,17 +339,15 @@ private void loadGuis() {
private void loadGuiFromFile(Configuration yaml, File file) {
DynamicGui dynamicGui = DynamicGui.get();
- DynamicGuiPlugin plugin = dynamicGui.getPlugin();
-
try {
String guiName = file.getName().substring(0, file.getName().lastIndexOf("."));
byte[] cachedHash = this.guiHashes.get(guiName);
GuiToken token = this.cachedTokens.get(guiName);
byte[] guiHash = HashUtil.getMD5(file);
- if(token != null && cachedHash != null && cachedHash == guiHash && !hasUpdatedMacro(token)) {
+ if (token != null && cachedHash != null && cachedHash == guiHash && !hasUpdatedMacro(token)) {
Gui cachedGui = this.cachedGuis.get(guiName);
- for(String alias : token.getAlias()) {
- plugin.createCommand(guiName, alias);
+ for (String alias : token.getAlias()) {
+ this.commandRegistrar.registerGuiCommand(guiName, alias);
}
this.guis.put(guiName, cachedGui);
@@ -293,7 +356,7 @@ private void loadGuiFromFile(Configuration yaml, File file) {
this.guiHashes.put(guiName, guiHash);
this.loadGuiFromConfiguration(guiName, yaml);
}
- } catch(NullPointerException ex) {
+ } catch (NullPointerException ex) {
dynamicGui.getLogger().info("Error loading in file: " + file.getName());
ex.printStackTrace();
}
@@ -306,8 +369,8 @@ private void loadFileGuis() {
Collection ar = FileUtils.listFiles(guiFolder, new String[]{"yml", "json", "conf", "xml"}, true);
- if(ar.size() != 0) {
- for(File file : ar) {
+ if (ar.size() != 0) {
+ for (File file : ar) {
Configuration config = Configuration.load(file);
this.loadGuiFromFile(config, file);
}
@@ -318,8 +381,8 @@ private void loadFileGuis() {
private boolean hasUpdatedMacro(GuiToken token) {
List macros = token.getLoadMacros();
- for(String macro : macros) {
- if(this.modifiedMacros.contains(macro)) {
+ for (String macro : macros) {
+ if (this.modifiedMacros.contains(macro)) {
return true;
}
}
@@ -333,7 +396,7 @@ private void loadRemoteGui(String guiName, String strUrl) {
File file = new File(DynamicGui.get().getPlugin().getGuiFolder(), guiName);
Configuration yaml = Configuration.load(url, file);
this.loadGuiFromFile(yaml, file);
- } catch(MalformedURLException e) {
+ } catch (MalformedURLException e) {
e.printStackTrace();
DynamicGui.get().getLogger().error("An error occured when loading from the url " + strUrl + " please ensure you have the correct url.");
}
@@ -343,9 +406,9 @@ private void loadRemoteGuis() {
File configFile = new File(DynamicGui.get().getPlugin().getDataFolder(), "config.yml");
Configuration config = Configuration.load(configFile);
- if(config.get("remote-guis") != null) {
+ if (config.get("remote-guis") != null) {
ConfigurationSection remote = config.getConfigurationSection("remote-guis");
- for(String key : remote.getKeys()) {
+ for (String key : remote.getKeys()) {
ConfigurationSection guiSection = remote.getConfigurationSection(key);
String strURL = guiSection.getString("url");
String guiName = guiSection.getString("file-name");
@@ -356,10 +419,10 @@ private void loadRemoteGuis() {
private void cleanupGuis() {
Iterator> it = this.cachedGuis.entrySet().iterator();
- while(it.hasNext()) {
+ while (it.hasNext()) {
Entry next = it.next();
String guiName = next.getKey();
- if(!this.guis.containsKey(guiName)) {
+ if (!this.guis.containsKey(guiName)) {
it.remove();
this.guiHashes.remove(guiName);
this.cachedTokens.remove(guiName);
@@ -374,11 +437,11 @@ private void loadGuiFromConfiguration(String guiName, Configuration config) {
List guiTokens = new ArrayList<>();
List loadMacros = guiToken.getLoadMacros();
- if(loadMacros.size() > 0) {
- for(String macro : loadMacros) {
+ if (loadMacros.size() > 0) {
+ for (String macro : loadMacros) {
List macroTokens = this.globalMacros.get(macro);
- if(macroTokens != null) {
- for(MacroToken t : macroTokens) {
+ if (macroTokens != null) {
+ for (MacroToken t : macroTokens) {
guiTokens.add(t);
}
} else {
@@ -400,7 +463,7 @@ private void loadGuiFromConfiguration(String guiName, Configuration config) {
private List createSlots(GuiToken guiToken) {
List slots = new ArrayList<>();
Iterator> it = guiToken.getSlots().entrySet().iterator();
- while(it.hasNext()) {
+ while (it.hasNext()) {
Entry next = it.next();
int index = next.getKey();
SlotToken slotToken = next.getValue();
@@ -408,20 +471,20 @@ private List createSlots(GuiToken guiToken) {
String icon = MaterialManager.get().normalizeMaterial(slotToken.getIcon());
String name = slotToken.getName();
- if(name != null) {
- name = ChatColor.translateAlternateColorCodes('&', name);
+ if (name != null) {
+ name = ChatColor.translateAlternateColorCodes(name);
}
String nbt = slotToken.getNbt();
List lore = new ArrayList<>();
- for(String ls : slotToken.getLore()) {
- lore.add(ChatColor.translateAlternateColorCodes('&', ls));
+ for (String ls : slotToken.getLore()) {
+ lore.add(ChatColor.translateAlternateColorCodes(ls));
}
List enchants = new ArrayList<>();
- for(String ench : slotToken.getEnchants()) {
+ for (String ench : slotToken.getEnchants()) {
String[] args = ench.split(",");
enchants.add(new EnchantmentWrapper(args[0], Integer.parseInt(args[1])));
}
@@ -430,12 +493,12 @@ private List createSlots(GuiToken guiToken) {
int amount = slotToken.getAmount();
- boolean close = slotToken.isClosed();
+ Boolean close = slotToken.isClosed();
short data = slotToken.getData();
boolean glow = slotToken.getGlow();
- boolean moveable = slotToken.isMoveable();
+ boolean movable = slotToken.isMovable();
String modelProvider = slotToken.getModelProvider();
String modelData = slotToken.getModelData();
@@ -444,7 +507,7 @@ private List createSlots(GuiToken guiToken) {
Map