From 33584589a5000146c335522899b53fefd565c56a Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 19 Dec 2020 14:42:50 +0100 Subject: [PATCH] Start BasicShowMode --- .../bausystem/tracer/TNTEntity_12.java | 29 +++++++++++-- .../bausystem/tracer/TNTEntity_15.java | 30 ++++++++++++-- .../bausystem/tracer/AbstractTNTEntity.java | 13 ++++++ .../tracer/show/mode/BasicShowMode.java | 41 +++++++++++++++++++ 4 files changed, 105 insertions(+), 8 deletions(-) create mode 100644 BauSystem_API/src/de/steamwar/bausystem/tracer/AbstractTNTEntity.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicShowMode.java diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java index c196d6e..f6b1dd3 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTEntity_12.java @@ -1,19 +1,26 @@ package de.steamwar.bausystem.tracer; -import net.minecraft.server.v1_12_R1.*; +import net.minecraft.server.v1_12_R1.Blocks; +import net.minecraft.server.v1_12_R1.EntityFallingBlock; +import net.minecraft.server.v1_12_R1.EnumMoveType; +import org.bukkit.World; +import org.bukkit.craftbukkit.v1_12_R1.CraftWorld; +import org.bukkit.entity.Player; -public class TNTEntity_12 extends EntityFallingBlock { +public class TNTEntity_12 extends EntityFallingBlock implements AbstractTNTEntity { private TNTPosition position; - public TNTEntity_12(World world, TNTPosition position) { - super(world, position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ(), Blocks.TNT.getBlockData()); + public TNTEntity_12(World world, TNTPosition position, Player player) { + super(((CraftWorld) world).getHandle(), position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ(), Blocks.TNT.getBlockData()); this.position = position; this.setNoGravity(true); this.ticksLived = -12000; this.dropItem = false; this.setCustomNameVisible(true); + + display(player); } @Override @@ -21,4 +28,18 @@ public class TNTEntity_12 extends EntityFallingBlock { } + @Override + public AbstractTNTEntity display(Player player) { + return this; + } + + @Override + public AbstractTNTEntity hide(Player player) { + return this; + } + + @Override + public void remove() { + killEntity(); + } } diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java index cf9984a..d1474af 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTEntity_15.java @@ -1,19 +1,27 @@ package de.steamwar.bausystem.tracer; -import net.minecraft.server.v1_15_R1.*; +import net.minecraft.server.v1_15_R1.Blocks; +import net.minecraft.server.v1_15_R1.EntityFallingBlock; +import net.minecraft.server.v1_15_R1.EnumMoveType; +import net.minecraft.server.v1_15_R1.Vec3D; +import org.bukkit.World; +import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; +import org.bukkit.entity.Player; -public class TNTEntity_15 extends EntityFallingBlock { +public class TNTEntity_15 extends EntityFallingBlock implements AbstractTNTEntity { private TNTPosition position; - public TNTEntity_15(World world, TNTPosition position) { - super(world, position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ(), Blocks.TNT.getBlockData()); + public TNTEntity_15(World world, TNTPosition position, Player player) { + super(((CraftWorld) world).getHandle(), position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ(), Blocks.TNT.getBlockData()); this.position = position; this.setNoGravity(true); this.ticksLived = -12000; this.dropItem = false; this.setCustomNameVisible(true); + + display(player); } @Override @@ -21,4 +29,18 @@ public class TNTEntity_15 extends EntityFallingBlock { } + @Override + public AbstractTNTEntity display(Player player) { + return this; + } + + @Override + public AbstractTNTEntity hide(Player player) { + return this; + } + + @Override + public void remove() { + killEntity(); + } } diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/AbstractTNTEntity.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/AbstractTNTEntity.java new file mode 100644 index 0000000..89c7dd3 --- /dev/null +++ b/BauSystem_API/src/de/steamwar/bausystem/tracer/AbstractTNTEntity.java @@ -0,0 +1,13 @@ +package de.steamwar.bausystem.tracer; + +import org.bukkit.entity.Player; + +public interface AbstractTNTEntity { + + AbstractTNTEntity display(Player player); + + AbstractTNTEntity hide(Player player); + + void remove(); + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicShowMode.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicShowMode.java new file mode 100644 index 0000000..0d704f6 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/BasicShowMode.java @@ -0,0 +1,41 @@ +package de.steamwar.bausystem.tracer.show.mode; + +import de.steamwar.bausystem.tracer.AbstractTNTEntity; +import de.steamwar.bausystem.tracer.TNTEntity_12; +import de.steamwar.bausystem.tracer.TNTEntity_15; +import de.steamwar.bausystem.tracer.TNTPosition; +import de.steamwar.bausystem.tracer.show.ShowMode; +import de.steamwar.core.Core; +import org.bukkit.entity.Player; + +import java.util.HashSet; +import java.util.Set; + +public class BasicShowMode implements ShowMode { + + private final Player player; + + private Set tntEntitySet = new HashSet<>(); + + public BasicShowMode(Player player) { + this.player = player; + } + + @Override + public void show(TNTPosition position) { + switch (Core.getVersion()) { + case 12: + tntEntitySet.add(new TNTEntity_12(player.getWorld(), position, player)); + break; + default: + tntEntitySet.add(new TNTEntity_15(player.getWorld(), position, player)); + break; + } + } + + @Override + public void hide() { + tntEntitySet.forEach(abstractTNTEntity -> abstractTNTEntity.hide(player)); + } + +}