forked from SteamWar/SteamWar
Compare commits
47 Commits
bf50b30460
...
swui-v2
| Author | SHA1 | Date | |
|---|---|---|---|
|
70c8678c60
|
|||
| 997292d58e | |||
|
8050f51424
|
|||
| e176b3bca8 | |||
|
a6681ffaf6
|
|||
|
a23530074c
|
|||
|
e88a4c624b
|
|||
| 105beaf7a6 | |||
|
5f7ab3cd7b
|
|||
| f81f05c3d0 | |||
| 0afb6ce06a | |||
|
5ce69e6b7a
|
|||
| a938abde3f | |||
| ec9b0387c5 | |||
| 03c3d49659 | |||
| 8d9a77ab67 | |||
| fc2997e011 | |||
| 8eb5f5ddf2 | |||
| aa807060f4 | |||
| 9bbbab9d4b | |||
| 7cca4ada10 | |||
| 725e6df047 | |||
| f3ce124a23 | |||
| e83f72a53e | |||
| def0c19e43 | |||
| 3810ccd63d | |||
| a018af1c8a | |||
| fd8f942014 | |||
| eab8826583 | |||
| bc0177df43 | |||
| 1dc78b8eb8 | |||
| a9fb982143 | |||
| 5b8d881e01 | |||
| eb55f4b395 | |||
| 273db91d06 | |||
| 983ad544c1 | |||
| a6a34b2221 | |||
| 6c6bd19038 | |||
| 89e05cd109 | |||
| ea9d7ac584 | |||
| 17e1cf53b0 | |||
| f64f337f17 | |||
| c5f5be7d58 | |||
| 9f18644763 | |||
| 1de17d27f4 | |||
| 3cd0db9bdf | |||
| 9711b48f2f |
@@ -34,6 +34,7 @@ dependencies {
|
||||
compileOnly(libs.classindex)
|
||||
annotationProcessor(libs.classindex)
|
||||
compileOnly(project(":SpigotCore", "default"))
|
||||
compileOnly(project(":KotlinCore", "default"))
|
||||
|
||||
compileOnly(libs.axiom)
|
||||
compileOnly(libs.authlib)
|
||||
|
||||
@@ -834,6 +834,10 @@ SKIN_NO_REGION = §7You are not in a region with a changealbe skin
|
||||
SKIN_ALREADY_EXISTS = §cThis skin already exists like this
|
||||
SKIN_MESSAGE = §7Skin created
|
||||
SKIN_MESSAGE_HOVER = §eClick to copy for YoyoNow and send
|
||||
# Blast Resistance
|
||||
BLASTRESISTANCE_HELP = §8/§eblastresistance §8-§7 Calculate min/max and average blast resistance of current clipboard
|
||||
BLASTRESISTANCE_NO_CLIPBOARD = §cYou currently do not have a clipboard to be used.
|
||||
BLASTRESISTANCE_RESULT = §7BlastResistance §8>>§7 Min§8: §e{0}§7 Max§8: §e{1}§7 Avg§8: §e{2}
|
||||
# Panzern
|
||||
PANZERN_HELP = §8/§epanzern §8[§7Block§8] §8[§7Slab§8] §8- §7Armor your WorldEdit selection
|
||||
PANZERN_PREPARE1 = §71. Check, if barrels reach until border of armor.
|
||||
|
||||
@@ -772,6 +772,10 @@ SKIN_NO_REGION = §7Du steht in keiner Region, welche mit einem Skin versehen we
|
||||
SKIN_ALREADY_EXISTS = §cDieser Skin existiert in der Form bereits
|
||||
SKIN_MESSAGE = §7Skin erstellt
|
||||
SKIN_MESSAGE_HOVER = §eKlicken zum kopieren für YoyoNow und an diesen senden
|
||||
# Blast Resistance
|
||||
BLASTRESISTANCE_HELP = §8/§eblastresistance §8-§7 Minimal-, Maximal- und durchschnittliche Sprengfestigkeit des aktuellen Inhalts der Zwischenablage berechnen
|
||||
BLASTRESISTANCE_NO_CLIPBOARD = §cDerzeit steht Ihnen keine Zwischenablage zur Verfügung.
|
||||
BLASTRESISTANCE_RESULT = §7BlastResistance §8>>§7 Min§8: §e{0}§7 Max§8: §e{1}§7 Avg§8: §e{2}
|
||||
# Panzern
|
||||
PANZERN_HELP = §8/§epanzern §8[§7Block§8] §8[§7Slab§8] §8- §7Panzer deine WorldEdit Auswahl
|
||||
PANZERN_PREPARE1 = §71. Gucke nochmal nach, ob Läufe auch bis zur Panzergrenze führen.
|
||||
|
||||
+15
-14
@@ -21,9 +21,7 @@ package de.steamwar.bausystem.features.design.endstone;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.entity.REntity;
|
||||
import de.steamwar.entity.REntityServer;
|
||||
import de.steamwar.entity.RFallingBlockEntity;
|
||||
import de.steamwar.entity.*;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@@ -59,15 +57,15 @@ public class DesignEndStone {
|
||||
.filter(material -> material.getBlastResistance() > region.getGameModeConfig().Schematic.MaxDesignBlastResistance)
|
||||
.collect(Collectors.toSet());
|
||||
calculateFromBottom = region.getGameModeConfig().Arena.NoFloor;
|
||||
}
|
||||
|
||||
entityServer.setCallback((player, rEntity, entityAction) -> {
|
||||
if (entityAction != REntityServer.EntityAction.ATTACK) return;
|
||||
Location location = new Location(WORLD, rEntity.getX(), rEntity.getY(), rEntity.getZ());
|
||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
||||
location.getBlock().breakNaturally();
|
||||
calc();
|
||||
}, 1);
|
||||
});
|
||||
private void interact(Player player, RInteraction entity, REntityAction action) {
|
||||
if (action != REntityAction.ATTACK) return;
|
||||
Location location = new Location(WORLD, entity.getX(), entity.getY(), entity.getZ());
|
||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
||||
location.getBlock().breakNaturally();
|
||||
calc();
|
||||
}, 1);
|
||||
}
|
||||
|
||||
public void calc() {
|
||||
@@ -110,12 +108,15 @@ public class DesignEndStone {
|
||||
Material material = WORLD.getBlockAt(cx, cy, cz).getType();
|
||||
|
||||
if (material != Material.WATER && material != Material.LAVA && limited.contains(material)) {
|
||||
Location location = new Location(WORLD, cx + 0.5, cy, cz + 0.5);
|
||||
Location location = new Location(WORLD, cx, cy, cz);
|
||||
if (!locations.add(location)) break;
|
||||
RFallingBlockEntity entity = new RFallingBlockEntity(entityServer, location, Material.RED_STAINED_GLASS);
|
||||
entity.setNoGravity(true);
|
||||
RBlockDisplay entity = new RBlockDisplay(entityServer, location);
|
||||
entity.setBlock(Material.RED_STAINED_GLASS.createBlockData());
|
||||
entity.setGlowing(true);
|
||||
entities.add(entity);
|
||||
RInteraction interaction = new RInteraction(entityServer, location);
|
||||
interaction.setCallback(this::interact);
|
||||
entities.add(interaction);
|
||||
break;
|
||||
} else if (!material.isAir() && material != Material.WATER && material != Material.LAVA) {
|
||||
break;
|
||||
|
||||
+10
-9
@@ -26,8 +26,9 @@ import de.steamwar.bausystem.features.autostart.AutostartListener;
|
||||
import de.steamwar.bausystem.features.detonator.storage.DetonatorStorage;
|
||||
import de.steamwar.bausystem.features.detonator.storage.ItemStorage;
|
||||
import de.steamwar.core.SWPlayer;
|
||||
import de.steamwar.entity.RBlockDisplay;
|
||||
import de.steamwar.entity.REntityServer;
|
||||
import de.steamwar.entity.RFallingBlockEntity;
|
||||
import de.steamwar.entity.RInteraction;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.UtilityClass;
|
||||
@@ -58,10 +59,6 @@ public class Detonator {
|
||||
@Override
|
||||
public void onMount(SWPlayer player) {
|
||||
entities.addPlayer(player.getPlayer());
|
||||
entities.setCallback((player1, entity, action) -> {
|
||||
Vector vector = new Vector(entity.getX(), entity.getY(), entity.getZ());
|
||||
DetonatorListener.addLocationToDetonator(vector.toLocation(player.getWorld()).getBlock().getLocation(), player1);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -70,8 +67,6 @@ public class Detonator {
|
||||
}
|
||||
}
|
||||
|
||||
private static final Vector HALF = new Vector(0.5, 0, 0.5);
|
||||
|
||||
public static boolean isDetonator(ItemStack itemStack) {
|
||||
return ItemStorage.isDetonator(itemStack);
|
||||
}
|
||||
@@ -79,8 +74,14 @@ public class Detonator {
|
||||
public static void showDetonator(Player p, List<Location> locs) {
|
||||
DetonatorComponent detonatorComponent = SWPlayer.of(p).getComponentOrDefault(DetonatorComponent.class, DetonatorComponent::new);
|
||||
locs.forEach(location -> {
|
||||
RFallingBlockEntity entity = new RFallingBlockEntity(detonatorComponent.entities, location.clone().add(HALF), Material.RED_STAINED_GLASS);
|
||||
entity.setNoGravity(true);
|
||||
RBlockDisplay blockDisplay = new RBlockDisplay(detonatorComponent.entities, location);
|
||||
blockDisplay.setBlock(Material.RED_STAINED_GLASS.createBlockData());
|
||||
|
||||
RInteraction interaction = new RInteraction(detonatorComponent.entities, location);
|
||||
interaction.setCallback((player, entity, action) -> {
|
||||
Vector vector = new Vector(entity.getX(), entity.getY(), entity.getZ());
|
||||
DetonatorListener.addLocationToDetonator(vector.toLocation(player.getWorld()).getBlock().getLocation(), player);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.features.experimental;
|
||||
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
|
||||
@Linked
|
||||
public class ExperimentalCommand extends SWCommand {
|
||||
|
||||
public ExperimentalCommand() {
|
||||
super("experimental", "experiment");
|
||||
}
|
||||
}
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.features.experimental.redstone_engine;
|
||||
|
||||
import de.steamwar.bausystem.features.experimental.ExperimentalCommand;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.utils.ScoreboardElement;
|
||||
import de.steamwar.command.AbstractSWCommand;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import io.papermc.paper.configuration.WorldConfiguration;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.title.TitlePart;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@AbstractSWCommand.PartOf(ExperimentalCommand.class)
|
||||
@Linked
|
||||
public class RedstoneEngine extends SWCommand implements Listener, ScoreboardElement {
|
||||
|
||||
public RedstoneEngine() {
|
||||
super("");
|
||||
}
|
||||
|
||||
private WorldConfiguration.Misc getConfig() {
|
||||
return ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle().paperConfig().misc;
|
||||
}
|
||||
|
||||
@Register("redstone")
|
||||
@Register("redstoneengine")
|
||||
public void setRedstoneEngine(Player player, @StaticValue("alternate_current") String __, WorldConfiguration.Misc.AlternateCurrentUpdateOrder updateOrder) {
|
||||
WorldConfiguration.Misc misc = getConfig();
|
||||
misc.redstoneImplementation = WorldConfiguration.Misc.RedstoneImplementation.ALTERNATE_CURRENT;
|
||||
misc.alternateCurrentUpdateOrder = updateOrder;
|
||||
broadcastTitle(Bukkit.getOnlinePlayers());
|
||||
}
|
||||
|
||||
@Register("redstone")
|
||||
@Register("redstoneengine")
|
||||
public void setRedstoneEngine(Player player, WorldConfiguration.Misc.RedstoneImplementation implementation) {
|
||||
getConfig().redstoneImplementation = implementation;
|
||||
broadcastTitle(Bukkit.getOnlinePlayers());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
WorldConfiguration.Misc misc = getConfig();
|
||||
if (misc.redstoneImplementation != WorldConfiguration.Misc.RedstoneImplementation.EIGENCRAFT) {
|
||||
broadcastTitle(List.of(event.getPlayer()));
|
||||
}
|
||||
}
|
||||
|
||||
private void broadcastTitle(Collection<? extends Player> players) {
|
||||
WorldConfiguration.Misc misc = getConfig();
|
||||
Component title = switch (misc.redstoneImplementation) {
|
||||
case VANILLA -> Component.text("⚠").color(NamedTextColor.RED).append(Component.text(" Redstone: Vanilla ").color(NamedTextColor.WHITE)).append(Component.text("⚠").color(NamedTextColor.RED));
|
||||
case EIGENCRAFT -> Component.text("Redstone: Eigencraft");
|
||||
case ALTERNATE_CURRENT -> Component.text("⚠").color(NamedTextColor.RED).append(Component.text(" Redstone: AC ").color(NamedTextColor.WHITE)).append(Component.text("⚠").color(NamedTextColor.RED));
|
||||
};
|
||||
Component subtitle;
|
||||
if (misc.redstoneImplementation != WorldConfiguration.Misc.RedstoneImplementation.ALTERNATE_CURRENT) {
|
||||
subtitle = Component.text().build();
|
||||
} else {
|
||||
subtitle = switch (misc.alternateCurrentUpdateOrder) {
|
||||
case VERTICAL_FIRST_INWARD -> Component.text("Y first inwards"); // Y before XZ
|
||||
case VERTICAL_FIRST_OUTWARD -> Component.text("Y first outwards"); // XZ before Y
|
||||
case HORIZONTAL_FIRST_INWARD -> Component.text("XZ first inwards"); // Y before XZ
|
||||
case HORIZONTAL_FIRST_OUTWARD -> Component.text("XZ first outwards"); // XZ before Y
|
||||
};
|
||||
}
|
||||
players.forEach(player -> {
|
||||
player.sendTitlePart(TitlePart.TITLE, title);
|
||||
player.sendTitlePart(TitlePart.SUBTITLE, subtitle);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScoreboardGroup getGroup() {
|
||||
return ScoreboardGroup.FOOTER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int order() {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get(Region region, Player p) {
|
||||
WorldConfiguration.Misc misc = getConfig();
|
||||
switch (misc.redstoneImplementation) {
|
||||
case ALTERNATE_CURRENT:
|
||||
switch (misc.alternateCurrentUpdateOrder) {
|
||||
case VERTICAL_FIRST_INWARD:
|
||||
return "§eRedstone§8: §cAC §8(§7Y in§8)";
|
||||
case VERTICAL_FIRST_OUTWARD:
|
||||
return "§eRedstone§8: §cAC §8(§7Y out§8)";
|
||||
case HORIZONTAL_FIRST_INWARD:
|
||||
return "§eRedstone§8: §cAC §8(§7XZ in§8)";
|
||||
case HORIZONTAL_FIRST_OUTWARD:
|
||||
return "§eRedstone§8: §cAC §8(§7XZ out§8)";
|
||||
}
|
||||
return "§eRedstone§8: §cAC";
|
||||
case EIGENCRAFT:
|
||||
return null;
|
||||
case VANILLA:
|
||||
default:
|
||||
return "§eRedstone§8: §cVanilla";
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -24,9 +24,9 @@ import de.steamwar.bausystem.region.Point;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.utils.bossbar.BauSystemBossbar;
|
||||
import de.steamwar.bausystem.utils.bossbar.BossBarService;
|
||||
import de.steamwar.entity.RBlockDisplay;
|
||||
import de.steamwar.entity.REntity;
|
||||
import de.steamwar.entity.REntityServer;
|
||||
import de.steamwar.entity.RFallingBlockEntity;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
@@ -290,8 +290,8 @@ public class KillcheckerVisualizer {
|
||||
}
|
||||
rEntities.get(point).die();
|
||||
}
|
||||
RFallingBlockEntity entity = new RFallingBlockEntity(outlinePoints.contains(point) ? outline : inner, point.toLocation(WORLD, 0.5, 0, 0.5), MATERIALS[Math.min(count - 1, MATERIALS.length) - 1]);
|
||||
entity.setNoGravity(true);
|
||||
RBlockDisplay entity = new RBlockDisplay(outlinePoints.contains(point) ? outline : inner, point.toLocation(WORLD, 0.5, 0, 0.5));
|
||||
entity.setBlock(MATERIALS[Math.min(count - 1, MATERIALS.length) - 1].createBlockData());
|
||||
rEntities.put(point, entity);
|
||||
if (outlinePoints.contains(point)) outlinePointsCache.add(point);
|
||||
killCount.put(point, count);
|
||||
|
||||
+133
-239
@@ -19,7 +19,6 @@
|
||||
|
||||
package de.steamwar.bausystem.features.simulator;
|
||||
|
||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.bausystem.SWUtils;
|
||||
@@ -38,77 +37,88 @@ import de.steamwar.bausystem.features.simulator.gui.SimulatorGui;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||
import de.steamwar.bausystem.utils.BauMemberUpdateEvent;
|
||||
import de.steamwar.bausystem.utils.ItemUtils;
|
||||
import de.steamwar.bausystem.utils.RayTraceUtils;
|
||||
import de.steamwar.core.SWPlayer;
|
||||
import de.steamwar.cursor.Cursor;
|
||||
import de.steamwar.entity.REntity;
|
||||
import de.steamwar.entity.REntityServer;
|
||||
import de.steamwar.entity.RFallingBlockEntity;
|
||||
import de.steamwar.inventory.SWAnvilInv;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryDragEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.event.player.PlayerItemHeldEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerToggleSneakEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Linked
|
||||
public class SimulatorCursor implements Listener {
|
||||
|
||||
private static final World WORLD = Bukkit.getWorlds().get(0);
|
||||
|
||||
private static Map<Player, CursorType> cursorType = Collections.synchronizedMap(new HashMap<>());
|
||||
private static Map<Player, REntityServer> cursors = Collections.synchronizedMap(new HashMap<>());
|
||||
private static final Set<Player> calculating = new HashSet<>();
|
||||
private static final Map<Player, CursorType> cursorType = Collections.synchronizedMap(new HashMap<>());
|
||||
private static final Map<Player, REntityServer> emptyTargetServers = Collections.synchronizedMap(new HashMap<>());
|
||||
|
||||
public static boolean isSimulatorItem(ItemStack itemStack) {
|
||||
return ItemUtils.isItem(itemStack, "simulator");
|
||||
}
|
||||
|
||||
public SimulatorCursor() {
|
||||
BiFunction<Player, ServerboundMovePlayerPacket, Object> function = (player, object) -> {
|
||||
calcCursor(player);
|
||||
return object;
|
||||
};
|
||||
TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.Pos.class, function);
|
||||
TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.Rot.class, function);
|
||||
TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.PosRot.class, function);
|
||||
private static boolean hasSimulatorItem(Player player) {
|
||||
return isSimulatorItem(player.getInventory().getItemInMainHand()) || isSimulatorItem(player.getInventory().getItemInOffHand());
|
||||
}
|
||||
|
||||
private static void scheduleCursorUpdate(Player player) {
|
||||
BauSystem.runTaskLater(BauSystem.getInstance(), () -> calcCursor(player), 1);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
||||
calcCursor(event.getPlayer());
|
||||
}, 0);
|
||||
scheduleCursorUpdate(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
calcCursor(event.getPlayer());
|
||||
scheduleCursorUpdate(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerItemHeld(PlayerItemHeldEvent event) {
|
||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
||||
calcCursor(event.getPlayer());
|
||||
}, 1);
|
||||
scheduleCursorUpdate(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
if (!(event.getWhoClicked() instanceof Player player)) return;
|
||||
if (!Permission.BUILD.hasPermission(player)) return;
|
||||
scheduleCursorUpdate(player);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryDrag(InventoryDragEvent event) {
|
||||
if (!(event.getWhoClicked() instanceof Player player)) return;
|
||||
if (!Permission.BUILD.hasPermission(player)) return;
|
||||
scheduleCursorUpdate(player);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@@ -119,10 +129,7 @@ public class SimulatorCursor implements Listener {
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
cursorType.remove(event.getPlayer());
|
||||
cursors.remove(event.getPlayer());
|
||||
synchronized (calculating) {
|
||||
calculating.remove(event.getPlayer());
|
||||
}
|
||||
removeCursor(event.getPlayer());
|
||||
}
|
||||
|
||||
private static final Map<Player, Long> LAST_SNEAKS = new HashMap<>();
|
||||
@@ -138,7 +145,7 @@ public class SimulatorCursor implements Listener {
|
||||
public void onPlayerToggleSneak(PlayerToggleSneakEvent event) {
|
||||
if (!event.isSneaking()) return;
|
||||
Player player = event.getPlayer();
|
||||
if (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand())) {
|
||||
if (!hasSimulatorItem(player)) {
|
||||
return;
|
||||
}
|
||||
if (LAST_SNEAKS.containsKey(player)) {
|
||||
@@ -164,17 +171,10 @@ public class SimulatorCursor implements Listener {
|
||||
}
|
||||
|
||||
public static void calcCursor(Player player) {
|
||||
synchronized (calculating) {
|
||||
if (calculating.contains(player)) return;
|
||||
calculating.add(player);
|
||||
}
|
||||
if (!Permission.BUILD.hasPermission(player) || (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand()))) {
|
||||
if (removeCursor(player) || SimulatorWatcher.show(null, player)) {
|
||||
if (!Permission.BUILD.hasPermission(player) || !hasSimulatorItem(player)) {
|
||||
if (removeCursor(player) | SimulatorWatcher.show(null, player)) {
|
||||
SWUtils.sendToActionbar(player, "");
|
||||
}
|
||||
synchronized (calculating) {
|
||||
calculating.remove(player);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -183,203 +183,98 @@ public class SimulatorCursor implements Listener {
|
||||
removeCursor(player);
|
||||
SimulatorWatcher.show(null, player);
|
||||
SWUtils.sendToActionbar(player, "§cGenerating Stab");
|
||||
synchronized (calculating) {
|
||||
calculating.remove(player);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
SimulatorWatcher.show(simulator, player);
|
||||
List<REntity> entities = SimulatorWatcher.getEntitiesOfSimulator(simulator);
|
||||
RayTraceUtils.RRayTraceResult rayTraceResult = RayTraceUtils.traceREntity(player, player.getLocation(), entities);
|
||||
if (rayTraceResult == null) {
|
||||
removeCursor(player);
|
||||
if (simulator == null) {
|
||||
SWUtils.sendToActionbar(player, "§eSelect Simulator");
|
||||
} else {
|
||||
SWUtils.sendToActionbar(player, "§eOpen Simulator");
|
||||
}
|
||||
synchronized (calculating) {
|
||||
calculating.remove(player);
|
||||
}
|
||||
return;
|
||||
Cursor cursor = getOrCreateCursor(player, simulator, cursorType.getOrDefault(player, CursorType.TNT));
|
||||
cursor.renderDeduplicated();
|
||||
}
|
||||
|
||||
private static Cursor getOrCreateCursor(Player player, Simulator simulator, CursorType type) {
|
||||
REntityServer targetServer = simulator == null ? emptyTargetServers.computeIfAbsent(player, __ -> new REntityServer()) : SimulatorWatcher.getEntityServerOfSimulator(simulator);
|
||||
SWPlayer swPlayer = SWPlayer.of(player);
|
||||
Optional<Cursor> activeCursor = swPlayer.getComponent(Cursor.class);
|
||||
|
||||
Cursor cursor = activeCursor.orElse(null);
|
||||
if (cursor == null || cursor.getTargetServer() != targetServer) {
|
||||
swPlayer.removeComponent(Cursor.class);
|
||||
cursor = new Cursor(
|
||||
targetServer,
|
||||
player,
|
||||
Material.GLASS,
|
||||
type.material,
|
||||
type.cursorModes,
|
||||
(location, hitEntity, action) -> handlePlayerClick(player, location, hitEntity, action),
|
||||
(location, hitEntity) -> sendCursorActionbar(player, SimulatorStorage.getSimulator(player), location != null, hitEntity.isPresent())
|
||||
);
|
||||
} else {
|
||||
cursor.setCursorMaterial(type.material);
|
||||
cursor.setAllowedCursorModes(type.cursorModes);
|
||||
}
|
||||
|
||||
showCursor(player, rayTraceResult, simulator != null);
|
||||
synchronized (calculating) {
|
||||
calculating.remove(player);
|
||||
}
|
||||
return cursor;
|
||||
}
|
||||
|
||||
private static synchronized boolean removeCursor(Player player) {
|
||||
REntityServer entityServer = cursors.get(player);
|
||||
boolean hadCursor = entityServer != null && !entityServer.getEntities().isEmpty();
|
||||
if (entityServer != null) {
|
||||
entityServer.getEntities().forEach(REntity::die);
|
||||
Optional<Cursor> cursor = SWPlayer.of(player).getComponent(Cursor.class);
|
||||
cursor.ifPresent(__ -> SWPlayer.of(player).removeComponent(Cursor.class));
|
||||
REntityServer emptyTargetServer = emptyTargetServers.remove(player);
|
||||
if (emptyTargetServer != null) {
|
||||
emptyTargetServer.close();
|
||||
}
|
||||
return hadCursor;
|
||||
return cursor.isPresent();
|
||||
}
|
||||
|
||||
private static synchronized void showCursor(Player player, RayTraceUtils.RRayTraceResult rayTraceResult, boolean hasSimulatorSelected) {
|
||||
REntityServer entityServer = cursors.computeIfAbsent(player, __ -> {
|
||||
REntityServer rEntityServer = new REntityServer();
|
||||
rEntityServer.addPlayer(player);
|
||||
return rEntityServer;
|
||||
});
|
||||
|
||||
CursorType type = cursorType.getOrDefault(player, CursorType.TNT);
|
||||
REntity hitEntity = rayTraceResult.getHitEntity();
|
||||
Location location = hitEntity != null ? new Vector(hitEntity.getX(), hitEntity.getY(), hitEntity.getZ()).toLocation(WORLD) :
|
||||
type.position.apply(player, rayTraceResult).toLocation(WORLD);
|
||||
|
||||
Material material = hitEntity != null ? Material.GLASS : type.getMaterial();
|
||||
List<RFallingBlockEntity> entities = entityServer.getEntitiesByType(RFallingBlockEntity.class);
|
||||
entities.removeIf(rFallingBlockEntity -> {
|
||||
if (rFallingBlockEntity.getMaterial() != material) {
|
||||
rFallingBlockEntity.die();
|
||||
return true;
|
||||
}
|
||||
rFallingBlockEntity.move(location);
|
||||
return false;
|
||||
});
|
||||
if (entities.isEmpty()) {
|
||||
RFallingBlockEntity rFallingBlockEntity = new RFallingBlockEntity(entityServer, location, material);
|
||||
rFallingBlockEntity.setNoGravity(true);
|
||||
if (material == Material.GLASS) {
|
||||
rFallingBlockEntity.setGlowing(true);
|
||||
}
|
||||
}
|
||||
|
||||
if (hasSimulatorSelected) {
|
||||
if (hitEntity != null) {
|
||||
SWUtils.sendToActionbar(player, "§eEdit Position");
|
||||
} else {
|
||||
SWUtils.sendToActionbar(player, "§eAdd new " + type.name);
|
||||
}
|
||||
} else {
|
||||
private static void sendCursorActionbar(Player player, Simulator simulator, boolean hasCursorLocation, boolean hasHitEntity) {
|
||||
if (!hasCursorLocation) {
|
||||
SWUtils.sendToActionbar(player, simulator == null ? "§eSelect Simulator" : "§eOpen Simulator");
|
||||
} else if (simulator == null) {
|
||||
SWUtils.sendToActionbar(player, "§eCreate new Simulator");
|
||||
}
|
||||
}
|
||||
|
||||
public static Vector getPosFree(Player player, RayTraceUtils.RRayTraceResult result) {
|
||||
Vector pos = result.getHitPosition();
|
||||
|
||||
BlockFace face = result.getHitBlockFace();
|
||||
if (face != null) {
|
||||
switch (face) {
|
||||
case DOWN:
|
||||
pos.setY(pos.getY() - 0.98);
|
||||
break;
|
||||
case EAST:
|
||||
pos.setX(pos.getX() + 0.49);
|
||||
break;
|
||||
case WEST:
|
||||
pos.setX(pos.getX() - 0.49);
|
||||
break;
|
||||
case NORTH:
|
||||
pos.setZ(pos.getZ() - 0.49);
|
||||
break;
|
||||
case SOUTH:
|
||||
pos.setZ(pos.getZ() + 0.49);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (face.getModY() == 0 && player.isSneaking()) {
|
||||
pos.setY(pos.getY() - 0.49);
|
||||
}
|
||||
}
|
||||
|
||||
if (!player.isSneaking()) {
|
||||
pos.setX(pos.getBlockX() + 0.5);
|
||||
if (face == null || face.getModY() == 0) {
|
||||
pos.setY(pos.getBlockY() + 0.0);
|
||||
}
|
||||
pos.setZ(pos.getBlockZ() + 0.5);
|
||||
}
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
private static Vector getPosBlockAligned(Player player, RayTraceUtils.RRayTraceResult result) {
|
||||
Vector pos = result.getHitPosition();
|
||||
|
||||
BlockFace face = result.getHitBlockFace();
|
||||
if (face != null) {
|
||||
switch (face) {
|
||||
case DOWN:
|
||||
pos.setY(pos.getY() - 0.98);
|
||||
break;
|
||||
case EAST:
|
||||
pos.setX(pos.getX() + 0.49);
|
||||
break;
|
||||
case WEST:
|
||||
pos.setX(pos.getX() - 0.49);
|
||||
break;
|
||||
case NORTH:
|
||||
pos.setZ(pos.getZ() - 0.49);
|
||||
break;
|
||||
case SOUTH:
|
||||
pos.setZ(pos.getZ() + 0.49);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
pos.setX(pos.getBlockX() + 0.5);
|
||||
if (pos.getY() - pos.getBlockY() != 0 && face == BlockFace.UP) {
|
||||
pos.setY(pos.getBlockY() + 1.0);
|
||||
} else if (hasHitEntity) {
|
||||
SWUtils.sendToActionbar(player, "§eEdit Position");
|
||||
} else {
|
||||
pos.setY(pos.getBlockY());
|
||||
SWUtils.sendToActionbar(player, "§eAdd new " + cursorType.getOrDefault(player, CursorType.TNT).name);
|
||||
}
|
||||
pos.setZ(pos.getBlockZ() + 0.5);
|
||||
return pos;
|
||||
}
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum CursorType {
|
||||
TNT(Material.TNT, Material.GUNPOWDER, SimulatorCursor::getPosFree, "TNT", vector -> new TNTElement(vector).add(new TNTPhase())),
|
||||
REDSTONE_BLOCK(Material.REDSTONE_BLOCK, Material.REDSTONE, SimulatorCursor::getPosBlockAligned, "Redstone Block", vector -> new RedstoneElement(vector).add(new RedstonePhase())),
|
||||
OBSERVER(Material.OBSERVER, Material.QUARTZ, SimulatorCursor::getPosBlockAligned, "Observer", vector -> new ObserverElement(vector).add(new ObserverPhase())),
|
||||
TNT(Material.TNT, Material.GUNPOWDER, List.of(Cursor.CursorMode.FREE, Cursor.CursorMode.SURFACE_ALIGNED), "TNT", vector -> new TNTElement(vector).add(new TNTPhase())),
|
||||
REDSTONE_BLOCK(Material.REDSTONE_BLOCK, Material.REDSTONE, List.of(Cursor.CursorMode.BLOCK_ALIGNED), "Redstone Block", vector -> new RedstoneElement(vector).add(new RedstonePhase())),
|
||||
OBSERVER(Material.OBSERVER, Material.QUARTZ, List.of(Cursor.CursorMode.BLOCK_ALIGNED), "Observer", vector -> new ObserverElement(vector).add(new ObserverPhase())),
|
||||
;
|
||||
|
||||
public final Material material;
|
||||
public final Material nonSelectedMaterial;
|
||||
public final BiFunction<Player, RayTraceUtils.RRayTraceResult, Vector> position;
|
||||
public final List<Cursor.CursorMode> cursorModes;
|
||||
public final String name;
|
||||
public final Function<Vector, SimulatorElement<?>> elementFunction;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
if (!ItemUtils.isItem(event.getItem(), "simulator")) {
|
||||
private static void handlePlayerClick(Player player, Location cursorLocation, Optional<REntity> hitEntity, Action action) {
|
||||
if (!Permission.BUILD.hasPermission(player)) return;
|
||||
if (!hasSimulatorItem(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
Player player = event.getPlayer();
|
||||
Simulator simulator = SimulatorStorage.getSimulator(player);
|
||||
|
||||
if (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_AIR) {
|
||||
if (action == Action.LEFT_CLICK_BLOCK || action == Action.LEFT_CLICK_AIR) {
|
||||
if (simulator == null) {
|
||||
return;
|
||||
}
|
||||
SimulatorExecutor.run(event.getPlayer(), simulator, null);
|
||||
SimulatorExecutor.run(player, simulator, null);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.RIGHT_CLICK_AIR) {
|
||||
if (action != Action.RIGHT_CLICK_BLOCK && action != Action.RIGHT_CLICK_AIR) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
RayTraceUtils.RRayTraceResult rayTraceResult = RayTraceUtils.traceREntity(player, player.getLocation(), SimulatorWatcher.getEntitiesOfSimulator(simulator));
|
||||
if (simulator == null) {
|
||||
if (rayTraceResult == null) {
|
||||
if (cursorLocation == null) {
|
||||
SimulatorStorage.openSimulatorSelector(player);
|
||||
} else {
|
||||
SWAnvilInv anvilInv = new SWAnvilInv(player, "Name");
|
||||
@@ -395,7 +290,7 @@ public class SimulatorCursor implements Listener {
|
||||
}
|
||||
sim = new Simulator(s);
|
||||
SimulatorStorage.addSimulator(s, sim);
|
||||
createElement(player, rayTraceResult, sim);
|
||||
createElement(player, cursorLocation, sim);
|
||||
SimulatorStorage.setSimulator(player, sim);
|
||||
});
|
||||
anvilInv.open();
|
||||
@@ -403,57 +298,56 @@ public class SimulatorCursor implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (rayTraceResult == null) {
|
||||
if (cursorLocation == null) {
|
||||
new SimulatorGui(player, simulator).open();
|
||||
return;
|
||||
}
|
||||
|
||||
if (rayTraceResult.getHitEntity() != null) {
|
||||
REntity hitEntity = rayTraceResult.getHitEntity();
|
||||
Vector vector = new Vector(hitEntity.getX(), hitEntity.getY(), hitEntity.getZ());
|
||||
List<SimulatorElement<?>> elements = simulator.getGroups().stream().map(SimulatorGroup::getElements).flatMap(List::stream).filter(element -> {
|
||||
return element.getWorldPos().distanceSquared(vector) < (1 / 16.0) * (1 / 16.0);
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
switch (elements.size()) {
|
||||
case 0:
|
||||
return;
|
||||
case 1:
|
||||
// Open single element present in Simulator
|
||||
SimulatorElement<?> element = elements.get(0);
|
||||
SimulatorGroup group1 = element.getGroup(simulator);
|
||||
SimulatorBaseGui back = new SimulatorGui(player, simulator);
|
||||
if (group1.getElements().size() > 1) {
|
||||
back = new SimulatorGroupGui(player, simulator, group1, back);
|
||||
}
|
||||
element.open(player, simulator, group1, back);
|
||||
break;
|
||||
default:
|
||||
List<SimulatorGroup> parents = elements.stream().map(e -> e.getGroup(simulator)).distinct().collect(Collectors.toList());
|
||||
if (parents.size() == 1) {
|
||||
// Open multi element present in Simulator in existing group
|
||||
SimulatorGui simulatorGui = new SimulatorGui(player, simulator);
|
||||
new SimulatorGroupGui(player, simulator, parents.get(0), simulatorGui).open();
|
||||
} else {
|
||||
// Open multi element present in Simulator in implicit group
|
||||
SimulatorGroup group2 = new SimulatorGroup();
|
||||
group2.setMaterial(null);
|
||||
group2.getElements().addAll(elements);
|
||||
SimulatorGui simulatorGui = new SimulatorGui(player, simulator);
|
||||
new SimulatorGroupGui(player, simulator, group2, simulatorGui).open();
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (hitEntity.isPresent()) {
|
||||
openElement(player, simulator, hitEntity.get());
|
||||
return;
|
||||
}
|
||||
|
||||
// Add new Element to current simulator
|
||||
createElement(player, rayTraceResult, simulator);
|
||||
createElement(player, cursorLocation, simulator);
|
||||
}
|
||||
|
||||
private void createElement(Player player, RayTraceUtils.RRayTraceResult rayTraceResult, Simulator simulator) {
|
||||
private static void openElement(Player player, Simulator simulator, REntity hitEntity) {
|
||||
Vector vector = new Vector(hitEntity.getX(), hitEntity.getY(), hitEntity.getZ());
|
||||
List<SimulatorElement<?>> elements = simulator.getGroups().stream().map(SimulatorGroup::getElements).flatMap(List::stream).filter(element -> {
|
||||
return element.getWorldPos().distanceSquared(vector) < (1 / 16.0) * (1 / 16.0);
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
switch (elements.size()) {
|
||||
case 0:
|
||||
return;
|
||||
case 1:
|
||||
SimulatorElement<?> element = elements.get(0);
|
||||
SimulatorGroup group1 = element.getGroup(simulator);
|
||||
SimulatorBaseGui back = new SimulatorGui(player, simulator);
|
||||
if (group1.getElements().size() > 1) {
|
||||
back = new SimulatorGroupGui(player, simulator, group1, back);
|
||||
}
|
||||
element.open(player, simulator, group1, back);
|
||||
break;
|
||||
default:
|
||||
List<SimulatorGroup> parents = elements.stream().map(e -> e.getGroup(simulator)).distinct().collect(Collectors.toList());
|
||||
if (parents.size() == 1) {
|
||||
SimulatorGui simulatorGui = new SimulatorGui(player, simulator);
|
||||
new SimulatorGroupGui(player, simulator, parents.get(0), simulatorGui).open();
|
||||
} else {
|
||||
SimulatorGroup group2 = new SimulatorGroup();
|
||||
group2.setMaterial(null);
|
||||
group2.getElements().addAll(elements);
|
||||
SimulatorGui simulatorGui = new SimulatorGui(player, simulator);
|
||||
new SimulatorGroupGui(player, simulator, group2, simulatorGui).open();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static void createElement(Player player, Location cursorLocation, Simulator simulator) {
|
||||
CursorType type = cursorType.getOrDefault(player, CursorType.TNT);
|
||||
Vector vector = type.position.apply(player, rayTraceResult);
|
||||
Vector vector = cursorLocation.toVector();
|
||||
if (type == CursorType.REDSTONE_BLOCK) {
|
||||
vector.subtract(new Vector(0.5, 0, 0.5));
|
||||
}
|
||||
|
||||
+7
@@ -124,4 +124,11 @@ public class SimulatorWatcher {
|
||||
}
|
||||
return entityServer.getEntities();
|
||||
}
|
||||
|
||||
synchronized REntityServer getEntityServerOfSimulator(Simulator simulator) {
|
||||
if (simulator == null) {
|
||||
return null;
|
||||
}
|
||||
return entityServers.computeIfAbsent(simulator, __ -> createSim(new REntityServer(), simulator));
|
||||
}
|
||||
}
|
||||
|
||||
+73
@@ -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.bausystem.features.slaves.blastresistance;
|
||||
|
||||
import com.google.common.util.concurrent.AtomicDouble;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@Linked
|
||||
public class BlastResistanceCommand extends SWCommand {
|
||||
|
||||
public BlastResistanceCommand() {
|
||||
super("blastresistance");
|
||||
}
|
||||
|
||||
@Register(description = "BLASTRESISTANCE_HELP")
|
||||
public void command(@Validator Player player) {
|
||||
LocalSession localSession = WorldEdit.getInstance().getSessionManager().get(BukkitAdapter.adapt(player));
|
||||
Clipboard clipboard;
|
||||
try {
|
||||
clipboard = localSession.getClipboard().getClipboards().getFirst();
|
||||
} catch (WorldEditException e) {
|
||||
BauSystem.MESSAGE.send("BLASTRESISTANCE_NO_CLIPBOARD", player);
|
||||
return;
|
||||
}
|
||||
|
||||
AtomicDouble min = new AtomicDouble(0);
|
||||
AtomicDouble max = new AtomicDouble(0);
|
||||
AtomicDouble sum = new AtomicDouble(0);
|
||||
AtomicInteger count = new AtomicInteger(0);
|
||||
clipboard.forEach(blockVector3 -> {
|
||||
BlockState blockState = clipboard.getBlock(blockVector3);
|
||||
Material material = BukkitAdapter.adapt(blockState).getMaterial();
|
||||
if (material == Material.WATER || material == Material.LAVA) return;
|
||||
double blastResistance = BukkitAdapter.adapt(blockState).getMaterial().getBlastResistance();
|
||||
min.set(Math.min(min.get(), blastResistance));
|
||||
max.set(Math.max(max.get(), blastResistance));
|
||||
sum.addAndGet(blastResistance);
|
||||
count.getAndIncrement();
|
||||
});
|
||||
|
||||
BauSystem.MESSAGE.send("BLASTRESISTANCE_RESULT", player, min.get(), max.get(), sum.get() / count.get());
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import de.steamwar.bausystem.features.tracer.rendering.TraceEntity;
|
||||
import de.steamwar.bausystem.features.tracer.rendering.ViewFlag;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.entity.REntity;
|
||||
import de.steamwar.entity.REntityAction;
|
||||
import de.steamwar.entity.REntityServer;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -143,14 +144,6 @@ public class Trace {
|
||||
} else {
|
||||
entityServer = new REntityServer();
|
||||
entityServer.addPlayer(player);
|
||||
entityServer.setCallback((p, rEntity, entityAction) -> {
|
||||
if (entityAction != REntityServer.EntityAction.INTERACT) {
|
||||
return;
|
||||
}
|
||||
if (rEntity instanceof TraceEntity) {
|
||||
((TraceEntity) rEntity).printIntoChat(p);
|
||||
}
|
||||
});
|
||||
entityServerMap.put(player, entityServer);
|
||||
}
|
||||
render(getRecords(), entityServer, playerTraceShowData);
|
||||
@@ -167,14 +160,6 @@ public class Trace {
|
||||
REntityServer entityServer = entityServerMap.computeIfAbsent(player, k -> {
|
||||
REntityServer newEntityServer = new REntityServer();
|
||||
newEntityServer.addPlayer(k);
|
||||
newEntityServer.setCallback((p, rEntity, entityAction) -> {
|
||||
if (entityAction != REntityServer.EntityAction.INTERACT) {
|
||||
return;
|
||||
}
|
||||
if (rEntity instanceof TraceEntity) {
|
||||
((TraceEntity) rEntity).printIntoChat(p);
|
||||
}
|
||||
});
|
||||
return newEntityServer;
|
||||
});
|
||||
|
||||
|
||||
+18
@@ -25,7 +25,9 @@ import de.steamwar.bausystem.features.tracer.TNTPoint;
|
||||
import de.steamwar.bausystem.features.tracer.Trace;
|
||||
import de.steamwar.bausystem.features.tracer.TraceManager;
|
||||
import de.steamwar.entity.RBlockDisplay;
|
||||
import de.steamwar.entity.REntityAction;
|
||||
import de.steamwar.entity.REntityServer;
|
||||
import de.steamwar.entity.RInteraction;
|
||||
import lombok.Getter;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import org.bukkit.Location;
|
||||
@@ -67,6 +69,7 @@ public class TraceEntity extends RBlockDisplay {
|
||||
private final String uniqueTntIdsString;
|
||||
|
||||
private final Trace trace;
|
||||
private final RInteraction hitbox;
|
||||
|
||||
public TraceEntity(REntityServer server, Location location, boolean isExplosion, List<TNTPoint> records, Trace trace) {
|
||||
super(server, location);
|
||||
@@ -74,8 +77,23 @@ public class TraceEntity extends RBlockDisplay {
|
||||
this.records = records;
|
||||
this.trace = trace;
|
||||
uniqueTntIdsString = records.stream().map(TNTPoint::getTntId).distinct().map(Object::toString).collect(Collectors.joining(" "));
|
||||
hitbox = new RInteraction(server, location);
|
||||
hitbox.setInteractionHeight(TNT_VISUAL_SCALE);
|
||||
hitbox.setInteractionWidth(TNT_VISUAL_SCALE);
|
||||
hitbox.setCallback((player, action) -> {
|
||||
if (action == REntityAction.INTERACT) {
|
||||
printIntoChat(player);
|
||||
}
|
||||
});
|
||||
setTransform(TNT_VISUAL_TRANSFORM);
|
||||
setBlock(material.createBlockData());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void die() {
|
||||
hitbox.die();
|
||||
super.die();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+5
-5
@@ -20,8 +20,8 @@
|
||||
package de.steamwar.bausystem.features.tracer.rendering;
|
||||
|
||||
import de.steamwar.bausystem.features.tracer.TNTPoint;
|
||||
import de.steamwar.entity.RBlockDisplay;
|
||||
import de.steamwar.entity.REntityServer;
|
||||
import de.steamwar.entity.RFallingBlockEntity;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.util.Vector;
|
||||
@@ -129,8 +129,8 @@ public abstract class ViewFlag {
|
||||
|
||||
Location yLocation = previous.getLocation().clone().add(0, delta.getY(), 0);
|
||||
if (yLocation.distanceSquared(representative.getLocation()) >= 1.0 / 256.0 && yLocation.distanceSquared(previous.getLocation()) >= 1.0 / 256.0) {
|
||||
RFallingBlockEntity y = new RFallingBlockEntity(server, yLocation, Material.WHITE_STAINED_GLASS);
|
||||
y.setNoGravity(true);
|
||||
RBlockDisplay y = new RBlockDisplay(server, yLocation);
|
||||
y.setBlock(Material.WHITE_STAINED_GLASS.createBlockData());
|
||||
}
|
||||
|
||||
Location secoundLocation;
|
||||
@@ -141,8 +141,8 @@ public abstract class ViewFlag {
|
||||
}
|
||||
|
||||
if (secoundLocation.distanceSquared(representative.getLocation()) >= 1.0 / 256.0 && secoundLocation.distanceSquared(previous.getLocation()) >= 1.0 / 256.0) {
|
||||
RFallingBlockEntity second = new RFallingBlockEntity(server, secoundLocation, Material.WHITE_STAINED_GLASS);
|
||||
second.setNoGravity(true);
|
||||
RBlockDisplay second = new RBlockDisplay(server, secoundLocation);
|
||||
second.setBlock(Material.WHITE_STAINED_GLASS.createBlockData());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,5 +37,6 @@ tasks.register<DevServer>("DevBau21") {
|
||||
dependsOn(":SpigotCore:shadowJar")
|
||||
dependsOn(":BauSystem:shadowJar")
|
||||
dependsOn(":SchematicSystem:shadowJar")
|
||||
dependsOn(":KotlinCore:shadowJar")
|
||||
template = "Bau21"
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ public class ArrowStopper {
|
||||
private void run() {
|
||||
Recording.iterateOverEntities(AbstractArrow.class::isInstance, entity -> {
|
||||
Projectile arrow = (Projectile) entity;
|
||||
if(!(arrow.getShooter() instanceof Player)) return;
|
||||
if (invalidEntity(arrow)) return;
|
||||
|
||||
Location prevLocation = arrow.getLocation().toVector().subtract(arrow.getVelocity()).toLocation(arrow.getWorld());
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
@@ -41,3 +43,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,82 @@
|
||||
/*
|
||||
* 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 kotlin.properties.ReadOnlyProperty
|
||||
import kotlin.properties.ReadWriteProperty
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
abstract class Observable<T> {
|
||||
private val listeners = mutableSetOf<ObserverListener>()
|
||||
|
||||
fun removeListener(render: ObserverListener) {
|
||||
listeners.remove(render)
|
||||
}
|
||||
|
||||
internal fun notifyListeners() {
|
||||
listeners.forEach { it.update() }
|
||||
}
|
||||
|
||||
context(render: ObserverListener)
|
||||
fun listen(): Observable<T> {
|
||||
listeners.add(render)
|
||||
render.observers.add(this)
|
||||
return this
|
||||
}
|
||||
|
||||
fun listen(callback: (T) -> Unit): () -> Unit {
|
||||
val listener = object: ObserverListener() {
|
||||
override fun update() = callback(get())
|
||||
}
|
||||
listeners.add(listener)
|
||||
return { removeListener(listener) }
|
||||
}
|
||||
|
||||
abstract fun get(): T
|
||||
|
||||
fun <R> map(mapper: (T) -> R): ReadOnlyProperty<Any?, R> = Delegate(mapper(get()))
|
||||
|
||||
class Delegate<T>(val value: T): ReadOnlyProperty<Any?, T> {
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): T = value
|
||||
}
|
||||
}
|
||||
|
||||
class Observer<T>(private var value: T): ReadWriteProperty<Any?, T>, Observable<T>() {
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): T {
|
||||
return value
|
||||
}
|
||||
|
||||
override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) {
|
||||
this.value = value
|
||||
notifyListeners()
|
||||
}
|
||||
|
||||
fun set(value: T) {
|
||||
this.value = value
|
||||
notifyListeners()
|
||||
}
|
||||
|
||||
override fun get() = value
|
||||
|
||||
fun update(update: (T) -> T) {
|
||||
this.value = update(value)
|
||||
notifyListeners()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
abstract class ObserverListener {
|
||||
val observers = mutableSetOf<Observable<*>>()
|
||||
|
||||
abstract fun update()
|
||||
|
||||
open fun destroy() {
|
||||
observers.forEach { it.removeListener(this) }
|
||||
observers.clear()
|
||||
}
|
||||
}
|
||||
@@ -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,53 @@
|
||||
/*
|
||||
* 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): ObserverListener() {
|
||||
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()
|
||||
}
|
||||
|
||||
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,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.components
|
||||
|
||||
import de.steamwar.kotlin.ui.ObserverListener
|
||||
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, ObserverListener() {
|
||||
override fun update() {
|
||||
val oldX = x
|
||||
val oldY = y
|
||||
render()
|
||||
if (oldX != x || oldY != y) {
|
||||
parent.resetSlot(oldX, oldY)
|
||||
}
|
||||
}
|
||||
|
||||
override fun 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.ObserverListener
|
||||
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): ObserverListener(), 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) } }
|
||||
@@ -20,7 +20,9 @@
|
||||
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;
|
||||
import de.steamwar.lobby.util.LeaderboardManager;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
@@ -58,11 +60,12 @@ public class BoatRace implements EventListener, Listener {
|
||||
|
||||
static {
|
||||
boatNpcServer = new REntityServer();
|
||||
REntity starter = new REntity(boatNpcServer, EntityType.VILLAGER, BoatRacePositions.NPC);
|
||||
boatNpcServer.setCallback((player, rEntity, entityAction) -> {
|
||||
if (rEntity != starter) return;
|
||||
Bukkit.getWorlds().get(0).getEntities().stream().filter(entity -> entity.getType() == EntityType.END_CRYSTAL).forEach(Entity::remove);
|
||||
if (entityAction == REntityServer.EntityAction.INTERACT && !oneNotStarted) {
|
||||
new REntity(boatNpcServer, EntityType.VILLAGER, BoatRacePositions.NPC);
|
||||
RInteraction interaction = new RInteraction(boatNpcServer, BoatRacePositions.NPC.clone().subtract(0.5, 0, 0.5));
|
||||
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) {
|
||||
oneNotStarted = true;
|
||||
new BoatRace(player);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,240 @@
|
||||
package de.steamwar.cursor;
|
||||
|
||||
import de.steamwar.core.SWPlayer;
|
||||
import de.steamwar.entity.REntity;
|
||||
import de.steamwar.entity.REntityServer;
|
||||
import de.steamwar.entity.RFallingBlockEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@Getter
|
||||
public class Cursor implements SWPlayer.Component {
|
||||
private final World WORLD = Bukkit.getWorlds().get(0);
|
||||
|
||||
private final REntityServer targetServer;
|
||||
private final Player owner;
|
||||
|
||||
private final AtomicBoolean isRendering = new AtomicBoolean(false);
|
||||
|
||||
private RFallingBlockEntity cursorEntity;
|
||||
private final REntityServer cursorServer;
|
||||
private Location cursorLocation;
|
||||
private REntity hitEntity;
|
||||
|
||||
@Setter
|
||||
private Material cursorMaterial;
|
||||
@Setter
|
||||
private List<CursorMode> allowedCursorModes;
|
||||
private final Material highlightMaterial;
|
||||
private final ClickHandler onClick;
|
||||
private final BiConsumer<Location, Optional<REntity>> onRender;
|
||||
|
||||
|
||||
public Cursor(REntityServer targetServer, Player owner, Material highlightMaterial, Material cursorMaterial, List<CursorMode> allowedModes, ClickHandler onClick) {
|
||||
this(targetServer, owner, highlightMaterial, cursorMaterial, allowedModes, onClick, (location, hitEntity) -> {
|
||||
});
|
||||
}
|
||||
|
||||
public Cursor(REntityServer targetServer, Player owner, Material highlightMaterial, Material cursorMaterial, List<CursorMode> allowedModes, ClickHandler onClick, BiConsumer<Location, Optional<REntity>> onRender) {
|
||||
this.targetServer = targetServer;
|
||||
this.owner = owner;
|
||||
this.highlightMaterial = highlightMaterial;
|
||||
this.cursorMaterial = cursorMaterial;
|
||||
this.allowedCursorModes = allowedModes;
|
||||
this.onClick = onClick;
|
||||
this.onRender = onRender;
|
||||
|
||||
cursorServer = new REntityServer();
|
||||
cursorServer.addPlayer(owner);
|
||||
|
||||
SWPlayer.of(owner).setComponent(this);
|
||||
}
|
||||
|
||||
public void renderDeduplicated() {
|
||||
if (!isRendering.getAndSet(true)) {
|
||||
render();
|
||||
isRendering.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void render() {
|
||||
RayTraceUtils.RRayTraceResult rayTraceResult = RayTraceUtils.traceREntity(owner, owner.getLocation(), targetServer.getEntities());
|
||||
if (rayTraceResult == null) {
|
||||
if (cursorEntity != null)
|
||||
cursorEntity.die();
|
||||
cursorEntity = null;
|
||||
cursorLocation = null;
|
||||
hitEntity = null;
|
||||
onRender.accept(null, Optional.empty());
|
||||
return;
|
||||
}
|
||||
|
||||
REntity hitEntity = rayTraceResult.getHitEntity() == cursorEntity ? null : rayTraceResult.getHitEntity();
|
||||
|
||||
|
||||
Material activeCursorMaterial = hitEntity == null ? cursorMaterial : highlightMaterial;
|
||||
CursorMode activeCursorMode = allowedCursorModes.stream().filter((mode) -> mode.isActive.test(owner)).min(Comparator.comparingInt(a -> a.priority))
|
||||
.orElse(CursorMode.BLOCK_ALIGNED);
|
||||
|
||||
Location activeCursorLocation = hitEntity == null ? activeCursorMode.positionTransform.apply(owner, rayTraceResult).toLocation(WORLD)
|
||||
: new Vector(hitEntity.getX(), hitEntity.getY(), hitEntity.getZ()).toLocation(WORLD);
|
||||
|
||||
cursorLocation = activeCursorLocation;
|
||||
this.hitEntity = hitEntity;
|
||||
|
||||
if (cursorEntity == null) {
|
||||
cursorEntity = new RFallingBlockEntity(cursorServer, activeCursorLocation, activeCursorMaterial);
|
||||
cursorEntity.setNoGravity(true);
|
||||
} else if (cursorEntity.getMaterial() == activeCursorMaterial) {
|
||||
cursorEntity.move(activeCursorLocation);
|
||||
} else {
|
||||
cursorEntity.die();
|
||||
cursorEntity = new RFallingBlockEntity(cursorServer, activeCursorLocation, activeCursorMaterial);
|
||||
cursorEntity.setNoGravity(true);
|
||||
if (activeCursorMaterial == highlightMaterial) {
|
||||
cursorEntity.setGlowing(true);
|
||||
}
|
||||
}
|
||||
onRender.accept(cursorLocation, Optional.ofNullable(hitEntity));
|
||||
}
|
||||
|
||||
protected void handlePlayerClick(Action clickAction) {
|
||||
renderDeduplicated();
|
||||
onClick.onClick(this.cursorLocation, Optional.ofNullable(this.hitEntity), clickAction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnmount(SWPlayer player) {
|
||||
cursorServer.close();
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
public enum CursorMode {
|
||||
FREE(1, (player, rayTraceResult) -> {
|
||||
Vector pos = rayTraceResult.getHitPosition();
|
||||
|
||||
BlockFace face = rayTraceResult.getHitBlockFace();
|
||||
if (face != null) {
|
||||
switch (face) {
|
||||
case DOWN:
|
||||
pos.setY(pos.getY() - 0.98);
|
||||
break;
|
||||
case EAST:
|
||||
pos.setX(pos.getX() + 0.49);
|
||||
break;
|
||||
case WEST:
|
||||
pos.setX(pos.getX() - 0.49);
|
||||
break;
|
||||
case NORTH:
|
||||
pos.setZ(pos.getZ() - 0.49);
|
||||
break;
|
||||
case SOUTH:
|
||||
pos.setZ(pos.getZ() + 0.49);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (face.getModY() == 0 && player.isSneaking()) {
|
||||
pos.setY(pos.getY() - 0.49);
|
||||
}
|
||||
}
|
||||
|
||||
return pos;
|
||||
}, Player::isSneaking),
|
||||
|
||||
SURFACE_ALIGNED(2, (player, rayTraceResult) -> {
|
||||
Vector hitPosition = rayTraceResult.getHitPosition().clone();
|
||||
Vector pos = blockAlignedPosition(rayTraceResult);
|
||||
BlockFace face = rayTraceResult.getHitBlockFace();
|
||||
|
||||
if (face != null && face != BlockFace.SELF) {
|
||||
switch (face) {
|
||||
case UP:
|
||||
pos.setY(hitPosition.getY());
|
||||
break;
|
||||
case DOWN:
|
||||
pos.setY(hitPosition.getY() + face.getModY());
|
||||
break;
|
||||
case EAST:
|
||||
case WEST:
|
||||
pos.setX(hitPosition.getX() + face.getModX() * 0.5);
|
||||
break;
|
||||
case NORTH:
|
||||
case SOUTH:
|
||||
pos.setZ(hitPosition.getZ() + face.getModZ() * 0.5);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return pos;
|
||||
}, (player) -> true),
|
||||
|
||||
BLOCK_ALIGNED(0, (player, rayTraceResult) -> blockAlignedPosition(rayTraceResult), (player) -> true);
|
||||
|
||||
|
||||
private final int priority;
|
||||
private final BiFunction<Player, RayTraceUtils.RRayTraceResult, Vector> positionTransform;
|
||||
private final Predicate<Player> isActive;
|
||||
|
||||
private static Vector blockAlignedPosition(RayTraceUtils.RRayTraceResult rayTraceResult) {
|
||||
Vector pos = rayTraceResult.getHitPosition();
|
||||
|
||||
BlockFace face = rayTraceResult.getHitBlockFace();
|
||||
if (face != null) {
|
||||
switch (face) {
|
||||
case DOWN:
|
||||
pos.setY(pos.getY() - 0.98);
|
||||
break;
|
||||
case EAST:
|
||||
pos.setX(pos.getX() + 0.49);
|
||||
break;
|
||||
case WEST:
|
||||
pos.setX(pos.getX() - 0.49);
|
||||
break;
|
||||
case NORTH:
|
||||
pos.setZ(pos.getZ() - 0.49);
|
||||
break;
|
||||
case SOUTH:
|
||||
pos.setZ(pos.getZ() + 0.49);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
pos.setX(pos.getBlockX() + 0.5);
|
||||
if (pos.getY() - pos.getBlockY() != 0 && face == BlockFace.UP) {
|
||||
pos.setY(pos.getBlockY() + 1.0);
|
||||
} else {
|
||||
pos.setY(pos.getBlockY());
|
||||
}
|
||||
pos.setZ(pos.getBlockZ() + 0.5);
|
||||
return pos;
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ClickHandler {
|
||||
void onClick(Location location, Optional<REntity> hitEntity, Action action);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package de.steamwar.cursor;
|
||||
|
||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.core.SWPlayer;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
@Linked
|
||||
public class CursorListener implements Listener {
|
||||
@Getter
|
||||
private static CursorListener instance;
|
||||
|
||||
public CursorListener() {
|
||||
if (instance == null) {
|
||||
instance = this;
|
||||
}
|
||||
|
||||
TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.Pos.class, this::updateCursorFromPacket);
|
||||
TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.Rot.class, this::updateCursorFromPacket);
|
||||
TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.PosRot.class, this::updateCursorFromPacket);
|
||||
|
||||
Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> {
|
||||
SWPlayer.allWithSingleComponent(Cursor.class)
|
||||
.map(SWPlayer.SWPlayerWithComponent::getComponent)
|
||||
.forEach(Cursor::renderDeduplicated);
|
||||
}, 1, 1);
|
||||
}
|
||||
|
||||
public Packet<?> updateCursorFromPacket(Player player, Packet<?> packet) {
|
||||
SWPlayer swPlayer = SWPlayer.of(player);
|
||||
Optional<Cursor> activeCursor = swPlayer.getComponent(Cursor.class);
|
||||
|
||||
activeCursor.ifPresent(Cursor::renderDeduplicated);
|
||||
|
||||
return packet;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
SWPlayer.of(event.getPlayer()).getComponent(Cursor.class).ifPresent(cursor -> {
|
||||
event.setCancelled(true);
|
||||
cursor.handlePlayerClick(event.getAction());
|
||||
});
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -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.bausystem.utils;
|
||||
package de.steamwar.cursor;
|
||||
|
||||
import de.steamwar.entity.REntity;
|
||||
import lombok.Data;
|
||||
@@ -20,6 +20,7 @@
|
||||
package de.steamwar.entity;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.minecraft.network.syncher.EntityDataAccessor;
|
||||
import net.minecraft.network.syncher.EntityDataSerializers;
|
||||
import org.bukkit.Location;
|
||||
@@ -27,13 +28,16 @@ import org.bukkit.entity.EntityType;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class RArmorStand extends REntity {
|
||||
@Getter
|
||||
public class RArmorStand extends REntity implements RInteractableEntity<RArmorStand> {
|
||||
|
||||
private static final EntityDataAccessor<Byte> sizeWatcher = new EntityDataAccessor<>(15, EntityDataSerializers.BYTE);
|
||||
|
||||
@Getter
|
||||
private final Size size;
|
||||
|
||||
@Setter
|
||||
private REntityActionListener<RArmorStand> callback = null;
|
||||
|
||||
public RArmorStand(REntityServer server, Location location, Size size) {
|
||||
super(server, EntityType.ARMOR_STAND, location, 0);
|
||||
this.size = size;
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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.entity;
|
||||
|
||||
public enum REntityAction {
|
||||
INTERACT,
|
||||
ATTACK,
|
||||
}
|
||||
@@ -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.entity;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface REntityActionListener<E extends REntity> {
|
||||
void onAction(Player player, E entity, REntityAction action);
|
||||
}
|
||||
@@ -51,7 +51,6 @@ public class REntityServer implements Listener {
|
||||
private final HashMap<Player, Location> lastLocation = new HashMap<>();
|
||||
private final HashMap<Player, Integer> viewDistance = new HashMap<>();
|
||||
|
||||
private EntityActionListener callback = null;
|
||||
private final Set<Player> playersThatClicked = Collections.synchronizedSet(new HashSet<>());
|
||||
|
||||
private final BiFunction<Player, ServerboundInteractPacket, Object> filter = (player, packet) -> {
|
||||
@@ -61,25 +60,19 @@ public class REntityServer implements Listener {
|
||||
if (playersThatClicked.contains(player)) return null;
|
||||
|
||||
playersThatClicked.add(player);
|
||||
EntityAction action = packet.isAttack() ? EntityAction.ATTACK : EntityAction.INTERACT;
|
||||
REntityAction action = packet.isAttack() ? REntityAction.ATTACK : REntityAction.INTERACT;
|
||||
Bukkit.getScheduler().runTask(Core.getInstance(), () -> {
|
||||
playersThatClicked.remove(player);
|
||||
callback.onAction(player, entity, action);
|
||||
if (entity instanceof RInteractableEntity interactable && interactable.getCallback() != null) {
|
||||
interactable.getCallback().onAction(player, entity, action);
|
||||
}
|
||||
});
|
||||
return null;
|
||||
};
|
||||
|
||||
public REntityServer() {
|
||||
Core.getInstance().getServer().getPluginManager().registerEvents(this, Core.getInstance());
|
||||
}
|
||||
|
||||
public void setCallback(EntityActionListener callback) {
|
||||
boolean uninitialized = this.callback == null;
|
||||
this.callback = callback;
|
||||
|
||||
if (uninitialized) {
|
||||
TinyProtocol.instance.addFilter(ServerboundInteractPacket.class, filter);
|
||||
}
|
||||
TinyProtocol.instance.addFilter(ServerboundInteractPacket.class, filter);
|
||||
}
|
||||
|
||||
public void addPlayer(Player player) {
|
||||
@@ -293,13 +286,4 @@ public class REntityServer implements Listener {
|
||||
private long chunkToId(int x, int z) {
|
||||
return ((long) x << 32) + z;
|
||||
}
|
||||
|
||||
public enum EntityAction {
|
||||
INTERACT,
|
||||
ATTACK,
|
||||
}
|
||||
|
||||
public interface EntityActionListener {
|
||||
void onAction(Player player, REntity entity, EntityAction action);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,16 +20,21 @@
|
||||
package de.steamwar.entity;
|
||||
|
||||
import de.steamwar.techhider.BlockIds;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
@Getter
|
||||
public class RFallingBlockEntity extends REntity {
|
||||
public class RFallingBlockEntity extends REntity implements RInteractableEntity<RFallingBlockEntity> {
|
||||
|
||||
private final Material material;
|
||||
|
||||
@Setter
|
||||
private REntityActionListener<RFallingBlockEntity> callback = null;
|
||||
|
||||
public RFallingBlockEntity(REntityServer server, Location location, Material material) {
|
||||
super(server, EntityType.FALLING_BLOCK, location, BlockIds.impl.materialToId(material));
|
||||
this.material = material;
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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.entity;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
public interface RInteractableEntity<E extends REntity> {
|
||||
REntityActionListener<E> getCallback();
|
||||
|
||||
void setCallback(REntityActionListener<E> callback);
|
||||
|
||||
default void setCallback(BiConsumer<Player, REntityAction> callback) {
|
||||
setCallback((player, interaction, entityAction) -> callback.accept(player, entityAction));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* 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.entity;
|
||||
|
||||
import de.steamwar.core.BountifulWrapper;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* !! This class cannot be used in Versions lower than or equal to 1.19.4 !!
|
||||
*/
|
||||
@Getter
|
||||
public class RInteraction extends REntity implements RInteractableEntity<RInteraction> {
|
||||
|
||||
protected final Consumer<Object> updatePacketSink = o -> server.updateEntity(this, o);
|
||||
|
||||
@Setter
|
||||
private REntityActionListener<RInteraction> callback = null;
|
||||
|
||||
private float interactionWidth = 1.0f;
|
||||
private float interactionHeight = 1.0f;
|
||||
private boolean responsive = false;
|
||||
|
||||
public RInteraction(REntityServer server, Location location) {
|
||||
super(server, EntityType.INTERACTION, location);
|
||||
server.addEntity(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void postSpawn(Consumer<Object> packetSink) {
|
||||
super.postSpawn(packetSink);
|
||||
sendPacket(packetSink,
|
||||
this::getInteractionWidthData,
|
||||
this::getInteractionHeightData,
|
||||
this::getResponsiveData
|
||||
);
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
protected final void sendPacket(Consumer<Object> packetSink, BiConsumer<Boolean, BiConsumer<Object, Object>>... dataSinkSinks) {
|
||||
List<Object> keyValueData = new ArrayList<>();
|
||||
boolean ignoreDefault = packetSink == updatePacketSink;
|
||||
for (BiConsumer<Boolean, BiConsumer<Object, Object>> dataSinkSink : dataSinkSinks) {
|
||||
dataSinkSink.accept(ignoreDefault, (dataWatcher, value) -> {
|
||||
keyValueData.add(dataWatcher);
|
||||
keyValueData.add(value);
|
||||
});
|
||||
}
|
||||
if (!keyValueData.isEmpty()) {
|
||||
packetSink.accept(getDataWatcherPacket(keyValueData.toArray()));
|
||||
}
|
||||
}
|
||||
|
||||
public void setInteractionWidth(float interactionWidth) {
|
||||
this.interactionWidth = interactionWidth;
|
||||
sendPacket(updatePacketSink, this::getInteractionWidthData);
|
||||
}
|
||||
|
||||
private static final Object interactionWidthWatcher = BountifulWrapper.impl.getDataWatcherObject(8, Float.class);
|
||||
|
||||
private void getInteractionWidthData(boolean ignoreDefault, BiConsumer<Object, Object> dataSink) {
|
||||
if (ignoreDefault || interactionWidth != 1.0) {
|
||||
dataSink.accept(interactionWidthWatcher, interactionWidth);
|
||||
}
|
||||
}
|
||||
|
||||
public void setInteractionHeight(float interactionHeight) {
|
||||
this.interactionHeight = interactionHeight;
|
||||
sendPacket(updatePacketSink, this::getInteractionHeightData);
|
||||
}
|
||||
|
||||
private static final Object interactionHeightWatcher = BountifulWrapper.impl.getDataWatcherObject(9, Float.class);
|
||||
|
||||
private void getInteractionHeightData(boolean ignoreDefault, BiConsumer<Object, Object> dataSink) {
|
||||
if (ignoreDefault || interactionHeight != 1.0) {
|
||||
dataSink.accept(interactionHeightWatcher, interactionHeight);
|
||||
}
|
||||
}
|
||||
|
||||
public void setResponsive(boolean responsive) {
|
||||
this.responsive = responsive;
|
||||
sendPacket(updatePacketSink, this::getResponsiveData);
|
||||
}
|
||||
|
||||
private static final Object responsiveWatcher = BountifulWrapper.impl.getDataWatcherObject(10, Boolean.class);
|
||||
|
||||
private void getResponsiveData(boolean ignoreDefault, BiConsumer<Object, Object> dataSink) {
|
||||
if (ignoreDefault || !responsive) {
|
||||
dataSink.accept(responsiveWatcher, responsive);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ import de.steamwar.network.CoreNetworkHandler;
|
||||
import de.steamwar.network.NetworkSender;
|
||||
import de.steamwar.network.packets.common.PlayerSkinRequestPacket;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.minecraft.network.protocol.game.ClientboundAddEntityPacket;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.bukkit.GameMode;
|
||||
@@ -39,7 +40,7 @@ import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class RPlayer extends REntity {
|
||||
public class RPlayer extends REntity implements RInteractableEntity<RPlayer> {
|
||||
|
||||
private static final Object skinPartsDataWatcher = BountifulWrapper.impl.getDataWatcherObject(17, Byte.class);
|
||||
|
||||
@@ -48,6 +49,10 @@ public class RPlayer extends REntity {
|
||||
@Getter
|
||||
private final String name;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
private REntityActionListener<RPlayer> callback = null;
|
||||
|
||||
public RPlayer(REntityServer server, UUID uuid, String name, Location location) {
|
||||
super(server, EntityType.PLAYER, UUID.nameUUIDFromBytes(uuid.toString().getBytes(StandardCharsets.UTF_8)), location, 0);
|
||||
this.actualUUID = uuid;
|
||||
|
||||
@@ -152,7 +152,7 @@ public class TechHider {
|
||||
ClientboundSetHeldSlotPacket.class, // 7.1.104 Set Held Item (Player owning the channel)
|
||||
ClientboundSetObjectivePacket.class, // 7.1.105 Update Objectives
|
||||
ClientboundSetPlayerInventoryPacket.class, // 7.1.107 Set Player Inventory Slot (Player owning the channel)
|
||||
ClientboundSetPlayerTeamPacket.class, // 7.1.108 Update Teams
|
||||
// ClientboundSetPlayerTeamPacket.class, // 7.1.108 Update Teams
|
||||
ClientboundSetScorePacket.class, // 7.1.109 Update Score
|
||||
ClientboundSetSimulationDistancePacket.class, // 7.1.110 Set Simulation Distance
|
||||
ClientboundSetSubtitleTextPacket.class, // 7.1.111 Set Subtitle Text
|
||||
|
||||
@@ -42,11 +42,12 @@ dependencies {
|
||||
implementation(project(":CommandFramework"))
|
||||
}
|
||||
|
||||
tasks.register<DevServer>("DevVelocity") {
|
||||
tasks.register<VelocityServer>("DevVelocity") {
|
||||
group = "run"
|
||||
description = "Run a Dev Velocity"
|
||||
dependsOn(":VelocityCore:shadowJar")
|
||||
dependsOn(":VelocityCore:Persistent:jar")
|
||||
dependsOn(":VelocityCore:Dependencies:shadowJar")
|
||||
template = "DevVelocity"
|
||||
packetDecodeLogging=true
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ public class ServerStarter {
|
||||
public ServerStarter event(EventFight eventFight) {
|
||||
arena(ArenaMode.getByInternal(eventFight.getSpielmodus()), eventFight.getMap());
|
||||
node = VelocityCore.local;
|
||||
worldDir = EVENT_PATH;
|
||||
worldDir = EVENT_PATH + "/" + serverToWorldName(Event.byId(eventFight.getEventID()).getEventName()) + "/" + eventFight.getStartTime().toLocalDateTime().format(DateTimeFormatter.ISO_LOCAL_DATE);
|
||||
worldCleanup = () -> {
|
||||
};
|
||||
arguments.put("fightID", String.valueOf(eventFight.getFightID()));
|
||||
@@ -351,7 +351,7 @@ public class ServerStarter {
|
||||
}
|
||||
|
||||
public static String serverToWorldName(String serverName) {
|
||||
return serverName.replace(' ', '_').replace("[", "").replace("]", "");
|
||||
return serverName.replace(' ', '_').replace("[", "").replace("]", "").replace(".", "");
|
||||
}
|
||||
|
||||
public static void copyWorld(Node node, String template, String target) {
|
||||
|
||||
@@ -307,6 +307,13 @@ public class CheckCommand extends SWCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove any added players from the schematic in the folder
|
||||
for (SchematicNode schematicNode : SchematicNode.getSchematicNodeInNode(teamFolder.getNodeId())) {
|
||||
for (NodeMember nodeMember : NodeMember.getNodeMembers(schematicNode.getNodeId())) {
|
||||
nodeMember.delete();
|
||||
}
|
||||
}
|
||||
|
||||
// Copy Schem into team folder of -1 user
|
||||
String name = DateTimeFormatter.ofPattern("yyyy.MM.dd_HH:mm:ss").format(schematic.getLastUpdate().toLocalDateTime());
|
||||
NodeData data = NodeData.getLatest(schematic);
|
||||
@@ -316,14 +323,8 @@ public class CheckCommand extends SWCommand {
|
||||
// Accept the team folder schematic and set other to Normal as well as adding the original owner on the schematic
|
||||
node.setSchemtype(GameModeConfig.getBySchematicType(schematic.getSchemtype()).Schematic.Type);
|
||||
NodeMember.createNodeMember(node.getNodeId(), schematic.getOwner());
|
||||
|
||||
// Remove any added players from the schematic in the folder
|
||||
for (SchematicNode schematicNode : SchematicNode.getSchematicNodeInNode(teamFolder.getNodeId())) {
|
||||
if (schematicNode.getNodeId() == node.getNodeId()) continue;
|
||||
for (NodeMember nodeMember : NodeMember.getNodeMembers(schematicNode.getNodeId())) {
|
||||
NodeMember.createNodeMember(node.getNodeId(), nodeMember.getMember());
|
||||
nodeMember.delete();
|
||||
}
|
||||
for (NodeMember nodeMember : NodeMember.getNodeMembers(schematic.getId())) {
|
||||
NodeMember.createNodeMember(node.getNodeId(), nodeMember.getMember());
|
||||
}
|
||||
|
||||
// Conclude by setting send in schematic to normal and broadcast
|
||||
|
||||
@@ -42,13 +42,6 @@ public class ReplayCommand extends SWCommand {
|
||||
super("replay");
|
||||
}
|
||||
|
||||
@Register
|
||||
public void genericCommand(PlayerChatter sender) {
|
||||
sender.system("REPLAY_UNAVAILABLE");
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
@Register
|
||||
public void genericCommand(PlayerChatter sender, int replayId, @StaticValue(value = {"", "-a"}, allowISE = true) @OptionalValue("") boolean isAdmin, @OptionalValue("") String optionalMap) {
|
||||
Fight fight = Fight.getById(replayId);
|
||||
@@ -64,6 +57,9 @@ public class ReplayCommand extends SWCommand {
|
||||
@Register
|
||||
public void genericCommand(PlayerChatter sender, @OptionalValue("") String optionalMap) {
|
||||
if (PunishmentCommand.isPunishedWithMessage(sender, Punishment.PunishmentType.NoFightServer)) return;
|
||||
if (!sender.user().hasPerm(UserPerm.TEAM)) return;
|
||||
|
||||
|
||||
|
||||
new SWStreamInv<>(sender, new Message("REPLAY_TITLE"), (click, fight) -> {
|
||||
startReplay(sender, click.isShiftClick(), optionalMap, fight);
|
||||
@@ -72,6 +68,7 @@ public class ReplayCommand extends SWCommand {
|
||||
|
||||
private void startReplay(PlayerChatter sender, boolean isAdmin, String optionalMap, Fight fight) {
|
||||
if (PunishmentCommand.isPunishedWithMessage(sender, Punishment.PunishmentType.NoFightServer)) return;
|
||||
if (!sender.user().hasPerm(UserPerm.TEAM)) return;
|
||||
|
||||
GameModeConfig<String, String> mode = ArenaMode.getBySchemType(fight.getSchemType());
|
||||
ServerStarter starter = new ServerStarter().replay(fight.getFightID()).blueLeader(sender.getPlayer());
|
||||
@@ -116,5 +113,5 @@ public class ReplayCommand extends SWCommand {
|
||||
private Message parseLeader(SteamwarUser leader, int players, boolean winner) {
|
||||
return new Message("REPLAY_" + (players > 1 ? "" : "SOLO_") + (winner ? "WINNER" : "LOSER"), leader.getUserName(), players - 1);
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
@@ -27,8 +27,7 @@ plugins {
|
||||
class DevServer extends DefaultTask {
|
||||
|
||||
@Input
|
||||
@Optional
|
||||
String worldName = null
|
||||
boolean debug = false
|
||||
|
||||
@Input
|
||||
String template = null
|
||||
@@ -84,10 +83,13 @@ class DevServer extends DefaultTask {
|
||||
}
|
||||
}
|
||||
|
||||
if (worldName == null) worldName = properties.get("worldName")
|
||||
worldName = properties.get("worldName")
|
||||
host = properties.get("host")
|
||||
debugPort = new Random().nextInt(5001, 10000)
|
||||
|
||||
if (worldName == null) {
|
||||
throw new GradleException("Please supply the 'worldName' in a 'steamwar.properties' files either in this project dir or any parent project!")
|
||||
}
|
||||
if (host == null) {
|
||||
throw new GradleException("Please supply the 'host' in a 'steamwar.properties' files either in this project dir or any parent project!")
|
||||
}
|
||||
@@ -95,7 +97,7 @@ class DevServer extends DefaultTask {
|
||||
doLast {
|
||||
setupTemplate(template)
|
||||
uploadDependencies()
|
||||
startDebugPort()
|
||||
if (debug) startDebugPort()
|
||||
startDevServer()
|
||||
}
|
||||
finalizedBy(new Finalizer())
|
||||
@@ -113,6 +115,9 @@ class DevServer extends DefaultTask {
|
||||
@Internal
|
||||
Boolean running = true
|
||||
|
||||
@Internal
|
||||
String worldName = null
|
||||
|
||||
class Finalizer extends DefaultTask {
|
||||
|
||||
Finalizer() {
|
||||
@@ -241,7 +246,7 @@ class DevServer extends DefaultTask {
|
||||
devPy.append(" -D${dParam.key}=${dParam.value}")
|
||||
}
|
||||
devPy.append(" $template")
|
||||
devPy.append(" -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:$debugPort")
|
||||
if (debug) devPy.append(" -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:$debugPort")
|
||||
if (jvmArgs != null) devPy.append(" $jvmArgs")
|
||||
println("Starting $template with command ${devPy.toString()}")
|
||||
|
||||
@@ -278,6 +283,19 @@ class DevServer extends DefaultTask {
|
||||
}
|
||||
}
|
||||
|
||||
class VelocityServer extends DevServer {
|
||||
@Input
|
||||
@Optional
|
||||
Boolean packetDecodeLogging = false
|
||||
|
||||
VelocityServer() {
|
||||
super()
|
||||
doFirst {
|
||||
if (packetDecodeLogging) dParams.put("velocity.packet-decode-logging", "true")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class FightServer extends DevServer {
|
||||
|
||||
@Input
|
||||
|
||||
Reference in New Issue
Block a user