forked from SteamWar/SteamWar
Add LegacyBauSystem with adaptions to current SpigotCore
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
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;
|
||||
|
||||
import de.steamwar.bausystem.tracer.TNTPosition;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Record {
|
||||
|
||||
private final long startTime;
|
||||
private final List<TNTRecord> tnt = new ArrayList<>();
|
||||
|
||||
public int size() {
|
||||
return tnt.size();
|
||||
}
|
||||
|
||||
public long getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public void showAll(ShowMode mode) {
|
||||
for (TNTRecord record : tnt)
|
||||
record.showAll(mode);
|
||||
}
|
||||
|
||||
/* The following methods should only be called by a recorder */
|
||||
public Record() {
|
||||
startTime = System.currentTimeMillis();
|
||||
StoredRecords.add(this);
|
||||
}
|
||||
|
||||
public TNTRecord spawn() {
|
||||
TNTRecord record = new TNTRecord();
|
||||
tnt.add(record);
|
||||
return record;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
tnt.clear();
|
||||
}
|
||||
|
||||
public static class TNTRecord {
|
||||
private final List<TNTPosition> positions = new ArrayList<>(41);
|
||||
|
||||
public void showAll(ShowMode mode) {
|
||||
for (TNTPosition position : positions)
|
||||
mode.show(position);
|
||||
}
|
||||
|
||||
/* The following methods should only be called by a recorder */
|
||||
public void add(TNTPrimed tntPrimed) {
|
||||
add(tntPrimed, false);
|
||||
}
|
||||
|
||||
private void add(TNTPrimed tntPrimed, boolean exploded) {
|
||||
TNTPosition position;
|
||||
if (positions.isEmpty()) {
|
||||
position = new TNTPosition(this, tntPrimed, null, exploded);
|
||||
} else {
|
||||
position = new TNTPosition(this, tntPrimed, positions.get(positions.size() - 1).getLocation(), exploded);
|
||||
}
|
||||
positions.add(position);
|
||||
TraceShowManager.show(position);
|
||||
}
|
||||
|
||||
public void explode(TNTPrimed tntPrimed) {
|
||||
add(tntPrimed, true);
|
||||
}
|
||||
|
||||
public List<TNTPosition> getPositions() {
|
||||
return positions;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
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;
|
||||
|
||||
import de.steamwar.bausystem.tracer.TNTPosition;
|
||||
|
||||
public interface ShowMode {
|
||||
void show(TNTPosition position);
|
||||
|
||||
void hide();
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
*
|
||||
* 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;
|
||||
|
||||
public class ShowModeParameter {
|
||||
|
||||
private boolean water = false;
|
||||
private boolean interpolate_Y = false;
|
||||
private boolean interpolate_XZ = 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public enum ShowModeParameterType {
|
||||
|
||||
WATER(showModeParameter -> showModeParameter.setWater(true)),
|
||||
INTERPOLATE_Y(showModeParameter -> showModeParameter.setInterpolate_Y(true)),
|
||||
INTERPOLATE_XZ(showModeParameter -> showModeParameter.setInterpolate_XZ(true)),
|
||||
ADVANCED(showModeParameter -> {
|
||||
showModeParameter.setInterpolate_Y(true);
|
||||
showModeParameter.setInterpolate_XZ(true);
|
||||
});
|
||||
|
||||
private final Consumer<ShowModeParameter> showModeParameterConsumer;
|
||||
|
||||
public Consumer<ShowModeParameter> getShowModeParameterConsumer() {
|
||||
return showModeParameterConsumer;
|
||||
}
|
||||
|
||||
ShowModeParameterType(Consumer<ShowModeParameter> showModeParameterConsumer) {
|
||||
this.showModeParameterConsumer = showModeParameterConsumer;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
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;
|
||||
|
||||
import de.steamwar.bausystem.tracer.record.RecordStateMachine;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class StoredRecords {
|
||||
|
||||
private static final List<Record> records = new ArrayList<>();
|
||||
|
||||
public static void add(Record record) {
|
||||
records.add(record);
|
||||
}
|
||||
|
||||
public static void showAll(ShowMode mode) {
|
||||
for (Record record : records) record.showAll(mode);
|
||||
}
|
||||
|
||||
public static void clear() {
|
||||
records.clear();
|
||||
TraceShowManager.clear();
|
||||
RecordStateMachine.postClear();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package de.steamwar.bausystem.tracer.show;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.tracer.TNTPosition;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class TraceShowManager implements Listener {
|
||||
private TraceShowManager() {
|
||||
}
|
||||
|
||||
private static final Map<Player, ShowMode> showModes = new HashMap<>();
|
||||
|
||||
public static void show(Player player, ShowMode showMode) {
|
||||
hide(player);
|
||||
showModes.put(player, showMode);
|
||||
StoredRecords.showAll(showMode);
|
||||
}
|
||||
|
||||
public static void hide(Player player) {
|
||||
ShowMode showMode = showModes.remove(player);
|
||||
if (showMode == null)
|
||||
return;
|
||||
showMode.hide();
|
||||
}
|
||||
|
||||
/* Only to be called by record */
|
||||
static void show(TNTPosition tnt) {
|
||||
for (ShowMode mode : showModes.values())
|
||||
mode.show(tnt);
|
||||
}
|
||||
|
||||
/* Only to be called by StoredRecords */
|
||||
static void clear() {
|
||||
for (ShowMode mode : showModes.values())
|
||||
mode.hide();
|
||||
}
|
||||
|
||||
/* Internal if player leaves*/
|
||||
static {
|
||||
Bukkit.getPluginManager().registerEvents(new TraceShowManager(), BauSystem.getPlugin());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onLeave(PlayerQuitEvent event) {
|
||||
showModes.remove(event.getPlayer());
|
||||
}
|
||||
|
||||
public static boolean hasActiveShow(Player player) {
|
||||
return showModes.containsKey(player);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
*
|
||||
* 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.CraftbukkitWrapper;
|
||||
import de.steamwar.bausystem.FlatteningWrapper;
|
||||
import de.steamwar.bausystem.tracer.AbstractTraceEntity;
|
||||
import de.steamwar.bausystem.tracer.RoundedTNTPosition;
|
||||
import de.steamwar.bausystem.tracer.TNTPosition;
|
||||
import de.steamwar.bausystem.tracer.show.ShowMode;
|
||||
import de.steamwar.bausystem.tracer.show.ShowModeParameter;
|
||||
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 EntityShowMode implements ShowMode {
|
||||
|
||||
protected final Player player;
|
||||
protected final ShowModeParameter showModeParameter;
|
||||
|
||||
private final Map<RoundedTNTPosition, AbstractTraceEntity> tntEntityMap = new HashMap<>();
|
||||
private final Map<RoundedTNTPosition, AbstractTraceEntity> updateEntityMap = new HashMap<>();
|
||||
|
||||
public EntityShowMode(Player player, ShowModeParameter showModeParameter) {
|
||||
this.player = player;
|
||||
this.showModeParameter = showModeParameter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show(TNTPosition position) {
|
||||
if (!showModeParameter.isWater() && position.isExploded() && checkWater(position.getLocation())) {
|
||||
// Basic
|
||||
for (TNTPosition pos : position.getRecord().getPositions()) {
|
||||
RoundedTNTPosition roundedTNTPosition = new RoundedTNTPosition(pos);
|
||||
tntEntityMap.computeIfPresent(roundedTNTPosition, (p, tnt) -> {
|
||||
return tnt.hide(player, false) ? null : tnt;
|
||||
});
|
||||
}
|
||||
// Advanced
|
||||
for (TNTPosition pos : position.getRecord().getPositions()) {
|
||||
applyOnPosition(pos, updatePointPosition -> {
|
||||
updateEntityMap.computeIfPresent(new RoundedTNTPosition(updatePointPosition), (p, point) -> {
|
||||
return point.hide(player, false) ? null : point;
|
||||
});
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
RoundedTNTPosition roundedTNTPosition = new RoundedTNTPosition(position);
|
||||
AbstractTraceEntity entity = tntEntityMap.computeIfAbsent(roundedTNTPosition, pos -> createEntity(player, position.getLocation(), true));
|
||||
entity.display(player, position.isExploded());
|
||||
|
||||
applyOnPosition(position, updatePointPosition -> {
|
||||
updateEntityMap.computeIfAbsent(new RoundedTNTPosition(updatePointPosition), pos -> {
|
||||
return createEntity(player, updatePointPosition, false);
|
||||
}).display(player, position.isExploded());
|
||||
});
|
||||
}
|
||||
|
||||
private boolean checkWater(Vector position) {
|
||||
return FlatteningWrapper.impl.inWater(player.getWorld(), position);
|
||||
}
|
||||
|
||||
public static AbstractTraceEntity createEntity(Player player, Vector position, boolean tnt) {
|
||||
return CraftbukkitWrapper.impl.create(player.getWorld(), position, tnt);
|
||||
}
|
||||
|
||||
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((roundedTNTPosition, abstractTraceEntity) -> abstractTraceEntity.hide(player, true));
|
||||
tntEntityMap.clear();
|
||||
updateEntityMap.forEach((roundedTNTPosition, abstractTraceEntity) -> abstractTraceEntity.hide(player, true));
|
||||
updateEntityMap.clear();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user