14 Commits

16 changed files with 259 additions and 104 deletions

View File

@ -1,25 +1,14 @@
#AncientGates - Easily create portals with custom design#
Read the full userguide here: TODO
With this plugin the server operators (OPs) can create gates that will teleport anyone who enter to a location specific to that gate. The hightlights are: __It is so darn easy to use!__ :D and __The gates can look any way you like__ \o/
Try the ingame command: __/gate__
Also have a look at the full __[userguide](http://www.craftinc.de/blog/?p=255)__.
Thought first you should take a look at the demonstration oloflarsson and karibu6 created:
__[http://www.youtube.com/watch?v=L4hyqTpeEaA](http://www.youtube.com/watch?v=L4hyqTpeEaA)__
##Commands##
* __/gate help,h,? *[page]__ Display a help page
* __/gate create,new [id]__ Create a gate
* __/gate createsetfrom,newsetfrom,csf,nsf [id]__ Create a gate and set "from"
* __/gate delete,del,remove,rm [id]__ Delete a gate
* __/gate setfrom [id]__ Set "from" to your location.
* __/gate setto [id]__ Set "to" to your location.
* __/gate open [id]__ Open that gate
* __/gate close [id]__ Close that gate
* __/gate list,ls [page]__ Display a list of the gates
* __/gate info,details [id]__ Display information about a gate
##FAQ##

View File

@ -1,7 +1,7 @@
name: AncientGates
version: 1.1
version: 1.1.1
main: org.mcteam.ancientgates.Plugin
commands:
gate:
description: All of the AncientGates commands
usage: See documentation.
usage: See documentation.

View File

@ -28,6 +28,8 @@ public class Gate
private transient String id;
private Location from;
private Location to;
private boolean isHidden = false;
private boolean isOpen = false;
private Integer[][] gateBlocks;
@ -56,6 +58,7 @@ public class Gate
public void setFrom(Location from)
{
this.from = from;
setGateBlocks(FloodUtil.getGateFrameBlocks(from.getBlock()));
}
@ -78,11 +81,11 @@ public class Gate
public Integer[][] getGateBlocks()
{
return gateBlocks;
return gateBlocks;
}
public void setGateBlocks(Set<Block> gateBlocks)
private void setGateBlocks(Set<Block> gateBlocks)
{
if (gateBlocks == null)
return;
@ -110,12 +113,26 @@ public class Gate
public boolean open()
{
Set<Block> blocks = FloodUtil.getGateFrameBlocks(from.getBlock());
setGateBlocks(blocks);
if (blocks == null)
{
return false;
// Uncomment lines below to have the old Portal open functionality back.
}
if (isHidden() == false)
{
fillGate(blocks);
}
setOpen(true);
return true;
}
private void fillGate(Set<Block> blocks)
{
// This is not to do an effect
// It is to stop portal blocks from destroying themself as they cant rely on non created blocks :P
for (Block block : blocks)
@ -123,12 +140,17 @@ public class Gate
for (Block block : blocks)
block.setType(Material.PORTAL);
return true;
}
public void close()
{
removeGateBlocks();
setOpen(false);
}
private void removeGateBlocks()
{
if (from != null)
{
@ -143,6 +165,67 @@ public class Gate
}
//----------------------------------------------//
// isHidden Setter and Getter
//----------------------------------------------//
public boolean setHidden(boolean isHidden)
{
this.isHidden = isHidden;
if (isHidden == true)
{
removeGateBlocks();
}
else if (this.isOpen && !open())
{
// cannot open that gate (no frame!)
this.isHidden = false;
return false;
}
return true;
}
public boolean isHidden()
{
return this.isHidden;
}
//----------------------------------------------//
// isOpen Setter and Getter
//----------------------------------------------//
private void setOpen(boolean isOpen)
{
this.isOpen = isOpen;
}
public boolean isOpen()
{
// check if gate is really open
if (getGateBlocks() == null)
{
isOpen = false;
}
else if (!isHidden())
{
Integer[] gateBlock = getGateBlocks()[0];
Block b = new Location(from.getWorld(), gateBlock[0], gateBlock[1], gateBlock[2]).getBlock();
if (b.getType() != Material.PORTAL)
{
isOpen = false;
}
}
return this.isOpen;
}
//----------------------------------------------//
// Persistance and entity management
//----------------------------------------------//
@ -233,6 +316,28 @@ public class Gate
fillIds();
// old releases did not save gate blocks - this fixes the problem
for (Gate g : getAll())
{
if (g.getGateBlocks() == null && g.getFrom() != null)
{
Plugin.log("Fixing problems with old gate: " + g.getId());
Set<Block> gateBlocks = FloodUtil.getGateFrameBlocks(g.getFrom().getBlock());
if (gateBlocks == null)
continue;
g.setGateBlocks(gateBlocks);
if (((Block) gateBlocks.toArray()[0]).getType() == Material.PORTAL )
g.setOpen(true);
}
}
save();
// end of fix
return true;
}

View File

@ -11,6 +11,7 @@ import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.mcteam.ancientgates.commands.*;
import org.mcteam.ancientgates.gson.Gson;
@ -63,6 +64,8 @@ public class Plugin extends JavaPlugin
commands.add(new CommandClose());
commands.add(new CommandList());
commands.add(new CommandInfo());
commands.add(new CommandHide());
commands.add(new CommandUnhide());
// Ensure basefolder exists!
this.getDataFolder().mkdirs();
@ -72,8 +75,9 @@ public class Plugin extends JavaPlugin
Gate.load();
// Register events
getServer().getPluginManager().registerEvents(this.playerListener, this);
getServer().getPluginManager().registerEvents(this.blockListener, this);
PluginManager pm = this.getServer().getPluginManager();
pm.registerEvents(this.playerListener, this);
pm.registerEvents(this.blockListener, this);
log("Enabled");
}
@ -90,13 +94,15 @@ public class Plugin extends JavaPlugin
// Commands
// -------------------------------------------- //
@SuppressWarnings("unchecked")
public String getBaseCommand() {
if (this.baseCommand != null) {
public String getBaseCommand()
{
if (this.baseCommand != null)
return this.baseCommand;
}
Map<String, Map<String, Object>> Commands = (Map<String, Map<String, Object>>) this.getDescription().getCommands();
Map<String, Map<String, Object>> Commands = this.getDescription().getCommands();
this.baseCommand = Commands.keySet().iterator().next();
return this.baseCommand;
}

View File

@ -119,7 +119,7 @@ public class BaseCommand
// -------------------------------------------- //
// Help and usage description
// -------------------------------------------- //
public String getUseageTemplate(boolean withColor, boolean withDescription) {
public String getUsageTemplate(boolean withColor, boolean withDescription) {
String ret = "";
if (withColor) {
@ -151,7 +151,7 @@ public class BaseCommand
}
public String getUseageTemplate(boolean withColor) {
return getUseageTemplate(withColor, false);
return getUsageTemplate(withColor, false);
}
public String getUseageTemplate() {

View File

@ -24,7 +24,7 @@ public class CommandCreate extends BaseCommand {
Gate.create(id);
sendMessage("Gate with id \"" + id + "\" was created. Now you should:");
sendMessage(new CommandSetFrom().getUseageTemplate(true, true));
sendMessage(new CommandSetFrom().getUsageTemplate(true, true));
Gate.save();
}

View File

@ -63,12 +63,10 @@ public class CommandCreateSetFrom extends BaseCommand
if (playerBlock.getType() == Material.AIR)
{
gate.setFrom(player.getLocation());
gate.setGateBlocks(gateBlocks);
}
else if (upBlock.getType() == Material.AIR)
{
gate.setFrom(playerUpLocation);
gate.setGateBlocks(gateBlocks);
}
else
{

View File

@ -5,9 +5,11 @@ import java.util.ArrayList;
import org.bukkit.command.CommandSender;
import org.mcteam.ancientgates.util.TextUtil;
public class CommandHelp extends BaseCommand {
public class CommandHelp extends BaseCommand
{
public CommandHelp() {
public CommandHelp()
{
aliases.add("help");
aliases.add("h");
aliases.add("?");
@ -19,7 +21,8 @@ public class CommandHelp extends BaseCommand {
}
@Override
public boolean hasPermission(CommandSender sender) {
public boolean hasPermission(CommandSender sender)
{
return true;
}
@ -65,17 +68,25 @@ public class CommandHelp extends BaseCommand {
ArrayList<String> pageLines;
pageLines = new ArrayList<String>();
pageLines.add( new CommandHelp().getUseageTemplate(true, true) );
pageLines.add( new CommandCreate().getUseageTemplate(true, true) );
pageLines.add( new CommandCreateSetFrom().getUseageTemplate(true, true) );
pageLines.add( new CommandDelete().getUseageTemplate(true, true) );
pageLines.add( new CommandSetFrom().getUseageTemplate(true, true) );
pageLines.add( new CommandSetTo().getUseageTemplate(true, true) );
pageLines.add( new CommandOpen().getUseageTemplate(true, true) );
pageLines.add( new CommandRename().getUseageTemplate(true, true) );
pageLines.add( new CommandClose().getUseageTemplate(true, true) );
pageLines.add( new CommandList().getUseageTemplate(true, true) );
pageLines.add( new CommandInfo().getUseageTemplate(true, true) );
pageLines.add( new CommandHelp().getUsageTemplate(true, true) );
pageLines.add( new CommandCreate().getUsageTemplate(true, true) );
pageLines.add( new CommandCreateSetFrom().getUsageTemplate(true, true) );
pageLines.add( new CommandDelete().getUsageTemplate(true, true) );
pageLines.add( new CommandSetFrom().getUsageTemplate(true, true) );
pageLines.add( new CommandSetTo().getUsageTemplate(true, true) );
pageLines.add( new CommandOpen().getUsageTemplate(true, true) );
helpPages.add(pageLines);
pageLines = new ArrayList<String>();
pageLines.add( new CommandRename().getUsageTemplate(true, true) );
pageLines.add( new CommandClose().getUsageTemplate(true, true) );
pageLines.add( new CommandList().getUsageTemplate(true, true) );
pageLines.add( new CommandInfo().getUsageTemplate(true, true) );
pageLines.add( new CommandHide().getUsageTemplate(true, true) );
pageLines.add( new CommandUnhide().getUsageTemplate(true, true) );
helpPages.add(pageLines);
}

View File

@ -0,0 +1,20 @@
package org.mcteam.ancientgates.commands;
public class CommandHide extends BaseCommand
{
public CommandHide()
{
aliases.add("hide");
requiredParameters.add("id");
helpDescription = "Hide that gate";
}
public void perform()
{
gate.setHidden(true);
sendMessage("The gate " + gate.getId() + " is now hidden.");
}
}

View File

@ -20,13 +20,27 @@ public class CommandInfo extends BaseCommand
{
sendMessage(ChatColor.LIGHT_PURPLE + "Information about " + ChatColor.WHITE + gate.getId() + ChatColor.LIGHT_PURPLE + ":");
String openHiddenMessage = "This gate is";
if (gate.isOpen())
openHiddenMessage += " open";
else
openHiddenMessage += " closed";
if (gate.isHidden())
openHiddenMessage += " and hidden";
openHiddenMessage += ".";
sendMessage(openHiddenMessage);
if (gate.getFrom() != null)
sendMessage(ChatColor.GREEN + "'from' location: " + ChatColor.YELLOW + "( " + gate.getFrom().getBlockX() + " | " + gate.getFrom().getBlockY() + " | " + gate.getFrom().getBlockZ() + " )");
sendMessage(ChatColor.GREEN + "'from' location: " + ChatColor.YELLOW + "( " + gate.getFrom().getBlockX() + " | " + gate.getFrom().getBlockY() + " | " + gate.getFrom().getBlockZ() + " ) in " + gate.getFrom().getWorld().getName());
else
sendMessage(ChatColor.GREEN + "this gate has no 'from' location");
if (gate.getTo() != null)
sendMessage(ChatColor.GREEN + "'to' location: " + ChatColor.YELLOW + "( " + gate.getTo().getBlockX() + " | " + gate.getTo().getBlockY() + " | " + gate.getTo().getBlockZ() + " )");
sendMessage(ChatColor.GREEN + "'to' location: " + ChatColor.YELLOW + "( " + gate.getTo().getBlockX() + " | " + gate.getTo().getBlockY() + " | " + gate.getTo().getBlockZ() + " ) in " + gate.getTo().getWorld().getName());
else
sendMessage(ChatColor.GREEN + "this gate has no 'to' location");

View File

@ -15,13 +15,13 @@ public class CommandOpen extends BaseCommand {
public void perform() {
if (gate.getFrom() == null) {
sendMessage("You must set the from location first. To fix that:");
sendMessage(new CommandSetFrom().getUseageTemplate(true, true));
sendMessage(new CommandSetFrom().getUsageTemplate(true, true));
return;
}
if (gate.getTo() == null) {
sendMessage("Sure, but note that this gate does not point anywhere :P");
sendMessage("To fix that: " + new CommandSetTo().getUseageTemplate(true, true));
sendMessage("To fix that: " + new CommandSetTo().getUsageTemplate(true, true));
}
if (gate.getFrom().getBlock().getType() != Material.AIR) {
@ -33,7 +33,7 @@ public class CommandOpen extends BaseCommand {
sendMessage("The gate was opened.");
} else {
sendMessage("Failed to open the gate. Have you built a frame?");
sendMessage("More info here: " + new CommandHelp().getUseageTemplate(true, true));
sendMessage("More info here: " + new CommandHelp().getUsageTemplate(true, true));
}
}
}

View File

@ -9,9 +9,11 @@ import org.mcteam.ancientgates.Conf;
import org.mcteam.ancientgates.Gate;
import org.mcteam.ancientgates.util.FloodUtil;
public class CommandSetFrom extends BaseCommand {
public class CommandSetFrom extends BaseCommand
{
public CommandSetFrom() {
public CommandSetFrom()
{
aliases.add("setfrom");
aliases.add("sf");
@ -20,37 +22,41 @@ public class CommandSetFrom extends BaseCommand {
helpDescription = "Set \"from\" to your location.";
}
public void perform() {
public void perform()
{
// The player might stand in a halfblock or a sign or whatever
// Therefore we load som extra locations and blocks
Block playerBlock = player.getLocation().getBlock();
Block upBlock = playerBlock.getRelative(BlockFace.UP);
Location playerUpLocation = new Location(player.getLocation().getWorld(),
player.getLocation().getX(),
player.getLocation().getY() + 1,
player.getLocation().getZ(),
player.getLocation().getYaw(),
player.getLocation().getPitch());
player.getLocation().getX(),
player.getLocation().getY() + 1,
player.getLocation().getZ(),
player.getLocation().getYaw(),
player.getLocation().getPitch());
Set<Block> gateBlocks = FloodUtil.getGateFrameBlocks(player.getLocation().getBlock());
if (gateBlocks == null) {
sendMessage("There is no portal here, or your portal is too large.\nMax size is: " + Conf.getGateMaxArea() + " Blocks.");
return;
}
Set<Block> gateBlocks = FloodUtil.getGateFrameBlocks(player.getLocation().getBlock());
if (gateBlocks == null)
{
sendMessage("There is no portal here, or your portal is too large.\nMax size is: " + Conf.getGateMaxArea() + " Blocks.");
return;
}
if (playerBlock.getType() == Material.AIR) {
if (playerBlock.getType() == Material.AIR)
{
gate.setFrom(player.getLocation());
gate.setGateBlocks(gateBlocks);
} else if (upBlock.getType() == Material.AIR) {
}
else if (upBlock.getType() == Material.AIR)
{
gate.setFrom(playerUpLocation);
gate.setGateBlocks(gateBlocks);
} else {
}
else
{
sendMessage("There is not enough room for a gate to open here");
return;
}
sendMessage("From location for gate \""+gate.getId()+"\" is now where you stand.");
sendMessage("Your gate includes " + gateBlocks.size() + " Blocks.");

View File

@ -6,6 +6,7 @@ public class CommandSetTo extends BaseCommand {
public CommandSetTo() {
aliases.add("setto");
aliases.add("st");
requiredParameters.add("id");

View File

@ -0,0 +1,22 @@
package org.mcteam.ancientgates.commands;
public class CommandUnhide extends BaseCommand
{
public CommandUnhide()
{
aliases.add("unhide");
requiredParameters.add("id");
helpDescription = "Unhide that gate";
}
public void perform()
{
if (gate.setHidden(false))
sendMessage("The gate " + gate.getId() + " is no longer hidden.");
else
sendMessage("Failed to unhide the gate. Does the portal have a frame?");
}
}

View File

@ -4,7 +4,6 @@ import java.util.logging.Level;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
@ -32,59 +31,43 @@ public class PluginPlayerListener implements Listener
Block blockTo = event.getTo().getBlock();
Block blockToUp = blockTo.getRelative(BlockFace.UP);
// Check if player is standing inside a portal
if (blockTo.getType() != Material.PORTAL && blockToUp.getType() != Material.PORTAL)
return;
// Ok so a player walks into a portal block
// Find the nearest gate!
Gate nearestGate = null;
Location playerLocation = event.getPlayer().getLocation();
//double shortestDistance = -1;
for (Gate gate : Gate.getAll())
{
if ( gate.getFrom() == null || gate.getTo() == null)
if (gate.getFrom() == null ||
gate.getTo() == null ||
gate.isOpen() == false ||
!gate.getFrom().getWorld().equals(playerLocation.getWorld()))
{
continue;
if ( ! gate.getFrom().getWorld().equals(playerLocation.getWorld()))
continue; // We can only be close to gates in the same world
}
double distance = GeometryUtil.distanceBetweenLocations(playerLocation, gate.getFrom());
if (distance > Conf.getGateSearchRadius())
continue;
Plugin.log(Level.ALL, "in gate search radius of " + gate.getId());
Plugin.log(Level.ALL, "in gate search radius.");
for (Integer[] blockXYZ: gate.getGateBlocks())
{
if ( (blockTo.getX() == blockXYZ[0] || blockToUp.getX() == blockXYZ[0]) &&
(blockTo.getY() == blockXYZ[1] || blockToUp.getY() == blockXYZ[1]) &&
(blockTo.getZ() == blockXYZ[2] || blockToUp.getZ() == blockXYZ[2])
)
if ((blockTo.getX() == blockXYZ[0] || blockToUp.getX() == blockXYZ[0]) &&
(blockTo.getY() == blockXYZ[1] || blockToUp.getY() == blockXYZ[1]) &&
(blockTo.getZ() == blockXYZ[2] || blockToUp.getZ() == blockXYZ[2]))
{
nearestGate = gate;
break;
}
}
}
/*if (shortestDistance == -1 || shortestDistance > distance) {
nearestGate = gate;
shortestDistance = distance;
}*/
}
}
if (nearestGate != null)
{
checkChunkLoad(nearestGate.getTo().getBlock());
Float newYaw = nearestGate.getFrom().getYaw() - nearestGate.getTo().getYaw() + playerLocation.getYaw();
Location teleportToLocation = new Location( nearestGate.getTo().getWorld(),
nearestGate.getTo().getX(),
nearestGate.getTo().getY(),

View File

@ -1,5 +1,5 @@
name: AncientGates
version: 1.0.1
version: 1.1.1
main: org.mcteam.ancientgates.Plugin
commands:
gate: