Added per item sitting height
Added sitting-height-adj option (non-stairs non-steps)
This commit is contained in:
29
src/net/spoothie/chairs/ChairBlock.java
Normal file
29
src/net/spoothie/chairs/ChairBlock.java
Normal 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;
|
||||
}
|
||||
}
|
@@ -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;
|
||||
@@ -34,8 +34,7 @@ public class Chairs extends JavaPlugin {
|
||||
public static final String LOG_HEADER = "[" + PLUGIN_NAME + "]";
|
||||
static final Logger log = Logger.getLogger("Minecraft");
|
||||
public PluginManager pm;
|
||||
public static ChairsIgnoreList ignoreList;
|
||||
|
||||
public static ChairsIgnoreList ignoreList;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
@@ -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,29 +91,45 @@ public class Chairs extends JavaPlugin {
|
||||
perItemPerms = getConfig().getBoolean("per-item-perms");
|
||||
opsOverridePerms = getConfig().getBoolean("ops-override-perms");
|
||||
|
||||
for (String type : getConfig().getStringList("allowed-blocks")) {
|
||||
try {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
for (String type : getConfig().getStringList("valid-signs")) {
|
||||
for (String type : getConfig().getStringList("valid-signs")) {
|
||||
try {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
@@ -55,6 +54,7 @@ public class EventListener implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class sendSitTask extends TimerTask {
|
||||
|
||||
@@ -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,9 +130,24 @@ 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;
|
||||
|
||||
|
Reference in New Issue
Block a user