mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
Fixed a small issue with backpacks
This commit is contained in:
parent
9c3c6d7245
commit
7eff4d381e
@ -42,6 +42,7 @@
|
|||||||
* Fixed #2721
|
* Fixed #2721
|
||||||
* Fixed #2662
|
* Fixed #2662
|
||||||
* Fixed #2728
|
* Fixed #2728
|
||||||
|
* Fixed some backpack opening issues
|
||||||
* Fixed Infused Hopper picking up items with a max pickup delay
|
* Fixed Infused Hopper picking up items with a max pickup delay
|
||||||
* Fixed duplication issues related to holograms/armorstands
|
* Fixed duplication issues related to holograms/armorstands
|
||||||
|
|
||||||
|
@ -46,6 +46,7 @@ public enum SlimefunBranch {
|
|||||||
|
|
||||||
SlimefunBranch(@Nonnull String name, boolean official) {
|
SlimefunBranch(@Nonnull String name, boolean official) {
|
||||||
Validate.notNull(name, "The branch name cannot be null");
|
Validate.notNull(name, "The branch name cannot be null");
|
||||||
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.official = official;
|
this.official = official;
|
||||||
|
|
||||||
|
@ -456,9 +456,9 @@ public final class PlayerProfile {
|
|||||||
|
|
||||||
if (id.isPresent()) {
|
if (id.isPresent()) {
|
||||||
int number = id.getAsInt();
|
int number = id.getAsInt();
|
||||||
|
|
||||||
fromUUID(UUID.fromString(uuid), profile -> {
|
fromUUID(UUID.fromString(uuid), profile -> {
|
||||||
Optional<PlayerBackpack> backpack = profile.getBackpack(number);
|
Optional<PlayerBackpack> backpack = profile.getBackpack(number);
|
||||||
|
|
||||||
backpack.ifPresent(callback);
|
backpack.ifPresent(callback);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ import io.github.thebusybiscuit.cscorelib2.collections.KeyMap;
|
|||||||
import io.github.thebusybiscuit.cscorelib2.config.Config;
|
import io.github.thebusybiscuit.cscorelib2.config.Config;
|
||||||
import io.github.thebusybiscuit.slimefun4.api.geo.GEOResource;
|
import io.github.thebusybiscuit.slimefun4.api.geo.GEOResource;
|
||||||
import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
|
import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
|
||||||
|
import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuide;
|
||||||
import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideImplementation;
|
import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideImplementation;
|
||||||
import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideMode;
|
import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideMode;
|
||||||
import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlock;
|
import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlock;
|
||||||
@ -132,14 +133,36 @@ public final class SlimefunRegistry {
|
|||||||
return backwardsCompatibility;
|
return backwardsCompatibility;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method sets the status of backwards compatibility.
|
||||||
|
* Backwards compatibility allows Slimefun to recognize items from older versions but comes
|
||||||
|
* at a huge performance cost.
|
||||||
|
*
|
||||||
|
* @param compatible
|
||||||
|
* Whether backwards compatibility should be enabled
|
||||||
|
*/
|
||||||
public void setBackwardsCompatible(boolean compatible) {
|
public void setBackwardsCompatible(boolean compatible) {
|
||||||
backwardsCompatibility = compatible;
|
backwardsCompatibility = compatible;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method will make any {@link SlimefunItem} which is registered automatically
|
||||||
|
* call {@link SlimefunItem#load()}.
|
||||||
|
* Normally this method call is delayed but when the {@link Server} is already running,
|
||||||
|
* the method can be called instantaneously.
|
||||||
|
*
|
||||||
|
* @param mode
|
||||||
|
* Whether auto-loading should be enabled
|
||||||
|
*/
|
||||||
public void setAutoLoadingMode(boolean mode) {
|
public void setAutoLoadingMode(boolean mode) {
|
||||||
automaticallyLoadItems = mode;
|
automaticallyLoadItems = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This returns a {@link List} containing every enabled {@link Category}.
|
||||||
|
*
|
||||||
|
* @return {@link List} containing every enabled {@link Category}
|
||||||
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public List<Category> getCategories() {
|
public List<Category> getCategories() {
|
||||||
return categories;
|
return categories;
|
||||||
@ -165,11 +188,23 @@ public final class SlimefunRegistry {
|
|||||||
return enabledItems;
|
return enabledItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This returns a {@link List} containing every enabled {@link Research}.
|
||||||
|
*
|
||||||
|
* @return A {@link List} containing every enabled {@link Research}
|
||||||
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public List<Research> getResearches() {
|
public List<Research> getResearches() {
|
||||||
return researches;
|
return researches;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method returns a {@link Set} containing the {@link UUID} of every
|
||||||
|
* {@link Player} who is currently unlocking a {@link Research}.
|
||||||
|
*
|
||||||
|
* @return A {@link Set} holding the {@link UUID} from every {@link Player}
|
||||||
|
* who is currently unlocking a {@link Research}
|
||||||
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public Set<UUID> getCurrentlyResearchingPlayers() {
|
public Set<UUID> getCurrentlyResearchingPlayers() {
|
||||||
return researchingPlayers;
|
return researchingPlayers;
|
||||||
@ -200,6 +235,11 @@ public final class SlimefunRegistry {
|
|||||||
return researchFireworks;
|
return researchFireworks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method returns a {@link List} of every enabled {@link MultiBlock}.
|
||||||
|
*
|
||||||
|
* @return A {@link List} containing every enabled {@link MultiBlock}
|
||||||
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public List<MultiBlock> getMultiBlocks() {
|
public List<MultiBlock> getMultiBlocks() {
|
||||||
return multiblocks;
|
return multiblocks;
|
||||||
@ -208,6 +248,10 @@ public final class SlimefunRegistry {
|
|||||||
/**
|
/**
|
||||||
* This returns the corresponding {@link SlimefunGuideImplementation} for a certain
|
* This returns the corresponding {@link SlimefunGuideImplementation} for a certain
|
||||||
* {@link SlimefunGuideMode}.
|
* {@link SlimefunGuideMode}.
|
||||||
|
* <p>
|
||||||
|
* This mainly only exists for internal purposes, if you want to open a certain section
|
||||||
|
* using the {@link SlimefunGuide}, then please use the static methods provided in the
|
||||||
|
* {@link SlimefunGuide} class.
|
||||||
*
|
*
|
||||||
* @param mode
|
* @param mode
|
||||||
* The {@link SlimefunGuideMode}
|
* The {@link SlimefunGuideMode}
|
||||||
|
@ -7,6 +7,7 @@ import java.util.UUID;
|
|||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import javax.annotation.ParametersAreNonnullByDefault;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@ -57,12 +58,21 @@ public class BackpackListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onClose(InventoryCloseEvent e) {
|
public void onClose(InventoryCloseEvent e) {
|
||||||
Player p = ((Player) e.getPlayer());
|
Player p = (Player) e.getPlayer();
|
||||||
|
|
||||||
|
if (markBackpackDirty(p)) {
|
||||||
|
p.playSound(p.getLocation(), Sound.ENTITY_HORSE_ARMOR, 1F, 1F);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean markBackpackDirty(@Nonnull Player p) {
|
||||||
ItemStack backpack = backpacks.remove(p.getUniqueId());
|
ItemStack backpack = backpacks.remove(p.getUniqueId());
|
||||||
|
|
||||||
if (backpack != null) {
|
if (backpack != null) {
|
||||||
p.playSound(p.getLocation(), Sound.ENTITY_HORSE_ARMOR, 1F, 1F);
|
|
||||||
PlayerProfile.getBackpack(backpack, PlayerBackpack::markDirty);
|
PlayerProfile.getBackpack(backpack, PlayerBackpack::markDirty);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,6 +119,7 @@ public class BackpackListener implements Listener {
|
|||||||
return backpack.isItemAllowed(item, SlimefunItem.getByItem(item));
|
return backpack.isItemAllowed(item, SlimefunItem.getByItem(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ParametersAreNonnullByDefault
|
||||||
public void openBackpack(Player p, ItemStack item, SlimefunBackpack backpack) {
|
public void openBackpack(Player p, ItemStack item, SlimefunBackpack backpack) {
|
||||||
if (item.getAmount() == 1) {
|
if (item.getAmount() == 1) {
|
||||||
if (Slimefun.hasUnlocked(p, backpack, true) && !PlayerProfile.get(p, profile -> openBackpack(p, item, profile, backpack.getSize()))) {
|
if (Slimefun.hasUnlocked(p, backpack, true) && !PlayerProfile.get(p, profile -> openBackpack(p, item, profile, backpack.getSize()))) {
|
||||||
@ -119,8 +130,10 @@ public class BackpackListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ParametersAreNonnullByDefault
|
||||||
private void openBackpack(Player p, ItemStack item, PlayerProfile profile, int size) {
|
private void openBackpack(Player p, ItemStack item, PlayerProfile profile, int size) {
|
||||||
List<String> lore = item.getItemMeta().getLore();
|
List<String> lore = item.getItemMeta().getLore();
|
||||||
|
|
||||||
for (int line = 0; line < lore.size(); line++) {
|
for (int line = 0; line < lore.size(); line++) {
|
||||||
if (lore.get(line).equals(ChatColor.GRAY + "ID: <ID>")) {
|
if (lore.get(line).equals(ChatColor.GRAY + "ID: <ID>")) {
|
||||||
setBackpackId(p, item, line, profile.createBackpack(size).getId());
|
setBackpackId(p, item, line, profile.createBackpack(size).getId());
|
||||||
@ -128,6 +141,15 @@ public class BackpackListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If the current Player is already viewing a backpack (for whatever reason),
|
||||||
|
* terminate that view.
|
||||||
|
*/
|
||||||
|
if (markBackpackDirty(p)) {
|
||||||
|
p.closeInventory();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if someone else is currently viewing this backpack
|
||||||
if (!backpacks.containsValue(item)) {
|
if (!backpacks.containsValue(item)) {
|
||||||
p.playSound(p.getLocation(), Sound.ENTITY_HORSE_ARMOR, 1F, 1F);
|
p.playSound(p.getLocation(), Sound.ENTITY_HORSE_ARMOR, 1F, 1F);
|
||||||
backpacks.put(p.getUniqueId(), item);
|
backpacks.put(p.getUniqueId(), item);
|
||||||
|
Loading…
Reference in New Issue
Block a user