Remove ID update. Add NPC awareness.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.massivecraft.factions.engine;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.EventException;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@@ -14,6 +15,7 @@ import com.massivecraft.factions.chat.ChatFormatter;
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
import com.massivecraft.massivecore.EngineAbstract;
|
||||
import com.massivecraft.massivecore.event.EventMassiveCorePlayerToRecipientChat;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
|
||||
public class EngineChat extends EngineAbstract
|
||||
{
|
||||
@@ -104,8 +106,11 @@ public class EngineChat extends EngineAbstract
|
||||
|
||||
public static void parseTags(AsyncPlayerChatEvent event)
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
if (MUtil.isNpc(player)) return;
|
||||
|
||||
String format = event.getFormat();
|
||||
format = ChatFormatter.format(format, event.getPlayer(), null);
|
||||
format = ChatFormatter.format(format, player, null);
|
||||
event.setFormat(format);
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
}
|
@@ -345,6 +345,7 @@ public class EngineMain extends EngineAbstract
|
||||
public static void updateLastActivity(CommandSender sender)
|
||||
{
|
||||
if (sender == null) throw new RuntimeException("sender");
|
||||
if (MUtil.isNpc(sender)) return;
|
||||
MPlayer mplayer = MPlayer.get(sender);
|
||||
mplayer.setLastActivityMillis();
|
||||
}
|
||||
@@ -389,6 +390,7 @@ public class EngineMain extends EngineAbstract
|
||||
{
|
||||
// Gather info ...
|
||||
final Player player = event.getPlayer();
|
||||
if (MUtil.isNpc(player)) return;
|
||||
final MPlayer mplayer = MPlayer.get(player);
|
||||
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 (MUtil.isSameChunk(event)) return;
|
||||
Player player = event.getPlayer();
|
||||
if (MUtil.isNpc(player)) return;
|
||||
|
||||
// ... gather info on the player and the move ...
|
||||
MPlayer mplayer = MPlayer.get(player);
|
||||
@@ -769,6 +772,7 @@ public class EngineMain extends EngineAbstract
|
||||
{
|
||||
// If a player dies ...
|
||||
Player player = event.getEntity();
|
||||
if (MUtil.isNpc(player)) return;
|
||||
|
||||
// ... and this is the first death event this 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();
|
||||
if (!(edefender instanceof Player)) return true;
|
||||
Player defender = (Player)edefender;
|
||||
if (MUtil.isNpc(defender)) return true;
|
||||
MPlayer mdefender = MPlayer.get(edefender);
|
||||
|
||||
// ... and the attacker is someone else ...
|
||||
@@ -992,6 +997,7 @@ public class EngineMain extends EngineAbstract
|
||||
Entity entity = event.getEntity();
|
||||
if (!(entity instanceof Player)) return;
|
||||
Player player = (Player)entity;
|
||||
if (MUtil.isNpc(player)) return;
|
||||
MPlayer mplayer = MPlayer.get(player);
|
||||
|
||||
// ... and that player has a faction ...
|
||||
@@ -1063,7 +1069,7 @@ public class EngineMain extends EngineAbstract
|
||||
{
|
||||
// If a player is trying to run a command ...
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (MUtil.isNpc(player)) return;
|
||||
MPlayer mplayer = MPlayer.get(player);
|
||||
|
||||
// ... 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)
|
||||
{
|
||||
if (MUtil.isNpc(player)) return true;
|
||||
|
||||
if ( ! MConf.get().materialsEditTools.contains(material) && ! MConf.get().materialsEditToolsDupeBug.contains(material)) return true;
|
||||
|
||||
String name = player.getName();
|
||||
@@ -1501,6 +1509,8 @@ public class EngineMain extends EngineAbstract
|
||||
|
||||
public static boolean canPlayerUseBlock(Player player, Block block, boolean verboose)
|
||||
{
|
||||
if (MUtil.isNpc(player)) return true;
|
||||
|
||||
String name = player.getName();
|
||||
if (MConf.get().playersWhoBypassAllProtection.contains(name)) return true;
|
||||
|
||||
@@ -1539,6 +1549,7 @@ public class EngineMain extends EngineAbstract
|
||||
{
|
||||
// If a player ...
|
||||
if (player == null) return true;
|
||||
if (MUtil.isNpc(player)) return true;
|
||||
|
||||
// ... interacts with an entity ...
|
||||
if (entity == null) return true;
|
||||
@@ -1595,6 +1606,7 @@ public class EngineMain extends EngineAbstract
|
||||
{
|
||||
// If a player is respawning ...
|
||||
final Player player = event.getPlayer();
|
||||
if (MUtil.isNpc(player)) return;
|
||||
final MPlayer mplayer = MPlayer.get(player);
|
||||
|
||||
// ... homes are enabled, active and at this priority ...
|
||||
|
Reference in New Issue
Block a user