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