Skip to content

Instantly share code, notes, and snippets.

@walterhiggins
Last active May 15, 2016 19:01
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walterhiggins/8b0a2ddead1118de0546 to your computer and use it in GitHub Desktop.
Save walterhiggins/8b0a2ddead1118de0546 to your computer and use it in GitHub Desktop.
Writing Minecraft Plugins: Errata

A Beginner's Guide to Writing Minecraft Plugins: Errata

Introduction

This is list of errors and their corrections that were found after the book was published. This document is a work in progress. If you find additional mistakes in the book please email walter.higgins@gmail.com.

Chapter 7

Page 84, Listing 7.3

The following code is listed with no explanation of the === operator and how it differs from the == operator which is explained in Chapter 3 (Comparing numbers):

if ( typeof sides === 'undefined' ) {
  sides = 6;
}

Like the == operator, the === is also used to compare two values in Javascript. However, the === uses a stricter set of rules for comparing two values, it tests that the values are of the same type and are equivalent. The == operator will resolve to true for the following comparisons:

4 + 1 == "5" 
0 == false 
'' == false 
1 == true 
'1' == true

This is because the == operator will try to convert the left and right operands (the values on either side of the == operator) so that they are the same type before comparing.

The === operator does no such conversion. It compares both the type and values and both type and value must be the same. This is why the === operator is more strict when comparing values. All of the above comparisons will return false because the types being compared are not the same. So the comparison 4 + 1 == '5' will evaluate to true but the comparison 4 + 1 === '5' evaluates to false because the number 5 is not the same as the string '5' when using the === comparison operator.

Page 85, 2nd Paragraph

The explanation for the code typeof sides === 'undefined' is incorrect. It reads:

The code inside the parentheses, typeof sides === 'undefined', returns the type of the sides parameter.

It should instead read:

The code inside the parentheses, typeof sides === 'undefined' does 2 things. The typeof sides expression gets the type of the sides parameter. This value is compared using the strict === operator to the string 'undefined'.

A better approach still when testing to see if a value is undefined is to compare it to the literal undefined using the === operator:

if ( sides === undefined ) {
  sides = 6;
}

Chapter 8

Page 93, 3rd Paragraph

The code js console.log(farmAnimals) will not always display the array contents. Some versions of Java will instead display [object Array] or jdk.nashorn.internal.objects.NativeArray@ . This is because different versions of Java display Javascript arrays differently. The code should instead read:

js console.log('' + farmAnimals)

The '' (single-quoted) string prefix forces the array contents to be displayed.

Page 95, Code Section, 2nd Statement

The following statment:

/js var greetings = require('greetings');

Should instead read:

/js var greetings = require('greeting');

The name of the module which must be required is 'greeting' not 'greetings'.

Chapter 9

Page 104, 2nd Paragraph

At the end of the paragraph, the book instructs you to issue the following commands at the server console prompt:

/js refresh();
/js guessTheNumber( self )

These commands should be issued at the in-game prompt instead because conversations only work within the in-game prompt, not the server prompt.

Page 106

There is an error in the code section half way down the page. The code should only be typed into the in-game prompt and should be as follows:

/js var input = require('input');
/js function respond( answer, player ) { echo(player,"Wow. " + answer + " that's old!" ) }
/js input( self, 'How old are you?', respond )

Once you've issued the above commands at the in-game prompt, press the T key to begin typing a response to the question How old are you?.

Page 116, Last Paragraph

The final sentence refers to appendices which were not included in the book. For a list of all of the items functions, please visit ScriptCraft's Online API reference instead https://github.com/walterhiggins/ScriptCraft/blob/master/docs/API-Reference.md#items-module

Chapter 11

Page 143

Beneath the code listing 11.4 there is a short 3 line code section:

var player = players[i];
var jumpStats = player.getStatistic( bukkit.stat.JUMP );
echo( receiver, player.name + ' ' + jumpStats);

The code section should instead read:

var player = players[i];
var jumpStats = player.getStat( utils.stat.JUMP );
echo( receiver, player.name + ' ' + jumpStats);

That is: the expression player.getStatistic( bukkit.stat.JUMP ); should be replaced with player.getStat( utils.stat.JUMP );. The code listing 11.4 is correct so you won't need to make any code changes.

Page 149

In paragraph 5 there are 2 javascript statements...

/js function boo( params, sender ) { echo( sender, 'Boo!') }
/js command( boo );

These statements should be entered at the in-game prompt not the server-console prompt. If entered at the server-console prompt you will see an error. The server console treats the ! (exclamation) character differently.

Chapter 14

Page 183, 2nd last Code example

There's an error in one of the code examples. The following code:

/js for (var key in myFirstObject){ self.sendMessage( key ) }

... should instead read:

/js for (var key in myFirstObject){ echo(self, key ) }

That is: the expression self.sendMessage( key ) should be replaced with echo( self, key ) .

Explanation

The expression self.sendMessage() only works with Bukkit and SpigotMC Minecraft servers. The book was originally written using the Bukkit API but was rewritten for use with CanaryMod when Bukkit was discontinued. The echo() function behaves much like the self.sendMessage() function but is compatible with both Bukkit/SpigotMC and CanaryMod.

Page 190, 1st Paragraph

The text:

Make your game mode creative by issuing the /gamemode survival command

...should instead read:

Make your game mode survival by issuing the /gamemode survival command

Page 190, 5th Paragraph

The text:

You're also going to change how you call the drop() function.

... should instead read:

You're also going to change how you call the boost() function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment