Merge remote-tracking branch 'origin/master' into CustomFactionEvents
This commit is contained in:
commit
cc772b00ce
@ -100,6 +100,7 @@ public class Conf
|
|||||||
public static boolean logLandClaims = true;
|
public static boolean logLandClaims = true;
|
||||||
public static boolean logLandUnclaims = true;
|
public static boolean logLandUnclaims = true;
|
||||||
public static boolean logMoneyTransactions = true;
|
public static boolean logMoneyTransactions = true;
|
||||||
|
public static boolean logPlayerCommands = true;
|
||||||
|
|
||||||
public static boolean homesEnabled = true;
|
public static boolean homesEnabled = true;
|
||||||
public static boolean homesMustBeInClaimedTerritory = true;
|
public static boolean homesMustBeInClaimedTerritory = true;
|
||||||
|
@ -2,16 +2,18 @@ package com.massivecraft.factions;
|
|||||||
|
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.command.CommandSender;
|
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.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
|
||||||
import com.massivecraft.factions.adapters.FFlagTypeAdapter;
|
import com.massivecraft.factions.adapters.FFlagTypeAdapter;
|
||||||
import com.massivecraft.factions.adapters.FLocToStringSetTypeAdapter;
|
import com.massivecraft.factions.adapters.FLocToStringSetTypeAdapter;
|
||||||
@ -26,7 +28,7 @@ import com.massivecraft.factions.integration.LWCFeatures;
|
|||||||
import com.massivecraft.factions.integration.SpoutFeatures;
|
import com.massivecraft.factions.integration.SpoutFeatures;
|
||||||
import com.massivecraft.factions.integration.Worldguard;
|
import com.massivecraft.factions.integration.Worldguard;
|
||||||
import com.massivecraft.factions.listeners.FactionsBlockListener;
|
import com.massivecraft.factions.listeners.FactionsBlockListener;
|
||||||
import com.massivecraft.factions.listeners.FactionsChatEarlyListener;
|
import com.massivecraft.factions.listeners.FactionsChatListener;
|
||||||
import com.massivecraft.factions.listeners.FactionsEntityListener;
|
import com.massivecraft.factions.listeners.FactionsEntityListener;
|
||||||
import com.massivecraft.factions.listeners.FactionsPlayerListener;
|
import com.massivecraft.factions.listeners.FactionsPlayerListener;
|
||||||
import com.massivecraft.factions.listeners.FactionsServerListener;
|
import com.massivecraft.factions.listeners.FactionsServerListener;
|
||||||
@ -36,6 +38,7 @@ import com.massivecraft.factions.struct.FPerm;
|
|||||||
import com.massivecraft.factions.struct.Rel;
|
import com.massivecraft.factions.struct.Rel;
|
||||||
import com.massivecraft.factions.util.AutoLeaveTask;
|
import com.massivecraft.factions.util.AutoLeaveTask;
|
||||||
import com.massivecraft.factions.zcore.MPlugin;
|
import com.massivecraft.factions.zcore.MPlugin;
|
||||||
|
import com.massivecraft.factions.zcore.util.TextUtil;
|
||||||
|
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
@ -48,7 +51,7 @@ public class P extends MPlugin
|
|||||||
|
|
||||||
// Listeners
|
// Listeners
|
||||||
public final FactionsPlayerListener playerListener;
|
public final FactionsPlayerListener playerListener;
|
||||||
public final FactionsChatEarlyListener chatEarlyListener;
|
public final FactionsChatListener chatListener;
|
||||||
public final FactionsEntityListener entityListener;
|
public final FactionsEntityListener entityListener;
|
||||||
public final FactionsBlockListener blockListener;
|
public final FactionsBlockListener blockListener;
|
||||||
public final FactionsServerListener serverListener;
|
public final FactionsServerListener serverListener;
|
||||||
@ -67,7 +70,7 @@ public class P extends MPlugin
|
|||||||
{
|
{
|
||||||
p = this;
|
p = this;
|
||||||
this.playerListener = new FactionsPlayerListener(this);
|
this.playerListener = new FactionsPlayerListener(this);
|
||||||
this.chatEarlyListener = new FactionsChatEarlyListener(this);
|
this.chatListener = new FactionsChatListener(this);
|
||||||
this.entityListener = new FactionsEntityListener(this);
|
this.entityListener = new FactionsEntityListener(this);
|
||||||
this.blockListener = new FactionsBlockListener(this);
|
this.blockListener = new FactionsBlockListener(this);
|
||||||
this.serverListener = new FactionsServerListener(this);
|
this.serverListener = new FactionsServerListener(this);
|
||||||
@ -107,11 +110,14 @@ public class P extends MPlugin
|
|||||||
|
|
||||||
// Register Event Handlers
|
// Register Event Handlers
|
||||||
getServer().getPluginManager().registerEvents(playerListener, this);
|
getServer().getPluginManager().registerEvents(playerListener, this);
|
||||||
getServer().getPluginManager().registerEvents(chatEarlyListener, this);
|
getServer().getPluginManager().registerEvents(chatListener, this);
|
||||||
getServer().getPluginManager().registerEvents(entityListener, this);
|
getServer().getPluginManager().registerEvents(entityListener, this);
|
||||||
getServer().getPluginManager().registerEvents(blockListener, this);
|
getServer().getPluginManager().registerEvents(blockListener, this);
|
||||||
getServer().getPluginManager().registerEvents(serverListener, this);
|
getServer().getPluginManager().registerEvents(serverListener, this);
|
||||||
|
|
||||||
|
// since some other plugins execute commands directly through this command interface, provide it
|
||||||
|
this.getCommand(this.refCommand).setExecutor(this);
|
||||||
|
|
||||||
postEnable();
|
postEnable();
|
||||||
this.loadSuccessful = true;
|
this.loadSuccessful = true;
|
||||||
}
|
}
|
||||||
@ -172,6 +178,12 @@ public class P extends MPlugin
|
|||||||
Conf.save();
|
Conf.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean logPlayerCommands()
|
||||||
|
{
|
||||||
|
return Conf.logPlayerCommands;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handleCommand(CommandSender sender, String commandString, boolean testOnly)
|
public boolean handleCommand(CommandSender sender, String commandString, boolean testOnly)
|
||||||
{
|
{
|
||||||
@ -180,6 +192,17 @@ public class P extends MPlugin
|
|||||||
return super.handleCommand(sender, commandString, testOnly);
|
return super.handleCommand(sender, commandString, testOnly);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] split)
|
||||||
|
{
|
||||||
|
// if bare command at this point, it has already been handled by MPlugin's command listeners
|
||||||
|
if (split == null || split.length == 0) return true;
|
||||||
|
|
||||||
|
// otherwise, needs to be handled; presumably another plugin directly ran the command
|
||||||
|
String cmd = Conf.baseCommandAliases.isEmpty() ? "/f" : "/" + Conf.baseCommandAliases.get(0);
|
||||||
|
return handleCommand(sender, cmd + " " + TextUtil.implode(Arrays.asList(split), " "), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
@ -5,6 +5,8 @@ import java.lang.reflect.ParameterizedType;
|
|||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -13,7 +15,10 @@ import org.bukkit.entity.Player;
|
|||||||
import com.massivecraft.factions.Conf;
|
import com.massivecraft.factions.Conf;
|
||||||
import com.massivecraft.factions.P;
|
import com.massivecraft.factions.P;
|
||||||
import com.massivecraft.factions.integration.SpoutFeatures;
|
import com.massivecraft.factions.integration.SpoutFeatures;
|
||||||
|
import com.massivecraft.factions.struct.FFlag;
|
||||||
|
import com.massivecraft.factions.struct.FPerm;
|
||||||
import com.massivecraft.factions.struct.Permission;
|
import com.massivecraft.factions.struct.Permission;
|
||||||
|
import com.massivecraft.factions.struct.Rel;
|
||||||
|
|
||||||
public class CmdConfig extends FCommand
|
public class CmdConfig extends FCommand
|
||||||
{
|
{
|
||||||
@ -174,76 +179,186 @@ public class CmdConfig extends FCommand
|
|||||||
ParameterizedType targSet = (ParameterizedType)target.getGenericType();
|
ParameterizedType targSet = (ParameterizedType)target.getGenericType();
|
||||||
Type innerType = targSet.getActualTypeArguments()[0];
|
Type innerType = targSet.getActualTypeArguments()[0];
|
||||||
|
|
||||||
// not a Set, somehow, and that should be the only collection we're using in Conf.java
|
// Set<?>
|
||||||
if (targSet.getRawType() != Set.class)
|
if (targSet.getRawType() == Set.class)
|
||||||
{
|
{
|
||||||
sendMessage("\""+fieldName+"\" is not a data collection type which can be modified with this command.");
|
// Set<Material>
|
||||||
return;
|
if (innerType == Material.class)
|
||||||
}
|
{
|
||||||
|
Material newMat = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
newMat = Material.valueOf(value.toUpperCase());
|
||||||
|
}
|
||||||
|
catch (IllegalArgumentException ex)
|
||||||
|
{
|
||||||
|
|
||||||
// Set<Material>
|
}
|
||||||
else if (innerType == Material.class)
|
if (newMat == null)
|
||||||
{
|
{
|
||||||
Material newMat = null;
|
sendMessage("Cannot change \""+fieldName+"\" set: \""+value.toUpperCase()+"\" is not a valid material.");
|
||||||
try
|
return;
|
||||||
{
|
}
|
||||||
newMat = Material.valueOf(value.toUpperCase());
|
|
||||||
}
|
@SuppressWarnings("unchecked")
|
||||||
catch (IllegalArgumentException ex)
|
Set<Material> matSet = (Set<Material>)target.get(null);
|
||||||
{
|
|
||||||
|
// Material already present, so remove it
|
||||||
}
|
if (matSet.contains(newMat))
|
||||||
if (newMat == null)
|
{
|
||||||
{
|
matSet.remove(newMat);
|
||||||
sendMessage("Cannot change \""+fieldName+"\" set: \""+value.toUpperCase()+"\" is not a valid material.");
|
target.set(null, matSet);
|
||||||
return;
|
success = "\""+fieldName+"\" set: Material \""+value.toUpperCase()+"\" removed.";
|
||||||
|
}
|
||||||
|
// Material not present yet, add it
|
||||||
|
else
|
||||||
|
{
|
||||||
|
matSet.add(newMat);
|
||||||
|
target.set(null, matSet);
|
||||||
|
success = "\""+fieldName+"\" set: Material \""+value.toUpperCase()+"\" added.";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
// Set<String>
|
||||||
Set<Material> matSet = (Set<Material>)target.get(null);
|
else if (innerType == String.class)
|
||||||
|
|
||||||
// Material already present, so remove it
|
|
||||||
if (matSet.contains(newMat))
|
|
||||||
{
|
{
|
||||||
matSet.remove(newMat);
|
@SuppressWarnings("unchecked")
|
||||||
target.set(null, matSet);
|
Set<String> stringSet = (Set<String>)target.get(null);
|
||||||
success = "\""+fieldName+"\" set: Material \""+value.toUpperCase()+"\" removed.";
|
|
||||||
|
// String already present, so remove it
|
||||||
|
if (stringSet.contains(value))
|
||||||
|
{
|
||||||
|
stringSet.remove(value);
|
||||||
|
success = "\""+fieldName+"\" set: \""+value+"\" removed.";
|
||||||
|
}
|
||||||
|
// String not present yet, add it
|
||||||
|
else
|
||||||
|
{
|
||||||
|
stringSet.add(value);
|
||||||
|
success = "\""+fieldName+"\" set: \""+value+"\" added.";
|
||||||
|
}
|
||||||
|
target.set(null, stringSet);
|
||||||
}
|
}
|
||||||
// Material not present yet, add it
|
|
||||||
|
// Set of unknown type
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
matSet.add(newMat);
|
sendMessage("\""+fieldName+"\" is not a data type set which can be modified with this command.");
|
||||||
target.set(null, matSet);
|
return;
|
||||||
success = "\""+fieldName+"\" set: Material \""+value.toUpperCase()+"\" added.";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set<String>
|
// Map<?, ?>
|
||||||
else if (innerType == String.class)
|
else if (targSet.getRawType() == Map.class)
|
||||||
{
|
{
|
||||||
@SuppressWarnings("unchecked")
|
if (args.size() < 3)
|
||||||
Set<String> stringSet = (Set<String>)target.get(null);
|
|
||||||
|
|
||||||
// String already present, so remove it
|
|
||||||
if (stringSet.contains(value))
|
|
||||||
{
|
{
|
||||||
stringSet.remove(value);
|
sendMessage("Cannot change \""+fieldName+"\" map: not enough arguments passed.");
|
||||||
target.set(null, stringSet);
|
return;
|
||||||
success = "\""+fieldName+"\" set: \""+value+"\" removed.";
|
|
||||||
}
|
}
|
||||||
// String not present yet, add it
|
Type innerType2 = targSet.getActualTypeArguments()[1];
|
||||||
else
|
String value1 = args.get(1);
|
||||||
|
String value2 = value.substring(value1.length() + 1);
|
||||||
|
|
||||||
|
// Map<FFlag, Boolean>
|
||||||
|
if (innerType == FFlag.class && innerType2 == Boolean.class)
|
||||||
{
|
{
|
||||||
stringSet.add(value);
|
value1 = value1.toUpperCase();
|
||||||
target.set(null, stringSet);
|
FFlag newFlag = null;
|
||||||
success = "\""+fieldName+"\" set: \""+value+"\" added.";
|
try
|
||||||
|
{
|
||||||
|
newFlag = FFlag.valueOf(value1);
|
||||||
|
}
|
||||||
|
catch (IllegalArgumentException ex) {}
|
||||||
|
|
||||||
|
if (newFlag == null)
|
||||||
|
{
|
||||||
|
sendMessage("Cannot change \""+fieldName+"\" map: \""+value1+"\" is not a valid FFlag.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Map<FFlag, Boolean> map = (Map<FFlag, Boolean>)target.get(null);
|
||||||
|
|
||||||
|
Boolean targetValue = this.strAsBool(value2);
|
||||||
|
|
||||||
|
map.put(newFlag, targetValue);
|
||||||
|
target.set(null, map);
|
||||||
|
|
||||||
|
if (targetValue)
|
||||||
|
success = "\""+fieldName+"\" flag \""+value1+"\" set to true (enabled).";
|
||||||
|
else
|
||||||
|
success = "\""+fieldName+"\" flag \""+value1+"\" set to false (disabled).";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Map<FPerm, Set<Rel>>
|
||||||
|
else if (innerType == FPerm.class && innerType2 instanceof ParameterizedType)
|
||||||
|
{
|
||||||
|
if (((ParameterizedType)innerType2).getRawType() != Set.class)
|
||||||
|
{
|
||||||
|
sendMessage("\""+fieldName+"\" is not a data type map which can be modified with this command, due to the inner collection type.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
value1 = value1.toUpperCase();
|
||||||
|
value2 = value2.toUpperCase();
|
||||||
|
|
||||||
|
FPerm newPerm = null;
|
||||||
|
Rel newRel = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
newPerm = FPerm.valueOf(value1);
|
||||||
|
newRel = Rel.valueOf(value2);
|
||||||
|
}
|
||||||
|
catch (IllegalArgumentException ex) {}
|
||||||
|
|
||||||
|
if (newPerm == null)
|
||||||
|
{
|
||||||
|
sendMessage("Cannot change \""+fieldName+"\" map: \""+value1+"\" is not a valid FPerm.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (newRel == null)
|
||||||
|
{
|
||||||
|
sendMessage("Cannot change \""+fieldName+"\" map: \""+value2+"\" is not a valid Rel.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Map<FPerm, Set<Rel>> map = (Map<FPerm, Set<Rel>>)target.get(null);
|
||||||
|
|
||||||
|
Set<Rel> relSet = map.get(newPerm);
|
||||||
|
if (relSet == null)
|
||||||
|
relSet = new HashSet<Rel>();
|
||||||
|
|
||||||
|
// Rel already present, so remove it
|
||||||
|
if (relSet.contains(newRel))
|
||||||
|
{
|
||||||
|
relSet.remove(newRel);
|
||||||
|
success = "\""+fieldName+"\" permission \""+value1+"\": relation \""+value2+"\" removed.";
|
||||||
|
}
|
||||||
|
// Rel not present yet, add it
|
||||||
|
else
|
||||||
|
{
|
||||||
|
relSet.add(newRel);
|
||||||
|
success = "\""+fieldName+"\" permission \""+value1+"\": relation \""+value2+"\" added.";
|
||||||
|
}
|
||||||
|
|
||||||
|
map.put(newPerm, relSet);
|
||||||
|
target.set(null, map);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Map of unknown type
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sendMessage("\""+fieldName+"\" is not a data type map which can be modified with this command.");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set of unknown type
|
// not a Set or Map?
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sendMessage("\""+fieldName+"\" is not a data type set which can be modified with this command.");
|
sendMessage("\""+fieldName+"\" is not a data collection type which can be modified with this command.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,94 +0,0 @@
|
|||||||
package com.massivecraft.factions.listeners;
|
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.PlayerChatEvent;
|
|
||||||
|
|
||||||
import com.massivecraft.factions.Conf;
|
|
||||||
import com.massivecraft.factions.FPlayer;
|
|
||||||
import com.massivecraft.factions.FPlayers;
|
|
||||||
import com.massivecraft.factions.Faction;
|
|
||||||
import com.massivecraft.factions.P;
|
|
||||||
import com.massivecraft.factions.struct.ChatMode;
|
|
||||||
import com.massivecraft.factions.struct.Rel;
|
|
||||||
|
|
||||||
|
|
||||||
// this is an addtional PlayerListener for handling slashless command usage and faction chat, to be set at low priority so Factions gets to them first
|
|
||||||
public class FactionsChatEarlyListener implements Listener
|
|
||||||
{
|
|
||||||
public P p;
|
|
||||||
public FactionsChatEarlyListener(P p)
|
|
||||||
{
|
|
||||||
this.p = p;
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
|
||||||
public void onPlayerChat(PlayerChatEvent event)
|
|
||||||
{
|
|
||||||
if (event.isCancelled()) return;
|
|
||||||
|
|
||||||
Player talkingPlayer = event.getPlayer();
|
|
||||||
String msg = event.getMessage();
|
|
||||||
|
|
||||||
FPlayer me = FPlayers.i.get(talkingPlayer);
|
|
||||||
ChatMode chat = me.getChatMode();
|
|
||||||
|
|
||||||
// slashless factions commands need to be handled here if the user isn't in public chat mode
|
|
||||||
if (chat != ChatMode.PUBLIC && p.handleCommand(event.getPlayer(), event.getMessage()))
|
|
||||||
{
|
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Is it a faction chat message?
|
|
||||||
if (chat == ChatMode.FACTION)
|
|
||||||
{
|
|
||||||
Faction myFaction = me.getFaction();
|
|
||||||
|
|
||||||
String message = String.format(Conf.factionChatFormat, me.describeTo(myFaction), msg);
|
|
||||||
myFaction.sendMessage(message);
|
|
||||||
|
|
||||||
P.p.log(Level.INFO, ChatColor.stripColor("FactionChat "+myFaction.getTag()+": "+message));
|
|
||||||
|
|
||||||
//Send to any players who are spying chat
|
|
||||||
for (FPlayer fplayer : FPlayers.i.getOnline())
|
|
||||||
{
|
|
||||||
if(fplayer.isSpyingChat() && fplayer.getFaction() != myFaction)
|
|
||||||
fplayer.sendMessage("[FCspy] "+myFaction.getTag()+": "+message);
|
|
||||||
}
|
|
||||||
|
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if (chat == ChatMode.ALLIANCE)
|
|
||||||
{
|
|
||||||
Faction myFaction = me.getFaction();
|
|
||||||
|
|
||||||
String message = String.format(Conf.allianceChatFormat, ChatColor.stripColor(me.getNameAndTag()), msg);
|
|
||||||
|
|
||||||
//Send message to our own faction
|
|
||||||
myFaction.sendMessage(message);
|
|
||||||
|
|
||||||
//Send to all our allies
|
|
||||||
for (FPlayer fplayer : FPlayers.i.getOnline())
|
|
||||||
{
|
|
||||||
if(myFaction.getRelationTo(fplayer) == Rel.ALLY)
|
|
||||||
fplayer.sendMessage(message);
|
|
||||||
|
|
||||||
//Send to any players who are spying chat
|
|
||||||
else if(fplayer.isSpyingChat())
|
|
||||||
fplayer.sendMessage("[ACspy]: " + message);
|
|
||||||
}
|
|
||||||
|
|
||||||
P.p.log(Level.INFO, ChatColor.stripColor("AllianceChat: "+message));
|
|
||||||
|
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,185 @@
|
|||||||
|
package com.massivecraft.factions.listeners;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.UnknownFormatConversionException;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerChatEvent;
|
||||||
|
|
||||||
|
import com.massivecraft.factions.Conf;
|
||||||
|
import com.massivecraft.factions.FPlayer;
|
||||||
|
import com.massivecraft.factions.FPlayers;
|
||||||
|
import com.massivecraft.factions.Faction;
|
||||||
|
import com.massivecraft.factions.P;
|
||||||
|
import com.massivecraft.factions.struct.ChatMode;
|
||||||
|
import com.massivecraft.factions.struct.Rel;
|
||||||
|
|
||||||
|
|
||||||
|
public class FactionsChatListener implements Listener
|
||||||
|
{
|
||||||
|
public P p;
|
||||||
|
public FactionsChatListener(P p)
|
||||||
|
{
|
||||||
|
this.p = p;
|
||||||
|
}
|
||||||
|
|
||||||
|
// this is for handling slashless command usage and faction/alliance chat, set at lowest priority so Factions gets to them first
|
||||||
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
|
public void onPlayerEarlyChat(PlayerChatEvent event)
|
||||||
|
{
|
||||||
|
if (event.isCancelled()) return;
|
||||||
|
|
||||||
|
Player talkingPlayer = event.getPlayer();
|
||||||
|
String msg = event.getMessage();
|
||||||
|
FPlayer me = FPlayers.i.get(talkingPlayer);
|
||||||
|
ChatMode chat = me.getChatMode();
|
||||||
|
|
||||||
|
// slashless factions commands need to be handled here if the user isn't in public chat mode
|
||||||
|
if (chat != ChatMode.PUBLIC && p.handleCommand(talkingPlayer, msg))
|
||||||
|
{
|
||||||
|
if (Conf.logPlayerCommands)
|
||||||
|
Bukkit.getLogger().log(Level.INFO, "[PLAYER_COMMAND] "+talkingPlayer.getName()+": "+msg);
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Is it a faction chat message?
|
||||||
|
if (chat == ChatMode.FACTION)
|
||||||
|
{
|
||||||
|
Faction myFaction = me.getFaction();
|
||||||
|
|
||||||
|
String message = String.format(Conf.factionChatFormat, me.describeTo(myFaction), msg);
|
||||||
|
myFaction.sendMessage(message);
|
||||||
|
|
||||||
|
Bukkit.getLogger().log(Level.INFO, ChatColor.stripColor("FactionChat "+myFaction.getTag()+": "+message));
|
||||||
|
|
||||||
|
//Send to any players who are spying chat
|
||||||
|
for (FPlayer fplayer : FPlayers.i.getOnline())
|
||||||
|
{
|
||||||
|
if(fplayer.isSpyingChat() && fplayer.getFaction() != myFaction)
|
||||||
|
fplayer.sendMessage("[FCspy] "+myFaction.getTag()+": "+message);
|
||||||
|
}
|
||||||
|
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (chat == ChatMode.ALLIANCE)
|
||||||
|
{
|
||||||
|
Faction myFaction = me.getFaction();
|
||||||
|
|
||||||
|
String message = String.format(Conf.allianceChatFormat, ChatColor.stripColor(me.getNameAndTag()), msg);
|
||||||
|
|
||||||
|
//Send message to our own faction
|
||||||
|
myFaction.sendMessage(message);
|
||||||
|
|
||||||
|
//Send to all our allies
|
||||||
|
for (FPlayer fplayer : FPlayers.i.getOnline())
|
||||||
|
{
|
||||||
|
if(myFaction.getRelationTo(fplayer) == Rel.ALLY)
|
||||||
|
fplayer.sendMessage(message);
|
||||||
|
|
||||||
|
//Send to any players who are spying chat
|
||||||
|
else if(fplayer.isSpyingChat())
|
||||||
|
fplayer.sendMessage("[ACspy]: " + message);
|
||||||
|
}
|
||||||
|
|
||||||
|
Bukkit.getLogger().log(Level.INFO, ChatColor.stripColor("AllianceChat: "+message));
|
||||||
|
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// this is for handling insertion of the player's faction tag, set at highest priority to give other plugins a chance to modify chat first
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public void onPlayerChat(PlayerChatEvent event)
|
||||||
|
{
|
||||||
|
if (event.isCancelled()) return;
|
||||||
|
|
||||||
|
// Are we to insert the Faction tag into the format?
|
||||||
|
// If we are not to insert it - we are done.
|
||||||
|
if ( ! Conf.chatTagEnabled || Conf.chatTagHandledByAnotherPlugin) return;
|
||||||
|
|
||||||
|
Player talkingPlayer = event.getPlayer();
|
||||||
|
String msg = event.getMessage();
|
||||||
|
String eventFormat = event.getFormat();
|
||||||
|
FPlayer me = FPlayers.i.get(talkingPlayer);
|
||||||
|
int InsertIndex = 0;
|
||||||
|
|
||||||
|
if (!Conf.chatTagReplaceString.isEmpty() && eventFormat.contains(Conf.chatTagReplaceString))
|
||||||
|
{
|
||||||
|
// we're using the "replace" method of inserting the faction tags
|
||||||
|
// if they stuck "[FACTION_TITLE]" in there, go ahead and do it too
|
||||||
|
if (eventFormat.contains("[FACTION_TITLE]"))
|
||||||
|
{
|
||||||
|
eventFormat = eventFormat.replace("[FACTION_TITLE]", me.getTitle());
|
||||||
|
}
|
||||||
|
InsertIndex = eventFormat.indexOf(Conf.chatTagReplaceString);
|
||||||
|
eventFormat = eventFormat.replace(Conf.chatTagReplaceString, "");
|
||||||
|
Conf.chatTagPadAfter = false;
|
||||||
|
Conf.chatTagPadBefore = false;
|
||||||
|
}
|
||||||
|
else if (!Conf.chatTagInsertAfterString.isEmpty() && eventFormat.contains(Conf.chatTagInsertAfterString))
|
||||||
|
{
|
||||||
|
// we're using the "insert after string" method
|
||||||
|
InsertIndex = eventFormat.indexOf(Conf.chatTagInsertAfterString) + Conf.chatTagInsertAfterString.length();
|
||||||
|
}
|
||||||
|
else if (!Conf.chatTagInsertBeforeString.isEmpty() && eventFormat.contains(Conf.chatTagInsertBeforeString))
|
||||||
|
{
|
||||||
|
// we're using the "insert before string" method
|
||||||
|
InsertIndex = eventFormat.indexOf(Conf.chatTagInsertBeforeString);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// we'll fall back to using the index place method
|
||||||
|
InsertIndex = Conf.chatTagInsertIndex;
|
||||||
|
if (InsertIndex > eventFormat.length())
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String formatStart = eventFormat.substring(0, InsertIndex) + ((Conf.chatTagPadBefore && !me.getChatTag().isEmpty()) ? " " : "");
|
||||||
|
String formatEnd = ((Conf.chatTagPadAfter && !me.getChatTag().isEmpty()) ? " " : "") + eventFormat.substring(InsertIndex);
|
||||||
|
|
||||||
|
String nonColoredMsgFormat = formatStart + me.getChatTag().trim() + formatEnd;
|
||||||
|
|
||||||
|
// Relation Colored?
|
||||||
|
if (Conf.chatTagRelationColored)
|
||||||
|
{
|
||||||
|
// We must choke the standard message and send out individual messages to all players
|
||||||
|
// Why? Because the relations will differ.
|
||||||
|
event.setCancelled(true);
|
||||||
|
|
||||||
|
for (Player listeningPlayer : event.getRecipients())
|
||||||
|
{
|
||||||
|
FPlayer you = FPlayers.i.get(listeningPlayer);
|
||||||
|
String yourFormat = formatStart + me.getChatTag(you).trim() + formatEnd;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
listeningPlayer.sendMessage(String.format(yourFormat, talkingPlayer.getDisplayName(), msg));
|
||||||
|
}
|
||||||
|
catch (UnknownFormatConversionException ex)
|
||||||
|
{
|
||||||
|
Conf.chatTagInsertIndex = 0;
|
||||||
|
P.p.log(Level.SEVERE, "Critical error in chat message formatting!");
|
||||||
|
P.p.log(Level.SEVERE, "NOTE: This has been automatically fixed right now by setting chatTagInsertIndex to 0.");
|
||||||
|
P.p.log(Level.SEVERE, "For a more proper fix, please read this regarding chat configuration: http://massivecraft.com/plugins/factions/config#Chat_configuration");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write to the log... We will write the non colored message.
|
||||||
|
String nonColoredMsg = ChatColor.stripColor(String.format(nonColoredMsgFormat, talkingPlayer.getDisplayName(), msg));
|
||||||
|
Bukkit.getLogger().log(Level.INFO, nonColoredMsg);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// No relation color.
|
||||||
|
event.setFormat(nonColoredMsgFormat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,7 @@
|
|||||||
package com.massivecraft.factions.listeners;
|
package com.massivecraft.factions.listeners;
|
||||||
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.UnknownFormatConversionException;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
@ -16,7 +13,6 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.player.PlayerBucketEmptyEvent;
|
import org.bukkit.event.player.PlayerBucketEmptyEvent;
|
||||||
import org.bukkit.event.player.PlayerBucketFillEvent;
|
import org.bukkit.event.player.PlayerBucketFillEvent;
|
||||||
import org.bukkit.event.player.PlayerChatEvent;
|
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerKickEvent;
|
import org.bukkit.event.player.PlayerKickEvent;
|
||||||
@ -48,100 +44,7 @@ public class FactionsPlayerListener implements Listener
|
|||||||
{
|
{
|
||||||
this.p = p;
|
this.p = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
|
||||||
public void onPlayerChat(PlayerChatEvent event)
|
|
||||||
{
|
|
||||||
if (event.isCancelled()) return;
|
|
||||||
|
|
||||||
Player talkingPlayer = event.getPlayer();
|
|
||||||
String msg = event.getMessage();
|
|
||||||
|
|
||||||
// ... it was not a command. This means that it is a chat message!
|
|
||||||
FPlayer me = FPlayers.i.get(talkingPlayer);
|
|
||||||
|
|
||||||
// Are we to insert the Faction tag into the format?
|
|
||||||
// If we are not to insert it - we are done.
|
|
||||||
if ( ! Conf.chatTagEnabled || Conf.chatTagHandledByAnotherPlugin)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int InsertIndex = 0;
|
|
||||||
String eventFormat = event.getFormat();
|
|
||||||
|
|
||||||
if (!Conf.chatTagReplaceString.isEmpty() && eventFormat.contains(Conf.chatTagReplaceString))
|
|
||||||
{
|
|
||||||
// we're using the "replace" method of inserting the faction tags
|
|
||||||
// if they stuck "[FACTION_TITLE]" in there, go ahead and do it too
|
|
||||||
if (eventFormat.contains("[FACTION_TITLE]"))
|
|
||||||
{
|
|
||||||
eventFormat = eventFormat.replace("[FACTION_TITLE]", me.getTitle());
|
|
||||||
}
|
|
||||||
InsertIndex = eventFormat.indexOf(Conf.chatTagReplaceString);
|
|
||||||
eventFormat = eventFormat.replace(Conf.chatTagReplaceString, "");
|
|
||||||
Conf.chatTagPadAfter = false;
|
|
||||||
Conf.chatTagPadBefore = false;
|
|
||||||
}
|
|
||||||
else if (!Conf.chatTagInsertAfterString.isEmpty() && eventFormat.contains(Conf.chatTagInsertAfterString))
|
|
||||||
{
|
|
||||||
// we're using the "insert after string" method
|
|
||||||
InsertIndex = eventFormat.indexOf(Conf.chatTagInsertAfterString) + Conf.chatTagInsertAfterString.length();
|
|
||||||
}
|
|
||||||
else if (!Conf.chatTagInsertBeforeString.isEmpty() && eventFormat.contains(Conf.chatTagInsertBeforeString))
|
|
||||||
{
|
|
||||||
// we're using the "insert before string" method
|
|
||||||
InsertIndex = eventFormat.indexOf(Conf.chatTagInsertBeforeString);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// we'll fall back to using the index place method
|
|
||||||
InsertIndex = Conf.chatTagInsertIndex;
|
|
||||||
if (InsertIndex > eventFormat.length())
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String formatStart = eventFormat.substring(0, InsertIndex) + ((Conf.chatTagPadBefore && !me.getChatTag().isEmpty()) ? " " : "");
|
|
||||||
String formatEnd = ((Conf.chatTagPadAfter && !me.getChatTag().isEmpty()) ? " " : "") + eventFormat.substring(InsertIndex);
|
|
||||||
|
|
||||||
String nonColoredMsgFormat = formatStart + me.getChatTag().trim() + formatEnd;
|
|
||||||
|
|
||||||
// Relation Colored?
|
|
||||||
if (Conf.chatTagRelationColored)
|
|
||||||
{
|
|
||||||
// We must choke the standard message and send out individual messages to all players
|
|
||||||
// Why? Because the relations will differ.
|
|
||||||
event.setCancelled(true);
|
|
||||||
|
|
||||||
for (Player listeningPlayer : event.getRecipients())
|
|
||||||
{
|
|
||||||
FPlayer you = FPlayers.i.get(listeningPlayer);
|
|
||||||
String yourFormat = formatStart + me.getChatTag(you).trim() + formatEnd;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
listeningPlayer.sendMessage(String.format(yourFormat, talkingPlayer.getDisplayName(), msg));
|
|
||||||
}
|
|
||||||
catch (UnknownFormatConversionException ex)
|
|
||||||
{
|
|
||||||
Conf.chatTagInsertIndex = 0;
|
|
||||||
P.p.log(Level.SEVERE, "Critical error in chat message formatting!");
|
|
||||||
P.p.log(Level.SEVERE, "NOTE: This has been automatically fixed right now by setting chatTagInsertIndex to 0.");
|
|
||||||
P.p.log(Level.SEVERE, "For a more proper fix, please read this regarding chat configuration: http://massivecraft.com/plugins/factions/config#Chat_configuration");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write to the log... We will write the non colored message.
|
|
||||||
String nonColoredMsg = ChatColor.stripColor(String.format(nonColoredMsgFormat, talkingPlayer.getDisplayName(), msg));
|
|
||||||
Logger.getLogger("Minecraft").info(nonColoredMsg);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// No relation color.
|
|
||||||
event.setFormat(nonColoredMsgFormat);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL)
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
public void onPlayerJoin(PlayerJoinEvent event)
|
||||||
{
|
{
|
||||||
|
@ -5,7 +5,6 @@ import java.lang.reflect.Type;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -37,6 +36,7 @@ public abstract class MPlugin extends JavaPlugin
|
|||||||
protected boolean loadSuccessful = false;
|
protected boolean loadSuccessful = false;
|
||||||
public boolean getAutoSave() {return this.autoSave;}
|
public boolean getAutoSave() {return this.autoSave;}
|
||||||
public void setAutoSave(boolean val) {this.autoSave = val;}
|
public void setAutoSave(boolean val) {this.autoSave = val;}
|
||||||
|
public String refCommand = "";
|
||||||
|
|
||||||
// Listeners
|
// Listeners
|
||||||
private MPluginSecretPlayerListener mPluginSecretPlayerListener;
|
private MPluginSecretPlayerListener mPluginSecretPlayerListener;
|
||||||
@ -62,13 +62,24 @@ public abstract class MPlugin extends JavaPlugin
|
|||||||
this.perm = new PermUtil(this);
|
this.perm = new PermUtil(this);
|
||||||
this.persist = new Persist(this);
|
this.persist = new Persist(this);
|
||||||
this.lib = new LibLoader(this);
|
this.lib = new LibLoader(this);
|
||||||
|
|
||||||
if ( ! lib.require("gson.jar", "http://search.maven.org/remotecontent?filepath=com/google/code/gson/gson/2.1/gson-2.1.jar")) return false;
|
// GSON 2.1 is now embedded in CraftBukkit, used by the auto-updater: https://github.com/Bukkit/CraftBukkit/commit/0ed1d1fdbb1e0bc09a70bc7bfdf40c1de8411665
|
||||||
|
// if ( ! lib.require("gson.jar", "http://search.maven.org/remotecontent?filepath=com/google/code/gson/gson/2.1/gson-2.1.jar")) return false;
|
||||||
this.gson = this.getGsonBuilder().create();
|
this.gson = this.getGsonBuilder().create();
|
||||||
|
|
||||||
this.txt = new TextUtil();
|
this.txt = new TextUtil();
|
||||||
initTXT();
|
initTXT();
|
||||||
|
|
||||||
|
// attempt to get first command defined in plugin.yml as reference command, if any commands are defined in there
|
||||||
|
// reference command will be used to prevent "unknown command" console messages
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Map<String, Map<String, Object>> refCmd = this.getDescription().getCommands();
|
||||||
|
if (refCmd != null && !refCmd.isEmpty())
|
||||||
|
this.refCommand = (String)(refCmd.keySet().toArray()[0]);
|
||||||
|
}
|
||||||
|
catch (ClassCastException ex) {}
|
||||||
|
|
||||||
// Create and register listeners
|
// Create and register listeners
|
||||||
this.mPluginSecretPlayerListener = new MPluginSecretPlayerListener(this);
|
this.mPluginSecretPlayerListener = new MPluginSecretPlayerListener(this);
|
||||||
this.mPluginSecretServerListener = new MPluginSecretServerListener(this);
|
this.mPluginSecretServerListener = new MPluginSecretServerListener(this);
|
||||||
@ -167,6 +178,12 @@ public abstract class MPlugin extends JavaPlugin
|
|||||||
// COMMAND HANDLING
|
// COMMAND HANDLING
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
// can be overridden by P method, to provide option
|
||||||
|
public boolean logPlayerCommands()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean handleCommand(CommandSender sender, String commandString, boolean testOnly)
|
public boolean handleCommand(CommandSender sender, String commandString, boolean testOnly)
|
||||||
{
|
{
|
||||||
boolean noSlash = true;
|
boolean noSlash = true;
|
||||||
@ -233,6 +250,6 @@ public abstract class MPlugin extends JavaPlugin
|
|||||||
|
|
||||||
public void log(Level level, Object msg)
|
public void log(Level level, Object msg)
|
||||||
{
|
{
|
||||||
Logger.getLogger("Minecraft").log(level, "["+this.getDescription().getFullName()+"] "+msg);
|
Bukkit.getLogger().log(level, "["+this.getDescription().getFullName()+"] "+msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,8 @@ public class MPluginSecretPlayerListener implements Listener
|
|||||||
|
|
||||||
if (p.handleCommand(event.getPlayer(), event.getMessage()))
|
if (p.handleCommand(event.getPlayer(), event.getMessage()))
|
||||||
{
|
{
|
||||||
Bukkit.getLogger().info("[PLAYER_COMMAND] "+event.getPlayer().getName()+": "+event.getMessage());
|
if (p.logPlayerCommands())
|
||||||
|
Bukkit.getLogger().info("[PLAYER_COMMAND] "+event.getPlayer().getName()+": "+event.getMessage());
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -40,7 +41,8 @@ public class MPluginSecretPlayerListener implements Listener
|
|||||||
|
|
||||||
if (p.handleCommand(event.getPlayer(), event.getMessage()))
|
if (p.handleCommand(event.getPlayer(), event.getMessage()))
|
||||||
{
|
{
|
||||||
Bukkit.getLogger().info("[PLAYER_COMMAND] "+event.getPlayer().getName()+": "+event.getMessage());
|
if (p.logPlayerCommands())
|
||||||
|
Bukkit.getLogger().info("[PLAYER_COMMAND] "+event.getPlayer().getName()+": "+event.getMessage());
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package com.massivecraft.factions.zcore;
|
package com.massivecraft.factions.zcore;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
@ -10,22 +8,10 @@ import org.bukkit.event.server.ServerCommandEvent;
|
|||||||
public class MPluginSecretServerListener implements Listener
|
public class MPluginSecretServerListener implements Listener
|
||||||
{
|
{
|
||||||
private MPlugin p;
|
private MPlugin p;
|
||||||
private String refCommand;
|
|
||||||
|
|
||||||
public MPluginSecretServerListener(MPlugin p)
|
public MPluginSecretServerListener(MPlugin p)
|
||||||
{
|
{
|
||||||
this.p = p;
|
this.p = p;
|
||||||
refCommand = "";
|
|
||||||
|
|
||||||
// attempt to get first command defined in plugin.yml as reference command, if any commands are defined in there
|
|
||||||
// reference command will be used to prevent "unknown command" console messages
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Map<String, Map<String, Object>> refCmd = p.getDescription().getCommands();
|
|
||||||
if (refCmd != null && !refCmd.isEmpty())
|
|
||||||
refCommand = (String)(refCmd.keySet().toArray()[0]);
|
|
||||||
}
|
|
||||||
catch (ClassCastException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
@ -35,7 +21,7 @@ public class MPluginSecretServerListener implements Listener
|
|||||||
|
|
||||||
if (p.handleCommand(event.getSender(), event.getCommand()))
|
if (p.handleCommand(event.getSender(), event.getCommand()))
|
||||||
{
|
{
|
||||||
event.setCommand(refCommand);
|
event.setCommand(p.refCommand);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user