Skip to content

Commit

Permalink
Add configuration for disabling certain pet names
Browse files Browse the repository at this point in the history
  • Loading branch information
DSH105 committed Feb 19, 2014
1 parent 4fd6d1a commit 2bee09d
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ public void setDefaults() {
}
}

set("petNames.My Pet", "allow");

set("autoSave", true, "If true, EchoPet will autosave all pet data to prevent data", "loss in the event of a server crash.");
set("autoSaveTimer", 180, "Interval between autosave of pet data (in seconds).");
set("loadSavedPets", true, "Auto-load pets from last session");
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/io/github/dsh105/echopet/entity/Pet.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.github.dsh105.echopet.api.event.PetTeleportEvent;
import io.github.dsh105.echopet.data.PetHandler;
import io.github.dsh105.echopet.util.Lang;
import io.github.dsh105.echopet.util.PetNames;
import net.minecraft.server.v1_7_R1.Entity;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
Expand Down Expand Up @@ -184,9 +185,15 @@ public String getPetNameWithoutColours() {
* @param name new name of this {@link io.github.dsh105.echopet.entity.Pet}
*/
public void setPetName(String name) {
this.name = ChatColor.translateAlternateColorCodes('&', name);
this.getCraftPet().setCustomName(this.name);
this.getCraftPet().setCustomNameVisible(EchoPetPlugin.getInstance().options.getConfig().getBoolean("pets." + this.getPetType().toString().toLowerCase().replace("_", " ") + ".tagVisible", true));
if (PetNames.allow(name, this)) {
this.name = ChatColor.translateAlternateColorCodes('&', name);
this.getCraftPet().setCustomName(this.name);
this.getCraftPet().setCustomNameVisible(EchoPetPlugin.getInstance().options.getConfig().getBoolean("pets." + this.getPetType().toString().toLowerCase().replace("_", " ") + ".tagVisible", true));
} else {
if (this.getOwner() != null) {
Lang.sendTo(this.getOwner(), Lang.NAME_NOT_ALLOWED.toString().replace("%name%", name));
}
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/github/dsh105/echopet/util/Lang.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public enum Lang {
PET_NAME_TOO_LONG("name_length", "&ePet names cannot be longer than &632 &echaracters."),
NAME_RIDER("name_rider", "&eYour &6%type%&e's rider has been named to &r%name%&e."),
NAME_PET("name_pet", "&eYour &6%type% &ehas been named &r%name%&e."),
NAME_NOT_ALLOWED("name_not_allowed", "&eYou are not permitted to name your pet &6%name%&e."),
REMOVE_PET("remove_pet", "&eYour pet has been removed."),
REMOVE_PET_DEATH("remove_pet_death", "&eUpon your death, your pet has despawned."),
REMOVE_RIDER("remove_rider", "&eYour pet's rider has been removed."),
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/io/github/dsh105/echopet/util/PetNames.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.github.dsh105.echopet.util;

import com.dsh105.dshutils.config.YAMLConfig;
import io.github.dsh105.echopet.config.ConfigOptions;
import io.github.dsh105.echopet.entity.Pet;
import org.bukkit.ChatColor;
import org.bukkit.configuration.ConfigurationSection;

public class PetNames {

public static boolean allow(String input, Pet pet) {
YAMLConfig config = ConfigOptions.instance.getConfig();
String nameToCheck = ChatColor.stripColor(input);
ConfigurationSection cs = config.getConfigurationSection("petNames");
if (cs != null) {
for (String key : cs.getKeys(false)) {
if (key.equalsIgnoreCase(nameToCheck)) {
String value = config.getString("petNames." + key);
return pet.getOwner().hasPermission("echopet.pet.name.override") ? true : !(value.equalsIgnoreCase("deny") || value.equalsIgnoreCase("false"));
}
}
}
return true;
}
}
1 change: 1 addition & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,7 @@ permissions:
echopet.pet.hide: true
echopet.pet.call: true
echopet.pet.name: true
echopet.pet.name.override: true
echopet.pet.select: true
echopet.pet.selector: true
echopet.pet.type.*: true
Expand Down

0 comments on commit 2bee09d

Please sign in to comment.