Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
SpraxDev committed Oct 2, 2024
2 parents 4bc990c + c921925 commit d6ce8ad
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 74 deletions.
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.songoda</groupId>
<artifactId>EpicHeads</artifactId>
<version>4.1.1</version>
<version>4.3.0</version>

<name>EpicHeads</name>
<description>Allows you and your players to search over 19,000 unique and artistic heads – Perfect for building immersive masterpieces.</description>
Expand Down Expand Up @@ -35,7 +35,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.4.1</version>
<version>3.6.0</version>

<executions>
<execution>
Expand Down Expand Up @@ -74,10 +74,10 @@
<excludeDefaults>false</excludeDefaults>
<includes>
<include>**/nms/v*/**</include>
<include>**/third_party/net/kyori/**</include>
</includes>
<excludes>
<exclude>**/third_party/org/apache/**</exclude>
<exclude>**/third_party/net/kyori/**</exclude>
<exclude>**/third_party/com/zaxxer/**</exclude>
<exclude>**/third_party/org/jooq/**</exclude>
<exclude>**/third_party/org/mariadb/**</exclude>
Expand Down Expand Up @@ -118,7 +118,7 @@
<dependency>
<groupId>com.craftaro</groupId>
<artifactId>CraftaroCore</artifactId>
<version>3.0.0-SNAPSHOT</version>
<version>3.5.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/craftaro/epicheads/EpicHeads.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ private void downloadHeads() {
private boolean loadHeads() {
try {
this.headManager.clear();
this.headManager.addCategory(new Category(getLocale().getMessage("general.word.latestpack").getMessage(), true));
this.headManager.addCategory(new Category(getLocale().getMessage("general.word.latestpack").toText(), true));

JSONParser parser = new JSONParser();
JSONArray jsonArray = (JSONArray) parser.parse(new FileReader(getDataFolder() + "/heads.json"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import com.craftaro.core.commands.AbstractCommand;
import com.craftaro.core.compatibility.CompatibleHand;
import com.craftaro.core.utils.ItemUtils;
import com.craftaro.epicheads.EpicHeads;
import com.craftaro.third_party.com.cryptomorin.xseries.SkullUtils;
import com.craftaro.third_party.com.cryptomorin.xseries.profiles.builder.XSkull;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
Expand All @@ -29,7 +28,7 @@ protected ReturnType runCommand(CommandSender sender, String... args) {
if (!item.hasItemMeta() || !(item.getItemMeta() instanceof SkullMeta)) {
return ReturnType.FAILURE;
}
String encodededStr = SkullUtils.getSkinValue(item.getItemMeta());
String encodededStr = XSkull.of(item).getProfileValue();
if (encodededStr == null) {
return ReturnType.FAILURE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected ReturnType runCommand(CommandSender sender, String... args) {
.processPlaceholder("name", head.get().getName()).sendPrefixedMessage(pl);
}
this.plugin.getLocale().getMessage("command.give.success")
.processPlaceholder("player", this.plugin.getLocale().getMessage("general.word.everyone").getMessage())
.processPlaceholder("player", this.plugin.getLocale().getMessage("general.word.everyone").toText())
.processPlaceholder("name", head.get().getName())
.sendPrefixedMessage(sender);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.craftaro.epicheads.commands;

import com.craftaro.core.chat.ChatMessage;
import com.craftaro.core.chat.AdventureUtils;
import com.craftaro.core.commands.AbstractCommand;
import com.craftaro.core.third_party.net.kyori.adventure.text.Component;
import com.craftaro.core.utils.TextUtils;
import com.craftaro.epicheads.EpicHeads;
import org.bukkit.ChatColor;
Expand All @@ -20,9 +21,9 @@ public CommandHelp(EpicHeads plugin) {
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
sender.sendMessage("");
new ChatMessage().fromText(String.format("#ff8080&l%s &8» &7Version %s Created with <3 by #ec4e74&l&oS#fa5b65&l&oo#ff6c55&l&on#ff7f44&l&og#ff9432&l&oo#ffaa1e&l&od#f4c009&l&oa",
this.plugin.getDescription().getName(), this.plugin.getDescription().getVersion()))
.sendTo(sender);
Component component = AdventureUtils.formatComponent(String.format("<color:#ff8080>&l%s &8» &7Version %s Created with <3 by <gradient:#ec4e74:#f4c009><b><o>Songoda</o></b></gradient>",
this.plugin.getDescription().getName(), this.plugin.getDescription().getVersion()));
AdventureUtils.sendMessage(this.plugin, component, sender);
sender.sendMessage("");
sender.sendMessage(TextUtils.formatText("&7Welcome to EpicHeads! To get started try using the command /heads to access the heads panel."));
sender.sendMessage("");
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/craftaro/epicheads/commands/CommandUrl.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.craftaro.core.compatibility.CompatibleHand;
import com.craftaro.core.utils.ItemUtils;
import com.craftaro.epicheads.EpicHeads;
import com.craftaro.third_party.com.cryptomorin.xseries.SkullUtils;
import com.craftaro.third_party.com.cryptomorin.xseries.profiles.builder.XSkull;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
Expand All @@ -29,14 +29,14 @@ protected AbstractCommand.ReturnType runCommand(CommandSender sender, String...
return ReturnType.FAILURE;
}

String encodedStr = SkullUtils.getSkinValue(item.getItemMeta());
String encodedStr = XSkull.of(item).getProfileValue();
if (encodedStr == null) {
return ReturnType.FAILURE;
}

String url = ItemUtils.getDecodedTexture(encodedStr);

player.sendMessage(this.plugin.getLocale().newMessage("http://textures.minecraft.net/texture/" + url).getPrefixedMessage());
this.plugin.getLocale().newMessage("http://textures.minecraft.net/texture/" + url).sendPrefixedMessage(player);
return ReturnType.SUCCESS;
}

Expand Down
28 changes: 20 additions & 8 deletions src/main/java/com/craftaro/epicheads/database/DataHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.craftaro.core.database.DataManager;
import com.craftaro.core.database.DatabaseConnector;
import com.craftaro.core.database.DatabaseType;
import com.craftaro.epicheads.EpicHeads;
import com.craftaro.epicheads.head.Head;
import com.craftaro.epicheads.players.EPlayer;
Expand Down Expand Up @@ -54,17 +55,28 @@ public static void getPlayer(Player player, Consumer<EPlayer> callback) {
Gson gson = new Gson();
dataManager.getAsyncPool().submit(() -> {
try (Connection connection = databaseConnector.getConnection()) {
String insertPlayer = "REPLACE INTO " + getTablePrefix() + "players (uuid, favorites) VALUES (?, ?)";
String selectPlayers = "SELECT * FROM " + getTablePrefix() + "players WHERE uuid = ?";
String sql;
boolean isH2 = databaseConnector.getType().equals(DatabaseType.H2);

try (PreparedStatement insert = connection.prepareStatement(insertPlayer);
PreparedStatement statement = connection.prepareStatement(selectPlayers)) {
insert.setString(1, player.getUniqueId().toString());
insert.setString(2, gson.toJson(new ArrayList<>()));
insert.execute();
if (!isH2) {
sql = "INSERT INTO " + getTablePrefix() + "players (uuid, favorites) VALUES (?, ?) ON DUPLICATE KEY UPDATE favorites = ?";
} else {
sql = "MERGE INTO " + getTablePrefix() + "players (uuid, favorites) KEY(uuid) VALUES (?, ?)";
}

String selectPlayers = "SELECT * FROM " + getTablePrefix() + "players WHERE uuid = ?";

try (PreparedStatement statement = connection.prepareStatement(sql);
PreparedStatement selectStatement = connection.prepareStatement(selectPlayers)) {
statement.setString(1, player.getUniqueId().toString());
ResultSet result = statement.executeQuery();
statement.setString(2, gson.toJson(new ArrayList<>()));
if (!isH2) {
statement.setString(3, gson.toJson(new ArrayList<>()));
}
statement.execute();

selectStatement.setString(1, player.getUniqueId().toString());
ResultSet result = selectStatement.executeQuery();
if (result.next()) {
UUID uuid = UUID.fromString(result.getString("uuid"));
List<String> favorites = gson.fromJson(result.getString("favorites"), new TypeToken<List<String>>() {
Expand Down
27 changes: 14 additions & 13 deletions src/main/java/com/craftaro/epicheads/gui/GUIHeads.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.craftaro.epicheads.gui;

import com.craftaro.core.chat.AdventureUtils;
import com.craftaro.core.gui.Gui;
import com.craftaro.core.gui.GuiManager;
import com.craftaro.core.gui.GuiUtils;
Expand Down Expand Up @@ -63,22 +64,22 @@ private void updateTitle() {

switch (this.type) {
case SEARCH:
name = this.plugin.getLocale().getMessage("general.word.query").getMessage() + ": " + this.query;
name = this.plugin.getLocale().getMessage("general.word.query").toText() + ": " + this.query;
break;
case CATEGORY:
name = category.getName();
break;
case FAVORITES:
name = this.plugin.getLocale().getMessage("general.word.favorites").getMessage();
name = this.plugin.getLocale().getMessage("general.word.favorites").toText();
break;
case PACK:
name = this.plugin.getLocale().getMessage("general.phrase.latestpack").getMessage();
name = this.plugin.getLocale().getMessage("general.phrase.latestpack").toText();
break;
}

this.pages = (int) Math.ceil(numHeads / 45.0);

this.setTitle(name + " (" + numHeads + ") " + this.plugin.getLocale().getMessage("general.word.page").getMessage() + " " + (this.page) + "/" + (this.pages));
this.setTitle(name + " (" + numHeads + ") " + this.plugin.getLocale().getMessage("general.word.page").toText() + " " + (this.page) + "/" + (this.pages));
}

private void showPage() {
Expand All @@ -88,7 +89,7 @@ private void showPage() {

if (this.page - 3 >= 1) {
setButton(0, GuiUtils.createButtonItem(XMaterial.ARROW, this.page - 3,
ChatColor.RED.toString() + this.plugin.getLocale().getMessage("general.word.page").getMessage() + " " + (this.page - 3)),
ChatColor.RED.toString() + this.plugin.getLocale().getMessage("general.word.page").toText() + " " + (this.page - 3)),
(event) -> changePage(-3));
} else {
clearActions(0);
Expand All @@ -97,7 +98,7 @@ private void showPage() {

if (this.page - 2 >= 1) {
setButton(1, GuiUtils.createButtonItem(XMaterial.ARROW, this.page - 2,
ChatColor.RED.toString() + this.plugin.getLocale().getMessage("general.word.page").getMessage() + " " + (this.page - 2)),
ChatColor.RED.toString() + this.plugin.getLocale().getMessage("general.word.page").toText() + " " + (this.page - 2)),
(event) -> changePage(-2));
} else {
clearActions(1);
Expand All @@ -106,7 +107,7 @@ private void showPage() {

if (this.page > 1) {
setButton(2, GuiUtils.createButtonItem(XMaterial.ARROW, this.page - 1,
ChatColor.RED.toString() + this.plugin.getLocale().getMessage("general.word.page").getMessage() + " " + (this.page - 1)),
ChatColor.RED.toString() + this.plugin.getLocale().getMessage("general.word.page").toText() + " " + (this.page - 1)),
(event) -> changePage(-1));
} else {
clearActions(2);
Expand All @@ -118,14 +119,14 @@ private void showPage() {
(event) -> doSearch(this.plugin, this, this.guiManager, event.player));

setButton(4, GuiUtils.createButtonItem(XMaterial.MAP, this.page,
this.plugin.getLocale().getMessage("gui.heads.categories").getMessage()), (event) -> this.guiManager.showGUI(this.player, new GUIOverview(event.player)));
this.plugin.getLocale().getMessage("gui.heads.categories").toText()), (event) -> this.guiManager.showGUI(this.player, new GUIOverview(event.player)));

if (pageHeads.size() > 1) {
setButton(5, GuiUtils.createButtonItem(XMaterial.COMPASS,
this.plugin.getLocale().getMessage("gui.heads.refine").getMessage()),
(event) -> {
exit();
ChatPrompt.showPrompt(this.plugin, event.player, this.plugin.getLocale().getMessage("general.search.refine").getPrefixedMessage(), promptEvent -> {
ChatPrompt.showPrompt(this.plugin, event.player, AdventureUtils.toLegacy(this.plugin.getLocale().getMessage("general.search.refine").getPrefixedMessage()), promptEvent -> {
this.page = 1;
this.heads = this.heads.stream().filter(head -> head.getName().toLowerCase()
.contains(promptEvent.getMessage().toLowerCase())).collect(Collectors.toList());
Expand All @@ -138,7 +139,7 @@ private void showPage() {
showPage();
this.guiManager.showGUI(event.player, this);
}).setOnCancel(() -> {
event.player.sendMessage(this.plugin.getLocale().getMessage("general.search.canceled").getPrefixedMessage());
this.plugin.getLocale().getMessage("general.search.canceled").sendPrefixedMessage(event.player);
});
});
}
Expand Down Expand Up @@ -186,7 +187,7 @@ private void showPage() {
ItemStack item = head.asItemStack(favorites.contains(head.getUrl()), free);
ItemMeta meta = item.getItemMeta();
List<String> lore = item.getItemMeta().getLore();
lore.add(this.plugin.getLocale().getMessage("gui.heads.delete").getMessage());
lore.add(this.plugin.getLocale().getMessage("gui.heads.delete").toText());
meta.setLore(lore);
item.setItemMeta(meta);

Expand All @@ -213,7 +214,7 @@ private void showPage() {
if (EconomyManager.hasBalance(this.player, cost)) {
EconomyManager.withdrawBalance(this.player, cost);
} else {
this.player.sendMessage(this.plugin.getLocale().getMessage("event.buyhead.cannotafford").getMessage());
this.player.sendMessage(this.plugin.getLocale().getMessage("event.buyhead.cannotafford").toText());
return;
}
} else {
Expand Down Expand Up @@ -242,7 +243,7 @@ public static void doSearch(EpicHeads plugin, Gui activeGui, GuiManager guiManag
if (activeGui != null) {
activeGui.exit();
}
ChatPrompt.showPrompt(plugin, player, plugin.getLocale().getMessage("general.search.global").getPrefixedMessage(), response -> {
ChatPrompt.showPrompt(plugin, player, AdventureUtils.toLegacy(plugin.getLocale().getMessage("general.search.global").getPrefixedMessage()), response -> {
List<Head> searchHeads = plugin.getHeadManager().getHeads().stream()
.filter(head -> head.getName().toLowerCase().contains(response.getMessage().toLowerCase()))
.filter(head -> player.hasPermission("epicheads.category." + head.getCategory().getName().replace(" ", "_")))
Expand Down
18 changes: 5 additions & 13 deletions src/main/java/com/craftaro/epicheads/gui/GUIOverview.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

import com.craftaro.core.gui.Gui;
import com.craftaro.core.gui.GuiUtils;
import com.craftaro.core.utils.SkullItemCreator;
import com.craftaro.epicheads.EpicHeads;
import com.craftaro.epicheads.head.Category;
import com.craftaro.epicheads.head.Head;
import com.craftaro.epicheads.settings.Settings;
import com.craftaro.third_party.com.cryptomorin.xseries.SkullUtils;
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import java.util.List;
import java.util.Random;
Expand Down Expand Up @@ -40,7 +39,7 @@ public GUIOverview(Player player) {
private void showPage() {
setButton(4, GuiUtils.createButtonItem(XMaterial.GOLDEN_APPLE,
this.plugin.getLocale().getMessage("gui.overview.viewfavorites").getMessage(),
this.plugin.getLocale().getMessage("gui.overview.favoriteslore").getMessage().split("\\|")),
this.plugin.getLocale().getMessage("gui.overview.favoriteslore").getMessageLines('|')),
(event) -> this.guiManager.showGUI(this.player, new GUIHeads(this.plugin, this.player, null, GUIHeads.QueryTypes.FAVORITES,
this.plugin.getPlayerManager().getPlayer(this.player).getFavoritesAsHeads())));

Expand Down Expand Up @@ -81,11 +80,7 @@ private void showPage() {
continue;
}

ItemStack buttonItem = XMaterial.PLAYER_HEAD.parseItem();
ItemMeta buttonMeta = buttonItem.getItemMeta();
SkullUtils.applySkin(buttonMeta, firstHead.getUrl());
buttonItem.setItemMeta(buttonMeta);

ItemStack buttonItem = SkullItemCreator.byTextureUrl(firstHead.getUrl());
setButton(i + 10 + add, GuiUtils.createButtonItem(buttonItem,
this.plugin.getLocale().getMessage("gui.overview.headname")
.processPlaceholder("name", Color.getRandomColor() + category.getName())
Expand All @@ -105,14 +100,11 @@ private void showPage() {
(event) -> GUIHeads.doSearch(this.plugin, this, this.guiManager, event.player));

if (Settings.DISCORD.getBoolean()) {
ItemStack discordButtonItem = XMaterial.PLAYER_HEAD.parseItem();
ItemMeta discordButtonMeta = discordButtonItem.getItemMeta();
SkullUtils.applySkin(discordButtonMeta, "a3b183b148b9b4e2b158334aff3b5bb6c2c2dbbc4d67f76a7be856687a2b623");
discordButtonItem.setItemMeta(discordButtonMeta);
ItemStack discordButtonItem = SkullItemCreator.byTextureUrlHash("a3b183b148b9b4e2b158334aff3b5bb6c2c2dbbc4d67f76a7be856687a2b623");

setButton(41, GuiUtils.createButtonItem(discordButtonItem,
this.plugin.getLocale().getMessage("gui.overview.discord").getMessage(),
this.plugin.getLocale().getMessage("gui.overview.discordlore").getMessage().split("\\|")),
this.plugin.getLocale().getMessage("gui.overview.discordlore").getMessageLines('|')),
(event) -> {
this.plugin.getLocale().newMessage("&9https://songoda.com/discord").sendPrefixedMessage(this.player);
exit();
Expand Down
Loading

0 comments on commit d6ce8ad

Please sign in to comment.