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 24557e7 commit 7503547
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 13 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.onlinecheck</groupId>
<artifactId>onlinecheck</artifactId>
<version>1.0</version>
<version>2.0</version>
<name>OnlineCheck</name>
<description>A Minecraft-Alpha-Server plugin which checks that there isn't already a player with the username online instead of kicking the online player.</description>
<dependencies>
<dependency>
<groupId>com.vanillage.minecraftalphaserver</groupId>
Expand All @@ -16,4 +17,9 @@
<build>
<finalName>OnlineCheck</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/onlinecheck/OnlineCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

public final class OnlineCheck extends Plugin {
@Override
public void onEnable() {
protected void onEnable() {
getMinecraftServer().getPluginManager().getEventManager().registerListener((PlayerLoggedInListener) new OnlineCheckPlayerLoggedInListener(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 @@ -5,28 +5,28 @@

public final class OnlineCheckPlayerLoggedInListener extends PlayerLoggedInListener {
private final OnlineCheck plugin;
private final int priority;
private String kickReason;

public OnlineCheckPlayerLoggedInListener(OnlineCheck plugin) {
this(plugin, -5, null);
this(plugin, -10, null);
}

public OnlineCheckPlayerLoggedInListener(OnlineCheck plugin, int priority) {
this(plugin, priority, null);
}

public OnlineCheckPlayerLoggedInListener(OnlineCheck plugin, String kickReason) {
this(plugin, -5, kickReason);
this(plugin, -10, kickReason);
}

public OnlineCheckPlayerLoggedInListener(OnlineCheck plugin, int priority, String kickReason) {
super(priority);

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

this.plugin = plugin;
this.priority = priority;
this.kickReason = kickReason == null ? "<username> is already online" : kickReason;
}

Expand All @@ -47,15 +47,10 @@ public void setKickReason(String kickReason) {
}

@Override
public void onEvent(PlayerLoggedInEvent event) {
protected void onEvent(PlayerLoggedInEvent event) {
if (!event.isDenied() && plugin.getMinecraftServer().configManager.getPlayerEntity(event.getPacket().username) != null) {
event.deny();
event.setKickReason(kickReason.replace("<username>", event.getPacket().username));
}
}

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

0 comments on commit 7503547

Please sign in to comment.