Code: public boolean onCommand(CommandSender sender, Command command, String label, String[] args0){ if(command.getName().equalsIgnoreCase("help")){ sender.sendMessage("test"); } else if(command.getName().equalsIgnoreCase("plugins")){ sender.sendMessage("test"); } return true; } Tips or fixes anyone? Offtopic: Bukkit, stop screwing up the edit post box.
Code: name: HelpMePatchy version: HaxSignEdition main: book.page commands: help: description: Request basic help. usage: /help plugins: description: Gets plugin listings. usage: /plugins Everything works, except /plugins EDIT by Moderator: merged posts, please use the edit button instead of double posting.
The problem was /plugins is already a command so you cant replace it that easy i believe. I changed the command to /pluginsl and it prints out test2 just fine. Also i edited the package name and all that so dont forget to change it back. If you have anymore questions just let me know Heres your Main Class: package me.h4.Basic; import java.util.logging.Logger; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.plugin.java.JavaPlugin; public class Basic extends JavaPlugin { public void onEnable() { Logger.getLogger("Minecraft").info(this + " is now Enabled!"); } public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){ if(cmd.getName().equalsIgnoreCase("help")){ sender.sendMessage("Test1"); return true; } else if (cmd.getName().equalsIgnoreCase("pluginsl")){ sender.sendMessage("Test2"); return false; } return false; } public void onDisable() { Logger.getLogger("Minecraft").info(this + " is now Disabled!"); } } And heres your plugin.yml: name: HelpMePatchy version: HaxSignEdition main: me.h4.Basic.Basic commands: help: description: Request basic help. usage: /help pluginsl: description: Gets plugin listings. usage: /pluginsl
Nonono, I was trying to replace the /plugins command, not create another >_> You could replace /help, so why not /plugins?
I'm not sure this will work, but try adding a chat listener and whenever the message is /plugins or /pl, cancel it use a player.sendMessage(String) or something like that with what you want to have. Heh, just kidding... Doesn't work.
ooooooooo ok lemme look around lol. Now the title makes sense to me. I think this would be your best bet too. I read that putting commands in the plugin.yml should replace them but since its clearly not, that option that he suggested would be best. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Code: package book; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerChatEvent; import org.bukkit.event.player.PlayerListener; public class ear extends PlayerListener { public page plugin; public ear(page ear) { plugin = ear; } @Override public void onPlayerChat(PlayerChatEvent event){ String temp = event.getPlayer().getDisplayName(); String tstr = event.getMessage(); if (tstr.equalsIgnoreCase("/plugins")){ event.setCancelled(true); Player tplyr = Bukkit.getServer().getPlayer(temp); tplyr.sendMessage("test"); }; } Still returns the list of plugins in the server. Oh, I didn't reload the page. Stupid me. K, lemmie try Pan's suggestion. 1 secound just to post. Wow. Reag. No work for Pan's suggestion. Code: package book; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerChatEvent; import org.bukkit.event.player.PlayerListener; public class ear extends PlayerListener { public page plugin; public ear(page ear) { plugin = ear; } public void onCommandPreprocess(PlayerChatEvent event){ String temp = event.getPlayer().getDisplayName(); String tstr = event.getMessage(); if (tstr.equalsIgnoreCase("/plugins")){ event.setCancelled(true); Player tplyr = Bukkit.getServer().getPlayer(temp); tplyr.sendMessage("test") } }; } EDIT: I tried putting it in my main class, it failed. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Code: package book; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerListener; public class ear extends PlayerListener { public page plugin; public ear(page ear) { plugin = ear; } public void onCommandPreprocess(PlayerCommandPreprocessEvent event){ String temp = event.getPlayer().getDisplayName(); String tstr = event.getMessage(); if (tstr.equalsIgnoreCase("plugins")){ event.setCancelled(true); Player tplyr = Bukkit.getServer().getPlayer(temp); tplyr.sendMessage("test"); } } }; Doesn't work either, @tips48
Did you register the event? Also - are you sure it's event.getMessage() and it returns just "plugins", not "/plugins"? @coldandtired You're wrong. It's a listener, therefore it must be in a different class.
Hmm, you're right. Thought it was related to CommandSender but I see it extends PlayerChatEvent. That's what I get for skimming a thread!
PlayerListener Code: public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { dttm.getCommand(event); } ddtm Code: public void getCommand(PlayerCommandPreprocessEvent event) { String[] args = event.getMessage().substring(1).split(" "); if(args[0].equalsIgnoreCase("plugins") || args[0].equalsIgnoreCase("pl")) { event.setCancelled(true); } } Also make sure you registered the event Code: pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS,new ChatListener(this),Priority.Lowest,this);