From ae1ef10ccbc77cf6c863d595a87e6165f4998652 Mon Sep 17 00:00:00 2001 From: Sn0wStorm Date: Mon, 27 Jun 2016 23:57:58 +0200 Subject: [PATCH] Added optional Player argument to /brew create adds #73 allowing /brew create in command blocks --- resources/languages/de.yml | 12 +-- resources/languages/en.yml | 12 +-- resources/languages/fr.yml | 12 +-- resources/languages/no.yml | 74 ------------------- src/com/dre/brewery/P.java | 2 +- .../dre/brewery/filedata/LanguageReader.java | 12 +-- .../brewery/listeners/CommandListener.java | 57 ++++++++------ 7 files changed, 60 insertions(+), 121 deletions(-) delete mode 100644 resources/languages/no.yml diff --git a/resources/languages/de.yml b/resources/languages/de.yml index ac662f9..bcd8367 100644 --- a/resources/languages/de.yml +++ b/resources/languages/de.yml @@ -55,23 +55,23 @@ Etc_Usage: 'Benutzung:' Etc_Barrel: Fass # Help -Help_Copy: '&6/brew Copy &9 Kopiert den Trank in deiner Hand' +Help_Copy: '&6/brew Copy [Anzahl]&9 Kopiert den Trank in deiner Hand' Help_Delete: '&6/brew Delete &9Entfernt den Trank in deiner Hand' -Help_Help: '&6/brew help &9Zeigt eine bestimmte Hilfeseite an' +Help_Help: '&6/brew help [Seite] &9Zeigt eine bestimmte Hilfeseite an' Help_Info: '&6/brew Info&9 Zeigt deine aktuelle Trunkenheit und Qualität an' -Help_InfoOther: '&6/brew Info &9 Zeigt die aktuelle Trunkenheit und Qualität von an' -Help_Player: '&6/brew <%Trunkenheit> &9 Setzt Trunkenheit (und Qualität) eines Spielers' +Help_InfoOther: '&6/brew Info [Spieler]&9 Zeigt die aktuelle Trunkenheit und Qualität von [Spieler] an' +Help_Player: '&6/brew <%Trunkenheit> [Qualität]&9 Setzt Trunkenheit (und Qualität) eines Spielers' Help_Reload: '&6/brew reload &9Config neuladen' Help_UnLabel: '&6/brew UnLabel &9Entfernt die genaue Beschriftung des Trankes' Help_Wakeup: '&6/brew Wakeup List &9 Listet alle Aufwachpunkte auf' Help_WakeupAdd: '&6/brew Wakeup Add &9Setzt einen Aufwachpunkt and deiner Position' Help_WakeupCheck: '&6/brew Wakeup Check &9Teleportiert zu allen Aufwachpunkten' Help_WakeupCheckSpecific: '&6/brew Wakeup Check &9Teleportiert zu einem Aufwachpunkt' -Help_WakeupList: '&6/brew Wakeup List &9 Listet die Aufwachpunkte einer Welt auf' +Help_WakeupList: '&6/brew Wakeup List [Welt]&9 Listet die Aufwachpunkte einer Welt auf' Help_WakeupRemove: '&6/brew Wakeup Remove &9Entfernt einen Aufwachpunkt' Help_Persist: '&6/brew Persist &9Trankdaten permanent machen -> Kopierbar durch andere Plugins' Help_Static: '&6/brew Static &9Trank unveränderlich machen -> Kein weiteres reifen oder destillieren möglich' -Help_Create: '&6/brew Create &9Erstellt einen Trank mit optionaler Qualität (1-10)' +Help_Create: '&6/brew Create [Qualität] [Spieler] &9Erstellt einen Trank mit optionaler Qualität (1-10)' # Player Player_BarrelCreated: Fass erfolgreich erstellt diff --git a/resources/languages/en.yml b/resources/languages/en.yml index efadaae..a4b49bf 100644 --- a/resources/languages/en.yml +++ b/resources/languages/en.yml @@ -48,14 +48,14 @@ Etc_Page: Page Etc_Usage: 'Usage:' # Help -Help_Copy: '&6/brew copy &9 Copies the potion in your hand' -Help_Create: '&6/brew create &9Create a Brew with optional quality (1-10)' +Help_Copy: '&6/brew copy [Quantity]&9 Copies the potion in your hand' +Help_Create: '&6/brew create [Quality] [Player] &9Create a Brew with optional quality (1-10)' Help_Delete: '&6/brew delete &9Deletes the potion in your hand' -Help_Help: '&6/brew help &9Shows a specific help-page' +Help_Help: '&6/brew help [Page] &9Shows a specific help-page' Help_Info: '&6/brew info&9 Displays your current Drunkeness and Quality' -Help_InfoOther: '&6/brew info &9 Displays the current Drunkeness and Quality of ' +Help_InfoOther: '&6/brew info [Player]&9 Displays the current Drunkeness and Quality of [Player]' Help_Persist: '&6/brew persist &9Make Brew persistent -> copyable by any plugin and technique' -Help_Player: '&6/brew <%Drunkeness> &9 Sets Drunkeness (and Quality) of a Player' +Help_Player: '&6/brew <%Drunkeness> [Quality]&9 Sets Drunkeness (and Quality) of a Player' Help_Reload: '&6/brew reload &9Reload config' Help_Static: '&6/brew static &9Make Brew static -> No further ageing or distilling' Help_UnLabel: '&6/brew unlabel &9Removes the detailled label of a potion' @@ -63,7 +63,7 @@ Help_Wakeup: '&6/brew wakeup list &9 Lists all wakeup points' Help_WakeupAdd: '&6/brew wakeup add &9Adds a wakeup point at your current position' Help_WakeupCheck: '&6/brew wakeup check &9Teleports to all wakeup points' Help_WakeupCheckSpecific: '&6/brew wakeup check &9Teleports to the wakeup point with ' -Help_WakeupList: '&6/brew wakeup list &9 Lists all wakeup points of ' +Help_WakeupList: '&6/brew wakeup list [World]&9 Lists all wakeup points of ' Help_WakeupRemove: '&6/brew wakeup remove &9Removes the wakeup point with ' # Perms diff --git a/resources/languages/fr.yml b/resources/languages/fr.yml index f4c94b2..0af27d9 100644 --- a/resources/languages/fr.yml +++ b/resources/languages/fr.yml @@ -48,14 +48,14 @@ Etc_Page: Page Etc_Usage: 'Utilise:' # Aide -Help_Copy: '&6/brew copy &9 Copie la potion qui est dans votre main' -Help_Create: '&6/brew create &9Crée une boisson avec une qualité optionelle (1-10)' +Help_Copy: '&6/brew copy [Quantity]&9 Copie la potion qui est dans votre main' +Help_Create: '&6/brew create [Quality] [Player] &9Crée une boisson avec une qualité optionelle (1-10)' Help_Delete: '&6/brew delete &9Supprime la potion qui est dans votre main' -Help_Help: '&6/brew help &9Affiche une page spécifique de l´aide' +Help_Help: '&6/brew help [Page] &9Affiche une page spécifique de l´aide' Help_Info: '&6/brew info&9 Affiche votre ivresse actuelle ainsi que sa qualité' -Help_InfoOther: '&6/brew info &9 Affiche l´ivresse actuelle de , cette commande affiche aussi sa qualité.' +Help_InfoOther: '&6/brew info [Player]&9 Affiche l´ivresse actuelle de , cette commande affiche aussi sa qualité.' Help_Persist: '&6/brew persist &9Crée une boisson persistante -> peut être copiée par n´importe quel plugin et technique' -Help_Player: '&6/brew <%Drunkeness> &9 Définit l´ivresse (et la qualité) du joueur' +Help_Player: '&6/brew <%Drunkeness> [Quality]&9 Définit l´ivresse (et la qualité) du joueur' Help_Reload: '&6/brew reload &9Reload la config' Help_Static: '&6/brew static &9Rend une boisson statique -> Plus affectée par l´âge ou la distillation' Help_UnLabel: '&6/brew unlabel &9Supprime l´étiquette détaillée d´une potion' @@ -63,7 +63,7 @@ Help_Wakeup: '&6/brew wakeup list &9 Affiche une liste de tous les points Help_WakeupAdd: '&6/brew wakeup add &9Ajoute un point de réveil à votre position' Help_WakeupCheck: '&6/brew wakeup check &9Téléportation vers tous les points de réveil' Help_WakeupCheckSpecific: '&6/brew wakeup check &9Téléportation vers le point de réveil avec l´ID ' -Help_WakeupList: '&6/brew wakeup list &9 Affiche une liste de tous les points de réveil de ' +Help_WakeupList: '&6/brew wakeup list [World]&9 Affiche une liste de tous les points de réveil de [world]' Help_WakeupRemove: '&6/brew wakeup remove &9Enlève le point de réveil avec l´ID ' # Permissions diff --git a/resources/languages/no.yml b/resources/languages/no.yml deleted file mode 100644 index 431ed1b..0000000 --- a/resources/languages/no.yml +++ /dev/null @@ -1,74 +0,0 @@ -Brew_-times: -times -Brew_BadPotion: Ruined Potion -Brew_BarrelRiped: Barrel aged -Brew_DistillUndefined: Indefinable Distillate -Brew_Distilled: Distilled -Brew_HundredsOfYears: Hundreds of Years -Brew_Ingredients: Ingredients -Brew_MinutePluralPostfix: s -Brew_OneYear: One Year -Brew_ThickBrew: Muddy Brewxxxxx -Brew_Undefined: Indefinable Brew -Brew_Woodtype: Woodtype -Brew_Years: Years -Brew_fermented: fermented -Brew_minute: minute -CMD_Copy_Error: '&6&v1 &cPotions did not fit into your inventory' -CMD_Info_Drunk: '&v1 is &6&v2% &fdrunk, with a quality of &6&v3' -CMD_Info_NotDrunk: '&v1 is not drunk' -CMD_Player: '&a&v1 is now &6&v2% &adrunk, with a quality of &6&v3' -CMD_Player_Error: '&cThe Quality has to be between 1 and 10!' -CMD_Reload: '&aConfig was successfully reloaded' -CMD_UnLabel: '&aLabel removed!' -Error_ConfigUpdate: 'Unknown Brewery Config version: v&v1, Config was not Updated!' -Error_ItemNotPotion: '&cThe Item in your hand could not be identified as Potion' -Error_NoPermissions: '&cYou have no permission to do this!' -Error_PlayerCommand: '&cThis command can only be executed as player' -Error_Recipeload: '&cNot all recipes could be restored: More information in the Serverlog!' -Error_ShowHelp: use &6/brew help &fto display the help -Error_UnknownCommand: Unknown Command -Etc_Barrel: Barrel -Etc_Page: Page -Etc_Usage: 'Usage:' -Help_Copy: '&6/brew Copy &9 Copies the Potion in your Hand' -Help_Delete: '&6/brew Delete &9Deletes the Potion in your Hand' -Help_Help: '&6/brew help &9Shows a specific help-page' -Help_Info: '&6/brew Info&9 Displays your current Drunkeness and Quality' -Help_InfoOther: '&6/brew Info &9 Displays the current Drunkeness and Quality - of ' -Help_Player: '&6/brew <%Drunkeness> &9 Sets Drunkeness (and Quality) - of a Player' -Help_Reload: '&6/brew reload &9Reload config' -Help_UnLabel: '&6/brew UnLabel &9Removes the detailled label of a Potion' -Help_Wakeup: '&6/brew Wakeup List &9 Lists all Wakeup Points' -Help_WakeupAdd: '&6/brew Wakeup Add &9Adds a Wakeup Point at your current Position' -Help_WakeupCheck: '&6/brew Wakeup Check &9Teleports to all Wakeup Points' -Help_WakeupCheckSpecific: '&6/brew Wakeup Check &9Teleports to the Wakeup Point - with ' -Help_WakeupList: '&6/brew Wakeup List &9 Lists all Wakeup Points of a - World' -Help_WakeupRemove: '&6/brew Wakeup Remove &9Removes the Wakeup Point with ' -Player_BarrelCreated: Barrel created -Player_CantDrink: You can't drink any more -Player_CauldronInfo1: This Cauldron seethes since &v1 minutes -Player_CauldronInfo2: This Cauldron seethes since less than one minute -Player_DrunkPassOut: You have drunken too much and fainted! -Player_LoginDeny: Your character is drunk and does not react. Try again! -Player_LoginDenyLong: Your character is really drunk and unconscious. Try again in 10 minutes! -Player_TriedToSay: '&v1 tried to say: &0&v2' -Player_Wake: Ohh no! I cannot remember how I got here... -Player_WakeAlreadyDeleted: '&cThe Wakeup Point with the id: &6&v1 &chas already been - deleted!' -Player_WakeCancel: '&6Wakeup Point Check was cancelled' -Player_WakeCreated: '&aWakeup Point with id: &6&v1 &awas created successfully!' -Player_WakeDeleted: '&aThe Wakeup Point with the id: &6&v1 &awas successfully deleted!' -Player_WakeFilled: '&cThe Wakeup Point with the id: &6&v1&c at position &6&v2 &v3, - &v4, &v5&c is filled with Blocks!' -Player_WakeHint1: 'To Next Wakeup Point: Punch your fist in the air' -Player_WakeHint2: 'To Cancel: &9/brew wakeup cancel' -Player_WakeLast: '&aThis was the last Wakeup Point' -Player_WakeNoCheck: '&cNo Wakeup Point Check is currently active' -Player_WakeNoPoints: '&cThere are no Wakeup Points!' -Player_WakeNotExist: '&cThe Wakeup Point with the id: &6&v1 &cdoesn''t exist!' -Player_WakeTeleport: 'Teleport to Wakeup Point with the id: &6&v1&f At position: &6&v2 - &v3, &v4, &v5' diff --git a/src/com/dre/brewery/P.java b/src/com/dre/brewery/P.java index 59a959d..94d7cbc 100644 --- a/src/com/dre/brewery/P.java +++ b/src/com/dre/brewery/P.java @@ -615,7 +615,7 @@ public class P extends JavaPlugin { File languages = new File(getDataFolder(), "languages"); if (!languages.exists()) { - String lang[] = new String[] {"de", "en", "fr", "no"}; + String lang[] = new String[] {"de", "en", "fr"}; for (String l : lang) { try { saveFile(getResource("languages/" + l + ".yml"), languages, l + ".yml", false); diff --git a/src/com/dre/brewery/filedata/LanguageReader.java b/src/com/dre/brewery/filedata/LanguageReader.java index 69cfc12..92a52e9 100644 --- a/src/com/dre/brewery/filedata/LanguageReader.java +++ b/src/com/dre/brewery/filedata/LanguageReader.java @@ -110,15 +110,15 @@ public class LanguageReader { defaults.put("Perms_NoCauldronFill", "&cYou don't have permissions to fill bottles from this cauldron!"); /* Help */ - defaults.put("Help_Help", "&6/brew help &9Shows a specific help-page"); - defaults.put("Help_Player", "&6/brew <%Drunkeness> &9 Sets Drunkeness (and Quality) of a Player"); + defaults.put("Help_Help", "&6/brew help [Page] &9Shows a specific help-page"); + defaults.put("Help_Player", "&6/brew <%Drunkeness> [Quality]&9 Sets Drunkeness (and Quality) of a Player"); defaults.put("Help_Info", "&6/brew info&9 Displays your current Drunkeness and Quality"); defaults.put("Help_UnLabel", "&6/brew unlabel &9Removes the detailled label of a potion"); - defaults.put("Help_Copy", "&6/brew copy &9 Copies the potion in your hand"); + defaults.put("Help_Copy", "&6/brew copy [Quantity]>&9 Copies the potion in your hand"); defaults.put("Help_Delete", "&6/brew delete &9Deletes the potion in your hand"); - defaults.put("Help_InfoOther", "&6/brew info &9 Displays the current Drunkeness and Quality of "); + defaults.put("Help_InfoOther", "&6/brew info [Player]&9 Displays the current Drunkeness and Quality of [Player]"); defaults.put("Help_Wakeup", "&6/brew wakeup list &9 Lists all wakeup points"); - defaults.put("Help_WakeupList", "&6/brew wakeup list &9 Lists all wakeup points of "); + defaults.put("Help_WakeupList", "&6/brew wakeup list [World]&9 Lists all wakeup points of [world]"); defaults.put("Help_WakeupCheck", "&6/brew wakeup check &9Teleports to all wakeup points"); defaults.put("Help_WakeupCheckSpecific", "&6/brew wakeup check &9Teleports to the wakeup point with "); defaults.put("Help_WakeupAdd", "&6/brew wakeup add &9Adds a wakeup point at your current position"); @@ -126,7 +126,7 @@ public class LanguageReader { defaults.put("Help_Reload", "&6/brew reload &9Reload config"); defaults.put("Help_Persist", "&6/brew persist &9Make Brew persistent -> copyable by any plugin and technique"); defaults.put("Help_Static", "&6/brew static &9Make Brew static -> No further ageing or distilling"); - defaults.put("Help_Create", "&6/brew create &9Create a Brew with optional quality (1-10)"); + defaults.put("Help_Create", "&6/brew create [Quality] [Player] &9Create a Brew with optional quality (1-10)"); /* Etc. */ defaults.put("Etc_Usage", "Usage:"); diff --git a/src/com/dre/brewery/listeners/CommandListener.java b/src/com/dre/brewery/listeners/CommandListener.java index ea81373..271fd8f 100644 --- a/src/com/dre/brewery/listeners/CommandListener.java +++ b/src/com/dre/brewery/listeners/CommandListener.java @@ -499,29 +499,45 @@ public class CommandListener implements CommandExecutor { public void cmdCreate(CommandSender sender, String[] args) { - if (sender instanceof Player) { - if (args.length < 2) { - p.msg(sender, p.languageReader.get("Etc_Usage")); - p.msg(sender, p.languageReader.get("Help_Create")); - return; - } + if (args.length < 2) { + p.msg(sender, p.languageReader.get("Etc_Usage")); + p.msg(sender, p.languageReader.get("Help_Create")); + return; + } - int quality = 10; - boolean hasQuality = false; - if (args.length > 2) { - quality = p.parseInt(args[args.length - 1]); - if (quality > 0 && quality <= 10) { - hasQuality = true; - } else { - quality = 10; + int quality = 10; + boolean hasQuality = false; + String pName = null; + if (args.length > 2) { + quality = p.parseInt(args[args.length - 1]); + + if (quality <= 0 || quality > 10) { + pName = args[args.length - 1]; + if (args.length > 3) { + quality = p.parseInt(args[args.length - 2]); } } - - int stringLength; - if (hasQuality) { - stringLength = args.length - 2; + if (quality > 0 && quality <= 10) { + hasQuality = true; } else { - stringLength = args.length - 1; + quality = 10; + } + } + Player player = null; + if (pName != null) { + player = p.getServer().getPlayer(pName); + } + + if (sender instanceof Player || player != null) { + if (player == null) { + player = ((Player) sender); + } + int stringLength = args.length - 1; + if (pName != null) { + stringLength--; + } + if (hasQuality) { + stringLength--; } String name; @@ -536,9 +552,6 @@ public class CommandListener implements CommandExecutor { name = args[1]; } - - Player player = (Player) sender; - if (player.getInventory().firstEmpty() == -1) { p.msg(sender, p.languageReader.get("CMD_Copy_Error", "1")); return;