Fix crash bug

This commit is contained in:
sky 2020-03-10 23:48:48 +08:00
parent 5ab083f19a
commit 32ee9705ac
3 changed files with 22 additions and 1 deletions

View File

@ -6,6 +6,7 @@ import io.izzel.taboolib.TabooLib;
import io.izzel.taboolib.Version; import io.izzel.taboolib.Version;
import io.izzel.taboolib.module.inject.TListener; import io.izzel.taboolib.module.inject.TListener;
import io.izzel.taboolib.module.lite.SimpleReflection; import io.izzel.taboolib.module.lite.SimpleReflection;
import io.izzel.taboolib.module.nms.NMS;
import io.izzel.taboolib.module.packet.Packet; import io.izzel.taboolib.module.packet.Packet;
import io.izzel.taboolib.module.packet.TPacket; import io.izzel.taboolib.module.packet.TPacket;
import io.izzel.taboolib.util.Ref; import io.izzel.taboolib.util.Ref;
@ -141,7 +142,7 @@ class THologramHandler implements Listener {
} }
public static void learn(Player player) { public static void learn(Player player) {
player.getWorld().spawn(player.getLocation(), ArmorStand.class, c -> { NMS.handle().spawn(player.getLocation(), ArmorStand.class, c -> {
learnTarget = c; learnTarget = c;
learnTarget.setMarker(true); learnTarget.setMarker(true);
learnTarget.setVisible(false); learnTarget.setVisible(false);

View File

@ -18,6 +18,7 @@ import org.bukkit.util.Vector;
import java.util.List; import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.Consumer;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -90,4 +91,6 @@ public abstract class NMS {
abstract public void sendPacketEntityTeleport(Player player, int entity, Location location); abstract public void sendPacketEntityTeleport(Player player, int entity, Location location);
abstract public <T extends Entity> T spawn(Location location, Class<T> entity, Consumer<T> e);
} }

View File

@ -29,6 +29,7 @@ import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Villager; import org.bukkit.entity.Villager;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.inventory.meta.PotionMeta;
@ -38,6 +39,7 @@ import java.lang.reflect.Field;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.function.Consumer;
/** /**
* @Author 坏黑 * @Author 坏黑
@ -462,4 +464,19 @@ public class NMSImpl extends NMS {
SimpleReflection.setFieldValue(net.minecraft.server.v1_13_R2.PacketPlayOutEntityTeleport.class, teleport, "d", location.getZ()); SimpleReflection.setFieldValue(net.minecraft.server.v1_13_R2.PacketPlayOutEntityTeleport.class, teleport, "d", location.getZ());
((CraftPlayer) player).getHandle().playerConnection.sendPacket((net.minecraft.server.v1_13_R2.PacketPlayOutEntityTeleport) teleport); ((CraftPlayer) player).getHandle().playerConnection.sendPacket((net.minecraft.server.v1_13_R2.PacketPlayOutEntityTeleport) teleport);
} }
@Override
public <T extends Entity> T spawn(Location location, Class<T> entity, Consumer<T> e) {
if (Version.isAfter(Version.v1_12)) {
return location.getWorld().spawn(location, entity, e::accept);
} else {
Object createEntity = ((CraftWorld) location.getWorld()).createEntity(location, entity);
try {
e.accept((T) createEntity);
} catch (Throwable t) {
t.printStackTrace();
}
return ((CraftWorld) location.getWorld()).addEntity((net.minecraft.server.v1_13_R2.Entity) createEntity, CreatureSpawnEvent.SpawnReason.CUSTOM);
}
}
} }