Rename and repackage the Engines/Listeners.

This commit is contained in:
Olof Larsson
2014-10-08 06:38:26 +02:00
parent 54e04fee88
commit f1375ea699
9 changed files with 107 additions and 44 deletions

View File

@ -0,0 +1,140 @@
package com.massivecraft.factions.engine;
import org.bukkit.Bukkit;
import org.bukkit.event.Event;
import org.bukkit.event.EventException;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.plugin.EventExecutor;
import org.bukkit.plugin.Plugin;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.chat.ChatFormatter;
import com.massivecraft.factions.entity.MConf;
import com.massivecraft.massivecore.EngineAbstract;
import com.massivecraft.massivecore.event.EventMassiveCorePlayerToRecipientChat;
public class EngineChat extends EngineAbstract
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static EngineChat i = new EngineChat();
public static EngineChat get() { return i; }
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public Plugin getPlugin()
{
return Factions.get();
}
@Override
public void activate()
{
super.activate();
if (MConf.get().chatSetFormat)
{
Bukkit.getPluginManager().registerEvent(AsyncPlayerChatEvent.class, this, MConf.get().chatSetFormatAt, new SetFormatEventExecutor(), Factions.get(), true);
}
if (MConf.get().chatParseTags)
{
Bukkit.getPluginManager().registerEvent(AsyncPlayerChatEvent.class, this, MConf.get().chatParseTagsAt, new ParseTagsEventExecutor(), Factions.get(), true);
}
if (MConf.get().chatParseTags)
{
Bukkit.getPluginManager().registerEvent(EventMassiveCorePlayerToRecipientChat.class, this, EventPriority.NORMAL, new ParseRelcolorEventExecutor(), Factions.get(), true);
}
}
// -------------------------------------------- //
// SET FORMAT
// -------------------------------------------- //
private class SetFormatEventExecutor implements EventExecutor
{
@Override
public void execute(Listener listener, Event event) throws EventException
{
try
{
if (!(event instanceof AsyncPlayerChatEvent)) return;
setFormat((AsyncPlayerChatEvent)event);
}
catch (Throwable t)
{
throw new EventException(t);
}
}
}
public static void setFormat(AsyncPlayerChatEvent event)
{
event.setFormat(MConf.get().chatSetFormatTo);
}
// -------------------------------------------- //
// PARSE TAGS
// -------------------------------------------- //
private class ParseTagsEventExecutor implements EventExecutor
{
@Override
public void execute(Listener listener, Event event) throws EventException
{
try
{
if (!(event instanceof AsyncPlayerChatEvent)) return;
parseTags((AsyncPlayerChatEvent)event);
}
catch (Throwable t)
{
throw new EventException(t);
}
}
}
public static void parseTags(AsyncPlayerChatEvent event)
{
String format = event.getFormat();
format = ChatFormatter.format(format, event.getPlayer(), null);
event.setFormat(format);
}
// -------------------------------------------- //
// PARSE RELCOLOR
// -------------------------------------------- //
private class ParseRelcolorEventExecutor implements EventExecutor
{
@Override
public void execute(Listener listener, Event event) throws EventException
{
try
{
if (!(event instanceof EventMassiveCorePlayerToRecipientChat)) return;
parseRelcolor((EventMassiveCorePlayerToRecipientChat)event);
}
catch (Throwable t)
{
throw new EventException(t);
}
}
}
public static void parseRelcolor(EventMassiveCorePlayerToRecipientChat event)
{
String format = event.getFormat();
format = ChatFormatter.format(format, event.getSender(), event.getRecipient());
event.setFormat(format);
}
}

View File

@ -0,0 +1,240 @@
package com.massivecraft.factions.engine;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.plugin.Plugin;
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.EventFactionsAbstractSender;
import com.massivecraft.factions.event.EventFactionsChunkChange;
import com.massivecraft.factions.event.EventFactionsChunkChangeType;
import com.massivecraft.factions.event.EventFactionsCreate;
import com.massivecraft.factions.event.EventFactionsDescriptionChange;
import com.massivecraft.factions.event.EventFactionsDisband;
import com.massivecraft.factions.event.EventFactionsHomeChange;
import com.massivecraft.factions.event.EventFactionsHomeTeleport;
import com.massivecraft.factions.event.EventFactionsInvitedChange;
import com.massivecraft.factions.event.EventFactionsMembershipChange;
import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason;
import com.massivecraft.factions.event.EventFactionsNameChange;
import com.massivecraft.factions.event.EventFactionsFlagChange;
import com.massivecraft.factions.event.EventFactionsRelationChange;
import com.massivecraft.factions.event.EventFactionsTitleChange;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.massivecore.EngineAbstract;
import com.massivecraft.massivecore.money.Money;
public class EngineEcon extends EngineAbstract
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static EngineEcon i = new EngineEcon();
public static EngineEcon get() { return i; }
public EngineEcon() {}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public Plugin getPlugin()
{
return Factions.get();
}
// -------------------------------------------- //
// TAKE ON LEAVE
// -------------------------------------------- //
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void takeOnLeave(EventFactionsMembershipChange event)
{
// If a player is leaving the faction ...
if (event.getReason() != MembershipChangeReason.LEAVE) return;
// ... and that player was the last one in the faction ...
MPlayer mplayer = event.getMPlayer();
Faction oldFaction = mplayer.getFaction();
if (oldFaction.getMPlayers().size() > 1) return;
// ... then transfer all money to the player.
double money = Money.get(oldFaction);
if (money == 0) return;
Econ.transferMoney(mplayer, oldFaction, mplayer, money);
}
// -------------------------------------------- //
// TAKE ON DISBAND
// -------------------------------------------- //
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void takeOnDisband(EventFactionsDisband event)
{
// If there is a usender ...
MPlayer usender = event.getMSender();
if (usender == null) return;
// ... and economy is enabled ...
if (!Econ.isEnabled()) return;
// ... then transfer all the faction money to the sender.
Faction faction = event.getFaction();
double amount = Money.get(faction);
String amountString = Money.format(amount);
Econ.transferMoney(faction, usender, usender, amount, true);
usender.msg("<i>You have been given the disbanded faction's bank, totaling %s.", amountString);
Factions.get().log(usender.getName() + " has been given bank holdings of "+amountString+" from disbanding "+faction.getName()+".");
}
// -------------------------------------------- //
// PAY FOR ACTION
// -------------------------------------------- //
public static void payForAction(EventFactionsAbstractSender event, Double cost, String desc)
{
// If there is a sender ...
MPlayer usender = event.getMSender();
if (usender == null) return;
// ... and there is a cost ...
if (cost == null) return;
if (cost == 0) return;
// ... that the sender can't afford ...
if (Econ.payForAction(cost, usender, desc)) return;
// ... then cancel.
event.setCancelled(true);
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void payForAction(EventFactionsChunkChange event)
{
EventFactionsChunkChangeType type = event.getType();
Double cost = MConf.get().econChunkCost.get(type);
String desc = type.toString().toLowerCase() + " this land";
payForAction(event, cost, desc);
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void payForAction(EventFactionsMembershipChange event)
{
Double cost = null;
String desc = null;
if (event.getReason() == MembershipChangeReason.JOIN)
{
cost = MConf.get().econCostJoin;
desc = "join a faction";
}
else if (event.getReason() == MembershipChangeReason.LEAVE)
{
cost = MConf.get().econCostLeave;
desc = "leave a faction";
}
else if (event.getReason() == MembershipChangeReason.KICK)
{
cost = MConf.get().econCostKick;
desc = "kick someone from a faction";
}
else
{
return;
}
payForAction(event, cost, desc);
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void payForCommand(EventFactionsRelationChange event)
{
Double cost = MConf.get().econRelCost.get(event.getNewRelation());
String desc = Factions.get().getOuterCmdFactions().cmdFactionsRelationNeutral.getDesc();
payForAction(event, cost, desc);
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void payForCommand(EventFactionsHomeChange event)
{
Double cost = MConf.get().econCostSethome;
String desc = Factions.get().getOuterCmdFactions().cmdFactionsSethome.getDesc();
payForAction(event, cost, desc);
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void payForCommand(EventFactionsCreate event)
{
Double cost = MConf.get().econCostCreate;
String desc = Factions.get().getOuterCmdFactions().cmdFactionsCreate.getDesc();
payForAction(event, cost, desc);
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void payForCommand(EventFactionsDescriptionChange event)
{
Double cost = MConf.get().econCostDescription;
String desc = Factions.get().getOuterCmdFactions().cmdFactionsDescription.getDesc();
payForAction(event, cost, desc);
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void payForCommand(EventFactionsNameChange event)
{
Double cost = MConf.get().econCostName;
String desc = Factions.get().getOuterCmdFactions().cmdFactionsName.getDesc();
payForAction(event, cost, desc);
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void payForCommand(EventFactionsTitleChange event)
{
Double cost = MConf.get().econCostTitle;
String desc = Factions.get().getOuterCmdFactions().cmdFactionsTitle.getDesc();
payForAction(event, cost, desc);
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void payForCommand(EventFactionsFlagChange event)
{
Double cost = MConf.get().econCostFlag;
String desc = Factions.get().getOuterCmdFactions().cmdFactionsFlag.getDesc();
payForAction(event, cost, desc);
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void payForCommand(EventFactionsInvitedChange event)
{
Double cost = event.isNewInvited() ? MConf.get().econCostInvite : MConf.get().econCostDeinvite;
String desc = Factions.get().getOuterCmdFactions().cmdFactionsInvite.getDesc();
payForAction(event, cost, desc);
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void payForCommand(EventFactionsHomeTeleport event)
{
Double cost = MConf.get().econCostHome;
String desc = Factions.get().getOuterCmdFactions().cmdFactionsHome.getDesc();
payForAction(event, cost, desc);
}
}

View File

@ -0,0 +1,140 @@
package com.massivecraft.factions.engine;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.block.Block;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.plugin.Plugin;
import org.bukkit.Location;
import org.bukkit.Material;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.entity.MConf;
import com.massivecraft.massivecore.EngineAbstract;
public class EngineExploit extends EngineAbstract
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static EngineExploit i = new EngineExploit();
public static EngineExploit get() { return i; }
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public Plugin getPlugin()
{
return Factions.get();
}
// -------------------------------------------- //
// OBSIDIAN GENERATORS
// -------------------------------------------- //
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void obsidianGenerators(BlockFromToEvent event)
{
if (!MConf.get().handleExploitObsidianGenerators) return;
// thanks to ObGenBlocker and WorldGuard for this method
Block block = event.getToBlock();
int source = event.getBlock().getTypeId();
int target = block.getTypeId();
if ((target == 55 || target == 132) && (source == 0 || source == 10 || source == 11))
{
block.setType(Material.AIR);
}
}
// -------------------------------------------- //
// ENDER PEARL CLIPPING
// -------------------------------------------- //
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void enderPearlClipping(PlayerTeleportEvent event)
{
if (!MConf.get().handleExploitEnderPearlClipping) return;
if (event.getCause() != PlayerTeleportEvent.TeleportCause.ENDER_PEARL) return;
// this exploit works when the target location is within 0.31 blocks or so of a door or glass block or similar...
Location target = event.getTo();
Location from = event.getFrom();
// blocks who occupy less than 1 block width or length wise need to be handled differently
Material mat = event.getTo().getBlock().getType();
if (
((mat == Material.THIN_GLASS || mat == Material.IRON_FENCE) && clippingThrough(target, from, 0.65))
|| ((mat == Material.FENCE || mat == Material.NETHER_FENCE) && clippingThrough(target, from, 0.45))
)
{
event.setTo(from);
return;
}
// simple fix otherwise: ender pearl target locations are standardized to be in the center (X/Z) of the target block, not at the edges
target.setX(target.getBlockX() + 0.5);
target.setZ(target.getBlockZ() + 0.5);
event.setTo(target);
}
public static boolean clippingThrough(Location target, Location from, double thickness)
{
return
(
(from.getX() > target.getX() && (from.getX() - target.getX() < thickness))
|| (target.getX() > from.getX() && (target.getX() - from.getX() < thickness))
|| (from.getZ() > target.getZ() && (from.getZ() - target.getZ() < thickness))
|| (target.getZ() > from.getZ() && (target.getZ() - from.getZ() < thickness))
);
}
// -------------------------------------------- //
// TNT WATERLOG
// -------------------------------------------- //
// TNT in water/lava doesn't normally destroy any surrounding blocks, which is usually desired behavior, but...
// this optional change below provides workaround for waterwalling providing perfect protection,
// and makes cheap (non-obsidian) TNT cannons require minor maintenance between shots
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void tntWaterlog(EntityExplodeEvent event)
{
if (!MConf.get().handleExploitTNTWaterlog) return;
if (!(event.getEntity() instanceof TNTPrimed)) return;
Block center = event.getLocation().getBlock();
if (!center.isLiquid()) return;
// a single surrounding block in all 6 directions is broken if the material is weak enough
List<Block> targets = new ArrayList<Block>();
targets.add(center.getRelative(0, 0, 1));
targets.add(center.getRelative(0, 0, -1));
targets.add(center.getRelative(0, 1, 0));
targets.add(center.getRelative(0, -1, 0));
targets.add(center.getRelative(1, 0, 0));
targets.add(center.getRelative(-1, 0, 0));
for (Block target : targets)
{
int id = target.getTypeId();
// ignore air, bedrock, water, lava, obsidian, enchanting table, etc.... too bad we can't get a blast resistance value through Bukkit yet
if (id != 0 && (id < 7 || id > 11) && id != 49 && id != 90 && id != 116 && id != 119 && id != 120 && id != 130)
{
target.breakNaturally();
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,58 @@
package com.massivecraft.factions.engine;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.plugin.Plugin;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.EngineAbstract;
import com.massivecraft.massivecore.event.EventMassiveCorePlayerLeave;
public class EngineSeeChunk extends EngineAbstract
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static EngineSeeChunk i = new EngineSeeChunk();
public static EngineSeeChunk get() { return i; }
public EngineSeeChunk() {}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public Plugin getPlugin()
{
return Factions.get();
}
// -------------------------------------------- //
// LEAVE AND WORLD CHANGE REMOVAL
// -------------------------------------------- //
public static void leaveAndWorldChangeRemoval(Player player)
{
final MPlayer mplayer = MPlayer.get(player);
mplayer.setSeeingChunk(false);
}
// Can't be cancelled
@EventHandler(priority = EventPriority.NORMAL)
public void leaveAndWorldChangeRemoval(EventMassiveCorePlayerLeave event)
{
leaveAndWorldChangeRemoval(event.getPlayer());
}
// Can't be cancelled
@EventHandler(priority = EventPriority.NORMAL)
public void leaveAndWorldChangeRemoval(PlayerChangedWorldEvent event)
{
leaveAndWorldChangeRemoval(event.getPlayer());
}
}