First Wave of Skript Support.

This commit is contained in:
ProSavage 2018-12-26 19:22:06 -06:00
parent 7be48b5942
commit bdd547309a
10 changed files with 327 additions and 7 deletions

View File

@ -3,12 +3,13 @@
<groupId>com.massivecraft</groupId> <groupId>com.massivecraft</groupId>
<artifactId>Factions</artifactId> <artifactId>Factions</artifactId>
<versioning> <versioning>
<release>1.6.9.5-U0.2.1-RC-1.5-STABLE</release> <release>1.6.9.5-U0.2.1-RC-1.6-BETA</release>
<versions> <versions>
<version>1.6.9.5-U0.2.1-RC-1.5-BETA</version> <version>1.6.9.5-U0.2.1-RC-1.5-BETA</version>
<version>1.6.9.5-U0.2.1-RC-1.5-BETA-2</version> <version>1.6.9.5-U0.2.1-RC-1.5-BETA-2</version>
<version>1.6.9.5-U0.2.1-RC-1.5-STABLE</version> <version>1.6.9.5-U0.2.1-RC-1.5-STABLE</version>
<version>1.6.9.5-U0.2.1-RC-1.6-BETA</version>
</versions> </versions>
<lastUpdated>20181222234636</lastUpdated> <lastUpdated>20181227012130</lastUpdated>
</versioning> </versioning>
</metadata> </metadata>

View File

@ -1 +1 @@
53a6a6cb7d4b4409eeaa35c1fababa7c 6755de8684a603d4c311a9b1baf8cc6a

View File

@ -1 +1 @@
6322473e3dc1d937e8d27f82b10f12ac42f8fbb4 29b5e6cf895598b826331314b9438732d72f9131

23
pom.xml
View File

@ -4,7 +4,7 @@
<groupId>com.massivecraft</groupId> <groupId>com.massivecraft</groupId>
<artifactId>Factions</artifactId> <artifactId>Factions</artifactId>
<version>1.6.9.5-U0.2.1-RC-1.5-STABLE</version> <version>1.6.9.5-U0.2.1-RC-1.6-BETA</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>SavageFactions</name> <name>SavageFactions</name>
@ -334,6 +334,19 @@
<version>2</version> <version>2</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>com.github.SkriptLang</groupId>
<artifactId>Skript</artifactId>
<version>dev37c</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies> </dependencies>
<repositories> <repositories>
@ -369,6 +382,14 @@
<id>ProSavage</id> <id>ProSavage</id>
<url>https://www.myget.org/F/prosavage/maven/</url> <url>https://www.myget.org/F/prosavage/maven/</url>
</repository> </repository>
<repository>
<id>papermc</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories> </repositories>
<distributionManagement> <distributionManagement>

View File

@ -1,5 +1,7 @@
package com.massivecraft.factions; package com.massivecraft.factions;
import ch.njol.skript.Skript;
import ch.njol.skript.SkriptAddon;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.massivecraft.factions.cmd.CmdAutoHelp; import com.massivecraft.factions.cmd.CmdAutoHelp;
@ -78,6 +80,8 @@ public class SavageFactions extends MPlugin {
private ClipPlaceholderAPIManager clipPlaceholderAPIManager; private ClipPlaceholderAPIManager clipPlaceholderAPIManager;
private boolean mvdwPlaceholderAPIManager = false; private boolean mvdwPlaceholderAPIManager = false;
SkriptAddon skriptAddon;
private Listener[] eventsListener; private Listener[] eventsListener;
public SavageFactions() { public SavageFactions() {
@ -203,6 +207,17 @@ public class SavageFactions extends MPlugin {
factionsFlight = true; 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 // Register Event Handlers
eventsListener = new Listener[] { eventsListener = new Listener[] {
@ -237,6 +252,10 @@ public class SavageFactions extends MPlugin {
this.loadSuccessful = true; this.loadSuccessful = true;
} }
public SkriptAddon getSkriptAddon() {
return skriptAddon;
}
private void setupMultiversionMaterials() { private void setupMultiversionMaterials() {
if (mc113) { if (mc113) {
BANNER = Material.valueOf("LEGACY_BANNER"); BANNER = Material.valueOf("LEGACY_BANNER");

View File

@ -35,6 +35,7 @@ public class CmdDisband extends FCommand {
senderMustBeModerator = false; senderMustBeModerator = false;
senderMustBeColeader = false; senderMustBeColeader = false;
senderMustBeAdmin = false; senderMustBeAdmin = false;
} }
@Override @Override

View File

@ -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<String> {
static {
Skript.registerExpression(PlayerFactionExpression.class, String.class, ExpressionType.SIMPLE, "[the] faction of %player%", "[the] %player%['s] faction");
}
Expression<Player> playerExpression;
@Override
public Class<? extends String> 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<Player>) 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;
}
}
}

View File

@ -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<Number> {
static {
Skript.registerExpression(PlayerPowerExpression.class, Number.class, ExpressionType.SIMPLE, "[the] power of %player%", "[the] %player%['s] power");
}
Expression<Player> playerExpression;
@Override
public Class<? extends Number> 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<Player>) 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;
}
}
}

View File

@ -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<String> {
static {
Skript.registerExpression(PlayerRoleExpression.class, String.class, ExpressionType.SIMPLE, "[the] role of %player%", "[the] %player%['s] role");
}
Expression<Player> playerExpression;
@Override
public Class<? extends String> 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<Player>) 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;
}
}
}

View File

@ -3,7 +3,7 @@ version: ${project.version}
api-version: 1.13 api-version: 1.13
main: com.massivecraft.factions.SavageFactions main: com.massivecraft.factions.SavageFactions
authors: [Olof Larsson, Brett Flannigan, drtshock, ProSavage, AL56AF50, Driftay] 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 website: www.prosavage.net
commands: commands:
factions: factions: