You are not logged in.

  • Login

[Bukkit-Plugin] Entity Freeze [Hilfe]

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.

Bino3069

User / Kunde

  • "Bino3069" started this thread

Posts: 48

  • Send private message

1

Saturday, September 9th 2017, 2:27pm

Entity Freeze [Hilfe]

Guten Tag,

Ich möchte ein "Entity Freeze" programmieren, sodass das Entity sich nicht bewegen kann und man es auch nicht "schieben"/schubsen kann...

Vielen Dank für die Hilfe

Ceddy_14

User / Kunde

  • "Ceddy_14" is male

Posts: 277

Occupation: Schüler und Projektleiter

Thanks: 15

  • Send private message

2

Monday, September 11th 2017, 5:18pm

Hi,

ich mache das folgendermaßen:

Spoiler Spoiler

Java 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
public class EntityFreeze {
	
	private static final List<Entity> FROZEN_ENTITIES = new LinkedList<Entity>();
	private static Class<?> clazz;
	
	static{
		try{
			clazz = Reflections.getNMSClass("NBTTagCompound");
			
			
		}catch(Exception e){
			clazz = NBTTagEnd.class;
		}
	}
	
	public static void freeze(Entity e){
		try{
			// Getting all needed fields and methods
		
			Method handle = e.getClass().getMethod("getHandle");
			Object nmsEnt = handle.invoke(e);
			Method methC = nmsEnt.getClass().getMethod("c", clazz);
			Method methf = nmsEnt.getClass().getMethod("f", clazz);
			
			
			//Create the Compound
			Object compound = null;
			for(Constructor<?> consts : clazz.getConstructors()){
				if(consts.getParameterCount() == 0) compound = consts.newInstance();
			}
			
			//Add the Compound to the Entity
			methC.invoke(nmsEnt, compound);
			
			//Set the Compounds values
			Method setByte = compound.getClass().getMethod("setByte", String.class, Byte.TYPE);
			setByte.invoke(compound, "NoAI", (byte) 1);
			
			//Register the changes
			methf.invoke(nmsEnt, compound);
			
			FROZEN_ENTITIES.add(e);
		}catch(Exception ex){
			ex.printStackTrace();
		}
	}
	
	public static List<Entity> getFrozenEntites(){
		return ImmutableList.copyOf(FROZEN_ENTITIES);
	}


}



Reflections-Class:

Spoiler Spoiler

Java 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
public class Reflections {
	private Reflections(){}
	
	private static /*final*/ String ver;
	private static final String nms = "net.minecraft.server.";
	
	static{
		try{
			String pkg = Bukkit.getServer().getClass().getPackage().getName();
			ver = pkg.substring(pkg.lastIndexOf(".") + 1);
		}catch(Exception e){
			System.out.println("Couldn't get Bukkit version..");
		} 
	}
	
	public static String version(){
		return ver;
	}
	public static String versionNMS(){
		return nms + version();
	}
	public static Class<?> getNMSClass(String name){
		return getClass(versionNMS() + '.' + name);
	}
	
	public static Class<?> getClass(String name){
		try{
			return Class.forName(name);
		}catch(ClassNotFoundException e){
			e.printStackTrace();
			return null;
		}
	}

}


Hoffe, ich konnte dir helfen!


Mit besten Grüßen
Ceddy
- Projektleiter des CraftGigant-Netzwerks -
:arrow: CraftGigant.de (Version: 1.13.2) [Derzeit in Überarbeitung]
:arrow: twitter.com/craftgigant

Bino3069

User / Kunde

  • "Bino3069" started this thread

Posts: 48

  • Send private message

3

Monday, September 11th 2017, 7:32pm

Vielen Dank!

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