Merge pull request #110 in MIN/mineplex from feature/MasterBuilder-Unban to develop

* commit 'f83016e0074ce810f727276a0feb127ecd69098f':
  Also really quickly fixed the Invisibility in lobby bug (hopefully)
  Removed a weird query :/
  Finished up the Unban feature...
  Added a feature to unban clients across the network But there still a bug when you type a username of a none registered member. Will fix ASAP - likely after Mineware
This commit is contained in:
Shaun Bennett 2015-12-31 11:27:08 -06:00
commit 456b0dbeb7
4 changed files with 217 additions and 12 deletions

View File

@ -15,6 +15,7 @@ import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilServer;
import mineplex.core.stats.command.GiveStatCommand;
import mineplex.core.stats.command.MasterBuilderUnban;
import mineplex.core.stats.command.TimeCommand;
import mineplex.core.stats.event.StatChangeEvent;
@ -26,6 +27,8 @@ public class StatsManager extends MiniDbClientPlugin<PlayerStats>
private NautHashMap<String, Integer> _stats = new NautHashMap<String, Integer>();
private NautHashMap<Player, NautHashMap<String, Long>> _statUploadQueue = new NautHashMap<Player, NautHashMap<String, Long>>();
private NautHashMap<Player, NautHashMap<String, Long>> _statUploadQueueOverRidable = new NautHashMap<Player, NautHashMap<String, Long>>();
private Runnable _saveRunnable;
public StatsManager(JavaPlugin plugin, CoreClientManager clientManager)
@ -41,6 +44,7 @@ public class StatsManager extends MiniDbClientPlugin<PlayerStats>
public void run()
{
saveStats();
overRidableSaveStats();
}
};
@ -81,6 +85,11 @@ public class StatsManager extends MiniDbClientPlugin<PlayerStats>
}
public void incrementStat(final Player player, final String statName, final long value)
{
incrementStat(player, statName, value, false);
}
public void incrementStat(final Player player, final String statName, final long value, boolean overRide)
{
if (value <= 0)
return;
@ -96,11 +105,80 @@ public class StatsManager extends MiniDbClientPlugin<PlayerStats>
@Override
public void run()
{
addToQueue(statName, player, value);
if(overRide)
{
addToOverRidableQueue(statName, player, value);
}
else
{
addToQueue(statName, player, value);
}
}
});
}
private void addToOverRidableQueue(String statName, Player player, long value)
{
synchronized (_statSync)
{
if (!_statUploadQueueOverRidable.containsKey(player))
_statUploadQueueOverRidable.put(player, new NautHashMap<String, Long>());
if (!_statUploadQueueOverRidable.get(player).containsKey(statName))
_statUploadQueueOverRidable.get(player).put(statName, 0L);
_statUploadQueueOverRidable.get(player).put(statName, _statUploadQueueOverRidable.get(player).get(statName) + value);
}
}
protected void overRidableSaveStats()
{
if (_statUploadQueueOverRidable.isEmpty())
return;
try
{
NautHashMap<Integer, NautHashMap<Integer, Long>> uploadQueue = new NautHashMap<Integer, NautHashMap<Integer, Long>>();
synchronized (_statSync)
{
for (Iterator<Player> statIterator = _statUploadQueueOverRidable.keySet().iterator(); statIterator.hasNext();)
{
Player player = statIterator.next();
if (player.isOnline())
continue;
try
{
int uploadKey = PlayerCache.getInstance().getPlayer(player.getUniqueId()).getAccountId();
uploadQueue.put(uploadKey, new NautHashMap<Integer, Long>());
for (String statName : _statUploadQueueOverRidable.get(player).keySet())
{
int statId = _stats.get(statName);
uploadQueue.get(uploadKey).put(statId, _statUploadQueueOverRidable.get(player).get(statName));
System.out.println(player.getName() + " saving stat : " + statName + " overriding " + _statUploadQueueOverRidable.get(player).get(statName));
}
statIterator.remove();
}
catch (Exception e)
{
//System.out.println("[StatsManager] AccountId was not set for " + player.getName());
}
}
}
_repository.saveStats(uploadQueue, true);
}
catch (Exception exception)
{
exception.printStackTrace();
}
}
private void addToQueue(String statName, Player player, long value)
{
synchronized (_statSync)
@ -162,8 +240,13 @@ public class StatsManager extends MiniDbClientPlugin<PlayerStats>
exception.printStackTrace();
}
}
public boolean incrementStat(final int accountId, final String statName, final long value)
{
return incrementStat(accountId, statName, value, false);
}
public boolean incrementStat(final int accountId, final String statName, final long value, boolean overRide)
{
// This will register a new stat if we don't have one, otherwise it will just run the callback
registerNewStat(statName, new Runnable()
@ -175,7 +258,7 @@ public class StatsManager extends MiniDbClientPlugin<PlayerStats>
uploadQueue.put(accountId, new NautHashMap<Integer, Long>());
uploadQueue.get(accountId).put(_stats.get(statName), value);
_repository.saveStats(uploadQueue);
_repository.saveStats(uploadQueue, overRide);
}
});
@ -237,6 +320,7 @@ public class StatsManager extends MiniDbClientPlugin<PlayerStats>
{
addCommand(new TimeCommand(this));
addCommand(new GiveStatCommand(this));
addCommand(new MasterBuilderUnban(this));
}
@Override

View File

@ -6,16 +6,14 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.database.Tables;
import net.md_5.bungee.chat.TranslatableComponentSerializer;
import org.bukkit.plugin.java.JavaPlugin;
import org.jooq.DSLContext;
import org.jooq.Insert;
import org.jooq.Record2;
@ -29,6 +27,7 @@ public class StatsRepository extends RepositoryBase
{
private static String RETRIEVE_STATS = "SELECT id, name FROM stats;";
private static String INSERT_STAT = "INSERT INTO stats (name) VALUES (?);";
public StatsRepository(JavaPlugin plugin)
{
@ -68,9 +67,15 @@ public class StatsRepository extends RepositoryBase
{
executeUpdate(INSERT_STAT, new ColumnVarChar("name", 100, name));
}
public void saveStats(NautHashMap<Integer, NautHashMap<Integer, Long>> uploadQueue)
{
saveStats(uploadQueue, false);
}
@SuppressWarnings("rawtypes")
public void saveStats(NautHashMap<Integer, NautHashMap<Integer, Long>> uploadQueue)
public void saveStats(NautHashMap<Integer, NautHashMap<Integer, Long>> uploadQueue, boolean overRideStat)
{
try
{
@ -83,13 +88,24 @@ public class StatsRepository extends RepositoryBase
{
for (Integer statId : uploadQueue.get(accountId).keySet())
{
Update update = context
if(overRideStat)
{
Update update = context
.update(Tables.accountStat)
.set(Tables.accountStat.value, ULong.valueOf(uploadQueue.get(accountId).get(statId)))
.where(Tables.accountStat.accountId.eq(accountId))
.and(Tables.accountStat.statId.eq(statId));
updates.add(update);
}
else
{
Update update = context
.update(Tables.accountStat)
.set(Tables.accountStat.value, Tables.accountStat.value.plus(uploadQueue.get(accountId).get(statId)))
.where(Tables.accountStat.accountId.eq(accountId))
.and(Tables.accountStat.statId.eq(statId));
updates.add(update);
updates.add(update);
}
Insert insert = context
.insertInto(Tables.accountStat)

View File

@ -0,0 +1,104 @@
package mineplex.core.stats.command;
import java.util.Iterator;
import java.util.List;
import mineplex.core.account.CoreClient;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.stats.StatsManager;
import org.bukkit.entity.Player;
public class MasterBuilderUnban extends CommandBase<StatsManager>
{
public MasterBuilderUnban(StatsManager plugin)
{
super(plugin, Rank.ADMIN, "buildunban");
}
@Override
public void Execute(Player caller, String[] args)
{
if(args.length != 1)
{
UtilPlayer.message(caller, F.main("MasterBuilder Unban", "/buildunban <Target>"));
return;
}
try
{
Plugin.getClientManager().getRepository().matchPlayerName(new Callback<List<String>>()
{
@Override
public void run(List<String> matches)
{
boolean matchedExact = false;
for (String match : matches)
{
if (match.equalsIgnoreCase(args[0]))
{
matchedExact = true;
}
}
if (matchedExact)
{
for (Iterator<String> matchIterator = matches.iterator(); matchIterator.hasNext();)
{
if (!matchIterator.next().equalsIgnoreCase(args[0]))
{
matchIterator.remove();
}
}
}
UtilPlayer.searchOffline(matches, new Callback<String>()
{
@Override
public void run(String target)
{
if(target == null)
{
caller.sendMessage(F.main("MasterBuilder Unban", "Couldn't find " + args[0] + "'s account!"));
return;
}
Plugin.getClientManager().loadClientByName(target, new Runnable()
{
@Override
public void run()
{
CoreClient theClient = Plugin.getClientManager().Get(target);
if(theClient != null)
{
Plugin.incrementStat(theClient.getAccountId(), "Global.Build Draw Abuse", 0, true); // True = Resets the stat
caller.sendMessage(F.main("MasterBuilder Unban", "The user " + target + " has been unbanned from Master Builders"));
}
else
{
caller.sendMessage(F.main("MasterBuilder Unban", "Couldn't find " + target + "'s client!"));
return;
}
}
});
}
}, caller, args[0], false);
}
}, args[0]);
}
catch(Exception e)
{
e.printStackTrace();
caller.sendMessage(F.main("MasterBuilder Unban", "Exception caught! Please contact Morten and explain what happened."));
}
}
}

View File

@ -70,13 +70,14 @@ public class HubVisibilityManager extends MiniPlugin
for (Player other : UtilServer.getPlayers())
{
boolean localHideMe = hideMe;
if (player.equals(other))
continue;
if(Manager.GetClients().Get(other).GetRank().has(Rank.MODERATOR))
hideMe = false;
localHideMe = false;
if (hideMe ||
if (localHideMe ||
!Manager.getPreferences().Get(other).ShowPlayers ||
Manager.GetTutorial().InTutorial(other))
{