PageRenderTime 60ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 1ms

/NewWorldFolder/Physics/physics/Physix.java

https://bitbucket.org/Indeleble/newworld
Java | 732 lines | 663 code | 51 blank | 18 comment | 139 complexity | 64a242ca8cc8f0e5dd8a3844535f1423 MD5 | raw file
  1. package physics;
  2. import java.io.File;
  3. import java.io.FileNotFoundException;
  4. import java.io.IOException;
  5. import java.util.ArrayList;
  6. import java.util.HashMap;
  7. import java.util.Set;
  8. import java.util.logging.Logger;
  9. import org.bukkit.ChatColor;
  10. import org.bukkit.Location;
  11. import org.bukkit.Material;
  12. import org.bukkit.World;
  13. import org.bukkit.block.Block;
  14. import org.bukkit.command.Command;
  15. import org.bukkit.command.CommandSender;
  16. import org.bukkit.configuration.InvalidConfigurationException;
  17. import org.bukkit.configuration.file.FileConfiguration;
  18. import org.bukkit.entity.Item;
  19. import org.bukkit.entity.Player;
  20. import org.bukkit.inventory.ItemStack;
  21. import org.bukkit.plugin.PluginDescriptionFile;
  22. import org.bukkit.plugin.java.JavaPlugin;
  23. public class Physix extends JavaPlugin{
  24. Logger log = Logger.getLogger("Minecraft");
  25. PluginDescriptionFile pdf = this.getDescription();
  26. //Per world
  27. public final HashMap<Integer,String> worldName = new HashMap<Integer, String>();
  28. public final HashMap<Integer,Boolean> worldApply = new HashMap<Integer, Boolean>();
  29. //Per world settings?
  30. //public final HashMap<String,Boolean> worldTreeCut = new HashMap<String, Boolean>();
  31. //public final HashMap<String,Boolean> worldAutoPlant = new HashMap<String, Boolean>();
  32. //public final HashMap<String,Integer> worldPlantDelay = new HashMap<String, Integer>();
  33. //public final HashMap<String,Integer> worldMinimumConnected = new HashMap<String, Integer>();
  34. //public final HashMap<String,Integer> worldCheckRadius = new HashMap<String, Integer>();
  35. //Per area
  36. public final HashMap<String,String> areaWorld = new HashMap<String, String>();
  37. public final HashMap<String,Location> areaLoc1 = new HashMap<String, Location>();
  38. public final HashMap<String,Location> areaLoc2 = new HashMap<String, Location>();
  39. String pcloc1="";
  40. String pcloc2="";
  41. Player pcplayer=null;
  42. String ignorelist="0:8:9:10:11:104:105:59:6:333:328:92:32:51:90:111:106:78:79"; //Another block can drop to these blocks
  43. String droppedlist="63:68:321:50:76:75:55:104:105:59:6:333:328:354:77:69"; //Another block can drop to these blocks and it will drop
  44. String nonphysixlist="63:68:321:50:75:76:55:69:77:79"; //No physic apply to these block
  45. String glueblocklist="30"; //Cobweb
  46. String areafile="Area.txt";
  47. int cubeCreated=0;
  48. String cubeName="";
  49. String cubeLoc1="";
  50. String creator="";
  51. boolean confirm=false;
  52. boolean wait=false;
  53. boolean treecut=true;
  54. boolean autoplant=true;
  55. boolean entityphysix=false; //Beta -> Still have error
  56. boolean progressive=false;
  57. boolean progressivePhysix=false;
  58. int plantdelay=10;
  59. int minimumconnected=2;
  60. int checkradius=15;
  61. public void onEnable() {
  62. getServer().getPluginManager().registerEvents(new MyListener(this), this);
  63. pdf = this.getDescription();
  64. log.info("["+pdf.getName()+"] v"+pdf.getVersion()+" successfully enabled.");
  65. initVars();
  66. }
  67. public Location str2loc(String str){
  68. Location loc = new Location(this.getServer().getWorlds().get(0),0,0,0);
  69. String str2loc[]=str.split("\\:");
  70. loc.setX(Double.parseDouble(str2loc[0]));
  71. loc.setY(Double.parseDouble(str2loc[1]));
  72. loc.setZ(Double.parseDouble(str2loc[2]));
  73. return loc;
  74. }
  75. public String loc2str(Location loc){
  76. return loc.getBlockX()+":"+loc.getBlockY()+":"+loc.getBlockZ();
  77. }
  78. private void initVars(){
  79. if(!this.getDataFolder().exists()){
  80. this.getDataFolder().mkdir();
  81. }
  82. File conf = new File(this.getDataFolder().toString(),"config.yml");
  83. FileConfiguration myConfig = this.getConfig();
  84. if(conf.exists()){
  85. try {
  86. myConfig.load(conf);
  87. progressive = myConfig.getBoolean("Physix.ProgressivePhysix",progressive);
  88. minimumconnected = myConfig.getInt("Physix.MinimumBlockConnected");
  89. checkradius = myConfig.getInt("Physix.CheckRadius",checkradius);
  90. entityphysix = myConfig.getBoolean("Physix.CheckEntity",entityphysix);
  91. glueblocklist = myConfig.getString("Physix.GlueBlockList",glueblocklist);
  92. treecut = myConfig.getBoolean("Physix.TreeCut",treecut);
  93. autoplant = myConfig.getBoolean("Physix.AutoPlant",autoplant);
  94. plantdelay = myConfig.getInt("Physix.PlantDelay",plantdelay);
  95. droppedlist = myConfig.getString("Physix.DroppedBlockList",droppedlist);
  96. ignorelist = myConfig.getString("Physix.IgnoredBlockList",ignorelist);
  97. nonphysixlist = myConfig.getString("Physix.NonPhysixBlockList",nonphysixlist);
  98. //Load world
  99. if(myConfig.contains("Physix.ApplyWorlds")){
  100. Set<String> keyl = myConfig.getConfigurationSection("Physix.ApplyWorlds").getKeys(false);
  101. if(keyl.size()>0){
  102. Object[] key= keyl.toArray();
  103. for(int i=0;i<key.length;i++){
  104. worldName.put(i, (String)key[i]);
  105. worldApply.put(i, myConfig.getBoolean("Physix.ApplyWorlds."+(String)key[i]));
  106. }
  107. }
  108. }
  109. int total = loadArea();
  110. if(total>0){
  111. log.info("["+pdf.getName()+"] Total "+total+" areas loaded.");
  112. }
  113. } catch (FileNotFoundException e) {
  114. log.info("Error Occured: onInitVars|FileNotFoundException|"+e.getMessage());
  115. } catch (IOException e) {
  116. log.info("Error Occured: onInitVars|IOException|"+e.getMessage());
  117. } catch (InvalidConfigurationException e) {
  118. log.info("Error Occured: onInitVars|InvalidConfigurationException|"+e.getMessage());
  119. }
  120. }
  121. myConfig.set("Physix.ProgressivePhysix",progressive);
  122. myConfig.set("Physix.MinimumBlockConnected",minimumconnected);
  123. myConfig.set("Physix.CheckRadius",checkradius);
  124. myConfig.set("Physix.CheckEntity",entityphysix);
  125. myConfig.set("Physix.GlueBlockList",glueblocklist);
  126. myConfig.set("Physix.DroppedBlockList",droppedlist);
  127. myConfig.set("Physix.IgnoredBlockList",ignorelist);
  128. myConfig.set("Physix.NonPhysixBlockList",nonphysixlist);
  129. myConfig.set("Physix.TreeCut",treecut);
  130. myConfig.set("Physix.AutoPlant",autoplant);
  131. myConfig.set("Physix.PlantDelay",plantdelay);
  132. for(int i=0;i<getServer().getWorlds().size();i++){
  133. if(!myConfig.contains("Physix.ApplyWorlds."+getServer().getWorlds().get(i).getName())){
  134. myConfig.set("Physix.ApplyWorlds."+getServer().getWorlds().get(i).getName(), false);
  135. worldName.put(worldName.size(), getServer().getWorlds().get(i).getName());
  136. worldApply.put(worldName.size(), false);
  137. }
  138. }
  139. try {
  140. myConfig.save(conf);
  141. } catch (IOException e) {
  142. log.info("Error Occured: onInitVars|IOException|"+e.getMessage());
  143. }
  144. }
  145. private int loadArea(){
  146. File conf = new File(getDataFolder().toString(),areafile);
  147. int i,total=0;
  148. if(conf.exists()){
  149. FlatFile config = new FlatFile(conf.getPath(),this);
  150. total=config.getInt("t");
  151. for(i=0;i<total;i++){
  152. String key=config.getString(i+"n");
  153. areaWorld.put(key.toLowerCase(), config.getString(i+"w"));
  154. areaLoc1.put(key.toLowerCase(), str2loc(config.getString(i+"l1")));
  155. areaLoc2.put(key.toLowerCase(), str2loc(config.getString(i+"l2")));
  156. }
  157. }
  158. return total;
  159. }
  160. private int saveArea(){
  161. if(!this.getDataFolder().exists()){
  162. this.getDataFolder().mkdir();
  163. }
  164. if(!areaWorld.isEmpty()){
  165. File conf = new File(this.getDataFolder().toString(),areafile);
  166. if(conf.exists()){
  167. conf.delete();
  168. }
  169. int i;
  170. FlatFile config = new FlatFile(conf.getPath(),this);
  171. config.setNumber("t", areaWorld.size());
  172. ArrayList<String> keys = new ArrayList<String>(areaWorld.keySet());
  173. for(i=0;i<keys.size();i++){
  174. String id = keys.get(i);
  175. config.setString(i+"n", id.toLowerCase());
  176. config.setString(i+"w", areaWorld.get(id));
  177. config.setString(i+"l1", loc2str(areaLoc1.get(id)));
  178. config.setString(i+"l2", loc2str(areaLoc2.get(id)));
  179. }
  180. config.save();
  181. return areaWorld.size();
  182. }
  183. return 0;
  184. }
  185. public void onDisable() {
  186. int total = saveArea();
  187. if(total>0){
  188. log.info("["+pdf.getName()+"] Total "+total+" areas saved.");
  189. }
  190. log.info("["+pdf.getName()+"] v"+pdf.getVersion()+" successfully disabled.");
  191. }
  192. public void autoPlant(Item drop,World world){
  193. if((drop.getItemStack().getType()==Material.SEEDS||drop.getItemStack().getType()==Material.PUMPKIN_SEEDS||drop.getItemStack().getType()==Material.MELON_SEEDS)&&autoplant&&(isApplyWorld(world)||isApplyArea(drop.getLocation(),world))){
  194. if(world.getBlockAt(drop.getLocation().getBlockX(), drop.getLocation().getBlockY()-1, drop.getLocation().getBlockZ()).getType()==Material.SOIL){
  195. if(world.getBlockAt(drop.getLocation()).getType()==Material.AIR){
  196. if(drop.getItemStack().getType()==Material.SEEDS){world.getBlockAt(drop.getLocation()).setType(Material.CROPS);drop.remove();}
  197. if(drop.getItemStack().getType()==Material.PUMPKIN_SEEDS){world.getBlockAt(drop.getLocation()).setType(Material.PUMPKIN_STEM);drop.remove();}
  198. if(drop.getItemStack().getType()==Material.MELON_SEEDS){world.getBlockAt(drop.getLocation()).setType(Material.MELON_STEM);drop.remove();}
  199. }
  200. }
  201. }
  202. if(drop.getItemStack().getType()==Material.SAPLING&&autoplant&&(isApplyWorld(world)||isApplyArea(drop.getLocation(),world))){
  203. if(world.getBlockAt(drop.getLocation().getBlockX(), drop.getLocation().getBlockY()-1, drop.getLocation().getBlockZ()).getType()==Material.DIRT||world.getBlockAt(drop.getLocation().getBlockX(), drop.getLocation().getBlockY()-1, drop.getLocation().getBlockZ()).getType()==Material.GRASS){
  204. if(world.getBlockAt(drop.getLocation()).getType()==Material.AIR){
  205. if(drop.getItemStack().getType()==Material.SAPLING){world.getBlockAt(drop.getLocation()).setType(drop.getItemStack().getType());world.getBlockAt(drop.getLocation()).setData(drop.getItemStack().getData().getData());drop.remove();}
  206. }
  207. }
  208. }
  209. }
  210. private boolean isApplyArea(Location loc,World world){
  211. ArrayList<String> keys = new ArrayList<String>(areaWorld.keySet());
  212. for(int i=0;i<keys.size();i++){
  213. String name = keys.get(i);
  214. if(world.getName().equalsIgnoreCase(areaWorld.get(name))){
  215. Location loc1 = areaLoc1.get(name);
  216. Location loc2 = areaLoc2.get(name);
  217. int pass=0;
  218. if(loc1.getBlockX()<loc2.getBlockX()){
  219. if(loc.getBlockX()>=loc1.getBlockX()&&loc.getBlockX()<=loc2.getBlockX()){
  220. pass++;
  221. }
  222. }else{
  223. if(loc.getBlockX()<=loc1.getBlockX()&&loc.getBlockX()>=loc2.getBlockX()){
  224. pass++;
  225. }
  226. }
  227. if(loc1.getBlockY()<loc2.getBlockY()){
  228. if(loc.getBlockY()>=loc1.getBlockY()&&loc.getBlockY()<=loc2.getBlockY()){
  229. pass++;
  230. }
  231. }else{
  232. if(loc.getBlockY()<=loc1.getBlockY()&&loc.getBlockY()>=loc2.getBlockY()){
  233. pass++;
  234. }
  235. }
  236. if(loc1.getBlockZ()<loc2.getBlockZ()){
  237. if(loc.getBlockZ()>=loc1.getBlockZ()&&loc.getBlockZ()<=loc2.getBlockZ()){
  238. pass++;
  239. }
  240. }else{
  241. if(loc.getBlockZ()<=loc1.getBlockZ()&&loc.getBlockZ()>=loc2.getBlockZ()){
  242. pass++;
  243. }
  244. }
  245. if(pass>=3){return true;}
  246. }
  247. }
  248. return false;
  249. }
  250. private boolean isApplyWorld(World world){
  251. ArrayList<Integer> keys = new ArrayList<Integer>(worldApply.keySet());
  252. for(int i=0;i<keys.size();i++){
  253. int id = keys.get(i);
  254. if(world.getName().equalsIgnoreCase(worldName.get(id))){
  255. return worldApply.get(id);
  256. }
  257. }
  258. return false;
  259. }
  260. private boolean isGlueBlock(Material mat){
  261. String[] dat=glueblocklist.split(":");
  262. for(int i=0;i<dat.length;i++){
  263. if(mat==Material.getMaterial(Integer.parseInt(dat[i]))){
  264. return true;
  265. }
  266. }
  267. return false;
  268. }
  269. private boolean isDroppedBlock(Material mat){
  270. //Another block can drop to these blocks and it will drop
  271. //63:68:321:50:76:75:55:104:105:59:6:333:328:354:77:69
  272. String[] dat=droppedlist.split(":");
  273. for(int i=0;i<dat.length;i++){
  274. if(mat==Material.getMaterial(Integer.parseInt(dat[i]))){
  275. return true;
  276. }
  277. }
  278. return false;
  279. }
  280. private boolean isIgnoredBlock(Material mat){
  281. //Another block can drop to these blocks
  282. //0:8:9:10:11:104:105:59:6:333:328:92:32:51:90:111:106:78
  283. String[] dat=ignorelist.split(":");
  284. for(int i=0;i<dat.length;i++){
  285. if(mat==Material.getMaterial(Integer.parseInt(dat[i]))){
  286. return true;
  287. }
  288. }
  289. return false;
  290. }
  291. private boolean isNonPhysixBlock(Material mat){
  292. //No physic apply to these block
  293. //63:68:321:50:75:76:55:69:77 GLUEBLOCK
  294. String[] dat=nonphysixlist.split(":");
  295. for(int i=0;i<dat.length;i++){
  296. if(mat==Material.getMaterial(Integer.parseInt(dat[i]))){
  297. return true;
  298. }
  299. }
  300. return isGlueBlock(mat);
  301. }
  302. private boolean isAroundGlueBlock(Block block){
  303. for(int x=-1;x<=1;x++){
  304. for(int y=-1;y<=1;y++){
  305. for(int z=-1;z<=1;z++){
  306. if(x!=0||y!=0||z!=0){
  307. if(isGlueBlock(block.getRelative(x, y, z).getType())){return true;}
  308. }
  309. }
  310. }
  311. }
  312. return false;
  313. }
  314. public int isTree(Block block,World world){
  315. int treeheight=0;
  316. for(int i=0;i>-block.getLocation().getBlockY();i--){
  317. if(block.getRelative(0, i, 0).getType()!=Material.LOG&&block.getRelative(0, i, 0).getType()!=Material.DIRT){
  318. return 0;
  319. }else{
  320. if(block.getRelative(0, i, 0).getType()==Material.DIRT){
  321. break;
  322. }
  323. }
  324. }
  325. for(int i=0;i<world.getMaxHeight()-block.getLocation().getBlockY();i++){
  326. if(block.getRelative(0, i, 0).getType()==Material.LOG){
  327. treeheight++;
  328. }else{
  329. if(block.getRelative(0, i, 0).getType()==Material.LEAVES){
  330. return treeheight;
  331. }else{
  332. return 0;
  333. }
  334. }
  335. }
  336. return 0;
  337. }
  338. private void cutTree(Block block,World world,int height){
  339. for(int i=0;i>-block.getLocation().getBlockY();i--){
  340. if(block.getRelative(0, i, 0).getType()==Material.DIRT){
  341. Block lowest=block.getRelative(0, i, 0);
  342. for(int x=-5;x<=5;x++){
  343. for(int y=0;y<=height+2;y++){
  344. for(int z=-5;z<=5;z++){
  345. Block rem=lowest.getRelative(x, y, z);
  346. if(rem.getType()==Material.LOG||rem.getType()==Material.LEAVES){
  347. rem.breakNaturally();
  348. }
  349. }
  350. }
  351. }
  352. }
  353. }
  354. }
  355. public void checkTree(Block block,World world){
  356. if(block.getType()==Material.LOG&&treecut&&(isApplyWorld(world)||isApplyArea(block.getLocation(),world))){
  357. int height=isTree(block,world);
  358. if(height>0){
  359. cutTree(block,world,height);
  360. }
  361. }
  362. }
  363. public void checkBreak(Block block,World world,boolean bypass){
  364. if(isApplyWorld(world)||isApplyArea(block.getLocation(),world)||bypass){
  365. checkRadius(block,world,bypass);
  366. for(int r=1;r<=checkradius;r++){
  367. checkRadius(block.getRelative(0, r, 0),world,bypass);
  368. checkRadius(block.getRelative(0, -r, 0),world,bypass);
  369. }
  370. }
  371. }
  372. public void checkRadius(Block block,World world,boolean bypass){
  373. for(int r=0;r<=checkradius;r++){
  374. for(int x=-r;x<=r;x++){
  375. if(x==-r||x==r){
  376. for(int y=-r;y<=r;y++){
  377. if(block.getRelative(x, 0, y).getType()!=Material.AIR){
  378. checkPhysix(block.getRelative(x, 0, y), world,bypass);
  379. }
  380. }
  381. }else{
  382. if(block.getRelative(x, 0, -r).getType()!=Material.AIR){
  383. checkPhysix(block.getRelative(x, 0, -r), world,bypass);
  384. }
  385. if(block.getRelative(x, 0, r).getType()!=Material.AIR){
  386. checkPhysix(block.getRelative(x, 0, r), world,bypass);
  387. }
  388. }
  389. }
  390. }
  391. for(int r=checkradius;r>=0;r--){
  392. for(int x=-r;x<=r;x++){
  393. if(x==-r||x==r){
  394. for(int y=-r;y<=r;y++){
  395. if(block.getRelative(x, 0, y).getType()!=Material.AIR){
  396. checkPhysix(block.getRelative(x, 0, y), world,bypass);
  397. }
  398. }
  399. }else{
  400. if(block.getRelative(x, 0, -r).getType()!=Material.AIR){
  401. checkPhysix(block.getRelative(x, 0, -r), world,bypass);
  402. }
  403. if(block.getRelative(x, 0, r).getType()!=Material.AIR){
  404. checkPhysix(block.getRelative(x, 0, r), world,bypass);
  405. }
  406. }
  407. }
  408. }
  409. }
  410. public void applyStepPhysix(Block block, World world){
  411. Block low = block;
  412. Block set = world.getBlockAt(low.getLocation());
  413. if(isIgnoredBlock(low.getType())||isDroppedBlock(low.getType())){
  414. if(block.getType()!=Material.LEAVES||(block.getType()==Material.LEAVES&&!treecut)){
  415. if((isIgnoredBlock(low.getType())||isDroppedBlock(low.getType()))&&(low.getLocation().getBlockY()>=1)&&(!isAroundGlueBlock(low))){
  416. set = low.getRelative(0, -1, 0);
  417. }
  418. if(isDroppedBlock(set.getType())){
  419. ItemStack drop = new ItemStack(set.getTypeId(), 1, (short)0, set.getData());
  420. world.dropItemNaturally(set.getLocation(), drop);
  421. }
  422. set.setType(block.getType());
  423. set.setData(block.getData());
  424. }
  425. block.setType(Material.AIR);
  426. }
  427. if(low.getLocation()==set.getLocation()){return;}
  428. getServer().getScheduler().scheduleSyncDelayedTask(this, new ProgressiveDrop(this,set,world),0);
  429. }
  430. private void applyPhysix(Block block,World world){
  431. if(progressivePhysix){
  432. getServer().getScheduler().scheduleSyncDelayedTask(this, new ProgressiveDrop(this,block,world),0);
  433. return;
  434. }
  435. Block low = block.getRelative(0, -1, 0);
  436. if(isIgnoredBlock(low.getType())||isDroppedBlock(low.getType())){
  437. if(block.getType()!=Material.LEAVES||(block.getType()==Material.LEAVES&&!treecut)){
  438. Block set = world.getBlockAt(getLowestAir(block,world));
  439. if(isDroppedBlock(set.getType())){
  440. ItemStack drop = new ItemStack(set.getTypeId(), 1, (short)0, set.getData());
  441. world.dropItemNaturally(set.getLocation(), drop);
  442. }
  443. set.setType(block.getType());
  444. set.setData(block.getData());
  445. }
  446. block.setType(Material.AIR); //Ploblem here!
  447. }
  448. }
  449. private Location getLowestAir(Block block,World world){
  450. Block low=block;
  451. while(true){
  452. if(isIgnoredBlock(low.getRelative(0, -1, 0).getType())||isDroppedBlock(low.getRelative(0, -1, 0).getType())){
  453. if(isDroppedBlock(low.getRelative(0, -1, 0).getType())){
  454. ItemStack drop = new ItemStack(low.getRelative(0, -1, 0).getTypeId(), 1, (short)0, low.getRelative(0, -1, 0).getData());
  455. world.dropItemNaturally(low.getRelative(0, -1, 0).getLocation(), drop);
  456. }
  457. low.getRelative(0, -1, 0).setType(Material.AIR);
  458. if(low.getLocation().getBlockY()<=-100||isAroundGlueBlock(low)){return low.getLocation();}
  459. low=low.getRelative(0, -1, 0);
  460. }else{
  461. return low.getLocation();
  462. }
  463. }
  464. }
  465. private Location getLowestAirByPass(Block block,World world){
  466. Block low=block;
  467. while(true){
  468. if(low.getRelative(0, -1, 0).getType()==Material.AIR){
  469. low.getRelative(0, -1, 0).setType(Material.AIR);
  470. if(low.getLocation().getBlockY()<=-100){return low.getLocation();}
  471. low=low.getRelative(0, -1, 0);
  472. }else{
  473. return low.getLocation();
  474. }
  475. }
  476. }
  477. private boolean checkBlockConnection(Block block){
  478. int samex=0;
  479. int samez=0;
  480. //Connected atlease # blocks
  481. if(!isIgnoredBlock(block.getRelative(0, 0, -1).getType())&&!isNonPhysixBlock(block.getRelative(0, 0, -1).getType())&&!isDroppedBlock(block.getRelative(0, 0, -1).getType())){samex++;}
  482. if(!isIgnoredBlock(block.getRelative(0, 0, 1).getType())&&!isNonPhysixBlock(block.getRelative(0, 0, 1).getType())&&!isDroppedBlock(block.getRelative(0, 0, 1).getType())){samex++;}
  483. if(!isIgnoredBlock(block.getRelative(-1, 0, 0).getType())&&!isNonPhysixBlock(block.getRelative(-1, 0, 0).getType())&&!isDroppedBlock(block.getRelative(-1, 0, 0).getType())){samez++;}
  484. if(!isIgnoredBlock(block.getRelative(1, 0, 0).getType())&&!isNonPhysixBlock(block.getRelative(1, 0, 0).getType())&&!isDroppedBlock(block.getRelative(1, 0, 0).getType())){samez++;}
  485. if(samex<minimumconnected&&samez<minimumconnected&&!isAroundGlueBlock(block)){
  486. return false;
  487. }else{
  488. return true;
  489. }
  490. }
  491. public boolean checkPhysix(Block block,World world,boolean bypass){
  492. if(!checkBlockConnection(block)&&!isNonPhysixBlock(block.getType())&&!isIgnoredBlock(block.getType())&&(isApplyWorld(world)||isApplyArea(block.getLocation(),world))||bypass){
  493. applyPhysix(block,world);
  494. return true;
  495. }
  496. return false;
  497. }
  498. int ptotal=0;
  499. int pdone=0;
  500. int px=0; //X
  501. int py=0; //Y
  502. int pz=0; //Z
  503. public void progressiveInstantArea(){
  504. Material mat = pcplayer.getWorld().getBlockAt(px, py, pz).getType();
  505. if(mat!=Material.AIR){
  506. byte data = pcplayer.getWorld().getBlockAt(px, py, pz).getData();
  507. pcplayer.getWorld().getBlockAt(px, py, pz).setType(Material.AIR);
  508. Block set = pcplayer.getWorld().getBlockAt(getLowestAirByPass(pcplayer.getWorld().getBlockAt(px, py, pz),pcplayer.getWorld()));
  509. set.setType(mat);
  510. set.setData(data);
  511. }
  512. pdone++;
  513. px++;
  514. if(px>str2loc(pcloc2).getBlockX()){
  515. px=str2loc(pcloc1).getBlockX();
  516. py++;
  517. }
  518. if(py>str2loc(pcloc2).getBlockY()){
  519. py=str2loc(pcloc1).getBlockY();
  520. pz++;
  521. }
  522. if(pz>str2loc(pcloc2).getBlockZ()){
  523. //Done
  524. confirm=false;
  525. log.info("["+pdf.getName()+"] Instant Physic Done.");
  526. pcplayer.sendMessage(ChatColor.GREEN+"Instant physic done.");
  527. return;
  528. }
  529. getServer().getScheduler().scheduleSyncDelayedTask(this, new ProgressiveInstantArea(this), 0);
  530. }
  531. public void instantArea(Location loc1,Location loc2,Player player){
  532. if(!confirm){
  533. if(loc1.getBlockX()>loc2.getBlockX()){
  534. Location tmp=loc1.clone();
  535. loc1.setX(loc2.getBlockX());
  536. loc2.setX(tmp.getBlockX());
  537. }
  538. if(loc1.getBlockY()>loc2.getBlockY()){
  539. Location tmp=loc1.clone();
  540. loc1.setY(loc2.getBlockY());
  541. loc2.setY(tmp.getBlockY());
  542. }
  543. if(loc1.getBlockZ()>loc2.getBlockZ()){
  544. Location tmp=loc1.clone();
  545. loc1.setZ(loc2.getBlockZ());
  546. loc2.setZ(tmp.getBlockZ());
  547. }
  548. //Calculate block
  549. int tx=loc2.getBlockX()-loc1.getBlockX();
  550. int ty=loc2.getBlockY()-loc1.getBlockY();
  551. int tz=loc2.getBlockZ()-loc1.getBlockZ();
  552. ptotal=(tx*ty*tz);
  553. player.sendMessage(ChatColor.YELLOW+""+ptotal+" blocks will be process...");
  554. player.sendMessage(ChatColor.YELLOW+"Are you sure you want to continue?");
  555. player.sendMessage(ChatColor.YELLOW+"Type \"/physix y\" or \"/physix n\" to confirm...");
  556. pcloc1=loc2str(loc1);
  557. pcloc2=loc2str(loc2);
  558. pcplayer=player;
  559. wait=true;
  560. }else{
  561. log.info("["+pdf.getName()+"] Instant Physic Started.");
  562. if(progressive){
  563. pdone=0;
  564. px=str2loc(pcloc1).getBlockX();
  565. py=str2loc(pcloc1).getBlockY();
  566. pz=str2loc(pcloc1).getBlockZ();
  567. getServer().getScheduler().scheduleSyncDelayedTask(this, new ProgressiveInstantArea(this), 0);
  568. }else{
  569. loc1=str2loc(pcloc1);
  570. loc2=str2loc(pcloc2);
  571. player=pcplayer;
  572. int x,y,z;
  573. for(x=loc1.getBlockX();x<=loc2.getBlockX();x++){
  574. for(y=loc1.getBlockY();y<=loc2.getBlockY();y++){
  575. for(z=loc1.getBlockZ();z<=loc2.getBlockZ();z++){
  576. Material mat = player.getWorld().getBlockAt(x, y, z).getType();
  577. if(mat!=Material.AIR){
  578. byte data = player.getWorld().getBlockAt(x, y, z).getData();
  579. player.getWorld().getBlockAt(x, y, z).setType(Material.AIR);
  580. Block set = player.getWorld().getBlockAt(getLowestAirByPass(player.getWorld().getBlockAt(x, y, z),player.getWorld()));
  581. set.setType(mat);
  582. set.setData(data);
  583. }
  584. }
  585. }
  586. }
  587. confirm=false;
  588. log.info("["+pdf.getName()+"] Instant Physic Done.");
  589. player.sendMessage(ChatColor.GREEN+"Instant physic done.");
  590. }
  591. }
  592. }
  593. private boolean isNumber(String str)
  594. {
  595. return str.matches("-?\\d+(.\\d+)?");
  596. }
  597. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
  598. if(sender.getName().compareTo("CONSOLE")!=0){
  599. if(((Player)sender).isOp()){
  600. if(args.length==1){
  601. if(wait){
  602. if(args[0].equalsIgnoreCase("y")){
  603. wait=false;
  604. confirm=true;
  605. sender.sendMessage(ChatColor.GREEN+"Selected area will now apply physic to it. Expecting some lags...");
  606. instantArea(null,null,null);
  607. return true;
  608. }
  609. if(args[0].equalsIgnoreCase("n")){
  610. wait=false;
  611. log.info("["+pdf.getName()+"] Instant Physic Cancelled.");
  612. sender.sendMessage(ChatColor.GREEN+"Instant physic cancelled.");
  613. return true;
  614. }
  615. }
  616. if(!wait){
  617. if(args[0].equalsIgnoreCase("list")||args[0].equalsIgnoreCase("all")){
  618. sender.sendMessage(ChatColor.GREEN+"Physix applied area:");
  619. ArrayList<String> keys = new ArrayList<String>(areaWorld.keySet());
  620. if(keys.size()>0){
  621. for(int i=0;i<keys.size();i++){
  622. String name = keys.get(i);
  623. sender.sendMessage(ChatColor.AQUA+"\""+ChatColor.YELLOW+name+ChatColor.AQUA+"\""+ChatColor.GREEN+" @ "+ChatColor.YELLOW+areaWorld.get(name)+" "+areaLoc1.get(name).getBlockX()+ChatColor.AQUA+":"+ChatColor.YELLOW+areaLoc1.get(name).getBlockY()+ChatColor.AQUA+":"+ChatColor.YELLOW+areaLoc1.get(name).getBlockZ()+ChatColor.GREEN+" to "+ChatColor.YELLOW+areaLoc2.get(name).getBlockX()+ChatColor.AQUA+":"+ChatColor.YELLOW+areaLoc2.get(name).getBlockY()+ChatColor.AQUA+":"+ChatColor.YELLOW+areaLoc2.get(name).getBlockZ());
  624. }
  625. }else{
  626. sender.sendMessage(ChatColor.YELLOW+"No area created.");
  627. }
  628. return true;
  629. }
  630. }
  631. }
  632. if(args.length>=1){
  633. if(!wait){
  634. if(args[0].equalsIgnoreCase("instant")){
  635. if(!creator.isEmpty()){sender.sendMessage("Please wait... Another OP is creating a new area...");return true;}
  636. if(args[1].equalsIgnoreCase("area")){
  637. cubeCreated=3;
  638. sender.sendMessage(ChatColor.AQUA+"Left Click 1st corner...");
  639. return true;
  640. }
  641. if(args[1].equalsIgnoreCase("around")){
  642. if(isNumber(args[2])){
  643. instantArea(((Player)sender).getLocation().subtract(Integer.parseInt(args[2]), 0, Integer.parseInt(args[2])), ((Player)sender).getLocation().add(Integer.parseInt(args[2]), Integer.parseInt(args[2]), Integer.parseInt(args[2])),((Player)sender));
  644. return true;
  645. }else{
  646. sender.sendMessage(ChatColor.YELLOW+"Radius must be an integer.");
  647. }
  648. }
  649. }
  650. if(args[0].equalsIgnoreCase("new")||args[0].equalsIgnoreCase("create")){
  651. if(args.length==2){
  652. if(!creator.isEmpty()){sender.sendMessage("Please wait... Another OP is creating a new area...");return true;}
  653. cubeCreated=1;
  654. cubeName=args[1].toLowerCase();
  655. creator=sender.getName().toLowerCase();
  656. sender.sendMessage(ChatColor.AQUA+"Left Click 1st corner...");
  657. sender.sendMessage(ChatColor.YELLOW+"Right Click to cancel...");
  658. return true;
  659. }
  660. }
  661. if(args[0].equalsIgnoreCase("remove")||args[0].equalsIgnoreCase("delete")){
  662. if(args.length==2){
  663. if(!creator.isEmpty()){sender.sendMessage("Please wait... Another OP is creating a new area...");return true;}
  664. if(areaWorld.containsKey(args[1].toLowerCase())){
  665. areaWorld.remove(args[1].toLowerCase());
  666. areaLoc1.remove(args[1].toLowerCase());
  667. areaLoc2.remove(args[1].toLowerCase());
  668. sender.sendMessage(ChatColor.LIGHT_PURPLE+"Area "+ChatColor.AQUA+"\""+ChatColor.YELLOW+args[1]+ChatColor.AQUA+"\""+ChatColor.LIGHT_PURPLE+" deleted.");
  669. }else{
  670. sender.sendMessage(ChatColor.YELLOW+"Area "+ChatColor.AQUA+"\""+ChatColor.YELLOW+args[1]+ChatColor.AQUA+"\""+ChatColor.YELLOW+" not found.");
  671. }
  672. return true;
  673. }
  674. }
  675. }
  676. }
  677. }
  678. }
  679. return false;
  680. }
  681. }