Skip to content

Commit

Permalink
fix(forge16): add placeholders to webhook & add "biome" placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
danorris709 committed Aug 24, 2022
1 parent f5e89ee commit 8a247fe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
import com.envyful.api.config.data.ConfigPath;
import com.envyful.api.config.yaml.AbstractYamlConfig;
import com.envyful.api.discord.DiscordWebHook;
import com.envyful.api.forge.world.UtilWorld;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.pixelmonmod.api.pokemon.PokemonSpecification;
import com.pixelmonmod.api.pokemon.PokemonSpecificationProxy;
import com.pixelmonmod.pixelmon.api.util.helpers.BiomeHelper;
import com.pixelmonmod.pixelmon.entities.pixelmon.PixelmonEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import org.apache.commons.io.FileUtils;
import org.spongepowered.configurate.objectmapping.ConfigSerializable;

Expand Down Expand Up @@ -77,7 +81,7 @@ public boolean isWebHookEnabled() {
return this.webhook == null || this.webhook.equalsIgnoreCase("none");
}

public DiscordWebHook getWebHook() {
public DiscordWebHook getWebHook(ServerPlayerEntity nearestPlayer, PixelmonEntity pixelmon) {
if (this.readFile == null) {
try {
this.readFile = String.join(System.lineSeparator(), Files.readAllLines(Paths.get(this.webhook), StandardCharsets.UTF_8));
Expand All @@ -86,7 +90,16 @@ public DiscordWebHook getWebHook() {
}
}

return DiscordWebHook.fromJson(this.readFile);
return DiscordWebHook.fromJson(
this.readFile
.replace("%nearest_name%", nearestPlayer.getName().getString())
.replace("%x%", pixelmon.getX() + "")
.replace("%y%", pixelmon.getY() + "")
.replace("%z%", pixelmon.getZ() + "")
.replace("%world%", UtilWorld.getName(pixelmon.level) + "")
.replace("%pokemon%", pixelmon.getPokemonName())
.replace("%biome%", BiomeHelper.getLocalizedBiomeName(pixelmon.level.getBiome(pixelmon.blockPosition())).getString())
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import com.envyful.better.poke.broadcaster.config.BetterPokeBroadcasterConfig;
import com.pixelmonmod.pixelmon.Pixelmon;
import com.pixelmonmod.pixelmon.api.events.spawning.SpawnEvent;
import com.pixelmonmod.pixelmon.api.util.helpers.BiomeHelper;
import com.pixelmonmod.pixelmon.entities.pixelmon.PixelmonEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.util.Util;
import net.minecraft.util.text.ChatType;
import net.minecraftforge.eventbus.api.SubscribeEvent;
Expand Down Expand Up @@ -43,7 +45,7 @@ public void onPixelmonSpawn(SpawnEvent event) {
continue;
}

PlayerEntity nearestPlayer = pixelmon.level.getNearestPlayer(pixelmon, option.getNearestPlayerRadius());
ServerPlayerEntity nearestPlayer = (ServerPlayerEntity)pixelmon.level.getNearestPlayer(pixelmon, option.getNearestPlayerRadius());

for (String broadcast : option.getBroadcasts()) {
ServerLifecycleHooks.getCurrentServer().getPlayerList().broadcastMessage(
Expand All @@ -55,14 +57,15 @@ public void onPixelmonSpawn(SpawnEvent event) {
.replace("%z%", pixelmon.getZ() + "")
.replace("%world%", UtilWorld.getName(pixelmon.level) + "")
.replace("%pokemon%", pixelmon.getPokemonName())
.replace("%biome%", BiomeHelper.getLocalizedBiomeName(pixelmon.level.getBiome(pixelmon.blockPosition())).getString())
),
ChatType.CHAT,
Util.NIL_UUID
);
}

if (option.isWebHookEnabled()) {
DiscordWebHook webHook = option.getWebHook();
DiscordWebHook webHook = option.getWebHook(nearestPlayer, pixelmon);

if (webHook != null) {
try {
Expand Down

0 comments on commit 8a247fe

Please sign in to comment.