mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 21:26:46 +01:00
More locale, command, and Party updates.
This commit is contained in:
parent
efc63b5230
commit
66b4388e64
@ -1,13 +1,10 @@
|
||||
package com.gmail.nossr50.api;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.Users;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.party.Party;
|
||||
|
||||
public class PartyAPI {
|
||||
@ -57,47 +54,7 @@ public class PartyAPI {
|
||||
* @return the list of parties.
|
||||
*/
|
||||
public ArrayList<String> getParties() {
|
||||
String location = mcMMO.usersFile;
|
||||
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);
|
||||
return Party.getInstance().getParties();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -158,4 +115,28 @@ public class PartyAPI {
|
||||
public ArrayList<Player> getAllMembers(Player 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);
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ public class ACommand implements CommandExecutor {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
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")) {
|
||||
return true;
|
||||
@ -78,7 +78,6 @@ public class ACommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
message = chatEvent.getMessage();
|
||||
|
||||
String prefix = ChatColor.AQUA + "{" + ChatColor.WHITE + "*Console*" + ChatColor.AQUA + "} ";
|
||||
|
||||
plugin.getLogger().info("[A]<*Console*> " + message);
|
||||
|
@ -8,10 +8,11 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.Users;
|
||||
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.events.chat.McMMOPartyChatEvent;
|
||||
import com.gmail.nossr50.locale.mcLocale;
|
||||
import com.gmail.nossr50.party.Party;
|
||||
|
||||
public class PCommand implements CommandExecutor {
|
||||
private final mcMMO plugin;
|
||||
@ -20,78 +21,95 @@ public class PCommand implements CommandExecutor {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
@Override
|
||||
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 (!(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];
|
||||
}
|
||||
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
McMMOPartyChatEvent chatEvent = new McMMOPartyChatEvent("Console", args[0], pMessage);
|
||||
plugin.getServer().getPluginManager().callEvent(chatEvent);
|
||||
|
||||
if(chatEvent.isCancelled()) return true;
|
||||
switch (args.length) {
|
||||
case 0:
|
||||
if (sender instanceof Player) {
|
||||
PP = Users.getProfile((Player) sender);
|
||||
|
||||
pMessage = chatEvent.getMessage();
|
||||
if (PP.getAdminChatMode()) {
|
||||
PP.toggleAdminChat();
|
||||
}
|
||||
|
||||
String pPrefix = ChatColor.GREEN + "(" + ChatColor.WHITE + "*Console*" + ChatColor.GREEN + ") ";
|
||||
PP.togglePartyChat();
|
||||
|
||||
plugin.getLogger().info("[P](" + args[0] + ")" + "<*Console*> " + pMessage);
|
||||
if (PP.getPartyChatMode()) {
|
||||
sender.sendMessage(mcLocale.getString("Commands.Party.Chat.On"));
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(mcLocale.getString("Commands.Party.Chat.Off"));
|
||||
}
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(usage);
|
||||
}
|
||||
|
||||
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);
|
||||
default:
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
PP = Users.getProfile(player);
|
||||
|
||||
if (!mcPermissions.getInstance().party(player)) {
|
||||
player.sendMessage(ChatColor.YELLOW + "[mcMMO] " + ChatColor.DARK_RED + mcLocale.getString("mcPlayerListener.NoPermission"));
|
||||
return true;
|
||||
}
|
||||
if (!PP.inParty()) {
|
||||
player.sendMessage(mcLocale.getString("Commands.Party.None"));
|
||||
return true;
|
||||
}
|
||||
|
||||
// Not a toggle, a message
|
||||
String message = args[0];
|
||||
|
||||
if (args.length >= 1) {
|
||||
if(!PP.inParty()) {
|
||||
player.sendMessage("You're not in a party."); //TODO: Use mcLocale
|
||||
return true;
|
||||
}
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
message = message + " " + args [i];
|
||||
}
|
||||
|
||||
String pMessage = args[0];
|
||||
for (int i = 1; i <= args.length - 1; i++) {
|
||||
pMessage = pMessage + " " + args[i];
|
||||
}
|
||||
PP.togglePartyChat();
|
||||
player.chat(message);
|
||||
PP.togglePartyChat();
|
||||
}
|
||||
else {
|
||||
if (args.length < 2) {
|
||||
sender.sendMessage(usage);
|
||||
return true;
|
||||
}
|
||||
|
||||
PP.togglePartyChat();
|
||||
player.chat(pMessage);
|
||||
PP.togglePartyChat();
|
||||
if (!Party.getInstance().getParties().contains(args[0])) {
|
||||
sender.sendMessage(mcLocale.getString("Party.InvalidName"));
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
String message = args[1];
|
||||
|
||||
if (PP.getAdminChatMode())
|
||||
PP.toggleAdminChat();
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
message = message + " " + args [i];
|
||||
}
|
||||
|
||||
PP.togglePartyChat();
|
||||
McMMOPartyChatEvent chatEvent = new McMMOPartyChatEvent("Console", args[0], message);
|
||||
plugin.getServer().getPluginManager().callEvent(chatEvent);
|
||||
|
||||
if (PP.getPartyChatMode()) {
|
||||
player.sendMessage(mcLocale.getString("mcPlayerListener.PartyChatOn"));
|
||||
} else {
|
||||
player.sendMessage(mcLocale.getString("mcPlayerListener.PartyChatOff"));
|
||||
}
|
||||
if (chatEvent.isCancelled()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,6 @@ public class PartyCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
|
||||
if (CommandHelper.noConsoleUsage(sender)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -1173,18 +1173,20 @@ public class PlayerProfile {
|
||||
* @return the party bonus multiplier
|
||||
*/
|
||||
private double partyModifier(SkillType skillType) {
|
||||
Player player = mcMMO.p.getServer().getPlayer(playerName);
|
||||
Player player = getPlayer();
|
||||
double bonusModifier = 0.0;
|
||||
|
||||
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)) {
|
||||
PlayerProfile PartyLeader = Users.getProfile(x);
|
||||
int leaderSkill = PartyLeader.getSkillLevel(skillType);
|
||||
int playerSkill = getSkillLevel(skillType);
|
||||
|
||||
if (PartyLeader.getSkillLevel(skillType) >= this.getSkillLevel(skillType)) {
|
||||
|
||||
int leaderLevel = PartyLeader.getSkillLevel(skillType);
|
||||
int difference = leaderLevel - this.getSkillLevel(skillType);
|
||||
if (leaderSkill >= playerSkill) {
|
||||
int difference = leaderSkill - playerSkill;
|
||||
bonusModifier = (difference * 0.75) / 100.0;
|
||||
}
|
||||
}
|
||||
|
@ -316,10 +316,8 @@ public class mcPlayerListener implements Listener {
|
||||
|
||||
event.setMessage(chatEvent.getMessage());
|
||||
|
||||
for (Player x : plugin.getServer().getOnlinePlayers()) {
|
||||
if (Party.getInstance().inSameParty(player, x)) {
|
||||
intendedRecipients.add(x);
|
||||
}
|
||||
for (Player x : Party.getInstance().getOnlineMembers(player)) {
|
||||
intendedRecipients.add(x);
|
||||
}
|
||||
|
||||
event.setFormat(color + "(" + ChatColor.WHITE + "%1$s" + color + ") %2$s");
|
||||
|
@ -1,10 +1,12 @@
|
||||
package com.gmail.nossr50.party;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.EOFException;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
@ -73,18 +75,12 @@ public class Party {
|
||||
* @return the number of players in this player's party
|
||||
*/
|
||||
public int partyCount(Player player) {
|
||||
PlayerProfile PP = Users.getProfile(player);
|
||||
int partyMembers = 0;
|
||||
|
||||
for (Player p : plugin.getServer().getOnlinePlayers()) {
|
||||
if (player != null && p != null) { //Is this even possible?
|
||||
if (PP.getParty().equals(Users.getProfile(p).getParty())) {
|
||||
partyMembers++;
|
||||
}
|
||||
}
|
||||
if (player != null) {
|
||||
return getAllMembers(player).size();
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return partyMembers;
|
||||
}
|
||||
|
||||
private void informPartyMembers(Player player) {
|
||||
@ -92,7 +88,9 @@ public class Party {
|
||||
|
||||
if (player != null) {
|
||||
for (Player p : getOnlineMembers(player)) {
|
||||
p.sendMessage(mcLocale.getString("Party.InformedOnJoin", new Object[] {playerName}));
|
||||
if (p.getName() != playerName) {
|
||||
p.sendMessage(mcLocale.getString("Party.InformedOnJoin", new Object[] {playerName}));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -106,9 +104,31 @@ public class Party {
|
||||
public ArrayList<Player> getOnlineMembers(Player player) {
|
||||
ArrayList<Player> players = new ArrayList<Player>();
|
||||
|
||||
if (player != null) {
|
||||
for (Player p : plugin.getServer().getOnlinePlayers()) {
|
||||
if (inSameParty(player, p)) {
|
||||
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()) {
|
||||
if (player != null && p != null) {
|
||||
if (inSameParty(player, p) && !p.getName().equals(player.getName())) {
|
||||
PlayerProfile PP = Users.getProfile(p);
|
||||
|
||||
if (PP.inParty()) {
|
||||
if (PP.getParty().equalsIgnoreCase(partyName)) {
|
||||
players.add(p);
|
||||
}
|
||||
}
|
||||
@ -139,6 +159,42 @@ public class Party {
|
||||
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.
|
||||
*
|
||||
@ -149,7 +205,9 @@ public class Party {
|
||||
|
||||
if (newOwner != null) {
|
||||
for (Player p : getOnlineMembers(newOwner)) {
|
||||
p.sendMessage(newOwnerName + " is the new party owner."); //TODO: Needs more locale
|
||||
if (p.getName() != newOwnerName) {
|
||||
p.sendMessage(newOwnerName + " is the new party owner."); //TODO: Needs more locale
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -164,7 +222,9 @@ public class Party {
|
||||
|
||||
if (player != null) {
|
||||
for (Player p : getOnlineMembers(player)) {
|
||||
p.sendMessage(mcLocale.getString("Party.InformedOnQuit", new Object[] {playerName}));
|
||||
if (p.getName() != playerName) {
|
||||
p.sendMessage(mcLocale.getString("Party.InformedOnQuit", new Object[] {playerName}));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user