Remove worldguard region integration

This commit is contained in:
Shevchik 2014-12-18 10:47:59 +04:00
parent 07d0e3d4a6
commit 94825e44a8
6 changed files with 355 additions and 394 deletions

Binary file not shown.

Binary file not shown.

View File

@ -1,301 +1,295 @@
package com.cnaude.chairs.listeners;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Entity;
import org.bukkit.entity.ItemFrame;
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.player.PlayerInteractEvent;
import org.bukkit.material.Stairs;
import org.bukkit.material.Step;
import org.bukkit.material.WoodenStep;
import com.cnaude.chairs.commands.ChairsIgnoreList;
import com.cnaude.chairs.core.ChairBlock;
import com.cnaude.chairs.core.Chairs;
import com.cnaude.chairs.pluginhooks.WGHook;
public class TrySitEventListener implements Listener {
public Chairs plugin;
public ChairsIgnoreList ignoreList;
public TrySitEventListener(Chairs plugin, ChairsIgnoreList ignoreList) {
this.plugin = plugin;
this.ignoreList = ignoreList;
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerInteract(PlayerInteractEvent event) {
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
Player player = event.getPlayer();
Block block = event.getClickedBlock();
if (sitAllowed(player, block)) {
Location sitLocation = getSitLocation(block, player.getLocation().getYaw());
if (plugin.getPlayerSitData().sitPlayer(player, block, sitLocation)) {
event.setCancelled(true);
}
}
}
}
private boolean sitAllowed(Player player, Block block) {
// Check for permissions
if (!player.hasPermission("chairs.sit")) {
return false;
}
// Check for already sitting
if (isSitting(player)) {
return false;
}
// Check for item in hand
if (plugin.ignoreIfBlockInHand && player.getItemInHand().getType() != Material.AIR) {
return false;
}
// Check for sneaking
if (player.isSneaking()) {
return false;
}
// Check for /chairs off
if (ignoreList.isIgnored(player.getName())) {
return false;
}
// Sit occupied check
if (plugin.getPlayerSitData().isBlockOccupied(block)) {
player.sendMessage(plugin.msgOccupied.replace("%PLAYER%", plugin.getPlayerSitData().getPlayerOnChair(block).getName()));
return false;
}
// Region allowance check
if (!WGHook.isAllowedInRegion(plugin.disabledRegions, block.getLocation())) {
return false;
}
Stairs stairs = null;
Step step = null;
WoodenStep wStep = null;
// Check for block is chair
if (isValidChair(block)) {
if (block.getState().getData() instanceof Stairs) {
stairs = (Stairs) block.getState().getData();
} else if (block.getState().getData() instanceof Step) {
step = (Step) block.getState().getData();
} else if (block.getState().getData() instanceof WoodenStep) {
wStep = (WoodenStep) block.getState().getData();
}
int chairwidth = 1;
// Check if block beneath chair is solid.
if (block.getRelative(BlockFace.DOWN).isLiquid()) {
return false;
}
if (block.getRelative(BlockFace.DOWN).isEmpty()) {
return false;
}
if (!block.getRelative(BlockFace.DOWN).getType().isSolid()) {
return false;
}
// Check for distance distance between player and chair.
if (plugin.distance > 0 && player.getLocation().distance(block.getLocation().add(0.5, 0, 0.5)) > plugin.distance) {
return false;
}
// Check if block is inverted
if (stairs != null && stairs.isInverted()) {
return false;
}
if (step != null && step.isInverted()) {
return false;
}
if (wStep != null && wStep.isInverted()) {
return false;
}
// Check for signs (only for stairs)
if (plugin.signCheck && stairs != null) {
boolean sign1 = false;
boolean sign2 = false;
if (stairs.getDescendingDirection() == BlockFace.NORTH || stairs.getDescendingDirection() == BlockFace.SOUTH) {
sign1 = checkSign(block, BlockFace.EAST) || checkFrame(block, BlockFace.EAST, player);
sign2 = checkSign(block, BlockFace.WEST) || checkFrame(block, BlockFace.WEST, player);
} else if (stairs.getDescendingDirection() == BlockFace.EAST || stairs.getDescendingDirection() == BlockFace.WEST) {
sign1 = checkSign(block, BlockFace.NORTH) || checkFrame(block, BlockFace.NORTH, player);
sign2 = checkSign(block, BlockFace.SOUTH) || checkFrame(block, BlockFace.SOUTH, player);
}
if (!(sign1 && sign2)) {
return false;
}
}
// Check for maximal chair width (only for stairs)
if (plugin.maxChairWidth > 0 && stairs != null) {
if (stairs.getDescendingDirection() == BlockFace.NORTH || stairs.getDescendingDirection() == BlockFace.SOUTH) {
chairwidth += getChairWidth(block, BlockFace.EAST);
chairwidth += getChairWidth(block, BlockFace.WEST);
} else if (stairs.getDescendingDirection() == BlockFace.EAST || stairs.getDescendingDirection() == BlockFace.WEST) {
chairwidth += getChairWidth(block, BlockFace.NORTH);
chairwidth += getChairWidth(block, BlockFace.SOUTH);
}
if (chairwidth > plugin.maxChairWidth) {
return false;
}
}
return true;
}
return false;
}
private Location getSitLocation(Block block, Float playerYaw) {
double sh = 0.7;
for (ChairBlock cb : plugin.allowedBlocks) {
if (cb.getMat().equals(block.getType())) {
sh = cb.getSitHeight();
break;
}
}
Stairs stairs = null;
if (block.getState().getData() instanceof Stairs) {
stairs = (Stairs) block.getState().getData();
}
Location plocation = block.getLocation();
plocation.add(0.5D, (sh - 0.5D), 0.5D);
// Rotate the player's view to the descending side of the block.
if (plugin.autoRotate && stairs != null) {
switch (stairs.getDescendingDirection()) {
case NORTH: {
plocation.setYaw(180);
break;
}
case EAST: {
plocation.setYaw(-90);
break;
}
case SOUTH: {
plocation.setYaw(0);
break;
}
case WEST: {
plocation.setYaw(90);
break;
}
default: {
}
}
} else {
plocation.setYaw(playerYaw);
}
return plocation;
}
private boolean isValidChair(Block block) {
for (ChairBlock cb : plugin.allowedBlocks) {
if (cb.getMat().equals(block.getType())) {
return true;
}
}
return false;
}
private boolean isSitting(Player player) {
return plugin.getPlayerSitData().isSitting(player);
}
private int getChairWidth(Block block, BlockFace face) {
int width = 0;
// Go through the blocks next to the clicked block and check if there are any further stairs.
for (int i = 1; i <= plugin.maxChairWidth; i++) {
Block relative = block.getRelative(face, i);
if (relative.getState().getData() instanceof Stairs) {
if (isValidChair(relative) && ((Stairs) relative.getState().getData()).getDescendingDirection() == ((Stairs) block.getState().getData()).getDescendingDirection()) {
width++;
} else {
break;
}
}
}
return width;
}
private boolean checkSign(Block block, BlockFace face) {
// Go through the blocks next to the clicked block and check if are signs on the end.
for (int i = 1; i <= 100; i++) {
Block relative = block.getRelative(face, i);
if (checkDirection(block, relative)) {
continue;
}
if (plugin.validSigns.contains(relative.getType())) {
return true;
} else {
return false;
}
}
return false;
}
private boolean checkDirection(Block block1, Block block2) {
if (block1.getState().getData() instanceof Stairs && block2.getState().getData() instanceof Stairs) {
if (((Stairs) block1.getState().getData()).getDescendingDirection().equals(((Stairs) block2.getState().getData()).getDescendingDirection())) {
return true;
}
}
return false;
}
private boolean checkFrame(Block block, BlockFace face, Player player) {
// Go through the blocks next to the clicked block and check if are signs on the end.
for (int i = 1; i <= 100; i++) {
Block relative = block.getRelative(face, i);
if (checkDirection(block, relative)) {
continue;
}
if (relative.getType().equals(Material.AIR)) {
int x = relative.getLocation().getBlockX();
int y = relative.getLocation().getBlockY();
int z = relative.getLocation().getBlockZ();
for (Entity e : player.getNearbyEntities(plugin.distance, plugin.distance, plugin.distance)) {
if (e instanceof ItemFrame && plugin.validSigns.contains(Material.ITEM_FRAME)) {
int x2 = e.getLocation().getBlockX();
int y2 = e.getLocation().getBlockY();
int z2 = e.getLocation().getBlockZ();
if (x == x2 && y == y2 && z == z2) {
return true;
}
}
}
return false;
} else {
return false;
}
}
return false;
}
package com.cnaude.chairs.listeners;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Entity;
import org.bukkit.entity.ItemFrame;
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.player.PlayerInteractEvent;
import org.bukkit.material.Stairs;
import org.bukkit.material.Step;
import org.bukkit.material.WoodenStep;
import com.cnaude.chairs.commands.ChairsIgnoreList;
import com.cnaude.chairs.core.ChairBlock;
import com.cnaude.chairs.core.Chairs;
public class TrySitEventListener implements Listener {
public Chairs plugin;
public ChairsIgnoreList ignoreList;
public TrySitEventListener(Chairs plugin, ChairsIgnoreList ignoreList) {
this.plugin = plugin;
this.ignoreList = ignoreList;
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerInteract(PlayerInteractEvent event) {
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
Player player = event.getPlayer();
Block block = event.getClickedBlock();
if (sitAllowed(player, block)) {
Location sitLocation = getSitLocation(block, player.getLocation().getYaw());
if (plugin.getPlayerSitData().sitPlayer(player, block, sitLocation)) {
event.setCancelled(true);
}
}
}
}
private boolean sitAllowed(Player player, Block block) {
// Check for permissions
if (!player.hasPermission("chairs.sit")) {
return false;
}
// Check for already sitting
if (isSitting(player)) {
return false;
}
// Check for item in hand
if (plugin.ignoreIfBlockInHand && player.getItemInHand().getType() != Material.AIR) {
return false;
}
// Check for sneaking
if (player.isSneaking()) {
return false;
}
// Check for /chairs off
if (ignoreList.isIgnored(player.getName())) {
return false;
}
// Sit occupied check
if (plugin.getPlayerSitData().isBlockOccupied(block)) {
player.sendMessage(plugin.msgOccupied.replace("%PLAYER%", plugin.getPlayerSitData().getPlayerOnChair(block).getName()));
return false;
}
Stairs stairs = null;
Step step = null;
WoodenStep wStep = null;
// Check for block is chair
if (isValidChair(block)) {
if (block.getState().getData() instanceof Stairs) {
stairs = (Stairs) block.getState().getData();
} else if (block.getState().getData() instanceof Step) {
step = (Step) block.getState().getData();
} else if (block.getState().getData() instanceof WoodenStep) {
wStep = (WoodenStep) block.getState().getData();
}
int chairwidth = 1;
// Check if block beneath chair is solid.
if (block.getRelative(BlockFace.DOWN).isLiquid()) {
return false;
}
if (block.getRelative(BlockFace.DOWN).isEmpty()) {
return false;
}
if (!block.getRelative(BlockFace.DOWN).getType().isSolid()) {
return false;
}
// Check for distance distance between player and chair.
if (plugin.distance > 0 && player.getLocation().distance(block.getLocation().add(0.5, 0, 0.5)) > plugin.distance) {
return false;
}
// Check if block is inverted
if (stairs != null && stairs.isInverted()) {
return false;
}
if (step != null && step.isInverted()) {
return false;
}
if (wStep != null && wStep.isInverted()) {
return false;
}
// Check for signs (only for stairs)
if (plugin.signCheck && stairs != null) {
boolean sign1 = false;
boolean sign2 = false;
if (stairs.getDescendingDirection() == BlockFace.NORTH || stairs.getDescendingDirection() == BlockFace.SOUTH) {
sign1 = checkSign(block, BlockFace.EAST) || checkFrame(block, BlockFace.EAST, player);
sign2 = checkSign(block, BlockFace.WEST) || checkFrame(block, BlockFace.WEST, player);
} else if (stairs.getDescendingDirection() == BlockFace.EAST || stairs.getDescendingDirection() == BlockFace.WEST) {
sign1 = checkSign(block, BlockFace.NORTH) || checkFrame(block, BlockFace.NORTH, player);
sign2 = checkSign(block, BlockFace.SOUTH) || checkFrame(block, BlockFace.SOUTH, player);
}
if (!(sign1 && sign2)) {
return false;
}
}
// Check for maximal chair width (only for stairs)
if (plugin.maxChairWidth > 0 && stairs != null) {
if (stairs.getDescendingDirection() == BlockFace.NORTH || stairs.getDescendingDirection() == BlockFace.SOUTH) {
chairwidth += getChairWidth(block, BlockFace.EAST);
chairwidth += getChairWidth(block, BlockFace.WEST);
} else if (stairs.getDescendingDirection() == BlockFace.EAST || stairs.getDescendingDirection() == BlockFace.WEST) {
chairwidth += getChairWidth(block, BlockFace.NORTH);
chairwidth += getChairWidth(block, BlockFace.SOUTH);
}
if (chairwidth > plugin.maxChairWidth) {
return false;
}
}
return true;
}
return false;
}
private Location getSitLocation(Block block, Float playerYaw) {
double sh = 0.7;
for (ChairBlock cb : plugin.allowedBlocks) {
if (cb.getMat().equals(block.getType())) {
sh = cb.getSitHeight();
break;
}
}
Stairs stairs = null;
if (block.getState().getData() instanceof Stairs) {
stairs = (Stairs) block.getState().getData();
}
Location plocation = block.getLocation();
plocation.add(0.5D, (sh - 0.5D), 0.5D);
// Rotate the player's view to the descending side of the block.
if (plugin.autoRotate && stairs != null) {
switch (stairs.getDescendingDirection()) {
case NORTH: {
plocation.setYaw(180);
break;
}
case EAST: {
plocation.setYaw(-90);
break;
}
case SOUTH: {
plocation.setYaw(0);
break;
}
case WEST: {
plocation.setYaw(90);
break;
}
default: {
}
}
} else {
plocation.setYaw(playerYaw);
}
return plocation;
}
private boolean isValidChair(Block block) {
for (ChairBlock cb : plugin.allowedBlocks) {
if (cb.getMat().equals(block.getType())) {
return true;
}
}
return false;
}
private boolean isSitting(Player player) {
return plugin.getPlayerSitData().isSitting(player);
}
private int getChairWidth(Block block, BlockFace face) {
int width = 0;
// Go through the blocks next to the clicked block and check if there are any further stairs.
for (int i = 1; i <= plugin.maxChairWidth; i++) {
Block relative = block.getRelative(face, i);
if (relative.getState().getData() instanceof Stairs) {
if (isValidChair(relative) && ((Stairs) relative.getState().getData()).getDescendingDirection() == ((Stairs) block.getState().getData()).getDescendingDirection()) {
width++;
} else {
break;
}
}
}
return width;
}
private boolean checkSign(Block block, BlockFace face) {
// Go through the blocks next to the clicked block and check if are signs on the end.
for (int i = 1; i <= 100; i++) {
Block relative = block.getRelative(face, i);
if (checkDirection(block, relative)) {
continue;
}
if (plugin.validSigns.contains(relative.getType())) {
return true;
} else {
return false;
}
}
return false;
}
private boolean checkDirection(Block block1, Block block2) {
if (block1.getState().getData() instanceof Stairs && block2.getState().getData() instanceof Stairs) {
if (((Stairs) block1.getState().getData()).getDescendingDirection().equals(((Stairs) block2.getState().getData()).getDescendingDirection())) {
return true;
}
}
return false;
}
private boolean checkFrame(Block block, BlockFace face, Player player) {
// Go through the blocks next to the clicked block and check if are signs on the end.
for (int i = 1; i <= 100; i++) {
Block relative = block.getRelative(face, i);
if (checkDirection(block, relative)) {
continue;
}
if (relative.getType().equals(Material.AIR)) {
int x = relative.getLocation().getBlockX();
int y = relative.getLocation().getBlockY();
int z = relative.getLocation().getBlockZ();
for (Entity e : player.getNearbyEntities(plugin.distance, plugin.distance, plugin.distance)) {
if (e instanceof ItemFrame && plugin.validSigns.contains(Material.ITEM_FRAME)) {
int x2 = e.getLocation().getBlockX();
int y2 = e.getLocation().getBlockY();
int z2 = e.getLocation().getBlockZ();
if (x == x2 && y == y2 && z == z2) {
return true;
}
}
}
return false;
} else {
return false;
}
}
return false;
}
}

View File

@ -1,31 +0,0 @@
package com.cnaude.chairs.pluginhooks;
import java.util.HashSet;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import com.sk89q.worldedit.bukkit.BukkitUtil;
import com.sk89q.worldguard.bukkit.WGBukkit;
public class WGHook {
public static boolean isAllowedInRegion(HashSet<String> disabledRegions, Location location) {
if (Bukkit.getPluginManager().getPlugin("WorldGuard") == null) {
return true;
}
if (disabledRegions.isEmpty()) {
return true;
}
List<String> aregions = WGBukkit.getRegionManager(location.getWorld()).getApplicableRegionsIDs(BukkitUtil.toVector(location));
for (String region : aregions) {
if (disabledRegions.contains(region)) {
return false;
}
}
return true;
}
}

View File

@ -1,62 +1,60 @@
# Configuration of the Chairs plugin for Craftbukkit
# ------
# A list of all compatible block and item names: http://bit.ly/AmJgMb.
# ------
# sit-blocks: Set the blocks you want to be able to sit down on and sitting height. Use material_name:sitting_height
# valid-signs: Valid sign materials for sign check
# auto-rotate: If set to true, you are automatically rotated to the descending face of the stairs-block when sitting down.
# max-chair-width: Define how many blocks a chair can be long (set to number <= 0 for unlimited width).
# sign-check: If set to true, you will only be able to sit down when there are signs on both of the ends of the chair.
# distance: The maximum distance between the chair (the center of the block) and the player to be able to sit down (to prevent glitching through walls, etc.).
# seat-occupied-check: Check if seat is already occupied.
# ignore-if-item-in-hand: Set this true to disable sititng if player is holding an item in hand.
# disabledWGRegions: Player won't be able to sit in those regions
# ------
sit-blocks:
- WOOD_STAIRS:0.7
- SPRUCE_WOOD_STAIRS:0.7
- JUNGLE_WOOD_STAIRS:0.7
- BIRCH_WOOD_STAIRS:0.7
- SANDSTONE_STAIRS:0.7
- COBBLESTONE_STAIRS:0.7
- BRICK_STAIRS:0.7
- SMOOTH_STAIRS:0.7
- NETHER_BRICK_STAIRS:0.7
- QUARTZ_STAIRS:0.7
- ACACIA_STAIRS:0.7
- DARK_OAK_STAIRS:0.7
valid-signs:
- SIGN
- WALL_SIGN
- SIGN_POST
- ITEM_FRAME
auto-rotate: true
max-chair-width: 3
sign-check: false
distance: 2
ignore-if-item-in-hand: false
disabledWGRegions:
- exampleregionname
sit-effects:
healing:
enabled: false
interval: 20
amount: 1
max-percent: 100
itempickup:
enabled: false
sit-restrictions:
commands:
all: false
list:
- /examplecommand
notify-player: true
messages:
sitting: '&7You are now sitting.'
standing: '&7You are no longer sitting.'
occupied: '&7This seat is occupied by &6%PLAYER%&7!'
reloaded: 'Chairs configuration reloaded.'
no-permission: '&cYou do not have permission to do this!'
enabled: '&7You have enabled chairs for yourself!'
disabled: '&7You have disabled chairs for yourself!'
command-restricted: '&7You can''t issue this command while sitting'
# Configuration of the Chairs plugin for Craftbukkit
# ------
# A list of all compatible block and item names: http://bit.ly/AmJgMb.
# ------
# sit-blocks: Set the blocks you want to be able to sit down on and sitting height. Use material_name:sitting_height
# valid-signs: Valid sign materials for sign check
# auto-rotate: If set to true, you are automatically rotated to the descending face of the stairs-block when sitting down.
# max-chair-width: Define how many blocks a chair can be long (set to number <= 0 for unlimited width).
# sign-check: If set to true, you will only be able to sit down when there are signs on both of the ends of the chair.
# distance: The maximum distance between the chair (the center of the block) and the player to be able to sit down (to prevent glitching through walls, etc.).
# seat-occupied-check: Check if seat is already occupied.
# ignore-if-item-in-hand: Set this true to disable sititng if player is holding an item in hand.
# disabledWGRegions: Player won't be able to sit in those regions
# ------
sit-blocks:
- WOOD_STAIRS:0.7
- SPRUCE_WOOD_STAIRS:0.7
- JUNGLE_WOOD_STAIRS:0.7
- BIRCH_WOOD_STAIRS:0.7
- SANDSTONE_STAIRS:0.7
- COBBLESTONE_STAIRS:0.7
- BRICK_STAIRS:0.7
- SMOOTH_STAIRS:0.7
- NETHER_BRICK_STAIRS:0.7
- QUARTZ_STAIRS:0.7
- ACACIA_STAIRS:0.7
- DARK_OAK_STAIRS:0.7
valid-signs:
- SIGN
- WALL_SIGN
- SIGN_POST
- ITEM_FRAME
auto-rotate: true
max-chair-width: 3
sign-check: false
distance: 2
ignore-if-item-in-hand: false
sit-effects:
healing:
enabled: false
interval: 20
amount: 1
max-percent: 100
itempickup:
enabled: false
sit-restrictions:
commands:
all: false
list:
- /examplecommand
notify-player: true
messages:
sitting: '&7You are now sitting.'
standing: '&7You are no longer sitting.'
occupied: '&7This seat is occupied by &6%PLAYER%&7!'
reloaded: 'Chairs configuration reloaded.'
no-permission: '&cYou do not have permission to do this!'
enabled: '&7You have enabled chairs for yourself!'
disabled: '&7You have disabled chairs for yourself!'
command-restricted: '&7You can''t issue this command while sitting'

View File

@ -1,5 +1,5 @@
name: Chairs
version: 4.3
version: 4.4
description: Let players sit on blocks.
website: http://dev.bukkit.org/bukkit-plugins/chairsreloaded/
authors: