Legendary contribution by hacker here
Code:
package com.notorious.world.content.obj;
import java.util.HashMap;
import java.util.Map;
import com.notorious.definition.ItemDefinition;
import com.notorious.entity.item.Item;
import com.notorious.entity.player.Player;
/**
* @author Raw Envy
*/
public class LightSources
{
public static final int TINDERBOX = 590;
/**
* Enum used for storing the light sources data
*/
public enum LightSource
{
TORCH(1, 596, 594),
CANDLE(1, 36, 33),
BLACK_CANDLE(1, 38, 32),
CANDLE_LANTERN(4, 4529, 4531),
OIL_LAMP(12, 4522, 4524),
OIL_LANTERN(26, 4537, 4539),
BULLSEYE_LANTERN(49, 4548, 4550),
SAPPHIRE_LANTERN(49, 4701, 4702),
EMERALD_LANTERN(49, 9064, 9065),
MINING_HELMET(65, 5014, 5013);
private int levelReq;
private int unlitId;
private int litId;
private static Map<Integer, LightSource> sources = new HashMap<>();
static
{
for (LightSource s : values())
{
sources.put(s.unlitId, s);
sources.put(s.litId, s);
}
}
/**
* Enum constructor
*
* @Param levelRequirement
* @Param unlitItemID
* @Param litItemID
*/
private LightSource(final int levelRequirement, final int unlitItemId, final int litItemId) // Enum constructors always private
{
this.levelReq = levelRequirement;
this.unlitId = unlitItemId;
this.litId = litItemId;
}
public int getlevelReq()
{
return levelReq; // Checks the level requirement
}
public int getUnlitId()
{
return unlitId; // Gets the unlit item Id
}
public int getLitId()
{
return litId; // Gets the lit item Id
}
public static LightSource getSource(int id)
{
return sources.get(id);
}
}
/**
* Method used to light an unlit source. Checks the item used id and
* lights if its unlit and if player has a tinderbox
*
* @Param player
* @Param itemUsed
* @Param usedWith
*/
public static boolean lightSource(Player p, int itemUsed, int usedWith)
{
final int item = (itemUsed != TINDERBOX ? itemUsed : usedWith);
LightSource s = LightSource.getSource(item);
if (s == null)
{
return false;
}
p.getFields().getInventory().remove(new Item(item));
p.getFields().getInventory().add(new Item(s.getLitId()));
p.sendMessage("You light the " + ItemDefinition.getName(item).toLowerCase() + ".");
return true;
}
public static boolean extinguish(Player p, int itemId)
{
LightSource s = LightSource.getSource(itemId);
if (s == null || !p.getFields().getInventory().contains(itemId))
{
return false;
}
p.getFields().getInventory().remove(itemId, 1);
p.getFields().getInventory().add(new Item(s.getUnlitId(), 1));
p.sendMessage("You extinguish the " + ItemDefinition.getName(itemId).toLowerCase() + ".");
return true;
}
}