Finish fixing warps
This commit is contained in:
parent
9f79565d56
commit
516f067fb9
9 changed files with 103 additions and 35 deletions
|
@ -137,7 +137,6 @@ dependencies {
|
||||||
minecraft "net.minecraftforge:forge:${mc_version}-${forge_version}"
|
minecraft "net.minecraftforge:forge:${mc_version}-${forge_version}"
|
||||||
|
|
||||||
implementation fg.deobf("dev.zontreck:libzontreck:${mc_version}-${libz_version}:dev")
|
implementation fg.deobf("dev.zontreck:libzontreck:${mc_version}-${libz_version}:dev")
|
||||||
compileOnly fg.deobf("dev.zontreck:libzontreck:${mc_version}-${libz_version}:dev")
|
|
||||||
runtimeOnly fg.deobf("dev.zontreck:libzontreck:${mc_version}-${libz_version}")
|
runtimeOnly fg.deobf("dev.zontreck:libzontreck:${mc_version}-${libz_version}")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,4 +12,4 @@ my_modid="ariasessentials"
|
||||||
mc_version=1.18.2
|
mc_version=1.18.2
|
||||||
forge_version=40.2.1
|
forge_version=40.2.1
|
||||||
parchment_version=2022.11.06
|
parchment_version=2022.11.06
|
||||||
libz_version=1.0.5.4
|
libz_version=1.0.5.0227232305
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package dev.zontreck.essentials;
|
package dev.zontreck.essentials;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
@ -11,6 +14,7 @@ import com.mojang.logging.LogUtils;
|
||||||
import dev.zontreck.essentials.commands.CommandRegister;
|
import dev.zontreck.essentials.commands.CommandRegister;
|
||||||
import dev.zontreck.essentials.homes.Homes;
|
import dev.zontreck.essentials.homes.Homes;
|
||||||
import dev.zontreck.essentials.homes.HomesProvider;
|
import dev.zontreck.essentials.homes.HomesProvider;
|
||||||
|
import dev.zontreck.essentials.util.EssentialsDatastore;
|
||||||
import dev.zontreck.libzontreck.events.ProfileLoadedEvent;
|
import dev.zontreck.libzontreck.events.ProfileLoadedEvent;
|
||||||
import dev.zontreck.libzontreck.events.ProfileUnloadedEvent;
|
import dev.zontreck.libzontreck.events.ProfileUnloadedEvent;
|
||||||
import dev.zontreck.libzontreck.profiles.Profile;
|
import dev.zontreck.libzontreck.profiles.Profile;
|
||||||
|
@ -33,6 +37,7 @@ public class AriasEssentials {
|
||||||
{
|
{
|
||||||
IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
|
IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||||
|
|
||||||
|
EssentialsDatastore.initialize();
|
||||||
MinecraftForge.EVENT_BUS.register(this);
|
MinecraftForge.EVENT_BUS.register(this);
|
||||||
MinecraftForge.EVENT_BUS.register(new CommandRegister());
|
MinecraftForge.EVENT_BUS.register(new CommandRegister());
|
||||||
}
|
}
|
||||||
|
@ -52,15 +57,4 @@ public class AriasEssentials {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public void onProfileLoaded(ProfileLoadedEvent ev)
|
|
||||||
{
|
|
||||||
player_homes.put(UUID.fromString(ev.profile.user_id), HomesProvider.getHomesForPlayer(ev.profile.user_id));
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public void onProfileUnloaded(ProfileUnloadedEvent ev)
|
|
||||||
{
|
|
||||||
player_homes.remove(UUID.fromString(ev.user_id));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,12 @@ import dev.zontreck.essentials.commands.teleport.TPAHereCommand;
|
||||||
import dev.zontreck.essentials.commands.teleport.TPAcceptCommand;
|
import dev.zontreck.essentials.commands.teleport.TPAcceptCommand;
|
||||||
import dev.zontreck.essentials.commands.teleport.TPCancelCommand;
|
import dev.zontreck.essentials.commands.teleport.TPCancelCommand;
|
||||||
import dev.zontreck.essentials.commands.teleport.TPDenyCommand;
|
import dev.zontreck.essentials.commands.teleport.TPDenyCommand;
|
||||||
|
import dev.zontreck.essentials.commands.warps.DelWarpCommand;
|
||||||
|
import dev.zontreck.essentials.commands.warps.RTPWarpCommand;
|
||||||
|
import dev.zontreck.essentials.commands.warps.SetWarpCommand;
|
||||||
|
import dev.zontreck.essentials.commands.warps.WarpCommand;
|
||||||
|
import dev.zontreck.essentials.commands.warps.WarpsCommand;
|
||||||
|
import dev.zontreck.essentials.warps.Warps;
|
||||||
import net.minecraftforge.event.RegisterCommandsEvent;
|
import net.minecraftforge.event.RegisterCommandsEvent;
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
|
|
||||||
|
@ -28,5 +34,11 @@ public class CommandRegister {
|
||||||
TPACommand.register(ev.getDispatcher());
|
TPACommand.register(ev.getDispatcher());
|
||||||
TPCancelCommand.register(ev.getDispatcher());
|
TPCancelCommand.register(ev.getDispatcher());
|
||||||
TPDenyCommand.register(ev.getDispatcher());
|
TPDenyCommand.register(ev.getDispatcher());
|
||||||
|
|
||||||
|
DelWarpCommand.register(ev.getDispatcher());
|
||||||
|
RTPWarpCommand.register(ev.getDispatcher());
|
||||||
|
SetWarpCommand.register(ev.getDispatcher());
|
||||||
|
WarpCommand.register(ev.getDispatcher());
|
||||||
|
WarpsCommand.register(ev.getDispatcher());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ public class HomesProvider {
|
||||||
*/
|
*/
|
||||||
public static Homes getHomesForPlayer(String player)
|
public static Homes getHomesForPlayer(String player)
|
||||||
{
|
{
|
||||||
Path homesFile = EssentialsDatastore.of(player).resolve("homes.nbt");
|
Path homesFile = EssentialsDatastore.of(player,true).resolve("homes.nbt");
|
||||||
|
|
||||||
Homes homes = new Homes(player);
|
Homes homes = new Homes(player);
|
||||||
if(homesFile.toFile().exists())
|
if(homesFile.toFile().exists())
|
||||||
|
@ -37,7 +37,7 @@ public class HomesProvider {
|
||||||
public static void commitHomes(Homes playerHomes)
|
public static void commitHomes(Homes playerHomes)
|
||||||
{
|
{
|
||||||
|
|
||||||
Path homesFile = EssentialsDatastore.of(playerHomes.playerID).resolve("homes.nbt");
|
Path homesFile = EssentialsDatastore.of(playerHomes.playerID,true).resolve("homes.nbt");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
NbtIo.write(playerHomes.serialize(), homesFile.toFile());
|
NbtIo.write(playerHomes.serialize(), homesFile.toFile());
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package dev.zontreck.essentials.util;
|
package dev.zontreck.essentials.util;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
import dev.zontreck.libzontreck.util.FileTreeDatastore;
|
import dev.zontreck.libzontreck.util.FileTreeDatastore;
|
||||||
|
@ -7,12 +9,45 @@ import dev.zontreck.libzontreck.util.FileTreeDatastore;
|
||||||
public class EssentialsDatastore extends FileTreeDatastore
|
public class EssentialsDatastore extends FileTreeDatastore
|
||||||
{
|
{
|
||||||
public static final Path AEBASE;
|
public static final Path AEBASE;
|
||||||
|
|
||||||
static{
|
static{
|
||||||
AEBASE = FileTreeDatastore.of("essentials");
|
AEBASE = FileTreeDatastore.of("essentials");
|
||||||
|
if(!AEBASE.toFile().exists())
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
Files.createDirectory(AEBASE);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Path of(String path)
|
public static void initialize()
|
||||||
{
|
{
|
||||||
return AEBASE.resolve(path);
|
if(!AEBASE.toFile().exists())
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
Files.createDirectory(AEBASE);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Path of(String path, boolean directory)
|
||||||
|
{
|
||||||
|
Path p = AEBASE.resolve(path);
|
||||||
|
if(!directory)return p;
|
||||||
|
if(!p.toFile().exists())
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
Files.createDirectory(p);
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
package dev.zontreck.essentials.util;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import dev.zontreck.essentials.AriasEssentials;
|
||||||
|
import dev.zontreck.essentials.homes.HomesProvider;
|
||||||
|
import dev.zontreck.libzontreck.events.ProfileLoadedEvent;
|
||||||
|
import dev.zontreck.libzontreck.events.ProfileUnloadedEvent;
|
||||||
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
|
||||||
|
@Mod.EventBusSubscriber(modid = AriasEssentials.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE)
|
||||||
|
public class ForgeEventsHandler {
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void onProfileLoaded(final ProfileLoadedEvent ev)
|
||||||
|
{
|
||||||
|
//Path playerStore = EssentialsDatastore.of(ev.profile.user_id,true);
|
||||||
|
|
||||||
|
AriasEssentials.player_homes.put(UUID.fromString(ev.profile.user_id), HomesProvider.getHomesForPlayer(ev.profile.user_id));
|
||||||
|
AriasEssentials.LOGGER.info("Homes loaded");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void onProfileUnloaded(final ProfileUnloadedEvent ev)
|
||||||
|
{
|
||||||
|
AriasEssentials.player_homes.remove(UUID.fromString(ev.user_id));
|
||||||
|
AriasEssentials.LOGGER.info("Homes unloaded");
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,19 +9,10 @@ import net.minecraft.nbt.NbtIo;
|
||||||
|
|
||||||
public class WarpsProvider extends EssentialsDatastore
|
public class WarpsProvider extends EssentialsDatastore
|
||||||
{
|
{
|
||||||
public static final Path BASE = of("warps");
|
public static final Path BASE = of("warps.nbt", false);
|
||||||
public static final Path WARPS_DATA = BASE.resolve("warps.nbt");
|
|
||||||
|
|
||||||
public static final Warps WARPS_INSTANCE;
|
public static final Warps WARPS_INSTANCE;
|
||||||
static{
|
static{
|
||||||
if(!BASE.toFile().exists()){
|
|
||||||
try {
|
|
||||||
Files.createDirectory(BASE);
|
|
||||||
} catch (IOException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
WARPS_INSTANCE = getOrCreate();
|
WARPS_INSTANCE = getOrCreate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,10 +23,10 @@ public class WarpsProvider extends EssentialsDatastore
|
||||||
private static Warps getOrCreate()
|
private static Warps getOrCreate()
|
||||||
{
|
{
|
||||||
Warps instance = null;
|
Warps instance = null;
|
||||||
if(WARPS_DATA.toFile().exists())
|
if(BASE.toFile().exists())
|
||||||
{
|
{
|
||||||
try{
|
try{
|
||||||
instance= Warps.deserialize(NbtIo.read(WARPS_DATA.toFile()));
|
instance= Warps.deserialize(NbtIo.read(BASE.toFile()));
|
||||||
|
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
instance=Warps.getNew();
|
instance=Warps.getNew();
|
||||||
|
@ -50,7 +41,7 @@ public class WarpsProvider extends EssentialsDatastore
|
||||||
public static void updateFile()
|
public static void updateFile()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
NbtIo.write(WARPS_INSTANCE.serialize(), WARPS_DATA.toFile());
|
NbtIo.write(WARPS_INSTANCE.serialize(), BASE.toFile());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ license="All rights reserved"
|
||||||
# A list of mods - how many allowed here is determined by the individual mod loader
|
# A list of mods - how many allowed here is determined by the individual mod loader
|
||||||
[[mods]] #mandatory
|
[[mods]] #mandatory
|
||||||
# The modid of the mod
|
# The modid of the mod
|
||||||
modId="essentials" #mandatory
|
modId="ariasessentials" #mandatory
|
||||||
# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it
|
# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it
|
||||||
# ${file.jarVersion} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata
|
# ${file.jarVersion} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata
|
||||||
# see the associated build.gradle script for how to populate this completely automatically during a build
|
# see the associated build.gradle script for how to populate this completely automatically during a build
|
||||||
|
@ -37,7 +37,7 @@ description='''
|
||||||
This mod provides homes, warps, and teleporting of all kinds
|
This mod provides homes, warps, and teleporting of all kinds
|
||||||
'''
|
'''
|
||||||
# A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional.
|
# A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional.
|
||||||
[[dependencies.essentials]] #optional
|
[[dependencies.ariasessentials]] #optional
|
||||||
# the modid of the dependency
|
# the modid of the dependency
|
||||||
modId="forge" #mandatory
|
modId="forge" #mandatory
|
||||||
# Does this dependency have to exist - if not, ordering below must be specified
|
# Does this dependency have to exist - if not, ordering below must be specified
|
||||||
|
@ -49,16 +49,16 @@ This mod provides homes, warps, and teleporting of all kinds
|
||||||
# Side this dependency is applied on - BOTH, CLIENT or SERVER
|
# Side this dependency is applied on - BOTH, CLIENT or SERVER
|
||||||
side="BOTH"
|
side="BOTH"
|
||||||
# Here's another dependency
|
# Here's another dependency
|
||||||
[[dependencies.essentials]]
|
[[dependencies.ariasessentials]]
|
||||||
modId="minecraft"
|
modId="minecraft"
|
||||||
mandatory=true
|
mandatory=true
|
||||||
# This version range declares a minimum of the current minecraft version up to but not including the next major version
|
# This version range declares a minimum of the current minecraft version up to but not including the next major version
|
||||||
versionRange="[1.18.2,1.19)"
|
versionRange="[1.18.2,1.19)"
|
||||||
ordering="NONE"
|
ordering="NONE"
|
||||||
side="BOTH"
|
side="BOTH"
|
||||||
[[dependencies.essentials]]
|
[[dependencies.ariasessentials]]
|
||||||
modId="libzontreck"
|
modId="libzontreck"
|
||||||
mandatory=true
|
mandatory=true
|
||||||
versionRange="[1,)"
|
versionRange="[1.0.5,1.0.6)"
|
||||||
ordering="NONE"
|
ordering="NONE"
|
||||||
side="BOTH"
|
side="BOTH"
|
Loading…
Add table
Add a link
Reference in a new issue