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
12 minutes ago, Differentiation said:

Also, what do I attach the capability to?

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.

16 minutes ago, Differentiation said:

Do I need an interface

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

17 minutes ago, Differentiation said:

and storage

Yes all Capabilities need an IStorage component.

17 minutes ago, 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).

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
7 hours ago, 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.

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
9 hours ago, Differentiation said:

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

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

 

9 hours ago, Differentiation said:

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

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.

 

9 hours ago, Differentiation said:

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

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
2 hours ago, 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.

 

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?

2 hours ago, Animefan8888 said:

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

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

Posted
9 minutes ago, Differentiation said:

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

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

 

9 minutes ago, Differentiation said:

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

Use the ServerStartingEvent or ServerStartedEvent.

 

11 minutes ago, Differentiation said:

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

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)
2 hours ago, Animefan8888 said:

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

 

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
1 hour ago, Differentiation said:

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

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

 

1 hour ago, Differentiation said:

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

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)
7 hours ago, Animefan8888 said:

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

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/12/2019 at 10:48 AM, Animefan8888 said:

JSonArray probably.

Okay, so I did everything and the command works. However, when I mute another player the file just replaces the entry that's in it with the one I just added. How do I fix this? Is this only an issue with using Player[number] test GameProfiles?

Posted
1 minute ago, Differentiation said:

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

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)
2 hours ago, 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.

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
Just now, Differentiation said:

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

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
4 minutes ago, Differentiation said:

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

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
8 minutes ago, Differentiation 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.

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
1 hour ago, 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.

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

Posted
6 minutes ago, Differentiation said:

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

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)
1 hour ago, Animefan8888 said:

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

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
1 minute ago, Differentiation said:

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

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.