Skip to content

Commit

Permalink
fix: more 1.20.6 issues
Browse files Browse the repository at this point in the history
update guice
  • Loading branch information
Machine-Maker committed May 21, 2024
1 parent a376996 commit 281c787
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 15 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mm-lectern = "0.3.0" # deprecated
cloud = "2.0.0-SNAPSHOT"
bstats = "3.0.2"
moonshine = "2.0.4"
guice = "5.1.0"
guice = "7.0.0"
jdbi = "3.22.0"
jackson = "2.15.2"
commons-config = "2.8.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ public CommandDispatcher from(final CommandSender sender) {
return new ConsoleCommandDispatcher(consoleCommandSender, consoleCommandSender);
} else if (sender instanceof final Player player) {
return new PlayerCommandDispatcher(player, ignored -> player);
} else {
return new FallbackCommandDispatcher(sender);
}
throw new IllegalArgumentException(sender + " is unknown");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package me.machinemaker.papertweaks.cloud.dispatchers;

import java.util.Locale;
import java.util.UUID;
import net.kyori.adventure.audience.Audience;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;

public class FallbackCommandDispatcher extends CommandDispatcher {

private final UUID uuid;

protected FallbackCommandDispatcher(final CommandSender bukkitCommandSender) {
super(bukkitCommandSender);
if (bukkitCommandSender instanceof final Entity entity) {
this.uuid = entity.getUniqueId();
} else {
this.uuid = UUID.randomUUID();
}
}

@Override
public UUID getUUID() {
return this.uuid;
}

@Override
public Locale locale() {
return Locale.US;
}

@Override
public Audience audience() {
return this.sender();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class GemVillagers extends ModuleBase {
Map<String, VillagerData> tempVillagers;
try {
tempVillagers = JSON_MAPPER.readValue(loader.getResourceAsStream("data/gem_villagers.json"), new TypeReference<Map<String, VillagerData>>() {});
} catch (final IOException e) {
} catch (final Exception e) {
tempVillagers = Collections.emptyMap();
LOGGER.error("Could not load gem villagers from data/gem_villagers.json. This module will not work properly", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class TreasureGems extends ModuleBase {
tempHeads.put(entry.getKey(), PTUtils.getSkull(GsonComponentSerializer.gson().deserialize(entry.getValue().get("name").asText()), UUID.fromString(entry.getValue().get("uuid").asText()), entry.getValue().get("texture").asText(), 1));
}

} catch (final IOException ex) {
} catch (final Exception ex) {
tempTables = Collections.emptySet();
LOGGER.error("Could not load treasure gems from data/treasure_gems/. This module will not work properly", ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class WanderingTrades extends ModuleBase {
List<Trade> tempTrades;
try {
tempTrades = JSON_MAPPER.readValue(loader.getResourceAsStream("data/wandering_trades.json"), new TypeReference<List<Trade>>() {});
} catch (final IOException e) {
} catch (final Exception e) {
LOGGER.error("Could not load wandering trades from data/wandering_trades.json. This module will not work properly", e);
tempTrades = Collections.emptyList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static Multimap<EntityType, MobHead> createMobHeadMap(final ClassLoader loader)
try {
//noinspection Convert2Diamond
heads = MAPPER.readValue(loader.getResourceAsStream("data/more_mob_heads.json"), new TypeReference<List<MobHead>>() {});
} catch (final IOException e) {
} catch (final Exception e) {
MoreMobHeads.LOGGER.error("Could not load mob heads from data/more_mob_heads.json. This module will not work properly", e);
return Multimaps.unmodifiableMultimap(ArrayListMultimap.create());
}
Expand Down
33 changes: 24 additions & 9 deletions src/main/java/me/machinemaker/papertweaks/utils/PTUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.framework.qual.DefaultQualifier;

import static net.kyori.adventure.text.Component.text;
import static net.kyori.adventure.text.Component.translatable;
import static net.kyori.adventure.text.format.TextDecoration.ITALIC;
import static net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer.plainText;

@DefaultQualifier(NonNull.class)
public final class PTUtils {
Expand Down Expand Up @@ -90,22 +93,29 @@ public static ItemStack getSkull(final Component name, final String texture) {
}

public static ItemStack getSkull(final Component name, final @Nullable UUID uuid, final String texture, final int count) {
return getSkull(name, PlainTextComponentSerializer.plainText().serialize(name), uuid, texture, count);
return getSkull(name, makeValidGameProfileName(name), uuid, texture, count);
}

public static ItemStack getSkull(final String gameProfileName, final UUID uuid, final String texture) {
return getSkull(null, gameProfileName, uuid, texture, 1);
public static ItemStack getSkull(final String stringName, final UUID uuid, final String texture) {
final String gameProfileName = makeValidGameProfileName(stringName);
final @Nullable Component name;
if (!gameProfileName.equals(stringName)) {
name = translatable("block.minecraft.player_head.named", text(stringName));
} else {
name = null; // name is valid in the gameprofile
}
return getSkull(name, gameProfileName, uuid, texture, 1);
}

public static ItemStack getSkull(final @Nullable Component name, final String gameProfileName, final @Nullable UUID uuid, final String texture, final int count) {
private static ItemStack getSkull(final @Nullable Component customName, final String gameProfileName, final @Nullable UUID uuid, final String texture, final int count) {
final ItemStack skull = new ItemStack(Material.PLAYER_HEAD, count);
if (name == null && uuid == null) {
return skull;
}
final @Nullable SkullMeta meta = (SkullMeta) Objects.requireNonNull(skull.getItemMeta());
final PlayerProfile profile = Bukkit.createProfile(uuid == null ? UUID.randomUUID() : uuid, gameProfileName);
profile.setProperty(new ProfileProperty("textures", texture));
meta.setPlayerProfile(profile);
if (customName != null) {
meta.itemName(customName);
}
skull.setItemMeta(meta);
return skull;
}
Expand All @@ -120,10 +130,15 @@ public static void sanitizeTextures(final PlayerProfile profile) {
}
}

public static void loadMeta(final ItemMeta meta, final Component displayName) {
meta.displayName(displayName);
public static String makeValidGameProfileName(final Component input) {
return makeValidGameProfileName(plainText().serialize(input));
}

public static String makeValidGameProfileName(final String input) {
return input.replace(' ', '_').substring(0, Math.min(16, input.length()));
}


public static Location toBlockLoc(final Location location) {
return new Location(location.getWorld(), location.getBlockX(), location.getBlockY(), location.getBlockZ());
}
Expand Down

0 comments on commit 281c787

Please sign in to comment.