Skip to content

Commit

Permalink
Refactoring, Shadowing, and also Player death and villager names and …
Browse files Browse the repository at this point in the history
…deaths. Caveat: Villagers that spawn because a village generated don't have names yet.
  • Loading branch information
transdryad committed Aug 11, 2024
1 parent a0a4fd0 commit 46a306c
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 7 deletions.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id 'java'
id("xyz.jpenilla.run-paper") version "2.3.0"
id 'com.gradleup.shadow' version '8.3.0'
}

group = 'io.github.transdrad'
Expand All @@ -20,6 +21,7 @@ repositories {

dependencies {
compileOnly "io.papermc.paper:paper-api:1.21.1-R0.1-SNAPSHOT"
implementation "org.ajbrown:name-machine:1.0.0"
}

def targetJavaVersion = 21
Expand All @@ -45,7 +47,7 @@ tasks {
// Configure the Minecraft version for our task.
// This is the only required configuration besides applying the plugin.
// Your plugin's jar (or shadowJar if present) will be used automatically.
minecraftVersion("1.21")
minecraftVersion("1.21.1")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.Random;
import java.util.logging.Level;

public final class BasilExplore extends JavaPlugin {
Expand All @@ -13,7 +14,6 @@ public void onEnable() {
this.getLogger().log(Level.INFO, "Enabling BasilExplore.");
this.saveDefaultConfig();
getLogger().log(Level.INFO, "Logging in a different way.");
FileConfiguration config = this.getConfig();
getServer().getPluginManager().registerEvents(new BasilListener(), this);
this.getCommand("home").setExecutor( new CommandHome());

Expand Down
22 changes: 20 additions & 2 deletions src/main/java/io/github/transdryad/basilexplore/BasilListener.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
package io.github.transdryad.basilexplore;

import org.ajbrown.namemachine.NameGenerator;
import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.entity.PlayerDeathEvent;

public class BasilListener implements Listener {

@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
public void onPlayerDeath(PlayerDeathEvent event) {
PlayerDeath.playerDeath(event);
}

@EventHandler
public void onEntitySpawn(EntitySpawnEvent event) {
if (event.getEntityType() == EntityType.VILLAGER) {
Villagers.nameVillager(event.getEntity());
}
}
@EventHandler
public void onEntityDeath(EntityDeathEvent event) {
if (event.getEntityType() == EntityType.VILLAGER) {
Villagers.villagerDeath(event.getEntity());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

import java.util.logging.Level;

import io.github.transdryad.basilexplore.Home;

public class CommandHome implements CommandExecutor {
Home home = new Home();
JavaPlugin plugin = BasilExplore.getPlugin(BasilExplore.class);
Expand All @@ -20,7 +18,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
if (sender instanceof Player) {
Player player = (Player) sender;
Location PlayerLocation = player.getLocation();
player.sendMessage("This plugin is running the config version " + plugin.getConfig().getString("config_version"));
//player.sendMessage("This plugin is running the config version " + plugin.getConfig().getString("config_version"));
if (args.length == 0) {
plugin.getLogger().log(Level.INFO,player.getName() + " ran /home from " + PlayerLocation.getBlockX() + ", " + PlayerLocation.getBlockY() + ", " + PlayerLocation.getBlockZ() + ".");
try {
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/io/github/transdryad/basilexplore/PlayerDeath.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.github.transdryad.basilexplore;

import org.bukkit.entity.Player;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.logging.Level;

public class PlayerDeath {

static JavaPlugin plugin = BasilExplore.getPlugin(BasilExplore.class);

public static void playerDeath(PlayerDeathEvent event) {
Player deadPlayer = event.getPlayer();
event.setKeepInventory(false);
int x = deadPlayer.getLocation().getBlockX();
int y = deadPlayer.getLocation().getBlockY();
int z = deadPlayer.getLocation().getBlockZ();
deadPlayer.sendMessage("You died at: " + x + ", " + y + ", " + z + ".");
plugin.getLogger().log(Level.INFO, deadPlayer.getName() + " died at: " + x + ", " + y + ", " + z + ".");
}
}
32 changes: 32 additions & 0 deletions src/main/java/io/github/transdryad/basilexplore/Villagers.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.github.transdryad.basilexplore;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import org.ajbrown.namemachine.Name;
import org.ajbrown.namemachine.NameGenerator;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.plugin.java.JavaPlugin;

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

public class Villagers {

static JavaPlugin plugin = BasilExplore.getPlugin(BasilExplore.class);

static NameGenerator generator = new NameGenerator();

public static void nameVillager(Entity entity) {
List<Name> names = generator.generateNames( 1 );
TextComponent textComponent = Component.text(names.getFirst().getFirstName() + " " + names.getFirst().getLastName());
entity.customName(textComponent);
//plugin.getLogger().log(Level.INFO, "Villager Spawned.");
}

public static void villagerDeath(Entity entity) {
Component deadName = entity.name();
TextComponent deathMessage = Component.text("The villager ").append(deadName).append(Component.text(" has just died."));
Bukkit.broadcast(deathMessage);
}
}

0 comments on commit 46a306c

Please sign in to comment.