diff --git a/doc/Modding.md b/doc/Modding.md index b6b7641a3..37556f016 100644 --- a/doc/Modding.md +++ b/doc/Modding.md @@ -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. \ No newline at end of file diff --git a/src/main/java/de/bixilon/minosoft/modding/event/EventManager.java b/src/main/java/de/bixilon/minosoft/modding/event/EventManager.java index 0ece4d229..14a55b061 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/EventManager.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/EventManager.java @@ -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 serverAddresses = new HashSet<>(Arrays.asList(addresses)); specificEventListeners.put(serverAddresses, getEventMethods(listener)); diff --git a/src/main/java/de/bixilon/minosoft/modding/event/address/HostnameValidator.java b/src/main/java/de/bixilon/minosoft/modding/event/address/HostnameValidator.java index a4fff89b4..6b8b4b362 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/address/HostnameValidator.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/address/HostnameValidator.java @@ -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 hostnames; + + public HostnameValidator(String... hostnames) { + this(new HashSet<>(Arrays.asList(hostnames))); + } + + public HostnameValidator(HashSet 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 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); } }