Advertisement
Guest User

Untitled

a guest
May 21st, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.76 KB | None | 0 0
  1.   /*
  2.  * Copyright (C) 2004-2020 L2J DataPack
  3.  *
  4.  * This file is part of L2J DataPack.
  5.  *
  6.  * L2J DataPack is free software: you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation, either version 3 of the License, or
  9.  * (at your option) any later version.
  10.  *
  11.  * L2J DataPack is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14.  * General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18.  */
  19.  package custom.BugReport;
  20.  
  21. import java.io.BufferedWriter;
  22. import java.io.File;
  23. import java.io.FileWriter;
  24.  
  25. import com.l2jserver.gameserver.cache.HtmCache;
  26. import com.l2jserver.gameserver.model.L2World;
  27. import com.l2jserver.gameserver.model.actor.L2Npc;
  28. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  29. import com.l2jserver.gameserver.model.quest.Quest;
  30. import com.l2jserver.gameserver.network.L2GameClient;
  31. import com.l2jserver.gameserver.network.clientpackets.Say2;
  32. import com.l2jserver.gameserver.network.serverpackets.CreatureSay;
  33. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  34.  
  35. /**
  36.  * @author -=DoctorNo=- Version 2.1
  37.  */
  38. public class BugReport extends Quest
  39. {
  40.     private static final int NpcId = 36630; // npc id here
  41.     private static String qn = "BugReport";
  42.     private static String _type;
  43.    
  44.     public BugReport(int questId, String name, String descr)
  45.     {
  46.         super(questId, name, descr);
  47.         addFirstTalkId(NpcId);
  48.         addTalkId(NpcId);
  49.         addStartNpc(NpcId);
  50.     }
  51.    
  52.     /**
  53.      * Method to manage all player bypasses
  54.      * @param event
  55.      * @param npc
  56.      * @param player
  57.      * @return
  58.      */
  59.     @Override
  60.     public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  61.     {
  62.         if (event.startsWith("report"))
  63.         {
  64.             sendReport(event, npc, player, event);
  65.         }
  66.         return "";
  67.     }
  68.    
  69.     private void sendReport(String event, L2Npc npc, L2PcInstance player, String command)
  70.     {
  71.         String message = "";
  72.         String[] type = command.split(" "); // General, Fatal, Misuse, Balance, Other
  73.         L2GameClient info = player.getClient().getConnection().getClient();
  74.        
  75.         if (type[1].equals("General"))
  76.         {
  77.             _type = "General";
  78.         }
  79.         if (type[1].equals("Fatal"))
  80.         {
  81.             _type = "Fatal";
  82.         }
  83.         if (type[1].equals("Misuse"))
  84.         {
  85.             _type = "Misuse";
  86.         }
  87.         if (type[1].equals("Balance"))
  88.         {
  89.             _type = "Balance";
  90.         }
  91.         if (type[1].equals("Other"))
  92.         {
  93.             _type = "Other";
  94.         }
  95.        
  96.         try
  97.         {
  98.             for (String s : event.split(" "))
  99.             {
  100.                 message = message + " " + s;
  101.             }
  102.             message = message.replaceFirst("report", "");
  103.             message = message.replaceFirst("General", "");
  104.             message = message.replaceFirst("Fatal", "");
  105.             message = message.replaceFirst("Misuse", "");
  106.             message = message.replaceFirst("Balance", "");
  107.             message = message.replaceFirst("Other", "");
  108.             message = message.replaceFirst("  ", "");
  109.            
  110.             String fname = "data/BugReports/" + player.getName() + ".txt";
  111.             File file = new File(fname);
  112.             boolean exist = file.createNewFile();
  113.             if (!exist)
  114.             {
  115.                 player.sendMessage("You have already sent a bug report, GMs must check it first.");
  116.                 return;
  117.             }
  118.             FileWriter fstream = new FileWriter(fname);
  119.             BufferedWriter out = new BufferedWriter(fstream);
  120.             out.write("Character Info: " + info + "\r\nBug Type: " + _type + "\r\nMessage: " + message);
  121.             player.sendMessage("Report sent. GMs will check it soon. Thanks...");
  122.            
  123.             for (L2PcInstance allgms : L2World.getInstance().getAllGMs())
  124.             {
  125.                 allgms.sendPacket(new CreatureSay(0, Say2.SHOUT, "Bug Report Manager", player.getName() + " sent a bug report."));
  126.             }
  127.            
  128.             System.out.println("Character: " + player.getName() + " sent a bug report.");
  129.             out.close();
  130.         }
  131.         catch (Exception e)
  132.         {
  133.             player.sendMessage("Something went wrong try again.");
  134.         }
  135.     }
  136.    
  137.     @Override
  138.     public String onFirstTalk(L2Npc npc, L2PcInstance player)
  139.     {
  140.         final int npcId = npc.getId();
  141.         if (player.getQuestState(qn) == null)
  142.         {
  143.             newQuestState(player);
  144.         }
  145.        
  146.         if (npcId == NpcId)
  147.         {
  148.             String html = HtmCache.getInstance().getHtm(player.getHtmlPrefix(), "data/scripts/custom/BugReport/1.htm");
  149.             html = html.replaceAll("%player%", player.getName());
  150.            
  151.             NpcHtmlMessage npcHtml = new NpcHtmlMessage(0);
  152.             npcHtml.setHtml(html);
  153.             player.sendPacket(npcHtml);
  154.         }
  155.         return "";
  156.     }
  157.    
  158.     public static void main(final String[] args)
  159.     {
  160.         new BugReport(-1, "BugReport", "custom");
  161.         _log.info("------------------------------------------=[ Master Scripts ]");
  162.         _log.info("BugReport Manager: Enabled.");
  163.     }
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement