From f05d49f5e7a2a86397e7f61fed02fed782f37dbb Mon Sep 17 00:00:00 2001 From: Khyperia Date: Tue, 6 Dec 2011 06:25:54 +0800 Subject: New command: /find Test #278 Test #293 Test #348 --- .../earth2me/essentials/commands/Commandfind.java | 25 ++++++++++++++++++++++ .../essentials/commands/Commandlightning.java | 23 +++++++++++++++++++- .../earth2me/essentials/commands/Commandnick.java | 23 +++++++++++++++++++- Essentials/src/plugin.yml | 6 +++++- 4 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 Essentials/src/com/earth2me/essentials/commands/Commandfind.java diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandfind.java b/Essentials/src/com/earth2me/essentials/commands/Commandfind.java new file mode 100644 index 000000000..40590501f --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/commands/Commandfind.java @@ -0,0 +1,25 @@ +package com.earth2me.essentials.commands; + +import org.bukkit.Server; +import org.bukkit.command.CommandSender; +import org.bukkit.inventory.ItemStack; + + +public class Commandfind extends EssentialsCommand +{ + public Commandfind() + { + super("find"); + } + + @Override + protected void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception + { + if (args.length < 1) + { + throw new NotEnoughArgumentsException(); + } + ItemStack itemStack = ess.getItemDb().get(args[0]); + sender.sendMessage(itemStack.getType().toString() + "- " + itemStack.getTypeId() + ":" + Integer.toString(itemStack.getData().getData())); + } +} diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandlightning.java b/Essentials/src/com/earth2me/essentials/commands/Commandlightning.java index 582f048a1..be9ac61f5 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandlightning.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandlightning.java @@ -4,6 +4,7 @@ import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import org.bukkit.Server; import org.bukkit.command.CommandSender; +import org.bukkit.entity.LightningStrike; import org.bukkit.entity.Player; @@ -34,10 +35,30 @@ public class Commandlightning extends EssentialsCommand throw new Exception(_("playerNotFound")); } + int power = 1; + if (args.length > 1) + { + try + { + power = Integer.parseInt(args[1]); + } + catch (NumberFormatException ex) + { + } + } + for (Player matchPlayer : server.matchPlayer(args[0])) { sender.sendMessage(_("lightningUse", matchPlayer.getDisplayName())); - matchPlayer.getWorld().strikeLightning(matchPlayer.getLocation()); + if (power <= 0) + { + matchPlayer.getWorld().strikeLightningEffect(matchPlayer.getLocation()); + } + else + { + LightningStrike strike = matchPlayer.getWorld().strikeLightning(matchPlayer.getLocation()); + matchPlayer.damage(power - 1, strike); + } if (!ess.getUser(matchPlayer).isGodModeEnabled()) { matchPlayer.setHealth(matchPlayer.getHealth() < 5 ? 0 : matchPlayer.getHealth() - 5); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandnick.java b/Essentials/src/com/earth2me/essentials/commands/Commandnick.java index a1f1c77ca..95ad5ea84 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandnick.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandnick.java @@ -50,7 +50,14 @@ public class Commandnick extends EssentialsCommand { throw new Exception(_("nickDisplayName")); } - setNickname(server, getPlayer(server, args, 0), formatNickname(null, args[1])); + if ((args[0].equalsIgnoreCase("*") || args[0].equalsIgnoreCase("all")) && args[1].equalsIgnoreCase("off")) + { + resetAllNicknames(server); + } + else + { + setNickname(server, getPlayer(server, args, 0), formatNickname(null, args[1])); + } sender.sendMessage(_("nickChanged")); } @@ -63,6 +70,20 @@ public class Commandnick extends EssentialsCommand return nick; } + private void resetAllNicknames(final Server server) + { + for (Player player : server.getOnlinePlayers()) + { + try + { + setNickname(server, ess.getUser(player), "off"); + } + catch (Exception ex) + { + } + } + } + private void setNickname(final Server server, final User target, final String nick) throws Exception { if (nick.matches("[^a-zA-Z_0-9]")) diff --git a/Essentials/src/plugin.yml b/Essentials/src/plugin.yml index e6bf865b7..681ff428f 100644 --- a/Essentials/src/plugin.yml +++ b/Essentials/src/plugin.yml @@ -102,6 +102,10 @@ commands: description: Satisfy the hunger. usage: / [player] aliases: [efeed] + find: + description: Searches for an item. + usage: / + aliases: [efind] fireball: description: Throw a fireball. usage: / [small] @@ -188,7 +192,7 @@ commands: aliases: [playerlist,who,online,elist,ewho,eplayerlist,eonline] lightning: description: The power of Thor. Strike at cursor or player. - usage: / [player] + usage: / [player] [power] aliases: [strike,smite,thor,shock,elightning,estrike,esmite,ethor,eshock] mail: description: Manages inter-player, intra-server mail. -- cgit v1.2.3 From 345aeca35bd56ac18aa0d436f87bcfbef05ebfe1 Mon Sep 17 00:00:00 2001 From: Khyperia Date: Wed, 7 Dec 2011 05:58:44 +0800 Subject: Renamed /find to /itemdb --- .../earth2me/essentials/commands/Commandfind.java | 25 --------------- .../essentials/commands/Commanditemdb.java | 37 ++++++++++++++++++++++ Essentials/src/plugin.yml | 4 +-- 3 files changed, 39 insertions(+), 27 deletions(-) delete mode 100644 Essentials/src/com/earth2me/essentials/commands/Commandfind.java create mode 100644 Essentials/src/com/earth2me/essentials/commands/Commanditemdb.java diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandfind.java b/Essentials/src/com/earth2me/essentials/commands/Commandfind.java deleted file mode 100644 index 40590501f..000000000 --- a/Essentials/src/com/earth2me/essentials/commands/Commandfind.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.earth2me.essentials.commands; - -import org.bukkit.Server; -import org.bukkit.command.CommandSender; -import org.bukkit.inventory.ItemStack; - - -public class Commandfind extends EssentialsCommand -{ - public Commandfind() - { - super("find"); - } - - @Override - protected void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception - { - if (args.length < 1) - { - throw new NotEnoughArgumentsException(); - } - ItemStack itemStack = ess.getItemDb().get(args[0]); - sender.sendMessage(itemStack.getType().toString() + "- " + itemStack.getTypeId() + ":" + Integer.toString(itemStack.getData().getData())); - } -} diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanditemdb.java b/Essentials/src/com/earth2me/essentials/commands/Commanditemdb.java new file mode 100644 index 000000000..2fff20e8c --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/commands/Commanditemdb.java @@ -0,0 +1,37 @@ +package com.earth2me.essentials.commands; + +import org.bukkit.Server; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + + +public class Commanditemdb extends EssentialsCommand +{ + public Commanditemdb() + { + super("find"); + } + + @Override + protected void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception + { + ItemStack itemStack = null; + if (args.length < 1) + { + if (sender instanceof Player) + { + itemStack = ((Player)sender).getItemInHand(); + } + if (itemStack == null) + { + throw new NotEnoughArgumentsException(); + } + } + else + { + itemStack = ess.getItemDb().get(args[0]); + } + sender.sendMessage(itemStack.getType().toString() + "- " + itemStack.getTypeId() + ":" + Integer.toString(itemStack.getData().getData())); + } +} diff --git a/Essentials/src/plugin.yml b/Essentials/src/plugin.yml index 681ff428f..ac1ced96e 100644 --- a/Essentials/src/plugin.yml +++ b/Essentials/src/plugin.yml @@ -102,10 +102,10 @@ commands: description: Satisfy the hunger. usage: / [player] aliases: [efeed] - find: + itemdb: description: Searches for an item. usage: / - aliases: [efind] + aliases: [eitemdb] fireball: description: Throw a fireball. usage: / [small] -- cgit v1.2.3 From a21203f5cb57d4d2c466afc72492964bd3ffa50e Mon Sep 17 00:00:00 2001 From: Khyperia Date: Wed, 7 Dec 2011 08:46:35 +0800 Subject: New feature: /mail sendall Test: #649 --- .../earth2me/essentials/commands/Commandmail.java | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java index d02e5a13a..8a2787d82 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java @@ -63,6 +63,14 @@ public class Commandmail extends EssentialsCommand user.sendMessage(_("mailSent")); return; } + if (args.length >= 1 && "sendall".equalsIgnoreCase(args[0])) + { + if (!user.isAuthorized("essentials.mail.sendall")) + { + throw new Exception(_("noMailSendPerm")); + } + ess.scheduleAsyncDelayedTask(new SendAll(ChatColor.stripColor(user.getDisplayName()) + ": " + getFinalArg(args, 2))); + } if (args.length >= 1 && "clear".equalsIgnoreCase(args[0])) { user.setMails(null); @@ -103,6 +111,10 @@ public class Commandmail extends EssentialsCommand sender.sendMessage(_("mailSent")); return; } + else if (args.length >= 1 && "sendall".equalsIgnoreCase(args[0])) + { + ess.scheduleAsyncDelayedTask(new SendAll("Server: " + getFinalArg(args, 2))); + } else if (args.length >= 2) { //allow sending from console without "send" argument, since it's the only thing the console can do @@ -126,4 +138,28 @@ public class Commandmail extends EssentialsCommand } throw new NotEnoughArgumentsException(); } + + + private class SendAll implements Runnable + { + String message; + + public SendAll(String message) + { + this.message = message; + } + + @Override + public void run() + { + for (String username : ess.getUserMap().getAllUniqueUsers()) + { + User user = ess.getUserMap().getUser(username); + if (user != null) + { + user.addMail(message); + } + } + } + } } -- cgit v1.2.3