Permalink
Browse files

Loads of changes, mostly materials & items.

Resolves #30, #29, #26
  • Loading branch information...
1 parent 481741d commit 0aa090022fc3ebcf25229a6f1540640e47563591 @CmdrDats committed Dec 14, 2012
View
@@ -23,6 +23,21 @@ understand what changes are made and adjust your plugins accordingly.
Changelog:
+14 December 2012:
+ - Implement material handling types properly
+ o You can now specify [:wood :jungle :north] as a material key for (get-material)
+ o Supports everything down to [:mushroom false :north] for a non-stem north-painted mushroom block
+ - Command Tab completion support for event types and entity types
+ - Add 'spawnentity' and 'addevent' commands to showcase tabcompletion.
+ - Add 'find-entity' function in entity.clj - can use that to lookup the kinds of entities
+ - Tweak the event macro to be a simple function and the register-event to do the actual legwork.
+ - Add 'find-event' and 'describe-event' for making events easier to poke at from the REPL
+ - Moved the materials to items.clj
+ - The item-stack function in items.clj uses get-material
+ o This makes creating a specific itemstack straightforward and consistent (item-stack [:wood :jungle] 2)
+ - Tweak the recipes to use get-material, to make recipe material definitions very precise
+ - Add some class helpers in util.clj
+
09 December 2012:
- Implement first version of recipe wrapper functions
o Support for both shaped and unshaped recipes from the same function.
@@ -12,10 +12,6 @@
import org.bukkit.plugin.*;
import org.bukkit.plugin.java.*;
-
-
-
-
public abstract class BasePlugin extends JavaPlugin{
protected final static String selfPluginName=ClojurePlugin.class.getPackage().getName();//"cljminecraft";
@@ -324,5 +320,4 @@ public final void onDisable() {//called only when onEnable didn't fail (if we di
+ " clojure Plugin because it wasn't successfully enabled previously" );
}
}
-
}
View
@@ -5,8 +5,8 @@
[org.clojure/tools.nrepl "0.2.0-RC1"]
[org.bukkit/bukkit "1.4.5-R0.3-SNAPSHOT"]
[clojure-complete "0.2.2"]
- [cheshire "2.0.4"]]
-
+ [cheshire "2.0.4"]
+ [org.reflections/reflections "0.9.8"]]
:javac-options [ "-d" "classes/" "-source" "1.6" "-target" "1.6"]
:java-source-paths ["javasrc"]
@@ -2,7 +2,10 @@
(:require [cljminecraft.bukkit :as bk]
[cljminecraft.util :as util]
[cljminecraft.logging :as log]
- [cljminecraft.player :as plr])
+ [cljminecraft.player :as plr]
+ [cljminecraft.events :as ev]
+ [cljminecraft.entity :as ent]
+ )
(:import [org.bukkit.command TabExecutor]))
(defn respond
@@ -44,6 +47,30 @@
(defmethod convert-type :default [sender type arg]
(str arg))
+(defmethod convert-type :event [sender type arg]
+ (str arg))
+
+(defmethod convert-type :entity [sender type arg]
+ (str arg))
+
+(defmulti param-type-tabcomplete (fn [_ x _] x))
+
+(defmethod param-type-tabcomplete :player [sender type arg]
+ (let [lower (.toLowerCase arg)]
+ (map #(.getDisplayName %)
+ (filter #(.startsWith (.toLowerCase (org.bukkit.ChatColor/stripColor (.getDisplayName %))) lower)
+ (bk/online-players)))))
+
+(defmethod param-type-tabcomplete :material [sender type arg]
+ (let [lower (.toLowerCase arg)]
+ (filter #(.startsWith % lower) (map name (keys plr/materials)))))
+
+(defmethod param-type-tabcomplete :event [sender type arg]
+ (ev/find-event arg))
+
+(defmethod param-type-tabcomplete :entity [sender type arg]
+ (ent/find-entity arg))
+
(defn arity-split [args]
(split-with #(not= '& %) args))
@@ -71,18 +98,6 @@
(catch RuntimeException e (.printStackTrace e) (respond sender "An error occurred with this command")))
true)
-(defmulti param-type-tabcomplete (fn [_ x _] x))
-
-(defmethod param-type-tabcomplete :player [sender type arg]
- (let [lower (.toLowerCase arg)]
- (map #(.getDisplayName %)
- (filter #(.startsWith (.toLowerCase (org.bukkit.ChatColor/stripColor (.getDisplayName %))) lower)
- (bk/online-players)))))
-
-(defmethod param-type-tabcomplete :material [sender type arg]
- (let [lower (.toLowerCase arg)]
- (filter #(.startsWith % lower) (map name (keys plr/materials)))))
-
(defn to-string-seq [a]
(for [i (seq a)] (if (keyword? i) (name i) (str i))))
View
@@ -1,6 +1,8 @@
(ns cljminecraft.core
(:require [cljminecraft.bukkit :as bk]
[cljminecraft.events :as events]
+ [cljminecraft.entity :as ent]
+ [cljminecraft.player :as plr]
[cljminecraft.util :as util]
[cljminecraft.logging :as log]
[cljminecraft.config :as cfg]
@@ -60,12 +62,22 @@
(defn tabcomplete-reverse-first [sender command alias args]
[(apply str (reverse (first args)))])
+(defn addevent-command [sender eventname message]
+ (events/register-event @clj-plugin eventname (fn [ev] (.sendMessage sender (str message ": " ev))))
+ {:msg (format "Adding event %s with message %s" eventname message)})
+
+(defn spawn-command [sender entity]
+ (ent/spawn-entity (.getLocation sender) entity)
+ (log/info "Spawning %s in front of %s" entity (.getName sender)))
+
(defn start
"onEnable cljminecraft"
[plugin]
(reset! clj-plugin plugin)
(cmd/register-command @clj-plugin "clj.repl" #'repl-command [:keyword [:start :stop]] [:int [(cfg/get-int plugin "repl.port")]])
(cmd/register-command @clj-plugin "clj.tabtest" #'tabtest-command :player :material [:keyword [:start :stop]] [:string #'tabcomplete-reverse-first])
+ (cmd/register-command @clj-plugin "clj.addevent" #'addevent-command :event :string)
+ (cmd/register-command @clj-plugin "clj.spawnentity" #'spawn-command :entity)
(start-repl-if-needed plugin))
(defn stop
@@ -104,3 +116,4 @@
)
+
@@ -0,0 +1,23 @@
+(ns cljminecraft.entity
+ (:require [cljminecraft.util :as util]))
+
+(def entitytypes (util/map-enums org.bukkit.entity.EntityType))
+
+(defn find-entity [nm]
+ (let [names (map #(name (first %)) entitytypes)]
+ (filter #(.contains % (.toLowerCase nm)) names)))
+
+(defn spawn-entity [location entityname]
+ (let [type (get entitytypes (keyword entityname))]
+ (when (and type (.isSpawnable type))
+ (.spawn (.getWorld location) location type))))
+
+
+
+
+
+
+
+
+
+
@@ -6,15 +6,16 @@
(defonce priorities (util/map-enums org.bukkit.event.EventPriority))
-(defn register-event [plugin event-class f & [priority-key]]
- (.registerEvent
- (bk/plugin-manager)
- event-class
- (proxy [org.bukkit.event.Listener] [])
- (get priorities (or priority-key :normal))
- (proxy [org.bukkit.plugin.EventExecutor] []
- (execute [l e] (f e)))
- plugin))
+(defn register-event [plugin eventname f & [priority-key]]
+ (let [eventclass (resolve (symbol (util/package-classname "org.bukkit.event" (str eventname "-event"))))]
+ (.registerEvent
+ (bk/plugin-manager)
+ eventclass
+ (proxy [org.bukkit.event.Listener] [])
+ (get priorities (or priority-key :normal))
+ (proxy [org.bukkit.plugin.EventExecutor] []
+ (execute [l e] (f e)))
+ plugin)))
(defonce registered-events
(atom #{}))
@@ -26,14 +27,28 @@
(register-event plugin (:classname ev) (:event-fn ev) (:priority ev))
)))
-(defmacro event
- "Convenience function for registering events, event-name being prefixed with org.bukkit.event.
+(defn event
+ "Convenience function for registering events, eventname being prefixed with org.bukkit.event.
and camelcased so that you can simply call (onevent block.block-break-event [e] (logging/info (bean e)))
to register for the org.bukkit.event.block.BlockBreakEvent and run the body with the BlockBreakEvent as its only
argument"
- [event-name fn & [priority]]
- (let [classname (util/package-classname "org.bukkit.event" (str event-name "-event"))]
- `{:classname ~(resolve (symbol classname))
- :event-fn ~fn
- :priority ~priority}))
+ [eventname fn & [priority]]
+ {:eventname eventname
+ :event-fn fn
+ :priority priority})
+(defn find-event [name]
+ (let [classes (util/find-subclasses "org.bukkit" org.bukkit.event.Event)
+ names (map #(.replaceAll
+ (.replaceAll (util/class-named %) "org.bukkit.event." "")
+ "-event$" "") classes)]
+ (filter #(.contains % (.toLowerCase name)) names)))
+
+(def boring-methods #{"getHandlers" "getHandlerList" "wait" "equals" "toString" "hashCode" "getClass" "notify" "notifyAll" "isAsynchronous"})
+
+(defn describe-event [eventname]
+ (let [classname (util/package-classname "org.bukkit.event" (str eventname "-event"))
+ cl (resolve (symbol classname))]
+ (set
+ (filter #(not (contains? boring-methods %))
+ (map #(:name (bean %)) (seq (:methods (bean cl))))))))
Oops, something went wrong.

0 comments on commit 0aa0900

Please sign in to comment.