PageRenderTime 171ms CodeModel.GetById 45ms RepoModel.GetById 0ms app.codeStats 0ms

/src/me/rigi/acceptrules/AcceptRulesMain.java

https://github.com/rigor789/AcceptRules
Java | 126 lines | 114 code | 10 blank | 2 comment | 4 complexity | 6ec89eb458abb8745fa2f5bca623ffe6 MD5 | raw file
  1. package me.rigi.acceptrules;
  2. import java.util.ArrayList;
  3. import java.util.logging.Logger;
  4. import org.bukkit.Bukkit;
  5. import org.bukkit.Location;
  6. import org.bukkit.World;
  7. import org.bukkit.configuration.file.FileConfiguration;
  8. import org.bukkit.entity.Player;
  9. import org.bukkit.plugin.PluginManager;
  10. import org.bukkit.plugin.java.JavaPlugin;
  11. public class AcceptRulesMain extends JavaPlugin {
  12. Logger Log = Logger.getLogger("Minecraft");
  13. public static AcceptRulesMain plugin;
  14. public static ArrayList<String> players = new ArrayList<String>();
  15. public static ArrayList<String> rules = new ArrayList<String>();
  16. public static ArrayList<Player> readed = new ArrayList<Player>();
  17. public static String AcceptedMsg,AcceptedAllreadyMsg,InformMsg,MustReadRules,CantBuildMsg,TpWorld,SpawnWorld,RulesCmd;
  18. public static boolean TpAfterAccept,AllowBuild,Notify,Inform,AllowMove,TpOnJoin, BlockCmds, RulesMngr;
  19. public static Location TpPosition;
  20. public static Location SpawnPosition;
  21. public static FileConfiguration config;
  22. //@Override
  23. public void onDisable() {
  24. Log.info("[AcceptRules] AcceptRules plugin succesfully disabled!");
  25. }
  26. //@Override
  27. public void onEnable() {
  28. PluginManager pm = getServer().getPluginManager();
  29. AcceptRulesPreferences acceptrulespreferences = new AcceptRulesPreferences();
  30. acceptrulespreferences.createDir();
  31. getConfig().options().copyDefaults(true);
  32. saveConfig();
  33. config = getConfig();
  34. AcceptedMsg = config.getString("AcceptedMsg", "You have succesfully accepted the rules! Have fun!");
  35. AcceptedAllreadyMsg = config.getString("AcceptedAllreadyMsg", "You have allready accepted the rules!");
  36. CantBuildMsg = config.getString("CantBuildMsg", "You must accept rules to build!");
  37. MustReadRules = config.getString("MustReadRules", "You must read the rules in order to accept them!");
  38. InformMsg = config.getString("InformMsg","You have to accept the rules! Use /rules and then /acceptrules!");
  39. RulesCmd = config.getString("RulesCmd","/rules");
  40. TpAfterAccept = config.getBoolean("TpAfterAccept", false);
  41. TpOnJoin = config.getBoolean("TpOnJoin", false);
  42. AllowBuild = config.getBoolean("AllowBuildBeforeAccept", false);
  43. AllowMove = config.getBoolean("AllowMoveBeforeAccept", true);
  44. Notify = config.getBoolean("NotifyOPs", true);
  45. Inform = config.getBoolean("InformUser", true);
  46. BlockCmds = config.getBoolean("BlockCommandsBeforeAccept", true);
  47. RulesMngr = config.getBoolean("BuiltInRulesManager", true);
  48. TpWorld = config.getString("TpWorld", "world");
  49. SpawnWorld = config.getString("SpawnWorld", "world");
  50. Double PosX = config.getDouble("TpPositionX", 0);
  51. Double PosY = config.getDouble("TpPositionY", 0);
  52. Double PosZ = config.getDouble("TpPositionZ", 0);
  53. float Pitch =(float) config.getDouble("TpPositionPitch", 0);
  54. float Yaw = (float) config.getDouble("TpPositionYaw", 0);
  55. World world = Bukkit.getServer().getWorld(TpWorld);
  56. Location location = new Location(world, PosX, PosY, PosZ, Yaw, Pitch);
  57. TpPosition = location;
  58. Double SPosX = config.getDouble("SpawnPositionX", 0);
  59. Double SPosY = config.getDouble("SpawnPositionY", 0);
  60. Double SPosZ = config.getDouble("SpawnPositionZ", 0);
  61. float SPitch = (float) config.getDouble("SpawnPositionPitch", 0);
  62. float SYaw = (float) config.getDouble("SpawnPositionYaw", 0);
  63. World Sworld = Bukkit.getServer().getWorld(SpawnWorld);
  64. Location Slocation = new Location(Sworld, SPosX, SPosY, SPosZ, SYaw, SPitch);
  65. SpawnPosition = Slocation;
  66. saveConfig();
  67. AcceptRulesPreferences.UserReader();
  68. AcceptRulesPreferences.RulesReader();
  69. pm.registerEvents(new AcceptRulesListener(), this);
  70. getCommand("acceptrules").setExecutor(new acceptrulesCmdExecutor(this));
  71. Log.info("[AcceptRules] AcceptRules plugin succesfully enabled!");
  72. }
  73. public void savePosToConfig(String type, String world, double x, double y, double z, double pitch, double yaw) {
  74. if(type.equalsIgnoreCase("tp")){
  75. config.set("TpWorld", world);
  76. config.set("TpPositionX", x);
  77. config.set("TpPositionY", y);
  78. config.set("TpPositionZ", z);
  79. config.set("TpPositionPitch", pitch);
  80. config.set("TpPositionYaw", yaw);
  81. }
  82. if(type.equalsIgnoreCase("spawn")){
  83. config.set("SpawnWorld", world);
  84. config.set("SpawnPositionX", x);
  85. config.set("SpawnPositionY", y);
  86. config.set("SpawnPositionZ", z);
  87. config.set("SpawnPositionPitch", pitch);
  88. config.set("SpawnPositionYaw", yaw);
  89. }
  90. saveConfig();
  91. reloadConfig();
  92. if(type.equalsIgnoreCase("tp")){
  93. TpWorld = config.getString("TpWorld", "world");
  94. Double PosX = config.getDouble("TpPositionX", 0);
  95. Double PosY = config.getDouble("TpPositionY", 0);
  96. Double PosZ = config.getDouble("TpPositionZ", 0);
  97. float Pitch =(float) config.getDouble("TpPositionPitch", 0);
  98. float Yaw = (float) config.getDouble("TpPositionYaw", 0);
  99. World worldd = Bukkit.getServer().getWorld(TpWorld);
  100. Location location = new Location(worldd, PosX, PosY, PosZ, Yaw, Pitch);
  101. TpPosition = location;
  102. }
  103. if(type.equalsIgnoreCase("spawn")){
  104. TpWorld = config.getString("SpawnWorld", "world");
  105. Double PosX = config.getDouble("SpawnPositionX", 0);
  106. Double PosY = config.getDouble("SpawnPositionY", 0);
  107. Double PosZ = config.getDouble("SpawnPositionZ", 0);
  108. float Pitch = (float) config.getDouble("SpawnPositionPitch", 0);
  109. float Yaw = (float) config.getDouble("SpawnPositionYaw", 0);
  110. config.set("SpawnPositionYaw", yaw);
  111. World worldd = Bukkit.getServer().getWorld(TpWorld);
  112. Location location = new Location(worldd, PosX, PosY, PosZ, Yaw, Pitch);
  113. SpawnPosition = location;
  114. }
  115. }
  116. }