mirror of
https://github.com/PlaceholderAPI/PlaceholderAPI
synced 2025-02-05 03:45:28 +01:00
This commit is contained in:
parent
f91b4e3752
commit
36fa9ac96d
@ -40,6 +40,14 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
*/
|
*/
|
||||||
public abstract class PlaceholderExpansion extends PlaceholderHook {
|
public abstract class PlaceholderExpansion extends PlaceholderHook {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type is {@link Type#INTERNAL} by default.
|
||||||
|
* For external expansions, the type is updated on {@link me.clip.placeholderapi.expansion.manager.LocalExpansionManager#register(Class) register}.
|
||||||
|
* @since 2.11.4
|
||||||
|
*/
|
||||||
|
@ApiStatus.Internal
|
||||||
|
protected Type expansionType = Type.INTERNAL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The placeholder identifier of this expansion. May not contain {@literal %},
|
* The placeholder identifier of this expansion. May not contain {@literal %},
|
||||||
* {@literal {}} or _
|
* {@literal {}} or _
|
||||||
@ -159,6 +167,27 @@ public abstract class PlaceholderExpansion extends PlaceholderHook {
|
|||||||
return PlaceholderAPIPlugin.getInstance();
|
return PlaceholderAPIPlugin.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the type of the expansion
|
||||||
|
*
|
||||||
|
* @return the type of the expansion
|
||||||
|
* @since 2.11.4
|
||||||
|
*/
|
||||||
|
@ApiStatus.Internal
|
||||||
|
public Type getExpansionType() {
|
||||||
|
return expansionType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the type of the expansion
|
||||||
|
* @param expansionType the new type
|
||||||
|
* @since 2.11.4
|
||||||
|
*/
|
||||||
|
@ApiStatus.Internal
|
||||||
|
public void setExpansionType(Type expansionType) {
|
||||||
|
this.expansionType = expansionType;
|
||||||
|
}
|
||||||
|
|
||||||
// === Configuration ===
|
// === Configuration ===
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -166,7 +195,7 @@ public abstract class PlaceholderExpansion extends PlaceholderHook {
|
|||||||
* null when not specified.
|
* null when not specified.
|
||||||
* <br>You may use the {@link Configurable} interface to define default values set
|
* <br>You may use the {@link Configurable} interface to define default values set
|
||||||
*
|
*
|
||||||
* @return ConfigurationSection that this epxpansion has.
|
* @return ConfigurationSection that this expansion has.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public final ConfigurationSection getConfigSection() {
|
public final ConfigurationSection getConfigSection() {
|
||||||
@ -394,8 +423,8 @@ public abstract class PlaceholderExpansion extends PlaceholderHook {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final String toString() {
|
public final String toString() {
|
||||||
return String.format("PlaceholderExpansion[name: '%s', author: '%s', version: '%s']", getName(),
|
return String.format("PlaceholderExpansion[name: '%s', author: '%s', version: '%s', type: '%s']", getName(),
|
||||||
getAuthor(), getVersion());
|
getAuthor(), getVersion(), getExpansionType());
|
||||||
}
|
}
|
||||||
|
|
||||||
// === Deprecated API ===
|
// === Deprecated API ===
|
||||||
@ -432,4 +461,19 @@ public abstract class PlaceholderExpansion extends PlaceholderHook {
|
|||||||
public String getLink() {
|
public String getLink() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum Type {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An expansion provided by a plugin is considered internal
|
||||||
|
*/
|
||||||
|
INTERNAL,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An expansion loaded from the expansions folder is considered external
|
||||||
|
*/
|
||||||
|
EXTERNAL
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -187,6 +187,8 @@ public final class LocalExpansionManager implements Listener {
|
|||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
expansion.setExpansionType(PlaceholderExpansion.Type.EXTERNAL);
|
||||||
|
|
||||||
if (!expansion.register()) {
|
if (!expansion.register()) {
|
||||||
Msg.warn("Cannot load expansion %s due to an unknown issue.", expansion.getIdentifier());
|
Msg.warn("Cannot load expansion %s due to an unknown issue.", expansion.getIdentifier());
|
||||||
@ -209,6 +211,11 @@ public final class LocalExpansionManager implements Listener {
|
|||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempt to register a {@link PlaceholderExpansion}
|
||||||
|
* @param expansion the expansion to register
|
||||||
|
* @return if the expansion was registered
|
||||||
|
*/
|
||||||
@ApiStatus.Internal
|
@ApiStatus.Internal
|
||||||
public boolean register(@NotNull final PlaceholderExpansion expansion) {
|
public boolean register(@NotNull final PlaceholderExpansion expansion) {
|
||||||
final String identifier = expansion.getIdentifier().toLowerCase(Locale.ROOT);
|
final String identifier = expansion.getIdentifier().toLowerCase(Locale.ROOT);
|
||||||
@ -216,10 +223,10 @@ public final class LocalExpansionManager implements Listener {
|
|||||||
if (!expansion.canRegister()) {
|
if (!expansion.canRegister()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expansions.containsKey(identifier)) {
|
// Avoid loading two external expansions with the same identifier
|
||||||
Msg.warn("Failed to load expansion %s. Identifier is already in use.",
|
if (expansion.getExpansionType() == PlaceholderExpansion.Type.EXTERNAL && expansions.containsKey(identifier)) {
|
||||||
expansion.getIdentifier());
|
Msg.warn("Failed to load external expansion %s. Identifier is already in use.", expansion.getIdentifier());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -287,21 +294,24 @@ public final class LocalExpansionManager implements Listener {
|
|||||||
Bukkit.getPluginManager().registerEvents(((Listener) expansion), plugin);
|
Bukkit.getPluginManager().registerEvents(((Listener) expansion), plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
Msg.info("Successfully registered expansion: %s [%s]", expansion.getIdentifier(),
|
Msg.info(
|
||||||
expansion.getVersion());
|
"Successfully registered %s expansion: %s [%s]",
|
||||||
|
expansion.getExpansionType().name().toLowerCase(),
|
||||||
|
expansion.getIdentifier(),
|
||||||
|
expansion.getVersion()
|
||||||
|
);
|
||||||
|
|
||||||
if (expansion instanceof Taskable) {
|
if (expansion instanceof Taskable) {
|
||||||
((Taskable) expansion).start();
|
((Taskable) expansion).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin.getPlaceholderAPIConfig().isCloudEnabled()) {
|
// Check eCloud for updates only if the expansion is external
|
||||||
final Optional<CloudExpansion> cloudExpansionOptional =
|
if (plugin.getPlaceholderAPIConfig().isCloudEnabled() && expansion.getExpansionType() == PlaceholderExpansion.Type.EXTERNAL) {
|
||||||
plugin.getCloudExpansionManager().findCloudExpansionByName(identifier);
|
final Optional<CloudExpansion> cloudExpansionOptional = plugin.getCloudExpansionManager().findCloudExpansionByName(identifier);
|
||||||
if (cloudExpansionOptional.isPresent()) {
|
if (cloudExpansionOptional.isPresent()) {
|
||||||
CloudExpansion cloudExpansion = cloudExpansionOptional.get();
|
CloudExpansion cloudExpansion = cloudExpansionOptional.get();
|
||||||
cloudExpansion.setHasExpansion(true);
|
cloudExpansion.setHasExpansion(true);
|
||||||
cloudExpansion.setShouldUpdate(
|
cloudExpansion.setShouldUpdate(!cloudExpansion.getLatestVersion().equals(expansion.getVersion()));
|
||||||
!cloudExpansion.getLatestVersion().equals(expansion.getVersion()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user