Skip to content

Commit

Permalink
added immune permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
BuildTools committed Mar 4, 2017
1 parent 47ae628 commit 595e689
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 12 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.blocktyper</groupId>
<artifactId>spoileralert</artifactId>
<version>1.1.4</version>
<version>1.1.5</version>
<name>SpoilerAlert</name>

<properties>
Expand Down Expand Up @@ -43,7 +43,7 @@
<dependency>
<groupId>com.blocktyper</groupId>
<artifactId>blocktyperplugin</artifactId>
<version>1.2.0</version>
<version>1.2.3</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/blocktyper/spoileralert/ConfigKeyEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public enum ConfigKeyEnum {
DATE_FORMAT("spoileralert-date-format"),
USE_REAL_DATES("spoileralert-use-real-dates"),
USE_LORE("spoileralert-use-lore"),
BLOCK_SPOILED_TRADES("spoileralert-block-spoiled-trades");
BLOCK_SPOILED_TRADES("spoileralert-block-spoiled-trades"),
IMMUNE_PERMISSIONS("spoiler-alert-immune-permissions");


private String key;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
import com.blocktyper.spoileralert.listeners.InventoryOpenListener;
import com.blocktyper.spoileralert.listeners.PickupListener;
import com.blocktyper.spoileralert.listeners.PlayerTradeListener;
import com.blocktyper.v1_2_0.BlockTyperBasePlugin;
import com.blocktyper.v1_2_0.config.BlockTyperConfig;
import com.blocktyper.v1_2_0.recipes.IRecipe;
import com.blocktyper.v1_2_3.BlockTyperBasePlugin;
import com.blocktyper.v1_2_3.config.BlockTyperConfig;
import com.blocktyper.v1_2_3.recipes.IRecipe;
import com.blocktyper.spoileralert.listeners.BlockBreakListener;
import com.blocktyper.spoileralert.listeners.BlockPlaceListener;
import com.blocktyper.spoileralert.listeners.CakeListener;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.blocktyper.spoileralert.listeners;

import java.util.List;

import org.bukkit.entity.HumanEntity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerItemConsumeEvent;

import com.blocktyper.spoileralert.ConfigKeyEnum;
import com.blocktyper.spoileralert.SpoilerAlertPlugin;

public class FoodEatListener extends SpoilerAlertListenerBase {
Expand All @@ -17,6 +21,11 @@ public FoodEatListener(SpoilerAlertPlugin plugin) {
*/
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = false)
public void onFoodEat(PlayerItemConsumeEvent event) {

List<String> immunePermissions = getConfig().getStringList(ConfigKeyEnum.IMMUNE_PERMISSIONS.getKey());
if(playerIsImmune(event.getPlayer(), immunePermissions)){
return;
}

Long daysExpired = getDaysExpired(event.getItem(), event.getPlayer().getWorld(), event.getPlayer());

Expand All @@ -26,6 +35,20 @@ public void onFoodEat(PlayerItemConsumeEvent event) {

makePlayerSick(daysExpired, event.getItem(), event.getPlayer());
}

public boolean playerIsImmune(HumanEntity player, List<String> permissions) {
if (permissions == null || permissions.isEmpty()) {
return false;
}

for (String permission : permissions) {
if (player.hasPermission(permission)) {
return true;
}
}

return false;
}
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
import com.blocktyper.spoileralert.PerishableBlockRepo;
import com.blocktyper.spoileralert.SpoilerAlertCalendar;
import com.blocktyper.spoileralert.SpoilerAlertPlugin;
import com.blocktyper.v1_2_0.helpers.InvisibleLoreHelper;
import com.blocktyper.v1_2_0.nbt.NBTItem;
import com.blocktyper.v1_2_0.recipes.translation.ContinuousTranslationListener;
import com.blocktyper.v1_2_3.helpers.InvisHelper;
import com.blocktyper.v1_2_3.nbt.NBTItem;
import com.blocktyper.v1_2_3.recipes.translation.ContinuousTranslationListener;

public abstract class SpoilerAlertListenerBase extends ContinuousTranslationListener {

Expand Down Expand Up @@ -125,7 +125,7 @@ protected ItemStack setExpirationDate(ItemStack itemStack, World world, Long day
}

private boolean loreLineContainsInvisExpirationDatePrefix(String loreLine) {
return loreLine != null && InvisibleLoreHelper.convertToVisibleString(loreLine)
return loreLine != null && InvisHelper.convertToVisibleString(loreLine)
.contains(INVISIBLE_PREFIX_SPOILER_ALERT_EXPIRATION_DATE);
}

Expand Down Expand Up @@ -192,7 +192,7 @@ private ItemStack getItemWithNbtTagExpirationDate(HumanEntity player, ItemStack
}

private String getExpirationDateLoreLine(HumanEntity player, String formattedDateString) {
String invis = InvisibleLoreHelper.convertToInvisibleString(INVISIBLE_PREFIX_SPOILER_ALERT_EXPIRATION_DATE);
String invis = InvisHelper.convertToInvisibleString(INVISIBLE_PREFIX_SPOILER_ALERT_EXPIRATION_DATE);
String expirationDateText = getLocalizedMessage(LocalizedMessageEnum.EXPIRATION_DATE.getKey(), player);
String loreFormat = "{0}{1}: {2}";
String loreLine = new MessageFormat(loreFormat)
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ spoileralert-date-format.en_us: M/d/yyyy
spoileralert-date-format.zh_cn: yyyy-MM-dd
spoileralert-date-format.de: dd-MM-yyyy

spoiler-alert-immune-permissions:
- spoiler-alert-immune
- your-custom-permission-here

spoileralert-recipe-shelf-life:
- candy-apple=21
- salted-beef=21
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: SpoilerAlert
version: 1.1.4
version: 1.1.5
main: com.blocktyper.spoileralert.SpoilerAlertPlugin
author: spaarkimus
website: blocktyper.com
Expand Down
10 changes: 10 additions & 0 deletions upgradeVersion
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash


if [[ -z $1 ]]; then
echo "original version required as first parameter"
elif [[ -z $2 ]]; then
echo "new version required as second parameter"
else
grep -rl $1 src/main/java/com/blocktyper | xargs sed -i "s/$1/$2/g"
fi

0 comments on commit 595e689

Please sign in to comment.