[Spigot]転移ゲートシステムがうまく働きません

Modやプラグインの制作/開発に関する質問はこちらへどうぞ。
ゲスト
ID: 23BN3NPNFE

[Spigot]転移ゲートシステムがうまく働きません

投稿記事 by ゲスト » 2020年7月23日(木) 13:39

Locationで座標取得し、ブロック判定しているのにもかかわらず、どこでも転移ゲートの作用が働いてしまいます

転移ゲートは二種類あり、1段目と3段目のブロックの種類で、普通の地面でないか・どちらの転移ゲートか、を判別しています。
・転移1:一段目は黒色の色付きガラス、三段目はマグマブロック
・転移2:一段目は黒色の色付きガラス、三段目はネザーラック

locationで指定位置の座標を取得、変数に代入し、ifでMaterialTypeの判定をしているのですが、
なぜか、地面についた時点でテレポートしてしまいます。

ちなみにこれが実装部分です。(いろいろ試したため、要らない部分があります。)

コード: 全て選択

public class UnderworldGateListener implements Listener {
	public UnderworldGateListener(PluginMain plugin) {
		plugin.getServer().getPluginManager().registerEvents(this, (Plugin)plugin);
	}

	//@SuppressWarnings("unlikely-arg-type")
	@EventHandler
	public void onGateToUnderworld(PlayerMoveEvent event) {
		Player player = event.getPlayer();
		if (player.isOnGround()) {
			Location location = event.getTo().clone();
			Location location2 = event.getTo().clone();
			Location underworld = event.getTo();
			location.add(0, -0.1, 0);
			location2.add(0, -2.1, 0);
			underworld.add(233.5, 204.0, -253.5);
			//ItemStack Glass = new ItemStack(Material.STAINED_GLASS, 1, (byte) 15);
			if (location.getBlock().getType().equals(Material.STAINED_GLASS)) {
				if (location2.getBlock().getType().equals(Material.MAGMA)) {
					player.teleport(underworld);
					player.sendTitle("地下世界", "Under world", 10, 40, 10);
				}
			}
		}
	}

	//@SuppressWarnings("unlikely-arg-type")
	@EventHandler
	public void onGateToGround(PlayerMoveEvent event) {
		Player player = event.getPlayer();
		if (player.isOnGround()) {
			Location location = event.getTo().clone();
			Location location2 = event.getTo().clone();
			Location ground = event.getTo();
			location.add(0, -0.1, 0);
			location2.add(0, -2.1, 0);
			ground.add(15.5, 5.0, -266.5);
			//ItemStack Glass = new ItemStack(Material.STAINED_GLASS, 1, (byte) 15);
			if (location.getBlock().getType().equals(Material.STAINED_GLASS)) {
				if (location2.getBlock().getType().equals(Material.NETHERRACK)) {
					player.teleport(ground);
					player.sendTitle("地上世界", "Terrestrial world", 10, 40, 10);
					player.playSound(player.getLocation(), Sound.BLOCK_NOTE_CHIME, 1, 24);
				}
			}
		}
	}



アバター
Reiga
ID: 23BN3NPNFE
記事: 36
登録日時: 2019年12月24日(火) 15:11
お住まい: 自室
Minecraft ID: Ign1s_Reiga
いいね: 1回
連絡する:

Re: [Spigot]転移ゲートシステムがうまく働きません

投稿記事 by Reiga » 2020年7月23日(木) 13:40

ログインするのを忘れていました...
0

アバター
Reiga
ID: 23BN3NPNFE
記事: 36
登録日時: 2019年12月24日(火) 15:11
お住まい: 自室
Minecraft ID: Ign1s_Reiga
いいね: 1回
連絡する:

Re: [Spigot]転移ゲートシステムがうまく働きません

投稿記事 by Reiga » 2020年7月23日(木) 16:28

すみません。自己解決しました。

動いたバージョン

コード: 全て選択

public class UnderworldGateListener implements Listener {
	public UnderworldGateListener(PluginMain plugin) {
		plugin.getServer().getPluginManager().registerEvents(this, (Plugin)plugin);
	}

	//@SuppressWarnings("unlikely-arg-type")
	@EventHandler
	public void onGateToUnderworld(PlayerMoveEvent event) {
		Player player = event.getPlayer();
		if (player.isOnGround()) {
			Location location = event.getPlayer().getLocation();
			Location location2 = event.getPlayer().getLocation();;
			location.add(0, -0.1, 0);
			location2.add(0, -2.1, 0);
			//ItemStack Glass = new ItemStack(Material.STAINED_GLASS, 1, (byte) 15);
			if (location.getBlock().getType().equals(Material.STAINED_GLASS)) {
				if (location2.getBlock().getType().equals(Material.MAGMA)) {
					World world = player.getWorld();
					Location underworld = new Location(world, 233.5, 204.0, -253.5);
					player.teleport(underworld);
					player.sendTitle("地下世界", "Under world", 10, 40, 10);
				}
			}
		}
	}

	//@SuppressWarnings("unlikely-arg-type")
	@EventHandler
	public void onGateToGround(PlayerMoveEvent event) {
		Player player = event.getPlayer();
		if (player.isOnGround()) {
			Location location = event.getPlayer().getLocation();
			Location location2 = event.getPlayer().getLocation();
			location.add(0, -0.1, 0);
			location2.add(0, -2.1, 0);
			//ItemStack Glass = new ItemStack(Material.STAINED_GLASS, 1, (byte) 15);
			if (location.getBlock().getType().equals(Material.STAINED_GLASS)) {
				if (location2.getBlock().getType().equals(Material.NETHERRACK)) {
					World world = player.getWorld();
					Location ground = new Location(world, 15.5, 5.0, -266.5);
					player.teleport(ground);
					player.sendTitle("地上世界", "Terrestrial world", 10, 40, 10);
					player.playSound(player.getLocation(), Sound.BLOCK_NOTE_CHIME, 1, 24);
				}
			}
		}
	}
}
0

返信する