From e59ddd4e3beedcd93c024dd5ca288d94733b3185 Mon Sep 17 00:00:00 2001 From: MCMDEV Date: Mon, 5 Jun 2023 18:44:39 +0200 Subject: [PATCH] Fix velocity config Remove bukkit module --- hostprofiles-bukkit/pom.xml | 89 --------------- .../bukkit/BukkitHostprofilesPlugin.java | 67 ----------- .../bukkit/config/BukkitConfiguration.java | 38 ------- .../bukkit/listener/BukkitListener.java | 106 ------------------ .../src/main/resources/plugin.yml | 5 - hostprofiles-common/pom.xml | 2 +- hostprofiles-paper/pom.xml | 4 +- .../src/main/resources/plugin.yml | 2 +- hostprofiles-velocity/pom.xml | 4 +- .../velocity/VelocityHostprofilesPlugin.java | 3 +- pom.xml | 3 +- 11 files changed, 9 insertions(+), 314 deletions(-) delete mode 100644 hostprofiles-bukkit/pom.xml delete mode 100644 hostprofiles-bukkit/src/main/java/de/mcmdev/hostprofiles/bukkit/BukkitHostprofilesPlugin.java delete mode 100644 hostprofiles-bukkit/src/main/java/de/mcmdev/hostprofiles/bukkit/config/BukkitConfiguration.java delete mode 100644 hostprofiles-bukkit/src/main/java/de/mcmdev/hostprofiles/bukkit/listener/BukkitListener.java delete mode 100644 hostprofiles-bukkit/src/main/resources/plugin.yml diff --git a/hostprofiles-bukkit/pom.xml b/hostprofiles-bukkit/pom.xml deleted file mode 100644 index 7d40d68..0000000 --- a/hostprofiles-bukkit/pom.xml +++ /dev/null @@ -1,89 +0,0 @@ - - - - hostprofiles - de.mcmdev - 0.1.2 - - 4.0.0 - - hostprofiles-bukkit - - - 17 - 17 - - - - - de.mcmdev - hostprofiles-common - 0.1.2 - - - org.spigotmc - spigot - 1.18.2-R0.1-SNAPSHOT - remapped-mojang - provided - - - - - - - net.md-5 - specialsource-maven-plugin - 1.2.2 - - - package - - remap - - remap-obf - - org.spigotmc:minecraft-server:1.18.1-R0.1-SNAPSHOT:txt:maps-mojang - true - org.spigotmc:spigot:1.18.1-R0.1-SNAPSHOT:jar:remapped-mojang - - true - remapped-obf - - - - package - - remap - - remap-spigot - - - ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar - - org.spigotmc:minecraft-server:1.18.1-R0.1-SNAPSHOT:csrg:maps-spigot - org.spigotmc:spigot:1.18.1-R0.1-SNAPSHOT:jar:remapped-obf - - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.2.4 - - - package - - shade - - - - - - - - \ No newline at end of file diff --git a/hostprofiles-bukkit/src/main/java/de/mcmdev/hostprofiles/bukkit/BukkitHostprofilesPlugin.java b/hostprofiles-bukkit/src/main/java/de/mcmdev/hostprofiles/bukkit/BukkitHostprofilesPlugin.java deleted file mode 100644 index 90e4d8b..0000000 --- a/hostprofiles-bukkit/src/main/java/de/mcmdev/hostprofiles/bukkit/BukkitHostprofilesPlugin.java +++ /dev/null @@ -1,67 +0,0 @@ -package de.mcmdev.hostprofiles.bukkit; - -import de.mcmdev.hostprofiles.bukkit.config.BukkitConfiguration; -import de.mcmdev.hostprofiles.bukkit.listener.BukkitListener; -import de.mcmdev.hostprofiles.common.HostprofilesPlatform; -import de.mcmdev.hostprofiles.common.HostprofilesPlugin; -import de.mcmdev.hostprofiles.common.config.Configuration; -import de.mcmdev.hostprofiles.common.connection.ConnectionHandler; -import org.bukkit.Bukkit; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.event.HandlerList; -import org.bukkit.plugin.java.JavaPlugin; - -import java.io.File; - -public class BukkitHostprofilesPlugin extends JavaPlugin implements HostprofilesPlugin { - - private HostprofilesPlatform platform; - - @Override - public void onEnable() { - this.platform = new HostprofilesPlatform(this); - this.platform.enable(); - } - - @Override - public void onDisable() { - this.platform.disable(); - this.platform = null; - } - - @Override - public HostprofilesPlatform getPlatform() { - return this.platform; - } - - @Override - public Configuration loadFile(String name) { - File file = new File(getDataFolder(), name); - if (!file.getParentFile().exists()) { - file.getParentFile().mkdirs(); - } - if (!file.exists()) { - saveResource(name, false); - } - - YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(file); - return new BukkitConfiguration(yamlConfiguration); - } - - @Override - public void listen(ConnectionHandler connectionHandler) { - Bukkit.getPluginManager().registerEvents(new BukkitListener(connectionHandler), this); - } - - @Override - public void unlisten(ConnectionHandler connectionHandler) { - HandlerList.unregisterAll(this); - } - - @Override - public void disableSelf() { - Bukkit.getPluginManager().disablePlugin(this); - } - - -} diff --git a/hostprofiles-bukkit/src/main/java/de/mcmdev/hostprofiles/bukkit/config/BukkitConfiguration.java b/hostprofiles-bukkit/src/main/java/de/mcmdev/hostprofiles/bukkit/config/BukkitConfiguration.java deleted file mode 100644 index b7ecc2f..0000000 --- a/hostprofiles-bukkit/src/main/java/de/mcmdev/hostprofiles/bukkit/config/BukkitConfiguration.java +++ /dev/null @@ -1,38 +0,0 @@ -package de.mcmdev.hostprofiles.bukkit.config; - -import de.mcmdev.hostprofiles.common.config.Configuration; -import lombok.RequiredArgsConstructor; -import org.bukkit.configuration.ConfigurationSection; - -import java.util.Set; -import java.util.stream.Collectors; - -@RequiredArgsConstructor -public class BukkitConfiguration implements Configuration { - - private final ConfigurationSection handle; - - @Override - public String getName() { - return handle.getName(); - } - - @Override - public Set getKeys(String key) { - ConfigurationSection section = handle.getConfigurationSection(key); - return section.getKeys(false) - .stream() - .map(s -> new BukkitConfiguration(section.getConfigurationSection(s))) - .collect(Collectors.toSet()); - } - - @Override - public String tryString(String key) { - return handle.getString(key); - } - - @Override - public boolean getBoolean(String key) { - return handle.getBoolean(key); - } -} diff --git a/hostprofiles-bukkit/src/main/java/de/mcmdev/hostprofiles/bukkit/listener/BukkitListener.java b/hostprofiles-bukkit/src/main/java/de/mcmdev/hostprofiles/bukkit/listener/BukkitListener.java deleted file mode 100644 index 3a4c4d3..0000000 --- a/hostprofiles-bukkit/src/main/java/de/mcmdev/hostprofiles/bukkit/listener/BukkitListener.java +++ /dev/null @@ -1,106 +0,0 @@ -package de.mcmdev.hostprofiles.bukkit.listener; - -import com.mojang.authlib.GameProfile; -import com.mojang.authlib.properties.Property; -import de.mcmdev.hostprofiles.common.connection.ConnectionEvent; -import de.mcmdev.hostprofiles.common.connection.ConnectionHandler; -import lombok.RequiredArgsConstructor; -import net.minecraft.network.Connection; -import net.minecraft.server.network.ServerLoginPacketListenerImpl; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_18_R2.CraftServer; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.AsyncPlayerPreLoginEvent; - -import java.lang.reflect.Field; - -@RequiredArgsConstructor -public class BukkitListener implements Listener { - - private static Field GAME_PROFILE_FIELD = null; - - static { - for (Field field : ServerLoginPacketListenerImpl.class.getDeclaredFields()) { - if (field.getType().equals(GameProfile.class)) { - GAME_PROFILE_FIELD = field; - break; - } - } - GAME_PROFILE_FIELD.setAccessible(true); - } - - private final ConnectionHandler connectionHandler; - - @EventHandler - private void onAsyncLogin(AsyncPlayerPreLoginEvent event) { - GameProfile gameProfile = null; - ServerLoginPacketListenerImpl packetListener = null; - int tries = 0; - while (tries < 5) { - try { - for (Connection connection : ((CraftServer) Bukkit.getServer()).getHandle().getServer().getConnection().getConnections()) { - if (connection.getPacketListener() instanceof ServerLoginPacketListenerImpl) { - packetListener = (ServerLoginPacketListenerImpl) connection.getPacketListener(); - gameProfile = (GameProfile) GAME_PROFILE_FIELD.get(packetListener); - if (gameProfile.getId().equals(event.getUniqueId())) { - break; - } - } - } - Thread.sleep(20); - } catch (InterruptedException | IllegalAccessException e) { - e.printStackTrace(); - return; - } - tries++; - } - - String hostname = packetListener.hostname.split(":")[0]; - - ConnectionEvent connectionEvent = fromBukkit(hostname, event); - boolean changes = connectionHandler.handleLogin(connectionEvent); - if (!changes) { - return; - } - - if (connectionEvent.isDisallowed()) { - event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_WHITELIST); - event.setKickMessage(connectionEvent.getKickMessage()); - return; - } - - GameProfile newGameProfile = new GameProfile(connectionEvent.getUuid(), connectionEvent.getName()); - if (connectionEvent.isSkinCopy()) { - if (gameProfile != null) { - gameProfile.getProperties().forEach((s, property) -> { - newGameProfile.getProperties().put(s, property); - }); - } - } else { - if (connectionEvent.getSkinValue() != null) { - Property property; - if (connectionEvent.getSkinSignature() != null) { - property = new Property("textures", connectionEvent.getSkinValue(), connectionEvent.getSkinSignature()); - } else { - property = new Property("textures", connectionEvent.getSkinValue()); - } - newGameProfile.getProperties().put("textures", property); - } - } - try { - GAME_PROFILE_FIELD.set(packetListener, newGameProfile); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - } - - private ConnectionEvent fromBukkit(String hostname, AsyncPlayerPreLoginEvent bukkitEvent) { - return new ConnectionEvent( - hostname, - bukkitEvent.getUniqueId(), - bukkitEvent.getName() - ); - } - -} diff --git a/hostprofiles-bukkit/src/main/resources/plugin.yml b/hostprofiles-bukkit/src/main/resources/plugin.yml deleted file mode 100644 index 24d0e80..0000000 --- a/hostprofiles-bukkit/src/main/resources/plugin.yml +++ /dev/null @@ -1,5 +0,0 @@ -name: hostprofiles -version: 0.1.2 -author: MCMDEV -description: Define hosts to which players can connect to have a different profile. -main: de.mcmdev.hostprofiles.bukkit.BukkitHostprofilesPlugin \ No newline at end of file diff --git a/hostprofiles-common/pom.xml b/hostprofiles-common/pom.xml index 0884f15..4292617 100644 --- a/hostprofiles-common/pom.xml +++ b/hostprofiles-common/pom.xml @@ -5,7 +5,7 @@ hostprofiles de.mcmdev - 0.1.2 + 0.1.3-SNAPSHOT 4.0.0 diff --git a/hostprofiles-paper/pom.xml b/hostprofiles-paper/pom.xml index 003d5ce..f4ac977 100644 --- a/hostprofiles-paper/pom.xml +++ b/hostprofiles-paper/pom.xml @@ -5,7 +5,7 @@ hostprofiles de.mcmdev - 0.1.2 + 0.1.3-SNAPSHOT 4.0.0 @@ -27,7 +27,7 @@ de.mcmdev hostprofiles-common - 0.1.2 + 0.1.3-SNAPSHOT io.papermc.paper diff --git a/hostprofiles-paper/src/main/resources/plugin.yml b/hostprofiles-paper/src/main/resources/plugin.yml index 99dfced..3bc379a 100644 --- a/hostprofiles-paper/src/main/resources/plugin.yml +++ b/hostprofiles-paper/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: hostprofiles -version: 0.1.2 +version: 0.1.3 author: MCMDEV description: Define hosts to which players can connect to have a different profile. main: de.mcmdev.hostprofiles.paper.PaperHostprofilesPlugin \ No newline at end of file diff --git a/hostprofiles-velocity/pom.xml b/hostprofiles-velocity/pom.xml index df54d39..2ebf1f0 100644 --- a/hostprofiles-velocity/pom.xml +++ b/hostprofiles-velocity/pom.xml @@ -5,7 +5,7 @@ hostprofiles de.mcmdev - 0.1.2 + 0.1.3-SNAPSHOT 4.0.0 @@ -27,7 +27,7 @@ de.mcmdev hostprofiles-common - 0.1.2 + 0.1.3-SNAPSHOT org.spongepowered diff --git a/hostprofiles-velocity/src/main/java/de/mcmdev/hostprofiles/velocity/VelocityHostprofilesPlugin.java b/hostprofiles-velocity/src/main/java/de/mcmdev/hostprofiles/velocity/VelocityHostprofilesPlugin.java index d2fe695..b4405e0 100644 --- a/hostprofiles-velocity/src/main/java/de/mcmdev/hostprofiles/velocity/VelocityHostprofilesPlugin.java +++ b/hostprofiles-velocity/src/main/java/de/mcmdev/hostprofiles/velocity/VelocityHostprofilesPlugin.java @@ -25,7 +25,7 @@ @Plugin( id = "hostprofiles", - version = "0.1.2", + version = "0.1.3", description = "Define hosts to which players can connect to have a different profile.", url = "https://github.com/MCMDEV/hostprofiles", authors = "MCMDEV" @@ -67,6 +67,7 @@ public Configuration loadFile(String name) { if (!Files.exists(path)) { try { InputStream resourceAsStream = getClass().getResourceAsStream("/" + name); + Files.createDirectories(path.getParent()); Files.copy(resourceAsStream, path); } catch (IOException e) { e.printStackTrace(); diff --git a/pom.xml b/pom.xml index 9938c52..fb18b1e 100644 --- a/pom.xml +++ b/pom.xml @@ -7,10 +7,9 @@ de.mcmdev hostprofiles pom - 0.1.2 + 0.1.3-SNAPSHOT hostprofiles-common - hostprofiles-bukkit hostprofiles-paper hostprofiles-velocity