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

Commit

Permalink
update to 1.13.2 & use args.nextOfflinePlayer
Browse files Browse the repository at this point in the history
  • Loading branch information
cyilin committed Oct 26, 2018
1 parent 834fbcd commit 1dd5e1d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 61 deletions.
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ configurations.all {
// Note the spaces before and after the equals sign
ext.majorVersion = 6
ext.minorVersion = 1
ext.minecraftVersion = "1.13.1"
ext.minecraftVersion = "1.13.2"

sourceCompatibility = 1.8
targetCompatibility = 1.8
Expand Down Expand Up @@ -51,11 +51,11 @@ repositories {
}

dependencies {
compile 'org.spigotmc:spigot-api:1.13.1-R0.1-SNAPSHOT'
compile 'org.spigotmc:spigot-api:1.13.2-R0.1-SNAPSHOT'
if (gradle.hasProperty("useLocalDependencies") && gradle.useLocalDependencies) {
compile project(":NyaaCore")
} else {
compile('cat.nyaa:nyaacore:6.2-SNAPSHOT') {
compile('cat.nyaa:nyaacore:6.3-SNAPSHOT') {
transitive = false
}
}
Expand All @@ -64,6 +64,7 @@ dependencies {
compile ('com.sk89q.worldedit:worldedit-bukkit:7.0.0-SNAPSHOT') {
exclude group: 'io.papermc', module: 'paperlib'
exclude group: 'org.bstats.bStats-Metrics', module: 'bstats-bukkit'
exclude group: 'org.bukkit', module: 'bukkit'
}
compile 'org.librazy:NyaaUtilsLangChecker:2.0-SNAPSHOT'
annotationProcessor 'org.librazy:NyaaUtilsLangChecker:2.0-SNAPSHOT'
Expand Down
92 changes: 42 additions & 50 deletions src/main/java/cat/nyaa/nyaautils/mailbox/MailboxCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@
public class MailboxCommands extends CommandReceiver {
private final NyaaUtils plugin;

@Override
public String getHelpPrefix() {
return "mailbox";
}

public MailboxCommands(Object plugin, LanguageRepository i18n) {
super((NyaaUtils) plugin, i18n);
this.plugin = (NyaaUtils) plugin;
}

@Override
public String getHelpPrefix() {
return "mailbox";
}

@SubCommand(value = "create", permission = "nu.mailbox")
public void createMailbox(CommandSender sender, Arguments args) {
Player p = asPlayer(sender);
String tmp = args.top();
if (tmp != null) {
if (sender.hasPermission("nu.mailadmin")) {
createMailbox(p, tmp);
createMailbox(p, args.nextOfflinePlayer());
} else {
msg(sender, "user.mailbox.permission_required");
}
Expand All @@ -61,22 +61,20 @@ public void createMailbox(CommandSender sender, Arguments args) {
msg(p, "user.mailbox.now_right_click");
}

@SuppressWarnings("deprecation")
public void createMailbox(Player admin, String player) {
if (plugin.cfg.mailbox.getMailboxLocation(player) != null) {
public void createMailbox(Player admin, OfflinePlayer player) {
UUID id = player.getUniqueId();
if (plugin.cfg.mailbox.getMailboxLocation(id) != null) {
msg(admin, "user.mailbox.admin.already_set");
return;
}
OfflinePlayer p = plugin.getServer().getOfflinePlayer(player);
UUID id = p.getUniqueId();
plugin.mailboxListener.registerRightClickCallback(admin, 100,
(Location clickedBlock) -> {
Block b = clickedBlock.getBlock();
if (b.getState() instanceof Chest) {
plugin.cfg.mailbox.updateNameMapping(id, player);
plugin.cfg.mailbox.updateNameMapping(id, player.getName());
plugin.cfg.mailbox.updateLocationMapping(id, b.getLocation());
msg(admin, "user.mailbox.admin.success_set");
if (p.isOnline()) {
if (player.isOnline()) {
Player tmp = plugin.getServer().getPlayer(id);
if (tmp != null) {
msg(tmp, "user.mailbox.admin.player_hint_set");
Expand All @@ -95,7 +93,7 @@ public void removeMailbox(CommandSender sender, Arguments args) {
String tmp = args.top();
if (tmp != null) {
if (sender.hasPermission("nu.mailadmin")) {
removeMailbox(p, tmp);
removeMailbox(p, args.nextOfflinePlayer());
} else {
msg(sender, "user.mailbox.permission_required");
}
Expand All @@ -109,16 +107,15 @@ public void removeMailbox(CommandSender sender, Arguments args) {
msg(p, "user.mailbox.remove_success");
}

public void removeMailbox(Player admin, String player) {
if (plugin.cfg.mailbox.getMailboxLocation(player) == null) {
public void removeMailbox(Player admin, OfflinePlayer player) {
if (plugin.cfg.mailbox.getMailboxLocation(player.getUniqueId()) == null) {
msg(admin, "user.mailbox.admin.no_mailbox");
} else {
UUID id = plugin.cfg.mailbox.getUUIDbyName(player);
UUID id = player.getUniqueId();
plugin.cfg.mailbox.updateLocationMapping(id, null);
msg(admin, "user.mailbox.admin.success_remove");
Player p = plugin.getServer().getPlayer(player);
if (p != null) {
msg(p, "user.mailbox.admin.player_hint_removed");
if (player.isOnline()) {
msg((Player) player, "user.mailbox.admin.player_hint_removed");
}
}
}
Expand All @@ -128,7 +125,7 @@ public void infoMailbox(CommandSender sender, Arguments args) {
String tmp = args.top();
if (tmp != null) {
if (sender.hasPermission("nu.mailadmin")) {
infoMailbox(sender, tmp);
infoMailbox(sender, args.nextOfflinePlayer());
} else {
msg(sender, "user.mailbox.permission_required");
}
Expand All @@ -149,23 +146,21 @@ public void infoMailbox(CommandSender sender, Arguments args) {
}
}

public void infoMailbox(CommandSender admin, String player) {
Location loc = plugin.cfg.mailbox.getMailboxLocation(player);
public void infoMailbox(CommandSender admin, OfflinePlayer player) {
Location loc = plugin.cfg.mailbox.getMailboxLocation(player.getUniqueId());
if (loc != null) {
msg(admin, "user.mailbox.admin.info", player, plugin.cfg.mailbox.getUUIDbyName(player).toString(),
msg(admin, "user.mailbox.admin.info", player.getName(), player.getUniqueId().toString(),
loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
} else {
msg(admin, "user.mailbox.admin.no_mailbox");
}
}


@SubCommand(value = "send", permission = "nu.mailbox")
public void sendMailbox(CommandSender sender, Arguments args) {
Player p = asPlayer(sender);
ItemStack stack = getItemInHand(sender);
String toPlayer = args.next();
if (toPlayer == null) {
if (args.top() == null) {
msg(sender, "manual.mailbox.send.usage");
return;
}
Expand All @@ -174,8 +169,8 @@ public void sendMailbox(CommandSender sender, Arguments args) {
msg(p, "user.mailbox.money_insufficient");
return;
}

UUID recipient = plugin.cfg.mailbox.getUUIDbyName(toPlayer);
OfflinePlayer toPlayer = args.nextOfflinePlayer();
UUID recipient = toPlayer.getUniqueId();
Location toLocation = plugin.cfg.mailbox.getMailboxLocation(recipient);

// Check remote mailbox
Expand All @@ -188,19 +183,18 @@ public void sendMailbox(CommandSender sender, Arguments args) {
}

if (recipient == null) {
msg(sender, "user.mailbox.player_no_mailbox", toPlayer);
msg(sender, "user.mailbox.player_no_mailbox", toPlayer.getName());
return;
} else if (toLocation == null) {
msg(sender, "user.mailbox.player_no_mailbox", toPlayer);
Player tmp = plugin.getServer().getPlayer(toPlayer);
if (tmp != null && tmp.isOnline()) {
msg(tmp, "user.mailbox.create_mailbox_hint", sender.getName());
msg(sender, "user.mailbox.player_no_mailbox", toPlayer.getName());
if (toPlayer.isOnline()) {
msg((Player) toPlayer, "user.mailbox.create_mailbox_hint", sender.getName());
}
return;
}

Player recp = plugin.getServer().getPlayer(toPlayer);
if (recp != null && !recp.isOnline()) recp = null;
Player recp = null;
if (toPlayer.isOnline()) recp = (Player) toPlayer;
Inventory targetInventory = ((InventoryHolder) toLocation.getBlock().getState()).getInventory();
if (!InventoryUtils.hasEnoughSpace(targetInventory, stack)) {
msg(sender, "user.mailbox.recipient_no_space");
Expand All @@ -213,7 +207,7 @@ public void sendMailbox(CommandSender sender, Arguments args) {
}
InventoryUtils.addItem(targetInventory, stack);
p.getInventory().setItemInMainHand(new ItemStack(Material.AIR));
msg(sender, "user.mailbox.mail_sent", toPlayer, (float) plugin.cfg.mailHandFee);
msg(sender, "user.mailbox.mail_sent", toPlayer.getName(), (float) plugin.cfg.mailHandFee);
if (recp != null) {
msg(recp, "user.mailbox.mail_received", sender.getName());
}
Expand All @@ -224,8 +218,7 @@ public void sendMailbox(CommandSender sender, Arguments args) {
@SubCommand(value = "sendchest", permission = "nu.mailbox")
public void sendBoxMailbox(CommandSender sender, Arguments args) {
Player p = asPlayer(sender);
String toPlayer = args.next();
if (toPlayer == null) {
if (args.top() == null) {
msg(sender, "manual.mailbox.sendchest.usage");
return;
}
Expand All @@ -234,8 +227,8 @@ public void sendBoxMailbox(CommandSender sender, Arguments args) {
msg(p, "user.mailbox.money_insufficient");
return;
}

UUID recipient = plugin.cfg.mailbox.getUUIDbyName(toPlayer);
OfflinePlayer toPlayer = args.nextOfflinePlayer();
UUID recipient = toPlayer.getUniqueId();
Location toLocation = plugin.cfg.mailbox.getMailboxLocation(recipient);

// Check remote mailbox
Expand All @@ -248,20 +241,19 @@ public void sendBoxMailbox(CommandSender sender, Arguments args) {
}

if (recipient == null) {
msg(sender, "user.mailbox.player_no_mailbox", toPlayer);
msg(sender, "user.mailbox.player_no_mailbox", toPlayer.getName());
return;
} else if (toLocation == null) {
msg(sender, "user.mailbox.player_no_mailbox", toPlayer);
Player tmp = plugin.getServer().getPlayer(toPlayer);
if (tmp != null && tmp.isOnline()) {
msg(tmp, "user.mailbox.create_mailbox_hint", sender.getName());
msg(sender, "user.mailbox.player_no_mailbox", toPlayer.getName());
if (toPlayer.isOnline()) {
msg((Player) toPlayer, "user.mailbox.create_mailbox_hint", sender.getName());
}
return;
}

final Location toLocationFinal = toLocation;
Player recp = plugin.getServer().getPlayer(toPlayer);
if (recp != null && !recp.isOnline()) recp = null;
Player recp = null;
if (toPlayer.isOnline()) recp = (Player) toPlayer;
final Player recpFinal = recp;

plugin.mailboxListener.registerRightClickCallback(p, 100,
Expand Down Expand Up @@ -309,7 +301,7 @@ public void sendBoxMailbox(CommandSender sender, Arguments args) {
plugin.systemBalance.deposit(plugin.cfg.mailChestFee, plugin);
}
toInventory.setStorageContents(to);
msg(sender, "user.mailbox.mail_sent", toPlayer, (float) plugin.cfg.mailChestFee);
msg(sender, "user.mailbox.mail_sent", toPlayer.getName(), (float) plugin.cfg.mailChestFee);
if (recpFinal != null) {
msg(recpFinal, "user.mailbox.mail_received", sender.getName());
}
Expand All @@ -318,6 +310,6 @@ public void sendBoxMailbox(CommandSender sender, Arguments args) {
msg(sender, "user.mailbox.mail_sent_nothing");
}
});
msg(p, "user.mailbox.now_right_click_send", toPlayer);
msg(p, "user.mailbox.now_right_click_send", toPlayer.getName());
}
}
9 changes: 1 addition & 8 deletions src/main/java/cat/nyaa/nyaautils/realm/RealmCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.regions.Region;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
Expand All @@ -27,7 +26,6 @@ public String getHelpPrefix() {
return "realm";
}

@SuppressWarnings("deprecation")
@SubCommand(value = "create", permission = "nu.realm.admin")
public void commandCreate(CommandSender sender, Arguments args) throws IncompleteRegionException {
if (args.length() < 4) {
Expand All @@ -52,12 +50,7 @@ public void commandCreate(CommandSender sender, Arguments args) throws Incomplet
OfflinePlayer owner = null;
if (realmType == RealmType.PRIVATE) {
if (args.length() == 5) {
String playerName = args.next();
owner = Bukkit.getOfflinePlayer(playerName);
if (owner == null) {
msg(sender, "internal.error.player_not_found", playerName);
return;
}
owner = args.nextOfflinePlayer();
} else {
msg(sender, "manual.realm.create.usage");
return;
Expand Down

0 comments on commit 1dd5e1d

Please sign in to comment.