Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
570ccf2
commit 2db2415
Showing
10 changed files
with
204 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
group 'Hooks:ItemsAdder' | ||
|
||
dependencies { | ||
compileOnly 'dev.lone:ItemsAdder:3.5.0' | ||
compileOnly "org.spigotmc:v1_8_R3-Taco:latest" | ||
compileOnly project(":API") | ||
compileOnly rootProject | ||
} | ||
|
||
if (project.hasProperty('hook.compile_itemsadder') && | ||
!Boolean.valueOf(project.findProperty("hook.compile_itemsadder").toString())) { | ||
project.tasks.all { task -> task.enabled = false } | ||
} |
113 changes: 113 additions & 0 deletions
113
Hooks/ItemsAdder/src/main/java/com/bgsoftware/superiorskyblock/external/ItemsAdderHook.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,113 @@ | ||
package com.bgsoftware.superiorskyblock.external; | ||
|
||
import com.bgsoftware.common.annotations.Nullable; | ||
import com.bgsoftware.superiorskyblock.SuperiorSkyblockPlugin; | ||
import com.bgsoftware.superiorskyblock.api.events.IslandGenerateBlockEvent; | ||
import com.bgsoftware.superiorskyblock.api.key.CustomKeyParser; | ||
import com.bgsoftware.superiorskyblock.api.key.Key; | ||
import com.bgsoftware.superiorskyblock.core.Singleton; | ||
import com.bgsoftware.superiorskyblock.core.key.KeyIndicator; | ||
import com.bgsoftware.superiorskyblock.core.key.Keys; | ||
import com.bgsoftware.superiorskyblock.core.threads.BukkitExecutor; | ||
import com.bgsoftware.superiorskyblock.listener.BlockChangesListener; | ||
import dev.lone.itemsadder.api.CustomBlock; | ||
import dev.lone.itemsadder.api.CustomStack; | ||
import org.bukkit.Location; | ||
import org.bukkit.Material; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.block.BlockState; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.block.BlockPlaceEvent; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
import java.util.Locale; | ||
|
||
public class ItemsAdderHook { | ||
|
||
private static final String ITEMS_ADDER_PREFIX = "ITEMS_ADDER"; | ||
private static final Key BLOCK_ITEM_KEY = Keys.of(Material.PAPER); | ||
private static final Key BLOCK_KEY = Keys.of(Material.NOTE_BLOCK); | ||
|
||
private static Singleton<BlockChangesListener> blockChangesListener; | ||
|
||
public static void register(SuperiorSkyblockPlugin plugin) { | ||
blockChangesListener = plugin.getListener(BlockChangesListener.class); | ||
plugin.getBlockValues().registerKeyParser(new ItemsAdderKeyParser(), BLOCK_ITEM_KEY, BLOCK_KEY); | ||
plugin.getServer().getPluginManager().registerEvents(new ListenerImpl(), plugin); | ||
} | ||
|
||
private static class ListenerImpl implements Listener { | ||
|
||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) | ||
public void onBlockPlace(BlockPlaceEvent e) { | ||
// ItemsAdder calls BlockPlaceEvent when the block is AIR. | ||
if (e.getBlock().getType() != Material.AIR) | ||
return; | ||
|
||
BlockState oldState = e.getBlockReplacedState(); | ||
|
||
BukkitExecutor.sync(() -> { | ||
blockChangesListener.get().onBlockPlace(Keys.of(e.getBlock()), e.getBlock().getLocation(), 1, | ||
oldState, BlockChangesListener.BlockTrackFlags.DIRTY_CHUNKS | BlockChangesListener.BlockTrackFlags.SAVE_BLOCK_COUNT); | ||
}, 1L); | ||
|
||
} | ||
|
||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) | ||
public void onIslandGenerateBlock(IslandGenerateBlockEvent event) { | ||
if (!event.getBlock().getGlobalKey().equals(ITEMS_ADDER_PREFIX)) | ||
return; | ||
|
||
String itemId = event.getBlock().getSubKey().toLowerCase(Locale.ENGLISH); | ||
|
||
CustomBlock customBlock = CustomBlock.getInstance(itemId); | ||
|
||
if (customBlock == null) { | ||
event.setCancelled(true); | ||
return; | ||
} | ||
|
||
event.setPlaceBlock(false); | ||
customBlock.place(event.getLocation()); | ||
} | ||
|
||
} | ||
|
||
private static class ItemsAdderKeyParser implements CustomKeyParser { | ||
|
||
@Override | ||
public Key getCustomKey(Location location) { | ||
Block block = location.getBlock(); | ||
CustomBlock customBlock = CustomBlock.byAlreadyPlaced(block); | ||
if (customBlock == null) | ||
return BLOCK_KEY; | ||
return Keys.of(ITEMS_ADDER_PREFIX, customBlock.getId().toUpperCase(Locale.ENGLISH), KeyIndicator.CUSTOM); | ||
} | ||
|
||
@Override | ||
public Key getCustomKey(ItemStack itemStack, Key def) { | ||
CustomStack customStack = CustomStack.byItemStack(itemStack); | ||
if (customStack == null) | ||
return def; | ||
return Keys.of(ITEMS_ADDER_PREFIX, customStack.getId().toUpperCase(Locale.ENGLISH), KeyIndicator.CUSTOM); | ||
} | ||
|
||
@Override | ||
public boolean isCustomKey(Key key) { | ||
return key.getGlobalKey().equals(ITEMS_ADDER_PREFIX); | ||
} | ||
|
||
@Override | ||
@Nullable | ||
public ItemStack getCustomKeyItem(Key key) { | ||
CustomStack customStack = CustomStack.getInstance(key.getSubKey().toLowerCase(Locale.ENGLISH)); | ||
if (customStack == null) | ||
return null; | ||
return customStack.getItemStack(); | ||
} | ||
|
||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -52,4 +52,4 @@ include 'NMS:v1_17' | |
include 'NMS:v1_18' | ||
include 'NMS:v1_19' | ||
include 'NMS:v1_20_1' | ||
|
||
include 'Hooks:ItemsAdder' |
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