Updated ChestSortAPI to 11.0.0-SNAPSHOT

This commit is contained in:
mfnalex 2021-07-07 09:19:30 +02:00
parent c1d9b43f40
commit 4109a24bd4
10 changed files with 288 additions and 83 deletions

View File

@ -1,5 +1,10 @@
# Changelog
## 11.0.0
- Enhanced API
- Added Chinese (Simplified) translation
- Updated Dutch translation
## 10.3.2
- Updated Hungarian translation

View File

@ -1,46 +0,0 @@
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at mail@jeff-media.de. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/

View File

@ -23,34 +23,12 @@ You can use maven to add ChestSort as a dependency to your Spigot-/Bukkit-Plugin
<dependency>
<groupId>de.jeff_media</groupId>
<artifactId>ChestSortAPI</artifactId>
<version>4.0.1</version> <!-- The API version is independent of the ChestSort version -->
<version>11.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
```
If you use the `Sortable`class or the `ISortable` interface, you must also shade the ChestSortAPI into your plugin:
```xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
```
## Accessing the API
Then you can access the API via the plugin manager:

18
pom.xml
View File

@ -9,7 +9,7 @@
<name>ChestSort</name>
<url>https://www.chestsort.de</url>
<description>Allows automatic chest sorting!</description>
<version>10.3.2</version>
<version>11.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
@ -91,8 +91,17 @@
<exclude>org.jetbrains:*</exclude>
<exclude>org.intellij.lang:*</exclude>
<exclude>org.slf4j</exclude>
<exclude>de.jeff_media.chestsortapi:de.jeff_media.chestsortapi.ChestSortAPI</exclude>
</excludes>
</artifactSet>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>de/jeff_media/chestsortapi/**</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
@ -168,13 +177,6 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>de.jeff_media</groupId>
<artifactId>ChestSortAPI</artifactId>
<version>4.0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>de.jeff_media</groupId>
<artifactId>SpigotUpdateChecker</artifactId>

View File

@ -0,0 +1,29 @@
package de.jeff_media.chestsort.api;
import de.jeff_media.chestsort.ChestSortPlugin;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
public class ChestSortAPI {
public static void sortInventory(Inventory inventory) {
ChestSortPlugin.getInstance().getOrganizer().sortInventory(inventory);
}
public static void sortInventory(Inventory inventory, int startSlot, int endSlot) {
ChestSortPlugin.getInstance().getOrganizer().sortInventory(inventory, startSlot, endSlot);
}
public static boolean hasSortingEnabled(Player player) {
return ChestSortPlugin.getInstance().isSortingEnabled(player);
}
public static void setSortable(Inventory inv) {
ChestSortPlugin.getInstance().getOrganizer().setSortable(inv);
}
public static void setUnsortable(Inventory inv) {
ChestSortPlugin.getInstance().getOrganizer().setUnsortable(inv);
}
}

View File

@ -0,0 +1,166 @@
package de.jeff_media.chestsort.api;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.bukkit.Location;
import org.bukkit.entity.HumanEntity;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* This event is called whenever ChestSort attempts to sort an inventory. Can be cancelled to prevent ChestSort from manipulating this inventory.
*/
public class ChestSortEvent extends Event implements Cancellable {
private static final HandlerList HANDLERS = new HandlerList();
final Inventory inv;
// For each ItemStack, a map of "{placeholder}", "sortString" pairs.
Map<ItemStack, Map<String, String>> invSortableMaps;
boolean cancelled = false;
Location loc;
HumanEntity p;
public List<ItemStack> getUnmovableItemStacks() {
return unmovableItemStacks;
}
public List<Integer> getUnmovableSlots() {
return unmovableSlots;
}
List<ItemStack> unmovableItemStacks;
List<Integer> unmovableSlots;
public ChestSortEvent(Inventory inv) {
this.inv = inv;
this.unmovableItemStacks = new ArrayList<>();
this.unmovableSlots = new ArrayList<>();
}
public static HandlerList getHandlerList() {
return HANDLERS;
}
/**
* Returns the location associated with this event. Might be null
* @return Location associated with this event, or null if no location has been set
*/
@Nullable
public Location getLocation() {
return loc;
}
/**
* Sets the location associated with this event
* @param loc
*/
public void setLocation(Location loc) { this.loc=loc; }
/**
* Returns the inventory associated with this event
* @return Inventory to be sorted
*/
public Inventory getInventory() {
return inv;
}
public Map<ItemStack, Map<String, String>> getSortableMaps() {
return invSortableMaps;
}
public void setSortableMaps(Map<ItemStack, Map<String, String>> sortableMap) {
invSortableMaps = sortableMap;
}
/**
* Returns the player associated with this event. Might be null
* @return Player associated with this event, or null if no player has been set
*/
@Nullable
public HumanEntity getPlayer() {
return p;
}
/**
* Sets the player associated with this event
* @param p Player associated with this event, can be null
*/
public void setPlayer(@Nullable HumanEntity p) { this.p=p; }
/**
* Prevents ChestSort from sorting/moving this specific slot
* @param slot
*/
public void setUnmovable(int slot) {
unmovableSlots.add(slot);
}
/**
* Prevents ChestSort from sorting/moving matching ItemStacks
* @param itemStack
*/
public void setUnmovable(ItemStack itemStack) {
unmovableItemStacks.add(itemStack);
}
/**
* Removes a slot number from the list of unmovable slots
* @param slot
*/
public void removeUnmovable(int slot) {
unmovableSlots.remove(slot);
}
/**
* Removes an ItemStack from the list of unmovable ItemStacks
* @param itemStack
*/
public void removeUnmovable(ItemStack itemStack) {
unmovableItemStacks.remove(itemStack);
}
/**
* Checks whether a slot number is set as unmovable
* @param slot
* @return true if the slot number has been set unmovable, otherwise false
*/
public boolean isUnmovable(int slot) {
return unmovableSlots.contains(slot);
}
/**
* Checks whether an ItemStack is set as unmovable
* @param itemStack
* @return true if the ItemStack has been set unmovable, otherwise false
*/
public boolean isUnmovable(ItemStack itemStack) {
return unmovableItemStacks.contains(itemStack);
}
public @NotNull HandlerList getHandlers() {
return HANDLERS;
}
/**
* Checks whether this event is cancelled. If true, the Inventory will not be sorted
* @return true when the event has been cancelled, otherwise false
*/
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancel) {
cancelled = cancel;
}
}

View File

@ -0,0 +1,9 @@
package de.jeff_media.chestsort.api;
import org.bukkit.inventory.InventoryHolder;
/**
* Public interface that can be used as InventoryHolder to tell ChestSort that the associated inventory is sortable
*/
public interface ISortable extends InventoryHolder {
}

View File

@ -0,0 +1,44 @@
package de.jeff_media.chestsort.api;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Public class that can be used as InventoryHolder to tell ChestSort that the associated inventory is sortable.
*/
public class Sortable implements ISortable {
private Inventory inv;
private InventoryHolder h = null;
public Sortable() {
}
public Sortable(InventoryHolder h) {
this.h=h;
}
public void setHolder(@NotNull InventoryHolder player) {
this.h=h;
}
public void removeHolder() {
this.h=null;
}
@Nullable
public InventoryHolder getHolder() {
return h;
}
@Override
public Inventory getInventory() {
return inv;
}
public void setInventory(Inventory inv) {
this.inv=inv;
}
}

View File

@ -1,6 +1,6 @@
package de.jeff_media.chestsort.handlers;
import de.jeff_media.chestsort.ChestSortEvent;
import de.jeff_media.chestsort.api.ChestSortEvent;
import de.jeff_media.chestsort.ChestSortPlugin;
import de.jeff_media.chestsort.data.Category;
import de.jeff_media.chestsort.hooks.CrackShotHook;
@ -59,6 +59,8 @@ public class ChestSortOrganizer {
// We store a list of all Category objects
public final ArrayList<Category> categories = new ArrayList<>();
final ArrayList<String> stickyCategoryNames = new ArrayList<>();
private final HashSet<Inventory> sortableInventories = new HashSet<>();
private final HashSet<Inventory> unsortableInventories = new HashSet<>();
public ChestSortOrganizer(ChestSortPlugin plugin) {
this.plugin = plugin;
@ -149,6 +151,18 @@ public class ChestSortOrganizer {
}
}
public void setSortable(Inventory inv) {
sortableInventories.add(inv);
}
public void setUnsortable(Inventory inv) {
unsortableInventories.add(inv);
}
public boolean isMarkedAsSortable(Inventory inv) {
return sortableInventories.contains(inv);
}
static int getNumberOfEnchantments(ItemStack is) {
int totalEnchants = 0;
@ -464,6 +478,7 @@ public class ChestSortOrganizer {
// Sort an inventory only between startSlot and endSlot
public void sortInventory(@NotNull Inventory inv, int startSlot, int endSlot) {
if(inv==null) return;
if(unsortableInventories.contains(inv)) return;
plugin.debug("Attempting to sort an Inventory and calling ChestSortEvent.");
Class<? extends Inventory> invClass = inv.getClass();
ChestSortEvent chestSortEvent = new ChestSortEvent(inv);

View File

@ -1,11 +1,11 @@
package de.jeff_media.chestsort.listeners;
import de.jeff_media.chestsort.ChestSortEvent;
import de.jeff_media.chestsort.api.ChestSortEvent;
import de.jeff_media.chestsort.config.Messages;
import de.jeff_media.chestsort.enums.Hotkey;
import de.jeff_media.chestsort.handlers.Logger;
import de.jeff_media.chestsort.ChestSortPlugin;
import de.jeff_media.chestsort.ISortable;
import de.jeff_media.chestsort.api.*;
import de.jeff_media.chestsort.data.PlayerSetting;
import de.jeff_media.chestsort.hooks.*;
import de.jeff_media.chestsort.utils.LlamaUtils;
@ -186,7 +186,8 @@ public class Listener implements org.bukkit.event.Listener {
if (!isAPICall(inventory)
&& !belongsToChestLikeBlock(inventory)
&& !plugin.getEnderContainersHook().isEnderchest(inventory)
&& !LlamaUtils.belongsToLlama(inventory)) {
&& !LlamaUtils.belongsToLlama(inventory)
&& !plugin.getOrganizer().isMarkedAsSortable(inventory)) {
return;
}
@ -236,7 +237,8 @@ public class Listener implements org.bukkit.event.Listener {
if (!isAPICall(inventory)
&& !belongsToChestLikeBlock(inventory)
&& !plugin.getEnderContainersHook().isEnderchest(inventory)
&& !LlamaUtils.belongsToLlama(inventory)) {
&& !LlamaUtils.belongsToLlama(inventory)
&& !plugin.getOrganizer().isMarkedAsSortable(inventory)) {
return;
}
@ -515,6 +517,7 @@ public class Listener implements org.bukkit.event.Listener {
if (isAPICall
|| belongsToChestLikeBlock(event.getClickedInventory())
|| plugin.getOrganizer().isMarkedAsSortable(event.getClickedInventory())
|| LlamaUtils.belongsToLlama(event.getClickedInventory())
|| minepacksHook.isMinepacksBackpack(event.getClickedInventory())
|| plugin.getPlayerVaultsHook().isPlayerVault(event.getClickedInventory())
@ -559,7 +562,7 @@ public class Listener implements org.bukkit.event.Listener {
private boolean isAPICall(Inventory inv) {
if(inv==null) return false;
return inv.getHolder() instanceof ISortable;
return inv.getHolder() instanceof ISortable || plugin.getOrganizer().isMarkedAsSortable(inv);
}
@EventHandler