Put commands and listener in their own files

This commit is contained in:
Jimmy Allen 2018-07-27 19:29:00 +12:00
parent b5f44cd15e
commit 0fda8c8118
15 changed files with 258 additions and 70 deletions

49
.classpath Normal file
View File

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="target/generated-sources/annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

23
.project Normal file
View File

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

View File

@ -0,0 +1,4 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding/<project>=UTF-8

View File

@ -0,0 +1,2 @@
eclipse.preferences.version=1
org.eclipse.jdt.apt.aptEnabled=false

View File

@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.processAnnotations=disabled
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.7

View File

@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

29
pom.xml
View File

@ -55,6 +55,7 @@
<filtering>true</filtering>
<includes>
<include>plugin.yml</include>
<include>config.yml</include>
</includes>
</resource>
<resource>
@ -81,31 +82,3 @@
</project>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<!--Spigot API-->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.13-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!--Bukkit API-->
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.13-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>

View File

@ -1,2 +0,0 @@
#Minecraft server properties
#Thu Jul 26 07:47:14 GMT 2018

View File

@ -1,37 +0,0 @@
package nz.jimmy.easyspawn;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class EasySpawn extends JavaPlugin{
@Override
public boolean onCommand(CommandSender sender, Command command,
String label, String[] args) {
if(sender instanceof Player){
Player player = (Player)sender;
if(command.getName().equalsIgnoreCase("spawn")){
player.teleport(player.getWorld().getSpawnLocation());
player.sendMessage("You have been teleported to spawn.");
return true;
}
if(command.getName().equalsIgnoreCase("setspawn")){
player.getWorld().setSpawnLocation(player.getLocation().getBlockX(),
player.getLocation().getBlockY(),player.getLocation().getBlockZ());
player.sendMessage("Spawn set.");
return true;
}
if(command.getName().equalsIgnoreCase("bed")){
if(player.getBedSpawnLocation()!=null){
player.teleport(player.getBedSpawnLocation());
player.sendMessage("You have been teleported to your bed.");
}else sender.sendMessage("Your bed cannot be found.");
return true;
}
}
return false;
}
}

View File

@ -0,0 +1,33 @@
package nz.jimmy.easyspawn;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.Configuration;
import org.bukkit.entity.Player;
/**
* Bed
*/
public class Bed implements CommandExecutor {
EasySpawn plugin;
public Bed(EasySpawn plugin) {
this.plugin = plugin;
plugin.getCommand("bed").setExecutor(this);
}
public boolean onCommand(CommandSender sender, Command cmd, String label,
String[] args) {
if(sender instanceof Player) {
Player player = (Player)sender;
//Check if player has a bed
if(player.getBedSpawnLocation()!=null){
player.teleport(player.getBedSpawnLocation());
player.sendMessage("You have been teleported to your bed.");
}else sender.sendMessage("You need to sleep in a bed first.");
return true;
}
return false;
}
}

View File

@ -0,0 +1,13 @@
package nz.jimmy.easyspawn;
import org.bukkit.plugin.java.JavaPlugin;
public class EasySpawn extends JavaPlugin {
@Override
public void onEnable(){
new PlayerListener(this);
new SetSpawn(this);
new Spawn(this);
new Bed(this);
}
}

View File

@ -0,0 +1,42 @@
package nz.jimmy.easyspawn;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
/**
* PlayerListener
*/
public class PlayerListener implements Listener{
EasySpawn plugin;
public PlayerListener(EasySpawn plugin) {
this.plugin = plugin;
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
if(!player.hasPlayedBefore()){
World world = player.getWorld();
String w = world.getName();
FileConfiguration config = plugin.getConfig();
//Check is spawn is set
if(config.contains("spawn."+w)){
int x = config.getInt("spawn."+w+".x");
int y = config.getInt("spawn."+w+".y");
int z = config.getInt("spawn."+w+".z");
float pitch = config.getInt("spawn."+w+".pitch");
float yaw = config.getInt("spawn."+w+".yaw");
player.teleport(new Location(world, x, y, z, yaw, pitch));
}
}
}
}

View File

@ -0,0 +1,38 @@
package nz.jimmy.easyspawn;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.Configuration;
import org.bukkit.entity.Player;
/**
* SetSpawn
*/
public class SetSpawn implements CommandExecutor{
EasySpawn plugin;
public SetSpawn(EasySpawn plugin) {
this.plugin = plugin;
plugin.getCommand("setspawn").setExecutor(this);
}
public boolean onCommand(CommandSender sender, Command cmd, String label,
String[] args) {
if( sender instanceof Player) {
Player player = (Player)sender;
Location location = player.getLocation();
String world = player.getWorld().getName();
Configuration config = plugin.getConfig();
config.set("spawn."+world+".x", location.getBlockX());
config.set("spawn."+world+".y", location.getBlockY());
config.set("spawn."+world+".z", location.getBlockZ());
config.set("spawn."+world+".pitch", location.getPitch());
config.set("spawn."+world+".yaw", location.getYaw());
plugin.saveConfig();
player.sendMessage("Spawn set.");
return true;
}
return false;
}
}

View File

@ -0,0 +1,39 @@
package nz.jimmy.easyspawn;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.Configuration;
import org.bukkit.entity.Player;
/**
* Spawn
*/
public class Spawn implements CommandExecutor{
private EasySpawn plugin;
public Spawn(EasySpawn plugin) {
this.plugin = plugin;
plugin.getCommand("spawn").setExecutor(this);;
}
public boolean onCommand(CommandSender sender, Command cmd, String label,
String[] args) {
if(sender instanceof Player) {
Player player = (Player)sender;
Configuration config = plugin.getConfig();
World world = player.getWorld();
String w = world.getName();
if(config.contains("spawn."+w)){
Location location = new Location(world, config.getInt("spawn."+w+".x"),
config.getInt("spawn."+w+".y"),config.getInt("spawn."+w+".z"),
config.getInt("spawn."+w+".pitch"), config.getInt("spawn."+w+".yaw"));
player.teleport(location);
player.sendMessage("You have been teleported to spawn.");
}else player.sendMessage("This world has no spawn");
return true;
}
return false;
}
}

View File

@ -10,17 +10,17 @@ commands:
description: Teleports you to spawn
usage: /spawn
permission: easyspawn.spawn
permission-message: You don't have <permission>
permission-message: You are not allowed
bed:
description: Teleports you to your bed
usage: /bed
permission: easyspawn.bed
permission-message: You don't have <permission>
permission-message: You are not allowed
setspawn:
description: Sets spawn location
usage: /setspawn
permission: easyspawn.setspawn
permission-message: You don't have <permission>
permission-message: You are not allowed
permissions:
easyspawn.spawn:
description: Teleports you to spawn