Update to Core.versionDependantCall
Dieser Commit ist enthalten in:
Ursprung
1b188977a0
Commit
19394d03ee
@ -24,6 +24,7 @@ import com.google.common.io.ByteStreams;
|
|||||||
import de.steamwar.comms.handlers.BungeeHandler;
|
import de.steamwar.comms.handlers.BungeeHandler;
|
||||||
import de.steamwar.comms.handlers.InventoryHandler;
|
import de.steamwar.comms.handlers.InventoryHandler;
|
||||||
import de.steamwar.core.Core;
|
import de.steamwar.core.Core;
|
||||||
|
import de.steamwar.core.VersionedRunnable;
|
||||||
import de.steamwar.sql.*;
|
import de.steamwar.sql.*;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -46,11 +47,8 @@ public class BungeeReceiver implements PluginMessageListener {
|
|||||||
UUID uuid = SteamwarUser.get(byteArrayDataInput.readInt()).getUUID();
|
UUID uuid = SteamwarUser.get(byteArrayDataInput.readInt()).getUUID();
|
||||||
if(Bukkit.getPlayer(uuid).isOnline()) {
|
if(Bukkit.getPlayer(uuid).isOnline()) {
|
||||||
Player player = Bukkit.getPlayer(uuid);
|
Player player = Bukkit.getPlayer(uuid);
|
||||||
if (Core.getVersion() == 8) {
|
Core.versionDependantCall(new VersionedRunnable(() -> BungeeReceiver_8.playPling(player), 8),
|
||||||
BungeeReceiver_8.playPling(player);
|
new VersionedRunnable(() -> BungeeReceiver_9.playpling(player)));
|
||||||
} else {
|
|
||||||
BungeeReceiver_9.playpling(player);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -147,4 +147,19 @@ public class Core extends JavaPlugin{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void versionDependantCall(VersionedRunnable versionedRunnable1, VersionedRunnable versionedRunnable2) {
|
||||||
|
if (versionedRunnable1.isVersion()) {
|
||||||
|
versionedRunnable1.run();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
versionedRunnable2.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> T versionDependantCall(VersionedCallable<T> versionedCallable1, VersionedCallable<T> versionedCallable2) {
|
||||||
|
if (versionedCallable1.isVersion()) {
|
||||||
|
return versionedCallable1.call();
|
||||||
|
}
|
||||||
|
return versionedCallable2.call();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -71,21 +71,7 @@ public class TPSWatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static double[] getSpigotTPS() {
|
private static double[] getSpigotTPS() {
|
||||||
switch (Core.getVersion()) {
|
return Core.versionDependantCall(SpigotTPS_8::getTps, SpigotTPS_9::getTps, SpigotTPS_10::getTps, SpigotTPS_12::getTps, SpigotTPS_14::getTps, SpigotTPS_15::getTps);
|
||||||
case 8:
|
|
||||||
return SpigotTPS_8.getTps();
|
|
||||||
case 9:
|
|
||||||
return SpigotTPS_9.getTps();
|
|
||||||
case 10:
|
|
||||||
return SpigotTPS_10.getTps();
|
|
||||||
case 12:
|
|
||||||
return SpigotTPS_12.getTps();
|
|
||||||
case 14:
|
|
||||||
return SpigotTPS_14.getTps();
|
|
||||||
case 15:
|
|
||||||
default:
|
|
||||||
return SpigotTPS_15.getTps();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static double round(double d) {
|
private static double round(double d) {
|
||||||
|
45
SpigotCore_Main/src/de/steamwar/core/VersionedCallable.java
Normale Datei
45
SpigotCore_Main/src/de/steamwar/core/VersionedCallable.java
Normale Datei
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 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 java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class VersionedCallable<T> {
|
||||||
|
|
||||||
|
private ExceptionlessCallable<T> exceptionlessCallable;
|
||||||
|
private Set<Integer> versions = new HashSet<>();
|
||||||
|
|
||||||
|
public VersionedCallable(ExceptionlessCallable<T> exceptionlessCallable, int... versions) {
|
||||||
|
this.exceptionlessCallable = exceptionlessCallable;
|
||||||
|
for (int version : versions) this.versions.add(version);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isVersion() {
|
||||||
|
return versions.contains(Core.getVersion());
|
||||||
|
}
|
||||||
|
|
||||||
|
public T call() {
|
||||||
|
return exceptionlessCallable.call();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
45
SpigotCore_Main/src/de/steamwar/core/VersionedRunnable.java
Normale Datei
45
SpigotCore_Main/src/de/steamwar/core/VersionedRunnable.java
Normale Datei
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 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 java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class VersionedRunnable {
|
||||||
|
|
||||||
|
private Runnable runnable;
|
||||||
|
private Set<Integer> versions = new HashSet<>();
|
||||||
|
|
||||||
|
public VersionedRunnable(Runnable runnable, int... versions) {
|
||||||
|
this.runnable = runnable;
|
||||||
|
for (int version : versions) this.versions.add(version);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isVersion() {
|
||||||
|
return versions.contains(Core.getVersion());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
runnable.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -71,25 +71,11 @@ public class ChunkListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void sendChunk(Player p, int chunkX, int chunkZ){
|
public static void sendChunk(Player p, int chunkX, int chunkZ){
|
||||||
switch(Core.getVersion()){
|
Core.versionDependantCall(() -> Chunk_8.sendChunk(p, chunkX, chunkZ),
|
||||||
case 15:
|
() -> Chunk_9.sendChunk(p, chunkX, chunkZ),
|
||||||
Chunk_15.sendChunk(p, chunkX, chunkZ);
|
() -> Chunk_10.sendChunk(p, chunkX, chunkZ),
|
||||||
break;
|
() -> Chunk_12.sendChunk(p, chunkX, chunkZ),
|
||||||
case 14:
|
() -> Chunk_14.sendChunk(p, chunkX, chunkZ),
|
||||||
Chunk_14.sendChunk(p, chunkX, chunkZ);
|
() -> Chunk_15.sendChunk(p, chunkX, chunkZ));
|
||||||
break;
|
|
||||||
case 12:
|
|
||||||
Chunk_12.sendChunk(p, chunkX, chunkZ);
|
|
||||||
break;
|
|
||||||
case 10:
|
|
||||||
Chunk_10.sendChunk(p, chunkX, chunkZ);
|
|
||||||
break;
|
|
||||||
case 9:
|
|
||||||
Chunk_9.sendChunk(p, chunkX, chunkZ);
|
|
||||||
break;
|
|
||||||
case 8:
|
|
||||||
Chunk_8.sendChunk(p, chunkX, chunkZ);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ package de.steamwar.inventory;
|
|||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import de.steamwar.core.Core;
|
import de.steamwar.core.Core;
|
||||||
|
import de.steamwar.core.VersionedCallable;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
@ -44,53 +45,24 @@ public class SWItem {
|
|||||||
|
|
||||||
public static SWItem getPlayerSkull(String playerName){
|
public static SWItem getPlayerSkull(String playerName){
|
||||||
SWItem p = new SWItem();
|
SWItem p = new SWItem();
|
||||||
ItemStack head;
|
ItemStack head = Core.versionDependantCall(new VersionedCallable<>(() -> SWItem_8.setSkullOwner(playerName), 8, 9, 10, 12),
|
||||||
switch(Core.getVersion()){
|
new VersionedCallable<>(() -> SWItem_14.setSkullOwner(playerName)));
|
||||||
case 8:
|
|
||||||
case 9:
|
|
||||||
case 10:
|
|
||||||
case 12:
|
|
||||||
head = SWItem_8.setSkullOwner(playerName);
|
|
||||||
break;
|
|
||||||
case 14:
|
|
||||||
case 15:
|
|
||||||
default:
|
|
||||||
head = SWItem_14.setSkullOwner(playerName);
|
|
||||||
}
|
|
||||||
p.setItemStack(head);
|
p.setItemStack(head);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Material getMaterial(String material){
|
public static Material getMaterial(String material){
|
||||||
try{
|
try{
|
||||||
switch(Core.getVersion()){
|
return Core.versionDependantCall(new VersionedCallable<>(() -> SWItem_8.getMaterial(material), 8, 9, 10, 12),
|
||||||
case 8:
|
new VersionedCallable<>(() -> SWItem_14.getMaterial(material)));
|
||||||
case 9:
|
|
||||||
case 10:
|
|
||||||
case 12:
|
|
||||||
return SWItem_8.getMaterial(material);
|
|
||||||
case 14:
|
|
||||||
case 15:
|
|
||||||
default:
|
|
||||||
return SWItem_14.getMaterial(material);
|
|
||||||
}
|
|
||||||
}catch(IllegalArgumentException e){
|
}catch(IllegalArgumentException e){
|
||||||
return Material.STONE;
|
return Material.STONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Material getDye(int colorCode){
|
public static Material getDye(int colorCode){
|
||||||
switch(Core.getVersion()){
|
return Core.versionDependantCall(new VersionedCallable<>(SWItem_8::getDye, 8, 9, 10, 12),
|
||||||
case 8:
|
new VersionedCallable<>(() -> SWItem_14.getDye(colorCode)));
|
||||||
case 9:
|
|
||||||
case 10:
|
|
||||||
case 12:
|
|
||||||
return SWItem_8.getDye();
|
|
||||||
case 14:
|
|
||||||
case 15:
|
|
||||||
default:
|
|
||||||
return SWItem_14.getDye(colorCode);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SWItem() {
|
public SWItem() {
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
package de.steamwar.message;
|
package de.steamwar.message;
|
||||||
|
|
||||||
import de.steamwar.core.Core;
|
import de.steamwar.core.Core;
|
||||||
|
import de.steamwar.core.VersionedCallable;
|
||||||
import net.md_5.bungee.api.ChatMessageType;
|
import net.md_5.bungee.api.ChatMessageType;
|
||||||
import net.md_5.bungee.api.chat.ClickEvent;
|
import net.md_5.bungee.api.chat.ClickEvent;
|
||||||
import net.md_5.bungee.api.chat.HoverEvent;
|
import net.md_5.bungee.api.chat.HoverEvent;
|
||||||
@ -73,17 +74,8 @@ public class Message {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Locale getLocale(Player player){
|
private Locale getLocale(Player player){
|
||||||
switch(Core.getVersion()){
|
return Core.versionDependantCall(new VersionedCallable<>(() -> Message_8.getLocale(player), 8, 9, 10),
|
||||||
case 8:
|
new VersionedCallable<>(() -> Message_12.getLocale(player)));
|
||||||
case 9:
|
|
||||||
case 10:
|
|
||||||
return Message_8.getLocale(player);
|
|
||||||
case 12:
|
|
||||||
case 14:
|
|
||||||
case 15:
|
|
||||||
default:
|
|
||||||
return Message_12.getLocale(player);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Send a message to one player */
|
/* Send a message to one player */
|
||||||
|
@ -25,6 +25,7 @@ import com.comphenix.protocol.ProtocolManager;
|
|||||||
import com.comphenix.protocol.events.PacketContainer;
|
import com.comphenix.protocol.events.PacketContainer;
|
||||||
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
||||||
import de.steamwar.core.Core;
|
import de.steamwar.core.Core;
|
||||||
|
import de.steamwar.core.VersionedRunnable;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@ -94,18 +95,8 @@ public class SWScoreboard {
|
|||||||
PacketContainer packet = manager.createPacket(PacketType.Play.Server.SCOREBOARD_OBJECTIVE);
|
PacketContainer packet = manager.createPacket(PacketType.Play.Server.SCOREBOARD_OBJECTIVE);
|
||||||
packet.getStrings().write(0, SIDEBAR + toggle);
|
packet.getStrings().write(0, SIDEBAR + toggle);
|
||||||
packet.getIntegers().write(0, 0); //0 to create
|
packet.getIntegers().write(0, 0); //0 to create
|
||||||
switch(Core.getVersion()){
|
Core.versionDependantCall(new VersionedRunnable(() -> packet.getStrings().write(1, name), 8, 9, 10, 12),
|
||||||
case 8:
|
new VersionedRunnable(() -> packet.getChatComponents().write(0, WrappedChatComponent.fromText(name))));
|
||||||
case 9:
|
|
||||||
case 10:
|
|
||||||
case 12:
|
|
||||||
packet.getStrings().write(1, name);
|
|
||||||
break;
|
|
||||||
case 14:
|
|
||||||
case 15:
|
|
||||||
default:
|
|
||||||
packet.getChatComponents().write(0, WrappedChatComponent.fromText(name));
|
|
||||||
}
|
|
||||||
packet.getEnumModifier(RenderType.class, 2).write(0, RenderType.INTEGER);
|
packet.getEnumModifier(RenderType.class, 2).write(0, RenderType.INTEGER);
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ package de.steamwar.sql;
|
|||||||
|
|
||||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||||
import de.steamwar.core.Core;
|
import de.steamwar.core.Core;
|
||||||
|
import de.steamwar.core.VersionedCallable;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren