SteamWar/SpigotCore
Archiviert
13
0

Merge pull request 'Prevent SWScoreboard instanciation if not necessary' (#167) from PreventSWScoreboard into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Reviewed-on: #167
Reviewed-by: YoyoNow <jwsteam@nidido.de>
Dieser Commit ist enthalten in:
Lixfel 2022-02-03 21:24:28 +01:00
Commit 76c7962e17
4 geänderte Dateien mit 17 neuen und 17 gelöschten Zeilen

Datei anzeigen

@ -20,7 +20,6 @@
package de.steamwar.core;
import com.comphenix.tinyprotocol.Reflection;
import de.steamwar.scoreboard.SWScoreboard;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
@ -222,7 +221,7 @@ public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper
renamedLegacy.put("RECORD_12", Material.MUSIC_DISC_WAIT);
}
private static final Reflection.FieldAccessor<?> scoreboardName = Reflection.getField(SWScoreboard.scoreboardObjective, Reflection.getClass("{nms.network.chat}.IChatBaseComponent"), 0);
private static final Reflection.FieldAccessor<?> scoreboardName = Reflection.getField(FlatteningWrapper.scoreboardObjective, Reflection.getClass("{nms.network.chat}.IChatBaseComponent"), 0);
private static final Reflection.ConstructorInvoker chatComponentConstructor = Reflection.getConstructor(Reflection.getClass("{nms.network.chat}.ChatComponentText"), String.class);
@Override
@ -231,7 +230,7 @@ public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper
}
private static final Class<?> scoreActionEnum = Reflection.getClass("{nms.server}.ScoreboardServer$Action");
private static final Reflection.FieldAccessor<?> scoreAction = Reflection.getField(SWScoreboard.scoreboardScore, scoreActionEnum, 0);
private static final Reflection.FieldAccessor<?> scoreAction = Reflection.getField(FlatteningWrapper.scoreboardScore, scoreActionEnum, 0);
private static final Object scoreActionChange = scoreActionEnum.getEnumConstants()[0];
@Override

Datei anzeigen

@ -20,16 +20,15 @@
package de.steamwar.core;
import com.comphenix.tinyprotocol.Reflection;
import de.steamwar.scoreboard.SWScoreboard;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
public class FlatteningWrapper8 implements FlatteningWrapper.IFlatteningWrapper {
private static final Reflection.FieldAccessor<String> scoreboardName = Reflection.getField(SWScoreboard.scoreboardObjective, String.class, 1);
private static final Reflection.FieldAccessor<String> scoreboardName = Reflection.getField(FlatteningWrapper.scoreboardObjective, String.class, 1);
private static final Class<?> scoreActionEnum = Reflection.getClass("{nms}.PacketPlayOutScoreboardScore$EnumScoreboardAction");
private static final Reflection.FieldAccessor<?> scoreAction = Reflection.getField(SWScoreboard.scoreboardScore, scoreActionEnum, 0);
private static final Reflection.FieldAccessor<?> scoreAction = Reflection.getField(FlatteningWrapper.scoreboardScore, scoreActionEnum, 0);
private static final Object scoreActionChange = scoreActionEnum.getEnumConstants()[0];
@Override

Datei anzeigen

@ -19,12 +19,16 @@
package de.steamwar.core;
import com.comphenix.tinyprotocol.Reflection;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
public class FlatteningWrapper {
private FlatteningWrapper() {}
public static final Class<?> scoreboardObjective = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutScoreboardObjective");
public static final Class<?> scoreboardScore = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutScoreboardScore");
public static final IFlatteningWrapper impl = VersionDependent.getVersionImpl(Core.getInstance());
public interface IFlatteningWrapper {

Datei anzeigen

@ -32,17 +32,15 @@ import java.util.Map;
public class SWScoreboard {
private SWScoreboard() {}
public static final Class<?> scoreboardObjective = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutScoreboardObjective");
private static final Reflection.FieldAccessor<String> scoreboardName = Reflection.getField(scoreboardObjective, String.class, 0);
private static final Reflection.FieldAccessor<Integer> scoreboardAction = Reflection.getField(scoreboardObjective, int.class, 0);
private static final Reflection.FieldAccessor<String> scoreboardName = Reflection.getField(FlatteningWrapper.scoreboardObjective, String.class, 0);
private static final Reflection.FieldAccessor<Integer> scoreboardAction = Reflection.getField(FlatteningWrapper.scoreboardObjective, int.class, Core.getVersion() > 15 ? 3 : 0);
private static final Class<?> scoreboardDisplayEnum = Reflection.getClass("{nms.world.scores.criteria}.IScoreboardCriteria$EnumScoreboardHealthDisplay");
private static final Reflection.FieldAccessor<?> scoreboardDisplayType = Reflection.getField(scoreboardObjective, scoreboardDisplayEnum, 0);
private static final Reflection.FieldAccessor<?> scoreboardDisplayType = Reflection.getField(FlatteningWrapper.scoreboardObjective, scoreboardDisplayEnum, 0);
private static final Object displayTypeIntegers = scoreboardDisplayEnum.getEnumConstants()[0];
public static final Class<?> scoreboardScore = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutScoreboardScore");
private static final Reflection.FieldAccessor<String> scoreName = Reflection.getField(scoreboardScore, String.class, 0);
private static final Reflection.FieldAccessor<String> scoreScoreboardName = Reflection.getField(scoreboardScore, String.class, 1);
private static final Reflection.FieldAccessor<Integer> scoreValue = Reflection.getField(scoreboardScore, int.class, 0);
private static final Reflection.FieldAccessor<String> scoreName = Reflection.getField(FlatteningWrapper.scoreboardScore, String.class, 0);
private static final Reflection.FieldAccessor<String> scoreScoreboardName = Reflection.getField(FlatteningWrapper.scoreboardScore, String.class, 1);
private static final Reflection.FieldAccessor<Integer> scoreValue = Reflection.getField(FlatteningWrapper.scoreboardScore, int.class, 0);
private static final HashMap<Player, ScoreboardCallback> playerBoards = new HashMap<>(); //Object -> Scoreboard | Alle Versionen in der Map!
private static int toggle = 0; // Scoreboard 0 updates while scoreboard 1 is presenting. toggle marks the current active scoreboard
@ -56,7 +54,7 @@ public class SWScoreboard {
Reflection.FieldAccessor<String> scoreboardDisplayName = Reflection.getField(scoreboardDisplayObjective, String.class, 0);
Reflection.FieldAccessor<Integer> scoreboardDisplaySlot = Reflection.getField(scoreboardDisplayObjective, int.class, 0);
for(int id = 0; id < 2; id++) {
DELETE_SCOREBOARD[id] = Reflection.newInstance(scoreboardObjective);
DELETE_SCOREBOARD[id] = Reflection.newInstance(FlatteningWrapper.scoreboardObjective);
scoreboardName.set(DELETE_SCOREBOARD[id], SIDEBAR + id);
scoreboardAction.set(DELETE_SCOREBOARD[id], 1); //1 to remove
@ -100,7 +98,7 @@ public class SWScoreboard {
}
private static Object createSidebarPacket(String name){
Object packet = Reflection.newInstance(scoreboardObjective);
Object packet = Reflection.newInstance(FlatteningWrapper.scoreboardObjective);
scoreboardName.set(packet, SIDEBAR + toggle);
scoreboardAction.set(packet, 0); //0 to create
FlatteningWrapper.impl.setScoreboardTitle(packet, name);
@ -109,7 +107,7 @@ public class SWScoreboard {
}
private static Object createScorePacket(String name, int value){
Object packet = Reflection.newInstance(scoreboardScore);
Object packet = Reflection.newInstance(FlatteningWrapper.scoreboardScore);
scoreName.set(packet, name);
scoreScoreboardName.set(packet, SIDEBAR + toggle);
scoreValue.set(packet, value);