kept players yaw and pitch while walking through a gate; saving for actual gate size (preventing resizing of gates after creation); all credit goes to s1m0ne

This commit is contained in:
Tobias Ottenweller 2012-02-25 17:46:19 +01:00
parent 4a6b5902e3
commit 254137e74d
6 changed files with 81 additions and 19 deletions

View File

@ -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;
}
// -------------------------------------------- //

View File

@ -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<Block> 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<Block> blocks = FloodUtil.getGateFrameBlocks(from.getBlock());
// Uncomment lines below to have the old Portal open functionality back.
for (Block block : blocks) {
block.setType(Material.AIR);
}

View File

@ -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<Location>, 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;
}
}

View File

@ -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<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) {
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();
}

View File

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

7
src/plugin.yml Normal file
View File

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