Skocz do zawartości
  • 1

[ blad ] InteractEvent


InawiaczeG1338

Pytanie

	    @EventHandler
    public void onWater(PlayerInteractEvent w))
	    {
	      if (((w.getAction() == Action.RIGHT_CLICK_AIR) || (e1.getAction() == Action.RIGHT_CLICK_BLOCK)) && 
	        (w.getItem().getType().toString().toUpperCase().contains("WATER"))) {
	        w.setCancelled(true);
	      }
	    }

https://scr.hu/kLN3oy

Pomożecie?

Odnośnik do komentarza
https://skript.pl/temat/24821-blad-interactevent/
Udostępnij na innych stronach

14 odpowiedzi na to pytanie

Rekomendowane odpowiedzi

  • 1

Ehhh

@EventHandler
	public void onWater(PlayerInteractEvent w){
		if(w.getAction() == Action.RIGHT_CLICK_AIR || w.getAction() == Action.RIGHT_CLICK_BLOCK){
			if(w.getItem().getType().toString().contains("WATER")){
				w.setCancelled(true);
			}
		}
	}

 

Odnośnik do komentarza
https://skript.pl/temat/24821-blad-interactevent/#findComment-165628
Udostępnij na innych stronach

  • 1
6 minut temu, knugi napisał:

Ehhh


		if(w.getItem().getType().toString().contains("WATER")){

 

Nie.

if(w.getItem().getType() == Material.WATER){

 

Edytowane przez Ixidi
Odnośnik do komentarza
https://skript.pl/temat/24821-blad-interactevent/#findComment-165630
Udostępnij na innych stronach

  • 1
package pl.knugi.test.listeners;

import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;

public class OnInteract implements Listener{
	@EventHandler
	public void onWater(PlayerInteractEvent w){
		if(w.getAction() == Action.RIGHT_CLICK_AIR || w.getAction() == Action.RIGHT_CLICK_BLOCK){
			if(w.getItem().getType() == Material.WATER){{
				w.setCancelled(true);
			}
		}
	}

}

Cały kod. Bez błędów 

Odnośnik do komentarza
https://skript.pl/temat/24821-blad-interactevent/#findComment-165636
Udostępnij na innych stronach

  • 1
7 minut temu, knugi napisał:

package pl.knugi.test.listeners;

import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;

public class OnInteract implements Listener{
	@EventHandler
	public void onWater(PlayerInteractEvent w){
		if(w.getAction() == Action.RIGHT_CLICK_AIR || w.getAction() == Action.RIGHT_CLICK_BLOCK){
			if(w.getItem().getType() == Material.WATER){{
				w.setCancelled(true);
			}
		}
	}

}

Cały kod. Bez błędów 

Puste/pełne wiaderko zwraca Material.WATER?

Odnośnik do komentarza
https://skript.pl/temat/24821-blad-interactevent/#findComment-165641
Udostępnij na innych stronach

  • 0
@EventHandler
public void onUsingWater(PlayerInteractEvent ev) {
	final Action ac = ev.getAction();
	final ItemStack item = ev.getItem();
	if (ac == Action.RIGHT_CLICK_BLOCK || ac == Action.RIGHT_CLICK_AIR) {
		if (item != null && item.getType.toString().toLowerCase().contains("water"))
			ev.setCancelled(true);
	}
}

 

Edytowane przez yooniks
EventHandler
Odnośnik do komentarza
https://skript.pl/temat/24821-blad-interactevent/#findComment-165820
Udostępnij na innych stronach

Nieaktywny
Ten temat został zamknięty. Brak możliwości dodania odpowiedzi.
  • Ostatnio przeglądający   0 użytkowników

    • Brak zarejestrowanych użytkowników przeglądających tę stronę.
×
×
  • Dodaj nową pozycję...