use of org.bukkit.block.data.type.Switch in project TARDIS by eccentricdevotion.
the class TARDISJunkControlListener method onJunkBrakeUse.
@EventHandler(priority = EventPriority.MONITOR)
public void onJunkBrakeUse(PlayerInteractEvent event) {
if (event.getHand() == null || event.getHand().equals(EquipmentSlot.OFF_HAND)) {
return;
}
if (plugin.getGeneralKeeper().isJunkTravelling()) {
return;
}
Block block = event.getClickedBlock();
if (block != null) {
Material blockType = block.getType();
Location controlLoc = block.getLocation();
String c_loc = controlLoc.toString();
HashMap<String, Object> where = new HashMap<>();
where.put("location", c_loc);
if (blockType == Material.LEVER) {
// Checks handbrake location against the database.
where.put("type", 0);
ResultSetControls rsh = new ResultSetControls(plugin, where, false);
if (rsh.resultSet()) {
int id = rsh.getTardis_id();
// is it the Junk TARDIS?
ResultSetTardisPreset rs = new ResultSetTardisPreset(plugin);
if (rs.fromID(id) && rs.getPreset().equals(PRESET.JUNK)) {
Player player = event.getPlayer();
if (!TARDISPermission.hasPermission(player, "tardis.junk")) {
TARDISMessage.send(player, "JUNK_NO_PERM");
return;
}
// get the destination
getDestination(id, player);
if (plugin.getGeneralKeeper().getJunkDestination() != null) {
// get the current location
Location junkloc = null;
HashMap<String, Object> wherecl = new HashMap<>();
wherecl.put("tardis_id", id);
ResultSetCurrentLocation rsc = new ResultSetCurrentLocation(plugin, wherecl);
if (rsc.resultSet()) {
junkloc = new Location(rsc.getWorld(), rsc.getX(), rsc.getY(), rsc.getZ());
}
if (junkloc == null) {
TARDISMessage.send(player, "JUNK_NOT_FOUND");
return;
}
Switch lever = (Switch) block.getBlockData();
lever.setPowered(!lever.isPowered());
block.setBlockData(lever);
// destroy junk TARDIS
DestroyData dd = new DestroyData();
dd.setPlayer(player);
dd.setDirection(COMPASS.SOUTH);
dd.setLocation(junkloc);
dd.setHide(false);
dd.setOutside(false);
dd.setSubmarine(rsc.isSubmarine());
dd.setTardisID(id);
dd.setThrottle(SpaceTimeThrottle.JUNK);
plugin.getPresetDestroyer().destroyPreset(dd);
// fly my pretties
plugin.getGeneralKeeper().setJunkTravelling(true);
} else {
TARDISMessage.send(event.getPlayer(), "JUNK_NO_DEST");
return;
}
}
}
}
if (blockType == Material.TRIPWIRE_HOOK) {
// 4
where.put("type", 4);
ResultSetControls rst = new ResultSetControls(plugin, where, false);
if (rst.resultSet()) {
int id = rst.getTardis_id();
// is it the Junk TARDIS?
ResultSetTardisPreset rs = new ResultSetTardisPreset(plugin);
if (rs.fromID(id) && rs.getPreset().equals(PRESET.JUNK)) {
Player player = event.getPlayer();
if (!TARDISPermission.hasPermission(player, "tardis.junk")) {
TARDISMessage.send(player, "JUNK_NO_PERM");
return;
}
setSignWorld(id, player.getUniqueId());
}
}
}
if (blockType == Material.STONE_BUTTON) {
// 1
where.put("type", 1);
ResultSetControls rsh = new ResultSetControls(plugin, where, false);
if (rsh.resultSet()) {
int id = rsh.getTardis_id();
// is it the Junk TARDIS?
ResultSetTardisPreset rs = new ResultSetTardisPreset(plugin);
if (rs.fromID(id) && rs.getPreset().equals(PRESET.JUNK)) {
Player player = event.getPlayer();
if (!TARDISPermission.hasPermission(player, "tardis.junk")) {
TARDISMessage.send(player, "JUNK_NO_PERM");
return;
}
setSignCoords(id, 2);
}
}
}
if (blockType == Material.OAK_BUTTON) {
// 6
where.put("type", 6);
ResultSetControls rsh = new ResultSetControls(plugin, where, false);
if (rsh.resultSet()) {
int id = rsh.getTardis_id();
// is it the Junk TARDIS?
ResultSetTardisPreset rs = new ResultSetTardisPreset(plugin);
if (rs.fromID(id) && rs.getPreset().equals(PRESET.JUNK)) {
Player player = event.getPlayer();
if (!TARDISPermission.hasPermission(player, "tardis.junk")) {
TARDISMessage.send(player, "JUNK_NO_PERM");
return;
}
setSignCoords(id, 3);
}
}
}
}
}
use of org.bukkit.block.data.type.Switch in project SignShop by wargamer.
the class SignShopBlockListener method getAttachables.
private List<Block> getAttachables(Block originalBlock) {
List<Block> attachables = new ArrayList<>();
List<BlockFace> checkFaces = new ArrayList<>();
checkFaces.add(BlockFace.UP);
checkFaces.add(BlockFace.NORTH);
checkFaces.add(BlockFace.EAST);
checkFaces.add(BlockFace.SOUTH);
checkFaces.add(BlockFace.WEST);
Block relativeBlock;
BlockData relativeBlockData;
for (BlockFace face : checkFaces) {
relativeBlock = originalBlock.getRelative(face);
relativeBlockData = relativeBlock.getBlockData();
if (relativeBlockData instanceof Switch) {
Switch switchData = (Switch) relativeBlockData;
if (switchData.getFace() == Switch.Face.FLOOR && relativeBlock.getRelative(BlockFace.DOWN).equals(originalBlock)) {
attachables.add(relativeBlock);
}
} else if (relativeBlockData instanceof WallSign) {
WallSign wallSign = (WallSign) relativeBlockData;
if (relativeBlock.getRelative(wallSign.getFacing().getOppositeFace()).equals(originalBlock)) {
// may need to add getOppositeFace
attachables.add(relativeBlock);
}
} else if (relativeBlockData instanceof Sign)
if (relativeBlock.getRelative(BlockFace.DOWN).equals(originalBlock)) {
attachables.add(relativeBlock);
}
}
return attachables;
}
use of org.bukkit.block.data.type.Switch in project SignShop by wargamer.
the class setRedstoneOff method checkRequirements.
@Override
public Boolean checkRequirements(SignShopArguments ssArgs, Boolean activeCheck) {
if (!setupOperation(ssArgs))
return false;
boolean bReturn = false;
Block bLever;
for (int i = 0; i < ssArgs.getActivatables().get().size(); i++) {
bLever = ssArgs.getActivatables().get().get(i);
if (bLever.getType() == Material.getMaterial("LEVER") && bLever.getBlockData() instanceof Switch) {
Switch switchLever = (Switch) bLever.getBlockData();
if (switchLever.isPowered())
bReturn = true;
}
}
if (!bReturn)
ssArgs.sendFailedRequirementsMessage("already_off");
return bReturn;
}
use of org.bukkit.block.data.type.Switch in project SignShop by wargamer.
the class setRedstoneOff method runOperation.
@Override
public Boolean runOperation(SignShopArguments ssArgs) {
if (!setupOperation(ssArgs))
return false;
Block bLever;
for (int i = 0; i < ssArgs.getActivatables().get().size(); i++) {
bLever = ssArgs.getActivatables().get().get(i);
if (bLever.getType() == Material.getMaterial("LEVER") && bLever.getBlockData() instanceof Switch) {
Switch switchLever = (Switch) bLever.getBlockData();
if (switchLever.isPowered()) {
switchLever.setPowered(false);
bLever.setBlockData(switchLever);
signshopUtil.generateInteractEvent(bLever, ssArgs.getPlayer().get().getPlayer(), ssArgs.getBlockFace().get());
}
}
}
return true;
}
use of org.bukkit.block.data.type.Switch in project SignShop by wargamer.
the class setRedstoneOn method checkRequirements.
@Override
public Boolean checkRequirements(SignShopArguments ssArgs, Boolean activeCheck) {
if (!setupOperation(ssArgs))
return false;
boolean bReturn = false;
Block bLever;
for (int i = 0; i < ssArgs.getActivatables().get().size(); i++) {
bLever = ssArgs.getActivatables().get().get(i);
if (bLever.getType() == Material.getMaterial("LEVER") && bLever.getBlockData() instanceof Switch) {
Switch switchLever = (Switch) bLever.getBlockData();
if (!switchLever.isPowered())
bReturn = true;
}
}
if (!bReturn)
ssArgs.sendFailedRequirementsMessage("already_on");
return bReturn;
}
Aggregations