HungerArena/src/me/travja/hungerarena/BlockStorage.java

364 lines
15 KiB
Java
Raw Normal View History

2012-07-17 15:50:34 -06:00
package me.Travja.HungerArena;
2012-07-18 07:14:50 +10:00
import java.util.List;
2012-08-08 22:11:05 -06:00
import org.bukkit.ChatColor;
2012-07-18 07:14:50 +10:00
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
2012-10-08 17:55:42 -06:00
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
2012-09-01 22:11:35 -06:00
import org.bukkit.entity.Player;
2012-07-18 07:14:50 +10:00
import org.bukkit.event.EventHandler;
2012-10-22 21:05:25 -06:00
import org.bukkit.event.EventPriority;
2012-07-18 07:14:50 +10:00
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockFadeEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;
public class BlockStorage implements Listener {
public Main plugin;
public BlockStorage(Main m) {
this.plugin = m;
}
2012-10-22 21:05:25 -06:00
@EventHandler(priority = EventPriority.MONITOR)
2012-09-01 22:11:35 -06:00
public void BlockBreak(BlockBreakEvent event){
Block b = event.getBlock();
Player p = event.getPlayer();
2012-10-08 17:55:42 -06:00
String pname = p.getName();
2012-10-22 21:05:25 -06:00
if(!event.isCancelled()){
if(plugin.Playing.contains(pname)){
if(plugin.config.getString("Protected_Arena").equalsIgnoreCase("True")){
if(!plugin.management.getStringList("blocks.blacklist").isEmpty() && plugin.management.getStringList("blocks.blacklist").contains(b.getData())){
event.setCancelled(true);
p.sendMessage(ChatColor.RED + "That is an illegal block!");
}else if(!plugin.management.getStringList("blocks.whitelist").isEmpty() && !plugin.management.getStringList("blocks.whitelist").contains(b.getData())){
if(!plugin.management.getStringList("blocks.blacklist").isEmpty() && !plugin.management.getStringList("blocks.blacklist").contains(b.getData())){
event.setCancelled(true);
p.sendMessage(ChatColor.RED + "That is an illegal block!");
}
}else if(!plugin.management.getStringList("blocks.blacklist").isEmpty() && !plugin.management.getStringList("blocks.blacklist").contains(b.getData())){
if(!plugin.management.getStringList("blocks.whitelist").isEmpty() && !plugin.management.getStringList("blocks.whitelist").contains(b.getData())){
event.setCancelled(true);
p.sendMessage(ChatColor.RED + "That is an illegal block!");
}
}else{
event.setCancelled(true);
p.sendMessage(ChatColor.RED + "That is an illegal block!");
}
}
if(plugin.canjoin){
if(plugin.config.getStringList("worlds").isEmpty() || (!plugin.config.getStringList("worlds").isEmpty() && plugin.config.getStringList("worlds").contains(p.getWorld().getName()))){
if(!plugin.management.getStringList("blocks.blacklist").isEmpty() && plugin.management.getStringList("blocks.blacklist").contains(b.getData())){
event.setCancelled(true);
p.sendMessage(ChatColor.RED + "That is an illegal block!");
}else if(!plugin.management.getStringList("blocks.whitelist").isEmpty() && !plugin.management.getStringList("blocks.whitelist").contains(b.getData())){
if(!plugin.management.getStringList("blocks.blacklist").isEmpty() && !plugin.management.getStringList("blocks.blacklist").contains(b.getData())){
event.setCancelled(true);
p.sendMessage(ChatColor.RED + "That is an illegal block!");
}
}else if(!plugin.management.getStringList("blocks.blacklist").isEmpty() && !plugin.management.getStringList("blocks.blacklist").contains(b.getData())){
if(!plugin.management.getStringList("blocks.whitelist").isEmpty() && !plugin.management.getStringList("blocks.whitelist").contains(b.getData())){
event.setCancelled(true);
p.sendMessage(ChatColor.RED + "That is an illegal block!");
}
}else{
String w = b.getWorld().getName();
int x = b.getX();
int y = b.getY();
int z = b.getZ();
int d = b.getTypeId();
byte m = b.getData();
String coords = w + "," + x + "," + y + "," + z + "," + d + "," + m;
List<String> blocks = plugin.data.getStringList("Blocks_Destroyed");
if(!plugin.data.getStringList("Blocks_Placed").contains(w + "," + x + "," + y + "," + z)){
blocks.add(coords);
plugin.data.set("Blocks_Destroyed", blocks);
plugin.saveData();
}
}
2012-10-08 17:55:42 -06:00
}
2012-09-01 22:11:35 -06:00
}
}
}
}
2012-10-22 21:05:25 -06:00
@EventHandler(priority = EventPriority.MONITOR)
2012-10-08 17:55:42 -06:00
public void Explosion(EntityExplodeEvent event){
List<Block> blocksd = event.blockList();
Entity e = event.getEntity();
2012-10-22 21:05:25 -06:00
if(!event.isCancelled()){
if(plugin.canjoin){
if(plugin.config.getStringList("worlds").isEmpty() || (!plugin.config.getStringList("worlds").isEmpty() && plugin.config.getStringList("worlds").contains(event.getEntity().getWorld().getName()))){
if(e.getType()== EntityType.PRIMED_TNT){
if(!plugin.data.getStringList("Blocks_Placed").contains(e.getLocation().getWorld() + "," + e.getLocation().getX() + "," + e.getLocation().getY() + "," + e.getLocation().getZ()) /*|| !plugin.data.getStringList("Blocks_Destroyed").contains(e.getLocation().getWorld() + "," + e.getLocation().getX() + "," + e.getLocation().getY() + "," + e.getLocation().getZ())*/){
List<String> blocks = plugin.data.getStringList("Blocks_Destroyed");
blocks.add(e.getLocation().getWorld().getName() + "," + e.getLocation().getX() + "," + e.getLocation().getY() + "," + e.getLocation().getZ() + ",46" + ",0");
plugin.data.set("Blocks_Destroyed", blocks);
plugin.saveData();
plugin.getServer().broadcastMessage("TNT blew up!");
}
}
for(Block b:blocksd){
String w = event.getEntity().getWorld().getName();
int x = b.getX();
int y = b.getY();
int z = b.getZ();
int d = b.getTypeId();
byte m = b.getData();
String coords = w + "," + x + "," + y + "," + z + "," + d + "," + m;
2012-10-08 17:55:42 -06:00
List<String> blocks = plugin.data.getStringList("Blocks_Destroyed");
2012-10-22 21:05:25 -06:00
if(!plugin.data.getStringList("Blocks_Placed").contains(w + "," + x + "," + y + "," + z) || !plugin.data.getStringList("Blocks_Destroyed").contains(w + "," + x + "," + y + "," + z)){
blocks.add(coords);
plugin.data.set("Blocks_Destroyed", blocks);
plugin.saveData();
}
2012-10-08 17:55:42 -06:00
}
}
2012-10-22 21:05:25 -06:00
}
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void burningBlocks(BlockBurnEvent event){
Block b = event.getBlock();
if(!event.isCancelled()){
if(plugin.canjoin){
if(plugin.config.getStringList("worlds").isEmpty() || (!plugin.config.getStringList("worlds").isEmpty() && plugin.config.getStringList("worlds").contains(b.getWorld().getName()))){
String w = b.getWorld().getName();
2012-10-08 17:55:42 -06:00
int x = b.getX();
int y = b.getY();
int z = b.getZ();
int d = b.getTypeId();
byte m = b.getData();
String coords = w + "," + x + "," + y + "," + z + "," + d + "," + m;
List<String> blocks = plugin.data.getStringList("Blocks_Destroyed");
2012-10-22 21:05:25 -06:00
if(!plugin.data.getStringList("Blocks_Placed").contains(w + "," + x + "," + y + "," + z)){
2012-10-08 17:55:42 -06:00
blocks.add(coords);
plugin.data.set("Blocks_Destroyed", blocks);
plugin.saveData();
}
}
}
2012-07-18 07:14:50 +10:00
}
}
2012-10-22 21:05:25 -06:00
@EventHandler(priority = EventPriority.MONITOR)
2012-07-18 07:14:50 +10:00
public void blockPlace(BlockPlaceEvent event){
2012-10-08 17:55:42 -06:00
Block b = event.getBlock();
Player p = event.getPlayer();
2012-10-22 21:05:25 -06:00
if(!event.isCancelled()){
if(plugin.Playing.contains(p.getName())){
if(plugin.canjoin){
if(plugin.config.getStringList("worlds").isEmpty() || (!plugin.config.getStringList("worlds").isEmpty() && plugin.config.getStringList("worlds").contains(b.getWorld().getName()))){
if((b.getType()== Material.SAND || b.getType()== Material.GRAVEL) && (b.getRelative(BlockFace.DOWN).getType()== Material.AIR || b.getRelative(BlockFace.DOWN).getType()== Material.WATER || b.getRelative(BlockFace.DOWN).getType()== Material.LAVA)){
int n = b.getY() -1;
while(b.getWorld().getBlockAt(b.getX(), n, b.getZ()).getType()== Material.AIR || b.getWorld().getBlockAt(b.getX(), n, b.getZ()).getType()== Material.WATER || b.getWorld().getBlockAt(b.getX(), n, b.getZ()).getType()== Material.LAVA){
n = n -1;
event.getPlayer().sendMessage(b.getWorld().getBlockAt(b.getX(), n, b.getZ()).getType().toString().toLowerCase());
if(b.getWorld().getBlockAt(b.getX(), n, b.getZ()).getType()!= Material.AIR || b.getWorld().getBlockAt(b.getX(), n, b.getZ()).getType()!= Material.WATER || b.getWorld().getBlockAt(b.getX(), n, b.getZ()).getType()!= Material.LAVA){
int l = n +1;
Block br = b.getWorld().getBlockAt(b.getX(), l, b.getZ());
String w = br.getWorld().getName();
int x = br.getX();
int y = br.getY();
int z = br.getZ();
String coords = w + "," + x + "," + y + "," + z;
p.sendMessage(ChatColor.GREEN + "Sand/Gravel will land at " + coords);
List<String> blocks = plugin.data.getStringList("Blocks_Placed");
blocks.add(coords);
plugin.data.set("Blocks_Placed", blocks);
plugin.saveData();
}
}
}else{
if(b.getType()!= Material.SAND || b.getType()!= Material.GRAVEL){
String w = b.getWorld().getName();
int x = b.getX();
int y = b.getY();
int z = b.getZ();
2012-10-08 17:55:42 -06:00
String coords = w + "," + x + "," + y + "," + z;
List<String> blocks = plugin.data.getStringList("Blocks_Placed");
blocks.add(coords);
plugin.data.set("Blocks_Placed", blocks);
plugin.saveData();
}
}
2012-07-18 07:14:50 +10:00
}
2012-08-29 17:58:39 -06:00
}
2012-07-18 07:14:50 +10:00
}
}
}
2012-10-22 21:05:25 -06:00
@EventHandler(priority = EventPriority.MONITOR)
2012-07-18 07:14:50 +10:00
public void bucketEmpty(PlayerBucketEmptyEvent event){
2012-10-22 21:05:25 -06:00
if(!event.isCancelled()){
if(plugin.canjoin){
if(plugin.Playing.contains(event.getPlayer().getName())){
if(plugin.config.getStringList("worlds").isEmpty() || (!plugin.config.getStringList("worlds").isEmpty() && plugin.config.getStringList("worlds").contains(event.getPlayer().getWorld().getName()))){
Block b = event.getBlockClicked().getRelative(event.getBlockFace());
String w = b.getWorld().getName();
int x = b.getX();
int y = b.getY();
int z = b.getZ();
String coords = w + "," + x + "," + y + "," + z;
List<String> blocks = plugin.data.getStringList("Blocks_Placed");
blocks.add(coords);
plugin.data.set("Blocks_Placed", blocks);
plugin.saveData();
}
2012-10-08 17:55:42 -06:00
}
}
2012-07-18 07:14:50 +10:00
}
}
2012-10-22 21:05:25 -06:00
@EventHandler(priority = EventPriority.MONITOR)
2012-07-18 07:14:50 +10:00
public void bucketFill(PlayerBucketFillEvent event){
2012-10-22 21:05:25 -06:00
if(!event.isCancelled()){
if(plugin.canjoin){
if(plugin.Playing.contains(event.getPlayer().getName())){
if(plugin.config.getStringList("worlds").isEmpty() || (!plugin.config.getStringList("worlds").isEmpty() && plugin.config.getStringList("worlds").contains(event.getPlayer().getWorld().getName()))){
Block b = event.getBlockClicked().getRelative(event.getBlockFace());
String w = b.getWorld().getName();
int x = b.getX();
int y = b.getY();
int z = b.getZ();
int d = b.getTypeId();
byte m = b.getData();
String coords = w + "," + x + "," + y + "," + z + "," + d + "," + m;
List<String> blocks = plugin.data.getStringList("Blocks_Destroyed");
if(!plugin.data.getStringList("Blocks_Placed").contains(w + "," + x + "," + y + "," + z)){
blocks.add(coords);
plugin.data.set("Blocks_Destroyed", blocks);
plugin.saveData();
}
}
}
}
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void blockMelt(BlockFadeEvent event){
if(!event.isCancelled()){
if(plugin.canjoin){
if(plugin.config.getStringList("worlds").isEmpty() || (!plugin.config.getStringList("worlds").isEmpty() && plugin.config.getStringList("worlds").contains(event.getBlock().getWorld().getName()))){
Block b = event.getBlock();
2012-10-08 17:55:42 -06:00
String w = b.getWorld().getName();
int x = b.getX();
int y = b.getY();
int z = b.getZ();
int d = b.getTypeId();
byte m = b.getData();
String coords = w + "," + x + "," + y + "," + z + "," + d + "," + m;
List<String> blocks = plugin.data.getStringList("Blocks_Destroyed");
if(!plugin.data.getStringList("Blocks_Placed").contains(w + "," + x + "," + y + "," + z)){
blocks.add(coords);
plugin.data.set("Blocks_Destroyed", blocks);
plugin.saveData();
}
}
}
2012-07-18 07:14:50 +10:00
}
}
2012-10-08 17:55:42 -06:00
/*@EventHandler
2012-07-18 07:14:50 +10:00
public void blockGrow(BlockGrowEvent event){
if(plugin.canjoin== true){
Block b = event.getBlock();
String w = b.getWorld().getName();
int x = b.getX();
int y = b.getY();
int z = b.getZ();
int d = b.getTypeId();
String coords = w + "," + x + "," + y + "," + z + "," + d;
System.out.println("Grow: " + coords);
2012-10-08 17:55:42 -06:00
List<String> blocks = plugin.data.getStringList("Blocks_Placed");
2012-07-18 07:14:50 +10:00
blocks.add(coords);
2012-10-08 17:55:42 -06:00
plugin.data.set("Blocks_Destroyed", blocks);
2012-07-18 07:14:50 +10:00
plugin.saveConfig();
}
}
@EventHandler
public void blockForm(BlockFormEvent event){
if(plugin.canjoin== true){
Block b = event.getBlock();
String w = b.getWorld().getName();
int x = b.getX();
int y = b.getY();
int z = b.getZ();
int d = b.getTypeId();
String coords = w + "," + x + "," + y + "," + z + "," + d;
System.out.println("Snowfall: " + coords);
2012-10-08 17:55:42 -06:00
List<String> blocks = plugin.data.getStringList("Blocks_Placed");
2012-07-18 07:14:50 +10:00
blocks.add(coords);
2012-10-08 17:55:42 -06:00
plugin.data.set("Blocks_Destroyed", blocks);
2012-07-18 07:14:50 +10:00
plugin.saveConfig();
}
}
@EventHandler
public void pistonPush(BlockPistonExtendEvent event){
if(plugin.canjoin== true){
for(Block b:event.getBlocks()){
String w = b.getWorld().getName();
int x = b.getX();
int y = b.getY();
int z = b.getZ();
int d = b.getTypeId();
String coords = w + "," + x + "," + y + "," + z + "," + d;
System.out.println("Piston: " + coords);
2012-10-08 17:55:42 -06:00
List<String> blocks = plugin.data.getStringList("Blocks_Destroyed");
2012-07-18 07:14:50 +10:00
blocks.add(coords);
2012-10-08 17:55:42 -06:00
plugin.data.set("Blocks_Destroyed", blocks);
2012-07-18 07:14:50 +10:00
plugin.saveConfig();
}
}
}
2012-08-29 17:58:39 -06:00
@EventHandler
2012-07-18 07:14:50 +10:00
public void onChange(BlockPhysicsEvent event){
Block block = event.getBlock();
Material changed = event.getChangedType();
if (block.getType() == Material.LAVA){
if (changed == Material.LAVA){
Block b = event.getBlock();
String w = b.getWorld().getName();
int x = b.getX();
int y = b.getY();
int z = b.getZ();
int d = b.getTypeId();
String coords = w + "," + x + "," + y + "," + z + "," + d;
System.out.println("Lava Change: " + coords);
2012-10-08 17:55:42 -06:00
List<String> blocks = plugin.data.getStringList("Blocks_Placed");
2012-07-18 07:14:50 +10:00
blocks.add(coords);
2012-10-08 17:55:42 -06:00
plugin.data.set("Blocks_Destroyed", blocks);
2012-07-18 07:14:50 +10:00
plugin.saveConfig();
}else if(changed == Material.WATER){
Block b = event.getBlock();
String w = b.getWorld().getName();
int x = b.getX();
int y = b.getY();
int z = b.getZ();
int d = b.getTypeId();
String coords = w + "," + x + "," + y + "," + z + "," + d;
System.out.println("Water Change: " + coords);
2012-10-08 17:55:42 -06:00
List<String> blocks = plugin.data.getStringList("Blocks_Placed");
2012-07-18 07:14:50 +10:00
blocks.add(coords);
2012-10-08 17:55:42 -06:00
plugin.data.set("Blocks_Destroyed", blocks);
2012-07-18 07:14:50 +10:00
plugin.saveConfig();
}
}else if (block.getType() == Material.SAND || block.getType() == Material.GRAVEL) {
if (changed == Material.AIR) {
Block b = event.getBlock();
String w = b.getWorld().getName();
int x = b.getX();
int y = b.getY();
int z = b.getZ();
int d = b.getTypeId();
String coords = w + "," + x + "," + y + "," + z + "," + d;
System.out.println("Sand/Gravel Fall: " + coords);
2012-10-08 17:55:42 -06:00
List<String> blocks = plugin.data.getStringList("Blocks_Placed");
2012-07-18 07:14:50 +10:00
blocks.add(coords);
2012-10-08 17:55:42 -06:00
plugin.data.set("Blocks_Destroyed", blocks);
2012-07-18 07:14:50 +10:00
plugin.saveConfig();
}
}
}*/
}