Last active
August 24, 2019 19:01
-
-
Save riftrsps/7bed287d3ef48676e47c1404a9d09856 to your computer and use it in GitHub Desktop.
Main Package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main; | |
import api.YourAPI; | |
class Launcher extends JavaPlugin { | |
private YourAPI api; | |
@Override | |
public void onEnable() { | |
api = new YourAPIV1(this); | |
api.enable(); | |
startUpdater(); | |
} | |
private void startUpdater() { | |
int secondsPerDelay = 30; // 30 seconds for each delay | |
int updateDelay = 20 * secondsPerDelay; // server runs at 20 ticks per second | |
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(getPlugin(), api::updatePeriodically, 0, updateDelay); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main; | |
import api.YourAPI; | |
import api.buff.BuffModule; // https://gist.github.com/riftrsps/57634ff1f4c8ac58ff7db2d03d3ffcd5#file-buffmodule-java | |
import api.buff.CommandModule; | |
import api.quest.QuestModule; // https://gist.github.com/riftrsps/84e2151f0c366b3f9de058442af02aef#file-questmodule-java | |
public class YourAPIV1 implements YourAPI { | |
private final JavaPlugin plugin; | |
private BuffModule buffModule; | |
private CommandModule commandModule; | |
private QuestModule questModule; | |
public YourAPIV1(JavaPlugin plugin) { | |
this.plugin = plugin; | |
} | |
@Override | |
public void enable() { | |
buffModule = BuffModule.load(this); | |
commandModule = CommandModule.load(this); | |
questModule = QuestModule.load(this); | |
registerListener(buffModule); | |
registerListener(commandModule); | |
registerListener(questModule); | |
} | |
@Override | |
public void registerListener(Listener listener) { | |
plugin.getServer().getPluginManager().registerListener(listener, plugin); | |
} | |
@Override | |
public void deregisterListener(Listener listener) { | |
plugin.getServer().getPluginManager().deregisterListener(listener, plugin); | |
} | |
@Override | |
private void updatePeriodically() { | |
buffModule.updatePeriodically(); | |
} | |
@Override | |
public Set<Villager> findVillagersNearby(Entity entity, int radius) { | |
return entity.getWorld().getNearbyEntities(entity.getLocation(), radius, radius, radius) | |
.stream() | |
.filter(e -> e instanceof Villager) | |
.map(e -> (Villager) e) | |
.peek(v -> buffModule.activateBuffs(v, entity)) | |
.collect(Collectors.toSet()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment