Skip to content

Commit

Permalink
Update to the new priority implementation and fix the project
Browse files Browse the repository at this point in the history
  • Loading branch information
stonar96 committed Oct 11, 2019
1 parent 3640df8 commit 3d9eedb
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 15 deletions.
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Maven
target/
pom.xml.tag
pom.xml.releaseBackup
Expand All @@ -11,6 +12,31 @@ buildNumber.properties
# Avoid ignoring Maven wrapper jar file (.jar files are usually ignored)
!/.mvn/wrapper/maven-wrapper.jar

# Java
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

# IDE
/.settings/
/lib/
Expand Down
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.vanillage.validusername</groupId>
<artifactId>validusername</artifactId>
<version>1.0</version>
<version>2.0</version>
<name>ValidUsername</name>
<description>A Minecraft-Alpha-Server plugin which verifies that usernames match the default username pattern of Minecraft.</description>
<dependencies>
<dependency>
<groupId>com.vanillage.minecraftalphaserver</groupId>
Expand All @@ -16,4 +17,9 @@
<build>
<finalName>ValidUsername</finalName>
</build>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
4 changes: 2 additions & 2 deletions src/main/java/com/vanillage/validusername/ValidUsername.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

public final class ValidUsername extends Plugin {
@Override
public void onEnable() {
protected void onEnable() {
getMinecraftServer().getPluginManager().getEventManager().registerListener((PlayerLoggedInListener) new ValidUsernamePlayerLoggedInListener(this));
getMinecraftServer().log(getName() + " enabled");
}

@Override
public void onDisable() {
protected void onDisable() {
getMinecraftServer().log(getName() + " disabled");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,23 @@

public final class ValidUsernamePlayerLoggedInListener extends PlayerLoggedInListener {
private final ValidUsername plugin;
private final int priority;
private Pattern userNamePattern;
private String kickReason;

public ValidUsernamePlayerLoggedInListener(ValidUsername plugin) {
this(plugin, -10, null, null);
this(plugin, -20, null, null);
}

public ValidUsernamePlayerLoggedInListener(ValidUsername plugin, int priority) {
this(plugin, priority, null, null);
}

public ValidUsernamePlayerLoggedInListener(ValidUsername plugin, Pattern userNamePattern) {
this(plugin, -10, userNamePattern, null);
this(plugin, -20, userNamePattern, null);
}

public ValidUsernamePlayerLoggedInListener(ValidUsername plugin, String kickReason) {
this(plugin, -10, null, kickReason);
this(plugin, -20, null, kickReason);
}

public ValidUsernamePlayerLoggedInListener(ValidUsername plugin, int priority, Pattern userNamePattern) {
Expand All @@ -36,16 +35,17 @@ public ValidUsernamePlayerLoggedInListener(ValidUsername plugin, int priority, S
}

public ValidUsernamePlayerLoggedInListener(ValidUsername plugin, Pattern userNamePattern, String kickReason) {
this(plugin, -10, userNamePattern, kickReason);
this(plugin, -20, userNamePattern, kickReason);
}

public ValidUsernamePlayerLoggedInListener(ValidUsername plugin, int priority, Pattern userNamePattern, String kickReason) {
super(priority);

if (plugin == null) {
throw new IllegalArgumentException("plugin cannot be null");
}

this.plugin = plugin;
this.priority = priority;
this.userNamePattern = userNamePattern == null ? Pattern.compile("[A-Za-z0-9_]{2,16}") : userNamePattern;
this.kickReason = kickReason == null ? "Invalid username <username>, try: " + this.userNamePattern.pattern() : kickReason;
}
Expand Down Expand Up @@ -79,15 +79,10 @@ public void setKickReason(String kickReason) {
}

@Override
public void onEvent(PlayerLoggedInEvent event) {
protected void onEvent(PlayerLoggedInEvent event) {
if (!userNamePattern.matcher(event.getPacket().username).matches()) {
event.setKickReason(kickReason.replace("<username>", event.getPacket().username));
event.deny();
}
}

@Override
public int getPriority() {
return priority;
}
}

0 comments on commit 3d9eedb

Please sign in to comment.