Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### Eclipse Workspace Patch 1.0
- #P aCis_datapack
- Index: data/xml/BossEvent.xml
- ===================================================================
- --- data/xml/BossEvent.xml (revision 0)
- +++ data/xml/BossEvent.xml (revision 0)
- @@ -0,0 +1,15 @@
- +<?xml version="1.0" encoding="utf-8"?>
- +<list>
- + <Boss id="20445">
- + <announce onSpawn="Raidboss %s has been spawned on the world."/>
- + <spawnLoc x="-71624" y="258648" z="-3096" />
- + <despawn after="5"/> <!-- minutes -->
- + <scheduleSpawnTime val="15:50;15:51;15:52" />
- + </Boss>
- + <Boss id="20172">
- + <announce onSpawn="Raidboss %s has been spawned on the world."/>
- + <spawnLoc x="-71480" y="258504" z="-3104" />
- + <despawn after="5"/> <!-- minutes -->
- + <scheduleSpawnTime val="15:53;15:54;15:55" />
- + </Boss>
- +</list>
- \ No newline at end of file
- #P aCis_gameserver
- Index: java/net/sf/l2j/gameserver/data/xml/BossEventData.java
- ===================================================================
- --- java/net/sf/l2j/gameserver/data/xml/BossEventData.java (revision 0)
- +++ java/net/sf/l2j/gameserver/data/xml/BossEventData.java (revision 0)
- @@ -0,0 +1,65 @@
- +package net.sf.l2j.gameserver.data.xml;
- +
- +import java.nio.file.Path;
- +import java.util.ArrayList;
- +import java.util.List;
- +
- +import net.sf.l2j.commons.data.xml.IXmlReader;
- +
- +import net.sf.l2j.gameserver.model.event.BossEvent;
- +import net.sf.l2j.gameserver.templates.StatsSet;
- +
- +import org.w3c.dom.Document;
- +import org.w3c.dom.NamedNodeMap;
- +
- +/**
- + * @author StinkyMadness
- + */
- +public class BossEventData implements IXmlReader
- +{
- + private static final List<StatsSet> data = new ArrayList<>();
- +
- + protected BossEventData()
- + {
- + load();
- + }
- +
- + @Override
- + public void load()
- + {
- + parseFile("./data/xml/BossEvent.xml");
- + }
- +
- + @Override
- + public void parseDocument(Document doc, Path path)
- + {
- +
- + forEach(doc, "list", listNode -> forEach(listNode, "Boss", bossNode ->
- + {
- + final StatsSet set = parseAttributes(bossNode);
- + forEach(bossNode, "announce", messageNode -> set.set("announceOnSpawn", parseString(messageNode.getAttributes(), "onSpawn")));
- + forEach(bossNode, "spawnLoc", positionNode ->
- + {
- + final NamedNodeMap attrs = positionNode.getAttributes();
- + set.set("posX", parseInteger(attrs, "x"));
- + set.set("posY", parseInteger(attrs, "y"));
- + set.set("posZ", parseInteger(attrs, "z"));
- + });
- + forEach(bossNode, "despawn", messageNode -> set.set("despawnTime", parseInteger(messageNode.getAttributes(), "after")));
- + forEach(bossNode, "scheduleSpawnTime", spawnTimeNode -> set.set("spawnDateData", parseString(spawnTimeNode.getAttributes(), "val")));
- + data.add(set);
- + }));
- +
- + data.forEach(BossEvent::new);
- + }
- +
- + public static BossEventData getInstance()
- + {
- + return SingletonHolder.INSTANCE;
- + }
- +
- + private static class SingletonHolder
- + {
- + protected static final BossEventData INSTANCE = new BossEventData();
- + }
- +}
- \ No newline at end of file
- Index: java/net/sf/l2j/gameserver/model/event/BossEvent.java
- ===================================================================
- --- java/net/sf/l2j/gameserver/model/event/BossEvent.java (revision 0)
- +++ java/net/sf/l2j/gameserver/model/event/BossEvent.java (revision 0)
- @@ -0,0 +1,95 @@
- +package net.sf.l2j.gameserver.model.event;
- +
- +import java.util.ArrayList;
- +import java.util.Arrays;
- +import java.util.Calendar;
- +import java.util.List;
- +import java.util.concurrent.ScheduledFuture;
- +import java.util.concurrent.TimeUnit;
- +import java.util.logging.Level;
- +import java.util.logging.Logger;
- +
- +import net.sf.l2j.commons.concurrent.ThreadPool;
- +
- +import net.sf.l2j.gameserver.data.SpawnTable;
- +import net.sf.l2j.gameserver.data.xml.NpcData;
- +import net.sf.l2j.gameserver.model.L2Spawn;
- +import net.sf.l2j.gameserver.model.actor.Npc;
- +import net.sf.l2j.gameserver.model.actor.template.NpcTemplate;
- +import net.sf.l2j.gameserver.model.location.Location;
- +import net.sf.l2j.gameserver.templates.StatsSet;
- +import net.sf.l2j.gameserver.util.Broadcast;
- +
- +/**
- + * @author StinkyMadness
- + */
- +public class BossEvent implements Runnable
- +{
- + private final static Logger _log = Logger.getLogger(BossEvent.class.getName());
- + private final int _bossId;
- + private final String _onSpawnMessage;
- + private final Location _spawnLoc;
- + private final int _despawnTime;
- + private final List<ScheduledFuture<?>> _scheduler = new ArrayList<>();
- +
- + public BossEvent(StatsSet set)
- + {
- + _bossId = set.getInteger("id");
- + _onSpawnMessage = set.getString("announceOnSpawn", "");
- + _spawnLoc = new Location(set.getInteger("posX"), set.getInteger("posY"), set.getInteger("posZ"));
- + _despawnTime = set.getInteger("despawnTime", 0);
- + executeScheduler(set.getString("spawnDateData"));
- + }
- +
- + private void executeScheduler(String string)
- + {
- + Arrays.asList(string.split(";")).forEach(date ->
- + {
- + _scheduler.add(ThreadPool.scheduleAtFixedRate(this, parseDate(date), TimeUnit.DAYS.toMillis(1)));
- + });
- + }
- +
- + @Override
- + public void run()
- + {
- + spawnRaidBoss();
- + }
- +
- + private void spawnRaidBoss()
- + {
- + try
- + {
- + final NpcTemplate template = NpcData.getInstance().getTemplate(_bossId);
- + final L2Spawn spawn = new L2Spawn(template);
- + spawn.setLoc(_spawnLoc.getX(), _spawnLoc.getY(), _spawnLoc.getZ(), 0);
- + spawn.setRespawnState(false);
- + SpawnTable.getInstance().addNewSpawn(spawn, false);
- + final Npc _raidBoss = spawn.doSpawn(false);
- +
- + if (!_onSpawnMessage.isEmpty())
- + Broadcast.announceToOnlinePlayers(String.format(_onSpawnMessage, _raidBoss.getName()), true);
- + if (_despawnTime != 0)
- + _raidBoss.scheduleDespawn(TimeUnit.MINUTES.toMillis(_despawnTime));
- + }
- + catch (Exception e)
- + {
- + _log.log(Level.WARNING, "BossEvent: spawnRaidboss() exception: " + e.getMessage(), e);
- + return;
- + }
- + }
- +
- + private static long parseDate(String str)
- + {
- + final String[] split = str.split(":");
- + final Calendar calendar = Calendar.getInstance();
- + calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(split[0]));
- + calendar.set(Calendar.MINUTE, Integer.parseInt(split[1]));
- + calendar.set(Calendar.SECOND, 0);
- +
- + if (calendar.getTimeInMillis() <= System.currentTimeMillis())
- + calendar.add(Calendar.DATE, 1);
- +
- + return calendar.getTimeInMillis() - System.currentTimeMillis();
- + }
- +}
- \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement