Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
75b822ece1
Commit
bb5312ee92
@ -1,70 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 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.tracer;
|
|
||||||
|
|
||||||
import com.comphenix.tinyprotocol.Reflection;
|
|
||||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
|
||||||
import de.steamwar.bausystem.features.tracer.show.TraceShowManager;
|
|
||||||
import de.steamwar.bausystem.utils.RayTraceUtils;
|
|
||||||
import de.steamwar.linkage.Linked;
|
|
||||||
import de.steamwar.linkage.api.Plain;
|
|
||||||
import net.md_5.bungee.api.chat.ClickEvent;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.util.RayTraceResult;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@Linked
|
|
||||||
public class TraceTNTClickListener implements Plain {
|
|
||||||
|
|
||||||
private static final Class<?> useEntity = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseEntity");
|
|
||||||
|
|
||||||
{
|
|
||||||
Set<Player> playerSet = new HashSet<>();
|
|
||||||
|
|
||||||
TinyProtocol.instance.addFilter(useEntity, (player, o) -> {
|
|
||||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
|
||||||
if (!playerSet.add(player)) return;
|
|
||||||
RayTraceResult rayTraceResult = RayTraceUtils.trace(player, player.getLocation(), TraceShowManager.getEntities(player));
|
|
||||||
if (rayTraceResult == null) return;
|
|
||||||
if (rayTraceResult.getHitEntity() == null) return;
|
|
||||||
TNTPosition tntPosition = TraceShowManager.getTNTPosition(player, rayTraceResult.getHitEntity());
|
|
||||||
if (tntPosition == null) return;
|
|
||||||
|
|
||||||
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_HEADER", player);
|
|
||||||
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_FUSE_TIME", player, tntPosition.getFuseTicks());
|
|
||||||
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_POSITION_X", player, tntPosition.getLocation().getX() + "");
|
|
||||||
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_POSITION_Y", player, tntPosition.getLocation().getY() + "");
|
|
||||||
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_POSITION_Z", player, tntPosition.getLocation().getZ() + "");
|
|
||||||
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_VELOCITY_X", player, tntPosition.getVelocity().getX() + "");
|
|
||||||
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_VELOCITY_Y", player, tntPosition.getVelocity().getY() + "");
|
|
||||||
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_VELOCITY_Z", player, tntPosition.getVelocity().getZ() + "");
|
|
||||||
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_ISOLATE", player, BauSystem.MESSAGE.parse("TRACE_MESSAGE_CLICK_ISOLATE", player), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/trace isolate " + tntPosition.getRecord().getId()));
|
|
||||||
}, 1);
|
|
||||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
|
||||||
playerSet.remove(player);
|
|
||||||
}, 2);
|
|
||||||
return o;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.tracer.show;
|
package de.steamwar.bausystem.features.tracer.show;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.features.tracer.TNTPosition;
|
import de.steamwar.bausystem.features.tracer.TNTPosition;
|
||||||
import de.steamwar.bausystem.shared.RoundedPosition;
|
import de.steamwar.bausystem.shared.RoundedPosition;
|
||||||
import de.steamwar.bausystem.shared.ShowMode;
|
import de.steamwar.bausystem.shared.ShowMode;
|
||||||
@ -26,6 +27,7 @@ import de.steamwar.bausystem.utils.FlatteningWrapper;
|
|||||||
import de.steamwar.entity.REntity;
|
import de.steamwar.entity.REntity;
|
||||||
import de.steamwar.entity.REntityServer;
|
import de.steamwar.entity.REntityServer;
|
||||||
import de.steamwar.entity.RFallingBlockEntity;
|
import de.steamwar.entity.RFallingBlockEntity;
|
||||||
|
import net.md_5.bungee.api.chat.ClickEvent;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -33,6 +35,7 @@ import org.bukkit.util.Vector;
|
|||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class EntityShowMode implements ShowMode<TNTPosition> {
|
public class EntityShowMode implements ShowMode<TNTPosition> {
|
||||||
|
|
||||||
@ -56,6 +59,25 @@ public class EntityShowMode implements ShowMode<TNTPosition> {
|
|||||||
public void show(TNTPosition position) {
|
public void show(TNTPosition position) {
|
||||||
if (entityServer == null) {
|
if (entityServer == null) {
|
||||||
entityServer = new REntityServer();
|
entityServer = new REntityServer();
|
||||||
|
entityServer.setCallback((player, rEntity, entityAction) -> {
|
||||||
|
if (entityAction != REntityServer.EntityAction.INTERACT) return;
|
||||||
|
TNTPosition tntPosition = Stream.concat(tntEntityMap.values().stream(), explodeEntityMap.values().stream())
|
||||||
|
.filter(entityStack -> entityStack.entity == rEntity)
|
||||||
|
.findFirst()
|
||||||
|
.map(entityStack -> entityStack.tntPosition)
|
||||||
|
.orElse(null);
|
||||||
|
if (tntPosition == null) return;
|
||||||
|
|
||||||
|
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_HEADER", player);
|
||||||
|
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_FUSE_TIME", player, tntPosition.getFuseTicks());
|
||||||
|
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_POSITION_X", player, tntPosition.getLocation().getX() + "");
|
||||||
|
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_POSITION_Y", player, tntPosition.getLocation().getY() + "");
|
||||||
|
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_POSITION_Z", player, tntPosition.getLocation().getZ() + "");
|
||||||
|
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_VELOCITY_X", player, tntPosition.getVelocity().getX() + "");
|
||||||
|
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_VELOCITY_Y", player, tntPosition.getVelocity().getY() + "");
|
||||||
|
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_VELOCITY_Z", player, tntPosition.getVelocity().getZ() + "");
|
||||||
|
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_ISOLATE", player, BauSystem.MESSAGE.parse("TRACE_MESSAGE_CLICK_ISOLATE", player), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/trace isolate " + tntPosition.getRecord().getId()));
|
||||||
|
});
|
||||||
entityServer.addPlayer(player);
|
entityServer.addPlayer(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,11 +146,11 @@ public class EntityShowMode implements ShowMode<TNTPosition> {
|
|||||||
RoundedPosition roundedPosition = new RoundedPosition(vector, factor);
|
RoundedPosition roundedPosition = new RoundedPosition(vector, factor);
|
||||||
EntityStack entityStack;
|
EntityStack entityStack;
|
||||||
if (positionType == PositionType.TNT) {
|
if (positionType == PositionType.TNT) {
|
||||||
entityStack = tntEntityMap.computeIfAbsent(roundedPosition, i -> new EntityStack(vector, positionType, position.getFuseTicks()));
|
entityStack = tntEntityMap.computeIfAbsent(roundedPosition, i -> new EntityStack(position, vector, positionType, position.getFuseTicks()));
|
||||||
} else if (positionType == PositionType.EXPLODE) {
|
} else if (positionType == PositionType.EXPLODE) {
|
||||||
entityStack = explodeEntityMap.computeIfAbsent(roundedPosition, i -> new EntityStack(vector, positionType, position.getFuseTicks()));
|
entityStack = explodeEntityMap.computeIfAbsent(roundedPosition, i -> new EntityStack(position, vector, positionType, position.getFuseTicks()));
|
||||||
} else {
|
} else {
|
||||||
entityStack = updateEntityMap.computeIfAbsent(roundedPosition, i -> new EntityStack(vector, positionType, position.getFuseTicks()));
|
entityStack = updateEntityMap.computeIfAbsent(roundedPosition, i -> new EntityStack(position, vector, positionType, position.getFuseTicks()));
|
||||||
}
|
}
|
||||||
entityStack.add(position.getRecord());
|
entityStack.add(position.getRecord());
|
||||||
});
|
});
|
||||||
@ -152,16 +174,9 @@ public class EntityShowMode implements ShowMode<TNTPosition> {
|
|||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Entity> getEntities() {
|
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public TNTPosition getTNTPosition(Entity entity) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private class EntityStack {
|
private class EntityStack {
|
||||||
|
|
||||||
|
private final TNTPosition tntPosition;
|
||||||
private final Vector position;
|
private final Vector position;
|
||||||
private final PositionType positionType;
|
private final PositionType positionType;
|
||||||
private final int fuseTicks;
|
private final int fuseTicks;
|
||||||
@ -170,7 +185,8 @@ public class EntityShowMode implements ShowMode<TNTPosition> {
|
|||||||
private int count;
|
private int count;
|
||||||
private List<Record.TNTRecord> records = new ArrayList<>();
|
private List<Record.TNTRecord> records = new ArrayList<>();
|
||||||
|
|
||||||
public EntityStack(Vector position, PositionType positionType, int fuseTicks) {
|
public EntityStack(TNTPosition tntPosition, Vector position, PositionType positionType, int fuseTicks) {
|
||||||
|
this.tntPosition = tntPosition;
|
||||||
this.position = position;
|
this.position = position;
|
||||||
this.positionType = positionType;
|
this.positionType = positionType;
|
||||||
this.fuseTicks = fuseTicks;
|
this.fuseTicks = fuseTicks;
|
||||||
|
@ -23,6 +23,7 @@ import de.steamwar.bausystem.BauSystem;
|
|||||||
import de.steamwar.bausystem.features.tracer.TNTPosition;
|
import de.steamwar.bausystem.features.tracer.TNTPosition;
|
||||||
import de.steamwar.bausystem.region.Region;
|
import de.steamwar.bausystem.region.Region;
|
||||||
import de.steamwar.bausystem.shared.ShowMode;
|
import de.steamwar.bausystem.shared.ShowMode;
|
||||||
|
import de.steamwar.entity.REntity;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -70,44 +71,6 @@ public class TraceShowManager implements Listener {
|
|||||||
showMode.hide();
|
showMode.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Entity> getEntities(Player player) {
|
|
||||||
Region region = Region.getRegion(player.getLocation());
|
|
||||||
if (region.isGlobal()) {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
Map<Player, ShowMode<TNTPosition>> regionalShowModes = showModes.get(region);
|
|
||||||
if (regionalShowModes == null) {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
ShowMode<TNTPosition> showMode = regionalShowModes.get(player);
|
|
||||||
if (showMode == null) {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
if (showMode instanceof EntityShowMode) {
|
|
||||||
return ((EntityShowMode) showMode).getEntities();
|
|
||||||
}
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static TNTPosition getTNTPosition(Player player, Entity entity) {
|
|
||||||
Region region = Region.getRegion(player.getLocation());
|
|
||||||
if (region.isGlobal()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
Map<Player, ShowMode<TNTPosition>> regionalShowModes = showModes.get(region);
|
|
||||||
if (regionalShowModes == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
ShowMode<TNTPosition> showMode = regionalShowModes.get(player);
|
|
||||||
if (showMode == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (showMode instanceof EntityShowMode) {
|
|
||||||
return ((EntityShowMode) showMode).getTNTPosition(entity);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void reshow(Region region, Player p) {
|
public static void reshow(Region region, Player p) {
|
||||||
Map<Player, ShowMode<TNTPosition>> regionalShowModes = showModes.get(region);
|
Map<Player, ShowMode<TNTPosition>> regionalShowModes = showModes.get(region);
|
||||||
if (regionalShowModes == null) {
|
if (regionalShowModes == null) {
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren