Skip to content

Commit

Permalink
Merge pull request #20 from PXAV/development
Browse files Browse the repository at this point in the history
Changes for release 0.0.2 - "The inventory update"
  • Loading branch information
PXAV committed Aug 3, 2020
2 parents bfe3300 + c9a6a00 commit 8f789d5
Show file tree
Hide file tree
Showing 36 changed files with 2,500 additions and 1,101 deletions.
17 changes: 16 additions & 1 deletion CHANGELOG.md
Expand Up @@ -6,8 +6,12 @@ The headlines with `MR <number>` stand for the major release. The following head

## MR 0

#### v0.0.0 (28.09.2020)
* **Beginning of Kelp development**
* First commit to the Git repo

#### v0.0.1 (30.06.2020)
* First release of Kelp
* **First release of Kelp**
* Add entity system
* Add command system
* Add NPC system
Expand All @@ -16,3 +20,14 @@ The headlines with `MR <number>` stand for the major release. The following head
* Add sidebar system
* Add entity system
* Add 1.8 support

#### v0.0.2 (03.08.2020)
* **"The inventory update"**
* Add item-bound listener system
* Implement new widgets: `ToggleableWidget`, `ItemWidget`, `Pagination`
* Remove redundant bukkitSubId modifier from `KelpMaterial`
* Interactions (taking out of an inventory, ...) with `KelpItems` are now canceled by default and have to be enabled manually
* Improve/Add documentation for many classes
* Fixed bug that CPU load was on 100% when `AnimatedInventory` was opened.
* Fixed NPE when trying to get item tags of items with type `AIR`

2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -117,7 +117,7 @@ There are version implementations for the following version implementations avai
To build all Kelp modules you first have to compile all CraftBukkit versions from 1.8 to 1.14 for yourself using the official BuildTools.jar. The CraftBukkit library may not be distributed by Kelp for legal reasons. A tutorial can be found [here](https://www.spigotmc.org/wiki/buildtools/).

```shell
java -jar BuildTools.jar --rev <version>
java -jar BuildTools.jar --compile craftbukkit --rev <version>
```


Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>de.pxav.kelp</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
<version>0.0.2-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
7 changes: 6 additions & 1 deletion core/src/main/java/de/pxav/kelp/core/KelpPlugin.java
Expand Up @@ -31,7 +31,7 @@
*
* @author pxav
*/
@Plugin(name = "Kelp", version = "0.0.1-SNAPSHOT")
@Plugin(name = "Kelp", version = "0.0.2-SNAPSHOT")
@Author("pxav")
@Description("A cross version spigot framework.")
@Singleton
Expand Down Expand Up @@ -112,6 +112,11 @@ public void onEnable() {
injector.getInstance(SoundVersionTemplate.class).defineDefaults();
injector.getInstance(KelpInventoryRepository.class).loadMaterials();
logger().log("[GENERAL] Successfully enabled KelpFramework. Have fun.");

logger().log("[GENERAL] NOTE: Kelp is still under heavy development and will contain bugs. " +
"Applications developed with the current version might not work with future releases. Do not use " +
"Kelp in production environments, but only for testing purposes. Report bugs and issues to https://github.com/PXAV/kelp " +
"to get them fixed in the next version.");
}

@Override
Expand Down
Expand Up @@ -7,7 +7,7 @@
import org.bukkit.entity.Entity;

/**
* A class description goes here.
* This factory class allows you to create new {@code KelpEntities}
*
* @author pxav
*/
Expand All @@ -21,10 +21,26 @@ public KelpEntityFactory(EntityTypeVersionTemplate typeVersionTemplate) {
this.typeVersionTemplate = typeVersionTemplate;
}

/**
* Creates a new {@code KelpEntity} instance based on the given entity type.
*
* @param entityType The type of the entity you want to spawn.
* @param location The initial location of the entity. This also contains the
* world where it is added to later.
* @return The new {@code KelpEntity}
* @see KelpEntity
* @see KelpEntityType
*/
public KelpEntity newKelpEntity(KelpEntityType entityType, Location location) {
return typeVersionTemplate.newKelpEntity(entityType, location);
}

/**
* Converts the given bukkit entity to a {@code KelpEntity}.
*
* @param bukkitEntity The instance of the bukkit entity you want to convert.
* @return The {@code KelpEntity} equivalent to the bukkit
*/
public KelpEntity getKelpEntity(Entity bukkitEntity) {
return typeVersionTemplate.getKelpEntity(bukkitEntity);
}
Expand Down
Expand Up @@ -3,21 +3,25 @@
import com.google.common.collect.Maps;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import de.pxav.kelp.core.inventory.listener.KelpListenerRepository;
import de.pxav.kelp.core.inventory.material.MaterialVersionTemplate;
import de.pxav.kelp.core.inventory.type.AnimatedInventory;
import de.pxav.kelp.core.inventory.type.KelpInventory;
import de.pxav.kelp.core.inventory.widget.Pagination;
import de.pxav.kelp.core.player.KelpPlayer;
import de.pxav.kelp.core.reflect.MethodCriterion;
import de.pxav.kelp.core.reflect.MethodFinder;
import de.pxav.kelp.core.sidebar.type.AnimatedSidebar;
import org.bukkit.inventory.Inventory;

import java.lang.reflect.Method;
import java.util.Map;
import java.util.UUID;

/**
* A class description goes here.
* This repository class stores and handles all kelp
* inventories. You can open, close and update kelp inventories
* from here. Some of the methods are also callable
* from the {@link KelpPlayer} class directly, if you are working
* with players.
*
* @author pxav
*/
Expand All @@ -26,32 +30,47 @@ public class KelpInventoryRepository {

private MaterialVersionTemplate materialVersionTemplate;
private MethodFinder methodFinder;
private KelpListenerRepository kelpListenerRepository;

private Map<String, Method> methods = Maps.newHashMap();

private Map<UUID, KelpInventory> playerInventories = Maps.newHashMap();
private Map<UUID, Map<Pagination, Integer>> playerPages = Maps.newHashMap();
private Map<UUID, AnimatedInventory> playerAnimations = Maps.newHashMap();

@Inject
public KelpInventoryRepository(MaterialVersionTemplate materialVersionTemplate, MethodFinder methodFinder) {
public KelpInventoryRepository(MaterialVersionTemplate materialVersionTemplate,
MethodFinder methodFinder,
KelpListenerRepository kelpListenerRepository) {
this.materialVersionTemplate = materialVersionTemplate;
this.methodFinder = methodFinder;
this.kelpListenerRepository = kelpListenerRepository;
}

/**
* Maps all kelp materials with the version specific bukkit materials.
*/
public void loadMaterials() {
this.materialVersionTemplate.defineDefaults();
}

public void detectInventories(String... packages) {
/* public void detectInventories(String... packages) {
methodFinder.filter(packages, MethodCriterion.annotatedWith(CreateInventory.class)).forEach(method -> {
CreateInventory annotation = method.getAnnotation(CreateInventory.class);
String identifier = annotation.identifier();
methods.put(identifier, method);
});
}

}*/

/**
* Opens a kelp inventory to the given player. This also adds the
* player to all required lists.
*
* @param inventory The inventory you want to show to the player.
* @param player The player who should see the inventory.
*/
public void openInventory(KelpInventory inventory, KelpPlayer player) {
Inventory renderedInventory = inventory.render();
player.getBukkitPlayer().openInventory(renderedInventory);
Expand All @@ -65,27 +84,42 @@ public void openInventory(KelpInventory inventory, KelpPlayer player) {
playerInventories.put(player.getUUID(), inventory);
}

/**
* This method should be executed when a player closes their
* kelp inventory as it removes the player from the cache and
* stops all schedulers.
*
* @param player The player you want to remove from the cache/whose inventory
* you want to close.
*/
public void closeInventory(KelpPlayer player) {
KelpInventory inventory = this.playerInventories.get(player.getUUID());

// if his inventory was animated, stop the scheduler
if (inventory instanceof AnimatedInventory) {
AnimatedInventory animatedInventory = (AnimatedInventory) inventory;
animatedInventory.stopUpdater();
}

this.playerInventories.remove(player.getUUID());
this.playerAnimations.remove(player.getUUID());
this.kelpListenerRepository.unregisterListeners(player.getUUID());
}

public void schedule() {

}

public void openInventory(KelpPlayer player, String identifier) {

}

/**
* Updates the entire kelp inventory of a player.
* This includes all widgets, but not the normal
* inventory of the player.
*
* @param player The player whose inventory you want to update.
*/
public void updateInventory(KelpPlayer player) {
KelpInventory kelpInventory = playerInventories.get(player.getUUID());
kelpInventory.update(player);
}

public Map<UUID, Map<Pagination, Integer>> getPlayerPages() {
return playerPages;
}

}
Expand Up @@ -3,20 +3,73 @@
import de.pxav.kelp.core.application.KelpVersionTemplate;
import org.bukkit.inventory.ItemStack;

import java.util.Collection;

/**
* A class description goes here.
* This version template can be used to handle the tags
* of an item.
*
* Every item can have a tag in minecraft. Those are called NBT tags.
* If you set a display name or a lore for your item, it automatically
* has NBT tags saving the name and lore of your item.
*
* To define custom tags, there are different ways - depending on the
* version you are using. Since 1.14 the NBT tag library in Bukkit has
* been "replaced" by the {@code PersistentDataContainer}, which is why
* tag handling has become a version dependent thing. That's why there
* is a version template: It uses either the PersistentData library or
* the NBT tag library depending on the server version you are using.
*
* @author pxav
*/
@KelpVersionTemplate
public abstract class ItemTagVersionTemplate {

/**
* Adds a string tag to the given item stack.
*
* @param itemStack The item stack you want to apply the tag to.
* @param key The key of the tag. This is how you will access the
* tag value later.
* @param value The actual value to save inside your tag.
* @return The new {@code ItemStack} containing the tag data.
*/
public abstract ItemStack tagItem(ItemStack itemStack, String key, String value);

/**
* Removes the tag with the given key from the given item stack.
*
* @param itemStack The item stack you want to remove the tag from.
* @param key The key of the tag you want to remove.
* @return The new {@code ItemStack} containing the updated tag data.
*/
public abstract ItemStack removeTag(ItemStack itemStack, String key);

/**
* Checks whether the given item stack has a tag with the given key.
*
* @param itemStack The item stack you want to check.
* @param key The key of the tag you want to check the existence of.
* @return {@code true} if the item stack has the desired tag.
*/
public abstract boolean hasTagKey(ItemStack itemStack, String key);

/**
* Gets the tag value of the tag with the specified key. This method
* only accepts string values.
*
* @param itemStack The item stack you want to get the tag from.
* @param key The key of the tag you want to get the value from.
* @return The string value of the desired tag.
*/
public abstract String getStringValue(ItemStack itemStack, String key);

/**
* Gets the keys of all tags the given item stack has.
*
* @param itemStack The item stack you want to get the tag keys of.
* @return A collection of all tag keys of the given item stack.
*/
public abstract Collection<String> getTagKeys(ItemStack itemStack);

}

0 comments on commit 8f789d5

Please sign in to comment.