lots of changes that i can't remember at this point

This commit is contained in:
NewGarbo 2015-12-23 18:22:20 +00:00
parent 1840572c49
commit ff24ebc9f4
16 changed files with 714 additions and 9 deletions

View File

@ -42,9 +42,9 @@ public class F
return C.sysHead + head + "> " + C.sysBody + body;
}
public static String elem(String elem)
public static String elem(Object elem)
{
return C.mElem + elem + ChatColor.RESET + C.mBody;
return C.mElem + elem.toString() + ChatColor.RESET + C.mBody;
}
public static String name(String elem)

View File

@ -28,6 +28,12 @@ public class UtilTime
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_DAY);
return sdf.format(cal.getTime());
}
public static String date(long date)
{
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_DAY);
return sdf.format(date);
}
public static String getDayOfMonthSuffix(final int n)
{

View File

@ -19,6 +19,7 @@ import mineplex.core.common.util.NautHashMap;
import mineplex.core.donation.command.CoinCommand;
import mineplex.core.donation.command.GemCommand;
import mineplex.core.donation.command.GoldCommand;
import mineplex.core.donation.command.SetGoldCommand;
import mineplex.core.donation.repository.DonationRepository;
import mineplex.core.donation.repository.token.DonorTokenWrapper;
import mineplex.core.server.util.TransactionResponse;
@ -48,6 +49,7 @@ public class DonationManager extends MiniDbClientPlugin<Donor>
addCommand(new GemCommand(this));
addCommand(new CoinCommand(this));
addCommand(new GoldCommand(this));
addCommand(new SetGoldCommand(this));
}
@EventHandler
@ -335,6 +337,35 @@ public class DonationManager extends MiniDbClientPlugin<Donor>
}, caller, name, accountId, amount);
}
public void setGold(final Callback<Boolean> callback, final String caller, final String name, final int accountId, final int amount, final boolean updateTotal)
{
_repository.setGold(new Callback<Boolean>()
{
public void run(Boolean success)
{
if (success)
{
if (updateTotal)
{
Donor donor = Get(name);
if (donor != null)
{
donor.addGold(amount);
}
}
}
else
{
System.out.println("SET GOLD FAILED...");
}
if (callback != null)
callback.run(success);
}
}, caller, name, accountId, amount);
}
public void RewardGoldLater(final String caller, final Player player, final int amount)
{
if (!_goldQueue.containsKey(player))

View File

@ -0,0 +1,75 @@
package mineplex.core.donation.command;
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.donation.DonationManager;
import org.bukkit.entity.Player;
public class SetGoldCommand extends CommandBase<DonationManager>
{
public SetGoldCommand(DonationManager plugin)
{
super(plugin, Rank.ADMIN, "setgold");
}
@Override
public void Execute(final Player caller, String[] args)
{
if (args == null || args.length < 2)
{
UtilPlayer.message(caller, F.main("Clans", "Error! Usage: " + F.elem("/setgold <player> <amount>")));
return;
}
final String targetName = args[0];
final String goldString = args[1];
Player target = UtilPlayer.searchExact(targetName);
try
{
if (target == null)
{
Plugin.getClientManager().loadClientByName(targetName, new Runnable()
{
public void run()
{
CoreClient client = Plugin.getClientManager().Get(targetName);
if (client != null)
{
setGold(caller, null, targetName, client.getAccountId(), Integer.parseInt(goldString));
}
else
{
UtilPlayer.message(caller, F.main("Gold", "Could not find player " + F.name(targetName)));
}
}
});
}
else
{
setGold(caller, target, target.getName(), Plugin.getClientManager().Get(target).getAccountId(), Integer.parseInt(goldString));
}
}
catch (Exception e)
{
UtilPlayer.message(target, F.main("Clans", "You must provide a valid number in the gold parameter."));
}
}
private void setGold(final Player caller, final Player target, final String targetName, final int accountId, final int gold)
{
Plugin.setGold(new Callback<Boolean>()
{
public void run(Boolean completed)
{
UtilPlayer.message(caller, F.main("Gold", "You set " + F.name(targetName) + "'s Gold to " + F.elem(gold) + "."));
}
}, caller.getName(), targetName, accountId, gold, true);
}
}

View File

@ -31,6 +31,7 @@ public class DonationRepository extends RepositoryBase
private static String INSERT_COIN_TRANSACTION = "INSERT INTO accountCoinTransactions(accountId, reason, coins) VALUES(?, ?, ?);";
private static String UPDATE_ACCOUNT_COINS = "UPDATE accounts SET coins = coins + ? WHERE id = ?;";
private static String UPDATE_ACCOUNT_GOLD = "UPDATE accounts SET gold = gold + ? WHERE id = ?;";
private static String SET_ACCOUNT_GOLD = "UPDATE accounts SET gold = ? WHERE id = ?;";
private static String UPDATE_NULL_ACCOUNT_GEMS_AND_COINS_ = "UPDATE accounts SET gems = ?, coins = ? WHERE id = ? AND gems IS NULL AND coins IS NULL;";
private String _webAddress;
@ -198,6 +199,18 @@ public class DonationRepository extends RepositoryBase
}
}), "Error updating player gold amount in DonationRepository : ");
}
public void setGold(final Callback<Boolean> callback, final String giver, final String name, final int accountId, final int gold)
{
handleDatabaseCall(new DatabaseRunnable(new Runnable()
{
public void run()
{
boolean success = executeUpdate(SET_ACCOUNT_GOLD, new ColumnInt("gold", gold), new ColumnInt("id", accountId)) > 0;
callback.run(success);
}
}), "Error updating player gold amount in DonationRepository : ");
}
@Override
protected void initialize()

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.Core"/>
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.Core.Common"/>
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.ServerData"/>

View File

@ -1,11 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7
org.eclipse.jdt.core.compiler.source=1.8

View File

@ -39,6 +39,7 @@ import mineplex.core.updater.FileUpdater;
import mineplex.core.updater.Updater;
import mineplex.core.visibility.VisibilityManager;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.ban.ClansBanManager;
import mineplex.game.clans.items.GearManager;
import mineplex.game.clans.shop.building.BuildingShop;
import mineplex.game.clans.shop.farming.FarmingShop;
@ -98,7 +99,9 @@ public class Clans extends JavaPlugin
Teleport teleport = new Teleport(this, _clientManager);
Portal portal = new Portal(this, _clientManager, serverStatusManager.getCurrentServerName());
new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion());
// new ClansBanManager(this, webServerAddress, _clientManager, _donationManager);
Punish punish = new Punish(this, webServerAddress, _clientManager);
AntiHack.Initialize(this, punish, portal, preferenceManager, _clientManager);
AntiHack.Instance.setKick(false);

View File

@ -0,0 +1,81 @@
package mineplex.game.clans.clans.ban;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilTime;
public class ClansBan
{
private int _id;
private int _accountId;
private String _reason;
private long _banTime;
private long _unbanTime;
private boolean _permanent;
public ClansBan(int id, int accountId, String reason, long banTime, long unbanTime, boolean permanent)
{
_id = id;
_accountId = accountId;
_reason = reason;
_banTime = banTime;
_unbanTime = unbanTime;
_permanent = permanent;
}
public int getId()
{
return _id;
}
public int getAccountId()
{
return _accountId;
}
public String getReason()
{
return _reason;
}
public long getBanTime()
{
return _banTime;
}
public long getLength()
{
return _unbanTime - _banTime;
}
public long getTimeLeft()
{
return Math.max(0, _unbanTime - System.currentTimeMillis());
}
public long getUnbanTime()
{
return _unbanTime;
}
public boolean isPermanent()
{
return _permanent;
}
public String getBanTimeFormatted(boolean wording)
{
long time = getTimeLeft();
return time == -1 ? F.time("permanently") : (wording ? "for " : "") + F.time(UtilTime.MakeStr(time));
}
public boolean isRemoved()
{
return _unbanTime == -1;
}
public boolean isActive()
{
return (isPermanent() || getTimeLeft() > 0) && !isRemoved();
}
}

View File

@ -0,0 +1,71 @@
package mineplex.game.clans.clans.ban;
import java.util.List;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilTime;
public class ClansBanClient
{
public int AccountId;
public List<ClansBan> Bans;
public ClansBanClient(int accountId, List<ClansBan> bans)
{
AccountId = accountId;
Bans = bans;
}
public boolean isBanned()
{
for (ClansBan ban : Bans)
{
if (ban.isActive())
{
return true;
}
}
return false;
}
public long getBanTime()
{
long time = 0;
for (ClansBan ban : Bans)
{
if (ban.isPermanent())
{
return -1;
}
time += ban.getTimeLeft();
}
return time;
}
public String getBanTimeFormatted()
{
long time = getBanTime();
return time == -1 ? F.time("permanently") : "for " + F.time(UtilTime.MakeStr(time));
}
public String toString()
{
StringBuilder str = new StringBuilder();
str.append("{ClansBanClient:" + AccountId + "} [\n");
for (ClansBan ban : Bans)
{
str.append("(\nid: " + ban.getId() + ",\nbanTime: " + ban.getBanTime() + ",\nunbanTime: " + ban.getUnbanTime() + ",\nbanTimeLeft:" + ban.getTimeLeft() + ",\nReason:\"" + ban.getReason() + "\"\n)");
}
str.append("]");
return str.toString();
}
}

View File

@ -0,0 +1,136 @@
package mineplex.game.clans.clans.ban;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback;
import mineplex.core.donation.DonationManager;
import mineplex.game.clans.clans.ban.commands.ClansBanCommand;
import mineplex.game.clans.clans.ban.ui.ClansBanShop;
public class ClansBanManager extends MiniPlugin
{
private CoreClientManager _clientManager;
private ClansBanRepository _repository;
private Map<String, ClansBanClient> _clients;
private Map<String, String> _cache;
private ClansBanShop _shop;
public ClansBanManager(JavaPlugin plugin, String webServerAddress, CoreClientManager clientManager, DonationManager donationManager)
{
super("Blacklist", plugin);
_clientManager = clientManager;
_repository = new ClansBanRepository(plugin, this, webServerAddress);
_clients = new HashMap<>();
_cache = new HashMap<>();
_shop = new ClansBanShop(this, clientManager, donationManager);
}
@Override
public void addCommands()
{
addCommand(new ClansBanCommand(this));
}
public void ban(ClansBanClient client, String name, long time, String reason)
{
_repository.ban(client.AccountId, time, reason, time == -1);
LoadClient(name, null);
}
public CoreClientManager getClientManager()
{
return _clientManager;
}
public ClansBanRepository GetRepository()
{
return _repository;
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event)
{
LoadClient(event.getPlayer().getName(), null);
ClansBanClient client = _clients.get(event.getPlayer().getName());
if (client.isBanned())
{
event.setJoinMessage(null);
event.getPlayer().kickPlayer(C.cRed + "You have been banned from Clans " + client.getBanTimeFormatted() + ".");
}
}
@EventHandler
public void onPlayerKicked(PlayerKickEvent event)
{
ClansBanClient client = _clients.get(event.getPlayer().getName());
if (client.isBanned())
{
event.setLeaveMessage(null);
}
}
public void LoadClient(final String name, Callback<ClansBanClient> callback)
{
GetRepository().loadBans(name, client -> {
_clients.put(name, client);
if (callback != null) callback.run(client);
});
}
public ClansBanClient GetClient(String name)
{
synchronized (this)
{
return _clients.get(name.toLowerCase());
}
}
public ClansBanShop getShop()
{
return _shop;
}
public void cache(Player player, String playerName)
{
_cache.put(player.getName(), playerName);
}
public String getCachedName(Player player)
{
return _cache.get(player.getName());
}
public void clearCachedName(String name)
{
_cache.remove(name);
}
public void unban(ClansBanClient target, ClansBan ban, String name)
{
if (target.AccountId != ban.getAccountId())
{
return;
}
_repository.removeBan(ban);
LoadClient(name, null);
}
}

View File

@ -0,0 +1,145 @@
package mineplex.game.clans.clans.ban;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.plugin.java.JavaPlugin;
import com.google.gson.reflect.TypeToken;
import mineplex.core.common.util.Callback;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnBoolean;
import mineplex.core.database.column.ColumnInt;
import mineplex.core.database.column.ColumnTimestamp;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.core.server.remotecall.JsonWebCall;
public class ClansBanRepository extends RepositoryBase
{
private ClansBanManager _manager;
private static final String GET_LONGEST_BAN = "SELECT * FROM clanBans WHERE (NOW() < unbanTime OR permanent=1) AND accountId = ? ORDER BY permanent DESC, unbanTime DESC LIMIT 1;";
private static final String BAN_PLAYER = "INSERT INTO clanBans (accountId, reason, banTime, unbanTime, permanent) VALUES (?, ?, ?, ?, ?);";
private static final String REMOVE_BAN = "UPDATE clanBans SET unbanTime = -1 WHERE id = ?;";
private static final String GET_ALL_BANS = "SELECT * FROM clanBans WHERE accountId = ?;";
private String _webAddress;
public ClansBanRepository(JavaPlugin plugin, ClansBanManager manager, String webServerAddress)
{
super(plugin, DBPool.ACCOUNT);
_manager = manager;
}
public void ban(int accountId, long time, String reason, boolean permanent)
{
executeInsert(BAN_PLAYER, null,
new ColumnInt("accountId", accountId),
new ColumnVarChar("reason", 128, reason),
new ColumnTimestamp("banTime", new Timestamp(System.currentTimeMillis())),
new ColumnTimestamp("unbanTime", new Timestamp(System.currentTimeMillis() + time)),
new ColumnBoolean("permanent", permanent)
);
}
public void loadBans(final String name, final Callback<ClansBanClient> callback)
{
_manager.getClientManager().loadClientByName(name, new Runnable() {
public void run()
{
executeQuery(GET_ALL_BANS, new ResultSetCallable()
{
@Override
public void processResultSet(ResultSet resultSet) throws SQLException
{
final List<ClansBan> list = new ArrayList<ClansBan>();
while (resultSet.next())
{
int id = resultSet.getInt(1);
int accountId = resultSet.getInt(2);
String reason = resultSet.getString(3);
long banTime = resultSet.getLong(4);
long unbanTime = resultSet.getLong(5);
boolean permanent = resultSet.getBoolean(6);
list.add(new ClansBan(id, accountId, reason, banTime, unbanTime, permanent));
}
callback.run(new ClansBanClient(_manager.getClientManager().Get(name).getAccountId(), list));
}
}, new ColumnInt("accountId", _manager.getClientManager().Get(name).getAccountId()));
}
});
}
public void getLongestBan(final String name, final Callback<ClansBan> callback)
{
if (callback == null)
{
return;
}
_manager.getClientManager().loadClientByName(name, new Runnable(){
public void run()
{
executeQuery(GET_LONGEST_BAN, new ResultSetCallable()
{
@Override
public void processResultSet(ResultSet resultSet) throws SQLException
{
while (resultSet.next())
{
int id = resultSet.getInt(1);
int accountId = resultSet.getInt(2);
String reason = resultSet.getString(3);
Timestamp banTime = resultSet.getTimestamp(4);
Timestamp unbanTime = resultSet.getTimestamp(5);
boolean permanent = resultSet.getBoolean(6);
callback.run(new ClansBan(id, accountId, reason, banTime.getTime(), unbanTime.getTime(), permanent));
}
}
}, new ColumnInt("accountId", _manager.getClientManager().Get(name).getAccountId()));
}
});
}
public void matchPlayerName(final Callback<List<String>> callback, final String userName)
{
Thread asyncThread = new Thread(new Runnable()
{
public void run()
{
List<String> tokenList = new JsonWebCall(_webAddress + "PlayerAccount/GetMatches").Execute(new TypeToken<List<String>>(){}.getType(), userName);
callback.run(tokenList);
}
});
asyncThread.start();
}
@Override
protected void initialize()
{
}
@Override
protected void update()
{
}
public void removeBan(ClansBan ban)
{
executeUpdate(REMOVE_BAN, new ColumnInt("id", ban.getId()));
}
}

View File

@ -0,0 +1,94 @@
package mineplex.game.clans.clans.ban.commands;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.game.clans.clans.ban.ClansBanManager;
public class ClansBanCommand extends CommandBase<ClansBanManager>
{
public ClansBanCommand(ClansBanManager plugin)
{
super(plugin, Rank.ADMIN, "cbans", "cb");
}
@Override
public void Execute(final Player caller, String[] args)
{
if (args == null || args.length < 1)
{
UtilPlayer.message(caller, C.cGold + "/cb <username> <timeInDays(number)/p(ermanent)> <description> - Bans the specified player for the specified amount of time");
UtilPlayer.message(caller, C.cGold + "/cb <username> - Displays the \"Clans Punish\" UI, and will display all of the player's past bans (including current ones)");
}
else if (args.length == 1)
{
final String playerName = args[0];
Plugin.LoadClient(playerName, client -> {
Plugin.cache(caller, playerName);
Plugin.getShop().attemptShopOpen(caller);
});
}
else if (args.length > 2)
{
final String playerName = args[0];
final float time;
final boolean permanent = args[1].startsWith("p");
if (!permanent)
{
try
{
time = Float.parseFloat(args[1]);
}
catch(NumberFormatException e)
{
UtilPlayer.message(caller, F.main("Clans", "You must provide a valid floating point number for the time (in days). e.g. " + F.elem("1.5") + ", " + F.elem("3.2") + "."));
return;
}
}
else
{
//Required for compilation reasons
time = 0;
}
String reason = args[2];
for (int i = 3; i < args.length; i++)
{
reason += " " + args[i];
}
final String finalReason = reason;
//Match exact online first
Player target = UtilPlayer.searchExact(playerName);
if (target != null)
{
Plugin.LoadClient(playerName, client -> {
Plugin.ban(client, target.getName(), permanent ? -1 : (long) (time * 24.f * 60.f * 60.f * 1000.f), finalReason);
UtilPlayer.message(caller, F.main("Clans", F.elem(playerName) + " is now banned " + F.time(client.getBanTimeFormatted()) + "."));
Plugin.runSync(() -> target.kickPlayer(C.cRed + "You have been banned from Clans " + client.getBanTimeFormatted() + "."));
});
return;
}
Plugin.LoadClient(playerName, client -> {
Plugin.ban(client, playerName, permanent ? -1 : (long) (time * 24.f * 60.f * 60.f * 1000.f), finalReason);
UtilPlayer.message(caller, F.main("Clans", F.elem(playerName) + " is now banned " + client.getBanTimeFormatted() + "."));
});
}
else
{
UtilPlayer.message(caller, C.cGold + "/cp <username> <timeInDays(number)/p(ermanent)> <description> - Bans the specified player for the specified amount of time");
UtilPlayer.message(caller, C.cGold + "/cp <username> - Displays the \"Clans Punish\" UI, and will display all of the player's past bans (including current ones)");
}
}
}

View File

@ -0,0 +1,23 @@
package mineplex.game.clans.clans.ban.ui;
import org.bukkit.entity.Player;
import mineplex.core.account.CoreClientManager;
import mineplex.core.donation.DonationManager;
import mineplex.core.shop.page.ShopPageBase;
import mineplex.game.clans.clans.ban.ClansBanManager;
public class ClansBanPage extends ShopPageBase<ClansBanManager, ClansBanShop>
{
public ClansBanPage(final ClansBanManager banManager, final ClansBanShop shop, final CoreClientManager clientManager, final DonationManager donationManager, final String name, final Player player)
{
super(banManager, shop, clientManager, donationManager, name, player);
buildPage();
}
protected void buildPage()
{
}
}

View File

@ -0,0 +1,23 @@
package mineplex.game.clans.clans.ban.ui;
import org.bukkit.entity.Player;
import mineplex.core.account.CoreClientManager;
import mineplex.core.donation.DonationManager;
import mineplex.core.shop.ShopBase;
import mineplex.core.shop.page.ShopPageBase;
import mineplex.game.clans.clans.ban.ClansBanManager;
public class ClansBanShop extends ShopBase<ClansBanManager>
{
public ClansBanShop(final ClansBanManager plugin, final CoreClientManager clientManager, final DonationManager donationManager)
{
super(plugin, clientManager, donationManager, "Customize New Gear");
}
@Override
protected ShopPageBase<ClansBanManager, ? extends ShopBase<ClansBanManager>> buildPagesFor(final Player player)
{
return new ClansBanPage(getPlugin(), this, getClientManager(), getDonationManager(), "Customize New Gear", player);
}
}

View File

@ -185,8 +185,12 @@ public class PvpTimer extends MiniClientPlugin<PvpTimerClient>
@EventHandler
public void onSkill(SkillTriggerEvent event)
{
if (event.GetTargets() != null
&& event.GetTargets().size() == 1
if (event.GetTargets() == null)
{
return;
}
if (event.GetTargets().size() == 1
&& event.GetTargets().get(0) instanceof Player
&& hasTimer((Player) event.GetTargets().get(0)))
{