You are not logged in.

  • Login
Bitte besucht unser neues Forum unter https://forum.nitrado.net | Please visit our new Forum at https://forum.nitrado.net

Dear visitor, welcome to Nitrado.net Prepaid Gameserver Community-Support - Archiv. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

Dogix

User / Kunde

  • "Dogix" is male
  • "Dogix" started this thread

Posts: 175

Location: localhost

Occupation: Schüler

  • Send private message

1

Friday, June 23rd 2017, 11:26pm

Ballons - Fledermaus & FallingBlock Problem

Guten Tag,
ich sitze derzeit an meinem Extras - System. Nun bin ich bei den Ballons angekommen und habe bereits eine Enum Klasse programmiert.
Das Spawnen der Fledermaus und des FallingBlocks funktioniert, außer das der FallingBlock nicht als Passenger der Fledermaus gesetzt wird
und sie "schläft". Fehler gibt es keine..

Mein Code:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package *.LobbySystem.Enums;

import java.util.HashMap;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Bat;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.Vector;

import *.LobbySystem.Main.Main;

public enum Ballons {

	WERKBANK("Werkbank", org.bukkit.Material.WORKBENCH, (byte) 0);
	
	String Name;
	Material Material;
	Byte Byte;

	public static HashMap<Player, FallingBlock> Block = new HashMap<>();
	public static HashMap<Player, Bat> Bat = new HashMap<>();
	public static HashMap<Player, BukkitTask> Task = new HashMap<>();
	
	Ballons(String Name, Material Material, Byte Byte) {
		this.Name = Name;
		this.Material = Material;
		this.Byte = Byte;
	}
	
	@SuppressWarnings("deprecation")
	public void spawn(Player p) {
		
		FallingBlock FallingBlock = Bukkit.getWorld(p.getWorld().getName()).spawnFallingBlock(p.getLocation().add(0, 1.5, 0), Material, Byte);
		FallingBlock.setDropItem(false);
		Block.put(p, FallingBlock);
		
		Bat Fledermaus = (Bat) Bukkit.getWorld(p.getWorld().getName()).spawnCreature(p.getLocation().add(0, 1.5, 0), EntityType.BAT);
		Fledermaus.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 3, Integer.MAX_VALUE));
		Fledermaus.setLeashHolder(p);
		Fledermaus.setPassenger(FallingBlock);
		Fledermaus.setAwake(true);
		Bat.put(p, Fledermaus);
		
		Task.put(p, new BukkitRunnable() {

			@Override
			public void run() {
				
				if(Fledermaus.getLocation().distance(p.getLocation()) >= 2) {
					Vector v = new Vector(p.getLocation().getX() - Fledermaus.getLocation().getX(), p.getLocation().getY() - Fledermaus.getLocation().getY(), p.getLocation().getZ() - Fledermaus.getLocation().getZ()).normalize().multiply(0.5);
					Fledermaus.setVelocity(v);
				}
				
				if(p.getEyeLocation().getY() - Fledermaus.getLocation().getY() >= 0.25) {
					Fledermaus.setVelocity(new Vector(0, 0.5, 0));
				}
				
				if(Fledermaus.getLocation().distance(p.getLocation()) >= 8) {
					Vector v = new Vector(p.getLocation().getX() - Fledermaus.getLocation().getX(), p.getLocation().getY() - Fledermaus.getLocation().getY(), p.getLocation().getZ() - Fledermaus.getLocation().getZ()).normalize().multiply(1.25);
					Fledermaus.setVelocity(v);
				}
				
			}
			
		}.runTaskTimer(Main.getInstance(), 2, 2));
		
	}
	
	public static void despawn(Player p) {
		
		if(Block.containsKey(p)) {
			Block.get(p).remove();
			Block.remove(p);
		}
		
		if(Bat.containsKey(p)) {
			Bat.get(p).remove();
			Bat.remove(p);
		}
		
		if(Task.containsKey(p)) {
			Task.get(p).cancel();
			Task.remove(p);
		}
		
	}
	
	public String getName() {
		return Name;
	}
	
	public Material getMaterial() {
		return Material;
	}
	
	public Byte getByte() {
		return Byte;
	}
	
}
Mit freundlichen Grüßen
Dennis

Bitte besucht unser neues Forum unter https://forum.nitrado.net| Please visit our new Forum at https://forum.nitrado.net