-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring, Shadowing, and also Player death and villager names and …
…deaths. Caveat: Villagers that spawn because a village generated don't have names yet.
- Loading branch information
1 parent
a0a4fd0
commit 46a306c
Showing
6 changed files
with
79 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 20 additions & 2 deletions
22
src/main/java/io/github/transdryad/basilexplore/BasilListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/main/java/io/github/transdryad/basilexplore/PlayerDeath.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
32
src/main/java/io/github/transdryad/basilexplore/Villagers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |