Fixed up friends.

This commit is contained in:
Jonathan Williams 2014-10-03 01:50:23 -07:00
parent 9b2a2cbbd6
commit c641eab3c7
13 changed files with 251 additions and 129 deletions

View File

@ -30,9 +30,6 @@ public class MysqlAccountRepository extends RepositoryBase
int affectedRows = executeUpdate(ACCOUNT_LOGIN_UPDATE, new ColumnVarChar("uuid", 100, uuid), new ColumnVarChar("name", 40, name), new ColumnVarChar("uuid", 100, uuid));
if (affectedRows == 0)
{
executeUpdate(ACCOUNT_LOGIN_NEW, new ColumnVarChar("uuid", 100, uuid), new ColumnVarChar("name", 40, name));
System.out.println("Executed LOGIN_NEW");
}
}
}

View File

@ -1,6 +1,7 @@
package mineplex.core.friend;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.bukkit.Bukkit;
@ -23,6 +24,7 @@ import mineplex.core.friend.command.DeleteFriend;
import mineplex.core.friend.data.FriendData;
import mineplex.core.friend.data.FriendRepository;
import mineplex.core.friend.data.FriendStatus;
import mineplex.core.preferences.PreferencesManager;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
@ -30,12 +32,14 @@ public class FriendManager extends MiniClientPlugin<FriendData>
{
private static FriendSorter _friendSorter = new FriendSorter();
private PreferencesManager _preferenceManager;
private FriendRepository _repository;
public FriendManager(JavaPlugin plugin)
public FriendManager(JavaPlugin plugin, PreferencesManager preferences)
{
super("Friends", plugin);
_preferenceManager = preferences;
_repository = new FriendRepository(plugin);
}
@ -72,11 +76,13 @@ public class FriendManager extends MiniClientPlugin<FriendData>
if (event.getType() != UpdateType.SLOW || Bukkit.getOnlinePlayers().size() == 0)
return;
final Player[] onlinePlayers = UtilServer.getPlayers();
Bukkit.getServer().getScheduler().runTaskAsynchronously(_plugin, new Runnable()
{
public void run()
{
final NautHashMap<String, FriendData> newData = _repository.getFriendsForAll(UtilServer.getPlayers());
final NautHashMap<String, FriendData> newData = _repository.getFriendsForAll(onlinePlayers);
Bukkit.getServer().getScheduler().runTask(_plugin, new Runnable()
{
@ -101,9 +107,63 @@ public class FriendManager extends MiniClientPlugin<FriendData>
public void addFriend(final Player caller, final String name)
{
boolean update = false;
for (FriendStatus status : Get(caller).Friends)
{
if (status.Name.equalsIgnoreCase(name))
{
if (status.Status == FriendStatusType.Pending || status.Status == FriendStatusType.Blocked)
{
update = true;
break;
}
else if (status.Status == FriendStatusType.Denied)
{
caller.sendMessage(F.main(GetName(), ChatColor.GREEN + name + ChatColor.GRAY + " has denied your friend request."));
return;
}
else if (status.Status == FriendStatusType.Accepted)
{
caller.sendMessage(F.main(GetName(), "You are already friends with " + ChatColor.GREEN + name));
return;
}
else if (status.Status == FriendStatusType.Sent)
{
caller.sendMessage(F.main(GetName(), ChatColor.GREEN + name + ChatColor.GRAY + " has yet to respond to your friend request."));
return;
}
}
}
final boolean updateFinal = update;
Bukkit.getServer().getScheduler().runTaskAsynchronously(GetPlugin(), new Runnable()
{
public void run()
{
if (updateFinal)
{
_repository.updateFriend(caller.getName(), name, "Accepted");
_repository.updateFriend(name, caller.getName(), "Accepted");
Bukkit.getServer().getScheduler().runTask(_plugin, new Runnable()
{
public void run()
{
for (Iterator<FriendStatus> statusIterator = Get(caller).Friends.iterator(); statusIterator.hasNext();)
{
FriendStatus status = statusIterator.next();
if (status.Name.equalsIgnoreCase(name))
{
status.Status = FriendStatusType.Accepted;
break;
}
}
}
});
}
else
{
_repository.addFriend(caller, name);
@ -111,7 +171,28 @@ public class FriendManager extends MiniClientPlugin<FriendData>
{
public void run()
{
caller.sendMessage(F.main(GetName(), "Added " + ChatColor.GREEN + name + " to your friends list!"));
for (Iterator<FriendStatus> statusIterator = Get(caller).Friends.iterator(); statusIterator.hasNext();)
{
FriendStatus status = statusIterator.next();
if (status.Name.equalsIgnoreCase(name))
{
status.Status = FriendStatusType.Sent;
break;
}
}
}
});
}
Bukkit.getServer().getScheduler().runTask(_plugin, new Runnable()
{
public void run()
{
if (updateFinal)
caller.sendMessage(F.main(GetName(), "You and " + ChatColor.GREEN + name + ChatColor.GRAY + " are now friends!"));
else
caller.sendMessage(F.main(GetName(), "Added " + ChatColor.GREEN + name + ChatColor.GRAY + " to your friends list!"));
}
});
}
@ -120,17 +201,54 @@ public class FriendManager extends MiniClientPlugin<FriendData>
public void removeFriend(final Player caller, final String name)
{
boolean delete = false;
for (Iterator<FriendStatus> statusIterator = Get(caller).Friends.iterator(); statusIterator.hasNext();)
{
FriendStatus status = statusIterator.next();
if (status.Name.equalsIgnoreCase(name))
{
if (status.Status == FriendStatusType.Sent)
{
delete = true;
statusIterator.remove();
}
break;
}
}
final boolean deleteFinal = delete;
Bukkit.getServer().getScheduler().runTaskAsynchronously(GetPlugin(), new Runnable()
{
public void run()
{
_repository.removeFriend(caller.getUniqueId().toString(), name);
if (deleteFinal)
{
_repository.removeFriend(caller.getName(), name);
}
else
{
_repository.updateFriend(caller.getName(), name, "Blocked");
_repository.updateFriend(name, caller.getName(), "Denied");
}
Bukkit.getServer().getScheduler().runTask(_plugin, new Runnable()
{
public void run()
{
caller.sendMessage(F.main(GetName(), "Deleted " + ChatColor.GREEN + name + " from your friends list!"));
for (Iterator<FriendStatus> statusIterator = Get(caller).Friends.iterator(); statusIterator.hasNext();)
{
FriendStatus status = statusIterator.next();
if (status.Name.equalsIgnoreCase(name))
{
status.Status = FriendStatusType.Blocked;
break;
}
}
caller.sendMessage(F.main(GetName(), "Deleted " + ChatColor.GREEN + name + ChatColor.GRAY + " from your friends list!"));
}
});
}
@ -139,28 +257,55 @@ public class FriendManager extends MiniClientPlugin<FriendData>
public void showFriends(Player caller)
{
boolean gotAFriend = false;
List<FriendStatus> friendStatuses = Get(caller).Friends;
Collections.sort(friendStatuses, _friendSorter);
caller.sendMessage(C.cBlue + "======================[" + ChatColor.RESET + C.cYellow + C.Bold + "Friends" + ChatColor.RESET + C.cBlue + "]======================");
caller.sendMessage(C.cAqua + C.Strike + "======================[" + ChatColor.RESET + C.cWhite + C.Bold + "Friends" + ChatColor.RESET + C.cAqua + C.Strike + "]======================");
for (FriendStatus friend : friendStatuses)
{
ChildJsonMessage message = new JsonMessage(friend.Name).color(friend.Online ? "gold" : "gray").extra(" - ").color("white");
if (friend.Status == FriendStatusType.Blocked || friend.Status == FriendStatusType.Denied)
continue;
if (!_preferenceManager.Get(caller).PendingFriendRequests && friend.Status == FriendStatusType.Pending)
continue;
gotAFriend = true;
ChildJsonMessage message = new JsonMessage(friend.Name).color(friend.Online ? "green" : "gray").extra(" - ").color("white");
if (friend.Status == FriendStatusType.Accepted)
{
if (friend.Online)
{
if (friend.Mutual)
message.add(friend.ServerName + " Connect").color("green").bold().click("run_command", "/server " + friend.ServerName).add(" - ").color("white");
else
message.add("Friend request pending").color("yellow").add(" - ").color("white");
message.add(friend.ServerName).color("dark_green").add(" - ").color("white");
message.add("Teleport").color("green").bold().click("run_command", "/server " + friend.ServerName).hover("show_text", "Change to " + friend.Name + "'s server.").add(" - ").color("white");
}
else
message.add("Last online : ").color("blue").add(UtilTime.when(friend.LastSeenOnline)).color("yellow").add(" - ").color("white");
message.add("Last online : ").color("gray").add(UtilTime.MakeStr(friend.LastSeenOnline)).color("gray").add(" - ").color("white");
message.add("Unfriend").color("red").bold().click("run_command", "/unfriend " + friend.Name).sendToPlayer(caller);
message.add("Unfriend").color("red").bold().click("run_command", "/unfriend " + friend.Name).hover("show_text", "Remove " + friend.Name + " from your friends list.").sendToPlayer(caller);
}
else if (friend.Status == FriendStatusType.Pending)
{
message.add("Friendship Pending").color("gray").add(" - ").color("white");
message.add("Accept").color("green").bold().click("run_command", "/friend " + friend.Name).hover("show_text", "Accept " + friend.Name + "'s friend request.").add(" - ").color("white");
message.add("Deny").color("red").bold().click("run_command", "/unfriend " + friend.Name).hover("show_text", "Deny " + friend.Name + "'s friend request.").sendToPlayer(caller);
}
else if (friend.Status == FriendStatusType.Sent)
{
message.add("Friendship Requested").color("gray").add(" - ").color("white");
message.add("Cancel").color("red").bold().click("run_command", "/unfriend " + friend.Name).hover("show_text", "Cancel friend request to " + friend.Name).sendToPlayer(caller);
}
}
caller.sendMessage(C.cBlue + "=====================================================");
if (!gotAFriend)
{
caller.sendMessage(C.cGray + "You don't have any friends. Type " + ChatColor.GREEN + "/friend name" + ChatColor.GRAY + " to add someone!");
}
caller.sendMessage(C.cAqua + C.Strike + "=====================================================");
}
}

View File

@ -10,33 +10,33 @@ public class FriendSorter implements Comparator<FriendStatus>
{
if (a.Online && !b.Online)
{
return -1;
return 1;
}
if (b.Online && !a.Online)
{
return 1;
return -1;
}
// If online we sort by mutual
if (a.Online && b.Online)
{
if (a.Mutual && !b.Mutual)
return -1;
else if (b.Mutual && !a.Mutual)
if (a.Status == FriendStatusType.Accepted && b.Status != FriendStatusType.Accepted)
return 1;
else if (b.Status == FriendStatusType.Accepted && a.Status != FriendStatusType.Accepted)
return -1;
if (a.Name.compareTo(b.Name) > 0)
return -1;
else if (b.Name.compareTo(a.Name) > 0)
return 1;
else if (b.Name.compareTo(a.Name) > 0)
return -1;
}
if (a.LastSeenOnline < b.LastSeenOnline)
return -1;
return 1;
if (b.LastSeenOnline < a.LastSeenOnline)
return 1;
return -1;
return 0;
}

View File

@ -0,0 +1,10 @@
package mineplex.core.friend;
public enum FriendStatusType
{
Sent,
Pending,
Accepted,
Denied,
Blocked
}

View File

@ -12,7 +12,7 @@ public class AddFriend extends CommandBase<FriendManager>
{
public AddFriend(FriendManager plugin)
{
super(plugin, Rank.ALL, "friend");
super(plugin, Rank.ALL, "friend", "f");
}
@Override

View File

@ -11,16 +11,16 @@ import mineplex.core.common.util.NautHashMap;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.core.friend.FriendStatusType;
public class FriendRepository extends RepositoryBase
{
private static String CREATE_FRIEND_TABLE = "CREATE TABLE IF NOT EXISTS accountFriend (id INT NOT NULL AUTO_INCREMENT, uuidSource VARCHAR(100), uuidTarget VARCHAR(100), status VARCHAR(100), PRIMARY KEY (id), UNIQUE INDEX uuidIndex (uuidSource, uuidTarget));";
private static String RETRIEVE_MULTIPLE_FRIEND_RECORDS = "SELECT uuidSource, tA.Name, status, serverName, tA.lastLogin FROM accountFriend INNER Join accounts AS fA ON fA.uuid = uuidSource INNER JOIN accounts AS tA ON tA.uuid = uuidTarget LEFT JOIN playerMap ON tA.name = playerName WHERE uuidSource IN ";
private static String RETRIEVE_FRIEND_RECORDS = "SELECT tA.Name, mutual, serverName, tA.lastLogin FROM accountFriend INNER Join accounts AS fA ON fA.uuid = uuidSource INNER JOIN accounts AS tA ON tA.uuid = uuidTarget LEFT JOIN playerMap ON tA.name = playerName WHERE uuidSource = ?;";
private static String RETRIEVE_OTHER_FRIEND_RECORDS_BY_NAME = "SELECT tA.Name, mutual, serverName, tA.lastLogin FROM accountFriend INNER Join accounts AS fA ON fA.uuid = uuidSource INNER JOIN accounts AS tA ON tA.uuid = uuidTarget LEFT JOIN playerMap ON tA.name = playerName WHERE name = ?;";
private static String ADD_FRIEND_RECORD = "INSERT INTO accountFriend (uuidSource, uuidTarget, status) SELECT fA.uuid AS uuidSource, tA.uuid AS uuidTarget, 'Pending' FROM accounts as fA LEFT JOIN accounts AS tA ON tA.name = ? WHERE fA.name = ?;";
private static String UPDATE_MUTUAL_RECORD = "UPDATE aF SET status = ? FROM accountFriend AS aF INNER JOIN accounts as fA LEFT JOIN accounts AS tA ON tA.name = ? WHERE fA.name = ?;";
private static String DELETE_FRIEND_RECORD = "DELETE aF FROM accountFriend AS aF INNER JOIN accounts ON accounts.name = ? WHERE uuidSource = ? AND uuidTarget = accounts.uuid;";
private static String RETRIEVE_MULTIPLE_FRIEND_RECORDS = "SELECT uuidSource, tA.Name, status, serverName, tA.lastLogin, now() FROM accountFriend INNER Join accounts AS fA ON fA.uuid = uuidSource INNER JOIN accounts AS tA ON tA.uuid = uuidTarget LEFT JOIN playerMap ON tA.name = playerName WHERE uuidSource IN ";
private static String RETRIEVE_FRIEND_RECORDS = "SELECT tA.Name, status, serverName, tA.lastLogin, now() FROM accountFriend INNER Join accounts AS fA ON fA.uuid = uuidSource INNER JOIN accounts AS tA ON tA.uuid = uuidTarget LEFT JOIN playerMap ON tA.name = playerName WHERE uuidSource = ?;";
private static String ADD_FRIEND_RECORD = "INSERT INTO accountFriend (uuidSource, uuidTarget, status) SELECT fA.uuid AS uuidSource, tA.uuid AS uuidTarget, ? FROM accounts as fA LEFT JOIN accounts AS tA ON tA.name = ? WHERE fA.name = ?;";
private static String UPDATE_MUTUAL_RECORD = "UPDATE accountFriend AS aF INNER JOIN accounts as fA ON aF.uuidSource = fA.uuid INNER JOIN accounts AS tA ON aF.uuidTarget = tA.uuid SET aF.status = ? WHERE tA.name = ? AND fA.name = ?;";
private static String DELETE_FRIEND_RECORD = "DELETE aF FROM accountFriend AS aF INNER JOIN accounts as fA ON aF.uuidSource = fA.uuid INNER JOIN accounts AS tA ON aF.uuidTarget = tA.uuid WHERE fA.name = ? AND tA.name = ?;";
// Not mutual, need to drop accountFriend to recreate with constraint.
@ -44,22 +44,17 @@ public class FriendRepository extends RepositoryBase
public boolean addFriend(final Player caller, String name)
{
int rowsAffected = executeUpdate(ADD_FRIEND_RECORD, new ColumnVarChar("name", 100, name), new ColumnVarChar("name", 100, caller.getName()));
int rowsAffected = executeUpdate(ADD_FRIEND_RECORD, new ColumnVarChar("status", 100, "Sent"), new ColumnVarChar("name", 100, name), new ColumnVarChar("name", 100, caller.getName()));
if (rowsAffected > 0)
return executeUpdate(ADD_FRIEND_RECORD, new ColumnVarChar("name", 100, caller.getName()), new ColumnVarChar("uuid", 100, name)) > 0;
return executeUpdate(ADD_FRIEND_RECORD, new ColumnVarChar("status", 100, "Pending"), new ColumnVarChar("name", 100, caller.getName()), new ColumnVarChar("uuid", 100, name)) > 0;
return false;
}
public boolean updateFriend(Player caller, String name, String status)
public boolean updateFriend(String caller, String name, String status)
{
int rowsAffected = executeUpdate(UPDATE_MUTUAL_RECORD, new ColumnVarChar("status", 100, status), new ColumnVarChar("name", 100, name), new ColumnVarChar("name", 100, caller.getName()));
if (rowsAffected > 0)
return executeUpdate(UPDATE_MUTUAL_RECORD, new ColumnVarChar("status", 100, status), new ColumnVarChar("name", 100, caller.getName()), new ColumnVarChar("uuid", 100, name)) > 0;
return false;
return executeUpdate(UPDATE_MUTUAL_RECORD, new ColumnVarChar("status", 100, status), new ColumnVarChar("uuid", 100, name), new ColumnVarChar("name", 100, caller)) > 0;
}
public boolean removeFriend(String caller, String name)
@ -97,11 +92,11 @@ public class FriendRepository extends RepositoryBase
String uuidSource = resultSet.getString(1);
friend.Name = resultSet.getString(2);
friend.Mutual = resultSet.getBoolean(3);
friend.Status = Enum.valueOf(FriendStatusType.class, resultSet.getString(3));
friend.ServerName = resultSet.getString(4);
friend.Online = !friend.ServerName.isEmpty();
friend.Online = !(friend.ServerName == null || friend.ServerName.isEmpty());
friend.LastSeenOnline = resultSet.getTimestamp(5).getTime();
friend.LastSeenOnline = resultSet.getTimestamp(6).getTime() - resultSet.getTimestamp(5).getTime();
if (!friends.containsKey(uuidSource))
friends.put(uuidSource, new FriendData());
@ -127,9 +122,9 @@ public class FriendRepository extends RepositoryBase
FriendStatus friend = new FriendStatus();
friend.Name = resultSet.getString(1);
friend.Mutual = resultSet.getBoolean(2);
friend.Status = Enum.valueOf(FriendStatusType.class, resultSet.getString(2));
friend.ServerName = resultSet.getString(3);
friend.LastSeenOnline = resultSet.getLong(4);
friend.LastSeenOnline = resultSet.getTimestamp(5).getTime() - resultSet.getTimestamp(5).getTime();
friendData.Friends.add(friend);
}

View File

@ -1,10 +1,12 @@
package mineplex.core.friend.data;
import mineplex.core.friend.FriendStatusType;
public class FriendStatus
{
public String Name;
public String ServerName;
public boolean Online;
public long LastSeenOnline;
public boolean Mutual;
public FriendStatusType Status;
}

View File

@ -1,54 +0,0 @@
package mineplex.core.friend.ui;
import java.util.Collections;
import java.util.List;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.core.friend.FriendSorter;
import mineplex.core.friend.data.FriendStatus;
import org.bukkit.ChatColor;
public class FriendTabList extends TabList
{
private static FriendSorter _friendSorter = new FriendSorter();
public FriendTabList(List<FriendStatus> friends)
{
super();
set(0, 0, ChatColor.GOLD + "" + ChatColor.BOLD + " Name");
set(1, 0, ChatColor.GOLD + "" + ChatColor.BOLD + " Location");
set(2, 0, ChatColor.GOLD + "" + ChatColor.BOLD + " Status");
updateFriends(friends);
}
public void updateFriends(List<FriendStatus> friends)
{
Collections.sort(friends, _friendSorter);
int row = 1;
for (int i = 0; i < 16; i++)
{
if (i < friends.size())
{
FriendStatus status = friends.get(i);
set(0, row, (status.Mutual ? ChatColor.GREEN : ChatColor.YELLOW) + status.Name);
set(1, row, status.Mutual ? ChatColor.GREEN + status.ServerName : ChatColor.YELLOW + "Unknown");
set(2, row, (status.Mutual ? ChatColor.GREEN : ChatColor.YELLOW) + (status.Online ? "Online" : UtilTime.convert(status.LastSeenOnline, 2, TimeUnit.MINUTES) + ""));
}
else
{
set(0, row, null);
set(1, row, null);
set(2, row, null);
}
row++;
}
}
}

View File

@ -17,8 +17,8 @@ public class PreferencesRepository extends RepositoryBase
{
private static String CREATE_ACCOUNT_TABLE = "CREATE TABLE IF NOT EXISTS accountPreferences (id INT NOT NULL AUTO_INCREMENT, uuid VARCHAR(256), games BOOL NOT NULL DEFAULT 1, visibility BOOL NOT NULL DEFAULT 1, showChat BOOL NOT NULL DEFAULT 1, friendChat BOOL NOT NULL DEFAULT 1, privateMessaging BOOL NOT NULL DEFAULT 1, partyRequests BOOL NOT NULL DEFAULT 0, invisibility BOOL NOT NULL DEFAULT 0, forcefield BOOL NOT NULL DEFAULT 0, showMacReports BOOL NOT NULL DEFAULT 0, ignoreVelocity BOOL NOT NULL DEFAULT 0, PRIMARY KEY (id), UNIQUE INDEX uuid_index (uuid));";
private static String INSERT_ACCOUNT = "INSERT INTO accountPreferences (uuid) VALUES (?) ON DUPLICATE KEY UPDATE uuid=uuid;";
private static String RETRIEVE_ACCOUNT_PREFERENCES = "SELECT games, visibility, showChat, friendChat, privateMessaging, partyRequests, invisibility, forcefield, showMacReports, ignoreVelocity FROM accountPreferences WHERE uuid = ?;";
private static String UPDATE_ACCOUNT_PREFERENCES = "UPDATE accountPreferences SET games = ?, visibility = ?, showChat = ?, friendChat = ?, privateMessaging = ?, partyRequests = ?, invisibility = ?, forcefield = ?, showMacReports = ?, ignoreVelocity = ? WHERE uuid=?;";
private static String RETRIEVE_ACCOUNT_PREFERENCES = "SELECT games, visibility, showChat, friendChat, privateMessaging, partyRequests, invisibility, forcefield, showMacReports, ignoreVelocity, pendingFriendRequests FROM accountPreferences WHERE uuid = ?;";
private static String UPDATE_ACCOUNT_PREFERENCES = "UPDATE accountPreferences SET games = ?, visibility = ?, showChat = ?, friendChat = ?, privateMessaging = ?, partyRequests = ?, invisibility = ?, forcefield = ?, showMacReports = ?, ignoreVelocity = ?, pendingFriendRequests = ? WHERE uuid=?;";
public PreferencesRepository(JavaPlugin plugin, String connectionString)
{
@ -56,7 +56,8 @@ public class PreferencesRepository extends RepositoryBase
preparedStatement.setBoolean(8, entry.getValue().HubForcefield);
preparedStatement.setBoolean(9, entry.getValue().ShowMacReports);
preparedStatement.setBoolean(10, entry.getValue().IgnoreVelocity);
preparedStatement.setString(11, entry.getKey());
preparedStatement.setBoolean(11, entry.getValue().PendingFriendRequests);
preparedStatement.setString(12, entry.getKey());
preparedStatement.addBatch();
}
@ -107,6 +108,7 @@ public class PreferencesRepository extends RepositoryBase
preferences.HubForcefield = resultSet.getBoolean(8);
preferences.ShowMacReports = resultSet.getBoolean(9);
preferences.IgnoreVelocity = resultSet.getBoolean(10);
preferences.PendingFriendRequests = resultSet.getBoolean(11);
}
}
}, new ColumnVarChar("uuid", 100, uuid.toString()));

View File

@ -13,4 +13,5 @@ public class UserPreferences
public boolean HubForcefield = false;
public boolean ShowMacReports = false;
public boolean IgnoreVelocity = false;
public boolean PendingFriendRequests = true;
}

View File

@ -20,6 +20,7 @@ public class PreferencesPage extends ShopPageBase<PreferencesManager, Preference
private IButton _toggleChat;
private IButton _togglePrivateChat;
private IButton _toggleHubPartyRequests;
private IButton _togglePendingFriendRequests;
private IButton _toggleHubInvisibility;
private IButton _toggleHubForcefield;
private IButton _toggleHubIgnoreVelocity;
@ -30,6 +31,7 @@ public class PreferencesPage extends ShopPageBase<PreferencesManager, Preference
private boolean _hubChatToggled;
private boolean _hubPrivateChatToggled;
private boolean _hubPartyRequestsToggled;
private boolean _pendingFriendRequestsToggled;
private boolean _hubInvisibilityToggled;
private boolean _hubForcefieldToggled;
private boolean _macReportsToggled;
@ -120,6 +122,21 @@ public class PreferencesPage extends ShopPageBase<PreferencesManager, Preference
}
};
_togglePendingFriendRequests = new IButton()
{
@Override
public void ClickedLeft(Player player)
{
togglePendingFriendRequests(player);
}
@Override
public void ClickedRight(Player player)
{
togglePendingFriendRequests(player);
}
};
_toggleHubInvisibility = new IButton()
{
@Override
@ -218,6 +235,13 @@ public class PreferencesPage extends ShopPageBase<PreferencesManager, Preference
BuildPage();
}
protected void togglePendingFriendRequests(org.bukkit.entity.Player player)
{
Plugin.Get(player).PendingFriendRequests = !Plugin.Get(player).PendingFriendRequests;
_pendingFriendRequestsToggled = !_pendingFriendRequestsToggled;
BuildPage();
}
protected void togglePrivateChat(org.bukkit.entity.Player player)
{
Plugin.Get(player).PrivateMessaging = !Plugin.Get(player).PrivateMessaging;
@ -276,12 +300,7 @@ public class PreferencesPage extends ShopPageBase<PreferencesManager, Preference
clear();
UserPreferences userPreferences = Plugin.Get(Player);
int index = 18;
if (ClientManager.Get(Player).GetRank().Has(Rank.MODERATOR) || ClientManager.Get(Player).GetRank() == Rank.YOUTUBE)
{
index = 9;
}
int index = 9;
buildPreference(index, Material.FIREBALL, "Hub Stacker", userPreferences.HubGames, _toggleHubGames);
index += 2;
@ -293,27 +312,29 @@ public class PreferencesPage extends ShopPageBase<PreferencesManager, Preference
index += 2;
buildPreference(index, Material.SKULL_ITEM, (byte)3, "Hub Party Requests", userPreferences.PartyRequests, _toggleHubPartyRequests);
buildPreference(40, Material.RED_ROSE, "Show Pending Friend Requests", userPreferences.PendingFriendRequests, _togglePendingFriendRequests);
if (ClientManager.Get(Player).GetRank() == Rank.YOUTUBE)
{
buildPreference(39, Material.NETHER_STAR, "Hub Invisibility", userPreferences.Invisibility, _toggleHubInvisibility);
buildPreference(41, Material.SLIME_BALL, "Hub Forcefield", userPreferences.HubForcefield, _toggleHubForcefield);
buildPreference(38, Material.NETHER_STAR, "Hub Invisibility", userPreferences.Invisibility, _toggleHubInvisibility);
buildPreference(42, Material.SLIME_BALL, "Hub Forcefield", userPreferences.HubForcefield, _toggleHubForcefield);
}
if (ClientManager.Get(Player).GetRank().Has(Rank.ADMIN))
{
buildPreference(37, Material.NETHER_STAR, "Hub Invisibility", userPreferences.Invisibility, _toggleHubInvisibility);
buildPreference(39, Material.SLIME_BALL, "Hub Forcefield", userPreferences.HubForcefield, _toggleHubForcefield);
buildPreference(41, Material.PAPER, "Mac Reports", userPreferences.ShowMacReports, _toggleMacReports);
buildPreference(43, Material.SADDLE, "Hub Ignore Velocity", userPreferences.IgnoreVelocity, _toggleHubIgnoreVelocity);
buildPreference(36, Material.NETHER_STAR, "Hub Invisibility", userPreferences.Invisibility, _toggleHubInvisibility);
buildPreference(38, Material.SLIME_BALL, "Hub Forcefield", userPreferences.HubForcefield, _toggleHubForcefield);
buildPreference(42, Material.PAPER, "Mac Reports", userPreferences.ShowMacReports, _toggleMacReports);
buildPreference(44, Material.SADDLE, "Hub Ignore Velocity", userPreferences.IgnoreVelocity, _toggleHubIgnoreVelocity);
}
else if (ClientManager.Get(Player).GetRank().Has(Rank.MODERATOR))
{
buildPreference(39, Material.PAPER, "Mac Reports", userPreferences.ShowMacReports, _toggleMacReports);
buildPreference(41, Material.SADDLE, "Hub Ignore Velocity", userPreferences.IgnoreVelocity, _toggleHubIgnoreVelocity);
buildPreference(38, Material.PAPER, "Mac Reports", userPreferences.ShowMacReports, _toggleMacReports);
buildPreference(42, Material.SADDLE, "Hub Ignore Velocity", userPreferences.IgnoreVelocity, _toggleHubIgnoreVelocity);
}
}
public boolean preferencesChanged()
{
return _hubGamesToggled || _hubPlayersToggled || _hubChatToggled || _hubPrivateChatToggled || _hubPartyRequestsToggled || _hubInvisibilityToggled || _hubForcefieldToggled;
return _hubGamesToggled || _hubPlayersToggled || _hubChatToggled || _hubPrivateChatToggled || _hubPartyRequestsToggled || _hubInvisibilityToggled || _hubForcefieldToggled || _pendingFriendRequestsToggled;
}
}

View File

@ -132,7 +132,7 @@ public class Hub extends JavaPlugin implements IRelation
new ClassCombatShop(shopManager, clientManager, donationManager, "Knight", classManager.GetClass("Knight"));
new ClassCombatShop(shopManager, clientManager, donationManager, "Assassin", classManager.GetClass("Assassin"));
//new FriendManager(this);
new FriendManager(this, preferenceManager);
//Updates
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Updater(this), 1, 1);

View File

@ -10,8 +10,8 @@ import java.io.InputStreamReader;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import net.minecraft.server.v1_7_R4.MinecraftServer;
import net.minecraft.server.v1_7_R4.MinecraftServer;
import mineplex.core.CustomTagFix;
import mineplex.core.account.CoreClientManager;
import mineplex.core.antihack.AntiHack;
@ -25,6 +25,7 @@ import mineplex.core.cosmetic.CosmeticManager;
import mineplex.core.creature.Creature;
import mineplex.core.disguise.DisguiseManager;
import mineplex.core.donation.DonationManager;
import mineplex.core.friend.FriendManager;
import mineplex.core.gadget.GadgetManager;
import mineplex.core.inventory.InventoryManager;
import mineplex.core.itemstack.ItemStackFactory;
@ -125,6 +126,8 @@ public class Arcade extends JavaPlugin
new MemoryFix(this);
new FriendManager(this, preferenceManager);
//Updates
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Updater(this), 1, 1);