added __on_player_connects and dis. fixes #294
This commit is contained in:
1 parent
a7cd2c49cc
commit
e2e45bb20d
8 files changed
+48
-2
No files matched your search
@@ -3047,6 +3047,8 @@ __on_player_starts_sprinting(player)
|
||||
__on_player_stops_sprinting(player)
|
||||
__on_player_drops_item(player)
|
||||
__on_player_drops_stack(player)
|
||||
__on_player_connects(player)
|
||||
__on_player_disconnects(player, reason)
|
||||
__on_statistic(player, category, event, value) // player statistic changes
|
||||
</pre>
|
||||
|
||||
|
||||
@@ -48,6 +48,8 @@ __on_player_starts_sprinting(player)
|
||||
__on_player_stops_sprinting(player)
|
||||
__on_player_drops_item(player)
|
||||
__on_player_drops_stack(player)
|
||||
__on_player_connects(player)
|
||||
__on_player_disconnects(player, reason)
|
||||
__on_statistic(player, category, event, value) // player statistic changes
|
||||
</pre>
|
||||
|
||||
|
||||
@@ -30,4 +30,6 @@ __on_tick_nether
|
||||
__on_player_takes_damage
|
||||
__on_player_deals_damage
|
||||
__on_player_dies
|
||||
__on_player_respawns
|
||||
__on_player_respawns
|
||||
__on_player_disconnects
|
||||
__on_player_connects
|
||||
@@ -112,6 +112,8 @@
|
||||
__on_player_deals_damage
|
||||
__on_player_dies
|
||||
__on_player_respawns
|
||||
__on_player_disconnects
|
||||
__on_player_connects
|
||||
</Keywords>
|
||||
<Keywords name="Keywords8">$</Keywords>
|
||||
<Keywords name="Delimiters">00' 01\ 02' 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23</Keywords>
|
||||
|
||||
@@ -9,6 +9,8 @@ import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import static carpet.script.CarpetEventServer.Event.PLAYER_CONNECTS;
|
||||
|
||||
@Mixin(PlayerManager.class)
|
||||
public class PlayerManager_coreMixin
|
||||
{
|
||||
@@ -16,5 +18,6 @@ public class PlayerManager_coreMixin
|
||||
private void onPlayerConnected(ClientConnection connection, ServerPlayerEntity player, CallbackInfo ci)
|
||||
{
|
||||
CarpetServer.onPlayerLoggedIn(player);
|
||||
PLAYER_CONNECTS.onPlayerEvent(player);
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,8 @@ import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import static carpet.script.CarpetEventServer.Event.PLAYER_DISCONNECTS;
|
||||
|
||||
@Mixin(ServerPlayNetworkHandler.class)
|
||||
public class ServerPlayNetworkHandler_coreMixin {
|
||||
@Shadow
|
||||
@@ -21,5 +23,6 @@ public class ServerPlayNetworkHandler_coreMixin {
|
||||
@Inject(method = "onDisconnected", at = @At("HEAD"))
|
||||
private void onPlayerDisconnect(Text reason, CallbackInfo ci) {
|
||||
CarpetServer.onPlayerLoggedOut(this.player);
|
||||
if (PLAYER_DISCONNECTS.isNeeded()) PLAYER_DISCONNECTS.onPlayerMessage(player, reason.asString());
|
||||
}
|
||||
}
|
||||
@@ -553,6 +553,23 @@ public class CarpetEventServer
|
||||
), player::getCommandSource);
|
||||
}
|
||||
},
|
||||
PLAYER_CONNECTS("player_connects", 1, false) {
|
||||
@Override
|
||||
public void onPlayerEvent(ServerPlayerEntity player)
|
||||
{
|
||||
handler.call( () -> Collections.singletonList(((c, t) -> new EntityValue(player))), player::getCommandSource);
|
||||
}
|
||||
},
|
||||
PLAYER_DISCONNECTS("player_disconnects", 2, false) {
|
||||
@Override
|
||||
public void onPlayerMessage(ServerPlayerEntity player, String message)
|
||||
{
|
||||
handler.call( () -> Arrays.asList(
|
||||
((c, t) -> new EntityValue(player)),
|
||||
((c, t) -> new StringValue(message))
|
||||
), player::getCommandSource);
|
||||
}
|
||||
},
|
||||
STATISTICS("statistic", 4, false)
|
||||
{
|
||||
private <T> Identifier getStatId(Stat<T> stat)
|
||||
@@ -617,6 +634,7 @@ public class CarpetEventServer
|
||||
public void onTick() { }
|
||||
public void onChunkGenerated(ServerWorld world, Chunk chunk) { }
|
||||
public void onPlayerEvent(ServerPlayerEntity player) { }
|
||||
public void onPlayerMessage(ServerPlayerEntity player, String message) { }
|
||||
public void onPlayerStatistic(ServerPlayerEntity player, Stat<?> stat, int amount) { }
|
||||
public void onMountControls(ServerPlayerEntity player, float strafeSpeed, float forwardSpeed, boolean jumping, boolean sneaking) { }
|
||||
public void onItemAction(ServerPlayerEntity player, Hand enumhand, ItemStack itemstack) { }
|
||||
|
||||
@@ -229,4 +229,18 @@ __on_player_changes_dimension(player, from_pos, from_dimension, to_pos, to_dimen
|
||||
print(' - player: '+player);
|
||||
print(' - from '+from_dimension+' at '+map(from_pos, str('%.2f',_)));
|
||||
print(' - to '+to_dimension+if(to_pos == null, '', ' at '+map(to_pos, str('%.2f',_))));
|
||||
)
|
||||
);
|
||||
|
||||
__on_player_connects(player) ->
|
||||
( // you will never sees it
|
||||
print('');
|
||||
print('__on_player_connects(player)');
|
||||
print('Player '+player+' connects.')
|
||||
);
|
||||
|
||||
__on_player_disconnects(player, reason) ->
|
||||
( // you will never sees it either
|
||||
print('');
|
||||
print('__on_player_disconnects(player)');
|
||||
print('Player '+player+' disconnects because: '+reason)
|
||||
);
|
||||
Reference in new issue
Block a user