Skip to content

Commit

Permalink
2.1.6
Browse files Browse the repository at this point in the history
### Improved:
* Removed command `/rpginv list [type]`. Now you can just skip `list` and write `/rpginv items` instead of `/rpginv list items`.
* Improved tips on wrong usage of command
* Added support of short form of command. You can now use just first letter of command. For example, instead of `/rpginv reload` you can write `/rpginv r`. Instead of `pets` - `p` and so on.
* Added notifications about items giving (#8) 
* Improved resource packs warnings

### Fixed:
* Inventory glitch (#142)
* Giving of backpacks (#143)
* Exception on player death (#144)
  • Loading branch information
osipxd authored May 10, 2018
2 parents fc11a60 + 5fd954a commit 6bff7da
Show file tree
Hide file tree
Showing 13 changed files with 400 additions and 337 deletions.
11 changes: 9 additions & 2 deletions ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@

# WARNING!
DON'T JUST DELETE THIS TEMPLATE \
WITHOUT IT I'LL JUST MARK YOUR ISSUE AS `INVALID`\
(you can skip only `Steps to Reproduce` and `Environment` if it is feature request)


### Prerequisites

* [ ] Are you running the latest version?
* [ ] Did you check the FAQs on [plugin's page](https://www.spigotmc.org/resources/12498/)?
* [ ] Did you check the [Wiki](http://rpginventory.endlesscode.ru/)?
* [ ] Did you configure [config.yml](https://github.com/EndlessCodeGroup/RPGInventory/blob/master/src/main/resources/config.yml)?
* [ ] Did you perform a cursory search?
* [ ] Can you reproduce the problem in clean server (with installed only the plugin and dependencies)?
* [ ] Can you reproduce the problem on clean server (with installed only the plugin and dependencies)?

### Description

Expand All @@ -25,7 +32,7 @@

**Server Core:** [Spigot/Paper/etc.]\
**Server Version:** [e.g. 1.12.2]\
**Plugin Version:** [e.g. 2.1.4-PRE]
**Plugin Version:** [e.g. 2.1.4-PRE] ***(YOU SHOULD WRITE VERSION NUMBER, NOT JUST "LATEST")***


***HIGHLY RECOMMENDED TO ATTACH SERVER LOGS TO THE ISSUE!***
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pluginVersion=2.1.6-PRE
pluginVersion=2.1.6
pluginDesc=Change inventory how you need
url=https://github.com/EndlessCodeGroup/RPGInventory

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,14 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.event.player.PlayerItemBreakEvent;
import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.inventory.*;
import org.bukkit.event.player.*;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.scheduler.BukkitRunnable;

import org.jetbrains.annotations.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import ru.endlesscode.rpginventory.RPGInventory;
import ru.endlesscode.rpginventory.api.InventoryAPI;
import ru.endlesscode.rpginventory.event.PlayerInventoryLoadEvent;
Expand Down Expand Up @@ -270,7 +256,15 @@ public void onInventoryClick(@NotNull final InventoryClickEvent event) {

switch (event.getSlotType()) {
case CRAFTING:
playerWrapper.openInventory(true);
//Without this stupid shit we already get click in the our inventory on bukkit 1.9.4
//Ofc, player picking up item in the clicked slot (1, 2, 3, 4, depends on clicked slot in the small crafting grid)
//Fixes #142.
new BukkitRunnable() {
@Override
public void run() {
playerWrapper.openInventory(true);
}
}.runTaskLater(RPGInventory.getInstance(), 0);
case QUICKBAR:
// Shield slot is QUICKBAR and has rawId - 45 o.O
if (rawSlot != 45) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ public static boolean open(@NotNull Player player, @Nullable ItemStack bpItem) {

BackpackType type;
String bpId = ItemUtils.getTag(bpItem, ItemUtils.BACKPACK_TAG);
if (bpId == null || (type = BackpackManager.getBackpackType(bpId)) == null) {
if (bpId.isEmpty() || (type = BackpackManager.getBackpackType(bpId)) == null) {
return false;
}

Backpack backpack;
String bpUid = ItemUtils.getTag(bpItem, ItemUtils.BACKPACK_UID_TAG);
UUID uuid = bpUid == null ? null : UUID.fromString(bpUid);
UUID uuid = bpUid.isEmpty() ? null : UUID.fromString(bpUid);
if (!BACKPACKS.containsKey(uuid)) {
if (uuid == null) {
backpack = type.createBackpack();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public class CustomItem extends ClassedItem {
}

@Contract("null -> false")
public static boolean isCustomItem(ItemStack itemStack) {
public static boolean isCustomItem(@Nullable ItemStack itemStack) {
return !ItemUtils.isEmpty(itemStack) && ItemUtils.hasTag(itemStack, ItemUtils.ITEM_TAG);
}

Expand Down
10 changes: 7 additions & 3 deletions src/main/java/ru/endlesscode/rpginventory/item/ItemManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,13 @@ public static ItemStack getItem(String itemId) {
}

@Nullable
public static CustomItem getCustomItem(ItemStack item) {
public static CustomItem getCustomItem(@Nullable ItemStack item) {
if (ItemUtils.isEmpty(item)) {
return null;
}

String tag = ItemUtils.getTag(item, ItemUtils.ITEM_TAG);
if (tag == null) {
if (tag.isEmpty()) {
return null;
}

Expand All @@ -160,7 +164,7 @@ public static boolean allowedForPlayer(Player player, ItemStack item, boolean no
}

if (classedItem == null) {
return true; //Or false?
return true;
}

if (!PlayerUtils.checkLevel(player, classedItem.getLevel())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ public void run() {
}

Inventory inventory = InventoryManager.get(this.player).getInventory();
if (!this.player.isOnline() || this.player.isDead() || !PetManager.isEnabled() || inventory == null || inventory.getItem(PetManager.getPetSlotId()) == null) {
final boolean playerIsAlive = !this.player.isOnline() || this.player.isDead();
final boolean playerHasPetItem = inventory == null || inventory.getItem(PetManager.getPetSlotId()) == null;
if (playerIsAlive || !PetManager.isEnabled() || playerHasPetItem) {
this.cancel();
return;
}
Expand All @@ -74,7 +76,7 @@ public void run() {
PetManager.addGlow(item);
String itemTag = ItemUtils.getTag(this.petItem, ItemUtils.PET_TAG);

if (itemTag == null) {
if (itemTag.isEmpty()) {
Slot petSlot = Objects.requireNonNull(SlotManager.instance().getPetSlot(), "Pet slot can't be null!");
inventory.setItem(PetManager.getPetSlotId(), petSlot.getCup());
this.cancel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void run() {
}

final Player player = this.plugin.getServer().getPlayer(next.getKey());
if (player == null || !InventoryManager.playerIsLoaded(player)) {
if (!InventoryManager.playerIsLoaded(player)) {
iterator.remove();
continue;
}
Expand Down Expand Up @@ -102,7 +102,7 @@ public void run() {
PetManager.addGlow(item);

String itemTag = ItemUtils.getTag(item, ItemUtils.PET_TAG);
if (itemTag != null) {
if (!itemTag.isEmpty()) {
ItemUtils.setTag(item, ItemUtils.PET_TAG, itemTag);
inventory.setItem(PetManager.getPetSlotId(), item);
} else {
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/ru/endlesscode/rpginventory/pet/PetManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ public static void despawnPet(OfflinePlayer player) {
playerWrapper.setPet(null);
}

public static void respawnPet(OfflinePlayer player) {
public static void respawnPet(@Nullable OfflinePlayer player) {
if (!InventoryManager.playerIsLoaded(player) || !PetManager.isEnabled()) {
return;
}
Expand All @@ -319,23 +319,23 @@ public static void respawnPet(OfflinePlayer player) {
}

@Nullable
@Contract("null - > null")
@Contract("null -> null")
public static PetFood getFoodFromItem(@Nullable ItemStack item) {
String id;

if (ItemUtils.isEmpty(item) || (id = ItemUtils.getTag(item, ItemUtils.FOOD_TAG)) == null) {
if (ItemUtils.isEmpty(item) || (id = ItemUtils.getTag(item, ItemUtils.FOOD_TAG)).isEmpty()) {
return null;
}

return PET_FOOD.get(id);
}

@Nullable
@Contract("null - > null")
@Contract("null -> null")
public static PetType getPetFromItem(@Nullable ItemStack item) {
String id;

if (ItemUtils.isEmpty(item) || (id = ItemUtils.getTag(item, ItemUtils.PET_TAG)) == null) {
if (ItemUtils.isEmpty(item) || (id = ItemUtils.getTag(item, ItemUtils.PET_TAG)).isEmpty()) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private static void syncPlayer(MyPetPlayer mpPlayer) {
if (isMyPetItem(currentPet)) {
MyPet pet = mpPlayer.getMyPet();
String petId = ItemUtils.getTag(currentPet, MYPET_TAG);
if (petId == null) {
if (petId.isEmpty()) {
return;
}

Expand Down Expand Up @@ -154,7 +154,7 @@ private static boolean swapMyPets(@NotNull final Player player, boolean hasPet,
}

String petId = ItemUtils.getTag(newPet, MYPET_TAG);
if (petId == null) {
if (petId.isEmpty()) {
return false;
}

Expand All @@ -169,7 +169,8 @@ public void run() {
return true;
}

private static boolean isMyPetItem(ItemStack item) {
@Contract("null -> false")
private static boolean isMyPetItem(@Nullable ItemStack item) {
return !ItemUtils.isEmpty(item) && ItemUtils.hasTag(item, MYPET_TAG);
}

Expand Down Expand Up @@ -280,7 +281,7 @@ public void onMyPetCall(@NotNull MyPetCallEvent event) {
keepPet = false;
} else {
String petTag = ItemUtils.getTag(currentPet, MYPET_TAG);
if (petTag == null) {
if (petTag.isEmpty()) {
keepPet = false;
} else {
UUID petUUID = UUID.fromString(petTag);
Expand Down Expand Up @@ -309,7 +310,7 @@ public void onMyPetRemove(@NotNull MyPetRemoveEvent event) {

if (isMyPetItem(currentPetItem)) {
String petTag = ItemUtils.getTag(currentPetItem, MYPET_TAG);
if (petTag == null) {
if (petTag.isEmpty()) {
inventory.setItem(petSlot.getSlotId(), petSlot.getCup());
return;
}
Expand Down
18 changes: 11 additions & 7 deletions src/main/java/ru/endlesscode/rpginventory/utils/ItemUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ public static ItemStack setTag(ItemStack item, String tag, @NotNull String value
return item;
}

@Nullable
public static String getTag(ItemStack item, String tag) {
return getTag(item, tag, null);
@NotNull
public static String getTag(@NotNull ItemStack item, @NotNull String tag) {
return getTag(item, tag, "");
}

@Nullable
@NotNull
@SuppressWarnings("WeakerAccess")
public static String getTag(ItemStack item, String tag, @Nullable String defaultValue) {
public static String getTag(@NotNull ItemStack item, @NotNull String tag, @NotNull String defaultValue) {
item = toBukkitItemStack(item);
NbtCompound nbt = NbtFactory.asCompound(NbtFactory.fromItemTag(item));

Expand Down Expand Up @@ -202,7 +202,6 @@ private static ItemStack syncItem(@NotNull ItemStack item) {
textureDurability = custom.getTextureDurability();
item = ItemManager.getItem(ItemUtils.getTag(item, ItemUtils.ITEM_TAG));
} else if (BackpackManager.isBackpack(item)) {
String bpUID = ItemUtils.getTag(item, ItemUtils.BACKPACK_UID_TAG);
BackpackType type = BackpackManager.getBackpackType(ItemUtils.getTag(item, ItemUtils.BACKPACK_TAG));

if (type == null) {
Expand All @@ -211,7 +210,9 @@ private static ItemStack syncItem(@NotNull ItemStack item) {

textureDurability = type.getTextureDurability();
item = type.getItem();
if (bpUID != null) {

String bpUID = ItemUtils.getTag(item, ItemUtils.BACKPACK_UID_TAG);
if (!bpUID.isEmpty()) {
ItemUtils.setTag(item, ItemUtils.BACKPACK_UID_TAG, bpUID);
}
} else if (PetType.isPetItem(item)) {
Expand Down Expand Up @@ -251,6 +252,9 @@ public static boolean isEmpty(@Nullable ItemStack item) {

@NotNull
private static ItemStack toBukkitItemStack(ItemStack item) {
if (item == null) {
return new ItemStack(Material.AIR);
}
return !item.getClass().getName().endsWith("CraftItemStack") ? MinecraftReflection.getBukkitItemStack(item) : item;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
*/
public final class ResourcePackUtils {

private final static String HEADER_LOCATION = "Location";
private final static String MIME_ZIP = "application/zip";
private static final String HEADER_LOCATION = "Location";
private static final String MIME_ZIP = "application/zip";

private ResourcePackUtils() {
// Utility class
Expand All @@ -56,8 +56,10 @@ public static void validateUrl(@NotNull String address) throws IOException {
String realUrl = conn.getURL().toString();
if (!realUrl.equals(address)) {
throw new IllegalArgumentException(
String.format("Link isn't direct. Redirect found!\n" +
"Your link: %s\nDirect link: %s", address, realUrl)
String.format("Link isn't direct. Redirect found!\n"
+ "Try to replace your link: %s\n"
+ "By this link: %s\n"
+ "If your link works normally, just ignore this message.", address, realUrl)
);
}

Expand All @@ -69,7 +71,8 @@ public static void validateUrl(@NotNull String address) throws IOException {
String contentType = conn.getContentType();
if (!contentType.equals(MIME_ZIP)) {
throw new IllegalArgumentException(
String.format("MIME type should be '%s' but given '%s'", MIME_ZIP, contentType)
String.format("MIME type should be '%s' but given '%s'\n"
+ "Please provide link to resource pack file, not to download page.", MIME_ZIP, contentType)
);
}
}
Expand Down

0 comments on commit 6bff7da

Please sign in to comment.