Refactored RankBenefitsGiver9000

Added Thanksgiving benefits (1 treasure key).

ServerMonitor now ignores Testing group.
This commit is contained in:
Jonathan Williams 2014-11-20 21:24:23 -08:00
parent 77b47c9e13
commit 6c63552480
10 changed files with 255 additions and 126 deletions

View File

@ -1,123 +0,0 @@
package mineplex.core;
import java.util.HashSet;
import mineplex.core.account.CoreClientManager;
import mineplex.core.account.event.RetrieveClientInformationEvent;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.inventory.InventoryManager;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
public class RankBenefitsGiver9000 extends MiniPlugin
{
private CoreClientManager _clientManager;
private InventoryManager _inventoryManager;
private RankBenefitsGiver9000Repository _repository;
private NautHashMap<String, String> _playersNeedingBenefit = new NautHashMap<String, String>();
public RankBenefitsGiver9000(JavaPlugin plugin, CoreClientManager clientManager, InventoryManager inventoryManager)
{
super("RankBenefitsGiver9000", plugin);
_clientManager = clientManager;
_inventoryManager = inventoryManager;
_repository = new RankBenefitsGiver9000Repository(plugin);
}
@EventHandler
public void loadPlayer(RetrieveClientInformationEvent event)
{
boolean treasureUpdate = false;
boolean horrorUpdate = false;
for (String benefit : _repository.retrievePlayerBenefits(event.getUniqueId().toString()))
{
if (benefit.equalsIgnoreCase("TreasureUpdate"))
treasureUpdate = true;
if (benefit.equalsIgnoreCase("HalloweenHorror"))
horrorUpdate = true;
}
if (!horrorUpdate)
{
_playersNeedingBenefit.put(event.getPlayerName(), "Horror");
}
if (!treasureUpdate)
{
_playersNeedingBenefit.put(event.getPlayerName(), "Treasure");
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void giveBenefit(final PlayerJoinEvent event)
{
if (!_playersNeedingBenefit.containsKey(event.getPlayer().getName()))
return;
if (_playersNeedingBenefit.get(event.getPlayer().getName()).contains("Horror"))
{
_inventoryManager.addItemToInventory(event.getPlayer(), "Treasure", "Treasure Key", 2);
Bukkit.getServer().getScheduler().runTaskAsynchronously(GetPlugin(), new Runnable()
{
public void run()
{
_repository.addBenefit(event.getPlayer().getUniqueId().toString(), "HalloweenHorror");
}
});
Bukkit.getServer().getScheduler().runTaskLater(GetPlugin(), new Runnable()
{
public void run()
{
UtilPlayer.message(event.getPlayer(), C.cPurple + C.Strike + "=============================================");
UtilPlayer.message(event.getPlayer(), "");
UtilPlayer.message(event.getPlayer(), C.cGold + C.Strike + "HAPPY HALLOWEEN");
UtilPlayer.message(event.getPlayer(), "You received 2 Treasure Keys!");
UtilPlayer.message(event.getPlayer(), "");
UtilPlayer.message(event.getPlayer(), C.cPurple + C.Strike + "=============================================");
}
}, 5L);
}
else if (_playersNeedingBenefit.get(event.getPlayer().getName()).contains("Treasure"))
{
if (_clientManager.Get(event.getPlayer()).GetRank() == Rank.ALL)
{
_inventoryManager.addItemToInventory(event.getPlayer(), "Utility", "Treasure Chest", 1);
_inventoryManager.addItemToInventory(event.getPlayer(), "Treasure", "Treasure Key", 1);
}
else if (_clientManager.Get(event.getPlayer()).GetRank() == Rank.ULTRA)
{
_inventoryManager.addItemToInventory(event.getPlayer(), "Utility", "Treasure Chest", 20);
_inventoryManager.addItemToInventory(event.getPlayer(), "Treasure", "Treasure Key", 5);
}
else
{
_inventoryManager.addItemToInventory(event.getPlayer(), "Utility", "Treasure Chest", 40);
_inventoryManager.addItemToInventory(event.getPlayer(), "Treasure", "Treasure Key", 10);
}
Bukkit.getServer().getScheduler().runTaskAsynchronously(GetPlugin(), new Runnable()
{
public void run()
{
_repository.addBenefit(event.getPlayer().getUniqueId().toString(), "TreasureUpdate");
}
});
}
_playersNeedingBenefit.remove(event.getPlayer().getName());
}
}

View File

@ -0,0 +1,8 @@
package mineplex.core.benefit;
import java.util.HashSet;
public class PlayerBenefit
{
public HashSet<String> Benefits = new HashSet<String>();
}

View File

@ -0,0 +1,68 @@
package mineplex.core.benefit;
import java.util.ArrayList;
import java.util.List;
import mineplex.core.MiniClientPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.account.event.RetrieveClientInformationEvent;
import mineplex.core.benefit.benefits.BenefitBase;
import mineplex.core.benefit.benefits.HalloweenHorror2014;
import mineplex.core.benefit.benefits.Thanksgiving2014;
import mineplex.core.benefit.benefits.TreasureRelease;
import mineplex.core.inventory.InventoryManager;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
public class RankBenefitsGiver9000 extends MiniClientPlugin<PlayerBenefit>
{
private RankBenefitsGiver9000Repository _repository;
private List<BenefitBase> _benefits = new ArrayList<BenefitBase>();
public RankBenefitsGiver9000(JavaPlugin plugin, CoreClientManager clientManager, InventoryManager inventoryManager)
{
super("RankBenefitsGiver9000", plugin);
_repository = new RankBenefitsGiver9000Repository(plugin);
_benefits.add(new HalloweenHorror2014(plugin, _repository, inventoryManager));
_benefits.add(new TreasureRelease(plugin, _repository, inventoryManager, clientManager));
_benefits.add(new Thanksgiving2014(plugin, _repository, inventoryManager));
}
@EventHandler(priority = EventPriority.LOWEST)
public void giveBenefit(final PlayerJoinEvent event)
{
for (BenefitBase benefit : _benefits)
{
if (!Get(event.getPlayer()).Benefits.contains(benefit.getName()))
{
benefit.rewardPlayer(event.getPlayer());
benefit.recordBenefit(event.getPlayer());
}
}
}
@Override
protected PlayerBenefit AddPlayer(String player)
{
return new PlayerBenefit();
}
@Override
protected void loadClientInformation(RetrieveClientInformationEvent event)
{
event.incrementProcessingCount();
for (String benefit : _repository.retrievePlayerBenefits(event.getUniqueId().toString()))
{
Get(event.getPlayerName()).Benefits.add(benefit);
}
event.decreaseProcessingCount();
}
}

View File

@ -1,4 +1,4 @@
package mineplex.core;
package mineplex.core.benefit;
import java.sql.ResultSet;
import java.sql.SQLException;

View File

@ -0,0 +1,49 @@
package mineplex.core.benefit.benefits;
import mineplex.core.benefit.RankBenefitsGiver9000Repository;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public abstract class BenefitBase
{
private JavaPlugin _plugin;
private String _name;
private RankBenefitsGiver9000Repository _repository;
protected BenefitBase(JavaPlugin plugin, String name, RankBenefitsGiver9000Repository repository)
{
_plugin = plugin;
_name = name;
_repository = repository;
}
public JavaPlugin getPlugin()
{
return _plugin;
}
public RankBenefitsGiver9000Repository getRepository()
{
return _repository;
}
public abstract void rewardPlayer(Player player);
public void recordBenefit(final Player player)
{
Bukkit.getServer().getScheduler().runTaskAsynchronously(_plugin, new Runnable()
{
public void run()
{
_repository.addBenefit(player.getUniqueId().toString(), _name);
}
});
}
public String getName()
{
return _name;
}
}

View File

@ -0,0 +1,41 @@
package mineplex.core.benefit.benefits;
import mineplex.core.benefit.RankBenefitsGiver9000Repository;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.inventory.InventoryManager;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class HalloweenHorror2014 extends BenefitBase
{
private InventoryManager _inventoryManager;
public HalloweenHorror2014(JavaPlugin plugin, RankBenefitsGiver9000Repository repository, InventoryManager inventoryManager)
{
super(plugin, "HalloweenHorror", repository);
_inventoryManager = inventoryManager;
}
@Override
public void rewardPlayer(final Player player)
{
_inventoryManager.addItemToInventory(player, "Treasure", "Treasure Key", 2);
Bukkit.getServer().getScheduler().runTaskLater(getPlugin(), new Runnable()
{
public void run()
{
UtilPlayer.message(player, C.cPurple + C.Strike + "=============================================");
UtilPlayer.message(player, "");
UtilPlayer.message(player, C.cGold + "HAPPY HALLOWEEN");
UtilPlayer.message(player, "You received 2 Treasure Keys!");
UtilPlayer.message(player, "");
UtilPlayer.message(player, C.cPurple + C.Strike + "=============================================");
}
}, 5L);
}
}

View File

@ -0,0 +1,41 @@
package mineplex.core.benefit.benefits;
import mineplex.core.benefit.RankBenefitsGiver9000Repository;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.inventory.InventoryManager;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class Thanksgiving2014 extends BenefitBase
{
private InventoryManager _inventoryManager;
public Thanksgiving2014(JavaPlugin plugin, RankBenefitsGiver9000Repository repository, InventoryManager inventoryManager)
{
super(plugin, "Thanksgiving2014", repository);
_inventoryManager = inventoryManager;
}
@Override
public void rewardPlayer(final Player player)
{
_inventoryManager.addItemToInventory(player, "Treasure", "Treasure Key", 1);
Bukkit.getServer().getScheduler().runTaskLater(getPlugin(), new Runnable()
{
public void run()
{
UtilPlayer.message(player, C.cPurple + C.Strike + "=============================================");
UtilPlayer.message(player, "");
UtilPlayer.message(player, C.cGold + "HAPPY THANKSGIVING");
UtilPlayer.message(player, "You received 1 Treasure Key!");
UtilPlayer.message(player, "");
UtilPlayer.message(player, C.cPurple + C.Strike + "=============================================");
}
}, 5L);
}
}

View File

@ -0,0 +1,43 @@
package mineplex.core.benefit.benefits;
import mineplex.core.account.CoreClientManager;
import mineplex.core.benefit.RankBenefitsGiver9000Repository;
import mineplex.core.common.Rank;
import mineplex.core.inventory.InventoryManager;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class TreasureRelease extends BenefitBase
{
private InventoryManager _inventoryManager;
private CoreClientManager _clientManager;
public TreasureRelease(JavaPlugin plugin, RankBenefitsGiver9000Repository repository, InventoryManager inventoryManager, CoreClientManager clientManager)
{
super(plugin, "TreasureUpdate", repository);
_inventoryManager = inventoryManager;
_clientManager = clientManager;
}
@Override
public void rewardPlayer(final Player player)
{
if (_clientManager.Get(player).GetRank() == Rank.ALL)
{
_inventoryManager.addItemToInventory(player, "Utility", "Treasure Chest", 1);
_inventoryManager.addItemToInventory(player, "Treasure", "Treasure Key", 1);
}
else if (_clientManager.Get(player).GetRank() == Rank.ULTRA)
{
_inventoryManager.addItemToInventory(player, "Utility", "Treasure Chest", 20);
_inventoryManager.addItemToInventory(player, "Treasure", "Treasure Key", 5);
}
else
{
_inventoryManager.addItemToInventory(player, "Utility", "Treasure Chest", 40);
_inventoryManager.addItemToInventory(player, "Treasure", "Treasure Key", 10);
}
}
}

View File

@ -40,12 +40,11 @@ import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Scoreboard;
import mineplex.core.MiniClientPlugin;
import mineplex.core.RankBenefitsGiver9000;
import mineplex.core.account.CoreClient;
import mineplex.core.account.CoreClientManager;
import mineplex.core.account.event.RetrieveClientInformationEvent;
import mineplex.core.achievement.Achievement;
import mineplex.core.achievement.AchievementManager;
import mineplex.core.benefit.RankBenefitsGiver9000;
import mineplex.core.blockrestore.BlockRestore;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;

View File

@ -186,6 +186,9 @@ public class ServerMonitor
for (ServerGroup serverGroup : serverGroups)
{
if (serverGroup.getName().equals("Testing"))
continue;
handleGroupChanges(dedicatedServers, serverTracker, serverGroup, false);
}