Djomobil

Rush Plugin | Main Class

Mar 14th, 2017
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.62 KB | None | 0 0
  1. package fr.jojofumelebedo.rush;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import java.util.Map;
  7.  
  8. import org.bukkit.Bukkit;
  9. import org.bukkit.Chunk;
  10. import org.bukkit.Location;
  11. import org.bukkit.configuration.ConfigurationSection;
  12. import org.bukkit.entity.Entity;
  13. import org.bukkit.entity.Player;
  14. import org.bukkit.plugin.java.JavaPlugin;
  15.  
  16. import fr.jojofumelebedo.rush.team.TeamManager;
  17. import fr.jojofumelebedo.rush.team.Teams;
  18. import fr.jojofumelebedo.rush.villager.VillagerListener;
  19.  
  20. public class Rush extends JavaPlugin {
  21.  
  22.     private RushGame current;
  23.     public RushTitle title = new RushTitle();
  24.     public List<Teams> teams = new ArrayList<>();
  25.     public Map<Player, ScoreboardSign> board = new HashMap<>();
  26.     public int timer;
  27.  
  28.     @Override
  29.     public void onEnable() {
  30.         timer = 15;
  31.  
  32.         // on set le status de jeu en ...
  33.         current = RushGame.WAITING;
  34.         // on initialise une classe contenant les listeners
  35.         getServer().getPluginManager().registerEvents(new RushListener(this), this);
  36.  
  37.         // on sauvegarde la config de base
  38.         saveDefaultConfig();
  39.  
  40.         // TEAMS
  41.  
  42.         // on recupere la section "teams" de la config.yml
  43.         ConfigurationSection section = getConfig().getConfigurationSection("teams");
  44.  
  45.         // on recup l'ensemble des equipes defini par la section au dessu dans
  46.         // la config
  47.         for (String team : section.getKeys(false)) {
  48.  
  49.             // on recupere les sous partie grace a un chemin d'acces
  50.             String name = section.getString(team + ".name");
  51.             String color = section.getString(team + ".color").replace("&", "§");
  52.             String spawn = section.getString(team + ".spawn");
  53.  
  54.             byte data = (byte) section.getInt(team + ".data");
  55.  
  56.             // on cree une nouvelle team grace au contructeur de la classe Teams
  57.             teams.add(new Teams(name, color, data, getParseLoc(spawn)));
  58.         }
  59.  
  60.         // VILLAGERS
  61.  
  62.         // meme procede que pour les teams
  63.         ConfigurationSection villagers = getConfig().getConfigurationSection("villagers");
  64.         for (String v : villagers.getKeys(false)) {
  65.            
  66.             //recup de nom + des loc des villagers + on les fait spawn via la classe VillagerListener
  67.             String name = villagers.getString(v + ".name").replace("&", "§");
  68.             for(String loc : villagers.getStringList(v + ".locations")){
  69.                 VillagerListener vil = new VillagerListener(this);
  70.                 vil.spawnVillager(name, getParseLoc(loc), villagers.getStringList(v + ".content"));
  71.             }
  72.  
  73.         }
  74.  
  75.         System.out.println(teams.size() + " : teams ont ete charge");
  76.  
  77.         super.onEnable();
  78.     }
  79.  
  80.     @Override
  81.     public void onDisable() {
  82.  
  83.         // methode pour remove toutes les entite vivante lorsque le plugin
  84.         // s'eteind
  85.         for (Chunk chunk : Bukkit.getWorld(getConfig().getString("gameworld")).getLoadedChunks()) {
  86.             for (Entity entity : chunk.getEntities()) {
  87.                 if (!(entity instanceof Player)) {
  88.                     entity.remove();
  89.                 }
  90.             }
  91.         }
  92.         super.onDisable();
  93.     }
  94.    
  95.  
  96.     private Location getParseLoc(String spawn) {
  97.         // on separe la string grace a la ","
  98.         String[] spawns = spawn.split(",");
  99.  
  100.         // on recup les sous partie sous forme de double
  101.         double x = Double.valueOf(spawns[0]);
  102.         double y = Double.valueOf(spawns[1]);
  103.         double z = Double.valueOf(spawns[2]);
  104.         float yaw = 0;
  105.         float pitch = 0;
  106.  
  107.         // on check si la loc contien le Yaw et le Pitch
  108.         if (spawns.length >= 5) {
  109.             yaw = Float.valueOf(spawns[3]);
  110.             pitch = Float.valueOf(spawns[4]);
  111.         }
  112.        
  113.         String world = getConfig().getString("gameworld");
  114.        
  115.         return new Location(Bukkit.getWorld(world), x, y, z, yaw, pitch);
  116.     }
  117.    
  118.    
  119.    
  120.  
  121.     public void setState(RushGame state) {
  122.  
  123.         current = state;
  124.     }
  125.  
  126.     public boolean isState(RushGame state) {
  127.  
  128.         return current == state;
  129.  
  130.     }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment