Skip to content

Commit

Permalink
add placeholder for entity name
Browse files Browse the repository at this point in the history
  • Loading branch information
steve4744 committed Oct 31, 2023
1 parent 06152f8 commit 240ef09
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ of this software and associated documentation files (the "Software"), to deal
import org.bukkit.OfflinePlayer;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.util.RayTraceResult;

import io.github.steve4744.whatisthis.utils.Utils;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
Expand Down Expand Up @@ -81,6 +82,10 @@ public String onRequest(OfflinePlayer p, String identifier) {
} else if (identifier.equals("blockname")) {
return plugin.getDataHandler().getDisplayName(Utils.getTargetBlock(player), player);

} else if (identifier.equals("entityname")) {
RayTraceResult result = Utils.getRayTraceResult(player);
return Utils.isEntity(result) ? plugin.getDataHandler().getEntityDisplayName(result.getHitEntity(), player) : "";

} else if (identifier.equals("resourcename")) {
return plugin.getDataHandler().getCustomResourceName(Utils.getTargetBlock(player));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
Copyright (c) 2022 steve4744
Copyright (c) 2023 steve4744
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -48,7 +48,7 @@ public WhatIsThisCommand(String version, WhatIsThis plugin) {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
String prefix = ChatColor.GREEN + "[WhatIsThis] " + ChatColor.WHITE;
String infoMessage = prefix + "Version " + version + " : plugin by "+ ChatColor.AQUA + "steve4744";

if (!sender.hasPermission("whatisthis.use")) {
sender.sendMessage(prefix + "You do not have permission to run this command");
return true;
Expand Down Expand Up @@ -78,16 +78,19 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
sender.sendMessage(infoMessage);
return false;
}

Player player = (Player) sender;
RayTraceResult result = Utils.getRayTraceResult(player);
if (result == null) {
return true;
}
if (result.getHitBlock() != null) {

if (Utils.isBlock(result)) {
plugin.getDataHandler().processBlock(result.getHitBlock(), player);
} else if (result.getHitEntity() != null) {
} else if (Utils.isEntity(result)) {
plugin.getDataHandler().processEntity(result.getHitEntity(), player);
}

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public String getDisplayName(Block block, Player player) {
return translatedName;
}

private String getEntityDisplayName(Entity entity, Player player) {
public String getEntityDisplayName(Entity entity, Player player) {
if (isBlacklistedEntity(entity)) {
return "";
}
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/io/github/steve4744/whatisthis/utils/Utils.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
Copyright (c) 2022 steve4744
Copyright (c) 2023 steve4744
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -78,6 +78,14 @@ public static RayTraceResult getRayTraceResult(Player player) {
entity -> !entity.getUniqueId().equals(player.getUniqueId()));
}

public static boolean isBlock(RayTraceResult result) {
return result != null && result.getHitBlock() != null;
}

public static boolean isEntity(RayTraceResult result) {
return result != null && result.getHitEntity() != null;
}

/**
* Get a string representation of the location of the targeted block.
*
Expand Down

0 comments on commit 240ef09

Please sign in to comment.