Well, I have started working on a Magic Clock plugin and I finished it but when I loaded it to my server it doesn't do anything it is supposed to in the code there is no errors at ALL! Here is my code: Code:java package me.webbhead.magicclock; import java.util.ArrayList; import org.bukkit.Bukkit;import org.bukkit.ChatColor;import org.bukkit.Material;import org.bukkit.entity.Player;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; public class MagicClock extends JavaPlugin implements Listener { private ArrayList<Player> vanished = new ArrayList<Player>(); public void onEnable() { Bukkit.getServer().getPluginManager().registerEvents(this, this); getConfig().options().copyDefaults(true); saveConfig(); } public void onDisable() { } @EventHandler public void onPlayerInteract(PlayerInteractEvent e) { Player player = e.getPlayer(); for (Player players : Bukkit.getOnlinePlayers()) { if (!vanished.contains(players)) { if (e.getAction() == Action.RIGHT_CLICK_BLOCK && player.getItemInHand().getType() == Material.WATCH) { player.hidePlayer(players); player.sendMessage(ChatColor.DARK_RED + "All players have been hidden!"); } vanished.add(players); } else { if (e.getAction() == Action.RIGHT_CLICK_BLOCK && player.getItemInHand().getType() == Material.WATCH) { player.showPlayer(players); player.sendMessage(ChatColor.DARK_RED + "All players have been revealed!"); } vanished.remove(players); } } }}
Try this: Code:java for (Player online : getServer().getOnlinePlayers) {Player player = e.getPlayer(); //How to hide the player:online.hidePlayer(player); //Then to show the player againonline.showPlayer(player);}
Code:java if(event.getAction().equals(Action.RIGHT_CLICK_BLOCK) || event.getAction().equals(Action.RIGHT_CLICK_AIR)){ if(this.players.contains(event.getPlayer().getName())){ for(Player targetPlayers : Bukkit.getOnlinePlayers()){ if(player.canSee(targetPlayers)){ player.hidePlayer(targetPlayers); } else{ event.setCancelled(true); Try this code out, I tried it in mine. And it did work.
ShearsSheep I actually got it working.. But I ran into another problem: Im the only one on the server i right click the Clock It sends me the messages correctly. However when there is 2 people on the server it sends me the message twice! Please help :/
That is because you have the server sending the player the message within the for loop. You are basically saying: for every player on the server, do this x amount of times.
rbrick ShearsSheep Thank you! I'll for SURE try this! rbrick ShearsSheep put the message like this: This screwed everything up It still shows double on each and the plugin stopped working right. player.sendMessage(ChatColor.RED + "All Players have been revealed!" if (e.getAction() == Action.RIGHT_CLICK_AIR && player.getItemInHand().getType() == Material.WATCH) { player.showPlayer(players); Well anyways I had to put it back and it still does it. :/ Any Suggestions or could you give me any example of taking it out of the "Loop" because I don't know if I did it right. EDIT by Moderator: merged posts, please use the edit button instead of double posting.