From 6736672639f2bb734b8e0f4b975552a72acc3386 Mon Sep 17 00:00:00 2001 From: Tim P Date: Tue, 18 Oct 2011 12:12:41 -0400 Subject: Made a couple commands available for the console (ones that make sense to be able to access from the command line). --- .../earth2me/essentials/commands/Commandmail.java | 33 ++++++++++++++++ .../essentials/commands/Commandrealname.java | 10 ++--- .../essentials/commands/Commandweather.java | 41 ++++++++++++++++++-- .../earth2me/essentials/commands/Commandworth.java | 45 ++++++++++++++++++++++ Essentials/src/messages.properties | 8 ++-- 5 files changed, 124 insertions(+), 13 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java index acffd57a1..a241c787a 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java @@ -5,6 +5,7 @@ import org.bukkit.Server; import com.earth2me.essentials.User; import com.earth2me.essentials.Util; import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -69,4 +70,36 @@ public class Commandmail extends EssentialsCommand } throw new NotEnoughArgumentsException(); } + + @Override protected void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception { + if (args.length >= 1 && "read".equalsIgnoreCase(args[0])) + { + throw new Exception(Util.format("onlyPlayers", commandLabel+" read")); + } + if (args.length >= 3 && "send".equalsIgnoreCase(args[0])) + { + Player player = server.getPlayer(args[1]); + User u; + if (player != null) + { + u = ess.getUser(player); + } + else + { + u = ess.getOfflineUser(args[1]); + } + if (u == null) + { + throw new Exception(Util.format("playerNeverOnServer", args[1])); + } + u.addMail("Server: " + getFinalArg(args, 2)); + sender.sendMessage(Util.i18n("mailSent")); + return; + } + if (args.length >= 1 && "clear".equalsIgnoreCase(args[0])) + { + throw new Exception(Util.format("onlyPlayers", commandLabel+" clear")); + } + throw new NotEnoughArgumentsException(); + } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java b/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java index 5e12c535d..7265dd546 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.commands; import org.bukkit.Server; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import com.earth2me.essentials.User; import com.earth2me.essentials.Util; @@ -13,10 +14,9 @@ public class Commandrealname extends EssentialsCommand { super("realname"); } - - @Override - public void run(Server server, User user, String commandLabel, String[] args) throws Exception - { + + @Override + protected void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception { if (args.length < 1) { throw new NotEnoughArgumentsException(); @@ -36,7 +36,7 @@ public class Commandrealname extends EssentialsCommand { continue; } - user.sendMessage(u.getDisplayName() + " " + Util.i18n("is") + " " + u.getName()); + sender.sendMessage(u.getDisplayName() + " " + Util.i18n("is") + " " + u.getName()); } } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandweather.java b/Essentials/src/com/earth2me/essentials/commands/Commandweather.java index 45c62d787..d5d899b09 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandweather.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandweather.java @@ -4,6 +4,7 @@ import com.earth2me.essentials.User; import com.earth2me.essentials.Util; import org.bukkit.Server; import org.bukkit.World; +import org.bukkit.command.CommandSender; public class Commandweather extends EssentialsCommand @@ -29,16 +30,48 @@ public class Commandweather extends EssentialsCommand world.setStorm(isStorm ? true : false); world.setWeatherDuration(Integer.parseInt(args[1]) * 20); user.sendMessage(isStorm - ? Util.format("weatherStormFor", args[1]) - : Util.format("weatherSunFor", args[1])); + ? Util.format("weatherStormFor", world.getName(), args[1]) + : Util.format("weatherSunFor", world.getName(), args[1])); return; } else { world.setStorm(isStorm ? true : false); user.sendMessage(isStorm - ? Util.i18n("weatherStorm") - : Util.i18n("weatherSun")); + ? Util.format("weatherStorm", world.getName()) + : Util.format("weatherSun", world.getName())); + return; + } + } + + @Override protected void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception { + if (args.length < 2) //running from console means inserting a world arg before other args + { + throw new NotEnoughArgumentsException(); + } + + boolean isStorm = args[1].equalsIgnoreCase("storm"); + World world = server.getWorld(args[0]); + if (world == null) + { + throw new Exception("World named "+args[0]+" not found!"); + } + if (args.length > 2) + { + + world.setStorm(isStorm ? true : false); + world.setWeatherDuration(Integer.parseInt(args[1]) * 20); + sender.sendMessage(isStorm + ? Util.format("weatherStormFor", world.getName(), args[1]) + : Util.format("weatherSunFor", world.getName(), args[1])); + return; + } + else + { + world.setStorm(isStorm ? true : false); + sender.sendMessage(isStorm + ? Util.format("weatherStorm", world.getName()) + : Util.format("weatherSun", world.getName())); return; } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandworth.java b/Essentials/src/com/earth2me/essentials/commands/Commandworth.java index b59070320..6ca894f4b 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandworth.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandworth.java @@ -3,6 +3,8 @@ package com.earth2me.essentials.commands; import org.bukkit.Server; import com.earth2me.essentials.User; import com.earth2me.essentials.Util; + +import org.bukkit.command.CommandSender; import org.bukkit.inventory.ItemStack; @@ -56,4 +58,47 @@ public class Commandworth extends EssentialsCommand amount, Util.formatCurrency(worth, ess))); } + + @Override protected void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception { + if (args.length < 1) + { + throw new NotEnoughArgumentsException(); + } + + ItemStack is = ess.getItemDb().get(args[0]);// = user.getInventory().getItemInHand(); + int amount = is.getAmount(); + + try + { + if (args.length > 1) + { + amount = Integer.parseInt(args[1]); + } + } + catch (NumberFormatException ex) + { + amount = 64; + } + + is.setAmount(amount); + double worth = ess.getWorth().getPrice(is); + if (Double.isNaN(worth)) + { + throw new Exception(Util.i18n("itemCannotBeSold")); + } + + sender.sendMessage(is.getDurability() != 0 + ? Util.format("worthMeta", + is.getType().toString().toLowerCase().replace("_", ""), + is.getDurability(), + Util.formatCurrency(worth * amount, ess), + amount, + Util.formatCurrency(worth, ess)) + : Util.format("worth", + is.getType().toString().toLowerCase().replace("_", ""), + Util.formatCurrency(worth * amount, ess), + amount, + Util.formatCurrency(worth, ess))); + + } } diff --git a/Essentials/src/messages.properties b/Essentials/src/messages.properties index c756d4384..0eb9f9d37 100644 --- a/Essentials/src/messages.properties +++ b/Essentials/src/messages.properties @@ -351,10 +351,10 @@ warpSet = \u00a77Warp {0} set. warpUsePermission = \u00a7cYou do not have Permission to use that warp. warpingTo = \u00a77Warping to {0}. warpsCount = \u00a77There are {0} warps. Showing page {1} of {2}. -weatherStorm = \u00a77You set the weather to storm in your world -weatherStormFor = \u00a77You set the weather to storm in your world for {0} seconds -weatherSun = \u00a77You set the weather to sun in your world -weatherSunFor = \u00a77You set the weather to sun in your world for {0} seconds +weatherStorm = \u00a77You set the weather to storm in {0} +weatherStormFor = \u00a77You set the weather to storm in {0} for {1} seconds +weatherSun = \u00a77You set the weather to sun in {0} +weatherSunFor = \u00a77You set the weather to sun in {0} for {1} seconds whoisGeoLocation = \u00a79 - Location: {0} whoisHealth = \u00a79 - Health: {0}/20 whoisIPAddress = \u00a79 - IP Address: {0} -- cgit v1.2.3 From e96d33cb8b5a71a66b07c64700307b0a1b04edaf Mon Sep 17 00:00:00 2001 From: Tim P Date: Tue, 18 Oct 2011 22:01:23 -0400 Subject: Made a concerted effort to change the messages.properties in the various languages to the new format for weather. - Incidently, there was an error in the _da translation - the message for the key weatherSun did not have a "in your world" clause. This is added with the "your world" clause changed, like it is everywhere. --- Essentials/src/messages_da.properties | 8 ++++---- Essentials/src/messages_de.properties | 8 ++++---- Essentials/src/messages_en.properties | 8 ++++---- Essentials/src/messages_fr.properties | 8 ++++---- Essentials/src/messages_nl.properties | 8 ++++---- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Essentials/src/messages_da.properties b/Essentials/src/messages_da.properties index 1f21b1a50..7526e4858 100644 --- a/Essentials/src/messages_da.properties +++ b/Essentials/src/messages_da.properties @@ -350,10 +350,10 @@ warpSet = \u00a77Warp {0} sat. warpUsePermission = \u00a7cDu har ikke tilladelse til at benytte den warp. warpingTo = \u00a77Warper til {0}. warpsCount = \u00a77There are {0} warps. Showing page {1} of {2}. -weatherStorm = \u00a77Du har sat vejret til storm i din verden -weatherStormFor = \u00a77Du har sat vejret til storm i din verden i {0} sekunder -weatherSun = \u00a77Du har sat vejret til sol -weatherSunFor = \u00a77Du har sat vejret til sol i din verden i {0} sekunder +weatherStorm = \u00a77Du har sat vejret til storm i {0} +weatherStormFor = \u00a77Du har sat vejret til storm i {0} i {1} sekunder +weatherSun = \u00a77Du har sat vejret til sol i {0} +weatherSunFor = \u00a77Du har sat vejret til sol i {0} i {1} sekunder whoisGeoLocation = \u00a79 - Placering: {0} whoisHealth = \u00a79 - Helbred: {0}/20 whoisIPAddress = \u00a79 - IP Addresse: {0} diff --git a/Essentials/src/messages_de.properties b/Essentials/src/messages_de.properties index f22094333..5ccedd370 100644 --- a/Essentials/src/messages_de.properties +++ b/Essentials/src/messages_de.properties @@ -350,10 +350,10 @@ warpSet = \u00a77Warp-Punkt {0} wurde erstellt. warpUsePermission = \u00a7cDu hast keinen Zugriff f\u00fcr diesen Warp-Punkt. warpingTo = \u00a77Teleportiere zu Warp-Punkt {0}. warpsCount = \u00a77Es gibt {0} Warp-Punkte. Zeige Seite {1} von {2}. -weatherStorm = \u00a77In deiner Welt st\u00fcrmt es nun. -weatherStormFor = \u00a77In deiner Welt st\u00fcrmt es nun f\u00fcr {0} Sekunden. -weatherSun = \u00a77In deiner Welt scheint nun die Sonne. -weatherSunFor = \u00a77In deiner Welt scheint nun f\u00fcr {0} Sekunden die Sonne. +weatherStorm = \u00a77In {0} st\u00fcrmt es nun. +weatherStormFor = \u00a77In {0} st\u00fcrmt es nun f\u00fcr {1} Sekunden. +weatherSun = \u00a77In {0} scheint nun die Sonne. +weatherSunFor = \u00a77In {0} scheint nun f\u00fcr {1} Sekunden die Sonne. whoisGeoLocation = \u00a79 - Herkunft: {0} whoisHealth = \u00a79 - Gesundheit: {0}/20 whoisIPAddress = \u00a79 - IP-Adresse: {0} diff --git a/Essentials/src/messages_en.properties b/Essentials/src/messages_en.properties index ea73ccc56..39fe33d83 100644 --- a/Essentials/src/messages_en.properties +++ b/Essentials/src/messages_en.properties @@ -350,10 +350,10 @@ warpSet = \u00a77Warp {0} set. warpUsePermission = \u00a7cYou do not have Permission to use that warp. warpingTo = \u00a77Warping to {0}. warpsCount = \u00a77There are {0} warps. Showing page {1} of {2}. -weatherStorm = \u00a77You set the weather to storm in your world -weatherStormFor = \u00a77You set the weather to storm in your world for {0} seconds -weatherSun = \u00a77You set the weather to sun in your world -weatherSunFor = \u00a77You set the weather to sun in your world for {0} seconds +weatherStorm = \u00a77You set the weather to storm in {0} +weatherStormFor = \u00a77You set the weather to storm in {0} for {1} seconds +weatherSun = \u00a77You set the weather to sun in {0} +weatherSunFor = \u00a77You set the weather to sun in {0} for {1} seconds whoisGeoLocation = \u00a79 - Location: {0} whoisHealth = \u00a79 - Health: {0}/20 whoisIPAddress = \u00a79 - IP Address: {0} diff --git a/Essentials/src/messages_fr.properties b/Essentials/src/messages_fr.properties index 987a41eb0..11fa2e6a4 100644 --- a/Essentials/src/messages_fr.properties +++ b/Essentials/src/messages_fr.properties @@ -350,10 +350,10 @@ warpSet = \u00a77Le warp {0} a \u00e9t\u00e9 cr\u00e9\u00e9. warpUsePermission = \u00a7cVous n''avez pas la permission d''utiliser ce warp. warpingTo = \u00a77T\u00e9l\u00e9portation au warp {0}. warpsCount = \u00a77There are {0} warps. Showing page {1} of {2}. -weatherStorm = \u00a77Vous avez d\u00e9fini l''orage dans votre monde -weatherStormFor = \u00a77Vous avez d\u00e9fini l''orage dans votre monde pour {0} secondes. -weatherSun = \u00a77Vous avez mis le beau temps dans votre monde -weatherSunFor = \u00a77Vous avez mis le beau temps dans votre monde pour {0} secondes. +weatherStorm = \u00a77Vous avez d\u00e9fini l''orage dans {0} +weatherStormFor = \u00a77Vous avez d\u00e9fini l''orage dans {0} pour {1} secondes. +weatherSun = \u00a77Vous avez mis le beau temps dans {0} +weatherSunFor = \u00a77Vous avez mis le beau temps dans {0} pour {1} secondes. whoisGeoLocation = \u00a79 - Emplacement: {0} whoisHealth = \u00a79 - Vie: {0} / 20 whoisIPAddress = \u00a79 - Adresse IP: {0} diff --git a/Essentials/src/messages_nl.properties b/Essentials/src/messages_nl.properties index e11791444..c3ce54543 100644 --- a/Essentials/src/messages_nl.properties +++ b/Essentials/src/messages_nl.properties @@ -350,10 +350,10 @@ warpSet = \u00a77Warp {0} ingesteld. warpUsePermission = \u00a7cOnbevoegd om die warp te gebruiken. warpingTo = \u00a77Aan het warpen naar {0}. warpsCount = \u00a77There are {0} warps. Showing page {1} of {2}. -weatherStorm = \u00a77Je hebt het weer naar storm gezet in de wereld -weatherStormFor = \u00a77Je hebt het weer in de wereld naar storm gezet voor {0} seconde -weatherSun = \u00a77Je hebt het weer naar zon gezet in de wereld -weatherSunFor = \u00a77Je hebt het weer in de wereld naar zon gezet voor {0} seconde +weatherStorm = \u00a77Je hebt het weer naar storm gezet in de {0} +weatherStormFor = \u00a77Je hebt het weer in de {0} naar storm gezet voor {1} seconde +weatherSun = \u00a77Je hebt het weer naar zon gezet in de {0} +weatherSunFor = \u00a77Je hebt het weer in de {0} naar zon gezet voor {1} seconde whoisGeoLocation = \u00a79 - Locatie: {0} whoisHealth = \u00a79 - Levens: {0}/20 whoisIPAddress = \u00a79 - IP Adres: {0} -- cgit v1.2.3 From 35121d9c4b329cbfbe47872e6c92ba1f6990d193 Mon Sep 17 00:00:00 2001 From: Tim P Date: Tue, 18 Oct 2011 23:08:06 -0400 Subject: Minor fixes. Basic testing shows all works. --- .../earth2me/essentials/commands/Commandmail.java | 30 ++++++++++++++++++---- .../essentials/commands/Commandweather.java | 2 +- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java index a241c787a..d7d33d469 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java @@ -76,7 +76,11 @@ public class Commandmail extends EssentialsCommand { throw new Exception(Util.format("onlyPlayers", commandLabel+" read")); } - if (args.length >= 3 && "send".equalsIgnoreCase(args[0])) + else if (args.length >= 1 && "clear".equalsIgnoreCase(args[0])) + { + throw new Exception(Util.format("onlyPlayers", commandLabel+" clear")); + } + else if (args.length >= 3 && "send".equalsIgnoreCase(args[0])) { Player player = server.getPlayer(args[1]); User u; @@ -95,10 +99,26 @@ public class Commandmail extends EssentialsCommand u.addMail("Server: " + getFinalArg(args, 2)); sender.sendMessage(Util.i18n("mailSent")); return; - } - if (args.length >= 1 && "clear".equalsIgnoreCase(args[0])) - { - throw new Exception(Util.format("onlyPlayers", commandLabel+" clear")); + } + else if (args.length >= 2) + { //allow sending from console without "send" argument, since it's the only thing the console can do + Player player = server.getPlayer(args[0]); + User u; + if (player != null) + { + u = ess.getUser(player); + } + else + { + u = ess.getOfflineUser(args[0]); + } + if (u == null) + { + throw new Exception(Util.format("playerNeverOnServer", args[0])); + } + u.addMail("Server: " + getFinalArg(args, 1)); + sender.sendMessage(Util.i18n("mailSent")); + return; } throw new NotEnoughArgumentsException(); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandweather.java b/Essentials/src/com/earth2me/essentials/commands/Commandweather.java index d5d899b09..0201d594b 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandweather.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandweather.java @@ -47,7 +47,7 @@ public class Commandweather extends EssentialsCommand @Override protected void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception { if (args.length < 2) //running from console means inserting a world arg before other args { - throw new NotEnoughArgumentsException(); + throw new Exception("When running from console, usage is: /"+commandLabel+" [duration]"); } boolean isStorm = args[1].equalsIgnoreCase("storm"); -- cgit v1.2.3