Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.thebukkitarea.signcommands;
- import org.bukkit.block.Sign;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.block.Action;
- import org.bukkit.event.player.PlayerInteractEvent;
- import org.bukkit.plugin.java.JavaPlugin;
- import java.util.*;
- public class Main extends JavaPlugin implements Listener {
- private HashMap<Integer, String> signCommands = new HashMap<Integer, String>();
- @Override
- public void onEnable() {
- getServer().getPluginManager().registerEvents(this, this);
- for (Map.Entry<String, Object> entry : getConfig().getValues(false).entrySet()) {
- int id;
- try { id = Integer.parseInt(entry.getKey()); }
- catch (NumberFormatException ex) { continue; }
- signCommands.put(id, String.valueOf(entry.getValue()));
- }
- saveConfig();
- }
- @EventHandler
- public void onSignClick(PlayerInteractEvent event) {
- if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getState() instanceof Sign) {
- Sign sign = (Sign) event.getClickedBlock().getState();
- if (sign.getLine(0).equalsIgnoreCase("[command]")) {
- int id;
- try { id = Integer.parseInt(sign.getLine(1)); }
- catch (NumberFormatException ex) { return; }
- String cmd;
- if ((cmd = signCommands.get(id)) != null)
- event.getPlayer().performCommand(cmd);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement