Skip to content

Commit 7e2fc71

Browse files
committed
Improve group worldname validation on deserialize
1 parent c29e392 commit 7e2fc71

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

src/main/java/org/mvplugins/multiverse/inventories/profile/group/YamlWorldGroupManager.java

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import com.dumptruckman.minecraft.util.Logging;
44
import com.google.common.collect.Lists;
5+
import org.apache.logging.log4j.util.Strings;
56
import org.jvnet.hk2.annotations.Service;
67
import org.mvplugins.multiverse.core.command.MVCommandManager;
8+
import org.mvplugins.multiverse.core.utils.StringFormatter;
79
import org.mvplugins.multiverse.core.world.WorldManager;
810
import org.mvplugins.multiverse.external.commentedconfiguration.CommentedConfiguration;
911
import org.mvplugins.multiverse.external.jakarta.inject.Inject;
@@ -14,12 +16,11 @@
1416
import org.mvplugins.multiverse.inventories.profile.container.ProfileContainerStoreProvider;
1517
import org.mvplugins.multiverse.inventories.share.Sharables;
1618
import org.mvplugins.multiverse.inventories.util.DeserializationException;
17-
import org.bukkit.Bukkit;
18-
import org.bukkit.World;
1919
import org.bukkit.configuration.Configuration;
2020
import org.bukkit.configuration.ConfigurationSection;
2121
import org.bukkit.configuration.file.FileConfiguration;
2222
import org.bukkit.event.EventPriority;
23+
import org.mvplugins.multiverse.inventories.util.GroupWorldNameValidator;
2324

2425
import java.io.File;
2526
import java.util.ArrayList;
@@ -38,6 +39,8 @@ final class YamlWorldGroupManager extends AbstractWorldGroupManager {
3839
"# No support will be given for those who manually edit these groups."
3940
};
4041

42+
private final GroupWorldNameValidator groupWorldNameValidator;
43+
4144
private CommentedConfiguration groupsConfig;
4245

4346
@Inject
@@ -46,8 +49,10 @@ final class YamlWorldGroupManager extends AbstractWorldGroupManager {
4649
@NotNull MVCommandManager commandManager,
4750
@NotNull InventoriesConfig inventoriesConfig,
4851
@NotNull ProfileContainerStoreProvider profileContainerStoreProvider,
49-
@NotNull WorldManager worldManager) {
52+
@NotNull WorldManager worldManager,
53+
@NotNull GroupWorldNameValidator groupWorldNameValidator) {
5054
super(plugin, commandManager, inventoriesConfig, profileContainerStoreProvider, worldManager);
55+
this.groupWorldNameValidator = groupWorldNameValidator;
5156
}
5257

5358
@Override
@@ -151,25 +156,23 @@ private WorldGroup deserializeGroup(final String name, final Map<String, Object>
151156
Logging.fine("No worlds for group: " + name);
152157
} else {
153158
if (!(worldListObj instanceof List)) {
154-
Logging.fine("World list formatted incorrectly for world group: " + name);
159+
Logging.warning("World list formatted incorrectly for world group: " + name);
155160
} else {
156-
final StringBuilder builder = new StringBuilder();
161+
final List<String> invalidWorlds = new ArrayList<>();
157162
for (Object worldNameObj : (List) worldListObj) {
158163
if (worldNameObj == null) {
159-
Logging.fine("Error with a world listed in group: " + name);
164+
Logging.warning("Error with a world listed in group: " + name);
160165
continue;
161166
}
162-
profile.addWorld(worldNameObj.toString(), false);
163-
World world = Bukkit.getWorld(worldNameObj.toString());
164-
if (world == null) {
165-
if (!builder.isEmpty()) {
166-
builder.append(", ");
167-
}
168-
builder.append(worldNameObj);
167+
String worldName = worldNameObj.toString();
168+
profile.addWorld(worldName, false);
169+
if (!groupWorldNameValidator.validateWorldName(worldName)) {
170+
invalidWorlds.add(worldName);
169171
}
170172
}
171-
if (!builder.isEmpty()) {
172-
Logging.config("The following worlds for group '%s' are not loaded: %s", name, builder.toString());
173+
if (!invalidWorlds.isEmpty()) {
174+
Logging.warning("The following worlds for group '%s' does not exist: %s",
175+
name, StringFormatter.join(invalidWorlds, ", "));
173176
}
174177
}
175178
}

0 commit comments

Comments
 (0)