Skip to content

Commit

Permalink
Merge pull request #536 from FireML/fixes
Browse files Browse the repository at this point in the history
Fixes various things
  • Loading branch information
sarhatabaot authored Jan 16, 2025
2 parents 1f559ab + 7f163a1 commit 0d9310c
Show file tree
Hide file tree
Showing 17 changed files with 80 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,10 @@ public String formatColours(@NotNull String message) {

try {
// Parse MiniMessage
LegacyComponentSerializer legacyAmpersandSerializer = LegacyComponentSerializer.builder()
.hexColors()
.useUnusualXRepeatedCharacterHexFormat()
.build();
Component component = MiniMessage.builder().strict(true).build().deserialize(message);
Component component = miniMessage.deserialize(message);
// Get legacy color codes from MiniMessage
message = legacyAmpersandSerializer.serialize(component);
} catch (ParsingException exception) {
// Ignore. If MiniMessage throws an exception, we'll only use legacy colors.
}
message = legacySerializer.serialize(component);
} catch (ParsingException exception) { /* Ignore. If MiniMessage throws an exception, we'll only use legacy colors. */ }

char COLOR_CHAR = '§';
Matcher matcher = HEX_PATTERN.matcher(message);
Expand Down
19 changes: 9 additions & 10 deletions even-more-fish-plugin/src/main/java/com/oheers/fish/FishUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static boolean isFish(Skull skull) {
return NbtUtils.hasKey(skull, NbtKeys.EMF_FISH_NAME);
}

public static Fish getFish(ItemStack item) {
public static @Nullable Fish getFish(ItemStack item) {
// all appropriate null checks can be safely assumed to have passed to get to a point where we're running this method.

String nameString = NbtUtils.getString(item, NbtKeys.EMF_FISH_NAME);
Expand Down Expand Up @@ -102,7 +102,7 @@ public static Fish getFish(ItemStack item) {
return finalFish;
}

public static Fish getFish(Skull skull, Player fisher) throws InvalidFishException {
public static @Nullable Fish getFish(Skull skull, Player fisher) throws InvalidFishException {
// all appropriate null checks can be safely assumed to have passed to get to a point where we're running this method.
final String nameString = NBT.getPersistentData(skull, nbt -> nbt.getString(NbtUtils.getNamespacedKey(NbtKeys.EMF_FISH_NAME).toString()));
final String playerString = NBT.getPersistentData(skull, nbt -> nbt.getString(NbtUtils.getNamespacedKey(NbtKeys.EMF_FISH_PLAYER).toString()));
Expand Down Expand Up @@ -200,7 +200,7 @@ public static boolean checkRegion(Location l, List<String> whitelistedRegions) {
}
}

public static String getRegionName(Location location) {
public static @Nullable String getRegionName(Location location) {
if (MainConfig.getInstance().isRegionBoostsEnabled()) {
Plugin worldGuard = EvenMoreFish.getInstance().getServer().getPluginManager().getPlugin("WorldGuard");
if (worldGuard != null && worldGuard.isEnabled()) {
Expand Down Expand Up @@ -237,12 +237,12 @@ public static boolean checkWorld(Location l) {
}
}

public static String translateColorCodes(String message) {
public static @NotNull String translateColorCodes(String message) {
return EvenMoreFish.getAdapter().translateColorCodes(message);
}

//gets the item with a custom texture
public static ItemStack getSkullFromBase64(String base64EncodedString) {
public static @NotNull ItemStack getSkullFromBase64(String base64EncodedString) {
final ItemStack skull = new ItemStack(Material.PLAYER_HEAD);
UUID headUuid = UUID.randomUUID();
// 1.20.5+ handling
Expand Down Expand Up @@ -270,7 +270,7 @@ public static ItemStack getSkullFromBase64(String base64EncodedString) {
}

//gets the item with a custom uuid
public static ItemStack getSkullFromUUID(UUID uuid) {
public static @NotNull ItemStack getSkullFromUUID(UUID uuid) {
final ItemStack skull = new ItemStack(Material.PLAYER_HEAD);
// 1.20.5+ handling
if (MinecraftVersion.isNewerThan(MinecraftVersion.MC1_20_R3)) {
Expand All @@ -288,7 +288,7 @@ public static ItemStack getSkullFromUUID(UUID uuid) {
return skull;
}

public static String timeFormat(long timeLeft) {
public static @NotNull String timeFormat(long timeLeft) {
String returning = "";
long hours = timeLeft / 3600;
long minutes = (timeLeft % 3600) / 60;
Expand Down Expand Up @@ -316,7 +316,7 @@ public static String timeFormat(long timeLeft) {
return returning.trim();
}

public static String timeRaw(long timeLeft) {
public static @NotNull String timeRaw(long timeLeft) {
String returning = "";
long hours = timeLeft / 3600;

Expand All @@ -334,7 +334,6 @@ public static String timeRaw(long timeLeft) {
}

public static void broadcastFishMessage(AbstractMessage message, Player referencePlayer, boolean actionBar) {

String formatted = message.getLegacyMessage();
Competition activeComp = Competition.getCurrentlyActive();

Expand Down Expand Up @@ -394,7 +393,7 @@ public static char getCharFromString(@NotNull String string, char defaultChar) {
}
}

public static Biome getBiome(@NotNull String keyString) {
public static @Nullable Biome getBiome(@NotNull String keyString) {
// Force lowercase
keyString = keyString.toLowerCase();
// If no namespace, assume minecraft
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.logging.Level;

public class AddonManager {

private static final String ADDON_FOLDER = "addons";
private final EvenMoreFish plugin;
private final File folder;
Expand All @@ -44,7 +45,6 @@ public AddonManager(final @NotNull EvenMoreFish plugin) {
@Nullable
public ItemStack getItemStack(final String prefix, final String id) throws NoPrefixException {
if (!addonMap.containsKey(prefix)) {

if (!loadingMap.getOrDefault(prefix, true)) {
throw new NoPrefixException(prefix);
}
Expand Down Expand Up @@ -78,7 +78,6 @@ public boolean registerAddon(final @NotNull Addon addon) {
Bukkit.getPluginManager().registerEvents(listener, plugin);
}
return true;

}

public Optional<Addon> registerAddon(final @NotNull Class<? extends Addon> addon) {
Expand Down Expand Up @@ -125,7 +124,6 @@ public Addon createAddonInstance(@NotNull final Class<? extends Addon> clazz) th
if (ex.getCause() instanceof LinkageError) {
throw (LinkageError) ex.getCause();
}

plugin.getLogger().warning("There was an issue with loading an addon.");
return null;
}
Expand Down Expand Up @@ -172,7 +170,6 @@ private void registerAll() {
.map(Optional::get)
.toList();


final String message = String.format("%s new addons registered! (%s total)", registered.size(), addonMap.size());
plugin.getLogger().info(message);
});
Expand All @@ -199,4 +196,5 @@ public Map<String, Addon> getAddonMap() {
public boolean isLoading(final String prefix) {
return loadingMap.getOrDefault(prefix, true);
}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.oheers.fish.addons;

public enum DefaultAddons {
J8("8"),
J17("17")
;
J17("17"),
J21("21");

private final String targetJavaVersion;
private final String fullFileName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.bukkit.inventory.ItemStack;

public class Head64ItemAddon extends ItemAddon {

@Override
public String getPrefix() {
return "head64";
Expand All @@ -25,7 +26,7 @@ public String getAuthor() {

@Override
public ItemStack getItemStack(String id) {
if(!Base64.isBase64(id)) {
if (!Base64.isBase64(id)) {
EvenMoreFish.getInstance().getLogger().warning(() -> String.format("%s is not a valid base64 string.", id));
return null;
}
Expand All @@ -37,4 +38,5 @@ public ItemStack getItemStack(String id) {
public boolean canRegister() {
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,28 @@
import org.bukkit.block.Skull;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class EMFAPI {

public boolean isFish(ItemStack item) {
public boolean isFish(@Nullable ItemStack item) {
return FishUtils.isFish(item);
}

public boolean isFish(Skull skull) {
public boolean isFish(@Nullable Skull skull) {
return FishUtils.isFish(skull);
}

public boolean isBait(ItemStack item) {
public boolean isBait(@NotNull ItemStack item) {
return FishUtils.isBaitObject(item);
}

public Fish getFish(ItemStack item) {
public @Nullable Fish getFish(ItemStack item) {
return FishUtils.getFish(item);
}

public Fish getFish(Skull skull, Player fisher) throws InvalidFishException {
public @Nullable Fish getFish(Skull skull, Player fisher) throws InvalidFishException {
return FishUtils.getFish(skull, fisher);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ public class EMFCompetitionEndEvent extends Event {

private static final HandlerList handlers = new HandlerList();

Competition competition;
private final Competition competition;

public EMFCompetitionEndEvent(Competition competition) {
public EMFCompetitionEndEvent(@NotNull Competition competition) {
this.competition = competition;
}

Expand All @@ -27,7 +27,7 @@ public static HandlerList getHandlerList() {
/**
* @return the Competition object that has been terminated
*/
public Competition getCompetition() {
public @NotNull Competition getCompetition() {
return this.competition;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ public class EMFCompetitionStartEvent extends Event {

private static final HandlerList handlers = new HandlerList();

Competition competition;
private final Competition competition;

public EMFCompetitionStartEvent(Competition competition) {
public EMFCompetitionStartEvent(@NotNull Competition competition) {
this.competition = competition;
}

Expand All @@ -27,7 +27,7 @@ public static HandlerList getHandlerList() {
/**
* @return the Competition object that has been begun
*/
public Competition getCompetition() {
public @NotNull Competition getCompetition() {
return this.competition;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
public class EMFFishEvent extends Event implements Cancellable {

private static final HandlerList handlers = new HandlerList();
Fish fish;
Player player;
boolean cancel;
private final Fish fish;
private final Player player;
private boolean cancel;

public EMFFishEvent(Fish fish, Player player) {
public EMFFishEvent(@NotNull Fish fish, @NotNull Player player) {
this.fish = fish;
this.player = player;
}
Expand All @@ -31,14 +31,14 @@ public static HandlerList getHandlerList() {
/**
* @return The fish that the player is receiving
*/
public Fish getFish() {
public @NotNull Fish getFish() {
return fish;
}

/**
* @return The player that has fished the fish
*/
public Player getPlayer() {
public @NotNull Player getPlayer() {
return player;
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,10 @@ public static int deleteAllBaits(ItemStack itemStack) {
}

public static List<String> newApplyLore(ItemStack itemStack) {
if (itemStack.getItemMeta() == null) {
ItemMeta meta = itemStack.getItemMeta();
if (meta == null) {
return Collections.emptyList();
}
ItemMeta meta = itemStack.getItemMeta();

List<String> lore = meta.getLore();
if (lore == null) {
Expand Down Expand Up @@ -404,7 +404,7 @@ public static List<String> deleteOldLore(ItemStack itemStack) throws IndexOutOfB
}

List<String> lore = itemStack.getItemMeta().getLore();
if (lore == null) {
if (lore == null || lore.isEmpty()) {
return Collections.emptyList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ public class InvalidFishException extends Exception {
public InvalidFishException(String errorMessage) {
super(errorMessage);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ public class InvalidTableException extends Exception {
public InvalidTableException(String errorMessage) {
super(errorMessage);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@

import com.oheers.fish.baits.ApplicationResult;
import com.oheers.fish.baits.Bait;
import org.jetbrains.annotations.NotNull;

public class MaxBaitReachedException extends Exception {

ApplicationResult recoveryResult;
private final ApplicationResult recoveryResult;

public MaxBaitReachedException(Bait bait, ApplicationResult recoveryResult) {
public MaxBaitReachedException(@NotNull Bait bait, @NotNull ApplicationResult recoveryResult) {
super(bait.getName() + " has reached its maximum number of uses on the fishing rod.");
this.recoveryResult = recoveryResult;
}

/**
* @return The interrupted ApplicationResult object that would have been returned if it weren't for the error.
*/
public ApplicationResult getRecoveryResult() {
public @NotNull ApplicationResult getRecoveryResult() {
return recoveryResult;
}

}
Loading

0 comments on commit 0d9310c

Please sign in to comment.