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;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
@ -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;
|
||||||
@ -20,78 +21,95 @@ public class PCommand implements CommandExecutor {
|
|||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@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)) {
|
return true;
|
||||||
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;
|
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()) {
|
return true;
|
||||||
if (Users.getProfile(herp).inParty()) {
|
|
||||||
if (Users.getProfile(herp).getParty().equalsIgnoreCase(args[0])) {
|
|
||||||
herp.sendMessage(pPrefix + pMessage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Player player = (Player) sender;
|
default:
|
||||||
PlayerProfile PP = Users.getProfile(player);
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
PP = Users.getProfile(player);
|
||||||
|
|
||||||
if (!mcPermissions.getInstance().party(player)) {
|
if (!PP.inParty()) {
|
||||||
player.sendMessage(ChatColor.YELLOW + "[mcMMO] " + ChatColor.DARK_RED + mcLocale.getString("mcPlayerListener.NoPermission"));
|
player.sendMessage(mcLocale.getString("Commands.Party.None"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not a toggle, a message
|
String message = args[0];
|
||||||
|
|
||||||
if (args.length >= 1) {
|
for (int i = 1; i < args.length; i++) {
|
||||||
if(!PP.inParty()) {
|
message = message + " " + args [i];
|
||||||
player.sendMessage("You're not in a party."); //TODO: Use mcLocale
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
String pMessage = args[0];
|
PP.togglePartyChat();
|
||||||
for (int i = 1; i <= args.length - 1; i++) {
|
player.chat(message);
|
||||||
pMessage = pMessage + " " + args[i];
|
PP.togglePartyChat();
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
if (args.length < 2) {
|
||||||
|
sender.sendMessage(usage);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
PP.togglePartyChat();
|
if (!Party.getInstance().getParties().contains(args[0])) {
|
||||||
player.chat(pMessage);
|
sender.sendMessage(mcLocale.getString("Party.InvalidName"));
|
||||||
PP.togglePartyChat();
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
String message = args[1];
|
||||||
}
|
|
||||||
|
|
||||||
if (PP.getAdminChatMode())
|
for (int i = 2; i < args.length; i++) {
|
||||||
PP.toggleAdminChat();
|
message = message + " " + args [i];
|
||||||
|
}
|
||||||
|
|
||||||
PP.togglePartyChat();
|
McMMOPartyChatEvent chatEvent = new McMMOPartyChatEvent("Console", args[0], message);
|
||||||
|
plugin.getServer().getPluginManager().callEvent(chatEvent);
|
||||||
|
|
||||||
if (PP.getPartyChatMode()) {
|
if (chatEvent.isCancelled()) {
|
||||||
player.sendMessage(mcLocale.getString("mcPlayerListener.PartyChatOn"));
|
return true;
|
||||||
} else {
|
}
|
||||||
player.sendMessage(mcLocale.getString("mcPlayerListener.PartyChatOff"));
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
@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;
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -316,10 +316,8 @@ 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");
|
||||||
|
@ -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,18 +75,12 @@ 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()) {
|
else {
|
||||||
if (player != null && p != null) { //Is this even possible?
|
return 0;
|
||||||
if (PP.getParty().equals(Users.getProfile(p).getParty())) {
|
|
||||||
partyMembers++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return partyMembers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void informPartyMembers(Player player) {
|
private void informPartyMembers(Player player) {
|
||||||
@ -92,7 +88,9 @@ public class Party {
|
|||||||
|
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
for (Player p : getOnlineMembers(player)) {
|
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) {
|
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()) {
|
||||||
|
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()) {
|
for (Player p : plugin.getServer().getOnlinePlayers()) {
|
||||||
if (player != null && p != null) {
|
PlayerProfile PP = Users.getProfile(p);
|
||||||
if (inSameParty(player, p) && !p.getName().equals(player.getName())) {
|
|
||||||
|
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,7 +205,9 @@ public class Party {
|
|||||||
|
|
||||||
if (newOwner != null) {
|
if (newOwner != null) {
|
||||||
for (Player p : getOnlineMembers(newOwner)) {
|
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) {
|
if (player != null) {
|
||||||
for (Player p : getOnlineMembers(player)) {
|
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