Skip to content

Commit

Permalink
Add ignored_name and ignored_lore settings
Browse files Browse the repository at this point in the history
  • Loading branch information
BeepSterr committed Jun 15, 2024
1 parent 71cbe61 commit 24e8a27
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 6 deletions.
30 changes: 30 additions & 0 deletions src/main/java/dev/beeps/plugins/BetterConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ public BetterConfig(BetterKeepInventory _plugin, FileConfiguration _config){
case 3:
migrateToExpandedEcoAndGriefPrevention();
break;
case 4:
migrateToNameAndLore();
break;

}

Expand Down Expand Up @@ -299,6 +302,33 @@ public void migrateToExpandedEcoAndGriefPrevention(){

}

public void migrateToNameAndLore(){

plugin.log(Level.INFO, "ConfigMigrator", "Migrating to config format 5");
File file = new File(plugin.getDataFolder() + File.separator + "config.yml");

if(!moveConfigToOld(file)){
plugin.log(Level.WARNING, "ConfigMigrator", "Could not back up config file, stopping migration!");
return;
};

config.set("main.config_version", 5);

config.set("items.hotbar.ignored_name", "NONE");
config.set("items.hotbar.ignored_lore", "NONE");

config.set("items.inventory.ignored_name", "NONE");
config.set("items.inventory.ignored_lore", "NONE");

config.set("items.armor.ignored_name", "NONE");
config.set("items.armor.ignored_lore", "NONE");

plugin.saveConfig();
plugin.log(Level.INFO, "ConfigMigrator", "Saved new config");
plugin.log(Level.INFO, "ConfigMigrator", "Completed migration to format 5");

}

public boolean getBoolean(String path){
return this.config.getBoolean(path);
}
Expand Down
31 changes: 25 additions & 6 deletions src/main/java/dev/beeps/plugins/Events/Types/ItemHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.bukkit.inventory.meta.ItemMeta;

import java.util.List;
import java.util.Objects;
import java.util.logging.Level;

public class ItemHandler {
Expand Down Expand Up @@ -38,18 +39,36 @@ public ItemHandler(BetterKeepInventory plugin, Player ply, ItemStack item, SlotT
boolean use_enchantments = config.getBoolean(path("use_enchantments"), true);
boolean dont_break = config.getBoolean(path("dont_break"), true);

// String ingored_name = config.getString(path("name"), "NONE");
// String ignored_lore = config.getString(path("lore"), "NONE");

List<Material> ignored_materials = config.getMaterialList(path("ignored_materials"));

if(ignored_materials.contains(item.getType())){
ItemMeta meta = item.getItemMeta();
Material type = item.getType();

if(ignored_materials.contains(type)){
plugin.log(Level.FINE, ply, "Exited Early: Item is in ignored_materials");
return;
}

ItemMeta meta = item.getItemMeta();
Material type = item.getType();
if(meta != null){
String ingored_name = config.getString(path("ignored_name"), "NONE");
String ignored_lore = config.getString(path("ignored_lore"), "NONE");

if(!Objects.equals(ingored_name, "NONE") && meta.getDisplayName().toLowerCase().contains(ingored_name.toLowerCase())){
plugin.log(Level.FINE, ply, "Exited Early: Item contains ignored name");
return;
}

if(!Objects.equals(ignored_lore, "NONE") && meta.getLore() != null) {
for (String lore : Objects.requireNonNull(meta.getLore())) {
if (lore.toLowerCase().contains(ignored_lore.toLowerCase())) {
plugin.log(Level.FINE, ply, "Exited Early: Item contains ignored lore");
return;
}
}
}
}



if(meta instanceof Damageable damageableMeta) {

Expand Down
18 changes: 18 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ items:
# Should we always leave at least 1 use left on items?
dont_break: true

# Any item with a custom name that includes this text will be ignored and left alone. set to "NONE" to disable.
ignored_name: "NONE"

# Any item with a custom lore that includes this text will be ignored and left alone. set to "NONE" to disable.
ignored_lore: "NONE"

# Materials in this list will be ignored
# Use names from this list: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Material.html
# Example:
Expand Down Expand Up @@ -71,6 +77,12 @@ items:
# Should we always leave at least 1 use left on items?
dont_break: true

# Any item with a custom name that includes this text will be ignored and left alone. set to "NONE" to disable.
ignored_name: "NONE"

# Any item with a custom lore that includes this text will be ignored and left alone. set to "NONE" to disable.
ignored_lore: "NONE"

# Materials in this list will be ignored
# Use names from this list: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Material.html
# Example:
Expand Down Expand Up @@ -99,6 +111,12 @@ items:
# Should we always leave at least 1 use left on items?
dont_break: true

# Any item with a custom name that includes this text will be ignored and left alone. set to "NONE" to disable.
ignored_name: "NONE"

# Any item with a custom lore that includes this text will be ignored and left alone. set to "NONE" to disable.
ignored_lore: "NONE"

# Materials in this list will be ignored
# Use names from this list: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Material.html
# Example:
Expand Down

0 comments on commit 24e8a27

Please sign in to comment.