Votifier fixes
This commit is contained in:
parent
5d3503b733
commit
c177307f70
@ -125,6 +125,21 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
|
|||||||
private StreakRecord _dailyStreak;
|
private StreakRecord _dailyStreak;
|
||||||
private StreakRecord _voteStreak;
|
private StreakRecord _voteStreak;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* THIS SHOULD ONLY BE USED FOR VOTIFIER!
|
||||||
|
*/
|
||||||
|
public BonusManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager)
|
||||||
|
{
|
||||||
|
super("Bonus", plugin);
|
||||||
|
_enabled = false;
|
||||||
|
|
||||||
|
_repository = new BonusRepository(plugin, this, donationManager);
|
||||||
|
_clientManager = clientManager;
|
||||||
|
_donationManager = donationManager;
|
||||||
|
|
||||||
|
updateOffSet();
|
||||||
|
}
|
||||||
|
|
||||||
public BonusManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, PollManager pollManager, NpcManager npcManager, HologramManager hologramManager, StatsManager statsManager, InventoryManager inventoryManager, PetManager petManager)
|
public BonusManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, PollManager pollManager, NpcManager npcManager, HologramManager hologramManager, StatsManager statsManager, InventoryManager inventoryManager, PetManager petManager)
|
||||||
{
|
{
|
||||||
super("Bonus", plugin);
|
super("Bonus", plugin);
|
||||||
@ -146,6 +161,9 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
|
|||||||
|
|
||||||
// Hope to god this works!
|
// Hope to god this works!
|
||||||
_canVote = true;
|
_canVote = true;
|
||||||
|
|
||||||
|
if (npcManager != null)
|
||||||
|
{
|
||||||
_carlNpc = _npcManager.getNpcByName("Carl the Creeper");
|
_carlNpc = _npcManager.getNpcByName("Carl the Creeper");
|
||||||
if (_carlNpc == null)
|
if (_carlNpc == null)
|
||||||
{
|
{
|
||||||
@ -159,6 +177,11 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
|
|||||||
_animation = new AnimationCarl(_carlNpc.getEntity());
|
_animation = new AnimationCarl(_carlNpc.getEntity());
|
||||||
_animation.setRunning(false);
|
_animation.setRunning(false);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_enabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
clientManager.addStoredProcedureLoginProcessor(this);
|
clientManager.addStoredProcedureLoginProcessor(this);
|
||||||
|
|
||||||
@ -229,24 +252,24 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
|
|||||||
|
|
||||||
public void handleVote(final Player player)
|
public void handleVote(final Player player)
|
||||||
{
|
{
|
||||||
_repository.attemptVoteBonus(player, new Callback<Boolean>()
|
runAsync(new Runnable()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void run(Boolean data)
|
public void run()
|
||||||
{
|
{
|
||||||
if (data)
|
Get(player).getRecord().refresh();
|
||||||
|
runSync(new Runnable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
{
|
{
|
||||||
incrementVoteStreak(player);
|
|
||||||
addPendingExplosion(player, player.getName());
|
addPendingExplosion(player, player.getName());
|
||||||
awardBonus(player, getVoteBonusAmount(player));
|
|
||||||
UtilPlayer.message(player, F.main("Vote", "Thanks for your vote!"));
|
UtilPlayer.message(player, F.main("Vote", "Thanks for your vote!"));
|
||||||
}
|
}
|
||||||
else
|
});
|
||||||
{
|
|
||||||
UtilPlayer.message(player, F.main("Vote", "There was an error processing your vote. Please contact an admin!"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@ -498,14 +521,12 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
|
|||||||
data.setMaxDailyStreak(data.getDailyStreak());
|
data.setMaxDailyStreak(data.getDailyStreak());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void incrementVoteStreak(Player player)
|
public void incrementVoteStreak(BonusClientData client)
|
||||||
{
|
{
|
||||||
BonusClientData data = Get(player);
|
client.setVoteStreak(client.getVoteStreak() + 1);
|
||||||
|
|
||||||
data.setVoteStreak(data.getVoteStreak() + 1);
|
if (client.getVoteStreak() > client.getMaxVoteStreak())
|
||||||
|
client.setMaxVoteStreak(client.getVoteStreak());
|
||||||
if (data.getVoteStreak() > data.getMaxVoteStreak())
|
|
||||||
data.setMaxVoteStreak(data.getVoteStreak());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean continueStreak(long localLastBonus, long extendTime)
|
public boolean continueStreak(long localLastBonus, long extendTime)
|
||||||
@ -548,9 +569,8 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
|
|||||||
return multiplyer;
|
return multiplyer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getVoteMultiplyer(Player player)
|
public int getVoteMultiplyer(BonusClientData client)
|
||||||
{
|
{
|
||||||
BonusClientData client = Get(player);
|
|
||||||
int streak = client.getVoteStreak();
|
int streak = client.getVoteStreak();
|
||||||
|
|
||||||
int multiplyer = Math.min(100, 5 * streak);
|
int multiplyer = Math.min(100, 5 * streak);
|
||||||
@ -579,7 +599,12 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
|
|||||||
|
|
||||||
public BonusAmount getVoteBonusAmount(Player player)
|
public BonusAmount getVoteBonusAmount(Player player)
|
||||||
{
|
{
|
||||||
double mult = getVoteMultiplyer(player) / 100.0;
|
return getVoteBonusAmount(Get(player));
|
||||||
|
}
|
||||||
|
|
||||||
|
public BonusAmount getVoteBonusAmount(BonusClientData client)
|
||||||
|
{
|
||||||
|
double mult = getVoteMultiplyer(client) / 100.0;
|
||||||
|
|
||||||
BonusAmount amount = new BonusAmount();
|
BonusAmount amount = new BonusAmount();
|
||||||
amount.setTickets(1);
|
amount.setTickets(1);
|
||||||
|
@ -131,7 +131,7 @@ 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(C.cYellow + "Streak Bonus: " + C.cWhite + "+" + _bonusManager.getVoteMultiplyer(client) + "%");
|
||||||
if (client.getVoteTime() != null)
|
if (client.getVoteTime() != null)
|
||||||
{
|
{
|
||||||
long lastBonus = _bonusManager.getLocalTime(client.getVoteTime().getTime());
|
long lastBonus = _bonusManager.getLocalTime(client.getVoteTime().getTime());
|
||||||
|
@ -3,6 +3,7 @@ package mineplex.votifier;
|
|||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import mineplex.core.account.CoreClientManager;
|
import mineplex.core.account.CoreClientManager;
|
||||||
|
import mineplex.core.bonuses.BonusManager;
|
||||||
import mineplex.core.command.CommandCenter;
|
import mineplex.core.command.CommandCenter;
|
||||||
import mineplex.core.donation.DonationManager;
|
import mineplex.core.donation.DonationManager;
|
||||||
|
|
||||||
@ -25,8 +26,9 @@ public class Votifier extends JavaPlugin
|
|||||||
CommandCenter.Initialize(this);
|
CommandCenter.Initialize(this);
|
||||||
CoreClientManager clientManager = new CoreClientManager(this, webServerAddress);
|
CoreClientManager clientManager = new CoreClientManager(this, webServerAddress);
|
||||||
DonationManager donationManager = new DonationManager(this, clientManager, webServerAddress);
|
DonationManager donationManager = new DonationManager(this, clientManager, webServerAddress);
|
||||||
|
BonusManager bonusManager = new BonusManager(this, clientManager, donationManager);
|
||||||
|
|
||||||
|
|
||||||
VotifierManager vote = new VotifierManager(this, clientManager, donationManager);
|
VotifierManager vote = new VotifierManager(this, clientManager, donationManager, bonusManager);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package mineplex.votifier;
|
package mineplex.votifier;
|
||||||
|
|
||||||
|
import java.sql.Date;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -9,6 +10,10 @@ 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.bonuses.BonusAmount;
|
||||||
|
import mineplex.core.bonuses.BonusClientData;
|
||||||
|
import mineplex.core.bonuses.BonusManager;
|
||||||
|
import mineplex.core.common.util.Callback;
|
||||||
import mineplex.core.common.util.UUIDFetcher;
|
import mineplex.core.common.util.UUIDFetcher;
|
||||||
import mineplex.core.database.DBPool;
|
import mineplex.core.database.DBPool;
|
||||||
import mineplex.core.donation.DonationManager;
|
import mineplex.core.donation.DonationManager;
|
||||||
@ -23,6 +28,7 @@ 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.DSLContext;
|
||||||
|
import org.jooq.Record1;
|
||||||
import org.jooq.SQLDialect;
|
import org.jooq.SQLDialect;
|
||||||
import org.jooq.impl.DSL;
|
import org.jooq.impl.DSL;
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.Jedis;
|
||||||
@ -36,6 +42,7 @@ public class VotifierManager extends MiniPlugin
|
|||||||
{
|
{
|
||||||
private CoreClientManager _clientManager;
|
private CoreClientManager _clientManager;
|
||||||
private DonationManager _donationManager;
|
private DonationManager _donationManager;
|
||||||
|
private BonusManager _bonusManager;
|
||||||
|
|
||||||
private RedisConfig _usConfig;
|
private RedisConfig _usConfig;
|
||||||
private RedisConfig _euConfig;
|
private RedisConfig _euConfig;
|
||||||
@ -44,12 +51,13 @@ public class VotifierManager extends MiniPlugin
|
|||||||
private JedisPool _usWritePool;
|
private JedisPool _usWritePool;
|
||||||
private JedisPool _euWritePool;
|
private JedisPool _euWritePool;
|
||||||
|
|
||||||
public VotifierManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager)
|
public VotifierManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, BonusManager bonusManager)
|
||||||
{
|
{
|
||||||
super("Votifier", plugin);
|
super("Votifier", plugin);
|
||||||
|
|
||||||
_clientManager = clientManager;
|
_clientManager = clientManager;
|
||||||
_donationManager = donationManager;
|
_donationManager = donationManager;
|
||||||
|
_bonusManager = bonusManager;
|
||||||
|
|
||||||
_usConfig = ServerManager.getConfig("us-redis.dat");
|
_usConfig = ServerManager.getConfig("us-redis.dat");
|
||||||
_euConfig = ServerManager.getConfig("eu-redis.dat");
|
_euConfig = ServerManager.getConfig("eu-redis.dat");
|
||||||
@ -71,7 +79,24 @@ public class VotifierManager extends MiniPlugin
|
|||||||
|
|
||||||
System.out.println("New Vote: " + playerName);
|
System.out.println("New Vote: " + playerName);
|
||||||
|
|
||||||
// UUID uuid = UUIDFetcher.getUUIDOf(playerName);
|
UUID uuid = UUIDFetcher.getUUIDOf(playerName);
|
||||||
|
if (uuid == null)
|
||||||
|
{
|
||||||
|
System.out.println("Failed to load UUID of " + playerName + " from UUIDFetcher. Trying with database");
|
||||||
|
uuid = _clientManager.loadUUIDFromDB(playerName);
|
||||||
|
|
||||||
|
if (uuid == null)
|
||||||
|
{
|
||||||
|
System.out.println("Failed to load UUID from database. Giving up on " + playerName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Loaded " + playerName + " with uuid " + uuid);
|
||||||
|
System.out.println("Attempting to award bonus");
|
||||||
|
awardBonus(playerName, uuid);
|
||||||
|
System.out.println();
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
// UUID uuid = _clientManager.loadUUIDFromDB(playerName);
|
// UUID uuid = _clientManager.loadUUIDFromDB(playerName);
|
||||||
// if (uuid != null)
|
// if (uuid != null)
|
||||||
// {
|
// {
|
||||||
@ -116,13 +141,61 @@ public class VotifierManager extends MiniPlugin
|
|||||||
publishCommand(command, writePool);
|
publishCommand(command, writePool);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void awardBonus(UUID uuid)
|
private void awardBonus(final String playerName, UUID uuid)
|
||||||
{
|
{
|
||||||
// Don't use this right now!
|
|
||||||
DSLContext create = DSL.using(DBPool.ACCOUNT, SQLDialect.MYSQL);
|
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();
|
Record1<Integer> idRecord = create.select(Tables.accounts.id).from(Tables.accounts).where(Tables.accounts.uuid.eq(uuid.toString())).fetchOne();
|
||||||
System.out.println("Ran query with response: " + updated);
|
if (idRecord != null)
|
||||||
|
{
|
||||||
|
final int accountId = idRecord.value1();
|
||||||
|
final BonusClientData client = new BonusClientData(_bonusManager.getRepository().loadRecord(playerName, accountId));
|
||||||
|
|
||||||
|
final BonusAmount amount = _bonusManager.getVoteBonusAmount(client);
|
||||||
|
|
||||||
|
// Reward Amount
|
||||||
|
if (amount.getTickets() > 0)
|
||||||
|
client.setTickets(client.getTickets() + amount.getTickets());
|
||||||
|
|
||||||
|
if (amount.getGems() > 0)
|
||||||
|
{
|
||||||
|
_donationManager.RewardGems(new Callback<Boolean>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run(Boolean data)
|
||||||
|
{
|
||||||
|
if (data)
|
||||||
|
System.out.println("Gave " + amount.getGems() + " gems to " + playerName);
|
||||||
|
else
|
||||||
|
System.out.println("Failed to give " + amount.getGems() + " gems to " + playerName);
|
||||||
|
}
|
||||||
|
}, "Votifier", playerName, uuid, amount.getGems());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (amount.getCoins() > 0)
|
||||||
|
{
|
||||||
|
_donationManager.RewardCoins(new Callback<Boolean>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run(Boolean data)
|
||||||
|
{
|
||||||
|
if (data)
|
||||||
|
System.out.println("Gave " + amount.getGems() + " coins to " + playerName);
|
||||||
|
else
|
||||||
|
System.out.println("Failed to give " + amount.getGems() + " coins to " + playerName);
|
||||||
|
}
|
||||||
|
}, "Votifier", playerName, accountId, amount.getCoins());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update time
|
||||||
|
client.getRecord().setVotetime(new Date(_bonusManager.getSqlTime()));
|
||||||
|
|
||||||
|
// Update Streak
|
||||||
|
_bonusManager.incrementVoteStreak(client);
|
||||||
|
|
||||||
|
client.getRecord().store();
|
||||||
|
System.out.println("Awarded carl ticket to " + playerName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void publishCommand(final ServerCommand serverCommand, final JedisPool writePool)
|
private void publishCommand(final ServerCommand serverCommand, final JedisPool writePool)
|
||||||
|
Loading…
Reference in New Issue
Block a user