SteamWar/BauSystem
Archiviert
13
0

update for CommandGamemode

Dieser Commit ist enthalten in:
Zeanon 2021-04-01 21:42:57 +02:00
Ursprung d16af698bf
Commit 3d6d2cbc73
2 geänderte Dateien mit 36 neuen und 86 gelöschten Zeilen

Datei anzeigen

@ -66,9 +66,8 @@ public class BauSystem extends JavaPlugin implements Listener {
Mapper.init();
try {
CommandRemover.removeAll("tp", "gamemode", "time", "clear");
CommandRemover.removeAll("tp", "time", "clear");
CommandInjector.injectCommand(new CommandTeleport());
CommandInjector.injectCommand(new CommandGamemode());
CommandInjector.injectCommand(new CommandTime());
CommandInjector.injectCommand(new CommandClear());
} catch (Exception e) {
@ -84,6 +83,7 @@ public class BauSystem extends JavaPlugin implements Listener {
new CommandSpeed();
new CommandTNT();
new CommandBau();
new CommandGamemode();
getCommand("fire").setExecutor(new CommandFire());
getCommand("freeze").setExecutor(new CommandFreeze());
new CommandTestblock();

Datei anzeigen

@ -1,60 +1,51 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.commands;
import com.google.common.collect.ImmutableList;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.command.SWCommand;
import de.steamwar.sql.BauweltMember;
import org.apache.commons.lang.Validate;
import org.bukkit.GameMode;
import org.bukkit.command.CommandSender;
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
import java.util.ArrayList;
import java.util.List;
public class CommandGamemode extends BukkitCommand {
private static final List<String> GAMEMODE_NAMES = ImmutableList.of("adventure", "creative", "survival",
"spectator");
public class CommandGamemode extends SWCommand {
public CommandGamemode() {
super("gamemode");
List<String> aliases = new ArrayList<>();
aliases.add("gm");
this.setAliases(aliases);
this.description = "Ändert den Spielmodus eines Spielers";
this.usageMessage = "/gm [Spielmodus]";
super("gamemode", "gm");
}
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!(sender instanceof Player)) {
return false;
} else if (args.length == 0) {
sender.sendMessage(BauSystem.PREFIX + this.usageMessage);
return false;
@Register(help = true)
public void gamemodeHelp(Player p, String... args) {
p.sendMessage(BauSystem.PREFIX + "§cUnbekannter Spielmodus");
}
@Register
public void genericCommand(Player p) {
if (!permissionCheck(p)) {
//noinspection UnnecessaryReturnStatement
return;
} else {
if (p.getGameMode() == GameMode.CREATIVE) {
p.setGameMode(GameMode.SPECTATOR);
} else {
p.setGameMode(GameMode.CREATIVE);
}
}
}
Player p = (Player) sender;
@Register
public void gamemodeCommand(Player p, GameMode gameMode) {
if (!permissionCheck(p)) {
//noinspection UnnecessaryReturnStatement
return;
} else {
p.setGameMode(gameMode);
}
}
private boolean permissionCheck(Player p) {
if (!p.getUniqueId().equals(BauSystem.getOwner())) {
BauweltMember member = BauweltMember.getBauMember(BauSystem.getOwner(), p.getUniqueId());
if (member == null || !member.isBuild()) {
@ -62,47 +53,6 @@ public class CommandGamemode extends BukkitCommand {
return false;
}
}
GameMode mode = createMode(args[0]);
if (mode == null) {
p.sendMessage(BauSystem.PREFIX + "§cUnbekannter Spielmodus");
return false;
}
p.setGameMode(mode);
return true;
}
@SuppressWarnings("deprecation")
private GameMode createMode(String modeArg) {
try {
return GameMode.getByValue(Integer.parseInt(modeArg));
} catch (NumberFormatException ignored) {
if ((modeArg.equalsIgnoreCase("creative")) || (modeArg.equalsIgnoreCase("c")))
return GameMode.CREATIVE;
else if ((modeArg.equalsIgnoreCase("adventure")) || (modeArg.equalsIgnoreCase("a")))
return GameMode.ADVENTURE;
else if ((modeArg.equalsIgnoreCase("spectator")) || (modeArg.equalsIgnoreCase("sp")))
return GameMode.SPECTATOR;
else if ((modeArg.equalsIgnoreCase("survival")) || (modeArg.equalsIgnoreCase("s")))
return GameMode.SURVIVAL;
}
return null;
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
if (args.length == 1)
return StringUtil.copyPartialMatches(args[0], GAMEMODE_NAMES,
new ArrayList<>(GAMEMODE_NAMES.size()));
if (args.length == 2) {
return super.tabComplete(sender, alias, args);
}
return ImmutableList.of();
}
}
}