/EssentialsProtect/src/net/ess3/protect/EssentialsProtect.java

https://github.com/mbax/Essentials · Java · 157 lines · 101 code · 18 blank · 38 comment · 7 complexity · 465e30e161cc0eb37538bc1690a20364 MD5 · raw file

  1. package net.ess3.protect;
  2. import net.ess3.protect.data.IProtectedBlock;
  3. import java.util.logging.Filter;
  4. import java.util.logging.Level;
  5. import java.util.logging.LogRecord;
  6. import java.util.logging.Logger;
  7. import org.bukkit.entity.Player;
  8. import org.bukkit.plugin.Plugin;
  9. import org.bukkit.plugin.PluginManager;
  10. import org.bukkit.plugin.java.JavaPlugin;
  11. public class EssentialsProtect extends JavaPlugin implements IProtect
  12. {
  13. private static final Logger LOGGER = Logger.getLogger("Minecraft");
  14. private static com.mchange.v2.log.MLogger C3P0logger;
  15. //private final transient Map<ProtectConfig, Boolean> settingsBoolean = new EnumMap<ProtectConfig, Boolean>(ProtectConfig.class);
  16. //private final transient Map<ProtectConfig, String> settingsString = new EnumMap<ProtectConfig, String>(ProtectConfig.class);
  17. //private final transient Map<ProtectConfig, List<Integer>> settingsList = new EnumMap<ProtectConfig, List<Integer>>(ProtectConfig.class);
  18. private transient IProtectedBlock storage = null;
  19. private transient EssentialsConnect ess = null;
  20. private transient ProtectHolder settings = null;
  21. private transient com.mchange.v2.c3p0.management.ActiveManagementCoordinator temp; // leave this here for maven
  22. @Override
  23. public void onLoad()
  24. {
  25. C3P0logger = com.mchange.v2.log.MLog.getLogger(com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.class);
  26. C3P0logger.setFilter(new Filter()
  27. {
  28. public boolean isLoggable(final LogRecord lr)
  29. {
  30. return lr.getLevel() != Level.INFO;
  31. }
  32. });
  33. }
  34. @Override
  35. public void onEnable()
  36. {
  37. final PluginManager pm = this.getServer().getPluginManager();
  38. final Plugin essPlugin = pm.getPlugin("Essentials-3");
  39. if (essPlugin == null || !essPlugin.isEnabled())
  40. {
  41. enableEmergencyMode(pm);
  42. return;
  43. }
  44. ess = new EssentialsConnect(essPlugin, this);
  45. final EssentialsProtectPlayerListener playerListener = new EssentialsProtectPlayerListener(this);
  46. pm.registerEvents(playerListener, this);
  47. final EssentialsProtectBlockListener blockListener = new EssentialsProtectBlockListener(this);
  48. pm.registerEvents(blockListener, this);
  49. final EssentialsProtectEntityListener entityListener = new EssentialsProtectEntityListener(this);
  50. pm.registerEvents(entityListener, this);
  51. final EssentialsProtectWeatherListener weatherListener = new EssentialsProtectWeatherListener(this);
  52. pm.registerEvents(weatherListener, this);
  53. }
  54. private void enableEmergencyMode(final PluginManager pm)
  55. {
  56. final EmergencyListener emListener = new EmergencyListener();
  57. pm.registerEvents(emListener, this);
  58. for (Player player : getServer().getOnlinePlayers())
  59. {
  60. player.sendMessage("Essentials Protect is in emergency mode. Check your log for errors.");
  61. }
  62. LOGGER.log(Level.SEVERE, "Essentials not installed or failed to load. Essenials Protect is in emergency mode now.");
  63. }
  64. /*@Override
  65. public boolean checkProtectionItems(final ProtectConfig list, final int id)
  66. {
  67. final List<Integer> itemList = settingsList.get(list);
  68. return itemList != null && !itemList.isEmpty() && itemList.contains(id);
  69. }*/
  70. @Override
  71. public IProtectedBlock getStorage()
  72. {
  73. return storage;
  74. }
  75. @Override
  76. public void setStorage(final IProtectedBlock pb)
  77. {
  78. storage = pb;
  79. }
  80. @Override
  81. public EssentialsConnect getEssentialsConnect()
  82. {
  83. return ess;
  84. }
  85. /*public Map<ProtectConfig, Boolean> getSettingsBoolean()
  86. {
  87. return settingsBoolean;
  88. }
  89. public Map<ProtectConfig, String> getSettingsString()
  90. {
  91. return settingsString;
  92. }
  93. public Map<ProtectConfig, List<Integer>> getSettingsList()
  94. {
  95. return settingsList;
  96. }
  97. @Override
  98. public boolean getSettingBool(final ProtectConfig protectConfig)
  99. {
  100. final Boolean bool = settingsBoolean.get(protectConfig);
  101. return bool == null ? protectConfig.getDefaultValueBoolean() : bool;
  102. }
  103. @Override
  104. public String getSettingString(final ProtectConfig protectConfig)
  105. {
  106. final String str = settingsString.get(protectConfig);
  107. return str == null ? protectConfig.getDefaultValueString() : str;
  108. }*/
  109. @Override
  110. public void onDisable()
  111. {
  112. if (storage != null)
  113. {
  114. storage.onPluginDeactivation();
  115. }
  116. // Sleep for a second to allow the database to close.
  117. try
  118. {
  119. Thread.sleep(1000);
  120. }
  121. catch (InterruptedException ex)
  122. {
  123. }
  124. }
  125. @Override
  126. public ProtectHolder getSettings()
  127. {
  128. return settings;
  129. }
  130. @Override
  131. public void setSettings(final ProtectHolder settings)
  132. {
  133. this.settings = settings;
  134. }
  135. }