Merge remote-tracking branch 'origin/SchemTypeMaterial' into SchemTypeMaterial
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Dieser Commit ist enthalten in:
Commit
de126919b1
@ -222,15 +222,15 @@ public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper
|
|||||||
renamedLegacy.put("RECORD_12", Material.MUSIC_DISC_WAIT);
|
renamedLegacy.put("RECORD_12", Material.MUSIC_DISC_WAIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Reflection.FieldAccessor<?> scoreboardName = Reflection.getField(SWScoreboard.scoreboardObjective, Reflection.getClass("{nms}.IChatBaseComponent"), 0);
|
private static final Reflection.FieldAccessor<?> scoreboardName = Reflection.getField(SWScoreboard.scoreboardObjective, Reflection.getClass("{nms.network.chat}.IChatBaseComponent"), 0);
|
||||||
private static final Reflection.ConstructorInvoker chatComponentConstructor = Reflection.getConstructor(Reflection.getClass("{nms}.ChatComponentText"), String.class);
|
private static final Reflection.ConstructorInvoker chatComponentConstructor = Reflection.getConstructor(Reflection.getClass("{nms.network.chat}.ChatComponentText"), String.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setScoreboardTitle(Object packet, String title) {
|
public void setScoreboardTitle(Object packet, String title) {
|
||||||
scoreboardName.set(packet, chatComponentConstructor.invoke(title));
|
scoreboardName.set(packet, chatComponentConstructor.invoke(title));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Class<?> scoreActionEnum = Reflection.getClass("{nms}.ScoreboardServer$Action");
|
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(SWScoreboard.scoreboardScore, scoreActionEnum, 0);
|
||||||
private static final Object scoreActionChange = scoreActionEnum.getEnumConstants()[0];
|
private static final Object scoreActionChange = scoreActionEnum.getEnumConstants()[0];
|
||||||
|
|
||||||
|
50
SpigotCore_18/build.gradle
Normale Datei
50
SpigotCore_18/build.gradle
Normale Datei
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2021 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
id 'base'
|
||||||
|
id 'java'
|
||||||
|
}
|
||||||
|
|
||||||
|
group 'steamwar'
|
||||||
|
version '1.0'
|
||||||
|
|
||||||
|
compileJava.options.encoding = 'UTF-8'
|
||||||
|
|
||||||
|
sourceCompatibility = 1.8
|
||||||
|
targetCompatibility = 1.8
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
main {
|
||||||
|
java {
|
||||||
|
srcDirs = ['src/']
|
||||||
|
}
|
||||||
|
resources {
|
||||||
|
srcDirs = ['src/']
|
||||||
|
exclude '**/*.java', '**/*.kt'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation project(":SpigotCore_Main")
|
||||||
|
|
||||||
|
compileOnly 'org.spigotmc:spigot-api:1.18-R0.1-SNAPSHOT'
|
||||||
|
compileOnly files("${project.rootDir}/lib/Spigot-1.18.jar")
|
||||||
|
}
|
20
SpigotCore_18/settings.gradle
Normale Datei
20
SpigotCore_18/settings.gradle
Normale Datei
@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
rootProject.name = 'SpigotCore_18'
|
42
SpigotCore_18/src/de/steamwar/core/CraftbukkitWrapper18.java
Normale Datei
42
SpigotCore_18/src/de/steamwar/core/CraftbukkitWrapper18.java
Normale Datei
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
This file is a part of the SteamWar software.
|
||||||
|
|
||||||
|
Copyright (C) 2021 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 net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.world.level.chunk.Chunk;
|
||||||
|
import org.bukkit.craftbukkit.v1_18_R1.CraftChunk;
|
||||||
|
import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class CraftbukkitWrapper18 implements CraftbukkitWrapper.ICraftbukkitWrapper {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendChunk(Player p, int chunkX, int chunkZ) {
|
||||||
|
Chunk chunk = ((CraftChunk)p.getWorld().getChunkAt(chunkX, chunkZ)).getHandle();
|
||||||
|
((CraftPlayer)p).getHandle().b.a(new ClientboundLevelChunkWithLightPacket(chunk, chunk.q.l_(), null, null, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public double[] getSpigotTPS() {
|
||||||
|
return MinecraftServer.getServer().recentTps;
|
||||||
|
}
|
||||||
|
}
|
@ -53,7 +53,10 @@ sourceSets {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly files("${project.rootDir}/lib/Spigot-1.15.jar")
|
compileOnly 'org.spigotmc:spigot-api:1.18-R0.1-SNAPSHOT'
|
||||||
|
compileOnly 'io.netty:netty-all:4.1.68.Final'
|
||||||
|
compileOnly 'com.mojang:authlib:1.5.25'
|
||||||
|
compileOnly 'mysql:mysql-connector-java:5.1.49'
|
||||||
compileOnly files("${project.rootDir}/lib/WorldEdit-1.12.jar")
|
compileOnly files("${project.rootDir}/lib/WorldEdit-1.12.jar")
|
||||||
implementation 'net.wesjd:anvilgui:1.4.0-SNAPSHOT'
|
implementation 'net.wesjd:anvilgui:1.4.0-SNAPSHOT'
|
||||||
|
|
||||||
|
@ -17,47 +17,83 @@
|
|||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
|
|
||||||
SCHEM_SELECTOR_TITLE={0} auswählen: {1}
|
SCHEM_SELECTOR_TITLE={0} auswählen: {1}
|
||||||
SCHEM_SELECTOR_BACK=§eZurück
|
SCHEM_SELECTOR_BACK=§eZurück
|
||||||
SCHEM_SELECTOR_DIR=§9Ordner
|
SCHEM_SELECTOR_DIR=§9Ordner
|
||||||
SCHEM_SELECTOR_RANK=§8Rang {0}
|
SCHEM_SELECTOR_RANK=§8Rang {0}
|
||||||
SCHEM_SELECTOR_OWN=§7Eigene Schematics
|
SCHEM_SELECTOR_OWN=§7Eigene Schematics
|
||||||
SCHEM_SELECTOR_PUB=§7Public Schematics
|
SCHEM_SELECTOR_PUB=§7Public Schematics
|
||||||
SCHEM_SELECTOR_SEL_DIR=§7Ordner auswählen
|
SCHEM_SELECTOR_SEL_DIR=§7Ordner auswählen
|
||||||
SCHEM_SELECTOR_NEW_DIR=§7Neuer Ordner
|
SCHEM_SELECTOR_NEW_DIR=§7Neuer Ordner
|
||||||
SCHEM_SELECTOR_FILTER=§7Filter
|
SCHEM_SELECTOR_FILTER=§7Filter
|
||||||
SCHEM_SELECTOR_SORTING=§7Sortierung
|
SCHEM_SELECTOR_SORTING=§7Sortierung
|
||||||
SCHEM_SELECTOR_SORTING_CURRENT=§7Aktuell: §e{0}
|
SCHEM_SELECTOR_SORTING_CURRENT=§7Aktuell: §e{0}
|
||||||
SCHEM_SELECTOR_SORTING_NAME=Name
|
SCHEM_SELECTOR_SORTING_NAME=Name
|
||||||
SCHEM_SELECTOR_SORTING_TYPE=Schematic-Typ
|
SCHEM_SELECTOR_SORTING_TYPE=Schematic-Typ
|
||||||
SCHEM_SELECTOR_SORTING_UPDATE=Letztes Update
|
SCHEM_SELECTOR_SORTING_UPDATE=Letztes Update
|
||||||
SCHEM_SELECTOR_SORTING_DIRECTION=§7Richtung: §e{0}
|
SCHEM_SELECTOR_SORTING_DIRECTION=§7Richtung: §e{0}
|
||||||
SCHEM_SELECTOR_SORTING_ASC=Aufsteigend
|
SCHEM_SELECTOR_SORTING_ASC=Aufsteigend
|
||||||
SCHEM_SELECTOR_SORTING_DSC=Absteigend
|
SCHEM_SELECTOR_SORTING_DSC=Absteigend
|
||||||
|
|
||||||
SCHEM_SELECTOR_ITEM_NAME=§e{0}
|
SCHEM_SELECTOR_ITEM_NAME=§e{0}
|
||||||
SCHEM_SELECTOR_ITEM_NAME_FILTER=§7{0}
|
SCHEM_SELECTOR_ITEM_NAME_FILTER=§7{0}
|
||||||
SCHEM_SELECTOR_ITEM_REPLACE=§e{0}§7
|
SCHEM_SELECTOR_ITEM_REPLACE=§e{0}§7
|
||||||
SCHEM_SELECTOR_ITEM_LORE_TYPE=§7{0}
|
SCHEM_SELECTOR_ITEM_LORE_TYPE=§7{0}
|
||||||
|
|
||||||
SCHEM_SELECTOR_CREATE_DIR_TITLE=Ordner erstellen
|
SCHEM_SELECTOR_CREATE_DIR_TITLE=Ordner erstellen
|
||||||
|
|
||||||
SCHEM_SELECTOR_FILTER_TITLE=Filter
|
SCHEM_SELECTOR_FILTER_TITLE=Filter
|
||||||
SCHEM_SELECTOR_FILTER_ENTER_NAME=Name eingeben
|
SCHEM_SELECTOR_FILTER_ENTER_NAME=Name eingeben
|
||||||
SCHEM_SELECTOR_FILTER_NAME=§7Nach Namen suchen...
|
SCHEM_SELECTOR_FILTER_NAME=§7Nach Namen suchen...
|
||||||
SCHEM_SELECTOR_FILTER_NAME_SEARCH=§7Suchbegriff: §e{0}
|
SCHEM_SELECTOR_FILTER_NAME_SEARCH=§7Suchbegriff: §e{0}
|
||||||
SCHEM_SELECTOR_FILTER_ENTER_OWNER=Besitzer eingeben
|
SCHEM_SELECTOR_FILTER_ENTER_OWNER=Besitzer eingeben
|
||||||
SCHEM_SELECTOR_FILTER_OWNER=§7Nach Besitzer suchen...
|
SCHEM_SELECTOR_FILTER_OWNER=§7Nach Besitzer suchen...
|
||||||
SCHEM_SELECTOR_FILTER_OWNER_SEARCH=§7Besitzer: §e{0}
|
SCHEM_SELECTOR_FILTER_OWNER_SEARCH=§7Besitzer: §e{0}
|
||||||
SCHEM_SELECTOR_FILTER_SEL_TYPE=Typ wählen...
|
SCHEM_SELECTOR_FILTER_SEL_TYPE=Typ wählen...
|
||||||
SCHEM_SELECTOR_FILTER_TYPE=§7Nach Typ filtern...
|
SCHEM_SELECTOR_FILTER_TYPE=§7Nach Typ filtern...
|
||||||
SCHEM_SELECTOR_FILTER_TYPE_SEARCH=§7Typ: §e{0}
|
SCHEM_SELECTOR_FILTER_TYPE_SEARCH=§7Typ: §e{0}
|
||||||
SCHEM_SELECTOR_FILTER_MAT=§7Nach Item filtern...
|
SCHEM_SELECTOR_FILTER_MAT=§7Nach Item filtern...
|
||||||
SCHEM_SELECTOR_FILTER_MAT_SEARCH=§7Item: §e{0}
|
SCHEM_SELECTOR_FILTER_MAT_SEARCH=§7Item: §e{0}
|
||||||
SCHEM_SELECTOR_CANCEL=§eAbbrechen
|
SCHEM_SELECTOR_CANCEL=§eAbbrechen
|
||||||
SCHEM_SELECTOR_GO=§eSuchen...
|
SCHEM_SELECTOR_GO=§eSuchen...
|
||||||
SCHEM_SELECTOR_SCHEMATIC=Schematic
|
SCHEM_SELECTOR_SCHEMATIC=Schematic
|
||||||
SCHEM_SELECTOR_DIRECTORY=Ordner
|
SCHEM_SELECTOR_DIRECTORY=Ordner
|
||||||
SCHEM_SELECTOR_SCHEMATIC_NODE=Schematic/Ordner
|
SCHEM_SELECTOR_SCHEMATIC_NODE=Schematic/Ordner
|
||||||
|
|
||||||
MATERIAL_SELECTOR_TITLE=Material auswählen
|
MATERIAL_SELECTOR_TITLE=Material auswählen
|
||||||
|
|
||||||
|
BAN_TEAM={0} §e{1} §7wurde von §e{2} {3} §e§lgebannt§8. §7Grund§8: §f{4}
|
||||||
|
BAN_PERMA=§7Du bist §epermanent §e§lgebannt§8. §7Grund§8: §e{0}
|
||||||
|
BAN_UNTIL=§7Du bist §ebis zum {0} §e§lgebannt§8. §7Grund§8: §e{1}
|
||||||
|
UNBAN_ERROR=§cDer Spieler ist nicht gebannt.
|
||||||
|
UNBAN=§7Du hast §e{0} §e§lentbannt.
|
||||||
|
|
||||||
|
MUTE_TEAM={0} §e{1} §7wurde von §e{2} {3} §e§lgemuted§8. §7Grund§8: §f{4}
|
||||||
|
MUTE_PERMA=§7Du bist §epermanent §e§lgemuted§8. §7Grund§8: §e{0}
|
||||||
|
MUTE_UNTIL=§7Du bist §ebis zum {0} §e§lgemuted§8. §7Grund§8: §e{1}
|
||||||
|
UNMUTE_ERROR=§cDer Spieler ist nicht gemuted.
|
||||||
|
UNMUTE=§7Du hast §e{0} §e§lentmuted.
|
||||||
|
|
||||||
|
NOSCHEMRECEIVING_TEAM={0} §e{1} §7wurde von §e{2} {3} §7vom §e§lSchematicerhalten ausgeschlossen§8. §7Grund§8: §f{4}
|
||||||
|
NOSCHEMRECEIVING_PERMA=§7Du bist §epermanent §7vom Erhalten von §e§lSchematics ausgeschlossen§8. §7Grund§8: §e{0}
|
||||||
|
NOSCHEMRECEIVING_UNTIL=§7Du bist §ebis zum {0} §7vom Erhalten von §e§lSchematics ausgeschlossen§8. §7Grund§8: §e{1}
|
||||||
|
UNNOSCHEMRECEIVING_ERROR=§cDer Spieler ist nicht vom Erhalten von Schematics ausgeschlossen.
|
||||||
|
UNNOSCHEMRECEIVING=§e{0} §7darf nun wieder §e§lSchematics erhalten§8.
|
||||||
|
|
||||||
|
NOSCHEMSHARING_TEAM={0} §e{1} §7wurde von §e{2} {3} §7vom §e§lSchematicverteilen ausgeschlossen§8. §7Grund§8: §f{4}
|
||||||
|
NOSCHEMSHARING_PERMA=§7Du bist §epermanent §7vom §e§lVerteilen von Schematics§7 ausgeschlossen§8. §7Grund§8: §e{0}
|
||||||
|
NOSCHEMSHARING_UNTIL=§7Du bist §ebis zum {0} §7vom §e§lVerteilen von Schematics§7 ausgeschlossen§8. §7Grund§8: §e{1}
|
||||||
|
UNNOSCHEMSHARING_ERROR=§cDer Spieler ist nicht vom Verteilen von Schematics ausgeschlossen.
|
||||||
|
UNNOSCHEMSHARING=§e{0} §7darf nun wieder §e§lSchematics verteilen§8.
|
||||||
|
|
||||||
|
NOSCHEMSUBMITTING_TEAM={0} §e{1} §7wurde von §e{2} {3} §7vom §e§lSchematiceinsenden ausgeschlossen§8. §7Grund§8: §f{4}
|
||||||
|
NOSCHEMSUBMITTING_PERMA=§7Du bist §epermanent §7vom §e§lEinsenden von Schematics§7 ausgeschlossen§8. §7Grund§8: §e{0}
|
||||||
|
NOSCHEMSUBMITTING_UNTIL=§7Du bist §ebis zum {0} §7vom §e§lEinsenden von Schematics§7 ausgeschlossen§8. §7Grund§8: §e{1}
|
||||||
|
UNNOSCHEMSUBMITTING_ERROR=§cDer Spieler ist nicht vom Einsenden von Schematics ausgeschlossen.
|
||||||
|
UNNOSCHEMSUBMITTING=§e{0} §7darf nun wieder §e§lSchematis einsenden§8.
|
||||||
|
|
||||||
|
NODEVSERVER_TEAM={0} §e{1} §7hat §e{2} §7mit Grund §f{4}§7 zu generft und hat daher §e§lDevserververbot §7erhalten§8, §e{3}
|
||||||
|
NODEVSERVER_PERMA=§7Du bist §epermanent §7vom §e§lDevserver §7ausgeschlossen§8. §7Grund§8: §e{0}
|
||||||
|
NODEVSERVER_UNTIL=§7Du bist §ebis zum {0} §7vom §e§lDevserver §7ausgeschlossen§8. §7Grund§8: §e{1}
|
||||||
|
UNNODEVSERVER_ERROR=§cDer Spieler ist nicht vom Devserver ausgeschlossen.
|
||||||
|
UNNODEVSERVER=§e{0} §7darf nun wieder dem §e§lDevserver beitreten§8.
|
@ -1,5 +1,6 @@
|
|||||||
package com.comphenix.tinyprotocol;
|
package com.comphenix.tinyprotocol;
|
||||||
|
|
||||||
|
import de.steamwar.core.Core;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
@ -25,7 +26,7 @@ public final class Reflection {
|
|||||||
* @param arguments - the arguments to pass to the constructor.
|
* @param arguments - the arguments to pass to the constructor.
|
||||||
* @return The constructed object.
|
* @return The constructed object.
|
||||||
*/
|
*/
|
||||||
public Object invoke(Object... arguments);
|
Object invoke(Object... arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -39,7 +40,7 @@ public final class Reflection {
|
|||||||
* @param arguments - the arguments to pass to the method.
|
* @param arguments - the arguments to pass to the method.
|
||||||
* @return The return value, or NULL if is void.
|
* @return The return value, or NULL if is void.
|
||||||
*/
|
*/
|
||||||
public Object invoke(Object target, Object... arguments);
|
Object invoke(Object target, Object... arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -54,7 +55,7 @@ public final class Reflection {
|
|||||||
* @param target - the target object, or NULL for a static field.
|
* @param target - the target object, or NULL for a static field.
|
||||||
* @return The value of the field.
|
* @return The value of the field.
|
||||||
*/
|
*/
|
||||||
public T get(Object target);
|
T get(Object target);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the content of a field.
|
* Set the content of a field.
|
||||||
@ -62,7 +63,7 @@ public final class Reflection {
|
|||||||
* @param target - the target object, or NULL for a static field.
|
* @param target - the target object, or NULL for a static field.
|
||||||
* @param value - the new value of the field.
|
* @param value - the new value of the field.
|
||||||
*/
|
*/
|
||||||
public void set(Object target, Object value);
|
void set(Object target, Object value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if the given object has this field.
|
* Determine if the given object has this field.
|
||||||
@ -70,16 +71,16 @@ public final class Reflection {
|
|||||||
* @param target - the object to test.
|
* @param target - the object to test.
|
||||||
* @return TRUE if it does, FALSE otherwise.
|
* @return TRUE if it does, FALSE otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean hasField(Object target);
|
boolean hasField(Object target);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deduce the net.minecraft.server.v* package
|
// Deduce the net.minecraft.server.v* package
|
||||||
private static String OBC_PREFIX = Bukkit.getServer().getClass().getPackage().getName();
|
private static final String OBC_PREFIX = Bukkit.getServer().getClass().getPackage().getName();
|
||||||
private static String NMS_PREFIX = OBC_PREFIX.replace("org.bukkit.craftbukkit", "net.minecraft.server");
|
private static final String NMS_PREFIX = OBC_PREFIX.replace("org.bukkit.craftbukkit", "net.minecraft.server");
|
||||||
private static String VERSION = OBC_PREFIX.replace("org.bukkit.craftbukkit", "").replace(".", "");
|
private static final String VERSION = OBC_PREFIX.replace("org.bukkit.craftbukkit", "").replace(".", "");
|
||||||
|
|
||||||
// Variable replacement
|
// Variable replacement
|
||||||
private static Pattern MATCH_VARIABLE = Pattern.compile("\\{([^\\}]+)\\}");
|
private static final Pattern MATCH_VARIABLE = Pattern.compile("\\{([^\\}]+)\\}");
|
||||||
|
|
||||||
private Reflection() {
|
private Reflection() {
|
||||||
// Seal class
|
// Seal class
|
||||||
@ -148,7 +149,7 @@ public final class Reflection {
|
|||||||
try {
|
try {
|
||||||
return (T) field.get(target);
|
return (T) field.get(target);
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
throw new RuntimeException("Cannot access reflection.", e);
|
throw new IllegalArgumentException("Cannot access reflection.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,7 +158,7 @@ public final class Reflection {
|
|||||||
try {
|
try {
|
||||||
field.set(target, value);
|
field.set(target, value);
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
throw new RuntimeException("Cannot access reflection.", e);
|
throw new IllegalArgumentException("Cannot access reflection.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,17 +221,12 @@ public final class Reflection {
|
|||||||
&& Arrays.equals(method.getParameterTypes(), params)) {
|
&& Arrays.equals(method.getParameterTypes(), params)) {
|
||||||
method.setAccessible(true);
|
method.setAccessible(true);
|
||||||
|
|
||||||
return new MethodInvoker() {
|
return (target, arguments) -> {
|
||||||
|
try {
|
||||||
@Override
|
return method.invoke(target, arguments);
|
||||||
public Object invoke(Object target, Object... arguments) {
|
} catch (Exception e) {
|
||||||
try {
|
throw new IllegalArgumentException("Cannot invoke method " + method, e);
|
||||||
return method.invoke(target, arguments);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException("Cannot invoke method " + method, e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -267,17 +263,12 @@ public final class Reflection {
|
|||||||
if (Arrays.equals(constructor.getParameterTypes(), params)) {
|
if (Arrays.equals(constructor.getParameterTypes(), params)) {
|
||||||
constructor.setAccessible(true);
|
constructor.setAccessible(true);
|
||||||
|
|
||||||
return new ConstructorInvoker() {
|
return arguments -> {
|
||||||
|
try {
|
||||||
@Override
|
return constructor.newInstance(arguments);
|
||||||
public Object invoke(Object... arguments) {
|
} catch (Exception e) {
|
||||||
try {
|
throw new IllegalArgumentException("Cannot invoke constructor " + constructor, e);
|
||||||
return constructor.newInstance(arguments);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException("Cannot invoke constructor " + constructor, e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -290,8 +281,7 @@ public final class Reflection {
|
|||||||
* <p>
|
* <p>
|
||||||
* This is useful when looking up fields by a NMS or OBC type.
|
* This is useful when looking up fields by a NMS or OBC type.
|
||||||
* <p>
|
* <p>
|
||||||
*
|
*
|
||||||
* @see {@link #getClass()} for more information.
|
|
||||||
* @param lookupName - the class name with variables.
|
* @param lookupName - the class name with variables.
|
||||||
* @return The class.
|
* @return The class.
|
||||||
*/
|
*/
|
||||||
@ -330,40 +320,10 @@ public final class Reflection {
|
|||||||
* @throws IllegalArgumentException If a variable or class could not be found.
|
* @throws IllegalArgumentException If a variable or class could not be found.
|
||||||
*/
|
*/
|
||||||
public static Class<?> getClass(String lookupName) {
|
public static Class<?> getClass(String lookupName) {
|
||||||
return getCanonicalClass(expandVariables(lookupName));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve a class in the net.minecraft.server.VERSION.* package.
|
|
||||||
*
|
|
||||||
* @param name - the name of the class, excluding the package.
|
|
||||||
* @throws IllegalArgumentException If the class doesn't exist.
|
|
||||||
*/
|
|
||||||
public static Class<?> getMinecraftClass(String name) {
|
|
||||||
return getCanonicalClass(NMS_PREFIX + "." + name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve a class in the org.bukkit.craftbukkit.VERSION.* package.
|
|
||||||
*
|
|
||||||
* @param name - the name of the class, excluding the package.
|
|
||||||
* @throws IllegalArgumentException If the class doesn't exist.
|
|
||||||
*/
|
|
||||||
public static Class<?> getCraftBukkitClass(String name) {
|
|
||||||
return getCanonicalClass(OBC_PREFIX + "." + name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve a class by its canonical name.
|
|
||||||
*
|
|
||||||
* @param canonicalName - the canonical name.
|
|
||||||
* @return The class.
|
|
||||||
*/
|
|
||||||
private static Class<?> getCanonicalClass(String canonicalName) {
|
|
||||||
try {
|
try {
|
||||||
return Class.forName(canonicalName);
|
return Class.forName(expandVariables(lookupName));
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
throw new IllegalArgumentException("Cannot find " + canonicalName, e);
|
throw new IllegalArgumentException("Cannot find " + expandVariables(lookupName), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -379,14 +339,17 @@ public final class Reflection {
|
|||||||
|
|
||||||
while (matcher.find()) {
|
while (matcher.find()) {
|
||||||
String variable = matcher.group(1);
|
String variable = matcher.group(1);
|
||||||
String replacement = "";
|
String replacement;
|
||||||
|
|
||||||
// Expand all detected variables
|
// Expand all detected variables
|
||||||
if ("nms".equalsIgnoreCase(variable))
|
if (variable.startsWith("nms")) {
|
||||||
replacement = NMS_PREFIX;
|
if(Core.getVersion() >= 17)
|
||||||
else if ("obc".equalsIgnoreCase(variable))
|
replacement = "net.minecraft" + variable.substring(3);
|
||||||
|
else
|
||||||
|
replacement = NMS_PREFIX;
|
||||||
|
} else if ("obc".equals(variable))
|
||||||
replacement = OBC_PREFIX;
|
replacement = OBC_PREFIX;
|
||||||
else if ("version".equalsIgnoreCase(variable))
|
else if ("version".equals(variable))
|
||||||
replacement = VERSION;
|
replacement = VERSION;
|
||||||
else
|
else
|
||||||
throw new IllegalArgumentException("Unknown variable: " + variable);
|
throw new IllegalArgumentException("Unknown variable: " + variable);
|
||||||
@ -401,6 +364,7 @@ public final class Reflection {
|
|||||||
return output.toString();
|
return output.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public static Object newInstance(Class<?> clazz) {
|
public static Object newInstance(Class<?> clazz) {
|
||||||
try {
|
try {
|
||||||
return clazz.newInstance();
|
return clazz.newInstance();
|
||||||
|
@ -5,6 +5,7 @@ import com.comphenix.tinyprotocol.Reflection.MethodInvoker;
|
|||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.MapMaker;
|
import com.google.common.collect.MapMaker;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
|
import de.steamwar.core.Core;
|
||||||
import io.netty.channel.*;
|
import io.netty.channel.*;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -28,72 +29,88 @@ import java.util.logging.Level;
|
|||||||
*
|
*
|
||||||
* @author Kristian
|
* @author Kristian
|
||||||
*/
|
*/
|
||||||
public abstract class TinyProtocol {
|
public class TinyProtocol {
|
||||||
private static final AtomicInteger ID = new AtomicInteger(0);
|
private static final AtomicInteger ID = new AtomicInteger(0);
|
||||||
|
|
||||||
// Used in order to lookup a channel
|
// Used in order to lookup a channel
|
||||||
private static final MethodInvoker getPlayerHandle = Reflection.getMethod("{obc}.entity.CraftPlayer", "getHandle");
|
private static final MethodInvoker getPlayerHandle = Reflection.getMethod("{obc}.entity.CraftPlayer", "getHandle");
|
||||||
private static final FieldAccessor<Object> getConnection = Reflection.getField("{nms}.EntityPlayer", "playerConnection", Object.class);
|
private static final Class<Object> playerConnection = Reflection.getUntypedClass("{nms.server.network}.PlayerConnection");
|
||||||
private static final FieldAccessor<Object> getManager = Reflection.getField("{nms}.PlayerConnection", "networkManager", Object.class);
|
private static final FieldAccessor<Object> getConnection = Reflection.getField("{nms.server.level}.EntityPlayer", playerConnection, 0);
|
||||||
private static final FieldAccessor<Channel> getChannel = Reflection.getField("{nms}.NetworkManager", Channel.class, 0);
|
private static final Class<Object> networkManager = Reflection.getUntypedClass("{nms.network}.NetworkManager");
|
||||||
|
private static final FieldAccessor<Object> getManager = Reflection.getField(playerConnection, networkManager, 0);
|
||||||
|
private static final FieldAccessor<Channel> getChannel = Reflection.getField(networkManager, Channel.class, 0);
|
||||||
|
|
||||||
// Looking up ServerConnection
|
// Looking up ServerConnection
|
||||||
private static final Class<Object> minecraftServerClass = Reflection.getUntypedClass("{nms}.MinecraftServer");
|
private static final Class<Object> minecraftServerClass = Reflection.getUntypedClass("{nms.server}.MinecraftServer");
|
||||||
private static final Class<Object> serverConnectionClass = Reflection.getUntypedClass("{nms}.ServerConnection");
|
private static final Class<Object> serverConnectionClass = Reflection.getUntypedClass("{nms.server.network}.ServerConnection");
|
||||||
private static final FieldAccessor<Object> getMinecraftServer = Reflection.getField("{obc}.CraftServer", minecraftServerClass, 0);
|
private static final FieldAccessor<Object> getMinecraftServer = Reflection.getField("{obc}.CraftServer", minecraftServerClass, 0);
|
||||||
private static final FieldAccessor<Object> getServerConnection = Reflection.getField(minecraftServerClass, serverConnectionClass, 0);
|
private static final FieldAccessor<Object> getServerConnection = Reflection.getField(minecraftServerClass, serverConnectionClass, 0);
|
||||||
private static final MethodInvoker getNetworkMarkers;
|
private static final FieldAccessor<Collection> getNetworkMarkers = Reflection.getField(serverConnectionClass, Collection.class, 1);
|
||||||
static {
|
|
||||||
MethodInvoker networkMarkers;
|
|
||||||
try {
|
|
||||||
networkMarkers = Reflection.getTypedMethod(serverConnectionClass, null, List.class, serverConnectionClass);
|
|
||||||
} catch (IllegalStateException e) { // Paper, wtf why.
|
|
||||||
networkMarkers = Reflection.getTypedMethod(serverConnectionClass, null, Queue.class, serverConnectionClass);
|
|
||||||
}
|
|
||||||
getNetworkMarkers = networkMarkers;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Packets we have to intercept
|
// Packets we have to intercept
|
||||||
private static final Class<?> PACKET_LOGIN_IN_START = Reflection.getMinecraftClass("PacketLoginInStart");
|
private static final Class<?> PACKET_LOGIN_IN_START = Reflection.getClass("{nms.network.protocol.login}.PacketLoginInStart");
|
||||||
private static final FieldAccessor<GameProfile> getGameProfile = Reflection.getField(PACKET_LOGIN_IN_START, GameProfile.class, 0);
|
private static final FieldAccessor<GameProfile> getGameProfile = Reflection.getField(PACKET_LOGIN_IN_START, GameProfile.class, 0);
|
||||||
|
|
||||||
// Speedup channel lookup
|
// Speedup channel lookup
|
||||||
private Map<String, Channel> channelLookup = new MapMaker().weakValues().makeMap();
|
private final Map<String, Channel> channelLookup = new MapMaker().weakValues().makeMap();
|
||||||
private Listener listener;
|
private final Listener listener;
|
||||||
|
|
||||||
// Channels that have already been removed
|
// Channels that have already been removed
|
||||||
private Set<Channel> uninjectedChannels = Collections.newSetFromMap(new MapMaker().weakKeys().<Channel, Boolean>makeMap());
|
private final Set<Channel> uninjectedChannels = Collections.newSetFromMap(new MapMaker().weakKeys().<Channel, Boolean>makeMap());
|
||||||
|
|
||||||
// List of network markers
|
// List of network markers
|
||||||
private Collection<Object> networkManagers;
|
private Collection<Object> networkManagers;
|
||||||
|
|
||||||
// Injected channel handlers
|
// Injected channel handlers
|
||||||
private List<Channel> serverChannels = Lists.newArrayList();
|
private final List<Channel> serverChannels = Lists.newArrayList();
|
||||||
private ChannelInboundHandlerAdapter serverChannelHandler;
|
private ChannelInboundHandlerAdapter serverChannelHandler;
|
||||||
private ChannelInitializer<Channel> beginInitProtocol;
|
private ChannelInitializer<Channel> beginInitProtocol;
|
||||||
private ChannelInitializer<Channel> endInitProtocol;
|
private ChannelInitializer<Channel> endInitProtocol;
|
||||||
|
|
||||||
// Current handler name
|
// Current handler name
|
||||||
private String handlerName;
|
private final String handlerName;
|
||||||
|
private volatile boolean closed;
|
||||||
|
private final Plugin plugin;
|
||||||
|
|
||||||
protected volatile boolean closed;
|
private PacketFilter inFilter = (player, channel, packet) -> packet;
|
||||||
protected Plugin plugin;
|
private PacketFilter outFilter = (player, channel, packet) -> packet;
|
||||||
|
|
||||||
|
public static final TinyProtocol instance = new TinyProtocol(Core.getInstance());
|
||||||
|
|
||||||
|
public static void init() {
|
||||||
|
//enforce init
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Construct a new instance of TinyProtocol, and start intercepting packets for all connected clients and future clients.
|
|
||||||
* <p>
|
|
||||||
* You can construct multiple instances per plugin.
|
|
||||||
*
|
|
||||||
* @param plugin - the plugin.
|
|
||||||
*/
|
|
||||||
public TinyProtocol(final Plugin plugin) {
|
public TinyProtocol(final Plugin plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
|
||||||
// Compute handler name
|
// Compute handler name
|
||||||
this.handlerName = getHandlerName();
|
this.handlerName = "tiny-" + plugin.getName() + "-" + ID.incrementAndGet();
|
||||||
|
|
||||||
// Prepare existing players
|
// Prepare existing players
|
||||||
registerBukkitEvents();
|
listener = new Listener() {
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
|
public void onPlayerLogin(PlayerLoginEvent e) {
|
||||||
|
if (closed)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Channel channel = getChannel(e.getPlayer());
|
||||||
|
|
||||||
|
// Don't inject players that have been explicitly uninjected
|
||||||
|
if (!uninjectedChannels.contains(channel)) {
|
||||||
|
injectPlayer(e.getPlayer());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPluginDisable(PluginDisableEvent e) {
|
||||||
|
if (e.getPlugin().equals(plugin)) {
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
plugin.getServer().getPluginManager().registerEvents(listener, plugin);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
registerChannelHandler();
|
registerChannelHandler();
|
||||||
@ -158,37 +175,6 @@ public abstract class TinyProtocol {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Register bukkit events.
|
|
||||||
*/
|
|
||||||
private void registerBukkitEvents() {
|
|
||||||
listener = new Listener() {
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
|
||||||
public final void onPlayerLogin(PlayerLoginEvent e) {
|
|
||||||
if (closed)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Channel channel = getChannel(e.getPlayer());
|
|
||||||
|
|
||||||
// Don't inject players that have been explicitly uninjected
|
|
||||||
if (!uninjectedChannels.contains(channel)) {
|
|
||||||
injectPlayer(e.getPlayer());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public final void onPluginDisable(PluginDisableEvent e) {
|
|
||||||
if (e.getPlugin().equals(plugin)) {
|
|
||||||
close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
plugin.getServer().getPluginManager().registerEvents(listener, plugin);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private void registerChannelHandler() {
|
private void registerChannelHandler() {
|
||||||
Object mcServer = getMinecraftServer.get(Bukkit.getServer());
|
Object mcServer = getMinecraftServer.get(Bukkit.getServer());
|
||||||
@ -196,7 +182,7 @@ public abstract class TinyProtocol {
|
|||||||
boolean looking = true;
|
boolean looking = true;
|
||||||
|
|
||||||
// We need to synchronize against this list
|
// We need to synchronize against this list
|
||||||
networkManagers = (Collection<Object>) getNetworkMarkers.invoke(null, serverConnection);
|
networkManagers = getNetworkMarkers.get(serverConnection);
|
||||||
createServerChannelHandler();
|
createServerChannelHandler();
|
||||||
|
|
||||||
// Find the correct list, or implicitly throw an exception
|
// Find the correct list, or implicitly throw an exception
|
||||||
@ -204,7 +190,7 @@ public abstract class TinyProtocol {
|
|||||||
List<Object> list = Reflection.getField(serverConnection.getClass(), List.class, i).get(serverConnection);
|
List<Object> list = Reflection.getField(serverConnection.getClass(), List.class, i).get(serverConnection);
|
||||||
|
|
||||||
for (Object item : list) {
|
for (Object item : list) {
|
||||||
if (!ChannelFuture.class.isInstance(item))
|
if (!(item instanceof ChannelFuture))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Channel future that contains the server connection
|
// Channel future that contains the server connection
|
||||||
@ -225,17 +211,12 @@ public abstract class TinyProtocol {
|
|||||||
final ChannelPipeline pipeline = serverChannel.pipeline();
|
final ChannelPipeline pipeline = serverChannel.pipeline();
|
||||||
|
|
||||||
// Remove channel handler
|
// Remove channel handler
|
||||||
serverChannel.eventLoop().execute(new Runnable() {
|
serverChannel.eventLoop().execute(() -> {
|
||||||
|
try {
|
||||||
@Override
|
pipeline.remove(serverChannelHandler);
|
||||||
public void run() {
|
} catch (NoSuchElementException e) {
|
||||||
try {
|
// That's fine
|
||||||
pipeline.remove(serverChannelHandler);
|
|
||||||
} catch (NoSuchElementException e) {
|
|
||||||
// That's fine
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -246,120 +227,46 @@ public abstract class TinyProtocol {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Invoked when the server is starting to send a packet to a player.
|
|
||||||
* <p>
|
|
||||||
* Note that this is not executed on the main thread.
|
|
||||||
*
|
|
||||||
* @param receiver - the receiving player, NULL for early login/status packets.
|
|
||||||
* @param channel - the channel that received the packet. Never NULL.
|
|
||||||
* @param packet - the packet being sent.
|
|
||||||
* @return The packet to send instead, or NULL to cancel the transmission.
|
|
||||||
*/
|
|
||||||
public Object onPacketOutAsync(Player receiver, Channel channel, Object packet) {
|
public Object onPacketOutAsync(Player receiver, Channel channel, Object packet) {
|
||||||
return packet;
|
return outFilter.onPacket(receiver, channel, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Invoked when the server has received a packet from a given player.
|
|
||||||
* <p>
|
|
||||||
* Use {@link Channel#remoteAddress()} to get the remote address of the client.
|
|
||||||
*
|
|
||||||
* @param sender - the player that sent the packet, NULL for early login/status packets.
|
|
||||||
* @param channel - channel that received the packet. Never NULL.
|
|
||||||
* @param packet - the packet being received.
|
|
||||||
* @return The packet to recieve instead, or NULL to cancel.
|
|
||||||
*/
|
|
||||||
public Object onPacketInAsync(Player sender, Channel channel, Object packet) {
|
public Object onPacketInAsync(Player sender, Channel channel, Object packet) {
|
||||||
return packet;
|
return inFilter.onPacket(sender, channel, packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInFilter(PacketFilter filter) {
|
||||||
|
inFilter = filter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOutFilter(PacketFilter filter) {
|
||||||
|
outFilter = filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Send a packet to a particular player.
|
|
||||||
* <p>
|
|
||||||
* Note that {@link #onPacketOutAsync(Player, Channel, Object)} will be invoked with this packet.
|
|
||||||
*
|
|
||||||
* @param player - the destination player.
|
|
||||||
* @param packet - the packet to send.
|
|
||||||
*/
|
|
||||||
public void sendPacket(Player player, Object packet) {
|
public void sendPacket(Player player, Object packet) {
|
||||||
sendPacket(getChannel(player), packet);
|
sendPacket(getChannel(player), packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Send a packet to a particular client.
|
|
||||||
* <p>
|
|
||||||
* Note that {@link #onPacketOutAsync(Player, Channel, Object)} will be invoked with this packet.
|
|
||||||
*
|
|
||||||
* @param channel - client identified by a channel.
|
|
||||||
* @param packet - the packet to send.
|
|
||||||
*/
|
|
||||||
public void sendPacket(Channel channel, Object packet) {
|
public void sendPacket(Channel channel, Object packet) {
|
||||||
channel.pipeline().writeAndFlush(packet);
|
channel.pipeline().writeAndFlush(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Pretend that a given packet has been received from a player.
|
|
||||||
* <p>
|
|
||||||
* Note that {@link #onPacketInAsync(Player, Channel, Object)} will be invoked with this packet.
|
|
||||||
*
|
|
||||||
* @param player - the player that sent the packet.
|
|
||||||
* @param packet - the packet that will be received by the server.
|
|
||||||
*/
|
|
||||||
public void receivePacket(Player player, Object packet) {
|
public void receivePacket(Player player, Object packet) {
|
||||||
receivePacket(getChannel(player), packet);
|
receivePacket(getChannel(player), packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Pretend that a given packet has been received from a given client.
|
|
||||||
* <p>
|
|
||||||
* Note that {@link #onPacketInAsync(Player, Channel, Object)} will be invoked with this packet.
|
|
||||||
*
|
|
||||||
* @param channel - client identified by a channel.
|
|
||||||
* @param packet - the packet that will be received by the server.
|
|
||||||
*/
|
|
||||||
public void receivePacket(Channel channel, Object packet) {
|
public void receivePacket(Channel channel, Object packet) {
|
||||||
channel.pipeline().context("encoder").fireChannelRead(packet);
|
channel.pipeline().context("encoder").fireChannelRead(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve the name of the channel injector, default implementation is "tiny-" + plugin name + "-" + a unique ID.
|
|
||||||
* <p>
|
|
||||||
* Note that this method will only be invoked once. It is no longer necessary to override this to support multiple instances.
|
|
||||||
*
|
|
||||||
* @return A unique channel handler name.
|
|
||||||
*/
|
|
||||||
protected String getHandlerName() {
|
|
||||||
return "tiny-" + plugin.getName() + "-" + ID.incrementAndGet();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a custom channel handler to the given player's channel pipeline, allowing us to intercept sent and received packets.
|
|
||||||
* <p>
|
|
||||||
* This will automatically be called when a player has logged in.
|
|
||||||
*
|
|
||||||
* @param player - the player to inject.
|
|
||||||
*/
|
|
||||||
public void injectPlayer(Player player) {
|
public void injectPlayer(Player player) {
|
||||||
injectChannelInternal(getChannel(player)).player = player;
|
injectChannelInternal(getChannel(player)).player = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a custom channel handler to the given channel.
|
|
||||||
*
|
|
||||||
* @param channel - the channel to inject.
|
|
||||||
* @return The intercepted channel, or NULL if it has already been injected.
|
|
||||||
*/
|
|
||||||
public void injectChannel(Channel channel) {
|
public void injectChannel(Channel channel) {
|
||||||
injectChannelInternal(channel);
|
injectChannelInternal(channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a custom channel handler to the given channel.
|
|
||||||
*
|
|
||||||
* @param channel - the channel to inject.
|
|
||||||
* @return The packet interceptor.
|
|
||||||
*/
|
|
||||||
private PacketInterceptor injectChannelInternal(Channel channel) {
|
private PacketInterceptor injectChannelInternal(Channel channel) {
|
||||||
try {
|
try {
|
||||||
PacketInterceptor interceptor = (PacketInterceptor) channel.pipeline().get(handlerName);
|
PacketInterceptor interceptor = (PacketInterceptor) channel.pipeline().get(handlerName);
|
||||||
@ -378,12 +285,6 @@ public abstract class TinyProtocol {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve the Netty channel associated with a player. This is cached.
|
|
||||||
*
|
|
||||||
* @param player - the player.
|
|
||||||
* @return The Netty channel.
|
|
||||||
*/
|
|
||||||
public Channel getChannel(Player player) {
|
public Channel getChannel(Player player) {
|
||||||
Channel channel = channelLookup.get(player.getName());
|
Channel channel = channelLookup.get(player.getName());
|
||||||
|
|
||||||
@ -398,22 +299,10 @@ public abstract class TinyProtocol {
|
|||||||
return channel;
|
return channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Uninject a specific player.
|
|
||||||
*
|
|
||||||
* @param player - the injected player.
|
|
||||||
*/
|
|
||||||
public void uninjectPlayer(Player player) {
|
public void uninjectPlayer(Player player) {
|
||||||
uninjectChannel(getChannel(player));
|
uninjectChannel(getChannel(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Uninject a specific channel.
|
|
||||||
* <p>
|
|
||||||
* This will also disable the automatic channel injection that occurs when a player has properly logged in.
|
|
||||||
*
|
|
||||||
* @param channel - the injected channel.
|
|
||||||
*/
|
|
||||||
public void uninjectChannel(final Channel channel) {
|
public void uninjectChannel(final Channel channel) {
|
||||||
// No need to guard against this if we're closing
|
// No need to guard against this if we're closing
|
||||||
if (!closed) {
|
if (!closed) {
|
||||||
@ -421,39 +310,17 @@ public abstract class TinyProtocol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// See ChannelInjector in ProtocolLib, line 590
|
// See ChannelInjector in ProtocolLib, line 590
|
||||||
channel.eventLoop().execute(new Runnable() {
|
channel.eventLoop().execute(() -> channel.pipeline().remove(handlerName));
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
channel.pipeline().remove(handlerName);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Determine if the given player has been injected by TinyProtocol.
|
|
||||||
*
|
|
||||||
* @param player - the player.
|
|
||||||
* @return TRUE if it is, FALSE otherwise.
|
|
||||||
*/
|
|
||||||
public boolean hasInjected(Player player) {
|
public boolean hasInjected(Player player) {
|
||||||
return hasInjected(getChannel(player));
|
return hasInjected(getChannel(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Determine if the given channel has been injected by TinyProtocol.
|
|
||||||
*
|
|
||||||
* @param channel - the channel.
|
|
||||||
* @return TRUE if it is, FALSE otherwise.
|
|
||||||
*/
|
|
||||||
public boolean hasInjected(Channel channel) {
|
public boolean hasInjected(Channel channel) {
|
||||||
return channel.pipeline().get(handlerName) != null;
|
return channel.pipeline().get(handlerName) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Cease listening for packets. This is called automatically when your plugin is disabled.
|
|
||||||
*/
|
|
||||||
public final void close() {
|
public final void close() {
|
||||||
if (!closed) {
|
if (!closed) {
|
||||||
closed = true;
|
closed = true;
|
||||||
@ -469,11 +336,10 @@ public abstract class TinyProtocol {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public interface PacketFilter {
|
||||||
* Channel handler that is inserted into the player's channel pipeline, allowing us to intercept sent and received packets.
|
Object onPacket(Player player, Channel channel, Object packet);
|
||||||
*
|
}
|
||||||
* @author Kristian
|
|
||||||
*/
|
|
||||||
private final class PacketInterceptor extends ChannelDuplexHandler {
|
private final class PacketInterceptor extends ChannelDuplexHandler {
|
||||||
// Updated by the login event
|
// Updated by the login event
|
||||||
public volatile Player player;
|
public volatile Player player;
|
||||||
|
@ -19,10 +19,10 @@
|
|||||||
|
|
||||||
package de.steamwar.core;
|
package de.steamwar.core;
|
||||||
|
|
||||||
|
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||||
import de.steamwar.comms.BungeeReceiver;
|
import de.steamwar.comms.BungeeReceiver;
|
||||||
import de.steamwar.core.authlib.AuthlibInjector;
|
import de.steamwar.core.authlib.AuthlibInjector;
|
||||||
import de.steamwar.core.events.ChattingEvent;
|
import de.steamwar.core.events.ChattingEvent;
|
||||||
import de.steamwar.core.events.ChunkListener;
|
|
||||||
import de.steamwar.core.events.PlayerJoinedEvent;
|
import de.steamwar.core.events.PlayerJoinedEvent;
|
||||||
import de.steamwar.core.events.WorldLoadEvent;
|
import de.steamwar.core.events.WorldLoadEvent;
|
||||||
import de.steamwar.message.Message;
|
import de.steamwar.message.Message;
|
||||||
@ -38,24 +38,31 @@ import java.util.logging.Level;
|
|||||||
|
|
||||||
public class Core extends JavaPlugin{
|
public class Core extends JavaPlugin{
|
||||||
|
|
||||||
|
private static final int VERSION;
|
||||||
|
public static final Message MESSAGE;
|
||||||
|
|
||||||
private static Core instance;
|
private static Core instance;
|
||||||
private static final int version;
|
|
||||||
public static Message MESSAGE;
|
|
||||||
|
|
||||||
static{
|
static{
|
||||||
String packageName = Bukkit.getServer().getClass().getPackage().getName();
|
String packageName = Bukkit.getServer().getClass().getPackage().getName();
|
||||||
if(packageName.contains("1_15"))
|
if(packageName.contains("1_18"))
|
||||||
version = 15;
|
VERSION = 18;
|
||||||
|
else if(packageName.contains("1_15"))
|
||||||
|
VERSION = 15;
|
||||||
else if(packageName.contains("1_14"))
|
else if(packageName.contains("1_14"))
|
||||||
version = 14;
|
VERSION = 14;
|
||||||
|
else if(packageName.contains("1_12"))
|
||||||
|
VERSION = 12;
|
||||||
else if(packageName.contains("1_10"))
|
else if(packageName.contains("1_10"))
|
||||||
version = 10;
|
VERSION = 10;
|
||||||
else if(packageName.contains("1_9"))
|
else if(packageName.contains("1_9"))
|
||||||
version = 9;
|
VERSION = 9;
|
||||||
else if(packageName.contains("1_8"))
|
else if(packageName.contains("1_8"))
|
||||||
version = 8;
|
VERSION = 8;
|
||||||
else
|
else
|
||||||
version = 12;
|
VERSION = 18;
|
||||||
|
|
||||||
|
MESSAGE = new Message("SpigotCore", Core.class.getClassLoader());
|
||||||
}
|
}
|
||||||
|
|
||||||
private ErrorHandler errorHandler;
|
private ErrorHandler errorHandler;
|
||||||
@ -74,20 +81,18 @@ public class Core extends JavaPlugin{
|
|||||||
Bukkit.getPluginManager().registerEvents(new WorldLoadEvent(), this);
|
Bukkit.getPluginManager().registerEvents(new WorldLoadEvent(), this);
|
||||||
getServer().getMessenger().registerIncomingPluginChannel(this, "sw:bridge", new BungeeReceiver());
|
getServer().getMessenger().registerIncomingPluginChannel(this, "sw:bridge", new BungeeReceiver());
|
||||||
getServer().getMessenger().registerOutgoingPluginChannel(this, "sw:bridge");
|
getServer().getMessenger().registerOutgoingPluginChannel(this, "sw:bridge");
|
||||||
ChunkListener.init();
|
|
||||||
AuthlibInjector.inject();
|
AuthlibInjector.inject();
|
||||||
|
TinyProtocol.init();
|
||||||
try {
|
try {
|
||||||
Bukkit.getLogger().log(Level.INFO, "Running on: " + new BufferedReader(new InputStreamReader(Runtime.getRuntime().exec("hostname").getInputStream())).readLine());
|
Bukkit.getLogger().log(Level.INFO, "Running on: " + new BufferedReader(new InputStreamReader(Runtime.getRuntime().exec("hostname").getInputStream())).readLine());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new SecurityException("Could not load Hostname", e);
|
throw new SecurityException("Could not load Hostname", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
MESSAGE = new Message("SpigotCore", getClassLoader());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
ChunkListener.protocol.close();
|
TinyProtocol.instance.close();
|
||||||
errorHandler.unregister();
|
errorHandler.unregister();
|
||||||
SQL.close();
|
SQL.close();
|
||||||
}
|
}
|
||||||
@ -97,7 +102,7 @@ public class Core extends JavaPlugin{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static int getVersion(){
|
public static int getVersion(){
|
||||||
return version;
|
return VERSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setInstance(Core instance) {
|
private static void setInstance(Core instance) {
|
||||||
|
@ -27,7 +27,7 @@ public class AuthlibInjector {
|
|||||||
private AuthlibInjector() {}
|
private AuthlibInjector() {}
|
||||||
|
|
||||||
public static void inject() {
|
public static void inject() {
|
||||||
Class<?> minecraftServerClass = Reflection.getClass("{nms}.MinecraftServer");
|
Class<?> minecraftServerClass = Reflection.getClass("{nms.server}.MinecraftServer");
|
||||||
Reflection.FieldAccessor<GameProfileRepository> gameProfile = Reflection.getField(minecraftServerClass, GameProfileRepository.class, 0);
|
Reflection.FieldAccessor<GameProfileRepository> gameProfile = Reflection.getField(minecraftServerClass, GameProfileRepository.class, 0);
|
||||||
Object minecraftServer = Reflection.getTypedMethod(minecraftServerClass, "getServer", minecraftServerClass).invoke(null);
|
Object minecraftServer = Reflection.getTypedMethod(minecraftServerClass, "getServer", minecraftServerClass).invoke(null);
|
||||||
gameProfile.set(minecraftServer, new SteamwarGameProfileRepository((YggdrasilGameProfileRepository) gameProfile.get(minecraftServer)));
|
gameProfile.set(minecraftServer, new SteamwarGameProfileRepository((YggdrasilGameProfileRepository) gameProfile.get(minecraftServer)));
|
||||||
|
@ -19,41 +19,14 @@
|
|||||||
|
|
||||||
package de.steamwar.core.events;
|
package de.steamwar.core.events;
|
||||||
|
|
||||||
import com.comphenix.tinyprotocol.Reflection;
|
|
||||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
|
||||||
import de.steamwar.core.Core;
|
|
||||||
import de.steamwar.core.CraftbukkitWrapper;
|
import de.steamwar.core.CraftbukkitWrapper;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
|
||||||
import io.netty.channel.Channel;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public class ChunkListener {
|
public class ChunkListener {
|
||||||
private ChunkListener(){}
|
private ChunkListener(){}
|
||||||
|
|
||||||
private static final Class<?> mapChunkPacket = Reflection.getClass("{nms}.PacketPlayOutMapChunk");
|
@Deprecated
|
||||||
private static final Reflection.FieldAccessor<Boolean> fullChunk = Reflection.getField(mapChunkPacket, boolean.class, 0);
|
|
||||||
private static final Reflection.FieldAccessor<Integer> chunkX = Reflection.getField(mapChunkPacket, int.class, 0);
|
|
||||||
private static final Reflection.FieldAccessor<Integer> chunkZ = Reflection.getField(mapChunkPacket, int.class, 1);
|
|
||||||
|
|
||||||
public static final TinyProtocol protocol = new TinyProtocol(Core.getInstance()){
|
|
||||||
@Override
|
|
||||||
public Object onPacketOutAsync(Player receiver, Channel channel, Object packet) {
|
|
||||||
if (
|
|
||||||
!mapChunkPacket.isInstance(packet) ||
|
|
||||||
!SteamwarUser.get(receiver.getUniqueId()).isBedrock() ||
|
|
||||||
fullChunk.get(packet)
|
|
||||||
)
|
|
||||||
return packet;
|
|
||||||
|
|
||||||
CraftbukkitWrapper.impl.sendChunk(receiver, chunkX.get(packet), chunkZ.get(packet));
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public static void init(){
|
|
||||||
//triggering <cinit>
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void sendChunk(Player p, int chunkX, int chunkZ) {
|
public static void sendChunk(Player p, int chunkX, int chunkZ) {
|
||||||
CraftbukkitWrapper.impl.sendChunk(p, chunkX, chunkZ);
|
CraftbukkitWrapper.impl.sendChunk(p, chunkX, chunkZ);
|
||||||
}
|
}
|
||||||
|
@ -20,9 +20,9 @@
|
|||||||
package de.steamwar.scoreboard;
|
package de.steamwar.scoreboard;
|
||||||
|
|
||||||
import com.comphenix.tinyprotocol.Reflection;
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
|
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||||
import de.steamwar.core.Core;
|
import de.steamwar.core.Core;
|
||||||
import de.steamwar.core.FlatteningWrapper;
|
import de.steamwar.core.FlatteningWrapper;
|
||||||
import de.steamwar.core.events.ChunkListener;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@ -32,14 +32,14 @@ import java.util.Map;
|
|||||||
public class SWScoreboard {
|
public class SWScoreboard {
|
||||||
private SWScoreboard() {}
|
private SWScoreboard() {}
|
||||||
|
|
||||||
public static final Class<?> scoreboardObjective = Reflection.getClass("{nms}.PacketPlayOutScoreboardObjective");
|
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<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<Integer> scoreboardAction = Reflection.getField(scoreboardObjective, int.class, 0);
|
||||||
private static final Class<?> scoreboardDisplayEnum = Reflection.getClass("{nms}.IScoreboardCriteria$EnumScoreboardHealthDisplay");
|
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(scoreboardObjective, scoreboardDisplayEnum, 0);
|
||||||
private static final Object displayTypeIntegers = scoreboardDisplayEnum.getEnumConstants()[0];
|
private static final Object displayTypeIntegers = scoreboardDisplayEnum.getEnumConstants()[0];
|
||||||
|
|
||||||
public static final Class<?> scoreboardScore = Reflection.getClass("{nms}.PacketPlayOutScoreboardScore");
|
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> 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<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<Integer> scoreValue = Reflection.getField(scoreboardScore, int.class, 0);
|
||||||
@ -52,7 +52,7 @@ public class SWScoreboard {
|
|||||||
private static final Object[] DISPLAY_SIDEBAR = new Object[2];
|
private static final Object[] DISPLAY_SIDEBAR = new Object[2];
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Class<?> scoreboardDisplayObjective = Reflection.getClass("{nms}.PacketPlayOutScoreboardDisplayObjective");
|
Class<?> scoreboardDisplayObjective = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutScoreboardDisplayObjective");
|
||||||
Reflection.FieldAccessor<String> scoreboardDisplayName = Reflection.getField(scoreboardDisplayObjective, String.class, 0);
|
Reflection.FieldAccessor<String> scoreboardDisplayName = Reflection.getField(scoreboardDisplayObjective, String.class, 0);
|
||||||
Reflection.FieldAccessor<Integer> scoreboardDisplaySlot = Reflection.getField(scoreboardDisplayObjective, int.class, 0);
|
Reflection.FieldAccessor<Integer> scoreboardDisplaySlot = Reflection.getField(scoreboardDisplayObjective, int.class, 0);
|
||||||
for(int id = 0; id < 2; id++) {
|
for(int id = 0; id < 2; id++) {
|
||||||
@ -72,16 +72,16 @@ public class SWScoreboard {
|
|||||||
Player player = scoreboard.getKey();
|
Player player = scoreboard.getKey();
|
||||||
ScoreboardCallback callback = scoreboard.getValue();
|
ScoreboardCallback callback = scoreboard.getValue();
|
||||||
|
|
||||||
ChunkListener.protocol.sendPacket(player, DELETE_SCOREBOARD[toggle]);
|
TinyProtocol.instance.sendPacket(player, DELETE_SCOREBOARD[toggle]);
|
||||||
ChunkListener.protocol.sendPacket(player, createSidebarPacket(callback.getTitle()));
|
TinyProtocol.instance.sendPacket(player, createSidebarPacket(callback.getTitle()));
|
||||||
for(Map.Entry<String, Integer> score : callback.getData().entrySet()){
|
for(Map.Entry<String, Integer> score : callback.getData().entrySet()){
|
||||||
ChunkListener.protocol.sendPacket(player, createScorePacket(score.getKey(), score.getValue()));
|
TinyProtocol.instance.sendPacket(player, createScorePacket(score.getKey(), score.getValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> {
|
||||||
if(!player.isOnline())
|
if(!player.isOnline())
|
||||||
return;
|
return;
|
||||||
ChunkListener.protocol.sendPacket(player, DISPLAY_SIDEBAR[toggle]);
|
TinyProtocol.instance.sendPacket(player, DISPLAY_SIDEBAR[toggle]);
|
||||||
}, 2);
|
}, 2);
|
||||||
}
|
}
|
||||||
}, 10, 5);
|
}, 10, 5);
|
||||||
@ -96,7 +96,7 @@ public class SWScoreboard {
|
|||||||
if(playerBoards.remove(player) == null || !player.isOnline())
|
if(playerBoards.remove(player) == null || !player.isOnline())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ChunkListener.protocol.sendPacket(player, DELETE_SCOREBOARD[toggle]);
|
TinyProtocol.instance.sendPacket(player, DELETE_SCOREBOARD[toggle]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Object createSidebarPacket(String name){
|
private static Object createSidebarPacket(String name){
|
||||||
|
130
SpigotCore_Main/src/de/steamwar/sql/Punishment.java
Normale Datei
130
SpigotCore_Main/src/de/steamwar/sql/Punishment.java
Normale Datei
@ -0,0 +1,130 @@
|
|||||||
|
/*
|
||||||
|
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.sql;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class Punishment {
|
||||||
|
|
||||||
|
private static final SQL.Statement getPunishment = new SQL.Statement("SELECT * FROM Punishments WHERE UserId = ? AND Type = ? ORDER BY PunishmentId DESC LIMIT 1");
|
||||||
|
private static final SQL.Statement getPunishments = new SQL.Statement("SELECT * FROM Punishments WHERE PunishmentId IN (SELECT MAX(PunishmentId) FROM Punishments WHERE UserId = ? GROUP BY Type)");
|
||||||
|
|
||||||
|
public static Punishment getPunishmentOfPlayer(int user, PunishmentType type) {
|
||||||
|
return getPunishment.select(rs -> {
|
||||||
|
if (rs.next())
|
||||||
|
return new Punishment(rs);
|
||||||
|
return null;
|
||||||
|
}, user, type.name());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<PunishmentType, Punishment> getPunishmentsOfPlayer(int user) {
|
||||||
|
return getPunishments.select(rs -> {
|
||||||
|
Map<PunishmentType, Punishment> punishments = new HashMap<>();
|
||||||
|
while (rs.next())
|
||||||
|
punishments.put(PunishmentType.valueOf(rs.getString("Type")), new Punishment(rs));
|
||||||
|
return punishments;
|
||||||
|
}, user);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Timestamp startTime;
|
||||||
|
private Timestamp endTime;
|
||||||
|
private final PunishmentType type;
|
||||||
|
private final int user;
|
||||||
|
private final int id;
|
||||||
|
private String reason;
|
||||||
|
private final int punisher;
|
||||||
|
private boolean perma;
|
||||||
|
|
||||||
|
private Punishment(ResultSet set) throws SQLException {
|
||||||
|
user = set.getInt("UserId");
|
||||||
|
reason = set.getString("Reason");
|
||||||
|
type = PunishmentType.valueOf(set.getString("Type"));
|
||||||
|
startTime = set.getTimestamp("StartTime");
|
||||||
|
endTime = set.getTimestamp("EndTime");
|
||||||
|
punisher = set.getInt("Punisher");
|
||||||
|
perma = set.getBoolean("Perma");
|
||||||
|
id = set.getInt("PunishmentId");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Timestamp getStartTime() {
|
||||||
|
return startTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Timestamp getEndTime() {
|
||||||
|
return endTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PunishmentType getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getReason() {
|
||||||
|
return reason;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPunisher() {
|
||||||
|
return punisher;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPerma() {
|
||||||
|
return perma;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBantime(Timestamp endTime, boolean perma) {
|
||||||
|
if (perma) {
|
||||||
|
return "permanent";
|
||||||
|
} else {
|
||||||
|
return endTime.toLocalDateTime().format(DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCurrent() {
|
||||||
|
return isPerma() || getEndTime().after(new Date());
|
||||||
|
}
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Getter
|
||||||
|
public enum PunishmentType {
|
||||||
|
Ban(false, "BAN_TEAM", "BAN_PERMA", "BAN_UNTIL", "UNBAN_ERROR", "UNBAN"),
|
||||||
|
Mute( false, "MUTE_TEAM", "MUTE_PERMA", "MUTE_UNTIL", "UNMUTE_ERROR", "UNMUTE"),
|
||||||
|
NoSchemReceiving(false, "NOSCHEMRECEIVING_TEAM", "NOSCHEMRECEIVING_PERMA", "NOSCHEMRECEIVING_UNTIL", "UNNOSCHEMRECEIVING_ERROR", "UNNOSCHEMRECEIVING"),
|
||||||
|
NoSchemSharing(false, "NOSCHEMSHARING_TEAM", "NOSCHEMSHARING_PERMA", "NOSCHEMSHARING_UNTIL", "UNNOSCHEMSHARING_ERROR", "UNNOSCHEMSHARING"),
|
||||||
|
NoSchemSubmitting(true, "NOSCHEMSUBMITTING_TEAM", "NOSCHEMSUBMITTING_PERMA", "NOSCHEMSUBMITTING_UNTIL", "UNNOSCHEMSUBMITTING_ERROR", "UNNOSCHEMSUBMITTING"),
|
||||||
|
NoDevServer(true, "NODEVSERVER_TEAM", "NODEVSERVER_PERMA", "NODEVSERVER_UNTIL", "UNNODEVSERVER_ERROR", "UNNODEVSERVER");
|
||||||
|
|
||||||
|
private final boolean needsAdmin;
|
||||||
|
private final String teamMessage;
|
||||||
|
private final String playerMessagePerma;
|
||||||
|
private final String playerMessageUntil;
|
||||||
|
private final String usageNotPunished;
|
||||||
|
private final String unpunishmentMessage;
|
||||||
|
}
|
||||||
|
}
|
@ -7,4 +7,5 @@ softdepend:
|
|||||||
- WorldEdit
|
- WorldEdit
|
||||||
|
|
||||||
main: de.steamwar.core.Core
|
main: de.steamwar.core.Core
|
||||||
commands:
|
libraries:
|
||||||
|
- mysql:mysql-connector-java:5.1.49
|
@ -74,6 +74,14 @@ allprojects {
|
|||||||
maven {
|
maven {
|
||||||
url = uri("https://repo.codemc.io/repository/maven-snapshots/")
|
url = uri("https://repo.codemc.io/repository/maven-snapshots/")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
maven {
|
||||||
|
url = uri('https://hub.spigotmc.org/nexus/content/repositories/snapshots/')
|
||||||
|
}
|
||||||
|
|
||||||
|
maven {
|
||||||
|
url = uri('https://libraries.minecraft.net')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,6 +93,7 @@ dependencies {
|
|||||||
implementation project(":SpigotCore_12")
|
implementation project(":SpigotCore_12")
|
||||||
implementation project(":SpigotCore_14")
|
implementation project(":SpigotCore_14")
|
||||||
implementation project(":SpigotCore_15")
|
implementation project(":SpigotCore_15")
|
||||||
|
implementation project(":SpigotCore_18")
|
||||||
}
|
}
|
||||||
|
|
||||||
task buildProject {
|
task buildProject {
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
rootProject.name = 'SpigotCore'
|
rootProject.name = 'SpigotCore'
|
||||||
|
|
||||||
include 'SpigotCore_Main'
|
include 'SpigotCore_Main'
|
||||||
|
include 'SpigotCore_18'
|
||||||
include 'SpigotCore_15'
|
include 'SpigotCore_15'
|
||||||
include 'SpigotCore_14'
|
include 'SpigotCore_14'
|
||||||
include 'SpigotCore_12'
|
include 'SpigotCore_12'
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren