mirror of
https://github.com/essentials/Essentials.git
synced 2025-08-06 14:46:32 +02:00
Adding command cost for !shout and ?question.
This commit is contained in:
@@ -299,6 +299,7 @@ hide-permissionless-help: true
|
|||||||
# Note that users with the "essentials.chat.spy" permission will hear everything, regardless of this setting.
|
# Note that users with the "essentials.chat.spy" permission will hear everything, regardless of this setting.
|
||||||
# Users with essentials.chat.shout can override this by prefixing text with an exclamation mark (!)
|
# Users with essentials.chat.shout can override this by prefixing text with an exclamation mark (!)
|
||||||
# Or with essentials.chat.question can override this by prefixing text with a question mark (?)
|
# Or with essentials.chat.question can override this by prefixing text with a question mark (?)
|
||||||
|
# You can add command costs for shout/question by adding chat-shout and chat-question to the command costs section."
|
||||||
chat:
|
chat:
|
||||||
radius: 0
|
radius: 0
|
||||||
|
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
package com.earth2me.essentials.chat;
|
package com.earth2me.essentials.chat;
|
||||||
|
|
||||||
|
import com.earth2me.essentials.ChargeException;
|
||||||
import com.earth2me.essentials.IEssentials;
|
import com.earth2me.essentials.IEssentials;
|
||||||
|
import com.earth2me.essentials.Trade;
|
||||||
import com.earth2me.essentials.User;
|
import com.earth2me.essentials.User;
|
||||||
import com.earth2me.essentials.Util;
|
import com.earth2me.essentials.Util;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -8,6 +10,7 @@ import java.util.logging.Logger;
|
|||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.player.PlayerChatEvent;
|
import org.bukkit.event.player.PlayerChatEvent;
|
||||||
import org.bukkit.event.player.PlayerListener;
|
import org.bukkit.event.player.PlayerListener;
|
||||||
@@ -59,29 +62,38 @@ public class EssentialsChatPlayerListener extends PlayerListener
|
|||||||
}
|
}
|
||||||
radius *= radius;
|
radius *= radius;
|
||||||
|
|
||||||
if (event.getMessage().startsWith("!") && event.getMessage().length() > 1)
|
try {
|
||||||
{
|
if (event.getMessage().startsWith("!") && event.getMessage().length() > 1)
|
||||||
if (user.isAuthorized("essentials.chat.shout"))
|
|
||||||
{
|
{
|
||||||
event.setMessage(event.getMessage().substring(1));
|
if (user.isAuthorized("essentials.chat.shout"))
|
||||||
event.setFormat(Util.format("shoutFormat", event.getFormat()));
|
{
|
||||||
|
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;
|
return;
|
||||||
}
|
}
|
||||||
user.sendMessage(Util.i18n("notAllowedToShout"));
|
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.getMessage().startsWith("?") && event.getMessage().length() > 1)
|
if (event.getMessage().startsWith("?") && event.getMessage().length() > 1)
|
||||||
{
|
|
||||||
if (user.isAuthorized("essentials.chat.question"))
|
|
||||||
{
|
{
|
||||||
event.setMessage(event.getMessage().substring(1));
|
if (user.isAuthorized("essentials.chat.question"))
|
||||||
event.setFormat(Util.format("questionFormat", event.getFormat()));
|
{
|
||||||
|
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;
|
return;
|
||||||
}
|
}
|
||||||
user.sendMessage(Util.i18n("notAllowedToQuestion"));
|
}
|
||||||
event.setCancelled(true);
|
catch (ChargeException ex)
|
||||||
|
{
|
||||||
|
ess.showError(user, ex, "Shout");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,4 +135,12 @@ public class EssentialsChatPlayerListener extends PlayerListener
|
|||||||
u.sendMessage(message);
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user