blob: 7a53572aaeec1c596cba2d046b3ea9bb4ea761c9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
package gtPlusPlus.xmod.ob;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.api.objects.data.AutoMap;
import gtPlusPlus.core.util.minecraft.ItemUtils;
import gtPlusPlus.core.util.minecraft.PlayerUtils;
import gtPlusPlus.core.util.reflect.ReflectionUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
public class GliderHandler {
private static final AutoMap<Integer> mDimensionalBlacklist = new AutoMap<Integer>();
@SubscribeEvent
public void onItemUsageEx(final PlayerInteractEvent event) {
if (event != null && event.entityPlayer != null) {
if (event.action != Action.RIGHT_CLICK_BLOCK && event.action != Action.RIGHT_CLICK_AIR) {
Logger.WARNING("[OpenBlocks] Wrong type of PlayerInteractEvent, skipping.");
}
if (event.entityPlayer.worldObj.isRemote) {
return;
}
ItemStack aItem = event.entityPlayer.getItemInUse();
if (!ItemUtils.checkForInvalidItems(aItem)) {
Logger.WARNING("[OpenBlocks] Item in use was invalid, trying currentlyEquipped.");
aItem = event.entityPlayer.getCurrentEquippedItem();
}
if (!ItemUtils.checkForInvalidItems(aItem)) {
Logger.WARNING("[OpenBlocks] Item in use was invalid, trying heldItem.");
aItem = event.entityPlayer.getHeldItem();
}
if (ItemUtils.checkForInvalidItems(aItem)) {
Class aItemGliderClass = ReflectionUtils.getClass("openblocks.common.item.ItemHangGlider");
if (aItemGliderClass.isInstance(aItem.getItem())) {
if (!canPlayerGlideInThisDimension(event.entityPlayer)){
event.setCanceled(true);
PlayerUtils.messagePlayer(event.entityPlayer, "Glider is blacklisted in this dimension.");
Logger.WARNING("[OpenBlocks] "+event.entityPlayer.getCommandSenderName()+" tried to use glider in dimension "+event.entityPlayer.getEntityWorld().provider.dimensionId+".");
}
else {
Logger.WARNING("[OpenBlocks] "+event.entityPlayer.getCommandSenderName()+" used glider in dimension "+event.entityPlayer.getEntityWorld().provider.dimensionId+".");
}
}
else {
Logger.WARNING("[OpenBlocks] Item was not a glider.");
}
}
else {
Logger.WARNING("[OpenBlocks] Bad Item in player hand.");
}
}
else {
Logger.WARNING("[OpenBlocks] Bad event or player.");
}
}
private static final boolean canPlayerGlideInThisDimension(EntityPlayer aPlayer) {
World aWorld = aPlayer.worldObj;
if (aWorld == null) {
return false;
}
else {
if (aWorld.provider == null) {
return false;
}
else {
int aDimID = aWorld.provider.dimensionId;
for (int i : mDimensionalBlacklist) {
if (i == aDimID) {
return false;
}
}
}
}
return true;
}
static final void populateBlacklist() {
if (!mDimensionalBlacklist.isEmpty()) {
return;
}
File aBlacklist = gtPlusPlus.core.util.data.FileUtils.getFile("config/GTplusplus/", "GliderBlacklist", "cfg");
List<String> lines = new ArrayList<String>();
try {
lines = org.apache.commons.io.FileUtils.readLines(aBlacklist, "utf-8");
} catch (IOException e) {
e.printStackTrace();
}
if (lines.isEmpty()) {
FileWriter fw;
try {
String aInfoTip = "# Add one dimension ID per line. Lines with a # are comments and are ignored.";
fw = new FileWriter(aBlacklist);
fw.write(aInfoTip);
fw.close();
lines.add(aInfoTip);
} catch (IOException e) {
e.printStackTrace();
}
}
if (!lines.isEmpty()) {
for (String s : lines) {
if (s != null && !s.equals("") && !s.contains("#")) {
s = StringUtils.remove(s, " ");
s = StringUtils.trim(s);
s = StringUtils.remove(s, ",");
Integer g = Integer.decode(s);
if (g != null) {
mDimensionalBlacklist.add(g);
Logger.INFO("[OpenBlocks] Added Dimension with ID '"+g+"' to Blacklist for Glider.");
}
}
}
}
}
}
|