Skip to content

Commit 0c05794

Browse files
authored
Merge pull request #932 from Ghost-chu/hikari
4.2.2.2
2 parents 70aed0c + 0c56636 commit 0c05794

File tree

115 files changed

+2309
-406
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+2309
-406
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,4 @@ buildNumber.properties
112112
# Common working directory
113113
run/
114114
/build-artifacts/
115+
/.vscode/settings.json

addon/bluemap/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>com.ghostchu</groupId>
99
<artifactId>quickshop-hikari</artifactId>
10-
<version>4.2.2.1</version>
10+
<version>4.2.2.2</version>
1111
<relativePath>../../pom.xml</relativePath>
1212
</parent>
1313
<groupId>com.ghostchu.quickshop.addon</groupId>
@@ -18,7 +18,7 @@
1818

1919
<description>Displaying the quickshops on your BlueMap instance</description>
2020
<properties>
21-
<java.version>16</java.version>
21+
<java.version>17</java.version>
2222
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2323
</properties>
2424

addon/discordsrv/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>com.ghostchu</groupId>
99
<artifactId>quickshop-hikari</artifactId>
10-
<version>4.2.2.1</version>
10+
<version>4.2.2.2</version>
1111
<relativePath>../../pom.xml</relativePath>
1212
</parent>
1313
<groupId>com.ghostchu.quickshop.addon</groupId>
@@ -18,7 +18,7 @@
1818

1919
<description>Enhance the QuickShop-Hikari with DiscordSRV</description>
2020
<properties>
21-
<java.version>16</java.version>
21+
<java.version>17</java.version>
2222
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2323
</properties>
2424

addon/discordsrv/src/main/java/com/ghostchu/quickshop/addon/discordsrv/Main.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ public void onEnable() {
7171
Bukkit.getPluginManager().disablePlugin(this);
7272
return;
7373
}
74-
plugin.getCommandManager().registerCmd(CommandContainer.builder().permission("quickshopaddon.discord.use").description((locale) -> plugin.text().of("addon.discord.commands.discord.description").forLocale(locale)).prefix("discord").executor(new SubCommand_Discord(plugin, this)).build());
74+
plugin.getCommandManager().registerCmd(CommandContainer.builder()
75+
.permission("quickshopaddon.discord.use")
76+
.description((locale) -> plugin.text().of("addon.discord.commands.discord.description")
77+
.forLocale(locale)).prefix("discord").executor(new SubCommand_Discord(plugin, this)).build());
7578
Bukkit.getPluginManager().registerEvents(this, this);
7679
Bukkit.getPluginManager().registerEvents(new QuickShopEventListener(this), this);
7780
}

addon/discordsrv/src/main/java/com/ghostchu/quickshop/addon/discordsrv/database/DiscordDatabaseHelper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ public DiscordDatabaseHelper(@NotNull Main plugin, @NotNull SQLManager sqlManage
4242
} else {
4343
settings.getSettings().put(feature, status);
4444
}
45-
try (ResultSet set = DiscordTables.DISCORD_PLAYERS.createQuery()
45+
try (SQLQuery query = DiscordTables.DISCORD_PLAYERS.createQuery()
4646
.setLimit(1)
4747
.addCondition("player", uuid.toString())
48-
.build().execute().getResultSet()) {
48+
.build().execute();
49+
ResultSet set = query.getResultSet()) {
4950
if (set.next()) {
5051
return DiscordTables.DISCORD_PLAYERS.createUpdate()
5152
.setLimit(1)

addon/discordsrv/src/main/resources/plugin.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@ depend:
77
- DiscordSRV
88
authors: [ Ghost_chu ]
99
#libraries:
10-
# - net.dv8tion:JDA:4.4.0_352.fix-2
10+
# - net.dv8tion:JDA:4.4.0_352.fix-2
11+
permissions:
12+
quickshopaddon.discord.use:
13+
description: Allows players to use discord commands
14+
default: true

addon/discount/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>com.ghostchu</groupId>
99
<artifactId>quickshop-hikari</artifactId>
10-
<version>4.2.2.1</version>
10+
<version>4.2.2.2</version>
1111
<relativePath>../../pom.xml</relativePath>
1212
</parent>
1313
<groupId>com.ghostchu.quickshop.addon</groupId>
@@ -18,7 +18,7 @@
1818

1919
<description>Add discount code to your QuickShop-Hikari server</description>
2020
<properties>
21-
<java.version>16</java.version>
21+
<java.version>17</java.version>
2222
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2323
</properties>
2424

addon/displaycontrol/pom.xml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns="http://maven.apache.org/POM/4.0.0"
5+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
6+
<modelVersion>4.0.0</modelVersion>
7+
<parent>
8+
<groupId>com.ghostchu</groupId>
9+
<artifactId>quickshop-hikari</artifactId>
10+
<version>4.2.2.2</version>
11+
<relativePath>../../pom.xml</relativePath>
12+
</parent>
13+
<groupId>com.ghostchu.quickshop.addon</groupId>
14+
<artifactId>displaycontrol</artifactId>
15+
<packaging>jar</packaging>
16+
17+
<name>Addon-DisplayControl</name>
18+
19+
<description>Allow clients toggle the virtual display items status</description>
20+
<properties>
21+
<java.version>17</java.version>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
</properties>
24+
25+
<repositories>
26+
<repository>
27+
<id>dv8tion</id>
28+
<name>m2-dv8tion</name>
29+
<url>https://m2.dv8tion.net/releases</url>
30+
</repository>
31+
<repository>
32+
<id>Scarsz-Nexus</id>
33+
<url>https://nexus.scarsz.me/content/groups/public/</url>
34+
</repository>
35+
</repositories>
36+
37+
<build>
38+
<plugins>
39+
<plugin>
40+
<groupId>org.apache.maven.plugins</groupId>
41+
<artifactId>maven-compiler-plugin</artifactId>
42+
</plugin>
43+
44+
<plugin>
45+
<groupId>org.apache.maven.plugins</groupId>
46+
<artifactId>maven-shade-plugin</artifactId>
47+
</plugin>
48+
</plugins>
49+
<resources>
50+
<resource>
51+
<directory>src/main/resources</directory>
52+
<filtering>true</filtering>
53+
</resource>
54+
</resources>
55+
</build>
56+
57+
58+
<dependencies>
59+
<dependency>
60+
<groupId>org.spigotmc</groupId>
61+
<artifactId>spigot-api</artifactId>
62+
</dependency>
63+
<dependency>
64+
<groupId>com.ghostchu</groupId>
65+
<artifactId>quickshop-bukkit</artifactId>
66+
<version>${parent.version}</version>
67+
<scope>provided</scope>
68+
</dependency>
69+
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
70+
<dependency>
71+
<groupId>org.apache.commons</groupId>
72+
<artifactId>commons-lang3</artifactId>
73+
<version>3.12.0</version>
74+
<scope>provided</scope>
75+
</dependency>
76+
<!-- <dependency>-->
77+
<!-- <groupId>net.kyori</groupId>-->
78+
<!-- <artifactId>adventure-text-serializer-plain</artifactId>-->
79+
<!-- <version>4.12.0</version>-->
80+
<!-- <scope>provided</scope>-->
81+
<!-- </dependency>-->
82+
</dependencies>
83+
</project>
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
package com.ghostchu.quickshop.addon.displaycontrol;
2+
3+
import com.ghostchu.quickshop.QuickShop;
4+
import com.ghostchu.quickshop.addon.displaycontrol.bean.ClientType;
5+
import com.ghostchu.quickshop.addon.displaycontrol.bean.DisplayOption;
6+
import com.ghostchu.quickshop.addon.displaycontrol.command.SubCommand_DisplayControl;
7+
import com.ghostchu.quickshop.addon.displaycontrol.database.DisplayControlDatabaseHelper;
8+
import com.ghostchu.quickshop.api.command.CommandContainer;
9+
import com.ghostchu.quickshop.api.event.DisplayApplicableCheckEvent;
10+
import com.ghostchu.quickshop.util.PackageUtil;
11+
import com.ghostchu.quickshop.util.Util;
12+
import com.ghostchu.quickshop.util.logger.Log;
13+
import com.google.common.io.ByteArrayDataInput;
14+
import com.google.common.io.ByteStreams;
15+
import org.bukkit.Bukkit;
16+
import org.bukkit.entity.Player;
17+
import org.bukkit.event.EventHandler;
18+
import org.bukkit.event.EventPriority;
19+
import org.bukkit.event.HandlerList;
20+
import org.bukkit.event.Listener;
21+
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
22+
import org.bukkit.event.player.PlayerQuitEvent;
23+
import org.bukkit.plugin.Plugin;
24+
import org.bukkit.plugin.java.JavaPlugin;
25+
import org.bukkit.plugin.messaging.PluginMessageListener;
26+
import org.jetbrains.annotations.NotNull;
27+
28+
import java.sql.SQLException;
29+
import java.util.Map;
30+
import java.util.UUID;
31+
import java.util.concurrent.ConcurrentHashMap;
32+
import java.util.logging.Level;
33+
34+
public final class Main extends JavaPlugin implements Listener, PluginMessageListener {
35+
private static final String BUNGEE_CHANNEL = "quickshopcompat:bcgeyser";
36+
private static final String RESPONSE_PREFIX = "CLIENTTYPE";
37+
static Main instance;
38+
private final Map<UUID, ClientType> playerClientMapping = new ConcurrentHashMap<>();
39+
private final Map<UUID, DisplayOption> playerDisplayStatus = new ConcurrentHashMap<>();
40+
private QuickShop plugin;
41+
private DisplayControlDatabaseHelper databaseHelper;
42+
43+
@Override
44+
public void onLoad() {
45+
instance = this;
46+
}
47+
48+
@Override
49+
public void onDisable() {
50+
HandlerList.unregisterAll((Plugin) this);
51+
}
52+
53+
@Override
54+
public void onEnable() {
55+
saveDefaultConfig();
56+
plugin = QuickShop.getInstance();
57+
try {
58+
databaseHelper = new DisplayControlDatabaseHelper(instance, plugin.getSqlManager(), plugin.getDbPrefix());
59+
} catch (SQLException e) {
60+
getLogger().log(Level.WARNING, "Failed to init database helper", e);
61+
Bukkit.getPluginManager().disablePlugin(this);
62+
return;
63+
}
64+
Bukkit.getPluginManager().registerEvents(this, this);
65+
Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> this.playerClientMapping.entrySet().removeIf(e -> Bukkit.getPlayer(e.getKey()) == null), 60 * 20 * 60, 60 * 20 * 60);
66+
plugin.getCommandManager().registerCmd(CommandContainer.builder()
67+
.prefix("displaycontrol")
68+
.permission("quickshopaddon.displaycontrol.use")
69+
.description((locale) -> plugin.text().of("addon.displaycontrol.command.displaycontrol").forLocale(locale))
70+
.executor(new SubCommand_DisplayControl(plugin, this))
71+
.build());
72+
getLogger().info("BungeeCord: " + Util.checkIfBungee());
73+
if (Util.checkIfBungee()) {
74+
getLogger().info("Detected BungeeCord, register the BungeeCord client information forward module, you will need install Compat-BungeeCord-Geyser module to make this feature work.");
75+
Bukkit.getMessenger().registerIncomingPluginChannel
76+
(this, BUNGEE_CHANNEL, this); // we register the incoming channel
77+
}
78+
}
79+
80+
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
81+
public void playerLogin(AsyncPlayerPreLoginEvent event) {
82+
UUID uuid = event.getUniqueId();
83+
try {
84+
DisplayOption displayOption = databaseHelper.getDisplayOption(uuid);
85+
this.playerDisplayStatus.put(uuid, displayOption);
86+
} catch (SQLException e) {
87+
getLogger().log(Level.WARNING, "Failed to getting the player display status from database", e);
88+
}
89+
}
90+
91+
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
92+
public void playerQuit(PlayerQuitEvent event) {
93+
//noinspection ConstantConditions
94+
cleanup(event.getPlayer().getUniqueId());
95+
}
96+
97+
private void cleanup(UUID uuid) {
98+
this.playerDisplayStatus.remove(uuid);
99+
this.playerClientMapping.remove(uuid);
100+
}
101+
102+
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
103+
public void displaySending(DisplayApplicableCheckEvent event) {
104+
UUID uuid = event.getPlayer();
105+
DisplayOption option = this.playerDisplayStatus.getOrDefault(uuid, DisplayOption.AUTO);
106+
boolean bedrockClient = this.playerClientMapping.getOrDefault(uuid, ClientType.UNDISCOVERED).isBedrockType();
107+
if (!option.isDisplayAvailable(bedrockClient)) {
108+
event.setApplicable(false);
109+
}
110+
}
111+
112+
public DisplayControlDatabaseHelper getDatabaseHelper() {
113+
return databaseHelper;
114+
}
115+
116+
@Override
117+
public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) {
118+
if (!channel.equalsIgnoreCase(BUNGEE_CHANNEL)) return;
119+
ByteArrayDataInput in = ByteStreams.newDataInput(message);
120+
String prefix = in.readUTF();
121+
//noinspection SwitchStatementWithTooFewBranches
122+
switch (prefix) {
123+
case RESPONSE_PREFIX -> handleBungeeBedrockPlayerCallback(in);
124+
default -> getLogger().log(Level.WARNING, "Unrecognized type: " + prefix);
125+
}
126+
}
127+
128+
private void handleBungeeBedrockPlayerCallback(ByteArrayDataInput in) {
129+
if (!PackageUtil.parsePackageProperly("acceptBungeeCordBedrockPlayerDiscoveryCallback").asBoolean(true)) {
130+
return;
131+
}
132+
UUID uuid = UUID.fromString(in.readUTF());
133+
int responseType = in.readShort();
134+
ClientType clientType = ClientType.UNDISCOVERED;
135+
if (responseType == 0) {
136+
clientType = ClientType.JAVA_EDITION_PLAYER;
137+
}
138+
if (responseType == 1) {
139+
clientType = ClientType.BEDROCK_EDITION_PLAYER_GEYSER;
140+
}
141+
if (responseType == 2) {
142+
clientType = ClientType.BEDROCK_EDITION_PLAYER_FLOODGATE;
143+
}
144+
Log.debug("Player " + uuid + " client type check callback: " + clientType.name() + ", isBedrockClient: " + clientType.isBedrockType());
145+
if (this.playerClientMapping.getOrDefault(uuid, ClientType.UNDISCOVERED).isWaitingDiscover()) {
146+
Log.debug("[BUNGEE-CALLBACK] Discovered player " + uuid + " client type is: " + clientType.name());
147+
this.playerClientMapping.put(uuid, clientType);
148+
}
149+
}
150+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.ghostchu.quickshop.addon.displaycontrol.bean;
2+
3+
public enum ClientType {
4+
UNDISCOVERED,
5+
BEDROCK_EDITION_PLAYER_GEYSER,
6+
BEDROCK_EDITION_PLAYER_FLOODGATE,
7+
JAVA_EDITION_PLAYER;
8+
9+
public boolean isBedrockType() {
10+
return this == BEDROCK_EDITION_PLAYER_FLOODGATE || this == BEDROCK_EDITION_PLAYER_GEYSER;
11+
}
12+
13+
public boolean isWaitingDiscover() {
14+
return this == UNDISCOVERED;
15+
}
16+
}

0 commit comments

Comments
 (0)