-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from architects-land/fix/kicking-bugs
[Fix] Kicking can provoke bugs
- Loading branch information
Showing
6 changed files
with
138 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...in/java/world/anhgelus/architectsland/difficultydeathscaler/mixin/PlayerManagerMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package world.anhgelus.architectsland.difficultydeathscaler.mixin; | ||
|
||
import com.mojang.authlib.GameProfile; | ||
import net.minecraft.server.PlayerManager; | ||
import net.minecraft.text.Text; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
import world.anhgelus.architectsland.difficultydeathscaler.difficulty.player.PlayerDifficultyManager; | ||
|
||
import java.net.SocketAddress; | ||
|
||
import static world.anhgelus.architectsland.difficultydeathscaler.utils.Getters.PROFILE_DIFFICULTY_GETTER; | ||
|
||
@Mixin(PlayerManager.class) | ||
public abstract class PlayerManagerMixin { | ||
@Inject(at = @At("HEAD"), method = "checkCanJoin", cancellable = true) | ||
private void checkCanJoin(SocketAddress address, GameProfile profile, CallbackInfoReturnable<Text> cir) { | ||
if (PROFILE_DIFFICULTY_GETTER == null) return; | ||
final var difficulty = PROFILE_DIFFICULTY_GETTER.get(profile); | ||
if (difficulty == null) return; | ||
if (difficulty.diedTooMuch()) | ||
cir.setReturnValue(PlayerDifficultyManager.KICKED_DIED_TOO_MUCH_MESSAGE); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/world/anhgelus/architectsland/difficultydeathscaler/utils/Getters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package world.anhgelus.architectsland.difficultydeathscaler.utils; | ||
|
||
import com.mojang.authlib.GameProfile; | ||
import net.minecraft.server.MinecraftServer; | ||
import net.minecraft.server.network.ServerPlayerEntity; | ||
import world.anhgelus.architectsland.difficultydeathscaler.difficulty.global.GlobalDifficultyManager; | ||
import world.anhgelus.architectsland.difficultydeathscaler.difficulty.player.PlayerDifficultyManager; | ||
|
||
public class Getters { | ||
/** | ||
* Functional interface giving the player difficulty manager with GameProfile | ||
*/ | ||
@FunctionalInterface | ||
public interface ProfileDifficultyGetter { | ||
PlayerDifficultyManager get(GameProfile profile); | ||
} | ||
|
||
/** | ||
* Functional interface giving the global difficulty manager | ||
*/ | ||
@FunctionalInterface | ||
public interface GlobalDifficultyGetter { | ||
GlobalDifficultyManager get(); | ||
} | ||
|
||
/** | ||
* Functional interface giving the player difficulty manager | ||
*/ | ||
@FunctionalInterface | ||
public interface PlayerDifficultyGetter { | ||
PlayerDifficultyManager get(MinecraftServer server, ServerPlayerEntity player); | ||
} | ||
|
||
public static Getters.ProfileDifficultyGetter PROFILE_DIFFICULTY_GETTER; | ||
|
||
public static Getters.PlayerDifficultyGetter PLAYER_DIFFICULTY_GETTER; | ||
|
||
public static Getters.GlobalDifficultyGetter GLOBAL_DIFFICULTY_GETTER; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters