feat: 更新实体信息查询指令

This commit is contained in:
2022-10-29 00:33:39 +08:00
parent 5da7d10337
commit 719d68c8b9
5 changed files with 67 additions and 36 deletions

View File

@@ -3,7 +3,7 @@ plugins {
} }
group 'cn.hamster3.mc.plugin' group 'cn.hamster3.mc.plugin'
version '1.0.0' version '1.0.0-SNAPSHOT'
subprojects { subprojects {
apply plugin: 'java-library' apply plugin: 'java-library'

View File

@@ -11,21 +11,22 @@ import org.jetbrains.annotations.NotNull;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
public class InfoModeCommand extends ChildCommand {
public static final InfoModeCommand INSTANCE = new InfoModeCommand();
private InfoModeCommand() {
}
@Override
@SuppressWarnings("SpellCheckingInspection") @SuppressWarnings("SpellCheckingInspection")
public class BlockInfoCommand extends ChildCommand {
public static final BlockInfoCommand INSTANCE = new BlockInfoCommand();
private BlockInfoCommand() {
}
@Override
public @NotNull String getName() { public @NotNull String getName() {
return "blockinfo"; return "infomode";
} }
@Override @Override
@SuppressWarnings("SpellCheckingInspection")
public @NotNull String getUsage() { public @NotNull String getUsage() {
return "blockinfo [on/off]"; return "infomode [on/off]";
} }
@Override @Override
@@ -35,7 +36,7 @@ public class BlockInfoCommand extends ChildCommand {
@Override @Override
public @NotNull String getDescription() { public @NotNull String getDescription() {
return "开启方块信息查询模式"; return "开启信息查询模式";
} }
@Override @Override
@@ -50,25 +51,25 @@ public class BlockInfoCommand extends ChildCommand {
switch (args[0]) { switch (args[0]) {
case "1": case "1":
case "on": { case "on": {
DebugListener.BLOCK_INFO.add(uuid); DebugListener.INFO_MODE_PLAYERS.add(uuid);
CoreMessage.COMMAND_DEBUG_BLOCK_INFO_ON.show(player); CoreMessage.COMMAND_DEBUG_INFO_MODE_ON.show(player);
return true; return true;
} }
case "0": case "0":
case "off": { case "off": {
DebugListener.BLOCK_INFO.remove(uuid); DebugListener.INFO_MODE_PLAYERS.remove(uuid);
CoreMessage.COMMAND_DEBUG_BLOCK_INFO_OFF.show(player); CoreMessage.COMMAND_DEBUG_INFO_MODE_OFF.show(player);
return true; return true;
} }
} }
} }
if (DebugListener.BLOCK_INFO.contains(uuid)) { if (DebugListener.INFO_MODE_PLAYERS.contains(uuid)) {
DebugListener.BLOCK_INFO.remove(uuid); DebugListener.INFO_MODE_PLAYERS.remove(uuid);
CoreMessage.COMMAND_DEBUG_BLOCK_INFO_OFF.show(player); CoreMessage.COMMAND_DEBUG_INFO_MODE_OFF.show(player);
} else { } else {
DebugListener.BLOCK_INFO.add(uuid); DebugListener.INFO_MODE_PLAYERS.add(uuid);
CoreMessage.COMMAND_DEBUG_BLOCK_INFO_ON.show(player); CoreMessage.COMMAND_DEBUG_INFO_MODE_ON.show(player);
} }
return true; return true;
} }

View File

@@ -8,8 +8,8 @@ public class ParentCoreCommand extends ParentCommand {
private ParentCoreCommand() { private ParentCoreCommand() {
super(HamsterCorePlugin.getInstance(), "core"); super(HamsterCorePlugin.getInstance(), "core");
addChildCommand(YamlCommand.INSTANCE);
addChildCommand(GCCommand.INSTANCE); addChildCommand(GCCommand.INSTANCE);
addChildCommand(BlockInfoCommand.INSTANCE); addChildCommand(YamlCommand.INSTANCE);
addChildCommand(InfoModeCommand.INSTANCE);
} }
} }

View File

@@ -7,8 +7,8 @@ public enum CoreMessage {
COMMAND_NOT_FOUND, COMMAND_NOT_FOUND,
COMMAND_MUST_USED_BY_PLAYER, COMMAND_MUST_USED_BY_PLAYER,
COMMAND_DEBUG_BLOCK_INFO_ON, COMMAND_DEBUG_INFO_MODE_ON,
COMMAND_DEBUG_BLOCK_INFO_OFF, COMMAND_DEBUG_INFO_MODE_OFF,
COMMAND_LORE_HAND_EMPTY, COMMAND_LORE_HAND_EMPTY,
COMMAND_LORE_EMPTY_INPUT, COMMAND_LORE_EMPTY_INPUT,

View File

@@ -1,9 +1,14 @@
package cn.hamster3.mc.plugin.core.bukkit.listener; package cn.hamster3.mc.plugin.core.bukkit.listener;
import org.bukkit.Location;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
@@ -15,43 +20,68 @@ public class DebugListener implements Listener {
/** /**
* 要查看方块信息的玩家 * 要查看方块信息的玩家
*/ */
public static final HashSet<UUID> BLOCK_INFO = new HashSet<>(); public static final HashSet<UUID> INFO_MODE_PLAYERS = new HashSet<>();
private DebugListener() { private DebugListener() {
} }
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true, priority = EventPriority.LOW)
public void onPlayerQuit(PlayerQuitEvent event) { public void onPlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
UUID uuid = player.getUniqueId(); UUID uuid = player.getUniqueId();
BLOCK_INFO.remove(uuid); INFO_MODE_PLAYERS.remove(uuid);
} }
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true, priority = EventPriority.LOW)
public void onPlayerInteract(PlayerInteractEvent event) { public void onPlayerInteract(PlayerInteractEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
UUID uuid = player.getUniqueId(); UUID uuid = player.getUniqueId();
if (!BLOCK_INFO.contains(uuid)) { if (!INFO_MODE_PLAYERS.contains(uuid)) {
return; return;
} }
switch (event.getAction()) { if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
case LEFT_CLICK_BLOCK:
case LEFT_CLICK_AIR: {
break;
}
default: {
return; return;
} }
} event.setCancelled(true);
Block block = event.getClickedBlock(); Block block = event.getClickedBlock();
player.sendMessage("§e=============================="); player.sendMessage("§e==============================");
player.sendMessage(String.format("§a方块位置: %s %d %d %d", block.getWorld().getName(), block.getX(), block.getY(), block.getZ())); player.sendMessage(String.format("§a方块位置: %s %d %d %d",
block.getWorld().getName(),
block.getX(), block.getY(),
block.getZ()
));
player.sendMessage("§a方块材质: " + block.getType().name()); player.sendMessage("§a方块材质: " + block.getType().name());
player.sendMessage("§a方块能量: " + block.getBlockPower()); player.sendMessage("§a方块能量: " + block.getBlockPower());
player.sendMessage("§a方块湿度: " + block.getHumidity()); player.sendMessage("§a方块湿度: " + block.getHumidity());
player.sendMessage("§a自发光亮度: " + block.getLightLevel()); player.sendMessage("§a自发光亮度: " + block.getLightLevel());
player.sendMessage("§a获取天空亮度: " + block.getLightFromSky()); player.sendMessage("§a获取天空亮度: " + block.getLightFromSky());
player.sendMessage("§a方块吸收亮度: " + block.getLightFromBlocks()); player.sendMessage("§a方块吸收亮度: " + block.getLightFromBlocks());
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOW)
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
Player player = event.getPlayer();
UUID uuid = player.getUniqueId();
if (!INFO_MODE_PLAYERS.contains(uuid)) {
return;
}
event.setCancelled(true); event.setCancelled(true);
Entity entity = event.getRightClicked();
player.sendMessage("§e==============================");
Location location = entity.getLocation();
player.sendMessage(String.format("§a实体位置: %s %.2f %.2f %.2f %.2f %.2f",
entity.getWorld().getName(), location.getX(),
location.getY(),
location.getZ(),
location.getPitch(),
location.getYaw()
));
player.sendMessage("§a实体UUID: " + entity.getUniqueId());
player.sendMessage("§a实体类型: " + entity.getType().name());
player.sendMessage("§a实体名称: " + entity.getName());
player.sendMessage("§a自定义名称: " + entity.getCustomName());
player.sendMessage("§a名称可见: " + entity.isCustomNameVisible());
player.sendMessage("§a计分板标签: " + entity.getScoreboardTags());
} }
} }