Skip to content

Commit

Permalink
Implement basic Sniffer pet #145
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnuh committed Jun 10, 2023
1 parent 2c3e090 commit 51c76f1
Show file tree
Hide file tree
Showing 12 changed files with 783 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public enum PetType implements IPetType{
SKELETON("Skeleton", "Skeleton Pet", "skeleton"),
SKELETONHORSE("SkeletonHorse", "Skeleton Horse Pet", "skeleton_horse", PetData.SADDLE),
SLIME("Slime", "Slime Pet", "slime", new PetDataCategory[]{PetDataCategory.SLIME_SIZE}),
SNIFFER("Sniffer", "Sniffer Pet", "sniffer", new Version("1.20-R1"), new PetDataCategory[]{PetDataCategory.SNIFFER_STATE}),
SNOWMAN("Snowman", "Snowman Pet", "snow_golem", Material.PUMPKIN, PetData.SHEARED),
SPIDER("Spider", "Spider Pet", "spider"),
SQUID("Squid", "Squid Pet", "squid"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import com.dsh105.echopet.compat.api.entity.type.pet.ISheepPet;
import com.dsh105.echopet.compat.api.entity.type.pet.IShulkerPet;
import com.dsh105.echopet.compat.api.entity.type.pet.ISlimePet;
import com.dsh105.echopet.compat.api.entity.type.pet.ISnifferPet;
import com.dsh105.echopet.compat.api.entity.type.pet.ISnowmanPet;
import com.dsh105.echopet.compat.api.entity.type.pet.IStriderPet;
import com.dsh105.echopet.compat.api.entity.type.pet.ITropicalFishPet;
Expand Down Expand Up @@ -849,7 +850,50 @@ public class PetData<T>{
return (t)->goat.setColor(null);
}
return null;
}).material(Material.SHULKER_BOX).name("No Color").parser(booleanParser()).create();
}).material(Material.SHULKER_BOX).name("No Color").parser(booleanParser()).create(),
// Sniffer States
IDLING = new Builder<Boolean>().configKey("idling").action((player, pet, category)->{
if(pet instanceof ISnifferPet sniffer){
return (t)->sniffer.transitionTo(ISnifferPet.State.IDLING);
}
return null;
}).material(Material.BONE).name("Idling").parser(booleanParser()).create(),
FEELING_HAPPY = new Builder<Boolean>().configKey("feeling_happy").action((player, pet, category)->{
if(pet instanceof ISnifferPet sniffer){
return (t)->sniffer.transitionTo(ISnifferPet.State.FEELING_HAPPY);
}
return null;
}).material(Material.GLOW_BERRIES).name("Feeling Happy").parser(booleanParser()).create(),
SCENTING = new Builder<Boolean>().configKey("scenting").action((player, pet, category)->{
if(pet instanceof ISnifferPet sniffer){
return (t)->sniffer.transitionTo(ISnifferPet.State.SCENTING);
}
return null;
}).material(Material.valueOf("PITCHER_POD")).name("Scenting").parser(booleanParser()).create(),
SNIFFING = new Builder<Boolean>().configKey("sniffing").action((player, pet, category)->{
if(pet instanceof ISnifferPet sniffer){
return (t)->sniffer.transitionTo(ISnifferPet.State.SNIFFING);
}
return null;
}).material(Material.WHEAT_SEEDS).name("Sniffing").parser(booleanParser()).create(),
SEARCHING = new Builder<Boolean>().configKey("searching").action((player, pet, category)->{
if(pet instanceof ISnifferPet sniffer){
return (t)->sniffer.transitionTo(ISnifferPet.State.SEARCHING);
}
return null;
}).material(Material.valueOf("TORCHFLOWER_SEEDS")).name("Searching").parser(booleanParser()).create(),
DIGGING = new Builder<Boolean>().configKey("digging").action((player, pet, category)->{
if(pet instanceof ISnifferPet sniffer){
return (t)->sniffer.transitionTo(ISnifferPet.State.DIGGING);
}
return null;
}).material(Material.DIRT).name("Digging").parser(booleanParser()).create(),
RISING = new Builder<Boolean>().configKey("rising").action((player, pet, category)->{
if(pet instanceof ISnifferPet sniffer){
return (t)->sniffer.transitionTo(ISnifferPet.State.RISING);
}
return null;
}).material(Material.BONE).name("Rising").parser(booleanParser()).create();

public static final PetData<Integer>
SIZE = PetData.create("size", (player, pet, category)->value->{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public enum PetDataCategory{
COLLAR_COLOR(Material.WHITE_WOOL, "Collar Color", false, PetData.WHITE, PetData.ORANGE, PetData.MAGENTA, PetData.LIGHT_BLUE, PetData.YELLOW, PetData.LIME, PetData.PINK, PetData.GRAY, PetData.LIGHT_GRAY, PetData.CYAN, PetData.PURPLE, PetData.BLUE, PetData.BROWN, PetData.GREEN, PetData.RED, PetData.BLACK),
SHULKER_COLOR("shulker_", Material.PURPLE_DYE, "Shulker Color", false, PetData.NO_COLOR, PetData.WHITE, PetData.ORANGE, PetData.MAGENTA, PetData.LIGHT_BLUE, PetData.YELLOW, PetData.LIME, PetData.PINK, PetData.GRAY, PetData.LIGHT_GRAY, PetData.CYAN, PetData.PURPLE, PetData.BLUE, PetData.BROWN, PetData.GREEN, PetData.RED, PetData.BLACK),
SLIME_SIZE("slime_", Material.SLIME_BALL, "Slime Size", false, PetData.SIZE_SMALL, PetData.SIZE_MEDIUM, PetData.SIZE_LARGE),
SNIFFER_STATE("sniffer_", Material.DIRT, "Sniffer State", false, PetData.IDLING, PetData.FEELING_HAPPY, PetData.SCENTING, PetData.SNIFFING, PetData.SEARCHING, PetData.DIGGING, PetData.RISING),
PUFFERFISH_SIZE("pufferfish_", Material.PUFFERFISH, "PufferFish Size", false, PetData.SIZE_SMALL, PetData.SIZE_MEDIUM, PetData.SIZE_LARGE),
VILLAGER_TYPE("villager_", Material.SAND, "Villager Type", false, PetData.DESERT, PetData.JUNGLE, PetData.PLAINS, PetData.SAVANNA, PetData.SNOWY, PetData.SWAMP, PetData.TAIGA),
VILLAGER_PROFESSION("villager_", Material.IRON_AXE, "Villager Profession", false, PetData.NONE, PetData.ARMORER, PetData.BUTCHER, PetData.CARTOGRAPHER, PetData.CLERIC, PetData.FARMER, PetData.FISHERMAN, PetData.FLETCHER, PetData.LEATHERWORKER, PetData.LIBRARIAN, PetData.MASON, PetData.NITWIT, PetData.SHEPHERD, PetData.TOOLSMITH, PetData.WEAPONSMITH),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* This file is part of EchoPet.
*
* EchoPet is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EchoPet is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EchoPet. If not, see <http://www.gnu.org/licenses/>.
*/

package com.dsh105.echopet.compat.api.entity.type.nms.handle;

import com.dsh105.echopet.compat.api.entity.nms.handle.IEntityAnimalPetHandle;
import com.dsh105.echopet.compat.api.entity.type.pet.ISnifferPet;

public interface IEntitySnifferPetHandle extends IEntityAnimalPetHandle{

void transitionTo(ISnifferPet.State state);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* This file is part of EchoPet.
*
* EchoPet is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EchoPet is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EchoPet. If not, see <http://www.gnu.org/licenses/>.
*/

package com.dsh105.echopet.compat.api.entity.type.pet;

import com.dsh105.echopet.compat.api.config.PetConfigEntry;

public interface ISnifferPet extends IAnimalPet{

PetConfigEntry<Boolean> BRAIN_ENABLED = new PetConfigEntry<>(Boolean.class, "brain.enabled", false);

enum State{
IDLING,
FEELING_HAPPY,
SCENTING,
SNIFFING,
SEARCHING,
DIGGING,
RISING;

public static final State[] values = values();

State(){}
}

void transitionTo(ISnifferPet.State state);

ISnifferPet.State getState();
}
13 changes: 10 additions & 3 deletions main/src/main/java/com/dsh105/echopet/EchoPetPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,12 @@ public void onEnable(){
petRegistry = ReflectionUtil.getVersionedClass(IPetRegistry.class, "PetRegistry").getConstructor().newInstance();
craftBukkitUtil = ReflectionUtil.getVersionedClass(ICraftBukkitUtil.class, "CraftBukkitUtil").getConstructor().newInstance();
}catch(Exception ex){
getLogger().warning("EchoPet " + ChatColor.GOLD + this.getDescription().getVersion() + ChatColor.RED + " is not compatible with this version of Spigot");
getLogger().warning("EchoPet " + ChatColor.GOLD + this.getDescription()
.getVersion() + ChatColor.RED + " is not compatible with this version of Spigot");
getLogger().warning("Initialisation failed. Please update the plugin.");

DynamicPluginCommand cmd = new DynamicPluginCommand(this.cmdString, new String[0], "", "", new VersionIncompatibleCommand(this.cmdString, prefix, ChatColor.YELLOW + "EchoPet " + ChatColor.GOLD + this.getDescription().getVersion() + ChatColor.YELLOW + " is not compatible with this version of Spigot. Please update the plugin.", "echopet.pet", ChatColor.YELLOW + "You are not allowed to do that."), null, this);
DynamicPluginCommand cmd = new DynamicPluginCommand(this.cmdString, new String[0], "", "", new VersionIncompatibleCommand(this.cmdString, prefix, ChatColor.YELLOW + "EchoPet " + ChatColor.GOLD + this.getDescription()
.getVersion() + ChatColor.YELLOW + " is not compatible with this version of Spigot. Please update the plugin.", "echopet.pet", ChatColor.YELLOW + "You are not allowed to do that."), null, this);
COMMAND_MANAGER.register(cmd);
return;
}
Expand Down Expand Up @@ -166,7 +168,12 @@ public void onDisable(){
}

private void loadConfiguration(){
String[] header = {"EchoPet By DSH105", "Updated by Borlea", "& NobleProductions <3", "---------------------", "Configuration for EchoPet 2", "See the EchoPet Wiki before editing this file"};
String[] header = {"EchoPet By DSH105",
"Updated by Borlea",
"& NobleProductions <3",
"---------------------",
"Configuration for EchoPet 2",
"See the EchoPet Wiki before editing this file"};
// Load categories first because PetData default config is dependent on category petdata being loaded.
try{
petCategoryConfig = configManager.getNewConfig("pet-categories.yml");
Expand Down
27 changes: 27 additions & 0 deletions main/src/main/java/com/dsh105/echopet/api/pet/AnimalPet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* This file is part of EchoPet.
*
* EchoPet is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EchoPet is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EchoPet. If not, see <http://www.gnu.org/licenses/>.
*/

package com.dsh105.echopet.api.pet;

import org.bukkit.entity.Player;

public abstract class AnimalPet extends AgeablePet{

public AnimalPet(Player owner){
super(owner);
}
}
55 changes: 55 additions & 0 deletions main/src/main/java/com/dsh105/echopet/api/pet/type/SnifferPet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* This file is part of EchoPet.
*
* EchoPet is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EchoPet is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EchoPet. If not, see <http://www.gnu.org/licenses/>.
*/

package com.dsh105.echopet.api.pet.type;

import java.util.List;
import com.dsh105.echopet.api.pet.AnimalPet;
import com.dsh105.echopet.compat.api.entity.EntityPetType;
import com.dsh105.echopet.compat.api.entity.PetType;
import com.dsh105.echopet.compat.api.entity.type.nms.handle.IEntitySnifferPetHandle;
import com.dsh105.echopet.compat.api.entity.type.pet.ISnifferPet;
import com.dsh105.echopet.compat.api.util.StringUtil;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;

@EntityPetType(petType = PetType.SNIFFER)
public class SnifferPet extends AnimalPet implements ISnifferPet{

private State state;

public SnifferPet(Player owner){
super(owner);
}

@Override
public void transitionTo(State state){
((IEntitySnifferPetHandle) getHandle()).transitionTo(state);
this.state = state;
}

@Override
public State getState(){
return state;
}

@Override
public void generatePetInfo(List<String> info){
super.generatePetInfo(info);
info.add(ChatColor.GOLD + " - State: " + ChatColor.YELLOW + StringUtil.capitalise(getState().name()));
}
}
Loading

0 comments on commit 51c76f1

Please sign in to comment.