Remove Maven
This commit is contained in:
@ -1,140 +0,0 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
@ -1,261 +0,0 @@
|
||||
package com.massivecraft.factions.engine;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
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.EventFactionsChunksChange;
|
||||
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;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
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(EventFactionsChunksChange event)
|
||||
{
|
||||
double cost = 0;
|
||||
List<String> typeNames = new ArrayList<String>();
|
||||
|
||||
for (Entry<EventFactionsChunkChangeType, Set<PS>> typeChunks : event.getTypeChunks().entrySet())
|
||||
{
|
||||
final EventFactionsChunkChangeType type = typeChunks.getKey();
|
||||
final Set<PS> chunks = typeChunks.getValue();
|
||||
|
||||
Double typeCost = MConf.get().econChunkCost.get(type);
|
||||
if (typeCost == null) continue;
|
||||
if (typeCost == 0) continue;
|
||||
|
||||
typeCost *= chunks.size();
|
||||
cost += typeCost;
|
||||
|
||||
typeNames.add(type.now);
|
||||
}
|
||||
|
||||
String desc = Txt.implodeCommaAnd(typeNames) + " 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);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,140 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,112 +0,0 @@
|
||||
package com.massivecraft.factions.engine;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.TerritoryAccess;
|
||||
import com.massivecraft.factions.entity.Board;
|
||||
import com.massivecraft.factions.entity.BoardColl;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.FactionColl;
|
||||
import com.massivecraft.factions.entity.MPlayerColl;
|
||||
import com.massivecraft.massivecore.EngineAbstract;
|
||||
import com.massivecraft.massivecore.event.EventMassiveCoreUuidUpdate;
|
||||
import com.massivecraft.massivecore.util.IdUpdateUtil;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
|
||||
public class EngineIdUpdate extends EngineAbstract
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static EngineIdUpdate i = new EngineIdUpdate();
|
||||
public static EngineIdUpdate get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Plugin getPlugin()
|
||||
{
|
||||
return Factions.get();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// LISTENER
|
||||
// -------------------------------------------- //
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void update(EventMassiveCoreUuidUpdate event)
|
||||
{
|
||||
for (Faction entity : FactionColl.get().getAll())
|
||||
{
|
||||
update(entity);
|
||||
}
|
||||
|
||||
IdUpdateUtil.update(MPlayerColl.get());
|
||||
|
||||
update(BoardColl.get());
|
||||
}
|
||||
|
||||
public static void update(Faction entity)
|
||||
{
|
||||
// Before and After
|
||||
Set<String> before = entity.getInvitedPlayerIds();
|
||||
if (before == null) return;
|
||||
Set<String> after = IdUpdateUtil.update(before, true);
|
||||
if (after == null) return;
|
||||
|
||||
// NoChange
|
||||
if (MUtil.equals(before, after)) return;
|
||||
|
||||
// Apply
|
||||
entity.setInvitedPlayerIds(after);
|
||||
entity.sync();
|
||||
}
|
||||
|
||||
public static void update(BoardColl coll)
|
||||
{
|
||||
for (Board board : coll.getAll())
|
||||
{
|
||||
update(board);
|
||||
}
|
||||
}
|
||||
|
||||
public static void update(Board board)
|
||||
{
|
||||
boolean changed = false;
|
||||
for (TerritoryAccess ta : board.getMap().values())
|
||||
{
|
||||
changed |= update(ta);
|
||||
}
|
||||
if (changed)
|
||||
{
|
||||
board.changed();
|
||||
board.sync();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean update(TerritoryAccess entity)
|
||||
{
|
||||
// Before and After
|
||||
Set<String> before = entity.playerIds;
|
||||
if (before == null) return false;
|
||||
Set<String> after = IdUpdateUtil.update(before, true);
|
||||
if (after == null) return false;
|
||||
|
||||
// NoChange
|
||||
if (MUtil.equals(before, after)) return false;
|
||||
|
||||
// Apply
|
||||
entity.playerIds = after;
|
||||
//entity.sync();
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,186 +0,0 @@
|
||||
package com.massivecraft.factions.engine;
|
||||
|
||||
import java.security.InvalidParameterException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
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.MConf;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.massivecore.EngineAbstract;
|
||||
import com.massivecraft.massivecore.event.EventMassiveCorePlayerLeave;
|
||||
import com.massivecraft.massivecore.particleeffect.ParticleEffect;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
import com.massivecraft.massivecore.util.PeriodUtil;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getPeriod()
|
||||
{
|
||||
return 1L;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// 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());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// MODULO REPEAT TASK
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
// Do we have a new period?
|
||||
final long now = System.currentTimeMillis();
|
||||
final long length = MConf.get().seeChunkPeriodMillis;
|
||||
if ( ! PeriodUtil.isNewPeriod(this, length, now)) return;
|
||||
|
||||
// Get the period number
|
||||
final long period = PeriodUtil.getPeriod(length, now);
|
||||
|
||||
// Calculate the "step" from the period number
|
||||
final int steps = MConf.get().seeChunkSteps; // Example: 4
|
||||
final int step = (int) (period % steps); // Example: 0, 1, 2, 3
|
||||
|
||||
// Load other related config options
|
||||
final float offsetX = 0.0f;
|
||||
final float offsetY = MConf.get().seeChunkParticleOffsetY;
|
||||
final float offsetZ = 0.0f;
|
||||
final float speed = 0;
|
||||
final int amount = MConf.get().seeChunkParticleAmount;
|
||||
|
||||
// For each player
|
||||
for (Player player : MUtil.getOnlinePlayers())
|
||||
{
|
||||
// Hide for dead players since the death screen looks better without.
|
||||
if (player.isDead()) continue;
|
||||
|
||||
// The player must obviously have the feature activated.
|
||||
MPlayer mplayer = MPlayer.get(player);
|
||||
if ( ! mplayer.isSeeingChunk()) continue;
|
||||
|
||||
// Calculate locations and play the effect there.
|
||||
List<Location> locations = getLocations(player, steps, step);
|
||||
for (Location location : locations)
|
||||
{
|
||||
ParticleEffect.EXPLOSION_NORMAL.display(location, offsetX, offsetY, offsetZ, speed, amount, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Location> getLocations(Player player, int steps, int step)
|
||||
{
|
||||
// Clean Args
|
||||
if (player == null) throw new NullPointerException("player");
|
||||
if (steps < 1) throw new InvalidParameterException("steps must be larger than 0");
|
||||
if (step < 0) throw new InvalidParameterException("step must at least be 0");
|
||||
if (step >= steps) throw new InvalidParameterException("step must be less than steps");
|
||||
|
||||
// Create Ret
|
||||
List<Location> ret = new ArrayList<Location>();
|
||||
|
||||
final Location location = player.getLocation();
|
||||
final World world = location.getWorld();
|
||||
PS chunk = PS.valueOf(location).getChunk(true);
|
||||
|
||||
final int xmin = chunk.getChunkX() * 16;
|
||||
final int xmax = xmin + 15;
|
||||
final double y = location.getBlockY() + MConf.get().seeChunkParticleDeltaY;
|
||||
final int zmin = chunk.getChunkZ() * 16;
|
||||
final int zmax = zmin + 15;
|
||||
|
||||
int keepEvery = MConf.get().seeChunkKeepEvery;
|
||||
if (keepEvery <= 0) keepEvery = Integer.MAX_VALUE;
|
||||
|
||||
int skipEvery = MConf.get().seeChunkSkipEvery;
|
||||
if (skipEvery <= 0) skipEvery = Integer.MAX_VALUE;
|
||||
|
||||
int x = xmin;
|
||||
int z = zmin;
|
||||
int i = 0;
|
||||
|
||||
// Add #1
|
||||
while (x + 1 <= xmax)
|
||||
{
|
||||
x++;
|
||||
i++;
|
||||
if (i % steps == step && (i % keepEvery == 0 && i % skipEvery != 0)) ret.add(new Location(world, x + 0.5, y + 0.5, z + 0.5));
|
||||
}
|
||||
|
||||
// Add #2
|
||||
while (z + 1 <= zmax)
|
||||
{
|
||||
z++;
|
||||
i++;
|
||||
if (i % steps == step && (i % keepEvery == 0 && i % skipEvery != 0)) ret.add(new Location(world, x + 0.5, y + 0.5, z + 0.5));
|
||||
}
|
||||
|
||||
// Add #3
|
||||
while (x - 1 >= xmin)
|
||||
{
|
||||
x--;
|
||||
i++;
|
||||
if (i % steps == step && (i % keepEvery == 0 && i % skipEvery != 0)) ret.add(new Location(world, x + 0.5, y + 0.5, z + 0.5));
|
||||
}
|
||||
|
||||
// Add #4
|
||||
while (z - 1 >= zmin)
|
||||
{
|
||||
z--;
|
||||
i++;
|
||||
if (i % steps == step && (i % keepEvery == 0 && i % skipEvery != 0)) ret.add(new Location(world, x + 0.5, y + 0.5, z + 0.5));
|
||||
}
|
||||
|
||||
// Return Ret
|
||||
return ret;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user