How do you do invisibility? I think it involves hash maps and such... Here's the main: Code: package me.sunmin.DeadRinger; import java.util.ArrayList; import java.util.logging.Logger; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; public class DeadRinger extends JavaPlugin{ private final Logger log = Logger.getLogger("Minecraft"); public final DeadRingerListener entityListener = new DeadRingerListener(this); public final ArrayList<Player> DeadRingerUsers = new ArrayList<Player>(); @Override public void onEnable() { log.info("The plugin [DeadRinger] has been enabled"); PluginManager pm = getServer().getPluginManager(); pm.registerEvent(Event.Type.ENTITY_DAMAGE, entityListener, Event.Priority.Normal, this); } @Override public void onDisable() { log.info("The plugin [DeadRinger] has been disabled"); } @Override public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { if(cmd.getName().equalsIgnoreCase("DeadRinger")) { if(!(((Player) sender).getItemInHand().getType() == Material.WATCH)); toggleDeadRinger(sender); } return true; } private void toggleDeadRinger(final CommandSender sender) { if( !enabled((Player) sender) ) { DeadRingerUsers.add((Player) sender); ((Player) sender).sendMessage(ChatColor.BLUE + "You are now using DeadRinger"); log.info("Someone is using DeadRinger"); System.out.println(DeadRingerUsers); for (Player p:Bukkit.getServer().getOnlinePlayers()) { if (p.isOp()) { p.sendMessage("Someone is using DeadRinger"); } } // TODO Remove From DeadRingerUsers if not holding clock Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() { public void run() { DeadRingerUsers.remove((Player) sender); } },300L); } else { DeadRingerUsers.remove((Player) sender); ((Player) sender).sendMessage(ChatColor.RED + "You are now NOT using DeadRinger"); log.info("Someone is not using DeadRinger"); System.out.println(DeadRingerUsers); for (Player p:Bukkit.getServer().getOnlinePlayers()) { if (p.isOp()) { p.sendMessage("Someone is not using DeadRinger"); } } // TODO Cooldown 10 seconds } } public boolean enabled(Player player) { return DeadRingerUsers.contains(player); } } And the listener. Code: package me.sunmin.DeadRinger; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageEvent; public class DeadRingerListener implements Listener { @EventHandler public void onEntityDamage(EntityDamageEvent event) { if(plugin.enabled((Player) event.getEntity())) event.setDamage(2); System.out.println("You have been hit! You should now be invisible!"); // TODO Invisibility!!! } public static DeadRinger plugin; public DeadRingerListener(DeadRinger instance) { plugin = instance; } }
loop through all the players online and do player.hidePlayer(player2); where player is a player online and player2 is the one to be hidden.
event.setCancelled(true); This will stop the event from taking place. Simply check if the player is still "invincible" by doing a time check (stored in your hashmap) and deny it if your time limit has not been achieved. HashMap<Player, Double> PlayerList; is what you'll be looking for http://docs.oracle.com/javase/1.4.2/docs/api/java/util/Calendar.html this document will contain the knowledge you need on time codes (milliseconds)
There is no hidePlayer. I have no idea what that would do. It doesn't seem to turn a player invisible... EDIT by Moderator: merged posts, please use the edit button instead of double posting.
I believe the best you'll accomplish is swapping the players mesh with something else... turning them into a chicken or something. I don't quite see the point in "invisibility" on a server plugin except forcing monsters to only hit you once (then not take notice of you). time-delayed invincibility would help you prevent your player from taking damage too frequently, extending the "blink" time, but as sunmin said, there is no way to hide a player completely?
Code: private List<Player> hidden = new ArrayList<Player>(); @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args){ Player p = null; if(sender instanceof Player){ p = ((Player) sender).getPlayer(); } else { sender.sendMessage("Command must be run by a player."); return true; } if(label.equalsIgnoreCase("invisibru")){ Player[] players = this.getServer().getOnlinePlayers(); if (!hidden.contains(p)) { for (Player player : players) { player.hidePlayer(p); } this.hidden.add(p); p.sendMessage(ChatColor.RED + "You are now invisibru!"); } else { for(Player player : players) { player.showPlayer(p); } this.hidden.remove(p); p.sendMessage(ChatColor.RED + "You are now visibru."); } } } Then all you need to do to check if a player is invisible is see if he is on the list. (Last time I checked, setting a player invisible to himself is ok xD ) Also, this is very easy to apply to something besides on command, but it was the first thing I have setup in eclipse.
Oh. Now, how do you do that? (Using hidePlayer) (Sorry, I'm an absolute newb.) It would be extremely appreciated if you could show me in my own listener. EDIT by Moderator: merged posts, please use the edit button instead of double posting.