From ccc9a27917624c8f33a0ecc116a95280ddc7a6c3 Mon Sep 17 00:00:00 2001 From: Tobias Ottenweller Date: Sat, 25 Feb 2012 17:46:19 +0100 Subject: [PATCH] kept players yaw and pitch while walking through a gate; saving of actual gate size (preventing resizing of gates after creation); all credit goes to s1m0ne --- src/org/mcteam/ancientgates/Conf.java | 4 +-- src/org/mcteam/ancientgates/Gate.java | 34 +++++++++++++++++-- .../ancientgates/MyLocationTypeAdapter.java | 10 +++--- .../ancientgates/commands/CommandSetFrom.java | 33 ++++++++++++++---- .../mcteam/ancientgates/util/FloodUtil.java | 12 ++++--- src/plugin.yml | 7 ++++ 6 files changed, 81 insertions(+), 19 deletions(-) create mode 100644 src/plugin.yml diff --git a/src/org/mcteam/ancientgates/Conf.java b/src/org/mcteam/ancientgates/Conf.java index b64edc3..a708cdf 100644 --- a/src/org/mcteam/ancientgates/Conf.java +++ b/src/org/mcteam/ancientgates/Conf.java @@ -21,7 +21,7 @@ public class Conf { public static ChatColor colorCommand = ChatColor.AQUA; public static ChatColor colorParameter = ChatColor.DARK_AQUA; - private static double gateSearchRadius = 7.0; + private static double gateSearchRadius = 10.0; static { @@ -32,7 +32,7 @@ public class Conf { } public static int getGateMaxArea() { - return (int)gateSearchRadius*10; + return (int)gateSearchRadius * 7; } // -------------------------------------------- // diff --git a/src/org/mcteam/ancientgates/Gate.java b/src/org/mcteam/ancientgates/Gate.java index 0093390..8c803ae 100644 --- a/src/org/mcteam/ancientgates/Gate.java +++ b/src/org/mcteam/ancientgates/Gate.java @@ -2,7 +2,9 @@ package org.mcteam.ancientgates; import java.io.File; import java.io.IOException; + import java.lang.reflect.Type; + import java.util.Collection; import java.util.Map.Entry; import java.util.Map; @@ -12,7 +14,9 @@ import java.util.TreeMap; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; + import org.mcteam.ancientgates.gson.reflect.TypeToken; + import org.mcteam.ancientgates.util.DiscUtil; import org.mcteam.ancientgates.util.FloodUtil; @@ -24,7 +28,9 @@ public class Gate { private transient String id; private Location from; private Location to; - + + private Integer[][] gateBlocks; + public Gate() { } @@ -56,6 +62,27 @@ public class Gate { public Location getTo() { return to; } + + public Integer[][] getGateBlocks() { + return gateBlocks; + } + + public void setGateBlocks(Set gateBlocks) { + if (gateBlocks == null) + return; + + this.gateBlocks = new Integer[gateBlocks.size()][3]; + + int blockcount = 0; + for (Block b: gateBlocks) { + if (b != null) { + this.gateBlocks[blockcount][0] = b.getX(); + this.gateBlocks[blockcount][1] = b.getY(); + this.gateBlocks[blockcount][2] = b.getZ(); + } + blockcount++; + } + } //----------------------------------------------// // The Open And Close Methods @@ -68,6 +95,8 @@ public class Gate { return false; } + // Uncomment lines below to have the old Portal open functionality back. + // This is not to do an effect // It is to stop portalblocks from destroyingthemself as they cant rely on non created blocks :P for (Block block : blocks) { @@ -83,7 +112,8 @@ public class Gate { public void close() { Set blocks = FloodUtil.getGateFrameBlocks(from.getBlock()); - + + // Uncomment lines below to have the old Portal open functionality back. for (Block block : blocks) { block.setType(Material.AIR); } diff --git a/src/org/mcteam/ancientgates/MyLocationTypeAdapter.java b/src/org/mcteam/ancientgates/MyLocationTypeAdapter.java index 84f7322..e8ba0b4 100644 --- a/src/org/mcteam/ancientgates/MyLocationTypeAdapter.java +++ b/src/org/mcteam/ancientgates/MyLocationTypeAdapter.java @@ -4,7 +4,8 @@ import java.lang.reflect.Type; import org.bukkit.Location; import org.bukkit.World; -import org.bukkit.World.Environment; +import org.bukkit.WorldCreator; + import org.mcteam.ancientgates.gson.JsonDeserializationContext; import org.mcteam.ancientgates.gson.JsonDeserializer; import org.mcteam.ancientgates.gson.JsonElement; @@ -62,9 +63,10 @@ public class MyLocationTypeAdapter implements JsonDeserializer, JsonSe private World getWorld(String name) { World world = Plugin.instance.getServer().getWorld(name); - if (world == null) { - world = Plugin.instance.getServer().createWorld(name, Environment.NORMAL); - } + + if (world == null) + world = Plugin.instance.getServer().createWorld(new WorldCreator(name)); + return world; } } diff --git a/src/org/mcteam/ancientgates/commands/CommandSetFrom.java b/src/org/mcteam/ancientgates/commands/CommandSetFrom.java index 16b8877..d71830e 100644 --- a/src/org/mcteam/ancientgates/commands/CommandSetFrom.java +++ b/src/org/mcteam/ancientgates/commands/CommandSetFrom.java @@ -1,9 +1,13 @@ package org.mcteam.ancientgates.commands; +import java.util.Set; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.mcteam.ancientgates.Conf; import org.mcteam.ancientgates.Gate; +import org.mcteam.ancientgates.util.FloodUtil; public class CommandSetFrom extends BaseCommand { @@ -19,21 +23,36 @@ public class CommandSetFrom extends BaseCommand { // 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.getFace(BlockFace.UP); - + 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()); + + Set 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) { - gate.setFrom(playerBlock.getLocation()); + gate.setFrom(player.getLocation()); + gate.setGateBlocks(gateBlocks); } else if (upBlock.getType() == Material.AIR) { - gate.setFrom(upBlock.getLocation()); + gate.setFrom(playerUpLocation); + gate.setGateBlocks(gateBlocks); } 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("Build a frame around that block and:"); - sendMessage(new CommandOpen().getUseageTemplate(true, true)); - + sendMessage("Your gate includes " + gateBlocks.size() + " Blocks."); + Gate.save(); } diff --git a/src/org/mcteam/ancientgates/util/FloodUtil.java b/src/org/mcteam/ancientgates/util/FloodUtil.java index 0575c8b..3e83e54 100644 --- a/src/org/mcteam/ancientgates/util/FloodUtil.java +++ b/src/org/mcteam/ancientgates/util/FloodUtil.java @@ -45,7 +45,7 @@ public class FloodUtil { if (blocks1.size() > blocks2.size()) { return blocks2; } - + return blocks1; } @@ -54,8 +54,10 @@ public class FloodUtil { return null; } + //System.out.println("limit: " + limit); if (foundBlocks.size() > limit) { - return null; + System.out.println("Exceeding gate size limit."); + return null; } if (foundBlocks.contains(startBlock)) { @@ -68,11 +70,13 @@ public class FloodUtil { // ... And flood away ! for (BlockFace face : expandFaces) { - Block potentialBlock = startBlock.getFace(face); + Block potentialBlock = startBlock.getRelative(face); foundBlocks = getAirFloodBlocks(potentialBlock, foundBlocks, expandFaces, limit); } } - + if (foundBlocks != null) { + //System.out.println("size: " + foundBlocks.size()); + } return foundBlocks; } diff --git a/src/plugin.yml b/src/plugin.yml new file mode 100644 index 0000000..5a3ab39 --- /dev/null +++ b/src/plugin.yml @@ -0,0 +1,7 @@ +name: AncientGates +version: 1.0.1 +main: org.mcteam.ancientgates.Plugin +commands: + gate: + description: All of the AncientGates commands + usage: See documentation. \ No newline at end of file