mirror of
https://github.com/PikaMug/Quests.git
synced 2024-11-25 03:55:35 +01:00
Yet another Paper workaround, fixes #2243
This commit is contained in:
parent
2d11b996ff
commit
40e2ccc129
@ -58,8 +58,10 @@ public class BukkitBlockListener implements Listener {
|
|||||||
}
|
}
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
if (plugin.canUseQuests(player.getUniqueId())) {
|
if (plugin.canUseQuests(player.getUniqueId())) {
|
||||||
final short durability = getBlockDurability(event.getBlock());
|
final ItemStack blockItemStack = getItemEquivalent(event.getBlock());
|
||||||
final ItemStack blockItemStack = new ItemStack(event.getBlock().getType(), 1, durability);
|
if (blockItemStack == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
final BukkitQuester quester = plugin.getQuester(player.getUniqueId());
|
final BukkitQuester quester = plugin.getQuester(player.getUniqueId());
|
||||||
final ObjectiveType breakType = ObjectiveType.BREAK_BLOCK;
|
final ObjectiveType breakType = ObjectiveType.BREAK_BLOCK;
|
||||||
final ObjectiveType placeType = ObjectiveType.PLACE_BLOCK;
|
final ObjectiveType placeType = ObjectiveType.PLACE_BLOCK;
|
||||||
@ -186,8 +188,10 @@ public class BukkitBlockListener implements Listener {
|
|||||||
}
|
}
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
if (plugin.canUseQuests(player.getUniqueId())) {
|
if (plugin.canUseQuests(player.getUniqueId())) {
|
||||||
final short durability = getBlockDurability(event.getBlock());
|
final ItemStack blockItemStack = getItemEquivalent(event.getBlock());
|
||||||
final ItemStack blockItemStack = new ItemStack(event.getBlock().getType(), 1, durability);
|
if (blockItemStack == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
final Quester quester = plugin.getQuester(player.getUniqueId());
|
final Quester quester = plugin.getQuester(player.getUniqueId());
|
||||||
final ObjectiveType type = ObjectiveType.DAMAGE_BLOCK;
|
final ObjectiveType type = ObjectiveType.DAMAGE_BLOCK;
|
||||||
final Set<String> dispatchedQuestIDs = new HashSet<>();
|
final Set<String> dispatchedQuestIDs = new HashSet<>();
|
||||||
@ -220,8 +224,10 @@ public class BukkitBlockListener implements Listener {
|
|||||||
}
|
}
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
if (plugin.canUseQuests(player.getUniqueId())) {
|
if (plugin.canUseQuests(player.getUniqueId())) {
|
||||||
final short durability = getBlockDurability(event.getBlock());
|
final ItemStack blockItemStack = getItemEquivalent(event.getBlock());
|
||||||
final ItemStack blockItemStack = new ItemStack(event.getBlock().getType(), 1, durability);
|
if (blockItemStack == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
final BukkitQuester quester = plugin.getQuester(player.getUniqueId());
|
final BukkitQuester quester = plugin.getQuester(player.getUniqueId());
|
||||||
final ObjectiveType placeType = ObjectiveType.PLACE_BLOCK;
|
final ObjectiveType placeType = ObjectiveType.PLACE_BLOCK;
|
||||||
final ObjectiveType breakType = ObjectiveType.BREAK_BLOCK;
|
final ObjectiveType breakType = ObjectiveType.BREAK_BLOCK;
|
||||||
@ -337,8 +343,10 @@ public class BukkitBlockListener implements Listener {
|
|||||||
}
|
}
|
||||||
if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
|
if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
|
||||||
if (!event.isCancelled() && event.getClickedBlock() != null) {
|
if (!event.isCancelled() && event.getClickedBlock() != null) {
|
||||||
final short durability = getBlockDurability(event.getClickedBlock());
|
final ItemStack blockItemStack = getItemEquivalent(event.getClickedBlock());
|
||||||
final ItemStack blockItemStack = new ItemStack(event.getClickedBlock().getType(), 1, durability);
|
if (blockItemStack == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
final ObjectiveType type = ObjectiveType.USE_BLOCK;
|
final ObjectiveType type = ObjectiveType.USE_BLOCK;
|
||||||
final Set<String> dispatchedQuestIDs = new HashSet<>();
|
final Set<String> dispatchedQuestIDs = new HashSet<>();
|
||||||
for (final Quest quest : plugin.getLoadedQuests()) {
|
for (final Quest quest : plugin.getLoadedQuests()) {
|
||||||
@ -366,19 +374,25 @@ public class BukkitBlockListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets durability for item equivalent of Block, unless server is on certain builds of Paper
|
* Gets item equivalent of Block, unless server is on certain builds of Paper
|
||||||
* server software, in which case returns 0
|
* server software, in which case may return null
|
||||||
*
|
*
|
||||||
* @param block Block of item
|
* @param block Block to convert
|
||||||
* @return durability or 0
|
* @return item or null
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
private short getBlockDurability(final Block block) {
|
private ItemStack getItemEquivalent(final Block block) {
|
||||||
|
short durability = 0;
|
||||||
try {
|
try {
|
||||||
// Occurs with certain builds of Paper server software
|
durability = block.getState().getData().toItemStack().getDurability();
|
||||||
return block.getState().getData().toItemStack().getDurability();
|
} catch (final IllegalArgumentException e) {
|
||||||
} catch (final IllegalArgumentException ex) {
|
// https://github.com/PikaMug/Quests/issues/2236
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
return new ItemStack(block.getType(), 1, durability);
|
||||||
|
} catch (final IllegalArgumentException e) {
|
||||||
|
// https://github.com/PikaMug/Quests/issues/2243
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ public class BukkitLang {
|
|||||||
String locale;
|
String locale;
|
||||||
try {
|
try {
|
||||||
locale = player.getLocale();
|
locale = player.getLocale();
|
||||||
} catch (NoSuchMethodError e) {
|
} catch (final NoSuchMethodError e) {
|
||||||
locale = player.spigot().getLocale();
|
locale = player.spigot().getLocale();
|
||||||
}
|
}
|
||||||
final int separator = locale.indexOf("_");
|
final int separator = locale.indexOf("_");
|
||||||
@ -86,7 +86,7 @@ public class BukkitLang {
|
|||||||
if (!otherLang.containsKey(locale)) {
|
if (!otherLang.containsKey(locale)) {
|
||||||
try {
|
try {
|
||||||
load(plugin, locale);
|
load(plugin, locale);
|
||||||
} catch (Exception e) {
|
} catch (final Exception e) {
|
||||||
return defaultLang.containsKey(key) ? BukkitFormatToken.convertString(player, defaultLang.get(key)) : "NULL";
|
return defaultLang.containsKey(key) ? BukkitFormatToken.convertString(player, defaultLang.get(key)) : "NULL";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user