Skip to content

Commit 618c23d

Browse files
author
Flo56958
committed
Improve Performance of Void Netting
or reduce chance of crashing the server with it
1 parent 0df995b commit 618c23d

File tree

2 files changed

+46
-39
lines changed

2 files changed

+46
-39
lines changed

core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<artifactId>MineTinker-Core</artifactId>
1313
<description>A TinkersConstruct (and other mods) inspired server plugin</description>
1414
<url>https://flo56958.github.io/MineTinker</url>
15-
<version>1.5</version>
15+
<version>1.5.1</version>
1616

1717
<parent>
1818
<groupId>de.flo56958</groupId>

core/src/main/java/de/flo56958/MineTinker/Modifiers/Types/VoidNetting.java

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -144,47 +144,54 @@ public void onDamage(EntityDamageEvent event) {
144144
}
145145
}
146146

147-
Location loc = player.getLocation();
148-
for (int i = 0; i < level * radiusPerLevel; i++) {
149-
for (int d = -i; d <= i; d++) {
150-
int y = loc.getWorld().getHighestBlockYAt(loc.getBlockX() + d, loc.getBlockZ() + i - Math.abs(d));
151-
if (y > 1) {
152-
loc = new Location(loc.getWorld(), loc.getBlockX() + d, y + 2, loc.getBlockZ() + i - Math.abs(d));
153-
break;
147+
cooldownTracker.put(player.getUniqueId().toString(), time - Math.round(this.cooldownInSeconds * 0.95)); //Add small cooldown to improve server performance
148+
149+
Bukkit.getScheduler().runTaskAsynchronously(Main.getPlugin(), () -> { //run effect async as it does not need to stop all action on server if search takes to long
150+
Location loc = player.getLocation();
151+
for (int i = 0; i < level * radiusPerLevel; i++) {
152+
for (int d = -i; d <= i; d++) {
153+
int y = loc.getWorld().getHighestBlockYAt(loc.getBlockX() + d, loc.getBlockZ() + i - Math.abs(d));
154+
if (y > 1) {
155+
loc = new Location(loc.getWorld(), loc.getBlockX() + d, y + 2, loc.getBlockZ() + i - Math.abs(d));
156+
break;
157+
}
154158
}
155-
}
156-
for (int d = -i + 1; d < i; d++) {
157-
int y = loc.getWorld().getHighestBlockYAt(loc.getBlockX() + d, loc.getBlockZ() + Math.abs(d) - i);
158-
if (y > 1) {
159-
loc = new Location(loc.getWorld(), loc.getBlockX() + d, y + 2,loc.getBlockZ() + Math.abs(d) - i);
160-
break;
159+
for (int d = -i + 1; d < i; d++) {
160+
int y = loc.getWorld().getHighestBlockYAt(loc.getBlockX() + d, loc.getBlockZ() + Math.abs(d) - i);
161+
if (y > 1) {
162+
loc = new Location(loc.getWorld(), loc.getBlockX() + d, y + 2,loc.getBlockZ() + Math.abs(d) - i);
163+
break;
164+
}
161165
}
162166
}
163-
}
164167

165-
if (loc.equals(player.getLocation())) {
166-
//No suitable place found
167-
ChatWriter.logModifier(player, event, this, armor, "Could not find suitable Block to teleport!");
168-
ChatWriter.sendActionBar(player, this.getName() + ": " + LanguageManager.getString("Modifier.Void-Netting.CouldNotFindBlock", player));
169-
return;
170-
}
171-
172-
Location oldLoc = player.getLocation().clone();
173-
player.teleport(loc);
174-
player.setVelocity(new Vector(0, 0.1, 0)); //Slow the fall
175-
cooldownTracker.put(player.getUniqueId().toString(), time);
176-
ChatWriter.logModifier(player, event, this, armor,
177-
String.format("Location(%d/%d/%d -> %d/%d/%d)",
178-
oldLoc.getBlockX(), oldLoc.getBlockY(), oldLoc.getBlockZ(),
179-
loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()), String.format("Cooldown(%ds)", cooldownTime / 1000));
180-
181-
if (this.particles) {
182-
loc.getWorld().spawnParticle(Particle.PORTAL, loc, 20);
183-
loc.getWorld().spawnParticle(Particle.PORTAL, oldLoc, 20);
184-
}
185-
if (this.sound) {
186-
player.getWorld().playSound(loc, Sound.ENTITY_ENDERMAN_TELEPORT, 1.0f, 1.0f);
187-
player.getWorld().playSound(oldLoc, Sound.ENTITY_ENDERMAN_TELEPORT, 1.0f, 1.0f);
188-
}
168+
if (loc.equals(player.getLocation())) {
169+
//No suitable place found
170+
ChatWriter.logModifier(player, event, this, armor, "Could not find suitable Block to teleport!");
171+
ChatWriter.sendActionBar(player, this.getName() + ": " + LanguageManager.getString("Modifier.Void-Netting.CouldNotFindBlock", player));
172+
return;
173+
}
174+
Location oldLoc = player.getLocation().clone();
175+
cooldownTracker.put(player.getUniqueId().toString(), time);
176+
ChatWriter.logModifier(player, event, this, armor,
177+
String.format("Location(%d/%d/%d -> %d/%d/%d)",
178+
oldLoc.getBlockX(), oldLoc.getBlockY(), oldLoc.getBlockZ(),
179+
loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()), String.format("Cooldown(%ds)", cooldownTime / 1000));
180+
181+
Location finalLoc = loc;
182+
Bukkit.getScheduler().runTask(Main.getPlugin(), () -> { //Teleport needs to be in sync
183+
player.teleport(finalLoc);
184+
player.setVelocity(new Vector(0, 0.3, 0)); //Slow the fall
185+
186+
if (this.particles) {
187+
finalLoc.getWorld().spawnParticle(Particle.PORTAL, finalLoc, 20);
188+
finalLoc.getWorld().spawnParticle(Particle.PORTAL, oldLoc, 20);
189+
}
190+
if (this.sound) {
191+
player.getWorld().playSound(finalLoc, Sound.ENTITY_ENDERMAN_TELEPORT, 1.0f, 1.0f);
192+
player.getWorld().playSound(oldLoc, Sound.ENTITY_ENDERMAN_TELEPORT, 1.0f, 1.0f);
193+
}
194+
});
195+
});
189196
}
190197
}

0 commit comments

Comments
 (0)