Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Bukkit4Clojure
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mariell
Bukkit4Clojure
Commits
7af374bd
Commit
7af374bd
authored
7 years ago
by
Mariell
Browse files
Options
Downloads
Patches
Plain Diff
Finalised params in methods and implemented commands
parent
bb0c1048
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/com/coalesce/bukkitforclojure/Main.java
+28
-3
28 additions, 3 deletions
src/com/coalesce/bukkitforclojure/Main.java
with
28 additions
and
3 deletions
src/com/coalesce/bukkitforclojure/Main.java
+
28
−
3
View file @
7af374bd
...
@@ -2,6 +2,9 @@ package com.coalesce.bukkitforclojure;
...
@@ -2,6 +2,9 @@ package com.coalesce.bukkitforclojure;
import
clojure.java.api.Clojure
;
import
clojure.java.api.Clojure
;
import
clojure.lang.IFn
;
import
clojure.lang.IFn
;
import
org.bukkit.command.Command
;
import
org.bukkit.command.CommandSender
;
import
org.bukkit.command.PluginCommand
;
import
org.bukkit.configuration.file.YamlConfiguration
;
import
org.bukkit.configuration.file.YamlConfiguration
;
import
org.bukkit.event.Event
;
import
org.bukkit.event.Event
;
import
org.bukkit.event.EventPriority
;
import
org.bukkit.event.EventPriority
;
...
@@ -25,6 +28,7 @@ public class Main extends JavaPlugin {
...
@@ -25,6 +28,7 @@ public class Main extends JavaPlugin {
private
final
IFn
require
=
Clojure
.
var
(
"clojure.core"
,
"require"
);
private
final
IFn
require
=
Clojure
.
var
(
"clojure.core"
,
"require"
);
private
final
Map
<
Class
<?
extends
Event
>,
Set
<
IFn
>>
events
=
new
HashMap
<>();
private
final
Map
<
Class
<?
extends
Event
>,
Set
<
IFn
>>
events
=
new
HashMap
<>();
private
final
EventExecutor
executor
=
(
listener
,
event
)
->
fireEvent
(
event
);
private
final
EventExecutor
executor
=
(
listener
,
event
)
->
fireEvent
(
event
);
private
final
Map
<
Command
,
IFn
>
commands
=
new
HashMap
<>();
@Override
@Override
public
void
onLoad
()
{
public
void
onLoad
()
{
...
@@ -68,12 +72,12 @@ public class Main extends JavaPlugin {
...
@@ -68,12 +72,12 @@ public class Main extends JavaPlugin {
}
}
}
}
public
void
registerEvent
(
Class
<?
extends
Event
>
event
,
EventPriority
priority
,
IFn
method
)
{
public
void
registerEvent
(
final
Class
<?
extends
Event
>
event
,
final
EventPriority
priority
,
final
IFn
method
)
{
registerEvent
(
event
,
priority
,
method
,
false
);
registerEvent
(
event
,
priority
,
method
,
false
);
}
}
@SuppressWarnings
({
"WeakerAccess"
,
"SameParameterValue"
})
@SuppressWarnings
({
"WeakerAccess"
,
"SameParameterValue"
})
public
void
registerEvent
(
Class
<?
extends
Event
>
event
,
EventPriority
priority
,
IFn
method
,
boolean
ignoreCancelled
)
{
public
void
registerEvent
(
final
Class
<?
extends
Event
>
event
,
final
EventPriority
priority
,
final
IFn
method
,
final
boolean
ignoreCancelled
)
{
Set
<
IFn
>
methods
=
events
.
getOrDefault
(
event
,
new
HashSet
<>());
Set
<
IFn
>
methods
=
events
.
getOrDefault
(
event
,
new
HashSet
<>());
methods
.
add
(
method
);
methods
.
add
(
method
);
events
.
put
(
event
,
methods
);
events
.
put
(
event
,
methods
);
...
@@ -81,7 +85,7 @@ public class Main extends JavaPlugin {
...
@@ -81,7 +85,7 @@ public class Main extends JavaPlugin {
},
priority
,
executor
,
this
,
ignoreCancelled
);
},
priority
,
executor
,
this
,
ignoreCancelled
);
}
}
private
<
T
extends
Event
>
void
fireEvent
(
T
event
)
{
private
<
T
extends
Event
>
void
fireEvent
(
final
T
event
)
{
Set
<
IFn
>
methods
=
events
.
get
(
event
.
getClass
());
Set
<
IFn
>
methods
=
events
.
get
(
event
.
getClass
());
if
(
methods
==
null
)
{
if
(
methods
==
null
)
{
return
;
// No events have been registered from the plugin, thus no need to fire any.
return
;
// No events have been registered from the plugin, thus no need to fire any.
...
@@ -89,6 +93,27 @@ public class Main extends JavaPlugin {
...
@@ -89,6 +93,27 @@ public class Main extends JavaPlugin {
methods
.
forEach
(
it
->
it
.
invoke
(
event
));
methods
.
forEach
(
it
->
it
.
invoke
(
event
));
}
}
public
void
registerCommand
(
final
String
name
,
final
IFn
method
)
{
PluginCommand
command
=
getCommand
(
name
);
command
.
setExecutor
(
this
);
commands
.
put
(
command
,
method
);
}
@Override
public
boolean
onCommand
(
CommandSender
sender
,
Command
cmd
,
String
label
,
String
[]
args
)
{
IFn
command
=
commands
.
get
(
cmd
);
if
(
command
==
null
)
{
return
true
;
}
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.
}
return
true
;
}
public
static
Logger
sLogger
()
{
public
static
Logger
sLogger
()
{
return
logger
;
return
logger
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment