Remove unused code

This commit is contained in:
2026-05-16 22:41:17 +02:00
parent 245072f02c
commit 81dd8045f2
37 changed files with 95 additions and 260 deletions
@@ -1,44 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2025 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.core;
import lombok.experimental.UtilityClass;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.contents.PlainTextContents;
import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket;
import net.minecraft.network.syncher.SynchedEntityData;
import java.util.ArrayList;
@UtilityClass
public class ChatWrapper {
public Object stringToChatComponent(String text) {
return MutableComponent.create(PlainTextContents.create(text));
}
public Object getDataWatcherPacket(int entityId, Object... dataWatcherKeyValues) {
ArrayList<SynchedEntityData.DataValue<?>> nativeWatchers = new ArrayList<>(1);
for(int i = 0; i < dataWatcherKeyValues.length; i+=2) {
nativeWatchers.add(((SynchedEntityData.DataItem<?>) BountifulWrapper.impl.getDataWatcherItem(dataWatcherKeyValues[i], dataWatcherKeyValues[i+1])).value());
}
return new ClientboundSetEntityDataPacket(entityId, nativeWatchers);
}
}
@@ -1,38 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2025 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.core;
import lombok.experimental.UtilityClass;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.craftbukkit.CraftServer;
import java.util.Map;
@UtilityClass
public class CommandRemover {
private static final Map<String, Command> knownCommands = ((CraftServer) Bukkit.getServer()).getCommandMap().getKnownCommands();
public static void removeAll(String... cmds) {
for (String cmd : cmds) {
knownCommands.remove(cmd.toLowerCase());
}
}
}
@@ -20,15 +20,15 @@
package de.steamwar.core;
import com.comphenix.tinyprotocol.TinyProtocol;
import lombok.experimental.UtilityClass;
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.level.chunk.status.ChunkStatus;
import org.bukkit.craftbukkit.CraftChunk;
import org.bukkit.entity.Player;
@UtilityClass
public class CraftbukkitWrapper {
public static final CraftbukkitWrapper impl = new CraftbukkitWrapper();
public void sendChunk(Player p, int chunkX, int chunkZ) {
LevelChunk chunk = (LevelChunk) ((CraftChunk) p.getWorld().getChunkAt(chunkX, chunkZ)).getHandle(ChunkStatus.FULL);
TinyProtocol.instance.sendPacket(p, new ClientboundLevelChunkWithLightPacket(chunk, chunk.level.getLightEngine(), null, null, true));
@@ -20,6 +20,8 @@
package de.steamwar.core;
import lombok.experimental.UtilityClass;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.contents.PlainTextContents;
import java.util.Optional;
@@ -27,6 +29,6 @@ import java.util.Optional;
public class FlatteningWrapper {
public Object formatDisplayName(String displayName) {
return displayName != null ? Optional.of(ChatWrapper.stringToChatComponent(displayName)) : Optional.empty();
return displayName != null ? Optional.of((Object) MutableComponent.create(PlainTextContents.create(displayName))) : Optional.empty();
}
}
@@ -20,30 +20,22 @@
package de.steamwar.core;
import com.mojang.authlib.GameProfile;
import net.minecraft.network.protocol.game.ClientboundAddEntityPacket;
import lombok.experimental.UtilityClass;
import net.minecraft.network.protocol.game.ClientboundPlayerInfoRemovePacket;
import net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.GameType;
import org.bukkit.GameMode;
import java.util.Collections;
import java.util.EnumSet;
@UtilityClass
public class ProtocolWrapper {
public static final Class<?> itemStack = ItemStack.class;
public static final Class<?> spawnPacket = ClientboundAddEntityPacket.class;
// 0: hand, 1: offhand, 2: feet, 3: legs, 4: chest, 5: head
public static final EquipmentSlot[] itemSlots = EquipmentSlot.values();
public static final ProtocolWrapper impl = new ProtocolWrapper();
public Object playerInfoPacketConstructor(PlayerInfoAction action, GameProfile profile, GameMode mode) {
if(action == PlayerInfoAction.REMOVE)
if(action == PlayerInfoAction.REMOVE) {
return new ClientboundPlayerInfoRemovePacket(Collections.singletonList(profile.getId()));
}
return new ClientboundPlayerInfoUpdatePacket(action == PlayerInfoAction.ADD ?
EnumSet.of(ClientboundPlayerInfoUpdatePacket.Action.ADD_PLAYER, ClientboundPlayerInfoUpdatePacket.Action.UPDATE_GAME_MODE) : EnumSet.of(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_GAME_MODE),
@@ -68,21 +68,17 @@ public class TPSWatcher {
case TEN_SECONDS:
return round(tps_TenSecond.tps);
case ONE_MINUTE:
return round(getSpigotTPS()[0]);
return round(MinecraftServer.getServer().tps1.getAverage());
case FIVE_MINUTES:
return round(getSpigotTPS()[1]);
return round(MinecraftServer.getServer().tps5.getAverage());
case TEN_MINUTES:
return round(getSpigotTPS()[2]);
return round(MinecraftServer.getServer().tps15.getAverage());
case ONE_SECOND:
default:
return round(tps_OneSecond.tps);
}
}
private static double[] getSpigotTPS() {
return MinecraftServer.getServer().recentTps;
}
private static double round(double d) {
return Math.round(d * 10) / 10.0;
}
@@ -1,30 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2025 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.core;
import org.bukkit.Particle;
public class TrickyParticleWrapper {
public static final TrickyParticleWrapper impl = new TrickyParticleWrapper();
public Particle getVillagerHappy() {
return Particle.HAPPY_VILLAGER;
}
}
@@ -1,45 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2025 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.core;
import com.mojang.authlib.properties.Property;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
public class TrickyTrialsWrapper {
public static final TrickyTrialsWrapper impl = new TrickyTrialsWrapper();
public EntityType getTntEntityType() {
return EntityType.TNT;
}
public Enchantment getUnbreakingEnchantment() {
return Enchantment.UNBREAKING;
}
public Material getTurtleScute() {
return Material.TURTLE_SCUTE;
}
public String getValue(Property property) {
return property.value();
}
}
@@ -56,7 +56,7 @@ public class WorldEditRendererFallback {
private void drawLine(Player player, boolean clipboard, Vector min, Vector max) {
Particle particle;
if (clipboard) {
particle = TrickyParticleWrapper.impl.getVillagerHappy();
particle = Particle.HAPPY_VILLAGER;
} else {
particle = Particle.DRAGON_BREATH;
}
@@ -22,9 +22,7 @@ package de.steamwar.entity;
import com.mojang.datafixers.util.Pair;
import de.steamwar.Reflection;
import de.steamwar.core.BountifulWrapper;
import de.steamwar.core.ChatWrapper;
import de.steamwar.core.FlatteningWrapper;
import de.steamwar.core.ProtocolWrapper;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import lombok.Getter;
import net.minecraft.core.registries.BuiltInRegistries;
@@ -32,6 +30,7 @@ import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.game.*;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.Pose;
@@ -249,9 +248,9 @@ public class REntity {
server.updateEntity(this,getDataWatcherPacket(entityStatusWatcher,getEntityStatus()));
}
private static final Function<REntity, Object> spawnPacketGenerator = entitySpawnPacketGenerator(ProtocolWrapper.spawnPacket, 2);
private static final Function<REntity, Object> spawnPacketGenerator = entitySpawnPacketGenerator(ClientboundAddEntityPacket.class, 2);
private static final Reflection.Field<Integer> additionalData = Reflection.getField(ProtocolWrapper.spawnPacket, int.class, 4);
private static final Reflection.Field<Integer> additionalData = Reflection.getField(ClientboundAddEntityPacket.class, int.class, 4);
private Object spawnPacketGenerator() {
Object packet = spawnPacketGenerator.apply(this);
@@ -332,7 +331,12 @@ public class REntity {
}
protected Object getDataWatcherPacket(Object... dataWatcherKeyValues) {
return ChatWrapper.getDataWatcherPacket(entityId, dataWatcherKeyValues);
ArrayList<SynchedEntityData.DataValue<?>> nativeWatchers = new ArrayList<>(1);
for(int i = 0; i < dataWatcherKeyValues.length; i+=2) {
nativeWatchers.add(((SynchedEntityData.DataItem<?>) BountifulWrapper.impl.getDataWatcherItem(dataWatcherKeyValues[i], dataWatcherKeyValues[i+1])).value());
}
return new ClientboundSetEntityDataPacket(entityId, nativeWatchers);
}
private Object getTeleportPacket(){
@@ -371,7 +375,7 @@ public class REntity {
return new ClientboundSetEquipmentPacket(entityId, Collections.singletonList(Pair.of((EquipmentSlot) slot, CraftItemStack.asNMSCopy(stack))));
}
private static final Reflection.Field<net.minecraft.world.entity.EntityType> spawnType = Reflection.getField(ProtocolWrapper.spawnPacket, net.minecraft.world.entity.EntityType.class, 0);
private static final Reflection.Field<net.minecraft.world.entity.EntityType> spawnType = Reflection.getField(ClientboundAddEntityPacket.class, net.minecraft.world.entity.EntityType.class, 0);
private static Function<REntity, Object> entitySpawnPacketGenerator(Class<?> spawnPacket, int posOffset) {
BountifulWrapper.UUIDSetter uuid = BountifulWrapper.impl.getUUIDSetter(spawnPacket);
Function<REntity, Object> packetGenerator = spawnPacketGenerator(spawnPacket, posOffset);
@@ -23,7 +23,6 @@ import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import de.steamwar.core.BountifulWrapper;
import de.steamwar.core.ProtocolWrapper;
import de.steamwar.core.TrickyTrialsWrapper;
import de.steamwar.network.CoreNetworkHandler;
import de.steamwar.network.NetworkSender;
import de.steamwar.network.packets.common.PlayerSkinRequestPacket;
@@ -61,7 +60,7 @@ public class RPlayer extends REntity {
NetworkSender.sendOrQueue(new PlayerSkinRequestPacket(actualUUID));
return new Property("textures", null, null);
});
if (TrickyTrialsWrapper.impl.getValue(skinData) != null) {
if (skinData.value() != null) {
GameProfile gameProfile = new GameProfile(uuid, name);
gameProfile.getProperties().put("textures", skinData);
return gameProfile;
@@ -75,7 +74,7 @@ public class RPlayer extends REntity {
@Override
void list(Consumer<Object> packetSink) {
saved = getGameProfile();
packetSink.accept(ProtocolWrapper.impl.playerInfoPacketConstructor(ProtocolWrapper.PlayerInfoAction.ADD, saved, GameMode.CREATIVE));
packetSink.accept(ProtocolWrapper.playerInfoPacketConstructor(ProtocolWrapper.PlayerInfoAction.ADD, saved, GameMode.CREATIVE));
}
@Override
@@ -93,7 +92,7 @@ public class RPlayer extends REntity {
@Override
void delist(Consumer<Object> packetSink) {
if (saved == null) saved = getGameProfile();
packetSink.accept(ProtocolWrapper.impl.playerInfoPacketConstructor(ProtocolWrapper.PlayerInfoAction.REMOVE, saved, GameMode.CREATIVE));
packetSink.accept(ProtocolWrapper.playerInfoPacketConstructor(ProtocolWrapper.PlayerInfoAction.REMOVE, saved, GameMode.CREATIVE));
}
private Object getNamedSpawnPacket() {
@@ -19,9 +19,10 @@
package de.steamwar.entity;
import de.steamwar.core.ChatWrapper;
import lombok.Getter;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.contents.PlainTextContents;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import org.bukkit.Location;
@@ -77,7 +78,7 @@ public class RTextDisplay extends RDisplay {
private static final EntityDataAccessor<Component> textWatcher = new EntityDataAccessor<>(23, EntityDataSerializers.COMPONENT);
private void getText(boolean ignoreDefault, BiConsumer<Object, Object> packetSink) {
if (ignoreDefault || !text.isEmpty()) {
packetSink.accept(textWatcher, ChatWrapper.stringToChatComponent(text));
packetSink.accept(textWatcher, MutableComponent.create(PlainTextContents.create(text)));
}
}
@@ -22,10 +22,10 @@ package de.steamwar.inventory;
import com.destroystokyo.paper.profile.PlayerProfile;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import de.steamwar.core.TrickyTrialsWrapper;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
@@ -114,7 +114,7 @@ public class SWItem {
itemMeta.setDisplayName(name);
if (lore != null && !lore.isEmpty()) itemMeta.setLore(lore);
if (enchanted) itemMeta.addEnchant(TrickyTrialsWrapper.impl.getUnbreakingEnchantment(), 10, true);
if (enchanted) itemMeta.addEnchant(Enchantment.UNBREAKING, 10, true);
itemStack.setItemMeta(itemMeta);
}
callback = c;
@@ -205,9 +205,9 @@ public class SWItem {
public SWItem setEnchanted(boolean enchanted) {
if (enchanted){
itemMeta.addEnchant(TrickyTrialsWrapper.impl.getUnbreakingEnchantment() , 10, true);
itemMeta.addEnchant(Enchantment.UNBREAKING, 10, true);
} else {
itemMeta.removeEnchant(TrickyTrialsWrapper.impl.getUnbreakingEnchantment());
itemMeta.removeEnchant(Enchantment.UNBREAKING);
}
itemStack.setItemMeta(itemMeta);
return this;