Merge branch 'master' of ssh://184.154.0.242:7999/min/mineplex
Conflicts: Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java
This commit is contained in:
commit
661a869116
@ -85,7 +85,7 @@ public class UtilInv
|
||||
|
||||
public static void Clear(Player player)
|
||||
{
|
||||
player.getOpenInventory().close();
|
||||
//player.getOpenInventory().close();
|
||||
|
||||
PlayerInventory inv = player.getInventory();
|
||||
|
||||
|
@ -0,0 +1,64 @@
|
||||
package mineplex.core.simpleStats;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.common.util.NautHashMap;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
|
||||
public class SimpleStats extends MiniPlugin
|
||||
{
|
||||
private static Object _transferLock = new Object();
|
||||
|
||||
private SimpleStatsRepository _repository = new SimpleStatsRepository();
|
||||
private NautHashMap<String, String> _entries = new NautHashMap<String, String>();
|
||||
|
||||
public SimpleStats(JavaPlugin plugin)
|
||||
{
|
||||
super("SimpleStats", plugin);
|
||||
|
||||
_repository.initialize();
|
||||
}
|
||||
|
||||
public NautHashMap<String, String> get_entries() {
|
||||
return _entries;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void storeStatsUpdate(final UpdateEvent updateEvent)
|
||||
{
|
||||
if (updateEvent.getType() != UpdateType.SLOW)
|
||||
return;
|
||||
|
||||
synchronized (_transferLock)
|
||||
{
|
||||
Bukkit.getScheduler().runTaskAsynchronously(GetPlugin(), new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
_entries = (_repository.retrieveStatRecords());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void store(String statName, String statValue)
|
||||
{
|
||||
final String statNameFinal = statName;
|
||||
final String statValueFinal = statValue;
|
||||
|
||||
synchronized (_transferLock)
|
||||
{
|
||||
Bukkit.getScheduler().runTaskAsynchronously(GetPlugin(), new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
_repository.storeStatValue(statNameFinal, statValueFinal);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,158 @@
|
||||
package mineplex.core.simpleStats;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import mineplex.core.common.util.NautHashMap;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class SimpleStatsRepository
|
||||
{
|
||||
private static Object _connectionLock = new Object();
|
||||
|
||||
private String _connectionString = "jdbc:mysql://sqlstats.mineplex.com:3306/Queue?autoReconnect=true&failOverReadOnly=false&maxReconnects=10";
|
||||
private String _userName = "root";
|
||||
private String _password = "tAbechAk3wR7tuTh"; //try to obfuscate this in the future!
|
||||
|
||||
private static String CREATE_STATS_TABLE = "CREATE TABLE IF NOT EXISTS simpleStats (id INT NOT NULL AUTO_INCREMENT, statName VARCHAR(64), statValue VARCHAR(64), PRIMARY KEY (id));";
|
||||
private static String RETRIEVE_STATS_RECORDS = "SELECT statName.*, statValue.* FROM simpleStats;";
|
||||
private static String STORE_STATS_RECORD = "INSERT INTO simpleStats (statName,statValue) VALUES(";
|
||||
|
||||
private Connection _connection = null;
|
||||
|
||||
public void initialize()
|
||||
{
|
||||
PreparedStatement preparedStatement = null;
|
||||
|
||||
try
|
||||
{
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
|
||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||
|
||||
// Create table
|
||||
preparedStatement = _connection.prepareStatement(CREATE_STATS_TABLE);
|
||||
preparedStatement.execute();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
exception.printStackTrace();
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (preparedStatement != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
preparedStatement.close();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public NautHashMap<String, String> retrieveStatRecords()
|
||||
{
|
||||
ResultSet resultSet = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
NautHashMap<String, String> statRecords = new NautHashMap<String, String>();
|
||||
|
||||
try
|
||||
{
|
||||
synchronized (_connectionLock)
|
||||
{
|
||||
if (_connection.isClosed())
|
||||
{
|
||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||
}
|
||||
|
||||
preparedStatement = _connection.prepareStatement(RETRIEVE_STATS_RECORDS);
|
||||
|
||||
resultSet = preparedStatement.executeQuery();
|
||||
|
||||
while (resultSet.next())
|
||||
{
|
||||
statRecords.put(resultSet.getString(1), resultSet.getString(2));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
exception.printStackTrace();
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (preparedStatement != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
preparedStatement.close();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (resultSet != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
resultSet.close();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return statRecords;
|
||||
}
|
||||
|
||||
public void storeStatValue(String statName, String statValue)
|
||||
{
|
||||
PreparedStatement preparedStatement = null;
|
||||
|
||||
try
|
||||
{
|
||||
synchronized (_connectionLock)
|
||||
{
|
||||
if (_connection.isClosed())
|
||||
{
|
||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||
}
|
||||
|
||||
preparedStatement = _connection.prepareStatement(STORE_STATS_RECORD + statName + "," + statValue + ");");
|
||||
|
||||
preparedStatement.executeUpdate();
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
exception.printStackTrace();
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (preparedStatement != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
preparedStatement.close();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -169,7 +169,7 @@ public class GadgetPage extends ShopPageBase<GadgetManager, GadgetShop>
|
||||
itemLore.add(C.cBlack);
|
||||
itemLore.addAll(Arrays.asList(gadget.GetDescription()));
|
||||
|
||||
if (DonationManager.Get(Player.getName()).OwnsUnknownPackage(gadget.GetName()))
|
||||
if (gadget.GetCost(CurrencyType.Gems) == -1 || DonationManager.Get(Player.getName()).OwnsUnknownPackage(gadget.GetName()))
|
||||
{
|
||||
if (gadget.GetActive().contains(Player))
|
||||
{
|
||||
|
@ -9,8 +9,8 @@ import mineplex.core.donation.DonationManager;
|
||||
import mineplex.hub.gadget.GadgetManager;
|
||||
import mineplex.hub.pet.Pet;
|
||||
import mineplex.hub.pet.PetExtra;
|
||||
import mineplex.core.pet.repository.token.PetChangeToken;
|
||||
import mineplex.core.pet.repository.token.PetToken;
|
||||
import mineplex.hub.pet.repository.token.PetChangeToken;
|
||||
import mineplex.hub.pet.repository.token.PetToken;
|
||||
import mineplex.core.shop.page.ConfirmationPage;
|
||||
import mineplex.core.shop.page.ShopPageBase;
|
||||
import net.minecraft.server.v1_7_R3.ItemStack;
|
||||
|
@ -1,9 +1,9 @@
|
||||
package mineplex.hub.pet;
|
||||
|
||||
import mineplex.core.common.CurrencyType;
|
||||
import mineplex.core.pet.repository.token.PetSalesToken;
|
||||
import mineplex.core.shop.item.SalesPackageBase;
|
||||
import mineplex.core.shop.item.ShopItem;
|
||||
import mineplex.hub.pet.repository.token.PetSalesToken;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
@ -3,8 +3,8 @@ package mineplex.hub.pet;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
import mineplex.core.common.util.NautHashMap;
|
||||
import mineplex.core.pet.repository.token.ClientPetToken;
|
||||
import mineplex.core.pet.repository.token.PetToken;
|
||||
import mineplex.hub.pet.repository.token.ClientPetToken;
|
||||
import mineplex.hub.pet.repository.token.PetToken;
|
||||
|
||||
public class PetClient
|
||||
{
|
||||
|
@ -2,8 +2,8 @@ package mineplex.hub.pet;
|
||||
|
||||
import mineplex.core.common.CurrencyType;
|
||||
import mineplex.core.itemstack.ItemStackFactory;
|
||||
import mineplex.core.pet.repository.token.PetExtraToken;
|
||||
import mineplex.core.shop.item.SalesPackageBase;
|
||||
import mineplex.hub.pet.repository.token.PetExtraToken;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
|
@ -5,9 +5,9 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import mineplex.core.common.util.NautHashMap;
|
||||
import mineplex.core.pet.repository.token.PetExtraToken;
|
||||
import mineplex.core.pet.repository.token.PetSalesToken;
|
||||
import mineplex.hub.pet.repository.PetRepository;
|
||||
import mineplex.hub.pet.repository.token.PetExtraToken;
|
||||
import mineplex.hub.pet.repository.token.PetSalesToken;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
@ -5,7 +5,6 @@ import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import mineplex.core.MiniClientPlugin;
|
||||
import mineplex.core.pet.repository.token.ClientPetTokenWrapper;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
@ -17,6 +16,7 @@ import mineplex.core.common.util.UtilInv;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
import mineplex.core.itemstack.ItemStackFactory;
|
||||
import mineplex.hub.pet.repository.PetRepository;
|
||||
import mineplex.hub.pet.repository.token.ClientPetTokenWrapper;
|
||||
import net.minecraft.server.v1_7_R3.EntityCreature;
|
||||
import net.minecraft.server.v1_7_R3.EntityHuman;
|
||||
import net.minecraft.server.v1_7_R3.EntityInsentient;
|
||||
@ -30,6 +30,7 @@ import net.minecraft.server.v1_7_R3.PathfinderGoalSelector;
|
||||
|
||||
|
||||
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
|
@ -4,11 +4,11 @@ import java.util.List;
|
||||
|
||||
import org.bukkit.craftbukkit.libs.com.google.gson.reflect.TypeToken;
|
||||
|
||||
import mineplex.core.pet.repository.token.PetChangeToken;
|
||||
import mineplex.core.pet.repository.token.PetExtraToken;
|
||||
import mineplex.core.pet.repository.token.PetSalesToken;
|
||||
import mineplex.core.server.remotecall.AsyncJsonWebCall;
|
||||
import mineplex.core.server.remotecall.JsonWebCall;
|
||||
import mineplex.hub.pet.repository.token.PetChangeToken;
|
||||
import mineplex.hub.pet.repository.token.PetExtraToken;
|
||||
import mineplex.hub.pet.repository.token.PetSalesToken;
|
||||
|
||||
public class PetRepository
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
package mineplex.core.pet.repository.token;
|
||||
package mineplex.hub.pet.repository.token;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package mineplex.core.pet.repository.token;
|
||||
package mineplex.hub.pet.repository.token;
|
||||
|
||||
public class ClientPetTokenWrapper
|
||||
{
|
@ -1,4 +1,4 @@
|
||||
package mineplex.core.pet.repository.token;
|
||||
package mineplex.hub.pet.repository.token;
|
||||
|
||||
public class PetChangeToken
|
||||
{
|
@ -1,4 +1,4 @@
|
||||
package mineplex.core.pet.repository.token;
|
||||
package mineplex.hub.pet.repository.token;
|
||||
|
||||
public class PetExtraToken
|
||||
{
|
@ -1,4 +1,4 @@
|
||||
package mineplex.core.pet.repository.token;
|
||||
package mineplex.hub.pet.repository.token;
|
||||
|
||||
public class PetSalesToken
|
||||
{
|
@ -1,4 +1,4 @@
|
||||
package mineplex.core.pet.repository.token;
|
||||
package mineplex.hub.pet.repository.token;
|
||||
|
||||
public class PetToken
|
||||
{
|
@ -77,8 +77,13 @@ public class Arcade extends JavaPlugin implements INautilusPlugin
|
||||
|
||||
_donationManager = new DonationManager(this, GetWebServerAddress());
|
||||
|
||||
<<<<<<< HEAD
|
||||
PreferencesManager preferences = new PreferencesManager(this, _clientManager, _donationManager);
|
||||
new MessageManager(this, _clientManager, preferences);
|
||||
=======
|
||||
PreferencesManager preferenceManager = new PreferencesManager(this, _clientManager, _donationManager);
|
||||
new MessageManager(this, _clientManager, preferenceManager);
|
||||
>>>>>>> 0bf702902e17516316ac3453297110af4cfdec5f
|
||||
|
||||
AntiStack antistack = new AntiStack(this);
|
||||
|
||||
@ -98,7 +103,11 @@ public class Arcade extends JavaPlugin implements INautilusPlugin
|
||||
AntiHack.Initialize(this, punish, portal);
|
||||
|
||||
//Arcade Manager
|
||||
<<<<<<< HEAD
|
||||
_gameManager = new ArcadeManager(this, serverStatusManager, ReadServerConfig(), _clientManager, _donationManager, _damageManager, disguiseManager, creature, teleport, new Blood(this), antistack, portal, packetHandler, preferences, GetWebServerAddress());
|
||||
=======
|
||||
_gameManager = new ArcadeManager(this, serverStatusManager, ReadServerConfig(), _clientManager, _donationManager, _damageManager, disguiseManager, creature, teleport, new Blood(this), antistack, portal, packetHandler, preferenceManager, GetWebServerAddress());
|
||||
>>>>>>> 0bf702902e17516316ac3453297110af4cfdec5f
|
||||
|
||||
new MemoryFix(this);
|
||||
|
||||
|
@ -52,7 +52,7 @@ public class ChampionsDominate extends Domination
|
||||
|
||||
Manager.GetDamage().UseSimpleWeaponDamage = false;
|
||||
|
||||
EloRanking = true;
|
||||
EloRanking = false;
|
||||
EloStart = 1000;
|
||||
}
|
||||
|
||||
@ -64,6 +64,7 @@ public class ChampionsDominate extends Domination
|
||||
{
|
||||
SetKit(player, GetKits()[2], true);
|
||||
player.closeInventory();
|
||||
System.out.println("Closing inventory from validate kit");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -330,6 +330,7 @@ public class Domination extends TeamGame
|
||||
{
|
||||
event.setCancelled(true);
|
||||
event.getWhoClicked().closeInventory();
|
||||
System.out.println("Closing inventory from crafting in Domination");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,180 @@
|
||||
package nautilus.game.arcade.scoreboard;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
import mineplex.core.common.util.UtilTime.TimeUnit;
|
||||
import nautilus.game.arcade.game.Game;
|
||||
import nautilus.game.arcade.game.GameTeam;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scoreboard.DisplaySlot;
|
||||
import org.bukkit.scoreboard.Objective;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
public class GameScoreboard
|
||||
{
|
||||
private Game Game;
|
||||
|
||||
private Scoreboard _scoreboard;
|
||||
private Objective _sideObjective;
|
||||
|
||||
private ArrayList<ScoreboardElement> _elements = new ArrayList<ScoreboardElement>();
|
||||
private String _space = " ";
|
||||
|
||||
public GameScoreboard(Game game)
|
||||
{
|
||||
Game = game;
|
||||
|
||||
//Scoreboard
|
||||
_scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
|
||||
|
||||
_sideObjective = _scoreboard.registerNewObjective("Obj"+UtilMath.r(999999999), "dummy");
|
||||
_sideObjective.setDisplaySlot(DisplaySlot.SIDEBAR);
|
||||
_sideObjective.setDisplayName(C.Bold + game.GetName());
|
||||
}
|
||||
|
||||
public Scoreboard GetScoreboard()
|
||||
{
|
||||
return _scoreboard;
|
||||
}
|
||||
|
||||
public Objective GetObjectiveSide()
|
||||
{
|
||||
return _sideObjective;
|
||||
}
|
||||
|
||||
public void CreateTeams()
|
||||
{
|
||||
System.out.println("Creating Scoreboard Teams.");
|
||||
|
||||
//Base Groups
|
||||
for (Rank rank : Rank.values())
|
||||
{
|
||||
//Spectator
|
||||
if (rank == Rank.ALL)
|
||||
{
|
||||
_scoreboard.registerNewTeam(rank.Name + "SPEC").setPrefix(ChatColor.GRAY + "");
|
||||
}
|
||||
else
|
||||
{
|
||||
_scoreboard.registerNewTeam(rank.Name + "SPEC").setPrefix(ChatColor.GRAY + "");
|
||||
//_scoreboard.registerNewTeam(rank.Name + "SPEC").setPrefix(rank.Color + C.Bold + rank.Name.toUpperCase() + ChatColor.RESET + " " + ChatColor.GRAY);
|
||||
}
|
||||
}
|
||||
|
||||
//Team Groups
|
||||
for (GameTeam team : Game.GetTeamList())
|
||||
{
|
||||
for (Rank rank : Rank.values())
|
||||
{
|
||||
if (rank == Rank.ALL)
|
||||
{
|
||||
_scoreboard.registerNewTeam(rank.Name + team.GetName().toUpperCase()).setPrefix(team.GetColor() + "");
|
||||
}
|
||||
else
|
||||
{
|
||||
//_scoreboard.registerNewTeam(rank.Name + team.GetName().toUpperCase()).setPrefix(rank.Color + C.Bold + rank.Name.toUpperCase() + ChatColor.RESET + " " + team.GetColor());
|
||||
_scoreboard.registerNewTeam(rank.Name + team.GetName().toUpperCase()).setPrefix(team.GetColor() + "");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetPlayerTeam(Player player, String teamName)
|
||||
{
|
||||
for (Team team : _scoreboard.getTeams())
|
||||
team.removePlayer(player);
|
||||
|
||||
if (teamName == null)
|
||||
teamName = "";
|
||||
|
||||
_scoreboard.getTeam(Game.Manager.GetClients().Get(player).GetRank().Name + teamName).addPlayer(player);
|
||||
}
|
||||
|
||||
public void ResetScore(String line)
|
||||
{
|
||||
_scoreboard.resetScores(line);
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
for (ScoreboardElement elem : _elements)
|
||||
{
|
||||
for (String line : elem.GetLines())
|
||||
{
|
||||
ResetScore(line);
|
||||
}
|
||||
}
|
||||
|
||||
_elements.clear();
|
||||
|
||||
_space = " ";
|
||||
}
|
||||
|
||||
public String Clean(String line)
|
||||
{
|
||||
if (line.length() >= 16)
|
||||
line = line.substring(0, 15);
|
||||
|
||||
return line;
|
||||
}
|
||||
|
||||
public void Write(String line)
|
||||
{
|
||||
line = Clean(line);
|
||||
|
||||
_elements.add(new ScoreboardElementText(line));
|
||||
}
|
||||
|
||||
public void WriteOrdered(String key, String line, int value, boolean prependScore)
|
||||
{
|
||||
if (prependScore)
|
||||
line = value + " " + line;
|
||||
|
||||
line = Clean(line);
|
||||
|
||||
for (ScoreboardElement elem : _elements)
|
||||
{
|
||||
if (elem instanceof ScoreboardElementScores)
|
||||
{
|
||||
ScoreboardElementScores scores = (ScoreboardElementScores)elem;
|
||||
|
||||
if (scores.IsKey(key))
|
||||
{
|
||||
scores.AddScore(line, value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_elements.add(new ScoreboardElementScores(key, line, value, true));
|
||||
}
|
||||
|
||||
public void WriteBlank()
|
||||
{
|
||||
_elements.add(new ScoreboardElementText(_space));
|
||||
_space += " ";
|
||||
}
|
||||
|
||||
public void Draw()
|
||||
{
|
||||
int i = 15;
|
||||
for (ScoreboardElement elem : _elements)
|
||||
{
|
||||
for (String line : elem.GetLines())
|
||||
{
|
||||
GetObjectiveSide().getScore(line).setScore(i--);
|
||||
}
|
||||
|
||||
if (i <= 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package nautilus.game.arcade.scoreboard;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public abstract class ScoreboardElement
|
||||
{
|
||||
public abstract ArrayList<String> GetLines();
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package nautilus.game.arcade.scoreboard;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ScoreboardElementScores extends ScoreboardElement
|
||||
{
|
||||
private String _key;
|
||||
|
||||
private HashMap<String, Integer> _scores;
|
||||
|
||||
private boolean _higherIsBetter;
|
||||
|
||||
public ScoreboardElementScores(String key, String line, int value, boolean higherIsBetter)
|
||||
{
|
||||
_scores = new HashMap<String, Integer>();
|
||||
|
||||
_key = key;
|
||||
|
||||
AddScore(line, value);
|
||||
|
||||
_higherIsBetter = higherIsBetter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<String> GetLines()
|
||||
{
|
||||
ArrayList<String> orderedScores = new ArrayList<String>();
|
||||
|
||||
//Order Scores
|
||||
while (orderedScores.size() < _scores.size())
|
||||
{
|
||||
String bestKey = null;
|
||||
int bestScore = 0;
|
||||
|
||||
for (String key : _scores.keySet())
|
||||
{
|
||||
if (orderedScores.contains(key))
|
||||
continue;
|
||||
|
||||
if (bestKey == null ||
|
||||
(_higherIsBetter && _scores.get(key) >= bestScore) ||
|
||||
(!_higherIsBetter && _scores.get(key) <= bestScore))
|
||||
{
|
||||
bestKey = key;
|
||||
bestScore = _scores.get(key);
|
||||
}
|
||||
}
|
||||
|
||||
orderedScores.add(bestKey);
|
||||
}
|
||||
|
||||
return orderedScores;
|
||||
}
|
||||
|
||||
public boolean IsKey(String key)
|
||||
{
|
||||
return _key.equals(key);
|
||||
}
|
||||
|
||||
public void AddScore(String line, int value)
|
||||
{
|
||||
_scores.put(line, value);
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package nautilus.game.arcade.scoreboard;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ScoreboardElementText extends ScoreboardElement
|
||||
{
|
||||
private String _line;
|
||||
|
||||
public ScoreboardElementText(String line)
|
||||
{
|
||||
_line = line;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<String> GetLines()
|
||||
{
|
||||
ArrayList<String> orderedScores = new ArrayList<String>();
|
||||
|
||||
orderedScores.add(_line);
|
||||
|
||||
return orderedScores;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user