Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jgoett154 committed Nov 8, 2014
1 parent 86a4fe5 commit d2146b5
Show file tree
Hide file tree
Showing 48 changed files with 556 additions and 560 deletions.
8 changes: 4 additions & 4 deletions src/main/java/mytown/MyTown.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public void preInit(FMLPreInitializationEvent ev) {
// Register ICrashCallable's
FMLCommonHandler.instance().registerCrashCallable(new DatasourceCrashCallable());

if(ev.getSide() == Side.SERVER) {
if (ev.getSide() == Side.SERVER) {
isCauldron = MinecraftServer.getServer().getServerModName().contains("cauldron") || MinecraftServer.getServer().getServerModName().contains("mcpc");
if(isCauldron)
if (isCauldron)
BukkitCompat.getInstance().loadPEX(ev.getSourceFile());
//MyTown.instance.log.info("Server is using cauldron or some implementation between forge and bukkit/spigot.");
}
Expand Down Expand Up @@ -118,7 +118,7 @@ public void serverStopping(FMLServerStoppingEvent ev) {
private void registerCommands() {
Method m = null;
try {
if(isCauldron && BukkitCompat.getInstance().hasPlugin("PermissionsEx")) {
if (isCauldron && BukkitCompat.getInstance().hasPlugin("PermissionsEx")) {
m = PEXCompat.class.getMethod("firstPermissionBreachPEX", String.class, ICommandSender.class);
} else {
m = Commands.class.getMethod("firstPermissionBreach", String.class, ICommandSender.class);
Expand All @@ -130,7 +130,7 @@ private void registerCommands() {

CommandManager.registerCommands(CommandsEveryone.class, m);
CommandManager.registerCommands(CommandsAssistant.class, m);
if(Config.modifiableRanks)
if (Config.modifiableRanks)
CommandManager.registerCommands(CommandsAssistant.ModifyRanks.class, m);

CommandManager.registerCommands(CommandsAdmin.class);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/mytown/api/events/TownEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public TownDeleteEvent(Town town) {
// TODO: Make them cancelable?
public static class TownEnterEvent extends TownEvent {
public Resident resident = null;

public TownEnterEvent(Town town, Resident resident) {
super(town);
this.resident = resident;
Expand All @@ -41,6 +42,7 @@ public TownEnterEvent(Town town, Resident resident) {

public static class TownEnterInRangeEvent extends TownEvent {
public Resident resident = null;

public TownEnterInRangeEvent(Town town, Resident resident) {
super(town);
this.resident = resident;
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/mytown/api/interfaces/IBlockWhitelister.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package mytown.api.interfaces;

import mytown.entities.Plot;
import mytown.entities.Town;
import mytown.entities.flag.FlagType;

/**
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/mytown/api/interfaces/IHasBlockWhitelists.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ public interface IHasBlockWhitelists {
void addBlockWhitelist(BlockWhitelist bw);

boolean hasBlockWhitelist(BlockWhitelist bw);

boolean hasBlockWhitelist(int dim, int x, int y, int z, FlagType flagType);

void removeBlockWhitelist(BlockWhitelist bw);

void removeBlockWhitelist(int dim, int x, int y, int z, FlagType flagType);

BlockWhitelist getBlockWhitelist(int dim, int x, int y, int z, FlagType flagType);

List<BlockWhitelist> getWhitelists();
}
1 change: 1 addition & 0 deletions src/main/java/mytown/api/interfaces/IHasBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public interface IHasBlocks {

/**
* Sets the number of extra blocks it can have.
*
* @param extra
*/
public void setExtraBlocks(int extra);
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/mytown/api/interfaces/IHasFlags.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import mytown.entities.flag.Flag;
import mytown.entities.flag.FlagType;

import java.util.List;

/**
* Created by AfterWind on 8/26/2014.
* Why do we need interfaces for this?
Expand Down
50 changes: 24 additions & 26 deletions src/main/java/mytown/commands/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import mytown.util.exceptions.MyTownCommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ChatComponentText;
Expand Down Expand Up @@ -63,21 +62,21 @@ public static boolean callSubFunctions(ICommandSender sender, List<String> args,
public static void sendHelpMessage(ICommandSender sender, String permissionBase) {
List<String> scList = CommandManager.getSubCommandsList(permissionBase);
String command = null;
for(String s = permissionBase; s != null; s = CommandManager.getParentPermNode(s)) {
if(command == null)
for (String s = permissionBase; s != null; s = CommandManager.getParentPermNode(s)) {
if (command == null)
command = CommandManager.commandNames.get(s);
else
command = new StringBuilder(command).insert(0, CommandManager.commandNames.get(s) + " ").toString();
}
sendMessageBackToSender(sender, "/" + command + ": ");
for(String s : scList) {
for (String s : scList) {
sendMessageBackToSender(sender, " " + CommandManager.commandNames.get(s) + ": " + getLocal().getLocalization(s + ".help"));
}
}

public static void sendHelpMessageWithArgs(ICommandSender sender, List<String> args, String permBase) {
String node;
if(args.size() < 1) {
if (args.size() < 1) {
//If no arguments are provided then we check for the base permission
node = permBase;
} else {
Expand All @@ -87,9 +86,9 @@ public static void sendHelpMessageWithArgs(ICommandSender sender, List<String> a

String command = "/" + CommandManager.commandNames.get(permBase);
String prevNode = permBase;
for(String s : args) {
for (String s : args) {
String t = CommandManager.getSubCommandNode(s, prevNode);
if(t != null) {
if (t != null) {
command += " " + s;
prevNode = t;
} else
Expand All @@ -98,7 +97,7 @@ public static void sendHelpMessageWithArgs(ICommandSender sender, List<String> a

sendMessageBackToSender(sender, command);
List<String> scList = CommandManager.getSubCommandsList(node);
if(scList == null || scList.size() == 0) {
if (scList == null || scList.size() == 0) {
sendMessageBackToSender(sender, " " + getLocal().getLocalization(node + ".help"));
} else {
for (String s : scList) {
Expand All @@ -108,13 +107,12 @@ public static void sendHelpMessageWithArgs(ICommandSender sender, List<String> a
}



public static boolean firstPermissionBreach(String permission, ICommandSender sender) {
// Since everybody should have permission to /t
if (permission.equals("mytown.cmd"))
return true;

if(!(sender instanceof EntityPlayer))
if (!(sender instanceof EntityPlayer))
return true;

Resident res = getDatasource().getOrMakeResident(sender);
Expand Down Expand Up @@ -201,21 +199,21 @@ public static ImmutableList<Town> getInvitesFromResident(Resident res) {

public static Flag getFlagFromType(IHasFlags hasFlags, FlagType flagType) {
Flag flag = hasFlags.getFlag(flagType);
if(flag == null)
if (flag == null)
throw new MyTownCommandException("mytown.cmd.err.flagNotExists", flagType.toString());
return flag;
}

public static Flag getFlagFromName(IHasFlags hasFlags, String name) {
Flag flag = hasFlags.getFlag(FlagType.valueOf(name));
if(flag == null)
if (flag == null)
throw new MyTownCommandException("mytown.cmd.err.flagNotExists", name);
return flag;
}

public static TownBlock getBlockAtResident(Resident res) {
TownBlock block = getDatasource().getBlock(res.getPlayer().dimension, res.getPlayer().chunkCoordX, res.getPlayer().chunkCoordZ);
if(block == null)
if (block == null)
throw new MyTownCommandException("mytown.cmd.err.claim.notexist", res.getSelectedTown());
return block;
}
Expand Down Expand Up @@ -255,28 +253,28 @@ public static FlagType getFlagTypeFromName(String name) {
}

public static int getPaymentStack(ICommandSender sender, int minAmount) {
if(!(sender instanceof EntityPlayer))
if (!(sender instanceof EntityPlayer))
throw new MyTownCommandException("The sender is not a player!");
if(minAmount == 0)
if (minAmount == 0)
return 0;
EntityPlayer player = (EntityPlayer)sender;
EntityPlayer player = (EntityPlayer) sender;
int stackNumber = -1;
for(int i = 0; i < player.inventory.mainInventory.length; i++) {
for (int i = 0; i < player.inventory.mainInventory.length; i++) {
ItemStack itemStack = player.inventory.mainInventory[i];
if(itemStack == null)
if (itemStack == null)
continue;
if(GameRegistry.findUniqueIdentifierFor(itemStack.getItem()).name.equals(Config.costItemName) && itemStack.stackSize >= minAmount) {
if (GameRegistry.findUniqueIdentifierFor(itemStack.getItem()).name.equals(Config.costItemName) && itemStack.stackSize >= minAmount) {
stackNumber = i;
break;
}
}
if(stackNumber == -1)
if (stackNumber == -1)
throw new MyTownCommandException("mytown.cmd.err.cost", minAmount, Config.costItemName);
return stackNumber;
}

public static void sendMessageBackToSender(ICommandSender sender, String message) {
if(sender instanceof EntityPlayer) {
if (sender instanceof EntityPlayer) {
Resident res = getDatasource().getOrMakeResident(sender);
res.sendMessage(message);
} else {
Expand All @@ -285,16 +283,16 @@ public static void sendMessageBackToSender(ICommandSender sender, String message
}

public static void returnPaymentStack(ICommandSender sender, int amount) {
if(sender instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer)sender;
if (sender instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) sender;
String[] itemName = Config.costItemName.split(":");
Item item;
if(itemName.length > 1) {
if (itemName.length > 1) {
item = GameRegistry.findItem(itemName[0], itemName[1]);
} else {
item = (Item)Item.itemRegistry.getObject(Config.costItemName);
item = (Item) Item.itemRegistry.getObject(Config.costItemName);
}
for(int left = amount; left > 0; left -= 64) {
for (int left = amount; left > 0; left -= 64) {
ItemStack stack = new ItemStack(item, left > 64 ? 64 : left);
//stack = addToInventory(player.inventory, stack);
if (!player.inventory.addItemStackToInventory(stack)) {
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/mytown/commands/CommandsAdmin.java
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public static void permTownCommand(ICommandSender sender, List<String> args, Lis
nonPlayers = true,
completionKeys = {"townCompletion"})
public static void permTownListCommand(ICommandSender sender, List<String> args) {
if(args.size() < 1) {
if (args.size() < 1) {
throw new MyTownWrongUsageException("mytown.adm.cmd.usage.perm.list");
}

Expand Down Expand Up @@ -298,7 +298,7 @@ public static void permTownListCommand(ICommandSender sender, List<String> args)
nonPlayers = true,
completionKeys = {"townCompletion", "flagCompletion"})
public static void permTownSetCommand(ICommandSender sender, List<String> args) {
if(args.size() < 3) {
if (args.size() < 3) {
throw new MyTownWrongUsageException("mytown.adm.cmd.usage.perm.town.set");
}

Expand All @@ -320,14 +320,14 @@ public static void permTownSetCommand(ICommandSender sender, List<String> args)
parentName = "mytown.adm.cmd.perm.town",
completionKeys = {"townCompletion", "flagCompletionWhitelist"})
public static void permTownWhitelistCommand(ICommandSender sender, List<String> args, List<String> subCommands) {
if(args.size() < 2)
if (args.size() < 2)
throw new MyTownCommandException("mytown.cmd.usage.plot.whitelist.add");

Resident res = getDatasource().getOrMakeResident(sender);
Town town = getTownFromName(args.get(0));
FlagType flagType = getFlagTypeFromName(args.get(1));

if(flagType.isWhitelistable())
if (flagType.isWhitelistable())
res.startBlockSelection(flagType, town.getName(), false);
else
throw new MyTownCommandException("mytown.cmd.err.flag.notForWhitelist");
Expand Down Expand Up @@ -358,7 +358,7 @@ public static void permWildListCommand(ICommandSender sender, List<String> args)
}
formattedFlagList += flag;
}
if(formattedFlagList != null)
if (formattedFlagList != null)
sendMessageBackToSender(sender, formattedFlagList);
else
sendMessageBackToSender(sender, getLocal().getLocalization("mytown.cmd.err.flag.list"));
Expand All @@ -371,7 +371,7 @@ public static void permWildListCommand(ICommandSender sender, List<String> args)
nonPlayers = true,
completionKeys = {"flagCompletion"})
public static void permWildSetCommand(ICommandSender sender, List<String> args) {
if(args.size() < 2) {
if (args.size() < 2) {
throw new MyTownWrongUsageException("mytown.adm.cmd.usage.perm.wild.set");
}
FlagType type = getFlagTypeFromName(args.get(0));
Expand Down Expand Up @@ -403,7 +403,7 @@ public static void claimCommand(ICommandSender sender, List<String> args) {
throw new MyTownCommandException("mytown.cmd.err.claim.already");
if (CommandsAssistant.checkNearby(player.dimension, player.chunkCoordX, player.chunkCoordZ, town)) // Checks if the player can claim far
throw new MyTownCommandException("mytown.cmd.err.farClaim.unimplemented");
//Assert.Perm(player, "mytown.cmd.assistant.claim.far");
//Assert.Perm(player, "mytown.cmd.assistant.claim.far");
TownBlock block = getDatasource().newBlock(player.dimension, player.chunkCoordX, player.chunkCoordZ, town);
if (block == null)
throw new MyTownCommandException("Failed to create Block"); // TODO Localize
Expand Down
Loading

0 comments on commit d2146b5

Please sign in to comment.