Skip to content

Commit

Permalink
Critical Bug Fix #60
Browse files Browse the repository at this point in the history
  • Loading branch information
ryandw11 committed Jun 13, 2020
1 parent a978f44 commit 2494c96
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 67 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
*.tar.gz
*.rar

*.iml
/.idea/

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
/bin/
Expand Down
22 changes: 11 additions & 11 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: CustomStructures
version: 1.4.3.1
main: com.ryandw11.structure.CustomStructures
author: Ryandw11
description: A plugin which allows you to spawn in custom structures!
depend: [WorldEdit]
softdepend: [MythicMobs]
api-version: 1.13
commands:
customstructure:
description: Main command.
name: CustomStructures
version: 1.4.3.2
main: com.ryandw11.structure.CustomStructures
author: Ryandw11
description: A plugin which allows you to spawn in custom structures!
depend: [WorldEdit]
softdepend: [MythicMobs]
api-version: 1.13
commands:
customstructure:
description: Main command.
aliases: [cs, cstructure, customs, cws]
114 changes: 58 additions & 56 deletions src/com/ryandw11/structure/listener/ChunkLoad.java
Original file line number Diff line number Diff line change
@@ -1,56 +1,58 @@
package com.ryandw11.structure.listener;

import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.world.ChunkLoadEvent;

import com.ryandw11.structure.CustomStructures;
import com.ryandw11.structure.utils.StructurePicker;

/**
* Class for when a chunk loads.
* @author Ryandw11
*
*/
public class ChunkLoad implements Listener{

//private CustomStructures plugin;

public ChunkLoad(){
//this.plugin = CustomStructures.plugin;
}

@EventHandler
public void loadevent(ChunkLoadEvent e){
if(!CustomStructures.enabled) return;

if(e.isNewChunk()){ //Checks to see if the chunk is new or an old one.
World w = e.getChunk().getWorld(); //Grabs the world
Block b = e.getChunk().getBlock(0, 5, 0); //Grabs the block 0, 5, 0 in that chunk.

boolean foundLand = false; //True when the block selected is an ideal place for a structure.
Block bb = e.getChunk().getBlock(0, w.getHighestBlockYAt(b.getX(), b.getZ()), 0); //grabs the highest block in that chunk at X = 0 and Z = 0 for that chunk.
int trys = 0;
while (!foundLand){//While land was not found it keeps checking.
if(trys >= 20) return; //added anti crash.
if(bb.getType() != Material.AIR){
foundLand = true;
}
else{
bb = bb.getLocation().subtract(0, 1, 0).getBlock();
}
trys++;
}

/*
* Schematic handeler
* Runs a BukkitRunnable to prevent the server from crashing.
*/
StructurePicker s = new StructurePicker(bb, e.getChunk());
s.runTaskTimer(CustomStructures.plugin, 1, 10);
}
}
}
package com.ryandw11.structure.listener;

import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.world.ChunkLoadEvent;

import com.ryandw11.structure.CustomStructures;
import com.ryandw11.structure.utils.StructurePicker;

/**
* Class for when a chunk loads.
* @author Ryandw11
*
*/
public class ChunkLoad implements Listener{

//private CustomStructures plugin;

public ChunkLoad(){
//this.plugin = CustomStructures.plugin;
}

@EventHandler
public void loadevent(ChunkLoadEvent e){
if(!CustomStructures.enabled) return;

if(e.isNewChunk()){ //Checks to see if the chunk is new or an old one.
World w = e.getChunk().getWorld(); //Grabs the world
Block b = e.getChunk().getBlock(0, 5, 0); //Grabs the block 0, 5, 0 in that chunk.

if(w.getHighestBlockYAt(b.getX(), b.getZ()) == -1) return;

boolean foundLand = false; //True when the block selected is an ideal place for a structure.
Block bb = e.getChunk().getBlock(0, w.getHighestBlockYAt(b.getX(), b.getZ()), 0); //grabs the highest block in that chunk at X = 0 and Z = 0 for that chunk.
int trys = 0;
while (!foundLand){//While land was not found it keeps checking.
if(trys >= 20) return; //added anti crash.
if(bb.getType() != Material.AIR){
foundLand = true;
}
else{
bb = bb.getLocation().subtract(0, 1, 0).getBlock();
}
trys++;
}

/*
* Schematic handeler
* Runs a BukkitRunnable to prevent the server from crashing.
*/
StructurePicker s = new StructurePicker(bb, e.getChunk());
s.runTaskTimer(CustomStructures.plugin, 1, 10);
}
}
}

0 comments on commit 2494c96

Please sign in to comment.