SteamWar/BauSystem2.0
Archiviert
12
0

Add TraceEntityExplodeShowMode

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2021-07-04 21:04:00 +02:00
Ursprung 4f63adf749
Commit 72dbdd0989
2 geänderte Dateien mit 104 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -29,6 +29,7 @@ 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;
@ -161,6 +162,7 @@ public class TraceCommand extends SWCommand {
private enum ShowModeType { private enum ShowModeType {
ENTITY, ENTITY,
EXPLODE, /* Entity Explode */
PARTICLE, PARTICLE,
BLOCK BLOCK
} }
@ -181,6 +183,9 @@ 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:
return; return;
} }

Datei anzeigen

@ -0,0 +1,99 @@
/*
*
* 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();
}
}