Skip to content

Commit

Permalink
Added new API features and creations of your own Detection
Browse files Browse the repository at this point in the history
  • Loading branch information
DoubleNico committed Jun 28, 2023
1 parent 49be95d commit b4237c6
Show file tree
Hide file tree
Showing 31 changed files with 469 additions and 158 deletions.
9 changes: 1 addition & 8 deletions HypeGradients-API/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,12 @@
<parent>
<artifactId>HypeGradients</artifactId>
<groupId>me.doublenico</groupId>
<version>1.0.5</version>
<version>1.0.6</version>
</parent>
<artifactId>HypeGradients-API</artifactId>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>com.github.PerryPlaysMC</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package me.doublenico.hypegradients.api;

import com.comphenix.protocol.wrappers.WrappedChatComponent;
import dev.perryplaysmc.dynamicconfigurations.utils.DynamicConfigurationDirectory;
import me.doublenico.hypegradients.api.detection.ChatDetectionConfiguration;
import org.bukkit.entity.Player;

public interface MessageDetection {

String getName();

String getJSON(Player player, String jsonMessage);

String getPlainMessage(Player player, String plainMessage);

WrappedChatComponent getChatComponent(Player player, WrappedChatComponent component);

boolean isEnabled(Player player, String plainMessage, String jsonMessage, WrappedChatComponent component);

ChatDetectionConfiguration chatDetectionConfiguration(Player player, DynamicConfigurationDirectory directory);


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package me.doublenico.hypegradients.api;

import java.util.ArrayList;
import java.util.List;

public class MessageDetectionManager {
private final List<MessageDetection> messageDetectionList = new ArrayList<>();

private MessageDetectionManager() {
}

public static MessageDetectionManager getInstance() {
return MessageDetectionManager.InstanceHolder.instance;
}

public List<MessageDetection> getMessageDetectionList() {
return messageDetectionList;
}

public void addMessageDetection(MessageDetection messageDetection) {
messageDetectionList.add(messageDetection);
}

public void removeMessageDetection(MessageDetection messageDetection) {
messageDetectionList.remove(messageDetection);
}

public MessageDetection getMessageDetection(String name) {
for (MessageDetection messageDetection : messageDetectionList) {
if (messageDetection.getName().equals(name))
return messageDetection;
}
return null;
}

private static final class InstanceHolder {
private static final MessageDetectionManager instance = new MessageDetectionManager();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

import org.bukkit.entity.Player;

import java.util.HashMap;
import java.util.Map;

public record AnimationCache(Player player, AnimationHandler animationHandler) {

private final static Map<String, AnimationHolder> animations = new HashMap<>();

public AnimationHolder getAnimationHolder(String animation) {
AnimationHolder animationHolder = animations.get(animation);
if (animationHolder == null) {
animationHolder = new AnimationHolder(this);
animations.put(animation, animationHolder);
}
return animationHolder;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

public class AnimationHandler {

private int currentFrame = 0;

public List<Animation> getAnimations() {
List<Animation> animations = new ArrayList<>();
IDynamicConfiguration config = ConfigurationManager.getInstance().getConfiguration("animations").getConfig();
Expand Down Expand Up @@ -38,15 +36,5 @@ public Animation getAnimation(String name) {
return null;
}

public String getNextFrame(String name) {
Animation animation = getAnimation(name);
if (animation != null) {
if (currentFrame == animation.frames().size() - 1) currentFrame = 0;
else currentFrame++;
return animation.frames().get(currentFrame);
}
return null;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package me.doublenico.hypegradients.api.animations;

public record AnimationHolder(AnimationCache animationCache) {

private static int currentFrame = 0;


public String getNextFrame(String name) {
Animation animation = animationCache.animationHandler().getAnimation(name);
if (animation != null) {
if (currentFrame == animation.frames().size() - 1) currentFrame = 0;
else currentFrame++;
return animation.frames().get(currentFrame);
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,78 @@ public record ChatDetectionValues(
boolean entity, boolean entityMetadata, boolean motd,
boolean footer, boolean header, boolean playerInfo) {

@Override
public boolean enabled() {
return enabled;
}

@Override
public boolean chat() {
return chat || enabled;
}

@Override
public boolean title() {
return title || enabled;
}

@Override
public boolean subtitle() {
return subtitle || enabled;
}

@Override
public boolean guiItem() {
return guiItem || enabled;
}

@Override
public boolean guiTitle() {
return guiTitle || enabled;
}

@Override
public boolean scoreboardTitle() {
return scoreboardTitle || enabled;
}

@Override
public boolean scoreboardLines() {
return scoreboardLines || enabled;
}

@Override
public boolean bossbar() {
return bossbar || enabled;
}

@Override
public boolean entity() {
return entity || enabled;
}

@Override
public boolean entityMetadata() {
return entityMetadata || enabled;
}

@Override
public boolean motd() {
return motd || enabled;
}

@Override
public boolean footer() {
return footer || enabled;
}

@Override
public boolean header() {
return header || enabled;
}

@Override
public boolean playerInfo() {
return playerInfo || enabled;
}
}
24 changes: 12 additions & 12 deletions HypeGradients-Build/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>HypeGradients</artifactId>
<groupId>me.doublenico</groupId>
<version>1.0.5</version>
<version>1.0.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down Expand Up @@ -76,15 +76,15 @@
<filtering>true</filtering>
</resource>
</resources>
<finalName>HypeGradients 1.0.5</finalName>
<finalName>HypeGradients 1.0.6</finalName>
</build>


<dependencies>
<dependency>
<groupId>me.doublenico</groupId>
<artifactId>HypeGradients-Dev</artifactId>
<version>1.0.5</version>
<version>1.0.6</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand All @@ -93,28 +93,28 @@
<version>2.11.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.PerryPlaysMC</groupId>
<artifactId>DynamicJson</artifactId>
<version>v2.0.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>me.lucko</groupId>
<artifactId>commodore</artifactId>
<version>2.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>3.0.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.github.PerryPlaysMC</groupId>
<artifactId>DynamicConfigurations</artifactId>
<version>1.4.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>3.0.2</version>
<groupId>com.github.PerryPlaysMC</groupId>
<artifactId>DynamicJson</artifactId>
<version>v2.0.3</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public void onEnable() {
public void onDisable() {
if (MessagePacketHandler.getPackets() != null)
MessagePacketHandler.getPackets().clear();

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.wrappers.WrappedChatComponent;
import dev.perryplaysmc.dynamicconfigurations.utils.DynamicConfigurationDirectory;
import me.doublenico.hypegradients.HypeGradients;
import me.doublenico.hypegradients.api.MessageDetection;
import me.doublenico.hypegradients.api.MessageDetectionManager;
import me.doublenico.hypegradients.api.chat.ChatGradient;
import me.doublenico.hypegradients.api.chat.ChatJson;
import me.doublenico.hypegradients.api.detection.ChatDetectionConfiguration;
Expand Down Expand Up @@ -34,11 +37,11 @@ public void onPacketSending(PacketEvent event) {
if (component == null) return;
String message = component.getJson();
String string = (new ChatJson(message)).convertToString();
ChatGradient gradient = new ChatGradient(string);
MessagePacketEvent messagePacketEvent = new MessagePacketEvent(getMessageType(), string, message, component);
Bukkit.getPluginManager().callEvent(messagePacketEvent);
message = messagePacketEvent.getJsonMessage();
string = messagePacketEvent.getPlainMessage();
ChatGradient gradient = new ChatGradient(string);
component = messagePacketEvent.getChatComponent();
if (gradient.isGradient() && getChatDetectionConfiguration().getChatDetectionValues().bossbar()) {
GradientModifyEvent gradientModifyEvent = new GradientModifyEvent(string, message, gradient.getMessage(), getMessageType());
Expand All @@ -49,6 +52,18 @@ public void onPacketSending(PacketEvent event) {
if (((HypeGradients) getPlugin()).getMetricsWrapper() == null) return;
((HypeGradients) getPlugin()).getMetricsWrapper().gradientChart();
((HypeGradients) getPlugin()).getMetricsWrapper().gradientDetectionChart("Bossbar", "Title");
} else {
for (MessageDetection messageDetection : MessageDetectionManager.getInstance().getMessageDetectionList()) {
if (!messageDetection.isEnabled(event.getPlayer(), string, message, component)) continue;
HypeGradients plugin = JavaPlugin.getPlugin(HypeGradients.class);
ChatDetectionConfiguration chatDetectionConfiguration = messageDetection.chatDetectionConfiguration(event.getPlayer(), new DynamicConfigurationDirectory(plugin, plugin.getDataFolder()));
if (!chatDetectionConfiguration.getChatDetectionValues().bossbar()) continue;
string = messageDetection.getPlainMessage(event.getPlayer(), string);
component.setJson(new ChatJson(string).convertToJson());
wrapper.setTitle(component);
}
component.setJson(new ChatJson(string).convertToJson());
wrapper.setTitle(component);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.wrappers.WrappedChatComponent;
import dev.perryplaysmc.dynamicconfigurations.utils.DynamicConfigurationDirectory;
import me.doublenico.hypegradients.HypeGradients;
import me.doublenico.hypegradients.api.MessageDetection;
import me.doublenico.hypegradients.api.MessageDetectionManager;
import me.doublenico.hypegradients.api.chat.ChatGradient;
import me.doublenico.hypegradients.api.chat.ChatJson;
import me.doublenico.hypegradients.api.detection.ChatDetectionConfiguration;
Expand Down Expand Up @@ -38,11 +41,11 @@ public void onPacketSending(PacketEvent event) {
return;
String message = component.getJson();
String string = (new ChatJson(message)).convertToString();
ChatGradient gradient = new ChatGradient(string);
MessagePacketEvent messagePacketEvent = new MessagePacketEvent(getMessageType(), string, message, component);
Bukkit.getPluginManager().callEvent(messagePacketEvent);
message = messagePacketEvent.getJsonMessage();
string = messagePacketEvent.getPlainMessage();
ChatGradient gradient = new ChatGradient(string);
component = messagePacketEvent.getChatComponent();
if (gradient.isGradient() && getChatDetectionConfiguration().getChatDetectionValues().chat()) {
GradientModifyEvent gradientModifyEvent = new GradientModifyEvent(string, message, gradient.getMessage(), getMessageType());
Expand All @@ -53,6 +56,18 @@ public void onPacketSending(PacketEvent event) {
if (((HypeGradients) getPlugin()).getMetricsWrapper() == null) return;
((HypeGradients) getPlugin()).getMetricsWrapper().gradientChart();
((HypeGradients) getPlugin()).getMetricsWrapper().gradientDetectionChart("Chat", "Chat");
} else {
for (MessageDetection messageDetection : MessageDetectionManager.getInstance().getMessageDetectionList()) {
if (!messageDetection.isEnabled(event.getPlayer(), string, message, component)) continue;
HypeGradients plugin = JavaPlugin.getPlugin(HypeGradients.class);
ChatDetectionConfiguration chatDetectionConfiguration = messageDetection.chatDetectionConfiguration(event.getPlayer(), new DynamicConfigurationDirectory(plugin, plugin.getDataFolder()));
if (!chatDetectionConfiguration.getChatDetectionValues().chat()) continue;
string = messageDetection.getPlainMessage(event.getPlayer(), string);
component.setJson(new ChatJson(string).convertToJson());
wrapper.setMessage(component);
}
component.setJson(new ChatJson(string).convertToJson());
wrapper.setMessage(component);
}
}
}
Loading

0 comments on commit b4237c6

Please sign in to comment.