Skip to content

Commit

Permalink
feat: Add support for add/remove multiple worlds from group
Browse files Browse the repository at this point in the history
  • Loading branch information
benwoo1110 committed Feb 16, 2023
1 parent 917bcb8 commit e12b05c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import com.onarandombox.MultiverseCore.api.MVPlugin;
import com.onarandombox.MultiverseCore.commandtools.MVCommandManager;
import com.onarandombox.multiverseinventories.command.AddSharesCommand;
import com.onarandombox.multiverseinventories.command.AddWorldCommand;
import com.onarandombox.multiverseinventories.command.AddWorldsCommand;
import com.onarandombox.multiverseinventories.command.CreateGroupCommand;
import com.onarandombox.multiverseinventories.command.DeleteGroupCommand;
import com.onarandombox.multiverseinventories.command.GroupCommand;
Expand All @@ -22,7 +22,7 @@
import com.onarandombox.multiverseinventories.command.MigrateCommand;
import com.onarandombox.multiverseinventories.command.ReloadCommand;
import com.onarandombox.multiverseinventories.command.RemoveSharesCommand;
import com.onarandombox.multiverseinventories.command.RemoveWorldCommand;
import com.onarandombox.multiverseinventories.command.RemoveWorldsCommand;
import com.onarandombox.multiverseinventories.command.SpawnCommand;
import com.onarandombox.multiverseinventories.command.ToggleCommand;
import com.onarandombox.multiverseinventories.command.tools.MVInvCommandCompletions;
Expand Down Expand Up @@ -202,7 +202,7 @@ private void registerCommands() {

MVCommandManager commandManager = this.getCore().getMVCommandManager();
commandManager.registerCommand(new AddSharesCommand(this));
commandManager.registerCommand(new AddWorldCommand(this));
commandManager.registerCommand(new AddWorldsCommand(this));
commandManager.registerCommand(new CreateGroupCommand(this));
commandManager.registerCommand(new DeleteGroupCommand(this));
commandManager.registerCommand(new GroupCommand(this));
Expand All @@ -212,7 +212,7 @@ private void registerCommands() {
commandManager.registerCommand(new MigrateCommand(this));
commandManager.registerCommand(new ReloadCommand(this));
commandManager.registerCommand(new RemoveSharesCommand(this));
commandManager.registerCommand(new RemoveWorldCommand(this));
commandManager.registerCommand(new RemoveWorldsCommand(this));
commandManager.registerCommand(new SpawnCommand(this));
commandManager.registerCommand(new ToggleCommand(this));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.onarandombox.multiverseinventories.command;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import com.onarandombox.MultiverseCore.api.MVWorld;
import com.onarandombox.acf.BukkitCommandIssuer;
import com.onarandombox.acf.annotation.CommandAlias;
Expand All @@ -14,33 +18,34 @@
import org.jetbrains.annotations.NotNull;

@CommandAlias("mvinv")
public class AddWorldCommand extends InventoriesCommand {
public AddWorldCommand(@NotNull MultiverseInventories plugin) {
public class AddWorldsCommand extends InventoriesCommand {
public AddWorldsCommand(@NotNull MultiverseInventories plugin) {
super(plugin);
setPerm(Perm.COMMAND_ADDWORLD);
}

@Subcommand("addworld")
@CommandCompletion("@mvworlds @worldGroups")
@Syntax("<world> <group>")
@Subcommand("addworlds")
@CommandCompletion("@mvworlds:multiple @worldGroups")
@Syntax("<world[,extra]> <group>")
@Description("Adds a World to a World Group.")
public void onAddWorldCommand(BukkitCommandIssuer issuer,

@Syntax("<world>")
@Description("World name to add.")
MVWorld world,
MVWorld[] world,

@Syntax("<group>")
@Description("Group you want to add the world to.")
WorldGroup group
) {
if (group.containsWorld(world.getName())) {
this.messager.normal(Message.WORLD_ALREADY_EXISTS, issuer.getIssuer(), world.getName(), group.getName());
List<String> worldNames = Arrays.stream(world).map(MVWorld::getName).collect(Collectors.toList());
String worldNamesString = String.join(", ", worldNames);
if (!group.getWorlds().addAll(worldNames)) {
this.messager.normal(Message.WORLD_ALREADY_EXISTS, issuer.getIssuer(), worldNamesString, group.getName());
return;
}
group.addWorld(world.getCBWorld());
this.plugin.getGroupManager().updateGroup(group);
this.plugin.getMVIConfig().save();
this.messager.normal(Message.WORLD_ADDED, issuer.getIssuer(), world.getName(), group.getName());
this.messager.normal(Message.WORLD_ADDED, issuer.getIssuer(), worldNamesString, group.getName());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.onarandombox.multiverseinventories.command;

import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;

import com.onarandombox.MultiverseCore.api.MVWorld;
import com.onarandombox.acf.BukkitCommandIssuer;
import com.onarandombox.acf.annotation.CommandAlias;
Expand All @@ -14,33 +18,34 @@
import org.jetbrains.annotations.NotNull;

@CommandAlias("mvinv")
public class RemoveWorldCommand extends InventoriesCommand {
public RemoveWorldCommand(@NotNull MultiverseInventories plugin) {
public class RemoveWorldsCommand extends InventoriesCommand {
public RemoveWorldsCommand(@NotNull MultiverseInventories plugin) {
super(plugin);
setPerm(Perm.COMMAND_ADDWORLD);
}

@Subcommand("removeworld")
@Subcommand("removeworlds")
@CommandCompletion("@mvworlds @worldGroups")
@Syntax("<world> <group>")
@Syntax("<world[,extra]> <group>")
@Description("Adds a World to a World Group.")
public void onRemoveWorldCommand(BukkitCommandIssuer issuer,

@Syntax("<world>")
@Description("World name to remove.")
MVWorld world,
MVWorld[] world,

@Syntax("<group>")
@Description("Group you want to remove the world from.")
@NotNull WorldGroup group
) {
if (!group.containsWorld(world.getName())) {
this.messager.normal(Message.WORLD_NOT_IN_GROUP, issuer.getIssuer(), world.getName(), group.getName());
Set<String> worldNames = Arrays.stream(world).map(MVWorld::getName).collect(Collectors.toSet());
String worldNamesString = String.join(", ", worldNames);
if (!group.getWorlds().removeAll(worldNames)) {
this.messager.normal(Message.WORLD_NOT_IN_GROUP, issuer.getIssuer(), worldNamesString, group.getName());
return;
}
group.removeWorld(world.getCBWorld());
this.plugin.getGroupManager().updateGroup(group);
this.plugin.getMVIConfig().save();
this.messager.normal(Message.WORLD_REMOVED, issuer.getIssuer(), world.getName(), group.getName());
this.messager.normal(Message.WORLD_REMOVED, issuer.getIssuer(), worldNamesString, group.getName());
}
}

0 comments on commit e12b05c

Please sign in to comment.