From bdd547309a63892521ce58224b8b75726c365fb7 Mon Sep 17 00:00:00 2001 From: ProSavage Date: Wed, 26 Dec 2018 19:22:06 -0600 Subject: [PATCH] First Wave of Skript Support. --- .../massivecraft/Factions/maven-metadata.xml | 7 +- .../Factions/maven-metadata.xml.md5 | 2 +- .../Factions/maven-metadata.xml.sha1 | 2 +- pom.xml | 23 ++++- .../massivecraft/factions/SavageFactions.java | 19 ++++ .../massivecraft/factions/cmd/CmdDisband.java | 1 + .../player/PlayerFactionExpression.java | 95 +++++++++++++++++++ .../player/PlayerPowerExpression.java | 93 ++++++++++++++++++ .../player/PlayerRoleExpression.java | 90 ++++++++++++++++++ src/main/resources/plugin.yml | 2 +- 10 files changed, 327 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/massivecraft/factions/skript/expressions/player/PlayerFactionExpression.java create mode 100644 src/main/java/com/massivecraft/factions/skript/expressions/player/PlayerPowerExpression.java create mode 100644 src/main/java/com/massivecraft/factions/skript/expressions/player/PlayerRoleExpression.java diff --git a/mvn-repo/com/massivecraft/Factions/maven-metadata.xml b/mvn-repo/com/massivecraft/Factions/maven-metadata.xml index 82d83dd7..787f6648 100644 --- a/mvn-repo/com/massivecraft/Factions/maven-metadata.xml +++ b/mvn-repo/com/massivecraft/Factions/maven-metadata.xml @@ -3,12 +3,13 @@ com.massivecraft Factions - 1.6.9.5-U0.2.1-RC-1.5-STABLE + 1.6.9.5-U0.2.1-RC-1.6-BETA 1.6.9.5-U0.2.1-RC-1.5-BETA 1.6.9.5-U0.2.1-RC-1.5-BETA-2 - 1.6.9.5-U0.2.1-RC-1.5-STABLE + 1.6.9.5-U0.2.1-RC-1.5-STABLE + 1.6.9.5-U0.2.1-RC-1.6-BETA - 20181222234636 + 20181227012130 diff --git a/mvn-repo/com/massivecraft/Factions/maven-metadata.xml.md5 b/mvn-repo/com/massivecraft/Factions/maven-metadata.xml.md5 index 2a0689bb..ec36a470 100644 --- a/mvn-repo/com/massivecraft/Factions/maven-metadata.xml.md5 +++ b/mvn-repo/com/massivecraft/Factions/maven-metadata.xml.md5 @@ -1 +1 @@ -53a6a6cb7d4b4409eeaa35c1fababa7c \ No newline at end of file +6755de8684a603d4c311a9b1baf8cc6a \ No newline at end of file diff --git a/mvn-repo/com/massivecraft/Factions/maven-metadata.xml.sha1 b/mvn-repo/com/massivecraft/Factions/maven-metadata.xml.sha1 index b765ecc1..8aa238f8 100644 --- a/mvn-repo/com/massivecraft/Factions/maven-metadata.xml.sha1 +++ b/mvn-repo/com/massivecraft/Factions/maven-metadata.xml.sha1 @@ -1 +1 @@ -6322473e3dc1d937e8d27f82b10f12ac42f8fbb4 \ No newline at end of file +29b5e6cf895598b826331314b9438732d72f9131 \ No newline at end of file diff --git a/pom.xml b/pom.xml index ac1cdeef..0406e196 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.massivecraft Factions - 1.6.9.5-U0.2.1-RC-1.5-STABLE + 1.6.9.5-U0.2.1-RC-1.6-BETA jar SavageFactions @@ -334,6 +334,19 @@ 2 provided + + com.github.SkriptLang + Skript + dev37c + provided + + + * + * + + + + @@ -369,6 +382,14 @@ ProSavage https://www.myget.org/F/prosavage/maven/ + + papermc + https://papermc.io/repo/repository/maven-public/ + + + jitpack.io + https://jitpack.io + diff --git a/src/main/java/com/massivecraft/factions/SavageFactions.java b/src/main/java/com/massivecraft/factions/SavageFactions.java index 2db45f72..d8ed36a8 100644 --- a/src/main/java/com/massivecraft/factions/SavageFactions.java +++ b/src/main/java/com/massivecraft/factions/SavageFactions.java @@ -1,5 +1,7 @@ package com.massivecraft.factions; +import ch.njol.skript.Skript; +import ch.njol.skript.SkriptAddon; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import com.massivecraft.factions.cmd.CmdAutoHelp; @@ -78,6 +80,8 @@ public class SavageFactions extends MPlugin { private ClipPlaceholderAPIManager clipPlaceholderAPIManager; private boolean mvdwPlaceholderAPIManager = false; + SkriptAddon skriptAddon; + private Listener[] eventsListener; public SavageFactions() { @@ -203,6 +207,17 @@ public class SavageFactions extends MPlugin { factionsFlight = true; } + if (getServer().getPluginManager().getPlugin("Skript") != null) { + log("Skript was found! Registering SavageFactions Addon..."); + skriptAddon = Skript.registerAddon(this); + try { + skriptAddon.loadClasses("com.massivecraft.factions.skript", "expressions"); + } catch (IOException ex) { + ex.printStackTrace(); + } + log("Skript addon registered!"); + } + // Register Event Handlers eventsListener = new Listener[] { @@ -237,6 +252,10 @@ public class SavageFactions extends MPlugin { this.loadSuccessful = true; } + public SkriptAddon getSkriptAddon() { + return skriptAddon; + } + private void setupMultiversionMaterials() { if (mc113) { BANNER = Material.valueOf("LEGACY_BANNER"); diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdDisband.java b/src/main/java/com/massivecraft/factions/cmd/CmdDisband.java index 80b52a5d..446a7e42 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdDisband.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdDisband.java @@ -35,6 +35,7 @@ public class CmdDisband extends FCommand { senderMustBeModerator = false; senderMustBeColeader = false; senderMustBeAdmin = false; + } @Override diff --git a/src/main/java/com/massivecraft/factions/skript/expressions/player/PlayerFactionExpression.java b/src/main/java/com/massivecraft/factions/skript/expressions/player/PlayerFactionExpression.java new file mode 100644 index 00000000..1d9cd101 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/skript/expressions/player/PlayerFactionExpression.java @@ -0,0 +1,95 @@ +package com.massivecraft.factions.skript.expressions.player; + +import ch.njol.skript.Skript; +import ch.njol.skript.classes.Changer; +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 ch.njol.util.coll.CollectionUtils; +import com.massivecraft.factions.FPlayer; +import com.massivecraft.factions.FPlayers; +import com.massivecraft.factions.Faction; +import com.massivecraft.factions.Factions; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; + +public class PlayerFactionExpression extends SimpleExpression { + + + static { + Skript.registerExpression(PlayerFactionExpression.class, String.class, ExpressionType.SIMPLE, "[the] faction of %player%", "[the] %player%['s] faction"); + } + + Expression playerExpression; + + @Override + public Class getReturnType() { + return String.class; + } + + + @Override + public boolean isSingle() { + return true; + } + + @Override + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parser) { + playerExpression = (Expression) exprs[0]; + return true; + } + + @Override + public String toString(Event event, boolean debug) { + return "Player Faction Name Expression with expression player" + playerExpression.toString(event, debug); + } + + @Override + protected String[] get(Event event) { + Player player = playerExpression.getSingle(event); + + if (player != null) { + FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player); + return new String[]{fPlayer.getFaction().getTag()}; + } + + return null; + + } + + @Override + public Class[] acceptChange(final Changer.ChangeMode mode) { + if (mode == Changer.ChangeMode.DELETE || mode == Changer.ChangeMode.RESET || mode == Changer.ChangeMode.SET) { + return CollectionUtils.array(String.class); + } + return null; + } + + + @Override + public void change(Event event, Object[] delta, Changer.ChangeMode mode) { + Player player = playerExpression.getSingle(event); + if (player == null) { + return; + } + + FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player); + switch (mode) { + case DELETE: + case RESET: + fPlayer.setFaction(Factions.getInstance().getWilderness()); + break; + case SET: + Faction faction = Factions.getInstance().getByTag((String) delta[0]); + if (faction == null) { + faction = Factions.getInstance().getWilderness(); + } + fPlayer.setFaction(faction); + break; + } + + } + +} diff --git a/src/main/java/com/massivecraft/factions/skript/expressions/player/PlayerPowerExpression.java b/src/main/java/com/massivecraft/factions/skript/expressions/player/PlayerPowerExpression.java new file mode 100644 index 00000000..9fca5569 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/skript/expressions/player/PlayerPowerExpression.java @@ -0,0 +1,93 @@ +package com.massivecraft.factions.skript.expressions.player; + +import ch.njol.skript.Skript; +import ch.njol.skript.classes.Changer; +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 ch.njol.util.coll.CollectionUtils; +import com.massivecraft.factions.FPlayer; +import com.massivecraft.factions.FPlayers; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; + +public class PlayerPowerExpression extends SimpleExpression { + + + static { + Skript.registerExpression(PlayerPowerExpression.class, Number.class, ExpressionType.SIMPLE, "[the] power of %player%", "[the] %player%['s] power"); + } + + Expression playerExpression; + + @Override + public Class getReturnType() { + return Double.class; + } + + + @Override + public boolean isSingle() { + return true; + } + + @Override + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parser) { + playerExpression = (Expression) exprs[0]; + return true; + } + + @Override + public String toString(Event event, boolean debug) { + return "Player Power with expression player" + playerExpression.toString(event, debug); + } + + @Override + protected Double[] get(Event event) { + Player player = playerExpression.getSingle(event); + + if (player != null) { + FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player); + return new Double[]{fPlayer.getFaction().getPower()}; + } + + return null; + + } + + @Override + public Class[] acceptChange(final Changer.ChangeMode mode) { + if (mode == Changer.ChangeMode.RESET || mode == Changer.ChangeMode.ADD || mode == Changer.ChangeMode.REMOVE) { + return CollectionUtils.array(Number.class); + } + return null; + } + + + @Override + public void change(Event event, Object[] delta, Changer.ChangeMode mode) { + Player player = playerExpression.getSingle(event); + if (player == null) { + return; + } + + FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player); + switch (mode) { + case ADD: + fPlayer.alterPower(Double.valueOf((Long) delta[0])); + break; + case REMOVE: + fPlayer.alterPower(Double.valueOf((Long) delta[0]) * -1); + break; + case RESET: + fPlayer.alterPower(fPlayer.getPowerMax() * -1); + break; + } + + + } + + +} diff --git a/src/main/java/com/massivecraft/factions/skript/expressions/player/PlayerRoleExpression.java b/src/main/java/com/massivecraft/factions/skript/expressions/player/PlayerRoleExpression.java new file mode 100644 index 00000000..130aeaa5 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/skript/expressions/player/PlayerRoleExpression.java @@ -0,0 +1,90 @@ +package com.massivecraft.factions.skript.expressions.player; + +import ch.njol.skript.Skript; +import ch.njol.skript.classes.Changer; +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 ch.njol.util.coll.CollectionUtils; +import com.massivecraft.factions.FPlayer; +import com.massivecraft.factions.FPlayers; +import com.massivecraft.factions.struct.Role; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; + +public class PlayerRoleExpression extends SimpleExpression { + + static { + Skript.registerExpression(PlayerRoleExpression.class, String.class, ExpressionType.SIMPLE, "[the] role of %player%", "[the] %player%['s] role"); + } + + Expression playerExpression; + + @Override + public Class getReturnType() { + return String.class; + } + + + @Override + public boolean isSingle() { + return true; + } + + @Override + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parser) { + playerExpression = (Expression) exprs[0]; + return true; + } + + @Override + public String toString(Event event, boolean debug) { + return "Player Faction Name Expression with expression player" + playerExpression.toString(event, debug); + } + + @Override + protected String[] get(Event event) { + Player player = playerExpression.getSingle(event); + + if (player != null) { + FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player); + return new String[]{fPlayer.getRole().toString()}; + } + + return null; + + } + + @Override + public Class[] acceptChange(final Changer.ChangeMode mode) { + if (mode == Changer.ChangeMode.DELETE || mode == Changer.ChangeMode.RESET || mode == Changer.ChangeMode.SET) { + return CollectionUtils.array(String.class); + } + return null; + } + + + @Override + public void change(Event event, Object[] delta, Changer.ChangeMode mode) { + Player player = playerExpression.getSingle(event); + if (player == null) { + return; + } + + FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player); + switch (mode) { + case DELETE: + case RESET: + fPlayer.setRole(Role.RECRUIT); + break; + case SET: + fPlayer.setRole(Role.fromString(((String) delta[0]).toLowerCase())); + break; + } + + } + + +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index c6b0e53f..d81009dd 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -3,7 +3,7 @@ version: ${project.version} api-version: 1.13 main: com.massivecraft.factions.SavageFactions authors: [Olof Larsson, Brett Flannigan, drtshock, ProSavage, AL56AF50, Driftay] -softdepend: [CoreProtect, PlayerVaults, PlaceholderAPI, MVdWPlaceholderAPI, PermissionsEx, Permissions, Essentials, EssentialsChat, HeroChat, iChat, LocalAreaChat, LWC, nChat, ChatManager, CAPI, AuthMe, Vault, Spout, WorldEdit, WorldGuard, AuthDB, CaptureThePoints, CombatTag, dynmap, FactionsTop] +softdepend: [Skript, CoreProtect, PlayerVaults, PlaceholderAPI, MVdWPlaceholderAPI, PermissionsEx, Permissions, Essentials, EssentialsChat, HeroChat, iChat, LocalAreaChat, LWC, nChat, ChatManager, CAPI, AuthMe, Vault, Spout, WorldEdit, WorldGuard, AuthDB, CaptureThePoints, CombatTag, dynmap, FactionsTop] website: www.prosavage.net commands: factions: