mirror of
https://github.com/RonanPlugins/BetterRTP.git
synced 2026-04-09 09:26:02 +00:00
addons can now register commands + new portals addon
This commit is contained in:
@@ -24,6 +24,7 @@ public class Commands {
|
||||
public HashMap<UUID, Boolean> rtping = new HashMap<>();
|
||||
public RTPCooldown cooldowns = new RTPCooldown();
|
||||
private int delayTimer;
|
||||
List<RTPCommand> commands = new ArrayList<>();
|
||||
|
||||
public Commands(BetterRTP pl) {
|
||||
this.pl = pl;
|
||||
@@ -34,22 +35,28 @@ public class Commands {
|
||||
delayTimer = config.getInt("Settings.Delay.Time");
|
||||
cooldowns.load();
|
||||
rtping.clear();
|
||||
commands.clear();
|
||||
for (RTPCommandType cmd : RTPCommandType.values())
|
||||
registerCommand(cmd.getCmd(), false);
|
||||
}
|
||||
|
||||
public void registerCommand(RTPCommand cmd, boolean forced) {
|
||||
if (!cmd.isDebugOnly() || pl.getSettings().debug || forced) //If debug only, can it be enabled?
|
||||
commands.add(cmd);
|
||||
}
|
||||
|
||||
public void commandExecuted(CommandSender sendi, String label, String[] args) {
|
||||
if (pl.getPerms().getUse(sendi)) {
|
||||
if (args != null && args.length > 0) {
|
||||
for (RTPCommandType cmd : RTPCommandType.values()) {
|
||||
if (cmd.name().equalsIgnoreCase(args[0])) {
|
||||
if (!cmd.isDebugOnly() || pl.getSettings().debug) { //Debug only?
|
||||
if (cmd.getCmd().permission(sendi)) {
|
||||
cmd.getCmd().execute(sendi, label, args);
|
||||
//Command Event
|
||||
Bukkit.getServer().getPluginManager().callEvent(new RTP_CommandEvent(sendi, cmd));
|
||||
} else
|
||||
noPerm(sendi);
|
||||
return;
|
||||
}
|
||||
for (RTPCommand cmd : commands) {
|
||||
if (cmd.getName().equalsIgnoreCase(args[0])) {
|
||||
if (cmd.permission(sendi)) {
|
||||
//Command Event
|
||||
Bukkit.getServer().getPluginManager().callEvent(new RTP_CommandEvent(sendi, cmd));
|
||||
cmd.execute(sendi, label, args);
|
||||
} else
|
||||
noPerm(sendi);
|
||||
return;
|
||||
}
|
||||
}
|
||||
invalid(sendi, label);
|
||||
@@ -66,21 +73,19 @@ public class Commands {
|
||||
public List<String> onTabComplete(CommandSender sendi, String[] args) {
|
||||
List<String> list = new ArrayList<>();
|
||||
if (args.length == 1) {
|
||||
for (RTPCommandType cmd : RTPCommandType.values()) {
|
||||
if (cmd.name().toLowerCase().startsWith(args[0].toLowerCase()))
|
||||
if (!cmd.isDebugOnly() || pl.getSettings().debug) //Debug only?
|
||||
if (cmd.getCmd().permission(sendi))
|
||||
list.add(cmd.name().toLowerCase());
|
||||
for (RTPCommand cmd : commands) {
|
||||
if (cmd.getName().toLowerCase().startsWith(args[0].toLowerCase()))
|
||||
if (cmd.permission(sendi))
|
||||
list.add(cmd.getName().toLowerCase());
|
||||
}
|
||||
} else if (args.length > 1) {
|
||||
for (RTPCommandType cmd : RTPCommandType.values()) {
|
||||
if (cmd.name().equalsIgnoreCase(args[0]))
|
||||
if (!cmd.isDebugOnly() || pl.getSettings().debug) //Debug only?
|
||||
if (cmd.getCmd().permission(sendi)) {
|
||||
List<String> _cmdlist = cmd.getCmd().tabComplete(sendi, args);
|
||||
if (_cmdlist != null)
|
||||
list.addAll(_cmdlist);
|
||||
}
|
||||
for (RTPCommand cmd : commands) {
|
||||
if (cmd.getName().equalsIgnoreCase(args[0]))
|
||||
if (cmd.permission(sendi)) {
|
||||
List<String> _cmdlist = cmd.tabComplete(sendi, args);
|
||||
if (_cmdlist != null)
|
||||
list.addAll(_cmdlist);
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
|
||||
@@ -11,4 +11,10 @@ public interface RTPCommand {
|
||||
List<String> tabComplete(CommandSender sendi, String[] args);
|
||||
|
||||
boolean permission(CommandSender sendi);
|
||||
|
||||
String getName();
|
||||
|
||||
default boolean isDebugOnly() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,10 @@ import java.util.List;
|
||||
|
||||
public class CmdBiome implements RTPCommand, RTPCommandHelpable {
|
||||
|
||||
public String getName() {
|
||||
return "biome";
|
||||
}
|
||||
|
||||
//rtp biome <biome1, biome2...>
|
||||
public void execute(CommandSender sendi, String label, String[] args) {
|
||||
if (args.length >= 2)
|
||||
|
||||
@@ -15,6 +15,10 @@ import java.util.*;
|
||||
|
||||
public class CmdEdit implements RTPCommand, RTPCommandHelpable { //Edit a worlds properties
|
||||
|
||||
public String getName() {
|
||||
return "edit";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sendi, String label, String[] args) {
|
||||
if (args.length >= 4) {
|
||||
|
||||
@@ -12,6 +12,10 @@ import java.util.List;
|
||||
|
||||
public class CmdHelp implements RTPCommand, RTPCommandHelpable {
|
||||
|
||||
public String getName() {
|
||||
return "help";
|
||||
}
|
||||
|
||||
public void execute(CommandSender sendi, String label, String[] args) {
|
||||
Messages txt = BetterRTP.getInstance().getText();
|
||||
List<String> list = new ArrayList<>();
|
||||
|
||||
@@ -18,6 +18,10 @@ import java.util.List;
|
||||
|
||||
public class CmdInfo implements RTPCommand, RTPCommandHelpable {
|
||||
|
||||
public String getName() {
|
||||
return "info";
|
||||
}
|
||||
|
||||
public void execute(CommandSender sendi, String label, String[] args) {
|
||||
if (args.length > 1) {
|
||||
if (args[1].equalsIgnoreCase(CmdInfoSub.PARTICLES.name()))
|
||||
|
||||
@@ -16,6 +16,10 @@ import java.util.List;
|
||||
|
||||
public class CmdPlayer implements RTPCommand, RTPCommandHelpable {
|
||||
|
||||
public String getName() {
|
||||
return "player";
|
||||
}
|
||||
|
||||
//rtp player <world> <biome1> <biome2...>
|
||||
public void execute(CommandSender sendi, String label, String[] args) {
|
||||
if (args.length == 2)
|
||||
|
||||
@@ -9,6 +9,10 @@ import java.util.List;
|
||||
|
||||
public class CmdReload implements RTPCommand, RTPCommandHelpable {
|
||||
|
||||
public String getName() {
|
||||
return "reload";
|
||||
}
|
||||
|
||||
public void execute(CommandSender sendi, String label, String[] args) {
|
||||
BetterRTP.getInstance().reload(sendi);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,10 @@ import java.util.List;
|
||||
|
||||
public class CmdSettings implements RTPCommand, RTPCommandHelpable {
|
||||
|
||||
public String getName() {
|
||||
return "settings";
|
||||
}
|
||||
|
||||
public void execute(CommandSender sendi, String label, String[] args) {
|
||||
if (sendi instanceof Player)
|
||||
BetterRTP.getInstance().getInvs().getInv(RTP_INV_SETTINGS.MAIN).show((Player) sendi);
|
||||
|
||||
@@ -11,6 +11,10 @@ import java.util.List;
|
||||
//Meant to just test particles and effects without actually rtp'ing around the world
|
||||
public class CmdTest implements RTPCommand, RTPCommandHelpable {
|
||||
|
||||
public String getName() {
|
||||
return "test";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sendi, String label, String[] args) {
|
||||
if (sendi instanceof Player) {
|
||||
@@ -35,4 +39,8 @@ public class CmdTest implements RTPCommand, RTPCommandHelpable {
|
||||
return BetterRTP.getInstance().getText().getHelpTest();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugOnly() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,10 @@ import java.util.List;
|
||||
|
||||
public class CmdVersion implements RTPCommand, RTPCommandHelpable {
|
||||
|
||||
public String getName() {
|
||||
return "version";
|
||||
}
|
||||
|
||||
public void execute(CommandSender sendi, String label, String[] args) {
|
||||
sendi.sendMessage(BetterRTP.getInstance().getText().colorPre("&aVersion #&e" + BetterRTP.getInstance().getDescription().getVersion()));
|
||||
}
|
||||
|
||||
@@ -14,6 +14,10 @@ import java.util.List;
|
||||
|
||||
public class CmdWorld implements RTPCommand, RTPCommandHelpable {
|
||||
|
||||
public String getName() {
|
||||
return "world";
|
||||
}
|
||||
|
||||
//rtp world <world> <biome1, biome2...>
|
||||
public void execute(CommandSender sendi, String label, String[] args) {
|
||||
if (args.length >= 2)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package me.SuperRonanCraft.BetterRTP.references.customEvents;
|
||||
|
||||
import me.SuperRonanCraft.BetterRTP.player.commands.RTPCommand;
|
||||
import me.SuperRonanCraft.BetterRTP.player.commands.RTPCommandType;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.event.Event;
|
||||
@@ -8,10 +9,10 @@ import org.bukkit.event.HandlerList;
|
||||
public class RTP_CommandEvent extends Event {
|
||||
|
||||
CommandSender sendi;
|
||||
RTPCommandType cmd;
|
||||
RTPCommand cmd;
|
||||
private static final HandlerList handler = new HandlerList();
|
||||
|
||||
public RTP_CommandEvent(CommandSender sendi, RTPCommandType cmd) {
|
||||
public RTP_CommandEvent(CommandSender sendi, RTPCommand cmd) {
|
||||
this.sendi = sendi;
|
||||
this.cmd = cmd;
|
||||
}
|
||||
@@ -20,7 +21,7 @@ public class RTP_CommandEvent extends Event {
|
||||
return sendi;
|
||||
}
|
||||
|
||||
public RTPCommandType getCmd() {
|
||||
public RTPCommand getCmd() {
|
||||
return cmd;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user