Merge remote-tracking branch 'origin/master'

This commit is contained in:
Shaun Bennett 2014-08-08 01:51:50 -05:00
commit 9395711dcb
13 changed files with 380 additions and 92 deletions

View File

@ -0,0 +1,56 @@
package mineplex.core.achievement;
public enum Achievement
{
GEM_HUNTER("Gem Hunter", new String[] {"Global.GemsEarned"}, new int[] {10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000, 110000, 120000});
private String _name;
private String[] _stats;
private int[] _levels;
Achievement(String name, String[] stats, int[] levels)
{
_name = name;
_stats = stats;
_levels = levels;
}
public String getName()
{
return _name;
}
public String[] getStats()
{
return _stats;
}
public int[] getLevels()
{
return _levels;
}
public int getMaxLevel()
{
return _levels.length;
}
public AchivementData getLevelData(int exp)
{
for (int i=0 ; i<_levels.length ; i++)
{
int req = _levels[i];
//Has Experience, Level Up!
if (exp >= req)
{
exp -= req;
continue;
}
return new AchivementData(i, exp, req);
}
return new AchivementData(getMaxLevel(), -1, -1);
}
}

View File

@ -0,0 +1,74 @@
package mineplex.core.achievement;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import mineplex.core.MiniPlugin;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.stats.StatsManager;
import mineplex.core.stats.event.StatChangeEvent;
public class AchievementManager extends MiniPlugin
{
private StatsManager _statsManager;
private boolean debug = true;
public AchievementManager(StatsManager statsManager)
{
super("Achievement Manager", statsManager.GetPlugin());
_statsManager = statsManager;
}
public AchivementData get(Player player, Achievement type)
{
return get(player.getName(), type);
}
public AchivementData get(String playerName, Achievement type)
{
int exp = 0;
for (String stat : type.getStats())
{
exp += _statsManager.Get(playerName).getStat(stat);
if (debug)
System.out.println(type.getName() + " Value [" + stat + "] is [" + _statsManager.Get(playerName).getStat(stat) + "]");
}
return type.getLevelData(exp);
}
@EventHandler
public void informLevelUp(StatChangeEvent event)
{
Player player = UtilPlayer.searchExact(event.getPlayerName());
if (player == null)
return;
for (Achievement type : Achievement.values())
{
for (String stat : type.getStats())
{
if (stat.equalsIgnoreCase(event.getStatName()))
{
if (debug)
System.out.println(player.getName() + " - " + type.getName() +
" [" + type.getLevelData(event.getValueAfter()).getLevel() + " & " + type.getLevelData(event.getValueBefore()).getLevel() + "]");
if (type.getLevelData(event.getValueAfter()).getLevel() > type.getLevelData(event.getValueBefore()).getLevel())
{
UtilPlayer.message(player, F.main("Achievement",
"You leveled up " + F.elem(type.getName()) + " to " + F.elem("Level " + type.getLevelData(event.getValueAfter()).getLevel())));
player.playSound(player.getLocation(), Sound.LEVEL_UP, 2f, 1f);
}
}
}
}
}
}

View File

@ -0,0 +1,30 @@
package mineplex.core.achievement;
public class AchivementData
{
private int _level;
private int _expRemainder;
private int _expNextLevel;
public AchivementData(int level, int expRemainder, int expNextLevel)
{
_level = level;
_expRemainder = expRemainder;
_expNextLevel = expNextLevel;
}
public int getLevel()
{
return _level;
}
public int getExpRemainder()
{
return _expRemainder;
}
public int getExpNextLevel()
{
return _expNextLevel;
}
}

View File

@ -13,9 +13,14 @@ import mineplex.core.MiniClientPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.account.event.RetrieveClientInformationEvent;
import mineplex.core.common.util.C;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.donation.DonationManager;
import mineplex.core.gadget.GadgetManager;
import mineplex.core.gadget.types.Gadget;
import mineplex.core.gadget.types.GadgetType;
import mineplex.core.inventory.data.Category;
import mineplex.core.inventory.data.InventoryRepository;
import mineplex.core.inventory.data.Item;
import mineplex.core.inventory.ui.InventoryShop;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.mount.MountManager;
@ -31,6 +36,9 @@ public class InventoryManager extends MiniClientPlugin<ClientInventory>
private InventoryRepository _repository;
private NautHashMap<String, Item> _items;
private NautHashMap<String, Category> _categories;
public InventoryManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, GadgetManager gadgetManager, MountManager mountManager, PetManager petManager)
{
super("Inventory Manager", plugin);
@ -42,6 +50,20 @@ public class InventoryManager extends MiniClientPlugin<ClientInventory>
_inventoryShop = new InventoryShop(this, clientManager, donationManager, _moduleName);
_repository = new InventoryRepository(plugin);
/*
for (GadgetType gadgetType : GadgetType.values())
{
if (!_categories.containsKey(gadgetType.name()))
_repository.addCategory(new Category(0, gadgetType.name()));
for (Gadget gadget : _gadgetManager.getGadgets(gadgetType))
{
if (!_items.containsKey(gadget.GetName()))
_repository.addItem(new Item(0, gadget.GetName(), null));
}
}
*/
}
@Override

View File

@ -8,14 +8,18 @@ public class PlayerStats
{
private NautHashMap<String, Integer> _statHash = new NautHashMap<String, Integer>();
public void addStat(String statName, int value)
public int addStat(String statName, int value)
{
if (!_statHash.containsKey(statName))
{
_statHash.put(statName, 0);
}
_statHash.put(statName, _statHash.get(statName) + value);
int current = _statHash.get(statName);
_statHash.put(statName, current + value);
return current+value;
}
public int getStat(String statName)

View File

@ -10,6 +10,8 @@ import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniClientPlugin;
import mineplex.core.account.event.RetrieveClientInformationEvent;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilServer;
import mineplex.core.stats.event.StatChangeEvent;
public class StatsManager extends MiniClientPlugin<PlayerStats>
{
@ -48,7 +50,10 @@ public class StatsManager extends MiniClientPlugin<PlayerStats>
public void incrementStat(Player player, final String statName, int value)
{
Get(player).addStat(statName, Get(player).getStat(statName) + value);
int newValue = Get(player).addStat(statName, Get(player).getStat(statName) + value);
//Event
UtilServer.getServer().getPluginManager().callEvent(new StatChangeEvent(player.getName(), statName, newValue - value, newValue));
String uuidString = player.getUniqueId().toString();

View File

@ -0,0 +1,54 @@
package mineplex.core.stats.event;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class StatChangeEvent extends Event
{
private static final HandlerList handlers = new HandlerList();
private String _player;
private String _statName;
private int _valueBefore;
private int _valueAfter;
public StatChangeEvent(String player, String statName, int valueBefore, int valueAfter)
{
_player = player;
_statName = statName;
_valueBefore = valueBefore;
_valueAfter = valueAfter;
}
public HandlerList getHandlers()
{
return handlers;
}
public static HandlerList getHandlerList()
{
return handlers;
}
public String getPlayerName()
{
return _player;
}
public String getStatName()
{
return _statName;
}
public int getValueBefore()
{
return _valueBefore;
}
public int getValueAfter()
{
return _valueAfter;
}
}

View File

@ -1,5 +1,7 @@
package mineplex.enjinTranslator;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import org.bukkit.command.Command;
@ -27,6 +29,8 @@ public class Enjin extends MiniPlugin implements CommandExecutor
public long _lastPoll = System.currentTimeMillis() - 120000;
private SimpleDateFormat _dateFormat = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss");
public Enjin(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, Punish punish)
{
super("Enjin", plugin);
@ -58,16 +62,22 @@ public class Enjin extends MiniPlugin implements CommandExecutor
if (label.equalsIgnoreCase("enjin_mineplex"))
{
System.out.println("enjin command");
if (args.length == 3 && args[0].equalsIgnoreCase("gem"))
{
String name = args[1];
int amount = Integer.parseInt(args[2]);
_donationManager.RewardGems(null, "purchase", name, amount);
System.out.println("enjin gem");
System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " gems.");
}
else if (args.length == 3 && args[0].equalsIgnoreCase("coin"))
{
String name = args[1];
int amount = Integer.parseInt(args[2]);
_donationManager.RewardCoins(null, "purchase", name, amount);
System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " coins.");
}
else if (args.length == 4 && args[0].equalsIgnoreCase("rank"))
{
String name = args[1];
@ -75,7 +85,7 @@ public class Enjin extends MiniPlugin implements CommandExecutor
boolean perm = Boolean.parseBoolean(args[3]);
_clientManager.SaveRank(name, mineplex.core.common.Rank.valueOf(rank), perm);
System.out.println("enjin rank");
System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + rank + " " + (perm ? "permanently." : "for 1 month."));
}
else if (args.length >= 3 && args[0].equalsIgnoreCase("purchase"))
{
@ -88,8 +98,8 @@ public class Enjin extends MiniPlugin implements CommandExecutor
packageName += " " + args[i];
}
_donationManager.PurchaseUnknownSalesPackage(null, name, packageName, 0, false);
System.out.println("enjin purchase");
_donationManager.PurchaseUnknownSalesPackage(null, name, packageName, false, 0, false);
System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + packageName + ".");
}
else if (args.length >= 3 && args[0].equalsIgnoreCase("unban"))
{
@ -102,7 +112,7 @@ public class Enjin extends MiniPlugin implements CommandExecutor
}
_punish.RemoveBan(name, reason);
System.out.println("enjin unban");
System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " unbanned for " + reason);
}
else if (args.length >= 3 && args[0].equalsIgnoreCase("ban"))
{
@ -115,7 +125,7 @@ public class Enjin extends MiniPlugin implements CommandExecutor
}
_punish.AddPunishment(name, Category.Other, reason, null, 3, true, -1);
System.out.println("enjin ban");
System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " banned for " + reason);
}
}

View File

@ -52,6 +52,7 @@ import mineplex.minecraft.game.core.fire.Fire;
import mineplex.core.MiniPlugin;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.account.CoreClientManager;
import mineplex.core.achievement.AchievementManager;
import mineplex.core.antihack.AntiHack;
import mineplex.core.antistack.AntiStack;
import mineplex.core.blockrestore.BlockRestore;
@ -102,10 +103,10 @@ public class ArcadeManager extends MiniPlugin implements IRelation
private GameGemManager _gameGemManager;
private GameManager _gameManager;
private GameLobbyManager _gameLobbyManager;
private GameStatsManager _gameStatsManager;
private GameWorldManager _gameWorldManager;
private ServerStatusManager _serverStatusManager;
private AchievementManager _achievementManager;
private StatsManager _statsManager;
private ClassManager _classManager;
private SkillFactory _skillFactory;
@ -197,7 +198,8 @@ public class ArcadeManager extends MiniPlugin implements IRelation
_eloManager = new EloManager(_plugin);
}
// _statsManager = new StatsManager(plugin);
_statsManager = new StatsManager(plugin);
_achievementManager = new AchievementManager(_statsManager);
_portal = portal;
@ -215,7 +217,6 @@ public class ArcadeManager extends MiniPlugin implements IRelation
_gameLobbyManager = new GameLobbyManager(this, packetHandler);
new GameFlagManager(this);
new GamePlayerManager(this);
_gameStatsManager = new GameStatsManager(this);
_gameWorldManager = new GameWorldManager(this);
_miscManager = new MiscManager(this);
new IdleManager(this);
@ -242,6 +243,11 @@ public class ArcadeManager extends MiniPlugin implements IRelation
{
return GetServerConfig().GameList;
}
public AchievementManager GetAchievement()
{
return _achievementManager;
}
public AntiStack GetAntiStack()
{
@ -333,11 +339,6 @@ public class ArcadeManager extends MiniPlugin implements IRelation
return _arcadeShop;
}
public GameStatsManager GetStats()
{
return _gameStatsManager;
}
public GameCreationManager GetGameCreationManager()
{
return _gameCreationManager;

View File

@ -207,6 +207,8 @@ public abstract class Game implements Listener
public boolean EloRanking = false;
public int EloStart = 1000;
public ArrayList<String> GemBoosters = new ArrayList<String>();
public Game(ArcadeManager manager, GameType gameType, Kit[] kits, String[] gameDesc)
{
@ -1040,4 +1042,33 @@ public abstract class Game implements Listener
{
SetState(GameState.End);
}
public void AddGemBooster(Player player)
{
if (GemBoosters.size() >= 4)
{
UtilPlayer.message(player, F.main("Game", "Games cannot have more than " + F.elem("4 Gem Boosters")) + ".");
return;
}
if (GemBoosters.contains(player.getName()))
{
UtilPlayer.message(player, F.main("Game", "You can only use " + F.elem("1 Gem Booster")) + " per game.");
return;
}
Announce(F.elem(player.getName()) + " used a " + F.elem("Gem Booster") + " for " + F.elem("+" + (100-(GemBoosters.size()*25)) + "% Gems") + "!");
GemBoosters.add(player.getName());
}
public double GetGemBoostAmount()
{
if (GemBoosters.size() == 1) return 1;
if (GemBoosters.size() == 2) return 1.75;
if (GemBoosters.size() == 3) return 2.25;
if (GemBoosters.size() == 4) return 2.5;
return 0;
}
}

View File

@ -2,8 +2,9 @@ package nautilus.game.arcade.managers;
import java.util.HashMap;
import mineplex.core.common.Rank;
import mineplex.core.achievement.Achievement;
import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
@ -29,13 +30,13 @@ import org.bukkit.event.player.PlayerQuitEvent;
public class GameGemManager implements Listener
{
ArcadeManager Manager;
boolean DoubleGem = false;
public GameGemManager(ArcadeManager manager)
{
Manager = manager;
Manager.GetPluginManager().registerEvents(this, Manager.GetPlugin());
}
@ -44,13 +45,13 @@ public class GameGemManager implements Listener
{
if (Manager.IsTournamentServer())
return;
Game game = Manager.GetGame();
if (game == null) return;
if (!(event.GetEvent().getEntity() instanceof Player))
return;
Player killed = (Player)event.GetEvent().getEntity();
if (event.GetLog().GetKiller() != null)
@ -86,43 +87,43 @@ public class GameGemManager implements Listener
game.AddGems(assist, game.GetKillsGems(assist, killed, true), "Kill Assists", true);
}
}
@EventHandler
public void PlayerQuit(PlayerQuitEvent event)
{
if (Manager.IsTournamentServer())
return;
Game game = Manager.GetGame();
if (game == null) return;
RewardGems(game, event.getPlayer(), true);
}
@EventHandler(priority = EventPriority.MONITOR)
public void PlayerStateChange(PlayerStateChangeEvent event)
{
if (Manager.IsTournamentServer())
return;
if (event.GetState() != PlayerState.OUT)
return;
if (event.GetGame().GetType() == GameType.Paintball)
return;
RewardGems(event.GetGame(), event.GetPlayer(), false);
}
@EventHandler
public void GameStateChange(GameStateChangeEvent event)
{
if (Manager.IsTournamentServer())
return;
if (event.GetState() != GameState.Dead)
return;
for (Player player : UtilServer.getPlayers())
RewardGems(event.GetGame(), player, true);
}
@ -131,55 +132,63 @@ public class GameGemManager implements Listener
{
if (Manager.IsTournamentServer())
return;
//Inform Gems
AnnounceGems(game, player, game.GetPlayerGems().get(player), give);
//Give Gems
if (give)
GiveGems(game, player, game.GetPlayerGems().remove(player), game.GemMultiplier);
}
public void GiveGems(Game game, Player player, HashMap<String,GemData> gems, double gameMult)
{
if (Manager.IsTournamentServer())
return;
if (gems == null)
return;
int total = 0;
int earned = 0;
for (GemData data : gems.values())
total += (int)data.Gems;
earned += (int)data.Gems;
if (total <= 0)
total = 1;
if (earned <= 0)
earned = 1;
earned = (int) (earned * gameMult);
int total = earned;
//Gem Boooster
total += (int)(earned * game.GetGemBoostAmount());
//Gem Finder
int gemFinder = Manager.GetAchievement().get(player.getName(), Achievement.GEM_HUNTER).getLevel();
if (gemFinder > 0)
{
total += (int)(earned * (gemFinder * 0.25));
}
/*
if (Manager.GetClients().Get(player).GetRank().Has(Rank.HERO))
total = total * 3;
else if (Manager.GetClients().Get(player).GetRank().Has(Rank.ULTRA) || Manager.GetDonation().Get(player.getName()).OwnsUnknownPackage(Manager.GetServerConfig().ServerType + " ULTRA"))
total = total * 2;
*/
if (DoubleGem)
total = total * 2;
total = (int) (total * gameMult);
total += earned;
Manager.GetDonation().RewardGems(null, "Earned " + game.GetName(), player.getName(), total);
//Stats
Manager.GetStatsManager().incrementStat(player, "Global.GemsEarned", total);
Manager.GetStatsManager().incrementStat(player, game.GetName()+".GemsEarned", total);
}
public void AnnounceGems(Game game, Player player, HashMap<String,GemData> gems, boolean give)
{
if (Manager.IsTournamentServer())
return;
if (gems == null)
return;
player.playSound(player.getLocation(), Sound.LEVEL_UP, 2f, 1f);
UtilPlayer.message(player, "");
@ -197,7 +206,7 @@ public class GameGemManager implements Listener
gemCount = 1;
earnedGems += gemCount;
int amount = gems.get(type).Amount;
String amountStr = "";
if (amount > 0)
@ -205,43 +214,54 @@ public class GameGemManager implements Listener
UtilPlayer.message(player, F.elem(C.cGreen + "+" + (int)(gemCount * game.GemMultiplier) + " Gems") + " for " + F.elem(amountStr + type));
}
earnedGems = (int) (earnedGems * game.GemMultiplier);
//Hero / Ultra Boost
/*
if (Manager.GetClients().Get(player).GetRank().Has(Rank.HERO))
int totalGems = earnedGems;
//Gem Booster
if (game.GetGemBoostAmount() > 0)
{
UtilPlayer.message(player, F.elem(C.cGreen + "+" + (earnedGems*2) + " Gems") + " for " + F.elem(C.cPurple + "Hero Rank 3x Gems"));
earnedGems = earnedGems * 3;
UtilPlayer.message(player, F.elem(C.cGreen + "+" + (earnedGems*game.GetGemBoostAmount()) + " Gems") + " for " +
F.elem(game.GemBoosters.size() + " Gem Booster " + C.cGreen + "+" + (int)(game.GetGemBoostAmount()*100)));
totalGems += earnedGems * game.GetGemBoostAmount();
}
else if (Manager.GetClients().Get(player).GetRank().Has(Rank.ULTRA) || Manager.GetDonation().Get(player.getName()).OwnsUnknownPackage(Manager.GetServerConfig().ServerType + " ULTRA"))
//Gem Finder
int gemFinder = Manager.GetAchievement().get(player.getName(), Achievement.GEM_HUNTER).getLevel();
if (gemFinder > 0)
{
UtilPlayer.message(player, F.elem(C.cGreen + "+" + earnedGems + " Gems") + " for " + F.elem(C.cAqua + "Ultra Rank 2x Gems"));
earnedGems = earnedGems * 2;
UtilPlayer.message(player, F.elem(C.cGreen + "+" + (earnedGems*(gemFinder * 0.25) + " Gems") + " for " +
F.elem("Gem Finder " + gemFinder + " (+" + (gemFinder*25) + "%)")));
totalGems += earnedGems * (gemFinder * 0.25);
}
*/
//Double Gem
if (DoubleGem)
{
UtilPlayer.message(player, F.elem(C.cGreen + "+" + (earnedGems) + " Gems") + " for " + F.elem(C.cDGreen + "Double Gem Weekend"));
earnedGems = earnedGems * 2;
totalGems += earnedGems;
}
//Inform
UtilPlayer.message(player, "");
if (give)
{
UtilPlayer.message(player, F.elem(C.cWhite + "§lYou now have " +
C.cGreen + C.Bold + (Manager.GetDonation().Get(player.getName()).GetGems() + earnedGems) + " Gems"));
C.cGreen + C.Bold + (Manager.GetDonation().Get(player.getName()).GetGems() + totalGems) + " Gems"));
}
else
{
UtilPlayer.message(player, F.elem(C.cWhite + "§lGame is still in progress..."));
UtilPlayer.message(player, F.elem(C.cWhite + "§lYou may earn more " + C.cGreen + C.Bold + "Gems" + C.cWhite + C.Bold + " when its completed."));
}
UtilPlayer.message(player, ArcadeFormat.Line);
}
}

View File

@ -1,19 +0,0 @@
package nautilus.game.arcade.managers;
import nautilus.game.arcade.ArcadeManager;
import org.bukkit.event.Listener;
public class GameStatsManager implements Listener
{
ArcadeManager Manager;
public GameStatsManager(ArcadeManager manager)
{
Manager = manager;
Manager.GetPluginManager().registerEvents(this, Manager.GetPlugin());
}
}

Binary file not shown.