Minecraft plugins

Op deze pagina vind je alle Minecraft Plugins maken Video Lessen!

CODE VOOR DEZE LES :
=============================================
HelloWorld.java

package nl.gamelab.helloworld

import net.canarymod.Canary;
import net.canarymod.plugin.Plugin;

public class HelloWorld extends Plugin {

@Override
public boolean enable() {
Canary.hooks().registerListener(new HelloListener(), this);
getLogman().info("Enabling "+getName() + " Version " + getVersion()); //getName() returns the class name, in this case HelloWorld
getLogman().info("Authored by "+getAuthor());
return true;
}

@Override
public void disable() {
// TODO Auto-generated method stub
}

}

======================================
HelloListener.java:

package nl.gamelab.helloworld;

import net.canarymod.chat.Colors;
import net.canarymod.hook.HookHandler;
import net.canarymod.hook.player.ConnectionHook;
import net.canarymod.plugin.PluginListener;

public class HelloListener implements PluginListener {

@HookHandler
public void onLogin(ConnectionHook hook) {
hook.getPlayer().message(Colors.YELLOW+"Hello World, " +hook.getPlayer().getName());
}
}

===================================
Canary.inf:
main-class = nl.gamelab.helloworld.HelloWorld
name= HelloWorld
author = gamelab
version = 1.0

CODE VOOR DEZE LES :

=============================================
HelloWorld.java

package nl.gamelab.helloworld;

import net.canarymod.Canary;

import net.canarymod.plugin.Plugin;

public class HelloWorld extends Plugin {

@Override

public boolean enable() {

Canary.hooks().registerListener(new HelloListener(), this);

getLogman().info("Enabling "+getName() + " Version " + getVersion()); //getName() returns the class name, in this case HelloWorld

getLogman().info("Authored by "+getAuthor());

return true;

}

@Override

public void disable() {

// TODO Auto-generated method stub

}

}

======================================

HelloListener.java:

package nl.gamelab.helloworld;

import net.canarymod.api.world.blocks.BlockType;

import net.canarymod.chat.Colors;

import net.canarymod.hook.HookHandler;

import net.canarymod.hook.player.BlockDestroyHook;

import net.canarymod.hook.player.ConnectionHook;

import net.canarymod.plugin.PluginListener;

public class HelloListener implements PluginListener {

@HookHandler

public void onLogin(ConnectionHook hook) {

hook.getPlayer().message(Colors.YELLOW+"Hello World 3, "+hook.getPlayer().getName());

}

@HookHandler

public void blockDestroy(BlockDestroyHook hook) { //The name of the method can be anything, it doesn't matter. Important is the hook you set as parameter!

BlockType destroyedThisType = hook.getBlock().getType();

String destroyedThis = destroyedThisType.getMachineName().toString();

hook.getPlayer().message(Colors.RED+"You Destroyed : "+destroyedThis);

if ( destroyedThis.equals("minecraft:stone")) {

hook.getPlayer().message(Colors.LIGHT_GREEN + "Congratulations! You found CobbleStone!");

}else

{

hook.getPlayer().message(Colors.LIGHT_GREEN + "This is definitely no minecraft:stone!");

}

if (destroyedThis.equalsIgnoreCase("minecraft:log")) {

hook.getPlayer().message(Colors.LIGHT_GREEN + "Noooooo! Save the trees!!!!!");

}

}

}

===================================
Canary.inf:
main-class = nl.gamelab.helloworld.HelloWorld
name= HelloWorld
author = gamelab
version = 1.1