Résolu Commande Homes
-
Bonjour, je veux faire un mod avec un /home et pour cela j’utilise Json Simple
Mais je galère un peu et je ne sais pas totalement comment m’y prendre.
Merci d’avance.
Voici mon codepackage com.drastic.redskyll.commands; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.Collections; import java.util.List; import java.util.Timer; import java.util.TimerTask; import java.util.function.BiConsumer; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; import com.google.common.collect.Lists; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.server.MinecraftServer; import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextFormatting; import net.minecraft.world.World; import net.minecraftforge.common.DimensionManager; public class CommandSetHome extends CommandBase { private final List<String> aliases = Lists.newArrayList("shome", "sh"); @Override public String getName() { return "sethome"; } @Override public String getUsage(ICommandSender sender) { return "/sethome"; } @Override public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { if(sender instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer)sender; World world = server.getEntityWorld(); JSONObject homeProperty = new JSONObject(); homeProperty.put("x", (int)player.posX); homeProperty.put("y", (int)player.posY); homeProperty.put("z", (int)player.posZ); homeProperty.put("dim", (int)player.dimension); try { File fileDir = new File(DimensionManager.getCurrentSaveRootDirectory() + "/homes/"); fileDir.mkdirs(); File file = new File(DimensionManager.getCurrentSaveRootDirectory() + "/homes/" + player.getName() + ".json"); if(file.exists()) { FileReader reader = new FileReader(file); JSONParser parser = new JSONParser(); JSONArray array = (JSONArray)parser.parse(reader); if(((JSONObject)array.get(0)).containsKey(args[0] + "")) { player.sendMessage(new TextComponentString(TextFormatting.RED + "VOUS AVEZ DEJA UN HOME APPELLE " + TextFormatting.AQUA + args[0].toUpperCase())); } else { //System.out.println(array.size()); if(((JSONObject)array.get(0)).size() < 3) { JSONObject homesList = ((JSONObject)array.get(0)); homesList.put(args[0] + "", homeProperty); array.add(homesList); FileWriter writer = new FileWriter(file); writer.write(array.toJSONString()); writer.flush(); writer.close(); reader.close(); } else { player.sendMessage(new TextComponentString(TextFormatting.RED + "VOUS AVEZ DEJA PLUS DE " + TextFormatting.AQUA + "3" + TextFormatting.RED + " HOMES")); } } } else { FileWriter writer = new FileWriter(file); JSONObject homesList = new JSONObject(); homesList.put(args[0] + "", homeProperty); JSONArray array = new JSONArray(); array.add(homesList); writer.write(array.toJSONString()); writer.flush(); writer.close(); } } catch(IOException e) { } catch(ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } @Override public boolean checkPermission(MinecraftServer server, ICommandSender sender) { return true; } @Override public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos targetPos) { return Collections.EMPTY_LIST; } }
-
@pazzazzo ma commande marche bien en solo mais vu que j’ai un hébergeur nitrado, le fichier des homes est deleted x)
-
@feedback salut je te conseille de faire ca cote plugin c plus simple
-
@havzen mais si il a pas envie de faire un serveur?
c un mod donc c’est pour le solo
-
@pazzazzo ma commande marche bien en solo mais vu que j’ai un hébergeur nitrado, le fichier des homes est deleted x)