Skip to content

Commit 7ef02f1

Browse files
LoneDev6MelonCode
authored andcommitted
Optimization (4 PR in one)
1 parent 7f3c400 commit 7ef02f1

4 files changed

Lines changed: 67 additions & 14 deletions

File tree

src/main/java/ru/meloncode/xmas/Events.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,4 +261,18 @@ public void onSaplingGrow(StructureGrowEvent event) {
261261
}
262262
}
263263

264+
@EventHandler
265+
public void disableDecay(LeavesDecayEvent e)
266+
{
267+
if(e.isCancelled())
268+
return;
269+
270+
if(e.getBlock().getType() != Material.SPRUCE_LEAVES)
271+
return;
272+
273+
if (MagicTree.isBlockBelongs(e.getBlock().getLocation().getBlock()))
274+
e.setCancelled(true);
275+
}
276+
277+
264278
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package ru.meloncode.xmas;
2+
3+
import org.bukkit.scheduler.BukkitRunnable;
4+
5+
class MagicTaskParticles extends BukkitRunnable {
6+
7+
private final Main xmas;
8+
9+
MagicTaskParticles(Main main) {
10+
this.xmas = main;
11+
}
12+
13+
@Override
14+
public void run() {
15+
if (Main.inProgress)
16+
for (MagicTree tree : XMas.getAllTrees()) {
17+
tree.playParticles();
18+
}
19+
if ((Main.autoEnd && Main.endTime < System.currentTimeMillis()) || !Main.inProgress) {
20+
xmas.end();
21+
cancel();
22+
}
23+
}
24+
}

src/main/java/ru/meloncode/xmas/MagicTree.java

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -106,23 +106,28 @@ public void update() {
106106
}
107107
presentCounter--;
108108
}
109+
}
110+
}
109111

110-
if (blocks != null && blocks.size() > 0) {
111-
for (Block block : blocks) {
112-
if (block.getType() == Material.SPRUCE_LEAVES) {
113-
if (level.getSwagEffect() != null) {
114-
level.getSwagEffect().playEffect(block.getLocation());
115-
}
116-
}
117-
if (block.getType() == Material.SPRUCE_LOG) {
118-
if (level.getBodyEffect() != null) {
119-
level.getBodyEffect().playEffect(block.getLocation());
120-
}
112+
public void playParticles()
113+
{
114+
if (blocks != null && blocks.size() > 0) {
115+
for (Block block : blocks) {
116+
if(!block.getChunk().isLoaded())
117+
continue;
118+
if (block.getType() == Material.SPRUCE_LEAVES) {
119+
if (level.getSwagEffect() != null) {
120+
level.getSwagEffect().playEffect(block.getLocation());
121121
}
122-
if (level.getAmbientEffect() != null) {
123-
level.getAmbientEffect().playEffect(location.clone().add(0, level.getTreeHeight(), 0));
122+
}
123+
if (block.getType() == Material.SPRUCE_LOG) {
124+
if (level.getBodyEffect() != null) {
125+
level.getBodyEffect().playEffect(block.getLocation());
124126
}
125127
}
128+
if (level.getAmbientEffect() != null) {
129+
level.getAmbientEffect().playEffect(location.clone().add(0, level.getTreeHeight(), 0));
130+
}
126131
}
127132
}
128133
}

src/main/java/ru/meloncode/xmas/Main.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public class Main extends JavaPlugin implements Listener {
3434
static long endTime;
3535
static boolean inProgress;
3636
private static int UPDATE_SPEED;
37+
private static int TASK_DELAY;
38+
private static int PARTICLES_DELAY;
3739
private static List<String> heads;
3840
private static Plugin plugin;
3941
private FileConfiguration config;
@@ -67,6 +69,13 @@ public void onEnable() {
6769
config.set("core.update-speed", 7);
6870
UPDATE_SPEED = 7;
6971
}
72+
TASK_DELAY = config.getInt("core.task-delay");
73+
if (TASK_DELAY <= 0)
74+
config.set("core.task-delay", 7);
75+
PARTICLES_DELAY = config.getInt("core.particles-delay");
76+
if (PARTICLES_DELAY <= 0)
77+
config.set("particles-delay", 35);
78+
7079
autoEnd = config.getBoolean("core.holiday-ends.enabled");
7180
resourceBack = config.getBoolean("core.holiday-ends.resource-back");
7281
MAX_TREE_COUNT = config.getInt("core.tree-limit");
@@ -118,7 +127,8 @@ public void onEnable() {
118127
LUCK_CHANCE_ENABLED = config.getBoolean("xmas.luck.enabled");
119128
LUCK_CHANCE = (float) config.getInt("xmas.luck.chance") / 100;
120129
new Events().registerListener();
121-
new MagicTask(this).runTaskTimer(this, 5, UPDATE_SPEED);
130+
new MagicTask(this).runTaskTimer(this, 5, TASK_DELAY);
131+
new MagicTaskParticles(this).runTaskTimer(this, 5, PARTICLES_DELAY);
122132
XMas.XMAS_CRYSTAL = new ItemMaker(Material.EMERALD, LocaleManager.CRYSTAL_NAME, LocaleManager.CRYSTAL_LORE).make();
123133

124134
ShapedRecipe grinderRecipe;

0 commit comments

Comments
 (0)