Skip to content

Commit

Permalink
merge: Merge pull request #40
Browse files Browse the repository at this point in the history
feat: nether npc teleporting
  • Loading branch information
darksaid98 authored Jan 23, 2024
2 parents 59455c3 + 02f150d commit e5e12f8
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import me.ShermansWorld.AlathraExtras.misc.PaperRecipesListener;
import me.ShermansWorld.AlathraExtras.misc.ItemFrameListener;
import me.ShermansWorld.AlathraExtras.misc.MsgEditor;
import me.ShermansWorld.AlathraExtras.npcs.NPCListener;
import me.ShermansWorld.AlathraExtras.npcs.bossItemMerchantNPC;
import me.ShermansWorld.AlathraExtras.crafting.CraftingListener;
import me.ShermansWorld.AlathraExtras.playtime.PlaytimeCommand;
import me.ShermansWorld.AlathraExtras.playtime.PlaytimeTabCompleter;
Expand Down Expand Up @@ -156,6 +158,8 @@ public void onEnable() {
this.getServer().getPluginManager().registerEvents(new TeleportRequestResponseListener(), this);
this.getServer().getPluginManager().registerEvents(new TownyListener(), this);
this.getServer().getPluginManager().registerEvents(new VotingListener(), this);
this.getServer().getPluginManager().registerEvents(new DispenserListener(), this);
this.getServer().getPluginManager().registerEvents(new NPCListener(), this);

initRecipeItems();
FurnaceRecipes furnaceRecipes = new FurnaceRecipes();
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/me/ShermansWorld/AlathraExtras/npcs/NPCListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package me.ShermansWorld.AlathraExtras.npcs;

import net.citizensnpcs.api.event.NPCSpawnEvent;
import org.bukkit.event.EventHandler;

import org.bukkit.event.Listener;

public class NPCListener implements Listener {
@EventHandler
public void npcSpawnListener(NPCSpawnEvent e) {
if (e.getNPC().getId() == bossItemMerchantNPC.ID){
bossItemMerchantNPC.teleportMerchant();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package me.ShermansWorld.AlathraExtras.npcs;

import net.citizensnpcs.api.CitizensAPI;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.event.player.PlayerTeleportEvent;

import java.util.ArrayList;
import java.util.Random;

/**
* Handles code for the boss item merchant, specifically the one for the nether update.
*/
public class bossItemMerchantNPC{
public static final int ID = 83;

/**
* Teleports the merchant to one of their random locations
*/
public static void teleportMerchant(){
// Location information
final World world = Bukkit.getWorld("world");
if (world == null) return;

ArrayList<Location> locationArrayList = new ArrayList<>();
locationArrayList.add(new Location(world, -14.5, 109, 157.5)); //
locationArrayList.add(new Location(world, -66.5, 65, -95.5)); //
locationArrayList.add(new Location(world, 109.5, 73, 259.5)); //
locationArrayList.add(new Location(world, 92.5, 121, 70.5)); //
locationArrayList.add(new Location(world, 50.5, 100, 58.5)); //
locationArrayList.add(new Location(world, 7.5, 118, 56.5)); //
locationArrayList.add(new Location(world, 66.5, 111, 31.5)); //
locationArrayList.add(new Location(world, 38.5, 121, 122.5)); //
locationArrayList.add(new Location(world, 95.5, 66, -147.5)); //
locationArrayList.add(new Location(world, -168.5, 64, 111.5)); //
locationArrayList.add(new Location(world, -135.5, 73, 100.5)); //
locationArrayList.add(new Location(world, 95.5, 82, 71.5)); //

Random random = new Random();
int newLocationIndex = random.nextInt(locationArrayList.size()); //Pick random location

//Teleport the npc
CitizensAPI.getNPCRegistry().getById(ID).teleport(locationArrayList.get(newLocationIndex), PlayerTeleportEvent.TeleportCause.COMMAND);
}
}

0 comments on commit e5e12f8

Please sign in to comment.