Skip to content

Commit

Permalink
Merge pull request #37 from PXAV/development
Browse files Browse the repository at this point in the history
Changes for release 0.0.5 - "The player interaction update"
  • Loading branch information
PXAV committed Dec 30, 2020
2 parents d139862 + 00dadf2 commit d1f2d29
Show file tree
Hide file tree
Showing 54 changed files with 3,979 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -5,6 +5,7 @@
# Compilation files
*.class
target
builds

# Log files
*.log
Expand All @@ -31,4 +32,3 @@ hs_err_pid*
# Maven
dependency-reduced-pom.xml


19 changes: 19 additions & 0 deletions CHANGELOG/kelp-v0.0.5.md
@@ -0,0 +1,19 @@
# v0.0.5
> Release date: 30.12.2020
**The player interaction update**:
* Add `KelpServer` class, which serves as a kind of kelp wrapper for the `Bukkit` class:
* Broadcast messages to `KelpPlayers` (instead of bukkit players)
* Fetch all online `KelpPlayers` of the server
* You can now send centered chat messages using the `KelpPlayer` as well as the `KelpServer` class.
* Add player prompts accessible via the `KelpPlayer` class:
* `AnvilPrompt`: Use an anvil GUI to query text input from a player (default texts possible)
* `SignPrompt`: Use the sign editor to query multiple lines of text from a player (default lines are possible)
* `ChatPrompt`: Simple utility to use the chat as a method to query text input (default input not possible yet).
* Add methods to display a `boss bar` to a player (including process modification and boss bar removal)
* Add new custom event `KelpPlayerChangeSettingsEvent` that is triggered when a player changes their settings
* Fix bug that custom kelp inventory events crashed the plugin when they were actually used in an event handler
* Add `KelpPlayerLoginEvent` which is called on login of a player but after it has been initialized by kelp, so that calls to the `KelpPlayerRepository` are safe. If you want to handle logins now, it is recommended to use this event instead of the normal bukkit event.
* You can now send interactive messages to KelpPlayers. You can assign messages that are displayable when you hover over them and define events which are triggered when a player clicks on a message. You can combine unlimited components per message unlike the normal `TextComponent#addExtra` method which is wide spread across the spigot community.
* Documentation improvements in the code as well as in the GitHub wiki
* Create empty kelp sql module
4 changes: 2 additions & 2 deletions core/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.github.pxav.kelp</groupId>
<artifactId>parent</artifactId>
<version>0.0.4</version>
<version>0.0.5</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down Expand Up @@ -139,7 +139,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.14.4-R0.1-SNAPSHOT</version>
<version>1.16.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

Expand Down
82 changes: 82 additions & 0 deletions core/src/main/java/de/pxav/kelp/core/KelpServer.java
@@ -0,0 +1,82 @@
package de.pxav.kelp.core;

import com.google.common.collect.Lists;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import de.pxav.kelp.core.player.KelpPlayer;
import de.pxav.kelp.core.player.KelpPlayerRepository;
import de.pxav.kelp.core.version.KelpVersion;
import org.bukkit.Bukkit;

import java.util.Collection;

/**
* A class description goes here.
*
* @author pxav
*/
@Singleton
public class KelpServer {

private KelpPlayerRepository kelpPlayerRepository;

@Inject
public KelpServer(KelpPlayerRepository kelpPlayerRepository) {
this.kelpPlayerRepository = kelpPlayerRepository;
}

public KelpVersion getVersion() {
return KelpVersion.withBukkitVersion(Bukkit.getBukkitVersion());
}

public Collection<KelpPlayer> getOnlinePlayers() {
Collection<KelpPlayer> output = Lists.newArrayList();
Bukkit.getOnlinePlayers().forEach(current -> output.add(kelpPlayerRepository.getKelpPlayer(current)));
return output;
}

public int getMaxPlayers() {
return Bukkit.getMaxPlayers();
}

public void broadcastMessage(String message) {
Bukkit.getOnlinePlayers().forEach(current -> current.sendMessage(message));
}

public void broadcastCenteredMessage(String message) {
this.getOnlinePlayers().forEach(current -> current.sendCenteredMessage(message));
}

public void broadcastMessages(String... message) {
Bukkit.getOnlinePlayers().forEach(current -> {
for (String s : message) {
current.sendMessage(s);
}
});
}

public void broadcastCenteredMessages(String... message) {
this.getOnlinePlayers().forEach(current -> {
for (String s : message) {
current.sendCenteredMessage(s);
}
});
}

public void broadcastCenteredMessages(Collection<String> messages) {
this.getOnlinePlayers().forEach(current -> {
for (String s : messages) {
current.sendCenteredMessage(s);
}
});
}

public void broadcastMessages(Collection<String> messages) {
Bukkit.getOnlinePlayers().forEach(current -> {
for (String s : messages) {
current.sendMessage(s);
}
});
}

}
62 changes: 62 additions & 0 deletions core/src/main/java/de/pxav/kelp/core/common/StringUtils.java
Expand Up @@ -2,9 +2,11 @@

import com.google.common.collect.Lists;
import com.google.inject.Singleton;
import net.md_5.bungee.api.ChatColor;

import java.util.Collections;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;

/**
* This class contains useful methods to work with strings
Expand Down Expand Up @@ -241,6 +243,66 @@ public boolean isStyleCode(char indicator) {
return false;
}

public ChatColor getChatColor(char formattingCode) {
return isFormattingCode(formattingCode)
? ChatColor.getByChar(formattingCode)
: ChatColor.WHITE;
}

public org.bukkit.ChatColor getBukkitChatColor(char formattingCode) {
return isFormattingCode(formattingCode)
? org.bukkit.ChatColor.getByChar(formattingCode)
: org.bukkit.ChatColor.WHITE;
}

public ChatColor getChatColor(String formattingCode) {
char code = formattingCode.charAt(1);
return isFormattingCode(code) && formattingCode.charAt(0) == '§'
? ChatColor.getByChar(code)
: ChatColor.WHITE;
}

public org.bukkit.ChatColor getBukkitChatColor(String formattingCode) {
char code = formattingCode.charAt(1);
return isFormattingCode(code) && formattingCode.charAt(0) == '§'
? org.bukkit.ChatColor.getByChar(code)
: org.bukkit.ChatColor.WHITE;
}

public String endsWithColorCode(String text) {
if (text.length() < 2) {
return null;
}

String code = text.substring(text.length() - 2);
if (code.charAt(0) == '§' && isColorCode(code.charAt(1))) {
return code;
}

return null;
}

public String endsWithFormattingCode(String text) {
if (text.length() < 2) {
return null;
}

String code = text.substring(text.length() - 2);
if (code.charAt(0) == '§' && isFormattingCode(code.charAt(1))) {
return code;
}

return null;
}

public char randomColorCode() {
return colorCodes[ThreadLocalRandom.current().nextInt(colorCodes.length - 1)];
}

public char randomStyleCode() {
return styleCodes[ThreadLocalRandom.current().nextInt(colorCodes.length - 1)];
}

/**
* @param indicator The indicator of the code you want to check.
* @return {@code true} if the either a color code or a style code.
Expand Down
Expand Up @@ -20,7 +20,7 @@ public final class KelpDefaultConfiguration extends KelpConfiguration {

@Override
public void defineDefaults() {
defaultValues.add(new ConfigurationAttribute(developmentMode(), false));
add(developmentMode(), false);
}

public String developmentMode() {
Expand Down
Expand Up @@ -34,4 +34,9 @@ public boolean isAnimated() {
public HandlerList getHandlers() {
return handlers;
}

public static HandlerList getHandlerList() {
return handlers;
}

}
Expand Up @@ -35,4 +35,8 @@ public HandlerList getHandlers() {
return handlers;
}

public static HandlerList getHandlerList() {
return handlers;
}

}
Expand Up @@ -28,4 +28,9 @@ public KelpInventory getInventory() {
public HandlerList getHandlers() {
return handlers;
}

public static HandlerList getHandlerList() {
return handlers;
}

}
@@ -0,0 +1,71 @@
package de.pxav.kelp.core.event.kelpevent;

import de.pxav.kelp.core.player.KelpPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.event.player.PlayerLoginEvent;

/**
* This event is triggered on any player login. It is recommended to use this
* event instead of the normal {@link PlayerLoginEvent} as this event is used
* to handle the handshake between the client and server.
*
* If a kelp application would try to convert the {@link Player} instance into a
* {@link KelpPlayer} instance, there would be a {@link NullPointerException} as
* the player has not been registered yet. So the login event handler that creates
* the {@link KelpPlayer} instances calls this event after it has finished so that
* it is safe to use the kelp player object.
*
* All methods (except {@link #getKelpPlayer()}) are the same as those from the normal
* bukkit event, so you can look for more detailed information there.
*
* @author pxav
*/
public class KelpPlayerLoginEvent extends PlayerEvent {

// list of all event handlers listening for this event
private static final HandlerList handlers = new HandlerList();

private String hostname;
private PlayerLoginEvent.Result result;
private String message;
private KelpPlayer kelpPlayer;

public KelpPlayerLoginEvent(Player who, KelpPlayer kelpPlayer, String hostname, PlayerLoginEvent.Result result, String message) {
super(who);
this.hostname = hostname;
this.result = result;
this.message = message;
this.kelpPlayer = kelpPlayer;
}

/**
* @return The {@link KelpPlayer} instance of the player who logged in.
*/
public KelpPlayer getKelpPlayer() {
return kelpPlayer;
}

public String getHostname() {
return hostname;
}

public PlayerLoginEvent.Result getResult() {
return result;
}

public String getMessage() {
return message;
}

@Override
public HandlerList getHandlers() {
return handlers;
}

public static HandlerList getHandlerList() {
return handlers;
}

}

0 comments on commit d1f2d29

Please sign in to comment.