Skip to content
This repository has been archived by the owner on Mar 8, 2022. It is now read-only.

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Librazy committed Mar 23, 2019
1 parent 9e67816 commit db44ec0
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/main/java/cat/nyaa/nyaautils/NyaaUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void onEnable() {
mentionListener = new MentionListener(this);
messageQueueListener = new MessageQueue(this);
NyaaComponent.register(IMessageQueue.class, messageQueueListener);
redstoneControlListener = new cat.nyaa.nyaautils.redstonecontrol.RedstoneControlListener(this);
redstoneControlListener = new RedstoneControlListener(this);
sitListener = new SitListener(this);
extraBackpackListener = new ExtraBackpackListener(this);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
Expand All @@ -41,12 +42,17 @@ public String getHelpPrefix() {

@Override
public void acceptCommand(CommandSender sender, Arguments cmd) {
if (!plugin.cfg.bp_enable) {
return;
}
String subCommand = cmd.top();
if (subCommand == null) subCommand = "";
if (subCommand.length() > 0) {
super.acceptCommand(sender, cmd);
} else {
open(sender, cmd);
if (sender.hasPermission("nu.bp.use")) {
open(sender, cmd);
}
}
}

Expand Down Expand Up @@ -88,6 +94,9 @@ public void setBackpackLine(CommandSender sender, Arguments args) {
asPlayer(sender);
UUID ownerId = player.getUniqueId();
int maxLine = args.nextInt();
if (maxLine > plugin.cfg.bp_max_lines) {
maxLine = plugin.cfg.bp_max_lines;
}
if (ExtraBackpackGUI.isOpened(ownerId)) {
msg(sender, "user.backpack.already_opened");
return;
Expand All @@ -112,6 +121,7 @@ public void setBackpackLine(CommandSender sender, Arguments args) {
if (maxLine < oldMax) {
deleteLines(asPlayer(sender), ownerId, maxLine, oldMax);
}
msg(sender, "user.backpack.n_lines", player.getName(), maxLine);
}

private void deleteLines(Player sender, UUID ownerId, int from, int to) {
Expand Down Expand Up @@ -142,20 +152,30 @@ public void addBackpackLine(CommandSender sender, Arguments args) {
msg(sender, "user.backpack.already_opened");
return;
}
int maxLine;
try (Query<ExtraBackpackConfig> query = database.queryTransactional(ExtraBackpackConfig.class).whereEq("player_id", ownerId.toString())) {
ExtraBackpackConfig cfg = query.selectUniqueForUpdate();
if (cfg != null) {
cfg.setMaxLine(cfg.getMaxLine() + addLine);
maxLine = cfg.getMaxLine() + addLine;
if (maxLine > plugin.cfg.bp_max_lines) {
maxLine = plugin.cfg.bp_max_lines;
}
cfg.setMaxLine(maxLine);
query.update(cfg);
query.commit();
} else {
cfg = new ExtraBackpackConfig();
cfg.setPlayerId(ownerId.toString());
cfg.setMaxLine(plugin.cfg.bp_default_lines + addLine);
maxLine = plugin.cfg.bp_default_lines + addLine;
if (maxLine > plugin.cfg.bp_max_lines) {
maxLine = plugin.cfg.bp_max_lines;
}
cfg.setMaxLine(maxLine);
query.insert(cfg);
query.commit();
}
}
msg(sender, "user.backpack.n_lines", maxLine);
}

@SubCommand(value = "open", permission = "nu.bp.use")
Expand Down Expand Up @@ -186,8 +206,8 @@ private void open(CommandSender commandSender, Arguments args) {
).collect(Collectors.toList());
boolean match = nearbyBlock.parallelStream().anyMatch(loc -> loc.getBlock().getType() == plugin.cfg.bp_require_nearby_block);
if (!match) {
new Message(I18n.format("user.backpack.no_required_block"))
.append(LocaleUtils.getNameComponent(new ItemStack(plugin.cfg.bp_require_nearby_block)))
new Message("")
.append(I18n.format("user.backpack.no_required_block", plugin.cfg.bp_require_nearby_distance), Collections.singletonMap("{block}", LocaleUtils.getNameComponent(new ItemStack(plugin.cfg.bp_require_nearby_block))))
.send(sender);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public class ExtraBackpackListener implements Listener {

public ExtraBackpackListener(NyaaUtils plugin) {
this.plugin = plugin;
if (!plugin.cfg.bp_enable) {
return;
}
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/lang/en_US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ user:
error_saving: Error saving backpack. Please concat operators for help.
error_state: 'Backpack of %s line %d failed to save when opened by %s'
disabled: Current backpack is disabled
n_lines: 'Backpack of %s set to %d lines'
no_required_blocks: 'There are no {block} in %d blocks'
manual:
help:
description: Show help message
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/lang/zh_CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,8 @@ user:
error_saving: 背包保存失败。请联系管理员获取帮助。
error_state: '%s 的背包第 %d 行保存失败(由 %s 打开)。'
disabled: 当前背包已被禁用
n_lines: '%s 的背包设为 %d 行'
no_required_blocks: '%d格范围内没有{block}'
manual:
help:
description: 显示帮助信息
Expand Down
8 changes: 7 additions & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,10 @@ permissions:
default: true
nu.tpall:
description: teleport all players to you
default: op
default: op
nu.bp.use:
description: use extra backpack
default: op
nu.bp.admin:
description: admin extra backpack
default: op

0 comments on commit db44ec0

Please sign in to comment.