mirror of
https://github.com/MassiveCraft/Factions.git
synced 2024-11-23 02:35:22 +01:00
Support for the CAPI plugin.
This commit is contained in:
parent
3967579884
commit
00f6f4ab05
BIN
lib/capi.jar
Normal file
BIN
lib/capi.jar
Normal file
Binary file not shown.
@ -2,7 +2,7 @@ name: Factions
|
||||
version: 1.6.0_dev
|
||||
main: com.massivecraft.factions.P
|
||||
authors: [Olof Larsson, Brett Flannigan]
|
||||
softdepend: [PermissionsEx, Permissions, Essentials, EssentialsChat, HeroChat, iChat, LocalAreaChat, nChat, ChatManager, AuthMe, Register, Spout, WorldEdit, WorldGuard]
|
||||
softdepend: [PermissionsEx, Permissions, Essentials, EssentialsChat, HeroChat, iChat, LocalAreaChat, nChat, ChatManager, CAPI, AuthMe, Register, Spout, WorldEdit, WorldGuard]
|
||||
permissions:
|
||||
factions.kit.admin:
|
||||
description: All faction permissions.
|
||||
|
@ -15,13 +15,6 @@ public class Conf
|
||||
public static ChatColor colorAlly = ChatColor.LIGHT_PURPLE;
|
||||
public static ChatColor colorNeutral = ChatColor.WHITE;
|
||||
public static ChatColor colorEnemy = ChatColor.RED;
|
||||
/*
|
||||
public static ChatColor colorSystem = ChatColor.YELLOW;
|
||||
public static ChatColor colorChrome = ChatColor.GOLD;
|
||||
public static ChatColor colorCommand = ChatColor.AQUA;
|
||||
public static ChatColor colorParameter = ChatColor.DARK_AQUA;
|
||||
|
||||
*/
|
||||
|
||||
// Power
|
||||
public static double powerPlayerMax = 10.0;
|
||||
|
@ -33,6 +33,7 @@ import com.earth2me.essentials.chat.EssentialsChat;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.massivecraft.factions.integration.EssentialsFeatures;
|
||||
import com.massivecraft.factions.integration.capi.CapiFeatures;
|
||||
|
||||
public class P extends MPlugin
|
||||
{
|
||||
@ -92,6 +93,7 @@ public class P extends MPlugin
|
||||
setupSpout(this);
|
||||
Econ.doSetup();
|
||||
Econ.oldMoneyDoTransfer();
|
||||
CapiFeatures.setup();
|
||||
|
||||
if(Conf.worldGuardChecking)
|
||||
{
|
||||
|
@ -0,0 +1,21 @@
|
||||
package com.massivecraft.factions.integration.capi;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.Event.Priority;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.massivecraft.factions.P;
|
||||
|
||||
public class CapiFeatures
|
||||
{
|
||||
public static void setup()
|
||||
{
|
||||
Plugin plug = Bukkit.getServer().getPluginManager().getPlugin("CAPI");
|
||||
if (plug != null && plug.getClass().getName().equals("com.massivecraft.capi.CAPI"))
|
||||
{
|
||||
P.p.log("Integration with the CAPI plugin was successful");
|
||||
P.p.registerEvent(Event.Type.CUSTOM_EVENT, new PluginCapiListener(P.p), Priority.Normal);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,115 @@
|
||||
package com.massivecraft.factions.integration.capi;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.massivecraft.capi.Channel;
|
||||
import com.massivecraft.capi.Channels;
|
||||
import com.massivecraft.capi.events.CAPIListChannelsEvent;
|
||||
import com.massivecraft.capi.events.CAPIMessageToChannelEvent;
|
||||
import com.massivecraft.capi.events.CAPIMessageToPlayerEvent;
|
||||
import com.massivecraft.capi.events.CAPISelectChannelEvent;
|
||||
import com.massivecraft.capi.listeners.CapiListener;
|
||||
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.Relation;
|
||||
|
||||
public class PluginCapiListener extends CapiListener
|
||||
{
|
||||
P p;
|
||||
|
||||
Set<String> myChannelIds = new LinkedHashSet<String>();
|
||||
|
||||
public PluginCapiListener(P p)
|
||||
{
|
||||
this.p = p;
|
||||
|
||||
myChannelIds.add("faction");
|
||||
myChannelIds.add("allies");
|
||||
}
|
||||
|
||||
private String replacePlayerTags(String format, FPlayer me, FPlayer you)
|
||||
{
|
||||
String meFactionTag = me.getChatTag(you);
|
||||
format = format.replace("{ME_FACTIONTAG}", meFactionTag.length() == 0 ? "" : meFactionTag);
|
||||
format = format.replace("{ME_FACTIONTAG_PADR}", meFactionTag.length() == 0 ? "" : meFactionTag+" ");
|
||||
format = format.replace("{ME_FACTIONTAG_PADL}", meFactionTag.length() == 0 ? "" : " "+meFactionTag);
|
||||
format = format.replace("{ME_FACTIONTAG_PADB}", meFactionTag.length() == 0 ? "" : " "+meFactionTag+" ");
|
||||
|
||||
String youFactionTag = you.getChatTag(me);
|
||||
format = format.replace("{YOU_FACTIONTAG}", youFactionTag.length() == 0 ? "" : youFactionTag);
|
||||
format = format.replace("{YOU_FACTIONTAG_PADR}", youFactionTag.length() == 0 ? "" : youFactionTag+" ");
|
||||
format = format.replace("{YOU_FACTIONTAG_PADL}", youFactionTag.length() == 0 ? "" : " "+youFactionTag);
|
||||
format = format.replace("{YOU_FACTIONTAG_PADB}", youFactionTag.length() == 0 ? "" : " "+youFactionTag+" ");
|
||||
|
||||
return format;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListChannelsEvent(CAPIListChannelsEvent event)
|
||||
{
|
||||
for (Channel c : Channels.i.get())
|
||||
{
|
||||
if (myChannelIds.contains(c.getId()))
|
||||
{
|
||||
event.getChannels().add(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageToChannel(CAPIMessageToChannelEvent event)
|
||||
{
|
||||
if (event.isCancelled()) return;
|
||||
if ( ! myChannelIds.contains(event.getChannel().getId())) return;
|
||||
|
||||
Player me = event.getMe();
|
||||
FPlayer fme = FPlayers.i.get(me);
|
||||
Faction myFaction = fme.getFaction();
|
||||
|
||||
if (event.getChannel().getId().equals("faction") && myFaction.isNormal())
|
||||
{
|
||||
event.getThem().addAll(myFaction.getOnlinePlayers());
|
||||
}
|
||||
else if (event.getChannel().getId().equals("allies"))
|
||||
{
|
||||
for (Player somePlayer : Bukkit.getServer().getOnlinePlayers())
|
||||
{
|
||||
FPlayer someFPlayer = FPlayers.i.get(somePlayer);
|
||||
if (someFPlayer.getRelationTo(fme).value >= Relation.ALLY.value)
|
||||
{
|
||||
event.getThem().add(somePlayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageToPlayer(CAPIMessageToPlayerEvent event)
|
||||
{
|
||||
if (event.isCancelled()) return;
|
||||
event.setFormat(this.replacePlayerTags(event.getFormat(), FPlayers.i.get(event.getMe()), FPlayers.i.get(event.getYou())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSelectChannel(CAPISelectChannelEvent event)
|
||||
{
|
||||
if (event.isCancelled()) return;
|
||||
String channelId = event.getChannel().getId();
|
||||
if ( ! myChannelIds.contains(channelId)) return;
|
||||
|
||||
Player me = event.getMe();
|
||||
FPlayer fme = FPlayers.i.get(me);
|
||||
|
||||
if ( ! fme.hasFaction())
|
||||
{
|
||||
event.setFailMessage(p.txt.parse("<b>You must be member in a faction to use this channel."));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
@ -180,10 +180,10 @@ public abstract class MPlugin extends JavaPlugin
|
||||
|
||||
public boolean handleCommand(CommandSender sender, String commandString, boolean testOnly)
|
||||
{
|
||||
boolean noSlash = false;
|
||||
boolean noSlash = true;
|
||||
if (commandString.startsWith("/"))
|
||||
{
|
||||
noSlash = true;
|
||||
noSlash = false;
|
||||
commandString = commandString.substring(1);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user