mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-12 20:29:20 +00:00
Merge branch 'master' into release
This commit is contained in:
commit
5467e502a5
8 changed files with 105 additions and 38 deletions
|
@ -2,6 +2,8 @@ package com.earth2me.essentials.chat;
|
|||
|
||||
import com.earth2me.essentials.IEssentials;
|
||||
import com.earth2me.essentials.Util;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.event.Event.Priority;
|
||||
|
@ -13,15 +15,17 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||
public class EssentialsChat extends JavaPlugin
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger("Minecraft");
|
||||
private Map<String, IEssentialsChatListener> chatListener;
|
||||
|
||||
public void onEnable()
|
||||
{
|
||||
final PluginManager pluginManager = getServer().getPluginManager();
|
||||
final IEssentials ess = (IEssentials)pluginManager.getPlugin("Essentials");
|
||||
|
||||
EssentialsChatPlayerListener.checkFactions(pluginManager);
|
||||
chatListener = new HashMap<String, IEssentialsChatListener>();
|
||||
//EssentialsChatPlayerListener.checkFactions(pluginManager);
|
||||
|
||||
final EssentialsChatPlayerListener playerListener = new EssentialsChatPlayerListener(getServer(), ess);
|
||||
final EssentialsChatPlayerListener playerListener = new EssentialsChatPlayerListener(getServer(), ess, chatListener);
|
||||
pluginManager.registerEvent(Type.PLAYER_CHAT, playerListener, Priority.Highest, this);
|
||||
if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion()))
|
||||
{
|
||||
|
@ -32,5 +36,11 @@ public class EssentialsChat extends JavaPlugin
|
|||
|
||||
public void onDisable()
|
||||
{
|
||||
chatListener.clear();
|
||||
}
|
||||
|
||||
public void addEssentialsChatListener(String plugin, IEssentialsChatListener listener)
|
||||
{
|
||||
chatListener.put(plugin, listener);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,31 +3,30 @@ package com.earth2me.essentials.chat;
|
|||
import com.earth2me.essentials.IEssentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
import java.util.Map;
|
||||
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.player.PlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerListener;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
import org.mcteam.factions.Factions;
|
||||
|
||||
//import org.mcteam.factions.Factions;
|
||||
|
||||
public class EssentialsChatPlayerListener extends PlayerListener
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger("Minecraft");
|
||||
private final transient IEssentials ess;
|
||||
private final transient Server server;
|
||||
private static Factions factions = null;
|
||||
private final transient Map<String, IEssentialsChatListener> listeners;
|
||||
//private static Factions factions = null;
|
||||
|
||||
public EssentialsChatPlayerListener(final Server server, final IEssentials ess)
|
||||
public EssentialsChatPlayerListener(final Server server, final IEssentials ess, final Map<String, IEssentialsChatListener> listeners)
|
||||
{
|
||||
this.server = server;
|
||||
this.ess = ess;
|
||||
this.listeners = listeners;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -38,8 +37,15 @@ public class EssentialsChatPlayerListener extends PlayerListener
|
|||
return;
|
||||
}
|
||||
|
||||
if (factions != null && (factions.shouldLetFactionsHandleThisChat(event)))
|
||||
return;
|
||||
//if (factions != null && (factions.shouldLetFactionsHandleThisChat(event)))
|
||||
// return;
|
||||
for (IEssentialsChatListener listener : listeners.values())
|
||||
{
|
||||
if (listener.shouldHandleThisChat(event))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
|
||||
|
@ -112,37 +118,42 @@ public class EssentialsChatPlayerListener extends PlayerListener
|
|||
}
|
||||
String message = String.format(event.getFormat(), user.getDisplayName(), event.getMessage());
|
||||
|
||||
if (factions != null)
|
||||
message = message.replace("{FACTION}", factions.getPlayerFactionTagRelation(event.getPlayer(), p)).replace("{FACTION_TITLE}", factions.getPlayerTitle(event.getPlayer()));
|
||||
for (IEssentialsChatListener listener : listeners.values())
|
||||
{
|
||||
message = listener.modifyMessage(event, message);
|
||||
|
||||
}
|
||||
//if (factions != null)
|
||||
// message = message.replace("{FACTION}", factions.getPlayerFactionTagRelation(event.getPlayer(), p)).replace("{FACTION_TITLE}", factions.getPlayerTitle(event.getPlayer()));
|
||||
|
||||
u.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
protected static void checkFactions(PluginManager pm)
|
||||
/*protected static void checkFactions(PluginManager pm)
|
||||
{
|
||||
if (factions != null)
|
||||
return;
|
||||
|
||||
Plugin factionsPlugin = pm.getPlugin("Factions");
|
||||
if (factionsPlugin == null)
|
||||
return;
|
||||
|
||||
factions = (Factions)factionsPlugin;
|
||||
try
|
||||
{ // make sure Factions is sufficiently up-to-date
|
||||
if (factions.hookSupportVersion() < 1)
|
||||
factions = null;
|
||||
}
|
||||
catch (NoSuchMethodError ex)
|
||||
{ // if not, we can't work with it, so don't bother
|
||||
factions = null;
|
||||
}
|
||||
|
||||
if (factions == null)
|
||||
return;
|
||||
|
||||
// normally a good thing, but we'll skip it to let Factions handle faction tags for global messages
|
||||
//factions.handleFactionTagExternally(true);
|
||||
if (factions != null)
|
||||
return;
|
||||
|
||||
Plugin factionsPlugin = pm.getPlugin("Factions");
|
||||
if (factionsPlugin == null)
|
||||
return;
|
||||
|
||||
factions = (Factions)factionsPlugin;
|
||||
try
|
||||
{ // make sure Factions is sufficiently up-to-date
|
||||
if (factions.hookSupportVersion() < 1)
|
||||
factions = null;
|
||||
}
|
||||
catch (NoSuchMethodError ex)
|
||||
{ // if not, we can't work with it, so don't bother
|
||||
factions = null;
|
||||
}
|
||||
|
||||
if (factions == null)
|
||||
return;
|
||||
|
||||
// normally a good thing, but we'll skip it to let Factions handle faction tags for global messages
|
||||
//factions.handleFactionTagExternally(true);
|
||||
}*/
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package com.earth2me.essentials.chat;
|
||||
|
||||
import org.bukkit.event.player.PlayerChatEvent;
|
||||
|
||||
|
||||
public interface IEssentialsChatListener
|
||||
{
|
||||
boolean shouldHandleThisChat(PlayerChatEvent event);
|
||||
|
||||
String modifyMessage(PlayerChatEvent event, String message);
|
||||
}
|
|
@ -7,4 +7,4 @@ website: http://www.earth2me.net:8001/
|
|||
description: Provides chat control features for Essentials. Requires Permissions.
|
||||
authors: [Zenexer, ementalo, Aelux, Brettflan, KimKandor, snowleo, ceulemans, Xeology]
|
||||
depend: [Essentials]
|
||||
softdepend: [Factions]
|
||||
#softdepend: [Factions]
|
|
@ -12,7 +12,9 @@ import java.beans.PropertyVetoException;
|
|||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Filter;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -25,12 +27,26 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||
public class EssentialsProtect extends JavaPlugin implements IConf, IProtect
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger("Minecraft");
|
||||
private static com.mchange.v2.log.MLogger C3P0logger;
|
||||
private final transient Map<ProtectConfig, Boolean> settingsBoolean = new EnumMap<ProtectConfig, Boolean>(ProtectConfig.class);
|
||||
private final transient Map<ProtectConfig, String> settingsString = new EnumMap<ProtectConfig, String>(ProtectConfig.class);
|
||||
private final transient Map<ProtectConfig, List<Integer>> settingsList = new EnumMap<ProtectConfig, List<Integer>>(ProtectConfig.class);
|
||||
private transient IProtectedBlock storage = null;
|
||||
public transient IEssentials ess = null;
|
||||
|
||||
@Override
|
||||
public void onLoad()
|
||||
{
|
||||
C3P0logger = com.mchange.v2.log.MLog.getLogger(com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.class);
|
||||
C3P0logger.setFilter(new Filter()
|
||||
{
|
||||
public boolean isLoggable(LogRecord lr)
|
||||
{
|
||||
return lr.getLevel() != Level.INFO;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void onEnable()
|
||||
{
|
||||
final PluginManager pm = this.getServer().getPluginManager();
|
||||
|
@ -96,6 +112,10 @@ public class EssentialsProtect extends JavaPlugin implements IConf, IProtect
|
|||
|
||||
public void reloadConfig()
|
||||
{
|
||||
if (storage != null)
|
||||
{
|
||||
storage.onPluginDeactivation();
|
||||
}
|
||||
for (ProtectConfig protectConfig : ProtectConfig.values())
|
||||
{
|
||||
if (protectConfig.isList())
|
||||
|
@ -166,6 +186,10 @@ public class EssentialsProtect extends JavaPlugin implements IConf, IProtect
|
|||
|
||||
public void onDisable()
|
||||
{
|
||||
if (storage != null)
|
||||
{
|
||||
storage.onPluginDeactivation();
|
||||
}
|
||||
}
|
||||
|
||||
public IEssentials getEssentials()
|
||||
|
|
|
@ -11,4 +11,5 @@ public interface IProtectedBlock {
|
|||
public boolean isProtected(Block block, String playerName);
|
||||
public List<String> getOwners(Block block);
|
||||
public int unprotectBlock(Block block);
|
||||
public void onPluginDeactivation();
|
||||
}
|
||||
|
|
|
@ -418,4 +418,9 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onPluginDeactivation()
|
||||
{
|
||||
cpds.close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -245,4 +245,9 @@ public class ProtectedBlockMemory implements IProtectedBlock
|
|||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
public void onPluginDeactivation()
|
||||
{
|
||||
storage.onPluginDeactivation();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue