From 11ce513ec2eb4dc4a72185a3da1bd2dfeada8f6b Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 20 Aug 2023 15:18:59 +0200 Subject: [PATCH] Add TNTPrimedIterator 1.20 support Signed-off-by: yoyosource --- .../tracer/record/TNTPrimedIterator18.java | 12 ++++-- .../tracer/record/TNTPrimedIterator19.java | 41 ------------------- 2 files changed, 8 insertions(+), 45 deletions(-) delete mode 100644 BauSystem_19/src/de/steamwar/bausystem/features/tracer/record/TNTPrimedIterator19.java diff --git a/BauSystem_18/src/de/steamwar/bausystem/features/tracer/record/TNTPrimedIterator18.java b/BauSystem_18/src/de/steamwar/bausystem/features/tracer/record/TNTPrimedIterator18.java index e6771471..0ae4692b 100644 --- a/BauSystem_18/src/de/steamwar/bausystem/features/tracer/record/TNTPrimedIterator18.java +++ b/BauSystem_18/src/de/steamwar/bausystem/features/tracer/record/TNTPrimedIterator18.java @@ -19,9 +19,11 @@ package de.steamwar.bausystem.features.tracer.record; +import com.comphenix.tinyprotocol.Reflection; +import net.minecraft.server.level.WorldServer; import net.minecraft.world.entity.item.EntityTNTPrimed; +import net.minecraft.world.level.entity.LevelEntityGetter; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_18_R2.CraftWorld; import org.bukkit.entity.TNTPrimed; import java.util.stream.Stream; @@ -29,13 +31,15 @@ import java.util.stream.StreamSupport; public class TNTPrimedIterator18 implements TNTPrimedIterator { - private static final CraftWorld WORLD = (CraftWorld) Bukkit.getWorlds().get(0); + private static final Reflection.MethodInvoker getWorld = Reflection.getMethod(Reflection.getClass("{obc}.CraftWorld"), "getHandle"); + 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); @Override public Stream iterator() { - return StreamSupport.stream(WORLD.getHandle().H().a().spliterator(), false) + return StreamSupport.stream(((Iterable) getIterable.invoke(getWorldEntities.invoke(getWorld.invoke(Bukkit.getWorlds().get(0))))).spliterator(), false) .filter(EntityTNTPrimed.class::isInstance) - .map(entity -> (TNTPrimed) entity.getBukkitEntity()); + .map(entity -> (TNTPrimed) (((EntityTNTPrimed) entity).getBukkitEntity())); } } diff --git a/BauSystem_19/src/de/steamwar/bausystem/features/tracer/record/TNTPrimedIterator19.java b/BauSystem_19/src/de/steamwar/bausystem/features/tracer/record/TNTPrimedIterator19.java deleted file mode 100644 index 17498269..00000000 --- a/BauSystem_19/src/de/steamwar/bausystem/features/tracer/record/TNTPrimedIterator19.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 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 . - */ - -package de.steamwar.bausystem.features.tracer.record; - -import net.minecraft.world.entity.item.EntityTNTPrimed; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_19_R2.CraftWorld; -import org.bukkit.entity.TNTPrimed; - -import java.util.stream.Stream; -import java.util.stream.StreamSupport; - -public class TNTPrimedIterator19 implements TNTPrimedIterator { - - private static final CraftWorld WORLD = (CraftWorld) Bukkit.getWorlds().get(0); - - @Override - public Stream iterator() { - return StreamSupport.stream(WORLD.getHandle().F().a().spliterator(), false) - .filter(EntityTNTPrimed.class::isInstance) - .map(entity -> (TNTPrimed) entity.getBukkitEntity()); - } -} -