2022-01-14 18:58:00 +01:00
|
|
|
/*
|
|
|
|
This file is a part of the SteamWar software.
|
|
|
|
|
|
|
|
Copyright (C) 2021 SteamWar.de-Serverteam
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package de.steamwar.fightsystem.utils;
|
|
|
|
|
2023-02-03 11:59:39 +01:00
|
|
|
import com.comphenix.tinyprotocol.Reflection;
|
2022-03-29 20:47:33 +02:00
|
|
|
import de.steamwar.fightsystem.Config;
|
2023-02-03 11:59:39 +01:00
|
|
|
import net.minecraft.server.level.WorldServer;
|
2022-02-02 23:58:45 +01:00
|
|
|
import net.minecraft.world.level.chunk.Chunk;
|
2023-02-03 11:59:39 +01:00
|
|
|
import net.minecraft.world.level.chunk.ChunkSection;
|
|
|
|
import net.minecraft.world.level.entity.LevelEntityGetter;
|
2022-01-14 18:58:00 +01:00
|
|
|
import org.bukkit.World;
|
|
|
|
import org.bukkit.entity.Entity;
|
|
|
|
|
2022-03-29 20:47:33 +02:00
|
|
|
import java.util.stream.Stream;
|
|
|
|
import java.util.stream.StreamSupport;
|
2022-01-14 18:58:00 +01:00
|
|
|
|
2022-04-09 16:14:03 +02:00
|
|
|
public class CraftbukkitWrapper18 implements CraftbukkitWrapper {
|
2022-01-14 18:58:00 +01:00
|
|
|
|
2023-02-03 11:59:39 +01:00
|
|
|
private static final Reflection.MethodInvoker getWorld = Reflection.getTypedMethod(Reflection.getClass("{obc}.CraftWorld"), "getHandle", net.minecraft.world.level.World.class);
|
|
|
|
private static final Reflection.MethodInvoker getChunk = Reflection.getTypedMethod(net.minecraft.world.level.World.class, null, Chunk.class, int.class, int.class);
|
|
|
|
private static final Reflection.MethodInvoker getChunkSections = Reflection.getTypedMethod(Chunk.class, null, ChunkSection[].class);
|
|
|
|
private ChunkSection[] getChunkSections(World world, int x, int z) {
|
|
|
|
return (ChunkSection[]) getChunkSections.invoke(getChunk.invoke(getWorld.invoke(world), x, z));
|
2022-01-14 18:58:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-02-03 11:59:39 +01:00
|
|
|
public void resetChunk(World world, World backup, int x, int z) {
|
|
|
|
ChunkSection[] sections = getChunkSections(world, x, z);
|
|
|
|
System.arraycopy(getChunkSections(backup, x, z), 0, sections, 0, sections.length);
|
2022-01-14 18:58:00 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 11:59:39 +01:00
|
|
|
private static final Reflection.MethodInvoker getEntity = Reflection.getTypedMethod(Reflection.getClass("{obc}.entity.CraftEntity"), "getHandle", net.minecraft.world.entity.Entity.class);
|
|
|
|
protected net.minecraft.world.entity.Entity getEntity(Entity e) {
|
|
|
|
return (net.minecraft.world.entity.Entity) getEntity.invoke(e);
|
2022-01-14 18:58:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-02-03 11:59:39 +01:00
|
|
|
public float headRotation(Entity e) {
|
|
|
|
return getEntity(e).ce();
|
2022-01-14 18:58:00 +01:00
|
|
|
}
|
2022-03-29 20:47:33 +02:00
|
|
|
|
2023-02-03 11:59:39 +01:00
|
|
|
private static final Reflection.MethodInvoker getWorldEntities = Reflection.getTypedMethod(WorldServer.class, null, LevelEntityGetter.class);
|
|
|
|
private static final Reflection.MethodInvoker getIterable = Reflection.getTypedMethod(LevelEntityGetter.class, null, Iterable.class);
|
2022-03-29 20:47:33 +02:00
|
|
|
@Override
|
2022-04-09 16:14:03 +02:00
|
|
|
public Stream<?> entityIterator() {
|
2023-02-03 11:59:39 +01:00
|
|
|
return StreamSupport.stream(((Iterable<?>) getIterable.invoke(getWorldEntities.invoke(getWorld.invoke(Config.world)))).spliterator(), false);
|
2022-03-29 20:47:33 +02:00
|
|
|
}
|
2022-01-14 18:58:00 +01:00
|
|
|
}
|