added hide and unhide feature

This commit is contained in:
Tobias Ottenweller 2012-03-11 20:39:05 +01:00
parent 3fc35e13bc
commit 33c03d68c1
11 changed files with 140 additions and 53 deletions

View File

@ -29,6 +29,7 @@ public class Gate
private Location from;
private Location to;
private boolean isHidden = false;
private boolean isOpen = false;
private Integer[][] gateBlocks;
@ -57,6 +58,7 @@ public class Gate
public void setFrom(Location from)
{
this.from = from;
setGateBlocks(FloodUtil.getGateFrameBlocks(from.getBlock()));
}
@ -83,7 +85,7 @@ public class Gate
}
public void setGateBlocks(Set<Block> gateBlocks)
private void setGateBlocks(Set<Block> gateBlocks)
{
if (gateBlocks == null)
return;
@ -116,6 +118,17 @@ public class Gate
if (blocks == null)
return false;
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,13 +136,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)
{
@ -148,9 +165,20 @@ public class Gate
// isHidden Setter and Getter
//----------------------------------------------//
public void setHidden(boolean isHidden)
public boolean setHidden(boolean isHidden)
{
this.isHidden = isHidden;
if (isHidden == true)
removeGateBlocks();
else if (isOpen() && !open())
{
this.isHidden = false;
return false;
}
return true;
}
@ -160,6 +188,22 @@ public class Gate
}
//----------------------------------------------//
// isOpen Setter and Getter
//----------------------------------------------//
private void setOpen(boolean isOpen)
{
this.isOpen = isOpen;
}
public boolean isOpen()
{
return this.isOpen;
}
//----------------------------------------------//
// Persistance and entity management
//----------------------------------------------//

View File

@ -64,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();

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

@ -65,17 +65,19 @@ 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) );
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

@ -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

@ -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

@ -71,15 +71,8 @@ public class PluginPlayerListener implements Listener
}*/
}
if (nearestGate != null)
{
if (nearestGate.isHidden() == false)
{
// Check if player is standing inside portal blocks
if (blockTo.getType() != Material.PORTAL && blockToUp.getType() != Material.PORTAL)
return;
}
if (nearestGate != null && nearestGate.isOpen())
{
checkChunkLoad(nearestGate.getTo().getBlock());
Float newYaw = nearestGate.getFrom().getYaw() - nearestGate.getTo().getYaw() + playerLocation.getYaw();
Location teleportToLocation = new Location( nearestGate.getTo().getWorld(),