Skip to content

Commit

Permalink
1.4.8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ThisKarolGajda committed Nov 12, 2022
1 parent a1ead6b commit c3bf58b
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@
<target>17</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<javadocExecutable>${java.home}/bin/javadoc</javadocExecutable>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.opkarol.opc.api.commands;

import me.opkarol.opc.api.location.OpSerializableLocation;
import me.opkarol.opc.api.utils.FormatUtils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -33,4 +34,8 @@ public void sendMessage(String message) {
sender.sendMessage(message);
}
}

public @Nullable OpSerializableLocation getLocation() {
return isPlayer() ? new OpSerializableLocation(getPlayer().getLocation()) : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Range;

import java.util.function.Consumer;

public record OpCommandArgument<I extends IType>(
OpLinkedMap<IType, OpTypeArg<I>> args,
String[] strings,
Expand Down Expand Up @@ -44,4 +46,12 @@ public String getString(@NotNull IType name) {
public String getString(@Range(from = 0, to = 15) int i) {
return String.valueOf(get(OP16.values()[i]));
}

public void useString(@NotNull IType name, @NotNull Consumer<String> consumer) {
consumer.accept(getString(name));
}

public void useString(@Range(from = 0, to = 15) int i, @NotNull Consumer<String> consumer) {
consumer.accept(getString(i));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package me.opkarol.opc.api.database.manager;

public class DatabaseHolder<O, C> {
private static DatabaseImpl<?, ?> database;

public static <O, C> void setDatabase(DatabaseImpl<O, C> database) {
DatabaseHolder.database = database;
}

public static DatabaseImpl<?, ?> getDatabase() {
return database;
}

public IDefaultDatabase<O, C> getLocalDatabase() {
return (IDefaultDatabase<O, C>) database.getLocalDatabase();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ default void checkAndUse(UUID uuid, C object, Runnable noObject, Consumer<O> obj
}
}

default void checkAndUse(UUID uuid, C object, Runnable noObject, Runnable objectFound) {
if (contains(uuid, object)) {
Optional<O> optional = get(uuid, object);
if (optional.isEmpty()) {
noObject.run();
} else {
objectFound.run();
}
} else {
noObject.run();
}
}

default void deleteAndUse(UUID uuid, C object, Runnable noObject, Runnable objectFound) {
if (delete(uuid, object)) {
objectFound.run();
Expand All @@ -54,6 +67,15 @@ default void addAndUse(UUID uuid, C object, O obj, Runnable noObject, Consumer<O
}
}

default void addAndUse(UUID uuid, C object, O obj, Runnable noObject, Runnable objectFound) {
if (contains(uuid, object)) {
noObject.run();
} else {
add(uuid, obj);
objectFound.run();
}
}

default OpCommandSuggestion getSuggestions(Function<O, String> function) {
return new OpCommandSuggestion((sender, args) -> {
if (sender.isPlayer()) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/me/opkarol/opc/api/plugin/OpDatabasePlugin.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package me.opkarol.opc.api.plugin;

import me.opkarol.opc.api.database.manager.Database;
import me.opkarol.opc.api.database.manager.DatabaseHolder;
import me.opkarol.opc.api.database.manager.DatabaseImpl;
import me.opkarol.opc.api.database.manager.IDefaultDatabase;
import org.jetbrains.annotations.NotNull;

import java.util.UUID;

public abstract class OpDatabasePlugin<O, C> extends OpPlugin {
private static DatabaseImpl<?, ?> databaseInterface;

Expand All @@ -27,6 +30,7 @@ public static <O, C> void setDatabasePlugin(@NotNull Database<O, C> databasePlug
@Override
public void onEnable() {
setDatabasePlugin(getBase());
DatabaseHolder.setDatabase((DatabaseImpl<UUID, String>) getLocalDatabase());
super.onEnable();
}

Expand Down
10 changes: 10 additions & 0 deletions src/main/java/me/opkarol/opc/api/plugin/OpMessagesPlugin.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package me.opkarol.opc.api.plugin;

import me.opkarol.opc.api.commands.OpCommandSender;
import me.opkarol.opc.api.files.ConfigurationMap;
import me.opkarol.opc.api.files.TranslationObject;
import org.jetbrains.annotations.NotNull;

public abstract class OpMessagesPlugin<O, C> extends OpDatabasePlugin<O, C> {
private static final ConfigurationMap configurationMap;
Expand Down Expand Up @@ -30,4 +32,12 @@ public static String getValue(String path, TranslationObject... objects) {
public static String getValue(String path, String[][] objects) {
return getMap().getValue(path, objects);
}

public static void sendMappedMessage(@NotNull OpCommandSender sender, String path, String[][] strings) {
sender.sendMessage(getValue(path, strings));
}

public static @NotNull Runnable getMappedMessage(OpCommandSender sender, String path, String[][] strings) {
return () -> sender.sendMessage(getValue(path, strings));
}
}

0 comments on commit c3bf58b

Please sign in to comment.