Update Bonus amounts, Attempting to fix Votifier plugin for EU/US
This commit is contained in:
parent
d20fe54010
commit
28806aaf0a
@ -150,7 +150,7 @@ public class BonusAmount
|
|||||||
if (amount > 0)
|
if (amount > 0)
|
||||||
lore.add(C.cYellow + "Reward: " + C.cWhite + amount + " " + suffix);
|
lore.add(C.cYellow + "Reward: " + C.cWhite + amount + " " + suffix);
|
||||||
|
|
||||||
if (bonus > 0)
|
// if (bonus > 0)
|
||||||
lore.add(C.cYellow + "Streak Bonus: " + C.cWhite + bonus + " " + suffix);
|
// lore.add(C.cYellow + "Streak Bonus: " + C.cWhite + bonus + " " + suffix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -211,6 +211,8 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
|
|||||||
|
|
||||||
public void handleVote(Player player)
|
public void handleVote(Player player)
|
||||||
{
|
{
|
||||||
|
// _repository.attemptDailyBonus();
|
||||||
|
|
||||||
addPendingExplosion(player, player.getName());
|
addPendingExplosion(player, player.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -500,20 +502,54 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
|
|||||||
return calendar.getTimeInMillis();
|
return calendar.getTimeInMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getDailyMultiplier(Player player)
|
||||||
|
{
|
||||||
|
BonusClientData client = Get(player);
|
||||||
|
int streak = client.getDailyStreak();
|
||||||
|
|
||||||
|
int multiplyer = Math.min(200, 5 * streak);
|
||||||
|
if (streak >= 40) multiplyer += (1 * (streak - 40));
|
||||||
|
return multiplyer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getVoteMultiplyer(Player player)
|
||||||
|
{
|
||||||
|
BonusClientData client = Get(player);
|
||||||
|
int streak = client.getVoteStreak();
|
||||||
|
|
||||||
|
int multiplyer = Math.min(100, 5 * streak);
|
||||||
|
if (streak >= 20) multiplyer += (1 * (streak - 40));
|
||||||
|
return multiplyer;
|
||||||
|
}
|
||||||
|
|
||||||
public BonusAmount getDailyBonusAmount(Player player)
|
public BonusAmount getDailyBonusAmount(Player player)
|
||||||
{
|
{
|
||||||
|
double mult = getDailyMultiplier(player) / 100.0;
|
||||||
|
|
||||||
BonusAmount amount = new BonusAmount();
|
BonusAmount amount = new BonusAmount();
|
||||||
amount.setTickets(1);
|
int coins = 100;
|
||||||
amount.setBonusCoins(100);
|
int gems = 100;
|
||||||
amount.setBonusExperience(1000);
|
int experience = 250;
|
||||||
|
|
||||||
|
amount.setCoins(coins);
|
||||||
|
amount.setGems(gems);
|
||||||
|
amount.setExperience(experience);
|
||||||
|
amount.setBonusCoins((int) (mult * coins));
|
||||||
|
amount.setBonusGems((int) (mult * gems));
|
||||||
|
amount.setBonusExperience((int) (mult * experience));
|
||||||
|
|
||||||
return amount;
|
return amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BonusAmount getVoteBonusAmount(Player player)
|
public BonusAmount getVoteBonusAmount(Player player)
|
||||||
{
|
{
|
||||||
|
double mult = getVoteMultiplyer(player) / 100.0;
|
||||||
|
|
||||||
BonusAmount amount = new BonusAmount();
|
BonusAmount amount = new BonusAmount();
|
||||||
amount.setTickets(1);
|
amount.setTickets(1);
|
||||||
amount.setGems(500);
|
amount.setGems(400);
|
||||||
|
amount.setBonusGems((int) (mult * 400));
|
||||||
|
|
||||||
return amount;
|
return amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -545,7 +581,7 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
|
|||||||
|
|
||||||
//VOTE
|
//VOTE
|
||||||
|
|
||||||
public void atteptVoteBonus(final Player player, final Callback<Boolean> result)
|
public void attemptVoteBonus(final Player player, final Callback<Boolean> result)
|
||||||
{
|
{
|
||||||
if (timeTillRankBonus(player) > 0)
|
if (timeTillRankBonus(player) > 0)
|
||||||
result.run(false);
|
result.run(false);
|
||||||
|
@ -251,13 +251,8 @@ public class BonusRepository extends RepositoryBase
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void voteBonus(final Player player, final Callback<Boolean> result)
|
public void attemptVoteBonus(final Player player, final Callback<Boolean> result)
|
||||||
{
|
{
|
||||||
if (!Recharge.Instance.usable(player, "AttemptVoteBonus"))
|
|
||||||
{
|
|
||||||
result.run(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final int accountId = _manager.getClientManager().Get(player).getAccountId();
|
final int accountId = _manager.getClientManager().Get(player).getAccountId();
|
||||||
final int coins = _manager.getRankBonusAmount(player).getCoins();
|
final int coins = _manager.getRankBonusAmount(player).getCoins();
|
||||||
|
|
||||||
|
@ -143,6 +143,8 @@ public class DailyBonusButton implements GuiItem, Listener
|
|||||||
lore.add(" ");
|
lore.add(" ");
|
||||||
|
|
||||||
lore.add(C.cYellow + "Current Streak: " + C.cWhite + client.getDailyStreak());
|
lore.add(C.cYellow + "Current Streak: " + C.cWhite + client.getDailyStreak());
|
||||||
|
lore.add(C.cYellow + "Streak Bonus: " + C.cWhite + _bonusManager.getDailyMultiplier(_player) + "%");
|
||||||
|
lore.add(" ");
|
||||||
lore.add(C.cYellow + "Highest Streak: " + C.cWhite + client.getMaxDailyStreak());
|
lore.add(C.cYellow + "Highest Streak: " + C.cWhite + client.getMaxDailyStreak());
|
||||||
|
|
||||||
if (client.getDailyTime() != null)
|
if (client.getDailyTime() != null)
|
||||||
|
@ -139,6 +139,8 @@ public class VoteButton implements GuiItem, Listener {
|
|||||||
lore.add(" ");
|
lore.add(" ");
|
||||||
|
|
||||||
lore.add(C.cYellow + "Current Streak: " + C.cWhite + client.getVoteStreak());
|
lore.add(C.cYellow + "Current Streak: " + C.cWhite + client.getVoteStreak());
|
||||||
|
lore.add(C.cYellow + "Streak Bonus: " + C.cWhite + _bonusManager.getVoteMultiplyer(_player) + "%");
|
||||||
|
lore.add(" ");
|
||||||
lore.add(C.cYellow + "Highest Streak: " + C.cWhite + client.getMaxVoteStreak());
|
lore.add(C.cYellow + "Highest Streak: " + C.cWhite + client.getMaxVoteStreak());
|
||||||
|
|
||||||
if (client.getVoteTime() != null)
|
if (client.getVoteTime() != null)
|
||||||
|
@ -22,6 +22,7 @@ import mineplex.serverdata.servers.ConnectionData.ConnectionType;
|
|||||||
public class ServerManager
|
public class ServerManager
|
||||||
{
|
{
|
||||||
public static final String SERVER_STATUS_LABEL = "ServerStatus"; // Label differentiating ServerStatus related servers
|
public static final String SERVER_STATUS_LABEL = "ServerStatus"; // Label differentiating ServerStatus related servers
|
||||||
|
private static final String DEFAULT_CONFIG = "redis-config.dat";
|
||||||
|
|
||||||
// Configuration determining connection information
|
// Configuration determining connection information
|
||||||
private static RedisConfig _config;
|
private static RedisConfig _config;
|
||||||
@ -74,7 +75,7 @@ public class ServerManager
|
|||||||
|
|
||||||
public static ConnectionData getConnection(boolean writeable, String name)
|
public static ConnectionData getConnection(boolean writeable, String name)
|
||||||
{
|
{
|
||||||
return getConfig().getConnection(writeable, name);
|
return getConfig(DEFAULT_CONFIG).getConnection(writeable, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -89,13 +90,13 @@ public class ServerManager
|
|||||||
/**
|
/**
|
||||||
* @return the {@link RedisConfig} associated with this manager, providing appropriate connections.
|
* @return the {@link RedisConfig} associated with this manager, providing appropriate connections.
|
||||||
*/
|
*/
|
||||||
public static RedisConfig getConfig()
|
public static RedisConfig getConfig(String fileName)
|
||||||
{
|
{
|
||||||
if (_config == null)
|
if (_config == null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
File configFile = new File("redis-config.dat");
|
File configFile = new File(fileName);
|
||||||
|
|
||||||
if (configFile.exists())
|
if (configFile.exists())
|
||||||
{
|
{
|
||||||
@ -113,7 +114,7 @@ public class ServerManager
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log("redis-config.dat not found at " + configFile.toPath().toString());
|
log(fileName + " not found at " + configFile.toPath().toString());
|
||||||
_config = new RedisConfig();
|
_config = new RedisConfig();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,5 +19,9 @@
|
|||||||
<orderEntry type="module" module-name="Mineplex.ServerData" />
|
<orderEntry type="module" module-name="Mineplex.ServerData" />
|
||||||
<orderEntry type="module" module-name="Mineplex.Core" />
|
<orderEntry type="module" module-name="Mineplex.Core" />
|
||||||
<orderEntry type="library" name="craftbukkit" level="project" />
|
<orderEntry type="library" name="craftbukkit" level="project" />
|
||||||
|
<orderEntry type="library" name="jedis" level="project" />
|
||||||
|
<orderEntry type="library" name="jooq" level="project" />
|
||||||
|
<orderEntry type="module" module-name="Mineplex.Core.Common" />
|
||||||
|
<orderEntry type="module" module-name="Mineplex.Database" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
@ -1,5 +1,7 @@
|
|||||||
package mineplex.votifier;
|
package mineplex.votifier;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
@ -7,64 +9,156 @@ import com.vexsoftware.votifier.model.Vote;
|
|||||||
import com.vexsoftware.votifier.model.VotifierEvent;
|
import com.vexsoftware.votifier.model.VotifierEvent;
|
||||||
import mineplex.core.MiniPlugin;
|
import mineplex.core.MiniPlugin;
|
||||||
import mineplex.core.account.CoreClientManager;
|
import mineplex.core.account.CoreClientManager;
|
||||||
|
import mineplex.core.common.util.UUIDFetcher;
|
||||||
|
import mineplex.core.database.DBPool;
|
||||||
import mineplex.core.donation.DonationManager;
|
import mineplex.core.donation.DonationManager;
|
||||||
import mineplex.core.votifier.VotifierCommand;
|
import mineplex.core.votifier.VotifierCommand;
|
||||||
|
import mineplex.database.Tables;
|
||||||
import mineplex.serverdata.Region;
|
import mineplex.serverdata.Region;
|
||||||
|
import mineplex.serverdata.Utility;
|
||||||
|
import mineplex.serverdata.commands.ServerCommand;
|
||||||
import mineplex.serverdata.commands.ServerCommandManager;
|
import mineplex.serverdata.commands.ServerCommandManager;
|
||||||
import mineplex.serverdata.data.PlayerStatus;
|
import mineplex.serverdata.data.PlayerStatus;
|
||||||
|
import mineplex.serverdata.redis.RedisConfig;
|
||||||
import mineplex.serverdata.redis.RedisDataRepository;
|
import mineplex.serverdata.redis.RedisDataRepository;
|
||||||
import mineplex.serverdata.servers.ServerManager;
|
import mineplex.serverdata.servers.ServerManager;
|
||||||
|
import org.jooq.DSLContext;
|
||||||
|
import org.jooq.SQLDialect;
|
||||||
|
import org.jooq.impl.DSL;
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
|
import redis.clients.jedis.JedisPool;
|
||||||
|
import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by shaun on 15-08-05.
|
* Created by shaun on 15-08-05.
|
||||||
*/
|
*/
|
||||||
public class VotifierManager extends MiniPlugin
|
public class VotifierManager extends MiniPlugin
|
||||||
{
|
{
|
||||||
|
private CoreClientManager _clientManager;
|
||||||
|
private DonationManager _donationManager;
|
||||||
|
|
||||||
|
private RedisConfig _usConfig;
|
||||||
|
private RedisConfig _euConfig;
|
||||||
private RedisDataRepository<PlayerStatus> _usPlayerRepo;
|
private RedisDataRepository<PlayerStatus> _usPlayerRepo;
|
||||||
private RedisDataRepository<PlayerStatus> _euPlayerRepo;
|
private RedisDataRepository<PlayerStatus> _euPlayerRepo;
|
||||||
|
private JedisPool _usWritePool;
|
||||||
|
private JedisPool _euWritePool;
|
||||||
|
|
||||||
public VotifierManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager)
|
public VotifierManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager)
|
||||||
{
|
{
|
||||||
super("Votifier", plugin);
|
super("Votifier", plugin);
|
||||||
|
|
||||||
_usPlayerRepo = new RedisDataRepository<PlayerStatus>(ServerManager.getMasterConnection(), ServerManager.getSlaveConnection(),
|
_clientManager = clientManager;
|
||||||
Region.US, PlayerStatus.class, "playerStatus");
|
_donationManager = donationManager;
|
||||||
_euPlayerRepo = new RedisDataRepository<PlayerStatus>(ServerManager.getMasterConnection(), ServerManager.getSlaveConnection(),
|
|
||||||
Region.EU, PlayerStatus.class, "playerStatus");
|
|
||||||
|
|
||||||
ServerCommandManager.getInstance().registerCommandType("VotifierCommand", VotifierCommand.class);
|
_usConfig = ServerManager.getConfig("us-redis.dat");
|
||||||
|
_euConfig = ServerManager.getConfig("eu-redis.dat");
|
||||||
|
|
||||||
|
_usPlayerRepo = new RedisDataRepository<PlayerStatus>(_usConfig.getConnection(true, "DefaultConnection"),
|
||||||
|
_usConfig.getConnection(false, "DefaultConnection"), Region.US, PlayerStatus.class, "playerStatus");
|
||||||
|
_euPlayerRepo = new RedisDataRepository<PlayerStatus>(_euConfig.getConnection(true, "DefaultConnection"),
|
||||||
|
_euConfig.getConnection(false, "DefaultConnection"), Region.EU, PlayerStatus.class, "playerStatus");
|
||||||
|
|
||||||
|
_usWritePool = Utility.generatePool(_usConfig.getConnection(true, "DefaultConnection"));
|
||||||
|
_euWritePool = Utility.generatePool(_euConfig.getConnection(true, "DefaultConnection"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void handleVote(VotifierEvent event)
|
public void handleVote(VotifierEvent event)
|
||||||
{
|
{
|
||||||
Vote vote = event.getVote();
|
Vote vote = event.getVote();
|
||||||
|
String playerName = "Phinary";
|
||||||
|
|
||||||
System.out.println("New Vote: " + vote.getUsername());
|
System.out.println("New Vote: " + playerName);
|
||||||
|
|
||||||
PlayerStatus usStatus = _usPlayerRepo.getElement(vote.getUsername());
|
// UUID uuid = UUIDFetcher.getUUIDOf(playerName);
|
||||||
// VotifierCommand command = new VotifierCommand(vote.getUsername(), "PhiTest-1");
|
UUID uuid = _clientManager.loadUUIDFromDB(playerName);
|
||||||
// command.publish();
|
if (uuid != null)
|
||||||
|
{
|
||||||
|
System.out.println("Found UUID:" + uuid.toString());
|
||||||
|
// if (playerName.equalsIgnoreCase("Phinary"))
|
||||||
|
// {
|
||||||
|
// System.out.println("award bonus");
|
||||||
|
// awardBonus(uuid);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.out.println("Failed to load UUID for player: " + playerName);
|
||||||
|
}
|
||||||
|
|
||||||
|
notifyServer(playerName);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean notifyServer(String playerName)
|
||||||
|
{
|
||||||
|
JedisPool writePool = null;
|
||||||
|
String serverName = null;
|
||||||
|
|
||||||
|
PlayerStatus usStatus = _usPlayerRepo.getElement(playerName);
|
||||||
if (usStatus != null)
|
if (usStatus != null)
|
||||||
{
|
{
|
||||||
System.out.println("Found on US Server: " + usStatus.getServer());
|
System.out.println("Found on US Server: " + usStatus.getServer());
|
||||||
VotifierCommand command = new VotifierCommand(vote.getUsername(), usStatus.getServer());
|
writePool = _usWritePool;
|
||||||
command.publish();
|
serverName = usStatus.getServer();
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
System.out.println("Not found on US Server!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerStatus euStatus = _euPlayerRepo.getElement(vote.getUsername());
|
PlayerStatus euStatus = _euPlayerRepo.getElement(playerName);
|
||||||
if (euStatus != null)
|
if (euStatus != null)
|
||||||
{
|
{
|
||||||
System.out.println("Found on EU Server: " + euStatus.getServer());
|
System.out.println("Found on EU Server: " + euStatus.getServer());
|
||||||
|
writePool = _euWritePool;
|
||||||
|
serverName = euStatus.getServer();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if (writePool != null && serverName != null)
|
||||||
{
|
{
|
||||||
System.out.println("Not found on EU Server!");
|
VotifierCommand command = new VotifierCommand(playerName, serverName);
|
||||||
|
System.out.println("Publishing Server Command!");
|
||||||
|
publishCommand(command, writePool);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void awardBonus(UUID uuid)
|
||||||
|
{
|
||||||
|
DSLContext create = DSL.using(DBPool.ACCOUNT, SQLDialect.MYSQL);
|
||||||
|
int updated = create.update(Tables.bonus).set(Tables.bonus.tickets, Tables.bonus.tickets.add(1))
|
||||||
|
.where(Tables.bonus.accountId.eq(DSL.select(Tables.accounts.id).where(Tables.accounts.uuid.eq(uuid.toString())))).execute();
|
||||||
|
System.out.println("Ran query with response: " + updated);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void publishCommand(final ServerCommand serverCommand, final JedisPool writePool)
|
||||||
|
{
|
||||||
|
new Thread(new Runnable()
|
||||||
|
{
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
Jedis jedis = writePool.getResource();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String commandType = serverCommand.getClass().getSimpleName();
|
||||||
|
String serializedCommand = Utility.serialize(serverCommand);
|
||||||
|
jedis.publish("commands.server" + ":" + commandType, serializedCommand);
|
||||||
|
}
|
||||||
|
catch (JedisConnectionException exception)
|
||||||
|
{
|
||||||
|
exception.printStackTrace();
|
||||||
|
writePool.returnBrokenResource(jedis);
|
||||||
|
jedis = null;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (writePool != null)
|
||||||
|
{
|
||||||
|
writePool.returnResource(jedis);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user