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

Added multiple worldsupport #100

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,13 @@ public HitClickType getHitClickType() {

public void onEnable() {
//save a copy of the default config.yml if one is not there
this.saveDefaultConfig();
//get host and port from config.yml
this.saveDefaultConfig();
//get host and port from config.yml
String hostname = this.getConfig().getString("hostname");
if (hostname == null || hostname.isEmpty()) hostname = "0.0.0.0";
if (hostname == null || hostname.isEmpty()) {
hostname = "0.0.0.0";
this.getConfig().set("hostname", "0.0.0.0");
}
int port = this.getConfig().getInt("port");
getLogger().info("Using host:port - " + hostname + ":" + Integer.toString(port));

Expand All @@ -66,7 +69,15 @@ public void onEnable() {
locationType = LocationType.valueOf("RELATIVE");
}
getLogger().info("Using " + locationType.name() + " locations");


//get world (and set it to default if empty) from config.yml
String world = this.getConfig().getString("world");
if (world == null || world.isEmpty()) this.getConfig().set("world", getServer().getWorlds().get(0).getName());
this.saveConfig();
this.reloadConfig();

getLogger().info("Using " + world + " as the active world!");

//get hit click type (LEFT, RIGHT or BOTH) from config.yml
String hitClick = this.getConfig().getString("hitclick").toUpperCase();
try {
Expand Down
54 changes: 53 additions & 1 deletion src/main/java/net/zhuoweizhang/raspberryjuice/RemoteSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import org.bukkit.Bukkit;
import org.bukkit.Location;
Expand Down Expand Up @@ -170,7 +172,24 @@ protected void handleCommand(String c, String[] args) {
Server server = plugin.getServer();

// get the world
World world = origin.getWorld();
String worldString = plugin.getConfig().getString("world");
World world;

List<World> worldsList = Bukkit.getWorlds();
List<String> worldNamesList = new ArrayList<String>();

for(World w: worldsList){
worldNamesList.add(w.getName());
}

if((worldNamesList.contains(worldString)) && (worldString != null)) {
world = plugin.getServer().getWorld(worldString);
} else {
world = plugin.getServer().getWorlds().get(0);
plugin.getConfig().set("world", world.getName());
plugin.saveConfig();
plugin.reloadConfig();
}

// world.getBlock
if (c.equals("world.getBlock")) {
Expand Down Expand Up @@ -621,6 +640,39 @@ protected void handleCommand(String c, String[] args) {
}
}
send(bdr.toString());

//getWorlds
} else if (c.equals("getWorlds")) {

String worldNames = "";
List<World> worlds = Bukkit.getWorlds();
for(World w: worlds){
worldNames += w.getName() + ",";
}
send(worldNames);

// getCurrentWorld
}else if (c.equals("getCurrentWorld")) {
send(world.getName());

// setWorld
}

else if (c.equals("setWorld")) {
if(worldNamesList.contains(args[0])) {
plugin.getConfig().set("world", args[0]);
plugin.saveConfig();
plugin.reloadConfig();
send("Set active world to " + args[0]);
} else {

send(args[0] + " is not a valid world!");
}
//player.getWorld
}else if (c.equals("player.getWorld")) {

Player currentPlayer = getCurrentPlayer();
send(currentPlayer.getWorld().getName());

// not a command which is supported
} else {
Expand Down
10 changes: 5 additions & 5 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# default config.yml

# The host name and port to listen on
# hostname - ip address or hostname to allow connections from, default is "0.0.0.0"
# (any). "localhost" would prevent remote clients from connecting.
# location determines whether locations are RELATIVE to the spawn point (default like pi) or ABSOLUTE
# world determines in what world RaspberryJuice will execute its commands
# hitclick determines whether hit events are triggered by LEFT clicks, RIGHT clicks or BOTH

hostname:
port: 4711

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

# Determine whether hit events are triggered by LEFT clicks, RIGHT clicks or BOTH
world:
hitclick: RIGHT
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ description: Implementation of the Minecraft PI modding API
main: net.zhuoweizhang.raspberryjuice.RaspberryJuicePlugin
name: RaspberryJuice
startup: postworld
version: '1.12.1'
version: '1.13.0'