Skip to content

Commit 951b45a

Browse files
committed
Fix some bug
1 parent 2edbc11 commit 951b45a

File tree

13 files changed

+98
-40
lines changed

13 files changed

+98
-40
lines changed

patches/minecraft/net/minecraft/server/level/ChunkMap.java.patch

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,21 +229,41 @@
229229
EntityType<?> entitytype = p_140200_.m_6095_();
230230
int i = entitytype.m_20681_() * 16;
231231
if (i != 0) {
232-
@@ -1163,8 +_,11 @@
233-
if (p_140332_ instanceof ServerPlayer serverplayer) {
234-
this.m_140192_(serverplayer, false);
232+
@@ -1160,25 +_,28 @@
233+
}
235234

235+
protected void m_140331_(Entity p_140332_) {
236+
- if (p_140332_ instanceof ServerPlayer serverplayer) {
237+
- this.m_140192_(serverplayer, false);
238+
-
236239
- for(ChunkMap.TrackedEntity chunkmap$trackedentity : this.f_140150_.values()) {
237240
- chunkmap$trackedentity.m_140485_(serverplayer);
238-
+ try {
241+
- }
242+
- }
243+
-
244+
- ChunkMap.TrackedEntity chunkmap$trackedentity1 = this.f_140150_.remove(p_140332_.m_19879_());
245+
- if (chunkmap$trackedentity1 != null) {
246+
- chunkmap$trackedentity1.m_140482_();
247+
- }
248+
-
249+
+ try {
250+
+ if (p_140332_ instanceof ServerPlayer serverplayer) {
251+
+ this.m_140192_(serverplayer, false);
252+
+
239253
+ for (ChunkMap.TrackedEntity chunkmap$trackedentity : this.f_140150_.values()) {
240254
+ chunkmap$trackedentity.m_140485_(serverplayer);
241255
+ }
242-
+ } catch (NullPointerException ignored) { // Mohist TODO
243-
}
244-
}
256+
+
257+
+ }
258+
+
259+
+ ChunkMap.TrackedEntity chunkmap$trackedentity1 = this.f_140150_.remove(p_140332_.m_19879_());
260+
+ if (chunkmap$trackedentity1 != null) {
261+
+ chunkmap$trackedentity1.m_140482_();
262+
+ }
263+
+ } catch (Exception ignored) { // Mohist TODO
264+
+ }
265+
}
245266

246-
@@ -1178,7 +_,7 @@
247267
protected void m_140421_() {
248268
List<ServerPlayer> list = Lists.newArrayList();
249269
List<ServerPlayer> list1 = this.f_140133_.m_6907_();

patches/minecraft/net/minecraft/world/level/Level.java.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@
243243
+
244244
public boolean m_6933_(BlockPos p_46605_, BlockState p_46606_, int p_46607_, int p_46608_) {
245245
+ {
246-
+ if (this.getWorld() != null) {
246+
+ if (SetBlockEvent.getHandlerList().getRegisteredListeners().length > 0 && this.getWorld() != null) {
247247
+ SetBlockEvent event = new SetBlockEvent(new Location(this.getWorld(), p_46605_.m_123341_(), p_46605_.m_123342_(), p_46605_.m_123343_()));
248248
+ Bukkit.getPluginManager().callEvent(event);
249249
+ if (event.isCancelled()) {
@@ -348,7 +348,7 @@
348348
+ bukkit = WorldAPI.destroyBlockProgress.get(p_46626_).getBukkitEntity();
349349
+ WorldAPI.destroyBlockProgress.remove(p_46626_);
350350
+ }
351-
+ if (bukkit != null) {
351+
+ if (ModsEntityDestroyBlockEvent.getHandlerList().getRegisteredListeners().length > 0 && bukkit != null) {
352352
+ ModsEntityDestroyBlockEvent event = new ModsEntityDestroyBlockEvent(new Location(this.getWorld(), p_46626_.m_123341_(), p_46626_.m_123342_(), p_46626_.m_123343_()), bukkit);
353353
+ Bukkit.getPluginManager().callEvent(event);
354354
+ if (event.isCancelled()) {

src/main/java/com/mohistmc/MohistConfig.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,11 @@ public static boolean isProxyOnlineMode() {
199199
public static int server_thread;
200200

201201
public static boolean clear_item;
202+
public static boolean clear_enable;
202203
public static List<String> clear_item_whitelist;
203204
public static String clear_item_msg;
204-
public static int clear_item_time;
205+
public static String clear_countdown_msg;
206+
public static int clear_time;
205207

206208
public static boolean clear_monster;
207209
public static List<String> clear_monster_whitelist;
@@ -282,15 +284,17 @@ private static void mohist() {
282284
keepinventory_exp_permission = getString("keepinventory.permission.exp", "mohist.keepinventory.exp");
283285
server_thread = getInt("threadpriority.server_thread", 8);
284286

287+
clear_enable = getBoolean("entity.clear.enable", false);
288+
clear_time = getInt("entity.clear.time", 1800);
289+
clear_countdown_msg = getString("entity.clear.countdown.msg", "[Server] §cItems will be cleared after %seconds% seconds!");
290+
285291
clear_item = getBoolean("entity.clear.item.enable", false);
286292
clear_item_whitelist = getStringList("entity.clear.item.whitelist", new ArrayList<>());
287293
clear_item_msg = getString("entity.clear.item.msg", "[Server] Cleaned up %size% drop item");
288-
clear_item_time = getInt("entity.clear.item.time", 1800);
289294

290295
clear_monster = getBoolean("entity.clear.monster.enable", false);
291296
clear_monster_whitelist = getStringList("entity.clear.monster.whitelist", new ArrayList<>());
292297
clear_monster_msg = getString("entity.clear.monster.msg", "[Server] Cleaned up %size% monster");
293-
clear_monster_time = getInt("entity.clear.monster.time", 1800);
294298

295299
ban_item_enable = getBoolean("ban.item.enable" , false);
296300
ban_item_materials = getStringList("ban.item.list", new ArrayList<>());

src/main/java/com/mohistmc/commands/BansCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public boolean execute(@NotNull CommandSender sender, @NotNull String commandLab
9191
sender.sendMessage(ChatColor.RED + check);
9292
return false;
9393
}
94-
BanSaveInventory banSaveInventory = new BanSaveInventory(BanType.ITEM, "§4Add bans entity");
94+
BanSaveInventory banSaveInventory = new BanSaveInventory(BanType.ENTITY, "§4Add bans entity");
9595
Inventory inventory = banSaveInventory.getInventory();
9696
player.openInventory(inventory);
9797
BanListener.openInventory = banSaveInventory;
@@ -102,7 +102,7 @@ public boolean execute(@NotNull CommandSender sender, @NotNull String commandLab
102102
sender.sendMessage(ChatColor.RED + check);
103103
return false;
104104
}
105-
BanSaveInventory banSaveInventory = new BanSaveInventory(BanType.ITEM, "§4Add bans enchantment");
105+
BanSaveInventory banSaveInventory = new BanSaveInventory(BanType.ENCHANTMENT, "§4Add bans enchantment");
106106
Inventory inventory = banSaveInventory.getInventory();
107107
player.openInventory(inventory);
108108
BanListener.openInventory = banSaveInventory;

src/main/java/com/mohistmc/plugins/EntityClear.java

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.mohistmc.MohistConfig;
44
import java.util.concurrent.ScheduledExecutorService;
5+
import java.util.concurrent.ScheduledFuture;
56
import java.util.concurrent.ScheduledThreadPoolExecutor;
67
import java.util.concurrent.TimeUnit;
78
import java.util.concurrent.atomic.AtomicInteger;
@@ -21,26 +22,38 @@ public class EntityClear {
2122

2223
public static final ScheduledExecutorService ENTITYCLEAR_ITEM = new ScheduledThreadPoolExecutor(1, new NamedThreadFactory("EntityClear - Item"));
2324
public static final ScheduledExecutorService ENTITYCLEAR_MONSTER = new ScheduledThreadPoolExecutor(1, new NamedThreadFactory("EntityClear - Item"));
25+
private static final ScheduledExecutorService COUNTDOWN_SERVICE = new ScheduledThreadPoolExecutor(1, new NamedThreadFactory("EntityClear-Countdown"));
26+
private static final AtomicInteger countdownSeconds = new AtomicInteger(15);
27+
private static ScheduledFuture<?> countdownFuture;
2428

2529
public static void start() {
26-
if (MohistConfig.clear_item) {
30+
if (MohistConfig.clear_enable) {
2731
ENTITYCLEAR_ITEM.scheduleAtFixedRate(() -> {
2832
if (MinecraftServer.getServer().hasStopped()) {
2933
return;
3034
}
31-
run_item();
32-
}, 1000 * 60, 1000L * MohistConfig.clear_item_time, TimeUnit.MILLISECONDS);
33-
}
34-
if (MohistConfig.clear_monster) {
35-
ENTITYCLEAR_MONSTER.scheduleAtFixedRate(() -> {
36-
if (MinecraftServer.getServer().hasStopped()) {
37-
return;
38-
}
39-
run_monster();
40-
}, 1000 * 60, 1000L * MohistConfig.clear_monster_time, TimeUnit.MILLISECONDS);
35+
startCountdown();
36+
}, MohistConfig.clear_time, MohistConfig.clear_time, TimeUnit.SECONDS);
4137
}
4238
}
4339

40+
public static void startCountdown() {
41+
countdownFuture = COUNTDOWN_SERVICE.scheduleAtFixedRate(() -> {
42+
int remaining = countdownSeconds.decrementAndGet();
43+
if (remaining > 0) {
44+
String msg = MohistConfig.clear_countdown_msg
45+
.replace("&", "§")
46+
.replace("%seconds%", String.valueOf(remaining));
47+
if (remaining == 14 || remaining == 10 || remaining < 4) Bukkit.broadcastMessage(msg);
48+
} else {
49+
countdownSeconds.set(15);
50+
if (MohistConfig.clear_item)run_item();
51+
if (MohistConfig.clear_monster)run_monster();
52+
countdownFuture.cancel(false);
53+
}
54+
}, 0, 1, TimeUnit.SECONDS);
55+
}
56+
4457
public static void stop() {
4558
ENTITYCLEAR_ITEM.shutdown();
4659
ENTITYCLEAR_MONSTER.shutdown();

src/main/java/com/mohistmc/plugins/back/BackCommands.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.mohistmc.MohistConfig;
44
import com.mohistmc.util.I18n;
5+
import org.bukkit.Location;
56
import org.bukkit.command.Command;
67
import org.bukkit.command.CommandSender;
78
import org.bukkit.entity.Player;
@@ -23,9 +24,13 @@ public BackCommands(String name) {
2324
public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) {
2425
if (sender instanceof Player player) {
2526
if (BackConfig.INSTANCE.has(player.getUniqueId().toString())) {
26-
player.teleport(BackConfig.INSTANCE.getLocation(player));
27-
player.sendMessage(I18n.as("backcommands.success",
28-
BackConfig.INSTANCE.getBackType(player).isTeleport() ? I18n.as("backcommands.backtype.teleport") : I18n.as("backcommands.backtype.death")));
27+
Location location = BackConfig.INSTANCE.getLocation(player);
28+
if (location != null) {
29+
player.teleport(BackConfig.INSTANCE.getLocation(player));
30+
player.sendMessage(I18n.as("backcommands.success",
31+
BackConfig.INSTANCE.getBackType(player).isTeleport() ? I18n.as("backcommands.backtype.teleport") : I18n.as("backcommands.backtype.death")));
32+
return true;
33+
}
2934
}
3035
else {
3136
sender.sendMessage(I18n.as("backcommands.none"));

src/main/java/com/mohistmc/plugins/back/BackConfig.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public void saveLocation(Player player, Location location, BackType backType) {
3434

3535
public Location getLocation(Player player) {
3636
final World world = Bukkit.getWorld(yaml.getString(player.getUniqueId() + ".location.world"));
37+
if (world == null) return null;
3738
final double x = yaml.getInt(player.getUniqueId() + ".location.x");
3839
final double y = yaml.getInt(player.getUniqueId() + ".location.y");
3940
final double z = yaml.getInt(player.getUniqueId() + ".location.z");

src/main/java/com/mohistmc/plugins/ban/BanType.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@
66
*/
77
public enum BanType {
88

9-
ITEM("ban.item.list"),
10-
ITEM_MOSHOU(null),
11-
ENTITY("ban.entity.list"),
12-
ENCHANTMENT("ban.enchantment.list");
9+
ITEM("ban.item.list", "bans.add.item", "bans.remove.item"),
10+
ITEM_MOSHOU(null, "bans.add.item_moshou", "bans.remove.item_moshou"),
11+
ENTITY("ban.entity.list", "bans.add.entity", "bans.remove.entity"),
12+
ENCHANTMENT("ban.enchantment.list", "bans.add.enchantment", "bans.remove.enchantment");
1313

1414
public final String key;
15+
public final String i18n_key_add;
16+
public final String i18n_key_remove;
1517

16-
BanType(String key) {
18+
BanType(String key, String i18n_key_add, String i18n_key_remove) {
1719
this.key = key;
20+
this.i18n_key_add = i18n_key_add;
21+
this.i18n_key_remove = i18n_key_remove;
1822
}
1923
}

src/main/java/com/mohistmc/plugins/ban/utils/BanUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ public static void saveToYaml(Player player, ClickType clickType, List<String> l
1717
MohistConfig.yml.set(banType.key, list);
1818
MohistConfig.save();
1919
if (clickType == ClickType.ADD) {
20-
player.sendMessage(I18n.as("bans.add.item"));
20+
player.sendMessage(I18n.as(banType.i18n_key_add));
2121
} else if (clickType == ClickType.REMOVE) {
22-
player.sendMessage(I18n.as("bans.remove.item"));
22+
player.sendMessage(I18n.as(banType.i18n_key_remove));
2323
}
2424
}
2525
}

src/main/java/net/minecraftforge/items/wrapper/InvWrapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate
6565
return ItemStack.EMPTY;
6666

6767
ItemStack stackInSlot = getInv().getItem(slot);
68-
if (InventoryOwner.inventoryFromForge(this) != null) {
68+
if (InvWrapperMoveItemEvent.Insert.getHandlerList().getRegisteredListeners().length > 0 && InventoryOwner.inventoryFromForge(this) != null) {
6969
var event = new InvWrapperMoveItemEvent.Insert(InventoryOwner.inventoryFromForge(this), CraftItemStack.asCraftMirror(stackInSlot));
7070
Bukkit.getPluginManager().callEvent(event);
7171
if (event.isCancelled()) {
@@ -165,7 +165,7 @@ public ItemStack extractItem(int slot, int amount, boolean simulate)
165165
if (stackInSlot.isEmpty())
166166
return ItemStack.EMPTY;
167167

168-
if (InventoryOwner.inventoryFromForge(this) != null) {
168+
if (InvWrapperMoveItemEvent.Extract.getHandlerList().getRegisteredListeners().length > 0 && InventoryOwner.inventoryFromForge(this) != null) {
169169
var event = new InvWrapperMoveItemEvent.Extract(InventoryOwner.inventoryFromForge(this), CraftItemStack.asCraftMirror(stackInSlot));
170170
Bukkit.getPluginManager().callEvent(event);
171171
if (event.isCancelled()) {

0 commit comments

Comments
 (0)