1
0
mirror of https://github.com/essentials/Essentials.git synced 2025-08-14 02:24:16 +02:00

Clean up protect :: transient is not needed :: remove unnecessary returns :: @Override all the things!

This commit is contained in:
Iaccidentally
2013-02-12 18:37:40 -05:00
parent c2d904ac7d
commit ec8c778f68
8 changed files with 1771 additions and 1786 deletions

View File

@@ -1,12 +1,12 @@
package com.earth2me.essentials.protect; package com.earth2me.essentials.protect;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.IConf; import com.earth2me.essentials.IConf;
import com.earth2me.essentials.IEssentials; import com.earth2me.essentials.IEssentials;
import com.earth2me.essentials.protect.data.ProtectedBlockMemory; import com.earth2me.essentials.protect.data.ProtectedBlockMemory;
import com.earth2me.essentials.protect.data.ProtectedBlockMySQL; import com.earth2me.essentials.protect.data.ProtectedBlockMySQL;
import com.earth2me.essentials.protect.data.ProtectedBlockSQLite; import com.earth2me.essentials.protect.data.ProtectedBlockSQLite;
import java.beans.PropertyVetoException; import java.beans.PropertyVetoException;
import static com.earth2me.essentials.I18n._;
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;
@@ -15,8 +15,8 @@ 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)
{ {
@@ -31,16 +31,11 @@ public class EssentialsConnect
ess.addReloadListener(pr); ess.addReloadListener(pr);
} }
public void onDisable()
{
}
public IEssentials getEssentials() public IEssentials getEssentials()
{ {
return ess; return ess;
} }
private class ProtectReloader implements IConf private class ProtectReloader implements IConf
{ {
@Override @Override

View File

@@ -6,9 +6,7 @@ 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.LogRecord;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
@@ -20,11 +18,11 @@ public class EssentialsProtect extends JavaPlugin implements IProtect
{ {
private static final Logger LOGGER = Logger.getLogger("Minecraft"); private static final Logger LOGGER = Logger.getLogger("Minecraft");
private static com.mchange.v2.log.MLogger C3P0logger; private static com.mchange.v2.log.MLogger C3P0logger;
private final transient Map<ProtectConfig, Boolean> settingsBoolean = new EnumMap<ProtectConfig, Boolean>(ProtectConfig.class); private final 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 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 final Map<ProtectConfig, List<Integer>> settingsList = new EnumMap<ProtectConfig, List<Integer>>(ProtectConfig.class);
private transient IProtectedBlock storage = null; private IProtectedBlock storage = null;
private transient EssentialsConnect ess = null; private EssentialsConnect ess = null;
@Override @Override
public void onLoad() public void onLoad()
@@ -45,6 +43,7 @@ public class EssentialsProtect extends JavaPlugin implements IProtect
C3P0logger.setLevel(MLevel.WARNING); C3P0logger.setLevel(MLevel.WARNING);
} }
@Override
public void onEnable() public void onEnable()
{ {
final PluginManager pm = this.getServer().getPluginManager(); final PluginManager pm = this.getServer().getPluginManager();
@@ -93,21 +92,25 @@ public class EssentialsProtect extends JavaPlugin implements IProtect
storage = pb; storage = pb;
} }
@Override
public EssentialsConnect getEssentialsConnect() public EssentialsConnect getEssentialsConnect()
{ {
return ess; return ess;
} }
@Override
public Map<ProtectConfig, Boolean> getSettingsBoolean() public Map<ProtectConfig, Boolean> getSettingsBoolean()
{ {
return settingsBoolean; return settingsBoolean;
} }
@Override
public Map<ProtectConfig, String> getSettingsString() public Map<ProtectConfig, String> getSettingsString()
{ {
return settingsString; return settingsString;
} }
@Override
public Map<ProtectConfig, List<Integer>> getSettingsList() public Map<ProtectConfig, List<Integer>> getSettingsList()
{ {
return settingsList; return settingsList;
@@ -127,6 +130,7 @@ public class EssentialsProtect extends JavaPlugin implements IProtect
return str == null ? protectConfig.getDefaultValueString() : str; return str == null ? protectConfig.getDefaultValueString() : str;
} }
@Override
public void onDisable() public void onDisable()
{ {
if (storage != null) if (storage != null)
@@ -140,6 +144,7 @@ public class EssentialsProtect extends JavaPlugin implements IProtect
} }
catch (InterruptedException ex) catch (InterruptedException ex)
{ {
Logger.getLogger(EssentialsProtect.class.getName()).log(Level.SEVERE, null, ex);
} }
} }
} }

View File

@@ -16,8 +16,8 @@ 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)
{ {
@@ -29,11 +29,7 @@ public class EssentialsProtectBlockListener implements Listener
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 int id = blockPlaced.getTypeId();
final Block below = blockPlaced.getRelative(BlockFace.DOWN); final Block below = blockPlaced.getRelative(BlockFace.DOWN);
if ((below.getType() == Material.RAILS || below.getType() == Material.POWERED_RAIL || below.getType() == Material.DETECTOR_RAIL) if ((below.getType() == Material.RAILS || below.getType() == Material.POWERED_RAIL || below.getType() == Material.DETECTOR_RAIL)
&& prot.getSettingBool(ProtectConfig.prevent_block_on_rail) && prot.getSettingBool(ProtectConfig.prevent_block_on_rail)
@@ -117,7 +113,6 @@ public class EssentialsProtectBlockListener implements Listener
if (event.getCause().equals(BlockIgniteEvent.IgniteCause.LIGHTNING)) if (event.getCause().equals(BlockIgniteEvent.IgniteCause.LIGHTNING))
{ {
event.setCancelled(prot.getSettingBool(ProtectConfig.prevent_lightning_fire_spread)); event.setCancelled(prot.getSettingBool(ProtectConfig.prevent_lightning_fire_spread));
return;
} }
} }
@@ -154,7 +149,6 @@ public class EssentialsProtectBlockListener implements Listener
if (block.getType() == Material.AIR) if (block.getType() == Material.AIR)
{ {
event.setCancelled(prot.getSettingBool(ProtectConfig.prevent_water_bucket_flow)); event.setCancelled(prot.getSettingBool(ProtectConfig.prevent_water_bucket_flow));
return;
} }
} }
@@ -176,7 +170,6 @@ public class EssentialsProtectBlockListener implements Listener
if (prot.getSettingBool(ProtectConfig.prevent_fire_spread)) if (prot.getSettingBool(ProtectConfig.prevent_fire_spread))
{ {
event.setCancelled(true); event.setCancelled(true);
return;
} }
} }
private final static BlockFace[] faces = new BlockFace[] private final static BlockFace[] faces = new BlockFace[]
@@ -194,12 +187,8 @@ public class EssentialsProtectBlockListener implements Listener
public void onBlockBreak(final BlockBreakEvent event) public void onBlockBreak(final BlockBreakEvent event)
{ {
final User user = ess.getUser(event.getPlayer()); final User user = ess.getUser(event.getPlayer());
final Block block = event.getBlock(); final Block block = event.getBlock();
final int typeId = block.getTypeId();
final Material type = block.getType(); final Material type = block.getType();
final IProtectedBlock storage = prot.getStorage(); final IProtectedBlock storage = prot.getStorage();
if (user.isAuthorized("essentials.protect.admin")) if (user.isAuthorized("essentials.protect.admin"))

View File

@@ -17,8 +17,8 @@ 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)
{ {
@@ -169,7 +169,6 @@ public class EssentialsProtectEntityListener implements Listener
&& !shouldBeDamaged(user, "wither")) && !shouldBeDamaged(user, "wither"))
{ {
event.setCancelled(true); event.setCancelled(true);
return;
} }
} }
} }
@@ -307,7 +306,6 @@ public class EssentialsProtectEntityListener implements Listener
&& !user.isAuthorized("essentials.protect.entitytarget.bypass")) && !user.isAuthorized("essentials.protect.entitytarget.bypass"))
{ {
event.setCancelled(true); event.setCancelled(true);
return;
} }
} }
@@ -332,7 +330,6 @@ public class EssentialsProtectEntityListener implements Listener
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;
} }
} }
} }

View File

@@ -13,8 +13,8 @@ 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)
{ {

View File

@@ -10,7 +10,7 @@ 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)
{ {
@@ -25,7 +25,6 @@ public class EssentialsProtectWeatherListener implements Listener
{ {
event.setCancelled(true); event.setCancelled(true);
} }
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)

View File

@@ -16,22 +16,14 @@ 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 getStatementUpdateFrom2_0Table(Connection conn) throws SQLException;
protected abstract PreparedStatement getStatementDeleteAll(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 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 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 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 getStatementDeleteByLocation(Connection conn, String world, int x, int y, int z) throws SQLException;
protected abstract PreparedStatement getStatementAllBlocks(Connection conn) throws SQLException; protected abstract PreparedStatement getStatementAllBlocks(Connection conn) throws SQLException;
public ProtectedBlockJDBC(String driver, String url) throws PropertyVetoException public ProtectedBlockJDBC(String driver, String url) throws PropertyVetoException
@@ -97,6 +89,7 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock
} }
} }
@Override
public void clearProtections() public void clearProtections()
{ {
Connection conn = null; Connection conn = null;
@@ -138,6 +131,7 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock
} }
} }
@Override
public void importProtections(List<OwnedBlock> blocks) public void importProtections(List<OwnedBlock> blocks)
{ {
for (OwnedBlock ownedBlock : blocks) for (OwnedBlock ownedBlock : blocks)
@@ -150,6 +144,7 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock
} }
} }
@Override
public List<OwnedBlock> exportProtections() public List<OwnedBlock> exportProtections()
{ {
Connection conn = null; Connection conn = null;
@@ -216,6 +211,7 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock
} }
} }
@Override
public void protectBlock(Block block, String playerName) public void protectBlock(Block block, String playerName)
{ {
protectBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), playerName); protectBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), playerName);
@@ -262,6 +258,7 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock
} }
} }
@Override
public boolean isProtected(Block block, String playerName) public boolean isProtected(Block block, String playerName)
{ {
Connection conn = null; Connection conn = null;
@@ -317,6 +314,7 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock
} }
} }
@Override
public List<String> getOwners(Block block) public List<String> getOwners(Block block)
{ {
Connection conn = null; Connection conn = null;
@@ -377,6 +375,7 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock
} }
} }
@Override
public int unprotectBlock(Block block) public int unprotectBlock(Block block)
{ {
Connection conn = null; Connection conn = null;
@@ -419,6 +418,7 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock
} }
} }
@Override
public void onPluginDeactivation() public void onPluginDeactivation()
{ {
cpds.close(); cpds.close();

View File

@@ -9,18 +9,18 @@ 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)
{ {
@@ -59,8 +59,8 @@ public class ProtectedBlockMemory implements IProtectedBlock
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)
{ {
@@ -114,7 +114,7 @@ public class ProtectedBlockMemory implements IProtectedBlock
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)
{ {