Skip to content

Commit c50f968

Browse files
committed
v1.0.6-ClearAndBright
1 parent f83a3d0 commit c50f968

File tree

5 files changed

+76
-4
lines changed

5 files changed

+76
-4
lines changed

pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
<id>spigot-repo</id>
1313
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
1414
</repository>
15+
<repository>
16+
<id>dmulloy2-repo</id>
17+
<url>https://repo.dmulloy2.net/repository/public/</url>
18+
</repository>
1519
</repositories>
1620

1721
<!-- Dependencies -->
@@ -24,6 +28,11 @@
2428
<type>jar</type>
2529
<scope>provided</scope>
2630
</dependency>
31+
<dependency>
32+
<groupId>com.comphenix.protocol</groupId>
33+
<artifactId>ProtocolLib</artifactId>
34+
<version>4.7.0</version>
35+
</dependency>
2736
</dependencies>
2837

2938
<build>

src/main/java/com/github/katorly/starlinutils/StarlinUtils.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
import java.util.Map;
88
import java.util.UUID;
99

10+
import com.comphenix.protocol.ProtocolLibrary;
11+
import com.comphenix.protocol.ProtocolManager;
1012
import com.github.katorly.starlinutils.backup.ConfigReader;
1113
import com.github.katorly.starlinutils.commands.*;
12-
import com.github.katorly.starlinutils.festival.AprilFools;
14+
import com.github.katorly.starlinutils.festival.*;
1315
import com.github.katorly.starlinutils.utils.PlayTime;
1416

1517
import org.bukkit.Bukkit;
@@ -30,11 +32,13 @@ public StarlinUtils() {
3032
public Map<UUID, Long> StartTime = new HashMap<>();
3133
public static boolean serverClosing = false;
3234
public final List<NamespacedKey> recipeKeys = new ArrayList<>();
33-
35+
public static ProtocolManager cab = ProtocolLibrary.getProtocolManager();
36+
3437
@Override
3538
public void onEnable() {
36-
getServer().getPluginManager().registerEvents(new EventListener(),this);
37-
getServer().getPluginManager().registerEvents(new AprilFools(),this);
39+
getServer().getPluginManager().registerEvents(new EventListener(), this);
40+
ClearAndBright.grayChatting();
41+
// getServer().getPluginManager().registerEvents(new AprilFools(),this);
3842
config = new ConfigReader(this,"","config.yml");
3943
config.saveDefaultConfig();
4044
timedata = new ConfigReader(this, "", "timedata.yml");
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.github.katorly.starlinutils;
2+
3+
public class WrappedChatComponent {
4+
5+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.github.katorly.starlinutils.festival;
2+
3+
import java.text.SimpleDateFormat;
4+
import java.util.Objects;
5+
6+
import com.comphenix.protocol.PacketType;
7+
import com.comphenix.protocol.events.*;
8+
import com.comphenix.protocol.injector.GamePhase;
9+
import com.comphenix.protocol.wrappers.EnumWrappers;
10+
import com.comphenix.protocol.wrappers.WrappedChatComponent;
11+
import com.github.katorly.starlinutils.StarlinUtils;
12+
13+
import net.md_5.bungee.api.ChatColor;
14+
import net.md_5.bungee.api.chat.BaseComponent;
15+
import net.md_5.bungee.api.chat.TextComponent;
16+
import net.md_5.bungee.chat.ComponentSerializer;
17+
18+
public class ClearAndBright {
19+
public static boolean isToday(String date) {
20+
long t = System.currentTimeMillis();
21+
SimpleDateFormat d = new SimpleDateFormat("MM-dd");
22+
String n = d.format(t);
23+
if (Objects.equals(n, date))
24+
return true;
25+
else
26+
return false;
27+
}
28+
29+
public static void grayChatting() {
30+
StarlinUtils.cab.addPacketListener(new PacketAdapter(PacketAdapter.params().plugin(StarlinUtils.INSTANCE).serverSide().listenerPriority(ListenerPriority.NORMAL).gamePhase(GamePhase.PLAYING).optionAsync().options(ListenerOptions.SKIP_PLUGIN_VERIFIER).types(PacketType.Play.Server.CHAT)) {
31+
@Override
32+
public void onPacketSending(PacketEvent event) {
33+
if (isToday("04-05")) {
34+
PacketContainer packet = event.getPacket();
35+
PacketType packetType = event.getPacketType();
36+
if (packetType.equals(PacketType.Play.Server.CHAT)) {
37+
if (packet.getChatTypes() == null) return;
38+
if (packet.getChatTypes().getValues().get(0) != EnumWrappers.ChatType.SYSTEM) return;
39+
WrappedChatComponent warppedComponent = packet.getChatComponents().getValues().get(0);
40+
String json = warppedComponent.getJson();
41+
BaseComponent[] components = ComponentSerializer.parse(json);
42+
components = TextComponent.fromLegacyText(TextComponent.toLegacyText(components));
43+
for(BaseComponent component:components) component.setColor(ChatColor.GRAY);
44+
String newJson = ComponentSerializer.toString(components);
45+
warppedComponent.setJson(newJson);
46+
packet.getChatComponents().write(0, warppedComponent);
47+
}
48+
}
49+
}
50+
});
51+
}
52+
}

src/main/resources/plugin.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ version: 1.0.6
33
author: Katorly
44
main: com.github.katorly.starlinutils.StarlinUtils
55
api-version: 1.18
6+
softdepend:
7+
- "ProtocolLib"
68
description: A Spigot plugin made for StarlinWorld.
79
commands:
810
su:

0 commit comments

Comments
 (0)