More locale, command, and Party updates.

This commit is contained in:
GJ 2012-04-22 15:36:48 -04:00
parent efc63b5230
commit 66b4388e64
7 changed files with 189 additions and 132 deletions

View File

@ -1,13 +1,10 @@
package com.gmail.nossr50.api; package com.gmail.nossr50.api;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList; import java.util.ArrayList;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.Users; import com.gmail.nossr50.Users;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.party.Party; import com.gmail.nossr50.party.Party;
public class PartyAPI { public class PartyAPI {
@ -57,47 +54,7 @@ public class PartyAPI {
* @return the list of parties. * @return the list of parties.
*/ */
public ArrayList<String> getParties() { public ArrayList<String> getParties() {
String location = mcMMO.usersFile; return Party.getInstance().getParties();
ArrayList<String> parties = new ArrayList<String>();
try {
//Open the users file
FileReader file = new FileReader(location);
BufferedReader in = new BufferedReader(file);
String line = "";
while((line = in.readLine()) != null) {
String[] character = line.split(":");
String theparty = null;
//Party
if (character.length > 3) {
theparty = character[3];
}
if (!parties.contains(theparty)) {
parties.add(theparty);
}
}
in.close();
}
catch (Exception e) {
mcMMO.p.getLogger().severe("Exception while reading " + location + " (Are you sure you formatted it correctly?)" + e.toString());
}
return parties;
}
/**
* Get a list of all online players in this player's party.
* </br>
* This function is designed for API usage.
*
* @param player The player to check
* @return all online players in the player's party
*/
public ArrayList<Player> getOnlineMembers(Player player) {
return Party.getInstance().getOnlineMembers(player);
} }
/** /**
@ -158,4 +115,28 @@ public class PartyAPI {
public ArrayList<Player> getAllMembers(Player player) { public ArrayList<Player> getAllMembers(Player player) {
return Party.getInstance().getAllMembers(player); return Party.getInstance().getAllMembers(player);
} }
/**
* Get a list of all online players in this party.
* </br>
* This function is designed for API usage.
*
* @param partyName The party to check
* @return all online players in this party
*/
public ArrayList<Player> getOnlineMembers(String partyName) {
return Party.getInstance().getOnlineMembers(partyName);
}
/**
* Get a list of all online players in this player's party.
* </br>
* This function is designed for API usage.
*
* @param player The player to check
* @return all online players in the player's party
*/
public ArrayList<Player> getOnlineMembers(Player player) {
return Party.getInstance().getOnlineMembers(player);
}
} }

View File

@ -24,7 +24,7 @@ public class ACommand implements CommandExecutor {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
PlayerProfile PP; PlayerProfile PP;
String usage = ChatColor.RED + "Proper usage is /a [message]"; //TODO: Needs more locale. String usage = ChatColor.RED + "Proper usage is /a <message>"; //TODO: Needs more locale.
if (CommandHelper.noCommandPermissions(sender, "mcmmo.chat.adminchat")) { if (CommandHelper.noCommandPermissions(sender, "mcmmo.chat.adminchat")) {
return true; return true;
@ -78,7 +78,6 @@ public class ACommand implements CommandExecutor {
} }
message = chatEvent.getMessage(); message = chatEvent.getMessage();
String prefix = ChatColor.AQUA + "{" + ChatColor.WHITE + "*Console*" + ChatColor.AQUA + "} "; String prefix = ChatColor.AQUA + "{" + ChatColor.WHITE + "*Console*" + ChatColor.AQUA + "} ";
plugin.getLogger().info("[A]<*Console*> " + message); plugin.getLogger().info("[A]<*Console*> " + message);

View File

@ -8,10 +8,11 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.Users; import com.gmail.nossr50.Users;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.mcPermissions; import com.gmail.nossr50.commands.CommandHelper;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.events.chat.McMMOPartyChatEvent; import com.gmail.nossr50.events.chat.McMMOPartyChatEvent;
import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.locale.mcLocale;
import com.gmail.nossr50.party.Party;
public class PCommand implements CommandExecutor { public class PCommand implements CommandExecutor {
private final mcMMO plugin; private final mcMMO plugin;
@ -22,76 +23,93 @@ public class PCommand implements CommandExecutor {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
PlayerProfile PP;
String usage = ChatColor.RED + "Proper usage is /p <partyname> <message>"; //TODO: Needs more locale.
// Console message? if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party")) {
if (!(sender instanceof Player)) {
if (args.length < 2)
return true;
String pMessage = args[1];
for (int i = 2; i <= args.length - 1; i++) {
pMessage = pMessage + " " + args[i];
}
McMMOPartyChatEvent chatEvent = new McMMOPartyChatEvent("Console", args[0], pMessage);
plugin.getServer().getPluginManager().callEvent(chatEvent);
if(chatEvent.isCancelled()) return true;
pMessage = chatEvent.getMessage();
String pPrefix = ChatColor.GREEN + "(" + ChatColor.WHITE + "*Console*" + ChatColor.GREEN + ") ";
plugin.getLogger().info("[P](" + args[0] + ")" + "<*Console*> " + pMessage);
for (Player herp : plugin.getServer().getOnlinePlayers()) {
if (Users.getProfile(herp).inParty()) {
if (Users.getProfile(herp).getParty().equalsIgnoreCase(args[0])) {
herp.sendMessage(pPrefix + pMessage);
}
}
}
return true; return true;
} }
Player player = (Player) sender;
PlayerProfile PP = Users.getProfile(player);
if (!mcPermissions.getInstance().party(player)) { switch (args.length) {
player.sendMessage(ChatColor.YELLOW + "[mcMMO] " + ChatColor.DARK_RED + mcLocale.getString("mcPlayerListener.NoPermission")); case 0:
return true; if (sender instanceof Player) {
} PP = Users.getProfile((Player) sender);
// Not a toggle, a message if (PP.getAdminChatMode()) {
if (args.length >= 1) {
if(!PP.inParty()) {
player.sendMessage("You're not in a party."); //TODO: Use mcLocale
return true;
}
String pMessage = args[0];
for (int i = 1; i <= args.length - 1; i++) {
pMessage = pMessage + " " + args[i];
}
PP.togglePartyChat();
player.chat(pMessage);
PP.togglePartyChat();
return true;
}
if (PP.getAdminChatMode())
PP.toggleAdminChat(); PP.toggleAdminChat();
}
PP.togglePartyChat(); PP.togglePartyChat();
if (PP.getPartyChatMode()) { if (PP.getPartyChatMode()) {
player.sendMessage(mcLocale.getString("mcPlayerListener.PartyChatOn")); sender.sendMessage(mcLocale.getString("Commands.Party.Chat.On"));
} else { }
player.sendMessage(mcLocale.getString("mcPlayerListener.PartyChatOff")); else {
sender.sendMessage(mcLocale.getString("Commands.Party.Chat.Off"));
}
}
else {
sender.sendMessage(usage);
}
return true;
default:
if (sender instanceof Player) {
Player player = (Player) sender;
PP = Users.getProfile(player);
if (!PP.inParty()) {
player.sendMessage(mcLocale.getString("Commands.Party.None"));
return true;
}
String message = args[0];
for (int i = 1; i < args.length; i++) {
message = message + " " + args [i];
}
PP.togglePartyChat();
player.chat(message);
PP.togglePartyChat();
}
else {
if (args.length < 2) {
sender.sendMessage(usage);
return true;
}
if (!Party.getInstance().getParties().contains(args[0])) {
sender.sendMessage(mcLocale.getString("Party.InvalidName"));
return true;
}
String message = args[1];
for (int i = 2; i < args.length; i++) {
message = message + " " + args [i];
}
McMMOPartyChatEvent chatEvent = new McMMOPartyChatEvent("Console", args[0], message);
plugin.getServer().getPluginManager().callEvent(chatEvent);
if (chatEvent.isCancelled()) {
return true;
}
message = chatEvent.getMessage();
String prefix = ChatColor.GREEN + "(" + ChatColor.WHITE + "*Console*" + ChatColor.GREEN + ") ";
plugin.getLogger().info("[P](" + args[0] + ")" + "<*Console*> " + message);
for (Player player : Party.getInstance().getOnlineMembers(args[0])) {
player.sendMessage(prefix + message);
}
} }
return true; return true;
} }
} }
}

View File

@ -24,7 +24,6 @@ public class PartyCommand implements CommandExecutor {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (CommandHelper.noConsoleUsage(sender)) { if (CommandHelper.noConsoleUsage(sender)) {
return true; return true;
} }

View File

@ -1173,18 +1173,20 @@ public class PlayerProfile {
* @return the party bonus multiplier * @return the party bonus multiplier
*/ */
private double partyModifier(SkillType skillType) { private double partyModifier(SkillType skillType) {
Player player = mcMMO.p.getServer().getPlayer(playerName); Player player = getPlayer();
double bonusModifier = 0.0; double bonusModifier = 0.0;
for (Player x : Party.getInstance().getOnlineMembers(player)) { for (Player x : Party.getInstance().getOnlineMembers(player)) {
if (x.isOnline() && !x.getName().equals(player.getName()) && Party.getInstance().isPartyLeader(x.getName(), this.getParty())) { String memberName = x.getName();
if (!memberName.equals(playerName) && Party.getInstance().isPartyLeader(memberName, getParty())) {
if (m.isNear(player.getLocation(), x.getLocation(), 25.0)) { if (m.isNear(player.getLocation(), x.getLocation(), 25.0)) {
PlayerProfile PartyLeader = Users.getProfile(x); PlayerProfile PartyLeader = Users.getProfile(x);
int leaderSkill = PartyLeader.getSkillLevel(skillType);
int playerSkill = getSkillLevel(skillType);
if (PartyLeader.getSkillLevel(skillType) >= this.getSkillLevel(skillType)) { if (leaderSkill >= playerSkill) {
int difference = leaderSkill - playerSkill;
int leaderLevel = PartyLeader.getSkillLevel(skillType);
int difference = leaderLevel - this.getSkillLevel(skillType);
bonusModifier = (difference * 0.75) / 100.0; bonusModifier = (difference * 0.75) / 100.0;
} }
} }

View File

@ -316,11 +316,9 @@ public class mcPlayerListener implements Listener {
event.setMessage(chatEvent.getMessage()); event.setMessage(chatEvent.getMessage());
for (Player x : plugin.getServer().getOnlinePlayers()) { for (Player x : Party.getInstance().getOnlineMembers(player)) {
if (Party.getInstance().inSameParty(player, x)) {
intendedRecipients.add(x); intendedRecipients.add(x);
} }
}
event.setFormat(color + "(" + ChatColor.WHITE + "%1$s" + color + ") %2$s"); event.setFormat(color + "(" + ChatColor.WHITE + "%1$s" + color + ") %2$s");
} }

View File

@ -1,10 +1,12 @@
package com.gmail.nossr50.party; package com.gmail.nossr50.party;
import java.io.BufferedReader;
import java.io.EOFException; import java.io.EOFException;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
@ -73,29 +75,25 @@ public class Party {
* @return the number of players in this player's party * @return the number of players in this player's party
*/ */
public int partyCount(Player player) { public int partyCount(Player player) {
PlayerProfile PP = Users.getProfile(player); if (player != null) {
int partyMembers = 0; return getAllMembers(player).size();
for (Player p : plugin.getServer().getOnlinePlayers()) {
if (player != null && p != null) { //Is this even possible?
if (PP.getParty().equals(Users.getProfile(p).getParty())) {
partyMembers++;
} }
else {
return 0;
} }
} }
return partyMembers;
}
private void informPartyMembers(Player player) { private void informPartyMembers(Player player) {
String playerName = player.getName(); String playerName = player.getName();
if (player != null) { if (player != null) {
for (Player p : getOnlineMembers(player)) { for (Player p : getOnlineMembers(player)) {
if (p.getName() != playerName) {
p.sendMessage(mcLocale.getString("Party.InformedOnJoin", new Object[] {playerName})); p.sendMessage(mcLocale.getString("Party.InformedOnJoin", new Object[] {playerName}));
} }
} }
} }
}
/** /**
* Get a list of all online players in this player's party. * Get a list of all online players in this player's party.
@ -106,9 +104,31 @@ public class Party {
public ArrayList<Player> getOnlineMembers(Player player) { public ArrayList<Player> getOnlineMembers(Player player) {
ArrayList<Player> players = new ArrayList<Player>(); ArrayList<Player> players = new ArrayList<Player>();
if (player != null) {
for (Player p : plugin.getServer().getOnlinePlayers()) { for (Player p : plugin.getServer().getOnlinePlayers()) {
if (player != null && p != null) { if (inSameParty(player, p)) {
if (inSameParty(player, p) && !p.getName().equals(player.getName())) { players.add(p);
}
}
}
return players;
}
/**
* Get a list of all online players in this party.
*
* @param partyName The party to check
* @return all online players in this party
*/
public ArrayList<Player> getOnlineMembers(String partyName) {
ArrayList<Player> players = new ArrayList<Player>();
for (Player p : plugin.getServer().getOnlinePlayers()) {
PlayerProfile PP = Users.getProfile(p);
if (PP.inParty()) {
if (PP.getParty().equalsIgnoreCase(partyName)) {
players.add(p); players.add(p);
} }
} }
@ -139,6 +159,42 @@ public class Party {
return players; return players;
} }
/**
* Get a list of all current party names.
*
* @return the list of parties.
*/
public ArrayList<String> getParties() {
String location = mcMMO.usersFile;
ArrayList<String> parties = new ArrayList<String>();
try {
FileReader file = new FileReader(location);
BufferedReader in = new BufferedReader(file);
String line = "";
while ((line = in.readLine()) != null) {
String[] character = line.split(":");
String theparty = null;
//Party
if (character.length > 3) {
theparty = character[3];
}
if (!parties.contains(theparty)) {
parties.add(theparty);
}
}
in.close();
}
catch (Exception e) {
mcMMO.p.getLogger().severe("Exception while reading " + location + " (Are you sure you formatted it correctly?)" + e.toString());
}
return parties;
}
/** /**
* Notify party members when the party owner changes. * Notify party members when the party owner changes.
* *
@ -149,10 +205,12 @@ public class Party {
if (newOwner != null) { if (newOwner != null) {
for (Player p : getOnlineMembers(newOwner)) { for (Player p : getOnlineMembers(newOwner)) {
if (p.getName() != newOwnerName) {
p.sendMessage(newOwnerName + " is the new party owner."); //TODO: Needs more locale p.sendMessage(newOwnerName + " is the new party owner."); //TODO: Needs more locale
} }
} }
} }
}
/** /**
* Notify party members when the a party member quits. * Notify party members when the a party member quits.
@ -164,10 +222,12 @@ public class Party {
if (player != null) { if (player != null) {
for (Player p : getOnlineMembers(player)) { for (Player p : getOnlineMembers(player)) {
if (p.getName() != playerName) {
p.sendMessage(mcLocale.getString("Party.InformedOnQuit", new Object[] {playerName})); p.sendMessage(mcLocale.getString("Party.InformedOnQuit", new Object[] {playerName}));
} }
} }
} }
}
/** /**
* Remove a player from a party. * Remove a player from a party.