Refactor other classes to reflect new Cache class name

This commit is contained in:
Bea 2022-05-31 20:14:53 +02:00
parent 3bc9969ed4
commit 433418ca70
16 changed files with 109 additions and 138 deletions

View File

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AntConfiguration">
<buildFile url="file://$PROJECT_DIR$/ant_build_increment.xml">
<executeOn event="afterCompilation" target="end" />
<executeOn event="beforeCompilation" target="init" />
</buildFile>
</component>
</project>

View File

@ -1,6 +1,6 @@
package net.mindoverflow.network.uhccore.commands.uhccommands; package net.mindoverflow.network.uhccore.commands.uhccommands;
import net.mindoverflow.network.uhccore.utils.CommonValues; import net.mindoverflow.network.uhccore.utils.Cache;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import java.util.ArrayList; import java.util.ArrayList;
@ -12,12 +12,12 @@ public class ListCommand
{ {
HashMap<Integer, ArrayList<String>>playersPerTeam = new HashMap<>(); HashMap<Integer, ArrayList<String>>playersPerTeam = new HashMap<>();
for(int i = 0; i < CommonValues.totalTeams; i++) for(int i = 0; i < Cache.totalTeams; i++)
{ {
ArrayList<String>playersInThisTeam = new ArrayList<>(); ArrayList<String>playersInThisTeam = new ArrayList<>();
for(String playerName : CommonValues.playerTeam.keySet()) for(String playerName : Cache.playerTeam.keySet())
{ {
if(CommonValues.playerTeam.get(playerName).equals(i)) if(Cache.playerTeam.get(playerName).equals(i))
{ {
playersInThisTeam.add(playerName); playersInThisTeam.add(playerName);
} }
@ -28,7 +28,7 @@ public class ListCommand
commandSender.sendMessage("§6-------[ UHC: Lista Team ]-------"); commandSender.sendMessage("§6-------[ UHC: Lista Team ]-------");
for(Integer i : playersPerTeam.keySet()) for(Integer i : playersPerTeam.keySet())
{ {
String teamName = CommonValues.teamNames.get(i); String teamName = Cache.teamNames.get(i);
int playersInThisTeam = playersPerTeam.get(i).size(); int playersInThisTeam = playersPerTeam.get(i).size();
ArrayList<String>playersNames = playersPerTeam.get(i); ArrayList<String>playersNames = playersPerTeam.get(i);
String playersList = playersNames.toString().replace("[", "").replace("]", "").replace(",", "§7,§r"); String playersList = playersNames.toString().replace("[", "").replace("]", "").replace(",", "§7,§r");

View File

@ -1,6 +1,6 @@
package net.mindoverflow.network.uhccore.commands.uhccommands; package net.mindoverflow.network.uhccore.commands.uhccommands;
import net.mindoverflow.network.uhccore.utils.CommonValues; import net.mindoverflow.network.uhccore.utils.Cache;
import net.mindoverflow.network.uhccore.utils.configuration.ConfigEntries; import net.mindoverflow.network.uhccore.utils.configuration.ConfigEntries;
import net.mindoverflow.network.uhccore.utils.Debugger; import net.mindoverflow.network.uhccore.utils.Debugger;
import net.mindoverflow.network.uhccore.utils.configuration.FileUtils; import net.mindoverflow.network.uhccore.utils.configuration.FileUtils;
@ -23,17 +23,17 @@ public class SetFireworkCommand
YamlConfiguration config = FileUtils.FileType.CONFIG_YAML.yaml; YamlConfiguration config = FileUtils.FileType.CONFIG_YAML.yaml;
int listPos = CommonValues.fireworksLocations.size() + 1; int listPos = Cache.fireworksLocations.size() + 1;
if(CommonValues.fireworksLocations.get(0).getWorld() == null) if(Cache.fireworksLocations.get(0).getWorld() == null)
{ {
debugger.sendDebugMessage(Level.SEVERE, "WORLD IS NULL!"); debugger.sendDebugMessage(Level.SEVERE, "WORLD IS NULL!");
listPos = 1; listPos = 1;
CommonValues.fireworksLocations.set(0, fireworkLoc); Cache.fireworksLocations.set(0, fireworkLoc);
} }
else else
{ {
CommonValues.fireworksLocations.add(fireworkLoc); Cache.fireworksLocations.add(fireworkLoc);
} }
String currentPath = ConfigEntries.FIREWORK_POS.path + "." + listPos; String currentPath = ConfigEntries.FIREWORK_POS.path + "." + listPos;

View File

@ -1,6 +1,6 @@
package net.mindoverflow.network.uhccore.commands.uhccommands; package net.mindoverflow.network.uhccore.commands.uhccommands;
import net.mindoverflow.network.uhccore.utils.CommonValues; import net.mindoverflow.network.uhccore.utils.Cache;
import net.mindoverflow.network.uhccore.utils.configuration.ConfigEntries; import net.mindoverflow.network.uhccore.utils.configuration.ConfigEntries;
import net.mindoverflow.network.uhccore.utils.configuration.FileUtils; import net.mindoverflow.network.uhccore.utils.configuration.FileUtils;
import org.bukkit.Location; import org.bukkit.Location;
@ -16,7 +16,7 @@ public class SetSpawnCommand
Player player = (Player) sender; Player player = (Player) sender;
Location playerLoc = player.getLocation(); Location playerLoc = player.getLocation();
CommonValues.spawn = playerLoc; Cache.spawn = playerLoc;
YamlConfiguration config = FileUtils.FileType.CONFIG_YAML.yaml; YamlConfiguration config = FileUtils.FileType.CONFIG_YAML.yaml;
config.set(ConfigEntries.SPAWN_WORLD.path, playerLoc.getWorld().getName()); config.set(ConfigEntries.SPAWN_WORLD.path, playerLoc.getWorld().getName());
config.set(ConfigEntries.SPAWN_X.path, playerLoc.getX()); config.set(ConfigEntries.SPAWN_X.path, playerLoc.getX());

View File

@ -1,7 +1,7 @@
package net.mindoverflow.network.uhccore.commands.uhccommands; package net.mindoverflow.network.uhccore.commands.uhccommands;
import net.mindoverflow.network.uhccore.UhcCore; import net.mindoverflow.network.uhccore.UhcCore;
import net.mindoverflow.network.uhccore.utils.CommonValues; import net.mindoverflow.network.uhccore.utils.Cache;
import net.mindoverflow.network.uhccore.utils.Debugger; import net.mindoverflow.network.uhccore.utils.Debugger;
import net.mindoverflow.network.uhccore.utils.math.NumberUtils; import net.mindoverflow.network.uhccore.utils.math.NumberUtils;
import org.bukkit.*; import org.bukkit.*;
@ -23,17 +23,17 @@ public class StartUhcCommand {
HashMap<Integer, Location> spawnPerTeam = new HashMap<>(); HashMap<Integer, Location> spawnPerTeam = new HashMap<>();
World spawnWorld = plugin.getServer().getWorld(CommonValues.uhcWorlds.get(0)); World spawnWorld = plugin.getServer().getWorld(Cache.uhcWorlds.get(0));
int borderX = CommonValues.borderX; int borderX = Cache.borderX;
int borderZ = CommonValues.borderZ; int borderZ = Cache.borderZ;
int borderSize = CommonValues.borderSize; int borderSize = Cache.borderSize;
int range = borderSize / 2; int range = borderSize / 2;
Location borderCenter = new Location(spawnWorld, borderX, 64, borderZ); Location borderCenter = new Location(spawnWorld, borderX, 64, borderZ);
for(String playerName : CommonValues.playerTeam.keySet()) for(String playerName : Cache.playerTeam.keySet())
{ {
Player player = plugin.getServer().getPlayer(playerName); Player player = plugin.getServer().getPlayer(playerName);
player.sendTitle("La §dUHC§r inizierà a breve!", "ricerca degli spawnpoint...", 20, 70, 10); player.sendTitle("La §dUHC§r inizierà a breve!", "ricerca degli spawnpoint...", 20, 70, 10);
@ -42,7 +42,7 @@ public class StartUhcCommand {
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, ()-> plugin.getServer().getScheduler().runTaskAsynchronously(plugin, ()->
{ {
for(int i = 0; i < CommonValues.totalTeams; i++) for(int i = 0; i < Cache.totalTeams; i++)
{ {
double x = NumberUtils.getRandomNumberInRange(borderX - range + 1, borderX + range - 1) + 0.5; double x = NumberUtils.getRandomNumberInRange(borderX - range + 1, borderX + range - 1) + 0.5;
@ -67,18 +67,18 @@ public class StartUhcCommand {
} }
plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, ()-> plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, ()->
{ {
CommonValues.allowMovement = false; Cache.allowMovement = false;
}, 20L); }, 20L);
plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, ()-> plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, ()->
{ {
CommonValues.allowMovement = true; Cache.allowMovement = true;
}, loadDelay * 20L); }, loadDelay * 20L);
for(String playerName : CommonValues.playerTeam.keySet()) for(String playerName : Cache.playerTeam.keySet())
{ {
int teamNumber = CommonValues.playerTeam.get(playerName); int teamNumber = Cache.playerTeam.get(playerName);
Player player = plugin.getServer().getPlayer(playerName); Player player = plugin.getServer().getPlayer(playerName);
Location hisTeamLoc = spawnPerTeam.get(teamNumber); Location hisTeamLoc = spawnPerTeam.get(teamNumber);

View File

@ -1,7 +1,7 @@
package net.mindoverflow.network.uhccore.listeners; package net.mindoverflow.network.uhccore.listeners;
import net.mindoverflow.network.uhccore.UhcCore; import net.mindoverflow.network.uhccore.UhcCore;
import net.mindoverflow.network.uhccore.utils.CommonValues; import net.mindoverflow.network.uhccore.utils.Cache;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -28,11 +28,11 @@ public class PlayerChatListener implements Listener {
String message; String message;
// Check if the player is in a team. // Check if the player is in a team.
if(CommonValues.playerTeam.containsKey(playerName)) if(Cache.playerTeam.containsKey(playerName))
{ {
// Load the team number and the team name from that. // Load the team number and the team name from that.
int teamNumber = CommonValues.playerTeam.get(playerName); int teamNumber = Cache.playerTeam.get(playerName);
String teamName = CommonValues.teamNames.get(teamNumber); String teamName = Cache.teamNames.get(teamNumber);
// Build the chat message. // Build the chat message.
message = "§7[" + teamName + "§7] §f" + displayName + "§7: " + event.getMessage(); message = "§7[" + teamName + "§7] §f" + displayName + "§7: " + event.getMessage();

View File

@ -1,7 +1,7 @@
package net.mindoverflow.network.uhccore.listeners; package net.mindoverflow.network.uhccore.listeners;
import net.mindoverflow.network.uhccore.UhcCore; import net.mindoverflow.network.uhccore.UhcCore;
import net.mindoverflow.network.uhccore.utils.CommonValues; import net.mindoverflow.network.uhccore.utils.Cache;
import net.mindoverflow.network.uhccore.utils.Debugger; import net.mindoverflow.network.uhccore.utils.Debugger;
import net.mindoverflow.network.uhccore.utils.UhcUtils; import net.mindoverflow.network.uhccore.utils.UhcUtils;
import org.bukkit.*; import org.bukkit.*;
@ -44,10 +44,10 @@ public class PlayerDeathRespawnListener implements Listener
Player player = event.getEntity(); Player player = event.getEntity();
// Remove the Teams selector item from the drops. // Remove the Teams selector item from the drops.
event.getDrops().remove(CommonValues.teamsItem); event.getDrops().remove(Cache.teamsItem);
// Check if the player died in the lobby... // Check if the player died in the lobby...
if(CommonValues.lobbyWorlds.contains(player.getWorld().getName())) if(Cache.lobbyWorlds.contains(player.getWorld().getName()))
{ {
// And clear all drops. // And clear all drops.
event.getDrops().clear(); event.getDrops().clear();
@ -58,7 +58,7 @@ public class PlayerDeathRespawnListener implements Listener
// check if the death world is a UHC world (we don't want this to happen in the lobby!) // check if the death world is a UHC world (we don't want this to happen in the lobby!)
// and // and
// check if the player is in any team (players who are not in a team are not playing!) // check if the player is in any team (players who are not in a team are not playing!)
if((CommonValues.uhcWorlds.contains(player.getWorld().getName())) && CommonValues.playerTeam.containsKey(player.getName())) if((Cache.uhcWorlds.contains(player.getWorld().getName())) && Cache.playerTeam.containsKey(player.getName()))
{ {
// Spawn a Firework where the player died. // Spawn a Firework where the player died.
@ -71,11 +71,11 @@ public class PlayerDeathRespawnListener implements Listener
deadPlayers.put(playerName, player.getLocation()); deadPlayers.put(playerName, player.getLocation());
// Load the dead player's team number. // Load the dead player's team number.
int thisPlayerTeamNumber = CommonValues.playerTeam.get(playerName); int thisPlayerTeamNumber = Cache.playerTeam.get(playerName);
// Load the death player's team name. // Load the death player's team name.
String thisPlayerTeamName = CommonValues.teamNames.get(thisPlayerTeamNumber); String thisPlayerTeamName = Cache.teamNames.get(thisPlayerTeamNumber);
// Remove the player from his team. // Remove the player from his team.
CommonValues.playerTeam.remove(playerName); Cache.playerTeam.remove(playerName);
// Run this task Async, because it may be CPU heavy. // Run this task Async, because it may be CPU heavy.
@ -86,44 +86,44 @@ public class PlayerDeathRespawnListener implements Listener
UhcUtils.updatePlayersPerTeam(); UhcUtils.updatePlayersPerTeam();
// Check how many players are left in the dead player's team. // Check how many players are left in the dead player's team.
int thisPlayerTeamPlayers = CommonValues.playersPerTeam.get(thisPlayerTeamNumber); int thisPlayerTeamPlayers = Cache.playersPerTeam.get(thisPlayerTeamNumber);
// Run this task Sync, because we need to access the API, and also delay it by 1 second. // Run this task Sync, because we need to access the API, and also delay it by 1 second.
plugin.getServer().getScheduler().runTaskLater(plugin, () -> plugin.getServer().getScheduler().runTaskLater(plugin, () ->
{ {
int playingPlayers = CommonValues.playerTeam.size(); int playingPlayers = Cache.playerTeam.size();
for(Player p : plugin.getServer().getOnlinePlayers()) for(Player p : plugin.getServer().getOnlinePlayers())
{ {
p.playSound(p.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, 1, 1); p.playSound(p.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, 1, 1);
} }
plugin.getServer().broadcastMessage(playerName + "§7 del team §e" + thisPlayerTeamName + "§7 è fuori gioco!"); plugin.getServer().broadcastMessage(playerName + "§7 del team §e" + thisPlayerTeamName + "§7 è fuori gioco!");
plugin.getServer().broadcastMessage("§7Nel team " + thisPlayerTeamName + "§7 rimangono §e" + thisPlayerTeamPlayers + "§7 giocatori."); plugin.getServer().broadcastMessage("§7Nel team " + thisPlayerTeamName + "§7 rimangono §e" + thisPlayerTeamPlayers + "§7 giocatori.");
plugin.getServer().broadcastMessage("§7In totale rimangono §e" + playingPlayers + "§7 giocatori, in §e" + CommonValues.playingTeams + "§7 team."); plugin.getServer().broadcastMessage("§7In totale rimangono §e" + playingPlayers + "§7 giocatori, in §e" + Cache.playingTeams + "§7 team.");
if(CommonValues.playingTeams <= 1) if(Cache.playingTeams <= 1)
{ {
CommonValues.allowMovement = false; Cache.allowMovement = false;
scheduleTask(); scheduleTask();
plugin.getServer().broadcastMessage("§6La UHC è finita!"); plugin.getServer().broadcastMessage("§6La UHC è finita!");
int winningTeam = 0; int winningTeam = 0;
for(int i = 0; i < CommonValues.totalTeams; i++) for(int i = 0; i < Cache.totalTeams; i++)
{ {
if(CommonValues.playersPerTeam.get(i) > 0) if(Cache.playersPerTeam.get(i) > 0)
{ {
winningTeam = i; winningTeam = i;
} }
} }
String teamName = CommonValues.teamNames.get(winningTeam) + "§r"; String teamName = Cache.teamNames.get(winningTeam) + "§r";
plugin.getServer().broadcastMessage("§6Ha vinto il team: " + teamName); plugin.getServer().broadcastMessage("§6Ha vinto il team: " + teamName);
for(Player currentPlayer : plugin.getServer().getOnlinePlayers()) for(Player currentPlayer : plugin.getServer().getOnlinePlayers())
{ {
currentPlayer.teleport(CommonValues.spawn); currentPlayer.teleport(Cache.spawn);
// Clear his inventory and give him the Teams selector item. // Clear his inventory and give him the Teams selector item.
UhcUtils.giveTeamsSelectorItem(currentPlayer); UhcUtils.giveTeamsSelectorItem(currentPlayer);
plugin.getLogger().log(Level.INFO,"UHC Finished!"); plugin.getLogger().log(Level.INFO,"UHC Finished!");
@ -159,7 +159,7 @@ public class PlayerDeathRespawnListener implements Listener
// Check if there is more than 1 team alive. // Check if there is more than 1 team alive.
// If there is only 1 team alive, then the UHC is over. // If there is only 1 team alive, then the UHC is over.
if(CommonValues.playingTeams > 1) if(Cache.playingTeams > 1)
{ {
// warn the player that he's not a spectator. // warn the player that he's not a spectator.
player.sendMessage("§cSei morto nella UHC e ora sei uno spettatore!"); player.sendMessage("§cSei morto nella UHC e ora sei uno spettatore!");
@ -221,7 +221,7 @@ public class PlayerDeathRespawnListener implements Listener
taskID = 0; taskID = 0;
} }
for(Location loc : CommonValues.fireworksLocations) for(Location loc : Cache.fireworksLocations)
{ {
debugger.sendDebugMessage(Level.INFO, "FIREWORK LOC: " + loc); debugger.sendDebugMessage(Level.INFO, "FIREWORK LOC: " + loc);
UhcUtils.spawnFirework(loc, 10L); UhcUtils.spawnFirework(loc, 10L);
@ -236,7 +236,7 @@ public class PlayerDeathRespawnListener implements Listener
plugin.getServer().getScheduler().runTaskLater(plugin, ()-> plugin.getServer().getScheduler().runTaskLater(plugin, ()->
{ {
isTaskScheduled = false; isTaskScheduled = false;
CommonValues.allowMovement = true; Cache.allowMovement = true;
for (Player currentPlayer : plugin.getServer().getOnlinePlayers()) for (Player currentPlayer : plugin.getServer().getOnlinePlayers())
{ {

View File

@ -1,6 +1,6 @@
package net.mindoverflow.network.uhccore.listeners; package net.mindoverflow.network.uhccore.listeners;
import net.mindoverflow.network.uhccore.utils.CommonValues; import net.mindoverflow.network.uhccore.utils.Cache;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -14,7 +14,7 @@ public class PlayerHitListener implements Listener
public void onPlayerHitPlayer(EntityDamageByEntityEvent event) public void onPlayerHitPlayer(EntityDamageByEntityEvent event)
{ {
// if friendly fire is enabled, then skip everything that follows and let the hit happen. // if friendly fire is enabled, then skip everything that follows and let the hit happen.
if(CommonValues.friendlyFire) return; if(Cache.friendlyFire) return;
// check if the damaged and damager entities are both players. If they're not, stop. // check if the damaged and damager entities are both players. If they're not, stop.
if(!(event.getDamager() instanceof Player && event.getEntity() instanceof Player)) if(!(event.getDamager() instanceof Player && event.getEntity() instanceof Player))
@ -27,13 +27,13 @@ public class PlayerHitListener implements Listener
String damagerName = event.getDamager().getName(); String damagerName = event.getDamager().getName();
// Check if they're in a team. if they're not, stop. // Check if they're in a team. if they're not, stop.
if(!(CommonValues.playerTeam.containsKey(damagedName) && CommonValues.playerTeam.containsKey(damagerName))) if(!(Cache.playerTeam.containsKey(damagedName) && Cache.playerTeam.containsKey(damagerName)))
{ {
return; return;
} }
// check if they're both in the same team. // check if they're both in the same team.
if(CommonValues.playerTeam.get(damagedName).equals(CommonValues.playerTeam.get(damagerName))) if(Cache.playerTeam.get(damagedName).equals(Cache.playerTeam.get(damagerName)))
{ {
// cancel the event. // cancel the event.
event.setCancelled(true); event.setCancelled(true);

View File

@ -1,7 +1,7 @@
package net.mindoverflow.network.uhccore.listeners; package net.mindoverflow.network.uhccore.listeners;
import net.mindoverflow.network.uhccore.utils.CommonValues; import net.mindoverflow.network.uhccore.utils.Cache;
import net.mindoverflow.network.uhccore.utils.UhcUtils; import net.mindoverflow.network.uhccore.utils.UhcUtils;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -28,10 +28,10 @@ public class PlayerInteractListener implements Listener
Player player = event.getPlayer(); Player player = event.getPlayer();
// check if the player's item in hand was the Teams selector item. // check if the player's item in hand was the Teams selector item.
if(player.getInventory().getItemInMainHand().equals(CommonValues.teamsItem)) if(player.getInventory().getItemInMainHand().equals(Cache.teamsItem))
{ {
// Open the teams selector GUI. // Open the teams selector GUI.
player.openInventory(CommonValues.teamsSelectorGUI.getInventory()); player.openInventory(Cache.teamsSelectorGUI.getInventory());
} }
} }
} }
@ -49,7 +49,7 @@ public class PlayerInteractListener implements Listener
ItemStack item = event.getCurrentItem(); ItemStack item = event.getCurrentItem();
// Check if the clicked inventory is the Teams selector GUI. // Check if the clicked inventory is the Teams selector GUI.
if(event.getClickedInventory().equals(CommonValues.teamsSelectorGUI.getInventory())) if(event.getClickedInventory().equals(Cache.teamsSelectorGUI.getInventory()))
{ {
// Cancel the event (we don't want items to be moved!) // Cancel the event (we don't want items to be moved!)
event.setCancelled(true); event.setCancelled(true);
@ -64,15 +64,15 @@ public class PlayerInteractListener implements Listener
player.closeInventory(); player.closeInventory();
// Check if the clicked item is an existing Team. // Check if the clicked item is an existing Team.
if(CommonValues.teamNames.contains(im.getDisplayName())) if(Cache.teamNames.contains(im.getDisplayName()))
{ {
// Load the team number from the team name in the teams list. // Load the team number from the team name in the teams list.
int teamNumber = CommonValues.teamNames.indexOf(im.getDisplayName()); int teamNumber = Cache.teamNames.indexOf(im.getDisplayName());
// Add the player to that team. // Add the player to that team.
CommonValues.playerTeam.remove(player.getName()); Cache.playerTeam.remove(player.getName());
CommonValues.playerTeam.put(player.getName(), teamNumber); Cache.playerTeam.put(player.getName(), teamNumber);
// Update the total number of players in each team, and the total number of alive teams. // Update the total number of players in each team, and the total number of alive teams.
UhcUtils.updatePlayersPerTeam(); UhcUtils.updatePlayersPerTeam();
@ -81,14 +81,14 @@ public class PlayerInteractListener implements Listener
player.sendMessage("§7Aggiunto al team " + im.getDisplayName()); player.sendMessage("§7Aggiunto al team " + im.getDisplayName());
} }
// Else, check if the clicked item is the one used to quit teams. // Else, check if the clicked item is the one used to quit teams.
else if(item.equals(CommonValues.quitTeamItem)) else if(item.equals(Cache.quitTeamItem))
{ {
// Check if the player is in any team. // Check if the player is in any team.
if(CommonValues.playerTeam.containsKey(player.getName())) if(Cache.playerTeam.containsKey(player.getName()))
{ {
// Remove the player from the team. // Remove the player from the team.
player.sendMessage("§eRimosso dal Team!"); player.sendMessage("§eRimosso dal Team!");
CommonValues.playerTeam.remove(player.getName()); Cache.playerTeam.remove(player.getName());
// Update the total number of players in each team, and the total number of alive teams. // Update the total number of players in each team, and the total number of alive teams.
UhcUtils.updatePlayersPerTeam(); UhcUtils.updatePlayersPerTeam();
@ -98,10 +98,10 @@ public class PlayerInteractListener implements Listener
} }
} }
} // Check if the non-clicked inventory (there always are two inventories) is the Teams selector GUI, and cancel the event (we don't want items to be put inside of it!) } // Check if the non-clicked inventory (there always are two inventories) is the Teams selector GUI, and cancel the event (we don't want items to be put inside of it!)
else if(event.getInventory().equals(CommonValues.teamsSelectorGUI.getInventory())) event.setCancelled(true); else if(event.getInventory().equals(Cache.teamsSelectorGUI.getInventory())) event.setCancelled(true);
// Prevent everyone from moving the Teams selector item in their inventory. // Prevent everyone from moving the Teams selector item in their inventory.
if(item.equals(CommonValues.teamsItem)) event.setCancelled(true); if(item.equals(Cache.teamsItem)) event.setCancelled(true);
} }
@ -111,7 +111,7 @@ public class PlayerInteractListener implements Listener
public void onItemDrop(PlayerDropItemEvent event) public void onItemDrop(PlayerDropItemEvent event)
{ {
// Check if the dropped item is the Teams selector item. // Check if the dropped item is the Teams selector item.
if(event.getItemDrop().getItemStack().equals(CommonValues.teamsItem)) if(event.getItemDrop().getItemStack().equals(Cache.teamsItem))
{ {
// Prevent it from being dropped. // Prevent it from being dropped.
event.setCancelled(true); event.setCancelled(true);

View File

@ -1,17 +1,12 @@
package net.mindoverflow.network.uhccore.listeners; package net.mindoverflow.network.uhccore.listeners;
import net.mindoverflow.network.uhccore.utils.CommonValues; import net.mindoverflow.network.uhccore.utils.Cache;
import net.mindoverflow.network.uhccore.utils.Debugger; import net.mindoverflow.network.uhccore.utils.Debugger;
import net.mindoverflow.network.uhccore.utils.UhcUtils; import net.mindoverflow.network.uhccore.utils.UhcUtils;
import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.logging.Level;
public class PlayerJoinListener implements Listener public class PlayerJoinListener implements Listener
{ {
@ -28,7 +23,7 @@ public class PlayerJoinListener implements Listener
Player player = e.getPlayer(); Player player = e.getPlayer();
if(!(CommonValues.playerTeam.containsKey(player.getName()))) if(!(Cache.playerTeam.containsKey(player.getName())))
{ {
UhcUtils.tpSpawnAndGiveItem(player); UhcUtils.tpSpawnAndGiveItem(player);
} }

View File

@ -1,16 +1,10 @@
package net.mindoverflow.network.uhccore.listeners; package net.mindoverflow.network.uhccore.listeners;
import net.mindoverflow.network.uhccore.UhcCore; import net.mindoverflow.network.uhccore.UhcCore;
import net.mindoverflow.network.uhccore.utils.CommonValues; import net.mindoverflow.network.uhccore.utils.Cache;
import net.mindoverflow.network.uhccore.utils.Debugger;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.scheduler.BukkitTask;
import java.util.logging.Level;
public class PlayerMoveListener implements Listener public class PlayerMoveListener implements Listener
{ {
@ -26,7 +20,7 @@ public class PlayerMoveListener implements Listener
@EventHandler @EventHandler
public void onPlayerMove(PlayerMoveEvent event) public void onPlayerMove(PlayerMoveEvent event)
{ {
if(CommonValues.allowMovement) return; if(Cache.allowMovement) return;
event.setCancelled(true); event.setCancelled(true);
} }
} }

View File

@ -1,6 +1,6 @@
package net.mindoverflow.network.uhccore.listeners; package net.mindoverflow.network.uhccore.listeners;
import net.mindoverflow.network.uhccore.utils.CommonValues; import net.mindoverflow.network.uhccore.utils.Cache;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
@ -8,8 +8,6 @@ import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import java.util.LinkedHashMap;
public class TeamsSelectorGUI implements InventoryHolder public class TeamsSelectorGUI implements InventoryHolder
{ {
@ -28,15 +26,15 @@ public class TeamsSelectorGUI implements InventoryHolder
public void initializeInv() public void initializeInv()
{ {
for(int i = 0; i < CommonValues.totalTeams; i++) for(int i = 0; i < Cache.totalTeams; i++)
{ {
String teamName = CommonValues.teamNames.get(i); String teamName = Cache.teamNames.get(i);
Material itemMat = CommonValues.teamItemsMaterials.get(i); Material itemMat = Cache.teamItemsMaterials.get(i);
inv.setItem(i, createItem(teamName, itemMat)); inv.setItem(i, createItem(teamName, itemMat));
} }
inv.setItem(17, CommonValues.quitTeamItem); inv.setItem(17, Cache.quitTeamItem);
} }

View File

@ -1,22 +1,15 @@
package net.mindoverflow.network.uhccore.utils; package net.mindoverflow.network.uhccore.utils;
import net.mindoverflow.network.uhccore.UhcCore;
import net.mindoverflow.network.uhccore.listeners.TeamsSelectorGUI; import net.mindoverflow.network.uhccore.listeners.TeamsSelectorGUI;
import org.bukkit.Color;
import org.bukkit.FireworkEffect;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Firework;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.FireworkMeta;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
public class CommonValues { public class Cache {
// Values to save the uhc and lobby world names. // Values to save the uhc and lobby world names.
public static List<String> uhcWorlds = new ArrayList<>(), lobbyWorlds = new ArrayList<>(); public static List<String> uhcWorlds = new ArrayList<>(), lobbyWorlds = new ArrayList<>();

View File

@ -19,16 +19,16 @@ public class UhcUtils {
int playingTeams = 0; int playingTeams = 0;
// Iterate through every existing team. // Iterate through every existing team.
for(int i = 0; i < CommonValues.totalTeams; i++) for(int i = 0; i < Cache.totalTeams; i++)
{ {
// Int to store the players number for each team. // Int to store the players number for each team.
int playersNumber = 0; int playersNumber = 0;
// Iterate through every player and... // Iterate through every player and...
for(String s : CommonValues.playerTeam.keySet()) for(String s : Cache.playerTeam.keySet())
{ {
//if his team is the current checked one... //if his team is the current checked one...
if(CommonValues.playerTeam.get(s) == i) if(Cache.playerTeam.get(s) == i)
{ {
//increase the playersNumber by 1. //increase the playersNumber by 1.
playersNumber++; playersNumber++;
@ -36,21 +36,21 @@ public class UhcUtils {
} }
// Finally, put the team number and his player count in the playersPerTeam HashMap. // Finally, put the team number and his player count in the playersPerTeam HashMap.
CommonValues.playersPerTeam.put(i, playersNumber); Cache.playersPerTeam.put(i, playersNumber);
// If there is at least 1 player in this team, then count this as an "alive team". // If there is at least 1 player in this team, then count this as an "alive team".
if(playersNumber != 0) playingTeams++; if(playersNumber != 0) playingTeams++;
} }
// Return the number of alive teams. // Return the number of alive teams.
CommonValues.playingTeams = playingTeams; Cache.playingTeams = playingTeams;
} }
public static void giveTeamsSelectorItem(Player player) public static void giveTeamsSelectorItem(Player player)
{ {
player.getInventory().clear(); player.getInventory().clear();
player.getInventory().setItem(4, CommonValues.teamsItem); player.getInventory().setItem(4, Cache.teamsItem);
} }
public static void spawnFirework(Location location, long detonateDelay) { public static void spawnFirework(Location location, long detonateDelay) {
@ -70,7 +70,7 @@ public class UhcUtils {
public static void tpSpawnAndGiveItem(Player player) public static void tpSpawnAndGiveItem(Player player)
{ {
player.teleport(CommonValues.spawn); player.teleport(Cache.spawn);
// Clear the player's inventory and give hims the Teams selector item. // Clear the player's inventory and give hims the Teams selector item.
UhcUtils.giveTeamsSelectorItem(player); UhcUtils.giveTeamsSelectorItem(player);

View File

@ -2,7 +2,7 @@ package net.mindoverflow.network.uhccore.utils.configuration;
import net.mindoverflow.network.uhccore.UhcCore; import net.mindoverflow.network.uhccore.UhcCore;
import net.mindoverflow.network.uhccore.listeners.TeamsSelectorGUI; import net.mindoverflow.network.uhccore.listeners.TeamsSelectorGUI;
import net.mindoverflow.network.uhccore.utils.CommonValues; import net.mindoverflow.network.uhccore.utils.Cache;
import net.mindoverflow.network.uhccore.utils.Debugger; import net.mindoverflow.network.uhccore.utils.Debugger;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -59,46 +59,46 @@ public class FileUtils
FileType.CONFIG_YAML.yaml = YamlConfiguration.loadConfiguration(FileType.CONFIG_YAML.file); FileType.CONFIG_YAML.yaml = YamlConfiguration.loadConfiguration(FileType.CONFIG_YAML.file);
FileType.LANG_YAML.yaml = YamlConfiguration.loadConfiguration(FileType.LANG_YAML.file); FileType.LANG_YAML.yaml = YamlConfiguration.loadConfiguration(FileType.LANG_YAML.file);
CommonValues.playerTeam.clear(); Cache.playerTeam.clear();
CommonValues.playersPerTeam.clear(); Cache.playersPerTeam.clear();
CommonValues.teamNames.clear(); Cache.teamNames.clear();
CommonValues.teamItemsMaterials.clear(); Cache.teamItemsMaterials.clear();
CommonValues.spawn = null; Cache.spawn = null;
CommonValues.fireworksLocations.clear(); Cache.fireworksLocations.clear();
CommonValues.playingTeams = 0; Cache.playingTeams = 0;
YamlConfiguration config = FileType.CONFIG_YAML.yaml; YamlConfiguration config = FileType.CONFIG_YAML.yaml;
CommonValues.teamNames = config.getStringList(ConfigEntries.TEAMS_NAMES.path); Cache.teamNames = config.getStringList(ConfigEntries.TEAMS_NAMES.path);
for(String matName : config.getStringList(ConfigEntries.TEAMS_ITEMS.path)) for(String matName : config.getStringList(ConfigEntries.TEAMS_ITEMS.path))
{ {
CommonValues.teamItemsMaterials.add(Material.valueOf(matName)); Cache.teamItemsMaterials.add(Material.valueOf(matName));
} }
CommonValues.uhcWorlds = config.getStringList(ConfigEntries.UHC_WORLDS.path); Cache.uhcWorlds = config.getStringList(ConfigEntries.UHC_WORLDS.path);
CommonValues.lobbyWorlds = config.getStringList(ConfigEntries.LOBBY_WORLDS.path); Cache.lobbyWorlds = config.getStringList(ConfigEntries.LOBBY_WORLDS.path);
CommonValues.friendlyFire = config.getBoolean(ConfigEntries.FRIENDLY_FIRE.path); Cache.friendlyFire = config.getBoolean(ConfigEntries.FRIENDLY_FIRE.path);
CommonValues.teamsItem = new ItemStack(Material.NETHER_STAR); Cache.teamsItem = new ItemStack(Material.NETHER_STAR);
ItemMeta im = CommonValues.teamsItem.getItemMeta(); ItemMeta im = Cache.teamsItem.getItemMeta();
im.setDisplayName("§eTeam"); im.setDisplayName("§eTeam");
CommonValues.teamsItem.setItemMeta(im); Cache.teamsItem.setItemMeta(im);
CommonValues.quitTeamItem = new ItemStack(Material.BARRIER); Cache.quitTeamItem = new ItemStack(Material.BARRIER);
im = CommonValues.quitTeamItem.getItemMeta(); im = Cache.quitTeamItem.getItemMeta();
im.setDisplayName("§cEsci dal Team"); im.setDisplayName("§cEsci dal Team");
CommonValues.quitTeamItem.setItemMeta(im); Cache.quitTeamItem.setItemMeta(im);
CommonValues.totalTeams = config.getInt(ConfigEntries.TEAMS_NUMBER.path); Cache.totalTeams = config.getInt(ConfigEntries.TEAMS_NUMBER.path);
CommonValues.teamsSelectorGUI = new TeamsSelectorGUI(); Cache.teamsSelectorGUI = new TeamsSelectorGUI();
CommonValues.teamsSelectorGUI.initializeInv(); Cache.teamsSelectorGUI.initializeInv();
CommonValues.borderX = config.getInt(ConfigEntries.BORDER_CENTER_X.path); Cache.borderX = config.getInt(ConfigEntries.BORDER_CENTER_X.path);
CommonValues.borderZ = config.getInt(ConfigEntries.BORDER_CENTER_Z.path); Cache.borderZ = config.getInt(ConfigEntries.BORDER_CENTER_Z.path);
CommonValues.borderSize = config.getInt(ConfigEntries.BORDER_SIZE.path); Cache.borderSize = config.getInt(ConfigEntries.BORDER_SIZE.path);
String spawnWorldName = config.getString(ConfigEntries.SPAWN_WORLD.path); String spawnWorldName = config.getString(ConfigEntries.SPAWN_WORLD.path);
if(spawnWorldName != null) if(spawnWorldName != null)
@ -112,7 +112,7 @@ public class FileUtils
double z = config.getDouble(ConfigEntries.SPAWN_Z.path); double z = config.getDouble(ConfigEntries.SPAWN_Z.path);
double yaw = config.getDouble(ConfigEntries.SPAWN_YAW.path); double yaw = config.getDouble(ConfigEntries.SPAWN_YAW.path);
double pitch = config.getDouble(ConfigEntries.SPAWN_PITCH.path); double pitch = config.getDouble(ConfigEntries.SPAWN_PITCH.path);
CommonValues.spawn = new Location(spawnWorld, x, y, z, (float) yaw, (float) pitch); Cache.spawn = new Location(spawnWorld, x, y, z, (float) yaw, (float) pitch);
} }
} }
@ -124,7 +124,7 @@ public class FileUtils
double y = config.getDouble(currentPath + ".y"); double y = config.getDouble(currentPath + ".y");
double z = config.getDouble(currentPath + ".z"); double z = config.getDouble(currentPath + ".z");
CommonValues.fireworksLocations.add(new Location(plugin.getServer().getWorld(world), x, y, z)); Cache.fireworksLocations.add(new Location(plugin.getServer().getWorld(world), x, y, z));
} }
} }

View File

@ -1,5 +1,5 @@
name: UHC-Core name: UHC-Core
version: BUILD_NUMBER version: 0.0.136
author: mind_overflow author: mind_overflow
api-version: '1.15' api-version: '1.15'
main: net.mindoverflow.network.uhccore.UhcCore main: net.mindoverflow.network.uhccore.UhcCore