Skip to content

Commit e1359fb

Browse files
committed
migrate to paper plugin
1 parent c2428b2 commit e1359fb

5 files changed

Lines changed: 96 additions & 57 deletions

File tree

pom.xml

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<name>TimeBar</name>
3030

3131
<properties>
32-
<java.version>21</java.version>
32+
<java.version>25</java.version>
3333
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3434
</properties>
3535

@@ -57,27 +57,6 @@
5757
<target>${java.version}</target>
5858
</configuration>
5959
</plugin>
60-
<plugin>
61-
<groupId>org.apache.maven.plugins</groupId>
62-
<artifactId>maven-shade-plugin</artifactId>
63-
<version>3.6.1</version>
64-
<configuration>
65-
<relocations>
66-
<relocation>
67-
<pattern>lol.hyper.hyperlib</pattern>
68-
<shadedPattern>lol.hyper.timebar.hyperlib</shadedPattern>
69-
</relocation>
70-
</relocations>
71-
</configuration>
72-
<executions>
73-
<execution>
74-
<phase>package</phase>
75-
<goals>
76-
<goal>shade</goal>
77-
</goals>
78-
</execution>
79-
</executions>
80-
</plugin>
8160
</plugins>
8261
<resources>
8362
<resource>
@@ -113,7 +92,7 @@
11392
<groupId>com.github.hyperdefined</groupId>
11493
<artifactId>hyperlib</artifactId>
11594
<version>1.0.9</version>
116-
<scope>compile</scope>
95+
<scope>provided</scope>
11796
</dependency>
11897
<dependency>
11998
<groupId>me.casperge.realisticseasons</groupId>

src/main/java/lol/hyper/timebar/TimeBar.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public final class TimeBar extends JavaPlugin {
5353

5454
public PlayerJoinLeave playerJoinLeave;
5555
public WorldChange worldChange;
56-
public CommandTimeBar commandReload;
56+
public CommandTimeBar commandTimeBar;
5757
public HyperLib hyperLib;
5858
public TextUtils textUtils;
5959

@@ -94,9 +94,9 @@ public void onEnable() {
9494
loadConfig();
9595
playerJoinLeave = new PlayerJoinLeave(this);
9696
worldChange = new WorldChange(this);
97-
commandReload = new CommandTimeBar(this);
97+
commandTimeBar = new CommandTimeBar(this);
9898

99-
this.getCommand("timebar").setExecutor(commandReload);
99+
registerCommand("timebar", commandTimeBar);
100100

101101
Bukkit.getServer().getPluginManager().registerEvents(playerJoinLeave, this);
102102
Bukkit.getServer().getPluginManager().registerEvents(worldChange, this);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* This file is part of TimeBar.
3+
*
4+
* TimeBar is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* TimeBar is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with TimeBar. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
package lol.hyper.timebar;
19+
20+
import io.papermc.paper.plugin.loader.PluginClasspathBuilder;
21+
import io.papermc.paper.plugin.loader.PluginLoader;
22+
import io.papermc.paper.plugin.loader.library.impl.MavenLibraryResolver;
23+
import org.eclipse.aether.artifact.DefaultArtifact;
24+
import org.eclipse.aether.graph.Dependency;
25+
import org.eclipse.aether.repository.RemoteRepository;
26+
27+
public class TimeBarLoader implements PluginLoader {
28+
29+
@Override
30+
public void classloader(PluginClasspathBuilder classpathBuilder) {
31+
MavenLibraryResolver resolver = new MavenLibraryResolver();
32+
33+
resolver.addRepository(new RemoteRepository.Builder("jitpack", "default", "https://jitpack.io").build());
34+
resolver.addDependency(new Dependency(new DefaultArtifact("com.github.hyperdefined:hyperlib:1.0.9"), null));
35+
36+
classpathBuilder.addLibrary(resolver);
37+
}
38+
}

src/main/java/lol/hyper/timebar/commands/CommandTimeBar.java

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,22 @@
1717

1818
package lol.hyper.timebar.commands;
1919

20+
import io.papermc.paper.command.brigadier.BasicCommand;
21+
import io.papermc.paper.command.brigadier.CommandSourceStack;
2022
import lol.hyper.timebar.TimeBar;
2123
import lol.hyper.timebar.tracker.WorldTimeTracker;
2224
import net.kyori.adventure.text.Component;
2325
import net.kyori.adventure.text.format.NamedTextColor;
2426
import org.bukkit.Bukkit;
2527
import org.bukkit.World;
26-
import org.bukkit.command.Command;
2728
import org.bukkit.command.CommandSender;
2829
import org.bukkit.command.ConsoleCommandSender;
29-
import org.bukkit.command.TabExecutor;
3030
import org.bukkit.entity.Player;
31-
import org.jetbrains.annotations.NotNull;
31+
import org.checkerframework.checker.nullness.qual.NonNull;
3232

33-
import java.util.Arrays;
34-
import java.util.List;
33+
import java.util.*;
3534

36-
public class CommandTimeBar implements TabExecutor {
35+
public class CommandTimeBar implements BasicCommand {
3736

3837
private final TimeBar timeBar;
3938

@@ -42,15 +41,11 @@ public CommandTimeBar(TimeBar timeBar) {
4241
}
4342

4443
@Override
45-
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
44+
public void execute(@NonNull CommandSourceStack source, String @NonNull [] args) {
45+
CommandSender sender = source.getSender();
4646
if (args.length == 0) {
4747
sender.sendMessage(Component.text("TimeBar version " + timeBar.getPluginMeta().getVersion() + ". Created by hyperdefined.", NamedTextColor.GREEN));
48-
return true;
49-
}
50-
51-
if (!sender.hasPermission("timebar.command")) {
52-
sender.sendMessage(Component.text("You do not have permission for this command.", NamedTextColor.RED));
53-
return true;
48+
return;
5449
}
5550

5651
switch (args[0]) {
@@ -75,20 +70,20 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
7570
} else {
7671
sender.sendMessage(Component.text("You do not have permission for this command.", NamedTextColor.RED));
7772
}
78-
return true;
73+
return;
7974
}
8075
case "on" -> {
8176
if (sender instanceof ConsoleCommandSender) {
8277
sender.sendMessage(Component.text("You must be a player for this command.", NamedTextColor.RED));
83-
return true;
78+
return;
8479
}
8580
if (!sender.hasPermission("timebar.enable")) {
8681
sender.sendMessage(Component.text("You do not have permission for this command.", NamedTextColor.RED));
87-
return true;
82+
return;
8883
}
8984
if (timeBar.config.getBoolean("hold-clock-to-show")) {
9085
sender.sendMessage(Component.text("You must be holding a clock to show/hide the TimeBar.", NamedTextColor.RED));
91-
return true;
86+
return;
9287
}
9388
Player player = (Player) sender;
9489
World world = player.getWorld();
@@ -102,20 +97,20 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
10297
timeBar.enabledBossBar.add(player);
10398
}
10499
player.sendMessage(Component.text("TimeBar is now enabled.", NamedTextColor.GREEN));
105-
return true;
100+
return;
106101
}
107102
case "off" -> {
108103
if (sender instanceof ConsoleCommandSender) {
109104
sender.sendMessage(Component.text("You must be a player for this command.", NamedTextColor.RED));
110-
return true;
105+
return;
111106
}
112107
if (!sender.hasPermission("timebar.disable")) {
113108
sender.sendMessage(Component.text("You do not have permission for this command.", NamedTextColor.RED));
114-
return true;
109+
return;
115110
}
116111
if (timeBar.config.getBoolean("hold-clock-to-show")) {
117112
sender.sendMessage(Component.text("You must be holding a clock to show/hide the TimeBar.", NamedTextColor.RED));
118-
return true;
113+
return;
119114
}
120115
Player player = (Player) sender;
121116
World world = player.getWorld();
@@ -129,15 +124,29 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
129124
timeBar.enabledBossBar.remove(player);
130125
}
131126
player.sendMessage(Component.text("TimeBar is now disabled.", NamedTextColor.GREEN));
132-
return true;
127+
return;
133128
}
134129
default -> sender.sendMessage(Component.text("Invalid sub-command. Valid options are: reload, on, off.", NamedTextColor.RED));
135130
}
136-
return true;
131+
return;
137132
}
138133

139134
@Override
140-
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String @NotNull [] args) {
141-
return Arrays.asList("reload", "on", "off");
135+
public @NonNull Collection<String> suggest(@NonNull CommandSourceStack source, String[] args) {
136+
CommandSender sender = source.getSender();
137+
if (args.length == 1) {
138+
List<String> suggestions = new ArrayList<>();
139+
if (sender.hasPermission("timebar.reload")) {
140+
suggestions.add("reload");
141+
}
142+
if (sender.hasPermission("timebar.enable")) {
143+
suggestions.add("on");
144+
}
145+
if (sender.hasPermission("timebar.disable")) {
146+
suggestions.add("off");
147+
}
148+
return suggestions;
149+
}
150+
return Collections.emptyList();
142151
}
143152
}
Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ website: https://github.com/hyperdefined/TimeBar
77
description: See the world's time as a bossbar.
88
softdepend: [Multiverse-Core, RealisticSeasons, AdvancedSeasons, PlaceholderAPI]
99
load: POSTWORLD
10-
commands:
11-
timebar:
12-
aliases: [tb]
13-
usage: /timebar
14-
permission: timebar.command
10+
11+
loader: lol.hyper.timebar.TimeBarLoader
12+
1513
permissions:
1614
timebar.command:
1715
default: true
@@ -24,4 +22,19 @@ permissions:
2422
description: Allows the usage of /timebar on.
2523
timebar.disable:
2624
default: true
27-
description: Allows the usage of /timebar off.
25+
description: Allows the usage of /timebar off.
26+
27+
dependencies:
28+
server:
29+
Multiverse-Core:
30+
load: AFTER
31+
required: false
32+
RealisticSeasons:
33+
load: AFTER
34+
required: false
35+
AdvancedSeasons:
36+
load: AFTER
37+
required: false
38+
PlaceholderAPI:
39+
load: AFTER
40+
required: false

0 commit comments

Comments
 (0)