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 Oraxen with generators (#1143)
* Added support for Oraxen custom blocks * Added Oraxen as a soft dependency
- Loading branch information
1 parent
2e354d3
commit b7e2f3d
Showing
8 changed files
with
95 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
group 'Hook_Oraxen' | ||
|
||
java { | ||
toolchain { | ||
languageVersion.set(JavaLanguageVersion.of(16)) | ||
} | ||
} | ||
|
||
dependencies { | ||
compileOnly 'io.th0rgal:Oraxen:1.133.0' | ||
compileOnly "org.spigotmc:v1_8_R3-Taco:latest" | ||
compileOnly project(":API") | ||
compileOnly parent | ||
} | ||
|
||
if (project.hasProperty('hook.compile_oraxen') && | ||
!Boolean.valueOf(project.findProperty("hook.compile_oraxen").toString())) { | ||
project.tasks.all { task -> task.enabled = false } | ||
} |
69 changes: 69 additions & 0 deletions
69
Hook_Oraxen/src/main/java/com/bgsoftware/superiorskyblock/hooks/support/OraxenHook.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,69 @@ | ||
package com.bgsoftware.superiorskyblock.hooks.support; | ||
|
||
import com.bgsoftware.superiorskyblock.SuperiorSkyblockPlugin; | ||
import com.bgsoftware.superiorskyblock.api.events.IslandGenerateBlockEvent; | ||
import com.bgsoftware.superiorskyblock.api.objects.Pair; | ||
import com.google.common.collect.ImmutableList; | ||
import io.th0rgal.oraxen.items.OraxenItems; | ||
import io.th0rgal.oraxen.mechanics.MechanicFactory; | ||
import io.th0rgal.oraxen.mechanics.MechanicsManager; | ||
import io.th0rgal.oraxen.mechanics.provided.gameplay.block.BlockMechanicFactory; | ||
import io.th0rgal.oraxen.mechanics.provided.gameplay.noteblock.NoteBlockMechanicFactory; | ||
import io.th0rgal.oraxen.mechanics.provided.gameplay.stringblock.StringBlockMechanicFactory; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.Listener; | ||
|
||
import java.util.List; | ||
import java.util.Locale; | ||
|
||
public final class OraxenHook { | ||
|
||
private static final List<Pair<MechanicFactory, SetBlockModelFunction>> AVAILABLE_MECHANICS = ImmutableList.of( | ||
new Pair<>(MechanicsManager.getMechanicFactory("block"), BlockMechanicFactory::setBlockModel), | ||
new Pair<>(MechanicsManager.getMechanicFactory("noteblock"), NoteBlockMechanicFactory::setBlockModel), | ||
new Pair<>(MechanicsManager.getMechanicFactory("stringblock"), StringBlockMechanicFactory::setBlockModel) | ||
); | ||
|
||
public static void register(SuperiorSkyblockPlugin plugin) { | ||
Bukkit.getPluginManager().registerEvents(new GeneratorListener(), plugin); | ||
} | ||
|
||
private static final class GeneratorListener implements Listener { | ||
|
||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) | ||
public void onIslandGenerateBlock(IslandGenerateBlockEvent event) { | ||
if (!event.getBlock().getGlobalKey().equals("ORAXEN")) | ||
return; | ||
|
||
String itemId = event.getBlock().getSubKey().toLowerCase(Locale.ENGLISH); | ||
|
||
if (!OraxenItems.exists(itemId)) { | ||
event.setCancelled(true); | ||
return; | ||
} | ||
|
||
Pair<MechanicFactory, SetBlockModelFunction> mechanic = AVAILABLE_MECHANICS.stream() | ||
.filter(pair -> pair.getKey() != null && !pair.getKey().isNotImplementedIn(itemId)) | ||
.findFirst().orElse(null); | ||
|
||
if (mechanic == null) { | ||
event.setCancelled(true); | ||
return; | ||
} | ||
|
||
event.setPlaceBlock(false); | ||
mechanic.getValue().setBlockModel(event.getLocation().getBlock(), itemId); | ||
} | ||
|
||
} | ||
|
||
private interface SetBlockModelFunction { | ||
|
||
void setBlockModel(Block block, String itemId); | ||
|
||
} | ||
|
||
} |
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
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