1
0
mirror of https://github.com/essentials/Essentials.git synced 2025-08-13 01:54:25 +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;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.IConf;
import com.earth2me.essentials.IEssentials;
import com.earth2me.essentials.protect.data.ProtectedBlockMemory;
import com.earth2me.essentials.protect.data.ProtectedBlockMySQL;
import com.earth2me.essentials.protect.data.ProtectedBlockSQLite;
import java.beans.PropertyVetoException;
import static com.earth2me.essentials.I18n._;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.plugin.Plugin;
@@ -15,8 +15,8 @@ import org.bukkit.plugin.Plugin;
public class EssentialsConnect
{
private static final Logger LOGGER = Logger.getLogger("Minecraft");
private final transient IEssentials ess;
private final transient IProtect protect;
private final IEssentials ess;
private final IProtect protect;
public EssentialsConnect(Plugin essPlugin, Plugin essProtect)
{
@@ -31,16 +31,11 @@ public class EssentialsConnect
ess.addReloadListener(pr);
}
public void onDisable()
{
}
public IEssentials getEssentials()
{
return ess;
}
private class ProtectReloader implements IConf
{
@Override

View File

@@ -6,9 +6,7 @@ import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
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;
@@ -20,11 +18,11 @@ 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 final Map<ProtectConfig, Boolean> settingsBoolean = new EnumMap<ProtectConfig, Boolean>(ProtectConfig.class);
private final Map<ProtectConfig, String> settingsString = new EnumMap<ProtectConfig, String>(ProtectConfig.class);
private final Map<ProtectConfig, List<Integer>> settingsList = new EnumMap<ProtectConfig, List<Integer>>(ProtectConfig.class);
private IProtectedBlock storage = null;
private EssentialsConnect ess = null;
@Override
public void onLoad()
@@ -45,6 +43,7 @@ public class EssentialsProtect extends JavaPlugin implements IProtect
C3P0logger.setLevel(MLevel.WARNING);
}
@Override
public void onEnable()
{
final PluginManager pm = this.getServer().getPluginManager();
@@ -93,21 +92,25 @@ public class EssentialsProtect extends JavaPlugin implements IProtect
storage = pb;
}
@Override
public EssentialsConnect getEssentialsConnect()
{
return ess;
}
@Override
public Map<ProtectConfig, Boolean> getSettingsBoolean()
{
return settingsBoolean;
}
@Override
public Map<ProtectConfig, String> getSettingsString()
{
return settingsString;
}
@Override
public Map<ProtectConfig, List<Integer>> getSettingsList()
{
return settingsList;
@@ -127,6 +130,7 @@ public class EssentialsProtect extends JavaPlugin implements IProtect
return str == null ? protectConfig.getDefaultValueString() : str;
}
@Override
public void onDisable()
{
if (storage != null)
@@ -140,6 +144,7 @@ public class EssentialsProtect extends JavaPlugin implements IProtect
}
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
{
final private transient IProtect prot;
final private transient IEssentials ess;
final private IProtect prot;
final private IEssentials ess;
public EssentialsProtectBlockListener(final IProtect parent)
{
@@ -29,11 +29,7 @@ public class EssentialsProtectBlockListener implements Listener
public void onBlockPlace(final BlockPlaceEvent event)
{
final User user = ess.getUser(event.getPlayer());
final Block blockPlaced = event.getBlockPlaced();
final int id = blockPlaced.getTypeId();
final Block below = blockPlaced.getRelative(BlockFace.DOWN);
if ((below.getType() == Material.RAILS || below.getType() == Material.POWERED_RAIL || below.getType() == Material.DETECTOR_RAIL)
&& prot.getSettingBool(ProtectConfig.prevent_block_on_rail)
@@ -117,7 +113,6 @@ public class EssentialsProtectBlockListener implements Listener
if (event.getCause().equals(BlockIgniteEvent.IgniteCause.LIGHTNING))
{
event.setCancelled(prot.getSettingBool(ProtectConfig.prevent_lightning_fire_spread));
return;
}
}
@@ -154,7 +149,6 @@ public class EssentialsProtectBlockListener implements Listener
if (block.getType() == Material.AIR)
{
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))
{
event.setCancelled(true);
return;
}
}
private final static BlockFace[] faces = new BlockFace[]
@@ -194,12 +187,8 @@ public class EssentialsProtectBlockListener implements Listener
public void onBlockBreak(final BlockBreakEvent event)
{
final User user = ess.getUser(event.getPlayer());
final Block block = event.getBlock();
final int typeId = block.getTypeId();
final Material type = block.getType();
final IProtectedBlock storage = prot.getStorage();
if (user.isAuthorized("essentials.protect.admin"))

View File

@@ -17,8 +17,8 @@ import org.bukkit.event.entity.EntityTargetEvent.TargetReason;
public class EssentialsProtectEntityListener implements Listener
{
private final transient IProtect prot;
private final transient IEssentials ess;
private final IProtect prot;
private final IEssentials ess;
public EssentialsProtectEntityListener(final IProtect prot)
{
@@ -169,7 +169,6 @@ public class EssentialsProtectEntityListener implements Listener
&& !shouldBeDamaged(user, "wither"))
{
event.setCancelled(true);
return;
}
}
}
@@ -307,7 +306,6 @@ public class EssentialsProtectEntityListener implements Listener
&& !user.isAuthorized("essentials.protect.entitytarget.bypass"))
{
event.setCancelled(true);
return;
}
}
@@ -332,7 +330,6 @@ public class EssentialsProtectEntityListener implements Listener
if (event.getEntityType() == EntityType.WITHER && prot.getSettingBool(ProtectConfig.prevent_wither_blockreplace))
{
event.setCancelled(true);
return;
}
}
}

View File

@@ -13,8 +13,8 @@ import org.bukkit.event.player.PlayerInteractEvent;
public class EssentialsProtectPlayerListener implements Listener
{
private final transient IProtect prot;
private final transient IEssentials ess;
private final IProtect prot;
private final IEssentials ess;
public EssentialsProtectPlayerListener(final IProtect prot)
{

View File

@@ -10,7 +10,7 @@ import org.bukkit.event.weather.WeatherChangeEvent;
public class EssentialsProtectWeatherListener implements Listener
{
private final transient IProtect prot;
private final IProtect prot;
public EssentialsProtectWeatherListener(final IProtect prot)
{
@@ -25,7 +25,6 @@ public class EssentialsProtectWeatherListener implements Listener
{
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)

View File

@@ -16,22 +16,14 @@ 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 final 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(String driver, String url) throws PropertyVetoException
@@ -97,6 +89,7 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock
}
}
@Override
public void clearProtections()
{
Connection conn = null;
@@ -138,6 +131,7 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock
}
}
@Override
public void importProtections(List<OwnedBlock> blocks)
{
for (OwnedBlock ownedBlock : blocks)
@@ -150,6 +144,7 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock
}
}
@Override
public List<OwnedBlock> exportProtections()
{
Connection conn = null;
@@ -216,6 +211,7 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock
}
}
@Override
public void protectBlock(Block block, String 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)
{
Connection conn = null;
@@ -317,6 +314,7 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock
}
}
@Override
public List<String> getOwners(Block block)
{
Connection conn = null;
@@ -377,6 +375,7 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock
}
}
@Override
public int unprotectBlock(Block block)
{
Connection conn = null;
@@ -419,6 +418,7 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock
}
}
@Override
public void onPluginDeactivation()
{
cpds.close();

View File

@@ -9,18 +9,18 @@ import org.bukkit.plugin.Plugin;
public 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;
private final List<String> worlds = new ArrayList<String>();
private final List<String> playerNames = new ArrayList<String>();
private final IProtectedBlock storage;
private final 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;
private final int x;
private final int y;
private final int z;
private final int w;
public ProtectedLocation(final Block block, final int worldId)
{
@@ -59,8 +59,8 @@ public class ProtectedBlockMemory implements IProtectedBlock
static class ProtectedBy
{
private transient int playerId = -1;
private transient Set<Integer> playerIds;
private int playerId = -1;
private Set<Integer> playerIds;
public void add(final int playerId)
{
@@ -114,7 +114,7 @@ public class ProtectedBlockMemory implements IProtectedBlock
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)
{