Closed ghost closed 7 years ago
First, you need to register a server instance, then you need to register a server listener, provide a data-handler class and override the onActionBar method. You can then update the variables you want by referencing the gameMode
parameter.
Now register a module item, provide your created date class to the super constructor and implement the get value method.
Do I need to make a ServerListener
or a ServerGameListener
class at
then you need to register a server listener
And what methods would I need to specify?
You can then update the variables you want by referencing the
gameMode
parameter.
Sorry to be a pain, but do you have an example of how I can do this?
What if I want to make the ModuleItem
simply render the most recent action bar message?
I've added an example plugin to examples/basic2 which should help you.
Wow, thank you so much for putting all the work into creating that helpful example for me!
I am having a problem though, I can't see the module in the HUD, even though I can locate it in Options>5zig>Display
Are you sure that you are playing on the server you specified? Also, you need to add the created item in the Customize Display GUI of the mod.
are you playing on the server you specified?
What do you mean? How can I just make it run on every server?
I already am. In fact, my file is identical to that one:
package io.github.theonlygusti.fivezigaddons;
import eu.the5zig.mod.server.ServerInstance;
public class ServerInstanceHandler extends ServerInstance {
@Override
public void registerListeners() {
// Register a listener class
getGameListener().registerListener(new MyActionBarListener());
}
@Override
public String getName() {
return "localhost";
}
@Override
public String getConfigName() {
return "localhost";
}
@Override
public boolean handleServer(String host, int port) {
return true;
}
}
Then I have my MyActionBarListener
:
package io.github.theonlygusti.fivezigaddons;
import eu.the5zig.mod.server.AbstractGameListener;
import eu.the5zig.util.minecraft.ChatColor;
public class MyActionBarListener extends AbstractGameListener<MyServer.MainServer> {
@Override
public Class<MyServer.MainServer> getGameMode() {
return MyServer.MainServer.class;
}
@Override
public boolean matchLobby(String lobby) {
return true;
}
@Override
public boolean onActionBar(MyServer.MainServer gameMode, String message) {
gameMode.lastActionBarMessage = ChatColor.stripColor(message);
return false;
}
}
and my MyServer
:
package io.github.theonlygusti.fivezigaddons;
import eu.the5zig.mod.server.GameMode;
public class MyServer {
public static class MainServer extends GameMode {
public String lastActionBarMessage;
@Override
public String getName() {
return "Server";
}
}
}
MyModuleItem
:
package io.github.theonlygusti.fivezigaddons;
import eu.the5zig.mod.modules.GameModeItem;
public class MyModuleItem extends GameModeItem<MyServer.MainServer> {
public MyModuleItem() {
super(MyServer.MainServer.class);
}
@Override
protected Object getValue(boolean dummy) {
if (dummy) {
return "Example Action Bar Message";
} else {
return getGameMode().lastActionBarMessage;
}
}
@Override
public String getName() {
return "AddOns";
}
}
Main
package io.github.theonlygusti.fivezigaddons;
import eu.the5zig.mod.The5zigAPI;
import eu.the5zig.mod.event.EventHandler;
import eu.the5zig.mod.event.LoadEvent;
import eu.the5zig.mod.modules.Category;
import eu.the5zig.mod.plugin.Plugin;
@Plugin(name = "AddOns", version = "1.0")
public class Main {
@EventHandler(priority = EventHandler.Priority.LOW)
public void onLoad(LoadEvent event) {
The5zigAPI.getAPI().registerServerInstance(this, ServerInstanceHandler.class);
The5zigAPI.getAPI().registerModuleItem(this, "AddOns", MyModuleItem.class, Category.OTHER);
}
}
I guess you've been pretty busy for the last four days, I definitely have! Too many deadlines...
Anyway, I was wondering if you could give me a guess as to when you'll get around to taking a look at this?
All your help so far has been absolutely brilliant so don't feel that you have to do anything soon (I know I just dumped a huge load of code here, me myself having no idea what to do xD) I'd just like to know when you'd next be able to help me with this :)
I'm sorry for the late response, but I've now finally figured out how to solve your problem.
The issue is the following: the MyActionBarListener
doesn't get activated because you have to call switchLobby
at least once. To do this, you need to create another Listener class, register it and return null
in getGameMode()
. Now override the onServerJoin
method and call getGameListener().switchLobby("Lobby");
The issue was also present in the example plugin, so I've just updated it.
Let me know if that resolved your issue. Sorry again for the late reply, I didn't have a lot time during the past week.
I realize that the Api may seem a little bit too complicated, especially if you just want to support a single server, but it is really powerful when you want to support large server networks with many different child servers and lobbies (like for example the hypixel.net server). I might add a simplified concept for vanilla servers sometime in the future though.
That hasn't resolved the issue, it's still not displaying.
I added this file:
package io.github.theonlygusti.fivezigaddons;
import eu.the5zig.mod.server.AbstractGameListener;
public class MyLobbyListener extends AbstractGameListener<MyServer.MainServer> {
@Override
public Class<MyServer.MainServer> getGameMode() {
return null;
}
@Override
public boolean matchLobby(String lobby) {
return false;
}
@Override
public void onServerJoin() {
getGameListener().switchLobby("Lobby");
}
}
Have you registered it, too?
support large server networks with many different child servers and lobbies
Reading this I tried to use it on mineplex, and it still wasn't working. Are there actually ways for a module item to display only on one type of lobby? E.g. SG-1
?
Oh I don't think I registered it. Where does that happen? (And by the way thanks for your awesomely fast response XD)
Same as with the MyActionBarListener
class.
It still doesn't work, and I've registered it now.
Here's my MyServerInstance
:
package io.github.theonlygusti.fivezigaddons;
import eu.the5zig.mod.server.ServerInstance;
public class MyServerInstance extends ServerInstance {
@Override
public void registerListeners() {
// Register a listener class
getGameListener().registerListener(new MyActionBarListener());
getGameListener().registerListener(new MyLobbyListener());
}
@Override
public String getName() {
return "localhost";
}
@Override
public String getConfigName() {
return "localhost";
}
@Override
public boolean handleServer(String host, int port) {
return true;
}
}
Did you try connecting to a server that is currently not supported by the 5zig mod?
I don't know. I just tried it on mineplex. Everything else works though, e.g. the text replacements in chat.
Well, do you need your plugin to work on mineplex? If not, try it out on another server.
I'd like it to work everywhere, and I just checked; it doesn't work anywhere.
Checked on mineplex, havoc, badlion, my localhost, a friends server. This covered BungeeCord, Spigot, Vanilla. Idk what Badlion is.
Could you please compare your plugin with the following source folder: src.zip? It worked fine for me. Note that the module item will only be displayed if there actually was a recent action bar message and if the 5zig mod does not support the current server by itself.
What do I need to do if it does support the server? And how can I get it to show all the time even if there has been no "recent' action bar message?
And your source code didn't work for me, I saw your message
Note that the module item will only be displayed if there actually was a recent action bar message
and so tried running /title @p actionbar {"text":"boi"}
a bunch of times. Still doesn't display the module item in 5zig.
Maven is creating this jarfile:
Your plugin worked totally fine for me. Just make sure you are actually connected to a real server when testing. The item will be always displayed if you don't return null
in the getValue
method.
But actually, I think there is a way easier way for you to display an action bar message, even without all the limitations I talked about earlier, if I reconsider your special case. (I really don't know why I didn't though about that earlier, to be honest, sorry). The way it would work is that you would register an event listener that gets called on every action message, no matter if you are connected to a server or not. You would need to reset the message when leaving the world by yourself, but that's it. Heres the source folder of my test-project: src.zip The only problem I noticed is that the action bar event does not get called when executed by the /title command, that will be fixed in an upcoming mod update. When using the raw chat command (what most server do use), the plugin does work though. Hope that helps.
Nice, that new plugin works just as expected.
Is there a way to show/hide (toggle) module items on keypresses?
Sure, just register a keybinding like in the basic1 example plugin.
Awesome, everything is working perfectly now! Thank you so much for all your help, you've been incredible!
Damn I love your client so much, it's so nice as well for it to have a brilliant developer willing to spend time with noobs like me ;) Thanks so much
No problem, glad I could help. ;)
From the example plugin provided and the source code I can't figure out how to do this.