CONNEXION
  • RetourJeux
    • Sorties
    • Hit Parade
    • Les + populaires
    • Les + attendus
    • Soluces
    • Tous les Jeux
    • Gaming
  • RetourActu Gaming
    • News
    • Astuces
    • Tests
    • Previews
    • Toute l'actu gaming
  • RetourBons plans
    • Bons plans
    • Bons plans Smartphone
    • Bons plans Hardware
    • Bons plans Image et Son
    • Bons plans Amazon
    • Bons plans Cdiscount
    • Bons plans Decathlon
    • Bons plans Fnac
    • Tous les Bons plans
  • RetourJVTech
    • Actus High-Tech
    • Intelligence Artificielle
    • Smartphones
    • Mobilité urbaine
    • Hardware
    • Image et son
    • Tutoriels
    • Tests produits High-Tech
    • Guides d'achat High-Tech
    • JVTech
  • RetourCulture
    • Actus Culture
    • Culture
  • RetourVidéos
    • A la une
    • Gaming Live
    • Vidéos Tests
    • Vidéos Previews
    • Gameplay
    • Trailers
    • Chroniques
    • Replay Web TV
    • Toutes les vidéos
  • RetourForums
    • Hardware PC
    • PS5
    • Switch 2
    • Xbox Series
    • Switch
    • Pokemon pocket
    • FC 25 Ultimate Team
    • League of Legends
    • Tous les Forums
  • PC
  • PS5
  • Xbox Series
  • Switch 2
  • PS4
  • One
  • Switch
  • iOS
  • Android
  • MMO
  • RPG
  • FPS
En ce moment Genshin Impact Valhalla Breath of the wild Animal Crossing GTA 5 Red dead 2
Minecraft
  • Tout support
  • PC
  • Xbox Series
  • Switch
  • PS4
  • ONE
  • WiiU
  • PS3
  • 360
  • Vita
  • iOS
  • Android
  • Web
  • New 3DS
Forum
  • Accueil
  • Actus
  • Tests
  • Vidéos
  • Images
  • Soluces
  • Forum
Liste des sujets

Problème de Message en Console (code java plugin)

DuckInGame
DuckInGame
Niveau 3
02 mai 2019 à 18:59:24

Bonjour j'ai créer ce plugin ou le code c'est ça:

package fr.kenzogamig.nfd;

import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.plugin.java.JavaPlugin;

public class Main extends JavaPlugin implements Listener {
	
	@Override
	public void onEnable() {
		System.out.println("[BressoliaNoFall] Le plugin vient de demarrer");
		getServer().getPluginManager().registerEvents(this, this);
	}
	
	@EventHandler
	private void playerfall(EntityDamageEvent e) {
		Player p = (Player)e.getEntity();
		Location loc = p.getLocation();
		if(e.getCause() == DamageCause.FALL) {
			e.setCancelled(true);
			p.sendMessage("§7Tu vient de faire une chute et le serveur protège contre les dégàts de chute");
			p.playSound(loc, Sound.BLOCK_NOTE_HARP, 10f, 1f);
			return;
		}
	}
	
	@EventHandler
	public void playervoid(EntityDamageEvent e) {
		Player player = (Player)e.getEntity();
		Location loc2 = player.getLocation();
		if(e.getCause() == DamageCause.VOID) {
			e.setCancelled(true);
			player.playSound(loc2, Sound.BLOCK_NOTE_HARP, 10f, 1f);
			return;
		}
	}
	
	@Override
	public void onDisable() {
		System.out.println("[BressoliaNoFall] Le plugin vient de s'eteindre");
	}

}

et le problème c'est que sa me met un message déguelasse comme sa

[17:58:40 ERROR]: Could not pass event EntityDamageEvent to BressoliaNoFall v1.0.0
org.bukkit.event.EventException: null
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:309) ~[spigot.jar:git-Spigot-518206a-a5b9c7b]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-518206a-a5b9c7b]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:500) [spigot.jar:git-Spigot-518206a-a5b9c7b]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:485) [spigot.jar:git-Spigot-518206a-a5b9c7b]
        at org.bukkit.craftbukkit.v1_13_R2.event.CraftEventFactory.callEvent(CraftEventFactory.java:101) [spigot.jar:git-Spigot-518206a-a5b9c7b]
        at org.bukkit.craftbukkit.v1_13_R2.event.CraftEventFactory.callEntityDamageEvent(CraftEventFactory.java:757) [spigot.jar:git-Spigot-518206a-a5b9c7b]
        at org.bukkit.craftbukkit.v1_13_R2.event.CraftEventFactory.handleEntityDamageEvent(CraftEventFactory.java:743) [spigot.jar:git-Spigot-518206a-a5b9c7b]
        at org.bukkit.craftbukkit.v1_13_R2.event.CraftEventFactory.handleLivingEntityDamageEvent(CraftEventFactory.java:789) [spigot.jar:git-Spigot-518206a-a5b9c7b]
        at net.minecraft.server.v1_13_R2.EntityLiving.damageEntity0(EntityLiving.java:1445) [spigot.jar:git-Spigot-518206a-a5b9c7b]
        at net.minecraft.server.v1_13_R2.EntityLiving.damageEntity(EntityLiving.java:967) [spigot.jar:git-Spigot-518206a-a5b9c7b]
        at net.minecraft.server.v1_13_R2.EntityMonster.damageEntity(SourceFile:61) [spigot.jar:git-Spigot-518206a-a5b9c7b]
        at net.minecraft.server.v1_13_R2.EntityZombie.damageEntity(EntityZombie.java:260) [spigot.jar:git-Spigot-518206a-a5b9c7b]
        at net.minecraft.server.v1_13_R2.Entity.W(Entity.java:450) [spigot.jar:git-Spigot-518206a-a5b9c7b]
        at net.minecraft.server.v1_13_R2.EntityLiving.W(EntityLiving.java:210) [spigot.jar:git-Spigot-518206a-a5b9c7b]
        at net.minecraft.server.v1_13_R2.EntityInsentient.W(EntityInsentient.java:188) [spigot.jar:git-Spigot-518206a-a5b9c7b]
        at net.minecraft.server.v1_13_R2.Entity.tick(Entity.java:331) [spigot.jar:git-Spigot-518206a-a5b9c7b]
        at net.minecraft.server.v1_13_R2.EntityLiving.tick(EntityLiving.java:2026) [spigot.jar:git-Spigot-518206a-a5b9c7b]
        at net.minecraft.server.v1_13_R2.EntityInsentient.tick(EntityInsentient.java:248) [spigot.jar:git-Spigot-518206a-a5b9c7b]
        at net.minecraft.server.v1_13_R2.EntityMonster.tick(SourceFile:40) [spigot.jar:git-Spigot-518206a-a5b9c7b]
        at net.minecraft.server.v1_13_R2.EntityZombie.tick(EntityZombie.java:177) [spigot.jar:git-Spigot-518206a-a5b9c7b]
        at net.minecraft.server.v1_13_R2.World.entityJoinedWorld(World.java:1326) [spigot.jar:git-Spigot-518206a-a5b9c7b]
        at net.minecraft.server.v1_13_R2.World.g(World.java:1293) [spigot.jar:git-Spigot-518206a-a5b9c7b]
        at net.minecraft.server.v1_13_R2.World.tickEntities(World.java:1127) [spigot.jar:git-Spigot-518206a-a5b9c7b]
        at net.minecraft.server.v1_13_R2.WorldServer.tickEntities(WorldServer.java:583) [spigot.jar:git-Spigot-518206a-a5b9c7b]
        at net.minecraft.server.v1_13_R2.MinecraftServer.b(MinecraftServer.java:967) [spigot.jar:git-Spigot-518206a-a5b9c7b]
        at net.minecraft.server.v1_13_R2.DedicatedServer.b(DedicatedServer.java:417) [spigot.jar:git-Spigot-518206a-a5b9c7b]
        at net.minecraft.server.v1_13_R2.MinecraftServer.a(MinecraftServer.java:830) [spigot.jar:git-Spigot-518206a-a5b9c7b]
        at net.minecraft.server.v1_13_R2.MinecraftServer.run(MinecraftServer.java:728) [spigot.jar:git-Spigot-518206a-a5b9c7b]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_211]
Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_13_R2.entity.CraftZombie cannot be cast to org.bukkit.entity.Player
        at fr.kenzogamig.nfd.Main.playervoid(Main.java:34) ~[?:?]
        at sun.reflect.GeneratedMethodAccessor22.invoke(Unknown Source) ~[?:?]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_211]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_211]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:305) ~[spigot.jar:git-Spigot-518206a-a5b9c7b]
        ... 28 more

Merci d'avance de votre réponse, cordialement DuckInGame/kenzogamig x)

Nintendo82
Nintendo82
Niveau 8
02 mai 2019 à 20:51:14

Je ne m'y connais pas vraiment en Java, mais d'après ce que je vois, ça a peut-être un rapport avec le .jar de Spigot que tu utilises. Le serveur où tu testes le plugin utilise-t-il la même version de Spigot que celle utilisée pour la création du plugin ?

LeGeko
LeGeko
Niveau 15
02 mai 2019 à 21:02:39
Player p = (Player)e.getEntity();

Rien ne dit que l'entité est un joueur :(
Fais d'abord une condition
if(e.getEntity() instanceOf Player) { Player p = (Player)e.getEntity(); //La suite du code }
Je sais pas si le problème vient vraiment de là, mais ça évitera d'en avoir d'autres par la suite

-[Franckyi]-
-[Franckyi]-
Niveau 10
02 mai 2019 à 21:05:41

Non, le problème vient bien du code.
EntityDamageEvent se déclenche pour tout type d'Entity. Dans ton code, tu assumes directement que l'Entity est de type Player.
Or ce n'est pas toujours le cas, d'où ton erreur : tu as essayé de convertir un Zombie en Player.
Avant ta ligne Player p = (Player)e.getEntity();, tu dois vérifier que l'Entity est bien de type Player, en faisant par exemple :
Entity entity = e.getEntity(); if (entity instanceof Player) { Player p = (Player) entity; // la suite de ton code }

Edit : ah mince, mon VDD a été plus rapide :hap:

Message édité le 02 mai 2019 à 21:06:14 par -[Franckyi]-
LeGeko
LeGeko
Niveau 15
02 mai 2019 à 21:16:35

Au moins t'es plus précis :o))

LeGeko
LeGeko
Niveau 15
02 mai 2019 à 21:31:10

Et tu pourrais passer par un switch pour détecter le type de dégât, ce serait plus simple.
T'as pas non plus besoin de mettre return à la fin des evenst, y a déjà plus rien qui peut s'exécuter après

DuckInGame
DuckInGame
Niveau 3
03 mai 2019 à 00:20:13

OK merci les gas

Sous forums
  • Recherche de joueurs et serveurs PC/Consoles