Skip to content

Commit

Permalink
Added "/perfectflight bypass" subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan923 committed Sep 17, 2020
1 parent 3b9000c commit b4d6aca
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> 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.";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ protected List<String> 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b4d6aca

Please sign in to comment.