Add new player update task for players not on the playerlist

This commit is contained in:
fullwall 2016-03-02 13:53:18 +08:00
parent a320832c4d
commit 8e85dde59b
5 changed files with 76 additions and 3 deletions

View File

@ -58,6 +58,7 @@ import net.citizensnpcs.npc.profile.ProfileFetcher;
import net.citizensnpcs.npc.skin.Skin;
import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.PlayerUpdateTask;
import net.citizensnpcs.util.StringHelper;
import net.citizensnpcs.util.Util;
import net.milkbowl.vault.economy.Economy;
@ -297,6 +298,7 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
startMetrics();
scheduleSaveTask(Setting.SAVE_TASK_DELAY.asInt());
Bukkit.getPluginManager().callEvent(new CitizensEnableEvent());
new PlayerUpdateTask().runTaskTimer(Citizens.this, 0, 1);
}
}, 1) == -1) {
Messaging.severeTr(Messages.LOAD_TASK_NOT_SCHEDULED);

View File

@ -101,6 +101,7 @@ public class NMS {
} else if (!handle.world.players.contains(handle)) {
handle.world.players.add(handle);
}
PlayerUpdateTask.addOrRemove(entity, remove);
}
public static boolean addToWorld(org.bukkit.World world, org.bukkit.entity.Entity entity,

View File

@ -0,0 +1,60 @@
package net.citizensnpcs.util;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.bukkit.scheduler.BukkitRunnable;
import net.minecraft.server.v1_9_R1.CrashReport;
import net.minecraft.server.v1_9_R1.CrashReportSystemDetails;
import net.minecraft.server.v1_9_R1.Entity;
import net.minecraft.server.v1_9_R1.ReportedException;
public class PlayerUpdateTask extends BukkitRunnable {
@Override
public void cancel() {
super.cancel();
TICKERS.clear();
}
@Override
public void run() {
Iterator<org.bukkit.entity.Entity> itr = TICKERS.iterator();
while (itr.hasNext()) {
Entity entity = NMS.getHandle(itr.next());
Entity entity1 = entity.by();
if (entity1 != null) {
if ((entity1.dead) || (!entity1.w(entity))) {
entity.stopRiding();
}
} else {
if (!entity.dead) {
try {
entity.world.g(entity);
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.a(throwable, "Ticking player");
CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Player being ticked");
entity.appendEntityCrashDetails(crashreportsystemdetails);
throw new ReportedException(crashreport);
}
}
if (entity.dead) {
entity.world.removeEntity(entity);
itr.remove();
}
}
}
}
public static void addOrRemove(org.bukkit.entity.Entity entity, boolean remove) {
if (remove) {
TICKERS.remove(entity);
} else {
TICKERS.add(entity);
}
}
private static List<org.bukkit.entity.Entity> TICKERS = new ArrayList<org.bukkit.entity.Entity>();
}

View File

@ -3,7 +3,6 @@ package net.citizensnpcs.util.nms;
import net.citizensnpcs.npc.entity.EntityHumanNPC;
import net.minecraft.server.v1_9_R1.EntityInsentient;
import net.minecraft.server.v1_9_R1.IBlockAccess;
import net.minecraft.server.v1_9_R1.IntHashMap;
import net.minecraft.server.v1_9_R1.MathHelper;
import net.minecraft.server.v1_9_R1.PathPoint;
import net.minecraft.server.v1_9_R1.PathType;
@ -12,7 +11,6 @@ import net.minecraft.server.v1_9_R1.PathfinderAbstract;
public abstract class PlayerPathfinderAbstract extends PathfinderAbstract {
protected IBlockAccess a;
protected EntityHumanNPC b;
protected final IntHashMap<PathPoint> c = new IntHashMap();
protected int d;
protected int e;
protected int f;
@ -20,13 +18,16 @@ public abstract class PlayerPathfinderAbstract extends PathfinderAbstract {
protected boolean h;
protected boolean i;
@Override
public void a() {
}
@Override
public void a(boolean paramBoolean) {
this.g = paramBoolean;
}
@Override
public abstract PathPoint a(double paramDouble1, double paramDouble2, double paramDouble3);
public void a(IBlockAccess paramIBlockAccess, EntityHumanNPC paramEntityInsentient) {
@ -43,10 +44,12 @@ public abstract class PlayerPathfinderAbstract extends PathfinderAbstract {
EntityHumanNPC paramEntityInsentient, int paramInt4, int paramInt5, int paramInt6, boolean paramBoolean1,
boolean paramBoolean2);
@Override
public abstract PathType a(IBlockAccess paramIBlockAccess, int paramInt1, int paramInt2, int paramInt3,
EntityInsentient paramEntityInsentient, int paramInt4, int paramInt5, int paramInt6, boolean paramBoolean1,
boolean paramBoolean2);
@Override
protected PathPoint a(int paramInt1, int paramInt2, int paramInt3) {
int j = PathPoint.b(paramInt1, paramInt2, paramInt3);
PathPoint localPathPoint = this.c.get(j);
@ -57,27 +60,34 @@ public abstract class PlayerPathfinderAbstract extends PathfinderAbstract {
return localPathPoint;
}
@Override
public abstract int a(PathPoint[] paramArrayOfPathPoint, PathPoint paramPathPoint1, PathPoint paramPathPoint2,
float paramFloat);
@Override
public abstract PathPoint b();
@Override
public void b(boolean paramBoolean) {
this.h = paramBoolean;
}
@Override
public boolean c() {
return this.g;
}
@Override
public void c(boolean paramBoolean) {
this.i = paramBoolean;
}
@Override
public boolean d() {
return this.h;
}
@Override
public boolean e() {
return this.i;
}

View File

@ -341,7 +341,7 @@ public class PlayerPathfinderNormal extends PlayerPathfinderAbstract {
localObject1 = new BlockPosition(this.b);
Object localObject2 = a(this.b, localObject1.getX(), i, localObject1.getZ());
if (this.b.a((PathType) localObject2) < 0.0F) {
HashSet<BlockPosition> localHashSet = new HashSet();
HashSet<BlockPosition> localHashSet = new HashSet<BlockPosition>();
localHashSet.add(new BlockPosition(this.b.getBoundingBox().a, i, this.b.getBoundingBox().c));
localHashSet.add(new BlockPosition(this.b.getBoundingBox().a, i, this.b.getBoundingBox().f));
localHashSet.add(new BlockPosition(this.b.getBoundingBox().d, i, this.b.getBoundingBox().c));