Fixed many broken features and added the ability to check who is in your party.

This commit is contained in:
nossr50 2011-02-04 16:51:37 -08:00
parent 980d8fb374
commit 9084b3fca4
2 changed files with 68 additions and 17 deletions

View File

@ -25,27 +25,60 @@ public class mcPlayerListener extends PlayerListener {
player.sendMessage("Set your spawn with "+ChatColor.YELLOW+"/setmyspawn"+ChatColor.WHITE+", Travel to it with /myspawn"); player.sendMessage("Set your spawn with "+ChatColor.YELLOW+"/setmyspawn"+ChatColor.WHITE+", Travel to it with /myspawn");
player.sendMessage(ChatColor.RED+"WARNING: "+ChatColor.DARK_GRAY+ "Using /myspawn will clear your inventory!"); player.sendMessage(ChatColor.RED+"WARNING: "+ChatColor.DARK_GRAY+ "Using /myspawn will clear your inventory!");
} }
//Check if string is a player
public boolean isPlayer(String playerName){
for(Player herp : plugin.getServer().getOnlinePlayers()){
if(herp.getName().toLowerCase().equals(playerName.toLowerCase())){
return true;
}
}
return false;
}
public int partyCount(Player player){
Player players[] = plugin.getServer().getOnlinePlayers();
int x = 0;
for(Player hurrdurr: players){
if(mcUsers.getProfile(player).getParty().equals(mcUsers.getProfile(hurrdurr).getParty()))
x++;
}
return x;
}
public Player getPlayer(String playerName){
for(Player herp : plugin.getServer().getOnlinePlayers()){
if(herp.getName().toLowerCase().equals(playerName.toLowerCase())){
return herp;
}
}
return null;
}
public void onPlayerCommand(PlayerChatEvent event) { public void onPlayerCommand(PlayerChatEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
String[] split = event.getMessage().split(" "); String[] split = event.getMessage().split(" ");
String playerName = player.getName(); String playerName = player.getName();
//mcMMO command //mcMMO command
if(split[0].equalsIgnoreCase("/whereis")){ if(player.isOp() && split[0].equalsIgnoreCase("/whois")){
if(!player.isOp()) if(split.length < 2){
return; player.sendMessage(ChatColor.RED + "Proper usage is /whois <playername>");
if(split.length == 1){
player.sendMessage("Usage is /whereis [player]");
return; return;
} }
for(Player derp : plugin.getServer().getOnlinePlayers()){ //if split[1] is a player
if(derp.getName().toLowerCase().equals(split[2].toLowerCase())){ if(isPlayer(split[1])){
Location loc = derp.getLocation(); Player target = getPlayer(split[1]);
player.sendMessage("Player " + derp.getName() + " Coordinates"); double x,y,z;
player.sendMessage("X: " + String(loc.getX())); x = target.getLocation().getX();
player.sendMessage("Y: " + String(loc.getY())); y = target.getLocation().getY();
player.sendMessage("Z: " + String(loc.getZ())); z = target.getLocation().getZ();
} player.sendMessage(ChatColor.GREEN + "~~WHOIS RESULTS~~");
} player.sendMessage(target.getName());
player.sendMessage("Health: "+target.getHealth()+ChatColor.GRAY+" (20 is full health)");
player.sendMessage("OP: " + target.isOp());
player.sendMessage(ChatColor.GREEN+"~~mcMMO stats~~");
player.sendMessage("Gathering Skill: "+mcUsers.getProfile(target).getgather());
player.sendMessage(ChatColor.GREEN+"~~COORDINATES~~");
player.sendMessage("X: "+x);
player.sendMessage("Y: "+y);
player.sendMessage("Z: "+z);
}
} }
if(split[0].equalsIgnoreCase("/setmyspawn")){ if(split[0].equalsIgnoreCase("/setmyspawn")){
double x = player.getLocation().getX(); double x = player.getLocation().getX();
@ -68,10 +101,28 @@ public class mcPlayerListener extends PlayerListener {
//Party command //Party command
if(split[0].equalsIgnoreCase("/party")){ if(split[0].equalsIgnoreCase("/party")){
event.setCancelled(true); event.setCancelled(true);
if(split.length == 1){ if(split.length == 1 && !mcUsers.getProfile(player).inParty()){
player.sendMessage("Proper usage is /party <name> or 'q' to quit"); player.sendMessage("Proper usage is /party <name> or 'q' to quit");
return; return;
} }
if(split.length == 1 && mcUsers.getProfile(player).inParty()){
String tempList = "";
int x = 0;
for(Player p : plugin.getServer().getOnlinePlayers())
{
if(mcUsers.getProfile(player).getParty().equals(mcUsers.getProfile(p).getParty())){
if(p != null && x+1 >= partyCount(player)){
tempList+= p.getName();
x++;
}
if(p != null && x < partyCount(player)){
tempList+= p.getName() +", ";
x++;
}
}
}
player.sendMessage(ChatColor.GREEN + "Party Members ("+ChatColor.WHITE+tempList+ChatColor.GREEN+")");
}
if(split[1].equals("q") && mcUsers.getProfile(player).inParty()){ if(split[1].equals("q") && mcUsers.getProfile(player).inParty()){
mcUsers.getProfile(player).removeParty(); mcUsers.getProfile(player).removeParty();
informPartyMembersQuit(player); informPartyMembersQuit(player);

View File

@ -12,7 +12,7 @@ import org.bukkit.entity.*;
public class mcUsers { public class mcUsers {
private static volatile mcUsers instance; private static volatile mcUsers instance;
protected static final Logger log = Logger.getLogger("Minecraft"); protected static final Logger log = Logger.getLogger("Minecraft");
String location = "mcMMO.users"; String location = "mcmmo.users";
public static PlayerList players = new PlayerList(); public static PlayerList players = new PlayerList();
private Properties properties = new Properties(); private Properties properties = new Properties();
@ -158,7 +158,7 @@ class PlayerList
private boolean dead; private boolean dead;
char defaultColor; char defaultColor;
String location = "mcMMO.users"; String location = "mcmmo.users";
//===================================================================== //=====================================================================