Permalink
Browse files

TNT起爆判定の修正、TNTカート検知設定のミスの修正

  • Loading branch information...
hide92795 authored and hide92795 committed Sep 22, 2013
1 parent 52f9728 commit 2d92eac736323749d622e7f0316e873488050890
Binary file not shown.
@@ -10,8 +10,6 @@
import org.bukkit.plugin.java.JavaPlugin;
public class BlockRestrictions extends JavaPlugin {
private final BlockPlaceListener blockPlaceListener = new BlockPlaceListener(this);
private final TNTListener tntListener = new TNTListener(this);
public Localize localize;
private Logger logger;
@@ -21,9 +19,14 @@ public void onEnable() {
reloadConfig();
logger = getLogger();
localize = new Localize(this);
try {
reload();
} catch (Exception e1) {
logger.severe("Error has occured on loading config.");
}
PluginManager pm = getServer().getPluginManager();
pm.registerEvents(this.blockPlaceListener, this);
pm.registerEvents(this.tntListener, this);
pm.registerEvents(new BlockPlaceListener(this), this);
pm.registerEvents(new TNTListener(this), this);
logger.info("BlockRestrictions enabled!");
}
@@ -2,9 +2,11 @@
import hide92795.bukkit.plugin.blockrestrictions.BlockRestrictions;
import hide92795.bukkit.plugin.blockrestrictions.Type;
import java.util.ArrayList;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.entity.minecart.ExplosiveMinecart;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityExplodeEvent;
@@ -18,38 +20,68 @@ public TNTListener(BlockRestrictions instance) {
@EventHandler
public void onEntityExplode(EntityExplodeEvent event) {
if (plugin.isEnabled()) {
if (event.getEntity() instanceof TNTPrimed) {
Location location = event.getLocation();
Player[] players = plugin.getServer().getOnlinePlayers();
for (Player player : players) {
if (player.isOp()) {
continue;
}
if (isPlayerDetonate(player, location)) {
if (!player.hasPermission("blockrestrictions.detonate.tnt")) {
player.sendMessage(plugin.localize.getString(Type.DETONATE_TNT));
event.setCancelled(true);
}
if (event.getEntity() instanceof TNTPrimed || event.getEntity() instanceof ExplosiveMinecart) {
Location location = event.getLocation();
Player[] players = plugin.getServer().getOnlinePlayers();
boolean hasAllowedPlayer = false;
ArrayList<Player> inRangePlayers = new ArrayList<>();
for (Player player : players) {
if (isPlayerDetonate(player, location)) {
if (player.hasPermission("blockrestrictions.detonate.tnt") || player.isOp()) {
hasAllowedPlayer = true;
break;
}
inRangePlayers.add(player);
}
}
if (!hasAllowedPlayer) {
for (Player player : inRangePlayers) {
player.sendMessage(plugin.localize.getString(Type.DETONATE_TNT));
}
event.setCancelled(true);
}
}
}
private boolean isPlayerDetonate(Player player, Location location) {
if (player.getLocation().getX() > location.getX() + 20.0d) {
return false;
private boolean isInRange(int x, int i, int j) {
if (i >= j) {
if (i >= x && x >= j) {
return true;
}
} else {
if (i < x && x < j) {
return true;
}
}
if (player.getLocation().getY() > location.getY() + 20.0d) {
return false;
}
private boolean isPlayerInArea(Player player, int[] pos1ia, int[] pos2ia) {
int x = player.getLocation().getBlockX();
int y = player.getLocation().getBlockY();
int z = player.getLocation().getBlockZ();
if (!isInRange(x, pos1ia[0], pos2ia[0])) {
return false;
}
if (player.getLocation().getY() > location.getZ() + 20.0d) {
if (!isInRange(y, pos1ia[1], pos2ia[1])) {
return false;
}
if (player.getLocation().getY() > location.getZ() + 20.0d) {
if (!isInRange(z, pos1ia[2], pos2ia[2])) {
return false;
}
return true;
}
private boolean isPlayerDetonate(Player player, Location location) {
if (player.getWorld().getName().equals(location.getWorld().getName())) {
int[] pos1 = { location.getBlockX() + 10, location.getBlockY() + 10, location.getBlockZ() + 10 };
int[] pos2 = { location.getBlockX() - 10, location.getBlockY() - 10, location.getBlockZ() - 10 };
return isPlayerInArea(player, pos1, pos2);
}
return false;
}
}
@@ -1,7 +1,7 @@
name: BlockRestrictions
main: hide92795.bukkit.plugin.blockrestrictions.BlockRestrictions
description: Restrict TNT and BedRock
version: 1.6.2_2
version: 1.6.2_3
depend: [hide92795CoreLib]
author: hide92795

0 comments on commit 2d92eac

Please sign in to comment.