update for CommandGamemode
Dieser Commit ist enthalten in:
Ursprung
d16af698bf
Commit
3d6d2cbc73
@ -66,9 +66,8 @@ public class BauSystem extends JavaPlugin implements Listener {
|
|||||||
Mapper.init();
|
Mapper.init();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
CommandRemover.removeAll("tp", "gamemode", "time", "clear");
|
CommandRemover.removeAll("tp", "time", "clear");
|
||||||
CommandInjector.injectCommand(new CommandTeleport());
|
CommandInjector.injectCommand(new CommandTeleport());
|
||||||
CommandInjector.injectCommand(new CommandGamemode());
|
|
||||||
CommandInjector.injectCommand(new CommandTime());
|
CommandInjector.injectCommand(new CommandTime());
|
||||||
CommandInjector.injectCommand(new CommandClear());
|
CommandInjector.injectCommand(new CommandClear());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -84,6 +83,7 @@ public class BauSystem extends JavaPlugin implements Listener {
|
|||||||
new CommandSpeed();
|
new CommandSpeed();
|
||||||
new CommandTNT();
|
new CommandTNT();
|
||||||
new CommandBau();
|
new CommandBau();
|
||||||
|
new CommandGamemode();
|
||||||
getCommand("fire").setExecutor(new CommandFire());
|
getCommand("fire").setExecutor(new CommandFire());
|
||||||
getCommand("freeze").setExecutor(new CommandFreeze());
|
getCommand("freeze").setExecutor(new CommandFreeze());
|
||||||
new CommandTestblock();
|
new CommandTestblock();
|
||||||
|
@ -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;
|
package de.steamwar.bausystem.commands;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
|
import de.steamwar.command.SWCommand;
|
||||||
import de.steamwar.sql.BauweltMember;
|
import de.steamwar.sql.BauweltMember;
|
||||||
import org.apache.commons.lang.Validate;
|
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.command.defaults.BukkitCommand;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.util.StringUtil;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class CommandGamemode extends BukkitCommand {
|
public class CommandGamemode extends SWCommand {
|
||||||
private static final List<String> GAMEMODE_NAMES = ImmutableList.of("adventure", "creative", "survival",
|
|
||||||
"spectator");
|
|
||||||
|
|
||||||
public CommandGamemode() {
|
public CommandGamemode() {
|
||||||
super("gamemode");
|
super("gamemode", "gm");
|
||||||
List<String> aliases = new ArrayList<>();
|
|
||||||
aliases.add("gm");
|
|
||||||
this.setAliases(aliases);
|
|
||||||
this.description = "Ändert den Spielmodus eines Spielers";
|
|
||||||
this.usageMessage = "/gm [Spielmodus]";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
|
|
||||||
if (!(sender instanceof Player)) {
|
@Register(help = true)
|
||||||
return false;
|
public void gamemodeHelp(Player p, String... args) {
|
||||||
} else if (args.length == 0) {
|
p.sendMessage(BauSystem.PREFIX + "§cUnbekannter Spielmodus");
|
||||||
sender.sendMessage(BauSystem.PREFIX + this.usageMessage);
|
}
|
||||||
return false;
|
|
||||||
|
@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())) {
|
if (!p.getUniqueId().equals(BauSystem.getOwner())) {
|
||||||
BauweltMember member = BauweltMember.getBauMember(BauSystem.getOwner(), p.getUniqueId());
|
BauweltMember member = BauweltMember.getBauMember(BauSystem.getOwner(), p.getUniqueId());
|
||||||
if (member == null || !member.isBuild()) {
|
if (member == null || !member.isBuild()) {
|
||||||
@ -62,47 +53,6 @@ public class CommandGamemode extends BukkitCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GameMode mode = createMode(args[0]);
|
|
||||||
|
|
||||||
if (mode == null) {
|
|
||||||
p.sendMessage(BauSystem.PREFIX + "§cUnbekannter Spielmodus");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
p.setGameMode(mode);
|
|
||||||
return true;
|
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
In neuem Issue referenzieren
Einen Benutzer sperren