14 Commits

16 changed files with 259 additions and 104 deletions

View File

@ -1,25 +1,14 @@
#AncientGates - Easily create portals with custom design# #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/ 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__ 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: 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)__ __[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## ##FAQ##

View File

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

View File

@ -28,6 +28,8 @@ public class Gate
private transient String id; private transient String id;
private Location from; private Location from;
private Location to; private Location to;
private boolean isHidden = false;
private boolean isOpen = false;
private Integer[][] gateBlocks; private Integer[][] gateBlocks;
@ -56,6 +58,7 @@ public class Gate
public void setFrom(Location from) public void setFrom(Location from)
{ {
this.from = from; this.from = from;
setGateBlocks(FloodUtil.getGateFrameBlocks(from.getBlock()));
} }
@ -82,7 +85,7 @@ public class Gate
} }
public void setGateBlocks(Set<Block> gateBlocks) private void setGateBlocks(Set<Block> gateBlocks)
{ {
if (gateBlocks == null) if (gateBlocks == null)
return; return;
@ -110,12 +113,26 @@ public class Gate
public boolean open() public boolean open()
{ {
Set<Block> blocks = FloodUtil.getGateFrameBlocks(from.getBlock()); Set<Block> blocks = FloodUtil.getGateFrameBlocks(from.getBlock());
setGateBlocks(blocks);
if (blocks == null) if (blocks == null)
{
return false; 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 // 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 // It is to stop portal blocks from destroying themself as they cant rely on non created blocks :P
for (Block block : blocks) for (Block block : blocks)
@ -123,12 +140,17 @@ public class Gate
for (Block block : blocks) for (Block block : blocks)
block.setType(Material.PORTAL); block.setType(Material.PORTAL);
return true;
} }
public void close() public void close()
{
removeGateBlocks();
setOpen(false);
}
private void removeGateBlocks()
{ {
if (from != null) 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 // Persistance and entity management
//----------------------------------------------// //----------------------------------------------//
@ -233,6 +316,28 @@ public class Gate
fillIds(); 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; return true;
} }

View File

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

View File

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

View File

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

View File

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

View File

@ -5,9 +5,11 @@ import java.util.ArrayList;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.mcteam.ancientgates.util.TextUtil; 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("help");
aliases.add("h"); aliases.add("h");
aliases.add("?"); aliases.add("?");
@ -19,7 +21,8 @@ public class CommandHelp extends BaseCommand {
} }
@Override @Override
public boolean hasPermission(CommandSender sender) { public boolean hasPermission(CommandSender sender)
{
return true; return true;
} }
@ -65,17 +68,25 @@ public class CommandHelp extends BaseCommand {
ArrayList<String> pageLines; ArrayList<String> pageLines;
pageLines = new ArrayList<String>(); pageLines = new ArrayList<String>();
pageLines.add( new CommandHelp().getUseageTemplate(true, true) );
pageLines.add( new CommandCreate().getUseageTemplate(true, true) ); pageLines.add( new CommandHelp().getUsageTemplate(true, true) );
pageLines.add( new CommandCreateSetFrom().getUseageTemplate(true, true) ); pageLines.add( new CommandCreate().getUsageTemplate(true, true) );
pageLines.add( new CommandDelete().getUseageTemplate(true, true) ); pageLines.add( new CommandCreateSetFrom().getUsageTemplate(true, true) );
pageLines.add( new CommandSetFrom().getUseageTemplate(true, true) ); pageLines.add( new CommandDelete().getUsageTemplate(true, true) );
pageLines.add( new CommandSetTo().getUseageTemplate(true, true) ); pageLines.add( new CommandSetFrom().getUsageTemplate(true, true) );
pageLines.add( new CommandOpen().getUseageTemplate(true, true) ); pageLines.add( new CommandSetTo().getUsageTemplate(true, true) );
pageLines.add( new CommandRename().getUseageTemplate(true, true) ); pageLines.add( new CommandOpen().getUsageTemplate(true, true) );
pageLines.add( new CommandClose().getUseageTemplate(true, true) );
pageLines.add( new CommandList().getUseageTemplate(true, true) ); helpPages.add(pageLines);
pageLines.add( new CommandInfo().getUseageTemplate(true, true) ); 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); 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 + ":"); 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) 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 else
sendMessage(ChatColor.GREEN + "this gate has no 'from' location"); sendMessage(ChatColor.GREEN + "this gate has no 'from' location");
if (gate.getTo() != null) 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 else
sendMessage(ChatColor.GREEN + "this gate has no 'to' location"); sendMessage(ChatColor.GREEN + "this gate has no 'to' location");

View File

@ -15,13 +15,13 @@ public class CommandOpen extends BaseCommand {
public void perform() { public void perform() {
if (gate.getFrom() == null) { if (gate.getFrom() == null) {
sendMessage("You must set the from location first. To fix that:"); sendMessage("You must set the from location first. To fix that:");
sendMessage(new CommandSetFrom().getUseageTemplate(true, true)); sendMessage(new CommandSetFrom().getUsageTemplate(true, true));
return; return;
} }
if (gate.getTo() == null) { if (gate.getTo() == null) {
sendMessage("Sure, but note that this gate does not point anywhere :P"); 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) { if (gate.getFrom().getBlock().getType() != Material.AIR) {
@ -33,7 +33,7 @@ public class CommandOpen extends BaseCommand {
sendMessage("The gate was opened."); sendMessage("The gate was opened.");
} else { } else {
sendMessage("Failed to open the gate. Have you built a frame?"); 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.Gate;
import org.mcteam.ancientgates.util.FloodUtil; 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("setfrom");
aliases.add("sf"); aliases.add("sf");
@ -20,7 +22,8 @@ public class CommandSetFrom extends BaseCommand {
helpDescription = "Set \"from\" to your location."; helpDescription = "Set \"from\" to your location.";
} }
public void perform() { public void perform()
{
// The player might stand in a halfblock or a sign or whatever // The player might stand in a halfblock or a sign or whatever
// Therefore we load som extra locations and blocks // Therefore we load som extra locations and blocks
Block playerBlock = player.getLocation().getBlock(); Block playerBlock = player.getLocation().getBlock();
@ -33,24 +36,27 @@ public class CommandSetFrom extends BaseCommand {
player.getLocation().getPitch()); player.getLocation().getPitch());
Set<Block> gateBlocks = FloodUtil.getGateFrameBlocks(player.getLocation().getBlock()); Set<Block> gateBlocks = FloodUtil.getGateFrameBlocks(player.getLocation().getBlock());
if (gateBlocks == null) {
if (gateBlocks == null)
{
sendMessage("There is no portal here, or your portal is too large.\nMax size is: " + Conf.getGateMaxArea() + " Blocks."); sendMessage("There is no portal here, or your portal is too large.\nMax size is: " + Conf.getGateMaxArea() + " Blocks.");
return; return;
} }
if (playerBlock.getType() == Material.AIR) { if (playerBlock.getType() == Material.AIR)
{
gate.setFrom(player.getLocation()); gate.setFrom(player.getLocation());
gate.setGateBlocks(gateBlocks); }
} else if (upBlock.getType() == Material.AIR) { else if (upBlock.getType() == Material.AIR)
{
gate.setFrom(playerUpLocation); gate.setFrom(playerUpLocation);
gate.setGateBlocks(gateBlocks); }
} else { else
{
sendMessage("There is not enough room for a gate to open here"); sendMessage("There is not enough room for a gate to open here");
return; return;
} }
sendMessage("From location for gate \""+gate.getId()+"\" is now where you stand."); sendMessage("From location for gate \""+gate.getId()+"\" is now where you stand.");
sendMessage("Your gate includes " + gateBlocks.size() + " Blocks."); sendMessage("Your gate includes " + gateBlocks.size() + " Blocks.");

View File

@ -6,6 +6,7 @@ public class CommandSetTo extends BaseCommand {
public CommandSetTo() { public CommandSetTo() {
aliases.add("setto"); aliases.add("setto");
aliases.add("st");
requiredParameters.add("id"); 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.Chunk;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@ -32,59 +31,43 @@ public class PluginPlayerListener implements Listener
Block blockTo = event.getTo().getBlock(); Block blockTo = event.getTo().getBlock();
Block blockToUp = blockTo.getRelative(BlockFace.UP); 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! // Find the nearest gate!
Gate nearestGate = null; Gate nearestGate = null;
Location playerLocation = event.getPlayer().getLocation(); Location playerLocation = event.getPlayer().getLocation();
//double shortestDistance = -1;
for (Gate gate : Gate.getAll()) 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; 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()); double distance = GeometryUtil.distanceBetweenLocations(playerLocation, gate.getFrom());
if (distance > Conf.getGateSearchRadius()) if (distance > Conf.getGateSearchRadius())
continue; 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()) for (Integer[] blockXYZ: gate.getGateBlocks())
{ {
if ((blockTo.getX() == blockXYZ[0] || blockToUp.getX() == blockXYZ[0]) && if ((blockTo.getX() == blockXYZ[0] || blockToUp.getX() == blockXYZ[0]) &&
(blockTo.getY() == blockXYZ[1] || blockToUp.getY() == blockXYZ[1]) && (blockTo.getY() == blockXYZ[1] || blockToUp.getY() == blockXYZ[1]) &&
(blockTo.getZ() == blockXYZ[2] || blockToUp.getZ() == blockXYZ[2]) (blockTo.getZ() == blockXYZ[2] || blockToUp.getZ() == blockXYZ[2]))
)
{ {
nearestGate = gate; nearestGate = gate;
break; break;
} }
} }
/*if (shortestDistance == -1 || shortestDistance > distance) {
nearestGate = gate;
shortestDistance = distance;
}*/
} }
if (nearestGate != null) if (nearestGate != null)
{ {
checkChunkLoad(nearestGate.getTo().getBlock()); checkChunkLoad(nearestGate.getTo().getBlock());
Float newYaw = nearestGate.getFrom().getYaw() - nearestGate.getTo().getYaw() + playerLocation.getYaw(); Float newYaw = nearestGate.getFrom().getYaw() - nearestGate.getTo().getYaw() + playerLocation.getYaw();
Location teleportToLocation = new Location( nearestGate.getTo().getWorld(), Location teleportToLocation = new Location( nearestGate.getTo().getWorld(),
nearestGate.getTo().getX(), nearestGate.getTo().getX(),
nearestGate.getTo().getY(), nearestGate.getTo().getY(),

View File

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