[Plugin/API] ServerControl

ServerControl - Take control of your server!


This plugin allows you to manage your server more efficiently. Why use multiple plugins to do things that can all be categorized in the same plugin. This may seem like another essentials clone, but I’ve been working on it for a good while and everything within it is either my own idea or contains inspiration from other plugins.

Github Repo

I’ve been porting it over from Bukkit ever since I joined the Sponge community. I’ve seen the “Foundation” plugin and I think it’s a neat idea, but I’m sure essentials will probably move on to either Sponge or another API possibly rendering that plugin useless.

ServerControl in itself is an API, and within the config (when and if there is one) you will have the ability to completely shut down the plugin or use only certain pieces of the plugin. I’ve been trying to fully develop the APIs within the plugin to allow other people to use it as a dependency.

Within the plugin there are these APIs:

  • Cooldown API
  • Chat Color API (contains custom formats and more accurate color names)
  • File Manager API
  • Logger API
  • Messaging API
  • User API
  • World Manager API

This project is still in development since the Sponge API isn’t finished yet. If you have any questions, ideas or suggestions, please feel free to leave a reply to this. It would be greatly appreciated!

Note: I’ll be updating this as I further develop the plugin.

4 Likes

One thing I’ve used in my own lib is a Clr.fromChars("6lmno") (could use char[] as well I guess, just more to type), which basically prepends each character with \u00A7, then returns the resulting String. This could be nice so people won’t need to do ChatColor.GOLD + "" + ChatColor.BOLD + etc, (The intermediate "" to prevent errors whilst concatenating enums, as they seem to attempt math operations until interpreted as a String, presumably). Used Clr above as a stand-in for whatever (presumably) static class you have for the Color API.

What would your File Management API entail? Would that allow you to load/save config files or is it more inclined to fetching any file on the server?

I’ve used this in almost all of my plugins.

public String f(String s){
return ChatColor.translateAlternateColorCodes(’&’, s);
}

That way you can use player.sendMessage(f("&aHello World!");

The downside is you need to remember all of the color codes, but if you use them a lot like I do you will get to know them.

I hope Sponge will be implementing something like this :slight_smile:

2 Likes

I doubt they’ll do this. It’s more inclined to individual devs since it’s strictly for convenience and less typing, but generally goes against coding conventions. The method names in any decent API should be named something easily recognizable, usually disregarding ease of typing.

So… This is acctually like Essentials but better? Love it. :heart_eyes_cat:
How about adding an permission API? Would make it even better. :smile:

Errors whilst concatenating enums

You can opt to call the toString() method on ChatColor to avoid this.

No offense, but by the looks of your code you seem relatively new to java. Are you sure you can do this all by yourself? I’ll submit some pull requests removing some unnecessary code and renaming things such as ‘registerEvent(Object listener)’ to registerListener (you seem to think that a listener is an event?). Again, not trying to be mean, just trying to help.

That’s true, but then it becomes even lengthier than just concatenating a blank to it XD

Haha agreed. IMO "" + ChatColor.RED + ... doesn’t look well compared to ChatColor.RED.toString() + ... All about preference I guess :stuck_out_tongue:

1 Like

I’ve been working with Java for about 3 years now… maybe 4… I can’t quite remember, but I like to think that I’m well versed in it. I’ve been coding other languages for about 5 or 6 years now.

My code may like “noobish,” but that’s probably because I try to avoid coding the ways that the creators and maintainers of essentials do. It’s way to confusing and takes much more time.

I’m not saying I know everything about java, because I’m far from that. I’m just experienced in it and I can usually sort out my own issues without the help of others. I just try to keep things as simple and clean as I possibly can. Maybe this slows down code, or maybe it’s an improvement, I’m not sure.

Also, thank you very much for the feedback and pull requests!

I wouldn’t say better… I would say more simplified. And I think that the permissions API would be a great addition, thank you!

I could be mistaken, but it feels like some classes could be static. I’m thinking the cooldown manager currently since it’s not static and initialized with a player passed in, but used to store cooldowns for all players? In effect, I think that means that the HashMap storing the timings will be reset each time the class is re-initialized, so previously stored entries will be lost if more than one plugin uses it.

I may fork this later and try to alter it to allow different HashMaps per plugin if possible and making it a static thing. If I get time at least.

Are you saying that if I create a new instance of the Cooldown Manager class then it will also create an instance of anything it extends? I thought it didn’t work like that?

Don’t let confusing code bring you down. Try to learn how it works, that’s how you get better. Unless of course it’s confusing because it is poorly written (I like to think that Essentials has well written code, but I’ve not really looked at it’s sauce).

I just don’t like how complex it is. It seems like it does so many unnecessary things using like 20 classes when it could be done simply using like 2.

I’m like OCD when it comes to code, and if I stop coding for a week which I do from time to time, I like to be able to understand my code without much thought. Maybe my code does look quite new, but I just hate the mess that some developers make.

I’m sure there are things that I do wrongly that the developers that make the crazy, hard to read code do better. and I’m sure that I do things that are much more simplified than the things they do.

Actually, in reply to myself, I think I’ve mis-read something about this. Let me re-check XD Just realized that it’s extending something that could change what I was saying there.

1 Like

Ah, I see what you mean. But I don’t understand why it would do something like that… Each cooldown is stored in the TimeManager class and you can access each instance from there.

Each instance should have their own “cooldown” map. I’m pretty sure that the static modifier would have effect whether or not the map is reset… I may be mistaken though. Most of this is pseudo-code since there isn’t really a way to test against the Sponge server itself.

I agree that it could be an issue if there’s another plugin that’s using the same Cooldown instance or trying to create a Cooldown instance with the same name, could create problems. I’ll try to make it more suitable for multi-plugin support since it is an API.

Alright, sorry. Just misinterpreted something. I was thinking the constructor for the Cooldown object took a player name, but that’s just a name for the cached Cooldown object. So the static thing isn’t an issue. It does make me realize that using a name to cache the Cooldown internally though is probably a bad idea. Would probably be better to have it accept a UUID or something unique to the plugin or another plugin may overwrite data.

If ya use a UUID, then the plugin can cache the UUID it used itself and use it to re-fetch the cached Cooldown. Alternatively, I suppose you could allow a class pass itself in, but I’m not sure if that’s the best way to do it.

I can see what you’re saying about how using Strings for storing the Cooldowns can be bad, but I’m just going to say that I didn’t implement the multi-plugin support to save some trouble… I will most likely switch to UUIDs. Thank you for the idea :smiley:

No problem XD If there was a class that was extended to use Sponge’s plugin API, then I’d say have a HashMap<SpongePlugin, Cooldown>, but as that isn’t a thing, it seems the next best thing is <UUID, Cooldown> or <Object, Cooldown> maybe. Class would seem alright, but I’m not sure if that’s a thing honestly XD I might toy with the fork I made of it and see about it.

Edit: Can’t use angle brackets XD Doesn’t agree if it’s not HTML.

1 Like