Fix crash bug
This commit is contained in:
parent
5ab083f19a
commit
32ee9705ac
@ -6,6 +6,7 @@ import io.izzel.taboolib.TabooLib;
|
||||
import io.izzel.taboolib.Version;
|
||||
import io.izzel.taboolib.module.inject.TListener;
|
||||
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.TPacket;
|
||||
import io.izzel.taboolib.util.Ref;
|
||||
@ -141,7 +142,7 @@ class THologramHandler implements Listener {
|
||||
}
|
||||
|
||||
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.setMarker(true);
|
||||
learnTarget.setVisible(false);
|
||||
|
@ -18,6 +18,7 @@ import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.function.Consumer;
|
||||
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 <T extends Entity> T spawn(Location location, Class<T> entity, Consumer<T> e);
|
||||
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.event.entity.ProjectileHitEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
@ -38,6 +39,7 @@ import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* @Author 坏黑
|
||||
@ -462,4 +464,19 @@ public class NMSImpl extends NMS {
|
||||
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);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user