Browse Source

elytra snuvi events, bugfixes

Kajetan Johannes Hammerle 3 years ago
parent
commit
5026e1bee0

+ 10 - 0
src/main/java/me/km/overrides/ModEntityPlayerMP.java

@@ -15,11 +15,13 @@ import net.minecraft.world.GameRules;
 import net.minecraft.world.server.ServerWorld;
 
 public class ModEntityPlayerMP extends ServerPlayerEntity {
+
     private final PlayerScoreboard board;
     private int id = -1;
     private final HashMap<String, Integer> timedData;
     private final HashMap<String, Object> data;
     private StringTextComponent tabDisplayName = null;
+    private boolean elytra = false;
 
     private boolean isIterating = false;
 
@@ -47,6 +49,14 @@ public class ModEntityPlayerMP extends ServerPlayerEntity {
         super.tick();
         board.update(this);
         tickData();
+        if(ticksElytraFlying == 1) {
+            elytra = true;
+            Server.scriptEvents.onPlayerStartElytra(this);
+        }
+        if(ticksElytraFlying == 0 && elytra) {
+            elytra = false;
+            Server.scriptEvents.onPlayerStopElytra(this);
+        }
     }
 
     public void setTabListDisplayName(String name, ISnuviScheduler scheduler) {

+ 12 - 0
src/main/java/me/km/snuviscript/ScriptEvents.java

@@ -142,6 +142,18 @@ public class ScriptEvents implements BlockHarvest, Craft {
             sc.setVar("var", var);
         });
     }
+    
+    public void onPlayerStartElytra(PlayerEntity p) {
+        handleEvent("player_elytra_start", sc -> {
+            setPlayer(sc, p);
+        });
+    }
+    
+    public void onPlayerStopElytra(PlayerEntity p) {
+        handleEvent("player_elytra_stop", sc -> {
+            setPlayer(sc, p);
+        });
+    }
 
     public void onPlayerMove(PlayerEntity p, int id) {
         handleEvent("player_move", sc -> {

+ 0 - 3
src/main/java/me/km/snuviscript/commands/CommandUtils.java

@@ -9,13 +9,10 @@ import me.km.permissions.Permissions;
 import me.km.playerbank.IPlayerBank;
 import me.km.snuviscript.Scripts;
 import me.km.utils.Location;
-import me.km.utils.Utils;
 import net.minecraft.block.BlockState;
 import net.minecraft.command.ICommandSource;
 import net.minecraft.entity.player.PlayerEntity;
-import net.minecraft.entity.player.ServerPlayerEntity;
 import net.minecraft.server.MinecraftServer;
-import net.minecraft.server.management.PlayerList;
 import net.minecraft.util.text.ITextComponent;
 import net.minecraft.util.text.StringTextComponent;
 

+ 11 - 8
src/main/java/me/km/snuviscript/commands/PlayerCommands.java

@@ -42,6 +42,7 @@ import net.minecraft.world.World;
 import net.minecraft.world.server.ServerWorld;
 
 public class PlayerCommands {
+
     public static void registerFunctions(ScriptManager sm, Scripts scripts,
             Permissions perms, SnuviScheduler scheduler, MinecraftServer server,
             IPlayerBank playerBank) {
@@ -98,7 +99,11 @@ public class PlayerCommands {
             if(o instanceof PlayerEntity) {
                 return ((PlayerEntity) o).getName().getFormattedText();
             }
-            return server.getPlayerProfileCache().getProfileByUUID(getUUID(o.toString())).getName();
+            GameProfile gp = server.getPlayerProfileCache().getProfileByUUID(getUUID(o));
+            if(gp == null) {
+                return null;
+            }
+            return gp.getName();
         });
         sm.registerFunction("player.getuuid", (sc, in) -> {
             Object o = in[0].get(sc);
@@ -135,26 +140,24 @@ public class PlayerCommands {
                 case "s":
                 case "0":
                     p.setGameType(GameType.SURVIVAL);
-                    break;
+                    return;
                 case "creative":
                 case "c":
                 case "1":
                     p.setGameType(GameType.CREATIVE);
-                    break;
+                    return;
                 case "adventure":
                 case "a":
                 case "2":
                     p.setGameType(GameType.ADVENTURE);
-                    break;
+                    return;
                 case "spectator":
                 case "w":
                 case "3":
                     p.setGameType(GameType.SPECTATOR);
-                    break;
-                default:
-                    p.setGameType(GameType.CREATIVE);
-                    break;
+                    return;
             }
+            p.setGameType(GameType.CREATIVE);
         });
         sm.registerFunction("player.getlastdamager", (sc, in) -> {
             DamageSource ds = ((PlayerEntity) in[0].get(sc)).getLastDamageSource();

+ 2 - 0
src/main/java/me/km/snuviscript/commands/ReadCommands.java

@@ -1,5 +1,6 @@
 package me.km.snuviscript.commands;
 
+import java.util.UUID;
 import me.hammerle.snuviscript.code.ScriptManager;
 import me.hammerle.snuviscript.code.SnuviUtils;
 import me.km.utils.ItemStackUtils;
@@ -49,5 +50,6 @@ public class ReadCommands {
             });
             return entity;
         });
+        sm.registerFunction("read.uuid", (sc, in) -> UUID.fromString(in[0].getString(sc)));
     }
 }

+ 1 - 0
src/main/java/me/km/snuviscript/commands/TextCommands.java

@@ -1,5 +1,6 @@
 package me.km.snuviscript.commands;
 
+import java.util.UUID;
 import me.hammerle.snuviscript.code.ScriptManager;
 import me.km.utils.ItemStackUtils;
 import me.km.utils.Location;