Finish fixing warps
This commit is contained in:
parent
9f79565d56
commit
516f067fb9
9 changed files with 103 additions and 35 deletions
|
@ -1,5 +1,8 @@
|
|||
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.Map;
|
||||
import java.util.UUID;
|
||||
|
@ -11,6 +14,7 @@ import com.mojang.logging.LogUtils;
|
|||
import dev.zontreck.essentials.commands.CommandRegister;
|
||||
import dev.zontreck.essentials.homes.Homes;
|
||||
import dev.zontreck.essentials.homes.HomesProvider;
|
||||
import dev.zontreck.essentials.util.EssentialsDatastore;
|
||||
import dev.zontreck.libzontreck.events.ProfileLoadedEvent;
|
||||
import dev.zontreck.libzontreck.events.ProfileUnloadedEvent;
|
||||
import dev.zontreck.libzontreck.profiles.Profile;
|
||||
|
@ -33,6 +37,7 @@ public class AriasEssentials {
|
|||
{
|
||||
IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
|
||||
EssentialsDatastore.initialize();
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
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.TPCancelCommand;
|
||||
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.eventbus.api.SubscribeEvent;
|
||||
|
||||
|
@ -28,5 +34,11 @@ public class CommandRegister {
|
|||
TPACommand.register(ev.getDispatcher());
|
||||
TPCancelCommand.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)
|
||||
{
|
||||
Path homesFile = EssentialsDatastore.of(player).resolve("homes.nbt");
|
||||
Path homesFile = EssentialsDatastore.of(player,true).resolve("homes.nbt");
|
||||
|
||||
Homes homes = new Homes(player);
|
||||
if(homesFile.toFile().exists())
|
||||
|
@ -37,7 +37,7 @@ public class HomesProvider {
|
|||
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 {
|
||||
NbtIo.write(playerHomes.serialize(), homesFile.toFile());
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package dev.zontreck.essentials.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import dev.zontreck.libzontreck.util.FileTreeDatastore;
|
||||
|
@ -7,12 +9,45 @@ import dev.zontreck.libzontreck.util.FileTreeDatastore;
|
|||
public class EssentialsDatastore extends FileTreeDatastore
|
||||
{
|
||||
public static final Path AEBASE;
|
||||
|
||||
static{
|
||||
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 static final Path BASE = of("warps");
|
||||
public static final Path WARPS_DATA = BASE.resolve("warps.nbt");
|
||||
public static final Path BASE = of("warps.nbt", false);
|
||||
|
||||
public static final Warps WARPS_INSTANCE;
|
||||
static{
|
||||
if(!BASE.toFile().exists()){
|
||||
try {
|
||||
Files.createDirectory(BASE);
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
WARPS_INSTANCE = getOrCreate();
|
||||
}
|
||||
|
||||
|
@ -32,10 +23,10 @@ public class WarpsProvider extends EssentialsDatastore
|
|||
private static Warps getOrCreate()
|
||||
{
|
||||
Warps instance = null;
|
||||
if(WARPS_DATA.toFile().exists())
|
||||
if(BASE.toFile().exists())
|
||||
{
|
||||
try{
|
||||
instance= Warps.deserialize(NbtIo.read(WARPS_DATA.toFile()));
|
||||
instance= Warps.deserialize(NbtIo.read(BASE.toFile()));
|
||||
|
||||
}catch(Exception e){
|
||||
instance=Warps.getNew();
|
||||
|
@ -50,7 +41,7 @@ public class WarpsProvider extends EssentialsDatastore
|
|||
public static void updateFile()
|
||||
{
|
||||
try {
|
||||
NbtIo.write(WARPS_INSTANCE.serialize(), WARPS_DATA.toFile());
|
||||
NbtIo.write(WARPS_INSTANCE.serialize(), BASE.toFile());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue