Gem Booster In Lobby

Achievement Stuff
This commit is contained in:
Chiss 2014-08-08 17:05:11 +10:00
parent 8f72ba4ab7
commit fa3695be4e
14 changed files with 206 additions and 36 deletions

View File

@ -2,7 +2,9 @@ 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});
GLOBAL_GEM_HUNTER("Gem Hunter", new String[] {"Global.GemsEarned"}, new int[] {10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000, 110000, 120000}),
GAME_SPLEEF_SMASHER("Spleef Smasher", new String[] {"Super Spleef.BlocksBroken"}, new int[] {100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200});
private String _name;
private String[] _stats;

View File

@ -0,0 +1,13 @@
package mineplex.core.achievement;
public class AchievementLog
{
public int Amount;
public boolean LevelUp;
public AchievementLog(int amount, boolean levelUp)
{
Amount = amount;
LevelUp = levelUp;
}
}

View File

@ -1,11 +1,11 @@
package mineplex.core.achievement;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerQuitEvent;
import mineplex.core.MiniPlugin;
import mineplex.core.common.util.F;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.stats.StatsManager;
import mineplex.core.stats.event.StatChangeEvent;
@ -14,7 +14,7 @@ public class AchievementManager extends MiniPlugin
{
private StatsManager _statsManager;
private boolean debug = true;
private NautHashMap<String, NautHashMap<Achievement, AchievementLog>> _log = new NautHashMap<String, NautHashMap<Achievement, AchievementLog>>();
public AchievementManager(StatsManager statsManager)
{
@ -35,9 +35,6 @@ public class AchievementManager extends MiniPlugin
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);
@ -56,19 +53,59 @@ public class AchievementManager extends MiniPlugin
{
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 (!_log.containsKey(player.getName()))
_log.put(player.getName(), new NautHashMap<Achievement, AchievementLog>());
//Record that achievement has leveled up
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);
//Add new
if (!_log.get(player.getName()).containsKey(type))
{
_log.get(player.getName()).put(type, new AchievementLog(event.getValueAfter() - event.getValueBefore(), true));
}
//Edit previous
else
{
AchievementLog log = _log.get(player.getName()).get(type);
log.Amount += event.getValueAfter() - event.getValueBefore();
log.LevelUp = true;
}
}
//Record that there has been changes in this Achievement
else if (!_log.get(player.getName()).containsKey(type))
{
//Add new
if (!_log.get(player.getName()).containsKey(type))
{
_log.get(player.getName()).put(type, new AchievementLog(event.getValueAfter() - event.getValueBefore(), false));
}
//Edit previous
else
{
AchievementLog log = _log.get(player.getName()).get(type);
log.Amount += event.getValueAfter() - event.getValueBefore();
}
}
}
}
}
}
@EventHandler
public void playerQuit(PlayerQuitEvent event)
{
_log.remove(event.getPlayer().getName());
}
public void clearLog(Player player)
{
_log.remove(player.getName());
}
public NautHashMap<Achievement, AchievementLog> getLog(Player player)
{
return _log.remove(player.getName());
}
}

View File

@ -15,11 +15,9 @@ public class PlayerStats
_statHash.put(statName, 0);
}
int current = _statHash.get(statName);
_statHash.put(statName, _statHash.get(statName) + value);
_statHash.put(statName, current + value);
return current+value;
return _statHash.get(statName);
}
public int getStat(String statName)

View File

@ -51,6 +51,8 @@ public class StatsManager extends MiniClientPlugin<PlayerStats>
public void incrementStat(Player player, final String statName, int value)
{
int newValue = Get(player).addStat(statName, Get(player).getStat(statName) + value);
System.out.println(player.getName() + " - " + statName + " - " + value + " ? " + newValue);
//Event
UtilServer.getServer().getPluginManager().callEvent(new StatChangeEvent(player.getName(), statName, newValue - value, newValue));
@ -69,7 +71,7 @@ public class StatsManager extends MiniClientPlugin<PlayerStats>
_statUploadQueue.get(uuidString).put(statName, 0);
}
_statUploadQueue.get(uuidString).put(statName, _statUploadQueue.get(uuidString).get(statName) + value);
_statUploadQueue.get(uuidString).put(statName, value);
}
// Verify stat is in our local cache, if not add it remotely.

View File

@ -19,7 +19,7 @@ public class StatsRepository extends RepositoryBase
private static String CREATE_STAT_RELATION_TABLE = "CREATE TABLE IF NOT EXISTS accountStats (id INT NOT NULL AUTO_INCREMENT, accountId INT NOT NULL, statId INT NOT NULL, value INT NOT NULL, PRIMARY KEY (id), FOREIGN KEY (accountId) REFERENCES accounts(id), FOREIGN KEY (statId) REFERENCES stats(id), UNIQUE INDEX accountStatIndex (accountId, statId));";
private static String RETRIEVE_PLAYER_STATS = "SELECT stats.name, value FROM accountStats INNER JOIN stats ON stats.id = accountStats.statId INNER JOIN accounts ON accountStats.accountId = accounts.id WHERE accounts.uuid = ?;";
private static String INSERT_PLAYER_STAT = "INSERT INTO accountStats (accountId, statId, value) SELECT accounts.id, ?, ? FROM accounts WHERE accounts.uuid = ? ON DUPLICATE KEY UPDATE value=VALUES(value);";
private static String INSERT_PLAYER_STAT = "INSERT INTO accountStats (accountId, statId, value) SELECT accounts.id, ?, ? FROM accounts WHERE accounts.uuid = ? ON DUPLICATE KEY UPDATE value=value+VALUES(value);";
private static String RETRIEVE_STATS = "SELECT id, name FROM stats;";
private static String INSERT_STAT = "INSERT INTO stats (name) VALUES (?);";

View File

@ -47,6 +47,7 @@ import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
@ -551,7 +552,15 @@ public class HubManager extends MiniClientPlugin<HubClient>
{
if (event.isCancelled())
return;
//Dont Let Chat Near Spawn!
if (UtilMath.offset(GetSpawn(), event.getPlayer().getLocation()) < 4)
{
UtilPlayer.message(event.getPlayer(), F.main("Chat", "You must leave spawn before you can chat!"));
event.setCancelled(true);
return;
}
Player player = event.getPlayer();
Rank rank = GetClients().Get(player).GetRank();

View File

@ -217,6 +217,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
_gameLobbyManager = new GameLobbyManager(this, packetHandler);
new GameFlagManager(this);
new GamePlayerManager(this);
new GameAchievementManager(this);
_gameWorldManager = new GameWorldManager(this);
_miscManager = new MiscManager(this);
new IdleManager(this);

View File

@ -94,8 +94,11 @@ public abstract class Game implements Listener
//Player Preferences
protected NautHashMap<Player, Kit> _playerKit = new NautHashMap<Player, Kit>();
private NautHashMap<GameTeam, ArrayList<Player>> _teamPreference = new NautHashMap<GameTeam, ArrayList<Player>>();
private NautHashMap<Player, HashMap<String,GemData>> _gemCount = new NautHashMap<Player, HashMap<String,GemData>>();
//Player Data
private NautHashMap<Player, HashMap<String,GemData>> _gemCount = new NautHashMap<Player, HashMap<String,GemData>>();
private NautHashMap<Player, HashMap<String,Integer>> _stats = new NautHashMap<Player, HashMap<String,Integer>>();
//Player Location Store
private NautHashMap<String, Location> _playerLocationStore = new NautHashMap<String, Location>();
@ -1057,7 +1060,7 @@ public abstract class Game implements Listener
return;
}
Announce(F.elem(player.getName()) + " used a " + F.elem("Gem Booster") + " for " + F.elem("+" + (100-(GemBoosters.size()*25)) + "% Gems") + "!");
Announce(F.elem(player.getName()) + " used a " + F.elem(C.cGreen + "Gem Booster") + " for " + F.elem("+" + (100-(GemBoosters.size()*25)) + "% Gems") + "!");
GemBoosters.add(player.getName());
}
@ -1071,4 +1074,26 @@ public abstract class Game implements Listener
return 0;
}
public void AddStat(Player player, String stat, int amount, boolean global)
{
if (!_stats.containsKey(player))
_stats.put(player, new HashMap<String, Integer>());
if (global)
stat = "Global." + stat;
else
stat = GetName() + "." + stat;
int past = 0;
if (_stats.get(player).containsKey(stat))
past = _stats.get(player).get(stat);
_stats.get(player).put(stat, past + amount);
}
public NautHashMap<Player, HashMap<String, Integer>> GetStats()
{
return _stats;
}
}

View File

@ -1,6 +1,7 @@
package nautilus.game.arcade.game.games.spleef;
import java.lang.reflect.Field;
import java.util.HashMap;
import org.bukkit.Effect;
import org.bukkit.block.Block;
@ -133,6 +134,8 @@ public class Spleef extends SoloGame
public void BlockFade(Block block, Player player)
{
AddStat(player, "BlocksBroken", 1, false);
UtilPlayer.hunger(player, 1);
//Wool and Stained Clay

View File

@ -115,7 +115,7 @@ public class GameGemManager implements Listener
RewardGems(event.GetGame(), event.GetPlayer(), false);
}
@EventHandler
@EventHandler(priority = EventPriority.MONITOR)
public void GameStateChange(GameStateChangeEvent event)
{
if (Manager.IsTournamentServer())
@ -165,12 +165,12 @@ public class GameGemManager implements Listener
total += (int)(earned * game.GetGemBoostAmount());
//Gem Finder
int gemFinder = Manager.GetAchievement().get(player.getName(), Achievement.GEM_HUNTER).getLevel();
int gemFinder = Manager.GetAchievement().get(player.getName(), Achievement.GLOBAL_GEM_HUNTER).getLevel();
if (gemFinder > 0)
{
total += (int)(earned * (gemFinder * 0.25));
}
if (DoubleGem)
total += earned;
@ -180,8 +180,8 @@ public class GameGemManager implements Listener
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)
public void AnnounceGems(Game game, Player player, HashMap<String,GemData> gems, boolean give)
{
if (Manager.IsTournamentServer())
return;
@ -194,9 +194,9 @@ public class GameGemManager implements Listener
UtilPlayer.message(player, "");
UtilPlayer.message(player, ArcadeFormat.Line);
UtilPlayer.message(player, "§aGame - §f§l" + game.GetName());
UtilPlayer.message(player, "§f§lGems Earned");
UtilPlayer.message(player, "");
int earnedGems = 0;
for (String type : gems.keySet())
@ -222,15 +222,15 @@ public class GameGemManager implements Listener
//Gem Booster
if (game.GetGemBoostAmount() > 0)
{
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)));
UtilPlayer.message(player, F.elem(C.cGreen + "+" + (int)(earnedGems*game.GetGemBoostAmount()) + " Gems") + " for " +
F.elem(game.GemBoosters.size() + " Gem Boosters " + C.cGreen + "+" + (int)(game.GetGemBoostAmount()*100) + "%"));
totalGems += earnedGems * game.GetGemBoostAmount();
}
//Gem Finder
int gemFinder = Manager.GetAchievement().get(player.getName(), Achievement.GEM_HUNTER).getLevel();
int gemFinder = Manager.GetAchievement().get(player.getName(), Achievement.GLOBAL_GEM_HUNTER).getLevel();
if (gemFinder > 0)
{
UtilPlayer.message(player, F.elem(C.cGreen + "+" + (earnedGems*(gemFinder * 0.25) + " Gems") + " for " +

View File

@ -29,7 +29,10 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityCombustEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Scoreboard;
@ -41,12 +44,14 @@ import mineplex.core.common.util.MapUtil;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilText;
import mineplex.core.common.util.UtilText.TextAlign;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilWorld;
import mineplex.core.donation.Donor;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.packethandler.IPacketRunnable;
import mineplex.core.packethandler.PacketHandler;
import mineplex.core.packethandler.PacketVerifier;
@ -1104,4 +1109,64 @@ public class GameLobbyManager implements IPacketRunnable, Listener
}
}
}
@EventHandler
public void GemBoosterUpdate(UpdateEvent event)
{
if (Manager.IsTournamentServer())
return;
if (event.getType() != UpdateType.SEC)
return;
if (Manager.GetGame() == null)
return;
if (Manager.GetGame().GetState() != GameState.Recruit)
return;
for (Player player : UtilServer.getPlayers())
{
if (!player.getInventory().contains(Material.EMERALD))
{
player.getInventory().setItem(
7,
ItemStackFactory.Instance.CreateStack(Material.EMERALD, (byte) 0, 1, (short) 0, C.cGreen
+ "Gem Booster", new String[] { "", ChatColor.RESET + "Boosts Gems earned for",
ChatColor.RESET + "everyone in the game." }));
}
for (int i : player.getInventory().all(Material.EMERALD).keySet())
{
ItemStack stack = player.getInventory().getItem(i);
ItemMeta itemMeta = stack.getItemMeta();
itemMeta.setDisplayName(C.cGreen + "Gem Booster" +
" " + C.cWhite + "Click for " + (100-Manager.GetGame().GemBoosters.size()*25) + "% Boost");
stack.setItemMeta(itemMeta);
player.getInventory().setItem(i, stack);
}
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void HubClockInteract(PlayerInteractEvent event)
{
if (Manager.IsTournamentServer())
return;
Player player = event.getPlayer();
if (player.getItemInHand() == null)
return;
if (player.getItemInHand().getType() != Material.EMERALD)
return;
if (Manager.GetGame() == null)
return;
Manager.GetGame().AddGemBooster(player);
}
}

View File

@ -249,6 +249,21 @@ public class GameManager implements Listener
event.GetGame().DeregisterKits();
}
@EventHandler
public void StatRegister(GameStateChangeEvent event)
{
if (event.GetState() != GameState.End)
return;
for (Player player : event.GetGame().GetStats().keySet())
{
for (String stat : event.GetGame().GetStats().get(player).keySet())
{
Manager.GetStatsManager().incrementStat(player, stat, event.GetGame().GetStats().get(player).get(stat));
}
}
}
@EventHandler(priority = EventPriority.LOWEST) //BEFORE PARSE DATA
public void TeamGeneration(GameStateChangeEvent event)

View File

@ -17,7 +17,7 @@ import org.bukkit.event.world.ChunkUnloadEvent;
public class GameWorldManager implements Listener
{
ArcadeManager Manager;
private HashSet<WorldData> _worldLoader = new HashSet<WorldData>();
public GameWorldManager(ArcadeManager manager)
@ -32,7 +32,7 @@ public class GameWorldManager implements Listener
{
if (event.getType() != UpdateType.TICK)
return;
Iterator<WorldData> worldIterator = _worldLoader.iterator();
long endTime = System.currentTimeMillis() + 25;