Gates can now consist of any material.

You can left or right click the button to open a gate
Gates are now initialized on sign placement, not more right clicking!
This commit is contained in:
Drakia 2011-02-13 00:04:49 -08:00
parent 13dbf6e8f1
commit 916b6df55d
5 changed files with 88 additions and 50 deletions

24
README
View File

@ -13,7 +13,6 @@ Known Issues
============= =============
- Vehicle implementation is nowhere near done. - Vehicle implementation is nowhere near done.
- Signs aren't always updating, I don't know what's causing this, I think it's a Bukkit thing. - Signs aren't always updating, I don't know what's causing this, I think it's a Bukkit thing.
- You need to right-click the sign to initialize the gate, waiting on SIGN_CHANGE hook update.
============= =============
Permissions Permissions
@ -36,17 +35,16 @@ Building a gate:
- Type a set destination name on the second line if desired. - Type a set destination name on the second line if desired.
- Type a network name on the third line if desired. - Type a network name on the third line if desired.
- Type any options on the 4th line if desired. - Type any options on the 4th line if desired.
- Right click the sign block to initialize the gate as a Stargate. (Bug Alert: Sign may not update right away)
Sign Layout: Sign Layout:
- Line 1: Gate Name (Max 12 characters) - Line 1: Gate Name (Max 12 characters)
- Line 2: Destination Name (Max 12 characters, used for fixed-gates only) - Line 2: Destination Name [Optional] (Max 12 characters, used for fixed-gates only)
- Line 3: Network name (Max 12 characters) - Line 3: Network name [Optional] (Max 12 characters)
- Line 4: Options ('A' for always-on fixed gate, 'H' for hidden networked gate) - Line 4: Options [Optional] ('A' for always-on fixed gate, 'H' for hidden networked gate)
Using a gate: Using a gate:
- Right click the sign to choose a destination. - Right click the sign to choose a destination.
- Right click the button to open up a portal. - Right/left click the button to open up a portal.
- Step through. - Step through.
Fixed gates: Fixed gates:
@ -68,11 +66,23 @@ Hidden Gates:
============== ==============
Configuration Configuration
============== ==============
- To change the text shown during events edit stargates.txt default-gate-network - The default gate network
not-selected-message - The message when no destination is selected
portal-destroy-message - The message when a gate is destroyed
portal-create-message - The message when a gate is created
not-owner-message - The message when you aren't allowed to push the gate button
other-side-blocked-message - The message when the gate you're dialing is open
teleport-message - The message when you are teleported
portal-save-location - The file your portal database is saved as
gate-folder - The folder containing your .gate files
============= =============
Changes Changes
============= =============
[Version 0.08]
- Gates can now consist of any material.
- You can left or right click the button to open a gate
- Gates are now initialized on sign placement, not more right clicking!
[Version 0.07] [Version 0.07]
- Fixed where the default gate is saved to. - Fixed where the default gate is saved to.
[Version 0.06] [Version 0.06]

View File

@ -93,6 +93,8 @@ public class Blox {
public String toString() { public String toString() {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
//builder.append(world.getName());
//builder.append(',');
builder.append(x); builder.append(x);
builder.append(','); builder.append(',');
builder.append(y); builder.append(y);

View File

@ -217,7 +217,7 @@ public class Portal {
public void teleport(Vehicle vehicle, Portal origin) { public void teleport(Vehicle vehicle, Portal origin) {
Location traveller = new Location(this.world, vehicle.getLocation().getX(), vehicle.getLocation().getY(), vehicle.getLocation().getZ()); Location traveller = new Location(this.world, vehicle.getLocation().getX(), vehicle.getLocation().getY(), vehicle.getLocation().getZ());
Location exit = getExit(traveller, origin); Location exit = getExit(traveller, origin);
double velocity = vehicle.getVelocity().length(); double velocity = vehicle.getVelocity().length();
// Stop and teleport // Stop and teleport
@ -311,7 +311,7 @@ public class Portal {
} }
public boolean isVerified() { public boolean isVerified() {
verified = verified || getBlockAt(1, 0).getType() == OBSIDIAN; verified = verified || getBlockAt(1, 0).getBlock().getTypeId() == gate.getControlBlock();
return verified; return verified;
} }
@ -584,7 +584,7 @@ public class Portal {
public static Portal createPortal(SignPost id, Player player) { public static Portal createPortal(SignPost id, Player player) {
Block idParent = id.getParent(); Block idParent = id.getParent();
if (idParent.getType() != Material.OBSIDIAN) return null; if (Gate.getGatesByControlBlock(idParent).length == 0) return null;
Blox parent = new Blox(player.getWorld(), idParent.getX(), idParent.getY(), idParent.getZ()); Blox parent = new Blox(player.getWorld(), idParent.getX(), idParent.getY(), idParent.getZ());
Blox topleft = null; Blox topleft = null;

View File

@ -20,6 +20,7 @@ import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.BlockRightClickEvent; import org.bukkit.event.block.BlockRightClickEvent;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.player.PlayerListener; import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.vehicle.VehicleListener; import org.bukkit.event.vehicle.VehicleListener;
@ -102,14 +103,14 @@ public class Stargate extends JavaPlugin implements Runnable {
pm.registerEvent(Event.Type.BLOCK_PLACED, blockListener, Priority.Normal, this); pm.registerEvent(Event.Type.BLOCK_PLACED, blockListener, Priority.Normal, this);
pm.registerEvent(Event.Type.BLOCK_DAMAGED, blockListener, Priority.Normal, this); pm.registerEvent(Event.Type.BLOCK_DAMAGED, blockListener, Priority.Normal, this);
pm.registerEvent(Event.Type.VEHICLE_MOVE, vehicleListener, Priority.Normal, this); pm.registerEvent(Event.Type.VEHICLE_MOVE, vehicleListener, Priority.Normal, this);
//pm.registerEvent(Event.Type.SIGN_CHANGE, blockListener, Priority.Normal, this); pm.registerEvent(Event.Type.SIGN_CHANGE, blockListener, Priority.Normal, this);
setInterval(160); // 8 seconds. setInterval(160); // 8 seconds.
clock.start(); clock.start();
} }
public void reloadConfig() { public void reloadConfig() {
config.load(); config.load();
portalFile = config.getString("portal-save-location", portalFile); portalFile = config.getString("portal-save-location", portalFile);
gateFolder = config.getString("gate-folder", gateFolder); gateFolder = config.getString("gate-folder", gateFolder);
@ -122,7 +123,7 @@ public class Stargate extends JavaPlugin implements Runnable {
defNetwork = config.getString("default-gate-network", defNetwork).trim(); defNetwork = config.getString("default-gate-network", defNetwork).trim();
saveConfig(); saveConfig();
} }
public void saveConfig() { public void saveConfig() {
config.setProperty("portal-save-location", portalFile); config.setProperty("portal-save-location", portalFile);
config.setProperty("gate-folder", gateFolder); config.setProperty("gate-folder", gateFolder);
@ -135,7 +136,7 @@ public class Stargate extends JavaPlugin implements Runnable {
config.setProperty("default-gate-network", defNetwork); config.setProperty("default-gate-network", defNetwork);
config.save(); config.save();
} }
public void reloadGates() { public void reloadGates() {
Gate.loadGates(gateFolder); Gate.loadGates(gateFolder);
Portal.loadAllGates(this.getServer().getWorlds().get(0)); Portal.loadAllGates(this.getServer().getWorlds().get(0));
@ -159,7 +160,7 @@ public class Stargate extends JavaPlugin implements Runnable {
file.renameTo(new File(gateFolder + file.getName())); file.renameTo(new File(gateFolder + file.getName()));
} }
} }
} }
public synchronized void doWork() { public synchronized void doWork() {
Portal open = Portal.getNextOpen(); Portal open = Portal.getNextOpen();
@ -219,12 +220,12 @@ public class Stargate extends JavaPlugin implements Runnable {
public void setupPermissions() { public void setupPermissions() {
Plugin perm = pm.getPlugin("Permissions"); Plugin perm = pm.getPlugin("Permissions");
if(perm != null) { if(perm != null) {
Stargate.Permissions = ((Permissions)perm).getHandler(); Stargate.Permissions = ((Permissions)perm).getHandler();
} else { } else {
log.info("[" + this.getDescription().getName() + "] Permission system not enabled. Disabling plugin."); log.info("[" + this.getDescription().getName() + "] Permission system not enabled. Disabling plugin.");
pm.disablePlugin(this); pm.disablePlugin(this);
} }
} }
private class vListener extends VehicleListener { private class vListener extends VehicleListener {
@ -236,24 +237,24 @@ public class Stargate extends JavaPlugin implements Runnable {
Portal portal = Portal.getByEntrance(event.getTo()); Portal portal = Portal.getByEntrance(event.getTo());
if (portal != null && portal.isOpen()) { if (portal != null && portal.isOpen()) {
if (passenger instanceof Player) { if (passenger instanceof Player) {
Player player = (Player)event.getVehicle().getPassenger(); Player player = (Player)event.getVehicle().getPassenger();
if (!portal.isOpenFor(player)) { if (!portal.isOpenFor(player)) {
player.sendMessage(ChatColor.RED + denyMsg); player.sendMessage(ChatColor.RED + denyMsg);
return; return;
} }
Portal dest = portal.getDestination(); Portal dest = portal.getDestination();
if (dest == null) return; if (dest == null) return;
dest.teleport(vehicle, portal); dest.teleport(vehicle, portal);
if (!teleMsg.isEmpty()) if (!teleMsg.isEmpty())
player.sendMessage(ChatColor.BLUE + teleMsg); player.sendMessage(ChatColor.BLUE + teleMsg);
portal.close(false); portal.close(false);
} else { } else {
} }
} }
}
} }
}
private class pListener extends PlayerListener { private class pListener extends PlayerListener {
@Override @Override
@ -293,6 +294,34 @@ public class Stargate extends JavaPlugin implements Runnable {
if (portal != null) event.setCancelled(true); if (portal != null) event.setCancelled(true);
} }
} }
@Override
public void onSignChange(SignChangeEvent event) {
Player player = event.getPlayer();
Block block = event.getBlock();
// Initialize a stargate
if (Stargate.Permissions.has(player, "stargate.create")) {
SignPost sign = new SignPost(new Blox(block));
// Set sign text so we can create a gate with it.
sign.setText(0, event.getLine(0));
sign.setText(1, event.getLine(1));
sign.setText(2, event.getLine(2));
sign.setText(3, event.getLine(3));
Portal portal = Portal.createPortal(sign, player);
if (portal == null) return;
if (!regMsg.isEmpty()) {
player.sendMessage(ChatColor.GREEN + regMsg);
}
log.info("Initialized stargate: " + portal.getName());
portal.drawSign(true);
// Set event text so our new sign is instantly initialized
event.setLine(0, sign.getText(0));
event.setLine(1, sign.getText(1));
event.setLine(2, sign.getText(2));
event.setLine(3, sign.getText(3));
}
}
@Override @Override
public void onBlockRightClick(BlockRightClickEvent event) { public void onBlockRightClick(BlockRightClickEvent event) {
@ -308,21 +337,7 @@ public class Stargate extends JavaPlugin implements Runnable {
} }
} }
} }
}
// Check if the player is initializing a stargate
if (portal == null && Stargate.Permissions.has(player, "stargate.create")) {
SignPost sign = new SignPost(new Blox(block));
portal = Portal.createPortal(sign, player);
if (portal != null && !regMsg.isEmpty()) {
player.sendMessage(ChatColor.GREEN + regMsg);
}
if (portal == null) return;
log.info("Initialized stargate: " + portal.getName());
portal.drawSign(true);
}
}
// Implement right-click to toggle a stargate, gets around spawn protection problem. // Implement right-click to toggle a stargate, gets around spawn protection problem.
if ((block.getType() == Material.STONE_BUTTON)) { if ((block.getType() == Material.STONE_BUTTON)) {
@ -339,7 +354,20 @@ public class Stargate extends JavaPlugin implements Runnable {
public void onBlockDamage(BlockDamageEvent event) { public void onBlockDamage(BlockDamageEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
Block block = event.getBlock(); Block block = event.getBlock();
if (block.getType() != Material.WALL_SIGN && block.getType() != Material.OBSIDIAN && block.getType() != Material.STONE_BUTTON) { // Check if we're pushing a button.
if (block.getType() == Material.STONE_BUTTON && event.getDamageLevel() == BlockDamageLevel.STOPPED) {
if (Stargate.Permissions.has(player, "stargate.use")) {
Portal portal = Portal.getByBlock(block);
if (portal != null) {
onButtonPressed(player, portal);
}
}
}
// Drop out if we're not breaking a block
if (event.getDamageLevel() != BlockDamageLevel.BROKEN) return;
if (block.getType() != Material.WALL_SIGN && block.getType() != Material.STONE_BUTTON && Gate.getGatesByControlBlock(block).length == 0) {
return; return;
} }
@ -351,11 +379,9 @@ public class Stargate extends JavaPlugin implements Runnable {
return; return;
} }
if (event.getDamageLevel() == BlockDamageLevel.BROKEN) { portal.unregister();
portal.unregister(); if (!dmgMsg.isEmpty()) {
if (!dmgMsg.isEmpty()) { player.sendMessage(ChatColor.RED + dmgMsg);
player.sendMessage(ChatColor.RED + dmgMsg);
}
} }
} }

View File

@ -1,6 +1,6 @@
name: Stargate name: Stargate
main: net.TheDgtl.Stargate.Stargate main: net.TheDgtl.Stargate.Stargate
version: 0.07 version: 0.08
description: Stargate mod for Bukkit description: Stargate mod for Bukkit
author: Drakia author: Drakia
website: http://www.thedgtl.net website: http://www.thedgtl.net