diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..09429de --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020-2021 Camotoy + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index 0b3db5e..d66ad11 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,21 @@ if player is from floodgate: Finding a player's platform: ``` -set {_device} to device of player +set {_device} to device of floodgate player +``` + +Finding a player's version: + +``` +set {_version} to version of floodgate player +``` + +Finding a player's language/locale: + +``` +set {_language} to language of floodgate player ``` *Compiling:* Clone the repo and run `mvn clean install` in the source directory. -Discord server: https://discord.gg/jNNC4CZtsN +Camotoy's Discord server: https://discord.gg/jNNC4CZtsN diff --git a/pom.xml b/pom.xml index 859e5c7..2c5c7d5 100644 --- a/pom.xml +++ b/pom.xml @@ -4,9 +4,9 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.geysermc + com.github.camotoy floodgate-skript - 1.2-SNAPSHOT + 2.0-SNAPSHOT jar Floodgate-Skript @@ -71,8 +71,8 @@ http://maven.sk89q.com/repo/ - nukkitx-snapshot - https://repo.nukkitx.com/maven-snapshots/ + opencollab-snapshot + https://ci.opencollab.dev/maven-snapshots/ jitpack.io diff --git a/src/main/java/org/geysermc/floodgateskript/FloodgateSkript.java b/src/main/java/com/github/camotoy/floodgate_skript/FloodgateSkript.java similarity index 85% rename from src/main/java/org/geysermc/floodgateskript/FloodgateSkript.java rename to src/main/java/com/github/camotoy/floodgate_skript/FloodgateSkript.java index 6159612..0ada7fe 100644 --- a/src/main/java/org/geysermc/floodgateskript/FloodgateSkript.java +++ b/src/main/java/com/github/camotoy/floodgate_skript/FloodgateSkript.java @@ -1,4 +1,4 @@ -package org.geysermc.floodgateskript; +package com.github.camotoy.floodgate_skript; import ch.njol.skript.Skript; import ch.njol.skript.SkriptAddon; @@ -7,7 +7,6 @@ import java.io.IOException; - public final class FloodgateSkript extends JavaPlugin { private static SkriptAddon addonInstance; @@ -17,7 +16,7 @@ public void onEnable() { if (Bukkit.getPluginManager().getPlugin("floodgate-bukkit") != null && Bukkit.getPluginManager().getPlugin("Skript") != null) { addonInstance = Skript.registerAddon(this); try { - addonInstance.loadClasses("org.geysermc.floodgateskript", "expressions", "conditions"); + addonInstance.loadClasses("com.github.camotoy.floodgate_skript", "expressions", "conditions"); } catch (IOException e) { getLogger().warning("IOException caught. Disabling plugin."); getServer().getPluginManager().disablePlugin(this); diff --git a/src/main/java/org/geysermc/floodgateskript/conditions/IsFloodgatePlayer.java b/src/main/java/com/github/camotoy/floodgate_skript/conditions/IsFloodgatePlayer.java similarity index 65% rename from src/main/java/org/geysermc/floodgateskript/conditions/IsFloodgatePlayer.java rename to src/main/java/com/github/camotoy/floodgate_skript/conditions/IsFloodgatePlayer.java index 85f286e..c2ee60d 100644 --- a/src/main/java/org/geysermc/floodgateskript/conditions/IsFloodgatePlayer.java +++ b/src/main/java/com/github/camotoy/floodgate_skript/conditions/IsFloodgatePlayer.java @@ -1,5 +1,4 @@ -package org.geysermc.floodgateskript.conditions; - +package com.github.camotoy.floodgate_skript.conditions; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Name; @@ -11,6 +10,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.geysermc.floodgate.FloodgateAPI; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @Name("Is from Floodgate") @@ -24,21 +24,22 @@ public class IsFloodgatePlayer extends Condition { private Expression player; @Override - public String toString(@Nullable Event e, boolean debug) { + public @NotNull String toString(@Nullable Event e, boolean debug) { return "Is player from Floodgate: " + player.toString(e, debug); } @Override - public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { + public boolean init(Expression @NotNull [] exprs, int matchedPattern, @NotNull Kleenean isDelayed, SkriptParser.ParseResult parseResult) { player = (Expression) exprs[0]; setNegated(parseResult.mark == 1); return true; } @Override - public boolean check(Event e) { - if (player.getSingle(e) != null) { - return (FloodgateAPI.isBedrockPlayer(player.getSingle(e))) == isNegated(); + public boolean check(@NotNull Event e) { + Player bukkitPlayer = player.getSingle(e); + if (bukkitPlayer != null) { + return (FloodgateAPI.isBedrockPlayer(bukkitPlayer)) == isNegated(); } return isNegated(); } diff --git a/src/main/java/com/github/camotoy/floodgate_skript/expressions/GetBedrockLocale.java b/src/main/java/com/github/camotoy/floodgate_skript/expressions/GetBedrockLocale.java new file mode 100644 index 0000000..31c8046 --- /dev/null +++ b/src/main/java/com/github/camotoy/floodgate_skript/expressions/GetBedrockLocale.java @@ -0,0 +1,61 @@ +package com.github.camotoy.floodgate_skript.expressions; + +import ch.njol.skript.Skript; +import ch.njol.skript.doc.Description; +import ch.njol.skript.doc.Name; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.ExpressionType; +import ch.njol.skript.lang.SkriptParser; +import ch.njol.skript.lang.util.SimpleExpression; +import ch.njol.util.Kleenean; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.geysermc.floodgate.FloodgateAPI; +import org.geysermc.floodgate.FloodgatePlayer; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +@Name("get Bedrock locale") +@Description("Returns the Bedrock language of the client") +public class GetBedrockLocale extends SimpleExpression { + + static { + Skript.registerExpression(GetBedrockLocale.class, String.class, ExpressionType.COMBINED, + "[the] [bedrock] (locale|language) of [the] [floodgate] %player%"); + } + + private Expression player; + + @Override + protected String[] get(@NotNull Event e) { + Player bukkitPlayer = player.getSingle(e); + if (bukkitPlayer != null) { + FloodgatePlayer floodgatePlayer = FloodgateAPI.getPlayer(bukkitPlayer); + if (floodgatePlayer != null) { + return new String[] {floodgatePlayer.getLanguageCode()}; + } + } + return new String[] {"Java"}; + } + + @Override + public boolean isSingle() { + return true; + } + + @Override + public @NotNull Class getReturnType() { + return String.class; + } + + @Override + public @NotNull String toString(@Nullable Event e, boolean debug) { + return "Get Floodgate player's language: " + player.toString(e, debug); + } + + @Override + public boolean init(Expression @NotNull [] exprs, int matchedPattern, @NotNull Kleenean isDelayed, SkriptParser.@NotNull ParseResult parseResult) { + player = (Expression) exprs[0]; + return true; + } +} diff --git a/src/main/java/org/geysermc/floodgateskript/expressions/GetBedrockPlatform.java b/src/main/java/com/github/camotoy/floodgate_skript/expressions/GetBedrockPlatform.java similarity index 54% rename from src/main/java/org/geysermc/floodgateskript/expressions/GetBedrockPlatform.java rename to src/main/java/com/github/camotoy/floodgate_skript/expressions/GetBedrockPlatform.java index 5d6a4ed..e2aef9a 100644 --- a/src/main/java/org/geysermc/floodgateskript/expressions/GetBedrockPlatform.java +++ b/src/main/java/com/github/camotoy/floodgate_skript/expressions/GetBedrockPlatform.java @@ -1,4 +1,4 @@ -package org.geysermc.floodgateskript.expressions; +package com.github.camotoy.floodgate_skript.expressions; import ch.njol.skript.Skript; import ch.njol.skript.doc.Description; @@ -11,25 +11,28 @@ import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.geysermc.floodgate.FloodgateAPI; +import org.geysermc.floodgate.FloodgatePlayer; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @Name("get Bedrock platform") -@Description("Get the device that the Floodgate player is playing on") +@Description("Returns the device that the Floodgate player is playing on") public class GetBedrockPlatform extends SimpleExpression { static { Skript.registerExpression(GetBedrockPlatform.class, String.class, ExpressionType.COMBINED, - "[the] [bedrock] (platform|device) of [the] %player%"); + "[the] [bedrock] (platform|device) of [the] [floodgate] %player%"); } private Expression player; - @Nullable @Override - protected String[] get(Event e) { - if (player.getSingle(e) != null) { - if (FloodgateAPI.isBedrockPlayer(player.getSingle(e))) { - return new String[] {FloodgateAPI.getPlayer(player.getSingle(e)).getDeviceOS().toString()}; + protected String[] get(@NotNull Event e) { + Player bukkitPlayer = player.getSingle(e); + if (bukkitPlayer != null) { + FloodgatePlayer floodgatePlayer = FloodgateAPI.getPlayer(bukkitPlayer); + if (floodgatePlayer != null) { + return new String[] {floodgatePlayer.getDeviceOS().toString()}; } } return new String[] {"Java"}; @@ -41,17 +44,17 @@ public boolean isSingle() { } @Override - public Class getReturnType() { + public @NotNull Class getReturnType() { return String.class; } @Override - public String toString(@Nullable Event e, boolean debug) { + public @NotNull String toString(@Nullable Event e, boolean debug) { return "Get Floodgate player's platform: " + player.toString(e, debug); } @Override - public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { + public boolean init(Expression @NotNull [] exprs, int matchedPattern, @NotNull Kleenean isDelayed, SkriptParser.@NotNull ParseResult parseResult) { player = (Expression) exprs[0]; return true; } diff --git a/src/main/java/com/github/camotoy/floodgate_skript/expressions/GetBedrockVersion.java b/src/main/java/com/github/camotoy/floodgate_skript/expressions/GetBedrockVersion.java new file mode 100644 index 0000000..1cf2a2e --- /dev/null +++ b/src/main/java/com/github/camotoy/floodgate_skript/expressions/GetBedrockVersion.java @@ -0,0 +1,61 @@ +package com.github.camotoy.floodgate_skript.expressions; + +import ch.njol.skript.Skript; +import ch.njol.skript.doc.Description; +import ch.njol.skript.doc.Name; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.ExpressionType; +import ch.njol.skript.lang.SkriptParser; +import ch.njol.skript.lang.util.SimpleExpression; +import ch.njol.util.Kleenean; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.geysermc.floodgate.FloodgateAPI; +import org.geysermc.floodgate.FloodgatePlayer; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +@Name("get Bedrock version") +@Description("Returns the Bedrock version that the client is playing on") +public class GetBedrockVersion extends SimpleExpression { + + static { + Skript.registerExpression(GetBedrockVersion.class, String.class, ExpressionType.COMBINED, + "[the] [bedrock] version of [the] [floodgate] %player%"); + } + + private Expression player; + + @Override + protected String[] get(@NotNull Event e) { + Player bukkitPlayer = player.getSingle(e); + if (bukkitPlayer != null) { + FloodgatePlayer floodgatePlayer = FloodgateAPI.getPlayer(bukkitPlayer); + if (floodgatePlayer != null) { + return new String[] {floodgatePlayer.getVersion()}; + } + } + return new String[] {"Java"}; + } + + @Override + public boolean isSingle() { + return true; + } + + @Override + public @NotNull Class getReturnType() { + return String.class; + } + + @Override + public @NotNull String toString(@Nullable Event e, boolean debug) { + return "Get Floodgate player's Bedrock version: " + player.toString(e, debug); + } + + @Override + public boolean init(Expression @NotNull [] exprs, int matchedPattern, @NotNull Kleenean isDelayed, SkriptParser.@NotNull ParseResult parseResult) { + player = (Expression) exprs[0]; + return true; + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index a952b41..c7fbdf0 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,7 +1,7 @@ name: Floodgate-Skript version: ${project.version} -main: org.geysermc.floodgateskript.FloodgateSkript +main: com.github.camotoy.floodgate_skript.FloodgateSkript api-version: 1.15 -authors: [GeyserMC] +authors: [Camotoy] depend: [floodgate-bukkit, Skript] -softdepend: [Geyser-Bukkit] +softdepend: [Geyser-Spigot]