Compare commits

..

2 Commits

Author SHA1 Message Date
WildInterloper ea2859d915 Updated README.MD 2024-03-10 21:19:41 -04:00
WildInterloper 4214b562bf v1.0-SNAPSHOT 2024-03-10 21:08:48 -04:00
9 changed files with 81 additions and 3 deletions

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@ -0,0 +1,41 @@
# CustomBlockCMD
Something similar was requested [here](https://www.spigotmc.org/threads/clickable-items-command.492629/).
```#======================================================================================#
# NVus PRISON SETUP #
# by never2nv #
# www.FNGnation.net #
# Discord: FNGnation.net/discord #
#======================================================================================#
GOLD_BLOCK:
# Action type: hand or world. Hand means if the player has this block in their hand
# and right clicks it'll execute the command and optional message.
# world means if they right-click on this block anywhere in the world they see it
# it'll execute the command and optional message.
action-type: world
# Command type: player or server. Player means it'll execute the command as the player
cmd-type: player
# Command to execute
command: warp shop
# Optional message to send to the player. Leave "" for no message.
message: "Teleporting to the shop..."
DIAMOND_BLOCK:
action-type: hand
cmd-type: server
command: give @p diamond
IRON_BLOCK:
action-type: hand
cmd-type: player
command: spawn
message: "Teleporting to spawn..."
EMERALD_BLOCK:
action-type: world
cmd-type: server
command: give @p emerald
```

View File

@ -9,7 +9,6 @@ import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.plugin.java.JavaPlugin;
public class CustomBlockCMD extends JavaPlugin implements Listener {
@Override
@ -27,12 +26,18 @@ public class CustomBlockCMD extends JavaPlugin implements Listener {
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
Material heldMaterial = player.getInventory().getItemInMainHand().getType();
if (event.getAction().toString().contains("RIGHT")) {
Material clickedMaterial = event.getClickedBlock().getType();
FileConfiguration config = getConfig();
ConfigurationSection blockSection = config.getConfigurationSection(clickedMaterial.toString());
if (blockSection != null) {
String actionType = blockSection.getString("action-type", "hand");
if (actionType.equalsIgnoreCase("hand") && !heldMaterial.equals(clickedMaterial)) {
return; // Skip if action-type is hand and the held item doesn't match the clicked block
}
String cmdType = blockSection.getString("cmd-type");
String command = blockSection.getString("command");
String message = blockSection.getString("message", "");

View File

@ -6,19 +6,32 @@
#======================================================================================#
GOLD_BLOCK:
# Action type: hand or world. Hand means if the player has this block in their hand
# and right clicks it'll execute the command and optional message.
# world means if they right-click on this block anywhere in the world they see it
# it'll execute the command and optional message.
action-type: world
# Command type: player or server. Player means it'll execute the command as the player
cmd-type: player
# Command to execute
command: warp shop
# Optional message to send to the player. Leave "" for no message.
message: "Teleporting to the shop..."
DIAMOND_BLOCK:
action-type: hand
cmd-type: server
command: give @p diamond
IRON_BLOCK:
action-type: hand
cmd-type: player
command: spawn
message: "Teleporting to spawn..."
EMERALD_BLOCK:
action-type: world
cmd-type: server
command: give @p emerald
...

Binary file not shown.

View File

@ -6,19 +6,32 @@
#======================================================================================#
GOLD_BLOCK:
# Action type: hand or world. Hand means if the player has this block in their hand
# and right clicks it'll execute the command and optional message.
# world means if they right-click on this block anywhere in the world they see it
# it'll execute the command and optional message.
action-type: world
# Command type: player or server. Player means it'll execute the command as the player
cmd-type: player
# Command to execute
command: warp shop
# Optional message to send to the player. Leave "" for no message.
message: "Teleporting to the shop..."
DIAMOND_BLOCK:
action-type: hand
cmd-type: server
command: give @p diamond
IRON_BLOCK:
action-type: hand
cmd-type: player
command: spawn
message: "Teleporting to spawn..."
EMERALD_BLOCK:
action-type: world
cmd-type: server
command: give @p emerald
...