Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 3 additions & 42 deletions src/main/java/com/indra87g/Main.java
Original file line number Diff line number Diff line change
@@ -1,52 +1,13 @@
package com.indra87g;

import cn.nukkit.block.Block;
import cn.nukkit.level.Level;
import cn.nukkit.math.Vector3;
import cn.nukkit.plugin.PluginBase;
import cn.nukkit.command.Command;
import cn.nukkit.command.CommandSender;
import cn.nukkit.Player;
import com.indra87g.commands.SetBlockCommand;

public class Main extends PluginBase {

@Override
public void onEnable() {
getLogger().info("plugin activated!");

this.getServer().getCommandMap().register("setblock", new Command("setblock") {
@Override
public boolean execute(CommandSender sender, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage("This command can only be used by player.");
return false;
}

Player player = (Player) sender;
Level level = player.getLevel();

if (args.length != 4) {
player.sendMessage("§cusage: /setblock <x> <y> <z> <block_id>");
return false;
}

try {
int x = Integer.parseInt(args[0]);
int y = Integer.parseInt(args[1]);
int z = Integer.parseInt(args[2]);
int blockId = Integer.parseInt(args[3]);

Vector3 pos = new Vector3(x, y, z);
Block block = Block.get(blockId);

level.setBlock(pos, block);
player.sendMessage("§aBlock " + block.getName() + " successfully placed in (" + x + ", " + y + ", " + z + ")");
} catch (NumberFormatException e) {
player.sendMessage("§cMake sure all arguments are valid numbers. ");
}

return true;
}
});
getLogger().info("ContohPlugin has been enabled.");
this.getServer().getCommandMap().register("setblock", new SetBlockCommand());
}
}
48 changes: 48 additions & 0 deletions src/main/java/com/indra87g/commands/SetBlockCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.indra87g.commands;

import cn.nukkit.Player;
import cn.nukkit.block.Block;
import cn.nukkit.command.Command;
import cn.nukkit.command.CommandSender;
import cn.nukkit.level.Level;
import cn.nukkit.math.Vector3;

public class SetBlockCommand extends Command {

public SetBlockCommand() {
super("setblock", "Sets a block at a specific location", "/setblock <x> <y> <z> <block_id>");
}

@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage("This command can only be used by a player.");
return false;
}

Player player = (Player) sender;
Level level = player.getLevel();

if (args.length != 4) {
player.sendMessage("§cUsage: " + this.getUsage());
return false;
}

try {
int x = Integer.parseInt(args[0]);
int y = Integer.parseInt(args[1]);
int z = Integer.parseInt(args[2]);
int blockId = Integer.parseInt(args[3]);

Vector3 pos = new Vector3(x, y, z);
Block block = Block.get(blockId);

level.setBlock(pos, block);
player.sendMessage("§aBlock " + block.getName() + " successfully placed at (" + x + ", " + y + ", " + z + ")");
} catch (NumberFormatException e) {
player.sendMessage("§cPlease provide valid numbers for coordinates and block ID.");
}

return true;
}
}
9 changes: 9 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,12 @@ version: 0.1.0
api: 1.0.0
author: indra87g
description: Plugin Nukkit dari GitHub Actions
commands:
setblock:
description: "Sets a block at a specific location"
usage: "/setblock <x> <y> <z> <block_id>"
permission: contohplugin.command.setblock
permissions:
contohplugin.command.setblock:
description: "Allows the user to use the /setblock command"
default: op