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 getEntityManager() { + return BukkitEntityManager.class; + } + + @Override + public Class getInventoryManager() { + return BukkitInventoryManager.class; + } + + @Override + public Class getItemStackManager() { + return BukkitItemStackManager.class; + } + + @Override + public Class getMaterialManager() { + return BukkitMaterialManager.class; + } + + @Override + public Class getLocationManger() { + return BukkitLocationManager.class; + } + + @Override + public Class 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 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 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 entityClass = this.getEntityManager(); + private final Class inventoryClass = this.getInventoryManager(); + private final Class itemStackClass = this.getItemStackManager(); + private final Class materialClass = this.getMaterialManager(); + private final Class 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 getEntityManager(); + + public abstract Class getInventoryManager(); + + public abstract Class getItemStackManager(); + + public abstract Class getMaterialManager(); + + public abstract Class getLocationManger(); + + public abstract Class 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 metadata = slotToken.getMetadata(); - slots.add(new Slot(index, amount, icon, name, nbt, data, glow, moveable, + slots.add(new Slot(index, amount, icon, name, nbt, data, glow, movable, close, lore, enchants, itemFlags, modelProvider, modelData, slotToken.getFunctionTree(), updateInterval, metadata)); } @@ -458,14 +521,14 @@ private Gui createGui(final GuiToken guiToken, final String guiName, final List< int rows = guiToken.getRows(); List aliases = guiToken.getAlias(); - for(String alias : aliases) { - plugin.createCommand(guiName, alias); + for (String alias : aliases) { + this.commandRegistrar.registerGuiCommand(guiName, alias); } - boolean close = guiToken.isClosed(); + Boolean close = guiToken.isClosed(); List> locations = new ArrayList<>(); - for(String location : guiToken.getLocations()) { + for (String location : guiToken.getLocations()) { locations.add(LocationManager.get().toLocationWrapper(location)); } @@ -474,6 +537,10 @@ private Gui createGui(final GuiToken guiToken, final String guiName, final List< Map> npcIds = guiToken.getNpcs(); Map metadata = guiToken.getMetadata(); - return new Gui(guiName, type, title, rows, close, modeEnum, npcIds, slots, locations, guiToken.getFunctions(), metadata); + boolean isStatic = guiToken.isStatic(); + + return new Gui(guiName, type, title, rows, close, modeEnum, + npcIds, slots, locations, guiToken.getFunctions(), metadata, + isStatic); } } \ No newline at end of file diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/manager/dynamicgui/MiniMessageManager.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/manager/dynamicgui/MiniMessageManager.java similarity index 71% rename from core/src/main/java/com/clubobsidian/dynamicgui/manager/dynamicgui/MiniMessageManager.java rename to core/src/main/java/com/clubobsidian/dynamicgui/core/manager/dynamicgui/MiniMessageManager.java index 219ab4d9f..880108285 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/manager/dynamicgui/MiniMessageManager.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/manager/dynamicgui/MiniMessageManager.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,10 +14,10 @@ * limitations under the License. */ -package com.clubobsidian.dynamicgui.manager.dynamicgui; +package com.clubobsidian.dynamicgui.core.manager.dynamicgui; -import com.clubobsidian.dynamicgui.DynamicGui; -import com.clubobsidian.dynamicgui.event.DynamicGuiReloadEvent; +import com.clubobsidian.dynamicgui.core.DynamicGui; +import com.clubobsidian.dynamicgui.core.event.plugin.DynamicGuiReloadEvent; import com.clubobsidian.trident.EventHandler; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.MiniMessage; @@ -31,28 +31,23 @@ public class MiniMessageManager { public static MiniMessageManager instance; public static MiniMessageManager get() { - if(instance == null) { + if (instance == null) { instance = new MiniMessageManager(); } return instance; } - private final Map json; - private final MiniMessage miniMessage; - private final GsonComponentSerializer serializer; + private final Map json = new HashMap<>(); + private final MiniMessage miniMessage = MiniMessage.builder().build(); + private final GsonComponentSerializer serializer = GsonComponentSerializer.builder().build(); private MiniMessageManager() { - this.json = new HashMap<>(); - this.miniMessage = MiniMessage - .builder() - .build(); - this.serializer = GsonComponentSerializer.builder().build(); DynamicGui.get().getEventBus().registerEvents(this); } public String toJson(String data) { String cached = this.json.get(data); - if(cached == null) { + if (cached == null) { Component component = this.miniMessage.deserialize(data); cached = this.serializer.serialize(component); this.json.put(data, cached); diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/manager/dynamicgui/ModelManager.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/manager/dynamicgui/ModelManager.java similarity index 76% rename from core/src/main/java/com/clubobsidian/dynamicgui/manager/dynamicgui/ModelManager.java rename to core/src/main/java/com/clubobsidian/dynamicgui/core/manager/dynamicgui/ModelManager.java index 1b4d0b0ca..50ebae5e8 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/manager/dynamicgui/ModelManager.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/manager/dynamicgui/ModelManager.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,10 +14,10 @@ * limitations under the License. */ -package com.clubobsidian.dynamicgui.manager.dynamicgui; +package com.clubobsidian.dynamicgui.core.manager.dynamicgui; -import com.clubobsidian.dynamicgui.registry.model.ModelProvider; -import com.clubobsidian.dynamicgui.registry.model.vanilla.VanillaModelProvider; +import com.clubobsidian.dynamicgui.core.registry.model.ModelProvider; +import com.clubobsidian.dynamicgui.core.registry.model.vanilla.VanillaModelProvider; import java.util.HashMap; import java.util.Map; @@ -27,7 +27,7 @@ public class ModelManager { private static ModelManager instance; public static ModelManager get() { - if(instance == null) { + if (instance == null) { instance = new ModelManager(); } return instance; @@ -36,11 +36,11 @@ public static ModelManager get() { private Map registries = new HashMap<>(); private ModelManager() { - this.register(new VanillaModelProvider()); + this.register(new VanillaModelProvider()); } public ModelProvider getProvider(final String registryName) { - if(registryName == null) { + if (registryName == null) { return null; } String lowerName = registryName.toLowerCase(); diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/manager/dynamicgui/ReplacerManager.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/manager/dynamicgui/ReplacerManager.java similarity index 79% rename from core/src/main/java/com/clubobsidian/dynamicgui/manager/dynamicgui/ReplacerManager.java rename to core/src/main/java/com/clubobsidian/dynamicgui/core/manager/dynamicgui/ReplacerManager.java index 3ac134f3d..be0f02a3b 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/manager/dynamicgui/ReplacerManager.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/manager/dynamicgui/ReplacerManager.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.manager.dynamicgui; -import com.clubobsidian.dynamicgui.entity.PlayerWrapper; -import com.clubobsidian.dynamicgui.registry.replacer.ReplacerRegistry; +package com.clubobsidian.dynamicgui.core.manager.dynamicgui; + +import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper; +import com.clubobsidian.dynamicgui.core.registry.replacer.ReplacerRegistry; import java.util.ArrayList; import java.util.List; @@ -32,7 +33,7 @@ private ReplacerManager() { } public static ReplacerManager get() { - if(instance == null) { + if (instance == null) { instance = new ReplacerManager(); } return instance; @@ -40,7 +41,7 @@ public static ReplacerManager get() { public String replace(String text, PlayerWrapper playerWrapper) { String newText = text; - for(ReplacerRegistry registry : this.registries) { + for (ReplacerRegistry registry : this.registries) { newText = registry.replace(playerWrapper, newText); } diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/manager/dynamicgui/SlotManager.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/manager/dynamicgui/SlotManager.java new file mode 100644 index 000000000..748d71343 --- /dev/null +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/manager/dynamicgui/SlotManager.java @@ -0,0 +1,92 @@ +/* + * 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.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.parser.function.FunctionType; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.UUID; + +public class SlotManager { + + private static SlotManager instance; + + public static SlotManager get() { + if (instance == null) { + instance = new SlotManager(); + } + return instance; + } + + private SlotManager() { + this.updateSlots(); + } + + private void updateSlots() { + DynamicGui.get().getPlatform().getScheduler().scheduleSyncRepeatingTask(() -> { + Map> updatedStaticGui = new HashMap<>(); + for (Entry next : GuiManager.get().getPlayerGuis().entrySet()) { + UUID key = next.getKey(); + PlayerWrapper playerWrapper = DynamicGui.get().getPlatform().getPlayer(key); + Gui gui = next.getValue(); + Collection cachedSlots = updatedStaticGui.get(gui); + if (gui.isStatic() && cachedSlots != null) { + InventoryWrapper inventoryWrapper = gui.getInventoryWrapper(); + for (Slot slot : cachedSlots) { + inventoryWrapper.updateItem(slot.getIndex(), playerWrapper); + } + continue; + } + Collection updatedSlots = new ArrayList<>(); + for (Slot slot : gui.getSlots()) { + if (slot.getUpdateInterval() == 0 && !slot.getUpdate()) { + continue; + } + + slot.tick(); + if (slot.getUpdate() || (slot.getCurrentTick() % slot.getUpdateInterval() == 0)) { + ItemStackWrapper itemStackWrapper = slot.buildItemStack(playerWrapper); + int slotIndex = slot.getIndex(); + + InventoryWrapper inventoryWrapper = slot.getOwner().getInventoryWrapper(); + inventoryWrapper.setItem(slotIndex, itemStackWrapper); + + FunctionManager.get().tryFunctions(slot, FunctionType.LOAD, playerWrapper); + if (!slot.getItemStack().getType().equalsIgnoreCase(Slot.IGNORE_MATERIAL)) { + inventoryWrapper.updateItem(slotIndex, playerWrapper); + updatedSlots.add(slot); + } + slot.setUpdate(false); + } + } + if (gui.isStatic()) { //Cache if gui is static an attempt to update was made + updatedStaticGui.put(gui, updatedSlots); + } + } + }, 1L, 1L); + } +} \ No newline at end of file diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/manager/dynamicgui/cooldown/Cooldown.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/manager/dynamicgui/cooldown/Cooldown.java similarity index 74% rename from core/src/main/java/com/clubobsidian/dynamicgui/manager/dynamicgui/cooldown/Cooldown.java rename to core/src/main/java/com/clubobsidian/dynamicgui/core/manager/dynamicgui/cooldown/Cooldown.java index bbff291c7..7a2bb4aaa 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/manager/dynamicgui/cooldown/Cooldown.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/manager/dynamicgui/cooldown/Cooldown.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.manager.dynamicgui.cooldown; + +package com.clubobsidian.dynamicgui.core.manager.dynamicgui.cooldown; public class Cooldown { private final String name; - private final Long time; - private final Long cooldown; + private final long time; + private final long cooldown; - public Cooldown(String name, Long time, Long cooldown) { + public Cooldown(String name, long time, long cooldown) { this.name = name; this.time = time; this.cooldown = cooldown; @@ -31,11 +32,11 @@ public String getName() { return this.name; } - public Long getTime() { + public long getTime() { return this.time; } - public Long getCooldown() { + public long getCooldown() { return this.cooldown; } } \ No newline at end of file diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/manager/dynamicgui/cooldown/CooldownManager.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/manager/dynamicgui/cooldown/CooldownManager.java similarity index 70% rename from core/src/main/java/com/clubobsidian/dynamicgui/manager/dynamicgui/cooldown/CooldownManager.java rename to core/src/main/java/com/clubobsidian/dynamicgui/core/manager/dynamicgui/cooldown/CooldownManager.java index 87621d5c7..1585fbfa6 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/manager/dynamicgui/cooldown/CooldownManager.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/manager/dynamicgui/cooldown/CooldownManager.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,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.clubobsidian.dynamicgui.manager.dynamicgui.cooldown; -import com.clubobsidian.dynamicgui.DynamicGui; -import com.clubobsidian.dynamicgui.entity.PlayerWrapper; -import com.clubobsidian.dynamicgui.plugin.DynamicGuiPlugin; -import com.clubobsidian.dynamicgui.server.FakeServer; +package com.clubobsidian.dynamicgui.core.manager.dynamicgui.cooldown; + +import com.clubobsidian.dynamicgui.core.DynamicGui; +import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper; +import com.clubobsidian.dynamicgui.core.platform.Platform; import com.clubobsidian.wrappy.Configuration; import com.clubobsidian.wrappy.ConfigurationSection; import java.io.File; -import java.util.Collection; +import java.util.ArrayList; +import java.util.Collections; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.UUID; @@ -36,21 +38,19 @@ public class CooldownManager { private static CooldownManager instance; public static CooldownManager get() { - if(instance == null) { + if (instance == null) { instance = new CooldownManager(); } return instance; } - private final Map> cooldowns; + private final Map> cooldowns = new ConcurrentHashMap<>(); + private final AtomicBoolean updateConfig = new AtomicBoolean(false); private final Configuration cooldownConfig; - private final AtomicBoolean updateConfig; private CooldownManager() { - this.cooldowns = new ConcurrentHashMap<>(); this.cooldownConfig = this.loadConfig(); - this.updateConfig = new AtomicBoolean(false); this.scheduleCooldownUpdate(); this.scheduleConfigUpdate(); } @@ -59,59 +59,55 @@ private Configuration loadConfig() { File dataFolder = DynamicGui.get().getPlugin().getDataFolder(); File cooldownsFile = new File(dataFolder, "cooldowns.yml"); Configuration config = Configuration.load(cooldownsFile); - for(String uuidStr : config.getKeys()) { + for (String uuidStr : config.getKeys()) { ConfigurationSection section = config.getConfigurationSection(uuidStr); - Map cooldownMap = new ConcurrentHashMap<>(); - for(String cooldownName : section.getKeys()) { - Long time = section.getLong(cooldownName + ".time"); - Long cooldown = section.getLong(cooldownName + ".cooldown"); + for (String cooldownName : section.getKeys()) { + long time = section.getLong(cooldownName + ".time"); + long cooldown = section.getLong(cooldownName + ".cooldown"); Cooldown cooldownObj = new Cooldown(cooldownName, time, cooldown); - if(this.getRemainingCooldown(cooldownObj) != -1L) { + if (this.getRemainingCooldown(cooldownObj) != -1L) { cooldownMap.put(cooldownName, cooldownObj); } else { section.set(cooldownName, null); } } - - if(section.isEmpty()) { + if (section.isEmpty()) { config.set(uuidStr, null); } - - if(cooldownMap.size() > 0) { + if (cooldownMap.size() > 0) { UUID uuid = UUID.fromString(uuidStr); this.cooldowns.put(uuid, cooldownMap); } } - config.save(); return config; } - public Long getRemainingCooldown(PlayerWrapper playerWrapper, String name) { + public long getRemainingCooldown(PlayerWrapper playerWrapper, String name) { return this.getRemainingCooldown(playerWrapper.getUniqueId(), name); } - public Long getRemainingCooldown(UUID uuid, String name) { + public long getRemainingCooldown(UUID uuid, String name) { Map cooldownMap = this.cooldowns.get(uuid); - if(cooldownMap == null) { + if (cooldownMap == null) { return -1L; } Cooldown cooldown = cooldownMap.get(name); - if(cooldown == null) { + if (cooldown == null) { return -1L; } return this.getRemainingCooldown(cooldown); } - public Long getRemainingCooldown(Cooldown cooldown) { + public long getRemainingCooldown(Cooldown cooldown) { long currentTime = System.currentTimeMillis(); - Long cooldownTime = cooldown.getTime(); - Long cooldownAmount = cooldown.getCooldown(); + long cooldownTime = cooldown.getTime(); + long cooldownAmount = cooldown.getCooldown(); - if((currentTime - cooldownTime) >= cooldownAmount) { + if ((currentTime - cooldownTime) >= cooldownAmount) { return -1L; } else { return cooldownAmount - (currentTime - cooldownTime); @@ -126,41 +122,38 @@ public boolean isOnCooldown(UUID uuid, String name) { return this.getRemainingCooldown(uuid, name) != -1L; } - public Collection getCooldown(PlayerWrapper playerWrapper) { + public List getCooldowns(PlayerWrapper playerWrapper) { UUID uuid = playerWrapper.getUniqueId(); return this.getCooldowns(uuid); } - public Collection getCooldowns(UUID uuid) { + public List getCooldowns(UUID uuid) { Map cooldowns = this.cooldowns.get(uuid); - if(cooldowns == null) { - return null; + if (cooldowns == null) { + return Collections.emptyList(); } - - return cooldowns.values(); + return new ArrayList<>(cooldowns.values()); } - public Cooldown createCooldown(PlayerWrapper playerWrapper, String name, Long cooldownTime) { + public Cooldown createCooldown(PlayerWrapper playerWrapper, String name, long cooldownTime) { UUID uuid = playerWrapper.getUniqueId(); return this.createCooldown(uuid, name, cooldownTime); } - public Cooldown createCooldown(UUID uuid, String name, Long cooldownTime) { - Long cooldownRemaining = this.getRemainingCooldown(uuid, name); - if(cooldownRemaining == -1L) { - Long currentTime = System.currentTimeMillis(); + public Cooldown createCooldown(UUID uuid, String name, long cooldownTime) { + long cooldownRemaining = this.getRemainingCooldown(uuid, name); + if (cooldownRemaining == -1L) { + long currentTime = System.currentTimeMillis(); Cooldown cooldown = new Cooldown(name, currentTime, cooldownTime); Map cooldownMap = this.cooldowns.get(uuid); - if(cooldownMap == null) { + if (cooldownMap == null) { cooldownMap = new ConcurrentHashMap<>(); this.cooldowns.put(uuid, cooldownMap); } - this.updateConfig.set(true); cooldownMap.put(name, cooldown); return cooldown; } - return null; } @@ -170,12 +163,12 @@ public boolean removeCooldown(PlayerWrapper playerWrapper, String name) { public boolean removeCooldown(UUID uuid, String name) { Map cooldownMap = this.cooldowns.get(uuid); - if(cooldownMap == null) { + if (cooldownMap == null) { return false; } boolean removed = cooldownMap.remove(name) != null; - if(removed) { + if (removed) { this.updateConfig.set(true); } return removed; @@ -187,14 +180,14 @@ public void shutdown() { private void updateAndSaveConfig() { Iterator>> it = this.cooldowns.entrySet().iterator(); - while(it.hasNext()) { + while (it.hasNext()) { Entry> next = it.next(); UUID uuid = next.getKey(); String uuidStr = uuid.toString(); Map cooldownMap = next.getValue(); cooldownMap.forEach((cooldownName, cooldownObj) -> { - Long time = cooldownObj.getTime(); - Long cooldown = cooldownObj.getCooldown(); + long time = cooldownObj.getTime(); + long cooldown = cooldownObj.getCooldown(); ConfigurationSection cooldownSection = this.cooldownConfig.getConfigurationSection(uuidStr + "." + cooldownName); cooldownSection.set("time", time); cooldownSection.set("cooldown", cooldown); @@ -207,45 +200,42 @@ private void updateAndSaveConfig() { private void updateCache() { Iterator>> it = this.cooldowns.entrySet().iterator(); boolean modified = false; - while(it.hasNext()) { + while (it.hasNext()) { Entry> next = it.next(); UUID uuid = next.getKey(); String uuidStr = uuid.toString(); Map cooldownMap = next.getValue(); Iterator> cooldownIt = cooldownMap.entrySet().iterator(); - while(cooldownIt.hasNext()) { + while (cooldownIt.hasNext()) { Entry cooldownNext = cooldownIt.next(); String cooldownName = cooldownNext.getKey(); Cooldown cooldown = cooldownNext.getValue(); - Long cooldownRemaining = this.getRemainingCooldown(cooldown); - if(cooldownRemaining == -1L) { + long cooldownRemaining = this.getRemainingCooldown(cooldown); + if (cooldownRemaining == -1L) { cooldownIt.remove(); this.cooldownConfig.set(uuidStr + "." + cooldownName, null); modified = true; } } } - - if(modified) { + if (modified) { this.updateConfig.set(true); } } private void scheduleCooldownUpdate() { DynamicGui dynamicGui = DynamicGui.get(); - DynamicGuiPlugin plugin = dynamicGui.getPlugin(); - FakeServer server = dynamicGui.getServer(); - server.getScheduler().scheduleSyncRepeatingTask(plugin, () -> { + Platform server = dynamicGui.getPlatform(); + server.getScheduler().scheduleSyncRepeatingTask(() -> { this.updateCache(); }, 1L, 1L); } private void scheduleConfigUpdate() { DynamicGui dynamicGui = DynamicGui.get(); - DynamicGuiPlugin plugin = dynamicGui.getPlugin(); - FakeServer server = dynamicGui.getServer(); - server.getScheduler().scheduleAsyncRepeatingTask(plugin, () -> { - if(this.updateConfig.get()) { + Platform server = dynamicGui.getPlatform(); + server.getScheduler().scheduleAsyncRepeatingTask(() -> { + if (this.updateConfig.get()) { this.updateConfig.set(false); this.updateAndSaveConfig(); } diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/manager/entity/EntityManager.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/manager/entity/EntityManager.java similarity index 84% rename from core/src/main/java/com/clubobsidian/dynamicgui/manager/entity/EntityManager.java rename to core/src/main/java/com/clubobsidian/dynamicgui/core/manager/entity/EntityManager.java index d678f95ff..45ee92d6c 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/manager/entity/EntityManager.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/manager/entity/EntityManager.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.entity; -import com.clubobsidian.dynamicgui.entity.PlayerWrapper; +package com.clubobsidian.dynamicgui.core.manager.entity; + +import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper; import com.google.inject.Inject; import java.util.List; diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/manager/inventory/InventoryManager.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/manager/inventory/InventoryManager.java similarity index 87% rename from core/src/main/java/com/clubobsidian/dynamicgui/manager/inventory/InventoryManager.java rename to core/src/main/java/com/clubobsidian/dynamicgui/core/manager/inventory/InventoryManager.java index 6ebab9809..051594d63 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/manager/inventory/InventoryManager.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/manager/inventory/InventoryManager.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.inventory; -import com.clubobsidian.dynamicgui.inventory.InventoryWrapper; +package com.clubobsidian.dynamicgui.core.manager.inventory; + +import com.clubobsidian.dynamicgui.core.inventory.InventoryWrapper; import com.google.inject.Inject; public abstract class InventoryManager { diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/manager/inventory/ItemStackManager.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/manager/inventory/ItemStackManager.java similarity index 86% rename from core/src/main/java/com/clubobsidian/dynamicgui/manager/inventory/ItemStackManager.java rename to core/src/main/java/com/clubobsidian/dynamicgui/core/manager/inventory/ItemStackManager.java index da026865f..375801552 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/manager/inventory/ItemStackManager.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/manager/inventory/ItemStackManager.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.inventory; -import com.clubobsidian.dynamicgui.inventory.ItemStackWrapper; +package com.clubobsidian.dynamicgui.core.manager.inventory; + +import com.clubobsidian.dynamicgui.core.inventory.ItemStackWrapper; import com.google.inject.Inject; public abstract class ItemStackManager { diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/manager/material/MaterialManager.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/manager/material/MaterialManager.java similarity index 89% rename from core/src/main/java/com/clubobsidian/dynamicgui/manager/material/MaterialManager.java rename to core/src/main/java/com/clubobsidian/dynamicgui/core/manager/material/MaterialManager.java index 9eb868c83..bcc49e697 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/manager/material/MaterialManager.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/manager/material/MaterialManager.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.manager.material; + +package com.clubobsidian.dynamicgui.core.manager.material; import com.google.inject.Inject; diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/manager/world/LocationManager.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/manager/world/LocationManager.java similarity index 88% rename from core/src/main/java/com/clubobsidian/dynamicgui/manager/world/LocationManager.java rename to core/src/main/java/com/clubobsidian/dynamicgui/core/manager/world/LocationManager.java index 46d7bc7ef..f595958fb 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/manager/world/LocationManager.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/manager/world/LocationManager.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.world; -import com.clubobsidian.dynamicgui.world.LocationWrapper; +package com.clubobsidian.dynamicgui.core.manager.world; + +import com.clubobsidian.dynamicgui.core.world.LocationWrapper; import com.google.inject.Inject; public abstract class LocationManager { diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/messaging/MessagingRunnable.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/messaging/MessagingRunnable.java similarity index 80% rename from core/src/main/java/com/clubobsidian/dynamicgui/messaging/MessagingRunnable.java rename to core/src/main/java/com/clubobsidian/dynamicgui/core/messaging/MessagingRunnable.java index 167bdf6b2..69ac7e3b8 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/messaging/MessagingRunnable.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/messaging/MessagingRunnable.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.messaging; -import com.clubobsidian.dynamicgui.entity.PlayerWrapper; +package com.clubobsidian.dynamicgui.core.messaging; + +import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper; public interface MessagingRunnable { diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/permission/Permission.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/permission/Permission.java similarity index 84% rename from core/src/main/java/com/clubobsidian/dynamicgui/permission/Permission.java rename to core/src/main/java/com/clubobsidian/dynamicgui/core/permission/Permission.java index 9002bfa8e..fcd68a437 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/permission/Permission.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/permission/Permission.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; -import com.clubobsidian.dynamicgui.entity.PlayerWrapper; +package com.clubobsidian.dynamicgui.core.permission; + +import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper; public interface Permission { diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/platform/Platform.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/platform/Platform.java new file mode 100644 index 000000000..bf12e189a --- /dev/null +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/platform/Platform.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.platform; + +import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper; +import com.clubobsidian.dynamicgui.core.messaging.MessagingRunnable; +import com.clubobsidian.dynamicgui.core.plugin.DynamicGuiPlugin; +import com.clubobsidian.dynamicgui.core.scheduler.Scheduler; +import com.clubobsidian.dynamicgui.core.world.WorldWrapper; + +import java.util.Collection; +import java.util.UUID; + +public interface Platform { + + Scheduler getScheduler(); + + boolean isMainThread(); + + void broadcastMessage(String message); + + void broadcastJsonMessage(String json); + + void dispatchServerCommand(String command); + + PlayerWrapper getPlayer(UUID uuid); + + PlayerWrapper getPlayer(String name); + + Collection> getOnlinePlayers(); + + int getGlobalPlayerCount(); + + PlatformType getType(); + + void registerOutgoingPluginChannel(DynamicGuiPlugin plugin, String channel); + + void registerIncomingPluginChannel(DynamicGuiPlugin plugin, String channel, MessagingRunnable runnable); + + WorldWrapper getWorld(String worldName); + +} \ No newline at end of file diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/server/ServerType.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/platform/PlatformType.java similarity index 80% rename from core/src/main/java/com/clubobsidian/dynamicgui/server/ServerType.java rename to core/src/main/java/com/clubobsidian/dynamicgui/core/platform/PlatformType.java index 783379e55..66decb6e3 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/server/ServerType.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/platform/PlatformType.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.server; -public enum ServerType { +package com.clubobsidian.dynamicgui.core.platform; +public enum PlatformType { + + BUKKIT, SPONGE, - SPIGOT } \ No newline at end of file diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/plugin/DynamicGuiPlugin.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/plugin/DynamicGuiPlugin.java similarity index 53% rename from core/src/main/java/com/clubobsidian/dynamicgui/plugin/DynamicGuiPlugin.java rename to core/src/main/java/com/clubobsidian/dynamicgui/core/plugin/DynamicGuiPlugin.java index 8426f3e3c..0c4c88a46 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/plugin/DynamicGuiPlugin.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/plugin/DynamicGuiPlugin.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,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.clubobsidian.dynamicgui.plugin; -import com.clubobsidian.dynamicgui.economy.Economy; -import com.clubobsidian.dynamicgui.permission.Permission; -import com.clubobsidian.dynamicgui.registry.npc.NPCRegistry; +package com.clubobsidian.dynamicgui.core.plugin; + +import cloud.commandframework.CommandManager; +import com.clubobsidian.dynamicgui.core.command.GuiCommandSender; +import com.clubobsidian.dynamicgui.core.economy.Economy; +import com.clubobsidian.dynamicgui.core.permission.Permission; +import com.clubobsidian.dynamicgui.core.registry.npc.NPCRegistry; import java.io.File; import java.util.List; @@ -36,16 +39,17 @@ public interface DynamicGuiPlugin { File getDataFolder(); - File getConfigFile(); - - File getGuiFolder(); - - File getMacroFolder(); - - List getRegisteredCommands(); + default File getConfigFile() { + return new File(this.getDataFolder(), "config.yml"); + } - void createCommand(String guiName, String alias); + default File getGuiFolder() { + return new File(this.getDataFolder(), "guis"); + } - void unloadCommands(); + default File getMacroFolder() { + return new File(this.getDataFolder(), "macros"); + } + //void unregisterNativeCommand(String commandName); } \ No newline at end of file diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/proxy/Proxy.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/proxy/Proxy.java new file mode 100644 index 000000000..ebf43f329 --- /dev/null +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/proxy/Proxy.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.proxy; + +import java.util.Locale; + +public enum Proxy { + + BUNGEECORD, + REDIS_BUNGEE, + NONE; + + public static Proxy fromString(String proxyStr) { + if (proxyStr.toLowerCase(Locale.ROOT).startsWith("bungee")) { + return Proxy.BUNGEECORD; + } else if (proxyStr.toLowerCase(Locale.ROOT).startsWith("redis")) { + return Proxy.REDIS_BUNGEE; + } + return Proxy.NONE; + } +} diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/registry/model/ModelProvider.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/registry/model/ModelProvider.java similarity index 80% rename from core/src/main/java/com/clubobsidian/dynamicgui/registry/model/ModelProvider.java rename to core/src/main/java/com/clubobsidian/dynamicgui/core/registry/model/ModelProvider.java index fc8428365..8aefb987f 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/registry/model/ModelProvider.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/registry/model/ModelProvider.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,14 @@ * limitations under the License. */ -package com.clubobsidian.dynamicgui.registry.model; +package com.clubobsidian.dynamicgui.core.registry.model; -import com.clubobsidian.dynamicgui.inventory.ItemStackWrapper; +import com.clubobsidian.dynamicgui.core.inventory.ItemStackWrapper; public interface ModelProvider { String name(); + boolean applyModel(ItemStackWrapper itemStack, String data); } \ No newline at end of file diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/registry/model/vanilla/VanillaModelProvider.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/registry/model/vanilla/VanillaModelProvider.java similarity index 77% rename from core/src/main/java/com/clubobsidian/dynamicgui/registry/model/vanilla/VanillaModelProvider.java rename to core/src/main/java/com/clubobsidian/dynamicgui/core/registry/model/vanilla/VanillaModelProvider.java index 86d4cc82f..a9b540611 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/registry/model/vanilla/VanillaModelProvider.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/registry/model/vanilla/VanillaModelProvider.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,10 +14,10 @@ * limitations under the License. */ -package com.clubobsidian.dynamicgui.registry.model.vanilla; +package com.clubobsidian.dynamicgui.core.registry.model.vanilla; -import com.clubobsidian.dynamicgui.inventory.ItemStackWrapper; -import com.clubobsidian.dynamicgui.registry.model.ModelProvider; +import com.clubobsidian.dynamicgui.core.inventory.ItemStackWrapper; +import com.clubobsidian.dynamicgui.core.registry.model.ModelProvider; import org.apache.commons.lang3.math.NumberUtils; public class VanillaModelProvider implements ModelProvider { @@ -29,7 +29,7 @@ public String name() { @Override public boolean applyModel(ItemStackWrapper itemStack, String data) { - if(!NumberUtils.isParsable(data)) { + if (!NumberUtils.isParsable(data)) { return false; } int modelData = NumberUtils.toInt(data); diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/registry/npc/NPC.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/registry/npc/NPC.java similarity index 85% rename from core/src/main/java/com/clubobsidian/dynamicgui/registry/npc/NPC.java rename to core/src/main/java/com/clubobsidian/dynamicgui/core/registry/npc/NPC.java index 7ad520f13..53bf48cc6 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/registry/npc/NPC.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/registry/npc/NPC.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.registry.npc; -import com.clubobsidian.dynamicgui.entity.EntityWrapper; +package com.clubobsidian.dynamicgui.core.registry.npc; + +import com.clubobsidian.dynamicgui.core.entity.EntityWrapper; public class NPC { diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/registry/npc/NPCMeta.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/registry/npc/NPCMeta.java similarity index 89% rename from core/src/main/java/com/clubobsidian/dynamicgui/registry/npc/NPCMeta.java rename to core/src/main/java/com/clubobsidian/dynamicgui/core/registry/npc/NPCMeta.java index e1a3d1f92..6af23588e 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/registry/npc/NPCMeta.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/registry/npc/NPCMeta.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.registry.npc; + +package com.clubobsidian.dynamicgui.core.registry.npc; public class NPCMeta { diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/registry/npc/NPCRegistry.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/registry/npc/NPCRegistry.java similarity index 81% rename from core/src/main/java/com/clubobsidian/dynamicgui/registry/npc/NPCRegistry.java rename to core/src/main/java/com/clubobsidian/dynamicgui/core/registry/npc/NPCRegistry.java index e4fb577e8..93b54061d 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/registry/npc/NPCRegistry.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/registry/npc/NPCRegistry.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.registry.npc; -import com.clubobsidian.dynamicgui.entity.EntityWrapper; +package com.clubobsidian.dynamicgui.core.registry.npc; + +import com.clubobsidian.dynamicgui.core.entity.EntityWrapper; public interface NPCRegistry { diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/registry/package-info.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/registry/package-info.java new file mode 100644 index 000000000..e1fd3d39b --- /dev/null +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/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.core.registry; diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/registry/replacer/AnimationReplacerRegistry.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/registry/replacer/AnimationReplacerRegistry.java similarity index 74% rename from core/src/main/java/com/clubobsidian/dynamicgui/registry/replacer/AnimationReplacerRegistry.java rename to core/src/main/java/com/clubobsidian/dynamicgui/core/registry/replacer/AnimationReplacerRegistry.java index f7415c1e5..8049bdd46 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/registry/replacer/AnimationReplacerRegistry.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/registry/replacer/AnimationReplacerRegistry.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.registry.replacer; -import com.clubobsidian.dynamicgui.animation.AnimationHolder; -import com.clubobsidian.dynamicgui.entity.PlayerWrapper; +package com.clubobsidian.dynamicgui.core.registry.replacer; + +import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper; +import com.clubobsidian.dynamicgui.core.gui.property.animation.AnimationHolder; public interface AnimationReplacerRegistry { diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/registry/replacer/ReplacerRegistry.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/registry/replacer/ReplacerRegistry.java similarity index 79% rename from core/src/main/java/com/clubobsidian/dynamicgui/registry/replacer/ReplacerRegistry.java rename to core/src/main/java/com/clubobsidian/dynamicgui/core/registry/replacer/ReplacerRegistry.java index d10ad3786..1522529a7 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/registry/replacer/ReplacerRegistry.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/registry/replacer/ReplacerRegistry.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.registry.replacer; -import com.clubobsidian.dynamicgui.entity.PlayerWrapper; +package com.clubobsidian.dynamicgui.core.registry.replacer; + +import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper; public interface ReplacerRegistry { diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/registry/replacer/impl/CooldownReplacerRegistry.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/registry/replacer/impl/CooldownReplacerRegistry.java similarity index 76% rename from core/src/main/java/com/clubobsidian/dynamicgui/registry/replacer/impl/CooldownReplacerRegistry.java rename to core/src/main/java/com/clubobsidian/dynamicgui/core/registry/replacer/impl/CooldownReplacerRegistry.java index 7ae241ff9..e48539c72 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/registry/replacer/impl/CooldownReplacerRegistry.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/registry/replacer/impl/CooldownReplacerRegistry.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.registry.replacer.impl; -import com.clubobsidian.dynamicgui.entity.PlayerWrapper; -import com.clubobsidian.dynamicgui.manager.dynamicgui.cooldown.Cooldown; -import com.clubobsidian.dynamicgui.manager.dynamicgui.cooldown.CooldownManager; -import com.clubobsidian.dynamicgui.registry.replacer.ReplacerRegistry; +package com.clubobsidian.dynamicgui.core.registry.replacer.impl; + +import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper; +import com.clubobsidian.dynamicgui.core.manager.dynamicgui.cooldown.Cooldown; +import com.clubobsidian.dynamicgui.core.manager.dynamicgui.cooldown.CooldownManager; +import com.clubobsidian.dynamicgui.core.registry.replacer.ReplacerRegistry; import org.apache.commons.lang3.StringUtils; import java.util.Collection; @@ -29,7 +30,7 @@ public class CooldownReplacerRegistry implements ReplacerRegistry { private static CooldownReplacerRegistry instance; public static CooldownReplacerRegistry get() { - if(instance == null) { + if (instance == null) { instance = new CooldownReplacerRegistry(); } @@ -43,32 +44,32 @@ public String replace(PlayerWrapper playerWrapper, String text) { UUID uuid = playerWrapper.getUniqueId(); Collection cooldowns = CooldownManager.get().getCooldowns(uuid); - if(cooldowns == null) { + if (cooldowns == null) { return text; } - for(Cooldown cooldown : cooldowns) { + for (Cooldown cooldown : cooldowns) { String cooldownName = cooldown.getName(); String cooldownReplacer = COOLDOWN_PREFIX + cooldownName; - if(text.contains(cooldownReplacer)) { + if (text.contains(cooldownReplacer)) { long seconds = CooldownManager.get().getRemainingCooldown(playerWrapper, cooldownName) / 1000; String hoursReplacer = COOLDOWN_PREFIX + cooldownName + "_hours%"; - if(text.contains(hoursReplacer)) { + if (text.contains(hoursReplacer)) { long hours = seconds / 3600; text = StringUtils.replace(text, hoursReplacer, String.valueOf(hours)); seconds -= hours * 3600; } String minutesReplacer = COOLDOWN_PREFIX + cooldownName + "_minutes%"; - if(text.contains(minutesReplacer)) { + if (text.contains(minutesReplacer)) { long minutes = seconds / 60; text = StringUtils.replace(text, minutesReplacer, String.valueOf(minutes)); seconds -= minutes * 60; } String secondsReplacer = COOLDOWN_PREFIX + cooldownName + "_seconds%"; - if(text.contains(secondsReplacer)) { + if (text.contains(secondsReplacer)) { text = StringUtils.replace(text, secondsReplacer, String.valueOf(seconds)); } } diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/registry/replacer/impl/DynamicGuiAnimationReplacerRegistry.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/registry/replacer/impl/DynamicGuiAnimationReplacerRegistry.java similarity index 70% rename from core/src/main/java/com/clubobsidian/dynamicgui/registry/replacer/impl/DynamicGuiAnimationReplacerRegistry.java rename to core/src/main/java/com/clubobsidian/dynamicgui/core/registry/replacer/impl/DynamicGuiAnimationReplacerRegistry.java index f20336aac..eb326a8df 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/registry/replacer/impl/DynamicGuiAnimationReplacerRegistry.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/registry/replacer/impl/DynamicGuiAnimationReplacerRegistry.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.registry.replacer.impl; - -import com.clubobsidian.dynamicgui.animation.AnimationHolder; -import com.clubobsidian.dynamicgui.entity.PlayerWrapper; -import com.clubobsidian.dynamicgui.registry.replacer.AnimationReplacerRegistry; -import com.clubobsidian.dynamicgui.replacer.AnimationReplacer; -import com.clubobsidian.dynamicgui.replacer.animation.impl.MultiLineTestAnimationReplacer; -import com.clubobsidian.dynamicgui.replacer.animation.impl.TestAnimationReplacer; + +package com.clubobsidian.dynamicgui.core.registry.replacer.impl; + +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 com.clubobsidian.dynamicgui.core.replacer.AnimationReplacer; +import com.clubobsidian.dynamicgui.core.replacer.animation.impl.MultiLineTestAnimationReplacer; +import com.clubobsidian.dynamicgui.core.replacer.animation.impl.TestAnimationReplacer; import org.apache.commons.lang3.StringUtils; import java.util.HashMap; @@ -39,7 +40,7 @@ private DynamicGuiAnimationReplacerRegistry() { } public static DynamicGuiAnimationReplacerRegistry get() { - if(instance == null) { + if (instance == null) { instance = new DynamicGuiAnimationReplacerRegistry(); } return instance; @@ -51,8 +52,8 @@ public boolean addReplacer(AnimationReplacer replacer) { @Override public String replace(AnimationHolder holder, PlayerWrapper playerWrapper, String text) { - for(AnimationReplacer replacer : this.replacers.values()) { - if(text.contains(replacer.getToReplace())) { + for (AnimationReplacer replacer : this.replacers.values()) { + if (text.contains(replacer.getToReplace())) { text = StringUtils.replace(text, replacer.getToReplace(), replacer.replacement(playerWrapper, holder, text)); } } diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/registry/replacer/impl/DynamicGuiReplacerRegistry.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/registry/replacer/impl/DynamicGuiReplacerRegistry.java similarity index 52% rename from core/src/main/java/com/clubobsidian/dynamicgui/registry/replacer/impl/DynamicGuiReplacerRegistry.java rename to core/src/main/java/com/clubobsidian/dynamicgui/core/registry/replacer/impl/DynamicGuiReplacerRegistry.java index 9966d4c01..77259ef4a 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/registry/replacer/impl/DynamicGuiReplacerRegistry.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/registry/replacer/impl/DynamicGuiReplacerRegistry.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,23 +13,21 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.clubobsidian.dynamicgui.registry.replacer.impl; -import com.clubobsidian.dynamicgui.DynamicGui; -import com.clubobsidian.dynamicgui.entity.PlayerWrapper; -import com.clubobsidian.dynamicgui.event.DynamicGuiReloadEvent; -import com.clubobsidian.dynamicgui.manager.entity.EntityManager; -import com.clubobsidian.dynamicgui.manager.material.MaterialManager; -import com.clubobsidian.dynamicgui.registry.replacer.ReplacerRegistry; -import com.clubobsidian.dynamicgui.replacer.Replacer; -import com.clubobsidian.dynamicgui.replacer.impl.GlobalPlayerCountReplacer; -import com.clubobsidian.dynamicgui.replacer.impl.OnlinePlayersReplacer; -import com.clubobsidian.dynamicgui.replacer.impl.PlayerLevelReplacer; -import com.clubobsidian.dynamicgui.replacer.impl.PlayerReplacer; -import com.clubobsidian.dynamicgui.replacer.impl.PreviousGuiReplacer; -import com.clubobsidian.dynamicgui.replacer.impl.StatisticReplacer; -import com.clubobsidian.dynamicgui.replacer.impl.UUIDReplacer; -import com.clubobsidian.dynamicgui.util.Statistic; +package com.clubobsidian.dynamicgui.core.registry.replacer.impl; + +import com.clubobsidian.dynamicgui.core.DynamicGui; +import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper; +import com.clubobsidian.dynamicgui.core.event.plugin.DynamicGuiReloadEvent; +import com.clubobsidian.dynamicgui.core.registry.replacer.ReplacerRegistry; +import com.clubobsidian.dynamicgui.core.replacer.Replacer; +import com.clubobsidian.dynamicgui.core.replacer.impl.GlobalPlayerCountReplacer; +import com.clubobsidian.dynamicgui.core.replacer.impl.OnlinePlayersReplacer; +import com.clubobsidian.dynamicgui.core.replacer.impl.PlayerLevelReplacer; +import com.clubobsidian.dynamicgui.core.replacer.impl.PlayerReplacer; +import com.clubobsidian.dynamicgui.core.replacer.impl.PreviousGuiReplacer; +import com.clubobsidian.dynamicgui.core.replacer.impl.SkinTextureReplacer; +import com.clubobsidian.dynamicgui.core.replacer.impl.UUIDReplacer; import com.clubobsidian.trident.EventHandler; import org.apache.commons.lang3.StringUtils; @@ -54,7 +52,7 @@ private DynamicGuiReplacerRegistry() { this.addReplacer(new UUIDReplacer("%uuid%")); this.addReplacer(new PlayerLevelReplacer("%player-level%")); this.addReplacer(new PreviousGuiReplacer("%previous-gui-name%")); - this.generateStatisticReplacers(); + this.addReplacer(new SkinTextureReplacer("%skin_texture%")); DynamicGui.get().getEventBus().registerEvents(this); } @@ -62,14 +60,14 @@ private DynamicGuiReplacerRegistry() { public String replace(final PlayerWrapper playerWrapper, final String text) { String newText = text; List cachedReplacerList = this.cachedReplacers.get(text); - if(cachedReplacerList != null) { - for(Replacer replacer : cachedReplacerList) { + if (cachedReplacerList != null) { + for (Replacer replacer : cachedReplacerList) { newText = StringUtils.replace(newText, replacer.getToReplace(), replacer.replacement(newText, playerWrapper)); } } else { cachedReplacerList = new ArrayList<>(); - for(Replacer replacer : this.replacers.values()) { - if(newText.contains(replacer.getToReplace())) { + for (Replacer replacer : this.replacers.values()) { + if (newText.contains(replacer.getToReplace())) { newText = StringUtils.replace(newText, replacer.getToReplace(), replacer.replacement(newText, playerWrapper)); cachedReplacerList.add(replacer); } @@ -83,7 +81,7 @@ public String replace(final PlayerWrapper playerWrapper, final String text) { } public static DynamicGuiReplacerRegistry get() { - if(instance == null) { + if (instance == null) { instance = new DynamicGuiReplacerRegistry(); } return instance; @@ -99,25 +97,4 @@ public boolean addReplacer(Replacer replacer) { public void onReload(DynamicGuiReloadEvent event) { this.cachedReplacers.clear(); } - - private void generateStatisticReplacers() { - for(Statistic statistic : Statistic.values()) { - if(statistic.getStatisticType() == Statistic.StatisticType.MATERIAL) { - for(String material : MaterialManager.get().getMaterials()) { - String lowerMaterial = material.toLowerCase(); - String replacerName = "%statistic-" + statistic.name().toLowerCase() + "-" + lowerMaterial + "%"; - this.addReplacer(new StatisticReplacer(replacerName, statistic, lowerMaterial)); - } - } else if(statistic.getStatisticType() == Statistic.StatisticType.ENTITY) { - for(String entityType : EntityManager.get().getEntityTypes()) { - String lowerEntityType = entityType.toLowerCase(); - String replacerName = "%statistic-" + statistic.name().toLowerCase() + "-" + lowerEntityType + "%"; - this.addReplacer(new StatisticReplacer(replacerName, statistic, lowerEntityType)); - } - } else { - String replacerName = "%statistic-" + statistic.name().toLowerCase() + "%"; - this.addReplacer(new StatisticReplacer(replacerName, statistic)); - } - } - } } \ No newline at end of file diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/registry/replacer/impl/MetadataReplacerRegistry.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/registry/replacer/impl/MetadataReplacerRegistry.java similarity index 73% rename from core/src/main/java/com/clubobsidian/dynamicgui/registry/replacer/impl/MetadataReplacerRegistry.java rename to core/src/main/java/com/clubobsidian/dynamicgui/core/registry/replacer/impl/MetadataReplacerRegistry.java index c2493b763..b2e949164 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/registry/replacer/impl/MetadataReplacerRegistry.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/registry/replacer/impl/MetadataReplacerRegistry.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,16 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.clubobsidian.dynamicgui.registry.replacer.impl; - -import com.clubobsidian.dynamicgui.DynamicGui; -import com.clubobsidian.dynamicgui.entity.PlayerWrapper; -import com.clubobsidian.dynamicgui.event.inventory.GuiLoadEvent; -import com.clubobsidian.dynamicgui.event.inventory.GuiPreloadEvent; -import com.clubobsidian.dynamicgui.event.inventory.InventoryCloseEvent; -import com.clubobsidian.dynamicgui.gui.Gui; -import com.clubobsidian.dynamicgui.manager.dynamicgui.GuiManager; -import com.clubobsidian.dynamicgui.registry.replacer.ReplacerRegistry; + +package com.clubobsidian.dynamicgui.core.registry.replacer.impl; + +import com.clubobsidian.dynamicgui.core.DynamicGui; +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.InventoryCloseEvent; +import com.clubobsidian.dynamicgui.core.gui.Gui; +import com.clubobsidian.dynamicgui.core.manager.dynamicgui.GuiManager; +import com.clubobsidian.dynamicgui.core.registry.replacer.ReplacerRegistry; import com.clubobsidian.trident.EventHandler; import com.clubobsidian.trident.EventPriority; import org.apache.commons.lang3.StringUtils; @@ -36,7 +37,7 @@ public class MetadataReplacerRegistry implements ReplacerRegistry { private static MetadataReplacerRegistry instance; public static MetadataReplacerRegistry get() { - if(instance == null) { + if (instance == null) { instance = new MetadataReplacerRegistry(); } @@ -55,15 +56,15 @@ private MetadataReplacerRegistry() { @Override public String replace(PlayerWrapper playerWrapper, String text) { Gui gui = this.cachedGuis.get(playerWrapper.getUniqueId()); - if(gui == null) { + if (gui == null) { return text; } - for(Map.Entry entry : gui.getMetadata().entrySet()) { + for (Map.Entry entry : gui.getMetadata().entrySet()) { String metadataKey = entry.getKey(); String metadataValue = entry.getValue(); String metadataReplacer = METADATA_PREFIX + metadataKey + "%"; - if(text.contains(metadataReplacer)) { + if (text.contains(metadataReplacer)) { text = StringUtils.replace(text, metadataReplacer, metadataValue); } } @@ -80,7 +81,7 @@ public void onGuiLoad(GuiPreloadEvent event) { @EventHandler(priority = EventPriority.HIGHEST) public void onGuiLoad(GuiLoadEvent event) { - if(event.isCancelled()) { + if (event.isCancelled()) { UUID uuid = event.getPlayerWrapper().getUniqueId(); this.cachedGuis.remove(uuid); } @@ -91,7 +92,7 @@ public void onInventoryClose(InventoryCloseEvent event) { PlayerWrapper wrapper = event.getPlayerWrapper(); UUID uuid = wrapper.getUniqueId(); Gui gui = this.cachedGuis.get(uuid); - if(gui != null && gui.equals(GuiManager.get().getCurrentGui(wrapper))) { + if (gui != null && gui.equals(GuiManager.get().getPlayerGui(wrapper))) { this.cachedGuis.remove(uuid); } } diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/replacer/AnimationReplacer.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/replacer/AnimationReplacer.java similarity index 79% rename from core/src/main/java/com/clubobsidian/dynamicgui/replacer/AnimationReplacer.java rename to core/src/main/java/com/clubobsidian/dynamicgui/core/replacer/AnimationReplacer.java index e568bb404..fb41ab282 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/replacer/AnimationReplacer.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/replacer/AnimationReplacer.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.replacer; -import com.clubobsidian.dynamicgui.animation.AnimationHolder; -import com.clubobsidian.dynamicgui.entity.PlayerWrapper; +package com.clubobsidian.dynamicgui.core.replacer; + +import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper; +import com.clubobsidian.dynamicgui.core.gui.property.animation.AnimationHolder; public abstract class AnimationReplacer { diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/replacer/Replacer.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/replacer/Replacer.java similarity index 84% rename from core/src/main/java/com/clubobsidian/dynamicgui/replacer/Replacer.java rename to core/src/main/java/com/clubobsidian/dynamicgui/core/replacer/Replacer.java index 83fac181e..74751c5d0 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/replacer/Replacer.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/replacer/Replacer.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.replacer; -import com.clubobsidian.dynamicgui.entity.PlayerWrapper; +package com.clubobsidian.dynamicgui.core.replacer; + +import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper; public abstract class Replacer { diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/replacer/animation/impl/MultiLineTestAnimationReplacer.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/replacer/animation/impl/MultiLineTestAnimationReplacer.java similarity index 74% rename from core/src/main/java/com/clubobsidian/dynamicgui/replacer/animation/impl/MultiLineTestAnimationReplacer.java rename to core/src/main/java/com/clubobsidian/dynamicgui/core/replacer/animation/impl/MultiLineTestAnimationReplacer.java index 6377f49c5..04a7813f9 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/replacer/animation/impl/MultiLineTestAnimationReplacer.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/replacer/animation/impl/MultiLineTestAnimationReplacer.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.replacer.animation.impl; -import com.clubobsidian.dynamicgui.animation.AnimationHolder; -import com.clubobsidian.dynamicgui.entity.PlayerWrapper; -import com.clubobsidian.dynamicgui.replacer.AnimationReplacer; +package com.clubobsidian.dynamicgui.core.replacer.animation.impl; + +import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper; +import com.clubobsidian.dynamicgui.core.gui.property.animation.AnimationHolder; +import com.clubobsidian.dynamicgui.core.replacer.AnimationReplacer; public class MultiLineTestAnimationReplacer extends AnimationReplacer { diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/replacer/animation/impl/TestAnimationReplacer.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/replacer/animation/impl/TestAnimationReplacer.java similarity index 73% rename from core/src/main/java/com/clubobsidian/dynamicgui/replacer/animation/impl/TestAnimationReplacer.java rename to core/src/main/java/com/clubobsidian/dynamicgui/core/replacer/animation/impl/TestAnimationReplacer.java index 004195ba9..d337ef69a 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/replacer/animation/impl/TestAnimationReplacer.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/replacer/animation/impl/TestAnimationReplacer.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.replacer.animation.impl; -import com.clubobsidian.dynamicgui.animation.AnimationHolder; -import com.clubobsidian.dynamicgui.entity.PlayerWrapper; -import com.clubobsidian.dynamicgui.replacer.AnimationReplacer; +package com.clubobsidian.dynamicgui.core.replacer.animation.impl; + +import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper; +import com.clubobsidian.dynamicgui.core.gui.property.animation.AnimationHolder; +import com.clubobsidian.dynamicgui.core.replacer.AnimationReplacer; public class TestAnimationReplacer extends AnimationReplacer { diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/replacer/impl/GlobalPlayerCountReplacer.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/replacer/impl/GlobalPlayerCountReplacer.java similarity index 69% rename from core/src/main/java/com/clubobsidian/dynamicgui/replacer/impl/GlobalPlayerCountReplacer.java rename to core/src/main/java/com/clubobsidian/dynamicgui/core/replacer/impl/GlobalPlayerCountReplacer.java index c798c8aa3..377010058 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/replacer/impl/GlobalPlayerCountReplacer.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/replacer/impl/GlobalPlayerCountReplacer.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.replacer.impl; -import com.clubobsidian.dynamicgui.DynamicGui; -import com.clubobsidian.dynamicgui.entity.PlayerWrapper; -import com.clubobsidian.dynamicgui.replacer.Replacer; +package com.clubobsidian.dynamicgui.core.replacer.impl; + +import com.clubobsidian.dynamicgui.core.DynamicGui; +import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper; +import com.clubobsidian.dynamicgui.core.replacer.Replacer; public class GlobalPlayerCountReplacer extends Replacer { @@ -27,6 +28,6 @@ public GlobalPlayerCountReplacer(String toReplace) { @Override public String replacement(String text, PlayerWrapper playerWrapper) { - return String.valueOf(DynamicGui.get().getServer().getGlobalPlayerCount()); + return String.valueOf(DynamicGui.get().getPlatform().getGlobalPlayerCount()); } } \ No newline at end of file diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/replacer/impl/OnlinePlayersReplacer.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/replacer/impl/OnlinePlayersReplacer.java similarity index 69% rename from core/src/main/java/com/clubobsidian/dynamicgui/replacer/impl/OnlinePlayersReplacer.java rename to core/src/main/java/com/clubobsidian/dynamicgui/core/replacer/impl/OnlinePlayersReplacer.java index 9b603839b..e7fc983d4 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/replacer/impl/OnlinePlayersReplacer.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/replacer/impl/OnlinePlayersReplacer.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.replacer.impl; -import com.clubobsidian.dynamicgui.DynamicGui; -import com.clubobsidian.dynamicgui.entity.PlayerWrapper; -import com.clubobsidian.dynamicgui.replacer.Replacer; +package com.clubobsidian.dynamicgui.core.replacer.impl; + +import com.clubobsidian.dynamicgui.core.DynamicGui; +import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper; +import com.clubobsidian.dynamicgui.core.replacer.Replacer; public class OnlinePlayersReplacer extends Replacer { @@ -27,6 +28,6 @@ public OnlinePlayersReplacer(String toReplace) { @Override public String replacement(String text, PlayerWrapper player) { - return String.valueOf(DynamicGui.get().getServer().getOnlinePlayers().size()); + return String.valueOf(DynamicGui.get().getPlatform().getOnlinePlayers().size()); } } \ No newline at end of file diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/replacer/impl/PlayerLevelReplacer.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/replacer/impl/PlayerLevelReplacer.java similarity index 79% rename from core/src/main/java/com/clubobsidian/dynamicgui/replacer/impl/PlayerLevelReplacer.java rename to core/src/main/java/com/clubobsidian/dynamicgui/core/replacer/impl/PlayerLevelReplacer.java index fc3a610d1..f3f14f453 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/replacer/impl/PlayerLevelReplacer.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/replacer/impl/PlayerLevelReplacer.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.replacer.impl; -import com.clubobsidian.dynamicgui.entity.PlayerWrapper; -import com.clubobsidian.dynamicgui.replacer.Replacer; +package com.clubobsidian.dynamicgui.core.replacer.impl; + +import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper; +import com.clubobsidian.dynamicgui.core.replacer.Replacer; public class PlayerLevelReplacer extends Replacer { diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/replacer/impl/PlayerReplacer.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/replacer/impl/PlayerReplacer.java similarity index 78% rename from core/src/main/java/com/clubobsidian/dynamicgui/replacer/impl/PlayerReplacer.java rename to core/src/main/java/com/clubobsidian/dynamicgui/core/replacer/impl/PlayerReplacer.java index 94d6fbe3a..671b549ec 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/replacer/impl/PlayerReplacer.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/replacer/impl/PlayerReplacer.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.replacer.impl; -import com.clubobsidian.dynamicgui.entity.PlayerWrapper; -import com.clubobsidian.dynamicgui.replacer.Replacer; +package com.clubobsidian.dynamicgui.core.replacer.impl; + +import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper; +import com.clubobsidian.dynamicgui.core.replacer.Replacer; public class PlayerReplacer extends Replacer { diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/replacer/impl/PreviousGuiReplacer.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/replacer/impl/PreviousGuiReplacer.java similarity index 73% rename from core/src/main/java/com/clubobsidian/dynamicgui/replacer/impl/PreviousGuiReplacer.java rename to core/src/main/java/com/clubobsidian/dynamicgui/core/replacer/impl/PreviousGuiReplacer.java index 348006a4e..8e98d0583 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/replacer/impl/PreviousGuiReplacer.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/replacer/impl/PreviousGuiReplacer.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,16 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.clubobsidian.dynamicgui.replacer.impl; -import com.clubobsidian.dynamicgui.DynamicGui; -import com.clubobsidian.dynamicgui.entity.PlayerWrapper; -import com.clubobsidian.dynamicgui.event.inventory.GuiLoadEvent; -import com.clubobsidian.dynamicgui.event.inventory.GuiPreloadEvent; -import com.clubobsidian.dynamicgui.event.inventory.InventoryCloseEvent; -import com.clubobsidian.dynamicgui.gui.Gui; -import com.clubobsidian.dynamicgui.manager.dynamicgui.GuiManager; -import com.clubobsidian.dynamicgui.replacer.Replacer; +package com.clubobsidian.dynamicgui.core.replacer.impl; + +import com.clubobsidian.dynamicgui.core.DynamicGui; +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.InventoryCloseEvent; +import com.clubobsidian.dynamicgui.core.gui.Gui; +import com.clubobsidian.dynamicgui.core.manager.dynamicgui.GuiManager; +import com.clubobsidian.dynamicgui.core.replacer.Replacer; import com.clubobsidian.trident.EventHandler; import com.clubobsidian.trident.EventPriority; @@ -43,12 +44,12 @@ public PreviousGuiReplacer(String toReplace) { public String replacement(String text, PlayerWrapper playerWrapper) { Gui gui = this.cachedGuis.get(playerWrapper.getUniqueId()); System.out.println("gui: " + gui); - if(gui == null) { + if (gui == null) { return null; } Gui prev = gui.getBack(); System.out.println("prev: " + prev); - if(prev == null) { + if (prev == null) { return null; } return prev.getName(); @@ -63,7 +64,7 @@ public void onGuiLoad(GuiPreloadEvent event) { @EventHandler(priority = EventPriority.HIGHEST) public void onGuiLoad(GuiLoadEvent event) { - if(event.isCancelled()) { + if (event.isCancelled()) { UUID uuid = event.getPlayerWrapper().getUniqueId(); this.cachedGuis.remove(uuid); } @@ -74,7 +75,7 @@ public void onInventoryClose(InventoryCloseEvent event) { PlayerWrapper wrapper = event.getPlayerWrapper(); UUID uuid = wrapper.getUniqueId(); Gui gui = this.cachedGuis.get(uuid); - if(gui != null && gui.equals(GuiManager.get().getCurrentGui(wrapper))) { + if (gui != null && gui.equals(GuiManager.get().getPlayerGui(wrapper))) { this.cachedGuis.remove(uuid); } } diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/replacer/impl/SkinTextureReplacer.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/replacer/impl/SkinTextureReplacer.java new file mode 100644 index 000000000..5d8338695 --- /dev/null +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/replacer/impl/SkinTextureReplacer.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.core.replacer.impl; + +import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper; +import com.clubobsidian.dynamicgui.core.replacer.Replacer; +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.Caffeine; + +import java.util.UUID; +import java.util.concurrent.TimeUnit; + +public class SkinTextureReplacer extends Replacer { + + private static final String DEFAULT_SKIN_TEXTURE = "ewogICJ0aW1lc3RhbXAiIDogMTY0ODUzNDUwMjUwOCwKIC" + + "AicHJvZmlsZUlkIiA6ICJlYzU2MTUzOGYzZmQ0NjFkYWZmNTA4NmIyMjE1NGJjZSIsCiAgInByb2ZpbGVOYW1lIiA" + + "6ICJBbGV4IiwKICAidGV4dHVyZXMiIDogewogICAgIlNLSU4iIDogewogICAgICAidXJsIiA6ICJodHRwOi8vdGV4" + + "dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlLzFhNGFmNzE4NDU1ZDRhYWI1MjhlN2E2MWY4NmZhMjVlNmEzNjlkM" + + "Tc2OGRjYjEzZjdkZjMxOWE3MTNlYjgxMGIiCiAgICB9CiAgfQp9"; + + private final Cache textureCache = Caffeine + .newBuilder() + .expireAfterWrite(5, TimeUnit.MINUTES) + .build(); + + public SkinTextureReplacer(String toReplace) { + super(toReplace); + } + + @Override + public String replacement(String text, PlayerWrapper playerWrapper) { + UUID uuid = playerWrapper.getUniqueId(); + String texture = this.textureCache.get(uuid, (key) -> playerWrapper.getSkinTexture()); + return texture == null ? DEFAULT_SKIN_TEXTURE : texture; + } +} diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/replacer/impl/UUIDReplacer.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/replacer/impl/UUIDReplacer.java similarity index 78% rename from core/src/main/java/com/clubobsidian/dynamicgui/replacer/impl/UUIDReplacer.java rename to core/src/main/java/com/clubobsidian/dynamicgui/core/replacer/impl/UUIDReplacer.java index 85167b91b..b560e9b8a 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/replacer/impl/UUIDReplacer.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/replacer/impl/UUIDReplacer.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.replacer.impl; -import com.clubobsidian.dynamicgui.entity.PlayerWrapper; -import com.clubobsidian.dynamicgui.replacer.Replacer; +package com.clubobsidian.dynamicgui.core.replacer.impl; + +import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper; +import com.clubobsidian.dynamicgui.core.replacer.Replacer; public class UUIDReplacer extends Replacer { diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/scheduler/Scheduler.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/scheduler/Scheduler.java similarity index 53% rename from core/src/main/java/com/clubobsidian/dynamicgui/scheduler/Scheduler.java rename to core/src/main/java/com/clubobsidian/dynamicgui/core/scheduler/Scheduler.java index 2652684a9..e1db2af03 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/scheduler/Scheduler.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/scheduler/Scheduler.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.scheduler; -import com.clubobsidian.dynamicgui.plugin.DynamicGuiPlugin; +package com.clubobsidian.dynamicgui.core.scheduler; public abstract class Scheduler { - public abstract void scheduleSyncDelayedTask(DynamicGuiPlugin plugin, Runnable runnable, Long delay); + public abstract void runSyncDelayedTask(Runnable runnable, long delay); - public abstract void scheduleSyncRepeatingTask(DynamicGuiPlugin plugin, Runnable runnable, Long delayInitial, Long delayRepeating); + public abstract void runAsynchronousDelayedTask(Runnable runnable, long delay); - public abstract void scheduleAsyncRepeatingTask(DynamicGuiPlugin plugin, Runnable runnable, Long delayInitial, Long delayRepeating); + public abstract void scheduleSyncRepeatingTask(Runnable runnable, long delayInitial, long delayRepeating); + + public abstract void scheduleAsyncRepeatingTask(Runnable runnable, long delayInitial, long delayRepeating); } \ No newline at end of file diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/util/ChatColor.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/util/ChatColor.java new file mode 100644 index 000000000..ede299b74 --- /dev/null +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/util/ChatColor.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.util; + +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; + +public class ChatColor { + + public static final char SECTION_CODE = '\u00A7'; + + private static final LegacyComponentSerializer AMPERSAND = LegacyComponentSerializer.builder() + .hexColors() + .useUnusualXRepeatedCharacterHexFormat() + .character('&') + .build(); + private static final LegacyComponentSerializer SECTION = LegacyComponentSerializer.builder() + .hexColors() + .useUnusualXRepeatedCharacterHexFormat() + .character(SECTION_CODE) + .build(); + + public static String translateAlternateColorCodes(String message) { + return SECTION.serialize(AMPERSAND.deserialize(message)); + } +} \ No newline at end of file diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/util/HashUtil.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/util/HashUtil.java similarity index 89% rename from core/src/main/java/com/clubobsidian/dynamicgui/util/HashUtil.java rename to core/src/main/java/com/clubobsidian/dynamicgui/core/util/HashUtil.java index 6b622d17b..1e8582f16 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/util/HashUtil.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/util/HashUtil.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.util; + +package com.clubobsidian.dynamicgui.core.util; import java.io.File; import java.io.IOException; @@ -38,7 +39,7 @@ private static byte[] getHash(String hash, File file) { try { byte[] fileBytes = Files.readAllBytes(file.toPath()); return getHash(hash, fileBytes); - } catch(IOException e) { + } catch (IOException e) { e.printStackTrace(); } return new byte[0]; @@ -50,7 +51,7 @@ private static byte[] getHash(String hash, byte[] data) { md.reset(); md.update(data); return md.digest(); - } catch(NoSuchAlgorithmException e) { + } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return new byte[0]; diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/util/ReflectionUtil.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/util/ReflectionUtil.java new file mode 100644 index 000000000..b50c3de86 --- /dev/null +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/util/ReflectionUtil.java @@ -0,0 +1,180 @@ +/* + * 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.util; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.Arrays; + +public final class ReflectionUtil { + + private ReflectionUtil() { + } + + public static boolean classExists(String className) { + try { + Class.forName(className); + return true; + } catch (ClassNotFoundException e) { + return false; + } + } + + + public static Class getClassIfExists(String... clazzes) { + for (String className : clazzes) { + try { + return Class.forName(className); + } catch (ClassNotFoundException e) { + } + } + return null; + } + + public static Class classForName(String name) { + try { + return Class.forName(name); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + return null; + } + + public static Method getMethod(Class cl, String methodName) { + try { + Method method = cl.getDeclaredMethod(methodName); + method.setAccessible(true); + return method; + } catch (NoSuchMethodException | SecurityException e) { + e.printStackTrace(); + } + return null; + } + + public static Method getMethod(Class cl, String... methods) { + for (Method m : cl.getDeclaredMethods()) { + for (String methodName : methods) { + if(m.getName().equals(methodName)) { + return m; + } + } + } + return null; + } + + public static Method getMethod(Class cl, String methodName, Class... params) { + try { + Method method = cl.getDeclaredMethod(methodName, params); + method.setAccessible(true); + return method; + } catch (NoSuchMethodException | SecurityException e) { + e.printStackTrace(); + } + return null; + } + + public static Method getMethodByReturnType(Class searchIn, Class returnType) { + for (Method m : searchIn.getDeclaredMethods()) { + if (m.getReturnType().equals(returnType)) { + m.setAccessible(true); + return m; + } + } + return null; + } + + public static T get(Object getFrom, Class searchIn, String name) { + try { + return (T) getFieldByName(searchIn, name).get(getFrom); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + return null; + } + + public static Field getFieldByName(Class searchIn, String name) { + try { + Field f = searchIn.getDeclaredField(name); + f.setAccessible(true); + return f; + } catch (NoSuchFieldException | SecurityException e) { + return null; + } + } + + public static Field getFieldByType(Class searchIn, Class fieldType) { + for (Field f : searchIn.getDeclaredFields()) { + if (f.getType().equals(fieldType)) { + f.setAccessible(true); + return f; + } + } + return null; + } + + public static Field getDeclaredField(Class clazz, String... fields) { + for (String fieldName : fields) { + try { + Field field = clazz.getDeclaredField(fieldName); + field.setAccessible(true); + return field; + } catch (NoSuchFieldException e) { + } + } + return null; + } + + public static Field getDeclaredField(Object fieldIn, Class clazz, Class returnType, String... fields) { + for (Field field : clazz.getDeclaredFields()) { + for (String fieldName : fields) { + try { + if (fieldName.equals(field.getName())) { + field.setAccessible(true); + Object got = field.get(fieldIn); + if (got.getClass().equals(returnType)) { + return field; + } + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + } + return null; + } + + public static Method getStaticMethod(Class searchIn, Class returnType) { + for (Method m : searchIn.getDeclaredMethods()) { + if (Modifier.isStatic(m.getModifiers()) && m.getReturnType().equals(returnType)) { + return m; + } + } + return null; + } + + public static Method getMethod(Class searchIn, Class returnType, Class... params) { + for (Method m : searchIn.getDeclaredMethods()) { + if (m.getReturnType().equals(returnType)) { + if (Arrays.equals(m.getParameterTypes(), params)) { + return m; + } + } + } + return null; + } +} \ No newline at end of file diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/util/ThreadUtil.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/util/ThreadUtil.java new file mode 100644 index 000000000..e73a5ba2a --- /dev/null +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/util/ThreadUtil.java @@ -0,0 +1,41 @@ +/* + * 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.util; + +import com.clubobsidian.dynamicgui.core.DynamicGui; +import com.clubobsidian.dynamicgui.core.platform.Platform; +import com.clubobsidian.dynamicgui.core.scheduler.Scheduler; + +public final class ThreadUtil { + + public static void run(Runnable runnable, boolean async) { + Platform server = DynamicGui.get().getPlatform(); + Scheduler scheduler = server.getScheduler(); + if (async) { + scheduler.runAsynchronousDelayedTask(runnable, 0); + } else { + if (!server.isMainThread()) { + scheduler.runSyncDelayedTask(runnable, 0); + } else { + runnable.run(); + } + } + } + + private ThreadUtil() { + } +} diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/world/LocationWrapper.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/world/LocationWrapper.java similarity index 85% rename from core/src/main/java/com/clubobsidian/dynamicgui/world/LocationWrapper.java rename to core/src/main/java/com/clubobsidian/dynamicgui/core/world/LocationWrapper.java index c012052a0..4f167f76a 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/world/LocationWrapper.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/world/LocationWrapper.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.world; + +package com.clubobsidian.dynamicgui.core.world; import java.io.Serializable; @@ -60,17 +61,17 @@ public String toString() { @Override public boolean equals(Object obj) { - if(obj == null) + if (obj == null) return false; - if(!(obj instanceof LocationWrapper)) + if (!(obj instanceof LocationWrapper)) return false; LocationWrapper other = (LocationWrapper) obj; - if(other.getX() != this.getX()) + if (other.getX() != this.getX()) return false; - if(other.getY() != this.getY()) + if (other.getY() != this.getY()) return false; - if(other.getZ() != this.getZ()) + if (other.getZ() != this.getZ()) return false; return other.getWorld().equals(this.world); diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/world/WorldWrapper.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/world/WorldWrapper.java similarity index 84% rename from core/src/main/java/com/clubobsidian/dynamicgui/world/WorldWrapper.java rename to core/src/main/java/com/clubobsidian/dynamicgui/core/world/WorldWrapper.java index 70c975d93..1d01a44e0 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/world/WorldWrapper.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/world/WorldWrapper.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.world; + +package com.clubobsidian.dynamicgui.core.world; import java.io.Serializable; @@ -36,7 +37,7 @@ public String getName() { public abstract T getWorld(); - public abstract void setGameRule(String rule, String value); + public abstract void setGameRule(String key, String value); public abstract String getGameRule(String rule); @@ -51,17 +52,17 @@ public int hashCode() { @Override @SuppressWarnings("unchecked") public boolean equals(Object obj) { - if(this == obj) { + if (this == obj) { return true; - } else if(obj == null) { + } else if (obj == null) { return false; - } else if(getClass() != obj.getClass()) { + } else if (getClass() != obj.getClass()) { return false; } WorldWrapper otherWrapper = (WorldWrapper) obj; T world = this.getWorld(); - if(world == null) { + if (world == null) { return false; } diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/effect/ParticleWrapper.java b/core/src/main/java/com/clubobsidian/dynamicgui/effect/ParticleWrapper.java deleted file mode 100644 index 4060d0e50..000000000 --- a/core/src/main/java/com/clubobsidian/dynamicgui/effect/ParticleWrapper.java +++ /dev/null @@ -1,49 +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.effect; - -import com.clubobsidian.dynamicgui.entity.PlayerWrapper; - -import java.io.Serializable; - -public class ParticleWrapper implements Serializable { - - /** - * - */ - private static final long serialVersionUID = -5003322741003989392L; - private String effect; - private int data; - - public ParticleWrapper(String str) { - this.loadFromString(str); - } - - private void loadFromString(String str) { - if(str.contains(",")) { - String[] args = str.split(","); - this.effect = args[0].toUpperCase(); - this.data = Integer.parseInt(args[1]); - } else { - this.effect = str; - this.data = 0; - } - } - - public void spawnEffect(PlayerWrapper player) { - player.playEffect(this.effect.toUpperCase(), this.data); - } -} \ No newline at end of file diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/Function.java b/core/src/main/java/com/clubobsidian/dynamicgui/function/Function.java deleted file mode 100644 index 81e24bb93..000000000 --- a/core/src/main/java/com/clubobsidian/dynamicgui/function/Function.java +++ /dev/null @@ -1,82 +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.function; - -import com.clubobsidian.dynamicgui.entity.PlayerWrapper; -import com.clubobsidian.dynamicgui.gui.FunctionOwner; -import com.clubobsidian.fuzzutil.StringFuzz; -import org.apache.commons.lang3.SerializationUtils; - -import java.io.Serializable; - -public abstract class Function implements Cloneable, Serializable { - - /** - * - */ - private static final long serialVersionUID = 1492427006104061443L; - private final String name; - private String data; - private FunctionOwner owner; - private int index = -1; - - public Function(String name, String data) { - this.name = StringFuzz.normalize(name); - this.data = data; - } - - public Function(String name) { - this(name, null); - } - - public Function(Function function) { - this(function.getName(), function.getData()); - } - - public abstract boolean function(PlayerWrapper playerWrapper); - - public String getName() { - return this.name; - } - - public String getData() { - return this.data; - } - - public void setData(String data) { - this.data = data; - } - - public void setOwner(FunctionOwner slot) { - this.owner = slot; - } - - 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); - } -} \ No newline at end of file diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/ExpPayFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/ExpPayFunction.java deleted file mode 100644 index 4327b6c1b..000000000 --- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/ExpPayFunction.java +++ /dev/null @@ -1,51 +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.function.impl; - -import com.clubobsidian.dynamicgui.DynamicGui; -import com.clubobsidian.dynamicgui.entity.PlayerWrapper; -import com.clubobsidian.dynamicgui.function.Function; - -public class ExpPayFunction extends Function { - - /** - * - */ - private static final long serialVersionUID = -2383762506458369815L; - - public ExpPayFunction(String name) { - super(name); - } - - @Override - public boolean function(PlayerWrapper playerWrapper) { - int amt; - try { - amt = Integer.parseInt(this.getData()); - } catch(Exception ex) { - DynamicGui.get().getLogger().info("Experience is set to an invalid number for data " + this.getData() + ", failing gracefully!"); - return false; - } - System.out.println("Exp: " + playerWrapper.getExperience()); - if(playerWrapper.getExperience() < amt) { - return false; - } - - playerWrapper.setExperience(playerWrapper.getExperience() - amt); - return true; - - } -} \ No newline at end of file diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/SetAmountFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/SetAmountFunction.java deleted file mode 100644 index 0194589bd..000000000 --- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/SetAmountFunction.java +++ /dev/null @@ -1,64 +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.function.impl; - -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.inventory.InventoryWrapper; -import com.clubobsidian.dynamicgui.inventory.ItemStackWrapper; - -public class SetAmountFunction extends Function { - - /** - * - */ - private static final long serialVersionUID = 6943230273788425141L; - - public SetAmountFunction(String name) { - super(name); - } - - @Override - public boolean function(PlayerWrapper playerWrapper) { - FunctionOwner owner = this.getOwner(); - if(owner != null) { - if(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/function/impl/SetCloseFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/SetCloseFunction.java deleted file mode 100644 index 0e2eab335..000000000 --- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/SetCloseFunction.java +++ /dev/null @@ -1,56 +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.function.impl; - -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; - -public class SetCloseFunction extends Function { - - /** - * - */ - private static final long serialVersionUID = -5671625221707551692L; - - public SetCloseFunction(String name) { - super(name); - } - - @Override - public boolean function(PlayerWrapper playerWrapper) { - try { - Boolean value = Boolean.valueOf(this.getData()); - if(value != null) { - if(this.getOwner() instanceof Slot) { - Slot slot = (Slot) this.getOwner(); - slot.setClose(value); - return true; - } else if(this.getOwner() instanceof Gui) { - Gui gui = (Gui) this.getOwner(); - gui.setClose(value); - return true; - } - } - } catch(Exception ex) { - DynamicGui.get().getLogger().info("Error parsing value " + this.getData() + " for setclose function"); - ex.printStackTrace(); - } - return false; - } -} diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/SetDataFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/SetDataFunction.java deleted file mode 100644 index 8c538407a..000000000 --- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/SetDataFunction.java +++ /dev/null @@ -1,65 +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.function.impl; - -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.inventory.InventoryWrapper; -import com.clubobsidian.dynamicgui.inventory.ItemStackWrapper; - -public class SetDataFunction extends Function { - - /** - * - */ - private static final long serialVersionUID = 6943230273788425141L; - - public SetDataFunction(String name) { - super(name); - } - - @Override - public boolean function(PlayerWrapper playerWrapper) { - FunctionOwner owner = this.getOwner(); - if(owner != null) { - if(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 dura = Short.parseShort(this.getData()); - item.setDurability(dura); - 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/function/impl/SetEnchantsFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/SetEnchantsFunction.java deleted file mode 100644 index e3872847c..000000000 --- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/SetEnchantsFunction.java +++ /dev/null @@ -1,81 +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.function.impl; - -import com.clubobsidian.dynamicgui.enchantment.EnchantmentWrapper; -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; - -import java.util.HashMap; -import java.util.Map; - -public class SetEnchantsFunction extends Function { - - - /** - * - */ - private static final long serialVersionUID = 8291956007296368761L; - - public SetEnchantsFunction(String name) { - super(name); - } - - @Override - public boolean function(PlayerWrapper playerWrapper) { - FunctionOwner owner = this.getOwner(); - if(owner != null) { - if(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 ench : item.getEnchants()) { - item.removeEnchant(ench); - } - - 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/SetGlowFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/SetGlowFunction.java deleted file mode 100644 index 0fa912051..000000000 --- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/SetGlowFunction.java +++ /dev/null @@ -1,68 +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.function.impl; - -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.inventory.InventoryWrapper; -import com.clubobsidian.dynamicgui.inventory.ItemStackWrapper; - -public class SetGlowFunction extends Function { - - /** - * - */ - private static final long serialVersionUID = -3727112026677117024L; - - public SetGlowFunction(String name) { - super(name); - } - - @Override - public boolean function(PlayerWrapper playerWrapper) { - try { - Boolean value = Boolean.valueOf(this.getData()); - if(value != null) { - FunctionOwner owner = this.getOwner(); - if(owner != null) { - if(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.setGlowing(value); - inv.setItem(slot.getIndex(), item); - return true; - } - } - } - } - } - } catch(Exception ex) { - DynamicGui.get().getLogger().info("Unable to parse + " + this.getData() + " as a glow"); - ex.printStackTrace(); - } - - return false; - } -} \ No newline at end of file diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/SetLoreFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/SetLoreFunction.java deleted file mode 100644 index 7eba63d03..000000000 --- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/SetLoreFunction.java +++ /dev/null @@ -1,83 +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.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; -import com.clubobsidian.dynamicgui.manager.dynamicgui.AnimationReplacerManager; -import com.clubobsidian.dynamicgui.manager.dynamicgui.ReplacerManager; -import com.clubobsidian.dynamicgui.util.ChatColor; - -import java.util.ArrayList; -import java.util.List; - -public class SetLoreFunction extends Function { - - - /** - * - */ - private static final long serialVersionUID = -6723628078978301156L; - - public SetLoreFunction(String name) { - super(name); - } - - @Override - public boolean function(PlayerWrapper playerWrapper) { - FunctionOwner owner = this.getOwner(); - if(owner != null) { - if(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 = this.getData(); - newData = ReplacerManager.get().replace(ChatColor.translateAlternateColorCodes('&', this.getData()), playerWrapper); - newData = AnimationReplacerManager.get().replace(slot, playerWrapper, 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/function/impl/SetMoveableFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/SetMoveableFunction.java deleted file mode 100644 index 7fe04c478..000000000 --- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/SetMoveableFunction.java +++ /dev/null @@ -1,57 +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.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; - -public class SetMoveableFunction extends Function { - - /** - * - */ - private static final long serialVersionUID = 453447798953153174L; - - public SetMoveableFunction(String name) { - super(name); - } - - @Override - public boolean function(PlayerWrapper playerWrapper) { - if(this.getOwner() instanceof Slot) { - Boolean value = Boolean.valueOf(this.getData()); - if(value != null) { - FunctionOwner owner = this.getOwner(); - if(owner != null) { - if(owner instanceof Slot) { - Slot slot = (Slot) owner; - Gui gui = slot.getOwner(); - if(gui != null) { - slot.setMoveable(value); - return true; - } - } - } - } - } - - return false; - } -} \ No newline at end of file diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/SetNBTFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/SetNBTFunction.java deleted file mode 100644 index bf319e3ef..000000000 --- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/SetNBTFunction.java +++ /dev/null @@ -1,57 +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.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; - -public class SetNBTFunction extends Function { - - /** - * - */ - private static final long serialVersionUID = 6943230273788425141L; - - public SetNBTFunction(String name) { - super(name); - } - - @Override - public boolean function(PlayerWrapper playerWrapper) { - FunctionOwner owner = this.getOwner(); - if(owner != null) { - if(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/function/impl/SetNameFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/SetNameFunction.java deleted file mode 100644 index bc50c6a28..000000000 --- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/SetNameFunction.java +++ /dev/null @@ -1,63 +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.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; -import com.clubobsidian.dynamicgui.manager.dynamicgui.AnimationReplacerManager; -import com.clubobsidian.dynamicgui.manager.dynamicgui.ReplacerManager; -import com.clubobsidian.dynamicgui.util.ChatColor; - -public class SetNameFunction extends Function { - - /** - * - */ - private static final long serialVersionUID = -5599516930903780834L; - - public SetNameFunction(String name) { - super(name); - } - - @Override - public boolean function(PlayerWrapper playerWrapper) { - FunctionOwner owner = this.getOwner(); - if(owner != null) { - if(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/function/impl/SetTypeFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/SetTypeFunction.java deleted file mode 100644 index 412ba02f6..000000000 --- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/SetTypeFunction.java +++ /dev/null @@ -1,58 +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.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; - -public class SetTypeFunction extends Function { - - /** - * - */ - private static final long serialVersionUID = 6943230273788425141L; - - public SetTypeFunction(String name) { - super(name); - } - - @Override - public boolean function(PlayerWrapper playerWrapper) { - FunctionOwner owner = this.getOwner(); - - if(owner != null) { - if(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/StatisticFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/StatisticFunction.java deleted file mode 100644 index 5c35c0375..000000000 --- a/core/src/main/java/com/clubobsidian/dynamicgui/function/impl/StatisticFunction.java +++ /dev/null @@ -1,60 +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.function.impl; - -import com.clubobsidian.dynamicgui.entity.PlayerWrapper; -import com.clubobsidian.dynamicgui.function.Function; -import com.clubobsidian.dynamicgui.util.Statistic; -import com.clubobsidian.dynamicgui.util.Statistic.StatisticType; - -public class StatisticFunction extends Function { - - /** - * - */ - private static final long serialVersionUID = -8624786841614185001L; - - public StatisticFunction(String name) { - super(name); - } - - @Override - public boolean function(PlayerWrapper playerWrapper) { - String[] split = this.getData().split(","); - String statisticString = null; - - if(split.length >= 2) - statisticString = split[0].toUpperCase(); - - if(statisticString == null) - return false; - - if(split.length == 3) { - Statistic stat = Statistic.valueOf(statisticString); - String type = split[1]; - Integer num = Integer.parseInt(split[2]); - - if(stat.getStatisticType() != StatisticType.NONE) { - return playerWrapper.getStatistic(stat, type) >= num; - } - } else if(split.length == 2) { - Statistic stat = Statistic.valueOf(split[0]); - Integer num = Integer.parseInt(split[1]); - return playerWrapper.getStatistic(stat) >= num; - } - return false; - } -} \ No newline at end of file diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/inject/module/PluginModule.java b/core/src/main/java/com/clubobsidian/dynamicgui/inject/module/PluginModule.java deleted file mode 100644 index de2b2e91d..000000000 --- a/core/src/main/java/com/clubobsidian/dynamicgui/inject/module/PluginModule.java +++ /dev/null @@ -1,107 +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.inject.module; - -import com.clubobsidian.dynamicgui.DynamicGui; -import com.clubobsidian.dynamicgui.logger.LoggerWrapper; -import com.clubobsidian.dynamicgui.manager.entity.EntityManager; -import com.clubobsidian.dynamicgui.manager.inventory.InventoryManager; -import com.clubobsidian.dynamicgui.manager.inventory.ItemStackManager; -import com.clubobsidian.dynamicgui.manager.material.MaterialManager; -import com.clubobsidian.dynamicgui.manager.world.LocationManager; -import com.clubobsidian.dynamicgui.plugin.DynamicGuiPlugin; -import com.clubobsidian.dynamicgui.server.FakeServer; -import com.google.inject.Binder; -import com.google.inject.Guice; -import com.google.inject.Module; -import com.google.inject.TypeLiteral; - -public class PluginModule implements Module { - - private Class entityClass; - private Class inventoryClass; - private Class itemStackClass; - private Class materialClass; - private Class locationClass; - private DynamicGuiPlugin plugin; - private FakeServer fakeServer; - private LoggerWrapper loggerWrapper; - - public PluginModule setEntity(Class clazz) { - this.entityClass = clazz; - return this; - } - - public PluginModule setInventory(Class clazz) { - this.inventoryClass = clazz; - return this; - } - - public PluginModule setItemStack(Class clazz) { - this.itemStackClass = clazz; - return this; - } - - public PluginModule setMaterial(Class clazz) { - this.materialClass = clazz; - return this; - } - - public PluginModule setLocation(Class clazz) { - this.locationClass = clazz; - return this; - } - - public PluginModule setPlugin(DynamicGuiPlugin plugin) { - this.plugin = plugin; - return this; - } - - public PluginModule setServer(FakeServer server) { - this.fakeServer = server; - return this; - } - - public PluginModule setLogger(LoggerWrapper logger) { - this.loggerWrapper = logger; - return this; - } - - @Override - public void configure(Binder binder) { - 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(FakeServer.class).toInstance(this.fakeServer); - binder.bind(new TypeLiteral>() { - }).toInstance(this.loggerWrapper); - - binder.requestStaticInjection(EntityManager.class); - binder.requestStaticInjection(InventoryManager.class); - binder.requestStaticInjection(ItemStackManager.class); - binder.requestStaticInjection(MaterialManager.class); - binder.requestStaticInjection(LocationManager.class); - binder.requestStaticInjection(DynamicGui.class); - } - - public boolean bootstrap() { - Guice.createInjector(this); - return DynamicGui.get() != null; - } -} \ No newline at end of file diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/listener/GuiListener.java b/core/src/main/java/com/clubobsidian/dynamicgui/listener/GuiListener.java deleted file mode 100644 index 281da5e3a..000000000 --- a/core/src/main/java/com/clubobsidian/dynamicgui/listener/GuiListener.java +++ /dev/null @@ -1,63 +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.listener; - -import com.clubobsidian.dynamicgui.entity.PlayerWrapper; -import com.clubobsidian.dynamicgui.event.inventory.GuiLoadEvent; -import com.clubobsidian.dynamicgui.event.inventory.InventoryCloseEvent; -import com.clubobsidian.dynamicgui.gui.Gui; -import com.clubobsidian.dynamicgui.manager.dynamicgui.GuiManager; -import com.clubobsidian.dynamicgui.parser.function.FunctionType; -import com.clubobsidian.dynamicgui.util.FunctionUtil; -import com.clubobsidian.trident.EventHandler; - -import java.util.HashSet; -import java.util.Set; -import java.util.UUID; - -public class GuiListener { - - private final Set users; - - public GuiListener() { - this.users = new HashSet<>(); - } - - @EventHandler - public void onGuiOpen(GuiLoadEvent event) { - PlayerWrapper wrapper = event.getPlayerWrapper(); - Gui gui = GuiManager.get().getCurrentGui(wrapper); - PlayerWrapper playerWrapper = event.getPlayerWrapper(); - boolean open = (gui != null); - if(open) { - UUID uuid = wrapper.getUniqueId(); - this.users.add(uuid); - FunctionUtil.tryFunctions(gui, FunctionType.SWITCH_MENU, playerWrapper); - } - } - - @EventHandler - public void onClose(InventoryCloseEvent event) { - PlayerWrapper playerWrapper = event.getPlayerWrapper(); - UUID uuid = playerWrapper.getUniqueId(); - if(!this.users.remove(uuid)) { - Gui gui = GuiManager.get().getCurrentGui(playerWrapper); - if(gui != null) { - FunctionUtil.tryFunctions(gui, FunctionType.EXIT_MENU, playerWrapper); - } - } - } -} \ No newline at end of file diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/listener/InventoryInteractListener.java b/core/src/main/java/com/clubobsidian/dynamicgui/listener/InventoryInteractListener.java deleted file mode 100644 index fd243e719..000000000 --- a/core/src/main/java/com/clubobsidian/dynamicgui/listener/InventoryInteractListener.java +++ /dev/null @@ -1,154 +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.listener; - -import com.clubobsidian.dynamicgui.entity.PlayerWrapper; -import com.clubobsidian.dynamicgui.event.inventory.Click; -import com.clubobsidian.dynamicgui.event.inventory.InventoryClickEvent; -import com.clubobsidian.dynamicgui.event.inventory.InventoryDragEvent; -import com.clubobsidian.dynamicgui.gui.Gui; -import com.clubobsidian.dynamicgui.gui.InventoryView; -import com.clubobsidian.dynamicgui.gui.Slot; -import com.clubobsidian.dynamicgui.inventory.InventoryWrapper; -import com.clubobsidian.dynamicgui.inventory.ItemStackWrapper; -import com.clubobsidian.dynamicgui.manager.dynamicgui.GuiManager; -import com.clubobsidian.dynamicgui.parser.function.FunctionType; -import com.clubobsidian.dynamicgui.parser.function.tree.FunctionNode; -import com.clubobsidian.dynamicgui.util.FunctionUtil; -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().getCurrentGui(player); - - Slot slot = this.getSlotFromIndex(gui, e.getSlot()); - if(slot == null && e.getView() != InventoryView.BOTTOM) { - e.setCancelled(true); - return; - } - - ItemStackWrapper item = e.getItemStackWrapper(); - if(e.getClick() == null) //For other types of clicks besides left, right, middle - { - e.setCancelled(true); - 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)) { - e.setCancelled(true); - } - } - - return; - } - - - List functions = slot.getFunctions().getRootNodes(); - if(functions.size() > 0) { - String clickString = e.getClick().toString(); - FunctionUtil.tryFunctions(slot, FunctionType.valueOf(clickString), player); - } - - if(!slot.isMoveable()) { - e.setCancelled(true); - } - - Boolean close = null; - if(slot.getClose() != null) { - close = slot.getClose(); - } else if(gui.getClose() != null) { - close = gui.getClose(); - } else { - close = true; - } - - if(close) { - player.closeInventory(); - } - } - - @EventHandler - public void onDrag(InventoryDragEvent e) { - PlayerWrapper player = e.getPlayerWrapper(); - if(!GuiManager.get().hasGuiOpen(player)) { - return; - } - - Gui gui = GuiManager.get().getCurrentGui(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.isMoveable())) { - 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.isMoveable()) { - canStack = true; - } else if(canStack && !slot.isMoveable()) { - 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/manager/dynamicgui/FunctionManager.java b/core/src/main/java/com/clubobsidian/dynamicgui/manager/dynamicgui/FunctionManager.java deleted file mode 100644 index 060bba63d..000000000 --- a/core/src/main/java/com/clubobsidian/dynamicgui/manager/dynamicgui/FunctionManager.java +++ /dev/null @@ -1,67 +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.manager.dynamicgui; - -import com.clubobsidian.dynamicgui.function.Function; -import com.clubobsidian.fuzzutil.StringFuzz; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class FunctionManager { - - private static FunctionManager instance; - - private final Map functions; - - private FunctionManager() { - this.functions = new HashMap<>(); - } - - public static FunctionManager get() { - if(instance == null) { - instance = new FunctionManager(); - } - return instance; - } - - 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() { - List funcs = new ArrayList<>(); - funcs.addAll(this.functions.values()); - return funcs; - } - - public boolean addFunction(Function function) { - return this.functions.put(function.getName(), function) != null; - } - - public boolean removeFunctionByName(String functionName) { - String normalized = StringFuzz.normalize(functionName); - return this.functions.keySet().remove(normalized); - } -} \ No newline at end of file diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/manager/dynamicgui/SlotManager.java b/core/src/main/java/com/clubobsidian/dynamicgui/manager/dynamicgui/SlotManager.java deleted file mode 100644 index 9701d253f..000000000 --- a/core/src/main/java/com/clubobsidian/dynamicgui/manager/dynamicgui/SlotManager.java +++ /dev/null @@ -1,79 +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.manager.dynamicgui; - -import com.clubobsidian.dynamicgui.DynamicGui; -import com.clubobsidian.dynamicgui.entity.PlayerWrapper; -import com.clubobsidian.dynamicgui.gui.Gui; -import com.clubobsidian.dynamicgui.gui.Slot; -import com.clubobsidian.dynamicgui.inventory.InventoryWrapper; -import com.clubobsidian.dynamicgui.inventory.ItemStackWrapper; -import com.clubobsidian.dynamicgui.parser.function.FunctionType; -import com.clubobsidian.dynamicgui.util.FunctionUtil; - -import java.util.Iterator; -import java.util.Map.Entry; -import java.util.UUID; - -public class SlotManager { - - private static SlotManager instance; - - public static SlotManager get() { - if(instance == null) { - instance = new SlotManager(); - } - return instance; - } - - - private SlotManager() { - this.updateSlots(); - } - - private void updateSlots() { - DynamicGui.get().getServer().getScheduler().scheduleSyncRepeatingTask(DynamicGui.get().getPlugin(), () -> { - Iterator> it = GuiManager.get().getPlayerGuis().entrySet().iterator(); - while(it.hasNext()) { - Entry next = it.next(); - UUID key = next.getKey(); - PlayerWrapper playerWrapper = DynamicGui.get().getServer().getPlayer(key); - Gui gui = next.getValue(); - - for(Slot slot : gui.getSlots()) { - if(slot.getUpdateInterval() == 0 && !slot.getUpdate()) { - continue; - } - - slot.tick(); - if(slot.getUpdate() || (slot.getCurrentTick() % slot.getUpdateInterval() == 0)) { - ItemStackWrapper itemStackWrapper = slot.buildItemStack(playerWrapper); - int slotIndex = slot.getIndex(); - - InventoryWrapper inventoryWrapper = slot.getOwner().getInventoryWrapper(); - inventoryWrapper.setItem(slotIndex, itemStackWrapper); - - FunctionUtil.tryFunctions(slot, FunctionType.LOAD, playerWrapper); - if(!slot.getItemStack().getType().equalsIgnoreCase(Slot.IGNORE_MATERIAL)) { - inventoryWrapper.updateItem(slotIndex, playerWrapper); - } - slot.setUpdate(false); - } - } - } - }, 1L, 1L); - } -} \ No newline at end of file diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/replacer/impl/StatisticReplacer.java b/core/src/main/java/com/clubobsidian/dynamicgui/replacer/impl/StatisticReplacer.java deleted file mode 100644 index f95020433..000000000 --- a/core/src/main/java/com/clubobsidian/dynamicgui/replacer/impl/StatisticReplacer.java +++ /dev/null @@ -1,48 +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.replacer.impl; - -import com.clubobsidian.dynamicgui.entity.PlayerWrapper; -import com.clubobsidian.dynamicgui.replacer.Replacer; -import com.clubobsidian.dynamicgui.util.Statistic; - -/* - * Generated in DynamicGuiReplacerRegistry - */ -@Deprecated -public class StatisticReplacer extends Replacer { - - private final Statistic statistic; - private final String data; - - public StatisticReplacer(String toReplace, Statistic statistic) { - this(toReplace, statistic, null); - } - - public StatisticReplacer(String toReplace, Statistic statistic, String data) { - super(toReplace); - this.statistic = statistic; - this.data = data; - } - - @Override - public String replacement(String text, PlayerWrapper playerWrapper) { - if(this.data != null) { - return String.valueOf(playerWrapper.getStatistic(this.statistic, data)); - } - return String.valueOf(playerWrapper.getStatistic(this.statistic)); - } -} \ No newline at end of file diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/server/FakeServer.java b/core/src/main/java/com/clubobsidian/dynamicgui/server/FakeServer.java deleted file mode 100644 index 33244012b..000000000 --- a/core/src/main/java/com/clubobsidian/dynamicgui/server/FakeServer.java +++ /dev/null @@ -1,61 +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.server; - -import com.clubobsidian.dynamicgui.entity.PlayerWrapper; -import com.clubobsidian.dynamicgui.messaging.MessagingRunnable; -import com.clubobsidian.dynamicgui.plugin.DynamicGuiPlugin; -import com.clubobsidian.dynamicgui.scheduler.Scheduler; -import com.clubobsidian.dynamicgui.world.WorldWrapper; - -import java.util.Collection; -import java.util.UUID; - -public abstract class FakeServer { - - private final Scheduler scheduler; - - public FakeServer(Scheduler scheduler) { - this.scheduler = scheduler; - } - - public Scheduler getScheduler() { - return this.scheduler; - } - - public abstract void broadcastMessage(String message); - - public abstract void broadcastJsonMessage(String json); - - public abstract void dispatchServerCommand(String command); - - public abstract PlayerWrapper getPlayer(UUID uuid); - - public abstract PlayerWrapper getPlayer(String name); - - public abstract Collection> getOnlinePlayers(); - - public abstract int getGlobalPlayerCount(); - - public abstract ServerType getType(); - - public abstract void registerOutgoingPluginChannel(DynamicGuiPlugin plugin, String channel); - - public abstract void registerIncomingPluginChannel(DynamicGuiPlugin plugin, String channel, MessagingRunnable runnable); - - public abstract WorldWrapper getWorld(String worldName); - -} \ No newline at end of file diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/sound/SoundWrapper.java b/core/src/main/java/com/clubobsidian/dynamicgui/sound/SoundWrapper.java deleted file mode 100644 index b596e338e..000000000 --- a/core/src/main/java/com/clubobsidian/dynamicgui/sound/SoundWrapper.java +++ /dev/null @@ -1,48 +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.sound; - -import com.clubobsidian.dynamicgui.entity.PlayerWrapper; - -import java.io.Serializable; - -public class SoundWrapper implements Serializable { - - /** - * - */ - private static final long serialVersionUID = -8096584636206059158L; - private final String sound; - private final Float volume; - private final Float pitch; - - public SoundWrapper(String str) { - String[] args = str.split(","); - this.sound = args[0]; - this.volume = Float.parseFloat(args[1]); - this.pitch = Float.parseFloat(args[2]); - } - - public SoundWrapper(String sound, Float volume, Float pitch) { - this.sound = sound; - this.volume = volume; - this.pitch = pitch; - } - - public void playSoundToPlayer(PlayerWrapper player) { - player.playSound(this.sound, this.volume, this.pitch); - } -} \ No newline at end of file diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/util/ChatColor.java b/core/src/main/java/com/clubobsidian/dynamicgui/util/ChatColor.java deleted file mode 100644 index 7dcf68a13..000000000 --- a/core/src/main/java/com/clubobsidian/dynamicgui/util/ChatColor.java +++ /dev/null @@ -1,120 +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; - -import java.awt.*; - -public enum ChatColor { - - AQUA('b', 85, 255, 255), - BLACK('0', 0, 0, 0), - BLUE('9', 85, 85, 255), - DARK_AQUA('3', 0, 170, 170), - DARK_BLUE('1', 0, 0, 170), - DARK_GRAY('8', 85, 85, 85), - DARK_GREEN('2', 0, 170, 0), - DARK_PURPLE('5', 170, 0, 170), - DARK_RED('4', 170, 0, 0), - GOLD('6', 170, 170, 0), - GRAY('7', 170, 170, 170), - GREEN('a', 85, 255, 85), - LIGHT_PURPLE('d', 255, 85, 255), - RED('c', 255, 85, 85), - WHITE('f', 255, 255, 255), - YELLOW('e', 255, 255, 85), - //Formatting - BOLD('l', true), - ITALIC('o', true), - MAGIC('k', true), - RESET('r', true), - STRIKETHROUGH('m', true), - UNDERLINE('n', true); - - public static final char FORMATTING_CODE = '\u00A7'; - - private final char colorCode; - private final boolean formatting; - private int red; - private int green; - private int blue; - private Color color; - - ChatColor(char colorCode, int red, int green, int blue) { - this(colorCode, false); - this.red = red; - this.green = green; - this.blue = blue; - this.color = new Color(red, green, blue); - } - - ChatColor(char colorCode, boolean formatting) { - this.colorCode = colorCode; - this.formatting = formatting; - } - - public char getColorCode() { - return this.colorCode; - } - - public boolean isColor() { - return !this.isFormatting(); - } - - public boolean isFormatting() { - return this.formatting; - } - - public int getRed() { - return this.red; - } - - public int getGreen() { - return this.green; - } - - public int getBlue() { - return this.blue; - } - - public Color getJavaColor() { - return this.color; - } - - public static String translateAlternateColorCodes(char translate, String message) { - char[] chars = message.toCharArray(); - for(int i = 0; i < chars.length; i++) { - if(chars[i] == translate) { - if(i + 1 < chars.length) { - for(ChatColor color : ChatColor.values()) { - if(chars[i + 1] == color.getColorCode()) { - chars[i] = ChatColor.FORMATTING_CODE; - } - } - } - } - } - return String.valueOf(chars); - } - - public static String translateAlternateColorCodes(String message) { - return translateAlternateColorCodes('&', message); - } - - @Override - public String toString() { - return ChatColor.FORMATTING_CODE + "" + this.getColorCode(); - } -} \ No newline at end of file diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/util/FunctionUtil.java b/core/src/main/java/com/clubobsidian/dynamicgui/util/FunctionUtil.java deleted file mode 100644 index e9cb2223d..000000000 --- a/core/src/main/java/com/clubobsidian/dynamicgui/util/FunctionUtil.java +++ /dev/null @@ -1,131 +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; - -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.manager.dynamicgui.FunctionManager; -import com.clubobsidian.dynamicgui.manager.dynamicgui.ReplacerManager; -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 java.util.List; - -public final class FunctionUtil { - - private FunctionUtil() { - } - - public static boolean tryFunctions(FunctionOwner owner, FunctionType type, PlayerWrapper playerWrapper) { - return recurFunctionNodes(null, owner, owner.getFunctions().getRootNodes(), type, playerWrapper); - } - - private static boolean recurFunctionNodes(FunctionResponse fail, FunctionOwner owner, List functionNodes, FunctionType type, PlayerWrapper playerWrapper) { - for(FunctionNode node : functionNodes) { - FunctionToken functionToken = node.getToken(); - List types = functionToken.getTypes(); - if(types.contains(type) || (type.isClick() && types.contains(FunctionType.CLICK))) { - if(type != FunctionType.FAIL) { - FunctionResponse response = runFunctionData(owner, functionToken.getFunctions(), playerWrapper); - - if(!response.result) { - if(response.failedFunction == null) { - return false; - } - - recurFunctionNodes(response, owner, node.getChildren(), FunctionType.FAIL, playerWrapper); - return false; - } else { - recurFunctionNodes(response, owner, node.getChildren(), type, playerWrapper); - } - } else if(type == FunctionType.FAIL) { - if(isFail(fail, functionToken)) { - FunctionResponse response = runFunctionData(owner, functionToken.getFunctions(), playerWrapper); - if(!response.result) { - recurFunctionNodes(response, owner, node.getChildren(), FunctionType.FAIL, playerWrapper); - } - } - } - } - } - - return true; - } - - private static FunctionResponse runFunctionData(FunctionOwner owner, List datas, PlayerWrapper playerWrapper) { - for(FunctionData data : datas) { - 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()); - return new FunctionResponse(false); - } - - function.setOwner(owner); - - if(data.getData() != null) { - String newData = ReplacerManager.get().replace(functionData, playerWrapper); - function.setData(newData); - } - - boolean ran = function.function(playerWrapper); - if(data.getModifier() == FunctionModifier.NOT) { - ran = !ran; - } - - if(!ran) { - return new FunctionResponse(false, functionName, functionData); - } - } - return new FunctionResponse(true); - } - - private static boolean isFail(FunctionResponse response, FunctionToken token) { - for(FunctionData data : token.getFailOnFunctions()) { - if(data.getName().equals(response.failedFunction)) { - if(data.getData() == null) { - return true; - } else if(data.getData().equals(response.data)) { - return true; - } - } - } - - return false; - } - - private static 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/util/ReflectionUtil.java b/core/src/main/java/com/clubobsidian/dynamicgui/util/ReflectionUtil.java deleted file mode 100644 index cde89b949..000000000 --- a/core/src/main/java/com/clubobsidian/dynamicgui/util/ReflectionUtil.java +++ /dev/null @@ -1,114 +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; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; - -public final class ReflectionUtil { - - private ReflectionUtil() { - } - - public static Class classForName(String name) { - try { - return Class.forName(name); - } catch(ClassNotFoundException e) { - e.printStackTrace(); - } - return null; - } - - public static Method getMethod(Class cl, String methodName) { - try { - Method method = cl.getDeclaredMethod(methodName); - method.setAccessible(true); - return method; - } catch(NoSuchMethodException | SecurityException e) { - e.printStackTrace(); - } - return null; - } - - public static Method getMethod(Class cl, String methodName, Class... params) { - try { - Method method = cl.getDeclaredMethod(methodName, params); - method.setAccessible(true); - return method; - } catch(NoSuchMethodException | SecurityException e) { - e.printStackTrace(); - } - return null; - } - - public static Method getMethodByReturnType(Class searchIn, Class returnType) { - for(Method m : searchIn.getDeclaredMethods()) { - if(m.getReturnType().equals(returnType)) { - m.setAccessible(true); - return m; - } - } - return null; - } - - public static Field getFieldByName(Class searchIn, String name) { - try { - Field f = searchIn.getDeclaredField(name); - f.setAccessible(true); - return f; - } catch(NoSuchFieldException | SecurityException e) { - return null; - } - } - - public static Field getFieldByType(Class searchIn, Class fieldType) { - for(Field f : searchIn.getDeclaredFields()) { - if(f.getType().equals(fieldType)) { - f.setAccessible(true); - return f; - } - } - return null; - } - - public static Field getDeclaredField(Class clazz, String... fields) { - for(String fieldName : fields) { - try { - Field field = clazz.getDeclaredField(fieldName); - field.setAccessible(true); - return field; - } catch(NoSuchFieldException e) { - } - } - return null; - } - - public static class ReflectionHelper { - - public T get(Field field) { - return this.get(field, null); - } - - @SuppressWarnings("unchecked") - public T get(Field field, Object getFromClass) { - try { - return (T) field.get(getFromClass); - } catch(IllegalArgumentException | IllegalAccessException e) { - return null; - } - } - } -} \ No newline at end of file diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/util/Statistic.java b/core/src/main/java/com/clubobsidian/dynamicgui/util/Statistic.java deleted file mode 100644 index cf2b69e2d..000000000 --- a/core/src/main/java/com/clubobsidian/dynamicgui/util/Statistic.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.util; - -public enum Statistic { - - ANIMALS_BRED("ANIMALS_BRED", "ANIMALS_BRED"), - ARMOR_CLEANED("ARMOR_CLEANED", "ARMOR_CLEANED"), - AVIATE_ONE_CM("AVIATE_ONE_CM", "AVIATE_ONE_CM"), - BANNER_CLEANED("BANNER_CLEANED", "BANNER_CLEANED"), - BEACON_INTERACTION("BEACON_INTERACTION", "BEACON_INTERACTION"), - BOAT_ONE_CM("BOAT_ONE_CM", "BOAT_ONE_CM"), - BREAK_ITEM("BREAK_ITEM", null, StatisticType.MATERIAL), - BREWINGSTAND_INTERACTION("BREWINGSTAND_INTERACTION", "BREWINGSTAND_INTERACTION"), - CAKE_SLICES_EATEN("CAKES_SLICES_EATEN", "CAKES_SLICES_EATEN"), - CAULDRON_FILLED("CAULDRON_FILLED", "CAULDRON_FILLED"), - CAULDRON_USED("CAULDRON_USED", "CAULDRON_USED"), - CHEST_OPENED("CHEST_OPENED", "CHEST_OPENED"), - CLIMB_ONE_CM("CLIMB_ONE_CM", "CLIMB_ONE_CM"), - CRAFT_ITEM("CRAFT_ITEM", null, StatisticType.MATERIAL), - CRAFTING_TABLE_INTERACTION("CRAFTING_TABLE_INTERACTION", "CRAFTING_TABLE_INTERACTION"), - CROUCH_ONE_CM("CROUCH_ONE_CM", "CROUCH_ONE_CM"), - DAMAGE_DEALT("DAMAGE_DEALT", "DAMAGE_DEALT"), - DAMAGE_TAKEN("DAMAGE_TAKEN", "DAMAGE_TAKEN"), - DEATHS("DEATHS", "DEATHS"), - DISPENSER_INSPECTED("DISPENSER_INSPECTED", "DISPENSER_INSPECTED"), - DROP("DROP", "DROP", StatisticType.MATERIAL), - DROP_COUNT("DROP_COUNT", null), - DROPPER_INSPECTED("DROPPER_INSPECTED", "DROPPED_INSPECTED"), - ENDERCHEST_OPENED("ENDERCHEST_OPENED", "ENDERCHEST_OPENED"), - ENTITY_KILLED_BY("ENTITY_KILLED_BY", null, StatisticType.ENTITY), - FALL_ONE_CM("FALL_ONE_CM", "FALL_ONE_CM"), - FISH_CAUGHT("FISH_CAUGHT", "FISH_CAUGHT"), - FLOWER_POTTED("FLOWER_POTTED", "FLOWER_POTTED"), - FLY_ONE_CM("FLY_ONE_CM", null), - FURNACE_INTERACTION("FURNACE_INTERACTION", "FURNACE_INTERACTION"), - HOPPER_INSPECTED("HOPPER_INSPECTED", "HOPPER_INSPECTED"), - HORSE_ONE_CM("HORSE_ONE_CM", "HORSE_ONE_CM"), - ITEM_ENCHANTED("ITEM_ENCHANTED", "ITEM_ENCHANTED"), - JUMP("JUMP", "JUMP"), - KILL_ENTITY("KILL_ENTITY", null, StatisticType.ENTITY), - LEAVE_GAME("LEAVE_GAME", "LEAVE_GAME"), - MINE_BLOCK("MINE_BLOCK", null, StatisticType.MATERIAL), - MINECART_ONE_CM("MINECART_ONE_CM", "MINECART_ONE_CM"), - MOB_KILLS("MOB_KILLS", "MOB_KILLS"), - NOTEBLOCK_PLAYED("NOTEBLOCK_PLAYED", "NOTEBLOCK_PLAYED"), - NOTEBLOCK_TUNED("NOTEBLOCK_TUNED", "NOTEBLOCK_TUNED"), - PICKUP("PICKUP", null, StatisticType.MATERIAL), - PIG_ONE_CM("PIG_ONE_CM", "PIG_ONE_CM"), - PLAYER_KILLS("PLAYER_KILLS", "PLAYER_KILLS"), - RECORD_PLAYED("RECORD_PLAYED", "RECORD_PLAYED"), - SHULKER_BOX_OPENED("SHULKER_BOX_OPENED", "OPEN_SHULKER_BOX"), - SLEEP_IN_BED("SLEEP_IN_BED", "SLEEP_IN_BED"), - SNEAK_TIME("SNEAK_TIME", "SNEAK_TIME"), - SPRINT_ONE_CM("SPRINT_ONE_CM", "SPRINT_ONE_CM"), - SWIM_ONE_CM("SWIM_ONE_CM", "SWIM_ONE_CM"), - TALKED_TO_VILLAGER("TALKED_TO_VILAGER", "TALKED_TO_VILLAGER"), - TIME_PLAYED_TICK("PLAY_ONE_TICK", "TIME_PLAYED"), - TIME_PLAYED("PLAY_ONE_MINUTE", "TIME_PLAYED"), - TIME_SINCE_DEATH("TIME_SINCE_DEATH", "TIME_SINCE_DEATH"), - TIME_SINCE_REST("TIME_SINCE_REST", "TIME_SINCE_REST"), - TRADED_WITH_VILLAGER("TRADED_WITH_VILLAGER", "TRADED_WITH_VILLAGER"), - TRAPPED_CHEST_TRIGGERED("TRAPPED_CHEST_TRIGGERED", "TRAPPED_CHEST_TRIGGERED"), - USE_ITEM("USE_ITEM", null, StatisticType.MATERIAL), - WALK_ON_WATER_ONE_CM("WALK_ON_WATER_ONE_CM", null), - WALK_ONE_CM("WALK_ONE_CM", "WALK_ONE_CM"), - WALK_UNDER_WATER_ONE_CM("WALK_UNDER_WATER_ONE_CM", null); - - private final String bukkitID; - private final String spongeID; - private final StatisticType statisticType; - - Statistic(String bukkitID, String spongeID) { - this(bukkitID, spongeID, StatisticType.NONE); - } - - Statistic(String bukkitID, String spongeID, StatisticType statisticType) { - this.bukkitID = bukkitID; - this.spongeID = spongeID; - this.statisticType = statisticType; - } - - public String getBukkitID() { - return this.bukkitID; - } - - public String getSpongeID() { - return this.spongeID; - } - - public StatisticType getStatisticType() { - return this.statisticType; - } - - public enum StatisticType { - NONE, - MATERIAL, - ENTITY - } -} \ No newline at end of file diff --git a/bukkit/src/main/resources/config.yml b/core/src/main/resources/config.yml similarity index 72% rename from bukkit/src/main/resources/config.yml rename to core/src/main/resources/config.yml index 2f8b0932f..61278ceff 100644 --- a/bukkit/src/main/resources/config.yml +++ b/core/src/main/resources/config.yml @@ -1,4 +1,7 @@ -no-gui: "&4That gui does not exist!" +message: + no-gui: "&e[&fDynamicGui&e] &cThat gui does not exist!" + no-gui-permission: "&e[&fDynamicGui&e] &cYou do not have permission for that gui!" + #Configure proxy types # Proxy types: # bungee - If you use Bungeecord as your proxy diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/builder/EnchantmentBuilderTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/builder/EnchantmentBuilderTest.java new file mode 100644 index 000000000..1a31dff42 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/builder/EnchantmentBuilderTest.java @@ -0,0 +1,44 @@ +/* + * 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.test.builder; + +import com.clubobsidian.dynamicgui.core.builder.EnchantmentBuilder; +import com.clubobsidian.dynamicgui.core.enchantment.EnchantmentWrapper; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class EnchantmentBuilderTest { + + @Test + public void testName() { + String enchantmentName = "test"; + EnchantmentWrapper enchantment = new EnchantmentBuilder() + .setEnchantment(enchantmentName) + .build(); + assertEquals(enchantmentName, enchantment.getEnchant()); + } + + @Test + public void testLevel() { + int enchantmentLevel = 1; + EnchantmentWrapper enchantment = new EnchantmentBuilder() + .setLevel(enchantmentLevel) + .build(); + assertEquals(enchantmentLevel, enchantment.getLevel()); + } +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/builder/FunctionBuilderTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/builder/FunctionBuilderTest.java new file mode 100644 index 000000000..25de7a654 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/builder/FunctionBuilderTest.java @@ -0,0 +1,54 @@ +/* + * 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.test.builder; + +import com.clubobsidian.dynamicgui.core.builder.FunctionBuilder; +import com.clubobsidian.dynamicgui.parser.function.FunctionData; +import com.clubobsidian.dynamicgui.parser.function.FunctionModifier; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class FunctionBuilderTest { + + @Test + public void nameTest() { + String functionName = "test"; + FunctionData function = new FunctionBuilder() + .setName(functionName) + .build(); + assertEquals(functionName, function.getName()); + } + + @Test + public void dataTest() { + String functionData = "data"; + FunctionData function = new FunctionBuilder() + .setData(functionData) + .build(); + assertEquals(functionData, function.getData()); + } + + @Test + public void modifierTest() { + FunctionModifier functionModifier = FunctionModifier.NOT; + FunctionData function = new FunctionBuilder() + .setModifier(functionModifier) + .build(); + assertEquals(functionModifier, function.getModifier()); + } +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/command/CloudArgumentTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/command/CloudArgumentTest.java new file mode 100644 index 000000000..e6c2faacc --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/command/CloudArgumentTest.java @@ -0,0 +1,96 @@ +/* + * 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.test.command; + +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 com.clubobsidian.dynamicgui.core.command.cloud.CloudArgument; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; + +public class CloudArgumentTest { + + @Test + public void testFromTypeText() { + assertEquals(CloudArgument.STRING, CloudArgument.fromType("text").get()); + } + + @Test + public void testFromTypeNumber() { + assertEquals(CloudArgument.INTEGER, CloudArgument.fromType("number").get()); + } + + @Test + public void testBooleanArgument() { + assertInstanceOf(BooleanArgument.class, CloudArgument.BOOLEAN.argument("test")); + } + + @Test + public void testByteArgument() { + assertInstanceOf(ByteArgument.class, CloudArgument.BYTE.argument("test")); + } + + @Test + public void testCharArgument() { + assertInstanceOf(CharArgument.class, CloudArgument.CHAR.argument("test")); + } + + @Test + public void testDoubleArgument() { + assertInstanceOf(DoubleArgument.class, CloudArgument.DOUBLE.argument("test")); + } + + @Test + public void testFloatArgument() { + assertInstanceOf(FloatArgument.class, CloudArgument.FLOAT.argument("test")); + } + + @Test + public void testIntegerArgument() { + assertInstanceOf(IntegerArgument.class, CloudArgument.INTEGER.argument("test")); + } + + @Test + public void testLongArgument() { + assertInstanceOf(LongArgument.class, CloudArgument.LONG.argument("test")); + } + + @Test + public void testShortArgument() { + assertInstanceOf(ShortArgument.class, CloudArgument.SHORT.argument("test")); + } + + @Test + public void testStringArgument() { + assertInstanceOf(StringArgument.class, CloudArgument.STRING.argument("test")); + } + + @Test + public void testUUIDArgument() { + assertInstanceOf(UUIDArgument.class, CloudArgument.UUID.argument("test")); + } +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/config/ChatColorTransformerTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/config/ChatColorTransformerTest.java new file mode 100644 index 000000000..cc6bb71b7 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/config/ChatColorTransformerTest.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.test.config; + +import com.clubobsidian.dynamicgui.core.config.ChatColorTransformer; +import com.clubobsidian.dynamicgui.core.util.ChatColor; +import com.clubobsidian.wrappy.transformer.NodeTransformer; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class ChatColorTransformerTest { + + @Test + public void transformTest() { + String str = "&ctest"; + String colorized = '\u00A7' + "ctest"; + NodeTransformer transformer = new ChatColorTransformer(); + String transformed = transformer.transform(str); + assertEquals(colorized, transformed); + } +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/config/MessageTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/config/MessageTest.java new file mode 100644 index 000000000..9eeee3a80 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/config/MessageTest.java @@ -0,0 +1,41 @@ +/* + * 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.test.config; + +import com.clubobsidian.dynamicgui.core.DynamicGui; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class MessageTest extends FactoryTest { + + @Test + public void notNullTest() { + this.getFactory().inject(); + assertNotNull(DynamicGui.get().getMessage()); + } + + @Test + public void noGuiTest() { + this.getFactory().inject(); + String noGuiMessage = DynamicGui.get().getMessage().getNoGui(); + assertNotNull(noGuiMessage); + assertTrue(noGuiMessage.length() > 0); + } +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/AddPermissionFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/AddPermissionFunctionTest.java new file mode 100644 index 000000000..4811de4f5 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/AddPermissionFunctionTest.java @@ -0,0 +1,54 @@ +/* + * 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.test.function; + +import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper; +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.AddPermissionFunction; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class AddPermissionFunctionTest extends FactoryTest { + + @Test + public void testNullPermission() throws Exception { + Function function = new AddPermissionFunction(); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void testPermissionAdded() throws Exception { + String permission = "test"; + Function function = new AddPermissionFunction(); + function.setData(permission); + PlayerWrapper player = this.getFactory().createPlayer(); + assertTrue(function.function(player)); + } + + @Test + public void testPermissionNotAdded() throws Exception { + String permission = "test"; + Function function = new AddPermissionFunction(); + function.setData(permission); + PlayerWrapper player = this.getFactory().createPlayer(); + player.addPermission(permission); + assertFalse(function.function(player)); + } +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/AsyncRunningFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/AsyncRunningFunctionTest.java new file mode 100644 index 000000000..2ce92cbab --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/AsyncRunningFunctionTest.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.test.function; + +import com.clubobsidian.dynamicgui.core.function.impl.AsyncRunningFunction; +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; + +public class AsyncRunningFunctionTest extends FactoryTest { + + //TODO - implement the passing test + + @Test + public void failingTest() throws Exception { + Function function = new AsyncRunningFunction(); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void failingWithoutDataTest() throws Exception { + Function function = new AsyncRunningFunction(); + function.setData("delay"); + assertFalse(function.function(this.getFactory().createPlayer())); + } +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/CheckItemInTypeHandFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/CheckItemInTypeHandFunctionTest.java new file mode 100644 index 000000000..249fde076 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/CheckItemInTypeHandFunctionTest.java @@ -0,0 +1,63 @@ +/* + * 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.test.function; + +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.CheckItemTypeInHandFunction; +import com.clubobsidian.dynamicgui.core.inventory.ItemStackWrapper; +import com.clubobsidian.dynamicgui.core.test.mock.entity.player.MockPlayerWrapper; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class CheckItemInTypeHandFunctionTest extends FactoryTest { + + @Test + public void testNull() throws Exception { + String material = "stone"; + Function function = new CheckItemTypeInHandFunction(); + ItemStackWrapper hand = this.getFactory().createItemStack(material); + MockPlayerWrapper player = this.getFactory().createPlayer(); + player.setItemInHand(hand); + assertFalse(function.function(player)); + } + + @Test + public void testOneType() throws Exception { + String material = "stone"; + Function function = new CheckItemTypeInHandFunction(); + function.setData(material); + ItemStackWrapper hand = this.getFactory().createItemStack(material); + MockPlayerWrapper player = this.getFactory().createPlayer(); + player.setItemInHand(hand); + assertTrue(function.function(player)); + } + + @Test + public void testTwoTypes() throws Exception { + String handMaterial = "stone"; + String functionMaterials = "dirt,stone"; + Function function = new CheckItemTypeInHandFunction(); + function.setData(functionMaterials); + ItemStackWrapper hand = this.getFactory().createItemStack(handMaterial); + MockPlayerWrapper player = this.getFactory().createPlayer(); + player.setItemInHand(hand); + assertTrue(function.function(player)); + } +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/CheckLevelFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/CheckLevelFunctionTest.java new file mode 100644 index 000000000..30bb5506c --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/CheckLevelFunctionTest.java @@ -0,0 +1,72 @@ +/* + * 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.test.function; + +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.CheckLevelFunction; +import com.clubobsidian.dynamicgui.core.test.mock.entity.player.MockPlayerWrapper; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class CheckLevelFunctionTest extends FactoryTest { + + @Test + public void testNull() throws Exception { + MockPlayerWrapper wrapper = this.getFactory().createPlayer(); + Function function = new CheckLevelFunction(); + assertFalse(function.function(wrapper)); + } + + @Test + public void testLevelGreater() throws Exception { + MockPlayerWrapper wrapper = this.getFactory().createPlayer(); + wrapper.setLevel(10); + Function function = new CheckLevelFunction(); + function.setData("1"); + assertTrue(function.function(wrapper)); + } + + @Test + public void testLevelEqual() throws Exception { + MockPlayerWrapper wrapper = this.getFactory().createPlayer(); + wrapper.setLevel(10); + Function function = new CheckLevelFunction(); + function.setData("10"); + assertTrue(function.function(wrapper)); + } + + @Test + public void testLevelLessThan() throws Exception { + MockPlayerWrapper wrapper = this.getFactory().createPlayer(); + wrapper.setLevel(1); + Function function = new CheckLevelFunction(); + function.setData("10"); + assertFalse(function.function(wrapper)); + } + + @Test + public void testInvalidFormat() throws Exception { + MockPlayerWrapper wrapper = this.getFactory().createPlayer(); + wrapper.setLevel(1); + Function function = new CheckLevelFunction(); + function.setData("a"); + assertFalse(function.function(wrapper)); + } +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/CheckMovableFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/CheckMovableFunctionTest.java new file mode 100644 index 000000000..fd258c3c6 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/CheckMovableFunctionTest.java @@ -0,0 +1,54 @@ +/* + * 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.test.function; + +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.CheckMovableFunction; +import com.clubobsidian.dynamicgui.core.test.mock.entity.player.MockPlayerWrapper; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class CheckMovableFunctionTest extends FactoryTest { + + @Test + public void nullTest() throws Exception { + Function function = new CheckMovableFunction(); + MockPlayerWrapper wrapper = this.getFactory().createPlayer(); + assertFalse(function.function(wrapper)); + } + + @Test + public void ownerNotSlotTest() throws Exception { + Function function = new CheckMovableFunction(); + function.setData("true"); + function.setOwner(this.getFactory().createGui("test")); + MockPlayerWrapper wrapper = this.getFactory().createPlayer(); + assertFalse(function.function(wrapper)); + } + + @Test + public void isMovableTest() throws Exception { + Function function = new CheckMovableFunction(); + function.setData("true"); + function.setOwner(this.getFactory().createSlot("STONE", true)); + MockPlayerWrapper wrapper = this.getFactory().createPlayer(); + assertTrue(function.function(wrapper)); + } +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/CheckPlayerWorldFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/CheckPlayerWorldFunctionTest.java new file mode 100644 index 000000000..10c114dce --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/CheckPlayerWorldFunctionTest.java @@ -0,0 +1,46 @@ +/* + * 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.test.function; + +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.CheckPlayerWorldFunction; +import com.clubobsidian.dynamicgui.core.test.mock.entity.player.MockPlayerWrapper; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class CheckPlayerWorldFunctionTest extends FactoryTest { + + @Test + public void nullTest() throws Exception { + Function function = new CheckPlayerWorldFunction(); + MockPlayerWrapper player = this.getFactory().createPlayer(); + assertFalse(function.function(player)); + } + + @Test + public void worldEqualsTest() throws Exception { + String worldName = "test"; + Function function = new CheckPlayerWorldFunction(); + function.setData(worldName); + MockPlayerWrapper player = this.getFactory().createPlayer(); + player.setLocation(this.getFactory().createLocation(0, 0, 0, worldName)); + assertTrue(function.function(player)); + } +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/ConsoleCommandFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/ConsoleCommandFunctionTest.java new file mode 100644 index 000000000..346bacb4f --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/ConsoleCommandFunctionTest.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.test.function; + +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.ConsoleCommandFunction; +import com.clubobsidian.dynamicgui.core.test.mock.plugin.MockPlatform; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class ConsoleCommandFunctionTest extends FactoryTest { + + @Test + public void nullTest() throws Exception { + Function function = new ConsoleCommandFunction(); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void withDataTest() throws Exception { + String data = "test"; + MockPlatform platform = this.getFactory().inject().getPlatform(); + Function function = new ConsoleCommandFunction(); + function.setData(data); + assertTrue(function.function(this.getFactory().createPlayer())); + assertEquals(data, platform.getDispatchedServerCommands().get(0)); + } + +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/DelayFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/DelayFunctionTest.java new file mode 100644 index 000000000..963000b44 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/DelayFunctionTest.java @@ -0,0 +1,79 @@ +/* + * 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.test.function; + +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.DelayFunction; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import java.util.concurrent.atomic.AtomicBoolean; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class DelayFunctionTest extends FactoryTest { + + @Test + public void testNull() throws Exception { + Function function = new DelayFunction(); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void testNonNumber() throws Exception { + Function function = new DelayFunction(); + function.setData("a"); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void testInterrupt() { + AtomicBoolean value = new AtomicBoolean(true); + Thread thread = new Thread(() -> { + Function function = new DelayFunction(); + function.setData("5000"); + try { + value.set(function.function(this.getFactory().createPlayer())); + } catch (Exception e) { + e.printStackTrace(); + } + }); + thread.start(); + thread.interrupt(); + int count = 0; + while (thread.isAlive()) { + try { + Thread.sleep(1); + count += 1; + if (count > 1000) { + break; //Just so the test doesn't get stuck in an infinite loop + } + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + assertFalse(value.get()); + } + + @Test + public void testValidData() throws Exception { + Function function = new DelayFunction(); + function.setData("1"); + assertTrue(function.function(this.getFactory().createPlayer())); + } +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/GetGameRuleFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/GetGameRuleFunctionTest.java new file mode 100644 index 000000000..a722b3935 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/GetGameRuleFunctionTest.java @@ -0,0 +1,70 @@ +/* + * 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.test.function; + +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.GetGameRuleFunction; +import com.clubobsidian.dynamicgui.core.test.mock.plugin.MockPlatform; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import com.clubobsidian.dynamicgui.core.world.WorldWrapper; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class GetGameRuleFunctionTest extends FactoryTest { + + @Test + public void nullTest() throws Exception { + Function function = new GetGameRuleFunction(); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void noCommaTest() throws Exception { + Function function = new GetGameRuleFunction(); + function.setData(""); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void lengthNotThreeTest() throws Exception { + Function function = new GetGameRuleFunction(); + function.setData("a,b"); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void worldNullTest() throws Exception { + this.getFactory().inject().getPlatform(); + Function function = new GetGameRuleFunction(); + function.setData("test,key,value"); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void hasGameRuleTest() throws Exception { + String worldName = "test"; + MockPlatform platform = this.getFactory().inject().getPlatform(); + WorldWrapper world = this.getFactory().createWorld(worldName); + platform.addWorld(world); + world.setGameRule("key", "value"); + Function function = new GetGameRuleFunction(); + function.setData("test,key,value"); + assertTrue(function.function(this.getFactory().createPlayer())); + } +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/IsBedrockPlayerFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/IsBedrockPlayerFunctionTest.java new file mode 100644 index 000000000..feb871219 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/IsBedrockPlayerFunctionTest.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.test.function; + +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.IsBedrockPlayerFunction; +import com.clubobsidian.dynamicgui.core.test.mock.entity.player.MockPlayerWrapper; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import java.util.UUID; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class IsBedrockPlayerFunctionTest extends FactoryTest { + + @Test + public void functionTest() throws Exception { + String name = "test"; + UUID uuid = new UUID(0, 1); + MockPlayerWrapper player = this.getFactory().createPlayer(name, uuid); + Function function = new IsBedrockPlayerFunction(); + assertTrue(function.function(player)); + } +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/IsNotOnCooldownFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/IsNotOnCooldownFunctionTest.java new file mode 100644 index 000000000..d05a8d24b --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/IsNotOnCooldownFunctionTest.java @@ -0,0 +1,44 @@ +/* + * 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.test.function; + +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.cooldown.IsNotOnCooldownFunction; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import java.util.UUID; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class IsNotOnCooldownFunctionTest extends FactoryTest { + + @Test + public void nullDataTest() throws Exception { + Function function = new IsNotOnCooldownFunction(); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void notOnCooldownTest() throws Exception { + this.getFactory().inject(); + Function function = new IsNotOnCooldownFunction(); + function.setData(UUID.randomUUID().toString()); + assertTrue(function.function(this.getFactory().createPlayer())); + } +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/IsOnCooldownFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/IsOnCooldownFunctionTest.java new file mode 100644 index 000000000..49de3f2d3 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/IsOnCooldownFunctionTest.java @@ -0,0 +1,49 @@ +/* + * 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.test.function; + +import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper; +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.cooldown.IsOnCooldownFunction; +import com.clubobsidian.dynamicgui.core.manager.dynamicgui.cooldown.CooldownManager; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import java.util.UUID; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class IsOnCooldownFunctionTest extends FactoryTest { + + @Test + public void nullDataTest() throws Exception { + Function function = new IsOnCooldownFunction(); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void onCooldownTest() throws Exception { + this.getFactory().inject(); + PlayerWrapper player = this.getFactory().createPlayer(); + String cooldownName = UUID.randomUUID().toString(); + CooldownManager.get().createCooldown(player, cooldownName, 1000); + Function function = new IsOnCooldownFunction(); + function.setData(cooldownName); + assertTrue(function.function(player)); + } +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/LogFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/LogFunctionTest.java new file mode 100644 index 000000000..60ec30b2e --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/LogFunctionTest.java @@ -0,0 +1,52 @@ +/* + * 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.test.function; + +import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper; +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.LogFunction; +import com.clubobsidian.dynamicgui.core.test.mock.logger.MockLogger; +import com.clubobsidian.dynamicgui.core.test.mock.logger.MockLoggerWrapper; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class LogFunctionTest extends FactoryTest { + + @Test + public void nullTest() throws Exception { + Function function = new LogFunction(); + PlayerWrapper player = this.getFactory().createPlayer(); + assertFalse(function.function(player)); + } + + @Test + public void withDataTest() throws Exception { + String data = "test"; + Function function = new LogFunction(); + function.setData(data); + MockLoggerWrapper wrapper = this.getFactory().inject().getLogger(); + MockLogger logger = wrapper.getLogger(); + PlayerWrapper player = this.getFactory().createPlayer(); + assertTrue(function.function(player)); + assertTrue(logger.getInfoMessages().size() == 1); + assertEquals(data, logger.getInfoMessages().get(0)); + } +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/LoggedInFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/LoggedInFunctionTest.java new file mode 100644 index 000000000..485f8ea70 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/LoggedInFunctionTest.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.test.function; + +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.LoggedInFunction; +import com.clubobsidian.dynamicgui.core.test.mock.entity.player.MockPlayerWrapper; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class LoggedInFunctionTest extends FactoryTest { + + @Test + public void testLoggedOff() throws Exception { + Function function = new LoggedInFunction(); + MockPlayerWrapper player = this.getFactory().createPlayer(); + this.getFactory().getPlatform().getOnlinePlayers().add(player); + player.setOnline(false); + assertFalse(function.function(player)); + } + + @Test + public void testLoggedOffNullRetrieval() throws Exception { + Function function = new LoggedInFunction(); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void testLoggedOffAndBackOn() throws Exception { + Function function = new LoggedInFunction(); + this.getFactory().getPlatform().getOnlinePlayers().add(this.getFactory().createPlayer()); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void testOnline() throws Exception { + Function function = new LoggedInFunction(); + MockPlayerWrapper player = this.getFactory().createPlayer(); + this.getFactory().getPlatform().getOnlinePlayers().add(player); + assertTrue(function.function(player)); + } +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/MoneyBalanceFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/MoneyBalanceFunctionTest.java new file mode 100644 index 000000000..b7a7706cf --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/MoneyBalanceFunctionTest.java @@ -0,0 +1,82 @@ +/* + * 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.test.function; + +import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper; +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.MoneyBalanceFunction; +import com.clubobsidian.dynamicgui.core.test.mock.plugin.MockEconomy; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import java.math.BigDecimal; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class MoneyBalanceFunctionTest extends FactoryTest { + + @Test + public void testBelowBalance() throws Exception { + this.getFactory().inject(); + PlayerWrapper player = this.getFactory().createPlayer(); + Function function = new MoneyBalanceFunction(); + function.setData("10"); + assertFalse(function.function(player)); + } + + @Test + public void testInvalidData() throws Exception { + this.getFactory().inject(); + PlayerWrapper player = this.getFactory().createPlayer(); + Function function = new MoneyBalanceFunction(); + function.setData("a"); + assertFalse(function.function(player)); + } + + @Test + public void testNullEconomy() throws Exception { + this.getFactory().inject().getPlugin().economy = null; + PlayerWrapper player = this.getFactory().createPlayer(); + Function function = new MoneyBalanceFunction(); + function.setData("10"); + assertFalse(function.function(player)); + } + + @Test + public void testEqualBalance() throws Exception { + PlayerWrapper player = this.getFactory().createPlayer(); + MockEconomy economy = this.getFactory().inject().getEconomy(); + BigDecimal amount = new BigDecimal(1); + economy.deposit(player, amount); + Function function = new MoneyBalanceFunction(); + function.setData("" + amount.intValue()); + assertTrue(function.function(player)); + } + + @Test + public void testAboveBalance() throws Exception { + PlayerWrapper player = this.getFactory().createPlayer(); + MockEconomy economy = this.getFactory().inject().getEconomy(); + int checkAmount = 9; + BigDecimal depositAmount = new BigDecimal(checkAmount + 1); + economy.deposit(player, depositAmount); + Function function = new MoneyBalanceFunction(); + function.setData("" + checkAmount); + assertTrue(function.function(player)); + } +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/MoneyDepositFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/MoneyDepositFunctionTest.java new file mode 100644 index 000000000..ce14bdd21 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/MoneyDepositFunctionTest.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.test.function; + +import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper; +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.MoneyDepositFunction; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class MoneyDepositFunctionTest extends FactoryTest { + + @Test + public void testInvalidData() throws Exception { + this.getFactory().inject(); + PlayerWrapper player = this.getFactory().createPlayer(); + Function function = new MoneyDepositFunction(); + function.setData("a"); + assertFalse(function.function(player)); + } + + @Test + public void testNullEconomy() throws Exception { + this.getFactory().inject().getPlugin().economy = null; + PlayerWrapper player = this.getFactory().createPlayer(); + Function function = new MoneyDepositFunction(); + function.setData("10"); + assertFalse(function.function(player)); + } + + @Test + public void testValidDeposit() throws Exception { + PlayerWrapper player = this.getFactory().createPlayer(); + this.getFactory().inject(); + Function function = new MoneyDepositFunction(); + function.setData("10"); + assertTrue(function.function(player)); + } +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/MoneyWithdrawFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/MoneyWithdrawFunctionTest.java new file mode 100644 index 000000000..c9254043f --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/MoneyWithdrawFunctionTest.java @@ -0,0 +1,82 @@ +/* + * 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.test.function; + +import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper; +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.MoneyWithdrawFunction; +import com.clubobsidian.dynamicgui.core.test.mock.plugin.MockEconomy; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import java.math.BigDecimal; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class MoneyWithdrawFunctionTest extends FactoryTest { + + @Test + public void testBelowBalance() throws Exception { + this.getFactory().inject(); + PlayerWrapper player = this.getFactory().createPlayer(); + Function function = new MoneyWithdrawFunction(); + function.setData("10"); + assertFalse(function.function(player)); + } + + @Test + public void testInvalidData() throws Exception { + this.getFactory().inject(); + PlayerWrapper player = this.getFactory().createPlayer(); + Function function = new MoneyWithdrawFunction(); + function.setData("a"); + assertFalse(function.function(player)); + } + + @Test + public void testNullEconomy() throws Exception { + this.getFactory().inject().getPlugin().economy = null; + PlayerWrapper player = this.getFactory().createPlayer(); + Function function = new MoneyWithdrawFunction(); + function.setData("10"); + assertFalse(function.function(player)); + } + + @Test + public void testEqualBalance() throws Exception { + PlayerWrapper player = this.getFactory().createPlayer(); + MockEconomy economy = this.getFactory().inject().getEconomy(); + BigDecimal amount = new BigDecimal(1); + economy.deposit(player, amount); + Function function = new MoneyWithdrawFunction(); + function.setData("" + amount.intValue()); + assertTrue(function.function(player)); + } + + @Test + public void testAboveBalance() throws Exception { + PlayerWrapper player = this.getFactory().createPlayer(); + MockEconomy economy = this.getFactory().inject().getEconomy(); + int withdrawAmount = 9; + BigDecimal depositAmount = new BigDecimal(withdrawAmount + 1); + economy.deposit(player, depositAmount); + Function function = new MoneyWithdrawFunction(); + function.setData("" + withdrawAmount); + assertTrue(function.function(player)); + } +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/NoPermissionFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/NoPermissionFunctionTest.java new file mode 100644 index 000000000..93f04b05b --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/NoPermissionFunctionTest.java @@ -0,0 +1,54 @@ +/* + * 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.test.function; + +import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper; +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.NoPermissionFunction; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class NoPermissionFunctionTest extends FactoryTest { + + @Test + public void testNullData() throws Exception { + Function function = new NoPermissionFunction(); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void testHasNoPermission() throws Exception { + this.getFactory().inject(); + Function function = new NoPermissionFunction(); + function.setData("test"); + assertTrue(function.function(this.getFactory().createPlayer())); + } + + @Test + public void testHasPermission() throws Exception { + String permission = "test"; + this.getFactory().inject(); + Function function = new NoPermissionFunction(); + function.setData(permission); + PlayerWrapper player = this.getFactory().createPlayer(); + player.addPermission(permission); + assertFalse(function.function(player)); + } +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/ParticleFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/ParticleFunctionTest.java new file mode 100644 index 000000000..b17db7b8a --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/ParticleFunctionTest.java @@ -0,0 +1,44 @@ +/* + * 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.test.function; + +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.ParticleFunction; +import com.clubobsidian.dynamicgui.core.test.mock.entity.player.MockPlayerWrapper; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class ParticleFunctionTest extends FactoryTest { + + @Test + public void testNullData() throws Exception { + Function function = new ParticleFunction(); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void testValid() throws Exception { + Function function = new ParticleFunction(); + function.setData("test,0"); + MockPlayerWrapper player = this.getFactory().createPlayer(); + assertTrue(function.function(player)); + assertTrue(player.getParticles().size() == 1); + } +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/PermissionFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/PermissionFunctionTest.java new file mode 100644 index 000000000..e6c45fb8c --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/PermissionFunctionTest.java @@ -0,0 +1,54 @@ +/* + * 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.test.function; + +import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper; +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.PermissionFunction; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class PermissionFunctionTest extends FactoryTest { + + @Test + public void nullTest() throws Exception { + Function function = new PermissionFunction(); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + + @Test + public void doesNotHavePermissionTest() throws Exception { + Function function = new PermissionFunction(); + function.setData("test"); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void hasPermissionTest() throws Exception { + String permission = "test"; + Function function = new PermissionFunction(); + function.setData(permission); + PlayerWrapper player = this.getFactory().createPlayer(); + player.addPermission(permission); + assertTrue(function.function(player)); + } + +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/PlayerCommandFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/PlayerCommandFunctionTest.java new file mode 100644 index 000000000..36a53c48c --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/PlayerCommandFunctionTest.java @@ -0,0 +1,48 @@ +/* + * 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.test.function; + +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.PlayerCommandFunction; +import com.clubobsidian.dynamicgui.core.test.mock.entity.player.MockPlayerWrapper; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class PlayerCommandFunctionTest extends FactoryTest { + + @Test + public void nullDataTest() throws Exception { + Function function = new PlayerCommandFunction(); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void validTest() throws Exception { + String cmd = "test"; + String slashCmd = "/" + cmd; + Function function = new PlayerCommandFunction(); + function.setData(cmd); + MockPlayerWrapper player = this.getFactory().createPlayer(); + assertTrue(function.function(player)); + assertTrue(player.getOutgoingChat().size() == 1); + assertEquals(slashCmd, player.getOutgoingChat().get(0)); + } +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/PlayerMessageFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/PlayerMessageFunctionTest.java new file mode 100644 index 000000000..ceae82039 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/PlayerMessageFunctionTest.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.test.function; + +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.PlayerMessageFunction; +import com.clubobsidian.dynamicgui.core.test.mock.entity.player.MockPlayerWrapper; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class PlayerMessageFunctionTest extends FactoryTest { + + @Test + public void nullTest() throws Exception { + Function function = new PlayerMessageFunction(); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void withDataTest() throws Exception { + String data = "test"; + MockPlayerWrapper playerWrapper = this.getFactory().createPlayer(); + Function function = new PlayerMessageFunction(); + function.setData(data); + assertTrue(function.function(playerWrapper)); + assertEquals(1, playerWrapper.getIncomingChat().size()); + assertEquals(data, playerWrapper.getIncomingChat().get(0)); + } +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/PlayerMiniMessageFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/PlayerMiniMessageFunctionTest.java new file mode 100644 index 000000000..3826849ce --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/PlayerMiniMessageFunctionTest.java @@ -0,0 +1,48 @@ +/* + * 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.test.function; + +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.PlayerMiniMessageFunction; +import com.clubobsidian.dynamicgui.core.test.mock.entity.player.MockPlayerWrapper; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class PlayerMiniMessageFunctionTest extends FactoryTest { + + @Test + public void nullTest() throws Exception { + Function function = new PlayerMiniMessageFunction(); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void dataTest() throws Exception { + this.getFactory().inject(); + String data = "test"; + Function function = new PlayerMiniMessageFunction(); + function.setData(data); + MockPlayerWrapper player = this.getFactory().createPlayer(); + assertTrue(function.function(player)); + assertEquals(1, player.getIncomingChat().size()); + assertEquals("{\"text\":\"test\"}", player.getIncomingChat().get(0)); + } +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/PlayerMsgJsonFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/PlayerMsgJsonFunctionTest.java new file mode 100644 index 000000000..1d938e46f --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/PlayerMsgJsonFunctionTest.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.test.function; + +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.PlayerMsgJsonFunction; +import com.clubobsidian.dynamicgui.core.test.mock.entity.player.MockPlayerWrapper; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class PlayerMsgJsonFunctionTest extends FactoryTest { + + @Test + public void nullTest() throws Exception { + Function function = new PlayerMsgJsonFunction(); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void dataTest() throws Exception { + String data = "{\"text\":\"test\"}"; + Function function = new PlayerMsgJsonFunction(); + function.setData(data); + MockPlayerWrapper player = this.getFactory().createPlayer(); + assertTrue(function.function(player)); + assertEquals(1, player.getIncomingChat().size()); + assertEquals(data, player.getIncomingChat().get(0)); + } +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/RandomFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/RandomFunctionTest.java new file mode 100644 index 000000000..083c429d4 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/RandomFunctionTest.java @@ -0,0 +1,48 @@ +/* + * 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.test.function; + +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.RandomFunction; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class RandomFunctionTest extends FactoryTest { + + @Test + public void nullTest() throws Exception { + Function function = new RandomFunction(); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void incorrectLengthTest() throws Exception { + Function function = new RandomFunction(); + function.setData("1-1-1"); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void correctLengthTest() throws Exception { + Function function = new RandomFunction(); + function.setData("1-1"); + assertTrue(function.function(this.getFactory().createPlayer())); + } +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/RemovePermissionFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/RemovePermissionFunctionTest.java new file mode 100644 index 000000000..8b30838f4 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/RemovePermissionFunctionTest.java @@ -0,0 +1,54 @@ +/* + * 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.test.function; + +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.RemovePermissionFunction; +import com.clubobsidian.dynamicgui.core.test.mock.entity.player.MockPlayerWrapper; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class RemovePermissionFunctionTest extends FactoryTest { + + @Test + public void nullTest() throws Exception { + Function function = new RemovePermissionFunction(); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void permissionNotRemovedTest() throws Exception { + String permission = "data"; + Function function = new RemovePermissionFunction(); + function.setData(permission); + MockPlayerWrapper player = this.getFactory().createPlayer(); + assertFalse(function.function(player)); + } + + @Test + public void permissionRemoveTest() throws Exception { + String permission = "data"; + Function function = new RemovePermissionFunction(); + function.setData(permission); + MockPlayerWrapper player = this.getFactory().createPlayer(); + player.addPermission(permission); + assertTrue(function.function(player)); + } +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/RemoveSlotFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/RemoveSlotFunctionTest.java new file mode 100644 index 000000000..5fc15dc24 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/RemoveSlotFunctionTest.java @@ -0,0 +1,73 @@ +/* + * 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.test.function; + +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.RemoveSlotFunction; +import com.clubobsidian.dynamicgui.core.gui.Gui; +import com.clubobsidian.dynamicgui.core.gui.Slot; +import com.clubobsidian.dynamicgui.core.test.mock.entity.player.MockPlayerWrapper; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class RemoveSlotFunctionTest extends FactoryTest { + + @Test + public void randomDataTest() throws Exception { + Function function = new RemoveSlotFunction(); + function.setData(UUID.randomUUID().toString()); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void noDataTest() throws Exception { + this.getFactory().inject(); + MockPlayerWrapper player = this.getFactory().createPlayer(); + Slot slot = this.getFactory().createSlot(0, Slot.TEST_MATERIAL, false); + slot.buildItemStack(player); + List slots = new ArrayList<>(); + Gui gui = this.getFactory().createGui("test", slots); + gui.buildInventory(player); + slot.setOwner(gui); + Function function = new RemoveSlotFunction(); + function.setOwner(slot); + assertTrue(function.function(player)); + } + + @Test + public void thisDataTest() throws Exception { + this.getFactory().inject(); + MockPlayerWrapper player = this.getFactory().createPlayer(); + Slot slot = this.getFactory().createSlot(0, Slot.TEST_MATERIAL, false); + slot.buildItemStack(player); + List slots = new ArrayList<>(); + Gui gui = this.getFactory().createGui("test", slots); + gui.buildInventory(player); + slot.setOwner(gui); + Function function = new RemoveSlotFunction(); + function.setData("this"); + function.setOwner(slot); + assertTrue(function.function(player)); + } +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/ResetFrameFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/ResetFrameFunctionTest.java new file mode 100644 index 000000000..2098097e6 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/ResetFrameFunctionTest.java @@ -0,0 +1,46 @@ +/* + * 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.test.function; + +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.ResetFrameFunction; +import com.clubobsidian.dynamicgui.core.gui.Gui; +import com.clubobsidian.dynamicgui.core.gui.Slot; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class ResetFrameFunctionTest extends FactoryTest { + + @Test + public void ownerNotSlotTest() throws Exception { + Gui gui = this.getFactory().createGui("test"); + Function function = new ResetFrameFunction(); + function.setOwner(gui); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void slotOwnerTest() throws Exception { + Slot slot = this.getFactory().createSlot(); + Function function = new ResetFrameFunction(); + function.setOwner(slot); + assertTrue(function.function(this.getFactory().createPlayer())); + } +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/ResetTickFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/ResetTickFunctionTest.java new file mode 100644 index 000000000..4adce9805 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/ResetTickFunctionTest.java @@ -0,0 +1,46 @@ +/* + * 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.test.function; + +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.ResetTickFunction; +import com.clubobsidian.dynamicgui.core.gui.Gui; +import com.clubobsidian.dynamicgui.core.gui.Slot; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class ResetTickFunctionTest extends FactoryTest { + + @Test + public void ownerNotSlotTest() throws Exception { + Gui gui = this.getFactory().createGui("test"); + Function function = new ResetTickFunction(); + function.setOwner(gui); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void slotOwnerTest() throws Exception { + Slot slot = this.getFactory().createSlot(); + Function function = new ResetTickFunction(); + function.setOwner(slot); + assertTrue(function.function(this.getFactory().createPlayer())); + } +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SendFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SendFunctionTest.java new file mode 100644 index 000000000..665a93a3b --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SendFunctionTest.java @@ -0,0 +1,77 @@ +/* + * 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.test.function; + +import com.clubobsidian.dynamicgui.core.DynamicGui; +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.SendFunction; +import com.clubobsidian.dynamicgui.core.proxy.Proxy; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import java.lang.reflect.Field; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class SendFunctionTest extends FactoryTest { + + @Test + public void nullTest() throws Exception { + Function function = new SendFunction(); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void noProxyTest() throws Exception { + this.getFactory().inject(); + Function function = new SendFunction(); + function.setData("test"); + assertTrue(this.setProxy(Proxy.NONE)); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void bungeeCordTest() throws Exception { + this.getFactory().inject(); + Function function = new SendFunction(); + function.setData("test"); + assertTrue(this.setProxy(Proxy.BUNGEECORD)); + assertTrue(function.function(this.getFactory().createPlayer())); + } + + @Test + public void redisBungeeTest() throws Exception { + this.getFactory().inject(); + Function function = new SendFunction(); + function.setData("test"); + assertTrue(this.setProxy(Proxy.REDIS_BUNGEE)); + assertTrue(function.function(this.getFactory().createPlayer())); + } + + private boolean setProxy(Proxy proxy) { + try { + Field proxyField = DynamicGui.class.getDeclaredField("proxy"); + proxyField.setAccessible(true); + proxyField.set(DynamicGui.get(), proxy); + return true; + } catch (NoSuchFieldException | IllegalAccessException e) { + e.printStackTrace(); + return false; + } + } +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/ServerBroadcastFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/ServerBroadcastFunctionTest.java new file mode 100644 index 000000000..d152f470a --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/ServerBroadcastFunctionTest.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.test.function; + +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.ServerBroadcastFunction; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import com.clubobsidian.dynamicgui.core.util.ChatColor; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class ServerBroadcastFunctionTest extends FactoryTest { + + @Test + public void noDataTest() throws Exception { + Function function = new ServerBroadcastFunction(); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void dataTest() throws Exception { + this.getFactory().inject(); + String data = "&4test"; + String colorized = ChatColor.translateAlternateColorCodes(data); + Function function = new ServerBroadcastFunction(); + function.setData(data); + assertTrue(function.function(this.getFactory().createPlayer())); + List messages = this.getFactory().getPlatform().getBroadcastMessages(); + assertTrue(messages.size() == 1); + assertEquals(colorized, messages.get(0)); + } +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/ServerBroadcastJsonFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/ServerBroadcastJsonFunctionTest.java new file mode 100644 index 000000000..adf9e768a --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/ServerBroadcastJsonFunctionTest.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.test.function; + +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.ServerBroadcastJsonFunction; +import com.clubobsidian.dynamicgui.core.manager.dynamicgui.MiniMessageManager; +import com.clubobsidian.dynamicgui.core.test.mock.plugin.MockPlatform; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class ServerBroadcastJsonFunctionTest extends FactoryTest { + + @Test + public void nullTest() throws Exception { + Function function = new ServerBroadcastJsonFunction(); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void dataTest() throws Exception { + MockPlatform platform = this.getFactory().inject().getPlatform(); + String json = MiniMessageManager.get().toJson("test"); + Function function = new ServerBroadcastJsonFunction(); + function.setData(json); + assertTrue(function.function(this.getFactory().createPlayer())); + List messages = platform.getBroadcastMessages(); + assertTrue(messages.size() == 1); + assertEquals(json, messages.get(0)); + } +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/ServerMiniBroadcastFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/ServerMiniBroadcastFunctionTest.java new file mode 100644 index 000000000..90d131835 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/ServerMiniBroadcastFunctionTest.java @@ -0,0 +1,52 @@ +/* + * 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.test.function; + +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.ServerMiniBroadcastFunction; +import com.clubobsidian.dynamicgui.core.manager.dynamicgui.MiniMessageManager; +import com.clubobsidian.dynamicgui.core.test.mock.plugin.MockPlatform; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class ServerMiniBroadcastFunctionTest extends FactoryTest { + + @Test + public void nullTest() throws Exception { + Function function = new ServerMiniBroadcastFunction(); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void dataTest() throws Exception { + MockPlatform platform = this.getFactory().inject().getPlatform(); + String data = "test"; + String json = MiniMessageManager.get().toJson(data); + Function function = new ServerMiniBroadcastFunction(); + function.setData(data); + assertTrue(function.function(this.getFactory().createPlayer())); + List messages = platform.getBroadcastMessages(); + assertTrue(messages.size() == 1); + assertEquals(json, messages.get(0)); + } +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SetAmountFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SetAmountFunctionTest.java new file mode 100644 index 000000000..cc5cab419 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SetAmountFunctionTest.java @@ -0,0 +1,86 @@ +/* + * 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.test.function; + +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.SetAmountFunction; +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.test.mock.entity.player.MockPlayerWrapper; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class SetAmountFunctionTest extends FactoryTest { + + @Test + public void nullTest() throws Exception { + Function function = new SetAmountFunction(); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void nonSlotOwnerTest() throws Exception { + Function function = new SetAmountFunction(); + function.setOwner(this.getFactory().createGui("test")); + function.setData("1"); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void invalidDataTest() throws Exception { + this.getFactory().inject(); + MockPlayerWrapper player = this.getFactory().createPlayer(); + Slot slot = this.getFactory().createSlot(); + slot.buildItemStack(player); + List slots = new ArrayList<>(); + slots.add(slot); + Gui gui = this.getFactory().createGui("test", slots); + gui.buildInventory(player); + slot.setOwner(gui); + Function function = new SetAmountFunction(); + function.setOwner(slot); + function.setData("a"); + assertFalse(function.function(player)); + } + + @Test + public void dataTest() throws Exception { + this.getFactory().inject(); + MockPlayerWrapper player = this.getFactory().createPlayer(); + int newAmount = 2; + Slot slot = this.getFactory().createSlot(); + slot.buildItemStack(player); + List slots = new ArrayList<>(); + slots.add(slot); + Gui gui = this.getFactory().createGui("test", slots); + InventoryWrapper inventory = gui.buildInventory(player); + slot.setOwner(gui); + Function function = new SetAmountFunction(); + function.setOwner(slot); + function.setData("" + newAmount); + assertTrue(function.function(player)); + assertEquals(newAmount, inventory.getItem(slot.getIndex()).getAmount()); + } +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SetCloseFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SetCloseFunctionTest.java new file mode 100644 index 000000000..ec629c081 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SetCloseFunctionTest.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.test.function; + +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.SetCloseFunction; +import com.clubobsidian.dynamicgui.core.gui.FunctionOwner; +import com.clubobsidian.dynamicgui.core.gui.property.CloseableComponent; +import com.clubobsidian.dynamicgui.core.test.mock.gui.MockCloseableFunctionOwner; +import com.clubobsidian.dynamicgui.core.test.mock.gui.MockNonCloseableFunctionOwner; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class SetCloseFunctionTest extends FactoryTest { + + @Test + public void nullTest() throws Exception { + Function function = new SetCloseFunction(); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void nonCloseableComponentTest() throws Exception { + Function function = new SetCloseFunction(); + function.setOwner(new MockNonCloseableFunctionOwner()); + function.setData("true"); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void invalidDataTest() throws Exception { + Function function = new SetCloseFunction(); + CloseableComponent component = new MockCloseableFunctionOwner(); + function.setOwner((FunctionOwner) component); + function.setData("a"); + assertTrue(function.function(this.getFactory().createPlayer())); + assertEquals(false, component.getClose()); + } + + @Test + public void validDataTest() throws Exception { + Function function = new SetCloseFunction(); + CloseableComponent component = new MockCloseableFunctionOwner(); + function.setOwner((FunctionOwner) component); + function.setData("true"); + assertTrue(function.function(this.getFactory().createPlayer())); + assertEquals(true, component.getClose()); + } +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SetCooldownFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SetCooldownFunctionTest.java new file mode 100644 index 000000000..54343d8d4 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SetCooldownFunctionTest.java @@ -0,0 +1,69 @@ +/* + * 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.test.function; + +import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper; +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.cooldown.SetCooldownFunction; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import java.util.UUID; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class SetCooldownFunctionTest extends FactoryTest { + + @Test + public void nullDataTest() throws Exception { + Function function = new SetCooldownFunction(); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void noCommaTest() throws Exception { + Function function = new SetCooldownFunction(); + function.setData("a"); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void invalidNumberTest() throws Exception { + Function function = new SetCooldownFunction(); + function.setData("a,a"); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void lengthNotTwoTest() throws Exception { + Function function = new SetCooldownFunction(); + function.setData("a,a,a"); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void onCooldownTest() throws Exception { + this.getFactory().inject(); + PlayerWrapper player = this.getFactory().createPlayer(); + String cooldownName = UUID.randomUUID().toString(); + String data = cooldownName + ",1000"; + Function function = new SetCooldownFunction(); + function.setData(data); + assertTrue(function.function(player)); + } +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SetDurabilityFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SetDurabilityFunctionTest.java new file mode 100644 index 000000000..6431d9040 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SetDurabilityFunctionTest.java @@ -0,0 +1,86 @@ +/* + * 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.test.function; + +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.SetDurabilityFunction; +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.test.mock.entity.player.MockPlayerWrapper; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class SetDurabilityFunctionTest extends FactoryTest { + + @Test + public void nullTest() throws Exception { + Function function = new SetDurabilityFunction(); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void nonSlotOwnerTest() throws Exception { + Function function = new SetDurabilityFunction(); + function.setOwner(this.getFactory().createGui("test")); + function.setData("1"); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void invalidDataTest() throws Exception { + this.getFactory().inject(); + MockPlayerWrapper player = this.getFactory().createPlayer(); + Slot slot = this.getFactory().createSlot(); + slot.buildItemStack(player); + List slots = new ArrayList<>(); + slots.add(slot); + Gui gui = this.getFactory().createGui("test", slots); + gui.buildInventory(player); + slot.setOwner(gui); + Function function = new SetDurabilityFunction(); + function.setOwner(slot); + function.setData("a"); + assertFalse(function.function(player)); + } + + @Test + public void dataTest() throws Exception { + this.getFactory().inject(); + MockPlayerWrapper player = this.getFactory().createPlayer(); + int newDurability = 2; + Slot slot = this.getFactory().createSlot(); + slot.buildItemStack(player); + List slots = new ArrayList<>(); + slots.add(slot); + Gui gui = this.getFactory().createGui("test", slots); + InventoryWrapper inventory = gui.buildInventory(player); + slot.setOwner(gui); + Function function = new SetDurabilityFunction(); + function.setOwner(slot); + function.setData("" + newDurability); + assertTrue(function.function(player)); + assertEquals(newDurability, inventory.getItem(slot.getIndex()).getDurability()); + } +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SetEnchantsFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SetEnchantsFunctionTest.java new file mode 100644 index 000000000..670c2e32a --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SetEnchantsFunctionTest.java @@ -0,0 +1,104 @@ +/* + * 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.test.function; + +import com.clubobsidian.dynamicgui.core.enchantment.EnchantmentWrapper; +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.SetEnchantsFunction; +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.test.mock.entity.player.MockPlayerWrapper; +import com.clubobsidian.dynamicgui.core.test.mock.gui.MockNonCloseableFunctionOwner; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class SetEnchantsFunctionTest extends FactoryTest { + + @Test + public void nullTest() throws Exception { + Function function = new SetEnchantsFunction(); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void noOwnerTest() throws Exception { + Function function = new SetEnchantsFunction(); + function.setData(EnchantmentWrapper.TEST_ENCHANT_2 + ",1"); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void ownerNotSlotTest() throws Exception { + Function function = new SetEnchantsFunction(); + function.setData(EnchantmentWrapper.TEST_ENCHANT_2 + ",1"); + function.setOwner(new MockNonCloseableFunctionOwner()); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void testOneEnchant() throws Exception { + int index = 0; + this.getFactory().inject(); + MockPlayerWrapper player = this.getFactory().createPlayer(); + List enchants = new ArrayList<>(); + enchants.add(new EnchantmentWrapper(EnchantmentWrapper.TEST_ENCHANT_1, 1)); + Slot slot = this.getFactory().createSlot(index, Slot.TEST_MATERIAL, enchants, false); + slot.buildItemStack(player); + List slots = new ArrayList<>(); + slots.add(slot); + Gui gui = this.getFactory().createGui("test", slots); + InventoryWrapper inventory = gui.buildInventory(player); + slot.setOwner(gui); + Function function = new SetEnchantsFunction(); + function.setOwner(slot); + function.setData(EnchantmentWrapper.TEST_ENCHANT_2 + ",1"); + assertTrue(function.function(this.getFactory().createPlayer())); + assertTrue(inventory.getItem(index).getEnchants().size() == 1); + assertEquals(EnchantmentWrapper.TEST_ENCHANT_2, inventory.getItem(index).getEnchants().get(0).getEnchant()); + } + + @Test + public void testMultipleEnchants() throws Exception { + int index = 0; + this.getFactory().inject(); + MockPlayerWrapper player = this.getFactory().createPlayer(); + List enchants = new ArrayList<>(); + enchants.add(new EnchantmentWrapper(EnchantmentWrapper.TEST_ENCHANT_1, 1)); + Slot slot = this.getFactory().createSlot(index, Slot.TEST_MATERIAL, enchants, false); + slot.buildItemStack(player); + List slots = new ArrayList<>(); + slots.add(slot); + Gui gui = this.getFactory().createGui("test", slots); + InventoryWrapper inventory = gui.buildInventory(player); + slot.setOwner(gui); + Function function = new SetEnchantsFunction(); + function.setOwner(slot); + function.setData(EnchantmentWrapper.TEST_ENCHANT_2 + ",1;" + EnchantmentWrapper.TEST_ENCHANT_3 + ",1"); + assertTrue(function.function(this.getFactory().createPlayer())); + assertTrue(inventory.getItem(index).getEnchants().size() == 2); + assertEquals(EnchantmentWrapper.TEST_ENCHANT_2, inventory.getItem(index).getEnchants().get(0).getEnchant()); + assertEquals(EnchantmentWrapper.TEST_ENCHANT_3, inventory.getItem(index).getEnchants().get(1).getEnchant()); + } +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SetGameRuleFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SetGameRuleFunctionTest.java new file mode 100644 index 000000000..d26cf3248 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SetGameRuleFunctionTest.java @@ -0,0 +1,69 @@ +/* + * 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.test.function; + +import com.clubobsidian.dynamicgui.core.DynamicGui; +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.SetGameRuleFunction; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import com.clubobsidian.dynamicgui.core.test.mock.world.MockWorldWrapper; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class SetGameRuleFunctionTest extends FactoryTest { + + @Test + public void nullTest() throws Exception { + Function function = new SetGameRuleFunction(); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void dataDoesNotHaveCommaTest() throws Exception { + Function function = new SetGameRuleFunction(); + function.setData("a"); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void sizeNotThreeTest() throws Exception { + Function function = new SetGameRuleFunction(); + function.setData("a,a"); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void worldNullTest() throws Exception { + this.getFactory().inject(); + Function function = new SetGameRuleFunction(); + function.setData("test,key,value"); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void validTest() throws Exception { + MockWorldWrapper world = this.getFactory().inject().createWorld("test"); + this.getFactory().getPlatform().addWorld(world); + Function function = new SetGameRuleFunction(); + function.setData("test,key,value"); + assertTrue(function.function(this.getFactory().createPlayer())); + assertEquals("value", DynamicGui.get().getPlatform().getWorld("test").getGameRule("key")); + } +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SetGlowFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SetGlowFunctionTest.java new file mode 100644 index 000000000..fdc0f238f --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SetGlowFunctionTest.java @@ -0,0 +1,55 @@ +/* + * 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.test.function; + +import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper; +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.SetGlowFunction; +import com.clubobsidian.dynamicgui.core.gui.Slot; +import com.clubobsidian.dynamicgui.core.test.mock.gui.MockNonCloseableFunctionOwner; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class SetGlowFunctionTest extends FactoryTest { + + @Test + public void nullTest() throws Exception { + Function function = new SetGlowFunction(); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void notSlotTest() throws Exception { + Function function = new SetGlowFunction(); + function.setData("true"); + function.setOwner(new MockNonCloseableFunctionOwner()); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void slotTest() throws Exception { + PlayerWrapper player = this.getFactory().createPlayer(); + Slot slot = this.getFactory().createSlot(player); + Function function = new SetGlowFunction(); + function.setData("true"); + function.setOwner(slot); + assertTrue(function.function(player)); + } +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SetLoreFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SetLoreFunctionTest.java new file mode 100644 index 000000000..380dc7257 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SetLoreFunctionTest.java @@ -0,0 +1,86 @@ +/* + * 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.test.function; + +import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper; +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.SetLoreFunction; +import com.clubobsidian.dynamicgui.core.gui.Gui; +import com.clubobsidian.dynamicgui.core.gui.Slot; +import com.clubobsidian.dynamicgui.core.test.mock.gui.MockNonCloseableFunctionOwner; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class SetLoreFunctionTest extends FactoryTest { + + @Test + public void nullTest() throws Exception { + PlayerWrapper player = this.getFactory().createPlayer(); + String line = "test"; + List lore = new ArrayList<>(); + lore.add(line); + Slot slot = this.getFactory().createSlot(player, lore); + Function function = new SetLoreFunction(); + function.setOwner(slot); + Gui gui = slot.getOwner(); + assertTrue(function.function(player)); + assertTrue(gui.getInventoryWrapper().getItem(slot.getIndex()).getLore().size() == 0); + } + + @Test + public void nonSlotTest() throws Exception { + Function function = new SetLoreFunction(); + function.setOwner(new MockNonCloseableFunctionOwner()); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void oneLineTest() throws Exception { + PlayerWrapper player = this.getFactory().createPlayer(); + Slot slot = this.getFactory().createSlot(player); + Function function = new SetLoreFunction(); + function.setData("test"); + function.setOwner(slot); + Gui gui = slot.getOwner(); + assertTrue(function.function(player)); + List lore = gui.getInventoryWrapper().getItem(slot.getIndex()).getLore(); + assertTrue(lore.size() == 1); + assertEquals("test", lore.get(0)); + } + + @Test + public void multiLineTest() throws Exception { + PlayerWrapper player = this.getFactory().createPlayer(); + Slot slot = this.getFactory().createSlot(player); + Function function = new SetLoreFunction(); + function.setData("test1\ntest2"); + function.setOwner(slot); + Gui gui = slot.getOwner(); + assertTrue(function.function(player)); + List lore = gui.getInventoryWrapper().getItem(slot.getIndex()).getLore(); + assertTrue(lore.size() == 2); + assertEquals("test1", lore.get(0)); + assertEquals("test2", lore.get(1)); + } +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SetMovableFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SetMovableFunctionTest.java new file mode 100644 index 000000000..9dba65e9b --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SetMovableFunctionTest.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.test.function; + +import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper; +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.SetMovableFunction; +import com.clubobsidian.dynamicgui.core.gui.Slot; +import com.clubobsidian.dynamicgui.core.test.mock.gui.MockNonCloseableFunctionOwner; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class SetMovableFunctionTest extends FactoryTest { + + @Test + public void nullTest() throws Exception { + Function function = new SetMovableFunction(); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void notSlotTest() throws Exception { + Function function = new SetMovableFunction(); + function.setData("a"); + function.setOwner(new MockNonCloseableFunctionOwner()); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void setMovableFalseTest() throws Exception { + PlayerWrapper player = this.getFactory().createPlayer(); + Function function = new SetMovableFunction(); + function.setData("false"); + Slot slot = this.getFactory().createSlot(player); + function.setOwner(slot); + assertTrue(function.function(this.getFactory().createPlayer())); + assertFalse(slot.isMovable()); + } + + @Test + public void setMovableTrueTest() throws Exception { + PlayerWrapper player = this.getFactory().createPlayer(); + Function function = new SetMovableFunction(); + function.setData("true"); + Slot slot = this.getFactory().createSlot(player); + function.setOwner(slot); + assertTrue(function.function(this.getFactory().createPlayer())); + assertTrue(slot.isMovable()); + } +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SetNBTFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SetNBTFunctionTest.java new file mode 100644 index 000000000..8a72b7fa7 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SetNBTFunctionTest.java @@ -0,0 +1,62 @@ +/* + * 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.test.function; + +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.SetNBTFunction; +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.test.mock.entity.player.MockPlayerWrapper; +import com.clubobsidian.dynamicgui.core.test.mock.gui.MockNonCloseableFunctionOwner; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class SetNBTFunctionTest extends FactoryTest { + + @Test + public void nullTest() throws Exception { + Function function = new SetNBTFunction(); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void notSlotTest() throws Exception { + Function function = new SetNBTFunction(); + function.setData("asdf"); + function.setOwner(new MockNonCloseableFunctionOwner()); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void nbtTest() throws Exception { + String nbt = "asdf"; + MockPlayerWrapper player = this.getFactory().createPlayer(); + Slot slot = this.getFactory().createSlot(player); + Gui gui = slot.getOwner(); + InventoryWrapper inventory = gui.getInventoryWrapper(); + Function function = new SetNBTFunction(); + function.setOwner(slot); + function.setData(nbt); + assertTrue(function.function(player)); + assertEquals(nbt, inventory.getItem(slot.getIndex()).getNBT()); + } +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SetNameFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SetNameFunctionTest.java new file mode 100644 index 000000000..3a94642b9 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SetNameFunctionTest.java @@ -0,0 +1,62 @@ +/* + * 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.test.function; + +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.SetNameFunction; +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.test.mock.entity.player.MockPlayerWrapper; +import com.clubobsidian.dynamicgui.core.test.mock.gui.MockNonCloseableFunctionOwner; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class SetNameFunctionTest extends FactoryTest { + + @Test + public void nullTest() throws Exception { + Function function = new SetNameFunction(); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void notSlotTest() throws Exception { + Function function = new SetNameFunction(); + function.setData("asdf"); + function.setOwner(new MockNonCloseableFunctionOwner()); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void nameTest() throws Exception { + String name = "asdf"; + MockPlayerWrapper player = this.getFactory().createPlayer(); + Slot slot = this.getFactory().createSlot(player); + Gui gui = slot.getOwner(); + InventoryWrapper inventory = gui.getInventoryWrapper(); + Function function = new SetNameFunction(); + function.setOwner(slot); + function.setData(name); + assertTrue(function.function(player)); + assertEquals(name, inventory.getItem(slot.getIndex()).getName()); + } +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SetTypeFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SetTypeFunctionTest.java new file mode 100644 index 000000000..a85010552 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SetTypeFunctionTest.java @@ -0,0 +1,62 @@ +/* + * 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.test.function; + +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.SetTypeFunction; +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.test.mock.entity.player.MockPlayerWrapper; +import com.clubobsidian.dynamicgui.core.test.mock.gui.MockNonCloseableFunctionOwner; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class SetTypeFunctionTest extends FactoryTest { + + @Test + public void nullTest() throws Exception { + Function function = new SetTypeFunction(); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void notSlotTest() throws Exception { + Function function = new SetTypeFunction(); + function.setData(Slot.TEST_MATERIAL); + function.setOwner(new MockNonCloseableFunctionOwner()); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void typeTest() throws Exception { + String type = Slot.TEST_MATERIAL; + MockPlayerWrapper player = this.getFactory().createPlayer(); + Slot slot = this.getFactory().createSlot(player); + Gui gui = slot.getOwner(); + InventoryWrapper inventory = gui.getInventoryWrapper(); + Function function = new SetTypeFunction(); + function.setOwner(slot); + function.setData(type); + assertTrue(function.function(player)); + assertEquals(type, inventory.getItem(slot.getIndex()).getType()); + } +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SoundFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SoundFunctionTest.java new file mode 100644 index 000000000..043e6f7b1 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/SoundFunctionTest.java @@ -0,0 +1,54 @@ +/* + * 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.test.function; + +import com.clubobsidian.dynamicgui.core.effect.SoundWrapper; +import com.clubobsidian.dynamicgui.core.function.Function; +import com.clubobsidian.dynamicgui.core.function.impl.SoundFunction; +import com.clubobsidian.dynamicgui.core.gui.Slot; +import com.clubobsidian.dynamicgui.core.test.mock.entity.player.MockPlayerWrapper; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class SoundFunctionTest extends FactoryTest { + + @Test + public void nullTest() throws Exception { + Function function = new SoundFunction(); + assertFalse(function.function(this.getFactory().createPlayer())); + } + + @Test + public void soundTest() throws Exception { + String type = SoundWrapper.TEST_SOUND_STRING; + MockPlayerWrapper player = this.getFactory().createPlayer(); + Slot slot = this.getFactory().createSlot(player); + Function function = new SoundFunction(); + function.setOwner(slot); + function.setData(type); + assertTrue(function.function(player)); + List sounds = player.getSounds(); + assertTrue(sounds.size() == 1); + assertEquals(new SoundWrapper(SoundWrapper.TEST_SOUND_STRING).getData(), sounds.get(0)); + } +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/manager/FunctionManagerTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/manager/FunctionManagerTest.java new file mode 100644 index 000000000..855ed1a03 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/manager/FunctionManagerTest.java @@ -0,0 +1,173 @@ +/* + * 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.test.manager; + +import com.clubobsidian.dynamicgui.core.gui.Gui; +import com.clubobsidian.dynamicgui.core.gui.Slot; +import com.clubobsidian.dynamicgui.core.manager.dynamicgui.FunctionManager; +import com.clubobsidian.dynamicgui.core.manager.dynamicgui.GuiManager; +import com.clubobsidian.dynamicgui.core.test.mock.entity.player.MockPlayerWrapper; +import com.clubobsidian.dynamicgui.core.test.mock.test.ScheduledTest; +import com.clubobsidian.dynamicgui.parser.function.FunctionType; +import org.junit.jupiter.api.Test; + +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class FunctionManagerTest extends ScheduledTest { + + @Test + public void testHasAsyncFunctionRunningPassing() throws InterruptedException, ExecutionException { + MockPlayerWrapper playerWrapper = this.getFactory().createPlayer(); + Gui gui = GuiManager.get().getGui("test"); + Slot slot = gui.getSlots().get(2); + CompletableFuture future = FunctionManager + .get() + .tryFunctions(slot, FunctionType.CLICK, playerWrapper); + Thread.sleep(500); + boolean has = FunctionManager.get().hasAsyncFunctionRunning(playerWrapper); + future.get(); + assertTrue(has); + } + + @Test + public void testHasAsyncFunctionRunningFailing() throws ExecutionException, InterruptedException { + MockPlayerWrapper playerWrapper = this.getFactory().createPlayer(); + Gui gui = GuiManager.get().getGui("test"); + Slot slot = gui.getSlots().get(2); + FunctionManager.get().tryFunctions(slot, FunctionType.CLICK, playerWrapper).get(); + assertFalse(FunctionManager.get().hasAsyncFunctionRunning(playerWrapper)); + } + + @Test + public void testHasAsyncFunctionRunningWithFunctionNamePassing() throws InterruptedException, ExecutionException { + MockPlayerWrapper playerWrapper = this.getFactory().createPlayer(); + Gui gui = GuiManager.get().getGui("test"); + Slot slot = gui.getSlots().get(2); + CompletableFuture future = FunctionManager + .get() + .tryFunctions(slot, FunctionType.CLICK, playerWrapper); + Thread.sleep(500); + boolean has = FunctionManager.get().hasAsyncFunctionRunning(playerWrapper, "delay"); + future.get(); + assertTrue(has); + } + + @Test + public void testHasAsyncFunctionRunningWithFunctionNameFailing() throws ExecutionException, InterruptedException { + MockPlayerWrapper playerWrapper = this.getFactory().createPlayer(); + Gui gui = GuiManager.get().getGui("test"); + Slot slot = gui.getSlots().get(2); + FunctionManager.get().tryFunctions(slot, FunctionType.CLICK, playerWrapper).get(); + assertFalse(FunctionManager.get().hasAsyncFunctionRunning(playerWrapper, "delay")); + } + + @Test + public void testTryFunctionsPassing() throws ExecutionException, InterruptedException { + MockPlayerWrapper playerWrapper = this.getFactory().createPlayer(); + Gui gui = GuiManager.get().getGui("test"); + Slot slot = gui.getSlots().get(0); + assertTrue(FunctionManager.get().tryFunctions(slot, FunctionType.CLICK, playerWrapper).get()); + assertTrue(playerWrapper.getIncomingChat().size() == 1); + assertEquals("test", playerWrapper.getIncomingChat().get(0)); + } + + @Test + public void testTryFunctionsFailing() throws ExecutionException, InterruptedException { + MockPlayerWrapper playerWrapper = this.getFactory().createPlayer(); + Gui gui = GuiManager.get().getGui("test"); + Slot slot = gui.getSlots().get(1); + assertFalse(FunctionManager.get().tryFunctions(slot, FunctionType.CLICK, playerWrapper).get()); + assertTrue(playerWrapper.getIncomingChat().size() == 1); + assertEquals("fail", playerWrapper.getIncomingChat().get(0)); + } + + @Test + public void testTryFunctionsAsync() throws ExecutionException, InterruptedException { + MockPlayerWrapper playerWrapper = this.getFactory().createPlayer(); + Gui gui = GuiManager.get().getGui("test"); + Slot slot = gui.getSlots().get(2); + long time = System.currentTimeMillis(); + assertTrue(FunctionManager.get().tryFunctions(slot, FunctionType.CLICK, playerWrapper).get()); + assertTrue(playerWrapper.getIncomingChat().size() == 1); + assertEquals("async", playerWrapper.getIncomingChat().get(0)); + long delta = System.currentTimeMillis() - time; + assertTrue(delta >= 500); + } + + @Test + public void testTryFunctionsMainThread() throws ExecutionException, InterruptedException { + MockPlayerWrapper playerWrapper = this.getFactory().createPlayer(); + Gui gui = GuiManager.get().getGui("test"); + Slot slot = gui.getSlots().get(3); + assertTrue(FunctionManager.get().tryFunctions(slot, FunctionType.CLICK, playerWrapper).get()); + } + + @Test + public void testTryFunctionsAsyncThread() throws ExecutionException, InterruptedException { + MockPlayerWrapper playerWrapper = this.getFactory().createPlayer(); + Gui gui = GuiManager.get().getGui("test"); + Slot slot = gui.getSlots().get(4); + assertTrue(FunctionManager.get().tryFunctions(slot, FunctionType.CLICK, playerWrapper).get()); + } + + @Test + public void testLoadWithClick() throws ExecutionException, InterruptedException { + MockPlayerWrapper playerWrapper = this.getFactory().createPlayer(); + playerWrapper.addPermission("test"); + Gui gui = GuiManager.get().getGui("multi-function-test"); + Slot slot = gui.getSlots().get(0); + boolean failed = FunctionManager.get().tryFunctions(slot, FunctionType.LOAD, playerWrapper).get(); + assertFalse(failed); + List chat = playerWrapper.getIncomingChat(); + assertEquals(1, chat.size()); + assertEquals("condition failed", chat.get(0)); + } + + @Test + public void testFailNoFailFunction() throws ExecutionException, InterruptedException { + MockPlayerWrapper playerWrapper = this.getFactory().createPlayer(); + Gui gui = GuiManager.get().getGui("no-fail-function"); + Slot slot = gui.getSlots().get(0); + boolean failed = FunctionManager.get().tryFunctions(slot, FunctionType.LOAD, playerWrapper).get(); + assertFalse(failed); + } + + @Test + public void testNoFunctionType() throws ExecutionException, InterruptedException { + MockPlayerWrapper playerWrapper = this.getFactory().createPlayer(); + playerWrapper.addPermission("test"); + Gui gui = GuiManager.get().getGui("test-no-function-type"); + Slot slot = gui.getSlots().get(0); + boolean result = FunctionManager.get().tryFunctions(slot, FunctionType.LOAD, playerWrapper).get(); + assertTrue(result); + } + + @Test + public void testFailNoFailType() throws ExecutionException, InterruptedException { + MockPlayerWrapper playerWrapper = this.getFactory().createPlayer(); + Gui gui = GuiManager.get().getGui("test-fail-no-fail-type"); + Slot slot = gui.getSlots().get(0); + boolean result = FunctionManager.get().tryFunctions(slot, FunctionType.LOAD, playerWrapper).get(); + assertFalse(result); + } +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/manager/GuiManagerTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/manager/GuiManagerTest.java new file mode 100644 index 000000000..1c7646b9c --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/manager/GuiManagerTest.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.core.test.manager; + +import com.clubobsidian.dynamicgui.core.gui.Gui; +import com.clubobsidian.dynamicgui.core.manager.dynamicgui.GuiManager; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class GuiManagerTest extends FactoryTest { + + private static final String TEST_GUI = "test"; + + @Test + public void testGetGuiNotNull() { + Gui gui = GuiManager.get().getGui(TEST_GUI); + assertNotNull(gui); + } + + @Test + public void testHasGui() { + assertTrue(GuiManager.get().isGuiLoaded(TEST_GUI)); + } + + @Test + public void testGetGuis() { + List guis = GuiManager.get().getGuis(); + assertNotNull(guis); + assertTrue(guis.size() > 1); + } +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/MockFactory.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/MockFactory.java new file mode 100644 index 000000000..c11882f49 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/MockFactory.java @@ -0,0 +1,223 @@ +/* + * 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.test.mock; + +import cloud.commandframework.CommandManager; +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.enchantment.EnchantmentWrapper; +import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper; +import com.clubobsidian.dynamicgui.core.gui.Gui; +import com.clubobsidian.dynamicgui.core.gui.InventoryType; +import com.clubobsidian.dynamicgui.core.gui.ModeEnum; +import com.clubobsidian.dynamicgui.core.gui.Slot; +import com.clubobsidian.dynamicgui.core.logger.LoggerWrapper; +import com.clubobsidian.dynamicgui.core.platform.Platform; +import com.clubobsidian.dynamicgui.core.plugin.DynamicGuiPlugin; +import com.clubobsidian.dynamicgui.core.test.mock.command.MockCommandManager; +import com.clubobsidian.dynamicgui.core.test.mock.entity.player.MockPlayer; +import com.clubobsidian.dynamicgui.core.test.mock.entity.player.MockPlayerWrapper; +import com.clubobsidian.dynamicgui.core.test.mock.inject.MockPluginModule; +import com.clubobsidian.dynamicgui.core.test.mock.inventory.MockItemStack; +import com.clubobsidian.dynamicgui.core.test.mock.inventory.MockItemStackWrapper; +import com.clubobsidian.dynamicgui.core.test.mock.logger.MockLogger; +import com.clubobsidian.dynamicgui.core.test.mock.logger.MockLoggerWrapper; +import com.clubobsidian.dynamicgui.core.test.mock.plugin.MockDynamicGuiPlugin; +import com.clubobsidian.dynamicgui.core.test.mock.plugin.MockEconomy; +import com.clubobsidian.dynamicgui.core.test.mock.plugin.MockPlatform; +import com.clubobsidian.dynamicgui.core.test.mock.world.MockLocation; +import com.clubobsidian.dynamicgui.core.test.mock.world.MockLocationWrapper; +import com.clubobsidian.dynamicgui.core.test.mock.world.MockWorld; +import com.clubobsidian.dynamicgui.core.test.mock.world.MockWorldWrapper; +import com.clubobsidian.dynamicgui.parser.function.tree.FunctionTree; +import org.mockito.Mockito; + +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.UUID; + +public class MockFactory { + + public T mock(Class mockClazz) { + return Mockito.mock(mockClazz, Mockito.withSettings() + .useConstructor() + .defaultAnswer(Mockito.CALLS_REAL_METHODS)); + } + + public T mock(Class mockClazz, Object... args) { + return Mockito.mock(mockClazz, Mockito.withSettings().useConstructor(args) + .defaultAnswer(Mockito.CALLS_REAL_METHODS)); + } + + public MockPlayerWrapper createPlayer() { + return this.mock(MockPlayerWrapper.class); + } + + public MockPlayerWrapper createPlayer(String name, UUID uuid) { + MockPlayer player = this.mock(MockPlayer.class, name, uuid); + return this.mock(MockPlayerWrapper.class, player); + } + + public MockItemStackWrapper createItemStack(String type) { + MockItemStack itemStack = this.mock(MockItemStack.class, type); + return this.createItemStack(itemStack); + } + + public MockItemStackWrapper createItemStack(MockItemStack itemStack) { + return this.mock(MockItemStackWrapper.class, itemStack); + } + + public Gui createGui(String title) { + return this.createGui(title, new ArrayList<>()); + } + + public Gui createGui(String title, List slots) { + return new Gui(title, + InventoryType.CHEST.toString(), + title, + 6, + true, + ModeEnum.SET, + new HashMap<>(), + slots, + new ArrayList<>(), + new FunctionTree(), + new HashMap<>(), + false); + } + + public Slot createSlot(PlayerWrapper player) { + return this.createSlot(player, new ArrayList<>()); + } + + public Slot createSlot(PlayerWrapper player, List lore) { + Slot slot = this.inject().createSlot(0, + Slot.TEST_MATERIAL, + lore, + new ArrayList<>(), + false); + slot.buildItemStack(player); + List slots = new ArrayList<>(); + slots.add(slot); + Gui gui = this.createGui("test", slots); + gui.buildInventory(player); + slot.setOwner(gui); + return slot; + } + + public Slot createSlot() { + return this.createSlot(Slot.TEST_MATERIAL); + } + + public Slot createSlot(String type) { + return this.createSlot(type, false); + } + + public Slot createSlot(String type, boolean movable) { + return this.createSlot(0, type, movable); + } + + public Slot createSlot(int index, String type, boolean movable) { + return this.createSlot(index, type, new ArrayList<>(), movable); + } + + public Slot createSlot(int index, String type, List enchants, boolean movable) { + return this.createSlot(index, type, new ArrayList<>(), enchants, movable); + } + + public Slot createSlot(int index, String type, List lore, List enchants, boolean movable) { + return new Slot(index, + 1, + type, + "test", + null, + (short) 0, + false, + movable, + false, + lore, + enchants, + new ArrayList<>(), + null, + null, + new FunctionTree(), + 0, + new HashMap<>()); + } + + public MockWorldWrapper createWorld(String worldName) { + MockWorld mockWorld = new MockWorld(worldName); + return new MockWorldWrapper(mockWorld); + } + + public MockLocationWrapper createLocation(int x, int y, int z, String worldName) { + MockWorldWrapper worldWrapper = this.createWorld(worldName); + MockLocation mockLocation = new MockLocation(x, y, z, worldWrapper); + return new MockLocationWrapper(mockLocation); + } + + public MockFactory inject() { + DynamicGuiPlugin plugin = new MockDynamicGuiPlugin(); + File cooldownsFile = new File(plugin.getDataFolder(), "cooldowns.yml"); + if (cooldownsFile.exists()) { //Have to do manual cleanup of this or tests fail + cooldownsFile.delete(); + } + Platform platform = new MockPlatform(); + LoggerWrapper logger = new MockLoggerWrapper(new MockLogger()); + CommandManager commandManager = new MockCommandManager(); + MockPluginModule module = new MockPluginModule(plugin, platform, logger, commandManager); + module.bootstrap(); + DynamicGui.get(); //Initializes dynamic gui + this.getLogger().getLogger().clear(); //Clear logs for initialization + return this; + } + + public MockPlatform getPlatform() { + Platform platform = DynamicGui.get().getPlatform(); + if (!(platform instanceof MockPlatform)) { + return null; + } + return (MockPlatform) platform; + } + + public MockLoggerWrapper getLogger() { + LoggerWrapper logger = DynamicGui.get().getLogger(); + if (!(logger instanceof MockLoggerWrapper)) { + return null; + } + return (MockLoggerWrapper) logger; + } + + public MockEconomy getEconomy() { + Economy economy = DynamicGui.get().getPlugin().getEconomy(); + if (!(economy instanceof MockEconomy)) { + return null; + } + return (MockEconomy) economy; + } + + public MockDynamicGuiPlugin getPlugin() { + DynamicGuiPlugin plugin = DynamicGui.get().getPlugin(); + if (!(plugin instanceof MockDynamicGuiPlugin)) { + return null; + } + return (MockDynamicGuiPlugin) plugin; + } +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/command/MockCloudExtender.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/command/MockCloudExtender.java new file mode 100644 index 000000000..85ebef86c --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/command/MockCloudExtender.java @@ -0,0 +1,28 @@ +/* + * 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.test.mock.command; + +import cloud.commandframework.Command; +import cloud.commandframework.CommandManager; +import com.clubobsidian.dynamicgui.core.command.cloud.CloudExtender; + +public class MockCloudExtender implements CloudExtender { + @Override + public boolean unregister(CommandManager commandManager, Command command, String commandName) { + return false; //TODO - implement + } +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/command/MockCommandManager.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/command/MockCommandManager.java new file mode 100644 index 000000000..c040e98a9 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/command/MockCommandManager.java @@ -0,0 +1,63 @@ +/* + * 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.test.mock.command; + +import cloud.commandframework.CommandManager; +import cloud.commandframework.CommandTree; +import cloud.commandframework.execution.AsynchronousCommandExecutionCoordinator; +import cloud.commandframework.execution.CommandExecutionCoordinator; +import cloud.commandframework.internal.CommandRegistrationHandler; +import cloud.commandframework.meta.CommandMeta; +import org.checkerframework.checker.nullness.qual.NonNull; + +import java.util.function.Function; + +public class MockCommandManager extends CommandManager { + + public MockCommandManager() { + this(CommandExecutionCoordinator.simpleCoordinator(), + CommandRegistrationHandler.nullCommandRegistrationHandler()); + } + + /** + * Create a new command manager instance + * + * @param commandExecutionCoordinator Execution coordinator instance. The coordinator is in charge of executing incoming + * commands. Some considerations must be made when picking a suitable execution coordinator + * for your platform. For example, an entirely asynchronous coordinator is not suitable + * when the parsers used in that particular platform are not thread safe. If you have + * commands that perform blocking operations, however, it might not be a good idea to + * use a synchronous execution coordinator. In most cases you will want to pick between + * {@link CommandExecutionCoordinator#simpleCoordinator()} and + * {@link AsynchronousCommandExecutionCoordinator} + * @param commandRegistrationHandler Command registration handler. This will get called every time a new command is + * registered to the command manager. This may be used to forward command registration + */ + protected MockCommandManager(@NonNull Function<@NonNull CommandTree, @NonNull CommandExecutionCoordinator> commandExecutionCoordinator, @NonNull CommandRegistrationHandler commandRegistrationHandler) { + super(commandExecutionCoordinator, commandRegistrationHandler); + } + + @Override + public boolean hasPermission(@NonNull C sender, @NonNull String permission) { + return false; + } + + @Override + public @NonNull CommandMeta createDefaultCommandMeta() { + return null; + } +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/entity/package-info.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/entity/package-info.java new file mode 100644 index 000000000..b9143b901 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/entity/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.core.test.mock.entity; diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/entity/player/MockPlayer.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/entity/player/MockPlayer.java new file mode 100644 index 000000000..def2afd67 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/entity/player/MockPlayer.java @@ -0,0 +1,136 @@ +/* + * 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.test.mock.entity.player; + +import com.clubobsidian.dynamicgui.core.effect.ParticleWrapper; +import com.clubobsidian.dynamicgui.core.effect.SoundWrapper; +import com.clubobsidian.dynamicgui.core.inventory.ItemStackWrapper; +import com.clubobsidian.dynamicgui.core.world.LocationWrapper; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.UUID; + +public class MockPlayer { + + private final String name; + private final UUID uuid; + private final List incomingChat = new ArrayList<>(); + private final List outgoingChat = new ArrayList<>(); + private final Collection permissions = new HashSet<>(); + private ItemStackWrapper hand; + private int level = 0; + private LocationWrapper location; + private final List particles = new ArrayList<>(); + private final List sounds = new ArrayList<>(); + private boolean online = true; + + public MockPlayer(String name, UUID uuid) { + this.name = name; + this.uuid = uuid; + } + + public MockPlayer() { + this("test", UUID.randomUUID()); + } + + public String getName() { + return this.name; + } + + public UUID getUniqueId() { + return this.uuid; + } + + public void chat(String message) { + this.outgoingChat.add(message); + } + + public void sendMessage(String message) { + this.incomingChat.add(message); + } + + public List getIncomingChat() { + return this.incomingChat; + } + + public List getOutgoingChat() { + return this.outgoingChat; + } + + public boolean hasPermission(String permission) { + return this.permissions.contains(permission); + } + + public boolean addPermission(String permission) { + return this.permissions.add(permission); + } + + public boolean removePermission(String permission) { + return this.permissions.remove(permission); + } + + public ItemStackWrapper getItemInHand() { + return this.hand; + } + + public void setItemInHand(ItemStackWrapper hand) { + this.hand = hand; + } + + public int getLevel() { + return this.level; + } + + public void setLevel(int level) { + this.level = level; + } + + public LocationWrapper getLocation() { + return this.location; + } + + public void setLocation(LocationWrapper location) { + this.location = location; + } + + public void playEffect(ParticleWrapper.ParticleData particleData) { + this.particles.add(particleData); + } + + public List getParticles() { + return this.particles; + } + + public void playSound(SoundWrapper.SoundData soundData) { + this.sounds.add(soundData); + } + + public List getSounds() { + return this.sounds; + } + + public boolean isOnline() { + return this.online; + } + + public void setOnline(boolean online) { + this.online = online; + } +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/entity/player/MockPlayerWrapper.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/entity/player/MockPlayerWrapper.java new file mode 100644 index 000000000..91ee5440c --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/entity/player/MockPlayerWrapper.java @@ -0,0 +1,141 @@ +/* + * 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.test.mock.entity.player; + +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.ItemStackWrapper; +import com.clubobsidian.dynamicgui.core.world.LocationWrapper; + +import java.util.List; +import java.util.UUID; + +public abstract class MockPlayerWrapper extends PlayerWrapper { + + private ItemStackWrapper hand; + + public MockPlayerWrapper() { + this(new MockPlayer()); + } + + public MockPlayerWrapper(MockPlayer player) { + super(player); + } + + @Override + public String getName() { + return this.getPlayer().getName(); + } + + @Override + public UUID getUniqueId() { + return this.getPlayer().getUniqueId(); + } + + @Override + public void chat(String message) { + this.getPlayer().chat(message); + } + + public List getOutgoingChat() { + return this.getPlayer().getOutgoingChat(); + } + + public List getIncomingChat() { + return this.getPlayer().getIncomingChat(); + } + + @Override + public void sendMessage(String message) { + this.getPlayer().sendMessage(message); + } + + @Override + public void sendJsonMessage(String message) { + this.sendMessage(message); + } + + @Override + public boolean hasPermission(String permission) { + return this.getPlayer().hasPermission(permission); + } + + @Override + public boolean addPermission(String permission) { + return this.getPlayer().addPermission(permission); + } + + @Override + public boolean removePermission(String permission) { + return this.getPlayer().removePermission(permission); + } + + @Override + public ItemStackWrapper getItemInHand() { + return this.getPlayer().getItemInHand(); + } + + public void setItemInHand(ItemStackWrapper hand) { + this.getPlayer().setItemInHand(hand); + } + + @Override + public int getLevel() { + return this.getPlayer().getLevel(); + } + + public void setLevel(int level) { + this.getPlayer().setLevel(level); + } + + @Override + public LocationWrapper getLocation() { + return this.getPlayer().getLocation(); + } + + public void setLocation(LocationWrapper location) { + this.getPlayer().setLocation(location); + } + + @Override + public void playEffect(ParticleWrapper.ParticleData particleData) { + this.getPlayer().playEffect(particleData); + } + + public List getParticles() { + return this.getPlayer().getParticles(); + } + + @Override + public void playSound(SoundWrapper.SoundData soundData) { + this.getPlayer().playSound(soundData); + } + + public List getSounds() { + return this.getPlayer().getSounds(); + } + + @Override + public boolean isOnline() { + return this.getPlayer().isOnline(); + } + + public void setOnline(boolean online) { + this.getPlayer().setOnline(online); + } +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/gui/MockCloseableFunctionOwner.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/gui/MockCloseableFunctionOwner.java new file mode 100644 index 000000000..eb3a996b8 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/gui/MockCloseableFunctionOwner.java @@ -0,0 +1,41 @@ +/* + * 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.test.mock.gui; + +import com.clubobsidian.dynamicgui.core.gui.FunctionOwner; +import com.clubobsidian.dynamicgui.core.gui.property.CloseableComponent; +import com.clubobsidian.dynamicgui.parser.function.tree.FunctionTree; + +public class MockCloseableFunctionOwner implements FunctionOwner, CloseableComponent { + + private Boolean close; + + @Override + public FunctionTree getFunctions() { + return null; + } + + @Override + public Boolean getClose() { + return this.close; + } + + @Override + public void setClose(Boolean close) { + this.close = close; + } +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/gui/MockNonCloseableFunctionOwner.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/gui/MockNonCloseableFunctionOwner.java new file mode 100644 index 000000000..ad23f14cb --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/gui/MockNonCloseableFunctionOwner.java @@ -0,0 +1,28 @@ +/* + * 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.test.mock.gui; + +import com.clubobsidian.dynamicgui.core.gui.FunctionOwner; +import com.clubobsidian.dynamicgui.parser.function.tree.FunctionTree; + +public class MockNonCloseableFunctionOwner implements FunctionOwner { + + @Override + public FunctionTree getFunctions() { + return null; + } +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/inject/MockPluginModule.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/inject/MockPluginModule.java new file mode 100644 index 000000000..5e0047612 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/inject/MockPluginModule.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.core.test.mock.inject; + +import cloud.commandframework.CommandManager; +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; +import com.clubobsidian.dynamicgui.core.test.mock.command.MockCloudExtender; +import com.clubobsidian.dynamicgui.core.test.mock.manager.MockEntityManager; +import com.clubobsidian.dynamicgui.core.test.mock.manager.MockInventoryManager; +import com.clubobsidian.dynamicgui.core.test.mock.manager.MockItemStackManager; +import com.clubobsidian.dynamicgui.core.test.mock.manager.MockLocationManager; +import com.clubobsidian.dynamicgui.core.test.mock.manager.MockMaterialManager; + +public class MockPluginModule extends PluginModule { + + public MockPluginModule(DynamicGuiPlugin plugin, + Platform platform, + LoggerWrapper logger, + CommandManager commandManager) { + super(plugin, platform, logger, commandManager); + } + + @Override + public Class getEntityManager() { + return MockEntityManager.class; + } + + @Override + public Class getInventoryManager() { + return MockInventoryManager.class; + } + + @Override + public Class getItemStackManager() { + return MockItemStackManager.class; + } + + @Override + public Class getMaterialManager() { + return MockMaterialManager.class; + } + + @Override + public Class getLocationManger() { + return MockLocationManager.class; + } + + @Override + public Class getPlatformExtender() { + return MockCloudExtender.class; + } +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/inventory/MockInventory.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/inventory/MockInventory.java new file mode 100644 index 000000000..7ecb8c3f0 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/inventory/MockInventory.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.test.mock.inventory; + +import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper; +import com.clubobsidian.dynamicgui.core.gui.Slot; +import com.clubobsidian.dynamicgui.core.inventory.ItemStackWrapper; +import com.clubobsidian.dynamicgui.core.test.mock.MockFactory; + +import java.util.HashMap; +import java.util.Map; + +public class MockInventory { + + private final MockFactory factory = new MockFactory(); + private final int size; + private final Map contents = new HashMap<>(); + + public MockInventory(int size) { + this.size = size; + } + + public ItemStackWrapper[] getContents() { + ItemStackWrapper[] ar = new ItemStackWrapper[this.size]; + for (int i = 0; i < this.size; i++) { + ar[i] = this.getItem(i); + } + return ar; + } + + public ItemStackWrapper getItem(int index) { + return this.contents.get(index) == null ? + this.factory.createItemStack(Slot.IGNORE_MATERIAL) + : this.factory.createItemStack(this.contents.get(index)); + } + + public void setItem(int index, ItemStackWrapper itemStack) { + this.contents.put(index, (MockItemStack) itemStack.getItemStack()); + } + + public void updateItem(int index, PlayerWrapper player) { + //do nothing + } + + public int getSize() { + return this.size; + } + + public int getCurrentContentSize() { + return this.contents.size(); + } +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/inventory/MockInventoryWrapper.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/inventory/MockInventoryWrapper.java new file mode 100644 index 000000000..bdcf23b14 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/inventory/MockInventoryWrapper.java @@ -0,0 +1,58 @@ +/* + * 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.test.mock.inventory; + +import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper; +import com.clubobsidian.dynamicgui.core.inventory.InventoryWrapper; +import com.clubobsidian.dynamicgui.core.inventory.ItemStackWrapper; + +public class MockInventoryWrapper extends InventoryWrapper { + + public MockInventoryWrapper(MockInventory inventory) { + super(inventory); + } + + @Override + public ItemStackWrapper[] getContents() { + return this.getInventory().getContents(); + } + + @Override + public ItemStackWrapper getItem(int index) { + return this.getInventory().getItem(index); + } + + @Override + public void setItem(int index, ItemStackWrapper itemStack) { + this.getInventory().setItem(index, itemStack); + } + + @Override + public void updateItem(int index, PlayerWrapper player) { + this.getInventory().updateItem(index, player); + } + + @Override + public int getSize() { + return this.getInventory().getSize(); + } + + @Override + public int getCurrentContentSize() { + return this.getInventory().getCurrentContentSize(); + } +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/inventory/MockItemStack.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/inventory/MockItemStack.java new file mode 100644 index 000000000..c42e2f2f9 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/inventory/MockItemStack.java @@ -0,0 +1,106 @@ +/* + * 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.test.mock.inventory; + +import com.clubobsidian.dynamicgui.core.enchantment.EnchantmentWrapper; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +public class MockItemStack { + + private final String type; + private int amount; + private short durability = 0; + private final Map enchants = new LinkedHashMap<>(); + private boolean glowing = false; + private List lore = new ArrayList<>(); + private String name; + private String nbt; + + public MockItemStack(String type) { + this(type, 1); + } + + public MockItemStack(String type, int quantity) { + this.type = type; + this.amount = quantity; + } + + public String getType() { + return this.type; + } + + public int getAmount() { + return this.amount; + } + + public void setAmount(int amount) { + this.amount = amount; + } + + public short getDurability() { + return this.durability; + } + + public void setDurability(short durability) { + this.durability = durability; + } + + public List getEnchants() { + return new ArrayList<>(this.enchants.values()); + } + + public void addEnchant(EnchantmentWrapper enchant) { + this.enchants.put(enchant.getEnchant(), enchant); + } + + public void removeEnchant(EnchantmentWrapper enchant) { + this.enchants.remove(enchant.getEnchant()); + } + + public void setGlowing(boolean glowing) { + this.glowing = glowing; + } + + public List getLore() { + return this.lore; + } + + public void setLore(List lore) { + List l = lore == null ? new ArrayList<>() : lore; + this.lore = l; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return this.name; + } + + public String getNBT() { + return this.nbt; + } + + public void setNBT(String nbt) { + this.nbt = nbt; + } +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/inventory/MockItemStackWrapper.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/inventory/MockItemStackWrapper.java new file mode 100644 index 000000000..eb2e1b240 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/inventory/MockItemStackWrapper.java @@ -0,0 +1,104 @@ +/* + * 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.test.mock.inventory; + +import com.clubobsidian.dynamicgui.core.enchantment.EnchantmentWrapper; +import com.clubobsidian.dynamicgui.core.inventory.ItemStackWrapper; + +import java.util.List; + +public abstract class MockItemStackWrapper extends ItemStackWrapper { + + public MockItemStackWrapper(MockItemStack itemStack) { + super(itemStack); + } + + @Override + public String getType() { + return this.getItemStack().getType(); + } + + @Override + public List getLore() { + return this.getItemStack().getLore(); + } + + @Override + public void setLore(List lore) { + this.getItemStack().setLore(lore); + } + + @Override + public int getAmount() { + return this.getItemStack().getAmount(); + } + + @Override + public void setAmount(int amount) { + this.getItemStack().setAmount(amount); + } + + @Override + public short getDurability() { + return this.getItemStack().getDurability(); + } + + @Override + public void setDurability(short durability) { + this.getItemStack().setDurability(durability); + } + + @Override + public List getEnchants() { + return this.getItemStack().getEnchants(); + } + + @Override + public void addEnchant(EnchantmentWrapper enchant) { + this.getItemStack().addEnchant(enchant); + } + + @Override + public void removeEnchant(EnchantmentWrapper enchant) { + this.getItemStack().removeEnchant(enchant); + } + + @Override + public void setGlowing(boolean glowing) { + this.getItemStack().setGlowing(glowing); + } + + @Override + public void setName(String name) { + this.getItemStack().setName(name); + } + + @Override + public String getName() { + return this.getItemStack().getName(); + } + + @Override + public String getNBT() { + return this.getItemStack().getNBT(); + } + + @Override + public void setNBT(String nbt) { + this.getItemStack().setNBT(nbt); + } +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/logger/MockLogger.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/logger/MockLogger.java new file mode 100644 index 000000000..d0c63bba2 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/logger/MockLogger.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.test.mock.logger; + +import java.util.ArrayList; +import java.util.List; + +public class MockLogger { + + private final List infoMessages = new ArrayList<>(); + private final List errorMessages = new ArrayList<>(); + + public void info(String message) { + this.infoMessages.add(message); + } + + public void error(String message) { + this.errorMessages.add(message); + } + + public List getInfoMessages() { + return this.infoMessages; + } + + public List getErrorMessages() { + return this.errorMessages; + } + + public void clear() { + this.infoMessages.clear(); + this.errorMessages.clear(); + } +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/logger/MockLoggerWrapper.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/logger/MockLoggerWrapper.java new file mode 100644 index 000000000..63df4757b --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/logger/MockLoggerWrapper.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.test.mock.logger; + +import com.clubobsidian.dynamicgui.core.logger.LoggerWrapper; + +public class MockLoggerWrapper extends LoggerWrapper { + + public MockLoggerWrapper(MockLogger logger) { + super(logger); + } + + @Override + public void info(String message) { + this.getLogger().info(message); + } + + @Override + public void error(String message) { + this.getLogger().error(message); + } +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/manager/MockEntityManager.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/manager/MockEntityManager.java new file mode 100644 index 000000000..022e97b2f --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/manager/MockEntityManager.java @@ -0,0 +1,34 @@ +/* + * 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.test.mock.manager; + +import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper; +import com.clubobsidian.dynamicgui.core.manager.entity.EntityManager; + +import java.util.List; + +public class MockEntityManager extends EntityManager { + @Override + public PlayerWrapper createPlayerWrapper(Object player) { + return null; + } + + @Override + public List getEntityTypes() { + return null; + } +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/manager/MockInventoryManager.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/manager/MockInventoryManager.java new file mode 100644 index 000000000..fad2293b1 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/manager/MockInventoryManager.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.test.mock.manager; + +import com.clubobsidian.dynamicgui.core.inventory.InventoryWrapper; +import com.clubobsidian.dynamicgui.core.manager.inventory.InventoryManager; +import com.clubobsidian.dynamicgui.core.test.mock.inventory.MockInventory; +import com.clubobsidian.dynamicgui.core.test.mock.inventory.MockInventoryWrapper; + +public class MockInventoryManager extends InventoryManager { + @Override + public Object createInventory(int size, String title) { + return new MockInventory(size); + } + + @Override + public Object createInventory(String title, String type) { + return new MockInventory(9); //TODO - Do inventory size based on type + } + + @Override + public InventoryWrapper createInventoryWrapper(Object inventory) { + return new MockInventoryWrapper((MockInventory) inventory); + } +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/manager/MockItemStackManager.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/manager/MockItemStackManager.java new file mode 100644 index 000000000..55b23c582 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/manager/MockItemStackManager.java @@ -0,0 +1,37 @@ +/* + * 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.test.mock.manager; + +import com.clubobsidian.dynamicgui.core.inventory.ItemStackWrapper; +import com.clubobsidian.dynamicgui.core.manager.inventory.ItemStackManager; +import com.clubobsidian.dynamicgui.core.test.mock.MockFactory; +import com.clubobsidian.dynamicgui.core.test.mock.inventory.MockItemStack; + +public class MockItemStackManager extends ItemStackManager { + + private final MockFactory factory = new MockFactory(); + + @Override + public Object createItemStack(String type, int quantity) { + return new MockItemStack(type, quantity); + } + + @Override + public ItemStackWrapper createItemStackWrapper(Object itemStack) { + return this.factory.createItemStack((MockItemStack) itemStack); + } +} diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/listener/InventoryOpenListener.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/manager/MockLocationManager.java similarity index 52% rename from core/src/main/java/com/clubobsidian/dynamicgui/listener/InventoryOpenListener.java rename to core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/manager/MockLocationManager.java index b93062484..aee872a11 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/listener/InventoryOpenListener.java +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/manager/MockLocationManager.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,21 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.clubobsidian.dynamicgui.listener; -import com.clubobsidian.dynamicgui.event.inventory.InventoryOpenEvent; -import com.clubobsidian.trident.EventHandler; +package com.clubobsidian.dynamicgui.core.test.mock.manager; -public class InventoryOpenListener { +import com.clubobsidian.dynamicgui.core.manager.world.LocationManager; +import com.clubobsidian.dynamicgui.core.world.LocationWrapper; - @EventHandler - public void inventoryOpen(final InventoryOpenEvent e) { - /*if(GuiManager.get().hasGuiCurrently(e.getPlayerWrapper())) - { - if(e.getPlayerWrapper().getOpenInventoryWrapper().getInventory() != null) - { - e.getPlayerWrapper().closeInventory(); - } - }*/ +public class MockLocationManager extends LocationManager { + @Override + public LocationWrapper toLocationWrapper(String world, int x, int y, int z) { + return null; } -} \ No newline at end of file + + @Override + public LocationWrapper toLocationWrapper(Object obj) { + return null; + } +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/manager/MockMaterialManager.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/manager/MockMaterialManager.java new file mode 100644 index 000000000..1136e486f --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/manager/MockMaterialManager.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.test.mock.manager; + +import com.clubobsidian.dynamicgui.core.manager.material.MaterialManager; + +import java.util.List; + +public class MockMaterialManager extends MaterialManager { + @Override + public List getMaterials() { + return null; + } + + @Override + public String normalizeMaterial(String material) { + if (material == null) { + return null; + } + return material.toUpperCase(); + } +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/plugin/MockDynamicGuiPlugin.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/plugin/MockDynamicGuiPlugin.java new file mode 100644 index 000000000..40e1ed276 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/plugin/MockDynamicGuiPlugin.java @@ -0,0 +1,85 @@ +/* + * 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.test.mock.plugin; + +import cloud.commandframework.CommandManager; +import com.clubobsidian.dynamicgui.core.command.GuiCommandSender; +import com.clubobsidian.dynamicgui.core.economy.Economy; +import com.clubobsidian.dynamicgui.core.permission.Permission; +import com.clubobsidian.dynamicgui.core.plugin.DynamicGuiPlugin; +import com.clubobsidian.dynamicgui.core.registry.npc.NPCRegistry; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +public class MockDynamicGuiPlugin implements DynamicGuiPlugin { + + private final File dataFolder = new File("mock_data"); + private final File guiFolder = new File(this.dataFolder, "guis"); + private final File macroFolder = new File(this.dataFolder, "macros"); + private final File mainFolder = new File("src", "main"); + private final File resourcesFolder = new File(this.mainFolder, "resources"); + private final File configFile = new File(this.resourcesFolder, "config.yml"); + public Economy economy = new MockEconomy(); //Visible for testing + public Permission permission = new MockPermission(); //Visible for testing + + @Override + public void start() { + + } + + @Override + public void stop() { + + } + + @Override + public Economy getEconomy() { + return this.economy; + } + + @Override + public Permission getPermission() { + return this.permission; + } + + @Override + public List getNPCRegistries() { + return new ArrayList<>(); //TODO - implement + } + + @Override + public File getDataFolder() { + return this.dataFolder; + } + + @Override + public File getConfigFile() { + return this.configFile; + } + + @Override + public File getGuiFolder() { + return this.guiFolder; + } + + @Override + public File getMacroFolder() { + return this.macroFolder; + } +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/plugin/MockEconomy.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/plugin/MockEconomy.java new file mode 100644 index 000000000..1d7d57044 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/plugin/MockEconomy.java @@ -0,0 +1,62 @@ +/* + * 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.test.mock.plugin; + +import com.clubobsidian.dynamicgui.core.economy.Economy; +import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper; + +import java.math.BigDecimal; +import java.util.HashMap; +import java.util.Map; + +public class MockEconomy implements Economy { + + private final Map, BigDecimal> balances = new HashMap<>(); + + @Override + public boolean setup() { + return true; + } + + @Override + public BigDecimal getBalance(PlayerWrapper playerWrapper) { + return this.balances.getOrDefault(playerWrapper, new BigDecimal(0)); + } + + @Override + public boolean withdraw(PlayerWrapper playerWrapper, BigDecimal amt) { + BigDecimal balance = this.getBalance(playerWrapper); + if (balance.intValue() >= amt.intValue()) { + balance = balance.subtract(amt); + this.balances.put(playerWrapper, balance); + return true; + } + return false; + } + + @Override + public boolean deposit(PlayerWrapper playerWrapper, BigDecimal amt) { + BigDecimal balance = this.getBalance(playerWrapper); + balance = balance.add(amt); + this.balances.put(playerWrapper, balance); + return true; + } + + public Map, BigDecimal> getBalances() { + return this.balances; + } +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/plugin/MockPermission.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/plugin/MockPermission.java new file mode 100644 index 000000000..e6c8690ce --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/plugin/MockPermission.java @@ -0,0 +1,43 @@ +/* + * 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.test.mock.plugin; + +import com.clubobsidian.dynamicgui.core.entity.PlayerWrapper; +import com.clubobsidian.dynamicgui.core.permission.Permission; + +public class MockPermission implements Permission { + + @Override + public boolean setup() { + return true; + } + + @Override + public boolean hasPermission(PlayerWrapper playerWrapper, String permission) { + return playerWrapper.hasPermission(permission); + } + + @Override + public boolean addPermission(PlayerWrapper playerWrapper, String permission) { + return playerWrapper.addPermission(permission); + } + + @Override + public boolean removePermission(PlayerWrapper playerWrapper, String permission) { + return playerWrapper.removePermission(permission); + } +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/plugin/MockPlatform.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/plugin/MockPlatform.java new file mode 100644 index 000000000..fba069774 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/plugin/MockPlatform.java @@ -0,0 +1,129 @@ +/* + * 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.test.mock.plugin; + +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.scheduler.Scheduler; +import com.clubobsidian.dynamicgui.core.test.mock.scheduler.MockScheduler; +import com.clubobsidian.dynamicgui.core.world.WorldWrapper; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +public class MockPlatform implements Platform { + + private final Map> worlds = new HashMap<>(); + private final List dispatchedServerCommands = new ArrayList<>(); + private final MockScheduler scheduler = new MockScheduler(); + private final List broadcastMessages = new ArrayList<>(); + private final List> players = new ArrayList<>(); + + @Override + public Scheduler getScheduler() { + return this.scheduler; + } + + @Override + public boolean isMainThread() { + return this.scheduler.isOnMainThread(); + } + + @Override + public void broadcastMessage(String message) { + this.broadcastMessages.add(message); + } + + public List getBroadcastMessages() { + return this.broadcastMessages; + } + + @Override + public void broadcastJsonMessage(String json) { + this.broadcastMessages.add(json); + } + + @Override + public void dispatchServerCommand(String command) { + this.dispatchedServerCommands.add(command); + } + + public List getDispatchedServerCommands() { + return this.dispatchedServerCommands; + } + + @Override + public PlayerWrapper getPlayer(UUID uuid) { + for (PlayerWrapper player : this.players) { + if(player.getUniqueId().equals(uuid)) { + return player; + } + } + return null; + } + + @Override + public PlayerWrapper getPlayer(String name) { + for (PlayerWrapper player : this.players) { + if(player.getName().equals(name)) { + return player; + } + } + return null; + } + + @Override + public Collection> getOnlinePlayers() { + return this.players; + } + + @Override + public int getGlobalPlayerCount() { + return 0; + } + + @Override + public PlatformType getType() { + return null; + } + + @Override + public void registerOutgoingPluginChannel(DynamicGuiPlugin plugin, String channel) { + + } + + @Override + public void registerIncomingPluginChannel(DynamicGuiPlugin plugin, String channel, MessagingRunnable runnable) { + + } + + @Override + public WorldWrapper getWorld(String worldName) { + return this.worlds.get(worldName); + } + + public void addWorld(WorldWrapper world) { + this.worlds.put(world.getName(), world); + } +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/scheduler/MockScheduler.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/scheduler/MockScheduler.java new file mode 100644 index 000000000..d6e5b5191 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/scheduler/MockScheduler.java @@ -0,0 +1,62 @@ +/* + * 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.test.mock.scheduler; + +import com.clubobsidian.dynamicgui.core.scheduler.Scheduler; + +public class MockScheduler extends Scheduler { + + private final MockThreadRunnable synchronous = new MockThreadRunnable(); + private final MockThreadRunnable async = new MockThreadRunnable(); + + private final Thread mainThread = new Thread(this.synchronous); + private final Thread asyncThread = new Thread(this.async); + + public MockScheduler() { + this.mainThread.start(); + this.asyncThread.start(); + } + + @Override + public void runSyncDelayedTask(Runnable runnable, long delay) { + this.synchronous.addTask(new MockTask(runnable, delay)); + } + + @Override + public void runAsynchronousDelayedTask(Runnable runnable, long delay) { + this.async.addTask(new MockTask(runnable, delay)); + } + + @Override + public void scheduleSyncRepeatingTask(Runnable runnable, long delayInitial, long delayRepeating) { + this.synchronous.addTask(new MockTask(runnable, delayInitial, delayRepeating)); + } + + @Override + public void scheduleAsyncRepeatingTask(Runnable runnable, long delayInitial, long delayRepeating) { + this.async.addTask(new MockTask(runnable, delayInitial, delayRepeating)); + } + + public boolean isOnMainThread() { + return Thread.currentThread().equals(this.mainThread); + } + + public void stop() { + this.synchronous.stop(); + this.async.stop(); + } +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/scheduler/MockTask.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/scheduler/MockTask.java new file mode 100644 index 000000000..49fe47b24 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/scheduler/MockTask.java @@ -0,0 +1,55 @@ +/* + * 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.test.mock.scheduler; + +public class MockTask implements Runnable { + + private final Runnable runnable; + private final long delayInitial; + private long delay; + private final long delayRepeating; + + public MockTask(Runnable runnable, long delayInitial) { + this(runnable, delayInitial, -1); + } + + public MockTask(Runnable runnable, long delayInitial, long delayRepeating) { + this.runnable = runnable; + this.delayInitial = delayInitial; + this.delay = delayInitial; + this.delayRepeating = delayRepeating; + } + + public long decrementDelay() { + this.delay -= 1; + return this.delay; + } + + public long resetDelay() { + this.delay = this.delayRepeating; + return this.delay; + } + + public boolean isRepeating() { + return this.delayRepeating != -1; + } + + @Override + public void run() { + this.runnable.run(); + } +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/scheduler/MockThreadRunnable.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/scheduler/MockThreadRunnable.java new file mode 100644 index 000000000..387cfb9c5 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/scheduler/MockThreadRunnable.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.test.mock.scheduler; + +import java.util.Collection; +import java.util.Iterator; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.atomic.AtomicBoolean; + +public class MockThreadRunnable implements Runnable { + + private final AtomicBoolean running = new AtomicBoolean(true); + private final Collection tasks = new ConcurrentLinkedQueue<>(); + + public boolean addTask(MockTask task) { + return this.tasks.add(task); + } + + @Override + public void run() { + while (this.running.get()) { + try { + Thread.sleep(50); + Iterator it = this.tasks.iterator(); + while (it.hasNext()) { + MockTask task = it.next(); + if (task.decrementDelay() <= 0) { + task.run(); + if (task.isRepeating()) { + task.resetDelay(); + } else { + it.remove(); + } + } + } + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + + public void stop() { + this.running.set(false); + } +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/test/FactoryTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/test/FactoryTest.java new file mode 100644 index 000000000..458e940aa --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/test/FactoryTest.java @@ -0,0 +1,34 @@ +/* + * 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.test.mock.test; + +import com.clubobsidian.dynamicgui.core.test.mock.MockFactory; +import org.junit.jupiter.api.BeforeEach; + +public abstract class FactoryTest { + + private final MockFactory factory = new MockFactory(); + + public MockFactory getFactory() { + return this.factory; + } + + @BeforeEach + public void setup() { + this.getFactory().inject(); + } +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/test/ScheduledTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/test/ScheduledTest.java new file mode 100644 index 000000000..85b48e0f5 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/test/ScheduledTest.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.test.mock.test; + +import com.clubobsidian.dynamicgui.core.DynamicGui; +import com.clubobsidian.dynamicgui.core.scheduler.Scheduler; +import com.clubobsidian.dynamicgui.core.test.mock.scheduler.MockScheduler; +import org.junit.jupiter.api.AfterEach; + +public abstract class ScheduledTest extends FactoryTest { + + @AfterEach + public void stop() { + Scheduler scheduler = DynamicGui.get().getPlatform().getScheduler(); + if (scheduler != null) { + ((MockScheduler) scheduler).stop(); + } + } +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/world/MockLocation.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/world/MockLocation.java new file mode 100644 index 000000000..8d98a3cbe --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/world/MockLocation.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.core.test.mock.world; + +import com.clubobsidian.dynamicgui.core.world.WorldWrapper; + +public class MockLocation { + + private final int x; + private final int y; + private final int z; + private final WorldWrapper world; + + public MockLocation(int x, int y, int z, WorldWrapper world) { + this.x = x; + this.y = y; + this.z = z; + this.world = world; + } + + public int getX() { + return this.x; + } + + public int getY() { + return this.y; + } + + public int getZ() { + return this.z; + } + + public WorldWrapper getWorld() { + return this.world; + } +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/world/MockLocationWrapper.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/world/MockLocationWrapper.java new file mode 100644 index 000000000..57140c802 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/world/MockLocationWrapper.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.test.mock.world; + +import com.clubobsidian.dynamicgui.core.world.LocationWrapper; + +public class MockLocationWrapper extends LocationWrapper { + + public MockLocationWrapper(MockLocation location) { + super(location.getX(), location.getY(), location.getZ(), location.getWorld()); + } +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/world/MockWorld.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/world/MockWorld.java new file mode 100644 index 000000000..0f70c3ba8 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/world/MockWorld.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.test.mock.world; + +import java.util.HashMap; +import java.util.Map; + +public class MockWorld { + + private final String name; + private final Map gameRules = new HashMap<>(); + + public MockWorld(String name) { + this.name = name; + } + + public String getName() { + return this.name; + } + + public void setGameRule(String rule, String value) { + this.gameRules.put(rule, value); + } + + public String getGameRule(String rule) { + return this.gameRules.get(rule); + } +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/world/MockWorldWrapper.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/world/MockWorldWrapper.java new file mode 100644 index 000000000..c50568276 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/world/MockWorldWrapper.java @@ -0,0 +1,44 @@ +/* + * 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.test.mock.world; + +import com.clubobsidian.dynamicgui.core.world.WorldWrapper; + +public class MockWorldWrapper extends WorldWrapper { + + private final MockWorld world; + + public MockWorldWrapper(MockWorld world) { + super(world.getName()); + this.world = world; + } + + @Override + public MockWorld getWorld() { + return this.world; + } + + @Override + public void setGameRule(String key, String value) { + this.world.setGameRule(key, value); + } + + @Override + public String getGameRule(String rule) { + return this.world.getGameRule(rule); + } +} diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/command/package-info.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/package-info.java similarity index 85% rename from core/src/main/java/com/clubobsidian/dynamicgui/command/package-info.java rename to core/src/test/java/com/clubobsidian/dynamicgui/core/test/package-info.java index 132140e5e..256720cfc 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/command/package-info.java +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/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.command; \ No newline at end of file +package com.clubobsidian.dynamicgui.core.test; diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/proxy/ProxyTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/proxy/ProxyTest.java new file mode 100644 index 000000000..cfead302a --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/proxy/ProxyTest.java @@ -0,0 +1,43 @@ +/* + * 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.test.proxy; + +import com.clubobsidian.dynamicgui.core.proxy.Proxy; +import org.junit.jupiter.api.Test; + +import java.util.UUID; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class ProxyTest { + + @Test + public void noProxyTest() { + assertEquals(Proxy.NONE, Proxy.fromString(UUID.randomUUID().toString())); + } + + @Test + public void bungeeTest() { + ; + assertEquals(Proxy.BUNGEECORD, Proxy.fromString("BUNGEE")); + } + + @Test + public void redisBungeeTest() { + assertEquals(Proxy.REDIS_BUNGEE, Proxy.fromString("REDIS")); + } +} \ No newline at end of file diff --git a/jitpack.yml b/jitpack.yml new file mode 100644 index 000000000..46c852919 --- /dev/null +++ b/jitpack.yml @@ -0,0 +1,2 @@ +jdk: + - openjdk11 \ No newline at end of file diff --git a/parser/build.gradle b/parser/build.gradle index 1fc6e3e33..0d6938d5d 100644 --- a/parser/build.gradle +++ b/parser/build.gradle @@ -3,6 +3,5 @@ plugins { } dependencies { - testImplementation 'junit:junit:4.12' api 'com.github.ClubObsidian:FuzzUtil:1.1.0' } \ No newline at end of file diff --git a/parser/src/main/java/com/clubobsidian/dynamicgui/parser/function/FunctionData.java b/parser/src/main/java/com/clubobsidian/dynamicgui/parser/function/FunctionData.java index dfa82e69e..721155083 100644 --- a/parser/src/main/java/com/clubobsidian/dynamicgui/parser/function/FunctionData.java +++ b/parser/src/main/java/com/clubobsidian/dynamicgui/parser/function/FunctionData.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.parser.function; -import java.io.Serializable; +package com.clubobsidian.dynamicgui.parser.function; import com.clubobsidian.fuzzutil.StringFuzz; +import java.io.Serializable; + public class FunctionData implements Serializable { /** diff --git a/parser/src/main/java/com/clubobsidian/dynamicgui/parser/function/FunctionModifier.java b/parser/src/main/java/com/clubobsidian/dynamicgui/parser/function/FunctionModifier.java index 27d77a8c1..d500f9f91 100644 --- a/parser/src/main/java/com/clubobsidian/dynamicgui/parser/function/FunctionModifier.java +++ b/parser/src/main/java/com/clubobsidian/dynamicgui/parser/function/FunctionModifier.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,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.clubobsidian.dynamicgui.parser.function; public enum FunctionModifier { diff --git a/parser/src/main/java/com/clubobsidian/dynamicgui/parser/function/FunctionToken.java b/parser/src/main/java/com/clubobsidian/dynamicgui/parser/function/FunctionToken.java index 17f8c06c1..b2681004f 100644 --- a/parser/src/main/java/com/clubobsidian/dynamicgui/parser/function/FunctionToken.java +++ b/parser/src/main/java/com/clubobsidian/dynamicgui/parser/function/FunctionToken.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,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.clubobsidian.dynamicgui.parser.function; import java.io.Serializable; diff --git a/parser/src/main/java/com/clubobsidian/dynamicgui/parser/function/FunctionType.java b/parser/src/main/java/com/clubobsidian/dynamicgui/parser/function/FunctionType.java index d7abb006b..cc2736e8d 100644 --- a/parser/src/main/java/com/clubobsidian/dynamicgui/parser/function/FunctionType.java +++ b/parser/src/main/java/com/clubobsidian/dynamicgui/parser/function/FunctionType.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.parser.function; +import com.clubobsidian.fuzzutil.StringFuzz; + import java.util.HashMap; import java.util.Map; -import com.clubobsidian.fuzzutil.StringFuzz; - public enum FunctionType { CLICK(true), diff --git a/parser/src/main/java/com/clubobsidian/dynamicgui/parser/function/FunctionTypeParser.java b/parser/src/main/java/com/clubobsidian/dynamicgui/parser/function/FunctionTypeParser.java index 6fa8687ed..7c556efe4 100644 --- a/parser/src/main/java/com/clubobsidian/dynamicgui/parser/function/FunctionTypeParser.java +++ b/parser/src/main/java/com/clubobsidian/dynamicgui/parser/function/FunctionTypeParser.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.parser.function; +import com.clubobsidian.dynamicgui.parser.macro.MacroParser; + import java.io.Serializable; import java.util.ArrayList; import java.util.List; -import com.clubobsidian.dynamicgui.parser.macro.MacroParser; - public class FunctionTypeParser implements Serializable { /** diff --git a/parser/src/main/java/com/clubobsidian/dynamicgui/parser/function/tree/FunctionNode.java b/parser/src/main/java/com/clubobsidian/dynamicgui/parser/function/tree/FunctionNode.java index 08c31bab9..5e538e5c9 100644 --- a/parser/src/main/java/com/clubobsidian/dynamicgui/parser/function/tree/FunctionNode.java +++ b/parser/src/main/java/com/clubobsidian/dynamicgui/parser/function/tree/FunctionNode.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.parser.function.tree; +import com.clubobsidian.dynamicgui.parser.function.FunctionToken; + import java.io.Serializable; import java.util.ArrayList; import java.util.List; -import com.clubobsidian.dynamicgui.parser.function.FunctionToken; - public class FunctionNode implements Serializable { /** @@ -28,16 +29,22 @@ public class FunctionNode implements Serializable { */ private static final long serialVersionUID = -8331607544830166913L; + private final String name; private final int depth; private final FunctionToken token; private final List children; - public FunctionNode(int depth, FunctionToken token) { + public FunctionNode(String name, int depth, FunctionToken token) { + this.name = name; this.depth = depth; this.token = token; this.children = new ArrayList<>(); } + public String getName() { + return this.name; + } + public int getDepth() { return this.depth; } diff --git a/parser/src/main/java/com/clubobsidian/dynamicgui/parser/function/tree/FunctionTree.java b/parser/src/main/java/com/clubobsidian/dynamicgui/parser/function/tree/FunctionTree.java index 1fdea1c8f..92889d6b0 100644 --- a/parser/src/main/java/com/clubobsidian/dynamicgui/parser/function/tree/FunctionTree.java +++ b/parser/src/main/java/com/clubobsidian/dynamicgui/parser/function/tree/FunctionTree.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,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.clubobsidian.dynamicgui.parser.function.tree; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; +package com.clubobsidian.dynamicgui.parser.function.tree; -import com.clubobsidian.dynamicgui.parser.function.*; +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.FunctionTypeParser; import com.clubobsidian.dynamicgui.parser.macro.MacroParser; import com.clubobsidian.fuzzutil.StringFuzz; import com.clubobsidian.wrappy.ConfigurationSection; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + public class FunctionTree implements Serializable { /** @@ -126,7 +131,7 @@ private void walkTree(int depth, ConfigurationSection section, FunctionNode pare List failFunctions = this.parseFunctionData(rootSection.getStringList("fail-on")); FunctionToken data = new FunctionToken(name, types, functionTokens, failFunctions); - FunctionNode childNode = new FunctionNode(depth, data); + FunctionNode childNode = new FunctionNode(name, depth, data); if (depth == 0) { this.rootNodes.add(childNode); diff --git a/parser/src/main/java/com/clubobsidian/dynamicgui/parser/gui/GuiMode.java b/parser/src/main/java/com/clubobsidian/dynamicgui/parser/gui/GuiMode.java index c519aee1a..e6884f100 100644 --- a/parser/src/main/java/com/clubobsidian/dynamicgui/parser/gui/GuiMode.java +++ b/parser/src/main/java/com/clubobsidian/dynamicgui/parser/gui/GuiMode.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,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.clubobsidian.dynamicgui.parser.gui; public enum GuiMode { diff --git a/parser/src/main/java/com/clubobsidian/dynamicgui/parser/gui/GuiToken.java b/parser/src/main/java/com/clubobsidian/dynamicgui/parser/gui/GuiToken.java index 5bcb6d236..b86746b79 100644 --- a/parser/src/main/java/com/clubobsidian/dynamicgui/parser/gui/GuiToken.java +++ b/parser/src/main/java/com/clubobsidian/dynamicgui/parser/gui/GuiToken.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,8 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.clubobsidian.dynamicgui.parser.gui; +import com.clubobsidian.dynamicgui.parser.function.tree.FunctionTree; +import com.clubobsidian.dynamicgui.parser.macro.MacroParser; +import com.clubobsidian.dynamicgui.parser.macro.MacroToken; +import com.clubobsidian.dynamicgui.parser.slot.SlotToken; +import com.clubobsidian.wrappy.ConfigurationSection; + import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; @@ -22,12 +29,6 @@ import java.util.List; import java.util.Map; -import com.clubobsidian.dynamicgui.parser.function.tree.FunctionTree; -import com.clubobsidian.dynamicgui.parser.macro.MacroParser; -import com.clubobsidian.dynamicgui.parser.macro.MacroToken; -import com.clubobsidian.dynamicgui.parser.slot.SlotToken; -import com.clubobsidian.wrappy.ConfigurationSection; - public class GuiToken implements Serializable { /** @@ -39,7 +40,7 @@ public class GuiToken implements Serializable { private final String type; private final int rows; private final GuiMode mode; - private final boolean closed; + private final Boolean closed; //This should be boxed private final List alias; private final List locations; private final Map> npcs; @@ -48,6 +49,7 @@ public class GuiToken implements Serializable { private final FunctionTree functions; private final List loadMacros; private final Map metadata; + private final boolean isStatic; public GuiToken(ConfigurationSection section) { this(section, new ArrayList<>()); @@ -65,7 +67,7 @@ public GuiToken(ConfigurationSection section, List macroTokens) { this.type = this.parseType(section.getString("type")); this.rows = section.getInteger("rows"); this.mode = this.parseMode(section.getString("mode")); - this.closed = section.getBoolean("close"); + this.closed = this.parseBoxedBoolean(section.getString("close")); this.alias = this.macroParser.parseListMacros(section.getStringList("alias")); this.locations = this.macroParser.parseListMacros(section.getStringList("locations")); this.npcs = this.loadNpcs(section); @@ -79,6 +81,15 @@ public GuiToken(ConfigurationSection section, List macroTokens) { ConfigurationSection metadataSection = section.getConfigurationSection("metadata"); this.metadata = this.parseMetadata(metadataSection); + this.isStatic = section.getBoolean("static"); + } + + private Boolean parseBoxedBoolean(String data) { + if(data == null) { + return null; + } + String parsed = this.macroParser.parseStringMacros(data); + return Boolean.parseBoolean(parsed); } public String parseType(String type) { @@ -147,7 +158,7 @@ public GuiMode getMode() { return this.mode; } - public boolean isClosed() { + public Boolean isClosed() { return this.closed; } @@ -182,4 +193,8 @@ public List getLoadMacros() { public Map getMetadata() { return this.metadata; } + + public boolean isStatic() { + return this.isStatic; + } } \ No newline at end of file diff --git a/parser/src/main/java/com/clubobsidian/dynamicgui/parser/macro/MacroParser.java b/parser/src/main/java/com/clubobsidian/dynamicgui/parser/macro/MacroParser.java index 957d2dd3c..c0c8a70b4 100644 --- a/parser/src/main/java/com/clubobsidian/dynamicgui/parser/macro/MacroParser.java +++ b/parser/src/main/java/com/clubobsidian/dynamicgui/parser/macro/MacroParser.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,16 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.clubobsidian.dynamicgui.parser.macro; +import org.apache.commons.lang3.StringUtils; + import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map.Entry; -import org.apache.commons.lang3.StringUtils; - public class MacroParser implements Serializable { /** diff --git a/parser/src/main/java/com/clubobsidian/dynamicgui/parser/macro/MacroToken.java b/parser/src/main/java/com/clubobsidian/dynamicgui/parser/macro/MacroToken.java index bfaa1a768..7f1d19ea1 100644 --- a/parser/src/main/java/com/clubobsidian/dynamicgui/parser/macro/MacroToken.java +++ b/parser/src/main/java/com/clubobsidian/dynamicgui/parser/macro/MacroToken.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.parser.macro; +import com.clubobsidian.wrappy.ConfigurationSection; + import java.io.Serializable; import java.util.LinkedHashMap; import java.util.Map; -import com.clubobsidian.wrappy.ConfigurationSection; - public class MacroToken implements Serializable { /** diff --git a/parser/src/main/java/com/clubobsidian/dynamicgui/parser/package-info.java b/parser/src/main/java/com/clubobsidian/dynamicgui/parser/package-info.java index e02375768..57e038c63 100644 --- a/parser/src/main/java/com/clubobsidian/dynamicgui/parser/package-info.java +++ b/parser/src/main/java/com/clubobsidian/dynamicgui/parser/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.parser; \ No newline at end of file +package com.clubobsidian.dynamicgui.parser; diff --git a/parser/src/main/java/com/clubobsidian/dynamicgui/parser/slot/SlotToken.java b/parser/src/main/java/com/clubobsidian/dynamicgui/parser/slot/SlotToken.java index 94e733933..04132e054 100644 --- a/parser/src/main/java/com/clubobsidian/dynamicgui/parser/slot/SlotToken.java +++ b/parser/src/main/java/com/clubobsidian/dynamicgui/parser/slot/SlotToken.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,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.clubobsidian.dynamicgui.parser.slot; +import com.clubobsidian.dynamicgui.parser.function.tree.FunctionTree; +import com.clubobsidian.dynamicgui.parser.macro.MacroParser; +import com.clubobsidian.dynamicgui.parser.macro.MacroToken; +import com.clubobsidian.wrappy.ConfigurationSection; + import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import com.clubobsidian.dynamicgui.parser.function.tree.FunctionTree; -import com.clubobsidian.dynamicgui.parser.macro.MacroParser; -import com.clubobsidian.dynamicgui.parser.macro.MacroToken; -import com.clubobsidian.wrappy.ConfigurationSection; - public class SlotToken implements Serializable { /** @@ -39,8 +40,8 @@ public class SlotToken implements Serializable { private final String name; private final String nbt; private final boolean glow; - private final boolean moveable; - private final boolean closed; + private final boolean movable; + private final Boolean closed; //This should be boxed private final byte data; private final List lore; private final List enchants; @@ -69,8 +70,8 @@ public SlotToken(int index, ConfigurationSection section, List macro this.name = this.macroParser.parseStringMacros(section.getString("name")); this.nbt = this.macroParser.parseStringMacros(section.getString("nbt")); this.glow = this.parseBoolean(section.getString("glow")); - this.moveable = this.parseBoolean(section.getString("moveable")); - this.closed = this.parseBoolean(section.getString("close")); + this.movable = this.parseBoolean(section.getString("movable")); + this.closed = this.parseBoxedBoolean(section.getString("close")); this.data = this.parseByte(section.getString("data")); this.lore = this.macroParser.parseListMacros(section.getStringList("lore")); this.enchants = this.macroParser.parseListMacros(section.getStringList("enchants")); @@ -108,13 +109,16 @@ private boolean parseBoolean(String data) { if (data == null) { return false; } - String parsed = this.macroParser.parseStringMacros(data); - if (data.equals("true")) { - return Boolean.parseBoolean(parsed); - } + return Boolean.parseBoolean(parsed); + } - return false; + private Boolean parseBoxedBoolean(String data) { + if(data == null) { + return null; + } + String parsed = this.macroParser.parseStringMacros(data); + return Boolean.parseBoolean(parsed); } private int parseInteger(String data) { @@ -171,11 +175,11 @@ public boolean getGlow() { return this.glow; } - public boolean isMoveable() { - return this.moveable; + public boolean isMovable() { + return this.movable; } - public boolean isClosed() { + public Boolean isClosed() { return this.closed; } @@ -194,6 +198,7 @@ public int getUpdateInterval() { public List getEnchants() { return this.enchants; } + public List getItemFlags() { return this.itemFlags; } diff --git a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/FunctionDataTest.java b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/FunctionDataTest.java index 5d55799bf..1424e463b 100644 --- a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/FunctionDataTest.java +++ b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/FunctionDataTest.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. @@ -18,10 +18,10 @@ import com.clubobsidian.dynamicgui.parser.function.FunctionData; import com.clubobsidian.dynamicgui.parser.function.FunctionModifier; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class FunctionDataTest { @@ -32,7 +32,7 @@ public class FunctionDataTest { private FunctionData data; - @Before + @BeforeEach public void setup() { this.data = new FunctionData(NAME, DATA, MODIFIER); } diff --git a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/FunctionModifierTest.java b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/FunctionModifierTest.java index 9b1c70ac8..f1b11260f 100644 --- a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/FunctionModifierTest.java +++ b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/FunctionModifierTest.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. @@ -17,9 +17,9 @@ package com.clubobsidian.dynamicgui.parser.test; import com.clubobsidian.dynamicgui.parser.function.FunctionModifier; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class FunctionModifierTest { diff --git a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/FunctionTreeTest.java b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/FunctionTreeTest.java index 11290a9d4..a0681d75e 100644 --- a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/FunctionTreeTest.java +++ b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/FunctionTreeTest.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,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.clubobsidian.dynamicgui.parser.test; - -import static org.junit.Assert.assertTrue; - -import java.io.File; -import java.util.List; -import org.junit.BeforeClass; -import org.junit.Test; +package com.clubobsidian.dynamicgui.parser.test; import com.clubobsidian.dynamicgui.parser.function.FunctionData; import com.clubobsidian.dynamicgui.parser.function.FunctionToken; @@ -31,12 +24,21 @@ import com.clubobsidian.dynamicgui.parser.macro.MacroToken; import com.clubobsidian.wrappy.Configuration; import com.clubobsidian.wrappy.ConfigurationSection; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertSame; public class FunctionTreeTest { private static FunctionTree tree; - @BeforeClass + @BeforeAll public static void loadTree() { File testFile = new File("test.yml"); System.out.println(testFile.getAbsolutePath()); @@ -49,7 +51,7 @@ public static void loadTree() { @Test public void testRootNodeSize() { int rootNodeSize = tree.getRootNodes().size(); - assertTrue("Root node size is not three", rootNodeSize == 3); + assertEquals(3, rootNodeSize); } @Test @@ -57,7 +59,7 @@ public void testFunctionTypes() { FunctionNode node = tree.getRootNodes().get(0); FunctionToken token = node.getToken(); FunctionType type = token.getTypes().get(0); - assertTrue("Function type is not load", type == FunctionType.LOAD); + assertSame(type, FunctionType.LOAD); } @Test @@ -66,16 +68,16 @@ public void testDescend() { int childrenNodeSize = childrenNodes.size(); FunctionToken token = childrenNodes.get(0).getToken(); FunctionData data = token.getFunctions().get(0); - assertTrue("Children node size for descend is not one", childrenNodeSize == 1); - assertTrue("Function is not function", data.getName().equals("function")); - assertTrue("Function data for child not is not 'with other data'", data.getData().equals("with other data")); + assertEquals(1, childrenNodeSize); + assertEquals("function", data.getName()); + assertEquals("with other data", data.getData()); } @Test public void testDescendTwoFunctions() { List childrenNodes = tree.getRootNodes().get(1).getChildren(); int childrenNodeSize = childrenNodes.size(); - assertTrue("Children node size for descend is not two", childrenNodeSize == 2); + assertEquals(2, childrenNodeSize); } @Test @@ -87,10 +89,10 @@ public void testDepthTwo() { String name = node.getToken().getName(); int depth = node.getDepth(); FunctionData data = token.getFunctions().get(0); - assertTrue("Depth is not two", depth == 2); - assertTrue("Children node size for depth two is not one", childrenNodeSize == 1); - assertTrue("Invalid data for depth-2-left node", data.getData().equals("some other data")); - assertTrue("Section name is not 'depth-2-left'", name.equals("depth-2-left")); + assertEquals(2, depth); + assertEquals(1, childrenNodeSize); + assertEquals("some other data", data.getData()); + assertEquals("depth-2-left", name); } @Test @@ -99,7 +101,7 @@ public void testColonParsing() { FunctionToken token = node.getToken(); FunctionData data = token.getFunctions().get(1); String functionData = data.getData(); - assertTrue("Function data is not 'with:a colon'", functionData.equals("with:a colon")); + assertEquals("with:a colon", functionData); } @Test @@ -108,7 +110,7 @@ public void testTrimming() { FunctionToken token = node.getToken(); FunctionData data = token.getFunctions().get(2); String functionDataStr = data.getData(); - assertTrue("Function data is not 'test trimming'", functionDataStr.equals("test trimming")); + assertEquals("test trimming", functionDataStr); } @Test @@ -117,7 +119,7 @@ public void testNormalize() { FunctionToken token = node.getToken(); FunctionData data = token.getFunctions().get(1); String functionName = data.getName(); - assertTrue("Function normalization failed, function is not 'functiontonormalize'", functionName.equals("functiontonormalize")); + assertEquals("functiontonormalize", functionName); } @Test @@ -133,7 +135,7 @@ public void testFailFunctionsList() { FunctionData data = token.getFailOnFunctions().get(0); String functionName = data.getName(); - assertTrue("Function normalization failed, function is not 'onfailfunction'", functionName.equals("onfailfunction")); + assertEquals("onfailfunction", functionName); } @Test @@ -149,12 +151,12 @@ public void testFailFunctionsString() { FunctionData data = token.getFailOnFunctions().get(0); String functionName = data.getName(); - assertTrue("Function normalization failed, function is not 'onfailfunctionstring'", functionName.equals("onfailfunctionstring")); + assertEquals("onfailfunctionstring", functionName); } @Test public void testMacroTokens() { List tokens = tree.getMacroParser().getTokens(); - assertTrue("MacroToken's for functions should not be null", tokens != null); + assertNotNull(tokens); } } \ No newline at end of file diff --git a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/FunctionTypeParserTest.java b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/FunctionTypeParserTest.java index febed8974..6dbdb4600 100644 --- a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/FunctionTypeParserTest.java +++ b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/FunctionTypeParserTest.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,94 +13,94 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.clubobsidian.dynamicgui.parser.test; -import static org.junit.Assert.assertTrue; +import com.clubobsidian.dynamicgui.parser.function.FunctionType; +import com.clubobsidian.dynamicgui.parser.function.FunctionTypeParser; +import com.clubobsidian.dynamicgui.parser.macro.MacroParser; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.junit.Test; - -import com.clubobsidian.dynamicgui.parser.function.FunctionType; -import com.clubobsidian.dynamicgui.parser.function.FunctionTypeParser; -import com.clubobsidian.dynamicgui.parser.macro.MacroParser; -import com.clubobsidian.dynamicgui.parser.macro.MacroToken; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; public class FunctionTypeParserTest { @Test public void testLeft() { - MacroParser macroParser = new MacroParser(new ArrayList()); + MacroParser macroParser = new MacroParser(new ArrayList<>()); FunctionTypeParser typeParser = new FunctionTypeParser(macroParser); - assertTrue(typeParser.parseType("LEFT").equals(FunctionType.LEFT)); + assertEquals(typeParser.parseType("LEFT"), FunctionType.LEFT); } @Test public void testRight() { - MacroParser macroParser = new MacroParser(new ArrayList()); + MacroParser macroParser = new MacroParser(new ArrayList<>()); FunctionTypeParser typeParser = new FunctionTypeParser(macroParser); - assertTrue(typeParser.parseType("RIGHT").equals(FunctionType.RIGHT)); + assertEquals(typeParser.parseType("RIGHT"), FunctionType.RIGHT); } @Test public void testLowercase() { - MacroParser macroParser = new MacroParser(new ArrayList()); + MacroParser macroParser = new MacroParser(new ArrayList<>()); FunctionTypeParser typeParser = new FunctionTypeParser(macroParser); - assertTrue(typeParser.parseType("left").equals(FunctionType.LEFT)); + assertEquals(typeParser.parseType("left"), FunctionType.LEFT); } @Test public void testParseShiftLeftWithUnderscore() { - MacroParser macroParser = new MacroParser(new ArrayList()); + MacroParser macroParser = new MacroParser(new ArrayList<>()); FunctionTypeParser typeParser = new FunctionTypeParser(macroParser); - assertTrue(typeParser.parseType("SHIFT_LEFT").equals(FunctionType.SHIFT_LEFT)); + assertEquals(typeParser.parseType("SHIFT_LEFT"), FunctionType.SHIFT_LEFT); } @Test public void testParseShiftLeftNoUnderscore() { - MacroParser macroParser = new MacroParser(new ArrayList()); + MacroParser macroParser = new MacroParser(new ArrayList<>()); FunctionTypeParser typeParser = new FunctionTypeParser(macroParser); - assertTrue(typeParser.parseType("SHIFTLEFT").equals(FunctionType.SHIFT_LEFT)); + assertEquals(typeParser.parseType("SHIFTLEFT"), FunctionType.SHIFT_LEFT); } @Test public void testParseShiftRighWithUnderscore() { - MacroParser macroParser = new MacroParser(new ArrayList()); + MacroParser macroParser = new MacroParser(new ArrayList<>()); FunctionTypeParser typeParser = new FunctionTypeParser(macroParser); - assertTrue(typeParser.parseType("SHIFT_RIGHT").equals(FunctionType.SHIFT_RIGHT)); + assertEquals(typeParser.parseType("SHIFT_RIGHT"), FunctionType.SHIFT_RIGHT); } @Test public void testParseShiftRightNoUnderscore() { - MacroParser macroParser = new MacroParser(new ArrayList()); + MacroParser macroParser = new MacroParser(new ArrayList<>()); FunctionTypeParser typeParser = new FunctionTypeParser(macroParser); - assertTrue(typeParser.parseType("SHIFTRIGHT").equals(FunctionType.SHIFT_RIGHT)); + assertEquals(typeParser.parseType("SHIFTRIGHT"), FunctionType.SHIFT_RIGHT); } @Test public void testInvalidFunctionType() { - MacroParser macroParser = new MacroParser(new ArrayList()); + MacroParser macroParser = new MacroParser(new ArrayList<>()); FunctionTypeParser typeParser = new FunctionTypeParser(macroParser); - assertTrue(typeParser.parseType("DOESNOTEXIST") == null); + assertNull(typeParser.parseType("DOESNOTEXIST")); } @Test public void testFunctionTypeList() { - MacroParser macroParser = new MacroParser(new ArrayList()); + MacroParser macroParser = new MacroParser(new ArrayList<>()); FunctionTypeParser typeParser = new FunctionTypeParser(macroParser); List types = new ArrayList<>(Arrays.asList("LEFT", "RIGHT")); List parsedTypes = typeParser.parseTypes(types); - assertTrue(parsedTypes.size() == 2); + assertEquals(2, parsedTypes.size()); } @Test public void testFunctionTypeListWithInvalidFunction() { - MacroParser macroParser = new MacroParser(new ArrayList()); + MacroParser macroParser = new MacroParser(new ArrayList<>()); FunctionTypeParser typeParser = new FunctionTypeParser(macroParser); List types = new ArrayList<>(Arrays.asList("LEFT", "DOESNOTEXIST")); List parsedTypes = typeParser.parseTypes(types); - assertTrue(parsedTypes.size() == 1); + assertEquals(1, parsedTypes.size()); } } \ No newline at end of file diff --git a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/FunctionTypeTest.java b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/FunctionTypeTest.java index b560a0dcc..a331e52f4 100644 --- a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/FunctionTypeTest.java +++ b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/FunctionTypeTest.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. @@ -16,12 +16,11 @@ package com.clubobsidian.dynamicgui.parser.test; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - import com.clubobsidian.dynamicgui.parser.function.FunctionType; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; public class FunctionTypeTest { diff --git a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/GuiTokenTest.java b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/GuiTokenTest.java index 430942807..cee071b69 100644 --- a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/GuiTokenTest.java +++ b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/GuiTokenTest.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,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.clubobsidian.dynamicgui.parser.test; - -import static org.junit.Assert.assertTrue; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import org.junit.BeforeClass; -import org.junit.Test; +package com.clubobsidian.dynamicgui.parser.test; import com.clubobsidian.dynamicgui.parser.function.FunctionData; import com.clubobsidian.dynamicgui.parser.function.tree.FunctionNode; @@ -34,12 +25,24 @@ import com.clubobsidian.dynamicgui.parser.slot.SlotToken; import com.clubobsidian.wrappy.Configuration; import com.clubobsidian.wrappy.ConfigurationSection; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; public class GuiTokenTest { private static GuiToken token; - @BeforeClass + @BeforeAll public static void loadToken() { File file = new File("test.yml"); Configuration config = Configuration.load(file); @@ -49,41 +52,41 @@ public static void loadToken() { @Test public void testTitle() { String title = token.getTitle(); - assertTrue("Gui title is not 'test gui title'", title.equals("test gui title")); + assertEquals("test gui title", title); } @Test public void testRows() { int rows = token.getRows(); - assertTrue("Gui rows is not 1", rows == 1); + assertEquals(1, rows); } @Test public void testMode() { GuiMode mode = token.getMode(); - assertTrue("Gui mode is not 'set'", mode == GuiMode.SET); + assertSame(mode, GuiMode.SET); } @Test public void testClose() { boolean closed = token.isClosed(); - assertTrue("Gui close it not true", closed); + assertTrue(closed); } @Test public void testNpcs() { Map> npcs = token.getNpcs(); List npcIds = npcs.get("citizens"); - assertTrue("No npc ids were found for citizens", npcIds != null); - assertTrue("Npcs size is not 2", npcIds.size() == 2); - assertTrue("Npc at index 0 is not 5", npcIds.get(0) == 5); - assertTrue("Npc at index 1 is not 88", npcIds.get(1) == 77); + assertNotNull(npcIds); + assertEquals(2, npcIds.size()); + assertEquals(5, (int) npcIds.get(0)); + assertEquals(77, (int) npcIds.get(1)); } @Test public void testSlots() { Map slots = token.getSlots(); - assertTrue("Slots size is not 6", slots.size() == 6); + assertEquals(6, slots.size()); } @Test @@ -92,13 +95,13 @@ public void testGuiFunctions() { FunctionNode node = tree.getRootNodes().get(0); FunctionData data = node.getToken().getFunctions().get(0); String functionName = data.getName(); - assertTrue("Function name is not function2", functionName.equals("function2")); + assertEquals("function2", functionName); } @Test public void testMacroToken() { MacroToken macroToken = token.getMacroParser().getTokens().get(0); - assertTrue("Macro token was not initialized", macroToken != null); + assertNotNull(macroToken); } @Test @@ -117,6 +120,6 @@ public void testExternalMacroToken() { String title = token.getTitle(); - assertTrue("External gui test's title is not 'test gui title'", title.equals("test gui title")); + assertEquals("test gui title", title); } } \ No newline at end of file diff --git a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/SlotTokenTest.java b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/SlotTokenTest.java index a3acc1911..aacc032e2 100644 --- a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/SlotTokenTest.java +++ b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/SlotTokenTest.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,29 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.clubobsidian.dynamicgui.parser.test; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.io.File; -import org.junit.BeforeClass; -import org.junit.Test; +package com.clubobsidian.dynamicgui.parser.test; import com.clubobsidian.dynamicgui.parser.function.tree.FunctionTree; import com.clubobsidian.dynamicgui.parser.macro.MacroToken; import com.clubobsidian.dynamicgui.parser.slot.SlotToken; import com.clubobsidian.wrappy.Configuration; import com.clubobsidian.wrappy.ConfigurationSection; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import java.io.File; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class SlotTokenTest { private static SlotToken token; - @BeforeClass + @BeforeAll public static void loadSlotToken() { File file = new File("test.yml"); Configuration config = Configuration.load(file); @@ -44,19 +46,19 @@ public static void loadSlotToken() { @Test public void testSlotName() { String name = token.getName(); - assertTrue("Name was not test for slot token", name.equals("test")); + assertEquals("test", name); } @Test public void testSlotIcon() { String icon = token.getIcon(); - assertTrue("Icon was not dirt", icon.equals("DIRT")); + assertEquals("DIRT", icon); } @Test public void testSlotNbt() { String nbt = token.getNbt(); - assertTrue("Nbt was not '{SomeKey:\"some value\"}'", nbt.equals("{SomeKey:\"some value\"}")); + assertEquals("{SomeKey:\"some value\"}", nbt); } @Test @@ -68,13 +70,13 @@ public void testSlotGlow() { @Test public void testSlotClose() { boolean close = token.isClosed(); - assertTrue("Close not was true", close); + assertTrue(close); } @Test public void testSlotData() { byte data = token.getData(); - assertTrue("Data was not 1", data == 1); + assertEquals(1, data); } @@ -82,12 +84,12 @@ public void testSlotData() { public void testSlotFunctionTree() { FunctionTree tree = token.getFunctionTree(); int nodeSize = tree.getRootNodes().size(); - assertTrue("Node were not parsed for the function tree", nodeSize == 1); + assertEquals(1, nodeSize); } @Test public void testMacroToken() { MacroToken macroToken = token.getMacroParser().getTokens().get(0); - assertTrue("Macro token was not initialized", macroToken != null); + assertNotNull(macroToken); } } \ No newline at end of file diff --git a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/functiontree/EmptyFunctionTreeTest.java b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/functiontree/EmptyFunctionTreeTest.java index 1aa8d5fb0..86eef514a 100644 --- a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/functiontree/EmptyFunctionTreeTest.java +++ b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/functiontree/EmptyFunctionTreeTest.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. @@ -16,17 +16,16 @@ package com.clubobsidian.dynamicgui.parser.test.functiontree; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - import com.clubobsidian.dynamicgui.parser.function.tree.FunctionTree; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class EmptyFunctionTreeTest { @Test public void testEmptyFunctionTree() { FunctionTree tree = new FunctionTree(); - assertTrue("Tree nodes are not empty", tree.getRootNodes().size() == 0); + assertEquals(0, tree.getRootNodes().size()); } } \ No newline at end of file diff --git a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/gui/AliasTest.java b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/gui/AliasTest.java index 5d947a769..f9c3ef41b 100644 --- a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/gui/AliasTest.java +++ b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/gui/AliasTest.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. @@ -16,14 +16,13 @@ package com.clubobsidian.dynamicgui.parser.test.gui; -import static org.junit.Assert.assertTrue; +import com.clubobsidian.dynamicgui.parser.gui.GuiToken; +import com.clubobsidian.wrappy.Configuration; +import org.junit.jupiter.api.Test; import java.io.File; -import org.junit.Test; - -import com.clubobsidian.dynamicgui.parser.gui.GuiToken; -import com.clubobsidian.wrappy.Configuration; +import static org.junit.jupiter.api.Assertions.assertEquals; public class AliasTest { @@ -34,6 +33,6 @@ public void testAlias() { Configuration config = Configuration.load(file); GuiToken token = new GuiToken(config); String alias = token.getAlias().get(0); - assertTrue("Gui alias is not 'test'", alias.equals("test")); + assertEquals("test", alias); } } \ No newline at end of file diff --git a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/gui/GuitMetadataTest.java b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/gui/GuiMetadataTest.java similarity index 75% rename from parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/gui/GuitMetadataTest.java rename to parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/gui/GuiMetadataTest.java index 3e2cae59e..69c870497 100644 --- a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/gui/GuitMetadataTest.java +++ b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/gui/GuiMetadataTest.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. @@ -16,19 +16,16 @@ package com.clubobsidian.dynamicgui.parser.test.gui; -import static org.junit.Assert.assertTrue; +import com.clubobsidian.dynamicgui.parser.gui.GuiToken; +import com.clubobsidian.wrappy.Configuration; +import org.junit.jupiter.api.Test; import java.io.File; import java.util.Map; -import org.junit.Test; - -import com.clubobsidian.dynamicgui.parser.gui.GuiToken; -import com.clubobsidian.dynamicgui.parser.slot.SlotToken; -import com.clubobsidian.wrappy.Configuration; -import com.clubobsidian.wrappy.ConfigurationSection; +import static org.junit.jupiter.api.Assertions.assertEquals; -public class GuitMetadataTest { +public class GuiMetadataTest { @Test public void testSlotMetadata() { @@ -37,7 +34,7 @@ public void testSlotMetadata() { Configuration config = Configuration.load(metadataFile); GuiToken token = new GuiToken(config); Map metadata = token.getMetadata(); - assertTrue(metadata.size() == 1); - assertTrue(metadata.get("some").equals("metadata")); + assertEquals(1, metadata.size()); + assertEquals("metadata", metadata.get("some")); } } \ No newline at end of file diff --git a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/gui/InvalidTypeTest.java b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/gui/InvalidTypeTest.java index 64c3e2e89..a2dc2af61 100644 --- a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/gui/InvalidTypeTest.java +++ b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/gui/InvalidTypeTest.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. @@ -16,14 +16,13 @@ package com.clubobsidian.dynamicgui.parser.test.gui; -import static org.junit.Assert.assertTrue; +import com.clubobsidian.dynamicgui.parser.gui.GuiToken; +import com.clubobsidian.wrappy.Configuration; +import org.junit.jupiter.api.Test; import java.io.File; -import org.junit.Test; - -import com.clubobsidian.dynamicgui.parser.gui.GuiToken; -import com.clubobsidian.wrappy.Configuration; +import static org.junit.jupiter.api.Assertions.assertEquals; public class InvalidTypeTest { @@ -34,6 +33,6 @@ public void testType() { Configuration config = Configuration.load(file); GuiToken token = new GuiToken(config); String type = token.getType(); - assertTrue("Gui type is not 'CHEST'", type.equals("CHEST")); + assertEquals("CHEST", type); } } \ No newline at end of file diff --git a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/gui/LoadMacrosTest.java b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/gui/LoadMacrosTest.java index cd97dfd05..a9ede852d 100644 --- a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/gui/LoadMacrosTest.java +++ b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/gui/LoadMacrosTest.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. @@ -16,15 +16,14 @@ package com.clubobsidian.dynamicgui.parser.test.gui; -import static org.junit.Assert.assertTrue; +import com.clubobsidian.dynamicgui.parser.gui.GuiToken; +import com.clubobsidian.wrappy.Configuration; +import org.junit.jupiter.api.Test; import java.io.File; import java.util.List; -import org.junit.Test; - -import com.clubobsidian.dynamicgui.parser.gui.GuiToken; -import com.clubobsidian.wrappy.Configuration; +import static org.junit.jupiter.api.Assertions.assertEquals; public class LoadMacrosTest { @@ -35,7 +34,7 @@ public void testLoadMacros() { Configuration config = Configuration.load(file); GuiToken token = new GuiToken(config); List loadMacros = token.getLoadMacros(); - assertTrue(loadMacros.size() == 1); - assertTrue(loadMacros.get(0).equals("test")); + assertEquals(1, loadMacros.size()); + assertEquals("test", loadMacros.get(0)); } } \ No newline at end of file diff --git a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/gui/LocationTest.java b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/gui/LocationTest.java index 52ce6b5b4..e527b331d 100644 --- a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/gui/LocationTest.java +++ b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/gui/LocationTest.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. @@ -16,14 +16,13 @@ package com.clubobsidian.dynamicgui.parser.test.gui; -import static org.junit.Assert.assertTrue; +import com.clubobsidian.dynamicgui.parser.gui.GuiToken; +import com.clubobsidian.wrappy.Configuration; +import org.junit.jupiter.api.Test; import java.io.File; -import org.junit.Test; - -import com.clubobsidian.dynamicgui.parser.gui.GuiToken; -import com.clubobsidian.wrappy.Configuration; +import static org.junit.jupiter.api.Assertions.assertEquals; public class LocationTest { @@ -34,7 +33,7 @@ public void testAlias() { Configuration config = Configuration.load(file); GuiToken token = new GuiToken(config); String location = token.getLocations().get(0); - assertTrue("Location is not '0,0,0,world'", location.equals("0,0,0,world")); + assertEquals("0,0,0,world", location); } } \ No newline at end of file diff --git a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/gui/NoModeTest.java b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/gui/NoModeTest.java index 8dd636db2..b68038c1a 100644 --- a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/gui/NoModeTest.java +++ b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/gui/NoModeTest.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. @@ -16,15 +16,14 @@ package com.clubobsidian.dynamicgui.parser.test.gui; -import static org.junit.Assert.assertTrue; - -import java.io.File; - -import org.junit.Test; - import com.clubobsidian.dynamicgui.parser.gui.GuiMode; import com.clubobsidian.dynamicgui.parser.gui.GuiToken; import com.clubobsidian.wrappy.Configuration; +import org.junit.jupiter.api.Test; + +import java.io.File; + +import static org.junit.jupiter.api.Assertions.assertSame; public class NoModeTest { @@ -35,7 +34,7 @@ public void testAlias() { Configuration config = Configuration.load(file); GuiToken token = new GuiToken(config); GuiMode alias = token.getMode(); - assertTrue("Gui mode was null but is set by default", alias == GuiMode.SET); + assertSame(alias, GuiMode.SET); } } \ No newline at end of file diff --git a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/gui/StaticTest.java b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/gui/StaticTest.java new file mode 100644 index 000000000..1a13aeb15 --- /dev/null +++ b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/gui/StaticTest.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.parser.test.gui; + +import com.clubobsidian.dynamicgui.parser.gui.GuiToken; +import com.clubobsidian.wrappy.Configuration; +import org.junit.jupiter.api.Test; + +import java.io.File; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class StaticTest { + + @Test + public void testStatic() { + File guiFolder = new File("test", "gui"); + File file = new File(guiFolder, "static.yml"); + Configuration config = Configuration.load(file); + GuiToken token = new GuiToken(config); + boolean isStatic = token.isStatic(); + assertTrue(isStatic); + } +} diff --git a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/gui/ValidTypeTest.java b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/gui/ValidTypeTest.java index 53816d486..7f529301c 100644 --- a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/gui/ValidTypeTest.java +++ b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/gui/ValidTypeTest.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. @@ -16,14 +16,13 @@ package com.clubobsidian.dynamicgui.parser.test.gui; -import static org.junit.Assert.assertTrue; +import com.clubobsidian.dynamicgui.parser.gui.GuiToken; +import com.clubobsidian.wrappy.Configuration; +import org.junit.jupiter.api.Test; import java.io.File; -import org.junit.Test; - -import com.clubobsidian.dynamicgui.parser.gui.GuiToken; -import com.clubobsidian.wrappy.Configuration; +import static org.junit.jupiter.api.Assertions.assertEquals; public class ValidTypeTest { @@ -34,6 +33,6 @@ public void testType() { Configuration config = Configuration.load(file); GuiToken token = new GuiToken(config); String type = token.getType(); - assertTrue("Gui type is not 'DISPENSER'", type.equals("DISPENSER")); + assertEquals("DISPENSER", type); } } \ No newline at end of file diff --git a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/macro/MacroNonStringTest.java b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/macro/MacroNonStringTest.java index d8c81c12b..5e7641ebc 100644 --- a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/macro/MacroNonStringTest.java +++ b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/macro/MacroNonStringTest.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. @@ -16,18 +16,17 @@ package com.clubobsidian.dynamicgui.parser.test.macro; -import static org.junit.Assert.assertTrue; +import com.clubobsidian.dynamicgui.parser.macro.MacroParser; +import com.clubobsidian.dynamicgui.parser.macro.MacroToken; +import com.clubobsidian.wrappy.Configuration; +import com.clubobsidian.wrappy.ConfigurationSection; +import org.junit.jupiter.api.Test; import java.io.File; import java.util.ArrayList; import java.util.List; -import org.junit.Test; - -import com.clubobsidian.dynamicgui.parser.macro.MacroParser; -import com.clubobsidian.dynamicgui.parser.macro.MacroToken; -import com.clubobsidian.wrappy.Configuration; -import com.clubobsidian.wrappy.ConfigurationSection; +import static org.junit.jupiter.api.Assertions.assertEquals; public class MacroNonStringTest { @@ -43,7 +42,7 @@ public void testNonStringParseStringMacros() { tokens.add(token); MacroParser parser = new MacroParser(tokens); String parsed = parser.parseStringMacros("%test-non-string%"); - assertTrue(parsed.equals("1")); + assertEquals("1", parsed); } @Test @@ -62,8 +61,8 @@ public void testNonStringParseListMacros() { nonString.add("%test-non-string%"); nonString.add("%test-non-string%"); List parsed = parser.parseListMacros(nonString); - assertTrue(parsed.size() == 2); - assertTrue(parsed.get(0).equals("1")); - assertTrue(parsed.get(1).equals("1")); + assertEquals(2, parsed.size()); + assertEquals("1", parsed.get(0)); + assertEquals("1", parsed.get(1)); } } \ No newline at end of file diff --git a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/macro/MacroParserTest.java b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/macro/MacroParserTest.java index cd3080076..2eb27f213 100644 --- a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/macro/MacroParserTest.java +++ b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/macro/MacroParserTest.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. @@ -16,18 +16,17 @@ package com.clubobsidian.dynamicgui.parser.test.macro; -import static org.junit.Assert.assertTrue; +import com.clubobsidian.dynamicgui.parser.macro.MacroParser; +import com.clubobsidian.dynamicgui.parser.macro.MacroToken; +import com.clubobsidian.wrappy.Configuration; +import com.clubobsidian.wrappy.ConfigurationSection; +import org.junit.jupiter.api.Test; import java.io.File; import java.util.ArrayList; import java.util.List; -import org.junit.Test; - -import com.clubobsidian.dynamicgui.parser.macro.MacroParser; -import com.clubobsidian.dynamicgui.parser.macro.MacroToken; -import com.clubobsidian.wrappy.Configuration; -import com.clubobsidian.wrappy.ConfigurationSection; +import static org.junit.jupiter.api.Assertions.assertEquals; public class MacroParserTest { @@ -52,15 +51,15 @@ public void testMultilineParsing() { System.out.println("newLore:" + newLore.toString()); - assertTrue("New lore size is not 8", newLore.size() == 8); - assertTrue("First line is not 'This is some gui text'", newLore.get(0).equals("This is some text")); - assertTrue("Second line is not 'Replace some text'", newLore.get(1).equals("Replace some text")); - assertTrue("Third line is not 'and some other text test'", newLore.get(2).equals("and some other text test")); - assertTrue("Forth line is not 'with some other text'", newLore.get(3).equals("with some other text")); - assertTrue("Fifth line is not 'Replace some text'", newLore.get(4).equals("Replace some text")); - assertTrue("Sixth line is not 'and some other text'", newLore.get(5).equals("and some other text")); - assertTrue("Seventh line is not 'with some other text'", newLore.get(6).equals("with some other text")); - assertTrue("Eigth line is not 'not-a-macro'", newLore.get(7).equals("not-a-macro")); + assertEquals(8, newLore.size()); + assertEquals("This is some text", newLore.get(0)); + assertEquals("Replace some text", newLore.get(1)); + assertEquals("and some other text test", newLore.get(2)); + assertEquals("with some other text", newLore.get(3)); + assertEquals("Replace some text", newLore.get(4)); + assertEquals("and some other text", newLore.get(5)); + assertEquals("with some other text", newLore.get(6)); + assertEquals("not-a-macro", newLore.get(7)); } @Test @@ -84,9 +83,9 @@ public void testSmallMultiLine() { System.out.println(newLore.toString()); - assertTrue("Size of new lore is not 2", newLore.size() == 2); - assertTrue("First line is not 'Replace some text", newLore.get(0).equals("Replace some text")); - assertTrue("Second line is not 'test'", newLore.get(1).equals("test")); + assertEquals(2, newLore.size()); + assertEquals("Replace some text", newLore.get(0)); + assertEquals("test", newLore.get(1)); } @Test @@ -110,7 +109,7 @@ public void testOutOfIndexSmallMultiLine() { System.out.println("New lore: " + newLore + " Size: " + newLore.size()); - assertTrue("First line is not 'Replace some text", newLore.get(0).equals("Replace some text")); + assertEquals("Replace some text", newLore.get(0)); } @@ -133,7 +132,7 @@ public void testSingleLineParsing() { String newName = parser.parseStringMacros(name); - assertTrue("New name is not 'A name'", newName.equals("A name")); + assertEquals("A name", newName); } @Test @@ -160,11 +159,11 @@ public void testMacroChaining() { System.out.println("parsedLore: " + parsedLore.size()); - assertTrue("Lore length is not 5'", parsedLore.size() == 5); - assertTrue("First line of lore is not 'not-a-macro'", parsedLore.get(0).equals("not-a-macro")); - assertTrue("Second line of lore is not 'Replace some text'", parsedLore.get(1).equals("Replace some text")); - assertTrue("Third line of lore is not 'and some other text test'", parsedLore.get(2).equals("and some other text test")); - assertTrue("Forth line of lore is not 'with some other text'", parsedLore.get(3).equals("with some other text")); - assertTrue("Fifth line of lore is not 'still-not-a-macro'", parsedLore.get(4).equals("still-not-a-macro")); + assertEquals(5, parsedLore.size()); + assertEquals("not-a-macro", parsedLore.get(0)); + assertEquals("Replace some text", parsedLore.get(1)); + assertEquals("and some other text test", parsedLore.get(2)); + assertEquals("with some other text", parsedLore.get(3)); + assertEquals("still-not-a-macro", parsedLore.get(4)); } } \ No newline at end of file diff --git a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/macro/MacrosTokenTest.java b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/macro/MacrosTokenTest.java index 964d8aa9f..e372b277b 100644 --- a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/macro/MacrosTokenTest.java +++ b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/macro/MacrosTokenTest.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. @@ -16,17 +16,18 @@ package com.clubobsidian.dynamicgui.parser.test.macro; -import static org.junit.Assert.assertTrue; +import com.clubobsidian.dynamicgui.parser.macro.MacroToken; +import com.clubobsidian.wrappy.Configuration; +import com.clubobsidian.wrappy.ConfigurationSection; +import org.junit.jupiter.api.Test; import java.io.File; import java.util.List; import java.util.Map; -import org.junit.Test; - -import com.clubobsidian.dynamicgui.parser.macro.MacroToken; -import com.clubobsidian.wrappy.Configuration; -import com.clubobsidian.wrappy.ConfigurationSection; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class MacrosTokenTest { @@ -39,7 +40,7 @@ public void testGuiMacroToken() { MacroToken token = new MacroToken(section); Map macros = token.getMacros(); - assertTrue("Macros did not load in for gui macros, size is not 2", macros.size() == 2); + assertEquals(2, macros.size()); } @Test @@ -57,16 +58,16 @@ public void testSlotMacroToken() { Map macros = token.getMacros(); Object firstMacro = macros.get("%test%"); - assertTrue("First line of slot macro is not a string", firstMacro instanceof String); - assertTrue("First macro is not 'This is some text'", firstMacro.equals("This is some text")); + assertTrue(firstMacro instanceof String); + assertEquals("This is some text", firstMacro); Object secondMacro = macros.get("%multiline-test%"); - assertTrue("Second line of slot macro is not a list", secondMacro instanceof List); + assertTrue(secondMacro instanceof List); List listMacro = ((List) secondMacro); - assertTrue("Second line of slot macro's first line is not a string", listMacro.get(0) instanceof String); - assertTrue("Second line of slot macro's size is not 3", listMacro.size() == 3); + assertTrue(listMacro.get(0) instanceof String); + assertEquals(3, listMacro.size()); } @@ -81,7 +82,7 @@ public void testEmptyMacroToken() { MacroToken token = new MacroToken(section); Map macros = token.getMacros(); - assertTrue("Macros is null on an empty slot, it should just be empty", macros != null); - assertTrue("Macros is not empty when it should be empty", macros.size() == 0); + assertNotNull(macros); + assertEquals(0, macros.size()); } } \ No newline at end of file diff --git a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/macro/MultiMacroSameFileTest.java b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/macro/MultiMacroSameFileTest.java index 96e1c648a..2f3123a49 100644 --- a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/macro/MultiMacroSameFileTest.java +++ b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/macro/MultiMacroSameFileTest.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. @@ -16,17 +16,16 @@ package com.clubobsidian.dynamicgui.parser.test.macro; -import static org.junit.Assert.assertTrue; +import com.clubobsidian.dynamicgui.parser.macro.MacroParser; +import com.clubobsidian.dynamicgui.parser.macro.MacroToken; +import com.clubobsidian.wrappy.Configuration; +import org.junit.jupiter.api.Test; import java.io.File; import java.util.ArrayList; import java.util.List; -import org.junit.Test; - -import com.clubobsidian.dynamicgui.parser.macro.MacroParser; -import com.clubobsidian.dynamicgui.parser.macro.MacroToken; -import com.clubobsidian.wrappy.Configuration; +import static org.junit.jupiter.api.Assertions.assertEquals; public class MultiMacroSameFileTest { @@ -48,7 +47,7 @@ public void stringTest() { String toParse = "%uses-test%"; String parsed = parser.parseStringMacros(toParse); System.out.println(parsed); - assertTrue(parsed.equals("test")); + assertEquals("test", parsed); } @Test @@ -71,9 +70,9 @@ public void listTest() { replaceIn.add(toParse); List parsed = parser.parseListMacros(replaceIn); System.out.println(parsed); - assertTrue(parsed.size() == 2); - assertTrue(parsed.get(0).equals("test1")); - assertTrue(parsed.get(1).equals("test2")); + assertEquals(2, parsed.size()); + assertEquals("test1", parsed.get(0)); + assertEquals("test2", parsed.get(1)); } } \ No newline at end of file diff --git a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/EnchantTest.java b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/EnchantTest.java index b68b34eaf..1459bc245 100644 --- a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/EnchantTest.java +++ b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/EnchantTest.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. @@ -16,16 +16,15 @@ package com.clubobsidian.dynamicgui.parser.test.slot; -import static org.junit.Assert.assertTrue; +import com.clubobsidian.dynamicgui.parser.slot.SlotToken; +import com.clubobsidian.wrappy.Configuration; +import com.clubobsidian.wrappy.ConfigurationSection; +import org.junit.jupiter.api.Test; import java.io.File; import java.util.List; -import org.junit.Test; - -import com.clubobsidian.dynamicgui.parser.slot.SlotToken; -import com.clubobsidian.wrappy.Configuration; -import com.clubobsidian.wrappy.ConfigurationSection; +import static org.junit.jupiter.api.Assertions.assertEquals; public class EnchantTest { @@ -37,6 +36,6 @@ public void enchantTest() { ConfigurationSection section = config.getConfigurationSection("0"); SlotToken token = new SlotToken(0, section); List enchants = token.getEnchants(); - assertTrue("Slot enchants size is not 3", enchants.size() == 3); + assertEquals(3, enchants.size()); } } \ No newline at end of file diff --git a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/InvalidAmountTest.java b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/InvalidAmountTest.java index 8e9fb7f02..57b0f851a 100644 --- a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/InvalidAmountTest.java +++ b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/InvalidAmountTest.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. @@ -16,15 +16,14 @@ package com.clubobsidian.dynamicgui.parser.test.slot; -import static org.junit.Assert.assertTrue; - -import java.io.File; - -import org.junit.Test; - import com.clubobsidian.dynamicgui.parser.slot.SlotToken; import com.clubobsidian.wrappy.Configuration; import com.clubobsidian.wrappy.ConfigurationSection; +import org.junit.jupiter.api.Test; + +import java.io.File; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class InvalidAmountTest { @@ -36,6 +35,6 @@ public void amountTest() { ConfigurationSection section = config.getConfigurationSection("0"); SlotToken token = new SlotToken(0, section); int amount = token.getAmount(); - assertTrue("Amount is not 1", amount == 1); + assertEquals(1, amount); } } \ No newline at end of file diff --git a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/InvalidFunctionTypeMacroTest.java b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/InvalidFunctionTypeMacroTest.java index ac8f08ba2..09b3ebdbc 100644 --- a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/InvalidFunctionTypeMacroTest.java +++ b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/InvalidFunctionTypeMacroTest.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. @@ -16,17 +16,16 @@ package com.clubobsidian.dynamicgui.parser.test.slot; -import static org.junit.Assert.assertTrue; - -import java.io.File; - -import org.junit.Test; - import com.clubobsidian.dynamicgui.parser.function.FunctionToken; import com.clubobsidian.dynamicgui.parser.function.tree.FunctionTree; import com.clubobsidian.dynamicgui.parser.slot.SlotToken; import com.clubobsidian.wrappy.Configuration; import com.clubobsidian.wrappy.ConfigurationSection; +import org.junit.jupiter.api.Test; + +import java.io.File; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class InvalidFunctionTypeMacroTest { @@ -40,6 +39,6 @@ public void invalidFunctionTypeTest() { SlotToken token = new SlotToken(0, section); FunctionTree tree = token.getFunctionTree(); FunctionToken functionToken = tree.getRootNodes().get(0).getToken(); - assertTrue("Function node parsed incorrect function type", functionToken.getTypes().size() == 1); + assertEquals(1, functionToken.getTypes().size()); } } \ No newline at end of file diff --git a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/InvalidSlotDataMacroTest.java b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/InvalidSlotDataMacroTest.java index e31e66afe..d9b120381 100644 --- a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/InvalidSlotDataMacroTest.java +++ b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/InvalidSlotDataMacroTest.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. @@ -16,15 +16,14 @@ package com.clubobsidian.dynamicgui.parser.test.slot; -import static org.junit.Assert.assertTrue; - -import java.io.File; - -import org.junit.Test; - import com.clubobsidian.dynamicgui.parser.slot.SlotToken; import com.clubobsidian.wrappy.Configuration; import com.clubobsidian.wrappy.ConfigurationSection; +import org.junit.jupiter.api.Test; + +import java.io.File; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class InvalidSlotDataMacroTest { @@ -37,6 +36,6 @@ public void testInvalidSlotData() { ConfigurationSection section = config.getConfigurationSection("0"); SlotToken token = new SlotToken(0, section); byte data = token.getData(); - assertTrue("Slot data was not parsed correctly, data is not 0", data == 0); + assertEquals(0, data); } } \ No newline at end of file diff --git a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/InvalidUpdateIntervalTest.java b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/InvalidUpdateIntervalTest.java index 2266ef463..80e44612b 100644 --- a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/InvalidUpdateIntervalTest.java +++ b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/InvalidUpdateIntervalTest.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. @@ -16,15 +16,14 @@ package com.clubobsidian.dynamicgui.parser.test.slot; -import static org.junit.Assert.assertTrue; - -import java.io.File; - -import org.junit.Test; - import com.clubobsidian.dynamicgui.parser.slot.SlotToken; import com.clubobsidian.wrappy.Configuration; import com.clubobsidian.wrappy.ConfigurationSection; +import org.junit.jupiter.api.Test; + +import java.io.File; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class InvalidUpdateIntervalTest { @@ -36,7 +35,7 @@ public void lessThanZeroupdateIntervalTest() { ConfigurationSection section = config.getConfigurationSection("0"); SlotToken token = new SlotToken(0, section); int interval = token.getUpdateInterval(); - assertTrue("Update interval is not 0", interval == 0); + assertEquals(0, interval); } @Test @@ -47,6 +46,6 @@ public void invalidIntervalTest() { ConfigurationSection section = config.getConfigurationSection("1"); SlotToken token = new SlotToken(1, section); int interval = token.getUpdateInterval(); - assertTrue("Update interval was not invalid", interval == 0); + assertEquals(0, interval); } } \ No newline at end of file diff --git a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/ItemFlagTest.java b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/ItemFlagTest.java index cdd8a6f7d..cc101ee9c 100644 --- a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/ItemFlagTest.java +++ b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/ItemFlagTest.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. @@ -19,12 +19,12 @@ import com.clubobsidian.dynamicgui.parser.slot.SlotToken; import com.clubobsidian.wrappy.Configuration; import com.clubobsidian.wrappy.ConfigurationSection; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.File; import java.util.List; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; public class ItemFlagTest { @@ -36,6 +36,6 @@ public void enchantTest() { ConfigurationSection section = config.getConfigurationSection("0"); SlotToken token = new SlotToken(0, section); List enchants = token.getItemFlags(); - assertTrue("Slot item-flags size is not 2", enchants.size() == 2); + assertEquals(2, enchants.size()); } } \ No newline at end of file diff --git a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/LoreTest.java b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/LoreTest.java index a75d7cbeb..af632481f 100644 --- a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/LoreTest.java +++ b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/LoreTest.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. @@ -16,16 +16,15 @@ package com.clubobsidian.dynamicgui.parser.test.slot; -import static org.junit.Assert.assertTrue; +import com.clubobsidian.dynamicgui.parser.slot.SlotToken; +import com.clubobsidian.wrappy.Configuration; +import com.clubobsidian.wrappy.ConfigurationSection; +import org.junit.jupiter.api.Test; import java.io.File; import java.util.List; -import org.junit.Test; - -import com.clubobsidian.dynamicgui.parser.slot.SlotToken; -import com.clubobsidian.wrappy.Configuration; -import com.clubobsidian.wrappy.ConfigurationSection; +import static org.junit.jupiter.api.Assertions.assertEquals; public class LoreTest { @@ -37,6 +36,6 @@ public void loreTest() { ConfigurationSection section = config.getConfigurationSection("0"); SlotToken token = new SlotToken(0, section); List lore = token.getLore(); - assertTrue("Slot lore size is not 2", lore.size() == 2); + assertEquals(2, lore.size()); } } \ No newline at end of file diff --git a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/ModelTest.java b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/ModelTest.java index 85860d29c..3a117339f 100644 --- a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/ModelTest.java +++ b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/ModelTest.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. @@ -19,12 +19,12 @@ import com.clubobsidian.dynamicgui.parser.slot.SlotToken; import com.clubobsidian.wrappy.Configuration; import com.clubobsidian.wrappy.ConfigurationSection; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.File; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; public class ModelTest { diff --git a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/MoveableTest.java b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/MovableTest.java similarity index 72% rename from parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/MoveableTest.java rename to parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/MovableTest.java index 2b6d923bf..baaa34ee6 100644 --- a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/MoveableTest.java +++ b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/MovableTest.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. @@ -16,36 +16,35 @@ package com.clubobsidian.dynamicgui.parser.test.slot; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.io.File; - -import org.junit.Test; - import com.clubobsidian.dynamicgui.parser.slot.SlotToken; import com.clubobsidian.wrappy.Configuration; import com.clubobsidian.wrappy.ConfigurationSection; +import org.junit.jupiter.api.Test; + +import java.io.File; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; -public class MoveableTest { +public class MovableTest { @Test - public void testSlotMoveable() { + public void testSlotMovable() { File slotFolder = new File("test", "slot"); - File metadataFile = new File(slotFolder, "moveable.yml"); + File metadataFile = new File(slotFolder, "movable.yml"); Configuration config = Configuration.load(metadataFile); ConfigurationSection slot = config.getConfigurationSection("0"); SlotToken token = new SlotToken(0, slot); - assertTrue(token.isMoveable()); + assertTrue(token.isMovable()); } @Test - public void testSlotNotMoveable() { + public void testSlotNotMovable() { File slotFolder = new File("test", "slot"); - File metadataFile = new File(slotFolder, "moveable.yml"); + File metadataFile = new File(slotFolder, "movable.yml"); Configuration config = Configuration.load(metadataFile); ConfigurationSection slot = config.getConfigurationSection("1"); SlotToken token = new SlotToken(1, slot); - assertFalse(token.isMoveable()); + assertFalse(token.isMovable()); } } \ No newline at end of file diff --git a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/SlotIndexTest.java b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/SlotIndexTest.java index 112ee8f8f..1335b9d9e 100644 --- a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/SlotIndexTest.java +++ b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/SlotIndexTest.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. @@ -16,15 +16,14 @@ package com.clubobsidian.dynamicgui.parser.test.slot; -import static org.junit.Assert.assertTrue; - -import java.io.File; - -import org.junit.Test; - import com.clubobsidian.dynamicgui.parser.slot.SlotToken; import com.clubobsidian.wrappy.Configuration; import com.clubobsidian.wrappy.ConfigurationSection; +import org.junit.jupiter.api.Test; + +import java.io.File; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class SlotIndexTest { @@ -35,6 +34,6 @@ public void testSlotIndex() { Configuration config = Configuration.load(file); ConfigurationSection section = config.getConfigurationSection("13"); SlotToken token = new SlotToken(13, section); - assertTrue("Slot index is not 13", token.getIndex() == 13); + assertEquals(13, token.getIndex()); } } \ No newline at end of file diff --git a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/SlotMetadataTest.java b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/SlotMetadataTest.java index c84784434..44603360a 100644 --- a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/SlotMetadataTest.java +++ b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/SlotMetadataTest.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. @@ -16,16 +16,15 @@ package com.clubobsidian.dynamicgui.parser.test.slot; -import static org.junit.Assert.assertTrue; +import com.clubobsidian.dynamicgui.parser.slot.SlotToken; +import com.clubobsidian.wrappy.Configuration; +import com.clubobsidian.wrappy.ConfigurationSection; +import org.junit.jupiter.api.Test; import java.io.File; import java.util.Map; -import org.junit.Test; - -import com.clubobsidian.dynamicgui.parser.slot.SlotToken; -import com.clubobsidian.wrappy.Configuration; -import com.clubobsidian.wrappy.ConfigurationSection; +import static org.junit.jupiter.api.Assertions.assertEquals; public class SlotMetadataTest { @@ -37,8 +36,8 @@ public void testSlotMetadata() { ConfigurationSection slot = config.getConfigurationSection("0"); SlotToken token = new SlotToken(0, slot); Map metadata = token.getMetadata(); - assertTrue(metadata.size() == 1); - assertTrue(metadata.get("some").equals("metadata")); + assertEquals(1, metadata.size()); + assertEquals("metadata", metadata.get("some")); } @Test @@ -49,6 +48,6 @@ public void testSlotNoMetadata() { ConfigurationSection slot = config.getConfigurationSection("1"); SlotToken token = new SlotToken(1, slot); Map metadata = token.getMetadata(); - assertTrue(metadata.size() == 0); + assertEquals(0, metadata.size()); } } \ No newline at end of file diff --git a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/ValidAmountTest.java b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/ValidAmountTest.java index d3d166e82..edfa51669 100644 --- a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/ValidAmountTest.java +++ b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/ValidAmountTest.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. @@ -16,15 +16,14 @@ package com.clubobsidian.dynamicgui.parser.test.slot; -import static org.junit.Assert.assertTrue; - -import java.io.File; - -import org.junit.Test; - import com.clubobsidian.dynamicgui.parser.slot.SlotToken; import com.clubobsidian.wrappy.Configuration; import com.clubobsidian.wrappy.ConfigurationSection; +import org.junit.jupiter.api.Test; + +import java.io.File; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class ValidAmountTest { @@ -36,6 +35,6 @@ public void amountTest() { ConfigurationSection section = config.getConfigurationSection("0"); SlotToken token = new SlotToken(0, section); int amount = token.getAmount(); - assertTrue("Amount is not 32", amount == 32); + assertEquals(32, amount); } } \ No newline at end of file diff --git a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/ValidFunctionTypeMacroTest.java b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/ValidFunctionTypeMacroTest.java index c9f3e08ca..9c608af07 100644 --- a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/ValidFunctionTypeMacroTest.java +++ b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/ValidFunctionTypeMacroTest.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. @@ -16,18 +16,17 @@ package com.clubobsidian.dynamicgui.parser.test.slot; -import static org.junit.Assert.assertTrue; - -import java.io.File; - -import org.junit.Test; - import com.clubobsidian.dynamicgui.parser.function.FunctionToken; import com.clubobsidian.dynamicgui.parser.function.FunctionType; import com.clubobsidian.dynamicgui.parser.function.tree.FunctionTree; import com.clubobsidian.dynamicgui.parser.slot.SlotToken; import com.clubobsidian.wrappy.Configuration; import com.clubobsidian.wrappy.ConfigurationSection; +import org.junit.jupiter.api.Test; + +import java.io.File; + +import static org.junit.jupiter.api.Assertions.assertSame; public class ValidFunctionTypeMacroTest { @@ -41,6 +40,6 @@ public void validFunctionTypeMacroTest() { SlotToken token = new SlotToken(0, section); FunctionTree tree = token.getFunctionTree(); FunctionToken functionToken = tree.getRootNodes().get(0).getToken(); - assertTrue("Function node parsed incorrect function type", functionToken.getTypes().get(0) == FunctionType.RIGHT); + assertSame(functionToken.getTypes().get(0), FunctionType.RIGHT); } } \ No newline at end of file diff --git a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/ValidSlotDataMacroTest.java b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/ValidSlotDataMacroTest.java index a50c80fff..ebe05dc42 100644 --- a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/ValidSlotDataMacroTest.java +++ b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/ValidSlotDataMacroTest.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. @@ -16,15 +16,14 @@ package com.clubobsidian.dynamicgui.parser.test.slot; -import static org.junit.Assert.assertTrue; - -import java.io.File; - -import org.junit.Test; - import com.clubobsidian.dynamicgui.parser.slot.SlotToken; import com.clubobsidian.wrappy.Configuration; import com.clubobsidian.wrappy.ConfigurationSection; +import org.junit.jupiter.api.Test; + +import java.io.File; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class ValidSlotDataMacroTest { @@ -37,6 +36,6 @@ public void validSlotDataMacroTest() { ConfigurationSection section = config.getConfigurationSection("0"); SlotToken token = new SlotToken(0, section); byte data = token.getData(); - assertTrue("Slot data was not parsed correctly, data is not 1", data == 1); + assertEquals(1, data); } } \ No newline at end of file diff --git a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/ValidUpdateIntervalTest.java b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/ValidUpdateIntervalTest.java index c58f4b57d..89e91e04d 100644 --- a/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/ValidUpdateIntervalTest.java +++ b/parser/src/test/java/com/clubobsidian/dynamicgui/parser/test/slot/ValidUpdateIntervalTest.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. @@ -16,15 +16,14 @@ package com.clubobsidian.dynamicgui.parser.test.slot; -import static org.junit.Assert.assertTrue; - -import java.io.File; - -import org.junit.Test; - import com.clubobsidian.dynamicgui.parser.slot.SlotToken; import com.clubobsidian.wrappy.Configuration; import com.clubobsidian.wrappy.ConfigurationSection; +import org.junit.jupiter.api.Test; + +import java.io.File; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class ValidUpdateIntervalTest { @@ -36,6 +35,6 @@ public void updateIntervalTest() { ConfigurationSection section = config.getConfigurationSection("0"); SlotToken token = new SlotToken(0, section); int interval = token.getUpdateInterval(); - assertTrue("Update interval is not 5", interval == 5); + assertEquals(5, interval); } } \ No newline at end of file diff --git a/parser/test/gui/static.yml b/parser/test/gui/static.yml new file mode 100644 index 000000000..a9afeb4a7 --- /dev/null +++ b/parser/test/gui/static.yml @@ -0,0 +1 @@ +static: true \ No newline at end of file diff --git a/parser/test/slot/movable.yml b/parser/test/slot/movable.yml new file mode 100644 index 000000000..ade9d7349 --- /dev/null +++ b/parser/test/slot/movable.yml @@ -0,0 +1,4 @@ +'0': + movable: true +'1': + movable: false \ No newline at end of file diff --git a/parser/test/slot/moveable.yml b/parser/test/slot/moveable.yml deleted file mode 100644 index f84f85c70..000000000 --- a/parser/test/slot/moveable.yml +++ /dev/null @@ -1,4 +0,0 @@ -'0': - moveable: true -'1': - moveable: false \ No newline at end of file