Jump to content

Recommended Posts

Posted (edited)

Hey,

 

I'm trying to create a mute command that'll add entries to a list (similar to how MC does it for bans). I don't know if the NBT data (with a list of String values for muted player names) saves after server shutdown. Also, what do I attach the capability to? Do I need an interface and storage? I'm just confused as to how I'd do NBT with an ArrayList (NBT is already kind of confusing in and of itself).

 

If anyone could help, that'd be appreciated.

 

Thanks!

Edited by Differentiation
Posted
  On 9/11/2019 at 2:48 AM, Differentiation said:

Also, what do I attach the capability to?

Expand  

I wouldn't use a capability for this. I would just save this to a file yourself. For simplicity sake probably a json file like the ops file.

But if you really wanted to use a Capability here you would probably attach it to the Player and not use an ArrayList at all.

  On 9/11/2019 at 2:48 AM, Differentiation said:

Do I need an interface

Expand  

No you don't need an interface. You only need to use an interface if your capability is modifiable. IE can have different implementations.

  On 9/11/2019 at 2:48 AM, Differentiation said:

and storage

Expand  

Yes all Capabilities need an IStorage component.

  On 9/11/2019 at 2:48 AM, Differentiation said:

I'm just confused as to how I'd do NBT with an ArrayList (NBT is already kind of confusing in and of itself).

Expand  

You would use NBTTagList.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
  On 9/11/2019 at 3:07 AM, Animefan8888 said:

I wouldn't use a capability for this. I would just save this to a file yourself. For simplicity sake probably a json file like the ops file.

But if you really wanted to use a Capability here you would probably attach it to the Player and not use an ArrayList at all.

No you don't need an interface. You only need to use an interface if your capability is modifiable. IE can have different implementations.

Yes all Capabilities need an IStorage component.

You would use NBTTagList.

Expand  

Currently I have it being put in player capability, however, I want to be able to ban any GameProfile, even if its offline (like how banning does it).

 

I thought of maybe creating a muted.json file, but I  dont know how to do that. How would I add an entry to ops.json without the entry being opped, but instead muted?

Posted
  On 9/11/2019 at 10:38 AM, Differentiation said:

How would I add an entry to ops.json without the entry being opped, but instead muted?

Expand  

You dont. ops.json is for oped players you wouldn't use it for this.

 

  On 9/11/2019 at 10:38 AM, Differentiation said:

I thought of maybe creating a muted.json file, but I  dont know how to do that.

Expand  

Create a file in the server directory called muted.json and save that file when the world saves? You would use the Gson library minecraft uses for its json interactions.

 

  On 9/11/2019 at 10:38 AM, Differentiation said:

I want to be able to ban any GameProfile, even if its offline (like how banning does it).

Expand  

I dont think the vanilla ban command let's you ban people that aren't online unless it's with IPs.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
  On 9/11/2019 at 8:13 PM, Animefan8888 said:

Create a file in the server directory called muted.json and save that file when the world saves? You would use the Gson library minecraft uses for its json interactions.

 

Expand  

I want the mod to create it when the server starts for the first time, exactly like Minecraft does bans.json when on a dedicated server, and have it update every time an entry is added (a player is muted). I don't really know how to start a json file like that or what I need to do. Is there any help or tutorial or something I could get?

  On 9/11/2019 at 8:13 PM, Animefan8888 said:

I dont think the vanilla ban command let's you ban people that aren't online unless it's with IPs.

Expand  

It does, it bans the GameProfile, not EntityPlayer. I've tested this out and it works.

Posted
  On 9/11/2019 at 11:00 PM, Differentiation said:

I don't really know how to start a json file like that or what I need to do.

Expand  

Think basic Java file creation. Look up some tutorials on Gson if you need it.

 

  On 9/11/2019 at 11:00 PM, Differentiation said:

I want the mod to create it when the server starts for the first time,

Expand  

Use the ServerStartingEvent or ServerStartedEvent.

 

  On 9/11/2019 at 11:00 PM, Differentiation said:

and have it update every time an entry is added (a player is muted).

Expand  

Then everytime the command is run update the file.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted (edited)
  On 9/11/2019 at 11:11 PM, Animefan8888 said:

Think basic Java file creation. Look up some tutorials on Gson if you need it.

 

Expand  

I'll probably just copy UserList and UserListBans, etc. because it's pointless to do this from scratch I think...

Can I attach a capability to MinecraftServer and have it save the list when I exit or something? Is there any other solution for this without making it too complicated?

Edited by Differentiation
Posted
  On 9/12/2019 at 1:49 AM, Differentiation said:

 Can I attach a capability to MinecraftServer and have it save the list when I exit or something?

Expand  

No you cannot. The server doesn't have capabilities. Because there is only one server in question.

 

  On 9/12/2019 at 1:49 AM, Differentiation said:

Is there any other solution for this without making it too complicated?

Expand  

It's not that complicated... Use events such as ServerStartingEvent to create a file if it doesnt exist(muted.json).

 

Then whenever you run your mute command save the data to the file using Gson.

 

If you dont want it to save when you run the command use the ServerStoppingEvent to save the data you have.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted (edited)
  On 9/12/2019 at 3:03 AM, Animefan8888 said:

Then whenever you run your mute command save the data to the file using Gson.

Expand  

I watched the tutorial on Gson and it seemed pretty easy, but how would I create multiple entries in one file?

 

Other than that, everything else seems straight forward.

Edited by Differentiation
Posted
  On 9/13/2019 at 11:59 PM, Differentiation said:

However, when I mute another player the file just replaces the entry that's in it with the one I just added.

Expand  

You'll either have to write all of the entries again. Or append to the file in some way. Look up FIle IO tutorials for Java.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted (edited)
  On 9/14/2019 at 12:01 AM, Animefan8888 said:

You'll either have to write all of the entries again. Or append to the file in some way. Look up FIle IO tutorials for Java.

Expand  

I don't know, it's whenever I create another MutedList (every time I run the command). I don't know how to really fix this.

Now the entries all go in but when I leave (the server closes), enter, and run the command once more, all the previous entries are deleted and there's just this one. I could send the code if you'd like :S

I'm not sure of a way to avoid that. And that ties back to the problem I had at the very beginning of this thread, a way to read and write the old values

Edited by Differentiation
Posted
  On 9/14/2019 at 2:41 AM, Differentiation said:

could send the code if you'd like

Expand  

Code always helps. Are you reading the entries from the file on server start up?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
  On 9/14/2019 at 3:00 AM, Differentiation said:

Yeah, but where and when should I write the values?

Expand  

You said you wanted to do it every time the command was ran. So do it then...

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
  On 9/14/2019 at 3:45 AM, Differentiation said:

I do, but then it resets anyways once I add an entry (run the command)

Expand  

Post your code I can't help without it anymore than I already have. My suspicion is that you are just writing the new entry to the file instead of writing the whole thing again.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
  On 9/14/2019 at 10:27 PM, Differentiation said:
Expand  

Thank you for posting your code.

This part right here is your problem.

		File file = new File("muted-players.json");

		try
		{
			file.setWritable(true);
			file.createNewFile();
		}
		catch (IOException exception)
		{
			Log.info("Error creating file 'muted-players.json'!");
		}

 

You create an new file even if the file already exists. You need to check if the file exists before you create it.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
  On 9/14/2019 at 10:39 PM, Animefan8888 said:

Thank you for posting your code.

This part right here is your problem.

		File file = new File("muted-players.json");

		try
		{
			file.setWritable(true);
			file.createNewFile();
		}
		catch (IOException exception)
		{
			Log.info("Error creating file 'muted-players.json'!");
		}

 

You create an new file even if the file already exists. You need to check if the file exists before you create it.

Expand  

File::createNewfile(); only creates the file if it does not already exist, I thought.  I'll have to double check 

Posted
  On 9/15/2019 at 12:00 AM, Differentiation said:

File::createNewfile(); only creates the file if it does not already exist, I thought.  I'll have to double check 

Expand  

This is true my bad. Try stepping through your read and write methods in the debugger.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted (edited)
  On 9/15/2019 at 12:07 AM, Animefan8888 said:

This is true my bad. Try stepping through your read and write methods in the debugger.

Expand  

It inevitably creates a new instance of UserListMutes every time the mod is loaded. That's my issue. I could make the class abstract, but then I can't really instantiate it. I have no idea how to resolve this. :/

Edited by Differentiation
Posted
  On 9/15/2019 at 1:26 AM, Differentiation said:

It inevitably creates a new instance of UserListMutes every time the mod is loaded.

Expand  

Yeah it has to do that...how much do you know about programming? Have you stepped through the code execution in the debugger?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.