Files
src
build.gradle
Code
19 826
src/main/java/com/qolplugin/QoLPlugin.java
package com.qolplugin;
import com.qolplugin.commands.*;
import com.qolplugin.inventory.gui.GUIListener;
import com.qolplugin.inventory.gui.GUIManager;
import com.qolplugin.manager.PlaytimeManager;
import com.qolplugin.util.ColorUtil;
import net.kyori.adventure.text.Component;
import org.bukkit.plugin.java.JavaPlugin;
public class QoLPlugin extends JavaPlugin {
private static QoLPlugin instance;
private GUIManager guiManager;
private PlaytimeManager playtimeManager;
@Override
public void onEnable() {
instance = this;
saveDefaultConfig();
this.guiManager = new GUIManager();
this.playtimeManager = new PlaytimeManager(this);
getServer().getPluginManager().registerEvents(new GUIListener(guiManager), this);
registerCommands();
getLogger().info("QoLPlugin enabled!");
}
@Override
public void onDisable() {
}
private void registerCommands() {
getCommand("ping").setExecutor(new PingCommand());
getCommand("trash").setExecutor(new TrashCommand(guiManager));
getCommand("enderchest").setExecutor(new EnderchestCommand());
getCommand("playtime").setExecutor(new PlaytimeCommand(playtimeManager));
getCommand("grindstone").setExecutor(new WorkstationCommand("grindstone", "qol.grindstone",
p -> p.openGrindstone(null, true)));
getCommand("loom").setExecutor(new WorkstationCommand("loom", "qol.loom",
p -> p.openLoom(null, true)));
getCommand("stonecutter").setExecutor(new WorkstationCommand("stonecutter", "qol.stonecutter",
p -> p.openStonecutter(null, true)));
getCommand("cartographytable").setExecutor(new WorkstationCommand("cartographytable", "qol.cartography",
p -> p.openCartographyTable(null, true)));
getCommand("anvil").setExecutor(new WorkstationCommand("anvil", "qol.anvil",
p -> p.openAnvil(null, true)));
getCommand("smithingtable").setExecutor(new WorkstationCommand("smithingtable", "qol.smithing",
p -> p.openSmithingTable(null, true)));
getCommand("craft").setExecutor(new CraftCommand());
getCommand("qol").setExecutor(new ReloadCommand());
}
/**
* Format a message from config with MiniMessage and placeholder replacement.
* Placeholders are paired as key, value, key, value, ...
*/
public static Component formatMessage(String key, String... replacements) {
String message = instance.getConfig().getString("messages." + key, "");
String prefix = instance.getConfig().getString("messages.prefix", "");
message = message.replace("<prefix>", prefix);
for (int i = 0; i < replacements.length - 1; i += 2) {
message = message.replace(replacements[i], replacements[i + 1]);
}
return ColorUtil.colorize(message);
}
public static QoLPlugin getInstance() {
return instance;
}
public GUIManager getGuiManager() {
return guiManager;
}
public PlaytimeManager getPlaytimeManager() {
return playtimeManager;
}
}