Lixfel
6941cc98f0
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Signed-off-by: Lixfel <agga-games@gmx.de>
83 Zeilen
3.2 KiB
Java
83 Zeilen
3.2 KiB
Java
/*
|
|
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;
|
|
|
|
import com.comphenix.tinyprotocol.Reflection;
|
|
import com.mojang.authlib.GameProfile;
|
|
import com.mojang.datafixers.util.Pair;
|
|
import de.steamwar.fightsystem.fight.Fight;
|
|
import de.steamwar.fightsystem.record.REntity;
|
|
import net.minecraft.world.entity.EntityTypes;
|
|
import org.bukkit.entity.EntityType;
|
|
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
|
|
public class ProtocolWrapper19 implements ProtocolWrapper {
|
|
|
|
private static final Reflection.FieldAccessor<List> equipmentStack = Reflection.getField(REntity.equipmentPacket, List.class, 0);
|
|
@Override
|
|
public void setEquipmentPacketStack(Object packet, String slot, Object stack) {
|
|
equipmentStack.set(packet, Collections.singletonList(new Pair<>(getSlot(slot), stack)));
|
|
}
|
|
|
|
private static final Reflection.FieldAccessor<?> spawnType = Reflection.getField(REntity.spawnPacket, EntityTypes.class, 0);
|
|
@Override
|
|
public void setSpawnPacketType(Object packet, EntityType type) {
|
|
switch(type) {
|
|
case PRIMED_TNT:
|
|
spawnType.set(packet, EntityTypes.av);
|
|
break;
|
|
case ARROW:
|
|
spawnType.set(packet, EntityTypes.e);
|
|
break;
|
|
case FIREBALL:
|
|
spawnType.set(packet, EntityTypes.V);
|
|
break;
|
|
}
|
|
}
|
|
|
|
private static final Class<?> enumItemSlot = Reflection.getClass("{nms.world.entity}.EnumItemSlot");
|
|
private static final Object[] itemSlots = enumItemSlot.getEnumConstants();
|
|
private static Object getSlot(String slot) {
|
|
switch(slot){
|
|
case "HEAD":
|
|
return itemSlots[5];
|
|
case "CHEST":
|
|
return itemSlots[4];
|
|
case "LEGS":
|
|
return itemSlots[3];
|
|
case "FEET":
|
|
return itemSlots[2];
|
|
case "OFFHAND":
|
|
return itemSlots[1];
|
|
case "MAINHAND":
|
|
default:
|
|
return itemSlots[0];
|
|
}
|
|
}
|
|
|
|
private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(Fight.playerInfoDataClass, GameProfile.class, int.class, Fight.enumGamemode, Fight.iChatBaseComponent, Reflection.getClass("net.minecraft.world.entity.player.ProfilePublicKey$a"));
|
|
@Override
|
|
public Object playerInfoDataConstructor(Object packet, GameProfile profile, Object mode) {
|
|
return playerInfoDataConstructor.invoke(profile, 0, mode, null, null);
|
|
}
|
|
}
|