feat: 更新实体信息查询指令
This commit is contained in:
@@ -3,7 +3,7 @@ plugins {
|
||||
}
|
||||
|
||||
group 'cn.hamster3.mc.plugin'
|
||||
version '1.0.0'
|
||||
version '1.0.0-SNAPSHOT'
|
||||
|
||||
subprojects {
|
||||
apply plugin: 'java-library'
|
||||
|
@@ -11,21 +11,22 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@SuppressWarnings("SpellCheckingInspection")
|
||||
public class BlockInfoCommand extends ChildCommand {
|
||||
public static final BlockInfoCommand INSTANCE = new BlockInfoCommand();
|
||||
public class InfoModeCommand extends ChildCommand {
|
||||
public static final InfoModeCommand INSTANCE = new InfoModeCommand();
|
||||
|
||||
private BlockInfoCommand() {
|
||||
private InfoModeCommand() {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("SpellCheckingInspection")
|
||||
public @NotNull String getName() {
|
||||
return "blockinfo";
|
||||
return "infomode";
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("SpellCheckingInspection")
|
||||
public @NotNull String getUsage() {
|
||||
return "blockinfo [on/off]";
|
||||
return "infomode [on/off]";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -35,7 +36,7 @@ public class BlockInfoCommand extends ChildCommand {
|
||||
|
||||
@Override
|
||||
public @NotNull String getDescription() {
|
||||
return "开启方块信息查询模式";
|
||||
return "开启信息查询模式";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -50,25 +51,25 @@ public class BlockInfoCommand extends ChildCommand {
|
||||
switch (args[0]) {
|
||||
case "1":
|
||||
case "on": {
|
||||
DebugListener.BLOCK_INFO.add(uuid);
|
||||
CoreMessage.COMMAND_DEBUG_BLOCK_INFO_ON.show(player);
|
||||
DebugListener.INFO_MODE_PLAYERS.add(uuid);
|
||||
CoreMessage.COMMAND_DEBUG_INFO_MODE_ON.show(player);
|
||||
return true;
|
||||
}
|
||||
case "0":
|
||||
case "off": {
|
||||
DebugListener.BLOCK_INFO.remove(uuid);
|
||||
CoreMessage.COMMAND_DEBUG_BLOCK_INFO_OFF.show(player);
|
||||
DebugListener.INFO_MODE_PLAYERS.remove(uuid);
|
||||
CoreMessage.COMMAND_DEBUG_INFO_MODE_OFF.show(player);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (DebugListener.BLOCK_INFO.contains(uuid)) {
|
||||
DebugListener.BLOCK_INFO.remove(uuid);
|
||||
CoreMessage.COMMAND_DEBUG_BLOCK_INFO_OFF.show(player);
|
||||
if (DebugListener.INFO_MODE_PLAYERS.contains(uuid)) {
|
||||
DebugListener.INFO_MODE_PLAYERS.remove(uuid);
|
||||
CoreMessage.COMMAND_DEBUG_INFO_MODE_OFF.show(player);
|
||||
} else {
|
||||
DebugListener.BLOCK_INFO.add(uuid);
|
||||
CoreMessage.COMMAND_DEBUG_BLOCK_INFO_ON.show(player);
|
||||
DebugListener.INFO_MODE_PLAYERS.add(uuid);
|
||||
CoreMessage.COMMAND_DEBUG_INFO_MODE_ON.show(player);
|
||||
}
|
||||
return true;
|
||||
}
|
@@ -8,8 +8,8 @@ public class ParentCoreCommand extends ParentCommand {
|
||||
|
||||
private ParentCoreCommand() {
|
||||
super(HamsterCorePlugin.getInstance(), "core");
|
||||
addChildCommand(YamlCommand.INSTANCE);
|
||||
addChildCommand(GCCommand.INSTANCE);
|
||||
addChildCommand(BlockInfoCommand.INSTANCE);
|
||||
addChildCommand(YamlCommand.INSTANCE);
|
||||
addChildCommand(InfoModeCommand.INSTANCE);
|
||||
}
|
||||
}
|
||||
|
@@ -7,8 +7,8 @@ public enum CoreMessage {
|
||||
COMMAND_NOT_FOUND,
|
||||
COMMAND_MUST_USED_BY_PLAYER,
|
||||
|
||||
COMMAND_DEBUG_BLOCK_INFO_ON,
|
||||
COMMAND_DEBUG_BLOCK_INFO_OFF,
|
||||
COMMAND_DEBUG_INFO_MODE_ON,
|
||||
COMMAND_DEBUG_INFO_MODE_OFF,
|
||||
|
||||
COMMAND_LORE_HAND_EMPTY,
|
||||
COMMAND_LORE_EMPTY_INPUT,
|
||||
|
@@ -1,9 +1,14 @@
|
||||
package cn.hamster3.mc.plugin.core.bukkit.listener;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
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.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() {
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOW)
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
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) {
|
||||
Player player = event.getPlayer();
|
||||
UUID uuid = player.getUniqueId();
|
||||
if (!BLOCK_INFO.contains(uuid)) {
|
||||
if (!INFO_MODE_PLAYERS.contains(uuid)) {
|
||||
return;
|
||||
}
|
||||
switch (event.getAction()) {
|
||||
case LEFT_CLICK_BLOCK:
|
||||
case LEFT_CLICK_AIR: {
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
event.setCancelled(true);
|
||||
Block block = event.getClickedBlock();
|
||||
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.getBlockPower());
|
||||
player.sendMessage("§a方块湿度: " + block.getHumidity());
|
||||
player.sendMessage("§a自发光亮度: " + block.getLightLevel());
|
||||
player.sendMessage("§a获取天空亮度: " + block.getLightFromSky());
|
||||
player.sendMessage("§a方块吸收亮度: " + block.getLightFromBlocks());
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@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);
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user