Skip to content

Commit

Permalink
only fire generic yep event if no other msg types match
Browse files Browse the repository at this point in the history
should fix #1

Signed-off-by: unilock <[email protected]>
  • Loading branch information
unilock committed Jul 5, 2024
1 parent 02434dc commit b498e49
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 45 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ org.gradle.parallel=true
# Plugin Properties
archives_base_name=yeplib
maven_group=cc.unilock
plugin_version=2.2.0
plugin_version=2.3.0

# Dependencies
velocity_version=3.3.0-SNAPSHOT
7 changes: 3 additions & 4 deletions src/main/java/cc/unilock/yeplib/YepLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,12 @@ public void onPluginMessage(PluginMessageEvent event) {
final var type = MinecraftChannelIdentifier.from(parts[0]);
final var parameters = Arrays.asList(parts[1].split(UNIT_SEPARATOR));

this.proxy.getEventManager().fireAndForget(new YepMessageEvent(type, parameters, source));

if (YEP_ADVANCEMENT.equals(type)) {
this.proxy.getEventManager().fireAndForget(new YepAdvancementEvent(type, parameters, source));
}
if (YEP_DEATH.equals(type)) {
} else if (YEP_DEATH.equals(type)) {
this.proxy.getEventManager().fireAndForget(new YepDeathEvent(type, parameters, source));
} else {
this.proxy.getEventManager().fireAndForget(new YepMessageEvent(type, parameters, source));
}
}

Expand Down
22 changes: 2 additions & 20 deletions src/main/java/cc/unilock/yeplib/api/event/YepAdvancementEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@
import cc.unilock.yeplib.YepLib;
import cc.unilock.yeplib.api.AdvancementType;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ServerConnection;
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;

import java.util.List;

public class YepAdvancementEvent {
protected final MinecraftChannelIdentifier type;
protected final List<String> parameters;
protected final ServerConnection source;
public class YepAdvancementEvent extends YepMessageEvent{
private final Player player;
private final String username;
private final String displayname;
Expand All @@ -22,9 +18,7 @@ public class YepAdvancementEvent {
private final String description;

public YepAdvancementEvent(MinecraftChannelIdentifier type, List<String> params, ServerConnection source) {
this.type = Preconditions.checkNotNull(type);
this.parameters = Preconditions.checkNotNull(params);
this.source = source;
super(type, params, source);
this.player = YepLib.getProxy().getPlayer(params.get(0)).orElse(null);
this.username = params.get(0);
this.displayname = params.get(1);
Expand All @@ -33,18 +27,6 @@ public YepAdvancementEvent(MinecraftChannelIdentifier type, List<String> params,
this.description = params.get(4);
}

public MinecraftChannelIdentifier getType() {
return this.type;
}

public List<String> getParameters() {
return this.parameters;
}

public ServerConnection getSource() {
return this.source;
}

public Player getPlayer() {
return this.player;
}
Expand Down
22 changes: 2 additions & 20 deletions src/main/java/cc/unilock/yeplib/api/event/YepDeathEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,26 @@

import cc.unilock.yeplib.YepLib;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ServerConnection;
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;

import java.util.List;

public class YepDeathEvent {
protected final MinecraftChannelIdentifier type;
protected final List<String> parameters;
protected final ServerConnection source;
public class YepDeathEvent extends YepMessageEvent {
private final Player player;
private final String username;
private final String displayname;
private final String message;

public YepDeathEvent(MinecraftChannelIdentifier type, List<String> params, ServerConnection source) {
this.type = Preconditions.checkNotNull(type);
this.parameters = Preconditions.checkNotNull(params);
this.source = source;
super(type, params, source);
this.player = YepLib.getProxy().getPlayer(params.get(0)).orElse(null);
this.username = params.get(0);
this.displayname = params.get(1);
this.message = params.get(2);
}

public MinecraftChannelIdentifier getType() {
return this.type;
}

public List<String> getParameters() {
return this.parameters;
}

public ServerConnection getSource() {
return this.source;
}

public Player getPlayer() {
return this.player;
}
Expand Down

0 comments on commit b498e49

Please sign in to comment.