SteamWar/BauSystem2.0
Archiviert
12
0

Fix ShieldPrinting
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2023-04-16 16:53:58 +02:00
Ursprung e9d7c8211f
Commit 48b2a87c96
5 geänderte Dateien mit 75 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -513,6 +513,8 @@ SCRIPT_GUI_CONSTANT_TPS_LIMIT_LORE = §etps_limit§7 of the server
SHIELD_PRINTING_NO_REGION = §cYou are not in a region.
SHIELD_PRINTING_NOT_RUNNING = §cThe shield printing is not running.
SHIELD_PRINTING_DISALLOWED = §cYou are not allowed to use shield printing here.
SHIELD_PRINTING_BOSSBAR = §fMovements: {0}
SHIELD_PRINTING_BOSSBAR_COPIED = §fMovements: {0} Copied: {1}
SHIELD_PRINTING_START = §aThe shield printing has been started.
SHIELD_PRINTING_COPY = §aThe shield has been copied.

Datei anzeigen

@ -506,6 +506,8 @@ SCRIPT_GUI_CONSTANT_TPS_LIMIT_LORE = §etps_limit§7 vom Server
SHIELD_PRINTING_NO_REGION = §cDu bist in keiner Region.
SHIELD_PRINTING_NOT_RUNNING = §cShield printing ist nicht aktiv.
SHIELD_PRINTING_DISALLOWED = §cDu darfst Shield printing nicht benutzen.
SHIELD_PRINTING_BOSSBAR = §fBewegungen: {0}
SHIELD_PRINTING_BOSSBAR_COPIED = §fBewegungen: {0} Kopiert: {1}
SHIELD_PRINTING_START = §aShield printing wurde gestartet.
SHIELD_PRINTING_COPY = §aSchilde wurden kopiert.

Datei anzeigen

@ -21,15 +21,24 @@ package de.steamwar.bausystem.features.shieldprinting;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.region.Region;
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.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.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.util.Vector;
import java.util.*;
@ -49,12 +58,14 @@ public class ShieldPrinting implements Listener {
public ShieldPrinting(Region region) {
this.region = region;
Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance());
updateBossbars();
}
public void copy() {
for (Map.Entry<Vector, Vector> entry : shieldMap.entrySet()) {
shieldData.put(entry.getValue(), entry.getKey().toLocation(WORLD).getBlock().getBlockData());
}
updateBossbars();
}
public void apply() {
@ -64,10 +75,13 @@ public class ShieldPrinting implements Listener {
}
public void disable() {
BlockPistonExtendEvent.getHandlerList().unregister(this);
BlockPistonRetractEvent.getHandlerList().unregister(this);
HandlerList.unregisterAll(this);
shieldMap.clear();
shieldData.clear();
for (Player player : Bukkit.getOnlinePlayers()) {
BossBarService.instance.remove(player, region, "shieldprinting");
}
}
@EventHandler
@ -97,5 +111,33 @@ public class ShieldPrinting implements Listener {
}
shieldMap.keySet().removeAll(toRemove);
shieldMap.putAll(temp);
updateBossbars();
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
if (event.getClickedBlock() == null) return;
if (event.getItem() == null) return;
if (Region.getRegion(event.getClickedBlock().getLocation()) != region) return;
Vector vector = event.getClickedBlock().getLocation().toVector();
if (!shieldMap.containsKey(vector)) return;
event.getClickedBlock().setType(Material.AIR);
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
updateBossbar(event.getPlayer());
}
private void updateBossbars() {
for (Player player : Bukkit.getOnlinePlayers()) {
updateBossbar(player);
}
}
private void updateBossbar(Player player) {
BauSystemBossbar bossbar = BossBarService.instance.get(player, region, "shieldprinting");
bossbar.setColor(BarColor.YELLOW);
bossbar.setTitle(BauSystem.MESSAGE.parse(shieldData.isEmpty() ? "SHIELD_PRINTING_BOSSBAR" : "SHIELD_PRINTING_BOSSBAR_COPIED", player, shieldMap.size(), shieldData.size()));
}
}

Datei anzeigen

@ -26,12 +26,15 @@ import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeValidator;
import de.steamwar.linkage.Linked;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;
import java.util.HashMap;
import java.util.Map;
@Linked
public class ShieldPrintingCommand extends SWCommand {
public class ShieldPrintingCommand extends SWCommand implements Listener {
public ShieldPrintingCommand() {
super("shieldprinting");
@ -43,7 +46,7 @@ public class ShieldPrintingCommand extends SWCommand {
public void genericCommand(@Validator Player player, ShieldPrintingState shieldPrintingState) {
Region region = Region.getRegion(player.getLocation());
if (region.isGlobal()) {
// BauSystem.MESSAGE.send("SHIELD_PRINTING_NO_REGION", player);
BauSystem.MESSAGE.send("SHIELD_PRINTING_NO_REGION", player);
return;
}
ShieldPrinting shieldPrinting;
@ -107,4 +110,20 @@ public class ShieldPrintingCommand extends SWCommand {
return true;
};
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
if (event.getClickedBlock() == null) {
return;
}
Region region = Region.getRegion(event.getClickedBlock().getLocation());
if (region.isGlobal()) {
return;
}
ShieldPrinting shieldPrinting = shieldMap.get(region);
if (shieldPrinting == null) {
return;
}
shieldPrinting.onPlayerInteract(event);
}
}

Datei anzeigen

@ -37,6 +37,12 @@ import java.util.Map;
@Linked
public class BossBarService implements Listener {
public static BossBarService instance;
public BossBarService() {
instance = this;
}
private final Map<Player, Map<Region, Map<String, BauSystemBossbar>>> playerBossBars = new HashMap<>();
public synchronized BauSystemBossbar get(Player player, Region region, String key) {