added hide and unhide feature
This commit is contained in:
parent
3fc35e13bc
commit
33c03d68c1
@ -29,6 +29,7 @@ public class Gate
|
|||||||
private Location from;
|
private Location from;
|
||||||
private Location to;
|
private Location to;
|
||||||
private boolean isHidden = false;
|
private boolean isHidden = false;
|
||||||
|
private boolean isOpen = false;
|
||||||
|
|
||||||
private Integer[][] gateBlocks;
|
private Integer[][] gateBlocks;
|
||||||
|
|
||||||
@ -57,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()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -83,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;
|
||||||
@ -116,6 +118,17 @@ public class Gate
|
|||||||
if (blocks == null)
|
if (blocks == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
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,13 +136,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)
|
||||||
{
|
{
|
||||||
@ -148,9 +165,20 @@ public class Gate
|
|||||||
// isHidden Setter and Getter
|
// isHidden Setter and Getter
|
||||||
//----------------------------------------------//
|
//----------------------------------------------//
|
||||||
|
|
||||||
public void setHidden(boolean isHidden)
|
public boolean setHidden(boolean isHidden)
|
||||||
{
|
{
|
||||||
this.isHidden = 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
|
// Persistance and entity management
|
||||||
//----------------------------------------------//
|
//----------------------------------------------//
|
||||||
|
@ -64,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();
|
||||||
|
@ -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() {
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
{
|
{
|
||||||
|
@ -65,17 +65,19 @@ 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 CommandHelp().getUsageTemplate(true, true) );
|
||||||
pageLines.add( new CommandCreate().getUseageTemplate(true, true) );
|
pageLines.add( new CommandCreate().getUsageTemplate(true, true) );
|
||||||
pageLines.add( new CommandCreateSetFrom().getUseageTemplate(true, true) );
|
pageLines.add( new CommandCreateSetFrom().getUsageTemplate(true, true) );
|
||||||
pageLines.add( new CommandDelete().getUseageTemplate(true, true) );
|
pageLines.add( new CommandDelete().getUsageTemplate(true, true) );
|
||||||
pageLines.add( new CommandSetFrom().getUseageTemplate(true, true) );
|
pageLines.add( new CommandSetFrom().getUsageTemplate(true, true) );
|
||||||
pageLines.add( new CommandSetTo().getUseageTemplate(true, true) );
|
pageLines.add( new CommandSetTo().getUsageTemplate(true, true) );
|
||||||
pageLines.add( new CommandOpen().getUseageTemplate(true, true) );
|
pageLines.add( new CommandOpen().getUsageTemplate(true, true) );
|
||||||
pageLines.add( new CommandRename().getUseageTemplate(true, true) );
|
pageLines.add( new CommandRename().getUsageTemplate(true, true) );
|
||||||
pageLines.add( new CommandClose().getUseageTemplate(true, true) );
|
pageLines.add( new CommandClose().getUsageTemplate(true, true) );
|
||||||
pageLines.add( new CommandList().getUseageTemplate(true, true) );
|
pageLines.add( new CommandList().getUsageTemplate(true, true) );
|
||||||
pageLines.add( new CommandInfo().getUseageTemplate(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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
20
src/org/mcteam/ancientgates/commands/CommandHide.java
Normal file
20
src/org/mcteam/ancientgates/commands/CommandHide.java
Normal 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.");
|
||||||
|
}
|
||||||
|
}
|
@ -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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.");
|
||||||
|
|
||||||
|
22
src/org/mcteam/ancientgates/commands/CommandUnhide.java
Normal file
22
src/org/mcteam/ancientgates/commands/CommandUnhide.java
Normal 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?");
|
||||||
|
}
|
||||||
|
}
|
@ -71,15 +71,8 @@ public class PluginPlayerListener implements Listener
|
|||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nearestGate != null)
|
if (nearestGate != null && nearestGate.isOpen())
|
||||||
{
|
{
|
||||||
if (nearestGate.isHidden() == false)
|
|
||||||
{
|
|
||||||
// Check if player is standing inside portal blocks
|
|
||||||
if (blockTo.getType() != Material.PORTAL && blockToUp.getType() != Material.PORTAL)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
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(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user