SteamWar/BauSystem2.0
Archiviert
12
0

Fix TraceCommand

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2021-07-04 21:18:26 +02:00
Ursprung 1b6bea2442
Commit 023f4216ec
7 geänderte Dateien mit 26 neuen und 134 gelöschten Zeilen

Datei anzeigen

@ -29,7 +29,6 @@ import de.steamwar.bausystem.features.tracer.show.StoredRecords;
import de.steamwar.bausystem.features.tracer.show.TraceShowManager; import de.steamwar.bausystem.features.tracer.show.TraceShowManager;
import de.steamwar.bausystem.features.tracer.show.mode.BlockShowMode; import de.steamwar.bausystem.features.tracer.show.mode.BlockShowMode;
import de.steamwar.bausystem.features.tracer.show.mode.ParticleShowMode; import de.steamwar.bausystem.features.tracer.show.mode.ParticleShowMode;
import de.steamwar.bausystem.features.tracer.show.mode.TraceEntityExplodeShowMode;
import de.steamwar.bausystem.features.tracer.show.mode.TraceEntityShowMode; import de.steamwar.bausystem.features.tracer.show.mode.TraceEntityShowMode;
import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked; import de.steamwar.bausystem.linkage.Linked;
@ -81,6 +80,9 @@ public class TraceCommand extends SWCommand {
showModeParameterTypesMap.put("advanced", ShowModeParameterType.ADVANCED); showModeParameterTypesMap.put("advanced", ShowModeParameterType.ADVANCED);
showModeParameterTypesMap.put("a", ShowModeParameterType.ADVANCED); showModeParameterTypesMap.put("a", ShowModeParameterType.ADVANCED);
showModeParameterTypesMap.put("-explode", ShowModeParameterType.EXPLODE);
showModeParameterTypesMap.put("-explodeonly", ShowModeParameterType.EXPLODE);
List<String> tabCompletes = new ArrayList<>(showModeParameterTypesMap.keySet()); List<String> tabCompletes = new ArrayList<>(showModeParameterTypesMap.keySet());
return SWCommandUtils.createMapper(s -> showModeParameterTypesMap.getOrDefault(s, null), s -> tabCompletes); return SWCommandUtils.createMapper(s -> showModeParameterTypesMap.getOrDefault(s, null), s -> tabCompletes);
} }
@ -162,7 +164,6 @@ public class TraceCommand extends SWCommand {
private enum ShowModeType { private enum ShowModeType {
ENTITY, ENTITY,
EXPLODE, /* Entity Explode */
PARTICLE, PARTICLE,
BLOCK BLOCK
} }
@ -183,9 +184,6 @@ public class TraceCommand extends SWCommand {
case ENTITY: case ENTITY:
TraceShowManager.show(p, new TraceEntityShowMode(p, showModeParameter)); TraceShowManager.show(p, new TraceEntityShowMode(p, showModeParameter));
break; break;
case EXPLODE:
TraceShowManager.show(p, new TraceEntityExplodeShowMode(p, showModeParameter));
break;
default: default:
BauSystem.MESSAGE.send("TRACE_MESSAGE_SHOW_UNKNOWN", p); BauSystem.MESSAGE.send("TRACE_MESSAGE_SHOW_UNKNOWN", p);
return; return;

Datei anzeigen

@ -21,37 +21,14 @@
package de.steamwar.bausystem.features.tracer.show; package de.steamwar.bausystem.features.tracer.show;
public class ShowModeParameter { import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class ShowModeParameter {
private boolean water = false; private boolean water = false;
private boolean interpolate_Y = false; private boolean interpolate_Y = false;
private boolean interpolate_XZ = false; private boolean interpolate_XZ = false;
private boolean explodeOnly = false;
public ShowModeParameter() {
}
public boolean isWater() {
return water;
}
public boolean isInterpolate_Y() {
return interpolate_Y;
}
public boolean isInterpolate_XZ() {
return interpolate_XZ;
}
public void setWater(boolean water) {
this.water = water;
}
public void setInterpolate_Y(boolean interpolate_Y) {
this.interpolate_Y = interpolate_Y;
}
public void setInterpolate_XZ(boolean interpolate_XZ) {
this.interpolate_XZ = interpolate_XZ;
}
} }

Datei anzeigen

@ -29,7 +29,8 @@ public enum ShowModeParameterType {
ADVANCED(showModeParameter -> { ADVANCED(showModeParameter -> {
showModeParameter.setInterpolate_Y(true); showModeParameter.setInterpolate_Y(true);
showModeParameter.setInterpolate_XZ(true); showModeParameter.setInterpolate_XZ(true);
}); }),
EXPLODE(showModeParameter -> showModeParameter.setExplodeOnly(true));
private final Consumer<ShowModeParameter> showModeParameterConsumer; private final Consumer<ShowModeParameter> showModeParameterConsumer;

Datei anzeigen

@ -44,6 +44,9 @@ public class BlockShowMode implements ShowMode<TNTPosition> {
@Override @Override
public void show(TNTPosition position) { public void show(TNTPosition position) {
if (showModeParameter.isExplodeOnly() && !position.isExploded()) {
return;
}
Location location = position.getLocation().toLocation(player.getWorld()); Location location = position.getLocation().toLocation(player.getWorld());
Point point = Point.fromLocation(location); Point point = Point.fromLocation(location);
if (positionSet.contains(point)) { if (positionSet.contains(point)) {

Datei anzeigen

@ -48,6 +48,9 @@ public class ParticleShowMode implements ShowMode<TNTPosition> {
@Override @Override
public void show(TNTPosition position) { public void show(TNTPosition position) {
if (showModeParameter.isExplodeOnly() && !position.isExploded()) {
return;
}
if (positionSet.contains(position.getLocation())) { if (positionSet.contains(position.getLocation())) {
return; return;
} }

Datei anzeigen

@ -1,99 +0,0 @@
/*
*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2020 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.show.mode;
import de.steamwar.bausystem.features.tracer.AbstractTraceEntity;
import de.steamwar.bausystem.features.tracer.TNTPosition;
import de.steamwar.bausystem.features.tracer.TNTTracer_15;
import de.steamwar.bausystem.features.tracer.show.ShowModeParameter;
import de.steamwar.bausystem.shared.RoundedPosition;
import de.steamwar.bausystem.shared.ShowMode;
import de.steamwar.core.VersionedCallable;
import org.bukkit.entity.Player;
import org.bukkit.util.Consumer;
import org.bukkit.util.Vector;
import java.util.HashMap;
import java.util.Map;
public class TraceEntityExplodeShowMode implements ShowMode<TNTPosition> {
protected final Player player;
protected final ShowModeParameter showModeParameter;
private final Map<RoundedPosition, AbstractTraceEntity> tntEntityMap = new HashMap<>();
private final Map<RoundedPosition, AbstractTraceEntity> updateEntityMap = new HashMap<>();
public TraceEntityExplodeShowMode(Player player, ShowModeParameter showModeParameter) {
this.player = player;
this.showModeParameter = showModeParameter;
}
@Override
public void show(TNTPosition position) {
if (!position.isExploded()) {
return;
}
RoundedPosition roundedPosition = new RoundedPosition(position);
AbstractTraceEntity entity = tntEntityMap.computeIfAbsent(roundedPosition, pos -> createEntity(player, position.getLocation(), true));
entity.display(player, position.isExploded());
}
private boolean checkWater(Vector position) {
return VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_15.inWater(player.getWorld(), position), 15));
}
public static AbstractTraceEntity createEntity(Player player, Vector position, boolean tnt) {
return VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_15.create(player.getWorld(), position, tnt), 15));
}
private void applyOnPosition(TNTPosition position, Consumer<Vector> function) {
if (position.getPreviousLocation() == null) return;
if (showModeParameter.isInterpolate_Y()) {
Vector updatePointY = position.getPreviousLocation().clone().setY(position.getLocation().getY());
if (!position.getLocation().equals(updatePointY)) {
function.accept(updatePointY);
}
}
if (showModeParameter.isInterpolate_XZ()) {
Vector movement = position.getLocation().clone().subtract(position.getPreviousLocation());
Vector updatePointXZ = Math.abs(movement.getX()) > Math.abs(movement.getZ())
? position.getLocation().clone().setZ(position.getPreviousLocation().getZ())
: position.getLocation().clone().setX(position.getPreviousLocation().getX());
if (!position.getLocation().equals(updatePointXZ)) {
function.accept(updatePointXZ);
}
}
}
@Override
public void hide() {
tntEntityMap.forEach((roundedPosition, abstractTraceEntity) -> abstractTraceEntity.hide(player, true));
tntEntityMap.clear();
updateEntityMap.forEach((roundedPosition, abstractTraceEntity) -> abstractTraceEntity.hide(player, true));
updateEntityMap.clear();
}
}

Datei anzeigen

@ -50,6 +50,15 @@ public class TraceEntityShowMode implements ShowMode<TNTPosition> {
@Override @Override
public void show(TNTPosition position) { public void show(TNTPosition position) {
if (showModeParameter.isExplodeOnly()) {
if (!position.isExploded()) {
return;
}
RoundedPosition roundedPosition = new RoundedPosition(position);
AbstractTraceEntity entity = tntEntityMap.computeIfAbsent(roundedPosition, pos -> createEntity(player, position.getLocation(), true));
entity.display(player, position.isExploded());
return;
}
if (!showModeParameter.isWater() && position.isExploded() && checkWater(position.getLocation())) { if (!showModeParameter.isWater() && position.isExploded() && checkWater(position.getLocation())) {
// Basic // Basic
for (TNTPosition pos : position.getRecord().getPositions()) { for (TNTPosition pos : position.getRecord().getPositions()) {