0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

MinecraftのPaperPluginでLocationに躓いた備忘録

Posted at

Locationむずい

event.getPlayer().teleport(100, 60, 100)
こんなのじゃ動いてくれない訳である。
teleportにはLocationが必要なので正しくLocationを指定してやる必要があるのだが、
このLocationという形がそこそこ面倒なのである。

import org.bukkit.Location;の中身を覗いてみると、

public class Location implements java.lang.Cloneable, org.bukkit.configuration.serialization.ConfigurationSerializable, io.papermc.paper.math.FinePosition {
    private java.lang.ref.Reference<org.bukkit.World> world;
    private double x;
    private double y;
    private double z;
    private float pitch;
    private float yaw;

    public Location(@org.bukkit.UndefinedNullability org.bukkit.World world, double x, double y, double z) { /* compiled code */ }

    public Location(@org.bukkit.UndefinedNullability org.bukkit.World world, double x, double y, double z, float yaw, float pitch) { /* compiled code */ }
    
    ...

となっている。

ので、少なくともLocation型を新規作成するときには、下のあいつを呼び出さないといけない。

よって正しくは、

Location {変数名} = new Location(Bukkit.getWorld("World"), 100, 60, 100. 0 ,0);

が正解。

右から順に、

    private java.lang.ref.Reference<org.bukkit.World> world; //ワールドの名前
    private double x; //x座標
    private double y; //y座標
    private double z; //z座標
    private float pitch; //視点の向き(縦)
    private float yaw; //視点の向き(横)

を指定してやれば良いということ

Worldよくわかんない( ᐛ )

Worldの型は、私は全く理解せずに使っているのだが、

とりあえず私は

Bukkit.getWorld("{ワールド名}") 

で使っている。
おそらく、multiverse-coreやserver.propertiesなどでワールド名が変わっている場合、ここも変えないといけない。(逆に言えば、ワールド名をStringで変数として渡せるからそれはそれで拡張性があって便利)
Paperサーバー起動していたらworldとworld-netherがバラバラに生成される時点で大方お察しだが...

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?