Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to 1.16. Hex colors patterns, bug fixes etc.
- Loading branch information
Showing
47 changed files
with
1,047 additions
and
278 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>chatty</artifactId> | ||
<groupId>ru.mrbrikster</groupId> | ||
<version>2.19-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>chatty-api</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.1</version> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>3.2.2</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<createDependencyReducedPom>false</createDependencyReducedPom> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
<resources> | ||
<resource> | ||
<directory>src/main/resources</directory> | ||
<filtering>true</filtering> | ||
</resource> | ||
</resources> | ||
</build> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.spigotmc</groupId> | ||
<artifactId>spigot-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jetbrains</groupId> | ||
<artifactId>annotations</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package ru.mrbrikster.chatty.api; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import ru.mrbrikster.chatty.api.chats.Chat; | ||
|
||
import java.util.Collection; | ||
import java.util.Optional; | ||
|
||
public interface ChattyApi { | ||
|
||
/** | ||
* Returns collection of enabled chats | ||
* @return collection of enabled chats | ||
*/ | ||
@NotNull | ||
Collection<Chat> getChats(); | ||
|
||
/** | ||
* Returns chat with given name, if exists | ||
* @param name chat name | ||
* @return optional chat with given name | ||
*/ | ||
@NotNull | ||
Optional<Chat> getChat(String name); | ||
|
||
} |
144 changes: 144 additions & 0 deletions
144
api/src/main/java/ru/mrbrikster/chatty/api/chats/Chat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
package ru.mrbrikster.chatty.api.chats; | ||
|
||
import lombok.experimental.UtilityClass; | ||
import org.bukkit.World; | ||
import org.bukkit.entity.Player; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import ru.mrbrikster.chatty.json.FormattedMessage; | ||
|
||
import java.util.Collection; | ||
import java.util.function.Predicate; | ||
|
||
public interface Chat { | ||
|
||
@UtilityClass | ||
class Ranges { | ||
public final int MULTI_SERVER = -3; | ||
public final int CROSS_WORLD = -2; | ||
public final int SINGLE_WORLD = -1; | ||
|
||
/** | ||
* Checks if range is applicable to messaging between two players | ||
* @return whether range is applicable or not | ||
*/ | ||
public boolean isApplicable(@NotNull Player firstPlayer, @NotNull Player secondPlayer, int range) { | ||
if (range == CROSS_WORLD || range == MULTI_SERVER) { | ||
return true; | ||
} | ||
|
||
World firstPlayerWorld = firstPlayer.getWorld(); | ||
World secondPlayerWorld = secondPlayer.getWorld(); | ||
if (range == SINGLE_WORLD) { | ||
return firstPlayerWorld.equals(secondPlayerWorld); | ||
} | ||
|
||
if (range >= 0) { | ||
return firstPlayerWorld.equals(secondPlayerWorld) | ||
&& firstPlayer.getLocation().distanceSquared(secondPlayer.getLocation()) <= (range * range); | ||
} else { | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Name of chat from plugin configuration | ||
* @return name of chat | ||
*/ | ||
@NotNull | ||
String getName(); | ||
|
||
/** | ||
* Chat format has the following variables: | ||
* 1) {player} - player nickname | ||
* 2) {prefix}, {suffix} - prefix and suffix of player | ||
* 3) %<placeholder>% - various placeholders from PlaceholderAPI | ||
* | ||
* Also chat format supports own color formats (1.16+): | ||
* {#hexhex}text - for plain hex-colored strings | ||
* {#hexhex:#hexhex:#hexhex... text} - for gradient-colored strings | ||
* | ||
* @return chat format specified in configuration | ||
*/ | ||
@NotNull | ||
String getFormat(); | ||
|
||
/** | ||
* Range param for the chat messages | ||
* -3 is used for multi-server messaging (when "general.bungeecord" is true) | ||
* -2 is used for cross-world chats | ||
* -1 is for global single-world chats | ||
* 0 and higher for ranged local-chats | ||
* | ||
* @see Ranges#isApplicable(Player, Player, int) | ||
* | ||
* @return range value for this chat | ||
*/ | ||
int getRange(); | ||
|
||
/** | ||
* Permission requiring can be disable in configuration | ||
* If permission is enable, player must has "chatty.chat.<chat>" permission to use it | ||
* @return whether permission required or not | ||
*/ | ||
boolean isPermissionRequired(); | ||
|
||
/** | ||
* Creates collection of online players chat can see message from this chat | ||
* | ||
* @param player player who sends a message. Can be null only if chat chat range <= -2 | ||
* @return collection of chat recipients | ||
*/ | ||
@NotNull | ||
Collection<? extends Player> getRecipients(@Nullable Player player); | ||
|
||
/** | ||
* This method let you send any message to the chat participants | ||
* Message will be processed with {@link ru.mrbrikster.chatty.util.TextUtil#stylish(String)} | ||
* | ||
* Messages supports Chatty stylish formats (1.16+): | ||
* {#hexhex}text - for plain hex-colored strings | ||
* {#hexhex:#hexhex:#hexhex... text} - for gradient-colored strings | ||
* | ||
* @param message message to send | ||
*/ | ||
default void sendMessage(String message) { | ||
sendMessage(message, (player -> true)); | ||
} | ||
|
||
/** | ||
* This method let you send any message to the chat participants | ||
* Message will be processed with {@link ru.mrbrikster.chatty.util.TextUtil#stylish(String)} | ||
* | ||
* Messages supports Chatty stylish formats (1.16+): | ||
* {#hexhex}text - for plain hex-colored strings | ||
* {#hexhex:#hexhex:#hexhex... text} - for gradient-colored strings | ||
* | ||
* @param message message to send | ||
* @param playerPredicate predicate for message recipient | ||
*/ | ||
void sendMessage(String message, Predicate<Player> playerPredicate); | ||
|
||
/** | ||
* This method let you send {@link FormattedMessage} to the chat participants | ||
* {@link FormattedMessage} object let you create various JSON-formatted messages, | ||
* make hover tooltips, clickable links etc. | ||
* | ||
* @param formattedMessage message to send | ||
*/ | ||
default void sendFormattedMessage(FormattedMessage formattedMessage) { | ||
sendFormattedMessage(formattedMessage, (player -> true)); | ||
} | ||
|
||
/** | ||
* This method let you send {@link FormattedMessage} to the chat participants | ||
* {@link FormattedMessage} object let you create various JSON-formatted messages, | ||
* make hover tooltips, clickable links etc. | ||
* | ||
* @param formattedMessage message to send | ||
* @param playerPredicate predicate for message recipient | ||
*/ | ||
void sendFormattedMessage(FormattedMessage formattedMessage, Predicate<Player> playerPredicate); | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
api/src/main/java/ru/mrbrikster/chatty/api/events/ChattyMessageEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package ru.mrbrikster.chatty.api.events; | ||
|
||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.Event; | ||
import org.bukkit.event.HandlerList; | ||
import org.jetbrains.annotations.NotNull; | ||
import ru.mrbrikster.chatty.api.chats.Chat; | ||
|
||
public class ChattyMessageEvent extends Event { | ||
|
||
private static final HandlerList HANDLER_LIST = new HandlerList(); | ||
|
||
private final Player player; | ||
private final Chat chat; | ||
private final String message; | ||
|
||
public ChattyMessageEvent(@NotNull Player player, @NotNull Chat chat, @NotNull String message) { | ||
super(true); | ||
this.player = player; | ||
this.chat = chat; | ||
this.message = message; | ||
} | ||
|
||
/** | ||
* Returns the player that sends a message | ||
* @return player that sends a message | ||
*/ | ||
@NotNull | ||
public Player getPlayer() { | ||
return player; | ||
} | ||
|
||
/** | ||
* Returns the chat to which message sends | ||
* @return chat to which message sends | ||
*/ | ||
@NotNull | ||
public Chat getChat() { | ||
return chat; | ||
} | ||
|
||
/** | ||
* Returns the message typed by player | ||
* @return message typed by player | ||
*/ | ||
@NotNull | ||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
@Override | ||
@NotNull | ||
public HandlerList getHandlers() { | ||
return HANDLER_LIST; | ||
} | ||
|
||
public static HandlerList getHandlerList() { | ||
return HANDLER_LIST; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.