Removed tab list stuff for friends.

Implemented rudimentary friends chat list.
removed unused code in server stuff.
Added null check for retrieving server statuses.
This commit is contained in:
Jonathan Williams 2014-09-24 01:31:56 -07:00
parent efb3c26115
commit d32085f05b
14 changed files with 92 additions and 90 deletions

View File

@ -34,6 +34,14 @@ public class ChildJsonMessage extends JsonMessage
return this;
}
@Override
public ChildJsonMessage bold()
{
super.bold();
return this;
}
@Override
public ChildJsonMessage click(String action, String value)

View File

@ -25,6 +25,13 @@ public class JsonMessage
return this;
}
public JsonMessage bold()
{
Builder.append(", bold:true");
return this;
}
public ChildJsonMessage extra(String text)
{
Builder.append(", \"extra\":[");

View File

@ -5,8 +5,8 @@ import java.util.Calendar;
public class UtilTime
{
public static final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss";
public static final String DATE_FORMAT_DAY = "yyyy-MM-dd";
public static final String DATE_FORMAT_NOW = "MM-dd-yyyy HH:mm:ss";
public static final String DATE_FORMAT_DAY = "MM-dd-yyyy";
public static String now()
{

View File

@ -1,47 +1,42 @@
package mineplex.core.friend;
import net.minecraft.server.v1_7_R4.PacketPlayOutPlayerInfo;
import java.util.Collections;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniClientPlugin;
import mineplex.core.account.event.RetrieveClientInformationEvent;
import mineplex.core.common.jsonchat.ChildJsonMessage;
import mineplex.core.common.jsonchat.JsonMessage;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.friend.command.AddFriend;
import mineplex.core.friend.command.DeleteFriend;
import mineplex.core.friend.data.FriendData;
import mineplex.core.friend.data.FriendRepository;
import mineplex.core.friend.ui.FriendTabList;
import mineplex.core.packethandler.IPacketHandler;
import mineplex.core.packethandler.PacketHandler;
import mineplex.core.packethandler.PacketInfo;
import mineplex.core.timing.TimingManager;
import mineplex.core.friend.data.FriendStatus;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
public class FriendManager extends MiniClientPlugin<FriendData> implements IPacketHandler
public class FriendManager extends MiniClientPlugin<FriendData>
{
private static FriendSorter _friendSorter = new FriendSorter();
private FriendRepository _repository;
private NautHashMap<Player, FriendTabList> _playerTabMap;
private boolean _sendingPackets = false;
public FriendManager(JavaPlugin plugin, PacketHandler packetHandler)
public FriendManager(JavaPlugin plugin)
{
super("Friends", plugin);
packetHandler.addPacketHandler(this);
_repository = new FriendRepository(plugin);
_playerTabMap = new NautHashMap<Player, FriendTabList>();
}
@Override
@ -65,31 +60,12 @@ public class FriendManager extends MiniClientPlugin<FriendData> implements IPack
{
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
public void updateTabLists(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC)
return;
_sendingPackets = true;
for (Player player : Bukkit.getOnlinePlayers())
{
if (!_playerTabMap.containsKey(player) || !_playerTabMap.get(player).shouldUpdate())
continue;
_playerTabMap.get(player).refreshForPlayer(player);
}
_sendingPackets = false;
}
@EventHandler
public void updateFriends(UpdateEvent event)
{
@ -106,7 +82,7 @@ public class FriendManager extends MiniClientPlugin<FriendData> implements IPack
{
public void run()
{
for (Player player : _playerTabMap.keySet())
for (Player player : Bukkit.getOnlinePlayers())
{
if (newData.containsKey(player.getUniqueId().toString()))
{
@ -116,38 +92,12 @@ public class FriendManager extends MiniClientPlugin<FriendData> implements IPack
{
Get(player).Friends.clear();
}
_playerTabMap.get(player).updateFriends(Get(player).Friends);
}
}
});
}
});
}
@EventHandler
public void addFriendTab(PlayerJoinEvent event)
{
_playerTabMap.put(event.getPlayer(), new FriendTabList(Get(event.getPlayer().getName()).Friends));
_playerTabMap.get(event.getPlayer()).refreshForPlayer(event.getPlayer());
}
@EventHandler
public void removeFriendTab(PlayerQuitEvent event)
{
_playerTabMap.remove(event.getPlayer());
}
public void handle(PacketInfo packetInfo)
{
if (packetInfo.isCancelled())
return;
if (packetInfo.getPacket() instanceof PacketPlayOutPlayerInfo)
{
packetInfo.setCancelled(_sendingPackets);
}
}
public void addFriend(final Player caller, final String name)
{
@ -186,4 +136,31 @@ public class FriendManager extends MiniClientPlugin<FriendData> implements IPack
}
});
}
public void showFriends(Player caller)
{
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 + "]======================");
for (FriendStatus friend : friendStatuses)
{
ChildJsonMessage message = new JsonMessage(friend.Name).color(friend.Online ? "gold" : "gray").extra(" - ").color("white");
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");
}
else
message.add("Last online : ").color("blue").add(UtilTime.when(friend.LastSeenOnline)).color("yellow").add(" - ").color("white");
message.add("Unfriend").color("red").bold().click("run_command", "/unfriend " + friend.Name).sendToPlayer(caller);
}
caller.sendMessage(C.cBlue + "=====================================================");
}
}

View File

@ -19,7 +19,9 @@ public class AddFriend extends CommandBase<FriendManager>
public void Execute(final Player caller, final String[] args)
{
if (args == null)
F.main(Plugin.GetName(), "You need to include a player's name.");
{
Plugin.showFriends(caller);
}
else
{
CommandCenter.GetClientManager().checkPlayerName(caller, args[0], new Callback<Boolean>()

View File

@ -14,12 +14,16 @@ import mineplex.core.database.column.ColumnVarChar;
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), mutual BOOL, PRIMARY KEY (id), INDEX uuidIndex (uuidSource, uuidTarget));";
private static String CREATE_FRIEND_TABLE = "CREATE TABLE IF NOT EXISTS accountFriend (id INT NOT NULL AUTO_INCREMENT, uuidSource VARCHAR(100), uuidTarget VARCHAR(100), mutual BOOL, PRIMARY KEY (id), UNIQUE INDEX uuidIndex (uuidSource, uuidTarget));";
private static String RETRIEVE_MULTIPLE_FRIEND_RECORDS = "SELECT uuidSource, 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 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 ADD_FRIEND_RECORD = "INSERT INTO accountFriend (uuidSource, uuidTarget) SELECT fA.uuid AS uuidSource, tA.uuid AS uuidTarget FROM accounts as fA LEFT JOIN accounts AS tA ON tA.name = ? WHERE fA.uuid = ?;";
private static String DELETE_FRIEND_RECORD = "DELETE aF FROM accountFriend AS aF INNER JOIN accounts ON accounts.name = ? WHERE uuidSource = ? AND uuidTarget = accounts.uuid;";
// Not mutual, need to drop accountFriend to recreate with constraint.
// On add record need to check for a reverse uuidsource/uuidtarget and set mutual
public FriendRepository(JavaPlugin plugin)
{
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
@ -73,7 +77,9 @@ public class FriendRepository extends RepositoryBase
friend.Name = resultSet.getString(2);
friend.Mutual = resultSet.getBoolean(3);
friend.ServerName = resultSet.getString(4);
friend.LastSeenOnline = resultSet.getLong(5);
friend.Online = !friend.ServerName.isEmpty();
friend.LastSeenOnline = resultSet.getTimestamp(5).getTime();
if (!friends.containsKey(uuidSource))
friends.put(uuidSource, new FriendData());

View File

@ -30,7 +30,7 @@ public class FriendTabList extends TabList
Collections.sort(friends, _friendSorter);
int row = 1;
for (int i = 0; i < 19; i++)
for (int i = 0; i < 16; i++)
{
if (i < friends.size())
{

View File

@ -13,6 +13,9 @@ import mineplex.core.common.util.NautHashMap;
public class TabList implements Listener
{
private static int MAX_SLOTS = 64;
private static int COLUMN_SLOTS = 16;
private static NautHashMap<Integer, String> _invisibleHolders = new NautHashMap<Integer, String>();
private NautHashMap<Integer, LineTracker> _tabSlots = new NautHashMap<Integer, LineTracker>();
@ -23,12 +26,12 @@ public class TabList implements Listener
static {
String spaces = "";
for (int i=0; i < 60; i++)
for (int i=0; i < MAX_SLOTS; i++)
{
int markerSymbol = i / 15;
int markerSymbol = i / COLUMN_SLOTS;
String symbol = null;
if (i % 15 == 0)
if (i % COLUMN_SLOTS == 0)
spaces = "";
else
spaces += " ";
@ -56,7 +59,7 @@ public class TabList implements Listener
public TabList()
{
for (Integer i=0; i < 60; i++)
for (Integer i=0; i < MAX_SLOTS; i++)
{
_tabSlots.put(i, new LineTracker(_invisibleHolders.get(i)));
}
@ -64,9 +67,9 @@ public class TabList implements Listener
public void set(int column, int row, String lineContent)
{
int index = row * 3 + column;
int index = row * 4 + column;
if (index >= 60)
if (index >= MAX_SLOTS)
return;
if (lineContent == null || lineContent.isEmpty())
@ -83,21 +86,21 @@ public class TabList implements Listener
{
EntityPlayer entityPlayer = ((CraftPlayer)player).getHandle();
int indexChanged = 60;
int indexChanged = MAX_SLOTS;
for (int i=0; i < 60; i++)
for (int i=0; i < MAX_SLOTS; i++)
{
if (indexChanged == 60 && _updatedSlots.contains(i))
if (indexChanged == MAX_SLOTS && _updatedSlots.contains(i))
{
indexChanged = i;
}
else if (indexChanged != 60 && !_updatedSlots.contains(i))
else if (indexChanged != MAX_SLOTS && !_updatedSlots.contains(i))
{
_tabSlots.get(i).removeLineForPlayer(entityPlayer);
}
}
for (int i=indexChanged; i < 60; i++)
for (int i=indexChanged; i < MAX_SLOTS; i++)
{
_tabSlots.get(i).displayLineToPlayer(entityPlayer);
}

View File

@ -12,7 +12,7 @@
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="true"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value=""/>
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_BUILDER_ENABLED" value="true"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${build_files}${BUILD_FILES}\common.xml"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${BUILD_FILES}\common.xml"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,auto,clean"/>
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${workspace_loc:/Mineplex.Hub}"/>

View File

@ -16,6 +16,7 @@ import mineplex.core.disguise.DisguiseManager;
import mineplex.core.donation.DonationManager;
import mineplex.core.elo.EloManager;
import mineplex.core.energy.Energy;
import mineplex.core.friend.FriendManager;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.logger.Logger;
import mineplex.core.memory.MemoryFix;
@ -131,6 +132,8 @@ 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);
//Updates
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Updater(this), 1, 1);
}

View File

@ -2,10 +2,8 @@ package mineplex.serverdata;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import redis.clients.jedis.Jedis;

View File

@ -17,9 +17,6 @@ import redis.clients.jedis.Transaction;
import redis.clients.jedis.Tuple;
import redis.clients.jedis.exceptions.JedisConnectionException;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
/**
* RedisServerRepository offers a Redis-based implementation of {@link ServerRepository}
* using a mixture of hash and JSON encoded storage.
@ -72,7 +69,12 @@ public class RedisServerRepository implements ServerRepository
for (Response<String> response : responses)
{
String serializedData = response.get();
servers.add(Utility.deserialize(serializedData, MinecraftServer.class));
MinecraftServer server = Utility.deserialize(serializedData, MinecraftServer.class);
if (server != null)
{
servers.add(server);
}
}
}
catch (JedisConnectionException exception)

View File

@ -1,10 +1,7 @@
package mineplex.serverdata;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

View File

@ -1,6 +1,5 @@
package mineplex.serverdata;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;