Skip to content

Instantly share code, notes, and snippets.

@Alvin-LB
Created July 28, 2017 08:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Alvin-LB/f03e39ddb1d29f41b634e34ff765a98b to your computer and use it in GitHub Desktop.
Save Alvin-LB/f03e39ddb1d29f41b634e34ff765a98b to your computer and use it in GitHub Desktop.
EasyElevator - Edited to work with CraftBukkit 1.12 by AlvinB
/**
* This code is licensed under the GNU GPLv3 as viewable on https://dev.bukkit.org/projects/easyelevator
*
* It was modified on the 27th of July 2017 by AlvinB
*/
package me;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
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.Sign;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
public class EasyElevator extends JavaPlugin {
private EEPlayerListener pl = new EEPlayerListener(this);
private EEConfiguration config = new EEConfiguration();
public List<Elevator> elevators = new ArrayList<>();
private int MaxPerimeter = 24;
private int MaxFloors = 10;
private boolean ArrivalSound = true;
private boolean ArrivalMessage = true;
private String BlockBorder = "41";
private String BlockFloor = "42";
private String BlockOutputDoor = "35:14";
private String BlockOutputFloor = "35:1";
public void onEnable() {
PluginManager pm = this.getServer().getPluginManager();
pm.registerEvents(this.pl, this);
this.config.createConfig();
this.MaxPerimeter = this.config.getMaxPerimeter();
this.MaxFloors = this.config.getMaxFloors();
this.ArrivalSound = this.config.getArrivalSound();
this.ArrivalMessage = this.config.getArrivalMessage();
this.BlockBorder = this.config.getBlock("Border");
this.BlockFloor = this.config.getBlock("Floor");
this.BlockOutputFloor = this.config.getBlock("OutputFloor");
this.BlockOutputDoor = this.config.getBlock("OutputDoor");
this.getLogger().info("This plugin was modified by AlvinB on the 27th of July 2017"); // Added by AlvinB
}
public void onDisable() {
Iterator var2 = this.elevators.iterator();
while(var2.hasNext()) {
Elevator e = (Elevator)var2.next();
if (e.currentFloor != null) {
e.currentFloor.switchRedstoneFloorOn(false);
}
}
}
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel1, String[] args) {
if ((commandLabel1.equals("elv") || commandLabel1.equals("eelevator")) && sender instanceof Player) {
Player player = (Player)sender;
EEPermissionManager pm = new EEPermissionManager(player);
int target;
if (args.length == 1) {
if (args[0].equals("reload")) {
if (!pm.has("easyelevator.reload")) {
player.sendMessage(ChatColor.DARK_GRAY + "[EElevator] " + ChatColor.GRAY + "You don't have permission to do this");
} else {
this.MaxPerimeter = this.config.getMaxPerimeter();
this.MaxFloors = this.config.getMaxFloors();
this.ArrivalSound = this.config.getArrivalSound();
this.ArrivalMessage = this.config.getArrivalMessage();
this.BlockBorder = this.config.getBlock("Border");
this.BlockFloor = this.config.getBlock("Floor");
this.BlockOutputFloor = this.config.getBlock("OutputFloor");
this.BlockOutputDoor = this.config.getBlock("OutputDoor");
Iterator var8 = this.elevators.iterator();
while(var8.hasNext()) {
Elevator e = (Elevator)var8.next();
if (e.currentFloor != null) {
e.currentFloor.switchRedstoneFloorOn(false);
}
}
this.elevators.clear();
player.sendMessage(ChatColor.DARK_GRAY + "[EElevator] " + ChatColor.GRAY + "The plugin has been reloaded");
}
}
if (args[0].equals("call")) {
if (!pm.has("easyelevator.call.cmd") && !pm.has("easyelevator.call.*")) {
player.sendMessage(ChatColor.DARK_GRAY + "[EElevator] " + ChatColor.GRAY + "You don't have permission to do this");
} else {
boolean success = this.Call(player);
if (success) {
player.sendMessage(ChatColor.DARK_GRAY + "[EElevator] " + ChatColor.GRAY + "The Elevator has been called");
} else {
player.sendMessage(ChatColor.DARK_GRAY + "[EElevator] " + ChatColor.GRAY + "No Elevator in range");
}
}
}
if (args[0].equals("stop")) {
if (!pm.has("easyelevator.stop.cmd") && !pm.has("easyelevator.stop.*")) {
player.sendMessage(ChatColor.DARK_GRAY + "[EElevator] " + ChatColor.GRAY + "You don't have permission to do this");
} else {
for(target = 0; target < this.elevators.size(); ++target) {
Elevator e = (Elevator)this.elevators.get(target);
if (e.isInElevator(player)) {
int target1 = e.getFloorNumberFromHeight(e.getNextFloorHeight_2());
if (target1 != -1) {
e.addStops(target);
player.sendMessage(ChatColor.DARK_GRAY + "[EElevator] " + ChatColor.GRAY + "Stopping at floor " + target);
return true;
}
}
}
}
}
}
if (args.length == 2) {
if (!args[0].equals("stop")) {
player.sendMessage(ChatColor.DARK_GRAY + "[EElevator] " + ChatColor.GRAY + "You don't have permission to do this");
} else if (pm.has("easyelevator.stop.cmd") || pm.has("easyelevator.stop.*")) {
try {
target = Integer.parseInt(args[1]);
for(int i = 0; i < this.elevators.size(); ++i) {
Elevator e = (Elevator)this.elevators.get(i);
if (e.isInElevator(player)) {
if (target > e.getFloors().size() || target < 1) {
player.sendMessage(ChatColor.DARK_GRAY + "[EElevator] " + ChatColor.GRAY + "Floor '" + target + "' is not in range");
return true;
}
e.addStops(target);
player.sendMessage(ChatColor.DARK_GRAY + "[EElevator] " + ChatColor.GRAY + "Stopping at floor " + target);
i = this.elevators.size();
}
}
} catch (Exception var10) {
player.sendMessage(ChatColor.DARK_GRAY + "[EElevator] " + ChatColor.GRAY + "Floor '" + args[1] + "' is not a valid value");
return true;
}
}
}
}
return true;
}
private boolean Call(Player player) {
Sign sign = this.getSurroundingElevatorSign(player);
if (sign != null) {
Elevator e = this.getElevator(sign);
if (e != null) {
e.Call(sign.getY());
return true;
}
}
return false;
}
private Sign getSurroundingElevatorSign(Player player) {
Block tempBlock = null;
World world = player.getWorld();
Location loc = player.getLocation();
Location l1 = null;
Location l2 = null;
int x1 = loc.getBlockX();
int y1 = loc.getBlockY();
int z1 = loc.getBlockZ();
int x2 = loc.getBlockX();
int y2 = loc.getBlockY();
int z2 = loc.getBlockZ();
int xStart = 0;
int xEnd = 0;
int yStart = 0;
int yEnd = 0;
int zStart = 0;
int zEnd = 0;
if (x1 < x2) {
xStart = x1;
xEnd = x2;
}
if (x1 > x2) {
xStart = x2;
xEnd = x1;
}
if (x1 == x2) {
xStart = x1;
xEnd = x1;
}
if (z1 < z2) {
zStart = z1;
zEnd = z2;
}
if (z1 > z2) {
zStart = z2;
zEnd = z1;
}
if (z1 == z2) {
zStart = z1;
zEnd = z1;
}
if (y1 < y2) {
yStart = y1;
yEnd = y2;
}
if (y1 > y2) {
yStart = y2;
yEnd = y1;
}
if (y1 == y2) {
yStart = y1;
yEnd = y1;
}
xStart -= 5;
yStart += 0;
zStart -= 5;
xEnd += 5;
yEnd += 2;
zEnd += 5;
for(int i = xStart; i <= xEnd; ++i) {
int x = i;
for(int j = yStart; j <= yEnd; ++j) {
int y = j;
for(int k = zStart; k <= zEnd; ++k) {
tempBlock = world.getBlockAt(x, y, k);
if (tempBlock.getType().equals(Material.WALL_SIGN) || tempBlock.getType().equals(Material.SIGN) || tempBlock.getType().equals(Material.SIGN_POST)) {
Sign sign = (Sign)tempBlock.getState();
if (sign.getLine(0).equals(ChatColor.DARK_GRAY + "[EElevator]")) {
boolean isPS = false;
Iterator var28 = this.elevators.iterator();
while(var28.hasNext()) {
Elevator e = (Elevator)var28.next();
if (e.getPlatform().getSign().equals(sign)) {
isPS = true;
}
}
if (!isPS) {
return (Sign)tempBlock.getState();
}
}
}
tempBlock = null;
}
}
}
return null;
}
public Elevator getElevator(Sign sign) {
if (sign.getLine(0).equals("[EElevator]") || sign.getLine(0).equals(ChatColor.DARK_GRAY + "[EElevator]")) {
Elevator e = null;
for(int i = 0; i < this.elevators.size(); ++i) {
org.bukkit.material.Sign signData = (org.bukkit.material.Sign)sign.getData();
Block attached = sign.getBlock().getRelative(signData.getAttachedFace());
if (((Elevator)this.elevators.get(i)).isPartOfElevator(attached.getLocation()) && (((Elevator)this.elevators.get(i)).isFloorSign(sign) || ((Elevator)this.elevators.get(i)).isPlatformSign(sign))) {
e = (Elevator)this.elevators.get(i);
i = this.elevators.size();
}
}
if (e == null) {
e = new Elevator(this, sign);
}
if (e != null && e.isInitialized()) {
if (!this.elevators.contains(e)) {
this.elevators.add(e);
}
return e;
}
}
return null;
}
public int getMaxPerimeter() {
return this.MaxPerimeter;
}
public int getMaxFloors() {
return this.MaxFloors;
}
public boolean getArrivalSound() {
return this.ArrivalSound;
}
public boolean getArrivalMessage() {
return this.ArrivalMessage;
}
public String getBlockBorder() {
return this.BlockBorder;
}
public String getBlockFloor() {
return this.BlockFloor;
}
public String getBlockOutputDoor() {
return this.BlockOutputDoor;
}
public String getBlockOutputFloor() {
return this.BlockOutputFloor;
}
}
/**
* This code is licensed under the GNU GPLv3 as viewable on https://dev.bukkit.org/projects/easyelevator
*
* It was modified on the 27th of July 2017 by AlvinB
*/
package me;
import java.io.File;
import org.bukkit.configuration.file.YamlConfiguration;
public class EEConfiguration {
private String folder = "plugins/EasyElevator";
private File configFile;
private YamlConfiguration config;
public EEConfiguration() {
this.configFile = new File(this.folder + File.separator + "config.yml");
}
private YamlConfiguration loadConfig() {
try {
YamlConfiguration config = new YamlConfiguration();
config.load(this.configFile);
return config;
} catch (Exception var2) {
System.out.println("[EasyElevator] An error occured! Please delete your SkyDiver folder an reload this Plugin!");
return null;
}
}
public void createConfig() {
(new File(this.folder)).mkdir();
if (!this.configFile.exists()) {
try {
System.out.println("[EasyElevator] Creating Config...");
this.configFile.createNewFile();
this.config = this.loadConfig();
this.config.set("MaxPerimeter", 25);
this.config.set("MaxFloors", 10);
this.config.set("Arrival.Sound", true);
this.config.set("Arrival.Message", true);
this.config.set("Blocks.Border", "41");
this.config.set("Blocks.Floor", "42");
this.config.set("Blocks.OutputDoor", "35:14");
this.config.set("Blocks.OutputFloor", "35:1");
this.config.save(this.configFile);
} catch (Exception var2) {
var2.printStackTrace();
}
} else {
this.config = this.loadConfig();
this.addNewNodes();
this.config = this.loadConfig();
}
}
public int getMaxPerimeter() {
this.config = this.loadConfig();
return this.config.getInt("MaxPerimeter");
}
public int getMaxFloors() {
this.config = this.loadConfig();
return this.config.getInt("MaxFloors");
}
public boolean getArrivalSound() {
this.config = this.loadConfig();
return this.config.getBoolean("Arrival.Sound");
}
public boolean getArrivalMessage() {
this.config = this.loadConfig();
return this.config.getBoolean("Arrival.Message");
}
public String getBlock(String Block) {
this.config = this.loadConfig();
if (this.config.contains("Blocks." + Block)) {
return this.config.getString("Blocks." + Block);
} else {
System.out.println("[EasyElevator] An error occured in your config. Please check for errors! (" + Block + ")");
return "ERROR";
}
}
public void addNewNodes() {
try {
if (this.config.contains("PlayElevatorSound")) {
this.config.set("Arrival.Sound", this.config.get("PlayElevatorSound"));
this.config.set("PlayElevatorSound", (Object)null);
System.out.println("[EasyElevator] Added Arrival.Sound Node to Configuration");
System.out.println("[EasyElevator] Removed PlayElevatorSound Node from Configuration");
}
if (!this.config.contains("Arrival.Sound")) {
this.config.set("Arrival.Sound", true);
System.out.println("[EasyElevator] Added Arrival.Sound Node to Configuration");
}
if (!this.config.contains("Arrival.Message")) {
this.config.set("Arrival.Message", true);
System.out.println("[EasyElevator] Added Arrival.Message Node to Configuration");
}
if (!this.config.contains("Blocks.Border")) {
this.config.set("Blocks.Border", "41");
System.out.println("[EasyElevator] Added Blocks.Border Node to Configuration");
}
if (!this.config.contains("Blocks.Floor")) {
this.config.set("Blocks.Floor", "42");
System.out.println("[EasyElevator] Added Blocks.Floor Node to Configuration");
}
if (!this.config.contains("Blocks.OutputDoor")) {
this.config.set("Blocks.OutputDoor", "35:14");
System.out.println("[EasyElevator] Added Blocks.OutputDoor Node to Configuration");
}
if (!this.config.contains("Blocks.OutputFloor")) {
this.config.set("Blocks.OutputFloor", "35:1");
System.out.println("[EasyElevator] Added Blocks.OutputFloor Node to Configuration");
}
this.config.save(this.configFile);
} catch (Exception var2) {
;
}
}
}
/**
* This code is licensed under the GNU GPLv3 as viewable on https://dev.bukkit.org/projects/easyelevator
*
* It was modified on the 27th of July 2017 by AlvinB
*/
package me;
import org.bukkit.entity.Player;
public class EEPermissionManager {
Player player;
String admin = "easyelevator.admin";
public EEPermissionManager(Player p) {
this.player = p;
}
public boolean has(String permission) {
return this.isAdmin() ? true : this.player.hasPermission(permission);
}
private boolean isAdmin() {
return this.player.isOp() ? true : this.player.hasPermission(this.admin);
}
}
/**
* This code is licensed under the GNU GPLv3 as viewable on https://dev.bukkit.org/projects/easyelevator
*
* It was modified on the 27th of July 2017 by AlvinB
*/
package me;
import org.bukkit.ChatColor;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockRedstoneEvent;
import org.bukkit.event.player.PlayerInteractEvent;
public class EEPlayerListener implements Listener {
EasyElevator plugin;
public EEPlayerListener(EasyElevator pl) {
this.plugin = pl;
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
Player player;
EEPermissionManager pm;
Block clicked;
Sign sign;
Elevator e;
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
player = event.getPlayer();
pm = new EEPermissionManager(player);
clicked = event.getClickedBlock();
if (clicked.getState() instanceof Sign) {
sign = (Sign)clicked.getState();
e = this.plugin.getElevator(sign);
if (e != null) {
if ((pm.has("easyelevator.call.sign") || pm.has("easyelevator.call.*")) && e.isFloorSign(sign)) {
e.Call(sign.getY());
player.sendMessage(ChatColor.DARK_GRAY + "[EElevator] " + ChatColor.GRAY + "The Elevator has been called");
return;
}
if (e.isPlatformSign(sign)) {
e.changeFloor();
return;
}
}
}
}
if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
player = event.getPlayer();
pm = new EEPermissionManager(player);
clicked = event.getClickedBlock();
if (clicked.getState() instanceof Sign) {
sign = (Sign)clicked.getState();
e = this.plugin.getElevator(sign);
if (e != null) {
if (!pm.has("easyelevator.stop.sign") && !pm.has("easyelevator.stop.*")) {
player.sendMessage(ChatColor.DARK_GRAY + "[EElevator] " + ChatColor.GRAY + "You don't have permission to do this");
} else if (e.isPlatformSign(sign)) {
e.StopAt(Integer.parseInt(e.getPlatform().getSign().getLine(1)));
player.sendMessage(ChatColor.DARK_GRAY + "[EElevator] " + ChatColor.GRAY + "Stopping at floor " + Integer.parseInt(e.getPlatform().getSign().getLine(1)));
}
}
}
}
}
@EventHandler
public void onBlockPlace(BlockRedstoneEvent event) {
}
}
/**
* This code is licensed under the GNU GPLv3 as viewable on https://dev.bukkit.org/projects/easyelevator
*
* It was modified on the 27th of July 2017 by AlvinB
*/
package me;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
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.block.Sign;
import org.bukkit.entity.Player;
public class Elevator implements Runnable {
public EasyElevator plugin;
private Sign s;
private Block attached;
private World world;
private int highestPoint;
private int lowestPoint;
private int xLow;
private int xHigh;
private int zLow;
private int zHigh;
private int maxFloors = -1;
private int maxPerimeter = -1;
private List<Integer> stops = new ArrayList();
public Floor currentFloor = null;
private String Direction = "";
private boolean isMoving = false;
private boolean hasOpenDoor = false;
private boolean isInitialized = false;
private List<Floor> floors = new ArrayList();
private Platform platform;
int lcount = 0;
public Elevator(EasyElevator elev, Sign s) {
this.plugin = elev;
this.world = s.getWorld();
this.s = s;
this.maxFloors = elev.getMaxFloors();
this.maxPerimeter = elev.getMaxPerimeter();
org.bukkit.material.Sign signData = (org.bukkit.material.Sign)s.getData();
this.attached = s.getBlock().getRelative(signData.getAttachedFace());
this.initializeLift();
}
private void initializeLift() {
int count = 0;
int low = -1;
int high = -1;
int i;
Block b2;
for(i = this.s.getY(); i >= 0; --i) {
b2 = this.world.getBlockAt(this.attached.getLocation().getBlockX(), i, this.attached.getLocation().getBlockZ());
if (this.isBorder(b2)) {
low = i;
i = -1;
}
}
for(i = this.s.getY(); i < this.world.getMaxHeight(); ++i) {
b2 = this.world.getBlockAt(this.attached.getLocation().getBlockX(), i, this.attached.getLocation().getBlockZ());
if (this.isBorder(b2)) {
high = i;
i = this.world.getMaxHeight();
}
}
if (low != -1 && high != -1) {
this.highestPoint = high;
this.lowestPoint = low;
Block b1 = null;
b2 = null;
for(i = low; i < high; ++i) {
Location currLoc = new Location(this.world, (double)this.attached.getLocation().getBlockX(), (double)i, (double)this.attached.getLocation().getBlockZ());
Block target = this.world.getBlockAt(currLoc);
if (this.isFloor(target)) {
int dirChange = 0;
String dir = "";
List<Block> blocks = new ArrayList();
Block Start = target;
Block t = null;
b2 = null;
b1 = null;
do {
Block temp = null;
if (t == null) {
if (temp == null) {
temp = this.checkForIron(Start, Start.getRelative(0, 0, 1), blocks);
if (temp != null) {
t = temp;
if (this.dirChanged(dir, "East")) {
++dirChange;
}
dir = "East";
}
}
if (temp == null) {
temp = this.checkForIron(Start, Start.getRelative(0, 0, -1), blocks);
if (temp != null) {
t = temp;
if (this.dirChanged(dir, "West")) {
++dirChange;
}
dir = "West";
}
}
if (temp == null) {
temp = this.checkForIron(Start, Start.getRelative(1, 0, 0), blocks);
if (temp != null) {
t = temp;
if (this.dirChanged(dir, "North")) {
++dirChange;
}
dir = "North";
}
}
if (temp == null) {
temp = this.checkForIron(Start, Start.getRelative(-1, 0, 0), blocks);
if (temp != null) {
t = temp;
if (this.dirChanged(dir, "South")) {
++dirChange;
}
dir = "South";
}
}
} else if (t != null) {
if (temp == null) {
temp = this.checkForIron(Start, t.getRelative(0, 0, 1), blocks);
if (temp != null) {
t = temp;
if (this.dirChanged(dir, "East")) {
++dirChange;
}
dir = "East";
}
}
if (temp == null) {
temp = this.checkForIron(Start, t.getRelative(0, 0, -1), blocks);
if (temp != null) {
t = temp;
if (this.dirChanged(dir, "West")) {
++dirChange;
}
dir = "West";
}
}
if (temp == null) {
temp = this.checkForIron(Start, t.getRelative(1, 0, 0), blocks);
if (temp != null) {
t = temp;
if (this.dirChanged(dir, "North")) {
++dirChange;
}
dir = "North";
}
}
if (temp == null) {
temp = this.checkForIron(Start, t.getRelative(-1, 0, 0), blocks);
if (temp != null) {
t = temp;
if (this.dirChanged(dir, "South")) {
++dirChange;
}
dir = "South";
}
}
}
if (temp == null) {
return;
}
if (dirChange == 1 && b1 == null) {
b1 = (Block)blocks.get(blocks.size() - 1);
}
if (dirChange == 3 && b2 == null) {
b2 = (Block)blocks.get(blocks.size() - 1);
}
blocks.add(temp);
} while(!Start.equals(t));
if (blocks.size() > this.maxPerimeter) {
return;
}
if (!blocks.contains(target)) {
return;
}
if (b1 == null || b2 == null) {
return;
}
if (dirChange != 4 && dirChange != 3) {
return;
}
Sign callSign = this.getCallSign(b1.getLocation(), b2.getLocation());
if (callSign != null) {
Floor floor = new Floor(this, b1.getLocation(), b2.getLocation(), callSign, count + 1);
this.floors.add(floor);
++count;
}
}
}
if (this.floors.size() <= this.maxFloors) {
this.platform = new Platform(this.plugin, b1.getLocation(), b2.getLocation(), ((Floor)this.floors.get(0)).getHeight(), ((Floor)this.floors.get(this.floors.size() - 1)).getHeight());
if (this.platform.isInitialized()) {
this.isInitialized = true;
System.out.println("[EasyElevator] An elevator has been initialized");
}
}
}
}
private Sign getCallSign(Location l1, Location l2) {
BlockFace[] faces = new BlockFace[]{BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST};
int x1 = l1.getBlockX();
int z1 = l1.getBlockZ();
int x2 = l2.getBlockX();
int z2 = l2.getBlockZ();
int xStart = 0;
int xEnd = 0;
int zStart = 0;
int zEnd = 0;
if (x1 < x2) {
xStart = x1;
xEnd = x2;
}
if (x1 > x2) {
xStart = x2;
xEnd = x1;
}
if (x1 == x2) {
xStart = x1;
xEnd = x1;
}
if (z1 < z2) {
zStart = z1;
zEnd = z2;
}
if (z1 > z2) {
zStart = z2;
zEnd = z1;
}
if (z1 == z2) {
zStart = z1;
zEnd = z1;
}
this.xLow = xStart;
this.xHigh = xEnd;
this.zLow = zStart;
this.zHigh = zEnd;
--xStart;
++xEnd;
--zStart;
++zEnd;
for(int i = l1.getBlockY() + 2; i <= l1.getBlockY() + 3; ++i) {
for(int x = xStart; x <= xEnd; ++x) {
for(int z = zStart; z <= zEnd; ++z) {
Block tempBlock = this.world.getBlockAt(x, i, z);
Sign sign;
if (x != xStart && x != xEnd) {
if ((z == zStart || z == zEnd) && tempBlock.getType().equals(Material.WALL_SIGN)) {
sign = (Sign)tempBlock.getState();
return sign;
}
} else if (tempBlock.getType().equals(Material.WALL_SIGN)) {
sign = (Sign)tempBlock.getState();
return sign;
}
}
}
}
return null;
}
private boolean dirChanged(String dir, String newDir) {
if (dir.equals("")) {
return false;
} else {
return !dir.equals(newDir);
}
}
private Block checkForIron(Block Start, Block t, List<Block> blocks) {
if (this.isFloor(t) || this.isOutputDoor(t) || this.isOutputFloor(t)) {
if (Start.equals(t) && blocks.size() <= 4) {
return null;
}
if (!blocks.contains(t)) {
return t;
}
}
return null;
}
public void addStops(int Floor) {
int height = -1;
for(int i = 0; i < this.floors.size(); ++i) {
if (((Floor)this.floors.get(i)).getFloor() == Floor) {
height = ((Floor)this.floors.get(i)).getHeight();
}
}
this.addStopsFromHeight(height);
}
public void addStopsFromHeight(int height) {
if (height != -1 && !this.stops.contains(height)) {
this.stops.add(height);
if (!this.isMoving) {
this.isMoving = true;
this.run();
}
}
}
public void Call(int height) {
boolean hasHeight = false;
Floor f = null;
for(int i = 0; i < this.floors.size(); ++i) {
f = (Floor)this.floors.get(i);
if (f.getSignHeight() == height) {
hasHeight = true;
f.setCalled(true);
i = this.floors.size();
}
}
if (hasHeight) {
this.addStopsFromHeight(f.getHeight());
}
}
public void StopAt(int floor) {
Iterator var3 = this.floors.iterator();
while(var3.hasNext()) {
Floor f = (Floor)var3.next();
if (f.getFloor() == floor) {
this.Call(f.getSignHeight());
return;
}
}
}
public void run() {
if (this.lcount == 6) {
this.lcount = 0;
}
this.updateDirection();
this.updateFloorIndicator();
if (!this.hasOpenDoor) {
if (!this.platform.isStuck()) {
if (this.stops.contains(this.platform.getHeight())) {
Iterator var2 = this.floors.iterator();
while(var2.hasNext()) {
Floor f = (Floor)var2.next();
if (f.getHeight() == this.platform.getHeight()) {
this.currentFloor = f;
}
}
if (this.currentFloor != null) {
if (this.plugin.getArrivalSound()) {
this.currentFloor.playOpenSound();
}
this.currentFloor.switchRedstoneFloorOn(true);
this.currentFloor.OpenDoor();
this.hasOpenDoor = true;
this.currentFloor.setCalled(false);
this.platform.stopTeleport();
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, this, 100L);
}
} else {
if (!this.Direction.equals("") && this.currentFloor != null) {
this.currentFloor.switchRedstoneFloorOn(false);
this.currentFloor = null;
}
if (this.Direction.equals("DOWN")) {
this.platform.moveDown(this.lcount);
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, this, 1L);
++this.lcount;
} else if (!this.Direction.equals("UP")) {
this.isMoving = false;
return;
}
if (this.Direction.equals("UP")) {
this.platform.moveUp(this.lcount);
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, this, 1L);
++this.lcount;
} else if (!this.Direction.equals("DOWN")) {
this.isMoving = false;
}
}
} else {
if (this.Direction.equals("UP")) {
this.Direction = "DOWN";
} else {
this.Direction = "UP";
}
this.stops.clear();
this.addStops(this.getFloorNumberFromHeight(this.getNextFloorHeight_2()));
this.platform.isStuck(false);
this.platform.sendMessage(ChatColor.DARK_GRAY + "[EElevator] " + ChatColor.GRAY + "The Elevator is stuck. Resetting...");
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, this, 50L);
}
} else if (this.currentFloor != null) {
this.currentFloor.CloseDoor();
this.hasOpenDoor = false;
this.removeCurrentFloor();
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, this, 5L);
}
}
public void changeFloor() {
int curr = Integer.parseInt(this.platform.getSign().getLine(1));
int next = curr + 1;
if (next > this.floors.size()) {
next = 1;
}
this.platform.writeSign(1, "" + next);
}
public int getFloorNumberFromHeight(int hight) {
int floor = -1;
Iterator var4 = this.floors.iterator();
while(var4.hasNext()) {
Floor f = (Floor)var4.next();
if (f.getHeight() == hight) {
return f.getFloor();
}
}
return floor;
}
public int getNextFloorHeight_2() {
int next = -1;
int current = this.platform.getHeight();
int i;
int t;
if (this.Direction.equals("UP")) {
for(i = 0; i < this.floors.size(); ++i) {
t = ((Floor)this.floors.get(i)).getHeight();
if (next == -1 && t > current) {
next = t;
}
if (t > current && t < next) {
next = t;
}
}
return next;
} else if (this.Direction.equals("DOWN")) {
for(i = 0; i < this.floors.size(); ++i) {
t = ((Floor)this.floors.get(i)).getHeight();
if (next == -1 && t < current) {
next = t;
}
if (t < current && t > next) {
next = t;
}
}
return next;
} else {
return this.Direction.equals("") ? this.platform.getHeight() : -1;
}
}
public int getNextFloorHeight() {
if (this.currentFloor == null) {
return -1;
} else {
int next = -1;
int current = this.currentFloor.getHeight();
int i;
int t;
if (this.Direction.equals("UP")) {
for(i = 0; i < this.stops.size(); ++i) {
t = (Integer)this.stops.get(i);
if (next == -1 && t > current) {
next = t;
}
if (t > current && t < next) {
next = t;
}
}
}
if (this.Direction.equals("DOWN")) {
for(i = 0; i < this.stops.size(); ++i) {
t = (Integer)this.stops.get(i);
if (next == -1 && t < current) {
next = t;
}
if (t < current && t > next) {
next = t;
}
}
}
return next;
}
}
public Platform getPlatform() {
return this.platform;
}
public Floor getMainFloor() {
return (Floor)this.floors.get(0);
}
public boolean isInitialized() {
return this.isInitialized;
}
private void removeCurrentFloor() {
for(int i = 0; i < this.stops.size(); ++i) {
if ((Integer)this.stops.get(i) == this.platform.getHeight()) {
this.stops.remove(i);
}
}
}
private void updateDirection() {
int height = this.platform.getHeight();
Iterator localIterator = this.stops.iterator();
int i;
do {
if (!localIterator.hasNext()) {
if (this.stops.size() > 0) {
if (this.Direction.equals("DOWN")) {
this.Direction = "UP";
return;
}
if (this.Direction.equals("UP")) {
this.Direction = "DOWN";
}
} else {
this.Direction = "";
}
return;
}
i = (Integer)localIterator.next();
if (this.Direction.equals("DOWN") && i < height) {
return;
}
if (this.Direction.equals("UP") && i > height) {
return;
}
} while(!this.Direction.equals(""));
if (i > height) {
this.Direction = "UP";
} else {
this.Direction = "DOWN";
}
}
private void updateFloorIndicator() {
int curr = this.getCurrentFloor();
int i;
for(i = 0; i < this.floors.size(); ++i) {
if (curr != -1) {
((Floor)this.floors.get(i)).writeSign(2, "" + curr);
} else {
if (this.Direction.equals("UP")) {
((Floor)this.floors.get(i)).writeSign(2, "/\\");
}
if (this.Direction.equals("DOWN")) {
((Floor)this.floors.get(i)).writeSign(2, "\\/");
}
}
}
if (curr != -1) {
this.platform.writeSign(2, "" + curr);
} else {
if (this.Direction.equals("UP")) {
this.platform.writeSign(2, "/\\");
}
if (this.Direction.equals("DOWN")) {
this.platform.writeSign(2, "\\/");
}
}
i = this.getFloorNumberFromHeight(this.getNextFloorHeight());
if (i != -1) {
this.platform.writeSign(3, "" + i);
} else {
this.platform.writeSign(3, "-");
}
}
public int getCurrentFloor() {
if (this.isFloor(this.platform.getHeight())) {
for(int i = 0; i < this.floors.size(); ++i) {
if (this.platform.getHeight() == ((Floor)this.floors.get(i)).getHeight()) {
return ((Floor)this.floors.get(i)).getFloor();
}
}
}
return -1;
}
public boolean isPartOfElevator(Location loc) {
int x = loc.getBlockX();
int y = loc.getBlockY();
int z = loc.getBlockZ();
return y > this.lowestPoint && y < this.highestPoint && x >= this.xLow && x <= this.xHigh && z >= this.zLow && z <= this.zHigh;
}
public boolean isFloorSign(Sign sign) {
for(int i = 0; i < this.floors.size(); ++i) {
Floor f = (Floor)this.floors.get(i);
if (f.getSign().equals(sign)) {
return true;
}
}
return false;
}
public boolean isPlatformSign(Sign sign) {
return this.platform.getSign().equals(sign);
}
public boolean isInElevator(Player player) {
return this.platform.hasPlayer(player);
}
public boolean isFloor(int floorHeight) {
for(int i = 0; i < this.floors.size(); ++i) {
if (floorHeight == ((Floor)this.floors.get(i)).getHeight()) {
return true;
}
}
return false;
}
public List<Floor> getFloors() {
return this.floors;
}
public boolean isBorder(Block b) {
try {
String border = this.plugin.getBlockBorder();
int data = -1;
int id;
if (border.contains(":")) {
id = Integer.parseInt(border.split(":")[0]);
data = Integer.parseInt(border.split(":")[1]);
} else {
id = Integer.parseInt(border);
}
if (data != -1) {
if (data == b.getData() && id == b.getTypeId()) {
return true;
}
} else if (id == b.getTypeId()) {
return true;
}
} catch (Exception var5) {
;
}
return false;
}
public boolean isFloor(Block b) {
try {
String border = this.plugin.getBlockFloor();
int data = -1;
int id;
if (border.contains(":")) {
id = Integer.parseInt(border.split(":")[0]);
data = Integer.parseInt(border.split(":")[1]);
} else {
id = Integer.parseInt(border);
}
if (data != -1) {
if (data == b.getData() && id == b.getTypeId()) {
return true;
}
} else if (id == b.getTypeId()) {
return true;
}
} catch (Exception var5) {
;
}
return false;
}
public boolean isOutputFloor(Block b) {
try {
String border = this.plugin.getBlockOutputFloor();
int data = -1;
int id;
if (border.contains(":")) {
id = Integer.parseInt(border.split(":")[0]);
data = Integer.parseInt(border.split(":")[1]);
} else {
id = Integer.parseInt(border);
}
if (data != -1) {
if (data == b.getData() && id == b.getTypeId()) {
return true;
}
} else if (id == b.getTypeId()) {
return true;
}
} catch (Exception var5) {
;
}
return false;
}
public boolean isOutputDoor(Block b) {
try {
String border = this.plugin.getBlockOutputDoor();
int data = -1;
int id;
if (border.contains(":")) {
id = Integer.parseInt(border.split(":")[0]);
data = Integer.parseInt(border.split(":")[1]);
} else {
id = Integer.parseInt(border);
}
if (data != -1) {
if (data == b.getData() && id == b.getTypeId()) {
return true;
}
} else if (id == b.getTypeId()) {
return true;
}
} catch (Exception var5) {
;
}
return false;
}
}
/**
* This code is licensed under the GNU GPLv3 as viewable on https://dev.bukkit.org/projects/easyelevator
*
* It was modified on the 27th of July 2017 by AlvinB
*/
package me;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
public class Floor {
private Elevator elevator;
private Location l1;
private Location l2;
private World world;
private Sign callSign;
private int floor;
private int height;
private boolean isCalled = false;
private boolean hasOpenDoors = false;
private Material OutputDoorMat = null;
private byte OutputDoorData = 0;
private Material OutputFloorMat = null;
private byte OutputFloorData = 0;
private List<Block> doorOpenBlock = new ArrayList();
private List<Block> redstoneOutDoorBlock = new ArrayList();
private List<Block> redstoneOutFloorBlock = new ArrayList();
public Floor(Elevator elv, Location l1, Location l2, Sign callSign, int floor) {
this.elevator = elv;
this.l1 = l1;
this.l2 = l2;
this.world = l1.getWorld();
this.callSign = callSign;
this.floor = floor;
this.height = l1.getBlockY();
this.updateSign("0");
this.initializeSign();
this.initializeDoor();
}
private void initializeSign() {
this.callSign.setLine(0, ChatColor.DARK_GRAY + "[EElevator]");
this.callSign.setLine(1, "" + this.floor);
this.callSign.update();
}
private void initializeDoor() {
int x1 = this.l1.getBlockX();
int z1 = this.l1.getBlockZ();
int x2 = this.l2.getBlockX();
int z2 = this.l2.getBlockZ();
int xStart = 0;
int xEnd = 0;
int zStart = 0;
int zEnd = 0;
if (x1 < x2) {
xStart = x1;
xEnd = x2;
}
if (x1 > x2) {
xStart = x2;
xEnd = x1;
}
if (x1 == x2) {
xStart = x1;
xEnd = x1;
}
if (z1 < z2) {
zStart = z1;
zEnd = z2;
}
if (z1 > z2) {
zStart = z2;
zEnd = z1;
}
if (z1 == z2) {
zStart = z1;
zEnd = z1;
}
for(int x = xStart; x <= xEnd; ++x) {
for(int z = zStart; z <= zEnd; ++z) {
Block tempBlock = this.world.getBlockAt(x, this.l1.getBlockY() + 1, z);
if ((x == xStart || x == xEnd || z == zStart || z == zEnd) && (tempBlock.getType().equals(Material.WOODEN_DOOR) || tempBlock.getType().equals(Material.IRON_DOOR_BLOCK))) {
this.doorOpenBlock.add(tempBlock);
}
}
}
}
private void switchRedstoneDoorOn(boolean b) {
int x1 = this.l1.getBlockX();
int z1 = this.l1.getBlockZ();
int x2 = this.l2.getBlockX();
int z2 = this.l2.getBlockZ();
int xStart = 0;
int xEnd = 0;
int zStart = 0;
int zEnd = 0;
if (x1 < x2) {
xStart = x1;
xEnd = x2;
}
if (x1 > x2) {
xStart = x2;
xEnd = x1;
}
if (x1 == x2) {
xStart = x1;
xEnd = x1;
}
if (z1 < z2) {
zStart = z1;
zEnd = z2;
}
if (z1 > z2) {
zStart = z2;
zEnd = z1;
}
if (z1 == z2) {
zStart = z1;
zEnd = z1;
}
for(int x = xStart; x <= xEnd; ++x) {
for(int z = zStart; z <= zEnd; ++z) {
Block tempBlock = this.world.getBlockAt(x, this.l1.getBlockY(), z);
if (x == xStart || x == xEnd || z == zStart || z == zEnd) {
if (b) {
if (this.elevator.isOutputDoor(tempBlock)) {
this.OutputDoorMat = tempBlock.getType();
this.OutputDoorData = tempBlock.getData();
tempBlock.setType(Material.REDSTONE_TORCH_ON);
tempBlock.setData((byte)5);
this.redstoneOutDoorBlock.add(tempBlock);
}
} else if ((this.elevator.isOutputDoor(tempBlock) || tempBlock.getType().equals(Material.REDSTONE_TORCH_ON)) && this.redstoneOutDoorBlock.contains(tempBlock)) {
tempBlock.setType(this.OutputDoorMat);
tempBlock.setData(this.OutputDoorData);
this.redstoneOutDoorBlock.remove(tempBlock);
}
}
}
}
if (!b) {
this.redstoneOutDoorBlock = new ArrayList();
}
}
public void switchRedstoneFloorOn(boolean b) {
int x1 = this.l1.getBlockX();
int z1 = this.l1.getBlockZ();
int x2 = this.l2.getBlockX();
int z2 = this.l2.getBlockZ();
int xStart = 0;
int xEnd = 0;
int zStart = 0;
int zEnd = 0;
if (x1 < x2) {
xStart = x1;
xEnd = x2;
}
if (x1 > x2) {
xStart = x2;
xEnd = x1;
}
if (x1 == x2) {
xStart = x1;
xEnd = x1;
}
if (z1 < z2) {
zStart = z1;
zEnd = z2;
}
if (z1 > z2) {
zStart = z2;
zEnd = z1;
}
if (z1 == z2) {
zStart = z1;
zEnd = z1;
}
for(int x = xStart; x <= xEnd; ++x) {
for(int z = zStart; z <= zEnd; ++z) {
Block tempBlock = this.world.getBlockAt(x, this.l1.getBlockY(), z);
if (x == xStart || x == xEnd || z == zStart || z == zEnd) {
if (b) {
if (this.elevator.isOutputFloor(tempBlock)) {
this.OutputFloorMat = tempBlock.getType();
this.OutputFloorData = tempBlock.getData();
tempBlock.setType(Material.REDSTONE_TORCH_ON);
tempBlock.setData((byte)5);
this.redstoneOutFloorBlock.add(tempBlock);
}
} else if ((this.elevator.isOutputFloor(tempBlock) || tempBlock.getType().equals(Material.REDSTONE_TORCH_ON)) && this.redstoneOutFloorBlock.contains(tempBlock)) {
tempBlock.setType(this.OutputFloorMat);
tempBlock.setData(this.OutputFloorData);
this.redstoneOutFloorBlock.remove(tempBlock);
}
}
}
}
if (!b) {
this.redstoneOutFloorBlock = new ArrayList();
}
}
public void OpenDoor() {
this.switchRedstoneDoorOn(true);
Iterator var2 = this.doorOpenBlock.iterator();
while(var2.hasNext()) {
Block block = (Block)var2.next();
if (block.getData() <= 3) {
block.setData((byte)(block.getData() + 4));
}
}
this.hasOpenDoors = true;
}
public void CloseDoor() {
Iterator var2 = this.doorOpenBlock.iterator();
while(var2.hasNext()) {
Block block = (Block)var2.next();
if (block.getData() >= 4) {
block.setData((byte)(block.getData() - 4));
}
}
this.hasOpenDoors = false;
this.switchRedstoneDoorOn(false);
}
public void updateSign(String platformFloor) {
this.callSign.setLine(2, platformFloor);
this.callSign.update();
}
public void setCalled(boolean b) {
if (b) {
if (!this.hasOpenDoors) {
this.callSign.setLine(3, "Called");
this.callSign.update();
this.isCalled = true;
}
} else {
this.callSign.setLine(3, "");
this.callSign.update();
this.isCalled = false;
}
}
public boolean isCalled() {
return this.isCalled;
}
public int getHeight() {
return this.height;
}
public int getFloor() {
return this.floor;
}
public int getSignHeight() {
return this.callSign.getY();
}
public void writeSign(int line, String message) {
this.callSign.setLine(line, message);
this.callSign.update();
}
public String getIdentifyLocation() {
return this.callSign.getBlock().getLocation().getBlockX() + " " + this.callSign.getBlock().getLocation().getBlockZ();
}
public Sign getSign() {
return this.callSign;
}
public void playOpenSound() {
Iterator var2 = this.doorOpenBlock.iterator();
while(var2.hasNext()) {
Block block = (Block)var2.next();
Location loc = block.getLocation();
loc.getWorld().playSound(loc, Sound.BLOCK_NOTE_PLING, 1.0F, 0.0F); // Changed by AlvinB
}
}
}
/**
* This code is licensed under the GNU GPLv3 as viewable on https://dev.bukkit.org/projects/easyelevator
*
* It was modified on the 27th of July 2017 by AlvinB
*/
package me;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
public class Platform {
private final EasyElevator plugin;
private final Server server;
private World world;
private int level = -1;
private int min = -1;
private int max = -1;
private int xmin;
private int zmin;
private int xmax;
private int zmax;
private boolean isInitialized = false;
private boolean isStuck = false;
private Sign platformSign = null;
private Location l1;
private Location l2;
private List<Block> platform = new ArrayList();
public Platform(EasyElevator plugin, Location l1, Location l2, int min, int max) {
this.plugin = plugin;
this.server = plugin.getServer();
this.min = min;
this.max = max;
this.world = l1.getWorld();
this.initializePlatform(l1, l2);
}
private void initializePlatform(Location l1, Location l2) {
int x1 = l1.getBlockX();
int z1 = l1.getBlockZ();
int x2 = l2.getBlockX();
int z2 = l2.getBlockZ();
int xStart = 0;
int xEnd = 0;
int zStart = 0;
int zEnd = 0;
if (x1 < x2) {
xStart = x1;
xEnd = x2;
}
if (x1 > x2) {
xStart = x2;
xEnd = x1;
}
if (x1 == x2) {
xStart = x1;
xEnd = x1;
}
if (z1 < z2) {
zStart = z1;
zEnd = z2;
}
if (z1 > z2) {
zStart = z2;
zEnd = z1;
}
if (z1 == z2) {
zStart = z1;
zEnd = z1;
}
++xStart;
--xEnd;
++zStart;
--zEnd;
this.xmin = xStart;
this.zmin = zStart;
this.xmax = xEnd;
this.zmax = zEnd;
this.l1 = this.world.getBlockAt(xStart, l1.getBlockY(), zStart).getLocation();
this.l2 = this.world.getBlockAt(xEnd, l1.getBlockY(), zEnd).getLocation();
for(int i = this.min; i <= this.max; ++i) {
for(int x = xStart; x <= xEnd; ++x) {
for(int z = zStart; z <= zEnd; ++z) {
Block tempBlock = this.world.getBlockAt(x, i, z);
Block signBlock = this.world.getBlockAt(x, i + 2, z);
if (tempBlock.getTypeId() == 43) {
this.platform.add(tempBlock);
if (signBlock.getState() instanceof Sign) {
this.platformSign = (Sign)signBlock.getState();
}
this.l1.setY((double)i);
this.l2.setY((double)i);
} else if (this.platform.size() != 0) {
return;
}
}
}
if (this.platform.size() != 0) {
i = this.max + 1;
}
}
if (this.platform.size() != 0) {
if (this.platformSign != null) {
this.isInitialized = true;
this.platformSign.setLine(0, ChatColor.DARK_GRAY + "[EElevator]");
this.platformSign.setLine(1, "1");
this.platformSign.update();
}
}
}
public void moveDown(int lcount) {
if (this.canMove(this.l1.getBlockY() - 1)) {
this.isStuck = false;
if (lcount == 5) {
for(int i = 0; i < this.platform.size(); ++i) {
Block b = (Block)this.platform.get(i);
b.setTypeId(0);
b = this.world.getBlockAt(b.getLocation().getBlockX(), b.getLocation().getBlockY() - 1, b.getLocation().getBlockZ());
b.setTypeId(43);
b.setData((byte)0);
this.platform.remove(i);
this.platform.add(i, b);
this.l1.setY((double)b.getLocation().getBlockY());
this.l2.setY((double)b.getLocation().getBlockY());
}
this.updateSign(this.platformSign.getY() - 1);
}
List<Player> players = this.world.getPlayers();
Iterator var4 = players.iterator();
while(var4.hasNext()) {
Player player = (Player)var4.next();
if (this.hasPlayer(player)) {
player.setVelocity(new Vector(0.0D, -0.17D, 0.0D));
player.setFallDistance(0.0F);
}
}
} else {
this.isStuck = true;
}
}
public void moveUp(int lcount) {
if (this.canMove(this.l1.getBlockY() + 3)) {
if (lcount == 5) {
for(int i = 0; i < this.platform.size(); ++i) {
Block b = (Block)this.platform.get(i);
b.setTypeId(0);
b = this.world.getBlockAt(b.getLocation().getBlockX(), b.getLocation().getBlockY() + 1, b.getLocation().getBlockZ());
b.setTypeId(43);
b.setData((byte)0);
this.platform.remove(i);
this.platform.add(i, b);
this.l1.setY((double)b.getLocation().getBlockY());
this.l2.setY((double)b.getLocation().getBlockY());
}
this.updateSign(this.platformSign.getY() + 1);
}
List<Player> players = this.world.getPlayers();
Iterator var4 = players.iterator();
while(var4.hasNext()) {
Player player = (Player)var4.next();
if (this.hasPlayer(player)) {
player.setVelocity(new Vector(0.0D, 0.17D, 0.0D));
player.setFallDistance(0.0F);
this.moveUpCorrection(player);
}
}
this.isStuck = false;
} else {
this.isStuck = true;
}
}
private void moveUpCorrection(Player player) {
Location pLoc = player.getLocation();
if ((double)pLoc.getBlockY() <= (double)this.l1.getBlockY() - 0.5D) {
pLoc.setY((double)(pLoc.getBlockY() + 2));
player.teleport(pLoc);
}
}
public boolean hasPlayer(Player player) {
int x = player.getLocation().getBlockX();
int y = player.getLocation().getBlockY();
int z = player.getLocation().getBlockZ();
return (y >= this.min + 5 || y <= this.max + 2) && z >= this.zmin && z <= this.zmax && x >= this.xmin && x <= this.xmax;
}
private void updateSign(int height) {
Block signBlock = this.world.getBlockAt(this.platformSign.getX(), height, this.platformSign.getZ());
signBlock.setType(Material.WALL_SIGN);
Sign nSign = (Sign)signBlock.getState();
nSign.getData().setData(this.platformSign.getData().getData());
nSign.setLine(0, this.platformSign.getLine(0));
nSign.setLine(1, this.platformSign.getLine(1));
nSign.setLine(2, this.platformSign.getLine(2));
nSign.setLine(3, this.platformSign.getLine(3));
nSign.update();
this.platformSign.getBlock().setTypeId(0);
this.platformSign = nSign;
}
public boolean canMove(int height) {
int x1 = this.l1.getBlockX();
int z1 = this.l1.getBlockZ();
int x2 = this.l2.getBlockX();
int z2 = this.l2.getBlockZ();
int xStart = 0;
int xEnd = 0;
int zStart = 0;
int zEnd = 0;
if (x1 < x2) {
xStart = x1;
xEnd = x2;
}
if (x1 > x2) {
xStart = x2;
xEnd = x1;
}
if (x1 == x2) {
xStart = x1;
xEnd = x1;
}
if (z1 < z2) {
zStart = z1;
zEnd = z2;
}
if (z1 > z2) {
zStart = z2;
zEnd = z1;
}
if (z1 == z2) {
zStart = z1;
zEnd = z1;
}
for(int x = xStart; x <= xEnd; ++x) {
for(int z = zStart; z <= zEnd; ++z) {
Block tempBlock = this.world.getBlockAt(x, height, z);
if (!tempBlock.getType().equals(Material.AIR)) {
return false;
}
}
}
return true;
}
public void sendMessage(String message) {
List<Player> players = this.world.getPlayers();
Iterator var4 = players.iterator();
while(var4.hasNext()) {
Player player = (Player)var4.next();
if (this.hasPlayer(player)) {
player.sendMessage(message);
}
}
}
public void stopTeleport() {
List<Player> players = this.world.getPlayers();
Iterator var3 = players.iterator();
while(var3.hasNext()) {
Player player = (Player)var3.next();
if (this.hasPlayer(player)) {
Location loc = player.getLocation();
loc.setY((double)(this.getHeight() + 1));
player.teleport(loc);
}
}
}
public Sign getSign() {
return this.platformSign;
}
public boolean isInitialized() {
return this.isInitialized;
}
public boolean isStuck() {
return this.isStuck;
}
public void isStuck(boolean b) {
this.isStuck = b;
}
public int getHeight() {
return this.l1.getBlockY();
}
public void writeSign(int line, String message) {
this.platformSign.setLine(line, message);
this.platformSign.update();
}
}
name: EasyElevator
main: me.EasyElevator
version: 1.2
commands:
elv:
description: Elevator Commands
usage: /elv
eelevator:
description: Elevator Commands
usage: /eelevator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment