Skip to content

Commit e79dda3

Browse files
WunderoWundero
Wundero
authored and
Wundero
committed
Minor bug fixes I found when testing with Gluon.
1 parent 50b4b01 commit e79dda3

File tree

6 files changed

+19
-16
lines changed

6 files changed

+19
-16
lines changed

src/main/java/me/rojo8399/placeholderapi/PlaceholderService.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,7 @@ public interface PlaceholderService {
6262
*
6363
* @return the expansion builder.
6464
*/
65-
public default ExpansionBuilder<?, ?, ?, ?> load(Object handle, String id, Object plugin) {
66-
return builder().from(handle, id, plugin);
67-
}
68-
65+
public ExpansionBuilder<?, ?, ?, ?> load(Object handle, String id, Object plugin);
6966
/**
7067
* Create new ExpansionBuilders for all methods annotated with
7168
* '@Placeholder' in an object.

src/main/java/me/rojo8399/placeholderapi/impl/PlaceholderAPIPlugin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,6 @@ public void saveConfig() {
139139
public void onGamePreInitializationEvent(GamePreInitializationEvent event)
140140
throws IOException, ObjectMappingException {
141141
instance = this;
142-
// Provide default implementation
143-
game.getServiceManager().setProvider(this, PlaceholderService.class, s = PlaceholderServiceImpl.get());
144142
plugin = game.getPluginManager().getPlugin(PLUGIN_ID).get();
145143
Asset conf = game.getAssetManager().getAsset(this, "config.conf").get();
146144
jsm = new JavascriptManager(new File(path.toFile().getParentFile(), "javascript"));
@@ -207,6 +205,8 @@ public void onGamePreInitializationEvent(GamePreInitializationEvent event)
207205
}
208206
Messages.init(msgs);
209207
this.formatter = DateTimeFormatter.ofPattern(config.dateFormat);
208+
// Provide default implementation
209+
game.getServiceManager().setProvider(this, PlaceholderService.class, s = PlaceholderServiceImpl.get());
210210
}
211211

212212
@Listener

src/main/java/me/rojo8399/placeholderapi/impl/PlaceholderServiceImpl.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,4 +274,12 @@ public boolean registerExpansion(Expansion<?, ?, ?> expansion) {
274274
return ExpansionBuilderImpl.loadAll(handle, plugin);
275275
}
276276

277+
/* (non-Javadoc)
278+
* @see me.rojo8399.placeholderapi.PlaceholderService#load(java.lang.Object, java.lang.String, java.lang.Object)
279+
*/
280+
@Override
281+
public ExpansionBuilder<?, ?, ?, ?> load(Object handle, String id, Object plugin) {
282+
return ExpansionBuilderImpl.unverified().from(handle, id, plugin);
283+
}
284+
277285
}

src/main/java/me/rojo8399/placeholderapi/impl/commands/InfoCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ private static Text format(Expansion<?, ?, ?> e, CommandSource src) {
120120
Text url = e.url() == null ? Text.EMPTY
121121
: Text.of(Text.NEW_LINE, TextColors.BLUE, TextActions.openUrl(e.url()), e.url().toString());
122122
String d = e.description();
123-
Text desc = d.isEmpty() || d == null ? Text.EMPTY : Text.of(Text.NEW_LINE, TextColors.AQUA, e.description());
123+
Text desc = d == null || d.isEmpty() ? Text.EMPTY : Text.of(Text.NEW_LINE, TextColors.AQUA, e.description());
124124
Text reload = Text.of(Text.NEW_LINE, Messages.get().placeholder.clickReload.t(), " ", reload(e.id()));
125125
Text support = supportedTokens.isEmpty() ? Text.EMPTY
126126
: Text.of(Text.NEW_LINE, Messages.get().placeholder.supportedPlaceholders.t(),

src/main/java/me/rojo8399/placeholderapi/impl/placeholder/Expansion.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,8 @@ void setConfig(Object o) {
347347
* Popoulate configuration object. Override only if necessary.
348348
*/
349349
protected void populateConfigObject() {
350-
if (configObject == null) {
350+
if (configObject == null || PlaceholderAPIPlugin.getInstance() == null
351+
|| PlaceholderAPIPlugin.getInstance().getRootConfig() == null) {
351352
return;
352353
}
353354
ConfigurationNode node = PlaceholderAPIPlugin.getInstance().getRootConfig().getNode("expansions",

src/main/java/me/rojo8399/placeholderapi/impl/placeholder/ExpansionBuilderImpl.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ of this software and associated documentation files (the "Software"), to deal
4545

4646
import me.rojo8399.placeholderapi.ExpansionBuilder;
4747
import me.rojo8399.placeholderapi.Placeholder;
48-
import me.rojo8399.placeholderapi.impl.utils.TypeUtils;
4948

5049
/**
5150
* @author Wundero
@@ -142,7 +141,7 @@ public static <S, O, V> ExpansionBuilderImpl<S, O, V> builder() {
142141
return new ExpansionBuilderImpl<S, O, V>(true);
143142
}
144143

145-
private static <S, O, V> ExpansionBuilderImpl<S, O, V> unverified() {
144+
public static <S, O, V> ExpansionBuilderImpl<S, O, V> unverified() {
146145
return new ExpansionBuilderImpl<S, O, V>(false);
147146
}
148147

@@ -512,13 +511,13 @@ public void unregisterListeners() {
512511
@SuppressWarnings({ "rawtypes" })
513512
private ExpansionBuilderImpl frommethod(Object o, Method m, Object p) {
514513
Expansion<?, ?, ?> exp = Store.get().createForMethod(m, o, p);
515-
return from(this, exp);
514+
return from(this.id(exp.id()).plugin(p), exp);
516515
}
517516

518517
@SuppressWarnings("unchecked")
519518
private static <S, O, V> ExpansionBuilderImpl<S, O, V> from(ExpansionBuilderImpl<?, ?, ?> builder,
520519
final Expansion<S, O, V> exp) {
521-
if (!(builder instanceof ExpansionBuilderImpl) || !exp.verify()) {
520+
if (!exp.verify()) {
522521
return (ExpansionBuilderImpl<S, O, V>) builder;
523522
}
524523
ExpansionBuilderImpl<?, ?, ?> b = (ExpansionBuilderImpl<?, ?, ?>) builder;
@@ -566,6 +565,7 @@ private static <S, O, V> ExpansionBuilderImpl<S, O, V> from(ExpansionBuilderImpl
566565
* The plugin holding the expansion.
567566
* @return This builder.
568567
*/
568+
@SuppressWarnings("unchecked")
569569
@Override
570570
public ExpansionBuilderImpl<S, O, V> from(Object obj, String id, Object plugin) {
571571
Class<?> clazz = obj.getClass();
@@ -578,10 +578,7 @@ public ExpansionBuilderImpl<S, O, V> from(Object obj, String id, Object plugin)
578578
}
579579
togglerel = true;
580580
}
581-
frommethod(obj, m, plugin);
582-
this.id(id);
583-
this.relational = TypeUtils.xor(togglerel, relational);
584-
return plugin(plugin);
581+
return frommethod(obj, m, plugin);
585582
}
586583

587584
/**

0 commit comments

Comments
 (0)