mirror of
https://github.com/Elecast2/EntityTrackerFixer.git
synced 2024-11-29 05:15:16 +01:00
Removed experimental option for 1.14 and 1.15 and fixed for 1.16
This commit is contained in:
parent
a15074bda0
commit
c118a77c2a
@ -9,7 +9,7 @@
|
|||||||
log-to-console: true
|
log-to-console: true
|
||||||
|
|
||||||
#disable tick for untracked entities (experimental, use at your own risk)
|
#disable tick for untracked entities (experimental, use at your own risk)
|
||||||
disable-tick-for-untracked-entities: false
|
disable-tick-for-untracked-entities: true
|
||||||
|
|
||||||
#How many ticks between untrack process
|
#How many ticks between untrack process
|
||||||
#The untrack process will check for untracked entities by players but still by the server, and untrack them.
|
#The untrack process will check for untracked entities by players but still by the server, and untrack them.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
name: EntityTrackerFixer
|
name: EntityTrackerFixer
|
||||||
main: net.minemora.entitytrackerfixer.EntityTrackerFixer
|
main: net.minemora.entitytrackerfixer.EntityTrackerFixer
|
||||||
version: 1.2.3
|
version: 1.2.4
|
||||||
api-version: 1.14
|
api-version: 1.16
|
||||||
author: Esmorall
|
author: Esmorall
|
||||||
description: Untrack entities that are not used at all by the server.
|
description: Untrack entities that are not used at all by the server.
|
||||||
commands:
|
commands:
|
@ -15,9 +15,6 @@ public class EntityTrackerFixer extends JavaPlugin {
|
|||||||
plugin = this;
|
plugin = this;
|
||||||
ConfigMain.getInstance().setup(this);
|
ConfigMain.getInstance().setup(this);
|
||||||
NMS nms = NMSCheck.getNMS(this);
|
NMS nms = NMSCheck.getNMS(this);
|
||||||
if(ConfigMain.isDisableTickUntracked()) {
|
|
||||||
nms.loadWorldCache();
|
|
||||||
}
|
|
||||||
nms.startTasks(this);
|
nms.startTasks(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ public final class ConfigMain extends Config {
|
|||||||
minTps = getConfig().getDouble("tps-limit", 18.5);
|
minTps = getConfig().getDouble("tps-limit", 18.5);
|
||||||
worlds = getConfig().getStringList("worlds");
|
worlds = getConfig().getStringList("worlds");
|
||||||
logToConsole = getConfig().getBoolean("log-to-console", true);
|
logToConsole = getConfig().getBoolean("log-to-console", true);
|
||||||
disableTickUntracked = getConfig().getBoolean("disable-tick-for-untracked-entities", false);
|
disableTickUntracked = getConfig().getBoolean("disable-tick-for-untracked-entities", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FileConfiguration get() {
|
public static FileConfiguration get() {
|
||||||
|
@ -5,7 +5,4 @@ import org.bukkit.plugin.Plugin;
|
|||||||
public interface NMS {
|
public interface NMS {
|
||||||
|
|
||||||
public void startTasks(Plugin plugin);
|
public void startTasks(Plugin plugin);
|
||||||
|
|
||||||
public void loadWorldCache();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,9 @@
|
|||||||
package net.minemora.entitytrackerfixer.v1_14_R1;
|
package net.minemora.entitytrackerfixer.v1_14_R1;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.craftbukkit.v1_14_R1.CraftWorld;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import net.minemora.entitytrackerfixer.config.ConfigMain;
|
import net.minemora.entitytrackerfixer.config.ConfigMain;
|
||||||
import net.minemora.entitytrackerfixer.nms.NMS;
|
import net.minemora.entitytrackerfixer.nms.NMS;
|
||||||
import net.minemora.entitytrackerfixer.v1_14_R1.entityTick.EntityTickManager;
|
|
||||||
import net.minemora.entitytrackerfixer.v1_14_R1.entityTick.EntityTickWorldCache;
|
|
||||||
import net.minemora.entitytrackerfixer.v1_14_R1.tasks.CheckTask;
|
import net.minemora.entitytrackerfixer.v1_14_R1.tasks.CheckTask;
|
||||||
import net.minemora.entitytrackerfixer.v1_14_R1.tasks.UntrackerTask;
|
import net.minemora.entitytrackerfixer.v1_14_R1.tasks.UntrackerTask;
|
||||||
|
|
||||||
@ -19,15 +15,4 @@ public class NMSHandler implements NMS {
|
|||||||
new CheckTask().runTaskTimer(plugin, ConfigMain.getUntrackTicks() + 1, ConfigMain.getCheckFrequency());
|
new CheckTask().runTaskTimer(plugin, ConfigMain.getUntrackTicks() + 1, ConfigMain.getCheckFrequency());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void loadWorldCache() {
|
|
||||||
for(String worldName : ConfigMain.getWorlds()) {
|
|
||||||
if(Bukkit.getWorld(worldName) == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
EntityTickManager.getInstance().getCache().put(worldName,
|
|
||||||
new EntityTickWorldCache(((CraftWorld)Bukkit.getWorld(worldName)).getHandle()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,105 +0,0 @@
|
|||||||
package net.minemora.entitytrackerfixer.v1_14_R1.entityTick;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
|
||||||
|
|
||||||
import net.minecraft.server.v1_14_R1.WorldServer;
|
|
||||||
import net.minemora.entitytrackerfixer.EntityTrackerFixer;
|
|
||||||
import net.minemora.entitytrackerfixer.util.ReflectionUtils;
|
|
||||||
import net.minemora.entitytrackerfixer.v1_14_R1.tasks.UntrackerTask;
|
|
||||||
|
|
||||||
public class EntityTickManager extends BukkitRunnable {
|
|
||||||
|
|
||||||
private static Field tickingEntitiesField;
|
|
||||||
private static Field entityCount;
|
|
||||||
|
|
||||||
static {
|
|
||||||
try {
|
|
||||||
tickingEntitiesField = ReflectionUtils.getClassPrivateField(WorldServer.class, "tickingEntities");
|
|
||||||
entityCount = ReflectionUtils.getClassPrivateField(net.minecraft.server.v1_14_R1.Entity.class, "entityCount");
|
|
||||||
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static EntityTickManager instance;
|
|
||||||
|
|
||||||
private Map<String, EntityTickWorldCache> cache = new HashMap<>();
|
|
||||||
|
|
||||||
private EntityTickManager(Plugin plugin) {
|
|
||||||
this.runTaskTimer(plugin, 61, 61);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void disableTicking(int id, String worldName) {
|
|
||||||
cache.get(worldName).getToTick().remove(id);
|
|
||||||
cache.get(worldName).getToUntick().add(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void enableTicking(net.minecraft.server.v1_14_R1.Entity entity, String worldName) {
|
|
||||||
cache.get(worldName).getToUntick().remove(entity.getId());
|
|
||||||
cache.get(worldName).getToTick().put(entity.getId(), entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if(UntrackerTask.isRunning()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for(String worldName : cache.keySet()) {
|
|
||||||
EntityTickWorldCache ewc = cache.get(worldName);
|
|
||||||
WorldServer ws = ewc.getWorldServer();
|
|
||||||
if(ws.b()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
if(tickingEntitiesField.getBoolean(ws)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
//System.out.println("unticking: " + ewc.getToUntick().size() + " entities, ticking again: " + ewc.getToTick().size() + " entities");
|
|
||||||
for(int i : ewc.getToUntick()) {
|
|
||||||
ws.entitiesById.remove(i);
|
|
||||||
}
|
|
||||||
ewc.getToUntick().clear();
|
|
||||||
for(int i : ewc.getToTick().keySet()) {
|
|
||||||
net.minecraft.server.v1_14_R1.Entity entity = ewc.getToTick().get(i);
|
|
||||||
if(entity == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(!entity.valid) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(ws.entitiesById.containsValue(entity)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(ws.entitiesById.containsKey(i)) {
|
|
||||||
int id = ((AtomicInteger)entityCount.get(null)).incrementAndGet();
|
|
||||||
ws.entitiesById.put(id, entity);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ws.entitiesById.put(i, entity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ewc.getToTick().clear();
|
|
||||||
} catch (IllegalArgumentException | IllegalAccessException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static EntityTickManager getInstance() {
|
|
||||||
if(instance == null) {
|
|
||||||
instance = new EntityTickManager(EntityTrackerFixer.plugin);
|
|
||||||
}
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, EntityTickWorldCache> getCache() {
|
|
||||||
return cache;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,38 +0,0 @@
|
|||||||
package net.minemora.entitytrackerfixer.v1_14_R1.entityTick;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import net.minecraft.server.v1_14_R1.WorldServer;
|
|
||||||
|
|
||||||
public class EntityTickWorldCache {
|
|
||||||
|
|
||||||
private String worldName;
|
|
||||||
private WorldServer worldServer;
|
|
||||||
|
|
||||||
private Set<Integer> toUntick = new HashSet<>();
|
|
||||||
private Map<Integer, net.minecraft.server.v1_14_R1.Entity> toTick = new HashMap<>();
|
|
||||||
|
|
||||||
public EntityTickWorldCache(WorldServer worldServer) {
|
|
||||||
this.worldName = worldServer.getWorld().getName();
|
|
||||||
this.worldServer = worldServer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<Integer> getToUntick() {
|
|
||||||
return toUntick;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<Integer, net.minecraft.server.v1_14_R1.Entity> getToTick() {
|
|
||||||
return toTick;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getWorldName() {
|
|
||||||
return worldName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public WorldServer getWorldServer() {
|
|
||||||
return worldServer;
|
|
||||||
}
|
|
||||||
}
|
|
@ -14,7 +14,6 @@ import net.minecraft.server.v1_14_R1.ChunkProviderServer;
|
|||||||
import net.minecraft.server.v1_14_R1.WorldServer;
|
import net.minecraft.server.v1_14_R1.WorldServer;
|
||||||
import net.minemora.entitytrackerfixer.config.ConfigMain;
|
import net.minemora.entitytrackerfixer.config.ConfigMain;
|
||||||
import net.minemora.entitytrackerfixer.v1_14_R1.NMSEntityTracker;
|
import net.minemora.entitytrackerfixer.v1_14_R1.NMSEntityTracker;
|
||||||
import net.minemora.entitytrackerfixer.v1_14_R1.entityTick.EntityTickManager;
|
|
||||||
|
|
||||||
public class CheckTask extends BukkitRunnable {
|
public class CheckTask extends BukkitRunnable {
|
||||||
|
|
||||||
@ -41,9 +40,6 @@ public class CheckTask extends BukkitRunnable {
|
|||||||
for(Player player : Bukkit.getWorld(worldName).getPlayers()) {
|
for(Player player : Bukkit.getWorld(worldName).getPlayers()) {
|
||||||
for(Entity ent : player.getNearbyEntities(d, d, d)) {
|
for(Entity ent : player.getNearbyEntities(d, d, d)) {
|
||||||
trackAgain.add(((CraftEntity)ent).getHandle());
|
trackAgain.add(((CraftEntity)ent).getHandle());
|
||||||
if(ConfigMain.isDisableTickUntracked()) {
|
|
||||||
EntityTickManager.getInstance().enableTicking(((CraftEntity)ent).getHandle(), worldName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
NMSEntityTracker.trackEntities(cps, trackAgain);
|
NMSEntityTracker.trackEntities(cps, trackAgain);
|
||||||
|
@ -18,7 +18,6 @@ import net.minecraft.server.v1_14_R1.EntityEnderDragon;
|
|||||||
import net.minemora.entitytrackerfixer.EntityTrackerFixer;
|
import net.minemora.entitytrackerfixer.EntityTrackerFixer;
|
||||||
import net.minemora.entitytrackerfixer.config.ConfigMain;
|
import net.minemora.entitytrackerfixer.config.ConfigMain;
|
||||||
import net.minemora.entitytrackerfixer.util.ReflectionUtils;
|
import net.minemora.entitytrackerfixer.util.ReflectionUtils;
|
||||||
import net.minemora.entitytrackerfixer.v1_14_R1.entityTick.EntityTickManager;
|
|
||||||
|
|
||||||
public class UntrackerTask extends BukkitRunnable {
|
public class UntrackerTask extends BukkitRunnable {
|
||||||
|
|
||||||
@ -94,9 +93,6 @@ public class UntrackerTask extends BukkitRunnable {
|
|||||||
|
|
||||||
for(int id : toRemove) {
|
for(int id : toRemove) {
|
||||||
cps.playerChunkMap.trackedEntities.remove(id);
|
cps.playerChunkMap.trackedEntities.remove(id);
|
||||||
if(ConfigMain.isDisableTickUntracked()) {
|
|
||||||
EntityTickManager.getInstance().disableTicking(id, worldName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -6,8 +6,6 @@ import org.bukkit.plugin.Plugin;
|
|||||||
|
|
||||||
import net.minemora.entitytrackerfixer.config.ConfigMain;
|
import net.minemora.entitytrackerfixer.config.ConfigMain;
|
||||||
import net.minemora.entitytrackerfixer.nms.NMS;
|
import net.minemora.entitytrackerfixer.nms.NMS;
|
||||||
import net.minemora.entitytrackerfixer.v1_15_R1.entityTick.EntityTickManager;
|
|
||||||
import net.minemora.entitytrackerfixer.v1_15_R1.entityTick.EntityTickWorldCache;
|
|
||||||
import net.minemora.entitytrackerfixer.v1_15_R1.tasks.CheckTask;
|
import net.minemora.entitytrackerfixer.v1_15_R1.tasks.CheckTask;
|
||||||
import net.minemora.entitytrackerfixer.v1_15_R1.tasks.UntrackerTask;
|
import net.minemora.entitytrackerfixer.v1_15_R1.tasks.UntrackerTask;
|
||||||
|
|
||||||
@ -19,15 +17,4 @@ public class NMSHandler implements NMS {
|
|||||||
new CheckTask().runTaskTimer(plugin, ConfigMain.getUntrackTicks() + 1, ConfigMain.getCheckFrequency());
|
new CheckTask().runTaskTimer(plugin, ConfigMain.getUntrackTicks() + 1, ConfigMain.getCheckFrequency());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void loadWorldCache() {
|
|
||||||
for(String worldName : ConfigMain.getWorlds()) {
|
|
||||||
if(Bukkit.getWorld(worldName) == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
EntityTickManager.getInstance().getCache().put(worldName,
|
|
||||||
new EntityTickWorldCache(((CraftWorld)Bukkit.getWorld(worldName)).getHandle()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,105 +0,0 @@
|
|||||||
package net.minemora.entitytrackerfixer.v1_15_R1.entityTick;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
|
||||||
|
|
||||||
import net.minecraft.server.v1_15_R1.WorldServer;
|
|
||||||
import net.minemora.entitytrackerfixer.EntityTrackerFixer;
|
|
||||||
import net.minemora.entitytrackerfixer.util.ReflectionUtils;
|
|
||||||
import net.minemora.entitytrackerfixer.v1_15_R1.tasks.UntrackerTask;
|
|
||||||
|
|
||||||
public class EntityTickManager extends BukkitRunnable {
|
|
||||||
|
|
||||||
private static Field tickingEntitiesField;
|
|
||||||
private static Field entityCount;
|
|
||||||
|
|
||||||
static {
|
|
||||||
try {
|
|
||||||
tickingEntitiesField = ReflectionUtils.getClassPrivateField(WorldServer.class, "tickingEntities");
|
|
||||||
entityCount = ReflectionUtils.getClassPrivateField(net.minecraft.server.v1_15_R1.Entity.class, "entityCount");
|
|
||||||
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static EntityTickManager instance;
|
|
||||||
|
|
||||||
private Map<String, EntityTickWorldCache> cache = new HashMap<>();
|
|
||||||
|
|
||||||
private EntityTickManager(Plugin plugin) {
|
|
||||||
this.runTaskTimer(plugin, 61, 61);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void disableTicking(int id, String worldName) {
|
|
||||||
cache.get(worldName).getToTick().remove(id);
|
|
||||||
cache.get(worldName).getToUntick().add(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void enableTicking(net.minecraft.server.v1_15_R1.Entity entity, String worldName) {
|
|
||||||
cache.get(worldName).getToUntick().remove(entity.getId());
|
|
||||||
cache.get(worldName).getToTick().put(entity.getId(), entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if(UntrackerTask.isRunning()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for(String worldName : cache.keySet()) {
|
|
||||||
EntityTickWorldCache ewc = cache.get(worldName);
|
|
||||||
WorldServer ws = ewc.getWorldServer();
|
|
||||||
if(ws.b()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
if(tickingEntitiesField.getBoolean(ws)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
//System.out.println("unticking: " + ewc.getToUntick().size() + " entities, ticking again: " + ewc.getToTick().size() + " entities");
|
|
||||||
for(int i : ewc.getToUntick()) {
|
|
||||||
ws.entitiesById.remove(i);
|
|
||||||
}
|
|
||||||
ewc.getToUntick().clear();
|
|
||||||
for(int i : ewc.getToTick().keySet()) {
|
|
||||||
net.minecraft.server.v1_15_R1.Entity entity = ewc.getToTick().get(i);
|
|
||||||
if(entity == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(!entity.valid) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(ws.entitiesById.containsValue(entity)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(ws.entitiesById.containsKey(i)) {
|
|
||||||
int id = ((AtomicInteger)entityCount.get(null)).incrementAndGet();
|
|
||||||
ws.entitiesById.put(id, entity);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ws.entitiesById.put(i, entity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ewc.getToTick().clear();
|
|
||||||
} catch (IllegalArgumentException | IllegalAccessException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static EntityTickManager getInstance() {
|
|
||||||
if(instance == null) {
|
|
||||||
instance = new EntityTickManager(EntityTrackerFixer.plugin);
|
|
||||||
}
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, EntityTickWorldCache> getCache() {
|
|
||||||
return cache;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,38 +0,0 @@
|
|||||||
package net.minemora.entitytrackerfixer.v1_15_R1.entityTick;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import net.minecraft.server.v1_15_R1.WorldServer;
|
|
||||||
|
|
||||||
public class EntityTickWorldCache {
|
|
||||||
|
|
||||||
private String worldName;
|
|
||||||
private WorldServer worldServer;
|
|
||||||
|
|
||||||
private Set<Integer> toUntick = new HashSet<>();
|
|
||||||
private Map<Integer, net.minecraft.server.v1_15_R1.Entity> toTick = new HashMap<>();
|
|
||||||
|
|
||||||
public EntityTickWorldCache(WorldServer worldServer) {
|
|
||||||
this.worldName = worldServer.getWorld().getName();
|
|
||||||
this.worldServer = worldServer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<Integer> getToUntick() {
|
|
||||||
return toUntick;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<Integer, net.minecraft.server.v1_15_R1.Entity> getToTick() {
|
|
||||||
return toTick;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getWorldName() {
|
|
||||||
return worldName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public WorldServer getWorldServer() {
|
|
||||||
return worldServer;
|
|
||||||
}
|
|
||||||
}
|
|
@ -14,7 +14,6 @@ import net.minecraft.server.v1_15_R1.ChunkProviderServer;
|
|||||||
import net.minecraft.server.v1_15_R1.WorldServer;
|
import net.minecraft.server.v1_15_R1.WorldServer;
|
||||||
import net.minemora.entitytrackerfixer.config.ConfigMain;
|
import net.minemora.entitytrackerfixer.config.ConfigMain;
|
||||||
import net.minemora.entitytrackerfixer.v1_15_R1.NMSEntityTracker;
|
import net.minemora.entitytrackerfixer.v1_15_R1.NMSEntityTracker;
|
||||||
import net.minemora.entitytrackerfixer.v1_15_R1.entityTick.EntityTickManager;
|
|
||||||
|
|
||||||
public class CheckTask extends BukkitRunnable {
|
public class CheckTask extends BukkitRunnable {
|
||||||
|
|
||||||
@ -41,9 +40,6 @@ public class CheckTask extends BukkitRunnable {
|
|||||||
for(Player player : Bukkit.getWorld(worldName).getPlayers()) {
|
for(Player player : Bukkit.getWorld(worldName).getPlayers()) {
|
||||||
for(Entity ent : player.getNearbyEntities(d, d, d)) {
|
for(Entity ent : player.getNearbyEntities(d, d, d)) {
|
||||||
trackAgain.add(((CraftEntity)ent).getHandle());
|
trackAgain.add(((CraftEntity)ent).getHandle());
|
||||||
if(ConfigMain.isDisableTickUntracked()) {
|
|
||||||
EntityTickManager.getInstance().enableTicking(((CraftEntity)ent).getHandle(), worldName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
NMSEntityTracker.trackEntities(cps, trackAgain);
|
NMSEntityTracker.trackEntities(cps, trackAgain);
|
||||||
|
@ -18,7 +18,6 @@ import net.minecraft.server.v1_15_R1.PlayerChunkMap.EntityTracker;
|
|||||||
import net.minemora.entitytrackerfixer.EntityTrackerFixer;
|
import net.minemora.entitytrackerfixer.EntityTrackerFixer;
|
||||||
import net.minemora.entitytrackerfixer.config.ConfigMain;
|
import net.minemora.entitytrackerfixer.config.ConfigMain;
|
||||||
import net.minemora.entitytrackerfixer.util.ReflectionUtils;
|
import net.minemora.entitytrackerfixer.util.ReflectionUtils;
|
||||||
import net.minemora.entitytrackerfixer.v1_15_R1.entityTick.EntityTickManager;
|
|
||||||
|
|
||||||
public class UntrackerTask extends BukkitRunnable {
|
public class UntrackerTask extends BukkitRunnable {
|
||||||
|
|
||||||
@ -92,9 +91,6 @@ public class UntrackerTask extends BukkitRunnable {
|
|||||||
|
|
||||||
for(int id : toRemove) {
|
for(int id : toRemove) {
|
||||||
cps.playerChunkMap.trackedEntities.remove(id);
|
cps.playerChunkMap.trackedEntities.remove(id);
|
||||||
if(ConfigMain.isDisableTickUntracked()) {
|
|
||||||
EntityTickManager.getInstance().disableTicking(id, worldName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ConfigMain.isLogToConsole()) {
|
if(ConfigMain.isLogToConsole()) {
|
||||||
|
@ -29,9 +29,6 @@ public final class NMSEntityTracker {
|
|||||||
public static void trackEntities(ChunkProviderServer cps, Set<net.minecraft.server.v1_16_R1.Entity> trackList) {
|
public static void trackEntities(ChunkProviderServer cps, Set<net.minecraft.server.v1_16_R1.Entity> trackList) {
|
||||||
try {
|
try {
|
||||||
for(net.minecraft.server.v1_16_R1.Entity entity : trackList) {
|
for(net.minecraft.server.v1_16_R1.Entity entity : trackList) {
|
||||||
if(cps.playerChunkMap.trackedEntities.containsKey(entity.getId())) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
addEntityMethod.invoke(cps.playerChunkMap, entity);
|
addEntityMethod.invoke(cps.playerChunkMap, entity);
|
||||||
}
|
}
|
||||||
} catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
|
} catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
|
||||||
|
@ -1,13 +1,9 @@
|
|||||||
package net.minemora.entitytrackerfixer.v1_16_R1;
|
package net.minemora.entitytrackerfixer.v1_16_R1;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.craftbukkit.v1_16_R1.CraftWorld;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import net.minemora.entitytrackerfixer.config.ConfigMain;
|
import net.minemora.entitytrackerfixer.config.ConfigMain;
|
||||||
import net.minemora.entitytrackerfixer.nms.NMS;
|
import net.minemora.entitytrackerfixer.nms.NMS;
|
||||||
import net.minemora.entitytrackerfixer.v1_16_R1.entityTick.EntityTickManager;
|
|
||||||
import net.minemora.entitytrackerfixer.v1_16_R1.entityTick.EntityTickWorldCache;
|
|
||||||
import net.minemora.entitytrackerfixer.v1_16_R1.tasks.CheckTask;
|
import net.minemora.entitytrackerfixer.v1_16_R1.tasks.CheckTask;
|
||||||
import net.minemora.entitytrackerfixer.v1_16_R1.tasks.UntrackerTask;
|
import net.minemora.entitytrackerfixer.v1_16_R1.tasks.UntrackerTask;
|
||||||
|
|
||||||
@ -18,16 +14,4 @@ public class NMSHandler implements NMS {
|
|||||||
new UntrackerTask().runTaskTimer(plugin, ConfigMain.getUntrackTicks(), ConfigMain.getUntrackTicks());
|
new UntrackerTask().runTaskTimer(plugin, ConfigMain.getUntrackTicks(), ConfigMain.getUntrackTicks());
|
||||||
new CheckTask().runTaskTimer(plugin, ConfigMain.getUntrackTicks() + 1, ConfigMain.getCheckFrequency());
|
new CheckTask().runTaskTimer(plugin, ConfigMain.getUntrackTicks() + 1, ConfigMain.getCheckFrequency());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void loadWorldCache() {
|
|
||||||
for(String worldName : ConfigMain.getWorlds()) {
|
|
||||||
if(Bukkit.getWorld(worldName) == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
EntityTickManager.getInstance().getCache().put(worldName,
|
|
||||||
new EntityTickWorldCache(((CraftWorld)Bukkit.getWorld(worldName)).getHandle()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,105 +1,51 @@
|
|||||||
package net.minemora.entitytrackerfixer.v1_16_R1.entityTick;
|
package net.minemora.entitytrackerfixer.v1_16_R1.entityTick;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.util.Set;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
|
|
||||||
import org.bukkit.plugin.Plugin;
|
import net.minecraft.server.v1_16_R1.EntityInsentient;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import net.minecraft.server.v1_16_R1.MinecraftServer;
|
||||||
|
|
||||||
import net.minecraft.server.v1_16_R1.WorldServer;
|
public class EntityTickManager {
|
||||||
import net.minemora.entitytrackerfixer.EntityTrackerFixer;
|
|
||||||
import net.minemora.entitytrackerfixer.util.ReflectionUtils;
|
|
||||||
import net.minemora.entitytrackerfixer.v1_16_R1.tasks.UntrackerTask;
|
|
||||||
|
|
||||||
public class EntityTickManager extends BukkitRunnable {
|
|
||||||
|
|
||||||
private static Field tickingEntitiesField;
|
|
||||||
private static Field entityCount;
|
|
||||||
|
|
||||||
static {
|
|
||||||
try {
|
|
||||||
tickingEntitiesField = ReflectionUtils.getClassPrivateField(WorldServer.class, "tickingEntities");
|
|
||||||
entityCount = ReflectionUtils.getClassPrivateField(net.minecraft.server.v1_16_R1.Entity.class, "entityCount");
|
|
||||||
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static EntityTickManager instance;
|
private static EntityTickManager instance;
|
||||||
|
|
||||||
private Map<String, EntityTickWorldCache> cache = new HashMap<>();
|
private EntityTickManager() {}
|
||||||
|
|
||||||
private EntityTickManager(Plugin plugin) {
|
public void disableTicking(net.minecraft.server.v1_16_R1.Entity entity) {
|
||||||
this.runTaskTimer(plugin, 61, 61);
|
if(entity == null) {
|
||||||
}
|
|
||||||
|
|
||||||
public void disableTicking(int id, String worldName) {
|
|
||||||
cache.get(worldName).getToTick().remove(id);
|
|
||||||
cache.get(worldName).getToUntick().add(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void enableTicking(net.minecraft.server.v1_16_R1.Entity entity, String worldName) {
|
|
||||||
cache.get(worldName).getToUntick().remove(entity.getId());
|
|
||||||
cache.get(worldName).getToTick().put(entity.getId(), entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if(UntrackerTask.isRunning()) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for(String worldName : cache.keySet()) {
|
if(!entity.valid) {
|
||||||
EntityTickWorldCache ewc = cache.get(worldName);
|
return;
|
||||||
WorldServer ws = ewc.getWorldServer();
|
|
||||||
if(ws.m_()) {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
try {
|
entity.activatedTick = -2147483648L;
|
||||||
if(tickingEntitiesField.getBoolean(ws)) {
|
if(entity instanceof EntityInsentient) {
|
||||||
continue;
|
//System.out.println("disable tick for insentient entity currently aware is = " + ((EntityInsentient)entity).aware + " should be true");
|
||||||
|
((EntityInsentient)entity).aware = false;
|
||||||
}
|
}
|
||||||
//System.out.println("unticking: " + ewc.getToUntick().size() + " entities, ticking again: " + ewc.getToTick().size() + " entities");
|
|
||||||
for(int i : ewc.getToUntick()) {
|
|
||||||
ws.entitiesById.remove(i);
|
|
||||||
}
|
}
|
||||||
ewc.getToUntick().clear();
|
|
||||||
for(int i : ewc.getToTick().keySet()) {
|
public void enableTicking(Set<net.minecraft.server.v1_16_R1.Entity> entities) {
|
||||||
net.minecraft.server.v1_16_R1.Entity entity = ewc.getToTick().get(i);
|
for(net.minecraft.server.v1_16_R1.Entity entity : entities) {
|
||||||
if(entity == null) {
|
if(entity == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(!entity.valid) {
|
if(!entity.valid) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(ws.entitiesById.containsValue(entity)) {
|
entity.activatedTick = MinecraftServer.currentTick;
|
||||||
continue;
|
if(entity instanceof EntityInsentient) {
|
||||||
}
|
//System.out.println("enabling tick for insentient entity currently aware is = " + ((EntityInsentient)entity).aware + " should be false");
|
||||||
if(ws.entitiesById.containsKey(i)) {
|
((EntityInsentient)entity).aware = true;
|
||||||
int id = ((AtomicInteger)entityCount.get(null)).incrementAndGet();
|
|
||||||
ws.entitiesById.put(id, entity);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ws.entitiesById.put(i, entity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ewc.getToTick().clear();
|
|
||||||
} catch (IllegalArgumentException | IllegalAccessException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EntityTickManager getInstance() {
|
public static EntityTickManager getInstance() {
|
||||||
if(instance == null) {
|
if(instance == null) {
|
||||||
instance = new EntityTickManager(EntityTrackerFixer.plugin);
|
instance = new EntityTickManager();
|
||||||
}
|
}
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, EntityTickWorldCache> getCache() {
|
|
||||||
return cache;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,38 +0,0 @@
|
|||||||
package net.minemora.entitytrackerfixer.v1_16_R1.entityTick;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import net.minecraft.server.v1_16_R1.WorldServer;
|
|
||||||
|
|
||||||
public class EntityTickWorldCache {
|
|
||||||
|
|
||||||
private String worldName;
|
|
||||||
private WorldServer worldServer;
|
|
||||||
|
|
||||||
private Set<Integer> toUntick = new HashSet<>();
|
|
||||||
private Map<Integer, net.minecraft.server.v1_16_R1.Entity> toTick = new HashMap<>();
|
|
||||||
|
|
||||||
public EntityTickWorldCache(WorldServer worldServer) {
|
|
||||||
this.worldName = worldServer.getWorld().getName();
|
|
||||||
this.worldServer = worldServer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<Integer> getToUntick() {
|
|
||||||
return toUntick;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<Integer, net.minecraft.server.v1_16_R1.Entity> getToTick() {
|
|
||||||
return toTick;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getWorldName() {
|
|
||||||
return worldName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public WorldServer getWorldServer() {
|
|
||||||
return worldServer;
|
|
||||||
}
|
|
||||||
}
|
|
@ -40,13 +40,17 @@ public class CheckTask extends BukkitRunnable {
|
|||||||
int d = ConfigMain.getTrackingRange();
|
int d = ConfigMain.getTrackingRange();
|
||||||
for(Player player : Bukkit.getWorld(worldName).getPlayers()) {
|
for(Player player : Bukkit.getWorld(worldName).getPlayers()) {
|
||||||
for(Entity ent : player.getNearbyEntities(d, d, d)) {
|
for(Entity ent : player.getNearbyEntities(d, d, d)) {
|
||||||
trackAgain.add(((CraftEntity)ent).getHandle());
|
net.minecraft.server.v1_16_R1.Entity nms = ((CraftEntity)ent).getHandle();
|
||||||
if(ConfigMain.isDisableTickUntracked()) {
|
if(cps.playerChunkMap.trackedEntities.containsKey(nms.getId())) {
|
||||||
EntityTickManager.getInstance().enableTicking(((CraftEntity)ent).getHandle(), worldName);
|
continue;
|
||||||
}
|
}
|
||||||
|
trackAgain.add(nms);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
NMSEntityTracker.trackEntities(cps, trackAgain);
|
NMSEntityTracker.trackEntities(cps, trackAgain);
|
||||||
|
if(ConfigMain.isDisableTickUntracked()) {
|
||||||
|
EntityTickManager.getInstance().enableTicking(trackAgain);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -94,7 +94,7 @@ public class UntrackerTask extends BukkitRunnable {
|
|||||||
for(int id : toRemove) {
|
for(int id : toRemove) {
|
||||||
cps.playerChunkMap.trackedEntities.remove(id);
|
cps.playerChunkMap.trackedEntities.remove(id);
|
||||||
if(ConfigMain.isDisableTickUntracked()) {
|
if(ConfigMain.isDisableTickUntracked()) {
|
||||||
EntityTickManager.getInstance().disableTicking(id, worldName);
|
EntityTickManager.getInstance().disableTicking(ws.entitiesById.get(id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user