d### Eclipse Workspace Patch 1.0
#P L2J_Mobius_CT_2.6_HighFive
Index: dist/game/data/scripts/custom/NpcPremium/101000-info.htm
===================================================================
--- dist/game/data/scripts/custom/NpcPremium/101000-info.htm (nonexistent)
+++ dist/game/data/scripts/custom/NpcPremium/101000-info.htm (working copy)
@@ -0,0 +1,16 @@
+
Premium Benefits
+
+
+Premium Account Benefits
+
+Premium members receive the following benefits:
+ +50% Experience
+ +50% SP
+ +30% Drop Rate
+ +30% Spoil Rate
+ Access to Premium Zone
+ Premium Skills
+ No XP loss on death
+Price: 1 Premium Coin per day
+
+
\ No newline at end of file
Index: dist/game/data/scripts/custom/NpcPremium/PremiumNpc.java
===================================================================
--- dist/game/data/scripts/custom/NpcPremium/PremiumNpc.java (nonexistent)
+++ dist/game/data/scripts/custom/NpcPremium/PremiumNpc.java (working copy)
@@ -0,0 +1,306 @@
+/*
+ * Copyright (c) 2013 L2jMobius
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+ * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+package custom.NpcPremium;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.concurrent.TimeUnit;
+
+import org.l2jmobius.gameserver.managers.PremiumManager;
+import org.l2jmobius.gameserver.model.actor.Npc;
+import org.l2jmobius.gameserver.model.actor.Player;
+import org.l2jmobius.gameserver.model.item.enums.ItemProcessType;
+import org.l2jmobius.gameserver.model.script.Script;
+
+/**
+ * @author Stayway
+ */
+public class PremiumNpc extends Script
+{
+ private static final int NPC_ID = 101000;
+ private static final int PREMIUM_COIN_ID = 6393;
+
+ public PremiumNpc()
+ {
+ addStartNpc(NPC_ID);
+ addTalkId(NPC_ID);
+ addFirstTalkId(NPC_ID);
+ }
+
+ @Override
+ public String onEvent(String event, Npc npc, Player player)
+ {
+ if ((player == null) || (npc == null))
+ {
+ return null;
+ }
+
+ player.sendMessage("Debug: Event received: " + event);
+
+ if (event.equals("menu"))
+ {
+ return showMainHtml(npc, player);
+ }
+ else if (event.equals("info"))
+ {
+ return showInfoHtml(npc, player);
+ }
+ else if (event.startsWith("buy_"))
+ {
+ String[] split = event.split("_");
+ if (split.length == 2)
+ {
+ try
+ {
+ int days = Integer.parseInt(split[1]);
+ return processPurchase(player, days, days, npc);
+ }
+ catch (NumberFormatException e)
+ {
+ player.sendMessage("Invalid number of days.");
+ }
+ }
+ }
+ else if (event.equals("check_status"))
+ {
+ return showStatusHtml(npc, player);
+ }
+
+ // Se nenhum evento específico, mostrar menu principal
+ return showMainHtml(npc, player);
+ }
+
+ @Override
+ public String onFirstTalk(Npc npc, Player player)
+ {
+ return showMainHtml(npc, player);
+ }
+
+ private String showMainHtml(Npc npc, Player player)
+ {
+ String html = getHtm(player, "data/scripts/custom/NpcPremium/" + npc.getId() + "-main.html");
+ if (html == null)
+ {
+ html = createMainHtml();
+ }
+
+ // Substituir variáveis
+ if (html != null)
+ {
+ html = html.replace("%playername%", player.getName());
+ html = html.replace("%coinCount%", String.valueOf(getPlayerCoins(player)));
+
+ // Adicionar status do premium atual
+ String premiumStatus = getPremiumStatus(player);
+ html = html.replace("%premiumStatus%", premiumStatus);
+ }
+
+ return html;
+ }
+
+ private String showInfoHtml(Npc npc, Player player)
+ {
+ String html = getHtm(player, "data/scripts/custom/NpcPremium/" + npc.getId() + "-info.html");
+ if (html == null)
+ {
+ html = createInfoHtml();
+ }
+ return html;
+ }
+
+ private String showStatusHtml(Npc npc, Player player)
+ {
+ String html = getHtm(player, "data/scripts/custom/NpcPremium/" + npc.getId() + "-status.html");
+ if (html == null)
+ {
+ html = createStatusHtml(player);
+ }
+ else
+ {
+ html = html.replace("%premiumStatus%", getPremiumStatus(player));
+ }
+ return html;
+ }
+
+ private String processPurchase(Player player, int days, int coinsNeeded, Npc npc)
+ {
+ int currentCoins = getPlayerCoins(player);
+
+ if (currentCoins < coinsNeeded)
+ {
+ player.sendMessage("You need " + coinsNeeded + " Premium Coins! You have only " + currentCoins + ".");
+ return showMainHtml(npc, player);
+ }
+
+ if (PremiumManager.getInstance() == null)
+ {
+ player.sendMessage("❌ Premium system is not available. Please contact administration.");
+ return showMainHtml(npc, player);
+ }
+
+ boolean success = player.destroyItemByItemId(ItemProcessType.FEE, PREMIUM_COIN_ID, coinsNeeded, npc, true);
+
+ if (success)
+ {
+ boolean premiumAdded = addPremium(player, days);
+
+ if (premiumAdded)
+ {
+ player.sendMessage("🎉 Premium activated for " + days + " days! Enjoy!");
+
+ String html = getHtm(player, "data/scripts/custom/NpcPremium/" + npc.getId() + "-success.html");
+ if (html == null)
+ {
+ html = createSuccessHtml(days, coinsNeeded, currentCoins - coinsNeeded, player);
+ }
+ else
+ {
+ html = html.replace("%days%", String.valueOf(days));
+ html = html.replace("%coinsUsed%", String.valueOf(coinsNeeded));
+ html = html.replace("%coinsLeft%", String.valueOf(currentCoins - coinsNeeded));
+ html = html.replace("%premiumStatus%", getPremiumStatus(player));
+ }
+
+ return html;
+ }
+ player.addItem(ItemProcessType.REFUND, PREMIUM_COIN_ID, coinsNeeded, npc, true);
+ player.sendMessage("❌ Error activating premium. Your coins have been refunded.");
+ return showMainHtml(npc, player);
+ }
+
+ player.sendMessage("❌ Error processing payment. Please try again.");
+ return showMainHtml(npc, player);
+ }
+
+ private int getPlayerCoins(Player player)
+ {
+ return (int) player.getInventory().getInventoryItemCount(PREMIUM_COIN_ID, -1);
+ }
+
+ /**
+ * @param player
+ * @param days
+ * @return
+ */
+ private boolean addPremium(Player player, int days)
+ {
+ try
+ {
+ // Verificar se o PremiumManager está disponível
+ if (PremiumManager.getInstance() == null)
+ {
+ player.sendMessage("❌ Premium system is not available.");
+ return false;
+ }
+
+ // Adicionar tempo premium usando o PremiumManager
+ PremiumManager.getInstance().addPremiumTime(player.getAccountName(), days, TimeUnit.DAYS);
+
+ // Log para debug
+ System.out.println("Premium added for account: " + player.getAccountName() + ", days: " + days + ", by NPC: " + NPC_ID);
+
+ // **CORREÇÃO: Verificar usando getPremiumExpiration em vez de hasPremium**
+ long expiration = PremiumManager.getInstance().getPremiumExpiration(player.getAccountName());
+ long currentTime = System.currentTimeMillis();
+ boolean hasPremium = (expiration > currentTime);
+
+ player.sendMessage("Premium expiration: " + new SimpleDateFormat("dd/MM/yyyy HH:mm").format(new Date(expiration)));
+ player.sendMessage("Has premium: " + hasPremium);
+
+ return hasPremium;
+ }
+ catch (Exception e)
+ {
+ System.err.println("Error adding premium for player " + player.getName() + ": " + e.getMessage());
+ e.printStackTrace();
+ player.sendMessage("❌ System error while activating premium: " + e.getMessage());
+ return false;
+ }
+ }
+
+ /**
+ * @param player
+ * @return
+ */
+ private String getPremiumStatus(Player player)
+ {
+ try
+ {
+ if (PremiumManager.getInstance() == null)
+ {
+ return "Premium System Unavailable ";
+ }
+
+ long expiration = PremiumManager.getInstance().getPremiumExpiration(player.getAccountName());
+ long currentTime = System.currentTimeMillis();
+
+ if (expiration > currentTime)
+ {
+ String expireDate = new SimpleDateFormat("dd/MM/yyyy HH:mm").format(new Date(expiration));
+ long daysLeft = (expiration - currentTime) / (1000 * 60 * 60 * 24);
+ return "ACTIVE - Expires: " + expireDate + " (" + daysLeft + " days left)";
+ }
+ return "INACTIVE - No active premium";
+ }
+ catch (Exception e)
+ {
+ return "Error checking status ";
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ new PremiumNpc();
+ }
+}
\ No newline at end of file
Index: dist/game/data/scripts/custom/NpcPremium/101000-main.htm
===================================================================
--- dist/game/data/scripts/custom/NpcPremium/101000-main.htm (nonexistent)
+++ dist/game/data/scripts/custom/NpcPremium/101000-main.htm (working copy)
@@ -0,0 +1,40 @@
+
+Premium System
+
+
+
+Premium Account System
+
+
+Welcome, %playername%!
+Your Premium Coins: %coinCount%
+
+Choose your premium package:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
Index: dist/game/data/scripts/custom/NpcPremium/101000-info.htm
===================================================================
--- dist/game/data/scripts/custom/NpcPremium/101000-info.htm (nonexistent)
+++ dist/game/data/scripts/custom/NpcPremium/101000-info.htm (working copy)
@@ -0,0 +1,16 @@
+Premium Benefits
+
+
+Premium Account Benefits
+
+Premium members receive the following benefits:
+ +50% Experience
+ +50% SP
+ +30% Drop Rate
+ +30% Spoil Rate
+ Access to Premium Zone
+ Premium Skills
+ No XP loss on death
+Price: 1 Premium Coin per day
+
+
\ No newline at end of file
Index: dist/game/data/scripts/custom/NpcPremium/101000-main.htm
===================================================================
--- dist/game/data/scripts/custom/NpcPremium/101000-main.htm (nonexistent)
+++ dist/game/data/scripts/custom/NpcPremium/101000-main.htm (working copy)
@@ -0,0 +1,40 @@
+
+Premium System
+
+
+
+Premium Account System
+
+
+Welcome, %playername%!
+Your Premium Coins: %coinCount%
+
+Choose your premium package:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
Index: dist/game/data/scripts/custom/NpcPremium/101000-success.htm
===================================================================
--- dist/game/data/scripts/custom/NpcPremium/101000-success.htm (nonexistent)
+++ dist/game/data/scripts/custom/NpcPremium/101000-success.htm (working copy)
@@ -0,0 +1,10 @@
+Purchase Successful
+
+Purchase Successful!
+Thank you for your purchase!
+Days Purchased: %days% days
+Coins Used: %coinsUsed%
+Coins Left: %coinsLeft%
+Your premium benefits are now active!
+
+
\ No newline at end of file
Index: dist/game/data/scripts/custom/NpcPremium/PremiumNpc.java
===================================================================
--- dist/game/data/scripts/custom/NpcPremium/PremiumNpc.java (nonexistent)
+++ dist/game/data/scripts/custom/NpcPremium/PremiumNpc.java (working copy)
@@ -0,0 +1,306 @@
+/*
+ * Copyright (c) 2013 L2jMobius
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+ * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+package custom.NpcPremium;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.concurrent.TimeUnit;
+
+import org.l2jmobius.gameserver.managers.PremiumManager;
+import org.l2jmobius.gameserver.model.actor.Npc;
+import org.l2jmobius.gameserver.model.actor.Player;
+import org.l2jmobius.gameserver.model.item.enums.ItemProcessType;
+import org.l2jmobius.gameserver.model.script.Script;
+
+/**
+ * @author Stayway
+ */
+public class PremiumNpc extends Script
+{
+ private static final int NPC_ID = 101000;
+ private static final int PREMIUM_COIN_ID = 6393;
+
+ public PremiumNpc()
+ {
+ addStartNpc(NPC_ID);
+ addTalkId(NPC_ID);
+ addFirstTalkId(NPC_ID);
+ }
+
+ @Override
+ public String onEvent(String event, Npc npc, Player player)
+ {
+ if ((player == null) || (npc == null))
+ {
+ return null;
+ }
+
+ player.sendMessage("Debug: Event received: " + event);
+
+ if (event.equals("menu"))
+ {
+ return showMainHtml(npc, player);
+ }
+ else if (event.equals("info"))
+ {
+ return showInfoHtml(npc, player);
+ }
+ else if (event.startsWith("buy_"))
+ {
+ String[] split = event.split("_");
+ if (split.length == 2)
+ {
+ try
+ {
+ int days = Integer.parseInt(split[1]);
+ return processPurchase(player, days, days, npc);
+ }
+ catch (NumberFormatException e)
+ {
+ player.sendMessage("Invalid number of days.");
+ }
+ }
+ }
+ else if (event.equals("check_status"))
+ {
+ return showStatusHtml(npc, player);
+ }
+ return showMainHtml(npc, player);
+ }
+
+ @Override
+ public String onFirstTalk(Npc npc, Player player)
+ {
+ return showMainHtml(npc, player);
+ }
+
+ private String showMainHtml(Npc npc, Player player)
+ {
+ String html = getHtm(player, "data/scripts/custom/NpcPremium/" + npc.getId() + "-main.html");
+ if (html == null)
+ {
+ html = createMainHtml();
+ }
+
+ if (html != null)
+ {
+ html = html.replace("%playername%", player.getName());
+ html = html.replace("%coinCount%", String.valueOf(getPlayerCoins(player)));
+
+ // Adicionar status do premium atual
+ String premiumStatus = getPremiumStatus(player);
+ html = html.replace("%premiumStatus%", premiumStatus);
+ }
+
+ return html;
+ }
+
+ private String showInfoHtml(Npc npc, Player player)
+ {
+ String html = getHtm(player, "data/scripts/custom/NpcPremium/" + npc.getId() + "-info.html");
+ if (html == null)
+ {
+ html = createInfoHtml();
+ }
+ return html;
+ }
+
+ private String showStatusHtml(Npc npc, Player player)
+ {
+ String html = getHtm(player, "data/scripts/custom/NpcPremium/" + npc.getId() + "-status.html");
+ if (html == null)
+ {
+ html = createStatusHtml(player);
+ }
+ else
+ {
+ html = html.replace("%premiumStatus%", getPremiumStatus(player));
+ }
+ return html;
+ }
+
+ private String processPurchase(Player player, int days, int coinsNeeded, Npc npc)
+ {
+ int currentCoins = getPlayerCoins(player);
+
+ if (currentCoins < coinsNeeded)
+ {
+ player.sendMessage("You need " + coinsNeeded + " Premium Coins! You have only " + currentCoins + ".");
+ return showMainHtml(npc, player);
+ }
+
+ if (PremiumManager.getInstance() == null)
+ {
+ player.sendMessage("❌ Premium system is not available. Please contact administration.");
+ return showMainHtml(npc, player);
+ }
+ boolean success = player.destroyItemByItemId(ItemProcessType.FEE, PREMIUM_COIN_ID, coinsNeeded, npc, true);
+
+ if (success)
+ {
+ boolean premiumAdded = addPremium(player, days);
+
+ if (premiumAdded)
+ {
+ player.sendMessage("🎉 Premium activated for " + days + " days! Enjoy!");
+
+ String html = getHtm(player, "data/scripts/custom/NpcPremium/" + npc.getId() + "-success.html");
+ if (html == null)
+ {
+ html = createSuccessHtml(days, coinsNeeded, currentCoins - coinsNeeded, player);
+ }
+ else
+ {
+ html = html.replace("%days%", String.valueOf(days));
+ html = html.replace("%coinsUsed%", String.valueOf(coinsNeeded));
+ html = html.replace("%coinsLeft%", String.valueOf(currentCoins - coinsNeeded));
+ html = html.replace("%premiumStatus%", getPremiumStatus(player));
+ }
+
+ return html;
+ }
++ player.addItem(ItemProcessType.REFUND, PREMIUM_COIN_ID, coinsNeeded, npc, true);
+ player.sendMessage("❌ Error activating premium. Your coins have been refunded.");
+ return showMainHtml(npc, player);
+ }
+
+ player.sendMessage("❌ Error processing payment. Please try again.");
+ return showMainHtml(npc, player);
+ }
+
+ private int getPlayerCoins(Player player)
+ {
+ return (int) player.getInventory().getInventoryItemCount(PREMIUM_COIN_ID, -1);
+ }
+
+ /**
+ * @param player
+ * @param days
+ * @return
+ */
+ private boolean addPremium(Player player, int days)
+ {
+ try
+ {
+ // Verificar se o PremiumManager está disponível
+ if (PremiumManager.getInstance() == null)
+ {
+ player.sendMessage("❌ Premium system is not available.");
+ return false;
+ }
+
+ PremiumManager.getInstance().addPremiumTime(player.getAccountName(), days, TimeUnit.DAYS);
+
+ // Log para debug
+ System.out.println("Premium added for account: " + player.getAccountName() + ", days: " + days + ", by NPC: " + NPC_ID);
+
+ long expiration = PremiumManager.getInstance().getPremiumExpiration(player.getAccountName());
+ long currentTime = System.currentTimeMillis();
+ boolean hasPremium = (expiration > currentTime);
+
+ player.sendMessage("Premium expiration: " + new SimpleDateFormat("dd/MM/yyyy HH:mm").format(new Date(expiration)));
+ player.sendMessage("Has premium: " + hasPremium);
+
+ return hasPremium;
+ }
+ catch (Exception e)
+ {
+ System.err.println("Error adding premium for player " + player.getName() + ": " + e.getMessage());
+ e.printStackTrace();
+ player.sendMessage("❌ System error while activating premium: " + e.getMessage());
+ return false;
+ }
+ }
+
+ /**
+ * @param player
+ * @return
+ */
+ private String getPremiumStatus(Player player)
+ {
+ try
+ {
+ if (PremiumManager.getInstance() == null)
+ {
+ return "Premium System Unavailable ";
+ }
+
+ long expiration = PremiumManager.getInstance().getPremiumExpiration(player.getAccountName());
+ long currentTime = System.currentTimeMillis();
+
+ if (expiration > currentTime)
+ {
+ String expireDate = new SimpleDateFormat("dd/MM/yyyy HH:mm").format(new Date(expiration));
+ long daysLeft = (expiration - currentTime) / (1000 * 60 * 60 * 24);
+ return "ACTIVE - Expires: " + expireDate + " (" + daysLeft + " days left)";
+ }
+ return "INACTIVE - No active premium";
+ }
+ catch (Exception e)
+ {
+ return "Error checking status ";
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ new PremiumNpc();
+ }
+}
\ No newline at end of file
Index: dist/game/data/scripts/custom/NpcPremium/101000-success.htm
===================================================================
--- dist/game/data/scripts/custom/NpcPremium/101000-success.htm (nonexistent)
+++ dist/game/data/scripts/custom/NpcPremium/101000-success.htm (working copy)
@@ -0,0 +1,10 @@
+Purchase Successful
+
+Purchase Successful!
+Thank you for your purchase!
+Days Purchased: %days% days
+Coins Used: %coinsUsed%
+Coins Left: %coinsLeft%
+Your premium benefits are now active!
+
+
\ No newline at end of file