SteamWar/SpigotCore
Archiviert
13
0
Fix SecurityException
Dieser Commit ist enthalten in:
jojo 2020-12-24 14:44:03 +01:00
Ursprung 65f747fdb3
Commit 97a766c797
9 geänderte Dateien mit 13 neuen und 19 gelöschten Zeilen

Datei anzeigen

@ -23,7 +23,6 @@ import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteStreams;
import de.steamwar.comms.handlers.BungeeHandler;
import de.steamwar.comms.handlers.InventoryHandler;
import de.steamwar.core.Core;
import de.steamwar.core.VersionedRunnable;
import de.steamwar.sql.*;
import org.bukkit.Bukkit;
@ -47,7 +46,7 @@ public class BungeeReceiver implements PluginMessageListener {
UUID uuid = SteamwarUser.get(byteArrayDataInput.readInt()).getUUID();
if(Bukkit.getPlayer(uuid).isOnline()) {
Player player = Bukkit.getPlayer(uuid);
VersionedRunnable.versionDependantCall(new VersionedRunnable(() -> BungeeReceiver_8.playPling(player), 8),
VersionedRunnable.call(new VersionedRunnable(() -> BungeeReceiver_8.playPling(player), 8),
new VersionedRunnable(() -> BungeeReceiver_9.playpling(player), 9));
}

Datei anzeigen

@ -82,5 +82,4 @@ public class Core extends JavaPlugin{
private static void setInstance(Core instance) {
Core.instance = instance;
}
}

Datei anzeigen

@ -71,7 +71,7 @@ public class TPSWatcher {
}
private static double[] getSpigotTPS() {
return VersionedCallable.versionDependantCall(new VersionedCallable<>(SpigotTPS_8::getTps, 8),
return VersionedCallable.call(new VersionedCallable<>(SpigotTPS_8::getTps, 8),
new VersionedCallable<>(SpigotTPS_9::getTps, 9),
new VersionedCallable<>(SpigotTPS_10::getTps, 10),
new VersionedCallable<>(SpigotTPS_12::getTps, 12),

Datei anzeigen

@ -35,15 +35,14 @@ public class VersionedCallable<T> {
return exceptionlessCallable.call();
}
public static <T> T versionDependantCall(VersionedCallable<T>... versionedCallables) {
int version = Core.getVersion();
public static <T> T call(VersionedCallable<T>... versionedCallables) {
for (int i = versionedCallables.length - 1; i >= 0; i--) {
VersionedCallable<T> versionedCallable = versionedCallables[i];
if (version >= versionedCallable.minVersion || i == 0) {
if (Core.getVersion() >= versionedCallable.minVersion) {
return versionedCallable.call();
}
}
return null;
throw new SecurityException();
}
}

Datei anzeigen

@ -35,11 +35,10 @@ public class VersionedRunnable {
runnable.run();
}
public static void versionDependantCall(VersionedRunnable... versionedRunnables) {
int version = Core.getVersion();
public static void call(VersionedRunnable... versionedRunnables) {
for (int i = versionedRunnables.length - 1; i >= 0; i--) {
VersionedRunnable versionedRunnable = versionedRunnables[i];
if (version >= versionedRunnable.minVersion) {
if (Core.getVersion() >= versionedRunnable.minVersion) {
versionedRunnable.run();
return;
}

Datei anzeigen

@ -72,7 +72,7 @@ public class ChunkListener {
}
public static void sendChunk(Player p, int chunkX, int chunkZ){
VersionedRunnable.versionDependantCall(new VersionedRunnable(() -> Chunk_8.sendChunk(p, chunkX, chunkZ), 8),
VersionedRunnable.call(new VersionedRunnable(() -> Chunk_8.sendChunk(p, chunkX, chunkZ), 8),
new VersionedRunnable(() -> Chunk_9.sendChunk(p, chunkX, chunkZ), 9),
new VersionedRunnable(() -> Chunk_10.sendChunk(p, chunkX, chunkZ), 10),
new VersionedRunnable(() -> Chunk_12.sendChunk(p, chunkX, chunkZ), 12),

Datei anzeigen

@ -21,7 +21,6 @@ package de.steamwar.inventory;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import de.steamwar.core.Core;
import de.steamwar.core.VersionedCallable;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
@ -45,7 +44,7 @@ public class SWItem {
public static SWItem getPlayerSkull(String playerName){
SWItem p = new SWItem();
ItemStack head = VersionedCallable.versionDependantCall(new VersionedCallable<>(() -> SWItem_8.setSkullOwner(playerName), 8),
ItemStack head = VersionedCallable.call(new VersionedCallable<>(() -> SWItem_8.setSkullOwner(playerName), 8),
new VersionedCallable<>(() -> SWItem_14.setSkullOwner(playerName), 14));
p.setItemStack(head);
return p;
@ -53,7 +52,7 @@ public class SWItem {
public static Material getMaterial(String material){
try{
return VersionedCallable.versionDependantCall(new VersionedCallable<>(() -> SWItem_8.getMaterial(material), 8),
return VersionedCallable.call(new VersionedCallable<>(() -> SWItem_8.getMaterial(material), 8),
new VersionedCallable<>(() -> SWItem_14.getMaterial(material), 14));
}catch(IllegalArgumentException e){
return Material.STONE;
@ -61,7 +60,7 @@ public class SWItem {
}
public static Material getDye(int colorCode){
return VersionedCallable.versionDependantCall(new VersionedCallable<>(SWItem_8::getDye, 8),
return VersionedCallable.call(new VersionedCallable<>(SWItem_8::getDye, 8),
new VersionedCallable<>(() -> SWItem_14.getDye(colorCode), 14));
}

Datei anzeigen

@ -19,7 +19,6 @@
package de.steamwar.message;
import de.steamwar.core.Core;
import de.steamwar.core.VersionedCallable;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.ClickEvent;
@ -74,7 +73,7 @@ public class Message {
}
private Locale getLocale(Player player){
return VersionedCallable.versionDependantCall(new VersionedCallable<>(() -> Message_8.getLocale(player), 8),
return VersionedCallable.call(new VersionedCallable<>(() -> Message_8.getLocale(player), 8),
new VersionedCallable<>(() -> Message_12.getLocale(player), 12));
}

Datei anzeigen

@ -95,7 +95,7 @@ public class SWScoreboard {
PacketContainer packet = manager.createPacket(PacketType.Play.Server.SCOREBOARD_OBJECTIVE);
packet.getStrings().write(0, SIDEBAR + toggle);
packet.getIntegers().write(0, 0); //0 to create
VersionedRunnable.versionDependantCall(new VersionedRunnable(() -> packet.getStrings().write(1, name), 8),
VersionedRunnable.call(new VersionedRunnable(() -> packet.getStrings().write(1, name), 8),
new VersionedRunnable(() -> packet.getChatComponents().write(0, WrappedChatComponent.fromText(name)), 14));
packet.getEnumModifier(RenderType.class, 2).write(0, RenderType.INTEGER);
return packet;