-
-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added ExtraValueCommand #424
Changes from all commits
7105ce1
e73b658
f8b8ea7
95fccc9
0f65ef6
e82b083
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package com.iridium.iridiumskyblock.commands; | ||
|
||
import com.iridium.iridiumcore.utils.StringUtils; | ||
import com.iridium.iridiumskyblock.IridiumSkyblock; | ||
import com.iridium.iridiumskyblock.database.Island; | ||
import com.iridium.iridiumskyblock.database.User; | ||
import com.iridium.iridiumskyblock.utils.PlayerUtils; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
|
||
import java.time.Duration; | ||
import java.util.*; | ||
|
||
public class ExtraValueCommand extends Command { | ||
|
||
/** | ||
* The default constructor. | ||
*/ | ||
public ExtraValueCommand() { | ||
super(Collections.singletonList("extravalue"), "Set extra values of island", "%prefix% &7/is extravalue <add/remove/set> <player> <amount>", "iridiumskyblock.extravalue", false, Duration.ZERO); | ||
} | ||
|
||
/** | ||
* Executes the command for the specified {@link CommandSender} with the provided arguments. | ||
* Not called when the command execution was invalid (no permission, no player or command disabled). | ||
* Gives extra values to specific player's island | ||
* | ||
* @param sender The CommandSender which executes this command | ||
* @param args The arguments used with this command. They contain the sub-command | ||
*/ | ||
@Override | ||
public boolean execute(CommandSender sender, String[] args) { | ||
if (args.length < 4) { | ||
sender.sendMessage(StringUtils.color(syntax.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); | ||
return false; | ||
} | ||
|
||
Player player = Bukkit.getPlayer(args[2]); | ||
if (player != null) { | ||
User user = IridiumSkyblock.getInstance().getUserManager().getUser(player); | ||
Optional<Island> island = user.getIsland(); | ||
if (island.isPresent()) { | ||
try { | ||
double amount = Double.parseDouble(args[3]); | ||
switch (args[1].toUpperCase(Locale.ENGLISH)) { | ||
case "ADD": | ||
island.get().setExtraValue(island.get().getExtraValue() + amount); | ||
break; | ||
case "REMOVE": | ||
island.get().setExtraValue(island.get().getExtraValue() - amount); | ||
break; | ||
case "SET": | ||
island.get().setExtraValue(amount); | ||
break; | ||
default: | ||
sender.sendMessage(StringUtils.color(syntax.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); | ||
return false; | ||
|
||
} | ||
sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().setExtraValue.replace("%player%", player.getName()).replace("%amount%", String.valueOf(island.get().getExtraValue())).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); | ||
return true; | ||
} catch (NumberFormatException e) { | ||
sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notANumber.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); | ||
} | ||
} else { | ||
sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().userNoIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); | ||
} | ||
} else { | ||
sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notAPlayer.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Handles tab-completion for this command. | ||
* | ||
* @param commandSender The CommandSender which tries to tab-complete | ||
* @param command The command | ||
* @param label The label of the command | ||
* @param args The arguments already provided by the sender | ||
* @return The list of tab completions for this command | ||
*/ | ||
@Override | ||
public List<String> onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { | ||
if (args.length == 3) { | ||
return PlayerUtils.getOnlinePlayerNames(); | ||
} | ||
|
||
if (args.length == 2) { | ||
return Arrays.asList("add", "remove", "set"); | ||
} | ||
|
||
return Collections.emptyList(); | ||
} | ||
dlsf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,4 @@ CREATE UNIQUE INDEX island_rewards_id_island_id_uindex ON island_rewards (id, is | |
CREATE UNIQUE INDEX island_spawners_id_spawner_type_island_id_uindex ON island_spawners (id, spawner_type, island_id); | ||
CREATE UNIQUE INDEX island_trusted_id_user_island_id_uindex ON island_trusted (id, user, island_id); | ||
CREATE UNIQUE INDEX island_upgrade_id_upgrade_island_id_uindex ON island_upgrade (id, upgrade, island_id); | ||
CREATE UNIQUE INDEX island_warps_id_name_island_id_uindex ON island_warps (id, name, island_id); | ||
CREATE UNIQUE INDEX island_warps_id_name_island_id_uindex ON island_warps (id, name, island_id); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whats this aswell? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need more newlines |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
ALTER TABLE islands MODIFY name VARCHAR(512) NULL | ||
ALTER TABLE islands MODIFY name VARCHAR(512) NULL | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whats this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did it, just added a newline because they are important |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE islands ADD COLUMN extra_value DOUBLE PRECISION; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldnt this be called _mysql? and where is the sqllite version? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It works for both MySQL and SQLite. The two different patches for MySQL and SQLite are optional There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SQLite doenst have the ALTER TABLE stuff though does it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and why we had to do this mess for island names? CREATE TEMPORARY TABLE islands_backup(id, name, home, visit, create_time, experience, color);
INSERT INTO islands_backup SELECT id, name, home, visit, create_time, experience, color FROM islands;
DROP TABLE islands;
CREATE TABLE islands(`id` INTEGER PRIMARY KEY AUTOINCREMENT , `name` VARCHAR , `home` VARCHAR , `visit` BOOLEAN , `create_time` BIGINT , `experience` INTEGER , `color` VARCHAR NOT NULL , UNIQUE (`name`));
INSERT INTO islands SELECT id, name, home, visit, create_time, experience, color FROM islands_backup;
DROP TABLE islands_backup; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because creating tables works differently, I guess? The syntax checker said it's not possible There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Im confused? We are adding a new collum into the table, ALTER TABLE keyword doesnt work for sqllite, and I just tested it, this doesnt work. We need to do what we did for IslandNames There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SQLite also has certain |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use SubCommands
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind, thats dum
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was about to say the same... But I don't know, it would be a very small subcommand.
I can do a subcommand PR soon that adds subcommands for the other commands too.