Allow changing enableBungee with /sg reload
Fix issue where custom entries in lang files were removed on load
This commit is contained in:
parent
d464a16e38
commit
5aec85da3e
4
README
4
README
@ -207,7 +207,8 @@ createConflict=Gate conflicts with existing gate
|
||||
=============
|
||||
Known Bugs
|
||||
=============
|
||||
Client randomly crashes on teleport.
|
||||
Unable to reproduce: Stargates teleport a user to the Nether
|
||||
Unable to reproduce: Stargates teleport a user into the ground/under the ground
|
||||
|
||||
=============
|
||||
Changes
|
||||
@ -216,6 +217,7 @@ Client randomly crashes on teleport.
|
||||
- Added BungeeCord multi-server support (Requires Stargate-Bungee for BungeeCord)
|
||||
- Updated Spanish language file
|
||||
- Added basic plugin metrics via http://mcstats.org/
|
||||
- Resolve issue where language updating overwrote custom strings
|
||||
[Version 0.7.8.1]
|
||||
- Resolve issue of language file being overwritten as ANSI instead of UTF8
|
||||
[Version 0.7.8.0]
|
||||
|
@ -8,6 +8,7 @@ import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
@ -80,6 +81,9 @@ public class LangLoader {
|
||||
// with missing lines from the in-JAR files
|
||||
private void updateLanguage(String lang) {
|
||||
// Load the current language file
|
||||
ArrayList<String> keyList = new ArrayList<String>();
|
||||
ArrayList<String> valList = new ArrayList<String>();
|
||||
|
||||
HashMap<String, String> curLang = load(lang);
|
||||
|
||||
InputStream is = Stargate.class.getResourceAsStream("resources/" + lang + ".txt");
|
||||
@ -92,11 +96,6 @@ public class LangLoader {
|
||||
InputStreamReader isr = new InputStreamReader(is);
|
||||
BufferedReader br = new BufferedReader(isr);
|
||||
|
||||
// Save file
|
||||
fos = new FileOutputStream(datFolder + lang + ".txt");
|
||||
OutputStreamWriter out = new OutputStreamWriter(fos, "UTF8");
|
||||
BufferedWriter bw = new BufferedWriter(out);
|
||||
|
||||
String line = br.readLine();
|
||||
boolean firstLine = true;
|
||||
while (line != null) {
|
||||
@ -106,22 +105,44 @@ public class LangLoader {
|
||||
// Split at first "="
|
||||
int eq = line.indexOf('=');
|
||||
if (eq == -1) {
|
||||
bw.newLine();
|
||||
keyList.add("");
|
||||
valList.add("");
|
||||
line = br.readLine();
|
||||
continue;
|
||||
}
|
||||
String key = line.substring(0, eq);
|
||||
String val = line.substring(eq);
|
||||
|
||||
if (curLang == null || curLang.get(key) == null) {
|
||||
bw.write(line);
|
||||
bw.newLine();
|
||||
keyList.add(key);
|
||||
valList.add(val);
|
||||
updated = true;
|
||||
} else {
|
||||
bw.write(key + "=" + curLang.get(key));
|
||||
bw.newLine();
|
||||
keyList.add(key);
|
||||
valList.add("=" + curLang.get(key));
|
||||
curLang.remove(key);
|
||||
}
|
||||
line = br.readLine();
|
||||
}
|
||||
br.close();
|
||||
|
||||
// Save file
|
||||
fos = new FileOutputStream(datFolder + lang + ".txt");
|
||||
OutputStreamWriter out = new OutputStreamWriter(fos, "UTF8");
|
||||
BufferedWriter bw = new BufferedWriter(out);
|
||||
|
||||
// Output normal Language data
|
||||
for (int i = 0; i < keyList.size(); i++) {
|
||||
bw.write(keyList.get(i) + valList.get(i));
|
||||
bw.newLine();
|
||||
}
|
||||
bw.newLine();
|
||||
// Output any custom language strings the user had
|
||||
for (String key : curLang.keySet()) {
|
||||
bw.write(key + "=" + curLang.get(key));
|
||||
bw.newLine();
|
||||
}
|
||||
|
||||
bw.close();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
|
@ -1313,6 +1313,8 @@ public class Stargate extends JavaPlugin {
|
||||
Portal.clearGates();
|
||||
Gate.clearGates();
|
||||
|
||||
// Store the old Bungee enabled value
|
||||
boolean oldEnableBungee = enableBungee;
|
||||
// Reload data
|
||||
loadConfig();
|
||||
reloadGates();
|
||||
@ -1333,6 +1335,18 @@ public class Stargate extends JavaPlugin {
|
||||
iConomyHandler.register = null;
|
||||
iConomyHandler.economy = null;
|
||||
}
|
||||
|
||||
// Enable the required channels for Bungee support
|
||||
if (oldEnableBungee != enableBungee) {
|
||||
if (enableBungee) {
|
||||
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "SGBungee");
|
||||
Bukkit.getMessenger().registerIncomingPluginChannel(this, "SGBungee", new pmListener());
|
||||
} else {
|
||||
Bukkit.getMessenger().unregisterIncomingPluginChannel(this, "SGBungee");
|
||||
Bukkit.getMessenger().unregisterOutgoingPluginChannel(this, "SGBungee");
|
||||
}
|
||||
}
|
||||
|
||||
sendMessage(sender, "Stargate reloaded");
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user