Skip to content

Instantly share code, notes, and snippets.

View natemort's full-sized avatar

Nate Mortensen natemort

View GitHub Profile
import java.util.Map;
import java.util.HashMap;
class Java {
public static void main(String[] args) {
// Associate(or map) string values to numbers(Integerrs)
Map<String, Integer> map = new HashMap<String, Integer>();
// map["joe"] = 1;
map.put("Joe", 1);
map.put("Nate", 2);
// joe = 1, nate = 2
@natemort
natemort / NameFetcher.java
Last active September 24, 2017 13:31
NameFetcher version 4, utilizing Mojang's name history API which doesn't get rate limited as hard.
/*
* Copyright (c) 2015 Nate Mortensen
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
@natemort
natemort / CompletionFuture.java
Created June 19, 2015 19:30
A utility class I wrote that I keep coming back to. A class like this was added in Java 8 (https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html ), but if that's not an option, you've got this.
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
/**
* Add a Future object that doesn't involve Runnables or anything fancy.
* It allows for checking for completion, waiting until completion, and getting the value.
* Nice and simple.
*
@natemort
natemort / Database
Last active August 29, 2015 14:13
example 2
public @interface Database {
public DatabaseType value();
}
@natemort
natemort / NmsThing1_6
Created January 11, 2015 01:19
Example for BukkitGuice
@PluginService(value=SomeNmsThing.class, minecraftVersion="1_6R1")
public class NmsThing1_6 implements SomeNmsThing {
void doSomething() {}
}
#include <hxcpp.h>
#ifndef INCLUDED_Test
#include <Test.h>
#endif
#ifndef INCLUDED_haxe_Log
#include <haxe/Log.h>
#endif
Void Test_obj::__construct()
@natemort
natemort / Wee.hx
Created December 5, 2014 04:17
What should the value of someVariable be? Is it valid to initialize fields in an interface? Javascript says it's valid, and that the value should be 3. However, if someVariable isn't initialized in TestImplementation, the field gets stripped out and the generated javascript will result in an error. C# code is generated, but fails to compile, sta…
class Test {
static function main() {
var test = new TestImplementation();
trace(test.someVariable + "");
}
}
interface TestInterface {
public var someVariable:Int = 2;
}
@natemort
natemort / CB
Last active August 29, 2015 14:00
PlayerVaults serialized inventory
test:
==: org.bukkit.inventory.ItemStack
type: POTION
meta:
==: ItemMeta
meta-type: POTION
custom-effects:
- ==: PotionEffect
effect: 11
duration: 60
package com.evilmidget38.example;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.configuration.serialization.ConfigurationSerialization;
public void saveChestFile(Location loc, Inventory inv, String playerName){
File file = new File(getDataFolder(), loc.toString() + ".yml");
//Create a new File if one does not exist
if(!file.exists()){
try{
file.createNewFile();
}catch(IOException e){
getLogger().severe("Could not create a new chest file for chest at " + loc.toString());
}