Add sand shield printing tracking
Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
f991992528
Commit
3786f1e2bb
@ -25,18 +25,27 @@ import de.steamwar.bausystem.utils.bossbar.BauSystemBossbar;
|
||||
import de.steamwar.bausystem.utils.bossbar.BossBarService;
|
||||
import de.steamwar.bausystem.utils.bossbar.RegionedBossbar;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.boss.BarColor;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockFormEvent;
|
||||
import org.bukkit.event.block.BlockPistonExtendEvent;
|
||||
import org.bukkit.event.block.BlockPistonRetractEvent;
|
||||
import org.bukkit.event.block.EntityBlockFormEvent;
|
||||
import org.bukkit.event.entity.EntityAirChangeEvent;
|
||||
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
@ -47,6 +56,17 @@ public class ShieldPrinting implements Listener {
|
||||
|
||||
private static final World WORLD = Bukkit.getWorlds().get(0);
|
||||
|
||||
static {
|
||||
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {
|
||||
ShieldPrintingCommand.SHIELD_PRINTING_MAP.values().forEach(shieldPrinting -> {
|
||||
shieldPrinting.fallingBlocks.replaceAll((entity, location) -> {
|
||||
if (entity.isDead()) return null;
|
||||
return location;
|
||||
});
|
||||
});
|
||||
}, 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Vector of current position, Vector of origin
|
||||
*/
|
||||
@ -123,6 +143,29 @@ public class ShieldPrinting implements Listener {
|
||||
updateBossbars();
|
||||
}
|
||||
|
||||
private Map<Entity, Location> fallingBlocks = new HashMap<>();
|
||||
|
||||
@EventHandler
|
||||
public void onEntitySpawn(EntitySpawnEvent event) {
|
||||
if (event.getEntityType() != EntityType.FALLING_BLOCK) return;
|
||||
if (Region.getRegion(event.getLocation()) != region) return;
|
||||
fallingBlocks.put(event.getEntity(), event.getLocation().getBlock().getLocation());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityChangeBlock(EntityChangeBlockEvent event) {
|
||||
if (!event.getBlock().getType().isAir()) return;
|
||||
if (event.getEntityType() != EntityType.FALLING_BLOCK) return;
|
||||
if (Region.getRegion(event.getBlock().getLocation()) != region) return;
|
||||
Location origin = fallingBlocks.remove(event.getEntity());
|
||||
if (origin == null) return;
|
||||
Location destination = event.getBlock().getLocation();
|
||||
Vector originOrigin = shieldMap.remove(origin.toVector());
|
||||
shieldMap.put(destination.toVector(), originOrigin != null ? originOrigin : origin.toVector());
|
||||
|
||||
updateBossbars();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (event.getClickedBlock() == null) return;
|
||||
|
@ -40,7 +40,7 @@ public class ShieldPrintingCommand extends SWCommand implements Listener {
|
||||
super("shieldprinting");
|
||||
}
|
||||
|
||||
private Map<Region, ShieldPrinting> shieldMap = new HashMap<>();
|
||||
static final Map<Region, ShieldPrinting> SHIELD_PRINTING_MAP = new HashMap<>();
|
||||
|
||||
@Register
|
||||
public void genericCommand(@Validator Player player, ShieldPrintingState shieldPrintingState) {
|
||||
@ -52,14 +52,14 @@ public class ShieldPrintingCommand extends SWCommand implements Listener {
|
||||
ShieldPrinting shieldPrinting;
|
||||
switch (shieldPrintingState) {
|
||||
case START:
|
||||
shieldPrinting = shieldMap.put(region, new ShieldPrinting(region));
|
||||
shieldPrinting = SHIELD_PRINTING_MAP.put(region, new ShieldPrinting(region));
|
||||
if (shieldPrinting != null) {
|
||||
shieldPrinting.disable();
|
||||
}
|
||||
BauSystem.MESSAGE.send("SHIELD_PRINTING_START", player);
|
||||
break;
|
||||
case COPY:
|
||||
shieldPrinting = shieldMap.get(region);
|
||||
shieldPrinting = SHIELD_PRINTING_MAP.get(region);
|
||||
if (shieldPrinting == null) {
|
||||
BauSystem.MESSAGE.send("SHIELD_PRINTING_NOT_RUNNING", player);
|
||||
return;
|
||||
@ -68,7 +68,7 @@ public class ShieldPrintingCommand extends SWCommand implements Listener {
|
||||
BauSystem.MESSAGE.send("SHIELD_PRINTING_COPY", player);
|
||||
break;
|
||||
case APPLY:
|
||||
shieldPrinting = shieldMap.get(region);
|
||||
shieldPrinting = SHIELD_PRINTING_MAP.get(region);
|
||||
if (shieldPrinting == null) {
|
||||
BauSystem.MESSAGE.send("SHIELD_PRINTING_NOT_RUNNING", player);
|
||||
return;
|
||||
@ -86,7 +86,7 @@ public class ShieldPrintingCommand extends SWCommand implements Listener {
|
||||
BauSystem.MESSAGE.send("SHIELD_PRINTING_NO_REGION", player);
|
||||
return;
|
||||
}
|
||||
ShieldPrinting shieldPrinting = shieldMap.remove(region);
|
||||
ShieldPrinting shieldPrinting = SHIELD_PRINTING_MAP.remove(region);
|
||||
if (shieldPrinting == null) {
|
||||
BauSystem.MESSAGE.send("SHIELD_PRINTING_NOT_RUNNING", player);
|
||||
return;
|
||||
@ -120,7 +120,7 @@ public class ShieldPrintingCommand extends SWCommand implements Listener {
|
||||
if (region.isGlobal()) {
|
||||
return;
|
||||
}
|
||||
ShieldPrinting shieldPrinting = shieldMap.get(region);
|
||||
ShieldPrinting shieldPrinting = SHIELD_PRINTING_MAP.get(region);
|
||||
if (shieldPrinting == null) {
|
||||
return;
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren