mirror of
https://github.com/CivMC/Civ.git
synced 2026-07-18 00:20:44 +00:00
enhanced solution to dynamite bug
This commit is contained in:
@@ -19,9 +19,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.Door;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
@@ -104,10 +102,6 @@ public class BlockListener implements Listener {
|
||||
@EventHandler
|
||||
public void checkForExplosion(EntityExplodeEvent event){
|
||||
|
||||
if(event.isCancelled()){
|
||||
return;
|
||||
}
|
||||
|
||||
//Store blocks that are inside explosion's blast radius
|
||||
List<Block> blastRadiusBlocks = event.blockList();
|
||||
|
||||
@@ -117,6 +111,7 @@ public class BlockListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
List<Coordinate> reinforcedBlocks = new ArrayList<Coordinate>();
|
||||
HashMap<Coordinate, Block> affectedBlocks = new HashMap<Coordinate, Block>();
|
||||
|
||||
//Initialize min & max X,Y,Z coordinates
|
||||
@@ -170,44 +165,40 @@ public class BlockListener implements Listener {
|
||||
|
||||
//Query database for any reinforced blocks that may be in the blast radius
|
||||
//Reinforced blocks should have a durability > 0 (aka >= 1)
|
||||
ResultSet result = dao.selectReinforcements(worldName, smallestX, largestX, smallestY, largestY, smallestZ, largestZ);
|
||||
|
||||
reinforcedBlocks = dao.selectReinforcements(worldName, smallestX, largestX, smallestY, largestY, smallestZ, largestZ);
|
||||
System.out.println(reinforcedBlocks.get(0));
|
||||
|
||||
if(reinforcedBlocks.size() < 1){
|
||||
return;
|
||||
}
|
||||
|
||||
//If there was some found, loop through each one
|
||||
try {
|
||||
while(result.next()){
|
||||
//Get X,Y,Z coords of reinforced block
|
||||
int x = result.getInt(1);
|
||||
int y = result.getInt(2);
|
||||
int z = result.getInt(3);
|
||||
|
||||
//Pass in x, y, z of reinforced block into affectedBlocks HashMap to instantiate a Block
|
||||
Block protectedBlock = affectedBlocks.get(new Coordinate(world, x, y, z));
|
||||
//Then remove the protectedBlock from explosion list
|
||||
event.blockList().remove(protectedBlock);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
System.err.println("Citadel - explosion error");
|
||||
for(int i = 0; i < reinforcedBlocks.size(); i++){
|
||||
Coordinate reinforcedBlock = reinforcedBlocks.get(i);
|
||||
//Then remove it from explosion
|
||||
event.blockList().remove(affectedBlocks.get(reinforcedBlock));
|
||||
}
|
||||
|
||||
//Update reinforcements to set durability of blocks that are within blast radius
|
||||
//Explosion should decrement durability by 1
|
||||
dao.updateReinforcements(worldName, smallestX, largestX, smallestY, largestY, smallestZ, largestZ);
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void controlAccess(PlayerInteractEvent pie) {
|
||||
if (!pie.hasBlock()) return;
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (!event.hasBlock()) return;
|
||||
if(event.isCancelled()) return;
|
||||
|
||||
Block block = pie.getClickedBlock();
|
||||
Block block = event.getClickedBlock();
|
||||
|
||||
Material matl = block.getType();
|
||||
|
||||
Player p = pie.getPlayer();
|
||||
Player p = event.getPlayer();
|
||||
if ((matl == Material.CHEST) || (matl == Material.WOODEN_DOOR) || (matl == Material.IRON_DOOR)) {
|
||||
String group = dao.getRegisteredGroup(block);
|
||||
if (group != null && !dao.isPlayerInGroup(group, p.getDisplayName())) {
|
||||
p.sendMessage(ChatColor.RED + "That door/chest is locked.");
|
||||
pie.setCancelled(true);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
package com.untamedears.Citadel.dao;
|
||||
|
||||
import com.untamedears.Citadel.Citadel;
|
||||
import com.untamedears.Citadel.Coordinate;
|
||||
import com.untamedears.Citadel.DelayedReinforcement;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
@@ -34,6 +39,7 @@ public class CitadelDao {
|
||||
private static final String SELECT_REGISTRY = "SELECT grp FROM REGISTRY WHERE x=? AND y=? AND z=? AND world=?";
|
||||
|
||||
private Connection conn;
|
||||
private JavaPlugin myPlugin;
|
||||
|
||||
public CitadelDao() throws ClassNotFoundException {
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
@@ -142,18 +148,38 @@ public class CitadelDao {
|
||||
}
|
||||
}
|
||||
|
||||
public ResultSet selectReinforcements(String worldName, Integer smallestX, Integer largestX,
|
||||
public List<Coordinate> selectReinforcements(String worldName, Integer smallestX, Integer largestX,
|
||||
Integer smallestY, Integer largestY, Integer smallestZ, Integer largestZ){
|
||||
|
||||
List<Coordinate> reinforcedBlocks = new ArrayList<Coordinate>();
|
||||
World world = myPlugin.getServer().getWorld(worldName);
|
||||
|
||||
try {
|
||||
PreparedStatement tmp = conn.prepareStatement(SELECT_REINFORCEMENTS);
|
||||
tmp.setString(1, worldName);
|
||||
tmp.setInt(2, largestX);
|
||||
tmp.setInt(3, smallestX);
|
||||
tmp.setInt(4, largestY);
|
||||
tmp.setInt(5, smallestY);
|
||||
tmp.setInt(1, largestX);
|
||||
tmp.setInt(2, smallestX);
|
||||
tmp.setInt(3, largestY);
|
||||
tmp.setInt(4, smallestY);
|
||||
tmp.setInt(5, largestZ);
|
||||
tmp.setInt(6, smallestZ);
|
||||
tmp.setString(7, worldName);
|
||||
tmp.execute();
|
||||
ResultSet result = tmp.getResultSet();
|
||||
return result;
|
||||
|
||||
while(result.next()){
|
||||
//Get X,Y,Z coords of reinforced block
|
||||
int x = result.getInt(1);
|
||||
int y = result.getInt(2);
|
||||
int z = result.getInt(3);
|
||||
|
||||
//Pass in x, y, z of reinforced block into affectedBlocks HashMap to instantiate a Block
|
||||
reinforcedBlocks.add(new Coordinate(world, x, y, z));
|
||||
}
|
||||
|
||||
tmp.close();
|
||||
result.close();
|
||||
|
||||
return reinforcedBlocks;
|
||||
} catch (SQLException e){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@@ -163,13 +189,16 @@ public class CitadelDao {
|
||||
Integer smallestY, Integer largestY, Integer smallestZ, Integer largestZ){
|
||||
try {
|
||||
PreparedStatement tmp = conn.prepareStatement(UPDATE_REINFORCEMENTS);
|
||||
tmp.setString(1, worldName);
|
||||
tmp.setInt(2, largestX);
|
||||
tmp.setInt(3, smallestX);
|
||||
tmp.setInt(4, largestY);
|
||||
tmp.setInt(5, smallestY);
|
||||
tmp.setInt(1, largestX);
|
||||
tmp.setInt(2, smallestX);
|
||||
tmp.setInt(3, largestY);
|
||||
tmp.setInt(4, smallestY);
|
||||
tmp.setInt(5, largestZ);
|
||||
tmp.setInt(6, smallestZ);
|
||||
tmp.setString(7, worldName);
|
||||
tmp.execute();
|
||||
} catch (SQLException e){
|
||||
tmp.close();
|
||||
} catch (SQLException e){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user