Skip to content

Commit

Permalink
Update to 1.16. Hex colors patterns, bug fixes etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brikster committed Jul 17, 2020
1 parent 7cfc3bb commit 81cb230
Show file tree
Hide file tree
Showing 47 changed files with 1,047 additions and 278 deletions.
35 changes: 34 additions & 1 deletion README.md
Expand Up @@ -2,9 +2,12 @@

# Chatty (Bukkit plugin)

![GitHub release (latest by date)](https://img.shields.io/github/v/release/Brikster/Chatty)
![GitHub All Releases](https://img.shields.io/github/downloads/Brikster/Chatty/total)
[![Build Status](https://travis-ci.org/Brikster/Chatty.svg?branch=master)](https://travis-ci.org/Brikster/Chatty)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/8463f0bb652842d4a5676ce4fd54f65c)](https://www.codacy.com/manual/Brikster/Chatty?utm_source=github.com&utm_medium=referral&utm_content=MrBrikster/Chatty&utm_campaign=Badge_Grade)
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/Brikster/Chatty)
[![JitPack](https://jitpack.io/v/Brikster/Chatty.svg)](https://jitpack.io/#Brikster/Chatty)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/8463f0bb652842d4a5676ce4fd54f65c)](https://www.codacy.com/manual/Brikster/Chatty?utm_source=github.com&utm_medium=referral&utm_content=MrBrikster/Chatty&utm_campaign=Badge_Grade)

Chatty is the unique Bukkit-plugin, that supports all modern Bukkit-servers, such as Thermos, Cauldron, Spigot, PaperSpigot e t.c. This plugin doesn't have any non-switchable options. It's simple, stable and lightweight.

Expand Down Expand Up @@ -49,6 +52,28 @@ Chatty is the unique Bukkit-plugin, that supports all modern Bukkit-servers, suc
| Cooldowns | - | + |
| Built-in spy-mode | - | + |
| Private messages | - | + |
| New 1.16+ hex color codes | - | + |

## Hex color codes and gradient
Chatty supports new 1.16+ color codes.
To add a new color code in your chat format, you need use the following pattern:

{#12ABCD}text

{#12ABCD} is hex code. You also can combine it with style codes:

{#ffffff}&ltext

### Gradient
You can create various multi-color gradient strings with this pattern:

{#ffffff:#0039a6:#d52b1e This is awesome tricolor gradient}

Number of hex codes is unlimited:

{#d818c4:#ae6be6:#0f7584:#7983a7:#a793ba:#34344b This is multicolor gradient}

![In-game gradient example](https://i.imgur.com/Z1iXJm8.png)

## Configuration

Expand All @@ -66,6 +91,14 @@ Plugin will work even with this simple config:
format: '{prefix}{player}{suffix}&r: {message}'
permission: false

## API

Project provides particular Maven module with API classes.

You can get access to plugin API with <b>Chatty#api()</b> method.

Now plugin has only one event in API: <b>ChattyMessageEvent</b>, that calls when any player messages the chat.

## Building

Chatty uses Apache Maven to handle dependencies & building.
Expand Down
65 changes: 65 additions & 0 deletions api/pom.xml
@@ -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>
26 changes: 26 additions & 0 deletions api/src/main/java/ru/mrbrikster/chatty/api/ChattyApi.java
@@ -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 api/src/main/java/ru/mrbrikster/chatty/api/chats/Chat.java
@@ -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);

}
@@ -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;
}

}
Expand Up @@ -96,7 +96,7 @@ private FancyMessage buildFancyMessage() {
}

fancyMessage.getMessageParts().removeIf(messagePart ->
messagePart.text.toString().isEmpty()
messagePart.text.toString().isEmpty()
);

return fancyMessage;
Expand Down
@@ -1,7 +1,7 @@
package ru.mrbrikster.chatty.json;

import org.bukkit.ChatColor;
import ru.mrbrikster.chatty.json.fanciful.FancyMessage;
import ru.mrbrikster.chatty.util.TextUtil;

import java.util.List;

Expand Down Expand Up @@ -43,7 +43,7 @@ public JSONMessagePart link(String link) {

@Override
public FancyMessage append(FancyMessage fancyMessage) {
LegacyConverter.getMessageParts(fancyMessage.getLastColors() + ChatColor.translateAlternateColorCodes('&', text)).forEach(messagePart -> {
LegacyConverter.getMessageParts(fancyMessage.getLastColors() + TextUtil.stylish(text)).forEach(messagePart -> {
fancyMessage.then(messagePart);

if (command != null)
Expand Down

0 comments on commit 81cb230

Please sign in to comment.