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:
parent
553ff429f3
commit
5ee0aa47e9
62 changed files with 1385 additions and 705 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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")));
|
||||
|
||||
|
|
|
@ -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)));
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue