/*
* 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.entity;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Calendar;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.logging.Logger;
import com.l2jserver.commons.database.pool.impl.ConnectionFactory;
import com.l2jserver.gameserver.ThreadPoolManager;
import com.l2jserver.gameserver.model.L2World;
import com.l2jserver.gameserver.model.actor.instance.L2FactTeleporterInstance;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.model.actor.instance.L2TpFlagInstance;
import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
import com.l2jserver.gameserver.util.Broadcast;
import com.l2jserver.util.StringUtil;
/**
* @author Laikeriz
*/
public class FactionMaps
{
private final static Logger _log = Logger.getLogger(FactionMaps.class.getName());
public static Map<Integer, String> _all_maps = new HashMap<>();
public static int _mapId = 0;
public static String _mapName = "";
public static int _maps_count = 0;
public static boolean _voting = false;
public static int[] _mapVotes = new int[10];
public static String[] _mapNames = new String[10];
private static long _nextMapIn = 0;
public static boolean isVoting()
{
return _voting;
}
public static int getMapId()
{
return _mapId;
}
public static String getMapName()
{
return _mapName;
}
public static String getDelayUntilVoting()
{
long trim = _nextMapIn - Calendar.getInstance().getTimeInMillis();
int h = 0;
int m = 0;
int s = 0;
int k = 1 / 2;
if ((trim / 3600000) >= 1)
{
h = Math.round((trim / 3600000) - k);
trim -= h * 3600000;
}
if ((trim / 60) >= 1)
{
m = Math.round((trim / 60000) - k);
trim -= m * 60000;
}
if ((trim / 1000) >= 1)
{
s = Math.round((trim / 1000) - k);
}
return h + "h. " + m + "m. " + s + "s.";
}
@SuppressWarnings("resource")
public static void loadCurrentMap()
{
Connection con = null;
try
{
con = ConnectionFactory.getInstance().getConnection();
PreparedStatement stmt = con.prepareStatement("SELECT mapId,map_name FROM faction_maps WHERE current=1");
ResultSet rset = stmt.executeQuery();
while (rset.next())
{
_mapId = rset.getInt("mapId");
_mapName = rset.getString("map_name");
}
rset.close();
stmt.close();
// Put all maps in FastMap
PreparedStatement stmt_all = con.prepareStatement("SELECT mapId,map_name FROM faction_maps");
ResultSet rset_all = stmt_all.executeQuery();
while (rset_all.next())
{
_all_maps.put(rset_all.getInt("mapId"), rset_all.getString("map_name"));
}
rset_all.close();
stmt_all.close();
}
catch (Exception e)
{
_log.warning("Load current map: " + e);
}
finally
{
try
{
con.close();
}
catch (Exception e)
{
}
}
ThreadPoolManager.getInstance().scheduleGeneral(() -> endVoting(true), 1000);
}
public static void beginVoting()
{
for (L2TpFlagInstance flag : L2FactTeleporterInstance._tpBlueFlags)
{
flag.deleteMe();
}
for (L2TpFlagInstance flag : L2FactTeleporterInstance._tpRedFlags)
{
flag.deleteMe();
}
L2FactTeleporterInstance._tpBlueFlags.clear();
L2FactTeleporterInstance._tpRedFlags.clear();
for (L2PcInstance player : L2World.getInstance().getAllPlayers().values())
{
player.setVotedForMap(false);
}
Broadcast.toAllOnlinePlayers("Voting for next faction map has begun. It will end in 60 seconds.");
_voting = true;
NpcHtmlMessage html = new NpcHtmlMessage(1);
final StringBuilder tb = StringUtil.startAppend(3500, "<html><title>Faction Maps</title><body><center>");
tb.append("<img src=\"L2UI_CH3.onscrmsg_pattern01_1\" width=300 height=32 align=left><br>");
Connection con = null;
try
{
con = ConnectionFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement("SELECT * FROM faction_maps WHERE current=0");
ResultSet rset = statement.executeQuery();
for (int r = 0; r < _mapVotes.length; r++)
{
_mapVotes[r] = 0;
}
while (rset.next())
{
tb.append("<button value=\"" + rset.getString("map_name") + "\" action=\"bypass -h voteformap_" + rset.getInt("mapId") + "\" width=170 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
_mapNames[rset.getInt("mapId")] = rset.getString("map_name");
}
rset.close();
statement.close();
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
try
{
con.close();
}
catch (Exception e)
{
_log.info("Couldn't set player faction:" + " " + e);
}
}
tb.append("<img src=\"L2UI_CH3.onscrmsg_pattern01_2\" width=300 height=32 align=left></center></body></html>");
html.setHtml(tb.toString());
for (L2PcInstance player : L2World.getInstance().getAllPlayers().values())
{
player.sendPacket(html);
}
try
{
Thread.sleep(60000);
}
catch (Exception e)
{
}
endVoting(false);
}
@SuppressWarnings("resource")
public static void endVoting(boolean onLoad)
{
_nextMapIn = Calendar.getInstance().getTimeInMillis() + 250000;
if (!onLoad)
{
_voting = false;
int mostVotes = 0;
int mostMapId = 0;
for (int i = 0; i < _mapVotes.length; i++)
{
if (_mapVotes[i] > mostVotes)
{
mostVotes = _mapVotes[i];
mostMapId = i;
}
}
if (mostVotes == 0)
{
mostMapId = 2;
}
_mapName = _mapNames[mostMapId];
_mapId = mostMapId;
Broadcast.toAllOnlinePlayers("Voting for faction maps has ended.");
Broadcast.toAllOnlinePlayers("The next map will be: " + _mapName);
L2TpFlagInstance.spawnFlags();
@SuppressWarnings("resource")
Connection con = null;
try
{
con = ConnectionFactory.getInstance().getConnection();
PreparedStatement statement = null;
statement = con.prepareStatement("UPDATE faction_maps SET current=0");
statement.execute();
statement = con.prepareStatement("UPDATE faction_maps SET current=1 WHERE mapId=?");
statement.setInt(1, _mapId);
statement.execute();
statement.close();
}
catch (Exception e)
{
_log.warning("End voting: " + e);
}
finally
{
try
{
con.close();
}
catch (Exception e)
{
}
}
}
int durat = 4 * 60 * 1000;
try
{
Thread.sleep(durat);
}
catch (Exception e)
{
}
beginVoting();
}
public static int getNextMap(int mapid)
{
if (_mapId < _maps_count)
{
return _mapId + 1;
}
return 1;
}
public static class ValueComparator implements Comparator<Object>
{
Map<L2PcInstance, Integer> base;
public ValueComparator(Map<L2PcInstance, Integer> base1)
{
this.base = base1;
}
@Override
public int compare(Object a, Object b)
{
if (base.get(a) < base.get(b))
{
return 1;
}
else if (base.get(a) == base.get(b))
{
return 0;
}
else
{
return -1;
}
}
}
public static void voteForMap(int mapId)
{
_mapVotes[mapId] = _mapVotes[mapId] + 1;
}
}
.So im trying to adapt DarthVaders script for factionmap,l2factteleporter and l2tpflaginstance on h5 l2j.So far everything work perfect except voting.The window as you can see is working but when i press any button window just close and nothing happen.When voting ends and next map load it seems to be the same so i believe is something wrong with bypass,but i cant figured out .Any help/idea?
You can post now and register later.
If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.
I really don't even care about them haha, I just made a guide of what will happen if someone wants to publish free files. xD
actually I want to get to -50 to see what maxtor is doing hahahahaha
This is Gustavo!
Gustavo been naughty naughty, he came all the way from Argentina to avenge his fallen C4 Community and acted tough.
The "stupid" as he qualified us, europeans didnt appreciate him acting like a clown so they punished him with the power given from the forum to use the "downvotes" whenever they feel like that.
But Gustavo thought the only reason the Downvotes exist is because there is some shady mystery conspiracy are against him.
Few days will pass and Gustavo will scream this post to be closed again so he can heal and come back to the battlefield again.
A true Avenger should never back down, he might lose the fight, but he'll try to win the war.
Gustavo is a clown,
Dont be like Gustavo.
It's definitely not about sharing your files.
The issue lies in how you conduct yourself on the forums and how you treat others. Clearly, your behavior lacked both courtesy and respect.
if you share files for free on MaxCheaters you will get this...
think twice before sharing files.
it should be clarified that this is endorsed by the administrators and moderators of the site...
Question
misterelax
hello mates
.So im trying to adapt DarthVaders script for factionmap,l2factteleporter and l2tpflaginstance on h5 l2j.So far everything work perfect except voting.The window as you can see is working but when i press any button window just close and nothing happen.When voting ends and next map load it seems to be the same so i believe is something wrong with bypass,but i cant figured out .Any help/idea?
7 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.