Permalink
Browse files

Remove deprecated player_prelogin event and fix player_login prefilter

  • Loading branch information...
PseudoKnight committed Aug 13, 2018
1 parent ea2d406 commit 9422e9025fbaaa6d6e130ef3ba513f6d3540f936
@@ -49,7 +49,6 @@
import com.laytonsmith.abstraction.events.MCPlayerLoginEvent;
import com.laytonsmith.abstraction.events.MCPlayerMoveEvent;
import com.laytonsmith.abstraction.events.MCPlayerPortalEvent;
import com.laytonsmith.abstraction.events.MCPlayerPreLoginEvent;
import com.laytonsmith.abstraction.events.MCPlayerQuitEvent;
import com.laytonsmith.abstraction.events.MCPlayerRespawnEvent;
import com.laytonsmith.abstraction.events.MCPlayerTeleportEvent;
@@ -84,7 +83,6 @@
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerPortalEvent;
import org.bukkit.event.player.PlayerPreLoginEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
@@ -397,51 +395,6 @@ public String getHostname() {
}
}
public static class BukkitMCPlayerPreLoginEvent implements MCPlayerPreLoginEvent {
PlayerPreLoginEvent event;
public BukkitMCPlayerPreLoginEvent(PlayerPreLoginEvent e) {
event = e;
}
@Override
public Object _GetObject() {
return event;
}
@Override
public String getName() {
return event.getName();
}
@Override
public String getKickMessage() {
return event.getKickMessage();
}
@Override
public void setKickMessage(String msg) {
event.setKickMessage(msg);
}
@Override
public String getResult() {
return event.getResult().toString();
}
@Override
public void setResult(String rst) {
event.setResult(PlayerPreLoginEvent.Result.valueOf(rst.toUpperCase()));
}
@Override
public String getIP() {
return event.getAddress().toString();
}
}
@abstraction(type = Implementation.Type.BUKKIT)
public static class BukkitMCPlayerChatEvent extends BukkitMCPlayerEvent implements MCPlayerChatEvent {
@@ -16,7 +16,6 @@
import com.laytonsmith.abstraction.bukkit.events.BukkitPlayerEvents.BukkitMCPlayerLoginEvent;
import com.laytonsmith.abstraction.bukkit.events.BukkitPlayerEvents.BukkitMCPlayerMoveEvent;
import com.laytonsmith.abstraction.bukkit.events.BukkitPlayerEvents.BukkitMCPlayerPortalEvent;
import com.laytonsmith.abstraction.bukkit.events.BukkitPlayerEvents.BukkitMCPlayerPreLoginEvent;
import com.laytonsmith.abstraction.bukkit.events.BukkitPlayerEvents.BukkitMCPlayerQuitEvent;
import com.laytonsmith.abstraction.bukkit.events.BukkitPlayerEvents.BukkitMCPlayerRespawnEvent;
import com.laytonsmith.abstraction.bukkit.events.BukkitPlayerEvents.BukkitMCPlayerTeleportEvent;
@@ -50,7 +49,6 @@
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerPortalEvent;
import org.bukkit.event.player.PlayerPreLoginEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
@@ -97,12 +95,6 @@ public void onPlayerLogin(PlayerLoginEvent e) {
EventUtils.TriggerListener(Driver.PLAYER_LOGIN, "player_login", ple);
}
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerPreLogin(PlayerPreLoginEvent e) {
BukkitMCPlayerPreLoginEvent pple = new BukkitMCPlayerPreLoginEvent(e);
EventUtils.TriggerListener(Driver.PLAYER_PRELOGIN, "player_prelogin", pple);
}
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerJoin(PlayerJoinEvent e) {
BukkitMCPlayerJoinEvent pje = new BukkitMCPlayerJoinEvent(e);

This file was deleted.

Oops, something went wrong.
@@ -82,7 +82,6 @@
PLAYER_LOGIN,
PLAYER_MOVE,
PLAYER_PORTAL_TRAVEL,
PLAYER_PRELOGIN,
PLAYER_QUIT,
PLAYER_SPAWN,
PLAYER_TOGGLE_FLIGHT,
@@ -34,7 +34,6 @@
import com.laytonsmith.abstraction.events.MCPlayerLoginEvent;
import com.laytonsmith.abstraction.events.MCPlayerMoveEvent;
import com.laytonsmith.abstraction.events.MCPlayerPortalEvent;
import com.laytonsmith.abstraction.events.MCPlayerPreLoginEvent;
import com.laytonsmith.abstraction.events.MCPlayerQuitEvent;
import com.laytonsmith.abstraction.events.MCPlayerRespawnEvent;
import com.laytonsmith.abstraction.events.MCPlayerTeleportEvent;
@@ -546,94 +545,6 @@ public CHVersion since() {
}
}
@api
public static class player_prelogin extends AbstractEvent {
@Override
public String getName() {
return "player_prelogin";
}
@Override
public String docs() {
return "{player: <string match>} "
+ "This event is called when a player is about to be authed. "
+ "This event only fires if your server is in online mode. "
+ "This event cannot be cancelled. Instead, you can deny them by setting "
+ "'result' to KICK_BANNED, KICK_WHITELIST, KICK_OTHER, or KICK_FULL. "
+ "The default for 'result' is ALLOWED. When setting 'result', you "
+ "can specify the kick message by modifying 'kickmsg'. "
+ "{player: The player's name | kickmsg: The default kick message | "
+ "ip: the player's IP address | result: the default response to their logging in}"
+ "{kickmsg|result}"
+ "{player|kickmsg|ip|result}";
}
@Override
public boolean matches(Map<String, Construct> prefilter, BindableEvent e) throws PrefilterNonMatchException {
if(e instanceof MCPlayerPreLoginEvent) {
MCPlayerPreLoginEvent event = (MCPlayerPreLoginEvent) e;
if(prefilter.containsKey("player")) {
if(!event.getName().equals(prefilter.get("player").val())) {
return false;
}
}
}
return true;
}
@Override
public BindableEvent convert(CArray manualObject, Target t) {
return null;
}
@Override
public Map<String, Construct> evaluate(BindableEvent e) throws EventException {
if(e instanceof MCPlayerPreLoginEvent) {
MCPlayerPreLoginEvent event = (MCPlayerPreLoginEvent) e;
Map<String, Construct> map = evaluate_helper(e);
map.put("player", new CString(event.getName(), Target.UNKNOWN));
map.put("ip", new CString(event.getIP(), Target.UNKNOWN));
map.put("result", new CString(event.getResult(), Target.UNKNOWN));
map.put("kickmsg", new CString(event.getKickMessage(), Target.UNKNOWN));
return map;
} else {
throw new EventException("Cannot convert e to PlayerPreLoginEvent");
}
}
@Override
public Driver driver() {
return Driver.PLAYER_PRELOGIN;
}
@Override
public boolean modifyEvent(String key, Construct value, BindableEvent e) {
if(e instanceof MCPlayerPreLoginEvent) {
MCPlayerPreLoginEvent event = (MCPlayerPreLoginEvent) e;
if(key.equals("result")) {
String[] possible = new String[]{"ALLOWED", "KICK_WHITELIST",
"KICK_BANNED", "KICK_FULL", "KICK_OTHER"};
if(Arrays.asList(possible).contains(value.val().toUpperCase())) {
event.setResult(value.val().toUpperCase());
}
} else if(key.equals("kickmsg")) {
event.setKickMessage(value.val());
}
}
return false;
}
@Override
public CHVersion since() {
return CHVersion.V3_3_1;
}
}
@api
public static class player_login extends AbstractEvent {
@@ -660,16 +571,16 @@ public String docs() {
@Override
public boolean matches(Map<String, Construct> prefilter, BindableEvent e) throws PrefilterNonMatchException {
if(e instanceof MCPlayerPreLoginEvent) {
MCPlayerPreLoginEvent event = (MCPlayerPreLoginEvent) e;
if(e instanceof MCPlayerLoginEvent) {
MCPlayerLoginEvent event = (MCPlayerLoginEvent) e;
if(prefilter.containsKey("player")) {
if(!event.getName().equals(prefilter.get("player").val())) {
return false;
}
}
return true;
}
return true;
return false;
}
@Override

0 comments on commit 9422e90

Please sign in to comment.