I don't know how to setup randomNumber method so that it runs when I want it to under public boolean Code: package me.thedirtydan.AntiSwear; import java.util.Random; import java.util.logging.Logger; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.java.JavaPlugin; public class Main extends JavaPlugin { Logger log; Random random = new Random(); public void onDisable(){ PluginDescriptionFile pdfFile = this.getDescription(); Logger log = this.getServer().getLogger(); log.info(pdfFile.getName() + " has been disabled"); } public void onEnable(){ getServer().getPluginManager().registerEvents(new MainListener(), this); PluginDescriptionFile pdfFile = this.getDescription(); Logger log = this.getServer().getLogger(); log.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " has been enabled"); } public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){ this.getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable() { public void run() { getServer().broadcastMessage(randomNumber); } }, 60L, 200L); return true; } public void randomNumber(String t){ String alphaNumerics = "qwertyuiopasdfghjklzxcvbnm1234567890"; t = ""; for (int i = 0; i < 8; i++) { t += alphaNumerics.charAt(random.nextInt()* alphaNumerics.length()); } } }
To call a void method in java you just use: EDIT: (this is just in your case its different all the time) Code: randomNumber(//a String here); Just put that in your onCommand i guess is where you where specifying. Hope i helped For other methods you need to call say you need to call Code: public int add(int x, int y, int z) { return x+y+z; } You would use : Code: add(7,4,6); And get you get 17, you can use it to compare as well for example: Code: if(15 > add(7,5,5) { //stuff }
so you are saying it would look like this? Code: public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){ randomNumber(String t); } ?
Uh you wouldnt pass in String t, you would pass in a string variable or just a string like : Code: public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){ randomNumber("stringy"); }
That still doesn't help, I am trying to apply that method so that the server broadcasts the randomly generated number that is created in the method.
Well than you need to make a method that makes a random number. Make that method return an Integer, then broadcast that integer.
Code: Bukkit.getServer().broadcastMessage(String message); Now assuming you have generated a number called "randomNumber", here's how to broadcast it: Code: Bukkit.getServer().broadcastMessage("The randomly generated number is: " + randomNumber); You will have to import org.bukkit.Bukkit
It gives me an error with the randomNumber under the randomNumber in the broadcast, and it gives me the option to create a constant, create field, etc. .
You also need to change your randomNumber method from accepting a String parameter to returning a String.
So like Code: public String randomNumber(String t){ String alphaNumerics = "qwertyuiopasdfghjklzxcvbnm1234567890"; t = ""; for (int i = 0; i < 8; i++) { t += alphaNumerics.charAt(random.nextInt()* alphaNumerics.length()); } return alphaNumerics; }