Skip to content

Commit

Permalink
Add a facing-block convenience function for directional blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
CmdrDats committed Dec 13, 2012
1 parent af4a11f commit 481741d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/cljminecraft/util.clj
Expand Up @@ -55,13 +55,11 @@
(glue "." package classname)))


(defn port-in-use? [port bind]
(let [bind-addr (if (InetSocketAddress. bind port) (InetSocketAddress. port))]
(try
(defn port-in-use? [port bind]
(let [bind-addr (if (InetSocketAddress. bind port) (InetSocketAddress. port))]
(try
(with-open [ss (ServerSocket. port 0 (.getAddress bind-addr))] false)
(catch IOException e true))
)
)
(catch IOException e true))))

(defn throw-runtime [fmt & args]
(throw (java.lang.RuntimeException. (apply format fmt args))))
12 changes: 12 additions & 0 deletions src/cljminecraft/world.clj
@@ -0,0 +1,12 @@
(ns cljminecraft.world
(:require [cljminecraft.bukkit :as bk])
(:require [cljminecraft.player :as plr])
(:import [org.bukkit.material Directional]))

(defn facing-block
"If this is a directional block, will return the block it's facing, otherwise it will return the block itself"
[block]
(let [data (.. block getState getData)]
(if (instance? Directional data)
(.getFace block (.getFacing data))
block)))

0 comments on commit 481741d

Please sign in to comment.