Skip to content

Commit 8e7d7af

Browse files
committed
Initial commit.
0 parents  commit 8e7d7af

File tree

8 files changed

+1067
-0
lines changed

8 files changed

+1067
-0
lines changed

.gitignore

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Eclipse
2+
/.classpath
3+
/.project
4+
/.settings
5+
6+
# IntelliJ
7+
/.idea
8+
*.iml
9+
10+
# we use maven!
11+
/build.xml
12+
13+
# maven
14+
/target
15+
16+
# vim
17+
.*.sw[a-p]
18+
*~
19+
20+
# AWS map repository
21+
/s3
22+
23+
# various other potential build files
24+
/build
25+
/bin
26+
/dist
27+
/manifest.mf
28+
29+
# Mac filesystem dust
30+
/.DS_Store

.travis.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
language: java
2+
3+
jdk:
4+
- openjdk7
5+
- oraclejdk7
6+
- openjdk6
7+
8+
before_script:
9+
- git clone https://github.com/rmct/AutoReferee.git
10+
- pushd AutoReferee && mvn clean package install && popd

LICENSE.txt

+674
Large diffs are not rendered by default.

pom.xml

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
<!--
2+
Maven build file for AutoReferee
3+
Copyright (c) 2013 RMCT <http://www.reddit.com/r/mctourney>
4+
Licensed under GPL 3.0
5+
-->
6+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
7+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
8+
<modelVersion>4.0.0</modelVersion>
9+
10+
<groupId>org.mctourney.autoreferee</groupId>
11+
<artifactId>AutoRefereeUHC</artifactId>
12+
<version>0.1</version>
13+
<name>AutoReferee Ultra Hardcore Plugin</name>
14+
<url>http://www.reddit.com/r/mctourney</url>
15+
<description>AutoReferee addon: Manage ultrahardcore matches.</description>
16+
17+
<properties>
18+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
19+
<bukkit.version>1.4.7-R1.0</bukkit.version>
20+
<java.target.version>1.6</java.target.version>
21+
<autoreferee.version>2.1</autoreferee.version>
22+
</properties>
23+
24+
<scm>
25+
<connection>scm:git:git://github.com/rmct/AutoRefereeUHC.git</connection>
26+
<url>https://github.com/rmct/AutoRefereeUHC</url>
27+
<developerConnection>scm:git:[email protected]:rmct/AutoRefereeUHC.git</developerConnection>
28+
</scm>
29+
30+
<repositories>
31+
<repository>
32+
<id>bukkit-repo</id>
33+
<url>http://repo.bukkit.org/content/groups/public/</url>
34+
</repository>
35+
</repositories>
36+
37+
<dependencies>
38+
<!-- Bukkit -->
39+
<dependency>
40+
<groupId>org.bukkit</groupId>
41+
<artifactId>bukkit</artifactId>
42+
<version>${bukkit.version}</version>
43+
</dependency>
44+
45+
<dependency>
46+
<groupId>org.mctourney.autoreferee</groupId>
47+
<artifactId>AutoReferee</artifactId>
48+
<version>${autoreferee.version}</version>
49+
</dependency>
50+
51+
<dependency>
52+
<groupId>commons-collections</groupId>
53+
<artifactId>commons-collections</artifactId>
54+
<version>3.2</version>
55+
</dependency>
56+
</dependencies>
57+
58+
<build>
59+
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
60+
61+
<!-- Resources -->
62+
<resources>
63+
<resource>
64+
<targetPath>.</targetPath>
65+
<filtering>true</filtering>
66+
<directory>${basedir}/src/main/resources/</directory>
67+
<includes>
68+
<include>plugin.yml</include>
69+
</includes>
70+
</resource>
71+
</resources>
72+
73+
<plugins>
74+
<plugin>
75+
<groupId>org.codehaus.mojo</groupId>
76+
<artifactId>buildnumber-maven-plugin</artifactId>
77+
<version>1.1</version>
78+
<executions>
79+
<execution>
80+
<phase>validate</phase>
81+
<goals>
82+
<goal>create</goal>
83+
</goals>
84+
</execution>
85+
</executions>
86+
</plugin>
87+
88+
<plugin>
89+
<groupId>org.apache.maven.plugins</groupId>
90+
<artifactId>maven-surefire-plugin</artifactId>
91+
<version>2.11</version>
92+
</plugin>
93+
94+
<plugin>
95+
<groupId>org.apache.maven.plugins</groupId>
96+
<artifactId>maven-compiler-plugin</artifactId>
97+
<version>2.3.2</version>
98+
<configuration>
99+
<source>${java.target.version}</source>
100+
<target>${java.target.version}</target>
101+
<showDeprecation>true</showDeprecation>
102+
<showWarnings>true</showWarnings>
103+
<fork>true</fork>
104+
</configuration>
105+
</plugin>
106+
107+
<plugin>
108+
<groupId>org.apache.maven.plugins</groupId>
109+
<artifactId>maven-shade-plugin</artifactId>
110+
<version>1.7</version>
111+
<executions>
112+
<execution>
113+
<phase>package</phase>
114+
<goals>
115+
<goal>shade</goal>
116+
</goals>
117+
<configuration>
118+
<minimizeJar>true</minimizeJar>
119+
<artifactSet>
120+
<includes>
121+
<include>commons-collections:commons-collections</include>
122+
</includes>
123+
</artifactSet>
124+
</configuration>
125+
</execution>
126+
</executions>
127+
</plugin>
128+
</plugins>
129+
</build>
130+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package org.mctourney.autoreferee;
2+
3+
import org.bukkit.plugin.java.JavaPlugin;
4+
import org.mctourney.autoreferee.commands.UHCCommands;
5+
6+
public class AutoRefereeUHC extends JavaPlugin
7+
{
8+
public static final String WORLD_PREFIX = "world-aruhc-";
9+
10+
private static AutoRefereeUHC instance = null;
11+
12+
public static AutoRefereeUHC getInstance()
13+
{ return instance; }
14+
15+
@Override
16+
public void onEnable()
17+
{
18+
AutoRefereeUHC.instance = this;
19+
20+
AutoReferee ar = AutoReferee.getInstance();
21+
22+
ar.getCommandManager().registerCommands(new UHCCommands(ar), ar);
23+
24+
getLogger().info(this.getName() + " enabled.");
25+
}
26+
27+
@Override
28+
public void onDisable()
29+
{
30+
getLogger().info(this.getName() + " disabled.");
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
package org.mctourney.autoreferee;
2+
3+
import java.util.List;
4+
import java.util.LinkedList;
5+
import java.util.Collections;
6+
import java.util.Comparator;
7+
8+
import org.bukkit.ChatColor;
9+
import org.bukkit.Chunk;
10+
import org.bukkit.World;
11+
import org.bukkit.entity.Player;
12+
import org.bukkit.command.CommandSender;
13+
import org.bukkit.scheduler.BukkitRunnable;
14+
15+
import com.google.common.collect.Lists;
16+
17+
import org.mctourney.autoreferee.regions.AutoRefRegion;
18+
import org.mctourney.autoreferee.regions.CuboidRegion;
19+
20+
public class UHCMatch extends AutoRefMatch
21+
{
22+
// size of a default
23+
public static final int DEFAULT_SIZE = 1024;
24+
25+
protected boolean losersBecomeSpectators = false;
26+
27+
protected boolean acceptingPlayers = false;
28+
29+
private WorldPregenerationTask worldgen = null;
30+
31+
public class WorldPregenerationTask extends BukkitRunnable
32+
{
33+
private static final int CHUNKS_PER_STEP = 1;
34+
35+
private int totalChunks = 0;
36+
37+
public CommandSender recipient = null;
38+
39+
private LinkedList<Chunk> chunkQueue = Lists.newLinkedList();
40+
41+
// compares distance of chunk to spawn, places chunks nearer spawn earlier in queue
42+
public class ChunkSorter implements Comparator<Chunk>
43+
{
44+
public int compare(Chunk a, Chunk b)
45+
{
46+
int amax = Math.max(Math.abs(a.getX()), Math.abs(a.getZ()));
47+
int bmax = Math.max(Math.abs(b.getX()), Math.abs(b.getZ()));
48+
if (amax != bmax) return amax - bmax;
49+
50+
int amin = Math.min(Math.abs(a.getX()), Math.abs(a.getZ()));
51+
int bmin = Math.min(Math.abs(b.getX()), Math.abs(b.getZ()));
52+
return amin - bmin;
53+
}
54+
}
55+
56+
public WorldPregenerationTask(World w, int radius)
57+
{
58+
for (int x = -radius; x <= radius; ++x)
59+
for (int z = -radius; z <= radius; ++z)
60+
this.chunkQueue.add(w.getChunkAt(x, z));
61+
62+
this.totalChunks = this.chunkQueue.size();
63+
64+
// sort chunks on distance to spawn
65+
Collections.sort(chunkQueue, new ChunkSorter());
66+
}
67+
68+
private WorldPregenerationTask(AutoRefRegion region)
69+
{
70+
CuboidRegion bound = region.getBoundingCuboid();
71+
72+
World w = bound.world;
73+
74+
// get extremes of the bounding region
75+
Chunk bmin = w.getChunkAt(bound.getMinimumPoint());
76+
Chunk bmax = w.getChunkAt(bound.getMaximumPoint());
77+
78+
for (int x = bmin.getX(); x <= bmax.getX(); ++x)
79+
for (int z = bmin.getZ(); z <= bmax.getZ(); ++z)
80+
this.chunkQueue.add(w.getChunkAt(x, z));
81+
82+
this.totalChunks = this.chunkQueue.size();
83+
84+
// sort chunks on distance to spawn
85+
Collections.sort(chunkQueue, new ChunkSorter());
86+
}
87+
88+
@Override
89+
public void run()
90+
{
91+
// load a batch of chunks
92+
for (int i = CHUNKS_PER_STEP; i > 0 && this.chunkQueue.size() > 0; --i)
93+
this.chunkQueue.removeFirst().load(true);
94+
95+
int percent = (this.totalChunks - this.chunkQueue.size()) * 100 / this.totalChunks;
96+
String update = String.format("%d%% chunks generated", percent);
97+
UHCMatch.this.broadcast(ChatColor.DARK_GRAY + update);
98+
99+
if (this.recipient != null && (!(this.recipient instanceof Player)
100+
|| ((Player) this.recipient).getWorld() != UHCMatch.this.getWorld()))
101+
this.recipient.sendMessage(ChatColor.DARK_GRAY + update);
102+
}
103+
}
104+
105+
public UHCMatch(World world, int size, boolean tmp)
106+
{
107+
super(world, tmp);
108+
109+
this.setRespawnMode(RespawnMode.DISALLOW);
110+
111+
// to compute chunk radius, take size in blocks, divide by 16 (to get size in
112+
// chunks), then divide by 2 to convert diameter to radius.
113+
this.worldgen = new WorldPregenerationTask(world, size/32);
114+
this.worldgen.runTaskTimer(AutoRefereeUHC.getInstance(), 0L, 20L);
115+
}
116+
117+
public void setNotificationRecipient(CommandSender recp)
118+
{ if (this.worldgen != null) this.worldgen.recipient = recp; }
119+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package org.mctourney.autoreferee.commands;
2+
3+
import org.bukkit.Bukkit;
4+
import org.bukkit.WorldCreator;
5+
import org.bukkit.command.CommandSender;
6+
import org.bukkit.plugin.Plugin;
7+
8+
import org.apache.commons.cli.CommandLine;
9+
10+
import org.mctourney.autoreferee.AutoRefMatch;
11+
import org.mctourney.autoreferee.AutoReferee;
12+
import org.mctourney.autoreferee.AutoRefereeUHC;
13+
import org.mctourney.autoreferee.UHCMatch;
14+
import org.mctourney.autoreferee.util.commands.AutoRefCommand;
15+
import org.mctourney.autoreferee.util.commands.AutoRefPermission;
16+
import org.mctourney.autoreferee.util.commands.CommandHandler;
17+
18+
import java.util.Date;
19+
20+
public class UHCCommands implements CommandHandler
21+
{
22+
AutoReferee plugin;
23+
24+
public UHCCommands(Plugin plugin)
25+
{
26+
this.plugin = (AutoReferee) plugin;
27+
}
28+
29+
@AutoRefCommand(name={"autoref", "uhc"}, argmax=0, options="s+g+z+",
30+
description="Load a UHC match.")
31+
@AutoRefPermission(console=true, nodes={"autoreferee.admin"})
32+
33+
public boolean loadUHC(CommandSender sender, AutoRefMatch match, String[] args, CommandLine options)
34+
{
35+
String worldname = AutoRefereeUHC.WORLD_PREFIX + Long.toHexString(new Date().getTime());
36+
WorldCreator creator = WorldCreator.name(worldname);
37+
38+
int size = UHCMatch.DEFAULT_SIZE;
39+
if (options.hasOption('z'))
40+
{
41+
String szopt = options.getOptionValue('z');
42+
try { size = Integer.parseInt(szopt); }
43+
catch (NumberFormatException e)
44+
{ sender.sendMessage("Not a valid size: " + szopt); }
45+
}
46+
47+
if (options.hasOption('s'))
48+
{
49+
// parse out the provided seed (numbers are converted verbatim)
50+
long seed = options.getOptionValue('s').hashCode();
51+
try { seed = Long.parseLong(options.getOptionValue('s')); }
52+
catch (NumberFormatException e) { }
53+
54+
// set the seed for the world creator
55+
creator.seed(seed);
56+
}
57+
58+
// TODO Custom Generator
59+
60+
// TODO Move this to a sync thread
61+
match = new UHCMatch(Bukkit.createWorld(creator), size, true);
62+
plugin.addMatch(match);
63+
return true;
64+
}
65+
}

src/main/resources/plugin.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name: AutoRefereeUHC
2+
main: org.mctourney.autoreferee.AutoRefereeUHC
3+
version: 0.1
4+
author: authorblues
5+
6+
depend:
7+
- AutoReferee

0 commit comments

Comments
 (0)