From 375f0db70ca94c3de330775caae25cbdbbd41799 Mon Sep 17 00:00:00 2001 From: nivcoo Date: Mon, 29 Nov 2021 19:13:32 +0100 Subject: [PATCH] improv. fix error and convert to private key --- pom.xml | 17 +++++----- src/main/java/fr/nivcoo/pointz/Pointz.java | 8 ++--- .../fr/nivcoo/pointz/inventory/Inventory.java | 3 -- .../pointz/inventory/InventoryManager.java | 5 +-- .../nivcoo/pointz/inventory/ItemBuilder.java | 22 ------------- .../fr/nivcoo/pointz/utils/WebsiteAPI.java | 31 +++++++++---------- src/main/resources/config.yml | 16 +++++----- src/main/resources/plugin.yml | 2 +- 8 files changed, 37 insertions(+), 67 deletions(-) diff --git a/pom.xml b/pom.xml index ce58aff..54a7c88 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ fr.nivcoo Pointz - 2.5.1 + 2.6.0 jar ${project.artifactId} @@ -19,6 +19,10 @@ + + papermc + https://papermc.io/repo/repository/maven-public/ + vault-repo https://nexus.hc.to/content/repositories/pub_releases @@ -27,19 +31,16 @@ placeholderapi https://repo.extendedclip.com/content/repositories/placeholderapi/ - - private - https://edensky.fr/artifactory/private/ - + - org.spigotmc - spigot - 1.13.2 + com.destroystokyo.paper + paper-api + 1.13.2-R0.1-SNAPSHOT provided diff --git a/src/main/java/fr/nivcoo/pointz/Pointz.java b/src/main/java/fr/nivcoo/pointz/Pointz.java index 38842ac..00d2154 100644 --- a/src/main/java/fr/nivcoo/pointz/Pointz.java +++ b/src/main/java/fr/nivcoo/pointz/Pointz.java @@ -58,12 +58,11 @@ public void onEnable() { boolean pluginWebIsEnabled = false; try { - websiteAPI = new WebsiteAPI(config.getString("api.public_key"), config.getString("api.website_url")); + websiteAPI = new WebsiteAPI(config.getString("api.private_key"), config.getString("api.website_url")); goodKey = true; } catch (Exception e) { - e.printStackTrace(); Bukkit.getLogger() - .severe("[Pointz] The public_key isn't valid ! Please copy it on the website in config section"); + .severe("[Pointz] The private_key isn't valid ! Please copy it on the website in config section"); } if (websiteAPI != null) { HashMap check; @@ -126,7 +125,8 @@ public void onDisable() { if (inventoryManager != null) inventoryManager.closeAllInventories(); - cacheManager.stopScheduler(); + if (cacheManager != null) + cacheManager.stopScheduler(); } public void registerCommands() { diff --git a/src/main/java/fr/nivcoo/pointz/inventory/Inventory.java b/src/main/java/fr/nivcoo/pointz/inventory/Inventory.java index 5995c9e..5033925 100644 --- a/src/main/java/fr/nivcoo/pointz/inventory/Inventory.java +++ b/src/main/java/fr/nivcoo/pointz/inventory/Inventory.java @@ -1,6 +1,3 @@ -/** - * - */ package fr.nivcoo.pointz.inventory; import org.bukkit.Bukkit; diff --git a/src/main/java/fr/nivcoo/pointz/inventory/InventoryManager.java b/src/main/java/fr/nivcoo/pointz/inventory/InventoryManager.java index b5328ee..f2d1ac3 100644 --- a/src/main/java/fr/nivcoo/pointz/inventory/InventoryManager.java +++ b/src/main/java/fr/nivcoo/pointz/inventory/InventoryManager.java @@ -1,6 +1,3 @@ -/** - * - */ package fr.nivcoo.pointz.inventory; import fr.nivcoo.pointz.Pointz; @@ -32,7 +29,7 @@ public void init() { for (Inventory inv : inventories.values()) { int tick = 0; Object currentTick = inv.get(Inventory.TICK); - if (currentTick != null && currentTick instanceof Integer) + if (currentTick instanceof Integer) tick = Integer.parseInt(currentTick.toString()); inv.put(Inventory.TICK, tick + 1); inv.getInventoryProvider().update(inv); diff --git a/src/main/java/fr/nivcoo/pointz/inventory/ItemBuilder.java b/src/main/java/fr/nivcoo/pointz/inventory/ItemBuilder.java index cc32410..b26cc11 100644 --- a/src/main/java/fr/nivcoo/pointz/inventory/ItemBuilder.java +++ b/src/main/java/fr/nivcoo/pointz/inventory/ItemBuilder.java @@ -1,18 +1,11 @@ package fr.nivcoo.pointz.inventory; -import com.mojang.authlib.GameProfile; -import com.mojang.authlib.properties.Property; -import fr.nivcoo.pointz.utils.ServerVersion; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.inventory.meta.SkullMeta; -import java.lang.reflect.Field; import java.util.List; -import java.util.UUID; -import java.util.logging.Level; public class ItemBuilder { private Material m; @@ -63,21 +56,6 @@ public ItemStack build() { if (im != null) { im.setDisplayName(name); im.setLore(lores); - if (m == (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.PLAYER_HEAD : Material.valueOf("SKULL_ITEM")) && texture != null && !"".equalsIgnoreCase(texture.trim())) { - SkullMeta headMeta = (SkullMeta) im; - GameProfile profile = new GameProfile(UUID.randomUUID(), null); - - profile.getProperties().put("textures", new Property("textures", texture)); - - try { - Field profileField = headMeta.getClass().getDeclaredField("profile"); - profileField.setAccessible(true); - profileField.set(headMeta, profile); - } catch (IllegalArgumentException | NoSuchFieldException | SecurityException - | IllegalAccessException ex) { - Bukkit.getLogger().log(Level.SEVERE, "Error while setting head texture", ex); - } - } is.setItemMeta(im); } diff --git a/src/main/java/fr/nivcoo/pointz/utils/WebsiteAPI.java b/src/main/java/fr/nivcoo/pointz/utils/WebsiteAPI.java index 1ccd4f8..bde8a8a 100644 --- a/src/main/java/fr/nivcoo/pointz/utils/WebsiteAPI.java +++ b/src/main/java/fr/nivcoo/pointz/utils/WebsiteAPI.java @@ -21,30 +21,29 @@ import java.net.URL; import java.net.URLEncoder; import java.security.KeyFactory; -import java.security.PublicKey; -import java.security.spec.KeySpec; -import java.security.spec.X509EncodedKeySpec; +import java.security.PrivateKey; +import java.security.spec.PKCS8EncodedKeySpec; import java.util.*; import java.util.stream.Collectors; public class WebsiteAPI { private KeyFactory keyFactory; - private PublicKey publicKey; + private PrivateKey privateKey; private final String USER__AGENT = "Mozilla/5.0"; private String url; - public WebsiteAPI(String publicKeyString, String url) throws Exception { + public WebsiteAPI(String privateKeyString, String url) throws Exception { this.keyFactory = KeyFactory.getInstance("RSA"); this.url = url + "/pointz/api"; - String stringAfter = publicKeyString.replaceAll("\\n", "").replaceAll("-----BEGIN PUBLIC KEY-----", "") - .replaceAll("-----END PUBLIC KEY-----", "").trim(); + String stringAfter = privateKeyString.replaceAll("\\n", "").replaceAll("-----BEGIN PRIVATE KEY-----", "") + .replaceAll("-----END PRIVATE KEY-----", "").trim(); byte[] decoded = Base64.getMimeDecoder().decode(stringAfter); - KeySpec keySpec = new X509EncodedKeySpec(decoded); + PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(decoded); - publicKey = keyFactory.generatePublic(keySpec); + privateKey = keyFactory.generatePrivate(keySpec); } @@ -52,14 +51,14 @@ public String encryptToBase64(String plainText) { String encoded = null; try { final Cipher rsa = Cipher.getInstance("RSA"); - rsa.init(Cipher.ENCRYPT_MODE, publicKey); + rsa.init(Cipher.ENCRYPT_MODE, privateKey); rsa.update(plainText.getBytes()); final byte[] result = rsa.doFinal(); encoded = Base64.getUrlEncoder().withoutPadding().encodeToString(result); } catch (Exception e) { - Bukkit.getLogger().severe("[Pointz] You must Install the website plugin and link it with public key #6"); + Bukkit.getLogger().severe("[Pointz] You must Install the website plugin and link it with private key #6"); } return encoded; @@ -143,7 +142,7 @@ public List getPlayersInfos(List players) { results.addAll(Arrays.asList(playersObject)); } catch (Exception e) { - Bukkit.getLogger().severe("[Pointz] You must Install the website plugin and link it with public key #5"); + Bukkit.getLogger().severe("[Pointz] You must Install the website plugin and link it with private key #5"); } @@ -160,7 +159,7 @@ public void setMoneyPlayer(Player player, double getCibleMoneyAfter) { sendPost(url, params); } catch (Exception e) { - Bukkit.getLogger().severe("[Pointz] You must Install the website plugin and link it with public key #4"); + Bukkit.getLogger().severe("[Pointz] You must Install the website plugin and link it with private key #4"); } @@ -199,7 +198,7 @@ public MWConfig initMWConfig() { result = new MWConfig(String.valueOf(jobj.get("name_shop")), String.valueOf(jobj.get("name_gui"))); } catch (Exception e) { - Bukkit.getLogger().severe("[Pointz] You must Install the website plugin and link it with public key #3"); + Bukkit.getLogger().severe("[Pointz] You must Install the website plugin and link it with private key #3"); } @@ -230,7 +229,7 @@ public List initItemsConverter() { } catch (Exception e) { e.printStackTrace(); - Bukkit.getLogger().severe("[Pointz] You must Install the website plugin and link it with public key #2"); + Bukkit.getLogger().severe("[Pointz] You must Install the website plugin and link it with private key #2"); } @@ -271,7 +270,7 @@ public List initItemsShop() { } catch (Exception e) { e.printStackTrace(); - Bukkit.getLogger().severe("[Pointz] You must Install the website plugin and link it with public key #1"); + Bukkit.getLogger().severe("[Pointz] You must Install the website plugin and link it with private key #1"); } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 4b22761..51ba7c8 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -6,12 +6,10 @@ hooks: api: website_url: "https://edensky.fr" #paste here your public key, get it on website (this is an example) - public_key: "-----BEGIN PUBLIC KEY----- - MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3vcaidbuH0Atm50iMkSh - TzaYrKEa3zi9TR7yX3bjL4fCo/rKnRc/HbVeH1AUhOT/TYsqBb/ZTyx8/i+XAZDb - 0XnlnorTFSjC8tz7tVepv8+HfIw2jUIvUfMmgnhn1YwIXnJpgR/TJnAF04F5v/oD - UpIj2Dg6VP+MfBElaP4ddluHjZGzrIw+84gta1NuV1If2xgqQ0KxL8fxtnW3H9Qt - gu9BIH1Du8bpNBhURvtvUh3bf/3eHeilkfgI4KDTwTk8cnIIifPrafMAg/8/Apja - lDkFxztRYD7TTxFqLluhDFKR7sU8szDcivdB9NvXl4CoGXr5e/zaJ5IoeaiZBUTB - gQIDAQAB - -----END PUBLIC KEY-----" + private_key: "-----BEGIN PRIVATE KEY----- +MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDSxqe/XX3ROrvR +BrH7rR1WlfOjvzqY+3OKiVvr3WJRWID4lygSbDxz7X18pEIw+OyyEK3A1UijhvGL +..... +LzQvPzJ2nHBRRwjrXRo7cqEGBumELPdaPvNtTf5mCjqDTMnheCHoWd56+wvL85ii +OpxYOcxxb3hUv0KYII2b2g== +-----END PRIVATE KEY-----" diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index c465d2e..4355a4d 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: Pointz -version: 2.5.1 +version: 2.6.0 author: nivcoo main: fr.nivcoo.pointz.Pointz softdepend: [ MVdWPlaceholderAPI, PlaceholderAPI ]