|
|
|
@ -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]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|