diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index c76cb94..5257a61 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -8,10 +8,13 @@
-
-
+
+
+
+
+
@@ -35,13 +38,13 @@
-
+
-
+
-
+
@@ -50,8 +53,8 @@
-
-
+
+
@@ -59,19 +62,10 @@
-
-
-
-
-
-
-
-
-
-
-
+
+
@@ -79,20 +73,11 @@
-
-
-
-
-
-
-
-
-
-
-
+
+
@@ -103,8 +88,8 @@
-
-
+
+
@@ -112,11 +97,11 @@
-
+
-
-
+
+
@@ -124,11 +109,20 @@
+
+
+
+
+
+
+
+
+
-
-
+
+
@@ -197,16 +191,16 @@
-
-
-
+
+
+
+
+
+
-
-
-
@@ -278,7 +272,7 @@
-
+
@@ -335,7 +329,7 @@
-
+
1570710866817
@@ -372,11 +366,18 @@
1570880458708
-
+
+ 1570889569695
+
+
+
+ 1570889569695
+
+
-
+
@@ -460,57 +461,14 @@
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -589,27 +547,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -617,20 +554,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -688,133 +611,232 @@
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
+
+
+
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
+
-
+
-
+
-
-
+
+
-
+
-
-
+
+
+
+
+
+
+
+
+
-
+
-
-
+
+
+
+
+
+
-
+
-
-
+
+
-
-
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
+
-
-
+
+
-
+
diff --git a/src/io/meowtype/homeorback/HomeOrBack.scala b/src/io/meowtype/homeorback/HomeOrBack.scala
index 99cc7cf..255e5eb 100644
--- a/src/io/meowtype/homeorback/HomeOrBack.scala
+++ b/src/io/meowtype/homeorback/HomeOrBack.scala
@@ -36,7 +36,7 @@ class HomeOrBack extends JavaPlugin {
// region Configs
- def lang: String = getConfig.getString("lang", "en")
+ def lang: String = getConfig.getString("lang", "en").toLowerCase
def auto_respawn: Boolean = getConfig.getBoolean("auto_respawn", true)
def auto_back: Boolean = getConfig.getBoolean("auto_back", false)
@@ -60,7 +60,6 @@ class HomeOrBack extends JavaPlugin {
// endregion
- private val key_showP = new Object
private val key_show_death_loc = new Object
override def onCommand(sender: CommandSender, command: Command, label: String, args: Array[String]): Boolean = {
@@ -68,7 +67,13 @@ class HomeOrBack extends JavaPlugin {
val player = sender.asInstanceOf[Player]
if(label == "hob") {
player sendMessage util.Arrays.deepToString(args.asInstanceOf[Array[AnyRef]])
- Tpr.debug_show_randomPointWithinTheRing(player, player.getLocation, 100)
+ if(args(0) == "back") {
+ if(!player.hasPermission("hob.back")) {
+ player sendMessage (Lang getFor player).no_permission_command
+ } else {
+ player backTo (self.deathLocationMap get player)
+ }
+ }
//todo
true
} else if(label == "back") {
@@ -86,7 +91,6 @@ class HomeOrBack extends JavaPlugin {
val player = event.getEntity
val loc = player.getLocation
deathLocationMap.put(player, loc)
- player sendMessage "你死了 " + player.hashCode
if(show_death_loc) {
runTask(player, 0, 1, key_show_death_loc) { ()=>
@@ -103,10 +107,7 @@ class HomeOrBack extends JavaPlugin {
@EventHandler def onPlayerRespawn(event: PlayerRespawnEvent) {
val player = event.getPlayer
- player sendMessage "重生了 " + player.hashCode
if(deathLocationMap.containsKey(player)) {
- player sendMessage "死亡地点: " + deathLocationMap.get(player)
-
if(auto_back) {
player backTo (self.deathLocationMap get player)
} else {
@@ -117,11 +118,6 @@ class HomeOrBack extends JavaPlugin {
}
}
- @EventHandler def onInventoryClose(event: InventoryCloseEvent) {
- val player = event.getPlayer
- player sendMessage "你关闭了gui " + event.getInventory.getTitle
- }
-
@EventHandler def onInventoryClick(e: InventoryClickEvent) {
if(e.getInventory.getHolder.isInstanceOf[ReSpawnGui]) {
e.getInventory.getHolder.asInstanceOf[ReSpawnGui] onInventoryClick e
diff --git a/src/io/meowtype/homeorback/Lang.scala b/src/io/meowtype/homeorback/Lang.scala
index 782a82b..d15be9b 100644
--- a/src/io/meowtype/homeorback/Lang.scala
+++ b/src/io/meowtype/homeorback/Lang.scala
@@ -2,12 +2,17 @@ package io.meowtype.homeorback
import java.io._
import java.util
+import java.util.stream._
import java.util.zip._
+import java.util.function._
import org.bukkit.configuration.file._
import org.bukkit.entity.Player
-class Lang(val name: String, val choose_respawn: String,
+class Lang(val name: String,
+ val mapping: util.List[String],
+ val when_default_override: util.List[String],
+ val choose_respawn: String,
val respawn_on_spawn: String,
val auto_choose_when_close: String,
val respawn_near_death: String,
@@ -15,15 +20,27 @@ class Lang(val name: String, val choose_respawn: String,
val back_near_any_time: String,
val back_at_any_time: String,
val tpr_failed: String,
- val no_death_loc: String)
+ val no_death_loc: String,
+ val no_permission_command: String) {
+ var i = 0
+ loop(()=> i < mapping.size, ()=> i += 1) { _ =>
+ mapping.set(i, mapping.get(i).toLowerCase)
+ }
+ i = 0
+ loop(()=> i < when_default_override.size, ()=> i += 1) { _ =>
+ when_default_override.set(i, when_default_override.get(i).toLowerCase)
+ }
+}
object Lang {
- val lang_map = new util.HashMap[String, Lang]()
+ val lang_map = new util.HashMap[String, Lang]
def getFor(player: Player): Lang = {
val local = player.getLocale.toLowerCase
- if((lang_map containsKey local) && !(local == "zh_cn" && self.lang == "lzh_Hans")) lang_map get local
- else if(lang_map containsKey self.lang) lang_map get self.lang
- else lang_map get "en"
+ val default = self.lang
+ val default_lang = if(lang_map containsKey default) lang_map get default else lang_map get "en"
+ val player_lang = lang_map get local
+ if(player_lang == null || default_lang.when_default_override.contains(local) || default_lang.mapping.contains(local)) default_lang
+ else player_lang
}
def loadLang(): Unit = {
@@ -31,30 +48,41 @@ object Lang {
val jar = src.getLocation
val zip = new ZipInputStream(jar.openStream)
- val langs = zip filter { e =>
+ val langs: Stream[Lang] = (zip filter { e =>
val name = e.getName
name.startsWith("lang/") && name.endsWith(".yml")
- } stream() map[Lang] { e =>
- val reader = new InputStreamReader(self.getResource(e.getName), "UTF8")
- val lang: FileConfiguration = YamlConfiguration loadConfiguration reader
- new Lang(
- e.getName substring (5, e.getName.length - 4) toLowerCase,
- lang getString "choose_respawn",
- lang getString "respawn_on_spawn",
- lang getString "auto_choose_when_close",
- lang getString "respawn_near_death",
- lang getString "respawn_at_death",
- lang getString "back_near_any_time",
- lang getString "back_at_any_time",
- lang getString "tpr_failed",
- lang getString "no_death_loc",
- )
- }
+ } stream()).map[Lang](new Function[ZipEntry, Lang] {
+ override def apply(e: ZipEntry): Lang = {
+ val reader = new InputStreamReader(self.getResource(e.getName), "UTF8")
+ val lang: FileConfiguration = YamlConfiguration loadConfiguration reader
+ new Lang(
+ e.getName substring (5, e.getName.length - 4) toLowerCase,
+ {
+ val mapping = lang getStringList "mapping"
+ if(mapping != null) mapping else new util.ArrayList[String]
+ },
+ {
+ val when_default_override = lang getStringList "when_default_override"
+ if(when_default_override != null) when_default_override else new util.ArrayList[String]
+ },
+ lang getString "choose_respawn",
+ lang getString "respawn_on_spawn",
+ lang getString "auto_choose_when_close",
+ lang getString "respawn_near_death",
+ lang getString "respawn_at_death",
+ lang getString "back_near_any_time",
+ lang getString "back_at_any_time",
+ lang getString "tpr_failed",
+ lang getString "no_death_loc",
+ lang getString "no_permission_command",
+ )
+ }
+ })
lang_map.clear()
langs forEach { l: Lang =>
lang_map.put(l.name, l)
- if(l.name == "cmn_hans") lang_map.put("zh_cn", l)
+ l.mapping forEach { m => lang_map.put(m, l)}
}
}
}
diff --git a/src/io/meowtype/homeorback/ReSpawnGui.scala b/src/io/meowtype/homeorback/ReSpawnGui.scala
index 97bea1a..02f3d32 100644
--- a/src/io/meowtype/homeorback/ReSpawnGui.scala
+++ b/src/io/meowtype/homeorback/ReSpawnGui.scala
@@ -1,6 +1,8 @@
package io.meowtype.homeorback
import java.util
+import java.util.regex._
+import java.util.stream.Collectors
import org.bukkit._
import org.bukkit.entity._
@@ -31,9 +33,8 @@ class ReSpawnGui(lang: Lang) extends InventoryHolder {
meta setDisplayName name
if(lore != null) {
- val metalore = new util.ArrayList[String]
- metalore add lore
- meta setLore metalore
+ val lores = lore.split("\\\\n")
+ meta setLore (util.Arrays stream lores collect Collectors.toList[String])
}
item setItemMeta meta
diff --git a/src/io/meowtype/homeorback/package.scala b/src/io/meowtype/homeorback/package.scala
index 8123be7..2853690 100644
--- a/src/io/meowtype/homeorback/package.scala
+++ b/src/io/meowtype/homeorback/package.scala
@@ -9,6 +9,7 @@ import java.util.zip.{ZipEntry, ZipInputStream}
import org.bukkit.{Bukkit, Location, Particle}
import org.bukkit.entity.Player
+import org.bukkit.inventory.meta.ItemMeta
import org.bukkit.scheduler.{BukkitRunnable, BukkitTask}
import org.sqlite.SQLiteConfig
diff --git a/src/lang/cmn_Hans.yml b/src/lang/cmn_Hans.yml
index 5fb9965..226f4d2 100644
--- a/src/lang/cmn_Hans.yml
+++ b/src/lang/cmn_Hans.yml
@@ -1,3 +1,4 @@
+mapping: [zh_cn]
choose_respawn: 选择复活方式
respawn_on_spawn: §6在复活点重生
auto_choose_when_close: §f关闭界面自动选择此项
@@ -6,4 +7,5 @@ respawn_at_death: §6在死亡地点重生
back_near_any_time: §f你随时都能使用 §6/back §f来回到死亡地点附近
back_at_any_time: §f你随时都能使用 §6/back §f来回到死亡地点
tpr_failed: §c随机传送失败,附近没有任何落脚点
-no_death_loc: §c返回失败,你还没有死呢!
\ No newline at end of file
+no_death_loc: §c返回失败,你还没有死呢!
+no_permission_command: §c执行失败,你没有权限
\ No newline at end of file
diff --git a/src/lang/en.yml b/src/lang/en.yml
index 73f751d..ce06673 100644
--- a/src/lang/en.yml
+++ b/src/lang/en.yml
@@ -1,9 +1,11 @@
-choose_respawn: Choose a resurrection method
+mapping: [en_us]
+choose_respawn: Choose how to respawn
respawn_on_spawn: §6Respawn at the spawn location
auto_choose_when_close: §fWhen close auto choose this
respawn_near_death: §6Respawn near the death location
respawn_at_death: §6Respawn at the death location
-back_near_any_time: §fYou can always use §f/back §fto get back to near the death location
-back_at_any_time: §fYou can always use §f/back §fto get back to the death location
+back_near_any_time: §fYou can always use §f/back \n§fto get back to near the death location
+back_at_any_time: §fYou can always use §f/back \n§fto get back to the death location
tpr_failed: §cRandom teleport failed, there is no space nearby to stand
-no_death_loc: §cCan't back, you have not died yet!
\ No newline at end of file
+no_death_loc: §cCan't back, you have not died yet!
+no_permission_command: §cExecution command failed, you do not have permission
\ No newline at end of file
diff --git a/src/lang/lzh_Hans.yml b/src/lang/lzh_Hans.yml
index 7ce3775..408af60 100644
--- a/src/lang/lzh_Hans.yml
+++ b/src/lang/lzh_Hans.yml
@@ -1,3 +1,4 @@
+when_default_override: [zh_cn]
choose_respawn: 择生也
respawn_on_spawn: §6生于生点
auto_choose_when_close: §f闭自择此项
@@ -6,4 +7,5 @@ respawn_at_death: §6死地复生
back_near_any_time: §f尔时皆可以 §6/back §f归死地近
back_at_any_time: §f尔时皆可以 §6/back §f归死地
tpr_failed: §c随传失败,近无可立之间
-no_death_loc: §c不可归,汝尚未死!
\ No newline at end of file
+no_death_loc: §c不可归,汝尚未死!
+no_permission_command: §c不可执令,汝无权度
\ No newline at end of file