Skip to content

Commit

Permalink
[O] Make the language file replaceable
Browse files Browse the repository at this point in the history
  • Loading branch information
ClayCoffee committed Aug 29, 2020
1 parent d5e7164 commit eff15b2
Show file tree
Hide file tree
Showing 13 changed files with 394 additions and 334 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ You can translate ClayTech here: [Click me](https://gitlocalize.com/repo/4241)
The default language file(en-US、en-GB) might have some grammar mistakes, I hope you can help me translate it.

# 下载 / Download
* Jenkins: [Click me](http://build.claycoffee.cn:8688/)
* The Repo Server: [Click me](https://thebusybiscuit.github.io/builds/ClayCoffee/ClayTech/)
* Jenkins: [Click me](http://build.claycoffee.cn:8688/job/ClayTech/)
* Github Releases

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>club.claycoffee</groupId>
<artifactId>ClayTech</artifactId>
<version>1.2.12</version>
<version>1.2.13</version>
<build>
<plugins>
<plugin>
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/cn/claycoffee/ClayTech/api/ClayTechManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static boolean isRocket(ItemStack item) {
if (item == null)
return false;
if (item.hasItemMeta()) {
if (item.getItemMeta().getDisplayName().startsWith(Lang.readGeneralText("Rocket"))) {
if (item.getItemMeta().getDisplayName().startsWith(Lang.rocketPrefix)) {
return true;
} else {
return false;
Expand All @@ -65,7 +65,7 @@ public static boolean isSpaceSuit(ItemStack item) {
if (item == null)
return false;
if (item.hasItemMeta()) {
if (item.getItemMeta().getDisplayName().startsWith(Lang.readGeneralText("SpaceSuit"))) {
if (item.getItemMeta().getDisplayName().startsWith(Lang.spaceSuitPrefix)) {
return true;
} else {
return false;
Expand All @@ -78,7 +78,7 @@ public static boolean isOxygenDistributer(ItemStack item) {
if (item == null)
return false;
if (item.hasItemMeta()) {
if (item.getItemMeta().getDisplayName().startsWith(Lang.readGeneralText("OxygenDistributer"))) {
if (item.getItemMeta().getDisplayName().startsWith(Lang.oxygenDistributerPrefix)) {
return true;
} else {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void onBlockBreak(BlockBreakEvent e) {
e.getPlayer().sendMessage(Lang.readGeneralText("cantBreak"));
}
}
if (Utils.readPlayerMetadataBoolean(e.getPlayer(), "cantDestroy")) {
if (Utils.readPlayerMetadataBoolean(e.getPlayer(), "inRocket")) {
e.setCancelled(true);
e.getPlayer().sendMessage(Lang.readGeneralText("cantBreak"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ public void InventoryMoveItemEvent(InventoryClickEvent e) {
if (!inRocket.equalsIgnoreCase("true")) {
p.setMetadata("inrocket",
new FixedMetadataValue(ClayTech.getInstance(), "true"));
p.setMetadata("cantDestroy", new FixedMetadataValue(ClayTech.getInstance(), true));
p.sendMessage(Lang.readGeneralText("RocketOK"));
new BukkitRunnable() {
int time = 0;
Expand All @@ -110,7 +109,6 @@ public void run() {
BlockStorage.clearBlockInfo(b.getLocation(), true);
b.setType(Material.AIR);
p.getInventory().addItem(ClayTechItems.ROCKET_LAUNCHER);
p.setMetadata("cantDestroy", new FixedMetadataValue(ClayTech.getInstance(), false));
DataYML planetsData = ClayTech.getPlanetDataYML();
FileConfiguration pd = planetsData.getCustomConfig();
if (pd.getBoolean(p.getName() + "."
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/cn/claycoffee/ClayTech/utils/ClayItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public class ClayItem {
public static boolean hasDurability(ItemStack item) {
for (String each : Utils.getLoreList(item)) {
if (each.startsWith(Lang.readGeneralText("Durability"))) {
if (each.startsWith(Lang.durability)) {
return true;
}
}
Expand All @@ -18,9 +18,9 @@ public static boolean hasDurability(ItemStack item) {
public static int getDurability(ItemStack item) {
if (hasDurability(item)) {
for (String each : Utils.getLoreList(item)) {
if (each.startsWith(Lang.readGeneralText("Durability"))) {
if (each.startsWith(Lang.durability)) {
return new Integer(
each.replaceFirst(Lang.readGeneralText("Durability") + ":", "").replace(" §6", ""))
each.replaceFirst(Lang.durability + ":", "").replace(" §6", ""))
.intValue();
}
}
Expand All @@ -39,8 +39,8 @@ public static boolean setDurability(ItemStack item, int durability) {
List<String> Lore = Utils.getLoreList(item);
int i = 0;
for (String each : Lore) {
if (each.startsWith(Lang.readGeneralText("Durability"))) {
each = Lang.readGeneralText("Durability") + ": §6" + durability;
if (each.startsWith(Lang.durability)) {
each = Lang.durability + ": §6" + durability;
Lore.set(i, each);
break;
}
Expand Down
72 changes: 67 additions & 5 deletions src/main/java/cn/claycoffee/ClayTech/utils/Lang.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,35 @@

import cn.claycoffee.ClayTech.ClayTech;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Lang {
public static String[] LocaleList = {"zh-CN", "zh-TW", "en-GB", "en-US", "ja"};
public static String cantPlace = readGeneralText("CantPlaceLore");
public static String blindFive = readGeneralText("Blind_5_effect");
public static String slownessFive = readGeneralText("Slowness_5_effect");
public static String confusionFive = readGeneralText("Confusion_5_effect");
public static String poisonThree = readGeneralText("Poison_3_effect");
public static String antiSlownessThree = readGeneralText("Anti_Slowness_5_effect");
public static String durability = readGeneralText("Durability");
public static String cantEat = readGeneralText("CantEat");
public static String cantInteract = readGeneralText("CantInteract");
public static String rocketPrefix = readGeneralText("Rocket");
public static String spaceSuitPrefix = readGeneralText("SpaceSuit");
public static String fuelPrefix = readGeneralText("Fuel");
public static String oxygenPrefix = readGeneralText("Oxygen");
public static String protectLevel = readGeneralText("ProtectLevel");
public static String oxygenDistributerPrefix = readGeneralText("OxygenDistributer");



public static String readItemText(String name) {
if (ClayTech.getLangYML().getCustomConfig().getString("Items." + name) == null) {
return "Missing locale.";
} else {
return ClayTech.getLangYML().getCustomConfig().getString("Items." + name).replaceAll("&", "§");
return format(ClayTech.getLangYML().getCustomConfig().getString("Items." + name));
}
}

Expand All @@ -21,9 +39,8 @@ public static List<String> readItemLore(String name) {
if (ClayTech.getLangYML().getCustomConfig().getString("Items." + name + "_LORE") == null) {
return Arrays.asList(new String[]{"Missing locale."});
} else {
return Utils.replaceList(
((List<String>) ClayTech.getLangYML().getCustomConfig().getList("Items." + name + "_LORE")), "&",
"§");
return format(
((List<String>) ClayTech.getLangYML().getCustomConfig().getList("Items." + name + "_LORE")));
}
}

Expand Down Expand Up @@ -55,7 +72,7 @@ public static String readMachinesText(String name) {
if (ClayTech.getLangYML().getCustomConfig().getString("Machines." + name) == null) {
return "Missing locale.";
} else {
return ClayTech.getLangYML().getCustomConfig().getString("Machines." + name).replaceAll("&", "§");
return format(ClayTech.getLangYML().getCustomConfig().getString("Machines." + name));
}
}

Expand All @@ -82,4 +99,49 @@ public static String readResourcesText(String name) {
return ClayTech.getLangYML().getCustomConfig().getString("Resources." + name).replaceAll("&", "§");
}
}

public static String format(String s) {
s = s.replaceAll("&", "§");
s = s.replaceAll("<cantplace>", cantPlace);
s = s.replaceAll("<cantinteract>", cantInteract);
s = s.replaceAll("<canteat>", cantEat);
s = s.replaceAll("<blindFive>", blindFive);
s = s.replaceAll("<slownessfive>", slownessFive);
s = s.replaceAll("<confusionfive>", confusionFive);
s = s.replaceAll("<poisonthree>", poisonThree);
s = s.replaceAll("<antislownessthree>", antiSlownessThree);
s = s.replaceAll("<durability>", durability);
s = s.replaceAll("<rocket>", rocketPrefix);
s = s.replaceAll("<spacesuit>", spaceSuitPrefix);
s = s.replaceAll("<fuel>", fuelPrefix);
s = s.replaceAll("<oxygen>", oxygenPrefix);
s = s.replaceAll("<protectlevel>", protectLevel);
s = s.replaceAll("<oxygendistributer>", oxygenDistributerPrefix);

return s;
}

public static List<String> format(List<String> list) {
List<String> ret = new ArrayList<>();
for(String s : list) {
s = s.replaceAll("&", "§");
s = s.replaceAll("<cantplace>", cantPlace);
s = s.replaceAll("<cantinteract>", cantInteract);
s = s.replaceAll("<canteat>", cantEat);
s = s.replaceAll("<blindFive>", blindFive);
s = s.replaceAll("<slownessfive>", slownessFive);
s = s.replaceAll("<confusionfive>", confusionFive);
s = s.replaceAll("<poisonthree>", poisonThree);
s = s.replaceAll("<antislownessthree>", antiSlownessThree);
s = s.replaceAll("<durability>", durability);
s = s.replaceAll("<rocket>", rocketPrefix);
s = s.replaceAll("<spacesuit>", spaceSuitPrefix);
s = s.replaceAll("<fuel>", fuelPrefix);
s = s.replaceAll("<oxygen>", oxygenPrefix);
s = s.replaceAll("<protectlevel>", protectLevel);
s = s.replaceAll("<oxygendistributer>", oxygenDistributerPrefix);
ret.add(s);
}
return ret;
}
}
Loading

0 comments on commit eff15b2

Please sign in to comment.