Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.simonbhb.test;
- import java.io.File;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Optional;
- import org.spongepowered.api.Game;
- import org.spongepowered.api.entity.living.player.Player;
- import org.spongepowered.api.text.Text;
- import org.spongepowered.api.text.Texts;
- import org.spongepowered.api.text.format.TextColors;
- import org.spongepowered.api.util.command.CommandCallable;
- import org.spongepowered.api.util.command.CommandException;
- import org.spongepowered.api.util.command.CommandResult;
- import org.spongepowered.api.util.command.CommandSource;
- import org.spongepowered.api.util.command.source.ConsoleSource;
- import org.spongepowered.api.world.World;
- import ninja.leaping.configurate.ConfigurationNode;
- import ninja.leaping.configurate.ConfigurationOptions;
- import ninja.leaping.configurate.hocon.HoconConfigurationLoader;
- import ninja.leaping.configurate.loader.ConfigurationLoader;
- public class CommandSetHome implements CommandCallable {
- public Game game;
- public CommandSetHome(Game game) {
- this.game = game;
- }
- @Override
- public CommandResult process(CommandSource sender, String arguments) throws CommandException {
- if(sender instanceof Player) {
- Player player = (Player) sender;
- String[] args = arguments.split(" ");
- if(arguments == "") {
- player.sendMessage(Texts.builder("Home: default").color(TextColors.YELLOW).build());
- File folder = new File("config/test/home/" + player.getUniqueId().toString());
- if(!folder.exists()) folder.mkdir();
- File file = new File("config/test/home/" + player.getUniqueId().toString() + "/defaut.conf");
- ConfigurationLoader<?> manager = HoconConfigurationLoader.builder().setFile(file).build();
- ConfigurationNode homes = manager.createEmptyNode(ConfigurationOptions.defaults());
- try {
- String nameHome = "default";
- String playerName = player.getName();
- String world = player.getWorld().getName();
- int cX = player.getLocation().getBlockX();
- int cY = player.getLocation().getBlockY();
- int cZ = player.getLocation().getBlockZ();
- if(file.exists()) {
- //file.createNewFile();
- }
- //homes = manager.load();
- homes.getNode("home", "name").setValue( nameHome );
- homes.getNode("home", "pseudo").setValue(playerName);
- homes.getNode("home", "world").setValue(world);
- homes.getNode("home", "x").setValue(cX);
- homes.getNode("home", "y").setValue(cY);
- homes.getNode("home", "z").setValue(cZ);
- manager.save(homes);
- homes = manager.load();
- player.sendMessage(Texts.of("Sauvegarde du home: " + cX + " " + cY + " " + cZ));
- } catch (IOException e) {
- e.printStackTrace();
- }
- } else if(args.length == 1) {
- player.sendMessage(Texts.builder( "Nom du /home: " + args[0].toLowerCase() ).color(TextColors.YELLOW).build());
- File folder = new File("config/test/home/" + player.getUniqueId().toString());
- if(!folder.exists()) folder.mkdir();
- File file = new File("config/test/home/" + player.getUniqueId().toString() + "/" + args[0].toLowerCase() + ".conf");
- ConfigurationLoader<?> manager = HoconConfigurationLoader.builder().setFile(file).build();
- ConfigurationNode homes = manager.createEmptyNode(ConfigurationOptions.defaults());
- try {
- String nameHome = args[0].toLowerCase();
- String playerName = player.getName();
- String world = player.getWorld().getName();
- int cX = player.getLocation().getBlockX();
- int cY = player.getLocation().getBlockY();
- int cZ = player.getLocation().getBlockZ();
- if(file.exists()) {
- //file.createNewFile();
- }
- homes.getNode("home", "name").setValue( nameHome );
- homes.getNode("home", "pseudo").setValue(playerName);
- homes.getNode("home", "world").setValue(world);
- homes.getNode("home", "x").setValue(cX);
- homes.getNode("home", "y").setValue(cY);
- homes.getNode("home", "z").setValue(cZ);
- manager.save(homes);
- homes = manager.load();
- player.sendMessage(Texts.of("Sauvegarde du home: " + cX + " " + cY + " " + cZ));
- } catch (IOException e) {
- e.printStackTrace();
- }
- } else {
- player.sendMessage(Texts.builder("Usage: /home ou /home set [name]").color(TextColors.RED).build());
- }
- } else if(sender instanceof ConsoleSource) {
- sender.sendMessage(Texts.of("La commande doit etre tape par un joueur"));
- } else {
- }
- return null;
- }
- private final Text usage = Texts.builder("Usage: /sethome ou /sethome [name]").color(TextColors.YELLOW).build();
- private final Text help = Texts.builder("Help: /sethome ou /sethome [name]").color(TextColors.YELLOW).build();
- private final Text description = Texts.builder("Test | sethome Command").color(TextColors.YELLOW).build();
- private List<String> suggestions = new ArrayList<String>();
- private String permission = "";
- @Override
- public Text getUsage(CommandSource sender) { return usage; }
- @Override
- public Optional<Text> getHelp(CommandSource sender) { return Optional.of(help); }
- @Override
- public Optional<Text> getShortDescription(CommandSource sender) { return Optional.of(description); }
- @Override
- public List<String> getSuggestions(CommandSource sender, String args) throws CommandException { return suggestions; }
- @Override
- public boolean testPermission(CommandSource sender) { return permission.equals("") ? true : sender.hasPermission(permission); }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement