1
0
mirror of https://github.com/essentials/Essentials.git synced 2025-08-16 03:24:31 +02:00

2nd sweep over Essentials Chat, to implement 2.8 changes.

Formatting cache still needs reimplemented.
This commit is contained in:
KHobbits
2012-01-24 23:20:00 +00:00
parent 38a9327284
commit df061749dd
6 changed files with 34 additions and 36 deletions

View File

@@ -168,7 +168,7 @@ public class GroupsHolder extends AsyncStorageObjectHolder<Groups> implements IG
{
for (GroupOptions groupOptions : getGroups(player))
{
if (groupOptions.getMessageFormat() != null)
if (groupOptions != null && groupOptions.getMessageFormat() != null)
{
return groupOptions.getMessageFormat();
}

View File

@@ -10,7 +10,6 @@ public class ChatStore
private final transient IUser user;
private final transient String type;
private final transient Trade charge;
private long radius;
public ChatStore(final IEssentials ess, final IUser user, final String type)
{
@@ -38,14 +37,4 @@ public class ChatStore
{
return type.length() > 0 ? "chat" : "chat-" + type;
}
public long getRadius()
{
return radius;
}
public void setRadius(final long radius)
{
this.radius = radius;
}
}

View File

@@ -42,7 +42,7 @@ public class EssentialsChat extends JavaPlugin
pluginManager.registerEvents(playerListenerLowest, this);
pluginManager.registerEvents(playerListenerNormal, this);
pluginManager.registerEvents(playerListenerHighest, this);
final EssentialsLocalChatEventListener localChatListener = new EssentialsLocalChatEventListener(getServer(), ess);
pluginManager.registerEvents(localChatListener, this);

View File

@@ -83,18 +83,21 @@ public abstract class EssentialsChatPlayer implements Listener
}
String group = user.getGroup();
String world = user.getWorld().getName();
IGroups groupSettings = ess.getGroups();
groupSettings.acquireReadLock();
try
{
event.setFormat(groupSettings.getChatFormat(user).format(new Object[] {group, world, world.substring(0, 1).toUpperCase(Locale.ENGLISH)}));
{
event.setFormat(groupSettings.getChatFormat(user).format(new Object[]
{
group, world, world.substring(0, 1).toUpperCase(Locale.ENGLISH)
}));
}
finally
{
groupSettings.unlock();
}
}
//TODO: Flesh this out - '?' trigger is too easily accidentally triggered
@@ -105,7 +108,7 @@ public abstract class EssentialsChatPlayer implements Listener
case '!':
return "shout";
//case '?':
//return "question";
//return "question";
//case '@':
// return "admin";
default:
@@ -126,8 +129,13 @@ public abstract class EssentialsChatPlayer implements Listener
{
settings.unlock();
}
if (radius < 1)
{
return;
}
radius *= radius;
chatStore.setRadius(radius);
final IUser user = chatStore.getUser();
@@ -154,7 +162,7 @@ public abstract class EssentialsChatPlayer implements Listener
}
event.setCancelled(true);
final EssentialsLocalChatEvent localChat = new EssentialsLocalChatEvent(event, chatStore);
final EssentialsLocalChatEvent localChat = new EssentialsLocalChatEvent(event, radius);
ess.getServer().getPluginManager().callEvent(localChat);
}
}

View File

@@ -25,9 +25,9 @@ public class EssentialsLocalChatEvent extends Event implements Cancellable
this.radius = radius;
}
public EssentialsLocalChatEvent(final PlayerChatEvent event, final ChatStore chatStore)
public EssentialsLocalChatEvent(final PlayerChatEvent event, final long radius)
{
this(event.getPlayer(), event.getMessage(), event.getFormat(), chatStore.getRadius());
this(event.getPlayer(), event.getMessage(), event.getFormat(), radius);
this.parentEvent = event;
}

View File

@@ -3,33 +3,34 @@ package com.earth2me.essentials.chat;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.api.IUser;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
public class EssentialsLocalChatEventListener implements Listener {
public class EssentialsLocalChatEventListener implements Listener
{
protected transient IEssentials ess;
protected final transient Server server;
private static final Logger LOGGER = Logger.getLogger("Minecraft");
public EssentialsLocalChatEventListener(final Server server, final IEssentials ess)
{
this.ess = ess;
this.server = server;
}
@EventHandler
public void onLocalChat(final EssentialsLocalChatEvent event) {
@EventHandler(priority = EventPriority.HIGHEST)
public void onLocalChat(final EssentialsLocalChatEvent event)
{
final Player sender = event.getPlayer();
if (event.getRadius() < 1)
{
return;
}
event.setCancelled(true);
final Location loc = sender.getLocation();
final World world = loc.getWorld();
@@ -64,8 +65,8 @@ public class EssentialsLocalChatEventListener implements Listener {
}
}
final String message = String.format(event.getFormat(), type.concat(sender.getDisplayName()), event.getMessage());
final String message = type.concat(String.format(event.getFormat(), sender.getDisplayName(), event.getMessage()));
user.sendMessage(message);
}
}
}
}
}