SteamWar/SpigotCore
Archiviert
13
0

Merge branch 'master' into standalone
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
Lixfel 2022-02-11 22:05:35 +01:00
Commit 2202f5aa7b
9 geänderte Dateien mit 101 neuen und 58 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

@ -17,6 +17,11 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
SWLISINV_NEXT_PAGE_ACTIVE = §eSeite vor
SWLISINV_NEXT_PAGE_INACTIVE = §7Seite vor
SWLISINV_PREVIOUS_PAGE_ACTIVE = §eSeite zurück
SWLISINV_PREVIOUS_PAGE_INACTIVE = §7Seite zurück
SCHEM_SELECTOR_TITLE={0} auswählen: {1}
SCHEM_SELECTOR_BACK=§eZurück
SCHEM_SELECTOR_DIR=§9Ordner

Datei anzeigen

@ -1,6 +1,7 @@
package com.comphenix.tinyprotocol;
import de.steamwar.core.Core;
import jdk.internal.misc.Unsafe;
import org.bukkit.Bukkit;
import java.lang.reflect.Constructor;
@ -367,7 +368,11 @@ public final class Reflection {
@SuppressWarnings("deprecation")
public static Object newInstance(Class<?> clazz) {
try {
return clazz.newInstance();
if (Core.getVersion() > 15) {
return Unsafe.getUnsafe().allocateInstance(clazz);
} else {
return clazz.newInstance();
}
} catch (InstantiationException | IllegalAccessException e) {
throw new SecurityException("Could not create object", e);
}

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

@ -19,6 +19,7 @@
package de.steamwar.inventory;
import de.steamwar.core.Core;
import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SchematicType;
import org.bukkit.Bukkit;
@ -57,29 +58,33 @@ public class SWListInv<T> extends SWInventory {
callbacks.clear();
setCallback(-999, (ClickType click) -> player.closeInventory());
if(sizeBiggerMax()){
if(page != 0)
setItem(45, SWItem.getDye(10), (byte)10, "§eSeite zurück", (ClickType click) -> {
if (sizeBiggerMax()) {
if (page != 0) {
setItem(45, SWItem.getDye(10), (byte) 10, Core.MESSAGE.parse("SWLISINV_PREVIOUS_PAGE_ACTIVE", player), (ClickType click) -> {
page--;
open();
});
else
setItem(45, SWItem.getDye(8), (byte)8, "§7Seite zurück", (ClickType click) -> {});
if(page < elements.size()/45)
setItem(53, SWItem.getDye(10), (byte)10, "§eSeite vor", (ClickType click) -> {
} else {
setItem(45, SWItem.getDye(8), (byte) 8, Core.MESSAGE.parse("SWLISINV_PREVIOUS_PAGE_INACTIVE", player), (ClickType click) -> {
});
}
if (page < elements.size() / 45 - (elements.size() % 45 == 0 ? 1 : 0)) {
setItem(53, SWItem.getDye(10), (byte) 10, Core.MESSAGE.parse("SWLISINV_NEXT_PAGE_ACTIVE", player), (ClickType click) -> {
page++;
open();
});
else
setItem(53, SWItem.getDye(8), (byte)8, "§7Seite vor", (ClickType click) -> {});
} else {
setItem(53, SWItem.getDye(8), (byte) 8, Core.MESSAGE.parse("SWLISINV_NEXT_PAGE_INACTIVE", player), (ClickType click) -> {
});
}
}
int ipageLimit = elements.size() - page*45;
if(ipageLimit > 45 && sizeBiggerMax()){
int ipageLimit = elements.size() - page * 45;
if (ipageLimit > 45 && sizeBiggerMax()) {
ipageLimit = 45;
}
int i = page*45;
for(int ipage=0; ipage < ipageLimit; ipage++ ){
int i = page * 45;
for (int ipage = 0; ipage < ipageLimit; ipage++) {
SWItem e = elements.get(i).getItem();
final int pos = i;
@ -88,8 +93,9 @@ public class SWListInv<T> extends SWInventory {
i++;
}
for(Map.Entry<Integer, SWItem> customItem : customItems.entrySet())
for (Map.Entry<Integer, SWItem> customItem : customItems.entrySet()) {
setItem(customItem.getKey(), customItem.getValue());
}
super.open();
}

Datei anzeigen

@ -41,7 +41,8 @@ public class SchematicSelector {
@Getter
private SteamwarUser user;
@Getter
private final Consumer<SchematicNode> callback;
@Setter
private Consumer<SchematicNode> callback;
private final SelectorTarget target;
@Getter
private final SelectorFilter filter = new SelectorFilter();
@ -58,6 +59,8 @@ public class SchematicSelector {
private int depth = 0;
private Sorting sorting = Sorting.NAME;
private boolean invertSorting = false;
@Getter
private SchematicNode lastParent;
public SchematicSelector(Player player, SelectorTarget target, Consumer<SchematicNode> callback) {
this.player = player;
@ -78,9 +81,22 @@ public class SchematicSelector {
this.user = SteamwarUser.get(0);
}
openList(null);
injectable.onSelectorOpen(this, SchematicSelectorInjectable.OpenFrom.FRESH);
}
public void reOpen() {
openList(lastParent);
injectable.onSelectorOpen(this, SchematicSelectorInjectable.OpenFrom.REOPEN);
}
public void reOpenDirUp() {
depth--;
openList(dirUp(lastParent));
injectable.onSelectorOpen(this, SchematicSelectorInjectable.OpenFrom.REOPEN);
}
private void openList(SchematicNode parent) {
lastParent = parent;
List<SchematicNode> nodes = applySorting(filter.isFilter()?getFilteredSchematics():getSchematicList(parent));
if(sdoTrigger) {
@ -140,34 +156,38 @@ public class SchematicSelector {
inv.open();
}
private SchematicNode dirUp(SchematicNode parent) {
if(!singleDirOpen) {
if(NodeMember.getNodeMember(parent.getId(), user.getId()) != null) {
return null;
} else {
return getParent(parent);
}
} else {
SchematicNode currentParent = parent;
boolean isMember = false;
do {
sdoTrigger = false;
if(NodeMember.getNodeMember(currentParent.getId(), user.getId()) != null) {
isMember = true;
}
currentParent = getParent(currentParent);
if(currentParent == null)
break;
getSchematicList(currentParent);
} while (sdoTrigger);
if(isMember || NodeMember.getNodeMember(parent.getId(), user.getId()) != null) {
return null;
} else {
return currentParent;
}
}
}
private void handleClick(SchematicNode node, SchematicNode parent) {
if(node == null) {
depth--;
if(!singleDirOpen) {
if(NodeMember.getNodeMember(parent.getId(), user.getId()) != null) {
openList(null);
} else {
openList(getParent(parent));
}
} else {
SchematicNode currentParent = parent;
boolean isMember = false;
do {
sdoTrigger = false;
if(NodeMember.getNodeMember(currentParent.getId(), user.getId()) != null) {
isMember = true;
}
currentParent = getParent(currentParent);
if(currentParent == null)
break;
getSchematicList(currentParent);
} while (sdoTrigger);
if(isMember || NodeMember.getNodeMember(parent.getId(), user.getId()) != null) {
openList(null);
} else {
openList(currentParent);
}
}
openList(dirUp(parent));
return;
}
if(node.isDir()) {

Datei anzeigen

@ -42,4 +42,11 @@ public interface SchematicSelectorInjectable {
default boolean onFolderCreate(SchematicSelector selector, String name) {return true;}
default void onNodeFilter(SchematicSelector selector, SchematicNode node) {}
default void onSelectorOpen(SchematicSelector selector, OpenFrom from) {}
enum OpenFrom {
FRESH,
REOPEN
}
}

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);