Code Monkey home page Code Monkey logo

clj-minecraft's Introduction

cljminecraft

Join the chat at https://gitter.im/clj-minecraft/Lobby

cljminecraft has two specific goals:

Open up support for other clojure plugins on Bukkit

The first objective is accomplished within the ClojurePlugin.java class and the cljminecraft.core namespace. It will take care of calling the [plugin].core/start function, passing in the Bukkit plugin object for local plugin state handling.

Provide convenience functions to make writing plugins more idiomatic to clojure

The second objective is accomplished by the various other namespaces in clj-minecraft. I'm keeping the structure fairly flat and concise so that one can write idiomatic code for 80% of the plugin code.

Usage

Install the mod

Download the latest server mod build from http://dev.bukkit.org/server-mods/cljminecraft/files/ or build it yourself by cloning the repo and lein uberjar

Copy the jar into the Bukkit plugin folder and fire up your server. Once started, it should have opened a REPL port, by default on port 4005

If all you wanted was to enable clojure plugins on your server, you're done. If you want to write some code, read on.

Write some code

From now on, you will need leiningen installed - see https://github.com/technomancy/leiningen

lein repl :connect 4005

Now you have an active connection to push code onto the server, let's try some stuff (the part before => is the REPL prompt...):

user=> (in-ns 'cljminecraft.core)
#<Namespace cljminecraft.core>

cljminecraft.core=> (ev/find-event "break")
("painting.painting-break-by-entity" "hanging.hanging-break" "painting.painting-break" "entity.entity-break-door" "hanging.hanging-break-by-entity" "player.player-item-break" "block.block-break")

;; block.block-break looks good.. lets see what we can get out of it
cljminecraft.core=> (ev/describe-event "block.block-break")
#{"setExpToDrop" "isCancelled" "getEventName" "setCancelled" "getExpToDrop" "getPlayer" "getBlock"}

;; Cool, getBlock looks like I can use it..
cljminecraft.core=> (defn mybreakfn [ev] {:msg (format "You broke a %s" (.getBlock ev))})
#'cljminecraft.core/mybreakfn

cljminecraft.core=> (ev/register-event @clj-plugin "block.block-break" #'mybreakfn)
nil

;; Test breaking a block, I get a crazy message, let's make that more sane
cljminecraft.core=> (defn mybreakfn [ev] {:msg (format "You broke a %s" (.getType (.getBlock ev)))})
#'cljminecraft.core/mybreakfn

And that's a quick taste of interactive development.. The Rabbit hole goes rather deep :) enjoy.

Roll your own mod

Once you've got the cljminecraft mod installed on bukkit and you've played a bit with the REPL, you might want to build your own fully capable plugin:

lein new cljminecraft yourplugin

This will create a subfolder called yourplugin with the basics needed to get started, with some sample configuration in src/config.yml and the plugin.yml already setup under src/plugin.yml, ready to roll.

cd yourplugin
lein jar
cp target/*.jar /path/to/bukkit/plugins/

Start up your Bukkit server and go, by default, you'll see a message when you place a sign and there will be a command '/yourplugin.random' which does a dice roll. Very exciting stuff!

Remember to update your details in the plugin.yml and README.md files - and very importantly, commit to github to share with the world.

Also, be sure to look at the wiki for more in-depth instructions on all the moving parts: http://github.com/CmdrDats/clj-minecraft/wiki

Time to hack away.

Changelog:

30 December 2012:

  • Implement a simple permissions extension for checking and setting specific permissions on players
    • This does not yet persist given player permissions across sessions
  • Added clj.permission as a command to give a player a specific permission
    • Autocompletion may need work as command lists within commands are untested.

29 December 2012:

  • Now sends a message to the player triggering an event when the event function returns {:msg "..."}
  • Fix up line function
  • Add actions enum to events.clj
  • Add is-block convenience function to items.clj for checking if a block is a certain material

27 December 2012:

  • Introduce cut-to-mark, copy-to-mark, pen-from-mark and clear-mark
  • Interface of line and empty line-to-mark - have to work out the math involved
  • Thinking about how to define a brush instead of just 'material' and 'painting?' in the context.

21 December 2012:

  • Revamp the block action definitions by introducing a 'defaction' macro
  • Introduce cut, copy, paste and fork - still buggy though, especially for larger areas

19 December 2012:

  • get-material now always returns MaterialData and never Material for consistency
    • Note that this could lead to API breaks
  • Implement the first working version of the block drawing primitives
    • Similar idea to Logo, forward x, turn-right, forward x, extrude :up x
  • Playing with more things in the repl.clj scratchpatch
    • Noticed that you can send a block change to a player without changing the world.. I'll look into building the functionality to setup a 'virtual' paint mode in the block drawing. Either for all players, a list of players or a single player. It would need to track the virtual paint unless cleared so that it can resend it to players as required.

Contributions

A huge thanks to aiscott and basicsensei for their contributions to clj-minecraft!

Please feel free to fork and make pull requests if you want to contribute, I love code contributions - it makes the whole project that much more well rounded. On that note, we're desperately needing documentation, so if you're keen to contribute to the wiki, let me know.

License

Copyright (C) 2012 Deon Moolman

Distributed under the Eclipse Public License, the same as Clojure.

clj-minecraft's People

Contributors

brianbutton avatar cmdrdats avatar desertmonad avatar gitter-badger avatar magentaruby avatar rogerallen avatar taufiqkh avatar timjswan89 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

clj-minecraft's Issues

repl options now shown

the line should be like "Repl options: %s %s %s"
(log/info "Repl options: %s %s %s" (cfg/get-string plugin "repl.host") (cfg/get-int plugin "repl.port") (cfg/get-boolean plugin "repl.enabled")))

Persist player permissions across sessions

Need to save the permissions to individual player files when the plugin is disabled - perhaps more robust but not as scalable, whenever a permission is set.

It's possible to getPermissions on each PermissionAttachment, so just need to dump those, effectively.

And then when the plugin attaches the player, read from the player file and set the permissions accordingly.

spoutcraft plugin dependencies issue

I think the dependency on http://repo.spout.org needs updating as I don't believe that site exists any longer.

According to http://spoutcraft.org/threads/maven-repository-moved-updated.7505/ they have moved things to https://oss.sonatype.org/

I think that means the project :dependencies should adjust to

[org.spoutcraft/spoutcraftplugin "1.5.2-R1.0-SNAPSHOT"]

and the :repositories to

["spout.snapshots" "http://oss.sonatype.org/content/repositories/snapshots"]

I didn't find any other versions on that site, but I'm new to this code.

[p.s. thanks for putting this together. it's very cool]

Missing Download

The bukkit download link does not work. I have tried building it myself, but has turned into being a huge pain. Could you re-add the download link? Or at the very least create a shell-script build file? Thanks.

Update to bukkit 1.6.4, etc?

Bukkit has updated to 1.6.4 and this project is still at 1.4.5. In addition, most of the other libraries are a bit stale, too. My first attempt at updating fails & I see a couple forks ( @DavidJRobertson, @ddeaguiar ) have also updated project dependencies.

I'm curious if we could all try to work together to bring this main project up-to-date?

Player profiles

Often plugins need to store bits of information against a player and needs to persist that info when the player logs in or logs off.

Provide a way to get a player's profile and set arbitrary data for a given plugin against that data. This should take into account that two plugins may want to set the same keys, so make sure that each plugin is isolated for their profiles

Automatically save and load profiles when player logs out or in, and when the server is shutdown (for saving)

cant build plugin

I cant seem to build the plugin with lein. It gives the following error:

# lein uberjar
lein-javac: system java compiler not found; Be sure to use java from a JDK\nrather than a JRE by eit
her modifying PATH or setting JAVA_CMD.
Uberjar aborting because jar/compilation failed: Subprocess failed
#

Both on Windows and Linux, for me. I only have the JDK installeed.

Plugin refuses to load.

[16:53:18 ERROR]: Could not load 'plugins/cljminecraft-1.0.6-SNAPSHOT-standalone.jar' in folder 'plugins'
org.bukkit.plugin.InvalidPluginException: Cannot find main class `cljminecraft.ClojurePlugin'
        at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:42) ~[spigot-1.7.2-R0.4-SNAPSHOT.jar:git-Spigot-1328]
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:133) ~[spigot-1.7.2-R0.4-SNAPSHOT.jar:git-Spigot-1328]
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:314) ~[spigot-1.7.2-R0.4-SNAPSHOT.jar:git-Spigot-1328]
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:236) [spigot-1.7.2-R0.4-SNAPSHOT.jar:git-Spigot-1328]
        at org.bukkit.craftbukkit.v1_7_R1.CraftServer.loadPlugins(CraftServer.java:355) [spigot-1.7.2-R0.4-SNAPSHOT.jar:git-Spigot-1328]
        at net.minecraft.server.v1_7_R1.DedicatedServer.init(DedicatedServer.java:135) [spigot-1.7.2-R0.4-SNAPSHOT.jar:git-Spigot-1328]
        at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:437) [spigot-1.7.2-R0.4-SNAPSHOT.jar:git-Spigot-1328]
        at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [spigot-1.7.2-R0.4-SNAPSHOT.jar:git-Spigot-1328]
Caused by: java.lang.ClassNotFoundException: cljminecraft.ClojurePlugin
        at java.net.URLClassLoader$1.run(URLClassLoader.java:366) ~[?:1.7.0_25]
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355) ~[?:1.7.0_25]
        at java.security.AccessController.doPrivileged(Native Method) ~[?:1.7.0_25]
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354) ~[?:1.7.0_25]
        at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:77) ~[spigot-1.7.2-R0.4-SNAPSHOT.jar:git-Spigot-1328]
        at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:62) ~[spigot-1.7.2-R0.4-SNAPSHOT.jar:git-Spigot-1328]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[?:1.7.0_25]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[?:1.7.0_25]
        at java.lang.Class.forName0(Native Method) ~[?:1.7.0_25]
        at java.lang.Class.forName(Class.java:270) ~[?:1.7.0_25]
        at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:40) ~[spigot-1.7.2-R0.4-SNAPSHOT.jar:git-Spigot-1328]
        ... 7 more

Investigate subclassing ItemStack to include custom metadata

ItemStack can be serialized/deserialized - We should be able to implement and register our own serialization in a subclass of ItemStack so that we can store extra data against specific item stacks.

We'd need to test how this works with a stack of multiple items? Does it clone() and set the amounts on both, in which case splitting would work fine - not sure about combining together again..

Perhaps it would be best if the extra data was against single item stacks only if there are issues with splitting/combining.

Implement spoutcraft helper suite

All the spoutcraft functions need to provide ways of declaring what happens if Spoutcraft was not found. A plugin might be able to hobble along just fine without spoutcraft, or it may absolutely require spoutcraft in order to keep going.

Support for complex materials like 'jungle wood' in material definitions

Currently 'jungle wood' is a material type of WOOD, but using the Tree class and the TreeSpecies in the data. Need to work out a way to handle that within the recipe item specification.

The impact at the moment is in the recipe management, specifying :wood as a material type doesn't work unless it's the generic wood. The recipe system should, in wood's case, automatically handle all wood types if only :wood is selected and provide a simple way to specify the kind of wood required.

This goes for other similar Material's like step, double step and possibly others.

Look into support for setting permissions

This may be outside the scope of clj-minecraft, but it might be useful to find all the major permission plugins, abstract out an interface and support the use of any of them.

Implement some more building primitives/operations

Operations :

;; Done (fork [actions]) ;; run actions with ctx but don't update current ctx - effectively a subprocess
;; Done (copy-to-mark mark) ;; copy a block to a mark
;; Done (cut-to-mark mark) ;; cut a block to a mark, replacing everything with a given material or air if not provided
;; Done (paste mark) ;; paste a previously copied or cut block against a mark
;; Done (copy mark radius) ;; copy a sphere of a given radius into a mark
;; Done (cut mark radius) ;; cut a sphere to mark, replacing everything with a material or air

Primitives :

(line-to-mark mark) ;; draw a line to the given mark
(line fwd left up) ;; draw a line from the current point
(box-to-mark mark kind) ;; draw a :filled, :box or :outline box to a given mark
(box fwd left up kind) ;; convenience function to draw a box of kind :filled, :hollow, :outline of a given size
(circle direction radius kind) ;; build a hollow circle with the flat part 'pointing' to direction, so a flat disc to walk on would be :up or :down - kind can be :filled or :outline
(sphere radius) ;; build a hollow sphere with a given radius, kind can be :filled or :hollow or :outline

Mapping

The Mapping API looks potentially very flexible. Maybe there's a way to build some interesting functionality on top of it.

clj-minecraft + Light Table -> crash

I am trying to modify clj-minecraft to use it with Light Table nREPL by using the instructions of this link: http://manuelp.herokuapp.com/category/nrepl.

To have a LT-aware nREPL server, we have first to add a dependency to the LT middleware in project.clj

(defproject cljminecraft “1.0.6-SNAPSHOT”
:description “Clojure for Bukkit Minecraft”
:dependencies [[org.clojure/clojure "1.5.1"]
[org.clojure/tools.logging "0.2.6"]
[org.clojure/tools.nrepl "0.2.3"]
[org.bukkit/bukkit "1.6.4-R2.0"]
[clojure-complete "0.2.3"]
[cheshire "5.2.0"]
[org.reflections/reflections "0.9.8"]
[lein-light-nrepl "0.0.15"]] <———————– LT dependency
:profiles {:dev {:dependencies []}}
:javac-options [ "-d" "classes/" "-source" "1.6" "-target" "1.6"]
:java-source-paths ["javasrc"]
:uberjar-exclusions [#"(org|com|gnu)//"

"com[/]google[/]common/"

"org[/]apache[/]commons/"

"javax[/]persistence/"

"net[/]sf[/]cglib/"]

:repositories [["bukkit.snapshots" "http://repo.bukkit.org/content/repositories/snapshots"%5D
["bukkit.release" "http://repo.bukkit.org/content/repositories/releases"%5D%5D
)
-> After adding this dependency, if I ‘lein uberjar’, copy ‘cljminecraft-1.0.6-SNAPSHOT-standalone’ in the plugins and restart ‘craftbukkit-1.7.2-R0.2 Beta’ server, the clojure plugin is not crashing but to connect LT to the plugin, we have to also add the middlewares chains in the code:
(ns cljminecraft.core
(:require [cljminecraft.bukkit :as bk]
[cljminecraft.blocks :as blocks]
[cljminecraft.events :as ev]
[cljminecraft.entity :as ent]
[cljminecraft.player :as plr]
[cljminecraft.util :as util]
[cljminecraft.logging :as log]
[cljminecraft.config :as cfg]
[cljminecraft.commands :as cmd]
[cljminecraft.recipes :as r]
[cljminecraft.items :as i]
[cljminecraft.files]
[clojure.tools.nrepl.server :refer (start-server stop-server)]
[lighttable.nrepl.handler :refer [lighttable-ops]] <———— middlewares chains
))
After adding the middlewares chains in the code, I did ‘lein uberjar’, copied ‘cljminecraft-1.0.6-SNAPSHOT-standalone’ in the plugins and restarted the ‘craftbukkit-1.7.2-R0.2 Beta’ server. Doing that I got the message ‘Something broke setting up Clojure’ -> clojure in the crafbukkit server crashed.

I use LightTable 0.6.2. (0.8.4). I am just starting to learn clojure and Light Table and I am not a professional programmer, so I am probably missing something obvious.. Any idea how I can troubleshoot that?

Wrapper for potions

Probably just a map-enum over org.bukkit.potion.PotionType and a helper to apply/remove effects?

stop REPL on disable? else `reload` will fail to re-enable it

or find another way (investigate)
I know, reload should not be used right?(at least because it eats up memory until you run out of it - from my experience PermGen) but for tests at least I use it.

EDIT: maybe something like check if it's already running and don't rerun?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.