Skip to content

Commit a738e58

Browse files
Initial 1.20 support and fix test
1 parent bc04b26 commit a738e58

File tree

5 files changed

+89
-2
lines changed

5 files changed

+89
-2
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@
628628
<dependency>
629629
<groupId>org.spigotmc</groupId>
630630
<artifactId>spigot-api</artifactId>
631-
<version>1.19.4-R0.1-SNAPSHOT</version>
631+
<version>1.20-R0.1-SNAPSHOT</version>
632632
<scope>provided</scope>
633633
</dependency>
634634
<dependency>

src/main/java/org/maxgamer/quickshop/QuickShop.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
import org.maxgamer.quickshop.listener.PlayerListener;
9292
import org.maxgamer.quickshop.listener.PluginListener;
9393
import org.maxgamer.quickshop.listener.ShopProtectionListener;
94+
import org.maxgamer.quickshop.listener.SignListener;
9495
import org.maxgamer.quickshop.listener.WorldListener;
9596
import org.maxgamer.quickshop.listener.worldedit.WorldEditAdapter;
9697
import org.maxgamer.quickshop.localization.text.SimpleTextManager;
@@ -1054,6 +1055,10 @@ public final void onEnable() {
10541055
// Register events
10551056
// Listeners (These don't)
10561057
new BlockListener(this, this.shopCache).register();
1058+
// SignChangeListener for 1.20+
1059+
if (getGameVersion().ordinal() >= GameVersion.v1_20_R1.ordinal()) {
1060+
new SignListener(this, this.shopCache).register();
1061+
}
10571062
new PlayerListener(this).register();
10581063
new WorldListener(this).register();
10591064
// Listeners - We decide which one to use at runtime
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* This file is a part of project QuickShop, the name is SignListener.java
3+
* Copyright (C) PotatoCraft Studio and contributors
4+
*
5+
* This program is free software: you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License as published by the
7+
* Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
* for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*
18+
*/
19+
20+
package org.maxgamer.quickshop.listener;
21+
22+
import org.bukkit.Location;
23+
import org.bukkit.block.Block;
24+
import org.bukkit.event.EventHandler;
25+
import org.bukkit.event.EventPriority;
26+
import org.bukkit.event.block.SignChangeEvent;
27+
import org.jetbrains.annotations.NotNull;
28+
import org.jetbrains.annotations.Nullable;
29+
import org.maxgamer.quickshop.Cache;
30+
import org.maxgamer.quickshop.QuickShop;
31+
import org.maxgamer.quickshop.api.shop.Shop;
32+
import org.maxgamer.quickshop.util.Util;
33+
34+
import java.util.Locale;
35+
36+
public class SignListener extends AbstractProtectionListener {
37+
public SignListener(@NotNull QuickShop plugin, @Nullable Cache cache) {
38+
super(plugin, cache);
39+
}
40+
41+
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
42+
public void onChangeSign(SignChangeEvent e) {
43+
Block block = e.getBlock();
44+
if (Util.isWallSign(block.getType())) {
45+
String signSideLine0 = e.getLines()[0].toLowerCase(Locale.ROOT);
46+
String locketteHeader1 = getPlugin().getConfig().getString("lockette.private", "").toLowerCase(Locale.ROOT);
47+
String locketteHeader2 = getPlugin().getConfig().getString("lockette.more_users", "").toLowerCase(Locale.ROOT);
48+
if (signSideLine0.equals(locketteHeader1) || signSideLine0.equals(locketteHeader2)) {
49+
// Ignore changes on lockette sign
50+
return;
51+
}
52+
final Shop shop = getShopNextTo(block.getLocation());
53+
if (shop != null) {
54+
Util.debugLog("Player cannot change the shop infomation sign.");
55+
e.setCancelled(true);
56+
}
57+
}
58+
}
59+
60+
/**
61+
* Gets the shop a sign is attached to
62+
*
63+
* @param loc The location of the sign
64+
* @return The shop
65+
*/
66+
@Nullable
67+
private Shop getShopNextTo(@NotNull Location loc) {
68+
final Block b = Util.getAttached(loc.getBlock());
69+
// Util.getAttached(b)
70+
if (b == null) {
71+
return null;
72+
}
73+
return getShopPlayer(b.getLocation(), false);
74+
}
75+
}

src/main/java/org/maxgamer/quickshop/util/GameVersion.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public enum GameVersion {
6666
v1_19_R1(true, false, true, true, true, true),
6767
v1_19_R2(true, false, true, true, true, true),
6868
v1_19_R3(true, false, true, true, true, true),
69+
v1_20_R1(true, false, true, true, true, true),
6970

7071
UNKNOWN(true, false, false, true, true, true);
7172
/**

src/test/java/org/maxgamer/quickshop/eventmanager/ListenerContainerTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.maxgamer.quickshop.eventmanager;
2121

2222

23+
import io.papermc.paper.plugin.configuration.PluginMeta;
2324
import org.bukkit.Server;
2425
import org.bukkit.command.Command;
2526
import org.bukkit.command.CommandSender;
@@ -49,7 +50,6 @@ public void testMatches() {
4950
public File getDataFolder() {
5051
return null;
5152
}
52-
5353
@NotNull
5454
@Override
5555
public PluginDescriptionFile getDescription() {
@@ -67,6 +67,7 @@ public FileConfiguration getConfiguration() {
6767
return null;
6868
}
6969

70+
7071
@Nullable
7172
@Override
7273
public InputStream getResource(@NotNull String s) {
@@ -164,6 +165,11 @@ public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command
164165
return false;
165166
}
166167

168+
@Override
169+
public @NotNull PluginMeta getPluginMeta() {
170+
return null;
171+
}
172+
167173
@Nullable
168174
@Override
169175
public List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {

0 commit comments

Comments
 (0)