Added per item sitting height

Added sitting-height-adj option (non-stairs non-steps)
This commit is contained in:
cnaude 2013-02-24 11:24:22 -07:00
parent 896487cfce
commit 1a3c217284
5 changed files with 80 additions and 23 deletions

View File

@ -2,13 +2,14 @@
# ------ # ------
# 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.
# ------ # ------
# allowed-blocks: Set the blocks you want to be able to sit down on. Use descriptive name or item ID. # allowed-blocks: Set the blocks you want to be able to sit down on. Use descriptive name or item ID. Use name:number to set sitting height.
# 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.
# sneaking: If set to true, you have to sneak to sit down on a chair. # sneaking: If set to true, you have to sneak to sit down on a chair.
# 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.).
# sitting-height: Set how high you are sitting 'in' the stairs block (default is 0.7). # sitting-height: Set how high you are sitting 'in' the stairs block (default is 0.7).
# sitting-height-adj: Non-stairs and non-steps are adjusted automatically by this amount.
# upsidedown-check: If true then prevent players from sitting on upside down stairs. # upsidedown-check: If true then prevent players from sitting on upside down stairs.
# seat-occupied-check: Check if seat is already occupied. # seat-occupied-check: Check if seat is already occupied.
# per-item-perms: Enable chairs.sit.[item] permission node. Set to false if you're sitting on every block. # per-item-perms: Enable chairs.sit.[item] permission node. Set to false if you're sitting on every block.
@ -34,6 +35,7 @@ max-chair-width: 3
sign-check: false sign-check: false
distance: 2 distance: 2
sitting-height: 0.7 sitting-height: 0.7
sitting-height-adj: 1.0
permissions: true permissions: true
notify-player: true notify-player: true
upside-down-check: true upside-down-check: true

View File

@ -0,0 +1,29 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package net.spoothie.chairs;
import org.bukkit.Material;
/**
*
* @author cnaude
*/
public class ChairBlock {
private Material mat;
private double sitHeight;
public ChairBlock(Material m, double d) {
mat = m;
sitHeight = d;
}
public Material getMat() {
return mat;
}
public double getSitHeight() {
return sitHeight;
}
}

View File

@ -20,11 +20,11 @@ import org.bukkit.plugin.java.JavaPlugin;
public class Chairs extends JavaPlugin { public class Chairs extends JavaPlugin {
private static Chairs instance = null; private static Chairs instance = null;
public List<Material> allowedBlocks = new ArrayList<Material>(); public List<ChairBlock> allowedBlocks = new ArrayList<ChairBlock>();
public List<Material> validSigns = new ArrayList<Material>(); public List<Material> validSigns = new ArrayList<Material>();
public boolean sneaking, autoRotate, signCheck, permissions, notifyplayer, opsOverridePerms; public boolean sneaking, autoRotate, signCheck, permissions, notifyplayer, opsOverridePerms;
public boolean invertedStairCheck, seatOccupiedCheck, invertedStepCheck, perItemPerms; public boolean invertedStairCheck, seatOccupiedCheck, invertedStepCheck, perItemPerms;
public double sittingHeight, distance; public double sittingHeight, sittingHeightAdj, distance;
public int maxChairWidth; public int maxChairWidth;
private File pluginFolder; private File pluginFolder;
private File configFile; private File configFile;
@ -34,8 +34,7 @@ public class Chairs extends JavaPlugin {
public static final String LOG_HEADER = "[" + PLUGIN_NAME + "]"; public static final String LOG_HEADER = "[" + PLUGIN_NAME + "]";
static final Logger log = Logger.getLogger("Minecraft"); static final Logger log = Logger.getLogger("Minecraft");
public PluginManager pm; public PluginManager pm;
public static ChairsIgnoreList ignoreList; public static ChairsIgnoreList ignoreList;
@Override @Override
public void onEnable() { public void onEnable() {
@ -81,6 +80,7 @@ public class Chairs extends JavaPlugin {
sneaking = getConfig().getBoolean("sneaking"); sneaking = getConfig().getBoolean("sneaking");
signCheck = getConfig().getBoolean("sign-check"); signCheck = getConfig().getBoolean("sign-check");
sittingHeight = getConfig().getDouble("sitting-height"); sittingHeight = getConfig().getDouble("sitting-height");
sittingHeightAdj = getConfig().getDouble("sitting-height-adj");
distance = getConfig().getDouble("distance"); distance = getConfig().getDouble("distance");
maxChairWidth = getConfig().getInt("max-chair-width"); maxChairWidth = getConfig().getInt("max-chair-width");
permissions = getConfig().getBoolean("permissions"); permissions = getConfig().getBoolean("permissions");
@ -91,29 +91,45 @@ public class Chairs extends JavaPlugin {
perItemPerms = getConfig().getBoolean("per-item-perms"); perItemPerms = getConfig().getBoolean("per-item-perms");
opsOverridePerms = getConfig().getBoolean("ops-override-perms"); opsOverridePerms = getConfig().getBoolean("ops-override-perms");
for (String type : getConfig().getStringList("allowed-blocks")) { for (String s : getConfig().getStringList("allowed-blocks")) {
try { String type;
double sh = sittingHeight;
if (s.contains(":")) {
String tmp[] = s.split(":",2);
type = tmp[0];
sh = Double.parseDouble(tmp[1]);
} else {
type = s;
}
try {
Material mat;
if (type.matches("\\d+")) { if (type.matches("\\d+")) {
allowedBlocks.add(Material.getMaterial(Integer.parseInt(type))); mat = Material.getMaterial(Integer.parseInt(type));
} else { } else {
allowedBlocks.add(Material.getMaterial(type)); mat = Material.matchMaterial(type);
}
if (mat != null) {
logInfo("Allowed block: " + mat.toString() + " => " + sh);
allowedBlocks.add(new ChairBlock(mat,sh));
} else {
logError("Invalid block: " + type);
} }
} }
catch (Exception e) { catch (Exception e) {
logInfo("ERROR: " + e.getMessage()); logError(e.getMessage());
} }
} }
for (String type : getConfig().getStringList("valid-signs")) { for (String type : getConfig().getStringList("valid-signs")) {
try { try {
if (type.matches("\\d+")) { if (type.matches("\\d+")) {
validSigns.add(Material.getMaterial(Integer.parseInt(type))); validSigns.add(Material.getMaterial(Integer.parseInt(type)));
} else { } else {
validSigns.add(Material.getMaterial(type)); validSigns.add(Material.matchMaterial(type));
} }
} }
catch (Exception e) { catch (Exception e) {
logInfo("ERROR: " + e.getMessage()); logError(e.getMessage());
} }
} }

View File

@ -7,7 +7,6 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World;
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;
@ -55,6 +54,7 @@ public class EventListener implements Listener {
} }
} }
} }
class sendSitTask extends TimerTask { class sendSitTask extends TimerTask {
@ -106,13 +106,8 @@ public class EventListener implements Listener {
Stairs stairs = null; Stairs stairs = null;
Step step = null; Step step = null;
double sh = plugin.sittingHeight; double sh = plugin.sittingHeight;
if (block.getState().getData() instanceof Stairs) { boolean blockOkay = false;
stairs = (Stairs) block.getState().getData();
} else if (block.getState().getData() instanceof Step) {
step = (Step) block.getState().getData();
} else {
sh += 1.0;
}
Player player = event.getPlayer(); Player player = event.getPlayer();
if (ignoreList.isIgnored(player.getName())) { if (ignoreList.isIgnored(player.getName())) {
return; return;
@ -135,9 +130,24 @@ public class EventListener implements Listener {
PermissionDefault.FALSE)); PermissionDefault.FALSE));
} }
} }
if (plugin.allowedBlocks.contains(block.getType())
for (ChairBlock cb : plugin.allowedBlocks) {
if (cb.getMat().equals(block.getType())) {
blockOkay = true;
sh = cb.getSitHeight();
}
}
if (blockOkay
|| (player.hasPermission("chairs.sit." + block.getTypeId()) && plugin.perItemPerms) || (player.hasPermission("chairs.sit." + block.getTypeId()) && plugin.perItemPerms)
|| (player.hasPermission("chairs.sit." + block.getType().toString()) && plugin.perItemPerms)) { || (player.hasPermission("chairs.sit." + block.getType().toString()) && plugin.perItemPerms)) {
if (block.getState().getData() instanceof Stairs) {
stairs = (Stairs) block.getState().getData();
} else if (block.getState().getData() instanceof Step) {
step = (Step) block.getState().getData();
} else {
sh += plugin.sittingHeightAdj;
}
int chairwidth = 1; int chairwidth = 1;

View File

@ -1,5 +1,5 @@
name: Chairs name: Chairs
version: 1.16.0 version: 1.17.0
description: Let players sit on blocks. description: Let players sit on blocks.
authors: authors:
- spoothie - spoothie