Skip to content

Commit

Permalink
code cleanup, fixed bugs and enhancement
Browse files Browse the repository at this point in the history
  • Loading branch information
poyrazinan committed Oct 13, 2023
1 parent 491661d commit 7105100
Show file tree
Hide file tree
Showing 57 changed files with 1,286 additions and 592 deletions.
44 changes: 44 additions & 0 deletions bukkit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<repositories>
Expand All @@ -40,5 +41,48 @@
<version>4.0.43</version>
<scope>provided</scope>
</dependency>
<!-- InventoryAPI -->
<dependency>
<groupId>de.themoep</groupId>
<artifactId>inventorygui</artifactId>
<!--The following version may not be the latest. Check it before using.-->
<version>1.5-SNAPSHOT</version>
</dependency>
<!-- xSeries -->
<dependency>
<groupId>com.github.cryptomorin</groupId>
<artifactId>XSeries</artifactId>
<version>9.4.0</version>
</dependency>
<!-- NBT Api -->
<dependency>
<groupId>de.tr7zw</groupId>
<artifactId>item-nbt-api-plugin</artifactId>
<version>2.12.0</version>
</dependency>
<!-- Triump command -->
<dependency>
<groupId>dev.triumphteam</groupId>
<artifactId>triumph-cmd-bukkit</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<!-- Okaeri Config Storage -->
<dependency>
<groupId>eu.okaeri</groupId>
<artifactId>okaeri-configs-yaml-bukkit</artifactId>
<version>4.0.4</version>
</dependency>
<!-- PlaceholderAPI -->
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.11.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>dev.s7a</groupId>
<artifactId>base64-itemstack</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</project>
19 changes: 0 additions & 19 deletions bukkit/src/main/java/net/leaderos/plugin/Bungee.java

This file was deleted.

75 changes: 68 additions & 7 deletions bukkit/src/main/java/net/leaderos/plugin/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
import dev.triumphteam.cmd.bukkit.BukkitCommandManager;
import dev.triumphteam.cmd.bukkit.message.BukkitMessageKey;
import dev.triumphteam.cmd.core.message.MessageKey;
import eu.okaeri.configs.ConfigManager;
import eu.okaeri.configs.yaml.bukkit.YamlBukkitConfigurer;
import lombok.Getter;
import net.leaderos.plugin.api.LeaderOSAPI;
import net.leaderos.plugin.configuration.Config;
import net.leaderos.plugin.configuration.Language;
import net.leaderos.plugin.configuration.Modules;
import net.leaderos.plugin.helpers.ChatUtil;
import net.leaderos.plugin.modules.credit.Credit;
import net.leaderos.plugin.modules.donators.RecentDonations;
import net.leaderos.plugin.modules.voucher.Voucher;
Expand All @@ -13,11 +19,12 @@
import net.leaderos.plugin.commands.LeaderOSCommand;
import net.leaderos.plugin.modules.bazaar.Bazaar;
import net.leaderos.plugin.modules.webstore.WebStore;
import net.leaderos.shared.helpers.ChatUtil;
import net.leaderos.plugin.modules.auth.AuthLogin;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;

/**
* Main class of project
*
Expand All @@ -38,6 +45,25 @@ public class Main extends JavaPlugin {
@Getter
private static Shared shared;


/**
* Config file of plugin
*/
@Getter
private Config configFile;

/**
* Lang file of plugin
*/
@Getter
private Language langFile;

/**
* Module file of plugin
*/
@Getter
private Modules modulesFile;

/**
* CommandManager
*/
Expand All @@ -49,7 +75,9 @@ public class Main extends JavaPlugin {
*/
public void onLoad() {
instance = this;
shared = new Shared(this);
setupFiles();
shared = new Shared(this, Main.getInstance().getConfigFile().getSettings().getUrl(),
Main.getInstance().getConfigFile().getSettings().getApiKey());
}

/**
Expand Down Expand Up @@ -82,19 +110,52 @@ public void onDisable() {
private void setupCommands() {
commandManager.registerCommand(new LeaderOSCommand());
commandManager.registerMessage(MessageKey.INVALID_ARGUMENT, (sender, invalidArgumentContext) ->
ChatUtil.sendMessage(sender, shared.getLangFile().getMessages().getCommand().getInvalidArgument()));
ChatUtil.sendMessage(sender, getLangFile().getMessages().getCommand().getInvalidArgument()));

commandManager.registerMessage(MessageKey.UNKNOWN_COMMAND, (sender, invalidArgumentContext) ->
ChatUtil.sendMessage(sender, shared.getLangFile().getMessages().getCommand().getUnknownCommand()));
ChatUtil.sendMessage(sender, getLangFile().getMessages().getCommand().getUnknownCommand()));

commandManager.registerMessage(MessageKey.NOT_ENOUGH_ARGUMENTS, (sender, invalidArgumentContext) ->
ChatUtil.sendMessage(sender, shared.getLangFile().getMessages().getCommand().getNotEnoughArguments()));
ChatUtil.sendMessage(sender, getLangFile().getMessages().getCommand().getNotEnoughArguments()));

commandManager.registerMessage(MessageKey.TOO_MANY_ARGUMENTS, (sender, invalidArgumentContext) ->
ChatUtil.sendMessage(sender, shared.getLangFile().getMessages().getCommand().getTooManyArguments()));
ChatUtil.sendMessage(sender, getLangFile().getMessages().getCommand().getTooManyArguments()));

commandManager.registerMessage(BukkitMessageKey.NO_PERMISSION, (sender, invalidArgumentContext) ->
ChatUtil.sendMessage(sender, shared.getLangFile().getMessages().getCommand().getNoPerm()));
ChatUtil.sendMessage(sender, getLangFile().getMessages().getCommand().getNoPerm()));
}

/**
* Setups config, lang and modules file file
*/
public void setupFiles() {
try {
this.configFile = ConfigManager.create(Config.class, (it) -> {
it.withConfigurer(new YamlBukkitConfigurer());
it.withBindFile(new File(getDataFolder(), "config.yml"));
it.saveDefaults();
it.load(true);
});
this.modulesFile = ConfigManager.create(Modules.class, (it) -> {
it.withConfigurer(new YamlBukkitConfigurer());
it.withBindFile(new File(getDataFolder(), "modules.yml"));
it.saveDefaults();
it.load(true);
});
String langName = configFile.getSettings().getLang();
// TODO MULTI LANG
// Class langClass = Class.forName("net.leaderos.plugin.bukkit.configuration.lang." + langName);
// Class<Language> languageClass = langClass;
this.langFile = ConfigManager.create(Language.class, (it) -> {
it.withConfigurer(new YamlBukkitConfigurer());
it.withBindFile(new File(getDataFolder() + "/lang", langName + ".yml"));
it.saveDefaults();
it.load(true);
});
} catch (Exception exception) {
getPluginLoader().disablePlugin(this);
throw new RuntimeException("Error loading config.yml");
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public class ModuleDisableEvent extends Event {

/**
* Bought farmer object
* Disabled module object
* @see Modulable
*/
@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public class ModuleEnableEvent extends Event {

/**
* Bought farmer object
* Enabled module
* @see Modulable
*/
@Getter
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package net.leaderos.plugin.api.handlers;


import lombok.Getter;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;

/**
* @author poyrazinan
* @since 1.0
*/
public class UpdateCacheEvent extends Event {

/**
* Player who made action to be updated
*/
@Getter
private final String playerName;

/**
* UpdateCacheEvent constructor
*
* @param playerName who required to update
*/
public UpdateCacheEvent(String playerName) {
this.playerName = playerName;
}

/**
* Spigot handlers requirements
* @see HandlerList
*/
private static final HandlerList HANDLERS = new HandlerList();

/**
* Spigot handlers requirement
* @return handler list
*/
@Override
public HandlerList getHandlers() {
return HANDLERS;
}

/**
* Spigot handlers requirement
* * @return handler list
* @return HandlerList list
*/
public static HandlerList getHandlerList() {
return HANDLERS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import net.leaderos.plugin.api.handlers.ModuleDisableEvent;
import net.leaderos.plugin.api.handlers.ModuleEnableEvent;
import net.leaderos.shared.configuration.Language;
import net.leaderos.plugin.configuration.Language;
import net.leaderos.plugin.Main;
import net.leaderos.shared.helpers.ChatUtil;
import net.leaderos.plugin.helpers.ChatUtil;
import net.leaderos.shared.module.Modulable;
import org.bukkit.Bukkit;

Expand Down Expand Up @@ -44,7 +44,7 @@ public void registerModule(Modulable module) {
* Enables all modules
*/
public void enableModules() {
Language lang = Main.getShared().getLangFile();
Language lang = Main.getInstance().getLangFile();
modules.keySet().forEach(moduleName -> {
Modulable module = getModule(moduleName);
// Checks if module has dependency
Expand Down Expand Up @@ -91,7 +91,7 @@ public void disableModules() {
// Disable event
Bukkit.getPluginManager().callEvent(new ModuleDisableEvent(module));
module.onDisable();
String message = Main.getShared().getLangFile().getMessages().getInfo().getModuleDisabled()
String message = Main.getInstance().getLangFile().getMessages().getInfo().getModuleDisabled()
.replace("%module_name%", module.getName());
ChatUtil.sendMessage(Bukkit.getConsoleSender(), message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import dev.triumphteam.cmd.core.annotation.SubCommand;
import lombok.RequiredArgsConstructor;
import net.leaderos.plugin.Main;
import net.leaderos.shared.helpers.ChatUtil;
import net.leaderos.plugin.helpers.ChatUtil;
import org.bukkit.command.CommandSender;

/**
Expand All @@ -25,7 +25,7 @@ public class LeaderOSCommand extends BaseCommand {
@Default
@Permission("leaderos.help")
public void defaultCommand(CommandSender sender) {
for (String message : Main.getShared().getLangFile().getMessages().getHelp()) {
for (String message : Main.getInstance().getLangFile().getMessages().getHelp()) {
ChatUtil.sendMessage(sender, message);
}
}
Expand All @@ -37,7 +37,7 @@ public void defaultCommand(CommandSender sender) {
@Permission("leaderos.reload")
@SubCommand("reload")
public void reloadCommand(CommandSender sender) {
Main.getShared().getConfigFile().load(true);
Main.getInstance().getConfigFile().load(true);
// TODO Reload
ChatUtil.sendMessage(sender, "{prefix} &aPlugin reloaded successfully.");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.leaderos.shared.configuration;
package net.leaderos.plugin.configuration;

import eu.okaeri.configs.OkaeriConfig;
import eu.okaeri.configs.annotation.Comment;
Expand Down
Loading

0 comments on commit 7105100

Please sign in to comment.