mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-22 17:18:37 +01:00
Fix broken charge for shout and question
This commit is contained in:
parent
95d5217f58
commit
de12c5c6d1
@ -4,10 +4,12 @@ import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.IEssentials;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentSkipListMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.event.Event.Priority;
|
||||
import org.bukkit.event.Event.Type;
|
||||
import org.bukkit.event.player.PlayerChatEvent;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
@ -15,8 +17,10 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
public class EssentialsChat extends JavaPlugin
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger("Minecraft");
|
||||
private Map<String, IEssentialsChatListener> chatListener;
|
||||
private transient Map<String, IEssentialsChatListener> chatListener;
|
||||
|
||||
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
final PluginManager pluginManager = getServer().getPluginManager();
|
||||
@ -31,11 +35,13 @@ public class EssentialsChat extends JavaPlugin
|
||||
return;
|
||||
}
|
||||
|
||||
chatListener = new HashMap<String, IEssentialsChatListener>();
|
||||
chatListener = new ConcurrentSkipListMap<String, IEssentialsChatListener>();
|
||||
final Map<PlayerChatEvent, String> charges = new HashMap<PlayerChatEvent, String>();
|
||||
|
||||
|
||||
final EssentialsChatPlayerListenerLowest playerListenerLowest = new EssentialsChatPlayerListenerLowest(getServer(), ess, chatListener);
|
||||
final EssentialsChatPlayerListenerNormal playerListenerNormal = new EssentialsChatPlayerListenerNormal(getServer(), ess, chatListener);
|
||||
final EssentialsChatPlayerListenerHighest playerListenerHighest = new EssentialsChatPlayerListenerHighest(getServer(), ess, chatListener);
|
||||
final EssentialsChatPlayerListenerNormal playerListenerNormal = new EssentialsChatPlayerListenerNormal(getServer(), ess, chatListener, charges);
|
||||
final EssentialsChatPlayerListenerHighest playerListenerHighest = new EssentialsChatPlayerListenerHighest(getServer(), ess, chatListener, charges);
|
||||
pluginManager.registerEvent(Type.PLAYER_CHAT, playerListenerLowest, Priority.Lowest, this);
|
||||
pluginManager.registerEvent(Type.PLAYER_CHAT, playerListenerNormal, Priority.Normal, this);
|
||||
pluginManager.registerEvent(Type.PLAYER_CHAT, playerListenerHighest, Priority.Highest, this);
|
||||
@ -43,6 +49,7 @@ public class EssentialsChat extends JavaPlugin
|
||||
LOGGER.info(_("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), "essentials team"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
if (chatListener != null)
|
||||
|
@ -10,14 +10,25 @@ import org.bukkit.event.player.PlayerChatEvent;
|
||||
|
||||
public class EssentialsChatPlayerListenerHighest extends EssentialsChatPlayer
|
||||
{
|
||||
public EssentialsChatPlayerListenerHighest(Server server, IEssentials ess, Map<String, IEssentialsChatListener> listeners)
|
||||
private final transient Map<PlayerChatEvent, String> charges;
|
||||
|
||||
public EssentialsChatPlayerListenerHighest(final Server server,
|
||||
final IEssentials ess,
|
||||
final Map<String, IEssentialsChatListener> listeners,
|
||||
final Map<PlayerChatEvent, String> charges)
|
||||
{
|
||||
super(server, ess, listeners);
|
||||
this.charges = charges;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerChat(final PlayerChatEvent event)
|
||||
{
|
||||
String charge = charges.remove(event);
|
||||
if (charge == null)
|
||||
{
|
||||
charge = "chat";
|
||||
}
|
||||
if (isAborted(event))
|
||||
{
|
||||
return;
|
||||
@ -27,22 +38,14 @@ public class EssentialsChatPlayerListenerHighest extends EssentialsChatPlayer
|
||||
* This file should handle charging the user for the action before returning control back
|
||||
*/
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
final String chatType = getChatType(event.getMessage());
|
||||
final StringBuilder command = new StringBuilder();
|
||||
command.append("chat");
|
||||
|
||||
if (chatType.length() > 0)
|
||||
{
|
||||
command.append("-").append(chatType);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
charge(user, command.toString());
|
||||
charge(user, charge);
|
||||
}
|
||||
catch (ChargeException e)
|
||||
{
|
||||
ess.showError(user, e, command.toString());
|
||||
ess.showError(user, e, charge);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
@ -10,7 +10,9 @@ import org.bukkit.event.player.PlayerChatEvent;
|
||||
|
||||
public class EssentialsChatPlayerListenerLowest extends EssentialsChatPlayer
|
||||
{
|
||||
public EssentialsChatPlayerListenerLowest(Server server, IEssentials ess, Map<String, IEssentialsChatListener> listeners)
|
||||
public EssentialsChatPlayerListenerLowest(final Server server,
|
||||
final IEssentials ess,
|
||||
final Map<String, IEssentialsChatListener> listeners)
|
||||
{
|
||||
super(server, ess, listeners);
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.earth2me.essentials.chat;
|
||||
|
||||
import com.earth2me.essentials.ChargeException;
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.IEssentials;
|
||||
import com.earth2me.essentials.User;
|
||||
@ -12,9 +11,15 @@ import org.bukkit.event.player.PlayerChatEvent;
|
||||
|
||||
public class EssentialsChatPlayerListenerNormal extends EssentialsChatPlayer
|
||||
{
|
||||
public EssentialsChatPlayerListenerNormal(Server server, IEssentials ess, Map<String, IEssentialsChatListener> listeners)
|
||||
private final transient Map<PlayerChatEvent, String> charges;
|
||||
|
||||
public EssentialsChatPlayerListenerNormal(final Server server,
|
||||
final IEssentials ess,
|
||||
final Map<String, IEssentialsChatListener> listeners,
|
||||
final Map<PlayerChatEvent, String> charges)
|
||||
{
|
||||
super(server, ess, listeners);
|
||||
this.charges = charges;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -29,49 +34,46 @@ public class EssentialsChatPlayerListenerNormal extends EssentialsChatPlayer
|
||||
* This file should handle detection of the local chat features... if local chat is enabled, we need to handle
|
||||
* it here
|
||||
*/
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
final String chatType = getChatType(event.getMessage());
|
||||
final StringBuilder command = new StringBuilder();
|
||||
command.append("chat");
|
||||
|
||||
if (chatType.length() > 0)
|
||||
{
|
||||
command.append("-").append(chatType);
|
||||
}
|
||||
long radius = ess.getSettings().getChatRadius();
|
||||
if (radius < 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
radius *= radius;
|
||||
try
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
|
||||
if (event.getMessage().length() > 0 && chatType.length() > 0)
|
||||
{
|
||||
if (event.getMessage().length() > 0 && chatType.length() > 0)
|
||||
final StringBuilder permission = new StringBuilder();
|
||||
permission.append("essentials.chat.").append(chatType);
|
||||
|
||||
final StringBuilder format = new StringBuilder();
|
||||
format.append(chatType).append("Format");
|
||||
|
||||
final StringBuilder errorMsg = new StringBuilder();
|
||||
errorMsg.append("notAllowedTo").append(chatType.substring(0, 1).toUpperCase(Locale.ENGLISH)).append(chatType.substring(1));
|
||||
|
||||
if (user.isAuthorized(permission.toString()))
|
||||
{
|
||||
StringBuilder permission = new StringBuilder();
|
||||
permission.append("essentials.chat.").append(chatType);
|
||||
|
||||
StringBuilder command = new StringBuilder();
|
||||
command.append("chat-").append(chatType);
|
||||
|
||||
StringBuilder format = new StringBuilder();
|
||||
format.append(chatType).append("Format");
|
||||
|
||||
StringBuilder errorMsg = new StringBuilder();
|
||||
errorMsg.append("notAllowedTo").append(chatType.substring(0, 1).toUpperCase(Locale.ENGLISH)).append(chatType.substring(1));
|
||||
|
||||
if (user.isAuthorized(permission.toString()))
|
||||
{
|
||||
charge(user, command.toString());
|
||||
event.setMessage(event.getMessage().substring(1));
|
||||
event.setFormat(_(format.toString(), event.getFormat()));
|
||||
return;
|
||||
}
|
||||
|
||||
user.sendMessage(_(errorMsg.toString()));
|
||||
event.setCancelled(true);
|
||||
event.setMessage(event.getMessage().substring(1));
|
||||
event.setFormat(_(format.toString(), event.getFormat()));
|
||||
charges.put(event, command.toString());
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (ChargeException ex)
|
||||
{
|
||||
ess.showError(user, ex, "Shout");
|
||||
|
||||
user.sendMessage(_(errorMsg.toString()));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
sendLocalChat(user, radius, event);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user