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.
# ------
# 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.
# 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).
# 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.).
# 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.
# 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.
@ -34,6 +35,7 @@ max-chair-width: 3
sign-check: false
distance: 2
sitting-height: 0.7
sitting-height-adj: 1.0
permissions: true
notify-player: 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 {
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 boolean sneaking, autoRotate, signCheck, permissions, notifyplayer, opsOverridePerms;
public boolean invertedStairCheck, seatOccupiedCheck, invertedStepCheck, perItemPerms;
public double sittingHeight, distance;
public double sittingHeight, sittingHeightAdj, distance;
public int maxChairWidth;
private File pluginFolder;
private File configFile;
@ -36,7 +36,6 @@ public class Chairs extends JavaPlugin {
public PluginManager pm;
public static ChairsIgnoreList ignoreList;
@Override
public void onEnable() {
instance = this;
@ -81,6 +80,7 @@ public class Chairs extends JavaPlugin {
sneaking = getConfig().getBoolean("sneaking");
signCheck = getConfig().getBoolean("sign-check");
sittingHeight = getConfig().getDouble("sitting-height");
sittingHeightAdj = getConfig().getDouble("sitting-height-adj");
distance = getConfig().getDouble("distance");
maxChairWidth = getConfig().getInt("max-chair-width");
permissions = getConfig().getBoolean("permissions");
@ -91,16 +91,32 @@ public class Chairs extends JavaPlugin {
perItemPerms = getConfig().getBoolean("per-item-perms");
opsOverridePerms = getConfig().getBoolean("ops-override-perms");
for (String type : getConfig().getStringList("allowed-blocks")) {
for (String s : getConfig().getStringList("allowed-blocks")) {
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+")) {
allowedBlocks.add(Material.getMaterial(Integer.parseInt(type)));
mat = Material.getMaterial(Integer.parseInt(type));
} 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) {
logInfo("ERROR: " + e.getMessage());
logError(e.getMessage());
}
}
@ -109,11 +125,11 @@ public class Chairs extends JavaPlugin {
if (type.matches("\\d+")) {
validSigns.add(Material.getMaterial(Integer.parseInt(type)));
} else {
validSigns.add(Material.getMaterial(type));
validSigns.add(Material.matchMaterial(type));
}
}
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.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Entity;
@ -56,6 +55,7 @@ public class EventListener implements Listener {
}
}
class sendSitTask extends TimerTask {
@Override
@ -106,13 +106,8 @@ public class EventListener implements Listener {
Stairs stairs = null;
Step step = null;
double sh = plugin.sittingHeight;
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 += 1.0;
}
boolean blockOkay = false;
Player player = event.getPlayer();
if (ignoreList.isIgnored(player.getName())) {
return;
@ -135,10 +130,25 @@ public class EventListener implements Listener {
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.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;
// Check if block beneath chair is solid.

View File

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