Files
src
build.gradle
manifest.kod
Code
18 1,409
src/main/java/com/yugismp/yugicoins/YugiCoins.java
package com.yugismp.yugicoins;
import com.yugismp.yugicoins.command.CoinsAdminCommand;
import com.yugismp.yugicoins.command.CoinsCommand;
import com.yugismp.yugicoins.command.CoinShopCommand;
import com.yugismp.yugicoins.database.DatabaseManager;
import com.yugismp.yugicoins.inventory.gui.GUIListener;
import com.yugismp.yugicoins.inventory.gui.GUIManager;
import com.yugismp.yugicoins.manager.CoinManager;
import com.yugismp.yugicoins.placeholder.YugiCoinsExpansion;
import lombok.Getter;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Getter
public class YugiCoins extends JavaPlugin {
private DatabaseManager databaseManager;
private CoinManager coinManager;
private GUIManager guiManager;
private static final Pattern HEX_PATTERN = Pattern.compile("&#([A-Fa-f0-9]{6})");
@Override
public void onEnable() {
saveDefaultConfig();
this.databaseManager = new DatabaseManager(this);
this.databaseManager.initialize();
this.coinManager = new CoinManager(this);
this.guiManager = new GUIManager();
getCommand("coins").setExecutor(new CoinsCommand(this));
getCommand("coins").setTabCompleter(new CoinsCommand(this));
getCommand("coinsadmin").setExecutor(new CoinsAdminCommand(this));
getCommand("coinsadmin").setTabCompleter(new CoinsAdminCommand(this));
getCommand("coinshop").setExecutor(new CoinShopCommand(this));
Bukkit.getPluginManager().registerEvents(new GUIListener(guiManager), this);
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
new YugiCoinsExpansion(this).register();
getLogger().info("PlaceholderAPI hooked successfully!");
}
getLogger().info("YugiCoins has been enabled!");
}
@Override
public void onDisable() {
if (databaseManager != null) {
databaseManager.shutdown();
}
getLogger().info("YugiCoins has been disabled!");
}
public String getPrefix() {
return colorize(getConfig().getString("prefix", "�c1fe&lYugiSMP &8» "));
}
public String colorize(String message) {
if (message == null) return "";
Matcher matcher = HEX_PATTERN.matcher(message);
StringBuffer buffer = new StringBuffer(message.length() + 4 * 8);
while (matcher.find()) {
String group = matcher.group(1);
matcher.appendReplacement(buffer, ChatColor.of("#" + group).toString());
}
matcher.appendTail(buffer);
return ChatColor.translateAlternateColorCodes('&', buffer.toString());
}
}