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

Commit

Permalink
Merged pull request #221 from fabianwennink/breeding_category
Browse files Browse the repository at this point in the history
Added a new category: Breeding
  • Loading branch information
PyvesB authored Jul 17, 2017
2 parents cb386ba + 60264d1 commit bb19b66
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/main/java/com/hm/achievement/AdvancedAchievements.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import com.hm.achievement.listener.AchieveBedListener;
import com.hm.achievement.listener.AchieveBlockBreakListener;
import com.hm.achievement.listener.AchieveBlockPlaceListener;
import com.hm.achievement.listener.AchieveBreedListener;
import com.hm.achievement.listener.AchieveConnectionListener;
import com.hm.achievement.listener.AchieveConsumeListener;
import com.hm.achievement.listener.AchieveCraftListener;
Expand Down Expand Up @@ -124,6 +125,7 @@ public class AdvancedAchievements extends JavaPlugin implements Reloadable {
private AchievePickupListener pickupListener;
private AchieveHoeFertiliseFireworkMusicListener hoeFertiliseFireworkMusicListener;
private AchieveTameListener tameListener;
private AchieveBreedListener breedListener;
private AchieveBlockPlaceListener blockPlaceListener;
private AchieveBlockBreakListener blockBreakListener;
private AchieveKillListener killListener;
Expand Down Expand Up @@ -612,6 +614,11 @@ private void registerListeners() {
pm.registerEvents(tameListener, this);
}

if (!disabledCategorySet.contains(MultipleAchievements.BREEDING.toString())) {
breedListener = new AchieveBreedListener(this);
pm.registerEvents(breedListener, this);
}

if (!disabledCategorySet.contains(NormalAchievements.HOEPLOWING.toString())
|| !disabledCategorySet.contains(NormalAchievements.FERTILISING.toString())
|| !disabledCategorySet.contains(NormalAchievements.FIREWORKS.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public enum MultipleAchievements {
BREAKS("Breaks", "Blocks Broken", "When a specific block is broken (specify material name, lower case).", "blockid"),
KILLS("Kills", "Entities Killed", "When a specific mob is killed (specify an entity name or poweredcreeper or player, lower case).", "mobname"),
CRAFTS("Crafts", "Items Crafted", "When a specific item is crafted (specify material name, lower case).", "item"),
BREEDING("Breeding", "Animals Bred", "When animals breed (specify an entity name, lower case).", "mobname"),
PLAYERCOMMANDS("PlayerCommands", "Commands Entered", "When a player enters a specific command (specify command prefixes in lower case without spaces).", "command");

private final String categoryName;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.hm.achievement.listener;

import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityBreedEvent;

import com.hm.achievement.AdvancedAchievements;
import com.hm.achievement.category.MultipleAchievements;

/**
* Listener class to deal with Breeding achievements.
*/
public class AchieveBreedListener extends AbstractListener {

public AchieveBreedListener(AdvancedAchievements plugin) {
super(plugin);
}

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEntityBreed(EntityBreedEvent event) {
if(!(event.getBreeder() instanceof Player)) {
return;
}

Player player = (Player)event.getBreeder();

if (player == null) {
return;
}

if (!shouldEventBeTakenIntoAccountNoPermission(player)) {
return;
}

Entity entity = event.getMother();

if (!(entity instanceof LivingEntity)) {
return;
}

String mobName = entity.getType().name().toLowerCase();

MultipleAchievements category = MultipleAchievements.BREEDING;

if (plugin.getPluginConfig().isConfigurationSection(category + "." + mobName)
&& player.hasPermission(category.toPermName() + '.' + mobName)) {
updateStatisticAndAwardAchievementsIfAvailable(player, category, mobName, 1);
}
}
}
13 changes: 11 additions & 2 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ Shear:
Message: 100 sheep sheared!
Name: shear_100
DisplayName: "&1Wool Addict"

# When a cow is milked.
Milk:
1:
Expand Down Expand Up @@ -527,7 +527,16 @@ Taming:
Message: You tamed your first animal!
Name: taming_1
DisplayName: Tamer


# When animals breed.
# Use an Entity name, in lower case.
Breeding:
sheep:
100:
Message: You bred your first animal!
Name: breeding_1
DisplayName: Breeder

# When a potion is brewed.
Brewing:
1:
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/gui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ Fertilising:
Taming:
Item: leash
Metadata: 0
Breeding:
Item: wheat
Metadata: 0
Brewing:
Item: brewing_stand_item
Metadata: 0
Expand Down

0 comments on commit bb19b66

Please sign in to comment.