Skip to content

Instantly share code, notes, and snippets.

@Garris0n-
Garris0n- / lazy cooldown example.java
Last active Aug 29, 2015
Lazy cooldown example
View lazy cooldown example.java
//DISCLAIMER: NOT YET TESTED, THIS CODE MAY CONTAIN SYNTAX ERRORS
//this demonstrates lazy cooldowns, because using a list and a scheduler is an absolutely terrible idea
//BCBroz, why do you cause us so much pain...*sigh*
//in this example, the ability is to be able to break a block instantly with your fist once per minute
//as this is an example for tutorial purposes, a lot of code is dragged out into variables for clarity
//please do not copy-paste or use this code without reading the comments and fully understanding what is going on
private HashMap<UUID, Long> map = new HashMap<UUID, Long>(); //the map to hold our cooldown times
@Garris0n-
Garris0n- / self-cancelling task example.java
Last active Jul 18, 2021
Example of a self-cancelling Bukkit task.
View self-cancelling task example.java
public void countdown(final Player player){ //A method
new BukkitRunnable(){ //BukkitRunnable, not Runnable
int countdown = 10; //Instance variable in our anonymous class to easily hold the countdown value
@Override
public void run(){
if(countdown <= 0 || !player.isOnline()){ //countdown is over or player left the server, just two example reasons to exit
View DimensionChange.java
package de.bananaco.change;
import net.minecraft.server.v1_7_R1.*;
import org.bukkit.*;
import org.bukkit.command.*;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.*;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
public class WorldChanger extends JavaPlugin implements Listener {
View entityregistering.java
((Map) getPrivateStatic(EntityTypes.class, "c")).put(paramString, paramClass);
//Registers the name to the mob, this appears to be for saving nbt tags. Theoretically, this will turn all mobs in your world into your mob, so maybe you shouldn't touch it.
((Map) getPrivateStatic(EntityTypes.class, "d")).put(paramClass, paramString);
//Registers the name you provided. This appears to be used by stuff and not do anything wrong, so you should probably leave this one.
((Map) getPrivateStatic(EntityTypes.class, "e")).put(Integer.valueOf(paramInt), paramClass);
//Registers mob id to this mob, which, I believe, will cause it to become the default mob class for the id provided.
((Map) getPrivateStatic(EntityTypes.class, "f")).put(paramClass, paramInt);
//Registers the mob to the mob id. This is essentially the reverse of e, and, I believe, assigns how the mob will display to clients. I'm pretty sure the client crashes without this one.
((Map) getPrivateStatic(EntityTypes.class, "g")).put(paramString,
@Garris0n-
Garris0n- / gist:8509072
Created Jan 19, 2014
Copy-pasteable info thingy on java/bukkit learning resources
View gist:8509072
Java:
[url=http://docs.oracle.com/javase/tutorial/]Official[/url] | [url=http://thenewboston.org/list.php?cat=31]Youtube[/url] | [url=http://www.pearsonhighered.com/product?ISBN=0132830310]Book[/url]
Bukkit:
[url=http://wiki.bukkit.org/Plugin_Tutorial]Official[/url] | [url=http://www.youtube.com/PogoStick29Dev]Youtube[/url] | [url=http://www.packtpub.com/building-minecraft-server-modifications/book]Book[/url]
View Anvil Opener (1.7.2).java
// https://github.com/Bukkit/CraftBukkit/blob/7e1ac0a77129b169704c1e222ff2deb3ab6cd2d2/src/main/java/net/minecraft/server/EntityPlayer.java#L596
//Method to open an anvil inventory to a player
public static void openAnvil(Player player, Inventory inventory){
//Get our EntityPlayer
EntityPlayer p = ((CraftPlayer) player).getHandle();
//Create the AnvilContainer
AnvilContainer container = new AnvilContainer(p);
@Garris0n-
Garris0n- / LocationStringSerialization.java
Last active Dec 31, 2015
Location <--> String serialization
View LocationStringSerialization.java
//NO YAW/PITCH:
public static String locationToString(Location location){ //Method to turn a location into a string
return location.getWorld() + ";" + location.getX() + ";" + location.getY() + ";" + location.getZ(); //Return a string with the format world;x;y;z
}
public static Location stringToLocation(String string){ //turn a string into a location