Fix SQL bugs

This commit is contained in:
Telesphoreo 2020-11-23 01:52:18 -06:00
parent edb1f224ca
commit 9e107c546d
No known key found for this signature in database
GPG key ID: 50B67E055A6F167C
6 changed files with 76 additions and 135 deletions

View file

@ -237,7 +237,7 @@ public class LoginProcess extends FreedomService
int noteCount = playerData.getNotes().size();
if (noteCount != 0)
{
String noteMessage = "This player has " + noteCount + " admin note" + (noteCount > 1 ? "s" : "") + ".";
String noteMessage = "This player has " + noteCount + " note" + (noteCount > 1 ? "s" : "") + ".";
JSONMessage notice = JSONMessage.create(ChatColor.GOLD + noteMessage + " Click here to view them.")
.tooltip("Click here to view them.")
.runCommand("/notes " + player.getName() + " list");

View file

@ -17,7 +17,6 @@ import org.bukkit.entity.Player;
@CommandParameters(description = "Manage notes for a player", usage = "/<command> <name> <list | add <note> | remove <id> | clear>")
public class Command_notes extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
@ -46,69 +45,78 @@ public class Command_notes extends FreedomCommand
playerData = plugin.pl.getData(player);
}
if (args[1].equals("list"))
switch (args[1])
{
final StringBuilder noteList = new StringBuilder();
noteList.append(ChatColor.GREEN + "Player notes for " + playerData.getName() + ":");
int id = 1;
for (String note : playerData.getNotes())
case "list":
{
String noteLine = id + ". " + note;
noteList.append("\n" + ChatColor.GOLD + noteLine);
id++;
}
msg(noteList.toString());
return true;
}
else if (args[1].equals("add"))
{
if (args.length < 3)
{
return false;
}
String note = sender.getName() + ": " + StringUtils.join(ArrayUtils.subarray(args, 2, args.length), " ");
playerData.addNote(note);
plugin.pl.save(playerData);
msg("Note added.", ChatColor.GREEN);
return true;
}
else if (args[1].equals("remove"))
{
if (args.length < 3)
{
return false;
}
int id;
try
{
id = Integer.valueOf(args[2]);
}
catch (NumberFormatException e)
{
msg("Invalid number: " + args[2], ChatColor.RED);
if (playerData.getNotes().size() == 0)
{
msg("This player has no notes.", ChatColor.RED);
return true;
}
final StringBuilder noteList = new StringBuilder();
noteList.append(ChatColor.GREEN + "Player notes for ").append(playerData.getName()).append(":");
int id = 1;
for (String note : playerData.getNotes())
{
String noteLine = id + ". " + note;
noteList.append("\n" + ChatColor.GOLD).append(noteLine);
id++;
}
msg(noteList.toString());
return true;
}
id--;
if (playerData.removeNote(id))
{
case "add":
if (args.length < 3)
{
return false;
}
String note = sender.getName() + ": " + StringUtils.join(ArrayUtils.subarray(args, 2, args.length), " ");
playerData.addNote(note);
plugin.pl.save(playerData);
msg("Note removed.");
}
else
msg("Note added.", ChatColor.GREEN);
return true;
case "remove":
{
msg("No note with the ID of " + args[2] + " exists.", ChatColor.RED);
if (args.length < 3)
{
return false;
}
int id;
try
{
id = Integer.parseInt(args[2]);
}
catch (NumberFormatException e)
{
msg("Invalid number: " + args[2], ChatColor.RED);
return true;
}
id--;
if (playerData.removeNote(id))
{
plugin.pl.save(playerData);
msg("Note removed.");
}
else
{
msg("No note with the ID of " + args[2] + " exists.", ChatColor.RED);
}
return true;
}
case "clear":
{
int count = playerData.getNotes().size();
playerData.clearNotes();
plugin.pl.save(playerData);
msg("Cleared " + count + " notes.", ChatColor.GREEN);
return true;
}
default:
{
return false;
}
return true;
}
else if (args[1].equals("clear"))
{
int count = playerData.getNotes().size();
playerData.clearNotes();
plugin.pl.save(playerData);
msg("Cleared " + count + " notes.", ChatColor.GREEN);
return true;
}
return false;
}
@Override

View file

@ -117,27 +117,6 @@ public class ItemFun extends FreedomService
player.sendMessage("Stacked " + entity.getName());
}
}
if (player.getInventory().getItemInMainHand().getType().equals(Material.BONE) || entity.getType().equals(EntityType.PLAYER))
{
if (!fPlayer.mobThrowerEnabled())
{
return;
}
Location playerLoc = player.getLocation();
Vector direction = playerLoc.getDirection().normalize();
LivingEntity livingEntity = (LivingEntity)event.getRightClicked();
EntityType entityType = livingEntity.getType();
if (!(entityType == fPlayer.mobThrowerCreature()))
{
return;
}
livingEntity.setVelocity(direction.multiply(fPlayer.mobThrowerSpeed()));
fPlayer.enqueueMob(livingEntity);
}
}
@EventHandler(priority = EventPriority.MONITOR)

View file

@ -46,10 +46,6 @@ public class FPlayer
private final CageData cageData = new CageData(this);
private boolean isOrbiting = false;
private double orbitStrength = 10.0;
private boolean mobThrowerEnabled = false;
private EntityType mobThrowerEntity = EntityType.PIG;
private double mobThrowerSpeed = 4.0;
private final List<LivingEntity> mobThrowerQueue = new ArrayList<>();
private BukkitTask lockupScheduleTask = null;
private boolean lockedUp = false;
private String lastMessage = "";
@ -192,46 +188,6 @@ public class FPlayer
this.freecamPlaceCount = 0;
}
public void enableMobThrower(EntityType mobThrowerCreature, double mobThrowerSpeed)
{
this.mobThrowerEnabled = true;
this.mobThrowerEntity = mobThrowerCreature;
this.mobThrowerSpeed = mobThrowerSpeed;
}
public void disableMobThrower()
{
this.mobThrowerEnabled = false;
}
public EntityType mobThrowerCreature()
{
return this.mobThrowerEntity;
}
public double mobThrowerSpeed()
{
return this.mobThrowerSpeed;
}
public boolean mobThrowerEnabled()
{
return this.mobThrowerEnabled;
}
public void enqueueMob(LivingEntity mob)
{
mobThrowerQueue.add(mob);
if (mobThrowerQueue.size() > 4)
{
LivingEntity oldmob = mobThrowerQueue.remove(0);
if (oldmob != null)
{
oldmob.damage(500.0);
}
}
}
public boolean isMuted()
{
return unmuteTask != null;

View file

@ -17,7 +17,6 @@ import me.totalfreedom.totalfreedommod.util.FUtil;
public class SQLite extends FreedomService
{
private final String FILE_NAME = "database.db";
private Connection connection;
@Override
@ -93,7 +92,7 @@ public class SQLite extends FreedomService
{
try
{
connection.createStatement().execute("CREATE TABLE `players` (`username` VARCHAR NOT NULL, `ips` VARCHAR NOT NULL, `notes` VARCHAR, `tag` VARCHAR, `discord_id` VARCHAR, `backup_codes` VARCHAR, `donator` BOOLEAN NOT NULL, `master_builder` BOOLEAN NOT NULL,`verification` BOOLEAN NOT NULL, `ride_mode` VARCHAR NOT NULL, `coins` INT, `items` VARCHAR, `total_votes` INT NOT NULL, `display_discord` BOOLEAN NOT NULL, `login_message` VARCHAR);");
connection.createStatement().execute("CREATE TABLE `players` (`username` VARCHAR NOT NULL, `ips` VARCHAR NOT NULL, `notes` VARCHAR, `tag` VARCHAR, `discord_id` VARCHAR, `backup_codes` VARCHAR, `master_builder` BOOLEAN NOT NULL,`verification` BOOLEAN NOT NULL, `ride_mode` VARCHAR NOT NULL, `coins` INT, `items` VARCHAR, `total_votes` INT NOT NULL, `display_discord` BOOLEAN NOT NULL, `login_message` VARCHAR);");
}
catch (SQLException e)
{
@ -247,16 +246,16 @@ public class SQLite extends FreedomService
{
try
{
PreparedStatement statement = connection.prepareStatement("INSERT INTO admins VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
PreparedStatement statement = connection.prepareStatement("INSERT INTO admins VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
statement.setString(1, admin.getName());
statement.setString(2, FUtil.listToString(admin.getIps()));
statement.setString(3, admin.getRank().toString());
statement.setBoolean(4, admin.isActive());
statement.setLong(5, admin.getLastLogin().getTime());
statement.setBoolean(7, admin.getCommandSpy());
statement.setBoolean(8, admin.getPotionSpy());
statement.setString(9, admin.getAcFormat());
statement.setString(10, admin.getPteroID());
statement.setBoolean(6, admin.getCommandSpy());
statement.setBoolean(7, admin.getPotionSpy());
statement.setString(8, admin.getAcFormat());
statement.setString(9, admin.getPteroID());
statement.executeUpdate();
}
catch (SQLException e)
@ -270,7 +269,7 @@ public class SQLite extends FreedomService
{
try
{
PreparedStatement statement = connection.prepareStatement("INSERT INTO players VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
PreparedStatement statement = connection.prepareStatement("INSERT INTO players VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
statement.setString(1, player.getName());
statement.setString(2, FUtil.listToString(player.getIps()));
statement.setString(3, FUtil.listToString(player.getNotes()));
@ -281,10 +280,10 @@ public class SQLite extends FreedomService
statement.setBoolean(8, player.hasVerification());
statement.setString(9, player.getRideMode());
statement.setInt(10, player.getCoins());
statement.setString(12, FUtil.listToString(player.getItems()));
statement.setInt(13, player.getTotalVotes());
statement.setBoolean(14, player.doesDisplayDiscord());
statement.setString(15, player.getLoginMessage());
statement.setString(11, FUtil.listToString(player.getItems()));
statement.setInt(12, player.getTotalVotes());
statement.setBoolean(13, player.doesDisplayDiscord());
statement.setString(14, player.getLoginMessage());
statement.executeUpdate();
}
catch (SQLException e)

View file

@ -12,7 +12,6 @@ softdepend:
- WorldGuardExtraFlags
- TFGuilds
- JDA
- JRAW
- Votifier
authors: [Madgeek1450, Prozza]
api-version: "1.16"