9
0
mirror of https://gitlab.com/SamB440/rpgregions-2.git synced 2025-12-24 01:09:27 +00:00

Auto-add translation key if it does not exist

This commit is contained in:
SamB440
2021-10-09 20:43:42 +01:00
parent f21bafacb3
commit 0012ecf706
4 changed files with 16 additions and 12 deletions

View File

@@ -14,15 +14,9 @@ public enum PreventType {
if (event.getTo() == null) return;
Player player = event.getPlayer();
switch (this) {
case TELEPORT:
PaperLib.teleportAsync(player, event.getFrom());
break;
case PUSH:
player.setVelocity(event.getTo().toVector().subtract(event.getFrom().toVector()).multiply(-3));
break;
case CANCEL:
event.setCancelled(true);
break;
case TELEPORT -> PaperLib.teleportAsync(player, event.getFrom());
case PUSH -> player.setVelocity(event.getTo().toVector().subtract(event.getFrom().toVector()).multiply(-3));
case CANCEL -> event.setCancelled(true);
}
player.spawnParticle(Particle.BARRIER, event.getTo().getBlock().getLocation().add(0.5, 0.5, 0.5), 1);
}

View File

@@ -11,6 +11,7 @@ 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;
@@ -32,7 +33,8 @@ public enum Translations {
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");
REGION_ENTER_ACTIONBAR("&a%0"),
TEST("test");
private final String defaultValue;
private final boolean isList;
@@ -122,8 +124,14 @@ public enum Translations {
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.toString() + " was found. Regenerate language files?");
+ key + " was found. We will attempt to fix this. Otherwise, try to regenerate language files?");
}
}
}

View File

@@ -22,4 +22,5 @@ next_page_lore:
exit_lore:
- "&fExit the GUI"
cooldown: "&cThat is currently on cooldown."
region_enter_actionbar: "&a%0"
region_enter_actionbar: "&a%0"
test: "test"

View File

@@ -38,6 +38,7 @@ public class RPGRegionsIntegration implements IntegrationManager {
public RPGRegionsIntegration(IRPGRegionsAPI plugin) {
this.plugin = plugin;
this.regions = new HashMap<>();
// Register command completions and command, it's here because we only want it to enable if enabled.
if (plugin instanceof RPGRegions rpgRegions) {
rpgRegions.getCommandManager().getCommandContexts().registerContext(RPGRegionsRegion.class, context -> {
String id = context.popFirstArg();