Removed the current Placeholders API (it is unused)

This commit is contained in:
Florian CUNY 2018-08-16 21:35:10 +02:00
parent 5740ad7e0c
commit 7b3b1303b4
8 changed files with 0 additions and 278 deletions

View File

@ -1,6 +1,5 @@
package world.bentobox.bentobox;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.plugin.PluginManager;
@ -9,10 +8,8 @@ import org.bukkit.plugin.java.JavaPlugin;
import world.bentobox.bentobox.api.configuration.Config;
import world.bentobox.bentobox.api.configuration.WorldSettings;
import world.bentobox.bentobox.api.events.BentoBoxReadyEvent;
import world.bentobox.bentobox.api.placeholders.PlaceholderHandler;
import world.bentobox.bentobox.api.user.Notifier;
import world.bentobox.bentobox.commands.BentoBoxCommand;
import world.bentobox.bentobox.database.DatabaseSetup;
import world.bentobox.bentobox.listeners.BannedVisitorCommands;
import world.bentobox.bentobox.listeners.BlockEndDragon;
import world.bentobox.bentobox.listeners.JoinLeaveListener;
@ -109,7 +106,6 @@ public class BentoBox extends JavaPlugin {
// Locales manager must be loaded before addons
localesManager = new LocalesManager(instance);
PlaceholderHandler.register(instance);
// Load addons. Addons may load worlds, so they must go before islands are loaded.
addonsManager = new AddonsManager(instance);

View File

@ -1,29 +0,0 @@
package world.bentobox.bentobox.api.placeholders;
import world.bentobox.bentobox.api.user.User;
/**
* @author Poslovitch
*/
public class Placeholder {
private String identifier;
private PlaceholderRequest request;
Placeholder(String identifier, PlaceholderRequest request) {
this.identifier = identifier;
this.request = request;
}
public String getIdentifier() {
return this.identifier;
}
public PlaceholderRequest getRequest() {
return request;
}
public interface PlaceholderRequest {
String request(User user);
}
}

View File

@ -1,39 +0,0 @@
package world.bentobox.bentobox.api.placeholders;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.user.User;
/**
* Simple interface for every Placeholder API.
*
* @author Poslovitch
*/
public interface PlaceholderAPIInterface {
/**
* Gets the name of the Placeholder API
* @return name of the placeholder plugin
*/
String getName();
/**
* Registers the placeholder API
* @param plugin - plugin object
* @return true if successfully registered
*/
boolean register(BentoBox plugin);
/**
* Unregisters the placeholder API
* @param plugin - plugin object
*/
void unregister(BentoBox plugin);
/**
* Replace placeholders in the message according to the receiver
* @param receiver - user who will receive the message
* @param message - message
* @return updated message
*/
String replacePlaceholders(User receiver, String message);
}

View File

@ -1,26 +0,0 @@
package world.bentobox.bentobox.api.placeholders;
public class PlaceholderBuilder {
private String identifier;
private Placeholder.PlaceholderRequest value;
public PlaceholderBuilder identifier(String identifier) {
this.identifier = identifier;
return this;
}
/**
* The value this placeholder should take
* @param value - placeholder request value
* @return PlaceholderBuilder object
*/
public PlaceholderBuilder value(Placeholder.PlaceholderRequest value) {
this.value = value;
return this;
}
public Placeholder build() {
return new Placeholder(identifier, value);
}
}

View File

@ -1,98 +0,0 @@
package world.bentobox.bentobox.api.placeholders;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.user.User;
/**
* Handles hooks with other Placeholder APIs.
*
* @author Poslovitch, Tastybento
*/
public class PlaceholderHandler {
private static final String PACKAGE = "world.bentobox.bentobox.api.placeholders.hooks.";
// This class should never be instantiated (all methods are static)
private PlaceholderHandler() {}
/**
* List of API classes in the package specified above (except the Internal one)
*/
private static final String[] HOOKS = {
//TODO
};
private static List<PlaceholderAPIInterface> apis = new ArrayList<>();
/**
* Register placeholders and hooks
* @param plugin - plugin object
*/
public static void register(BentoBox plugin){
// Load Internal Placeholder API
try{
Class<?> clazz = Class.forName(PACKAGE + "InternalPlaceholderImpl");
PlaceholderAPIInterface internal = (PlaceholderAPIInterface)clazz.newInstance();
apis.add(internal);
} catch (Exception e){
// Should never happen.
plugin.logError("Failed to load default placeholder API");
}
// Load hooks
for(String hook : HOOKS){
if(plugin.getServer().getPluginManager().isPluginEnabled(hook)){
try{
Class<?> clazz = Class.forName(PACKAGE + hook + "PlaceholderImpl");
PlaceholderAPIInterface api = (PlaceholderAPIInterface)clazz.newInstance();
if(api.register(plugin)){
plugin.log("Hooked placeholders into " + hook); // since Java 8, we can use Supplier , which will be evaluated lazily
apis.add(api);
} else {
plugin.log("Failed to hook placeholders into " + hook);
}
} catch (Exception e){
plugin.log("Failed to hook placeholders into " + hook);
}
}
}
}
/**
* Unregister placeholder hooks
* @param plugin - plugin object
*/
public static void unregister(BentoBox plugin){
Iterator<PlaceholderAPIInterface> it = apis.iterator();
while (it.hasNext()) {
PlaceholderAPIInterface api = it.next();
api.unregister(plugin);
it.remove();
}
}
/**
* Replace placeholders in the message according to the receiver
* @param receiver - user to receive the message
* @param message - message
* @return updated message
*/
public static String replacePlaceholders(User receiver, String message){
for(PlaceholderAPIInterface api : apis){
message = api.replacePlaceholders(receiver, message);
}
return message;
}
/**
* @return true if APIs are registered (including Internal), otherwise false
*/
public static boolean hasHooks(){
return apis != null;
}
}

View File

@ -1,45 +0,0 @@
package world.bentobox.bentobox.api.placeholders.hooks;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.placeholders.Placeholder;
import world.bentobox.bentobox.api.placeholders.PlaceholderAPIInterface;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.lists.Placeholders;
/**
* Built-in placeholder API
*
* @author Poslovitch
*/
public class InternalPlaceholderImpl implements PlaceholderAPIInterface {
@Override
public String getName() {
return "Internal";
}
@Override
public boolean register(BentoBox plugin) {
return true;
}
@Override
public void unregister(BentoBox plugin) {
// Useless : it would disable the placeholders.
}
@Override
public String replacePlaceholders(User receiver, String message) {
if(message == null || message.isEmpty()) {
return "";
}
for(Placeholder placeholder : Placeholders.values()){
String identifier = "%" + placeholder.getIdentifier() + "%";
message = message.replaceAll(identifier, placeholder.getRequest().request(receiver));
}
return message;
}
}

View File

@ -18,7 +18,6 @@ import org.bukkit.inventory.PlayerInventory;
import org.bukkit.permissions.PermissionAttachmentInfo;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.placeholders.PlaceholderHandler;
/**
* BSB's user object. Wraps Player.
@ -210,9 +209,6 @@ public class User {
}
}
// Replace placeholders
translation = PlaceholderHandler.replacePlaceholders(this, translation);
return ChatColor.translateAlternateColorCodes('&', translation);
}

View File

@ -1,33 +0,0 @@
package world.bentobox.bentobox.lists;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import org.bukkit.Bukkit;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.placeholders.Placeholder;
import world.bentobox.bentobox.api.placeholders.PlaceholderBuilder;
public class Placeholders {
// Utility classes, which are collections of static members, are not meant to be instantiated.
private Placeholders() {}
public static final Placeholder PLUGIN_NAME = new PlaceholderBuilder().identifier("bsb_plugin_name").value(user -> BentoBox.getInstance().getDescription().getName()).build();
/**
* @return List of all the flags in this class
*/
public static List<Placeholder> values() {
return Arrays.stream(Placeholders.class.getFields()).map(field -> {
try {
return (Placeholder)field.get(null);
} catch (IllegalArgumentException | IllegalAccessException e) {
Bukkit.getLogger().severe("Could not get Placeholders values " + e.getMessage());
}
return null;
}).collect(Collectors.toList());
}
}