First commit

This commit is contained in:
Jos van 't Hof
2012-03-19 16:56:27 +01:00
commit f707591954
30 changed files with 1753 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="lib" path="C:/Users/Jos/Minecraft/Plugins/API&apos;s/bukkit-1.1-R6.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@@ -0,0 +1 @@
/bin

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Random Spawn</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6

View File

@@ -0,0 +1,8 @@
debug: false
fallfromsky: false
generator:
chunkspertick: 8
interval: 4
messages:
pleasewait: "Please wait while your spawn is being loaded."
randomspawned: "You wake up in an unfamiliar place."

View File

@@ -0,0 +1,111 @@
name: RandomSpawn
version: 1.8b
main: me.Josvth.RandomSpawn.RandomSpawn
author: Josvth
commands:
randomspawn:
description: The main command.
usage: Incorrect usage! Try /rs help
aliases: rs
reload:
description: Reloads the Random Spawn config files.
usage: /rs reload [config/worlds/spawnlocations]
permission: RandomSpawn.reload
prefix: randomspawn
info:
description: Shows the Random Spawn settings for this world.
usage: /rs info
permission: RandomSpawn.info
prefix: randomspawn
enable:
description: Enables Random Spawn in this world.
usage: /rs enable
permission: RandomSpawn.configure
prefix: randomspawn
disable:
description: Disables Random Spawn in this world.
usage: /rs disable
permission: RandomSpawn.configure
prefix: randomspawn
setarea:
description: Sets the Random Spawn area.
usage: /rssetarea [square/circle] radius or /rssetarea xrange zrange or /rssetarea xmin xmax zmin zmax
permission: RandomSpawn.configure
prefix: randomspawn
usebeds:
description: Toggles using beds.
usage: /rs usebeds [true/false]
permission: RandomSpawn.configure
prefix: randomspawn
keepfirstspawns:
description: Toggles spawn saving.
usage: /rs keepfirstspawns [true/false]
aliases: kfs
permission: RandomSpawn.configure
prefix: randomspawn
firstjoin:
description: Toggles randomspawning on first join.
usage: /rs firstjoin [true/false]
aliases: fj
permission: RandomSpawn.configure
prefix: randomspawn
setfirstspawn:
description: Sets the first spawn location for this world.
usage: /rs setfirstspawn
aliases: sfs
permission: RandomSpawn.setfirstspawn
prefix: randomspawn
tpfirstspawn:
description: Teleports you to the first spawn location of this world.
usage: /rs tpfirstspawn
aliases: tfs
permission: RandomSpawn.tpfirstspawn
prefix: randomspawn
unsetfirstspawn:
description: Unsets the first spawn location for this world.
usage: /rs unsetfirstspawn
aliases: rsunsetfs
permission: RandomSpawn.setfirstspawn
prefix: randomspawn
permissions:
RandomSpawn.*:
description: Gives access to all Random Spawn commands.
default: op
children:
RandomSpawn.configure: true
RandomSpawn.help: true
RandomSpawn.info: true
RandomSpawn.placesign: true
RandomSpawn.reload:
description: Allows you to use the /rs reload command.
default: op
RandomSpawn.configure:
description: Allows you to configure Random Spawn.
default: op
children:
RandomSpawn.setfirstspawn: true
RandomSpawn.teleporttofirstspawn: true
RandomSpawn.help:
description: Gives you access to the help commands.
default: false
RandomSpawn.info:
description: Gives you access to the world info screen.
default: true
RandomSpawn.setfirstspawn:
description: Allows you to use the /setfirstspawn command.
default: op
RandomSpawn.teleporttofirstspawn:
description: Allows you to use the /tpfirstspawn command.
default: op
RandomSpawn.exclude:
description: Excludes you from being randomly spawned.
default: false
RandomSpawn.placesign:
description: Allows you to place Random Spawn Signs.
default: op
RandomSpawn.usesign:
description: Allows you to use Random Spawn Signs.
default: true

View File

@@ -0,0 +1,53 @@
package me.Josvth.RandomSpawn.Commands;
import java.util.List;
import me.Josvth.RandomSpawn.RandomSpawnCommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class RandomSpawnBedsCommand extends RandomSpawnCommandExecutor{
public RandomSpawnBedsCommand(){
this.name = "usebeds";
}
public boolean onCommand(CommandSender sender, List<String> args){
Player player = (Player) sender;
String worldName = player.getWorld().getName();
if (args.size() == 0){
if (plugin.getYamlHandler().worlds.getBoolean(worldName + ".usebeds", true)){
plugin.getYamlHandler().worlds.set(worldName + ".usebeds", false);
plugin.playerInfo((Player)sender, "Beds are now disabled.");
plugin.getYamlHandler().saveWorlds();
return true;
}else{
plugin.getYamlHandler().worlds.set(worldName + ".usebeds", true);
plugin.playerInfo((Player)sender, "Beds will now work like normal.");
plugin.getYamlHandler().saveWorlds();
return true;
}
}
if (args.size() == 1){
if (args.get(0).matches("true")){
plugin.getYamlHandler().worlds.set(worldName + ".usebeds", true);
plugin.playerInfo(player, "Beds will now work like normal.");
plugin.getYamlHandler().saveWorlds();
return true;
}
if (args.get(0).matches("false")){
plugin.getYamlHandler().worlds.set(worldName + ".usebeds", false);
plugin.playerInfo(player, "Beds are now disabled.");
plugin.getYamlHandler().saveWorlds();
return true;
}
}
return false;
}
}

View File

@@ -0,0 +1,24 @@
package me.Josvth.RandomSpawn.Commands;
import java.util.List;
import me.Josvth.RandomSpawn.RandomSpawnCommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class RandomSpawnDisableCommand extends RandomSpawnCommandExecutor{
public RandomSpawnDisableCommand(){
this.name = "disable";
}
public boolean onCommand(CommandSender sender, List<String> args){
Player player = (Player) sender;
String worldname = player.getWorld().getName();
plugin.getYamlHandler().worlds.set(worldname + ".randomspawnenabled", false);
plugin.getYamlHandler().saveWorlds();
plugin.playerInfo(player, "Random Spawn is now disabled in this world!");
return true;
}
}

View File

@@ -0,0 +1,32 @@
package me.Josvth.RandomSpawn.Commands;
import java.util.List;
import me.Josvth.RandomSpawn.RandomSpawnCommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class RandomSpawnEnableCommand extends RandomSpawnCommandExecutor{
public RandomSpawnEnableCommand(){
this.name = "enable";
}
public boolean onCommand(CommandSender sender, List<String> args){
Player player = (Player) sender;
String worldname = player.getWorld().getName();
plugin.getYamlHandler().worlds.set(worldname + ".randomspawnenabled", true);
if (!(plugin.getYamlHandler().worlds.contains(worldname +".spawnarea"))){
plugin.getYamlHandler().worlds.set(worldname + ".spawnarea.x-min", -100);
plugin.getYamlHandler().worlds.set(worldname + ".spawnarea.x-max", 100);
plugin.getYamlHandler().worlds.set(worldname + ".spawnarea.z-min", -100);
plugin.getYamlHandler().worlds.set(worldname + ".spawnarea.z-max", 100);
}
plugin.getYamlHandler().saveWorlds();
plugin.playerInfo(player, "Random Spawn is now enabled in this world!");
return true;
}
}

View File

@@ -0,0 +1,51 @@
package me.Josvth.RandomSpawn.Commands;
import java.util.List;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import me.Josvth.RandomSpawn.RandomSpawnCommandExecutor;
public class RandomSpawnFirstJoinCommand extends RandomSpawnCommandExecutor{
public RandomSpawnFirstJoinCommand(){
this.name = "firstjoin";
}
public boolean onCommand(CommandSender sender, List<String> args){
Player player = (Player) sender;
String worldname = player.getWorld().getName();
if (args.size() == 0){
if (plugin.getYamlHandler().worlds.getBoolean(worldname + ".randomspawnonfirstjoin", true)){
plugin.getYamlHandler().worlds.set(worldname + ".randomspawnonfirstjoin", false);
plugin.playerInfo(player, "Random Spawn will not spawn new players.");
plugin.getYamlHandler().saveWorlds();
return true;
}else{
plugin.getYamlHandler().worlds.set(worldname + ".randomspawnonfirstjoin", true);
plugin.playerInfo(player, "Random Spawn will random spawn new players.");
plugin.getYamlHandler().saveWorlds();
return true;
}
}
if (args.size() == 1){
if (args.get(0).matches("true")){
plugin.getYamlHandler().worlds.set(worldname + ".randomspawnonfirstjoin", true);
plugin.playerInfo(player, "Random Spawn will random spawn new players.");
plugin.getYamlHandler().saveWorlds();
return true;
}
if (args.get(0).matches("false")){
plugin.getYamlHandler().worlds.set(worldname + ".randomspawnonfirstjoin", false);
plugin.playerInfo(player, "Random Spawn will not spawn new players.");
plugin.getYamlHandler().saveWorlds();
return true;
}
}
return false;
}
}

View File

@@ -0,0 +1,70 @@
package me.Josvth.RandomSpawn.Commands;
import java.util.List;
import me.Josvth.RandomSpawn.RandomSpawnCommandExecutor;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class RandomSpawnHelpCommand extends RandomSpawnCommandExecutor{
public RandomSpawnHelpCommand(){
this.name = "help";
}
public boolean onCommand(CommandSender sender, List<String> args){
String version = plugin.getDescription().getVersion();
Player player = (Player)sender;
if (args.size() == 0 || (args.size() == 1 && args.get(0).matches("1"))){
player.sendMessage(ChatColor.WHITE +" ---------------- " + ChatColor.AQUA + "Random Spawn ver: " + version + ChatColor.WHITE + " ----------------");
player.sendMessage(ChatColor.AQUA + "PAGE 1 of 3");
player.sendMessage("");
player.sendMessage(ChatColor.AQUA + "/rs help (1/2/3) " + ChatColor.WHITE + "Shows this screen." );
player.sendMessage(ChatColor.AQUA + "/rs reload " + ChatColor.WHITE + "Reloads the Random Spawn config files." );
player.sendMessage(ChatColor.AQUA + "/rs info " + ChatColor.WHITE + "Shows the Random Spawn settings for this world." );
player.sendMessage(ChatColor.AQUA + "/rs enable " + ChatColor.WHITE + "Enables Random Spawn in this world." );
player.sendMessage(ChatColor.AQUA + "/rs disable " + ChatColor.WHITE + "Disables Random Spawn in this world." );
player.sendMessage("");
player.sendMessage(ChatColor.WHITE +" -------------------------------------------------- ");
return true;
}
if (args.get(0).matches("2")){
player.sendMessage(ChatColor.WHITE +" ---------------- " + ChatColor.AQUA + "Random Spawn ver: " + version + ChatColor.WHITE + " ----------------");
player.sendMessage(ChatColor.AQUA + "PAGE 2 of 3");
player.sendMessage("");
player.sendMessage(ChatColor.AQUA + "/rs setarea " + ChatColor.WHITE + "Sets the Random Spawn area." );
player.sendMessage(ChatColor.AQUA + "/rs usebeds " + ChatColor.WHITE + "Toggles the use beds setting." );
player.sendMessage(ChatColor.AQUA + "/rs keeprandomspawns " + ChatColor.WHITE + "Toggles spawn saving." );
player.sendMessage(ChatColor.AQUA + "/rs firstjoin " + ChatColor.WHITE + "Toggles randomspawning on first join." );
player.sendMessage("");
player.sendMessage("");
player.sendMessage(ChatColor.WHITE +" -------------------------------------------------- ");
return true;
}
if (args.get(0).matches("3")){
player.sendMessage(ChatColor.WHITE +" ---------------- " + ChatColor.AQUA + "Random Spawn ver: " + version + ChatColor.WHITE + " ----------------");
player.sendMessage(ChatColor.AQUA + "PAGE 3 of 3");
player.sendMessage("");
player.sendMessage(ChatColor.AQUA + "/rs setfirstspawn ");
player.sendMessage(ChatColor.WHITE + "Sets the first spawn location for this world.");
player.sendMessage(ChatColor.AQUA + "/rs tpfirstspawn ");
player.sendMessage(ChatColor.WHITE + "Teleports you to the first spawn location of this world." );
player.sendMessage(ChatColor.AQUA + "/rs unsetfirstspawn ");
player.sendMessage(ChatColor.WHITE + "Unsets the first spawn location for this world." );
player.sendMessage(ChatColor.WHITE +" -------------------------------------------------- ");
return true;
}
return false;
}
}

View File

@@ -0,0 +1,80 @@
package me.Josvth.RandomSpawn.Commands;
import java.util.List;
import me.Josvth.RandomSpawn.RandomSpawnCommandExecutor;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class RandomSpawnInfoCommand extends RandomSpawnCommandExecutor {
public RandomSpawnInfoCommand(){
this.name = "info";
}
public boolean onCommand(CommandSender sender, List<String> args){
Player player = (Player)sender;
String version = plugin.getDescription().getVersion();
String worldname = player.getWorld().getName();
player.sendMessage(ChatColor.WHITE +" --------------- " + ChatColor.AQUA + "Random Spawn ver: " + version + ChatColor.WHITE + " ----------------");
player.sendMessage(ChatColor.AQUA + "World: " + ChatColor.WHITE + worldname );
if (!(plugin.getYamlHandler().worlds.contains(worldname))){
player.sendMessage("Is not configured in Random Spawn ");
player.sendMessage(ChatColor.WHITE +" --------------------------------------------------");
return true;
}
if(plugin.getYamlHandler().worlds.contains(worldname + ".randomspawnenabled")){
if (plugin.getYamlHandler().worlds.getBoolean(worldname + ".randomspawnenabled")){
player.sendMessage("Random spawning is ENABLED in this world");
}else{
player.sendMessage("Random spawning is DISABELD in this world");
}
}
if(plugin.getYamlHandler().worlds.contains(worldname + ".spawnarea")){
player.sendMessage(ChatColor.AQUA + "Spawnarea:");
int xmin = plugin.getYamlHandler().worlds.getInt(worldname +".spawnarea.x-min");
int xmax = plugin.getYamlHandler().worlds.getInt(worldname +".spawnarea.x-max");
int zmin = plugin.getYamlHandler().worlds.getInt(worldname +".spawnarea.z-min");
int zmax = plugin.getYamlHandler().worlds.getInt(worldname +".spawnarea.z-max");
player.sendMessage("x-min = "+ xmin + " | x-max = " + xmax + " | z-min = " + zmin + " | z-max = " + zmax);
}else
{
player.sendMessage("");
player.sendMessage("There is no spawn point set. Refering to defaults:");
player.sendMessage("x-min = -100 | x-max = 100 | z-min = -100 | z-max = 100");
}
player.sendMessage(ChatColor.AQUA + "usebeds: "+ ChatColor.WHITE + plugin.getYamlHandler().worlds.getBoolean(worldname + ".usebeds", true) +
ChatColor.AQUA + " keepspawns: " + ChatColor.WHITE + plugin.getYamlHandler().worlds.getBoolean(worldname + ".keeprandomspawns", false));
player.sendMessage(ChatColor.AQUA + "firstjoin: " + ChatColor.WHITE + plugin.getYamlHandler().worlds.getBoolean(worldname + ".randomspawnonfirstjoin", false) +
ChatColor.AQUA + " worldchange: " + ChatColor.WHITE + plugin.getYamlHandler().worlds.getBoolean(worldname + ".randomspawnonworldchange", false)
);
if(plugin.getYamlHandler().worlds.contains(worldname + ".firstspawn")){
player.sendMessage(ChatColor.AQUA + "Firstspawn:");
int x = plugin.getYamlHandler().worlds.getInt(worldname +".firstspawn.x");
int y = plugin.getYamlHandler().worlds.getInt(worldname +".firstspawn.y");
int z = plugin.getYamlHandler().worlds.getInt(worldname +".firstspawn.z");
double yaw = plugin.getYamlHandler().worlds.getInt(worldname +".firstspawn.yaw");
double pitch = plugin.getYamlHandler().worlds.getInt(worldname +".firstspawn.pitch");
player.sendMessage("x = "+ x + " | y = " + y + " | z = " + z + " | yaw = " + yaw + " | pitch = " + pitch);
}else
{
player.sendMessage("There is no first spawn point set. Refering to worldspawn.");
}
player.sendMessage(ChatColor.WHITE +" --------------------------------------------------");
return true;
}
}

View File

@@ -0,0 +1,52 @@
package me.Josvth.RandomSpawn.Commands;
import java.util.List;
import me.Josvth.RandomSpawn.RandomSpawnCommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class RandomSpawnKeepSpawnsCommand extends RandomSpawnCommandExecutor {
public RandomSpawnKeepSpawnsCommand(){
this.name = "keepfirstspawns";
}
public boolean onCommand(CommandSender sender, List<String> args){
Player player = (Player) sender;
String worldname = player.getWorld().getName();
if (args.size() == 0){
if (plugin.getYamlHandler().worlds.getBoolean(worldname + ".keeprandomspawns", false)){
plugin.getYamlHandler().worlds.set(worldname + ".keeprandomspawns", false);
plugin.playerInfo(player, "Keep random spawns is now disabled.");
plugin.getYamlHandler().saveWorlds();
return true;
}else
{
plugin.getYamlHandler().worlds.set(worldname + ".keeprandomspawns", true);
plugin.playerInfo(player, "Random Spawn will now save the spawn locations.");
plugin.getYamlHandler().saveWorlds();
return true;
}
}
if (args.size() == 1){
if (args.get(0).matches("true")){
plugin.getYamlHandler().worlds.set(worldname + ".keeprandomspawns", true);
plugin.playerInfo(player, "Random Spawn will now save the spawn locations.");
plugin.getYamlHandler().saveWorlds();
return true;
}
if (args.get(0).matches("false")){
plugin.getYamlHandler().worlds.set(worldname + ".keeprandomspawns", false);
plugin.playerInfo(player, "Keep random spawns is now disabled.");
plugin.getYamlHandler().saveWorlds();
return true;
}
}
return false;
}
}

View File

@@ -0,0 +1,45 @@
package me.Josvth.RandomSpawn.Commands;
import java.util.List;
import me.Josvth.RandomSpawn.RandomSpawnCommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class RandomSpawnReloadCommand extends RandomSpawnCommandExecutor {
public RandomSpawnReloadCommand(){
this.name = "reload";
}
public boolean onCommand(CommandSender sender, List<String> args){
Player player = (Player) sender;
if (args.size() == 0) {
plugin.getYamlHandler().loadYamls();
plugin.playerInfo(player, "Random Spawn configurations reloaded!");
return true;
}
if (args.get(0).matches("config")) {
plugin.getYamlHandler().loadConfig();
plugin.playerInfo(player, "Random Spawn config file is reloaded!");
return true;
}
if (args.get(0).matches("worlds")) {
plugin.getYamlHandler().loadWorlds();
plugin.playerInfo(player, "Random Spawn worlds file reloaded!");
return true;
}
if (args.get(0).matches("spawnlocations")) {
plugin.getYamlHandler().loadSpawnLocations();
plugin.playerInfo(player, "Random Spawn spawnlocations file reloaded!");
return true;
}
return false;
}
}

View File

@@ -0,0 +1,130 @@
package me.Josvth.RandomSpawn.Commands;
import java.util.List;
import me.Josvth.RandomSpawn.RandomSpawnCommandExecutor;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class RandomSpawnSetAreaCommand extends RandomSpawnCommandExecutor{
public RandomSpawnSetAreaCommand(){
this.name = "setarea";
}
public boolean onCommand(CommandSender sender, List<String> args){
Player player = (Player) sender;
if (args.size() == 1 && args.get(0).matches("[0-9]+")) {
Location reference = player.getLocation();
int xmin = (int) (reference.getX() - Integer.parseInt(args.get(0)));
int xmax = (int) (reference.getX() + Integer.parseInt(args.get(0)));
int zmin = (int) (reference.getZ() - Integer.parseInt(args.get(0)));
int zmax = (int) (reference.getZ() + Integer.parseInt(args.get(0)));
String worldname = reference.getWorld().getName();
plugin.getYamlHandler().worlds.set(worldname + ".spawnarea.x-min", xmin);
plugin.getYamlHandler().worlds.set(worldname + ".spawnarea.x-max", xmax);
plugin.getYamlHandler().worlds.set(worldname + ".spawnarea.z-min", zmin);
plugin.getYamlHandler().worlds.set(worldname + ".spawnarea.z-max", zmax);
plugin.getYamlHandler().worlds.set(worldname + ".randomspawnenabled", true);
plugin.getYamlHandler().saveWorlds();
plugin.playerInfo(player, "Spawn area set!");
return true;
}
if (args.size() == 2 && args.get(1).matches("[0-9]+")) {
if (args.get(0).matches("square")) {
Location reference = player.getLocation();
int xmin = (int) (reference.getX() - Integer.parseInt(args.get(1)));
int xmax = (int) (reference.getX() + Integer.parseInt(args.get(1)));
int zmin = (int) (reference.getZ() - Integer.parseInt(args.get(1)));
int zmax = (int) (reference.getZ() + Integer.parseInt(args.get(1)));
String worldname = reference.getWorld().getName();
plugin.getYamlHandler().worlds.set(worldname + ".spawnarea.x-min", xmin);
plugin.getYamlHandler().worlds.set(worldname + ".spawnarea.x-max", xmax);
plugin.getYamlHandler().worlds.set(worldname + ".spawnarea.z-min", zmin);
plugin.getYamlHandler().worlds.set(worldname + ".spawnarea.z-max", zmax);
plugin.getYamlHandler().worlds.set(worldname + ".randomspawnenabled", true);
plugin.getYamlHandler().saveWorlds();
plugin.playerInfo(player, "Spawn area set!");
return true;
}
if (args.get(0).matches("circle")) {
}
return false;
}
if (args.size() == 2) {
if (args.get(0).matches("-{0,1}[0-9]+") && args.get(1).matches("-{0,1}[0-9]+")){
Location reference = player.getLocation();
int xmin = (int) (reference.getX() - Integer.parseInt(args.get(0))/2);
int xmax = (int) (reference.getX() + Integer.parseInt(args.get(0))/2);
int zmin = (int) (reference.getZ() - Integer.parseInt(args.get(1))/2);
int zmax = (int) (reference.getZ() + Integer.parseInt(args.get(1))/2);
String worldname = reference.getWorld().getName();
plugin.getYamlHandler().worlds.set(worldname + ".spawnarea.x-min", xmin);
plugin.getYamlHandler().worlds.set(worldname + ".spawnarea.x-max", xmax);
plugin.getYamlHandler().worlds.set(worldname + ".spawnarea.z-min", zmin);
plugin.getYamlHandler().worlds.set(worldname + ".spawnarea.z-max", zmax);
plugin.getYamlHandler().worlds.set(worldname + ".randomspawnenabled", true);
plugin.getYamlHandler().saveWorlds();
plugin.playerInfo(player, "Spawn area set!");
return true;
}
}
if (args.size() == 4) {
if (args.get(0).matches("-{0,1}[0-9]+") && args.get(1).matches("-{0,1}[0-9]+") && args.get(2).matches("-{0,1}[0-9]+") && args.get(3).matches("-{0,1}[0-9]+")){
Location reference = player.getLocation();
int xmin = Integer.parseInt(args.get(0));
int xmax = Integer.parseInt(args.get(1));
int zmin = Integer.parseInt(args.get(2));
int zmax = Integer.parseInt(args.get(3));
String worldname = reference.getWorld().getName();
plugin.getYamlHandler().worlds.set(worldname + ".spawnarea.x-min", xmin);
plugin.getYamlHandler().worlds.set(worldname + ".spawnarea.x-max", xmax);
plugin.getYamlHandler().worlds.set(worldname + ".spawnarea.z-min", zmin);
plugin.getYamlHandler().worlds.set(worldname + ".spawnarea.z-max", zmax);
plugin.getYamlHandler().worlds.set(worldname + ".randomspawnenabled", true);
plugin.getYamlHandler().saveWorlds();
plugin.playerInfo(player, "Spawn area set!");
return true;
}
return false;
}
return false;
}
}

View File

@@ -0,0 +1,43 @@
package me.Josvth.RandomSpawn.Commands;
import java.util.List;
import me.Josvth.RandomSpawn.RandomSpawnCommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class RandomSpawnSetFirstSpawnCommand extends RandomSpawnCommandExecutor{
public RandomSpawnSetFirstSpawnCommand(){
this.name = "setfirstspawn";
}
public boolean onCommand(CommandSender sender, List<String> args){
Player player = (Player)sender;
String worldname = player.getWorld().getName();
double x = player.getLocation().getX();
double y = player.getLocation().getY();
double z = player.getLocation().getZ();
double yaw = (double)player.getLocation().getYaw();
double pitch = (double)player.getLocation().getPitch();
plugin.getYamlHandler().worlds.set(worldname+".firstspawn.x", x);
plugin.getYamlHandler().worlds.set(worldname+".firstspawn.y", y);
plugin.getYamlHandler().worlds.set(worldname+".firstspawn.z", z);
plugin.getYamlHandler().worlds.set(worldname+".firstspawn.yaw", yaw);
plugin.getYamlHandler().worlds.set(worldname+".firstspawn.pitch", pitch);
plugin.getYamlHandler().worlds.set(worldname+".randomspawnonfirstjoin", false);
plugin.getYamlHandler().saveWorlds();
plugin.playerInfo(player, "First spawn location set!");
plugin.playerInfo(player, "Random spawning on first join is now disabled!");
return true;
}
}

View File

@@ -0,0 +1,45 @@
package me.Josvth.RandomSpawn.Commands;
import java.util.List;
import me.Josvth.RandomSpawn.RandomSpawnCommandExecutor;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class RandomSpawnTpFirstSpawnCommand extends RandomSpawnCommandExecutor{
public RandomSpawnTpFirstSpawnCommand(){
this.name = "tpfirstspawn";
}
@Override
public boolean onCommand(CommandSender sender, List<String> args){
Player player = (Player)sender;
String worldname = player.getWorld().getName();
if (plugin.getYamlHandler().worlds.contains(worldname +".firstspawn")){
double x = plugin.getYamlHandler().worlds.getDouble(worldname+".firstspawn.x");
double y = plugin.getYamlHandler().worlds.getDouble(worldname+".firstspawn.y");
double z = plugin.getYamlHandler().worlds.getDouble(worldname+".firstspawn.z");
double dyaw = plugin.getYamlHandler().worlds.getDouble(worldname+".firstspawn.yaw");
double dpitch = plugin.getYamlHandler().worlds.getDouble(worldname+".firstspawn.pitch");
float yaw = (float)dyaw;
float pitch = (float)dpitch;
Location firstSpawn = new Location(player.getWorld(),x,y,z,yaw,pitch);
player.teleport(firstSpawn);
plugin.playerInfo(player, "You've been teleported to the first spawn location of this world!");
}else{
plugin.playerInfo(player, "There's no first spawnpoint set in this world!");
}
return true;
}
}

View File

@@ -0,0 +1,32 @@
package me.Josvth.RandomSpawn.Commands;
import java.util.List;
import me.Josvth.RandomSpawn.RandomSpawnCommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class RandomSpawnUnsetFirstSpawnCommand extends RandomSpawnCommandExecutor{
public RandomSpawnUnsetFirstSpawnCommand(){
this.name = "unsetfirstspawn";
}
public boolean onCommand(CommandSender sender, List<String> args){
Player player = (Player)sender;
String worldname = player.getWorld().getName();
if (plugin.getYamlHandler().worlds.contains((worldname +".firstspawn"))){
plugin.getYamlHandler().worlds.set(worldname +".firstspawn", null);
plugin.getYamlHandler().saveWorlds();
plugin.playerInfo(player, "The first spawn location of this world is removed!");
plugin.playerInfo(player, "Now refering to world spawn.");
}else{
plugin.playerInfo(player, "There's no first spawnpoint set in this world!");
}
return true;
}
}

View File

@@ -0,0 +1,28 @@
package me.Josvth.RandomSpawn.Listeners;
import me.Josvth.RandomSpawn.RandomSpawn;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDeathEvent;
public class RandomSpawnDeathListener implements Listener {
RandomSpawn plugin;
public RandomSpawnDeathListener(RandomSpawn instance){
plugin = instance;
plugin.getServer().getPluginManager().registerEvents(this, this.plugin);
}
@EventHandler
public void onPlayerDeath(EntityDeathEvent event){
if(event.getEntity() instanceof Player){
Player player = (Player) event.getEntity();
plugin.logDebug(player.getName() + " died from " + player.getLastDamageCause().getCause().name());
plugin.logDebug(player.getName() + " Falldistance: " + player.getFallDistance() + " Velocity: " + player.getVelocity() + " No damage tickes: " + player.getNoDamageTicks() + " Location: " + player.getLocation());
}
}
}

View File

@@ -0,0 +1,82 @@
package me.Josvth.RandomSpawn.Listeners;
import java.io.File;
import me.Josvth.RandomSpawn.RandomSpawn;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
public class RandomSpawnJoinListener implements Listener {
private RandomSpawn plugin;
public RandomSpawnJoinListener(RandomSpawn instance) {
this.plugin = instance;
this.plugin.getServer().getPluginManager().registerEvents(this, this.plugin);
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event){
Player player = event.getPlayer();
String playerName = player.getName();
World world = player.getWorld();
String worldName = world.getName();
File file = new File(world.getWorldFolder() + "/players/" + player.getName() + ".dat");
if(file.exists()){ return; } // checks if its not the first join of a player
plugin.logDebug(playerName + "'s first join in " + worldName);
if (plugin.getYamlHandler().worlds.getBoolean(worldName + ".randomspawnonfirstjoin",true) == false){
player.teleport(getFirstSpawn(world));
plugin.logDebug(playerName + " is teleported to the first spawn of " + worldName);
return;
}
if (player.hasPermission("RandomSpawn.exclude")){ return; } // checks if player should be excluded
if (this.plugin.getYamlHandler().worlds.getBoolean(worldName + ".randomspawnenabled", false)){ // checks if Random Spawn is enabled in this world
Location worldSpawn = world.getSpawnLocation();
Location skyLocation = new Location(worldSpawn.getWorld(), worldSpawn.getX(), +10000.0, worldSpawn.getY());
player.teleport(skyLocation);
this.plugin.logDebug(player.getName() + " is teleported somewhere in the sky.");
plugin.randomSpawnPlayer(player, world);
}
}
private Location getFirstSpawn(World world) {
String worldName = world.getName();
if (plugin.getYamlHandler().worlds.contains(worldName +".firstspawn")){
double x = this.plugin.getYamlHandler().worlds.getDouble(worldName+".firstspawn.x");
double y = this.plugin.getYamlHandler().worlds.getDouble(worldName+".firstspawn.y");
double z = this.plugin.getYamlHandler().worlds.getDouble(worldName+".firstspawn.z");
double dyaw = this.plugin.getYamlHandler().worlds.getDouble(worldName+".firstspawn.yaw");
double dpitch = this.plugin.getYamlHandler().worlds.getDouble(worldName+".firstspawn.pitch");
float yaw = (float)dyaw;
float pitch = (float)dpitch;
return new Location(world,x,y,z,yaw,pitch);
}
return world.getSpawnLocation();
}
}

View File

@@ -0,0 +1,79 @@
package me.Josvth.RandomSpawn.Listeners;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerRespawnEvent;
import me.Josvth.RandomSpawn.RandomSpawn;
public class RandomSpawnRespawnListener implements Listener {
private RandomSpawn plugin;
public RandomSpawnRespawnListener(RandomSpawn instance){
this.plugin = instance;
this.plugin.getServer().getPluginManager().registerEvents(this, this.plugin);
}
@EventHandler
public void onPlayerRespawn(PlayerRespawnEvent event){
Player player = event.getPlayer();
String playerName = player.getName();
World world = player.getWorld();
String worldName = world.getName();
Location deathLocation = player.getLocation();
if (player.hasPermission("RandomSpawn.exclude")){ // checks if player should be excluded
this.plugin.logDebug(playerName + " is excluded from Random Spawning.");
return;
}
if (event.isBedSpawn() && this.plugin.getYamlHandler().worlds.getBoolean(worldName + ".usebeds", true)){
this.plugin.logDebug(playerName + " is spawned at his bed!");
return;
}
if (this.plugin.getYamlHandler().worlds.getBoolean(worldName + ".keeprandomspawns", false)){ // checks if player should be spawned at a saved spawn
Location savedSpawn = getPlayerSpawn(player, world);
if (savedSpawn != null){
event.setRespawnLocation(savedSpawn);
this.plugin.logDebug(playerName + " is spawned at his saved spawn.");
return;
}
}
if (this.plugin.getYamlHandler().worlds.getBoolean(worldName + ".randomspawnenabled", false)){ // checks if Random Spawn is enabled in this world
Location skyLocation = new Location(deathLocation.getWorld(), deathLocation.getX(), +10000.0, deathLocation.getY());
event.setRespawnLocation(skyLocation);
this.plugin.logDebug(playerName + " is teleported somewhere in the sky.");
plugin.randomSpawnPlayer(player, world);
}
}
private Location getPlayerSpawn(Player player, World world) {
String playerName = player.getName();
String worldName = world.getName();
if (this.plugin.getYamlHandler().spawnLocations.contains(worldName + "." + playerName)){
double x = this.plugin.getYamlHandler().spawnLocations.getDouble(worldName + "." + player.getName() + ".x");
double y = this.plugin.getYamlHandler().spawnLocations.getDouble(worldName + "." + player.getName() + ".y");
double z = this.plugin.getYamlHandler().spawnLocations.getDouble(worldName + "." + player.getName() + ".z");
this.plugin.logDebug(playerName + "'s saved spawn found!");
return new Location(world, x,y,z);
}
this.plugin.logDebug(playerName + "'s saved spawn not found!");
return null;
}
}

View File

@@ -0,0 +1,63 @@
package me.Josvth.RandomSpawn.Listeners;
import me.Josvth.RandomSpawn.RandomSpawn;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.player.PlayerInteractEvent;
public class RandomSpawnSignListener implements Listener {
RandomSpawn plugin;
public RandomSpawnSignListener(RandomSpawn instance){
this.plugin = instance;
this.plugin.getServer().getPluginManager().registerEvents(this, this.plugin);
}
@EventHandler
public void onPlayerSignInteract(PlayerInteractEvent event){
if(event.getAction() == Action.RIGHT_CLICK_BLOCK){
Block block = event.getClickedBlock();
if (block.getTypeId() == 68 || block.getTypeId() == 63){
Sign sign = (Sign)block.getState();
Player player = event.getPlayer();
if (sign.getLine(0).equalsIgnoreCase("[RandomSpawn]")){
if (player.hasPermission("RandomSpawn.usesign")){
World world = player.getWorld();
Location playerLocation = player.getLocation();
Location skyLocation = new Location(playerLocation.getWorld(), playerLocation.getX(), +10000.0, playerLocation.getY());
player.teleport(skyLocation);
plugin.logDebug(player.getName() + " is teleported somewhere in the sky.");
plugin.randomSpawnPlayer(player, world);
}else{
this.plugin.playerInfo(player, "You don't have the permission to use this Random Spawn Sign!");
}
}
}
}
}
@EventHandler
public void onPlayerSignPlace(SignChangeEvent event){
if (event.getLine(0).equalsIgnoreCase("[RandomSpawn]")){
Player player = event.getPlayer();
if (player.hasPermission("RandomSpawn.placesign")){
this.plugin.playerInfo(player, "Random Spawn Sign created!");
}else{
event.setLine(0, "");
this.plugin.playerInfo(player, "You don't have the permission to place a Random Spawn Sign!");
}
}
}
}

View File

@@ -0,0 +1,80 @@
package me.Josvth.RandomSpawn;
import java.util.HashMap;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import me.Josvth.RandomSpawn.Listeners.*;
public class RandomSpawn extends JavaPlugin{
protected RandomSpawnLogger logger;
RandomSpawnYamlHandler yamlHandler;
RandomSpawnCommandHandler commandHandler;
RandomSpawnRespawnListener respawnListener;
RandomSpawnJoinListener joinListener;
RandomSpawnDeathListener deathListener;
RandomSpawnSignListener signListener;
public HashMap<Player,RandomSpawnSpawner> tasks = new HashMap<Player,RandomSpawnSpawner>();
@Override
public void onDisable() {
for(RandomSpawnSpawner spawner : tasks.values()){
spawner.forcestop(true);
}
}
@Override
public void onEnable() {
//setup handlers
this.logger = new RandomSpawnLogger(this);
this.yamlHandler = new RandomSpawnYamlHandler(this);
logDebug("Yamls loaded!");
this.commandHandler = new RandomSpawnCommandHandler(this);
logDebug("Commands registered!");
//setup listeners
this.respawnListener = new RandomSpawnRespawnListener(this);
this.joinListener = new RandomSpawnJoinListener(this);
this.deathListener = new RandomSpawnDeathListener(this);
this.signListener = new RandomSpawnSignListener(this);
}
public void playerInfo(Player player, String message){
this.logger.playerInfo(player, message);
}
public void logInfo(String message){
this.logger.info(message);
}
public void logDebug(String message){
if (yamlHandler.config.getBoolean("debug",false)) {
this.logger.debug(message);
}
}
public void logWarning(String message){
this.logger.warn(message);
}
public RandomSpawnYamlHandler getYamlHandler(){
return yamlHandler;
}
public void randomSpawnPlayer(Player player, World spawnWorld) {
RandomSpawnSpawner spawner = new RandomSpawnSpawner(this, player, spawnWorld);
spawner.setTaskId(this.getServer().getScheduler().scheduleSyncRepeatingTask(this, spawner, 0, this.yamlHandler.config.getInt("generator.interval",4)));
player.setMaximumNoDamageTicks(12000);
player.setNoDamageTicks(12000);
player.sendMessage(yamlHandler.config.getString("messages.pleasewait", "Please wait while your spawn is being loaded."));
}
}

View File

@@ -0,0 +1,46 @@
package me.Josvth.RandomSpawn;
import java.util.List;
import org.bukkit.command.CommandSender;
public abstract class RandomSpawnCommandExecutor {
protected RandomSpawn plugin;
protected String name;
public void setPlugin(RandomSpawn instance) {
this.plugin = instance;
}
public abstract boolean onCommand(CommandSender sender, List<String> args);
public String getName() {
return name;
}
public String getDescription() {
try {
return plugin.getCommand(name).getDescription();
} catch (NullPointerException e){
return null;
}
}
public String getUsage() {
try {
return plugin.getCommand(name).getUsage();
} catch (NullPointerException e){
return null;
}
}
public List<String> getAliases() {
try {
return plugin.getCommand(name).getAliases();
} catch (NullPointerException e) {
return null;
}
}
}

View File

@@ -0,0 +1,62 @@
package me.Josvth.RandomSpawn;
import java.util.Arrays;
import java.util.HashMap;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import me.Josvth.RandomSpawn.Commands.*;
public class RandomSpawnCommandHandler implements CommandExecutor{
RandomSpawn plugin;
HashMap<String,RandomSpawnCommandExecutor> commands = new HashMap<String,RandomSpawnCommandExecutor>();
public RandomSpawnCommandHandler(RandomSpawn instance) {
plugin = instance;
plugin.getCommand("randomspawn").setExecutor(this);
plugin.getCommand("rs").setExecutor(this);
registerCommands(new RandomSpawnCommandExecutor[]{
new RandomSpawnBedsCommand(), new RandomSpawnDisableCommand(), new RandomSpawnEnableCommand(), new RandomSpawnFirstJoinCommand(), new RandomSpawnHelpCommand(), new RandomSpawnInfoCommand(), new RandomSpawnKeepSpawnsCommand(), new RandomSpawnReloadCommand(), new RandomSpawnSetAreaCommand(), new RandomSpawnSetFirstSpawnCommand(), new RandomSpawnTpFirstSpawnCommand(), new RandomSpawnUnsetFirstSpawnCommand()
});
}
private void registerCommands(RandomSpawnCommandExecutor[] executors) {
for(RandomSpawnCommandExecutor executor : executors){
executor.setPlugin(plugin);
commands.put(executor.name, executor);
if (executor.getAliases() != null){
for(String alias : executor.getAliases()){
commands.put(alias, executor);
}
}
}
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (args.length == 0 || !commands.containsKey(args[0])) return false;
RandomSpawnCommandExecutor commandExecutor = commands.get(args[0]);
if (!(sender instanceof Player)){
sender.sendMessage("This command can only be used in game!");
return true;
}
if (commandExecutor.onCommand(sender, Arrays.asList(args).subList(1, args.length)) == false){
sender.sendMessage(commandExecutor.getUsage());
}
return true;
}
}

View File

@@ -0,0 +1,52 @@
package me.Josvth.RandomSpawn;
import java.util.logging.Logger;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginDescriptionFile;
public class RandomSpawnLogger {
RandomSpawn plugin;
Logger logger;
public RandomSpawnLogger(RandomSpawn instance){
this.plugin = instance;
this.logger = Logger.getLogger("Minecraft");
}
public void info(String message){
this.logger.info(this.buildString(message));
}
public void warn(String message){
this.logger.warning(this.buildStringWarning(message));
}
public void debug(String message){
this.logger.info(this.buildStringDebug(message));
}
public void playerInfo(Player player, String message){
player.sendMessage(ChatColor.AQUA + "[Random Spawn] " + ChatColor.WHITE + message);
}
private String buildString(String message){
PluginDescriptionFile pdfile = plugin.getDescription();
return "[" + pdfile.getName() + "]" + " : " + message;
}
private String buildStringDebug(String message){
PluginDescriptionFile pdfile = plugin.getDescription();
return "[" + pdfile.getName() + "]" + " (DEBUG): " + message;
}
private String buildStringWarning(String message){
PluginDescriptionFile pdfile = plugin.getDescription();
return "[" + pdfile.getName() + "]" + " (WARNING): " + message;
}
}

View File

@@ -0,0 +1,334 @@
// *------------------------------------------------------------------------------------------------------------*
// | The random location methods contain code made by NuclearW |
// | based on his SpawnArea plugin: |
// | http://forums.bukkit.org/threads/tp-spawnarea-v0-1-spawns-targetPlayers-in-a-set-area-randomly-1060.20408/ |
// *------------------------------------------------------------------------------------------------------------*
// *------------------------------------------------------------------------------------------------------*
// | The area generation is based on Brettflan's fill tool in WorldBorder |
// | http://dev.bukkit.org/server-mods/worldborder/ |
// *------------------------------------------------------------------------------------------------------*
package me.Josvth.RandomSpawn;
import java.io.File;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
public class RandomSpawnSpawner implements Runnable{
World world;
String worldName;
Player player;
String playerName;
Location spawnLocation = null;
RandomSpawn plugin;
int taskID = 0;
int viewDistance;
int chunksPerInterval;
//Random Location fields
int xmin;
int xmax;
int zmin;
int zmax;
int xrand;
int zrand;
int y;
int tries = 0;
boolean readyfornexttry = true;
//Spiral Generation fields
int processedChunks;
int skippedChunks;
long chunkaverage = 0;
int refchunkx;
int refchunkz;
int chunkx;
int chunkz;
int slength = 0;
int current = 1;
int negpos = 1;
boolean xside = true;
boolean readyfornextrun = true;
//Status fields
long startTime;
String status = "Initialising";
boolean initialised = false;
boolean finished = false;
boolean forcestopped = false;
public RandomSpawnSpawner(RandomSpawn instance, Player player, World world){
startTime = System.currentTimeMillis();
plugin = instance;
this.player = player;
this.world = world;
logStatus("New task created!");
}
public void setTaskId(int id) {
taskID = id;
plugin.logDebug("Has gotten an id!");
}
private void initialise() {
plugin.tasks.put(player,this);
logStatus(player.getName() + " is added to the deadlist.");
viewDistance = plugin.getServer().getViewDistance();
chunksPerInterval = plugin.getYamlHandler().config.getInt("generator.chunksperrun",32);
logStatus("Viewdistance: " + viewDistance);
logStatus("Chunks per interval: " + chunksPerInterval);
worldName = world.getName();
playerName = player.getName();
xmin = plugin.getYamlHandler().worlds.getInt(worldName +".spawnarea.x-min", -100);
xmax = plugin.getYamlHandler().worlds.getInt(worldName +".spawnarea.x-max", 100);
zmin = plugin.getYamlHandler().worlds.getInt(worldName +".spawnarea.z-min", -100);
zmax = plugin.getYamlHandler().worlds.getInt(worldName +".spawnarea.z-max", 100);
initialised = true;
logStatus("Initialisation done! (" + (System.currentTimeMillis() - startTime) + "ms)");
}
@Override
public void run() {
if (!initialised){
initialise();
}
if(!player.isOnline()){
logStatus("Player " + playerName + " is not online anymore. Force stopping task!");
forcestop(true);
return;
}
if (spawnLocation == null){
changeStatus("Chosing spawn.");
chooseRandomLocation();
return;
}else{
changeStatus("Generating spawn.");
generateArea();
}
}
private void chooseRandomLocation(){
if(!readyfornexttry) return;
readyfornexttry = false;
tries++;
generateRandomXZ();
int y = checklocation();
if(y != -1){
spawnLocation = new Location(world, Double.parseDouble(Integer.toString(xrand))+0.5, Double.parseDouble(Integer.toString(y)) ,Double.parseDouble(Integer.toString(zrand))+0.5);
logStatus("Random Location found: " + spawnLocation);
}
readyfornexttry = true;
}
private void generateRandomXZ(){
xrand = xmin + (int) ( Math.random()*(xmax - xmin) + 0.5 );
zrand = zmin + (int) ( Math.random()*(zmax - zmin) + 0.5 );
}
private int checklocation(){
Chunk chunk = world.getChunkAt(new Location(world, xrand, 0, zrand));
chunkx = chunk.getX();
chunkz = chunk.getZ();
refchunkx = chunkx;
refchunkz = chunkz;
chunk.load();
int y = world.getHighestBlockYAt(xrand, zrand);
int blockid = world.getBlockTypeIdAt(xrand, y - 1, zrand);
if (blockid == 8) {return -1;}
if (blockid == 9) {return -1;}
if (blockid == 10) {return -1;}
if (blockid == 11) {return -1;}
if (blockid == 51) {return -1;}
blockid = world.getBlockTypeIdAt(xrand, y + 1, zrand);
if (blockid == 81) {return -1;}
return y;
}
private void generateArea(){
if(!readyfornextrun){
logStatus("Not ready for next generation run!");
return;
}
readyfornextrun = false;
for (int loop = 0; loop < chunksPerInterval ; loop ++){
if(finished || forcestopped) return;
if (world.isChunkLoaded(chunkx, chunkz)){
skippedChunks++;
}else{
world.loadChunk(chunkx, chunkz, true);
world.refreshChunk(chunkx, chunkz);
}
processedChunks++;
nextChunk();
}
readyfornextrun = true;
}
private void nextChunk(){
if (chunkx == refchunkx + viewDistance && chunkz == refchunkz - viewDistance){
teleportPlayer();
}
if (current < slength){
current++;
}else{
current = 1;
xside ^= true;
if (!xside){
slength++;
negpos = negpos * -1;
}
}
if (xside){
chunkx = chunkx + negpos;
}else{
chunkz = chunkz + negpos;
}
}
private void finish() {
finished = true;
logStatus("Finished! (" + (System.currentTimeMillis() - startTime) + "ms)");
logStatus(processedChunks + " chunks processed.");
logStatus(skippedChunks + " chunks skipped.");
logStatus(tries + " random location tries.");
plugin.tasks.remove(player);
logStatus("involving " + playerName + " is removed from the tasklist.");
plugin.getServer().getScheduler().cancelTask(taskID);
}
public void forcestop(Boolean delete) {
forcestopped = true;
logStatus("Forcestopped! (" + (System.currentTimeMillis() - startTime) + "ms)");
logStatus(processedChunks + " chunks processed.");
logStatus(skippedChunks + " chunks skipped.");
logStatus(tries + " random location tries.");
if(delete){
if (player.isOnline()){
logStatus("Failed to delete " + player.getName() + " from world folder. Player is still online.");
}else{
logStatus("Player is not online! Removing from world folder! Causing first join!");
File file = new File(player.getWorld().getWorldFolder() + "/players/" + player.getName() + ".dat");
Boolean deleted = file.delete();
if (deleted){
logStatus(player.getName() + " is succesfully deleted from "+ worldName + " players folder.");
}else{
logStatus("Failed to delete " + player.getName() + " from "+ worldName + " players folder.");
}
}
}
plugin.tasks.remove(player);
logStatus("involving " + playerName + " is removed from the tasklist.");
plugin.getServer().getScheduler().cancelTask(taskID);
}
private void changeStatus(String newstatus){
if (status != newstatus){
status = newstatus;
logStatus(status);
}
}
private void logStatus(String message){
if (taskID == 0){
plugin.logDebug("Task NOID: " + message);
}else{
plugin.logDebug("Task "+ taskID + " : " + message);
}
}
private void teleportPlayer() {
player.setMaximumNoDamageTicks(400);
player.setNoDamageTicks(400);
player.setHealth(player.getMaxHealth());
player.setFallDistance(-100);
player.setVelocity(new Vector(0,0,0));
if (this.plugin.getYamlHandler().config.getBoolean("fallfromsky", false)){
spawnLocation.setY(300);
logStatus(playerName + " is dropped at: " + spawnLocation.getX() + "," + spawnLocation.getZ());
}else{
logStatus(playerName + " is spawned at: " + spawnLocation.getX() + "," + spawnLocation.getY() + "," + spawnLocation.getZ());
player.sendMessage(this.plugin.getYamlHandler().config.getString("messages.randomspawned", "You wake up in an unfamiliar place."));
}
if (this.plugin.getYamlHandler().worlds.getBoolean(worldName + ".keeprandomspawns",false)){ //checks if spawn should be saved
this.plugin.getYamlHandler().spawnLocations.set(worldName + "." + playerName + ".x", spawnLocation.getX());
this.plugin.getYamlHandler().spawnLocations.set(worldName + "." + playerName + ".y", spawnLocation.getY());
this.plugin.getYamlHandler().spawnLocations.set(worldName + "." + playerName + ".z", spawnLocation.getZ());
this.plugin.getYamlHandler().saveSpawnLocations();
logStatus(playerName + "'s Random Spawn location is saved!");
}
logStatus(playerName + " Falldistance: " + player.getFallDistance() + " Velocity: " + player.getVelocity() + " No damage tickes: " + player.getNoDamageTicks());
if (player.isOnline()){
player.teleport(spawnLocation);
finish();
}else{
forcestop(true);
}
}
}

View File

@@ -0,0 +1,101 @@
package me.Josvth.RandomSpawn;
import java.io.File;
import java.io.IOException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
public class RandomSpawnYamlHandler{
RandomSpawn plugin;
File configFile;
File worldsFile;
File spawnLocationsFile;
public FileConfiguration config;
public FileConfiguration worlds;
public FileConfiguration spawnLocations;
public RandomSpawnYamlHandler(RandomSpawn instance) {
this.plugin = instance;
setupYamls();
loadYamls();
}
public void setupYamls(){
configFile = new File(this.plugin.getDataFolder(), "config.yml");
worldsFile = new File(this.plugin.getDataFolder(), "worlds.yml");
spawnLocationsFile = new File(this.plugin.getDataFolder(), "spawnLocations.yml");
if (!(configFile.exists())){this.plugin.saveResource("config.yml", false);} // loads default config's on first run
if (!(worldsFile.exists())){this.plugin.saveResource("worlds.yml", false);}
if (!(spawnLocationsFile.exists())){this.plugin.saveResource("spawnLocations.yml", false);}
config = new YamlConfiguration();
worlds = new YamlConfiguration();
spawnLocations = new YamlConfiguration();
}
public void loadYamls() {
loadConfig();
loadWorlds();
loadSpawnLocations();
}
public void loadConfig(){
try {
config.load(configFile);
} catch (Exception e) {
e.printStackTrace();
}
}
public void loadWorlds(){
try {
worlds.load(worldsFile);
} catch (Exception e) {
e.printStackTrace();
}
}
public void loadSpawnLocations(){
try {
spawnLocations.load(spawnLocationsFile);
} catch (Exception e) {
e.printStackTrace();
}
}
public void saveYamls() {
saveConfig();
saveWorlds();
saveSpawnLocations();
}
public void saveConfig() {
try {
config.save(configFile);
} catch (IOException e) {
e.printStackTrace();
}
}
public void saveWorlds() {
try {
worlds.save(worldsFile);
} catch (IOException e) {
e.printStackTrace();
}
}
public void saveSpawnLocations() {
try {
spawnLocations.save(spawnLocationsFile);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@@ -0,0 +1,14 @@
#edit the following example world to your preferences
#remember to change 'example' into your world name
example:
randomspawnenabled: true
usebeds: true
keeprandomspawns: false
randomspawnonfirstjoin: true
randomspawnonworldchange: true
type: "square"
spawnarea:
x-min: -100
x-max: 100
z-min: -100
z-max: 100