Fix bugs that were preventing the mod from loading due to datapack issues

Restructure the vault system
Remove JDBC Drivers as a runtime requirement
Restructure profiles
Restructure homes
Restructure warps
Switch to a FileTreeDatastore
This commit is contained in:
Aria 2023-02-24 01:27:35 -07:00
parent 553ff429f3
commit 5ee0aa47e9
62 changed files with 1385 additions and 705 deletions

View file

@ -3,7 +3,7 @@
org.gradle.jvmargs=-Xmx8G
org.gradle.daemon=false
my_version=1.3.7.4
my_version=1.3.7.0224230125
mc_version=1.18.2
forge_version=40.2.1

View file

@ -1,5 +1,5 @@
#Minecraft server properties
#Thu Feb 23 07:24:56 MST 2023
#Fri Feb 24 01:20:51 MST 2023
allow-flight=false
allow-nether=true
broadcast-console-to-ops=true

View file

@ -42,14 +42,12 @@ import dev.zontreck.otemod.chat.ChatServerOverride;
import dev.zontreck.otemod.commands.CommandRegistry;
import dev.zontreck.otemod.commands.teleport.TeleportContainer;
import dev.zontreck.otemod.configs.OTEServerConfig;
import dev.zontreck.otemod.configs.Profile;
import dev.zontreck.otemod.database.Database;
import dev.zontreck.otemod.database.Database.DatabaseConnectionException;
import dev.zontreck.otemod.enchantments.ModEnchantments;
import dev.zontreck.otemod.entities.ModEntityTypes;
import dev.zontreck.otemod.entities.monsters.client.PossumRenderer;
import dev.zontreck.otemod.events.LoreHandlers;
import dev.zontreck.otemod.implementation.inits.ModMenuTypes;
import dev.zontreck.otemod.implementation.profiles.Profile;
import dev.zontreck.otemod.implementation.scrubber.ItemScrubberScreen;
import dev.zontreck.otemod.implementation.scrubber.MagicalScrubberScreen;
import dev.zontreck.otemod.implementation.vault.VaultScreen;
@ -69,7 +67,6 @@ public class OTEMod
public static final String MOD_ID = "otemod";
public static final String MODIFY_BIOMES = "modify_biomes";
public static final ResourceLocation MODIFY_BIOMES_RL = new ResourceLocation(OTEMod.MOD_ID, MODIFY_BIOMES);
public static Database DB=null;
public static Map<String,Profile> PROFILES = new HashMap<String,Profile>();
public static List<TeleportContainer> TeleportRegistry = new ArrayList<>();
public static MinecraftServer THE_SERVER;
@ -82,6 +79,7 @@ public class OTEMod
public static String OTEPrefix = "";
public static String ONLY_PLAYER = "";
public static IEventBus bus;
public OTEMod()
{
@ -89,7 +87,7 @@ public class OTEMod
OTEMod.OTEPrefix = ChatColor.doColors("!dark_gray![!dark_green!!bold!OTEMod!reset!!dark_gray!]!reset!");
OTEMod.ONLY_PLAYER = ChatColor.doColors("!dark_red!Only a player can execute this command");
IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
bus = FMLJavaModLoadingContext.get().getModEventBus();
// Register the setup method for modloading
bus.addListener(this::setup);
@ -156,86 +154,42 @@ public class OTEMod
// Do something when the server starts
//LOGGER.info("HELLO from server starting");
try {
OTEMod.DB = new Database(this);
OTEMod.ALIVE=true;
//HealerQueue.Initialize(); // Set up the queue
OTEMod.ALIVE=true;
//HealerQueue.Initialize(); // Set up the queue
// Set up the repeating task to expire a TeleportContainer
OTEMod.THE_SERVER = event.getServer();
OTEMod.MasterThread = new Thread(new Runnable(){
public void run()
{
while(OTEMod.ALIVE){
// Check if the teleports have expired
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
//e.printStackTrace();
}
// Validate that the database has been established and that tables exist
Connection con = OTEMod.DB.getConnection();
con.setAutoCommit(true);
con.beginRequest();
Statement lookup = con.createStatement();
lookup.execute("CREATE TABLE IF NOT EXISTS `homes` (" +
" `number` int(11) NOT NULL," +
" `user` varchar(255) NOT NULL," +
" `home_name` varchar(255) NOT NULL," +
" `teleporter` text not null)"); // 10/04/2022 - fix dimension column size due to a bug where mods might have long names!
lookup.execute("CREATE TABLE IF NOT EXISTS `profiles` ("+
"`username` varchar (255) not null,"+
"`uuid` varchar (255) not null,"+
"`prefix` varchar (255) not null,"+
"`nickname` varchar (255) not null,"+
"`name_color` varchar (255) not null,"+
"`prefix_color` varchar(255) not null,"+
"`chat_color` varchar(255) not null)");
lookup.execute("CREATE TABLE IF NOT EXISTS `vaults` (" +
"`uuid` varchar (128) NOT NULL, " +
"`number` int (11) not null," +
"`data` text not null);");
lookup.execute("CREATE TABLE IF NOT EXISTS `warps` (" +
"`warpname` varchar (128) not null, " +
"`owner` varchar(128) not null, " +
"`warptype` int (2) not null, "+
"`teleporter` text not null)");
con.endRequest();
// Set up the repeating task to expire a TeleportContainer
OTEMod.THE_SERVER = event.getServer();
OTEMod.MasterThread = new Thread(new Runnable(){
public void run()
{
while(OTEMod.ALIVE){
// Check if the teleports have expired
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
//e.printStackTrace();
}
for(TeleportContainer cont : OTEMod.TeleportRegistry){
if(cont.has_expired())
{
try{
Component expire = new TextComponent(OTEMod.OTEPrefix + ChatColor.DARK_PURPLE+" Teleport request has expired");
ChatServerOverride.broadcastTo(cont.FromPlayer, expire, OTEMod.THE_SERVER);
ChatServerOverride.broadcastTo(cont.ToPlayer, expire, OTEMod.THE_SERVER);
OTEMod.TeleportRegistry.remove(cont);
}catch(Exception e){
break;
}
for(TeleportContainer cont : OTEMod.TeleportRegistry){
if(cont.has_expired())
{
try{
Component expire = new TextComponent(OTEMod.OTEPrefix + ChatColor.DARK_PURPLE+" Teleport request has expired");
ChatServerOverride.broadcastTo(cont.FromPlayer, expire, OTEMod.THE_SERVER);
ChatServerOverride.broadcastTo(cont.ToPlayer, expire, OTEMod.THE_SERVER);
OTEMod.TeleportRegistry.remove(cont);
}catch(Exception e){
break;
}
}
}
OTEMod.LOGGER.info("Tearing down OTEMod teleport queue - The server is going down");
}
});
OTEMod.MasterThread.start();
} catch (DatabaseConnectionException | SQLException e) {
e.printStackTrace();
LOGGER.error("FATAL ERROR\n \n* DATABASE COULD NOT CONNECT *\n* SEE ABOVE STACK TRACE *");
}
OTEMod.LOGGER.info("Tearing down OTEMod teleport queue - The server is going down");
}
});
OTEMod.MasterThread.start();
}

View file

@ -40,6 +40,11 @@ public class ModBlocks {
public static final RegistryObject<Item> VAULT_STEEL_ORE_BLOCK_I = ITEMS.register("vault_steel_ore_block", ()->new BlockItem(VAULT_STEEL_ORE_BLOCK.get(), new Item.Properties().tab(CreativeModeTab.TAB_MATERIALS)));
public static final RegistryObject<Block> NETHER_VAULT_STEEL_ORE_BLOCK = BLOCKS.register("nether_vault_steel_ore_block", ()->new Block(BlockBehaviour.Properties.of(Material.METAL).requiresCorrectToolForDrops().strength(8F).explosionResistance(1200).destroyTime(100)));
public static final RegistryObject<Item> NETHER_VAULT_STEEL_ORE_BLOCK_I = ITEMS.register("nether_vault_steel_ore_block", ()->new BlockItem(NETHER_VAULT_STEEL_ORE_BLOCK.get(), new Item.Properties().tab(CreativeModeTab.TAB_MATERIALS)));
//#region TINKERS BLOCKS
public static final RegistryObject<Block> COBALT_ORE_BLOCK = BLOCKS.register("cobalt_ore", () -> new Block(BlockBehaviour.Properties.of(Material.STONE, MaterialColor.NETHER).sound(SoundType.NETHER_ORE).requiresCorrectToolForDrops().strength(10.0F)));

View file

@ -12,8 +12,9 @@ import dev.zontreck.libzontreck.util.ItemUtils;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.configs.OTEServerConfig;
import dev.zontreck.otemod.configs.PlayerFlyCache;
import dev.zontreck.otemod.configs.Profile;
import dev.zontreck.otemod.enchantments.ModEnchantments;
import dev.zontreck.otemod.implementation.profiles.Profile;
import dev.zontreck.otemod.implementation.profiles.UserProfileNotYetExistsException;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.Style;
import net.minecraft.network.chat.TextComponent;
@ -38,42 +39,8 @@ public class ChatServerOverride {
//Player joined, send custom alert
if(ev.getEntity().level.isClientSide)return;
ServerPlayer play = (ServerPlayer)ev.getEntity();
Profile prof = Profile.factory(play);
// Download user data from database
try{
Connection c = OTEMod.DB.getConnection();
String SQL = "SELECT * FROM `profiles` WHERE `uuid`=?;";
PreparedStatement pst = c.prepareStatement(SQL);
pst.setString(1,ev.getEntity().getStringUUID());
ResultSet rs = pst.executeQuery();
boolean has_profile=false;
while(rs.next())
{
has_profile=true;
OTEMod.PROFILES.put(ev.getEntity().getStringUUID(), new Profile(rs.getString("username"), rs.getString("prefix"), rs.getString("nickname"), rs.getString("name_color"), ev.getEntity().getStringUUID(), rs.getString("prefix_color"), rs.getString("chat_color"), rs.getBoolean("flying"), rs.getInt("vaults")));
}
if(!has_profile)
{
// Create profile!
Profile p = Profile.factory(play);
OTEMod.PROFILES.put(play.getStringUUID(), p);
p.commit(); // Commits the profile to the server
play.displayClientMessage(new TextComponent(ChatColor.doColors( OTEMod.OTEPrefix +" !Dark_Green!First join! Your server profile has been created")), false);
}
}catch (SQLException e){
e.printStackTrace();
}
Profile prof = Profile.get_profile_of(ev.getEntity().getStringUUID());
if(prof == null){
OTEMod.LOGGER.error("FATAL: Profile was null for "+ev.getEntity().getName().getString());
return;
}
if(prof.flying)
{
@ -84,11 +51,13 @@ public class ChatServerOverride {
Abilities playerAbilities = play.getAbilities();
boolean mayFly = false;
ItemStack feet = play.getItemBySlot(EquipmentSlot.FEET);
ItemStack legs = play.getItemBySlot(EquipmentSlot.LEGS);
if(ItemUtils.getEnchantmentLevel(ModEnchantments.FLIGHT_ENCHANTMENT.get(), feet)>0)mayFly = true;
playerAbilities.mayfly=mayFly;
play.onUpdateAbilities();
PlayerFlyCache c = PlayerFlyCache.cachePlayer(play);
c.Flying=prof.flying;
c.FlyEnabled = mayFly;
c.Assert(play);
if(!OTEServerConfig.USE_CUSTOM_JOINLEAVE.get()) return;
@ -101,7 +70,13 @@ public class ChatServerOverride {
{
if(ev.getEntity().level.isClientSide)return;
// Get player profile, send disconnect alert, then commit profile and remove it from memory
Profile px = Profile.get_profile_of(ev.getEntity().getStringUUID());
Profile px=null;
try {
px = Profile.get_profile_of(ev.getEntity().getStringUUID());
} catch (UserProfileNotYetExistsException e) {
e.printStackTrace();
}
Profile.unload(px);
ServerPlayer sp = (ServerPlayer)ev.getEntity();
@ -114,7 +89,6 @@ public class ChatServerOverride {
px.flying=sp.getAbilities().flying;
px.commit();
OTEMod.PROFILES.remove(ev.getEntity().getStringUUID());
}
@SubscribeEvent
@ -138,7 +112,13 @@ public class ChatServerOverride {
ServerPlayer sp = ev.getPlayer();
// Get profile
Profile XD = Profile.get_profile_of(sp.getStringUUID());
Profile XD=null;
try {
XD = Profile.get_profile_of(sp.getStringUUID());
} catch (UserProfileNotYetExistsException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Override the chat!
String prefixStr = "";

View file

@ -1,19 +1,15 @@
package dev.zontreck.otemod.commands.homes;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
import dev.zontreck.otemod.implementation.profiles.Profile;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;
import net.minecraft.network.chat.TextComponent;
public class DelHomeCommand {
@ -34,37 +30,18 @@ public class DelHomeCommand {
// CommandSourceStack ctx = ctx2.getSource();
// homeName = StringArgumentType.getString(ctx2, "nickname");
// if(homeName==null)return 0;
if(!(ctx.getEntity() instanceof Player))
{
return 1;
}
ServerPlayer p = (ServerPlayer) ctx.getEntity();
Connection con = OTEMod.DB.getConnection();
try {
con.beginRequest();
//Statement stat = con.createStatement();
String SQL = "DELETE FROM `homes` WHERE `user`=? AND `home_name`=?;";
PreparedStatement pstat = con.prepareStatement(SQL);
pstat.setString(1, p.getStringUUID());
pstat.setString(2, homeName);
pstat.execute();
try{
ServerPlayer p = ctx.getPlayerOrException();
Profile prof = Profile.get_profile_of(p.getStringUUID());
prof.player_homes.delete(homeName);
ChatServerOverride.broadcastTo(p.getUUID(), new TextComponent(OTEMod.OTEPrefix + ChatColor.doColors("!dark_green! Home was deleted successfully")), ctx.getServer());
con.endRequest();
} catch (SQLException e) {
// TODO Auto-generated catch block
}catch(Exception e)
{
e.printStackTrace();
ChatServerOverride.broadcastTo(p.getUUID(), new TextComponent(OTEMod.OTEPrefix + ChatColor.doColors("!dark_red! Home was unable to be deleted")), ctx.getServer());
return 1;
}
ChatServerOverride.broadcastTo(ctx.getEntity().getUUID(), new TextComponent(OTEMod.OTEPrefix + ChatColor.doColors("!dark_red! Home could not be deleted due to an unknown error")), ctx.getServer());
}
return 0;
}

View file

@ -1,33 +1,22 @@
package dev.zontreck.otemod.commands.homes;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.exceptions.InvalidDeserialization;
import dev.zontreck.libzontreck.exceptions.InvalidSideException;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
import dev.zontreck.otemod.commands.teleport.TeleportActioner;
import dev.zontreck.otemod.commands.teleport.TeleportContainer;
import dev.zontreck.otemod.database.TeleportDestination;
import dev.zontreck.otemod.implementation.homes.Home;
import dev.zontreck.otemod.implementation.homes.NoSuchHomeException;
import dev.zontreck.otemod.implementation.profiles.Profile;
import dev.zontreck.otemod.implementation.profiles.UserProfileNotYetExistsException;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.phys.Vec2;
import net.minecraft.world.phys.Vec3;
import net.minecraft.network.chat.Style;
import net.minecraft.network.chat.TextColor;
import net.minecraft.network.chat.TextComponent;
public class HomeCommand {
@ -48,77 +37,31 @@ public class HomeCommand {
// CommandSourceStack ctx = ctx2.getSource();
// homeName = StringArgumentType.getString(ctx2, "nickname");
// if(homeName==null)return 0;
if(!(ctx.getEntity() instanceof Player))
{
return 1;
}
ServerPlayer p = (ServerPlayer)ctx.getEntity();
Connection con = OTEMod.DB.getConnection();
String SQL="";
try {
con.beginRequest();
Statement stat = con.createStatement();
Vec3 position = p.position();
Vec2 rot = p.getRotationVector();
//stat.execute("REPLACE INTO `homes` (user, home_name, x, y, z, rot_x, rot_y, dimension) values (\"" + p.getStringUUID() + "\", \""+ homeName + "\", "+String.valueOf(position.x)+", "+String.valueOf(position.y)+", "+String.valueOf(position.z)+", "+String.valueOf(rot.x)+", "+String.valueOf(rot.y)+", \"" + p.getLevel().dimension().location().getNamespace() + ":" + p.getLevel().dimension().location().getPath() + "\");");
// Query database now
SQL = "SELECT * FROM `homes` WHERE `user`=? AND `home_name`=?;";
//ResultSet rs = stat.executeQuery(SQL);
PreparedStatement pstat = con.prepareStatement(SQL);
pstat.setString(1, p.getStringUUID());
pstat.setString(2, homeName);
try{
ServerPlayer p = ctx.getPlayerOrException();
Profile prof = Profile.get_profile_of(p.getStringUUID());
Home home = prof.player_homes.get(homeName);
ResultSet rs = pstat.executeQuery();
boolean has_home = false;
while(rs.next()){
has_home=true;
// Now, begin to extract the home data
TeleportDestination dest = new TeleportDestination(NbtUtils.snbtToStructure(rs.getString("teleporter")));
position = dest.Position.asMinecraftVector();
rot = dest.Rotation.asMinecraftVector();
ServerLevel dimL = (ServerLevel)dest.getActualDimension();
TeleportActioner.ApplyTeleportEffect(p);
// Instantiate a Teleport Runner
final ServerPlayer f_p = p;
final Vec3 f_pos = position;
final Vec2 f_rot = rot;
final ServerLevel f_dim = dimL;
TeleportContainer cont = new TeleportContainer(f_p, f_pos, f_rot, f_dim);
TeleportActioner.PerformTeleport(cont);
}
if(!has_home)throw new SQLException("NO HOME");
Style sxx = Style.EMPTY.withColor(TextColor.parseColor(ChatColor.DARK_GREEN)).withFont(Style.DEFAULT_FONT);
TeleportDestination dest = home.destination;
TeleportActioner.ApplyTeleportEffect(p);
TeleportContainer cont = new TeleportContainer(p, dest.Position.asMinecraftVector(), dest.Rotation.asMinecraftVector(), dest.getActualDimension());
TeleportActioner.PerformTeleport(cont);
ChatServerOverride.broadcastTo(p.getUUID(), new TextComponent(OTEMod.OTEPrefix + ChatColor.doColors(" !dark_green!Home found! Wormhole opening now...")), ctx.getServer());
con.endRequest();
} catch (SQLException e) {
// TODO Auto-generated catch block
}catch(CommandSyntaxException e)
{
e.printStackTrace();
if(!e.getMessage().equals("%%"))
ChatServerOverride.broadcastTo(p.getUUID(), new TextComponent(OTEMod.OTEPrefix + ChatColor.doColors(" !Dark_Red! Could not go to the home")), ctx.getServer());
else
ctx.sendFailure(new TextComponent("FAILED SQL: "+ ChatColor.GOLD+ SQL));
} catch (InvalidDeserialization e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (CommandSyntaxException e) {
return 1;
}catch(NoSuchHomeException e)
{
ChatServerOverride.broadcastTo(ctx.getEntity().getUUID(), new TextComponent(OTEMod.OTEPrefix + ChatColor.doColors(" !dark_red!Home not found. Maybe it does not exist?")), ctx.getServer());
return 0;
} catch (UserProfileNotYetExistsException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return 0;
}

View file

@ -9,12 +9,17 @@ import java.util.List;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.chat.Clickable;
import dev.zontreck.libzontreck.chat.HoverTip;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
import dev.zontreck.otemod.implementation.homes.Home;
import dev.zontreck.otemod.implementation.homes.Homes;
import dev.zontreck.otemod.implementation.profiles.Profile;
import dev.zontreck.otemod.implementation.profiles.UserProfileNotYetExistsException;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.server.level.ServerPlayer;
@ -31,33 +36,26 @@ public class HomesCommand {
private static int getHomes(CommandContext<CommandSourceStack> ctx)
{
// Request homes
if(!(ctx.getSource().getEntity() instanceof Player))
{
return 1;
}
ServerPlayer p = (ServerPlayer)ctx.getSource().getEntity();
Connection con = OTEMod.DB.getConnection();
try {
con.beginRequest();
Statement stat = con.createStatement();
ResultSet rs = stat.executeQuery("SELECT `home_name` FROM `homes` WHERE `user`=\"" + p.getStringUUID()+"\"");
List<String> homes = new ArrayList<String>();
while(rs.next()){
homes.add(rs.getString("home_name"));
}
ChatServerOverride.broadcastTo(p.getUUID(), new TextComponent(OTEMod.OTEPrefix + ChatColor.doColors(" !Dark_Purple!There are !gold!"+String.valueOf(homes.size())+" !dark_purple!total homes.")), p.server);
con.endRequest();
try{
ServerPlayer player = ctx.getSource().getPlayerOrException();
for (String string : homes) {
Style st = Style.EMPTY.withFont(Style.DEFAULT_FONT).withHoverEvent(HoverTip.get(ChatColor.BOLD+ChatColor.DARK_GREEN+"Click here to go to this home")).withClickEvent(Clickable.command("/home "+string));
Profile p = Profile.get_profile_of(player.getStringUUID());
Homes homes = p.player_homes;
ChatServerOverride.broadcastTo(p.getUUID(), new TextComponent(ChatColor.BOLD + ChatColor.MINECOIN_GOLD+"["+ChatColor.resetChat()+ChatColor.UNDERLINE+ChatColor.BOLD+ChatColor.DARK_GREEN+"HOME"+ChatColor.resetChat()+ChatColor.BOLD+ChatColor.MINECOIN_GOLD+"] "+ChatColor.resetChat()+ChatColor.YELLOW+string).setStyle(st), ctx.getSource().getServer());
ChatServerOverride.broadcastTo(player.getUUID(), new TextComponent(OTEMod.OTEPrefix + ChatColor.doColors(" !Dark_Purple!There are !gold!"+String.valueOf(homes.count())+" !dark_purple!total homes.")), player.server);
for (Home string : homes.getList()) {
Style st = Style.EMPTY.withFont(Style.DEFAULT_FONT).withHoverEvent(HoverTip.get(ChatColor.BOLD+ChatColor.DARK_GREEN+"Click here to go to this home")).withClickEvent(Clickable.command("/home "+string.homeName));
ChatServerOverride.broadcastTo(player.getUUID(), new TextComponent(ChatColor.BOLD + ChatColor.MINECOIN_GOLD+"["+ChatColor.resetChat()+ChatColor.UNDERLINE+ChatColor.BOLD+ChatColor.DARK_GREEN+"HOME"+ChatColor.resetChat()+ChatColor.BOLD+ChatColor.MINECOIN_GOLD+"] "+ChatColor.resetChat()+ChatColor.YELLOW+string).setStyle(st), ctx.getSource().getServer());
}
} catch (SQLException e) {
// TODO Auto-generated catch block
}catch(CommandSyntaxException ex)
{
ex.printStackTrace();
} catch (UserProfileNotYetExistsException e) {
e.printStackTrace();
}

View file

@ -6,6 +6,7 @@ import java.sql.SQLException;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.vectors.Vector2;
@ -13,6 +14,11 @@ import dev.zontreck.libzontreck.vectors.Vector3;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
import dev.zontreck.otemod.database.TeleportDestination;
import dev.zontreck.otemod.implementation.homes.Home;
import dev.zontreck.otemod.implementation.homes.Homes;
import dev.zontreck.otemod.implementation.homes.HomesProvider;
import dev.zontreck.otemod.implementation.profiles.Profile;
import dev.zontreck.otemod.implementation.profiles.UserProfileNotYetExistsException;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.server.level.ServerPlayer;
@ -40,39 +46,30 @@ public class SetHomeCommand {
// homeName = StringArgumentType.getString(ctx2, "nickname");
// if(homeName==null)return 0;
if(!(ctx.getEntity() instanceof Player))
{
return 1;
}
ServerPlayer p = (ServerPlayer)ctx.getEntity();
Connection con = OTEMod.DB.getConnection();
ServerPlayer p;
try {
con.beginRequest();
//Statement stat = con.createStatement();
p = ctx.getPlayerOrException();
Vec3 position = p.position();
Vec2 rot = p.getRotationVector();
TeleportDestination dest = new TeleportDestination(new Vector3(position), new Vector2(rot), p.getLevel());
String SQL = "REPLACE INTO `homes` (user, home_name, teleporter) VALUES (?, ?, ?);";
PreparedStatement pstat = con.prepareStatement(SQL);
pstat.setString(1, p.getStringUUID());
pstat.setString(2, homeName);
pstat.setString(3, dest.toString());
pstat.execute();
Home newhome = new Home(p, homeName, dest);
Profile profile = Profile.get_profile_of(p.getStringUUID());
Homes homes = profile.player_homes;
homes.add(newhome);
ChatServerOverride.broadcastTo(p.getUUID(), new TextComponent(OTEMod.OTEPrefix + ChatColor.doColors(" !dark_green!Home was created or updated successfully!")), ctx.getServer());
} catch (CommandSyntaxException e) {
con.endRequest();
} catch (SQLException e) {
// TODO Auto-generated catch block
ChatServerOverride.broadcastTo(ctx.getEntity().getUUID(), new TextComponent(OTEMod.OTEPrefix + ChatColor.doColors(" !dark_red!Home could not be created or updated!")), ctx.getServer());
e.printStackTrace();
} catch (UserProfileNotYetExistsException e) {
ChatServerOverride.broadcastTo(ctx.getEntity().getUUID(), new TextComponent(OTEMod.OTEPrefix + ChatColor.doColors(" !dark_red!Home could not be created or updated!")), ctx.getServer());
e.printStackTrace();
ChatServerOverride.broadcastTo(p.getUUID(), new TextComponent(OTEMod.OTEPrefix + ChatColor.doColors(" !dark_red!Home could not be updated or created for a unknown reason!")), ctx.getServer());
return 1;
}
return 0;
}

View file

@ -6,7 +6,8 @@ import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.chat.HoverTip;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
import dev.zontreck.otemod.configs.Profile;
import dev.zontreck.otemod.implementation.profiles.Profile;
import dev.zontreck.otemod.implementation.profiles.UserProfileNotYetExistsException;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.MutableComponent;
@ -42,7 +43,12 @@ public class ShareItemInChatCommand {
return 0;
}
Profile prof = Profile.get_profile_of(play.getUUID().toString());
Profile prof;
try {
prof = Profile.get_profile_of(play.getUUID().toString());
} catch (UserProfileNotYetExistsException e) {
return 1;
}
MutableComponent component = new TextComponent(OTEMod.OTEPrefix).append(is.getDisplayName()).append(new TextComponent(ChatColor.doColors(" !White!-!Dark_Purple! Hover here to see the item that "+prof.name_color+prof.nickname+"!Dark_Purple! shared")));
Style style = Style.EMPTY.withFont(Style.DEFAULT_FONT);

View file

@ -5,7 +5,8 @@ import com.mojang.brigadier.CommandDispatcher;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.chat.ChatColor.ColorOptions;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.configs.Profile;
import dev.zontreck.otemod.implementation.profiles.Profile;
import dev.zontreck.otemod.implementation.profiles.UserProfileNotYetExistsException;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
@ -42,7 +43,12 @@ public class ChatColorCommand {
return 1;
}
ServerPlayer play = (ServerPlayer)source.getEntity();
Profile p = Profile.get_profile_of(play.getStringUUID());
Profile p;
try {
p = Profile.get_profile_of(play.getStringUUID());
} catch (UserProfileNotYetExistsException e) {
return 1;
}
p.chat_color = colorcoded;
p.commit();
OTEMod.PROFILES.put(play.getStringUUID(), p);

View file

@ -5,7 +5,8 @@ import com.mojang.brigadier.CommandDispatcher;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.chat.ChatColor.ColorOptions;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.configs.Profile;
import dev.zontreck.otemod.implementation.profiles.Profile;
import dev.zontreck.otemod.implementation.profiles.UserProfileNotYetExistsException;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
@ -42,7 +43,12 @@ public class NameColorCommand {
return 1;
}
ServerPlayer play = (ServerPlayer)source.getEntity();
Profile p = Profile.get_profile_of(play.getStringUUID());
Profile p;
try {
p = Profile.get_profile_of(play.getStringUUID());
} catch (UserProfileNotYetExistsException e) {
return 1;
}
p.name_color = colorcoded;
p.commit();
OTEMod.PROFILES.put(play.getStringUUID(), p);

View file

@ -5,7 +5,8 @@ import com.mojang.brigadier.arguments.StringArgumentType;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.configs.Profile;
import dev.zontreck.otemod.implementation.profiles.Profile;
import dev.zontreck.otemod.implementation.profiles.UserProfileNotYetExistsException;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
@ -38,7 +39,12 @@ public class NickCommand {
}
ServerPlayer play = (ServerPlayer)source.getEntity();
Profile p = Profile.get_profile_of(play.getStringUUID());
Profile p;
try {
p = Profile.get_profile_of(play.getStringUUID());
} catch (UserProfileNotYetExistsException e) {
return 1;
}
p.nickname = string;
p.commit();
OTEMod.PROFILES.put(play.getStringUUID(), p);

View file

@ -5,7 +5,8 @@ import com.mojang.brigadier.CommandDispatcher;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.chat.ChatColor.ColorOptions;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.configs.Profile;
import dev.zontreck.otemod.implementation.profiles.Profile;
import dev.zontreck.otemod.implementation.profiles.UserProfileNotYetExistsException;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
@ -43,7 +44,12 @@ public class PrefixColorCommand {
}
ServerPlayer play = (ServerPlayer)source.getEntity();
Profile p = Profile.get_profile_of(play.getStringUUID());
Profile p;
try {
p = Profile.get_profile_of(play.getStringUUID());
} catch (UserProfileNotYetExistsException e) {
return 1;
}
p.prefix_color = colorcoded;
p.commit();
OTEMod.PROFILES.put(play.getStringUUID(), p);

View file

@ -5,7 +5,8 @@ import com.mojang.brigadier.arguments.StringArgumentType;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.configs.Profile;
import dev.zontreck.otemod.implementation.profiles.Profile;
import dev.zontreck.otemod.implementation.profiles.UserProfileNotYetExistsException;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
@ -38,7 +39,12 @@ public class PrefixCommand {
}
ServerPlayer play = (ServerPlayer)source.getEntity();
Profile p = Profile.get_profile_of(play.getStringUUID());
Profile p;
try {
p = Profile.get_profile_of(play.getStringUUID());
} catch (UserProfileNotYetExistsException e) {
return 1;
}
p.prefix = string;
p.commit();
OTEMod.PROFILES.put(play.getStringUUID(), p);

View file

@ -7,7 +7,8 @@ import dev.zontreck.libzontreck.chat.Clickable;
import dev.zontreck.libzontreck.chat.HoverTip;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
import dev.zontreck.otemod.configs.Profile;
import dev.zontreck.otemod.implementation.profiles.Profile;
import dev.zontreck.otemod.implementation.profiles.UserProfileNotYetExistsException;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.commands.arguments.EntityArgument;
@ -76,7 +77,12 @@ public class TPACommand {
Style s2 = Style.EMPTY.withFont(Style.DEFAULT_FONT).withClickEvent(ce2).withHoverEvent(he2);
Profile p = Profile.get_profile_of(cont.FromPlayer.toString());
Profile p;
try {
p = Profile.get_profile_of(cont.FromPlayer.toString());
} catch (UserProfileNotYetExistsException e) {
return 1;
}
ChatServerOverride.broadcastTo(cont.ToPlayer, new TextComponent(p.name_color+p.nickname + ChatColor.BOLD + ChatColor.DARK_PURPLE+" is requesting to teleport to you\n \n").
append(new TextComponent(ChatColor.DARK_GRAY+"["+ChatColor.DARK_GREEN+"ACCEPT" + ChatColor.DARK_GRAY+"] ").setStyle(s)).
append(new TextComponent(ChatColor.DARK_GRAY + "["+ChatColor.DARK_RED+"DENY"+ChatColor.DARK_GRAY+"]").setStyle(s2)), serverPlayer.server);

View file

@ -7,7 +7,8 @@ import dev.zontreck.libzontreck.chat.Clickable;
import dev.zontreck.libzontreck.chat.HoverTip;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
import dev.zontreck.otemod.configs.Profile;
import dev.zontreck.otemod.implementation.profiles.Profile;
import dev.zontreck.otemod.implementation.profiles.UserProfileNotYetExistsException;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.commands.arguments.EntityArgument;
@ -76,7 +77,12 @@ public class TPAHereCommand {
Style s2 = Style.EMPTY.withFont(Style.DEFAULT_FONT).withClickEvent(ce2).withHoverEvent(he2);
Profile p = Profile.get_profile_of(cont.ToPlayer.toString());
Profile p;
try {
p = Profile.get_profile_of(cont.ToPlayer.toString());
} catch (UserProfileNotYetExistsException e) {
return 1;
}
ChatServerOverride.broadcastTo(cont.FromPlayer, new TextComponent(p.name_color+p.nickname + ChatColor.BOLD + ChatColor.DARK_PURPLE+" is requesting you to teleport to them\n \n").
append(new TextComponent(ChatColor.DARK_GRAY+"["+ChatColor.DARK_GREEN+"ACCEPT" + ChatColor.DARK_GRAY+"] ").setStyle(s)).
append(new TextComponent(ChatColor.DARK_GRAY + "["+ChatColor.DARK_RED+"DENY"+ChatColor.DARK_GRAY+"]").setStyle(s2)), serverPlayer.server);

View file

@ -2,6 +2,10 @@ package dev.zontreck.otemod.commands.vaults;
import com.mojang.brigadier.CommandDispatcher;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
import dev.zontreck.otemod.implementation.vault.NoMoreVaultException;
import dev.zontreck.otemod.implementation.vault.VaultContainer;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
@ -28,7 +32,13 @@ public class TrashCommand {
//cont.startOpen(source.getPlayer());
ServerPlayer play = (ServerPlayer)source.getEntity();
VaultContainer container = new VaultContainer(play, -1);
VaultContainer container;
try {
container = new VaultContainer(play, -1);
} catch (NoMoreVaultException e) {
ChatServerOverride.broadcastTo(play.getUUID(), new TextComponent(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Red!You cannot open anymore vaults. Craft a new vault!")), play.server);
return 0;
}
NetworkHooks.openGui(play, new SimpleMenuProvider(container.serverMenu, new TextComponent("Trash")));

View file

@ -6,7 +6,11 @@ import com.mojang.brigadier.arguments.IntegerArgumentType;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
import dev.zontreck.otemod.implementation.profiles.Profile;
import dev.zontreck.otemod.implementation.vault.NoMoreVaultException;
import dev.zontreck.otemod.implementation.vault.Vault;
import dev.zontreck.otemod.implementation.vault.VaultContainer;
import dev.zontreck.otemod.implementation.vault.VaultProvider;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
@ -46,7 +50,13 @@ public class VaultCommand {
public static void doOpen(ServerPlayer p, int i){
VaultContainer container = new VaultContainer(p, i);
VaultContainer container;
try {
container = new VaultContainer(p, i);
} catch (NoMoreVaultException e) {
ChatServerOverride.broadcastTo(p.getUUID(), new TextComponent(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Red!You cannot open anymore vaults. Craft a new vault!")), p.server);
return;
}
NetworkHooks.openGui(p, new SimpleMenuProvider(container.serverMenu, new TextComponent("Vault "+i)));

View file

@ -13,6 +13,9 @@ import dev.zontreck.libzontreck.vectors.Vector3;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
import dev.zontreck.otemod.database.TeleportDestination;
import dev.zontreck.otemod.implementation.warps.NoSuchWarpException;
import dev.zontreck.otemod.implementation.warps.Warp;
import dev.zontreck.otemod.implementation.warps.WarpsProvider;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
@ -37,31 +40,30 @@ public class DelWarpCommand {
private static int setWarp(CommandSourceStack source, String string) {
ServerPlayer p = (ServerPlayer)source.getEntity();
Connection con = OTEMod.DB.getConnection();
Warp warp;
try {
con.beginRequest();
PreparedStatement pstat;
Vec3 position = p.position();
Vec2 rot = p.getRotationVector();
TeleportDestination dest = new TeleportDestination(new Vector3(position), new Vector2(rot), p.getLevel().dimension().location().getNamespace() + ":" + p.getLevel().dimension().location().getPath());
String SQL = "DELETE FROM `warps` WHERE `warpname`=? AND `owner`=?;";
pstat = con.prepareStatement(SQL);
pstat.setString(1, string);
pstat.setString(2, p.getStringUUID());
pstat.execute();
ChatServerOverride.broadcastTo(p.getUUID(), new TextComponent(ChatColor.GREEN).append(new TranslatableComponent("dev.zontreck.otemod.msgs.warps.del.success")), source.getServer());
con.endRequest();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
ChatServerOverride.broadcastTo(p.getUUID(), new TextComponent(ChatColor.DARK_RED).append(new TranslatableComponent("dev.zontreck.otemod.msgs.warps.del.fail")), source.getServer());
warp = WarpsProvider.WARPS_INSTANCE.getNamedWarp(string);
} catch (NoSuchWarpException e) {
ChatServerOverride.broadcastTo(p.getUUID(), new TextComponent(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Red!That warp does not exist")), p.server);
return 0;
}
if(p.getUUID().equals(warp.owner) || p.hasPermissions(5))
{
try {
WarpsProvider.WARPS_INSTANCE.delete(WarpsProvider.WARPS_INSTANCE.getNamedWarp(string));
} catch (NoSuchWarpException e) {
ChatServerOverride.broadcastTo(p.getUUID(), new TextComponent(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Red!That warp does not exist")), p.server);
return 0;
}
ChatServerOverride.broadcastTo(p.getUUID(), new TextComponent(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Green!Warp deleted successfully")), p.server);
}else {
ChatServerOverride.broadcastTo(p.getUUID(), new TextComponent(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Red!Warp could not be deleted, because you do not own the warp.")), p.server);
}
return 0;
}
}

View file

@ -13,6 +13,8 @@ import dev.zontreck.libzontreck.vectors.Vector3;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
import dev.zontreck.otemod.database.TeleportDestination;
import dev.zontreck.otemod.implementation.warps.Warp;
import dev.zontreck.otemod.implementation.warps.WarpsProvider;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
@ -37,32 +39,16 @@ public class RTPWarpCommand {
private static int setWarp(CommandSourceStack source, String string) {
ServerPlayer p = (ServerPlayer)source.getEntity();
Connection con = OTEMod.DB.getConnection();
try {
con.beginRequest();
PreparedStatement pstat;
Vec3 position = p.position();
Vec2 rot = p.getRotationVector();
TeleportDestination dest = new TeleportDestination(new Vector3(position), new Vector2(rot), p.getLevel());
Vec3 position = p.position();
Vec2 rot = p.getRotationVector();
String SQL = "REPLACE INTO `warps` (warpname, owner, warptype, teleporter) values (?, ?, ?, ?);";
pstat = con.prepareStatement(SQL);
pstat.setString(1, string);
pstat.setString(2, p.getStringUUID());
pstat.setInt(3, 1);
pstat.setString(4, dest.toString());
pstat.execute();
TeleportDestination dest = new TeleportDestination(new Vector3(position), new Vector2(rot), p.getLevel());
Warp warp = new Warp(p.getUUID(), string, true, true, dest);
WarpsProvider.WARPS_INSTANCE.add(warp);
ChatServerOverride.broadcastTo(p.getUUID(), new TextComponent(ChatColor.GREEN).append(new TranslatableComponent("dev.zontreck.otemod.msgs.warps.set.success")), source.getServer());
con.endRequest();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
ChatServerOverride.broadcastTo(p.getUUID(), new TextComponent(ChatColor.DARK_RED).append(new TranslatableComponent("dev.zontreck.otemod.msgs.warps.set.fail")), source.getServer());
}
ChatServerOverride.broadcastTo(p.getUUID(), new TextComponent(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Green!Random Position Teleport (RTP) Warp created successfully")), p.server);
return 0;
}

View file

@ -13,6 +13,8 @@ import dev.zontreck.libzontreck.vectors.Vector3;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
import dev.zontreck.otemod.database.TeleportDestination;
import dev.zontreck.otemod.implementation.warps.Warp;
import dev.zontreck.otemod.implementation.warps.WarpsProvider;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
@ -37,32 +39,16 @@ public class SetWarpCommand {
private static int setWarp(CommandSourceStack source, String string) {
ServerPlayer p = (ServerPlayer)source.getEntity();
Connection con = OTEMod.DB.getConnection();
try {
con.beginRequest();
PreparedStatement pstat;
Vec3 position = p.position();
Vec2 rot = p.getRotationVector();
TeleportDestination dest = new TeleportDestination(new Vector3(position), new Vector2(rot), p.getLevel());
Vec3 position = p.position();
Vec2 rot = p.getRotationVector();
String SQL = "REPLACE INTO `warps` (warpname, owner, warptype, teleporter) values (?, ?, ?, ?);";
pstat = con.prepareStatement(SQL);
pstat.setString(1, string);
pstat.setString(2, p.getStringUUID());
pstat.setInt(3, 0);
pstat.setString(4, dest.toString());
pstat.execute();
TeleportDestination dest = new TeleportDestination(new Vector3(position), new Vector2(rot), p.getLevel());
Warp w = new Warp(p.getUUID(), string, false, true, dest);
WarpsProvider.WARPS_INSTANCE.add(w);
ChatServerOverride.broadcastTo(p.getUUID(), new TextComponent(ChatColor.GREEN).append(new TranslatableComponent("dev.zontreck.otemod.msgs.warps.set.success")), source.getServer());
con.endRequest();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
ChatServerOverride.broadcastTo(p.getUUID(), new TextComponent(ChatColor.DARK_RED).append(new TranslatableComponent("dev.zontreck.otemod.msgs.warps.set.fail")), source.getServer());
}
ChatServerOverride.broadcastTo(p.getUUID(), new TextComponent(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Green!Warp created successfully")), p.server);
return 0;
}

View file

@ -3,9 +3,12 @@ package dev.zontreck.otemod.commands.warps;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Iterator;
import java.util.List;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.chat.Clickable;
@ -16,6 +19,9 @@ import dev.zontreck.otemod.commands.teleport.RTPCommand;
import dev.zontreck.otemod.commands.teleport.TeleportActioner;
import dev.zontreck.otemod.commands.teleport.TeleportContainer;
import dev.zontreck.otemod.database.TeleportDestination;
import dev.zontreck.otemod.implementation.warps.NoSuchWarpException;
import dev.zontreck.otemod.implementation.warps.Warp;
import dev.zontreck.otemod.implementation.warps.WarpsProvider;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.nbt.NbtUtils;
@ -38,49 +44,36 @@ public class WarpCommand {
private static int warp(CommandSourceStack source, String string) {
ServerPlayer p = (ServerPlayer)source.getEntity();
Connection con = OTEMod.DB.getConnection();
String SQL = "";
final ServerPlayer p;
try{
con.beginRequest();
p=source.getPlayerOrException();
Warp warp = WarpsProvider.WARPS_INSTANCE.getNamedWarp(string);
PreparedStatement pstat;
SQL = "SELECT * FROM `warps` WHERE `warpname`=?;";
pstat=con.prepareStatement(SQL);
pstat.setString(1, string);
ResultSet rs = pstat.executeQuery();
// Get the first result
if(rs.next())
{
TeleportDestination dest = new TeleportDestination(NbtUtils.snbtToStructure(rs.getString("teleporter")));
TeleportDestination dest = warp.destination;
ServerLevel dimL=(ServerLevel) dest.getActualDimension();
ServerLevel dimL=(ServerLevel) dest.getActualDimension();
final int type = warp.RTP ? 1 : 0;
final ServerLevel f_dim = dimL;
final int type = rs.getInt("warptype");
final ServerLevel f_dim = dimL;
Thread tx = new Thread(new Runnable(){
public void run(){
Thread tx = new Thread(new Runnable(){
public void run(){
if(type==1){
dest.Position = RTPCommand.findPosition(source.getLevel(), false);
}
TeleportActioner.ApplyTeleportEffect(p);
TeleportContainer tc = new TeleportContainer(p, dest.Position.asMinecraftVector(), dest.Rotation.asMinecraftVector(), f_dim);
TeleportActioner.PerformTeleport(tc);
if(type==1){
dest.Position = RTPCommand.findPosition(source.getLevel(), false);
}
});
tx.start();
}else {
ChatServerOverride.broadcastTo(p.getUUID(), new TextComponent(ChatColor.DARK_RED+"No such warp"), source.getServer());
}
con.endRequest();
}catch(Exception e){
TeleportActioner.ApplyTeleportEffect(p);
TeleportContainer tc = new TeleportContainer(p, dest.Position.asMinecraftVector(), dest.Rotation.asMinecraftVector(), f_dim);
TeleportActioner.PerformTeleport(tc);
}
});
tx.start();
}catch(NoSuchWarpException e)
{
ChatServerOverride.broadcastTo(source.getEntity().getUUID(), new TextComponent(ChatColor.DARK_RED+"No such warp"), source.getServer());
} catch (CommandSyntaxException e) {
e.printStackTrace();
}
return 0;

View file

@ -3,6 +3,10 @@ package dev.zontreck.otemod.commands.warps;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import com.mojang.brigadier.CommandDispatcher;
@ -11,7 +15,10 @@ import dev.zontreck.libzontreck.chat.Clickable;
import dev.zontreck.libzontreck.chat.HoverTip;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
import dev.zontreck.otemod.configs.Profile;
import dev.zontreck.otemod.implementation.profiles.Profile;
import dev.zontreck.otemod.implementation.profiles.UserProfileNotYetExistsException;
import dev.zontreck.otemod.implementation.warps.Warp;
import dev.zontreck.otemod.implementation.warps.WarpsProvider;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.ClickEvent;
@ -37,50 +44,46 @@ public class WarpsCommand {
ServerPlayer p = (ServerPlayer)source.getEntity();
Connection con = OTEMod.DB.getConnection();
try{
// Begin
con.beginRequest();
PreparedStatement pstat = con.prepareStatement("SELECT * FROM `warps`;"); // We want the warp owner, and the warp type, and name. We don't really care about the teleport properties right now, but a future version will show lore on the tooltip to indicate where it goes
Map<String, Warp> warps = WarpsProvider.WARPS_INSTANCE.get();
ChatServerOverride.broadcastTo(p.getUUID(), new TextComponent(OTEMod.OTEPrefix + " "+ChatColor.resetChat() + "There are "+warps.size()+" warps available"), source.getServer());
ResultSet rs = pstat.executeQuery();
int count=0;
while(rs.next())
{
// Lets do it!
count++;
}
rs=pstat.executeQuery();// Reset the query
ChatServerOverride.broadcastTo(p.getUUID(), new TextComponent(OTEMod.OTEPrefix + " "+ChatColor.resetChat() + "There are "+count+" warps available"), source.getServer());
while(rs.next())
{
// This is a warp!
// Pull the owner profile
Profile prof = Profile.get_profile_of(rs.getString("owner"));
String warpName = rs.getString("warpname");
int warpType = rs.getInt("warptype");
String appendType = (warpType == 0) ? "standard warp." : "RTP Warp. This has a position randomizer.";
HoverEvent hover = HoverTip.get(ChatColor.BOLD + ChatColor.DARK_PURPLE + "This warp is a "+appendType);
ClickEvent click = Clickable.command("/warp "+warpName);
Style S = Style.EMPTY.withFont(Style.DEFAULT_FONT).withHoverEvent(hover).withClickEvent(click);
Component warpMsg = new TextComponent(ChatColor.GREEN + warpName + ChatColor.resetChat()).withStyle(S);
// Now, display the warp name, along with the warp's owner information
HoverEvent h2 = HoverTip.get(prof.name_color+prof.nickname+ChatColor.resetChat()+ChatColor.AQUA+" is the owner of this warp");
S = Style.EMPTY.withFont(Style.DEFAULT_FONT).withHoverEvent(h2);
Component ownerInfo = new TextComponent(ChatColor.GOLD+ " [Hover to see the warp's info]").withStyle(S);
// Combine the two
warpMsg = new TextComponent("").append(warpMsg).append(ownerInfo);
ChatServerOverride.broadcastTo(p.getUUID(), warpMsg, source.getServer());
}
}catch (Exception E)
Iterator<Entry<String, Warp>> it = warps.entrySet().iterator();
while(it.hasNext())
{
E.printStackTrace();
// TODO: Implement public and private. Private requires an ACL be implemented. New GUI
Warp warp = it.next().getValue();
// Pull the owner profile
Profile prof=null;
try {
prof = Profile.get_profile_of(warp.owner.toString());
} catch (UserProfileNotYetExistsException e) {
e.printStackTrace();
return 1;
}
String warpName = warp.WarpName;
int warpType = 0;
if(warp.RTP) warpType=1;
String appendType = (warpType == 0) ? "standard warp." : "RTP Warp. This has a position randomizer.";
HoverEvent hover = HoverTip.get(ChatColor.BOLD + ChatColor.DARK_PURPLE + "This warp is a "+appendType);
ClickEvent click = Clickable.command("/warp "+warpName);
Style S = Style.EMPTY.withFont(Style.DEFAULT_FONT).withHoverEvent(hover).withClickEvent(click);
Component warpMsg = new TextComponent(ChatColor.GREEN + warpName + ChatColor.resetChat()).withStyle(S);
// Now, display the warp name, along with the warp's owner information
HoverEvent h2 = HoverTip.get(prof.name_color+prof.nickname+ChatColor.resetChat()+ChatColor.AQUA+" is the owner of this warp");
S = Style.EMPTY.withFont(Style.DEFAULT_FONT).withHoverEvent(h2);
Component ownerInfo = new TextComponent(ChatColor.GOLD+ " [Hover to see the warp's info]").withStyle(S);
// Combine the two
warpMsg = new TextComponent("").append(warpMsg).append(ownerInfo);
ChatServerOverride.broadcastTo(p.getUUID(), warpMsg, source.getServer());
}
return 0;
}

View file

@ -16,11 +16,6 @@ public class OTEServerConfig {
public static final ForgeConfigSpec.ConfigValue<List<ItemStack>> INITIAL_ITEMS_TO_GIVE_ON_FIRST_JOIN;
public static final ForgeConfigSpec.ConfigValue<Double> SPAWN_EGG_CHANCE;
public static final ForgeConfigSpec.ConfigValue<String> HOST_ADDR;
public static final ForgeConfigSpec.ConfigValue<Integer> PORT;
public static final ForgeConfigSpec.ConfigValue<String> USERNAME;
public static final ForgeConfigSpec.ConfigValue<String> PASSWORD;
public static final ForgeConfigSpec.ConfigValue<String> DATABASE;
public static final ForgeConfigSpec.ConfigValue<Integer> ITEM_DESPAWN_TIMER;
@ -49,15 +44,7 @@ public class OTEServerConfig {
INITIAL_ITEMS_TO_GIVE_ON_FIRST_JOIN = BUILDER.comment("What items, identified by modid:item, to give to a brand new user on the server").define("New Player Gear", defaults);
SPAWN_EGG_CHANCE = BUILDER.comment("What is the chance for a spawn egg to drop from a mob when looting 3 is used? Default: 0.25").define("spawn_egg_chance", 0.25);
MAX_VAULTS = BUILDER.comment("What is the maximum number of vaults a player may have available? (0 is unlimited)").define("max_vaults", 0);
BUILDER.pop();
BUILDER.push("DATABASE");
HOST_ADDR = BUILDER.comment("Database Host (MySQL)").define("host", "127.0.0.1");
PORT = BUILDER.comment("Database Port (MySQL)").define("port", 3306);
USERNAME = BUILDER.comment("Database Username (MySQL)").define("user", "ote");
PASSWORD = BUILDER.comment("Database Password (MySQL)").define("password", "password");
DATABASE = BUILDER.comment("Database Name (MySQL)").define("database", "otemod");
ITEM_DESPAWN_TIMER = BUILDER.comment("How many times should the item's expire be cancelled. The vanilla expire time is 5 minutes, so this would be ticked down once every 5 minutes.").define("item_extra_lives", (60/5));
ITEM_DESPAWN_TIMER = BUILDER.comment("How many times should the item's expire be cancelled. The vanilla expire time is 5 minutes, so this would be ticked down once every 5 minutes.").define("item_extra_lives", 2);
BUILDER.pop();
BUILDER.push("COMMANDS");

View file

@ -1,74 +0,0 @@
package dev.zontreck.otemod.configs;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.otemod.OTEMod;
import net.minecraft.server.level.ServerPlayer;
public class Profile {
public String username;
public String user_id;
public String prefix;
public String nickname;
public String name_color; // ChatColor.X
public String prefix_color;
public String chat_color;
public Boolean flying;
public int available_vaults;
public Profile(String username, String prefix, String nickname, String name_color, String ID, String prefix_color, String chat_color, Boolean isFlying, int vaults) {
this.username = username;
this.prefix = prefix;
this.nickname = nickname;
this.name_color = name_color;
this.user_id = ID;
this.prefix_color = prefix_color;
this.chat_color = chat_color;
this.flying=isFlying;
this.available_vaults=vaults;
}
public static Profile get_profile_of(String UUID)
{
if(OTEMod.PROFILES.containsKey(UUID)){
return OTEMod.PROFILES.get(UUID);
}else {
// profile does not exist!
// how can this happen?
return null;
}
}
public static Profile factory(ServerPlayer play)
{
Profile p = new Profile(play.getName().getString(), "Member", play.getDisplayName().getString(), ChatColor.GREEN, play.getStringUUID(), ChatColor.AQUA, ChatColor.WHITE, false, 0);
return p;
}
public void commit()
{
// Send player to server!
Connection con = OTEMod.DB.getConnection();
String SQL = "REPLACE INTO `profiles` (username, uuid, prefix, nickname, name_color, prefix_color, chat_color, flying, vaults) values (?, ?, ?, ?, ?, ?, ?, ?, ?);";
try {
PreparedStatement pstat = con.prepareStatement(SQL);
pstat.setString(1, username);
pstat.setString(2, user_id);
pstat.setString(3, prefix);
pstat.setString(4, nickname);
pstat.setString(5, name_color);
pstat.setString(6, prefix_color);
pstat.setString(7, chat_color);
pstat.setBoolean(8, flying);
pstat.setInt(9, available_vaults);
pstat.execute();
} catch (SQLException e) {
e.printStackTrace();
}
}
}

View file

@ -1,107 +0,0 @@
package dev.zontreck.otemod.database;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.configs.OTEServerConfig;
public class Database {
private OTEMod mod;
private Connection connection;
public Database (OTEMod instance) throws DatabaseConnectionException, SQLException
{
mod=instance;
try{
this.connect();
}catch(Exception e){
throw new DatabaseConnectionException(e.getMessage());
}
Thread tx = new Thread(new Runnable(){
public void run()
{
while(true){
// Watch the connection for disconnections
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(!OTEMod.ALIVE)return;// Exit now. We are being torn down/server is going down
try {
if(!OTEMod.DB.isConnected())
{
OTEMod.LOGGER.info("/!\\ Lost connection to data provider. Reconnecting...");
// Refresh
try {
OTEMod.DB.connect();
if(OTEMod.DB.isConnected())
{
OTEMod.LOGGER.info("/!\\ Reconnected!");
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
});
if(isConnected()){
tx.start();
}
}
public void connect() throws Exception
{
connection = DriverManager.getConnection("jdbc:mariadb://"+OTEServerConfig.HOST_ADDR.get()+":"+OTEServerConfig.PORT.get()+"/" + OTEServerConfig.DATABASE.get() + "?useSSL=false", OTEServerConfig.USERNAME.get(), OTEServerConfig.PASSWORD.get());
}
public class DatabaseConnectionException extends Exception
{
public DatabaseConnectionException(String X) {
super(X);
}
}
public boolean isConnected() throws SQLException
{
if(connection != null)
{
if(connection.isClosed())
{
return false;
}else return true;
}else return false;
}
public Connection getConnection() {
return connection;
}
public void disconnect() throws SQLException
{
if(isConnected())
{
try{
connection.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
}

View file

@ -0,0 +1,44 @@
package dev.zontreck.otemod.database;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.FileAttribute;
import java.util.ArrayList;
import java.util.List;
import net.minecraftforge.fml.loading.FMLPaths;
public class FileTreeDatastore {
private static final Path BASE;
static{
Path X = FMLPaths.CONFIGDIR.get().resolve("otemod");
BASE=X;
if(!BASE.toFile().exists())
{
try {
Files.createDirectory(BASE);
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static Path of(String nick)
{
return BASE.resolve(nick);
}
public static List<File> getListOfFiles(Path files)
{
List<File> fileList = new ArrayList<>();
File[] entries = files.toFile().listFiles();
for (File file : entries) {
fileList.add(file);
}
return fileList;
}
}

View file

@ -29,7 +29,7 @@ public class EventHandler {
@SubscribeEvent(priority = EventPriority.HIGH)
public static void addOresToBiomes(final BiomeLoadingEvent ev){
//ShapedAionResources.LOGGER.info("Biome loading event called. Registering aion ores");
OTEMod.LOGGER.info("/!\\ Registering OTEMod ores /!\\");
//OTEMod.LOGGER.info("/!\\ Registering OTEMod ores /!\\");
OreGenerator.generateOres(ev);
}

View file

@ -0,0 +1,13 @@
package dev.zontreck.otemod.implementation.events;
import dev.zontreck.otemod.implementation.homes.Home;
import net.minecraftforge.eventbus.api.Event;
public class HomeCreatedEvent extends Event
{
public Home home;
public HomeCreatedEvent(Home home)
{
this.home=home;
}
}

View file

@ -0,0 +1,12 @@
package dev.zontreck.otemod.implementation.events;
import dev.zontreck.otemod.implementation.homes.Home;
public class HomeDeletedEvent extends HomeCreatedEvent
{
public HomeDeletedEvent(Home home) {
super(home);
}
}

View file

@ -0,0 +1,13 @@
package dev.zontreck.otemod.implementation.events;
import dev.zontreck.otemod.implementation.profiles.Profile;
import net.minecraftforge.eventbus.api.Event;
public class ProfileCreatedEvent extends Event
{
public String playerID;
public ProfileCreatedEvent(Profile newProfile)
{
playerID = newProfile.user_id;
}
}

View file

@ -0,0 +1,30 @@
package dev.zontreck.otemod.implementation.events;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.configs.OTEServerConfig;
import dev.zontreck.otemod.implementation.profiles.Profile;
import dev.zontreck.otemod.implementation.vault.Vault;
import net.minecraftforge.eventbus.api.Event;
public class VaultCreatedEvent extends Event
{
public int vault_num;
public Profile user;
public int in_use;
public int max;
public int playerMax;
public int remaining;
public boolean at_max;
public VaultCreatedEvent(int num, Profile user, int vaultsInUse)
{
max=OTEServerConfig.MAX_VAULTS.get();
vault_num = num;
in_use = vaultsInUse;
playerMax=user.available_vaults;
remaining = playerMax-in_use;
if(remaining<=0)at_max=true;
this.user=user;
}
}

View file

@ -0,0 +1,11 @@
package dev.zontreck.otemod.implementation.events;
import dev.zontreck.otemod.implementation.profiles.Profile;
public class VaultDeletedEvent extends VaultCreatedEvent{
public VaultDeletedEvent(int num, Profile user, int vaultsInUse) {
super(num, user, vaultsInUse);
}
}

View file

@ -0,0 +1,18 @@
package dev.zontreck.otemod.implementation.events;
import dev.zontreck.otemod.implementation.profiles.Profile;
import net.minecraft.world.entity.player.Inventory;
import net.minecraftforge.items.ItemStackHandler;
public class VaultModifiedEvent extends VaultCreatedEvent
{
public ItemStackHandler inventory;
public ItemStackHandler oldInventory;
public VaultModifiedEvent(int num, Profile user, int vaultsInUse, ItemStackHandler inv, ItemStackHandler old) {
super(num, user, vaultsInUse);
inventory=inv;
oldInventory = old;
}
}

View file

@ -0,0 +1,13 @@
package dev.zontreck.otemod.implementation.events;
import dev.zontreck.otemod.implementation.warps.Warp;
import net.minecraftforge.eventbus.api.Event;
public class WarpCreatedEvent extends Event
{
public Warp warp;
public WarpCreatedEvent(Warp w)
{
warp=w;
}
}

View file

@ -0,0 +1,12 @@
package dev.zontreck.otemod.implementation.events;
import dev.zontreck.otemod.implementation.warps.Warp;
public class WarpDeletedEvent extends WarpCreatedEvent
{
public WarpDeletedEvent(Warp w) {
super(w);
}
}

View file

@ -0,0 +1,43 @@
package dev.zontreck.otemod.implementation.homes;
import java.util.UUID;
import dev.zontreck.libzontreck.exceptions.InvalidDeserialization;
import dev.zontreck.otemod.database.TeleportDestination;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerPlayer;
public class Home {
public UUID owner;
public String homeName;
public TeleportDestination destination;
public Home(ServerPlayer player, String name, TeleportDestination dest)
{
owner=player.getUUID();
homeName=name;
destination=dest;
}
public Home(CompoundTag tag)
{
owner = tag.getUUID("owner");
homeName = tag.getString("name");
try {
destination = new TeleportDestination(tag.getCompound("dest"));
} catch (InvalidDeserialization e) {
e.printStackTrace();
}
}
public CompoundTag serialize()
{
CompoundTag tag = new CompoundTag();
tag.putUUID("owner", owner);
tag.putString("name", homeName);
tag.put("dest", destination.serialize());
return tag;
}
}

View file

@ -0,0 +1,84 @@
package dev.zontreck.otemod.implementation.homes;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.implementation.events.HomeCreatedEvent;
import dev.zontreck.otemod.implementation.events.HomeDeletedEvent;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
public class Homes {
private Map<String, Home> homes = new HashMap<>();
public String playerID;
public Homes(String playerID)
{
this.playerID=playerID;
}
public int count()
{
return homes.size();
}
public List<Home> getList()
{
return new ArrayList<>(homes.values());
}
public Home get(String name) throws NoSuchHomeException
{
if(homes.containsKey(name))
return homes.get(name);
else throw new NoSuchHomeException();
}
public void delete(String name) throws NoSuchHomeException
{
Home home = homes.get(name);
HomeDeletedEvent e = new HomeDeletedEvent(home);
homes.remove(name);
OTEMod.bus.post(e);
HomesProvider.commitHomes(this);
}
public void add(Home toAdd)
{
HomeCreatedEvent hce = new HomeCreatedEvent(toAdd);
OTEMod.bus.post(hce);
homes.put(toAdd.homeName, toAdd);
HomesProvider.commitHomes(this);
}
public static Homes deserialize(CompoundTag tag)
{
Homes ret = new Homes(null);
ListTag theHomes = tag.getList("homes", Tag.TAG_COMPOUND);
for (Tag tag2 : theHomes) {
Home h = new Home((CompoundTag)tag2);
ret.homes.put(h.homeName, h);
}
return ret;
}
public CompoundTag serialize()
{
CompoundTag tag = new CompoundTag();
ListTag lst = new ListTag();
for (Map.Entry<String,Home> entry : homes.entrySet()) {
lst.add(entry.getValue().serialize());
}
tag.put("homes", lst);
return tag;
}
}

View file

@ -0,0 +1,49 @@
package dev.zontreck.otemod.implementation.homes;
import java.io.IOException;
import java.nio.file.Path;
import java.util.UUID;
import dev.zontreck.otemod.implementation.profiles.Profile;
import net.minecraft.nbt.NbtIo;
public class HomesProvider {
/**
* DO NOT USE. Internal use only.
* @see Profile#player_homes
* @param player
* @return
*/
public static Homes getHomesForPlayer(String player)
{
Path homesFile = Profile.BASE.resolve(player).resolve("homes.nbt");
Homes homes = new Homes(player);
if(homesFile.toFile().exists())
{
try {
homes=Homes.deserialize(NbtIo.read(homesFile.toFile()));
homes.playerID=player;
} catch (IOException e) {
e.printStackTrace();
}
}
return homes;
}
public static void commitHomes(Homes playerHomes)
{
Path homesFile = Profile.BASE.resolve(playerHomes.playerID).resolve("homes.nbt");
try {
NbtIo.write(playerHomes.serialize(), homesFile.toFile());
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,5 @@
package dev.zontreck.otemod.implementation.homes;
public class NoSuchHomeException extends Exception{
}

View file

@ -0,0 +1,162 @@
package dev.zontreck.otemod.implementation.profiles;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import dev.zontreck.libzontreck.LibZontreck.ForgeEventBus;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.database.FileTreeDatastore;
import dev.zontreck.otemod.implementation.events.ProfileCreatedEvent;
import dev.zontreck.otemod.implementation.homes.Homes;
import dev.zontreck.otemod.implementation.homes.HomesProvider;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtIo;
import net.minecraft.server.level.ServerPlayer;
import net.minecraftforge.eventbus.EventBus;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
public class Profile {
public String username;
public String user_id;
public String prefix;
public String nickname;
public String name_color; // ChatColor.X
public String prefix_color;
public String chat_color;
public Boolean flying;
public int available_vaults;
public Homes player_homes;
private File accessor;
public static final Path BASE = FileTreeDatastore.of("profiles");
public Profile(String username, String prefix, String nickname, String name_color, String ID, String prefix_color, String chat_color, Boolean isFlying, int vaults, File vaultFile) {
this.username = username;
this.prefix = prefix;
this.nickname = nickname;
this.name_color = name_color;
this.user_id = ID;
this.prefix_color = prefix_color;
this.chat_color = chat_color;
this.flying=isFlying;
this.available_vaults=vaults;
player_homes = HomesProvider.getHomesForPlayer(ID);
this.accessor = vaultFile;
}
public static Profile get_profile_of(String UUID) throws UserProfileNotYetExistsException
{
if(OTEMod.PROFILES.containsKey(UUID)){
return OTEMod.PROFILES.get(UUID);
}else {
// Create or load profile
Path userProfile = BASE.resolve(UUID);
if(userProfile.toFile().exists())
{
// Load profile data
File ace = userProfile.resolve("profile.dat").toFile();
try {
Profile actual = load(NbtIo.read(ace), ace);
OTEMod.PROFILES.put(UUID, actual);
return actual;
} catch (IOException e) {
throw new UserProfileNotYetExistsException(UUID);
}
}else {
// Create directory, then throw a exception so a new profile gets created
try {
Files.createDirectories(userProfile);
} catch (IOException e) {
e.printStackTrace();
}
throw new UserProfileNotYetExistsException(UUID);
}
}
}
private static Profile load(CompoundTag tag, File accessor)
{
return new Profile(tag.getString("user"), tag.getString("prefix"), tag.getString("nick"), tag.getString("nickc"), tag.getString("id"), tag.getString("prefixc"), tag.getString("chatc"), tag.getBoolean("flying"), tag.getInt("vaults"), accessor);
}
private static void generateNewProfile(ServerPlayer player)
{
Path userProfile = BASE.resolve(player.getStringUUID());
if(userProfile.toFile().exists())
{
// Load profile data
File ace = userProfile.resolve("profile.dat").toFile();
Profile template = new Profile(player.getName().getString(), "Member", player.getDisplayName().getString(), ChatColor.GREEN, player.getStringUUID(), ChatColor.AQUA, ChatColor.WHITE, false, 0, ace);
template.commit();
OTEMod.bus.post(new ProfileCreatedEvent(template));
template=null;
return;
}else {
try {
Files.createDirectories(userProfile);
} catch (IOException e) {
e.printStackTrace();
}
generateNewProfile(player);
}
}
@Override
public void finalize()
{
OTEMod.LOGGER.info("Profile is unloaded for "+username);
}
public static void unload(Profile prof)
{
OTEMod.PROFILES.remove(prof.user_id);
prof=null;
}
public static Profile factory(ServerPlayer play)
{
try {
return get_profile_of(play.getStringUUID());
} catch (UserProfileNotYetExistsException e) {
generateNewProfile(play);
return factory(play);
}
}
public void commit()
{
// Save data to FileTree
CompoundTag serial = new CompoundTag();
serial.putString("user", username);
serial.putString("prefix", prefix);
serial.putString("nick", nickname);
serial.putString("id", user_id);
serial.putString("nickc", name_color);
serial.putString("prefixc", prefix_color);
serial.putString("chatc", chat_color);
serial.putBoolean("flying", flying);
serial.putInt("vaults", available_vaults);
try {
NbtIo.write(serial, accessor);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,9 @@
package dev.zontreck.otemod.implementation.profiles;
public class UserProfileNotYetExistsException extends Exception{
String playerID;
public UserProfileNotYetExistsException(String id){
super("A user profile does not yet exist");
playerID=id;
}
}

View file

@ -0,0 +1,15 @@
package dev.zontreck.otemod.implementation.vault;
/**
* You cannot create or open the vault due to server settings
*/
public class NoMoreVaultException extends Exception
{
public int vault;
public NoMoreVaultException(String msg, int vaultNum)
{
super(msg);
vault=vaultNum;
}
}

View file

@ -0,0 +1,64 @@
package dev.zontreck.otemod.implementation.vault;
import java.io.File;
import java.io.IOException;
import dev.zontreck.otemod.implementation.profiles.Profile;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtIo;
public class Vault {
public int vaultNum;
public File file_location;
public Profile user;
public final boolean isNew;
private CompoundTag tag;
protected Vault(int num, File loc, Profile owner)
{
user=owner;
file_location=loc;
vaultNum=num;
isNew=!file_location.exists();
if(!isNew){
try {
tag = NbtIo.read(loc);
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* This will return the contents of the NBT Vault
* @return
*/
public CompoundTag getContents(){
return tag;
}
/**
* This sets the internal compound tag of the vault provider, but also saves it to the file immediately.
* @param newTag
*/
public void setContents(CompoundTag newTag)
{
tag=newTag;
try {
NbtIo.write(newTag, file_location);
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* This is called to dispose of the vault and the vault file
*/
public void delete()
{
if(file_location.exists())
file_location.delete();
}
}

View file

@ -13,15 +13,23 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
import dev.zontreck.otemod.implementation.events.VaultModifiedEvent;
import dev.zontreck.otemod.implementation.profiles.Profile;
import dev.zontreck.otemod.implementation.profiles.UserProfileNotYetExistsException;
import dev.zontreck.otemod.implementation.vault.VaultProvider.VaultAccessStrategy;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtIo;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.MenuConstructor;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.items.ItemStackHandler;
public class VaultContainer
@ -29,13 +37,16 @@ public class VaultContainer
public static Map<UUID, VaultContainer> VAULT_REGISTRY = new HashMap<>();
public VaultMenu theContainer;
public ItemStackHandler myInventory;
public ItemStackHandler startingInventory;
public MenuConstructor serverMenu;
public UUID owner;
private MinecraftServer server;
public final int VAULT_NUMBER;
public final UUID VaultID;
public VaultContainer(ServerPlayer player, int vaultNum) {
public Vault main_accessor;
public VaultContainer(ServerPlayer player, int vaultNum) throws NoMoreVaultException {
myInventory = new ItemStackHandler(54); // Vaults have a fixed size at the same as a double chest
startingInventory = new ItemStackHandler(64);
theContainer = new VaultMenu(player.containerCounter+1, player.getInventory(), myInventory, BlockPos.ZERO, player, vaultNum);
VaultID = theContainer.VaultMenuID;
owner = player.getUUID();
@ -44,67 +55,66 @@ public class VaultContainer
VAULT_NUMBER=vaultNum;
if(VAULT_NUMBER == -1)return; // Trash ID
Connection con = OTEMod.DB.getConnection();
// Check database for vault
PreparedStatement pstat;
VaultAccessStrategy strategy;
try {
con.beginRequest();
pstat = con.prepareStatement("SELECT * FROM `vaults` WHERE `uuid`=? AND `number`=?;");
pstat.setString(1, player.getStringUUID());
pstat.setInt(2, vaultNum);
ResultSet rs = pstat.executeQuery();
while(rs.next())
strategy = VaultProvider.check(Profile.get_profile_of(player.getStringUUID()), vaultNum);
if(strategy == VaultAccessStrategy.CREATE || strategy == VaultAccessStrategy.OPEN)
{
// We have a vault, deserialize the container
String data = rs.getString("data");
CompoundTag inv = NbtUtils.snbtToStructure(data);
myInventory.deserializeNBT(inv);
Vault accessor = VaultProvider.get(Profile.get_profile_of(player.getStringUUID()), vaultNum);
if(accessor.isNew)
{
main_accessor=accessor;
return;
}else {
myInventory.deserializeNBT(accessor.getContents());
startingInventory.deserializeNBT(accessor.getContents());
}
main_accessor=accessor;
}else {
// DENY
throw new NoMoreVaultException("No more vaults can be created", vaultNum);
}
con.endRequest();
} catch (SQLException | CommandSyntaxException e) {
e.printStackTrace();
} catch (UserProfileNotYetExistsException e) {
throw new NoMoreVaultException("User profile not exists. No vault can be opened or created", -9999);
}
// Container is now ready to be sent to the client!
}
public void commit()
{
if(VAULT_NUMBER == -1)return; // We have no need to save the trash
boolean isEmpty=true;
CompoundTag saved = myInventory.serializeNBT();
ChatServerOverride.broadcastToAbove(owner, new TextComponent(ChatColor.BOLD+ChatColor.DARK_GREEN+"Saving the vault's contents..."), server);
String toSave= NbtUtils.structureToSnbt(saved);
Connection con = OTEMod.DB.getConnection();
try{
con.beginRequest();
PreparedStatement ps = con.prepareStatement("REPLACE INTO `vaults` (uuid, number, data) VALUES (?,?,?);");
ps.setString(1, owner.toString());
ps.setInt(2, VAULT_NUMBER);
ps.setString(3, toSave);
boolean has_items = false;
for (int i = 0; i< myInventory.getSlots(); i++){
ItemStack IS = myInventory.getStackInSlot(i);
if(!IS.isEmpty()){
has_items=true;
}
}
if(!has_items)
{
ps = con.prepareStatement("DELETE FROM `vaults` WHERE uuid=? AND number=?;");
ps.setString(1, owner.toString());
ps.setInt(2, VAULT_NUMBER);
}
ps.execute();
con.endRequest();
}catch(SQLException e){
Profile profile=null;
try {
profile = Profile.get_profile_of(owner.toString());
} catch (UserProfileNotYetExistsException e) {
e.printStackTrace();
return;
}
for(int i = 0;i<myInventory.getSlots();i++)
{
ItemStack is = myInventory.getStackInSlot(i);
if(!is.is(Items.AIR))
{
isEmpty=false;
}
}
if(!isEmpty)
main_accessor.setContents(saved);
else
main_accessor.delete();
VaultModifiedEvent vme = new VaultModifiedEvent(VAULT_NUMBER, profile, VaultProvider.getInUse(profile), myInventory, startingInventory);
OTEMod.bus.post(vme);
}
}

View file

@ -0,0 +1,98 @@
package dev.zontreck.otemod.implementation.vault;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import dev.zontreck.otemod.configs.OTEServerConfig;
import dev.zontreck.otemod.database.FileTreeDatastore;
import dev.zontreck.otemod.implementation.profiles.Profile;
public class VaultProvider extends FileTreeDatastore
{
public enum VaultAccessStrategy
{
OPEN,
CREATE,
DENY
}
public static final Path FILE_TREE_PATH = of("vaults");
public static VaultAccessStrategy check(Profile profile, int vaultNum)
{
if(!FILE_TREE_PATH.toFile().exists())
{
try {
Files.createDirectory(FILE_TREE_PATH);
} catch (IOException e) {
e.printStackTrace();
}
}
Path userVaultPath = FILE_TREE_PATH.resolve(profile.user_id);
File vaultFile = userVaultPath.resolve(String.valueOf(vaultNum)+".nbt").toFile();
if(!userVaultPath.toFile().exists()){
try {
Files.createDirectory(userVaultPath);
} catch (IOException e) {
e.printStackTrace();
}
}
if(vaultFile.exists())
{
return VaultAccessStrategy.OPEN;
}else {
List<File> files = getListOfFiles(userVaultPath);
if(isAtMaxVaults(profile, files.size()))
{
return VaultAccessStrategy.DENY;
}else {
return VaultAccessStrategy.CREATE;
}
}
}
public static int getInUse(Profile prof)
{
Path uservaults = FILE_TREE_PATH.resolve(prof.user_id);
return getListOfFiles(uservaults).size();
}
public static boolean isAtMaxVaults(Profile prof, int consumed)
{
if(OTEServerConfig.MAX_VAULTS.get()==0){
if(consumed < prof.available_vaults){
return false;
}else return true;
}
if(prof.available_vaults >= OTEServerConfig.MAX_VAULTS.get())
{
if(consumed<prof.available_vaults)
{
return false;
}
return true;
}else{
if(consumed<prof.available_vaults)return false;
else return true;
}
}
public static Vault get(Profile profile, int vault) throws NoMoreVaultException
{
VaultAccessStrategy strat = check(profile,vault);
if(strat == VaultAccessStrategy.CREATE || strat == VaultAccessStrategy.OPEN)
{
Path userVault = FILE_TREE_PATH.resolve(profile.user_id);
Vault v = new Vault(vault, userVault.resolve(String.valueOf(vault)+".nbt").toFile(), profile);
return v;
}else throw new NoMoreVaultException("Cannot open due to server limits", vault);
}
}

View file

@ -0,0 +1,6 @@
package dev.zontreck.otemod.implementation.warps;
public class NoSuchWarpException extends Exception
{
}

View file

@ -0,0 +1,41 @@
package dev.zontreck.otemod.implementation.warps;
import java.util.UUID;
import dev.zontreck.libzontreck.exceptions.InvalidDeserialization;
import dev.zontreck.otemod.database.TeleportDestination;
import net.minecraft.nbt.CompoundTag;
public class Warp {
public UUID owner;
public String WarpName;
public boolean RTP;
public boolean isPublic;
public TeleportDestination destination;
public Warp(UUID owner, String name, boolean rtp, boolean publicWarp, TeleportDestination destination)
{
this.owner=owner;
WarpName=name;
RTP=rtp;
isPublic=publicWarp;
this.destination=destination;
}
public static Warp deserialize(CompoundTag tag) throws InvalidDeserialization
{
return new Warp(tag.getUUID("owner"), tag.getString("name"), tag.getBoolean("rtp"), tag.getBoolean("public"), new TeleportDestination(tag.getCompound("destination")));
}
public CompoundTag serialize()
{
CompoundTag tag = new CompoundTag();
tag.putUUID("owner", owner);
tag.putString("name", WarpName);
tag.putBoolean("rtp", RTP);
tag.putBoolean("public", isPublic);
tag.put("destination", destination.serialize());
return tag;
}
}

View file

@ -0,0 +1,92 @@
package dev.zontreck.otemod.implementation.warps;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import dev.zontreck.libzontreck.exceptions.InvalidDeserialization;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.implementation.events.WarpCreatedEvent;
import dev.zontreck.otemod.implementation.events.WarpDeletedEvent;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
public class Warps
{
private Map<String,Warp> warps = new HashMap<>();
private Warps(){
}
public Warp getNamedWarp(String name) throws NoSuchWarpException
{
if(warps.containsKey(name))
return warps.get(name);
else throw new NoSuchWarpException();
}
public void add(Warp w)
{
warps.put(w.WarpName,w);
WarpsProvider.updateFile();
WarpCreatedEvent e = new WarpCreatedEvent(w);
OTEMod.bus.post(e);
}
public Map<String, Warp> get()
{
return new HashMap<String, Warp>(warps);
}
public void delete(Warp w)
{
warps.remove(w.WarpName);
WarpsProvider.updateFile();
WarpDeletedEvent e = new WarpDeletedEvent(w);
OTEMod.bus.post(e);
}
public static Warps getNew()
{
return new Warps();
}
public CompoundTag serialize()
{
CompoundTag tag = new CompoundTag();
ListTag lst = new ListTag();
for(Map.Entry<String, Warp> entry : warps.entrySet())
{
lst.add(entry.getValue().serialize());
}
tag.put("warps", lst);
return tag;
}
public static Warps deserialize(CompoundTag tag)
{
Warps w = new Warps();
ListTag lst = tag.getList("warps", Tag.TAG_COMPOUND);
for (Tag tag2 : lst) {
Warp warp;
try {
warp = Warp.deserialize((CompoundTag)tag2);
w.warps.put(warp.WarpName, warp);
} catch (InvalidDeserialization e) {
e.printStackTrace();
}
}
return w;
}
}

View file

@ -0,0 +1,49 @@
package dev.zontreck.otemod.implementation.warps;
import java.io.IOException;
import java.nio.file.Path;
import dev.zontreck.otemod.database.FileTreeDatastore;
import net.minecraft.nbt.NbtIo;
public class WarpsProvider extends FileTreeDatastore
{
public static final Path BASE = of("warps");
public static final Path WARPS_DATA = BASE.resolve("warps.nbt");
public static final Warps WARPS_INSTANCE;
static{
WARPS_INSTANCE = getOrCreate();
}
/**
* Creates a new warps instance, or returns a fully deserialized instance
* @return
*/
private static Warps getOrCreate()
{
Warps instance = null;
if(WARPS_DATA.toFile().exists())
{
try{
instance= Warps.deserialize(NbtIo.read(WARPS_DATA.toFile()));
}catch(Exception e){
instance=Warps.getNew();
}
}else {
instance=Warps.getNew();
}
return instance;
}
public static void updateFile()
{
try {
NbtIo.write(WARPS_INSTANCE.serialize(), WARPS_DATA.toFile());
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -7,8 +7,9 @@ import dev.zontreck.libzontreck.items.lore.LoreEntry;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
import dev.zontreck.otemod.configs.OTEServerConfig;
import dev.zontreck.otemod.configs.Profile;
import dev.zontreck.otemod.events.LoreHandlers;
import dev.zontreck.otemod.implementation.profiles.Profile;
import dev.zontreck.otemod.implementation.profiles.UserProfileNotYetExistsException;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.world.InteractionHand;
@ -48,28 +49,34 @@ public class VaultItem extends Item
{
ItemStack is = pPlayer.getItemInHand(pUsedHand);
Profile p = Profile.get_profile_of(pPlayer.getStringUUID());
if(OTEServerConfig.MAX_VAULTS.get()>0)
{
if(p.available_vaults >= OTEServerConfig.MAX_VAULTS.get())
Profile p;
try {
p = Profile.get_profile_of(pPlayer.getStringUUID());
if(OTEServerConfig.MAX_VAULTS.get()>0)
{
ChatServerOverride.broadcastTo(pPlayer.getUUID(), new TextComponent(ChatColor.doColors(OTEMod.OTEPrefix+" !Dark_Red!You cannot activate anymore vaults due to the maximum set by the server admin")), OTEMod.THE_SERVER);
return InteractionResultHolder.pass(is);
} else {
if(p.available_vaults >= OTEServerConfig.MAX_VAULTS.get())
{
ChatServerOverride.broadcastTo(pPlayer.getUUID(), new TextComponent(ChatColor.doColors(OTEMod.OTEPrefix+" !Dark_Red!You cannot activate anymore vaults due to the maximum set by the server admin")), OTEMod.THE_SERVER);
return InteractionResultHolder.pass(is);
} else {
p.available_vaults++;
p.commit();
ChatServerOverride.broadcastTo(pPlayer.getUUID(), new TextComponent(ChatColor.doColors(OTEMod.OTEPrefix+" !Dark_Green!You now have "+String.valueOf(p.available_vaults)+" available vaults")), OTEMod.THE_SERVER);
pPlayer.setItemInHand(pUsedHand, new ItemStack(Items.AIR));
return InteractionResultHolder.consume(is);
}
}else {
p.available_vaults++;
p.commit();
ChatServerOverride.broadcastTo(pPlayer.getUUID(), new TextComponent(ChatColor.doColors(OTEMod.OTEPrefix+" !Dark_Green!You now have "+String.valueOf(p.available_vaults)+" available vaults")), OTEMod.THE_SERVER);
pPlayer.setItemInHand(pUsedHand, new ItemStack(Items.AIR));
return InteractionResultHolder.consume(is);
}
}else {
p.available_vaults++;
p.commit();
ChatServerOverride.broadcastTo(pPlayer.getUUID(), new TextComponent(ChatColor.doColors(OTEMod.OTEPrefix+" !Dark_Green!You now have "+String.valueOf(p.available_vaults)+" available vaults")), OTEMod.THE_SERVER);
pPlayer.setItemInHand(pUsedHand, new ItemStack(Items.AIR));
return InteractionResultHolder.consume(is);
} catch (UserProfileNotYetExistsException e) {
e.printStackTrace();
return super.use(pLevel, pPlayer, pUsedHand);
}
}

View file

@ -28,16 +28,24 @@ public class OreGenerator {
public static final List<OreConfiguration.TargetBlockState> OVERWORLD_VAULTSTEEL_ORE = List.of(OreConfiguration.target(OreFeatures.DEEPSLATE_ORE_REPLACEABLES, ModBlocks.VAULT_STEEL_ORE_BLOCK.get().defaultBlockState()));
public static final List<OreConfiguration.TargetBlockState> NETHER_VAULTSTEEL_ORE = List.of( OreConfiguration.target(OreFeatures.NETHER_ORE_REPLACEABLES, ModBlocks.NETHER_VAULT_STEEL_ORE_BLOCK.get().defaultBlockState()));
public static final Holder<ConfiguredFeature<OreConfiguration, ?>> ETERNIUM_ORE = FeatureUtils.register("eternium_ore_block", Feature.ORE, new OreConfiguration(OVERWORLD_ETERNIUM_ORE, 8));
public static final Holder<ConfiguredFeature<OreConfiguration, ?>> VAULTSTEEL_ORE = FeatureUtils.register("vault_steel_ore_block", Feature.ORE, new OreConfiguration(OVERWORLD_VAULTSTEEL_ORE, 6));
public static final Holder<ConfiguredFeature<OreConfiguration, ?>> VAULTSTEEL_ORE_NETHER = FeatureUtils.register("nether_vault_steel_ore_block", Feature.ORE, new OreConfiguration(NETHER_VAULTSTEEL_ORE, 8));
public static final Holder<PlacedFeature> ETERNIUM_ORE_PLACED = PlacementUtils.register("eternium_ore_placed",
ETERNIUM_ORE, ModdedOrePlacement.commonOrePlacement(3, // VeinsPerChunk
HeightRangePlacement.triangle(VerticalAnchor.absolute(-20), VerticalAnchor.absolute(20))));
public static final Holder<PlacedFeature> VAULT_STEEL_ORE_PLACED = PlacementUtils.register("vaultsteel_ore_placed", VAULTSTEEL_ORE, ModdedOrePlacement.rareOrePlacement(4, // Veins per chunk
HeightRangePlacement.triangle(VerticalAnchor.absolute(-63), VerticalAnchor.absolute(-50))));
HeightRangePlacement.triangle(VerticalAnchor.absolute(-63), VerticalAnchor.absolute(-50))));
public static final Holder<PlacedFeature> NETHER_VAULTSTEEL_ORE_PLACED = PlacementUtils.register("nether_vaultsteel_ore_placed", VAULTSTEEL_ORE_NETHER, ModdedOrePlacement.rareOrePlacement(5, // Veins per chunk
HeightRangePlacement.triangle(VerticalAnchor.absolute(1), VerticalAnchor.absolute(16))));
//public static final Holder<PlacedFeature> DEEPSLATE_AION_ORE_PLACED = PlacementUtils.register("deepslate_aion_ore_placed",
// DEEPSLATE_AION_ORE, ModdedOrePlacement.commonOrePlacement(3, // VeinsPerChunk
@ -51,6 +59,7 @@ public class OreGenerator {
//ShapedAionResources.LOGGER.info("Register: AION_ORE");
base.add(ETERNIUM_ORE_PLACED);
base.add(VAULT_STEEL_ORE_PLACED);
base.add(NETHER_VAULTSTEEL_ORE_PLACED);
//base.add(DEEPSLATE_AION_ORE_PLACED);
}
}

View file

@ -19,7 +19,7 @@ modId="otemod" #mandatory
# 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
# see the associated build.gradle script for how to populate this completely automatically during a build
version="1.3.7.4" #mandatory
version="1.3.7.0224230125" #mandatory
# A display name for the mod
displayName="OTEMod" #mandatory
# A URL to query for updates for this mod. See the JSON update specification https://mcforge.readthedocs.io/en/latest/gettingstarted/autoupdate/

View file

@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "otemod:block/nether_vault_steel_ore_block"
}
}
}

View file

@ -48,6 +48,7 @@
"block.otemod.magical_scrubber": "Magical Scrubber",
"block.otemod.stable_singularity": "Stable Singularity",
"block.otemod.vault_steel_ore_block": "Vault Steel Ore",
"block.otemod.nether_vault_steel_ore_block": "Nether Vault Steel Ore",
"enchantment.otemod.mob_egging": "Mob Egging",

View file

@ -0,0 +1,6 @@
{
"parent": "block/cube_all",
"textures": {
"all": "otemod:block/vault_steel_ore_block"
}
}

View file

@ -0,0 +1,3 @@
{
"parent": "otemod:block/vault_steel_ore_block"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 879 B

View file

@ -1,5 +1,6 @@
{
"values": [
"otemod:vault_steel_ore_block"
"otemod:vault_steel_ore_block",
"otemod:nether_vault_steel_ore_block"
]
}

View file

@ -28,4 +28,9 @@ fill ~-10 ~-32 ~-10 ~10 ~15 ~10 minecraft:air replace mekanism:deepslate_lead_or
fill ~-10 ~-32 ~-10 ~10 ~15 ~10 minecraft:air replace mekanism:deepslate_fluorite_ore
fill ~-10 ~-32 ~-10 ~10 ~15 ~10 minecraft:air replace mekanism:deepslate_uranium_ore
fill ~-10 ~-32 ~-10 ~10 ~15 ~10 minecraft:air replace mekanism:deepslate_osmium_ore
fill ~-10 ~-32 ~-10 ~10 ~15 ~10 minecraft:air replace mekanism:deepslate_tin_ore
fill ~-10 ~-32 ~-10 ~10 ~15 ~10 minecraft:air replace mekanism:deepslate_tin_ore
fill ~-10 ~-32 ~-10 ~10 ~15 ~10 minecraft:air replace minecraft:netherrack
fill ~-10 ~-32 ~-10 ~10 ~15 ~10 minecraft:air replace minecraft:soul_sand
fill ~-10 ~-32 ~-10 ~10 ~15 ~10 minecraft:air replace minecraft:soul_soil
fill ~-10 ~-32 ~-10 ~10 ~15 ~10 minecraft:air replace minecraft:magma_block
fill ~-10 ~-32 ~-10 ~10 ~15 ~10 minecraft:air replace minecraft:blackstone

View file

@ -0,0 +1,50 @@
{
"type": "minecraft:block",
"pools": [
{
"name": "main",
"rolls": 1.0,
"bonus_rolls": 0.0,
"entries": [
{
"type": "minecraft:alternatives",
"children": [
{
"type": "minecraft:item",
"conditions": [
{
"condition": "minecraft:match_tool",
"predicate": {
"enchantments": [
{
"enchantment": "minecraft:silk_touch",
"levels": {
"min": 1
}
}
]
}
}
],
"name": "otemod:nether_vault_steel_ore_block"
},
{
"type": "minecraft:item",
"functions": [
{
"function": "minecraft:apply_bonus",
"enchantment": "minecraft:fortune",
"formula": "minecraft:ore_drops"
},
{
"function": "minecraft:explosion_decay"
}
],
"name": "otemod:raw_vault_steel_ore"
}
]
}
]
}
]
}