-
Notifications
You must be signed in to change notification settings - Fork 2
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 #7 from Iteranya/1.20.1_Built_In_Script
1.20.1 built in script
- Loading branch information
Showing
36 changed files
with
696 additions
and
533 deletions.
There are no files selected for viewing
33 changes: 0 additions & 33 deletions
33
src/main/java/org/arsparadox/mobtalkerredux/DebugTile.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
53 changes: 0 additions & 53 deletions
53
src/main/java/org/arsparadox/mobtalkerredux/HelloWorldItem.java
This file was deleted.
Oops, something went wrong.
80 changes: 80 additions & 0 deletions
80
src/main/java/org/arsparadox/mobtalkerredux/MobTalkerItem.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,80 @@ | ||
package org.arsparadox.mobtalkerredux; | ||
|
||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.world.InteractionHand; | ||
import net.minecraft.world.InteractionResult; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.Level; | ||
import org.arsparadox.mobtalkerredux.vn.controller.VisualNovelEngine; | ||
import org.arsparadox.mobtalkerredux.vn.model.ScriptLoader; | ||
import org.arsparadox.mobtalkerredux.vn.view.DialogueScreen; | ||
|
||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
|
||
public class MobTalkerItem extends Item { | ||
|
||
public MobTalkerItem() { | ||
super(new Item.Properties()); | ||
} | ||
|
||
@Override | ||
public InteractionResult interactLivingEntity(ItemStack stack, Player player, LivingEntity target, InteractionHand hand) { | ||
Level world = player.level(); | ||
|
||
// Check if the entity has a custom name | ||
if (target.getCustomName() != null) { | ||
String entityName = target.getCustomName().getString(); | ||
boolean day = world.isDay(); | ||
|
||
if (!world.isClientSide()) { // Only run on the server side | ||
player.sendSystemMessage(Component.literal("Hewwo World~")); | ||
} else { // Client-side: Open dialogue screen | ||
Minecraft minecraft = Minecraft.getInstance(); | ||
minecraft.execute(() -> { | ||
|
||
serverSideExecute(player, entityName+".json"); | ||
|
||
}); | ||
} | ||
return InteractionResult.SUCCESS; | ||
} | ||
|
||
return InteractionResult.PASS; // Return PASS if the entity doesn't have a custom name | ||
} | ||
|
||
private static void serverSideExecute(Player player, String scriptFileName) { | ||
//String uid = player.getName().toString();//literal{Dev} | ||
String uid = player.getName().getString();//Dev | ||
long timeOfDay = player.level().getDayTime() % 24000; // Minecraft-style day/night cycle in ticks | ||
boolean day = (timeOfDay >= 0 && timeOfDay < 12000); | ||
try { | ||
VisualNovelEngine vnEngine = new VisualNovelEngine(ScriptLoader.loadScript(scriptFileName,uid), scriptFileName, uid,day); | ||
sendClientMessage(player, "Trying to load the file config/mobtalkerredux/" + scriptFileName); | ||
clientSideRenderDialogueScreen(vnEngine); | ||
} catch (IOException e) { | ||
sendClientMessage(player, "Failed to find the file config/mobtalkerredux/" + scriptFileName); | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private static void clientSideRenderDialogueScreen(VisualNovelEngine vnEngine) { | ||
Minecraft.getInstance().execute(() -> { | ||
try { | ||
//Minecraft.getInstance().setScreen(new DialogueScreen(vnEngine,player)); | ||
Minecraft.getInstance().setScreen(new DialogueScreen(vnEngine)); | ||
} catch (FileNotFoundException e) { | ||
throw new RuntimeException(e); | ||
} | ||
}); | ||
} | ||
|
||
private static void sendClientMessage(Player player, String message) { | ||
player.sendSystemMessage(Component.literal(message)); | ||
} | ||
} | ||
|
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
68 changes: 68 additions & 0 deletions
68
src/main/java/org/arsparadox/mobtalkerredux/vn/controller/CommandRequestHandler.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,68 @@ | ||
package org.arsparadox.mobtalkerredux.vn.controller; | ||
|
||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.server.MinecraftServer; | ||
import net.minecraft.server.level.ServerPlayer; | ||
|
||
public class CommandRequestHandler { | ||
public static boolean handleCommandRequest(ServerPlayer player, String command) { | ||
MinecraftServer server = player.getServer(); | ||
|
||
// Early return if server is null | ||
if (server == null) return false; | ||
|
||
// Check if it's single player | ||
boolean isSinglePlayer = server.isSingleplayer(); | ||
|
||
if (isSinglePlayer) { | ||
// Single player - just run the command with full permissions | ||
return ForgeCommandRunner.runCommand(server, command); | ||
} | ||
|
||
// Multiplayer validation | ||
if (!isCommandAllowed(command)) { | ||
// Command not in whitelist | ||
player.sendSystemMessage(Component.literal("This command is not allowed!")); | ||
return false; | ||
} | ||
|
||
if (!hasPermission(player)) { | ||
// Player doesn't have permission | ||
player.sendSystemMessage(Component.literal("You don't have permission to use visual novel commands!")); | ||
return false; | ||
} | ||
|
||
// Rate limiting check | ||
if (isRateLimited(player)) { | ||
player.sendSystemMessage(Component.literal("Please wait before using another command!")); | ||
return false; | ||
} | ||
|
||
// If we get here, command is allowed - run it with appropriate permission level | ||
// Note: You might want to run with player's actual permission level instead of level 4 | ||
return ForgeCommandRunner.runCommand(server, command); | ||
} | ||
|
||
private static boolean isCommandAllowed(String command) { | ||
// Example validation - you should implement your own logic | ||
// Maybe check against a config-defined whitelist | ||
// Maybe block dangerous commands like /op, /stop, etc. | ||
return !command.startsWith("/op") && | ||
!command.startsWith("/stop") && | ||
!command.startsWith("/ban"); | ||
} | ||
|
||
private static boolean hasPermission(ServerPlayer player) { | ||
// Example permission check | ||
// Could check against your mod's permission system | ||
// Or check player's op status | ||
return player.hasPermissions(2); // Level 2 is typical for command blocks | ||
} | ||
|
||
private static boolean isRateLimited(ServerPlayer player) { | ||
// Implement rate limiting logic | ||
// Could track last command time per player | ||
// Return true if player is sending too many commands | ||
return false; // Simplified for example | ||
} | ||
} |
Oops, something went wrong.