Fixed gamemode command
This commit is contained in:
@@ -1,37 +0,0 @@
|
||||
package me.trouper.ultrautils.commands.gamemode;
|
||||
|
||||
import io.github.itzispyder.pdk.commands.Args;
|
||||
import io.github.itzispyder.pdk.commands.CommandRegistry;
|
||||
import io.github.itzispyder.pdk.commands.CustomCommand;
|
||||
import io.github.itzispyder.pdk.commands.Permission;
|
||||
import io.github.itzispyder.pdk.commands.completions.CompletionBuilder;
|
||||
import me.trouper.ultrautils.functions.Text;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandRegistry(value = "gma",permission = @Permission("ultrautils.gamemode.adventure"),printStackTrace = true)
|
||||
public class GMACommand implements CustomCommand {
|
||||
|
||||
@Override
|
||||
public void dispatchCommand(CommandSender commandSender, Command command, String label, Args args) {
|
||||
Player target = Bukkit.getPlayer(args.get(0).toString());
|
||||
if (target == null && (commandSender instanceof Player)) target = (Player) commandSender;
|
||||
if (target == null) {
|
||||
commandSender.sendMessage(Text.prefix("Only players may execute that command"));
|
||||
return;
|
||||
}
|
||||
if (!commandSender.hasPermission("ultrautils.gamemode")) {
|
||||
commandSender.sendMessage(Text.prefix("You do not have the root permission to change gamemode."));
|
||||
return;
|
||||
}
|
||||
GamemodeCommand.setGameMode(commandSender,target,GameMode.ADVENTURE,"ultrautils.gamemode.adventure");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispatchCompletions(CompletionBuilder b, CommandSender sender) {
|
||||
b.arg(Bukkit.getOnlinePlayers(),Player::getName);
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package me.trouper.ultrautils.commands.gamemode;
|
||||
|
||||
import io.github.itzispyder.pdk.commands.Args;
|
||||
import io.github.itzispyder.pdk.commands.CommandRegistry;
|
||||
import io.github.itzispyder.pdk.commands.CustomCommand;
|
||||
import io.github.itzispyder.pdk.commands.Permission;
|
||||
import io.github.itzispyder.pdk.commands.completions.CompletionBuilder;
|
||||
import me.trouper.ultrautils.functions.Text;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandRegistry(value = "gmc",permission = @Permission("ultrautils.gamemode.creative"),printStackTrace = true)
|
||||
public class GMCCommand implements CustomCommand {
|
||||
|
||||
@Override
|
||||
public void dispatchCommand(CommandSender commandSender, Command command, String label, Args args) {
|
||||
Player target = Bukkit.getPlayer(args.get(0).toString());
|
||||
if (target == null && (commandSender instanceof Player)) target = (Player) commandSender;
|
||||
if (target == null) {
|
||||
commandSender.sendMessage(Text.prefix("Only players may execute that command"));
|
||||
return;
|
||||
}
|
||||
if (!commandSender.hasPermission("ultrautils.gamemode")) {
|
||||
commandSender.sendMessage(Text.prefix("You do not have the root permission to change gamemode."));
|
||||
return;
|
||||
}
|
||||
GamemodeCommand.setGameMode(commandSender,target,GameMode.CREATIVE,"ultrautils.gamemode.creative");}
|
||||
|
||||
@Override
|
||||
public void dispatchCompletions(CompletionBuilder b, CommandSender sender) {
|
||||
b.arg(Bukkit.getOnlinePlayers(),Player::getName);
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package me.trouper.ultrautils.commands.gamemode;
|
||||
|
||||
import io.github.itzispyder.pdk.commands.Args;
|
||||
import io.github.itzispyder.pdk.commands.CommandRegistry;
|
||||
import io.github.itzispyder.pdk.commands.CustomCommand;
|
||||
import io.github.itzispyder.pdk.commands.Permission;
|
||||
import io.github.itzispyder.pdk.commands.completions.CompletionBuilder;
|
||||
import me.trouper.ultrautils.functions.Text;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandRegistry(value = "gms",permission = @Permission("ultrautils.gamemode.survival"),printStackTrace = true)
|
||||
public class GMSCommand implements CustomCommand {
|
||||
|
||||
@Override
|
||||
public void dispatchCommand(CommandSender commandSender, Command command, String label, Args args) {
|
||||
Player target = Bukkit.getPlayer(args.get(0).toString());
|
||||
if (target == null && (commandSender instanceof Player)) target = (Player) commandSender;
|
||||
if (target == null) {
|
||||
commandSender.sendMessage(Text.prefix("Only players may execute that command"));
|
||||
return;
|
||||
}
|
||||
if (!commandSender.hasPermission("ultrautils.gamemode")) {
|
||||
commandSender.sendMessage(Text.prefix("You do not have the root permission to change gamemode."));
|
||||
return;
|
||||
}
|
||||
GamemodeCommand.setGameMode(commandSender,target,GameMode.SURVIVAL,"ultrautils.gamemode.survival");}
|
||||
|
||||
@Override
|
||||
public void dispatchCompletions(CompletionBuilder b, CommandSender sender) {
|
||||
b.arg(Bukkit.getOnlinePlayers(),Player::getName);
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package me.trouper.ultrautils.commands.gamemode;
|
||||
|
||||
import io.github.itzispyder.pdk.commands.Args;
|
||||
import io.github.itzispyder.pdk.commands.CommandRegistry;
|
||||
import io.github.itzispyder.pdk.commands.CustomCommand;
|
||||
import io.github.itzispyder.pdk.commands.Permission;
|
||||
import io.github.itzispyder.pdk.commands.completions.CompletionBuilder;
|
||||
import me.trouper.ultrautils.functions.Text;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandRegistry(value = "gmsp",permission = @Permission("ultrautils.gamemode.spectator"),printStackTrace = true)
|
||||
public class GMSPCommand implements CustomCommand {
|
||||
|
||||
@Override
|
||||
public void dispatchCommand(CommandSender commandSender, Command command, String label, Args args) {
|
||||
Player target = Bukkit.getPlayer(args.get(0).toString());
|
||||
if (target == null && (commandSender instanceof Player)) target = (Player) commandSender;
|
||||
if (target == null) {
|
||||
commandSender.sendMessage(Text.prefix("Only players may execute that command"));
|
||||
return;
|
||||
}
|
||||
if (!commandSender.hasPermission("ultrautils.gamemode")) {
|
||||
commandSender.sendMessage(Text.prefix("You do not have the root permission to change gamemode."));
|
||||
return;
|
||||
}
|
||||
GamemodeCommand.setGameMode(commandSender,target,GameMode.SPECTATOR,"ultrautils.gamemode.spectator");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispatchCompletions(CompletionBuilder b, CommandSender sender) {
|
||||
b.arg(Bukkit.getOnlinePlayers(),Player::getName);
|
||||
}
|
||||
}
|
||||
@@ -25,42 +25,13 @@ public class GamemodeCommand implements CustomCommand {
|
||||
sender.sendMessage(Text.prefix("Only players may execute that command"));
|
||||
return;
|
||||
}
|
||||
target.sendMessage("Target: %s, Sender: %s, Command: %s, Label: %s, Args: %s".formatted(target,sender,command,label,args));
|
||||
switch (label) {
|
||||
case "gma" -> {
|
||||
setGameMode(sender,target,GameMode.ADVENTURE, "ultrautils.gamemode.adventure");
|
||||
return;
|
||||
}
|
||||
case "gmc" -> {
|
||||
setGameMode(sender,target,GameMode.CREATIVE,"ultrautils.gamemode.creative");
|
||||
return;
|
||||
}
|
||||
case "gms" -> {
|
||||
setGameMode(sender,target,GameMode.SURVIVAL,"ultrautils.gamemode.survival");
|
||||
return;
|
||||
}
|
||||
case "gmsp" -> {
|
||||
setGameMode(sender,target,GameMode.SPECTATOR,"ultrautils.gamemode.spectator");
|
||||
return;
|
||||
}
|
||||
}
|
||||
switch (args.get(0).toString()) {
|
||||
case "a","adventure","adv","gma" -> {
|
||||
setGameMode(sender,target,GameMode.ADVENTURE, "ultrautils.gamemode.adventure");
|
||||
return;
|
||||
}
|
||||
case "c","creative","cre","gmc" -> {
|
||||
setGameMode(sender,target,GameMode.CREATIVE,"ultrautils.gamemode.creative");
|
||||
return;
|
||||
}
|
||||
case "s","survival","sur","gms" -> {
|
||||
setGameMode(sender,target,GameMode.SURVIVAL,"ultrautils.gamemode.survival");
|
||||
return;
|
||||
}
|
||||
case "sp","spectator","spec","gmsp" -> {
|
||||
setGameMode(sender,target,GameMode.SPECTATOR,"ultrautils.gamemode.spectator");
|
||||
return;
|
||||
}
|
||||
String gamemode = label;
|
||||
if (label.equals("gamemode")) gamemode = args.get(0).toString();
|
||||
switch (gamemode) {
|
||||
case "a","adventure","adv","gma" -> setGameMode(sender,target,GameMode.ADVENTURE, "ultrautils.gamemode.adventure");
|
||||
case "c","creative","cre","gmc" -> setGameMode(sender,target,GameMode.CREATIVE,"ultrautils.gamemode.creative");
|
||||
case "s","survival","sur","gms" -> setGameMode(sender,target,GameMode.SURVIVAL,"ultrautils.gamemode.survival");
|
||||
case "sp","spectator","spec","gmsp" -> setGameMode(sender,target,GameMode.SPECTATOR,"ultrautils.gamemode.spectator");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +44,7 @@ public class GamemodeCommand implements CustomCommand {
|
||||
|
||||
public static void setGameMode(CommandSender user, @Nullable Player target, GameMode gm, String permission) {
|
||||
if (!user.hasPermission(permission)) {
|
||||
user.sendMessage(Text.prefix("You lack the permission to swith gamemodes to %c%s&7."));
|
||||
user.sendMessage(Text.prefix("You lack the permission to switch gamemodes to %c%s&7."));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user