mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 03:15:35 -04:00
HostnameValidator: allow multiple addresses
This commit is contained in:
parent
c66dc4e8b9
commit
6e27430994
@ -149,7 +149,7 @@ public class ChatEvent extends EventListener {
|
||||
@EventHandler(priority = Priorities.HIGHEST)
|
||||
public void onChatMessageReceiving(ChatMessageReceivingEvent event) {
|
||||
if (event.getMessage().getMessage().contains("Bixilon")) {
|
||||
MinosoftExampleMod.getInstance().getLogger().game("Bixilon is awful, suppressing this potential bad chat message!");
|
||||
MinosoftExampleMod.getInstance().getLogger().info("Bixilon wrote a potential bad chat message. Suppressing it!");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@ -163,5 +163,5 @@ public class ChatEvent extends EventListener {
|
||||
}
|
||||
}
|
||||
```
|
||||
The following code would suppress messages containing the word "Bixilon" and if you write "jeb_" into the chat, the message's text will be "jeb_ is awesome".
|
||||
The following code would suppress messages containing the word "Bixilon" and if you write "jeb_ is stupid" into the chat, the message's text will be "jeb_ is awesome".
|
||||
To see a list of all events look into `de.bixilon.minosoft.modding.event.events`. There is also a javadoc.
|
@ -55,7 +55,7 @@ public class EventManager {
|
||||
|
||||
public void registerConnectionListener(EventListener listener, ServerAddressValidator... addresses) {
|
||||
if (addresses.length == 0) {
|
||||
throw new RuntimeException("You must provide at least one server address or use global events!");
|
||||
throw new RuntimeException("You must provide at least one address validator or use global events!");
|
||||
}
|
||||
HashSet<ServerAddressValidator> serverAddresses = new HashSet<>(Arrays.asList(addresses));
|
||||
specificEventListeners.put(serverAddresses, getEventMethods(listener));
|
||||
|
@ -15,29 +15,37 @@ package de.bixilon.minosoft.modding.event.address;
|
||||
|
||||
import de.bixilon.minosoft.util.ServerAddress;
|
||||
|
||||
public class HostnameValidator implements ServerAddressValidator {
|
||||
private final String hostname;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
public HostnameValidator(String hostname) {
|
||||
this.hostname = hostname;
|
||||
public class HostnameValidator implements ServerAddressValidator {
|
||||
private final HashSet<String> hostnames;
|
||||
|
||||
public HostnameValidator(String... hostnames) {
|
||||
this(new HashSet<>(Arrays.asList(hostnames)));
|
||||
}
|
||||
|
||||
public HostnameValidator(HashSet<String> hostnames) {
|
||||
this.hostnames = new HashSet<>();
|
||||
hostnames.forEach((hostname) -> this.hostnames.add(hostname.toLowerCase()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean check(ServerAddress address) {
|
||||
return this.hostname.equalsIgnoreCase(address.getHostname());
|
||||
return this.hostnames.contains(address.getHostname().toLowerCase());
|
||||
}
|
||||
|
||||
public String getHostname() {
|
||||
return hostname;
|
||||
public HashSet<String> getHostnames() {
|
||||
return hostnames;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return hostname.hashCode();
|
||||
return hostnames.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return hostname.equals(obj);
|
||||
return hostnames.equals(obj);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user