Skip to content

Commit

Permalink
make ignoring external heads configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
crashdemons committed Dec 20, 2019
1 parent 6946b56 commit 49b6b12
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import com.github.crashdemons.playerheads.compatibility.Compatibility;
import com.github.crashdemons.playerheads.compatibility.plugins.heads.ExternalHeadHandling;
import com.github.crashdemons.playerheads.compatibility.plugins.heads.ExternalHeadType;
import com.github.crashdemons.playerheads.compatibility.plugins.heads.ExternalHeads;
import java.util.UUID;
import org.bukkit.OfflinePlayer;
import org.bukkit.block.BlockState;
Expand All @@ -17,7 +17,6 @@
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
*
Expand All @@ -26,21 +25,18 @@
public class HeadPluginCompatibility extends CompatiblePlugin {
public HeadPluginCompatibility(Plugin parentPlugin){
super(parentPlugin,"");
ExternalHeads.loadNamesFromConfig(parentPlugin.getConfig(), "ignoredheadnames", ExternalHeadHandling.NO_INTERACTION);
ExternalHeads.loadIdsFromConfig(parentPlugin.getConfig(), "ignoredheaduuids", ExternalHeadHandling.NO_INTERACTION);
}

@Nullable
public ExternalHeadType getExternalHead(String ownerName, UUID ownerID){
ExternalHeadType result = ExternalHeadType.get(ownerID);
if(result!=null) return result;
result = ExternalHeadType.get(ownerName);
return result;
}


@NotNull
public ExternalHeadHandling getExternalHeadHandling(String ownerName, UUID ownerID){
ExternalHeadType head = getExternalHead(ownerName,ownerID);
if(head==null) return ExternalHeadHandling.NORMAL;
return head.getHandling();
ExternalHeadHandling handling = ExternalHeads.getHandling(ownerName);
if(handling==null) handling=ExternalHeads.getHandling(ownerID);
if(handling==null) return ExternalHeadHandling.NORMAL;
return handling;
}

@NotNull
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/ .
*/
package com.github.crashdemons.playerheads.compatibility.plugins.heads;

import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import org.bukkit.configuration.ConfigurationSection;
import org.jetbrains.annotations.Nullable;

/**
*
* @author crashdemons (crashenator at gmail.com)
*/
public class ExternalHeads {
private ExternalHeads(){}

private static final HashMap<String,ExternalHeadHandling> nameToHandling = new HashMap<>();
private static final HashMap<UUID,ExternalHeadHandling> idToHandling = new HashMap<>();

public static void loadNamesFromConfig(ConfigurationSection section, String key, ExternalHeadHandling handling){
List<String> names = section.getStringList(key);
if(names==null) return;
for(String name : names)
nameToHandling.put(name,handling);
}

public static void loadIdsFromConfig(ConfigurationSection section, String key, ExternalHeadHandling handling){
List<String> ids = section.getStringList(key);
if(ids==null) return;
for(String id : ids){
UUID uuid = null;
try{
uuid = UUID.fromString(id);
idToHandling.put(uuid,handling);
}catch(IllegalArgumentException e){
//do nothing - invalid UUID String, no logging facility for this internal class.
}
}
}

@Nullable
public static ExternalHeadHandling getHandling(String username){
if(username==null) return null;
return nameToHandling.get(username);
}

@Nullable
public static ExternalHeadHandling getHandling(UUID id){
if(id==null) return null;
return idToHandling.get(id);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ public enum configType {

put("delaywitherdrop", configType.BOOLEAN);
put("delaywitherdropms", configType.INT);


put("ignoredheadnames", configType.STRINGLIST);
put("ignoredheaduuids", configType.STRINGLIST);
}
};
/**
Expand Down
5 changes: 5 additions & 0 deletions PlayerHeads-core/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ requireditems: [wooden_axe,stone_axe,golden_axe,iron_axe,diamond_axe]
considermobkillers: false
considertameowner: false

#prevent PlayerHeads from interacting/modifying third-party heads with these names or UUIDs
ignoredheadnames: [CSCoreLib]
ignoredheaduuids: []


#modifier for the rate of drops from different sizes of slime/magma cubes.
#for instance, 1.0 means that the slime drops 100% of the slimedroprate.
#so, with a slimedroprate of 0.75 and a size modifier of 0.5, the effective drop rate is 0.375
Expand Down

0 comments on commit 49b6b12

Please sign in to comment.