Created
November 4, 2021 15:31
-
-
Save SzczurekYT/5a5d24a45803f474af74ab6bc478841e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package me.szczurekyt.magnoliechowany; | |
import org.bukkit.Bukkit; | |
import org.bukkit.entity.Player; | |
import org.bukkit.plugin.java.JavaPlugin; | |
import org.bukkit.scoreboard.Scoreboard; | |
import org.bukkit.scoreboard.Team; | |
import java.util.*; | |
public final class Main extends JavaPlugin { | |
public Game game; // Currently, running game | |
public Map<String, GameMap> maps = new HashMap<>(); | |
public Map<Player, Game> gameCreation = new HashMap<>(); | |
public List<Player> waitingForInput = new ArrayList<>(); | |
public Scoreboard scoreboard; | |
@Override | |
public void onEnable() { | |
// Plugin startup logic | |
// Register commands and events | |
this.getCommand("chowany").setExecutor(new ChowanyCMD(this)); | |
this.getServer().getPluginManager().registerEvents(new DeathListener(this), this); | |
this.getServer().getPluginManager().registerEvents(new InventoryListener(this), this); | |
this.getServer().getPluginManager().registerEvents(new ChatListener(this), this); | |
// create scoreboard | |
Bukkit.getScoreboardManager().getMainScoreboard(); | |
// Create no tag team | |
scoreboard.registerNewTeam("NoTag").setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER); | |
// Save default config | |
this.saveDefaultConfig(); | |
// If there is data to load than load it | |
if (this.getConfig().contains("maps")) { | |
loadMaps(); | |
} | |
// Remove old data | |
this.getConfig().set("maps", null); | |
this.saveConfig(); | |
} | |
@Override | |
public void onDisable() { | |
// Plugin shutdown logic | |
if (!(maps.isEmpty())) { | |
// There are maps to save | |
saveMaps(); | |
} | |
} | |
public void saveMaps() { | |
for (Map.Entry<String, GameMap> map: this.maps.entrySet()) { | |
this.getConfig().set("maps." + map.getKey() + ".name", map.getValue().name); | |
this.getConfig().set("maps." + map.getKey() + ".icon", map.getValue().icon); | |
this.getConfig().set("maps." + map.getKey() + ".lobby", map.getValue().lobbySpawn); | |
this.getConfig().set("maps." + map.getKey() + ".spectator", map.getValue().spectatorSpawn); | |
this.getConfig().set("maps." + map.getKey() + ".seeker", map.getValue().seekerSpawn); | |
this.getConfig().set("maps." + map.getKey() + ".start", map.getValue().startSpawn); | |
} | |
this.saveConfig(); | |
} | |
public void loadMaps() { | |
// Used to load all maps from config | |
for (String key: this.getConfig().getConfigurationSection("maps").getKeys(false)) { | |
// Iterate over all saved maps | |
// Recreate the GameMap | |
String name = this.getConfig().getString("maps." + key + ".name"); | |
GameMap map = new GameMap(name); | |
map.icon = this.getConfig().getItemStack("maps." + key + ".icon"); | |
map.lobbySpawn = this.getConfig().getLocation("maps." + key + ".lobby"); | |
map.spectatorSpawn = this.getConfig().getLocation("maps." + key + ".spectator"); | |
map.seekerSpawn = this.getConfig().getLocation("maps." + key + ".seeker"); | |
map.startSpawn = this.getConfig().getLocation("maps." + key + ".start"); | |
// Put map in the hashmap | |
this.maps.put(name, map); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment