[Version 0.7.8.0]

- Updated languages to include sign text (Please update any languages you are able!)
 - Resolved NPE due to Bukkit bug with signs
 - Resolved issue regarding new getTargetBlock code throwing an exception
 - Languages now auto-update based on the .JAR version (New entries only, doesnt overwrite customization)
 - New command "/sg about", will list the author of the current language file if available
 - Language now has a fallback to English for missing lines (Its the only language I can personally update on release)
 - Added Spanish (Thanks Manuestaire) and Hungarian (Thanks HPoltergeist)
This commit is contained in:
Steven Scott 2012-09-16 16:11:19 -07:00
parent d3834c5709
commit de7134f0a4
15 changed files with 265 additions and 39 deletions

8
README
View File

@ -212,6 +212,14 @@ Client randomly crashes on teleport.
============= =============
Changes Changes
============= =============
[Version 0.7.8.0]
- Updated languages to include sign text (Please update any languages you are able!)
- Resolved NPE due to Bukkit bug with signs
- Resolved issue regarding new getTargetBlock code throwing an exception
- Languages now auto-update based on the .JAR version (New entries only, doesn't overwrite customization)
- New command "/sg about", will list the author of the current language file if available
- Language now has a fallback to English for missing lines (It's the only language I can personally update on release)
- Added Spanish (Thanks Manuestaire) and Hungarian (Thanks HPoltergeist)
[Version 0.7.7.5] [Version 0.7.7.5]
- Resolve issue of right clicking introduced in 1.3.1/2 - Resolve issue of right clicking introduced in 1.3.1/2
[Version 0.7.7.4] [Version 0.7.7.4]

View File

@ -35,29 +35,39 @@ public class LangLoader {
private String datFolder; private String datFolder;
private String lang; private String lang;
private HashMap<String, String> strList; private HashMap<String, String> strList;
private HashMap<String, String> defList;
public LangLoader(String datFolder, String lang) { public LangLoader(String datFolder, String lang) {
this.lang = lang; this.lang = lang;
this.datFolder = datFolder; this.datFolder = datFolder;
strList = new HashMap<String, String>();
File tmp = new File(datFolder, lang + ".txt"); File tmp = new File(datFolder, lang + ".txt");
if (!tmp.exists()) { if (!tmp.exists()) {
tmp.getParentFile().mkdirs(); tmp.getParentFile().mkdirs();
loadDefaults();
} }
updateLanguage(lang);
load(); strList = load(lang);
// We have a default hashMap used for when new text is added.
InputStream is = Stargate.class.getResourceAsStream("resources/" + lang + ".txt");
if (is != null) {
defList = load("en", is);
} else {
defList = null;
Stargate.log.severe("[Stargate] Error loading backup language. There may be missing text ingame");
}
} }
public boolean reload() { public boolean reload() {
strList = new HashMap<String, String>(); // This extracts/updates the language as needed
load(); updateLanguage(lang);
strList = load(lang);
return true; return true;
} }
public String getString(String name) { public String getString(String name) {
String val = strList.get(name); String val = strList.get(name);
if (val == null && defList != null) val = defList.get(name);
if (val == null) return ""; if (val == null) return "";
return val; return val;
} }
@ -66,11 +76,16 @@ public class LangLoader {
this.lang = lang; this.lang = lang;
} }
private void loadDefaults() { // This function updates on-disk language files
// with missing lines from the in-JAR files
private void updateLanguage(String lang) {
// Load the current language file
HashMap<String, String> curLang = load(lang);
InputStream is = Stargate.class.getResourceAsStream("resources/" + lang + ".txt"); InputStream is = Stargate.class.getResourceAsStream("resources/" + lang + ".txt");
if (is == null) return; if (is == null) return;
Stargate.log.info("[Stargate] Extracting initial language file -- " + lang + ".txt");
boolean updated = false;
FileOutputStream fos = null; FileOutputStream fos = null;
try { try {
// Input stuff // Input stuff
@ -83,9 +98,28 @@ public class LangLoader {
BufferedWriter bw = new BufferedWriter(out); BufferedWriter bw = new BufferedWriter(out);
String line = br.readLine(); String line = br.readLine();
boolean firstLine = true;
while (line != null) { while (line != null) {
bw.write(line); // Strip UTF BOM
bw.newLine(); if (firstLine) line = removeUTF8BOM(line);
firstLine = false;
// Split at first "="
int eq = line.indexOf('=');
if (eq == -1) {
bw.newLine();
line = br.readLine();
continue;
}
String key = line.substring(0, eq);
if (curLang == null || curLang.get(key) == null) {
bw.write(line);
bw.newLine();
updated = true;
} else {
bw.write(key + "=" + curLang.get(key));
bw.newLine();
}
line = br.readLine(); line = br.readLine();
} }
bw.close(); bw.close();
@ -96,13 +130,25 @@ public class LangLoader {
try {fos.close();} catch (Exception ex) {} try {fos.close();} catch (Exception ex) {}
} }
} }
if (updated)
Stargate.log.info("[Stargate] Your language file (" + lang + ".txt) has been updated");
} }
private boolean load() { private HashMap<String, String> load(String lang) {
return load(lang, null);
}
private HashMap<String, String> load(String lang, InputStream is) {
HashMap<String, String> strings = new HashMap<String, String>();
FileInputStream fis = null; FileInputStream fis = null;
InputStreamReader isr = null;
try { try {
fis = new FileInputStream(datFolder + lang + ".txt"); if (is == null) {
InputStreamReader isr = new InputStreamReader(fis, "UTF8"); fis = new FileInputStream(datFolder + lang + ".txt");
isr = new InputStreamReader(fis, "UTF8");
} else {
isr = new InputStreamReader(is, "UTF8");
}
BufferedReader br = new BufferedReader(isr); BufferedReader br = new BufferedReader(isr);
String line = br.readLine(); String line = br.readLine();
boolean firstLine = true; boolean firstLine = true;
@ -118,24 +164,29 @@ public class LangLoader {
} }
String key = line.substring(0, eq); String key = line.substring(0, eq);
String val = line.substring(eq + 1); String val = line.substring(eq + 1);
strList.put(key, val); strings.put(key, val);
line = br.readLine(); line = br.readLine();
} }
} catch (Exception ex) { } catch (Exception ex) {
return false; return null;
} finally { } finally {
if (fis != null) { if (fis != null) {
try {fis.close();} try {fis.close();}
catch (Exception ex) {} catch (Exception ex) {}
} }
} }
return true; return strings;
} }
public void debug() { public void debug() {
Set<String> keys = strList.keySet(); Set<String> keys = strList.keySet();
for (String key : keys) { for (String key : keys) {
Stargate.debug("LangLoader::Debug", key + " => " + strList.get(key)); Stargate.debug("LangLoader::Debug::strList", key + " => " + strList.get(key));
}
if (defList == null) return;
keys = defList.keySet();
for (String key : keys) {
Stargate.debug("LangLoader::Debug::defList", key + " => " + defList.get(key));
} }
} }

View File

@ -23,7 +23,6 @@ import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -670,28 +669,27 @@ public class Portal {
} }
public final void drawSign() { public final void drawSign() {
BlockState bs = null; Material sMat = id.getBlock().getType();
bs = id.getBlock().getState(); if (sMat != Material.SIGN && sMat != Material.WALL_SIGN && sMat != Material.SIGN_POST) {
if (!(bs instanceof Sign)) {
Stargate.log.warning("[Stargate] Sign block is not a Sign object"); Stargate.log.warning("[Stargate] Sign block is not a Sign object");
Stargate.debug("Portal::drawSign", "Block: " + id.getBlock().getType() + " @ " + id.getBlock().getLocation()); Stargate.debug("Portal::drawSign", "Block: " + id.getBlock().getType() + " @ " + id.getBlock().getLocation());
return; return;
} }
Sign sign = (Sign)id.getBlock().getState(); Sign sign = (Sign)new StargateSign(id.getBlock());
Stargate.setLine(sign, 0, "-" + name + "-"); Stargate.setLine(sign, 0, "-" + name + "-");
int max = destinations.size() - 1; int max = destinations.size() - 1;
int done = 0; int done = 0;
if (!isActive()) { if (!isActive()) {
Stargate.setLine(sign, ++done, "Right click"); Stargate.setLine(sign, ++done, Stargate.getString("signRightClick"));
Stargate.setLine(sign, ++done, "to use gate"); Stargate.setLine(sign, ++done, Stargate.getString("signToUse"));
if (!noNetwork) { if (!noNetwork) {
Stargate.setLine(sign, ++done, "(" + network + ")"); Stargate.setLine(sign, ++done, "(" + network + ")");
} }
} else { } else {
if (isFixed()) { if (isFixed()) {
if (isRandom()) { if (isRandom()) {
Stargate.setLine(sign, ++done, "> Random <"); Stargate.setLine(sign, ++done, "> " + Stargate.getString("signRandom") + " <");
} else { } else {
Stargate.setLine(sign, ++done, ">" + destination + "<"); Stargate.setLine(sign, ++done, ">" + destination + "<");
} }
@ -702,7 +700,7 @@ public class Portal {
} }
Portal dest = Portal.getByName(destination, network); Portal dest = Portal.getByName(destination, network);
if (dest == null && !isRandom()) { if (dest == null && !isRandom()) {
Stargate.setLine(sign, ++done, "Disconnected"); Stargate.setLine(sign, ++done, Stargate.getString("signDisconnected"));
} else { } else {
Stargate.setLine(sign, ++done, ""); Stargate.setLine(sign, ++done, "");
} }

View File

@ -144,9 +144,12 @@ public class Stargate extends JavaPlugin {
pm.registerEvents(new sListener(), this); pm.registerEvents(new sListener(), this);
this.loadConfig(); this.loadConfig();
// It is important to load languages here, as they are used during reloadGates()
lang = new LangLoader(langFolder, Stargate.langName);
this.migrate(); this.migrate();
this.reloadGates(); this.reloadGates();
lang = new LangLoader(langFolder, Stargate.langName);
// Check to see if iConomy/Permissions is loaded yet. // Check to see if iConomy/Permissions is loaded yet.
permissions = (Permissions)checkPlugin("Permissions"); permissions = (Permissions)checkPlugin("Permissions");
@ -792,7 +795,12 @@ public class Stargate extends JavaPlugin {
Player player = event.getPlayer(); Player player = event.getPlayer();
Block block = null; Block block = null;
if (event.isCancelled() && event.getAction() == Action.RIGHT_CLICK_AIR) { if (event.isCancelled() && event.getAction() == Action.RIGHT_CLICK_AIR) {
block = player.getTargetBlock(null, 5); try {
block = player.getTargetBlock(null, 5);
} catch (IllegalStateException ex) {
// We can safely ignore this exception, it only happens in void or max height
return;
}
} else { } else {
block = event.getClickedBlock(); block = event.getClickedBlock();
} }
@ -1228,16 +1236,22 @@ public class Stargate extends JavaPlugin {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender instanceof Player) {
Player p = (Player)sender;
if (!hasPerm(p, "stargate.admin") && !hasPerm(p, "stargate.admin.reload")) {
sendMessage(sender, "Permission Denied");
return true;
}
}
String cmd = command.getName(); String cmd = command.getName();
if (cmd.equalsIgnoreCase("sg")) { if (cmd.equalsIgnoreCase("sg")) {
if (args.length != 1) return false; if (args.length != 1) return false;
if (args[0].equalsIgnoreCase("about")) {
sender.sendMessage("Stargate Plugin created by Drakia");
if (!lang.getString("author").isEmpty())
sender.sendMessage("Language created by " + lang.getString("author"));
return true;
}
if (sender instanceof Player) {
Player p = (Player)sender;
if (!hasPerm(p, "stargate.admin") && !hasPerm(p, "stargate.admin.reload")) {
sendMessage(sender, "Permission Denied");
return true;
}
}
if (args[0].equalsIgnoreCase("reload")) { if (args[0].equalsIgnoreCase("reload")) {
// Deactivate portals // Deactivate portals
for (Portal p : activeList) { for (Portal p : activeList) {

View File

@ -0,0 +1,58 @@
package net.TheDgtl.Stargate;
import net.minecraft.server.TileEntitySign;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.block.CraftBlockState;
public class StargateSign extends CraftBlockState implements Sign {
private final TileEntitySign sign;
private final String[] lines;
public StargateSign(final Block block) {
super(block);
CraftWorld world = (CraftWorld) block.getWorld();
sign = (TileEntitySign) world.getTileEntityAt(getX(), getY(), getZ());
if (sign != null) {
lines = new String[sign.lines.length];
System.arraycopy(sign.lines, 0, lines, 0, lines.length);
} else {
// Sadly, due to Minecraft having many issues with blocks, chunks
// and entities, we must assume a 4-line sign if the sign is null
lines = new String[4];
}
}
public String[] getLines() {
return lines;
}
public String getLine(int index) throws IndexOutOfBoundsException {
return lines[index];
}
public void setLine(int index, String line) throws IndexOutOfBoundsException {
lines[index] = line;
}
@Override
public boolean update(boolean force) {
boolean result = super.update(force) && (sign != null);
if (result) {
for(int i = 0; i < sign.lines.length; i++) {
if(lines[i] != null) {
sign.lines[i] = lines[i];
} else {
sign.lines[i] = "";
}
}
sign.update();
}
return result;
}
}

View File

@ -1,3 +1,4 @@
author=EduardBaer
prefix=[Stargate] prefix=[Stargate]
teleportMsg=Du wurdest Teleportiert. teleportMsg=Du wurdest Teleportiert.
destroyMsg=Gate zerstört destroyMsg=Gate zerstört
@ -20,3 +21,8 @@ createExists=Ein Gate mit diesem Name existiert bereits.
createFull=Dieses Netzwerk ist voll. createFull=Dieses Netzwerk ist voll.
createWorldDeny=Du hast keinen Zugriff auf diese Welt. createWorldDeny=Du hast keinen Zugriff auf diese Welt.
createConflict=Dieses Gate steht im Konflikt mit einem bereits existierenden. createConflict=Dieses Gate steht im Konflikt mit einem bereits existierenden.
signRightClick=Right click
signToUse=to use gate
signRandom=Random
signDisconnected=Disconnected

View File

@ -20,3 +20,8 @@ createExists=A gate by that name already exists
createFull=This network is full createFull=This network is full
createWorldDeny=You do not have access to that world createWorldDeny=You do not have access to that world
createConflict=Gate conflicts with existing gate createConflict=Gate conflicts with existing gate
signRightClick=Right click
signToUse=to use gate
signRandom=Random
signDisconnected=Disconnected

View File

@ -0,0 +1,28 @@
author=Manuestaire
prefix=[Stargate]
teleportMsg=Teletransportado
destroyMsg=Portal Destruido
invalidMsg=Destino Inválido
blockMsg=Destino Bloqueado
destEmpty=La lista de destinos está vacía
denyMsg=Acceso denegado
ecoDeduct=Pagaste %cost%
ecoRefund=Reembolsado %cost%
ecoObtain=Obtenido %cost% del Portal %portal%
ecoInFunds=No tienes suficiente dinero
createMsg=Portal creado
createNetDeny=No tienes acceso a esta red
createGateDeny=No tienes acceso a este diseño de portal
createPersonal=Creando el portal en una red personal
createNameLength=Nombre demasiado largo o demasiado corto
createExists=Ya existe una puerta con este nombre
createFull=Esta red está llena
createWorldDeny=No tienes permisos para acceder a ese mundo
createConflict=El portal entra en conflicto con un portal ya existente
signRightClick=Right click
signToUse=to use gate
signRandom=Random
signDisconnected=Disconnected

View File

@ -1,4 +1,5 @@
prefix=[Stargate] author=Dauphin14
prefix=[Stargate]
teleportMsg=Téléportation Réussie. teleportMsg=Téléportation Réussie.
destroyMsg=Portail detruit. destroyMsg=Portail detruit.
invalidMsg=Destination invalide. invalidMsg=Destination invalide.
@ -20,3 +21,8 @@ createExists=Il existe déjà un portail avec le même nom.
createFull=Le reseau est plein. createFull=Le reseau est plein.
createWorldDeny=Vous n'avez pas accès à ce monde. createWorldDeny=Vous n'avez pas accès à ce monde.
createConflict=Ce portail entre en conflit avec un portail déjà existant. createConflict=Ce portail entre en conflit avec un portail déjà existant.
signRightClick=Right click
signToUse=to use gate
signRandom=Random
signDisconnected=Disconnected

View File

@ -0,0 +1,28 @@
author=HPoltergeist
prefix=[Stargate]
teleportMsg=Teleportálás
destroyMsg=Kapu törölve
invalidMsg=Nincs ilyen cél
blockMsg=Cél blokkolva
destEmpty=A cél lista üres
denyMsg=Hozzáférés megtagadva
ecoDeduct=%cost% levonva
ecoRefund=%cost% visszatérítve
ecoObtain=%cost% bevétel a következő kapuból: %portal%
ecoInFunds=Nincs elég pénzed
createMsg=Kapu elkészült
createNetDeny=Nincs hozzáférésed ahhoz a hálózathoz
createGateDeny=Nincs hozzáférésed ahhoz a kapucsoporthoz
createPersonal=Kapu készítése magán hálózaton
createNameLength=A név túl rövid vagy túl hosszú
createExists=Már van ilyen nevű kapu
createFull=Ez a hálózat tele van
createWorldDeny=Nincs hozzáférésed ahhoz a világhoz
createConflict=Ez a kapu ütközik egy meglévö kapuval
signRightClick=Right click
signToUse=to use gate
signRandom=Random
signDisconnected=Disconnected

View File

@ -1,3 +1,4 @@
author=fr33soul
prefix=[Stargate] prefix=[Stargate]
teleportMsg=Teletrasporto teleportMsg=Teletrasporto
destroyMsg=Portale distrutto destroyMsg=Portale distrutto
@ -20,3 +21,8 @@ createExists=Questo nome gia' esiste
createFull=Questa rete e' piena createFull=Questa rete e' piena
createWorldDeny=Non hai accesso a questo mondo createWorldDeny=Non hai accesso a questo mondo
createConflict=Il portale crea conflitti con uno gia' esistente createConflict=Il portale crea conflitti con uno gia' esistente
signRightClick=Right click
signToUse=to use gate
signRandom=Random
signDisconnected=Disconnected

View File

@ -1,3 +1,4 @@
author=Grovert11
prefix=[Stargate] prefix=[Stargate]
teleportMsg=Je bent geteleporteerd. teleportMsg=Je bent geteleporteerd.
destroyMsg=Gate kapot gemaakt destroyMsg=Gate kapot gemaakt
@ -20,3 +21,8 @@ createExists=Er bestaat al een gate met die naam
createFull=Dit netwerk is vol. createFull=Dit netwerk is vol.
createWorldDeny=Je mag niet in die wereld komen. createWorldDeny=Je mag niet in die wereld komen.
createConflict=Gate maakt een conflict met een bestaande gate. createConflict=Gate maakt een conflict met een bestaande gate.
signRightClick=Right click
signToUse=to use gate
signRandom=Random
signDisconnected=Disconnected

View File

@ -1,3 +1,4 @@
author=TheProbleemm
prefix=[Stargate] prefix=[Stargate]
teleportMsg=Voce foi teleportado. teleportMsg=Voce foi teleportado.
destroyMsg=Portal destruido. destroyMsg=Portal destruido.
@ -20,3 +21,8 @@ createExists=J
createFull=Esta rede esta cheia. createFull=Esta rede esta cheia.
createWorldDeny=Voce nao tem acesso a esse mundo. createWorldDeny=Voce nao tem acesso a esse mundo.
createConflict=Portal em conflito com um portal ja existente. createConflict=Portal em conflito com um portal ja existente.
signRightClick=Right click
signToUse=to use gate
signRandom=Random
signDisconnected=Disconnected

View File

@ -1,4 +1,5 @@
prefix=[Портал] author=ckr@jk
prefix=[Портал]
teleportMsg=Вы перемещены teleportMsg=Вы перемещены
destroyMsg=Портал уничтожен destroyMsg=Портал уничтожен
invalidMsg=Недопустимый пункт назначения invalidMsg=Недопустимый пункт назначения
@ -20,3 +21,8 @@ createExists=Портал с таким именем уже существует
createFull=Эта сеть порталов заполнена createFull=Эта сеть порталов заполнена
createWorldDeny=У вас нет доступа к этому миру createWorldDeny=У вас нет доступа к этому миру
createConflict=Портал конфликтует с уже существующим порталом createConflict=Портал конфликтует с уже существующим порталом
signRightClick=Right click
signToUse=to use gate
signRandom=Random
signDisconnected=Disconnected

View File

@ -1,6 +1,6 @@
name: Stargate name: Stargate
main: net.TheDgtl.Stargate.Stargate main: net.TheDgtl.Stargate.Stargate
version: 0.7.7.5 version: 0.7.8.0
description: Stargate mod for Bukkit description: Stargate mod for Bukkit
author: Drakia author: Drakia
website: http://www.thedgtl.net website: http://www.thedgtl.net