Dropped dynamic extension support.
This commit is contained in:
parent
e6720af598
commit
6472e7822d
@ -1 +0,0 @@
|
||||
# Configuration file for dynamic extensions
|
@ -77,7 +77,6 @@ public final class Config
|
||||
public static final String SIEGE_CONFIG_FILE = "./config/main/Siege.ini";
|
||||
// protected
|
||||
private static final String DAEMONS_CONFIG_FILE = "./config/protected/Daemons.ini";
|
||||
public static final String EXTENDER_CONFIG_FILE = "./config/protected/Extender.ini";
|
||||
private static final String PROTECT_FLOOD_CONFIG_FILE = "./config/protected/Flood.ini";
|
||||
private static final String ID_CONFIG_FILE = "./config/protected/IdFactory.ini";
|
||||
private static final String PROTECT_OTHER_CONFIG_FILE = "./config/protected/Other.ini";
|
||||
@ -1143,10 +1142,6 @@ public final class Config
|
||||
public static String RAID_INFO_IDS;
|
||||
public static List<Integer> RAID_INFO_IDS_LIST = new ArrayList<>();
|
||||
|
||||
public static File SCRIPT_ROOT;
|
||||
|
||||
public static Map<String, List<String>> EXTENDERS;
|
||||
|
||||
public static long AUTOSAVE_INITIAL_TIME;
|
||||
public static long AUTOSAVE_DELAY_TIME;
|
||||
public static long CHECK_CONNECTION_INACTIVITY_TIME;
|
||||
@ -1168,6 +1163,7 @@ public final class Config
|
||||
public static int LOGIN_TRY_BEFORE_BAN;
|
||||
public static int LOGIN_BLOCK_AFTER_BAN;
|
||||
public static File DATAPACK_ROOT;
|
||||
public static File SCRIPT_ROOT;
|
||||
public static int GAME_SERVER_LOGIN_PORT;
|
||||
public static String GAME_SERVER_LOGIN_HOST;
|
||||
public static String INTERNAL_HOSTNAME;
|
||||
@ -3580,67 +3576,6 @@ public final class Config
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadExtendersConfig()
|
||||
{
|
||||
EXTENDERS = new HashMap<>();
|
||||
final File f = new File(EXTENDER_CONFIG_FILE);
|
||||
if (f.exists())
|
||||
{
|
||||
LineNumberReader lineReader = null;
|
||||
try
|
||||
{
|
||||
lineReader = new LineNumberReader(new BufferedReader(new FileReader(f)));
|
||||
String line;
|
||||
while ((line = lineReader.readLine()) != null)
|
||||
{
|
||||
int iPos = line.indexOf("#");
|
||||
|
||||
if (iPos != -1)
|
||||
{
|
||||
line = line.substring(0, iPos);
|
||||
}
|
||||
|
||||
if (line.trim().length() == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
iPos = line.indexOf("=");
|
||||
if (iPos != -1)
|
||||
{
|
||||
final String baseName = line.substring(0, iPos).trim();
|
||||
final String className = line.substring(iPos + 1).trim();
|
||||
|
||||
if (EXTENDERS.get(baseName) == null)
|
||||
{
|
||||
EXTENDERS.put(baseName, new ArrayList<String>());
|
||||
}
|
||||
|
||||
EXTENDERS.get(baseName).add(className);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.warning("Failed to Load " + EXTENDER_CONFIG_FILE + " File.");
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (lineReader != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
lineReader.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadDaemonsConf()
|
||||
{
|
||||
try
|
||||
@ -4047,7 +3982,6 @@ public final class Config
|
||||
loadOfflineConfig();
|
||||
|
||||
// Other
|
||||
loadExtendersConfig();
|
||||
loadDaemonsConf();
|
||||
|
||||
if (USE_SAY_FILTER)
|
||||
|
@ -140,7 +140,6 @@ import org.l2jmobius.gameserver.thread.daemons.DeadlockDetector;
|
||||
import org.l2jmobius.gameserver.thread.daemons.ItemsAutoDestroy;
|
||||
import org.l2jmobius.gameserver.thread.daemons.PcPoint;
|
||||
import org.l2jmobius.gameserver.ui.Gui;
|
||||
import org.l2jmobius.gameserver.util.DynamicExtension;
|
||||
import org.l2jmobius.status.Status;
|
||||
|
||||
public class GameServer
|
||||
@ -472,14 +471,6 @@ public class GameServer
|
||||
Util.printSection("Game Server");
|
||||
|
||||
LOGGER.info("IdFactory: Free ObjectID's remaining: " + IdFactory.getInstance().size());
|
||||
try
|
||||
{
|
||||
DynamicExtension.getInstance();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LOGGER.info("DynamicExtension could not be loaded and initialized" + ex);
|
||||
}
|
||||
|
||||
Util.printSection("Custom Mods");
|
||||
|
||||
|
@ -34,7 +34,6 @@ import org.l2jmobius.gameserver.model.actor.Summon;
|
||||
import org.l2jmobius.gameserver.model.actor.instance.NpcInstance;
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.actor.position.Location;
|
||||
import org.l2jmobius.gameserver.model.extender.BaseExtender.EventType;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ActionFailed;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.AutoAttackStart;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.AutoAttackStop;
|
||||
@ -287,10 +286,6 @@ abstract class AbstractAI implements Ctrl
|
||||
break;
|
||||
}
|
||||
}
|
||||
_actor.fireEvent(EventType.SETINTENTION.name, new Object[]
|
||||
{
|
||||
intention
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -16,7 +16,6 @@
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
@ -29,8 +28,6 @@ import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.actor.knownlist.WorldObjectKnownList;
|
||||
import org.l2jmobius.gameserver.model.actor.poly.ObjectPoly;
|
||||
import org.l2jmobius.gameserver.model.actor.position.ObjectPosition;
|
||||
import org.l2jmobius.gameserver.model.extender.BaseExtender;
|
||||
import org.l2jmobius.gameserver.model.extender.BaseExtender.EventType;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ActionFailed;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.GetItem;
|
||||
@ -58,99 +55,9 @@ public abstract class WorldObject
|
||||
// Objects can only see objects in same instancezone, instance 0 is normal world -1 the all seeing world
|
||||
private int _instanceId = 0;
|
||||
|
||||
private BaseExtender _extender = null;
|
||||
|
||||
public WorldObject(int objectId)
|
||||
{
|
||||
_objectId = objectId;
|
||||
if (Config.EXTENDERS.get(getClass().getName()) != null)
|
||||
{
|
||||
for (String className : Config.EXTENDERS.get(getClass().getName()))
|
||||
{
|
||||
try
|
||||
{
|
||||
final Class<?> clazz = Class.forName(className);
|
||||
if (clazz == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!BaseExtender.class.isAssignableFrom(clazz))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!(Boolean) clazz.getMethod("canCreateFor", WorldObject.class).invoke(null, this))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
final Constructor<?> construct = clazz.getConstructor(WorldObject.class);
|
||||
if (construct != null)
|
||||
{
|
||||
addExtender((BaseExtender) construct.newInstance(this));
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param newExtender as BaseExtender
|
||||
*/
|
||||
public void addExtender(BaseExtender newExtender)
|
||||
{
|
||||
if (_extender == null)
|
||||
{
|
||||
_extender = newExtender;
|
||||
}
|
||||
else
|
||||
{
|
||||
_extender.addExtender(newExtender);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param simpleName as String<br>
|
||||
* @return as BaseExtender - null<br>
|
||||
*/
|
||||
public BaseExtender getExtender(String simpleName)
|
||||
{
|
||||
if (_extender == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _extender.getExtender(simpleName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param event as String<br>
|
||||
* @param params
|
||||
* @return as Object
|
||||
*/
|
||||
public Object fireEvent(String event, Object... params)
|
||||
{
|
||||
if (_extender == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _extender.onEvent(event, params);
|
||||
}
|
||||
|
||||
public void removeExtender(BaseExtender ext)
|
||||
{
|
||||
if (_extender != null)
|
||||
{
|
||||
if (_extender == ext)
|
||||
{
|
||||
_extender = _extender.getNextExtender();
|
||||
}
|
||||
else
|
||||
{
|
||||
_extender.removeExtender(ext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onAction(PlayerInstance player)
|
||||
@ -188,7 +95,6 @@ public abstract class WorldObject
|
||||
*/
|
||||
public void onSpawn()
|
||||
{
|
||||
fireEvent(EventType.SPAWN.name, (Object[]) null);
|
||||
}
|
||||
|
||||
// Position - Should remove to fully move to WorldObjectPosition
|
||||
@ -268,8 +174,6 @@ public abstract class WorldObject
|
||||
{
|
||||
ItemsOnGroundManager.getInstance().removeObject(this);
|
||||
}
|
||||
|
||||
fireEvent(EventType.DELETE.name, (Object[]) null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -93,7 +93,6 @@ import org.l2jmobius.gameserver.model.entity.event.GameEvent;
|
||||
import org.l2jmobius.gameserver.model.entity.event.TvT;
|
||||
import org.l2jmobius.gameserver.model.entity.event.VIP;
|
||||
import org.l2jmobius.gameserver.model.entity.olympiad.Olympiad;
|
||||
import org.l2jmobius.gameserver.model.extender.BaseExtender.EventType;
|
||||
import org.l2jmobius.gameserver.model.quest.Quest;
|
||||
import org.l2jmobius.gameserver.model.quest.QuestState;
|
||||
import org.l2jmobius.gameserver.model.zone.ZoneId;
|
||||
@ -1203,10 +1202,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
|
||||
if (attack.hasHits())
|
||||
{
|
||||
broadcastPacket(attack);
|
||||
fireEvent(EventType.ATTACK.name, new Object[]
|
||||
{
|
||||
_target
|
||||
});
|
||||
}
|
||||
|
||||
// Like L2OFF mobs id 27181 can teleport players near cabrio
|
||||
@ -1967,12 +1962,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
|
||||
{
|
||||
onMagicLaunchedTimer(targets, skill, coolTime, true);
|
||||
}
|
||||
fireEvent(EventType.CAST.name, new Object[]
|
||||
{
|
||||
skill,
|
||||
target,
|
||||
targets
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2143,10 +2132,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
|
||||
{
|
||||
((PlayerInstance) this).reviveRequest(((PlayerInstance) this), null, false);
|
||||
}
|
||||
fireEvent(EventType.DIE.name, new Object[]
|
||||
{
|
||||
killer
|
||||
});
|
||||
|
||||
// Update active skills in progress (In Use and Not In Use because stacked) icones on client
|
||||
updateEffectIcons();
|
||||
@ -2204,7 +2189,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
|
||||
{
|
||||
setIsPendingRevive(true);
|
||||
}
|
||||
fireEvent(EventType.REVIVE.name, (Object[]) null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -38,7 +38,6 @@ import org.l2jmobius.gameserver.model.WorldObject;
|
||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
import org.l2jmobius.gameserver.model.actor.knownlist.NullKnownList;
|
||||
import org.l2jmobius.gameserver.model.actor.position.Location;
|
||||
import org.l2jmobius.gameserver.model.extender.BaseExtender.EventType;
|
||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ActionFailed;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.InventoryUpdate;
|
||||
@ -160,14 +159,7 @@ public final class ItemInstance extends WorldObject
|
||||
*/
|
||||
public void setOwnerId(String process, int owner_id, PlayerInstance creator, WorldObject reference)
|
||||
{
|
||||
final int oldOwner = _ownerId;
|
||||
setOwnerId(owner_id);
|
||||
|
||||
fireEvent(EventType.SETOWNER.name, new Object[]
|
||||
{
|
||||
process,
|
||||
oldOwner
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1141,14 +1133,6 @@ public final class ItemInstance extends WorldObject
|
||||
LOGGER.warning("Could not restore item " + objectId + " from DB " + e);
|
||||
}
|
||||
|
||||
if (inst != null)
|
||||
{
|
||||
inst.fireEvent(EventType.LOAD.name, new Object[]
|
||||
{
|
||||
// con
|
||||
});
|
||||
}
|
||||
|
||||
return inst;
|
||||
}
|
||||
|
||||
@ -1261,11 +1245,6 @@ public final class ItemInstance extends WorldObject
|
||||
{
|
||||
LOGGER.warning("Could not update item " + getObjectId() + " in DB: Reason: " + e);
|
||||
}
|
||||
|
||||
if (_existsInDb)
|
||||
{
|
||||
fireEvent(EventType.STORE.name, (Object[]) null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1345,11 +1324,6 @@ public final class ItemInstance extends WorldObject
|
||||
LOGGER.warning("Could not delete item " + getObjectId() + " in DB: " + e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (!_existsInDb)
|
||||
{
|
||||
fireEvent(EventType.DELETE.name, (Object[]) null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -148,7 +148,6 @@ import org.l2jmobius.gameserver.model.entity.siege.Castle;
|
||||
import org.l2jmobius.gameserver.model.entity.siege.FortSiege;
|
||||
import org.l2jmobius.gameserver.model.entity.siege.Siege;
|
||||
import org.l2jmobius.gameserver.model.entity.siege.clanhalls.DevastatedCastle;
|
||||
import org.l2jmobius.gameserver.model.extender.BaseExtender.EventType;
|
||||
import org.l2jmobius.gameserver.model.holders.PlayerStatsHolder;
|
||||
import org.l2jmobius.gameserver.model.holders.TimestampHolder;
|
||||
import org.l2jmobius.gameserver.model.quest.Quest;
|
||||
@ -9369,8 +9368,6 @@ public final class PlayerInstance extends Playable
|
||||
|
||||
if (player != null)
|
||||
{
|
||||
player.fireEvent(EventType.LOAD.name, (Object[]) null);
|
||||
|
||||
try
|
||||
{
|
||||
Thread.sleep(100);
|
||||
@ -9704,8 +9701,6 @@ public final class PlayerInstance extends Playable
|
||||
aVars.storeMe();
|
||||
}
|
||||
|
||||
fireEvent(EventType.STORE.name, (Object[]) null);
|
||||
|
||||
// If char is in Offline trade, setStored must be true
|
||||
if (isInOfflineMode())
|
||||
{
|
||||
|
@ -1,147 +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 org.l2jmobius.gameserver.model.extender;
|
||||
|
||||
import org.l2jmobius.gameserver.model.WorldObject;
|
||||
|
||||
/**
|
||||
* @author Azagthtot BaseExtender
|
||||
*/
|
||||
public class BaseExtender
|
||||
{
|
||||
public enum EventType
|
||||
{
|
||||
LOAD("load"), // null
|
||||
STORE("store"), // null
|
||||
CAST("cast"), // Skill , Creature, Creature[]
|
||||
ATTACK("attack"), // Creature
|
||||
CRAFT("craft"),
|
||||
ENCHANT("enchant"),
|
||||
SPAWN("spawn"), // null
|
||||
DELETE("delete"), // null
|
||||
SETOWNER("setwoner"), // int, String
|
||||
DROP("drop"), // null
|
||||
DIE("die"), // Creature
|
||||
REVIVE("revive"), // null
|
||||
SETINTENTION("setintention"); // CtrlIntention
|
||||
public final String name;
|
||||
|
||||
EventType(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object as WorldObject<br>
|
||||
* @return as boolean<br>
|
||||
*/
|
||||
public static boolean canCreateFor(WorldObject object)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected WorldObject _owner;
|
||||
private BaseExtender _next = null;
|
||||
|
||||
/**
|
||||
* @param owner - WorldObject
|
||||
*/
|
||||
public BaseExtender(WorldObject owner)
|
||||
{
|
||||
_owner = owner;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return as Object
|
||||
*/
|
||||
public WorldObject getOwner()
|
||||
{
|
||||
return _owner;
|
||||
}
|
||||
|
||||
/**
|
||||
* onEvent - super.onEvent(event,params);<BR>
|
||||
* <BR>
|
||||
* @param event as String<br>
|
||||
* @param params as Object[]<br>
|
||||
* @return as Object
|
||||
*/
|
||||
public Object onEvent(String event, Object... params)
|
||||
{
|
||||
if (_next == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _next.onEvent(event, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param simpleClassName as String<br>
|
||||
* @return as BaseExtender - null
|
||||
*/
|
||||
public BaseExtender getExtender(String simpleClassName)
|
||||
{
|
||||
if (getClass().getSimpleName().compareTo(simpleClassName) == 0)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
else if (_next != null)
|
||||
{
|
||||
return _next.getExtender(simpleClassName);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void removeExtender(BaseExtender ext)
|
||||
{
|
||||
if (_next != null)
|
||||
{
|
||||
if (_next == ext)
|
||||
{
|
||||
_next = _next._next;
|
||||
}
|
||||
else
|
||||
{
|
||||
_next.removeExtender(ext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BaseExtender getNextExtender()
|
||||
{
|
||||
return _next;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param newExtender as BaseExtender
|
||||
*/
|
||||
public void addExtender(BaseExtender newExtender)
|
||||
{
|
||||
if (_next == null)
|
||||
{
|
||||
_next = newExtender;
|
||||
}
|
||||
else
|
||||
{
|
||||
_next.addExtender(newExtender);
|
||||
}
|
||||
}
|
||||
}
|
@ -267,10 +267,6 @@ public class MultiSellChoose extends GameClientPacket
|
||||
LOGGER.warning("Character: " + player.getName() + " is trying to cheat in multisell, merchatnt id:" + (merchant != null ? merchant.getNpcId() : 0));
|
||||
return;
|
||||
}
|
||||
if (itemToTake.fireEvent("MULTISELL", (Object[]) null) != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (itemToTake.isWear())
|
||||
{
|
||||
|
@ -112,16 +112,10 @@ public final class RequestCrystallizeItem extends GameClientPacket
|
||||
}
|
||||
|
||||
final ItemInstance itemToRemove = player.getInventory().getItemByObjectId(_objectId);
|
||||
|
||||
if ((itemToRemove == null) || itemToRemove.isWear())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (itemToRemove.fireEvent("CRYSTALLIZE", (Object[]) null) != null)
|
||||
{
|
||||
player.sendPacket(SystemMessageId.CANNOT_DISCARD_THIS_ITEM);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!itemToRemove.getItem().isCrystallizable() || (itemToRemove.getItem().getCrystalCount() <= 0) || (itemToRemove.getItem().getCrystalType() == Item.CRYSTAL_NONE))
|
||||
{
|
||||
|
@ -85,11 +85,6 @@ public final class RequestDestroyItem extends GameClientPacket
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (itemToRemove.fireEvent("DESTROY", (Object[]) null) != null)
|
||||
{
|
||||
player.sendPacket(SystemMessageId.CANNOT_DISCARD_THIS_ITEM);
|
||||
return;
|
||||
}
|
||||
|
||||
// Cannot discard item that the skill is consumming
|
||||
if (player.isCastingNow())
|
||||
|
@ -620,11 +620,6 @@ public final class RequestEnchantItem extends GameClientPacket
|
||||
}
|
||||
}
|
||||
|
||||
final Object aChance = item.fireEvent("calcEnchantChance", new Object[chance]);
|
||||
if (aChance != null)
|
||||
{
|
||||
chance = (Integer) aChance;
|
||||
}
|
||||
synchronized (item)
|
||||
{
|
||||
if (rndValue < chance)
|
||||
@ -725,10 +720,6 @@ public final class RequestEnchantItem extends GameClientPacket
|
||||
count = 1;
|
||||
}
|
||||
|
||||
if (item.fireEvent("enchantFail", new Object[] {}) != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
final ItemInstance destroyItem = player.getInventory().destroyItem("Enchant", item, player, null);
|
||||
if (destroyItem == null)
|
||||
{
|
||||
|
@ -1,336 +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 org.l2jmobius.gameserver.util;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
|
||||
/**
|
||||
* extension loader
|
||||
* @author galun
|
||||
* @version $Id: DynamicExtension.java,v 1.3 2006/05/14 17:19:39 galun Exp $
|
||||
*/
|
||||
public class DynamicExtension
|
||||
{
|
||||
private static Logger LOGGER = Logger.getLogger(DynamicExtension.class.getName());
|
||||
private JarClassLoader _classLoader;
|
||||
private Properties _prop;
|
||||
private ConcurrentHashMap<String, Object> _loadedExtensions;
|
||||
private static DynamicExtension _instance;
|
||||
private final ConcurrentHashMap<String, ExtensionFunction> _getters;
|
||||
private final ConcurrentHashMap<String, ExtensionFunction> _setters;
|
||||
|
||||
/**
|
||||
* create an instance of DynamicExtension this will be done by GameServer according to the altsettings.ini
|
||||
*/
|
||||
private DynamicExtension()
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = this;
|
||||
}
|
||||
_getters = new ConcurrentHashMap<>();
|
||||
_setters = new ConcurrentHashMap<>();
|
||||
initExtensions();
|
||||
}
|
||||
|
||||
/**
|
||||
* get the singleton of DynamicInstance
|
||||
* @return the singleton instance
|
||||
*/
|
||||
public static DynamicExtension getInstance()
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = new DynamicExtension();
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* get an extension object by class name
|
||||
* @param className he class name as defined in the extension properties
|
||||
* @return the object or null if not found
|
||||
*/
|
||||
public Object getExtension(String className)
|
||||
{
|
||||
return _loadedExtensions.get(className);
|
||||
}
|
||||
|
||||
/**
|
||||
* initialize all configured extensions
|
||||
* @return
|
||||
*/
|
||||
public String initExtensions()
|
||||
{
|
||||
_prop = new Properties();
|
||||
String res = "";
|
||||
_loadedExtensions = new ConcurrentHashMap<>();
|
||||
|
||||
FileInputStream fis = null;
|
||||
|
||||
try
|
||||
{
|
||||
fis = new FileInputStream(Config.EXTENDER_CONFIG_FILE);
|
||||
_prop.load(fis);
|
||||
}
|
||||
catch (FileNotFoundException ex)
|
||||
{
|
||||
LOGGER.info(ex.getMessage() + ": no extensions to load");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LOGGER.warning("could not load properties " + ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (fis != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
fis.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_classLoader = new JarClassLoader();
|
||||
|
||||
for (Object o : _prop.keySet())
|
||||
{
|
||||
final String k = (String) o;
|
||||
|
||||
if (k.endsWith("Class"))
|
||||
{
|
||||
res += initExtension(_prop.getProperty(k)) + "\n";
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* init a named extension
|
||||
* @param name the class name and optionally a jar file name delimited with a '@' if the jar file is not in the class path
|
||||
* @return
|
||||
*/
|
||||
public String initExtension(String name)
|
||||
{
|
||||
String className = name;
|
||||
final String[] p = name.split("@");
|
||||
String res = name + " loaded";
|
||||
|
||||
if (p.length > 1)
|
||||
{
|
||||
_classLoader.addJarFile(p[1]);
|
||||
className = p[0];
|
||||
}
|
||||
|
||||
if (_loadedExtensions.containsKey(className))
|
||||
{
|
||||
return "already loaded";
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
final Class<?> extension = Class.forName(className, true, _classLoader);
|
||||
final Object obj = extension.getDeclaredConstructor().newInstance();
|
||||
extension.getMethod("init", new Class[0]).invoke(obj, new Object[0]);
|
||||
LOGGER.info("Extension " + className + " loaded.");
|
||||
_loadedExtensions.put(className, obj);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LOGGER.warning(name + " " + ex);
|
||||
res = ex.toString();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* create a new class loader which resets the cache (jar files and loaded classes) on next class loading request it will read the jar again
|
||||
*/
|
||||
protected void clearCache()
|
||||
{
|
||||
_classLoader = new JarClassLoader();
|
||||
}
|
||||
|
||||
/**
|
||||
* call unloadExtension() for all known extensions
|
||||
* @return
|
||||
*/
|
||||
public String unloadExtensions()
|
||||
{
|
||||
String res = "";
|
||||
|
||||
for (String e : _loadedExtensions.keySet())
|
||||
{
|
||||
res += unloadExtension(e) + "\n";
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* get all loaded extensions
|
||||
* @return a String array with the class names
|
||||
*/
|
||||
public String[] getExtensions()
|
||||
{
|
||||
final String[] l = new String[_loadedExtensions.size()];
|
||||
_loadedExtensions.keySet().toArray(l);
|
||||
return l;
|
||||
}
|
||||
|
||||
/**
|
||||
* unload a named extension
|
||||
* @param name the class name and optionally a jar file name delimited with a '@'
|
||||
* @return
|
||||
*/
|
||||
public String unloadExtension(String name)
|
||||
{
|
||||
String className = name;
|
||||
final String[] p = name.split("@");
|
||||
|
||||
if (p.length > 1)
|
||||
{
|
||||
_classLoader.addJarFile(p[1]);
|
||||
className = p[0];
|
||||
}
|
||||
|
||||
String res = className + " unloaded";
|
||||
|
||||
try
|
||||
{
|
||||
final Object obj = _loadedExtensions.get(className);
|
||||
final Class<?> extension = obj.getClass();
|
||||
_loadedExtensions.remove(className);
|
||||
extension.getMethod("unload", new Class[0]).invoke(obj, new Object[0]);
|
||||
LOGGER.info("Extension " + className + " unloaded.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LOGGER.warning("could not unload " + className + " " + ex);
|
||||
res = ex.toString();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* unloads all extensions, resets the cache and initializes all configured extensions
|
||||
*/
|
||||
public void reload()
|
||||
{
|
||||
unloadExtensions();
|
||||
clearCache();
|
||||
initExtensions();
|
||||
}
|
||||
|
||||
/**
|
||||
* unloads a named extension, resets the cache and initializes the extension
|
||||
* @param name the class name and optionally a jar file name delimited with a '@' if the jar file is not in the class path
|
||||
*/
|
||||
public void reload(String name)
|
||||
{
|
||||
unloadExtension(name);
|
||||
clearCache();
|
||||
initExtension(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* register a getter function given a (hopefully) unique name
|
||||
* @param name the name of the function
|
||||
* @param function the ExtensionFunction implementation
|
||||
*/
|
||||
public void addGetter(String name, ExtensionFunction function)
|
||||
{
|
||||
_getters.put(name, function);
|
||||
}
|
||||
|
||||
/**
|
||||
* deregister a getter function
|
||||
* @param name the name used for registering
|
||||
*/
|
||||
public void removeGetter(String name)
|
||||
{
|
||||
_getters.remove(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* call a getter function registered with DynamicExtension
|
||||
* @param name the function name
|
||||
* @param arg a function argument
|
||||
* @return an object from the extension
|
||||
*/
|
||||
public Object get(String name, String arg)
|
||||
{
|
||||
final ExtensionFunction func = _getters.get(name);
|
||||
|
||||
if (func != null)
|
||||
{
|
||||
return func.get(arg);
|
||||
}
|
||||
return "<none>";
|
||||
}
|
||||
|
||||
/**
|
||||
* register a setter function given a (hopefully) unique name
|
||||
* @param name the name of the function
|
||||
* @param function the ExtensionFunction implementation
|
||||
*/
|
||||
public void addSetter(String name, ExtensionFunction function)
|
||||
{
|
||||
_setters.put(name, function);
|
||||
}
|
||||
|
||||
/**
|
||||
* deregister a setter function
|
||||
* @param name the name used for registering
|
||||
*/
|
||||
public void removeSetter(String name)
|
||||
{
|
||||
_setters.remove(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* call a setter function registered with DynamicExtension
|
||||
* @param name the function name
|
||||
* @param arg a function argument
|
||||
* @param obj an object to set
|
||||
*/
|
||||
public void set(String name, String arg, Object obj)
|
||||
{
|
||||
final ExtensionFunction func = _setters.get(name);
|
||||
|
||||
if (func != null)
|
||||
{
|
||||
func.set(arg, obj);
|
||||
}
|
||||
}
|
||||
|
||||
public JarClassLoader getClassLoader()
|
||||
{
|
||||
return _classLoader;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user