Fix NPE of EnableTick and modifation of DisableTick (Issue #9)

Implement fix directly on DisableTick and EnableTicking for check world cache.
Some worlds may not be loaded when loading world cache on enable. (With plugins like Multiverse-Core)
This commit is contained in:
Futurixel 2020-04-01 02:11:24 +02:00
parent d6dfa48c17
commit b4806b4b6f
5 changed files with 17 additions and 14 deletions

View File

@ -5,6 +5,8 @@ import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_14_R1.CraftWorld;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
@ -36,11 +38,17 @@ public class EntityTickManager extends BukkitRunnable {
}
public void disableTicking(int id, String worldName) {
if(!cache.containsKey(worldName)){
cache.put(worldName, new EntityTickWorldCache(((CraftWorld) Bukkit.getWorld(worldName)).getHandle()));
}
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) {
if(!cache.containsKey(worldName)){
cache.put(worldName, new EntityTickWorldCache(((CraftWorld) Bukkit.getWorld(worldName)).getHandle()));
}
cache.get(worldName).getToUntick().remove(entity.getId());
cache.get(worldName).getToTick().put(entity.getId(), entity);
}

View File

@ -55,13 +55,6 @@ public class UntrackerTask extends BukkitRunnable {
return;
}
if(ConfigMain.isDisableTickUntracked()){
if(!EntityTickManager.getInstance().getCache().containsKey(worldName)){
EntityTickManager.getInstance().getCache().put(worldName,
new EntityTickWorldCache(((CraftWorld)Bukkit.getWorld(worldName)).getHandle()));
}
}
//Set<net.minecraft.server.v1_14_R1.Entity> toRemove = new HashSet<>();
Set<Integer> toRemove = new HashSet<>();
int removed = 0;

View File

@ -5,6 +5,8 @@ import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
@ -36,11 +38,17 @@ public class EntityTickManager extends BukkitRunnable {
}
public void disableTicking(int id, String worldName) {
if(!cache.containsKey(worldName)){
cache.put(worldName, new EntityTickWorldCache(((CraftWorld) Bukkit.getWorld(worldName)).getHandle()));
}
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) {
if(!cache.containsKey(worldName)){
cache.put(worldName, new EntityTickWorldCache(((CraftWorld) Bukkit.getWorld(worldName)).getHandle()));
}
cache.get(worldName).getToUntick().remove(entity.getId());
cache.get(worldName).getToTick().put(entity.getId(), entity);
}

View File

@ -3,6 +3,7 @@ package net.minemora.entitytrackerfixer.v1_15_R1.tasks;
import java.util.HashSet;
import java.util.Set;
import net.minemora.entitytrackerfixer.v1_15_R1.entityTick.EntityTickWorldCache;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity;

View File

@ -53,13 +53,6 @@ public class UntrackerTask extends BukkitRunnable {
return;
}
if(ConfigMain.isDisableTickUntracked()){
if(!EntityTickManager.getInstance().getCache().containsKey(worldName)){
EntityTickManager.getInstance().getCache().put(worldName,
new EntityTickWorldCache(((CraftWorld)Bukkit.getWorld(worldName)).getHandle()));
}
}
//Set<net.minecraft.server.v1_14_R1.Entity> toRemove = new HashSet<>();
Set<Integer> toRemove = new HashSet<>();
int removed = 0;