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