Skip to content

Commit

Permalink
Now using KrakenCore
Browse files Browse the repository at this point in the history
This adds some common utils for files & configurations.
Also fixes the "restart" to apply changes on reload.
  • Loading branch information
sarhatabaot committed Apr 30, 2022
1 parent 17e1b89 commit b9db122
Show file tree
Hide file tree
Showing 21 changed files with 363 additions and 389 deletions.
57 changes: 32 additions & 25 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,52 +1,51 @@
plugins {
id 'com.github.johnrengelman.shadow' version '7.1.0'
id "io.freefair.lombok" version "6.3.0"
id 'com.github.johnrengelman.shadow' version '7.1.2'
id 'io.freefair.lombok' version '6.3.0'
id 'java-library'
id 'org.sonarqube' version '3.3'
}

group = 'me.tychsen'
version = '1.6.1'

sourceCompatibility = targetCompatibility = 16
version = '1.7.0-SNAPSHOT'

repositories {
mavenCentral()
maven {
name= "aikar-acf"
url = "https://repo.aikar.co/content/groups/aikar/" }
name= 'aikar-acf'
url = 'https://repo.aikar.co/content/groups/aikar/' }
maven {
name = "spigot-repo"
url = "https://hub.spigotmc.org/nexus/content/repositories/snapshots/"
name = 'spigot-repo'
url = 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/'
}
maven {
name = "vault-repo"
url = "https://nexus.hc.to/content/repositories/pub_releases"
name = 'vault-repo'
url = 'https://nexus.hc.to/content/repositories/pub_releases'
}
maven {
name = "bungeecord-chat"
url = "https://oss.sonatype.org/content/groups/public/"
name = 'bungeecord-chat'
url = 'https://oss.sonatype.org/content/groups/public/'
}
maven {
name = "codemc-repo"
url = "https://repo.codemc.org/repository/maven-public"
name = 'codemc-repo'
url = 'https://repo.codemc.org/repository/maven-public'
}
maven {
name = "jitpack"
url = "https://jitpack.io"
name = 'jitpack'
url = 'https://jitpack.io'
}
maven {
name = "playerpoints"
name = 'playerpoints'
url = 'https://repo.rosewooddev.io/repository/public/'
}
}

dependencies {
compileOnly "org.spigotmc:spigot-api:1.17-R0.1-SNAPSHOT"
compileOnly "com.github.MilkBowl:VaultAPI:1.7.1"
compileOnly 'org.spigotmc:spigot-api:1.17-R0.1-SNAPSHOT'
compileOnly 'com.github.MilkBowl:VaultAPI:1.7.1'
compileOnly 'org.black_ixx:playerpoints:3.2.3'
api 'com.github.sarhatabaot:krakencore:1.1.3'
api 'de.tr7zw:item-nbt-api:2.9.2'
api "co.aikar:acf-paper:0.5.1-SNAPSHOT"
api 'co.aikar:acf-paper:0.5.1-SNAPSHOT'
api 'org.bstats:bstats-bukkit:3.0.0'
api group: 'org.jetbrains', name: 'annotations', version: '23.0.0'
}
Expand All @@ -55,6 +54,7 @@ rootProject.tasks.named("processResources") {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}


processResources {
def props = [version: version]
inputs.properties props
Expand All @@ -70,17 +70,24 @@ shadowJar {
relocate 'co.aikar.commands', 'me.tychsen.enchantgui.acf'
relocate 'co.aikar.locales', 'me.tychsen.enchantgui.locales'
relocate 'de.tr7zw', 'me.tychsen.enchantgui.nbt'
relocate 'com.github.sarhatabaot.kraken', 'me.tychsen.enchantgui.kraken'
}

wrapper {
gradleVersion = "7.4.2"
gradleVersion = '7.4.2'
}

sonarqube {
properties {
property "sonar.projectKey", "sarhatabaot_EnchantGUI"
property "sonar.organization", "sarhatabaot-github"
property "sonar.host.url", "https://sonarcloud.io"
property 'sonar.projectKey', 'sarhatabaot_EnchantGUI'
property 'sonar.organization', 'sarhatabaot-github'
property 'sonar.host.url', 'https://sonarcloud.io'
}
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(16))
}
}

3 changes: 1 addition & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
rootProject.name = 'EnchantGUI'

rootProject.name = 'EnchantGUI'
21 changes: 0 additions & 21 deletions src/main/java/me/tychsen/enchantgui/ChatUtil.java

This file was deleted.

28 changes: 22 additions & 6 deletions src/main/java/me/tychsen/enchantgui/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import me.tychsen.enchantgui.commands.ShopCommand;
import me.tychsen.enchantgui.config.EShopConfig;
import me.tychsen.enchantgui.event.EventManager;
import me.tychsen.enchantgui.localization.LocalizationManager;
import me.tychsen.enchantgui.menu.DefaultMenuSystem;
import me.tychsen.enchantgui.menu.MenuSystem;
import net.milkbowl.vault.economy.Economy;
Expand All @@ -16,6 +17,7 @@
import org.bukkit.Bukkit;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;

import java.util.HashSet;
import java.util.Set;
Expand All @@ -31,15 +33,19 @@ public class Main extends JavaPlugin {
@Getter @Setter (AccessLevel.PRIVATE)
private static Set<UUID> toggleRightClickPlayers = new HashSet<>();

private EShopConfig config;
private LocalizationManager lm;

@Getter
private PlayerPointsAPI ppApi;

@Override
public void onEnable() {
setInstance(this);
config = new EShopConfig();
lm = new LocalizationManager();
hookVaultEconomy();
// Generate config.yml if there is none
saveDefaultConfig();


// Register event manager
setMenuSystem(new DefaultMenuSystem());
Expand All @@ -55,7 +61,7 @@ public void onEnable() {
new Metrics(this, 3871);

getLogger().info(() -> getName() + " " + getDescription().getVersion() + " enabled!");
getLogger().info(() -> getName() + " " + getDescription().getVersion() + " using: "+ EShopConfig.getPaymentStrategy().name());
getLogger().info(() -> getName() + " " + getDescription().getVersion() + " using: "+ Main.getInstance().getMainConfig().getPaymentStrategy().name());
}

@Override
Expand All @@ -68,17 +74,19 @@ public void onDisable() {
}

public void onReload(){
config.reloadConfig();

hookVaultEconomy();
hookPlayerPoints();
}

public static void debug(String msg) {
if (EShopConfig.getDebug())
if (Main.getInstance().getMainConfig().getDebug())
Main.getInstance().getLogger().warning(() -> String.format("DEBUG %s", msg));
}

private void hookVaultEconomy() {
if(!EShopConfig.getPaymentType().equalsIgnoreCase("money")) {
if(!Main.getInstance().getMainConfig().getPaymentType().equalsIgnoreCase("money")) {
return;
}
if (getServer().getPluginManager().getPlugin("Vault") == null) {
Expand All @@ -94,14 +102,22 @@ private void hookVaultEconomy() {
}

private void hookPlayerPoints() {
if(!EShopConfig.getPaymentType().equalsIgnoreCase("playerpoints")) {
if(!config.getPaymentType().equalsIgnoreCase("playerpoints")) {
return;
}
if (Bukkit.getPluginManager().isPluginEnabled("PlayerPoints")) {
this.ppApi = PlayerPoints.getInstance().getAPI();
}
}

@NotNull
public EShopConfig getMainConfig() {
return config;
}

public LocalizationManager getLm() {
return lm;
}


}
29 changes: 12 additions & 17 deletions src/main/java/me/tychsen/enchantgui/commands/ShopCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

import co.aikar.commands.BaseCommand;
import co.aikar.commands.annotation.*;
import com.github.sarhatabaot.kraken.core.chat.ChatUtil;
import me.tychsen.enchantgui.Main;
import me.tychsen.enchantgui.config.EShopConfig;
import me.tychsen.enchantgui.config.EShopEnchants;
import me.tychsen.enchantgui.config.EShopShop;
import me.tychsen.enchantgui.config.Enchants;
import me.tychsen.enchantgui.localization.LocalizationManager;
import me.tychsen.enchantgui.menu.DefaultMenuSystem;
import me.tychsen.enchantgui.menu.MenuSystem;
import me.tychsen.enchantgui.ChatUtil;
import me.tychsen.enchantgui.permissions.EShopPermissionSys;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
Expand All @@ -21,10 +19,10 @@ public class ShopCommand extends BaseCommand {
private final String prefix;
private final MenuSystem menuSystem;

private final LocalizationManager lm = LocalizationManager.getInstance();
private final LocalizationManager lm = Main.getInstance().getLm();

public ShopCommand() {
this.prefix = lm.getString("prefix");
this.prefix = lm.getLanguageString("prefix");
this.menuSystem = Main.getMenuSystem();
}

Expand All @@ -37,35 +35,32 @@ public void onGui(final Player player){
@Subcommand("toggle")
@CommandPermission(EShopPermissionSys.TOGGLE)
public void onToggle(final Player player){
if(!EShopConfig.getBoolean("right-click-enchanting-table")){
tell(player,lm.getString("disabled-feature"));
if(!Main.getInstance().getMainConfig().getBoolean("right-click-enchanting-table")){
tell(player,lm.getLanguageString("disabled-feature"));
return;
}

if(Main.getToggleRightClickPlayers().contains(player.getUniqueId())){
Main.getToggleRightClickPlayers().remove(player.getUniqueId());
tell(player,lm.getString("toggle-on"));
tell(player,lm.getLanguageString("toggle-on"));
}
else {
Main.getToggleRightClickPlayers().add(player.getUniqueId());
tell(player,lm.getString("toggle-off"));
tell(player,lm.getLanguageString("toggle-off"));
}
}


@Subcommand("reload")
@CommandPermission(EShopPermissionSys.RELOAD)
public void onReload(final CommandSender player){
EShopConfig.reloadConfig(player);
LocalizationManager.getInstance().reload(player);
Main.setMenuSystem(new DefaultMenuSystem());
Main.getMenuSystem().getMenuGenerator().setShopEnchants(new EShopEnchants());
EShopShop.getInstance().reload(player);
Main.getInstance().onReload();
Main.getInstance().getLogger().info(getName() + " " + Main.getInstance().getDescription().getVersion() + " using: "+ EShopConfig.getPaymentStrategy().name());
Main.getInstance().getLm().reload(player);
Main.getMenuSystem().reload();
Main.getInstance().getLogger().info(() -> "%s %s using: %s".formatted(getName(),Main.getInstance().getDescription().getVersion(),Main.getInstance().getMainConfig().getPaymentStrategy().name()));
}

private void tell(final Player player, final String message){
ChatUtil.tell(player,String.format("%s %s",prefix,message));
ChatUtil.sendMessage(player,String.format("%s %s",prefix,message));
}
}
84 changes: 0 additions & 84 deletions src/main/java/me/tychsen/enchantgui/config/AConfig.java

This file was deleted.

Loading

0 comments on commit b9db122

Please sign in to comment.