forked from Bukkit/CraftBukkit
-
Notifications
You must be signed in to change notification settings - Fork 16
Skullrefactor #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mart2967
wants to merge
7
commits into
NicMcPhee:master
Choose a base branch
from
mart2967:skullrefactor
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Skullrefactor #16
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1006bd5
Refactored a if-else tower in CraftEventFactory.java to be a hashmap. It
mart2967 f6e47ae
amended previous; removed reformatting mess and made the sourceToCause
mart2967 8a2f501
Merge branch 'master' of https://github.com/mart2967/CraftBukkit.git
mart2967 4834ac7
added back file that git deleted
mart2967 7849208
Restored our changes
mart2967 c43c4a4
Created two Hashmaps which has some id and an object, and created a
mart2967 f3cf4d3
reverting to fresher branch
mart2967 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,11 @@ | ||
| package org.bukkit.craftbukkit.block; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Iterator; | ||
| import java.util.Map; | ||
|
|
||
| import com.google.common.base.Strings; | ||
| import com.google.common.collect.Multiset.Entry; | ||
|
|
||
| import net.minecraft.server.TileEntitySkull; | ||
|
|
||
|
|
@@ -16,6 +21,8 @@ public class CraftSkull extends CraftBlockState implements Skull { | |
| private SkullType skullType; | ||
| private byte rotation; | ||
| private final int MAX_OWNER_LENGTH = 16; | ||
| private static HashMap<Integer, SkullType> idToSkullType; | ||
| private static HashMap<Byte, BlockFace> idToBlockFace; | ||
|
|
||
| public CraftSkull(final Block block) { | ||
| super(block); | ||
|
|
@@ -25,118 +32,76 @@ public CraftSkull(final Block block) { | |
| player = skull.getExtraType(); | ||
| skullType = getSkullType(skull.getSkullType()); | ||
| rotation = (byte) skull.getRotation(); | ||
|
|
||
| idToSkullType = new HashMap<Integer, SkullType>(); | ||
| idToSkullType.put(0, SkullType.SKELETON); | ||
| idToSkullType.put(1, SkullType.WITHER); | ||
| idToSkullType.put(2, SkullType.ZOMBIE); | ||
| idToSkullType.put(3, SkullType.PLAYER); | ||
| idToSkullType.put(4, SkullType.CREEPER); | ||
|
|
||
| idToBlockFace = new HashMap<Byte, BlockFace>(); | ||
| idToBlockFace.put((byte) 0, BlockFace.NORTH); | ||
| idToBlockFace.put((byte) 1, BlockFace.NORTH_NORTH_EAST); | ||
| idToBlockFace.put((byte) 2, BlockFace.NORTH_EAST); | ||
| idToBlockFace.put((byte) 3, BlockFace.EAST_NORTH_EAST); | ||
| idToBlockFace.put((byte) 4, BlockFace.EAST); | ||
| idToBlockFace.put((byte) 5, BlockFace.EAST_SOUTH_EAST); | ||
| idToBlockFace.put((byte) 6, BlockFace.SOUTH_EAST); | ||
| idToBlockFace.put((byte) 7, BlockFace.SOUTH_SOUTH_EAST); | ||
| idToBlockFace.put((byte) 8, BlockFace.SOUTH); | ||
| idToBlockFace.put((byte) 9, BlockFace.SOUTH_SOUTH_WEST); | ||
| idToBlockFace.put((byte) 10, BlockFace.SOUTH_WEST); | ||
| idToBlockFace.put((byte) 11, BlockFace.WEST_SOUTH_WEST); | ||
| idToBlockFace.put((byte) 12, BlockFace.WEST); | ||
| idToBlockFace.put((byte) 13, BlockFace.WEST_NORTH_WEST); | ||
| idToBlockFace.put((byte) 14, BlockFace.NORTH_WEST); | ||
| idToBlockFace.put((byte) 15, BlockFace.NORTH_NORTH_WEST); | ||
| } | ||
|
|
||
| // TODO: test this to see if it works!: :#3 | ||
| public static <E, T> Object getIdFromObject(HashMap<T, E> map, E value) { | ||
| Iterator<Map.Entry<T, E>> iterator = map.entrySet().iterator(); | ||
| while (iterator.hasNext()) { | ||
| Map.Entry<T, E> entry = iterator.next(); | ||
| if (entry.getValue().equals(value)) { | ||
| return entry.getKey(); | ||
| } | ||
| } | ||
| throw new AssertionError(value); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you want to throw the error from here, or return |
||
| } | ||
|
|
||
| static SkullType getSkullType(int id) { | ||
| switch (id) { | ||
| case 0: | ||
| return SkullType.SKELETON; | ||
| case 1: | ||
| return SkullType.WITHER; | ||
| case 2: | ||
| return SkullType.ZOMBIE; | ||
| case 3: | ||
| return SkullType.PLAYER; | ||
| case 4: | ||
| return SkullType.CREEPER; | ||
| default: | ||
| throw new AssertionError(id); | ||
| SkullType result = idToSkullType.get(id); | ||
| if (result != null) { | ||
| return result; | ||
| } | ||
| throw new AssertionError(id); | ||
| } | ||
|
|
||
| static int getSkullType(SkullType type) { | ||
| switch(type) { | ||
| case SKELETON: | ||
| return 0; | ||
| case WITHER: | ||
| return 1; | ||
| case ZOMBIE: | ||
| return 2; | ||
| case PLAYER: | ||
| return 3; | ||
| case CREEPER: | ||
| return 4; | ||
| default: | ||
| throw new AssertionError(type); | ||
| Integer result = (Integer) getIdFromObject(idToSkullType, type); | ||
| if (result != null) { | ||
| return result; | ||
| } | ||
| throw new AssertionError(type); | ||
| } | ||
|
|
||
| static byte getBlockFace(BlockFace rotation) { | ||
| switch (rotation) { | ||
| case NORTH: | ||
| return 0; | ||
| case NORTH_NORTH_EAST: | ||
| return 1; | ||
| case NORTH_EAST: | ||
| return 2; | ||
| case EAST_NORTH_EAST: | ||
| return 3; | ||
| case EAST: | ||
| return 4; | ||
| case EAST_SOUTH_EAST: | ||
| return 5; | ||
| case SOUTH_EAST: | ||
| return 6; | ||
| case SOUTH_SOUTH_EAST: | ||
| return 7; | ||
| case SOUTH: | ||
| return 8; | ||
| case SOUTH_SOUTH_WEST: | ||
| return 9; | ||
| case SOUTH_WEST: | ||
| return 10; | ||
| case WEST_SOUTH_WEST: | ||
| return 11; | ||
| case WEST: | ||
| return 12; | ||
| case WEST_NORTH_WEST: | ||
| return 13; | ||
| case NORTH_WEST: | ||
| return 14; | ||
| case NORTH_NORTH_WEST: | ||
| return 15; | ||
| default: | ||
| throw new IllegalArgumentException("Invalid BlockFace rotation: " + rotation); | ||
| Byte result = (Byte) getIdFromObject(idToBlockFace, rotation); | ||
| if(result != null){ | ||
| return result; | ||
| } | ||
| throw new IllegalArgumentException("Invalid BlockFace rotation: " + rotation); | ||
|
|
||
| } | ||
|
|
||
| static BlockFace getBlockFace(byte rotation) { | ||
| switch (rotation) { | ||
| case 0: | ||
| return BlockFace.NORTH; | ||
| case 1: | ||
| return BlockFace.NORTH_NORTH_EAST; | ||
| case 2: | ||
| return BlockFace.NORTH_EAST; | ||
| case 3: | ||
| return BlockFace.EAST_NORTH_EAST; | ||
| case 4: | ||
| return BlockFace.EAST; | ||
| case 5: | ||
| return BlockFace.EAST_SOUTH_EAST; | ||
| case 6: | ||
| return BlockFace.SOUTH_EAST; | ||
| case 7: | ||
| return BlockFace.SOUTH_SOUTH_EAST; | ||
| case 8: | ||
| return BlockFace.SOUTH; | ||
| case 9: | ||
| return BlockFace.SOUTH_SOUTH_WEST; | ||
| case 10: | ||
| return BlockFace.SOUTH_WEST; | ||
| case 11: | ||
| return BlockFace.WEST_SOUTH_WEST; | ||
| case 12: | ||
| return BlockFace.WEST; | ||
| case 13: | ||
| return BlockFace.WEST_NORTH_WEST; | ||
| case 14: | ||
| return BlockFace.NORTH_WEST; | ||
| case 15: | ||
| return BlockFace.NORTH_NORTH_WEST; | ||
| default: | ||
| throw new AssertionError(rotation); | ||
| BlockFace result = idToBlockFace.get(rotation); | ||
| if (result != null) { | ||
| return result; | ||
| } | ||
| throw new IllegalArgumentException("Invalid BlockFace rotation: "+ rotation); | ||
| } | ||
|
|
||
| public boolean hasOwner() { | ||
|
|
@@ -161,7 +126,7 @@ public boolean setOwner(String name) { | |
| } | ||
|
|
||
| public BlockFace getRotation() { | ||
| return getBlockFace(rotation); | ||
| return getBlockFace(rotation); | ||
| } | ||
|
|
||
| public void setRotation(BlockFace rotation) { | ||
|
|
||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You claim in your write-up that you tested this, but I don't see any tests here, and this comment certainly isn't reassuring.