Remove ID update. Add NPC awareness.

This commit is contained in:
Olof Larsson 2015-05-16 12:19:36 +02:00
parent 24344ab6c8
commit a9b80dacfe
14 changed files with 44 additions and 123 deletions

View File

@ -7,6 +7,7 @@ import org.bukkit.command.CommandSender;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.massivecore.Predictate; import com.massivecraft.massivecore.Predictate;
import com.massivecraft.massivecore.util.MUtil;
public class FactionEqualsPredictate implements Predictate<CommandSender>, Serializable public class FactionEqualsPredictate implements Predictate<CommandSender>, Serializable
{ {
@ -35,6 +36,7 @@ public class FactionEqualsPredictate implements Predictate<CommandSender>, Seria
@Override @Override
public boolean apply(CommandSender sender) public boolean apply(CommandSender sender)
{ {
if (MUtil.isNpc(sender)) return false;
MPlayer mplayer = MPlayer.get(sender); MPlayer mplayer = MPlayer.get(sender);
return this.factionId.equals(mplayer.getFactionId()); return this.factionId.equals(mplayer.getFactionId());
} }

View File

@ -24,7 +24,6 @@ import com.massivecraft.factions.cmd.*;
import com.massivecraft.factions.engine.EngineChat; import com.massivecraft.factions.engine.EngineChat;
import com.massivecraft.factions.engine.EngineEcon; import com.massivecraft.factions.engine.EngineEcon;
import com.massivecraft.factions.engine.EngineExploit; import com.massivecraft.factions.engine.EngineExploit;
import com.massivecraft.factions.engine.EngineIdUpdate;
import com.massivecraft.factions.engine.EngineMain; import com.massivecraft.factions.engine.EngineMain;
import com.massivecraft.factions.engine.EngineSeeChunk; import com.massivecraft.factions.engine.EngineSeeChunk;
import com.massivecraft.factions.entity.Board; import com.massivecraft.factions.entity.Board;
@ -149,7 +148,6 @@ public class Factions extends MassivePlugin
EngineMain.get().activate(); EngineMain.get().activate();
EngineChat.get().activate(); EngineChat.get().activate();
EngineExploit.get().activate(); EngineExploit.get().activate();
EngineIdUpdate.get().activate();
EngineSeeChunk.get().activate(); EngineSeeChunk.get().activate();
EngineEcon.get().activate(); // TODO: Take an extra look and make sure all economy stuff is handled using events. EngineEcon.get().activate(); // TODO: Take an extra look and make sure all economy stuff is handled using events.

View File

@ -17,7 +17,7 @@ public class TerritoryAccess
// FIELDS: RAW // FIELDS: RAW
// -------------------------------------------- // // -------------------------------------------- //
// TODO: remake private final // TODO: Remake private final
// no default value, can't be null // no default value, can't be null
public String hostFactionId; public String hostFactionId;
public String getHostFactionId() { return this.hostFactionId; } public String getHostFactionId() { return this.hostFactionId; }
@ -26,14 +26,13 @@ public class TerritoryAccess
private final boolean hostFactionAllowed; private final boolean hostFactionAllowed;
public boolean isHostFactionAllowed() { return this.hostFactionAllowed; } public boolean isHostFactionAllowed() { return this.hostFactionAllowed; }
// TODO: remake private final // TODO: Remake private final
// default is empty // default is empty
public Set<String> factionIds; public Set<String> factionIds;
public Set<String> getFactionIds() { return this.factionIds; } public Set<String> getFactionIds() { return this.factionIds; }
// TODO: remake private final
// default is empty // default is empty
public Set<String> playerIds; private final Set<String> playerIds;
public Set<String> getPlayerIds() { return this.playerIds; } public Set<String> getPlayerIds() { return this.playerIds; }
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -23,6 +23,7 @@ import com.massivecraft.massivecore.mixin.TeleporterException;
import com.massivecraft.massivecore.ps.PS; import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.teleport.Destination; import com.massivecraft.massivecore.teleport.Destination;
import com.massivecraft.massivecore.teleport.DestinationSimple; import com.massivecraft.massivecore.teleport.DestinationSimple;
import com.massivecraft.massivecore.util.MUtil;
public class CmdFactionsHome extends FactionsCommandHome public class CmdFactionsHome extends FactionsCommandHome
@ -119,6 +120,8 @@ public class CmdFactionsHome extends FactionsCommandHome
for (Player p : me.getServer().getOnlinePlayers()) for (Player p : me.getServer().getOnlinePlayers())
{ {
if (MUtil.isNpc(p)) continue;
if (p == null || !p.isOnline() || p.isDead() || p == me || p.getWorld() != w) if (p == null || !p.isOnline() || p.isDead() || p == me || p.getWorld() != w)
continue; continue;

View File

@ -10,6 +10,7 @@ import org.bukkit.command.CommandSender;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.FactionColl; import com.massivecraft.factions.entity.FactionColl;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.factions.entity.MPlayerColl;
import com.massivecraft.massivecore.CaseInsensitiveComparator; import com.massivecraft.massivecore.CaseInsensitiveComparator;
import com.massivecraft.massivecore.MassiveCore; import com.massivecraft.massivecore.MassiveCore;
import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.MassiveException;
@ -53,7 +54,7 @@ public class ARFaction extends ARAbstract<Faction>
// MPlayer Name Exact // MPlayer Name Exact
String id = IdUtil.getId(str); String id = IdUtil.getId(str);
MPlayer mplayer = MPlayer.get(id); MPlayer mplayer = MPlayerColl.get().get(id, false);
if (mplayer != null) if (mplayer != null)
{ {
return mplayer.getFaction(); return mplayer.getFaction();

View File

@ -5,6 +5,7 @@ import org.bukkit.command.CommandSender;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.cmd.MassiveCommand; import com.massivecraft.massivecore.cmd.MassiveCommand;
import com.massivecraft.massivecore.cmd.req.ReqAbstract; import com.massivecraft.massivecore.cmd.req.ReqAbstract;
import com.massivecraft.massivecore.util.MUtil;
import com.massivecraft.massivecore.util.Txt; import com.massivecraft.massivecore.util.Txt;
public class ReqHasFaction extends ReqAbstract public class ReqHasFaction extends ReqAbstract
@ -25,7 +26,9 @@ public class ReqHasFaction extends ReqAbstract
@Override @Override
public boolean apply(CommandSender sender, MassiveCommand command) public boolean apply(CommandSender sender, MassiveCommand command)
{ {
return MPlayer.get(sender).hasFaction(); if (MUtil.isNpc(sender)) return false;
MPlayer mplayer = MPlayer.get(sender);
return mplayer.hasFaction();
} }
@Override @Override

View File

@ -5,6 +5,7 @@ import org.bukkit.command.CommandSender;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.cmd.MassiveCommand; import com.massivecraft.massivecore.cmd.MassiveCommand;
import com.massivecraft.massivecore.cmd.req.ReqAbstract; import com.massivecraft.massivecore.cmd.req.ReqAbstract;
import com.massivecraft.massivecore.util.MUtil;
import com.massivecraft.massivecore.util.Txt; import com.massivecraft.massivecore.util.Txt;
public class ReqHasntFaction extends ReqAbstract public class ReqHasntFaction extends ReqAbstract
@ -25,7 +26,9 @@ public class ReqHasntFaction extends ReqAbstract
@Override @Override
public boolean apply(CommandSender sender, MassiveCommand command) public boolean apply(CommandSender sender, MassiveCommand command)
{ {
return !MPlayer.get(sender).hasFaction(); if (MUtil.isNpc(sender)) return true;
MPlayer mplayer = MPlayer.get(sender);
return !mplayer.hasFaction();
} }
@Override @Override

View File

@ -6,6 +6,7 @@ import com.massivecraft.factions.Rel;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.cmd.MassiveCommand; import com.massivecraft.massivecore.cmd.MassiveCommand;
import com.massivecraft.massivecore.cmd.req.ReqAbstract; import com.massivecraft.massivecore.cmd.req.ReqAbstract;
import com.massivecraft.massivecore.util.MUtil;
import com.massivecraft.massivecore.util.Txt; import com.massivecraft.massivecore.util.Txt;
public class ReqRoleIsAtLeast extends ReqAbstract public class ReqRoleIsAtLeast extends ReqAbstract
@ -33,6 +34,7 @@ public class ReqRoleIsAtLeast extends ReqAbstract
@Override @Override
public boolean apply(CommandSender sender, MassiveCommand command) public boolean apply(CommandSender sender, MassiveCommand command)
{ {
if (MUtil.isNpc(sender)) return false;
MPlayer mplayer = MPlayer.get(sender); MPlayer mplayer = MPlayer.get(sender);
return mplayer.getRole().isAtLeast(this.rel); return mplayer.getRole().isAtLeast(this.rel);
} }

View File

@ -1,6 +1,7 @@
package com.massivecraft.factions.engine; package com.massivecraft.factions.engine;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.EventException; import org.bukkit.event.EventException;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
@ -14,6 +15,7 @@ import com.massivecraft.factions.chat.ChatFormatter;
import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.entity.MConf;
import com.massivecraft.massivecore.EngineAbstract; import com.massivecraft.massivecore.EngineAbstract;
import com.massivecraft.massivecore.event.EventMassiveCorePlayerToRecipientChat; import com.massivecraft.massivecore.event.EventMassiveCorePlayerToRecipientChat;
import com.massivecraft.massivecore.util.MUtil;
public class EngineChat extends EngineAbstract public class EngineChat extends EngineAbstract
{ {
@ -104,8 +106,11 @@ public class EngineChat extends EngineAbstract
public static void parseTags(AsyncPlayerChatEvent event) public static void parseTags(AsyncPlayerChatEvent event)
{ {
Player player = event.getPlayer();
if (MUtil.isNpc(player)) return;
String format = event.getFormat(); String format = event.getFormat();
format = ChatFormatter.format(format, event.getPlayer(), null); format = ChatFormatter.format(format, player, null);
event.setFormat(format); event.setFormat(format);
} }

View File

@ -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;
}
}

View File

@ -345,6 +345,7 @@ public class EngineMain extends EngineAbstract
public static void updateLastActivity(CommandSender sender) public static void updateLastActivity(CommandSender sender)
{ {
if (sender == null) throw new RuntimeException("sender"); if (sender == null) throw new RuntimeException("sender");
if (MUtil.isNpc(sender)) return;
MPlayer mplayer = MPlayer.get(sender); MPlayer mplayer = MPlayer.get(sender);
mplayer.setLastActivityMillis(); mplayer.setLastActivityMillis();
} }
@ -389,6 +390,7 @@ public class EngineMain extends EngineAbstract
{ {
// Gather info ... // Gather info ...
final Player player = event.getPlayer(); final Player player = event.getPlayer();
if (MUtil.isNpc(player)) return;
final MPlayer mplayer = MPlayer.get(player); final MPlayer mplayer = MPlayer.get(player);
final Faction faction = mplayer.getFaction(); final Faction faction = mplayer.getFaction();
@ -662,6 +664,7 @@ public class EngineMain extends EngineAbstract
// If the player is moving from one chunk to another ... // If the player is moving from one chunk to another ...
if (MUtil.isSameChunk(event)) return; if (MUtil.isSameChunk(event)) return;
Player player = event.getPlayer(); Player player = event.getPlayer();
if (MUtil.isNpc(player)) return;
// ... gather info on the player and the move ... // ... gather info on the player and the move ...
MPlayer mplayer = MPlayer.get(player); MPlayer mplayer = MPlayer.get(player);
@ -769,6 +772,7 @@ public class EngineMain extends EngineAbstract
{ {
// If a player dies ... // If a player dies ...
Player player = event.getEntity(); Player player = event.getEntity();
if (MUtil.isNpc(player)) return;
// ... and this is the first death event this tick ... // ... and this is the first death event this tick ...
// (yeah other plugins can case death event to fire twice the same tick) // (yeah other plugins can case death event to fire twice the same tick)
@ -870,6 +874,7 @@ public class EngineMain extends EngineAbstract
Entity edefender = event.getEntity(); Entity edefender = event.getEntity();
if (!(edefender instanceof Player)) return true; if (!(edefender instanceof Player)) return true;
Player defender = (Player)edefender; Player defender = (Player)edefender;
if (MUtil.isNpc(defender)) return true;
MPlayer mdefender = MPlayer.get(edefender); MPlayer mdefender = MPlayer.get(edefender);
// ... and the attacker is someone else ... // ... and the attacker is someone else ...
@ -992,6 +997,7 @@ public class EngineMain extends EngineAbstract
Entity entity = event.getEntity(); Entity entity = event.getEntity();
if (!(entity instanceof Player)) return; if (!(entity instanceof Player)) return;
Player player = (Player)entity; Player player = (Player)entity;
if (MUtil.isNpc(player)) return;
MPlayer mplayer = MPlayer.get(player); MPlayer mplayer = MPlayer.get(player);
// ... and that player has a faction ... // ... and that player has a faction ...
@ -1063,7 +1069,7 @@ public class EngineMain extends EngineAbstract
{ {
// If a player is trying to run a command ... // If a player is trying to run a command ...
Player player = event.getPlayer(); Player player = event.getPlayer();
if (MUtil.isNpc(player)) return;
MPlayer mplayer = MPlayer.get(player); MPlayer mplayer = MPlayer.get(player);
// ... and the player does not have adminmode ... // ... and the player does not have adminmode ...
@ -1488,6 +1494,8 @@ public class EngineMain extends EngineAbstract
public static boolean playerCanUseItemHere(Player player, PS ps, Material material, boolean verboose) public static boolean playerCanUseItemHere(Player player, PS ps, Material material, boolean verboose)
{ {
if (MUtil.isNpc(player)) return true;
if ( ! MConf.get().materialsEditTools.contains(material) && ! MConf.get().materialsEditToolsDupeBug.contains(material)) return true; if ( ! MConf.get().materialsEditTools.contains(material) && ! MConf.get().materialsEditToolsDupeBug.contains(material)) return true;
String name = player.getName(); String name = player.getName();
@ -1501,6 +1509,8 @@ public class EngineMain extends EngineAbstract
public static boolean canPlayerUseBlock(Player player, Block block, boolean verboose) public static boolean canPlayerUseBlock(Player player, Block block, boolean verboose)
{ {
if (MUtil.isNpc(player)) return true;
String name = player.getName(); String name = player.getName();
if (MConf.get().playersWhoBypassAllProtection.contains(name)) return true; if (MConf.get().playersWhoBypassAllProtection.contains(name)) return true;
@ -1539,6 +1549,7 @@ public class EngineMain extends EngineAbstract
{ {
// If a player ... // If a player ...
if (player == null) return true; if (player == null) return true;
if (MUtil.isNpc(player)) return true;
// ... interacts with an entity ... // ... interacts with an entity ...
if (entity == null) return true; if (entity == null) return true;
@ -1595,6 +1606,7 @@ public class EngineMain extends EngineAbstract
{ {
// If a player is respawning ... // If a player is respawning ...
final Player player = event.getPlayer(); final Player player = event.getPlayer();
if (MUtil.isNpc(player)) return;
final MPlayer mplayer = MPlayer.get(player); final MPlayer mplayer = MPlayer.get(player);
// ... homes are enabled, active and at this priority ... // ... homes are enabled, active and at this priority ...

View File

@ -1077,6 +1077,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
List<CommandSender> ret = new ArrayList<CommandSender>(); List<CommandSender> ret = new ArrayList<CommandSender>();
for (CommandSender player : IdUtil.getOnlineSenders()) for (CommandSender player : IdUtil.getOnlineSenders())
{ {
if (MUtil.isNpc(player)) continue;
MPlayer mplayer = MPlayer.get(player); MPlayer mplayer = MPlayer.get(player);
if (mplayer.getFaction() != this) continue; if (mplayer.getFaction() != this) continue;
ret.add(player); ret.add(player);
@ -1089,6 +1090,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
List<Player> ret = new ArrayList<Player>(); List<Player> ret = new ArrayList<Player>();
for (Player player : MUtil.getOnlinePlayers()) for (Player player : MUtil.getOnlinePlayers())
{ {
if (MUtil.isNpc(player)) continue;
MPlayer mplayer = MPlayer.get(player); MPlayer mplayer = MPlayer.get(player);
if (mplayer.getFaction() != this) continue; if (mplayer.getFaction() != this) continue;
ret.add(player); ret.add(player);

View File

@ -21,6 +21,7 @@ import com.massivecraft.factions.entity.MConf;
import com.massivecraft.factions.entity.MPerm; import com.massivecraft.factions.entity.MPerm;
import com.massivecraft.massivecore.EngineAbstract; import com.massivecraft.massivecore.EngineAbstract;
import com.massivecraft.massivecore.ps.PS; import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.util.MUtil;
public class EngineSpigot extends EngineAbstract public class EngineSpigot extends EngineAbstract
@ -70,6 +71,7 @@ public class EngineSpigot extends EngineAbstract
{ {
// Gather Info // Gather Info
final Player player = event.getPlayer(); final Player player = event.getPlayer();
if (MUtil.isNpc(player)) return;
final Entity entity = event.getRightClicked(); final Entity entity = event.getRightClicked();
final boolean verboose = true; final boolean verboose = true;

View File

@ -50,6 +50,7 @@ public class TaskPlayerPowerUpdate extends ModuloRepeatTask
for (Player player : MUtil.getOnlinePlayers()) for (Player player : MUtil.getOnlinePlayers())
{ {
if (MUtil.isNpc(player)) continue;
if (player.isDead()) continue; if (player.isDead()) continue;
MPlayer mplayer = MPlayer.get(player); MPlayer mplayer = MPlayer.get(player);