Update TNTClickListener
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
YoyoNow 2024-09-17 14:47:36 +02:00
Ursprung dbe6d40e36
Commit 9dde0659f5
3 geänderte Dateien mit 57 neuen und 12 gelöschten Zeilen

Datei anzeigen

@ -955,6 +955,7 @@ TNT_CLICK_VELOCITY_X=§7Velocity §eX§8: §e{0}
TNT_CLICK_VELOCITY_Y=§7Velocity §eY§8: §e{0}
TNT_CLICK_VELOCITY_Z=§7Velocity §eZ§8: §e{0}
TNT_CLICK_COUNT=§7Count §8: §e{0}
TNT_CLICK_SHOW_MORE=§7Show More
TNT_CLICK_ISOLATE=§eIsolate
SELECT_ITEM_CHOOSE_EXTENSION=Choose extension
SELECT_ITEM_CHOOSE_SELECTION=Choose selection

Datei anzeigen

@ -897,6 +897,7 @@ TNT_CLICK_VELOCITY_X=§7Velocity §eX§8: §e{0}
TNT_CLICK_VELOCITY_Y=§7Velocity §eY§8: §e{0}
TNT_CLICK_VELOCITY_Z=§7Velocity §eZ§8: §e{0}
TNT_CLICK_COUNT=§7Anzahl §8: §e{0}
TNT_CLICK_SHOW_MORE=§7Mehr zeigen
TNT_CLICK_ISOLATE=§eIsolieren
SELECT_ITEM_CHOOSE_EXTENSION=Extension auswählen
SELECT_ITEM_CHOOSE_SELECTION=Auswahl auswählen

Datei anzeigen

@ -21,17 +21,52 @@ package de.steamwar.bausystem.features.util;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.command.SWCommand;
import de.steamwar.linkage.Linked;
import net.md_5.bungee.api.chat.ClickEvent;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.inventory.EquipmentSlot;
import java.util.*;
import java.util.stream.Collectors;
@Linked
public class TNTClickListener implements Listener {
public class TNTClickListener extends SWCommand implements Listener {
public TNTClickListener() {
super("tnt-click");
}
@Register(noTabComplete = true)
public void runCommand(Player player, String uuid) {
Entity entity = Bukkit.getWorlds().get(0).getEntitiesByClass(TNTPrimed.class)
.stream()
.filter(tntPrimed -> tntPrimed.getUniqueId().toString().equals(uuid))
.findFirst()
.orElse(null);
if (entity == null) {
// TODO: Show unknown entity message
return;
}
Map<Integer, List<TNTPrimed>> groupingByFuse = new HashMap<>();
Bukkit.getWorlds().get(0).getEntitiesByClass(TNTPrimed.class)
.stream()
.filter(e -> e.getLocation().distanceSquared(entity.getLocation()) < 0.1)
.forEach(tntPrimed -> {
groupingByFuse.computeIfAbsent(tntPrimed.getFuseTicks(), ignored -> new ArrayList<>()).add(tntPrimed);
});
groupingByFuse.values().forEach(tntPrimeds -> {
tntPrimeds.sort(Comparator.comparingInt(this::getOrder));
});
if (groupingByFuse.isEmpty()) return;
// TODO: Implement GUI
}
@EventHandler
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
@ -40,18 +75,26 @@ public class TNTClickListener implements Listener {
Entity entity = event.getRightClicked();
if (event.getRightClicked() instanceof TNTPrimed) {
TNTPrimed tntPrimed = (TNTPrimed) entity;
long count = Bukkit.getWorlds().get(0).getEntitiesByClass(TNTPrimed.class).stream().filter(e -> e.getLocation().distanceSquared(tntPrimed.getLocation()) < 0.1).count();
Map<Integer, List<TNTPrimed>> groupingByFuse = new HashMap<>();
Bukkit.getWorlds().get(0).getEntitiesByClass(TNTPrimed.class)
.stream()
.filter(e -> e.getLocation().distanceSquared(entity.getLocation()) < 0.1)
.forEach(tntPrimed -> {
groupingByFuse.computeIfAbsent(tntPrimed.getFuseTicks(), ignored -> new ArrayList<>()).add(tntPrimed);
});
groupingByFuse.values().forEach(tntPrimeds -> {
tntPrimeds.sort(Comparator.comparingInt(this::getOrder));
});
if (groupingByFuse.isEmpty()) return;
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_HEADER", event.getPlayer());
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_ORDER", event.getPlayer(), getOrder(tntPrimed));
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_FUSE_TIME", event.getPlayer(), tntPrimed.getFuseTicks());
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_POSITION_X", event.getPlayer(), tntPrimed.getLocation().getX() + "");
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_POSITION_Y", event.getPlayer(), tntPrimed.getLocation().getY() + "");
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_POSITION_Z", event.getPlayer(), tntPrimed.getLocation().getZ() + "");
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_VELOCITY_X", event.getPlayer(), tntPrimed.getVelocity().getX() + "");
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_VELOCITY_Y", event.getPlayer(), tntPrimed.getVelocity().getY() + "");
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_VELOCITY_Z", event.getPlayer(), tntPrimed.getVelocity().getZ() + "");
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_COUNT", event.getPlayer(), count + "");
if (groupingByFuse.size() == 1) {
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_FUSE_TIME", event.getPlayer(), groupingByFuse.keySet().iterator().next());
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_COUNT", event.getPlayer(), groupingByFuse.values().iterator().next().size());
} else {
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_FUSE_TIME", event.getPlayer(), groupingByFuse.keySet().stream().sorted().map(String::valueOf).collect(Collectors.joining(", ")));
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_COUNT", event.getPlayer(), groupingByFuse.values().stream().mapToLong(List::size).sum());
}
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_SHOW_MORE", event.getPlayer(), "", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tnt-click " + entity.getUniqueId()), new Object[0]);
}
}