Skip to content

Commit

Permalink
Graves dimension blacklist, close #272
Browse files Browse the repository at this point in the history
  • Loading branch information
NightKosh committed Jul 14, 2018
1 parent 927ed16 commit 6170212
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/main/java/nightkosh/gravestone/config/Config.java
Expand Up @@ -62,6 +62,7 @@ public final void getConfigs() {
public static boolean vanillaRendererForSwordsGraves;
public static boolean generateEmptyPlayerGraves;
public static boolean removeCurseOfVanishingItems;
public static List<Integer> playerGravesDimensionalBlackList;

public static List<GraveStoneHelper.RestrictedArea> restrictGraveGenerationInArea;

Expand Down Expand Up @@ -104,6 +105,9 @@ private static void gravesConfig() {
}

removeCurseOfVanishingItems = config.get(CATEGORY_GRAVES, "RemoveCurseOfVanishingItems", true).getBoolean();

playerGravesDimensionalBlackList = ConfigsHelper.getDimensionList(config, CATEGORY_GRAVES, "PlayerGravesDimensionalBlackList", "",
"List of dimension ids in which player's graves will not be generated at death");
}


Expand Down
48 changes: 48 additions & 0 deletions src/main/java/nightkosh/gravestone/config/ConfigsHelper.java
@@ -0,0 +1,48 @@
package nightkosh.gravestone.config;

import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
import nightkosh.gravestone.core.logger.GSLogger;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
* GraveStone mod
*
* @author NightKosh
* @license Lesser GNU Public License v3 (http://www.gnu.org/licenses/lgpl.html)
*/
public class ConfigsHelper {


public static List<Integer> getDimensionList(Configuration config, String category, String ConfigID, String defaultValue, String comment) {
Property dimensionIdProperty = config.get(category, ConfigID, defaultValue);
dimensionIdProperty.setComment(comment);
String ar = dimensionIdProperty.getString();
String[] ids = ar.split(";");
List<Integer> dimensionIds = new ArrayList<>(ids.length);
for (String id : ids) {
try {
dimensionIds.add(Integer.parseInt(id));
} catch (NumberFormatException e) {
GSLogger.logError("Can't parse Dimension Id list!!!");
e.printStackTrace();
}
}
if (dimensionIds.isEmpty() && StringUtils.isNotBlank(defaultValue)) {
try {
dimensionIds.add(Integer.parseInt(defaultValue));
} catch (NumberFormatException e) {
GSLogger.logError("Can't parse Dimension Id list!!!");
e.printStackTrace();
}
}
return dimensionIds;
}

public static List<Integer> getDimensionList(Configuration config, String category, String ConfigID, int defaultValue, String comment) {
return getDimensionList(config, category, ConfigID, Integer.toString(defaultValue), comment);
}
}
12 changes: 7 additions & 5 deletions src/main/java/nightkosh/gravestone/core/event/EventsHandler.java
Expand Up @@ -34,13 +34,15 @@ public void onEntityLivingDeath(LivingDeathEvent event) {

if (Config.generatePlayerGraves && event.getEntityLiving() instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) event.getEntity();
for (IPlayerDeathHandler playerDeathHandler : APIGraveGeneration.PLAYER_DEATH_HANDLERS) {
if (playerDeathHandler.cancelGraveGeneration(player, event.getSource())) {
return;
if (!Config.playerGravesDimensionalBlackList.contains(player.dimension)) {
for (IPlayerDeathHandler playerDeathHandler : APIGraveGeneration.PLAYER_DEATH_HANDLERS) {
if (playerDeathHandler.cancelGraveGeneration(player, event.getSource())) {
return;
}
}
}

GraveGenerationHelper.createPlayerGrave(player, event, MobHandler.getAndRemoveSpawnTime(event.getEntity()));
GraveGenerationHelper.createPlayerGrave(player, event, MobHandler.getAndRemoveSpawnTime(event.getEntity()));
}
return;
} else {
if (Config.generateVillagerGraves && event.getEntity() instanceof EntityVillager) {
Expand Down

1 comment on commit 6170212

@crabdancing
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work! Thanks. :3

Please sign in to comment.