Skip to content

Commit

Permalink
Refactored for modern Bukkit (1.13+)
Browse files Browse the repository at this point in the history
Removed old large font
  • Loading branch information
lagnat committed May 31, 2019
1 parent 9779932 commit 69ad2b7
Show file tree
Hide file tree
Showing 20 changed files with 1,039 additions and 546 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
.classpath
.project
.settings/
.vscode/
target/


5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ SkyJot is a Bukkit Minecraft plugin for writing block letters in the sky. It wa
* Text direction is determined by the direction you are facing when you run the write command. Text will be left-to-right from the perspective of the player.

### Example
/skyjot write b:17:2 ~ ~ ~ Hello\nWorld
/skyjot write b:17:2 ~ ~ ~ Hello\nWorld

### Open Source
[github](https://github.com/lagnat/SkyJot)
22 changes: 5 additions & 17 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.allocinit</groupId>
<artifactId>SkyJot</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>BlockHunt</name>
<version>2.0.0-SNAPSHOT</version>
<name>SkyJot</name>

<repositories>
<repository>
Expand All @@ -17,31 +17,19 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.8.8-R0.1-SNAPSHOT</version>
<version>1.14.2-R0.1-SNAPSHOT</version>
</dependency>
</dependencies>

<build>
<resources>
<resource>
<targetPath>.</targetPath>
<filtering>true</filtering>
<directory>${basedir}/src/main/resources</directory>
<includes>
<include>plugin.yml</include>
</includes>
</resource>
</resources>

<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
Expand Down
64 changes: 64 additions & 0 deletions src/main/java/com/allocinit/bukkit/CommandPlugin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.allocinit.bukkit;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;

public class CommandPlugin extends JavaPlugin implements CommandExecutor {
private String cmdName;
private Map<String, SubCommand<?>> commands = new HashMap<>();

public CommandPlugin(String cmdName) {
this.cmdName = cmdName;
}

public void onEnable() {
try {
this.saveDefaultConfig();
} catch (Exception e) {
}

this.getCommand(cmdName).setExecutor(this);
}

protected void registerSubCommand(SubCommand<?> cmd) {
commands.put(cmd.getCommandName(), cmd);
}

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
try {
if (args.length == 0)
throw new UsageException();

SubCommand<?> cmd = commands.get(args[0]);

if (cmd == null)
throw new UsageException();

cmd.doCommand(sender, Arrays.copyOfRange(args, 1, args.length));
} catch (UsageException e) {
this.writeUsage(sender);
} catch (PermissionDeniedException e) {
sender.sendMessage(ChatColor.RED + "Permission Denied");
} catch (ErrorException e) {
sender.sendMessage(ChatColor.RED + e.getMessage());
} catch (Exception e) {
sender.sendMessage("Uncaught exception: " + e.getMessage());
}

return true;
}

public void writeUsage(CommandSender player) {
player.sendMessage("[" + ChatColor.GOLD + cmdName + ChatColor.WHITE + " usage]");
for (SubCommand<?> cmd : commands.values())
cmd.writeUsage(player);
}
}
9 changes: 9 additions & 0 deletions src/main/java/com/allocinit/bukkit/ErrorException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.allocinit.bukkit;

public class ErrorException extends RuntimeException {
private static final long serialVersionUID = 1L;

public ErrorException(String string) {
super(string);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.allocinit.bukkit;

public class PermissionDeniedException extends RuntimeException {
private static final long serialVersionUID = 1L;
}
29 changes: 29 additions & 0 deletions src/main/java/com/allocinit/bukkit/SubCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.allocinit.bukkit;

import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public abstract class SubCommand<T extends CommandPlugin> {
protected T plugin;
private String cmd;

public SubCommand(T plugin, String cmd) {
this.plugin = plugin;
this.cmd = cmd;
}

public String getCommandName() {
return this.cmd;
}

public abstract void doCommand(CommandSender sender, String[] args) throws Exception;

public abstract void writeUsage(CommandSender player);

protected void checkPerm(CommandSender sender, String perm) {
if (sender instanceof Player) {
if (!((Player) sender).hasPermission(perm))
throw new PermissionDeniedException();
}
}
}
5 changes: 5 additions & 0 deletions src/main/java/com/allocinit/bukkit/UsageException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.allocinit.bukkit;

public class UsageException extends RuntimeException {
private static final long serialVersionUID = 1L;
}
49 changes: 33 additions & 16 deletions src/main/java/com/allocinit/skyjot/Character.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,54 @@
import java.util.ArrayList;
import java.util.List;


public class Character
{
private List<Integer []> path = new ArrayList<>();
public class Character {
private List<Dot> path = new ArrayList<>();
private int width = 0;

public Character(String... rows)
{
for (int i = 0; i < rows.length; i++)
{
String row = rows [rows.length - i - 1];
public Character(String... rows) {
for (int i = 0; i < rows.length; i++) {
String row = rows[i];

for (int j = 0; j < row.length(); j++)
{
for (int j = 0; j < row.length(); j++) {
if (j >= width)
width = j + 1;

char dot = row.charAt(j);
if (dot != ' ')
path.add(new Integer [] { j, i });
path.add(new Dot(j, -i, dot));
}
}
}

public int getWidth()
{
public int getWidth() {
return width;
}

public List<Integer []> getPath()
{
public List<Dot> getPath() {
return path;
}

public static class Dot {
private int x;
private int y;
private char dot;

public Dot(int x, int y, char dot) {
this.x = x;
this.y = y;
this.dot = dot;
}

public int getX() {
return x;
}

public int getY() {
return y;
}

public char getDot() {
return dot;
}
}
}
27 changes: 13 additions & 14 deletions src/main/java/com/allocinit/skyjot/DirectionHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,34 @@
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;

class DirectionHelper
{
class DirectionHelper {
private double xAdd;
private double zAdd;
private Location location;

public DirectionHelper()
{
public DirectionHelper() {
}

public void setFromPlayerView(Player player)
{
Vector direction = player.getLocation().getDirection();
public Location getLocation() {
return location;
}

public void setFromPlayerView(Player player) {
location = player.getLocation();
Vector direction = location.getDirection();

direction.setY(0);

if (Math.abs(direction.getX()) < Math.abs(direction.getZ()))
{
if (Math.abs(direction.getX()) < Math.abs(direction.getZ())) {
xAdd = direction.getZ() > 0 ? -1 : 1;
zAdd = 0;
}
else
{
} else {
zAdd = direction.getX() < 0 ? -1 : 1;
xAdd = 0;
}
}

public void move(Location loc, int xoff, int yoff)
{
public void move(Location loc, int xoff, int yoff) {
loc.setX(loc.getX() + xoff * xAdd);
loc.setZ(loc.getZ() + xoff * zAdd);
loc.setY(loc.getY() + yoff);
Expand Down
Loading

0 comments on commit 69ad2b7

Please sign in to comment.