-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
258 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
rootProject.name = 'ServerKeyboardBridge Plugin' | ||
rootProject.name = 'ServerKeyboardBridge_Plugin' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
plugin/src/main/java/fr/anarchick/skb/skript/EffRegisterKeyEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package fr.anarchick.skb.skript; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.doc.Description; | ||
import ch.njol.skript.doc.Examples; | ||
import ch.njol.skript.doc.Name; | ||
import ch.njol.skript.doc.Since; | ||
import ch.njol.skript.lang.Effect; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.SkriptParser; | ||
import ch.njol.util.Kleenean; | ||
import fr.anarchick.skb.ServerKeyboardBridge; | ||
import fr.anarchick.skb.core.KeyEntry; | ||
import org.bukkit.NamespacedKey; | ||
import org.bukkit.event.Event; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
@Name("Register Key Entry") | ||
@Description({ | ||
"Register a key entry with a unique id, a name, a description, a category and a keycode", | ||
"the id must be unique and is used to identify the key entry", | ||
"the id must be lowercase and contain only letters, numbers and underscores", | ||
"keycode can be found here : https://www.glfw.org/docs/latest/group__keys.html" | ||
}) | ||
@Examples({ | ||
"on load:", | ||
"\tregister key entry with id \"horse\" named \"spawn your horse\", category \"page 1\" and keycode 72", | ||
|
||
}) | ||
@Since("1.1.0") | ||
public class EffRegisterKeyEntry extends Effect { | ||
|
||
private static final String pattern = "register key entry with id %string% named %string%, [description %-string%,] category %string% and keycode %number%"; | ||
|
||
static { | ||
Skript.registerEffect(EffRegisterKeyEntry.class, pattern); | ||
} | ||
|
||
private Expression<String> exprId; | ||
private Expression<String> exprName; | ||
private Expression<String> exprDescription; | ||
private Expression<String> exprCategory; | ||
private Expression<Number> exprKeycode; | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public boolean init(Expression<?>[] expr, int matchedPattern, @NotNull Kleenean isDelayed, SkriptParser.@NotNull ParseResult parseResult) { | ||
exprId = (Expression<String>) expr[0]; | ||
exprName = (Expression<String>) expr[1]; | ||
exprDescription = (Expression<String>) expr[2]; | ||
exprCategory = (Expression<String>) expr[3]; | ||
exprKeycode = (Expression<Number>) expr[4]; | ||
return true; | ||
} | ||
|
||
@Override | ||
protected void execute(@NotNull Event event) { | ||
String id = exprId.getSingle(event).toLowerCase(); | ||
String name = exprName.getSingle(event); | ||
String description = (exprDescription == null) ? "" : exprDescription.getSingle(event); | ||
String category = exprCategory.getSingle(event); | ||
Number keycodeNumber = exprKeycode.getSingle(event); | ||
short keycode = keycodeNumber.shortValue(); | ||
|
||
NamespacedKey namespacedKey = new NamespacedKey(ServerKeyboardBridge.getInstance(), id); | ||
KeyEntry keyEntry = new KeyEntry(namespacedKey, name, description, category, keycode); | ||
ServerKeyboardBridge.getInstance().registerKey(keyEntry); | ||
} | ||
|
||
@Override | ||
public @NotNull String toString(@Nullable Event event, boolean debug) { | ||
if (event == null || exprId == null || exprName == null || exprCategory == null || exprKeycode == null) { | ||
return pattern; | ||
} | ||
|
||
return String.format("register key entry with id %s named %s, description %s, category %s and keycode %s", | ||
exprId.toString(event, debug), | ||
exprName.toString(event, debug), | ||
exprDescription.toString(event, debug), | ||
exprCategory.toString(event, debug), | ||
exprKeycode.toString(event, debug) | ||
); | ||
} | ||
|
||
} |
84 changes: 84 additions & 0 deletions
84
plugin/src/main/java/fr/anarchick/skb/skript/EvtKeyEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package fr.anarchick.skb.skript; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.lang.Literal; | ||
import ch.njol.skript.lang.SkriptEvent; | ||
import ch.njol.skript.lang.SkriptParser; | ||
import ch.njol.skript.registrations.EventValues; | ||
import ch.njol.skript.util.Getter; | ||
import fr.anarchick.skb.ServerKeyboardBridge; | ||
import fr.anarchick.skb.event.KeyEvent; | ||
import org.bukkit.NamespacedKey; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.Event; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class EvtKeyEvent extends SkriptEvent { | ||
|
||
private static final String[] patterns = new String[] { | ||
"key pressed with id %string%", | ||
"key release with id %string%" | ||
}; | ||
|
||
static { | ||
Skript.registerEvent("Key Pressed", EvtKeyEvent.class, KeyEvent.class, patterns) | ||
.description("Called when the player press his keyboard key or mouse key. ServerKeyboardBridge Mod MUST be installed on the client. You can listen every input with a limit of 20 custom key entries.") | ||
.examples("on key pressed with id \"horse\":", | ||
"\tset {_playerIsInGui} to event-boolean\n", | ||
"\tif {_playerIsInGui} is false:\n", | ||
"\t\tspawn an horse at event-player") | ||
.since("1.1.0"); | ||
EventValues.registerEventValue(KeyEvent.class, Player.class, new Getter<>() { | ||
@Override | ||
@NotNull | ||
public Player get(KeyEvent event) { | ||
return event.getPlayer(); | ||
} | ||
}, 0); | ||
EventValues.registerEventValue(KeyEvent.class, Boolean.class, new Getter<>() { | ||
@Override | ||
@NotNull | ||
public Boolean get(KeyEvent event) { | ||
return event.isInGUI(); | ||
} | ||
}, 0); | ||
} | ||
|
||
private int matchedPattern; | ||
private Literal<String> litId; | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public boolean init(Literal<?>[] args, int matchedPattern, SkriptParser.@NotNull ParseResult parseResult) { | ||
this.matchedPattern = matchedPattern; | ||
litId = (Literal<String>) args[0]; | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean check(@NotNull Event event) { | ||
if (event instanceof KeyEvent keyEvent) { | ||
|
||
if (keyEvent.isPressed() != (matchedPattern == 0)) { | ||
return false; | ||
} | ||
|
||
String id = litId.getSingle(event); | ||
NamespacedKey namespacedKey = keyEvent.getKey(); | ||
return namespacedKey.namespace().equalsIgnoreCase(ServerKeyboardBridge.getInstance().getName()) && namespacedKey.getKey().equalsIgnoreCase(id); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public @NotNull String toString(@Nullable Event event, boolean debug) { | ||
String pattern = (matchedPattern == 0) ? patterns[0] : patterns[1]; | ||
|
||
if (event == null) { | ||
return pattern; | ||
} | ||
|
||
return String.format(pattern.replace("%string%", "%s"), litId.toString(event, debug)); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
plugin/src/main/java/fr/anarchick/skb/skript/EvtSkbJoin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package fr.anarchick.skb.skript; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.lang.util.SimpleEvent; | ||
import ch.njol.skript.registrations.EventValues; | ||
import ch.njol.skript.util.Getter; | ||
import fr.anarchick.skb.event.SkbJoinEvent; | ||
import org.bukkit.entity.Player; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class EvtSkbJoin { | ||
|
||
private static final String pattern = "(ServerKeyboardBridge|SKB) player (login|logging in|join[ing])"; | ||
|
||
static { | ||
Skript.registerEvent("ServerKeyboardBridge Join", SimpleEvent.class, SkbJoinEvent.class, pattern) | ||
.description("Called when the player joins the server with the ServerKeyboardBridge Mod installed. You can get the client mod version with event-string.") | ||
.examples("on SKB player join:", | ||
" message \"client version : %event-string%\"") | ||
.since("1.1.0"); | ||
EventValues.registerEventValue(SkbJoinEvent.class, Player.class, new Getter<>() { | ||
@Override | ||
@NotNull | ||
public Player get(SkbJoinEvent event) { | ||
return event.getPlayer(); | ||
} | ||
}, 0); | ||
EventValues.registerEventValue(SkbJoinEvent.class, String.class, new Getter<>() { | ||
@Override | ||
@NotNull | ||
public String get(SkbJoinEvent event) { | ||
return event.getVersion(); | ||
} | ||
}, 0); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters