Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgraded Bukkit from 1.12.2 to 1.14.4 #80

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ A Bukkit plugin which implements the Minecraft Pi Socket API.
### Commands supported

- world.get/setBlock
- world.getBlockWithData
- world.setBlocks
- world.getPlayerIds
- world.getBlocks
Expand Down Expand Up @@ -35,9 +34,8 @@ A Bukkit plugin which implements the Minecraft Pi Socket API.
- setDirection, setRotation, setPitch functions - set the 'direction' players and entities are facing
- getPlayerId(playerName) - get the entity of a player by name
- pollChatPosts() - get events back for posts to the chat
- setSign(x,y,z,block type id,data,line1,line2,line3,line4)
- Wall signs (id=68 or block.SIGN_WALL.id) require data for facing direction 2=north, 3=south, 4=west, 5=east
- Standing signs (id=63 or block.SIGN_STANDING.id) require data for facing rotation (0-15) 0=south, 4=west, 8=north, 12=east
- setSign(x,y,z,material,facing,line1,line2,line3,line4)
- Facing direction can be NORTH, SOUTH, EAST, WEST...
- spawnEntity(x,y,z,entity) - creates an entity and returns its entity id. see entity.py for list.
- getEntityTypes - returns all the entities supported by the server.
- entity.getName(id) - get a player name for entity id. Reverse of getPlayerId(playerName)
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version>
<version>1.14.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public class RaspberryJuicePlugin extends JavaPlugin implements Listener {

public static final Set<Material> blockBreakDetectionTools = EnumSet.of(
Material.DIAMOND_SWORD,
Material.GOLD_SWORD,
Material.GOLDEN_SWORD,
Material.IRON_SWORD,
Material.STONE_SWORD,
Material.WOOD_SWORD);
Material.WOODEN_SWORD);

public ServerListenerThread serverThread;

Expand Down
61 changes: 28 additions & 33 deletions src/main/java/net/zhuoweizhang/raspberryjuice/RemoteSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.bukkit.*;
import org.bukkit.entity.*;
import org.bukkit.block.*;
import org.bukkit.block.data.Rotatable;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.util.Vector;
Expand Down Expand Up @@ -146,31 +147,27 @@ protected void handleCommand(String c, String[] args) {
// world.getBlock
if (c.equals("world.getBlock")) {
Location loc = parseRelativeBlockLocation(args[0], args[1], args[2]);
send(world.getBlockTypeIdAt(loc));
send(world.getBlockAt(loc).getType().name());

// world.getBlocks
} else if (c.equals("world.getBlocks")) {
Location loc1 = parseRelativeBlockLocation(args[0], args[1], args[2]);
Location loc2 = parseRelativeBlockLocation(args[3], args[4], args[5]);
send(getBlocks(loc1, loc2));

// world.getBlockWithData
} else if (c.equals("world.getBlockWithData")) {
Location loc = parseRelativeBlockLocation(args[0], args[1], args[2]);
send(world.getBlockTypeIdAt(loc) + "," + world.getBlockAt(loc).getData());

// world.setBlock
} else if (c.equals("world.setBlock")) {
Location loc = parseRelativeBlockLocation(args[0], args[1], args[2]);
updateBlock(world, loc, Integer.parseInt(args[3]), (args.length > 4? Byte.parseByte(args[4]) : (byte) 0));
System.out.println("args are " + args[0] + ", " + args[1] + ", " + args[2]);
System.out.println("relative location is " + loc.toString());
updateBlock(world, loc, args[3]);

// world.setBlocks
} else if (c.equals("world.setBlocks")) {
Location loc1 = parseRelativeBlockLocation(args[0], args[1], args[2]);
Location loc2 = parseRelativeBlockLocation(args[3], args[4], args[5]);
int blockType = Integer.parseInt(args[6]);
byte data = args.length > 7? Byte.parseByte(args[7]) : (byte) 0;
setCuboid(loc1, loc2, blockType, data);
String blockType = args[6];
setCuboid(loc1, loc2, blockType);

// world.getPlayerIds
} else if (c.equals("world.getPlayerIds")) {
Expand Down Expand Up @@ -473,15 +470,15 @@ protected void handleCommand(String c, String[] args) {
} else if (c.equals("world.setSign")) {
Location loc = parseRelativeBlockLocation(args[0], args[1], args[2]);
Block thisBlock = world.getBlockAt(loc);
//blockType should be 68 for wall sign or 63 for standing sign
int blockType = Integer.parseInt(args[3]);
//facing direction for wall sign : 2=north, 3=south, 4=west, 5=east
//rotation 0 - to 15 for standing sign : 0=south, 4=west, 8=north, 12=east
byte blockData = Byte.parseByte(args[4]);
if ((thisBlock.getTypeId() != blockType) || (thisBlock.getData() != blockData)) {
thisBlock.setTypeIdAndData(blockType, blockData, true);
}
String blockType = args[3];
String facingDirection = args[4];

updateBlock(thisBlock, blockType);
//plugin.getLogger().info("Creating sign at " + loc);
if ( thisBlock.getBlockData() instanceof Rotatable) {
Rotatable rotatable = (Rotatable) thisBlock.getBlockData();
rotatable.setRotation(BlockFace.valueOf(facingDirection));
}
if ( thisBlock.getState() instanceof Sign ) {
Sign sign = (Sign) thisBlock.getState();
for ( int i = 5; i-5 < 4 && i < args.length; i++) {
Expand All @@ -493,17 +490,15 @@ protected void handleCommand(String c, String[] args) {
// world.spawnEntity
} else if (c.equals("world.spawnEntity")) {
Location loc = parseRelativeBlockLocation(args[0], args[1], args[2]);
Entity entity = world.spawnEntity(loc, EntityType.fromId(Integer.parseInt(args[3])));
Entity entity = world.spawnEntity(loc, EntityType.valueOf(args[3]));
send(entity.getEntityId());

// world.getEntityTypes
} else if (c.equals("world.getEntityTypes")) {
StringBuilder bdr = new StringBuilder();
for (EntityType entityType : EntityType.values()) {
if ( entityType.isSpawnable() && entityType.getTypeId() >= 0 ) {
bdr.append(entityType.getTypeId());
bdr.append(",");
bdr.append(entityType.toString());
if ( entityType.isSpawnable() && !entityType.name().isEmpty() ) {
bdr.append(entityType.name());
bdr.append("|");
}
}
Expand All @@ -524,7 +519,7 @@ protected void handleCommand(String c, String[] args) {
}

// create a cuboid of lots of blocks
private void setCuboid(Location pos1, Location pos2, int blockType, byte data) {
private void setCuboid(Location pos1, Location pos2, String blockType) {
int minX, maxX, minY, maxY, minZ, maxZ;
World world = pos1.getWorld();
minX = pos1.getBlockX() < pos2.getBlockX() ? pos1.getBlockX() : pos2.getBlockX();
Expand All @@ -537,7 +532,7 @@ private void setCuboid(Location pos1, Location pos2, int blockType, byte data) {
for (int x = minX; x <= maxX; ++x) {
for (int z = minZ; z <= maxZ; ++z) {
for (int y = minY; y <= maxY; ++y) {
updateBlock(world, x, y, z, blockType, data);
updateBlock(world, x, y, z, blockType);
}
}
}
Expand All @@ -559,7 +554,7 @@ private String getBlocks(Location pos1, Location pos2) {
for (int y = minY; y <= maxY; ++y) {
for (int x = minX; x <= maxX; ++x) {
for (int z = minZ; z <= maxZ; ++z) {
blockData.append(new Integer(world.getBlockTypeIdAt(x, y, z)).toString() + ",");
blockData.append(world.getBlockAt(x, y, z).getType().name() + ",");
}
}
}
Expand All @@ -568,20 +563,20 @@ private String getBlocks(Location pos1, Location pos2) {
}

// updates a block
private void updateBlock(World world, Location loc, int blockType, byte blockData) {
private void updateBlock(World world, Location loc, String blockType) {
Block thisBlock = world.getBlockAt(loc);
updateBlock(thisBlock, blockType, blockData);
updateBlock(thisBlock, blockType);
}

private void updateBlock(World world, int x, int y, int z, int blockType, byte blockData) {
private void updateBlock(World world, int x, int y, int z, String blockType) {
Block thisBlock = world.getBlockAt(x,y,z);
updateBlock(thisBlock, blockType, blockData);
updateBlock(thisBlock, blockType);
}

private void updateBlock(Block thisBlock, int blockType, byte blockData) {
private void updateBlock(Block thisBlock, String blockType) {
// check to see if the block is different - otherwise leave it
if ((thisBlock.getTypeId() != blockType) || (thisBlock.getData() != blockData)) {
thisBlock.setTypeIdAndData(blockType, blockData, true);
if ((thisBlock.getType().name() != blockType)) {
thisBlock.setType(Material.valueOf(blockType), true);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
port: 4711

# Determine whether locations are RELATIVE to the spawn point (default like pi) or ABSOLUTE
location: RELATIVE
location: ABSOLUTE

# Determine whether hit events are triggered by LEFT clicks, RIGHT clicks or BOTH
hitclick: RIGHT
hitclick: BOTH
31 changes: 5 additions & 26 deletions src/main/resources/mcpi/api/java/src-api/pi/Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,26 @@
*/
public class Block {

final int id, data;
final int id;

Block(int id, int data) {
Block(int id) {
this.id = id;
this.data = data & 0xf;
}

/**
* Get a block with and withId (use a constant like Block.TNT)
*/
public static Block id(int id) {
return new Block(id, 0);
}

/**
* Get a block with extra data
*/
public Block withData(int data) {
return new Block(id, data);
return new Block(id);
}

static Block decode(String s) {
return id(Integer.parseInt(s));
}

static Block decodeWithData(String s) {
String[] ss = s.split(",");
int id = Integer.parseInt(ss[0]);
int data = Integer.parseInt(ss[1]);
return new Block(id, data);
}

@Override
public int hashCode() {
return (id << 8) + data;
return (id << 8);
}

@Override
Expand All @@ -54,15 +39,9 @@ public boolean equals(Object obj) {

@Override
public String toString() {
return id + (data == 0 ? "" : "," + data);
return id;
}

/**
* Get a wool block of a specific color
*/
public static Block wool(Color color) {
return WOOL.withData(color.woolColorData);
}
// Predefined blocks
public static final Block //
AIR = id(0),
Expand Down
4 changes: 0 additions & 4 deletions src/main/resources/mcpi/api/java/src-api/pi/Color.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,4 @@ public enum Color {
LIGHT_GRAY, CYAN, PURPLE, BLUE,
BROWN, GREEN, RED, BLACK;

/**
* the block DATA for the color
*/
final int woolColorData = ordinal();
}
8 changes: 0 additions & 8 deletions src/main/resources/mcpi/api/java/src-api/pi/Minecraft.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,6 @@ public Block getBlock(Vec position) {
return Block.decode(receive());
}

/**
* Get a block
*/
public Block getBlockWithData(Vec position) {
send("world.getBlock", position);
return Block.decodeWithData(receive());
}

/**
* Set a block
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static void drawChristmasTree(Minecraft mc, Vec p) {

// Draw "branches"
for (int i = 0; i < tree.length; i++) {
drawDisc(mc, p.add(0, h, 0), tree[tree.length - i - 1], Block.LEAVES.withData(1));
drawDisc(mc, p.add(0, h, 0), tree[tree.length - i - 1], Block.LEAVES);
h++;
}

Expand Down
Loading