forked from Upstream/mmocore
Made commands customizable
This commit is contained in:
parent
c98a952261
commit
d3844ae12c
@ -1,9 +1,12 @@
|
||||
package net.Indyuce.mmocore;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
@ -268,18 +271,30 @@ public class MMOCore extends JavaPlugin {
|
||||
Bukkit.getOnlinePlayers().forEach(player -> PlayerData.setup(player).setPlayer(player));
|
||||
|
||||
// commands
|
||||
getCommand("player").setExecutor(new PlayerStatsCommand());
|
||||
getCommand("attributes").setExecutor(new AttributesCommand());
|
||||
getCommand("class").setExecutor(new ClassCommand());
|
||||
getCommand("waypoints").setExecutor(new WaypointsCommand());
|
||||
getCommand("quests").setExecutor(new QuestsCommand());
|
||||
getCommand("skills").setExecutor(new SkillsCommand());
|
||||
getCommand("friends").setExecutor(new FriendsCommand());
|
||||
getCommand("party").setExecutor(new PartyCommand());
|
||||
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();
|
||||
|
||||
commandMap.register(config.getString("player"), new PlayerStatsCommand(config.getConfigurationSection("player")));
|
||||
commandMap.register(config.getString("attributes"), new AttributesCommand(config.getConfigurationSection("attributes")));
|
||||
commandMap.register(config.getString("class"), new ClassCommand(config.getConfigurationSection("class")));
|
||||
commandMap.register(config.getString("waypoints"), new WaypointsCommand(config.getConfigurationSection("waypoints")));
|
||||
commandMap.register(config.getString("quests"), new QuestsCommand(config.getConfigurationSection("quests")));
|
||||
commandMap.register(config.getString("skills"), new SkillsCommand(config.getConfigurationSection("skills")));
|
||||
commandMap.register(config.getString("friends"), new FriendsCommand(config.getConfigurationSection("friends")));
|
||||
commandMap.register(config.getString("party"), new PartyCommand(config.getConfigurationSection("party")));
|
||||
|
||||
if (hasEconomy() && economy.isValid()) {
|
||||
getCommand("withdraw").setExecutor(new WithdrawCommand());
|
||||
getCommand("deposit").setExecutor(new DepositCommand());
|
||||
if (hasEconomy() && economy.isValid()) {
|
||||
commandMap.register(config.getString("withdraw"), new WithdrawCommand(config.getConfigurationSection("withdraw")));
|
||||
commandMap.register(config.getString("deposit"), new DepositCommand(config.getConfigurationSection("deposit")));
|
||||
}
|
||||
}
|
||||
catch(NoSuchFieldException | IllegalArgumentException | IllegalAccessException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
MMOCoreCommand mmoCoreCommand = new MMOCoreCommand();
|
||||
|
@ -1,17 +1,24 @@
|
||||
package net.Indyuce.mmocore.command;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
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.player.PlayerData;
|
||||
import net.Indyuce.mmocore.manager.InventoryManager;
|
||||
|
||||
public class AttributesCommand implements CommandExecutor {
|
||||
public class AttributesCommand extends BukkitCommand {
|
||||
public AttributesCommand(ConfigurationSection config) {
|
||||
super(config.getString("main"));
|
||||
|
||||
setAliases(config.getStringList("aliases"));
|
||||
setDescription("Opens the attribute menu.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
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;
|
||||
|
@ -2,17 +2,24 @@ package net.Indyuce.mmocore.command;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
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.player.PlayerData;
|
||||
import net.Indyuce.mmocore.manager.InventoryManager;
|
||||
|
||||
public class ClassCommand implements CommandExecutor {
|
||||
public class ClassCommand extends BukkitCommand {
|
||||
public ClassCommand(ConfigurationSection config) {
|
||||
super(config.getString("main"));
|
||||
|
||||
setAliases(config.getStringList("aliases"));
|
||||
setDescription("Select a new class.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
public boolean execute(CommandSender sender, String label, String[] args) {
|
||||
if (!sender.hasPermission("mmocore.class-select"))
|
||||
return false;
|
||||
|
||||
|
@ -2,16 +2,23 @@ package net.Indyuce.mmocore.command;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
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.gui.eco.DepositMenu;
|
||||
|
||||
public class DepositCommand implements CommandExecutor {
|
||||
public class DepositCommand extends BukkitCommand {
|
||||
public DepositCommand(ConfigurationSection config) {
|
||||
super(config.getString("main"));
|
||||
|
||||
setAliases(config.getStringList("aliases"));
|
||||
setDescription("Opens the currency deposit menu.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
public boolean execute(CommandSender sender, String label, String[] args) {
|
||||
if (!sender.hasPermission("mmocore.currency"))
|
||||
return false;
|
||||
|
||||
|
@ -3,9 +3,9 @@ package net.Indyuce.mmocore.command;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
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.MMOCore;
|
||||
@ -15,9 +15,16 @@ import net.Indyuce.mmocore.api.player.social.FriendRequest;
|
||||
import net.Indyuce.mmocore.api.player.social.Request;
|
||||
import net.Indyuce.mmocore.manager.InventoryManager;
|
||||
|
||||
public class FriendsCommand implements CommandExecutor {
|
||||
public class FriendsCommand extends BukkitCommand {
|
||||
public FriendsCommand(ConfigurationSection config) {
|
||||
super(config.getString("main"));
|
||||
|
||||
setAliases(config.getStringList("aliases"));
|
||||
setDescription("Opens the friends menu.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
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;
|
||||
|
@ -4,9 +4,9 @@ import java.util.UUID;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
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.MMOCore;
|
||||
@ -15,10 +15,17 @@ import net.Indyuce.mmocore.api.player.social.PartyInvite;
|
||||
import net.Indyuce.mmocore.api.player.social.Request;
|
||||
import net.Indyuce.mmocore.manager.InventoryManager;
|
||||
|
||||
public class PartyCommand implements CommandExecutor {
|
||||
public class PartyCommand extends BukkitCommand {
|
||||
|
||||
public PartyCommand(ConfigurationSection config) {
|
||||
super(config.getString("main"));
|
||||
|
||||
setAliases(config.getStringList("aliases"));
|
||||
setDescription("Opens the party menu.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
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;
|
||||
|
@ -1,17 +1,24 @@
|
||||
package net.Indyuce.mmocore.command;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
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.player.PlayerData;
|
||||
import net.Indyuce.mmocore.manager.InventoryManager;
|
||||
|
||||
public class PlayerStatsCommand implements CommandExecutor {
|
||||
public class PlayerStatsCommand extends BukkitCommand {
|
||||
public PlayerStatsCommand(ConfigurationSection config) {
|
||||
super(config.getString("main"));
|
||||
|
||||
setAliases(config.getStringList("aliases"));
|
||||
setDescription("Show player stats.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
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;
|
||||
|
@ -1,16 +1,23 @@
|
||||
package net.Indyuce.mmocore.command;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
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.player.PlayerData;
|
||||
import net.Indyuce.mmocore.manager.InventoryManager;
|
||||
|
||||
public class QuestsCommand implements CommandExecutor {
|
||||
public class QuestsCommand extends BukkitCommand {
|
||||
public QuestsCommand(ConfigurationSection config) {
|
||||
super(config.getString("main"));
|
||||
|
||||
setAliases(config.getStringList("aliases"));
|
||||
setDescription("Opens the quests menu.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
public boolean execute(CommandSender sender, String label, String[] args) {
|
||||
if (sender instanceof Player)
|
||||
InventoryManager.QUEST_LIST.newInventory(PlayerData.get((Player) sender)).open();
|
||||
return true;
|
||||
|
@ -1,17 +1,24 @@
|
||||
package net.Indyuce.mmocore.command;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
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.MMOCore;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.manager.InventoryManager;
|
||||
|
||||
public class SkillsCommand implements CommandExecutor {
|
||||
public class SkillsCommand extends BukkitCommand {
|
||||
public SkillsCommand(ConfigurationSection config) {
|
||||
super(config.getString("main"));
|
||||
|
||||
setAliases(config.getStringList("aliases"));
|
||||
setDescription("Opens the skills menu.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
public boolean execute(CommandSender sender, String label, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
PlayerData data = PlayerData.get((Player) sender);
|
||||
if (data.getProfess().getSkills().size() < 1) {
|
||||
|
@ -1,16 +1,23 @@
|
||||
package net.Indyuce.mmocore.command;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
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.player.PlayerData;
|
||||
import net.Indyuce.mmocore.manager.InventoryManager;
|
||||
|
||||
public class WaypointsCommand implements CommandExecutor {
|
||||
public class WaypointsCommand extends BukkitCommand {
|
||||
public WaypointsCommand(ConfigurationSection config) {
|
||||
super(config.getString("main"));
|
||||
|
||||
setAliases(config.getStringList("aliases"));
|
||||
setDescription("Open the waypoints menu.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
public boolean execute(CommandSender sender, String label, String[] args) {
|
||||
if (sender instanceof Player && sender.hasPermission("mmocore.waypoints"))
|
||||
InventoryManager.WAYPOINTS.newInventory(PlayerData.get((Player) sender)).open();
|
||||
return true;
|
||||
|
@ -4,17 +4,24 @@ import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
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.MMOCore;
|
||||
import net.Indyuce.mmocore.api.eco.Withdraw;
|
||||
|
||||
public class WithdrawCommand implements CommandExecutor {
|
||||
public class WithdrawCommand extends BukkitCommand {
|
||||
public WithdrawCommand(ConfigurationSection config) {
|
||||
super(config.getString("main"));
|
||||
|
||||
setAliases(config.getStringList("aliases"));
|
||||
setDescription("Creates a withdraw request.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
public boolean execute(CommandSender sender, String label, String[] args) {
|
||||
if (!sender.hasPermission("mmocore.currency"))
|
||||
return false;
|
||||
|
||||
|
@ -86,6 +86,7 @@ public class ConfigManager {
|
||||
loadDefaultFile("waypoints.yml");
|
||||
loadDefaultFile("restrictions.yml");
|
||||
loadDefaultFile("chests.yml");
|
||||
loadDefaultFile("commands.yml");
|
||||
|
||||
loadOptions();
|
||||
}
|
||||
|
30
src/main/resources/default/commands.yml
Normal file
30
src/main/resources/default/commands.yml
Normal file
@ -0,0 +1,30 @@
|
||||
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: []
|
||||
withdraw:
|
||||
main: "withdraw"
|
||||
aliases: ["w"]
|
||||
deposit:
|
||||
main: "deposit"
|
||||
aliases: ["d"]
|
@ -7,32 +7,9 @@ loadbefore: [MMOItems]
|
||||
softdepend: [Vault,MythicMobs,PlaceholderAPI]
|
||||
api-version: 1.13
|
||||
commands:
|
||||
player:
|
||||
description: Show player stats.
|
||||
aliases: [p]
|
||||
class:
|
||||
description: Choose a new class.
|
||||
attributes:
|
||||
description: Opens the attribute menu.
|
||||
waypoints:
|
||||
description: Open the waypoints menu.
|
||||
mmocore:
|
||||
description: Main command.
|
||||
aliases: [rpg]
|
||||
deposit:
|
||||
description: Opens the currency deposit menu.
|
||||
withdraw:
|
||||
description: Creates a withdraw request.
|
||||
friends:
|
||||
description: Opens the friends menu.
|
||||
aliases: [f]
|
||||
party:
|
||||
description: Opens the party menu.
|
||||
aliases: [f]
|
||||
quests:
|
||||
description: Opens the quests menu.
|
||||
skills:
|
||||
description: Opens the skills menu.
|
||||
permissions:
|
||||
mmocore.admin:
|
||||
description: Access to /rpg
|
||||
|
Loading…
Reference in New Issue
Block a user