Browse files

OfflinePlayers are more flexible than Strings

  • Loading branch information...
1 parent 6a3adbd commit f85bb7923f8c873f27b0e0e266dcac904487239d @holic holic committed Jun 5, 2012
Showing with 35 additions and 32 deletions.
  1. +1 −1 pom.xml
  2. +34 −31 src/com/minecarts/quicksilver/Quicksilver.java
View
2 pom.xml
@@ -1,7 +1,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.minecarts</groupId>
- <version>1.0.8</version>
+ <version>1.0.9</version>
<artifactId>Quicksilver</artifactId>
<name>Quicksilver</name>
<url>http://www.minecarts.com/</url>
View
65 src/com/minecarts/quicksilver/Quicksilver.java
@@ -7,9 +7,11 @@
import java.util.HashSet;
import java.util.List;
+import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
+import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
@@ -19,13 +21,12 @@
import org.bukkit.event.entity.EntityTargetEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
-import org.bukkit.plugin.java.JavaPlugin;
import com.minecarts.dbpermissions.PermissionsCalculated;
public class Quicksilver extends JavaPlugin implements Listener {
- protected final Set<String> deaggroedPlayers = new HashSet<String>();
- protected final Set<String> vanishedPlayers = new HashSet<String>();
+ protected final Set<OfflinePlayer> deaggroedPlayers = new HashSet<OfflinePlayer>();
+ protected final Set<OfflinePlayer> vanishedPlayers = new HashSet<OfflinePlayer>();
@Override
public void onEnable() {
@@ -45,11 +46,12 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
}
playerToVanish = (Player) sender;
break;
+
case 1:
if(args[0].equalsIgnoreCase("list")) {
sender.sendMessage("---Vanished players---");
- for(String name : vanishedPlayers) {
- sender.sendMessage(name);
+ for(OfflinePlayer player : vanishedPlayers) {
+ sender.sendMessage(player.getName());
}
return true;
}
@@ -65,24 +67,24 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
if(playerToVanish == null) return false;
- if(!vanishedPlayers.contains(playerToVanish.getName())) {
+ if(!vanishedPlayers.contains(playerToVanish)) {
//Hide this player from all players
- vanishedPlayers.add(playerToVanish.getName());
- deaggroedPlayers.add(playerToVanish.getName());
+ vanishedPlayers.add(playerToVanish);
+ deaggroedPlayers.add(playerToVanish);
updatePlayer(playerToVanish);
sender.sendMessage(playerToVanish.getName() + " is now vanished.");
- if(!playerToVanish.getName().equals(sender.getName())) {
+ if(!playerToVanish.equals(sender)) {
playerToVanish.sendMessage(sender.getName() + " has made you invisible.");
}
log("{0} VANISHED {1}", sender.getName(), playerToVanish.getName());
} else {
- vanishedPlayers.remove(playerToVanish.getName());
- deaggroedPlayers.remove(playerToVanish.getName());
+ vanishedPlayers.remove(playerToVanish);
+ deaggroedPlayers.remove(playerToVanish);
updatePlayer(playerToVanish);
sender.sendMessage(playerToVanish.getName() + " is now visible.");
- if(!playerToVanish.getName().equals(sender.getName())) {
+ if(!playerToVanish.equals(sender)) {
playerToVanish.sendMessage(sender.getName() + " has made you visible.");
}
log("{0} UNVANISHED {1}", sender.getName(), playerToVanish.getName());
@@ -103,13 +105,14 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
sender.sendMessage("You cannot deaggro yourself when you're not a player.");
return true;
}
- playerToDeaggro = (Player)sender;
+ playerToDeaggro = (Player) sender;
break;
+
case 1:
if(args[0].equalsIgnoreCase("list")) {
sender.sendMessage("---Deaggroed players---");
- for(String name : deaggroedPlayers) {
- sender.sendMessage(name);
+ for(OfflinePlayer player : deaggroedPlayers) {
+ sender.sendMessage(player.getName());
}
return true;
}
@@ -123,20 +126,20 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
playerToDeaggro = players.get(0);
}
- if(deaggroedPlayers.contains(playerToDeaggro.getName())) {
- deaggroedPlayers.remove(playerToDeaggro.getName());
+ if(deaggroedPlayers.contains(playerToDeaggro)) {
+ deaggroedPlayers.remove(playerToDeaggro);
sender.sendMessage(playerToDeaggro.getName() + " will now aggro mobs.");
- if(!playerToDeaggro.getName().equals(sender.getName())) {
+ if(!playerToDeaggro.equals(sender)) {
playerToDeaggro.sendMessage(sender.getName() + " has made it so you will aggro mobs.");
}
log("{0} AGGROED {1}", sender.getName(), playerToDeaggro.getName());
} else {
- deaggroedPlayers.add(playerToDeaggro.getName());
+ deaggroedPlayers.add(playerToDeaggro);
sender.sendMessage(playerToDeaggro.getName() + " will no longer aggro mobs.");
- if(!playerToDeaggro.getName().equals(sender.getName())) {
+ if(!playerToDeaggro.equals(sender)) {
playerToDeaggro.sendMessage(sender.getName() + " has made it so you will no long aggro mobs.");
}
log("{0} DEAGGROED {1}", sender.getName(), playerToDeaggro.getName());
@@ -163,13 +166,13 @@ public void onDisable() {
@EventHandler
public void playerAggro(EntityTargetEvent event) {
- if(event.getTarget() instanceof Player && deaggroedPlayers.contains(((Player) event.getTarget()).getName())) {
+ if(event.getTarget() instanceof Player && deaggroedPlayers.contains((Player) event.getTarget())) {
event.setCancelled(true);
}
}
@EventHandler
public void playerPickupItem(PlayerPickupItemEvent event) {
- if(vanishedPlayers.contains(event.getPlayer().getName())) {
+ if(vanishedPlayers.contains(event.getPlayer())) {
event.setCancelled(true);
}
}
@@ -181,11 +184,11 @@ public void permissionsUpdate(PermissionsCalculated event) {
if(player == null) return; // shouldn't happen, but something has been throwing NPEs
if(player.hasPermission("quicksilver.vanish.always")) {
- vanishedPlayers.add(player.getName());
- deaggroedPlayers.add(player.getName());
+ vanishedPlayers.add(player);
+ deaggroedPlayers.add(player);
}
else if(player.hasPermission("quicksilver.deaggro.always")) {
- deaggroedPlayers.add(player.getName());
+ deaggroedPlayers.add(player);
}
updatePlayer(player);
}
@@ -197,22 +200,22 @@ public void playerConnect(PlayerJoinEvent event) {
}
- protected Set<Player> getOnlinePlayers(Set<String> names) {
- Set<Player> players = new HashSet<Player>();
+ protected Set<Player> getOnlinePlayers(Set<OfflinePlayer> players) {
+ Set<Player> online = new HashSet<Player>();
for(Player player : Bukkit.getOnlinePlayers()) {
- if(names.contains(player.getName())) {
- players.add(player);
+ if(players.contains(player)) {
+ online.add(player);
}
}
- return players;
+ return online;
}
protected void updatePlayer(Player target) {
if(target == null) return; // shouldn't happen, but something has been throwing NPEs
// player is vanished
- if(vanishedPlayers.contains(target.getName())) {
+ if(vanishedPlayers.contains(target)) {
// hide player from online players
for(Player p : Bukkit.getOnlinePlayers()) {
if(target.equals(p)) continue; // skip self

0 comments on commit f85bb79

Please sign in to comment.