1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

Fix indentation

This commit is contained in:
TheBusyBiscuit 2020-01-11 20:20:49 +01:00
parent 2e7df8acd2
commit 86ec4e17ac
10 changed files with 120 additions and 120 deletions

View File

@ -14,54 +14,54 @@ import me.mrCookieSlime.Slimefun.api.PlayerProfile;
import me.mrCookieSlime.Slimefun.api.Slimefun; import me.mrCookieSlime.Slimefun.api.Slimefun;
public class AutoSavingService { public class AutoSavingService {
private int interval; private int interval;
public void start(Plugin plugin, int interval) { public void start(Plugin plugin, int interval) {
this.interval = interval; this.interval = interval;
plugin.getServer().getScheduler().runTaskTimer(plugin, this::saveAllPlayers, 2000L, interval * 60L * 20L); plugin.getServer().getScheduler().runTaskTimer(plugin, this::saveAllPlayers, 2000L, interval * 60L * 20L);
plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, this::saveAllBlocks, 2000L, interval * 60L * 20L); plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, this::saveAllBlocks, 2000L, interval * 60L * 20L);
} }
public void saveAllPlayers() { public void saveAllPlayers() {
Iterator<PlayerProfile> iterator = PlayerProfile.iterator(); Iterator<PlayerProfile> iterator = PlayerProfile.iterator();
int players = 0; int players = 0;
while (iterator.hasNext()) { while (iterator.hasNext()) {
PlayerProfile profile = iterator.next(); PlayerProfile profile = iterator.next();
if (profile.isDirty()) { if (profile.isDirty()) {
players++; players++;
profile.save(); profile.save();
} }
if (profile.isMarkedForDeletion()) iterator.remove(); if (profile.isMarkedForDeletion()) iterator.remove();
} }
if (players > 0) { if (players > 0) {
Slimefun.getLogger().log(Level.INFO, "Auto-Saved Player Data for {0} Player(s)!", players); Slimefun.getLogger().log(Level.INFO, "Auto-Saved Player Data for {0} Player(s)!", players);
} }
} }
public void saveAllBlocks() { public void saveAllBlocks() {
Set<BlockStorage> worlds = new HashSet<>(); Set<BlockStorage> worlds = new HashSet<>();
for (World world : Bukkit.getWorlds()) { for (World world : Bukkit.getWorlds()) {
if (BlockStorage.isWorldRegistered(world.getName())) { if (BlockStorage.isWorldRegistered(world.getName())) {
BlockStorage storage = BlockStorage.getStorage(world); BlockStorage storage = BlockStorage.getStorage(world);
storage.computeChanges(); storage.computeChanges();
if (storage.getChanges() > 0) { if (storage.getChanges() > 0) {
worlds.add(storage); worlds.add(storage);
} }
} }
} }
if (!worlds.isEmpty()) { if (!worlds.isEmpty()) {
Slimefun.getLogger().log(Level.INFO, "Auto-Saving Block Data... (Next Auto-Save: {0}m)", interval); Slimefun.getLogger().log(Level.INFO, "Auto-Saving Block Data... (Next Auto-Save: {0}m)", interval);
for (BlockStorage storage : worlds) { for (BlockStorage storage : worlds) {
storage.save(false); storage.save(false);
} }

View File

@ -9,18 +9,18 @@ import org.bukkit.plugin.Plugin;
import io.github.thebusybiscuit.cscorelib2.data.PersistentDataAPI; import io.github.thebusybiscuit.cscorelib2.data.PersistentDataAPI;
public class BlockDataService { public class BlockDataService {
private final NamespacedKey namespacedKey; private final NamespacedKey namespacedKey;
public BlockDataService(Plugin plugin, String key) { public BlockDataService(Plugin plugin, String key) {
namespacedKey = new NamespacedKey(plugin, key); namespacedKey = new NamespacedKey(plugin, key);
} }
public void setBlockData(TileState tileEntity, String value) { public void setBlockData(TileState tileEntity, String value) {
PersistentDataAPI.setString(tileEntity, namespacedKey, value); PersistentDataAPI.setString(tileEntity, namespacedKey, value);
tileEntity.update(); tileEntity.update();
} }
public Optional<String> getBlockData(TileState tileEntity) { public Optional<String> getBlockData(TileState tileEntity) {
return PersistentDataAPI.getOptionalString(tileEntity, namespacedKey); return PersistentDataAPI.getOptionalString(tileEntity, namespacedKey);
} }

View File

@ -10,9 +10,9 @@ import org.bukkit.plugin.Plugin;
import io.github.thebusybiscuit.cscorelib2.data.PersistentDataAPI; import io.github.thebusybiscuit.cscorelib2.data.PersistentDataAPI;
public class CustomItemDataService { public class CustomItemDataService {
private final NamespacedKey namespacedKey; private final NamespacedKey namespacedKey;
public CustomItemDataService(Plugin plugin, String key) { public CustomItemDataService(Plugin plugin, String key) {
namespacedKey = new NamespacedKey(plugin, key); namespacedKey = new NamespacedKey(plugin, key);
} }
@ -30,7 +30,7 @@ public class CustomItemDataService {
public Optional<String> getItemData(ItemStack item) { public Optional<String> getItemData(ItemStack item) {
return getItemData(item.getItemMeta()); return getItemData(item.getItemMeta());
} }
public Optional<String> getItemData(ItemMeta meta) { public Optional<String> getItemData(ItemMeta meta) {
return PersistentDataAPI.getOptionalString(meta, namespacedKey); return PersistentDataAPI.getOptionalString(meta, namespacedKey);
} }

View File

@ -8,17 +8,17 @@ import io.github.thebusybiscuit.cscorelib2.config.Config;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
public class CustomTextureService { public class CustomTextureService {
private final Config config; private final Config config;
private boolean modified = false; private boolean modified = false;
public CustomTextureService(Plugin plugin) { public CustomTextureService(Plugin plugin) {
this.config = new Config(plugin, "item-models.yml"); this.config = new Config(plugin, "item-models.yml");
} }
public void setup(Iterable<SlimefunItem> items) { public void setup(Iterable<SlimefunItem> items) {
config.setDefaultValue("SLIMEFUN_GUIDE", 0); config.setDefaultValue("SLIMEFUN_GUIDE", 0);
config.setDefaultValue("_UI_BACKGROUND", 0); config.setDefaultValue("_UI_BACKGROUND", 0);
config.setDefaultValue("_UI_BACK", 0); config.setDefaultValue("_UI_BACK", 0);
config.setDefaultValue("_UI_MENU", 0); config.setDefaultValue("_UI_MENU", 0);
@ -28,28 +28,28 @@ public class CustomTextureService {
config.setDefaultValue("_UI_PREVIOUS_INACTIVE", 0); config.setDefaultValue("_UI_PREVIOUS_INACTIVE", 0);
config.setDefaultValue("_UI_NEXT_ACTIVE", 0); config.setDefaultValue("_UI_NEXT_ACTIVE", 0);
config.setDefaultValue("_UI_NEXT_INACTIVE", 0); config.setDefaultValue("_UI_NEXT_INACTIVE", 0);
for (SlimefunItem item : items) { for (SlimefunItem item : items) {
if (item != null && item.getID() != null) { if (item != null && item.getID() != null) {
config.setDefaultValue(item.getID(), 0); config.setDefaultValue(item.getID(), 0);
if (config.getInt(item.getID()) != 0) { if (config.getInt(item.getID()) != 0) {
modified = true; modified = true;
} }
} }
} }
config.save(); config.save();
} }
public String getVersion() { public String getVersion() {
return config.getString("version"); return config.getString("version");
} }
public boolean isActive() { public boolean isActive() {
return modified; return modified;
} }
public int getModelData(String id) { public int getModelData(String id) {
return config.getInt(id); return config.getInt(id);
} }

View File

@ -19,51 +19,51 @@ import io.github.thebusybiscuit.slimefun4.core.services.github.GitHubTask;
import io.github.thebusybiscuit.slimefun4.utils.NumberUtils; import io.github.thebusybiscuit.slimefun4.utils.NumberUtils;
public class GitHubService { public class GitHubService {
private final String repository; private final String repository;
private final Set<GitHubConnector> connectors; private final Set<GitHubConnector> connectors;
private final ConcurrentMap<String, Contributor> contributors; private final ConcurrentMap<String, Contributor> contributors;
private boolean logging = false; private boolean logging = false;
private int issues = 0; private int issues = 0;
private int pullRequests = 0; private int pullRequests = 0;
private int forks = 0; private int forks = 0;
private int stars = 0; private int stars = 0;
private int codeBytes = 0; private int codeBytes = 0;
private Date lastUpdate = new Date(); private Date lastUpdate = new Date();
public GitHubService(String repository) { public GitHubService(String repository) {
this.repository = repository; this.repository = repository;
connectors = new HashSet<>(); connectors = new HashSet<>();
contributors = new ConcurrentHashMap<>(); contributors = new ConcurrentHashMap<>();
} }
public void start(Plugin plugin) { public void start(Plugin plugin) {
plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new GitHubTask(this), 80L, 60 * 60 * 20L); plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new GitHubTask(this), 80L, 60 * 60 * 20L);
} }
private void addDefaultContributors() { private void addDefaultContributors() {
Contributor thebusybiscuit = new Contributor("TheBusyBiscuit", "https://github.com/TheBusyBiscuit"); Contributor thebusybiscuit = new Contributor("TheBusyBiscuit", "https://github.com/TheBusyBiscuit");
thebusybiscuit.setContribution("&4Original Creator", 0); thebusybiscuit.setContribution("&4Original Creator", 0);
contributors.put(thebusybiscuit.getName(), thebusybiscuit); contributors.put(thebusybiscuit.getName(), thebusybiscuit);
Contributor fuffles = new Contributor("Fuffles_"); Contributor fuffles = new Contributor("Fuffles_");
fuffles.setContribution("&dSkull Texture Artist", 0); fuffles.setContribution("&dSkull Texture Artist", 0);
contributors.put(fuffles.getName(), fuffles); contributors.put(fuffles.getName(), fuffles);
} }
public void connect(boolean logging) { public void connect(boolean logging) {
this.logging = logging; this.logging = logging;
addDefaultContributors(); addDefaultContributors();
connectors.add(new ContributionsConnector(this, "code", repository, "&6Developer")); connectors.add(new ContributionsConnector(this, "code", repository, "&6Developer"));
connectors.add(new ContributionsConnector(this, "wiki", "TheBusyBiscuit/Slimefun4-wiki", "&3Wiki Editor")); connectors.add(new ContributionsConnector(this, "wiki", "TheBusyBiscuit/Slimefun4-wiki", "&3Wiki Editor"));
connectors.add(new ContributionsConnector(this, "resourcepack", "TheBusyBiscuit/Slimefun4-Resourcepack", "&cResourcepack Artist")); connectors.add(new ContributionsConnector(this, "resourcepack", "TheBusyBiscuit/Slimefun4-Resourcepack", "&cResourcepack Artist"));
connectors.add(new GitHubConnector(this) { connectors.add(new GitHubConnector(this) {
@Override @Override
public void onSuccess(JsonElement element) { public void onSuccess(JsonElement element) {
JsonObject object = element.getAsJsonObject(); JsonObject object = element.getAsJsonObject();
@ -71,12 +71,12 @@ public class GitHubService {
stars = object.get("stargazers_count").getAsInt(); stars = object.get("stargazers_count").getAsInt();
lastUpdate = NumberUtils.parseGitHubDate(object.get("pushed_at").getAsString()); lastUpdate = NumberUtils.parseGitHubDate(object.get("pushed_at").getAsString());
} }
@Override @Override
public String getRepository() { public String getRepository() {
return repository; return repository;
} }
@Override @Override
public String getFileName() { public String getFileName() {
return "repo"; return "repo";
@ -87,32 +87,32 @@ public class GitHubService {
return ""; return "";
} }
}); });
connectors.add(new GitHubConnector(this) { connectors.add(new GitHubConnector(this) {
@Override @Override
public void onSuccess(JsonElement element) { public void onSuccess(JsonElement element) {
JsonArray array = element.getAsJsonArray(); JsonArray array = element.getAsJsonArray();
int issueCount = 0; int issueCount = 0;
int prCount = 0; int prCount = 0;
for (JsonElement elem : array) { for (JsonElement elem : array) {
JsonObject obj = elem.getAsJsonObject(); JsonObject obj = elem.getAsJsonObject();
if (obj.has("pull_request")) prCount++; if (obj.has("pull_request")) prCount++;
else issueCount++; else issueCount++;
} }
issues = issueCount; issues = issueCount;
pullRequests = prCount; pullRequests = prCount;
} }
@Override @Override
public String getRepository() { public String getRepository() {
return repository; return repository;
} }
@Override @Override
public String getFileName() { public String getFileName() {
return "issues"; return "issues";
@ -123,20 +123,20 @@ public class GitHubService {
return "/issues"; return "/issues";
} }
}); });
connectors.add(new GitHubConnector(this) { connectors.add(new GitHubConnector(this) {
@Override @Override
public void onSuccess(JsonElement element) { public void onSuccess(JsonElement element) {
JsonObject object = element.getAsJsonObject(); JsonObject object = element.getAsJsonObject();
codeBytes = object.get("Java").getAsInt(); codeBytes = object.get("Java").getAsInt();
} }
@Override @Override
public String getRepository() { public String getRepository() {
return repository; return repository;
} }
@Override @Override
public String getFileName() { public String getFileName() {
return "languages"; return "languages";
@ -148,27 +148,27 @@ public class GitHubService {
} }
}); });
} }
public Set<GitHubConnector> getConnectors() { public Set<GitHubConnector> getConnectors() {
return connectors; return connectors;
} }
public ConcurrentMap<String, Contributor> getContributors() { public ConcurrentMap<String, Contributor> getContributors() {
return contributors; return contributors;
} }
public int getForks() { public int getForks() {
return forks; return forks;
} }
public int getStars() { public int getStars() {
return stars; return stars;
} }
public int getIssues() { public int getIssues() {
return issues; return issues;
} }
public int getPullRequests() { public int getPullRequests() {
return pullRequests; return pullRequests;
} }

View File

@ -21,7 +21,7 @@ import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.api.Slimefun; import me.mrCookieSlime.Slimefun.api.Slimefun;
public class LocalizationService extends SlimefunLocalization { public class LocalizationService extends SlimefunLocalization {
private static final String LANGUAGE_PATH = "language"; private static final String LANGUAGE_PATH = "language";
// All supported languages are stored in this LinkedHashMap, it is Linked so we keep the order // All supported languages are stored in this LinkedHashMap, it is Linked so we keep the order
@ -32,15 +32,15 @@ public class LocalizationService extends SlimefunLocalization {
public LocalizationService(SlimefunPlugin plugin, String serverDefaultLanguage) { public LocalizationService(SlimefunPlugin plugin, String serverDefaultLanguage) {
super(plugin); super(plugin);
this.plugin = plugin; this.plugin = plugin;
languageKey = new NamespacedKey(plugin, LANGUAGE_PATH); languageKey = new NamespacedKey(plugin, LANGUAGE_PATH);
defaultLanguage = new Language(serverDefaultLanguage, getConfig().getConfiguration(), "11b3188fd44902f72602bd7c2141f5a70673a411adb3d81862c69e536166b"); defaultLanguage = new Language(serverDefaultLanguage, getConfig().getConfiguration(), "11b3188fd44902f72602bd7c2141f5a70673a411adb3d81862c69e536166b");
loadLanguages(); loadLanguages();
String language = getConfig().getString(LANGUAGE_PATH); String language = getConfig().getString(LANGUAGE_PATH);
if (language == null) language = serverDefaultLanguage; if (language == null) language = serverDefaultLanguage;
if (hasLanguage(serverDefaultLanguage)) { if (hasLanguage(serverDefaultLanguage)) {
setLanguage(serverDefaultLanguage, !serverDefaultLanguage.equals(language)); setLanguage(serverDefaultLanguage, !serverDefaultLanguage.equals(language));
} }
@ -48,11 +48,11 @@ public class LocalizationService extends SlimefunLocalization {
setLanguage("en", false); setLanguage("en", false);
plugin.getLogger().log(Level.WARNING, "Could not recognize the given language: \"{0}\"", serverDefaultLanguage); plugin.getLogger().log(Level.WARNING, "Could not recognize the given language: \"{0}\"", serverDefaultLanguage);
} }
setPrefix("&aSlimefun 4 &7> "); setPrefix("&aSlimefun 4 &7> ");
save(); save();
} }
private void loadLanguages() { private void loadLanguages() {
addLanguage("en", "a1701f21835a898b20759fb30a583a38b994abf60d3912ab4ce9f2311e74f72"); addLanguage("en", "a1701f21835a898b20759fb30a583a38b994abf60d3912ab4ce9f2311e74f72");
} }
@ -66,7 +66,7 @@ public class LocalizationService extends SlimefunLocalization {
public Language getLanguage(String id) { public Language getLanguage(String id) {
return languages.get(id); return languages.get(id);
} }
@Override @Override
public Collection<Language> getLanguages() { public Collection<Language> getLanguages() {
return languages.values(); return languages.values();
@ -85,11 +85,11 @@ public class LocalizationService extends SlimefunLocalization {
@Override @Override
public Language getLanguage(Player p) { public Language getLanguage(Player p) {
Optional<String> language = PersistentDataAPI.getOptionalString(p, languageKey); Optional<String> language = PersistentDataAPI.getOptionalString(p, languageKey);
if (language.isPresent()) return languages.get(language.get()); if (language.isPresent()) return languages.get(language.get());
else return getDefaultLanguage(); else return getDefaultLanguage();
} }
private void setLanguage(String language, boolean reset) { private void setLanguage(String language, boolean reset) {
// Clearing out the old Language (if necessary) // Clearing out the old Language (if necessary)
if (reset) { if (reset) {
@ -97,26 +97,26 @@ public class LocalizationService extends SlimefunLocalization {
getConfig().setValue(key, null); getConfig().setValue(key, null);
} }
} }
Slimefun.getLogger().log(Level.INFO, "Loading language \"{0}\"", language); Slimefun.getLogger().log(Level.INFO, "Loading language \"{0}\"", language);
getConfig().setValue(LANGUAGE_PATH, language); getConfig().setValue(LANGUAGE_PATH, language);
// Loading in the defaults from our resources folder // Loading in the defaults from our resources folder
String path = "/languages/messages_" + language + ".yml"; String path = "/languages/messages_" + language + ".yml";
try (BufferedReader reader = new BufferedReader(new InputStreamReader(plugin.getClass().getResourceAsStream(path)))) { try (BufferedReader reader = new BufferedReader(new InputStreamReader(plugin.getClass().getResourceAsStream(path)))) {
FileConfiguration config = YamlConfiguration.loadConfiguration(reader); FileConfiguration config = YamlConfiguration.loadConfiguration(reader);
getConfig().getConfiguration().setDefaults(config); getConfig().getConfiguration().setDefaults(config);
} catch (IOException e) { } catch (IOException e) {
Slimefun.getLogger().log(Level.SEVERE, "Failed to load language file: \"" + path + "\"", e); Slimefun.getLogger().log(Level.SEVERE, "Failed to load language file: \"" + path + "\"", e);
} }
save(); save();
} }
private void addLanguage(String id, String hash) { private void addLanguage(String id, String hash) {
FileConfiguration cfg; FileConfiguration cfg;
if (!hasLanguage(id)) { if (!hasLanguage(id)) {
cfg = getConfig().getConfiguration(); cfg = getConfig().getConfiguration();
} }
@ -125,12 +125,12 @@ public class LocalizationService extends SlimefunLocalization {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(plugin.getClass().getResourceAsStream(path)))) { try (BufferedReader reader = new BufferedReader(new InputStreamReader(plugin.getClass().getResourceAsStream(path)))) {
cfg = YamlConfiguration.loadConfiguration(reader); cfg = YamlConfiguration.loadConfiguration(reader);
cfg.setDefaults(getConfig().getConfiguration()); cfg.setDefaults(getConfig().getConfiguration());
} catch (IOException e) { } catch (IOException e) {
Slimefun.getLogger().log(Level.SEVERE, "Failed to load language file into memory: \"" + path + "\"", e); Slimefun.getLogger().log(Level.SEVERE, "Failed to load language file into memory: \"" + path + "\"", e);
cfg = getConfig().getConfiguration(); cfg = getConfig().getConfiguration();
} }
} }
languages.put(id, new Language(id, cfg, hash)); languages.put(id, new Language(id, cfg, hash));
} }
} }

View File

@ -14,14 +14,14 @@ public class MetricsService extends Metrics {
public MetricsService(SlimefunPlugin plugin) { public MetricsService(SlimefunPlugin plugin) {
super(plugin); super(plugin);
addCustomChart(new SimplePie("auto_updates", () -> addCustomChart(new SimplePie("auto_updates", () ->
SlimefunPlugin.getCfg().getBoolean("options.auto-update") ? "enabled": "disabled" SlimefunPlugin.getCfg().getBoolean("options.auto-update") ? "enabled": "disabled"
)); ));
addCustomChart(new SimplePie("resourcepack", () -> { addCustomChart(new SimplePie("resourcepack", () -> {
String version = SlimefunPlugin.getItemTextureService().getVersion(); String version = SlimefunPlugin.getItemTextureService().getVersion();
if (version != null && version.startsWith("v")) { if (version != null && version.startsWith("v")) {
return version + " (Official)"; return version + " (Official)";
} }
@ -32,7 +32,7 @@ public class MetricsService extends Metrics {
return "None"; return "None";
} }
})); }));
addCustomChart(new SimplePie("branch", () -> { addCustomChart(new SimplePie("branch", () -> {
if (plugin.getDescription().getVersion().startsWith("DEV - ")) { if (plugin.getDescription().getVersion().startsWith("DEV - ")) {
return "master"; return "master";
@ -44,20 +44,20 @@ public class MetricsService extends Metrics {
return "Unknown"; return "Unknown";
} }
})); }));
addCustomChart(new SimplePie("language", () -> { addCustomChart(new SimplePie("language", () -> {
Language language = SlimefunPlugin.getLocal().getDefaultLanguage(); Language language = SlimefunPlugin.getLocal().getDefaultLanguage();
return language.getID(); return language.getID();
})); }));
addCustomChart(new AdvancedPie("player_languages", () -> { addCustomChart(new AdvancedPie("player_languages", () -> {
Map<String, Integer> languages = new HashMap<>(); Map<String, Integer> languages = new HashMap<>();
for (Player p : Bukkit.getOnlinePlayers()) { for (Player p : Bukkit.getOnlinePlayers()) {
Language lang = SlimefunPlugin.getLocal().getLanguage(p); Language lang = SlimefunPlugin.getLocal().getLanguage(p);
languages.merge(lang.getID(), 1, Integer::sum); languages.merge(lang.getID(), 1, Integer::sum);
} }
return languages; return languages;
})); }));
} }

View File

@ -10,12 +10,12 @@ import io.github.thebusybiscuit.cscorelib2.updater.GitHubBuildsUpdater;
import io.github.thebusybiscuit.cscorelib2.updater.Updater; import io.github.thebusybiscuit.cscorelib2.updater.Updater;
public class UpdaterService { public class UpdaterService {
private final Updater updater; private final Updater updater;
public UpdaterService(Plugin plugin, File file) { public UpdaterService(Plugin plugin, File file) {
String version = plugin.getDescription().getVersion(); String version = plugin.getDescription().getVersion();
if (version.equals("UNOFFICIAL")) { if (version.equals("UNOFFICIAL")) {
// This Server is using a modified build that is not a public release. // This Server is using a modified build that is not a public release.
plugin.getLogger().log(Level.WARNING, "It looks like you are using an unofficially modified build of Slimefun!"); plugin.getLogger().log(Level.WARNING, "It looks like you are using an unofficially modified build of Slimefun!");
@ -35,7 +35,7 @@ public class UpdaterService {
updater = new BukkitUpdater(plugin, file, 53485); updater = new BukkitUpdater(plugin, file, 53485);
} }
} }
public void start() { public void start() {
if (updater != null) { if (updater != null) {
updater.start(); updater.start();

View File

@ -8,25 +8,25 @@ import io.github.thebusybiscuit.cscorelib2.skull.SkullItem;
import me.mrCookieSlime.Slimefun.SlimefunPlugin; import me.mrCookieSlime.Slimefun.SlimefunPlugin;
public final class Language { public final class Language {
private final String id; private final String id;
private final FileConfiguration config; private final FileConfiguration config;
private final ItemStack item; private final ItemStack item;
public Language(String id, FileConfiguration config, String hash) { public Language(String id, FileConfiguration config, String hash) {
this.id = id; this.id = id;
this.config = config; this.config = config;
this.item = SkullItem.fromHash(hash); this.item = SkullItem.fromHash(hash);
} }
public String getID() { public String getID() {
return id; return id;
} }
public FileConfiguration getConfig() { public FileConfiguration getConfig() {
return config; return config;
} }
public ItemStack getItem() { public ItemStack getItem() {
return item; return item;
} }
@ -34,7 +34,7 @@ public final class Language {
public String getName(Player p) { public String getName(Player p) {
return SlimefunPlugin.getLocal().getMessage(p, "languages." + id); return SlimefunPlugin.getLocal().getMessage(p, "languages." + id);
} }
public boolean isDefault() { public boolean isDefault() {
return this == SlimefunPlugin.getLocal().getDefaultLanguage(); return this == SlimefunPlugin.getLocal().getDefaultLanguage();
} }

View File

@ -14,36 +14,36 @@ import io.github.thebusybiscuit.cscorelib2.config.Localization;
import me.mrCookieSlime.Slimefun.SlimefunPlugin; import me.mrCookieSlime.Slimefun.SlimefunPlugin;
public abstract class SlimefunLocalization extends Localization implements Keyed{ public abstract class SlimefunLocalization extends Localization implements Keyed{
public SlimefunLocalization(SlimefunPlugin plugin) { public SlimefunLocalization(SlimefunPlugin plugin) {
super(plugin); super(plugin);
} }
public abstract Language getLanguage(String id); public abstract Language getLanguage(String id);
public abstract Language getLanguage(Player p); public abstract Language getLanguage(Player p);
public abstract Language getDefaultLanguage(); public abstract Language getDefaultLanguage();
public abstract boolean hasLanguage(String id); public abstract boolean hasLanguage(String id);
public abstract Collection<Language> getLanguages(); public abstract Collection<Language> getLanguages();
public String getPrefix() { public String getPrefix() {
return getMessage("prefix"); return getMessage("prefix");
} }
public String getMessage(Player p, String key) { public String getMessage(Player p, String key) {
Language language = getLanguage(p); Language language = getLanguage(p);
return language.getConfig().getString(key); return language.getConfig().getString(key);
} }
public List<String> getMessages(Player p, String key) { public List<String> getMessages(Player p, String key) {
Language language = getLanguage(p); Language language = getLanguage(p);
return language.getConfig().getStringList(key); return language.getConfig().getStringList(key);
} }
@Override @Override
public void sendMessage(CommandSender sender, String key) { public void sendMessage(CommandSender sender, String key) {
String prefix = getPrefix(); String prefix = getPrefix();
if (sender instanceof Player) { if (sender instanceof Player) {
sender.sendMessage(ChatColors.color(prefix + getMessage((Player) sender, key))); sender.sendMessage(ChatColors.color(prefix + getMessage((Player) sender, key)));
} }
@ -51,15 +51,15 @@ public abstract class SlimefunLocalization extends Localization implements Keyed
sender.sendMessage(ChatColor.stripColor(ChatColors.color(prefix + getMessage(key)))); sender.sendMessage(ChatColor.stripColor(ChatColors.color(prefix + getMessage(key))));
} }
} }
@Override @Override
public void sendMessage(CommandSender sender, String key, boolean addPrefix) { public void sendMessage(CommandSender sender, String key, boolean addPrefix) {
sendMessage(sender, key); sendMessage(sender, key);
} }
public void sendMessage(CommandSender sender, String key, UnaryOperator<String> function) { public void sendMessage(CommandSender sender, String key, UnaryOperator<String> function) {
String prefix = getPrefix(); String prefix = getPrefix();
if (sender instanceof Player) { if (sender instanceof Player) {
sender.sendMessage(ChatColors.color(prefix + function.apply(getMessage((Player) sender, key)))); sender.sendMessage(ChatColors.color(prefix + function.apply(getMessage((Player) sender, key))));
} }
@ -67,16 +67,16 @@ public abstract class SlimefunLocalization extends Localization implements Keyed
sender.sendMessage(ChatColor.stripColor(ChatColors.color(prefix + function.apply(getMessage(key))))); sender.sendMessage(ChatColor.stripColor(ChatColors.color(prefix + function.apply(getMessage(key)))));
} }
} }
@Override @Override
public void sendMessage(CommandSender sender, String key, boolean addPrefix, UnaryOperator<String> function) { public void sendMessage(CommandSender sender, String key, boolean addPrefix, UnaryOperator<String> function) {
sendMessage(sender, key, function); sendMessage(sender, key, function);
} }
@Override @Override
public void sendMessages(CommandSender sender, String key) { public void sendMessages(CommandSender sender, String key) {
String prefix = getPrefix(); String prefix = getPrefix();
if (sender instanceof Player) { if (sender instanceof Player) {
for (String translation : getMessages((Player) sender, key)) { for (String translation : getMessages((Player) sender, key)) {
String message = ChatColors.color(prefix + translation); String message = ChatColors.color(prefix + translation);
@ -90,15 +90,15 @@ public abstract class SlimefunLocalization extends Localization implements Keyed
} }
} }
} }
@Override @Override
public void sendMessages(CommandSender sender, String key, boolean addPrefix, UnaryOperator<String> function) { public void sendMessages(CommandSender sender, String key, boolean addPrefix, UnaryOperator<String> function) {
sendMessages(sender, key, function); sendMessages(sender, key, function);
} }
public void sendMessages(CommandSender sender, String key, UnaryOperator<String> function) { public void sendMessages(CommandSender sender, String key, UnaryOperator<String> function) {
String prefix = getPrefix(); String prefix = getPrefix();
if (sender instanceof Player) { if (sender instanceof Player) {
for (String translation : getMessages((Player) sender, key)) { for (String translation : getMessages((Player) sender, key)) {
String message = ChatColors.color(prefix + function.apply(translation)); String message = ChatColors.color(prefix + function.apply(translation));