Browse Source

removed garbage, make plots in lists unique, update to new forge
version, removed debug element in perms

Kajetan Johannes Hammerle 4 years ago
parent
commit
90b5e1a311

+ 14 - 0
.gitignore

@@ -0,0 +1,14 @@
+/run
+/build
+/gradle
+gradle.properties
+gradlew
+/.gradle
+/.nb-gradle
+.nb-gradle-properties
+runClient.launch
+runServer.launch
+/libs
+LineCounter.jar
+cleanEclipse.sh
+uploadMod.sh

+ 3 - 3
build.gradle

@@ -10,8 +10,8 @@ buildscript {
 }
 apply plugin: 'net.minecraftforge.gradle'
 // Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.
-apply plugin: 'eclipse'
-apply plugin: 'maven-publish'
+//apply plugin: 'eclipse'
+//apply plugin: 'maven-publish'
 
 version = '1.0'
 group = 'me.hammerle.km'
@@ -39,7 +39,7 @@ minecraft {
 }
 
 dependencies {
-    minecraft 'net.minecraftforge:forge:1.14.4-28.0.91'
+    minecraft 'net.minecraftforge:forge:1.14.4-28.1.90'
     
     compile 'mysql:mysql-connector-java:5.1.42'
     

+ 0 - 3
cleanEclipse.sh

@@ -1,3 +0,0 @@
-rm .classpath
-rm -r .settings
-rm .project

+ 0 - 4
gradle.properties

@@ -1,4 +0,0 @@
-# Sets default memory used for gradle commands. Can be overridden by user or command line properties.
-# This is required to provide enough memory for the Minecraft decompilation process.
-org.gradle.jvmargs=-Xmx3G
-org.gradle.daemon=false

+ 0 - 172
gradlew

@@ -1,172 +0,0 @@
-#!/usr/bin/env sh
-
-##############################################################################
-##
-##  Gradle start up script for UN*X
-##
-##############################################################################
-
-# Attempt to set APP_HOME
-# Resolve links: $0 may be a link
-PRG="$0"
-# Need this for relative symlinks.
-while [ -h "$PRG" ] ; do
-    ls=`ls -ld "$PRG"`
-    link=`expr "$ls" : '.*-> \(.*\)$'`
-    if expr "$link" : '/.*' > /dev/null; then
-        PRG="$link"
-    else
-        PRG=`dirname "$PRG"`"/$link"
-    fi
-done
-SAVED="`pwd`"
-cd "`dirname \"$PRG\"`/" >/dev/null
-APP_HOME="`pwd -P`"
-cd "$SAVED" >/dev/null
-
-APP_NAME="Gradle"
-APP_BASE_NAME=`basename "$0"`
-
-# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
-DEFAULT_JVM_OPTS=""
-
-# Use the maximum available, or set MAX_FD != -1 to use that value.
-MAX_FD="maximum"
-
-warn () {
-    echo "$*"
-}
-
-die () {
-    echo
-    echo "$*"
-    echo
-    exit 1
-}
-
-# OS specific support (must be 'true' or 'false').
-cygwin=false
-msys=false
-darwin=false
-nonstop=false
-case "`uname`" in
-  CYGWIN* )
-    cygwin=true
-    ;;
-  Darwin* )
-    darwin=true
-    ;;
-  MINGW* )
-    msys=true
-    ;;
-  NONSTOP* )
-    nonstop=true
-    ;;
-esac
-
-CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
-
-# Determine the Java command to use to start the JVM.
-if [ -n "$JAVA_HOME" ] ; then
-    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
-        # IBM's JDK on AIX uses strange locations for the executables
-        JAVACMD="$JAVA_HOME/jre/sh/java"
-    else
-        JAVACMD="$JAVA_HOME/bin/java"
-    fi
-    if [ ! -x "$JAVACMD" ] ; then
-        die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
-
-Please set the JAVA_HOME variable in your environment to match the
-location of your Java installation."
-    fi
-else
-    JAVACMD="java"
-    which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
-
-Please set the JAVA_HOME variable in your environment to match the
-location of your Java installation."
-fi
-
-# Increase the maximum file descriptors if we can.
-if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
-    MAX_FD_LIMIT=`ulimit -H -n`
-    if [ $? -eq 0 ] ; then
-        if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
-            MAX_FD="$MAX_FD_LIMIT"
-        fi
-        ulimit -n $MAX_FD
-        if [ $? -ne 0 ] ; then
-            warn "Could not set maximum file descriptor limit: $MAX_FD"
-        fi
-    else
-        warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
-    fi
-fi
-
-# For Darwin, add options to specify how the application appears in the dock
-if $darwin; then
-    GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
-fi
-
-# For Cygwin, switch paths to Windows format before running java
-if $cygwin ; then
-    APP_HOME=`cygpath --path --mixed "$APP_HOME"`
-    CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
-    JAVACMD=`cygpath --unix "$JAVACMD"`
-
-    # We build the pattern for arguments to be converted via cygpath
-    ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
-    SEP=""
-    for dir in $ROOTDIRSRAW ; do
-        ROOTDIRS="$ROOTDIRS$SEP$dir"
-        SEP="|"
-    done
-    OURCYGPATTERN="(^($ROOTDIRS))"
-    # Add a user-defined pattern to the cygpath arguments
-    if [ "$GRADLE_CYGPATTERN" != "" ] ; then
-        OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
-    fi
-    # Now convert the arguments - kludge to limit ourselves to /bin/sh
-    i=0
-    for arg in "$@" ; do
-        CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
-        CHECK2=`echo "$arg"|egrep -c "^-"`                                 ### Determine if an option
-
-        if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then                    ### Added a condition
-            eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
-        else
-            eval `echo args$i`="\"$arg\""
-        fi
-        i=$((i+1))
-    done
-    case $i in
-        (0) set -- ;;
-        (1) set -- "$args0" ;;
-        (2) set -- "$args0" "$args1" ;;
-        (3) set -- "$args0" "$args1" "$args2" ;;
-        (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
-        (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
-        (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
-        (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
-        (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
-        (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
-    esac
-fi
-
-# Escape application args
-save () {
-    for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
-    echo " "
-}
-APP_ARGS=$(save "$@")
-
-# Collect all arguments for the java command, following the shell quoting and substitution rules
-eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
-
-# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
-if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
-  cd "$(dirname "$0")"
-fi
-
-exec "$JAVACMD" "$@"

+ 5 - 1
src/main/java/me/km/KajetansMod.java

@@ -10,6 +10,7 @@ import net.minecraftforge.fml.event.server.FMLServerStoppingEvent;
 import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
 import net.minecraftforge.fml.common.Mod;
 import net.minecraftforge.eventbus.api.IEventBus;
+import net.minecraftforge.eventbus.api.SubscribeEvent;
 import net.minecraftforge.fml.DeferredWorkQueue;
 
 @Mod.EventBusSubscriber
@@ -27,6 +28,8 @@ public class KajetansMod
         bus.addListener(this::setupServer);
         bus.addListener(this::clientInit);
         bus.addListener(this::onServerStop);
+        
+        MinecraftForge.EVENT_BUS.register(this);
     }
     
     private void init(FMLCommonSetupEvent e) 
@@ -49,7 +52,8 @@ public class KajetansMod
         Server.onStart(e.getServerSupplier().get());
     }
     
-    private void onServerStop(FMLServerStoppingEvent e) 
+    @SubscribeEvent
+    public void onServerStop(FMLServerStoppingEvent e) 
     {
         if(e.getServer().isDedicatedServer())
         {

+ 8 - 2
src/main/java/me/km/Server.java

@@ -45,6 +45,7 @@ public class Server
     private static DataBank databank;
     private static Scripts scripts;
     public static ScriptEvents scriptEvents;
+    private static WorldPlotMap plotMap;
     
     public static void onStart(DedicatedServer serverIn)
     {
@@ -99,8 +100,13 @@ public class Server
         }
         databank.startReconnecting(scheduler);
         
-        // protections / block protections / player manager
-        WorldPlotMap plotMap = new WorldPlotMap();
+        // protections
+        plotMap = new WorldPlotMap();
+        scheduler.scheduleTask(() -> plotMap.read(server, logger));
+        long time = 20 * 60 * 30; // all 30 minutes
+        scheduler.scheduleRepeatingTask(() -> plotMap.save(), time, time);
+                
+        // block protections / player manager
         IBlockProtection blockProtection;
         IPlayerBank playerBank;
         if(databank.isDummyDatabank())

+ 0 - 4
src/main/java/me/km/permissions/PermissionManager.java

@@ -55,10 +55,6 @@ public class PermissionManager
     
     public boolean hasPermission(UUID uuid, String perm) 
     {
-        if(perm.equals("plot.bypass"))
-        {
-            return false;
-        }
         if(debug)
         {
             return true;

+ 88 - 1
src/main/java/me/km/plots/PlotMap.java

@@ -1,5 +1,12 @@
 package me.km.plots;
 
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.EOFException;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
@@ -29,6 +36,13 @@ public class PlotMap
 
         public Plot(int id, int minX, int minY, int minZ, int maxX, int maxY, int maxZ)
         {
+            minX = Math.min(16000, Math.max(-16000, minX));
+            minY = Math.min(16000, Math.max(-16000, minY));
+            minZ = Math.min(16000, Math.max(-16000, minZ));
+            maxX = Math.min(16000, Math.max(-16000, maxX));
+            maxY = Math.min(16000, Math.max(-16000, maxY));
+            maxZ = Math.min(16000, Math.max(-16000, maxZ));
+            
             this.id = id;
             if(minX < maxX)
             {
@@ -211,7 +225,10 @@ public class PlotMap
                 {
                     data[hash] = new ArrayList<>();
                 }
-                data[hash].add(p);
+                if(!data[hash].contains(p))
+                {
+                    data[hash].add(p);
+                }
             }
         }
     }
@@ -389,4 +406,74 @@ public class PlotMap
             }
         };
     }
+    
+    public void save(String path)
+    {
+        File f = new File(path);
+        try(DataOutputStream out = new DataOutputStream(new FileOutputStream(f)))
+        {
+            Iterator<Plot> iter = getIterator();
+            while(iter.hasNext())
+            {
+                Plot p = iter.next();
+                
+                out.writeInt(p.id);
+                out.writeShort(p.minX);
+                out.writeShort(p.minY);
+                out.writeShort(p.minZ);
+                out.writeShort(p.maxX);
+                out.writeShort(p.maxY);
+                out.writeShort(p.maxZ);
+                int owners = Math.min(127, p.owners.size());
+                out.writeByte(owners);
+                for(int i = 0; i < owners; i++)
+                {
+                    out.writeLong(p.owners.get(i).getLeastSignificantBits());
+                    out.writeLong(p.owners.get(i).getMostSignificantBits());
+                }
+                out.writeInt(p.flags);
+                out.writeUTF(p.name);
+            }
+        }
+        catch(IOException ex)
+        {
+            ex.printStackTrace();
+        }
+    }
+    
+    public void read(File f)
+    {
+        if(!f.exists())
+        {
+            return;
+        }
+        try(DataInputStream in = new DataInputStream(new FileInputStream(f)))
+        {
+            int id = in.readInt();
+            int minX = in.readShort();
+            int minY = in.readShort();
+            int minZ = in.readShort();
+            int maxX = in.readShort();
+            int maxY = in.readShort();
+            int maxZ = in.readShort();
+            
+            Plot p = add(minX, minY, minZ, maxX, maxY, maxZ, id);
+            int owners = in.readByte();
+            for(int i = 0; i < owners; i++)
+            {
+                long lsb = in.readLong();
+                long msb = in.readLong();
+                p.owners.add(new UUID(msb, lsb));
+            }
+            p.flags = in.readInt();
+            p.name = in.readUTF();
+        }
+        catch(EOFException ex)
+        {
+        }
+        catch(IOException ex)
+        {
+            ex.printStackTrace();
+        }
+    }
 }

+ 37 - 0
src/main/java/me/km/plots/WorldPlotMap.java

@@ -1,13 +1,17 @@
 package me.km.plots;
 
+import java.io.File;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.UUID;
+import me.hammerle.snuviscript.code.ISnuviLogger;
 import me.km.plots.PlotMap.Plot;
+import me.km.world.WorldManager;
 import net.minecraft.entity.player.PlayerEntity;
+import net.minecraft.server.MinecraftServer;
 import net.minecraft.util.math.BlockPos;
 import net.minecraft.world.IWorld;
 
@@ -117,4 +121,37 @@ public class WorldPlotMap
         }
         return Collections.EMPTY_LIST.iterator();
     }
+    
+    public void save()
+    {
+        File f = new File("plot_storage");
+        f.mkdir();
+        maps.entrySet().forEach((entry) ->
+        {
+            String name = WorldManager.getName(entry.getKey());
+            entry.getValue().save("plot_storage/" + name);
+        });
+    }
+    
+    public void read(MinecraftServer ms, ISnuviLogger logger)
+    {
+        File dir = new File("plot_storage");
+        if(!dir.exists())
+        {
+            return;
+        }
+        for(File f : dir.listFiles())
+        {
+            String name = f.getName();
+            IWorld sw = WorldManager.get(ms, f.getName());
+            if(sw == null)
+            {
+                logger.print(String.format("invalid world storage '%s'", name));
+                continue;
+            }
+            PlotMap pm = new PlotMap();
+            maps.put(sw, pm);
+            pm.read(f);
+        }
+    }
 }

+ 0 - 2
uploadMod.sh

@@ -1,2 +0,0 @@
-./gradlew build
-scp build/libs/km-1.0.jar alpaga:../minecraft/server/mods