Potentially faster TNT iteration #343
@ -19,6 +19,7 @@
|
||||
|
||||
package de.steamwar.fightsystem.utils;
|
||||
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.fight.FightWorld;
|
||||
import net.minecraft.server.v1_10_R1.Chunk;
|
||||
import org.bukkit.World;
|
||||
@ -32,6 +33,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class CraftbukkitWrapper10 implements CraftbukkitWrapper.ICraftbukkitWrapper {
|
||||
@Override
|
||||
@ -67,4 +69,9 @@ public class CraftbukkitWrapper10 implements CraftbukkitWrapper.ICraftbukkitWrap
|
||||
keys.remove("Damage");
|
||||
return !keys.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<?> tntIterator() {
|
||||
return ((CraftWorld) Config.world).getHandle().entityList.stream();
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package de.steamwar.fightsystem.utils;
|
||||
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.fight.FightWorld;
|
||||
import net.minecraft.server.v1_12_R1.Chunk;
|
||||
import org.bukkit.World;
|
||||
@ -32,6 +33,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class CraftbukkitWrapper12 implements CraftbukkitWrapper.ICraftbukkitWrapper {
|
||||
@Override
|
||||
@ -67,4 +69,9 @@ public class CraftbukkitWrapper12 implements CraftbukkitWrapper.ICraftbukkitWrap
|
||||
keys.remove("Damage");
|
||||
return !keys.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<?> tntIterator() {
|
||||
return ((CraftWorld) Config.world).getHandle().entityList.stream();
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package de.steamwar.fightsystem.utils;
|
||||
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.fight.FightWorld;
|
||||
import net.minecraft.server.v1_14_R1.Chunk;
|
||||
import org.bukkit.World;
|
||||
@ -32,6 +33,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class CraftbukkitWrapper14 implements CraftbukkitWrapper.ICraftbukkitWrapper {
|
||||
@Override
|
||||
@ -68,4 +70,9 @@ public class CraftbukkitWrapper14 implements CraftbukkitWrapper.ICraftbukkitWrap
|
||||
keys.remove("Damage");
|
||||
return !keys.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<?> tntIterator() {
|
||||
return ((CraftWorld) Config.world).getHandle().entitiesById.values().stream();
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package de.steamwar.fightsystem.utils;
|
||||
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.fight.FightWorld;
|
||||
import net.minecraft.server.v1_15_R1.Chunk;
|
||||
import org.bukkit.World;
|
||||
@ -32,6 +33,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class CraftbukkitWrapper15 implements CraftbukkitWrapper.ICraftbukkitWrapper {
|
||||
@Override
|
||||
@ -68,4 +70,9 @@ public class CraftbukkitWrapper15 implements CraftbukkitWrapper.ICraftbukkitWrap
|
||||
keys.remove("Damage");
|
||||
return !keys.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<?> tntIterator() {
|
||||
return ((CraftWorld) Config.world).getHandle().entitiesById.values().stream();
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package de.steamwar.fightsystem.utils;
|
||||
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import net.minecraft.world.level.chunk.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_18_R2.CraftWorld;
|
||||
@ -31,6 +32,8 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
public class CraftbukkitWrapper18 implements CraftbukkitWrapper.ICraftbukkitWrapper {
|
||||
|
||||
@ -60,4 +63,9 @@ public class CraftbukkitWrapper18 implements CraftbukkitWrapper.ICraftbukkitWrap
|
||||
keys.remove("Damage");
|
||||
return !keys.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<?> tntIterator() {
|
||||
return StreamSupport.stream(((CraftWorld) Config.world).getHandle().H().a().spliterator(), false);
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package de.steamwar.fightsystem.utils;
|
||||
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import net.minecraft.server.v1_8_R3.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
|
||||
@ -31,6 +32,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class CraftbukkitWrapper8 implements CraftbukkitWrapper.ICraftbukkitWrapper {
|
||||
@Override
|
||||
@ -64,4 +66,9 @@ public class CraftbukkitWrapper8 implements CraftbukkitWrapper.ICraftbukkitWrapp
|
||||
keys.remove("Damage");
|
||||
return !keys.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<?> tntIterator() {
|
||||
return ((CraftWorld) Config.world).getHandle().entityList.stream();
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package de.steamwar.fightsystem.utils;
|
||||
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.fight.FightWorld;
|
||||
import net.minecraft.server.v1_9_R2.Chunk;
|
||||
import org.bukkit.World;
|
||||
@ -32,6 +33,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class CraftbukkitWrapper9 implements CraftbukkitWrapper.ICraftbukkitWrapper {
|
||||
@Override
|
||||
@ -67,4 +69,9 @@ public class CraftbukkitWrapper9 implements CraftbukkitWrapper.ICraftbukkitWrapp
|
||||
keys.remove("Damage");
|
||||
return !keys.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<?> tntIterator() {
|
||||
return ((CraftWorld) Config.world).getHandle().entityList.stream();
|
||||
}
|
||||
}
|
||||
|
@ -41,6 +41,8 @@ public class Config {
|
||||
|
||||
private Config(){}
|
||||
|
||||
public static final World world = Bukkit.getWorlds().get(0);
|
||||
|
||||
//Fight sequence
|
||||
public static final int NoPlayerOnlineDuration;
|
||||
public static final int PreSchemPasteDuration;
|
||||
|
@ -30,14 +30,12 @@ import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependent;
|
||||
import de.steamwar.fightsystem.states.StateDependentListener;
|
||||
import de.steamwar.fightsystem.states.StateDependentTask;
|
||||
import de.steamwar.fightsystem.utils.BountifulWrapper;
|
||||
import de.steamwar.fightsystem.utils.FlatteningWrapper;
|
||||
import de.steamwar.fightsystem.utils.ProtocolAPI;
|
||||
import de.steamwar.fightsystem.utils.SWSound;
|
||||
import de.steamwar.fightsystem.utils.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
@ -108,13 +106,18 @@ public class Recording implements Listener {
|
||||
if(FightState.getFightState() == FightState.SPECTATE || !GlobalRecorder.getInstance().recording())
|
||||
return;
|
||||
|
||||
for(TNTPrimed tnt : world.getEntitiesByClass(TNTPrimed.class)){
|
||||
GlobalRecorder.getInstance().entityMoves(tnt);
|
||||
GlobalRecorder.getInstance().entitySpeed(tnt);
|
||||
}
|
||||
CraftbukkitWrapper.impl.tntIterator().filter(primedTnt::isInstance).forEach(this::trackEntity);
|
||||
}, 1, 1);
|
||||
}
|
||||
|
||||
private static final Class<?> primedTnt = Reflection.getClass("{nms.world.entity}.EntityTNTPrimed");
|
||||
private static final Reflection.MethodInvoker getBukkitEntity = Reflection.getTypedMethod(Reflection.getClass("{nms.world.entity}.Entity"), "getBukkitEntity", null);
|
||||
private void trackEntity(Object e) {
|
||||
Entity entity = (Entity) getBukkitEntity.invoke(e);
|
||||
GlobalRecorder.getInstance().entityMoves(entity);
|
||||
GlobalRecorder.getInstance().entitySpeed(entity);
|
||||
}
|
||||
|
||||
private static final Class<?> blockDigPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInBlockDig");
|
||||
private static final Class<?> playerDigType = blockDigPacket.getDeclaredClasses()[0];
|
||||
private static final Reflection.FieldAccessor<?> blockDigType = Reflection.getField(blockDigPacket, playerDigType, 0);
|
||||
|
@ -26,6 +26,8 @@ import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class CraftbukkitWrapper {
|
||||
private CraftbukkitWrapper() {}
|
||||
|
||||
@ -36,5 +38,7 @@ public class CraftbukkitWrapper {
|
||||
void sendResourcePack(Player player, String pack, String sha1);
|
||||
float headRotation(Entity e);
|
||||
boolean hasItems(ItemStack stack);
|
||||
|
||||
Stream<?> tntIterator();
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren