mirror of
				https://github.com/IntellectualSites/PlotSquared.git
				synced 2025-11-04 03:03:43 +01:00 
			
		
		
		
	Compare commits
	
		
			3 Commits
		
	
	
		
			fix/plot-c
			...
			fix/missin
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					4a703a305b | ||
| 
						 | 
					f9f1a21cab | ||
| 
						 | 
					dce4922d34 | 
@@ -732,6 +732,11 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
 | 
			
		||||
        this.getServer().getPluginManager().disablePlugin(this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void shutdownServer() {
 | 
			
		||||
        getServer().shutdown();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void registerCommands() {
 | 
			
		||||
        final BukkitCommand bukkitCommand = new BukkitCommand();
 | 
			
		||||
        final PluginCommand plotCommand = getCommand("plots");
 | 
			
		||||
 
 | 
			
		||||
@@ -75,6 +75,11 @@ public interface PlotPlatform<P> extends LocaleHolder {
 | 
			
		||||
     */
 | 
			
		||||
    void shutdown();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Completely shuts down the server.
 | 
			
		||||
     */
 | 
			
		||||
    void shutdownServer();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the name of the plugin
 | 
			
		||||
     *
 | 
			
		||||
 
 | 
			
		||||
@@ -197,6 +197,9 @@ public class PlotSquared {
 | 
			
		||||
            this.loadCaptionMap();
 | 
			
		||||
        } catch (final Exception e) {
 | 
			
		||||
            LOGGER.error("Failed to load caption map", e);
 | 
			
		||||
            LOGGER.error("Shutting down server to prevent further issues");
 | 
			
		||||
            this.platform.shutdownServer();
 | 
			
		||||
            throw new RuntimeException("Abort loading PlotSquared");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Setup the global flag container
 | 
			
		||||
@@ -267,7 +270,7 @@ public class PlotSquared {
 | 
			
		||||
            captionMap = this.captionLoader.loadAll(this.platform.getDirectory().toPath().resolve("lang"));
 | 
			
		||||
        } else {
 | 
			
		||||
            String fileName = "messages_" + Settings.Enabled_Components.DEFAULT_LOCALE + ".json";
 | 
			
		||||
            captionMap = this.captionLoader.loadSingle(this.platform.getDirectory().toPath().resolve("lang").resolve(fileName));
 | 
			
		||||
            captionMap = this.captionLoader.loadOrCreateSingle(this.platform.getDirectory().toPath().resolve("lang").resolve(fileName));
 | 
			
		||||
        }
 | 
			
		||||
        this.captionMaps.put(TranslatableCaption.DEFAULT_NAMESPACE, captionMap);
 | 
			
		||||
        LOGGER.info(
 | 
			
		||||
 
 | 
			
		||||
@@ -190,13 +190,14 @@ public final class CaptionLoader {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Load a message file into a new CaptionMap. The file name must match
 | 
			
		||||
     * the pattern {@code messages_<locale>.json} where {@code <locale>}
 | 
			
		||||
     * is a valid {@link Locale} string.
 | 
			
		||||
     * the pattern expected by the {@link #localeExtractor}.
 | 
			
		||||
     * Note that this method does not attempt to create a new file.
 | 
			
		||||
     *
 | 
			
		||||
     * @param file The file to load
 | 
			
		||||
     * @return A new CaptionMap containing the loaded messages
 | 
			
		||||
     * @throws IOException              if the file couldn't be accessed or read successfully.
 | 
			
		||||
     * @throws IllegalArgumentException if the file name doesn't match the specified format.
 | 
			
		||||
     * @see #loadOrCreateSingle(Path)
 | 
			
		||||
     */
 | 
			
		||||
    public @NonNull CaptionMap loadSingle(final @NonNull Path file) throws IOException {
 | 
			
		||||
        final Locale locale = this.localeExtractor.apply(file);
 | 
			
		||||
@@ -205,14 +206,42 @@ public final class CaptionLoader {
 | 
			
		||||
            if (patch(map, locale)) {
 | 
			
		||||
                save(file, map); // update the file using the modified map
 | 
			
		||||
            }
 | 
			
		||||
            return new LocalizedCaptionMap(locale, map.entrySet().stream()
 | 
			
		||||
                    .collect(Collectors.toMap(
 | 
			
		||||
            return new LocalizedCaptionMap(locale, mapToCaptions(map));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Load a message file into a new CaptionMap. The file name must match
 | 
			
		||||
     * the pattern expected by the {@link #localeExtractor}.
 | 
			
		||||
     * If no file exists at the given path, this method will
 | 
			
		||||
     * attempt to create one and fill it with default values.
 | 
			
		||||
     *
 | 
			
		||||
     * @param file The file to load
 | 
			
		||||
     * @return A new CaptionMap containing the loaded messages
 | 
			
		||||
     * @throws IOException              if the file couldn't be accessed or read successfully.
 | 
			
		||||
     * @throws IllegalArgumentException if the file name doesn't match the specified format.
 | 
			
		||||
     * @see #loadSingle(Path)
 | 
			
		||||
     * @since TODO
 | 
			
		||||
     */
 | 
			
		||||
    public @NonNull CaptionMap loadOrCreateSingle(final @NonNull Path file) throws IOException {
 | 
			
		||||
        final Locale locale = this.localeExtractor.apply(file);
 | 
			
		||||
        if (!Files.exists(file) ) {
 | 
			
		||||
            Map<String, String> map = new LinkedHashMap<>();
 | 
			
		||||
            patch(map, locale);
 | 
			
		||||
            save(file, map);
 | 
			
		||||
            return new LocalizedCaptionMap(locale, mapToCaptions(map));
 | 
			
		||||
        } else {
 | 
			
		||||
            return loadSingle(file);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private @NonNull Map<TranslatableCaption, String> mapToCaptions(Map<String, String> map) {
 | 
			
		||||
        return map.entrySet().stream().collect(
 | 
			
		||||
                Collectors.toMap(
 | 
			
		||||
                        entry -> TranslatableCaption.of(this.namespace, entry.getKey()),
 | 
			
		||||
                        Map.Entry::getValue
 | 
			
		||||
                            )
 | 
			
		||||
                ));
 | 
			
		||||
    }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Add missing entries to the given map.
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user