Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 101 additions & 35 deletions src/main/java/woolbattle/woolbattle/Cache.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class Cache {

/**
* A Class that contains a few HashMaps with setters and getters to cache different things easily.
*
* @author SimsumMC
*/

Expand All @@ -33,75 +34,140 @@ public class Cache {

private static HashMap<Player, HashMap<String, Integer>> activePerkSlots = new HashMap<>();

private static HashMap<String, HashMap<Player, Integer>> killStreaks = new HashMap<String, HashMap<Player, Integer>>(){{
private static HashMap<String, HashMap<Player, Integer>> killStreaks = new HashMap<String, HashMap<Player, Integer>>() {{
put("Blue", new HashMap<>());
put("Red", new HashMap<>());
put("Green", new HashMap<>());
put("Yellow", new HashMap<>());
}};

private static HashMap<String, ArrayList<Player>> teamMembers = new HashMap<String, ArrayList<Player>>(){{
private static HashMap<String, ArrayList<Player>> teamMembers = new HashMap<String, ArrayList<Player>>() {{
put("Blue", new ArrayList<>());
put("Red", new ArrayList<>());
put("Green", new ArrayList<>());
put("Yellow", new ArrayList<>());
}};

private static HashMap<String, Integer> teamLives = new HashMap<String, Integer>(){{
private static HashMap<String, Integer> teamLives = new HashMap<String, Integer>() {{
put("Blue", 0);
put("Red", 0);
put("Green", 0);
put("Yellow", 0);
}};

private static HashMap<Integer, ArrayList<Player>> lifeVoting = new HashMap<Integer, ArrayList<Player>>(){{
private static HashMap<Integer, ArrayList<Player>> lifeVoting = new HashMap<Integer, ArrayList<Player>>() {{
put(5, new ArrayList<>());
put(10, new ArrayList<>());
put(15, new ArrayList<>());
}};

private static HashMap<Player, HashMap<String, Integer>> playerStats = new HashMap<>();

public static HashMap<String, ActivePerk> getActivePerks() {return activePerks;}
public static void setActivePerks(HashMap<String, ActivePerk> activePerks) {Cache.activePerks = activePerks;}
public static HashMap<String, ActivePerk> getActivePerks() {
return activePerks;
}

public static void setActivePerks(HashMap<String, ActivePerk> activePerks) {
Cache.activePerks = activePerks;
}

public static HashMap<String, PassivePerk<? extends Event, ?>> getPassivePerks() {
return passivePerks;
}

public static HashMap<String, PassivePerk<? extends Event,?>> getPassivePerks() {return passivePerks;}
public static void setPassivePerks(HashMap<String, PassivePerk<? extends Event,?>> passivePerks) {Cache.passivePerks = passivePerks;}
public static void setPassivePerks(HashMap<String, PassivePerk<? extends Event, ?>> passivePerks) {
Cache.passivePerks = passivePerks;
}

public static HashMap<Player, Player> getPlayerDuels() {
return playerDuels;
}

public static void setPlayerDuels(HashMap<Player, Player> playerDuels) {
Cache.playerDuels = playerDuels;
}

public static HashMap<Player, Player> getPlayerDuels() {return playerDuels;}
public static void setPlayerDuels(HashMap<Player, Player> playerDuels) {Cache.playerDuels = playerDuels;}
public static HashMap<Player, Long> getLastDamage() {
return lastDamage;
}

public static HashMap<Player, Long> getLastDamage() {return lastDamage;}
public static void setLastDamage(HashMap<Player, Long> lastDamage) {Cache.lastDamage = lastDamage;}
public static void setLastDamage(HashMap<Player, Long> lastDamage) {
Cache.lastDamage = lastDamage;
}

public static HashMap<Player, Long> getSpawnProtection() {return spawnProtection;}
public static void setSpawnProtection(HashMap<Player, Long> spawnProtection) {Cache.spawnProtection = spawnProtection;}
public static HashMap<Player, Long> getSpawnProtection() {
return spawnProtection;
}

public static HashMap<Player, ArrayList<EnderPearl>> getEnderPearls() {return enderPearls;}
public static void setEnderPearls(HashMap<Player, ArrayList<EnderPearl>> enderPearls) {Cache.enderPearls = enderPearls;}
public static void setSpawnProtection(HashMap<Player, Long> spawnProtection) {
Cache.spawnProtection = spawnProtection;
}

public static HashMap<Player, ArrayList<ArrayList<Block>>> getJumpPlatformBlocks() {return jumpPlatformBlocks;}
public static void setJumpPlatformBlocks(HashMap<Player, ArrayList<ArrayList<Block>>> jumpPlatformBlocks) {Cache.jumpPlatformBlocks = jumpPlatformBlocks;}
public static HashMap<Player, ArrayList<EnderPearl>> getEnderPearls() {
return enderPearls;
}

public static HashMap<String, HashMap<Player, Integer>> getKillStreaks() {return killStreaks;}
public static void setKillStreaks(HashMap<String, HashMap<Player, Integer>> killStreaks) {Cache.killStreaks = killStreaks;}
public static void setEnderPearls(HashMap<Player, ArrayList<EnderPearl>> enderPearls) {
Cache.enderPearls = enderPearls;
}

public static HashMap<String, ArrayList<Player>> getTeamMembers() {return teamMembers;}
public static void setTeamMembers(HashMap<String, ArrayList<Player>> teamMembers) {Cache.teamMembers = teamMembers;}
public static HashMap<Player, ArrayList<ArrayList<Block>>> getJumpPlatformBlocks() {
return jumpPlatformBlocks;
}

public static HashMap<String, Integer> getTeamLives() {return teamLives;}
public static void setTeamLives(HashMap<String, Integer> teamLives) {Cache.teamLives = teamLives;}
public static void setJumpPlatformBlocks(HashMap<Player, ArrayList<ArrayList<Block>>> jumpPlatformBlocks) {
Cache.jumpPlatformBlocks = jumpPlatformBlocks;
}

public static HashMap<Integer, ArrayList<Player>> getLifeVoting() {return lifeVoting;}
public static void setLifeVoting(HashMap<Integer, ArrayList<Player>> lifeVoting) {Cache.lifeVoting = lifeVoting;}
public static HashMap<String, HashMap<Player, Integer>> getKillStreaks() {
return killStreaks;
}

public static HashMap<Player, HashMap<String, Integer>> getPlayerStats() {return playerStats;}
public static void setPlayerStats(HashMap<Player, HashMap<String, Integer>> playerStats) {Cache.playerStats = playerStats;}
public static void setKillStreaks(HashMap<String, HashMap<Player, Integer>> killStreaks) {
Cache.killStreaks = killStreaks;
}

public static HashMap<Player, HashMap<String, Integer>> getActivePerkSlots() {return activePerkSlots;}
public static void setActivePerkSlots(HashMap<Player, HashMap<String, Integer>> activePerkSlots) {Cache.activePerkSlots = activePerkSlots;}
public static HashMap<String, ArrayList<Player>> getTeamMembers() {
return teamMembers;
}

public static void setTeamMembers(HashMap<String, ArrayList<Player>> teamMembers) {
Cache.teamMembers = teamMembers;
}

public static HashMap<String, Integer> getTeamLives() {
return teamLives;
}

public static void setTeamLives(HashMap<String, Integer> teamLives) {
Cache.teamLives = teamLives;
}

public static HashMap<Integer, ArrayList<Player>> getLifeVoting() {
return lifeVoting;
}

public static void setLifeVoting(HashMap<Integer, ArrayList<Player>> lifeVoting) {
Cache.lifeVoting = lifeVoting;
}

public static HashMap<Player, HashMap<String, Integer>> getPlayerStats() {
return playerStats;
}

public static void setPlayerStats(HashMap<Player, HashMap<String, Integer>> playerStats) {
Cache.playerStats = playerStats;
}

public static HashMap<Player, HashMap<String, Integer>> getActivePerkSlots() {
return activePerkSlots;
}

public static void setActivePerkSlots(HashMap<Player, HashMap<String, Integer>> activePerkSlots) {
Cache.activePerkSlots = activePerkSlots;
}

public static void clear(){
public static void clear() {
playerDuels = new HashMap<>();

lastDamage = new HashMap<>();
Expand All @@ -116,28 +182,28 @@ public static void clear(){

activePerkSlots = new HashMap<>();

killStreaks = new HashMap<String, HashMap<Player, Integer>>(){{
killStreaks = new HashMap<String, HashMap<Player, Integer>>() {{
put("Blue", new HashMap<>());
put("Red", new HashMap<>());
put("Green", new HashMap<>());
put("Yellow", new HashMap<>());
}};

teamMembers = new HashMap<String, ArrayList<Player>>(){{
teamMembers = new HashMap<String, ArrayList<Player>>() {{
put("Blue", new ArrayList<>());
put("Red", new ArrayList<>());
put("Green", new ArrayList<>());
put("Yellow", new ArrayList<>());
}};

teamLives = new HashMap<String, Integer>(){{
teamLives = new HashMap<String, Integer>() {{
put("Blue", 0);
put("Red", 0);
put("Green", 0);
put("Yellow", 0);
}};

lifeVoting = new HashMap<Integer, ArrayList<Player>>(){{
lifeVoting = new HashMap<Integer, ArrayList<Player>>() {{
put(5, new ArrayList<>());
put(10, new ArrayList<>());
put(15, new ArrayList<>());
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/woolbattle/woolbattle/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class Config {

/**
* A Config class that contains all default values from the config.json as variables.
*
* @author SimsumMC & Servaturus
*/

Expand Down Expand Up @@ -95,10 +96,11 @@ public class Config {

/**
* Returns the value of the given key from the config.json.
*
* @param key the JSON key as a String<br>
* @author SimsumMC & Servaturus
*/
public static Object getValue(String key) {
public static Object getValue(String key) {
if (!fileExisting) {

// make sure that the directory exists
Expand Down Expand Up @@ -146,5 +148,5 @@ public static Object getValue(String key) {
e.printStackTrace();
}
return jsonObject.get(key);
}
}
}
16 changes: 8 additions & 8 deletions src/main/java/woolbattle/woolbattle/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
import woolbattle.woolbattle.lobby.LobbySystem;
import woolbattle.woolbattle.lobby.StartGameCommand;
import woolbattle.woolbattle.lobby.StopGameCommand;
import woolbattle.woolbattle.maprestaurationsystem.MapCommand;
import woolbattle.woolbattle.map.MapCommand;
import woolbattle.woolbattle.perks.AllActivePerks;
import woolbattle.woolbattle.perks.AllPassivePerks;
import woolbattle.woolbattle.stats.StatsCommand;
import woolbattle.woolbattle.team.TeamSystem;
import woolbattle.woolbattle.woolsystem.BlockBreakingSystem;
import woolbattle.woolbattle.woolsystem.BlockRegistrationCommand;
import woolbattle.woolbattle.woolsystem.MapBlocksCommand;
import woolbattle.woolbattle.map.BlockBreakingSystem;
import woolbattle.woolbattle.map.BlockRegistrationCommand;
import woolbattle.woolbattle.map.Listener;
import woolbattle.woolbattle.map.MapBlocksCommand;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -80,13 +81,12 @@ public void onEnable() {
BlockBreakingSystem.setCollectBrokenBlocks(false);
BlockBreakingSystem.fetchMapBlocks();

for (Player player : Bukkit.getOnlinePlayers())
{
for (Player player : Bukkit.getOnlinePlayers()) {
player.setAllowFlight(true);
MongoCollection<Document> collection = db.getCollection("playerAchievements");

Document foundDocument = collection.find(eq("_id", player.getUniqueId().toString())).first();
if(foundDocument == null) {
if (foundDocument == null) {
HashMap<String, Object> playerData = new HashMap<String, Object>() {{
put("_id", player.getUniqueId().toString());
put("achievements", new ArrayList<String>());
Expand All @@ -102,7 +102,7 @@ public void onDisable() {
// Plugin shutdown logic
}

public static Main getInstance(){
public static Main getInstance() {
return instance;
}

Expand Down
Loading