Skip to content

Commit

Permalink
Fixes CRAFTBOOK-2205, Cart Lift
Browse files Browse the repository at this point in the history
Implements a Cart Lift block to teleport players either directly up or down
  • Loading branch information
DarkArc committed Nov 6, 2012
1 parent 17cc040 commit beb6155
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 33 deletions.
Expand Up @@ -19,10 +19,10 @@
package com.sk89q.craftbook;


import java.io.File;

import org.bukkit.configuration.file.FileConfiguration;

import java.io.File;

/**
* FileConfiguration handler for CraftBook.
* All fields are final because it is never appropriate to modify them during
Expand Down Expand Up @@ -54,6 +54,7 @@ public void load() {
matEjector = getInt("eject-block", 42);
matDeposit = getInt("deposit-block", 15);
matTeleport = getInt("teleport-block", 133);
matLift = getInt("lift-block", 112);
matDispenser = getInt("dispenser-block", 129);
matMessager = getInt("messager-block", 121);

Expand Down Expand Up @@ -86,6 +87,7 @@ public void load() {
public Integer matSorter;
public Integer matEjector;
public Integer matDeposit;
public Integer matLift;
public Integer matTeleport;
public Integer matDispenser;
public Integer matMessager;
Expand Down
49 changes: 49 additions & 0 deletions vehicles/src/main/java/com/sk89q/craftbook/cart/CartLift.java
@@ -0,0 +1,49 @@
package com.sk89q.craftbook.cart;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Sign;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Minecart;

public class CartLift extends CartMechanism {

@Override
public void impact(Minecart cart, CartMechanismBlocks blocks, boolean minor) {
// validate
if (cart == null) return;
if (blocks.sign == null) return;
if (!(blocks.matches("lift up") || blocks.matches("lift down"))) return;

// go
boolean up = blocks.matches("lift up");
Block destination = blocks.sign;

BlockFace face;
if (up) face = BlockFace.UP;
else face = BlockFace.DOWN;

while (true) {

destination = destination.getRelative(face);

if (destination.getState() instanceof Sign
&& blocks.base.getTypeId() == destination.getRelative(BlockFace.UP).getTypeId()) {
String testLine = ((Sign) destination.getState()).getLine(2);

if (testLine.equalsIgnoreCase("[Lift Up]") || testLine.equalsIgnoreCase("[Lift Down]")
|| testLine.equalsIgnoreCase("[Lift]")) {
destination.getRelative(BlockFace.UP, 2);
break;
}
}
}

cart.teleport(destination.getLocation());
}

@Override
public void enter(Minecart cart, Entity entity, CartMechanismBlocks blocks,
boolean minor) {

}
}
@@ -1,18 +1,17 @@
package com.sk89q.craftbook.cart;

import java.util.HashMap;
import java.util.Map;

import com.sk89q.craftbook.InvalidMechanismException;
import com.sk89q.craftbook.VehiclesConfiguration;
import com.sk89q.craftbook.bukkit.VehiclesPlugin;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Minecart;
import org.bukkit.event.block.BlockRedstoneEvent;
import org.bukkit.event.vehicle.VehicleEnterEvent;
import org.bukkit.event.vehicle.VehicleMoveEvent;

import com.sk89q.craftbook.InvalidMechanismException;
import com.sk89q.craftbook.VehiclesConfiguration;
import com.sk89q.craftbook.bukkit.VehiclesPlugin;
import java.util.HashMap;
import java.util.Map;

public class MinecartManager {

Expand All @@ -28,31 +27,19 @@ public MinecartManager(VehiclesPlugin plugin) {
public void reloadConfiguration(VehiclesConfiguration cfg) {

mechanisms = new HashMap<Integer, CartMechanism>();
if(cfg.matBoostMax > 0)
mechanisms.put(cfg.matBoostMax, new CartBooster(100));
if(cfg.matBoost25x > 0)
mechanisms.put(cfg.matBoost25x, new CartBooster(1.25));
if(cfg.matSlow20x > 0)
mechanisms.put(cfg.matSlow20x, new CartBooster(0.8));
if(cfg.matSlow50x > 0)
mechanisms.put(cfg.matSlow50x, new CartBooster(0.5));
if(cfg.matReverse > 0)
mechanisms.put(cfg.matReverse, new CartReverser());
if(cfg.matSorter > 0)
mechanisms.put(cfg.matSorter, new CartSorter(plugin));
if(cfg.matStation > 0)
mechanisms.put(cfg.matStation, new CartStation());
if(cfg.matEjector > 0)
mechanisms.put(cfg.matEjector, new CartEjector());
if(cfg.matDeposit > 0)
mechanisms.put(cfg.matDeposit, new CartDeposit());
if(cfg.matTeleport > 0)
mechanisms.put(cfg.matTeleport, new CartTeleporter());
if(cfg.matDispenser > 0)
mechanisms.put(cfg.matDispenser, new CartDispenser());
if(cfg.matMessager > 0)
mechanisms.put(cfg.matMessager, new CartMessager(plugin));

if (cfg.matBoostMax > 0) mechanisms.put(cfg.matBoostMax, new CartBooster(100));
if (cfg.matBoost25x > 0) mechanisms.put(cfg.matBoost25x, new CartBooster(1.25));
if (cfg.matSlow20x > 0) mechanisms.put(cfg.matSlow20x, new CartBooster(0.8));
if (cfg.matSlow50x > 0) mechanisms.put(cfg.matSlow50x, new CartBooster(0.5));
if (cfg.matReverse > 0) mechanisms.put(cfg.matReverse, new CartReverser());
if (cfg.matSorter > 0) mechanisms.put(cfg.matSorter, new CartSorter());
if (cfg.matStation > 0) mechanisms.put(cfg.matStation, new CartStation());
if (cfg.matEjector > 0) mechanisms.put(cfg.matEjector, new CartEjector());
if (cfg.matDeposit > 0) mechanisms.put(cfg.matDeposit, new CartDeposit());
if (cfg.matTeleport > 0) mechanisms.put(cfg.matTeleport, new CartTeleporter());
if (cfg.matLift > 0) mechanisms.put(cfg.matLift, new CartLift());
if (cfg.matDispenser > 0) mechanisms.put(cfg.matDispenser, new CartDispenser());
if (cfg.matMessager > 0) mechanisms.put(cfg.matMessager, new CartMessager(plugin));
for (Map.Entry<Integer, CartMechanism> ent : mechanisms.entrySet()) {
ent.getValue().setMaterial(ent.getKey());
}
Expand Down

0 comments on commit beb6155

Please sign in to comment.