-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for EpicSpawners 7 (#32)
- Loading branch information
1 parent
927a017
commit 699d5eb
Showing
7 changed files
with
91 additions
and
10 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
group 'Hook_EpicSpawners6' | ||
|
||
dependencies { | ||
compileOnly "com.songoda:EpicSpawners-7:latest" | ||
compileOnly "org.spigotmc:v1_8_R3-Taco:latest" | ||
compileOnly project(":API") | ||
compileOnly parent | ||
} | ||
|
||
if (project.hasProperty('hook.compile_epicspawners7') && | ||
!Boolean.valueOf(project.findProperty("hook.compile_epicspawners7").toString())) { | ||
project.tasks.all { task -> task.enabled = false } | ||
} |
59 changes: 59 additions & 0 deletions
59
...wners7/src/main/java/com/bgsoftware/wildloaders/hooks/TickableProvider_EpicSpawners7.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.bgsoftware.wildloaders.hooks; | ||
|
||
import com.bgsoftware.wildloaders.api.hooks.TickableProvider; | ||
import com.songoda.epicspawners.EpicSpawners; | ||
import org.bukkit.Chunk; | ||
import org.bukkit.Location; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
public final class TickableProvider_EpicSpawners7 implements TickableProvider { | ||
|
||
private final Map<Location, TickDelay> spawnerDelays = new HashMap<>(); | ||
|
||
@Override | ||
public void tick(Chunk[] chunks) { | ||
if (EpicSpawners.getInstance().getSpawnerManager() == null) | ||
return; | ||
|
||
List<Long> chunkList = Stream.of(chunks).map(chunk -> pair(chunk.getX(), chunk.getZ())).collect(Collectors.toList()); | ||
|
||
EpicSpawners.getInstance().getSpawnerManager().getSpawners().stream() | ||
.filter(spawner -> chunkList.contains(pair(spawner.getX() >> 4, spawner.getZ() >> 4))) | ||
.forEach(spawner -> { | ||
Location location = spawner.getLocation(); | ||
TickDelay tickDelay = spawnerDelays.get(location); | ||
|
||
if (tickDelay == null) { | ||
spawnerDelays.put(location, new TickDelay(spawner.updateDelay())); | ||
return; | ||
} | ||
|
||
tickDelay.delay -= 1; | ||
|
||
if (tickDelay.delay <= 0) { | ||
spawner.spawn(); | ||
spawnerDelays.remove(location); | ||
} | ||
}); | ||
} | ||
|
||
private long pair(int x, int z) { | ||
return (x & 0xFFFFFFFFL) | (z & 0xFFFFFFFFL) << 32; | ||
} | ||
|
||
private static final class TickDelay { | ||
|
||
private int delay; | ||
|
||
TickDelay(int delay) { | ||
this.delay = delay; | ||
} | ||
|
||
} | ||
|
||
} |
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
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
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