package dev.siskel.poketDimensions.commands; import java.io.File; import java.util.ArrayList; import java.util.List; import org.bukkit.Bukkit; import org.bukkit.GameRule; import org.bukkit.OfflinePlayer; import org.bukkit.World; import org.bukkit.WorldCreator; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; import org.bukkit.entity.Player; public class pdgamerule implements CommandExecutor, TabCompleter { public pdgamerule() { } public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (!(sender instanceof Player)) { sender.sendMessage("This command can only be executed by a player."); return true; } else { Player player = (Player)sender; if (args.length < 2) { player.sendMessage("Usage: /pdgamerule [value]"); return true; } else { OfflinePlayer targetPlayer = Bukkit.getOfflinePlayer(args[0]); String worldName = "poketdimensions/pocketdimension-" + targetPlayer.getUniqueId().toString(); File worldFolder = new File(Bukkit.getWorldContainer(), worldName); if (worldFolder.exists() && worldFolder.isDirectory()) { World targetWorld = Bukkit.getWorld(worldName); if (targetWorld == null) { targetWorld = (new WorldCreator(worldName)).createWorld(); } GameRule gameRule = GameRule.getByName(args[1]); if (gameRule == null) { player.sendMessage("Unknown game rule: " + args[1]); return true; } else if (args.length == 2) { Object currentValue = targetWorld.getGameRuleValue(gameRule); if (currentValue != null) { player.sendMessage("Current value of " + args[1] + ": " + currentValue.toString()); } else { player.sendMessage("Unable to get the value for game rule " + args[1]); } return true; } else { String inputValue = args[2]; try { if (gameRule.getType() == Boolean.class) { if (!inputValue.equalsIgnoreCase("true") && !inputValue.equalsIgnoreCase("false")) { player.sendMessage("Invalid Value, Valid Values are: true, false"); return true; } Boolean value = Boolean.parseBoolean(inputValue); targetWorld.setGameRule((GameRule) gameRule, value); } else { if (gameRule.getType() != Integer.class) { player.sendMessage("Unsupported game rule type."); return true; } if (!inputValue.matches("[0-9]+")) { player.sendMessage("Invalid Value, Valid Values are integers only."); return true; } Integer value = Integer.parseInt(inputValue); targetWorld.setGameRule((GameRule) gameRule, value); } player.sendMessage("Game rule " + args[1] + " set to " + inputValue); } catch (NumberFormatException var13) { player.sendMessage("Invalid value for game rule " + args[1]); } return true; } } else { player.sendMessage("That player doesn't have a pocket dimension."); return true; } } } } public List onTabComplete(CommandSender sender, Command cmd, String label, String[] args) { List suggestions = new ArrayList(); if (args.length == 2) { OfflinePlayer targetPlayer = Bukkit.getOfflinePlayer(args[0]); String worldName = "poketdimensions/pocketdimension-" + targetPlayer.getUniqueId().toString(); World targetWorld = Bukkit.getWorld(worldName); if (targetWorld != null) { for(String gameRule : targetWorld.getGameRules()) { if (gameRule.toLowerCase().startsWith(args[1].toLowerCase())) { suggestions.add(gameRule); } } } } return suggestions; } }