This commit is contained in:
rockyhawk64 2023-08-16 18:06:47 +10:00
parent 27648b7642
commit f384bec035
7 changed files with 60 additions and 43 deletions

View File

@ -129,7 +129,7 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
<version>2.13.0</version>
</dependency>
<dependency>
<groupId>com.bencodez</groupId>

View File

@ -1,4 +1,4 @@
version: 3.19.1.2
version: 3.19.1.3
main: me.rockyhawk.commandpanels.CommandPanels
name: CommandPanels
author: RockyHawk

View File

@ -122,7 +122,7 @@ public class Utils implements Listener {
if(panel.getConfig().contains("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
List<String> commandsAfterSequence = commands;
for (int i = 0; commands.size() - 1 >= i; i++) {
@ -146,8 +146,9 @@ public class Utils implements Listener {
plugin.commandTags.runMultiPaywall(panel,position,p,
panel.getConfig().getStringList("item." + clickedSlot + section + ".multi-paywall"),
commands,e.getClick());
} else
plugin.commandTags.runCommands(panel,position,p,commands,e.getClick());
} else {
plugin.commandTags.runCommands(panel, position, p, commands, e.getClick());
}
}
}
}

View File

@ -11,11 +11,8 @@ import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
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.Reader;
import java.lang.reflect.Field;
@ -25,6 +22,7 @@ import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Scanner;
import java.util.UUID;
public class GetCustomHeads {
@ -90,25 +88,25 @@ public class GetCustomHeads {
URLConnection uuidConnection = uuidUrl.openConnection();
uuidConnection.setConnectTimeout(2000); // Set connection timeout to 2 seconds
uuidConnection.setReadTimeout(2000); // Set read timeout to 2 seconds
Reader uuidReader = new InputStreamReader(uuidConnection.getInputStream(), StandardCharsets.UTF_8);
JSONObject uuidResponse = (JSONObject) new JSONParser().parse(uuidReader);
String uuid = (String) uuidResponse.get("id");
//Json is simple and structured so a hard code solution will avoid the need for a library
String uuidReader = new Scanner(uuidConnection.getInputStream(),
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
URL texturesUrl = new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid);
URLConnection texturesConnection = texturesUrl.openConnection();
texturesConnection.setConnectTimeout(2000); // Set connection timeout to 2 seconds
texturesConnection.setReadTimeout(2000); // Set read timeout to 2 seconds
Reader texturesReader = new InputStreamReader(texturesConnection.getInputStream(), StandardCharsets.UTF_8);
JSONObject texturesResponse = (JSONObject) new JSONParser().parse(texturesReader);
JSONArray propertiesArray = (JSONArray) texturesResponse.get("properties");
JSONObject texturesProperty = (JSONObject) propertiesArray.get(0);
String base64Texture = (String) texturesProperty.get("value");
playerHeadTextures.put(name, base64Texture);
//Json is simple and structured so a hard code solution will avoid the need for a library
String valueReader = new Scanner(texturesConnection.getInputStream(),
StandardCharsets.UTF_8.name()).useDelimiter("\\A").next();
String value = valueReader.split("\"value\" : \"")[1].split("\"")[0];
playerHeadTextures.put(name, value);
// Once the API call is finished, update the ItemStack on the main thread
Bukkit.getScheduler().runTask(plugin, () -> {
itemStack.setItemMeta(getCustomHead(base64Texture).getItemMeta());
itemStack.setItemMeta(getCustomHead(value).getItemMeta());
});
} catch (Exception e) {
// Handle exceptions
@ -121,6 +119,11 @@ public class GetCustomHeads {
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
@SuppressWarnings("deprecation")
public ItemStack getCustomHead(String b64stringtexture) {
@ -167,4 +170,4 @@ public class GetCustomHeads {
return head;
}
}
}
}

View File

@ -64,20 +64,16 @@ public class CommandTags {
}
public void runMultiPaywall(Panel panel, PanelPosition position, Player p, List<String> paywalls, List<String> commands, ClickType click) {
List<String> cmds = new ArrayList<String>();
for (String command : paywalls) {
PaywallOutput val = plugin.commandTags.commandPayWall(panel, p, command, false);
// 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);
boolean allPaywallsValid = paywalls.stream()
.map(command -> plugin.commandTags.commandPayWall(panel, p, command, false))
.allMatch(val -> val != PaywallOutput.Blocked);
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) {
@ -209,7 +205,9 @@ public class CommandTags {
assert api != null;
int balance = Integer.parseInt(Long.toString(api.getTokens(p).orElse(0)));
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 (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]));
@ -298,8 +296,9 @@ public class CommandTags {
if (plugin.isMMOItem(itm, mmoType, mmoID) && sellItem.getAmount() <= itm.getAmount()) {
if (plugin.inventorySaver.hasNormalInventory(p)) {
if (removal)
if (removal) {
p.getInventory().getItem(f).setAmount(itm.getAmount() - sellItem.getAmount());
}
p.updateInventory();
} else {
if (removal) itm.setAmount(itm.getAmount() - sellItem.getAmount());
@ -367,7 +366,7 @@ public class CommandTags {
if (f == remCont.size() - 1) {
if (plugin.inventorySaver.hasNormalInventory(p)) {
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();
} else {
if (removal)
@ -379,7 +378,7 @@ public class CommandTags {
if (removal) p.getInventory().getItem(remItem.getDurability()).setAmount(0);
p.updateInventory();
} 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])));
}
}

View File

@ -2,7 +2,6 @@ package me.rockyhawk.commandpanels.commandtags.tags.other;
import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.commandtags.CommandTagEvent;
import org.apache.commons.lang.ArrayUtils;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@ -24,7 +23,7 @@ public class PlaceholderTags implements Listener {
return;
}
Character[] cm = ArrayUtils.toObject(cmd.toCharArray());
Character[] cm = convertToCharacterArray(cmd.toCharArray());
for(int i = 0; i < cm.length; i++){
if(cm[i].equals('[')){
String contents = cmd.substring(i+1, i+cmd.substring(i).indexOf(']'));
@ -48,7 +47,7 @@ public class PlaceholderTags implements Listener {
return;
}
Character[] cm = ArrayUtils.toObject(cmd.toCharArray());
Character[] cm = convertToCharacterArray(cmd.toCharArray());
for (int i = 0; i < cm.length; i++) {
if (cm[i].equals('[')) {
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;
}
}

View File

@ -4,7 +4,6 @@ import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
import me.rockyhawk.commandpanels.commandtags.CommandTagEvent;
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
import org.apache.commons.lang.ArrayUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
@ -38,7 +37,7 @@ public class SpecialTags implements Listener {
return;
}
Character[] cm = ArrayUtils.toObject(cmd.toCharArray());
Character[] cm = convertToCharacterArray(cmd.toCharArray());
for(int i = 0; i < cm.length; i++){
if(cm[i].equals('[')){
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
}
}
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;
}
}