Some code cleanup (removed old NMS code)
Add item frames to work the same way signs do.
This commit is contained in:
parent
34920d7cee
commit
896487cfce
@ -23,6 +23,11 @@ allowed-blocks:
|
|||||||
- BRICK_STAIRS
|
- BRICK_STAIRS
|
||||||
- SMOOTH_STAIRS
|
- SMOOTH_STAIRS
|
||||||
- NETHER_BRICK_STAIRS
|
- NETHER_BRICK_STAIRS
|
||||||
|
valid-signs:
|
||||||
|
- SIGN
|
||||||
|
- WALL_SIGN
|
||||||
|
- SIGN_POST
|
||||||
|
- ITEM_FRAME
|
||||||
auto-rotate: true
|
auto-rotate: true
|
||||||
sneaking: true
|
sneaking: true
|
||||||
max-chair-width: 3
|
max-chair-width: 3
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
package net.spoothie.chairs;
|
package net.spoothie.chairs;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import net.minecraft.server.v1_4_6.DataWatcher;
|
import net.minecraft.server.v1_4_R1.DataWatcher;
|
||||||
import net.minecraft.server.v1_4_6.WatchableObject;
|
import net.minecraft.server.v1_4_R1.WatchableObject;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -6,12 +6,12 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import net.minecraft.server.v1_4_6.Packet40EntityMetadata;
|
import net.minecraft.server.v1_4_R1.Packet40EntityMetadata;
|
||||||
import org.bukkit.Bukkit;
|
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.craftbukkit.v1_4_6.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_4_R1.entity.CraftPlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.permissions.Permission;
|
import org.bukkit.permissions.Permission;
|
||||||
import org.bukkit.permissions.PermissionDefault;
|
import org.bukkit.permissions.PermissionDefault;
|
||||||
@ -21,6 +21,7 @@ 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<Material> allowedBlocks = 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, distance;
|
||||||
@ -35,6 +36,7 @@ public class Chairs extends JavaPlugin {
|
|||||||
public PluginManager pm;
|
public PluginManager pm;
|
||||||
public static ChairsIgnoreList ignoreList;
|
public static ChairsIgnoreList ignoreList;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
instance = this;
|
instance = this;
|
||||||
@ -102,6 +104,19 @@ public class Chairs extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
logInfo("ERROR: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ArrayList<String> perms = new ArrayList<String>();
|
ArrayList<String> perms = new ArrayList<String>();
|
||||||
perms.add("chairs.sit");
|
perms.add("chairs.sit");
|
||||||
perms.add("chairs.reload");
|
perms.add("chairs.reload");
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
*/
|
*/
|
||||||
package net.spoothie.chairs;
|
package net.spoothie.chairs;
|
||||||
|
|
||||||
import java.io.Console;
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
@ -7,8 +7,11 @@ 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.ItemFrame;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Event.Result;
|
import org.bukkit.event.Event.Result;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -145,7 +148,7 @@ public class EventListener implements Listener {
|
|||||||
if (block.getRelative(BlockFace.DOWN).isEmpty()) {
|
if (block.getRelative(BlockFace.DOWN).isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!net.minecraft.server.v1_4_6.Block.byId[block.getTypeId()].material.isSolid()) {
|
if (!block.getRelative(BlockFace.DOWN).getType().isSolid()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,11 +185,11 @@ public class EventListener implements Listener {
|
|||||||
boolean sign2 = false;
|
boolean sign2 = false;
|
||||||
|
|
||||||
if (stairs.getDescendingDirection() == BlockFace.NORTH || stairs.getDescendingDirection() == BlockFace.SOUTH) {
|
if (stairs.getDescendingDirection() == BlockFace.NORTH || stairs.getDescendingDirection() == BlockFace.SOUTH) {
|
||||||
sign1 = checkSign(block, BlockFace.EAST);
|
sign1 = checkSign(block, BlockFace.EAST) || checkFrame(block, BlockFace.EAST, player);
|
||||||
sign2 = checkSign(block, BlockFace.WEST);
|
sign2 = checkSign(block, BlockFace.WEST) || checkFrame(block, BlockFace.WEST, player);
|
||||||
} else if (stairs.getDescendingDirection() == BlockFace.EAST || stairs.getDescendingDirection() == BlockFace.WEST) {
|
} else if (stairs.getDescendingDirection() == BlockFace.EAST || stairs.getDescendingDirection() == BlockFace.WEST) {
|
||||||
sign1 = checkSign(block, BlockFace.NORTH);
|
sign1 = checkSign(block, BlockFace.NORTH) || checkFrame(block, BlockFace.NORTH, player);
|
||||||
sign2 = checkSign(block, BlockFace.SOUTH);
|
sign2 = checkSign(block, BlockFace.SOUTH) || checkFrame(block, BlockFace.SOUTH, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(sign1 == true && sign2 == true)) {
|
if (!(sign1 == true && sign2 == true)) {
|
||||||
@ -287,7 +290,7 @@ public class EventListener implements Listener {
|
|||||||
for (int i = 1; true; i++) {
|
for (int i = 1; true; i++) {
|
||||||
Block relative = block.getRelative(face, i);
|
Block relative = block.getRelative(face, i);
|
||||||
if (!plugin.allowedBlocks.contains(relative.getType()) || (block.getState().getData() instanceof Stairs && ((Stairs) relative.getState().getData()).getDescendingDirection() != ((Stairs) block.getState().getData()).getDescendingDirection())) {
|
if (!plugin.allowedBlocks.contains(relative.getType()) || (block.getState().getData() instanceof Stairs && ((Stairs) relative.getState().getData()).getDescendingDirection() != ((Stairs) block.getState().getData()).getDescendingDirection())) {
|
||||||
if (relative.getType() == Material.SIGN || relative.getType() == Material.WALL_SIGN || relative.getType() == Material.SIGN_POST) {
|
if (plugin.validSigns.contains(relative.getType())) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
@ -295,4 +298,31 @@ public class EventListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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; true; i++) {
|
||||||
|
Block relative = block.getRelative(face, i);
|
||||||
|
int x = relative.getLocation().getBlockX();
|
||||||
|
int y = relative.getLocation().getBlockY();
|
||||||
|
int z = relative.getLocation().getBlockZ();
|
||||||
|
if (!plugin.allowedBlocks.contains(relative.getType()) || (block.getState().getData() instanceof Stairs && ((Stairs) relative.getState().getData()).getDescendingDirection() != ((Stairs) block.getState().getData()).getDescendingDirection())) {
|
||||||
|
if (relative.getType().equals(Material.AIR)) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,5 +1,5 @@
|
|||||||
name: Chairs
|
name: Chairs
|
||||||
version: 1.15.0
|
version: 1.16.0
|
||||||
description: Let players sit on blocks.
|
description: Let players sit on blocks.
|
||||||
authors:
|
authors:
|
||||||
- spoothie
|
- spoothie
|
||||||
|
Loading…
Reference in New Issue
Block a user