Skip to content
This repository has been archived by the owner on Nov 2, 2021. It is now read-only.

Commit

Permalink
Support custom display names for Places achievements (#708)
Browse files Browse the repository at this point in the history
  • Loading branch information
PyvesB committed Oct 3, 2020
1 parent 36ba1b6 commit c6ff6a0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.hm.achievement.listener.statistics;

import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand All @@ -8,11 +9,13 @@
import javax.inject.Named;
import javax.inject.Singleton;

import org.bukkit.block.Block;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import com.hm.achievement.category.MultipleAchievements;
import com.hm.achievement.db.CacheManager;
Expand All @@ -38,15 +41,24 @@ public PlacesListener(@Named("main") CommentedYamlConfiguration mainConfig, int
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent event) {
Player player = event.getPlayer();
Block block = event.getBlock();
String blockName = block.getType().name().toLowerCase();
if (!player.hasPermission(category.toChildPermName(blockName))) {
return;
ItemStack placedItem = event.getItemInHand();

Set<String> foundAchievements = new HashSet<>();

String blockName = placedItem.getType().name().toLowerCase();
if (player.hasPermission(category.toChildPermName(blockName))) {
foundAchievements.addAll(findAchievementsByCategoryAndName(blockName + ':' + placedItem.getDurability()));
foundAchievements.addAll(findAchievementsByCategoryAndName(blockName));
}

ItemMeta itemMeta = placedItem.getItemMeta();
if (itemMeta != null && itemMeta.hasDisplayName()) {
String displayName = itemMeta.getDisplayName();
if (player.hasPermission(category.toChildPermName(StringUtils.deleteWhitespace(displayName)))) {
foundAchievements.addAll(findAchievementsByCategoryAndName(displayName));
}
}

Set<String> foundAchievements = findAchievementsByCategoryAndName(
blockName + ':' + block.getState().getData().toItemStack(0).getDurability());
foundAchievements.addAll(findAchievementsByCategoryAndName(blockName));
updateStatisticAndAwardAchievementsIfAvailable(player, foundAchievements, 1);
}
}
12 changes: 11 additions & 1 deletion advanced-achievements-plugin/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,10 @@ BungeeMode: false
# 5---------------------------------------------------------5 #
#============================ooooo============================#

# When a specific block is placed (available names: github.com/PyvesB/advanced-achievements/wiki/Material-names).
# When a specific block is placed. You can use any of the following:
# - a block name (available names: github.com/PyvesB/advanced-achievements/wiki/Material-names).
# - notations such as sand:1 for pre-1.13 versions, which means sand item with metadata 1 (red sand).
# - an item's custom display name (e.g. the name of a player's head).
Places:
chest:
5:
Expand Down Expand Up @@ -291,6 +294,13 @@ Places:
Command:
Execute: "say §7ALERT: §4PLAYER§7 has become the §4STONE GOD§7!"
Display: Become the Stone God!
# Item custom display name, for example Mario's head from the Custom Heads plugin.
§eMario:
1:
Goal: Place Mario's head.
Message: Mario's head is on the ground!
Name: place_1_mario
DisplayName: It's-a me, Mario!

# When a specific block is broken (available names: github.com/PyvesB/advanced-achievements/wiki/Material-names).
# You can use notations such as sand:1 for pre-1.13 versions, which means sand item with metadata 1 (red sand).
Expand Down
1 change: 1 addition & 0 deletions advanced-achievements-plugin/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,4 @@ permissions:
# - use the sub-category key: for example for stone breaks, achievement.count.breaks.stone
# - for PlayerCommands, use lower case without spaces nor the initial slash, e.g. achievement.count.playercommands.aachbook
# - for Kills with a custom mob name you should remove any whitespaces, e.g. achievement.count.kills.§2SkeletalKnight
# - for Places with a custom item display name you should also remove any whitespaces.

0 comments on commit c6ff6a0

Please sign in to comment.