-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "/text playback" to edit playback time
- Loading branch information
Showing
7 changed files
with
99 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/main/java/fr/skytasul/citizenstext/command/ArgumentTextPlaybackTime.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package fr.skytasul.citizenstext.command; | ||
|
||
import org.bukkit.ChatColor; | ||
import org.bukkit.command.CommandSender; | ||
|
||
import fr.skytasul.citizenstext.options.OptionPlaybackTime; | ||
import fr.skytasul.citizenstext.options.OptionRepeat; | ||
|
||
public class ArgumentTextPlaybackTime extends TextCommandArgument<OptionPlaybackTime> { | ||
|
||
public ArgumentTextPlaybackTime() { | ||
super("playback", "playback", OptionPlaybackTime.class); | ||
} | ||
|
||
@Override | ||
public boolean createTextInstance() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean onCommand(CommandSender sender, String[] args, OptionPlaybackTime option) { | ||
if (!option.getTextInstance().getOption(OptionRepeat.class).getOrDefault()) { | ||
sender.sendMessage("The \"no repeat\" option is enabled. You must first disable it using \"\text repeat\" before editing the playback time."); | ||
return false; | ||
} | ||
Integer oldTime = option.getValue(); | ||
if (args.length == 0) { | ||
if (oldTime == null) { | ||
sender.sendMessage("§cNo custom playback time was set. Default value: " + option.getDefault()); | ||
return false; | ||
} | ||
option.setValue(null); | ||
sender.sendMessage("§aCustom playback time removed. (old: \"" + oldTime + "§r§a\")"); | ||
}else { | ||
try { | ||
int time = Integer.parseInt(args[0]); | ||
if (time < 0) { | ||
sender.sendMessage(ChatColor.RED + args[0] + " is not a valid number. (must be positive)"); | ||
return false; | ||
} | ||
option.setValue(time); | ||
sender.sendMessage("§aCustom playback time set to " + time + " seconds. (old: \"" + oldTime + "§r§a\")"); | ||
}catch (IllegalArgumentException ex) { | ||
sender.sendMessage(ChatColor.RED + "\"" + args[0] + "\" is not a valid number."); | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public String getHelpString() { | ||
return super.getHelpString() + " <time in seconds> : Set the time before players can restart the conversation"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/fr/skytasul/citizenstext/options/OptionPlaybackTime.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package fr.skytasul.citizenstext.options; | ||
|
||
import org.bukkit.configuration.ConfigurationSection; | ||
|
||
import fr.skytasul.citizenstext.CitizensTextConfiguration; | ||
import fr.skytasul.citizenstext.texts.TextInstance; | ||
|
||
public class OptionPlaybackTime extends TextOption<Integer> { | ||
|
||
public OptionPlaybackTime(TextInstance txt) { | ||
super(txt); | ||
} | ||
|
||
@Override | ||
public Integer getDefault() { | ||
return CitizensTextConfiguration.getTimeToPlayback(); | ||
} | ||
|
||
@Override | ||
protected void saveValue(ConfigurationSection config, String key) { | ||
config.set(key, getValue()); | ||
} | ||
|
||
@Override | ||
protected Integer loadValue(ConfigurationSection config, String key) { | ||
return config.getInt(key); | ||
} | ||
|
||
@Override | ||
public void setDefaultValue() {} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters