Remove Maven

This commit is contained in:
Olof Larsson
2015-01-19 09:58:25 +01:00
parent 5e4a42d2ac
commit c81d7d8794
177 changed files with 42 additions and 70 deletions

View File

@@ -0,0 +1,276 @@
package com.massivecraft.factions.integration;
import java.util.HashSet;
import java.util.Set;
import com.massivecraft.factions.EconomyParticipator;
import com.massivecraft.factions.entity.MConf;
import com.massivecraft.factions.entity.MPerm;
import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.util.RelationUtil;
import com.massivecraft.massivecore.money.Money;
public class Econ
{
// -------------------------------------------- //
// STATE
// -------------------------------------------- //
public static boolean isEnabled()
{
return MConf.get().econEnabled && Money.enabled();
}
// -------------------------------------------- //
// UTIL
// -------------------------------------------- //
public static boolean payForAction(double cost, MPlayer usender, String actionDescription)
{
if (!isEnabled()) return true;
if (cost == 0D) return true;
if (usender.isUsingAdminMode()) return true;
Faction usenderFaction = usender.getFaction();
if (MConf.get().bankEnabled && MConf.get().bankFactionPaysCosts && usenderFaction.isNormal())
{
return modifyMoney(usenderFaction, -cost, actionDescription);
}
else
{
return modifyMoney(usender, -cost, actionDescription);
}
}
// -------------------------------------------- //
// ASSORTED
// -------------------------------------------- //
public static void modifyUniverseMoney(Object universe, double delta)
{
if ( ! isEnabled()) return;
if (MConf.get().econUniverseAccount == null) return;
if (MConf.get().econUniverseAccount.length() == 0) return;
if ( ! Money.exists(MConf.get().econUniverseAccount)) return;
Money.spawn(MConf.get().econUniverseAccount, null, delta);
}
public static void sendBalanceInfo(MPlayer to, EconomyParticipator about)
{
to.msg("<a>%s's<i> balance is <h>%s<i>.", about.describeTo(to, true), Money.format(Money.get(about)));
}
public static boolean isMePermittedYou(EconomyParticipator me, EconomyParticipator you, MPerm mperm)
{
// Null means special system invocation and is always to be accepted.
if (me == null) return true;
// Always accept when in admin mode.
if (me instanceof MPlayer && ((MPlayer)me).isUsingAdminMode()) return true;
// Always accept control of self
if (me == you) return true;
Faction fMe = RelationUtil.getFaction(me);
Faction fYou = RelationUtil.getFaction(you);
// A faction can always transfer away the money of it's members and its own money...
// This will however probably never happen as a faction does not have free will.
// Ohh by the way... Yes it could. For daily rent to the faction.
if (me == fMe && fMe == fYou) return true;
// Factions can be controlled by those that have permissions
if (you instanceof Faction)
{
if (me instanceof Faction && mperm.has((Faction)me, fYou)) return true;
if (me instanceof MPlayer && mperm.has((MPlayer)me, fYou, false)) return true;
}
// Otherwise you may not! ;,,;
return false;
}
public static boolean transferMoney(EconomyParticipator invoker, EconomyParticipator from, EconomyParticipator to, double amount)
{
return transferMoney(from, to, invoker, amount, true);
}
public static boolean transferMoney(EconomyParticipator from, EconomyParticipator to, EconomyParticipator by, double amount, boolean notify)
{
if ( ! isEnabled()) return false;
// The amount must be positive.
// If the amount is negative we must flip and multiply amount with -1.
if (amount < 0)
{
amount *= -1;
EconomyParticipator temp = from;
from = to;
to = temp;
}
// Check Permissions
if ( ! isMePermittedYou(by, from, MPerm.getPermWithdraw()))
{
by.msg("<h>%s<i> lack permission to withdraw money from <h>%s<i>.", by.describeTo(by, true), from.describeTo(by));
return false;
}
if ( ! isMePermittedYou(by, to, MPerm.getPermDeposit()))
{
by.msg("<h>%s<i> lack permission to deposit money to <h>%s<i>.", by.describeTo(by, true), to.describeTo(by));
return false;
}
// Is there enough money for the transaction to happen?
if (Money.get(from) < amount)
{
// There was not enough money to pay
if (by != null && notify)
{
by.msg("<h>%s<b> can't afford to transfer <h>%s<b> to %s<b>.", from.describeTo(by, true), Money.format(amount), to.describeTo(by));
}
return false;
}
// Transfer money
if (Money.move(from, to, by, amount, "Factions"))
{
if (notify)
{
sendTransferInfo(by, from, to, amount);
}
return true;
}
else
{
// if we get here something with the transaction failed
if (by != null && notify)
{
by.msg("Unable to transfer %s<b> to <h>%s<b> from <h>%s<b>.", Money.format(amount), to.describeTo(by), from.describeTo(by, true));
}
return false;
}
}
public static Set<MPlayer> getMPlayers(EconomyParticipator ep)
{
Set<MPlayer> mplayers = new HashSet<MPlayer>();
if (ep == null)
{
// Add nothing
}
else if (ep instanceof MPlayer)
{
mplayers.add((MPlayer)ep);
}
else if (ep instanceof Faction)
{
mplayers.addAll(((Faction)ep).getMPlayers());
}
return mplayers;
}
public static void sendTransferInfo(EconomyParticipator invoker, EconomyParticipator from, EconomyParticipator to, double amount)
{
Set<MPlayer> recipients = new HashSet<MPlayer>();
recipients.addAll(getMPlayers(invoker));
recipients.addAll(getMPlayers(from));
recipients.addAll(getMPlayers(to));
if (invoker == null)
{
for (MPlayer recipient : recipients)
{
recipient.msg("<h>%s<i> was transfered from <h>%s<i> to <h>%s<i>.", Money.format(amount), from.describeTo(recipient), to.describeTo(recipient));
}
}
else if (invoker == from)
{
for (MPlayer recipient : recipients)
{
recipient.msg("<h>%s<i> <h>gave %s<i> to <h>%s<i>.", from.describeTo(recipient, true), Money.format(amount), to.describeTo(recipient));
}
}
else if (invoker == to)
{
for (MPlayer recipient : recipients)
{
recipient.msg("<h>%s<i> <h>took %s<i> from <h>%s<i>.", to.describeTo(recipient, true), Money.format(amount), from.describeTo(recipient));
}
}
else
{
for (MPlayer recipient : recipients)
{
recipient.msg("<h>%s<i> transfered <h>%s<i> from <h>%s<i> to <h>%s<i>.", invoker.describeTo(recipient, true), Money.format(amount), from.describeTo(recipient), to.describeTo(recipient));
}
}
}
public static boolean hasAtLeast(EconomyParticipator ep, double delta, String toDoThis)
{
if ( ! isEnabled()) return true;
if (Money.get(ep) < delta)
{
if (toDoThis != null && !toDoThis.isEmpty())
{
ep.msg("<h>%s<i> can't afford <h>%s<i> %s.", ep.describeTo(ep, true), Money.format(delta), toDoThis);
}
return false;
}
return true;
}
public static boolean modifyMoney(EconomyParticipator ep, double delta, String actionDescription)
{
if ( ! isEnabled()) return false;
if (delta == 0) return true;
String You = ep.describeTo(ep, true);
boolean hasActionDesctription = (actionDescription != null && !actionDescription.isEmpty());
if (Money.spawn(ep, null, delta, "Factions"))
{
modifyUniverseMoney(ep, -delta);
if (hasActionDesctription)
{
if (delta > 0)
{
ep.msg("<h>%s<i> gained <h>%s<i> since did %s.", You, Money.format(delta), actionDescription);
}
else
{
ep.msg("<h>%s<i> lost <h>%s<i> since did %s.", You, Money.format(-delta), actionDescription);
}
}
return true;
}
else
{
if (hasActionDesctription)
{
if (delta > 0)
{
ep.msg("<h>%s<i> would have gained <h>%s<i> since did %s, but the deposit failed.", You, Money.format(delta), actionDescription);
}
else
{
ep.msg("<h>%s<i> can't afford <h>%s<i> to %s.", You, Money.format(-delta), actionDescription);
}
}
return false;
}
}
}

View File

@@ -0,0 +1,370 @@
package com.massivecraft.factions.integration.herochat;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.milkbowl.vault.chat.Chat;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.entity.Player;
import com.dthielke.herochat.Channel;
import com.dthielke.herochat.ChannelChatEvent;
import com.dthielke.herochat.ChannelStorage;
import com.dthielke.herochat.ChatCompleteEvent;
import com.dthielke.herochat.Chatter;
import com.dthielke.herochat.Herochat;
import com.dthielke.herochat.MessageFormatSupplier;
import com.dthielke.herochat.MessageNotFoundException;
import com.massivecraft.factions.Rel;
import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.massivecore.util.MUtil;
public abstract class ChannelFactionsAbstract implements Channel
{
private static final Pattern msgPattern = Pattern.compile("(.*)<(.*)%1\\$s(.*)> %2\\$s");
private final ChannelStorage storage = Herochat.getChannelManager().getStorage();
private final MessageFormatSupplier formatSupplier = Herochat.getChannelManager();
@Override
public boolean addMember(Chatter chatter, boolean announce, boolean flagUpdate)
{
if (chatter.hasChannel(this)) return false;
if ((announce) && (this.isVerbose()))
{
try
{
this.announce(Herochat.getMessage("channel_join").replace("$1", chatter.getPlayer().getDisplayName()));
}
catch (MessageNotFoundException e)
{
Herochat.severe("Messages.properties is missing: channel_join");
}
}
chatter.addChannel(this, announce, flagUpdate);
return true;
}
@Override
public boolean kickMember(Chatter chatter, boolean announce)
{
if (!chatter.hasChannel(this)) return false;
this.removeMember(chatter, false, true);
if (announce)
{
try
{
announce(Herochat.getMessage("channel_kick").replace("$1", chatter.getPlayer().getDisplayName()));
}
catch (MessageNotFoundException e)
{
Herochat.severe("Messages.properties is missing: channel_kick");
}
}
return true;
}
@Override
public boolean removeMember(Chatter chatter, boolean announce, boolean flagUpdate)
{
if (!chatter.hasChannel(this)) return false;
chatter.removeChannel(this, announce, flagUpdate);
if (announce && this.isVerbose())
{
try
{
this.announce(Herochat.getMessage("channel_leave").replace("$1", chatter.getPlayer().getDisplayName()));
}
catch (MessageNotFoundException e)
{
Herochat.severe("Messages.properties is missing: channel_leave");
}
}
return true;
}
@Override
public Set<Chatter> getMembers()
{
Set<Chatter> ret = new HashSet<Chatter>();
for (Chatter chatter : Herochat.getChatterManager().getChatters())
{
if(chatter.hasChannel(this)) ret.add(chatter);
}
return ret;
}
@Override
public void announce(String message)
{
String colorized = message.replaceAll("(?i)&([a-fklmno0-9])", "§$1");
message = applyFormat(this.getFormatSupplier().getAnnounceFormat(), "").replace("%2$s", colorized);
for (Chatter member : this.getMembers())
{
member.getPlayer().sendMessage(message);
}
Herochat.logChat(ChatColor.stripColor(message));
}
@Override
public String applyFormat(String format, String originalFormat)
{
format = format.replace("{default}", this.getFormatSupplier().getStandardFormat());
format = format.replace("{name}", this.getName());
format = format.replace("{nick}", this.getNick());
format = format.replace("{color}", this.getColor().toString());
format = format.replace("{msg}", "%2$s");
Matcher matcher = msgPattern.matcher(originalFormat);
if (matcher.matches() && matcher.groupCount() == 3)
{
format = format.replace("{sender}", matcher.group(1) + matcher.group(2) + "%1$s" + matcher.group(3));
}
else
{
format = format.replace("{sender}", "%1$s");
}
format = format.replaceAll("(?i)&([a-fklmnor0-9])", "§$1");
return format;
}
@Override
public String applyFormat(String format, String originalFormat, Player sender)
{
format = this.applyFormat(format, originalFormat);
format = format.replace("{plainsender}", sender.getName());
format = format.replace("{world}", sender.getWorld().getName());
Chat chat = Herochat.getChatService();
if (chat != null)
{
try
{
String prefix = chat.getPlayerPrefix(sender);
if (prefix == null || prefix == "")
{
prefix = chat.getPlayerPrefix((String)null, sender.getName());
}
String suffix = chat.getPlayerSuffix(sender);
if (suffix == null || suffix == "")
{
suffix = chat.getPlayerSuffix((String)null, sender.getName());
}
String group = chat.getPrimaryGroup(sender);
String groupPrefix = group == null ? "" : chat.getGroupPrefix(sender.getWorld(), group);
if (group != null && (groupPrefix == null || groupPrefix == ""))
{
groupPrefix = chat.getGroupPrefix((String)null, group);
}
String groupSuffix = group == null ? "" : chat.getGroupSuffix(sender.getWorld(), group);
if (group != null && (groupSuffix == null || groupSuffix == ""))
{
groupSuffix = chat.getGroupSuffix((String)null, group);
}
format = format.replace("{prefix}", prefix == null ? "" : prefix.replace("%", "%%"));
format = format.replace("{suffix}", suffix == null ? "" : suffix.replace("%", "%%"));
format = format.replace("{group}", group == null ? "" : group.replace("%", "%%"));
format = format.replace("{groupprefix}", groupPrefix == null ? "" : groupPrefix.replace("%", "%%"));
format = format.replace("{groupsuffix}", groupSuffix == null ? "" : groupSuffix.replace("%", "%%"));
}
catch (UnsupportedOperationException ignored)
{
}
}
else
{
format = format.replace("{prefix}", "");
format = format.replace("{suffix}", "");
format = format.replace("{group}", "");
format = format.replace("{groupprefix}", "");
format = format.replace("{groupsuffix}", "");
}
format = format.replaceAll("(?i)&([a-fklmno0-9])", "§$1");
return format;
}
@Override
public void emote(Chatter sender, String message)
{
message = this.applyFormat(this.getFormatSupplier().getEmoteFormat(), "").replace("%2$s", message);
Set<Player> recipients = new HashSet<Player>();
for (Chatter member : this.getMembers())
{
recipients.add(member.getPlayer());
}
this.trimRecipients(recipients, sender);
for (Player recipient : recipients)
{
recipient.sendMessage(message);
}
}
@Override
public boolean isMuted(String name)
{
if (this.isMuted()) return true;
return this.getMutes().contains(name.toLowerCase());
}
public abstract Set<Rel> getTargetRelations();
public Set<Player> getRecipients(Player sender)
{
Set<Player> ret = new HashSet<Player>();
MPlayer fsender = MPlayer.get(sender);
Faction faction = fsender.getFaction();
for (Player player : MUtil.getOnlinePlayers())
{
MPlayer frecipient = MPlayer.get(player);
if (!this.getTargetRelations().contains(faction.getRelationTo(frecipient))) continue;
ret.add(player);
}
return ret;
}
@Override
public void processChat(ChannelChatEvent event)
{
Player player = event.getSender().getPlayer();
String format = this.applyFormat(event.getFormat(), event.getBukkitFormat(), player);
Chatter sender = Herochat.getChatterManager().getChatter(player);
// NOTE: This line is not standard deobfuscation. It's altered to achieve the recipient limitations.
Set<Player> recipients = this.getRecipients(player);
this.trimRecipients(recipients, sender);
String msg = String.format(format, new Object[] { player.getDisplayName(), event.getMessage() });
for (Player recipient : recipients)
{
recipient.sendMessage(msg);
}
Bukkit.getPluginManager().callEvent(new ChatCompleteEvent(sender, this, msg));
Herochat.logChat(msg);
}
public boolean isMessageHeard(Set<Player> recipients, Chatter sender)
{
if (!isLocal()) return true;
Player senderPlayer = sender.getPlayer();
for (Player recipient : recipients)
{
if (recipient.equals(senderPlayer)) continue;
if (recipient.hasPermission("herochat.admin.stealth")) continue;
return true;
}
return false;
}
public void trimRecipients(Set<Player> recipients, Chatter sender)
{
World world = sender.getPlayer().getWorld();
Set<Chatter> members = this.getMembers();
Iterator<Player> iterator = recipients.iterator();
while(iterator.hasNext())
{
Chatter recipient = Herochat.getChatterManager().getChatter(iterator.next());
if (recipient == null) continue;
World recipientWorld = recipient.getPlayer().getWorld();
if (!members.contains(recipient))
iterator.remove();
else if ((isLocal()) && (!sender.isInRange(recipient, this.getDistance())))
iterator.remove();
else if (!hasWorld(recipientWorld))
iterator.remove();
else if (recipient.isIgnoring(sender))
iterator.remove();
else if ((!this.isCrossWorld()) && (!world.equals(recipientWorld)))
iterator.remove();
}
}
public boolean equals(Object other)
{
if (other == this) return true;
if (other == null) return false;
if (!(other instanceof Channel)) return false;
Channel channel = (Channel)other;
return (this.getName().equalsIgnoreCase(channel.getName())) || (this.getName().equalsIgnoreCase(channel.getNick()));
}
public int hashCode()
{
int prime = 31;
int result = 1;
result = prime * result + (this.getName() == null ? 0 : this.getName().toLowerCase().hashCode());
result = prime * result + (this.getNick() == null ? 0 : this.getNick().toLowerCase().hashCode());
return result;
}
@Override public boolean isTransient() { return false; }
@Override public String getPassword() { return ""; }
@Override public void setPassword(String password) {}
@Override public boolean isVerbose() { return false; }
@Override public void setVerbose(boolean verbose) {}
@Override public boolean isHidden() { return false; }
@Override public boolean isLocal() { return this.getDistance() != 0; }
@Override public void attachStorage(ChannelStorage storage) { }
@Override public boolean banMember(Chatter chatter, boolean announce) { return false; }
@Override public Set<String> getBans() { return Collections.emptySet(); }
@Override public Set<String> getModerators() { return Collections.emptySet(); }
@Override public Set<String> getMutes() { return Collections.emptySet(); }
@Override public ChannelStorage getStorage() { return this.storage; }
@Override public boolean hasWorld(String world) { return (this.getWorlds().isEmpty()) || (this.getWorlds().contains(world)); }
@Override public boolean hasWorld(World world) { return this.hasWorld(world.getName()); }
@Override public boolean isBanned(String name) { return this.getBans().contains(name.toLowerCase()); }
@Override public boolean isMember(Chatter chatter) { return this.getMembers().contains(chatter); }
@Override public boolean isModerator(String name) { return this.getModerators().contains(name.toLowerCase()); }
@Override public void onFocusGain(Chatter chatter) {}
@Override public void onFocusLoss(Chatter chatter) {}
@Override public void removeWorld(String world) { this.getWorlds().remove(world); }
@Override public void setBanned(String name, boolean banned) {}
@Override public void setBans(Set<String> bans) {}
@Override public void setModerator(String name, boolean moderator) {}
@Override public void setModerators(Set<String> moderators) { }
@Override public void setMuted(String name, boolean muted) {}
@Override public void setMutes(Set<String> mutes) {}
@Override
public MessageFormatSupplier getFormatSupplier()
{
return this.formatSupplier;
}
@Override
public void sendRawMessage(String rawMessage)
{
for (Chatter member : this.getMembers())
{
member.getPlayer().sendMessage(rawMessage);
}
}
}

View File

@@ -0,0 +1,42 @@
package com.massivecraft.factions.integration.herochat;
import java.util.EnumSet;
import java.util.Set;
import org.bukkit.ChatColor;
import com.massivecraft.factions.Rel;
import com.massivecraft.factions.entity.MConf;
public class ChannelFactionsAllies extends ChannelFactionsAbstract
{
public static final Set<Rel> targetRelations = EnumSet.of(Rel.MEMBER, Rel.RECRUIT, Rel.ALLY);
@Override public Set<Rel> getTargetRelations() { return targetRelations; }
@Override public String getName() { return MConf.get().herochatAlliesName; }
@Override public String getNick() { return MConf.get().herochatAlliesNick; }
@Override public void setNick(String nick) { MConf.get().herochatAlliesNick = nick; }
@Override public String getFormat() { return MConf.get().herochatAlliesFormat; }
@Override public void setFormat(String format) { MConf.get().herochatAlliesFormat = format; }
@Override public ChatColor getColor() { return MConf.get().herochatAlliesColor; }
@Override public void setColor(ChatColor color) { MConf.get().herochatAlliesColor = color; }
@Override public int getDistance() { return MConf.get().herochatAlliesDistance; }
@Override public void setDistance(int distance) { MConf.get().herochatAlliesDistance = distance; }
@Override public void addWorld(String world) { MConf.get().herochatAlliesWorlds.add(world); }
@Override public Set<String> getWorlds() { return MConf.get().herochatAlliesWorlds; }
@Override public void setWorlds(Set<String> worlds) { MConf.get().herochatAlliesWorlds = worlds; }
@Override public boolean isShortcutAllowed() { return MConf.get().herochatAlliesIsShortcutAllowed; }
@Override public void setShortcutAllowed(boolean shortcutAllowed) { MConf.get().herochatAlliesIsShortcutAllowed = shortcutAllowed; }
@Override public boolean isCrossWorld() { return MConf.get().herochatAlliesCrossWorld; }
@Override public void setCrossWorld(boolean crossWorld) { MConf.get().herochatAlliesCrossWorld = crossWorld; }
@Override public boolean isMuted() { return MConf.get().herochatAlliesMuted; }
@Override public void setMuted(boolean value) { MConf.get().herochatAlliesMuted = value; }
}

View File

@@ -0,0 +1,43 @@
package com.massivecraft.factions.integration.herochat;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Set;
import org.bukkit.ChatColor;
import com.massivecraft.factions.Rel;
import com.massivecraft.factions.entity.MConf;
public class ChannelFactionsFaction extends ChannelFactionsAbstract
{
public static final Set<Rel> targetRelations = EnumSet.of(Rel.MEMBER, Rel.RECRUIT);
@Override public Set<Rel> getTargetRelations() { return targetRelations; }
@Override public String getName() { return MConf.get().herochatFactionName; }
@Override public String getNick() { return MConf.get().herochatFactionNick; }
@Override public void setNick(String nick) { MConf.get().herochatFactionNick = nick; }
@Override public String getFormat() { return MConf.get().herochatFactionFormat; }
@Override public void setFormat(String format) { MConf.get().herochatFactionFormat = format; }
@Override public ChatColor getColor() { return MConf.get().herochatFactionColor; }
@Override public void setColor(ChatColor color) { MConf.get().herochatFactionColor = color; }
@Override public int getDistance() { return MConf.get().herochatFactionDistance; }
@Override public void setDistance(int distance) { MConf.get().herochatFactionDistance = distance; }
@Override public void addWorld(String world) { MConf.get().herochatFactionWorlds.add(world); }
@Override public Set<String> getWorlds() { return new HashSet<String>(MConf.get().herochatFactionWorlds); }
@Override public void setWorlds(Set<String> worlds) { MConf.get().herochatFactionWorlds = worlds; }
@Override public boolean isShortcutAllowed() { return MConf.get().herochatFactionIsShortcutAllowed; }
@Override public void setShortcutAllowed(boolean shortcutAllowed) { MConf.get().herochatFactionIsShortcutAllowed = shortcutAllowed; }
@Override public boolean isCrossWorld() { return MConf.get().herochatFactionCrossWorld; }
@Override public void setCrossWorld(boolean crossWorld) { MConf.get().herochatFactionCrossWorld = crossWorld; }
@Override public boolean isMuted() { return MConf.get().herochatFactionMuted; }
@Override public void setMuted(boolean value) { MConf.get().herochatFactionMuted = value; }
}

View File

@@ -0,0 +1,63 @@
package com.massivecraft.factions.integration.herochat;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import com.dthielke.herochat.ChannelChatEvent;
import com.dthielke.herochat.Herochat;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.chat.ChatFormatter;
import com.massivecraft.factions.entity.MConf;
public class EngineHerochat implements Listener
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static EngineHerochat i = new EngineHerochat();
public static EngineHerochat get() { return i; }
private EngineHerochat() {}
// -------------------------------------------- //
// ACTIVATE & DEACTIVATE
// -------------------------------------------- //
public void activate()
{
Herochat.getChannelManager().addChannel(new ChannelFactionsFaction());
Herochat.getChannelManager().addChannel(new ChannelFactionsAllies());
Bukkit.getPluginManager().registerEvents(this, Factions.get());
}
public void deactivate()
{
HandlerList.unregisterAll(this);
}
// -------------------------------------------- //
// LISTENER
// -------------------------------------------- //
@EventHandler(priority = EventPriority.NORMAL)
public void onChannelChatEvent(ChannelChatEvent event)
{
// Should we even parse?
if ( ! MConf.get().chatParseTags) return;
String format = event.getFormat();
// We trigger a replace of HeroChats tag {default} here
// This way we can replace faction tags hidden withing {default} as well.
format = format.replace("{default}", event.getChannel().getFormatSupplier().getStandardFormat());
format = ChatFormatter.format(format, event.getSender().getPlayer(), null);
event.setFormat(format);
}
}

View File

@@ -0,0 +1,31 @@
package com.massivecraft.factions.integration.herochat;
import com.massivecraft.massivecore.integration.IntegrationAbstract;
public class IntegrationHerochat extends IntegrationAbstract
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static IntegrationHerochat i = new IntegrationHerochat();
public static IntegrationHerochat get() { return i; }
private IntegrationHerochat() { super("Herochat"); }
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public void activate()
{
EngineHerochat.get().activate();
}
@Override
public void deactivate()
{
EngineHerochat.get().deactivate();
}
}

View File

@@ -0,0 +1,158 @@
package com.massivecraft.factions.integration.lwc;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.plugin.Plugin;
import com.griefcraft.lwc.LWC;
import com.griefcraft.model.Protection;
import com.griefcraft.sql.PhysDB;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MConf;
import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.factions.event.EventFactionsChunksChange;
import com.massivecraft.factions.event.EventFactionsChunkChangeType;
import com.massivecraft.massivecore.EngineAbstract;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.util.IdUtil;
public class EngineLwc extends EngineAbstract
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static EngineLwc i = new EngineLwc();
public static EngineLwc get() { return i; }
private EngineLwc() {}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public Plugin getPlugin()
{
return Factions.get();
}
@Override
public void activate()
{
super.activate();
LWC.getInstance().getModuleLoader().registerModule(Factions.get(), new FactionsLwcModule(Factions.get()));
}
@Override
public void deactivate()
{
super.deactivate();
LWC.getInstance().getModuleLoader().removeModules(Factions.get());
}
// -------------------------------------------- //
// LISTENER
// -------------------------------------------- //
public void removeProtectionsOnChunkChange(Faction newFaction, EventFactionsChunkChangeType type, Set<PS> chunks)
{
// If we are supposed to clear at this chunk change type ...
Boolean remove = MConf.get().lwcRemoveOnChange.get(type);
if (remove == null) return;
if (remove == false) return;
// ... then remove for all other factions than the new one.
// First we wait one tick to make sure the chunk ownership changes have been applied.
// Then we remove the protections but we do it asynchronously to not lock the main thread.
for (PS chunk : chunks)
{
removeAlienProtectionsAsyncNextTick(chunk, newFaction);
}
}
public void removeProtectionsOnChunkChange(Faction newFaction, Map<EventFactionsChunkChangeType, Set<PS>> typeChunks)
{
for (Entry<EventFactionsChunkChangeType, Set<PS>> typeChunk : typeChunks.entrySet())
{
final EventFactionsChunkChangeType type = typeChunk.getKey();
final Set<PS> chunks = typeChunk.getValue();
removeProtectionsOnChunkChange(newFaction, type, chunks);
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void removeProtectionsOnChunkChange(EventFactionsChunksChange event)
{
removeProtectionsOnChunkChange(event.getNewFaction(), event.getTypeChunks());
}
// -------------------------------------------- //
// UTIL
// -------------------------------------------- //
// This method causes LWC to run an SQL query which can take a few milliseconds.
// For that reason this method should not be executed in the main server thread.
// After looking through the source code of LWC I am also hopeful this is thread safe.
public static List<Protection> getProtectionsInChunk(PS chunkPs)
{
final int xmin = chunkPs.getChunkX() * 16;
final int xmax = xmin + 15;
final int ymin = 0;
final int ymax = 255;
final int zmin = chunkPs.getChunkZ() * 16;
final int zmax = zmin + 15;
PhysDB db = LWC.getInstance().getPhysicalDatabase();
return db.loadProtections(chunkPs.getWorld(), xmin, xmax, ymin, ymax, zmin, zmax);
}
// As with the method above: Thread safe and slow. Do run asynchronously.
public static void removeAlienProtectionsRaw(PS chunkPs, Faction faction)
{
List<MPlayer> nonAliens = faction.getMPlayers();
for (Protection protection : getProtectionsInChunk(chunkPs))
{
// NOTE: The LWC protection owner is still the name and not the UUID. For that reason we must convert it.
String ownerName = protection.getOwner();
String ownerId = IdUtil.getId(ownerName);
MPlayer owner = MPlayer.get(ownerId);
if (nonAliens.contains(owner)) continue;
protection.remove();
}
}
public static void removeAlienProtectionsAsync(final PS chunkPs, final Faction faction)
{
Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), new Runnable()
{
@Override
public void run()
{
removeAlienProtectionsRaw(chunkPs, faction);
}
});
}
public static void removeAlienProtectionsAsyncNextTick(final PS chunkPs, final Faction faction)
{
Bukkit.getScheduler().runTaskLater(Factions.get(), new Runnable()
{
@Override
public void run()
{
removeAlienProtectionsAsync(chunkPs, faction);
}
}, 0);
}
}

View File

@@ -0,0 +1,104 @@
package com.massivecraft.factions.integration.lwc;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import com.griefcraft.lwc.LWC;
import com.griefcraft.model.Protection;
import com.griefcraft.scripting.JavaModule;
import com.griefcraft.scripting.event.LWCProtectionInteractEvent;
import com.griefcraft.scripting.event.LWCProtectionRegisterEvent;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.engine.EngineMain;
import com.massivecraft.factions.entity.MConf;
import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.mixin.Mixin;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.util.IdUtil;
import com.massivecraft.massivecore.util.SmokeUtil;
import com.massivecraft.massivecore.util.Txt;
@SuppressWarnings("unused")
public class FactionsLwcModule extends JavaModule
{
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
// These plugin variables must be present.
// They are set by LWC using reflection somehow.
private Factions plugin;
private LWC lwc;
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public FactionsLwcModule(Factions plugin)
{
this.plugin = plugin;
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
//
@Override
public void onRegisterProtection(LWCProtectionRegisterEvent event)
{
// If this feature is enabled ...
if ( ! MConf.get().lwcMustHaveBuildRightsToCreate) return;
// ... and the player don't have build rights here ...
// NOTE: We verbosely check the build rights so that a proper info message is sent
if (EngineMain.canPlayerBuildAt(event.getPlayer(), PS.valueOf(event.getBlock()), true)) return;
// ... then cancel the event.
event.setCancelled(true);
}
@Override
public void onProtectionInteract(LWCProtectionInteractEvent event)
{
// If this feature is enabled ...
if ( ! MConf.get().lwcRemoveIfNoBuildRights) return;
// ... gather data ...
final Protection protection = event.getProtection();
final Block block = protection.getBlock();
final PS ps = PS.valueOf(block);
// NOTE: The LWC protection owner is still the name and not the UUID. For that reason we must convert it.
final String ownerName = protection.getOwner();
final String ownerId = IdUtil.getId(ownerName);
final MPlayer mowner = MPlayer.get(ownerId);
if (mowner == null) return;
// ... and if the protection owner no longer has build rights for the area ...
// NOTE: We silently check the build rights for the protection owner.
// NOTE: The protection owner may even be offline at the moment.
if (EngineMain.canPlayerBuildAt(mowner, ps, false)) return;
// ... remove the protection ...
protection.remove();
// ... cancel the event ...
// NOTE: The first time you click nothing but the unlock should happen.
// NOTE: This way it's more obvious the auto unlock system kicked in.
// NOTE: No inventory will get opened.
event.setResult(Result.CANCEL);
// ... play FX ...
Location location = block.getLocation();
SmokeUtil.spawnCloudSimple(location);
location.getWorld().playSound(location, Sound.DOOR_OPEN, 1, 1);
// ... and inform.
Player player = event.getPlayer();
String message = Txt.parse("<i>Factions removed <h>%s's <i>LWC. They lacked build rights.", mowner.getDisplayName(player));
player.sendMessage(message);
}
}

View File

@@ -0,0 +1,31 @@
package com.massivecraft.factions.integration.lwc;
import com.massivecraft.massivecore.integration.IntegrationAbstract;
public class IntegrationLwc extends IntegrationAbstract
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static IntegrationLwc i = new IntegrationLwc();
public static IntegrationLwc get() { return i; }
private IntegrationLwc() { super("LWC"); }
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public void activate()
{
EngineLwc.get().activate();
}
@Override
public void deactivate()
{
EngineLwc.get().deactivate();
}
}