Created
May 3, 2012 23:37
-
-
Save Double0negative/2590409 to your computer and use it in GitHub Desktop.
Multi-Thread arena duper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.skitscape.survivalgames.util; | |
import java.lang.management.ManagementFactory; | |
import org.bukkit.Bukkit; | |
import org.bukkit.Location; | |
import org.bukkit.World; | |
import org.bukkit.util.Vector; | |
import com.skitscape.survivalgames.Game; | |
import com.skitscape.survivalgames.GameManager; | |
import com.skitscape.survivalgames.SettingsManager; | |
public class ArenaDuplicator { | |
public void startDupe(Vector v1, Vector v2){ | |
int factor = ManagementFactory.getOperatingSystemMXBean().getAvailableProcessors(); | |
//factor = 1; | |
int xspan = v2.getBlockX() - v1.getBlockX(); | |
int maxx = GameManager.getInstance().getGame(1).getArena().getMax().getBlockX(); | |
for(Game g: GameManager.getInstance().getGames()){ | |
Vector a1 = g.getArena().getMin(); | |
Vector a2 = g.getArena().getMax(); | |
if(a1.getBlockX()>maxx){ | |
maxx = a1.getBlockX(); | |
} | |
if(a2.getBlockX()>maxx){ | |
maxx = a2.getBlockX(); | |
} | |
} | |
int divf = xspan / factor; | |
for(int a = 1; a<=factor; a++){ | |
System.out.println(xspan); | |
int sp1 = divf * a + v1.getBlockX(); | |
int sp2 = divf * (a+1) + v1.getBlockX(); | |
int y1 = v1.getBlockY(); | |
int y2 = v2.getBlockY(); | |
int z1 = v1.getBlockZ(); | |
int z2 = v2.getBlockZ(); | |
Vector s1 = new Vector((sp1<sp2)?sp1:sp2 , (y1<y2)?y1:y2 , (z1<z2)?z1:z2); | |
Vector s2 = new Vector((sp1>sp2)?sp1:sp2 , (y1>y2)?y1:y2 , (z1>z2)?z1:z2); | |
System.out.println(s1); | |
System.out.println(s2); | |
new DupeThread(s1,s2, maxx - v1.getBlockX(), 0).start(); | |
} | |
} | |
class DupeThread extends Thread{ | |
World w = SettingsManager.getGameWorld(); | |
Vector min; | |
Vector max; | |
int xoff; | |
int zoff; | |
public DupeThread(Vector min, Vector max, int xoff, int yoff){ | |
this.min = min; | |
this.max = max; | |
this.xoff = xoff; | |
this.zoff = yoff; | |
} | |
public void run(){ | |
Bukkit.getServer().broadcastMessage("Starting "); | |
for(int x = min.getBlockX(); x<max.getBlockX();x++){ | |
for(int y = min.getBlockY(); y<max.getBlockY();y++){ | |
for(int z = min.getBlockZ(); z<max.getBlockZ();z++){ | |
Location l1 = new Location(w,x,y,z); | |
Location l2 = new Location(w,x+xoff, y, z+zoff); | |
// System.out.println(l1); | |
// System.out.println(l2); | |
//if(w.getBlockTypeIdAt(l1) != w.getBlockTypeIdAt(l2)){ | |
w.getBlockAt(l2).setTypeId(w.getBlockTypeIdAt(l1)); | |
w.getBlockAt(l2).setData(w.getBlockAt(l1).getData()); | |
// w.getBlockAt(l2).getState().update(); | |
// System.out.println(l2); | |
// } | |
} | |
} | |
} | |
Bukkit.getServer().broadcastMessage("Ending "); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment