Added custom craft
This commit is contained in:
@@ -11,14 +11,20 @@ public final class ArmorSMP extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
getLogger().info("Initializing PDK");
|
||||
PDK.init(this);
|
||||
|
||||
getLogger().info("Instantiating Plugin");
|
||||
instance = this;
|
||||
|
||||
getLogger().info("Initializing Manager");
|
||||
manager = new Manager().init();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
|
||||
manager.io.saveAll();
|
||||
getLogger().info("Saved all IO files.");
|
||||
}
|
||||
|
||||
public static ArmorSMP getInstance() {
|
||||
|
||||
31
src/main/java/me/trouper/armorsmp/data/ArmorTier.java
Normal file
31
src/main/java/me/trouper/armorsmp/data/ArmorTier.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package me.trouper.armorsmp.data;
|
||||
|
||||
public enum ArmorTier {
|
||||
NONE(0),
|
||||
LEATHER(1),
|
||||
CHAINMAIL(2),
|
||||
GOLD(3),
|
||||
IRON(4),
|
||||
DIAMOND(5);
|
||||
|
||||
private int numeric;
|
||||
|
||||
ArmorTier(int numeric) {
|
||||
this.numeric = numeric;
|
||||
}
|
||||
|
||||
public int getNumeric() {
|
||||
return numeric;
|
||||
}
|
||||
|
||||
public static ArmorTier getTier(int numeric) {
|
||||
for (ArmorTier value : values()) {
|
||||
if (value.getNumeric() == numeric) return value;
|
||||
if (value.getNumeric() < 1 ) return NONE;
|
||||
if (value.getNumeric() > 5) {
|
||||
return DIAMOND;
|
||||
}
|
||||
}
|
||||
return NONE;
|
||||
}
|
||||
}
|
||||
@@ -8,13 +8,17 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Config implements JsonSerializable<Config> {
|
||||
|
||||
|
||||
public boolean debugMode = false;
|
||||
|
||||
@Override
|
||||
public File getFile() {
|
||||
return ArmorSMP.getInstance().getManager().io.CONFIG_FILE;
|
||||
}
|
||||
|
||||
public boolean maceCraftingeEnabled = true;
|
||||
public boolean maceCraftingEnabled = true;
|
||||
public boolean netherEnabled = true;
|
||||
public boolean endEnabled = true;
|
||||
|
||||
public String mainColor = "�ff00";
|
||||
public String prefix = "&9ArmorSMP> &7";
|
||||
|
||||
@@ -4,7 +4,9 @@ import io.github.itzispyder.pdk.utils.misc.config.JsonSerializable;
|
||||
import me.trouper.armorsmp.ArmorSMP;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class Storage implements JsonSerializable<Storage> {
|
||||
@@ -18,5 +20,7 @@ public class Storage implements JsonSerializable<Storage> {
|
||||
|
||||
public class UserData {
|
||||
public Set<String> tipsDisabled = new HashSet<>();
|
||||
public Map<String, Integer> playerTiers = new HashMap<>();
|
||||
public Map<String, Set<String>> playerTrust = new HashMap<>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,38 @@
|
||||
package me.trouper.armorsmp.server;
|
||||
|
||||
import me.trouper.armorsmp.ArmorSMP;
|
||||
import me.trouper.armorsmp.data.IO;
|
||||
import me.trouper.armorsmp.server.commands.AdminCommand;
|
||||
import me.trouper.armorsmp.server.commands.TrustCommand;
|
||||
import me.trouper.armorsmp.server.crafting.ArmorUpgrade;
|
||||
import me.trouper.armorsmp.server.events.CraftEvent;
|
||||
import me.trouper.armorsmp.server.functions.ArmorBackend;
|
||||
|
||||
public class Manager {
|
||||
// My systems
|
||||
public IO io;
|
||||
public ArmorBackend armor;
|
||||
|
||||
// Commands
|
||||
public AdminCommand adminCommand;
|
||||
public TrustCommand trustCommand;
|
||||
|
||||
// Events
|
||||
public CraftEvent craftEvent;
|
||||
|
||||
public Manager() {
|
||||
io = new IO();
|
||||
io = new IO(); // IO must come as the first.
|
||||
armor = new ArmorBackend();
|
||||
|
||||
adminCommand = new AdminCommand();
|
||||
trustCommand = new TrustCommand();
|
||||
craftEvent = new CraftEvent();
|
||||
}
|
||||
|
||||
public Manager init() {
|
||||
ArmorSMP.getInstance().getLogger().info("Loading all IO Files");
|
||||
io.loadAll();
|
||||
|
||||
registerCommands();
|
||||
registerEvents();
|
||||
registerCrafting();
|
||||
@@ -18,16 +40,23 @@ public class Manager {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
private void registerEvents() {
|
||||
|
||||
ArmorSMP.getInstance().getLogger().info("Registering Events");
|
||||
craftEvent.register();
|
||||
}
|
||||
|
||||
private void registerCommands() {
|
||||
|
||||
ArmorSMP.getInstance().getLogger().info("Registering Commands");
|
||||
adminCommand.register();
|
||||
trustCommand.register();
|
||||
}
|
||||
|
||||
private void registerCrafting() {
|
||||
ArmorSMP.getInstance().getLogger().info("Repairing Crafts");
|
||||
ArmorUpgrade.removeRecipe();
|
||||
|
||||
ArmorUpgrade.addRecipe();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,22 +11,21 @@ import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandRegistry(value = "armorsmp_give", permission = @Permission("armorsmp.give"))
|
||||
public class GiveCommand implements CustomCommand {
|
||||
@CommandRegistry(value = "armorsmp", permission = @Permission("op"), printStackTrace = true)
|
||||
public class AdminCommand implements CustomCommand {
|
||||
|
||||
@Override
|
||||
public void dispatchCommand(CommandSender commandSender, Command command, String label, Args args) {
|
||||
String target = args.get(0).toString();
|
||||
Player t = Bukkit.getPlayer(target);
|
||||
if (t == null) {
|
||||
Text.sendError((Player) commandSender);
|
||||
return;
|
||||
public void dispatchCommand(CommandSender sender, Command command, String label, Args args) {
|
||||
if (args.getSize() < 1) {
|
||||
Text.sendError(sender, "Error: Valid sub-commands are: [change, give, toggle, reset, remove]");
|
||||
}
|
||||
switch (label) {
|
||||
case "neth_axe" -> {
|
||||
case "change" -> {
|
||||
|
||||
}
|
||||
|
||||
default -> {
|
||||
Text.sendError(sender, "Error: Valid sub-commands are: [change, give, toggle, reset, remove]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import io.github.itzispyder.pdk.commands.completions.CompletionBuilder;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class MaceToggleCommand implements CustomCommand {
|
||||
public class TrustCommand implements CustomCommand {
|
||||
@Override
|
||||
public void dispatchCommand(CommandSender commandSender, Command command, String s, Args args) {
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package me.trouper.armorsmp.server.crafting;
|
||||
|
||||
import io.github.itzispyder.pdk.plugin.builders.ItemBuilder;
|
||||
import me.trouper.armorsmp.ArmorSMP;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.ShapedRecipe;
|
||||
|
||||
public class ArmorUpgrade {
|
||||
public static final ItemStack ARMOR_UGPRADE = ItemBuilder.create()
|
||||
.material(Material.NETHER_STAR)
|
||||
.name("§b§lArmor Upgrade")
|
||||
.lore("§9| §3Right click to upgrade your gear")
|
||||
.count(1)
|
||||
.customModelData(1)
|
||||
.build();
|
||||
|
||||
public static final NamespacedKey KEY = new NamespacedKey(ArmorSMP.getInstance(), "armor_upgrade_recipe");
|
||||
|
||||
public static ShapedRecipe recipe = new ShapedRecipe(KEY, ARMOR_UGPRADE);
|
||||
|
||||
public static void addRecipe() {
|
||||
recipe.shape("ABC", "DEF", "GHI");
|
||||
|
||||
recipe.setIngredient('A', Material.DIAMOND_BLOCK);
|
||||
recipe.setIngredient('B', Material.DIAMOND_BLOCK);
|
||||
recipe.setIngredient('C', Material.DIAMOND_BLOCK);
|
||||
|
||||
recipe.setIngredient('D', Material.OMINOUS_TRIAL_KEY);
|
||||
recipe.setIngredient('E', Material.ENCHANTED_GOLDEN_APPLE);
|
||||
recipe.setIngredient('F', Material.OMINOUS_TRIAL_KEY);
|
||||
|
||||
recipe.setIngredient('G', Material.DIAMOND_BLOCK);
|
||||
recipe.setIngredient('H', Material.DIAMOND_BLOCK);
|
||||
recipe.setIngredient('I', Material.DIAMOND_BLOCK);
|
||||
|
||||
ArmorSMP.getInstance().getServer().addRecipe(recipe);
|
||||
}
|
||||
|
||||
public static void removeRecipe() {
|
||||
ArmorSMP.getInstance().getServer().removeRecipe(KEY);
|
||||
}
|
||||
}
|
||||
@@ -19,11 +19,11 @@ public class CraftEvent implements CustomListener {
|
||||
&& !name.contains("CHESTPLATE")
|
||||
&& !name.contains("LEGGINGS")
|
||||
&& !name.contains("BOOTS")
|
||||
&& !name.contains("NETHERITE_AXE")
|
||||
&& !name.contains("NETHERITE_SWORD")
|
||||
&& !name.contains("NETHERITE_PICKAXE")
|
||||
&& !name.contains("NETHERITE_AXE")
|
||||
&& !name.contains("NETHERITE_SHOVEL")
|
||||
&& !name.contains("NETHERITE_HOE")
|
||||
&& !name.contains("NETHERITE_PICKAXE")
|
||||
) return;
|
||||
|
||||
e.setCancelled(true);
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package me.trouper.armorsmp.server.functions;
|
||||
|
||||
import me.trouper.armorsmp.ArmorSMP;
|
||||
import me.trouper.armorsmp.data.ArmorTier;
|
||||
import me.trouper.armorsmp.data.Storage;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class ArmorBackend {
|
||||
|
||||
private final Storage storage;
|
||||
|
||||
public ArmorBackend() {
|
||||
storage = ArmorSMP.getInstance().getManager().io.storage;
|
||||
}
|
||||
|
||||
public void setTier(Player target, ArmorTier tier) {
|
||||
storage.userData.playerTiers.put(target.getUniqueId().toString(),tier.getNumeric());
|
||||
storage.save();
|
||||
}
|
||||
|
||||
public void setTier(Player target, int tier) {
|
||||
setTier(target,ArmorTier.getTier(tier));
|
||||
}
|
||||
|
||||
public void downTier(Player target) {
|
||||
int numeric = storage.userData.playerTiers.get(target.getUniqueId().toString());
|
||||
setTier(target,ArmorTier.getTier(numeric - 1));
|
||||
}
|
||||
|
||||
public void upTier(Player target) {
|
||||
int numeric = storage.userData.playerTiers.get(target.getUniqueId().toString());
|
||||
setTier(target,ArmorTier.getTier(numeric + 1));
|
||||
}
|
||||
|
||||
public ArmorTier getTier(Player target) {
|
||||
int numeric = storage.userData.playerTiers.get(target.getUniqueId().toString());
|
||||
for (ArmorTier value : ArmorTier.values()) {
|
||||
if (value.getNumeric() == numeric) return value;
|
||||
if (value.getNumeric() > 5) {
|
||||
ArmorSMP.getInstance().getLogger().warning("Detected a player above tier 5 (diamond) this should not be possible. Setting them back to diamond.");
|
||||
setTier(target,ArmorTier.DIAMOND);
|
||||
return ArmorTier.DIAMOND;
|
||||
}
|
||||
}
|
||||
return ArmorTier.NONE;
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
@@ -23,33 +24,39 @@ public class Text {
|
||||
public static Component color(String msg) {
|
||||
return LegacyComponentSerializer.legacyAmpersand().deserialize(msg);
|
||||
}
|
||||
|
||||
public static void sendWarning(Player player,String warning, Object... args) {
|
||||
sendMessage(Pallet.WARNING,player,warning,false,args);
|
||||
}
|
||||
|
||||
public static void sendError(Player player, String error, Object... args) {
|
||||
sendMessage(Pallet.ERROR,player,error,false,args);
|
||||
|
||||
public static void sendWarning(CommandSender sender, String warning, Object... args) {
|
||||
sendMessage(Pallet.WARNING, sender, warning, false, args);
|
||||
}
|
||||
|
||||
public static void sendMessage(Player player, String text, boolean allowTip, Object... args) {
|
||||
sendMessage(Pallet.NEUTRAL,player,text,allowTip,args);
|
||||
public static void sendError(CommandSender sender, String error, Object... args) {
|
||||
sendMessage(Pallet.ERROR, sender, error, false, args);
|
||||
}
|
||||
|
||||
public static void sendMessage(Pallet pallet, Player player, String text, boolean allowTip, Object... args) {
|
||||
text = formatArgs(pallet,text,args);
|
||||
sendMessage(player,text,allowTip);
|
||||
public static void sendMessage(CommandSender sender, String text, boolean allowTip, Object... args) {
|
||||
sendMessage(Pallet.NEUTRAL, sender, text, allowTip, args);
|
||||
}
|
||||
|
||||
public static void sendMessage(Player player, String text, boolean allowTip) {
|
||||
allowTip = allowTip && ArmorSMP.getInstance().getManager().io.config.tips.tipsEnabled && !ArmorSMP.getInstance().getManager().io.storage.userData.tipsDisabled.contains(player.getUniqueId().toString());
|
||||
Component message = getMessage(text,allowTip);
|
||||
player.sendMessage(message);
|
||||
public static void sendMessage(Pallet pallet, CommandSender sender, String text, boolean allowTip, Object... args) {
|
||||
text = formatArgs(pallet, text, args);
|
||||
sendMessage(sender, text, allowTip);
|
||||
}
|
||||
|
||||
public static void sendMessage(CommandSender sender, String text, boolean allowTip) {
|
||||
if (sender instanceof Player player) {
|
||||
allowTip = allowTip
|
||||
&& ArmorSMP.getInstance().getManager().io.config.tips.tipsEnabled
|
||||
&& !ArmorSMP.getInstance().getManager().io.storage.userData.tipsDisabled.contains(player.getUniqueId().toString());
|
||||
} else {
|
||||
allowTip = false;
|
||||
}
|
||||
Component message = getMessage(text, allowTip);
|
||||
sender.sendMessage(message);
|
||||
}
|
||||
|
||||
public static Component getMessage(String text, boolean addFancyTip) {
|
||||
if (ArmorSMP.getInstance().getManager().io.config.fancyAlerts) {
|
||||
return formatFancyMessage(text,addFancyTip);
|
||||
return formatFancyMessage(text, addFancyTip);
|
||||
} else {
|
||||
return color(ArmorSMP.getInstance().getManager().io.config.prefix + text);
|
||||
}
|
||||
@@ -88,7 +95,7 @@ public class Text {
|
||||
return LegacyComponentSerializer.legacyAmpersand().serialize(message);
|
||||
}
|
||||
|
||||
public static Component formatFancyMessage(String text,boolean addTip) {
|
||||
public static Component formatFancyMessage(String text, boolean addTip) {
|
||||
Component message = Component.empty().appendNewline();
|
||||
|
||||
if (addTip) {
|
||||
|
||||
70
src/main/java/me/trouper/armorsmp/utils/Verbose.java
Normal file
70
src/main/java/me/trouper/armorsmp/utils/Verbose.java
Normal file
@@ -0,0 +1,70 @@
|
||||
package me.trouper.armorsmp.utils;
|
||||
|
||||
import me.trouper.armorsmp.ArmorSMP;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Verbose {
|
||||
|
||||
public static void send(int backtrace, String message, Object... args) {
|
||||
if (!ArmorSMP.getInstance().getManager().io.config.debugMode) return;
|
||||
String callerInfo = "Unknown Caller";
|
||||
|
||||
// Capture the stack trace to determine the caller
|
||||
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
|
||||
if (stackTrace.length > 2 + backtrace) { // Ensure we have enough depth
|
||||
StackTraceElement caller = stackTrace[2 + backtrace]; // The method that called `verbose()`
|
||||
|
||||
String className = caller.getClassName();
|
||||
className = className.substring(className.lastIndexOf(".") + 1);
|
||||
if (className.contains("-")) {
|
||||
callerInfo = "Protected";
|
||||
} else {
|
||||
callerInfo = className + "." + caller.getMethodName();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
String formattedMessage = message.formatted(args);
|
||||
String log = "[Sentinel] [DEBUG ^ %s] [%s]: %s".formatted(backtrace, callerInfo, formattedMessage);
|
||||
ArmorSMP.getInstance().getLogger().info(log);
|
||||
|
||||
for (Player operator : Bukkit.getOnlinePlayers()) {
|
||||
if (operator.isOp()) operator.sendMessage("§d§lSentinel §7[§bDEBUG ^ %s§7] §7[§e%s§7] §8» §7%s"
|
||||
.formatted(backtrace, callerInfo, formattedMessage));
|
||||
}
|
||||
}
|
||||
|
||||
public static void send(String message, Object... args) {
|
||||
if (!ArmorSMP.getInstance().getManager().io.config.debugMode) return;
|
||||
String callerInfo = "Unknown Caller";
|
||||
|
||||
// Capture the stack trace to determine the caller
|
||||
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
|
||||
if (stackTrace.length > 2) { // Ensure we have enough depth
|
||||
StackTraceElement caller = stackTrace[2]; // The method that called `verbose()`
|
||||
|
||||
String className = caller.getClassName();
|
||||
className = className.substring(className.lastIndexOf(".") + 1);
|
||||
if (className.contains("-")) {
|
||||
callerInfo = "Protected";
|
||||
} else {
|
||||
callerInfo = className + "." + caller.getMethodName();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
String formattedMessage = message.formatted(args);
|
||||
String log = "[Sentinel] [DEBUG] [%s]: %s".formatted(callerInfo, formattedMessage);
|
||||
ArmorSMP.getInstance().getLogger().info(log);
|
||||
|
||||
for (Player operator : Bukkit.getOnlinePlayers()) {
|
||||
if (operator.isOp()) operator.sendMessage("§d§lSentinel §7[§bDEBUG§7] §7[§e%s§7] §8» §7%s"
|
||||
.formatted(callerInfo, formattedMessage));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,3 +6,16 @@ prefix: ArmorSMP
|
||||
load: STARTUP
|
||||
authors: [ obvWolf ]
|
||||
description: Kill Based Armor Upgrading
|
||||
commands:
|
||||
trust:
|
||||
description: Make your friends immune to your abilities.
|
||||
usage: "<add|remove|list> <target>"
|
||||
aliases:
|
||||
- t
|
||||
armorsmp:
|
||||
permission: op
|
||||
description: Root command for giving items, everything is handled though alias labels.
|
||||
usage: "/asmp usage"
|
||||
aliases:
|
||||
- asmp
|
||||
- armor_smp
|
||||
Reference in New Issue
Block a user