Compare commits
160
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
397b10c319 | ||
|
|
32569f19d9 | ||
|
|
f19e4158e7 | ||
|
|
6c46b5b2a2 | ||
|
|
58516448d9 | ||
|
|
683236bb59 | ||
|
|
8dc101639d | ||
|
|
792620804a | ||
|
|
4aa7c99a6e | ||
|
|
cce18124f2 | ||
|
|
18ad0ad90c | ||
|
|
a58de898bb | ||
|
|
507b7c2569 | ||
|
|
a18098b8f4 | ||
|
|
97773f292d | ||
|
|
5fdfc03587 | ||
|
|
493e66cc98 | ||
|
|
2be3a136ae | ||
|
|
c62a566447 | ||
|
|
0684765a76 | ||
|
|
c40f29c3c1 | ||
|
|
72dc4eee9e | ||
|
|
c7a949322e | ||
|
|
9d5b7893f1 | ||
|
|
ae898e14c2 | ||
|
|
726f73cc45 | ||
|
|
badff1c70f | ||
|
|
1d2ac4f705 | ||
|
|
b48c75ef74 | ||
|
|
8b6ea12a08 | ||
|
|
801678ddd3 | ||
|
|
e5cc874834 | ||
|
|
95119fc93f | ||
|
|
d84ca3547a | ||
|
|
25ab79abc0 | ||
|
|
582d6a62e3 | ||
|
|
5eec792aff
|
||
|
|
e0f26c3e8d
|
||
|
|
a59e9b4343 | ||
|
|
64e627514d | ||
|
|
a8c68864d8 | ||
|
|
c0668723d7 | ||
|
|
5bc2daf37a | ||
|
|
e6d39da36b | ||
|
|
390d388692 | ||
|
|
9a60ac228c | ||
|
|
dab443b989 | ||
|
|
bf3c65c630 | ||
|
|
b488c4ed7c | ||
|
|
2e795aaf8e | ||
|
|
7a601235f5 | ||
|
|
3a247de43d
|
||
|
|
62e855ec1b
|
||
|
|
9e7311934f | ||
|
|
6fd3e6f690
|
||
|
|
7acd51fd61
|
||
|
|
b278ca15f3
|
||
|
|
029249c2b0
|
||
|
|
1ceb10439b
|
||
|
|
a5dfe6ab7e
|
||
|
|
c8a5f567eb | ||
|
|
47fb4da85b
|
||
|
|
0eef22aab0 | ||
|
|
013d18614f | ||
|
|
c7c1ab64e0 | ||
|
|
b68a27fbb6 | ||
|
|
7038dc2aa5
|
||
|
|
7af586ec16
|
||
|
|
b04e99ce54 | ||
|
|
524702fbb9 | ||
|
|
e07298e748 | ||
|
|
e1df793e9f | ||
|
|
806a1affea | ||
|
|
c538cdbbd2 | ||
|
|
d7ba19049a | ||
|
|
47909b6f07 | ||
|
|
48846a698f | ||
|
|
b771c95b99 | ||
|
|
d0aada2b00 | ||
|
|
6522fc77f2 | ||
|
|
27e01a56ae | ||
|
|
ed89770c0f | ||
|
|
3ec3c90f04 | ||
|
|
73d4ed26c8 | ||
|
|
256bcfb1bf | ||
|
|
28ce288815 | ||
|
|
6599dd026a | ||
|
|
03052b677f | ||
|
|
f76a6fa79d | ||
|
|
7fb7f46ca7 | ||
|
|
1269b7f00a | ||
|
|
91a0685724 | ||
|
|
72dd2ef59a | ||
|
|
54a1549973 | ||
|
|
fd5f5b92b4 | ||
|
|
60dc5e4442 | ||
|
|
4cdaf759af | ||
|
|
6e919d9148 | ||
|
|
a20ec8c93d | ||
|
|
18b65a2984 | ||
|
|
669235709e | ||
|
|
796e154c1c | ||
|
|
9efe35fe0d | ||
|
|
e0aaacd66a | ||
|
|
7adb1e8b4a | ||
|
|
b88e592e79 | ||
|
|
914134600e | ||
|
|
27877938bc
|
||
|
|
701964c2f2 | ||
|
|
70c8678c60
|
||
|
|
6cbfc94e6d | ||
|
|
c0ff123279 | ||
|
|
5511a1f08e | ||
|
|
8c8da355bb | ||
|
|
7326ed4aa0 | ||
|
|
2d59eb81c7 | ||
|
|
711920464a | ||
|
|
117dbd08ae | ||
|
|
b36464e69e | ||
|
|
f5ac006c0c | ||
|
|
414bfbfe3c | ||
|
|
c362a3e1f0 | ||
|
|
2b43af8851 | ||
|
|
1590f8f0ee | ||
|
|
932732737d | ||
|
|
2bc164c1b0 | ||
|
|
aa66b3dc83 | ||
|
|
f5d9c6e175 | ||
|
|
36b31fac77 | ||
|
|
641cefad01 | ||
|
|
eb866125ea | ||
|
|
961331f029 | ||
|
|
786257ad0e | ||
|
|
997292d58e | ||
|
|
8050f51424
|
||
|
|
e176b3bca8 | ||
|
|
a6681ffaf6
|
||
|
|
a23530074c
|
||
|
|
e88a4c624b
|
||
|
|
105beaf7a6 | ||
|
|
5f7ab3cd7b
|
||
|
|
f81f05c3d0 | ||
|
|
0afb6ce06a | ||
|
|
5ce69e6b7a
|
||
|
|
a938abde3f | ||
|
|
ec9b0387c5 | ||
|
|
03c3d49659 | ||
|
|
8d9a77ab67 | ||
|
|
fc2997e011 | ||
|
|
8eb5f5ddf2 | ||
|
|
9e43d5cd1b | ||
|
|
2ad9ae3c7f | ||
|
|
847eb3fe5d | ||
|
|
8fa9f7b0d3 | ||
|
|
559cae2b6d | ||
|
|
5dbf3638d0 | ||
|
|
fd8f942014 | ||
|
|
eab8826583 | ||
|
|
bc0177df43 | ||
|
|
1dc78b8eb8 |
@@ -51,6 +51,7 @@ jobs:
|
||||
rm -rf deploy
|
||||
mkdir -p deploy
|
||||
|
||||
cp "AccessWidener/build/libs/AccessWidener-all.jar" "deploy/AccessWidener.jar"
|
||||
cp "BauSystem/build/libs/BauSystem-all.jar" "deploy/BauSystem.jar"
|
||||
cp "FightSystem/build/libs/FightSystem-all.jar" "deploy/FightSystem.jar"
|
||||
cp "KotlinCore/build/libs/KotlinCore-all.jar" "deploy/KotlinCore.jar"
|
||||
|
||||
@@ -15,6 +15,11 @@ bin/
|
||||
.vscode
|
||||
.settings
|
||||
|
||||
# Language Server
|
||||
**/.project
|
||||
**/.factorypath
|
||||
**/.classpath
|
||||
|
||||
# Other
|
||||
lib
|
||||
/WebsiteBackend/data
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 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 {
|
||||
`java-library`
|
||||
alias(libs.plugins.shadow)
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("org.ow2.asm:asm:9.7")
|
||||
implementation("org.ow2.asm:asm-commons:9.7")
|
||||
}
|
||||
|
||||
tasks.shadowJar {
|
||||
manifest {
|
||||
attributes(
|
||||
"Manifest-Version" to "1.0",
|
||||
"Build-Jdk-Spec" to "21",
|
||||
"Main-Class" to "de.steamwar.Main",
|
||||
"Premain-Class" to "de.steamwar.Agent",
|
||||
"Can-Retransform-Classes" to "true",
|
||||
"Can-Redefine-Classes" to "true",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
tasks.build {
|
||||
dependsOn(tasks.shadowJar)
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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;
|
||||
|
||||
/**
|
||||
* A single parsed line from a .accesswidener file.
|
||||
* <p>
|
||||
* Examples:
|
||||
* accessible class net/minecraft/server/level/ServerPlayer
|
||||
* accessible method net/minecraft/server/level/ServerPlayer getStats ()V
|
||||
* mutable field net/minecraft/world/entity/Entity id I
|
||||
* extendable class net/minecraft/world/level/chunk/LevelChunk
|
||||
*/
|
||||
public record AccessWidenerEntry(
|
||||
/** accessible | mutable | extendable (may have "transitive-" prefix) */
|
||||
String directive,
|
||||
/** class | method | field */
|
||||
String memberType,
|
||||
/** Internal class name, e.g. net/minecraft/server/level/ServerPlayer */
|
||||
String target,
|
||||
/** Method/field name, null for class entries */
|
||||
String name,
|
||||
/** Descriptor, null for class entries */
|
||||
String descriptor) {
|
||||
/**
|
||||
* Returns true if this entry targets the class with the given internal name.
|
||||
*/
|
||||
public boolean targets(String internalName) {
|
||||
return target.equals(internalName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Parses Fabric-compatible .accesswidener files.
|
||||
* <p>
|
||||
* Supported format:
|
||||
* <pre>
|
||||
* accessWidener v2 named
|
||||
*
|
||||
* # comments are supported
|
||||
* accessible class net/minecraft/Foo
|
||||
* accessible method net/minecraft/Foo someMethod ()V
|
||||
* accessible field net/minecraft/Foo someField I
|
||||
* mutable field net/minecraft/Foo someField I
|
||||
* extendable class net/minecraft/Foo
|
||||
* extendable method net/minecraft/Foo someMethod ()V
|
||||
*
|
||||
* # transitive variants (expose widening to dependents)
|
||||
* transitive-accessible class net/minecraft/Foo
|
||||
* </pre>
|
||||
*/
|
||||
public final class AccessWidenerParser {
|
||||
|
||||
private AccessWidenerParser() {
|
||||
}
|
||||
|
||||
public static List<AccessWidenerEntry> parse(InputStream in) throws IOException {
|
||||
List<AccessWidenerEntry> entries = new ArrayList<>();
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8))) {
|
||||
|
||||
String line;
|
||||
boolean headerSeen = false;
|
||||
|
||||
while ((line = reader.readLine()) != null) {
|
||||
// Strip inline comments
|
||||
int commentIdx = line.indexOf('#');
|
||||
if (commentIdx >= 0) line = line.substring(0, commentIdx);
|
||||
line = line.strip();
|
||||
|
||||
if (line.isEmpty()) continue;
|
||||
|
||||
if (!headerSeen) {
|
||||
// First non-blank, non-comment line must be the header
|
||||
if (!line.startsWith("accessWidener")) {
|
||||
throw new IOException("Missing accessWidener header, got: " + line);
|
||||
}
|
||||
headerSeen = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
AccessWidenerEntry entry = parseLine(line);
|
||||
if (entry != null) entries.add(entry);
|
||||
}
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
private static AccessWidenerEntry parseLine(String line) {
|
||||
String[] parts = line.split("\\s+");
|
||||
if (parts.length < 3) return null;
|
||||
|
||||
String directive = parts[0]; // accessible / mutable / extendable / transitive-*
|
||||
String memberType = parts[1]; // class / method / field
|
||||
String target = parts[2]; // internal class name
|
||||
|
||||
return switch (memberType) {
|
||||
case "class" -> new AccessWidenerEntry(directive, "class", target, null, null);
|
||||
case "method", "field" -> {
|
||||
if (parts.length < 5) yield null;
|
||||
yield new AccessWidenerEntry(directive, memberType, target, parts[3], parts[4]);
|
||||
}
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.instrument.Instrumentation;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Java agent entry point.
|
||||
* <p>
|
||||
* At JVM startup: java -javaagent:paper-access-widener-agent.jar -jar server.jar
|
||||
* <p>
|
||||
* On attach the agent:
|
||||
* <ol>
|
||||
* <li>Find all .jar files inside the plugins folder</li>
|
||||
* <li>Scan all found jars for *.accesswidener resources</li>
|
||||
* <li>Transform any class during loading</li>
|
||||
* </ol>
|
||||
*/
|
||||
public class Agent {
|
||||
private Agent() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
private static final Logger LOG = Logger.getLogger("AccessWidenerAgent");
|
||||
|
||||
// -javaagent: startup
|
||||
public static void premain(String args, Instrumentation inst) {
|
||||
init(inst);
|
||||
}
|
||||
|
||||
private static void init(Instrumentation inst) {
|
||||
LOG.info("[AccessWidener] Agent initialising.");
|
||||
|
||||
List<AccessWidenerEntry> entries = new ArrayList<>();
|
||||
File file = new File(new File(".").getAbsoluteFile(), "plugins/");
|
||||
File[] files = file.listFiles();
|
||||
if (files == null) files = new File[0];
|
||||
for (File jarFile : files) {
|
||||
if (!jarFile.isFile()) continue;
|
||||
if (!jarFile.getName().endsWith(".jar")) continue;
|
||||
try {
|
||||
entries.addAll(Utils.findAndParseAccessWideners(jarFile.toPath()));
|
||||
} catch (IOException e) {
|
||||
LOG.warning("Failed to parse access wideners from " + jarFile.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
LOG.info("[AccessWidener] Loaded " + entries.size() + " access wideners.");
|
||||
|
||||
inst.addTransformer(new WideningTransformer(entries), false);
|
||||
LOG.info("[AccessWidener] Agent ready.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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;
|
||||
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Uses ASM to patch class bytecode according to a list of access widener entries.
|
||||
*
|
||||
* Returns {@code null} if the class is not targeted by any entry (no-op signal
|
||||
* to the caller so it can skip the write).
|
||||
*/
|
||||
public class ClassPatcher {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger("ClassPatcher");
|
||||
|
||||
private final List<AccessWidenerEntry> entries;
|
||||
|
||||
/** Pre-computed set of targeted internal names for fast filtering. */
|
||||
private final Set<String> targets;
|
||||
|
||||
private final Set<String> targetsPublicConstructor;
|
||||
|
||||
public ClassPatcher(List<AccessWidenerEntry> entries) {
|
||||
this.entries = entries;
|
||||
this.targets = entries.stream()
|
||||
.map(AccessWidenerEntry::target)
|
||||
.flatMap(s -> {
|
||||
if (!s.contains("$")) return Stream.of(s);
|
||||
int index = s.lastIndexOf('$');
|
||||
return Stream.of(s, s.substring(0, index));
|
||||
})
|
||||
.collect(Collectors.toSet());
|
||||
this.targetsPublicConstructor = entries.stream()
|
||||
.filter(entry -> entry.directive().equals("transitive-extendable"))
|
||||
.map(AccessWidenerEntry::target)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Patches {@code classBytes} if {@code className} is targeted.
|
||||
*
|
||||
* @return patched bytes, or {@code null} if no changes were needed
|
||||
*/
|
||||
public byte[] patch(String className, byte[] classBytes) {
|
||||
if (!targets.contains(className)) return null;
|
||||
|
||||
try {
|
||||
ClassReader cr = new ClassReader(classBytes);
|
||||
ClassWriter cw = new ClassWriter(cr, 0);
|
||||
cr.accept(new ClassTransformer(cw, className, entries, targetsPublicConstructor.contains(className)), ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
|
||||
return cw.toByteArray();
|
||||
} catch (Exception e) {
|
||||
LOG.warning("[AccessWidener] Failed to transform " + className + ": " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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;
|
||||
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
import org.objectweb.asm.FieldVisitor;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ClassTransformer extends ClassVisitor {
|
||||
|
||||
private final String internalName;
|
||||
private final List<AccessWidenerEntry> entries;
|
||||
private final boolean appendPublicConstructor;
|
||||
|
||||
public ClassTransformer(ClassVisitor cv, String internalName, List<AccessWidenerEntry> entries, boolean appendPublicConstructor) {
|
||||
super(Opcodes.ASM9, cv);
|
||||
this.internalName = internalName;
|
||||
this.entries = entries;
|
||||
this.appendPublicConstructor = appendPublicConstructor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
|
||||
int newAccess = access;
|
||||
for (AccessWidenerEntry e : entries) {
|
||||
if (!e.targets(internalName) || !"class".equals(e.memberType())) continue;
|
||||
newAccess = applyDirective(e.directive(), newAccess, false);
|
||||
}
|
||||
if (appendPublicConstructor) {
|
||||
MethodVisitor methodVisitor = visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
|
||||
methodVisitor.visitCode();
|
||||
methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
|
||||
methodVisitor.visitMethodInsn(
|
||||
Opcodes.INVOKESPECIAL,
|
||||
"java/lang/Object",
|
||||
"<init>",
|
||||
"()V",
|
||||
false
|
||||
);
|
||||
methodVisitor.visitInsn(Opcodes.RETURN);
|
||||
methodVisitor.visitMaxs(1, 1);
|
||||
methodVisitor.visitEnd();
|
||||
}
|
||||
super.visit(version, newAccess, name, signature, superName, interfaces);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitInnerClass(String name, String outerName, String innerName, int access) {
|
||||
int newAccess = access;
|
||||
for (AccessWidenerEntry e : entries) {
|
||||
if (!e.target().equals(name) || !"class".equals(e.memberType())) continue;
|
||||
newAccess = applyDirective(e.directive(), newAccess, false);
|
||||
}
|
||||
super.visitInnerClass(name, outerName, innerName, newAccess);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {
|
||||
int newAccess = access;
|
||||
for (AccessWidenerEntry e : entries) {
|
||||
if (!e.targets(internalName) || !"method".equals(e.memberType())) continue;
|
||||
if (!name.equals(e.name()) || !descriptor.equals(e.descriptor())) continue;
|
||||
newAccess = applyDirective(e.directive(), newAccess, false);
|
||||
}
|
||||
return super.visitMethod(newAccess, name, descriptor, signature, exceptions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FieldVisitor visitField(int access, String name, String descriptor, String signature, Object value) {
|
||||
int newAccess = access;
|
||||
for (AccessWidenerEntry e : entries) {
|
||||
if (!e.targets(internalName) || !"field".equals(e.memberType())) continue;
|
||||
if (!name.equals(e.name())) continue;
|
||||
newAccess = applyDirective(e.directive(), newAccess, true);
|
||||
}
|
||||
return super.visitField(newAccess, name, descriptor, signature, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a directive to an access bitmask.
|
||||
*
|
||||
* @param directive accessible / mutable / extendable (with optional "transitive-" prefix)
|
||||
* @param access current access flags
|
||||
* @param isField true when processing a field (mutable removes final)
|
||||
*/
|
||||
private static int applyDirective(String directive, int access, boolean isField) {
|
||||
// Strip transitive- prefix — the widening itself is the same
|
||||
String effective = directive.startsWith("transitive-") ? directive.substring("transitive-".length()) : directive;
|
||||
|
||||
return switch (effective) {
|
||||
case "accessible" -> makePublic(access);
|
||||
case "extendable" -> makePublic(removeFinal(access));
|
||||
case "mutable" -> isField ? removeFinal(access) : access;
|
||||
default -> access;
|
||||
};
|
||||
}
|
||||
|
||||
private static int makePublic(int access) {
|
||||
return (access & ~(Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED)) | Opcodes.ACC_PUBLIC;
|
||||
}
|
||||
|
||||
private static int removeFinal(int access) {
|
||||
return access & ~Opcodes.ACC_FINAL;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Command-line tool that produces a widened copy of a JAR for use as a
|
||||
* compile-time stub in IntelliJ / Gradle.
|
||||
*
|
||||
* Usage:
|
||||
* java -jar jar-widener.jar <input.jar> <output.jar> [file.accesswidener ...]
|
||||
*
|
||||
* The output JAR is identical to the input JAR except that every class
|
||||
* targeted by the access widener entries has its access flags patched:
|
||||
* accessible → public
|
||||
* extendable → public + non-final
|
||||
* mutable → non-final field
|
||||
*
|
||||
* Intended for use as a Gradle task so IntelliJ sees the already-widened
|
||||
* class when you Ctrl+click NMS code, and javac compiles without complaints.
|
||||
*/
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
if (args.length < 2) {
|
||||
System.err.println("Usage: jar-widener <input.jar> <output.jar> [*.accesswidener ...]");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
Path inputJar = Path.of(args[0]);
|
||||
Path outputJar = Path.of(args[1]);
|
||||
|
||||
if (!Files.exists(inputJar)) {
|
||||
System.err.println("Input JAR not found: " + inputJar);
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
// --- Collect all access widener entries ---
|
||||
List<AccessWidenerEntry> entries = new ArrayList<>();
|
||||
|
||||
if (args.length > 2) {
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
Path awFile = Path.of(args[i]);
|
||||
if (!Files.exists(awFile)) {
|
||||
System.err.println("Warning: access widener file not found, skipping: " + awFile);
|
||||
continue;
|
||||
}
|
||||
try (InputStream in = Files.newInputStream(awFile)) {
|
||||
List<AccessWidenerEntry> parsed = AccessWidenerParser.parse(in);
|
||||
System.out.println("Loaded " + parsed.size() + " entries from " + awFile.getFileName());
|
||||
entries.addAll(parsed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (entries.isEmpty()) {
|
||||
System.out.println("No access widener entries found — copying JAR unchanged.");
|
||||
Files.createDirectories(outputJar.getParent());
|
||||
Files.copy(inputJar, outputJar, StandardCopyOption.REPLACE_EXISTING);
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("Widening " + inputJar.getFileName()
|
||||
+ " with " + entries.size() + " total entr"
|
||||
+ (entries.size() == 1 ? "y" : "ies") + "...");
|
||||
|
||||
// --- Copy input → output, transforming .class files in place ---
|
||||
Files.createDirectories(outputJar.getParent());
|
||||
Files.copy(inputJar, outputJar, StandardCopyOption.REPLACE_EXISTING);
|
||||
|
||||
ClassPatcher patcher = new ClassPatcher(entries);
|
||||
|
||||
try (FileSystem fs = FileSystems.newFileSystem(outputJar)) {
|
||||
// Walk every .class entry in the JAR
|
||||
try (var stream = Files.walk(fs.getPath("/"))) {
|
||||
stream.filter(p -> p.toString().endsWith(".class"))
|
||||
.forEach(classPath -> patchClass(fs, classPath, patcher));
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("Done. Widened JAR written to " + outputJar);
|
||||
}
|
||||
|
||||
private static void patchClass(FileSystem fs, Path classPath, ClassPatcher patcher) {
|
||||
// Derive internal class name from path e.g. /net/minecraft/Foo.class → net/minecraft/Foo
|
||||
String internalName = classPath.toString()
|
||||
.replaceFirst("^/", "")
|
||||
.replace(".class", "");
|
||||
|
||||
try {
|
||||
byte[] original = Files.readAllBytes(classPath);
|
||||
byte[] patched = patcher.patch(internalName, original);
|
||||
|
||||
if (patched != null) {
|
||||
Files.write(classPath, patched);
|
||||
System.out.println(" Widened: " + internalName);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println(" Warning: failed to patch " + internalName + ": " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
public class Utils {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger("AccessWidenerAgent");
|
||||
|
||||
private Utils() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
public static List<AccessWidenerEntry> findAndParseAccessWideners(Path jarPath) throws IOException {
|
||||
List<AccessWidenerEntry> results = new ArrayList<>();
|
||||
|
||||
try (ZipFile zip = new ZipFile(jarPath.toFile())) {
|
||||
Enumeration<? extends ZipEntry> entries = zip.entries();
|
||||
while (entries.hasMoreElements()) {
|
||||
ZipEntry entry = entries.nextElement();
|
||||
if (entry.isDirectory() || !entry.getName().endsWith(".accesswidener")) continue;
|
||||
|
||||
try (InputStream in = zip.getInputStream(entry)) {
|
||||
results.addAll(AccessWidenerParser.parse(in));
|
||||
} catch (IOException e) {
|
||||
LOG.warning("[AccessWidener] Failed to parse " + entry.getName()
|
||||
+ " in " + jarPath.getFileName() + ": " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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;
|
||||
|
||||
import java.lang.instrument.ClassFileTransformer;
|
||||
import java.security.ProtectionDomain;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Transforms class bytecode to apply access widening rules.
|
||||
* <p>
|
||||
* Also monitors for new plugin ClassLoaders appearing (when plugins load after
|
||||
* the agent attaches) and automatically picks up their .accesswidener files.
|
||||
*/
|
||||
public class WideningTransformer implements ClassFileTransformer {
|
||||
|
||||
private final ClassPatcher patcher;
|
||||
|
||||
public WideningTransformer(List<AccessWidenerEntry> entries) {
|
||||
patcher = new ClassPatcher(entries);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) {
|
||||
return patcher.patch(className, classfileBuffer);
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
plugins {
|
||||
steamwar.java
|
||||
widener
|
||||
}
|
||||
|
||||
tasks.compileJava {
|
||||
@@ -34,6 +35,7 @@ dependencies {
|
||||
compileOnly(libs.classindex)
|
||||
annotationProcessor(libs.classindex)
|
||||
compileOnly(project(":SpigotCore", "default"))
|
||||
compileOnly(project(":KotlinCore", "default"))
|
||||
|
||||
compileOnly(libs.axiom)
|
||||
compileOnly(libs.authlib)
|
||||
@@ -47,3 +49,7 @@ dependencies {
|
||||
implementation(libs.luaj)
|
||||
implementation(files("$projectDir/../libs/YAPION-SNAPSHOT.jar"))
|
||||
}
|
||||
|
||||
widener {
|
||||
fromCatalog(libs.nms)
|
||||
}
|
||||
|
||||
@@ -834,6 +834,10 @@ SKIN_NO_REGION = §7You are not in a region with a changealbe skin
|
||||
SKIN_ALREADY_EXISTS = §cThis skin already exists like this
|
||||
SKIN_MESSAGE = §7Skin created
|
||||
SKIN_MESSAGE_HOVER = §eClick to copy for YoyoNow and send
|
||||
# Blast Resistance
|
||||
BLASTRESISTANCE_HELP = §8/§eblastresistance §8-§7 Calculate min/max and average blast resistance of current clipboard
|
||||
BLASTRESISTANCE_NO_CLIPBOARD = §cYou currently do not have a clipboard to be used.
|
||||
BLASTRESISTANCE_RESULT = §7BlastResistance §8>>§7 Min§8: §e{0}§7 Max§8: §e{1}§7 Avg§8: §e{2}
|
||||
# Panzern
|
||||
PANZERN_HELP = §8/§epanzern §8[§7Block§8] §8[§7Slab§8] §8- §7Armor your WorldEdit selection
|
||||
PANZERN_PREPARE1 = §71. Check, if barrels reach until border of armor.
|
||||
|
||||
@@ -772,6 +772,10 @@ SKIN_NO_REGION = §7Du steht in keiner Region, welche mit einem Skin versehen we
|
||||
SKIN_ALREADY_EXISTS = §cDieser Skin existiert in der Form bereits
|
||||
SKIN_MESSAGE = §7Skin erstellt
|
||||
SKIN_MESSAGE_HOVER = §eKlicken zum kopieren für YoyoNow und an diesen senden
|
||||
# Blast Resistance
|
||||
BLASTRESISTANCE_HELP = §8/§eblastresistance §8-§7 Minimal-, Maximal- und durchschnittliche Sprengfestigkeit des aktuellen Inhalts der Zwischenablage berechnen
|
||||
BLASTRESISTANCE_NO_CLIPBOARD = §cDerzeit steht Ihnen keine Zwischenablage zur Verfügung.
|
||||
BLASTRESISTANCE_RESULT = §7BlastResistance §8>>§7 Min§8: §e{0}§7 Max§8: §e{1}§7 Avg§8: §e{2}
|
||||
# Panzern
|
||||
PANZERN_HELP = §8/§epanzern §8[§7Block§8] §8[§7Slab§8] §8- §7Panzer deine WorldEdit Auswahl
|
||||
PANZERN_PREPARE1 = §71. Gucke nochmal nach, ob Läufe auch bis zur Panzergrenze führen.
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
accessWidener v2 named
|
||||
|
||||
# For NoClipCommand
|
||||
accessible field net/minecraft/server/level/ServerPlayerGameMode gameModeForPlayer Lnet/minecraft/world/level/GameType;
|
||||
|
||||
# For PlaceItemUtils
|
||||
accessible field org/bukkit/craftbukkit/block/CraftBlockState position Lnet/minecraft/core/BlockPos;
|
||||
mutable field org/bukkit/craftbukkit/block/CraftBlockState position Lnet/minecraft/core/BlockPos;
|
||||
accessible field org/bukkit/craftbukkit/block/CraftBlockState world Lorg/bukkit/craftbukkit/CraftWorld;
|
||||
mutable field org/bukkit/craftbukkit/block/CraftBlockState world Lorg/bukkit/craftbukkit/CraftWorld;
|
||||
|
||||
# For TickManager
|
||||
accessible field net/minecraft/server/ServerTickRateManager remainingSprintTicks J
|
||||
+8
-11
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 SteamWar.de-Serverteam
|
||||
* Copyright (C) 2026 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
|
||||
@@ -17,18 +17,15 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.core;
|
||||
package de.steamwar.bausystem.features.experimental;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.network.chat.contents.PlainTextContents;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
|
||||
import java.util.Optional;
|
||||
@Linked
|
||||
public class ExperimentalCommand extends SWCommand {
|
||||
|
||||
@UtilityClass
|
||||
public class FlatteningWrapper {
|
||||
|
||||
public Object formatDisplayName(String displayName) {
|
||||
return displayName != null ? Optional.of((Object) MutableComponent.create(PlainTextContents.create(displayName))) : Optional.empty();
|
||||
public ExperimentalCommand() {
|
||||
super("experimental", "experiment");
|
||||
}
|
||||
}
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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.bausystem.features.experimental.redstone_engine;
|
||||
|
||||
import de.steamwar.bausystem.features.experimental.ExperimentalCommand;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.utils.ScoreboardElement;
|
||||
import de.steamwar.command.AbstractSWCommand;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import io.papermc.paper.configuration.WorldConfiguration;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.title.TitlePart;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@AbstractSWCommand.PartOf(ExperimentalCommand.class)
|
||||
@Linked
|
||||
public class RedstoneEngine extends SWCommand implements Listener, ScoreboardElement {
|
||||
|
||||
public RedstoneEngine() {
|
||||
super("");
|
||||
}
|
||||
|
||||
private WorldConfiguration.Misc getConfig() {
|
||||
return ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle().paperConfig().misc;
|
||||
}
|
||||
|
||||
@Register("redstone")
|
||||
@Register("redstoneengine")
|
||||
public void setRedstoneEngine(Player player, @StaticValue("alternate_current") String __, WorldConfiguration.Misc.AlternateCurrentUpdateOrder updateOrder) {
|
||||
WorldConfiguration.Misc misc = getConfig();
|
||||
misc.redstoneImplementation = WorldConfiguration.Misc.RedstoneImplementation.ALTERNATE_CURRENT;
|
||||
misc.alternateCurrentUpdateOrder = updateOrder;
|
||||
broadcastTitle(Bukkit.getOnlinePlayers());
|
||||
}
|
||||
|
||||
@Register("redstone")
|
||||
@Register("redstoneengine")
|
||||
public void setRedstoneEngine(Player player, WorldConfiguration.Misc.RedstoneImplementation implementation) {
|
||||
getConfig().redstoneImplementation = implementation;
|
||||
broadcastTitle(Bukkit.getOnlinePlayers());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
WorldConfiguration.Misc misc = getConfig();
|
||||
if (misc.redstoneImplementation != WorldConfiguration.Misc.RedstoneImplementation.EIGENCRAFT) {
|
||||
broadcastTitle(List.of(event.getPlayer()));
|
||||
}
|
||||
}
|
||||
|
||||
private void broadcastTitle(Collection<? extends Player> players) {
|
||||
WorldConfiguration.Misc misc = getConfig();
|
||||
Component title = switch (misc.redstoneImplementation) {
|
||||
case VANILLA -> Component.text("⚠").color(NamedTextColor.RED).append(Component.text(" Redstone: Vanilla ").color(NamedTextColor.WHITE)).append(Component.text("⚠").color(NamedTextColor.RED));
|
||||
case EIGENCRAFT -> Component.text("Redstone: Eigencraft");
|
||||
case ALTERNATE_CURRENT -> Component.text("⚠").color(NamedTextColor.RED).append(Component.text(" Redstone: AC ").color(NamedTextColor.WHITE)).append(Component.text("⚠").color(NamedTextColor.RED));
|
||||
};
|
||||
Component subtitle;
|
||||
if (misc.redstoneImplementation != WorldConfiguration.Misc.RedstoneImplementation.ALTERNATE_CURRENT) {
|
||||
subtitle = Component.text().build();
|
||||
} else {
|
||||
subtitle = switch (misc.alternateCurrentUpdateOrder) {
|
||||
case VERTICAL_FIRST_INWARD -> Component.text("Y first inwards"); // Y before XZ
|
||||
case VERTICAL_FIRST_OUTWARD -> Component.text("Y first outwards"); // XZ before Y
|
||||
case HORIZONTAL_FIRST_INWARD -> Component.text("XZ first inwards"); // Y before XZ
|
||||
case HORIZONTAL_FIRST_OUTWARD -> Component.text("XZ first outwards"); // XZ before Y
|
||||
};
|
||||
}
|
||||
players.forEach(player -> {
|
||||
player.sendTitlePart(TitlePart.TITLE, title);
|
||||
player.sendTitlePart(TitlePart.SUBTITLE, subtitle);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScoreboardGroup getGroup() {
|
||||
return ScoreboardGroup.FOOTER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int order() {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get(Region region, Player p) {
|
||||
WorldConfiguration.Misc misc = getConfig();
|
||||
switch (misc.redstoneImplementation) {
|
||||
case ALTERNATE_CURRENT:
|
||||
switch (misc.alternateCurrentUpdateOrder) {
|
||||
case VERTICAL_FIRST_INWARD:
|
||||
return "§eRedstone§8: §cAC §8(§7Y in§8)";
|
||||
case VERTICAL_FIRST_OUTWARD:
|
||||
return "§eRedstone§8: §cAC §8(§7Y out§8)";
|
||||
case HORIZONTAL_FIRST_INWARD:
|
||||
return "§eRedstone§8: §cAC §8(§7XZ in§8)";
|
||||
case HORIZONTAL_FIRST_OUTWARD:
|
||||
return "§eRedstone§8: §cAC §8(§7XZ out§8)";
|
||||
}
|
||||
return "§eRedstone§8: §cAC";
|
||||
case EIGENCRAFT:
|
||||
return null;
|
||||
case VANILLA:
|
||||
default:
|
||||
return "§eRedstone§8: §cVanilla";
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -290,7 +290,7 @@ public class KillcheckerVisualizer {
|
||||
}
|
||||
rEntities.get(point).die();
|
||||
}
|
||||
RBlockDisplay entity = new RBlockDisplay(outlinePoints.contains(point) ? outline : inner, point.toLocation(WORLD, 0.5, 0, 0.5));
|
||||
RBlockDisplay entity = new RBlockDisplay(outlinePoints.contains(point) ? outline : inner, point.toLocation(WORLD, 0, 0, 0));
|
||||
entity.setBlock(MATERIALS[Math.min(count - 1, MATERIALS.length) - 1].createBlockData());
|
||||
rEntities.put(point, entity);
|
||||
if (outlinePoints.contains(point)) outlinePointsCache.add(point);
|
||||
|
||||
+4
-5
@@ -185,17 +185,16 @@ public class TestblockCommand extends SWCommand {
|
||||
return new TypeMapper<SchematicNode>() {
|
||||
@Override
|
||||
public List<String> tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) {
|
||||
List<String> stringList = new ArrayList<>(SchematicNode.getNodeTabcomplete(SteamwarUser.get(((Player) commandSender).getUniqueId()), s));
|
||||
List<String> stringList = new ArrayList<>();
|
||||
stringList.addAll(SchematicNode.getNodeTabcomplete(SteamwarUser.byId(0), s));
|
||||
stringList.addAll(SchematicNode.getNodeTabcomplete(SteamwarUser.get(((Player) commandSender).getUniqueId()), s));
|
||||
return stringList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SchematicNode map(CommandSender commandSender, PreviousArguments previousArguments, String s) {
|
||||
SchematicNode node = SchematicNode.getNodeFromPath(SteamwarUser.get(((Player) commandSender).getUniqueId()), s);
|
||||
if (node == null) {
|
||||
node = SchematicNode.getNodeFromPath(SteamwarUser.byId(0), s);
|
||||
}
|
||||
SchematicNode node = SchematicNode.getNodeFromPath(SteamwarUser.byId(0), s);
|
||||
if (node == null) node = SchematicNode.getNodeFromPath(SteamwarUser.get(((Player) commandSender).getUniqueId()), s);
|
||||
return node;
|
||||
}
|
||||
};
|
||||
|
||||
+14
-12
@@ -19,6 +19,7 @@
|
||||
|
||||
package de.steamwar.bausystem.features.simulator;
|
||||
|
||||
import com.destroystokyo.paper.event.server.ServerTickEndEvent;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.bausystem.SWUtils;
|
||||
@@ -55,19 +56,11 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryDragEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.event.player.PlayerItemHeldEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerToggleSneakEvent;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -85,8 +78,16 @@ public class SimulatorCursor implements Listener {
|
||||
return isSimulatorItem(player.getInventory().getItemInMainHand()) || isSimulatorItem(player.getInventory().getItemInOffHand());
|
||||
}
|
||||
|
||||
private static Set<Player> scheduledUpdates = new HashSet<>();
|
||||
|
||||
private static void scheduleCursorUpdate(Player player) {
|
||||
BauSystem.runTaskLater(BauSystem.getInstance(), () -> calcCursor(player), 1);
|
||||
scheduledUpdates.add(player);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onServerTickEnd(ServerTickEndEvent event) {
|
||||
scheduledUpdates.forEach(SimulatorCursor::calcCursor);
|
||||
scheduledUpdates.clear();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@@ -130,6 +131,7 @@ public class SimulatorCursor implements Listener {
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
cursorType.remove(event.getPlayer());
|
||||
removeCursor(event.getPlayer());
|
||||
scheduledUpdates.remove(event.getPlayer());
|
||||
}
|
||||
|
||||
private static final Map<Player, Long> LAST_SNEAKS = new HashMap<>();
|
||||
@@ -172,7 +174,7 @@ public class SimulatorCursor implements Listener {
|
||||
|
||||
public static void calcCursor(Player player) {
|
||||
if (!Permission.BUILD.hasPermission(player) || !hasSimulatorItem(player)) {
|
||||
if (removeCursor(player) || SimulatorWatcher.show(null, player)) {
|
||||
if (removeCursor(player) | SimulatorWatcher.show(null, player)) {
|
||||
SWUtils.sendToActionbar(player, "");
|
||||
}
|
||||
return;
|
||||
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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.bausystem.features.slaves.blastresistance;
|
||||
|
||||
import com.google.common.util.concurrent.AtomicDouble;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@Linked
|
||||
public class BlastResistanceCommand extends SWCommand {
|
||||
|
||||
public BlastResistanceCommand() {
|
||||
super("blastresistance");
|
||||
}
|
||||
|
||||
@Register(description = "BLASTRESISTANCE_HELP")
|
||||
public void command(@Validator Player player) {
|
||||
LocalSession localSession = WorldEdit.getInstance().getSessionManager().get(BukkitAdapter.adapt(player));
|
||||
Clipboard clipboard;
|
||||
try {
|
||||
clipboard = localSession.getClipboard().getClipboards().getFirst();
|
||||
} catch (WorldEditException e) {
|
||||
BauSystem.MESSAGE.send("BLASTRESISTANCE_NO_CLIPBOARD", player);
|
||||
return;
|
||||
}
|
||||
|
||||
AtomicDouble min = new AtomicDouble(0);
|
||||
AtomicDouble max = new AtomicDouble(0);
|
||||
AtomicDouble sum = new AtomicDouble(0);
|
||||
AtomicInteger count = new AtomicInteger(0);
|
||||
clipboard.forEach(blockVector3 -> {
|
||||
BlockState blockState = clipboard.getBlock(blockVector3);
|
||||
Material material = BukkitAdapter.adapt(blockState).getMaterial();
|
||||
if (material == Material.WATER || material == Material.LAVA) return;
|
||||
double blastResistance = BukkitAdapter.adapt(blockState).getMaterial().getBlastResistance();
|
||||
min.set(Math.min(min.get(), blastResistance));
|
||||
max.set(Math.max(max.get(), blastResistance));
|
||||
sum.addAndGet(blastResistance);
|
||||
count.getAndIncrement();
|
||||
});
|
||||
|
||||
BauSystem.MESSAGE.send("BLASTRESISTANCE_RESULT", player, min.get(), max.get(), sum.get() / count.get());
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -31,6 +31,7 @@ import de.steamwar.command.TypeMapper;
|
||||
import de.steamwar.core.CraftbukkitWrapper;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.linkage.LinkedInstance;
|
||||
import de.steamwar.techhider.legacy.TechHider;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -38,7 +39,6 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import de.steamwar.techhider.legacy.TechHider;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -165,6 +165,7 @@ public class TPSSystem implements Listener {
|
||||
}
|
||||
|
||||
@Register(value = "default", description = "TPSLIMIT_DEFAULT_HELP")
|
||||
@Register(value = "rate")
|
||||
public void reset(@Validator Player player) {
|
||||
TickManager.impl.setTickRate(20.0F);
|
||||
sendTickRateChange();
|
||||
@@ -187,15 +188,18 @@ public class TPSSystem implements Listener {
|
||||
}
|
||||
|
||||
@Register(value = {"rate", "0"}, description = "TICK_FREEZE_HELP")
|
||||
@Register(value = "freeze", description = "TICK_FREEZE_HELP_2")
|
||||
public void freeze(@Validator Player player) {
|
||||
public void rate(@Validator Player player) {
|
||||
TickManager.impl.setFreeze(true);
|
||||
sendTickRateChange();
|
||||
}
|
||||
|
||||
@Register(value = "unfreeze", description = "TICK_UNFREEZE_HELP")
|
||||
public void unfreeze(@Validator Player player) {
|
||||
TickManager.impl.setTickRate(20.0F);
|
||||
@Register(value = "freeze", description = "TICK_FREEZE_HELP_2")
|
||||
public void freezeToggle(@Validator Player player) {
|
||||
if (TickManager.impl.isFrozen()) {
|
||||
TickManager.impl.setTickRate(20.0F);
|
||||
} else {
|
||||
TickManager.impl.setFreeze(true);
|
||||
}
|
||||
sendTickRateChange();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ import de.steamwar.bausystem.features.tracer.rendering.TraceEntity;
|
||||
import de.steamwar.bausystem.features.tracer.rendering.ViewFlag;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.entity.REntity;
|
||||
import de.steamwar.entity.REntityAction;
|
||||
import de.steamwar.entity.REntityServer;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
+5
-1
@@ -153,7 +153,11 @@ public class TraceCommand extends SWCommand {
|
||||
|
||||
@Register(value = "isolate", description = "TRACE_COMMAND_HELP_ISOLATE")
|
||||
public void isolate(@Validator Player player, Trace trace, @ErrorMessage("TRACE_RECORD_ID_INVALID") TNTPoint... records) {
|
||||
TraceManager.instance.isolate(player, records);
|
||||
if (records.length == 0) {
|
||||
TraceManager.instance.isolate(player, trace, trace.getRecords().toArray(TNTPoint[]::new));
|
||||
} else {
|
||||
TraceManager.instance.isolate(player, trace, records);
|
||||
}
|
||||
BauSystem.MESSAGE.send("TRACE_MESSAGE_ISOLATE", player);
|
||||
}
|
||||
|
||||
|
||||
+15
-6
@@ -347,9 +347,10 @@ public class TraceManager implements Listener {
|
||||
* Toggles the isolated render for the given records and player
|
||||
*
|
||||
* @param player the player the trace is shown to
|
||||
* @param records the record for which isolation is toggled
|
||||
* @param ptrace the trace for whitch isolation is toggled
|
||||
* @param records the records of the trace for which isolation is toggled
|
||||
*/
|
||||
public void isolate(Player player, TNTPoint... records) {
|
||||
public void isolate(Player player, Trace ptrace, TNTPoint... records) {
|
||||
unfollow(player);
|
||||
|
||||
Region region = Region.getRegion(player.getLocation());
|
||||
@@ -374,12 +375,20 @@ public class TraceManager implements Listener {
|
||||
isolateFlag.toggleId(record.getTntId());
|
||||
}
|
||||
|
||||
if (isolateFlag.isEmpty() && playerTraceShowData.hasViewFlagOnly(IsolateFlag.class) && records.length != 0) {
|
||||
playerTraceShowData.removeViewFlag(IsolateFlag.class);
|
||||
}
|
||||
|
||||
PlayerTraceShowData finalPlayerTraceShowData = playerTraceShowData;
|
||||
tracesByRegion.getOrDefault(region, Collections.emptyMap()).forEach((integer, trace) -> {
|
||||
trace.render(player, finalPlayerTraceShowData);
|
||||
followerMap.getOrDefault(player, Collections.emptySet()).forEach(follower -> {
|
||||
trace.render(follower, finalPlayerTraceShowData);
|
||||
});
|
||||
if (trace.getUuid() == ptrace.getUuid() || finalPlayerTraceShowData.hasNoViewFlags()) {
|
||||
trace.render(player, finalPlayerTraceShowData);
|
||||
followerMap.getOrDefault(player, Collections.emptySet()).forEach(follower -> {
|
||||
trace.render(follower, finalPlayerTraceShowData);
|
||||
});
|
||||
} else {
|
||||
trace.hide(player);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -135,6 +135,13 @@ public class TraceRecorder implements Listener {
|
||||
Iterator<TNTPrimed> iter = trackedTNT.getOrDefault(region, Collections.emptyList()).iterator();
|
||||
while (iter.hasNext()) {
|
||||
TNTPrimed tnt = iter.next();
|
||||
if (tnt.isDead()) {
|
||||
iter.remove();
|
||||
tntSpawnRegion.remove(tnt);
|
||||
historyMap.remove(tnt);
|
||||
tntSpawnRegion.remove(tnt);
|
||||
continue;
|
||||
}
|
||||
if (tnt.getFuseTicks() == 80) continue;
|
||||
TNTPoint record = record(tnt, wrappedTrace, Collections.emptyList());
|
||||
if (record == null) {
|
||||
|
||||
+4
@@ -95,4 +95,8 @@ public class PlayerTraceShowData {
|
||||
public void addViewFlag(ViewFlag viewFlag) {
|
||||
viewFlags.put(viewFlag.getClass(), viewFlag);
|
||||
}
|
||||
|
||||
public <T extends ViewFlag> void removeViewFlag(Class<T> clazz) {
|
||||
viewFlags.remove(clazz);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -48,9 +48,9 @@ import static de.steamwar.bausystem.features.util.TNTClickListener.TNT_CLICK_DET
|
||||
*/
|
||||
public class TraceEntity extends RBlockDisplay {
|
||||
|
||||
private static final float TNT_VISUAL_SCALE = 0.98F;
|
||||
private static final float TNT_VISUAL_OFFSET = -TNT_VISUAL_SCALE / 2.0F;
|
||||
private static final Transformation TNT_VISUAL_TRANSFORM = new Transformation(
|
||||
public static final float TNT_VISUAL_SCALE = 0.98F;
|
||||
public static final float TNT_VISUAL_OFFSET = -TNT_VISUAL_SCALE / 2.0F;
|
||||
public static final Transformation TNT_VISUAL_TRANSFORM = new Transformation(
|
||||
new Vector3f(TNT_VISUAL_OFFSET, 0.0F, TNT_VISUAL_OFFSET),
|
||||
new Quaternionf(0, 0, 0, 1),
|
||||
new Vector3f(TNT_VISUAL_SCALE, TNT_VISUAL_SCALE, TNT_VISUAL_SCALE),
|
||||
|
||||
+2
@@ -131,6 +131,7 @@ public abstract class ViewFlag {
|
||||
if (yLocation.distanceSquared(representative.getLocation()) >= 1.0 / 256.0 && yLocation.distanceSquared(previous.getLocation()) >= 1.0 / 256.0) {
|
||||
RBlockDisplay y = new RBlockDisplay(server, yLocation);
|
||||
y.setBlock(Material.WHITE_STAINED_GLASS.createBlockData());
|
||||
y.setTransform(TraceEntity.TNT_VISUAL_TRANSFORM);
|
||||
}
|
||||
|
||||
Location secoundLocation;
|
||||
@@ -143,6 +144,7 @@ public abstract class ViewFlag {
|
||||
if (secoundLocation.distanceSquared(representative.getLocation()) >= 1.0 / 256.0 && secoundLocation.distanceSquared(previous.getLocation()) >= 1.0 / 256.0) {
|
||||
RBlockDisplay second = new RBlockDisplay(server, secoundLocation);
|
||||
second.setBlock(Material.WHITE_STAINED_GLASS.createBlockData());
|
||||
second.setTransform(TraceEntity.TNT_VISUAL_TRANSFORM);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
@@ -51,6 +51,10 @@ public class IsolateFlag extends ViewFlag {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return tntToIsolate.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<TNTPoint> filter(Stream<TNTPoint> records) {
|
||||
if (tntToIsolate.isEmpty()) return records;
|
||||
|
||||
@@ -38,6 +38,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@@ -47,7 +48,6 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -73,19 +73,7 @@ public class BindCommand extends SWCommand implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
private static final CommandMap commandMap;
|
||||
|
||||
static {
|
||||
Field knownCommandsField;
|
||||
try {
|
||||
knownCommandsField = Bukkit.getServer().getClass().getDeclaredField("commandMap");
|
||||
knownCommandsField.setAccessible(true);
|
||||
commandMap = (CommandMap) knownCommandsField.get(Bukkit.getServer());
|
||||
} catch (IllegalAccessException | NoSuchFieldException var2) {
|
||||
Bukkit.shutdown();
|
||||
throw new SecurityException("Oh shit. Commands cannot be registered.", var2);
|
||||
}
|
||||
}
|
||||
private static final CommandMap commandMap = ((CraftServer) Bukkit.getServer()).getCommandMap();
|
||||
|
||||
private static final NamespacedKey KEY = SWUtils.getNamespaceKey("command");
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ package de.steamwar.bausystem.features.util;
|
||||
|
||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import de.steamwar.Reflection;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.features.tpslimit.TPSUtils;
|
||||
import de.steamwar.bausystem.utils.BauMemberUpdateEvent;
|
||||
@@ -30,7 +29,6 @@ import de.steamwar.core.ProtocolWrapper;
|
||||
import de.steamwar.core.SWPlayer;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import net.minecraft.network.protocol.game.*;
|
||||
import net.minecraft.server.level.ServerPlayerGameMode;
|
||||
import net.minecraft.world.entity.player.Abilities;
|
||||
import net.minecraft.world.level.GameType;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -103,10 +101,8 @@ public class NoClipCommand extends SWCommand implements Listener {
|
||||
TinyProtocol.instance.addFilter(ServerboundSetCreativeModeSlotPacket.class, third);
|
||||
}
|
||||
|
||||
private static final Reflection.Field<GameType> playerGameMode = Reflection.getField(ServerPlayerGameMode.class, GameType.class, 0);
|
||||
|
||||
private void setInternalGameMode(Player player, GameMode gameMode) {
|
||||
playerGameMode.set(((CraftPlayer) player).getHandle().gameMode, GameType.byId(gameMode.getValue()));
|
||||
((CraftPlayer) player).getHandle().gameMode.gameModeForPlayer = GameType.byId(gameMode.getValue());
|
||||
}
|
||||
|
||||
@Register(help = true)
|
||||
@@ -143,6 +139,7 @@ public class NoClipCommand extends SWCommand implements Listener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBlock(BlockCanBuildEvent event) {
|
||||
if (event.getPlayer() == null) return;
|
||||
if (SWPlayer.of(event.getPlayer()).hasComponent(NoClipData.class)) {
|
||||
event.setBuildable(true);
|
||||
}
|
||||
|
||||
@@ -36,8 +36,6 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.player.PlayerItemConsumeEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
+1
-1
@@ -25,6 +25,7 @@ import de.steamwar.bausystem.config.BauServer;
|
||||
import de.steamwar.bausystem.utils.BauMemberUpdateEvent;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.sql.BauweltMember;
|
||||
import de.steamwar.techhider.legacy.TechHider;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@@ -39,7 +40,6 @@ import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.entity.EntityPickupItemEvent;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.util.Vector;
|
||||
import de.steamwar.techhider.legacy.TechHider;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@ public class WorldEditListener implements Listener {
|
||||
|
||||
private static final Set<String> commands = new HashSet<>();
|
||||
private static final Set<String> commandExclusions = new HashSet<>();
|
||||
private static final String[] shortcutCommands = {"//1", "//2", "//90", "//-90", "//180", "//p", "//c", "//flopy", "//floppy", "//flopyp", "//floppyp", "//u", "//r"};
|
||||
private static final String[] shortcutCommands = {"//1", "//2", "//90", "//-90", "//180", "//p", "//c", "//flopy", "//floppy", "//flopyp", "//floppyp", "//u", "//r", "//download", "/download"};
|
||||
|
||||
public static boolean isWorldEditCommand(String command) {
|
||||
for (String shortcut : shortcutCommands) {
|
||||
|
||||
@@ -28,6 +28,7 @@ import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.core.CraftbukkitWrapper;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.linkage.LinkedInstance;
|
||||
import de.steamwar.techhider.legacy.TechHider;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
@@ -40,7 +41,6 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import de.steamwar.techhider.legacy.TechHider;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
package de.steamwar.bausystem.utils;
|
||||
|
||||
import de.steamwar.Reflection;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.experimental.UtilityClass;
|
||||
@@ -86,9 +85,6 @@ public class PlaceItemUtils {
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
private static final Reflection.Field<?> positionAccessor = Reflection.getField(CraftBlockState.class, BlockPos.class, 0);
|
||||
private static final Reflection.Field<?> worldAccessor = Reflection.getField(CraftBlockState.class, CraftWorld.class, 0);
|
||||
|
||||
/**
|
||||
* Attempt to place an {@link ItemStack} the {@link Player} is holding against a {@link Block} inside the World.
|
||||
* This can be easily used inside the {@link org.bukkit.event.player.PlayerInteractEvent} to mimik placing a
|
||||
@@ -288,8 +284,9 @@ public class PlaceItemUtils {
|
||||
} else {
|
||||
// If a BlockState is present set the Position and World to the Block you want to place
|
||||
Location blockLocation = block.getLocation();
|
||||
positionAccessor.set(blockState, new BlockPos(blockLocation.getBlockX(), blockLocation.getBlockY(), blockLocation.getBlockZ()));
|
||||
worldAccessor.set(blockState, blockLocation.getWorld());
|
||||
CraftBlockState craftBlockState = (CraftBlockState) blockState;
|
||||
craftBlockState.position = new BlockPos(blockLocation.getBlockX(), blockLocation.getBlockY(), blockLocation.getBlockZ());
|
||||
craftBlockState.world = (CraftWorld) blockLocation.getWorld();
|
||||
}
|
||||
|
||||
if (blockData.getMaterial().isSolid()) {
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
package de.steamwar.bausystem.utils;
|
||||
|
||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||
import de.steamwar.Reflection;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import net.minecraft.network.protocol.game.ClientboundTickingStatePacket;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
@@ -33,7 +32,6 @@ public class TickManager implements Listener {
|
||||
public static final TickManager impl = new TickManager();
|
||||
|
||||
private static final ServerTickRateManager manager = MinecraftServer.getServer().tickRateManager();
|
||||
private static final Reflection.Field<Long> remainingSprintTicks = Reflection.getField(ServerTickRateManager.class, long.class, 0);
|
||||
|
||||
private boolean blockTpsPacket = true;
|
||||
private int totalSteps;
|
||||
@@ -121,7 +119,7 @@ public class TickManager implements Listener {
|
||||
|
||||
public long getRemainingTicks() {
|
||||
if (isSprinting()) {
|
||||
return remainingSprintTicks.get(manager);
|
||||
return manager.remainingSprintTicks;
|
||||
} else {
|
||||
return manager.frozenTicksToRun();
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
package de.steamwar.bausystem.utils;
|
||||
|
||||
import com.fastasyncworldedit.core.regions.selector.PolyhedralRegionSelector;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
@@ -32,16 +33,19 @@ import com.sk89q.worldedit.internal.registry.InputParser;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.*;
|
||||
import com.sk89q.worldedit.regions.selector.limit.SelectorLimits;
|
||||
import de.steamwar.Reflection;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import de.steamwar.bausystem.shared.Pair;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@UtilityClass
|
||||
@@ -91,17 +95,36 @@ public class WorldEditUtils {
|
||||
.getRegionSelector(BukkitAdapter.adapt(player.getWorld()));
|
||||
return new Pair<>(regionSelector.getClass(), regionSelector.getVertices()
|
||||
.stream()
|
||||
.map(blockVector3 -> blockVector3 == null ? null : adapt(player.getWorld(), blockVector3))
|
||||
.map(blockVector3 -> {
|
||||
if (blockVector3 == null) {
|
||||
return null;
|
||||
} else {
|
||||
return BukkitAdapter.adapt(player.getWorld(), blockVector3);
|
||||
}
|
||||
})
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
private static final Map<Class<? extends RegionSelector>, Function<World, RegionSelector>> constructors = new HashMap<>();
|
||||
static {
|
||||
constructors.put(CuboidRegionSelector.class, CuboidRegionSelector::new);
|
||||
constructors.put(ExtendingCuboidRegionSelector.class, ExtendingCuboidRegionSelector::new);
|
||||
constructors.put(Polygonal2DRegionSelector.class, Polygonal2DRegionSelector::new);
|
||||
constructors.put(EllipsoidRegionSelector.class, EllipsoidRegionSelector::new);
|
||||
constructors.put(SphereRegionSelector.class, SphereRegionSelector::new);
|
||||
constructors.put(CylinderRegionSelector.class, CylinderRegionSelector::new);
|
||||
constructors.put(ConvexPolyhedralRegionSelector.class, ConvexPolyhedralRegionSelector::new);
|
||||
constructors.put(PolyhedralRegionSelector.class, PolyhedralRegionSelector::new);
|
||||
}
|
||||
|
||||
public void setVertices(Player player, Class<? extends RegionSelector> clazz, List<Location> vertices) {
|
||||
LocalSession localSession = WorldEdit.getInstance()
|
||||
.getSessionManager()
|
||||
.get(BukkitAdapter.adapt(player));
|
||||
|
||||
Reflection.Constructor constructorInvoker = Reflection.getConstructor(clazz, com.sk89q.worldedit.world.World.class);
|
||||
RegionSelector regionSelector = (RegionSelector) constructorInvoker.invoke(BukkitAdapter.adapt(player.getWorld()));
|
||||
Function<World, RegionSelector> constructor = constructors.get(clazz);
|
||||
if (constructor == null) return;
|
||||
RegionSelector regionSelector = constructor.apply(BukkitAdapter.adapt(player.getWorld()));
|
||||
localSession.setRegionSelector(BukkitAdapter.adapt(player.getWorld()), regionSelector);
|
||||
|
||||
if (vertices.isEmpty()) return;
|
||||
@@ -127,13 +150,9 @@ public class WorldEditUtils {
|
||||
try {
|
||||
BlockVector3 min = regionSelector.getRegion().getMinimumPoint();
|
||||
BlockVector3 max = regionSelector.getRegion().getMaximumPoint();
|
||||
return new Pair<>(adapt(player.getWorld(), min), adapt(player.getWorld(), max));
|
||||
return new Pair<>(BukkitAdapter.adapt(player.getWorld(), min), BukkitAdapter.adapt(player.getWorld(), max));
|
||||
} catch (IncompleteRegionException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Location adapt(World world, BlockVector3 blockVector3) {
|
||||
return new Location(world, blockVector3.getBlockX(), blockVector3.getBlockY(), blockVector3.getBlockZ());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ version: "2.0"
|
||||
depend: [ WorldEdit, SpigotCore ]
|
||||
load: POSTWORLD
|
||||
main: de.steamwar.bausystem.BauSystem
|
||||
api-version: "1.13"
|
||||
api-version: "1.21"
|
||||
website: "https://steamwar.de"
|
||||
description: "So unseriös wie wir sind: BauSystem nur besser."
|
||||
|
||||
|
||||
@@ -37,5 +37,6 @@ tasks.register<DevServer>("DevBau21") {
|
||||
dependsOn(":SpigotCore:shadowJar")
|
||||
dependsOn(":BauSystem:shadowJar")
|
||||
dependsOn(":SchematicSystem:shadowJar")
|
||||
dependsOn(":KotlinCore:shadowJar")
|
||||
template = "Bau21"
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ dependencies {
|
||||
implementation("com.github.ajalt.clikt:clikt:5.0.3")
|
||||
implementation("com.github.ajalt.mordant:mordant:3.0.2")
|
||||
implementation(libs.logback)
|
||||
implementation("org.yaml:snakeyaml:2.2")
|
||||
implementation("org.mariadb.jdbc:mariadb-java-client:3.3.1")
|
||||
|
||||
implementation(libs.exposedCore)
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.github.ajalt.mordant.rendering.TextColors
|
||||
import com.github.ajalt.mordant.rendering.TextStyles
|
||||
import de.steamwar.db.Database
|
||||
import de.steamwar.db.execute
|
||||
import de.steamwar.db.executeScript
|
||||
import de.steamwar.db.useDb
|
||||
import java.io.File
|
||||
|
||||
@@ -22,13 +23,25 @@ class ResetCommand : CliktCommand() {
|
||||
|
||||
val schema = schemaFile.readText()
|
||||
|
||||
val tables = execute("SHOW TABLES;") { it.getString(1) }
|
||||
for (table in tables) {
|
||||
execute("DROP TABLE IF EXISTS $table;") { }
|
||||
execute("SET FOREIGN_KEY_CHECKS=0;") { }
|
||||
|
||||
val databaseObjects = execute("SHOW FULL TABLES;") { it.getString(1) to it.getString(2) }
|
||||
for (view in databaseObjects.filter { it.second == "VIEW" }.map { it.first }) {
|
||||
execute("DROP VIEW IF EXISTS `${view.replace("`", "``")}`;") { }
|
||||
}
|
||||
for (table in databaseObjects.filter { it.second == "BASE TABLE" }.map { it.first }) {
|
||||
execute("DROP TABLE IF EXISTS `${table.replace("`", "``")}`;") { }
|
||||
}
|
||||
|
||||
execute(schema) { }
|
||||
executeScript(schema)
|
||||
|
||||
val seed = javaClass.getResource("/db/reset-seed.sql")
|
||||
?: throw CliktError("Reset seed file not found!")
|
||||
|
||||
executeScript(seed.readText())
|
||||
|
||||
execute("SET FOREIGN_KEY_CHECKS=1;") { }
|
||||
|
||||
echo(TextColors.brightGreen(TextStyles.bold("Database reset!")))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,9 +14,11 @@ import com.github.ajalt.clikt.parameters.types.file
|
||||
import com.github.ajalt.clikt.parameters.types.long
|
||||
import com.github.ajalt.clikt.parameters.types.path
|
||||
import com.sun.security.auth.module.UnixSystem
|
||||
import org.yaml.snakeyaml.Yaml
|
||||
import java.io.File
|
||||
import kotlin.io.path.absolute
|
||||
import kotlin.io.path.absolutePathString
|
||||
import kotlin.random.Random
|
||||
|
||||
const val LOG4J_CONFIG = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="WARN" packages="com.mojang.util">
|
||||
@@ -69,35 +71,47 @@ class DevCommand : CliktCommand("dev") {
|
||||
override fun run() {
|
||||
val args = mutableListOf<String>()
|
||||
|
||||
val serverDirectory = File(workingDir, server)
|
||||
val serverDir =
|
||||
if (serverDirectory.exists() && serverDirectory.isDirectory) serverDirectory else File(workingDir, server)
|
||||
var serverDir = resolveServerDirectory(server)
|
||||
|
||||
if (isVelocity(server)) {
|
||||
runServer(
|
||||
args, jvmArgs, listOf(
|
||||
jar?.absolutePath
|
||||
?: File("/jar/Velocity.jar").absolutePath
|
||||
?: File("/jars/Velocity.jar").absolutePath
|
||||
), serverDir
|
||||
)
|
||||
} else {
|
||||
setLogConfig(args)
|
||||
val version = findVersion(server)
|
||||
?: throw CliktError("Unknown Server Version")
|
||||
val gameModeTemplate = if (serverDir.isDirectory) null else loadGameModeTemplate(server)
|
||||
if (gameModeTemplate != null) {
|
||||
serverDir = gameModeTemplate.serverDir
|
||||
args += "-Dconfig=$server.yml"
|
||||
}
|
||||
val worldFile = world?.absolute()?.toFile()
|
||||
?: File(serverDir, "devtempworld")
|
||||
val jarFile = jar?.absolutePath
|
||||
?: File(workingDir, "devtempworld")
|
||||
var jarFile = jar?.absolutePath
|
||||
?: additionalVersions[server]?.let { supportedVersionJars[it] }
|
||||
?: supportedVersionJars[version]
|
||||
?: throw CliktError("Unknown Server Version")
|
||||
if (gameModeTemplate != null) {
|
||||
jarFile = if (gameModeTemplate.spigot) {
|
||||
jarFile.replace("paper", "spigot")
|
||||
} else {
|
||||
jarFile.replace("spigot", "paper")
|
||||
}
|
||||
}
|
||||
|
||||
if (!worldFile.exists()) {
|
||||
val templateFile = File(serverDir, "Bauwelt")
|
||||
val templateFile = gameModeTemplate?.worldTemplate ?: File(serverDir, "Bauwelt")
|
||||
if (!templateFile.exists()) {
|
||||
throw CliktError("World Template not found!")
|
||||
throw CliktError("Could not find world template: ${templateFile.absolutePath}")
|
||||
}
|
||||
worldFile.parentFile?.mkdirs()
|
||||
templateFile.copyRecursively(worldFile)
|
||||
}
|
||||
val worldDir = worldFile.parentFile ?: workingDir
|
||||
|
||||
val devFile = File("/configs/DevServer/${System.getProperty("user.name")}.$port.$version")
|
||||
if (System.getProperty("user.name") != "minecraft") {
|
||||
@@ -108,10 +122,11 @@ class DevCommand : CliktCommand("dev") {
|
||||
args, jvmArgs, listOf(
|
||||
jarFile,
|
||||
*(if (forceUpgrade) arrayOf("-forceUpgrade") else arrayOf()),
|
||||
"--log-strip-color",
|
||||
"--port", port.toString(),
|
||||
"--level-name", worldFile.name,
|
||||
"--world-dir", workingDir.absolutePath,
|
||||
"--nogui",
|
||||
"--world-dir", worldDir.absolutePath,
|
||||
"nogui",
|
||||
*(if (plugins != null) arrayOf("--plugins", plugins!!.absolutePathString()) else arrayOf())
|
||||
), serverDir
|
||||
)
|
||||
@@ -123,6 +138,12 @@ class DevCommand : CliktCommand("dev") {
|
||||
}
|
||||
}
|
||||
|
||||
data class GameModeTemplate(
|
||||
val serverDir: File,
|
||||
val worldTemplate: File,
|
||||
val spigot: Boolean
|
||||
)
|
||||
|
||||
val jvmDefaultParams = arrayOf(
|
||||
"-Xmx1G",
|
||||
"-Xgc:excessiveGCratio=80",
|
||||
@@ -138,6 +159,16 @@ class DevCommand : CliktCommand("dev") {
|
||||
|
||||
val jvmArgOverrides = arrayOf("--add-opens", "java.base/jdk.internal.misc=ALL-UNNAMED")
|
||||
|
||||
val jvmNonJava8Params = arrayOf(
|
||||
*jvmArgOverrides,
|
||||
"-XX:-CRIUSecProvider"
|
||||
)
|
||||
|
||||
val extendedStartupParams = arrayOf(
|
||||
"-Dpaper.disablePluginRemapping=true",
|
||||
"-javaagent:/jars/AccessWidener.jar=start"
|
||||
)
|
||||
|
||||
val supportedVersionJars = mapOf(
|
||||
8 to "/jars/paper-1.8.8.jar",
|
||||
9 to "/jars/spigot-1.9.4.jar",
|
||||
@@ -152,8 +183,7 @@ class DevCommand : CliktCommand("dev") {
|
||||
)
|
||||
|
||||
val additionalVersions = mapOf(
|
||||
"Tutorial" to 15,
|
||||
"Lobby" to 20
|
||||
"Lobby" to 21
|
||||
)
|
||||
|
||||
fun findVersion(server: String): Int? =
|
||||
@@ -166,6 +196,41 @@ class DevCommand : CliktCommand("dev") {
|
||||
fun isVelocity(server: String): Boolean =
|
||||
server.endsWith("Velocity")
|
||||
|
||||
fun resolveServerDirectory(server: String): File {
|
||||
val localServer = File(workingDir, server)
|
||||
if (localServer.isDirectory) {
|
||||
return localServer
|
||||
}
|
||||
return File("/servers", server)
|
||||
}
|
||||
|
||||
fun loadGameModeTemplate(server: String): GameModeTemplate? {
|
||||
val configFile = File("/configs/GameModes/$server.yml")
|
||||
if (!configFile.exists()) {
|
||||
throw CliktError("Server/GameMode not found")
|
||||
}
|
||||
|
||||
val document = configFile.reader().use { reader ->
|
||||
Yaml().load<Map<String, Any?>>(reader)
|
||||
} ?: throw CliktError("GameMode config is empty: ${configFile.absolutePath}")
|
||||
val serverConfig = document["Server"] as? Map<*, *>
|
||||
?: throw CliktError("GameMode config is missing Server section: ${configFile.absolutePath}")
|
||||
val folder = serverConfig["Folder"] as? String
|
||||
?: throw CliktError("GameMode config is missing Server.Folder: ${configFile.absolutePath}")
|
||||
val maps = (serverConfig["Maps"] as? List<*>)
|
||||
?.filterIsInstance<String>()
|
||||
?.takeIf { it.isNotEmpty() }
|
||||
?: throw CliktError("GameMode config is missing Server.Maps: ${configFile.absolutePath}")
|
||||
|
||||
val serverDir = File("/servers", folder)
|
||||
val worldTemplate = File(File(serverDir, "arenas"), maps[Random.nextInt(maps.size)])
|
||||
return GameModeTemplate(
|
||||
serverDir = serverDir,
|
||||
worldTemplate = worldTemplate,
|
||||
spigot = serverConfig["Spigot"] == true
|
||||
)
|
||||
}
|
||||
|
||||
fun setLogConfig(args: MutableList<String>) {
|
||||
args += "-DlogPath=${workingDir.absolutePath}/logs"
|
||||
args += "-Dlog4j.configurationFile=${log4jConfig.absolutePath}"
|
||||
@@ -176,13 +241,23 @@ class DevCommand : CliktCommand("dev") {
|
||||
}
|
||||
|
||||
fun runServer(args: List<String>, jvmArgs: List<String>, cmd: List<String>, serverDir: File) {
|
||||
val effectiveJvmArgs = mutableListOf<String>()
|
||||
effectiveJvmArgs += jvmArgs
|
||||
if (!isVelocity(server)) {
|
||||
extendedStartupParams.forEach { arg ->
|
||||
if (effectiveJvmArgs.none { it == arg }) {
|
||||
effectiveJvmArgs += arg
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val process = ProcessBuilder(
|
||||
jvm?.absolutePath
|
||||
?: if (isJava8(server)) "/usr/lib/jvm/openj9-8/bin/java" else "java",
|
||||
*jvmArgs.toTypedArray(),
|
||||
?: if (isJava8(server)) "/usr/lib/jvm/openj9-8/bin/java" else "/usr/lib/jvm/openj9-21/bin/java",
|
||||
*effectiveJvmArgs.toTypedArray(),
|
||||
*args.toTypedArray(),
|
||||
*jvmDefaultParams,
|
||||
*(if (isJava8(server)) arrayOf() else jvmArgOverrides),
|
||||
*(if (isJava8(server)) arrayOf() else jvmNonJava8Params),
|
||||
*(if (profile) arrayOf("-javaagent:/jars/LixfelsProfiler.jar=start") else arrayOf()),
|
||||
"-Xshareclasses:nonfatal,name=$server",
|
||||
"-jar",
|
||||
@@ -191,4 +266,4 @@ class DevCommand : CliktCommand("dev") {
|
||||
Runtime.getRuntime().addShutdownHook(Thread { if (process.isAlive) process.destroyForcibly() })
|
||||
process.waitFor()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+120
-9
@@ -16,15 +16,14 @@ import java.sql.ResultSet
|
||||
import java.util.*
|
||||
|
||||
object Database {
|
||||
lateinit var host: String
|
||||
lateinit var port: String
|
||||
lateinit var database: String
|
||||
val host: String
|
||||
val port: String
|
||||
val database: String
|
||||
val username: String
|
||||
val password: String
|
||||
lateinit var db: Database
|
||||
|
||||
fun ensureConnected() {
|
||||
if (::db.isInitialized) {
|
||||
return
|
||||
}
|
||||
init {
|
||||
val config = File(System.getProperty("user.home"), "mysql.properties")
|
||||
|
||||
if (!config.exists()) {
|
||||
@@ -38,9 +37,14 @@ object Database {
|
||||
host = props.getProperty("host")
|
||||
port = props.getProperty("port")
|
||||
database = props.getProperty("database")
|
||||
username = props.getProperty("user")
|
||||
password = props.getProperty("password")
|
||||
}
|
||||
|
||||
val username = props.getProperty("user")
|
||||
val password = props.getProperty("password")
|
||||
fun ensureConnected() {
|
||||
if (::db.isInitialized) {
|
||||
return
|
||||
}
|
||||
|
||||
val url = "jdbc:mariadb://$host:$port/$database"
|
||||
|
||||
@@ -79,6 +83,113 @@ fun <T> JdbcTransaction.executeSingle(sql: String, transform: (ResultSet) -> T):
|
||||
}.single()
|
||||
}
|
||||
|
||||
fun JdbcTransaction.executeScript(sql: String) {
|
||||
for (statement in splitSqlScript(sql)) {
|
||||
exec(statement) { }
|
||||
}
|
||||
}
|
||||
|
||||
private fun splitSqlScript(sql: String): List<String> {
|
||||
val statements = mutableListOf<String>()
|
||||
val current = StringBuilder()
|
||||
var quote: Char? = null
|
||||
var inLineComment = false
|
||||
var inBlockComment = false
|
||||
var index = 0
|
||||
|
||||
fun addStatement() {
|
||||
val statement = current.toString().trim()
|
||||
if (statement.isNotEmpty()) {
|
||||
statements += statement
|
||||
}
|
||||
current.clear()
|
||||
}
|
||||
|
||||
while (index < sql.length) {
|
||||
val char = sql[index]
|
||||
val next = sql.getOrNull(index + 1)
|
||||
|
||||
if (inLineComment) {
|
||||
current.append(char)
|
||||
if (char == '\n') {
|
||||
inLineComment = false
|
||||
}
|
||||
index++
|
||||
continue
|
||||
}
|
||||
|
||||
if (inBlockComment) {
|
||||
current.append(char)
|
||||
if (char == '*' && next == '/') {
|
||||
current.append(next)
|
||||
inBlockComment = false
|
||||
index += 2
|
||||
} else {
|
||||
index++
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if (quote != null) {
|
||||
current.append(char)
|
||||
if (char == '\\' && quote != '`' && next != null) {
|
||||
current.append(next)
|
||||
index += 2
|
||||
continue
|
||||
}
|
||||
if (char == quote) {
|
||||
if (next == quote) {
|
||||
current.append(next)
|
||||
index += 2
|
||||
continue
|
||||
}
|
||||
quote = null
|
||||
}
|
||||
index++
|
||||
continue
|
||||
}
|
||||
|
||||
when {
|
||||
char == '-' && next == '-' -> {
|
||||
current.append(char).append(next)
|
||||
inLineComment = true
|
||||
index += 2
|
||||
}
|
||||
|
||||
char == '#' -> {
|
||||
current.append(char)
|
||||
inLineComment = true
|
||||
index++
|
||||
}
|
||||
|
||||
char == '/' && next == '*' -> {
|
||||
current.append(char).append(next)
|
||||
inBlockComment = true
|
||||
index += 2
|
||||
}
|
||||
|
||||
char == '\'' || char == '"' || char == '`' -> {
|
||||
current.append(char)
|
||||
quote = char
|
||||
index++
|
||||
}
|
||||
|
||||
char == ';' -> {
|
||||
addStatement()
|
||||
index++
|
||||
}
|
||||
|
||||
else -> {
|
||||
current.append(char)
|
||||
index++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addStatement()
|
||||
return statements
|
||||
}
|
||||
|
||||
fun useDb(statement: JdbcTransaction.() -> Unit) {
|
||||
de.steamwar.db.Database.ensureConnected()
|
||||
transaction(de.steamwar.db.Database.db, statement = statement)
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -86,6 +86,24 @@ class CheckedSchematic(id: EntityID<CompositeID>) : CompositeEntity(id) {
|
||||
useDb {
|
||||
find { (CheckedSchematicTable.nodeOwner eq owner.id) and (CheckedSchematicTable.seen eq false) }.orderBy(CheckedSchematicTable.endTime to SortOrder.DESC).toList()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun countAccepted(owner: SteamwarUser) =
|
||||
useDb {
|
||||
find { (CheckedSchematicTable.nodeOwner eq owner.id) and (CheckedSchematicTable.declineReason eq "freigegeben") }.count()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun countAccepted(owner: SteamwarUser, type: String) =
|
||||
useDb {
|
||||
find { (CheckedSchematicTable.nodeOwner eq owner.id) and (CheckedSchematicTable.declineReason eq "freigegeben") and (CheckedSchematicTable.nodeType like "$type%") }.count()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun countChecked(validator: SteamwarUser) =
|
||||
useDb {
|
||||
find { CheckedSchematicTable.validator eq validator.id }.count()
|
||||
}
|
||||
}
|
||||
|
||||
val node by CheckedSchematicTable.nodeId.transform({ it?.let { EntityID(it, SchematicNodeTable) } }, { it?.value })
|
||||
|
||||
@@ -130,6 +130,43 @@ class EventFight(id: EntityID<Int>) : IntEntity(id), Comparable<EventFight> {
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun countEventFights(fighter: SteamwarUser) =
|
||||
useDb {
|
||||
exec(
|
||||
"SELECT COUNT(DISTINCT F.FightID) AS FightCount FROM FightPlayer INNER JOIN Fight F on FightPlayer.FightID = F.FightID INNER JOIN EventFight EF on F.FightID = EF.Fight WHERE UserID = ?",
|
||||
args = listOf(IntegerColumnType() to fighter.id.value)
|
||||
) {
|
||||
if (it.next()) {
|
||||
it.getLong("FightCount")
|
||||
} else {
|
||||
0
|
||||
}
|
||||
}
|
||||
?: 0
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun countPlacement(fighter: SteamwarUser, placement: Int) =
|
||||
useDb {
|
||||
exec(
|
||||
"""
|
||||
SELECT COUNT(DISTINCT EventFight.EventID) AS PlacementCount FROM TeamTeilnahme
|
||||
INNER JOIN EventFight ON EventFight.EventID = TeamTeilnahme.EventID
|
||||
INNER JOIN FightPlayer ON FightPlayer.FightID = EventFight.Fight
|
||||
WHERE (IF(FightPlayer.Team = 1, EventFight.TeamBlue, EventFight.TeamRed)) = TeamTeilnahme.TeamID AND UserID = ? AND Placement = ?
|
||||
""".trimIndent(),
|
||||
args = listOf(IntegerColumnType() to fighter.id.value, IntegerColumnType() to placement)
|
||||
) {
|
||||
if (it.next()) {
|
||||
it.getInt("PlacementCount")
|
||||
} else {
|
||||
0
|
||||
}
|
||||
}
|
||||
?: 0
|
||||
}
|
||||
}
|
||||
|
||||
val fightID by EventFightTable.id.transform({ EntityID(it, EventFightTable) }, { it.value })
|
||||
@@ -200,6 +237,7 @@ class EventFight(id: EntityID<Int>) : IntEntity(id), Comparable<EventFight> {
|
||||
|
||||
override fun delete() =
|
||||
useDb {
|
||||
EventRelation.deleteRelations(this@EventFight)
|
||||
super.delete()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,10 +159,13 @@ class EventGroup(id: EntityID<Int>) : IntEntity(id) {
|
||||
}
|
||||
|
||||
override fun delete() =
|
||||
useDb { super.delete() }
|
||||
useDb {
|
||||
EventRelation.deleteRelations(this@EventGroup)
|
||||
super.delete()
|
||||
}
|
||||
|
||||
enum class EventGroupType {
|
||||
GROUP_STAGE,
|
||||
ELIMINATION_STAGE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,8 +24,10 @@ import org.jetbrains.exposed.v1.core.and
|
||||
import org.jetbrains.exposed.v1.core.dao.id.EntityID
|
||||
import org.jetbrains.exposed.v1.core.dao.id.IntIdTable
|
||||
import org.jetbrains.exposed.v1.core.eq
|
||||
import org.jetbrains.exposed.v1.core.or
|
||||
import org.jetbrains.exposed.v1.dao.IntEntity
|
||||
import org.jetbrains.exposed.v1.dao.IntEntityClass
|
||||
import org.jetbrains.exposed.v1.jdbc.deleteWhere
|
||||
import org.jetbrains.exposed.v1.jdbc.select
|
||||
|
||||
object EventRelationTable : IntIdTable("EventRelation") {
|
||||
@@ -59,6 +61,23 @@ class EventRelation(id: EntityID<Int>) : IntEntity(id) {
|
||||
fun getGroupRelations(group: EventGroup) =
|
||||
useDb { find { (EventRelationTable.fromId eq group.id.value) and (EventRelationTable.fromType eq FromType.GROUP) }.toList() }
|
||||
|
||||
@JvmStatic
|
||||
fun deleteRelations(fight: EventFight) =
|
||||
useDb {
|
||||
EventRelationTable.deleteWhere {
|
||||
(EventRelationTable.fightId eq fight.id) or
|
||||
((EventRelationTable.fromId eq fight.id.value) and (EventRelationTable.fromType eq FromType.FIGHT))
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun deleteRelations(group: EventGroup) =
|
||||
useDb {
|
||||
EventRelationTable.deleteWhere {
|
||||
(EventRelationTable.fromId eq group.id.value) and (EventRelationTable.fromType eq FromType.GROUP)
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun create(fight: EventFight, fightTeam: FightTeam, fromType: FromType, fromId: Int, fromPlace: Int) =
|
||||
useDb {
|
||||
@@ -159,4 +178,4 @@ class EventRelation(id: EntityID<Int>) : IntEntity(id) {
|
||||
enum class FromType {
|
||||
FIGHT, GROUP
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,9 +20,12 @@
|
||||
package de.steamwar.sql
|
||||
|
||||
import de.steamwar.sql.internal.useDb
|
||||
import org.jetbrains.exposed.v1.core.IntegerColumnType
|
||||
import org.jetbrains.exposed.v1.core.VarCharColumnType
|
||||
import org.jetbrains.exposed.v1.core.dao.id.CompositeID
|
||||
import org.jetbrains.exposed.v1.core.dao.id.CompositeIdTable
|
||||
import org.jetbrains.exposed.v1.core.dao.id.EntityID
|
||||
import org.jetbrains.exposed.v1.core.eq
|
||||
import org.jetbrains.exposed.v1.core.inList
|
||||
import org.jetbrains.exposed.v1.dao.CompositeEntity
|
||||
import org.jetbrains.exposed.v1.dao.CompositeEntityClass
|
||||
@@ -69,6 +72,28 @@ class FightPlayer(id: EntityID<CompositeID>) : CompositeEntity(id) {
|
||||
useDb {
|
||||
find { FightPlayerTable.fightId inList fightIds.toList() }.toList()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun countFights(userId: Int) =
|
||||
useDb {
|
||||
find { FightPlayerTable.userId eq userId }.count()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun countFights(userId: Int, type: String) =
|
||||
useDb {
|
||||
exec(
|
||||
"SELECT COUNT(*) AS FightCount FROM FightPlayer INNER JOIN Fight F on FightPlayer.FightID = F.FightID WHERE UserID = ? AND GameMode LIKE ?",
|
||||
args = listOf(IntegerColumnType() to userId, VarCharColumnType() to "$type%")
|
||||
) {
|
||||
if (it.next()) {
|
||||
it.getInt("FightCount")
|
||||
} else {
|
||||
0
|
||||
}
|
||||
}
|
||||
?: 0
|
||||
}
|
||||
}
|
||||
|
||||
val fightID by FightPlayerTable.fightId.transform({ EntityID(it, FightTable) }, { it.value })
|
||||
|
||||
@@ -146,12 +146,12 @@ public final class GameModeConfig<M, W> {
|
||||
public final List<String> CheckQuestions;
|
||||
|
||||
/**
|
||||
* The allowed checkers to check this schematic type denoted by a list of SteamWar ids.
|
||||
* The allowed checkers to check this schematic type denoted by a list of SteamwarUser ids.
|
||||
* The people need the {@link UserPerm#CHECK} to be able to check though.
|
||||
*
|
||||
* @implSpec {@code []} by default -> denoting every person with {@link UserPerm#CHECK} can check it
|
||||
*/
|
||||
public final List<Integer> Checkers;
|
||||
public final Set<Integer> Checkers;
|
||||
|
||||
/**
|
||||
* Bundle for countdowns during the fight
|
||||
@@ -246,7 +246,7 @@ public final class GameModeConfig<M, W> {
|
||||
}
|
||||
|
||||
CheckQuestions = loader.getStringList("CheckQuestions");
|
||||
Checkers = loader.getIntList("Checkers");
|
||||
Checkers = loader.getIntSet("Checkers");
|
||||
Times = new TimesConfig(loader.with("Times"));
|
||||
// Arena would be here to be in config order but needs Schematic.Size and EnterStages loaded afterwards
|
||||
Schematic = new SchematicConfig<>(loader.with("Schematic"));
|
||||
@@ -488,6 +488,27 @@ public final class GameModeConfig<M, W> {
|
||||
*/
|
||||
public final boolean NoFloor;
|
||||
|
||||
/**
|
||||
* Allows Wind Charges to cross the Middle.
|
||||
*
|
||||
* @implSpec {@code false} by default
|
||||
*/
|
||||
public final boolean WindchargesCanCrossMiddle;
|
||||
|
||||
/**
|
||||
* Allows Wind Charge interaction with Blocks.
|
||||
*
|
||||
* @implSpec {@code true} by default
|
||||
*/
|
||||
public final boolean WindchargesInteractWithBlocks;
|
||||
|
||||
/**
|
||||
* Allows Wind Charge to destroy Water.
|
||||
*
|
||||
* @implSpec {@code false} by default
|
||||
*/
|
||||
public final boolean WindchargesDestroyWater;
|
||||
|
||||
private ArenaConfig(YMLWrapper<M, W> loader, SchematicConfig.SizeConfig Size, List<Integer> EnterStages) {
|
||||
loaded = loader.canLoad();
|
||||
WaterDepth = loader.getInt("WaterDepth", 0);
|
||||
@@ -505,6 +526,9 @@ public final class GameModeConfig<M, W> {
|
||||
Leaveable = loader.getBoolean("Leaveable", false);
|
||||
AllowMissiles = loader.getBoolean("AllowMissiles", !EnterStages.isEmpty());
|
||||
NoFloor = loader.getBoolean("NoFloor", false);
|
||||
WindchargesCanCrossMiddle = loader.getBoolean("WindchargesCanCrossMiddle", false);
|
||||
WindchargesInteractWithBlocks = loader.getBoolean("WindchargesInteractWithBlocks", true);
|
||||
WindchargesDestroyWater = loader.getBoolean("WindchargesDestroyWater", false);
|
||||
}
|
||||
|
||||
@ToString
|
||||
@@ -929,6 +953,13 @@ public final class GameModeConfig<M, W> {
|
||||
*/
|
||||
public final boolean PersonalKits;
|
||||
|
||||
/**
|
||||
* Maximal blast resistance for the blocks in the kit
|
||||
*
|
||||
* @implSpec {@code 9.0} by default
|
||||
*/
|
||||
public final double MaxBlastResistance;
|
||||
|
||||
/**
|
||||
* Items (Valid spigot material values) that are not allowed in the personal kit
|
||||
*/
|
||||
@@ -940,7 +971,10 @@ public final class GameModeConfig<M, W> {
|
||||
MemberDefault = loader.getString("MemberDefault", "default");
|
||||
LeaderDefault = loader.getString("LeaderDefault", "default");
|
||||
PersonalKits = loader.getBoolean("PersonalKits", false);
|
||||
ForbiddenItems = loader.getMaterialList("ForbiddenItems");
|
||||
MaxBlastResistance = loader.getDouble("MaxBlastResistance", 9.0);
|
||||
List forbiddenItems = new ArrayList<>(loader.getMaterialList("ForbiddenItems"));
|
||||
forbiddenItems.addAll(SQLWrapper.impl.getMaterialWithGreaterBlastResistance(MaxBlastResistance));
|
||||
ForbiddenItems = Collections.unmodifiableList(forbiddenItems);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -139,6 +139,12 @@ final class YMLWrapper<M, W> {
|
||||
return get(path, o -> (List<Integer>) o);
|
||||
}
|
||||
|
||||
public Set<Integer> getIntSet(String path) {
|
||||
List<Integer> list = get(path, o -> (List<Integer>) o);
|
||||
if (list.isEmpty()) return Collections.emptySet();
|
||||
return Collections.unmodifiableSet(new HashSet<>(list));
|
||||
}
|
||||
|
||||
public List<SchematicType> getSchematicTypeList(String path) {
|
||||
List<String> list = getStringList(path);
|
||||
if (list.isEmpty()) {
|
||||
|
||||
@@ -64,6 +64,10 @@ Arena:
|
||||
AllowMissiles: false # defaults to true if EnterStages are present otherwise 'false'
|
||||
# Denotes that there is no floor for this GameMode
|
||||
NoFloor: false # defaults to false if missing
|
||||
# Allows Wind Charges to cross the Middle.
|
||||
WindchargesCanCrossMiddle: false # defaults to false if missing
|
||||
# Allows Wind Charge interaction with Blocks.
|
||||
WindchargesInteractWithBlocks: false # defaults to false if missing
|
||||
|
||||
Schematic:
|
||||
# The size of the schematics
|
||||
|
||||
@@ -32,7 +32,10 @@ import de.steamwar.fightsystem.record.GlobalRecorder;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.OneShotStateDependent;
|
||||
import de.steamwar.fightsystem.states.StateDependentListener;
|
||||
import de.steamwar.fightsystem.utils.*;
|
||||
import de.steamwar.fightsystem.utils.FightUI;
|
||||
import de.steamwar.fightsystem.utils.HullHider;
|
||||
import de.steamwar.fightsystem.utils.SWSound;
|
||||
import de.steamwar.fightsystem.utils.TechHiderWrapper;
|
||||
import de.steamwar.linkage.AbstractLinker;
|
||||
import de.steamwar.linkage.SpigotLinker;
|
||||
import de.steamwar.message.Message;
|
||||
|
||||
-4
@@ -27,12 +27,9 @@ import de.steamwar.fightsystem.fight.FightPlayer;
|
||||
import de.steamwar.fightsystem.utils.Message;
|
||||
import de.steamwar.fightsystem.utils.Region;
|
||||
import de.steamwar.fightsystem.utils.SWSound;
|
||||
import de.steamwar.techhider.ProtocolUtils;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class EnternCountdown extends Countdown {
|
||||
|
||||
private static int calcTime(FightPlayer fp, Countdown countdown) {
|
||||
@@ -47,7 +44,6 @@ public class EnternCountdown extends Countdown {
|
||||
}
|
||||
|
||||
private final FightPlayer fightPlayer;
|
||||
private List<ProtocolUtils.ChunkPos> chunkPos;
|
||||
|
||||
public EnternCountdown(FightPlayer fp, Countdown countdown) {
|
||||
super(calcTime(fp, countdown), new Message("ENTERN_COUNTDOWN"), SWSound.BLOCK_NOTE_PLING, false);
|
||||
|
||||
@@ -24,6 +24,7 @@ import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.record.GlobalRecorder;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
@@ -88,7 +89,7 @@ public class Fight {
|
||||
}
|
||||
|
||||
public static void playSound(Sound sound, float volume, float pitch) {
|
||||
GlobalRecorder.getInstance().soundAtPlayer(sound.name(), volume, pitch);
|
||||
GlobalRecorder.getInstance().soundAtPlayer(Registry.SOUNDS.getKey(sound).getKey(), volume, pitch);
|
||||
//volume: max. 100, pitch: max. 2
|
||||
Bukkit.getServer().getOnlinePlayers().forEach(player -> player.playSound(player, sound, volume, pitch));
|
||||
}
|
||||
|
||||
@@ -35,7 +35,9 @@ import de.steamwar.fightsystem.listener.TeamArea;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.OneShotStateDependent;
|
||||
import de.steamwar.fightsystem.states.StateDependent;
|
||||
import de.steamwar.fightsystem.utils.*;
|
||||
import de.steamwar.fightsystem.utils.FightUI;
|
||||
import de.steamwar.fightsystem.utils.ItemBuilder;
|
||||
import de.steamwar.fightsystem.utils.Region;
|
||||
import de.steamwar.fightsystem.winconditions.Wincondition;
|
||||
import de.steamwar.fightsystem.winconditions.Winconditions;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
|
||||
@@ -25,6 +25,7 @@ import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentListener;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.sql.GameModeConfig;
|
||||
import de.steamwar.sql.SchematicNode;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import de.steamwar.sql.UserPerm;
|
||||
@@ -44,14 +45,24 @@ public class Check implements Listener {
|
||||
new StateDependentListener(ArenaMode.Check, FightState.All, this);
|
||||
}
|
||||
|
||||
private boolean checkPermission(SteamwarUser user, SchematicNode schematic) {
|
||||
GameModeConfig<Object, String> gameModeConfig = GameModeConfig.getAll().stream()
|
||||
.filter(gmc -> gmc.Schematic.Type != null && gmc.Schematic.Type.equals(schematic.getSchemtype()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if (gameModeConfig == null) gameModeConfig = GameModeConfig.getDefaults();
|
||||
if (user.hasPerm(UserPerm.ADMINISTRATION)) return true;
|
||||
if (gameModeConfig.Checkers.isEmpty() && user.hasPerm(UserPerm.CHECK)) return true;
|
||||
return gameModeConfig.Checkers.contains(user.getId());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
Player player = e.getPlayer();
|
||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
||||
|
||||
if (user.hasPerm(UserPerm.CHECK)) return;
|
||||
|
||||
SchematicNode schem = SchematicNode.getSchematicNode(Config.CheckSchemID);
|
||||
if (checkPermission(user, schem)) return;
|
||||
if (user.getId() == schem.getOwner()) return;
|
||||
|
||||
FightSystem.getMessage().send("CHECK_JOIN_DENIED", player);
|
||||
|
||||
@@ -24,6 +24,7 @@ import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentListener;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
@@ -38,11 +39,13 @@ public class EntityDamage implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void handleEntityDamage(EntityDamageEvent event) {
|
||||
if (!(event.getEntity() instanceof Player)) return;
|
||||
if (Config.ArenaRegion.in2dRegion(event.getEntity().getLocation())) event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void handleEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
||||
if (!(event.getEntity() instanceof Player)) return;
|
||||
if (Config.ArenaRegion.in2dRegion(event.getEntity().getLocation())) event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
-1
@@ -25,7 +25,6 @@ import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentListener;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 SteamWar.de-Serverteam
|
||||
* Copyright (C) 2026 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
|
||||
@@ -31,17 +31,16 @@ import de.steamwar.linkage.Linked;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Tag;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.type.Dispenser;
|
||||
import org.bukkit.block.data.type.DriedGhast;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockDispenseEvent;
|
||||
import org.bukkit.event.block.BlockFromToEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.block.*;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
@@ -258,4 +257,16 @@ public class Permanent implements Listener {
|
||||
event.setCancelled(true);
|
||||
FightSystem.getMessage().sendPrefixless("NO_BLOCK_BREAK", event.getPlayer(), ChatMessageType.ACTION_BAR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents Dried Ghast from spawning and plants from growing
|
||||
*/
|
||||
@EventHandler
|
||||
public void onBlockGrow(BlockGrowEvent event) {
|
||||
var type = event.getBlock().getType();
|
||||
|
||||
if (event.getBlock().getBlockData() instanceof DriedGhast || Tag.CROPS.isTagged(type) || Tag.SAPLINGS.isTagged(type)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
package de.steamwar.fightsystem.listener;
|
||||
|
||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||
import de.steamwar.Reflection;
|
||||
import de.steamwar.fightsystem.ArenaMode;
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
@@ -37,7 +36,6 @@ import de.steamwar.fightsystem.states.StateDependentListener;
|
||||
import de.steamwar.fightsystem.states.StateDependentTask;
|
||||
import de.steamwar.fightsystem.utils.SWSound;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundUseItemPacket;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
@@ -115,18 +113,18 @@ public class Recording implements Listener {
|
||||
}.register();
|
||||
new StateDependent(ArenaMode.AntiReplay, FightState.Ingame) {
|
||||
private final BiFunction<Player, ServerboundUseItemPacket, Object> place = Recording.this::blockPlace;
|
||||
private final BiFunction<Player, Object, Object> dig = Recording.this::blockDig;
|
||||
private final BiFunction<Player, ServerboundPlayerActionPacket, Object> dig = Recording.this::blockDig;
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
TinyProtocol.instance.addFilter(ServerboundUseItemPacket.class, place);
|
||||
TinyProtocol.instance.addFilter(blockDigPacket, dig);
|
||||
TinyProtocol.instance.addFilter(ServerboundPlayerActionPacket.class, dig);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
TinyProtocol.instance.removeFilter(ServerboundUseItemPacket.class, place);
|
||||
TinyProtocol.instance.removeFilter(blockDigPacket, dig);
|
||||
TinyProtocol.instance.removeFilter(ServerboundPlayerActionPacket.class, dig);
|
||||
}
|
||||
}.register();
|
||||
new StateDependentTask(ArenaMode.AntiReplay, FightState.All, () -> {
|
||||
@@ -143,13 +141,8 @@ public class Recording implements Listener {
|
||||
GlobalRecorder.getInstance().entitySpeed(entity);
|
||||
}
|
||||
|
||||
private static final Class<? extends Packet<?>> blockDigPacket = ServerboundPlayerActionPacket.class;
|
||||
private static final Class<?> playerDigType = blockDigPacket.getDeclaredClasses()[0];
|
||||
private static final Reflection.Field<?> blockDigType = Reflection.getField(blockDigPacket, playerDigType, 0);
|
||||
private static final Object releaseUseItem = playerDigType.getEnumConstants()[5];
|
||||
|
||||
private Object blockDig(Player p, Object packet) {
|
||||
if (!isNotSent(p) && blockDigType.get(packet) == releaseUseItem) {
|
||||
private Object blockDig(Player p, ServerboundPlayerActionPacket packet) {
|
||||
if (!isNotSent(p) && packet.getAction() == ServerboundPlayerActionPacket.Action.RELEASE_USE_ITEM) {
|
||||
GlobalRecorder.getInstance().bowSpan(p, false, false);
|
||||
}
|
||||
return packet;
|
||||
|
||||
@@ -72,6 +72,9 @@ public class WaterRemover implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void handleEntityExplode(EntityExplodeEvent event) {
|
||||
if (event.getEntityType() == EntityType.WIND_CHARGE && !Config.GameModeConfig.Arena.WindchargesDestroyWater) {
|
||||
return;
|
||||
}
|
||||
event.setYield(0); //No drops (additionally to world config)
|
||||
|
||||
FightTeam spawn = tnt.remove(event.getEntity().getEntityId());
|
||||
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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.fightsystem.listener;
|
||||
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentListener;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
|
||||
@Linked
|
||||
public class WindchargeInteractionDisabler implements Listener {
|
||||
|
||||
public WindchargeInteractionDisabler() {
|
||||
new StateDependentListener(!Config.GameModeConfig.Arena.WindchargesInteractWithBlocks, FightState.Running, this);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void handleEntityExplode(EntityExplodeEvent event) {
|
||||
if (event.getEntityType() != EntityType.WIND_CHARGE) return;
|
||||
event.blockList().clear();
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -23,14 +23,14 @@ import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentTask;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import net.minecraft.world.entity.projectile.windcharge.WindCharge;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.WindCharge;
|
||||
|
||||
@Linked
|
||||
public class WindchargeStopper {
|
||||
|
||||
public WindchargeStopper() {
|
||||
new StateDependentTask(true, FightState.Running, this::run, 1, 1);
|
||||
new StateDependentTask(!Config.GameModeConfig.Arena.WindchargesCanCrossMiddle, FightState.Running, this::run, 1, 1);
|
||||
}
|
||||
|
||||
private static final int middleLine = Config.SpecSpawn.getBlockZ();
|
||||
@@ -39,13 +39,13 @@ public class WindchargeStopper {
|
||||
|
||||
private void run() {
|
||||
Recording.iterateOverEntities(windChargeClass::isInstance, entity -> {
|
||||
Location nextlocation = entity.getLocation().add(entity.getVelocity());
|
||||
Location location = entity.getLocation();
|
||||
Location prevLocation = location.clone().subtract(entity.getVelocity());
|
||||
|
||||
boolean passedMiddle = location.getBlockZ() > middleLine && prevLocation.getBlockZ() > middleLine ||
|
||||
location.getBlockZ() < middleLine && prevLocation.getBlockZ() < middleLine;
|
||||
boolean passedMiddle = nextlocation.getBlockZ() >= middleLine && location.getBlockZ() <= middleLine ||
|
||||
nextlocation.getBlockZ() <= middleLine && location.getBlockZ() >= middleLine;
|
||||
|
||||
if (!passedMiddle) {
|
||||
if (passedMiddle) {
|
||||
entity.remove();
|
||||
}
|
||||
});
|
||||
|
||||
+11
-5
@@ -34,7 +34,9 @@ import de.steamwar.fightsystem.fight.FightWorld;
|
||||
import de.steamwar.fightsystem.fight.FreezeWorld;
|
||||
import de.steamwar.fightsystem.listener.FightScoreboard;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.utils.*;
|
||||
import de.steamwar.fightsystem.utils.FightUI;
|
||||
import de.steamwar.fightsystem.utils.Message;
|
||||
import de.steamwar.fightsystem.utils.TechHiderWrapper;
|
||||
import de.steamwar.sql.SchematicNode;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import de.steamwar.sql.Team;
|
||||
@@ -510,11 +512,13 @@ public class PacketProcessor implements Listener {
|
||||
float volume = source.readFloat();
|
||||
float pitch = source.readFloat();
|
||||
|
||||
Sound sound = Sound.valueOf(soundName);
|
||||
Sound sound = Registry.SOUNDS.get(NamespacedKey.minecraft(soundName));
|
||||
if (sound == null) sound = Sound.valueOf(soundName); // TODO: Remove in 26.x because of no longer needed backwards compatibility
|
||||
Sound finalSound = sound;
|
||||
|
||||
execSync(() -> {
|
||||
Location location = new Location(Config.world, x, y, z);
|
||||
location.getWorld().playSound(location, sound, SoundCategory.valueOf(soundCategory), volume, pitch);
|
||||
location.getWorld().playSound(location, finalSound, SoundCategory.valueOf(soundCategory), volume, pitch);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -524,9 +528,11 @@ public class PacketProcessor implements Listener {
|
||||
float volume = source.readFloat();
|
||||
float pitch = source.readFloat();
|
||||
|
||||
Sound sound = Sound.valueOf(soundName);
|
||||
Sound sound = Registry.SOUNDS.get(NamespacedKey.minecraft(soundName));
|
||||
if (sound == null) sound = Sound.valueOf(soundName); // TODO: Remove in 26.x because of no longer needed backwards compatibility
|
||||
Sound finalSound = sound;
|
||||
|
||||
execSync(() -> Fight.playSound(sound, volume, pitch));
|
||||
execSync(() -> Fight.playSound(finalSound, volume, pitch));
|
||||
}
|
||||
|
||||
private void pasteSchem(FightTeam team) throws IOException {
|
||||
|
||||
@@ -33,6 +33,7 @@ import de.steamwar.sql.SchematicNode;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.craftbukkit.block.CraftBlockState;
|
||||
import org.bukkit.entity.Entity;
|
||||
@@ -238,7 +239,7 @@ public interface Recorder {
|
||||
}
|
||||
|
||||
default void sound(int x, int y, int z, SWSound soundType, String soundCategory, float volume, float pitch) {
|
||||
write(0x32, x, y, z, soundType.getSound().name(), soundCategory, volume, pitch);
|
||||
write(0x32, x, y, z, Registry.SOUNDS.getKey(soundType.getSound()).getKey(), soundCategory, volume, pitch);
|
||||
}
|
||||
|
||||
default void soundAtPlayer(String soundType, float volume, float pitch) {
|
||||
|
||||
+5
-11
@@ -19,7 +19,6 @@
|
||||
|
||||
package de.steamwar.fightsystem.utils;
|
||||
|
||||
import de.steamwar.Reflection;
|
||||
import de.steamwar.core.CraftbukkitWrapper;
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.events.BoardingEvent;
|
||||
@@ -51,7 +50,7 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -82,18 +81,13 @@ public class TechHiderWrapper extends StateDependent implements Listener {
|
||||
.map(CraftMagicNumbers::getBlock)
|
||||
.collect(Collectors.toUnmodifiableSet());
|
||||
|
||||
Object blockEntityType;
|
||||
try {
|
||||
blockEntityType = BuiltInRegistries.class.getDeclaredField("BLOCK_ENTITY_TYPE").get(null);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
Reflection.Method method = Reflection.getTypedMethod(Reflection.getClass("net.minecraft.core.Registry"), "get", Optional.class, ResourceLocation.class);
|
||||
Set<BlockEntityType<?>> blockEntityTypeToObfuscate = Config.GameModeConfig.Techhider.HiddenBlockEntities.stream()
|
||||
.map((id) -> {
|
||||
.map(id -> {
|
||||
ResourceLocation loc = ResourceLocation.parse(id);
|
||||
return ((Optional<Holder.Reference<BlockEntityType<?>>>) method.invoke(blockEntityType, loc)).get().value();
|
||||
return BuiltInRegistries.BLOCK_ENTITY_TYPE.get(loc).orElse(null);
|
||||
})
|
||||
.filter(Objects::nonNull)
|
||||
.map(Holder.Reference::value)
|
||||
.collect(Collectors.toUnmodifiableSet());
|
||||
|
||||
new TechHider(CraftMagicNumbers.getBlock(Config.GameModeConfig.Techhider.ObfuscateWith), new AccessPrivilegeProvider() {
|
||||
|
||||
@@ -30,16 +30,6 @@ dependencies {
|
||||
implementation(project(":FightSystem:FightSystem_Core"))
|
||||
}
|
||||
|
||||
tasks.register<FightServer>("WarGear20") {
|
||||
group = "run"
|
||||
description = "Run a WarGear 1.20 Fight Server"
|
||||
dependsOn(":SpigotCore:shadowJar")
|
||||
dependsOn(":FightSystem:shadowJar")
|
||||
template = "WarGear20"
|
||||
worldName = "arenas/Pentraki"
|
||||
config = "WarGear20.yml"
|
||||
}
|
||||
|
||||
tasks.register<FightServer>("HalloweenWS") {
|
||||
group = "run"
|
||||
description = "Run a Halloween 1.21 Fight Replay Server"
|
||||
@@ -63,23 +53,3 @@ tasks.register<FightServer>("WarGear21") {
|
||||
config = "WarGear21.yml"
|
||||
jar = "/jars/paper-1.21.6.jar"
|
||||
}
|
||||
|
||||
tasks.register<FightServer>("SpaceCraftDev20") {
|
||||
group = "run"
|
||||
description = "Run a SpaceCraftDev 1.20 Fight Server"
|
||||
dependsOn(":SpigotCore:shadowJar")
|
||||
dependsOn(":FightSystem:shadowJar")
|
||||
template = "SpaceCraft20"
|
||||
worldName = "arenas/AS_Horizon"
|
||||
config = "SpaceCraftDev20.yml"
|
||||
}
|
||||
|
||||
tasks.register<FightServer>("QuickGear20") {
|
||||
group = "run"
|
||||
description = "Run a QuickGear 1.20 Fight Server"
|
||||
dependsOn(":SpigotCore:shadowJar")
|
||||
dependsOn(":FightSystem:shadowJar")
|
||||
template = "QuickGear20"
|
||||
worldName = "arenas/WarGearPark"
|
||||
config = "QuickGear20.yml"
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
@@ -34,6 +36,7 @@ dependencies {
|
||||
compileOnly(libs.paperapi)
|
||||
compileOnly(project(":SpigotCore"))
|
||||
|
||||
implementation(libs.coroutinesCore)
|
||||
implementation(libs.exposedCore)
|
||||
implementation(libs.exposedDao)
|
||||
implementation(libs.exposedJdbc)
|
||||
@@ -41,3 +44,8 @@ dependencies {
|
||||
implementation(libs.mysql)
|
||||
implementation("org.slf4j:slf4j-simple:2.0.17")
|
||||
}
|
||||
val compileKotlin: KotlinCompile by tasks
|
||||
|
||||
compileKotlin.compilerOptions {
|
||||
freeCompilerArgs.set(listOf("-XXLanguage:+ContextParameters"))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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.kotlin.ui
|
||||
|
||||
@DslMarker
|
||||
annotation class RenderMarker()
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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.kotlin.ui
|
||||
|
||||
interface RenderObject {
|
||||
fun destroy()
|
||||
|
||||
fun render()
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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.kotlin.ui
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.ExperimentalForInheritanceCoroutinesApi
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.flow.FlowCollector
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.drop
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
private val uiStateScope = CoroutineScope(SupervisorJob() + Dispatchers.Unconfined)
|
||||
|
||||
context(render: StateFlowListener)
|
||||
fun <T> StateFlow<T>.listen(): StateFlow<T> {
|
||||
render.track(this) {
|
||||
drop(1).onEach { render.update() }.launchIn(uiStateScope)
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
context(render: StateFlowListener)
|
||||
fun <T> MutableStateFlow<T>.listen(): MutableStateFlow<T> {
|
||||
render.track(this) {
|
||||
drop(1).onEach { render.update() }.launchIn(uiStateScope)
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
fun <T> StateFlow<T>.listen(callback: (T) -> Unit): () -> Unit {
|
||||
callback(value)
|
||||
val job = drop(1).onEach { callback(it) }.launchIn(uiStateScope)
|
||||
return { job.cancel() }
|
||||
}
|
||||
|
||||
operator fun <T> StateFlow<T>.getValue(thisRef: Any?, property: KProperty<*>): T = value
|
||||
|
||||
operator fun <T> MutableStateFlow<T>.setValue(thisRef: Any?, property: KProperty<*>, value: T) {
|
||||
this.value = value
|
||||
}
|
||||
|
||||
fun <T, R> StateFlow<T>.map(mapper: (T) -> R): StateFlow<R> = MappedStateFlow(this, mapper)
|
||||
|
||||
@OptIn(ExperimentalForInheritanceCoroutinesApi::class)
|
||||
private class MappedStateFlow<T, R>(
|
||||
private val parent: StateFlow<T>,
|
||||
private val mapper: (T) -> R,
|
||||
): StateFlow<R> {
|
||||
override val replayCache: List<R>
|
||||
get() = listOf(value)
|
||||
|
||||
override val value: R
|
||||
get() = mapper(parent.value)
|
||||
|
||||
override suspend fun collect(collector: FlowCollector<R>): Nothing {
|
||||
var initialized = false
|
||||
var previous: Any? = null
|
||||
|
||||
parent.collect {
|
||||
val mapped = mapper(it)
|
||||
if (!initialized || previous != mapped) {
|
||||
initialized = true
|
||||
previous = mapped
|
||||
collector.emit(mapped)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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.kotlin.ui
|
||||
|
||||
import kotlinx.coroutines.Job
|
||||
|
||||
abstract class StateFlowListener {
|
||||
private val jobs = mutableMapOf<Any, Job>()
|
||||
|
||||
internal fun track(key: Any, createJob: () -> Job) {
|
||||
if (key in jobs) return
|
||||
|
||||
val job = createJob()
|
||||
jobs[key] = job
|
||||
job.invokeOnCompletion { jobs.remove(key) }
|
||||
}
|
||||
|
||||
abstract fun update()
|
||||
|
||||
open fun destroy() {
|
||||
jobs.values.toList().forEach { it.cancel() }
|
||||
jobs.clear()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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.kotlin.ui
|
||||
|
||||
import de.steamwar.kotlin.ui.components.item
|
||||
import de.steamwar.kotlin.util.count
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
val Counter = MutableStateFlow(0)
|
||||
|
||||
class TestInv(player: Player): UIInventory(player) {
|
||||
override fun view() {
|
||||
inventory(3, "") {
|
||||
item {
|
||||
val amount by Counter.map { it + 1 }.listen()
|
||||
item = ItemStack.of(Material.STONE)
|
||||
.count(amount)
|
||||
x = 0
|
||||
y = 0
|
||||
onClick {
|
||||
Counter.value += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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.kotlin.ui
|
||||
|
||||
import de.steamwar.kotlin.ui.context.WindowContext
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.event.inventory.InventoryType
|
||||
|
||||
abstract class UIInventory(val player: Player): StateFlowListener() {
|
||||
var window: UIWindow? = null
|
||||
|
||||
abstract fun view()
|
||||
|
||||
fun open() {
|
||||
if (window == null) {
|
||||
view()
|
||||
assert(window != null) { "View method must create a inventory" }
|
||||
}
|
||||
|
||||
window!!.open()
|
||||
}
|
||||
|
||||
fun render() {
|
||||
window?.onClose()
|
||||
window = null
|
||||
open()
|
||||
}
|
||||
|
||||
override fun update() = render()
|
||||
|
||||
protected fun inventory(size: Int, title: String, init: WindowContext.() -> Unit) {
|
||||
window = UIWindow(size, title, player, init)
|
||||
}
|
||||
|
||||
protected fun inventory(type: InventoryType, title: String, init: WindowContext.() -> Unit) {
|
||||
window = UIWindow(type, title, player, init)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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.kotlin.ui
|
||||
|
||||
import de.steamwar.kotlin.KotlinCore
|
||||
import de.steamwar.kotlin.ui.context.WindowContext
|
||||
import net.kyori.adventure.text.Component
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.Listener
|
||||
import org.bukkit.event.inventory.ClickType
|
||||
import org.bukkit.event.inventory.InventoryClickEvent
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent
|
||||
import org.bukkit.event.inventory.InventoryType
|
||||
import org.bukkit.inventory.Inventory
|
||||
import org.bukkit.inventory.InventoryHolder
|
||||
import org.bukkit.inventory.InventoryView
|
||||
|
||||
class UIWindow(val player: Player, val render: WindowContext.() -> Unit): InventoryHolder {
|
||||
val onClicks = mutableMapOf<Int, (event: InventoryClickEvent) -> Unit>()
|
||||
private var updating = false
|
||||
lateinit var bukkitInv: Inventory
|
||||
private set
|
||||
val context by lazy { WindowContext(this) }
|
||||
|
||||
constructor(size: Int, title: String, player: Player, render: WindowContext.() -> Unit): this(player, render) {
|
||||
bukkitInv = KotlinCore.plugin.server.createInventory(this, size * 9, Component.translatable(title))
|
||||
}
|
||||
|
||||
constructor(type: InventoryType, title: String, player: Player, render: WindowContext.() -> Unit): this(player, render) {
|
||||
assert(type != InventoryType.CHEST) { "Chest inventories should use the constructor with size" }
|
||||
bukkitInv = KotlinCore.plugin.server.createInventory(this, type, Component.translatable(title))
|
||||
}
|
||||
|
||||
fun open() {
|
||||
render(context)
|
||||
player.openInventory(bukkitInv)
|
||||
}
|
||||
|
||||
fun onClose() {
|
||||
if (updating) return
|
||||
|
||||
onClicks.clear()
|
||||
context.destroy()
|
||||
}
|
||||
|
||||
override fun getInventory() = bukkitInv
|
||||
|
||||
companion object : Listener {
|
||||
init {
|
||||
Bukkit.getPluginManager().registerEvents(this, KotlinCore.plugin)
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
fun onInventoryClick(event: InventoryClickEvent) {
|
||||
val window = event.inventory.holder
|
||||
if (window is UIWindow) {
|
||||
event.isCancelled = true
|
||||
|
||||
if (window.context.skipDoubleClick && event.click == ClickType.DOUBLE_CLICK) return
|
||||
window.onClicks[event.slot]?.invoke(event)
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
fun onInventoryClose(event: InventoryCloseEvent) {
|
||||
val window = event.inventory.holder
|
||||
if (window is UIWindow) {
|
||||
window.onClose()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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.kotlin.ui.components
|
||||
|
||||
import de.steamwar.kotlin.ui.StateFlowListener
|
||||
import de.steamwar.kotlin.ui.RenderMarker
|
||||
import de.steamwar.kotlin.ui.RenderObject
|
||||
import de.steamwar.kotlin.ui.context.GroupContext
|
||||
import de.steamwar.kotlin.ui.context.RenderParent
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.event.inventory.InventoryClickEvent
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
@RenderMarker
|
||||
class ItemContext(val parent: RenderParent, val renderFunc: ItemContext.() -> Unit): RenderObject, StateFlowListener() {
|
||||
override fun update() {
|
||||
val oldX = x
|
||||
val oldY = y
|
||||
render()
|
||||
if (oldX != x || oldY != y) {
|
||||
parent.resetSlot(oldX, oldY)
|
||||
}
|
||||
}
|
||||
|
||||
override fun destroy() {
|
||||
super.destroy()
|
||||
parent.resetSlot(x, y)
|
||||
}
|
||||
|
||||
override fun render() {
|
||||
renderFunc(this)
|
||||
parent.renderItem(x, y, item, onClick)
|
||||
}
|
||||
|
||||
init {
|
||||
render()
|
||||
}
|
||||
|
||||
var item: ItemStack = ItemStack.of(Material.AIR)
|
||||
var onClick: (event: InventoryClickEvent) -> Unit = {}
|
||||
var x: Int = 0
|
||||
var y: Int = 0
|
||||
|
||||
fun onClick(func: (event: InventoryClickEvent) -> Unit) {
|
||||
onClick = func
|
||||
}
|
||||
}
|
||||
|
||||
fun GroupContext.item(init: ItemContext.() -> Unit) = children.add(ItemContext(this, init))
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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.kotlin.ui.context
|
||||
|
||||
import de.steamwar.kotlin.ui.StateFlowListener
|
||||
import de.steamwar.kotlin.ui.RenderMarker
|
||||
import de.steamwar.kotlin.ui.RenderObject
|
||||
import org.bukkit.event.inventory.InventoryClickEvent
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
@RenderMarker
|
||||
open class GroupContext(val parent: RenderParent?, val init: GroupContext.() -> Unit): StateFlowListener(), RenderObject, RenderParent {
|
||||
val children = mutableListOf<RenderObject>()
|
||||
val updatedSlots = mutableSetOf<Pair<Int, Int>>()
|
||||
|
||||
override fun update() = render()
|
||||
|
||||
override fun destroy() {
|
||||
children.forEach { it.destroy() }
|
||||
super.destroy()
|
||||
}
|
||||
|
||||
init {
|
||||
init(this)
|
||||
}
|
||||
|
||||
override fun renderItem(x: Int, y: Int, item: ItemStack, onClick: (event: InventoryClickEvent) -> Unit) {
|
||||
updatedSlots.add(x to y)
|
||||
parent?.renderItem(x, y, item, onClick)
|
||||
}
|
||||
|
||||
override fun resetSlot(x: Int, y: Int) {
|
||||
parent?.resetSlot(x, y)
|
||||
}
|
||||
|
||||
fun group(init: GroupContext.() -> Unit) {
|
||||
children.add(GroupContext(this, init))
|
||||
}
|
||||
|
||||
override fun render() {
|
||||
children.forEach { it.destroy() }
|
||||
children.clear()
|
||||
val oldUpdatedSlots = updatedSlots.toList()
|
||||
updatedSlots.clear()
|
||||
init(this)
|
||||
(oldUpdatedSlots - updatedSlots).forEach { resetSlot(it.first, it.second) }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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.kotlin.ui.context
|
||||
|
||||
import org.bukkit.event.inventory.InventoryClickEvent
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
interface RenderParent {
|
||||
fun renderItem(x: Int, y: Int, item: ItemStack, onClick: (event: InventoryClickEvent) -> Unit)
|
||||
|
||||
fun resetSlot(x: Int, y: Int)
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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.kotlin.ui.context
|
||||
|
||||
import de.steamwar.kotlin.ui.RenderMarker
|
||||
import de.steamwar.kotlin.ui.UIWindow
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.event.inventory.InventoryClickEvent
|
||||
import org.bukkit.event.inventory.InventoryType
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
@RenderMarker
|
||||
class WindowContext(val window: UIWindow): GroupContext(null, {}) {
|
||||
override fun renderItem(x: Int, y: Int, item: ItemStack, onClick: (event: InventoryClickEvent) -> Unit) {
|
||||
val slot = calculateSlot(x, y)
|
||||
window.bukkitInv.setItem(slot, item)
|
||||
window.onClicks[slot] = onClick
|
||||
}
|
||||
|
||||
override fun resetSlot(x: Int, y: Int) {
|
||||
val slot = calculateSlot(x, y)
|
||||
window.bukkitInv.setItem(slot, ItemStack.of(Material.AIR))
|
||||
window.onClicks.remove(slot)
|
||||
}
|
||||
|
||||
private fun calculateSlot(x: Int, y: Int) = when (window.inventory.type) {
|
||||
InventoryType.DROPPER, InventoryType.DISPENSER -> x + y * 3
|
||||
InventoryType.HOPPER -> x
|
||||
else -> x + y * 9
|
||||
}
|
||||
|
||||
fun outsideClick(click: (event: InventoryClickEvent) -> Unit) {
|
||||
window.onClicks[-999] = click
|
||||
}
|
||||
|
||||
var skipDoubleClick = true
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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.kotlin.util
|
||||
|
||||
import net.kyori.adventure.text.Component
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.enchantments.Enchantment
|
||||
import org.bukkit.inventory.ItemFlag
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import org.bukkit.inventory.meta.SkullMeta
|
||||
import org.bukkit.inventory.meta.components.CustomModelDataComponent
|
||||
|
||||
fun ItemStack.count(count: Int) = apply { amount = count }
|
||||
|
||||
fun ItemStack.name(name: Component) = apply { itemMeta = itemMeta.also { it.displayName(name) } }
|
||||
|
||||
fun ItemStack.lored(lore: List<Component>) = apply { itemMeta = itemMeta.also { it.lore(lore) } }
|
||||
|
||||
fun String.asMaterial(): Material = Material.matchMaterial(this) ?: Material.BARRIER
|
||||
|
||||
fun skull(owner: String): ItemStack = ItemStack(Material.PLAYER_HEAD)
|
||||
.also {
|
||||
it.editMeta(SkullMeta::class.java) {
|
||||
it.playerProfile = Bukkit.getOfflinePlayer(owner.trimStart('.')).playerProfile.also { pp -> pp.complete() }
|
||||
}
|
||||
}
|
||||
|
||||
fun ItemStack.hideAttributes() = apply { itemMeta = itemMeta.also { it.addItemFlags(*ItemFlag.entries.toTypedArray()) } }
|
||||
|
||||
fun ItemStack.enchanted() = apply { itemMeta = itemMeta.also { it.addEnchant(Enchantment.UNBREAKING, 10, true) } }
|
||||
|
||||
fun ItemStack.customModelData(model: CustomModelDataComponent) = apply { itemMeta = itemMeta.also { it.setCustomModelDataComponent(model) } }
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
plugins {
|
||||
steamwar.java
|
||||
widener
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -32,11 +33,17 @@ dependencies {
|
||||
compileOnly(libs.fawe)
|
||||
}
|
||||
|
||||
tasks.register<DevServer>("DevLobby20") {
|
||||
widener {
|
||||
fromCatalog(libs.nms)
|
||||
fromCatalog(libs.paperapi)
|
||||
}
|
||||
|
||||
tasks.register<DevServer>("DevLobby") {
|
||||
group = "run"
|
||||
description = "Run a 1.20 Dev Lobby"
|
||||
description = "Run a Dev Lobby"
|
||||
dependsOn(":SpigotCore:shadowJar")
|
||||
dependsOn(":KotlinCore:shadowJar")
|
||||
dependsOn(":LobbySystem:jar")
|
||||
template = "Lobby20"
|
||||
template = "Lobby21"
|
||||
worldName = "Lobby"
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
package de.steamwar.lobby.boatrace;
|
||||
|
||||
import de.steamwar.entity.REntity;
|
||||
import de.steamwar.entity.REntityAction;
|
||||
import de.steamwar.entity.REntityServer;
|
||||
import de.steamwar.entity.RInteraction;
|
||||
import de.steamwar.lobby.LobbySystem;
|
||||
@@ -36,6 +35,7 @@ import org.bukkit.entity.Boat;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.boat.*;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
@@ -44,6 +44,7 @@ import org.bukkit.event.vehicle.VehicleMoveEvent;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.EventListener;
|
||||
import java.util.Random;
|
||||
|
||||
import static de.steamwar.lobby.util.LeaderboardManager.renderTime;
|
||||
|
||||
@@ -61,11 +62,11 @@ public class BoatRace implements EventListener, Listener {
|
||||
static {
|
||||
boatNpcServer = new REntityServer();
|
||||
new REntity(boatNpcServer, EntityType.VILLAGER, BoatRacePositions.NPC);
|
||||
RInteraction interaction = new RInteraction(boatNpcServer, BoatRacePositions.NPC.clone().subtract(0.5, 0, 0.5));
|
||||
RInteraction interaction = new RInteraction(boatNpcServer, BoatRacePositions.NPC.clone());
|
||||
interaction.setInteractionHeight(1.95f);
|
||||
interaction.setCallback((player, entity, action) -> {
|
||||
Bukkit.getWorlds().get(0).getEntities().stream().filter(e -> e.getType() == EntityType.END_CRYSTAL).forEach(Entity::remove);
|
||||
if (action == REntityAction.INTERACT && !oneNotStarted) {
|
||||
if (!oneNotStarted) {
|
||||
oneNotStarted = true;
|
||||
new BoatRace(player);
|
||||
}
|
||||
@@ -153,10 +154,24 @@ public class BoatRace implements EventListener, Listener {
|
||||
oneNotStarted = false;
|
||||
}
|
||||
|
||||
private final Class<? extends Boat>[] boatClasses = new Class[]{
|
||||
AcaciaBoat.class,
|
||||
BambooRaft.class,
|
||||
BirchBoat.class,
|
||||
CherryBoat.class,
|
||||
DarkOakBoat.class,
|
||||
JungleBoat.class,
|
||||
MangroveBoat.class,
|
||||
OakBoat.class,
|
||||
PaleOakBoat.class,
|
||||
SpruceBoat.class,
|
||||
};
|
||||
|
||||
private final Random random = new Random();
|
||||
|
||||
public BoatRace(Player player) {
|
||||
this.player = player;
|
||||
boat = Bukkit.getWorlds().get(0).spawn(BoatRacePositions.START, Boat.class);
|
||||
// boat.setBoatType(Boat.Type.values()[new Random().nextInt(Boat.Type.values().length)]);
|
||||
boat = Bukkit.getWorlds().get(0).spawn(BoatRacePositions.START, boatClasses[random.nextInt(boatClasses.length)]);
|
||||
boat.addPassenger(player);
|
||||
bossBar = Bukkit.createBossBar("", BarColor.BLUE, BarStyle.SOLID);
|
||||
task = Bukkit.getScheduler().runTaskTimer(LobbySystem.getInstance(), () -> {
|
||||
|
||||
@@ -42,7 +42,7 @@ public class ColorInit {
|
||||
if (inputStream == null) {
|
||||
colors = new byte[256 * 256 * 256];
|
||||
for (int i = 0; i < colors.length; i++) {
|
||||
colors[i] = MapPalette.matchColor(new Color(i));
|
||||
colors[i] = matchColor(new Color(i));
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
@@ -57,4 +57,26 @@ public class ColorInit {
|
||||
}
|
||||
System.out.println("[ColorInit] Initialization took " + (System.currentTimeMillis() - time) + "ms");
|
||||
}
|
||||
|
||||
public static byte matchColor(Color color) {
|
||||
if (color.getAlpha() < 128) return 0;
|
||||
|
||||
if (MapPalette.mapColorCache != null && MapPalette.mapColorCache.isCached()) {
|
||||
return MapPalette.mapColorCache.matchColor(color);
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
double best = -1;
|
||||
|
||||
for (int i = 4; i < MapPalette.colors.length; i++) {
|
||||
double distance = MapPalette.getDistance(color, MapPalette.colors[i]);
|
||||
if (distance < best || best == -1) {
|
||||
best = distance;
|
||||
index = i;
|
||||
}
|
||||
}
|
||||
|
||||
// Minecraft has 248 colors, some of which have negative byte representations
|
||||
return (byte) (index < 128 ? index : -129 + (index - 127));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,10 @@ import java.awt.image.BufferedImage;
|
||||
import java.awt.image.WritableRaster;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.Month;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public class CustomMap implements Listener {
|
||||
|
||||
@@ -56,7 +59,7 @@ public class CustomMap implements Listener {
|
||||
new Vector(2346, 45, 1297), new Vector(2345, 45, 1297), new Vector(2344, 45, 1297), new Vector(2343, 45, 1297), new Vector(2342, 45, 1297), new Vector(2341, 45, 1297), new Vector(2340, 45, 1297)
|
||||
);
|
||||
|
||||
private static final CustomMap RIGHT = new CustomMap(new File(System.getProperty("user.home") + "/lobbyBanner/right.png"),
|
||||
private static final CustomMap RIGHT = new CustomMap(new File(System.getProperty("user.home") + "/lobbyBanner/right/"),
|
||||
new Vector(2330, 48, 1297), new Vector(2329, 48, 1297), new Vector(2328, 48, 1297), new Vector(2327, 48, 1297), new Vector(2326, 48, 1297), new Vector(2325, 48, 1297), new Vector(2324, 48, 1297),
|
||||
new Vector(2330, 47, 1297), new Vector(2329, 47, 1297), new Vector(2328, 47, 1297), new Vector(2327, 47, 1297), new Vector(2326, 47, 1297), new Vector(2325, 47, 1297), new Vector(2324, 47, 1297),
|
||||
new Vector(2330, 46, 1297), new Vector(2329, 46, 1297), new Vector(2328, 46, 1297), new Vector(2327, 46, 1297), new Vector(2326, 46, 1297), new Vector(2325, 46, 1297), new Vector(2324, 46, 1297),
|
||||
@@ -66,32 +69,51 @@ public class CustomMap implements Listener {
|
||||
private File mapFile;
|
||||
private Map<Vector, Integer> itemFrameIndex = new HashMap<>();
|
||||
private ItemFrame[] itemFrames;
|
||||
private long lastModified = Long.MAX_VALUE;
|
||||
private boolean update = true;
|
||||
|
||||
public CustomMap(File mapFile, Vector... itemFrames) {
|
||||
this.mapFile = mapFile;
|
||||
public CustomMap(File mapFileOrDirectory, Vector... itemFrames) {
|
||||
this.mapFile = mapFileOrDirectory;
|
||||
this.itemFrames = new ItemFrame[itemFrames.length];
|
||||
for (int i = 0; i < itemFrames.length; i++) {
|
||||
itemFrameIndex.put(itemFrames[i], i);
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().runTaskTimer(LobbySystem.getInstance(), () -> {
|
||||
long modified = mapFile.lastModified();
|
||||
if (modified > lastModified) {
|
||||
lastModified = modified;
|
||||
System.out.println("Updating Banner: " + mapFile.getName());
|
||||
Bukkit.getScheduler().runTaskAsynchronously(LobbySystem.getInstance(), () -> {
|
||||
try {
|
||||
run();
|
||||
} catch (IOException e) {
|
||||
// Ignore
|
||||
}
|
||||
});
|
||||
}
|
||||
}, 200L, 200L);
|
||||
if (mapFileOrDirectory.isDirectory()) {
|
||||
AtomicReference<Month> lastMonth = new AtomicReference<>(LocalDateTime.now().getMonth());
|
||||
Bukkit.getScheduler().runTaskTimer(LobbySystem.getInstance(), () -> {
|
||||
Month current = LocalDateTime.now().getMonth();
|
||||
if (!current.equals(lastMonth.get()) || update) {
|
||||
lastMonth.set(current);
|
||||
update = false;
|
||||
this.mapFile = new File(mapFileOrDirectory, current.getValue() + ".png");
|
||||
update();
|
||||
}
|
||||
}, 200L, 1200L);
|
||||
} else {
|
||||
AtomicReference<Long> lastModified = new AtomicReference<>(Long.MAX_VALUE);
|
||||
Bukkit.getScheduler().runTaskTimer(LobbySystem.getInstance(), () -> {
|
||||
long modified = mapFileOrDirectory.lastModified();
|
||||
if (modified > lastModified.get() || update) {
|
||||
lastModified.set(modified);
|
||||
update = false;
|
||||
update();
|
||||
}
|
||||
}, 200L, 200L);
|
||||
}
|
||||
Bukkit.getPluginManager().registerEvents(this, LobbySystem.getInstance());
|
||||
}
|
||||
|
||||
private void update() {
|
||||
System.out.println("Updating Banner: " + mapFile.getName());
|
||||
Bukkit.getScheduler().runTaskAsynchronously(LobbySystem.getInstance(), () -> {
|
||||
try {
|
||||
run();
|
||||
} catch (IOException e) {
|
||||
// Ignore
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onChunkLoad(ChunkLoadEvent event) {
|
||||
for (Entity entity : event.getChunk().getEntities()) {
|
||||
@@ -101,7 +123,7 @@ public class CustomMap implements Listener {
|
||||
if (itemFrameIndex.containsKey(vector)) {
|
||||
if (itemFrames[itemFrameIndex.get(vector)] != null) continue;
|
||||
itemFrames[itemFrameIndex.get(vector)] = itemFrame;
|
||||
lastModified = 0;
|
||||
update = true;
|
||||
|
||||
ItemStack itemStack = new ItemStack(Material.FILLED_MAP, 1);
|
||||
MapMeta mapMeta = (MapMeta) itemStack.getItemMeta();
|
||||
@@ -254,7 +276,8 @@ public class CustomMap implements Listener {
|
||||
int green = pixels[i2];
|
||||
int i3 = (y * width + x) * numBands + 2;
|
||||
int blue = pixels[i3];
|
||||
Color nearest = MapPalette.getColor(ColorInit.getColorByte(red, green, blue));
|
||||
int colorIndex = ColorInit.getColorByte(red, green, blue);
|
||||
Color nearest = MapPalette.colors[colorIndex >= 0 ? colorIndex : colorIndex + 256];
|
||||
|
||||
pixels[(y * width + x) * numBands] = nearest.getRed();
|
||||
pixels[i2] = nearest.getGreen();
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
accessWidener v2 named
|
||||
|
||||
# For CustomMap and ColorInit
|
||||
accessible field org/bukkit/map/MapPalette colors [Ljava/awt/Color;
|
||||
accessible method org/bukkit/map/MapPalette getDistance (Ljava/awt/Color;Ljava/awt/Color;)D
|
||||
accessible field org/bukkit/map/MapPalette mapColorCache Lorg/bukkit/map/MapPalette$MapColorCache;
|
||||
@@ -29,5 +29,15 @@ dependencies {
|
||||
compileOnly(libs.paperapi)
|
||||
|
||||
compileOnly(libs.nms)
|
||||
compileOnly(libs.worldedit)
|
||||
compileOnly(libs.fawe)
|
||||
}
|
||||
|
||||
tasks.register<FightServer>("MissileWars21") {
|
||||
group = "run"
|
||||
description = "Run a 1.21 Dev MissileWars"
|
||||
dependsOn(":SpigotCore:shadowJar")
|
||||
dependsOn(":MissileWars:jar")
|
||||
template = "MissileWars"
|
||||
worldName = "Great_Wall"
|
||||
jar = "/jars/paper-1.21.6.jar"
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@ import com.sk89q.worldedit.function.operation.Operations;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.transform.AffineTransform;
|
||||
import com.sk89q.worldedit.session.ClipboardHolder;
|
||||
import com.sk89q.worldedit.util.SideEffect;
|
||||
import com.sk89q.worldedit.util.SideEffectSet;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import de.steamwar.misslewars.MissileWars;
|
||||
@@ -109,11 +111,17 @@ public class Missile extends SpecialItem {
|
||||
v = aT.apply(v.toVector3()).toBlockPoint();
|
||||
v = v.add(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
|
||||
EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1);
|
||||
EditSession e = WorldEdit.getInstance().getEditSessionFactory()
|
||||
.getEditSession(world, -1);
|
||||
e.setSideEffectApplier(SideEffectSet.defaults()
|
||||
.with(SideEffect.NEIGHBORS, SideEffect.State.ON)
|
||||
.with(SideEffect.LIGHTING, SideEffect.State.ON)
|
||||
.with(SideEffect.UPDATE, SideEffect.State.ON));
|
||||
ClipboardHolder ch = new ClipboardHolder(clipboard);
|
||||
ch.setTransform(aT);
|
||||
Operations.completeBlindly(ch.createPaste(e).to(v).ignoreAirBlocks(true).build());
|
||||
e.flushSession();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,9 +20,12 @@
|
||||
package de.steamwar.misslewars.slowmo;
|
||||
|
||||
import de.steamwar.misslewars.MissileWars;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.TickRateManager;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class SlowMoRunner {
|
||||
private static TickRateManager tickRateManager = MinecraftServer.getServer().tickRateManager();
|
||||
|
||||
private static long currentTime = 0;
|
||||
private static long current = 0;
|
||||
@@ -40,14 +43,14 @@ public class SlowMoRunner {
|
||||
if (currentTime > 0) {
|
||||
current += 1;
|
||||
if (current % 5 == 0) {
|
||||
SlowMoUtils.unfreeze();
|
||||
tickRateManager.setFrozen(false);
|
||||
current = 0;
|
||||
} else {
|
||||
SlowMoUtils.freeze();
|
||||
tickRateManager.setFrozen(true);
|
||||
}
|
||||
currentTime--;
|
||||
} else {
|
||||
SlowMoUtils.unfreeze();
|
||||
tickRateManager.setFrozen(false);
|
||||
}
|
||||
}, 0, 1);
|
||||
}
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 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.misslewars.slowmo;
|
||||
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class SlowMoUtils {
|
||||
|
||||
private static final Field field;
|
||||
public static final boolean freezeEnabled;
|
||||
|
||||
private static boolean frozen = false;
|
||||
|
||||
private static final World world;
|
||||
|
||||
static {
|
||||
Field temp;
|
||||
try {
|
||||
temp = ServerLevel.class.getField("freezed");
|
||||
} catch (NoSuchFieldException e) {
|
||||
temp = null;
|
||||
}
|
||||
field = temp;
|
||||
if (field != null) field.setAccessible(true);
|
||||
freezeEnabled = field != null;
|
||||
world = Bukkit.getWorlds().get(0);
|
||||
}
|
||||
|
||||
public static void freeze() {
|
||||
setFreeze(world, true);
|
||||
}
|
||||
|
||||
public static void unfreeze() {
|
||||
setFreeze(world, false);
|
||||
}
|
||||
|
||||
public static boolean frozen() {
|
||||
return freezeEnabled && frozen;
|
||||
}
|
||||
|
||||
private static void setFreeze(World world, boolean state) {
|
||||
if (freezeEnabled) {
|
||||
if (frozen == state) return;
|
||||
try {
|
||||
field.set(((CraftWorld) world).getHandle(), state);
|
||||
frozen = state;
|
||||
} catch (IllegalAccessException e) {
|
||||
// Ignored;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,40 +37,55 @@ public class AutoChecker {
|
||||
public static final AutoChecker impl = new AutoChecker();
|
||||
|
||||
public AutoCheckerResult check(Clipboard clipboard, GameModeConfig<Material, String> type) {
|
||||
return AutoCheckerResult.builder().type(type).height(clipboard.getDimensions().getBlockY()).width(clipboard.getDimensions().getBlockX())
|
||||
.depth(clipboard.getDimensions().getBlockZ()).blockScanResult(scan(clipboard, type))
|
||||
.entities(clipboard.getEntities().stream().map(Entity::getLocation)
|
||||
.map(blockVector3 -> new BlockPos(blockVector3.getBlockX(), blockVector3.getBlockY(), blockVector3.getBlockZ()))
|
||||
.collect(Collectors.toList()))
|
||||
return AutoCheckerResult.builder()
|
||||
.type(type)
|
||||
.height(clipboard.getDimensions().y())
|
||||
.width(clipboard.getDimensions().x())
|
||||
.depth(clipboard.getDimensions().z())
|
||||
.blockScanResult(scan(clipboard, type))
|
||||
.entities(
|
||||
clipboard.getEntities().stream()
|
||||
.map(Entity::getLocation)
|
||||
.map(blockVector3 -> new BlockPos(blockVector3.getBlockX(), blockVector3.getBlockY(), blockVector3.getBlockZ()))
|
||||
.collect(Collectors.toList()))
|
||||
.build();
|
||||
}
|
||||
|
||||
public AutoCheckerResult sizeCheck(Clipboard clipboard, GameModeConfig<Material, String> type) {
|
||||
return AutoCheckerResult.builder().type(type).height(clipboard.getDimensions().getBlockY()).width(clipboard.getDimensions().getBlockX())
|
||||
.depth(clipboard.getDimensions().getBlockZ()).build();
|
||||
return AutoCheckerResult.builder()
|
||||
.type(type)
|
||||
.height(clipboard.getDimensions().y())
|
||||
.width(clipboard.getDimensions().x())
|
||||
.depth(clipboard.getDimensions().z())
|
||||
.build();
|
||||
}
|
||||
|
||||
public AutoChecker.BlockScanResult scan(Clipboard clipboard, GameModeConfig<Material, String> type) {
|
||||
AutoChecker.BlockScanResult result = new AutoChecker.BlockScanResult();
|
||||
BlockVector3 min = clipboard.getMinimumPoint();
|
||||
BlockVector3 max = clipboard.getMaximumPoint();
|
||||
for (int x = min.getBlockX(); x <= max.getBlockX(); x++) {
|
||||
for (int y = min.getBlockY(); y <= max.getBlockY(); y++) {
|
||||
for (int z = min.getBlockZ(); z <= max.getBlockZ(); z++) {
|
||||
for (int x = min.x(); x <= max.x(); x++) {
|
||||
for (int y = min.y(); y <= max.y(); y++) {
|
||||
for (int z = min.z(); z <= max.z(); z++) {
|
||||
final BaseBlock block = clipboard.getFullBlock(BlockVector3.at(x, y, z));
|
||||
final Material material = Material.matchMaterial(block.getBlockType().getId());
|
||||
final Material material = Material.matchMaterial(block.getBlockType().id());
|
||||
if (material == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
result.getBlockCounts().merge(material, 1, Integer::sum);
|
||||
BlockPos pos = new BlockPos(x, y, z);
|
||||
|
||||
if (AutoCheckerItems.impl.getInventoryMaterials().contains(material)) {
|
||||
checkInventory(result, block, material, new BlockPos(x, y, z), type);
|
||||
checkInventory(result, block, material, pos, type);
|
||||
if (result.getDispenserItems().getOrDefault(pos, 0) > 0) {
|
||||
result.getBlockCounts().merge(material, 1, Integer::sum);
|
||||
}
|
||||
} else {
|
||||
result.getBlockCounts().merge(material, 1, Integer::sum);
|
||||
}
|
||||
|
||||
if (x == min.getBlockX() || x == max.getBlockX() || y == max.getBlockY() || z == min.getBlockZ() || z == max.getBlockZ()) {
|
||||
result.getDesignBlocks().computeIfAbsent(material, m -> new ArrayList<>()).add(new BlockPos(x, y, z));
|
||||
if (x == min.x() || x == max.x() || y == max.y() || z == min.z() || z == max.z()) {
|
||||
result.getDesignBlocks().computeIfAbsent(material, m -> new ArrayList<>()).add(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -245,12 +245,12 @@ public class SchematicCommand extends SWCommand {
|
||||
BlockState replaceType = Objects.requireNonNull(toReplace.contains(Material.END_STONE) ? BlockTypes.IRON_BLOCK : BlockTypes.END_STONE).getDefaultState();
|
||||
BlockVector3 min = clipboard.getMinimumPoint();
|
||||
BlockVector3 max = clipboard.getMaximumPoint();
|
||||
for (int i = min.getBlockX(); i <= max.getBlockX(); i++) {
|
||||
for (int j = min.getBlockY(); j <= max.getBlockY(); j++) {
|
||||
for (int k = min.getBlockZ(); k <= max.getBlockZ(); k++) {
|
||||
for (int i = min.x(); i <= max.x(); i++) {
|
||||
for (int j = min.y(); j <= max.y(); j++) {
|
||||
for (int k = min.z(); k <= max.z(); k++) {
|
||||
BlockVector3 vector = BlockVector3.at(i, j, k);
|
||||
BaseBlock block = clipboard.getFullBlock(vector);
|
||||
if (toReplace.contains(Material.matchMaterial(block.getBlockType().getId()))) {
|
||||
if (toReplace.contains(Material.matchMaterial(block.getBlockType().id()))) {
|
||||
clipboard.setBlock(vector, replaceType.toBaseBlock());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
plugins {
|
||||
steamwar.java
|
||||
widener
|
||||
}
|
||||
|
||||
tasks.compileJava {
|
||||
@@ -58,6 +59,8 @@ dependencies {
|
||||
compileOnly(libs.netty)
|
||||
compileOnly(libs.brigadier)
|
||||
compileOnly(libs.fastutil)
|
||||
|
||||
implementation(libs.anvilgui)
|
||||
}
|
||||
|
||||
widener {
|
||||
fromCatalog(libs.nms)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.comphenix.tinyprotocol;
|
||||
|
||||
import com.google.common.collect.MapMaker;
|
||||
import de.steamwar.Reflection;
|
||||
import de.steamwar.core.CRIUWakeupEvent;
|
||||
import de.steamwar.core.Core;
|
||||
import io.netty.channel.*;
|
||||
@@ -180,22 +179,12 @@ public class TinyProtocol {
|
||||
networkManagers = serverConnection.getConnections();
|
||||
// We need to synchronize against this list
|
||||
createServerChannelHandler();
|
||||
for (ChannelFuture item : serverConnection.channels) {
|
||||
// Channel future that contains the server connection
|
||||
Channel serverChannel = item.channel();
|
||||
|
||||
// Find the correct list, or implicitly throw an exception
|
||||
boolean looking = true;
|
||||
for (int i = 0; looking; i++) {
|
||||
List<Object> list = Reflection.getField(serverConnection.getClass(), List.class, i).get(serverConnection);
|
||||
|
||||
for (Object item : list) {
|
||||
if (!(item instanceof ChannelFuture)) break;
|
||||
|
||||
// Channel future that contains the server connection
|
||||
Channel serverChannel = ((ChannelFuture) item).channel();
|
||||
|
||||
serverChannels.add(serverChannel);
|
||||
serverChannel.pipeline().addFirst(serverChannelHandler);
|
||||
looking = false;
|
||||
}
|
||||
serverChannels.add(serverChannel);
|
||||
serverChannel.pipeline().addFirst(serverChannelHandler);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,315 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 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;
|
||||
|
||||
import de.steamwar.core.Core;
|
||||
import jdk.internal.misc.Unsafe;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@UtilityClass
|
||||
public final class Reflection {
|
||||
|
||||
public static final int MAJOR_VERSION;
|
||||
public static final int MINOR_VERSION;
|
||||
|
||||
static {
|
||||
String[] version = Bukkit.getServer().getBukkitVersion().split("-")[0].split("\\.");
|
||||
MAJOR_VERSION = Integer.parseInt(version[1]);
|
||||
MINOR_VERSION = version.length > 2 ? Integer.parseInt(version[2]) : 0;
|
||||
}
|
||||
|
||||
private static final String ORG_BUKKIT_CRAFTBUKKIT = Bukkit.getServer().getClass().getPackage().getName();
|
||||
public static final String LEGACY_NET_MINECRAFT_SERVER = ORG_BUKKIT_CRAFTBUKKIT.replace("org.bukkit.craftbukkit", "net.minecraft.server");
|
||||
|
||||
private static final Map<String, String> spigotClassnames = new HashMap<>();
|
||||
|
||||
static {
|
||||
// See https://mappings.dev for complete mappings
|
||||
spigotClassnames.put("net.minecraft.Util", "net.minecraft.SystemUtils");
|
||||
|
||||
spigotClassnames.put("net.minecraft.core.BlockPos", "net.minecraft.core.BlockPosition");
|
||||
spigotClassnames.put("net.minecraft.core.DefaultedRegistry", "net.minecraft.core.RegistryBlocks");
|
||||
spigotClassnames.put("net.minecraft.core.IdMapper", "net.minecraft.core.RegistryBlockID");
|
||||
spigotClassnames.put("net.minecraft.core.Vec3i", "net.minecraft.core.BaseBlockPosition");
|
||||
|
||||
spigotClassnames.put("net.minecraft.nbt.CompoundTag", "net.minecraft.nbt.NBTTagCompound");
|
||||
|
||||
spigotClassnames.put("net.minecraft.network.Connection", "net.minecraft.network.NetworkManager");
|
||||
|
||||
spigotClassnames.put("net.minecraft.network.chat.Component", "net.minecraft.network.chat.IChatBaseComponent");
|
||||
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundAddEntityPacket", "net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundAddPlayerPacket", "net.minecraft.network.protocol.game.PacketPlayOutNamedEntitySpawn");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundAnimatePacket", "net.minecraft.network.protocol.game.PacketPlayOutAnimation");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundBlockDestructionPacket", "net.minecraft.network.protocol.game.PacketPlayOutBlockBreak");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket", "net.minecraft.network.protocol.game.PacketPlayOutTileEntityData");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundBlockEventPacket", "net.minecraft.network.protocol.game.PacketPlayOutBlockAction");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket", "net.minecraft.network.protocol.game.PacketPlayOutBlockChange");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundContainerClosePacket", "net.minecraft.network.protocol.game.PacketPlayOutCloseWindow");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundEntityEventPacket", "net.minecraft.network.protocol.game.PacketPlayOutEntityStatus");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundExplodePacket", "net.minecraft.network.protocol.game.PacketPlayOutExplosion");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundGameEventPacket", "net.minecraft.network.protocol.game.PacketPlayOutGameStateChange");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData$BlockEntityInfo", "net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData$a");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundLevelEventPacket", "net.minecraft.network.protocol.game.PacketPlayOutWorldEvent");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundLevelParticlesPacket", "net.minecraft.network.protocol.game.PacketPlayOutWorldParticles");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundMoveEntityPacket", "net.minecraft.network.protocol.game.PacketPlayOutEntity");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundMoveEntityPacket$Pos", "net.minecraft.network.protocol.game.PacketPlayOutEntity$PacketPlayOutRelEntityMove");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundMoveEntityPacket$PosRot", "net.minecraft.network.protocol.game.PacketPlayOutEntity$PacketPlayOutRelEntityMoveLook");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundMoveEntityPacket$Rot", "net.minecraft.network.protocol.game.PacketPlayOutEntity$PacketPlayOutEntityLook");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundOpenSignEditorPacket", "net.minecraft.network.protocol.game.PacketPlayOutOpenSignEditor");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket", "net.minecraft.network.protocol.game.PacketPlayOutEntityDestroy");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundRotateHeadPacket", "net.minecraft.network.protocol.game.PacketPlayOutEntityHeadRotation");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundSectionBlocksUpdatePacket", "net.minecraft.network.protocol.game.PacketPlayOutMultiBlockChange");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket", "net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket", "net.minecraft.network.protocol.game.PacketPlayOutEntityVelocity");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket", "net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundSetObjectivePacket", "net.minecraft.network.protocol.game.PacketPlayOutScoreboardObjective");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundSetScorePacket", "net.minecraft.network.protocol.game.PacketPlayOutScoreboardScore");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundSoundPacket", "net.minecraft.network.protocol.game.PacketPlayOutNamedSoundEffect");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket", "net.minecraft.network.protocol.game.PacketPlayOutEntityTeleport");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundContainerClickPacket", "net.minecraft.network.protocol.game.PacketPlayInWindowClick");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundInteractPacket", "net.minecraft.network.protocol.game.PacketPlayInUseEntity");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundInteractPacket$Action", "net.minecraft.network.protocol.game.PacketPlayInUseEntity$EnumEntityUseAction");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundInteractPacket$ActionType", "net.minecraft.network.protocol.game.PacketPlayInUseEntity$b");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Pos", "net.minecraft.network.protocol.game.PacketPlayInFlying$PacketPlayInPosition");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$PosRot", "net.minecraft.network.protocol.game.PacketPlayInFlying$PacketPlayInPositionLook");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Rot", "net.minecraft.network.protocol.game.PacketPlayInFlying$PacketPlayInLook");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundPlayerActionPacket", "net.minecraft.network.protocol.game.PacketPlayInBlockDig");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundSetCreativeModeSlotPacket", "net.minecraft.network.protocol.game.PacketPlayInSetCreativeSlot");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundSignUpdatePacket", "net.minecraft.network.protocol.game.PacketPlayInUpdateSign");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundUseItemPacket", "net.minecraft.network.protocol.game.PacketPlayInBlockPlace");
|
||||
spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundUseItemOnPacket", "net.minecraft.network.protocol.game.PacketPlayInUseItem");
|
||||
|
||||
spigotClassnames.put("net.minecraft.network.syncher.EntityDataAccessor", "net.minecraft.network.syncher.DataWatcherObject");
|
||||
spigotClassnames.put("net.minecraft.network.syncher.EntityDataSerializer", "net.minecraft.network.syncher.DataWatcherSerializer");
|
||||
spigotClassnames.put("net.minecraft.network.syncher.EntityDataSerializers", "net.minecraft.network.syncher.DataWatcherRegistry");
|
||||
spigotClassnames.put("net.minecraft.network.syncher.SynchedEntityData$DataItem", "net.minecraft.network.syncher.DataWatcher$Item");
|
||||
|
||||
spigotClassnames.put("net.minecraft.server.ServerScoreboard$Method", "net.minecraft.server.ScoreboardServer$Action");
|
||||
|
||||
spigotClassnames.put("net.minecraft.server.level.ChunkMap", "net.minecraft.server.level.PlayerChunkMap");
|
||||
spigotClassnames.put("net.minecraft.server.level.ChunkMap$TrackedEntity", "net.minecraft.server.level.PlayerChunkMap$EntityTracker");
|
||||
spigotClassnames.put("net.minecraft.server.level.ServerChunkCache", "net.minecraft.server.level.ChunkProviderServer");
|
||||
spigotClassnames.put("net.minecraft.server.level.ServerLevel", "net.minecraft.server.level.WorldServer");
|
||||
spigotClassnames.put("net.minecraft.server.level.ServerPlayer", "net.minecraft.server.level.EntityPlayer");
|
||||
|
||||
spigotClassnames.put("net.minecraft.server.network.ServerConnectionListener", "net.minecraft.server.network.ServerConnection");
|
||||
|
||||
spigotClassnames.put("net.minecraft.world.InteractionHand", "net.minecraft.world.EnumHand");
|
||||
|
||||
spigotClassnames.put("net.minecraft.world.entity.EntityType", "net.minecraft.world.entity.EntityTypes");
|
||||
spigotClassnames.put("net.minecraft.world.entity.Pose", "net.minecraft.world.entity.EntityPose");
|
||||
|
||||
spigotClassnames.put("net.minecraft.world.entity.item.PrimedTnt", "net.minecraft.world.entity.item.EntityTNTPrimed");
|
||||
|
||||
spigotClassnames.put("net.minecraft.world.entity.projectile.AbstractArrow", "net.minecraft.world.entity.projectile.EntityArrow");
|
||||
|
||||
spigotClassnames.put("net.minecraft.world.level.GameType", "net.minecraft.world.level.EnumGamemode");
|
||||
spigotClassnames.put("net.minecraft.world.level.LevelAccessor", "net.minecraft.world.level.GeneratorAccess");
|
||||
|
||||
spigotClassnames.put("net.minecraft.world.level.block.state.BlockState", "net.minecraft.world.level.block.state.IBlockData");
|
||||
spigotClassnames.put("net.minecraft.world.level.block.state.StateDefinition", "net.minecraft.world.level.block.state.BlockStateList");
|
||||
|
||||
spigotClassnames.put("net.minecraft.world.level.chunk.LevelChunk", "net.minecraft.world.level.chunk.Chunk");
|
||||
|
||||
spigotClassnames.put("net.minecraft.world.level.material.FlowingFluid", "net.minecraft.world.level.material.FluidTypeFlowing");
|
||||
spigotClassnames.put("net.minecraft.world.level.material.Fluids", "net.minecraft.world.level.material.FluidTypes");
|
||||
spigotClassnames.put("net.minecraft.world.level.material.FluidState", "net.minecraft.world.level.material.Fluid");
|
||||
|
||||
spigotClassnames.put("net.minecraft.world.phys.BlockHitResult", "net.minecraft.world.phys.MovingObjectPositionBlock");
|
||||
spigotClassnames.put("net.minecraft.world.phys.Vec3", "net.minecraft.world.phys.Vec3D");
|
||||
|
||||
spigotClassnames.put("net.minecraft.resources.ResourceLocation", "net.minecraft.resources.MinecraftKey");
|
||||
|
||||
spigotClassnames.put("net.minecraft.util.ProgressListener", "net.minecraft.util.IProgressUpdate");
|
||||
}
|
||||
|
||||
public static Class<?> getClass(String name) {
|
||||
try {
|
||||
if (name.startsWith("org.bukkit.craftbukkit")) {
|
||||
return Class.forName(ORG_BUKKIT_CRAFTBUKKIT + name.substring(22));
|
||||
} else if (MAJOR_VERSION < 17 && name.startsWith("net.minecraft")) {
|
||||
return Class.forName(LEGACY_NET_MINECRAFT_SERVER + "." + spigotClassnames.getOrDefault(name, name).split("[.](?=[^.]*$)")[1]);
|
||||
} else if (MAJOR_VERSION < 21 || MINOR_VERSION < 4) {
|
||||
return Class.forName(spigotClassnames.getOrDefault(name, name));
|
||||
} else {
|
||||
Class<?> clazz = null;
|
||||
try {
|
||||
clazz = Class.forName(name);
|
||||
} catch (ClassNotFoundException e) {
|
||||
}
|
||||
if (clazz != null && clazz.getName().equals(name)) {
|
||||
return clazz;
|
||||
}
|
||||
|
||||
try {
|
||||
return Core.class.getClassLoader().getParent().loadClass(name);
|
||||
} catch (ClassNotFoundException e) {
|
||||
if (clazz == null) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
return clazz;
|
||||
}
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new IllegalArgumentException("Cannot find " + name, e);
|
||||
}
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
public static class Field<T> {
|
||||
private final java.lang.reflect.Field f;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public T get(Object target) {
|
||||
try {
|
||||
return (T) f.get(target);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new IllegalArgumentException("Cannot read field", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void set(Object target, Object value) {
|
||||
try {
|
||||
f.set(target, value);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new IllegalArgumentException("Cannot write field", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> Field<T> getField(Class<?> target, String name, Class<T> fieldType) {
|
||||
return getField(target, name, fieldType, 0);
|
||||
}
|
||||
|
||||
public static <T> Field<T> getField(Class<?> target, Class<T> fieldType, int index) {
|
||||
return getField(target, null, fieldType, index);
|
||||
}
|
||||
|
||||
public static <T> Field<T> getField(Class<?> target, Class<T> fieldType, int index, Class<?>... parameters) {
|
||||
return getField(target, null, fieldType, index, parameters);
|
||||
}
|
||||
|
||||
private static <T> Field<T> getField(Class<?> target, String name, Class<T> fieldType, int index, Class<?>... parameters) {
|
||||
for (final java.lang.reflect.Field field : target.getDeclaredFields()) {
|
||||
if (matching(field, name, fieldType, parameters) && index-- <= 0) {
|
||||
field.setAccessible(true);
|
||||
return new Field<>(field);
|
||||
}
|
||||
}
|
||||
|
||||
// Search in parent classes
|
||||
if (target.getSuperclass() != null) {
|
||||
return getField(target.getSuperclass(), name, fieldType, index);
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("Cannot find field with type " + fieldType);
|
||||
}
|
||||
|
||||
private static <T> boolean matching(java.lang.reflect.Field field, String name, Class<T> fieldType, Class<?>... parameters) {
|
||||
if (name != null && !field.getName().equals(name)) return false;
|
||||
|
||||
if (!fieldType.isAssignableFrom(field.getType())) return false;
|
||||
|
||||
if (parameters.length > 0) {
|
||||
Type[] arguments = ((ParameterizedType) field.getGenericType()).getActualTypeArguments();
|
||||
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
if (arguments[i] instanceof ParameterizedType ? ((ParameterizedType) arguments[i]).getRawType() != parameters[i] : arguments[i] != parameters[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
public static class Method {
|
||||
private final java.lang.reflect.Method m;
|
||||
|
||||
public Object invoke(Object target, Object... arguments) {
|
||||
try {
|
||||
return m.invoke(target, arguments);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("Cannot invoke method " + m, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Method getTypedMethod(Class<?> clazz, String methodName, Class<?> returnType, Class<?>... params) {
|
||||
for (final java.lang.reflect.Method method : clazz.getDeclaredMethods()) {
|
||||
if ((methodName == null || method.getName().equals(methodName))
|
||||
&& (returnType == null || method.getReturnType().equals(returnType))
|
||||
&& Arrays.equals(method.getParameterTypes(), params)) {
|
||||
method.setAccessible(true);
|
||||
return new Method(method);
|
||||
}
|
||||
}
|
||||
|
||||
// Search in every superclass
|
||||
if (clazz.getSuperclass() != null) {
|
||||
return getTypedMethod(clazz.getSuperclass(), methodName, returnType, params);
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException(String.format("Cannot find method %s (%s).", methodName, Arrays.asList(params)));
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
public static class Constructor {
|
||||
private final java.lang.reflect.Constructor<?> c;
|
||||
|
||||
public Object invoke(Object... arguments) {
|
||||
try {
|
||||
return c.newInstance(arguments);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("Cannot invoke constructor " + c, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Constructor getConstructor(Class<?> clazz, Class<?>... params) {
|
||||
for (final java.lang.reflect.Constructor<?> constructor : clazz.getDeclaredConstructors()) {
|
||||
if (Arrays.equals(constructor.getParameterTypes(), params)) {
|
||||
constructor.setAccessible(true);
|
||||
return new Constructor(constructor);
|
||||
}
|
||||
}
|
||||
|
||||
throw new IllegalStateException(String.format("Unable to find constructor for %s (%s).", clazz, Arrays.asList(params)));
|
||||
}
|
||||
|
||||
public static Object newInstance(Class<?> clazz) {
|
||||
try {
|
||||
return Unsafe.getUnsafe().allocateInstance(clazz);
|
||||
} catch (InstantiationException e) {
|
||||
throw new SecurityException("Could not create object", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,35 +22,20 @@ package de.steamwar.command;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.command.SimpleCommandMap;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Map;
|
||||
|
||||
@UtilityClass
|
||||
class CommandRegistering {
|
||||
|
||||
private static final CommandMap commandMap;
|
||||
private static final SimpleCommandMap commandMap;
|
||||
private static final Map<String, Command> knownCommandMap;
|
||||
|
||||
static {
|
||||
try {
|
||||
final Field commandMapField = Bukkit.getServer().getClass().getDeclaredField("commandMap");
|
||||
commandMapField.setAccessible(true);
|
||||
commandMap = (CommandMap) commandMapField.get(Bukkit.getServer());
|
||||
} catch (NoSuchFieldException | IllegalAccessException exception) {
|
||||
Bukkit.shutdown();
|
||||
throw new SecurityException("Oh shit. Commands cannot be registered.", exception);
|
||||
}
|
||||
try {
|
||||
final Field knownCommandsField = SimpleCommandMap.class.getDeclaredField("knownCommands");
|
||||
knownCommandsField.setAccessible(true);
|
||||
knownCommandMap = (Map<String, Command>) knownCommandsField.get(commandMap);
|
||||
} catch (NoSuchFieldException | IllegalAccessException exception) {
|
||||
Bukkit.shutdown();
|
||||
throw new SecurityException("Oh shit. Commands cannot be registered.", exception);
|
||||
}
|
||||
commandMap = ((CraftServer) Bukkit.getServer()).getCommandMap();
|
||||
knownCommandMap = commandMap.getKnownCommands();
|
||||
}
|
||||
|
||||
static void unregister(Command command) {
|
||||
|
||||
@@ -19,20 +19,11 @@
|
||||
|
||||
package de.steamwar.core;
|
||||
|
||||
import de.steamwar.Reflection;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.minecraft.network.syncher.EntityDataAccessor;
|
||||
import net.minecraft.network.syncher.EntityDataSerializer;
|
||||
import net.minecraft.network.syncher.EntityDataSerializers;
|
||||
import net.minecraft.network.syncher.SynchedEntityData;
|
||||
import net.minecraft.world.entity.PositionMoveRotation;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class BountifulWrapper {
|
||||
public static final BountifulWrapper impl = new BountifulWrapper();
|
||||
|
||||
@@ -44,60 +35,4 @@ public class BountifulWrapper {
|
||||
if (type == ChatMessageType.CHAT) type = ChatMessageType.SYSTEM;
|
||||
player.spigot().sendMessage(type, msg);
|
||||
}
|
||||
|
||||
private static final Class<?> dataWatcherRegistry = EntityDataSerializers.class;
|
||||
private static final Class<?> dataWatcherSerializer = EntityDataSerializer.class;
|
||||
|
||||
public Object getDataWatcherObject(int index, Class<?> type) {
|
||||
return new EntityDataAccessor<>(index, (EntityDataSerializer<Object>) Reflection.getField(dataWatcherRegistry, dataWatcherSerializer, 0, type).get(null));
|
||||
}
|
||||
|
||||
public Object getDataWatcherItem(Object dwo, Object value) {
|
||||
return new SynchedEntityData.DataItem<>((EntityDataAccessor<Object>) dwo, value);
|
||||
}
|
||||
|
||||
public BountifulWrapper.PositionSetter getPositionSetter(Class<?> packetClass, int fieldOffset) {
|
||||
try {
|
||||
Reflection.Field<PositionMoveRotation> field = Reflection.getField(packetClass, PositionMoveRotation.class, 0);
|
||||
|
||||
return (packet, x, y, z, pitch, yaw) -> {
|
||||
field.set(packet, new PositionMoveRotation(new Vec3(x, y, z), field.get(packet).deltaMovement(), yaw, pitch));
|
||||
};
|
||||
} catch (IllegalArgumentException e) {
|
||||
Reflection.Field<Double> posX = Reflection.getField(packetClass, double.class, fieldOffset);
|
||||
Reflection.Field<Double> posY = Reflection.getField(packetClass, double.class, fieldOffset + 1);
|
||||
Reflection.Field<Double> posZ = Reflection.getField(packetClass, double.class, fieldOffset + 2);
|
||||
boolean isByteClass = packetClass.getSimpleName().contains("PacketPlayOutEntityTeleport") || packetClass.getSimpleName().contains("PacketPlayOutNamedEntitySpawn");
|
||||
Class<?> pitchYawType = isByteClass ? byte.class : int.class;
|
||||
Reflection.Field<?> lookYaw = Reflection.getField(packetClass, pitchYawType, isByteClass ? 0 : 1);
|
||||
Reflection.Field<?> lookPitch = Reflection.getField(packetClass, pitchYawType, isByteClass ? 1 : 2);
|
||||
|
||||
return (packet, x, y, z, pitch, yaw) -> {
|
||||
posX.set(packet, x);
|
||||
posY.set(packet, y);
|
||||
posZ.set(packet, z);
|
||||
if (isByteClass) {
|
||||
lookYaw.set(packet, (byte) (yaw * 256 / 360));
|
||||
lookPitch.set(packet, (byte) (pitch * 256 / 360));
|
||||
} else {
|
||||
lookYaw.set(packet, (int) (yaw * 256 / 360));
|
||||
lookPitch.set(packet, (int) (pitch * 256 / 360));
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public BountifulWrapper.UUIDSetter getUUIDSetter(Class<?> packetClass) {
|
||||
Reflection.Field<UUID> uuidField = Reflection.getField(packetClass, UUID.class, 0);
|
||||
|
||||
return uuidField::set;
|
||||
}
|
||||
|
||||
public interface PositionSetter {
|
||||
void set(Object packet, double x, double y, double z, float pitch, float yaw);
|
||||
}
|
||||
|
||||
public interface UUIDSetter {
|
||||
void set(Object packet, UUID uuid);
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user