Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### Eclipse Workspace Patch 1.0
- #P L2JHellasD
- Index: data/scripts/handlers/itemhandlers/Hero24h.java
- ===================================================================
- --- data/scripts/handlers/itemhandlers/Hero24h.java (revision 0)
- +++ data/scripts/handlers/itemhandlers/Hero24h.java (working copy)
- @@ -0,0 +1,269 @@
- +/*
- + * 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 handlers.itemhandlers;
- +
- +import java.io.File;
- +import java.io.FileReader;
- +import java.io.FileWriter;
- +import java.io.IOException;
- +import java.io.LineNumberReader;
- +import java.util.StringTokenizer;
- +import java.util.concurrent.ScheduledFuture;
- +
- +import javolution.util.FastList;
- +
- +import com.PackRoot;
- +import com.l2jhellas.Config;
- +import com.l2jhellas.gameserver.ThreadPoolManager;
- +import com.l2jhellas.gameserver.handler.IItemHandler;
- +import com.l2jhellas.gameserver.model.L2ItemInstance;
- +import com.l2jhellas.gameserver.model.actor.L2Playable;
- +import com.l2jhellas.gameserver.model.actor.instance.L2PcInstance;
- +import com.l2jhellas.gameserver.model.entity.Hero;
- +
- +/**
- + * @author AbsolutePower
- + */
- +public class Hero24h implements IItemHandler
- +{
- + private static int[] _itemIds =
- + {
- + //custom item id here too
- + };
- +
- + //hero item id here(dont forget to put item id here :) )
- + private int HeroItemId =0;
- + private L2PcInstance _player = null;
- + private boolean is24Hero = false;
- + Hero _hero;
- +
- + public static FastList<String> HeroIds = new FastList<>();
- + static File file = new File(PackRoot.DATAPACK_ROOT, "data/HeroIds.txt");
- +
- +
- + @Override
- + public void useItem(L2Playable playable, L2ItemInstance item)
- + {
- + if (!(playable instanceof L2PcInstance))
- + return;
- +
- + final L2PcInstance activeChar = (L2PcInstance) playable;
- + _player = activeChar;
- + final int itemId = item.getItemId();
- +
- + if(isCatched(_player))
- + {
- + _player.sendMessage("You are already 24h hero!");
- + return;
- + }
- +
- + if(_player!=null && itemId == HeroItemId && _hero!=null)
- + {
- + MkTiNe();
- + _hero.activate24hHero(_player);
- + addHeroId( _player);
- + is24Hero = true;
- + HeroiDsLoad();
- + StartHeroChecker();
- +
- + }
- + }
- +
- + private ScheduledFuture<?> _HeroChecker;
- +
- + private class HeroChecker implements Runnable
- + {
- +
- + @Override
- + public void run()
- + {
- + if(_player != null)
- + {
- + if(is24Hero && _hero != null)
- + {
- + _hero.Deactivate24hHero(_player);
- + removeHeroId(_player);
- + stopHeroChecker();
- + }
- + }
- + else if(isCatched(_player))
- + {
- + _hero.Deactivate24hHero(_player);
- + removeHeroId(_player);
- + stopHeroChecker();
- + }
- + HeroiDsLoad();
- + }
- +
- + }
- + private void stopHeroChecker()
- + {
- + if(_HeroChecker!=null)
- + _HeroChecker.cancel(true);
- + _HeroChecker = null;
- + }
- +
- + private void StartHeroChecker()
- + {
- + _HeroChecker = ThreadPoolManager.getInstance().scheduleGeneral(new HeroChecker(), 60000* 1000);
- + }
- +
- + // make textfile if not exist
- + public static void MkTiNe()
- + {
- + try
- + {
- + File file = new File(PackRoot.DATAPACK_ROOT, "data/HeroIds.txt");
- + boolean exist = file.createNewFile();
- + if (!exist)
- + return;
- + }
- + catch (IOException e)
- + {
- + System.err.print("could not create new file:" + file);
- + if (Config.DEVELOPER)
- + e.printStackTrace();
- + }
- + }
- +
- + public void addHeroId(L2PcInstance p)
- + {
- + MkTiNe();
- + final int HeroId = getId(p);
- + final String name = p.getName();
- +
- + if (HeroId != 0 && name != null)
- + HeroIds.add("Name");
- + HeroIds.add(name);
- + HeroIds.add("HeroId");
- + HeroIds.add(String.valueOf(HeroId));
- + HeroIds.add("-");
- +
- + FileWriter s = null;
- + try
- + {
- + s = new FileWriter(file);
- + for (int i = 0; i < HeroIds.size(); i++)
- + {
- + s.write(HeroIds.get(i));
- + s.write("\r\n");
- + }
- + s.flush();
- + s.close();
- + s = null;
- + }
- + catch (IOException e)
- + {
- + System.err.print("could not add HeroiD in:" + file);
- + if (Config.DEVELOPER)
- + e.printStackTrace();
- + }
- + HeroiDsLoad();
- + }
- +
- + public void removeHeroId(L2PcInstance p)
- + {
- + final int HeroId = getId(p);
- + final String name = p.getName();
- +
- + if (HeroId != 0 && name != null)
- + HeroIds.remove("Name");
- + HeroIds.remove(name);
- + HeroIds.remove("HeroId");
- + HeroIds.remove(String.valueOf(HeroId));
- + HeroIds.remove("-");
- +
- + FileWriter s = null;
- + try
- + {
- + s = new FileWriter(file);
- + for (int i = 0; i < HeroIds.size(); i++)
- + {
- + s.write(HeroIds.get(i));
- + s.write("\r\n");
- + }
- + s.flush();
- + s.close();
- + s = null;
- + }
- + catch (IOException e)
- + {
- + System.err.print("could not remove heroid new file:" + file);
- + if (Config.DEVELOPER)
- + e.printStackTrace();
- + }
- + HeroiDsLoad();
- + }
- +
- + public static void HeroiDsLoad()
- + {
- + LineNumberReader l = null;
- + try
- + {
- + MkTiNe();
- + String line = null;
- + l = new LineNumberReader(new FileReader(file));
- + while ((line = l.readLine()) != null)
- + {
- + StringTokenizer st = new StringTokenizer(line, "\n\r");
- + if (st.hasMoreTokens())
- + {
- + String n = st.nextToken();
- + HeroIds.add(n);
- + }
- + }
- + }
- + catch (Exception e)
- + {
- + System.err.print("could not load heroIds from file:" + file);
- + if (Config.DEVELOPER)
- + e.printStackTrace();
- + }
- + finally
- + {
- + try
- + {
- + if (l != null)
- + l.close();
- + }
- + catch (Exception e)
- + {
- + }
- + }
- + }
- +
- + // return true if Hero include
- + public boolean isCatched(L2PcInstance p)
- + {
- + HeroiDsLoad();
- +
- + if (HeroIds.contains(getId(p)) || HeroIds.contains(p.getName()))
- + return true;
- +
- + return false;
- + }
- +
- + public int getId(L2PcInstance p)
- + {
- + return p.getObjectId();
- + }
- +
- +
- + @Override
- + public int[] getItemIds()
- + {
- + return _itemIds;
- + }
- +}
- \ No newline at end of file
- #P L2JHellasC
- Index: java/com/l2jhellas/gameserver/model/entity/Hero.java
- ===================================================================
- --- java/com/l2jhellas/gameserver/model/entity/Hero.java (revision 500)
- +++ java/com/l2jhellas/gameserver/model/entity/Hero.java (working copy)
- @@ -989,6 +989,38 @@
- updateHeroes(false);
- }
- + public void activate24hHero(L2PcInstance player)
- + {
- + StatsSet hero = _heroes.get(player.getObjectId());
- + hero.set(ACTIVE, 1);
- +
- + _heroes.put(player.getObjectId(), hero);
- +
- + player.setHero(true);
- + player.sendSkillList();
- + player.broadcastPacket(new SocialAction(player.getObjectId(), 16));
- + player.broadcastUserInfo();
- +
- + _heroMessage.put(player.getObjectId(), "");
- +
- + updateHeroes(false);
- + }
- +
- + public void Deactivate24hHero(L2PcInstance player)
- + {
- + StatsSet hero = _heroes.get(player.getObjectId());
- + hero.set(ACTIVE, 0);
- +
- + _completeHeroes.remove(player.getObjectId(),hero);
- + _heroes.remove(player.getObjectId(),hero);
- + _heroMessage.remove(player.getObjectId(), "");
- + player.setHero(false);
- + player.sendSkillList();
- + player.broadcastUserInfo();
- +
- + updateHeroes(false);
- + }
- +
- private static class SingletonHolder
- {
- protected static final Hero _instance = new Hero();
Advertisement
Add Comment
Please, Sign In to add comment