mirror of
https://gitlab.com/SamB440/rpgregions-2.git
synced 2025-12-28 03:09:14 +00:00
Allow console to run /rpgr add
This commit is contained in:
@@ -23,8 +23,11 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
@@ -81,26 +84,46 @@ public class RPGRegionsCommand extends BaseCommand {
|
||||
@Subcommand("add")
|
||||
@CommandPermission("rpgregions.add")
|
||||
@CommandCompletion("@integration-regions")
|
||||
public void onAdd(Player player, String region) {
|
||||
if (!plugin.getManagers().getIntegrationManager().exists(player.getLocation().getWorld(), region)) {
|
||||
player.sendMessage(StringUtils.colour("&cThat region does not exist in your protection plugin."));
|
||||
return;
|
||||
}
|
||||
|
||||
public void onAdd(CommandSender sender, String region, @co.aikar.commands.annotation.Optional @Nullable String worldName) {
|
||||
if (plugin.getManagers().getRegionsCache().getConfiguredRegion(region).isPresent()) {
|
||||
player.sendMessage(StringUtils.colour("&cThat region is already configured."));
|
||||
sender.sendMessage(StringUtils.colour("&cThat region is already configured."));
|
||||
return;
|
||||
}
|
||||
|
||||
ConfiguredRegion configuredRegion = new ConfiguredRegion(player.getWorld(), region, region, new ArrayList<>(),
|
||||
new ArrayList<>());
|
||||
configuredRegion.setLocation(player.getLocation());
|
||||
plugin.getManagers().getRegionsCache().addConfiguredRegion(configuredRegion);
|
||||
player.sendMessage(StringUtils.colour("&aAdded configured region " + region + "!"));
|
||||
player.sendMessage(StringUtils.colour("&e&oNow use /rpgregions edit "
|
||||
Location location = null;
|
||||
if (sender instanceof Player player) {
|
||||
location = player.getLocation();
|
||||
}
|
||||
|
||||
final World world = worldName == null ? null : Bukkit.getWorld(worldName);
|
||||
if (world != null) {
|
||||
if (location == null) location = new Location(world, 0, 100, 0);
|
||||
else location.setWorld(world);
|
||||
}
|
||||
|
||||
if (location == null) {
|
||||
sender.sendMessage(ChatColor.RED + "Console needs to provide a world name!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!plugin.getManagers().getIntegrationManager().exists(location.getWorld(), region)) {
|
||||
sender.sendMessage(StringUtils.colour("&cThat region does not exist in your protection plugin."));
|
||||
return;
|
||||
}
|
||||
|
||||
add(location, region);
|
||||
sender.sendMessage(StringUtils.colour("&aAdded configured region " + region + "!"));
|
||||
sender.sendMessage(StringUtils.colour("&e&oNow use /rpgregions edit "
|
||||
+ region
|
||||
+ " to edit it!"));
|
||||
player.sendMessage(StringUtils.colour("&e&oUse /rpgregions save to save this to file for editing."));
|
||||
sender.sendMessage(StringUtils.colour("&e&oUse /rpgregions save to save this to file for editing."));
|
||||
}
|
||||
|
||||
private void add(@NotNull final Location location, final String region) {
|
||||
ConfiguredRegion configuredRegion = new ConfiguredRegion(location.getWorld(), region, region, new ArrayList<>(),
|
||||
new ArrayList<>());
|
||||
configuredRegion.setLocation(location);
|
||||
plugin.getManagers().getRegionsCache().addConfiguredRegion(configuredRegion);
|
||||
}
|
||||
|
||||
@Subcommand("remove")
|
||||
|
||||
Reference in New Issue
Block a user