SteamWar/BauSystem
Archiviert
13
0
Add AdvancedNoWater
Add RoundedTNTPosition
Dieser Commit ist enthalten in:
jojo 2020-12-25 12:57:50 +01:00
Ursprung efb1535211
Commit 3f040e6130
11 geänderte Dateien mit 266 neuen und 52 gelöschten Zeilen

Datei anzeigen

@ -37,6 +37,9 @@ class TraceEntity_12 extends EntityFallingBlock implements AbstractTraceEntity {
this.ticksLived = -12000;
this.dropItem = false;
this.setCustomNameVisible(true);
if (position.isExploded()) {
this.setCustomName("Exploded");
}
display(player);
}

Datei anzeigen

@ -38,6 +38,9 @@ class TraceEntity_15 extends EntityFallingBlock implements AbstractTraceEntity {
this.ticksLived = -12000;
this.dropItem = false;
this.setCustomNameVisible(true);
if (position.isExploded()) {
this.setCustomName(new ChatComponentText("Exploded"));
}
display(player);
}

Datei anzeigen

@ -0,0 +1,65 @@
/*
*
* 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.tracer;
import org.bukkit.util.Vector;
import java.util.Objects;
public class RoundedTNTPosition {
private static final int factor = 10;
private int x;
private int y;
private int z;
public RoundedTNTPosition(TNTPosition tntPosition) {
this(tntPosition.getLocation().getX(), tntPosition.getLocation().getY(), tntPosition.getLocation().getZ());
}
public RoundedTNTPosition(Vector vector) {
this(vector.getX(), vector.getY(), vector.getZ());
}
public RoundedTNTPosition(double x, double y, double z) {
this.x = (int)(x * factor);
this.y = (int)(y * factor);
this.z = (int)(z * factor);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof RoundedTNTPosition)) return false;
RoundedTNTPosition that = (RoundedTNTPosition) o;
return x == that.x &&
y == that.y &&
z == that.z;
}
@Override
public int hashCode() {
return Objects.hash(x, y, z);
}
}

Datei anzeigen

@ -25,15 +25,33 @@ import org.bukkit.util.Vector;
public class TNTPosition {
private Vector location;
private TNTPosition previous;
private boolean exploded;
public TNTPosition(Entity entity) {
public TNTPosition(Entity entity, TNTPosition previous, boolean exploded) {
location = entity.getLocation().toVector();
this.previous = previous;
this.exploded = exploded;
}
public TNTPosition(Vector vector) {
location = vector;
this.previous = null;
this.exploded = false;
}
public Vector getLocation() {
return location;
}
public TNTPosition getPrevious() {
return previous;
}
public boolean isExploded() {
return exploded;
}
@Override
public String toString() {
return "Position{" +

Datei anzeigen

@ -51,7 +51,7 @@ public class CommandTraceTabCompleter implements TabCompleter {
tabComplete.add("auto");
tabComplete.add("show");
if (args[0].equalsIgnoreCase("show") && args.length == 2) {
return manageList(new ArrayList<>(Arrays.asList("water", "nowater", "no_water", "removedwater", "removed_water", "basic", "default")), args, 1);
return manageList(new ArrayList<>(Arrays.asList("nowater", "basic", "default", "advanced")), args, 1);
}
tabComplete.add("hide");
tabComplete.add("delete");

Datei anzeigen

@ -66,7 +66,12 @@ public class Record {
/* The following methods should only be called by a recorder */
public void add(TNTPrimed tntPrimed) {
TNTPosition position = new TNTPosition(tntPrimed);
TNTPosition position;
if (positions.isEmpty()) {
position = new TNTPosition(tntPrimed, null, exploded);
} else {
position = new TNTPosition(tntPrimed, positions.get(positions.size() - 1), exploded);
}
positions.add(position);
TraceShowManager.show(position);
}

Datei anzeigen

@ -2,6 +2,8 @@ package de.steamwar.bausystem.tracer.show;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.tracer.TNTPosition;
import de.steamwar.bausystem.tracer.show.mode.Advanced;
import de.steamwar.bausystem.tracer.show.mode.AdvancedNoWater;
import de.steamwar.bausystem.tracer.show.mode.Basic;
import de.steamwar.bausystem.tracer.show.mode.BasicNoWater;
import org.bukkit.Bukkit;
@ -26,13 +28,18 @@ public class TraceShowManager implements Listener {
showMode = new Basic(player);
} else {
switch (args[1].toLowerCase()) {
case "water":
case "nowater":
case "no_water":
case "removedwater":
case "removed_water":
case "basic-nowater":
case "basicnowater":
showMode = new BasicNoWater(player);
break;
case "advanced":
showMode = new Advanced(player);
break;
case "advanced-nowater":
case "advancednowater":
showMode = new AdvancedNoWater(player);
break;
case "basic":
case "default":
default:

Datei anzeigen

@ -21,5 +21,101 @@
package de.steamwar.bausystem.tracer.show.mode;
public class Advanced {
import de.steamwar.bausystem.tracer.*;
import de.steamwar.bausystem.tracer.show.ShowMode;
import de.steamwar.core.Core;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import java.util.HashMap;
import java.util.Map;
public class Advanced implements ShowMode {
private final Player player;
private Map<RoundedTNTPosition, AbstractTraceEntity> tntEntityMap = new HashMap<>();
private Map<RoundedTNTPosition, AbstractTraceEntity> updateEntityMap = new HashMap<>();
public Advanced(Player player) {
this.player = player;
}
@Override
public void show(TNTPosition position) {
RoundedTNTPosition roundedTNTPosition = new RoundedTNTPosition(position);
if (tntEntityMap.containsKey(roundedTNTPosition)) {
return;
}
switch (Core.getVersion()) {
case 12:
tntEntityMap.put(roundedTNTPosition, TNTTracer_12.createTNT(player.getWorld(), position, player));
break;
default:
tntEntityMap.put(roundedTNTPosition, TNTTracer_15.createTNT(player.getWorld(), position, player));
break;
}
if (position.getPrevious() == null) return;
Vector vector = position.getLocation().clone().subtract(position.getPrevious().getLocation());
Vector updatePointY = position.getPrevious().getLocation().clone().setY(position.getLocation().getY());
Vector updatePointXZ;
if (Math.abs(vector.getX()) > Math.abs(vector.getZ())) {
updatePointXZ = updatePointY.clone().setX(position.getLocation().getX());
} else {
updatePointXZ = updatePointY.clone().setZ(position.getLocation().getZ());
}
System.out.println(updatePointY);
System.out.println(updatePointXZ);
if (!position.getLocation().equals(updatePointY)) {
RoundedTNTPosition updatePointPosition = new RoundedTNTPosition(updatePointY);
if (updateEntityMap.containsKey(updatePointPosition)) {
return;
}
switch (Core.getVersion()) {
case 12:
updateEntityMap.put(updatePointPosition, TNTTracer_12.createUpdatePoint(player.getWorld(), new TNTPosition(updatePointY), player));
break;
default:
updateEntityMap.put(updatePointPosition, TNTTracer_15.createUpdatePoint(player.getWorld(), new TNTPosition(updatePointY), player));
break;
}
}
if (!position.getLocation().equals(updatePointXZ)) {
RoundedTNTPosition updatePointPosition = new RoundedTNTPosition(updatePointXZ);
if (updateEntityMap.containsKey(updatePointPosition)) {
return;
}
switch (Core.getVersion()) {
case 12:
updateEntityMap.put(updatePointPosition, TNTTracer_12.createUpdatePoint(player.getWorld(), new TNTPosition(updatePointXZ), player));
break;
default:
updateEntityMap.put(updatePointPosition, TNTTracer_15.createUpdatePoint(player.getWorld(), new TNTPosition(updatePointXZ), player));
break;
}
}
}
@Override
public void hide() {
tntEntityMap.forEach((roundedTNTPosition, abstractTraceEntity) -> {
abstractTraceEntity.hide(player);
abstractTraceEntity.remove();
});
tntEntityMap.clear();
updateEntityMap.forEach((roundedTNTPosition, abstractTraceEntity) -> {
abstractTraceEntity.hide(player);
abstractTraceEntity.remove();
});
updateEntityMap.clear();
}
}

Datei anzeigen

@ -0,0 +1,56 @@
/*
*
* 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.tracer.show.mode;
import de.steamwar.bausystem.tracer.TNTPosition;
import de.steamwar.bausystem.tracer.TNTTracer_12;
import de.steamwar.bausystem.tracer.TNTTracer_15;
import de.steamwar.core.Core;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Player;
public class AdvancedNoWater extends Advanced {
private static final World world = Bukkit.getWorlds().get(0);
public AdvancedNoWater(Player player) {
super(player);
}
@Override
public void show(TNTPosition position) {
boolean b;
switch (Core.getVersion()) {
case 12:
b = TNTTracer_12.inWater(world, position);
break;
default:
b = TNTTracer_15.inWater(world, position);
break;
}
if (!b) {
super.show(position);
}
}
}

Datei anzeigen

@ -5,7 +5,8 @@ import de.steamwar.bausystem.tracer.show.ShowMode;
import de.steamwar.core.Core;
import org.bukkit.entity.Player;
import java.util.*;
import java.util.HashMap;
import java.util.Map;
public class Basic implements ShowMode {
@ -36,46 +37,11 @@ public class Basic implements ShowMode {
@Override
public void hide() {
tntEntityMap.forEach((roundedTNTPosition, abstractTNTEntity) -> {
abstractTNTEntity.hide(player);
abstractTNTEntity.remove();
tntEntityMap.forEach((roundedTNTPosition, abstractTraceEntity) -> {
abstractTraceEntity.hide(player);
abstractTraceEntity.remove();
});
tntEntityMap.clear();
}
private static class RoundedTNTPosition {
private static final int factor = 10;
private int x;
private int y;
private int z;
private RoundedTNTPosition(TNTPosition tntPosition) {
this(tntPosition.getLocation().getX(), tntPosition.getLocation().getY(), tntPosition.getLocation().getZ());
}
private RoundedTNTPosition(double x, double y, double z) {
this.x = (int)(x * factor);
this.y = (int)(y * factor);
this.z = (int)(z * factor);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof RoundedTNTPosition)) return false;
RoundedTNTPosition that = (RoundedTNTPosition) o;
return x == that.x &&
y == that.y &&
z == that.z;
}
@Override
public int hashCode() {
return Objects.hash(x, y, z);
}
}
}

Datei anzeigen

@ -53,9 +53,4 @@ public class BasicNoWater extends Basic {
}
}
@Override
public void hide() {
super.hide();
}
}