Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

Commit

Permalink
Remove SimpleTuples library
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoNekoDev committed Jul 1, 2023
1 parent 3045209 commit 7d60f2c
Show file tree
Hide file tree
Showing 22 changed files with 347 additions and 317 deletions.
2 changes: 1 addition & 1 deletion astralbooks-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</parent>

<properties>
<java.version>8</java.version>
<java.version>17</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@

package ro.niconeko.astralbooks.api;

import io.github.NicoNekoDev.SimpleTuples.Pair;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import ro.niconeko.astralbooks.utils.Side;
import ro.niconeko.astralbooks.utils.tuples.PairTuple;

import java.util.Set;

Expand Down Expand Up @@ -289,7 +289,7 @@ public interface AstralBooksAPI {
* @param cmd The command
* @return A pair of filter name and permission
*/
Pair<String, String> getCommandFilter(String cmd);
PairTuple<String, String> getCommandFilter(String cmd);

/**
* Checks if the given command exists
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* CitizensBooks
* Copyright (c) 2023 @ Drăghiciu 'NicoNekoDev' Nicolae
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package ro.niconeko.astralbooks.utils.tuples;

public record PairTuple<K1, K2>(K1 firstValue, K2 secondValue) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* CitizensBooks
* Copyright (c) 2023 @ Drăghiciu 'NicoNekoDev' Nicolae
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package ro.niconeko.astralbooks.utils.tuples;

public record TripletTuple<K1, K2, K3>(K1 firstValue, K2 secondValue, K3 thirdValue) {
}
6 changes: 0 additions & 6 deletions astralbooks-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@
<version>3.0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.github.NicoNekoDev</groupId>
<artifactId>SimpleTuples</artifactId>
<version>1.0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

package ro.niconeko.astralbooks;

import io.github.NicoNekoDev.SimpleTuples.Pair;
import io.github.NicoNekoDev.SimpleTuples.Triplet;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import org.bukkit.Bukkit;
Expand All @@ -39,6 +37,8 @@
import ro.niconeko.astralbooks.utils.Message;
import ro.niconeko.astralbooks.utils.PersistentKey;
import ro.niconeko.astralbooks.utils.Side;
import ro.niconeko.astralbooks.utils.tuples.PairTuple;
import ro.niconeko.astralbooks.utils.tuples.TripletTuple;

import java.text.SimpleDateFormat;
import java.util.*;
Expand Down Expand Up @@ -1231,23 +1231,23 @@ private void sendSecurityPage(CommandSender sender, OfflinePlayer player, int pa
this.plugin.getLogger().warning("The date format for \"book_security_date_format\" is not correctly set. Please check the settings!");
dateFormat = new SimpleDateFormat("dd/MM/yyyy-HH:mm:ss");
}
LinkedList<Pair<Date, ItemStack>> securityBooks = this.plugin.getPluginStorage().getAllBookSecurity(player.getUniqueId(), page - 1, 10);
LinkedList<PairTuple<Date, ItemStack>> securityBooks = this.plugin.getPluginStorage().getAllBookSecurity(player.getUniqueId(), page - 1, 10);
if (securityBooks.isEmpty()) {
sender.sendMessage(messageSettings.getMessage(Message.BOOK_SECURITY_NOT_FOUND));
return;
}
sender.sendMessage(messageSettings.getMessage(Message.BOOK_SECURITY_LIST_PRESENT).replace("%page%", String.valueOf(page)));
int count = 0;
for (Pair<Date, ItemStack> securityBook : securityBooks) {
ItemStack book = securityBook.getSecondValue();
for (PairTuple<Date, ItemStack> securityBook : securityBooks) {
ItemStack book = securityBook.secondValue();
String title = "<no title>";
if (book.hasItemMeta() && book.getItemMeta() instanceof BookMeta bookMeta && bookMeta.hasTitle())
title = bookMeta.getTitle();
sender.sendMessage(messageSettings.parseMessage(
"&c&l " + (((page - 1) * 10) + count + 1) +
") &f" + player.getName() +
" &e- &f" + dateFormat.format(securityBook.getFirstValue()) +
" &c(&b" + securityBook.getFirstValue().getTime() + "&c) &e- &f" +
" &e- &f" + dateFormat.format(securityBook.firstValue()) +
" &c(&b" + securityBook.firstValue().getTime() + "&c) &e- &f" +
title
));
count++;
Expand All @@ -1263,24 +1263,24 @@ private void sendSecurityPage(CommandSender sender, int page) {
this.plugin.getLogger().warning("The date format for \"book_security_date_format\" is not correctly set. Please check the settings!");
dateFormat = new SimpleDateFormat("dd/MM/yyyy-HH:mm:ss");
}
LinkedList<Triplet<UUID, Date, ItemStack>> securityBooks = this.plugin.getPluginStorage().getAllBookSecurity(page - 1, 10);
LinkedList<TripletTuple<UUID, Date, ItemStack>> securityBooks = this.plugin.getPluginStorage().getAllBookSecurity(page - 1, 10);
if (securityBooks.isEmpty()) {
sender.sendMessage(messageSettings.getMessage(Message.BOOK_SECURITY_NOT_FOUND).replace("%page%", String.valueOf(page)));
return;
}
sender.sendMessage(messageSettings.getMessage(Message.BOOK_SECURITY_LIST_PRESENT));
int count = 0;
for (Triplet<UUID, Date, ItemStack> securityBook : securityBooks) {
OfflinePlayer player = Bukkit.getOfflinePlayer(securityBook.getFirstValue());
ItemStack book = securityBook.getThirdValue();
for (TripletTuple<UUID, Date, ItemStack> securityBook : securityBooks) {
OfflinePlayer player = Bukkit.getOfflinePlayer(securityBook.firstValue());
ItemStack book = securityBook.thirdValue();
String title = "<no title>";
if (book.hasItemMeta() && book.getItemMeta() instanceof BookMeta bookMeta && bookMeta.hasTitle())
title = bookMeta.getTitle();
sender.sendMessage(messageSettings.parseMessage(
"&c&l " + (((page - 1) * 10) + count + 1) +
") &f" + player.getName() +
" &e- &f" + dateFormat.format(securityBook.getSecondValue()) +
" &c(&b" + securityBook.getSecondValue().getTime() + "&c) &e- &f" +
" &e- &f" + dateFormat.format(securityBook.secondValue()) +
" &c(&b" + securityBook.secondValue().getTime() + "&c) &e- &f" +
title
));
count++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import io.github.NicoNekoDev.SimpleTuples.Pair;
import io.github.NicoNekoDev.SimpleTuples.Triplet;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import net.luckperms.api.LuckPerms;
Expand Down Expand Up @@ -58,9 +56,11 @@
import ro.niconeko.astralbooks.persistent.item.NBTAPIItemData;
import ro.niconeko.astralbooks.persistent.item.PersistentItemData;
import ro.niconeko.astralbooks.storage.PluginStorage;
import ro.niconeko.astralbooks.utils.tuples.PairTuple;
import ro.niconeko.astralbooks.utils.PersistentKey;
import ro.niconeko.astralbooks.utils.Side;
import ro.niconeko.astralbooks.utils.UpdateChecker;
import ro.niconeko.astralbooks.utils.tuples.TripletTuple;
import ro.nicuch.citizensbooks.CitizensBooksAPI;
import ro.nicuch.citizensbooks.CitizensBooksPlugin;

Expand All @@ -76,7 +76,7 @@ public class AstralBooksCore implements AstralBooksAPI {
private final AstralBooksPlugin plugin;
private Distribution distribution = null;
private final Map<Chunk, Set<Block>> blocksPairedToChunk = new HashMap<>();
private final Map<Block, Pair<ItemStack, ItemStack>> clickableBlocks = new HashMap<>();
private final Map<Block, PairTuple<ItemStack, ItemStack>> clickableBlocks = new HashMap<>();
private final Pattern namePattern = Pattern.compile("^[a-zA-Z0-9_-]+$");
private final Pattern permissionPattern = Pattern.compile("^[a-zA-Z0-9\\._-]+$");

Expand Down Expand Up @@ -143,7 +143,7 @@ protected void importFromCitizensBooks() {
this.plugin.getLogger().warning("Done :)");
}

public void deployBooksForChunk(Chunk chunk, Map<Block, Pair<ItemStack, ItemStack>> clickableBlocks) {
public void deployBooksForChunk(Chunk chunk, Map<Block, PairTuple<ItemStack, ItemStack>> clickableBlocks) {
this.clickableBlocks.putAll(clickableBlocks);
this.blocksPairedToChunk.put(chunk, new HashSet<>(clickableBlocks.keySet()));
}
Expand All @@ -159,8 +159,8 @@ public Set<Block> getBlocksPairedToChunk(Chunk chunk) {
return this.blocksPairedToChunk.get(chunk);
}

public Map<Block, Pair<ItemStack, ItemStack>> getBlocksEntriesPairedToChunk(Chunk chunk) {
Map<Block, Pair<ItemStack, ItemStack>> reducedMap = new HashMap<>();
public Map<Block, PairTuple<ItemStack, ItemStack>> getBlocksEntriesPairedToChunk(Chunk chunk) {
Map<Block, PairTuple<ItemStack, ItemStack>> reducedMap = new HashMap<>();
Set<Block> blocks = this.blocksPairedToChunk.get(chunk);
if (blocks != null)
for (Block block : blocks) {
Expand All @@ -169,18 +169,18 @@ public Map<Block, Pair<ItemStack, ItemStack>> getBlocksEntriesPairedToChunk(Chun
return reducedMap;
}

public Map<Block, Pair<ItemStack, ItemStack>> getClickableBlocks() {
public Map<Block, PairTuple<ItemStack, ItemStack>> getClickableBlocks() {
return this.clickableBlocks;
}

@Override
public ItemStack getBookOfBlock(Block block, Side side) {
Pair<ItemStack, ItemStack> pairBook = clickableBlocks.get(block);
PairTuple<ItemStack, ItemStack> pairBook = clickableBlocks.get(block);
if (pairBook == null)
return null;
return switch (side) {
case LEFT -> pairBook.getFirstValue();
case RIGHT -> pairBook.getSecondValue();
case LEFT -> pairBook.firstValue();
case RIGHT -> pairBook.secondValue();
};
}

Expand Down Expand Up @@ -230,14 +230,14 @@ public void removeBookOfBlock(Block block, Side side) {
}
switch (side) {
case LEFT -> {
Pair<ItemStack, ItemStack> pair = clickableBlocks.remove(block);
if (pair == null || pair.getSecondValue() == null) break;
clickableBlocks.put(block, Pair.of(null, pair.getSecondValue()));
PairTuple<ItemStack, ItemStack> pair = clickableBlocks.remove(block);
if (pair == null || pair.secondValue() == null) break;
clickableBlocks.put(block, new PairTuple<>(null, pair.secondValue()));
}
case RIGHT -> {
Pair<ItemStack, ItemStack> pair = clickableBlocks.remove(block);
if (pair == null || pair.getFirstValue() == null) break;
clickableBlocks.put(block, Pair.of(pair.getFirstValue(), null));
PairTuple<ItemStack, ItemStack> pair = clickableBlocks.remove(block);
if (pair == null || pair.firstValue() == null) break;
clickableBlocks.put(block, new PairTuple<>(pair.firstValue(), null));
}
}
}
Expand All @@ -259,12 +259,12 @@ public void putBookOnEntity(Entity entity, ItemStack book, Side side) {
public void putBookOnBlock(Block block, ItemStack book, Side side) {
switch (side) {
case LEFT -> {
Pair<ItemStack, ItemStack> pair = clickableBlocks.remove(block);
clickableBlocks.put(block, Pair.of(book, pair == null ? null : pair.getSecondValue()));
PairTuple<ItemStack, ItemStack> pair = clickableBlocks.remove(block);
clickableBlocks.put(block, new PairTuple<>(book, pair == null ? null : pair.secondValue()));
}
case RIGHT -> {
Pair<ItemStack, ItemStack> pair = clickableBlocks.remove(block);
clickableBlocks.put(block, Pair.of(pair == null ? null : pair.getFirstValue(), book));
PairTuple<ItemStack, ItemStack> pair = clickableBlocks.remove(block);
clickableBlocks.put(block, new PairTuple<>(pair == null ? null : pair.firstValue(), book));
}
}
this.blocksPairedToChunk.computeIfAbsent(block.getChunk(), k -> new HashSet<>()).add(block);
Expand Down Expand Up @@ -502,7 +502,7 @@ public boolean hasNPCBook(int npcId, Side side) {
}


public Set<Pair<Integer, Side>> getNPCBooks() {
public Set<PairTuple<Integer, Side>> getNPCBooks() {
return this.plugin.getPluginStorage().getNPCBooks();
}

Expand Down Expand Up @@ -549,7 +549,7 @@ public boolean removeCommandFilter(String cmd) {
}

@Override
public Pair<String, String> getCommandFilter(String cmd) {
public PairTuple<String, String> getCommandFilter(String cmd) {
return this.plugin.getPluginStorage().getCommandFilter(cmd);
}

Expand All @@ -563,11 +563,11 @@ public Set<String> getCommandFilterNames() {
return this.plugin.getPluginStorage().getCommandFilterNames();
}

public LinkedList<Pair<Date, ItemStack>> getAllBookSecurity(UUID uuid, int page, int amount) {
public LinkedList<PairTuple<Date, ItemStack>> getAllBookSecurity(UUID uuid, int page, int amount) {
return this.plugin.getPluginStorage().getAllBookSecurity(uuid, page, amount);
}

public LinkedList<Triplet<UUID, Date, ItemStack>> getAllBookSecurity(int page, int amount) {
public LinkedList<TripletTuple<UUID, Date, ItemStack>> getAllBookSecurity(int page, int amount) {
return this.plugin.getPluginStorage().getAllBookSecurity(page, amount);
}

Expand Down
Loading

0 comments on commit 7d60f2c

Please sign in to comment.