diff --git a/pom.xml b/pom.xml
index 65b8b5d..c8d6000 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see
+ * A special thanks to @ExtendedClip for letting me use and modify this class from PlaceholderAPI */ /** @@ -31,9 +33,13 @@ import java.util.regex.Pattern; public class TimeUtil { private static String dayFormat; + private static String dayPlural; private static String hourFormat; + private static String hourPlural; private static String minuteFormat; + private static String minutePlural; private static String secondFormat; + private static String secondPlural; /** * Gets formatted time from seconds @@ -71,23 +77,61 @@ public class TimeUtil { secondFormat = shorts[0]; break; case MEDIUM: - dayFormat = " " + mediums[3]; - hourFormat = " " + mediums[2]; - minuteFormat = " " + mediums[1]; - secondFormat = " " + mediums[0]; + String mediumsAfter[] = new String[4]; + String mediumsPlurals[] = new String[4]; + Pattern patternMediums = Pattern.compile("([^]]*)\\(([^]]*)\\)"); + for (int i = 0; i < mediums.length; i++) { + if (mediums[i].contains("(") && mediums[i].contains(")")) { + Matcher matcher = patternMediums.matcher(mediums[i]); + if (matcher.find()) { + mediumsAfter[i] = matcher.group(1); + mediumsPlurals[i] = matcher.group(2); + } + } else { + mediumsAfter[i] = mediums[i]; + mediumsPlurals[i] = ""; + } + } + dayFormat = " " + mediumsAfter[3]; + dayPlural = mediumsPlurals[3]; + hourFormat = " " + mediumsAfter[2]; + hourPlural = mediumsPlurals[2]; + minuteFormat = " " + mediumsAfter[1]; + minutePlural = mediumsPlurals[1]; + secondFormat = " " + mediumsAfter[0]; + secondPlural = mediumsPlurals[0]; break; case FULL: - dayFormat = " " + fulls[3]; - hourFormat = " " + fulls[2]; - minuteFormat = " " + fulls[1]; - secondFormat = " " + fulls[0]; + String fullsAfter[] = new String[4]; + String fullsPlurals[] = new String[4]; + Pattern patternFulls = Pattern.compile("([^]]*)\\(([^]]*)\\)"); + for (int i = 0; i < fulls.length; i++) { + if (fulls[i].contains("(") && fulls[i].contains(")")) { + Matcher matcher = patternFulls.matcher(fulls[i]); + if (matcher.find()) { + fullsAfter[i] = matcher.group(1); + fullsPlurals[i] = matcher.group(2); + } + } else { + fullsAfter[i] = fulls[i]; + fullsPlurals[i] = ""; + } + } + dayFormat = " " + fullsAfter[3]; + dayPlural = fullsPlurals[3]; + hourFormat = " " + fullsAfter[2]; + hourPlural = fullsPlurals[2]; + minuteFormat = " " + fullsAfter[1]; + minutePlural = fullsPlurals[1]; + secondFormat = " " + fullsAfter[0]; + secondPlural = fullsPlurals[0]; break; } if (seconds < 60) { if (seconds == 1 && !format.equals(DisplayFormat.SHORT)) - return seconds + secondFormat.substring(0, secondFormat.length() - 1); - return seconds + secondFormat; + return seconds + secondFormat; + return seconds + secondFormat + secondPlural; } long minutes = TimeUnit.SECONDS.toMinutes(seconds); @@ -97,41 +141,41 @@ public class TimeUtil { if (minutes == 1 && !format.equals(DisplayFormat.SHORT)) { if (secondsLeft > 0) { if (secondsLeft == 1 && !format.equals(DisplayFormat.SHORT)) - return String.valueOf(minutes + minuteFormat.substring(0, secondFormat.length() - 1) + " " + secondsLeft + secondFormat.substring(0, secondFormat.length() - 1)); - return String.valueOf(minutes + minuteFormat.substring(0, secondFormat.length() - 1) + " " + secondsLeft + secondFormat); + return String.valueOf(minutes + minuteFormat + " " + secondsLeft + secondFormat); + return String.valueOf(minutes + minuteFormat + " " + secondsLeft + secondFormat + secondPlural); } else - return String.valueOf(minutes + minuteFormat.substring(0, secondFormat.length() - 1)); + return String.valueOf(minutes + minuteFormat); } else { if (secondsLeft > 0) { if (secondsLeft == 1 && !format.equals(DisplayFormat.SHORT)) - return String.valueOf(minutes + minuteFormat + " " + secondsLeft + secondFormat.substring(0, secondFormat.length() - 1)); - return String.valueOf(minutes + minuteFormat + " " + secondsLeft + secondFormat); + return String.valueOf(minutes + minuteFormat + minutePlural + " " + secondsLeft + secondFormat); + return String.valueOf(minutes + minuteFormat + minutePlural + " " + secondsLeft + secondFormat + secondPlural); } else - return String.valueOf(minutes + minuteFormat); + return String.valueOf(minutes + minuteFormat + minutePlural); } } if (minutes < 1440) { - long hours = TimeUnit.MINUTES.toHours(minutes); + long hours = TimeUnit.MINUTES.toHours(minutes); String time; if (hours == 1 && !format.equals(DisplayFormat.SHORT)) - time = hours + hourFormat.substring(0, hourFormat.length() - 1); - else time = hours + hourFormat; + else + time = hours + hourFormat + hourPlural; long leftOver = minutes - TimeUnit.HOURS.toMinutes(hours); if (leftOver >= 1) { if (leftOver == 1 && !format.equals(DisplayFormat.SHORT)) - time += " " + leftOver + minuteFormat.substring(0, minuteFormat.length() - 1); - else time += " " + leftOver + minuteFormat; + else + time += " " + leftOver + minuteFormat + minutePlural; } if (secondsLeft > 0) if (secondsLeft == 1 && !format.equals(DisplayFormat.SHORT)) - time += " " + secondsLeft + secondFormat.substring(0, secondFormat.length() - 1); - else time += " " + secondsLeft + secondFormat; + else + time += " " + secondsLeft + secondFormat + secondPlural; return time; } @@ -139,36 +183,36 @@ public class TimeUtil { long days = TimeUnit.MINUTES.toDays(minutes); String time; if (days == 1 && !format.equals(DisplayFormat.SHORT)) - time = days + dayFormat.substring(0, dayFormat.length() - 1); - else time = days + dayFormat; + else + time = days + dayFormat + dayPlural; long leftOver = minutes - TimeUnit.DAYS.toMinutes(days); if (leftOver >= 1) { if (leftOver < 60) { if (leftOver == 1 && !format.equals(DisplayFormat.SHORT)) - time += " " + leftOver + minuteFormat.substring(0, minuteFormat.length() - 1); - else time += " " + leftOver + minuteFormat; + else + time += " " + leftOver + minuteFormat + minutePlural; } else { long hours = TimeUnit.MINUTES.toHours(leftOver); if (hours == 1 && !format.equals(DisplayFormat.SHORT)) - time += " " + hours + hourFormat.substring(0, hourFormat.length() - 1); - else time += " " + hours + hourFormat; + else + time += " " + hours + hourFormat + hourPlural; long minsLeft = leftOver - TimeUnit.HOURS.toMinutes(hours); if (minsLeft == 1 && !format.equals(DisplayFormat.SHORT)) - time += " " + minsLeft + minuteFormat.substring(0, minuteFormat.length() - 1); - else time += " " + minsLeft + minuteFormat; + else + time += " " + minsLeft + minuteFormat + minutePlural; } } if (secondsLeft > 0) { if (secondsLeft == 1 && !format.equals(DisplayFormat.SHORT)) - time += " " + secondsLeft + secondFormat.substring(0, secondFormat.length() - 1); - else time += " " + secondsLeft + secondFormat; + else + time += " " + secondsLeft + secondFormat + secondPlural; } return time; diff --git a/src/main/java/me/mattmoreira/citizenscmd/utility/Util.java b/src/main/java/me/mattmoreira/citizenscmd/utility/Util.java index 6cfb168..6a2f14e 100644 --- a/src/main/java/me/mattmoreira/citizenscmd/utility/Util.java +++ b/src/main/java/me/mattmoreira/citizenscmd/utility/Util.java @@ -22,8 +22,13 @@ import me.mattmoreira.citizenscmd.CitizensCMD; import net.citizensnpcs.api.CitizensAPI; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.configuration.InvalidConfigurationException; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; +import java.io.File; +import java.io.IOException; import java.util.concurrent.TimeUnit; public class Util { @@ -168,4 +173,47 @@ public class Util { return TimeUnit.SECONDS.convert((System.nanoTime() - storedTime), TimeUnit.NANOSECONDS); } + /** + * Checks for old config and renames it + */ + public static void checkOldConfig() { + File configFile; + File configFileNew; + FileConfiguration configConf; + + boolean isNew = true; + + boolean contains[] = new boolean[5]; + for (int i = 0; i < contains.length; i++) { + contains[i] = false; + } + + try { + configFile = new File(CitizensCMD.getPlugin().getDataFolder(), "config.yml"); + configFileNew = new File(CitizensCMD.getPlugin().getDataFolder(), "config_old.yml"); + configConf = new YamlConfiguration(); + + if (configFile.exists()) { + configConf.load(configFile); + if (configConf.contains("check-updates")) contains[0] = true; + if (configConf.contains("lang")) contains[1] = true; + if (configConf.contains("default-cooldown")) contains[2] = true; + if (configConf.contains("shift-confirm")) contains[3] = true; + if (configConf.contains("cooldown-time-display")) contains[4] = true; + } + + for (boolean bool : contains) { + if (!bool) { + isNew = false; + } + } + + if (!isNew) { + configFile.renameTo(configFileNew); + } + + } catch (IOException | InvalidConfigurationException e) { + e.printStackTrace(); + } + } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index ee0d194..d75f70e 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,12 +1,16 @@ # Citizens CMD Plugin by Mateus Moreira # @LichtHund # Version ${project.version} +# Wiki: https://github.com/ipsk/CitizensCMD/wiki +# GitHub: https://github.com/ipsk/CitizensCMD +# Spigot: https://www.spigotmc.org/resources/citizens-cmd.30224/ + # # Enables Checking for update. check-updates: true # -# Available languages EN, PT, BG, RO, NO -lang: en +# Available languages EN, PT, BG, RO, NO, CH +lang: 'en' # # The default npc cooldown in seconds default-cooldown: 0 diff --git a/src/main/resources/lang/ch.yml b/src/main/resources/lang/ch.yml new file mode 100644 index 0000000..e293880 --- /dev/null +++ b/src/main/resources/lang/ch.yml @@ -0,0 +1,62 @@ +# Citizens CMD Plugin by Mateus Moreira +# @LichtHund +# Version ${project.version} +# +# Change as much as you need. +# Remove placeholders with caution! +# Some placeholders can be removed but might not work correctly +# Cooldown placeholder is safe to be deleted +messages: + commands: + npc-add-command-added: "&a你已經成功新增指令到這個npc!" + npc-add-command-failed: "&c新增指令到這個npc失敗!" + npc-cooldown-set: "&a你已經成功設定冷卻時間!" + npc-cooldown-error: "&c設定冷卻時間時有錯誤!" + npc-price-set: "&a你已經成功設定價格!" + list-commnads-counter-right: "&c&o{count} &7&o- 右鍵指令:" + list-commnads-counter-left: "&c&o{count} &7&o- 左鍵指令:" + list-cooldown: "&7冷卻時間: &c" + list-price: "&7價格: &c" + list-tooltip: "&7按下來編輯!" + reload-command: "&a所有檔案已經被重新載入!" + removed-command: "&a這個指令已經被成功移除!" + edit-command: "&a {type} 已經被編輯!" + warnings: + no-npc-selected: "&c你一定要選擇NPC來執行那個指令!" + invalid-cooldown: "&c冷卻時間並不是數字!" + invalid-price: "&c價格並不是數字!" + invalid-id: "&c請用一個正確的指令ID!" + invalid-click-type: "&c你一定要選擇左邊或右邊!" + no-commands: "&c這個NPC已經沒有更多指令!" + invalid-arguments: "&c你一定要選擇 CMD 或 PERM!" + invalid-permission: "&c權限不能包括空格!" + console-not-allowed: "&c這指令只能在遊戲中執行!不能在console執行!" + no-permission: "&c你沒有權限去執行這個指令!" + wrong-usage: "&c錯誤用法! &7/npcmd &c來看指令用法!" + new-version: "&7有新的版本可供用: &cv" + download-at: "&7下載:" + npc: + on-cooldown: "&7請等 &c{time} 之後再用這個指令" + one-time-click: "&7這NPC只供一次性的使用!" + pay-confirm: "&7如果要用這個NPC,你要付費 &a{price}$&7!\n&a{shift}欲確定,按右鍵&7or &c{shift}欲取消,按左鍵\n&8這行動會自動在 &c15 &8秒內取消!" + pay-canceled: "&c付費被取消!" + pay-no-money: "&c你沒有足夠的金錢!" + pay-completed: "&a已經在你的帳戶扣去{price}$!" + help: + version: "&7&o版本:" + info: "&7欲要知道更多,把鼠標停留在一個指令上!" + example: "&8例子:" + description-add: "&7添加指令到NPC." + description-cooldown: "&7設定使用NPC冷卻時間,以秒作單位." + description-price: "&7設定要使用NPC的價格." + description-list: "&7顯示這個NPC的所有指令." + description-edit: "&7編輯特定的指令或權限." + description-remove: "&7從一個NPC移除一個指令." + description-reload: "&7重新載入所有檔案." +# IMPORTANT!! +# DO NOT CHANGE THIS PATTERN, KEEP THE "[]," CHANGE ONLY THE TEXT INSIDE + time-format: + seconds: "[s], [秒], [秒]" + minutes: "[m], [分钟], [分钟]" + hours: "[h], [小时], [小时]" + days: "[d], [天], [天]" \ No newline at end of file diff --git a/src/main/resources/lang/en.yml b/src/main/resources/lang/en.yml index e56dd48..5124f85 100644 --- a/src/main/resources/lang/en.yml +++ b/src/main/resources/lang/en.yml @@ -54,10 +54,9 @@ messages: description-remove: "&7Removes a command from the NPC." description-reload: "&7Reloads all the files." # IMPORTANT!! -# DO NOT CHANGE THIS PATTERN, KEEP THE "[]," CHANGE ONLY THE TEXT INSIDE +# DO NOT CHANGE THIS PATTERN, KEEP THE "[]," CHANGE ONLY THE TEXT INSIDE, O "()" contém os PLURALS time-format: - seconds: "[s], [secs], [seconds]" - minutes: "[m], [mins], [minutes]" - hours: "[h], [hours], [hours]" - days: "[d], [days], [days]" - + seconds: "[s], [sec(s)], [second(s)]" + minutes: "[m], [min(s)], [minute(s)]" + hours: "[h], [hour(s)], [hour(s)]" + days: "[d], [day(s)], [day(s)]" \ No newline at end of file diff --git a/src/main/resources/lang/no.yml b/src/main/resources/lang/no.yml new file mode 100644 index 0000000..f67f877 --- /dev/null +++ b/src/main/resources/lang/no.yml @@ -0,0 +1,62 @@ +# Citizens CMD Plugin by Mateus Moreira +# @LichtHund +# Version ${project.version} +# +# Change as much as you need. +# Remove placeholders with caution! +# Some placeholders can be removed but might not work correctly +# Cooldown placeholder is safe to be deleted +messages: + commands: + npc-add-command-added: "&aDu har lagt til kommandoen til NPCen!" + npc-add-command-failed: "&cKunne ikke legge til kommandoen!" + npc-cooldown-set: "&aEn nedtelling ble lagt til!" + npc-cooldown-error: "&cEn error ble oppdaget når du skulle legge til en nedtelling!" + npc-price-set: "&aDu har satt en pris!" + list-commnads-counter-right: "&c&o{count} &7&o- Høyre klikk:" + list-commnads-counter-left: "&c&o{count} &7&o- Venstre klikk" + list-cooldown: "&7Nedtelling: &c" + list-price: "&7Pris: &c" + list-tooltip: "&7Klikk for å endre!" + reload-command: "&aAlle fillene har blitt reloadet!" + removed-command: "&aKommandoen ble fjernet!" + edit-command: "&a{type} ble endret!" + warnings: + no-npc-selected: "&cDu må velge en NPC for å utføre denne kommandoen!" + invalid-cooldown: "&cNedtellingen må være et tall!" + invalid-price: "&cPrisen må være et tall!" + invalid-id: "&cBruk et gyldig ID" + invalid-click-type: "&cDu må enten velge left eller right" + no-commands: "&cDet er ingen flere kommandoer i denne NPCen" + invalid-arguments: "&cDu må velge enten CMD eller PERM!" + invalid-permission: "&cPermission kan ikke inneholde et mellomrom!" + console-not-allowed: "&cDenne kommandoen kan kun utføres ingame!" + no-permission: "&cDu har ikke tilgang til å bruke denne kommandoen!" + wrong-usage: "&cFeil bruk av kommandoen! &7/npcmd &cfor hjelp!" + new-version: "&7Ny versjon er tilgjengelig: &cv" + download-at: "&7Last ned her" + npc: + on-cooldown: "&7Vent &c{time} &7før du bruker denne igjen!" + one-time-click: "&7Denne NPCen kan kun brukes engang!" + pay-confirm: "&7For å bruke denne NPCen må du betale &a{price}$&7!\n&a{shift}Høyre klikk for å bekrefte &7or &c{shift}Venstre klikk for å avbryte\n&8Denne vil bli automatisk avslått om &c15 &8sekunder!" + pay-canceled: "&cBetaling avslått!" + pay-no-money: "&cDu har ikke nok penger til dette!" + pay-completed: "&a{price}$ har blitt tatt fra din konto!" + help: + version: "&7&oVersjon:" + info: "&7Hold musen over for å få infomarsjon!" + example: "&8Eksempel:" + description-add: "&7Legg til kommandoer." + description-cooldown: "&7Legge til en nedtelling i sekunder!" + description-price: "&7Sett en pris på NPCen" + description-list: "&7Se liste over kommandoen som er på NPCen" + description-edit: "&7Endre en kommando eller permission" + description-remove: "&7Fjerne en kommando fra NPCen" + description-reload: "&7reloade alle filene" +# IMPORTANT!! +# DO NOT CHANGE THIS PATTERN, KEEP THE "[]," CHANGE ONLY THE TEXT INSIDE + time-format: + seconds: "[s], [sek], [sekund(er)]" + minutes: "[m], [min], [minutt(er)]" + hours: "[h], [time(r)], [time(r)]" + days: "[d], [dag(er)], [dag(er)]" diff --git a/src/main/resources/lang/pt.yml b/src/main/resources/lang/pt.yml index 1c86c50..208dda4 100644 --- a/src/main/resources/lang/pt.yml +++ b/src/main/resources/lang/pt.yml @@ -1,5 +1,63 @@ +# Citizens CMD Plugin by Mateus Moreira +# @LichtHund +# Versão ${project.version} +# +# Mude o tanto que for necessário. +# Tome cuidado ao remover os placeholders! +# Alguns placeholders podem ser removidos mas podem não funcionar corretamente. +# Os placeholders do cooldown podem ser removidos com segurança. messages: commands: - command1: "" + npc-add-command-added: "&aVocê adicionou um comando ao NPC com sucesso!" + npc-add-command-failed: "&cFalha ao adicionar comando ao NPC!" + npc-cooldown-set: "&aVocê definiu com o cooldown sucesso!" + npc-cooldown-error: "&cOcorreu um erro ao definir o cooldown!" + npc-price-set: "&aVocê definiu o preço com sucesso!" + list-commnads-counter-right: "&c&o{count} &7&o- Comandos de clique direito:" + list-commnads-counter-left: "&c&o{count} &7&o- Comandos de clique esquerdo:" + list-cooldown: "&7Cooldown: &c" + list-price: "&7Preço: &c" + list-tooltip: "&7Clique para editar!" + reload-command: "&aTodos os arquivos foram recarregados com sucesso!" + removed-command: "&aO comando foi removido com sucesso!" + edit-command: "&aO {type} foi editado com sucesso!" warnings: - no-npc-selected: "&ctenho que traduzir depois mas aborrece!" \ No newline at end of file + no-npc-selected: "&cVocê deve ter um NPC selecionado para executar esse comando!" + invalid-cooldown: "&cO cooldown deve ser um número!" + invalid-price: "&cO preço deve ser um número!" + invalid-id: "&cPor favor, introduza um ID de comando válido!" + invalid-click-type: "&cVocê deve selecionar esquerda ou direita!" + no-commands: "&cNão há mais comandos neste NPC!" + invalid-arguments: "&cVocê deve selecionar CMD ou PERM!" + invalid-permission: "&cPermissões não podem conter espaços!" + console-not-allowed: "&cEste comando não pode ser executado a partir do console, apenas no jogo!" + no-permission: "&cVocê não tem permissão para executar este comando!" + wrong-usage: "&cUso errado do comando! &7/npcmd &cpara ajuda!" + new-version: "&7Nova versão disponível: &cv" + download-at: "&7Faça download em" + npc: + on-cooldown: "&7Por favor, aguarde &c{time} &7antes de usar este NPC novamente!" + one-time-click: "&7Este NPC permite apenas um uso!" + pay-confirm: "&7Para usar este NPC você deve pagar &a{price}$&7!\n&a{shift}Clique com o botão direito para confirmar &7or &c{shift}Clique esquerdo para cancelar\n&8Esta operação será cancelada em &c15 &8segundos!" + pay-canceled: "&cPagamento cancelado!" + pay-no-money: "&cVocê não tem dinheiro suficiente para fazer isso!" + pay-completed: "&a{price}$ foi retirado da sua conta!" + help: + version: "&7&oVersão:" + info: "&7Passe o mouse sobre um comando para mais informações e exemplos!" + example: "&8Exemplos:" + description-add: "&7Adiciona comandos a um NPC." + description-cooldown: "&7Define o tempo de espera do clique do NPC, em segundos." + description-price: "&7Define o preço para usar o NPC." + description-list: "&7Exibe lista de comandos para o NPC atual." + description-edit: "&7Edita um comando ou permissão específica." + description-remove: "&7Remove um comando do NPC." + description-reload: "&7Recarrega todos os arquivos." +# IMPORTANT!! +# NÃO MUDE ESTE PADRÃO, MANTENHA O "[]," MUDE APENAS O TEXTO DENTRO + time-format: + seconds: "[s], [seg(s)], [secondo(s)]" + minutes: "[m], [min(s)], [minuto(s)]" + hours: "[h], [hora(s)], [hora(s)]" + days: "[d], [dia(s)], [dia(s)]" + diff --git a/src/main/resources/lang/ro.yml b/src/main/resources/lang/ro.yml index 856df78..c6a00bf 100644 --- a/src/main/resources/lang/ro.yml +++ b/src/main/resources/lang/ro.yml @@ -57,6 +57,6 @@ messages: # NU MODIFICATI ACEST MODEL, PASTRATI "[]," SI MODIFICATI DOAR TEXTUL DIN INTERIOR time-format: seconds: "[s], [sec], [secunde]" - minutes: "[m], [min], [minute]" + minutes: "[m], [min], [minut(e)]" hours: "[h], [ore], [ore]" - days: "[z], [zile], [zile]" \ No newline at end of file + days: "[z], [zi(le)], [zi(le)]" \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 7a6796b..ea8d1a1 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,8 @@ # Citizens CMD Plugin by Mateus Moreira aka iPSYKO # @LichtHund +# Wiki: https://github.com/ipsk/CitizensCMD/wiki +# GitHub: https://github.com/ipsk/CitizensCMD +# Spigot: https://www.spigotmc.org/resources/citizens-cmd.30224/ main: me.mattmoreira.citizenscmd.CitizensCMD version: ${project.version}