Skip to content

Commit

Permalink
Compatibility with Minecraft 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
PikaMug committed Jun 15, 2024
1 parent cc48f14 commit 6afb92c
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -66,8 +67,11 @@ public BukkitActionFactory(final BukkitQuestsPlugin plugin) {
this.plugin = plugin;
// Ensure to initialize factory last so that 'this' is fully initialized before it is passed
this.conversationFactory = new ConversationFactory(plugin).withModality(false).withLocalEcho(false)
.withFirstPrompt(new ActionMenuPrompt(new ConversationContext(plugin, new BukkitFakeConversable(),
new HashMap<>()))).withTimeout(3600)
.withFirstPrompt(new ActionMenuPrompt(new ConversationContext(plugin, new BukkitFakeConversable() {
@Override
public void sendRawMessage(@Nullable final UUID uuid, @NotNull final String s) {
}
}, new HashMap<>()))).withTimeout(3600)
.withPrefix(new LineBreakPrefix()).addConversationAbandonedListener(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.io.IOException;
Expand All @@ -52,8 +53,11 @@ public BukkitConditionFactory(final BukkitQuestsPlugin plugin) {
this.plugin = plugin;
// Ensure to initialize factory last so that 'this' is fully initialized before it is passed
this.conversationFactory = new ConversationFactory(plugin).withModality(false).withLocalEcho(false)
.withFirstPrompt(new ConditionMenuPrompt(new ConversationContext(plugin, new BukkitFakeConversable(),
new HashMap<>()))).withTimeout(3600)
.withFirstPrompt(new ConditionMenuPrompt(new ConversationContext(plugin, new BukkitFakeConversable() {
@Override
public void sendRawMessage(@Nullable final UUID uuid, @NotNull final String s) {
}
}, new HashMap<>()))).withTimeout(3600)
.withPrefix(new LineBreakPrefix()).addConversationAbandonedListener(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -72,8 +73,11 @@ public BukkitQuestFactory(final BukkitQuestsPlugin plugin) {
this.plugin = plugin;
// Ensure to initialize factory last so that 'this' is fully initialized before it is passed
this.conversationFactory = new ConversationFactory(plugin).withModality(false).withLocalEcho(false)
.withFirstPrompt(new QuestMenuPrompt(new ConversationContext(plugin, new BukkitFakeConversable(),
new HashMap<>()))).withTimeout(3600)
.withFirstPrompt(new QuestMenuPrompt(new ConversationContext(plugin, new BukkitFakeConversable() {
@Override
public void sendRawMessage(@Nullable final UUID uuid, @NotNull final String s) {
}
}, new HashMap<>()))).withTimeout(3600)
.withPrefix(new LineBreakPrefix()).addConversationAbandonedListener(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Set;
import java.util.UUID;

/**
* For use when creating a new ConversationContext
*/
public class BukkitFakeConversable implements Conversable {
public abstract class BukkitFakeConversable implements Conversable {
public String lastSentMessage;
public Conversation begunConversation;
public Conversation abandonedConverstion;
Expand Down Expand Up @@ -115,5 +117,7 @@ public boolean isOp() {

public void setOp(final boolean value) {
}

public abstract void sendRawMessage(@Nullable UUID uuid, @NotNull String s);
}

70 changes: 1 addition & 69 deletions core/src/main/java/me/pikamug/quests/util/BukkitItemUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.Potion;

import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -178,9 +177,7 @@ public static int compareItems(final ItemStack one, final ItemStack two, final b
if (Material.getMaterial("LINGERING_POTION") == null) {
if (one.getType().equals(Material.POTION)) {
// Bukkit version is below 1.9
final Potion pot1 = new Potion(one.getDurability());
final Potion pot2 = new Potion(two.getDurability());
if (!pot1.getType().equals(pot2.getType())) {
if (one.getDurability() != two.getDurability()) {
return -9;
}
}
Expand Down Expand Up @@ -698,75 +695,10 @@ public static Enchantment getEnchantmentFromProperName(String properName) {
if (e.getName().replace("_", "").equalsIgnoreCase(properName.replace("_", ""))) {
return e;
}
if (getEnchantmentFromProperLegacyName(properName) != null) {
return e;
}
}
return null;
}

/**
* Gets Enchantment from name as it appears in lang file
*
* @deprecated Use {@link #getEnchantmentFromProperName(String)}
* @param enchant Name to match lang value to
* @return Enchantment or null if invalid
*/
@Deprecated
public static Enchantment getEnchantmentFromProperLegacyName(final String enchant) {
if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_ARROW_DAMAGE"))) {
return Enchantment.ARROW_DAMAGE;
} else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_ARROW_FIRE"))) {
return Enchantment.ARROW_FIRE;
} else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_ARROW_INFINITE"))) {
return Enchantment.ARROW_INFINITE;
} else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_ARROW_KNOCKBACK"))) {
return Enchantment.ARROW_KNOCKBACK;
} else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_DAMAGE_ALL"))) {
return Enchantment.DAMAGE_ALL;
} else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_DAMAGE_ARTHROPODS"))) {
return Enchantment.DAMAGE_ARTHROPODS;
} else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_DAMAGE_UNDEAD"))) {
return Enchantment.DAMAGE_UNDEAD;
} else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_DIG_SPEED"))) {
return Enchantment.DIG_SPEED;
} else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_DURABILITY"))) {
return Enchantment.DURABILITY;
} else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_FIRE_ASPECT"))) {
return Enchantment.FIRE_ASPECT;
} else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_KNOCKBACK"))) {
return Enchantment.KNOCKBACK;
} else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_LOOT_BONUS_BLOCKS"))) {
return Enchantment.LOOT_BONUS_BLOCKS;
} else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_LOOT_BONUS_MOBS"))) {
return Enchantment.LOOT_BONUS_MOBS;
} else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_LUCK"))) {
return Enchantment.LOOT_BONUS_MOBS;
} else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_LURE"))) {
return Enchantment.LOOT_BONUS_MOBS;
} else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_OXYGEN"))) {
return Enchantment.OXYGEN;
} else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_PROTECTION_ENVIRONMENTAL"))) {
return Enchantment.PROTECTION_ENVIRONMENTAL;
} else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_PROTECTION_EXPLOSIONS"))) {
return Enchantment.PROTECTION_EXPLOSIONS;
} else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_PROTECTION_FALL"))) {
return Enchantment.PROTECTION_FALL;
} else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_PROTECTION_FIRE"))) {
return Enchantment.PROTECTION_FIRE;
} else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_PROTECTION_PROJECTILE"))) {
return Enchantment.PROTECTION_PROJECTILE;
} else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_SILK_TOUCH"))) {
return Enchantment.SILK_TOUCH;
} else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_THORNS"))) {
return Enchantment.THORNS;
} else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_WATER_WORKER"))) {
return Enchantment.WATER_WORKER;
} else {
return null;
}
}

public static Enchantment getEnchantmentFromPrettyName(String enchant) {
if (enchant != null) {
if (BukkitMiscUtil.spaceToCapital(enchant) != null) {
Expand Down
7 changes: 1 addition & 6 deletions core/src/main/java/me/pikamug/quests/util/BukkitLang.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,7 @@ public static String get(final Player player, final String key) {
if (player == null) {
return get(key);
}
String locale;
try {
locale = player.getLocale();
} catch (NoSuchMethodError e) {
locale = player.spigot().getLocale();
}
String locale= player.getLocale();
final int separator = locale.indexOf("_");
if (separator == -1) {
return defaultLang.containsKey(key) ? BukkitFormatToken.convertString(player, defaultLang.get(key)) : "NULL";
Expand Down

0 comments on commit 6afb92c

Please sign in to comment.