forked from Schmoller/uSkyBlock
-
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.
Merge pull request Frostcast#2 from rlf/master
Many Fixes
- Loading branch information
Showing
33 changed files
with
778 additions
and
116 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
33 changes: 33 additions & 0 deletions
33
...-Core/src/main/java/us/talabrek/ultimateskyblock/handler/placeholder/ChatPlaceholder.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,33 @@ | ||
package us.talabrek.ultimateskyblock.handler.placeholder; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.AsyncPlayerChatEvent; | ||
import us.talabrek.ultimateskyblock.uSkyBlock; | ||
|
||
/** | ||
* Our native chat-placeholder handler. | ||
*/ | ||
public class ChatPlaceholder extends TextPlaceholder implements Listener { | ||
@Override | ||
public boolean registerPlaceholder(uSkyBlock plugin, PlaceholderReplacer replacer) { | ||
Bukkit.getPluginManager().registerEvents(this, plugin); | ||
return super.registerPlaceholder(plugin, replacer); | ||
} | ||
|
||
@EventHandler | ||
public void onChatEvent(AsyncPlayerChatEvent e) { | ||
Player player = e.getPlayer(); | ||
String result = replacePlaceholders(player, e.getFormat()); | ||
if (result != null) { | ||
e.setFormat(result); | ||
} | ||
result = replacePlaceholders(player, e.getMessage()); | ||
if (result != null) { | ||
e.setMessage(result); | ||
} | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
...re/src/main/java/us/talabrek/ultimateskyblock/handler/placeholder/MVdWPlaceholderAPI.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,35 @@ | ||
package us.talabrek.ultimateskyblock.handler.placeholder; | ||
|
||
import be.maximvdw.placeholderapi.PlaceholderReplaceEvent; | ||
import org.bukkit.Bukkit; | ||
import us.talabrek.ultimateskyblock.uSkyBlock; | ||
|
||
/** | ||
* MVdWPlaceholder proxy | ||
*/ | ||
public class MVdWPlaceholderAPI implements PlaceholderAPI { | ||
public boolean isAvailable() { | ||
// Might not be enabled yet... | ||
return Bukkit.getPluginManager().getPlugin("MVdWPlaceholderAPI") != null; | ||
} | ||
|
||
@Override | ||
public boolean registerPlaceholder(uSkyBlock plugin, final PlaceholderReplacer replacer) { | ||
if (isAvailable()) { | ||
be.maximvdw.placeholderapi.PlaceholderReplacer proxy = new be.maximvdw.placeholderapi.PlaceholderReplacer() { | ||
@Override | ||
public String onPlaceholderReplace(PlaceholderReplaceEvent e) { | ||
if (replacer.getPlaceholders().contains(e.getPlaceholder())) { | ||
return replacer.replace(e.getOfflinePlayer(), e.getPlayer(), e.getPlaceholder()); | ||
} | ||
return null; | ||
} | ||
}; | ||
for (String placeholder : replacer.getPlaceholders()) { | ||
be.maximvdw.placeholderapi.PlaceholderAPI.registerPlaceholder(plugin, placeholder, proxy); | ||
} | ||
return true; | ||
} | ||
return false; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...k-Core/src/main/java/us/talabrek/ultimateskyblock/handler/placeholder/PlaceholderAPI.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,17 @@ | ||
package us.talabrek.ultimateskyblock.handler.placeholder; | ||
|
||
import org.bukkit.OfflinePlayer; | ||
import org.bukkit.entity.Player; | ||
import us.talabrek.ultimateskyblock.uSkyBlock; | ||
|
||
import java.util.Set; | ||
|
||
/** | ||
*/ | ||
public interface PlaceholderAPI { | ||
interface PlaceholderReplacer { | ||
Set<String> getPlaceholders(); | ||
String replace(OfflinePlayer offlinePlayer, Player player, String placeholder); | ||
} | ||
boolean registerPlaceholder(uSkyBlock plugin, PlaceholderReplacer replacer); | ||
} |
35 changes: 35 additions & 0 deletions
35
...re/src/main/java/us/talabrek/ultimateskyblock/handler/placeholder/PlaceholderHandler.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,35 @@ | ||
package us.talabrek.ultimateskyblock.handler.placeholder; | ||
|
||
import dk.lockfuglsang.minecraft.file.FileUtil; | ||
import us.talabrek.ultimateskyblock.uSkyBlock; | ||
|
||
public class PlaceholderHandler { | ||
private static final String[] ADAPTORS = { | ||
ChatPlaceholder.class.getName(), | ||
ServerCommandPlaceholder.class.getName(), | ||
"us.talabrek.ultimateskyblock.handler.placeholder.MVdWPlaceholder" | ||
}; | ||
|
||
public static void register(uSkyBlock plugin) { | ||
PlaceholderReplacerImpl placeholderReplacer = new PlaceholderReplacerImpl(plugin); | ||
for (String className : ADAPTORS) { | ||
String baseName = FileUtil.getExtension(className); | ||
if (plugin.getConfig().getBoolean("placeholder." + baseName.toLowerCase() + ".enabled", false)) { | ||
try { | ||
Class<?> aClass = Class.forName(className); | ||
Object o = aClass.newInstance(); | ||
if (o instanceof PlaceholderAPI) { | ||
if (((PlaceholderAPI) o).registerPlaceholder(plugin, placeholderReplacer)) { | ||
plugin.getLogger().info("uSkyBlock hooked into " + baseName); | ||
} else { | ||
plugin.getLogger().info("uSkyBlock failed to hook into " + baseName); | ||
} | ||
} | ||
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { | ||
// Ignore | ||
plugin.getLogger().info("uSkyBlock failed to hook into " + baseName); | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.