Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * This program is free software: you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later
- * version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package com.l2jserver.gameserver.model.zone.type;
- import java.io.File;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.util.Random;
- import java.util.logging.Level;
- import javax.xml.parsers.DocumentBuilder;
- import javax.xml.parsers.DocumentBuilderFactory;
- import org.w3c.dom.Document;
- import org.w3c.dom.Element;
- import org.w3c.dom.Node;
- import org.w3c.dom.NodeList;
- import com.l2jserver.Config;
- import com.l2jserver.L2DatabaseFactory;
- import com.l2jserver.gameserver.model.actor.L2Character;
- import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- import com.l2jserver.gameserver.model.zone.ZoneId;
- /**
- * @author Marwan
- */
- public class L2CustomPvP extends L2RespawnZone
- {
- // Ramdom Locations configs
- File fXmlFile = new File(Config.DATAPACK_ROOT + "/data/customzone.xml");
- DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
- Random random = new Random();
- public L2CustomPvP(int id)
- {
- super(5555);
- }
- public void setNewName(L2PcInstance activeChar)
- {
- try (Connection con = L2DatabaseFactory.getInstance().getConnection();
- PreparedStatement statement = con.prepareStatement("UPDATE characters SET pvpname=? WHERE charId=?"))
- {
- int pvpname1 = random.nextInt();
- statement.setString(1, "" + pvpname1);
- statement.setInt(2, activeChar.getObjectId());
- statement.execute();
- }
- catch (Exception e)
- {
- _log.log(Level.SEVERE, "Failed updating character online status.", e);
- }
- }
- public void getName(L2PcInstance activeChar)
- {
- try (Connection con = L2DatabaseFactory.getInstance().getConnection())
- {
- String sql = "SELECT pvpname FROM characters WHERE charId=?";
- PreparedStatement statement = con.prepareStatement(sql);
- statement.setInt(1, activeChar.getObjectId());
- ResultSet rset = statement.executeQuery();
- while (rset.next())
- {
- String name = rset.getString("pvpname");
- activeChar.setName(name);
- activeChar.sendMessage(rset.getString("pvpname"));
- }
- rset.close();
- statement.close();
- }
- catch (Exception e)
- {
- _log.log(Level.SEVERE, "Could not restore premium items: " + e.getMessage(), e);
- }
- }
- @Override
- protected void onEnter(L2Character character)
- {
- try
- {
- DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
- Document doc = dBuilder.parse(fXmlFile);
- doc.getDocumentElement().normalize();
- NodeList nList = doc.getElementsByTagName("enter");
- for (int temp = 0; temp < nList.getLength(); temp++)
- {
- Node nNode = nList.item(temp);
- if (nNode.getNodeType() == Node.ELEMENT_NODE)
- {
- Element eElement = (Element) nNode;
- ((L2PcInstance) character).sendMessage(getTagValue("msg", eElement));
- if (getTagValue("randomName", eElement).equals("true"))
- {
- getName(((L2PcInstance) character));
- setNewName(((L2PcInstance) character));
- }
- if (getTagValue("parties", eElement).equals("true"))
- {
- ((L2PcInstance) character).getParty().removePartyMember(((L2PcInstance) character).getName(), null);
- }
- if (getTagValue("flag", eElement).equals("true"))
- {
- ((L2PcInstance) character).setPvpFlag(1);
- }
- }
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- character.setInsideZone(ZoneId.PVP, true);
- }
- @Override
- protected void onExit(L2Character character)
- {
- try
- {
- DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
- Document doc = dBuilder.parse(fXmlFile);
- doc.getDocumentElement().normalize();
- NodeList nList = doc.getElementsByTagName("exit");
- for (int temp = 0; temp < nList.getLength(); temp++)
- {
- Node nNode = nList.item(temp);
- if (nNode.getNodeType() == Node.ELEMENT_NODE)
- {
- Element eElement = (Element) nNode;
- ((L2PcInstance) character).sendMessage(getTagValue("msg", eElement));
- if (getTagValue("flag", eElement).equals("true"))
- {
- }
- }
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- @Override
- public void onDieInside(L2Character character)
- {
- try
- {
- DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
- Document doc = dBuilder.parse(fXmlFile);
- doc.getDocumentElement().normalize();
- NodeList nList = doc.getElementsByTagName("exit");
- for (int temp = 0; temp < nList.getLength(); temp++)
- {
- Node nNode = nList.item(temp);
- if (nNode.getNodeType() == Node.ELEMENT_NODE)
- {
- Element eElement = (Element) nNode;
- ((L2PcInstance) character).sendMessage(getTagValue("dieMsg", eElement));
- }
- }
- }
- catch (Exception e)
- {
- }
- }
- private static String getTagValue(String sTag, Element eElement)
- {
- NodeList nlList = eElement.getElementsByTagName(sTag).item(0).getChildNodes();
- Node nValue = nlList.item(0);
- return nValue.getNodeValue();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement