mirror of
https://github.com/essentials/Essentials.git
synced 2025-08-15 11:04:29 +02:00
Clean up protect :: transient is not needed :: remove unnecessary returns :: @Override all the things!
This commit is contained in:
@@ -1,102 +1,97 @@
|
|||||||
package com.earth2me.essentials.protect;
|
package com.earth2me.essentials.protect;
|
||||||
|
|
||||||
import com.earth2me.essentials.IConf;
|
import static com.earth2me.essentials.I18n._;
|
||||||
import com.earth2me.essentials.IEssentials;
|
import com.earth2me.essentials.IConf;
|
||||||
import com.earth2me.essentials.protect.data.ProtectedBlockMemory;
|
import com.earth2me.essentials.IEssentials;
|
||||||
import com.earth2me.essentials.protect.data.ProtectedBlockMySQL;
|
import com.earth2me.essentials.protect.data.ProtectedBlockMemory;
|
||||||
import com.earth2me.essentials.protect.data.ProtectedBlockSQLite;
|
import com.earth2me.essentials.protect.data.ProtectedBlockMySQL;
|
||||||
import java.beans.PropertyVetoException;
|
import com.earth2me.essentials.protect.data.ProtectedBlockSQLite;
|
||||||
import static com.earth2me.essentials.I18n._;
|
import java.beans.PropertyVetoException;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
|
||||||
public class EssentialsConnect
|
public class EssentialsConnect
|
||||||
{
|
{
|
||||||
private static final Logger LOGGER = Logger.getLogger("Minecraft");
|
private static final Logger LOGGER = Logger.getLogger("Minecraft");
|
||||||
private final transient IEssentials ess;
|
private final IEssentials ess;
|
||||||
private final transient IProtect protect;
|
private final IProtect protect;
|
||||||
|
|
||||||
public EssentialsConnect(Plugin essPlugin, Plugin essProtect)
|
public EssentialsConnect(Plugin essPlugin, Plugin essProtect)
|
||||||
{
|
{
|
||||||
if (!essProtect.getDescription().getVersion().equals(essPlugin.getDescription().getVersion()))
|
if (!essProtect.getDescription().getVersion().equals(essPlugin.getDescription().getVersion()))
|
||||||
{
|
{
|
||||||
LOGGER.log(Level.WARNING, _("versionMismatchAll"));
|
LOGGER.log(Level.WARNING, _("versionMismatchAll"));
|
||||||
}
|
}
|
||||||
ess = (IEssentials)essPlugin;
|
ess = (IEssentials)essPlugin;
|
||||||
protect = (IProtect)essProtect;
|
protect = (IProtect)essProtect;
|
||||||
ProtectReloader pr = new ProtectReloader();
|
ProtectReloader pr = new ProtectReloader();
|
||||||
pr.reloadConfig();
|
pr.reloadConfig();
|
||||||
ess.addReloadListener(pr);
|
ess.addReloadListener(pr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onDisable()
|
public IEssentials getEssentials()
|
||||||
{
|
{
|
||||||
}
|
return ess;
|
||||||
|
}
|
||||||
public IEssentials getEssentials()
|
|
||||||
{
|
private class ProtectReloader implements IConf
|
||||||
return ess;
|
{
|
||||||
}
|
@Override
|
||||||
|
public void reloadConfig()
|
||||||
|
{
|
||||||
private class ProtectReloader implements IConf
|
if (protect.getStorage() != null)
|
||||||
{
|
{
|
||||||
@Override
|
protect.getStorage().onPluginDeactivation();
|
||||||
public void reloadConfig()
|
}
|
||||||
{
|
for (ProtectConfig protectConfig : ProtectConfig.values())
|
||||||
if (protect.getStorage() != null)
|
{
|
||||||
{
|
if (protectConfig.isList())
|
||||||
protect.getStorage().onPluginDeactivation();
|
{
|
||||||
}
|
protect.getSettingsList().put(protectConfig, ess.getSettings().getProtectList(protectConfig.getConfigName()));
|
||||||
for (ProtectConfig protectConfig : ProtectConfig.values())
|
}
|
||||||
{
|
else if (protectConfig.isString())
|
||||||
if (protectConfig.isList())
|
{
|
||||||
{
|
protect.getSettingsString().put(protectConfig, ess.getSettings().getProtectString(protectConfig.getConfigName()));
|
||||||
protect.getSettingsList().put(protectConfig, ess.getSettings().getProtectList(protectConfig.getConfigName()));
|
}
|
||||||
}
|
else
|
||||||
else if (protectConfig.isString())
|
{
|
||||||
{
|
protect.getSettingsBoolean().put(protectConfig, ess.getSettings().getProtectBoolean(protectConfig.getConfigName(), protectConfig.getDefaultValueBoolean()));
|
||||||
protect.getSettingsString().put(protectConfig, ess.getSettings().getProtectString(protectConfig.getConfigName()));
|
}
|
||||||
}
|
|
||||||
else
|
}
|
||||||
{
|
|
||||||
protect.getSettingsBoolean().put(protectConfig, ess.getSettings().getProtectBoolean(protectConfig.getConfigName(), protectConfig.getDefaultValueBoolean()));
|
if (protect.getSettingString(ProtectConfig.datatype).equalsIgnoreCase("mysql"))
|
||||||
}
|
{
|
||||||
|
try
|
||||||
}
|
{
|
||||||
|
protect.setStorage(new ProtectedBlockMySQL(
|
||||||
if (protect.getSettingString(ProtectConfig.datatype).equalsIgnoreCase("mysql"))
|
protect.getSettingString(ProtectConfig.mysqlDB),
|
||||||
{
|
protect.getSettingString(ProtectConfig.dbUsername),
|
||||||
try
|
protect.getSettingString(ProtectConfig.dbPassword)));
|
||||||
{
|
}
|
||||||
protect.setStorage(new ProtectedBlockMySQL(
|
catch (PropertyVetoException ex)
|
||||||
protect.getSettingString(ProtectConfig.mysqlDB),
|
{
|
||||||
protect.getSettingString(ProtectConfig.dbUsername),
|
LOGGER.log(Level.SEVERE, null, ex);
|
||||||
protect.getSettingString(ProtectConfig.dbPassword)));
|
}
|
||||||
}
|
}
|
||||||
catch (PropertyVetoException ex)
|
else
|
||||||
{
|
{
|
||||||
LOGGER.log(Level.SEVERE, null, ex);
|
try
|
||||||
}
|
{
|
||||||
}
|
protect.setStorage(new ProtectedBlockSQLite("jdbc:sqlite:plugins/Essentials/EssentialsProtect.db"));
|
||||||
else
|
}
|
||||||
{
|
catch (PropertyVetoException ex)
|
||||||
try
|
{
|
||||||
{
|
LOGGER.log(Level.SEVERE, null, ex);
|
||||||
protect.setStorage(new ProtectedBlockSQLite("jdbc:sqlite:plugins/Essentials/EssentialsProtect.db"));
|
}
|
||||||
}
|
}
|
||||||
catch (PropertyVetoException ex)
|
if (protect.getSettingBool(ProtectConfig.memstore))
|
||||||
{
|
{
|
||||||
LOGGER.log(Level.SEVERE, null, ex);
|
protect.setStorage(new ProtectedBlockMemory(protect.getStorage(), protect));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (protect.getSettingBool(ProtectConfig.memstore))
|
}
|
||||||
{
|
}
|
||||||
protect.setStorage(new ProtectedBlockMemory(protect.getStorage(), protect));
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@@ -1,145 +1,150 @@
|
|||||||
package com.earth2me.essentials.protect;
|
package com.earth2me.essentials.protect;
|
||||||
|
|
||||||
import com.earth2me.essentials.protect.data.IProtectedBlock;
|
import com.earth2me.essentials.protect.data.IProtectedBlock;
|
||||||
import com.mchange.v2.log.MLevel;
|
import com.mchange.v2.log.MLevel;
|
||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.logging.Filter;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Logger;
|
||||||
import java.util.logging.LogRecord;
|
import org.bukkit.entity.Player;
|
||||||
import java.util.logging.Logger;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.plugin.PluginManager;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
public class EssentialsProtect extends JavaPlugin implements IProtect
|
||||||
|
{
|
||||||
public class EssentialsProtect extends JavaPlugin implements IProtect
|
private static final Logger LOGGER = Logger.getLogger("Minecraft");
|
||||||
{
|
private static com.mchange.v2.log.MLogger C3P0logger;
|
||||||
private static final Logger LOGGER = Logger.getLogger("Minecraft");
|
private final Map<ProtectConfig, Boolean> settingsBoolean = new EnumMap<ProtectConfig, Boolean>(ProtectConfig.class);
|
||||||
private static com.mchange.v2.log.MLogger C3P0logger;
|
private final Map<ProtectConfig, String> settingsString = new EnumMap<ProtectConfig, String>(ProtectConfig.class);
|
||||||
private final transient Map<ProtectConfig, Boolean> settingsBoolean = new EnumMap<ProtectConfig, Boolean>(ProtectConfig.class);
|
private final Map<ProtectConfig, List<Integer>> settingsList = new EnumMap<ProtectConfig, List<Integer>>(ProtectConfig.class);
|
||||||
private final transient Map<ProtectConfig, String> settingsString = new EnumMap<ProtectConfig, String>(ProtectConfig.class);
|
private IProtectedBlock storage = null;
|
||||||
private final transient Map<ProtectConfig, List<Integer>> settingsList = new EnumMap<ProtectConfig, List<Integer>>(ProtectConfig.class);
|
private EssentialsConnect ess = null;
|
||||||
private transient IProtectedBlock storage = null;
|
|
||||||
private transient EssentialsConnect ess = null;
|
@Override
|
||||||
|
public void onLoad()
|
||||||
@Override
|
{
|
||||||
public void onLoad()
|
try
|
||||||
{
|
{
|
||||||
try
|
// Simple fix for the case that log4j is on the class path by another plugin
|
||||||
{
|
Class propertyConfiguratorClass = Class.forName("org.apache.log4j.PropertyConfigurator");
|
||||||
// Simple fix for the case that log4j is on the class path by another plugin
|
Properties properties = new Properties();
|
||||||
Class propertyConfiguratorClass = Class.forName("org.apache.log4j.PropertyConfigurator");
|
properties.load(this.getClass().getResourceAsStream("log4j.properties"));
|
||||||
Properties properties = new Properties();
|
propertyConfiguratorClass.getMethod("configure", Properties.class).invoke(null, properties);
|
||||||
properties.load(this.getClass().getResourceAsStream("log4j.properties"));
|
}
|
||||||
propertyConfiguratorClass.getMethod("configure", Properties.class).invoke(null, properties);
|
catch (Exception ex)
|
||||||
}
|
{
|
||||||
catch (Exception ex)
|
//Ignore me, log4j not found on classloader.
|
||||||
{
|
}
|
||||||
//Ignore me, log4j not found on classloader.
|
C3P0logger = com.mchange.v2.log.MLog.getLogger(com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.class);
|
||||||
}
|
C3P0logger.setLevel(MLevel.WARNING);
|
||||||
C3P0logger = com.mchange.v2.log.MLog.getLogger(com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.class);
|
}
|
||||||
C3P0logger.setLevel(MLevel.WARNING);
|
|
||||||
}
|
@Override
|
||||||
|
public void onEnable()
|
||||||
public void onEnable()
|
{
|
||||||
{
|
final PluginManager pm = this.getServer().getPluginManager();
|
||||||
final PluginManager pm = this.getServer().getPluginManager();
|
final Plugin essPlugin = pm.getPlugin("Essentials");
|
||||||
final Plugin essPlugin = pm.getPlugin("Essentials");
|
if (essPlugin == null || !essPlugin.isEnabled())
|
||||||
if (essPlugin == null || !essPlugin.isEnabled())
|
{
|
||||||
{
|
enableEmergencyMode(pm);
|
||||||
enableEmergencyMode(pm);
|
return;
|
||||||
return;
|
}
|
||||||
}
|
ess = new EssentialsConnect(essPlugin, this);
|
||||||
ess = new EssentialsConnect(essPlugin, this);
|
|
||||||
|
final EssentialsProtectPlayerListener playerListener = new EssentialsProtectPlayerListener(this);
|
||||||
final EssentialsProtectPlayerListener playerListener = new EssentialsProtectPlayerListener(this);
|
pm.registerEvents(playerListener, this);
|
||||||
pm.registerEvents(playerListener, this);
|
|
||||||
|
final EssentialsProtectBlockListener blockListener = new EssentialsProtectBlockListener(this);
|
||||||
final EssentialsProtectBlockListener blockListener = new EssentialsProtectBlockListener(this);
|
pm.registerEvents(blockListener, this);
|
||||||
pm.registerEvents(blockListener, this);
|
|
||||||
|
final EssentialsProtectEntityListener entityListener = new EssentialsProtectEntityListener(this);
|
||||||
final EssentialsProtectEntityListener entityListener = new EssentialsProtectEntityListener(this);
|
pm.registerEvents(entityListener, this);
|
||||||
pm.registerEvents(entityListener, this);
|
|
||||||
|
final EssentialsProtectWeatherListener weatherListener = new EssentialsProtectWeatherListener(this);
|
||||||
final EssentialsProtectWeatherListener weatherListener = new EssentialsProtectWeatherListener(this);
|
pm.registerEvents(weatherListener, this);
|
||||||
pm.registerEvents(weatherListener, this);
|
}
|
||||||
}
|
|
||||||
|
private void enableEmergencyMode(final PluginManager pm)
|
||||||
private void enableEmergencyMode(final PluginManager pm)
|
{
|
||||||
{
|
final EmergencyListener emListener = new EmergencyListener();
|
||||||
final EmergencyListener emListener = new EmergencyListener();
|
pm.registerEvents(emListener, this);
|
||||||
pm.registerEvents(emListener, this);
|
|
||||||
|
for (Player player : getServer().getOnlinePlayers())
|
||||||
for (Player player : getServer().getOnlinePlayers())
|
{
|
||||||
{
|
player.sendMessage("Essentials Protect is in emergency mode. Check your log for errors.");
|
||||||
player.sendMessage("Essentials Protect is in emergency mode. Check your log for errors.");
|
}
|
||||||
}
|
LOGGER.log(Level.SEVERE, "Essentials not installed or failed to load. Essenials Protect is in emergency mode now.");
|
||||||
LOGGER.log(Level.SEVERE, "Essentials not installed or failed to load. Essenials Protect is in emergency mode now.");
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
public IProtectedBlock getStorage()
|
||||||
public IProtectedBlock getStorage()
|
{
|
||||||
{
|
return storage;
|
||||||
return storage;
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
public void setStorage(IProtectedBlock pb)
|
||||||
public void setStorage(IProtectedBlock pb)
|
{
|
||||||
{
|
storage = pb;
|
||||||
storage = pb;
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
public EssentialsConnect getEssentialsConnect()
|
public EssentialsConnect getEssentialsConnect()
|
||||||
{
|
{
|
||||||
return ess;
|
return ess;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<ProtectConfig, Boolean> getSettingsBoolean()
|
@Override
|
||||||
{
|
public Map<ProtectConfig, Boolean> getSettingsBoolean()
|
||||||
return settingsBoolean;
|
{
|
||||||
}
|
return settingsBoolean;
|
||||||
|
}
|
||||||
public Map<ProtectConfig, String> getSettingsString()
|
|
||||||
{
|
@Override
|
||||||
return settingsString;
|
public Map<ProtectConfig, String> getSettingsString()
|
||||||
}
|
{
|
||||||
|
return settingsString;
|
||||||
public Map<ProtectConfig, List<Integer>> getSettingsList()
|
}
|
||||||
{
|
|
||||||
return settingsList;
|
@Override
|
||||||
}
|
public Map<ProtectConfig, List<Integer>> getSettingsList()
|
||||||
|
{
|
||||||
@Override
|
return settingsList;
|
||||||
public boolean getSettingBool(final ProtectConfig protectConfig)
|
}
|
||||||
{
|
|
||||||
final Boolean bool = settingsBoolean.get(protectConfig);
|
@Override
|
||||||
return bool == null ? protectConfig.getDefaultValueBoolean() : bool;
|
public boolean getSettingBool(final ProtectConfig protectConfig)
|
||||||
}
|
{
|
||||||
|
final Boolean bool = settingsBoolean.get(protectConfig);
|
||||||
@Override
|
return bool == null ? protectConfig.getDefaultValueBoolean() : bool;
|
||||||
public String getSettingString(final ProtectConfig protectConfig)
|
}
|
||||||
{
|
|
||||||
final String str = settingsString.get(protectConfig);
|
@Override
|
||||||
return str == null ? protectConfig.getDefaultValueString() : str;
|
public String getSettingString(final ProtectConfig protectConfig)
|
||||||
}
|
{
|
||||||
|
final String str = settingsString.get(protectConfig);
|
||||||
public void onDisable()
|
return str == null ? protectConfig.getDefaultValueString() : str;
|
||||||
{
|
}
|
||||||
if (storage != null)
|
|
||||||
{
|
@Override
|
||||||
storage.onPluginDeactivation();
|
public void onDisable()
|
||||||
}
|
{
|
||||||
// Sleep for a second to allow the database to close.
|
if (storage != null)
|
||||||
try
|
{
|
||||||
{
|
storage.onPluginDeactivation();
|
||||||
Thread.sleep(1000);
|
}
|
||||||
}
|
// Sleep for a second to allow the database to close.
|
||||||
catch (InterruptedException ex)
|
try
|
||||||
{
|
{
|
||||||
}
|
Thread.sleep(1000);
|
||||||
}
|
}
|
||||||
}
|
catch (InterruptedException ex)
|
||||||
|
{
|
||||||
|
Logger.getLogger(EssentialsProtect.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -1,416 +1,405 @@
|
|||||||
package com.earth2me.essentials.protect;
|
package com.earth2me.essentials.protect;
|
||||||
|
|
||||||
import com.earth2me.essentials.IEssentials;
|
import com.earth2me.essentials.IEssentials;
|
||||||
import com.earth2me.essentials.User;
|
import com.earth2me.essentials.User;
|
||||||
import com.earth2me.essentials.protect.data.IProtectedBlock;
|
import com.earth2me.essentials.protect.data.IProtectedBlock;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.*;
|
import org.bukkit.event.block.*;
|
||||||
|
|
||||||
|
|
||||||
public class EssentialsProtectBlockListener implements Listener
|
public class EssentialsProtectBlockListener implements Listener
|
||||||
{
|
{
|
||||||
final private transient IProtect prot;
|
final private IProtect prot;
|
||||||
final private transient IEssentials ess;
|
final private IEssentials ess;
|
||||||
|
|
||||||
public EssentialsProtectBlockListener(final IProtect parent)
|
public EssentialsProtectBlockListener(final IProtect parent)
|
||||||
{
|
{
|
||||||
this.prot = parent;
|
this.prot = parent;
|
||||||
this.ess = prot.getEssentialsConnect().getEssentials();
|
this.ess = prot.getEssentialsConnect().getEssentials();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onBlockPlace(final BlockPlaceEvent event)
|
public void onBlockPlace(final BlockPlaceEvent event)
|
||||||
{
|
{
|
||||||
final User user = ess.getUser(event.getPlayer());
|
final User user = ess.getUser(event.getPlayer());
|
||||||
|
final Block blockPlaced = event.getBlockPlaced();
|
||||||
final Block blockPlaced = event.getBlockPlaced();
|
final Block below = blockPlaced.getRelative(BlockFace.DOWN);
|
||||||
final int id = blockPlaced.getTypeId();
|
if ((below.getType() == Material.RAILS || below.getType() == Material.POWERED_RAIL || below.getType() == Material.DETECTOR_RAIL)
|
||||||
|
&& prot.getSettingBool(ProtectConfig.prevent_block_on_rail)
|
||||||
|
&& isProtected(below, user))
|
||||||
final Block below = blockPlaced.getRelative(BlockFace.DOWN);
|
{
|
||||||
if ((below.getType() == Material.RAILS || below.getType() == Material.POWERED_RAIL || below.getType() == Material.DETECTOR_RAIL)
|
event.setCancelled(true);
|
||||||
&& prot.getSettingBool(ProtectConfig.prevent_block_on_rail)
|
return;
|
||||||
&& isProtected(below, user))
|
}
|
||||||
{
|
|
||||||
event.setCancelled(true);
|
final List<Block> protect = new ArrayList<Block>();
|
||||||
return;
|
if ((blockPlaced.getType() == Material.RAILS || blockPlaced.getType() == Material.POWERED_RAIL || blockPlaced.getType() == Material.DETECTOR_RAIL)
|
||||||
}
|
&& prot.getSettingBool(ProtectConfig.protect_rails)
|
||||||
|
&& user.isAuthorized("essentials.protect"))
|
||||||
final List<Block> protect = new ArrayList<Block>();
|
{
|
||||||
if ((blockPlaced.getType() == Material.RAILS || blockPlaced.getType() == Material.POWERED_RAIL || blockPlaced.getType() == Material.DETECTOR_RAIL)
|
protect.add(blockPlaced);
|
||||||
&& prot.getSettingBool(ProtectConfig.protect_rails)
|
if (prot.getSettingBool(ProtectConfig.protect_below_rails)
|
||||||
&& user.isAuthorized("essentials.protect"))
|
&& !isProtected(blockPlaced.getRelative(BlockFace.DOWN), user))
|
||||||
{
|
{
|
||||||
protect.add(blockPlaced);
|
protect.add(blockPlaced.getRelative(BlockFace.DOWN));
|
||||||
if (prot.getSettingBool(ProtectConfig.protect_below_rails)
|
}
|
||||||
&& !isProtected(blockPlaced.getRelative(BlockFace.DOWN), user))
|
}
|
||||||
{
|
if ((blockPlaced.getType() == Material.SIGN_POST || blockPlaced.getType() == Material.WALL_SIGN)
|
||||||
protect.add(blockPlaced.getRelative(BlockFace.DOWN));
|
&& prot.getSettingBool(ProtectConfig.protect_signs)
|
||||||
}
|
&& user.isAuthorized("essentials.protect"))
|
||||||
}
|
{
|
||||||
if ((blockPlaced.getType() == Material.SIGN_POST || blockPlaced.getType() == Material.WALL_SIGN)
|
protect.add(blockPlaced);
|
||||||
&& prot.getSettingBool(ProtectConfig.protect_signs)
|
if (prot.getSettingBool(ProtectConfig.protect_against_signs)
|
||||||
&& user.isAuthorized("essentials.protect"))
|
&& event.getBlockAgainst().getType() != Material.SIGN_POST
|
||||||
{
|
&& event.getBlockAgainst().getType() != Material.WALL_SIGN
|
||||||
protect.add(blockPlaced);
|
&& !isProtected(event.getBlockAgainst(), user))
|
||||||
if (prot.getSettingBool(ProtectConfig.protect_against_signs)
|
{
|
||||||
&& event.getBlockAgainst().getType() != Material.SIGN_POST
|
protect.add(event.getBlockAgainst());
|
||||||
&& event.getBlockAgainst().getType() != Material.WALL_SIGN
|
}
|
||||||
&& !isProtected(event.getBlockAgainst(), user))
|
}
|
||||||
{
|
for (Block block : protect)
|
||||||
protect.add(event.getBlockAgainst());
|
{
|
||||||
}
|
prot.getStorage().protectBlock(block, user.getName());
|
||||||
}
|
}
|
||||||
for (Block block : protect)
|
}
|
||||||
{
|
|
||||||
prot.getStorage().protectBlock(block, user.getName());
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
}
|
public void onBlockIgnite(BlockIgniteEvent event)
|
||||||
}
|
{
|
||||||
|
final Block block = event.getBlock();
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
if ((block.getType() == Material.RAILS || block.getType() == Material.POWERED_RAIL || block.getType() == Material.DETECTOR_RAIL)
|
||||||
public void onBlockIgnite(BlockIgniteEvent event)
|
&& prot.getSettingBool(ProtectConfig.protect_rails))
|
||||||
{
|
{
|
||||||
final Block block = event.getBlock();
|
event.setCancelled(true);
|
||||||
if ((block.getType() == Material.RAILS || block.getType() == Material.POWERED_RAIL || block.getType() == Material.DETECTOR_RAIL)
|
return;
|
||||||
&& prot.getSettingBool(ProtectConfig.protect_rails))
|
}
|
||||||
{
|
if ((block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST)
|
||||||
event.setCancelled(true);
|
&& prot.getSettingBool(ProtectConfig.protect_signs))
|
||||||
return;
|
{
|
||||||
}
|
event.setCancelled(true);
|
||||||
if ((block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST)
|
return;
|
||||||
&& prot.getSettingBool(ProtectConfig.protect_signs))
|
}
|
||||||
{
|
if (event.getBlock().getType() == Material.OBSIDIAN
|
||||||
event.setCancelled(true);
|
|| event.getBlock().getRelative(BlockFace.DOWN).getType() == Material.OBSIDIAN)
|
||||||
return;
|
{
|
||||||
}
|
event.setCancelled(prot.getSettingBool(ProtectConfig.prevent_portal_creation));
|
||||||
if (event.getBlock().getType() == Material.OBSIDIAN
|
return;
|
||||||
|| event.getBlock().getRelative(BlockFace.DOWN).getType() == Material.OBSIDIAN)
|
}
|
||||||
{
|
|
||||||
event.setCancelled(prot.getSettingBool(ProtectConfig.prevent_portal_creation));
|
if (event.getCause().equals(BlockIgniteEvent.IgniteCause.SPREAD))
|
||||||
return;
|
{
|
||||||
}
|
event.setCancelled(prot.getSettingBool(ProtectConfig.prevent_fire_spread));
|
||||||
|
return;
|
||||||
if (event.getCause().equals(BlockIgniteEvent.IgniteCause.SPREAD))
|
}
|
||||||
{
|
|
||||||
event.setCancelled(prot.getSettingBool(ProtectConfig.prevent_fire_spread));
|
if (event.getCause().equals(BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL))
|
||||||
return;
|
{
|
||||||
}
|
event.setCancelled(prot.getSettingBool(ProtectConfig.prevent_flint_fire));
|
||||||
|
return;
|
||||||
if (event.getCause().equals(BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL))
|
}
|
||||||
{
|
|
||||||
event.setCancelled(prot.getSettingBool(ProtectConfig.prevent_flint_fire));
|
if (event.getCause().equals(BlockIgniteEvent.IgniteCause.LAVA))
|
||||||
return;
|
{
|
||||||
}
|
event.setCancelled(prot.getSettingBool(ProtectConfig.prevent_lava_fire_spread));
|
||||||
|
return;
|
||||||
if (event.getCause().equals(BlockIgniteEvent.IgniteCause.LAVA))
|
}
|
||||||
{
|
if (event.getCause().equals(BlockIgniteEvent.IgniteCause.LIGHTNING))
|
||||||
event.setCancelled(prot.getSettingBool(ProtectConfig.prevent_lava_fire_spread));
|
{
|
||||||
return;
|
event.setCancelled(prot.getSettingBool(ProtectConfig.prevent_lightning_fire_spread));
|
||||||
}
|
}
|
||||||
if (event.getCause().equals(BlockIgniteEvent.IgniteCause.LIGHTNING))
|
}
|
||||||
{
|
|
||||||
event.setCancelled(prot.getSettingBool(ProtectConfig.prevent_lightning_fire_spread));
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
return;
|
public void onBlockFromTo(final BlockFromToEvent event)
|
||||||
}
|
{
|
||||||
}
|
final Block toBlock = event.getToBlock();
|
||||||
|
if ((toBlock.getType() == Material.RAILS || toBlock.getType() == Material.POWERED_RAIL || toBlock.getType() == Material.DETECTOR_RAIL)
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
&& prot.getSettingBool(ProtectConfig.protect_rails))
|
||||||
public void onBlockFromTo(final BlockFromToEvent event)
|
{
|
||||||
{
|
event.setCancelled(true);
|
||||||
final Block toBlock = event.getToBlock();
|
return;
|
||||||
if ((toBlock.getType() == Material.RAILS || toBlock.getType() == Material.POWERED_RAIL || toBlock.getType() == Material.DETECTOR_RAIL)
|
}
|
||||||
&& prot.getSettingBool(ProtectConfig.protect_rails))
|
if ((toBlock.getType() == Material.WALL_SIGN || toBlock.getType() == Material.SIGN_POST)
|
||||||
{
|
&& prot.getSettingBool(ProtectConfig.protect_signs))
|
||||||
event.setCancelled(true);
|
{
|
||||||
return;
|
event.setCancelled(true);
|
||||||
}
|
return;
|
||||||
if ((toBlock.getType() == Material.WALL_SIGN || toBlock.getType() == Material.SIGN_POST)
|
}
|
||||||
&& prot.getSettingBool(ProtectConfig.protect_signs))
|
|
||||||
{
|
final Block block = event.getBlock();
|
||||||
event.setCancelled(true);
|
if (block.getType() == Material.WATER || block.getType() == Material.STATIONARY_WATER)
|
||||||
return;
|
{
|
||||||
}
|
event.setCancelled(prot.getSettingBool(ProtectConfig.prevent_water_flow));
|
||||||
|
return;
|
||||||
final Block block = event.getBlock();
|
}
|
||||||
if (block.getType() == Material.WATER || block.getType() == Material.STATIONARY_WATER)
|
|
||||||
{
|
if (block.getType() == Material.LAVA || block.getType() == Material.STATIONARY_LAVA)
|
||||||
event.setCancelled(prot.getSettingBool(ProtectConfig.prevent_water_flow));
|
{
|
||||||
return;
|
event.setCancelled(prot.getSettingBool(ProtectConfig.prevent_lava_flow));
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
if (block.getType() == Material.LAVA || block.getType() == Material.STATIONARY_LAVA)
|
|
||||||
{
|
if (block.getType() == Material.AIR)
|
||||||
event.setCancelled(prot.getSettingBool(ProtectConfig.prevent_lava_flow));
|
{
|
||||||
return;
|
event.setCancelled(prot.getSettingBool(ProtectConfig.prevent_water_bucket_flow));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (block.getType() == Material.AIR)
|
|
||||||
{
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
event.setCancelled(prot.getSettingBool(ProtectConfig.prevent_water_bucket_flow));
|
public void onBlockBurn(final BlockBurnEvent event)
|
||||||
return;
|
{
|
||||||
}
|
final Block block = event.getBlock();
|
||||||
}
|
if ((block.getType() == Material.RAILS || block.getType() == Material.POWERED_RAIL || block.getType() == Material.DETECTOR_RAIL) && prot.getSettingBool(ProtectConfig.protect_rails))
|
||||||
|
{
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
event.setCancelled(true);
|
||||||
public void onBlockBurn(final BlockBurnEvent event)
|
return;
|
||||||
{
|
}
|
||||||
final Block block = event.getBlock();
|
if ((block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST)
|
||||||
if ((block.getType() == Material.RAILS || block.getType() == Material.POWERED_RAIL || block.getType() == Material.DETECTOR_RAIL) && prot.getSettingBool(ProtectConfig.protect_rails))
|
&& prot.getSettingBool(ProtectConfig.protect_signs))
|
||||||
{
|
{
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ((block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST)
|
if (prot.getSettingBool(ProtectConfig.prevent_fire_spread))
|
||||||
&& prot.getSettingBool(ProtectConfig.protect_signs))
|
{
|
||||||
{
|
event.setCancelled(true);
|
||||||
event.setCancelled(true);
|
}
|
||||||
return;
|
}
|
||||||
}
|
private final static BlockFace[] faces = new BlockFace[]
|
||||||
if (prot.getSettingBool(ProtectConfig.prevent_fire_spread))
|
{
|
||||||
{
|
BlockFace.NORTH,
|
||||||
event.setCancelled(true);
|
BlockFace.EAST,
|
||||||
return;
|
BlockFace.SOUTH,
|
||||||
}
|
BlockFace.WEST,
|
||||||
}
|
BlockFace.UP,
|
||||||
private final static BlockFace[] faces = new BlockFace[]
|
BlockFace.DOWN,
|
||||||
{
|
BlockFace.SELF
|
||||||
BlockFace.NORTH,
|
};
|
||||||
BlockFace.EAST,
|
|
||||||
BlockFace.SOUTH,
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
BlockFace.WEST,
|
public void onBlockBreak(final BlockBreakEvent event)
|
||||||
BlockFace.UP,
|
{
|
||||||
BlockFace.DOWN,
|
final User user = ess.getUser(event.getPlayer());
|
||||||
BlockFace.SELF
|
final Block block = event.getBlock();
|
||||||
};
|
final Material type = block.getType();
|
||||||
|
final IProtectedBlock storage = prot.getStorage();
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
|
||||||
public void onBlockBreak(final BlockBreakEvent event)
|
if (user.isAuthorized("essentials.protect.admin"))
|
||||||
{
|
{
|
||||||
final User user = ess.getUser(event.getPlayer());
|
if (type == Material.WALL_SIGN || type == Material.SIGN_POST || type == Material.RAILS || type == Material.POWERED_RAIL || type == Material.DETECTOR_RAIL)
|
||||||
|
{
|
||||||
final Block block = event.getBlock();
|
storage.unprotectBlock(block);
|
||||||
final int typeId = block.getTypeId();
|
if (type == Material.RAILS || type == Material.POWERED_RAIL || type == Material.DETECTOR_RAIL || type == Material.SIGN_POST)
|
||||||
|
{
|
||||||
final Material type = block.getType();
|
final Block below = block.getRelative(BlockFace.DOWN);
|
||||||
|
storage.unprotectBlock(below);
|
||||||
final IProtectedBlock storage = prot.getStorage();
|
}
|
||||||
|
else
|
||||||
if (user.isAuthorized("essentials.protect.admin"))
|
{
|
||||||
{
|
for (BlockFace blockFace : faces)
|
||||||
if (type == Material.WALL_SIGN || type == Material.SIGN_POST || type == Material.RAILS || type == Material.POWERED_RAIL || type == Material.DETECTOR_RAIL)
|
{
|
||||||
{
|
final Block against = block.getRelative(blockFace);
|
||||||
storage.unprotectBlock(block);
|
storage.unprotectBlock(against);
|
||||||
if (type == Material.RAILS || type == Material.POWERED_RAIL || type == Material.DETECTOR_RAIL || type == Material.SIGN_POST)
|
}
|
||||||
{
|
}
|
||||||
final Block below = block.getRelative(BlockFace.DOWN);
|
}
|
||||||
storage.unprotectBlock(below);
|
else
|
||||||
}
|
{
|
||||||
else
|
for (BlockFace blockFace : faces)
|
||||||
{
|
{
|
||||||
for (BlockFace blockFace : faces)
|
final Block against = block.getRelative(blockFace);
|
||||||
{
|
storage.unprotectBlock(against);
|
||||||
final Block against = block.getRelative(blockFace);
|
}
|
||||||
storage.unprotectBlock(against);
|
}
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
}
|
{
|
||||||
else
|
|
||||||
{
|
final boolean isProtected = isProtected(block, user);
|
||||||
for (BlockFace blockFace : faces)
|
if (isProtected)
|
||||||
{
|
{
|
||||||
final Block against = block.getRelative(blockFace);
|
event.setCancelled(true);
|
||||||
storage.unprotectBlock(against);
|
}
|
||||||
}
|
else
|
||||||
}
|
{
|
||||||
}
|
if (type == Material.WALL_SIGN || type == Material.SIGN_POST || type == Material.RAILS || type == Material.POWERED_RAIL || type == Material.DETECTOR_RAIL)
|
||||||
else
|
{
|
||||||
{
|
storage.unprotectBlock(block);
|
||||||
|
if (type == Material.RAILS || type == Material.POWERED_RAIL || type == Material.DETECTOR_RAIL || type == Material.SIGN_POST)
|
||||||
final boolean isProtected = isProtected(block, user);
|
{
|
||||||
if (isProtected)
|
final Block below = block.getRelative(BlockFace.DOWN);
|
||||||
{
|
storage.unprotectBlock(below);
|
||||||
event.setCancelled(true);
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
{
|
for (BlockFace blockFace : faces)
|
||||||
if (type == Material.WALL_SIGN || type == Material.SIGN_POST || type == Material.RAILS || type == Material.POWERED_RAIL || type == Material.DETECTOR_RAIL)
|
{
|
||||||
{
|
final Block against = block.getRelative(blockFace);
|
||||||
storage.unprotectBlock(block);
|
storage.unprotectBlock(against);
|
||||||
if (type == Material.RAILS || type == Material.POWERED_RAIL || type == Material.DETECTOR_RAIL || type == Material.SIGN_POST)
|
}
|
||||||
{
|
}
|
||||||
final Block below = block.getRelative(BlockFace.DOWN);
|
}
|
||||||
storage.unprotectBlock(below);
|
else
|
||||||
}
|
{
|
||||||
else
|
for (BlockFace blockFace : faces)
|
||||||
{
|
{
|
||||||
for (BlockFace blockFace : faces)
|
final Block against = block.getRelative(blockFace);
|
||||||
{
|
storage.unprotectBlock(against);
|
||||||
final Block against = block.getRelative(blockFace);
|
}
|
||||||
storage.unprotectBlock(against);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
for (BlockFace blockFace : faces)
|
public void onBlockPistonExtend(BlockPistonExtendEvent event)
|
||||||
{
|
{
|
||||||
final Block against = block.getRelative(blockFace);
|
for (Block block : event.getBlocks())
|
||||||
storage.unprotectBlock(against);
|
{
|
||||||
}
|
if ((block.getRelative(BlockFace.UP).getType() == Material.RAILS
|
||||||
}
|
|| block.getType() == Material.RAILS
|
||||||
}
|
|| block.getRelative(BlockFace.UP).getType() == Material.POWERED_RAIL
|
||||||
}
|
|| block.getType() == Material.POWERED_RAIL
|
||||||
}
|
|| block.getRelative(BlockFace.UP).getType() == Material.DETECTOR_RAIL
|
||||||
|
|| block.getType() == Material.DETECTOR_RAIL)
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
&& prot.getSettingBool(ProtectConfig.protect_rails))
|
||||||
public void onBlockPistonExtend(BlockPistonExtendEvent event)
|
{
|
||||||
{
|
event.setCancelled(true);
|
||||||
for (Block block : event.getBlocks())
|
return;
|
||||||
{
|
}
|
||||||
if ((block.getRelative(BlockFace.UP).getType() == Material.RAILS
|
if (prot.getSettingBool(ProtectConfig.protect_signs))
|
||||||
|| block.getType() == Material.RAILS
|
{
|
||||||
|| block.getRelative(BlockFace.UP).getType() == Material.POWERED_RAIL
|
for (BlockFace blockFace : faces)
|
||||||
|| block.getType() == Material.POWERED_RAIL
|
{
|
||||||
|| block.getRelative(BlockFace.UP).getType() == Material.DETECTOR_RAIL
|
if (blockFace == BlockFace.DOWN)
|
||||||
|| block.getType() == Material.DETECTOR_RAIL)
|
{
|
||||||
&& prot.getSettingBool(ProtectConfig.protect_rails))
|
continue;
|
||||||
{
|
}
|
||||||
event.setCancelled(true);
|
final Block sign = block.getRelative(blockFace);
|
||||||
return;
|
if ((blockFace == BlockFace.UP || blockFace == BlockFace.SELF)
|
||||||
}
|
&& sign.getType() == Material.SIGN_POST)
|
||||||
if (prot.getSettingBool(ProtectConfig.protect_signs))
|
{
|
||||||
{
|
event.setCancelled(true);
|
||||||
for (BlockFace blockFace : faces)
|
return;
|
||||||
{
|
}
|
||||||
if (blockFace == BlockFace.DOWN)
|
if ((blockFace == BlockFace.NORTH || blockFace == BlockFace.EAST
|
||||||
{
|
|| blockFace == BlockFace.SOUTH || blockFace == BlockFace.WEST
|
||||||
continue;
|
|| blockFace == BlockFace.SELF)
|
||||||
}
|
&& sign.getType() == Material.WALL_SIGN)
|
||||||
final Block sign = block.getRelative(blockFace);
|
{
|
||||||
if ((blockFace == BlockFace.UP || blockFace == BlockFace.SELF)
|
event.setCancelled(true);
|
||||||
&& sign.getType() == Material.SIGN_POST)
|
return;
|
||||||
{
|
}
|
||||||
event.setCancelled(true);
|
}
|
||||||
return;
|
}
|
||||||
}
|
}
|
||||||
if ((blockFace == BlockFace.NORTH || blockFace == BlockFace.EAST
|
}
|
||||||
|| blockFace == BlockFace.SOUTH || blockFace == BlockFace.WEST
|
|
||||||
|| blockFace == BlockFace.SELF)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
&& sign.getType() == Material.WALL_SIGN)
|
public void onBlockPistonRetract(BlockPistonRetractEvent event)
|
||||||
{
|
{
|
||||||
event.setCancelled(true);
|
if (!event.isSticky())
|
||||||
return;
|
{
|
||||||
}
|
return;
|
||||||
}
|
}
|
||||||
}
|
final Block block = event.getRetractLocation().getBlock();
|
||||||
}
|
if ((block.getRelative(BlockFace.UP).getType() == Material.RAILS
|
||||||
}
|
|| block.getType() == Material.RAILS
|
||||||
|
|| block.getRelative(BlockFace.UP).getType() == Material.POWERED_RAIL
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
|| block.getType() == Material.POWERED_RAIL
|
||||||
public void onBlockPistonRetract(BlockPistonRetractEvent event)
|
|| block.getRelative(BlockFace.UP).getType() == Material.DETECTOR_RAIL
|
||||||
{
|
|| block.getType() == Material.DETECTOR_RAIL)
|
||||||
if (!event.isSticky())
|
&& prot.getSettingBool(ProtectConfig.protect_rails))
|
||||||
{
|
{
|
||||||
return;
|
event.setCancelled(true);
|
||||||
}
|
return;
|
||||||
final Block block = event.getRetractLocation().getBlock();
|
}
|
||||||
if ((block.getRelative(BlockFace.UP).getType() == Material.RAILS
|
if (prot.getSettingBool(ProtectConfig.protect_signs))
|
||||||
|| block.getType() == Material.RAILS
|
{
|
||||||
|| block.getRelative(BlockFace.UP).getType() == Material.POWERED_RAIL
|
for (BlockFace blockFace : faces)
|
||||||
|| block.getType() == Material.POWERED_RAIL
|
{
|
||||||
|| block.getRelative(BlockFace.UP).getType() == Material.DETECTOR_RAIL
|
if (blockFace == BlockFace.DOWN)
|
||||||
|| block.getType() == Material.DETECTOR_RAIL)
|
{
|
||||||
&& prot.getSettingBool(ProtectConfig.protect_rails))
|
continue;
|
||||||
{
|
}
|
||||||
event.setCancelled(true);
|
final Block sign = block.getRelative(blockFace);
|
||||||
return;
|
if ((blockFace == BlockFace.UP || blockFace == BlockFace.SELF)
|
||||||
}
|
&& sign.getType() == Material.SIGN_POST)
|
||||||
if (prot.getSettingBool(ProtectConfig.protect_signs))
|
{
|
||||||
{
|
event.setCancelled(true);
|
||||||
for (BlockFace blockFace : faces)
|
return;
|
||||||
{
|
}
|
||||||
if (blockFace == BlockFace.DOWN)
|
if ((blockFace == BlockFace.NORTH || blockFace == BlockFace.EAST
|
||||||
{
|
|| blockFace == BlockFace.SOUTH || blockFace == BlockFace.WEST
|
||||||
continue;
|
|| blockFace == BlockFace.SELF)
|
||||||
}
|
&& sign.getType() == Material.WALL_SIGN)
|
||||||
final Block sign = block.getRelative(blockFace);
|
{
|
||||||
if ((blockFace == BlockFace.UP || blockFace == BlockFace.SELF)
|
event.setCancelled(true);
|
||||||
&& sign.getType() == Material.SIGN_POST)
|
return;
|
||||||
{
|
}
|
||||||
event.setCancelled(true);
|
}
|
||||||
return;
|
}
|
||||||
}
|
}
|
||||||
if ((blockFace == BlockFace.NORTH || blockFace == BlockFace.EAST
|
|
||||||
|| blockFace == BlockFace.SOUTH || blockFace == BlockFace.WEST
|
private boolean isProtected(final Block block, final User user)
|
||||||
|| blockFace == BlockFace.SELF)
|
{
|
||||||
&& sign.getType() == Material.WALL_SIGN)
|
final Material type = block.getType();
|
||||||
{
|
if (prot.getSettingBool(ProtectConfig.protect_signs))
|
||||||
event.setCancelled(true);
|
{
|
||||||
return;
|
if (type == Material.WALL_SIGN || type == Material.SIGN_POST)
|
||||||
}
|
{
|
||||||
}
|
return prot.getStorage().isProtected(block, user.getName());
|
||||||
}
|
}
|
||||||
}
|
if (prot.getSettingBool(ProtectConfig.protect_against_signs))
|
||||||
|
{
|
||||||
private boolean isProtected(final Block block, final User user)
|
final Block up = block.getRelative(BlockFace.UP);
|
||||||
{
|
if (up != null && up.getType() == Material.SIGN_POST)
|
||||||
final Material type = block.getType();
|
{
|
||||||
if (prot.getSettingBool(ProtectConfig.protect_signs))
|
return prot.getStorage().isProtected(block, user.getName());
|
||||||
{
|
}
|
||||||
if (type == Material.WALL_SIGN || type == Material.SIGN_POST)
|
final BlockFace[] directions = new BlockFace[]
|
||||||
{
|
{
|
||||||
return prot.getStorage().isProtected(block, user.getName());
|
BlockFace.NORTH,
|
||||||
}
|
BlockFace.EAST,
|
||||||
if (prot.getSettingBool(ProtectConfig.protect_against_signs))
|
BlockFace.SOUTH,
|
||||||
{
|
BlockFace.WEST
|
||||||
final Block up = block.getRelative(BlockFace.UP);
|
};
|
||||||
if (up != null && up.getType() == Material.SIGN_POST)
|
for (BlockFace blockFace : directions)
|
||||||
{
|
{
|
||||||
return prot.getStorage().isProtected(block, user.getName());
|
final Block signblock = block.getRelative(blockFace);
|
||||||
}
|
if (signblock.getType() == Material.WALL_SIGN)
|
||||||
final BlockFace[] directions = new BlockFace[]
|
{
|
||||||
{
|
final org.bukkit.material.Sign signMat = (org.bukkit.material.Sign)signblock.getState().getData();
|
||||||
BlockFace.NORTH,
|
if (signMat != null && signMat.getFacing() == blockFace)
|
||||||
BlockFace.EAST,
|
{
|
||||||
BlockFace.SOUTH,
|
return prot.getStorage().isProtected(block, user.getName());
|
||||||
BlockFace.WEST
|
}
|
||||||
};
|
}
|
||||||
for (BlockFace blockFace : directions)
|
}
|
||||||
{
|
}
|
||||||
final Block signblock = block.getRelative(blockFace);
|
}
|
||||||
if (signblock.getType() == Material.WALL_SIGN)
|
if (prot.getSettingBool(ProtectConfig.protect_rails))
|
||||||
{
|
{
|
||||||
final org.bukkit.material.Sign signMat = (org.bukkit.material.Sign)signblock.getState().getData();
|
if (type == Material.RAILS || type == Material.POWERED_RAIL || type == Material.DETECTOR_RAIL)
|
||||||
if (signMat != null && signMat.getFacing() == blockFace)
|
{
|
||||||
{
|
return prot.getStorage().isProtected(block, user.getName());
|
||||||
return prot.getStorage().isProtected(block, user.getName());
|
}
|
||||||
}
|
if (prot.getSettingBool(ProtectConfig.protect_below_rails))
|
||||||
}
|
{
|
||||||
}
|
final Block up = block.getRelative(BlockFace.UP);
|
||||||
}
|
if (up != null && (type == Material.RAILS || type == Material.POWERED_RAIL || type == Material.DETECTOR_RAIL))
|
||||||
}
|
{
|
||||||
if (prot.getSettingBool(ProtectConfig.protect_rails))
|
return prot.getStorage().isProtected(block, user.getName());
|
||||||
{
|
}
|
||||||
if (type == Material.RAILS || type == Material.POWERED_RAIL || type == Material.DETECTOR_RAIL)
|
}
|
||||||
{
|
}
|
||||||
return prot.getStorage().isProtected(block, user.getName());
|
return false;
|
||||||
}
|
}
|
||||||
if (prot.getSettingBool(ProtectConfig.protect_below_rails))
|
}
|
||||||
{
|
|
||||||
final Block up = block.getRelative(BlockFace.UP);
|
|
||||||
if (up != null && (type == Material.RAILS || type == Material.POWERED_RAIL || type == Material.DETECTOR_RAIL))
|
|
||||||
{
|
|
||||||
return prot.getStorage().isProtected(block, user.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@@ -1,338 +1,335 @@
|
|||||||
package com.earth2me.essentials.protect;
|
package com.earth2me.essentials.protect;
|
||||||
|
|
||||||
import com.earth2me.essentials.IEssentials;
|
import com.earth2me.essentials.IEssentials;
|
||||||
import com.earth2me.essentials.User;
|
import com.earth2me.essentials.User;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.entity.*;
|
import org.bukkit.entity.*;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.*;
|
import org.bukkit.event.entity.*;
|
||||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||||
import org.bukkit.event.entity.EntityTargetEvent.TargetReason;
|
import org.bukkit.event.entity.EntityTargetEvent.TargetReason;
|
||||||
|
|
||||||
|
|
||||||
public class EssentialsProtectEntityListener implements Listener
|
public class EssentialsProtectEntityListener implements Listener
|
||||||
{
|
{
|
||||||
private final transient IProtect prot;
|
private final IProtect prot;
|
||||||
private final transient IEssentials ess;
|
private final IEssentials ess;
|
||||||
|
|
||||||
public EssentialsProtectEntityListener(final IProtect prot)
|
public EssentialsProtectEntityListener(final IProtect prot)
|
||||||
{
|
{
|
||||||
this.prot = prot;
|
this.prot = prot;
|
||||||
this.ess = prot.getEssentialsConnect().getEssentials();
|
this.ess = prot.getEssentialsConnect().getEssentials();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onEntityDamage(final EntityDamageEvent event)
|
public void onEntityDamage(final EntityDamageEvent event)
|
||||||
{
|
{
|
||||||
final Entity target = event.getEntity();
|
final Entity target = event.getEntity();
|
||||||
|
|
||||||
if (target instanceof Villager && prot.getSettingBool(ProtectConfig.prevent_villager_death))
|
if (target instanceof Villager && prot.getSettingBool(ProtectConfig.prevent_villager_death))
|
||||||
{
|
{
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final User user = ess.getUser(target);
|
final User user = ess.getUser(target);
|
||||||
final DamageCause cause = event.getCause();
|
final DamageCause cause = event.getCause();
|
||||||
|
|
||||||
if (event instanceof EntityDamageByBlockEvent)
|
if (event instanceof EntityDamageByBlockEvent)
|
||||||
{
|
{
|
||||||
if (prot.getSettingBool(ProtectConfig.disable_contactdmg)
|
if (prot.getSettingBool(ProtectConfig.disable_contactdmg)
|
||||||
&& cause == DamageCause.CONTACT
|
&& cause == DamageCause.CONTACT
|
||||||
&& !(target instanceof Player && shouldBeDamaged(user, "contact")))
|
&& !(target instanceof Player && shouldBeDamaged(user, "contact")))
|
||||||
{
|
{
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (prot.getSettingBool(ProtectConfig.disable_lavadmg)
|
if (prot.getSettingBool(ProtectConfig.disable_lavadmg)
|
||||||
&& cause == DamageCause.LAVA
|
&& cause == DamageCause.LAVA
|
||||||
&& !(target instanceof Player && shouldBeDamaged(user, "lava")))
|
&& !(target instanceof Player && shouldBeDamaged(user, "lava")))
|
||||||
{
|
{
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (prot.getSettingBool(ProtectConfig.prevent_tnt_explosion)
|
if (prot.getSettingBool(ProtectConfig.prevent_tnt_explosion)
|
||||||
&& cause == DamageCause.BLOCK_EXPLOSION
|
&& cause == DamageCause.BLOCK_EXPLOSION
|
||||||
&& !(target instanceof Player && shouldBeDamaged(user, "tnt")))
|
&& !(target instanceof Player && shouldBeDamaged(user, "tnt")))
|
||||||
{
|
{
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event instanceof EntityDamageByEntityEvent)
|
if (event instanceof EntityDamageByEntityEvent)
|
||||||
{
|
{
|
||||||
final EntityDamageByEntityEvent edEvent = (EntityDamageByEntityEvent)event;
|
final EntityDamageByEntityEvent edEvent = (EntityDamageByEntityEvent)event;
|
||||||
final Entity eAttack = edEvent.getDamager();
|
final Entity eAttack = edEvent.getDamager();
|
||||||
final User attacker = ess.getUser(eAttack);
|
final User attacker = ess.getUser(eAttack);
|
||||||
|
|
||||||
//Creeper explode prevention
|
//Creeper explode prevention
|
||||||
if (eAttack instanceof Creeper
|
if (eAttack instanceof Creeper
|
||||||
&& (prot.getSettingBool(ProtectConfig.prevent_creeper_explosion)
|
&& (prot.getSettingBool(ProtectConfig.prevent_creeper_explosion)
|
||||||
|| prot.getSettingBool(ProtectConfig.prevent_creeper_playerdmg))
|
|| prot.getSettingBool(ProtectConfig.prevent_creeper_playerdmg))
|
||||||
&& !(target instanceof Player && shouldBeDamaged(user, "creeper")))
|
&& !(target instanceof Player && shouldBeDamaged(user, "creeper")))
|
||||||
{
|
{
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((event.getEntity() instanceof Fireball || event.getEntity() instanceof SmallFireball)
|
if ((event.getEntity() instanceof Fireball || event.getEntity() instanceof SmallFireball)
|
||||||
&& prot.getSettingBool(ProtectConfig.prevent_fireball_playerdmg)
|
&& prot.getSettingBool(ProtectConfig.prevent_fireball_playerdmg)
|
||||||
&& !(target instanceof Player && shouldBeDamaged(user, "fireball")))
|
&& !(target instanceof Player && shouldBeDamaged(user, "fireball")))
|
||||||
{
|
{
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.getEntity() instanceof WitherSkull
|
if (event.getEntity() instanceof WitherSkull
|
||||||
&& prot.getSettingBool(ProtectConfig.prevent_witherskull_playerdmg)
|
&& prot.getSettingBool(ProtectConfig.prevent_witherskull_playerdmg)
|
||||||
&& !(target instanceof Player && shouldBeDamaged(user, "witherskull")))
|
&& !(target instanceof Player && shouldBeDamaged(user, "witherskull")))
|
||||||
{
|
{
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (eAttack instanceof TNTPrimed && prot.getSettingBool(ProtectConfig.prevent_tnt_playerdmg)
|
if (eAttack instanceof TNTPrimed && prot.getSettingBool(ProtectConfig.prevent_tnt_playerdmg)
|
||||||
&& !(target instanceof Player && shouldBeDamaged(user, "tnt")))
|
&& !(target instanceof Player && shouldBeDamaged(user, "tnt")))
|
||||||
{
|
{
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// PVP Settings
|
// PVP Settings
|
||||||
if (target instanceof Player && eAttack instanceof Player
|
if (target instanceof Player && eAttack instanceof Player
|
||||||
&& prot.getSettingBool(ProtectConfig.disable_pvp)
|
&& prot.getSettingBool(ProtectConfig.disable_pvp)
|
||||||
&& (!user.isAuthorized("essentials.protect.pvp") || !attacker.isAuthorized("essentials.protect.pvp")))
|
&& (!user.isAuthorized("essentials.protect.pvp") || !attacker.isAuthorized("essentials.protect.pvp")))
|
||||||
{
|
{
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (edEvent.getDamager() instanceof Projectile
|
if (edEvent.getDamager() instanceof Projectile
|
||||||
&& target instanceof Player
|
&& target instanceof Player
|
||||||
&& ((prot.getSettingBool(ProtectConfig.disable_projectiles) && !shouldBeDamaged(user, "projectiles"))
|
&& ((prot.getSettingBool(ProtectConfig.disable_projectiles) && !shouldBeDamaged(user, "projectiles"))
|
||||||
|| (((Projectile)edEvent.getDamager()).getShooter() instanceof Player
|
|| (((Projectile)edEvent.getDamager()).getShooter() instanceof Player
|
||||||
&& prot.getSettingBool(ProtectConfig.disable_pvp)
|
&& prot.getSettingBool(ProtectConfig.disable_pvp)
|
||||||
&& (!user.isAuthorized("essentials.protect.pvp")
|
&& (!user.isAuthorized("essentials.protect.pvp")
|
||||||
|| !ess.getUser(((Projectile)edEvent.getDamager()).getShooter()).isAuthorized("essentials.protect.pvp")))))
|
|| !ess.getUser(((Projectile)edEvent.getDamager()).getShooter()).isAuthorized("essentials.protect.pvp")))))
|
||||||
{
|
{
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target instanceof Player)
|
if (target instanceof Player)
|
||||||
{
|
{
|
||||||
if (cause == DamageCause.FALL
|
if (cause == DamageCause.FALL
|
||||||
&& prot.getSettingBool(ProtectConfig.disable_fall)
|
&& prot.getSettingBool(ProtectConfig.disable_fall)
|
||||||
&& !shouldBeDamaged(user, "fall"))
|
&& !shouldBeDamaged(user, "fall"))
|
||||||
{
|
{
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cause == DamageCause.SUFFOCATION
|
if (cause == DamageCause.SUFFOCATION
|
||||||
&& prot.getSettingBool(ProtectConfig.disable_suffocate)
|
&& prot.getSettingBool(ProtectConfig.disable_suffocate)
|
||||||
&& !shouldBeDamaged(user, "suffocation"))
|
&& !shouldBeDamaged(user, "suffocation"))
|
||||||
{
|
{
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ((cause == DamageCause.FIRE || cause == DamageCause.FIRE_TICK)
|
if ((cause == DamageCause.FIRE || cause == DamageCause.FIRE_TICK)
|
||||||
&& prot.getSettingBool(ProtectConfig.disable_firedmg)
|
&& prot.getSettingBool(ProtectConfig.disable_firedmg)
|
||||||
&& !shouldBeDamaged(user, "fire"))
|
&& !shouldBeDamaged(user, "fire"))
|
||||||
{
|
{
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (cause == DamageCause.DROWNING
|
if (cause == DamageCause.DROWNING
|
||||||
&& prot.getSettingBool(ProtectConfig.disable_drown)
|
&& prot.getSettingBool(ProtectConfig.disable_drown)
|
||||||
&& !shouldBeDamaged(user, "drowning"))
|
&& !shouldBeDamaged(user, "drowning"))
|
||||||
{
|
{
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (cause == DamageCause.LIGHTNING
|
if (cause == DamageCause.LIGHTNING
|
||||||
&& prot.getSettingBool(ProtectConfig.disable_lightning)
|
&& prot.getSettingBool(ProtectConfig.disable_lightning)
|
||||||
&& !shouldBeDamaged(user, "lightning"))
|
&& !shouldBeDamaged(user, "lightning"))
|
||||||
{
|
{
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (cause == DamageCause.WITHER
|
if (cause == DamageCause.WITHER
|
||||||
&& prot.getSettingBool(ProtectConfig.disable_wither)
|
&& prot.getSettingBool(ProtectConfig.disable_wither)
|
||||||
&& !shouldBeDamaged(user, "wither"))
|
&& !shouldBeDamaged(user, "wither"))
|
||||||
{
|
{
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
private boolean shouldBeDamaged(final User user, final String type)
|
||||||
private boolean shouldBeDamaged(final User user, final String type)
|
{
|
||||||
{
|
return (user.isAuthorized("essentials.protect.damage.".concat(type))
|
||||||
return (user.isAuthorized("essentials.protect.damage.".concat(type))
|
&& !user.isAuthorized("essentials.protect.damage.disable"));
|
||||||
&& !user.isAuthorized("essentials.protect.damage.disable"));
|
}
|
||||||
}
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
public void onEntityExplode(final EntityExplodeEvent event)
|
||||||
public void onEntityExplode(final EntityExplodeEvent event)
|
{
|
||||||
{
|
if (event.getEntity() == null)
|
||||||
if (event.getEntity() == null)
|
{
|
||||||
{
|
return;
|
||||||
return;
|
}
|
||||||
}
|
final int maxHeight = ess.getSettings().getProtectCreeperMaxHeight();
|
||||||
final int maxHeight = ess.getSettings().getProtectCreeperMaxHeight();
|
|
||||||
|
if (event.getEntity() instanceof EnderDragon
|
||||||
if (event.getEntity() instanceof EnderDragon
|
&& prot.getSettingBool(ProtectConfig.prevent_enderdragon_blockdmg))
|
||||||
&& prot.getSettingBool(ProtectConfig.prevent_enderdragon_blockdmg))
|
{
|
||||||
{
|
event.setCancelled(true);
|
||||||
event.setCancelled(true);
|
if (prot.getSettingBool(ProtectConfig.enderdragon_fakeexplosions))
|
||||||
if (prot.getSettingBool(ProtectConfig.enderdragon_fakeexplosions))
|
{
|
||||||
{
|
event.getLocation().getWorld().createExplosion(event.getLocation(), 0F);
|
||||||
event.getLocation().getWorld().createExplosion(event.getLocation(), 0F);
|
}
|
||||||
}
|
return;
|
||||||
return;
|
}
|
||||||
}
|
if (event.getEntity() instanceof Wither
|
||||||
if (event.getEntity() instanceof Wither
|
&& prot.getSettingBool(ProtectConfig.prevent_wither_spawnexplosion))
|
||||||
&& prot.getSettingBool(ProtectConfig.prevent_wither_spawnexplosion))
|
{
|
||||||
{
|
event.setCancelled(true);
|
||||||
event.setCancelled(true);
|
return;
|
||||||
return;
|
}
|
||||||
}
|
else if (event.getEntity() instanceof Creeper
|
||||||
else if (event.getEntity() instanceof Creeper
|
&& (prot.getSettingBool(ProtectConfig.prevent_creeper_explosion)
|
||||||
&& (prot.getSettingBool(ProtectConfig.prevent_creeper_explosion)
|
|| prot.getSettingBool(ProtectConfig.prevent_creeper_blockdmg)
|
||||||
|| prot.getSettingBool(ProtectConfig.prevent_creeper_blockdmg)
|
|| (maxHeight >= 0 && event.getLocation().getBlockY() > maxHeight)))
|
||||||
|| (maxHeight >= 0 && event.getLocation().getBlockY() > maxHeight)))
|
{
|
||||||
{
|
//Nicccccccccce plaaacccccccccce..
|
||||||
//Nicccccccccce plaaacccccccccce..
|
event.setCancelled(true);
|
||||||
event.setCancelled(true);
|
event.getLocation().getWorld().createExplosion(event.getLocation(), 0F);
|
||||||
event.getLocation().getWorld().createExplosion(event.getLocation(), 0F);
|
return;
|
||||||
return;
|
}
|
||||||
}
|
else if (event.getEntity() instanceof TNTPrimed
|
||||||
else if (event.getEntity() instanceof TNTPrimed
|
&& prot.getSettingBool(ProtectConfig.prevent_tnt_explosion))
|
||||||
&& prot.getSettingBool(ProtectConfig.prevent_tnt_explosion))
|
{
|
||||||
{
|
event.setCancelled(true);
|
||||||
event.setCancelled(true);
|
return;
|
||||||
return;
|
}
|
||||||
}
|
else if ((event.getEntity() instanceof Fireball || event.getEntity() instanceof SmallFireball)
|
||||||
else if ((event.getEntity() instanceof Fireball || event.getEntity() instanceof SmallFireball)
|
&& prot.getSettingBool(ProtectConfig.prevent_fireball_explosion))
|
||||||
&& prot.getSettingBool(ProtectConfig.prevent_fireball_explosion))
|
{
|
||||||
{
|
event.setCancelled(true);
|
||||||
event.setCancelled(true);
|
return;
|
||||||
return;
|
}
|
||||||
}
|
else if ((event.getEntity() instanceof WitherSkull)
|
||||||
else if ((event.getEntity() instanceof WitherSkull)
|
&& prot.getSettingBool(ProtectConfig.prevent_witherskull_explosion))
|
||||||
&& prot.getSettingBool(ProtectConfig.prevent_witherskull_explosion))
|
{
|
||||||
{
|
event.setCancelled(true);
|
||||||
event.setCancelled(true);
|
return;
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
// This code will prevent explosions near protected rails, signs or protected chests
|
||||||
// This code will prevent explosions near protected rails, signs or protected chests
|
// TODO: Use protect db instead of this code
|
||||||
// TODO: Use protect db instead of this code
|
|
||||||
|
for (Block block : event.blockList())
|
||||||
for (Block block : event.blockList())
|
{
|
||||||
{
|
if ((block.getRelative(BlockFace.UP).getType() == Material.RAILS
|
||||||
if ((block.getRelative(BlockFace.UP).getType() == Material.RAILS
|
|| block.getType() == Material.RAILS
|
||||||
|| block.getType() == Material.RAILS
|
|| block.getRelative(BlockFace.UP).getType() == Material.POWERED_RAIL
|
||||||
|| block.getRelative(BlockFace.UP).getType() == Material.POWERED_RAIL
|
|| block.getType() == Material.POWERED_RAIL
|
||||||
|| block.getType() == Material.POWERED_RAIL
|
|| block.getRelative(BlockFace.UP).getType() == Material.DETECTOR_RAIL
|
||||||
|| block.getRelative(BlockFace.UP).getType() == Material.DETECTOR_RAIL
|
|| block.getType() == Material.DETECTOR_RAIL)
|
||||||
|| block.getType() == Material.DETECTOR_RAIL)
|
&& prot.getSettingBool(ProtectConfig.protect_rails))
|
||||||
&& prot.getSettingBool(ProtectConfig.protect_rails))
|
{
|
||||||
{
|
event.setCancelled(true);
|
||||||
event.setCancelled(true);
|
return;
|
||||||
return;
|
}
|
||||||
}
|
if ((block.getType() == Material.WALL_SIGN
|
||||||
if ((block.getType() == Material.WALL_SIGN
|
|| block.getRelative(BlockFace.NORTH).getType() == Material.WALL_SIGN
|
||||||
|| block.getRelative(BlockFace.NORTH).getType() == Material.WALL_SIGN
|
|| block.getRelative(BlockFace.EAST).getType() == Material.WALL_SIGN
|
||||||
|| block.getRelative(BlockFace.EAST).getType() == Material.WALL_SIGN
|
|| block.getRelative(BlockFace.SOUTH).getType() == Material.WALL_SIGN
|
||||||
|| block.getRelative(BlockFace.SOUTH).getType() == Material.WALL_SIGN
|
|| block.getRelative(BlockFace.WEST).getType() == Material.WALL_SIGN
|
||||||
|| block.getRelative(BlockFace.WEST).getType() == Material.WALL_SIGN
|
|| block.getType() == Material.SIGN_POST
|
||||||
|| block.getType() == Material.SIGN_POST
|
|| block.getRelative(BlockFace.UP).getType() == Material.SIGN_POST)
|
||||||
|| block.getRelative(BlockFace.UP).getType() == Material.SIGN_POST)
|
&& prot.getSettingBool(ProtectConfig.protect_signs))
|
||||||
&& prot.getSettingBool(ProtectConfig.protect_signs))
|
{
|
||||||
{
|
event.setCancelled(true);
|
||||||
event.setCancelled(true);
|
return;
|
||||||
return;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
public void onCreatureSpawn(final CreatureSpawnEvent event)
|
||||||
public void onCreatureSpawn(final CreatureSpawnEvent event)
|
{
|
||||||
{
|
if (event.getEntity() instanceof Player)
|
||||||
if (event.getEntity() instanceof Player)
|
{
|
||||||
{
|
return;
|
||||||
return;
|
}
|
||||||
}
|
final EntityType creature = event.getEntityType();
|
||||||
final EntityType creature = event.getEntityType();
|
if (creature == null)
|
||||||
if (creature == null)
|
{
|
||||||
{
|
return;
|
||||||
return;
|
}
|
||||||
}
|
final String creatureName = creature.toString().toLowerCase(Locale.ENGLISH);
|
||||||
final String creatureName = creature.toString().toLowerCase(Locale.ENGLISH);
|
if (creatureName == null || creatureName.isEmpty())
|
||||||
if (creatureName == null || creatureName.isEmpty())
|
{
|
||||||
{
|
return;
|
||||||
return;
|
}
|
||||||
}
|
if (ess.getSettings().getProtectPreventSpawn(creatureName))
|
||||||
if (ess.getSettings().getProtectPreventSpawn(creatureName))
|
{
|
||||||
{
|
event.setCancelled(true);
|
||||||
event.setCancelled(true);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
public void onEntityTarget(final EntityTargetEvent event)
|
||||||
public void onEntityTarget(final EntityTargetEvent event)
|
{
|
||||||
{
|
if (!(event.getTarget() instanceof Player))
|
||||||
if (!(event.getTarget() instanceof Player))
|
{
|
||||||
{
|
return;
|
||||||
return;
|
}
|
||||||
}
|
final User user = ess.getUser(event.getTarget());
|
||||||
final User user = ess.getUser(event.getTarget());
|
if ((event.getReason() == TargetReason.CLOSEST_PLAYER
|
||||||
if ((event.getReason() == TargetReason.CLOSEST_PLAYER
|
|| event.getReason() == TargetReason.TARGET_ATTACKED_ENTITY
|
||||||
|| event.getReason() == TargetReason.TARGET_ATTACKED_ENTITY
|
|| event.getReason() == TargetReason.PIG_ZOMBIE_TARGET
|
||||||
|| event.getReason() == TargetReason.PIG_ZOMBIE_TARGET
|
|| event.getReason() == TargetReason.RANDOM_TARGET
|
||||||
|| event.getReason() == TargetReason.RANDOM_TARGET
|
|| event.getReason() == TargetReason.DEFEND_VILLAGE
|
||||||
|| event.getReason() == TargetReason.DEFEND_VILLAGE
|
|| event.getReason() == TargetReason.TARGET_ATTACKED_OWNER
|
||||||
|| event.getReason() == TargetReason.TARGET_ATTACKED_OWNER
|
|| event.getReason() == TargetReason.OWNER_ATTACKED_TARGET)
|
||||||
|| event.getReason() == TargetReason.OWNER_ATTACKED_TARGET)
|
&& prot.getSettingBool(ProtectConfig.prevent_entitytarget)
|
||||||
&& prot.getSettingBool(ProtectConfig.prevent_entitytarget)
|
&& !user.isAuthorized("essentials.protect.entitytarget.bypass"))
|
||||||
&& !user.isAuthorized("essentials.protect.entitytarget.bypass"))
|
{
|
||||||
{
|
event.setCancelled(true);
|
||||||
event.setCancelled(true);
|
}
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
}
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onExplosionPrime(ExplosionPrimeEvent event)
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
{
|
||||||
public void onExplosionPrime(ExplosionPrimeEvent event)
|
if ((event.getEntity() instanceof Fireball || event.getEntity() instanceof SmallFireball)
|
||||||
{
|
&& prot.getSettingBool(ProtectConfig.prevent_fireball_fire))
|
||||||
if ((event.getEntity() instanceof Fireball || event.getEntity() instanceof SmallFireball)
|
{
|
||||||
&& prot.getSettingBool(ProtectConfig.prevent_fireball_fire))
|
event.setFire(false);
|
||||||
{
|
}
|
||||||
event.setFire(false);
|
}
|
||||||
}
|
|
||||||
}
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onEntityChangeBlock(EntityChangeBlockEvent event)
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
{
|
||||||
public void onEntityChangeBlock(EntityChangeBlockEvent event)
|
if (event.getEntityType() == EntityType.ENDERMAN && prot.getSettingBool(ProtectConfig.prevent_enderman_pickup))
|
||||||
{
|
{
|
||||||
if (event.getEntityType() == EntityType.ENDERMAN && prot.getSettingBool(ProtectConfig.prevent_enderman_pickup))
|
event.setCancelled(true);
|
||||||
{
|
return;
|
||||||
event.setCancelled(true);
|
}
|
||||||
return;
|
if (event.getEntityType() == EntityType.WITHER && prot.getSettingBool(ProtectConfig.prevent_wither_blockreplace))
|
||||||
}
|
{
|
||||||
if (event.getEntityType() == EntityType.WITHER && prot.getSettingBool(ProtectConfig.prevent_wither_blockreplace))
|
event.setCancelled(true);
|
||||||
{
|
}
|
||||||
event.setCancelled(true);
|
}
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@@ -1,52 +1,52 @@
|
|||||||
package com.earth2me.essentials.protect;
|
package com.earth2me.essentials.protect;
|
||||||
|
|
||||||
import static com.earth2me.essentials.I18n._;
|
import static com.earth2me.essentials.I18n._;
|
||||||
import com.earth2me.essentials.IEssentials;
|
import com.earth2me.essentials.IEssentials;
|
||||||
import com.earth2me.essentials.User;
|
import com.earth2me.essentials.User;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
|
||||||
|
|
||||||
public class EssentialsProtectPlayerListener implements Listener
|
public class EssentialsProtectPlayerListener implements Listener
|
||||||
{
|
{
|
||||||
private final transient IProtect prot;
|
private final IProtect prot;
|
||||||
private final transient IEssentials ess;
|
private final IEssentials ess;
|
||||||
|
|
||||||
public EssentialsProtectPlayerListener(final IProtect prot)
|
public EssentialsProtectPlayerListener(final IProtect prot)
|
||||||
{
|
{
|
||||||
this.prot = prot;
|
this.prot = prot;
|
||||||
this.ess = prot.getEssentialsConnect().getEssentials();
|
this.ess = prot.getEssentialsConnect().getEssentials();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOW)
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
public void onPlayerInteract(final PlayerInteractEvent event)
|
public void onPlayerInteract(final PlayerInteractEvent event)
|
||||||
{
|
{
|
||||||
// Do not return if cancelled, because the interact event has 2 cancelled states.
|
// Do not return if cancelled, because the interact event has 2 cancelled states.
|
||||||
final User user = ess.getUser(event.getPlayer());
|
final User user = ess.getUser(event.getPlayer());
|
||||||
|
|
||||||
if (user.isAuthorized("essentials.protect.ownerinfo") && event.getAction() == Action.RIGHT_CLICK_BLOCK)
|
if (user.isAuthorized("essentials.protect.ownerinfo") && event.getAction() == Action.RIGHT_CLICK_BLOCK)
|
||||||
{
|
{
|
||||||
final StringBuilder stringBuilder = new StringBuilder();
|
final StringBuilder stringBuilder = new StringBuilder();
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
final Block blockClicked = event.getClickedBlock();
|
final Block blockClicked = event.getClickedBlock();
|
||||||
for (String owner : prot.getStorage().getOwners(blockClicked))
|
for (String owner : prot.getStorage().getOwners(blockClicked))
|
||||||
{
|
{
|
||||||
if (!first)
|
if (!first)
|
||||||
{
|
{
|
||||||
stringBuilder.append(", ");
|
stringBuilder.append(", ");
|
||||||
}
|
}
|
||||||
first = false;
|
first = false;
|
||||||
stringBuilder.append(owner);
|
stringBuilder.append(owner);
|
||||||
}
|
}
|
||||||
final String ownerNames = stringBuilder.toString();
|
final String ownerNames = stringBuilder.toString();
|
||||||
if (ownerNames != null && !ownerNames.isEmpty())
|
if (ownerNames != null && !ownerNames.isEmpty())
|
||||||
{
|
{
|
||||||
user.sendMessage(_("protectionOwner", ownerNames));
|
user.sendMessage(_("protectionOwner", ownerNames));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,49 +1,48 @@
|
|||||||
package com.earth2me.essentials.protect;
|
package com.earth2me.essentials.protect;
|
||||||
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.weather.LightningStrikeEvent;
|
import org.bukkit.event.weather.LightningStrikeEvent;
|
||||||
import org.bukkit.event.weather.ThunderChangeEvent;
|
import org.bukkit.event.weather.ThunderChangeEvent;
|
||||||
import org.bukkit.event.weather.WeatherChangeEvent;
|
import org.bukkit.event.weather.WeatherChangeEvent;
|
||||||
|
|
||||||
|
|
||||||
public class EssentialsProtectWeatherListener implements Listener
|
public class EssentialsProtectWeatherListener implements Listener
|
||||||
{
|
{
|
||||||
private final transient IProtect prot;
|
private final IProtect prot;
|
||||||
|
|
||||||
public EssentialsProtectWeatherListener(final IProtect prot)
|
public EssentialsProtectWeatherListener(final IProtect prot)
|
||||||
{
|
{
|
||||||
this.prot = prot;
|
this.prot = prot;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onWeatherChange(final WeatherChangeEvent event)
|
public void onWeatherChange(final WeatherChangeEvent event)
|
||||||
{
|
{
|
||||||
if (prot.getSettingBool(ProtectConfig.disable_weather_storm)
|
if (prot.getSettingBool(ProtectConfig.disable_weather_storm)
|
||||||
&& event.toWeatherState())
|
&& event.toWeatherState())
|
||||||
{
|
{
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
public void onLightningStrike(final LightningStrikeEvent event)
|
||||||
public void onLightningStrike(final LightningStrikeEvent event)
|
{
|
||||||
{
|
if (prot.getSettingBool(ProtectConfig.disable_weather_lightning))
|
||||||
if (prot.getSettingBool(ProtectConfig.disable_weather_lightning))
|
{
|
||||||
{
|
event.setCancelled(true);
|
||||||
event.setCancelled(true);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
public void onThunderChange(final ThunderChangeEvent event)
|
||||||
public void onThunderChange(final ThunderChangeEvent event)
|
{
|
||||||
{
|
if (prot.getSettingBool(ProtectConfig.disable_weather_thunder)
|
||||||
if (prot.getSettingBool(ProtectConfig.disable_weather_thunder)
|
&& event.toThunderState())
|
||||||
&& event.toThunderState())
|
{
|
||||||
{
|
event.setCancelled(true);
|
||||||
event.setCancelled(true);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@@ -1,426 +1,426 @@
|
|||||||
package com.earth2me.essentials.protect.data;
|
package com.earth2me.essentials.protect.data;
|
||||||
|
|
||||||
import com.mchange.v2.c3p0.ComboPooledDataSource;
|
import com.mchange.v2.c3p0.ComboPooledDataSource;
|
||||||
import java.beans.PropertyVetoException;
|
import java.beans.PropertyVetoException;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
|
||||||
|
|
||||||
public abstract class ProtectedBlockJDBC implements IProtectedBlock
|
public abstract class ProtectedBlockJDBC implements IProtectedBlock
|
||||||
{
|
{
|
||||||
protected static final Logger LOGGER = Logger.getLogger("Minecraft");
|
protected static final Logger LOGGER = Logger.getLogger("Minecraft");
|
||||||
protected final transient ComboPooledDataSource cpds;
|
protected final ComboPooledDataSource cpds;
|
||||||
|
protected abstract PreparedStatement getStatementCreateTable(Connection conn) throws SQLException;
|
||||||
protected abstract PreparedStatement getStatementCreateTable(Connection conn) throws SQLException;
|
protected abstract PreparedStatement getStatementUpdateFrom2_0Table(Connection conn) throws SQLException;
|
||||||
|
protected abstract PreparedStatement getStatementDeleteAll(Connection conn) throws SQLException;
|
||||||
protected abstract PreparedStatement getStatementUpdateFrom2_0Table(Connection conn) throws SQLException;
|
protected abstract PreparedStatement getStatementInsert(Connection conn, String world, int x, int y, int z, String playerName) throws SQLException;
|
||||||
|
protected abstract PreparedStatement getStatementPlayerCountByLocation(Connection conn, String world, int x, int y, int z, String playerName) throws SQLException;
|
||||||
protected abstract PreparedStatement getStatementDeleteAll(Connection conn) throws SQLException;
|
protected abstract PreparedStatement getStatementPlayersByLocation(Connection conn, String name, int x, int y, int z) throws SQLException;
|
||||||
|
protected abstract PreparedStatement getStatementDeleteByLocation(Connection conn, String world, int x, int y, int z) throws SQLException;
|
||||||
protected abstract PreparedStatement getStatementInsert(Connection conn, String world, int x, int y, int z, String playerName) throws SQLException;
|
protected abstract PreparedStatement getStatementAllBlocks(Connection conn) throws SQLException;
|
||||||
|
|
||||||
protected abstract PreparedStatement getStatementPlayerCountByLocation(Connection conn, String world, int x, int y, int z, String playerName) throws SQLException;
|
public ProtectedBlockJDBC(String driver, String url) throws PropertyVetoException
|
||||||
|
{
|
||||||
protected abstract PreparedStatement getStatementPlayersByLocation(Connection conn, String name, int x, int y, int z) throws SQLException;
|
this(driver, url, null, null);
|
||||||
|
}
|
||||||
protected abstract PreparedStatement getStatementDeleteByLocation(Connection conn, String world, int x, int y, int z) throws SQLException;
|
|
||||||
|
public ProtectedBlockJDBC(String driver, String url, String username, String password) throws PropertyVetoException
|
||||||
protected abstract PreparedStatement getStatementAllBlocks(Connection conn) throws SQLException;
|
{
|
||||||
|
cpds = new ComboPooledDataSource();
|
||||||
public ProtectedBlockJDBC(String driver, String url) throws PropertyVetoException
|
cpds.setDriverClass(driver);
|
||||||
{
|
cpds.setJdbcUrl(url);
|
||||||
this(driver, url, null, null);
|
if (username != null)
|
||||||
}
|
{
|
||||||
|
cpds.setUser(username);
|
||||||
public ProtectedBlockJDBC(String driver, String url, String username, String password) throws PropertyVetoException
|
cpds.setPassword(password);
|
||||||
{
|
}
|
||||||
cpds = new ComboPooledDataSource();
|
cpds.setMaxStatements(20);
|
||||||
cpds.setDriverClass(driver);
|
createAndConvertTable();
|
||||||
cpds.setJdbcUrl(url);
|
}
|
||||||
if (username != null)
|
|
||||||
{
|
private void createAndConvertTable()
|
||||||
cpds.setUser(username);
|
{
|
||||||
cpds.setPassword(password);
|
Connection conn = null;
|
||||||
}
|
PreparedStatement ps = null;
|
||||||
cpds.setMaxStatements(20);
|
try
|
||||||
createAndConvertTable();
|
{
|
||||||
}
|
conn = cpds.getConnection();
|
||||||
|
ps = getStatementCreateTable(conn);
|
||||||
private void createAndConvertTable()
|
ps.execute();
|
||||||
{
|
ps.close();
|
||||||
Connection conn = null;
|
ps = getStatementUpdateFrom2_0Table(conn);
|
||||||
PreparedStatement ps = null;
|
ps.execute();
|
||||||
try
|
}
|
||||||
{
|
catch (SQLException ex)
|
||||||
conn = cpds.getConnection();
|
{
|
||||||
ps = getStatementCreateTable(conn);
|
LOGGER.log(Level.SEVERE, null, ex);
|
||||||
ps.execute();
|
}
|
||||||
ps.close();
|
finally
|
||||||
ps = getStatementUpdateFrom2_0Table(conn);
|
{
|
||||||
ps.execute();
|
if (ps != null)
|
||||||
}
|
{
|
||||||
catch (SQLException ex)
|
try
|
||||||
{
|
{
|
||||||
LOGGER.log(Level.SEVERE, null, ex);
|
ps.close();
|
||||||
}
|
}
|
||||||
finally
|
catch (SQLException ex)
|
||||||
{
|
{
|
||||||
if (ps != null)
|
LOGGER.log(Level.SEVERE, null, ex);
|
||||||
{
|
}
|
||||||
try
|
}
|
||||||
{
|
if (conn != null)
|
||||||
ps.close();
|
{
|
||||||
}
|
try
|
||||||
catch (SQLException ex)
|
{
|
||||||
{
|
conn.close();
|
||||||
LOGGER.log(Level.SEVERE, null, ex);
|
}
|
||||||
}
|
catch (SQLException ex)
|
||||||
}
|
{
|
||||||
if (conn != null)
|
LOGGER.log(Level.SEVERE, null, ex);
|
||||||
{
|
}
|
||||||
try
|
}
|
||||||
{
|
}
|
||||||
conn.close();
|
}
|
||||||
}
|
|
||||||
catch (SQLException ex)
|
@Override
|
||||||
{
|
public void clearProtections()
|
||||||
LOGGER.log(Level.SEVERE, null, ex);
|
{
|
||||||
}
|
Connection conn = null;
|
||||||
}
|
PreparedStatement ps = null;
|
||||||
}
|
try
|
||||||
}
|
{
|
||||||
|
conn = cpds.getConnection();
|
||||||
public void clearProtections()
|
ps = getStatementDeleteAll(conn);
|
||||||
{
|
ps.executeUpdate();
|
||||||
Connection conn = null;
|
}
|
||||||
PreparedStatement ps = null;
|
catch (SQLException ex)
|
||||||
try
|
{
|
||||||
{
|
LOGGER.log(Level.SEVERE, null, ex);
|
||||||
conn = cpds.getConnection();
|
}
|
||||||
ps = getStatementDeleteAll(conn);
|
finally
|
||||||
ps.executeUpdate();
|
{
|
||||||
}
|
if (ps != null)
|
||||||
catch (SQLException ex)
|
{
|
||||||
{
|
try
|
||||||
LOGGER.log(Level.SEVERE, null, ex);
|
{
|
||||||
}
|
ps.close();
|
||||||
finally
|
}
|
||||||
{
|
catch (SQLException ex)
|
||||||
if (ps != null)
|
{
|
||||||
{
|
LOGGER.log(Level.SEVERE, null, ex);
|
||||||
try
|
}
|
||||||
{
|
}
|
||||||
ps.close();
|
if (conn != null)
|
||||||
}
|
{
|
||||||
catch (SQLException ex)
|
try
|
||||||
{
|
{
|
||||||
LOGGER.log(Level.SEVERE, null, ex);
|
conn.close();
|
||||||
}
|
}
|
||||||
}
|
catch (SQLException ex)
|
||||||
if (conn != null)
|
{
|
||||||
{
|
LOGGER.log(Level.SEVERE, null, ex);
|
||||||
try
|
}
|
||||||
{
|
}
|
||||||
conn.close();
|
}
|
||||||
}
|
}
|
||||||
catch (SQLException ex)
|
|
||||||
{
|
@Override
|
||||||
LOGGER.log(Level.SEVERE, null, ex);
|
public void importProtections(List<OwnedBlock> blocks)
|
||||||
}
|
{
|
||||||
}
|
for (OwnedBlock ownedBlock : blocks)
|
||||||
}
|
{
|
||||||
}
|
if (ownedBlock.playerName == null)
|
||||||
|
{
|
||||||
public void importProtections(List<OwnedBlock> blocks)
|
continue;
|
||||||
{
|
}
|
||||||
for (OwnedBlock ownedBlock : blocks)
|
protectBlock(ownedBlock.world, ownedBlock.x, ownedBlock.y, ownedBlock.z, ownedBlock.playerName);
|
||||||
{
|
}
|
||||||
if (ownedBlock.playerName == null)
|
}
|
||||||
{
|
|
||||||
continue;
|
@Override
|
||||||
}
|
public List<OwnedBlock> exportProtections()
|
||||||
protectBlock(ownedBlock.world, ownedBlock.x, ownedBlock.y, ownedBlock.z, ownedBlock.playerName);
|
{
|
||||||
}
|
Connection conn = null;
|
||||||
}
|
PreparedStatement ps = null;
|
||||||
|
ResultSet rs = null;
|
||||||
public List<OwnedBlock> exportProtections()
|
List<OwnedBlock> blocks = new ArrayList<OwnedBlock>();
|
||||||
{
|
try
|
||||||
Connection conn = null;
|
{
|
||||||
PreparedStatement ps = null;
|
conn = cpds.getConnection();
|
||||||
ResultSet rs = null;
|
ps = getStatementAllBlocks(conn);
|
||||||
List<OwnedBlock> blocks = new ArrayList<OwnedBlock>();
|
rs = ps.executeQuery();
|
||||||
try
|
while (rs.next())
|
||||||
{
|
{
|
||||||
conn = cpds.getConnection();
|
OwnedBlock ob = new OwnedBlock(
|
||||||
ps = getStatementAllBlocks(conn);
|
rs.getInt(2),
|
||||||
rs = ps.executeQuery();
|
rs.getInt(3),
|
||||||
while (rs.next())
|
rs.getInt(4),
|
||||||
{
|
rs.getString(1),
|
||||||
OwnedBlock ob = new OwnedBlock(
|
rs.getString(5));
|
||||||
rs.getInt(2),
|
blocks.add(ob);
|
||||||
rs.getInt(3),
|
}
|
||||||
rs.getInt(4),
|
return blocks;
|
||||||
rs.getString(1),
|
}
|
||||||
rs.getString(5));
|
catch (SQLException ex)
|
||||||
blocks.add(ob);
|
{
|
||||||
}
|
LOGGER.log(Level.SEVERE, null, ex);
|
||||||
return blocks;
|
return blocks;
|
||||||
}
|
}
|
||||||
catch (SQLException ex)
|
finally
|
||||||
{
|
{
|
||||||
LOGGER.log(Level.SEVERE, null, ex);
|
if (rs != null)
|
||||||
return blocks;
|
{
|
||||||
}
|
try
|
||||||
finally
|
{
|
||||||
{
|
rs.close();
|
||||||
if (rs != null)
|
}
|
||||||
{
|
catch (SQLException ex)
|
||||||
try
|
{
|
||||||
{
|
LOGGER.log(Level.SEVERE, null, ex);
|
||||||
rs.close();
|
}
|
||||||
}
|
}
|
||||||
catch (SQLException ex)
|
if (ps != null)
|
||||||
{
|
{
|
||||||
LOGGER.log(Level.SEVERE, null, ex);
|
try
|
||||||
}
|
{
|
||||||
}
|
ps.close();
|
||||||
if (ps != null)
|
}
|
||||||
{
|
catch (SQLException ex)
|
||||||
try
|
{
|
||||||
{
|
LOGGER.log(Level.SEVERE, null, ex);
|
||||||
ps.close();
|
}
|
||||||
}
|
}
|
||||||
catch (SQLException ex)
|
if (conn != null)
|
||||||
{
|
{
|
||||||
LOGGER.log(Level.SEVERE, null, ex);
|
try
|
||||||
}
|
{
|
||||||
}
|
conn.close();
|
||||||
if (conn != null)
|
}
|
||||||
{
|
catch (SQLException ex)
|
||||||
try
|
{
|
||||||
{
|
LOGGER.log(Level.SEVERE, null, ex);
|
||||||
conn.close();
|
}
|
||||||
}
|
}
|
||||||
catch (SQLException ex)
|
}
|
||||||
{
|
}
|
||||||
LOGGER.log(Level.SEVERE, null, ex);
|
|
||||||
}
|
@Override
|
||||||
}
|
public void protectBlock(Block block, String playerName)
|
||||||
}
|
{
|
||||||
}
|
protectBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), playerName);
|
||||||
|
}
|
||||||
public void protectBlock(Block block, String playerName)
|
|
||||||
{
|
private void protectBlock(String world, int x, int y, int z, String playerName)
|
||||||
protectBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), playerName);
|
{
|
||||||
}
|
Connection conn = null;
|
||||||
|
PreparedStatement ps = null;
|
||||||
private void protectBlock(String world, int x, int y, int z, String playerName)
|
try
|
||||||
{
|
{
|
||||||
Connection conn = null;
|
conn = cpds.getConnection();
|
||||||
PreparedStatement ps = null;
|
ps = getStatementInsert(conn, world, x, y, z, playerName);
|
||||||
try
|
ps.executeUpdate();
|
||||||
{
|
}
|
||||||
conn = cpds.getConnection();
|
catch (SQLException ex)
|
||||||
ps = getStatementInsert(conn, world, x, y, z, playerName);
|
{
|
||||||
ps.executeUpdate();
|
LOGGER.log(Level.SEVERE, null, ex);
|
||||||
}
|
}
|
||||||
catch (SQLException ex)
|
finally
|
||||||
{
|
{
|
||||||
LOGGER.log(Level.SEVERE, null, ex);
|
if (ps != null)
|
||||||
}
|
{
|
||||||
finally
|
try
|
||||||
{
|
{
|
||||||
if (ps != null)
|
ps.close();
|
||||||
{
|
}
|
||||||
try
|
catch (SQLException ex)
|
||||||
{
|
{
|
||||||
ps.close();
|
LOGGER.log(Level.SEVERE, null, ex);
|
||||||
}
|
}
|
||||||
catch (SQLException ex)
|
}
|
||||||
{
|
if (conn != null)
|
||||||
LOGGER.log(Level.SEVERE, null, ex);
|
{
|
||||||
}
|
try
|
||||||
}
|
{
|
||||||
if (conn != null)
|
conn.close();
|
||||||
{
|
}
|
||||||
try
|
catch (SQLException ex)
|
||||||
{
|
{
|
||||||
conn.close();
|
LOGGER.log(Level.SEVERE, null, ex);
|
||||||
}
|
}
|
||||||
catch (SQLException ex)
|
}
|
||||||
{
|
}
|
||||||
LOGGER.log(Level.SEVERE, null, ex);
|
}
|
||||||
}
|
|
||||||
}
|
@Override
|
||||||
}
|
public boolean isProtected(Block block, String playerName)
|
||||||
}
|
{
|
||||||
|
Connection conn = null;
|
||||||
public boolean isProtected(Block block, String playerName)
|
PreparedStatement ps = null;
|
||||||
{
|
ResultSet rs = null;
|
||||||
Connection conn = null;
|
try
|
||||||
PreparedStatement ps = null;
|
{
|
||||||
ResultSet rs = null;
|
conn = cpds.getConnection();
|
||||||
try
|
ps = getStatementPlayerCountByLocation(conn, block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), playerName);
|
||||||
{
|
rs = ps.executeQuery();
|
||||||
conn = cpds.getConnection();
|
return rs.next() && rs.getInt(1) > 0 && rs.getInt(2) == 0;
|
||||||
ps = getStatementPlayerCountByLocation(conn, block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), playerName);
|
}
|
||||||
rs = ps.executeQuery();
|
catch (SQLException ex)
|
||||||
return rs.next() && rs.getInt(1) > 0 && rs.getInt(2) == 0;
|
{
|
||||||
}
|
LOGGER.log(Level.SEVERE, null, ex);
|
||||||
catch (SQLException ex)
|
return true;
|
||||||
{
|
}
|
||||||
LOGGER.log(Level.SEVERE, null, ex);
|
finally
|
||||||
return true;
|
{
|
||||||
}
|
if (rs != null)
|
||||||
finally
|
{
|
||||||
{
|
try
|
||||||
if (rs != null)
|
{
|
||||||
{
|
rs.close();
|
||||||
try
|
}
|
||||||
{
|
catch (SQLException ex)
|
||||||
rs.close();
|
{
|
||||||
}
|
LOGGER.log(Level.SEVERE, null, ex);
|
||||||
catch (SQLException ex)
|
}
|
||||||
{
|
}
|
||||||
LOGGER.log(Level.SEVERE, null, ex);
|
if (ps != null)
|
||||||
}
|
{
|
||||||
}
|
try
|
||||||
if (ps != null)
|
{
|
||||||
{
|
ps.close();
|
||||||
try
|
}
|
||||||
{
|
catch (SQLException ex)
|
||||||
ps.close();
|
{
|
||||||
}
|
LOGGER.log(Level.SEVERE, null, ex);
|
||||||
catch (SQLException ex)
|
}
|
||||||
{
|
}
|
||||||
LOGGER.log(Level.SEVERE, null, ex);
|
if (conn != null)
|
||||||
}
|
{
|
||||||
}
|
try
|
||||||
if (conn != null)
|
{
|
||||||
{
|
conn.close();
|
||||||
try
|
}
|
||||||
{
|
catch (SQLException ex)
|
||||||
conn.close();
|
{
|
||||||
}
|
LOGGER.log(Level.SEVERE, null, ex);
|
||||||
catch (SQLException ex)
|
}
|
||||||
{
|
}
|
||||||
LOGGER.log(Level.SEVERE, null, ex);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
@Override
|
||||||
}
|
public List<String> getOwners(Block block)
|
||||||
|
{
|
||||||
public List<String> getOwners(Block block)
|
Connection conn = null;
|
||||||
{
|
PreparedStatement ps = null;
|
||||||
Connection conn = null;
|
ResultSet rs = null;
|
||||||
PreparedStatement ps = null;
|
List<String> owners = new ArrayList<String>();
|
||||||
ResultSet rs = null;
|
try
|
||||||
List<String> owners = new ArrayList<String>();
|
{
|
||||||
try
|
conn = cpds.getConnection();
|
||||||
{
|
ps = getStatementPlayersByLocation(conn, block.getWorld().getName(), block.getX(), block.getY(), block.getZ());
|
||||||
conn = cpds.getConnection();
|
rs = ps.executeQuery();
|
||||||
ps = getStatementPlayersByLocation(conn, block.getWorld().getName(), block.getX(), block.getY(), block.getZ());
|
while (rs.next())
|
||||||
rs = ps.executeQuery();
|
{
|
||||||
while (rs.next())
|
owners.add(rs.getString(1));
|
||||||
{
|
}
|
||||||
owners.add(rs.getString(1));
|
return owners;
|
||||||
}
|
}
|
||||||
return owners;
|
catch (SQLException ex)
|
||||||
}
|
{
|
||||||
catch (SQLException ex)
|
LOGGER.log(Level.SEVERE, null, ex);
|
||||||
{
|
return owners;
|
||||||
LOGGER.log(Level.SEVERE, null, ex);
|
}
|
||||||
return owners;
|
finally
|
||||||
}
|
{
|
||||||
finally
|
if (rs != null)
|
||||||
{
|
{
|
||||||
if (rs != null)
|
try
|
||||||
{
|
{
|
||||||
try
|
rs.close();
|
||||||
{
|
}
|
||||||
rs.close();
|
catch (SQLException ex)
|
||||||
}
|
{
|
||||||
catch (SQLException ex)
|
LOGGER.log(Level.SEVERE, null, ex);
|
||||||
{
|
}
|
||||||
LOGGER.log(Level.SEVERE, null, ex);
|
}
|
||||||
}
|
if (ps != null)
|
||||||
}
|
{
|
||||||
if (ps != null)
|
try
|
||||||
{
|
{
|
||||||
try
|
ps.close();
|
||||||
{
|
}
|
||||||
ps.close();
|
catch (SQLException ex)
|
||||||
}
|
{
|
||||||
catch (SQLException ex)
|
LOGGER.log(Level.SEVERE, null, ex);
|
||||||
{
|
}
|
||||||
LOGGER.log(Level.SEVERE, null, ex);
|
}
|
||||||
}
|
if (conn != null)
|
||||||
}
|
{
|
||||||
if (conn != null)
|
try
|
||||||
{
|
{
|
||||||
try
|
conn.close();
|
||||||
{
|
}
|
||||||
conn.close();
|
catch (SQLException ex)
|
||||||
}
|
{
|
||||||
catch (SQLException ex)
|
LOGGER.log(Level.SEVERE, null, ex);
|
||||||
{
|
}
|
||||||
LOGGER.log(Level.SEVERE, null, ex);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
@Override
|
||||||
|
public int unprotectBlock(Block block)
|
||||||
public int unprotectBlock(Block block)
|
{
|
||||||
{
|
Connection conn = null;
|
||||||
Connection conn = null;
|
PreparedStatement ps = null;
|
||||||
PreparedStatement ps = null;
|
try
|
||||||
try
|
{
|
||||||
{
|
conn = cpds.getConnection();
|
||||||
conn = cpds.getConnection();
|
ps = getStatementDeleteByLocation(conn, block.getWorld().getName(), block.getX(), block.getY(), block.getZ());
|
||||||
ps = getStatementDeleteByLocation(conn, block.getWorld().getName(), block.getX(), block.getY(), block.getZ());
|
return ps.executeUpdate();
|
||||||
return ps.executeUpdate();
|
}
|
||||||
}
|
catch (SQLException ex)
|
||||||
catch (SQLException ex)
|
{
|
||||||
{
|
LOGGER.log(Level.SEVERE, null, ex);
|
||||||
LOGGER.log(Level.SEVERE, null, ex);
|
return 0;
|
||||||
return 0;
|
}
|
||||||
}
|
finally
|
||||||
finally
|
{
|
||||||
{
|
if (ps != null)
|
||||||
if (ps != null)
|
{
|
||||||
{
|
try
|
||||||
try
|
{
|
||||||
{
|
ps.close();
|
||||||
ps.close();
|
}
|
||||||
}
|
catch (SQLException ex)
|
||||||
catch (SQLException ex)
|
{
|
||||||
{
|
LOGGER.log(Level.SEVERE, null, ex);
|
||||||
LOGGER.log(Level.SEVERE, null, ex);
|
}
|
||||||
}
|
}
|
||||||
}
|
if (conn != null)
|
||||||
if (conn != null)
|
{
|
||||||
{
|
try
|
||||||
try
|
{
|
||||||
{
|
conn.close();
|
||||||
conn.close();
|
}
|
||||||
}
|
catch (SQLException ex)
|
||||||
catch (SQLException ex)
|
{
|
||||||
{
|
LOGGER.log(Level.SEVERE, null, ex);
|
||||||
LOGGER.log(Level.SEVERE, null, ex);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
public void onPluginDeactivation()
|
public void onPluginDeactivation()
|
||||||
{
|
{
|
||||||
cpds.close();
|
cpds.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,258 +1,258 @@
|
|||||||
package com.earth2me.essentials.protect.data;
|
package com.earth2me.essentials.protect.data;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
|
||||||
public class ProtectedBlockMemory implements IProtectedBlock
|
public class ProtectedBlockMemory implements IProtectedBlock
|
||||||
{
|
{
|
||||||
private final transient List<String> worlds = new ArrayList<String>();
|
private final List<String> worlds = new ArrayList<String>();
|
||||||
private final transient List<String> playerNames = new ArrayList<String>();
|
private final List<String> playerNames = new ArrayList<String>();
|
||||||
private final transient IProtectedBlock storage;
|
private final IProtectedBlock storage;
|
||||||
private final transient Plugin plugin;
|
private final Plugin plugin;
|
||||||
|
|
||||||
|
|
||||||
static class ProtectedLocation
|
static class ProtectedLocation
|
||||||
{
|
{
|
||||||
private final transient int x;
|
private final int x;
|
||||||
private final transient int y;
|
private final int y;
|
||||||
private final transient int z;
|
private final int z;
|
||||||
private final transient int w;
|
private final int w;
|
||||||
|
|
||||||
public ProtectedLocation(final Block block, final int worldId)
|
public ProtectedLocation(final Block block, final int worldId)
|
||||||
{
|
{
|
||||||
this.x = block.getX();
|
this.x = block.getX();
|
||||||
this.y = block.getY();
|
this.y = block.getY();
|
||||||
this.z = block.getZ();
|
this.z = block.getZ();
|
||||||
this.w = worldId;
|
this.w = worldId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProtectedLocation(final OwnedBlock ownedBlock, final int worldId)
|
public ProtectedLocation(final OwnedBlock ownedBlock, final int worldId)
|
||||||
{
|
{
|
||||||
this.x = ownedBlock.x;
|
this.x = ownedBlock.x;
|
||||||
this.y = ownedBlock.y;
|
this.y = ownedBlock.y;
|
||||||
this.z = ownedBlock.z;
|
this.z = ownedBlock.z;
|
||||||
this.w = worldId;
|
this.w = worldId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(final Object object)
|
public boolean equals(final Object object)
|
||||||
{
|
{
|
||||||
if (object instanceof ProtectedLocation)
|
if (object instanceof ProtectedLocation)
|
||||||
{
|
{
|
||||||
final ProtectedLocation pLoc = (ProtectedLocation)object;
|
final ProtectedLocation pLoc = (ProtectedLocation)object;
|
||||||
return x == pLoc.x && y == pLoc.y && z == pLoc.z && w == pLoc.w;
|
return x == pLoc.x && y == pLoc.y && z == pLoc.z && w == pLoc.w;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode()
|
public int hashCode()
|
||||||
{
|
{
|
||||||
return x ^ y ^ z ^ w;
|
return x ^ y ^ z ^ w;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static class ProtectedBy
|
static class ProtectedBy
|
||||||
{
|
{
|
||||||
private transient int playerId = -1;
|
private int playerId = -1;
|
||||||
private transient Set<Integer> playerIds;
|
private Set<Integer> playerIds;
|
||||||
|
|
||||||
public void add(final int playerId)
|
public void add(final int playerId)
|
||||||
{
|
{
|
||||||
if (this.playerId == -1 || this.playerId == playerId)
|
if (this.playerId == -1 || this.playerId == playerId)
|
||||||
{
|
{
|
||||||
this.playerId = playerId;
|
this.playerId = playerId;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (playerIds == null)
|
if (playerIds == null)
|
||||||
{
|
{
|
||||||
playerIds = new HashSet<Integer>(4);
|
playerIds = new HashSet<Integer>(4);
|
||||||
playerIds.add(this.playerId);
|
playerIds.add(this.playerId);
|
||||||
}
|
}
|
||||||
playerIds.add(playerId);
|
playerIds.add(playerId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean contains(final int playerId)
|
public boolean contains(final int playerId)
|
||||||
{
|
{
|
||||||
if (playerIds == null)
|
if (playerIds == null)
|
||||||
{
|
{
|
||||||
return this.playerId == playerId;
|
return this.playerId == playerId;
|
||||||
}
|
}
|
||||||
return playerIds.contains(playerId);
|
return playerIds.contains(playerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getPlayers(final List<String> playerNames)
|
public List<String> getPlayers(final List<String> playerNames)
|
||||||
{
|
{
|
||||||
final List<String> list = new ArrayList<String>(2);
|
final List<String> list = new ArrayList<String>(2);
|
||||||
if (playerIds == null)
|
if (playerIds == null)
|
||||||
{
|
{
|
||||||
list.add(playerNames.get(playerId));
|
list.add(playerNames.get(playerId));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (Integer integer : playerIds)
|
for (Integer integer : playerIds)
|
||||||
{
|
{
|
||||||
list.add(playerNames.get(integer));
|
list.add(playerNames.get(integer));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int size()
|
public int size()
|
||||||
{
|
{
|
||||||
if (playerIds == null)
|
if (playerIds == null)
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return playerIds.size();
|
return playerIds.size();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private final transient Map<ProtectedLocation, ProtectedBy> blocks = new HashMap<ProtectedLocation, ProtectedBy>();
|
private final Map<ProtectedLocation, ProtectedBy> blocks = new HashMap<ProtectedLocation, ProtectedBy>();
|
||||||
|
|
||||||
public ProtectedBlockMemory(final IProtectedBlock storage, final Plugin plugin)
|
public ProtectedBlockMemory(final IProtectedBlock storage, final Plugin plugin)
|
||||||
{
|
{
|
||||||
this.storage = storage;
|
this.storage = storage;
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
importProtections(storage.exportProtections());
|
importProtections(storage.exportProtections());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearProtections()
|
public void clearProtections()
|
||||||
{
|
{
|
||||||
blocks.clear();
|
blocks.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void importProtections(final List<OwnedBlock> blocks)
|
public final void importProtections(final List<OwnedBlock> blocks)
|
||||||
{
|
{
|
||||||
for (OwnedBlock ownedBlock : blocks)
|
for (OwnedBlock ownedBlock : blocks)
|
||||||
{
|
{
|
||||||
final ProtectedLocation pl = new ProtectedLocation(ownedBlock, getWorldId(ownedBlock.world));
|
final ProtectedLocation pl = new ProtectedLocation(ownedBlock, getWorldId(ownedBlock.world));
|
||||||
if (ownedBlock.playerName == null)
|
if (ownedBlock.playerName == null)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
protectBlock(pl, ownedBlock.playerName);
|
protectBlock(pl, ownedBlock.playerName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<OwnedBlock> exportProtections()
|
public List<OwnedBlock> exportProtections()
|
||||||
{
|
{
|
||||||
final List<OwnedBlock> blockList = new ArrayList<OwnedBlock>(blocks.size());
|
final List<OwnedBlock> blockList = new ArrayList<OwnedBlock>(blocks.size());
|
||||||
for (Entry<ProtectedLocation, ProtectedBy> entry : blocks.entrySet())
|
for (Entry<ProtectedLocation, ProtectedBy> entry : blocks.entrySet())
|
||||||
{
|
{
|
||||||
for (String name : entry.getValue().getPlayers(playerNames))
|
for (String name : entry.getValue().getPlayers(playerNames))
|
||||||
{
|
{
|
||||||
final OwnedBlock ob = new OwnedBlock(
|
final OwnedBlock ob = new OwnedBlock(
|
||||||
entry.getKey().x,
|
entry.getKey().x,
|
||||||
entry.getKey().y,
|
entry.getKey().y,
|
||||||
entry.getKey().z,
|
entry.getKey().z,
|
||||||
worlds.get(entry.getKey().w),
|
worlds.get(entry.getKey().w),
|
||||||
name);
|
name);
|
||||||
blockList.add(ob);
|
blockList.add(ob);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return blockList;
|
return blockList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void protectBlock(final Block block, final String playerName)
|
public void protectBlock(final Block block, final String playerName)
|
||||||
{
|
{
|
||||||
final ProtectedLocation pl = new ProtectedLocation(block, getWorldId(block.getWorld()));
|
final ProtectedLocation pl = new ProtectedLocation(block, getWorldId(block.getWorld()));
|
||||||
protectBlock(pl, playerName);
|
protectBlock(pl, playerName);
|
||||||
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable()
|
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
storage.protectBlock(block, playerName);
|
storage.protectBlock(block, playerName);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void protectBlock(ProtectedLocation pl, String playerName)
|
private void protectBlock(ProtectedLocation pl, String playerName)
|
||||||
{
|
{
|
||||||
int playerId = getPlayerId(playerName);
|
int playerId = getPlayerId(playerName);
|
||||||
ProtectedBy pb = blocks.get(pl);
|
ProtectedBy pb = blocks.get(pl);
|
||||||
if (pb == null)
|
if (pb == null)
|
||||||
{
|
{
|
||||||
pb = new ProtectedBy();
|
pb = new ProtectedBy();
|
||||||
blocks.put(pl, pb);
|
blocks.put(pl, pb);
|
||||||
}
|
}
|
||||||
pb.add(playerId);
|
pb.add(playerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isProtected(Block block, String playerName)
|
public boolean isProtected(Block block, String playerName)
|
||||||
{
|
{
|
||||||
int playerId = getPlayerId(playerName);
|
int playerId = getPlayerId(playerName);
|
||||||
ProtectedLocation pl = new ProtectedLocation(block, getWorldId(block.getWorld()));
|
ProtectedLocation pl = new ProtectedLocation(block, getWorldId(block.getWorld()));
|
||||||
ProtectedBy pb = blocks.get(pl);
|
ProtectedBy pb = blocks.get(pl);
|
||||||
return !pb.contains(playerId);
|
return !pb.contains(playerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getOwners(Block block)
|
public List<String> getOwners(Block block)
|
||||||
{
|
{
|
||||||
ProtectedLocation pl = new ProtectedLocation(block, getWorldId(block.getWorld()));
|
ProtectedLocation pl = new ProtectedLocation(block, getWorldId(block.getWorld()));
|
||||||
ProtectedBy pb = blocks.get(pl);
|
ProtectedBy pb = blocks.get(pl);
|
||||||
return pb.getPlayers(playerNames);
|
return pb.getPlayers(playerNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int unprotectBlock(final Block block)
|
public int unprotectBlock(final Block block)
|
||||||
{
|
{
|
||||||
ProtectedLocation pl = new ProtectedLocation(block, getWorldId(block.getWorld()));
|
ProtectedLocation pl = new ProtectedLocation(block, getWorldId(block.getWorld()));
|
||||||
ProtectedBy pb = blocks.remove(pl);
|
ProtectedBy pb = blocks.remove(pl);
|
||||||
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable()
|
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
storage.unprotectBlock(block);
|
storage.unprotectBlock(block);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return pb.size();
|
return pb.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getPlayerId(String playername)
|
private int getPlayerId(String playername)
|
||||||
{
|
{
|
||||||
int id = playerNames.indexOf(playername);
|
int id = playerNames.indexOf(playername);
|
||||||
if (id < 0)
|
if (id < 0)
|
||||||
{
|
{
|
||||||
playerNames.add(playername);
|
playerNames.add(playername);
|
||||||
id = playerNames.indexOf(playername);
|
id = playerNames.indexOf(playername);
|
||||||
}
|
}
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getWorldId(World world)
|
private int getWorldId(World world)
|
||||||
{
|
{
|
||||||
return getWorldId(world.getName());
|
return getWorldId(world.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getWorldId(String name)
|
private int getWorldId(String name)
|
||||||
{
|
{
|
||||||
int id = worlds.indexOf(name);
|
int id = worlds.indexOf(name);
|
||||||
if (id < 0)
|
if (id < 0)
|
||||||
{
|
{
|
||||||
worlds.add(name);
|
worlds.add(name);
|
||||||
id = worlds.indexOf(name);
|
id = worlds.indexOf(name);
|
||||||
}
|
}
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPluginDeactivation()
|
public void onPluginDeactivation()
|
||||||
{
|
{
|
||||||
storage.onPluginDeactivation();
|
storage.onPluginDeactivation();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user