This repository was archived by the owner on Feb 18, 2024. It is now read-only.
forked from CivClassic/JukeAlert
-
Notifications
You must be signed in to change notification settings - Fork 5
Added possibility to set lore or name for snitch items #14
Open
Aleksey-Terzi
wants to merge
1
commit into
CivMC:master
Choose a base branch
from
Aleksey-Terzi:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,29 +1,47 @@ | ||
| package com.untamedears.jukealert.model; | ||
|
|
||
| import com.untamedears.jukealert.JukeAlert; | ||
| import com.untamedears.jukealert.model.appender.AbstractSnitchAppender; | ||
| import com.untamedears.jukealert.model.field.FieldManager; | ||
| import com.untamedears.jukealert.model.field.SingleCuboidRangeManager; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.function.Function; | ||
|
|
||
| import net.kyori.adventure.text.Component; | ||
| import org.bukkit.Location; | ||
| import org.bukkit.Material; | ||
| import org.bukkit.inventory.ItemStack; | ||
| import org.bukkit.inventory.meta.ItemMeta; | ||
|
|
||
| public class SnitchFactoryType { | ||
| public static class ItemInfo { | ||
| public Material material; | ||
| public String name; | ||
| public List<String> lore; | ||
| } | ||
|
|
||
| private final int id; | ||
| private final ItemStack item; | ||
| private final ItemInfo item; | ||
| private final String name; | ||
| private final Function<Snitch, FieldManager> fieldGenerator; | ||
|
|
||
| private final List<Function<Snitch, AbstractSnitchAppender>> appenders; | ||
|
|
||
| public SnitchFactoryType(ItemStack item, Function<Snitch, FieldManager> fieldGenerator, String name, int id, | ||
| public SnitchFactoryType(ItemInfo item, Function<Snitch, FieldManager> fieldGenerator, String name, int id, | ||
| List<Function<Snitch, AbstractSnitchAppender>> appenders) { | ||
| this.item = item; | ||
| this.name = name; | ||
| this.id = id; | ||
| this.fieldGenerator = fieldGenerator; | ||
| this.appenders = appenders; | ||
|
|
||
| if (this.item.name != null && this.item.name.length() == 0) | ||
| this.item.name = null; | ||
|
|
||
| if (this.item.lore != null && this.item.lore.isEmpty()) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| this.item.lore = null; | ||
| } | ||
|
|
||
| public Snitch create(int snitchID, Location location, String name, int groupID, boolean isNew) { | ||
|
|
@@ -53,10 +71,59 @@ public String getName() { | |
| return name; | ||
| } | ||
|
|
||
| /** | ||
| * @return Material of item used to create instances of this snitch | ||
| */ | ||
| public Material getItemMaterial() { | ||
| return this.item.material; | ||
| } | ||
|
|
||
| /** | ||
| * @return Item used to create instances of this snitch | ||
| */ | ||
| public ItemStack getItem() { | ||
| return item.clone(); | ||
| public ItemStack getItemRepresentation() { | ||
| ItemStack item = new ItemStack(this.item.material); | ||
|
|
||
| if (this.item.name != null && this.item.name.length() > 0 || this.item.lore != null && this.item.lore.size() > 0) { | ||
| ItemMeta meta = item.getItemMeta(); | ||
|
|
||
| if (this.item.name != null && this.item.name.length() > 0) | ||
| meta.displayName(Component.text(this.item.name)); | ||
|
|
||
| if (this.item.lore != null && this.item.lore.size() > 0) { | ||
| List<Component> loreList = new ArrayList<>(); | ||
| for (String loreLine : this.item.lore) | ||
| loreList.add(Component.text(loreLine)); | ||
|
|
||
| meta.lore(loreList); | ||
| } | ||
|
|
||
| item.setItemMeta(meta); | ||
| } | ||
|
|
||
| return item; | ||
| } | ||
|
|
||
| public boolean isSame(ItemStack itemStack) { | ||
| if (itemStack == null || this.item.material != itemStack.getType()) | ||
| return false; | ||
|
|
||
| ItemMeta meta = itemStack.getItemMeta(); | ||
|
|
||
| String name = meta.getDisplayName(); | ||
| if (name != null && name.length() == 0) | ||
| name = null; | ||
|
|
||
| List<String> lore; | ||
| if (meta.hasLore()) { | ||
| lore = meta.getLore(); | ||
| if (lore != null && lore.isEmpty()) | ||
| lore = null; | ||
| } else { | ||
| lore = null; | ||
| } | ||
|
|
||
| return (this.item.name == null && name == null || this.item.name != null && this.item.name.equals(name)) | ||
| && (this.item.lore == null && lore == null || this.item.lore != null && this.item.lore.equals(lore)); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
StringUtils.isEmpty(this.item.name)