forked from Minecraft-AMS/Carpet-AMS-Addition
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Delete some laggy feature from /interaction
- Loading branch information
1 parent
e929ce3
commit b0edea1
Showing
21 changed files
with
168 additions
and
603 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package club.mcams.carpet.command; | ||
|
||
import carpet.utils.Messenger; | ||
import club.mcams.carpet.AmsServerSettings; | ||
import club.mcams.carpet.function.Ghost; | ||
import club.mcams.carpet.util.CommandHelper; | ||
import com.mojang.brigadier.CommandDispatcher; | ||
import com.mojang.brigadier.arguments.BoolArgumentType; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.server.command.ServerCommandSource; | ||
|
||
import static com.mojang.brigadier.arguments.BoolArgumentType.getBool; | ||
import static net.minecraft.server.command.CommandManager.argument; | ||
import static net.minecraft.server.command.CommandManager.literal; | ||
|
||
public class GhostCommand { | ||
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) { | ||
dispatcher.register(literal("ghost") | ||
.requires((player) -> CommandHelper.canUseCommand(player, AmsServerSettings.commandGhost)) | ||
.executes((c) -> listPlayerInteractions(c.getSource(), c.getSource().getName())) | ||
.then(argument("boolean", BoolArgumentType.bool()). | ||
executes((c) -> setPlayerInteraction(c.getSource(), c.getSource().getName(), getBool(c, "boolean"))) | ||
)); | ||
|
||
} | ||
|
||
private static int setPlayerInteraction(ServerCommandSource source, String playerName, boolean b) { | ||
PlayerEntity player = source.getServer().getPlayerManager().getPlayer(playerName); | ||
if (player == null) { | ||
Messenger.m(source, "r No player specified"); | ||
return 0; | ||
} | ||
Ghost.setPlayerInteraction(playerName, !b, true); | ||
Messenger.m(source, "w Set interaction ", "g " + "chunkloading", "w to ", "g " + b); | ||
return 1; | ||
} | ||
|
||
private static int listPlayerInteractions(ServerCommandSource source, String playerName) { | ||
PlayerEntity player = source.getServer().getPlayerManager().getPlayer(playerName); | ||
if (player == null) { | ||
Messenger.m(source, "r No player specified"); | ||
return 0; | ||
} | ||
boolean playerInteractions = Ghost.onlinePlayerMap.getOrDefault(playerName, true); | ||
|
||
if (playerInteractions) Messenger.m(source, "w " + "chunk loading" + ": ", "g false"); | ||
else Messenger.m(source, "w " + "chunk loading" + ": ", "g true"); | ||
return 1; | ||
} | ||
} |
67 changes: 0 additions & 67 deletions
67
src/main/java/club/mcams/carpet/command/InteractionCommand.java
This file was deleted.
Oops, something went wrong.
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,42 @@ | ||
package club.mcams.carpet.function; | ||
|
||
import carpet.CarpetServer; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.server.network.ServerPlayerEntity; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class Ghost { | ||
public static Map<String, Boolean> onlinePlayerMap = new HashMap<>(); | ||
public static Map<String, Boolean> offlinePlayerMap = new HashMap<>(); | ||
|
||
public static void setPlayerInteraction(String playerName, boolean b, boolean online) { | ||
if (playerFromName(playerName) == null) return; | ||
if (online) { | ||
onlinePlayerMap.put(playerName, b); | ||
} else { | ||
offlinePlayerMap.put(playerName, b); | ||
} | ||
} | ||
|
||
public static void onPlayerConnect(PlayerEntity player) { | ||
String playerName = player.getName().getString(); | ||
if (offlinePlayerMap.containsKey(playerName)) { | ||
setPlayerInteraction(playerName, true, true); | ||
offlinePlayerMap.remove(playerName); | ||
} | ||
} | ||
|
||
public static void onPlayerDisconnect(PlayerEntity player) { | ||
String playerName = player.getName().getString(); | ||
if (onlinePlayerMap.containsKey(playerName)) { | ||
setPlayerInteraction(playerName, true, false); | ||
onlinePlayerMap.remove(playerName); | ||
} | ||
} | ||
|
||
protected static ServerPlayerEntity playerFromName(String name) { | ||
return CarpetServer.minecraft_server.getPlayerManager().getPlayer(name); | ||
} | ||
} |
77 changes: 0 additions & 77 deletions
77
src/main/java/club/mcams/carpet/function/Interactions.java
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.