Adding hub & sethub commands

This commit is contained in:
Anonymus Raccoon
2020-10-30 21:33:47 +01:00
parent 0c83052d27
commit 1ad1c4101f
5 changed files with 88 additions and 2 deletions
+9
View File
@@ -17,6 +17,10 @@
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>worldedit</id>
<url>https://maven.enginehub.org/repo/</url>
</repository>
</repositories>
<dependencies>
@@ -26,5 +30,10 @@
<version>1.16.3-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-bukkit</artifactId>
<version>7.1.0</version>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,32 @@
package moe.sdg.PluginSDG.Commands;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
public class HubCommand implements CommandExecutor
{
FileConfiguration config;
public HubCommand(FileConfiguration config)
{
this.config = config;
}
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings)
{
if (commandSender instanceof Player) {
Player player = (Player)commandSender;
Location hub = config.getLocation("hub_pos");
if (hub != null && hub.getWorld() != null)
player.teleport(hub);
else
player.sendMessage("No hub location set.");
return true;
}
return false;
}
}
@@ -0,0 +1,29 @@
package moe.sdg.PluginSDG.Commands;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
public class SetHubCommand implements CommandExecutor
{
FileConfiguration config;
public SetHubCommand(FileConfiguration config)
{
this.config = config;
}
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings)
{
if (commandSender instanceof Player) {
Player player = (Player)commandSender;
config.set("hub_pos", player.getLocation());
player.sendMessage("Hub location set to your position.");
return true;
}
return false;
}
}
@@ -1,7 +1,10 @@
package moe.sdg.PluginSDG;
import moe.sdg.PluginSDG.Commands.HubCommand;
import moe.sdg.PluginSDG.Commands.SetHubCommand;
import org.apache.commons.lang.NotImplementedException;
import org.bukkit.Location;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
public class GameManager extends JavaPlugin
@@ -9,7 +12,13 @@ public class GameManager extends JavaPlugin
@Override
public void onEnable()
{
getLogger().info("Game manager loaded.");
FileConfiguration config = getConfig();
config.addDefault("hub_pos", new Location(getServer().getWorld("hub"), 0, 0, 0));
config.options().copyDefaults(true);
saveConfig();
getCommand("hub").setExecutor(new HubCommand(config));
getCommand("sethub").setExecutor(new SetHubCommand(config));
}
public Location getHubLocation()
+8 -1
View File
@@ -1,3 +1,10 @@
name: PluginSDG
version: 1.0
main: moe.sdg.PluginSDG.GameManager
main: moe.sdg.PluginSDG.GameManager
commands:
hub:
description: Return to the hub
usage: /<command>
sethub:
description: Set the hub location
usage: /<command>