Skip to content

Commit

Permalink
Refactor and add more conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
Camotoy committed Jan 21, 2021
1 parent 9415399 commit 74df0bf
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 30 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.geysermc</groupId>
<groupId>com.github.camotoy</groupId>
<artifactId>floodgate-skript</artifactId>
<version>1.2-SNAPSHOT</version>
<version>2.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Floodgate-Skript</name>
Expand Down Expand Up @@ -71,8 +71,8 @@
<url>http://maven.sk89q.com/repo/</url>
</repository>
<repository>
<id>nukkitx-snapshot</id>
<url>https://repo.nukkitx.com/maven-snapshots/</url>
<id>opencollab-snapshot</id>
<url>https://ci.opencollab.dev/maven-snapshots/</url>
</repository>
<repository>
<id>jitpack.io</id>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.geysermc.floodgateskript;
package com.github.camotoy.floodgate_skript;

import ch.njol.skript.Skript;
import ch.njol.skript.SkriptAddon;
Expand All @@ -7,7 +7,6 @@

import java.io.IOException;


public final class FloodgateSkript extends JavaPlugin {

private static SkriptAddon addonInstance;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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")
Expand All @@ -24,21 +24,22 @@ public class IsFloodgatePlayer extends Condition {
private Expression<Player> 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<Player>) 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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> {

static {
Skript.registerExpression(GetBedrockLocale.class, String.class, ExpressionType.COMBINED,
"[the] [bedrock] (locale|language) of [the] [floodgate] %player%");
}

private Expression<Player> 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<? extends String> 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<Player>) exprs[0];
return true;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<String> {

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> 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"};
Expand All @@ -41,17 +44,17 @@ public boolean isSingle() {
}

@Override
public Class<? extends String> getReturnType() {
public @NotNull Class<? extends String> 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<Player>) exprs[0];
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> {

static {
Skript.registerExpression(GetBedrockVersion.class, String.class, ExpressionType.COMBINED,
"[the] [bedrock] version of [the] [floodgate] %player%");
}

private Expression<Player> 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<? extends String> 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<Player>) exprs[0];
return true;
}
}
6 changes: 3 additions & 3 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -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]

0 comments on commit 74df0bf

Please sign in to comment.