Skip to content

Instantly share code, notes, and snippets.

CraftBukkit Scoreboard - Current Bug

Sometimes, when a player logs onto a server, the scoreboard is not properly sent. This can result in a client-side NullPointerException when the Scoreboard display slot is set for an objective already in that exact same slot. Here is an example stacktrace:

java.lang.NullPointerException
at arj.k(SourceFile:133)
at bdl.a(SourceFile:1086)
at fc.a(SourceFile:43)
at ci.b(SourceFile:350)
at bdl.d(SourceFile:95)
@riking
riking / mcmodchooser.bat
Created April 4, 2013 21:12
Mc Mod Chooser Batch program from several months ago. Enjoy.
@echo off
color 0a
SETLOCAL ENABLEEXTENSIONS
if errorlevel 1 echo this shouldnt happen
SETLOCAL ENABLEDELAYEDEXPANSION
if errorlevel 1 echo this shouldnt happen
set execdir=%0
::you have to change more than the two numbers below to change number of mod slots
set modmin=1
set modmax=9
@riking
riking / TestPlugin.java
Created April 7, 2013 00:15
QuitReason test plugin
package test;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.event.Listener;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public class TestPlugin extends JavaPlugin implements Listener {
public void onEnable() {
@riking
riking / TestPlugin.java
Created April 7, 2013 00:16
InventoryPaintEvent test plugin
package test;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.event.Listener;
import org.bukkit.event.EventHandler;
import org.bukkit.event.inventory.InventoryPaintEvent;
public class TestPlugin extends JavaPlugin implements Listener {
public void onEnable() {
getServer().getPluginManager().registerEvents((Listener)this, (JavaPlugin)this);

Packet 102

These are the click actions in Packet 102:

  • Shift=0
    • Button 0 = Left Mouse
    • Button 1 = Right Mouse
  • Shift=1
    • Button 0 = Shift + Left Mouse
    • Button 1 = Shift + Right Mouse (identical behavior to shiftleft)
  • Shift=2
Add events for new inventory features in 1.5
This commit brings the InventoryClickEvent in line with the new Minecraft changes in 1.5.
InventoryDragEvent (thanks to @YLivay for his PR) is added to represent the new "dragging" or "painting"
functionality, where if you hold an itemstack and click-drag over several slots, the items will be split
evenly (left click) or 1 each (right click). The InventoryAction enum is used for all the other new
actions.
Additionally, handling of creative inventory editing is improved with InventoryCreativeEvent, and
handling of numberkey presses is also improved within InventoryClickEvent and CraftItemEvent.
public enum InventoryAction {
/**
* left / right: cursor / current are different
*/
SWAP,
/**
* right: cursor not empty, current is same material or empty and not full
* rightdrag: only one slot
*/
PLACE_ONE,
if (clickedItem.doMaterialsMatch(cursor) && ItemStack.equals(clickedItem, cursor)) {
int toPlace = packet102windowclick.button == 0 ? clickedItem.count : 1;
toPlace = Math.min(toPlace, clickedItem.count - cursor.count);
toPlace = Math.min(toPlace, clickedItem.getMaxStackSize() - cursor.count);
toPlace = Math.min(toPlace, slot.inventory.getMaxStackSize() - cursor.count);
if (toPlace == 1) {
action = InventoryAction.PLACE_ONE;
} else if (toPlace == cursor.count) {
action = InventoryAction.PLACE_ALL;
} else if (toPlace <= 0) {
1. Server sends public key to client
- Call this EB
2. Client generates random number
- Call this random number RA
- Call client's name IA
3. Client computes EB(IA, RA) and sends to server
4. Server uses IA to look up EA
5. Server generates random number
- Call this random number RB
6. Server computes session key
public void checkSession() throws ExceptionWorldConflict { // CraftBukkit - throws ExceptionWorldConflict
try {
File file1 = new File(this.baseDir, "session.lock");
DataInputStream datainputstream = new DataInputStream(new FileInputStream(file1));
try {
if (datainputstream.readLong() != this.sessionId) {
throw new ExceptionWorldConflict("The save is being accessed from another location, aborting");
}
} finally {