Skip to content

Commit

Permalink
Merge pull request #47 from zhuowei/dev
Browse files Browse the repository at this point in the history
v1.9 promote from dev
  • Loading branch information
martinohanlon committed Jan 19, 2017
2 parents f7d2858 + 4216a60 commit 4492cdf
Show file tree
Hide file tree
Showing 16 changed files with 374 additions and 24 deletions.
52 changes: 52 additions & 0 deletions .gitignore
@@ -0,0 +1,52 @@
### Java template
target/

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

### JetBrains template
*.iml
# User-specific stuff:
/.idea/misc.xml
.idea/tasks.xml
.idea/workspace.xml

# Sensitive or high-churn files:
.idea/dataSources/
.idea/dataSources.ids
.idea/dataSources.xml
.idea/dataSources.local.xml
.idea/sqlDataSources.xml
.idea/dynamic.xml
.idea/uiDesigner.xml

# Gradle:
.idea/gradle.xml
.idea/libraries/

## File-based project format:
*.iws

# IntelliJ
/out/

# JIRA plugin
atlassian-ide-plugin.xml


### Eclipse template
.project
.classpath
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
.settings/

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions .idea/codeStyleSettings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions README.md
Expand Up @@ -31,7 +31,10 @@ Extra features(**):
- name added as an option parameter to player calls
- modded minecraft.py in python api library so player "name" can be passed on Minecraft.create(ip, port, name)
- this change does not stop standard python api library being used
- the default tcp port can be changed in config.yml

Config (in config.yml):
- port: 4711 - the default tcp port can be changed in config.yml
- location: RELATIVE - determine whether locations are RELATIVE to the spawn point (default like pi) or ABSOLUTE

** to use the extra features an modded version of the java and python libraries that were originally supplied by Mojang with the Pi is required, https://github.com/zhuowei/RaspberryJuice/tree/master/src/main/resources/mcpi. You only need the modded libraries to use the extra features, the original libraries still work, you just wont be able to use the extra features

Expand All @@ -49,4 +52,4 @@ Version history:
- 1.6 - added getPlayerId(playerName), getDirection, getRotation, getPitch
- 1.7 - added pollChatPosts() & block update performance improvements
- 1.8 - minecraft version 1.9.2 compatibility

- 1.9 - relative and absolute positions added to config.yml
Binary file added jars/raspberryjuice-1.9.jar
Binary file not shown.
44 changes: 37 additions & 7 deletions pom.xml
Expand Up @@ -2,34 +2,64 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.zhuoweizhang</groupId>
<artifactId>raspberryjuice</artifactId>
<version>1.8</version>
<version>1.9</version>
<name>RaspberryJuice</name>
<repositories>
<repository>
<id>bukkit-repo</id>
<url>http://repo.bukkit.org/content/groups/public</url>
<id>elmakers-repo</id>
<url>http://maven.elmakers.com/repository/</url>
</repository>
</repositories>
<build>
<!--Exclude files that aren't actually resources-->
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>mcpi/**/**</exclude>
<exclude>test/**/**</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>craftbukkit-1.9.2-R0.1-SNAPSHOT.jar</version>
<artifactId>craftbukkit</artifactId>
<version>1.9.2-R0.1-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>

<!--Test Dependencies-->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-testng</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jmockit</groupId>
<artifactId>jmockit</artifactId>
<version>1.23</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,9 @@
package net.zhuoweizhang.raspberryjuice;

/**
* Config option to determine whether locations are relative to the spawn point (default like pi) or absolute
* Set in the config.yml.
*/
public enum LocationType {
ABSOLUTE, RELATIVE
}
Expand Up @@ -28,13 +28,25 @@ public class RaspberryJuicePlugin extends JavaPlugin implements Listener {

public Player hostPlayer = null;

private LocationType locationType;

public LocationType getLocationType() {
return locationType;
}

public void onEnable() {
//save a copy of the default config.yml if one is not there
this.saveDefaultConfig();
//get port from config.yml
int port = this.getConfig().getInt("port");

//setup session array
getLogger().info("Using port " + Integer.toString(port));

//get location type (ABSOLUTE or RELATIVE) from config.yml
String location = this.getConfig().getString("location").toUpperCase();
locationType = LocationType.valueOf(location);
getLogger().info("Using " + locationType.name() + " locations");

//setup session array
sessions = new ArrayList<RemoteSession>();

//create new tcp listener thread
Expand Down Expand Up @@ -64,7 +76,7 @@ public void onPlayerInteract(PlayerInteractEvent event) {
session.queuePlayerInteractEvent(event);
}
}

@EventHandler(ignoreCancelled=true)
public void onChatPosted(AsyncPlayerChatEvent event) {
//debug
Expand Down Expand Up @@ -103,7 +115,7 @@ public Player getHostPlayer() {
}
return null;
}

//get entity by id - TODO to be compatible with the pi it should be changed to return an entity not a player...
public Player getEntity(int id) {
for (Player p: getServer().getOnlinePlayers()) {
Expand Down Expand Up @@ -137,7 +149,7 @@ public void onDisable() {
} catch (Exception e) {
e.printStackTrace();
}

sessions = null;
serverThread = null;
getLogger().info("Raspberry Juice Stopped");
Expand Down
70 changes: 61 additions & 9 deletions src/main/java/net/zhuoweizhang/raspberryjuice/RemoteSession.java
Expand Up @@ -12,6 +12,8 @@

public class RemoteSession {

private final LocationType locationType;

private Location origin;

private Socket socket;
Expand Down Expand Up @@ -47,6 +49,7 @@ public class RemoteSession {
public RemoteSession(RaspberryJuicePlugin plugin, Socket socket) throws IOException {
this.socket = socket;
this.plugin = plugin;
this.locationType = plugin.getLocationType();
init();
}

Expand Down Expand Up @@ -92,7 +95,18 @@ public void queueChatPostedEvent(AsyncPlayerChatEvent event) {

/** called from the server main thread */
public void tick() {
if (origin == null) this.origin = plugin.getServer().getWorlds().get(0).getSpawnLocation();
if (origin == null) {
switch (locationType) {
case ABSOLUTE:
this.origin = new Location(plugin.getServer().getWorlds().get(0), 0, 0, 0);
break;
case RELATIVE:
this.origin = plugin.getServer().getWorlds().get(0).getSpawnLocation();
break;
default:
throw new IllegalArgumentException("Unknown location type " + locationType);
}
}
int processedCount = 0;
String message;
while ((message = inQueue.poll()) != null) {
Expand Down Expand Up @@ -249,6 +263,30 @@ protected void handleCommand(String c, String[] args) {
Location loc = currentPlayer.getLocation();
currentPlayer.teleport(parseRelativeBlockLocation(x, y, z, loc.getPitch(), loc.getYaw()));

// player.getAbsPos
} else if (c.equals("player.getAbsPos")) {
String name = null;
if (args.length > 0) {
name = args[0];
}
Player currentPlayer = getCurrentPlayer(name);
send(currentPlayer.getLocation());

// player.setAbsPos
} else if (c.equals("player.setAbsPos")) {
String name = null, x = args[0], y = args[1], z = args[2];
if (args.length > 3) {
name = args[0]; x = args[1]; y = args[2]; z = args[3];
}

Player currentPlayer = getCurrentPlayer(name);
//get players current location, so when they are moved we will use the same pitch and yaw (rotation)
Location loc = currentPlayer.getLocation();
loc.setX(Double.parseDouble(x));
loc.setY(Double.parseDouble(y));
loc.setZ(Double.parseDouble(z));
currentPlayer.teleport(loc);

// player.getPos
} else if (c.equals("player.getPos")) {
String name = null;
Expand All @@ -257,14 +295,14 @@ protected void handleCommand(String c, String[] args) {
}
Player currentPlayer = getCurrentPlayer(name);
send(locationToRelative(currentPlayer.getLocation()));

// player.setPos
} else if (c.equals("player.setPos")) {
String name = null, x = args[0], y = args[1], z = args[2];
if (args.length > 3) {
name = args[0]; x = args[1]; y = args[2]; z = args[3];
}

Player currentPlayer = getCurrentPlayer(name);
//get players current location, so when they are moved we will use the same pitch and yaw (rotation)
Location loc = currentPlayer.getLocation();
Expand Down Expand Up @@ -487,14 +525,14 @@ public Location parseRelativeBlockLocation(String xstr, String ystr, String zstr
int x = (int) Double.parseDouble(xstr);
int y = (int) Double.parseDouble(ystr);
int z = (int) Double.parseDouble(zstr);
return new Location(origin.getWorld(), origin.getBlockX() + x, origin.getBlockY() + y, origin.getBlockZ() + z);
return parseLocation(origin.getWorld(), x, y, z, origin.getBlockX(), origin.getBlockY(), origin.getBlockZ());
}

public Location parseRelativeLocation(String xstr, String ystr, String zstr) {
double x = Double.parseDouble(xstr);
double y = Double.parseDouble(ystr);
double z = Double.parseDouble(zstr);
return new Location(origin.getWorld(), origin.getX() + x, origin.getY() + y, origin.getZ() + z);
return parseLocation(origin.getWorld(), x, y, z, origin.getX(), origin.getY(), origin.getZ());
}

public Location parseRelativeBlockLocation(String xstr, String ystr, String zstr, float pitch, float yaw) {
Expand All @@ -512,13 +550,27 @@ public Location parseRelativeLocation(String xstr, String ystr, String zstr, flo
}

public String blockLocationToRelative(Location loc) {
return (loc.getBlockX() - origin.getBlockX()) + "," + (loc.getBlockY() - origin.getBlockY()) + "," +
(loc.getBlockZ() - origin.getBlockZ());
return parseLocation(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), origin.getBlockX(), origin.getBlockY(), origin.getBlockZ());
}

public String locationToRelative(Location loc) {
return (loc.getX() - origin.getX()) + "," + (loc.getY() - origin.getY()) + "," +
(loc.getZ() - origin.getZ());
return parseLocation(loc.getX(), loc.getY(), loc.getZ(), origin.getX(), origin.getY(), origin.getZ());
}

private String parseLocation(double x, double y, double z, double originX, double originY, double originZ) {
return (x - originX) + "," + (y - originY) + "," + (z - originZ);
}

private Location parseLocation(World world, double x, double y, double z, double originX, double originY, double originZ) {
return new Location(world, originX + x, originY + y, originZ + z);
}

private String parseLocation(int x, int y, int z, int originX, int originY, int originZ) {
return (x - originX) + "," + (y - originY) + "," + (z - originZ);
}

private Location parseLocation(World world, int x, int y, int z, int originX, int originY, int originZ) {
return new Location(world, originX + x, originY + y, originZ + z);
}

public void send(Object a) {
Expand Down

0 comments on commit 4492cdf

Please sign in to comment.