Skip to content
Snippets Groups Projects
Commit 0c3abcd2 authored by Mariell's avatar Mariell :speech_balloon:
Browse files

Moved from Coalesce to own repo, fix license, fix examples, remove gitignore,...

Moved from Coalesce to own repo, fix license, fix examples, remove gitignore, fix plugin.yml and add Return exception.
parent 69f02626
No related branches found
No related tags found
No related merge requests found
/target
/classes
/checkouts
pom.xml
pom.xml.asc
*.jar
*.class
/.lein-*
/.nrepl-port
.hgignore
.hg/
MIT License
Copyright (c) 2017 Project Coalesce
Copyright (c) 2017 Mariell Hoversholm
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
......
......@@ -11,7 +11,7 @@ Simply download from the Releases tab or download the current (WIP) source and i
##### Loading the plugin
Add this to your plugin.yml:
```yaml
main: com.coalesce.bukkitforclojure.Main
main: com.proximyst.bukkitforclojure.Main
```
And add this to your clojure.yml:
......@@ -57,7 +57,7 @@ To register events you'll first need a method with an event as a param, whether
)
```
To now register this, you'll need to do this in the onEnable:
To now register this, you'll need to do this in the onEnable, but remember to call use on it first:
```clojure
(defn onEnable
[]
......@@ -72,7 +72,7 @@ To register commands, you'll need a pretty standard onCommand method somewhere,
[^CommandSender sender
^Command command
^String label
#^"[Ljava.lang.String;" args] ; Type hinting String arrays isnt possible, thus this workaround.
args] ; Type hinting String arrays isnt possible, thus we don't have any type of it, and rather just use it like a collection within clojure.
(prn (-> command (.getName) (.toUpperCase)) " was executed!")
)
```
......@@ -84,16 +84,16 @@ And now onto actually registering the command, again in onEnable:
)
```
And register the command like you always would in the plugin.yml.
All exceptions thrown are catched with no output, thus a nice return statement.
All exceptions thrown are caught with output, unless they're instance of Return.
### Bugs
Currently we have no bugs which we know of as it hasn't ever been tested, at least for now.
Currently no bugs are known.
## License
MIT License
Copyright (c) 2017 Project Coalesce
Copyright (c) 2017 Mariell Hoversholm
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
......
name: Bukkit4Clojure
author: ProjectCoalesce
author: Proximyst
version: 0.1.0-SNAPSHOT
main: com.coalesce.bukkitforclojure.Main
main: com.proximyst.bukkit4clojure.example.javaplugin
commands:
clojure:
\ No newline at end of file
#commands:
#clojure:
\ No newline at end of file
package com.coalesce.bukkitforclojure;
package com.proximyst.bukkitforclojure;
import clojure.java.api.Clojure;
import clojure.lang.IFn;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
......@@ -18,6 +19,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Main extends JavaPlugin {
......@@ -118,8 +120,12 @@ public class Main extends JavaPlugin {
try {
command.invoke(sender, command, label, args);
} catch (Exception ex) {
// Due to clojure having no return statement, this will be kind of the statement.
// If the developer expects one, use a try-catch block in Clojure.
//noinspection ConstantConditions
if (ex instanceof Return) {
return true;
}
sender.sendMessage(ChatColor.RED + "An error occurred within the code. Ask an admin about the stacktrace.");
getLogger().log(Level.SEVERE, "An error occurred!", ex);
}
return true;
}
......@@ -137,6 +143,9 @@ public class Main extends JavaPlugin {
}
public static Main getInstance() {
if (instance == null) {
instance = Main.getPlugin(Main.class);
}
return instance;
}
}
package com.proximyst.bukkitforclojure;
import java.io.PrintStream;
import java.io.PrintWriter;
public class Return extends Exception {
@Override
public void printStackTrace() {
}
@Override
public void printStackTrace(PrintStream s) {
}
@Override
public void printStackTrace(PrintWriter s) {
}
@Override
public String toString() {
return "";
}
@Override
public String getLocalizedMessage() {
return "Returned out of Clojure function.";
}
@Override
public String getMessage() {
return "Returned out of Clojure function.";
}
@Override
public synchronized Throwable getCause() {
return null;
}
@Override
public StackTraceElement[] getStackTrace() {
return new StackTraceElement[0];
}
}
(ns com.coalesce.bukkitforclojure.example.command
(ns com.proximyst.bukkitforclojure.example.command
(:gen-class)
(:import [org.bukkit.command CommandSender Command]
[org.bukkit.entity Player]
[org.bukkit Sound]))
......@@ -7,9 +8,9 @@
[^CommandSender sender
^Command command
^String label
#^"[Ljava.lang.String;" args]
args]
(.sendMessage sender "You successfully ran a command in Clojure.")
(if (instance? Player sender)
(let [player (cast Player sender)]
(.playSound player (.getLocation player) (Sound/BLOCK_NOTE_BASEDRUM) 1.0 1.0)))
(when (instance? Player sender)
(let [^Player player (cast Player sender)]
(.playSound player (.getLocation player) (Sound/BLOCK_NOTE_BASEDRUM) (float 1.0) (float 1.0))))
)
\ No newline at end of file
......@@ -4,12 +4,14 @@ com.coalesce.bukkitforclojure.example.example
(:gen-class)
(:import [org.bukkit.plugin PluginDescriptionFile]
[org.bukkit.configuration.file FileConfiguration]
[com.coalesce.bukkitforclojure Main]
[com.proximyst.bukkitforclojure Main]
[java.io File]
[org.bukkit Server]
[java.util.logging Logger]
[org.bukkit.event.player PlayerJoinEvent]
[org.bukkit.event EventPriority]))
[org.bukkit.event EventPriority])
(:use [com.proximyst.bukkitforclojure.example.command :only [clojureCommand]]
[com.proximyst.bukkitforclojure.example.listener :only [playerJoinedHandler]]))
(def ^Main wrapperMain)
(def ^File dataFolder)
......@@ -20,8 +22,8 @@ com.coalesce.bukkitforclojure.example.example
(defn onEnable
[]
(.registerEvent wrapperMain PlayerJoinEvent (EventPriority/NORMAL) (fn [event] (com.coalesce.bukkitforclojure.example.listener/playerJoinedHandler event)))
(.registerCommand wrapperMain "clojure" #(com.coalesce.bukkitforclojure.example.command/clojureCommand %1 %2 %3 %4))
(.registerEvent wrapperMain PlayerJoinEvent (EventPriority/NORMAL) (fn [event] (playerJoinedHandler event)))
(.registerCommand wrapperMain "clojure" #(clojureCommand %1 %2 %3 %4))
)
(defn setData
......
(ns com.coalesce.bukkitforclojure.example.listener
(ns com.proximyst.bukkitforclojure.example.listener
(:gen-class)
(:import [org.bukkit.event.player PlayerJoinEvent]
[org.bukkit Bukkit ChatColor]
[org.bukkit.entity Player]))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment