Lots of bonus work, start adding Votifier plugin
This commit is contained in:
parent
bcd4f4f9e2
commit
4cad99eb76
@ -1,5 +1,5 @@
|
||||
<component name="ArtifactManager">
|
||||
<artifact name="Mineplex.Hub:test">
|
||||
<artifact build-on-make="true" name="Mineplex.Hub:test">
|
||||
<output-path>$PROJECT_DIR$/../Testing/Hub/plugins</output-path>
|
||||
<root id="root">
|
||||
<element id="artifact" artifact-name="Mineplex.Hub:jar" />
|
||||
|
@ -1,11 +0,0 @@
|
||||
<component name="libraryTable">
|
||||
<library name="bukkit">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/Libraries/bukkit.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$PROJECT_DIR$/Libraries/bukkit.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
@ -16,6 +16,7 @@
|
||||
<module fileurl="file://$PROJECT_DIR$/Mineplex.PlayerCache/Mineplex.PlayerCache.iml" filepath="$PROJECT_DIR$/Mineplex.PlayerCache/Mineplex.PlayerCache.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/Mineplex.ServerData/Mineplex.ServerData.iml" filepath="$PROJECT_DIR$/Mineplex.ServerData/Mineplex.ServerData.iml" group="Core" />
|
||||
<module fileurl="file://$PROJECT_DIR$/Mineplex.ServerMonitor/Mineplex.ServerMonitor.iml" filepath="$PROJECT_DIR$/Mineplex.ServerMonitor/Mineplex.ServerMonitor.iml" group="Core" />
|
||||
<module fileurl="file://$PROJECT_DIR$/Mineplex.Votifier/Mineplex.Votifier.iml" filepath="$PROJECT_DIR$/Mineplex.Votifier/Mineplex.Votifier.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/Nautilus.Game.Arcade/Nautilus.Game.Arcade.iml" filepath="$PROJECT_DIR$/Nautilus.Game.Arcade/Nautilus.Game.Arcade.iml" group="Game" />
|
||||
</modules>
|
||||
</component>
|
||||
|
@ -24,6 +24,7 @@ public abstract class MiniClientPlugin<DataType extends Object> extends MiniPlug
|
||||
@EventHandler
|
||||
public void UnloadPlayer(ClientUnloadEvent event)
|
||||
{
|
||||
System.out.println("super unload " + this.getClass().getSimpleName());
|
||||
synchronized (_clientDataLock)
|
||||
{
|
||||
_clientData.remove(event.GetName());
|
||||
|
@ -2,6 +2,7 @@ package mineplex.core.account;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
@ -50,6 +51,7 @@ public class CoreClientManager extends MiniPlugin
|
||||
private RedisDataRepository<AccountCache> _accountCacheRepository;
|
||||
|
||||
private NautHashMap<String, ILoginProcessor> _loginProcessors = new NautHashMap<String, ILoginProcessor>();
|
||||
private LinkedList<IQuerylessLoginProcessor> _querylessLoginProcessors = new LinkedList<IQuerylessLoginProcessor>();
|
||||
|
||||
private Object _clientLock = new Object();
|
||||
|
||||
@ -110,7 +112,8 @@ public class CoreClientManager extends MiniPlugin
|
||||
{
|
||||
_clientList.remove(name);
|
||||
}
|
||||
|
||||
|
||||
System.out.println("Call from del");
|
||||
_plugin.getServer().getPluginManager().callEvent(new ClientUnloadEvent(name));
|
||||
}
|
||||
|
||||
@ -135,6 +138,16 @@ public class CoreClientManager extends MiniPlugin
|
||||
return Bukkit.getOnlinePlayers().size() + Math.max(0, _clientsConnecting.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the databse account id for a player. Requires the player is online
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public int getAccountId(Player player)
|
||||
{
|
||||
return Get(player).getAccountId();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void AsyncLogin(AsyncPlayerPreLoginEvent event)
|
||||
{
|
||||
@ -221,7 +234,7 @@ public class CoreClientManager extends MiniPlugin
|
||||
|
||||
CoreClient client = Add(playerName);
|
||||
client.SetRank(Rank.valueOf(token.Rank));
|
||||
client.setAccountId(_repository.login(_loginProcessors, uuid.toString(), client.GetPlayerName()));
|
||||
client.setAccountId(_repository.login(_loginProcessors, _querylessLoginProcessors, uuid.toString(), client.GetPlayerName()));
|
||||
|
||||
// JSON sql response
|
||||
Bukkit.getServer().getPluginManager().callEvent(new ClientWebResponseEvent(response, uuid));
|
||||
@ -261,7 +274,7 @@ public class CoreClientManager extends MiniPlugin
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
client.setAccountId(_repository.login(_loginProcessors, uuid.toString(), client.GetPlayerName()));
|
||||
client.setAccountId(_repository.login(_loginProcessors, _querylessLoginProcessors, uuid.toString(), client.GetPlayerName()));
|
||||
_clientLoginLock.remove(client.GetPlayerName());
|
||||
}
|
||||
});
|
||||
@ -451,7 +464,7 @@ public class CoreClientManager extends MiniPlugin
|
||||
callback.run(matchedName);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
callback.run(matchedName);
|
||||
}
|
||||
}, caller, playerName, true);
|
||||
@ -482,7 +495,9 @@ public class CoreClientManager extends MiniPlugin
|
||||
clientIterator.remove();
|
||||
|
||||
if (clientPlayer != null)
|
||||
{
|
||||
_plugin.getServer().getPluginManager().callEvent(new ClientUnloadEvent(clientPlayer.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -504,6 +519,11 @@ public class CoreClientManager extends MiniPlugin
|
||||
{
|
||||
_loginProcessors.put(processor.getName(), processor);
|
||||
}
|
||||
|
||||
public void addStoredProcedureLoginProcessor(IQuerylessLoginProcessor processor)
|
||||
{
|
||||
_querylessLoginProcessors.add(processor);
|
||||
}
|
||||
|
||||
public boolean hasRank(Player player, Rank rank)
|
||||
{
|
||||
|
@ -0,0 +1,6 @@
|
||||
package mineplex.core.account;
|
||||
|
||||
public interface IQuerylessLoginProcessor
|
||||
{
|
||||
public void processLogin(String playerName, int accountId);
|
||||
}
|
@ -6,6 +6,7 @@ import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -14,6 +15,7 @@ import org.bukkit.craftbukkit.libs.com.google.gson.reflect.TypeToken;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.account.ILoginProcessor;
|
||||
import mineplex.core.account.IQuerylessLoginProcessor;
|
||||
import mineplex.core.account.repository.token.LoginToken;
|
||||
import mineplex.core.account.repository.token.RankUpdateToken;
|
||||
import mineplex.core.common.Rank;
|
||||
@ -55,7 +57,7 @@ public class AccountRepository extends RepositoryBase
|
||||
//executeUpdate(CREATE_ACCOUNT_TABLE);
|
||||
}
|
||||
|
||||
public int login(NautHashMap<String, ILoginProcessor> loginProcessors, String uuid, String name)
|
||||
public int login(NautHashMap<String, ILoginProcessor> loginProcessors, LinkedList<IQuerylessLoginProcessor> querylessLoginProcessors, String uuid, String name)
|
||||
{
|
||||
int accountId = -1;
|
||||
try (
|
||||
@ -145,6 +147,11 @@ public class AccountRepository extends RepositoryBase
|
||||
loginProcessor.processLoginResultSet(name, accountId, statement.getResultSet());
|
||||
statement.getMoreResults();
|
||||
}
|
||||
|
||||
for (IQuerylessLoginProcessor loginProcessor : querylessLoginProcessors)
|
||||
{
|
||||
loginProcessor.processLogin(name, accountId);
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
|
@ -0,0 +1,12 @@
|
||||
package mineplex.core.votifier;
|
||||
|
||||
import mineplex.serverdata.commands.ServerCommand;
|
||||
|
||||
public class RedisVotifierCommand extends ServerCommand
|
||||
{
|
||||
public RedisVotifierCommand()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -16,7 +16,7 @@ package mineplex.database.tables;
|
||||
@java.lang.SuppressWarnings({ "all", "unchecked", "rawtypes" })
|
||||
public class Bonus extends org.jooq.impl.TableImpl<mineplex.database.tables.records.BonusRecord> implements java.io.Serializable, java.lang.Cloneable {
|
||||
|
||||
private static final long serialVersionUID = -524321170;
|
||||
private static final long serialVersionUID = -384307684;
|
||||
|
||||
/**
|
||||
* The reference instance of <code>Account.bonus</code>
|
||||
@ -54,27 +54,27 @@ public class Bonus extends org.jooq.impl.TableImpl<mineplex.database.tables.reco
|
||||
/**
|
||||
* The column <code>Account.bonus.dailyStreak</code>.
|
||||
*/
|
||||
public final org.jooq.TableField<mineplex.database.tables.records.BonusRecord, java.lang.Integer> dailyStreak = createField("dailyStreak", org.jooq.impl.SQLDataType.INTEGER.nullable(false), this, "");
|
||||
public final org.jooq.TableField<mineplex.database.tables.records.BonusRecord, java.lang.Integer> dailyStreak = createField("dailyStreak", org.jooq.impl.SQLDataType.INTEGER.defaulted(true), this, "");
|
||||
|
||||
/**
|
||||
* The column <code>Account.bonus.maxDailyStreak</code>.
|
||||
*/
|
||||
public final org.jooq.TableField<mineplex.database.tables.records.BonusRecord, java.lang.Integer> maxDailyStreak = createField("maxDailyStreak", org.jooq.impl.SQLDataType.INTEGER.nullable(false), this, "");
|
||||
public final org.jooq.TableField<mineplex.database.tables.records.BonusRecord, java.lang.Integer> maxDailyStreak = createField("maxDailyStreak", org.jooq.impl.SQLDataType.INTEGER.defaulted(true), this, "");
|
||||
|
||||
/**
|
||||
* The column <code>Account.bonus.voteStreak</code>.
|
||||
*/
|
||||
public final org.jooq.TableField<mineplex.database.tables.records.BonusRecord, java.lang.Integer> voteStreak = createField("voteStreak", org.jooq.impl.SQLDataType.INTEGER.nullable(false), this, "");
|
||||
public final org.jooq.TableField<mineplex.database.tables.records.BonusRecord, java.lang.Integer> voteStreak = createField("voteStreak", org.jooq.impl.SQLDataType.INTEGER.defaulted(true), this, "");
|
||||
|
||||
/**
|
||||
* The column <code>Account.bonus.maxVoteStreak</code>.
|
||||
*/
|
||||
public final org.jooq.TableField<mineplex.database.tables.records.BonusRecord, java.lang.Integer> maxVoteStreak = createField("maxVoteStreak", org.jooq.impl.SQLDataType.INTEGER.nullable(false), this, "");
|
||||
public final org.jooq.TableField<mineplex.database.tables.records.BonusRecord, java.lang.Integer> maxVoteStreak = createField("maxVoteStreak", org.jooq.impl.SQLDataType.INTEGER.defaulted(true), this, "");
|
||||
|
||||
/**
|
||||
* The column <code>Account.bonus.tickets</code>.
|
||||
*/
|
||||
public final org.jooq.TableField<mineplex.database.tables.records.BonusRecord, java.lang.Integer> tickets = createField("tickets", org.jooq.impl.SQLDataType.INTEGER.nullable(false), this, "");
|
||||
public final org.jooq.TableField<mineplex.database.tables.records.BonusRecord, java.lang.Integer> tickets = createField("tickets", org.jooq.impl.SQLDataType.INTEGER.defaulted(true), this, "");
|
||||
|
||||
/**
|
||||
* Create a <code>Account.bonus</code> table reference
|
||||
|
@ -83,12 +83,12 @@ public class BonusAmount
|
||||
|
||||
public int getTotalGems()
|
||||
{
|
||||
return getGems() + getBonusCoins();
|
||||
return getGems() + getBonusGems();
|
||||
}
|
||||
|
||||
public int getTotalCoins()
|
||||
{
|
||||
return getGems() + getBonusGems();
|
||||
return getCoins() + getBonusCoins();
|
||||
}
|
||||
|
||||
public int getTotalGold()
|
||||
@ -149,10 +149,9 @@ public class BonusAmount
|
||||
private void addLore(List<String> lore, int amount, int bonus, String suffix)
|
||||
{
|
||||
if (amount > 0)
|
||||
{
|
||||
lore.add(C.cYellow + "Reward: " + C.cWhite + amount + " " + suffix);
|
||||
if (bonus > 0)
|
||||
lore.add(C.cYellow + "Streak Bonus: " + C.cWhite + bonus + " " + suffix);
|
||||
}
|
||||
|
||||
if (bonus > 0)
|
||||
lore.add(C.cYellow + "Streak Bonus: " + C.cWhite + bonus + " " + suffix);
|
||||
}
|
||||
}
|
||||
|
@ -9,93 +9,103 @@ public class BonusClientData
|
||||
{
|
||||
private BonusRecord _record;
|
||||
|
||||
public BonusClientData(BonusRecord record)
|
||||
{
|
||||
_record = record;
|
||||
}
|
||||
|
||||
public BonusRecord getRecord()
|
||||
{
|
||||
return _record;
|
||||
}
|
||||
|
||||
public void setAccountId(Integer value)
|
||||
{
|
||||
_record.setAccountId(value);
|
||||
}
|
||||
|
||||
public Integer getAccountId()
|
||||
{
|
||||
return _record.getAccountId();
|
||||
}
|
||||
|
||||
public void setDailyTime(Timestamp value)
|
||||
{
|
||||
_record.setDailytime(value);
|
||||
}
|
||||
|
||||
private Timestamp _dailyTime;
|
||||
private Date _rankTime;
|
||||
private Date _voteTime;
|
||||
private int _dailyStreak;
|
||||
private int _maxDailyStreak;
|
||||
private int _voteStreak;
|
||||
private int _maxVoteStreak;
|
||||
private int _tickets;
|
||||
|
||||
public Timestamp getDailyTime()
|
||||
{
|
||||
return _dailyTime;
|
||||
return _record.getDailytime();
|
||||
}
|
||||
|
||||
public void setDailyTime(Timestamp dailyTime)
|
||||
|
||||
public void setRankTime(Date value)
|
||||
{
|
||||
this._dailyTime = dailyTime;
|
||||
_record.setRanktime(value);
|
||||
}
|
||||
|
||||
|
||||
public Date getRankTime()
|
||||
{
|
||||
return _rankTime;
|
||||
return _record.getRanktime();
|
||||
}
|
||||
|
||||
public void setRankTime(Date rankTime)
|
||||
|
||||
public void setVoteTime(Date value)
|
||||
{
|
||||
this._rankTime = rankTime;
|
||||
_record.setVotetime(value);
|
||||
}
|
||||
|
||||
|
||||
public Date getVoteTime()
|
||||
{
|
||||
return _voteTime;
|
||||
}
|
||||
|
||||
public void setVoteTime(Date _voteTime)
|
||||
{
|
||||
this._voteTime = _voteTime;
|
||||
return _record.getVotetime();
|
||||
}
|
||||
|
||||
public int getDailyStreak()
|
||||
public void setDailyStreak(Integer value)
|
||||
{
|
||||
return _dailyStreak;
|
||||
_record.setDailyStreak(value);
|
||||
}
|
||||
|
||||
public void setDailyStreak(int dailyStreak)
|
||||
public Integer getDailyStreak()
|
||||
{
|
||||
_dailyStreak = dailyStreak;
|
||||
return _record.getDailyStreak();
|
||||
}
|
||||
|
||||
public int getMaxDailyStreak()
|
||||
public void setMaxDailyStreak(Integer value)
|
||||
{
|
||||
return _maxDailyStreak;
|
||||
_record.setMaxDailyStreak(value);
|
||||
}
|
||||
|
||||
public void setMaxDailyStreak(int maxDailyStreak)
|
||||
public Integer getMaxDailyStreak()
|
||||
{
|
||||
_maxDailyStreak = maxDailyStreak;
|
||||
return _record.getMaxDailyStreak();
|
||||
}
|
||||
|
||||
public void setVoteStreak(int voteStreak)
|
||||
public void setVoteStreak(Integer value)
|
||||
{
|
||||
_voteStreak = voteStreak;
|
||||
_record.setVoteStreak(value);
|
||||
}
|
||||
|
||||
public int getVoteStreak()
|
||||
public Integer getVoteStreak()
|
||||
{
|
||||
return _voteStreak;
|
||||
return _record.getVoteStreak();
|
||||
}
|
||||
|
||||
public void setMaxVoteStreak(int maxVoteStreak)
|
||||
public void setMaxVoteStreak(Integer value)
|
||||
{
|
||||
_maxVoteStreak = maxVoteStreak;
|
||||
_record.setMaxVoteStreak(value);
|
||||
}
|
||||
|
||||
public int getMaxVoteStreak()
|
||||
public Integer getMaxVoteStreak()
|
||||
{
|
||||
return _maxVoteStreak;
|
||||
return _record.getMaxVoteStreak();
|
||||
}
|
||||
|
||||
public int getTickets()
|
||||
public void setTickets(Integer value)
|
||||
{
|
||||
return _tickets;
|
||||
_record.setTickets(value);
|
||||
}
|
||||
|
||||
public void setTickets(int tickets)
|
||||
public Integer getTickets()
|
||||
{
|
||||
_tickets = tickets;
|
||||
return _record.getTickets();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,16 +1,16 @@
|
||||
package mineplex.hub.bonuses;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Calendar;
|
||||
import java.util.TimeZone;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import mineplex.core.MiniDbClientPlugin;
|
||||
import mineplex.core.MiniClientPlugin;
|
||||
import mineplex.core.account.CoreClient;
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.account.IQuerylessLoginProcessor;
|
||||
import mineplex.core.account.event.ClientUnloadEvent;
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.util.Callback;
|
||||
import mineplex.core.common.util.F;
|
||||
@ -20,6 +20,7 @@ import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.hub.bonuses.commands.GuiCommand;
|
||||
import mineplex.hub.bonuses.gui.BonusGui;
|
||||
import mineplex.database.tables.records.BonusRecord;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
@ -29,7 +30,8 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class BonusManager extends MiniDbClientPlugin<BonusClientData> {
|
||||
public class BonusManager extends MiniClientPlugin<BonusClientData> implements IQuerylessLoginProcessor
|
||||
{
|
||||
|
||||
public static final TimeZone TIMEZONE = TimeZone.getTimeZone("UTC");
|
||||
|
||||
@ -69,15 +71,19 @@ public class BonusManager extends MiniDbClientPlugin<BonusClientData> {
|
||||
}
|
||||
|
||||
private BonusRepository _repository;
|
||||
private CoreClientManager _clientManager;
|
||||
private DonationManager _donationManager;
|
||||
|
||||
public BonusManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager)
|
||||
{
|
||||
super("Bonus", plugin, clientManager);
|
||||
super("Bonus", plugin);
|
||||
_repository = new BonusRepository(plugin, this, donationManager);
|
||||
_clientManager = clientManager;
|
||||
_donationManager = donationManager;
|
||||
|
||||
clientManager.addStoredProcedureLoginProcessor(this);
|
||||
|
||||
updateOffSet();
|
||||
registerSelf();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -98,7 +104,8 @@ public class BonusManager extends MiniDbClientPlugin<BonusClientData> {
|
||||
|
||||
// DAILY BONUS
|
||||
|
||||
private static final long TIME_BETWEEN_BONUSES = 1000 * 60 * 60 * 8;
|
||||
public static final long TIME_BETWEEN_BONUSES = 1000 * 60 * 60 * 16;
|
||||
public static final long STREAK_RESET_TIME = 1000 * 60 * 60 * 8;
|
||||
|
||||
public void attemptDailyBonus(final Player player, final BonusAmount amount, final Consumer<Boolean> result)
|
||||
{
|
||||
@ -112,9 +119,11 @@ public class BonusManager extends MiniDbClientPlugin<BonusClientData> {
|
||||
{
|
||||
if (r)
|
||||
{
|
||||
incrementDailyStreak(player);
|
||||
awardBonus(player, amount);
|
||||
result.accept(r);
|
||||
}
|
||||
|
||||
result.accept(r);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -123,12 +132,11 @@ public class BonusManager extends MiniDbClientPlugin<BonusClientData> {
|
||||
{
|
||||
return nextDailyBonus(player) - getLocalTime();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// This calculates the the next daily bonus, IT HAS TO MATCH THE MYSQL STORED FUNCTION.
|
||||
public long nextDailyBonus(Player player)
|
||||
{
|
||||
Timestamp timestamp = Get(player).getDailyTime();
|
||||
Timestamp timestamp = Get(player).getRecord().getDailytime();
|
||||
|
||||
if (timestamp == null)
|
||||
return 0;
|
||||
@ -156,7 +164,7 @@ public class BonusManager extends MiniDbClientPlugin<BonusClientData> {
|
||||
// This calculates the the next rank bonus, IT HAS TO MATCH THE MYSQL STORED FUNCTION.
|
||||
public long nextRankBonus(Player player)
|
||||
{
|
||||
Date date = Get(player).getRankTime();
|
||||
Date date = Get(player).getRecord().getRanktime();
|
||||
|
||||
if (date == null)
|
||||
return 0;
|
||||
@ -165,10 +173,47 @@ public class BonusManager extends MiniDbClientPlugin<BonusClientData> {
|
||||
|
||||
|
||||
return getNextRankBonusTime(getLocalTime(lastBonus));
|
||||
|
||||
}
|
||||
|
||||
public void updateDailyStreak(Player player)
|
||||
{
|
||||
BonusClientData client = Get(player);
|
||||
if (client.getDailyStreak() > 0 && client.getDailyTime() != null)
|
||||
{
|
||||
long lastBonus = getLocalTime(client.getDailyTime().getTime());
|
||||
long timeLeft = getStreakTimeRemaining(lastBonus, BonusManager.STREAK_RESET_TIME);
|
||||
|
||||
if (timeLeft < 0)
|
||||
{
|
||||
client.setDailyStreak(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void incrementDailyStreak(Player player)
|
||||
{
|
||||
BonusClientData data = Get(player);
|
||||
|
||||
data.setDailyStreak(data.getDailyStreak() + 1);
|
||||
|
||||
if (data.getDailyStreak() > data.getMaxDailyStreak())
|
||||
data.setMaxDailyStreak(data.getDailyStreak());
|
||||
}
|
||||
|
||||
public boolean continueStreak(long localLastBonus, long extendTime)
|
||||
{
|
||||
long maxTime = localLastBonus + TIME_BETWEEN_BONUSES + extendTime;
|
||||
return System.currentTimeMillis() < maxTime;
|
||||
}
|
||||
|
||||
public long getStreakTimeRemaining(long localLastBonus, long extendTime)
|
||||
{
|
||||
long maxTime = localLastBonus + TIME_BETWEEN_BONUSES + extendTime;
|
||||
return maxTime - System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public static long getNextRankBonusTime(long time) {
|
||||
public static long getNextRankBonusTime(long time)
|
||||
{
|
||||
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTimeZone(TIMEZONE);
|
||||
@ -189,13 +234,14 @@ public class BonusManager extends MiniDbClientPlugin<BonusClientData> {
|
||||
{
|
||||
BonusAmount amount = new BonusAmount();
|
||||
amount.setTickets(1);
|
||||
amount.setBonusCoins(200);
|
||||
amount.setBonusCoins(100);
|
||||
amount.setBonusExperience(1000);
|
||||
return amount;
|
||||
}
|
||||
|
||||
public BonusAmount getRankBonusAmount(Player player)
|
||||
{
|
||||
Rank rank = getClientManager().Get(player).GetRank();
|
||||
Rank rank = _clientManager.Get(player).GetRank();
|
||||
|
||||
BonusClientData client = Get(player);
|
||||
double multiplyer = 0.25; // TODO
|
||||
@ -250,7 +296,7 @@ public class BonusManager extends MiniDbClientPlugin<BonusClientData> {
|
||||
public void awardBonus(final Player player, BonusAmount amount)
|
||||
{
|
||||
BonusClientData bonusClient = Get(player);
|
||||
CoreClient coreClient = getClientManager().Get(player);
|
||||
CoreClient coreClient = _clientManager.Get(player);
|
||||
|
||||
final int gems = amount.getTotalGems();
|
||||
final int gold = amount.getTotalGold();
|
||||
@ -335,6 +381,7 @@ public class BonusManager extends MiniDbClientPlugin<BonusClientData> {
|
||||
Entity entity = event.getRightClicked();
|
||||
if (entity instanceof LivingEntity && entity.getType().equals(EntityType.CREEPER) && ((LivingEntity) entity).getCustomName().startsWith("Carl"))
|
||||
{
|
||||
updateDailyStreak(event.getPlayer());
|
||||
new BonusGui(_plugin, event.getPlayer(), this).openInventory();
|
||||
}
|
||||
}
|
||||
@ -354,24 +401,11 @@ public class BonusManager extends MiniDbClientPlugin<BonusClientData> {
|
||||
return calendar.getTimeInMillis();
|
||||
}
|
||||
|
||||
|
||||
// OTHER
|
||||
@Override
|
||||
protected BonusClientData AddPlayer(String player)
|
||||
{
|
||||
return new BonusClientData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processLoginResultSet(String playerName, int accountId, ResultSet resultSet) throws SQLException
|
||||
{
|
||||
Set(playerName, _repository.loadClientInformation(resultSet));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getQuery(int accountId, String uuid, String name)
|
||||
{
|
||||
return "SELECT dailytime, ranktime, votetime, dailyStreak, maxDailyStreak, voteStreak, maxVoteStreak, tickets FROM bonus WHERE accountId = '" + accountId + "';";
|
||||
// Should never be called!
|
||||
return null;
|
||||
}
|
||||
|
||||
public BonusRepository getRepository()
|
||||
@ -379,6 +413,34 @@ public class BonusManager extends MiniDbClientPlugin<BonusClientData> {
|
||||
return _repository;
|
||||
}
|
||||
|
||||
public CoreClientManager getClientManager()
|
||||
{
|
||||
return _clientManager;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@EventHandler
|
||||
public void UnloadPlayer(final ClientUnloadEvent event)
|
||||
{
|
||||
final BonusClientData clientData = Get(event.GetName());
|
||||
|
||||
runAsync(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
clientData.getRecord().store();
|
||||
}
|
||||
});
|
||||
|
||||
super.UnloadPlayer(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processLogin(String playerName, int accountId)
|
||||
{
|
||||
BonusRecord record = _repository.loadRecord(playerName, accountId);
|
||||
BonusClientData clientData = new BonusClientData(record);
|
||||
Set(playerName, clientData);
|
||||
}
|
||||
}
|
@ -16,7 +16,9 @@ import mineplex.core.database.RepositoryBase;
|
||||
import mineplex.core.database.ResultSetCallable;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
import mineplex.core.recharge.Recharge;
|
||||
import mineplex.database.Tables;
|
||||
import mineplex.database.tables.records.BonusRecord;
|
||||
import org.jooq.DSLContext;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -25,10 +27,6 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class BonusRepository extends RepositoryBase
|
||||
{
|
||||
|
||||
// private static String INSERT_ACCOUNT =
|
||||
// "INSERT INTO accountPreferences (uuid) VALUES (?) ON DUPLICATE KEY UPDATE uuid=uuid;";
|
||||
|
||||
private static String CREATE_BONUS_TABLE = "CREATE TABLE IF NOT EXISTS bonus (accountId INT NOT NULL AUTO_INCREMENT, dailytime TIMESTAMP NULL DEFAULT NULL, ranktime DATE NULL DEFAULT NULL, PRIMARY KEY (accountId), FOREIGN KEY (accountId) REFERENCES accounts(id));";
|
||||
private BonusManager _manager;
|
||||
private DonationManager _donationManager;
|
||||
@ -40,23 +38,26 @@ public class BonusRepository extends RepositoryBase
|
||||
_donationManager = donationManager;
|
||||
}
|
||||
|
||||
public BonusClientData loadClientInformation(ResultSet resultSet) throws SQLException
|
||||
public BonusRecord loadRecord(String playerName, int accountId)
|
||||
{
|
||||
BonusClientData clientData = new BonusClientData();
|
||||
DSLContext create = jooq();
|
||||
|
||||
while (resultSet.next())
|
||||
BonusRecord record = create.selectFrom(Tables.bonus).where(Tables.bonus.accountId.eq(accountId)).fetchOne();
|
||||
|
||||
if (record == null)
|
||||
{
|
||||
clientData.setDailyTime(resultSet.getTimestamp(1));
|
||||
clientData.setRankTime(resultSet.getDate(2));
|
||||
clientData.setVoteTime(resultSet.getDate(3));
|
||||
clientData.setDailyStreak(resultSet.getInt(4));
|
||||
clientData.setMaxDailyStreak(resultSet.getInt(5));
|
||||
clientData.setVoteStreak(resultSet.getInt(6));
|
||||
clientData.setMaxVoteStreak(resultSet.getInt(7));
|
||||
clientData.setTickets(resultSet.getInt(8));
|
||||
// Need to create new record!
|
||||
record = create.newRecord(Tables.bonus);
|
||||
record.setAccountId(accountId);
|
||||
record.setDailyStreak(0);
|
||||
record.setMaxDailyStreak(0);
|
||||
record.setVoteStreak(0);
|
||||
record.setMaxVoteStreak(0);
|
||||
record.setTickets(0);
|
||||
// record.store(); // Todo - is this necessary?
|
||||
}
|
||||
|
||||
return clientData;
|
||||
return record;
|
||||
}
|
||||
|
||||
public void attemptDailyBonus(final Player player, final Consumer<Boolean> result)
|
||||
@ -66,19 +67,21 @@ public class BonusRepository extends RepositoryBase
|
||||
return;
|
||||
}
|
||||
final int accountId = _manager.getClientManager().Get(player).getAccountId();
|
||||
final int coins = 500;
|
||||
final int gems = 500;
|
||||
final int coins = 0;
|
||||
final int gems = 0;
|
||||
/*
|
||||
* if (coins == 0 && gems == 0) { result.accept(false); return; }
|
||||
*/
|
||||
final JavaPlugin plug = _manager.getPlugin();
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plug, new Runnable() {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plug, new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try (Connection connection = getConnection();
|
||||
CallableStatement callableStatement = connection.prepareCall("{call check_daily(?, ?, ?, ?, ?)}")) {
|
||||
CallableStatement callableStatement = connection.prepareCall("{call check_daily(?, ?, ?, ?, ?)}"))
|
||||
{
|
||||
callableStatement.setInt(1, accountId);
|
||||
callableStatement.setInt(2, coins);
|
||||
callableStatement.setInt(3, gems);
|
||||
@ -91,44 +94,30 @@ public class BonusRepository extends RepositoryBase
|
||||
|
||||
final Timestamp timeStamp = callableStatement.getTimestamp(5);
|
||||
|
||||
Bukkit.getScheduler().runTask(plug, new Runnable() {
|
||||
_manager.Get(player).getRecord().update();
|
||||
|
||||
Bukkit.getScheduler().runTask(plug, new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
|
||||
if (pass) {
|
||||
if (pass)
|
||||
{
|
||||
_manager.Get(player).setDailyTime(new Timestamp(BonusManager.getSqlTime()));
|
||||
|
||||
_donationManager.RewardCoins(new Callback<Boolean>() {
|
||||
|
||||
@Override
|
||||
public void run(Boolean data)
|
||||
{
|
||||
if (data == false)
|
||||
UtilPlayer.message(player, F.main("Fail", "Coins failed..."));
|
||||
}
|
||||
}, "Daily bonus", player.getName(), accountId, coins);
|
||||
|
||||
_donationManager.RewardGems(new Callback<Boolean>() {
|
||||
|
||||
@Override
|
||||
public void run(Boolean data)
|
||||
{
|
||||
if (data == false)
|
||||
UtilPlayer.message(player, F.main("Fail", "Gems failed..."));
|
||||
}
|
||||
}, "Daily bonus", player.getName(), player.getUniqueId(), gems);
|
||||
|
||||
result.accept(true);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
Recharge.Instance.use(player, "AttemptDailyBonus", 1000 * 10, false, false);
|
||||
_manager.Get(player).setDailyTime(timeStamp);
|
||||
result.accept(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Recharge.Instance.use(player, "AttemptDailyBonus", 1000 * 30, false, false);
|
||||
e.printStackTrace();
|
||||
result.accept(false);
|
||||
@ -195,7 +184,8 @@ public class BonusRepository extends RepositoryBase
|
||||
|
||||
}, "Rank bonus", player.getName(), accountId, coins);
|
||||
|
||||
_donationManager.RewardGems(new Callback<Boolean>() {
|
||||
_donationManager.RewardGems(new Callback<Boolean>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public void run(Boolean data)
|
||||
@ -320,8 +310,6 @@ public class BonusRepository extends RepositoryBase
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void initialize()
|
||||
{
|
||||
|
@ -150,11 +150,23 @@ public class DailyBonusButton implements GuiItem, Listener {
|
||||
|
||||
BonusClientData client = _bonusManager.Get(_player);
|
||||
|
||||
BonusAmount bonusAmount = _bonusManager.getRankBonusAmount(_player);
|
||||
BonusAmount bonusAmount = _bonusManager.getDailyBonusAmount(_player);
|
||||
bonusAmount.addLore(lore);
|
||||
|
||||
lore.add(C.cYellow + "Current Streak: " + C.cWhite + client.getDailyStreak());
|
||||
lore.add(C.cYellow + "Highest Streak: " + C.cWhite + client.getMaxDailyStreak());
|
||||
|
||||
if (client.getDailyTime() != null)
|
||||
{
|
||||
long lastBonus = _bonusManager.getLocalTime(client.getDailyTime().getTime());
|
||||
long timeLeft = _bonusManager.getStreakTimeRemaining(lastBonus, BonusManager.STREAK_RESET_TIME);
|
||||
|
||||
if (timeLeft > 0)
|
||||
{
|
||||
lore.add(C.cYellow + "Streak Reset: " + C.cWhite + UtilTime.convertString(timeLeft, 1, TimeUnit.FIT));
|
||||
}
|
||||
}
|
||||
|
||||
lore.add(" ");
|
||||
lore.add(C.cYellow + "Record Holder: " + C.cWhite + "Phinary");
|
||||
lore.add(C.cYellow + "Streak: " + C.cWhite + "420");
|
||||
|
22
Plugins/Mineplex.Votifier/Mineplex.Votifier.iml
Normal file
22
Plugins/Mineplex.Votifier/Mineplex.Votifier.iml
Normal file
@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="jar://$MODULE_DIR$/../Libraries/Votifier.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module" module-name="Mineplex.Core" />
|
||||
<orderEntry type="library" name="craftbukkit" level="project" />
|
||||
</component>
|
||||
</module>
|
3
Plugins/Mineplex.Votifier/plugin.yml
Normal file
3
Plugins/Mineplex.Votifier/plugin.yml
Normal file
@ -0,0 +1,3 @@
|
||||
name: Hub
|
||||
main: mineplex.votifier.Votifier
|
||||
version: 0.1
|
@ -0,0 +1,30 @@
|
||||
package mineplex.votifier;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
|
||||
/**
|
||||
* Created by shaun on 15-08-05.
|
||||
*/
|
||||
public class Votifier extends JavaPlugin
|
||||
{
|
||||
private String WEB_CONFIG = "webServer";
|
||||
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
getConfig().addDefault(WEB_CONFIG, "http://accounts.mineplex.com/");
|
||||
getConfig().set(WEB_CONFIG, getConfig().getString(WEB_CONFIG));
|
||||
saveConfig();
|
||||
|
||||
String webServerAddress = getConfig().getString(WEB_CONFIG);
|
||||
|
||||
CoreClientManager clientManager = new CoreClientManager(this, webServerAddress);
|
||||
DonationManager donationManager = new DonationManager(this, clientManager, webServerAddress);
|
||||
|
||||
|
||||
VotifierManager vote = new VotifierManager(this, clientManager, donationManager);
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package mineplex.votifier;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.vexsoftware.votifier.model.Vote;
|
||||
import com.vexsoftware.votifier.model.VotifierEvent;
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
|
||||
/**
|
||||
* Created by shaun on 15-08-05.
|
||||
*/
|
||||
public class VotifierManager extends MiniPlugin
|
||||
{
|
||||
public VotifierManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager)
|
||||
{
|
||||
super("Votifier", plugin);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void handleVote(VotifierEvent event)
|
||||
{
|
||||
Vote vote = event.getVote();
|
||||
|
||||
System.out.println("New Vote: " + vote.getUsername());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user