Added BlockBreakEvent resets

This commit is contained in:
travja 2012-09-01 22:11:35 -06:00
parent 641ba0b3d1
commit 6b1a6b3c30
36 changed files with 83 additions and 3 deletions

View File

@ -7,6 +7,7 @@ import org.bukkit.Location;
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.Listener;
import org.bukkit.event.block.BlockBreakEvent;
@ -27,6 +28,29 @@ public class BlockStorage implements Listener {
public BlockStorage(Main m) {
this.plugin = m;
}
@EventHandler
public void BlockBreak(BlockBreakEvent event){
Block b = event.getBlock();
Player p = event.getPlayer();
if(plugin.canjoin){
if(plugin.Playing.contains(p.getName())){
if(plugin.config.getStringList("worlds").isEmpty() || (!plugin.config.getStringList("worlds").isEmpty() && plugin.config.getStringList("worlds").contains(p.getWorld().getName()))){
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;
System.out.println("Leaf Break: " + coords);
List<String> blocks = plugin.config.getStringList("Blocks_Destroyed");
blocks.add(coords);
plugin.config.set("Blocks_Destroyed", blocks);
plugin.saveConfig();
}
}
}
}
/*@EventHandler
public void creeperExplosion(EntityExplodeEvent event){
if(plugin.canjoin== true){

View File

@ -1,6 +1,7 @@
package me.Travja.HungerArena;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

View File

@ -9,6 +9,7 @@ import org.bukkit.block.Block;
import org.bukkit.block.Chest;
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.block.BlockBreakEvent;
@ -20,6 +21,43 @@ public class Chests implements Listener {
public Chests(Main m) {
this.plugin = m;
}
@EventHandler(priority = EventPriority.HIGHEST)
public void ChestBreak(BlockBreakEvent event){
Player p = event.getPlayer();
Block block = event.getBlock();
if(p.getItemInHand().getType()== Material.BLAZE_ROD && p.hasPermission("HungerArena.Chest.Store")){
if(block.getState() instanceof Chest){
event.setCancelled(true);
ItemStack[] itemsinchest = ((Chest) block.getState()).getInventory().getContents();
int blockx = block.getX();
int blocky = block.getY();
int blockz = block.getZ();
String blockw = block.getWorld().getName().toString();
if(!plugin.getConfig().contains("Storage." + blockx + "," + blocky + "," + blockz + ".Location.X")){
plugin.getConfig().addDefault("Storage." + blockx + "," + blocky + "," + blockz + ".Location.X", blockx);
plugin.getConfig().addDefault("Storage." + blockx + "," + blocky + "," + blockz + ".Location.Y", blocky);
plugin.getConfig().addDefault("Storage." + blockx + "," + blocky + "," + blockz + ".Location.Z",blockz);
plugin.getConfig().addDefault("Storage." + blockx + "," + blocky + "," + blockz + ".Location.W", blockw);
plugin.getConfig().addDefault("Storage." + blockx + "," + blocky + "," + blockz + ".ItemsInStorage", itemsinchest);
}else{
plugin.getConfig().set("Storage." + blockx + "," + blocky+ "," + blockz + ".Location.X",blockx);
plugin.getConfig().set("Storage." + blockx + "," + blocky + "," + blockz + ".Location.Y", blocky);
plugin.getConfig().set("Storage." + blockx + "," + blocky + "," + blockz + ".Location.Z", blockz);
plugin.getConfig().set("Storage." + blockx + "," + blocky + "," + blockz + ".Location.W", blockw);
plugin.getConfig().set("Storage." + blockx + "," + blocky + "," + blockz + ".ItemsInStorage", itemsinchest);
}
List<String> list2 = plugin.getConfig().getStringList("StorageXYZ");
list2.add(blockx + "," + blocky + "," + blockz);
plugin.getConfig().set("StorageXYZ", list2);
plugin.getConfig().options().copyDefaults(true);
plugin.saveConfig();
p.sendMessage(ChatColor.GREEN + "Chest Stored!");
}
}else if(p.getItemInHand().getType()== Material.BLAZE_ROD && !p.hasPermission("HungerArena.Chest.Store") && block.getState() instanceof Chest){
event.setCancelled(true);
p.sendMessage(ChatColor.RED + "You can't store chests!!");
}
}
@EventHandler
public void ChestSaves(PlayerInteractEvent event){
Block block = event.getClickedBlock();

View File

@ -18,9 +18,11 @@ public class CommandBlock implements Listener {
Player p = event.getPlayer();
String pname = p.getName();
if(!cmd.contains("/ha") && plugin.Playing.contains(pname) && plugin.canjoin== true){
if(!cmd.contains("/login") || !p.hasPermission("HungerArena.UseCommands")){
event.setCancelled(true);
p.sendMessage(ChatColor.RED + "You are only allowed to use /ha commands!");
if(!cmd.contains("/login")){
if(!p.hasPermission("HungerArena.UseCommands")){
event.setCancelled(true);
p.sendMessage(ChatColor.RED + "You are only allowed to use /ha commands!");
}
}
}
}

View File

@ -372,6 +372,21 @@ public class HaCommands implements CommandExecutor {
plugin.Out.clear();
plugin.Playing.clear();
plugin.canjoin = false;
List<String> blocksbroken = plugin.config.getStringList("Blocks_Destroyed");
for(String blocks:blocksbroken){
String[] coords = blocks.split(",");
World w = plugin.getServer().getWorld(coords[0]);
double x = Double.parseDouble(coords[1]);
double y = Double.parseDouble(coords[2]);
double z = Double.parseDouble(coords[3]);
int d = Integer.parseInt(coords[4]);
byte m = Byte.parseByte(coords[5]);
Location blockl = new Location(w, x, y, z);
Block block = w.getBlockAt(blockl);
block.setTypeIdAndData(d, m, true);
block.getState().update();
}
plugin.config.getStringList("Blocks_Destroyed").clear();
p.performCommand("ha refill");
p.sendMessage(ChatColor.AQUA + "The games have been reset!");
}else{