Allow changing enableBungee with /sg reload

Fix issue where custom entries in lang files were removed on load
This commit is contained in:
Steven Scott 2012-11-24 17:52:04 -08:00
parent d464a16e38
commit 5aec85da3e
3 changed files with 48 additions and 11 deletions

4
README
View File

@ -207,7 +207,8 @@ createConflict=Gate conflicts with existing gate
============= =============
Known Bugs 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 Changes
@ -216,6 +217,7 @@ Client randomly crashes on teleport.
- Added BungeeCord multi-server support (Requires Stargate-Bungee for BungeeCord) - Added BungeeCord multi-server support (Requires Stargate-Bungee for BungeeCord)
- Updated Spanish language file - Updated Spanish language file
- Added basic plugin metrics via http://mcstats.org/ - Added basic plugin metrics via http://mcstats.org/
- Resolve issue where language updating overwrote custom strings
[Version 0.7.8.1] [Version 0.7.8.1]
- Resolve issue of language file being overwritten as ANSI instead of UTF8 - Resolve issue of language file being overwritten as ANSI instead of UTF8
[Version 0.7.8.0] [Version 0.7.8.0]

View File

@ -8,6 +8,7 @@ import java.io.FileOutputStream;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Set; import java.util.Set;
@ -80,6 +81,9 @@ public class LangLoader {
// with missing lines from the in-JAR files // with missing lines from the in-JAR files
private void updateLanguage(String lang) { private void updateLanguage(String lang) {
// Load the current language file // Load the current language file
ArrayList<String> keyList = new ArrayList<String>();
ArrayList<String> valList = new ArrayList<String>();
HashMap<String, String> curLang = load(lang); HashMap<String, String> curLang = load(lang);
InputStream is = Stargate.class.getResourceAsStream("resources/" + lang + ".txt"); InputStream is = Stargate.class.getResourceAsStream("resources/" + lang + ".txt");
@ -92,11 +96,6 @@ public class LangLoader {
InputStreamReader isr = new InputStreamReader(is); InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr); 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(); String line = br.readLine();
boolean firstLine = true; boolean firstLine = true;
while (line != null) { while (line != null) {
@ -106,22 +105,44 @@ public class LangLoader {
// Split at first "=" // Split at first "="
int eq = line.indexOf('='); int eq = line.indexOf('=');
if (eq == -1) { if (eq == -1) {
bw.newLine(); keyList.add("");
valList.add("");
line = br.readLine(); line = br.readLine();
continue; continue;
} }
String key = line.substring(0, eq); String key = line.substring(0, eq);
String val = line.substring(eq);
if (curLang == null || curLang.get(key) == null) { if (curLang == null || curLang.get(key) == null) {
bw.write(line); keyList.add(key);
bw.newLine(); valList.add(val);
updated = true; updated = true;
} else { } else {
bw.write(key + "=" + curLang.get(key)); keyList.add(key);
bw.newLine(); valList.add("=" + curLang.get(key));
curLang.remove(key);
} }
line = br.readLine(); 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(); bw.close();
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();

View File

@ -1313,6 +1313,8 @@ public class Stargate extends JavaPlugin {
Portal.clearGates(); Portal.clearGates();
Gate.clearGates(); Gate.clearGates();
// Store the old Bungee enabled value
boolean oldEnableBungee = enableBungee;
// Reload data // Reload data
loadConfig(); loadConfig();
reloadGates(); reloadGates();
@ -1333,6 +1335,18 @@ public class Stargate extends JavaPlugin {
iConomyHandler.register = null; iConomyHandler.register = null;
iConomyHandler.economy = 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"); sendMessage(sender, "Stargate reloaded");
return true; return true;
} }