mirror of
https://github.com/essentials/Essentials.git
synced 2025-08-12 01:25:26 +02:00
Removing the signs and rails protection from protect
Remove the antibuild functionality from protect
This commit is contained in:
@@ -12,9 +12,7 @@ import org.bukkit.Material;
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class Prevent implements StorageObject
|
||||
{
|
||||
@Comment("Which blocks should a piston not be able to push?")
|
||||
@ListType(Material.class)
|
||||
private Set<Material> pistonPush = new HashSet<Material>();
|
||||
|
||||
private boolean lavaFlow = false;
|
||||
private boolean waterFlow = false;
|
||||
// private boolean waterbucketFlow = false; TODO: Test if this still works
|
||||
@@ -36,9 +34,4 @@ public class Prevent implements StorageObject
|
||||
"permission essentials.protect.entitytarget.bypass disables this"
|
||||
})
|
||||
private boolean entitytarget = false;
|
||||
|
||||
public Prevent()
|
||||
{
|
||||
pistonPush.add(Material.GLASS);
|
||||
}
|
||||
}
|
@@ -1,32 +1,15 @@
|
||||
package net.ess3.settings.protect;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import net.ess3.storage.Comment;
|
||||
import net.ess3.storage.ListType;
|
||||
import net.ess3.storage.StorageObject;
|
||||
import org.bukkit.Material;
|
||||
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class Protect implements StorageObject
|
||||
{
|
||||
@Comment("Either mysql or sqlite")
|
||||
private String dbtype = "sqlite";
|
||||
@Comment("If you specified MySQL above, you MUST enter the appropriate details here.")
|
||||
private String dbuser = "root";
|
||||
private String dbpassword = "";
|
||||
private String dburl = "jdbc:mysql://localhost:3306/minecraft";
|
||||
@Comment("For which block types would you like to be alerted?")
|
||||
@ListType(Material.class)
|
||||
private Set<Material> alertOnPlacement = new HashSet<Material>();
|
||||
@ListType(Material.class)
|
||||
private Set<Material> alertOnUse = new HashSet<Material>();
|
||||
@ListType(Material.class)
|
||||
private Set<Material> alertOnBreak = new HashSet<Material>();
|
||||
{
|
||||
@Comment("General physics/behavior modifications")
|
||||
private Prevent prevent = new Prevent();
|
||||
@Comment(
|
||||
@@ -41,12 +24,5 @@ public class Protect implements StorageObject
|
||||
private boolean disableStorm = false;
|
||||
private boolean disableThunder = false;
|
||||
private boolean disableLighting = false;
|
||||
private SignsAndRails signsAndRails = new SignsAndRails();
|
||||
|
||||
public Protect()
|
||||
{
|
||||
alertOnPlacement.add(Material.LAVA);
|
||||
alertOnUse.add(Material.LAVA_BUCKET);
|
||||
alertOnBreak.add(Material.GLASS);
|
||||
}
|
||||
}
|
||||
|
@@ -1,46 +0,0 @@
|
||||
package net.ess3.protect;
|
||||
|
||||
import net.ess3.api.IPermission;
|
||||
import net.ess3.permissions.AbstractSuperpermsPermission;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
|
||||
public final class BlockBreakPermissions extends AbstractSuperpermsPermission
|
||||
{
|
||||
private static Map<Material, IPermission> permissions = new EnumMap<Material, IPermission>(Material.class);
|
||||
private static final String base = "essentials.protect.blockbreak.";
|
||||
private final String permission;
|
||||
|
||||
public static IPermission getPermission(final Material mat)
|
||||
{
|
||||
IPermission perm = permissions.get(mat);
|
||||
if (perm == null)
|
||||
{
|
||||
perm = new BlockBreakPermissions(mat.toString().toLowerCase(Locale.ENGLISH));
|
||||
permissions.put(mat, perm);
|
||||
}
|
||||
return perm;
|
||||
}
|
||||
|
||||
private BlockBreakPermissions(final String matName)
|
||||
{
|
||||
super();
|
||||
this.permission = base + matName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionName()
|
||||
{
|
||||
return this.permission;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionDefault getPermissionDefault()
|
||||
{
|
||||
return PermissionDefault.TRUE;
|
||||
}
|
||||
}
|
@@ -1,46 +0,0 @@
|
||||
package net.ess3.protect;
|
||||
|
||||
import net.ess3.api.IPermission;
|
||||
import net.ess3.permissions.AbstractSuperpermsPermission;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
|
||||
public class BlockPlacePermissions extends AbstractSuperpermsPermission
|
||||
{
|
||||
private static Map<Material, IPermission> permissions = new EnumMap<Material, IPermission>(Material.class);
|
||||
private static final String base = "essentials.protect.blockplace.";
|
||||
private final String permission;
|
||||
|
||||
public static IPermission getPermission(final Material mat)
|
||||
{
|
||||
IPermission perm = permissions.get(mat);
|
||||
if (perm == null)
|
||||
{
|
||||
perm = new BlockPlacePermissions(mat.toString().toLowerCase(Locale.ENGLISH));
|
||||
permissions.put(mat, perm);
|
||||
}
|
||||
return perm;
|
||||
}
|
||||
|
||||
private BlockPlacePermissions(final String matName)
|
||||
{
|
||||
super();
|
||||
this.permission = base + matName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionName()
|
||||
{
|
||||
return this.permission;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionDefault getPermissionDefault()
|
||||
{
|
||||
return PermissionDefault.TRUE;
|
||||
}
|
||||
}
|
@@ -2,15 +2,8 @@ package net.ess3.protect;
|
||||
|
||||
import static net.ess3.I18n._;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.IReload;
|
||||
import net.ess3.api.IUser;
|
||||
import net.ess3.protect.data.ProtectedBlockMySQL;
|
||||
import net.ess3.protect.data.ProtectedBlockSQLite;
|
||||
import java.beans.PropertyVetoException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
|
||||
@@ -29,96 +22,11 @@ public class EssentialsConnect
|
||||
ess = (IEssentials)essPlugin;
|
||||
protect = (IProtect)essProtect;
|
||||
protect.setSettings(new ProtectHolder(ess));
|
||||
final ProtectReloader pr = new ProtectReloader();
|
||||
pr.onReload();
|
||||
ess.addReloadListener(pr);
|
||||
}
|
||||
|
||||
public IEssentials getEssentials()
|
||||
{
|
||||
return ess;
|
||||
}
|
||||
|
||||
public void alert(final Player user, final String item, final String type)
|
||||
{
|
||||
final Location loc = user.getLocation();
|
||||
final String warnMessage = _("alertFormat", user.getName(), type, item,
|
||||
loc.getWorld().getName() + "," + loc.getBlockX() + ","
|
||||
+ loc.getBlockY() + "," + loc.getBlockZ());
|
||||
LOGGER.log(Level.WARNING, warnMessage);
|
||||
for (Player p : ess.getServer().getOnlinePlayers())
|
||||
{
|
||||
final IUser alertUser = ess.getUserMap().getUser(p);
|
||||
if (Permissions.ALERTS.isAuthorized(alertUser))
|
||||
{
|
||||
alertUser.sendMessage(warnMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private class ProtectReloader implements IReload
|
||||
{
|
||||
@Override
|
||||
public void onReload()
|
||||
{
|
||||
if (protect.getStorage() != null)
|
||||
{
|
||||
protect.getStorage().onPluginDeactivation();
|
||||
}
|
||||
|
||||
/*
|
||||
* for (ProtectConfig protectConfig : ProtectConfig.values()) { if (protectConfig.isList()) {
|
||||
* protect.getSettingsList().put(protectConfig,
|
||||
* ess.getSettings().getProtectList(protectConfig.getConfigName())); } else if (protectConfig.isString()) {
|
||||
* protect.getSettingsString().put(protectConfig,
|
||||
* ess.getSettings().getProtectString(protectConfig.getConfigName())); } else {
|
||||
* protect.getSettingsBoolean().put(protectConfig,
|
||||
* ess.getSettings().getProtectBoolean(protectConfig.getConfigName(),
|
||||
* protectConfig.getDefaultValueBoolean())); }
|
||||
*
|
||||
* }
|
||||
*/
|
||||
|
||||
final ProtectHolder settings = protect.getSettings();
|
||||
settings.acquireReadLock();
|
||||
try
|
||||
{
|
||||
if (settings.getData().getDbtype().equalsIgnoreCase("mysql"))
|
||||
{
|
||||
try
|
||||
{
|
||||
protect.setStorage(new ProtectedBlockMySQL(
|
||||
settings.getData().getDburl(),
|
||||
settings.getData().getDbuser(),
|
||||
settings.getData().getDbpassword()));
|
||||
}
|
||||
catch (PropertyVetoException ex)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
protect.setStorage(new ProtectedBlockSQLite("jdbc:sqlite:" + ess.getPlugin().getDataFolder() + "/EssentialsProtect.db"));
|
||||
}
|
||||
catch (PropertyVetoException ex)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
/*if (protect.getSettingBool(ProtectConfig.memstore))
|
||||
{
|
||||
protect.setStorage(new ProtectedBlockMemory(protect.getStorage(), protect));
|
||||
}*/
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
settings.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,11 +1,7 @@
|
||||
package net.ess3.protect;
|
||||
|
||||
import net.ess3.protect.data.IProtectedBlock;
|
||||
import java.util.logging.Filter;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
@@ -15,28 +11,9 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
public class EssentialsProtect extends JavaPlugin implements IProtect
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger("Minecraft");
|
||||
private static com.mchange.v2.log.MLogger C3P0logger;
|
||||
//private final transient Map<ProtectConfig, Boolean> settingsBoolean = new EnumMap<ProtectConfig, Boolean>(ProtectConfig.class);
|
||||
//private final transient Map<ProtectConfig, String> settingsString = new EnumMap<ProtectConfig, String>(ProtectConfig.class);
|
||||
//private final transient Map<ProtectConfig, List<Integer>> settingsList = new EnumMap<ProtectConfig, List<Integer>>(ProtectConfig.class);
|
||||
private transient IProtectedBlock storage = null;
|
||||
private transient EssentialsConnect ess = null;
|
||||
private transient ProtectHolder settings = null;
|
||||
private transient com.mchange.v2.c3p0.management.ActiveManagementCoordinator temp; // leave this here for maven
|
||||
|
||||
@Override
|
||||
public void onLoad()
|
||||
{
|
||||
C3P0logger = com.mchange.v2.log.MLog.getLogger(com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.class);
|
||||
C3P0logger.setFilter(new Filter()
|
||||
{
|
||||
public boolean isLoggable(final LogRecord lr)
|
||||
{
|
||||
return lr.getLevel() != Level.INFO;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
@@ -47,10 +24,7 @@ public class EssentialsProtect extends JavaPlugin implements IProtect
|
||||
enableEmergencyMode(pm);
|
||||
return;
|
||||
}
|
||||
ess = new EssentialsConnect(essPlugin, this);
|
||||
|
||||
final EssentialsProtectPlayerListener playerListener = new EssentialsProtectPlayerListener(this);
|
||||
pm.registerEvents(playerListener, this);
|
||||
ess = new EssentialsConnect(essPlugin, this);
|
||||
|
||||
final EssentialsProtectBlockListener blockListener = new EssentialsProtectBlockListener(this);
|
||||
pm.registerEvents(blockListener, this);
|
||||
@@ -74,74 +48,12 @@ public class EssentialsProtect extends JavaPlugin implements IProtect
|
||||
LOGGER.log(Level.SEVERE, "Essentials not installed or failed to load. Essenials Protect is in emergency mode now.");
|
||||
}
|
||||
|
||||
/*@Override
|
||||
public boolean checkProtectionItems(final ProtectConfig list, final int id)
|
||||
{
|
||||
final List<Integer> itemList = settingsList.get(list);
|
||||
return itemList != null && !itemList.isEmpty() && itemList.contains(id);
|
||||
}*/
|
||||
@Override
|
||||
public IProtectedBlock getStorage()
|
||||
{
|
||||
return storage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStorage(final IProtectedBlock pb)
|
||||
{
|
||||
storage = pb;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public EssentialsConnect getEssentialsConnect()
|
||||
{
|
||||
return ess;
|
||||
}
|
||||
|
||||
/*public Map<ProtectConfig, Boolean> getSettingsBoolean()
|
||||
{
|
||||
return settingsBoolean;
|
||||
}
|
||||
|
||||
public Map<ProtectConfig, String> getSettingsString()
|
||||
{
|
||||
return settingsString;
|
||||
}
|
||||
|
||||
public Map<ProtectConfig, List<Integer>> getSettingsList()
|
||||
{
|
||||
return settingsList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getSettingBool(final ProtectConfig protectConfig)
|
||||
{
|
||||
final Boolean bool = settingsBoolean.get(protectConfig);
|
||||
return bool == null ? protectConfig.getDefaultValueBoolean() : bool;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSettingString(final ProtectConfig protectConfig)
|
||||
{
|
||||
final String str = settingsString.get(protectConfig);
|
||||
return str == null ? protectConfig.getDefaultValueString() : str;
|
||||
}*/
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
if (storage != null)
|
||||
{
|
||||
storage.onPluginDeactivation();
|
||||
}
|
||||
// Sleep for a second to allow the database to close.
|
||||
try
|
||||
{
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
catch (InterruptedException ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProtectHolder getSettings()
|
||||
|
@@ -1,13 +1,8 @@
|
||||
package net.ess3.protect;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import static net.ess3.I18n._;
|
||||
import net.ess3.protect.data.IProtectedBlock;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
@@ -21,80 +16,7 @@ public class EssentialsProtectBlockListener implements Listener
|
||||
public EssentialsProtectBlockListener(final IProtect parent)
|
||||
{
|
||||
this.prot = parent;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockPlace(final BlockPlaceEvent event)
|
||||
{
|
||||
final Player user = event.getPlayer();
|
||||
final ProtectHolder settings = prot.getSettings();
|
||||
settings.acquireReadLock();
|
||||
try
|
||||
{
|
||||
if (!Permissions.BUILD.isAuthorized(user))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
final Block blockPlaced = event.getBlockPlaced();
|
||||
|
||||
if (!BlockPlacePermissions.getPermission(blockPlaced.getType()).isAuthorized(user))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Permissions.ALERTS_NOTRIGGER.isAuthorized(user)
|
||||
&& settings.getData().getAlertOnPlacement().contains(blockPlaced.getType()))
|
||||
{
|
||||
prot.getEssentialsConnect().alert(user, blockPlaced.getType().toString(), _("alertPlaced"));
|
||||
}
|
||||
|
||||
final Block below = blockPlaced.getRelative(BlockFace.DOWN);
|
||||
if ((below.getType() == Material.RAILS || below.getType() == Material.POWERED_RAIL || below.getType() == Material.DETECTOR_RAIL)
|
||||
&& settings.getData().getSignsAndRails().isPreventBlockAboveRails()
|
||||
&& isProtected(below, user, settings))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
final List<Block> protect = new ArrayList<Block>();
|
||||
if ((blockPlaced.getType() == Material.RAILS || blockPlaced.getType() == Material.POWERED_RAIL || blockPlaced.getType() == Material.DETECTOR_RAIL)
|
||||
&& settings.getData().getSignsAndRails().isProtectRails()
|
||||
&& Permissions.RAILS.isAuthorized(user))
|
||||
{
|
||||
protect.add(blockPlaced);
|
||||
if (settings.getData().getSignsAndRails().isBlockBelow()
|
||||
&& !isProtected(blockPlaced.getRelative(BlockFace.DOWN), user, settings))
|
||||
{
|
||||
protect.add(blockPlaced.getRelative(BlockFace.DOWN));
|
||||
}
|
||||
}
|
||||
/*if ((blockPlaced.getType() == Material.SIGN_POST || blockPlaced.getType() == Material.WALL_SIGN)
|
||||
&& settings.getData().getSignsAndRails().isProtectSigns()
|
||||
&& user.isAuthorized("essentials.protect"))
|
||||
{
|
||||
protect.add(blockPlaced);
|
||||
if (settings.getData().getSignsAndRails().isBlockBelow()
|
||||
&& event.getBlockAgainst().getType() != Material.SIGN_POST
|
||||
&& event.getBlockAgainst().getType() != Material.WALL_SIGN
|
||||
&& !isProtected(event.getBlockAgainst(), user, settings))
|
||||
{
|
||||
protect.add(event.getBlockAgainst());
|
||||
}
|
||||
}*/
|
||||
for (Block block : protect)
|
||||
{
|
||||
prot.getStorage().protectBlock(block, user.getName());
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
settings.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockIgnite(BlockIgniteEvent event)
|
||||
@@ -103,19 +25,7 @@ public class EssentialsProtectBlockListener implements Listener
|
||||
settings.acquireReadLock();
|
||||
try
|
||||
{
|
||||
final Block block = event.getBlock();
|
||||
if ((block.getType() == Material.RAILS || block.getType() == Material.POWERED_RAIL || block.getType() == Material.DETECTOR_RAIL)
|
||||
&& settings.getData().getSignsAndRails().isProtectRails())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if ((block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST)
|
||||
&& settings.getData().getSignsAndRails().isProtectSigns())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
final Block block = event.getBlock();
|
||||
if (event.getBlock().getType() == Material.OBSIDIAN
|
||||
|| event.getBlock().getRelative(BlockFace.DOWN).getType() == Material.OBSIDIAN)
|
||||
{
|
||||
@@ -143,7 +53,6 @@ public class EssentialsProtectBlockListener implements Listener
|
||||
if (event.getCause().equals(BlockIgniteEvent.IgniteCause.LIGHTNING))
|
||||
{
|
||||
event.setCancelled(settings.getData().getPrevent().isLightningFirespread());
|
||||
return;
|
||||
}
|
||||
}
|
||||
finally
|
||||
@@ -159,21 +68,7 @@ public class EssentialsProtectBlockListener implements Listener
|
||||
settings.acquireReadLock();
|
||||
try
|
||||
{
|
||||
final Block toBlock = event.getToBlock();
|
||||
if ((toBlock.getType() == Material.RAILS || toBlock.getType() == Material.POWERED_RAIL || toBlock.getType() == Material.DETECTOR_RAIL)
|
||||
&& settings.getData().getSignsAndRails().isProtectRails())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if ((toBlock.getType() == Material.WALL_SIGN || toBlock.getType() == Material.SIGN_POST)
|
||||
&& settings.getData().getSignsAndRails().isProtectSigns())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
final Block block = event.getBlock();
|
||||
final Block block = event.getBlock();
|
||||
if (block.getType() == Material.WATER || block.getType() == Material.STATIONARY_WATER)
|
||||
{
|
||||
event.setCancelled(settings.getData().getPrevent().isWaterFlow());
|
||||
@@ -182,8 +77,7 @@ public class EssentialsProtectBlockListener implements Listener
|
||||
|
||||
if (block.getType() == Material.LAVA || block.getType() == Material.STATIONARY_LAVA)
|
||||
{
|
||||
event.setCancelled(settings.getData().getPrevent().isLavaFlow());
|
||||
return;
|
||||
event.setCancelled(settings.getData().getPrevent().isLavaFlow());
|
||||
}
|
||||
// TODO: Test if this still works
|
||||
/*
|
||||
@@ -204,23 +98,9 @@ public class EssentialsProtectBlockListener implements Listener
|
||||
settings.acquireReadLock();
|
||||
try
|
||||
{
|
||||
final Block block = event.getBlock();
|
||||
if ((block.getType() == Material.RAILS || block.getType() == Material.POWERED_RAIL || block.getType() == Material.DETECTOR_RAIL)
|
||||
&& settings.getData().getSignsAndRails().isProtectRails())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if ((block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST)
|
||||
&& settings.getData().getSignsAndRails().isProtectSigns())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (settings.getData().getPrevent().isFirespread())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
finally
|
||||
@@ -228,287 +108,4 @@ public class EssentialsProtectBlockListener implements Listener
|
||||
settings.unlock();
|
||||
}
|
||||
}
|
||||
private final static BlockFace[] faces = new BlockFace[]
|
||||
{
|
||||
BlockFace.NORTH,
|
||||
BlockFace.EAST,
|
||||
BlockFace.SOUTH,
|
||||
BlockFace.WEST,
|
||||
BlockFace.UP,
|
||||
BlockFace.DOWN,
|
||||
BlockFace.SELF
|
||||
};
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockBreak(final BlockBreakEvent event)
|
||||
{
|
||||
final Player user = event.getPlayer();
|
||||
|
||||
if (!Permissions.BUILD.isAuthorized(user))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
final Block block = event.getBlock();
|
||||
|
||||
if (!BlockBreakPermissions.getPermission(block.getType()).isAuthorized(user))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
final ProtectHolder settings = prot.getSettings();
|
||||
settings.acquireReadLock();
|
||||
try
|
||||
{
|
||||
final Material type = block.getType();
|
||||
|
||||
if (!Permissions.ALERTS_NOTRIGGER.isAuthorized(user) && settings.getData().getAlertOnBreak().contains(type))
|
||||
{
|
||||
prot.getEssentialsConnect().alert(user, type.toString(), _("alertBroke"));
|
||||
}
|
||||
final IProtectedBlock storage = prot.getStorage();
|
||||
|
||||
if (Permissions.ADMIN.isAuthorized(user))
|
||||
{
|
||||
if (type == Material.WALL_SIGN || type == Material.SIGN_POST || type == Material.RAILS || type == Material.POWERED_RAIL || type == Material.DETECTOR_RAIL)
|
||||
{
|
||||
storage.unprotectBlock(block);
|
||||
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
|
||||
{
|
||||
for (BlockFace blockFace : faces)
|
||||
{
|
||||
final Block against = block.getRelative(blockFace);
|
||||
storage.unprotectBlock(against);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (BlockFace blockFace : faces)
|
||||
{
|
||||
final Block against = block.getRelative(blockFace);
|
||||
storage.unprotectBlock(against);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
final boolean isProtected = isProtected(block, user, settings);
|
||||
if (isProtected)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (type == Material.WALL_SIGN || type == Material.SIGN_POST || type == Material.RAILS || type == Material.POWERED_RAIL || type == Material.DETECTOR_RAIL)
|
||||
{
|
||||
storage.unprotectBlock(block);
|
||||
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
|
||||
{
|
||||
for (BlockFace blockFace : faces)
|
||||
{
|
||||
final Block against = block.getRelative(blockFace);
|
||||
storage.unprotectBlock(against);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (BlockFace blockFace : faces)
|
||||
{
|
||||
final Block against = block.getRelative(blockFace);
|
||||
storage.unprotectBlock(against);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
settings.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockPistonExtend(final BlockPistonExtendEvent event)
|
||||
{
|
||||
final ProtectHolder settings = prot.getSettings();
|
||||
settings.acquireReadLock();
|
||||
try
|
||||
{
|
||||
for (Block block : event.getBlocks())
|
||||
{
|
||||
if (settings.getData().getPrevent().getPistonPush().contains(block.getType()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
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)
|
||||
&& settings.getData().getSignsAndRails().isProtectRails())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (settings.getData().getSignsAndRails().isProtectSigns())
|
||||
{
|
||||
for (BlockFace blockFace : faces)
|
||||
{
|
||||
if (blockFace == BlockFace.DOWN)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
final Block sign = block.getRelative(blockFace);
|
||||
if ((blockFace == BlockFace.UP || blockFace == BlockFace.SELF)
|
||||
&& sign.getType() == Material.SIGN_POST)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if ((blockFace == BlockFace.NORTH || blockFace == BlockFace.EAST
|
||||
|| blockFace == BlockFace.SOUTH || blockFace == BlockFace.WEST
|
||||
|| blockFace == BlockFace.SELF)
|
||||
&& sign.getType() == Material.WALL_SIGN)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
settings.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockPistonRetract(final BlockPistonRetractEvent event)
|
||||
{
|
||||
if (!event.isSticky())
|
||||
{
|
||||
return;
|
||||
}
|
||||
final ProtectHolder settings = prot.getSettings();
|
||||
settings.acquireReadLock();
|
||||
try
|
||||
{
|
||||
final Block block = event.getRetractLocation().getBlock();
|
||||
if (settings.getData().getPrevent().getPistonPush().contains(block.getType()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
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)
|
||||
&& settings.getData().getSignsAndRails().isProtectRails())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (settings.getData().getSignsAndRails().isProtectSigns())
|
||||
{
|
||||
for (BlockFace blockFace : faces)
|
||||
{
|
||||
if (blockFace == BlockFace.DOWN)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
final Block sign = block.getRelative(blockFace);
|
||||
if ((blockFace == BlockFace.UP || blockFace == BlockFace.SELF)
|
||||
&& sign.getType() == Material.SIGN_POST)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if ((blockFace == BlockFace.NORTH || blockFace == BlockFace.EAST
|
||||
|| blockFace == BlockFace.SOUTH || blockFace == BlockFace.WEST
|
||||
|| blockFace == BlockFace.SELF)
|
||||
&& sign.getType() == Material.WALL_SIGN)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
settings.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isProtected(final Block block, final Player user, final ProtectHolder settings)
|
||||
{
|
||||
final Material type = block.getType();
|
||||
if (settings.getData().getSignsAndRails().isProtectSigns())
|
||||
{
|
||||
if (type == Material.WALL_SIGN || type == Material.SIGN_POST)
|
||||
{
|
||||
return prot.getStorage().isProtected(block, user.getName());
|
||||
}
|
||||
|
||||
final Block up = block.getRelative(BlockFace.UP);
|
||||
if (up != null && up.getType() == Material.SIGN_POST)
|
||||
{
|
||||
return prot.getStorage().isProtected(block, user.getName());
|
||||
}
|
||||
final BlockFace[] directions = new BlockFace[]
|
||||
{
|
||||
BlockFace.NORTH,
|
||||
BlockFace.EAST,
|
||||
BlockFace.SOUTH,
|
||||
BlockFace.WEST
|
||||
};
|
||||
for (BlockFace blockFace : directions)
|
||||
{
|
||||
final Block signblock = block.getRelative(blockFace);
|
||||
if (signblock.getType() == Material.WALL_SIGN)
|
||||
{
|
||||
final org.bukkit.material.Sign signMat = (org.bukkit.material.Sign)signblock.getState().getData();
|
||||
if (signMat != null && signMat.getFacing() == blockFace)
|
||||
{
|
||||
return prot.getStorage().isProtected(block, user.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (settings.getData().getSignsAndRails().isProtectRails())
|
||||
{
|
||||
if (type == Material.RAILS || type == Material.POWERED_RAIL || type == Material.DETECTOR_RAIL)
|
||||
{
|
||||
return prot.getStorage().isProtected(block, user.getName());
|
||||
}
|
||||
if (settings.getData().getSignsAndRails().isBlockBelow())
|
||||
{
|
||||
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,9 +1,5 @@
|
||||
package net.ess3.protect;
|
||||
|
||||
import net.ess3.api.IEssentials;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@@ -154,8 +150,7 @@ public class EssentialsProtectEntityListener implements Listener
|
||||
&& (Permissions.PREVENTDAMAGE_LIGHTNING.isAuthorized(user)
|
||||
&& !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user)))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -200,36 +195,7 @@ public class EssentialsProtectEntityListener implements Listener
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
// This code will prevent explosions near protected rails, signs or protected chests
|
||||
// TODO: Use protect db instead of this code
|
||||
|
||||
for (Block block : event.blockList())
|
||||
{
|
||||
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)
|
||||
&& settings.getData().getSignsAndRails().isProtectRails())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if ((block.getType() == Material.WALL_SIGN
|
||||
|| block.getRelative(BlockFace.NORTH).getType() == Material.WALL_SIGN
|
||||
|| block.getRelative(BlockFace.EAST).getType() == Material.WALL_SIGN
|
||||
|| block.getRelative(BlockFace.SOUTH).getType() == Material.WALL_SIGN
|
||||
|| block.getRelative(BlockFace.WEST).getType() == Material.WALL_SIGN
|
||||
|| block.getType() == Material.SIGN_POST
|
||||
|| block.getRelative(BlockFace.UP).getType() == Material.SIGN_POST)
|
||||
&& settings.getData().getSignsAndRails().isProtectSigns())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@@ -1,98 +0,0 @@
|
||||
package net.ess3.protect;
|
||||
|
||||
import static net.ess3.I18n._;
|
||||
import net.ess3.api.IEssentials;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
||||
public class EssentialsProtectPlayerListener implements Listener
|
||||
{
|
||||
private final transient IProtect prot;
|
||||
|
||||
public EssentialsProtectPlayerListener(final IProtect prot)
|
||||
{
|
||||
this.prot = prot;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerInteract(final PlayerInteractEvent event)
|
||||
{
|
||||
// Do not return if cancelled, because the interact event has 2 cancelled states.
|
||||
final Player user = event.getPlayer();
|
||||
|
||||
final ProtectHolder settings = prot.getSettings();
|
||||
settings.acquireReadLock();
|
||||
try
|
||||
{
|
||||
if (event.hasItem()
|
||||
&& (event.getItem().getType() == Material.WATER_BUCKET
|
||||
|| event.getItem().getType() == Material.LAVA_BUCKET)
|
||||
&& !Permissions.BUILD.isAuthorized(user))
|
||||
{
|
||||
if (settings.getData().isWarnOnBuildDisallow())
|
||||
{
|
||||
user.sendMessage(_("buildAlert"));
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Permissions.INTERACT.isAuthorized(user))
|
||||
{
|
||||
if (settings.getData().isWarnOnBuildDisallow())
|
||||
{
|
||||
user.sendMessage(_("buildAlert"));
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
final ItemStack item = event.getItem();
|
||||
if (item != null
|
||||
&& !ItemUsePermissions.getPermission(item.getType()).isAuthorized(user))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Permissions.OWNERINFO.isAuthorized(user) && event.getAction() == Action.RIGHT_CLICK_BLOCK)
|
||||
{
|
||||
final StringBuilder stringBuilder = new StringBuilder();
|
||||
boolean first = true;
|
||||
final Block blockClicked = event.getClickedBlock();
|
||||
for (String owner : prot.getStorage().getOwners(blockClicked))
|
||||
{
|
||||
if (!first)
|
||||
{
|
||||
stringBuilder.append(", ");
|
||||
}
|
||||
first = false;
|
||||
stringBuilder.append(owner);
|
||||
}
|
||||
final String ownerNames = stringBuilder.toString();
|
||||
if (ownerNames != null && !ownerNames.isEmpty())
|
||||
{
|
||||
user.sendMessage(_("protectionOwner", ownerNames));
|
||||
}
|
||||
}
|
||||
if (item != null
|
||||
&& !Permissions.ALERTS_NOTRIGGER.isAuthorized(user)
|
||||
&& settings.getData().getAlertOnUse().contains(item.getType()))
|
||||
{
|
||||
prot.getEssentialsConnect().alert(user, item.getType().toString(), _("alertUsed"));
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
settings.unlock();
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,6 +1,5 @@
|
||||
package net.ess3.protect;
|
||||
|
||||
import net.ess3.protect.data.IProtectedBlock;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
|
||||
@@ -9,9 +8,7 @@ public interface IProtect extends Plugin
|
||||
// boolean checkProtectionItems(final ProtectConfig list, final int id);
|
||||
// boolean getSettingBool(final ProtectConfig protectConfig);
|
||||
// String getSettingString(final ProtectConfig protectConfig);
|
||||
IProtectedBlock getStorage();
|
||||
|
||||
void setStorage(IProtectedBlock pb);
|
||||
|
||||
EssentialsConnect getEssentialsConnect();
|
||||
|
||||
|
@@ -1,45 +0,0 @@
|
||||
package net.ess3.protect;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import net.ess3.api.IPermission;
|
||||
import net.ess3.permissions.AbstractSuperpermsPermission;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
|
||||
public class ItemUsePermissions extends AbstractSuperpermsPermission
|
||||
{
|
||||
private static Map<Material, IPermission> permissions = new EnumMap<Material, IPermission>(Material.class);
|
||||
private static final String base = "essentials.protect.itemuse.";
|
||||
private final String permission;
|
||||
|
||||
public static IPermission getPermission(final Material mat)
|
||||
{
|
||||
IPermission perm = permissions.get(mat);
|
||||
if (perm == null)
|
||||
{
|
||||
perm = new ItemUsePermissions(mat.toString().toLowerCase(Locale.ENGLISH));
|
||||
permissions.put(mat, perm);
|
||||
}
|
||||
return perm;
|
||||
}
|
||||
|
||||
private ItemUsePermissions(final String matName)
|
||||
{
|
||||
this.permission = base + matName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionName()
|
||||
{
|
||||
return this.permission;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionDefault getPermissionDefault()
|
||||
{
|
||||
return PermissionDefault.TRUE;
|
||||
}
|
||||
}
|
@@ -3,7 +3,6 @@ package net.ess3.protect;
|
||||
import java.util.Locale;
|
||||
import net.ess3.api.IPermission;
|
||||
import net.ess3.bukkit.PermissionFactory;
|
||||
import net.ess3.utils.Util;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
@@ -11,13 +10,9 @@ import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
public enum Permissions implements IPermission
|
||||
{
|
||||
ALERTS,
|
||||
ALERTS_NOTRIGGER,
|
||||
ADMIN,
|
||||
BUILD(PermissionDefault.TRUE),
|
||||
|
||||
ADMIN,
|
||||
ENTITYTARGET(PermissionDefault.TRUE),
|
||||
INTERACT(PermissionDefault.TRUE),
|
||||
OWNERINFO,
|
||||
PVP(PermissionDefault.TRUE),
|
||||
PREVENTDAMAGE_FALL(PermissionDefault.FALSE),
|
||||
PREVENTDAMAGE_CREEPER(PermissionDefault.FALSE),
|
||||
@@ -30,8 +25,7 @@ public enum Permissions implements IPermission
|
||||
PREVENTDAMAGE_FIRE(PermissionDefault.FALSE),
|
||||
PREVENTDAMAGE_DROWNING(PermissionDefault.FALSE),
|
||||
PREVENTDAMAGE_LIGHTNING(PermissionDefault.FALSE),
|
||||
PREVENTDAMAGE_NONE(PermissionDefault.FALSE),
|
||||
RAILS(PermissionDefault.TRUE),
|
||||
PREVENTDAMAGE_NONE(PermissionDefault.FALSE),
|
||||
USEFLINTSTEEL(PermissionDefault.TRUE);
|
||||
private static final String base = "essentials.protect.";
|
||||
private final String permission;
|
||||
|
@@ -1,10 +1,10 @@
|
||||
package net.ess3.protect;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.settings.protect.Protect;
|
||||
import net.ess3.storage.AsyncStorageObjectHolder;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
public class ProtectHolder extends AsyncStorageObjectHolder<Protect>
|
||||
|
@@ -1,24 +0,0 @@
|
||||
package net.ess3.protect.data;
|
||||
|
||||
import java.util.List;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
|
||||
public interface IProtectedBlock
|
||||
{
|
||||
public void clearProtections();
|
||||
|
||||
public void importProtections(List<OwnedBlock> blocks);
|
||||
|
||||
public List<OwnedBlock> exportProtections();
|
||||
|
||||
public void protectBlock(Block block, String playerName);
|
||||
|
||||
public boolean isProtected(Block block, String playerName);
|
||||
|
||||
public List<String> getOwners(Block block);
|
||||
|
||||
public int unprotectBlock(Block block);
|
||||
|
||||
public void onPluginDeactivation();
|
||||
}
|
@@ -1,20 +0,0 @@
|
||||
package net.ess3.protect.data;
|
||||
|
||||
|
||||
public class OwnedBlock
|
||||
{
|
||||
final int x;
|
||||
final int y;
|
||||
final int z;
|
||||
final String world;
|
||||
final String playerName;
|
||||
|
||||
public OwnedBlock(int x, int y, int z, String world, String playerName)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.world = world;
|
||||
this.playerName = playerName;
|
||||
}
|
||||
}
|
@@ -1,434 +0,0 @@
|
||||
package net.ess3.protect.data;
|
||||
|
||||
import com.mchange.v2.c3p0.ComboPooledDataSource;
|
||||
import java.beans.PropertyVetoException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
|
||||
public abstract class ProtectedBlockJDBC implements IProtectedBlock
|
||||
{
|
||||
protected static final Logger LOGGER = Logger.getLogger("Minecraft");
|
||||
protected final transient ComboPooledDataSource cpds;
|
||||
|
||||
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 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 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 getStatementAllBlocks(Connection conn) throws SQLException;
|
||||
|
||||
public ProtectedBlockJDBC(final String driver, final String url) throws PropertyVetoException
|
||||
{
|
||||
this(driver, url, null, null);
|
||||
}
|
||||
|
||||
public ProtectedBlockJDBC(final String driver, final String url, final String username, final String password) throws PropertyVetoException
|
||||
{
|
||||
cpds = new ComboPooledDataSource();
|
||||
cpds.setDriverClass(driver);
|
||||
cpds.setJdbcUrl(url);
|
||||
if (username != null)
|
||||
{
|
||||
cpds.setUser(username);
|
||||
cpds.setPassword(password);
|
||||
}
|
||||
cpds.setMaxStatements(20);
|
||||
createAndConvertTable();
|
||||
}
|
||||
|
||||
private void createAndConvertTable()
|
||||
{
|
||||
Connection conn = null;
|
||||
PreparedStatement ps = null;
|
||||
try
|
||||
{
|
||||
conn = cpds.getConnection();
|
||||
ps = getStatementCreateTable(conn);
|
||||
ps.execute();
|
||||
ps.close();
|
||||
ps = getStatementUpdateFrom2_0Table(conn);
|
||||
ps.execute();
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (ps != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
ps.close();
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
if (conn != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
conn.close();
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearProtections()
|
||||
{
|
||||
Connection conn = null;
|
||||
PreparedStatement ps = null;
|
||||
try
|
||||
{
|
||||
conn = cpds.getConnection();
|
||||
ps = getStatementDeleteAll(conn);
|
||||
ps.executeUpdate();
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (ps != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
ps.close();
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
if (conn != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
conn.close();
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void importProtections(final List<OwnedBlock> blocks)
|
||||
{
|
||||
for (OwnedBlock ownedBlock : blocks)
|
||||
{
|
||||
if (ownedBlock.playerName == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
protectBlock(ownedBlock.world, ownedBlock.x, ownedBlock.y, ownedBlock.z, ownedBlock.playerName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OwnedBlock> exportProtections()
|
||||
{
|
||||
Connection conn = null;
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
List<OwnedBlock> blocks = new ArrayList<OwnedBlock>();
|
||||
try
|
||||
{
|
||||
conn = cpds.getConnection();
|
||||
ps = getStatementAllBlocks(conn);
|
||||
rs = ps.executeQuery();
|
||||
while (rs.next())
|
||||
{
|
||||
OwnedBlock ob = new OwnedBlock(
|
||||
rs.getInt(2),
|
||||
rs.getInt(3),
|
||||
rs.getInt(4),
|
||||
rs.getString(1),
|
||||
rs.getString(5));
|
||||
blocks.add(ob);
|
||||
}
|
||||
return blocks;
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, null, ex);
|
||||
return blocks;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (rs != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
rs.close();
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
if (ps != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
ps.close();
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
if (conn != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
conn.close();
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void protectBlock(final Block block, final String playerName)
|
||||
{
|
||||
protectBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), playerName);
|
||||
}
|
||||
|
||||
private void protectBlock(final String world, final int x, final int y, final int z, final String playerName)
|
||||
{
|
||||
Connection conn = null;
|
||||
PreparedStatement ps = null;
|
||||
try
|
||||
{
|
||||
conn = cpds.getConnection();
|
||||
ps = getStatementInsert(conn, world, x, y, z, playerName);
|
||||
ps.executeUpdate();
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (ps != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
ps.close();
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
if (conn != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
conn.close();
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isProtected(final Block block, final String playerName)
|
||||
{
|
||||
Connection conn = null;
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
try
|
||||
{
|
||||
conn = cpds.getConnection();
|
||||
ps = getStatementPlayerCountByLocation(conn, block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), playerName);
|
||||
rs = ps.executeQuery();
|
||||
return rs.next() && rs.getInt(1) > 0 && rs.getInt(2) == 0;
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, null, ex);
|
||||
return true;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (rs != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
rs.close();
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
if (ps != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
ps.close();
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
if (conn != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
conn.close();
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getOwners(final Block block)
|
||||
{
|
||||
Connection conn = null;
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
List<String> owners = new ArrayList<String>();
|
||||
try
|
||||
{
|
||||
conn = cpds.getConnection();
|
||||
ps = getStatementPlayersByLocation(conn, block.getWorld().getName(), block.getX(), block.getY(), block.getZ());
|
||||
rs = ps.executeQuery();
|
||||
while (rs.next())
|
||||
{
|
||||
owners.add(rs.getString(1));
|
||||
}
|
||||
return owners;
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, null, ex);
|
||||
return owners;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (rs != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
rs.close();
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
if (ps != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
ps.close();
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
if (conn != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
conn.close();
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int unprotectBlock(final Block block)
|
||||
{
|
||||
Connection conn = null;
|
||||
PreparedStatement ps = null;
|
||||
try
|
||||
{
|
||||
conn = cpds.getConnection();
|
||||
ps = getStatementDeleteByLocation(conn, block.getWorld().getName(), block.getX(), block.getY(), block.getZ());
|
||||
return ps.executeUpdate();
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, null, ex);
|
||||
return 0;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (ps != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
ps.close();
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
if (conn != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
conn.close();
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPluginDeactivation()
|
||||
{
|
||||
cpds.close();
|
||||
}
|
||||
}
|
@@ -1,258 +0,0 @@
|
||||
package net.ess3.protect.data;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
|
||||
public final class ProtectedBlockMemory implements IProtectedBlock
|
||||
{
|
||||
private final transient List<String> worlds = new ArrayList<String>();
|
||||
private final transient List<String> playerNames = new ArrayList<String>();
|
||||
private final transient IProtectedBlock storage;
|
||||
private final transient Plugin plugin;
|
||||
|
||||
|
||||
static class ProtectedLocation
|
||||
{
|
||||
private final transient int x;
|
||||
private final transient int y;
|
||||
private final transient int z;
|
||||
private final transient int w;
|
||||
|
||||
public ProtectedLocation(final Block block, final int worldId)
|
||||
{
|
||||
this.x = block.getX();
|
||||
this.y = block.getY();
|
||||
this.z = block.getZ();
|
||||
this.w = worldId;
|
||||
}
|
||||
|
||||
public ProtectedLocation(final OwnedBlock ownedBlock, final int worldId)
|
||||
{
|
||||
this.x = ownedBlock.x;
|
||||
this.y = ownedBlock.y;
|
||||
this.z = ownedBlock.z;
|
||||
this.w = worldId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object object)
|
||||
{
|
||||
if (object instanceof ProtectedLocation)
|
||||
{
|
||||
final ProtectedLocation pLoc = (ProtectedLocation)object;
|
||||
return x == pLoc.x && y == pLoc.y && z == pLoc.z && w == pLoc.w;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return x ^ y ^ z ^ w;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static class ProtectedBy
|
||||
{
|
||||
private transient int playerId = -1;
|
||||
private transient Set<Integer> playerIds;
|
||||
|
||||
public void add(final int playerId)
|
||||
{
|
||||
if (this.playerId == -1 || this.playerId == playerId)
|
||||
{
|
||||
this.playerId = playerId;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (playerIds == null)
|
||||
{
|
||||
playerIds = new HashSet<Integer>(4);
|
||||
playerIds.add(this.playerId);
|
||||
}
|
||||
playerIds.add(playerId);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean contains(final int playerId)
|
||||
{
|
||||
if (playerIds == null)
|
||||
{
|
||||
return this.playerId == playerId;
|
||||
}
|
||||
return playerIds.contains(playerId);
|
||||
}
|
||||
|
||||
public List<String> getPlayers(final List<String> playerNames)
|
||||
{
|
||||
final List<String> list = new ArrayList<String>(2);
|
||||
if (playerIds == null)
|
||||
{
|
||||
list.add(playerNames.get(playerId));
|
||||
}
|
||||
else
|
||||
{
|
||||
for (Integer integer : playerIds)
|
||||
{
|
||||
list.add(playerNames.get(integer));
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public int size()
|
||||
{
|
||||
if (playerIds == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return playerIds.size();
|
||||
}
|
||||
}
|
||||
private final transient Map<ProtectedLocation, ProtectedBy> blocks = new HashMap<ProtectedLocation, ProtectedBy>();
|
||||
|
||||
public ProtectedBlockMemory(final IProtectedBlock storage, final Plugin plugin)
|
||||
{
|
||||
this.storage = storage;
|
||||
this.plugin = plugin;
|
||||
importProtections(storage.exportProtections());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearProtections()
|
||||
{
|
||||
blocks.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void importProtections(final List<OwnedBlock> blocks)
|
||||
{
|
||||
for (OwnedBlock ownedBlock : blocks)
|
||||
{
|
||||
final ProtectedLocation pl = new ProtectedLocation(ownedBlock, getWorldId(ownedBlock.world));
|
||||
if (ownedBlock.playerName == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
protectBlock(pl, ownedBlock.playerName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OwnedBlock> exportProtections()
|
||||
{
|
||||
final List<OwnedBlock> blockList = new ArrayList<OwnedBlock>(blocks.size());
|
||||
for (Entry<ProtectedLocation, ProtectedBy> entry : blocks.entrySet())
|
||||
{
|
||||
for (String name : entry.getValue().getPlayers(playerNames))
|
||||
{
|
||||
final OwnedBlock ob = new OwnedBlock(
|
||||
entry.getKey().x,
|
||||
entry.getKey().y,
|
||||
entry.getKey().z,
|
||||
worlds.get(entry.getKey().w),
|
||||
name);
|
||||
blockList.add(ob);
|
||||
}
|
||||
}
|
||||
return blockList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void protectBlock(final Block block, final String playerName)
|
||||
{
|
||||
final ProtectedLocation pl = new ProtectedLocation(block, getWorldId(block.getWorld()));
|
||||
protectBlock(pl, playerName);
|
||||
plugin.getServer().getScheduler().scheduleAsyncDelayedTask(plugin, new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
storage.protectBlock(block, playerName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void protectBlock(final ProtectedLocation pl, final String playerName)
|
||||
{
|
||||
final int playerId = getPlayerId(playerName);
|
||||
ProtectedBy pb = blocks.get(pl);
|
||||
if (pb == null)
|
||||
{
|
||||
pb = new ProtectedBy();
|
||||
blocks.put(pl, pb);
|
||||
}
|
||||
pb.add(playerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isProtected(final Block block, final String playerName)
|
||||
{
|
||||
final int playerId = getPlayerId(playerName);
|
||||
final ProtectedLocation pl = new ProtectedLocation(block, getWorldId(block.getWorld()));
|
||||
final ProtectedBy pb = blocks.get(pl);
|
||||
return !pb.contains(playerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getOwners(final Block block)
|
||||
{
|
||||
ProtectedLocation pl = new ProtectedLocation(block, getWorldId(block.getWorld()));
|
||||
ProtectedBy pb = blocks.get(pl);
|
||||
return pb.getPlayers(playerNames);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int unprotectBlock(final Block block)
|
||||
{
|
||||
final ProtectedLocation pl = new ProtectedLocation(block, getWorldId(block.getWorld()));
|
||||
final ProtectedBy pb = blocks.remove(pl);
|
||||
plugin.getServer().getScheduler().scheduleAsyncDelayedTask(plugin, new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
storage.unprotectBlock(block);
|
||||
}
|
||||
});
|
||||
return pb.size();
|
||||
}
|
||||
|
||||
private int getPlayerId(final String playername)
|
||||
{
|
||||
int id = playerNames.indexOf(playername);
|
||||
if (id < 0)
|
||||
{
|
||||
playerNames.add(playername);
|
||||
id = playerNames.indexOf(playername);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
private int getWorldId(final World world)
|
||||
{
|
||||
return getWorldId(world.getName());
|
||||
}
|
||||
|
||||
private int getWorldId(final String name)
|
||||
{
|
||||
int id = worlds.indexOf(name);
|
||||
if (id < 0)
|
||||
{
|
||||
worlds.add(name);
|
||||
id = worlds.indexOf(name);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPluginDeactivation()
|
||||
{
|
||||
storage.onPluginDeactivation();
|
||||
}
|
||||
}
|
@@ -1,160 +0,0 @@
|
||||
package net.ess3.protect.data;
|
||||
|
||||
import java.beans.PropertyVetoException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
||||
public class ProtectedBlockMySQL extends ProtectedBlockJDBC
|
||||
{
|
||||
public ProtectedBlockMySQL(final String url, final String username, final String password) throws PropertyVetoException
|
||||
{
|
||||
super("com.mysql.jdbc.Driver", url, username, password);
|
||||
}
|
||||
private static final String QueryCreateTable =
|
||||
"CREATE TABLE IF NOT EXISTS `EssentialsProtect` ("
|
||||
+ "`worldName` varchar(60) NOT NULL,"
|
||||
+ "`x` int(11) NOT NULL, `y` int(11) NOT NULL, `z` int(11) NOT NULL,"
|
||||
+ "`playerName` varchar(150) DEFAULT NULL,"
|
||||
+ "KEY `pos` (`worldName`,`x`,`z`,`y`)"
|
||||
+ ") ENGINE=MyISAM DEFAULT CHARSET=utf8";
|
||||
|
||||
@Override
|
||||
protected PreparedStatement getStatementCreateTable(final Connection conn) throws SQLException
|
||||
{
|
||||
return conn.prepareStatement(QueryCreateTable);
|
||||
}
|
||||
private static final String QueryUpdateFrom2_0TableCheck =
|
||||
"SHOW COLUMNS FROM `EssentialsProtect` LIKE 'id';";
|
||||
private static final String QueryUpdateFrom2_0Table =
|
||||
"ALTER TABLE `EssentialsProtect` "
|
||||
+ "CHARACTER SET = utf8, ENGINE = MyISAM,"
|
||||
+ "DROP COLUMN `id`,"
|
||||
+ "CHANGE COLUMN `playerName` `playerName` VARCHAR(150) NULL AFTER `z`,"
|
||||
+ "CHANGE COLUMN `worldName` `worldName` VARCHAR(60) NOT NULL,"
|
||||
+ "ADD INDEX `position` (`worldName` ASC, `x` ASC, `z` ASC, `y` ASC),"
|
||||
+ "DROP PRIMARY KEY ;";
|
||||
|
||||
@Override
|
||||
protected PreparedStatement getStatementUpdateFrom2_0Table(final Connection conn) throws SQLException
|
||||
{
|
||||
PreparedStatement testPS = null;
|
||||
ResultSet testRS = null;
|
||||
try
|
||||
{
|
||||
testPS = conn.prepareStatement(QueryUpdateFrom2_0TableCheck);
|
||||
testRS = testPS.executeQuery();
|
||||
if (testRS.first())
|
||||
{
|
||||
return conn.prepareStatement(QueryUpdateFrom2_0Table);
|
||||
}
|
||||
else
|
||||
{
|
||||
return conn.prepareStatement("SELECT 1;");
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (testRS != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
testRS.close();
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
Logger.getLogger(ProtectedBlockMySQL.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
if (testPS != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
testPS.close();
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
Logger.getLogger(ProtectedBlockMySQL.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private static final String QueryDeleteAll = "DELETE FROM EssentialsProtect;";
|
||||
|
||||
@Override
|
||||
protected PreparedStatement getStatementDeleteAll(final Connection conn) throws SQLException
|
||||
{
|
||||
return conn.prepareStatement(QueryDeleteAll);
|
||||
}
|
||||
private static final String QueryInsert =
|
||||
"INSERT INTO EssentialsProtect (worldName, x, y, z, playerName) VALUES (?, ?, ?, ?, ?);";
|
||||
|
||||
@Override
|
||||
protected PreparedStatement getStatementInsert(final Connection conn, final String world, final int x, final int y, final int z,
|
||||
final String playerName) throws SQLException
|
||||
{
|
||||
final PreparedStatement ps = conn.prepareStatement(QueryInsert);
|
||||
ps.setString(1, world);
|
||||
ps.setInt(2, x);
|
||||
ps.setInt(3, y);
|
||||
ps.setInt(4, z);
|
||||
ps.setString(5, playerName);
|
||||
return ps;
|
||||
}
|
||||
private static final String QueryCountByPlayer =
|
||||
"SELECT COUNT(playerName), SUM(playerName = ?) FROM EssentialsProtect "
|
||||
+ "WHERE worldName = ? AND x = ? AND y = ? AND z = ? GROUP BY x;";
|
||||
|
||||
@Override
|
||||
protected PreparedStatement getStatementPlayerCountByLocation(final Connection conn, final String world, final int x, final int y, final int z,
|
||||
final String playerName) throws SQLException
|
||||
{
|
||||
final PreparedStatement ps = conn.prepareStatement(QueryCountByPlayer);
|
||||
ps.setString(1, playerName);
|
||||
ps.setString(2, world);
|
||||
ps.setInt(3, x);
|
||||
ps.setInt(4, y);
|
||||
ps.setInt(5, z);
|
||||
return ps;
|
||||
}
|
||||
private static final String QueryPlayersByLocation =
|
||||
"SELECT playerName FROM EssentialsProtect WHERE worldname = ? AND x = ? AND y = ? AND z = ?;";
|
||||
|
||||
@Override
|
||||
protected PreparedStatement getStatementPlayersByLocation(final Connection conn, final String world,
|
||||
final int x, final int y, final int z) throws SQLException
|
||||
{
|
||||
final PreparedStatement ps = conn.prepareStatement(QueryPlayersByLocation);
|
||||
ps.setString(1, world);
|
||||
ps.setInt(2, x);
|
||||
ps.setInt(3, y);
|
||||
ps.setInt(4, z);
|
||||
return ps;
|
||||
}
|
||||
private static final String QueryDeleteByLocation =
|
||||
"DELETE FROM EssentialsProtect WHERE worldName = ? AND x = ? AND y = ? AND z = ?;";
|
||||
|
||||
@Override
|
||||
protected PreparedStatement getStatementDeleteByLocation(final Connection conn, final String world,
|
||||
final int x, final int y, final int z) throws SQLException
|
||||
{
|
||||
final PreparedStatement ps = conn.prepareStatement(QueryDeleteByLocation);
|
||||
ps.setString(1, world);
|
||||
ps.setInt(2, x);
|
||||
ps.setInt(3, y);
|
||||
ps.setInt(4, z);
|
||||
return ps;
|
||||
}
|
||||
private static final String QueryAllBlocks =
|
||||
"SELECT worldName, x, y, z, playerName FROM EssentialsProtect;";
|
||||
|
||||
@Override
|
||||
protected PreparedStatement getStatementAllBlocks(final Connection conn) throws SQLException
|
||||
{
|
||||
return conn.prepareStatement(QueryAllBlocks);
|
||||
}
|
||||
}
|
@@ -1,108 +0,0 @@
|
||||
package net.ess3.protect.data;
|
||||
|
||||
import java.beans.PropertyVetoException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
|
||||
public class ProtectedBlockSQLite extends ProtectedBlockJDBC
|
||||
{
|
||||
public ProtectedBlockSQLite(final String url) throws PropertyVetoException
|
||||
{
|
||||
super("org.sqlite.JDBC", url);
|
||||
}
|
||||
private static final String QueryCreateTable =
|
||||
"CREATE TABLE IF NOT EXISTS EssentialsProtect ("
|
||||
+ "worldName TEXT ,playerName TEXT, "
|
||||
+ "x NUMERIC, y NUMERIC, z NUMERIC)";
|
||||
|
||||
@Override
|
||||
protected PreparedStatement getStatementCreateTable(final Connection conn) throws SQLException
|
||||
{
|
||||
return conn.prepareStatement(QueryCreateTable);
|
||||
}
|
||||
private static final String QueryUpdateFrom2_0Table =
|
||||
"CREATE INDEX IF NOT EXISTS position ON EssentialsProtect ("
|
||||
+ "worldName, x, z, y)";
|
||||
|
||||
@Override
|
||||
protected PreparedStatement getStatementUpdateFrom2_0Table(final Connection conn) throws SQLException
|
||||
{
|
||||
return conn.prepareStatement(QueryUpdateFrom2_0Table);
|
||||
}
|
||||
private static final String QueryDeleteAll = "DELETE FROM EssentialsProtect;";
|
||||
|
||||
@Override
|
||||
protected PreparedStatement getStatementDeleteAll(final Connection conn) throws SQLException
|
||||
{
|
||||
return conn.prepareStatement(QueryDeleteAll);
|
||||
}
|
||||
private static final String QueryInsert =
|
||||
"INSERT INTO EssentialsProtect (worldName, x, y, z, playerName) VALUES (?, ?, ?, ?, ?);";
|
||||
|
||||
@Override
|
||||
protected PreparedStatement getStatementInsert(final Connection conn, final String world,
|
||||
final int x, final int y, final int z, final String playerName) throws SQLException
|
||||
{
|
||||
final PreparedStatement ps = conn.prepareStatement(QueryInsert);
|
||||
ps.setString(1, world);
|
||||
ps.setInt(2, x);
|
||||
ps.setInt(3, y);
|
||||
ps.setInt(4, z);
|
||||
ps.setString(5, playerName);
|
||||
return ps;
|
||||
}
|
||||
private static final String QueryPlayerCountByLocation =
|
||||
"SELECT COUNT(playerName), SUM(playerName = ?) FROM EssentialsProtect "
|
||||
+ "WHERE worldName = ? AND x = ? AND y = ? AND z = ? GROUP BY x;";
|
||||
|
||||
@Override
|
||||
protected PreparedStatement getStatementPlayerCountByLocation(final Connection conn, final String world,
|
||||
final int x, final int y, final int z, final String playerName) throws SQLException
|
||||
{
|
||||
final PreparedStatement ps = conn.prepareStatement(QueryPlayerCountByLocation);
|
||||
ps.setString(1, playerName);
|
||||
ps.setString(2, world);
|
||||
ps.setInt(3, x);
|
||||
ps.setInt(4, y);
|
||||
ps.setInt(5, z);
|
||||
return ps;
|
||||
}
|
||||
private static final String QueryPlayersByLocation =
|
||||
"SELECT playerName FROM EssentialsProtect WHERE worldname = ? AND x = ? AND y = ? AND z = ?;";
|
||||
|
||||
@Override
|
||||
protected PreparedStatement getStatementPlayersByLocation(final Connection conn, final String world,
|
||||
final int x, final int y, final int z) throws SQLException
|
||||
{
|
||||
final PreparedStatement ps = conn.prepareStatement(QueryPlayersByLocation);
|
||||
ps.setString(1, world);
|
||||
ps.setInt(2, x);
|
||||
ps.setInt(3, y);
|
||||
ps.setInt(4, z);
|
||||
return ps;
|
||||
}
|
||||
private static final String QueryDeleteByLocation =
|
||||
"DELETE FROM EssentialsProtect WHERE worldName = ? AND x = ? AND y = ? AND z = ?;";
|
||||
|
||||
@Override
|
||||
protected PreparedStatement getStatementDeleteByLocation(final Connection conn, final String world,
|
||||
final int x, final int y, final int z) throws SQLException
|
||||
{
|
||||
final PreparedStatement ps = conn.prepareStatement(QueryDeleteByLocation);
|
||||
ps.setString(1, world);
|
||||
ps.setInt(2, x);
|
||||
ps.setInt(3, y);
|
||||
ps.setInt(4, z);
|
||||
return ps;
|
||||
}
|
||||
private static final String QueryAllBlocks =
|
||||
"SELECT worldName, x, y, z, playerName FROM EssentialsProtect;";
|
||||
|
||||
@Override
|
||||
protected PreparedStatement getStatementAllBlocks(final Connection conn) throws SQLException
|
||||
{
|
||||
return conn.prepareStatement(QueryAllBlocks);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user