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; package com.cnaude.chairs.listeners;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.ItemFrame; import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.material.Stairs; import org.bukkit.material.Stairs;
import org.bukkit.material.Step; import org.bukkit.material.Step;
import org.bukkit.material.WoodenStep; import org.bukkit.material.WoodenStep;
import com.cnaude.chairs.commands.ChairsIgnoreList; import com.cnaude.chairs.commands.ChairsIgnoreList;
import com.cnaude.chairs.core.ChairBlock; import com.cnaude.chairs.core.ChairBlock;
import com.cnaude.chairs.core.Chairs; import com.cnaude.chairs.core.Chairs;
import com.cnaude.chairs.pluginhooks.WGHook;
public class TrySitEventListener implements Listener {
public class TrySitEventListener implements Listener {
public Chairs plugin;
public Chairs plugin; public ChairsIgnoreList ignoreList;
public ChairsIgnoreList ignoreList;
public TrySitEventListener(Chairs plugin, ChairsIgnoreList ignoreList) {
public TrySitEventListener(Chairs plugin, ChairsIgnoreList ignoreList) { this.plugin = plugin;
this.plugin = plugin; this.ignoreList = ignoreList;
this.ignoreList = ignoreList; }
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPlayerInteract(PlayerInteractEvent event) {
public void onPlayerInteract(PlayerInteractEvent event) { if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { Player player = event.getPlayer();
Player player = event.getPlayer(); Block block = event.getClickedBlock();
Block block = event.getClickedBlock(); if (sitAllowed(player, block)) {
if (sitAllowed(player, block)) { Location sitLocation = getSitLocation(block, player.getLocation().getYaw());
Location sitLocation = getSitLocation(block, player.getLocation().getYaw()); if (plugin.getPlayerSitData().sitPlayer(player, block, sitLocation)) {
if (plugin.getPlayerSitData().sitPlayer(player, block, sitLocation)) { event.setCancelled(true);
event.setCancelled(true); }
} }
} }
} }
}
private boolean sitAllowed(Player player, Block block) {
private boolean sitAllowed(Player player, Block block) { // Check for permissions
// Check for permissions if (!player.hasPermission("chairs.sit")) {
if (!player.hasPermission("chairs.sit")) { return false;
return false; }
}
// Check for already sitting
// Check for already sitting if (isSitting(player)) {
if (isSitting(player)) { return false;
return false; }
}
// Check for item in hand
// Check for item in hand if (plugin.ignoreIfBlockInHand && player.getItemInHand().getType() != Material.AIR) {
if (plugin.ignoreIfBlockInHand && player.getItemInHand().getType() != Material.AIR) { return false;
return false; }
}
// Check for sneaking
// Check for sneaking if (player.isSneaking()) {
if (player.isSneaking()) { return false;
return false; }
}
// Check for /chairs off
// Check for /chairs off if (ignoreList.isIgnored(player.getName())) {
if (ignoreList.isIgnored(player.getName())) { return false;
return false; }
}
// Sit occupied check
// Sit occupied check if (plugin.getPlayerSitData().isBlockOccupied(block)) {
if (plugin.getPlayerSitData().isBlockOccupied(block)) { player.sendMessage(plugin.msgOccupied.replace("%PLAYER%", plugin.getPlayerSitData().getPlayerOnChair(block).getName()));
player.sendMessage(plugin.msgOccupied.replace("%PLAYER%", plugin.getPlayerSitData().getPlayerOnChair(block).getName())); return false;
return false; }
}
Stairs stairs = null;
// Region allowance check Step step = null;
if (!WGHook.isAllowedInRegion(plugin.disabledRegions, block.getLocation())) { WoodenStep wStep = null;
return false;
} // Check for block is chair
if (isValidChair(block)) {
Stairs stairs = null;
Step step = null; if (block.getState().getData() instanceof Stairs) {
WoodenStep wStep = null; stairs = (Stairs) block.getState().getData();
} else if (block.getState().getData() instanceof Step) {
// Check for block is chair step = (Step) block.getState().getData();
if (isValidChair(block)) { } else if (block.getState().getData() instanceof WoodenStep) {
wStep = (WoodenStep) block.getState().getData();
if (block.getState().getData() instanceof Stairs) { }
stairs = (Stairs) block.getState().getData();
} else if (block.getState().getData() instanceof Step) { int chairwidth = 1;
step = (Step) block.getState().getData();
} else if (block.getState().getData() instanceof WoodenStep) { // Check if block beneath chair is solid.
wStep = (WoodenStep) block.getState().getData(); if (block.getRelative(BlockFace.DOWN).isLiquid()) {
} return false;
}
int chairwidth = 1; if (block.getRelative(BlockFace.DOWN).isEmpty()) {
return false;
// Check if block beneath chair is solid. }
if (block.getRelative(BlockFace.DOWN).isLiquid()) { if (!block.getRelative(BlockFace.DOWN).getType().isSolid()) {
return false; return false;
} }
if (block.getRelative(BlockFace.DOWN).isEmpty()) {
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) {
if (!block.getRelative(BlockFace.DOWN).getType().isSolid()) { return false;
return false; }
}
// Check if block is inverted
// Check for distance distance between player and chair. if (stairs != null && stairs.isInverted()) {
if (plugin.distance > 0 && player.getLocation().distance(block.getLocation().add(0.5, 0, 0.5)) > plugin.distance) { return false;
return false; }
} if (step != null && step.isInverted()) {
return false;
// Check if block is inverted }
if (stairs != null && stairs.isInverted()) { if (wStep != null && wStep.isInverted()) {
return false; return false;
} }
if (step != null && step.isInverted()) {
return false; // Check for signs (only for stairs)
} if (plugin.signCheck && stairs != null) {
if (wStep != null && wStep.isInverted()) { boolean sign1 = false;
return false; boolean sign2 = false;
}
if (stairs.getDescendingDirection() == BlockFace.NORTH || stairs.getDescendingDirection() == BlockFace.SOUTH) {
// Check for signs (only for stairs) sign1 = checkSign(block, BlockFace.EAST) || checkFrame(block, BlockFace.EAST, player);
if (plugin.signCheck && stairs != null) { sign2 = checkSign(block, BlockFace.WEST) || checkFrame(block, BlockFace.WEST, player);
boolean sign1 = false; } else if (stairs.getDescendingDirection() == BlockFace.EAST || stairs.getDescendingDirection() == BlockFace.WEST) {
boolean sign2 = false; sign1 = checkSign(block, BlockFace.NORTH) || checkFrame(block, BlockFace.NORTH, player);
sign2 = checkSign(block, BlockFace.SOUTH) || checkFrame(block, BlockFace.SOUTH, player);
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); if (!(sign1 && sign2)) {
} else if (stairs.getDescendingDirection() == BlockFace.EAST || stairs.getDescendingDirection() == BlockFace.WEST) { return false;
sign1 = checkSign(block, BlockFace.NORTH) || checkFrame(block, BlockFace.NORTH, player); }
sign2 = checkSign(block, BlockFace.SOUTH) || checkFrame(block, BlockFace.SOUTH, player); }
}
// Check for maximal chair width (only for stairs)
if (!(sign1 && sign2)) { if (plugin.maxChairWidth > 0 && stairs != null) {
return false; 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) {
// Check for maximal chair width (only for stairs) chairwidth += getChairWidth(block, BlockFace.NORTH);
if (plugin.maxChairWidth > 0 && stairs != null) { chairwidth += getChairWidth(block, BlockFace.SOUTH);
if (stairs.getDescendingDirection() == BlockFace.NORTH || stairs.getDescendingDirection() == BlockFace.SOUTH) { }
chairwidth += getChairWidth(block, BlockFace.EAST);
chairwidth += getChairWidth(block, BlockFace.WEST); if (chairwidth > plugin.maxChairWidth) {
} else if (stairs.getDescendingDirection() == BlockFace.EAST || stairs.getDescendingDirection() == BlockFace.WEST) { return false;
chairwidth += getChairWidth(block, BlockFace.NORTH); }
chairwidth += getChairWidth(block, BlockFace.SOUTH); }
}
return true;
if (chairwidth > plugin.maxChairWidth) { }
return false;
} return false;
} }
return true; private Location getSitLocation(Block block, Float playerYaw) {
} double sh = 0.7;
return false; for (ChairBlock cb : plugin.allowedBlocks) {
} if (cb.getMat().equals(block.getType())) {
sh = cb.getSitHeight();
private Location getSitLocation(Block block, Float playerYaw) { break;
double sh = 0.7; }
}
for (ChairBlock cb : plugin.allowedBlocks) {
if (cb.getMat().equals(block.getType())) { Stairs stairs = null;
sh = cb.getSitHeight(); if (block.getState().getData() instanceof Stairs) {
break; stairs = (Stairs) block.getState().getData();
} }
}
Location plocation = block.getLocation();
Stairs stairs = null; plocation.add(0.5D, (sh - 0.5D), 0.5D);
if (block.getState().getData() instanceof Stairs) {
stairs = (Stairs) block.getState().getData(); // Rotate the player's view to the descending side of the block.
} if (plugin.autoRotate && stairs != null) {
switch (stairs.getDescendingDirection()) {
Location plocation = block.getLocation(); case NORTH: {
plocation.add(0.5D, (sh - 0.5D), 0.5D); plocation.setYaw(180);
break;
// Rotate the player's view to the descending side of the block. }
if (plugin.autoRotate && stairs != null) { case EAST: {
switch (stairs.getDescendingDirection()) { plocation.setYaw(-90);
case NORTH: { break;
plocation.setYaw(180); }
break; case SOUTH: {
} plocation.setYaw(0);
case EAST: { break;
plocation.setYaw(-90); }
break; case WEST: {
} plocation.setYaw(90);
case SOUTH: { break;
plocation.setYaw(0); }
break; default: {
} }
case WEST: { }
plocation.setYaw(90); } else {
break; plocation.setYaw(playerYaw);
} }
default: { return plocation;
} }
}
} else {
plocation.setYaw(playerYaw);
} private boolean isValidChair(Block block) {
return plocation; for (ChairBlock cb : plugin.allowedBlocks) {
} if (cb.getMat().equals(block.getType())) {
return true;
}
}
private boolean isValidChair(Block block) { return false;
for (ChairBlock cb : plugin.allowedBlocks) { }
if (cb.getMat().equals(block.getType())) {
return true; private boolean isSitting(Player player) {
} return plugin.getPlayerSitData().isSitting(player);
} }
return false;
} private int getChairWidth(Block block, BlockFace face) {
int width = 0;
private boolean isSitting(Player player) {
return plugin.getPlayerSitData().isSitting(player); // 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);
private int getChairWidth(Block block, BlockFace face) { if (relative.getState().getData() instanceof Stairs) {
int width = 0; if (isValidChair(relative) && ((Stairs) relative.getState().getData()).getDescendingDirection() == ((Stairs) block.getState().getData()).getDescendingDirection()) {
width++;
// Go through the blocks next to the clicked block and check if there are any further stairs. } else {
for (int i = 1; i <= plugin.maxChairWidth; i++) { break;
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 { return width;
break; }
}
} 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++) {
return width; Block relative = block.getRelative(face, i);
} if (checkDirection(block, relative)) {
continue;
private boolean checkSign(Block block, BlockFace face) { }
// Go through the blocks next to the clicked block and check if are signs on the end. if (plugin.validSigns.contains(relative.getType())) {
for (int i = 1; i <= 100; i++) { return true;
Block relative = block.getRelative(face, i); } else {
if (checkDirection(block, relative)) { return false;
continue; }
} }
if (plugin.validSigns.contains(relative.getType())) { return false;
return true; }
} else {
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 false; return true;
} }
}
private boolean checkDirection(Block block1, Block block2) { return false;
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; 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.
}
return false; for (int i = 1; i <= 100; i++) {
} Block relative = block.getRelative(face, i);
if (checkDirection(block, relative)) {
private boolean checkFrame(Block block, BlockFace face, Player player) { continue;
// Go through the blocks next to the clicked block and check if are signs on the end. }
if (relative.getType().equals(Material.AIR)) {
for (int i = 1; i <= 100; i++) { int x = relative.getLocation().getBlockX();
Block relative = block.getRelative(face, i); int y = relative.getLocation().getBlockY();
if (checkDirection(block, relative)) { int z = relative.getLocation().getBlockZ();
continue; for (Entity e : player.getNearbyEntities(plugin.distance, plugin.distance, plugin.distance)) {
} if (e instanceof ItemFrame && plugin.validSigns.contains(Material.ITEM_FRAME)) {
if (relative.getType().equals(Material.AIR)) { int x2 = e.getLocation().getBlockX();
int x = relative.getLocation().getBlockX(); int y2 = e.getLocation().getBlockY();
int y = relative.getLocation().getBlockY(); int z2 = e.getLocation().getBlockZ();
int z = relative.getLocation().getBlockZ(); if (x == x2 && y == y2 && z == z2) {
for (Entity e : player.getNearbyEntities(plugin.distance, plugin.distance, plugin.distance)) { return true;
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(); return false;
if (x == x2 && y == y2 && z == z2) { } else {
return true; return false;
} }
} }
} return false;
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 # Configuration of the Chairs plugin for Craftbukkit
# ------ # ------
# A list of all compatible block and item names: http://bit.ly/AmJgMb. # 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 # 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 # 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. # 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). # 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. # 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.). # 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. # 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. # 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 # disabledWGRegions: Player won't be able to sit in those regions
# ------ # ------
sit-blocks: sit-blocks:
- WOOD_STAIRS:0.7 - WOOD_STAIRS:0.7
- SPRUCE_WOOD_STAIRS:0.7 - SPRUCE_WOOD_STAIRS:0.7
- JUNGLE_WOOD_STAIRS:0.7 - JUNGLE_WOOD_STAIRS:0.7
- BIRCH_WOOD_STAIRS:0.7 - BIRCH_WOOD_STAIRS:0.7
- SANDSTONE_STAIRS:0.7 - SANDSTONE_STAIRS:0.7
- COBBLESTONE_STAIRS:0.7 - COBBLESTONE_STAIRS:0.7
- BRICK_STAIRS:0.7 - BRICK_STAIRS:0.7
- SMOOTH_STAIRS:0.7 - SMOOTH_STAIRS:0.7
- NETHER_BRICK_STAIRS:0.7 - NETHER_BRICK_STAIRS:0.7
- QUARTZ_STAIRS:0.7 - QUARTZ_STAIRS:0.7
- ACACIA_STAIRS:0.7 - ACACIA_STAIRS:0.7
- DARK_OAK_STAIRS:0.7 - DARK_OAK_STAIRS:0.7
valid-signs: valid-signs:
- SIGN - SIGN
- WALL_SIGN - WALL_SIGN
- SIGN_POST - SIGN_POST
- ITEM_FRAME - ITEM_FRAME
auto-rotate: true auto-rotate: true
max-chair-width: 3 max-chair-width: 3
sign-check: false sign-check: false
distance: 2 distance: 2
ignore-if-item-in-hand: false ignore-if-item-in-hand: false
disabledWGRegions: sit-effects:
- exampleregionname healing:
sit-effects: enabled: false
healing: interval: 20
enabled: false amount: 1
interval: 20 max-percent: 100
amount: 1 itempickup:
max-percent: 100 enabled: false
itempickup: sit-restrictions:
enabled: false commands:
sit-restrictions: all: false
commands: list:
all: false - /examplecommand
list: notify-player: true
- /examplecommand messages:
notify-player: true sitting: '&7You are now sitting.'
messages: standing: '&7You are no longer sitting.'
sitting: '&7You are now sitting.' occupied: '&7This seat is occupied by &6%PLAYER%&7!'
standing: '&7You are no longer sitting.' reloaded: 'Chairs configuration reloaded.'
occupied: '&7This seat is occupied by &6%PLAYER%&7!' no-permission: '&cYou do not have permission to do this!'
reloaded: 'Chairs configuration reloaded.' enabled: '&7You have enabled chairs for yourself!'
no-permission: '&cYou do not have permission to do this!' disabled: '&7You have disabled chairs for yourself!'
enabled: '&7You have enabled chairs for yourself!' command-restricted: '&7You can''t issue this command while sitting'
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 name: Chairs
version: 4.3 version: 4.4
description: Let players sit on blocks. description: Let players sit on blocks.
website: http://dev.bukkit.org/bukkit-plugins/chairsreloaded/ website: http://dev.bukkit.org/bukkit-plugins/chairsreloaded/
authors: authors: