Merge branch 'master' of git://github.com/DrAgonmoray/minecraft-ancient-gates

Conflicts:
	src/org/mcteam/ancientgates/MyLocationTypeAdapter.java
	src/org/mcteam/ancientgates/Plugin.java
	src/org/mcteam/ancientgates/commands/CommandSetFrom.java
	src/org/mcteam/ancientgates/listeners/PluginBlockListener.java
	src/org/mcteam/ancientgates/listeners/PluginPlayerListener.java
	src/org/mcteam/ancientgates/util/FloodUtil.java
This commit is contained in:
Tobias Ottenweller
2012-03-10 15:38:54 +01:00
10 changed files with 116 additions and 82 deletions

View File

@ -4,8 +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;
@ -63,10 +63,9 @@ 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(new WorldCreator(name));
if (world == null) {
world = Plugin.instance.getServer().createWorld(new WorldCreator(name).environment(Environment.NORMAL));
}
return world;
}
}

View File

@ -7,27 +7,12 @@ import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;
import org.mcteam.ancientgates.commands.BaseCommand;
import org.mcteam.ancientgates.commands.CommandClose;
import org.mcteam.ancientgates.commands.CommandCreate;
import org.mcteam.ancientgates.commands.CommandCreateSetFrom;
import org.mcteam.ancientgates.commands.CommandDelete;
import org.mcteam.ancientgates.commands.CommandHelp;
import org.mcteam.ancientgates.commands.CommandInfo;
import org.mcteam.ancientgates.commands.CommandList;
import org.mcteam.ancientgates.commands.CommandOpen;
import org.mcteam.ancientgates.commands.CommandRename;
import org.mcteam.ancientgates.commands.CommandSetFrom;
import org.mcteam.ancientgates.commands.CommandSetTo;
import org.mcteam.ancientgates.commands.*;
import org.mcteam.ancientgates.gson.Gson;
import org.mcteam.ancientgates.gson.GsonBuilder;
@ -35,7 +20,8 @@ import org.mcteam.ancientgates.listeners.PluginBlockListener;
import org.mcteam.ancientgates.listeners.PluginPlayerListener;
public class Plugin extends JavaPlugin {
public class Plugin extends JavaPlugin
{
public static Plugin instance;
public PluginPlayerListener playerListener = new PluginPlayerListener();
@ -52,7 +38,8 @@ public class Plugin extends JavaPlugin {
// Commands
public List<BaseCommand> commands = new ArrayList<BaseCommand>();
public Plugin() {
public Plugin()
{
instance = this;
}
@ -87,7 +74,7 @@ public class Plugin extends JavaPlugin {
// Register events
getServer().getPluginManager().registerEvents(this.playerListener, this);
getServer().getPluginManager().registerEvents(this.blockListener, this);
log("Enabled");
}
@ -108,8 +95,7 @@ public class Plugin extends JavaPlugin {
if (this.baseCommand != null) {
return this.baseCommand;
}
Map<String, Object> Commands = (Map<String, Object>)this.getDescription().getCommands();
Map<String, Map<String, Object>> Commands = (Map<String, Map<String, Object>>) this.getDescription().getCommands();
this.baseCommand = Commands.keySet().iterator().next();
return this.baseCommand;
}

View File

@ -31,7 +31,7 @@ public class CommandSetFrom extends BaseCommand {
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.");
@ -48,12 +48,12 @@ public class CommandSetFrom extends BaseCommand {
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.");
Gate.save();
}

View File

@ -1,54 +1,47 @@
package org.mcteam.ancientgates.listeners;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.EventHandler;
public class PluginBlockListener implements Listener
{
@EventHandler
@EventHandler(priority = EventPriority.NORMAL)
public void onBlockPhysics(BlockPhysicsEvent event)
{
if (event.isCancelled())
return;
if (event.getBlock().getType() != Material.PORTAL)
if (event.getBlock().getType() != Material.PORTAL) {
return;
}
if (isBlockInPortal(event.getBlock()))
if (isBlockInPortal(event.getBlock())) {
event.setCancelled(true);
}
}
public boolean isBlockInPortal(Block block)
{
if (block.getRelative(BlockFace.UP).getType() == Material.AIR)
return false;
if (block.getRelative(BlockFace.DOWN).getType() == Material.AIR)
return false;
if ( block.getRelative(BlockFace.NORTH).getType() != Material.AIR && block.getRelative(BlockFace.SOUTH).getType() != Material.AIR )
return true;
if ( block.getRelative(BlockFace.WEST).getType() != Material.AIR && block.getRelative(BlockFace.EAST).getType() != Material.AIR )
return true;
return false;
}
}

View File

@ -9,8 +9,8 @@ import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
@ -20,12 +20,13 @@ import org.mcteam.ancientgates.Plugin;
import org.mcteam.ancientgates.util.GeometryUtil;
public class PluginPlayerListener implements Listener
{
@EventHandler
public class PluginPlayerListener implements Listener
{
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerMove(PlayerMoveEvent event)
{
if (event.isCancelled())
if (event.isCancelled())
return;
Block blockTo = event.getTo().getBlock();
@ -33,11 +34,9 @@ public class PluginPlayerListener implements Listener
// Check if player is standing inside a portal
if (blockTo.getType() != Material.PORTAL && blockToUp.getType() != Material.PORTAL)
{
if (blockTo.getType() != Material.PORTAL && blockToUp.getType() != Material.PORTAL)
return;
}
// Ok so a player walks into a portal block
// Find the nearest gate!
@ -71,14 +70,14 @@ public class PluginPlayerListener implements Listener
{
nearestGate = gate;
break;
}
}
}
/*if (shortestDistance == -1 || shortestDistance > distance) {
nearestGate = gate;
shortestDistance = distance;
}*/
}
}
if (nearestGate != null)
{

View File

@ -47,7 +47,7 @@ public class FloodUtil {
if (blocks1.size() > blocks2.size()) {
return blocks2;
}
return blocks1;
}
@ -55,11 +55,11 @@ public class FloodUtil {
{
if (foundBlocks == null)
return null;
if (foundBlocks.size() > limit)
{
Plugin.log(Level.ALL, "exceeding gate size limit.");
return null;
return null;
}
if (foundBlocks.contains(startBlock))
@ -77,7 +77,7 @@ public class FloodUtil {
foundBlocks = getAirFloodBlocks(potentialBlock, foundBlocks, expandFaces, limit);
}
}
return foundBlocks;
}