Disconnection class for HighFive.
This commit is contained in:
@@ -1,184 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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 custom.listeners;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.l2jmobius.commons.util.Rnd;
|
||||
import com.l2jmobius.gameserver.model.actor.L2Attackable;
|
||||
import com.l2jmobius.gameserver.model.events.Containers;
|
||||
import com.l2jmobius.gameserver.model.events.EventType;
|
||||
import com.l2jmobius.gameserver.model.events.ListenerRegisterType;
|
||||
import com.l2jmobius.gameserver.model.events.annotations.Id;
|
||||
import com.l2jmobius.gameserver.model.events.annotations.NpcLevelRange;
|
||||
import com.l2jmobius.gameserver.model.events.annotations.Priority;
|
||||
import com.l2jmobius.gameserver.model.events.annotations.Range;
|
||||
import com.l2jmobius.gameserver.model.events.annotations.RegisterEvent;
|
||||
import com.l2jmobius.gameserver.model.events.annotations.RegisterType;
|
||||
import com.l2jmobius.gameserver.model.events.impl.character.OnCreatureKill;
|
||||
import com.l2jmobius.gameserver.model.events.impl.character.npc.attackable.OnAttackableAttack;
|
||||
import com.l2jmobius.gameserver.model.events.impl.character.player.OnPlayerDlgAnswer;
|
||||
import com.l2jmobius.gameserver.model.events.impl.character.player.OnPlayerLogin;
|
||||
import com.l2jmobius.gameserver.model.events.impl.item.OnItemCreate;
|
||||
import com.l2jmobius.gameserver.model.events.impl.sieges.castle.OnCastleSiegeStart;
|
||||
import com.l2jmobius.gameserver.model.events.listeners.ConsumerEventListener;
|
||||
import com.l2jmobius.gameserver.model.events.returns.TerminateReturn;
|
||||
import com.l2jmobius.gameserver.model.holders.ItemHolder;
|
||||
|
||||
import ai.AbstractNpcAI;
|
||||
|
||||
/**
|
||||
* An example usage of Listeners.
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class ListenerTest extends AbstractNpcAI
|
||||
{
|
||||
private static final int[] ELPIES =
|
||||
{
|
||||
20432,
|
||||
22228
|
||||
};
|
||||
|
||||
private ListenerTest()
|
||||
{
|
||||
super(ListenerTest.class.getSimpleName(), "ai/npc");
|
||||
|
||||
// Method preset listener registration
|
||||
// An set function which is a Consumer it has one parameter and doesn't returns anything!
|
||||
setAttackableAttackId(this::onAttackableAttack, ELPIES);
|
||||
|
||||
// Manual listener registration
|
||||
Containers.Global().addListener(new ConsumerEventListener(Containers.Global(), EventType.ON_PLAYER_DLG_ANSWER, (OnPlayerDlgAnswer event) ->
|
||||
{
|
||||
_log.log(Level.INFO, ListenerTest.class.getSimpleName() + ": " + event.getActiveChar() + " OnPlayerDlgAnswer: Answer: " + event.getAnswer() + " MessageId: " + event.getMessageId());
|
||||
}, this));
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be invoked as soon as an L2Attackable (Rabbits 20432 and 22228) is being attacked from L2PcInstance (a player)
|
||||
* @param event
|
||||
*/
|
||||
public void onAttackableAttack(OnAttackableAttack event)
|
||||
{
|
||||
_log.log(Level.INFO, getClass().getSimpleName() + ": " + event.getClass().getSimpleName() + " invoked attacker: " + event.getAttacker() + " target: " + event.getTarget() + " damage: " + event.getDamage() + " skill: " + event.getSkill());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be invoked as soon as L2Attackable (Rabbits 20432 and 22228) are being killed by L2PcInstance (a player)<br>
|
||||
* This listener is registered into individual npcs container.
|
||||
* @param event
|
||||
*/
|
||||
// Annotation listener registration
|
||||
@RegisterEvent(EventType.ON_CREATURE_KILL)
|
||||
@RegisterType(ListenerRegisterType.NPC)
|
||||
@Id(20432)
|
||||
@Id(22228)
|
||||
public void onCreatureKill(OnCreatureKill event)
|
||||
{
|
||||
_log.log(Level.INFO, getClass().getSimpleName() + ": " + event.getClass().getSimpleName() + " invoked attacker: " + event.getAttacker() + " target: " + event.getTarget());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be invoked as soon as Siege of castle ids 1-9 starts<br>
|
||||
* This listener is registered into individual castle container.
|
||||
* @param event
|
||||
*/
|
||||
@RegisterEvent(EventType.ON_CASTLE_SIEGE_START)
|
||||
@RegisterType(ListenerRegisterType.CASTLE)
|
||||
@Range(from = 1, to = 9)
|
||||
public void onSiegeStart(OnCastleSiegeStart event)
|
||||
{
|
||||
_log.log(Level.INFO, getClass().getSimpleName() + ": The siege of " + event.getSiege().getCastle().getName() + " (" + event.getSiege().getCastle().getResidenceId() + ") has started!");
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be invoked as soon as Ancient Adena (5575) item is created on player's inventory (As new item!).<br>
|
||||
* This listener is registered into individual items container.
|
||||
* @param event
|
||||
*/
|
||||
@RegisterEvent(EventType.ON_ITEM_CREATE)
|
||||
@RegisterType(ListenerRegisterType.ITEM)
|
||||
@Id(5575)
|
||||
public void onItemCreate(OnItemCreate event)
|
||||
{
|
||||
_log.log(Level.INFO, getClass().getSimpleName() + ": Item [" + event.getItem() + "] has been created actor: " + event.getActiveChar() + " process: " + event.getProcess() + " reference: " + event.getReference());
|
||||
}
|
||||
|
||||
/**
|
||||
* Prioritized event notification <br>
|
||||
* This method will be invoked as soon as creature from level range between 1 and 10 dies.<br>
|
||||
* This listener is registered into individual npcs container.
|
||||
* @param event
|
||||
*/
|
||||
@RegisterEvent(EventType.ON_CREATURE_KILL)
|
||||
@RegisterType(ListenerRegisterType.NPC)
|
||||
@NpcLevelRange(from = 1, to = 10)
|
||||
@Priority(100)
|
||||
public void OnCreatureKill(OnCreatureKill event)
|
||||
{
|
||||
// 70% chance to drop
|
||||
if (Rnd.get(100) >= 70)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure a player killed this monster.
|
||||
if ((event.getAttacker() != null) && event.getAttacker().isPlayable() && event.getTarget().isAttackable())
|
||||
{
|
||||
final L2Attackable monster = (L2Attackable) event.getTarget();
|
||||
monster.dropItem(event.getAttacker().getActingPlayer(), new ItemHolder(57, Rnd.get(100, 1000)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be invoked as soon a a player logs into the game.<br>
|
||||
* This listener is registered into global players container.
|
||||
* @param event
|
||||
*/
|
||||
@RegisterEvent(EventType.ON_PLAYER_LOGIN)
|
||||
@RegisterType(ListenerRegisterType.GLOBAL_PLAYERS)
|
||||
public void onPlayerLogin(OnPlayerLogin event)
|
||||
{
|
||||
_log.log(Level.INFO, getClass().getSimpleName() + ": Player: " + event.getActiveChar() + " has logged in!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Prioritized event notification - Ensuring that this listener will be the first to receive notification.<br>
|
||||
* Also this method interrupts notification to other listeners and taking over return if somehow it wasn't the first one to set.<br>
|
||||
* This method will be invoked as soon a a creature dies.<br>
|
||||
* This listener is registered into global players container.
|
||||
* @param event
|
||||
* @return termination return preventing the base code execution if needed.
|
||||
*/
|
||||
@RegisterEvent(EventType.ON_CREATURE_KILL)
|
||||
@RegisterType(ListenerRegisterType.GLOBAL_PLAYERS)
|
||||
@Priority(Integer.MAX_VALUE)
|
||||
public TerminateReturn onPlayerDeath(OnCreatureKill event)
|
||||
{
|
||||
if (event.getTarget().isGM())
|
||||
{
|
||||
_log.log(Level.INFO, getClass().getSimpleName() + ": Player: " + event.getTarget() + " was prevented from dying!");
|
||||
return new TerminateReturn(true, true, true);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
new ListenerTest();
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,7 @@ import com.l2jmobius.gameserver.handler.IAdminCommandHandler;
|
||||
import com.l2jmobius.gameserver.model.L2AccessLevel;
|
||||
import com.l2jmobius.gameserver.model.L2World;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jmobius.gameserver.network.Disconnection;
|
||||
import com.l2jmobius.gameserver.network.SystemMessageId;
|
||||
|
||||
/**
|
||||
@@ -129,7 +130,7 @@ public final class AdminChangeAccessLevel implements IAdminCommandHandler
|
||||
{
|
||||
player.setAccessLevel(lvl);
|
||||
player.sendMessage("Your character has been banned. Bye.");
|
||||
player.logout();
|
||||
Disconnection.of(player).defaultSequence(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package handlers.admincommandhandlers;
|
||||
import com.l2jmobius.gameserver.handler.IAdminCommandHandler;
|
||||
import com.l2jmobius.gameserver.model.L2Object;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jmobius.gameserver.network.Disconnection;
|
||||
|
||||
/**
|
||||
* This class handles following admin commands: - character_disconnect = disconnects target player
|
||||
@@ -68,7 +69,7 @@ public class AdminDisconnect implements IAdminCommandHandler
|
||||
{
|
||||
activeChar.sendMessage("Character " + player.getName() + " disconnected from server.");
|
||||
|
||||
player.logout();
|
||||
Disconnection.of(player).defaultSequence(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,10 +18,10 @@ package handlers.admincommandhandlers;
|
||||
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import com.l2jmobius.gameserver.data.sql.impl.OfflineTradersTable;
|
||||
import com.l2jmobius.gameserver.handler.IAdminCommandHandler;
|
||||
import com.l2jmobius.gameserver.model.L2World;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jmobius.gameserver.network.Disconnection;
|
||||
|
||||
public class AdminKick implements IAdminCommandHandler
|
||||
{
|
||||
@@ -44,11 +44,7 @@ public class AdminKick implements IAdminCommandHandler
|
||||
final L2PcInstance plyr = L2World.getInstance().getPlayer(player);
|
||||
if (plyr != null)
|
||||
{
|
||||
if (plyr.getOfflineStartTime() > 0)
|
||||
{
|
||||
OfflineTradersTable.removeTrader(plyr.getObjectId());
|
||||
}
|
||||
plyr.logout();
|
||||
Disconnection.of(plyr).defaultSequence(false);
|
||||
activeChar.sendMessage("You kicked " + plyr.getName() + " from the game.");
|
||||
}
|
||||
}
|
||||
@@ -61,7 +57,7 @@ public class AdminKick implements IAdminCommandHandler
|
||||
if (!player.isGM())
|
||||
{
|
||||
counter++;
|
||||
player.logout();
|
||||
Disconnection.of(player).defaultSequence(false);
|
||||
}
|
||||
}
|
||||
activeChar.sendMessage("Kicked " + counter + " players.");
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jmobius.Config;
|
||||
import com.l2jmobius.gameserver.data.sql.impl.OfflineTradersTable;
|
||||
import com.l2jmobius.gameserver.data.xml.impl.AdminData;
|
||||
import com.l2jmobius.gameserver.handler.AdminCommandHandler;
|
||||
import com.l2jmobius.gameserver.handler.IAdminCommandHandler;
|
||||
@@ -31,6 +30,7 @@ import com.l2jmobius.gameserver.model.L2World;
|
||||
import com.l2jmobius.gameserver.model.Location;
|
||||
import com.l2jmobius.gameserver.model.actor.L2Character;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jmobius.gameserver.network.Disconnection;
|
||||
import com.l2jmobius.gameserver.network.SystemMessageId;
|
||||
|
||||
/**
|
||||
@@ -172,11 +172,7 @@ public class AdminMenu implements IAdminCommandHandler
|
||||
String text;
|
||||
if (plyr != null)
|
||||
{
|
||||
if (plyr.getOfflineStartTime() > 0)
|
||||
{
|
||||
OfflineTradersTable.removeTrader(plyr.getObjectId());
|
||||
}
|
||||
plyr.logout();
|
||||
Disconnection.of(plyr).defaultSequence(false);
|
||||
text = "You kicked " + plyr.getName() + " from the game.";
|
||||
}
|
||||
else
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.l2jmobius.gameserver.model.L2World;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jmobius.gameserver.model.punishment.PunishmentTask;
|
||||
import com.l2jmobius.gameserver.model.punishment.PunishmentType;
|
||||
import com.l2jmobius.gameserver.network.Disconnection;
|
||||
import com.l2jmobius.gameserver.network.L2GameClient;
|
||||
|
||||
/**
|
||||
@@ -58,7 +59,7 @@ public class BanHandler implements IPunishmentHandler
|
||||
}
|
||||
else
|
||||
{
|
||||
client.closeNow();
|
||||
Disconnection.of(client).defaultSequence(false);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -90,7 +91,7 @@ public class BanHandler implements IPunishmentHandler
|
||||
*/
|
||||
private static void applyToPlayer(L2PcInstance player)
|
||||
{
|
||||
player.logout();
|
||||
Disconnection.of(player).defaultSequence(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,6 +18,7 @@ package handlers.telnethandlers.player;
|
||||
|
||||
import com.l2jmobius.gameserver.model.L2World;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jmobius.gameserver.network.Disconnection;
|
||||
import com.l2jmobius.gameserver.network.telnet.ITelnetCommand;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
@@ -49,7 +50,7 @@ public class Kick implements ITelnetCommand
|
||||
final L2PcInstance player = L2World.getInstance().getPlayer(args[0]);
|
||||
if (player != null)
|
||||
{
|
||||
player.logout();
|
||||
Disconnection.of(player).defaultSequence(false);
|
||||
return "Player has been successfully kicked.";
|
||||
}
|
||||
return "Couldn't find player with such name.";
|
||||
|
||||
Reference in New Issue
Block a user