2011-03-30 04:03:21 +00:00
|
|
|
package com.earth2me.essentials.protect;
|
|
|
|
|
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-06 20:29:08 +00:00
|
|
|
import java.util.EnumMap;
|
2011-06-03 20:56:29 +00:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
2011-07-19 08:34:02 +00:00
|
|
|
import java.util.logging.Filter;
|
2011-03-30 04:03:21 +00:00
|
|
|
import java.util.logging.Level;
|
2011-07-19 08:34:02 +00:00
|
|
|
import java.util.logging.LogRecord;
|
2011-03-30 04:03:21 +00:00
|
|
|
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-06-06 20:29:08 +00:00
|
|
|
public class EssentialsProtect extends JavaPlugin implements IConf, IProtect
|
2011-03-30 04:03:21 +00:00
|
|
|
{
|
2011-06-06 20:29:08 +00:00
|
|
|
private static final Logger LOGGER = Logger.getLogger("Minecraft");
|
|
|
|
private final transient Map<ProtectConfig, Boolean> settingsBoolean = new EnumMap<ProtectConfig, Boolean>(ProtectConfig.class);
|
|
|
|
private final transient Map<ProtectConfig, String> settingsString = new EnumMap<ProtectConfig, String>(ProtectConfig.class);
|
|
|
|
private final transient Map<ProtectConfig, List<Integer>> settingsList = new EnumMap<ProtectConfig, List<Integer>>(ProtectConfig.class);
|
|
|
|
private transient IProtectedBlock storage = null;
|
|
|
|
public transient IEssentials ess = null;
|
2011-03-30 04:03:21 +00:00
|
|
|
|
|
|
|
public void onEnable()
|
|
|
|
{
|
2011-06-06 20:29:08 +00:00
|
|
|
final PluginManager pm = this.getServer().getPluginManager();
|
2011-07-15 23:33:22 +00:00
|
|
|
ess = (IEssentials)pm.getPlugin("Essentials");
|
2011-06-06 20:29:08 +00:00
|
|
|
|
|
|
|
final EssentialsProtectPlayerListener playerListener = new EssentialsProtectPlayerListener(this);
|
2011-03-30 14:28:46 +00:00
|
|
|
pm.registerEvent(Type.PLAYER_INTERACT, playerListener, Priority.Low, this);
|
2011-06-06 20:29:08 +00:00
|
|
|
|
|
|
|
final EssentialsProtectBlockListener blockListener = new EssentialsProtectBlockListener(this);
|
2011-03-30 14:28:46 +00:00
|
|
|
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);
|
2011-06-06 20:29:08 +00:00
|
|
|
pm.registerEvent(Type.BLOCK_BREAK, blockListener, Priority.Highest, this);
|
2011-07-17 23:05:42 +00:00
|
|
|
pm.registerEvent(Type.BLOCK_PISTON_EXTEND, blockListener, Priority.Highest, this);
|
|
|
|
pm.registerEvent(Type.BLOCK_PISTON_RETRACT, blockListener, Priority.Highest, this);
|
2011-06-06 20:29:08 +00:00
|
|
|
|
|
|
|
final EssentialsProtectEntityListener entityListener = new EssentialsProtectEntityListener(this);
|
2011-03-30 04:03:21 +00:00
|
|
|
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-03-30 04:03:21 +00:00
|
|
|
pm.registerEvent(Type.CREATURE_SPAWN, entityListener, Priority.Highest, this);
|
2011-06-06 20:29:08 +00:00
|
|
|
pm.registerEvent(Type.ENTITY_TARGET, entityListener, Priority.Highest, this);
|
2011-07-18 05:22:28 +00:00
|
|
|
pm.registerEvent(Type.EXPLOSION_PRIME, entityListener, Priority.Highest, this);
|
2011-06-06 20:29:08 +00:00
|
|
|
|
|
|
|
final EssentialsProtectWeatherListener weatherListener = new EssentialsProtectWeatherListener(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-07-19 08:34:02 +00:00
|
|
|
|
2011-06-03 21:03:08 +00:00
|
|
|
reloadConfig();
|
|
|
|
ess.addReloadListener(this);
|
2011-06-06 20:29:08 +00:00
|
|
|
if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion()))
|
2011-06-02 23:09:59 +00:00
|
|
|
{
|
2011-06-06 20:29:08 +00:00
|
|
|
LOGGER.log(Level.WARNING, Util.i18n("versionMismatchAll"));
|
2011-03-30 04:03:21 +00:00
|
|
|
}
|
2011-07-15 23:33:22 +00:00
|
|
|
LOGGER.info(Util.format("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), "essentials team"));
|
2011-03-30 04:03:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-06-06 20:29:08 +00:00
|
|
|
public boolean checkProtectionItems(final ProtectConfig list, final int id)
|
2011-03-30 04:03:21 +00:00
|
|
|
{
|
2011-06-06 20:29:08 +00:00
|
|
|
final List<Integer> itemList = settingsList.get(list);
|
|
|
|
return itemList != null && !itemList.isEmpty() && itemList.contains(id);
|
2011-03-30 04:03:21 +00:00
|
|
|
}
|
|
|
|
|
2011-06-06 20:29:08 +00:00
|
|
|
@Override
|
|
|
|
public void alert(final User user, final String item, final String type)
|
2011-03-30 12:56:34 +00:00
|
|
|
{
|
2011-06-06 20:29:08 +00:00
|
|
|
final Location loc = user.getLocation();
|
2011-07-15 17:52:29 +00:00
|
|
|
final String warnMessage = Util.format("alertFormat", user.getName(), type, item,
|
|
|
|
loc.getWorld().getName() + "," + loc.getBlockX() + ","
|
|
|
|
+ loc.getBlockY() + "," + loc.getBlockZ());
|
|
|
|
LOGGER.log(Level.WARNING, warnMessage);
|
2011-03-30 12:56:34 +00:00
|
|
|
for (Player p : this.getServer().getOnlinePlayers())
|
|
|
|
{
|
2011-06-06 20:29:08 +00:00
|
|
|
final User alertUser = ess.getUser(p);
|
2011-03-30 12:56:34 +00:00
|
|
|
if (alertUser.isAuthorized("essentials.protect.alerts"))
|
2011-06-06 20:29:08 +00:00
|
|
|
{
|
2011-07-15 17:52:29 +00:00
|
|
|
alertUser.sendMessage(warnMessage);
|
2011-06-06 20:29:08 +00:00
|
|
|
}
|
2011-06-02 23:09:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void reloadConfig()
|
|
|
|
{
|
2011-07-19 08:34:02 +00:00
|
|
|
if (storage != null)
|
|
|
|
{
|
|
|
|
storage.onPluginDeactivation();
|
|
|
|
}
|
2011-06-06 20:29:08 +00:00
|
|
|
for (ProtectConfig protectConfig : ProtectConfig.values())
|
|
|
|
{
|
2011-07-15 17:52:29 +00:00
|
|
|
if (protectConfig.isList())
|
|
|
|
{
|
2011-06-06 20:29:08 +00:00
|
|
|
settingsList.put(protectConfig, ess.getSettings().getProtectList(protectConfig.getConfigName()));
|
2011-07-15 17:52:29 +00:00
|
|
|
}
|
|
|
|
else if (protectConfig.isString())
|
|
|
|
{
|
2011-06-06 20:29:08 +00:00
|
|
|
settingsString.put(protectConfig, ess.getSettings().getProtectString(protectConfig.getConfigName()));
|
2011-07-15 17:52:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-06-06 20:29:08 +00:00
|
|
|
settingsBoolean.put(protectConfig, ess.getSettings().getProtectBoolean(protectConfig.getConfigName(), protectConfig.getDefaultValueBoolean()));
|
|
|
|
}
|
2011-07-15 17:52:29 +00:00
|
|
|
|
2011-06-06 20:29:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (getSettingString(ProtectConfig.datatype).equalsIgnoreCase("mysql"))
|
2011-06-02 23:09:59 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2011-06-06 20:29:08 +00:00
|
|
|
storage = new ProtectedBlockMySQL(
|
|
|
|
getSettingString(ProtectConfig.mysqlDB),
|
|
|
|
getSettingString(ProtectConfig.dbUsername),
|
|
|
|
getSettingString(ProtectConfig.dbPassword));
|
2011-06-02 23:09:59 +00:00
|
|
|
}
|
|
|
|
catch (PropertyVetoException ex)
|
|
|
|
{
|
2011-06-06 20:29:08 +00:00
|
|
|
LOGGER.log(Level.SEVERE, null, ex);
|
2011-06-02 23:09:59 +00:00
|
|
|
}
|
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)
|
|
|
|
{
|
2011-06-06 20:29:08 +00:00
|
|
|
LOGGER.log(Level.SEVERE, null, ex);
|
2011-06-02 23:09:59 +00:00
|
|
|
}
|
|
|
|
}
|
2011-06-06 20:29:08 +00:00
|
|
|
if (getSettingBool(ProtectConfig.memstore))
|
2011-06-02 23:09:59 +00:00
|
|
|
{
|
2011-06-06 20:29:08 +00:00
|
|
|
storage = new ProtectedBlockMemory(storage, this);
|
2011-06-02 23:09:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-06 20:29:08 +00:00
|
|
|
@Override
|
|
|
|
public IProtectedBlock getStorage()
|
|
|
|
{
|
|
|
|
return storage;
|
|
|
|
}
|
2011-07-15 17:52:29 +00:00
|
|
|
|
2011-06-06 20:29:08 +00:00
|
|
|
@Override
|
|
|
|
public boolean getSettingBool(final ProtectConfig protectConfig)
|
|
|
|
{
|
|
|
|
final Boolean bool = settingsBoolean.get(protectConfig);
|
|
|
|
return bool == null ? protectConfig.getDefaultValueBoolean() : bool;
|
|
|
|
}
|
2011-07-15 17:52:29 +00:00
|
|
|
|
2011-06-06 20:29:08 +00:00
|
|
|
@Override
|
|
|
|
public String getSettingString(final ProtectConfig protectConfig)
|
|
|
|
{
|
|
|
|
final String str = settingsString.get(protectConfig);
|
|
|
|
return str == null ? protectConfig.getDefaultValueString() : str;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onDisable()
|
|
|
|
{
|
2011-07-19 08:34:02 +00:00
|
|
|
if (storage != null)
|
|
|
|
{
|
|
|
|
storage.onPluginDeactivation();
|
|
|
|
}
|
2011-06-06 20:29:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public IEssentials getEssentials()
|
2011-06-02 23:09:59 +00:00
|
|
|
{
|
2011-06-06 20:29:08 +00:00
|
|
|
return ess;
|
2011-03-30 04:03:21 +00:00
|
|
|
}
|
|
|
|
}
|