private void register() { if (!lookupNamesNet.containsKey(getNetwork().toLowerCase())) { Stargate.debug("register", "Network not in lookupNamesNet, adding"); lookupNamesNet.put(getNetwork().toLowerCase(), new HashMap<String, Portal>()); } lookupNamesNet.get(getNetwork().toLowerCase()).put(getName().toLowerCase(), this); for (Blox block : getFrame()) { lookupBlocks.put(block, this); } // Include the sign and button lookupBlocks.put(new Blox(id.getBlock()), this); if (button != null) { lookupBlocks.put(button, this); } for (Blox entrance : getEntrances()) { lookupEntrances.put(entrance, this); } allPortals.add(this); // Check if this network exists if (!allPortalsNet.containsKey(getNetwork().toLowerCase())) { Stargate.debug("register", "Network not in allPortalsNet, adding"); allPortalsNet.put(getNetwork().toLowerCase(), new ArrayList<String>()); } allPortalsNet.get(getNetwork().toLowerCase()).add(getName().toLowerCase()); }
public void teleport(final Vehicle vehicle) { Location traveller = new Location( this.world, vehicle.getLocation().getX(), vehicle.getLocation().getY(), vehicle.getLocation().getZ()); Location exit = getExit(traveller); double velocity = vehicle.getVelocity().length(); // Stop and teleport vehicle.setVelocity(new Vector()); // Get new velocity final Vector newVelocity = new Vector(); switch ((int) id.getBlock().getData()) { case 2: newVelocity.setZ(-1); break; case 3: newVelocity.setZ(1); break; case 4: newVelocity.setX(-1); break; case 5: newVelocity.setX(1); break; } newVelocity.multiply(velocity); final Entity passenger = vehicle.getPassenger(); if (passenger != null) { final Vehicle v = exit.getWorld().spawn(exit, vehicle.getClass()); vehicle.eject(); vehicle.remove(); passenger.teleport(exit); Stargate.server .getScheduler() .scheduleSyncDelayedTask( Stargate.stargate, new Runnable() { public void run() { v.setPassenger(passenger); v.setVelocity(newVelocity); } }, 1); } else { Vehicle mc = exit.getWorld().spawn(exit, vehicle.getClass()); if (mc instanceof StorageMinecart) { StorageMinecart smc = (StorageMinecart) mc; smc.getInventory().setContents(((StorageMinecart) vehicle).getInventory().getContents()); } mc.setVelocity(newVelocity); vehicle.remove(); } }
public void unregister(boolean removeAll) { Stargate.debug("Unregister", "Unregistering gate " + getName()); close(true); lookupNamesNet.get(getNetwork().toLowerCase()).remove(getName().toLowerCase()); for (Blox block : getFrame()) { lookupBlocks.remove(block); } // Include the sign and button lookupBlocks.remove(new Blox(id.getBlock())); if (button != null) { lookupBlocks.remove(button); } for (Blox entrance : getEntrances()) { lookupEntrances.remove(entrance); } if (removeAll) allPortals.remove(this); allPortalsNet.get(getNetwork().toLowerCase()).remove(getName().toLowerCase()); if (id.getBlock().getType() == Material.WALL_SIGN) { id.setText(0, getName()); id.setText(1, ""); id.setText(2, ""); id.setText(3, ""); id.update(); } for (String originName : allPortalsNet.get(getNetwork().toLowerCase())) { Portal origin = Portal.getByName(originName, getNetwork()); if (origin == null) continue; if (!origin.getDestinationName().equalsIgnoreCase(getName())) continue; if (!origin.isVerified()) continue; if (origin.isFixed()) origin.drawSign(); if (origin.isAlwaysOn()) origin.close(true); } saveAllGates(getWorld()); }
public static Portal createPortal(SignChangeEvent event, Player player) { SignPost id = new SignPost(new Blox(event.getBlock())); Block idParent = id.getParent(); if (idParent == null) { return null; } if (Gate.getGatesByControlBlock(idParent).length == 0) return null; if (Portal.getByBlock(idParent) != null) { Stargate.debug("createPortal", "idParent belongs to existing gate"); return null; } Blox parent = new Blox(player.getWorld(), idParent.getX(), idParent.getY(), idParent.getZ()); Blox topleft = null; String name = filterName(event.getLine(0)); String destName = filterName(event.getLine(1)); String network = filterName(event.getLine(2)); String options = filterName(event.getLine(3)); boolean hidden = (options.indexOf('h') != -1 || options.indexOf('H') != -1); boolean alwaysOn = (options.indexOf('a') != -1 || options.indexOf('A') != -1); boolean priv = (options.indexOf('p') != -1 || options.indexOf('P') != -1); boolean free = (options.indexOf('f') != -1 || options.indexOf('F') != -1); boolean backwards = (options.indexOf('b') != -1 || options.indexOf('B') != -1); boolean show = (options.indexOf('s') != -1 || options.indexOf('S') != -1); // Check permissions for options. if (hidden && !Stargate.canOption(player, "hidden")) hidden = false; if (alwaysOn && !Stargate.canOption(player, "alwayson")) alwaysOn = false; if (priv && !Stargate.canOption(player, "private")) priv = false; if (free && !Stargate.canOption(player, "free")) free = false; if (backwards && !Stargate.canOption(player, "backwards")) backwards = false; if (show && !Stargate.canOption(player, "show")) show = false; // Can not create a non-fixed always-on gate. if (alwaysOn && destName.length() == 0) { alwaysOn = false; } // Show isn't useful if A is false if (show && !alwaysOn) { show = false; } // Moved the layout check so as to avoid invalid messages when not making a gate int modX = 0; int modZ = 0; float rotX = 0f; int facing = 0; if (idParent.getX() > id.getBlock().getX()) { modZ -= 1; rotX = 90f; facing = 2; } else if (idParent.getX() < id.getBlock().getX()) { modZ += 1; rotX = 270f; facing = 1; } else if (idParent.getZ() > id.getBlock().getZ()) { modX += 1; rotX = 180f; facing = 4; } else if (idParent.getZ() < id.getBlock().getZ()) { modX -= 1; rotX = 0f; facing = 3; } Gate[] possibleGates = Gate.getGatesByControlBlock(idParent); Gate gate = null; RelativeBlockVector buttonVector = null; for (Gate possibility : possibleGates) { if ((gate == null) && (buttonVector == null)) { RelativeBlockVector[] vectors = possibility.getControls(); RelativeBlockVector otherControl = null; for (RelativeBlockVector vector : vectors) { Blox tl = parent.modRelative( -vector.getRight(), -vector.getDepth(), -vector.getDistance(), modX, 1, modZ); if (gate == null) { if (possibility.matches(tl, modX, modZ, true)) { gate = possibility; topleft = tl; if (otherControl != null) { buttonVector = otherControl; } } } else if (otherControl != null) { buttonVector = vector; } otherControl = vector; } } } if ((gate == null) || (buttonVector == null)) { Stargate.debug("createPortal", "Could not find matching gate layout"); return null; } // Debug Stargate.debug( "createPortal", "h = " + hidden + " a = " + alwaysOn + " p = " + priv + " f = " + free + " b = " + backwards + " s = " + show); if ((network.length() < 1) || (network.length() > 11)) { network = Stargate.getDefaultNetwork(); } // Check if the player can create gates on this network if (!Stargate.canCreate(player, network)) { Stargate.debug( "createPortal", "Player doesn't have create permissions on network. Trying personal"); if (Stargate.canCreatePersonal(player)) { network = player.getName(); if (network.length() > 11) network = network.substring(0, 11); Stargate.debug("createPortal", "Creating personal portal"); Stargate.sendMessage(player, Stargate.getString("createPersonal")); } else { Stargate.debug("createPortal", "Player does not have access to network"); Stargate.sendMessage(player, Stargate.getString("createNetDeny")); return null; } } // Check if the player can create this gate layout String gateName = gate.getFilename(); gateName = gateName.substring(0, gateName.indexOf('.')); if (!Stargate.canCreateGate(player, gateName)) { Stargate.debug("createPortal", "Player does not have access to gate layout"); Stargate.sendMessage(player, Stargate.getString("createGateDeny")); return null; } if (name.length() < 1 || name.length() > 11) { Stargate.debug("createPortal", "Name length error"); Stargate.sendMessage(player, Stargate.getString("createNameLength")); return null; } if (getByName(name, network) != null) { Stargate.debug("createPortal", "Name Error"); Stargate.sendMessage(player, Stargate.getString("createExists")); return null; } // Check if there are too many gates in this network ArrayList<String> netList = allPortalsNet.get(network.toLowerCase()); if (Stargate.maxGates > 0 && netList != null && netList.size() >= Stargate.maxGates) { Stargate.sendMessage(player, Stargate.getString("createFull")); return null; } // Check if the user can create gates to this world. if (destName.length() > 0) { Portal p = Portal.getByName(destName, network); if (p != null) { String world = p.getWorld().getName(); if (!Stargate.canAccessWorld(player, world)) { Stargate.debug("canCreate", "Player does not have access to destination world"); Stargate.sendMessage(player, Stargate.getString("createWorldDeny")); return null; } } } // Bleh, gotta check to make sure none of this gate belongs to another gate. Boo slow. for (RelativeBlockVector v : gate.getBorder()) { Blox b = topleft.modRelative(v.getRight(), v.getDepth(), v.getDistance(), modX, 1, modZ); if (Portal.getByBlock(b.getBlock()) != null) { Stargate.debug("createPortal", "Gate conflicts with existing gate"); Stargate.sendMessage(player, Stargate.getString("createConflict")); return null; } } int cost = Stargate.getCreateCost(player, gate); if (cost > 0) { if (!Stargate.chargePlayer(player, null, gate.getCreateCost())) { String inFundMsg = Stargate.getString("ecoInFunds"); inFundMsg = Stargate.replaceVars( inFundMsg, new String[] {"%cost%", "%portal%"}, new String[] {iConomyHandler.format(cost), name}); Stargate.sendMessage(player, inFundMsg); Stargate.debug("createPortal", "Insufficient Funds"); return null; } String deductMsg = Stargate.getString("ecoDeduct"); deductMsg = Stargate.replaceVars( deductMsg, new String[] {"%cost%", "%portal%"}, new String[] {iConomyHandler.format(cost), name}); Stargate.sendMessage(player, deductMsg, false); } Portal portal = null; Blox button = null; // No button on an always-open gate. if (!alwaysOn) { button = topleft.modRelative( buttonVector.getRight(), buttonVector.getDepth(), buttonVector.getDistance() + 1, modX, 1, modZ); button.setType(Material.STONE_BUTTON.getId()); button.setData(facing); } portal = new Portal( topleft, modX, modZ, rotX, id, button, destName, name, true, network, gate, player.getName(), hidden, alwaysOn, priv, free, backwards, show); // Open always on gate if (portal.isAlwaysOn()) { Portal dest = Portal.getByName(destName, portal.getNetwork()); if (dest != null) { portal.open(true); dest.drawSign(); } // Set the inside of the gate to its closed material } else { for (Blox inside : portal.getEntrances()) { inside.setType(portal.getGate().getPortalBlockClosed()); } } // Open any always on gate pointing at this gate for (String originName : allPortalsNet.get(portal.getNetwork().toLowerCase())) { Portal origin = Portal.getByName(originName, portal.getNetwork()); if (origin == null) continue; if (!origin.getDestinationName().equalsIgnoreCase(portal.getName())) continue; if (!origin.isVerified()) continue; if (origin.isFixed()) origin.drawSign(); if (origin.isAlwaysOn()) origin.open(true); } saveAllGates(portal.getWorld()); return portal; }
public final void drawSign() { id.setText(0, "--" + name + "--"); int max = destinations.size() - 1; int done = 0; if (!isActive()) { id.setText(++done, "Right click to"); id.setText(++done, "use the gate"); id.setText(++done, " (" + network + ") "); } else { if (isFixed()) { id.setText(++done, "To: " + destination); id.setText(++done, " (" + network + ") "); Portal dest = Portal.getByName(destination, network); if (dest == null) { id.setText(++done, "(Not Connected)"); } else { id.setText(++done, ""); } } else { int index = destinations.indexOf(destination); if ((index == max) && (max > 1) && (++done <= 3)) { if (iConomyHandler.useiConomy() && iConomyHandler.freeGatesGreen) { Portal dest = Portal.getByName(destinations.get(index - 2), network); boolean green = Stargate.isFree(activePlayer, this, dest); id.setText(done, (green ? ChatColor.DARK_GREEN : "") + destinations.get(index - 2)); } else { id.setText(done, destinations.get(index - 2)); } } if ((index > 0) && (++done <= 3)) { if (iConomyHandler.useiConomy() && iConomyHandler.freeGatesGreen) { Portal dest = Portal.getByName(destinations.get(index - 1), network); boolean green = Stargate.isFree(activePlayer, this, dest); id.setText(done, (green ? ChatColor.DARK_GREEN : "") + destinations.get(index - 1)); } else { id.setText(done, destinations.get(index - 1)); } } if (++done <= 3) { if (iConomyHandler.useiConomy() && iConomyHandler.freeGatesGreen) { Portal dest = Portal.getByName(destination, network); boolean green = Stargate.isFree(activePlayer, this, dest); id.setText(done, (green ? ChatColor.DARK_GREEN : "") + " >" + destination + "< "); } else { id.setText(done, " >" + destination + "< "); } } if ((max >= index + 1) && (++done <= 3)) { if (iConomyHandler.useiConomy() && iConomyHandler.freeGatesGreen) { Portal dest = Portal.getByName(destinations.get(index + 1), network); boolean green = Stargate.isFree(activePlayer, this, dest); id.setText(done, (green ? ChatColor.DARK_GREEN : "") + destinations.get(index + 1)); } else { id.setText(done, destinations.get(index + 1)); } } if ((max >= index + 2) && (++done <= 3)) { if (iConomyHandler.useiConomy() && iConomyHandler.freeGatesGreen) { Portal dest = Portal.getByName(destinations.get(index + 2), network); boolean green = Stargate.isFree(activePlayer, this, dest); id.setText(done, (green ? ChatColor.DARK_GREEN : "") + destinations.get(index + 2)); } else { id.setText(done, destinations.get(index + 2)); } } } } for (done++; done <= 3; done++) { id.setText(done, ""); } id.update(); }