Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/npc teleporting feature #40

Merged
merged 16 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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){
Xavbeat03 marked this conversation as resolved.
Show resolved Hide resolved
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);
}
}
Loading