Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	api/pom.xml
#	plugin/pom.xml
#	pom.xml
  • Loading branch information
CarmJos committed Feb 3, 2024
2 parents df0db41 + c8d74aa commit f11e299
Show file tree
Hide file tree
Showing 16 changed files with 361 additions and 141 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ README LANGUAGES [ [**English**](README.md) | [中文](README_CN.md) ]

> Great **"Residence"** all **listed** !
![LOGO](.doc/logo.png)

List existing residence in server in a gui, and allow players to manage, teleport, and comment.

<img src=".doc/logo.png" width="300px" height="300px" alt="Project logo" align="right">

## Features & Advantages

- Display all residences in a GUI!
Expand Down Expand Up @@ -118,5 +118,8 @@ The source code of this project adopts the [GNU General Public License v3.0](htt

This project is mainly developed by the [Artfrom Games](https://github.com/ArtformGames/) .

<img src="https://raw.githubusercontent.com/ArtformGames/.github/master/logo/1000pxh/COMPLETE_Reverse_Color.png" width="50%" height="50%" alt="ArtformGames Logo">

Many thanks to Jetbrains for kindly providing a license for us to work on this and other open-source projects.

[![](https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.svg)](https://www.jetbrains.com/?from=https://github.com/ArtformGames/ResidenceList)
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.artformgames</groupId>
<artifactId>residencelist-parent</artifactId>
<version>1.0.2</version>
<version>1.1.0</version>
</parent>
<properties>
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ default int countRate(Predicate<ResidenceRate> predicate) {
return (int) getRates().values().stream().filter(predicate).count();
}

default double rateRatio(Predicate<ResidenceRate> predicate) {
return getRates().isEmpty() ? 0 : (double) countRate(predicate) / getRates().size();
}

default boolean canTeleport(Player player) {
return isOwner(player) || checkPermission(player, Flags.tp, true);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.artformgames.plugin.residencelist.api.sort;

import cc.carm.lib.easyplugin.utils.ColorParser;
import com.artformgames.plugin.residencelist.ResidenceListAPI;
import com.artformgames.plugin.residencelist.api.residence.ResidenceData;
import com.artformgames.plugin.residencelist.api.residence.ResidenceRate;
import com.bekvon.bukkit.residence.protection.ClaimedResidence;

import java.util.Arrays;
import java.util.Comparator;
import java.util.function.Function;

public enum SortFunctions {

NAME(comparingData(data -> ColorParser.clear(data.getDisplayName()), String::compareToIgnoreCase)),
RATINGS(comparingData(d -> d.rateRatio(ResidenceRate::recommend), Double::compare)
.thenComparing(d -> d.countRate(ResidenceRate::recommend), Integer::compare)
.thenComparing(NAME.comparator)),
SIZE(comparingData(d -> d.getResidence().getMainArea().getSize(), Long::compare).thenComparing(NAME.comparator));

private final Comparator<ResidenceData> comparator;

SortFunctions(Comparator<ResidenceData> comparator) {
this.comparator = comparator;
}

public Comparator<ResidenceData> dataComparator(boolean reverse) {
return reverse ? comparator.reversed() : comparator;
}

public Comparator<ClaimedResidence> residenceComparator(boolean reverse) {
return Comparator.comparing(ResidenceListAPI::getResidenceData, dataComparator(reverse));
}

public SortFunctions next() {
return next(this);
}

public static <U> Comparator<ResidenceData> comparingData(Function<ResidenceData, ? extends U> keyExtractor,
Comparator<? super U> keyComparator) {
return (c1, c2) -> keyComparator.compare(keyExtractor.apply(c1), keyExtractor.apply(c2));
}

public static SortFunctions next(SortFunctions v) {
return v.ordinal() >= values().length - 1 ? values()[0] : values()[v.ordinal() + 1];
}

public static SortFunctions parse(int i) {
return Arrays.stream(values()).filter(v -> v.ordinal() == i).findFirst().orElse(NAME);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.artformgames.plugin.residencelist.api.user;

import com.artformgames.plugin.residencelist.api.sort.SortFunctions;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;

Expand All @@ -18,4 +19,13 @@ default void removePin(@NotNull String residence) {
setPin(residence, -1);
}

@NotNull SortFunctions getSortFunction();

boolean isSortReversed();

void setSortFunction(SortFunctions function);

void setSortReversed(boolean reversed);


}
4 changes: 2 additions & 2 deletions plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.artformgames</groupId>
<artifactId>residencelist-parent</artifactId>
<version>1.0.2</version>
<version>1.1.0</version>
</parent>
<properties>
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
Expand Down Expand Up @@ -102,7 +102,7 @@
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>3.0.0</version>
<version>3.0.2</version>
<scope>compile</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.artformgames.plugin.residencelist.conf;

import cc.carm.lib.configuration.core.ConfigurationRoot;
import cc.carm.lib.configuration.core.Configuration;
import cc.carm.lib.configuration.core.annotation.HeaderComment;
import cc.carm.lib.configuration.core.value.type.ConfiguredList;
import cc.carm.lib.configuration.core.value.type.ConfiguredValue;
Expand All @@ -14,46 +14,46 @@
import java.time.format.DateTimeFormatter;
import java.util.Objects;

public class PluginConfig extends ConfigurationRoot {
public interface PluginConfig extends Configuration {

public static final DateTimeFormatter DATETIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
DateTimeFormatter DATETIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

public static final ConfiguredValue<Boolean> DEBUG = ConfiguredValue.of(Boolean.class, false);
ConfiguredValue<Boolean> DEBUG = ConfiguredValue.of(Boolean.class, false);

@HeaderComment({
"Statistics Settings",
"This option is used to help developers count plug-in versions and usage, and it will never affect performance and user experience.",
"Of course, you can also choose to turn it off here for this plugin,",
"or turn it off for all plugins in the configuration file under \"plugins/bStats\"."
})
public static final ConfiguredValue<Boolean> METRICS = ConfiguredValue.of(Boolean.class, true);
ConfiguredValue<Boolean> METRICS = ConfiguredValue.of(Boolean.class, true);

@HeaderComment({
"Check update settings",
"This option is used by the plug-in to determine whether to check for updates.",
"If you do not want the plug-in to check for updates and prompt you, you can choose to close.",
"Checking for updates is an asynchronous operation that will never affect performance and user experience."
})
public static final ConfiguredValue<Boolean> CHECK_UPDATE = ConfiguredValue.of(Boolean.class, true);
ConfiguredValue<Boolean> CHECK_UPDATE = ConfiguredValue.of(Boolean.class, true);


public static final class SETTINGS extends ConfigurationRoot {
interface SETTINGS extends Configuration {

@HeaderComment("Default residence status (Public / Private)")
public static final ConfiguredValue<Boolean> DEFAULT_STATUS = ConfiguredValue.of(Boolean.class, true);
ConfiguredValue<Boolean> DEFAULT_STATUS = ConfiguredValue.of(Boolean.class, true);

public static final ConfiguredValue<Integer> LETTERS_PRE_LINE = ConfiguredValue.of(Integer.class, 35);
ConfiguredValue<Integer> LETTERS_PRE_LINE = ConfiguredValue.of(Integer.class, 35);

public static final ConfiguredList<Material> BLOCKED_ICON_TYPES = ConfiguredList.builderOf(Material.class).fromString()
ConfiguredList<Material> BLOCKED_ICON_TYPES = ConfiguredList.builderOf(Material.class).fromString()
.parseValue(s -> Objects.requireNonNull(XMaterial.matchXMaterial(s).orElseThrow().parseMaterial()))
.serializeValue(d -> XMaterial.matchXMaterial(d).name())
.defaults(Material.CHEST, Material.CHAIN, Material.REDSTONE).build();

}

public static final class ICON extends ConfigurationRoot {
interface ICON extends Configuration {

public static final ConfiguredItem INFO = ConfiguredItem.create()
ConfiguredItem INFO = ConfiguredItem.create()
.defaultType(Material.GRASS_BLOCK)
.defaultName("&7# &f%(name)")
.defaultLore(
Expand All @@ -66,9 +66,9 @@ public static final class ICON extends ConfigurationRoot {
).params("name", "owner", "members", "size", "likes", "dislikes")
.build();

public static final class RATE extends ConfigurationRoot {
interface RATE extends Configuration {

public static final ConfiguredItem LIKE = ConfiguredItem.create()
ConfiguredItem LIKE = ConfiguredItem.create()
.defaultType(Material.PLAYER_HEAD)
.defaultName("&7From &f%(owner)")
.defaultLore(
Expand All @@ -78,7 +78,7 @@ public static final class RATE extends ConfigurationRoot {
"#click-lore#{1,0}"
).params("owner", "date").build();

public static final ConfiguredItem DISLIKE = ConfiguredItem.create()
ConfiguredItem DISLIKE = ConfiguredItem.create()
.defaultType(Material.PLAYER_HEAD)
.defaultName("&7From &f%(owner)")
.defaultLore(
Expand All @@ -92,14 +92,14 @@ public static final class RATE extends ConfigurationRoot {
}


public static final ConfiguredItem EMPTY = ConfiguredItem.create()
ConfiguredItem EMPTY = ConfiguredItem.create()
.defaultType(Material.BLACK_STAINED_GLASS_PANE)
.defaultName("&7 ").build();


public static final class PAGE extends ConfigurationRoot {
interface PAGE extends Configuration {

public static final ConfiguredItem PREVIOUS_PAGE = ConfiguredItem.create()
ConfiguredItem PREVIOUS_PAGE = ConfiguredItem.create()
.defaults(Material.ARROW, "&fPrevious page")
.defaultLore(
" ",
Expand All @@ -109,15 +109,15 @@ public static final class PAGE extends ConfigurationRoot {
.build();


public static final ConfiguredItem NO_PREVIOUS_PAGE = ConfiguredItem.create()
ConfiguredItem NO_PREVIOUS_PAGE = ConfiguredItem.create()
.defaults(Material.ARROW, "&fPrevious page")
.defaultLore(
" ",
"&f There is no previous page.",
" ")
.build();

public static final ConfiguredItem NEXT_PAGE = ConfiguredItem.create()
ConfiguredItem NEXT_PAGE = ConfiguredItem.create()
.defaults(Material.ARROW, "&fNext page")
.defaultLore(
" ",
Expand All @@ -126,7 +126,7 @@ public static final class PAGE extends ConfigurationRoot {
" "
).build();

public static final ConfiguredItem NO_NEXT_PAGE = ConfiguredItem.create()
ConfiguredItem NO_NEXT_PAGE = ConfiguredItem.create()
.defaults(Material.ARROW, "&fNext page")
.defaultLore(
" ",
Expand All @@ -138,16 +138,16 @@ public static final class PAGE extends ConfigurationRoot {

}

public static final class GUI extends ConfigurationRoot {
interface GUI extends Configuration {

public static final ConfiguredSound OPEN_SOUND = ConfiguredSound.of(Sound.ENTITY_EXPERIENCE_ORB_PICKUP);
public static final ConfiguredSound CLICK_SOUND = ConfiguredSound.of(Sound.UI_BUTTON_CLICK);
ConfiguredSound OPEN_SOUND = ConfiguredSound.of(Sound.ENTITY_EXPERIENCE_ORB_PICKUP);
ConfiguredSound CLICK_SOUND = ConfiguredSound.of(Sound.UI_BUTTON_CLICK);

public static final Class<?> LIST = ResidenceListUI.CONFIG.class;
public static final Class<?> INFO = ResidenceInfoUI.CONFIG.class;
public static final Class<?> MANAGE = ResidenceManageUI.CONFIG.class;
public static final Class<?> ADMIN = ResidenceAdminUI.CONFIG.class;
public static final Class<?> SELECT = SelectIconGUI.CONFIG.class;
Class<?> LIST = ResidenceListUI.CONFIG.class;
Class<?> INFO = ResidenceInfoUI.CONFIG.class;
Class<?> MANAGE = ResidenceManageUI.CONFIG.class;
Class<?> ADMIN = ResidenceAdminUI.CONFIG.class;
Class<?> SELECT = SelectIconGUI.CONFIG.class;

}

Expand Down
Loading

0 comments on commit f11e299

Please sign in to comment.