-
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.
- Loading branch information
Showing
11 changed files
with
692 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
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,87 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>me.szumielxd</groupId> | ||
<artifactId>MVdWPlaceholderSK</artifactId> | ||
<version>1.0</version> | ||
<name>MVdWPlaceholderSK</name> | ||
<properties> | ||
<author>szumielxd</author> | ||
<mainClass>me.szumielxd.MVdWPlaceholderSK.MVdWPlaceholderSK</mainClass> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.1</version> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>1.4</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
<resources> | ||
<resource> | ||
<directory>src/main/resources</directory> | ||
<filtering>true</filtering> | ||
<includes> | ||
<include>plugin.yml</include> | ||
</includes> | ||
</resource> | ||
<resource> | ||
<directory>src/main/resources</directory> | ||
<filtering>false</filtering> | ||
<excludes> | ||
<exclude>**/*.java</exclude> | ||
<exclude>plugin.yml</exclude> | ||
</excludes> | ||
</resource> | ||
</resources> | ||
</build> | ||
<repositories> | ||
<repository> | ||
<id>destroystokyo-repo</id> | ||
<url>https://repo.destroystokyo.com/content/repositories/snapshots/</url> | ||
</repository> | ||
<repository> | ||
<id>mvdw-software</id> | ||
<name>MVdW Public Repositories</name> | ||
<url>http://repo.mvdw-software.be/content/groups/public/</url> | ||
</repository> | ||
</repositories> | ||
<dependencies> | ||
<dependency> | ||
<groupId>ch.njol</groupId> | ||
<artifactId>Skript</artifactId> | ||
<version>2.4.1</version> | ||
<scope>system</scope> | ||
<systemPath>${project.basedir}/libs/Skript 2.4.1.jar</systemPath> | ||
</dependency> | ||
<dependency> | ||
<groupId>be.maximvdw</groupId> | ||
<artifactId>MVdWPlaceholderAPI</artifactId> | ||
<version>3.1.1-SNAPSHOT</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.spigotmc</groupId> | ||
<artifactId>spigot</artifactId> | ||
<version>1.9-R0.1-SNAPSHOT</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
76 changes: 76 additions & 0 deletions
76
src/main/java/me/szumielxd/MVdWPlaceholderSK/MVdWPlaceholderSK.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,76 @@ | ||
package me.szumielxd.MVdWPlaceholderSK; | ||
|
||
import java.io.IOException; | ||
import java.lang.reflect.Field; | ||
|
||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
import be.maximvdw.placeholderapi.PlaceholderAPI; | ||
import be.maximvdw.placeholderapi.internal.PlaceholderPack; | ||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.SkriptAddon; | ||
|
||
public class MVdWPlaceholderSK extends JavaPlugin { | ||
|
||
|
||
private static MVdWPlaceholderSK instance; | ||
private SkriptAddon addon; | ||
|
||
|
||
public void onEnable() { | ||
|
||
instance = this; | ||
try { | ||
getSkriptInstance(); | ||
(this.addon = getSkriptInstance()).loadClasses("me.szumielxd.MVdWPlaceholderSK.skript", "events", "expressions"); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
} | ||
|
||
|
||
public static MVdWPlaceholderSK getInstance() { | ||
|
||
if (instance == null) throw new IllegalStateException(); | ||
return instance; | ||
|
||
} | ||
|
||
|
||
public SkriptAddon getSkriptInstance() { | ||
|
||
if(addon == null) addon = Skript.registerAddon(this); | ||
return addon; | ||
|
||
} | ||
|
||
|
||
public static boolean isPlaceholderRegistered(String prefix) { | ||
try { | ||
Field f = PlaceholderAPI.class.getDeclaredField("customPlaceholders"); | ||
f.setAccessible(true); | ||
PlaceholderPack pack = (PlaceholderPack) f.get(null); | ||
f.setAccessible(false); | ||
return pack.getPlaceholderReplacer("{"+prefix+"}") != null; | ||
} catch (NoSuchFieldException|SecurityException | IllegalArgumentException | IllegalAccessException e) { | ||
e.printStackTrace(); | ||
} | ||
return false; | ||
} | ||
|
||
|
||
public static void unregisterPlaceholder(String prefix) { | ||
try { | ||
Field f = PlaceholderAPI.class.getDeclaredField("customPlaceholders"); | ||
f.setAccessible(true); | ||
PlaceholderPack pack = (PlaceholderPack) f.get(null); | ||
pack.removePlaceholder("{"+prefix+"}"); | ||
f.setAccessible(false); | ||
} catch (NoSuchFieldException|SecurityException | IllegalArgumentException | IllegalAccessException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
|
||
} |
68 changes: 68 additions & 0 deletions
68
src/main/java/me/szumielxd/MVdWPlaceholderSK/placeholderAPI/MVdWPAPIEvent.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,68 @@ | ||
package me.szumielxd.MVdWPlaceholderSK.placeholderAPI; | ||
|
||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.Event; | ||
import org.bukkit.event.HandlerList; | ||
|
||
public class MVdWPAPIEvent extends Event { | ||
|
||
|
||
private static HandlerList handlerList = new HandlerList(); | ||
private Player player; | ||
private String identifier; | ||
private String result; | ||
private String prefix; | ||
|
||
|
||
@Override | ||
public HandlerList getHandlers() { | ||
return handlerList; | ||
} | ||
|
||
|
||
public static HandlerList getHandlerList() { | ||
return handlerList; | ||
} | ||
|
||
public MVdWPAPIEvent(Player p, String prefix, String identifier) { | ||
this.identifier = identifier; | ||
this.player = p; | ||
this.prefix = prefix; | ||
} | ||
|
||
public MVdWPAPIEvent(Player p, String prefix, String identifier, boolean async) { | ||
super(async); | ||
this.identifier = identifier; | ||
this.player = p; | ||
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 String getPrefix() { | ||
return this.prefix; | ||
} | ||
|
||
|
||
|
||
|
||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/me/szumielxd/MVdWPlaceholderSK/placeholderAPI/MVdWPAPIListener.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,30 @@ | ||
package me.szumielxd.MVdWPlaceholderSK.placeholderAPI; | ||
|
||
import org.bukkit.Bukkit; | ||
import be.maximvdw.placeholderapi.PlaceholderReplaceEvent; | ||
import be.maximvdw.placeholderapi.PlaceholderReplacer; | ||
|
||
public class MVdWPAPIListener implements PlaceholderReplacer { | ||
|
||
|
||
private String identifier; | ||
|
||
|
||
public MVdWPAPIListener(String prefix) { | ||
this.identifier = prefix; | ||
} | ||
|
||
|
||
@Override | ||
public String onPlaceholderReplace(PlaceholderReplaceEvent e) { | ||
MVdWPAPIEvent event; | ||
if(Bukkit.isPrimaryThread()) { | ||
event = new MVdWPAPIEvent(e.getPlayer(), identifier, e.getPlaceholder()); | ||
}else { | ||
event = new MVdWPAPIEvent(e.getPlayer(), identifier, e.getPlaceholder(), true); | ||
} | ||
Bukkit.getPluginManager().callEvent(event); | ||
return event.getResult(); | ||
} | ||
|
||
} |
Oops, something went wrong.