2011-03-30 04:03:21 +00:00
|
|
|
package com.earth2me.essentials.protect;
|
|
|
|
|
|
|
|
import com.earth2me.essentials.Essentials;
|
2011-05-11 22:30:34 +00:00
|
|
|
import com.earth2me.essentials.IConf;
|
2011-06-02 23:09:59 +00:00
|
|
|
import com.earth2me.essentials.IEssentials;
|
2011-03-30 04:03:21 +00:00
|
|
|
import com.earth2me.essentials.User;
|
2011-05-10 19:57:59 +00:00
|
|
|
import com.earth2me.essentials.Util;
|
2011-06-02 23:09:59 +00:00
|
|
|
import com.earth2me.essentials.protect.data.IProtectedBlock;
|
|
|
|
import com.earth2me.essentials.protect.data.ProtectedBlockMemory;
|
|
|
|
import com.earth2me.essentials.protect.data.ProtectedBlockMySQL;
|
|
|
|
import com.earth2me.essentials.protect.data.ProtectedBlockSQLite;
|
|
|
|
import java.beans.PropertyVetoException;
|
2011-06-03 20:56:29 +00:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
2011-03-30 04:03:21 +00:00
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.Event.Priority;
|
|
|
|
import org.bukkit.event.Event.Type;
|
|
|
|
import org.bukkit.plugin.PluginManager;
|
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
|
|
|
|
|
2011-05-11 22:30:34 +00:00
|
|
|
public class EssentialsProtect extends JavaPlugin implements IConf
|
2011-03-30 04:03:21 +00:00
|
|
|
{
|
|
|
|
private EssentialsProtectBlockListener blockListener = null;
|
|
|
|
private EssentialsProtectPlayerListener playerListener = null;
|
|
|
|
private EssentialsProtectEntityListener entityListener = null;
|
2011-04-27 01:33:45 +00:00
|
|
|
private EssentialsProtectWeatherListener weatherListener = null;
|
2011-03-30 04:03:21 +00:00
|
|
|
public static final String AUTHORS = Essentials.AUTHORS;
|
|
|
|
private static final Logger logger = Logger.getLogger("Minecraft");
|
2011-06-03 20:56:29 +00:00
|
|
|
public static Map<String, Boolean> genSettings = null;
|
|
|
|
public static Map<String, String> dataSettings = null;
|
|
|
|
public static Map<String, Boolean> guardSettings = null;
|
|
|
|
public static Map<String, Boolean> playerSettings = null;
|
|
|
|
public static List<Integer> usageList = null;
|
|
|
|
public static List<Integer> blackListPlace = null;
|
|
|
|
public static List<Integer> breakBlackList = null;
|
|
|
|
public static List<Integer> onPlaceAlert = null;
|
|
|
|
public static List<Integer> onUseAlert = null;
|
|
|
|
public static List<Integer> onBreakAlert = null;
|
2011-06-02 23:09:59 +00:00
|
|
|
private IProtectedBlock storage = null;
|
|
|
|
IEssentials ess = null;
|
|
|
|
private static EssentialsProtect instance = null;
|
2011-03-30 04:03:21 +00:00
|
|
|
|
|
|
|
public EssentialsProtect()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onEnable()
|
|
|
|
{
|
2011-06-03 14:23:55 +00:00
|
|
|
ess = Essentials.getStatic();
|
|
|
|
ess.getDependancyChecker().checkProtectDependancies();
|
2011-06-03 21:03:08 +00:00
|
|
|
PluginManager pm = this.getServer().getPluginManager();
|
2011-03-30 04:03:21 +00:00
|
|
|
playerListener = new EssentialsProtectPlayerListener(this);
|
|
|
|
blockListener = new EssentialsProtectBlockListener(this);
|
|
|
|
entityListener = new EssentialsProtectEntityListener(this);
|
2011-04-27 01:33:45 +00:00
|
|
|
weatherListener = new EssentialsProtectWeatherListener(this);
|
2011-03-30 14:28:46 +00:00
|
|
|
pm.registerEvent(Type.PLAYER_INTERACT, playerListener, Priority.Low, this);
|
|
|
|
pm.registerEvent(Type.BLOCK_PLACE, blockListener, Priority.Highest, this);
|
|
|
|
pm.registerEvent(Type.BLOCK_FROMTO, blockListener, Priority.Highest, this);
|
2011-03-30 04:03:21 +00:00
|
|
|
pm.registerEvent(Type.BLOCK_IGNITE, blockListener, Priority.Highest, this);
|
|
|
|
pm.registerEvent(Type.BLOCK_BURN, blockListener, Priority.Highest, this);
|
|
|
|
pm.registerEvent(Type.ENTITY_EXPLODE, entityListener, Priority.Highest, this);
|
2011-03-30 14:28:46 +00:00
|
|
|
pm.registerEvent(Type.ENTITY_DAMAGE, entityListener, Priority.Highest, this);
|
2011-06-02 23:09:59 +00:00
|
|
|
pm.registerEvent(Type.BLOCK_BREAK, blockListener, Priority.Highest, this);
|
2011-03-30 04:03:21 +00:00
|
|
|
pm.registerEvent(Type.CREATURE_SPAWN, entityListener, Priority.Highest, this);
|
2011-04-27 01:33:45 +00:00
|
|
|
pm.registerEvent(Type.LIGHTNING_STRIKE, weatherListener, Priority.Highest, this);
|
2011-06-02 23:09:59 +00:00
|
|
|
pm.registerEvent(Type.THUNDER_CHANGE, weatherListener, Priority.Highest, this);
|
|
|
|
pm.registerEvent(Type.WEATHER_CHANGE, weatherListener, Priority.Highest, this);
|
2011-06-05 21:36:47 +00:00
|
|
|
pm.registerEvent(Type.ENTITY_TARGET, entityListener, Priority.Highest, this);
|
2011-06-03 21:03:08 +00:00
|
|
|
reloadConfig();
|
|
|
|
ess.addReloadListener(this);
|
2011-06-02 23:09:59 +00:00
|
|
|
if (!this.getDescription().getVersion().equals(Essentials.getStatic().getDescription().getVersion()))
|
|
|
|
{
|
2011-06-03 21:03:08 +00:00
|
|
|
logger.log(Level.WARNING, Util.i18n("versionMismatchAll"));
|
2011-03-30 04:03:21 +00:00
|
|
|
}
|
2011-06-03 20:56:29 +00:00
|
|
|
logger.info(Util.format("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), Essentials.AUTHORS));
|
2011-03-30 04:03:21 +00:00
|
|
|
}
|
|
|
|
|
2011-06-03 20:56:29 +00:00
|
|
|
public static boolean checkProtectionItems(List<Integer> itemList, int id)
|
2011-03-30 04:03:21 +00:00
|
|
|
{
|
2011-06-03 20:56:29 +00:00
|
|
|
return !itemList.isEmpty() && itemList.contains(id);
|
2011-03-30 04:03:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDisable()
|
|
|
|
{
|
|
|
|
genSettings.clear();
|
|
|
|
dataSettings.clear();
|
|
|
|
blockListener = null;
|
|
|
|
playerListener = null;
|
|
|
|
entityListener = null;
|
|
|
|
genSettings = null;
|
|
|
|
dataSettings = null;
|
|
|
|
guardSettings = null;
|
|
|
|
playerSettings = null;
|
|
|
|
usageList = null;
|
|
|
|
blackListPlace = null;
|
|
|
|
onPlaceAlert = null;
|
|
|
|
onUseAlert = null;
|
|
|
|
onBreakAlert = null;
|
|
|
|
}
|
|
|
|
|
2011-03-30 12:56:34 +00:00
|
|
|
public void alert(User user, String item, String type)
|
|
|
|
{
|
|
|
|
Location loc = user.getLocation();
|
|
|
|
for (Player p : this.getServer().getOnlinePlayers())
|
|
|
|
{
|
2011-06-02 23:09:59 +00:00
|
|
|
User alertUser = ess.getUser(p);
|
2011-03-30 12:56:34 +00:00
|
|
|
if (alertUser.isAuthorized("essentials.protect.alerts"))
|
2011-06-02 23:09:59 +00:00
|
|
|
alertUser.sendMessage(Util.format("alertFormat", user.getName(), type, item, formatCoords(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String formatCoords(int x, int y, int z)
|
|
|
|
{
|
|
|
|
return x + "," + y + "," + z;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void reloadConfig()
|
|
|
|
{
|
|
|
|
dataSettings = ess.getSettings().getEpDBSettings();
|
|
|
|
genSettings = ess.getSettings().getEpSettings();
|
|
|
|
guardSettings = ess.getSettings().getEpGuardSettings();
|
|
|
|
usageList = ess.getSettings().epBlackListUsage();
|
|
|
|
blackListPlace = ess.getSettings().epBlackListPlacement();
|
|
|
|
breakBlackList = ess.getSettings().epBlockBreakingBlacklist();
|
|
|
|
onPlaceAlert = ess.getSettings().getEpAlertOnPlacement();
|
|
|
|
onUseAlert = ess.getSettings().getEpAlertOnUse();
|
|
|
|
onBreakAlert = ess.getSettings().getEpAlertOnBreak();
|
|
|
|
playerSettings = ess.getSettings().getEpPlayerSettings();
|
|
|
|
|
|
|
|
if (dataSettings.get("protect.datatype").equals("mysql"))
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
storage = new ProtectedBlockMySQL(dataSettings.get("protect.mysqlDb"), dataSettings.get("protect.username"), dataSettings.get("protect.password"));
|
|
|
|
}
|
|
|
|
catch (PropertyVetoException ex)
|
|
|
|
{
|
|
|
|
logger.log(Level.SEVERE, null, ex);
|
|
|
|
}
|
2011-03-30 12:56:34 +00:00
|
|
|
}
|
2011-06-02 23:09:59 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
storage = new ProtectedBlockSQLite("jdbc:sqlite:plugins/Essentials/EssentialsProtect.db");
|
|
|
|
}
|
|
|
|
catch (PropertyVetoException ex)
|
|
|
|
{
|
|
|
|
logger.log(Level.SEVERE, null, ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (genSettings.get("protect.memstore"))
|
|
|
|
{
|
|
|
|
storage = new ProtectedBlockMemory(storage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static IProtectedBlock getStorage()
|
|
|
|
{
|
|
|
|
return EssentialsProtect.instance.storage;
|
2011-03-30 04:03:21 +00:00
|
|
|
}
|
|
|
|
}
|