-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated to Skript 2.6 and added relational placeholders
- Loading branch information
Showing
12 changed files
with
327 additions
and
181 deletions.
There are no files selected for viewing
68 changes: 0 additions & 68 deletions
68
src/main/java/me/szumielxd/PlaceholderSK/placeholderAPI/PAPIEvent.java
This file was deleted.
Oops, something went wrong.
63 changes: 0 additions & 63 deletions
63
src/main/java/me/szumielxd/PlaceholderSK/placeholderAPI/PAPIListener.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/main/java/me/szumielxd/placeholdersk/placeholderapi/PAPIEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
|
||
|
||
|
||
} |
96 changes: 96 additions & 0 deletions
96
src/main/java/me/szumielxd/placeholdersk/placeholderapi/PAPIListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
Oops, something went wrong.