Skip to content

Commit 90e7757

Browse files
committed
fix bugs
1 parent ff2cdaa commit 90e7757

27 files changed

Lines changed: 244 additions & 74 deletions
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright (C) <2022> <XiaoMoMi>
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
package net.momirealms.customfishing.api.event;
19+
20+
import org.bukkit.entity.Player;
21+
import org.bukkit.event.Cancellable;
22+
import org.bukkit.event.HandlerList;
23+
import org.bukkit.event.player.PlayerEvent;
24+
import org.bukkit.inventory.Inventory;
25+
import org.bukkit.inventory.ItemStack;
26+
import org.jetbrains.annotations.NotNull;
27+
28+
public class FishingBagPreCollectEvent extends PlayerEvent implements Cancellable {
29+
30+
private static final HandlerList handlerList = new HandlerList();
31+
private final ItemStack itemStack;
32+
private boolean isCancelled;
33+
private final Inventory bag;
34+
35+
public FishingBagPreCollectEvent(@NotNull Player who, ItemStack itemStack, Inventory bag) {
36+
super(who);
37+
this.itemStack = itemStack;
38+
this.isCancelled = false;
39+
this.bag = bag;
40+
}
41+
42+
@Override
43+
public boolean isCancelled() {
44+
return isCancelled;
45+
}
46+
47+
@Override
48+
public void setCancelled(boolean cancel) {
49+
isCancelled = cancel;
50+
}
51+
52+
public ItemStack getItemStack() {
53+
return itemStack;
54+
}
55+
56+
@Override
57+
public @NotNull HandlerList getHandlers() {
58+
return handlerList;
59+
}
60+
61+
public static HandlerList getHandlerList() {
62+
return handlerList;
63+
}
64+
65+
public Inventory getBagInventory() {
66+
return bag;
67+
}
68+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright (C) <2022> <XiaoMoMi>
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
package net.momirealms.customfishing.api.event;
19+
20+
import org.bukkit.Location;
21+
import org.bukkit.entity.Player;
22+
import org.bukkit.event.Cancellable;
23+
import org.bukkit.event.HandlerList;
24+
import org.bukkit.event.player.PlayerEvent;
25+
import org.bukkit.inventory.ItemStack;
26+
import org.jetbrains.annotations.NotNull;
27+
28+
public class FishingLootPreSpawnEvent extends PlayerEvent implements Cancellable {
29+
30+
private static final HandlerList handlerList = new HandlerList();
31+
private final Location location;
32+
private final ItemStack itemStack;
33+
private boolean isCancelled;
34+
35+
public FishingLootPreSpawnEvent(@NotNull Player who, Location location, ItemStack itemStack) {
36+
super(who);
37+
this.itemStack = itemStack;
38+
this.location = location;
39+
this.isCancelled = false;
40+
}
41+
42+
@Override
43+
public boolean isCancelled() {
44+
return isCancelled;
45+
}
46+
47+
@Override
48+
public void setCancelled(boolean cancel) {
49+
isCancelled = cancel;
50+
}
51+
52+
public Location getLocation() {
53+
return location;
54+
}
55+
56+
public ItemStack getItemStack() {
57+
return itemStack;
58+
}
59+
60+
@Override
61+
public @NotNull HandlerList getHandlers() {
62+
return handlerList;
63+
}
64+
65+
public static HandlerList getHandlerList() {
66+
return handlerList;
67+
}
68+
}

api/src/main/java/net/momirealms/customfishing/api/event/FishingLootSpawnEvent.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,23 @@
1818
package net.momirealms.customfishing.api.event;
1919

2020
import org.bukkit.Location;
21+
import org.bukkit.entity.Item;
2122
import org.bukkit.entity.Player;
2223
import org.bukkit.event.Cancellable;
2324
import org.bukkit.event.HandlerList;
2425
import org.bukkit.event.player.PlayerEvent;
25-
import org.bukkit.inventory.ItemStack;
2626
import org.jetbrains.annotations.NotNull;
2727

2828
public class FishingLootSpawnEvent extends PlayerEvent implements Cancellable {
2929

3030
private static final HandlerList handlerList = new HandlerList();
3131
private final Location location;
32-
private final ItemStack itemStack;
32+
private final Item item;
3333
private boolean isCancelled;
3434

35-
public FishingLootSpawnEvent(@NotNull Player who, Location location, ItemStack itemStack) {
35+
public FishingLootSpawnEvent(@NotNull Player who, Location location, Item item) {
3636
super(who);
37-
this.itemStack = itemStack;
37+
this.item = item;
3838
this.location = location;
3939
this.isCancelled = false;
4040
}
@@ -53,8 +53,8 @@ public Location getLocation() {
5353
return location;
5454
}
5555

56-
public ItemStack getItemStack() {
57-
return itemStack;
56+
public Item getItem() {
57+
return item;
5858
}
5959

6060
@Override

api/src/main/java/net/momirealms/customfishing/api/event/FishingResultEvent.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ public Loot getLoot() {
127127
}
128128

129129
/**
130-
* Gets the amount of loot received
130+
* Gets the amount of loot received.
131+
* This value is determined by the "multiple-loot" effect.
132+
* If you want to get the amount of item spawned, listen to FishingLootSpawnEvent
131133
*
132134
* @return The amount of loot received, or 1 if the loot is block or entity
133135
*/

api/src/main/java/net/momirealms/customfishing/api/manager/ActionManager.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.bukkit.configuration.ConfigurationSection;
2525

2626
import java.util.HashMap;
27-
import java.util.List;
2827

2928
public interface ActionManager {
3029

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77

88
allprojects {
99

10-
version = "2.0.10.2"
10+
version = "2.0.10.3"
1111

1212
apply<JavaPlugin>()
1313
apply(plugin = "java")

plugin/src/main/java/net/momirealms/customfishing/adventure/AdventureManagerImpl.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import com.comphenix.protocol.PacketType;
2121
import com.comphenix.protocol.events.PacketContainer;
22-
import com.comphenix.protocol.wrappers.WrappedChatComponent;
2322
import net.kyori.adventure.audience.Audience;
2423
import net.kyori.adventure.key.Key;
2524
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
@@ -28,7 +27,6 @@
2827
import net.kyori.adventure.text.minimessage.MiniMessage;
2928
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
3029
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
31-
import net.kyori.adventure.title.Title;
3230
import net.momirealms.customfishing.CustomFishingPluginImpl;
3331
import net.momirealms.customfishing.api.CustomFishingPlugin;
3432
import net.momirealms.customfishing.api.manager.AdventureManager;
@@ -42,7 +40,6 @@
4240
import org.bukkit.entity.Player;
4341

4442
import java.lang.reflect.InvocationTargetException;
45-
import java.time.Duration;
4643

4744
public class AdventureManagerImpl implements AdventureManager {
4845

plugin/src/main/java/net/momirealms/customfishing/command/sub/DataCommand.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import dev.jorel.commandapi.CommandAPICommand;
2525
import dev.jorel.commandapi.arguments.ArgumentSuggestions;
2626
import dev.jorel.commandapi.arguments.StringArgument;
27+
import dev.jorel.commandapi.arguments.UUIDArgument;
2728
import net.momirealms.customfishing.adventure.AdventureManagerImpl;
2829
import net.momirealms.customfishing.api.CustomFishingPlugin;
2930
import net.momirealms.customfishing.api.data.DataStorageInterface;
@@ -58,12 +59,23 @@ public CommandAPICommand getDataCommand() {
5859
.withSubcommands(
5960
getExportLegacyCommand(),
6061
getExportCommand(),
61-
getImportCommand()
62+
getImportCommand(),
63+
getUnlockCommand()
6264
);
6365
}
6466

67+
private CommandAPICommand getUnlockCommand() {
68+
return new CommandAPICommand("unlock")
69+
.withArguments(new UUIDArgument("uuid"))
70+
.executes((sender, args) -> {
71+
UUID uuid = (UUID) args.get("uuid");
72+
CustomFishingPlugin.get().getStorageManager().getDataSource().lockOrUnlockPlayerData(uuid, false);
73+
AdventureManagerImpl.getInstance().sendMessageWithPrefix(sender, "Successfully unlocked.");
74+
});
75+
}
76+
6577
@SuppressWarnings("DuplicatedCode")
66-
public CommandAPICommand getExportLegacyCommand() {
78+
private CommandAPICommand getExportLegacyCommand() {
6779
return new CommandAPICommand("export-legacy")
6880
.withArguments(new StringArgument("method")
6981
.replaceSuggestions(ArgumentSuggestions.strings("MySQL", "MariaDB", "YAML")))
@@ -137,7 +149,7 @@ public CommandAPICommand getExportLegacyCommand() {
137149
}
138150

139151
@SuppressWarnings("DuplicatedCode")
140-
public CommandAPICommand getExportCommand() {
152+
private CommandAPICommand getExportCommand() {
141153
return new CommandAPICommand("export")
142154
.executesConsole((sender, args) -> {
143155
if (Bukkit.getOnlinePlayers().size() != 0) {
@@ -151,7 +163,7 @@ public CommandAPICommand getExportCommand() {
151163
AdventureManagerImpl.getInstance().sendMessageWithPrefix(sender, "Starting <aqua>export</aqua>.");
152164
DataStorageInterface dataStorageInterface = plugin.getStorageManager().getDataSource();
153165

154-
Set<UUID> uuids = dataStorageInterface.getUniqueUsers(true);
166+
Set<UUID> uuids = dataStorageInterface.getUniqueUsers(false);
155167
Set<CompletableFuture<Void>> futures = new HashSet<>();
156168
AtomicInteger userCount = new AtomicInteger(0);
157169
Map<UUID, String> out = Collections.synchronizedMap(new TreeMap<>());
@@ -200,7 +212,7 @@ public CommandAPICommand getExportCommand() {
200212
}
201213

202214
@SuppressWarnings("DuplicatedCode")
203-
public CommandAPICommand getImportCommand() {
215+
private CommandAPICommand getImportCommand() {
204216
return new CommandAPICommand("import")
205217
.withArguments(new StringArgument("file"))
206218
.executesConsole((sender, args) -> {

plugin/src/main/java/net/momirealms/customfishing/command/sub/ItemCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ private CommandAPICommand getCommand(String namespace) {
125125
int amount = (int) args.getOrDefault("amount", 1);
126126
ItemStack item = CustomFishingPlugin.get().getItemManager().build(player, namespace, id, new Condition(player).getArgs());
127127
if (item != null) {
128-
int actual = ItemUtils.putLootsToBag(player, item, amount);
128+
int actual = ItemUtils.giveItem(player, item, amount);
129129
AdventureManagerImpl.getInstance().sendMessageWithPrefix(player, CFLocale.MSG_Get_Item.replace("{item}", id).replace("{amount}", String.valueOf(actual)));
130130
} else {
131131
AdventureManagerImpl.getInstance().sendMessageWithPrefix(player, CFLocale.MSG_Item_Not_Exists);
@@ -151,7 +151,7 @@ private CommandAPICommand giveCommand(String namespace) {
151151
assert players != null;
152152
for (Player player : players) {
153153
ItemStack item = CustomFishingPlugin.get().getItemManager().build(player, namespace, id, new Condition(player).getArgs());
154-
int actual = ItemUtils.putLootsToBag(player, item, amount);
154+
int actual = ItemUtils.giveItem(player, item, amount);
155155
AdventureManagerImpl.getInstance().sendMessageWithPrefix(sender, CFLocale.MSG_Give_Item.replace("{item}", id).replace("{amount}", String.valueOf(actual)).replace("{player}", player.getName()));
156156
}
157157
} else {

plugin/src/main/java/net/momirealms/customfishing/compatibility/IntegrationManagerImpl.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import java.util.ArrayList;
4343
import java.util.HashMap;
4444
import java.util.List;
45-
import java.util.Objects;
4645

4746
public class IntegrationManagerImpl implements IntegrationManager {
4847

0 commit comments

Comments
 (0)