Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cannons-bukkit/src/main/java/at/pavlov/cannons/Cannons.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ public void onLoad() {
CLogger.logger = this.getLogger();
// must be done in onLoad because "movecraft"
AsyncTaskManager.initialize(this);
UserMessages.initialize(this);
Config.initialize(this);
CannonManager.initialize(this);
this.config = Config.getInstance();
UserMessages.initialize(this);
CannonManager.initialize(this);

initUpdater();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import at.pavlov.cannons.builders.ParticleBuilder;
import at.pavlov.cannons.cannon.CannonManager;
import at.pavlov.cannons.container.ItemHolder;
import at.pavlov.cannons.utils.ArmorCalculationUtil;
import at.pavlov.cannons.utils.CannonsUtil;
import at.pavlov.cannons.utils.FileUtils;
import at.pavlov.cannons.utils.ParseUtils;
Expand All @@ -32,6 +31,7 @@
private boolean debugMode;
private boolean relayExplosionEvent;
private int claimEdgeLength;
private String localization;

//region hooks
private boolean economyEnabled;
Expand Down Expand Up @@ -135,8 +135,8 @@ public void loadConfig() {

setRelayExplosionEvent(config.getBoolean("general.relayExplosionEvent", false));
setClaimEdgeLength(config.getInt("general.claimEdgeLength", 60));
ArmorCalculationUtil.setMagicValue(config.getDouble("general.armorEffectiveness", 0.04));
setLocalization(config.getString("general.localization", "en_US"));

//limitOfCannons
setBuildLimitEnabled(config.getBoolean("cannonLimits.useLimits", true));
setBuildLimitA(config.getInt("cannonLimits.buildLimitA", 10));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import at.pavlov.cannons.cannon.Cannon;
import at.pavlov.cannons.cannon.CannonManager;
import at.pavlov.cannons.projectile.Projectile;
import at.pavlov.cannons.utils.CannonsUtil;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.Bukkit;
Expand All @@ -21,13 +20,20 @@
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.security.CodeSource;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
import java.util.UUID;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

public class UserMessages {
private static final String localizationFolder = "plugins/Cannons/localization/";

private FileConfiguration customLanguage = null;
private File customLanguageFile = null;

Expand All @@ -52,23 +58,45 @@ public static void initialize(Cannons plugin) {
instance = new UserMessages(plugin);
}

public void loadLanguage() {
this.loadCustom("localization");
public void saveAllLocalizations() {
try {
CodeSource codeSource = getClass().getProtectionDomain().getCodeSource();
if (codeSource == null) {
return;
}

//copy german language
File localizationGerman = new File(plugin.getDataFolder(), "localization/localization_german.yml");
URI jarUri = codeSource.getLocation().toURI();
try (JarFile jarFile = new JarFile(new File(jarUri))) {

localizationGerman.getParentFile().mkdirs();
if (!localizationGerman.exists()) {
CannonsUtil.copyFile(plugin.getResource("localization/localization_german.yml"), localizationGerman);
}
//copy english language
File localizationEnglish = new File(plugin.getDataFolder(), "localization/localization_english.yml");
if (!localizationEnglish.exists()) {
CannonsUtil.copyFile(plugin.getResource("localization/localization.yml"), localizationEnglish);
Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
String name = entry.getName();

if (!name.startsWith("localization/") || entry.isDirectory()) {
continue;
}

// Save the resource to the plugin folder
File outFile = new File(plugin.getDataFolder(), name);
if (outFile.exists()) {
continue;
}

plugin.saveResource(name, false);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}


public void loadLanguage() {
this.saveAllLocalizations();
this.loadCustom(Config.getInstance().getLocalization());
}

/**
* load the localization file from the disk
*
Expand Down Expand Up @@ -136,7 +164,7 @@ private String getEntry(String key) {

private void reloadCustomLanguage(String filename) {
if (customLanguageFile == null) {
customLanguageFile = new File(getDataFolder(), filename + ".yml");
customLanguageFile = new File(localizationFolder, filename + ".yml");
}
customLanguage = YamlConfiguration.loadConfiguration(customLanguageFile);

Expand All @@ -152,11 +180,6 @@ private void reloadCustomLanguage(String filename) {
}


private String getDataFolder() {
return "plugins/Cannons/localization/";
}


private void saveCustomLanguage() {
if (customLanguage == null || customLanguageFile == null) {
return;
Expand Down
6 changes: 2 additions & 4 deletions cannons-bukkit/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ general:
# sometimes you might need this disabled, and just create a cannon using the
# relative command
cannonPlaceListener: true
# changes how much the armor points are effective, max armor points in vanilla are 20
# meaning the most protection you can get is 80%, if you put this value at 0.05 or above player
# can be completely immune to cannon shots
armorEffectiveness: 0.04
# uses language files in /Cannons/localization
localization: "en_US"

hooks:
vault:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Cannon:
NEWLINE YELLOW 目标玩家: TARGET_PLAYER
NEWLINE YELLOW 目标大炮: TARGET_CANNON
NEWLINE YELLOW 其他目标: TARGET_OTHER
NEWLINE YELLOW 白名单': WHITELIST'
NEWLINE YELLOW 白名单: WHITELIST'
RenameSuccess: 'GREEN [Cannons] 你将大炮重命名为 GOLD CANNON_NAME.'
RenameFail: 'RED [Cannons] 已存在相同名称的大炮.'

Expand Down