mirror of
https://gitlab.com/SamB440/rpgregions-2.git
synced 2026-01-04 15:31:38 +00:00
Update to Languagy 3, temporarily disable fog effects
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package net.islandearth.rpgregions.api;
|
||||
|
||||
import com.convallyria.languagy.api.language.Translator;
|
||||
import com.google.gson.Gson;
|
||||
import net.islandearth.languagy.api.language.Translator;
|
||||
import net.islandearth.rpgregions.managers.IRPGRegionsManagers;
|
||||
import org.bukkit.configuration.Configuration;
|
||||
|
||||
|
||||
@@ -236,7 +236,7 @@ public class ConfiguredRegion {
|
||||
@NotNull
|
||||
public List<String> getTitle(Player player) {
|
||||
if (title == null) {
|
||||
return Translations.DISCOVERED_TITLE.getList(player, customName);
|
||||
return Translations.DISCOVERED_TITLE.get(player, customName);
|
||||
}
|
||||
|
||||
List<String> translatedTitle = new ArrayList<>();
|
||||
@@ -252,7 +252,7 @@ public class ConfiguredRegion {
|
||||
@NotNull
|
||||
public List<String> getSubtitle(Player player) {
|
||||
if (subtitle == null) {
|
||||
return Translations.DISCOVERED_SUBTITLE.getList(player, customName);
|
||||
return Translations.DISCOVERED_SUBTITLE.get(player, customName);
|
||||
}
|
||||
|
||||
List<String> translatedSubtitle = new ArrayList<>();
|
||||
@@ -268,7 +268,7 @@ public class ConfiguredRegion {
|
||||
@NotNull
|
||||
public List<String> getDiscoveredTitle(Player player) {
|
||||
if (discoveredTitle == null) {
|
||||
return Translations.ALREADY_DISCOVERED_TITLE.getList(player, customName);
|
||||
return Translations.ALREADY_DISCOVERED_TITLE.get(player, customName);
|
||||
}
|
||||
|
||||
List<String> translatedTitle = new ArrayList<>();
|
||||
@@ -284,7 +284,7 @@ public class ConfiguredRegion {
|
||||
@NotNull
|
||||
public List<String> getDiscoveredSubtitle(Player player) {
|
||||
if (discoveredSubtitle == null) {
|
||||
return Translations.ALREADY_DISCOVERED_SUBTITLE.getList(player, customName);
|
||||
return Translations.ALREADY_DISCOVERED_SUBTITLE.get(player, customName);
|
||||
}
|
||||
|
||||
List<String> translatedSubtitle = new ArrayList<>();
|
||||
|
||||
@@ -22,9 +22,9 @@ public enum PreventType {
|
||||
}
|
||||
|
||||
if (getVersionNumber() <= 17) {
|
||||
player.spawnParticle(Particle.BARRIER, event.getTo().getBlock().getLocation().add(0.5, 0.5, 0.5), 1);
|
||||
player.spawnParticle(Particle.valueOf("BARRIER"), event.getTo().getBlock().getLocation().add(0.5, 0.5, 0.5), 1);
|
||||
} else {
|
||||
player.spawnParticle(Particle.valueOf("BLOCK_MARKER"), event.getTo().getBlock().getLocation().add(0.5, 0.5, 0.5), 1, Material.BARRIER.createBlockData());
|
||||
player.spawnParticle(Particle.BLOCK_MARKER, event.getTo().getBlock().getLocation().add(0.5, 0.5, 0.5), 1, Material.BARRIER.createBlockData());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package net.islandearth.rpgregions.translation;
|
||||
|
||||
import com.convallyria.languagy.api.language.Language;
|
||||
import com.convallyria.languagy.api.language.key.LanguageKey;
|
||||
import com.convallyria.languagy.api.language.key.TranslationKey;
|
||||
import com.convallyria.languagy.api.language.translation.Translation;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.islandearth.languagy.api.language.Language;
|
||||
import net.islandearth.rpgregions.api.IRPGRegionsAPI;
|
||||
import net.islandearth.rpgregions.api.RPGRegionsAPI;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -11,47 +14,37 @@ import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public enum Translations {
|
||||
NEXT_PAGE("&aNext Page"),
|
||||
NEXT_PAGE_LORE("&fGo to the next page", true),
|
||||
PREVIOUS_PAGE("&cPrevious Page"),
|
||||
PREVIOUS_PAGE_LORE("&fGo to the previous page", true),
|
||||
REGIONS("Regions"),
|
||||
DISCOVERED_ON("&7Discovered on: %0"),
|
||||
DISCOVERED_TITLE("&d%0 discovered!", true),
|
||||
DISCOVERED_SUBTITLE("&fKeep exploring to discover more!", true),
|
||||
ALREADY_DISCOVERED_TITLE("&d%0 entered!", true),
|
||||
ALREADY_DISCOVERED_SUBTITLE("&fAlready discovered!", true),
|
||||
TELEPORT("&aClick to teleport"),
|
||||
CANNOT_TELEPORT("&cWe can't teleport you because that world doesn't exist!"),
|
||||
UNKNOWN_REGION("Unknown Realm"),
|
||||
EXIT("&cExit"),
|
||||
EXIT_LORE("&fExit the GUI", true),
|
||||
CANNOT_ENTER("&cYou require %0 to enter this area."),
|
||||
COOLDOWN("&cThat is currently on cooldown."),
|
||||
REGION_ENTER_ACTIONBAR("&a%0");
|
||||
NEXT_PAGE(TranslationKey.of("next_page")),
|
||||
NEXT_PAGE_LORE(TranslationKey.of("next_page_lore")),
|
||||
PREVIOUS_PAGE(TranslationKey.of("previous_page")),
|
||||
PREVIOUS_PAGE_LORE(TranslationKey.of("previous_page_lore")),
|
||||
REGIONS(TranslationKey.of("regions")),
|
||||
DISCOVERED_ON(TranslationKey.of("discovered_on")),
|
||||
DISCOVERED_TITLE(TranslationKey.of("discovered_title")),
|
||||
DISCOVERED_SUBTITLE(TranslationKey.of("discovered_subtitle")),
|
||||
ALREADY_DISCOVERED_TITLE(TranslationKey.of("already_discovered_title")),
|
||||
ALREADY_DISCOVERED_SUBTITLE(TranslationKey.of("already_discovered_subtitle")),
|
||||
TELEPORT(TranslationKey.of("teleport")),
|
||||
CANNOT_TELEPORT(TranslationKey.of("cannot_teleport")),
|
||||
UNKNOWN_REGION(TranslationKey.of("unknown_region")),
|
||||
EXIT(TranslationKey.of("exit")),
|
||||
EXIT_LORE(TranslationKey.of("exit_lore")),
|
||||
CANNOT_ENTER(TranslationKey.of("cannot_enter")),
|
||||
COOLDOWN(TranslationKey.of("cooldown")),
|
||||
REGION_ENTER_ACTIONBAR(TranslationKey.of("region_enter_actionbar"));
|
||||
|
||||
private final String defaultValue;
|
||||
private final TranslationKey key;
|
||||
private final boolean isList;
|
||||
|
||||
Translations(String defaultValue) {
|
||||
this.defaultValue = defaultValue;
|
||||
Translations(TranslationKey key) {
|
||||
this.key = key;
|
||||
this.isList = false;
|
||||
}
|
||||
|
||||
Translations(String defaultValue, boolean isList) {
|
||||
this.defaultValue = defaultValue;
|
||||
this.isList = isList;
|
||||
}
|
||||
|
||||
public String getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public boolean isList() {
|
||||
return isList;
|
||||
}
|
||||
@@ -60,52 +53,20 @@ public enum Translations {
|
||||
return this.toString().toLowerCase();
|
||||
}
|
||||
|
||||
public void send(Player player) {
|
||||
String message = RPGRegionsAPI.getAPI().getTranslator().getTranslationFor(player, this.getPath());
|
||||
player.sendMessage(message);
|
||||
public void send(Player player, Object... values) {
|
||||
final Translation translation = RPGRegionsAPI.getAPI().getTranslator().getTranslationFor(player, key);
|
||||
for (String translationString : translation.colour()) {
|
||||
player.sendMessage(this.setPapi(player, replaceVariables(translationString, values)));
|
||||
}
|
||||
}
|
||||
|
||||
public void send(Player player, String... values) {
|
||||
String message = RPGRegionsAPI.getAPI().getTranslator().getTranslationFor(player, this.getPath());
|
||||
message = this.setPapi(player, replaceVariables(message, values));
|
||||
player.sendMessage(message);
|
||||
}
|
||||
|
||||
public void sendList(Player player) {
|
||||
List<String> messages = RPGRegionsAPI.getAPI().getTranslator().getTranslationListFor(player, this.getPath());
|
||||
messages.forEach(player::sendMessage);
|
||||
}
|
||||
|
||||
public void sendList(Player player, String... values) {
|
||||
List<String> messages = RPGRegionsAPI.getAPI().getTranslator().getTranslationListFor(player, this.getPath());
|
||||
messages.forEach(message -> {
|
||||
message = this.setPapi(player, replaceVariables(message, values));
|
||||
player.sendMessage(message);
|
||||
});
|
||||
}
|
||||
|
||||
public String get(Player player) {
|
||||
return this.setPapi(player, RPGRegionsAPI.getAPI().getTranslator().getTranslationFor(player, this.getPath()));
|
||||
}
|
||||
|
||||
public String get(Player player, String... values) {
|
||||
String message = RPGRegionsAPI.getAPI().getTranslator().getTranslationFor(player, this.getPath());
|
||||
message = replaceVariables(message, values);
|
||||
return this.setPapi(player, message);
|
||||
}
|
||||
|
||||
public List<String> getList(Player player) {
|
||||
List<String> list = new ArrayList<>();
|
||||
RPGRegionsAPI.getAPI().getTranslator().getTranslationListFor(player, this.getPath()).forEach(text -> list.add(this.setPapi(player, text)));
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<String> getList(Player player, String... values) {
|
||||
List<String> messages = new ArrayList<>();
|
||||
RPGRegionsAPI.getAPI().getTranslator()
|
||||
.getTranslationListFor(player, this.getPath())
|
||||
.forEach(message -> messages.add(this.setPapi(player, replaceVariables(message, values))));
|
||||
return messages;
|
||||
public List<String> get(Player player, Object... values) {
|
||||
final Translation translation = RPGRegionsAPI.getAPI().getTranslator().getTranslationFor(player, key);
|
||||
List<String> transformed = new ArrayList<>();
|
||||
for (String translationString : translation.colour()) {
|
||||
transformed.add(this.setPapi(player, replaceVariables(translationString, values)));
|
||||
}
|
||||
return transformed;
|
||||
}
|
||||
|
||||
public static void generateLang(IRPGRegionsAPI plugin) {
|
||||
@@ -113,24 +74,19 @@ public enum Translations {
|
||||
lang.mkdirs();
|
||||
|
||||
for (Language language : Language.values()) {
|
||||
final LanguageKey languageKey = language.getKey();
|
||||
try {
|
||||
plugin.saveResource("lang/" + language.getCode() + ".yml", false);
|
||||
plugin.getLogger().info("Generated " + language.getCode() + ".yml");
|
||||
plugin.saveResource("lang/" + languageKey.getCode() + ".yml", false);
|
||||
plugin.getLogger().info("Generated " + languageKey.getCode() + ".yml");
|
||||
} catch (IllegalArgumentException ignored) { }
|
||||
|
||||
File file = new File(plugin.getDataFolder() + "/lang/" + language.getCode() + ".yml");
|
||||
File file = new File(plugin.getDataFolder() + "/lang/" + languageKey.getCode() + ".yml");
|
||||
if (file.exists()) {
|
||||
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||
for (Translations key : values()) {
|
||||
if (config.get(key.toString().toLowerCase()) == null) {
|
||||
config.set(key.toString().toLowerCase(), key.defaultValue);
|
||||
try {
|
||||
config.save(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
plugin.getLogger().warning("No value in translation file for key "
|
||||
+ key + " was found. We will attempt to fix this. Otherwise, try to regenerate language files?");
|
||||
+ key + " was found. Please regenerate or edit your language files with new values!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -138,10 +94,10 @@ public enum Translations {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String replaceVariables(String message, String... values) {
|
||||
private String replaceVariables(String message, Object... values) {
|
||||
String modifiedMessage = message;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
if (values.length > i) modifiedMessage = modifiedMessage.replaceAll("%" + i, values[i]);
|
||||
if (values.length > i) modifiedMessage = modifiedMessage.replaceAll("%" + i, String.valueOf(values[i]));
|
||||
else break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user