Skip to content
This repository
Browse code

Added line function

Also implement recommended .gitattributes
  • Loading branch information...
commit 2be38d60d52a0c24aadc085dcea3bcec055eee9e 1 parent 99fce91
brianbutton brianbutton authored
22 .gitattributes
... ... @@ -0,0 +1,22 @@
  1 +# Auto detect text files and perform LF normalization
  2 +* text=auto
  3 +
  4 +# Custom for Visual Studio
  5 +*.cs diff=csharp
  6 +*.sln merge=union
  7 +*.csproj merge=union
  8 +*.vbproj merge=union
  9 +*.fsproj merge=union
  10 +*.dbproj merge=union
  11 +
  12 +# Standard to msysgit
  13 +*.doc diff=astextplain
  14 +*.DOC diff=astextplain
  15 +*.docx diff=astextplain
  16 +*.DOCX diff=astextplain
  17 +*.dot diff=astextplain
  18 +*.DOT diff=astextplain
  19 +*.pdf diff=astextplain
  20 +*.PDF diff=astextplain
  21 +*.rtf diff=astextplain
  22 +*.RTF diff=astextplain
646 javasrc/cljminecraft/BasePlugin.java
... ... @@ -1,323 +1,323 @@
1   -package cljminecraft;
2   -
3   -import java.io.*;
4   -import java.net.*;
5   -import java.nio.charset.*;
6   -import java.security.*;
7   -import java.util.*;
8   -import java.util.logging.*;
9   -
10   -import org.bukkit.*;
11   -import org.bukkit.command.*;
12   -import org.bukkit.plugin.*;
13   -import org.bukkit.plugin.java.*;
14   -
15   -public abstract class BasePlugin extends JavaPlugin{
16   - protected final static String selfPluginName=ClojurePlugin.class.getPackage().getName();//"cljminecraft";
17   -
18   - public final static Charset UTF8 = Charset.forName("UTF-8");
19   -
20   - private final static Logger logger=Bukkit.getLogger();//it would've been the same instance across both main and child plugins
21   -// private final static Logger logger=Logger.getLogger( "Minecraft" );//this is equivalent to above
22   -
23   - //true when `reload` happened OR when this plugin got loaded to an already running server ie. via `plugman load pluginnamehere`
24   - private static boolean isServerReloaded=(null != Bukkit.getConsoleSender());
25   -
26   - //true if onEnable was successful, false or null(not found) if onEnable failed or was never executed
27   - private Boolean successfullyEnabled=null;//each plugin will have one of these
28   -
29   - static {//static initializer block
30   - //XXX: on server `reload` this gets re-executed
31   - if ( !isServerReloaded() ) {
32   - boolean asserts = false;
33   - assert ( true == ( asserts = true ) );
34   -
35   - _info( "assertions are " + ( !asserts ? "NOT " : "" ) + "enabled"
36   - + ( !asserts ? " (to enable pass jvm option -ea when starting bukkit)" : "" ) );
37   - }
38   -
39   - if (isServerReloaded()) {
40   - _info("you just `reload`-ed the server OR this plugin got loaded to an already running server ie. via `plugman load "
41   - +BasePlugin.class.getPackage().getName()+"`");
42   - //EDIT: there's one variant which may wrongly detect a `reload` if you're using this:
43   - //if you were running the server then then you just place your plugin in plugins folder and execute a
44   - //command something like `plugman load yourplugin` - it will detect it as a reload because getConsoleSender
45   - //is not null at this point. (tested to be true)
46   - //EDIT2: also note that if the plugin was already running doing `plugman unload it` then `plugman load it`
47   - //(or even `plugman reload it`) won't cause it to be detected as a `reload`
48   -
49   -
50   - }
51   -
52   - //this should only be executed for cljminecraft(the main not any children) plugin, and it is so if children have a depend on cljminecraft
53   - //bukkit will then make sure cljminecraft is loaded before them
54   -
55   - //one time in bukkit lifetime(right?) we set *loader* to the classloader which applies to any future clojure scripts loads
56   - ClassLoader previous = Thread.currentThread().getContextClassLoader();
57   - final ClassLoader parentClassLoader = ClojurePlugin.class.getClassLoader();
58   - Thread.currentThread().setContextClassLoader(parentClassLoader);
59   - try {
60   -// if (isServerReloaded()) {
61   -//// clojure.lang.Var.popThreadBindings();great there is nothing pushed
62   -// assert !clojure.lang.Compiler.LOADER.isBound();
63   -// }
64   - //this happens only once when ClojurePlugin.class gets loaded which actually happens once at bukkit server startup AND
65   - //also happens every time there's a `reload` command executed
66   - if (isServerReloaded()) {
67   - _info("!!!!!!!!!!!!!clojure reinit!!");
68   - }else{
69   - _info("!!!!!!!!!!!!!First time clojure init!!");
70   - }
71   - System.out.flush();
72   -
73   - clojure.lang.DynamicClassLoader newCL = (clojure.lang.DynamicClassLoader)AccessController.doPrivileged( new PrivilegedAction() {
74   - @Override
75   - public Object run() {
76   - assert parentClassLoader == ClojurePlugin.class.getClassLoader();
77   - assert this.getClass().getClassLoader() == ClojurePlugin.class.getClassLoader();//even though "this" is different
78   - return new clojure.lang.DynamicClassLoader( parentClassLoader );
79   - }
80   - } );
81   - assert !clojure.lang.Compiler.LOADER.isBound();//wow this really isn't bound even after `reload` also nothing remains pushed
82   - clojure.lang.Var.pushThreadBindings( clojure.lang.RT.map( clojure.lang.Compiler.LOADER, newCL) );//so this variant is the one
83   -// System.err.println(clojure.lang.RT.CLOJURE_NS);
84   -// clojure.lang.Var.intern(clojure.lang.RT.CLOJURE_NS,//just as I thought this variant won't work
85   -// Symbol.intern("clojure.lang.Compiler/LOADER")//can't intern namespace qualified symbol
86   -//// clojure.lang.Compiler.LOADER.sym this is actually null because there's no counterpart in clojure? :O I thought it was *loader*
87   -// , newCL, true);
88   -// clojure.lang.RT.WARN_ON_REFLECTION;
89   - //XXX: turn on reflection warnings for all plugins (maybe add/override this in each config.yml
90   - //XXX: does the above make sense? not sure how
91   - //no: maybe specify namespace to that *var* - can't intern namespace qualified symbol(I predict)
92   - clojure.lang.Var.intern(clojure.lang.RT.CLOJURE_NS,
93   - clojure.lang.Symbol.intern("*warn-on-reflection*")
94   - //there's no accessible java field from which to get the symbol directly (they are non-public but there in RT nd Compiler classes)
95   - ,
96   -// isServerReloaded()?clojure.lang.RT.T:clojure.lang.RT.F
97   - clojure.lang.RT.F
98   - , true);
99   - //the above is equivalent to clojure code: (set! *warn-on-reflection* true)
100   -
101   - clojure.lang.Var.intern(clojure.lang.RT.CLOJURE_NS,
102   - clojure.lang.Symbol.intern("*use-context-classloader*")
103   - ,clojure.lang.RT.F
104   - , true);
105   - }finally{
106   - Thread.currentThread().setContextClassLoader(previous);
107   - }
108   - }
109   -
110   - /**
111   - * @return true when `reload` happened on server<br>
112   - * OR when this plugin got loaded to an already running server ie. via `plugman load pluginnamehere`
113   - */
114   - public final static boolean isServerReloaded() {
115   - //TODO: find a way to know when it was actually `reload` or our plugin got inited the first time
116   - //or do we simply give no support for the variant of `plugman load cljminecraft` into an already running server(after just having placed the .jar first time in plugins folder)?
117   - return isServerReloaded;
118   - }
119   -
120   - @Override
121   - public final void onLoad() {
122   - URL jarURL;
123   - // XXX: executes once for each plugin TODO: investigate what happens if plugman unload and load is used AND server `reload`
124   - //main concern is if the url already exists is it re-added? if not then is it re-ordered /moved at beginning or end?
125   - try {
126   - jarURL = this.getFile().toURI().toURL();
127   - } catch ( MalformedURLException e ) {
128   - throw new RuntimeException( "should never happen", e );
129   - }
130   -
131   - info( "loaded jar: " + jarURL );
132   - assert clojure.lang.Compiler.LOADER.isBound();
133   - if (!getName().equals(selfPluginName)) {
134   - //we don't have to add cljminecraft.jar to classpath here
135   - ( (clojure.lang.DynamicClassLoader)clojure.lang.Compiler.LOADER.deref() ).addURL( jarURL );
136   - }
137   - }
138   -
139   - public BasePlugin() {
140   - super();
141   - //constructor
142   - info("CONSTRUCTOR");//for "+this.getFile().getAbsoluteFile()); these aren't yet set
143   - //we don't know yet for which plugin we got constructed
144   - //XXX: an instance is created of this class for every child plugin (including the main one)
145   - //TODO: maybe add a test to make sure this didn't change in the future
146   - }
147   -
148   - public static String showClassPath(String prefix, ClassLoader cl){
149   - _info("=="+prefix+"== For classloader "+cl+" ----------");
150   - _info(getClassPath(cl));
151   - _info("=="+prefix+"== ----END---"+cl+" ----------");
152   - return "";
153   - }
154   -
155   -
156   - public final static String getClassPath() {
157   - return getClassPath(Thread.currentThread().getContextClassLoader());
158   - }
159   -
160   - public final static String getClassPath(ClassLoader cl) {
161   - URL[] urls = ((URLClassLoader)cl).getURLs();
162   - String cp ="{";
163   -
164   - int max = urls.length-1;
165   - if (max>=0){
166   - cp+=" ";
167   - }
168   - for ( int i = 0; i <= max; i++ ) {
169   - URL url = urls[i];
170   - try {
171   - cp+= url.toURI().toString();
172   - if(i != max) {
173   - cp+=", ";
174   - }else {
175   - cp+=" ";
176   - }
177   - } catch ( URISyntaxException use ) {
178   - use.printStackTrace();
179   - throw new RuntimeException(use);
180   - }
181   - }
182   - cp+="}";
183   - return cp;
184   - }
185   -
186   - protected String showResources(ClassLoader cl, String file1) {
187   - try {
188   - Enumeration<URL> urls = cl.getResources( file1 );
189   - System.out.println("all `"+file1+"` Resources: { ");
190   - while (urls.hasMoreElements()) {
191   - System.out.println(urls.nextElement());
192   - }
193   - System.out.println(" }");
194   - } catch ( IOException e ) {
195   - e.printStackTrace();
196   - }
197   - return "";
198   - }
199   -
200   - protected int count(Enumeration e) {
201   - assert null != e:"you passed null, bug somewhere";
202   - int count=0;
203   - while(e.hasMoreElements()) {
204   - count++;
205   - e.nextElement();
206   - }
207   - return count;
208   - }
209   -
210   - @Override
211   - public InputStream getResource( String fileName ) {
212   - //XXX: when a file within the .jar of current plugin is needed then from within clojure or java either call this method or call
213   - //clojure.lang.RT.getResource(this.getClassLoader(), fileName); where this == plugin instance
214   - //or else it will get the file from cljminecraft not from memorystone, ie. file name like config.yml which exists in both in same location
215   - assert isNotMoreThanOneResource(fileName):"more than 1 file with the same name was detected in classpath,"
216   - +showClassPath("",getClassLoader())
217   - +showResources( getClassLoader(), fileName )
218   - +" PLEASE SEE ABOVE ";
219   -
220   - return super.getResource( fileName );
221   - }
222   -
223   - protected boolean isNotMoreThanOneResource(String fileName) {
224   - try {
225   - return count(getClassLoader().getResources( fileName )) <= 1;
226   - } catch ( IOException e ) {
227   - e.printStackTrace();
228   - throw new RuntimeException(e);
229   - }
230   - }
231   -
232   - public final void severe(String msg) {
233   - info(ChatColor.RED+"[SEVERE] "+ChatColor.RESET+msg);//because colored won't show [SEVERE] only [INFO] level msgs
234   - }
235   -
236   - public final void info(String msg) {
237   - PluginDescriptionFile descFile = getDescription();
238   - String pluginName = this.getClass().getName();
239   - if (null != descFile) pluginName=descFile.getName();
240   - tellConsole(ChatColor.GREEN+"["+pluginName+"]"+ChatColor.RESET+" "+msg);
241   - }
242   -
243   - public static final void _info(String msg) {
244   - info(BasePlugin.class, msg);
245   - }
246   -
247   - public static final void info(Class cls, String msg) {
248   - String className = cls.getName();//we won't know the difference if we're in main or child plugins (cljminecraft or memorystone) because they both use the same main class to start
249   - tellConsole(ChatColor.DARK_AQUA+"["+className+"]"+ChatColor.RESET+" "+msg);//the color is likely never seen due to not inited color console sender
250   - }
251   -
252   - public final static void tellConsole( String msg ) {
253   - // nvm; find another way to display colored msgs in console without having [INFO] prefix
254   - // there's no other way it's done via ColouredConsoleSender of craftbukkit
255   - // there are only two ways: [INFO]+colors+suffix, or no colors + whichever suffix
256   - ConsoleCommandSender cons = Bukkit.getConsoleSender();
257   - if (null != cons) {
258   - cons.sendMessage( msg );// this will log with [INFO] level
259   - }else {
260   - logger.info(ChatColor.stripColor( msg));
261   - }
262   - }
263   -
264   - public void setSuccessfullyEnabled() {
265   - assert (null == successfullyEnabled) || (false == successfullyEnabled.booleanValue())
266   - :"should not have been already enabled without getting disabled first";
267   -
268   - successfullyEnabled=Boolean.TRUE;
269   - }
270   -
271   - public void removeEnabledState() {
272   - assert ((null == successfullyEnabled) || (true == successfullyEnabled.booleanValue()));
273   - successfullyEnabled=null;
274   - }
275   -
276   - public boolean wasSuccessfullyEnabled() {
277   - return ((null != successfullyEnabled) && (true == successfullyEnabled.booleanValue()));
278   - }
279   -
280   - /**
281   - * if it doesn't return true, then stop() will not be called<br>
282   - * @return true if successfully enabled or false(or thrown exceptions) otherwise<br>
283   - */
284   - public abstract boolean start();//TODO: rename these or the clojure ones just so it's no confusion when reading code(because they have same name)
285   -
286   -
287   - /**
288   - * called only if start() didn't fail (that is: it returned true and didn't throw exceptions)
289   - *
290   - */
291   - public abstract void stop();
292   -
293   -
294   - //synchronized not needed because it's an instance method and each plugin has a different instance
295   - @Override
296   - public final void onEnable() {
297   - assert isEnabled() : "it should be set to enabled before this is called, by bukkit";
298   -
299   - if ( start() ) {
300   - setSuccessfullyEnabled();
301   - }
302   - }
303   -
304   -
305   - @Override
306   - public final void onDisable() {//called only when onEnable didn't fail (if we did the logic right)
307   - assert !isEnabled():"it should be set to disabled before this is called, by bukkit";
308   -
309   - String pluginName = getDescription().getName();
310   - if ( wasSuccessfullyEnabled() ) {
311   - // so it was enabled(successfully prior to this) then we can call to disable it
312   - try {
313   - stop();//return state unused
314   - } finally {
315   - // regardless of the failure to disable, we consider it disabled
316   - removeEnabledState();
317   - }
318   - } else {
319   - info( "did not attempt to disable " + pluginName
320   - + " clojure Plugin because it wasn't successfully enabled previously" );
321   - }
322   - }
323   -}
  1 +package cljminecraft;
  2 +
  3 +import java.io.*;
  4 +import java.net.*;
  5 +import java.nio.charset.*;
  6 +import java.security.*;
  7 +import java.util.*;
  8 +import java.util.logging.*;
  9 +
  10 +import org.bukkit.*;
  11 +import org.bukkit.command.*;
  12 +import org.bukkit.plugin.*;
  13 +import org.bukkit.plugin.java.*;
  14 +
  15 +public abstract class BasePlugin extends JavaPlugin{
  16 + protected final static String selfPluginName=ClojurePlugin.class.getPackage().getName();//"cljminecraft";
  17 +
  18 + public final static Charset UTF8 = Charset.forName("UTF-8");
  19 +
  20 + private final static Logger logger=Bukkit.getLogger();//it would've been the same instance across both main and child plugins
  21 +// private final static Logger logger=Logger.getLogger( "Minecraft" );//this is equivalent to above
  22 +
  23 + //true when `reload` happened OR when this plugin got loaded to an already running server ie. via `plugman load pluginnamehere`
  24 + private static boolean isServerReloaded=(null != Bukkit.getConsoleSender());
  25 +
  26 + //true if onEnable was successful, false or null(not found) if onEnable failed or was never executed
  27 + private Boolean successfullyEnabled=null;//each plugin will have one of these
  28 +
  29 + static {//static initializer block
  30 + //XXX: on server `reload` this gets re-executed
  31 + if ( !isServerReloaded() ) {
  32 + boolean asserts = false;
  33 + assert ( true == ( asserts = true ) );
  34 +
  35 + _info( "assertions are " + ( !asserts ? "NOT " : "" ) + "enabled"
  36 + + ( !asserts ? " (to enable pass jvm option -ea when starting bukkit)" : "" ) );
  37 + }
  38 +
  39 + if (isServerReloaded()) {
  40 + _info("you just `reload`-ed the server OR this plugin got loaded to an already running server ie. via `plugman load "
  41 + +BasePlugin.class.getPackage().getName()+"`");
  42 + //EDIT: there's one variant which may wrongly detect a `reload` if you're using this:
  43 + //if you were running the server then then you just place your plugin in plugins folder and execute a
  44 + //command something like `plugman load yourplugin` - it will detect it as a reload because getConsoleSender
  45 + //is not null at this point. (tested to be true)
  46 + //EDIT2: also note that if the plugin was already running doing `plugman unload it` then `plugman load it`
  47 + //(or even `plugman reload it`) won't cause it to be detected as a `reload`
  48 +
  49 +
  50 + }
  51 +
  52 + //this should only be executed for cljminecraft(the main not any children) plugin, and it is so if children have a depend on cljminecraft
  53 + //bukkit will then make sure cljminecraft is loaded before them
  54 +
  55 + //one time in bukkit lifetime(right?) we set *loader* to the classloader which applies to any future clojure scripts loads
  56 + ClassLoader previous = Thread.currentThread().getContextClassLoader();
  57 + final ClassLoader parentClassLoader = ClojurePlugin.class.getClassLoader();
  58 + Thread.currentThread().setContextClassLoader(parentClassLoader);
  59 + try {
  60 +// if (isServerReloaded()) {
  61 +//// clojure.lang.Var.popThreadBindings();great there is nothing pushed
  62 +// assert !clojure.lang.Compiler.LOADER.isBound();
  63 +// }
  64 + //this happens only once when ClojurePlugin.class gets loaded which actually happens once at bukkit server startup AND
  65 + //also happens every time there's a `reload` command executed
  66 + if (isServerReloaded()) {
  67 + _info("!!!!!!!!!!!!!clojure reinit!!");
  68 + }else{
  69 + _info("!!!!!!!!!!!!!First time clojure init!!");
  70 + }
  71 + System.out.flush();
  72 +
  73 + clojure.lang.DynamicClassLoader newCL = (clojure.lang.DynamicClassLoader)AccessController.doPrivileged( new PrivilegedAction() {
  74 + @Override
  75 + public Object run() {
  76 + assert parentClassLoader == ClojurePlugin.class.getClassLoader();
  77 + assert this.getClass().getClassLoader() == ClojurePlugin.class.getClassLoader();//even though "this" is different
  78 + return new clojure.lang.DynamicClassLoader( parentClassLoader );
  79 + }
  80 + } );
  81 + assert !clojure.lang.Compiler.LOADER.isBound();//wow this really isn't bound even after `reload` also nothing remains pushed
  82 + clojure.lang.Var.pushThreadBindings( clojure.lang.RT.map( clojure.lang.Compiler.LOADER, newCL) );//so this variant is the one
  83 +// System.err.println(clojure.lang.RT.CLOJURE_NS);
  84 +// clojure.lang.Var.intern(clojure.lang.RT.CLOJURE_NS,//just as I thought this variant won't work
  85 +// Symbol.intern("clojure.lang.Compiler/LOADER")//can't intern namespace qualified symbol
  86 +//// clojure.lang.Compiler.LOADER.sym this is actually null because there's no counterpart in clojure? :O I thought it was *loader*
  87 +// , newCL, true);
  88 +// clojure.lang.RT.WARN_ON_REFLECTION;
  89 + //XXX: turn on reflection warnings for all plugins (maybe add/override this in each config.yml
  90 + //XXX: does the above make sense? not sure how
  91 + //no: maybe specify namespace to that *var* - can't intern namespace qualified symbol(I predict)
  92 + clojure.lang.Var.intern(clojure.lang.RT.CLOJURE_NS,
  93 + clojure.lang.Symbol.intern("*warn-on-reflection*")
  94 + //there's no accessible java field from which to get the symbol directly (they are non-public but there in RT nd Compiler classes)
  95 + ,
  96 +// isServerReloaded()?clojure.lang.RT.T:clojure.lang.RT.F
  97 + clojure.lang.RT.F
  98 + , true);
  99 + //the above is equivalent to clojure code: (set! *warn-on-reflection* true)
  100 +
  101 + clojure.lang.Var.intern(clojure.lang.RT.CLOJURE_NS,
  102 + clojure.lang.Symbol.intern("*use-context-classloader*")
  103 + ,clojure.lang.RT.F
  104 + , true);
  105 + }finally{
  106 + Thread.currentThread().setContextClassLoader(previous);
  107 + }
  108 + }
  109 +
  110 + /**
  111 + * @return true when `reload` happened on server<br>
  112 + * OR when this plugin got loaded to an already running server ie. via `plugman load pluginnamehere`
  113 + */
  114 + public final static boolean isServerReloaded() {
  115 + //TODO: find a way to know when it was actually `reload` or our plugin got inited the first time
  116 + //or do we simply give no support for the variant of `plugman load cljminecraft` into an already running server(after just having placed the .jar first time in plugins folder)?
  117 + return isServerReloaded;
  118 + }
  119 +
  120 + @Override
  121 + public final void onLoad() {
  122 + URL jarURL;
  123 + // XXX: executes once for each plugin TODO: investigate what happens if plugman unload and load is used AND server `reload`
  124 + //main concern is if the url already exists is it re-added? if not then is it re-ordered /moved at beginning or end?
  125 + try {
  126 + jarURL = this.getFile().toURI().toURL();
  127 + } catch ( MalformedURLException e ) {
  128 + throw new RuntimeException( "should never happen", e );
  129 + }
  130 +
  131 + info( "loaded jar: " + jarURL );
  132 + assert clojure.lang.Compiler.LOADER.isBound();
  133 + if (!getName().equals(selfPluginName)) {
  134 + //we don't have to add cljminecraft.jar to classpath here
  135 + ( (clojure.lang.DynamicClassLoader)clojure.lang.Compiler.LOADER.deref() ).addURL( jarURL );
  136 + }
  137 + }
  138 +
  139 + public BasePlugin() {
  140 + super();
  141 + //constructor
  142 + info("CONSTRUCTOR");//for "+this.getFile().getAbsoluteFile()); these aren't yet set
  143 + //we don't know yet for which plugin we got constructed
  144 + //XXX: an instance is created of this class for every child plugin (including the main one)
  145 + //TODO: maybe add a test to make sure this didn't change in the future
  146 + }
  147 +
  148 + public static String showClassPath(String prefix, ClassLoader cl){
  149 + _info("=="+prefix+"== For classloader "+cl+" ----------");
  150 + _info(getClassPath(cl));
  151 + _info("=="+prefix+"== ----END---"+cl+" ----------");
  152 + return "";
  153 + }
  154 +
  155 +
  156 + public final static String getClassPath() {
  157 + return getClassPath(Thread.currentThread().getContextClassLoader());
  158 + }
  159 +
  160 + public final static String getClassPath(ClassLoader cl) {
  161 + URL[] urls = ((URLClassLoader)cl).getURLs();
  162 + String cp ="{";
  163 +
  164 + int max = urls.length-1;
  165 + if (max>=0){
  166 + cp+=" ";
  167 + }
  168 + for ( int i = 0; i <= max; i++ ) {
  169 + URL url = urls[i];
  170 + try {
  171 + cp+= url.toURI().toString();
  172 + if(i != max) {
  173 + cp+=", ";
  174 + }else {
  175 + cp+=" ";
  176 + }
  177 + } catch ( URISyntaxException use ) {
  178 + use.printStackTrace();
  179 + throw new RuntimeException(use);
  180 + }
  181 + }
  182 + cp+="}";
  183 + return cp;
  184 + }
  185 +
  186 + protected String showResources(ClassLoader cl, String file1) {
  187 + try {
  188 + Enumeration<URL> urls = cl.getResources( file1 );
  189 + System.out.println("all `"+file1+"` Resources: { ");
  190 + while (urls.hasMoreElements()) {
  191 + System.out.println(urls.nextElement());
  192 + }
  193 + System.out.println(" }");
  194 + } catch ( IOException e ) {
  195 + e.printStackTrace();
  196 + }
  197 + return "";
  198 + }
  199 +
  200 + protected int count(Enumeration e) {
  201 + assert null != e:"you passed null, bug somewhere";
  202 + int count=0;
  203 + while(e.hasMoreElements()) {
  204 + count++;
  205 + e.nextElement();
  206 + }
  207 + return count;
  208 + }
  209 +
  210 + @Override
  211 + public InputStream getResource( String fileName ) {
  212 + //XXX: when a file within the .jar of current plugin is needed then from within clojure or java either call this method or call
  213 + //clojure.lang.RT.getResource(this.getClassLoader(), fileName); where this == plugin instance
  214 + //or else it will get the file from cljminecraft not from memorystone, ie. file name like config.yml which exists in both in same location
  215 + assert isNotMoreThanOneResource(fileName):"more than 1 file with the same name was detected in classpath,"
  216 + +showClassPath("",getClassLoader())
  217 + +showResources( getClassLoader(), fileName )
  218 + +" PLEASE SEE ABOVE ";
  219 +
  220 + return super.getResource( fileName );
  221 + }
  222 +
  223 + protected boolean isNotMoreThanOneResource(String fileName) {
  224 + try {
  225 + return count(getClassLoader().getResources( fileName )) <= 1;
  226 + } catch ( IOException e ) {
  227 + e.printStackTrace();
  228 + throw new RuntimeException(e);
  229 + }
  230 + }
  231 +
  232 + public final void severe(String msg) {
  233 + info(ChatColor.RED+"[SEVERE] "+ChatColor.RESET+msg);//because colored won't show [SEVERE] only [INFO] level msgs
  234 + }
  235 +
  236 + public final void info(String msg) {
  237 + PluginDescriptionFile descFile = getDescription();
  238 + String pluginName = this.getClass().getName();
  239 + if (null != descFile) pluginName=descFile.getName();
  240 + tellConsole(ChatColor.GREEN+"["+pluginName+"]"+ChatColor.RESET+" "+msg);
  241 + }
  242 +
  243 + public static final void _info(String msg) {
  244 + info(BasePlugin.class, msg);
  245 + }
  246 +
  247 + public static final void info(Class cls, String msg) {
  248 + String className = cls.getName();//we won't know the difference if we're in main or child plugins (cljminecraft or memorystone) because they both use the same main class to start
  249 + tellConsole(ChatColor.DARK_AQUA+"["+className+"]"+ChatColor.RESET+" "+msg);//the color is likely never seen due to not inited color console sender
  250 + }
  251 +
  252 + public final static void tellConsole( String msg ) {
  253 + // nvm; find another way to display colored msgs in console without having [INFO] prefix
  254 + // there's no other way it's done via ColouredConsoleSender of craftbukkit
  255 + // there are only two ways: [INFO]+colors+suffix, or no colors + whichever suffix
  256 + ConsoleCommandSender cons = Bukkit.getConsoleSender();
  257 + if (null != cons) {
  258 + cons.sendMessage( msg );// this will log with [INFO] level
  259 + }else {
  260 + logger.info(ChatColor.stripColor( msg));
  261 + }
  262 + }
  263 +
  264 + public void setSuccessfullyEnabled() {
  265 + assert (null == successfullyEnabled) || (false == successfullyEnabled.booleanValue())
  266 + :"should not have been already enabled without getting disabled first";
  267 +
  268 + successfullyEnabled=Boolean.TRUE;
  269 + }
  270 +
  271 + public void removeEnabledState() {
  272 + assert ((null == successfullyEnabled) || (true == successfullyEnabled.booleanValue()));
  273 + successfullyEnabled=null;
  274 + }
  275 +
  276 + public boolean wasSuccessfullyEnabled() {
  277 + return ((null != successfullyEnabled) && (true == successfullyEnabled.booleanValue()));
  278 + }
  279 +
  280 + /**
  281 + * if it doesn't return true, then stop() will not be called<br>
  282 + * @return true if successfully enabled or false(or thrown exceptions) otherwise<br>
  283 + */
  284 + public abstract boolean start();//TODO: rename these or the clojure ones just so it's no confusion when reading code(because they have same name)
  285 +
  286 +
  287 + /**
  288 + * called only if start() didn't fail (that is: it returned true and didn't throw exceptions)
  289 + *
  290 + */
  291 + public abstract void stop();
  292 +
  293 +
  294 + //synchronized not needed because it's an instance method and each plugin has a different instance
  295 + @Override
  296 + public final void onEnable() {
  297 + assert isEnabled() : "it should be set to enabled before this is called, by bukkit";
  298 +
  299 + if ( start() ) {
  300 + setSuccessfullyEnabled();
  301 + }
  302 + }
  303 +
  304 +
  305 + @Override
  306 + public final void onDisable() {//called only when onEnable didn't fail (if we did the logic right)
  307 + assert !isEnabled():"it should be set to disabled before this is called, by bukkit";
  308 +
  309 + String pluginName = getDescription().getName();
  310 + if ( wasSuccessfullyEnabled() ) {
  311 + // so it was enabled(successfully prior to this) then we can call to disable it
  312 + try {
  313 + stop();//return state unused
  314 + } finally {
  315 + // regardless of the failure to disable, we consider it disabled
  316 + removeEnabledState();
  317 + }
  318 + } else {
  319 + info( "did not attempt to disable " + pluginName
  320 + + " clojure Plugin because it wasn't successfully enabled previously" );
  321 + }
  322 + }
  323 +}
18 lein_into_repo.bat
... ... @@ -1,10 +1,10 @@
1   -@rem needs this lein.bat https://github.com/technomancy/leiningen/blob/master/bin/lein.bat
2   - @rem put it in PATH
3   -
4   -@echo off
5   -
6   -rem every time you make a change in this project you should run this .bat file to put the updated .jar into the local repository
7   -
8   -set JAVA_CMD="c:\program files\java\jdk1.6.0_31\bin\java.exe"
9   -call lein install
  1 +@rem needs this lein.bat https://github.com/technomancy/leiningen/blob/master/bin/lein.bat
  2 + @rem put it in PATH
  3 +
  4 +@echo off
  5 +
  6 +rem every time you make a change in this project you should run this .bat file to put the updated .jar into the local repository
  7 +
  8 +set JAVA_CMD="c:\program files\java\jdk1.6.0_31\bin\java.exe"
  9 +call lein install
10 10 if NOT "%1" == "nopause" @pause
32 lein_uberjar.bat
... ... @@ -1,16 +1,16 @@
1   -@rem needs this lein.bat https://github.com/technomancy/leiningen/blob/master/bin/lein.bat
2   - @rem put it in PATH
3   -
4   -@echo off
5   -set JAVA_CMD="c:\program files\java\jdk1.6.0_31\bin\java.exe"
6   -call lein uberjar
7   -
8   -set deployDIR=deploy
9   -rem %deployDIR% is a folder link to your running server's plugin folder
10   -rem you make it by running this cmd: mklink /d deploy c:\craftbukkit\plugins\
11   -if EXIST "%deployDIR%" (
12   - move target\cljminecraft-*standalone.jar %deployDIR%\cljminecraft.jar
13   - if ERRORLEVEL 1 echo FAILED, make sure bukkit isn't running (so the plugin .jar isn't in locked)
14   - )
15   -
16   -if NOT "%1" == "nopause" @pause
  1 +@rem needs this lein.bat https://github.com/technomancy/leiningen/blob/master/bin/lein.bat
  2 + @rem put it in PATH
  3 +
  4 +@echo off
  5 +set JAVA_CMD="c:\program files\java\jdk1.6.0_31\bin\java.exe"
  6 +call lein uberjar
  7 +
  8 +set deployDIR=deploy
  9 +rem %deployDIR% is a folder link to your running server's plugin folder
  10 +rem you make it by running this cmd: mklink /d deploy c:\craftbukkit\plugins\
  11 +if EXIST "%deployDIR%" (
  12 + move target\cljminecraft-*standalone.jar %deployDIR%\cljminecraft.jar
  13 + if ERRORLEVEL 1 echo FAILED, make sure bukkit isn't running (so the plugin .jar isn't in locked)
  14 + )
  15 +
  16 +if NOT "%1" == "nopause" @pause
12 on_changed.bat
... ... @@ -1,6 +1,6 @@
1   -call lein_uberjar.bat nopause
2   -call lein_into_repo.bat nopause
3   -
4   -
5   -if NOT "%1" == "nopause" @pause
6   -
  1 +call lein_uberjar.bat nopause
  2 +call lein_into_repo.bat nopause
  3 +
  4 +
  5 +if NOT "%1" == "nopause" @pause
  6 +
15 src/cljminecraft/blocks.clj
@@ -213,6 +213,21 @@
213 213 ctx [mark]
214 214 (update-in ctx [:marks mark] {}))
215 215
  216 +
  217 +(defn line
  218 + "This returns a set of points for a line"
  219 + [xt yt zt]
  220 + (if (= [xt yt zt] [0 0 0])
  221 + '([0 0 0])
  222 + (let [q (max (Math/abs xt) (Math/abs yt) (Math/abs zt))
  223 + m (/ yt q)
  224 + n (/ zt q)
  225 + o (/ xt q)]
  226 + (for [qi (range q)]
  227 + [(Math/round (double (* o qi)))
  228 + (Math/round (double (* m qi)))
  229 + (Math/round (double (* n qi)))]))))
  230 +
216 231 ;; to be finished......
217 232 (defaction line-to-mark
218 233 "Draw a line directly to a given mark from current point"
4 src/cljminecraft/logging.clj
@@ -12,5 +12,5 @@
12 12
13 13 (defmacro bug
14 14 "as in bug in code/coding when this is reached"
15   - [fmt & args]
16   - `(.sendMessage (Bukkit/getConsoleSender) (format ~(str "[BUG]" ChatColor/RED (.getName *ns*) ChatColor/RESET ":" ChatColor/BLUE (:line (meta &form)) ChatColor/RESET " - " fmt) ~@args)))
  15 + [fmt & args]
  16 + `(.sendMessage (Bukkit/getConsoleSender) (format ~(str "[BUG]" ChatColor/RED (.getName *ns*) ChatColor/RESET ":" ChatColor/BLUE (:line (meta &form)) ChatColor/RESET " - " fmt) ~@args)))
2  src/cljminecraft/util.clj
... ... @@ -1,7 +1,7 @@
1 1 (ns cljminecraft.util
2 2 (:require [clojure.set :as set])
3 3 (:require [cljminecraft.logging :as log])
4   - (:import (java.net ServerSocket InetSocketAddress))
  4 + (:import (java.net ServerSocket InetSocketAddress))
5 5 (:import (java.io IOException))
6 6 )
7 7

0 comments on commit 2be38d6

Please sign in to comment.
Something went wrong with that request. Please try again.