Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package playertesting;
- import java.util.ArrayList;
- import net.risingworld.api.Plugin;
- import net.risingworld.api.Server;
- import net.risingworld.api.Timer;
- import net.risingworld.api.World;
- import net.risingworld.api.assets.AssetBundle;
- import net.risingworld.api.events.EventMethod;
- import net.risingworld.api.events.Listener;
- import net.risingworld.api.events.npc.NpcSpawnEvent;
- import net.risingworld.api.events.player.PlayerChangePositionEvent;
- import net.risingworld.api.objects.Player;
- import net.risingworld.api.events.player.PlayerConnectEvent;
- import net.risingworld.api.objects.Npc;
- import net.risingworld.api.utils.Key;
- import net.risingworld.api.utils.Utils;
- import net.risingworld.api.utils.Vector3f;
- import net.risingworld.api.worldelements.Text3D;
- public class playertesting extends Plugin implements Listener {
- public AssetBundle bundle;
- public ArrayList<Text3D> text3d;
- @Override
- public void onEnable() {
- this.registerEventListener(this);
- initnpcs();
- }
- @Override
- public void onDisable() {
- }
- public void initnpcs(){
- text3d = new ArrayList();
- Npc[] npcs = World.getAllNpcs();
- for(Npc npc : npcs){
- String type = npc.getDefinition().type.name();
- if(type.equalsIgnoreCase("Animal")){
- Text3D text = new Text3D("Wild");
- text.setBillboard(true);
- text.setFontSize(2.5f);
- text.setActive(true);
- float oy = npc.getPosition().y;
- float ny = oy+5.0f;
- text.setFontColor(0, 1, 0, 1);
- String b = npc.getDefinition().behaviour.name();
- if(b.equalsIgnoreCase("Aggressive")){
- text.setFontColor(1, 0, 0, 1);
- }
- text.setLocalPosition(npc.getPosition().x, ny, npc.getPosition().z);
- npc.setAttribute("text", text);
- text3d.add(text);
- }
- }
- Timer();
- }
- public void loadplayertexts(Player player){
- for(int i = 0; i<text3d.size();i++){
- Text3D text = (Text3D)text3d.get(i);
- player.addGameObject(text);
- }
- }
- @EventMethod
- public void playerconnect(PlayerConnectEvent evt){
- Player player = evt.getPlayer();
- player.registerKeys(Key.F);
- player.setListenForKeyInput(true);
- player.setListenForMouseInput(true);
- loadplayertexts(player);
- }
- public void Timer(){
- Timer timer = new Timer(0.0025f, 0f, -1, () -> {
- Npc[] npcs = World.getAllNpcs();
- for(Npc npc : npcs){
- if(npc.hasAttribute("text")){
- Text3D text = (Text3D)npc.getAttribute("text");
- float oy = npc.getPosition().y;
- float ny = oy+3.25f;
- text.setLocalPosition(npc.getPosition().x, ny, npc.getPosition().z);
- }
- }
- });
- timer.start();
- }
- @EventMethod
- public void npcspawn(NpcSpawnEvent evt){
- Npc npc = evt.getNpc();
- Timer timer= new Timer(60f, 5f, 1, null);
- timer.setTask(TimerRunnable(npc));
- timer.start();
- }
- public Runnable TimerRunnable(Npc npc){
- Runnable setNpcInfo = ()->{
- String type = npc.getDefinition().type.name();
- if(type.equalsIgnoreCase("Animal")){
- Text3D text = new Text3D("Wild");
- text.setBillboard(true);
- text.setFontSize(2.5f);
- text.setActive(false);
- float oy = npc.getPosition().y;
- float ny = oy+3.25f;
- text.setFontColor(0, 1, 0, 1);
- String b = npc.getDefinition().behaviour.name();
- if(b.equalsIgnoreCase("Aggressive")){
- text.setFontColor(1, 0, 0, 1);
- }
- text.setLocalPosition(npc.getPosition().x, ny, npc.getPosition().z);
- npc.setAttribute("text", text);
- text3d.add(text);
- updateplayeruis(npc);
- }
- };
- return setNpcInfo;
- }
- public void updateplayeruis(Npc npc){
- Player[] players = Server.getAllPlayers();
- for(Player player : players){
- Text3D text = (Text3D)npc.getAttribute("text");
- player.addGameObject(text);
- }
- }
- @EventMethod
- public void playerchangeposition(PlayerChangePositionEvent evt){
- Player player = evt.getPlayer();
- Npc[] npcs = World.getAllNpcs();
- for(Npc npc : npcs){
- if(npc.hasAttribute("text")){
- Text3D text = (Text3D)npc.getAttribute("text");
- Vector3f pos = npc.getPosition();
- float distance = Utils.MathUtils.distance(pos.x,pos.y,pos.z, player.getPosition().x,player.getPosition().y,player.getPosition().z);
- if(distance<=75){
- text.setActive(true);
- }if(distance>=76){
- text.setActive(false);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement