More work on FriendManager

This commit is contained in:
Jonathan Williams 2014-07-19 13:56:21 -07:00
parent 2ae3d89496
commit 1362deca59
2 changed files with 60 additions and 17 deletions

View File

@ -4,6 +4,7 @@ import net.minecraft.server.v1_7_R3.Packet;
import net.minecraft.server.v1_7_R3.PacketPlayOutPlayerInfo;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
@ -12,6 +13,7 @@ import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniClientPlugin;
import mineplex.core.account.event.RetrieveClientInformationEvent;
import mineplex.core.common.util.F;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.friend.command.AddFriend;
import mineplex.core.friend.command.DeleteFriend;
@ -21,6 +23,7 @@ import mineplex.core.friend.ui.FriendTabList;
import mineplex.core.packethandler.IPacketRunnable;
import mineplex.core.packethandler.PacketHandler;
import mineplex.core.packethandler.PacketVerifier;
import mineplex.core.timing.TimingManager;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
@ -55,9 +58,19 @@ public class FriendManager extends MiniClientPlugin<FriendData> implements IPack
}
@Override
protected void loadClientInformation(RetrieveClientInformationEvent event)
protected void loadClientInformation(final RetrieveClientInformationEvent event)
{
Set(event.getPlayerName(), _repository.loadClientInformation(event.getUniqueId()));
event.incrementProcessingCount();
Bukkit.getServer().getScheduler().runTaskAsynchronously(GetPlugin(), new Runnable()
{
public void run()
{
TimingManager.start(event.getPlayerName() + " friend Account call.");
Set(event.getPlayerName(), _repository.loadClientInformation(event.getUniqueId()));
TimingManager.stop(event.getPlayerName() + " friend Account call.");
event.decreaseProcessingCount();
}
});
}
@EventHandler
@ -77,9 +90,10 @@ public class FriendManager extends MiniClientPlugin<FriendData> implements IPack
_sendingPackets = false;
}
@EventHandler
public void updateFriends(UpdateEvent event)
{
if (event.getType() != UpdateType.SLOW)
if (event.getType() != UpdateType.SLOW || Bukkit.getOnlinePlayers().length == 0)
return;
Bukkit.getServer().getScheduler().runTaskAsynchronously(_plugin, new Runnable()
@ -94,11 +108,16 @@ public class FriendManager extends MiniClientPlugin<FriendData> implements IPack
{
for (Player player : _playerTabMap.keySet())
{
if (newData.containsKey(player.getName()))
if (newData.containsKey(player.getUniqueId().toString()))
{
_playerTabMap.get(player).updateFriends(newData.get(player.getName()).Friends);
Get(player).Friends = newData.get(player.getName()).Friends;
Get(player).Friends = newData.get(player.getUniqueId().toString()).Friends;
}
else
{
Get(player).Friends.clear();
}
_playerTabMap.get(player).updateFriends(Get(player).Friends);
}
}
});
@ -137,6 +156,14 @@ public class FriendManager extends MiniClientPlugin<FriendData> implements IPack
public void run()
{
_repository.addFriend(caller.getUniqueId().toString(), name);
Bukkit.getServer().getScheduler().runTask(_plugin, new Runnable()
{
public void run()
{
caller.sendMessage(F.main(GetName(), "Added " + ChatColor.GREEN + name + " to your friends list!"));
}
});
}
});
}
@ -148,6 +175,14 @@ public class FriendManager extends MiniClientPlugin<FriendData> implements IPack
public void run()
{
_repository.removeFriend(caller.getUniqueId().toString(), name);
Bukkit.getServer().getScheduler().runTask(_plugin, new Runnable()
{
public void run()
{
caller.sendMessage(F.main(GetName(), "Deleted " + ChatColor.GREEN + name + " from your friends list!"));
}
});
}
});
}

View File

@ -18,13 +18,11 @@ public class FriendTabList extends TabList
{
super();
set(0, 0, ChatColor.GOLD + " Name");
set(1, 0, ChatColor.GOLD + " Location");
set(2, 0, ChatColor.GOLD + " Status");
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);
System.out.println("created friend tablist with " + friends.size() + " friends");
}
public void updateFriends(List<FriendStatus> friends)
@ -32,14 +30,24 @@ public class FriendTabList extends TabList
Collections.sort(friends, _friendSorter);
int row = 1;
for (int i = 0; i < 20 && i < friends.size(); i++)
for (int i = 0; i < 19; i++)
{
FriendStatus status = friends.get(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) + ""));
System.out.println("Added friend " + status.Name + " to tablist");
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++;
}
}
}