Skip to content

Commit b44a9b2

Browse files
committed
Initial Move to Paper 1.21.6
1 parent 4ab3bbc commit b44a9b2

File tree

21 files changed

+259
-150
lines changed

21 files changed

+259
-150
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ out/
2525
build/
2626
target/
2727
*.class
28+
build-logic/.kotlin/
29+
build-logic/bin/
2830

2931
# Run directory
3032
/run/

Essentials/build.gradle

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,22 @@ dependencies {
1414
implementation 'org.checkerframework:checker-qual:3.49.0'
1515
implementation 'nu.studer:java-ordered-properties:1.0.4'
1616

17-
implementation 'net.kyori:adventure-api:4.21.0'
18-
implementation 'net.kyori:adventure-text-minimessage:4.21.0'
17+
implementation 'net.kyori:adventure-api:4.23.0'
18+
implementation 'net.kyori:adventure-text-minimessage:4.23.0'
1919
implementation 'net.kyori:adventure-platform-bukkit:4.4.0'
2020

2121
// Providers
22-
api project(':providers:BaseProviders')
23-
api project(path: ':providers:PaperProvider', configuration: 'shadow')
22+
api(project(':providers:BaseProviders')) {
23+
exclude(module: 'spigot-api')
24+
}
25+
api(project(path: ':providers:PaperProvider', configuration: 'shadow')){
26+
exclude(module: 'paper-api')
27+
}
2428
api(project(':providers:NMSReflectionProvider')) {
2529
exclude group: "org.bukkit", module: "bukkit"
2630
}
2731
api(project(':providers:1_8Provider')) {
28-
exclude group: "org.spigotmc", module: "spigot"
32+
exclude group: "org.spigotmc", module: "spigot-api"
2933
}
3034
api(project(':providers:1_12Provider')) {
3135
exclude group: "org.bukkit", module: "bukkit"

Essentials/src/main/java/com/earth2me/essentials/Essentials.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,9 @@
122122
import org.bukkit.inventory.InventoryView;
123123
import org.bukkit.plugin.InvalidDescriptionException;
124124
import org.bukkit.plugin.Plugin;
125-
import org.bukkit.plugin.PluginDescriptionFile;
126125
import org.bukkit.plugin.PluginManager;
127126
import org.bukkit.plugin.ServicePriority;
128127
import org.bukkit.plugin.java.JavaPlugin;
129-
import org.bukkit.plugin.java.JavaPluginLoader;
130128
import org.bukkit.scheduler.BukkitScheduler;
131129
import org.bukkit.scheduler.BukkitTask;
132130

@@ -187,17 +185,6 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
187185
EconomyLayers.init();
188186
}
189187

190-
public Essentials() {
191-
}
192-
193-
protected Essentials(final JavaPluginLoader loader, final PluginDescriptionFile description, final File dataFolder, final File file) {
194-
super(loader, description, dataFolder, file);
195-
}
196-
197-
public Essentials(final Server server) {
198-
super(new JavaPluginLoader(server), new PluginDescriptionFile("Essentials", "", "com.earth2me.essentials.Essentials"), null, null);
199-
}
200-
201188
@Override
202189
public ISettings getSettings() {
203190
return settings;
@@ -230,7 +217,12 @@ public void setupForTesting(final Server server) throws IOException, InvalidDesc
230217
jails = new Jails(this);
231218
registerListeners(server.getPluginManager());
232219
kits = new Kits(this);
233-
bukkitAudience = BukkitAudiences.create(this);
220+
//bukkitAudience = BukkitAudiences.create(this);
221+
}
222+
223+
public void tearDownForTesting() {
224+
//bukkitAudience.close();
225+
Economy.setEss(null);
234226
}
235227

236228
@Override
@@ -246,6 +238,10 @@ public void onLoad() {
246238

247239
@Override
248240
public void onEnable() {
241+
if (TESTING) {
242+
return;
243+
}
244+
249245
try {
250246
if (BUKKIT_LOGGER != super.getLogger()) {
251247
BUKKIT_LOGGER.setParent(super.getLogger());
@@ -554,6 +550,14 @@ public ProviderFactory getProviders() {
554550

555551
@Override
556552
public void onDisable() {
553+
if (bukkitAudience != null) {
554+
bukkitAudience.close();
555+
}
556+
557+
if (TESTING) {
558+
return;
559+
}
560+
557561
final boolean stopping = provider(ServerStateProvider.class).isStopping();
558562
if (!stopping) {
559563
LOGGER.log(Level.SEVERE, AdventureUtil.miniToLegacy(tlLiteral("serverReloading")));

Essentials/src/test/java/com/earth2me/essentials/EconomyTest.java

Lines changed: 50 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,91 +9,103 @@
99
import net.ess3.api.MaxMoneyException;
1010
import org.bukkit.command.CommandSender;
1111
import org.bukkit.plugin.InvalidDescriptionException;
12-
import org.junit.Assert;
13-
import org.junit.Test;
12+
import org.junit.jupiter.api.AfterAll;
13+
import org.junit.jupiter.api.Assertions;
14+
import org.junit.jupiter.api.BeforeAll;
15+
import org.junit.jupiter.api.Test;
16+
import org.mockbukkit.mockbukkit.MockBukkit;
17+
import org.mockbukkit.mockbukkit.ServerMock;
1418

1519
import java.io.IOException;
1620

1721
public class EconomyTest {
1822
private static final String NPCNAME = "npc1";
1923
private static final String PLAYERNAME = "testPlayer1";
2024
private static final String PLAYERNAME2 = "testPlayer2";
21-
private final transient Essentials ess;
22-
private final FakeServer server;
23-
24-
public EconomyTest() {
25-
this.server = FakeServer.getServer();
26-
ess = new Essentials(server);
25+
private static transient Essentials ess;
26+
private static ServerMock server;
27+
28+
@BeforeAll
29+
static void setUp() {
30+
server = MockBukkit.mock();
31+
Essentials.TESTING = true;
32+
ess = MockBukkit.load(Essentials.class);
2733
try {
2834
ess.setupForTesting(server);
2935
} catch (final InvalidDescriptionException ex) {
30-
Assert.fail("InvalidDescriptionException");
36+
Assertions.fail("InvalidDescriptionException");
3137
} catch (final IOException ex) {
32-
Assert.fail("IOException");
38+
Assertions.fail("IOException");
3339
}
34-
server.addPlayer(new OfflinePlayerStub(PLAYERNAME, ess.getServer()));
35-
server.addPlayer(new OfflinePlayerStub(PLAYERNAME2, ess.getServer()));
40+
server.addPlayer(PLAYERNAME);
41+
server.addPlayer(PLAYERNAME2);
42+
}
43+
44+
@AfterAll
45+
static void tearDown() {
46+
ess.tearDownForTesting();
47+
MockBukkit.unmock();
3648
}
3749

3850
// only one big test, since we use static instances
3951
@Test
4052
public void testEconomy() {
4153
// test NPC
42-
Assert.assertFalse("NPC does not exists", Economy.playerExists(NPCNAME));
43-
Assert.assertTrue("Create NPC", Economy.createNPC(NPCNAME));
44-
Assert.assertTrue("NPC exists", Economy.playerExists(NPCNAME));
45-
Assert.assertNotNull("NPC can be accessed", ess.getOfflineUser(NPCNAME));
54+
Assertions.assertFalse(Economy.playerExists(NPCNAME), "NPC does not exists");
55+
Assertions.assertTrue(Economy.createNPC(NPCNAME), "Create NPC");
56+
Assertions.assertTrue(Economy.playerExists(NPCNAME), "NPC exists");
57+
Assertions.assertNotNull(ess.getOfflineUser(NPCNAME), "NPC can be accessed");
4658
try {
4759
Economy.removeNPC(NPCNAME);
4860
} catch (final UserDoesNotExistException ex) {
49-
Assert.fail(ex.getMessage());
61+
Assertions.fail(ex.getMessage());
5062
}
51-
Assert.assertFalse("NPC can be removed", Economy.playerExists(NPCNAME));
63+
Assertions.assertFalse(Economy.playerExists(NPCNAME), "NPC can be removed");
5264

5365
//test Math
5466
try {
5567

56-
Assert.assertTrue("Player exists", Economy.playerExists(PLAYERNAME));
68+
Assertions.assertTrue(Economy.playerExists(PLAYERNAME), "Player exists");
5769
Economy.resetBalance(PLAYERNAME);
58-
Assert.assertEquals("Player has no money", 0.0, Economy.getMoney(PLAYERNAME), 0);
70+
Assertions.assertEquals(0.0, Economy.getMoney(PLAYERNAME), 0, "Player has no money");
5971
Economy.add(PLAYERNAME, 10.0);
60-
Assert.assertEquals("Add money", 10.0, Economy.getMoney(PLAYERNAME), 0);
72+
Assertions.assertEquals(10.0, Economy.getMoney(PLAYERNAME), 0, "Add money");
6173
Economy.subtract(PLAYERNAME, 5.0);
62-
Assert.assertEquals("Subtract money", 5.0, Economy.getMoney(PLAYERNAME), 0);
74+
Assertions.assertEquals(5.0, Economy.getMoney(PLAYERNAME), 0, "Subtract money");
6375
Economy.multiply(PLAYERNAME, 2.0);
64-
Assert.assertEquals("Multiply money", 10.0, Economy.getMoney(PLAYERNAME), 0);
76+
Assertions.assertEquals(10.0, Economy.getMoney(PLAYERNAME), 0, "Multiply money");
6577
Economy.divide(PLAYERNAME, 2.0);
66-
Assert.assertEquals("Divide money", 5.0, Economy.getMoney(PLAYERNAME), 0);
78+
Assertions.assertEquals(5.0, Economy.getMoney(PLAYERNAME), 0, "Divide money");
6779
Economy.setMoney(PLAYERNAME, 10.0);
68-
Assert.assertEquals("Set money", 10.0, Economy.getMoney(PLAYERNAME), 0);
80+
Assertions.assertEquals(10.0, Economy.getMoney(PLAYERNAME), 0, "Set money");
6981
} catch (final NoLoanPermittedException | UserDoesNotExistException | MaxMoneyException ex) {
70-
Assert.fail(ex.getMessage());
82+
Assertions.fail(ex.getMessage());
7183
}
7284

7385
//test Format
74-
Assert.assertEquals("Format $1,000", "$1,000", Economy.format(1000.0));
75-
Assert.assertEquals("Format $10", "$10", Economy.format(10.0));
76-
Assert.assertEquals("Format $10.10", "$10.10", Economy.format(10.10));
77-
Assert.assertEquals("Format $10.10", "$10.10", Economy.format(10.1000001));
78-
Assert.assertEquals("Format $10.10", "$10.10", Economy.format(10.1099999));
86+
Assertions.assertEquals("$1,000", Economy.format(1000.0), "Format $1,000");
87+
Assertions.assertEquals("$10", Economy.format(10.0), "Format $10");
88+
Assertions.assertEquals("$10.10", Economy.format(10.10), "Format $10.10");
89+
Assertions.assertEquals("$10.10", Economy.format(10.1000001), "Format $10.10");
90+
Assertions.assertEquals("$10.10", Economy.format(10.1099999), "Format $10.10");
7991

8092
//test Exceptions
8193
try {
82-
Assert.assertTrue("Player exists", Economy.playerExists(PLAYERNAME));
94+
Assertions.assertTrue(Economy.playerExists(PLAYERNAME), "Player exists");
8395
Economy.resetBalance(PLAYERNAME);
84-
Assert.assertEquals("Reset balance", 0.0, Economy.getMoney(PLAYERNAME), 0);
96+
Assertions.assertEquals(0.0, Economy.getMoney(PLAYERNAME), 0, "Reset balance");
8597
Economy.subtract(PLAYERNAME, 5.0);
86-
Assert.fail("Did not throw exception");
98+
Assertions.fail("Did not throw exception");
8799
} catch (final NoLoanPermittedException | MaxMoneyException ignored) {
88100
} catch (final UserDoesNotExistException ex) {
89-
Assert.fail(ex.getMessage());
101+
Assertions.fail(ex.getMessage());
90102
}
91103

92104
try {
93105
Economy.resetBalance("UnknownPlayer");
94-
Assert.fail("Did not throw exception");
106+
Assertions.fail("Did not throw exception");
95107
} catch (final NoLoanPermittedException | MaxMoneyException ex) {
96-
Assert.fail(ex.getMessage());
108+
Assertions.fail(ex.getMessage());
97109
} catch (final UserDoesNotExistException ignored) {
98110
}
99111
}
@@ -139,7 +151,7 @@ public void testNegativePayCommand() {
139151
try {
140152
runCommand("pay", user1, PLAYERNAME2 + " -123");
141153
} catch (final Exception e) {
142-
Assert.assertEquals(AdventureUtil.miniToLegacy(I18n.tlLiteral("payMustBePositive")), e.getMessage());
154+
Assertions.assertEquals(AdventureUtil.miniToLegacy(I18n.tlLiteral("payMustBePositive")), e.getMessage());
143155
}
144156
}
145157
}

Essentials/src/test/java/com/earth2me/essentials/MessagingTest.java

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,48 @@
44
import com.earth2me.essentials.commands.NoChargeException;
55
import org.bukkit.command.CommandSender;
66
import org.bukkit.plugin.InvalidDescriptionException;
7-
import org.junit.Test;
7+
import org.junit.jupiter.api.AfterEach;
8+
import org.junit.jupiter.api.BeforeEach;
9+
import org.junit.jupiter.api.Test;
10+
import org.mockbukkit.mockbukkit.MockBukkit;
11+
import org.mockbukkit.mockbukkit.ServerMock;
12+
import org.mockbukkit.mockbukkit.entity.PlayerMock;
813

914
import java.io.IOException;
1015

11-
import static org.junit.Assert.fail;
12-
import static org.junit.Assert.assertNull;
13-
import static org.junit.Assert.assertEquals;
16+
import static org.junit.jupiter.api.Assertions.assertEquals;
17+
import static org.junit.jupiter.api.Assertions.assertNull;
18+
import static org.junit.jupiter.api.Assertions.assertThrows;
19+
import static org.junit.jupiter.api.Assertions.fail;
1420

1521
public class MessagingTest {
1622

17-
private final OfflinePlayerStub base1;
18-
private final Essentials ess;
19-
private final FakeServer server;
23+
private PlayerMock base1;
24+
private Essentials ess;
25+
private ServerMock server;
2026

21-
public MessagingTest() {
22-
server = FakeServer.getServer();
23-
ess = new Essentials(server);
27+
@BeforeEach
28+
void setUp() {
29+
this.server = MockBukkit.mock();
30+
Essentials.TESTING = true;
31+
ess = MockBukkit.load(Essentials.class);
2432
try {
2533
ess.setupForTesting(server);
2634
} catch (final InvalidDescriptionException ex) {
2735
fail("InvalidDescriptionException");
2836
} catch (final IOException ex) {
2937
fail("IOException");
3038
}
31-
base1 = server.createPlayer("testPlayer1");
32-
server.addPlayer(base1);
39+
base1 = server.addPlayer("testPlayer1");
3340
ess.getUser(base1);
3441
}
3542

43+
@AfterEach
44+
void tearDown() {
45+
ess.tearDownForTesting();
46+
MockBukkit.unmock();
47+
}
48+
3649
private void runCommand(final String command, final User user, final String args) throws Exception {
3750
runCommand(command, user, args.split("\\s+"));
3851
}
@@ -68,27 +81,29 @@ private void runConsoleCommand(final String command, final String[] args) throws
6881
}
6982
}
7083

71-
@Test(expected = Exception.class) // I really don't like this, but see note below about console reply
72-
public void testNullLastMessageReplyRecipient() throws Exception {
73-
final User user1 = ess.getUser(base1);
74-
final Console console = Console.getInstance();
75-
if (ess.getSettings().isLastMessageReplyRecipient()) {
76-
assertNull(console.getReplyRecipient()); // console never messaged or received messages from anyone.
77-
84+
@Test
85+
public void testNullLastMessageReplyRecipient() {
86+
assertThrows(Exception.class, () -> {
87+
final User user1 = ess.getUser(base1);
88+
final Console console = Console.getInstance();
7889
if (ess.getSettings().isLastMessageReplyRecipient()) {
79-
runCommand("r", user1, "This is me sending you a message using /r without you replying!");
80-
}
90+
assertNull(console.getReplyRecipient()); // console never messaged or received messages from anyone.
8191

82-
// Not really much of a strict test, but just "testing" console output.
83-
user1.setAfk(true);
92+
if (ess.getSettings().isLastMessageReplyRecipient()) {
93+
runCommand("r", user1, "This is me sending you a message using /r without you replying!");
94+
}
8495

85-
// Console replies using "/r Hey, son!"
86-
//
87-
// This throws Exception because the console hasnt messaged anyone.
88-
runConsoleCommand("r", "Hey, son!");
89-
} else {
90-
throw new Exception(); // Needed to prevent build failures.
91-
}
96+
// Not really much of a strict test, but just "testing" console output.
97+
user1.setAfk(true);
98+
99+
// Console replies using "/r Hey, son!"
100+
//
101+
// This throws Exception because the console hasnt messaged anyone.
102+
runConsoleCommand("r", "Hey, son!");
103+
} else {
104+
throw new Exception(); // Needed to prevent build failures.
105+
}
106+
});
92107
}
93108

94109
@Test

0 commit comments

Comments
 (0)