Skip to content

Commit

Permalink
Merge pull request #13 from petulikan1/main
Browse files Browse the repository at this point in the history
Code quality + simplified building
  • Loading branch information
TheDevTec authored Aug 11, 2024
2 parents 3b6318f + cabe3e7 commit a102cb3
Show file tree
Hide file tree
Showing 22 changed files with 206 additions and 310 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ target/
qodana.yaml
.paper-nms/
*.tiny
.idea/material_theme_project_new.xml

### Eclipse ###
.apt_generated
Expand Down
10 changes: 10 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions .idea/runConfigurations/TheAPI__package_.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Loader - Bukkit/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@
<version>12.9.7</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.34</version>
<scope>provided</scope>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
6 changes: 6 additions & 0 deletions Loader - Bukkit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
<version>33.2.1-jre</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.34</version>
<scope>provided</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.bukkit.World;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -71,7 +72,7 @@ public ImplementableJar(File file) throws IOException {
}

@Override
public Enumeration<JarEntry> entries() {
public @NotNull Enumeration<JarEntry> entries() {
List<Enumeration<JarEntry>> totalEntries = new ArrayList<>();
totalEntries.add(super.entries());
for (JarFile search : file)
Expand Down Expand Up @@ -512,8 +513,8 @@ public Object read(Map<String, Object> map) {
public Map<String, Object> write(Object object) {
Map<String, Object> map = new HashMap<>();
Position pos = (Position) object;
map.put("classType", "Position");
map.put("world", pos.getWorldName());
map.put("classType", "org.bukkit.Location");
map.put("world", pos.getWorld().getName());
map.put("x", pos.getX());
map.put("y", pos.getY());
map.put("z", pos.getZ());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;

import javax.tools.ToolProvider;
import java.io.File;
Expand Down Expand Up @@ -400,60 +401,33 @@ public String apply(String text, UUID player) {
return me.clip.placeholderapi.PlaceholderAPI.setPlaceholders(player == null ? null : Bukkit.getOfflinePlayer(player), "%" + text + "%");
}
};
for (PlaceholderExpansion exp : PlaceholderAPI.getPlaceholders())
((me.clip.placeholderapi.expansion.PlaceholderExpansion) exp.setPapiInstance(new me.clip.placeholderapi.expansion.PlaceholderExpansion() {
@Override
public String onRequest(OfflinePlayer player, String params) {
return exp.apply(params, player == null ? null : player.getUniqueId());
}

@Override
public String getName() {
return exp.getName();
}

@Override
public String getIdentifier() {
return exp.getName().toLowerCase();
}

@Override
public String getAuthor() {
return "(Unknown) TheAPI Provided Placeholder";
}

@Override
public String getVersion() {
return BukkitLoader.this.getDescription().getVersion();
}
}).getPapiInstance()).register();
PlaceholderAPI.unregisterConsumer = exp -> ((me.clip.placeholderapi.expansion.PlaceholderExpansion) exp.getPapiInstance()).unregister();
PlaceholderAPI.registerConsumer = exp -> ((me.clip.placeholderapi.expansion.PlaceholderExpansion) exp.setPapiInstance(new me.clip.placeholderapi.expansion.PlaceholderExpansion() {
@Override
public String onRequest(OfflinePlayer player, String params) {
public String onRequest(OfflinePlayer player, @NotNull String params) {
return exp.apply(params, player == null ? null : player.getUniqueId());
}

@Override
public String getName() {
public @NotNull String getName() {
return exp.getName();
}

@Override
public String getIdentifier() {
public @NotNull String getIdentifier() {
return exp.getName().toLowerCase();
}

@Override
public String getAuthor() {
public @NotNull String getAuthor() {
return "(Unknown) TheAPI Provided Placeholder";
}

@Override
public String getVersion() {
public @NotNull String getVersion() {
return BukkitLoader.this.getDescription().getVersion();
}
}).getPapiInstance()).register();
PlaceholderAPI.unregisterConsumer = exp -> ((me.clip.placeholderapi.expansion.PlaceholderExpansion) exp.getPapiInstance()).unregister();
}

// Command to reload NmsProvider
Expand Down Expand Up @@ -517,13 +491,8 @@ private void checkForUpdateAndDownloadCompiled() {
serverVersion = 'v' + serverVersion;
try {
Config gitVersion = Config.loadFromInput(new URL("https://raw.githubusercontent.com/TheDevTec/TheAPI/main/version.yml").openStream());

Config localVersion = new Config("plugins/TheAPI/version.yml");

localVersion.setIfAbsent("build", 1);
localVersion.setComments("build", Arrays.asList("# DO NOT MODIFY THIS VALUE"));

Version ver = VersionUtils.getVersion(gitVersion.getString("release"), "" + release);
Version ver = getGitVersion(localVersion, gitVersion);

if (ver != Version.OLDER_VERSION && ver != Version.SAME_VERSION && new File("plugins/TheAPI/NmsProviders/" + serverVersion + ".jar").exists()) {
Bukkit.getConsoleSender().sendMessage("[TheAPI NmsProvider Updater] §cERROR! Can't download new NmsProvider, please update TheAPI.");
Expand All @@ -544,19 +513,20 @@ private void checkForUpdateAndDownloadCompiled() {
}
}

private Version getGitVersion(Config localVersion, Config gitVersion) {
localVersion.setIfAbsent("build", 1);
localVersion.setComments("build", Collections.singletonList("# DO NOT MODIFY THIS VALUE"));
return VersionUtils.getVersion(gitVersion.getString("release"), "" + release);
}

private void checkForUpdateAndDownload() {
String serverVersion = Ref.serverVersion().replace('.', '_');
if (!serverVersion.startsWith("v"))
serverVersion = 'v' + serverVersion;
try {
Config gitVersion = Config.loadFromInput(new URL("https://raw.githubusercontent.com/TheDevTec/TheAPI/main/version.yml").openStream());

Config localVersion = new Config("plugins/TheAPI/version.yml");

localVersion.setIfAbsent("build", 1);
localVersion.setComments("build", Arrays.asList("# DO NOT MODIFY THIS VALUE"));

Version ver = VersionUtils.getVersion(gitVersion.getString("release"), "" + release);
Version ver = getGitVersion(localVersion, gitVersion);

if (ver != Version.OLDER_VERSION && ver != Version.SAME_VERSION && new File("plugins/TheAPI/NmsProviders/" + serverVersion + ".java").exists()) {
Bukkit.getConsoleSender().sendMessage("[TheAPI NmsProvider Updater] §cERROR! Can't download new NmsProvider, please update TheAPI.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.devtec.theapi.bukkit.bossbar;

import lombok.Getter;
import me.devtec.shared.Ref;
import me.devtec.shared.scheduler.Tasker;
import me.devtec.shared.utility.ColorUtils;
Expand Down Expand Up @@ -29,9 +30,12 @@ public class BossBar {

private final Player holder;
private World before;
@Getter
private boolean hidden;

@Getter
private String title;
@Getter
private double progress;

private Object entityBar;
Expand Down Expand Up @@ -85,18 +89,6 @@ public void move() {
BukkitLoader.getPacketHandler().send(holder, packet);
}

public boolean isHidden() {
return hidden;
}

public double getProgress() {
return progress;
}

public String getTitle() {
return title;
}

public void hide() {
if (hidden)
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package me.devtec.theapi.bukkit.commands.hooker;

import lombok.Getter;
import me.devtec.shared.commands.holder.CommandHolder;
import org.bukkit.command.*;
import org.bukkit.plugin.Plugin;

import javax.annotation.CheckForNull;
import java.util.List;

public class CustomPluginCommand extends Command implements PluginIdentifiableCommand {

private final Plugin owningPlugin;
@Getter
private CommandExecutor executor;
private TabCompleter completer;
@Getter
private final CommandHolder<?> commandHolder;

protected CustomPluginCommand(String name, Plugin owner, CommandHolder<?> commandHolder) {
Expand Down Expand Up @@ -48,10 +50,6 @@ public void setExecutor(CommandExecutor executor) {
this.executor = executor == null ? owningPlugin : executor;
}

public CommandExecutor getExecutor() {
return executor;
}

public void setTabCompleter(TabCompleter completer) {
this.completer = completer;
}
Expand All @@ -65,10 +63,6 @@ public Plugin getPlugin() {
return owningPlugin;
}

public CommandHolder<?> getCommandHolder() {
return commandHolder;
}

@Override
public boolean testPermissionSilent(CommandSender target) {
if (commandHolder != null && !commandHolder.getStructure().getSenderClass().isAssignableFrom(target.getClass()))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package me.devtec.theapi.bukkit.events;

import lombok.Getter;
import lombok.Setter;
import me.devtec.shared.events.Cancellable;
import me.devtec.shared.events.Event;
import me.devtec.shared.events.ListenerHolder;
Expand All @@ -15,11 +17,21 @@ public class ServerListPingEvent extends Event implements Cancellable {
private boolean cancel;
private int online;
private int max;
@Setter
@Getter
private int protocol;
@Getter
private List<GameProfileHandler> slots;
@Setter
@Getter
private String motd;
@Setter
@Getter
private String favicon;
@Setter
@Getter
private String version;
@Getter
private final InetAddress address;

public ServerListPingEvent(int online, int max, List<GameProfileHandler> slots, String motd, String favicon, InetAddress inetAddress, String ver, int protocol) {
Expand All @@ -33,26 +45,6 @@ public ServerListPingEvent(int online, int max, List<GameProfileHandler> slots,
version = ver;
}

public String getVersion() {
return version;
}

public void setVersion(String ver) {
version = ver;
}

public int getProtocol() {
return protocol;
}

public void setProtocol(int protocol) {
this.protocol = protocol;
}

public InetAddress getAddress() {
return address;
}

public int getOnlinePlayers() {
return online;
}
Expand All @@ -69,30 +61,10 @@ public void setMaxPlayers(int max) {
this.max = max;
}

public List<GameProfileHandler> getSlots() {
return slots;
}

public void setPlayersText(List<GameProfileHandler> slots) {
this.slots = slots;
}

public String getMotd() {
return motd;
}

public void setMotd(String motd) {
this.motd = motd;
}

public String getFavicon() {
return favicon;
}

public void setFavicon(String falvicon) {
favicon = falvicon;
}

@Override
public boolean isCancelled() {
return cancel;
Expand Down
Loading

0 comments on commit a102cb3

Please sign in to comment.