Skip to content

Instantly share code, notes, and snippets.

@u3games
Created October 16, 2015 13:19
Show Gist options
  • Save u3games/47d7578cdb250cb0ce86 to your computer and use it in GitHub Desktop.
Save u3games/47d7578cdb250cb0ce86 to your computer and use it in GitHub Desktop.
Anti AFK - TvT
/*
* 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 xxxxx.custom.AntiAfkTvt;
import java.util.ArrayList;
import java.util.logging.Logger;
import com.l2jserver.gameserver.ThreadPoolManager;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.model.entity.TvTEvent;
import com.l2jserver.gameserver.model.entity.TvTEventTeam;
public class AntiAfkTvt
{
// Debug
static boolean debug = false;
// Delay between location checks , Default 30000 ms (30 Sec.)
private final int CheckDelay = 60000;
private static Logger _log = Logger.getLogger(AntiAfkTvt.class.getName());
static ArrayList<String> TvTPlayerList = new ArrayList<>();
private static String[] Splitter;
private static int xx, yy, zz, SameLoc;
static L2PcInstance _player;
@SuppressWarnings("synthetic-access")
private AntiAfkTvt()
{
ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new AntiAfk(), 60000, CheckDelay);
}
public class AntiAfk implements Runnable
{
@Override
public void run()
{
if (TvTEvent.isStarted())
{
// Iterate over all teams
for (TvTEventTeam team : TvTEvent._teams)
{
// Iterate over all participated player instances in this team
for (L2PcInstance playerInstance : team.getParticipatedPlayers().values())
{
if ((playerInstance != null) && playerInstance.isOnline())
{
_player = playerInstance;
AddTvTSpawnInfo(playerInstance.getName(), playerInstance.getX(), playerInstance.getY(), playerInstance.getZ());
if (debug)
{
System.err.println("TvT Player: " + playerInstance.getName() + " " + playerInstance.getX() + " " + playerInstance.getY() + " " + playerInstance.getZ());
}
}
}
}
}
else
{
TvTPlayerList.clear();
}
}
}
static void AddTvTSpawnInfo(String name, int _x, int _y, int _z)
{
if (!CheckTvTSpawnInfo(name))
{
String temp = name + ":" + Integer.toString(_x) + ":" + Integer.toString(_y) + ":" + Integer.toString(_z) + ":1";
TvTPlayerList.add(temp);
}
else
{
Object[] elements = TvTPlayerList.toArray();
for (int i = 0; i < elements.length; i++)
{
Splitter = ((String) elements[i]).split(":");
String nameVal = Splitter[0];
if (name.equals(nameVal))
{
GetTvTSpawnInfo(name);
if ((_x == xx) && (_y == yy) && (_z == zz) && (_player.isAttackingNow() == false) && (_player.isCastingNow() == false) && (_player.isOnline() == true))
{
++SameLoc;
if (SameLoc >= 4)// Kick after 4 same x/y/z, location checks
{
// kick here
TvTPlayerList.remove(i);
_player.logout();
return;
}
TvTPlayerList.remove(i);
String temp = name + ":" + Integer.toString(_x) + ":" + Integer.toString(_y) + ":" + Integer.toString(_z) + ":" + SameLoc;
TvTPlayerList.add(temp);
return;
}
TvTPlayerList.remove(i);
String temp = name + ":" + Integer.toString(_x) + ":" + Integer.toString(_y) + ":" + Integer.toString(_z) + ":1";
TvTPlayerList.add(temp);
}
}
}
}
private static boolean CheckTvTSpawnInfo(String name)
{
Object[] elements = TvTPlayerList.toArray();
for (Object element : elements)
{
Splitter = ((String) element).split(":");
String nameVal = Splitter[0];
if (name.equals(nameVal))
{
return true;
}
}
return false;
}
private static void GetTvTSpawnInfo(String name)
{
Object[] elements = TvTPlayerList.toArray();
for (Object element : elements)
{
Splitter = ((String) element).split(":");
String nameVal = Splitter[0];
if (name.equals(nameVal))
{
xx = Integer.parseInt(Splitter[1]);
yy = Integer.parseInt(Splitter[2]);
zz = Integer.parseInt(Splitter[3]);
SameLoc = Integer.parseInt(Splitter[4]);
}
}
}
public static AntiAfkTvt getInstance()
{
return SingletonHolder._instance;
}
@SuppressWarnings("synthetic-access")
private static class SingletonHolder
{
protected static final AntiAfkTvt _instance = new AntiAfkTvt();
}
public static void main(String[] args)
{
AntiAfkTvt.getInstance();
_log.info("Auto Kick-AFK for TvT Event, enabled!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment