Cleaned up command api

This commit is contained in:
Indyuce 2022-12-29 15:00:34 +01:00
parent ab85dd688b
commit 35d90ae55b
35 changed files with 336 additions and 228 deletions

View File

@ -4,6 +4,7 @@ import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.UtilityMethods;
import io.lumine.mythic.lib.version.SpigotPlugin;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.command.api.ToggleableCommand;
import net.Indyuce.mmocore.manager.social.PartyManager;
import net.Indyuce.mmocore.api.ConfigFile;
import net.Indyuce.mmocore.manager.ActionBarManager;
@ -250,45 +251,10 @@ public class MMOCore extends JavaPlugin {
// load guild data after loading player data
dataProvider.getGuildManager().load();
// Command
try {
final Field bukkitCommandMap = Bukkit.getServer().getClass().getDeclaredField("commandMap");
bukkitCommandMap.setAccessible(true);
CommandMap commandMap = (CommandMap) bukkitCommandMap.get(Bukkit.getServer());
FileConfiguration config = new ConfigFile("commands").getConfig();
if (config.contains("player"))
commandMap.register("mmocore", new PlayerStatsCommand(config.getConfigurationSection("player")));
if (config.contains("attributes"))
commandMap.register("mmocore", new AttributesCommand(config.getConfigurationSection("attributes")));
if (config.contains("class"))
commandMap.register("mmocore", new ClassCommand(config.getConfigurationSection("class")));
if (config.contains("waypoints"))
commandMap.register("mmocore", new WaypointsCommand(config.getConfigurationSection("waypoints")));
if (config.contains("quests"))
commandMap.register("mmocore", new QuestsCommand(config.getConfigurationSection("quests")));
if (config.contains("skills"))
commandMap.register("mmocore", new SkillsCommand(config.getConfigurationSection("skills")));
if (config.contains("friends"))
commandMap.register("mmocore", new FriendsCommand(config.getConfigurationSection("friends")));
if (config.contains("party"))
commandMap.register("mmocore", new PartyCommand(config.getConfigurationSection("party")));
if (config.contains("guild"))
commandMap.register("mmocore", new GuildCommand(config.getConfigurationSection("guild")));
if (config.contains("skill-trees"))
commandMap.register("mmocore", new SkillTreeCommand(config.getConfigurationSection("skill-trees")));
if (hasEconomy() && economy.isValid()) {
if (config.contains("withdraw"))
commandMap.register("mmocore", new WithdrawCommand(config.getConfigurationSection("withdraw")));
if (config.contains("deposit"))
commandMap.register("mmocore", new DepositCommand(config.getConfigurationSection("deposit")));
}
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException ex) {
ex.printStackTrace();
}
// Toggleable Commands
ToggleableCommand.register();
// Register MMOCore command what soever
MMOCoreCommandTreeRoot mmoCoreCommand = new MMOCoreCommandTreeRoot();
getCommand("mmocore").setExecutor(mmoCoreCommand);
getCommand("mmocore").setTabCompleter(mmoCoreCommand);

View File

@ -125,7 +125,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
private final Map<String, Integer> tableItemClaims = new HashMap<>();
// NON-FINAL player data stuff made public to facilitate field change
public boolean noCooldown, statsLoaded;
public boolean noCooldown, statsLoaded, pvpMode;
public CombatRunnable combat;
/**

View File

@ -1,21 +1,19 @@
package net.Indyuce.mmocore.command;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.command.api.RegisteredCommand;
import net.Indyuce.mmocore.command.api.ToggleableCommand;
import net.Indyuce.mmocore.manager.InventoryManager;
import net.Indyuce.mmocore.api.event.MMOCommandEvent;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
public class AttributesCommand extends BukkitCommand {
public class AttributesCommand extends RegisteredCommand {
public AttributesCommand(ConfigurationSection config) {
super(config.getString("main"));
setAliases(config.getStringList("aliases"));
setDescription("Opens the attribute menu.");
super(config, ToggleableCommand.ATTRIBUTES);
}
@Override

View File

@ -1,21 +1,19 @@
package net.Indyuce.mmocore.command;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.command.api.RegisteredCommand;
import net.Indyuce.mmocore.command.api.ToggleableCommand;
import net.Indyuce.mmocore.manager.InventoryManager;
import net.Indyuce.mmocore.api.event.MMOCommandEvent;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
public class ClassCommand extends BukkitCommand {
public class ClassCommand extends RegisteredCommand {
public ClassCommand(ConfigurationSection config) {
super(config.getString("main"));
setAliases(config.getStringList("aliases"));
setDescription("Select a new class.");
super(config, ToggleableCommand.CLASS);
}
@Override

View File

@ -1,19 +1,17 @@
package net.Indyuce.mmocore.command;
import net.Indyuce.mmocore.command.api.RegisteredCommand;
import net.Indyuce.mmocore.command.api.ToggleableCommand;
import net.Indyuce.mmocore.gui.eco.DepositMenu;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
public class DepositCommand extends BukkitCommand {
public class DepositCommand extends RegisteredCommand {
public DepositCommand(ConfigurationSection config) {
super(config.getString("main"));
setAliases(config.getStringList("aliases"));
setDescription("Opens the currency deposit menu.");
super(config, ToggleableCommand.DEPOSIT);
}
@Override

View File

@ -3,6 +3,8 @@ package net.Indyuce.mmocore.command;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.social.FriendRequest;
import net.Indyuce.mmocore.command.api.RegisteredCommand;
import net.Indyuce.mmocore.command.api.ToggleableCommand;
import net.Indyuce.mmocore.manager.InventoryManager;
import net.Indyuce.mmocore.api.event.MMOCommandEvent;
import net.Indyuce.mmocore.api.player.social.Request;
@ -10,19 +12,15 @@ import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable;
import java.util.UUID;
public class FriendsCommand extends BukkitCommand {
public class FriendsCommand extends RegisteredCommand {
public FriendsCommand(ConfigurationSection config) {
super(config.getString("main"));
setAliases(config.getStringList("aliases"));
setDescription("Opens the friends menu.");
super(config, ToggleableCommand.FRIENDS);
}
@Override

View File

@ -2,6 +2,8 @@ package net.Indyuce.mmocore.command;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.command.api.RegisteredCommand;
import net.Indyuce.mmocore.command.api.ToggleableCommand;
import net.Indyuce.mmocore.manager.InventoryManager;
import net.Indyuce.mmocore.api.event.MMOCommandEvent;
import net.Indyuce.mmocore.api.player.social.Request;
@ -11,20 +13,15 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable;
import java.util.UUID;
public class GuildCommand extends BukkitCommand {
public class GuildCommand extends RegisteredCommand {
public GuildCommand(ConfigurationSection config) {
super(config.getString("main"));
setAliases(config.getStringList("aliases"));
setDescription("Opens the guilds menu.");
super(config, ToggleableCommand.GUILD);
}
@Override

View File

@ -2,6 +2,8 @@ package net.Indyuce.mmocore.command;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.command.api.RegisteredCommand;
import net.Indyuce.mmocore.command.api.ToggleableCommand;
import net.Indyuce.mmocore.manager.InventoryManager;
import net.Indyuce.mmocore.api.event.MMOCommandEvent;
import net.Indyuce.mmocore.api.player.social.Request;
@ -12,20 +14,15 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable;
import java.util.UUID;
public class PartyCommand extends BukkitCommand {
public class PartyCommand extends RegisteredCommand {
public PartyCommand(ConfigurationSection config) {
super(config.getString("main"));
setAliases(config.getStringList("aliases"));
setDescription("Opens the party menu.");
super(config, ToggleableCommand.PARTY);
}
@Override

View File

@ -1,34 +1,32 @@
package net.Indyuce.mmocore.command;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.manager.InventoryManager;
import net.Indyuce.mmocore.api.event.MMOCommandEvent;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.command.api.RegisteredCommand;
import net.Indyuce.mmocore.command.api.ToggleableCommand;
import net.Indyuce.mmocore.manager.InventoryManager;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
public class PlayerStatsCommand extends BukkitCommand {
public PlayerStatsCommand(ConfigurationSection config) {
super(config.getString("main"));
setAliases(config.getStringList("aliases"));
setDescription("Show player stats.");
}
public class PlayerStatsCommand extends RegisteredCommand {
public PlayerStatsCommand(ConfigurationSection config) {
super(config, ToggleableCommand.PLAYER);
}
@Override
public boolean execute(CommandSender sender, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "This command is for players only.");
return true;
}
PlayerData data = PlayerData.get((Player) sender);
MMOCommandEvent event = new MMOCommandEvent(data, "profile");
Bukkit.getServer().getPluginManager().callEvent(event);
if(!event.isCancelled()) InventoryManager.PLAYER_STATS.newInventory(data).open();
return true;
}
@Override
public boolean execute(CommandSender sender, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "This command is for players only.");
return true;
}
PlayerData data = PlayerData.get((Player) sender);
MMOCommandEvent event = new MMOCommandEvent(data, "profile");
Bukkit.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) InventoryManager.PLAYER_STATS.newInventory(data).open();
return true;
}
}

View File

@ -0,0 +1,76 @@
package net.Indyuce.mmocore.command;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.event.MMOCommandEvent;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.social.Request;
import net.Indyuce.mmocore.command.api.RegisteredCommand;
import net.Indyuce.mmocore.command.api.ToggleableCommand;
import net.Indyuce.mmocore.guild.provided.GuildInvite;
import net.Indyuce.mmocore.manager.InventoryManager;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable;
import java.util.UUID;
public class PvpModeCommand extends RegisteredCommand {
public PvpModeCommand(ConfigurationSection config) {
super(config, ToggleableCommand.PVP_MODE);
}
@Override
public boolean execute(CommandSender sender, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "This command is for players only.");
return true;
}
PlayerData data = PlayerData.get((OfflinePlayer) sender);
MMOCommandEvent event = new MMOCommandEvent(data, "guild");
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) return true;
if (args.length > 1) {
final @Nullable GuildInvite invite;
if (args.length > 1)
// Search by request ID
try {
final UUID uuid = UUID.fromString(args[1]);
final Request req = MMOCore.plugin.requestManager.getRequest(uuid);
Validate.isTrue(!req.isTimedOut() && req instanceof GuildInvite);
invite = (GuildInvite) req;
Validate.isTrue(MMOCore.plugin.dataProvider.getGuildManager().isRegistered(invite.getGuild()));
} catch (Exception exception) {
return true;
}
// Search by target player
else
invite = MMOCore.plugin.requestManager.findRequest(data, GuildInvite.class);
// No invite found with given identifier/target player
if (invite == null)
return true;
if (args[0].equalsIgnoreCase("accept"))
invite.accept();
if (args[0].equalsIgnoreCase("deny"))
invite.deny();
return true;
}
if (data.inGuild())
InventoryManager.GUILD_VIEW.newInventory(data).open();
else
InventoryManager.GUILD_CREATION.newInventory(data).open();
return true;
}
}

View File

@ -1,20 +1,18 @@
package net.Indyuce.mmocore.command;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.command.api.RegisteredCommand;
import net.Indyuce.mmocore.command.api.ToggleableCommand;
import net.Indyuce.mmocore.manager.InventoryManager;
import net.Indyuce.mmocore.api.event.MMOCommandEvent;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
public class QuestsCommand extends BukkitCommand {
public class QuestsCommand extends RegisteredCommand {
public QuestsCommand(ConfigurationSection config) {
super(config.getString("main"));
setAliases(config.getStringList("aliases"));
setDescription("Opens the quests menu.");
super(config, ToggleableCommand.QUESTS);
}
@Override

View File

@ -1,23 +1,20 @@
package net.Indyuce.mmocore.command;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.ConfigMessage;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.event.MMOCommandEvent;
import net.Indyuce.mmocore.command.api.RegisteredCommand;
import net.Indyuce.mmocore.command.api.ToggleableCommand;
import net.Indyuce.mmocore.manager.InventoryManager;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class SkillTreeCommand extends BukkitCommand {
public SkillTreeCommand(ConfigurationSection config) {
super(config.getString("main"));
setAliases(config.getStringList("aliases"));
setDescription("Opens the skills menu.");
public class SkillTreesCommand extends RegisteredCommand {
public SkillTreesCommand(ConfigurationSection config) {
super(config, ToggleableCommand.SKILL_TREES);
}
@Override
@ -37,8 +34,5 @@ public class SkillTreeCommand extends BukkitCommand {
MMOCore.plugin.configManager.getSimpleMessage("no-skill-tree").send(player);
return true;
}
}
}

View File

@ -2,20 +2,18 @@ package net.Indyuce.mmocore.command;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.command.api.RegisteredCommand;
import net.Indyuce.mmocore.command.api.ToggleableCommand;
import net.Indyuce.mmocore.manager.InventoryManager;
import net.Indyuce.mmocore.api.event.MMOCommandEvent;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
public class SkillsCommand extends BukkitCommand {
public class SkillsCommand extends RegisteredCommand {
public SkillsCommand(ConfigurationSection config) {
super(config.getString("main"));
setAliases(config.getStringList("aliases"));
setDescription("Opens the skills menu.");
super(config, ToggleableCommand.SKILLS);
}
@Override

View File

@ -1,20 +1,18 @@
package net.Indyuce.mmocore.command;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.command.api.RegisteredCommand;
import net.Indyuce.mmocore.command.api.ToggleableCommand;
import net.Indyuce.mmocore.manager.InventoryManager;
import net.Indyuce.mmocore.api.event.MMOCommandEvent;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
public class WaypointsCommand extends BukkitCommand {
public class WaypointsCommand extends RegisteredCommand {
public WaypointsCommand(ConfigurationSection config) {
super(config.getString("main"));
setAliases(config.getStringList("aliases"));
setDescription("Open the waypoints menu.");
super(config, ToggleableCommand.WAYPOINTS);
}
@Override

View File

@ -1,23 +1,21 @@
package net.Indyuce.mmocore.command;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.command.api.RegisteredCommand;
import net.Indyuce.mmocore.command.api.ToggleableCommand;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Sound;
import org.bukkit.command.CommandSender;
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import net.Indyuce.mmocore.api.eco.Withdraw;
public class WithdrawCommand extends BukkitCommand {
public class WithdrawCommand extends RegisteredCommand {
public WithdrawCommand(ConfigurationSection config) {
super(config.getString("main"));
setAliases(config.getStringList("aliases"));
setDescription("Creates a withdraw request.");
super(config, ToggleableCommand.WITHDRAW);
}
@Override

View File

@ -1,4 +1,4 @@
package net.Indyuce.mmocore.command;
package net.Indyuce.mmocore.command.api;
import io.lumine.mythic.lib.UtilityMethods;
import net.Indyuce.mmocore.MMOCore;

View File

@ -0,0 +1,14 @@
package net.Indyuce.mmocore.command.api;
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.configuration.ConfigurationSection;
import org.jetbrains.annotations.NotNull;
public abstract class RegisteredCommand extends BukkitCommand {
public RegisteredCommand(@NotNull ConfigurationSection config, ToggleableCommand command) {
super(config.getString("main"));
setAliases(config.getStringList("aliases"));
setDescription(config.getString("description", command.getDescription()));
}
}

View File

@ -0,0 +1,112 @@
package net.Indyuce.mmocore.command.api;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.ConfigFile;
import net.Indyuce.mmocore.command.*;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandMap;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.logging.Level;
/**
* Commands which can be disabled using commands.yml
*/
public enum ToggleableCommand {
PLAYER("player", "Displays player stats", config -> new PlayerStatsCommand(config), "p", "profile"),
ATTRIBUTES("attributes", "Display and manage attributes", config -> new AttributesCommand(config), "att", "stats"),
CLASS("class", "Select a new class", config -> new ClassCommand(config), "c"),
WAYPOINTS("waypoints", "Display discovered waypoints", config -> new WaypointsCommand(config), "wp"),
QUESTS("quests", "Display available quests", config -> new QuestsCommand(config), "q", "journal"),
SKILLS("skills", "Spend skill points to unlock new skills", config -> new SkillsCommand(config), "s"),
FRIENDS("friends", "Show online/offline friends", config -> new FriendsCommand(config), "f"),
PARTY("party", "Invite players in a party to split exp", config -> new PartyCommand(config)),
GUILD("guild", "Show players in current guild", config -> new GuildCommand(config)),
WITHDRAW("withdraw", "Withdraw money into coins and notes", config -> new WithdrawCommand(config), v -> MMOCore.plugin.hasEconomy() && MMOCore.plugin.economy.isValid(), "w"),
SKILL_TREES("skiltrees", "Open up the skill tree menu", config -> new SkillTreesCommand(config), "st", "trees", "tree"),
DEPOSIT("deposit", "Open the currency deposit menu", config -> new DepositCommand(config), "d"),
PVP_MODE("pvpmode", "Toggle on/off PVP mode.", config -> new PvpModeCommand(config), "pvp");
private final String mainLabel;
private final String description;
private final Function<ConfigurationSection, RegisteredCommand> generator;
private final List<String> aliases;
private final Predicate<Void> enabled;
ToggleableCommand(@NotNull String mainLabel, @NotNull String description, @NotNull Function<ConfigurationSection, RegisteredCommand> generator, @NotNull String... aliases) {
this(mainLabel, description, generator, null, aliases);
}
ToggleableCommand(@NotNull String mainLabel, @NotNull String description, @NotNull Function<ConfigurationSection, RegisteredCommand> generator, @Nullable Predicate<Void> enabled, @NotNull String... aliases) {
this.mainLabel = mainLabel;
this.description = description;
this.generator = generator;
this.aliases = Arrays.asList(aliases);
this.enabled = enabled == null ? v -> true : enabled;
}
public String getMainLabel() {
return mainLabel;
}
public String getDescription() {
return description;
}
public List<String> getAliases() {
return aliases;
}
public String getConfigPath() {
return name().toLowerCase().replace("_", "-");
}
public boolean isEnabled() {
return enabled.test(null);
}
public static void register() {
// Load default config file
if (!new File(MMOCore.plugin.getDataFolder(), "commands.yml").exists()) {
final ConfigFile config = new ConfigFile("commands");
for (ToggleableCommand cmd : values()) {
final String path = cmd.getConfigPath();
config.getConfig().set(path + ".main", cmd.mainLabel);
config.getConfig().set(path + ".aliases", cmd.aliases);
config.getConfig().set(path + ".description", cmd.description);
}
config.save();
}
try {
// Find command map
final Field commandMapField = Bukkit.getServer().getClass().getDeclaredField("commandMap");
commandMapField.setAccessible(true);
final CommandMap commandMap = (CommandMap) commandMapField.get(Bukkit.getServer());
// Enable commands individually
final FileConfiguration config = new ConfigFile("commands").getConfig();
for (ToggleableCommand cmd : values())
if (cmd.isEnabled() && config.contains(cmd.getConfigPath()))
commandMap.register("mmocore", cmd.generator.apply(config.getConfigurationSection(cmd.getConfigPath())));
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING, "Unable to register custom commands:");
exception.printStackTrace();
}
}
}

View File

@ -4,7 +4,7 @@ import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute;
import net.Indyuce.mmocore.api.player.attribute.PlayerAttributes;
import net.Indyuce.mmocore.command.CommandVerbose;
import net.Indyuce.mmocore.command.api.CommandVerbose;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;

View File

@ -11,7 +11,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import net.Indyuce.mmocore.api.player.profess.SavedClassInformation;
import net.Indyuce.mmocore.command.CommandVerbose;
import net.Indyuce.mmocore.command.api.CommandVerbose;
import io.lumine.mythic.lib.command.api.CommandTreeNode;
import io.lumine.mythic.lib.command.api.Parameter;

View File

@ -8,7 +8,7 @@ import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.experience.EXPSource;
import net.Indyuce.mmocore.experience.PlayerProfessions;
import net.Indyuce.mmocore.experience.Profession;
import net.Indyuce.mmocore.command.CommandVerbose;
import net.Indyuce.mmocore.command.api.CommandVerbose;
import net.Indyuce.mmocore.command.MMOCoreCommandTreeRoot;
import net.Indyuce.mmocore.util.TriConsumer;
import org.apache.commons.lang.Validate;

View File

@ -3,7 +3,7 @@ package net.Indyuce.mmocore.command.rpg.admin;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.profess.PlayerClass;
import net.Indyuce.mmocore.command.CommandVerbose;
import net.Indyuce.mmocore.command.api.CommandVerbose;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;

View File

@ -7,7 +7,7 @@ import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.experience.EXPSource;
import net.Indyuce.mmocore.experience.PlayerProfessions;
import net.Indyuce.mmocore.experience.Profession;
import net.Indyuce.mmocore.command.CommandVerbose;
import net.Indyuce.mmocore.command.api.CommandVerbose;
import net.Indyuce.mmocore.util.TriConsumer;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;

View File

@ -1,7 +1,7 @@
package net.Indyuce.mmocore.command.rpg.admin;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.command.CommandVerbose;
import net.Indyuce.mmocore.command.api.CommandVerbose;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;

View File

@ -4,7 +4,7 @@ import java.util.function.BiConsumer;
import java.util.function.Function;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.command.CommandVerbose;
import net.Indyuce.mmocore.command.api.CommandVerbose;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;

View File

@ -10,7 +10,7 @@ import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import net.Indyuce.mmocore.command.CommandVerbose;
import net.Indyuce.mmocore.command.api.CommandVerbose;
import io.lumine.mythic.lib.command.api.CommandTreeNode;
import io.lumine.mythic.lib.command.api.Parameter;

View File

@ -5,7 +5,7 @@ import io.lumine.mythic.lib.command.api.Parameter;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.quest.trigger.ManaTrigger;
import net.Indyuce.mmocore.api.player.profess.resource.PlayerResource;
import net.Indyuce.mmocore.command.CommandVerbose;
import net.Indyuce.mmocore.command.api.CommandVerbose;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;

View File

@ -5,7 +5,7 @@ import io.lumine.mythic.lib.command.api.Parameter;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.skill.RegisteredSkill;
import net.Indyuce.mmocore.command.CommandVerbose;
import net.Indyuce.mmocore.command.api.CommandVerbose;
import net.Indyuce.mmocore.skill.ClassSkill;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;

View File

@ -4,7 +4,7 @@ import io.lumine.mythic.lib.command.api.CommandTreeNode;
import io.lumine.mythic.lib.command.api.Parameter;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.command.CommandVerbose;
import net.Indyuce.mmocore.command.api.CommandVerbose;
import net.Indyuce.mmocore.util.TriConsumer;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;

View File

@ -4,7 +4,7 @@ import io.lumine.mythic.lib.command.api.CommandTreeNode;
import io.lumine.mythic.lib.command.api.Parameter;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.command.CommandVerbose;
import net.Indyuce.mmocore.command.api.CommandVerbose;
import net.Indyuce.mmocore.waypoint.Waypoint;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;

View File

@ -1,32 +1,37 @@
package net.Indyuce.mmocore.comp.vault;
import net.Indyuce.mmocore.MMOCore;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.jetbrains.annotations.Nullable;
import java.util.logging.Level;
import net.Indyuce.mmocore.MMOCore;
import org.bukkit.Bukkit;
import net.milkbowl.vault.economy.Economy;
public class VaultEconomy {
private Economy economy;
public VaultEconomy() {
try {
economy = Bukkit.getServicesManager().getRegistration(Economy.class).getProvider();
MMOCore.log(Level.INFO, "Hooked onto Vault");
} catch (Exception exception) {
MMOCore.plugin.getLogger().log(Level.WARNING, "Vault was found but MMOCore was unable to successfully find/load an economy plugin.");
}
}
@Nullable
private final Economy economy;
/*
* checks if an economy plugin was found.
*/
public boolean isValid() {
return economy != null;
}
public VaultEconomy() {
Economy eco;
try {
eco = Bukkit.getServicesManager().getRegistration(Economy.class).getProvider();
MMOCore.log(Level.INFO, "Hooked onto Vault");
} catch (Exception exception) {
MMOCore.plugin.getLogger().log(Level.WARNING, "Vault was found but MMOCore was unable to successfully find/load an economy plugin.");
eco = null;
}
this.economy = eco;
}
public Economy getEconomy() {
return economy;
}
/**
* @return If an economy plugin was found
*/
public boolean isValid() {
return economy != null;
}
public Economy getEconomy() {
return economy;
}
}

View File

@ -15,6 +15,7 @@ import net.Indyuce.mmocore.gui.api.item.SimplePlaceholderItem;
import net.Indyuce.mmocore.skill.ClassSkill;
import net.Indyuce.mmocore.skill.RegisteredSkill;
import net.Indyuce.mmocore.api.SoundEvent;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Sound;
@ -28,7 +29,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
public class SkillList extends EditableInventory {
public class SkillList extends EditableInventory {
public SkillList() {
super("skill-list");
}
@ -340,6 +341,7 @@ public class SkillList extends EditableInventory {
skills = new ArrayList<>(playerData.getProfess().getSkills());
skillSlots = getEditable().getByFunction("skill").getSlots();
Validate.notNull(getEditable().getByFunction("active-slot"), "Your skill GUI config file is out-of-date, please regenerate it.");
activeSlotSlots = getEditable().getByFunction("active-slot").getSlots();
passiveSlotSlots = getEditable().getByFunction("passive-slot").getSlots();
selected = skills.get(page * skillSlots.size());

View File

@ -7,7 +7,7 @@ import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.util.input.ChatInput;
import net.Indyuce.mmocore.api.util.input.PlayerInput;
import net.Indyuce.mmocore.api.util.input.PlayerInput.InputType;
import net.Indyuce.mmocore.command.CommandVerbose;
import net.Indyuce.mmocore.command.api.CommandVerbose;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
@ -92,7 +92,6 @@ public class ConfigManager {
loadDefaultFile("restrictions.yml");
loadDefaultFile("sounds.yml");
loadDefaultFile("loot-chests.yml");
loadDefaultFile("commands.yml");
loadDefaultFile("exp-tables.yml");
loadDefaultFile("exp-sources.yml");
loadDefaultFile("triggers.yml");

View File

@ -1,36 +0,0 @@
player:
main: "player"
aliases: ["p", "profile"]
attributes:
main: "attributes"
aliases: ["att", "stats"]
class:
main: "class"
aliases: ["c"]
waypoints:
main: "waypoints"
aliases: ["wp"]
quests:
main: "quests"
aliases: ["q", "journal"]
skills:
main: "skills"
aliases: ["s"]
friends:
main: "friends"
aliases: ["f"]
party:
main: "party"
aliases: []
guild:
main: "guild"
aliases: []
withdraw:
main: "withdraw"
aliases: ["w"]
skill-trees:
main: "skilltrees"
aliase: ["st"]
deposit:
main: "deposit"
aliases: ["d"]

View File

@ -3,24 +3,24 @@ version: ${project.version}
main: net.Indyuce.mmocore.MMOCore
author: Indyuce
description: ${project.description}
loadbefore: [MMOItems]
depend: [MythicLib]
softdepend: [Vault,MythicMobs,PlaceholderAPI,Residence,Citizens,ProtocolLib]
loadbefore: [ MMOItems ]
depend: [ MythicLib ]
softdepend: [ Vault,MythicMobs,PlaceholderAPI,Residence,Citizens,ProtocolLib ]
api-version: 1.13
commands:
mmocore:
description: Main command.
aliases: [rpg]
mmocore:
description: Main command.
aliases: [ rpg ]
permissions:
mmocore.admin:
description: Access to /mmocore
default: op
mmocore.waypoints:
description: Access to /waypoints
default: op
mmocore.currency:
description: Access to /deposit and /withdraw
default: op
mmocore.class-select:
description: Access to /class
default: op
mmocore.admin:
description: Access to /mmocore
default: op
mmocore.waypoints:
description: Access to /waypoints
default: op
mmocore.currency:
description: Access to /deposit and /withdraw
default: op
mmocore.class-select:
description: Access to /class
default: op