Skip to content

Commit 2326630

Browse files
WunderoWundero
Wundero
authored and
Wundero
committed
Removed breaking expansion changes
This will be for version 3.12, the last update before annotation + builder rewrite.
1 parent 6bfc123 commit 2326630

File tree

8 files changed

+68
-7
lines changed

8 files changed

+68
-7
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
}
55

66
group = 'me.rojo8399.placeholderapi'
7-
version = '4.0'
7+
version = '3.12'
88
description = 'An API for all of your placeholders.'
99

1010
compileJava.options.encoding = 'UTF-8'

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public class PlaceholderAPIPlugin {
8585

8686
public static final String PLUGIN_ID = "placeholderapi";
8787
public static final String PLUGIN_NAME = "PlaceholderAPI";
88-
public static final String PLUGIN_VERSION = "4.0";
88+
public static final String PLUGIN_VERSION = "3.12";
8989
private static PlaceholderAPIPlugin instance;
9090

9191
@Inject

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ public String getVersion() {
250250
}
251251

252252
@Override
253-
public Object onValueRequest(Player player, Optional<String> token) {
253+
public Text onPlaceholderRequest(Player player, Optional<String> token) {
254254
return function.apply(player, token);
255255
}
256256

src/main/java/me/rojo8399/placeholderapi/expansions/Expansion.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ of this software and associated documentation files (the "Software"), to deal
3333

3434
import org.spongepowered.api.entity.living.player.Player;
3535
import org.spongepowered.api.item.inventory.ItemStack;
36+
import org.spongepowered.api.item.inventory.ItemStackSnapshot;
3637
import org.spongepowered.api.text.Text;
3738
import org.spongepowered.api.text.serializer.TextSerializers;
3839

@@ -115,6 +116,9 @@ public default <T> Optional<T> onValueRequest(Player player, Optional<String> to
115116
if (val instanceof Text) {
116117
return TypeUtils.tryOptional(() -> expected.cast(val));
117118
} else {
119+
if (val instanceof ItemStackSnapshot) {
120+
return TypeUtils.tryOptional(() -> expected.cast(TextUtils.ofItem((ItemStackSnapshot) val)));
121+
}
118122
if (val instanceof ItemStack) {
119123
return TypeUtils.tryOptional(() -> expected.cast(TextUtils.ofItem((ItemStack) val)));
120124
}
@@ -149,16 +153,32 @@ public default <T> Optional<T> onValueRequest(Player player, Optional<String> to
149153
*
150154
* @return the value, as an object
151155
*/
152-
public Object onValueRequest(Player player, Optional<String> token);
156+
public default Object onValueRequest(Player player, Optional<String> token) {
157+
Text v = onPlaceholderRequest(player, token);
158+
boolean rets = v.getClickAction().isPresent() || v.getHoverAction().isPresent()
159+
|| v.getShiftClickAction().isPresent();
160+
String p = v.toPlain().toLowerCase().trim();
161+
try {
162+
return Integer.parseInt(p);
163+
} catch (Exception e) {
164+
try {
165+
return Double.parseDouble(p);
166+
} catch (Exception e2) {
167+
try {
168+
return Boolean.valueOf(p);
169+
} catch (Exception e3) {
170+
}
171+
}
172+
}
173+
return rets ? v : p;
174+
}
153175

154176
/**
155177
* Parse the token for the player
156178
*
157179
* @return the result of the parse as a text.
158180
*/
159-
public default Text onPlaceholderRequest(Player player, Optional<String> token) {
160-
return onValueRequest(player, token, Text.class).orElse(null);
161-
}
181+
public Text onPlaceholderRequest(Player player, Optional<String> token);
162182

163183
/**
164184
* Parse the token for the player

src/main/java/me/rojo8399/placeholderapi/expansions/PlayerExpansion.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,4 +318,12 @@ public List<String> getSupportedRelationalTokens() {
318318
return Arrays.asList("distance", "distance_x", "distance_y", "distance_z", "visible", "audible");
319319
}
320320

321+
/* (non-Javadoc)
322+
* @see me.rojo8399.placeholderapi.expansions.Expansion#onPlaceholderRequest(org.spongepowered.api.entity.living.player.Player, java.util.Optional)
323+
*/
324+
@Override
325+
public Text onPlaceholderRequest(Player player, Optional<String> token) {
326+
return onValueRequest(player, token, Text.class).orElse(null);
327+
}
328+
321329
}

src/main/java/me/rojo8399/placeholderapi/expansions/RankExpansion.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ of this software and associated documentation files (the "Software"), to deal
2929

3030
import org.spongepowered.api.entity.living.player.Player;
3131
import org.spongepowered.api.service.permission.Subject;
32+
import org.spongepowered.api.text.Text;
3233

3334
import me.rojo8399.placeholderapi.PlaceholderAPIPlugin;
3435
import me.rojo8399.placeholderapi.configs.Messages;
@@ -132,6 +133,18 @@ public Object onValueRequest(Player player, Optional<String> token) {
132133
return null;
133134
}
134135

136+
/*
137+
* (non-Javadoc)
138+
*
139+
* @see
140+
* me.rojo8399.placeholderapi.expansions.Expansion#onPlaceholderRequest(org.
141+
* spongepowered.api.entity.living.player.Player, java.util.Optional)
142+
*/
143+
@Override
144+
public Text onPlaceholderRequest(Player player, Optional<String> token) {
145+
return onValueRequest(player, token, Text.class).orElse(null);
146+
}
147+
135148
/*
136149
* (non-Javadoc)
137150
*

src/main/java/me/rojo8399/placeholderapi/expansions/SoundExpansion.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@ public Object onValueRequest(Player p, Optional<String> identifier) {
8888

8989
}
9090

91+
/*
92+
* (non-Javadoc)
93+
*
94+
* @see
95+
* me.rojo8399.placeholderapi.expansions.Expansion#onPlaceholderRequest(org.
96+
* spongepowered.api.entity.living.player.Player, java.util.Optional)
97+
*/
98+
@Override
99+
public Text onPlaceholderRequest(Player player, Optional<String> token) {
100+
return onValueRequest(player, token, Text.class).orElse(null);
101+
}
102+
91103
/*
92104
* (non-Javadoc)
93105
*

src/main/java/me/rojo8399/placeholderapi/utils/TextUtils.java

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

3737
import org.spongepowered.api.data.key.Keys;
3838
import org.spongepowered.api.item.inventory.ItemStack;
39+
import org.spongepowered.api.item.inventory.ItemStackSnapshot;
3940
import org.spongepowered.api.text.Text;
4041
import org.spongepowered.api.text.TextTemplate;
4142
import org.spongepowered.api.text.action.TextActions;
@@ -96,6 +97,13 @@ public static Text ofItem(@Nullable ItemStack item) {
9697
}
9798
return Text.of(TextActions.showItem(item.createSnapshot()), item.getOrElse(Keys.DISPLAY_NAME, Text.of(item)));
9899
}
100+
101+
public static Text ofItem(@Nullable ItemStackSnapshot item) {
102+
if(item==null) {
103+
return Text.EMPTY;
104+
}
105+
return Text.of(TextActions.showItem(item), item.getOrElse(Keys.DISPLAY_NAME, Text.of(item)));
106+
}
99107

100108
private static Text fix(Text to, TextFormat l) {
101109
return to.toBuilder().format(l.merge(to.getFormat())).build();

0 commit comments

Comments
 (0)