Skip to content

Commit

Permalink
1.5
Browse files Browse the repository at this point in the history
INVENTORY UPDATE
  • Loading branch information
ThisKarolGajda committed Dec 28, 2022
1 parent 8e6c04d commit c5e8ab2
Show file tree
Hide file tree
Showing 54 changed files with 1,811 additions and 913 deletions.
39 changes: 16 additions & 23 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>17</source>
<target>17</target>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
Expand All @@ -30,19 +30,19 @@
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<outputFile>E:/Servers/Test6Plugin - 1.19.2/plugins/opc - 1.1.0.jar</outputFile>
<filters>
<filter>
<artifact>*:*</artifact>
<includes>
<include>me/opkarol/opc/**</include>
<include>plugin.yml</include>
<include>config.yml</include>
<include>com/tchristofferson/configupdater/**</include>
<include>com/zaxxer/hikari/**</include>
</includes>
</filter>
</filters>
<outputFile>E:/Servers/Test6Plugin - 1.19.2/plugins/opc - ${project.version}.jar</outputFile>
<filters>
<filter>
<artifact>*:*</artifact>
<includes>
<include>me/opkarol/opc/**</include>
<include>plugin.yml</include>
<include>config.yml</include>
<include>com/tchristofferson/configupdater/**</include>
<include>com/zaxxer/hikari/**</include>
</includes>
</filter>
</filters>
<relocations>
<relocation>
<pattern>com.tchristofferson.configupdater</pattern>
Expand All @@ -58,18 +58,11 @@
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>../src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<packaging>jar</packaging>

<name>opc</name>
<description>opc is a modern and blazing-ly fast spigot api extension which allows developers to do tasks fast</description>

<description>opc is a modern and blazingly fast spigot api extenstion which allows developers to do tasks fast.</description>
<properties>
<java.version>17</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public void setup(String jdbcUrl, String username, String password) {
public void close() {
if (hikariDataSource != null && !hikariDataSource.isClosed()) {
hikariDataSource.close();
hikariDataSource = null;
source = null;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.opkarol.opc.api.database.mysql.reflection.base;

import me.opkarol.opc.api.autostart.OpAutoDisable;
import me.opkarol.opc.api.commands.suggestions.OpCommandSuggestion;
import me.opkarol.opc.api.database.manager.IDefaultDatabase;
import me.opkarol.opc.api.database.manager.settings.MySqlDatabaseSettings;
Expand All @@ -16,31 +17,37 @@ public class OpDatabaseImpl<O, C> extends DatabaseImpl<O, C> implements IDefault

public OpDatabaseImpl() {
database = this;
registerDisablement();
}

public OpDatabaseImpl(String mysql) {
super(mysql);
database = this;
registerDisablement();
}

public OpDatabaseImpl(MySqlDatabaseSettings mysql) {
super(mysql);
database = this;
registerDisablement();
}

public OpDatabaseImpl(MySqlDatabaseSettings mysql, Class<O> clazz) {
super(clazz, mysql);
database = this;
registerDisablement();
}

public OpDatabaseImpl(Configuration configuration, String mysql) {
super(configuration, mysql);
database = this;
registerDisablement();
}

public OpDatabaseImpl(Class<O> clazz, Configuration configuration, String mysql) {
super(clazz, configuration, mysql);
database = this;
registerDisablement();
}

public OpDatabaseImpl<O, C> getLocalDatabase() {
Expand Down Expand Up @@ -95,8 +102,11 @@ public OpCommandSuggestion getSuggestions(Function<O, String> function) {
}

@Override
@SuppressWarnings("all")
public void add(UUID uuid, O object) {
add(object);
}

private void registerDisablement() {
OpAutoDisable.register((plugin) -> database.close());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import java.util.function.Consumer;

public class OpEvent {
public class EventRegister {
private static final Plugin opC = OpAPI.getInstance();

public static <E extends Event> void registerEvent(Class<E> clazz, Consumer<E> consumer) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package me.opkarol.opc.api.events;

import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;

public class OpCancellableEventExtender extends Event implements Cancellable {
private static final HandlerList HANDLERS = new HandlerList();
private boolean cancelled;

@NotNull
@Override
public HandlerList getHandlers() {
return HANDLERS;
}

public static HandlerList getHandlerList() {
return HANDLERS;
}

@Override
public boolean isCancelled() {
return cancelled;
}

@Override
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}
}
19 changes: 19 additions & 0 deletions src/main/java/me/opkarol/opc/api/events/OpEventExtender.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package me.opkarol.opc.api.events;

import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;

public class OpEventExtender extends Event {
private static final HandlerList HANDLERS = new HandlerList();

@NotNull
@Override
public HandlerList getHandlers() {
return HANDLERS;
}

public static HandlerList getHandlerList() {
return HANDLERS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public String getValue(String path) {
map.set(path, str);
return str;
}

return object.toString();
}

Expand Down
49 changes: 49 additions & 0 deletions src/main/java/me/opkarol/opc/api/gui/InventoryCache.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package me.opkarol.opc.api.gui;

import me.opkarol.opc.api.gui.events.InventoryListener;
import me.opkarol.opc.api.gui.replacement.ReplacementInventoryImpl;
import me.opkarol.opc.api.map.OpMap;

import java.util.*;

import static me.opkarol.opc.api.utils.VariableUtil.getOrDefault;

public class InventoryCache {
private static InventoryCache cache;
private final OpMap<UUID, ReplacementInventoryImpl> activeInventories = new OpMap<>();
private final Set<UUID> inventoriesOpened = new HashSet<>();

public InventoryCache() {
cache = this;
new InventoryListener(this);
}

public void setActiveInventory(UUID uuid, ReplacementInventoryImpl inventory) {
activeInventories.set(uuid, inventory);
inventoriesOpened.add(uuid);
}

public Optional<ReplacementInventoryImpl> getActiveInventory(UUID uuid) {
return activeInventories.getByKey(uuid);
}

public void removeActiveInventory(UUID uuid) {
activeInventories.remove(uuid);
}

public void removeInventoryOpen(UUID uuid) {
inventoriesOpened.remove(uuid);
}

public boolean hasSavedInventory(UUID uuid) {
return inventoriesOpened.contains(uuid);
}

public static InventoryCache getCache() {
return getOrDefault(cache, new InventoryCache());
}

public String getInventoriesOpened() {
return Arrays.toString(inventoriesOpened.toArray());
}
}
73 changes: 0 additions & 73 deletions src/main/java/me/opkarol/opc/api/gui/InventoryListener.java

This file was deleted.

38 changes: 38 additions & 0 deletions src/main/java/me/opkarol/opc/api/gui/OpInventory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package me.opkarol.opc.api.gui;

import me.opkarol.opc.api.gui.database.InvHolderImpl;
import me.opkarol.opc.api.gui.events.chest.OnInventoryClose;
import me.opkarol.opc.api.gui.holder.inventory.InventoryEventExtender;
import me.opkarol.opc.api.gui.holder.inventory.InventoryEventHolder;
import me.opkarol.opc.api.gui.inventory.AbstractInventory;
import me.opkarol.opc.api.gui.inventory.IInventoryIdentification;
import me.opkarol.opc.api.gui.items.InventoryItem;
import me.opkarol.opc.api.gui.replacement.ReplacementInventoryImpl;

import java.util.function.Consumer;

public final class OpInventory extends ReplacementInventoryImpl {
public <K extends AbstractInventory<?, ?> & IInventoryIdentification> OpInventory(K factory, Consumer<OnInventoryClose> action) {
super(new InvHolderImpl(factory.getType(), factory, new InventoryEventExtender(action)));
}

public <K extends AbstractInventory<?, ?> & IInventoryIdentification> OpInventory(K factory, InventoryEventHolder action) {
super(new InvHolderImpl(factory.getType(), factory, action));
}

public <K extends AbstractInventory<?, ?> & IInventoryIdentification> OpInventory(K factory) {
super(new InvHolderImpl(factory.getType(), factory, null));
}

public void setGlobalItem(InventoryItem item, int slot) {
setInPagesRange(getMaxPages(), item, slot);
}

public void setGlobalItem(int globalRange, InventoryItem item, int slot) {
setInPagesRange(globalRange, item, slot);
}

public void setAutoBuild(boolean autoBuild) {
getInventoryHolder().getHolder().setAutoBuild(autoBuild);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package me.opkarol.opc.api.gui.database;

import me.opkarol.opc.api.gui.inventory.AbstractInventory;
import me.opkarol.opc.api.gui.items.InventoryItem;

public class DefaultInvHolder extends InvHolder<InventoryItem> {

public DefaultInvHolder(AbstractInventory<Integer, InventoryItem> inventory) {
super(inventory);
}
}
Loading

0 comments on commit c5e8ab2

Please sign in to comment.