Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.jojofumelebedo.rush;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import org.bukkit.Bukkit;
- import org.bukkit.Chunk;
- import org.bukkit.Location;
- import org.bukkit.configuration.ConfigurationSection;
- import org.bukkit.entity.Entity;
- import org.bukkit.entity.Player;
- import org.bukkit.plugin.java.JavaPlugin;
- import fr.jojofumelebedo.rush.team.TeamManager;
- import fr.jojofumelebedo.rush.team.Teams;
- import fr.jojofumelebedo.rush.villager.VillagerListener;
- public class Rush extends JavaPlugin {
- private RushGame current;
- public RushTitle title = new RushTitle();
- public List<Teams> teams = new ArrayList<>();
- public Map<Player, ScoreboardSign> board = new HashMap<>();
- public int timer;
- @Override
- public void onEnable() {
- timer = 15;
- // on set le status de jeu en ...
- current = RushGame.WAITING;
- // on initialise une classe contenant les listeners
- getServer().getPluginManager().registerEvents(new RushListener(this), this);
- // on sauvegarde la config de base
- saveDefaultConfig();
- // TEAMS
- // on recupere la section "teams" de la config.yml
- ConfigurationSection section = getConfig().getConfigurationSection("teams");
- // on recup l'ensemble des equipes defini par la section au dessu dans
- // la config
- for (String team : section.getKeys(false)) {
- // on recupere les sous partie grace a un chemin d'acces
- String name = section.getString(team + ".name");
- String color = section.getString(team + ".color").replace("&", "§");
- String spawn = section.getString(team + ".spawn");
- byte data = (byte) section.getInt(team + ".data");
- // on cree une nouvelle team grace au contructeur de la classe Teams
- teams.add(new Teams(name, color, data, getParseLoc(spawn)));
- }
- // VILLAGERS
- // meme procede que pour les teams
- ConfigurationSection villagers = getConfig().getConfigurationSection("villagers");
- for (String v : villagers.getKeys(false)) {
- //recup de nom + des loc des villagers + on les fait spawn via la classe VillagerListener
- String name = villagers.getString(v + ".name").replace("&", "§");
- for(String loc : villagers.getStringList(v + ".locations")){
- VillagerListener vil = new VillagerListener(this);
- vil.spawnVillager(name, getParseLoc(loc), villagers.getStringList(v + ".content"));
- }
- }
- System.out.println(teams.size() + " : teams ont ete charge");
- super.onEnable();
- }
- @Override
- public void onDisable() {
- // methode pour remove toutes les entite vivante lorsque le plugin
- // s'eteind
- for (Chunk chunk : Bukkit.getWorld(getConfig().getString("gameworld")).getLoadedChunks()) {
- for (Entity entity : chunk.getEntities()) {
- if (!(entity instanceof Player)) {
- entity.remove();
- }
- }
- }
- super.onDisable();
- }
- private Location getParseLoc(String spawn) {
- // on separe la string grace a la ","
- String[] spawns = spawn.split(",");
- // on recup les sous partie sous forme de double
- double x = Double.valueOf(spawns[0]);
- double y = Double.valueOf(spawns[1]);
- double z = Double.valueOf(spawns[2]);
- float yaw = 0;
- float pitch = 0;
- // on check si la loc contien le Yaw et le Pitch
- if (spawns.length >= 5) {
- yaw = Float.valueOf(spawns[3]);
- pitch = Float.valueOf(spawns[4]);
- }
- String world = getConfig().getString("gameworld");
- return new Location(Bukkit.getWorld(world), x, y, z, yaw, pitch);
- }
- public void setState(RushGame state) {
- current = state;
- }
- public boolean isState(RushGame state) {
- return current == state;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment