Skip to content

Instantly share code, notes, and snippets.

@Garris0n-
Garris0n- / lazy cooldown example.java
Last active August 1, 2022 17:24
Lazy cooldown example
//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 January 12, 2022 00:07
Example of a self-cancelling Bukkit task.
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
@Garris0n-
Garris0n- / gist:8509072
Created January 19, 2014 18:42
Copy-pasteable info thingy on java/bukkit learning resources
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]
// 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 December 31, 2015 14:28
Location <--> String serialization
//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
@Garris0n-
Garris0n- / gist:d667ec05fe47e25674b7
Created October 9, 2014 03:16
people whose lists I trust
hintss
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 {
@Garris0n-
Garris0n- / entityregistering.java
Created January 29, 2014 16:13
Entity Registering
((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,