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

Feat: Commands improvement #73

Open
wants to merge 5 commits into
base: develop
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 @@ -36,6 +36,8 @@ public CommandManager() {
commands.put("import", new ImportWorldCmd());
commands.put("reload", new ReloadConfigCmd());
commands.put("create", new CreateWorldCmd());
commands.put("save", new SaveWorldCmd());
commands.put("setspawn", new SetSpawmCmd());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.grinderwolf.swm.plugin.commands.sub;

import com.grinderwolf.swm.plugin.log.Logging;
import lombok.Getter;
import org.bukkit.*;
import org.bukkit.block.BlockFace;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.List;

@Getter
public class SaveWorldCmd implements Subcommand {

private final String usage = "save <world>";
private final String description = "Save a world.";
private final String permission = "swm.saveworld";

@Override
public boolean onCommand(CommandSender sender, String[] args) {
if (args.length > 0) {
World world = Bukkit.getWorld(args[0]);

if (world == null) {
sender.sendMessage(Logging.COMMAND_PREFIX + ChatColor.RED + "World " + args[0] + " is not loaded!");

return true;
}

world.save();

sender.sendMessage(Logging.COMMAND_PREFIX + ChatColor.GREEN + "World " + ChatColor.YELLOW + args[0] + ChatColor.GREEN + " saved correctly.");

return true;
}

return false;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.grinderwolf.swm.plugin.commands.sub;

import com.grinderwolf.swm.plugin.config.ConfigManager;
import com.grinderwolf.swm.plugin.config.WorldsConfig;
import com.grinderwolf.swm.plugin.log.Logging;
import lombok.Getter;
import org.bukkit.*;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

@Getter
public class SetSpawmCmd implements Subcommand {

private final String usage = "setspawm <world>";
private final String description = "Set spawnpoint of a world to your location.";
private final String permission = "swm.setspawm";

@Override
public boolean onCommand(CommandSender sender, String[] args) {
if(!(sender instanceof Player)) {
sender.sendMessage(Logging.COMMAND_PREFIX + ChatColor.RED + "This command is for players)");
}

if (args.length > 0) {
World world = Bukkit.getWorld(args[0]);

if (world == null) {
sender.sendMessage(Logging.COMMAND_PREFIX + ChatColor.RED + "World " + args[0] + " does not exist!");

return true;
}

Player player = (Player) sender;

world.setSpawnLocation(player.getLocation());

WorldsConfig config = ConfigManager.getWorldConfig();

if (!(config.getWorlds().containsKey(world.getName()))) {
sender.sendMessage(Logging.COMMAND_PREFIX + ChatColor.RED + "The world " + world.getName() + " is not a Slime-World!");

return true;
}

String spawnVerbose = player.getLocation().getX() + ", " + player.getLocation().getY() + ", " + player.getLocation().getZ();

config.getWorlds().get(world.getName()).setSpawn(spawnVerbose);
config.save();

sender.sendMessage(Logging.COMMAND_PREFIX + ChatColor.GREEN + "Spawn for world " + ChatColor.YELLOW + args[0] + ChatColor.GREEN + " saved correctly.");

return true;
}

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
@Getter
public class UnloadWorldCmd implements Subcommand {

private final String usage = "unload <world> [data-source]";
private final String description = "Unload a world.";
private final String usage = "unload <world> [data-source] [save]";
private final String description = "Unload a world. Save enabled by default, use 'yes' or 'no'.";
private final String permission = "swm.unloadworld";

@Override
Expand All @@ -43,6 +43,14 @@ public boolean onCommand(CommandSender sender, String[] args) {
return true;
}

boolean shouldSaveWorld = true;
if(args.length >= 3) {
String saveParameter = args[2];
if(saveParameter == "no") {
shouldSaveWorld = false;
}
}

String source = null;

if (args.length > 1) {
Expand Down Expand Up @@ -71,6 +79,10 @@ public boolean onCommand(CommandSender sender, String[] args) {
return true;
}

if(shouldSaveWorld) {
world.save();
}

System.out.println("Attempting to unlock world.. " + worldName + ".");
try {
if(loader != null && loader.isWorldLocked(worldName)) {
Expand Down