Skip to content

Commit

Permalink
Updated to Skript 2.6 and added relational placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
szumielxd committed Aug 22, 2022
1 parent 3ebf80c commit 39b6c4b
Show file tree
Hide file tree
Showing 12 changed files with 327 additions and 181 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package me.szumielxd.PlaceholderSK;
package me.szumielxd.placeholdersk;

import java.io.IOException;

import org.bukkit.plugin.java.JavaPlugin;

import ch.njol.skript.Skript;
import ch.njol.skript.SkriptAddon;
import me.szumielxd.PlaceholderSK.utils.ReflectionUtils;
import me.szumielxd.placeholdersk.utils.ReflectionUtils;

public class PlaceholderSK extends JavaPlugin {

Expand All @@ -16,13 +16,14 @@ public class PlaceholderSK extends JavaPlugin {
private SkriptAddon addon;


@Override
public void onEnable() {

instance = this;
setInstance(this);
reflections = new ReflectionUtils();
try {
getSkriptInstance();
(this.addon = getSkriptInstance()).loadClasses("me.szumielxd.PlaceholderSK.skript", "events", "expressions");
this.addon = getSkriptInstance();
this.addon.loadClasses("me.szumielxd.placeholdersk.skript", "events", "expressions");
} catch (IOException e) {
e.printStackTrace();
}
Expand All @@ -31,24 +32,22 @@ public void onEnable() {


public static PlaceholderSK getInstance() {

if (instance == null) throw new IllegalStateException();
return instance;

}

private static void setInstance(PlaceholderSK instance) {
PlaceholderSK.instance = instance;
}

public SkriptAddon getSkriptInstance() {

public SkriptAddon getSkriptInstance() {
if(addon == null) addon = Skript.registerAddon(this);
return addon;

}


public ReflectionUtils getReflectionUtils() {
return this.reflections;
}


}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package me.szumielxd.placeholdersk.placeholderapi;

import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class PAPIEvent extends Event {


private static final @NotNull HandlerList handlerList = new HandlerList();
private @NotNull Player player;
private @Nullable Player target;
private @NotNull String identifier;
private @Nullable String result;
private @NotNull String prefix;


@Override
public @NotNull HandlerList getHandlers() {
return handlerList;
}


public static @NotNull HandlerList getHandlerList() {
return handlerList;
}

public PAPIEvent(@NotNull Player player, @Nullable Player target, @NotNull String prefix, @NotNull String identifier) {
this.identifier = identifier;
this.player = player;
this.target = target;
this.prefix = prefix;
}

public PAPIEvent(@NotNull Player player, @Nullable Player target, @NotNull String prefix, @NotNull String identifier, boolean async) {
super(async);
this.identifier = identifier;
this.player = player;
this.target = target;
this.prefix = prefix;
}


public void setResult(String result) {
this.result = result;
}


public String getResult() {
return this.result;
}


public String getIdentifier() {
return this.identifier;
}


public Player getPlayer() {
return this.player;
}


public Player getTarget() {
return this.target;
}


public String getPrefix() {
return this.prefix;
}




}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package me.szumielxd.placeholdersk.placeholderapi;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.bukkit.entity.Player;
import org.bukkit.event.EventException;
import org.bukkit.event.Listener;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import me.clip.placeholderapi.expansion.Relational;
import me.szumielxd.placeholdersk.PlaceholderSK;
import me.szumielxd.placeholdersk.skript.events.SKPlaceholderRequestEvent;

public class PAPIListener extends PlaceholderExpansion implements Relational {


private final String identifier;
private final List<String> placeholders;
private final SKPlaceholderRequestEvent skEvent;
private final Listener listener = new Listener() {};


public PAPIListener(@NotNull SKPlaceholderRequestEvent skEvent, @NotNull String prefix, @Nullable String[] placeholders) {
this.skEvent = skEvent;
this.identifier = prefix;
this.placeholders = placeholders == null ? Collections.emptyList() : Stream.of(placeholders).map(s -> "%" + prefix + "_" + s + "%").collect(Collectors.toList());
}


@Override
public boolean persist() {
return true;
}


@Override
public List<String> getPlaceholders() {
return this.placeholders;
}


@Override
public String getAuthor() {
return String.join(", ", PlaceholderSK.getInstance().getDescription().getAuthors());
}

@Override
public String getIdentifier() {
return identifier;
}

@Override
public String getVersion() {
return PlaceholderSK.getInstance().getDescription().getVersion();
}

@Deprecated
@Override
public String getPlugin() {
return "PlaceholderSK";
}

@Override
public String getRequiredPlugin() {
return "Skript";
}

@Override
public String onPlaceholderRequest(Player player, String param) {
PAPIEvent event = new PAPIEvent(player, null, this.identifier, param);
try {
this.skEvent.getExecutor().execute(this.listener, event);
} catch (EventException e) {
e.printStackTrace();
}
return event.getResult();
}


@Override
public String onPlaceholderRequest(Player target, Player player, String param) {
PAPIEvent event = new PAPIEvent(player, target, this.identifier, param);
try {
this.skEvent.getExecutor().execute(this.listener, event);
} catch (EventException e) {
e.printStackTrace();
}
return event.getResult();
}

}
Loading

0 comments on commit 39b6c4b

Please sign in to comment.