generated from Slimefun/Addon-Template
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat(Tesseract Binder): Added a binding tool for Tesseracts instead…
… of binding directly
- Loading branch information
1 parent
fdfec4d
commit 2d2d05b
Showing
5 changed files
with
86 additions
and
56 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
59 changes: 59 additions & 0 deletions
59
src/main/java/me/profelements/dynatech/items/tools/TesseractBinder.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 me.profelements.dynatech.items.tools; | ||
|
||
import java.util.Optional; | ||
|
||
import org.bukkit.Location; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.inventory.meta.ItemMeta; | ||
|
||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; | ||
import me.mrCookieSlime.Slimefun.Lists.RecipeType; | ||
import me.mrCookieSlime.Slimefun.Objects.Category; | ||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; | ||
import me.mrCookieSlime.Slimefun.api.BlockStorage; | ||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; | ||
import me.mrCookieSlime.Slimefun.cscorelib2.data.PersistentDataAPI; | ||
import me.profelements.dynatech.DynaTechItems; | ||
import me.profelements.dynatech.items.electric.transfer.Tesseract; | ||
import net.md_5.bungee.api.ChatColor; | ||
import net.md_5.bungee.api.ChatMessageType; | ||
import net.md_5.bungee.api.chat.TextComponent; | ||
|
||
public class TesseractBinder extends SlimefunItem { | ||
public TesseractBinder(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { | ||
super(category, item, recipeType, recipe); | ||
|
||
addItemHandler(bindTesseract()); | ||
} | ||
|
||
private ItemUseHandler bindTesseract() { | ||
return e -> { | ||
e.cancel(); | ||
|
||
Optional<Block> block = e.getClickedBlock(); | ||
Optional<SlimefunItem> sfBlock = e.getSlimefunBlock(); | ||
if (block.isPresent() && sfBlock.isPresent()) { | ||
Location blockLocation = block.get().getLocation(); | ||
SlimefunItem sfItem = sfBlock.get(); | ||
ItemStack item = e.getItem(); | ||
|
||
if (e.getPlayer().isSneaking()) { | ||
String locString = PersistentDataAPI.getString(item.getItemMeta(), Tesseract.WIRELESS_LOCATION_KEY); | ||
if (item != null && BlockStorage.checkID(blockLocation).equals(DynaTechItems.TESSERACT.getItemId()) && item.hasItemMeta() && locString != null) { | ||
BlockStorage.addBlockInfo(blockLocation, "tesseract-pair-location", locString); | ||
e.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(ChatColor.WHITE + "Tesseract Connected!")); | ||
} | ||
} else if (sfBlock != null && sfItem.getId().equals(DynaTechItems.TESSERACT.getItemId()) && blockLocation != null) { | ||
ItemMeta im = item.getItemMeta(); | ||
String locString = Tesseract.LocationToString(blockLocation); | ||
|
||
PersistentDataAPI.setString(im, Tesseract.WIRELESS_LOCATION_KEY, locString); | ||
item.setItemMeta(im); | ||
Tesseract.setItemLore(item, blockLocation); | ||
} | ||
|
||
} | ||
}; | ||
} | ||
} |
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