Hello! I would like to know how i can get a argument in a event class? so instead of add the command Mumble Jumble i can find the args, Such as Player p; p = e.getPlayer(); is a alternate to adding the Command Stuff... Thanks in advance!
You shoul better use CommandExecutors for all such stuff as it's much more stable Code (Text): ublic class MyCoolCommandClass implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String alias, String[] args) { if (sender instanceof Player) { Player player = (Player) sender; //TODO } return true; } return false; } }
What are you trying to do? There are no arguments in an event. You can get attributes of the event using the getters of the event.
In my event Class (WIP) Code (Text): package com.ionmc.Bot; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.AsyncPlayerChatEvent; public class OnChat implements Listener { @EventHandler public void onPlayerChat(AsyncPlayerChatEvent e){ Player p; p = e.getPlayer(); String google = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q="; boolean search = e.getMessage().contains("* google"); if(e.getMessage().contains("*")){ e.setCancelled(true); p.sendMessage("§7§l[§6§lIon§b§lBot§7§l] §8§lList Of Command's §4§l>>"); p.sendMessage("* Teleport me to spawn"); p.sendMessage(""); } if(e.getMessage().contains("* Teleport me to spawn")){ e.setCancelled(true); p.sendMessage("§7§l[§6§lIon§b§lBot§7§l] Teleporting"); Bukkit.dispatchCommand(p, "/spawn"); } } } I want to be able to access the players arguments such as "1010bob: Hi Im 1010bob" How can i get Im and or 1010bob
You're trying to use the chat event to make commands? Could you explain WHY this is your goal? Btw you shouldn't use .contains("*"), you should use .startsWith("*") for that.
Instead of creating a new 'BRAND-NEW-BOT-1337-HARDCODED-UNHACKABLE-UNCONFIGURABLE' try studying Java and SpigotAPI with it's Configuration system and (of course) terminology
Therefore you have to split the message: Code (Text): String[] args = e.getMessage().split(" "); But that way isn't nice!