mirror of
https://github.com/essentials/Essentials.git
synced 2025-08-11 00:55:10 +02:00
Revert to 1013
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1021 e251c2fe-e539-e718-e476-b85c1f46cddb
This commit is contained in:
@@ -78,7 +78,6 @@
|
||||
<zipfileset src="${dist.jar}" excludes="META-INF/*" />
|
||||
<zipfileset src="../lib/mysql.jar" excludes="META-INF/*" />
|
||||
<zipfileset src="../lib/sqlite.jar" excludes="META-INF/*" />
|
||||
<zipfileset src="../lib/c3p0-0.9.1.2.jar" excludes="META-INF/*" />
|
||||
<manifest>
|
||||
<attribute name="Classpath" value="Essentials.jar"/>
|
||||
</manifest>
|
||||
|
@@ -26,7 +26,6 @@ dist.jar=${dist.dir}/original-EssentialsProtect.jar
|
||||
dist.javadoc.dir=${dist.dir}/javadoc
|
||||
endorsed.classpath=
|
||||
excludes=
|
||||
file.reference.c3p0-0.9.1.2.jar=..\\lib\\c3p0-0.9.1.2.jar
|
||||
file.reference.craftbukkit-0.0.1-SNAPSHOT.jar=..\\lib\\craftbukkit-0.0.1-SNAPSHOT.jar
|
||||
file.reference.mysql.jar=..\\lib\\mysql.jar
|
||||
file.reference.sqlite.jar=..\\lib\\sqlite.jar
|
||||
@@ -38,8 +37,7 @@ javac.classpath=\
|
||||
${reference.Essentials.jar}:\
|
||||
${file.reference.mysql.jar}:\
|
||||
${file.reference.sqlite.jar}:\
|
||||
${file.reference.craftbukkit-0.0.1-SNAPSHOT.jar}:\
|
||||
${file.reference.c3p0-0.9.1.2.jar}
|
||||
${file.reference.craftbukkit-0.0.1-SNAPSHOT.jar}
|
||||
# Space-separated list of extra javac options
|
||||
javac.compilerargs=
|
||||
javac.deprecation=false
|
||||
|
@@ -1,13 +1,7 @@
|
||||
package com.earth2me.essentials.protect;
|
||||
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.IConf;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.protect.data.IProtectedBlock;
|
||||
import com.earth2me.essentials.protect.data.ProtectedBlockMemory;
|
||||
import com.earth2me.essentials.protect.data.ProtectedBlockMySQL;
|
||||
import com.earth2me.essentials.protect.data.ProtectedBlockSQLite;
|
||||
import java.beans.PropertyVetoException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.logging.Level;
|
||||
@@ -21,7 +15,7 @@ import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
|
||||
public class EssentialsProtect extends JavaPlugin implements IConf
|
||||
public class EssentialsProtect extends JavaPlugin
|
||||
{
|
||||
private EssentialsProtectBlockListener blockListener = null;
|
||||
private EssentialsProtectPlayerListener playerListener = null;
|
||||
@@ -39,8 +33,6 @@ public class EssentialsProtect extends JavaPlugin implements IConf
|
||||
public static ArrayList onUseAlert = null;
|
||||
public static ArrayList onBreakAlert = null;
|
||||
|
||||
private IProtectedBlock storage = null;
|
||||
private static EssentialsProtect instance = null;
|
||||
|
||||
public EssentialsProtect()
|
||||
{
|
||||
@@ -50,18 +42,15 @@ public class EssentialsProtect extends JavaPlugin implements IConf
|
||||
{
|
||||
PluginManager pm = this.getServer().getPluginManager();
|
||||
Essentials ess = (Essentials)pm.getPlugin("Essentials");
|
||||
if (!ess.isEnabled()) {
|
||||
if (!ess.isEnabled())
|
||||
pm.enablePlugin(ess);
|
||||
}
|
||||
|
||||
instance = this;
|
||||
reloadConfig();
|
||||
|
||||
playerListener = new EssentialsProtectPlayerListener(this);
|
||||
blockListener = new EssentialsProtectBlockListener(this);
|
||||
entityListener = new EssentialsProtectEntityListener(this);
|
||||
pm.registerEvent(Type.PLAYER_PICKUP_ITEM, playerListener, Priority.Low, this);
|
||||
pm.registerEvent(Type.PLAYER_INTERACT, playerListener, Priority.Low, this);
|
||||
// Why is this commented?
|
||||
//pm.registerEvent(Type.BLOCK_DAMAGED, blockListener, Priority.High, this);
|
||||
pm.registerEvent(Type.BLOCK_PLACE, blockListener, Priority.Highest, this);
|
||||
pm.registerEvent(Type.BLOCK_FROMTO, blockListener, Priority.Highest, this);
|
||||
pm.registerEvent(Type.BLOCK_IGNITE, blockListener, Priority.Highest, this);
|
||||
@@ -71,6 +60,7 @@ public class EssentialsProtect extends JavaPlugin implements IConf
|
||||
pm.registerEvent(Type.BLOCK_BREAK, blockListener, Priority.Highest, this);
|
||||
pm.registerEvent(Type.CREATURE_SPAWN, entityListener, Priority.Highest, this);
|
||||
|
||||
loadSettings();
|
||||
if (!this.getDescription().getVersion().equals(Essentials.getStatic().getDescription().getVersion())) {
|
||||
logger.log(Level.WARNING, "Version mismatch! Please update all Essentials jars to the same version.");
|
||||
}
|
||||
@@ -102,23 +92,8 @@ public class EssentialsProtect extends JavaPlugin implements IConf
|
||||
onBreakAlert = null;
|
||||
}
|
||||
|
||||
public void alert(User user, String item, String type)
|
||||
public static void loadSettings()
|
||||
{
|
||||
Location loc = user.getLocation();
|
||||
for (Player p : this.getServer().getOnlinePlayers())
|
||||
{
|
||||
User alertUser = User.get(p);
|
||||
if (alertUser.isAuthorized("essentials.protect.alerts"))
|
||||
alertUser.sendMessage(ChatColor.DARK_AQUA + "[" + user.getName() + "] " + ChatColor.WHITE + type + ChatColor.GOLD + item + " at: " + formatCoords(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
|
||||
}
|
||||
}
|
||||
|
||||
public static String formatCoords(int x, int y, int z)
|
||||
{
|
||||
return x + "," + y + "," + z;
|
||||
}
|
||||
|
||||
public void reloadConfig() {
|
||||
dataSettings = Essentials.getSettings().getEpDBSettings();
|
||||
genSettings = Essentials.getSettings().getEpSettings();
|
||||
guardSettings = Essentials.getSettings().getEpGuardSettings();
|
||||
@@ -129,26 +104,17 @@ public class EssentialsProtect extends JavaPlugin implements IConf
|
||||
onUseAlert = Essentials.getSettings().getEpAlertOnUse();
|
||||
onBreakAlert = Essentials.getSettings().getEpAlertOnBreak();
|
||||
playerSettings = Essentials.getSettings().getEpPlayerSettings();
|
||||
|
||||
if (dataSettings.get("protect.datatype").equals("mysql")) {
|
||||
try {
|
||||
storage = new ProtectedBlockMySQL(dataSettings.get("protect.mysqlDb"), dataSettings.get("protect.username"), dataSettings.get("protect.password"));
|
||||
} catch (PropertyVetoException ex) {
|
||||
logger.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
storage = new ProtectedBlockSQLite("jdbc:sqlite:plugins/Essentials/EssentialsProtect.db");
|
||||
} catch (PropertyVetoException ex) {
|
||||
logger.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
if (genSettings.get("protect.memstore")) {
|
||||
storage = new ProtectedBlockMemory(storage);
|
||||
}
|
||||
EssentialsProtectData.createSqlTable();
|
||||
}
|
||||
|
||||
public static IProtectedBlock getStorage() {
|
||||
return EssentialsProtect.instance.storage;
|
||||
|
||||
public void alert(User user, String item, String type)
|
||||
{
|
||||
Location loc = user.getLocation();
|
||||
for (Player p : this.getServer().getOnlinePlayers())
|
||||
{
|
||||
User alertUser = User.get(p);
|
||||
if (alertUser.isAuthorized("essentials.protect.alerts"))
|
||||
alertUser.sendMessage(ChatColor.DARK_AQUA + "[" + user.getName() + "] " + ChatColor.WHITE + type + ChatColor.GOLD + item + " at: " + EssentialsProtectData.formatCoords(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -2,24 +2,28 @@ package com.earth2me.essentials.protect;
|
||||
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockBurnEvent;
|
||||
import org.bukkit.event.block.BlockFromToEvent;
|
||||
import org.bukkit.event.block.BlockIgniteEvent;
|
||||
import org.bukkit.event.block.BlockInteractEvent;
|
||||
import org.bukkit.event.block.BlockListener;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.block.BlockRightClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
||||
public class EssentialsProtectBlockListener extends BlockListener
|
||||
{
|
||||
private EssentialsProtect parent;
|
||||
private int railBlockX;
|
||||
private int railBlockY;
|
||||
private int railBlockZ;
|
||||
private EssentialsProtectData spData;
|
||||
|
||||
public EssentialsProtectBlockListener(EssentialsProtect parent)
|
||||
{
|
||||
@@ -27,10 +31,17 @@ public class EssentialsProtectBlockListener extends BlockListener
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
private void initialize()
|
||||
{
|
||||
if (spData != null) return;
|
||||
spData = new EssentialsProtectData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlace(BlockPlaceEvent event)
|
||||
{
|
||||
if (event.isCancelled()) return;
|
||||
initialize();
|
||||
ItemStack item = event.getItemInHand();
|
||||
User user = User.get(event.getPlayer());
|
||||
|
||||
@@ -40,6 +51,7 @@ public class EssentialsProtectBlockListener extends BlockListener
|
||||
return;
|
||||
}
|
||||
|
||||
Block blockPlaced = event.getBlockAgainst();
|
||||
int id = event.getBlockPlaced().getTypeId();
|
||||
|
||||
if (EssentialsProtect.checkProtectionItems(EssentialsProtect.blackListPlace, id) && !user.isAuthorized("essentials.protect.exemptplacement"))
|
||||
@@ -53,48 +65,33 @@ public class EssentialsProtectBlockListener extends BlockListener
|
||||
parent.alert(user, item.getType().toString(), "placed: ");
|
||||
}
|
||||
|
||||
Block blockPlaced = event.getBlockPlaced();
|
||||
Block below = blockPlaced.getFace(BlockFace.DOWN);
|
||||
if (below.getType() == Material.RAILS) {
|
||||
if (spData.isBlockAboveProtectedRail(blockPlaced))
|
||||
{
|
||||
if (EssentialsProtect.genSettings.get("protect.protect.prevent.block-on-rail"))
|
||||
{
|
||||
if (EssentialsProtect.getStorage().isProtected(below, user.getName())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
List<Block> protect = new ArrayList<Block>();
|
||||
if (blockPlaced.getType() == Material.RAILS) {
|
||||
if (item.getTypeId() == 66)
|
||||
{
|
||||
if (EssentialsProtect.genSettings.get("protect.protect.rails"))
|
||||
{
|
||||
if (user.isAuthorized("essentials.protect"))
|
||||
{
|
||||
protect.add(blockPlaced);
|
||||
railBlockX = blockPlaced.getX();
|
||||
railBlockY = blockPlaced.getY();
|
||||
railBlockZ = blockPlaced.getZ();
|
||||
|
||||
spData.insertProtectionIntoDb(user.getWorld().getName(), user.getName(), railBlockX, railBlockY + 1, railBlockZ);
|
||||
if (EssentialsProtect.genSettings.get("protect.protect.block-below"))
|
||||
{
|
||||
protect.add(blockPlaced.getFace(BlockFace.DOWN));
|
||||
spData.insertProtectionIntoDb(user.getWorld().getName(), user.getName(), railBlockX, railBlockY, railBlockZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (blockPlaced.getType() == Material.SIGN_POST || blockPlaced.getType() == Material.WALL_SIGN) {
|
||||
if (EssentialsProtect.genSettings.get("protect.protect.signs"))
|
||||
{
|
||||
if (user.isAuthorized("essentials.protect"))
|
||||
{
|
||||
protect.add(blockPlaced);
|
||||
if (EssentialsProtect.genSettings.get("protect.protect.block-below"))
|
||||
{
|
||||
protect.add(event.getBlockAgainst());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Block block : protect) {
|
||||
EssentialsProtect.getStorage().protectBlock(block, user.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -131,7 +128,7 @@ public class EssentialsProtectBlockListener extends BlockListener
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockFromTo(BlockFromToEvent event)
|
||||
public void onBlockFlow(BlockFromToEvent event)
|
||||
{
|
||||
if (event.isCancelled()) return;
|
||||
Block block = event.getBlock();
|
||||
@@ -190,6 +187,7 @@ public class EssentialsProtectBlockListener extends BlockListener
|
||||
public void onBlockBreak(BlockBreakEvent event)
|
||||
{
|
||||
if (event.isCancelled()) return;
|
||||
initialize();
|
||||
User user = User.get(event.getPlayer());
|
||||
Block block = event.getBlock();
|
||||
if (EssentialsProtect.playerSettings.get("protect.disable.build") && !user.canBuild())
|
||||
@@ -213,57 +211,28 @@ public class EssentialsProtectBlockListener extends BlockListener
|
||||
{
|
||||
if (block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST || block.getType() == Material.RAILS)
|
||||
{
|
||||
EssentialsProtect.getStorage().unprotectBlock(block);
|
||||
if (block.getType() == Material.RAILS || block.getType() == Material.SIGN_POST) {
|
||||
Block below = block.getFace(BlockFace.DOWN);
|
||||
EssentialsProtect.getStorage().unprotectBlock(below);
|
||||
} else {
|
||||
BlockFace[] faces = new BlockFace[] {
|
||||
BlockFace.NORTH,
|
||||
BlockFace.EAST,
|
||||
BlockFace.SOUTH,
|
||||
BlockFace.WEST
|
||||
};
|
||||
for (BlockFace blockFace : faces) {
|
||||
Block against = block.getFace(blockFace);
|
||||
EssentialsProtect.getStorage().unprotectBlock(against);
|
||||
}
|
||||
}
|
||||
spData.removeProtectionFromDB(block, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
EssentialsProtect.getStorage().unprotectBlock(block);
|
||||
spData.removeProtectionFromDB(block);
|
||||
}
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
boolean isProtected = EssentialsProtect.getStorage().isProtected(block, user.getName());
|
||||
if (!isProtected) {
|
||||
boolean canDestroy = spData.canDestroy(user.getWorld().getName(), user.getName(), block);
|
||||
if (canDestroy)
|
||||
{
|
||||
if (block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST || block.getType() == Material.RAILS)
|
||||
{
|
||||
EssentialsProtect.getStorage().unprotectBlock(block);
|
||||
if (block.getType() == Material.RAILS || block.getType() == Material.SIGN_POST) {
|
||||
Block below = block.getFace(BlockFace.DOWN);
|
||||
EssentialsProtect.getStorage().unprotectBlock(below);
|
||||
} else {
|
||||
BlockFace[] faces = new BlockFace[] {
|
||||
BlockFace.NORTH,
|
||||
BlockFace.EAST,
|
||||
BlockFace.SOUTH,
|
||||
BlockFace.WEST
|
||||
};
|
||||
for (BlockFace blockFace : faces) {
|
||||
Block against = block.getFace(blockFace);
|
||||
EssentialsProtect.getStorage().unprotectBlock(against);
|
||||
}
|
||||
}
|
||||
{
|
||||
spData.removeProtectionFromDB(block, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
EssentialsProtect.getStorage().unprotectBlock(block);
|
||||
spData.removeProtectionFromDB(block);
|
||||
}
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
|
@@ -3,68 +3,92 @@ package com.earth2me.essentials.protect;
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerItemEvent;
|
||||
import org.bukkit.event.player.PlayerListener;
|
||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
||||
public class EssentialsProtectPlayerListener extends PlayerListener
|
||||
{
|
||||
private EssentialsProtect parent;
|
||||
|
||||
private int signBlockX;
|
||||
private int signBlockY;
|
||||
private int signBlockZ;
|
||||
private EssentialsProtectData spData = null;
|
||||
|
||||
public EssentialsProtectPlayerListener(EssentialsProtect parent)
|
||||
{
|
||||
Essentials.loadClasses();
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public void initialize()
|
||||
{
|
||||
if (spData != null) return;
|
||||
spData = new EssentialsProtectData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerInteract(PlayerInteractEvent event)
|
||||
{
|
||||
initialize();
|
||||
if (event.isCancelled()) return;
|
||||
ItemStack item = event.getItem();
|
||||
User user = User.get(event.getPlayer());
|
||||
Block blockClicked = event.getClickedBlock();
|
||||
|
||||
if (EssentialsProtect.playerSettings.get("protect.disable.build") && !user.canBuild())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (user.isAuthorized("essentials.protect.admin"))
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
boolean first = true;
|
||||
for (String owner : EssentialsProtect.getStorage().getOwners(event.getClickedBlock())) {
|
||||
if (!first) {
|
||||
sb.append(", ");
|
||||
}
|
||||
first = false;
|
||||
sb.append(owner);
|
||||
}
|
||||
String ownerNames = sb.toString();
|
||||
if (ownerNames != null)
|
||||
{
|
||||
user.sendMessage(ChatColor.GOLD + "[EssentialsProtect] Protection owners: " + ownerNames);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerPickupItem(PlayerPickupItemEvent event)
|
||||
{
|
||||
if(event.isCancelled()) return;
|
||||
ItemStack item = event.getItem().getItemStack();
|
||||
User user = User.get(event.getPlayer());
|
||||
if (EssentialsProtect.checkProtectionItems(EssentialsProtect.usageList, item.getTypeId()) && !user.isAuthorized("essentials.protect.exemptusage"))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (user.isAuthorized("essentials.protect.admin"))
|
||||
{
|
||||
String ownerName = spData.getBlockOwner(user.getWorld().getName(), user.getName(),
|
||||
blockClicked);
|
||||
if (ownerName != null)
|
||||
{
|
||||
user.sendMessage(ChatColor.GOLD + "[EssentialsProtect] Protection owner: "
|
||||
+ ownerName);
|
||||
}
|
||||
}
|
||||
if (EssentialsProtect.onUseAlert.contains(String.valueOf(item.getTypeId())))
|
||||
{
|
||||
parent.alert(user, item.getType().toString(), "used: ");
|
||||
}
|
||||
|
||||
if (item.getTypeId() == 323)
|
||||
{
|
||||
if (EssentialsProtect.genSettings.get("protect.protect.signs"))
|
||||
{
|
||||
if (user.isAuthorized("essentials.protect"))
|
||||
{
|
||||
|
||||
signBlockX = blockClicked.getX();
|
||||
signBlockY = blockClicked.getY();
|
||||
signBlockZ = blockClicked.getZ();
|
||||
|
||||
initialize();
|
||||
spData.insertProtectionIntoDb(user.getWorld().getName(), user.getName(), signBlockX,
|
||||
signBlockY + 1, signBlockZ);
|
||||
|
||||
if (EssentialsProtect.genSettings.get("protect.protect.block-below"))
|
||||
{
|
||||
spData.insertProtectionIntoDb(user.getWorld().getName(), user.getName(), signBlockX,
|
||||
signBlockY, signBlockZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user