forked from Upstream/CommandPanels
3.19.1.3
This commit is contained in:
parent
27648b7642
commit
f384bec035
2
pom.xml
2
pom.xml
@ -129,7 +129,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-io</groupId>
|
<groupId>commons-io</groupId>
|
||||||
<artifactId>commons-io</artifactId>
|
<artifactId>commons-io</artifactId>
|
||||||
<version>2.11.0</version>
|
<version>2.13.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.bencodez</groupId>
|
<groupId>com.bencodez</groupId>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
version: 3.19.1.2
|
version: 3.19.1.3
|
||||||
main: me.rockyhawk.commandpanels.CommandPanels
|
main: me.rockyhawk.commandpanels.CommandPanels
|
||||||
name: CommandPanels
|
name: CommandPanels
|
||||||
author: RockyHawk
|
author: RockyHawk
|
||||||
|
@ -122,7 +122,7 @@ public class Utils implements Listener {
|
|||||||
|
|
||||||
if(panel.getConfig().contains("item." + clickedSlot + section + ".commands")) {
|
if(panel.getConfig().contains("item." + clickedSlot + section + ".commands")) {
|
||||||
List<String> commands = panel.getConfig().getStringList("item." + clickedSlot + section + ".commands");
|
List<String> commands = panel.getConfig().getStringList("item." + clickedSlot + section + ".commands");
|
||||||
if (commands.size() != 0) {
|
if (!commands.isEmpty()) {
|
||||||
//this will replace a sequence tag command with the commands from the sequence
|
//this will replace a sequence tag command with the commands from the sequence
|
||||||
List<String> commandsAfterSequence = commands;
|
List<String> commandsAfterSequence = commands;
|
||||||
for (int i = 0; commands.size() - 1 >= i; i++) {
|
for (int i = 0; commands.size() - 1 >= i; i++) {
|
||||||
@ -146,8 +146,9 @@ public class Utils implements Listener {
|
|||||||
plugin.commandTags.runMultiPaywall(panel,position,p,
|
plugin.commandTags.runMultiPaywall(panel,position,p,
|
||||||
panel.getConfig().getStringList("item." + clickedSlot + section + ".multi-paywall"),
|
panel.getConfig().getStringList("item." + clickedSlot + section + ".multi-paywall"),
|
||||||
commands,e.getClick());
|
commands,e.getClick());
|
||||||
} else
|
} else {
|
||||||
plugin.commandTags.runCommands(panel,position,p,commands,e.getClick());
|
plugin.commandTags.runCommands(panel, position, p, commands, e.getClick());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,11 +11,8 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.inventory.meta.SkullMeta;
|
import org.bukkit.inventory.meta.SkullMeta;
|
||||||
import org.json.simple.JSONArray;
|
|
||||||
import org.json.simple.JSONObject;
|
|
||||||
import org.json.simple.parser.JSONParser;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
@ -25,6 +22,7 @@ import java.net.URLConnection;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.Scanner;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class GetCustomHeads {
|
public class GetCustomHeads {
|
||||||
@ -90,25 +88,25 @@ public class GetCustomHeads {
|
|||||||
URLConnection uuidConnection = uuidUrl.openConnection();
|
URLConnection uuidConnection = uuidUrl.openConnection();
|
||||||
uuidConnection.setConnectTimeout(2000); // Set connection timeout to 2 seconds
|
uuidConnection.setConnectTimeout(2000); // Set connection timeout to 2 seconds
|
||||||
uuidConnection.setReadTimeout(2000); // Set read timeout to 2 seconds
|
uuidConnection.setReadTimeout(2000); // Set read timeout to 2 seconds
|
||||||
Reader uuidReader = new InputStreamReader(uuidConnection.getInputStream(), StandardCharsets.UTF_8);
|
//Json is simple and structured so a hard code solution will avoid the need for a library
|
||||||
JSONObject uuidResponse = (JSONObject) new JSONParser().parse(uuidReader);
|
String uuidReader = new Scanner(uuidConnection.getInputStream(),
|
||||||
String uuid = (String) uuidResponse.get("id");
|
StandardCharsets.UTF_8.name()).useDelimiter("\\A").next();
|
||||||
|
String uuid = uuidReader.split("\"id\" : \"")[1].split("\"")[0];
|
||||||
|
|
||||||
// Fetch the skin texture from the Mojang API using the player UUID
|
// Fetch the skin texture from the Mojang API using the player UUID
|
||||||
URL texturesUrl = new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid);
|
URL texturesUrl = new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid);
|
||||||
URLConnection texturesConnection = texturesUrl.openConnection();
|
URLConnection texturesConnection = texturesUrl.openConnection();
|
||||||
texturesConnection.setConnectTimeout(2000); // Set connection timeout to 2 seconds
|
texturesConnection.setConnectTimeout(2000); // Set connection timeout to 2 seconds
|
||||||
texturesConnection.setReadTimeout(2000); // Set read timeout to 2 seconds
|
texturesConnection.setReadTimeout(2000); // Set read timeout to 2 seconds
|
||||||
Reader texturesReader = new InputStreamReader(texturesConnection.getInputStream(), StandardCharsets.UTF_8);
|
//Json is simple and structured so a hard code solution will avoid the need for a library
|
||||||
JSONObject texturesResponse = (JSONObject) new JSONParser().parse(texturesReader);
|
String valueReader = new Scanner(texturesConnection.getInputStream(),
|
||||||
JSONArray propertiesArray = (JSONArray) texturesResponse.get("properties");
|
StandardCharsets.UTF_8.name()).useDelimiter("\\A").next();
|
||||||
JSONObject texturesProperty = (JSONObject) propertiesArray.get(0);
|
String value = valueReader.split("\"value\" : \"")[1].split("\"")[0];
|
||||||
String base64Texture = (String) texturesProperty.get("value");
|
playerHeadTextures.put(name, value);
|
||||||
playerHeadTextures.put(name, base64Texture);
|
|
||||||
|
|
||||||
// Once the API call is finished, update the ItemStack on the main thread
|
// Once the API call is finished, update the ItemStack on the main thread
|
||||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||||
itemStack.setItemMeta(getCustomHead(base64Texture).getItemMeta());
|
itemStack.setItemMeta(getCustomHead(value).getItemMeta());
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// Handle exceptions
|
// Handle exceptions
|
||||||
@ -121,6 +119,11 @@ public class GetCustomHeads {
|
|||||||
return itemStack;
|
return itemStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String inputStreamToString(InputStream inputStream) {
|
||||||
|
Scanner scanner = new Scanner(inputStream, StandardCharsets.UTF_8.name()).useDelimiter("\\A");
|
||||||
|
return scanner.hasNext() ? scanner.next() : "";
|
||||||
|
}
|
||||||
|
|
||||||
//used to get heads from Base64 Textures
|
//used to get heads from Base64 Textures
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public ItemStack getCustomHead(String b64stringtexture) {
|
public ItemStack getCustomHead(String b64stringtexture) {
|
||||||
|
@ -64,20 +64,16 @@ public class CommandTags {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void runMultiPaywall(Panel panel, PanelPosition position, Player p, List<String> paywalls, List<String> commands, ClickType click) {
|
public void runMultiPaywall(Panel panel, PanelPosition position, Player p, List<String> paywalls, List<String> commands, ClickType click) {
|
||||||
List<String> cmds = new ArrayList<String>();
|
boolean allPaywallsValid = paywalls.stream()
|
||||||
for (String command : paywalls) {
|
.map(command -> plugin.commandTags.commandPayWall(panel, p, command, false))
|
||||||
PaywallOutput val = plugin.commandTags.commandPayWall(panel, p, command, false);
|
.allMatch(val -> val != PaywallOutput.Blocked);
|
||||||
// Stop the for loop if 1 of the outputs is blocked
|
|
||||||
if (val == PaywallOutput.Blocked) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// add the paywall so it will be executed in runCommands
|
|
||||||
cmds.add(command);
|
|
||||||
}
|
|
||||||
// Add the commands last so paywalls run first
|
|
||||||
cmds.addAll(commands);
|
|
||||||
plugin.commandTags.runCommands(panel, position, p, cmds, click);
|
|
||||||
|
|
||||||
|
if (allPaywallsValid) {
|
||||||
|
List<String> cmds = new ArrayList<>();
|
||||||
|
cmds.addAll(paywalls);
|
||||||
|
cmds.addAll(commands);
|
||||||
|
plugin.commandTags.runCommands(panel, position, p, cmds, click);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void runCommand(Panel panel, PanelPosition position, Player p, String commandRAW) {
|
public void runCommand(Panel panel, PanelPosition position, Player p, String commandRAW) {
|
||||||
@ -209,7 +205,9 @@ public class CommandTags {
|
|||||||
assert api != null;
|
assert api != null;
|
||||||
int balance = Integer.parseInt(Long.toString(api.getTokens(p).orElse(0)));
|
int balance = Integer.parseInt(Long.toString(api.getTokens(p).orElse(0)));
|
||||||
if (balance >= Double.parseDouble(command.split("\\s")[1])) {
|
if (balance >= Double.parseDouble(command.split("\\s")[1])) {
|
||||||
if (removal) api.removeTokens(p, Long.parseLong(command.split("\\s")[1]));
|
if (removal) {
|
||||||
|
api.removeTokens(p, Long.parseLong(command.split("\\s")[1]));
|
||||||
|
}
|
||||||
//if the message is empty don't send
|
//if the message is empty don't send
|
||||||
if (plugin.config.getBoolean("purchase.tokens.enable") && removal) {
|
if (plugin.config.getBoolean("purchase.tokens.enable") && removal) {
|
||||||
plugin.tex.sendString(panel, PanelPosition.Top, p, Objects.requireNonNull(plugin.config.getString("purchase.tokens.success")).replaceAll("%cp-args%", command.split("\\s")[1]));
|
plugin.tex.sendString(panel, PanelPosition.Top, p, Objects.requireNonNull(plugin.config.getString("purchase.tokens.success")).replaceAll("%cp-args%", command.split("\\s")[1]));
|
||||||
@ -298,8 +296,9 @@ public class CommandTags {
|
|||||||
|
|
||||||
if (plugin.isMMOItem(itm, mmoType, mmoID) && sellItem.getAmount() <= itm.getAmount()) {
|
if (plugin.isMMOItem(itm, mmoType, mmoID) && sellItem.getAmount() <= itm.getAmount()) {
|
||||||
if (plugin.inventorySaver.hasNormalInventory(p)) {
|
if (plugin.inventorySaver.hasNormalInventory(p)) {
|
||||||
if (removal)
|
if (removal) {
|
||||||
p.getInventory().getItem(f).setAmount(itm.getAmount() - sellItem.getAmount());
|
p.getInventory().getItem(f).setAmount(itm.getAmount() - sellItem.getAmount());
|
||||||
|
}
|
||||||
p.updateInventory();
|
p.updateInventory();
|
||||||
} else {
|
} else {
|
||||||
if (removal) itm.setAmount(itm.getAmount() - sellItem.getAmount());
|
if (removal) itm.setAmount(itm.getAmount() - sellItem.getAmount());
|
||||||
@ -367,7 +366,7 @@ public class CommandTags {
|
|||||||
if (f == remCont.size() - 1) {
|
if (f == remCont.size() - 1) {
|
||||||
if (plugin.inventorySaver.hasNormalInventory(p)) {
|
if (plugin.inventorySaver.hasNormalInventory(p)) {
|
||||||
if (removal)
|
if (removal)
|
||||||
p.getInventory().getItem((int) remItem.getDurability()).setAmount(remItem.getAmount() - sellItem.getAmount());
|
p.getInventory().getItem(remItem.getDurability()).setAmount(remItem.getAmount() - sellItem.getAmount());
|
||||||
p.updateInventory();
|
p.updateInventory();
|
||||||
} else {
|
} else {
|
||||||
if (removal)
|
if (removal)
|
||||||
@ -379,7 +378,7 @@ public class CommandTags {
|
|||||||
if (removal) p.getInventory().getItem(remItem.getDurability()).setAmount(0);
|
if (removal) p.getInventory().getItem(remItem.getDurability()).setAmount(0);
|
||||||
p.updateInventory();
|
p.updateInventory();
|
||||||
} else {
|
} else {
|
||||||
if (removal) cont.get((int) remItem.getDurability()).setAmount(0);
|
if (removal) cont.get(remItem.getDurability()).setAmount(0);
|
||||||
plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0])));
|
plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0])));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package me.rockyhawk.commandpanels.commandtags.tags.other;
|
|||||||
|
|
||||||
import me.rockyhawk.commandpanels.CommandPanels;
|
import me.rockyhawk.commandpanels.CommandPanels;
|
||||||
import me.rockyhawk.commandpanels.commandtags.CommandTagEvent;
|
import me.rockyhawk.commandpanels.commandtags.CommandTagEvent;
|
||||||
import org.apache.commons.lang.ArrayUtils;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
@ -24,7 +23,7 @@ public class PlaceholderTags implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Character[] cm = ArrayUtils.toObject(cmd.toCharArray());
|
Character[] cm = convertToCharacterArray(cmd.toCharArray());
|
||||||
for(int i = 0; i < cm.length; i++){
|
for(int i = 0; i < cm.length; i++){
|
||||||
if(cm[i].equals('[')){
|
if(cm[i].equals('[')){
|
||||||
String contents = cmd.substring(i+1, i+cmd.substring(i).indexOf(']'));
|
String contents = cmd.substring(i+1, i+cmd.substring(i).indexOf(']'));
|
||||||
@ -48,7 +47,7 @@ public class PlaceholderTags implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Character[] cm = ArrayUtils.toObject(cmd.toCharArray());
|
Character[] cm = convertToCharacterArray(cmd.toCharArray());
|
||||||
for (int i = 0; i < cm.length; i++) {
|
for (int i = 0; i < cm.length; i++) {
|
||||||
if (cm[i].equals('[')) {
|
if (cm[i].equals('[')) {
|
||||||
String contents = cmd.substring(i + 1, i + cmd.substring(i).indexOf(']'));
|
String contents = cmd.substring(i + 1, i + cmd.substring(i).indexOf(']'));
|
||||||
@ -65,4 +64,12 @@ public class PlaceholderTags implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Character[] convertToCharacterArray(char[] charArray) {
|
||||||
|
Character[] characterArray = new Character[charArray.length];
|
||||||
|
for (int i = 0; i < charArray.length; i++) {
|
||||||
|
characterArray[i] = charArray[i];
|
||||||
|
}
|
||||||
|
return characterArray;
|
||||||
|
}
|
||||||
}
|
}
|
@ -4,7 +4,6 @@ import me.rockyhawk.commandpanels.CommandPanels;
|
|||||||
import me.rockyhawk.commandpanels.api.Panel;
|
import me.rockyhawk.commandpanels.api.Panel;
|
||||||
import me.rockyhawk.commandpanels.commandtags.CommandTagEvent;
|
import me.rockyhawk.commandpanels.commandtags.CommandTagEvent;
|
||||||
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
||||||
import org.apache.commons.lang.ArrayUtils;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -38,7 +37,7 @@ public class SpecialTags implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Character[] cm = ArrayUtils.toObject(cmd.toCharArray());
|
Character[] cm = convertToCharacterArray(cmd.toCharArray());
|
||||||
for(int i = 0; i < cm.length; i++){
|
for(int i = 0; i < cm.length; i++){
|
||||||
if(cm[i].equals('[')){
|
if(cm[i].equals('[')){
|
||||||
String contents = cmd.substring(i+1, i+cmd.substring(i).indexOf(']'));
|
String contents = cmd.substring(i+1, i+cmd.substring(i).indexOf(']'));
|
||||||
@ -151,4 +150,12 @@ public class SpecialTags implements Listener {
|
|||||||
}.runTaskTimer(plugin, delayTicks, 1); //20 ticks == 1 second
|
}.runTaskTimer(plugin, delayTicks, 1); //20 ticks == 1 second
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Character[] convertToCharacterArray(char[] charArray) {
|
||||||
|
Character[] characterArray = new Character[charArray.length];
|
||||||
|
for (int i = 0; i < charArray.length; i++) {
|
||||||
|
characterArray[i] = charArray[i];
|
||||||
|
}
|
||||||
|
return characterArray;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user