From d64fcf8b3b7243637559a96c8276ce7299cfabc3 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 26 Jun 2021 13:51:28 +0200 Subject: [PATCH] Add BlockShowMode Signed-off-by: yoyosource --- .../features/tracer/TraceCommand.java | 31 ++++++++- .../tracer/show/mode/BlockShowMode.java | 67 +++++++++++++++++++ 2 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/mode/BlockShowMode.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java index edc879fd..c906b29b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java @@ -27,12 +27,15 @@ import de.steamwar.bausystem.features.tracer.show.ShowModeParameter; import de.steamwar.bausystem.features.tracer.show.ShowModeParameterType; import de.steamwar.bausystem.features.tracer.show.StoredRecords; 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.TraceEntityShowMode; import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.bausystem.shared.ShowMode; import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommandUtils; import de.steamwar.command.TypeMapper; +import lombok.NonNull; import org.bukkit.entity.Player; import java.util.ArrayList; @@ -141,13 +144,37 @@ public class TraceCommand extends SWCommand { } @Register({"show"}) - public void showCommand(Player p, ShowModeParameterType... showModeParameterTypes) { + @Register({"show", "entity"}) + public void showEntityCommand(Player p, ShowModeParameterType... showModeParameterTypes) { + internalShow(p, ShowModeType.ENTITY, showModeParameterTypes); + } + + @Register({"show", "block"}) + public void showBlockCommand(Player p, ShowModeParameterType... showModeParameterTypes) { + internalShow(p, ShowModeType.BLOCK, showModeParameterTypes); + } + + private enum ShowModeType { + ENTITY, + BLOCK + } + + private void internalShow(Player p, @NonNull ShowModeType showModeType, ShowModeParameterType... showModeParameterTypes) { if (!permissionCheck(p)) return; ShowModeParameter showModeParameter = new ShowModeParameter(); for (ShowModeParameterType showModeParameterType : showModeParameterTypes) { showModeParameterType.getShowModeParameterConsumer().accept(showModeParameter); } - TraceShowManager.show(p, new TraceEntityShowMode(p, showModeParameter)); + switch (showModeType) { + case BLOCK: + TraceShowManager.show(p, new BlockShowMode(p, showModeParameter)); + break; + case ENTITY: + TraceShowManager.show(p, new TraceEntityShowMode(p, showModeParameter)); + break; + default: + return; + } BauSystem.MESSAGE.send("TRACE_MESSAGE_SHOW", p); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/mode/BlockShowMode.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/mode/BlockShowMode.java new file mode 100644 index 00000000..f53ee3a9 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/mode/BlockShowMode.java @@ -0,0 +1,67 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2021 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 . + */ + +package de.steamwar.bausystem.features.tracer.show.mode; + +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.region.Point; +import de.steamwar.bausystem.shared.ShowMode; +import de.steamwar.core.VersionedCallable; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; + +import java.util.HashSet; +import java.util.Set; + +public class BlockShowMode implements ShowMode { + + protected final Player player; + protected final ShowModeParameter showModeParameter; + + private Set positionSet = new HashSet<>(); + + public BlockShowMode(Player player, ShowModeParameter showModeParameter) { + this.player = player; + this.showModeParameter = showModeParameter; + } + + @Override + public void show(TNTPosition position) { + Location location = position.getLocation().toLocation(player.getWorld()); + Point point = Point.fromLocation(location); + if (positionSet.contains(point)) { + return; + } + positionSet.add(point); + player.sendBlockChange(location, Material.RED_STAINED_GLASS.createBlockData()); + } + + @Override + public void hide() { + positionSet.forEach(point -> { + Location location = point.toLocation(player.getWorld()); + player.sendBlockChange(location, location.getBlock().getBlockData()); + }); + positionSet.clear(); + } +}