Can someone help me and give me a teleportation code? Because I don't know how to set up a command with arguments ingame. Code: if (label.equalsIgnoreCase("tp")) { How can I add arguments and how can I use them? Someone has an example please?
API: http://jd.bukkit.org/apidocs/org/bukkit/entity/Entity.html#teleport(org.bukkit.Location) It's simply entity.teleport(Location or Entity) For more info on how to create commands: http://wiki.bukkit.org/Plugin_Tutorial#Commands
is this ok to register the teleport command? Code: pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, playerListener, Event.Priority.Normal, this);
I would use this Code: public boolean onCommand(Command sender, Command cmd, String cmdLine, String[] args) { if (sender instanceof Player) { Player player = (Player) sender; if (cmd.getName().equalsIgnoreCase("tp")) { //Teleport code here } } } } Then you can use args[] for the arguments.
where i must put this in? in the PlayerListener or in the main? ok now i've made an example command wich should send a messega to the player. but all this player get is this command. and not the correct message. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Could you post your main/playerlistener, along with any errors you may have. Also, do you have a plugin.yml?
eTeleport.java (main): Code: package me.Etarus.eTeleport; import java.util.logging.Logger; import org.bukkit.event.Event; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; public class eTeleport extends JavaPlugin { private final eTeleportPlayerListener playerListener = new eTeleportPlayerListener(this); Logger log = Logger.getLogger("Minecraft"); public void onDisable() { log.info("[eTeleport] eTeleport plugin disabled."); } public void onEnable() { log.info("[eTeleport] eTeleport v." + getDescription().getVersion() + " plugin enabled"); PluginManager pm = this.getServer().getPluginManager(); pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, playerListener, Event.Priority.Normal, this); } } eTeleportPlayerListener (playerlistener): Code: package me.Etarus.eTeleport; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerListener; public class eTeleportPlayerListener extends PlayerListener { public static eTeleport plugin; public eTeleportPlayerListener(eTeleport instance) { plugin = instance; } public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (sender instanceof Player) { Player player = (Player) sender; if (cmd.getName().equalsIgnoreCase("test")) { player.sendMessage("Hallo"); return true; } } return false; } } plugin.yml: Code: name: eTeleport main: me.Etarus.eTeleport.eTeleport version: 0.1 author: Etarus commands: test: description: Say Something usage: /<command>
put Code:java public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (command.getName().equalsIgnoreCase("test")) { Player player = (Player) sender; player.sendMessage("Hallo"); } return false;} in the main and remove your playerlistener.
Should this be in the main or is it not needed? Code: pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, playerListener, Event.Priority.Normal, this);
Look at my corrected post and that is not needed This is what you want to teleport the player. Code:java public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (command.getName().equalsIgnoreCase("test") && args.length == 1) { Player player = (Player) sender; Player tele = getServer().getPlayer(args[0]); player.sendMessage("Teleport successful!"); player.teleport(tele); } return false;} EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Tank you, i'll try it. I have one question.The PluginManager is needed for what? (Sry, i'm new to java and to bukkit and try to learn sth.)
The plugin manage is to register events such as onPlayerChat (player listener), or onEntityDamage (entity listener), or onBlockPlace (block listener). So say you wanted to check when somebody places a block, you would have to register the Block Place event otherwise no matter what you do in your Block listener it will not register.
ok it works as it sends the message, but it say the executation command again If i type: /test It say: Code: Hallo /test ok thanks for that explanation. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
oh yeah, i forgot it. thank you. how can i write a colored text to a player? //EDIT: how can i get the player name? if i write: Code: victim.sendMessage(player + " ... you."); then it write something like: craftbukkit(name=player) ... or something like that... how can i fix this? 2nd problem solved. i changed to: Code: player.getDisplayName() Other problem exist: How to write colored messages to a player? EDIT by Moderator: merged posts, please use the edit button instead of double posting.
API: http://jd.bukkit.org/apidocs/org/bukkit/ChatColor.html Something like: player.sendMessage(ChatColor.RED + "blahblahblahblah");
Iterate through all players on the server, and send the error message to the player, if the specific player doesnt match any of the online players
well... an example? because i don't understand anything, sorry And: How can I hook into permissions 3.1.6?
Code: for(Player p : getCommandSender().getWorld().getPlayers() ) { if(p.getDisplayName() == playername_in_command) { do_something } } Might not be entirely correct since thats from my head, but I wish you can get the idea
Maybe Code:java Player pla = getServer().getPlayer(args[0]);List online = plugin.getServer().getOnlinePlayers();if (online.contains(pla)) { do somethin;} May or may not work, not sure
Thanks, it works. Next question: How can I make commands only for OP's or how to hook into permissions 3.1.6? I tried to hook into permissions but it doesn't work so far...
For the color in the chat use: Code: player.sendMessage(ChatColor.BLUE + "Hello " + ChatColor.WHITE + "how are you doing?"); You could better try to hook into a superperms system, like BukkitPermissions. Than you would need this: Code: Player s = (Player) sender; if (s.hasPermission("Permission Node")) { // than do something. } And in youre plugin.yml: Code: permissions: permissionnode: default: op Since youre having a permissions system integrated, and if its not found: Defaults to Operators only. Code: Player s = (Player) sender; if (!s.hasPermission("Permission Node")) { s.sendMessage(ChatColor.RED + "You dont have permission to do this.") } else { // teleport the player. } EDIT by Moderator: merged posts, please use the edit button instead of double posting.
A Location object contains a World value. For example in my warp plugin I don't care about /warp to another world or to the same world, it's the same.