summaryrefslogtreecommitdiffstats
path: root/EssentialsChat/src/com/earth2me/essentials
diff options
context:
space:
mode:
authorKHobbits <rob@khobbits.co.uk>2011-08-17 15:28:58 +0100
committerKHobbits <rob@khobbits.co.uk>2011-08-17 15:28:58 +0100
commit5d95d1fca60606c83b3e61790afbb273f5e92079 (patch)
treea3120ff1b65a001283509fcc7cf0f11bcb8288ea /EssentialsChat/src/com/earth2me/essentials
parent2541efb682a8f889ed2a4e04535ddf35ca912927 (diff)
downloadEssentials-5d95d1fca60606c83b3e61790afbb273f5e92079.tar
Essentials-5d95d1fca60606c83b3e61790afbb273f5e92079.tar.gz
Essentials-5d95d1fca60606c83b3e61790afbb273f5e92079.tar.lz
Essentials-5d95d1fca60606c83b3e61790afbb273f5e92079.tar.xz
Essentials-5d95d1fca60606c83b3e61790afbb273f5e92079.zip
Adding command cost for !shout and ?question.
Diffstat (limited to 'EssentialsChat/src/com/earth2me/essentials')
-rw-r--r--EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListener.java52
1 files changed, 36 insertions, 16 deletions
diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListener.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListener.java
index 6b3039d0b..85e821e7f 100644
--- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListener.java
+++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListener.java
@@ -1,6 +1,8 @@
package com.earth2me.essentials.chat;
+import com.earth2me.essentials.ChargeException;
import com.earth2me.essentials.IEssentials;
+import com.earth2me.essentials.Trade;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
import java.util.Map;
@@ -8,6 +10,7 @@ import java.util.logging.Logger;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.World;
+import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerListener;
@@ -59,29 +62,38 @@ public class EssentialsChatPlayerListener extends PlayerListener
}
radius *= radius;
- if (event.getMessage().startsWith("!") && event.getMessage().length() > 1)
- {
- if (user.isAuthorized("essentials.chat.shout"))
+ try {
+ if (event.getMessage().startsWith("!") && event.getMessage().length() > 1)
{
- event.setMessage(event.getMessage().substring(1));
- event.setFormat(Util.format("shoutFormat", event.getFormat()));
+ if (user.isAuthorized("essentials.chat.shout"))
+ {
+ charge(user,"chat-shout");
+ event.setMessage(event.getMessage().substring(1));
+ event.setFormat(Util.format("shoutFormat", event.getFormat()));
+ return;
+ }
+ user.sendMessage(Util.i18n("notAllowedToShout"));
+ event.setCancelled(true);
return;
}
- user.sendMessage(Util.i18n("notAllowedToShout"));
- event.setCancelled(true);
- return;
- }
- if (event.getMessage().startsWith("?") && event.getMessage().length() > 1)
- {
- if (user.isAuthorized("essentials.chat.question"))
+ if (event.getMessage().startsWith("?") && event.getMessage().length() > 1)
{
- event.setMessage(event.getMessage().substring(1));
- event.setFormat(Util.format("questionFormat", event.getFormat()));
+ if (user.isAuthorized("essentials.chat.question"))
+ {
+ charge(user,"chat-question");
+ event.setMessage(event.getMessage().substring(1));
+ event.setFormat(Util.format("questionFormat", event.getFormat()));
+ return;
+ }
+ user.sendMessage(Util.i18n("notAllowedToQuestion"));
+ event.setCancelled(true);
return;
}
- user.sendMessage(Util.i18n("notAllowedToQuestion"));
- event.setCancelled(true);
+ }
+ catch (ChargeException ex)
+ {
+ ess.showError(user, ex, "Shout");
return;
}
@@ -123,4 +135,12 @@ public class EssentialsChatPlayerListener extends PlayerListener
u.sendMessage(message);
}
}
+ protected void charge(final CommandSender sender, final String command) throws ChargeException
+ {
+ if (sender instanceof Player)
+ {
+ final Trade charge = new Trade(command, ess);
+ charge.charge(ess.getUser((Player)sender));
+ }
+ }
}