
์๋ ํ์ธ์ ๋ฟ์ ๋๋ค!!!
์ด๋ฒ์๋ ์ ๋ฒ ๊ธ์ ์ด์ด์ ์งํํฉ๋๋ค!!
์ ๋ฒ ๊ธ์์๋ ๋ฌธ์์ด์ ๋ฐ์์ ์ถ๋ ฅํ๋ค๋ฉด ์ด๋ฒ ๊ธ์์๋ ํ๋ ์ด์ด๋ฅผ ๋ฐ์์ ์ถ๋ ฅํด๋ณด๊ฒ ์ต๋๋ค!!!
๊ทธ๋ผ ์์ํฉ๋๋ค!!!!
๋ชฉํ
ํ๋ ์ด์ด๋ฅผ ๋ฐ์์ ํ๋ ์ด์ด ์ ๋ณด(๋ ๋ฒจ) ์ถ๋ ฅํ๊ธฐ
์ค๋ช
command๊ฐ ๋ฐ์ ์ ์๋ ์ธ์์๋ ๋ฌธ์์ด๋ง ์๋ ๊ฒ์ด ์๋๋๋ค. ๋ฌธ์์ด, ์ซ์, ์ขํ, ํ๋ ์ด์ด ๋ฑ ๋ค์ํ ์ธ์๋ฅผ ๋ฐ์ ์ ์์ต๋๋ค.
์ ๋ฒ ๊ธ์ ์ด์ด gamemode๋ฅผ ์๋ก ๋ค๋ฉด gamemode creative ppyom ์ด๋ผ๊ณ ์ ๋ ฅํ๋ฉด gamemode๋ผ๋ ๋ช ๋ น์ด๋ฅผ ์ฒ๋ฆฌํ๋ ๊ณณ์ creative, ppyom ์ด๋ผ๋ ๋ฌธ์์ด ๋ ๊ฐ๊ฐ ์ธ์๋ก ๋์ด๊ฐ๋๋ค. ๋ณ๊ฒฝ ๋์ ํ๋ ์ด์ด์ธ ppyom์ ํ๋ ์ด์ด ์ค๋ธ์ ํธ๋ก ๋ณ๊ฒฝํด์ ํด๋น ํ๋ ์ด์ด์ ๊ฒ์ ๋ชจ๋๋ฅผ creative๋ก ๋ณ๊ฒฝํฉ๋๋ค. ์ ๋ฆฌํ์๋ฉด gamemode creative ppyom์ ํด์ํ๋ฉด "ppyom์ ํ๋ ์ด์ด ์ค๋ธ์ ํธ๋ฅผ ๊ฐ์ ธ์์ ํด๋น ํ๋ ์ด์ด์ gamemode๋ฅผ creative๋ก ๋ณ๊ฒฝํด๋ผ!" ์ ๋๋ค.
ํ๋ ์ด์ด์ ์ด๋ฆ๋ง ์ ๋ ฅ๋ฐ์์ ์ค๋ธ์ ํธ๋ก ๊ฐ์ ธ์ฌ ๋์๋ Bukkit.getPlayer ๋ฉ์๋๋ฅผ ์ฌ์ฉํด ๊ฐ์ ธ์ฌ ์ ์์ต๋๋ค. ํด๋น ๋ฉ์๋๋ ์ฐ๋ฆฌ ์๋ฒ์ ํด๋น ํ๋ ์ด์ด ์ด๋ฆ์ ๊ฐ์ง ์ฌ์ฉ์๊ฐ ์๋์ง ํ์ธํ๊ณ ์๋ค๋ฉด ๊ทธ ํ๋ ์ด์ด์ Player ์ค๋ธ์ ํธ๋ฅผ ๋ฆฌํดํ๋ ์์ฃผ ์ ์ฉํ ๋ฉ์๋์ ๋๋ค.
๊ทธ๋ผ ์ด์ ... ๋ง๋ค์ด๋ณด๊ฒ ์ต๋๋ค!!
์ฝ๋
์ ๋ฒ ๊ธ์์ ๋ง๋ ํ๋ก์ ํธ์ ์ด์ด์ ์งํํฉ๋๋ค!
plugin.yml
name: CommandPlugin
version: '${version}'
main: com.ppyom.CommandPlugin
api-version: '1.20'
commands:
...
player:
description: ํ๋ ์ด์ด ์ ๋ณด
usage: /player [<player>]
PlayerCommand.java
์ปค๋งจ๋ ํด๋์ค์ ๋๋ค.
package com.ppyom.command;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class PlayerCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if(args.length > 1) {
sender.sendMessage("์ธ์๊ฐ ๋๋ฌด ๋ง์ต๋๋ค.");
return false;
}
if(args.length != 1 && !(sender instanceof Player)) {
sender.sendMessage("์ด ๋ช
๋ น์ด๋ ํ๋ ์ด์ด๋ง ์ฌ์ฉํ ์ ์์ต๋๋ค.");
return false;
}
Player target = args.length == 0 ? (Player) sender : Bukkit.getPlayer(args[0]);
if(target == null) {
sender.sendMessage("ํด๋น ํ๋ ์ด์ด๋ ์กด์ฌํ์ง ์์ต๋๋ค.");
return true;
}
Component message = Component.text(String.format("[%s ํ๋ ์ด์ด ์ ๋ณด]", target.getName()))
.append(Component.text(String.format("\n๋ ๋ฒจ: %d", target.getLevel())))
.append(Component.text(String.format("\n๊ฒฝํ์น: %.2f%%", target.getExp() * 100)))
;
sender.sendMessage(message);
return true;
}
}
CommandPlugin.java
๋ฉ์ธ ํด๋์ค์ ๋๋ค.
์์์ ์์ฑํ ์ปค๋งจ๋ ํด๋์ค๋ฅผ ๋ฑ๋กํด์ฃผ์์ต๋๋ค.
package com.ppyom;
import com.ppyom.command.NoticeCommand;
import com.ppyom.command.PlayerCommand;
import com.ppyom.command.TestCommand;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.java.JavaPlugin;
public final class CommandPlugin extends JavaPlugin {
@Override
public void onEnable() {
getLogger().info("CommandPlugin Enable");
registerCommand("test", new TestCommand());
registerCommand("notice", new NoticeCommand());
registerCommand("player", new PlayerCommand());
}
@Override
public void onDisable() {
getLogger().info("CommandPlugin Disable");
}
private void registerCommand(String name, CommandExecutor commandExecutor) {
PluginCommand pluginCommand = getServer().getPluginCommand(name);
if(pluginCommand != null) {
pluginCommand.setExecutor(commandExecutor);
} else {
getLogger().warning(String.format("Command %s is not found!", name));
}
}
}
๊ฒฐ๊ณผ


์ ์ฝ์ด๋ณด์ จ๋์?!
์ ๊ฐ ์ฌ์ค ์์ด๋์ด๊ฐ ๋ค ๋จ์ด์ ธ์...
์ด๋ค ๊ธ์ ์จ์ผํ ์ง ์ด์ ์ ๋ชจ๋ฅด๊ฒ ์ต๋๋ค....!!
ํน์ ์ด์ด์ ๋ณด๊ณ ์ถ๊ฑฐ๋ ๋ง๋ค์ด๋ณด๊ณ ์ถ์ ์์ด๋์ด๋ง ์์ผ์ ..! ๊ทธ๋ฐ๊ฑฐ ์์ผ๋ฉด ๋๊ธ ๋จ๊ฒจ์ฃผ์๋ฉด ์ด์ฌํ ๋ง๋ค์ด๋ณด๊ฒ ์ต๋๋ค..!!
๋ฟ์ด์์ต๋๋ค ๊ฐ์ฌํฉ๋๋ค!!