forked from SteamWar/SteamWar
Remove global Entity Interact callback
This commit is contained in:
@@ -19,7 +19,9 @@
|
||||
|
||||
package de.steamwar.entity;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.minecraft.network.syncher.EntityDataAccessor;
|
||||
import net.minecraft.network.syncher.EntityDataSerializers;
|
||||
import org.bukkit.Location;
|
||||
@@ -27,13 +29,17 @@ import org.bukkit.entity.EntityType;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class RArmorStand extends REntity {
|
||||
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
|
||||
@Getter(AccessLevel.PRIVATE)
|
||||
private REntityActionListener<RArmorStand> callback = null;
|
||||
|
||||
public RArmorStand(REntityServer server, Location location, Size size) {
|
||||
super(server, EntityType.ARMOR_STAND, location, 0);
|
||||
this.size = size;
|
||||
|
||||
@@ -21,7 +21,6 @@ package de.steamwar.entity;
|
||||
|
||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||
import de.steamwar.core.Core;
|
||||
import lombok.Setter;
|
||||
import net.minecraft.network.protocol.game.ServerboundInteractPacket;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@@ -52,8 +51,6 @@ public class REntityServer implements Listener {
|
||||
private final HashMap<Player, Location> lastLocation = new HashMap<>();
|
||||
private final HashMap<Player, Integer> viewDistance = new HashMap<>();
|
||||
|
||||
@Setter
|
||||
private REntityActionListener<REntity> callback = null;
|
||||
private final Set<Player> playersThatClicked = Collections.synchronizedSet(new HashSet<>());
|
||||
|
||||
private final BiFunction<Player, ServerboundInteractPacket, Object> filter = (player, packet) -> {
|
||||
@@ -66,11 +63,8 @@ public class REntityServer implements Listener {
|
||||
REntityAction action = packet.isAttack() ? REntityAction.ATTACK : REntityAction.INTERACT;
|
||||
Bukkit.getScheduler().runTask(Core.getInstance(), () -> {
|
||||
playersThatClicked.remove(player);
|
||||
if (entity instanceof RInteraction interaction && interaction.callback != null) {
|
||||
interaction.callback.onAction(player, interaction, action);
|
||||
}
|
||||
if (callback != null) {
|
||||
callback.onAction(player, entity, action);
|
||||
if (entity instanceof RInteractableEntity interactable && interactable.getCallback() != null) {
|
||||
interactable.getCallback().onAction(player, entity, action);
|
||||
}
|
||||
});
|
||||
return null;
|
||||
|
||||
@@ -20,16 +20,22 @@
|
||||
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
|
||||
@Getter(AccessLevel.PRIVATE)
|
||||
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));
|
||||
}
|
||||
}
|
||||
@@ -22,9 +22,9 @@ package de.steamwar.entity;
|
||||
import de.steamwar.core.BountifulWrapper;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -35,12 +35,13 @@ 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 {
|
||||
public class RInteraction extends REntity implements RInteractableEntity<RInteraction> {
|
||||
|
||||
protected final Consumer<Object> updatePacketSink = o -> server.updateEntity(this, o);
|
||||
|
||||
@Setter
|
||||
@Getter(AccessLevel.PRIVATE)
|
||||
protected REntityActionListener<RInteraction> callback = null;
|
||||
private REntityActionListener<RInteraction> callback = null;
|
||||
|
||||
private float interactionWidth = 1.0f;
|
||||
private float interactionHeight = 1.0f;
|
||||
@@ -114,12 +115,4 @@ public class RInteraction extends REntity {
|
||||
dataSink.accept(responsiveWatcher, responsive);
|
||||
}
|
||||
}
|
||||
|
||||
public void setCallback(REntityActionListener<RInteraction> callback) {
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
public void setCallback(BiConsumer<Player, REntityAction> callback) {
|
||||
this.callback = (player, interaction, entityAction) -> callback.accept(player, entityAction);
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,9 @@ import de.steamwar.core.ProtocolWrapper;
|
||||
import de.steamwar.network.CoreNetworkHandler;
|
||||
import de.steamwar.network.NetworkSender;
|
||||
import de.steamwar.network.packets.common.PlayerSkinRequestPacket;
|
||||
import lombok.AccessLevel;
|
||||
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 +41,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 +50,10 @@ public class RPlayer extends REntity {
|
||||
@Getter
|
||||
private final String name;
|
||||
|
||||
@Setter
|
||||
@Getter(AccessLevel.PRIVATE)
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user