Advertisement
Vinetos

CREER UN PLUGIN BUKKIT #30 - Les zones - Main.java

Apr 26th, 2015
921
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. public class Main extends JavaPlugin implements Listener{
  2.  
  3. private static Cuboide Zone1;
  4. private static Cuboide Zone2;
  5.  
  6. private Location loadLocation(String chemin){
  7. double x = getConfig().getDouble(chemin + ".x");
  8. double y = getConfig().getDouble(chemin + ".y");
  9. double z = getConfig().getDouble(chemin + ".z");
  10. World w = Bukkit.getWorld(getConfig().getString(chemin+".w"));
  11. return new Location(w,x,y,z);
  12. }
  13.  
  14. private void saveLocation(String chemin, Location l){
  15. getConfig().set(chemin + ".x", l.getX());
  16. getConfig().set(chemin + ".y", l.getY());
  17. getConfig().set(chemin + ".z", l.getZ());
  18. getConfig().set(chemin + ".w", l.getWorld().getName());
  19. saveConfig();
  20. }
  21.  
  22. private Boolean hasMoved(Location l1, Location l2){
  23. if(l1 != l2){
  24. return true;
  25. }else{
  26. return false;
  27. }
  28.  
  29. }
  30.  
  31. @EventHandler
  32. public void onMove(PlayerMoveEvent e){
  33. Player p = e.getPlayer();
  34. if(Zone1.isInCube(p)){
  35. p.sendMessage("§6Tu es dans la zone §4n°1§6 !");
  36. }else if(Zone2.isInCube(p)){
  37. p.sendMessage("§6Tu es dans la zone §4n°2§6 !");
  38. }
  39. }
  40.  
  41. @Override
  42. public void onEnable() {
  43. saveConfig();
  44. getServer().getPluginManager().registerEvents(this, this);
  45. if(getConfig().getBoolean("location")){
  46. Zone1 = new Cuboide(loadLocation("zone1.l1"), loadLocation("zone1.l2"));
  47. Zone2 = new Cuboide(loadLocation("zone2.l1"), loadLocation("zone2.l2"));
  48. }
  49.  
  50. }
  51.  
  52. @Override
  53. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
  54.  
  55. Player p = (Player) sender;
  56. if(cmd.getName().equalsIgnoreCase("setcube")){
  57. if(args.length == 2){
  58. if((args[1].equalsIgnoreCase("1") || args[1].equalsIgnoreCase("2"))){
  59. saveLocation(args[0]+".l"+args[1], p.getLocation());
  60. getConfig().set("location", true);
  61. saveConfig();
  62. p.sendMessage("§2La position §c"+args[1]+"§2 pour la zone §c"+args[0]+"§2 a été définis !");
  63. }
  64.  
  65. }
  66. }
  67. return true;
  68. }
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement