From 6e73dff5f7d7d353abfd54a01b628167df746346 Mon Sep 17 00:00:00 2001 From: MoBrot <90271578+MoBrot@users.noreply.github.com> Date: Thu, 20 Apr 2023 19:11:04 +0200 Subject: [PATCH 1/3] Modify Toggle --- .../steamwar/lobby/command/ModifyCommand.java | 21 ++++++++++++++----- .../steamwar/lobby/listener/PlayerSpawn.java | 3 ++- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/de/steamwar/lobby/command/ModifyCommand.java b/src/de/steamwar/lobby/command/ModifyCommand.java index cbd917c..fb5a5e0 100644 --- a/src/de/steamwar/lobby/command/ModifyCommand.java +++ b/src/de/steamwar/lobby/command/ModifyCommand.java @@ -21,6 +21,7 @@ package de.steamwar.lobby.command; import de.steamwar.command.SWCommand; import de.steamwar.lobby.LobbySystem; +import de.steamwar.lobby.listener.PlayerSpawn; import de.steamwar.sql.SteamwarUser; import org.bukkit.Bukkit; import org.bukkit.GameMode; @@ -52,15 +53,25 @@ public class ModifyCommand extends SWCommand implements Listener { if(!user.getUserGroup().isTeamGroup() && !user.getUserName().equals("joschi1")) return; - modifying.add(player); - LobbySystem.getEntityServer(true).addPlayer(player); - player.setGameMode(GameMode.CREATIVE); - player.setOp(true); + if(modifying(player)) { + modifying.remove(player); + player.setGameMode(GameMode.ADVENTURE); + player.setOp(false); + PlayerSpawn.giveItems(player); + }else { + modifying.add(player); + LobbySystem.getEntityServer(true).addPlayer(player); + player.setGameMode(GameMode.CREATIVE); + player.setOp(true); + } } @EventHandler public void onLeave(PlayerQuitEvent event) { - modifying.remove(event.getPlayer()); + Player player = event.getPlayer(); + + modifying.remove(player); + player.setOp(false); } @Register("waitinghallspawn") diff --git a/src/de/steamwar/lobby/listener/PlayerSpawn.java b/src/de/steamwar/lobby/listener/PlayerSpawn.java index 9a38417..e732668 100644 --- a/src/de/steamwar/lobby/listener/PlayerSpawn.java +++ b/src/de/steamwar/lobby/listener/PlayerSpawn.java @@ -50,7 +50,6 @@ public class PlayerSpawn extends BasicListener { public void onJoin(PlayerJoinEvent e) { Player player = e.getPlayer(); e.setJoinMessage(null); - player.getInventory().clear(); player.setGameMode(GameMode.ADVENTURE); player.setWalkSpeed(0.5f); @@ -68,6 +67,8 @@ public class PlayerSpawn extends BasicListener { public static void giveItems(Player player) { PlayerInventory inventory = player.getInventory(); + inventory.clear(); + inventory.setItem(EquipmentSlot.CHEST, ELYTRA); player.getInventory().setItem(FIREWORK_SLOT, FIREWORK); From 170aa09c683cf4816102d9179f81131c4d9fdf90 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 21 May 2023 20:58:01 +0200 Subject: [PATCH 2/3] Add Gradle Plugin --- build.gradle | 189 +----------------------------------------------- settings.gradle | 9 +++ 2 files changed, 10 insertions(+), 188 deletions(-) diff --git a/build.gradle b/build.gradle index f6c9e63..8ccd593 100644 --- a/build.gradle +++ b/build.gradle @@ -25,18 +25,7 @@ plugins { id 'application' id 'com.github.johnrengelman.shadow' version '5.0.0' -} - -ext.swdep = { s -> - if (file("${rootDir}/lib/${s}.jar").exists()) { - return files("${rootDir}/lib/${s}.jar") - } else { - if (s.contains("-")) { - return "de.steamwar:${s.toLowerCase().replace('-', ':')}" - } else { - return "de.steamwar:${s.toLowerCase()}:RELEASE" - } - } + id 'de.steamwar.gradle' version 'RELEASE' } group 'de.steamwar' @@ -44,26 +33,6 @@ version '' mainClassName = '' -Properties steamwarProperties = new Properties() -if (file("steamwar.properties").exists()) { - steamwarProperties.load(file("steamwar.properties").newDataInputStream()) -} - -ext { - buildName = 'LobbySystem2.0' - artifactName = 'lobbysystem2.0' - - uberJarName = "${buildName}-all.jar" - jarName = "${artifactName}.jar" - libs = "${buildDir}/libs" - - if (Os.isFamily(Os.FAMILY_WINDOWS)) { - operatingSystem = "windows" - } else { - operatingSystem = "unix" - } -} - compileJava.options.encoding = 'UTF-8' sourceCompatibility = 1.8 @@ -87,14 +56,6 @@ repositories { maven { url = uri('https://hub.spigotmc.org/nexus/content/repositories/snapshots/') } - - maven { - url = uri('https://steamwar.de/maven/') - credentials { - username = steamwarProperties.getProperty("maven.username") - password = steamwarProperties.getProperty("maven.password") - } - } } dependencies { @@ -108,152 +69,4 @@ dependencies { testCompileOnly 'org.projectlombok:lombok:1.18.22' annotationProcessor 'org.projectlombok:lombok:1.18.22' testAnnotationProcessor 'org.projectlombok:lombok:1.18.22' -} - -task buildProject { - description 'Build this project' - group "Steamwar" - - dependsOn build -} - -task finalizeProject { - description 'Finalize this project' - group "Steamwar" - - doLast { - if ("${buildDir}" == null) { - return - } - delete fileTree("${libs}").matching { - exclude("${uberJarName}") - } - file(libs + "/" + uberJarName).renameTo(file(libs + "/" + jarName)) - } -} -build.finalizedBy(finalizeProject) - -if (steamwarProperties.containsKey("hostname")) { - String hostname = steamwarProperties.get("hostname") - String uploadPath = steamwarProperties.getOrDefault("uploadPath", "~") - - String server = steamwarProperties.getOrDefault("server", "Dev1.15") - String serverStartFlags = steamwarProperties.getOrDefault("serverStartFlags", "") - - task uploadProject { - description 'Upload this project' - group "Steamwar" - - doLast { - await(shell("scp ${libs}/${jarName} ${hostname}:${uploadPath}/${server}/plugins")) - if (steamwarProperties.getOrDefault("directStart", "false") == "false" && !answer("Start ${server} server?")) { - return - } - serverStart(server, serverStartFlags, hostname) - } - } - uploadProject.dependsOn(buildProject) - - task startDevServer { - description 'Start the DevServer' - group "Steamwar" - - doLast { - serverStart(server, serverStartFlags, hostname) - } - } -} - -private def await(Process proc) { - def out = new StringBuilder() - def err = new StringBuilder() - proc.waitForProcessOutput(out, err) - return [out, err, proc.exitValue()] -} - -private def shell(String command) { - if (operatingSystem == "unix") { - return ['bash', '-c', command].execute() - } else { - return ["cmd", "/c", command].execute() - } -} - -private def serverStart(String serverName, String serverFlags, String hostname) { - def proc = shell("ssh -t ${hostname} \"./mc ${serverFlags} ${serverName}\"") - - Set strings = new HashSet<>() - File file = new File("${projectDir}/ignoredlog"); - if (file.exists()) { - new BufferedReader(new InputStreamReader(new FileInputStream(file))).readLines().forEach({ s -> - strings.add(s) - }) - } - - Thread outputThread = new Thread({ - Reader reader = proc.getInputStream().newReader(); - Writer writer = System.out.newWriter(); - try { - while (proc.alive) { - String s = reader.readLine() - if (s == null) { - return - } - if (strings.stream().anyMatch({check -> s.contains(check)})) { - continue - } - writer.write(s + "\n") - writer.flush() - } - } catch (IOException e) { - // Ignored - } - }) - outputThread.setName("${serverName} - OutputThread") - outputThread.start() - - Writer writer - Thread inputThread = new Thread({ - Reader reader = System.in.newReader() - writer = proc.getOutputStream().newWriter() - try { - while (proc.alive) { - String s = reader.readLine() - writer.write(s + "\n") - writer.flush() - } - } catch (IOException e) { - // Ignored - } - }) - inputThread.setName("${serverName} - InputThread") - inputThread.start() - - gradle.buildFinished { buildResult -> - if (!proc.alive) { - return - } - writer = proc.getOutputStream().newWriter() - writer.write("stop\n") - writer.flush() - awaitClose(proc, outputThread, inputThread) - } - awaitClose(proc, outputThread, inputThread) -}; - -private static def awaitClose(Process proc, Thread outputThread, Thread inputThread) { - while (proc.alive) { - Thread.sleep(10) - } - proc.closeStreams() - outputThread.interrupt() - inputThread.interrupt() -} - -private def answer(String question) { - while (System.in.available() > 0) System.in.read() - println(question) - boolean valid = "Yy".contains(((char) System.in.read()).toString()) - while (System.in.available() > 0) System.in.read() - return valid } \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 823766a..6b37444 100644 --- a/settings.gradle +++ b/settings.gradle @@ -17,4 +17,13 @@ * along with this program. If not, see . */ +pluginManagement { + repositories { + gradlePluginPortal() + maven { + url = uri("https://steamwar.de/maven/") + } + } +} + rootProject.name = 'LobbySystem2.0' From 40357f917b0053b8e8be9be74f11e41d06355274 Mon Sep 17 00:00:00 2001 From: MoBrot <90271578+MoBrot@users.noreply.github.com> Date: Mon, 29 May 2023 22:36:36 +0200 Subject: [PATCH 3/3] Modify Toggle --- src/de/steamwar/lobby/command/ModifyCommand.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/de/steamwar/lobby/command/ModifyCommand.java b/src/de/steamwar/lobby/command/ModifyCommand.java index fb5a5e0..f27d07f 100644 --- a/src/de/steamwar/lobby/command/ModifyCommand.java +++ b/src/de/steamwar/lobby/command/ModifyCommand.java @@ -55,6 +55,7 @@ public class ModifyCommand extends SWCommand implements Listener { if(modifying(player)) { modifying.remove(player); + LobbySystem.getEntityServer(true).removePlayer(player); player.setGameMode(GameMode.ADVENTURE); player.setOp(false); PlayerSpawn.giveItems(player);