forked from SteamWar/SteamWar
Compare commits
149
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5a02a58437 | ||
|
|
6209b86149 | ||
|
|
6f1403df9c | ||
|
|
0113788da2 | ||
|
|
8a7f65e000 | ||
|
|
8401f67b24 | ||
|
|
362468e756 | ||
|
|
ece12df0bc | ||
|
|
f35c07ab5b | ||
|
|
549f7e555c | ||
|
|
859238d7fa | ||
|
|
a79b00f78f | ||
|
|
105eda32e6 | ||
|
|
b4487b8079 | ||
|
|
ea3aad3bd2 | ||
|
|
d307f890e2 | ||
|
|
97c1da1b2a | ||
|
|
8a53aecfac | ||
|
|
5236afba17 | ||
|
|
d3c8b6e1c6 | ||
|
|
00ea792eee | ||
|
|
38e845b0e4 | ||
|
|
c60a8caed8 | ||
|
|
2e390286b2 | ||
|
|
6476125a3f | ||
|
|
311437d451 | ||
|
|
5a52771ec1 | ||
|
|
72b70a62e1 | ||
|
|
8575dcac33 | ||
|
|
cb744f6aa0 | ||
|
|
227f63c9ff | ||
|
|
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 | ||
|
|
7adb1e8b4a | ||
|
|
b88e592e79 | ||
|
|
914134600e | ||
|
|
70c8678c60
|
||
|
|
997292d58e | ||
|
|
8050f51424
|
||
|
|
a6681ffaf6
|
||
|
|
a23530074c
|
||
|
|
e88a4c624b
|
||
|
|
105beaf7a6 | ||
|
|
5f7ab3cd7b
|
||
|
|
5ce69e6b7a
|
||
|
|
9e43d5cd1b | ||
|
|
2ad9ae3c7f | ||
|
|
847eb3fe5d | ||
|
|
8fa9f7b0d3 | ||
|
|
559cae2b6d | ||
|
|
5dbf3638d0 |
@@ -15,6 +15,11 @@ bin/
|
||||
.vscode
|
||||
.settings
|
||||
|
||||
# Language Server
|
||||
**/.project
|
||||
**/.factorypath
|
||||
**/.classpath
|
||||
|
||||
# Other
|
||||
lib
|
||||
/WebsiteBackend/data
|
||||
|
||||
@@ -35,6 +35,7 @@ dependencies {
|
||||
compileOnly(libs.classindex)
|
||||
annotationProcessor(libs.classindex)
|
||||
compileOnly(project(":SpigotCore", "default"))
|
||||
compileOnly(project(":KotlinCore", "default"))
|
||||
|
||||
compileOnly(libs.axiom)
|
||||
compileOnly(libs.authlib)
|
||||
|
||||
@@ -32,6 +32,7 @@ import de.steamwar.bausystem.features.tracer.TraceManager;
|
||||
import de.steamwar.bausystem.features.tracer.TraceRecorder;
|
||||
import de.steamwar.bausystem.features.world.BauScoreboard;
|
||||
import de.steamwar.bausystem.linkage.BauGuiItem;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.region.RegionSystem;
|
||||
import de.steamwar.bausystem.utils.ScoreboardElement;
|
||||
import de.steamwar.bausystem.utils.TickManager;
|
||||
@@ -40,8 +41,9 @@ import de.steamwar.command.AbstractValidator;
|
||||
import de.steamwar.command.SWCommandUtils;
|
||||
import de.steamwar.core.CRIUSleepEvent;
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.core.WorldEditRendererCUIEditor;
|
||||
import de.steamwar.core.WorldIdentifier;
|
||||
import de.steamwar.core.worldedit.SteamEdit;
|
||||
import de.steamwar.core.worldedit.WorldEditRendererCUIEditor;
|
||||
import de.steamwar.linkage.AbstractLinker;
|
||||
import de.steamwar.linkage.SpigotLinker;
|
||||
import de.steamwar.message.Message;
|
||||
@@ -49,6 +51,7 @@ import de.steamwar.providers.BauServerInfo;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameRule;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -129,7 +132,19 @@ public class BauSystem extends JavaPlugin implements Listener {
|
||||
TraceManager.instance.init();
|
||||
TraceRecorder.instance.init();
|
||||
|
||||
new WorldEditRendererCUIEditor();
|
||||
SteamEdit.init();
|
||||
SteamEdit.ADJACENT_FILTERS = location -> {
|
||||
Region region = Region.getRegion(location);
|
||||
Region.Area area;
|
||||
if (region.getBuildArea().inRegion(location, true)) {
|
||||
area = region.getBuildArea();
|
||||
} else if (region.getTestblockArea().inRegion(location, true)) {
|
||||
area = region.getTestblockArea();
|
||||
} else {
|
||||
return SteamEdit.AdjacentFilter.ALWAYS;
|
||||
}
|
||||
return (x, y, z) -> area.inRegion(new Location(null, x, y, z), true);
|
||||
};
|
||||
|
||||
Bukkit.getWorlds().get(0).setGameRule(GameRule.SEND_COMMAND_FEEDBACK, false);
|
||||
|
||||
|
||||
+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);
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ public class ObserverTracerListener implements Listener {
|
||||
public ObserverTracerListener() {
|
||||
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {
|
||||
SWPlayer.allWithSingleComponent(ObserverTracer.class).forEach(pair -> {
|
||||
if (pair.getPlayer().getGameMode() != GameMode.SPECTATOR) return;
|
||||
if (pair.getSwPlayer().getPlayer().getGameMode() != GameMode.SPECTATOR) return;
|
||||
pair.getComponent().show();
|
||||
});
|
||||
}, 15L, 15L);
|
||||
|
||||
+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;
|
||||
}
|
||||
};
|
||||
|
||||
+11
-1
@@ -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;
|
||||
@@ -77,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
|
||||
@@ -122,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<>();
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
+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;
|
||||
|
||||
@@ -53,7 +53,7 @@ public class NoClipCommand extends SWCommand implements Listener {
|
||||
|
||||
@Override
|
||||
public void onUnmount(SWPlayer player) {
|
||||
player.setGameMode(GameMode.CREATIVE);
|
||||
player.getPlayer().setGameMode(GameMode.CREATIVE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,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);
|
||||
}
|
||||
|
||||
+41
@@ -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.bausystem.features.world;
|
||||
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
@Linked
|
||||
public class AntiPlayerCollision implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Scoreboard board = event.getPlayer().getScoreboard();
|
||||
Team team = board.getTeam("players");
|
||||
if (team == null) team = board.registerNewTeam("players");
|
||||
team.setOption(Team.Option.COLLISION_RULE, Team.OptionStatus.NEVER);
|
||||
team.addPlayer(event.getPlayer());
|
||||
}
|
||||
}
|
||||
@@ -37,5 +37,6 @@ tasks.register<DevServer>("DevBau21") {
|
||||
dependsOn(":SpigotCore:shadowJar")
|
||||
dependsOn(":BauSystem:shadowJar")
|
||||
dependsOn(":SchematicSystem:shadowJar")
|
||||
dependsOn(":KotlinCore:shadowJar")
|
||||
template = "Bau21"
|
||||
}
|
||||
|
||||
@@ -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!")))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,8 +108,10 @@ class DevCommand : CliktCommand("dev") {
|
||||
if (!templateFile.exists()) {
|
||||
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") {
|
||||
@@ -120,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
|
||||
)
|
||||
@@ -156,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",
|
||||
@@ -228,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",
|
||||
|
||||
+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
@@ -19,6 +19,7 @@
|
||||
|
||||
plugins {
|
||||
steamwar.kotlin
|
||||
kotlin("plugin.lombok")
|
||||
}
|
||||
|
||||
kotlin {
|
||||
@@ -40,4 +41,8 @@ dependencies {
|
||||
compileOnlyApi(libs.exposedDao)
|
||||
compileOnlyApi(libs.exposedJdbc)
|
||||
compileOnlyApi(libs.exposedTime)
|
||||
testImplementation(kotlin("test"))
|
||||
}
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
@@ -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
|
||||
@@ -664,13 +688,6 @@ public final class GameModeConfig<M, W> {
|
||||
*/
|
||||
public final int MaxBlocks;
|
||||
|
||||
/**
|
||||
* Maximal amount of items per dispenser
|
||||
*
|
||||
* @implSpec {@code 128} by default
|
||||
*/
|
||||
public final int MaxDispenserItems;
|
||||
|
||||
/**
|
||||
* Maximal blast resistance for the blocks
|
||||
*
|
||||
@@ -686,10 +703,12 @@ public final class GameModeConfig<M, W> {
|
||||
public final double MaxDesignBlastResistance;
|
||||
|
||||
/**
|
||||
* List of limited material (combinations)<br/>
|
||||
* List contains tags Amount (integer) and Materials (List of material names in Spigot 1.12 AND Spigot 1.15 format)
|
||||
* List of limited block materials
|
||||
*
|
||||
* @implSpec {@link SQLWrapper#getInventoryMaterials)} are all disallowed by default to have any content but are unlimited in number.
|
||||
* @implSpec Any Block that has more Blast Resistance than {@link #MaxBlastResistance} will be defaulted to 0.
|
||||
*/
|
||||
public final Map<Set<M>, Integer> Limited;
|
||||
public final List<BlockRule<M>> Limited;
|
||||
|
||||
private SchematicConfig(YMLWrapper<M, ?> loader) {
|
||||
loaded = loader.canLoad();
|
||||
@@ -707,32 +726,140 @@ public final class GameModeConfig<M, W> {
|
||||
IgnorePublicOnly = loader.getBoolean("IgnorePublicOnly", false);
|
||||
UnlimitedPrepare = loader.getBoolean("UnlimitedPrepare", false);
|
||||
MaxBlocks = loader.getInt("MaxBlocks", 0);
|
||||
MaxDispenserItems = loader.getInt("MaxDispenserItems", 128);
|
||||
MaxBlastResistance = loader.getDouble("MaxBlastResistance", Double.MAX_VALUE);
|
||||
MaxDesignBlastResistance = loader.getDouble("MaxDesignBlastResistance", MaxBlastResistance);
|
||||
|
||||
Map<Set<M>, Integer> Limited = new HashMap<>();
|
||||
for (Map<?, ?> entry : loader.getMapList("Limited")) {
|
||||
int amount = (Integer) entry.get("Amount");
|
||||
Set<String> materials = new HashSet<>((List<String>) entry.get("Materials"));
|
||||
if (amount == 0) {
|
||||
materials.forEach(material -> {
|
||||
Limited.put(Collections.singleton(loader.materialMapper.apply(material.toUpperCase())), 0);
|
||||
});
|
||||
} else {
|
||||
Limited.put(Collections.unmodifiableSet(materials.stream().map(String::toUpperCase).map(loader.materialMapper).collect(Collectors.toSet())), amount);
|
||||
}
|
||||
List<BlockRule<M>> limited = new ArrayList<>();
|
||||
Set<M> blocks = new HashSet<>();
|
||||
for (YMLWrapper<M, ?> limitedLoader : loader.withAsList("Limited")) {
|
||||
BlockRule<M> blockRule = new BlockRule<>(limitedLoader);
|
||||
blocks.addAll(blockRule.Materials);
|
||||
limited.add(blockRule);
|
||||
}
|
||||
SQLWrapper.impl.getMaterialWithGreaterBlastResistance(MaxBlastResistance).forEach(material -> {
|
||||
if (Limited.entrySet().stream().anyMatch(entry -> entry.getKey().contains(material))) return;
|
||||
Limited.put(Collections.singleton((M) material), 0);
|
||||
});
|
||||
this.Limited = Collections.unmodifiableMap(Limited);
|
||||
for (M material : (List<M>) SQLWrapper.impl.getMaterialWithGreaterBlastResistance(MaxBlastResistance)) {
|
||||
if (material == null || !blocks.add(material)) continue;
|
||||
limited.add(new BlockRule<>(material, 0));
|
||||
}
|
||||
for (M material : (Set<M>) SQLWrapper.impl.getInventoryMaterials()) {
|
||||
if (material == null || !blocks.add(material)) continue;
|
||||
limited.add(new BlockRule<>(material, Integer.MAX_VALUE));
|
||||
}
|
||||
this.Limited = Collections.unmodifiableList(limited);
|
||||
|
||||
this.ReplacementsWithoutBlockUpdates = loader.getMap("ReplacementsWithoutBlockUpdates", loader.materialMapper, loader.materialMapper);
|
||||
this.ReplacementsWithBlockUpdates = loader.getMap("ReplacementsWithBlockUpdates", loader.materialMapper, loader.materialMapper);
|
||||
}
|
||||
|
||||
public int getMaxCount(M material) {
|
||||
return Limited.stream()
|
||||
.filter(rule -> rule.Materials.contains(material))
|
||||
.mapToInt(rule -> rule.Amount)
|
||||
.max()
|
||||
.orElse(Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
public boolean isInventory(M material) {
|
||||
return Limited.stream()
|
||||
.filter(rule -> rule.Materials.contains(material))
|
||||
.anyMatch(rule -> rule.Content.loaded);
|
||||
}
|
||||
|
||||
public Integer getItemAmount(M material, M item) {
|
||||
return Limited.stream()
|
||||
.filter(rule -> rule.Materials.contains(material))
|
||||
.filter(rule -> rule.Content.Items.contains(item))
|
||||
.mapToInt(rule -> rule.Content.Amount)
|
||||
.max()
|
||||
.orElse(0);
|
||||
}
|
||||
|
||||
@ToString
|
||||
public static final class BlockRule<M> {
|
||||
|
||||
/**
|
||||
* The block materials this rule applies to
|
||||
*/
|
||||
public final Set<M> Materials;
|
||||
|
||||
/**
|
||||
* Maximal amount of Blocks allowed in the schematic
|
||||
*
|
||||
* @implSpec {@code 0} by default
|
||||
*/
|
||||
public final int Amount;
|
||||
|
||||
/**
|
||||
* The item content filter for Blocks
|
||||
*
|
||||
* @implSpec no Items with {@code Amount 0} (denies any item) by default
|
||||
*/
|
||||
public final Content<M> Content;
|
||||
|
||||
/**
|
||||
* Resolves one {@code Materials} entry to the concrete materials it denotes: {@code storage}
|
||||
* for {@link SQLWrapper#getStorageMaterials()}, {@code inventory} for
|
||||
* {@link SQLWrapper#getInventoryMaterials()}, or the material itself otherwise.
|
||||
*/
|
||||
private Set<M> expandInventoryGroup(YMLWrapper<M, ?> loader, String name) {
|
||||
switch (name.toUpperCase()) {
|
||||
case "STORAGE":
|
||||
return (Set<M>) SQLWrapper.impl.getStorageMaterials();
|
||||
case "INVENTORY":
|
||||
return (Set<M>) SQLWrapper.impl.getInventoryMaterials();
|
||||
default:
|
||||
M material = loader.materialMapper.apply(name.toUpperCase());
|
||||
return material != null ? Collections.singleton(material) : Collections.emptySet();
|
||||
}
|
||||
}
|
||||
|
||||
private BlockRule(YMLWrapper<M, ?> loader) {
|
||||
Set<M> blocks = loader.getStringList("Materials")
|
||||
.stream()
|
||||
.flatMap(value -> expandInventoryGroup(loader, value).stream())
|
||||
.collect(Collectors.toSet());
|
||||
Materials = Collections.unmodifiableSet(blocks);
|
||||
Amount = loader.getInt("Amount", 0);
|
||||
Content = new Content<>(loader.with("Content"));
|
||||
}
|
||||
|
||||
private BlockRule(M block, int amount) {
|
||||
Materials = Collections.singleton(block);
|
||||
Amount = amount;
|
||||
Content = new Content<>();
|
||||
}
|
||||
|
||||
@ToString
|
||||
public static final class Content<M> {
|
||||
|
||||
public final boolean loaded;
|
||||
|
||||
/**
|
||||
* Items allowed by this rule
|
||||
*/
|
||||
public final Set<M> Items;
|
||||
|
||||
/**
|
||||
* Maximal amount of an allowed item per single block instance
|
||||
*
|
||||
* @implSpec {@code 0} by default
|
||||
*/
|
||||
public final int Amount;
|
||||
|
||||
private Content(YMLWrapper<M, ?> loader) {
|
||||
loaded = loader.canLoad();
|
||||
List<M> items = loader.getMaterialList("Items");
|
||||
Items = Collections.unmodifiableSet(new HashSet<>(items));
|
||||
Amount = loader.getInt("Amount", 0);
|
||||
}
|
||||
|
||||
private Content() {
|
||||
loaded = false;
|
||||
Items = new HashSet<>();
|
||||
Amount = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ToString
|
||||
public static final class SizeConfig {
|
||||
|
||||
@@ -929,6 +1056,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 +1074,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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -183,14 +183,6 @@ class Punishment(id: EntityID<Int>) : IntEntity(id) {
|
||||
"UNNOFIGHTSERVER",
|
||||
UserPerm.MODERATION
|
||||
),
|
||||
NoTeamServer(
|
||||
"NOTEAMSERVER_TEAM",
|
||||
"NOTEAMSERVER_PERMA",
|
||||
"NOTEAMSERVER_UNTIL",
|
||||
"UNNOTEAMSERVER_ERROR",
|
||||
"UNNOTEAMSERVER",
|
||||
UserPerm.MODERATION
|
||||
),
|
||||
Note("NOTE_TEAM", null, null, null, null, UserPerm.PUNISHMENTS, true);
|
||||
|
||||
fun isMulti() =
|
||||
|
||||
@@ -24,6 +24,7 @@ import de.steamwar.ImplementationProvider;
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public interface SQLWrapper<M> {
|
||||
SQLWrapper<?> impl = ImplementationProvider.getImpl("de.steamwar.sql.SQLWrapperImpl");
|
||||
@@ -36,5 +37,21 @@ public interface SQLWrapper<M> {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Storage-type inventory materials (chests, barrels, shulker boxes of any color) - the
|
||||
* {@code storage} group usable in {@code GameModeConfig}'s {@code Limited}.
|
||||
*/
|
||||
default Set<M> getStorageMaterials() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Every inventory material - the {@code all} group usable in {@code GameModeConfig}'s
|
||||
* {@code Limited}. Expected to be a superset of {@link #getStorageMaterials()}.
|
||||
*/
|
||||
default Set<M> getInventoryMaterials() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
void additionalExceptionMetadata(StringBuilder builder);
|
||||
}
|
||||
|
||||
@@ -307,12 +307,12 @@ class SteamwarUser(id: EntityID<Int>) : IntEntity(id) {
|
||||
punishments[punishment] = Punishment.createPunishment(this@SteamwarUser.id.value, from, punishment, reason, time, perma)
|
||||
}
|
||||
|
||||
fun setLocale(locale: Locale?, manualeLocale: Boolean) {
|
||||
fun setLocale(locale: Locale?, manualLocale: Boolean) {
|
||||
if (locale == null || (this.manualLocale && !manualLocale)) return
|
||||
|
||||
useDb {
|
||||
this@SteamwarUser.locale = locale
|
||||
this@SteamwarUser.manualLocale = manualeLocale
|
||||
this@SteamwarUser.manualLocale = manualLocale
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -76,6 +76,25 @@ final class YMLWrapper<M, W> {
|
||||
return new YMLWrapper<>(false, Collections.emptyMap(), materialMapper, winconditionMapper);
|
||||
}
|
||||
|
||||
public List<YMLWrapper<M, W>> withAsList(String path) {
|
||||
if (document.containsKey(path)) {
|
||||
Object value = document.get(path);
|
||||
if (value instanceof List) {
|
||||
List<?> list = (List<?>) value;
|
||||
List<Map> maps = list.stream()
|
||||
.filter(Map.class::isInstance)
|
||||
.map(Map.class::cast)
|
||||
.collect(Collectors.toList());
|
||||
if (maps.size() == list.size()) {
|
||||
return (List) maps.stream()
|
||||
.map(map -> new YMLWrapper(true, map, materialMapper, winconditionMapper))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public <T> T get(String path, T defaultValue, Function<Object, T> mapper) {
|
||||
Object value = this.document.get(path);
|
||||
if (value == null) return defaultValue;
|
||||
@@ -139,6 +158,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
|
||||
@@ -103,15 +107,23 @@ Schematic:
|
||||
UnlimitedPrepare: false # defaults to false if missing
|
||||
# Maximal amount of blocks allowed in the schematic
|
||||
MaxBlocks: 0 # defaults to 0 (ignored) if missing
|
||||
# Maximal amount of items per dispenser
|
||||
MaxDispenserItems: 128 # defaults to 128 if missing
|
||||
# Maximal blast resistance for the design blocks
|
||||
MaxDesignBlastResistance: 100000000 # defaults to Double.MAX_VALUE if missing
|
||||
# List of limited material (combinations)
|
||||
# List contains tags Amount (integer) and Materials (List of material names in Spigot 1.12 AND Spigot 1.15 format)
|
||||
# List of limited block materials
|
||||
# InventoryMaterials are all disallowed by default to have any content but are unlimited in number
|
||||
# Any Block that has more Blast Resistance than MaxBlastResistance will be defaulted to 0.
|
||||
Limited:
|
||||
- Materials: [ ]
|
||||
Amount: 0
|
||||
- Blocks: [ DISPENSER ]
|
||||
MaxCount: 64
|
||||
- Blocks: [ DISPENSER ]
|
||||
MaxCount: 16
|
||||
Content:
|
||||
Items: [ ARROW, FIRE_CHARGE ]
|
||||
Amount: 128
|
||||
- Blocks: [ storage ]
|
||||
Content:
|
||||
Items: [ TNT ]
|
||||
Amount: 1728
|
||||
|
||||
# The name of the game mode presented to the players
|
||||
GameName: WarGear # defaults to WarGear if missing
|
||||
|
||||
@@ -39,6 +39,7 @@ public enum ArenaMode {
|
||||
public static final Set<ArenaMode> Test = Collections.unmodifiableSet(EnumSet.of(TEST, CHECK));
|
||||
public static final Set<ArenaMode> Prepare = Collections.unmodifiableSet(EnumSet.of(PREPARE));
|
||||
public static final Set<ArenaMode> Replay = Collections.unmodifiableSet(EnumSet.of(REPLAY, TEST));
|
||||
public static final Set<ArenaMode> TestOrReferee = Collections.unmodifiableSet(EnumSet.of(TEST, CHECK, EVENT));
|
||||
|
||||
public static final Set<ArenaMode> AntiReplay = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(REPLAY)));
|
||||
public static final Set<ArenaMode> AntiTest = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(TEST, CHECK)));
|
||||
|
||||
@@ -21,8 +21,8 @@ package de.steamwar.fightsystem;
|
||||
|
||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.core.WorldEditRendererCUIEditor;
|
||||
import de.steamwar.fightsystem.commands.TechareaCommand;
|
||||
import de.steamwar.core.worldedit.SteamEdit;
|
||||
import de.steamwar.core.worldedit.WorldEditRendererCUIEditor;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import de.steamwar.fightsystem.listener.ClickAnalyzer;
|
||||
@@ -108,7 +108,7 @@ public class FightSystem extends JavaPlugin {
|
||||
}
|
||||
});
|
||||
new OneShotStateDependent(ArenaMode.All, FightState.PreSchemSetup, () -> Fight.playSound(SWSound.BLOCK_NOTE_PLING.getSound(), 100.0f, 2.0f));
|
||||
new OneShotStateDependent(ArenaMode.Test, FightState.All, WorldEditRendererCUIEditor::new);
|
||||
new OneShotStateDependent(ArenaMode.Test, FightState.All, SteamEdit::init);
|
||||
Config.world.setGameRule(GameRule.REDUCED_DEBUG_INFO, ArenaMode.AntiTest.contains(Config.mode));
|
||||
|
||||
hullHider = new HullHider();
|
||||
@@ -127,8 +127,6 @@ public class FightSystem extends JavaPlugin {
|
||||
if (checkSchematicNode.isPrepared()) {
|
||||
Fight.getRedTeam().setSchem(checkSchematicNode, NodeData.getRevisions(checkSchematicNode) - 1);
|
||||
}
|
||||
|
||||
new TechareaCommand();
|
||||
} else if (Config.mode == ArenaMode.PREPARE) {
|
||||
Fight.getUnrotated().setSchem(SchematicNode.getSchematicNode(Config.PrepareSchemID));
|
||||
}
|
||||
|
||||
@@ -24,35 +24,25 @@ import de.steamwar.fightsystem.ArenaMode;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.fight.Kit;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import de.steamwar.sql.UserPerm;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Linked
|
||||
public class AkCommand implements CommandExecutor {
|
||||
public class AkCommand extends FightSWCommand {
|
||||
|
||||
public AkCommand() {
|
||||
new StateDependentCommand(ArenaMode.Test, FightState.All, "ak", this);
|
||||
super(ArenaMode.Test, FightState.All, "ak");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
if (!player.isOp()) return false;
|
||||
protected boolean hasPerm(Player player, SteamwarUser user) {
|
||||
return player.isOp() && user.hasPerm(UserPerm.ADMINISTRATION) && Core.getInstance() != FightSystem.getPlugin();
|
||||
}
|
||||
|
||||
if (!SteamwarUser.get(player.getUniqueId()).hasPerm(UserPerm.ADMINISTRATION) && Core.getInstance() != FightSystem.getPlugin()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Kit.createKit(args[0], player);
|
||||
return false;
|
||||
@Register
|
||||
public void run(@Validator Player player, String name) {
|
||||
Kit.createKit(name, player);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* 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.commands;
|
||||
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.command.TypeValidator;
|
||||
import de.steamwar.fightsystem.ArenaMode;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependent;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerCommandSendEvent;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class FightSWCommand extends SWCommand implements Listener {
|
||||
|
||||
private final String command;
|
||||
private final String[] aliases;
|
||||
|
||||
protected FightSWCommand(Set<ArenaMode> mode, Set<FightState> states, String command) {
|
||||
super(command);
|
||||
this.command = command;
|
||||
this.aliases = new String[0];
|
||||
stateDependant(mode, states);
|
||||
}
|
||||
|
||||
protected FightSWCommand(Set<ArenaMode> mode, Set<FightState> states, String command, String... aliases) {
|
||||
super(command, aliases);
|
||||
this.command = command;
|
||||
this.aliases = aliases;
|
||||
stateDependant(mode, states);
|
||||
}
|
||||
|
||||
private void stateDependant(Set<ArenaMode> mode, Set<FightState> states) {
|
||||
FightSWCommand.this.unregister();
|
||||
new StateDependent(mode, states) {
|
||||
@Override
|
||||
public void enable() {
|
||||
System.out.println("--- Enable: " + command);
|
||||
FightSWCommand.this.register();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
System.out.println("--- Disable: " + command);
|
||||
FightSWCommand.this.unregister();
|
||||
}
|
||||
}.register();
|
||||
}
|
||||
|
||||
public static void postFightStateChange() {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
player.updateCommands();
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean hasPerm(Player player, SteamwarUser user) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public final void onPlayerCommandSend(PlayerCommandSendEvent event) {
|
||||
if (hasPerm(event.getPlayer(), SteamwarUser.get(event.getPlayer().getUniqueId()))) return;
|
||||
event.getCommands().remove(command);
|
||||
for (String alias : aliases) {
|
||||
event.getCommands().remove(alias);
|
||||
}
|
||||
}
|
||||
|
||||
@ClassValidator(value = Player.class, local = true)
|
||||
public final TypeValidator<Player> permissionCheck() {
|
||||
return (sender, value, messageSender) -> hasPerm(value, SteamwarUser.get(value.getUniqueId()));
|
||||
}
|
||||
}
|
||||
+10
-74
@@ -19,92 +19,28 @@
|
||||
|
||||
package de.steamwar.fightsystem.commands;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import de.steamwar.fightsystem.ArenaMode;
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import org.bukkit.Bukkit;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.defaults.BukkitCommand;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.StringUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Linked
|
||||
public class GamemodeCommand extends BukkitCommand {
|
||||
|
||||
private static final List<String> GAMEMODE_NAMES = ImmutableList.of("adventure", "creative", "survival",
|
||||
"spectator");
|
||||
public class GamemodeCommand extends FightSWCommand {
|
||||
|
||||
public GamemodeCommand() {
|
||||
super("gamemode");
|
||||
List<String> aliases = new ArrayList<>();
|
||||
aliases.add("gm");
|
||||
this.setAliases(aliases);
|
||||
|
||||
Map<String, Command> knownCommands = ((CraftServer) Bukkit.getServer()).getCommandMap().getKnownCommands();
|
||||
knownCommands.remove("gamemode");
|
||||
Commands.injectCommand(this);
|
||||
super(ArenaMode.TestOrReferee, FightState.All, "gamemode", "gm");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
return false;
|
||||
} else if (args.length == 0) {
|
||||
FightSystem.getMessage().sendPrefixless("GAMEMODE_HELP", sender);
|
||||
return false;
|
||||
}
|
||||
|
||||
Player p = (Player) sender;
|
||||
|
||||
if (!(Config.test() || Config.isReferee(p))) {
|
||||
FightSystem.getMessage().sendPrefixless("GAMEMODE_NOT_ALLOWED", p, ChatMessageType.ACTION_BAR);
|
||||
return false;
|
||||
}
|
||||
|
||||
GameMode mode = createMode(args[0]);
|
||||
|
||||
if (mode == null) {
|
||||
FightSystem.getMessage().sendPrefixless("GAMEMODE_UNKNOWN", p, ChatMessageType.ACTION_BAR, args[0]);
|
||||
return false;
|
||||
}
|
||||
|
||||
p.setGameMode(mode);
|
||||
return true;
|
||||
protected boolean hasPerm(Player player, SteamwarUser user) {
|
||||
return Config.test() || Config.isReferee(player);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private GameMode createMode(String modeArg) {
|
||||
try {
|
||||
return GameMode.getByValue(Integer.parseInt(modeArg));
|
||||
} catch (NumberFormatException ignored) {
|
||||
if ((modeArg.equalsIgnoreCase("creative")) || (modeArg.equalsIgnoreCase("c"))) {
|
||||
return GameMode.CREATIVE;
|
||||
} else if ((modeArg.equalsIgnoreCase("adventure")) || (modeArg.equalsIgnoreCase("a"))) {
|
||||
return GameMode.ADVENTURE;
|
||||
} else if ((modeArg.equalsIgnoreCase("spectator")) || (modeArg.equalsIgnoreCase("sp"))) {
|
||||
return GameMode.SPECTATOR;
|
||||
} else if ((modeArg.equalsIgnoreCase("survival")) || (modeArg.equalsIgnoreCase("s"))) {
|
||||
return GameMode.SURVIVAL;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@Register(description = "GAMEMODE_HELP")
|
||||
public void execute(@Validator Player player, GameMode gameMode) {
|
||||
player.setGameMode(gameMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String alias, String[] args) {
|
||||
if (args.length == 1) {
|
||||
return StringUtil.copyPartialMatches(args[0], GAMEMODE_NAMES, new ArrayList<>(GAMEMODE_NAMES.size()));
|
||||
}
|
||||
return ImmutableList.of();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,34 +20,31 @@
|
||||
package de.steamwar.fightsystem.commands;
|
||||
|
||||
import de.steamwar.fightsystem.ArenaMode;
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import de.steamwar.fightsystem.listener.Check;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.sql.SchematicNode;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import de.steamwar.sql.UserPerm;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Linked
|
||||
public class InfoCommand implements CommandExecutor {
|
||||
public class InfoCommand extends FightSWCommand {
|
||||
|
||||
public InfoCommand() {
|
||||
new StateDependentCommand(ArenaMode.All, FightState.All, "fightinfo", this);
|
||||
super(ArenaMode.All, FightState.All, "fightinfo");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) return false;
|
||||
|
||||
Player player = (Player) sender;
|
||||
if (!SteamwarUser.get(player.getUniqueId()).hasPerm(UserPerm.CHECK)) return false;
|
||||
protected boolean hasPerm(Player player, SteamwarUser user) {
|
||||
return Check.checkPermission(user, Config.GameModeConfig);
|
||||
}
|
||||
|
||||
@Register
|
||||
public void run(@Validator Player player) {
|
||||
for (FightTeam team : Fight.teams()) {
|
||||
if (!team.isLeaderless()) {
|
||||
FightSystem.getMessage().send("INFO_LEADER", player, team.getColoredName(), team.getLeader().getEntity().getName());
|
||||
@@ -58,6 +55,5 @@ public class InfoCommand implements CommandExecutor {
|
||||
FightSystem.getMessage().send("INFO_SCHEMATIC", player, team.getColoredName(), schematic.getName(), SteamwarUser.byId(schematic.getOwner()).getUserName(), schematic.getRank());
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,32 +21,23 @@ package de.steamwar.fightsystem.commands;
|
||||
|
||||
import de.steamwar.fightsystem.ArenaMode;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Linked
|
||||
public class KitCommand implements CommandExecutor {
|
||||
public class KitCommand extends FightSWCommand {
|
||||
|
||||
public KitCommand() {
|
||||
new StateDependentCommand(ArenaMode.AntiReplay, FightState.Setup, "kit", this);
|
||||
super(ArenaMode.AntiReplay, FightState.Setup, "kit");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
@Register
|
||||
public void execute(Player player) {
|
||||
GUI.kitSelection(player, "");
|
||||
}
|
||||
|
||||
if (args.length != 1) {
|
||||
GUI.kitSelection(player, "");
|
||||
} else {
|
||||
Commands.kit(player, args[0]);
|
||||
}
|
||||
return false;
|
||||
@Register
|
||||
public void execute(Player player, String query) { // TODO: TabCompletion of Kit Names!
|
||||
GUI.kitSelection(player, query);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-14
@@ -21,28 +21,18 @@ package de.steamwar.fightsystem.commands;
|
||||
|
||||
import de.steamwar.fightsystem.ArenaMode;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Linked
|
||||
public class LeaveCommand implements CommandExecutor {
|
||||
public class LeaveCommand extends FightSWCommand {
|
||||
|
||||
public LeaveCommand() {
|
||||
new StateDependentCommand(ArenaMode.AntiReplay, FightState.Setup, "leave", this);
|
||||
super(ArenaMode.AntiReplay, FightState.Setup, "leave");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
|
||||
@Register
|
||||
public void execute(Player player) {
|
||||
Commands.leaveTeam(player);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
+10
-20
@@ -20,52 +20,42 @@
|
||||
package de.steamwar.fightsystem.commands;
|
||||
|
||||
import de.steamwar.fightsystem.ArenaMode;
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import de.steamwar.fightsystem.listener.Check;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.sql.SchematicNode;
|
||||
import de.steamwar.sql.SchematicType;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import de.steamwar.sql.UserPerm;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Linked
|
||||
public class LockschemCommand implements CommandExecutor {
|
||||
public class LockschemCommand extends FightSWCommand {
|
||||
|
||||
public LockschemCommand() {
|
||||
new StateDependentCommand(ArenaMode.All, FightState.Schem, "lockschem", this);
|
||||
super(ArenaMode.All, FightState.Schem, "lockschem");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) return false;
|
||||
Player player = (Player) sender;
|
||||
protected boolean hasPerm(Player player, SteamwarUser user) {
|
||||
return Check.checkPermission(user, Config.GameModeConfig);
|
||||
}
|
||||
|
||||
if (!SteamwarUser.get(player.getUniqueId()).hasPerm(UserPerm.CHECK)) return false;
|
||||
|
||||
if (args.length != 1) {
|
||||
FightSystem.getMessage().sendPrefixless("LOCKSCHEM_HELP", player);
|
||||
return false;
|
||||
}
|
||||
|
||||
String teamName = args[0];
|
||||
@Register(description = "LOCKSCHEM_HELP")
|
||||
public void execute(@Validator Player player, String teamName) {
|
||||
FightTeam fightTeam = Fight.getTeamByName(teamName);
|
||||
|
||||
if (fightTeam == null) {
|
||||
FightSystem.getMessage().sendPrefixless("UNKNOWN_TEAM", player, ChatMessageType.ACTION_BAR);
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
SchematicNode.getSchematicNode(fightTeam.getSchematic()).setSchemtype(SchematicType.Normal);
|
||||
FightSystem.getMessage().sendPrefixless("LOCKSCHEM_LOCKED", player, ChatMessageType.ACTION_BAR);
|
||||
fightTeam.broadcastSystem("LOCKSCHEM_LOCKED_BY", player.getName());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-14
@@ -21,28 +21,18 @@ package de.steamwar.fightsystem.commands;
|
||||
|
||||
import de.steamwar.fightsystem.ArenaMode;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Linked
|
||||
public class ReadyCommand implements CommandExecutor {
|
||||
public class ReadyCommand extends FightSWCommand {
|
||||
|
||||
public ReadyCommand() {
|
||||
new StateDependentCommand(ArenaMode.AntiPrepare, FightState.PostSchemSetup, "ready", this);
|
||||
super(ArenaMode.AntiPrepare, FightState.PostSchemSetup, "ready");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
|
||||
@Register
|
||||
public void execute(Player player) {
|
||||
Commands.toggleReady(player);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
+5
-21
@@ -20,35 +20,19 @@
|
||||
package de.steamwar.fightsystem.commands;
|
||||
|
||||
import de.steamwar.fightsystem.ArenaMode;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Linked
|
||||
public class RemoveCommand implements CommandExecutor {
|
||||
public class RemoveCommand extends FightSWCommand {
|
||||
|
||||
public RemoveCommand() {
|
||||
new StateDependentCommand(ArenaMode.VariableTeams, FightState.Setup, "remove", this);
|
||||
super(ArenaMode.VariableTeams, FightState.Setup, "remove");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
|
||||
if (args.length != 1) {
|
||||
FightSystem.getMessage().sendPrefixless("REMOVE_HELP", player);
|
||||
return false;
|
||||
}
|
||||
|
||||
Commands.kick(player, args[0]);
|
||||
return false;
|
||||
@Register(description = "REMOVE_HELP")
|
||||
public void execute(Player player, Player teamMember) {
|
||||
Commands.kick(player, teamMember.getName());
|
||||
}
|
||||
}
|
||||
|
||||
+6
-15
@@ -26,37 +26,28 @@ import de.steamwar.fightsystem.fight.FightPlayer;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import de.steamwar.fightsystem.fight.JoinRequest;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
@Linked
|
||||
public class RequestsCommand implements CommandExecutor {
|
||||
public class RequestsCommand extends FightSWCommand {
|
||||
|
||||
public RequestsCommand() {
|
||||
new StateDependentCommand(ArenaMode.VariableTeams, FightState.AntiSpectate, "request", this);
|
||||
new StateDependentCommand(ArenaMode.VariableTeams, FightState.AntiSpectate, "requests", this);
|
||||
super(ArenaMode.VariableTeams, FightState.AntiSpectate, "request", "requests");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) return false;
|
||||
Player player = (Player) sender;
|
||||
@Register
|
||||
public void execute(Player player) {
|
||||
FightPlayer fp = Fight.getFightPlayer(player);
|
||||
if (fp == null || !(fp.isLeader() || fp.isLiving())) {
|
||||
GUI.joinRequest(player);
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (Commands.checkGetLeader(player) == null) return false;
|
||||
|
||||
if (Commands.checkGetLeader(player) == null) return;
|
||||
GUI.chooseJoinRequests(player);
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void onJoinRequest(Player player, JoinRequest request, BiConsumer<JoinRequest, FightTeam> handleJoinRequest) {
|
||||
|
||||
@@ -24,32 +24,22 @@ import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.record.PacketProcessor;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Linked
|
||||
public class SkipCommand implements CommandExecutor {
|
||||
public class SkipCommand extends FightSWCommand {
|
||||
|
||||
public SkipCommand() {
|
||||
new StateDependentCommand(ArenaMode.AntiPrepare, ArenaMode.Replay.contains(Config.mode) ? FightState.All : FightState.TeamFix, "skip", this);
|
||||
super(ArenaMode.AntiPrepare, ArenaMode.Replay.contains(Config.mode) ? FightState.All : FightState.TeamFix, "skip");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
|
||||
@Register
|
||||
public void execute(Player player) {
|
||||
if (PacketProcessor.isReplaying() && player.getUniqueId().equals(Fight.getBlueTeam().getDesignatedLeader())) {
|
||||
PacketProcessor.currentReplay().skipToSubtitle();
|
||||
} else {
|
||||
Commands.toggleSkip(player);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
+5
-14
@@ -21,27 +21,18 @@ package de.steamwar.fightsystem.commands;
|
||||
|
||||
import de.steamwar.fightsystem.ArenaMode;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Linked
|
||||
public class StateCommand implements CommandExecutor {
|
||||
public class StateCommand extends FightSWCommand {
|
||||
|
||||
public StateCommand() {
|
||||
new StateDependentCommand(ArenaMode.Test, FightState.All, "state", this);
|
||||
super(ArenaMode.Test, FightState.All, "state");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
GUI.state((Player) sender);
|
||||
return false;
|
||||
@Register
|
||||
public void execute(Player player) {
|
||||
GUI.state(player);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,26 +22,18 @@ package de.steamwar.fightsystem.commands;
|
||||
import de.steamwar.fightsystem.ArenaMode;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Linked
|
||||
public class TBCommand implements CommandExecutor {
|
||||
public class TBCommand extends FightSWCommand {
|
||||
|
||||
public TBCommand() {
|
||||
new StateDependentCommand(ArenaMode.Check, FightState.All, "resettb", this);
|
||||
super(ArenaMode.Check, FightState.All, "resettb");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
@Register
|
||||
public void execute(Player player) {
|
||||
Fight.getRedTeam().pasteSchem();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
+5
-19
@@ -20,34 +20,20 @@ package de.steamwar.fightsystem.commands;
|
||||
import de.steamwar.fightsystem.ArenaMode;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Linked
|
||||
public class TPSWarpCommand implements CommandExecutor {
|
||||
public class TPSWarpCommand extends FightSWCommand {
|
||||
|
||||
public TPSWarpCommand() {
|
||||
new StateDependentCommand(ArenaMode.Prepare, FightState.PostSchemSetup, "tpswarp", this);
|
||||
new StateDependentCommand(ArenaMode.Prepare, FightState.PostSchemSetup, "tpslimit", this);
|
||||
super(ArenaMode.Prepare, FightState.PostSchemSetup, "tpswarp", "tpslimit");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
float tps;
|
||||
try {
|
||||
tps = Float.parseFloat(args[0]);
|
||||
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
|
||||
FightSystem.getMessage().send("TPSWARP_HELP", sender);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Register(description = "TPSWARP_HELP")
|
||||
public void execute(Player player, float tps) {
|
||||
MinecraftServer.getServer().tickRateManager().setTickRate(tps);
|
||||
|
||||
FightSystem.getMessage().broadcastActionbar("TPSWARP_SET", tps);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
+18
-21
@@ -19,42 +19,39 @@
|
||||
|
||||
package de.steamwar.fightsystem.commands;
|
||||
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.entity.CWireframe;
|
||||
import de.steamwar.entity.REntityServer;
|
||||
import de.steamwar.fightsystem.ArenaMode;
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import org.bukkit.Bukkit;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.OneShotStateDependent;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class TechareaCommand extends SWCommand {
|
||||
private final Map<UUID, REntityServer> servers = new HashMap<>();
|
||||
@Linked
|
||||
public class TechareaCommand extends FightSWCommand {
|
||||
private REntityServer entityServer = new REntityServer();
|
||||
|
||||
public TechareaCommand() {
|
||||
super("techarea");
|
||||
|
||||
Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), () -> servers.forEach((uuid, rEntityServer) -> rEntityServer.tick()), 2, 2);
|
||||
}
|
||||
|
||||
@Register
|
||||
public void genericCommand(Player player) {
|
||||
if (servers.containsKey(player.getUniqueId())) {
|
||||
servers.get(player.getUniqueId()).close();
|
||||
} else {
|
||||
super(ArenaMode.Check, FightState.All, "techarea");
|
||||
new OneShotStateDependent(ArenaMode.Check, FightState.All, () -> {
|
||||
if (!entityServer.getEntities().isEmpty()) return;
|
||||
REntityServer server = new REntityServer();
|
||||
CWireframe wireframe = new CWireframe(server);
|
||||
|
||||
wireframe.setPos1(Config.BlueInsetRegion.getMinLocation(Config.world));
|
||||
wireframe.setPos2(Config.BlueInsetRegion.getMaxLocation(Config.world).subtract(1, 1, 1));
|
||||
wireframe.setBlock(Material.RED_CONCRETE.createBlockData());
|
||||
});
|
||||
}
|
||||
|
||||
server.addPlayer(player);
|
||||
servers.put(player.getUniqueId(), server);
|
||||
@Register
|
||||
public void genericCommand(Player player) {
|
||||
if (entityServer.getPlayers().contains(player)) {
|
||||
entityServer.removePlayer(player);
|
||||
} else {
|
||||
entityServer.addPlayer(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-10
@@ -25,27 +25,24 @@ import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.sql.SWException;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.util.Arrays;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@Linked
|
||||
public class TechhiderbugCommand implements CommandExecutor {
|
||||
public class TechhiderbugCommand extends FightSWCommand {
|
||||
|
||||
public TechhiderbugCommand() {
|
||||
new StateDependentCommand(ArenaMode.All, FightState.All, "techhiderbug", this);
|
||||
super(ArenaMode.All, FightState.All, "techhiderbug");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String alias, String[] args) {
|
||||
@Register
|
||||
public void execute(Player player, String... args) {
|
||||
StringWriter writer = new StringWriter();
|
||||
|
||||
try {
|
||||
@@ -76,7 +73,6 @@ public class TechhiderbugCommand implements CommandExecutor {
|
||||
Bukkit.getLogger().log(Level.SEVERE, "Error while generating bug report", e);
|
||||
}
|
||||
|
||||
SWException.log("Techhider-Bug reported by " + sender.getName() + ": " + Arrays.toString(args), writer.toString());
|
||||
return false;
|
||||
SWException.log("Techhider-Bug reported by " + player.getName() + ": " + Arrays.toString(args), writer.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,28 +23,20 @@ import de.steamwar.fightsystem.ArenaMode;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.fight.FightWorld;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Linked
|
||||
public class WGCommand implements CommandExecutor {
|
||||
public class WGCommand extends FightSWCommand {
|
||||
|
||||
public WGCommand() {
|
||||
new StateDependentCommand(ArenaMode.Check, FightState.All, "resetwg", this);
|
||||
super(ArenaMode.Check, FightState.All, "resetwg");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
@Register
|
||||
public void execute(Player player) {
|
||||
FightWorld.resetWorld();
|
||||
Fight.getBlueTeam().pasteSchem();
|
||||
Fight.getRedTeam().pasteSchem();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,49 +25,34 @@ import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Linked
|
||||
public class WinCommand implements CommandExecutor {
|
||||
public class WinCommand extends FightSWCommand {
|
||||
|
||||
public WinCommand() {
|
||||
new StateDependentCommand(ArenaMode.Event, FightState.Ingame, "win", this);
|
||||
super(ArenaMode.Event, FightState.Ingame, "win");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
Player p = (Player) sender;
|
||||
protected boolean hasPerm(Player player, SteamwarUser user) {
|
||||
return Config.isReferee(player);
|
||||
}
|
||||
|
||||
if (!Config.isReferee(p)) {
|
||||
FightSystem.getMessage().sendPrefixless("NOT_FIGHTLEADER", p, ChatMessageType.ACTION_BAR);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args.length == 0) {
|
||||
FightSystem.getMessage().sendPrefixless("WIN_HELP", p);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("tie")) {
|
||||
@Register
|
||||
public void execute(@Validator Player player, String teamName) {
|
||||
if (teamName.equalsIgnoreCase("tie")) {
|
||||
FightSystem.setSpectateState(null, "Referee", "WIN_FIGHTLEADER");
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
for (FightTeam team : Fight.teams()) {
|
||||
if (args[0].equalsIgnoreCase(team.getName())) {
|
||||
if (teamName.equalsIgnoreCase(team.getName())) {
|
||||
FightSystem.setSpectateState(team, "Referee", "WIN_FIGHTLEADER");
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,28 @@ 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.checkType() != null && schematic.getSchemtype().name().equals(gmc.Schematic.Type.checkType().name()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if (gameModeConfig == null) gameModeConfig = GameModeConfig.getDefaults();
|
||||
return checkPermission(user, gameModeConfig);
|
||||
}
|
||||
|
||||
public static boolean checkPermission(SteamwarUser user, GameModeConfig gameModeConfig) {
|
||||
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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
});
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@
|
||||
package de.steamwar.fightsystem.record;
|
||||
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import de.steamwar.core.WorldEditWrapper;
|
||||
import de.steamwar.core.worldedit.WorldEditWrapper;
|
||||
import de.steamwar.entity.REntity;
|
||||
import de.steamwar.entity.REntityServer;
|
||||
import de.steamwar.entity.RPlayer;
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
package de.steamwar.fightsystem.states;
|
||||
|
||||
import de.steamwar.fightsystem.commands.FightSWCommand;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.*;
|
||||
@@ -62,6 +63,7 @@ public enum FightState {
|
||||
}
|
||||
|
||||
public static void setFightState(FightState state) {
|
||||
if (fightState.equals(state)) return;
|
||||
fightState = state;
|
||||
|
||||
for (Map.Entry<IStateDependent, Boolean> feature : stateDependentFeatures.entrySet()) {
|
||||
@@ -77,6 +79,7 @@ public enum FightState {
|
||||
feature.setValue(false);
|
||||
}
|
||||
}
|
||||
FightSWCommand.postFightStateChange();
|
||||
}
|
||||
|
||||
public static boolean setup() {
|
||||
|
||||
-58
@@ -1,58 +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.fightsystem.states;
|
||||
|
||||
import de.steamwar.fightsystem.ArenaMode;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class StateDependentCommand extends StateDependent {
|
||||
|
||||
private static final CommandExecutor unavailable = (sender, cmd, s, strings) -> {
|
||||
FightSystem.getMessage().sendPrefixless("COMMAND_CURRENTLY_UNAVAILABLE", sender, ChatMessageType.ACTION_BAR);
|
||||
return false;
|
||||
};
|
||||
|
||||
private final PluginCommand command;
|
||||
private final CommandExecutor executor;
|
||||
|
||||
public StateDependentCommand(Set<ArenaMode> mode, Set<FightState> states, String name, CommandExecutor executor) {
|
||||
super(mode, states);
|
||||
this.executor = executor;
|
||||
this.command = FightSystem.getPlugin().getCommand(name);
|
||||
assert command != null;
|
||||
disable();
|
||||
register();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
command.setExecutor(executor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
command.setExecutor(unavailable);
|
||||
}
|
||||
}
|
||||
@@ -10,22 +10,4 @@ depend:
|
||||
- WorldEdit
|
||||
api-version: "1.13"
|
||||
|
||||
commands:
|
||||
ak:
|
||||
request:
|
||||
requests:
|
||||
fightinfo:
|
||||
leave:
|
||||
ready:
|
||||
kit:
|
||||
remove:
|
||||
lockschem:
|
||||
state:
|
||||
skip:
|
||||
win:
|
||||
resetwg:
|
||||
resettb:
|
||||
tpslimit:
|
||||
tpswarp:
|
||||
techhiderbug:
|
||||
unrank:
|
||||
commands:
|
||||
@@ -53,3 +53,15 @@ tasks.register<FightServer>("WarGear21") {
|
||||
config = "WarGear21.yml"
|
||||
jar = "/jars/paper-1.21.6.jar"
|
||||
}
|
||||
|
||||
tasks.register<FightServer>("WarShip21") {
|
||||
group = "run"
|
||||
description = "Run a WarShip 1.21 Fight Server"
|
||||
dependsOn(":SpigotCore:shadowJar")
|
||||
dependsOn(":FightSystem:shadowJar")
|
||||
dependsOn(":KotlinCore:shadowJar")
|
||||
template = "WarShip21"
|
||||
worldName = "arenas/Artic"
|
||||
config = "WarShip21.yml"
|
||||
jar = "/jars/paper-1.21.6.jar"
|
||||
}
|
||||
|
||||
@@ -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) } }
|
||||
@@ -42,6 +42,7 @@ tasks.register<DevServer>("DevLobby") {
|
||||
group = "run"
|
||||
description = "Run a Dev Lobby"
|
||||
dependsOn(":SpigotCore:shadowJar")
|
||||
dependsOn(":KotlinCore:shadowJar")
|
||||
dependsOn(":LobbySystem:jar")
|
||||
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,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,54 @@ 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());
|
||||
AtomicReference<Long> lastModified = new AtomicReference<>(Long.MAX_VALUE);
|
||||
Bukkit.getScheduler().runTaskTimer(LobbySystem.getInstance(), () -> {
|
||||
long modified = mapFileOrDirectory.lastModified();
|
||||
Month current = LocalDateTime.now().getMonth();
|
||||
if (modified > lastModified.get() || !current.equals(lastMonth.get()) || update) {
|
||||
lastModified.set(modified);
|
||||
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 +126,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();
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
@@ -69,6 +69,7 @@ public class CustomItem extends SpecialItem {
|
||||
}
|
||||
for (File itemFile : Objects.requireNonNull(itemsFolder.listFiles())) {
|
||||
if (!itemFile.canRead() || !itemFile.isFile()) continue;
|
||||
if (!itemFile.getName().endsWith(".json")) continue;
|
||||
try {
|
||||
JsonObject jsonObject = new JsonParser().parse(new FileReader(itemFile)).getAsJsonObject();
|
||||
new CustomItem(new ScriptedItem(jsonObject));
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import de.steamwar.misslewars.scripts.RunnableScriptEvent;
|
||||
import de.steamwar.misslewars.scripts.ScriptedItem;
|
||||
import de.steamwar.misslewars.scripts.utils.EntityUtils;
|
||||
import de.steamwar.misslewars.scripts.utils.EntityUtils.ScriptShortcut;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Projectile;
|
||||
|
||||
public class LaunchScript implements RunnableScript {
|
||||
|
||||
@@ -75,6 +75,11 @@ public class EntityUtils {
|
||||
});
|
||||
case "arrow":
|
||||
return new ScriptShortcut<>(Arrow.class, (jsonObject, entity, runnableScriptEvent) -> setProjectileOptions(entity, jsonObject));
|
||||
case "windcharge":
|
||||
return new ScriptShortcut<>(WindCharge.class, (jsonObject, entity, runnableScriptEvent) -> {
|
||||
setFireballOptions(entity, jsonObject);
|
||||
entity.setDirection(runnableScriptEvent.getLocation().getDirection());
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -269,7 +269,7 @@ AUTO_CHECKER_RESULT_DEFUNCT_NBT = §7Defunct NBT: §7[{0}, {1}, {2}]
|
||||
AUTO_CHECKER_RESULT_DESIGN_BLOCK = §7{0} in Design: [{1}, {2}, {3}]
|
||||
AUTO_CHECKER_RESULT_ENTITY = §7Entity: §7[{0}, {1}, {2}]
|
||||
AUTO_CHECKER_RESULT_RECORD = §7Record: §c[{0}, {1}, {2}]
|
||||
AUTO_CHECKER_RESULT_TOO_MANY_DISPENSER_ITEMS = §7Dispenser: §c[{0}, {1}, {2}]§7, §c{3} §7items, Max: §e{4}
|
||||
AUTO_CHECKER_RESULT_TOO_MANY_INVENTORY_ITEMS = §7{6}: §c[{0}, {1}, {2}]§7, §c{3}x {5}§7, Max: §e{4}
|
||||
AUTO_CHECKER_RESULT_FORBIDDEN_ITEM_NBT = §7Forbidden Item NBT: [{0}, {1}, {2}] -> §c{3}
|
||||
AUTO_CHECKER_RESULT_TELEPORT_HERE = §7Teleport to block
|
||||
AUTO_CHECKER_RESULT_AFTER_DEADLINE = §cThe deadline has expired: {0}
|
||||
|
||||
@@ -248,7 +248,7 @@ AUTO_CHECKER_RESULT_FORBIDDEN_ITEM = §7Verbotener gegenstand: [{0}, {1}, {2}] -
|
||||
AUTO_CHECKER_RESULT_DEFUNCT_NBT = §7Keine NBT-Daten: §c[{0}, {1}, {2}]
|
||||
AUTO_CHECKER_RESULT_DESIGN_BLOCK = §7{0} im Design: [{1}, {2}, {3}]
|
||||
AUTO_CHECKER_RESULT_RECORD = §7Schallplatte: §c[{0}, {1}, {2}]
|
||||
AUTO_CHECKER_RESULT_TOO_MANY_DISPENSER_ITEMS = §7Dispenser: §c[{0}, {1}, {2}]§7, §c{3} §7gegenstände, Max: §e{4}
|
||||
AUTO_CHECKER_RESULT_TOO_MANY_INVENTORY_ITEMS = §7{6}: §c[{0}, {1}, {2}]§7, §c{3}x {5}§7, Max: §e{4}
|
||||
AUTO_CHECKER_RESULT_FORBIDDEN_ITEM_NBT = §7Verbotene NBT-Daten: [{0}, {1}, {2}] -> §c{3}
|
||||
AUTO_CHECKER_RESULT_TELEPORT_HERE = §7Zum block teleportieren
|
||||
AUTO_CHECKER_RESULT_AFTER_DEADLINE = §cDer einsendeschluss ist bereits vorbei: {0}
|
||||
|
||||
@@ -37,17 +37,27 @@ 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().x()).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()))
|
||||
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().y()).width(clipboard.getDimensions().x())
|
||||
.depth(clipboard.getDimensions().z()).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) {
|
||||
@@ -63,14 +73,19 @@ public class AutoChecker {
|
||||
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);
|
||||
if (type.Schematic.isInventory(material)) {
|
||||
checkInventory(result, block, material, pos, type);
|
||||
if (!result.getInventoryItemCounts().getOrDefault(pos, Collections.emptyMap()).isEmpty()) {
|
||||
result.getBlockCounts().merge(material, 1, Integer::sum);
|
||||
}
|
||||
} else {
|
||||
result.getBlockCounts().merge(material, 1, Integer::sum);
|
||||
}
|
||||
|
||||
if (x == min.x() || x == max.x() || y == max.y() || z == min.z() || z == max.z()) {
|
||||
result.getDesignBlocks().computeIfAbsent(material, m -> new ArrayList<>()).add(new BlockPos(x, y, z));
|
||||
result.getDesignBlocks().computeIfAbsent(material, m -> new ArrayList<>()).add(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -78,19 +93,6 @@ public class AutoChecker {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static final Map<Material, Set<Material>> itemsInInv = new EnumMap<>(Material.class);
|
||||
|
||||
static {
|
||||
itemsInInv.put(Material.BUCKET, EnumSet.of(Material.DISPENSER));
|
||||
itemsInInv.put(Material.TNT, EnumSet.of(Material.CHEST, Material.BARREL, Material.SHULKER_BOX, Material.BLACK_SHULKER_BOX, Material.BLUE_SHULKER_BOX,
|
||||
Material.BROWN_SHULKER_BOX, Material.CYAN_SHULKER_BOX, Material.GRAY_SHULKER_BOX, Material.GREEN_SHULKER_BOX, Material.LIGHT_BLUE_SHULKER_BOX,
|
||||
Material.LIGHT_GRAY_SHULKER_BOX, Material.LIME_SHULKER_BOX, Material.MAGENTA_SHULKER_BOX, Material.ORANGE_SHULKER_BOX,
|
||||
Material.PINK_SHULKER_BOX, Material.PURPLE_SHULKER_BOX, Material.RED_SHULKER_BOX, Material.WHITE_SHULKER_BOX, Material.YELLOW_SHULKER_BOX));
|
||||
itemsInInv.put(Material.FIRE_CHARGE, EnumSet.of(Material.DISPENSER));
|
||||
itemsInInv.put(Material.ARROW, EnumSet.of(Material.DISPENSER));
|
||||
AutoCheckerItems.impl.getAllowedMaterialsInInventory().forEach(material -> itemsInInv.put(material, AutoCheckerItems.impl.getInventoryMaterials()));
|
||||
}
|
||||
|
||||
private void checkInventory(AutoChecker.BlockScanResult result, BaseBlock block, Material material, BlockPos pos, GameModeConfig<Material, String> type) {
|
||||
CompoundTag nbt = block.getNbtData();
|
||||
if (nbt == null) {
|
||||
@@ -107,7 +109,7 @@ public class AutoChecker {
|
||||
List<CompoundTag> items = nbt.getList("Items", CompoundTag.class);
|
||||
if (items.isEmpty()) return; // Leeres Inventar
|
||||
|
||||
int counter = 0;
|
||||
Map<Material, Integer> itemCounts = new EnumMap<>(Material.class);
|
||||
int windChargeCount = 0;
|
||||
for (CompoundTag item : items) {
|
||||
if (!item.containsKey("id")) {
|
||||
@@ -121,16 +123,19 @@ public class AutoChecker {
|
||||
|
||||
if (type.Schematic.Type.getName().equals("wargearseason26") && material == Material.DISPENSER && itemType == Material.WIND_CHARGE) {
|
||||
windChargeCount += item.getInt("count");
|
||||
} else if (!itemsInInv.getOrDefault(itemType, EnumSet.noneOf(Material.class)).contains(material)) {
|
||||
} else if (type.Schematic.getItemAmount(material, itemType) == 0) {
|
||||
result.getForbiddenItems().computeIfAbsent(pos, blockVector3 -> new HashSet<>()).add(itemType);
|
||||
} else if (material == Material.DISPENSER && (itemType == Material.ARROW || itemType == Material.FIRE_CHARGE)) {
|
||||
counter += item.getInt("count");
|
||||
} else {
|
||||
itemCounts.merge(itemType, item.getInt("count"), Integer::sum);
|
||||
}
|
||||
if (item.containsKey("tag")) {
|
||||
result.getForbiddenNbt().computeIfAbsent(pos, blockVector3 -> new HashSet<>()).add(itemType);
|
||||
}
|
||||
}
|
||||
result.getDispenserItems().put(pos, counter);
|
||||
if (!itemCounts.isEmpty()) {
|
||||
result.getInventoryItemCounts().put(pos, itemCounts);
|
||||
result.getInventoryBlockType().put(pos, material);
|
||||
}
|
||||
result.getWindChargeCount().put(pos, windChargeCount);
|
||||
}
|
||||
|
||||
@@ -141,7 +146,8 @@ public class AutoChecker {
|
||||
private final List<BlockPos> defunctNbt = new ArrayList<>();
|
||||
private final List<BlockPos> records = new ArrayList<>();
|
||||
private final Map<Material, List<BlockPos>> designBlocks = new EnumMap<>(Material.class);
|
||||
private final Map<BlockPos, Integer> dispenserItems = new HashMap<>();
|
||||
private final Map<BlockPos, Map<Material, Integer>> inventoryItemCounts = new HashMap<>();
|
||||
private final Map<BlockPos, Material> inventoryBlockType = new HashMap<>();
|
||||
private final Map<BlockPos, Integer> windChargeCount = new HashMap<>();
|
||||
private final Map<BlockPos, Set<Material>> forbiddenItems = new HashMap<>();
|
||||
private final Map<BlockPos, Set<Material>> forbiddenNbt = new HashMap<>();
|
||||
|
||||
@@ -1,51 +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.schematicsystem.autocheck;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class AutoCheckerItems {
|
||||
|
||||
public static final AutoCheckerItems impl = new AutoCheckerItems();
|
||||
|
||||
private static final Set<Material> INVENTORY = EnumSet.of(Material.BARREL, Material.BLAST_FURNACE, Material.BREWING_STAND, Material.CAMPFIRE,
|
||||
Material.CHEST, Material.DISPENSER, Material.DROPPER, Material.FURNACE, Material.HOPPER, Material.JUKEBOX, Material.SHULKER_BOX,
|
||||
Material.WHITE_SHULKER_BOX, Material.ORANGE_SHULKER_BOX, Material.MAGENTA_SHULKER_BOX, Material.LIGHT_BLUE_SHULKER_BOX, Material.YELLOW_SHULKER_BOX,
|
||||
Material.LIME_SHULKER_BOX, Material.PINK_SHULKER_BOX, Material.GRAY_SHULKER_BOX, Material.LIGHT_GRAY_SHULKER_BOX, Material.CYAN_SHULKER_BOX,
|
||||
Material.PURPLE_SHULKER_BOX, Material.BLUE_SHULKER_BOX, Material.BROWN_SHULKER_BOX, Material.GREEN_SHULKER_BOX, Material.RED_SHULKER_BOX,
|
||||
Material.BLACK_SHULKER_BOX, Material.SMOKER, Material.TRAPPED_CHEST);
|
||||
|
||||
private static final Set<Material> FLOWERS = EnumSet.of(Material.CORNFLOWER, Material.POPPY, Material.FERN, Material.DANDELION, Material.BLUE_ORCHID,
|
||||
Material.ALLIUM, Material.AZURE_BLUET, Material.RED_TULIP, Material.ORANGE_TULIP, Material.WHITE_TULIP, Material.PINK_TULIP, Material.OXEYE_DAISY,
|
||||
Material.LILY_OF_THE_VALLEY, Material.WITHER_ROSE, Material.SUNFLOWER, Material.DIAMOND_HORSE_ARMOR, Material.IRON_HORSE_ARMOR,
|
||||
Material.GOLDEN_HORSE_ARMOR, Material.LEATHER_HORSE_ARMOR, Material.HONEY_BOTTLE, Material.LILAC, Material.ROSE_BUSH, Material.PEONY,
|
||||
Material.TALL_GRASS, Material.LARGE_FERN);
|
||||
|
||||
public Set<Material> getInventoryMaterials() {
|
||||
return INVENTORY;
|
||||
}
|
||||
|
||||
public Set<Material> getAllowedMaterialsInInventory() {
|
||||
return FLOWERS;
|
||||
}
|
||||
}
|
||||
@@ -50,7 +50,7 @@ public class AutoCheckerResult {
|
||||
isSizeOk() &&
|
||||
isBlockCountOk() &&
|
||||
isLimitedBlocksOK() &&
|
||||
isDispenserItemsOK() &&
|
||||
isInventoryItemsOK() &&
|
||||
isWindchargeCountOK() &&
|
||||
!type.isAfterDeadline() &&
|
||||
entities.isEmpty() &&
|
||||
@@ -71,8 +71,14 @@ public class AutoCheckerResult {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isDispenserItemsOK() {
|
||||
return blockScanResult.getDispenserItems().values().stream().allMatch(i -> i <= type.Schematic.MaxDispenserItems);
|
||||
public boolean isInventoryItemsOK() {
|
||||
return blockScanResult.getInventoryItemCounts().entrySet().stream().allMatch(posEntry -> {
|
||||
Material inventory = blockScanResult.getInventoryBlockType().get(posEntry.getKey());
|
||||
return posEntry.getValue().entrySet().stream().allMatch(itemEntry -> {
|
||||
int cap = type.Schematic.getItemAmount(inventory, itemEntry.getKey());
|
||||
return itemEntry.getValue() <= cap;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public boolean hasWarnings() {
|
||||
@@ -100,13 +106,8 @@ public class AutoCheckerResult {
|
||||
}
|
||||
|
||||
public boolean isLimitedBlocksOK() {
|
||||
try {
|
||||
return type.Schematic.Limited.entrySet().stream()
|
||||
.map(setIntegerEntry -> setIntegerEntry.getKey().stream().map(blockScanResult.getBlockCounts()::get).map(i -> i == null || i <= setIntegerEntry.getValue()).reduce(Boolean::logicalAnd).orElse(false))
|
||||
.reduce(Boolean::logicalAnd).orElse(true);
|
||||
} catch (NullPointerException e) {
|
||||
return false;
|
||||
}
|
||||
return blockScanResult.getBlockCounts().entrySet().stream()
|
||||
.allMatch(entry -> entry.getValue() <= type.Schematic.getMaxCount(entry.getKey()));
|
||||
}
|
||||
|
||||
public boolean isDesignBlastResistanceOK() {
|
||||
@@ -130,14 +131,13 @@ public class AutoCheckerResult {
|
||||
SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_BLOCKS", p, blockScanResult.getBlockCounts().values().stream().reduce(Integer::sum).orElse(0), type.Schematic.MaxBlocks);
|
||||
}
|
||||
if (!isLimitedBlocksOK()) {
|
||||
type.Schematic.Limited.forEach((materials, integer) -> {
|
||||
for (Material mat : materials) {
|
||||
if (mat != null && blockScanResult.getBlockCounts().getOrDefault(mat, 0) > integer) {
|
||||
if (integer == 0) {
|
||||
SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_FORBIDDEN_BLOCK", p, mat.name());
|
||||
} else {
|
||||
SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_TOO_MANY_BLOCK", p, mat.name(), blockScanResult.getBlockCounts().getOrDefault(mat, 0), integer);
|
||||
}
|
||||
blockScanResult.getBlockCounts().forEach((mat, count) -> {
|
||||
int maxCount = type.Schematic.getMaxCount(mat);
|
||||
if (count > maxCount) {
|
||||
if (maxCount == 0) {
|
||||
SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_FORBIDDEN_BLOCK", p, mat.name());
|
||||
} else {
|
||||
SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_TOO_MANY_BLOCK", p, mat.name(), count, maxCount);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -155,13 +155,20 @@ public class AutoCheckerResult {
|
||||
});
|
||||
}
|
||||
|
||||
blockScanResult.getDispenserItems().entrySet().stream().filter(blockVector3IntegerEntry -> blockVector3IntegerEntry.getValue() > type.Schematic.MaxDispenserItems).forEach(blockVector3IntegerEntry -> {
|
||||
SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_TOO_MANY_DISPENSER_ITEMS", p, SchematicSystem.MESSAGE.parse("AUTO_CHECKER_RESULT_TELEPORT_HERE", p), tpCommandTo(blockVector3IntegerEntry.getKey()),
|
||||
blockVector3IntegerEntry.getKey().getBlockX(),
|
||||
blockVector3IntegerEntry.getKey().getBlockY(),
|
||||
blockVector3IntegerEntry.getKey().getBlockZ(),
|
||||
blockVector3IntegerEntry.getValue(),
|
||||
type.Schematic.MaxDispenserItems);
|
||||
blockScanResult.getInventoryItemCounts().forEach((pos, itemCounts) -> {
|
||||
Material inventory = blockScanResult.getInventoryBlockType().get(pos);
|
||||
itemCounts.forEach((itemType, count) -> {
|
||||
int cap = type.Schematic.getItemAmount(inventory, itemType);
|
||||
if (count <= cap) return;
|
||||
SchematicSystem.MESSAGE.sendPrefixless("AUTO_CHECKER_RESULT_TOO_MANY_INVENTORY_ITEMS", p, SchematicSystem.MESSAGE.parse("AUTO_CHECKER_RESULT_TELEPORT_HERE", p), tpCommandTo(pos),
|
||||
pos.getBlockX(),
|
||||
pos.getBlockY(),
|
||||
pos.getBlockZ(),
|
||||
count,
|
||||
cap,
|
||||
itemType.name(),
|
||||
inventory.name());
|
||||
});
|
||||
});
|
||||
|
||||
blockScanResult.getRecords().forEach(blockVector3 -> {
|
||||
|
||||
+14
-10
@@ -197,27 +197,31 @@ public class SchematicCommand extends SWCommand {
|
||||
clipboard.setBlock(vector, block.toBaseBlock(builder.build()));
|
||||
}
|
||||
|
||||
if (type.Schematic.MaxDispenserItems > 0) {
|
||||
for (Map.Entry<BlockPos, Integer> entry : result.getBlockScanResult().getDispenserItems().entrySet()) {
|
||||
if (entry.getValue() <= type.Schematic.MaxDispenserItems) {
|
||||
for (Map.Entry<BlockPos, Map<Material, Integer>> posEntry : result.getBlockScanResult().getInventoryItemCounts().entrySet()) {
|
||||
BlockPos pos = posEntry.getKey();
|
||||
Material inventory = result.getBlockScanResult().getInventoryBlockType().get(pos);
|
||||
|
||||
for (Map.Entry<Material, Integer> itemEntry : posEntry.getValue().entrySet()) {
|
||||
Material itemType = itemEntry.getKey();
|
||||
Integer cap = type.Schematic.getItemAmount(inventory, itemType);
|
||||
if (itemEntry.getValue() <= cap) {
|
||||
continue;
|
||||
}
|
||||
|
||||
BlockPos pos = entry.getKey();
|
||||
BlockVector3 vector = BlockVector3.at(pos.getX(), pos.getY(), pos.getZ());
|
||||
BaseBlock block = clipboard.getFullBlock(vector);
|
||||
CompoundTag tag = block.getNbtData();
|
||||
CompoundTagBuilder builder = tag.createBuilder();
|
||||
List<CompoundTag> items = new ArrayList<>(tag.getList("Items", CompoundTag.class));
|
||||
Collections.reverse(items); // To let the first item be in the Dispenser
|
||||
Collections.reverse(items); // To let the first item be in the inventory
|
||||
List<CompoundTag> list = new ArrayList<>();
|
||||
int diff = entry.getValue() - type.Schematic.MaxDispenserItems;
|
||||
int diff = itemEntry.getValue() - cap;
|
||||
for (CompoundTag item : items) {
|
||||
if (item == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (diff == 0) {
|
||||
if (diff == 0 || Material.matchMaterial(item.getString("id")) != itemType) {
|
||||
list.add(item);
|
||||
continue;
|
||||
}
|
||||
@@ -238,9 +242,9 @@ public class SchematicCommand extends SWCommand {
|
||||
}
|
||||
|
||||
if (!result.isLimitedBlocksOK()) {
|
||||
Set<Material> toReplace = type.Schematic.Limited.entrySet().stream()
|
||||
.filter(setIntegerEntry -> setIntegerEntry.getValue() == 0)
|
||||
.flatMap(setIntegerEntry -> setIntegerEntry.getKey().stream())
|
||||
Set<Material> toReplace = type.Schematic.Limited.stream()
|
||||
.filter(rule -> rule.Amount == 0)
|
||||
.flatMap(rule -> rule.Materials.stream())
|
||||
.collect(Collectors.toSet());
|
||||
BlockState replaceType = Objects.requireNonNull(toReplace.contains(Material.END_STONE) ? BlockTypes.IRON_BLOCK : BlockTypes.END_STONE).getDefaultState();
|
||||
BlockVector3 min = clipboard.getMinimumPoint();
|
||||
|
||||
@@ -108,19 +108,33 @@ UNNOSCHEMSUBMITTING = §e{0} §7may now submit §e§lschematics§7 again§8.
|
||||
|
||||
WORLDEDIT_CUI_TITLE = WorldEdit CUI
|
||||
WORLDEDIT_CUI_TITLE_SUBMENU = WorldEdit CUI - {0}
|
||||
WORLDEDIT_CUI_SELECTION = Own Selection
|
||||
WORLDEDIT_CUI_CLIPBOARD = Own Clipboard
|
||||
WORLDEDIT_CUI_SELECTION_OTHER = Other Selection
|
||||
WORLDEDIT_CUI_CLIPBOARD_OTHER = Other Clipboard
|
||||
WORLDEDIT_CUI_SELECTION = Selection
|
||||
WORLDEDIT_CUI_CLIPBOARD = Clipboard
|
||||
WORLDEDIT_CUI_CURSOR = Cursor
|
||||
|
||||
WORLDEDIT_CUI_MATERIAL_NAME = §eWorldEdit {0}
|
||||
WORLDEDIT_CUI_MATERIAL_CLICK = §7Click to edit
|
||||
|
||||
WORLDEDIT_CUI_WIDTH_NAME = §eWidth {0}
|
||||
WORLDEDIT_CUI_WIDTH_NAME_DIST = §eRange {0}
|
||||
WORLDEDIT_CUI_WIDTH_LORE = §8> §7{0}
|
||||
WORLDEDIT_CUI_WIDTH_LORE_SELECTED = §8> §e{0}
|
||||
WORLDEDIT_CUI_WIDTH_CLICK = §7Click to change
|
||||
|
||||
WORLDEDIT_CUI_WIDTH_HUGE = 1/ 8 Block
|
||||
WORLDEDIT_CUI_WIDTH_LARGE = 1/16 Block
|
||||
WORLDEDIT_CUI_WIDTH_MEDIUM = 1/32 Block
|
||||
WORLDEDIT_CUI_WIDTH_SLIM = 1/64 Block
|
||||
WORLDEDIT_CUI_WIDTH_SLIM = 1/64 Block
|
||||
|
||||
WORLDEDIT_CUI_WIDTH_HUGE_DIST = 40 Blocks
|
||||
WORLDEDIT_CUI_WIDTH_LARGE_DIST = 30 Blocks
|
||||
WORLDEDIT_CUI_WIDTH_MEDIUM_DIST = 20 Blocks
|
||||
WORLDEDIT_CUI_WIDTH_SLIM_DIST = 10 Blocks
|
||||
|
||||
WORLDEDIT_CUI_TOOL_SOON = §7Tool cooming soon!
|
||||
WORLDEDIT_CUI_TOOL_COPY = §eCopy Tool
|
||||
WORLDEDIT_CUI_TOOL_COPY_LORE = §eClick§8:§7 copy selection
|
||||
WORLDEDIT_CUI_TOOL_PASTE = §ePaste Tool
|
||||
WORLDEDIT_CUI_TOOL_PASTE_LORE_1 = §eClick§8:§7 paste clipboard
|
||||
WORLDEDIT_CUI_TOOL_PASTE_LORE_2 = §eShift §8+§e Click§8:§7 paste clipboard and select
|
||||
WORLDEDIT_CUI_TOOL_PASTE_LORE_3 = §eDrop§8:§7 paste clipboard at copy origin
|
||||
@@ -101,13 +101,20 @@ NOSCHEMSUBMITTING_UNTIL = §7Du bist §ebis zum {0} §7vom §e§lEinsenden von S
|
||||
UNNOSCHEMSUBMITTING_ERROR = §cDer Spieler ist nicht vom Einsenden von Schematics ausgeschlossen.
|
||||
UNNOSCHEMSUBMITTING = §e{0} §7darf nun wieder §e§lSchematis§7 einsenden§8.
|
||||
|
||||
WORLDEDIT_CUI_SELECTION = Eigene Auswahl
|
||||
WORLDEDIT_CUI_CLIPBOARD = Eigene Kopie
|
||||
WORLDEDIT_CUI_SELECTION_OTHER = Auswahl Anderer
|
||||
WORLDEDIT_CUI_CLIPBOARD_OTHER = Kopie Anderer
|
||||
WORLDEDIT_CUI_SELECTION = Auswahl
|
||||
WORLDEDIT_CUI_CLIPBOARD = Kopie
|
||||
|
||||
WORLDEDIT_CUI_MATERIAL_NAME = §eWorldEdit {0}
|
||||
WORLDEDIT_CUI_MATERIAL_CLICK = §7Klicke zum Editieren
|
||||
|
||||
WORLDEDIT_CUI_WIDTH_NAME = §eDicke - {0}
|
||||
WORLDEDIT_CUI_WIDTH_CLICK = §7Klicke zum ändern
|
||||
WORLDEDIT_CUI_WIDTH_NAME = §eKlicke - {0}
|
||||
WORLDEDIT_CUI_WIDTH_NAME_DIST = Reichweite§e {0}
|
||||
WORLDEDIT_CUI_WIDTH_CLICK = §7Klicke zum ändern
|
||||
|
||||
WORLDEDIT_CUI_TOOL_SOON = §7Werkzeug kommt in kürze!
|
||||
WORLDEDIT_CUI_TOOL_COPY = §eCopy Werkzeug
|
||||
WORLDEDIT_CUI_TOOL_COPY_LORE = §eKlick§8:§7 Auswahl zu kopieren
|
||||
WORLDEDIT_CUI_TOOL_PASTE = §ePaste Werkzeug
|
||||
WORLDEDIT_CUI_TOOL_PASTE_LORE_1 = §eKlick§8:§7 Clipboard einzufügen
|
||||
WORLDEDIT_CUI_TOOL_PASTE_LORE_2 = §eUmschalt §8+§e Klick§8:§7 Clipboard einzufügen und auszuwählen
|
||||
WORLDEDIT_CUI_TOOL_PASTE_LORE_3 = §eDrop§8:§7 Clipboard am Kopierpunkt einzufügen
|
||||
@@ -21,8 +21,8 @@ package de.steamwar.core;
|
||||
|
||||
import de.steamwar.message.Message;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.experimental.Delegate;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -99,11 +99,11 @@ public class SWPlayer {
|
||||
|
||||
@Data
|
||||
public static final class SWPlayerWithComponent<T extends Component> {
|
||||
private final SWPlayer player;
|
||||
private final SWPlayer swPlayer;
|
||||
private final T component;
|
||||
}
|
||||
|
||||
@Delegate
|
||||
@Getter
|
||||
private final Player player;
|
||||
private final Map<Class<? extends Component>, Component> components = new HashMap<>();
|
||||
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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.core.worldedit;
|
||||
|
||||
import de.steamwar.command.SWCommand;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Function;
|
||||
|
||||
@UtilityClass
|
||||
public class SteamEdit {
|
||||
|
||||
private static final AtomicBoolean INITIALIZED = new AtomicBoolean();
|
||||
|
||||
public static void init() {
|
||||
INITIALIZED.set(true);
|
||||
new Command();
|
||||
new SteamEditWand();
|
||||
new WorldEditRendererCUIEditor();
|
||||
}
|
||||
|
||||
public boolean isInitialized() {
|
||||
return INITIALIZED.get();
|
||||
}
|
||||
|
||||
public static Function<Location, AdjacentFilter> ADJACENT_FILTERS = location -> AdjacentFilter.ALWAYS;
|
||||
|
||||
public interface AdjacentFilter {
|
||||
AdjacentFilter ALWAYS = (x, y, z) -> true;
|
||||
|
||||
boolean contains(int x, int y, int z);
|
||||
}
|
||||
|
||||
private static final class Command extends SWCommand {
|
||||
|
||||
public Command() {
|
||||
super("steamwand", "steamedit", "steameditwand", "swwand", "sweditwand", "swedit");
|
||||
}
|
||||
|
||||
@Register
|
||||
public void get(Player player) {
|
||||
if (player.getInventory().contains(SteamEditWand.ITEM)) {
|
||||
player.getInventory().remove(SteamEditWand.ITEM);
|
||||
}
|
||||
ItemStack handItem = player.getInventory().getItemInMainHand();
|
||||
player.getInventory().setItemInMainHand(SteamEditWand.ITEM);
|
||||
if (!handItem.isEmpty()) {
|
||||
player.getInventory().addItem(handItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+117
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* 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.core.worldedit;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import de.steamwar.core.Core;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class SteamEditSelectAdjacent {
|
||||
|
||||
private static final BlockFace[] FACES = {
|
||||
BlockFace.NORTH,
|
||||
BlockFace.SOUTH,
|
||||
BlockFace.EAST,
|
||||
BlockFace.WEST,
|
||||
BlockFace.UP,
|
||||
BlockFace.DOWN,
|
||||
};
|
||||
|
||||
private Location min;
|
||||
private Location max;
|
||||
|
||||
private SteamEdit.AdjacentFilter filter;
|
||||
|
||||
private LinkedHashSet<Location> frontier = new LinkedHashSet<>();
|
||||
|
||||
public SteamEditSelectAdjacent(Location origin) {
|
||||
// TODO: Fix the flood fill algorithm!
|
||||
min = origin.clone();
|
||||
max = origin.clone();
|
||||
frontier.add(origin);
|
||||
filter = SteamEdit.ADJACENT_FILTERS.apply(origin);
|
||||
|
||||
long time = System.currentTimeMillis();
|
||||
for (int i = 0; i < 500_000 && !frontier.isEmpty(); i++) {
|
||||
if (System.currentTimeMillis() - time > 1000) break;
|
||||
expandNext();
|
||||
}
|
||||
|
||||
Core.getInstance().getLogger().finer(System.currentTimeMillis() - time + "ms " + frontier.size() + " " + min + " to " + max);
|
||||
}
|
||||
|
||||
public BlockVector3 pos1() {
|
||||
return BlockVector3.at(min.getBlockX(), min.getBlockY(), min.getBlockZ());
|
||||
}
|
||||
|
||||
public BlockVector3 pos2() {
|
||||
return BlockVector3.at(max.getBlockX(), max.getBlockY(), max.getBlockZ());
|
||||
}
|
||||
|
||||
private boolean inside(Location loc, int offset) {
|
||||
return loc.getBlockX() >= min.getBlockX() + offset && loc.getBlockX() <= max.getBlockX() - offset &&
|
||||
loc.getBlockY() >= min.getBlockY() + offset && loc.getBlockY() <= max.getBlockY() - offset &&
|
||||
loc.getBlockZ() >= min.getBlockZ() + offset && loc.getBlockZ() <= max.getBlockZ() - offset;
|
||||
}
|
||||
|
||||
public void expandNext() {
|
||||
Location location = frontier.removeFirst();
|
||||
expand(location);
|
||||
}
|
||||
|
||||
private void expand(Location loc) {
|
||||
for (BlockFace face : FACES) {
|
||||
Vector direction = face.getDirection();
|
||||
Location location = loc.clone().add(direction);
|
||||
if (!filter.contains(location.getBlockX(), location.getBlockY(), location.getBlockZ())) continue;
|
||||
if (inside(location, 0)) continue;
|
||||
List<Location> layer = Stream.concat(selectFrontier(direction.getBlockX() == 0 ? null : loc.getBlockX(), direction.getBlockY() == 0 ? null : loc.getBlockY(), direction.getBlockZ() == 0 ? null : loc.getBlockZ())
|
||||
.map(Location::clone)
|
||||
.map(l -> l.add(direction)), Stream.of(location))
|
||||
.filter(l -> !l.getBlock().isEmpty())
|
||||
.filter(l -> !l.getBlock().isLiquid())
|
||||
.toList();
|
||||
if (layer.isEmpty()) continue;
|
||||
|
||||
if (direction.getBlockX() < 0 || direction.getBlockY() < 0 || direction.getBlockZ() < 0) {
|
||||
min.add(direction);
|
||||
} else {
|
||||
max.add(direction);
|
||||
}
|
||||
layer.stream().filter(l -> !inside(l, 1))
|
||||
.filter(l -> filter.contains(l.getBlockX(), l.getBlockY(), l.getBlockZ()))
|
||||
.forEach(frontier::add);
|
||||
}
|
||||
}
|
||||
|
||||
private Stream<Location> selectFrontier(Integer x, Integer y, Integer z) {
|
||||
Stream<Location> stream = frontier.stream();
|
||||
if (x != null) stream = stream.filter(loc -> loc.getBlockX() == x);
|
||||
if (y != null) stream = stream.filter(loc -> loc.getBlockY() == y);
|
||||
if (z != null) stream = stream.filter(loc -> loc.getBlockZ() == z);
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,409 @@
|
||||
/*
|
||||
* 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.core.worldedit;
|
||||
|
||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.limit.PermissiveSelectorLimits;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.core.SWPlayer;
|
||||
import de.steamwar.entity.CWireframe;
|
||||
import de.steamwar.entity.REntityServer;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.game.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.FluidCollisionMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.bukkit.util.RayTraceResult;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SteamEditWand implements Listener {
|
||||
|
||||
public static final Material MATERIAL = Material.GOLDEN_AXE;
|
||||
public static final String NAME = "§eSteam§8Edit §7Wand";
|
||||
public static final String[] LORE = {
|
||||
"§eL-Click§8: §7Set Pos1",
|
||||
"§eR-Click§8: §7Set Pos2",
|
||||
"§eShift §8+ §eR-Click§8: §7Set Pos2 or Expand Selection",
|
||||
"§eM-Click§8: §7Select connected",
|
||||
"§eSwap-Hands§8: §7Open CUI"
|
||||
};
|
||||
public static final ItemStack ITEM = new SWItem(MATERIAL, NAME).setLore(LORE).getItemStack();
|
||||
|
||||
private boolean noWand(Player player) {
|
||||
return player.getInventory().getItemInMainHand().getType() != SteamEditWand.MATERIAL;
|
||||
}
|
||||
|
||||
private final WorldEditPlugin we;
|
||||
|
||||
SteamEditWand() {
|
||||
we = WorldEditWrapper.getWorldEditPlugin();
|
||||
Bukkit.getPluginManager().registerEvents(this, Core.getInstance());
|
||||
|
||||
TinyProtocol.instance.addFilter(ServerboundSwingPacket.class, this::leftClick);
|
||||
TinyProtocol.instance.addFilter(ServerboundInteractPacket.class, (player, packet) -> {
|
||||
if (packet.isAttack()) {
|
||||
return leftClick(player, packet);
|
||||
} else {
|
||||
return rightClick(player, packet);
|
||||
}
|
||||
});
|
||||
TinyProtocol.instance.addFilter(ServerboundUseItemPacket.class, this::rightClick);
|
||||
TinyProtocol.instance.addFilter(ServerboundUseItemOnPacket.class, this::rightClick);
|
||||
TinyProtocol.instance.addFilter(ServerboundPickItemFromBlockPacket.class, this::middleClick);
|
||||
TinyProtocol.instance.addFilter(ServerboundPlayerActionPacket.class, this::swapHands);
|
||||
TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.Pos.class, this::movePlayerPacket);
|
||||
TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.Rot.class, this::movePlayerPacket);
|
||||
TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.PosRot.class, this::movePlayerPacket);
|
||||
|
||||
Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (noWand(player)) SWPlayer.of(player).removeComponent(SWEditCursor.class);
|
||||
}
|
||||
}, 1, 1);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (noWand(event.getPlayer())) return;
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
public static class SWEditCursor implements SWPlayer.Component {
|
||||
private Player player;
|
||||
private REntityServer entityServer = new REntityServer();
|
||||
private CWireframe wireframe;
|
||||
|
||||
@Override
|
||||
public void onMount(SWPlayer player) {
|
||||
this.player = player.getPlayer();
|
||||
entityServer.addPlayer(player.getPlayer());
|
||||
wireframe = new CWireframe(entityServer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnmount(SWPlayer player) {
|
||||
entityServer.close();
|
||||
}
|
||||
|
||||
public void setLocation(Location location) {
|
||||
wireframe.setPos1And2(location, location);
|
||||
wireframe.setBlock(WorldEditRendererCUIEditor.Type.CURSOR.getMaterial(player).createBlockData());
|
||||
}
|
||||
}
|
||||
|
||||
private Packet<?> leftClick(Player player, Packet<?> packet) {
|
||||
if (noWand(player)) return packet;
|
||||
if (player.getOpenInventory().getType() != InventoryType.CREATIVE) return packet;
|
||||
double distance = WorldEditRendererCUIEditor.Type.CURSOR.getWidth(player).blocks;
|
||||
RayTraceResult result = player.rayTraceBlocks(distance, FluidCollisionMode.NEVER);
|
||||
if (result == null) return packet;
|
||||
Block block = result.getHitBlock();
|
||||
if (block == null) return packet;
|
||||
BlockVector3 pos1 = BlockVector3.at(block.getX(), block.getY(), block.getZ());
|
||||
setPos1(player, pos1);
|
||||
return null;
|
||||
}
|
||||
|
||||
private void setPos1(Player player, BlockVector3 pos1) {
|
||||
LocalSession session = we.getSession(player);
|
||||
World world = session.getSelectionWorld();
|
||||
if (world == null) return;
|
||||
selectPos1(session.getRegionSelector(world), player, session, pos1);
|
||||
}
|
||||
|
||||
private Packet<?> rightClick(Player player, Packet<?> packet) {
|
||||
if (noWand(player)) return packet;
|
||||
double distance = WorldEditRendererCUIEditor.Type.CURSOR.getWidth(player).blocks;
|
||||
RayTraceResult result = player.rayTraceBlocks(distance, FluidCollisionMode.NEVER);
|
||||
if (result == null) return packet;
|
||||
Block block = result.getHitBlock();
|
||||
if (block == null) return packet;
|
||||
BlockVector3 pos2 = BlockVector3.at(block.getX(), block.getY(), block.getZ());
|
||||
if (!player.isSneaking()) {
|
||||
setPos2(player, pos2);
|
||||
} else {
|
||||
setPos2OrExpand(player, pos2);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void setPos2(Player player, BlockVector3 pos2) {
|
||||
LocalSession session = we.getSession(player);
|
||||
World world = session.getSelectionWorld();
|
||||
if (world == null) return;
|
||||
selectPos2(session.getRegionSelector(world), player, session, pos2);
|
||||
}
|
||||
|
||||
private void setPos2OrExpand(Player player, BlockVector3 expand) {
|
||||
LocalSession session = we.getSession(player);
|
||||
World world = session.getSelectionWorld();
|
||||
if (world == null) return;
|
||||
RegionSelector regionSelector = session.getRegionSelector(world);
|
||||
|
||||
// Only primary set for now
|
||||
if (!regionSelector.isDefined()) {
|
||||
selectPos2(session.getRegionSelector(world), player, session, expand);
|
||||
return;
|
||||
}
|
||||
|
||||
List<BlockVector3> vertices = regionSelector.getVertices();
|
||||
// Probably not a cuboid selection!
|
||||
if (vertices.size() > 2) {
|
||||
selectPos2(session.getRegionSelector(world), player, session, expand);
|
||||
return;
|
||||
}
|
||||
|
||||
BlockVector3 pos1 = vertices.get(0);
|
||||
BlockVector3 pos2 = vertices.get(1);
|
||||
|
||||
BlockVector3 min = pos1.getMinimum(pos2);
|
||||
BlockVector3 max = pos1.getMaximum(pos2);
|
||||
if (expand.containedWithin(pos1, pos2)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Closer x = Closer.UNKNOWN;
|
||||
Closer y = Closer.UNKNOWN;
|
||||
Closer z = Closer.UNKNOWN;
|
||||
|
||||
boolean insideX = min.x() < expand.x() && max.x() > expand.x();
|
||||
boolean insideY = min.y() < expand.y() && max.y() > expand.y();
|
||||
boolean insideZ = min.z() < expand.z() && max.z() > expand.z();
|
||||
|
||||
if (insideX) {
|
||||
// No Change needed
|
||||
} else if (Math.abs(pos1.x() - expand.x()) > Math.abs(pos2.x() - expand.x())) {
|
||||
x = Closer.POS2;
|
||||
} else if (Math.abs(pos1.x() - expand.x()) < Math.abs(pos2.x() - expand.x())) {
|
||||
x = Closer.POS1;
|
||||
}
|
||||
|
||||
if (insideY) {
|
||||
// No Change needed
|
||||
} else if (Math.abs(pos1.y() - expand.y()) > Math.abs(pos2.y() - expand.y())) {
|
||||
y = Closer.POS2;
|
||||
} else if (Math.abs(pos1.y() - expand.y()) < Math.abs(pos2.y() - expand.y())) {
|
||||
y = Closer.POS1;
|
||||
}
|
||||
|
||||
if (insideZ) {
|
||||
// No Change needed
|
||||
} else if (Math.abs(pos1.z() - expand.z()) > Math.abs(pos2.z() - expand.z())) {
|
||||
z = Closer.POS2;
|
||||
} else if (Math.abs(pos1.z() - expand.z()) < Math.abs(pos2.z() - expand.z())) {
|
||||
z = Closer.POS1;
|
||||
}
|
||||
|
||||
Closer x1 = Closer.UNKNOWN;
|
||||
Closer y1 = Closer.UNKNOWN;
|
||||
Closer z1 = Closer.UNKNOWN;
|
||||
|
||||
if (!insideX && pos1.x() != expand.x() && pos2.x() != expand.x() && x == Closer.UNKNOWN) {
|
||||
x1 = y.and(z).or(Closer.POS1);
|
||||
}
|
||||
if (!insideY && pos1.y() != expand.y() && pos2.y() != expand.y() && y == Closer.UNKNOWN) {
|
||||
y1 = x.and(z).or(Closer.POS1);
|
||||
}
|
||||
if (!insideZ && pos1.z() != expand.z() && pos2.z() != expand.z() && z == Closer.UNKNOWN) {
|
||||
z1 = x.and(y).or(Closer.POS1);
|
||||
}
|
||||
|
||||
if (x1 != Closer.UNKNOWN) x = x1;
|
||||
if (y1 != Closer.UNKNOWN) y = y1;
|
||||
if (z1 != Closer.UNKNOWN) z = z1;
|
||||
|
||||
boolean p1updated = false;
|
||||
boolean p2updated = false;
|
||||
|
||||
if (x == Closer.POS1) {
|
||||
pos1 = pos1.withX(expand.x());
|
||||
p1updated = true;
|
||||
} else if (x == Closer.POS2) {
|
||||
pos2 = pos2.withX(expand.x());
|
||||
p2updated = true;
|
||||
}
|
||||
|
||||
if (y == Closer.POS1) {
|
||||
pos1 = pos1.withY(expand.y());
|
||||
p1updated = true;
|
||||
} else if (y == Closer.POS2) {
|
||||
pos2 = pos2.withY(expand.y());
|
||||
p2updated = true;
|
||||
}
|
||||
|
||||
if (z == Closer.POS1) {
|
||||
pos1 = pos1.withZ(expand.z());
|
||||
p1updated = true;
|
||||
} else if (z == Closer.POS2) {
|
||||
pos2 = pos2.withZ(expand.z());
|
||||
p2updated = true;
|
||||
}
|
||||
|
||||
if (p1updated) selectPos1(session.getRegionSelector(world), player, session, pos1);
|
||||
if (p2updated) selectPos2(session.getRegionSelector(world), player, session, pos2);
|
||||
}
|
||||
|
||||
private enum Closer {
|
||||
POS1,
|
||||
POS2,
|
||||
UNKNOWN,
|
||||
;
|
||||
|
||||
public Closer and(Closer closer) {
|
||||
if (this == closer) {
|
||||
return this;
|
||||
} else if (this == UNKNOWN) {
|
||||
return closer;
|
||||
} else if (closer == UNKNOWN) {
|
||||
return this;
|
||||
} else {
|
||||
return UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
public Closer or(Closer closer) {
|
||||
if (this == UNKNOWN) return closer;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
private ServerboundPickItemFromBlockPacket middleClick(Player player, ServerboundPickItemFromBlockPacket packet) {
|
||||
if (noWand(player)) return packet;
|
||||
LocalSession session = we.getSession(player);
|
||||
World world = session.getSelectionWorld();
|
||||
if (world == null) return packet;
|
||||
RegionSelector regionSelector = session.getRegionSelector(world);
|
||||
BlockPos pos = packet.pos();
|
||||
SteamEditSelectAdjacent selector = new SteamEditSelectAdjacent(new Location(player.getWorld(), pos.getX(), pos.getY(), pos.getZ()));
|
||||
selectPos1(regionSelector, player, session, selector.pos1());
|
||||
selectPos2(regionSelector, player, session, selector.pos2());
|
||||
return null;
|
||||
}
|
||||
|
||||
private static class Pos1Message implements SWPlayer.Component {
|
||||
private BukkitTask task;
|
||||
|
||||
public Pos1Message(RegionSelector regionSelector, Player player, LocalSession session, BlockVector3 pos1) {
|
||||
task = Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> {
|
||||
regionSelector.explainPrimarySelection(BukkitAdapter.adapt(player), session, pos1);
|
||||
SWPlayer.of(player).removeComponent(Pos1Message.class);
|
||||
}, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnmount(SWPlayer player) {
|
||||
task.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
private void selectPos1(RegionSelector regionSelector, Player player, LocalSession session, BlockVector3 pos1) {
|
||||
try {
|
||||
if (!pos1.equals(regionSelector.getPrimaryPosition())) {
|
||||
SWPlayer.of(player).setComponent(new Pos1Message(regionSelector, player, session, pos1));
|
||||
}
|
||||
} catch (IncompleteRegionException e) {
|
||||
SWPlayer.of(player).setComponent(new Pos1Message(regionSelector, player, session, pos1));
|
||||
}
|
||||
regionSelector.selectPrimary(pos1, PermissiveSelectorLimits.getInstance());
|
||||
WorldEditRenderer.renderPlayer(player);
|
||||
}
|
||||
|
||||
private static class Pos2Message implements SWPlayer.Component {
|
||||
private BukkitTask task;
|
||||
|
||||
public Pos2Message(RegionSelector regionSelector, Player player, LocalSession session, BlockVector3 pos2) {
|
||||
task = Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> {
|
||||
regionSelector.explainSecondarySelection(BukkitAdapter.adapt(player), session, pos2);
|
||||
SWPlayer.of(player).removeComponent(Pos1Message.class);
|
||||
}, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnmount(SWPlayer player) {
|
||||
task.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
private void selectPos2(RegionSelector regionSelector, Player player, LocalSession session, BlockVector3 pos2) {
|
||||
try {
|
||||
if (regionSelector.getVertices().size() == 2 && !pos2.equals(regionSelector.getVertices().get(1))) {
|
||||
SWPlayer.of(player).setComponent(new Pos2Message(regionSelector, player, session, pos2));
|
||||
}
|
||||
} catch (IncompleteRegionException e) {
|
||||
SWPlayer.of(player).setComponent(new Pos2Message(regionSelector, player, session, pos2));
|
||||
}
|
||||
regionSelector.selectSecondary(pos2, PermissiveSelectorLimits.getInstance());
|
||||
WorldEditRenderer.renderPlayer(player);
|
||||
}
|
||||
|
||||
private ServerboundPlayerActionPacket swapHands(Player player, ServerboundPlayerActionPacket packet) {
|
||||
if (noWand(player)) return packet;
|
||||
if (packet.getAction() != ServerboundPlayerActionPacket.Action.SWAP_ITEM_WITH_OFFHAND) return packet;
|
||||
Bukkit.getScheduler().runTask(Core.getInstance(), () -> {
|
||||
WorldEditRendererCUIEditor.open(player, true);
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
public ServerboundMovePlayerPacket movePlayerPacket(Player player, ServerboundMovePlayerPacket packet) {
|
||||
SWPlayer swPlayer = SWPlayer.of(player);
|
||||
|
||||
if (noWand(player)) {
|
||||
swPlayer.removeComponent(SWEditCursor.class);
|
||||
return packet;
|
||||
}
|
||||
|
||||
double distance = WorldEditRendererCUIEditor.Type.CURSOR.getWidth(player).blocks;
|
||||
RayTraceResult result = player.rayTraceBlocks(distance, FluidCollisionMode.NEVER);
|
||||
Block block = result == null ? null : result.getHitBlock();
|
||||
if (result == null || block == null) {
|
||||
swPlayer.removeComponent(SWEditCursor.class);
|
||||
return packet;
|
||||
}
|
||||
|
||||
if (!swPlayer.hasComponent(SWEditCursor.class)) {
|
||||
swPlayer.setComponent(new SWEditCursor());
|
||||
}
|
||||
|
||||
swPlayer.getComponent(SWEditCursor.class).ifPresent(cursor -> {
|
||||
cursor.setLocation(block.getLocation());
|
||||
});
|
||||
return packet;
|
||||
}
|
||||
}
|
||||
+9
-5
@@ -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,7 +17,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.core;
|
||||
package de.steamwar.core.worldedit;
|
||||
|
||||
import com.sk89q.worldedit.EmptyClipboardException;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
@@ -28,6 +28,7 @@ import com.sk89q.worldedit.math.transform.Transform;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.linkage.PluginCheck;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -39,13 +40,15 @@ import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@Linked
|
||||
@PluginCheck("FastAsyncWorldEdit")
|
||||
public class WorldEditRenderer implements Listener {
|
||||
|
||||
private static WorldEditRenderer INSTANCE;
|
||||
|
||||
private static final Material WAND = Material.WOODEN_AXE;
|
||||
private static final Set<Material> WANDS = Set.of(Material.WOODEN_AXE, SteamEditWand.MATERIAL);
|
||||
|
||||
private final WorldEditPlugin we;
|
||||
|
||||
@@ -102,7 +105,7 @@ public class WorldEditRenderer implements Listener {
|
||||
|
||||
private void drawCuboid(Vector min, Vector max, boolean scheduled, boolean clipboard, Player owner) {
|
||||
//noinspection deprecation
|
||||
if (owner.getItemInHand().getType() != WAND) {
|
||||
if (!WANDS.contains(owner.getItemInHand().getType())) {
|
||||
WorldEditRendererWrapper.impl.hide(owner, true, true);
|
||||
WorldEditRendererWrapper.impl.hide(owner, false, true);
|
||||
} else {
|
||||
@@ -114,7 +117,8 @@ public class WorldEditRenderer implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
if (event.getPlayer().getItemInHand().getType() == WAND) {
|
||||
//noinspection deprecation
|
||||
if (WANDS.contains(event.getPlayer().getItemInHand().getType())) {
|
||||
WorldEditRendererWrapper.impl.tick(event.getPlayer());
|
||||
}
|
||||
renderClipboard(event.getPlayer(), we.getSession(event.getPlayer()), false);
|
||||
+78
-15
@@ -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,9 +17,11 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.core;
|
||||
package de.steamwar.core.worldedit;
|
||||
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.core.CRIUSleepEvent;
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.inventory.SWInventory;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import de.steamwar.sql.UserConfig;
|
||||
@@ -30,6 +32,7 @@ import org.bukkit.block.data.type.Light;
|
||||
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.player.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.meta.BlockDataMeta;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
@@ -59,6 +62,7 @@ public class WorldEditRendererCUIEditor implements Listener {
|
||||
public enum Type {
|
||||
SELECTION("cui_selection_material", "cui_selection_width", Material.PURPLE_CONCRETE, Width.MEDIUM),
|
||||
CLIPBOARD("cui_clipboard_material", "cui_clipboard_width", Material.LIME_CONCRETE, Width.SLIM),
|
||||
CURSOR("cui_cursor_material", "cui_cursor_range", Material.RED_CONCRETE, Width.SLIM),
|
||||
;
|
||||
|
||||
private final Map<Player, Material> materialCache = new HashMap<>();
|
||||
@@ -104,19 +108,27 @@ public class WorldEditRendererCUIEditor implements Listener {
|
||||
|
||||
@AllArgsConstructor
|
||||
public enum Width {
|
||||
HUGE(15, "WORLDEDIT_CUI_WIDTH_HUGE", 2 / 16f),
|
||||
LARGE(8, "WORLDEDIT_CUI_WIDTH_LARGE", 1 / 16f),
|
||||
MEDIUM(4, "WORLDEDIT_CUI_WIDTH_MEDIUM", 1 / 32f),
|
||||
SLIM(0, "WORLDEDIT_CUI_WIDTH_SLIM", 1 / 64f);
|
||||
HUGE(15, "WORLDEDIT_CUI_WIDTH_HUGE", 1 / 8f, 40),
|
||||
LARGE(8, "WORLDEDIT_CUI_WIDTH_LARGE", 1 / 16f, 30),
|
||||
MEDIUM(4, "WORLDEDIT_CUI_WIDTH_MEDIUM", 1 / 32f, 20),
|
||||
SLIM(0, "WORLDEDIT_CUI_WIDTH_SLIM", 1 / 64f, 10);
|
||||
|
||||
public final int lightLevel;
|
||||
public final String name;
|
||||
public final float value;
|
||||
public final float width;
|
||||
public final int blocks;
|
||||
}
|
||||
|
||||
private static Command command = null;
|
||||
|
||||
public WorldEditRendererCUIEditor() {
|
||||
Bukkit.getPluginManager().registerEvents(this, Core.getInstance());
|
||||
new Command();
|
||||
command = new Command();
|
||||
}
|
||||
|
||||
public static void open(Player player, boolean steamEditWand) {
|
||||
if (command == null) return;
|
||||
command.cuiEditor(player, steamEditWand);
|
||||
}
|
||||
|
||||
private static class Command extends SWCommand {
|
||||
@@ -127,18 +139,44 @@ public class WorldEditRendererCUIEditor implements Listener {
|
||||
|
||||
@Register
|
||||
public void cuiEditor(Player player) {
|
||||
cuiEditor(player, false);
|
||||
}
|
||||
|
||||
public void cuiEditor(Player player, boolean steamEditWand) {
|
||||
SWInventory inv = new SWInventory(player, 9 * 2, Core.MESSAGE.parse("WORLDEDIT_CUI_TITLE", player));
|
||||
setElement(inv, player, 3, "WORLDEDIT_CUI_SELECTION", Type.SELECTION);
|
||||
setElement(inv, player, 5, "WORLDEDIT_CUI_CLIPBOARD", Type.CLIPBOARD);
|
||||
if (SteamEdit.isInitialized() && steamEditWand) {
|
||||
setElement(inv, player, true, 1, "WORLDEDIT_CUI_SELECTION", Type.SELECTION);
|
||||
setElement(inv, player, true, 2, "WORLDEDIT_CUI_CLIPBOARD", Type.CLIPBOARD);
|
||||
setCursor(inv, player, 3, "WORLDEDIT_CUI_CURSOR");
|
||||
inv.setItem(5, new SWItem(Material.PAPER, "WORLDEDIT_CUI_TOOL_COPY").setLore("WORLDEDIT_CUI_TOOL_COPY_LORE").translate(player, Core.MESSAGE).getItemStack(), click -> {
|
||||
player.performCommand("/copy");
|
||||
});
|
||||
inv.setItem(6, new SWItem(Material.STRUCTURE_VOID, "WORLDEDIT_CUI_TOOL_SOON").translate(player, Core.MESSAGE).getItemStack(), click -> {});
|
||||
inv.setItem(7, new SWItem(Material.GRASS_BLOCK, "WORLDEDIT_CUI_TOOL_PASTE").setLore("WORLDEDIT_CUI_TOOL_PASTE_LORE_1", "WORLDEDIT_CUI_TOOL_PASTE_LORE_2", "WORLDEDIT_CUI_TOOL_PASTE_LORE_3").translate(player, Core.MESSAGE).getItemStack(), click -> {
|
||||
if (click == ClickType.DROP) {
|
||||
player.performCommand("/paste -o");
|
||||
} else if (click == ClickType.SHIFT_LEFT || click == ClickType.SHIFT_RIGHT) {
|
||||
player.performCommand("/paste -s");
|
||||
} else if (click == ClickType.LEFT || click == ClickType.RIGHT) {
|
||||
player.performCommand("/paste");
|
||||
}
|
||||
});
|
||||
inv.setItem(14, new SWItem(Material.STRUCTURE_VOID, "WORLDEDIT_CUI_TOOL_SOON").translate(player, Core.MESSAGE).getItemStack(), click -> {});
|
||||
inv.setItem(15, new SWItem(Material.STRUCTURE_VOID, "WORLDEDIT_CUI_TOOL_SOON").translate(player, Core.MESSAGE).getItemStack(), click -> {});
|
||||
inv.setItem(16, new SWItem(Material.STRUCTURE_VOID, "WORLDEDIT_CUI_TOOL_SOON").translate(player, Core.MESSAGE).getItemStack(), click -> {});
|
||||
} else {
|
||||
setElement(inv, player, false, 3, "WORLDEDIT_CUI_SELECTION", Type.SELECTION);
|
||||
setElement(inv, player, false, 5, "WORLDEDIT_CUI_CLIPBOARD", Type.CLIPBOARD);
|
||||
}
|
||||
inv.open();
|
||||
}
|
||||
|
||||
private void setElement(SWInventory inv, Player player, int index, String uiName, Type type) {
|
||||
private void setElement(SWInventory inv, Player player, boolean steamEditWand, int index, String uiName, Type type) {
|
||||
Material material = type.getMaterial(player);
|
||||
Width width = type.getWidth(player);
|
||||
|
||||
inv.setItem(index, new SWItem(material, Core.MESSAGE.parse("WORLDEDIT_CUI_MATERIAL_NAME", player, Core.MESSAGE.parse(uiName, player)), Arrays.asList(Core.MESSAGE.parse("WORLDEDIT_CUI_MATERIAL_CLICK", player)), false, click -> {
|
||||
cuiMaterial(player, uiName, type, material);
|
||||
cuiMaterial(player, steamEditWand, uiName, type, material);
|
||||
}));
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
@@ -153,7 +191,7 @@ public class WorldEditRendererCUIEditor implements Listener {
|
||||
}
|
||||
SWItem lightItem = new SWItem(Material.LIGHT, Core.MESSAGE.parse("WORLDEDIT_CUI_WIDTH_NAME", player, Core.MESSAGE.parse(uiName, player)), lore, false, click -> {
|
||||
type.setWidth(player, Width.values()[(width.ordinal() + 1) % Width.values().length]);
|
||||
setElement(inv, player, index, uiName, type);
|
||||
setElement(inv, player, steamEditWand, index, uiName, type);
|
||||
});
|
||||
ItemMeta itemMeta = lightItem.getItemMeta();
|
||||
Light light = (Light) Material.LIGHT.createBlockData();
|
||||
@@ -163,16 +201,41 @@ public class WorldEditRendererCUIEditor implements Listener {
|
||||
inv.setItem(index + 9, lightItem);
|
||||
}
|
||||
|
||||
private void setCursor(SWInventory inv, Player player, int index, String uiName) {
|
||||
Material material = Type.CURSOR.getMaterial(player);
|
||||
Width width = Type.CURSOR.getWidth(player);
|
||||
|
||||
inv.setItem(index, new SWItem(material, Core.MESSAGE.parse("WORLDEDIT_CUI_MATERIAL_NAME", player, Core.MESSAGE.parse(uiName, player)), Arrays.asList(Core.MESSAGE.parse("WORLDEDIT_CUI_MATERIAL_CLICK", player)), false, click -> {
|
||||
cuiMaterial(player, true, uiName, Type.CURSOR, material);
|
||||
}));
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add(Core.MESSAGE.parse("WORLDEDIT_CUI_WIDTH_CLICK", player));
|
||||
lore.add("");
|
||||
for (Width value : Width.values()) {
|
||||
if (value == width) {
|
||||
lore.add(Core.MESSAGE.parse("WORLDEDIT_CUI_WIDTH_LORE_SELECTED", player, Core.MESSAGE.parse(value.name + "_DIST", player)));
|
||||
} else {
|
||||
lore.add(Core.MESSAGE.parse("WORLDEDIT_CUI_WIDTH_LORE", player, Core.MESSAGE.parse(value.name + "_DIST", player)));
|
||||
}
|
||||
}
|
||||
SWItem stickItem = new SWItem(Material.STICK, Core.MESSAGE.parse("WORLDEDIT_CUI_WIDTH_NAME_DIST", player, Core.MESSAGE.parse(uiName, player)), lore, false, click -> {
|
||||
Type.CURSOR.setWidth(player, Width.values()[(width.ordinal() + 1) % Width.values().length]);
|
||||
setCursor(inv, player, index, uiName);
|
||||
}).setCustomModelData(1);
|
||||
inv.setItem(index + 9, stickItem);
|
||||
}
|
||||
|
||||
private final Material[] materials = {Material.WHITE_CONCRETE, Material.LIGHT_GRAY_CONCRETE, Material.GRAY_CONCRETE, Material.BLACK_CONCRETE, Material.BROWN_CONCRETE, Material.RED_CONCRETE, Material.ORANGE_CONCRETE, Material.YELLOW_CONCRETE, Material.LIME_CONCRETE, Material.GREEN_CONCRETE, Material.CYAN_CONCRETE, Material.LIGHT_BLUE_CONCRETE, Material.BLUE_CONCRETE, Material.PURPLE_CONCRETE, Material.MAGENTA_CONCRETE, Material.PINK_CONCRETE, null, Material.BARRIER};
|
||||
|
||||
private void cuiMaterial(Player player, String subMenu, Type type, Material currentSelection) {
|
||||
private void cuiMaterial(Player player, boolean steamEditWand, String subMenu, Type type, Material currentSelection) {
|
||||
SWInventory inv = new SWInventory(player, 9 * 2, Core.MESSAGE.parse("WORLDEDIT_CUI_TITLE_SUBMENU", player, Core.MESSAGE.parse(subMenu, player)));
|
||||
for (int i = 0; i < materials.length; i++) {
|
||||
Material material = materials[i];
|
||||
if (material == null) continue;
|
||||
inv.setItem(i, new SWItem(material, "", Collections.emptyList(), material == currentSelection, click -> {
|
||||
type.setMaterial(player, material);
|
||||
cuiEditor(player);
|
||||
cuiEditor(player, steamEditWand);
|
||||
}));
|
||||
}
|
||||
inv.open();
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.core;
|
||||
package de.steamwar.core.worldedit;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user