diff --git a/src/main/java/me/stefan923/perfectflight/commands/CommandManager.java b/src/main/java/me/stefan923/perfectflight/commands/CommandManager.java index bb5ed63..34787fb 100644 --- a/src/main/java/me/stefan923/perfectflight/commands/CommandManager.java +++ b/src/main/java/me/stefan923/perfectflight/commands/CommandManager.java @@ -1,6 +1,7 @@ package me.stefan923.perfectflight.commands; import me.stefan923.perfectflight.PerfectFlight; +import me.stefan923.perfectflight.commands.type.CommandBypass; import me.stefan923.perfectflight.commands.type.CommandFly; import me.stefan923.perfectflight.commands.type.CommandPerfectFlight; import me.stefan923.perfectflight.commands.type.CommandReload; @@ -29,12 +30,15 @@ public CommandManager(PerfectFlight instance) { instance.getCommand("perfectflight").setExecutor(this); AbstractCommand commandPerfectFlight = addCommand(new CommandPerfectFlight()); - addCommand(new CommandReload(commandPerfectFlight)); if (settings.getBoolean("Enabled Commands.Fly")) { instance.getCommand("fly").setExecutor(this); addCommand(new CommandFly()); } + if (settings.getBoolean("Enabled Commands.Bypass")) { + addCommand(new CommandBypass(commandPerfectFlight)); + } + addCommand(new CommandReload(commandPerfectFlight)); for (AbstractCommand abstractCommand : commands) { if (abstractCommand.getParent() != null) continue; diff --git a/src/main/java/me/stefan923/perfectflight/commands/type/CommandBypass.java b/src/main/java/me/stefan923/perfectflight/commands/type/CommandBypass.java new file mode 100644 index 0000000..25f2ab3 --- /dev/null +++ b/src/main/java/me/stefan923/perfectflight/commands/type/CommandBypass.java @@ -0,0 +1,58 @@ +package me.stefan923.perfectflight.commands.type; + +import me.stefan923.perfectflight.PerfectFlight; +import me.stefan923.perfectflight.commands.AbstractCommand; +import me.stefan923.perfectflight.language.LanguageManager; +import me.stefan923.perfectflight.utils.MessageUtils; +import me.stefan923.perfectflight.utils.User; +import org.bukkit.command.CommandSender; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; + +import java.util.List; + +public class CommandBypass extends AbstractCommand implements MessageUtils { + + public CommandBypass(AbstractCommand abstractCommand) { + super(abstractCommand, true, "bypass"); + } + + @Override + protected ReturnType runCommand(PerfectFlight instance, CommandSender sender, String... args) { + FileConfiguration language = instance.getLanguageManager().getConfig(); + User user = instance.getUser((Player) sender); + + if (user.isBypassing()) { + user.setBypassing(false); + sender.sendMessage(formatAll(language.getString("Command.Bypass.Enabled"))); + + return ReturnType.SUCCESS; + } + + user.setBypassing(true); + sender.sendMessage(formatAll(language.getString("Command.Bypass.Disabled"))); + + return ReturnType.SUCCESS; + } + + @Override + protected List onTab(PerfectFlight instance, CommandSender sender, String... args) { + return null; + } + + @Override + public String getPermissionNode() { + return "perfectflight.bypass"; + } + + @Override + public String getSyntax() { + return "/perfectflight bypass"; + } + + @Override + public String getDescription() { + return "Enables bypass mode for fly checker."; + } + +} diff --git a/src/main/java/me/stefan923/perfectflight/commands/type/CommandPerfectFlight.java b/src/main/java/me/stefan923/perfectflight/commands/type/CommandPerfectFlight.java index f850a8a..9882a15 100644 --- a/src/main/java/me/stefan923/perfectflight/commands/type/CommandPerfectFlight.java +++ b/src/main/java/me/stefan923/perfectflight/commands/type/CommandPerfectFlight.java @@ -37,6 +37,9 @@ protected List onTab(PerfectFlight instance, CommandSender sender, Strin if (sender.hasPermission("perfectflight.admin")) { list.addAll(Stream.of("reload").filter(string -> string.startsWith(args[0].toLowerCase())).collect(Collectors.toList())); } + if (sender.hasPermission("perfectflight.bypass")) { + list.addAll(Stream.of("bypass").filter(string -> string.startsWith(args[0].toLowerCase())).collect(Collectors.toList())); + } return list.isEmpty() ? null : list; } diff --git a/src/main/java/me/stefan923/perfectflight/language/LanguageManager.java b/src/main/java/me/stefan923/perfectflight/language/LanguageManager.java index cca338d..23c819c 100644 --- a/src/main/java/me/stefan923/perfectflight/language/LanguageManager.java +++ b/src/main/java/me/stefan923/perfectflight/language/LanguageManager.java @@ -23,6 +23,8 @@ public void setup(PerfectFlight instance) { config = YamlConfiguration.loadConfiguration(cfile); config.options().header("PerfectFlight by Stefan923\n"); + config.addDefault("Command.Bypass.Enabled", "&8(&3!&8) &fNow, you are bypassing all fly checkers!"); + config.addDefault("Command.Bypass.Disabled", "&8(&3!&8) &fYou are &cno longer &fbypassing all fly checkers!"); config.addDefault("Command.Fly.Can Not Fly", "&8(&3!&8) &cYou &4can't &cenable your flight mode here!"); config.addDefault("Command.Fly.Enabled", "&8(&3!&8) &fYour flight mode has been &aenabled&f!"); config.addDefault("Command.Fly.Disabled", "&8(&3!&8) &fYour flight mode has been &cdisabled&f!"); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 1cefe70..3fe5723 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -17,6 +17,9 @@ permissions: perfectflight.admin: description: Access to powerfull commands, like reload, configuration commands. default: op + perfectflight.bypass: + description: Access to use /perfectflight bypass command. + default: op perfectflight.fly: description: Access to use /fly command. default: op